Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1806)

Side by Side Diff: test/cctest/test-func-name-inference.cc

Issue 12716010: Added a version of the v8::HandleScope constructor with an Isolate and use that consistently. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Feedback. Rebased Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-disasm-mips.cc ('k') | test/cctest/test-global-object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 using ::v8::internal::SmartArrayPointer; 45 using ::v8::internal::SmartArrayPointer;
46 using ::v8::internal::SharedFunctionInfo; 46 using ::v8::internal::SharedFunctionInfo;
47 using ::v8::internal::String; 47 using ::v8::internal::String;
48 48
49 49
50 static v8::Persistent<v8::Context> env; 50 static v8::Persistent<v8::Context> env;
51 51
52 52
53 static void InitializeVM() { 53 static void InitializeVM() {
54 if (env.IsEmpty()) { 54 if (env.IsEmpty()) {
55 v8::HandleScope scope;
56 env = v8::Context::New(); 55 env = v8::Context::New();
57 } 56 }
58 v8::HandleScope scope;
59 env->Enter(); 57 env->Enter();
60 } 58 }
61 59
62 60
63 static void CheckFunctionName(v8::Handle<v8::Script> script, 61 static void CheckFunctionName(v8::Handle<v8::Script> script,
64 const char* func_pos_src, 62 const char* func_pos_src,
65 const char* ref_inferred_name) { 63 const char* ref_inferred_name) {
66 // Get script source. 64 // Get script source.
67 Handle<Object> obj = v8::Utils::OpenHandle(*script); 65 Handle<Object> obj = v8::Utils::OpenHandle(*script);
68 Handle<SharedFunctionInfo> shared_function; 66 Handle<SharedFunctionInfo> shared_function;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 102 }
105 103
106 104
107 static v8::Handle<v8::Script> Compile(const char* src) { 105 static v8::Handle<v8::Script> Compile(const char* src) {
108 return v8::Script::Compile(v8::String::New(src)); 106 return v8::Script::Compile(v8::String::New(src));
109 } 107 }
110 108
111 109
112 TEST(GlobalProperty) { 110 TEST(GlobalProperty) {
113 InitializeVM(); 111 InitializeVM();
114 v8::HandleScope scope; 112 v8::HandleScope scope(env->GetIsolate());
115 113
116 v8::Handle<v8::Script> script = Compile( 114 v8::Handle<v8::Script> script = Compile(
117 "fun1 = function() { return 1; }\n" 115 "fun1 = function() { return 1; }\n"
118 "fun2 = function() { return 2; }\n"); 116 "fun2 = function() { return 2; }\n");
119 CheckFunctionName(script, "return 1", "fun1"); 117 CheckFunctionName(script, "return 1", "fun1");
120 CheckFunctionName(script, "return 2", "fun2"); 118 CheckFunctionName(script, "return 2", "fun2");
121 } 119 }
122 120
123 121
124 TEST(GlobalVar) { 122 TEST(GlobalVar) {
125 InitializeVM(); 123 InitializeVM();
126 v8::HandleScope scope; 124 v8::HandleScope scope(env->GetIsolate());
127 125
128 v8::Handle<v8::Script> script = Compile( 126 v8::Handle<v8::Script> script = Compile(
129 "var fun1 = function() { return 1; }\n" 127 "var fun1 = function() { return 1; }\n"
130 "var fun2 = function() { return 2; }\n"); 128 "var fun2 = function() { return 2; }\n");
131 CheckFunctionName(script, "return 1", "fun1"); 129 CheckFunctionName(script, "return 1", "fun1");
132 CheckFunctionName(script, "return 2", "fun2"); 130 CheckFunctionName(script, "return 2", "fun2");
133 } 131 }
134 132
135 133
136 TEST(LocalVar) { 134 TEST(LocalVar) {
137 InitializeVM(); 135 InitializeVM();
138 v8::HandleScope scope; 136 v8::HandleScope scope(env->GetIsolate());
139 137
140 v8::Handle<v8::Script> script = Compile( 138 v8::Handle<v8::Script> script = Compile(
141 "function outer() {\n" 139 "function outer() {\n"
142 " var fun1 = function() { return 1; }\n" 140 " var fun1 = function() { return 1; }\n"
143 " var fun2 = function() { return 2; }\n" 141 " var fun2 = function() { return 2; }\n"
144 "}"); 142 "}");
145 CheckFunctionName(script, "return 1", "fun1"); 143 CheckFunctionName(script, "return 1", "fun1");
146 CheckFunctionName(script, "return 2", "fun2"); 144 CheckFunctionName(script, "return 2", "fun2");
147 } 145 }
148 146
149 147
150 TEST(InConstructor) { 148 TEST(InConstructor) {
151 InitializeVM(); 149 InitializeVM();
152 v8::HandleScope scope; 150 v8::HandleScope scope(env->GetIsolate());
153 151
154 v8::Handle<v8::Script> script = Compile( 152 v8::Handle<v8::Script> script = Compile(
155 "function MyClass() {\n" 153 "function MyClass() {\n"
156 " this.method1 = function() { return 1; }\n" 154 " this.method1 = function() { return 1; }\n"
157 " this.method2 = function() { return 2; }\n" 155 " this.method2 = function() { return 2; }\n"
158 "}"); 156 "}");
159 CheckFunctionName(script, "return 1", "MyClass.method1"); 157 CheckFunctionName(script, "return 1", "MyClass.method1");
160 CheckFunctionName(script, "return 2", "MyClass.method2"); 158 CheckFunctionName(script, "return 2", "MyClass.method2");
161 } 159 }
162 160
163 161
164 TEST(Factory) { 162 TEST(Factory) {
165 InitializeVM(); 163 InitializeVM();
166 v8::HandleScope scope; 164 v8::HandleScope scope(env->GetIsolate());
167 165
168 v8::Handle<v8::Script> script = Compile( 166 v8::Handle<v8::Script> script = Compile(
169 "function createMyObj() {\n" 167 "function createMyObj() {\n"
170 " var obj = {};\n" 168 " var obj = {};\n"
171 " obj.method1 = function() { return 1; }\n" 169 " obj.method1 = function() { return 1; }\n"
172 " obj.method2 = function() { return 2; }\n" 170 " obj.method2 = function() { return 2; }\n"
173 " return obj;\n" 171 " return obj;\n"
174 "}"); 172 "}");
175 CheckFunctionName(script, "return 1", "obj.method1"); 173 CheckFunctionName(script, "return 1", "obj.method1");
176 CheckFunctionName(script, "return 2", "obj.method2"); 174 CheckFunctionName(script, "return 2", "obj.method2");
177 } 175 }
178 176
179 177
180 TEST(Static) { 178 TEST(Static) {
181 InitializeVM(); 179 InitializeVM();
182 v8::HandleScope scope; 180 v8::HandleScope scope(env->GetIsolate());
183 181
184 v8::Handle<v8::Script> script = Compile( 182 v8::Handle<v8::Script> script = Compile(
185 "function MyClass() {}\n" 183 "function MyClass() {}\n"
186 "MyClass.static1 = function() { return 1; }\n" 184 "MyClass.static1 = function() { return 1; }\n"
187 "MyClass.static2 = function() { return 2; }\n" 185 "MyClass.static2 = function() { return 2; }\n"
188 "MyClass.MyInnerClass = {}\n" 186 "MyClass.MyInnerClass = {}\n"
189 "MyClass.MyInnerClass.static3 = function() { return 3; }\n" 187 "MyClass.MyInnerClass.static3 = function() { return 3; }\n"
190 "MyClass.MyInnerClass.static4 = function() { return 4; }"); 188 "MyClass.MyInnerClass.static4 = function() { return 4; }");
191 CheckFunctionName(script, "return 1", "MyClass.static1"); 189 CheckFunctionName(script, "return 1", "MyClass.static1");
192 CheckFunctionName(script, "return 2", "MyClass.static2"); 190 CheckFunctionName(script, "return 2", "MyClass.static2");
193 CheckFunctionName(script, "return 3", "MyClass.MyInnerClass.static3"); 191 CheckFunctionName(script, "return 3", "MyClass.MyInnerClass.static3");
194 CheckFunctionName(script, "return 4", "MyClass.MyInnerClass.static4"); 192 CheckFunctionName(script, "return 4", "MyClass.MyInnerClass.static4");
195 } 193 }
196 194
197 195
198 TEST(Prototype) { 196 TEST(Prototype) {
199 InitializeVM(); 197 InitializeVM();
200 v8::HandleScope scope; 198 v8::HandleScope scope(env->GetIsolate());
201 199
202 v8::Handle<v8::Script> script = Compile( 200 v8::Handle<v8::Script> script = Compile(
203 "function MyClass() {}\n" 201 "function MyClass() {}\n"
204 "MyClass.prototype.method1 = function() { return 1; }\n" 202 "MyClass.prototype.method1 = function() { return 1; }\n"
205 "MyClass.prototype.method2 = function() { return 2; }\n" 203 "MyClass.prototype.method2 = function() { return 2; }\n"
206 "MyClass.MyInnerClass = function() {}\n" 204 "MyClass.MyInnerClass = function() {}\n"
207 "MyClass.MyInnerClass.prototype.method3 = function() { return 3; }\n" 205 "MyClass.MyInnerClass.prototype.method3 = function() { return 3; }\n"
208 "MyClass.MyInnerClass.prototype.method4 = function() { return 4; }"); 206 "MyClass.MyInnerClass.prototype.method4 = function() { return 4; }");
209 CheckFunctionName(script, "return 1", "MyClass.method1"); 207 CheckFunctionName(script, "return 1", "MyClass.method1");
210 CheckFunctionName(script, "return 2", "MyClass.method2"); 208 CheckFunctionName(script, "return 2", "MyClass.method2");
211 CheckFunctionName(script, "return 3", "MyClass.MyInnerClass.method3"); 209 CheckFunctionName(script, "return 3", "MyClass.MyInnerClass.method3");
212 CheckFunctionName(script, "return 4", "MyClass.MyInnerClass.method4"); 210 CheckFunctionName(script, "return 4", "MyClass.MyInnerClass.method4");
213 } 211 }
214 212
215 213
216 TEST(ObjectLiteral) { 214 TEST(ObjectLiteral) {
217 InitializeVM(); 215 InitializeVM();
218 v8::HandleScope scope; 216 v8::HandleScope scope(env->GetIsolate());
219 217
220 v8::Handle<v8::Script> script = Compile( 218 v8::Handle<v8::Script> script = Compile(
221 "function MyClass() {}\n" 219 "function MyClass() {}\n"
222 "MyClass.prototype = {\n" 220 "MyClass.prototype = {\n"
223 " method1: function() { return 1; },\n" 221 " method1: function() { return 1; },\n"
224 " method2: function() { return 2; } }"); 222 " method2: function() { return 2; } }");
225 CheckFunctionName(script, "return 1", "MyClass.method1"); 223 CheckFunctionName(script, "return 1", "MyClass.method1");
226 CheckFunctionName(script, "return 2", "MyClass.method2"); 224 CheckFunctionName(script, "return 2", "MyClass.method2");
227 } 225 }
228 226
229 227
230 TEST(AsParameter) { 228 TEST(AsParameter) {
231 InitializeVM(); 229 InitializeVM();
232 v8::HandleScope scope; 230 v8::HandleScope scope(env->GetIsolate());
233 231
234 v8::Handle<v8::Script> script = Compile( 232 v8::Handle<v8::Script> script = Compile(
235 "function f1(a) { return a(); }\n" 233 "function f1(a) { return a(); }\n"
236 "function f2(a, b) { return a() + b(); }\n" 234 "function f2(a, b) { return a() + b(); }\n"
237 "var result1 = f1(function() { return 1; })\n" 235 "var result1 = f1(function() { return 1; })\n"
238 "var result2 = f2(function() { return 2; }, function() { return 3; })"); 236 "var result2 = f2(function() { return 2; }, function() { return 3; })");
239 // Can't infer names here. 237 // Can't infer names here.
240 CheckFunctionName(script, "return 1", ""); 238 CheckFunctionName(script, "return 1", "");
241 CheckFunctionName(script, "return 2", ""); 239 CheckFunctionName(script, "return 2", "");
242 CheckFunctionName(script, "return 3", ""); 240 CheckFunctionName(script, "return 3", "");
243 } 241 }
244 242
245 243
246 TEST(MultipleFuncsConditional) { 244 TEST(MultipleFuncsConditional) {
247 InitializeVM(); 245 InitializeVM();
248 v8::HandleScope scope; 246 v8::HandleScope scope(env->GetIsolate());
249 247
250 v8::Handle<v8::Script> script = Compile( 248 v8::Handle<v8::Script> script = Compile(
251 "fun1 = 0 ?\n" 249 "fun1 = 0 ?\n"
252 " function() { return 1; } :\n" 250 " function() { return 1; } :\n"
253 " function() { return 2; }"); 251 " function() { return 2; }");
254 CheckFunctionName(script, "return 1", "fun1"); 252 CheckFunctionName(script, "return 1", "fun1");
255 CheckFunctionName(script, "return 2", "fun1"); 253 CheckFunctionName(script, "return 2", "fun1");
256 } 254 }
257 255
258 256
259 TEST(MultipleFuncsInLiteral) { 257 TEST(MultipleFuncsInLiteral) {
260 InitializeVM(); 258 InitializeVM();
261 v8::HandleScope scope; 259 v8::HandleScope scope(env->GetIsolate());
262 260
263 v8::Handle<v8::Script> script = Compile( 261 v8::Handle<v8::Script> script = Compile(
264 "function MyClass() {}\n" 262 "function MyClass() {}\n"
265 "MyClass.prototype = {\n" 263 "MyClass.prototype = {\n"
266 " method1: 0 ? function() { return 1; } :\n" 264 " method1: 0 ? function() { return 1; } :\n"
267 " function() { return 2; } }"); 265 " function() { return 2; } }");
268 CheckFunctionName(script, "return 1", "MyClass.method1"); 266 CheckFunctionName(script, "return 1", "MyClass.method1");
269 CheckFunctionName(script, "return 2", "MyClass.method1"); 267 CheckFunctionName(script, "return 2", "MyClass.method1");
270 } 268 }
271 269
272 270
273 // See http://code.google.com/p/v8/issues/detail?id=380 271 // See http://code.google.com/p/v8/issues/detail?id=380
274 TEST(Issue380) { 272 TEST(Issue380) {
275 InitializeVM(); 273 InitializeVM();
276 v8::HandleScope scope; 274 v8::HandleScope scope(env->GetIsolate());
277 275
278 v8::Handle<v8::Script> script = Compile( 276 v8::Handle<v8::Script> script = Compile(
279 "function a() {\n" 277 "function a() {\n"
280 "var result = function(p,a,c,k,e,d)" 278 "var result = function(p,a,c,k,e,d)"
281 "{return p}(\"if blah blah\",62,1976,\'a|b\'.split(\'|\'),0,{})\n" 279 "{return p}(\"if blah blah\",62,1976,\'a|b\'.split(\'|\'),0,{})\n"
282 "}"); 280 "}");
283 CheckFunctionName(script, "return p", ""); 281 CheckFunctionName(script, "return p", "");
284 } 282 }
285 283
286 284
287 TEST(MultipleAssignments) { 285 TEST(MultipleAssignments) {
288 InitializeVM(); 286 InitializeVM();
289 v8::HandleScope scope; 287 v8::HandleScope scope(env->GetIsolate());
290 288
291 v8::Handle<v8::Script> script = Compile( 289 v8::Handle<v8::Script> script = Compile(
292 "var fun1 = fun2 = function () { return 1; }\n" 290 "var fun1 = fun2 = function () { return 1; }\n"
293 "var bar1 = bar2 = bar3 = function () { return 2; }\n" 291 "var bar1 = bar2 = bar3 = function () { return 2; }\n"
294 "foo1 = foo2 = function () { return 3; }\n" 292 "foo1 = foo2 = function () { return 3; }\n"
295 "baz1 = baz2 = baz3 = function () { return 4; }"); 293 "baz1 = baz2 = baz3 = function () { return 4; }");
296 CheckFunctionName(script, "return 1", "fun2"); 294 CheckFunctionName(script, "return 1", "fun2");
297 CheckFunctionName(script, "return 2", "bar3"); 295 CheckFunctionName(script, "return 2", "bar3");
298 CheckFunctionName(script, "return 3", "foo2"); 296 CheckFunctionName(script, "return 3", "foo2");
299 CheckFunctionName(script, "return 4", "baz3"); 297 CheckFunctionName(script, "return 4", "baz3");
300 } 298 }
301 299
302 300
303 TEST(AsConstructorParameter) { 301 TEST(AsConstructorParameter) {
304 InitializeVM(); 302 InitializeVM();
305 v8::HandleScope scope; 303 v8::HandleScope scope(env->GetIsolate());
306 304
307 v8::Handle<v8::Script> script = Compile( 305 v8::Handle<v8::Script> script = Compile(
308 "function Foo() {}\n" 306 "function Foo() {}\n"
309 "var foo = new Foo(function() { return 1; })\n" 307 "var foo = new Foo(function() { return 1; })\n"
310 "var bar = new Foo(function() { return 2; }, function() { return 3; })"); 308 "var bar = new Foo(function() { return 2; }, function() { return 3; })");
311 CheckFunctionName(script, "return 1", ""); 309 CheckFunctionName(script, "return 1", "");
312 CheckFunctionName(script, "return 2", ""); 310 CheckFunctionName(script, "return 2", "");
313 CheckFunctionName(script, "return 3", ""); 311 CheckFunctionName(script, "return 3", "");
314 } 312 }
315 313
316 314
317 TEST(FactoryHashmap) { 315 TEST(FactoryHashmap) {
318 InitializeVM(); 316 InitializeVM();
319 v8::HandleScope scope; 317 v8::HandleScope scope(env->GetIsolate());
320 318
321 v8::Handle<v8::Script> script = Compile( 319 v8::Handle<v8::Script> script = Compile(
322 "function createMyObj() {\n" 320 "function createMyObj() {\n"
323 " var obj = {};\n" 321 " var obj = {};\n"
324 " obj[\"method1\"] = function() { return 1; }\n" 322 " obj[\"method1\"] = function() { return 1; }\n"
325 " obj[\"method2\"] = function() { return 2; }\n" 323 " obj[\"method2\"] = function() { return 2; }\n"
326 " return obj;\n" 324 " return obj;\n"
327 "}"); 325 "}");
328 CheckFunctionName(script, "return 1", "obj.method1"); 326 CheckFunctionName(script, "return 1", "obj.method1");
329 CheckFunctionName(script, "return 2", "obj.method2"); 327 CheckFunctionName(script, "return 2", "obj.method2");
330 } 328 }
331 329
332 330
333 TEST(FactoryHashmapVariable) { 331 TEST(FactoryHashmapVariable) {
334 InitializeVM(); 332 InitializeVM();
335 v8::HandleScope scope; 333 v8::HandleScope scope(env->GetIsolate());
336 334
337 v8::Handle<v8::Script> script = Compile( 335 v8::Handle<v8::Script> script = Compile(
338 "function createMyObj() {\n" 336 "function createMyObj() {\n"
339 " var obj = {};\n" 337 " var obj = {};\n"
340 " var methodName = \"method1\";\n" 338 " var methodName = \"method1\";\n"
341 " obj[methodName] = function() { return 1; }\n" 339 " obj[methodName] = function() { return 1; }\n"
342 " methodName = \"method2\";\n" 340 " methodName = \"method2\";\n"
343 " obj[methodName] = function() { return 2; }\n" 341 " obj[methodName] = function() { return 2; }\n"
344 " return obj;\n" 342 " return obj;\n"
345 "}"); 343 "}");
346 // Can't infer function names statically. 344 // Can't infer function names statically.
347 CheckFunctionName(script, "return 1", "obj.(anonymous function)"); 345 CheckFunctionName(script, "return 1", "obj.(anonymous function)");
348 CheckFunctionName(script, "return 2", "obj.(anonymous function)"); 346 CheckFunctionName(script, "return 2", "obj.(anonymous function)");
349 } 347 }
350 348
351 349
352 TEST(FactoryHashmapConditional) { 350 TEST(FactoryHashmapConditional) {
353 InitializeVM(); 351 InitializeVM();
354 v8::HandleScope scope; 352 v8::HandleScope scope(env->GetIsolate());
355 353
356 v8::Handle<v8::Script> script = Compile( 354 v8::Handle<v8::Script> script = Compile(
357 "function createMyObj() {\n" 355 "function createMyObj() {\n"
358 " var obj = {};\n" 356 " var obj = {};\n"
359 " obj[0 ? \"method1\" : \"method2\"] = function() { return 1; }\n" 357 " obj[0 ? \"method1\" : \"method2\"] = function() { return 1; }\n"
360 " return obj;\n" 358 " return obj;\n"
361 "}"); 359 "}");
362 // Can't infer the function name statically. 360 // Can't infer the function name statically.
363 CheckFunctionName(script, "return 1", "obj.(anonymous function)"); 361 CheckFunctionName(script, "return 1", "obj.(anonymous function)");
364 } 362 }
365 363
366 364
367 TEST(GlobalAssignmentAndCall) { 365 TEST(GlobalAssignmentAndCall) {
368 InitializeVM(); 366 InitializeVM();
369 v8::HandleScope scope; 367 v8::HandleScope scope(env->GetIsolate());
370 368
371 v8::Handle<v8::Script> script = Compile( 369 v8::Handle<v8::Script> script = Compile(
372 "var Foo = function() {\n" 370 "var Foo = function() {\n"
373 " return 1;\n" 371 " return 1;\n"
374 "}();\n" 372 "}();\n"
375 "var Baz = Bar = function() {\n" 373 "var Baz = Bar = function() {\n"
376 " return 2;\n" 374 " return 2;\n"
377 "}"); 375 "}");
378 // The inferred name is empty, because this is an assignment of a result. 376 // The inferred name is empty, because this is an assignment of a result.
379 CheckFunctionName(script, "return 1", ""); 377 CheckFunctionName(script, "return 1", "");
380 // See MultipleAssignments test. 378 // See MultipleAssignments test.
381 CheckFunctionName(script, "return 2", "Bar"); 379 CheckFunctionName(script, "return 2", "Bar");
382 } 380 }
383 381
384 382
385 TEST(AssignmentAndCall) { 383 TEST(AssignmentAndCall) {
386 InitializeVM(); 384 InitializeVM();
387 v8::HandleScope scope; 385 v8::HandleScope scope(env->GetIsolate());
388 386
389 v8::Handle<v8::Script> script = Compile( 387 v8::Handle<v8::Script> script = Compile(
390 "(function Enclosing() {\n" 388 "(function Enclosing() {\n"
391 " var Foo;\n" 389 " var Foo;\n"
392 " Foo = function() {\n" 390 " Foo = function() {\n"
393 " return 1;\n" 391 " return 1;\n"
394 " }();\n" 392 " }();\n"
395 " var Baz = Bar = function() {\n" 393 " var Baz = Bar = function() {\n"
396 " return 2;\n" 394 " return 2;\n"
397 " }\n" 395 " }\n"
398 "})();"); 396 "})();");
399 // The inferred name is empty, because this is an assignment of a result. 397 // The inferred name is empty, because this is an assignment of a result.
400 CheckFunctionName(script, "return 1", ""); 398 CheckFunctionName(script, "return 1", "");
401 // See MultipleAssignments test. 399 // See MultipleAssignments test.
402 // TODO(2276): Lazy compiling the enclosing outer closure would yield 400 // TODO(2276): Lazy compiling the enclosing outer closure would yield
403 // in "Enclosing.Bar" being the inferred name here. 401 // in "Enclosing.Bar" being the inferred name here.
404 CheckFunctionName(script, "return 2", "Bar"); 402 CheckFunctionName(script, "return 2", "Bar");
405 } 403 }
406 404
407 405
408 TEST(MethodAssignmentInAnonymousFunctionCall) { 406 TEST(MethodAssignmentInAnonymousFunctionCall) {
409 InitializeVM(); 407 InitializeVM();
410 v8::HandleScope scope; 408 v8::HandleScope scope(env->GetIsolate());
411 409
412 v8::Handle<v8::Script> script = Compile( 410 v8::Handle<v8::Script> script = Compile(
413 "(function () {\n" 411 "(function () {\n"
414 " var EventSource = function () { };\n" 412 " var EventSource = function () { };\n"
415 " EventSource.prototype.addListener = function () {\n" 413 " EventSource.prototype.addListener = function () {\n"
416 " return 2012;\n" 414 " return 2012;\n"
417 " };\n" 415 " };\n"
418 " this.PublicEventSource = EventSource;\n" 416 " this.PublicEventSource = EventSource;\n"
419 "})();"); 417 "})();");
420 CheckFunctionName(script, "return 2012", "EventSource.addListener"); 418 CheckFunctionName(script, "return 2012", "EventSource.addListener");
421 } 419 }
422 420
423 421
424 TEST(ReturnAnonymousFunction) { 422 TEST(ReturnAnonymousFunction) {
425 InitializeVM(); 423 InitializeVM();
426 v8::HandleScope scope; 424 v8::HandleScope scope(env->GetIsolate());
427 425
428 v8::Handle<v8::Script> script = Compile( 426 v8::Handle<v8::Script> script = Compile(
429 "(function() {\n" 427 "(function() {\n"
430 " function wrapCode() {\n" 428 " function wrapCode() {\n"
431 " return function () {\n" 429 " return function () {\n"
432 " return 2012;\n" 430 " return 2012;\n"
433 " };\n" 431 " };\n"
434 " };\n" 432 " };\n"
435 " var foo = 10;\n" 433 " var foo = 10;\n"
436 " function f() {\n" 434 " function f() {\n"
437 " return wrapCode();\n" 435 " return wrapCode();\n"
438 " }\n" 436 " }\n"
439 " this.ref = f;\n" 437 " this.ref = f;\n"
440 "})()"); 438 "})()");
441 script->Run(); 439 script->Run();
442 CheckFunctionName(script, "return 2012", ""); 440 CheckFunctionName(script, "return 2012", "");
443 } 441 }
OLDNEW
« no previous file with comments | « test/cctest/test-disasm-mips.cc ('k') | test/cctest/test-global-object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698