| OLD | NEW |
| 1 // Copyright 2007-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2010 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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 startup_name.Dispose(); | 384 startup_name.Dispose(); |
| 385 { | 385 { |
| 386 v8::Isolate::Scope isolate_scope(v8_isolate); | 386 v8::Isolate::Scope isolate_scope(v8_isolate); |
| 387 | 387 |
| 388 const char* file_name = FLAG_testing_serialization_file; | 388 const char* file_name = FLAG_testing_serialization_file; |
| 389 | 389 |
| 390 int snapshot_size = 0; | 390 int snapshot_size = 0; |
| 391 byte* snapshot = ReadBytes(file_name, &snapshot_size); | 391 byte* snapshot = ReadBytes(file_name, &snapshot_size); |
| 392 | 392 |
| 393 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | 393 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); |
| 394 Object* root; | 394 HandleScope handle_scope(isolate); |
| 395 Handle<Object> root; |
| 396 Handle<FixedArray> outdated_contexts; |
| 395 { | 397 { |
| 396 SnapshotData snapshot_data(Vector<const byte>(snapshot, snapshot_size)); | 398 SnapshotData snapshot_data(Vector<const byte>(snapshot, snapshot_size)); |
| 397 Deserializer deserializer(&snapshot_data); | 399 Deserializer deserializer(&snapshot_data); |
| 398 deserializer.DeserializePartial(isolate, &root); | 400 root = deserializer.DeserializePartial(isolate, &outdated_contexts) |
| 401 .ToHandleChecked(); |
| 402 CHECK_EQ(0, outdated_contexts->length()); |
| 399 CHECK(root->IsString()); | 403 CHECK(root->IsString()); |
| 400 } | 404 } |
| 401 HandleScope handle_scope(isolate); | |
| 402 Handle<Object> root_handle(root, isolate); | |
| 403 | 405 |
| 404 | 406 Handle<Object> root2; |
| 405 Object* root2; | |
| 406 { | 407 { |
| 407 SnapshotData snapshot_data(Vector<const byte>(snapshot, snapshot_size)); | 408 SnapshotData snapshot_data(Vector<const byte>(snapshot, snapshot_size)); |
| 408 Deserializer deserializer(&snapshot_data); | 409 Deserializer deserializer(&snapshot_data); |
| 409 deserializer.DeserializePartial(isolate, &root2); | 410 root2 = deserializer.DeserializePartial(isolate, &outdated_contexts) |
| 411 .ToHandleChecked(); |
| 410 CHECK(root2->IsString()); | 412 CHECK(root2->IsString()); |
| 411 CHECK(*root_handle == root2); | 413 CHECK(root.is_identical_to(root2)); |
| 412 } | 414 } |
| 413 } | 415 } |
| 414 v8_isolate->Dispose(); | 416 v8_isolate->Dispose(); |
| 415 } | 417 } |
| 416 } | 418 } |
| 417 | 419 |
| 418 | 420 |
| 419 UNINITIALIZED_TEST(ContextSerialization) { | 421 UNINITIALIZED_TEST(ContextSerialization) { |
| 420 if (!Snapshot::HaveASnapshotToStartFrom()) { | 422 if (!Snapshot::HaveASnapshotToStartFrom()) { |
| 421 v8::Isolate::CreateParams params; | 423 v8::Isolate::CreateParams params; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 startup_name.Dispose(); | 496 startup_name.Dispose(); |
| 495 { | 497 { |
| 496 v8::Isolate::Scope isolate_scope(v8_isolate); | 498 v8::Isolate::Scope isolate_scope(v8_isolate); |
| 497 | 499 |
| 498 const char* file_name = FLAG_testing_serialization_file; | 500 const char* file_name = FLAG_testing_serialization_file; |
| 499 | 501 |
| 500 int snapshot_size = 0; | 502 int snapshot_size = 0; |
| 501 byte* snapshot = ReadBytes(file_name, &snapshot_size); | 503 byte* snapshot = ReadBytes(file_name, &snapshot_size); |
| 502 | 504 |
| 503 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | 505 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); |
| 504 Object* root; | 506 HandleScope handle_scope(isolate); |
| 507 Handle<Object> root; |
| 508 Handle<FixedArray> outdated_contexts; |
| 505 { | 509 { |
| 506 SnapshotData snapshot_data(Vector<const byte>(snapshot, snapshot_size)); | 510 SnapshotData snapshot_data(Vector<const byte>(snapshot, snapshot_size)); |
| 507 Deserializer deserializer(&snapshot_data); | 511 Deserializer deserializer(&snapshot_data); |
| 508 deserializer.DeserializePartial(isolate, &root); | 512 root = deserializer.DeserializePartial(isolate, &outdated_contexts) |
| 513 .ToHandleChecked(); |
| 509 CHECK(root->IsContext()); | 514 CHECK(root->IsContext()); |
| 515 CHECK_EQ(1, outdated_contexts->length()); |
| 510 } | 516 } |
| 511 HandleScope handle_scope(isolate); | |
| 512 Handle<Object> root_handle(root, isolate); | |
| 513 | 517 |
| 514 | 518 Handle<Object> root2; |
| 515 Object* root2; | |
| 516 { | 519 { |
| 517 SnapshotData snapshot_data(Vector<const byte>(snapshot, snapshot_size)); | 520 SnapshotData snapshot_data(Vector<const byte>(snapshot, snapshot_size)); |
| 518 Deserializer deserializer(&snapshot_data); | 521 Deserializer deserializer(&snapshot_data); |
| 519 deserializer.DeserializePartial(isolate, &root2); | 522 root2 = deserializer.DeserializePartial(isolate, &outdated_contexts) |
| 523 .ToHandleChecked(); |
| 520 CHECK(root2->IsContext()); | 524 CHECK(root2->IsContext()); |
| 521 CHECK(*root_handle != root2); | 525 CHECK(!root.is_identical_to(root2)); |
| 522 } | 526 } |
| 523 } | 527 } |
| 524 v8_isolate->Dispose(); | 528 v8_isolate->Dispose(); |
| 529 } |
| 530 } |
| 531 |
| 532 |
| 533 UNINITIALIZED_TEST(CustomContextSerialization) { |
| 534 if (!Snapshot::HaveASnapshotToStartFrom()) { |
| 535 v8::Isolate::CreateParams params; |
| 536 params.enable_serializer = true; |
| 537 v8::Isolate* v8_isolate = v8::Isolate::New(params); |
| 538 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); |
| 539 Heap* heap = isolate->heap(); |
| 540 { |
| 541 v8::Isolate::Scope isolate_scope(v8_isolate); |
| 542 |
| 543 v8::Persistent<v8::Context> env; |
| 544 { |
| 545 HandleScope scope(isolate); |
| 546 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); |
| 547 } |
| 548 DCHECK(!env.IsEmpty()); |
| 549 { |
| 550 v8::HandleScope handle_scope(v8_isolate); |
| 551 v8::Local<v8::Context>::New(v8_isolate, env)->Enter(); |
| 552 // After execution, e's function context refers to the global object. |
| 553 CompileRun( |
| 554 "var e;" |
| 555 "(function() {" |
| 556 " e = function(s) { eval (s); }" |
| 557 "})();"); |
| 558 } |
| 559 // Make sure all builtin scripts are cached. |
| 560 { |
| 561 HandleScope scope(isolate); |
| 562 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
| 563 isolate->bootstrapper()->NativesSourceLookup(i); |
| 564 } |
| 565 } |
| 566 // If we don't do this then we end up with a stray root pointing at the |
| 567 // context even after we have disposed of env. |
| 568 heap->CollectAllGarbage(Heap::kNoGCFlags); |
| 569 |
| 570 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
| 571 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
| 572 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
| 573 |
| 574 { |
| 575 v8::HandleScope handle_scope(v8_isolate); |
| 576 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); |
| 577 } |
| 578 |
| 579 i::Object* raw_context = *v8::Utils::OpenPersistent(env); |
| 580 |
| 581 env.Reset(); |
| 582 |
| 583 SnapshotByteSink startup_sink; |
| 584 StartupSerializer startup_serializer(isolate, &startup_sink); |
| 585 startup_serializer.SerializeStrongReferences(); |
| 586 |
| 587 SnapshotByteSink partial_sink; |
| 588 PartialSerializer partial_serializer(isolate, &startup_serializer, |
| 589 &partial_sink); |
| 590 partial_serializer.Serialize(&raw_context); |
| 591 startup_serializer.SerializeWeakReferences(); |
| 592 |
| 593 SnapshotData startup_snapshot(startup_sink, startup_serializer); |
| 594 SnapshotData partial_snapshot(partial_sink, partial_serializer); |
| 595 |
| 596 WritePayload(partial_snapshot.RawData(), FLAG_testing_serialization_file); |
| 597 WritePayload(startup_snapshot.RawData(), startup_name.start()); |
| 598 |
| 599 startup_name.Dispose(); |
| 600 } |
| 601 v8_isolate->Dispose(); |
| 602 } |
| 603 } |
| 604 |
| 605 |
| 606 UNINITIALIZED_DEPENDENT_TEST(CustomContextDeSerialization, |
| 607 CustomContextSerialization) { |
| 608 if (!Snapshot::HaveASnapshotToStartFrom()) { |
| 609 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
| 610 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
| 611 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
| 612 |
| 613 v8::Isolate* v8_isolate = InitializeFromFile(startup_name.start()); |
| 614 CHECK(v8_isolate); |
| 615 startup_name.Dispose(); |
| 616 { |
| 617 v8::Isolate::Scope isolate_scope(v8_isolate); |
| 618 |
| 619 const char* file_name = FLAG_testing_serialization_file; |
| 620 |
| 621 int snapshot_size = 0; |
| 622 byte* snapshot = ReadBytes(file_name, &snapshot_size); |
| 623 |
| 624 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); |
| 625 HandleScope handle_scope(isolate); |
| 626 Handle<Object> root; |
| 627 Handle<FixedArray> outdated_contexts; |
| 628 { |
| 629 SnapshotData snapshot_data(Vector<const byte>(snapshot, snapshot_size)); |
| 630 Deserializer deserializer(&snapshot_data); |
| 631 root = deserializer.DeserializePartial(isolate, &outdated_contexts) |
| 632 .ToHandleChecked(); |
| 633 CHECK_EQ(2, outdated_contexts->length()); |
| 634 CHECK(root->IsContext()); |
| 635 } |
| 636 } |
| 637 v8_isolate->Dispose(); |
| 525 } | 638 } |
| 526 } | 639 } |
| 527 | 640 |
| 528 | 641 |
| 529 TEST(TestThatAlwaysSucceeds) { | 642 TEST(TestThatAlwaysSucceeds) { |
| 530 } | 643 } |
| 531 | 644 |
| 532 | 645 |
| 533 TEST(TestThatAlwaysFails) { | 646 TEST(TestThatAlwaysFails) { |
| 534 bool ArtificialFailure = false; | 647 bool ArtificialFailure = false; |
| (...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1212 { | 1325 { |
| 1213 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); | 1326 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); |
| 1214 script = v8::ScriptCompiler::CompileUnbound( | 1327 script = v8::ScriptCompiler::CompileUnbound( |
| 1215 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); | 1328 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); |
| 1216 } | 1329 } |
| 1217 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); | 1330 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); |
| 1218 CHECK(result->ToString(isolate2)->Equals(v8_str("XY"))); | 1331 CHECK(result->ToString(isolate2)->Equals(v8_str("XY"))); |
| 1219 } | 1332 } |
| 1220 isolate2->Dispose(); | 1333 isolate2->Dispose(); |
| 1221 } | 1334 } |
| OLD | NEW |