OLD | NEW |
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 InitializeVM(); | 274 InitializeVM(); |
275 v8::HandleScope scope; | 275 v8::HandleScope scope; |
276 | 276 |
277 v8::Handle<v8::Script> script = Compile( | 277 v8::Handle<v8::Script> script = Compile( |
278 "function a() {\n" | 278 "function a() {\n" |
279 "var result = function(p,a,c,k,e,d)" | 279 "var result = function(p,a,c,k,e,d)" |
280 "{return p}(\"if blah blah\",62,1976,\'a|b\'.split(\'|\'),0,{})\n" | 280 "{return p}(\"if blah blah\",62,1976,\'a|b\'.split(\'|\'),0,{})\n" |
281 "}"); | 281 "}"); |
282 CheckFunctionName(script, "return p", ""); | 282 CheckFunctionName(script, "return p", ""); |
283 } | 283 } |
| 284 |
| 285 |
| 286 TEST(MultipleAssignments) { |
| 287 InitializeVM(); |
| 288 v8::HandleScope scope; |
| 289 |
| 290 v8::Handle<v8::Script> script = Compile( |
| 291 "var fun1 = fun2 = function () { return 1; }"); |
| 292 CheckFunctionName(script, "return 1", "fun2"); |
| 293 } |
| 294 |
| 295 |
| 296 TEST(PassedAsConstructorParameter) { |
| 297 InitializeVM(); |
| 298 v8::HandleScope scope; |
| 299 |
| 300 v8::Handle<v8::Script> script = Compile( |
| 301 "function Foo() {}\n" |
| 302 "var foo = new Foo(function() { return 1; })"); |
| 303 CheckFunctionName(script, "return 1", ""); |
| 304 } |
| 305 |
| 306 |
| 307 TEST(FactoryHashmap) { |
| 308 InitializeVM(); |
| 309 v8::HandleScope scope; |
| 310 |
| 311 v8::Handle<v8::Script> script = Compile( |
| 312 "function createMyObj() {\n" |
| 313 " var obj = {};\n" |
| 314 " obj[\"method1\"] = function() { return 1; }\n" |
| 315 " obj[\"method2\"] = function() { return 2; }\n" |
| 316 " return obj;\n" |
| 317 "}"); |
| 318 CheckFunctionName(script, "return 1", "obj.method1"); |
| 319 CheckFunctionName(script, "return 2", "obj.method2"); |
| 320 } |
| 321 |
| 322 |
| 323 TEST(FactoryHashmapVariable) { |
| 324 InitializeVM(); |
| 325 v8::HandleScope scope; |
| 326 |
| 327 v8::Handle<v8::Script> script = Compile( |
| 328 "function createMyObj() {\n" |
| 329 " var obj = {};\n" |
| 330 " var methodName = \"method1\";\n" |
| 331 " obj[methodName] = function() { return 1; }\n" |
| 332 " methodName = \"method2\";\n" |
| 333 " obj[methodName] = function() { return 2; }\n" |
| 334 " return obj;\n" |
| 335 "}"); |
| 336 // Can't infer function names statically. |
| 337 CheckFunctionName(script, "return 1", "obj.(anonymous function)"); |
| 338 CheckFunctionName(script, "return 2", "obj.(anonymous function)"); |
| 339 } |
| 340 |
| 341 |
| 342 TEST(FactoryHashmapConditional) { |
| 343 InitializeVM(); |
| 344 v8::HandleScope scope; |
| 345 |
| 346 v8::Handle<v8::Script> script = Compile( |
| 347 "function createMyObj() {\n" |
| 348 " var obj = {};\n" |
| 349 " obj[0 ? \"method1\" : \"method2\"] = function() { return 1; }\n" |
| 350 " return obj;\n" |
| 351 "}"); |
| 352 // Can't infer the function name statically. |
| 353 CheckFunctionName(script, "return 1", "obj.(anonymous function)"); |
| 354 } |
OLD | NEW |