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 11 matching lines...) Expand all Loading... |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 <signal.h> | 28 #include <signal.h> |
29 | 29 |
30 #include "sys/stat.h" | 30 #include "sys/stat.h" |
31 | 31 |
32 // TODO(dcarney): remove | |
33 #define V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT | |
34 #define V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW | |
35 | |
36 #include "v8.h" | 32 #include "v8.h" |
37 | 33 |
38 #include "debug.h" | 34 #include "debug.h" |
39 #include "ic-inl.h" | 35 #include "ic-inl.h" |
40 #include "runtime.h" | 36 #include "runtime.h" |
41 #include "serialize.h" | 37 #include "serialize.h" |
42 #include "scopeinfo.h" | 38 #include "scopeinfo.h" |
43 #include "snapshot.h" | 39 #include "snapshot.h" |
44 #include "cctest.h" | 40 #include "cctest.h" |
45 #include "spaces.h" | 41 #include "spaces.h" |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 CHECK_EQ(4, script->Run()->Int32Value()); | 362 CHECK_EQ(4, script->Run()->Int32Value()); |
367 } | 363 } |
368 } | 364 } |
369 | 365 |
370 | 366 |
371 TEST(PartialSerialization) { | 367 TEST(PartialSerialization) { |
372 if (!Snapshot::HaveASnapshotToStartFrom()) { | 368 if (!Snapshot::HaveASnapshotToStartFrom()) { |
373 Serializer::Enable(); | 369 Serializer::Enable(); |
374 v8::V8::Initialize(); | 370 v8::V8::Initialize(); |
375 Isolate* isolate = Isolate::Current(); | 371 Isolate* isolate = Isolate::Current(); |
| 372 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
376 Heap* heap = isolate->heap(); | 373 Heap* heap = isolate->heap(); |
377 | 374 |
378 v8::Persistent<v8::Context> env; | 375 v8::Persistent<v8::Context> env; |
379 { | 376 { |
380 HandleScope scope(isolate); | 377 HandleScope scope(isolate); |
381 env.Reset(v8::Isolate::GetCurrent(), | 378 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); |
382 v8::Context::New(v8::Isolate::GetCurrent())); | |
383 } | 379 } |
384 ASSERT(!env.IsEmpty()); | 380 ASSERT(!env.IsEmpty()); |
385 env->Enter(); | 381 { |
| 382 v8::HandleScope handle_scope(v8_isolate); |
| 383 v8::Local<v8::Context>::New(v8_isolate, env)->Enter(); |
| 384 } |
386 // Make sure all builtin scripts are cached. | 385 // Make sure all builtin scripts are cached. |
387 { HandleScope scope(isolate); | 386 { HandleScope scope(isolate); |
388 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { | 387 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
389 isolate->bootstrapper()->NativesSourceLookup(i); | 388 isolate->bootstrapper()->NativesSourceLookup(i); |
390 } | 389 } |
391 } | 390 } |
392 heap->CollectAllGarbage(Heap::kNoGCFlags); | 391 heap->CollectAllGarbage(Heap::kNoGCFlags); |
393 heap->CollectAllGarbage(Heap::kNoGCFlags); | 392 heap->CollectAllGarbage(Heap::kNoGCFlags); |
394 | 393 |
395 Object* raw_foo; | 394 Object* raw_foo; |
396 { | 395 { |
397 v8::HandleScope handle_scope(env->GetIsolate()); | 396 v8::HandleScope handle_scope(v8_isolate); |
398 v8::Local<v8::String> foo = v8::String::New("foo"); | 397 v8::Local<v8::String> foo = v8::String::New("foo"); |
399 ASSERT(!foo.IsEmpty()); | 398 ASSERT(!foo.IsEmpty()); |
400 raw_foo = *(v8::Utils::OpenHandle(*foo)); | 399 raw_foo = *(v8::Utils::OpenHandle(*foo)); |
401 } | 400 } |
402 | 401 |
403 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | 402 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
404 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | 403 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
405 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | 404 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
406 | 405 |
407 env->Exit(); | 406 { |
408 env.Dispose(env->GetIsolate()); | 407 v8::HandleScope handle_scope(v8_isolate); |
| 408 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); |
| 409 } |
| 410 env.Dispose(v8_isolate); |
409 | 411 |
410 FileByteSink startup_sink(startup_name.start()); | 412 FileByteSink startup_sink(startup_name.start()); |
411 StartupSerializer startup_serializer(&startup_sink); | 413 StartupSerializer startup_serializer(&startup_sink); |
412 startup_serializer.SerializeStrongReferences(); | 414 startup_serializer.SerializeStrongReferences(); |
413 | 415 |
414 FileByteSink partial_sink(FLAG_testing_serialization_file); | 416 FileByteSink partial_sink(FLAG_testing_serialization_file); |
415 PartialSerializer p_ser(&startup_serializer, &partial_sink); | 417 PartialSerializer p_ser(&startup_serializer, &partial_sink); |
416 p_ser.Serialize(&raw_foo); | 418 p_ser.Serialize(&raw_foo); |
417 startup_serializer.SerializeWeakReferences(); | 419 startup_serializer.SerializeWeakReferences(); |
418 | 420 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 } | 507 } |
506 } | 508 } |
507 } | 509 } |
508 | 510 |
509 | 511 |
510 TEST(ContextSerialization) { | 512 TEST(ContextSerialization) { |
511 if (!Snapshot::HaveASnapshotToStartFrom()) { | 513 if (!Snapshot::HaveASnapshotToStartFrom()) { |
512 Serializer::Enable(); | 514 Serializer::Enable(); |
513 v8::V8::Initialize(); | 515 v8::V8::Initialize(); |
514 Isolate* isolate = Isolate::Current(); | 516 Isolate* isolate = Isolate::Current(); |
| 517 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
515 Heap* heap = isolate->heap(); | 518 Heap* heap = isolate->heap(); |
516 | 519 |
517 v8::Persistent<v8::Context> env; | 520 v8::Persistent<v8::Context> env; |
518 { | 521 { |
519 HandleScope scope(isolate); | 522 HandleScope scope(isolate); |
520 env.Reset(v8::Isolate::GetCurrent(), | 523 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); |
521 v8::Context::New(v8::Isolate::GetCurrent())); | |
522 } | 524 } |
523 ASSERT(!env.IsEmpty()); | 525 ASSERT(!env.IsEmpty()); |
524 env->Enter(); | 526 { |
| 527 v8::HandleScope handle_scope(v8_isolate); |
| 528 v8::Local<v8::Context>::New(v8_isolate, env)->Enter(); |
| 529 } |
525 // Make sure all builtin scripts are cached. | 530 // Make sure all builtin scripts are cached. |
526 { HandleScope scope(isolate); | 531 { HandleScope scope(isolate); |
527 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { | 532 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
528 isolate->bootstrapper()->NativesSourceLookup(i); | 533 isolate->bootstrapper()->NativesSourceLookup(i); |
529 } | 534 } |
530 } | 535 } |
531 // If we don't do this then we end up with a stray root pointing at the | 536 // If we don't do this then we end up with a stray root pointing at the |
532 // context even after we have disposed of env. | 537 // context even after we have disposed of env. |
533 heap->CollectAllGarbage(Heap::kNoGCFlags); | 538 heap->CollectAllGarbage(Heap::kNoGCFlags); |
534 | 539 |
535 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | 540 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
536 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | 541 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
537 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | 542 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
538 | 543 |
539 env->Exit(); | 544 { |
| 545 v8::HandleScope handle_scope(v8_isolate); |
| 546 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); |
| 547 } |
540 | 548 |
541 Object* raw_context = *(v8::Utils::OpenHandle(*env)); | 549 Object* raw_context = *(v8::Utils::OpenHandle(*env)); |
542 | 550 |
543 env.Dispose(env->GetIsolate()); | 551 env.Dispose(v8_isolate); |
544 | 552 |
545 FileByteSink startup_sink(startup_name.start()); | 553 FileByteSink startup_sink(startup_name.start()); |
546 StartupSerializer startup_serializer(&startup_sink); | 554 StartupSerializer startup_serializer(&startup_sink); |
547 startup_serializer.SerializeStrongReferences(); | 555 startup_serializer.SerializeStrongReferences(); |
548 | 556 |
549 FileByteSink partial_sink(FLAG_testing_serialization_file); | 557 FileByteSink partial_sink(FLAG_testing_serialization_file); |
550 PartialSerializer p_ser(&startup_serializer, &partial_sink); | 558 PartialSerializer p_ser(&startup_serializer, &partial_sink); |
551 p_ser.Serialize(&raw_context); | 559 p_ser.Serialize(&raw_context); |
552 startup_serializer.SerializeWeakReferences(); | 560 startup_serializer.SerializeWeakReferences(); |
553 | 561 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 TEST(TestThatAlwaysFails) { | 625 TEST(TestThatAlwaysFails) { |
618 bool ArtificialFailure = false; | 626 bool ArtificialFailure = false; |
619 CHECK(ArtificialFailure); | 627 CHECK(ArtificialFailure); |
620 } | 628 } |
621 | 629 |
622 | 630 |
623 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { | 631 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { |
624 bool ArtificialFailure2 = false; | 632 bool ArtificialFailure2 = false; |
625 CHECK(ArtificialFailure2); | 633 CHECK(ArtificialFailure2); |
626 } | 634 } |
OLD | NEW |