public
Created

V8 reflection

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
var reflection = {
getCallStack: function getCallStack() {
var old = Error.prepareStackTrace, e = {};
Error.prepareStackTrace = function (e, cs) { return cs; };
if (Error.captureStackTrace) {
Error.captureStackTrace(e, getCallStack);
e = e.stack;
e.shift();
Error.prepareStackTrace = old;
}
return e;
},
fnInfo: function (callsite) {
return {
name: function () { return callsite.getFunctionName(); },
module: function () { return urlToModuleName(callsite.getScriptNameOrSourceURL()); },
params: function () { return getParams(callsite.getFunction()); }
};
},
getCallingModule: function () {
var stack = reflection.getCallStack();
if (stack.length) {
stack.shift();
return reflection.fnInfo(stack[0]).module();
}
}
};

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.