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 14 matching lines...) Expand all Loading... |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include <stdlib.h> | 28 #include <stdlib.h> |
29 #include <wchar.h> | 29 #include <wchar.h> |
30 | 30 |
31 #include "src/v8.h" | 31 #include "src/v8.h" |
32 | 32 |
33 #include "src/compiler.h" | 33 #include "src/compiler.h" |
34 #include "src/disasm.h" | 34 #include "src/disasm.h" |
| 35 #include "src/parser.h" |
35 #include "test/cctest/cctest.h" | 36 #include "test/cctest/cctest.h" |
36 | 37 |
37 using namespace v8::internal; | 38 using namespace v8::internal; |
38 | 39 |
39 static Handle<Object> GetGlobalProperty(const char* name) { | 40 static Handle<Object> GetGlobalProperty(const char* name) { |
40 Isolate* isolate = CcTest::i_isolate(); | 41 Isolate* isolate = CcTest::i_isolate(); |
41 return Object::GetProperty( | 42 return Object::GetProperty( |
42 isolate, isolate->global_object(), name).ToHandleChecked(); | 43 isolate, isolate->global_object(), name).ToHandleChecked(); |
43 } | 44 } |
44 | 45 |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 *v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("closure2")))); | 392 *v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("closure2")))); |
392 CHECK(fun1->IsOptimized() | 393 CHECK(fun1->IsOptimized() |
393 || !CcTest::i_isolate()->use_crankshaft() || !fun1->IsOptimizable()); | 394 || !CcTest::i_isolate()->use_crankshaft() || !fun1->IsOptimizable()); |
394 CHECK(fun2->IsOptimized() | 395 CHECK(fun2->IsOptimized() |
395 || !CcTest::i_isolate()->use_crankshaft() || !fun2->IsOptimizable()); | 396 || !CcTest::i_isolate()->use_crankshaft() || !fun2->IsOptimizable()); |
396 CHECK_EQ(fun1->code(), fun2->code()); | 397 CHECK_EQ(fun1->code(), fun2->code()); |
397 } | 398 } |
398 } | 399 } |
399 | 400 |
400 | 401 |
| 402 TEST(SerializeToplevel) { |
| 403 FLAG_serialize_toplevel = true; |
| 404 v8::HandleScope scope(CcTest::isolate()); |
| 405 v8::Local<v8::Context> context = CcTest::NewContext(PRINT_EXTENSION); |
| 406 v8::Context::Scope context_scope(context); |
| 407 |
| 408 const char* source1 = "1 + 1"; |
| 409 const char* source2 = "1 + 2"; // Use alternate string to verify caching. |
| 410 |
| 411 Isolate* isolate = CcTest::i_isolate(); |
| 412 Handle<String> source1_string = isolate->factory() |
| 413 ->NewStringFromUtf8(CStrVector(source1)) |
| 414 .ToHandleChecked(); |
| 415 Handle<String> source2_string = isolate->factory() |
| 416 ->NewStringFromUtf8(CStrVector(source2)) |
| 417 .ToHandleChecked(); |
| 418 |
| 419 ScriptData* cache = NULL; |
| 420 |
| 421 Handle<SharedFunctionInfo> orig = |
| 422 Compiler::CompileScript(source1_string, Handle<String>(), 0, 0, false, |
| 423 Handle<Context>(isolate->native_context()), NULL, |
| 424 &cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE); |
| 425 |
| 426 Handle<SharedFunctionInfo> info = |
| 427 Compiler::CompileScript(source2_string, Handle<String>(), 0, 0, false, |
| 428 Handle<Context>(isolate->native_context()), NULL, |
| 429 &cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE); |
| 430 |
| 431 CHECK_NE(*orig, *info); |
| 432 Handle<JSFunction> fun = |
| 433 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 434 info, isolate->native_context()); |
| 435 Handle<JSObject> global(isolate->context()->global_object()); |
| 436 Handle<Object> result = |
| 437 Execution::Call(isolate, fun, global, 0, NULL).ToHandleChecked(); |
| 438 CHECK_EQ(2, Handle<Smi>::cast(result)->value()); |
| 439 } |
| 440 |
| 441 |
401 #ifdef ENABLE_DISASSEMBLER | 442 #ifdef ENABLE_DISASSEMBLER |
402 static Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj, | 443 static Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj, |
403 const char* property_name) { | 444 const char* property_name) { |
404 v8::Local<v8::Function> fun = | 445 v8::Local<v8::Function> fun = |
405 v8::Local<v8::Function>::Cast(obj->Get(v8_str(property_name))); | 446 v8::Local<v8::Function>::Cast(obj->Get(v8_str(property_name))); |
406 return v8::Utils::OpenHandle(*fun); | 447 return v8::Utils::OpenHandle(*fun); |
407 } | 448 } |
408 | 449 |
409 | 450 |
410 static void CheckCodeForUnsafeLiteral(Handle<JSFunction> f) { | 451 static void CheckCodeForUnsafeLiteral(Handle<JSFunction> f) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 CompileRun("function f() { a = 12345678 }; f();"); | 484 CompileRun("function f() { a = 12345678 }; f();"); |
444 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 485 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
445 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); | 486 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); |
446 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 487 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
447 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); | 488 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); |
448 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 489 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
449 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); | 490 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); |
450 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 491 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
451 } | 492 } |
452 #endif | 493 #endif |
OLD | NEW |