36 using ::v8::internal::Factory;
37 using ::v8::internal::Handle;
38 using ::v8::internal::Heap;
39 using ::v8::internal::Isolate;
40 using ::v8::internal::JSFunction;
42 using ::v8::internal::Runtime;
43 using ::v8::internal::Script;
44 using ::v8::internal::SmartArrayPointer;
45 using ::v8::internal::SharedFunctionInfo;
46 using ::v8::internal::String;
52 static void InitializeVM() {
63 const char* func_pos_src,
64 const char* ref_inferred_name) {
67 Handle<SharedFunctionInfo> shared_function;
68 if (obj->IsSharedFunctionInfo()) {
70 Handle<SharedFunctionInfo>(SharedFunctionInfo::cast(*obj));
73 Handle<SharedFunctionInfo>(JSFunction::cast(*obj)->shared());
75 Handle<Script> i_script(Script::cast(shared_function->script()));
76 CHECK(i_script->source()->IsString());
77 Handle<String> script_src(String::cast(i_script->source()));
80 Handle<String> func_pos_str =
82 int func_pos = Runtime::StringMatch(Isolate::Current(),
88 #ifdef ENABLE_DEBUGGER_SUPPORT
90 Object* shared_func_info_ptr =
91 Runtime::FindSharedFunctionInfoInScript(Isolate::Current(),
94 CHECK(shared_func_info_ptr !=
HEAP->undefined_value());
95 Handle<SharedFunctionInfo> shared_func_info(
96 SharedFunctionInfo::cast(shared_func_info_ptr));
99 SmartArrayPointer<char> inferred_name =
100 shared_func_info->inferred_name()->ToCString();
101 CHECK_EQ(ref_inferred_name, *inferred_name);
102 #endif // ENABLE_DEBUGGER_SUPPORT
116 "fun1 = function() { return 1; }\n"
117 "fun2 = function() { return 2; }\n");
118 CheckFunctionName(script,
"return 1",
"fun1");
119 CheckFunctionName(script,
"return 2",
"fun2");
128 "var fun1 = function() { return 1; }\n"
129 "var fun2 = function() { return 2; }\n");
130 CheckFunctionName(script,
"return 1",
"fun1");
131 CheckFunctionName(script,
"return 2",
"fun2");
140 "function outer() {\n"
141 " var fun1 = function() { return 1; }\n"
142 " var fun2 = function() { return 2; }\n"
144 CheckFunctionName(script,
"return 1",
"fun1");
145 CheckFunctionName(script,
"return 2",
"fun2");
154 "function MyClass() {\n"
155 " this.method1 = function() { return 1; }\n"
156 " this.method2 = function() { return 2; }\n"
158 CheckFunctionName(script,
"return 1",
"MyClass.method1");
159 CheckFunctionName(script,
"return 2",
"MyClass.method2");
168 "function createMyObj() {\n"
170 " obj.method1 = function() { return 1; }\n"
171 " obj.method2 = function() { return 2; }\n"
174 CheckFunctionName(script,
"return 1",
"obj.method1");
175 CheckFunctionName(script,
"return 2",
"obj.method2");
184 "function MyClass() {}\n"
185 "MyClass.static1 = function() { return 1; }\n"
186 "MyClass.static2 = function() { return 2; }\n"
187 "MyClass.MyInnerClass = {}\n"
188 "MyClass.MyInnerClass.static3 = function() { return 3; }\n"
189 "MyClass.MyInnerClass.static4 = function() { return 4; }");
190 CheckFunctionName(script,
"return 1",
"MyClass.static1");
191 CheckFunctionName(script,
"return 2",
"MyClass.static2");
192 CheckFunctionName(script,
"return 3",
"MyClass.MyInnerClass.static3");
193 CheckFunctionName(script,
"return 4",
"MyClass.MyInnerClass.static4");
202 "function MyClass() {}\n"
203 "MyClass.prototype.method1 = function() { return 1; }\n"
204 "MyClass.prototype.method2 = function() { return 2; }\n"
205 "MyClass.MyInnerClass = function() {}\n"
206 "MyClass.MyInnerClass.prototype.method3 = function() { return 3; }\n"
207 "MyClass.MyInnerClass.prototype.method4 = function() { return 4; }");
208 CheckFunctionName(script,
"return 1",
"MyClass.method1");
209 CheckFunctionName(script,
"return 2",
"MyClass.method2");
210 CheckFunctionName(script,
"return 3",
"MyClass.MyInnerClass.method3");
211 CheckFunctionName(script,
"return 4",
"MyClass.MyInnerClass.method4");
220 "function MyClass() {}\n"
221 "MyClass.prototype = {\n"
222 " method1: function() { return 1; },\n"
223 " method2: function() { return 2; } }");
224 CheckFunctionName(script,
"return 1",
"MyClass.method1");
225 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) {
251 " function() { return 1; } :\n"
252 " function() { return 2; }");
253 CheckFunctionName(script,
"return 1",
"fun1");
254 CheckFunctionName(script,
"return 2",
"fun1");
263 "function MyClass() {}\n"
264 "MyClass.prototype = {\n"
265 " method1: 0 ? function() { return 1; } :\n"
266 " function() { return 2; } }");
267 CheckFunctionName(script,
"return 1",
"MyClass.method1");
268 CheckFunctionName(script,
"return 2",
"MyClass.method1");
279 "var result = function(p,a,c,k,e,d)"
280 "{return p}(\"if blah blah\",62,1976,\'a|b\'.split(\'|\'),0,{})\n"
282 CheckFunctionName(script,
"return p",
"");
291 "var fun1 = fun2 = function () { return 1; }\n"
292 "var bar1 = bar2 = bar3 = function () { return 2; }\n"
293 "foo1 = foo2 = function () { return 3; }\n"
294 "baz1 = baz2 = baz3 = function () { return 4; }");
295 CheckFunctionName(script,
"return 1",
"fun2");
296 CheckFunctionName(script,
"return 2",
"bar3");
297 CheckFunctionName(script,
"return 3",
"foo2");
298 CheckFunctionName(script,
"return 4",
"baz3");
307 "function Foo() {}\n"
308 "var foo = new Foo(function() { return 1; })\n"
309 "var bar = new Foo(function() { return 2; }, function() { return 3; })");
310 CheckFunctionName(script,
"return 1",
"");
311 CheckFunctionName(script,
"return 2",
"");
312 CheckFunctionName(script,
"return 3",
"");
321 "function createMyObj() {\n"
323 " obj[\"method1\"] = function() { return 1; }\n"
324 " obj[\"method2\"] = function() { return 2; }\n"
327 CheckFunctionName(script,
"return 1",
"obj.method1");
328 CheckFunctionName(script,
"return 2",
"obj.method2");
337 "function createMyObj() {\n"
339 " var methodName = \"method1\";\n"
340 " obj[methodName] = function() { return 1; }\n"
341 " methodName = \"method2\";\n"
342 " obj[methodName] = function() { return 2; }\n"
346 CheckFunctionName(script,
"return 1",
"obj.(anonymous function)");
347 CheckFunctionName(script,
"return 2",
"obj.(anonymous function)");
351 TEST(FactoryHashmapConditional) {
356 "function createMyObj() {\n"
358 " obj[0 ? \"method1\" : \"method2\"] = function() { return 1; }\n"
362 CheckFunctionName(script,
"return 1",
"obj.(anonymous function)");
366 TEST(GlobalAssignmentAndCall) {
371 "var Foo = function() {\n"
374 "var Baz = Bar = function() {\n"
378 CheckFunctionName(script,
"return 1",
"");
380 CheckFunctionName(script,
"return 2",
"Bar");
389 "(function Enclosing() {\n"
391 " Foo = function() {\n"
394 " var Baz = Bar = function() {\n"
399 CheckFunctionName(script,
"return 1",
"");
401 CheckFunctionName(script,
"return 2",
"Enclosing.Bar");
405 TEST(MethodAssignmentInAnonymousFunctionCall) {
411 " var EventSource = function () { };\n"
412 " EventSource.prototype.addListener = function () {\n"
415 " this.PublicEventSource = EventSource;\n"
417 CheckFunctionName(script,
"return 2012",
"EventSource.addListener");
421 TEST(ReturnAnonymousFunction) {
427 " function wrapCode() {\n"
428 " return function () {\n"
434 " return wrapCode();\n"
439 CheckFunctionName(script,
"return 2012",
"");
static Local< Script > Compile(Handle< String > source, ScriptOrigin *origin=NULL, ScriptData *pre_data=NULL, Handle< String > script_data=Handle< String >())
#define CHECK_EQ(expected, value)
static V8EXPORT Local< String > New(const char *data, int length=-1)
#define CHECK_NE(unexpected, value)
Vector< const char > CStrVector(const char *data)
static Persistent< Context > New(ExtensionConfiguration *extensions=NULL, Handle< ObjectTemplate > global_template=Handle< ObjectTemplate >(), Handle< Value > global_object=Handle< Value >())
static v8::internal::Handle< v8::internal::TemplateInfo > OpenHandle(const Template *that)