38 using ::v8::internal::Factory;
39 using ::v8::internal::Handle;
40 using ::v8::internal::Heap;
41 using ::v8::internal::Isolate;
42 using ::v8::internal::JSFunction;
44 using ::v8::internal::Runtime;
45 using ::v8::internal::Script;
46 using ::v8::internal::SmartArrayPointer;
47 using ::v8::internal::SharedFunctionInfo;
48 using ::v8::internal::String;
52 const char* func_pos_src,
53 const char* ref_inferred_name) {
55 Factory* factory = isolate->factory();
59 Handle<SharedFunctionInfo> shared_function;
60 if (obj->IsSharedFunctionInfo()) {
62 Handle<SharedFunctionInfo>(SharedFunctionInfo::cast(*obj));
65 Handle<SharedFunctionInfo>(JSFunction::cast(*obj)->shared());
67 Handle<Script> i_script(Script::cast(shared_function->script()));
68 CHECK(i_script->source()->IsString());
69 Handle<String> script_src(String::cast(i_script->source()));
72 Handle<String> func_pos_str =
73 factory->NewStringFromAscii(
CStrVector(func_pos_src));
74 int func_pos = Runtime::StringMatch(isolate,
80 #ifdef ENABLE_DEBUGGER_SUPPORT
82 isolate->debug()->PrepareForBreakPoints();
83 Object* shared_func_info_ptr =
84 isolate->debug()->FindSharedFunctionInfoInScript(i_script, func_pos);
86 Handle<SharedFunctionInfo> shared_func_info(
87 SharedFunctionInfo::cast(shared_func_info_ptr));
90 SmartArrayPointer<char> inferred_name =
91 shared_func_info->inferred_name()->ToCString();
92 CHECK_EQ(ref_inferred_name, inferred_name.get());
93 #endif // ENABLE_DEBUGGER_SUPPORT
108 "fun1 = function() { return 1; }\n"
109 "fun2 = function() { return 2; }\n");
110 CheckFunctionName(script,
"return 1",
"fun1");
111 CheckFunctionName(script,
"return 2",
"fun2");
121 "var fun1 = function() { return 1; }\n"
122 "var fun2 = function() { return 2; }\n");
123 CheckFunctionName(script,
"return 1",
"fun1");
124 CheckFunctionName(script,
"return 2",
"fun2");
134 "function outer() {\n"
135 " var fun1 = function() { return 1; }\n"
136 " var fun2 = function() { return 2; }\n"
138 CheckFunctionName(script,
"return 1",
"fun1");
139 CheckFunctionName(script,
"return 2",
"fun2");
149 "function MyClass() {\n"
150 " this.method1 = function() { return 1; }\n"
151 " this.method2 = function() { return 2; }\n"
153 CheckFunctionName(script,
"return 1",
"MyClass.method1");
154 CheckFunctionName(script,
"return 2",
"MyClass.method2");
164 "function createMyObj() {\n"
166 " obj.method1 = function() { return 1; }\n"
167 " obj.method2 = function() { return 2; }\n"
170 CheckFunctionName(script,
"return 1",
"obj.method1");
171 CheckFunctionName(script,
"return 2",
"obj.method2");
181 "function MyClass() {}\n"
182 "MyClass.static1 = function() { return 1; }\n"
183 "MyClass.static2 = function() { return 2; }\n"
184 "MyClass.MyInnerClass = {}\n"
185 "MyClass.MyInnerClass.static3 = function() { return 3; }\n"
186 "MyClass.MyInnerClass.static4 = function() { return 4; }");
187 CheckFunctionName(script,
"return 1",
"MyClass.static1");
188 CheckFunctionName(script,
"return 2",
"MyClass.static2");
189 CheckFunctionName(script,
"return 3",
"MyClass.MyInnerClass.static3");
190 CheckFunctionName(script,
"return 4",
"MyClass.MyInnerClass.static4");
200 "function MyClass() {}\n"
201 "MyClass.prototype.method1 = function() { return 1; }\n"
202 "MyClass.prototype.method2 = function() { return 2; }\n"
203 "MyClass.MyInnerClass = function() {}\n"
204 "MyClass.MyInnerClass.prototype.method3 = function() { return 3; }\n"
205 "MyClass.MyInnerClass.prototype.method4 = function() { return 4; }");
206 CheckFunctionName(script,
"return 1",
"MyClass.method1");
207 CheckFunctionName(script,
"return 2",
"MyClass.method2");
208 CheckFunctionName(script,
"return 3",
"MyClass.MyInnerClass.method3");
209 CheckFunctionName(script,
"return 4",
"MyClass.MyInnerClass.method4");
219 "function MyClass() {}\n"
220 "MyClass.prototype = {\n"
221 " method1: function() { return 1; },\n"
222 " method2: function() { return 2; } }");
223 CheckFunctionName(script,
"return 1",
"MyClass.method1");
224 CheckFunctionName(script,
"return 2",
"MyClass.method2");
234 "function f1(a) { return a(); }\n"
235 "function f2(a, b) { return a() + b(); }\n"
236 "var result1 = f1(function() { return 1; })\n"
237 "var result2 = f2(function() { return 2; }, function() { return 3; })");
239 CheckFunctionName(script,
"return 1",
"");
240 CheckFunctionName(script,
"return 2",
"");
241 CheckFunctionName(script,
"return 3",
"");
245 TEST(MultipleFuncsConditional) {
252 " function() { return 1; } :\n"
253 " function() { return 2; }");
254 CheckFunctionName(script,
"return 1",
"fun1");
255 CheckFunctionName(script,
"return 2",
"fun1");
265 "function MyClass() {}\n"
266 "MyClass.prototype = {\n"
267 " method1: 0 ? function() { return 1; } :\n"
268 " function() { return 2; } }");
269 CheckFunctionName(script,
"return 1",
"MyClass.method1");
270 CheckFunctionName(script,
"return 2",
"MyClass.method1");
274 TEST(AnonymousInAnonymousClosure1) {
285 " var b = function() {\n"
290 CheckFunctionName(script,
"return",
"");
294 TEST(AnonymousInAnonymousClosure2) {
307 CheckFunctionName(script,
"return",
"");
311 TEST(NamedInAnonymousClosure) {
317 "var foo = function() {\n"
318 " (function named() {\n"
324 CheckFunctionName(script,
"return",
"foo");
336 "var result = function(p,a,c,k,e,d)"
337 "{return p}(\"if blah blah\",62,1976,\'a|b\'.split(\'|\'),0,{})\n"
339 CheckFunctionName(script,
"return p",
"");
349 "var fun1 = fun2 = function () { return 1; }\n"
350 "var bar1 = bar2 = bar3 = function () { return 2; }\n"
351 "foo1 = foo2 = function () { return 3; }\n"
352 "baz1 = baz2 = baz3 = function () { return 4; }");
353 CheckFunctionName(script,
"return 1",
"fun2");
354 CheckFunctionName(script,
"return 2",
"bar3");
355 CheckFunctionName(script,
"return 3",
"foo2");
356 CheckFunctionName(script,
"return 4",
"baz3");
366 "function Foo() {}\n"
367 "var foo = new Foo(function() { return 1; })\n"
368 "var bar = new Foo(function() { return 2; }, function() { return 3; })");
369 CheckFunctionName(script,
"return 1",
"");
370 CheckFunctionName(script,
"return 2",
"");
371 CheckFunctionName(script,
"return 3",
"");
381 "function createMyObj() {\n"
383 " obj[\"method1\"] = function() { return 1; }\n"
384 " obj[\"method2\"] = function() { return 2; }\n"
387 CheckFunctionName(script,
"return 1",
"obj.method1");
388 CheckFunctionName(script,
"return 2",
"obj.method2");
398 "function createMyObj() {\n"
400 " var methodName = \"method1\";\n"
401 " obj[methodName] = function() { return 1; }\n"
402 " methodName = \"method2\";\n"
403 " obj[methodName] = function() { return 2; }\n"
407 CheckFunctionName(script,
"return 1",
"obj.(anonymous function)");
408 CheckFunctionName(script,
"return 2",
"obj.(anonymous function)");
412 TEST(FactoryHashmapConditional) {
418 "function createMyObj() {\n"
420 " obj[0 ? \"method1\" : \"method2\"] = function() { return 1; }\n"
424 CheckFunctionName(script,
"return 1",
"obj.(anonymous function)");
428 TEST(GlobalAssignmentAndCall) {
434 "var Foo = function() {\n"
437 "var Baz = Bar = function() {\n"
441 CheckFunctionName(script,
"return 1",
"");
443 CheckFunctionName(script,
"return 2",
"Bar");
453 "(function Enclosing() {\n"
455 " Foo = function() {\n"
458 " var Baz = Bar = function() {\n"
463 CheckFunctionName(script,
"return 1",
"");
467 CheckFunctionName(script,
"return 2",
"Bar");
471 TEST(MethodAssignmentInAnonymousFunctionCall) {
478 " var EventSource = function () { };\n"
479 " EventSource.prototype.addListener = function () {\n"
482 " this.PublicEventSource = EventSource;\n"
484 CheckFunctionName(script,
"return 2012",
"EventSource.addListener");
488 TEST(ReturnAnonymousFunction) {
495 " function wrapCode() {\n"
496 " return function () {\n"
502 " return wrapCode();\n"
507 CheckFunctionName(script,
"return 2012",
"");
#define CHECK_EQ(expected, value)
kSerializedDataOffset Object
static Local< Script > Compile(Handle< String > source, ScriptOrigin *origin=NULL, ScriptData *script_data=NULL)
static i::Isolate * i_isolate()
static v8::internal::Handle< To > OpenHandle(v8::Local< From > handle)
#define CHECK_NE(unexpected, value)
Vector< const char > CStrVector(const char *data)
static void InitializeVM()
static v8::Isolate * isolate()
static Local< String > NewFromUtf8(Isolate *isolate, const char *data, NewStringType type=kNormalString, int length=-1)