Commit acf743a5 authored by oliver@apple.com's avatar oliver@apple.com

BUG 25171: It should be possible to manually set the name of an anonymous function

<https://bugs.webkit.org/show_bug.cgi?id=25171>

Submitted by Francisco Tolmasky <francisco@280north.com>
Reviewed by Oliver Hunt.

This change adds the displayName property to functions, which when set overrides the
normal name when appearing in the console.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@42478 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 80811805
2009-04-13 Francisco Tolmasky <francisco@280north.com>
Reviewed by Oliver Hunt.
BUG 25171: It should be possible to manually set the name of an anonymous function
<https://bugs.webkit.org/show_bug.cgi?id=25171>
This change adds the displayName property to functions, which when set overrides the
normal name when appearing in the console.
* profiler/Profiler.cpp:
(JSC::createCallIdentifierFromFunctionImp): Changed call to InternalFunction::name to InternalFunction::calculatedDisplayName
* runtime/CommonIdentifiers.h: Added displayName common identifier.
* runtime/InternalFunction.cpp:
(JSC::InternalFunction::displayName): Access to user settable displayName property
(JSC::InternalFunction::calculatedDisplayName): Returns displayName if it exists, if not then the natural name
2009-04-13 Geoffrey Garen <ggaren@apple.com>
Reviewed by Sam Weinig.
......@@ -148,7 +148,7 @@ CallIdentifier Profiler::createCallIdentifier(JSGlobalData* globalData, JSValueP
CallIdentifier createCallIdentifierFromFunctionImp(JSGlobalData* globalData, JSFunction* function)
{
const UString& name = function->name(globalData);
const UString& name = function->calculatedDisplayName(globalData);
return CallIdentifier(name.isEmpty() ? AnonymousFunction : name, function->body()->sourceURL(), function->body()->lineNo());
}
......
......@@ -63,7 +63,8 @@
macro(toPrecision) \
macro(toString) \
macro(UTC) \
macro(valueOf)
macro(valueOf) \
macro(displayName)
namespace JSC {
......
......@@ -48,4 +48,24 @@ const UString& InternalFunction::name(JSGlobalData* globalData)
return asString(getDirect(globalData->propertyNames->name))->value();
}
const UString& InternalFunction::displayName(JSGlobalData* globalData)
{
JSValuePtr displayName = getDirect(globalData->propertyNames->displayName);
if (displayName)
return asString(displayName)->value();
return UString::null();
}
const UString& InternalFunction::calculatedDisplayName(JSGlobalData* globalData)
{
const UString& explicitName = displayName(globalData);
if (!explicitName.isEmpty())
return explicitName;
return name(globalData);
}
} // namespace JSC
......@@ -37,6 +37,8 @@ namespace JSC {
static const ClassInfo info;
const UString& name(JSGlobalData*);
const UString& displayName(JSGlobalData*);
const UString& calculatedDisplayName(JSGlobalData*);
static PassRefPtr<Structure> createStructure(JSValuePtr proto)
{
......
2009-04-13 Francisco Tolmasky <francisco@280north.com>
Reviewed by Oliver Hunt.
BUG 25171: It should be possible to manually set the name of an anonymous function
<https://bugs.webkit.org/show_bug.cgi?id=25171>
Added test cases for using displayName property on anonymous and named functions.
* fast/profiler/anonymous-functions-with-display-names-expected.txt: Added.
* fast/profiler/anonymous-functions-with-display-names.html: Added.
* fast/profiler/named-functions-with-display-names-expected.txt: Added.
* fast/profiler/named-functions-with-display-names.html: Added.
2009-04-13 Darin Adler <darin@apple.com>
Reviewed by Dan Bernstein.
......
This page's JavaScript calls anonymous functions with display names.
To run this test manually, load it in the browser then load the WebInspector and look at the profile. You should see functions named "[x] iterations function", and no anonymous functions.
Profile title: Anonymous functions with display names
Thread_1 (no file) (line 0)
startTest anonymous-functions-with-display-names.html (line 23)
anonymousFunctionGenerator anonymous-functions-with-display-names.html (line 11)
0 iterations function anonymous-functions-with-display-names.html (line 13)
1 iterations function anonymous-functions-with-display-names.html (line 13)
2 iterations function anonymous-functions-with-display-names.html (line 13)
20 iterations function anonymous-functions-with-display-names.html (line 13)
1000 iterations function anonymous-functions-with-display-names.html (line 13)
endTest profiler-test-JS-resources.js (line 1)
<html>
<head>
<script src="resources/profiler-test-JS-resources.js"></script>
<script>
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.setJavaScriptProfilingEnabled(true);
}
function anonymousFunctionGenerator(iterations)
{
var variableThatPointsToAnAnonymousFunction = function()
{
for (var i = 0; i < iterations; ++i) ;
}
variableThatPointsToAnAnonymousFunction.displayName = iterations + " iterations function";
return variableThatPointsToAnAnonymousFunction;
}
function startTest()
{
console.profile("Anonymous functions with display names");
anonymousFunctionGenerator(0)();
anonymousFunctionGenerator(1)();
anonymousFunctionGenerator(2)();
anonymousFunctionGenerator(20)();
anonymousFunctionGenerator(1000)();
endTest();
}
</script>
</head>
<body onload="startTest()">
This page's JavaScript calls anonymous functions with display names.
<br>
<br>
To run this test manually, load it in the browser then load the WebInspector and look at
the profile. You should see functions named "[x] iterations function", and no anonymous functions.
<div id="output"></div>
</body>
</html>
This page's JavaScript calls named functions and changes their display names.
To run this test manually, load it in the browser then load the WebInspector and look at the profile. You should see functions named "[x] iteration[s] function", and not "function[x]"
Profile title: Named functions with display names
Thread_1 (no file) (line 0)
startTest named-functions-with-display-names.html (line 46)
0 iterations function named-functions-with-display-names.html (line 11)
1 iteration function named-functions-with-display-names.html (line 18)
2 iterations function named-functions-with-display-names.html (line 25)
20 iterations function named-functions-with-display-names.html (line 32)
1000 iterations function named-functions-with-display-names.html (line 39)
endTest profiler-test-JS-resources.js (line 1)
<html>
<head>
<script src="resources/profiler-test-JS-resources.js"></script>
<script>
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.setJavaScriptProfilingEnabled(true);
}
function function0()
{
for (var i = 0; i < 0; ++i) ;
}
function0.displayName = "0 iterations function";
function function1()
{
for (var i = 0; i < 1; ++i) ;
}
function1.displayName = "1 iteration function";
function function2()
{
for (var i = 0; i < 2; ++i) ;
}
function2.displayName = "2 iterations function";
function function20()
{
for (var i = 0; i < 20; ++i) ;
}
function20.displayName = "20 iterations function";
function function1000()
{
for (var i = 0; i < 1000; ++i) ;
}
function1000.displayName = "1000 iterations function";
function startTest()
{
console.profile("Named functions with display names");
function0();
function1();
function2();
function20();
function1000();
endTest();
}
</script>
</head>
<body onload="startTest()">
This page's JavaScript calls named functions and changes their display names.
<br>
<br>
To run this test manually, load it in the browser then load the WebInspector and look at
the profile. You should see functions named "[x] iteration[s] function", and not "function[x]"
<div id="output"></div>
</body>
</html>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment