From beb5161b84d47a9cfd754107a0e96b261b5259c0 Mon Sep 17 00:00:00 2001 From: "yurys@chromium.org" Date: Tue, 5 May 2009 18:12:03 +0000 Subject: [PATCH] Add function inferred name to FunctionMirror and its json representation. Review URL: http://codereview.chromium.org/109026 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1871 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/mirror-delay.js | 18 +++++++++++++++ src/runtime.cc | 9 ++++++++ src/runtime.h | 3 ++- test/mjsunit/debug-backtrace.js | 36 +++++++++++++++++++----------- test/mjsunit/mirror-unresolved-function.js | 2 ++ 5 files changed, 54 insertions(+), 14 deletions(-) diff --git a/src/mirror-delay.js b/src/mirror-delay.js index dc4d7eb..6511c7c 100644 --- a/src/mirror-delay.js +++ b/src/mirror-delay.js @@ -756,6 +756,15 @@ FunctionMirror.prototype.name = function() { /** + * Returns the inferred name of the function. + * @return {string} Name of the function + */ +FunctionMirror.prototype.inferredName = function() { + return %FunctionGetInferredName(this.value_); +}; + + +/** * Returns the source code for the function. * @return {string or undefined} The source code for the function. If the * function is not resolved undefined will be returned. @@ -857,6 +866,11 @@ UnresolvedFunctionMirror.prototype.name = function() { }; +UnresolvedFunctionMirror.prototype.inferredName = function() { + return undefined; +}; + + UnresolvedFunctionMirror.prototype.propertyNames = function(kind, limit) { return []; } @@ -1835,6 +1849,10 @@ JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content, if (mirror.isFunction()) { // Add function specific properties. content.push(MakeJSONPair_('name', StringToJSON_(mirror.name()))); + if (!IS_UNDEFINED(mirror.inferredName())) { + content.push(MakeJSONPair_('inferredName', + StringToJSON_(mirror.inferredName()))); + } content.push(MakeJSONPair_('resolved', BooleanToJSON_(mirror.resolved()))); if (mirror.resolved()) { content.push(MakeJSONPair_('source', StringToJSON_(mirror.source()))); diff --git a/src/runtime.cc b/src/runtime.cc index 3a738df..cb564d6 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -6860,6 +6860,15 @@ static Object* Runtime_FunctionGetAssemblerCode(Arguments args) { #endif // DEBUG return Heap::undefined_value(); } + + +static Object* Runtime_FunctionGetInferredName(Arguments args) { + NoHandleAllocation ha; + ASSERT(args.length() == 1); + + CONVERT_CHECKED(JSFunction, f, args[0]); + return f->shared()->inferred_name(); +} #endif // ENABLE_DEBUGGER_SUPPORT diff --git a/src/runtime.h b/src/runtime.h index 9430073..cc23db6 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -298,7 +298,8 @@ namespace v8 { namespace internal { F(DebugConstructedBy, 2) \ F(DebugGetPrototype, 1) \ F(SystemBreak, 0) \ - F(FunctionGetAssemblerCode, 1) + F(FunctionGetAssemblerCode, 1) \ + F(FunctionGetInferredName, 1) #else #define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) #endif diff --git a/test/mjsunit/debug-backtrace.js b/test/mjsunit/debug-backtrace.js index 940c4cb..f08f639 100644 --- a/test/mjsunit/debug-backtrace.js +++ b/test/mjsunit/debug-backtrace.js @@ -32,10 +32,14 @@ function f(x, y) { a=1; }; -function g() { +var m = function() { new f(1); }; +function g() { + m(); +}; + // Get the Debug object exposed from the debug context global object. Debug = debug.Debug @@ -90,22 +94,26 @@ function listener(event, exec_state, event_data, data) { // Get the backtrace. var json; json = '{"seq":0,"type":"request","command":"backtrace"}' - response = new ParsedResponse(dcp.processDebugJSONRequest(json)); + var resp = dcp.processDebugJSONRequest(json); + response = new ParsedResponse(resp); backtrace = response.body(); assertEquals(0, backtrace.fromFrame); - assertEquals(3, backtrace.toFrame); - assertEquals(3, backtrace.totalFrames); + assertEquals(4, backtrace.toFrame); + assertEquals(4, backtrace.totalFrames); var frames = backtrace.frames; - assertEquals(3, frames.length); + assertEquals(4, frames.length); for (var i = 0; i < frames.length; i++) { assertEquals('frame', frames[i].type); } assertEquals(0, frames[0].index); assertEquals("f", response.lookup(frames[0].func.ref).name); assertEquals(1, frames[1].index); - assertEquals("g", response.lookup(frames[1].func.ref).name); + assertEquals("", response.lookup(frames[1].func.ref).name); + assertEquals("m", response.lookup(frames[1].func.ref).inferredName); assertEquals(2, frames[2].index); - assertEquals("", response.lookup(frames[2].func.ref).name); + assertEquals("g", response.lookup(frames[2].func.ref).name); + assertEquals(3, frames[3].index); + assertEquals("", response.lookup(frames[3].func.ref).name); // Get backtrace with two frames. json = '{"seq":0,"type":"request","command":"backtrace","arguments":{"fromFrame":1,"toFrame":3}}' @@ -113,16 +121,17 @@ function listener(event, exec_state, event_data, data) { backtrace = response.body(); assertEquals(1, backtrace.fromFrame); assertEquals(3, backtrace.toFrame); - assertEquals(3, backtrace.totalFrames); + assertEquals(4, backtrace.totalFrames); var frames = backtrace.frames; assertEquals(2, frames.length); for (var i = 0; i < frames.length; i++) { assertEquals('frame', frames[i].type); } assertEquals(1, frames[0].index); - assertEquals("g", response.lookup(frames[0].func.ref).name); + assertEquals("", response.lookup(frames[0].func.ref).name); + assertEquals("m", response.lookup(frames[0].func.ref).inferredName); assertEquals(2, frames[1].index); - assertEquals("", response.lookup(frames[1].func.ref).name); + assertEquals("g", response.lookup(frames[1].func.ref).name); // Get the individual frames. json = '{"seq":0,"type":"request","command":"frame"}' @@ -158,16 +167,17 @@ function listener(event, exec_state, event_data, data) { response = new ParsedResponse(dcp.processDebugJSONRequest(json)); frame = response.body(); assertEquals(1, frame.index); - assertEquals("g", response.lookup(frame.func.ref).name); + assertEquals("", response.lookup(frame.func.ref).name); + assertEquals("m", response.lookup(frame.func.ref).inferredName); assertFalse(frame.constructCall); assertEquals(35, frame.line); assertEquals(2, frame.column); assertEquals(0, frame.arguments.length); - json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":2}}' + json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":3}}' response = new ParsedResponse(dcp.processDebugJSONRequest(json)); frame = response.body(); - assertEquals(2, frame.index); + assertEquals(3, frame.index); assertEquals("", response.lookup(frame.func.ref).name); // Source slices for the individual frames (they all refer to this script). diff --git a/test/mjsunit/mirror-unresolved-function.js b/test/mjsunit/mirror-unresolved-function.js index 21d0e56..8d8ca37 100644 --- a/test/mjsunit/mirror-unresolved-function.js +++ b/test/mjsunit/mirror-unresolved-function.js @@ -57,6 +57,7 @@ assertEquals('function', mirror.type()); assertFalse(mirror.isPrimitive()); assertEquals("Function", mirror.className()); assertEquals("f", mirror.name()); +assertEquals('undefined', typeof mirror.inferredName()); assertFalse(mirror.resolved()); assertEquals(void 0, mirror.source()); assertEquals('undefined', mirror.constructorFunction().type()); @@ -75,4 +76,5 @@ assertEquals(mirror.prototypeObject().handle(), fromJSON.prototypeObject.ref, 'U assertEquals('undefined', refs.lookup(fromJSON.prototypeObject.ref).type, 'Unexpected prototype object type in JSON'); assertFalse(fromJSON.resolved); assertEquals("f", fromJSON.name); +assertFalse('inferredName' in fromJSON); assertEquals(void 0, fromJSON.source); -- 2.7.4