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

Side by Side Diff: test/cctest/test-compiler.cc

Issue 373713006: Introduce code serializer/deserializer. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 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
« src/version.h ('K') | « src/version.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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* source = "1 + 1";
vogelheim 2014/07/07 15:20:01 It might be useful - maybe as a separate test - to
Yang 2014/07/08 09:01:05 Done.
409
410 Isolate* isolate = CcTest::i_isolate();
411 Handle<String> source_code = isolate->factory()
412 ->NewStringFromUtf8(CStrVector(source))
413 .ToHandleChecked();
414
415 ScriptData* cache = NULL;
416
417 Handle<SharedFunctionInfo> orig =
418 Compiler::CompileScript(source_code, Handle<String>(), 0, 0, false,
419 Handle<Context>(isolate->native_context()), NULL,
420 &cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE);
421
422 Handle<SharedFunctionInfo> info =
423 Compiler::CompileScript(source_code, Handle<String>(), 0, 0, false,
424 Handle<Context>(isolate->native_context()), NULL,
425 &cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE);
426
427 CHECK_NE(*orig, *info);
428 Handle<JSFunction> fun =
429 isolate->factory()->NewFunctionFromSharedFunctionInfo(
430 info, isolate->native_context());
431 Handle<JSObject> global(isolate->context()->global_object());
432 Handle<Object> result =
433 Execution::Call(isolate, fun, global, 0, NULL).ToHandleChecked();
434 CHECK_EQ(2, Handle<Smi>::cast(result)->value());
435 }
436
437
401 #ifdef ENABLE_DISASSEMBLER 438 #ifdef ENABLE_DISASSEMBLER
402 static Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj, 439 static Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj,
403 const char* property_name) { 440 const char* property_name) {
404 v8::Local<v8::Function> fun = 441 v8::Local<v8::Function> fun =
405 v8::Local<v8::Function>::Cast(obj->Get(v8_str(property_name))); 442 v8::Local<v8::Function>::Cast(obj->Get(v8_str(property_name)));
406 return v8::Utils::OpenHandle(*fun); 443 return v8::Utils::OpenHandle(*fun);
407 } 444 }
408 445
409 446
410 static void CheckCodeForUnsafeLiteral(Handle<JSFunction> f) { 447 static void CheckCodeForUnsafeLiteral(Handle<JSFunction> f) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 CompileRun("function f() { a = 12345678 }; f();"); 480 CompileRun("function f() { a = 12345678 }; f();");
444 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 481 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
445 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); 482 CompileRun("function f(x) { a = 12345678 + x}; f(1);");
446 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 483 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
447 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); 484 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);");
448 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 485 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
449 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); 486 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);");
450 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 487 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
451 } 488 }
452 #endif 489 #endif
OLDNEW
« src/version.h ('K') | « src/version.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698