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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 *v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("closure2")))); | 392 *v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("closure2")))); |
393 CHECK(fun1->IsOptimized() | 393 CHECK(fun1->IsOptimized() |
394 || !CcTest::i_isolate()->use_crankshaft() || !fun1->IsOptimizable()); | 394 || !CcTest::i_isolate()->use_crankshaft() || !fun1->IsOptimizable()); |
395 CHECK(fun2->IsOptimized() | 395 CHECK(fun2->IsOptimized() |
396 || !CcTest::i_isolate()->use_crankshaft() || !fun2->IsOptimizable()); | 396 || !CcTest::i_isolate()->use_crankshaft() || !fun2->IsOptimizable()); |
397 CHECK_EQ(fun1->code(), fun2->code()); | 397 CHECK_EQ(fun1->code(), fun2->code()); |
398 } | 398 } |
399 } | 399 } |
400 | 400 |
401 | 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 delete cache; | |
441 } | |
442 | |
443 | |
444 #ifdef ENABLE_DISASSEMBLER | 402 #ifdef ENABLE_DISASSEMBLER |
445 static Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj, | 403 static Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj, |
446 const char* property_name) { | 404 const char* property_name) { |
447 v8::Local<v8::Function> fun = | 405 v8::Local<v8::Function> fun = |
448 v8::Local<v8::Function>::Cast(obj->Get(v8_str(property_name))); | 406 v8::Local<v8::Function>::Cast(obj->Get(v8_str(property_name))); |
449 return v8::Utils::OpenHandle(*fun); | 407 return v8::Utils::OpenHandle(*fun); |
450 } | 408 } |
451 | 409 |
452 | 410 |
453 static void CheckCodeForUnsafeLiteral(Handle<JSFunction> f) { | 411 static void CheckCodeForUnsafeLiteral(Handle<JSFunction> f) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 CompileRun("function f() { a = 12345678 }; f();"); | 444 CompileRun("function f() { a = 12345678 }; f();"); |
487 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 445 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
488 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); | 446 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); |
489 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 447 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
490 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); | 448 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); |
491 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 449 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
492 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); | 450 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); |
493 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 451 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
494 } | 452 } |
495 #endif | 453 #endif |
OLD | NEW |