Ignore:
Timestamp:
Feb 1, 2012, 3:23:30 PM (13 years ago)
Author:
[email protected]
Message:

Add support for inferred function names
https://bugs.webkit.org/show_bug.cgi?id=77579

Reviewed by Gavin Barraclough.

Source/JavaScriptCore:

Add new "inferred" names to function expressions, getters, and setters.
This property is not exposed to JS, so is only visible in the debugger
and profiler.

(JSC::BytecodeGenerator::makeFunction):

  • debugger/DebuggerCallFrame.cpp:

(JSC::DebuggerCallFrame::calculatedFunctionName):

  • parser/ASTBuilder.h:

(JSC::ASTBuilder::createAssignResolve):
(JSC::ASTBuilder::createGetterOrSetterProperty):
(JSC::ASTBuilder::createProperty):
(JSC::ASTBuilder::makeAssignNode):

  • parser/Nodes.h:

(JSC::FunctionBodyNode::setInferredName):
(JSC::FunctionBodyNode::inferredName):
(FunctionBodyNode):

  • profiler/Profiler.cpp:

(JSC):
(JSC::Profiler::createCallIdentifier):
(JSC::createCallIdentifierFromFunctionImp):

  • runtime/Executable.cpp:

(JSC::FunctionExecutable::FunctionExecutable):
(JSC::FunctionExecutable::fromGlobalCode):

  • runtime/Executable.h:

(JSC::FunctionExecutable::create):
(JSC::FunctionExecutable::inferredName):
(FunctionExecutable):

  • runtime/JSFunction.cpp:

(JSC::JSFunction::calculatedDisplayName):
(JSC):
(JSC::getCalculatedDisplayName):

  • runtime/JSFunction.h:

(JSC):

LayoutTests:

Update test case results.

  • fast/profiler/anonymous-event-handler-expected.txt:
  • fast/profiler/anonymous-function-called-from-different-contexts-expected.txt:
  • fast/profiler/anonymous-function-calls-built-in-functions-expected.txt:
  • fast/profiler/anonymous-function-calls-eval-expected.txt:
  • fast/profiler/built-in-function-calls-anonymous-expected.txt:
  • fast/profiler/inline-event-handler-expected.txt:
  • fast/profiler/many-calls-in-the-same-scope-expected.txt:
  • fast/profiler/multiple-and-different-scoped-anonymous-function-calls-expected.txt:
  • fast/profiler/multiple-and-different-scoped-function-calls-expected.txt:
  • fast/profiler/multiple-anonymous-functions-called-from-the-same-function-expected.txt:
  • fast/profiler/nested-anonymous-functon-expected.txt:
  • fast/profiler/start-and-stop-profiler-multiple-times-expected.txt:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/profiler/Profiler.cpp

    r99223 r106504  
    4949static unsigned ProfilesUID = 0;
    5050
    51 static CallIdentifier createCallIdentifierFromFunctionImp(ExecState*, JSFunction*);
     51static CallIdentifier createCallIdentifierFromFunctionImp(ExecState*, JSObject*, const UString& defaultSourceURL, int defaultLineNumber);
    5252
    5353Profiler* Profiler::s_sharedProfiler = 0;
     
    164164    if (!functionValue.isObject())
    165165        return CallIdentifier("(unknown)", defaultSourceURL, defaultLineNumber);
    166     if (asObject(functionValue)->inherits(&JSFunction::s_info)) {
    167         JSFunction* function = asFunction(functionValue);
    168         if (!function->executable()->isHostFunction())
    169             return createCallIdentifierFromFunctionImp(exec, function);
    170     }
    171     if (asObject(functionValue)->inherits(&JSFunction::s_info))
    172         return CallIdentifier(static_cast<JSFunction*>(asObject(functionValue))->name(exec), defaultSourceURL, defaultLineNumber);
    173     if (asObject(functionValue)->inherits(&InternalFunction::s_info))
    174         return CallIdentifier(static_cast<InternalFunction*>(asObject(functionValue))->name(exec), defaultSourceURL, defaultLineNumber);
     166    if (asObject(functionValue)->inherits(&JSFunction::s_info) || asObject(functionValue)->inherits(&InternalFunction::s_info))
     167        return createCallIdentifierFromFunctionImp(exec, asObject(functionValue), defaultSourceURL, defaultLineNumber);
    175168    return CallIdentifier(makeUString("(", asObject(functionValue)->methodTable()->className(asObject(functionValue)), " object)"), defaultSourceURL, defaultLineNumber);
    176169}
    177170
    178 CallIdentifier createCallIdentifierFromFunctionImp(ExecState* exec, JSFunction* function)
     171CallIdentifier createCallIdentifierFromFunctionImp(ExecState* exec, JSObject* function, const UString& defaultSourceURL, int defaultLineNumber)
    179172{
    180     ASSERT(!function->isHostFunction());
    181     const UString& name = function->calculatedDisplayName(exec);
    182     return CallIdentifier(name.isEmpty() ? AnonymousFunction : name, function->jsExecutable()->sourceURL(), function->jsExecutable()->lineNo());
     173    const UString& name = getCalculatedDisplayName(exec, function);
     174    JSFunction* jsFunction = jsDynamicCast<JSFunction*>(function);
     175    if (jsFunction && !jsFunction->isHostFunction())
     176        return CallIdentifier(name.isEmpty() ? AnonymousFunction : name, jsFunction->jsExecutable()->sourceURL(), jsFunction->jsExecutable()->lineNo());
     177    return CallIdentifier(name.isEmpty() ? AnonymousFunction : name, defaultSourceURL, defaultLineNumber);
    183178}
    184179
Note: See TracChangeset for help on using the changeset viewer.