| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( | 348 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( |
| 349 env->Global()->Get(v8::String::New("f"))); | 349 env->Global()->Get(v8::String::New("f"))); |
| 350 CHECK_EQ(i, f->GetScriptLineNumber()); | 350 CHECK_EQ(i, f->GetScriptLineNumber()); |
| 351 } | 351 } |
| 352 } | 352 } |
| 353 | 353 |
| 354 | 354 |
| 355 // Test that optimized code for different closures is actually shared | 355 // Test that optimized code for different closures is actually shared |
| 356 // immediately by the FastNewClosureStub when run in the same context. | 356 // immediately by the FastNewClosureStub when run in the same context. |
| 357 TEST(OptimizedCodeSharing) { | 357 TEST(OptimizedCodeSharing) { |
| 358 // Skip test if --cache-optimized-code is not activated by default because |
| 359 // FastNewClosureStub that is baked into the snapshot is incorrect. |
| 360 if (!FLAG_cache_optimized_code) return; |
| 358 FLAG_allow_natives_syntax = true; | 361 FLAG_allow_natives_syntax = true; |
| 359 InitializeVM(); | 362 InitializeVM(); |
| 360 v8::HandleScope scope; | 363 v8::HandleScope scope; |
| 361 for (int i = 0; i < 10; i++) { | 364 for (int i = 0; i < 10; i++) { |
| 362 LocalContext env; | 365 LocalContext env; |
| 363 env->Global()->Set(v8::String::New("x"), v8::Integer::New(i)); | 366 env->Global()->Set(v8::String::New("x"), v8::Integer::New(i)); |
| 364 CompileRun("function MakeClosure() {" | 367 CompileRun("function MakeClosure() {" |
| 365 " return function() { return x; };" | 368 " return function() { return x; };" |
| 366 "}" | 369 "}" |
| 367 "var closure0 = MakeClosure();" | 370 "var closure0 = MakeClosure();" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 CompileRun("function f() { a = 12345678 }; f();"); | 428 CompileRun("function f() { a = 12345678 }; f();"); |
| 426 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); | 429 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); |
| 427 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); | 430 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); |
| 428 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); | 431 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); |
| 429 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); | 432 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); |
| 430 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); | 433 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); |
| 431 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); | 434 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); |
| 432 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); | 435 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); |
| 433 } | 436 } |
| 434 #endif | 437 #endif |
| OLD | NEW |