Hi,

ext Nyx wrote:
I'm in the process of writing a program to analyze traces of JavaScript code.
This involves logging events that occur in the interpreter. Currently, I'm
trying to just log function calls and property accesses. However, I'm unsure
exactly how to go about getting the names (identifiers) associated with
functions (and properties).

I wrote the following piece of code just to test things out, which I
inserted in Interpreter.cpp, in the definition of the op_call opcode, after
the "vPC = newCodeBlock->instructions().begin();" line:

JSGlobalObject* globalObject = callFrame->scopeChain()->globalObject;

printf("Function call: %s\n",
asFunction(v)->name(globalObject->globalExec()).ascii());
printf("%s\n", newCodeBlock->ownerExecutable()->sourceURL().ascii());
printf("%i\n", newCodeBlock->ownerExecutable()->lineNo());

Works for me.
You can pass callFrame to name() if you want, the result is the same.

What does your JavaScript look like?
E.g., if you're using a function expression

Foo.prototype.bar = function() { ... }

Then that function isn't going to have a name, e.g. your op_call code will print an empty string if you do "f = new Foo(); f.bar();".
You could "partially" name it by doing

Foo.prototype.bar = function bar() { ... }

For function definitions (e.g. "function foo() { ... }" in global code), the function is named accordingly.

Kent
_______________________________________________
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev

Reply via email to