| 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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 Local<Value> value = script->Run(); | 405 Local<Value> value = script->Run(); |
| 406 CHECK(value->IsNumber()); | 406 CHECK(value->IsNumber()); |
| 407 CHECK_EQ(7, value->Int32Value()); | 407 CHECK_EQ(7, value->Int32Value()); |
| 408 CHECK(source->IsExternal()); | 408 CHECK(source->IsExternal()); |
| 409 CHECK_EQ(resource, | 409 CHECK_EQ(resource, |
| 410 static_cast<TestResource*>(source->GetExternalStringResource())); | 410 static_cast<TestResource*>(source->GetExternalStringResource())); |
| 411 String::Encoding encoding = String::UNKNOWN_ENCODING; | 411 String::Encoding encoding = String::UNKNOWN_ENCODING; |
| 412 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), | 412 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), |
| 413 source->GetExternalStringResourceBase(&encoding)); | 413 source->GetExternalStringResourceBase(&encoding)); |
| 414 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding); | 414 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding); |
| 415 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 415 CcTest::heap()->CollectAllGarbage(); |
| 416 CHECK_EQ(0, dispose_count); | 416 CHECK_EQ(0, dispose_count); |
| 417 } | 417 } |
| 418 CcTest::i_isolate()->compilation_cache()->Clear(); | 418 CcTest::i_isolate()->compilation_cache()->Clear(); |
| 419 CcTest::heap()->CollectAllAvailableGarbage(); | 419 CcTest::heap()->CollectAllAvailableGarbage(); |
| 420 CHECK_EQ(1, dispose_count); | 420 CHECK_EQ(1, dispose_count); |
| 421 } | 421 } |
| 422 | 422 |
| 423 | 423 |
| 424 THREADED_TEST(ScriptUsingOneByteStringResource) { | 424 THREADED_TEST(ScriptUsingOneByteStringResource) { |
| 425 int dispose_count = 0; | 425 int dispose_count = 0; |
| 426 const char* c_source = "1 + 2 * 3"; | 426 const char* c_source = "1 + 2 * 3"; |
| 427 { | 427 { |
| 428 LocalContext env; | 428 LocalContext env; |
| 429 v8::HandleScope scope(env->GetIsolate()); | 429 v8::HandleScope scope(env->GetIsolate()); |
| 430 TestOneByteResource* resource = | 430 TestOneByteResource* resource = |
| 431 new TestOneByteResource(i::StrDup(c_source), &dispose_count); | 431 new TestOneByteResource(i::StrDup(c_source), &dispose_count); |
| 432 Local<String> source = String::NewExternal(env->GetIsolate(), resource); | 432 Local<String> source = String::NewExternal(env->GetIsolate(), resource); |
| 433 CHECK(source->IsExternalOneByte()); | 433 CHECK(source->IsExternalOneByte()); |
| 434 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), | 434 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), |
| 435 source->GetExternalOneByteStringResource()); | 435 source->GetExternalOneByteStringResource()); |
| 436 String::Encoding encoding = String::UNKNOWN_ENCODING; | 436 String::Encoding encoding = String::UNKNOWN_ENCODING; |
| 437 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), | 437 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), |
| 438 source->GetExternalStringResourceBase(&encoding)); | 438 source->GetExternalStringResourceBase(&encoding)); |
| 439 CHECK_EQ(String::ONE_BYTE_ENCODING, encoding); | 439 CHECK_EQ(String::ONE_BYTE_ENCODING, encoding); |
| 440 Local<Script> script = v8_compile(source); | 440 Local<Script> script = v8_compile(source); |
| 441 Local<Value> value = script->Run(); | 441 Local<Value> value = script->Run(); |
| 442 CHECK(value->IsNumber()); | 442 CHECK(value->IsNumber()); |
| 443 CHECK_EQ(7, value->Int32Value()); | 443 CHECK_EQ(7, value->Int32Value()); |
| 444 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 444 CcTest::heap()->CollectAllGarbage(); |
| 445 CHECK_EQ(0, dispose_count); | 445 CHECK_EQ(0, dispose_count); |
| 446 } | 446 } |
| 447 CcTest::i_isolate()->compilation_cache()->Clear(); | 447 CcTest::i_isolate()->compilation_cache()->Clear(); |
| 448 CcTest::heap()->CollectAllAvailableGarbage(); | 448 CcTest::heap()->CollectAllAvailableGarbage(); |
| 449 CHECK_EQ(1, dispose_count); | 449 CHECK_EQ(1, dispose_count); |
| 450 } | 450 } |
| 451 | 451 |
| 452 | 452 |
| 453 THREADED_TEST(ScriptMakingExternalString) { | 453 THREADED_TEST(ScriptMakingExternalString) { |
| 454 int dispose_count = 0; | 454 int dispose_count = 0; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 466 String::Encoding encoding = String::UNKNOWN_ENCODING; | 466 String::Encoding encoding = String::UNKNOWN_ENCODING; |
| 467 CHECK(!source->GetExternalStringResourceBase(&encoding)); | 467 CHECK(!source->GetExternalStringResourceBase(&encoding)); |
| 468 CHECK_EQ(String::ONE_BYTE_ENCODING, encoding); | 468 CHECK_EQ(String::ONE_BYTE_ENCODING, encoding); |
| 469 bool success = source->MakeExternal(new TestResource(two_byte_source, | 469 bool success = source->MakeExternal(new TestResource(two_byte_source, |
| 470 &dispose_count)); | 470 &dispose_count)); |
| 471 CHECK(success); | 471 CHECK(success); |
| 472 Local<Script> script = v8_compile(source); | 472 Local<Script> script = v8_compile(source); |
| 473 Local<Value> value = script->Run(); | 473 Local<Value> value = script->Run(); |
| 474 CHECK(value->IsNumber()); | 474 CHECK(value->IsNumber()); |
| 475 CHECK_EQ(7, value->Int32Value()); | 475 CHECK_EQ(7, value->Int32Value()); |
| 476 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 476 CcTest::heap()->CollectAllGarbage(); |
| 477 CHECK_EQ(0, dispose_count); | 477 CHECK_EQ(0, dispose_count); |
| 478 } | 478 } |
| 479 CcTest::i_isolate()->compilation_cache()->Clear(); | 479 CcTest::i_isolate()->compilation_cache()->Clear(); |
| 480 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 480 CcTest::heap()->CollectAllGarbage(); |
| 481 CHECK_EQ(1, dispose_count); | 481 CHECK_EQ(1, dispose_count); |
| 482 } | 482 } |
| 483 | 483 |
| 484 | 484 |
| 485 THREADED_TEST(ScriptMakingExternalOneByteString) { | 485 THREADED_TEST(ScriptMakingExternalOneByteString) { |
| 486 int dispose_count = 0; | 486 int dispose_count = 0; |
| 487 const char* c_source = "1 + 2 * 3"; | 487 const char* c_source = "1 + 2 * 3"; |
| 488 { | 488 { |
| 489 LocalContext env; | 489 LocalContext env; |
| 490 v8::HandleScope scope(env->GetIsolate()); | 490 v8::HandleScope scope(env->GetIsolate()); |
| 491 Local<String> source = v8_str(c_source); | 491 Local<String> source = v8_str(c_source); |
| 492 // Trigger GCs so that the newly allocated string moves to old gen. | 492 // Trigger GCs so that the newly allocated string moves to old gen. |
| 493 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 493 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now |
| 494 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 494 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now |
| 495 bool success = source->MakeExternal( | 495 bool success = source->MakeExternal( |
| 496 new TestOneByteResource(i::StrDup(c_source), &dispose_count)); | 496 new TestOneByteResource(i::StrDup(c_source), &dispose_count)); |
| 497 CHECK(success); | 497 CHECK(success); |
| 498 Local<Script> script = v8_compile(source); | 498 Local<Script> script = v8_compile(source); |
| 499 Local<Value> value = script->Run(); | 499 Local<Value> value = script->Run(); |
| 500 CHECK(value->IsNumber()); | 500 CHECK(value->IsNumber()); |
| 501 CHECK_EQ(7, value->Int32Value()); | 501 CHECK_EQ(7, value->Int32Value()); |
| 502 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 502 CcTest::heap()->CollectAllGarbage(); |
| 503 CHECK_EQ(0, dispose_count); | 503 CHECK_EQ(0, dispose_count); |
| 504 } | 504 } |
| 505 CcTest::i_isolate()->compilation_cache()->Clear(); | 505 CcTest::i_isolate()->compilation_cache()->Clear(); |
| 506 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 506 CcTest::heap()->CollectAllGarbage(); |
| 507 CHECK_EQ(1, dispose_count); | 507 CHECK_EQ(1, dispose_count); |
| 508 } | 508 } |
| 509 | 509 |
| 510 | 510 |
| 511 TEST(MakingExternalStringConditions) { | 511 TEST(MakingExternalStringConditions) { |
| 512 LocalContext env; | 512 LocalContext env; |
| 513 v8::HandleScope scope(env->GetIsolate()); | 513 v8::HandleScope scope(env->GetIsolate()); |
| 514 | 514 |
| 515 // Free some space in the new space so that we can check freshness. | 515 // Free some space in the new space so that we can check freshness. |
| 516 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 516 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 const char* c_cons = "_abcdefghijklmnopqrstuvwxyz"; | 615 const char* c_cons = "_abcdefghijklmnopqrstuvwxyz"; |
| 616 bool success = | 616 bool success = |
| 617 cons->MakeExternal(new TestOneByteResource(i::StrDup(c_cons), NULL, 1)); | 617 cons->MakeExternal(new TestOneByteResource(i::StrDup(c_cons), NULL, 1)); |
| 618 CHECK(success); | 618 CHECK(success); |
| 619 const char* c_slice = "_bcdefghijklmnopqrstuvwxyz"; | 619 const char* c_slice = "_bcdefghijklmnopqrstuvwxyz"; |
| 620 success = | 620 success = |
| 621 slice->MakeExternal(new TestOneByteResource(i::StrDup(c_slice), NULL, 1)); | 621 slice->MakeExternal(new TestOneByteResource(i::StrDup(c_slice), NULL, 1)); |
| 622 CHECK(success); | 622 CHECK(success); |
| 623 | 623 |
| 624 // Trigger GCs and force evacuation. | 624 // Trigger GCs and force evacuation. |
| 625 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 625 CcTest::heap()->CollectAllGarbage(); |
| 626 CcTest::heap()->CollectAllGarbage(i::Heap::kReduceMemoryFootprintMask); | 626 CcTest::heap()->CollectAllGarbage(i::Heap::kReduceMemoryFootprintMask); |
| 627 } | 627 } |
| 628 | 628 |
| 629 | 629 |
| 630 THREADED_TEST(UsingExternalString) { | 630 THREADED_TEST(UsingExternalString) { |
| 631 i::Factory* factory = CcTest::i_isolate()->factory(); | 631 i::Factory* factory = CcTest::i_isolate()->factory(); |
| 632 { | 632 { |
| 633 v8::HandleScope scope(CcTest::isolate()); | 633 v8::HandleScope scope(CcTest::isolate()); |
| 634 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); | 634 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); |
| 635 Local<String> string = String::NewExternal( | 635 Local<String> string = String::NewExternal( |
| 636 CcTest::isolate(), new TestResource(two_byte_string)); | 636 CcTest::isolate(), new TestResource(two_byte_string)); |
| 637 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 637 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
| 638 // Trigger GCs so that the newly allocated string moves to old gen. | 638 // Trigger GCs so that the newly allocated string moves to old gen. |
| 639 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 639 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now |
| 640 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 640 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now |
| 641 i::Handle<i::String> isymbol = | 641 i::Handle<i::String> isymbol = |
| 642 factory->InternalizeString(istring); | 642 factory->InternalizeString(istring); |
| 643 CHECK(isymbol->IsInternalizedString()); | 643 CHECK(isymbol->IsInternalizedString()); |
| 644 } | 644 } |
| 645 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 645 CcTest::heap()->CollectAllGarbage(); |
| 646 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 646 CcTest::heap()->CollectAllGarbage(); |
| 647 } | 647 } |
| 648 | 648 |
| 649 | 649 |
| 650 THREADED_TEST(UsingExternalOneByteString) { | 650 THREADED_TEST(UsingExternalOneByteString) { |
| 651 i::Factory* factory = CcTest::i_isolate()->factory(); | 651 i::Factory* factory = CcTest::i_isolate()->factory(); |
| 652 { | 652 { |
| 653 v8::HandleScope scope(CcTest::isolate()); | 653 v8::HandleScope scope(CcTest::isolate()); |
| 654 const char* one_byte_string = "test string"; | 654 const char* one_byte_string = "test string"; |
| 655 Local<String> string = String::NewExternal( | 655 Local<String> string = String::NewExternal( |
| 656 CcTest::isolate(), new TestOneByteResource(i::StrDup(one_byte_string))); | 656 CcTest::isolate(), new TestOneByteResource(i::StrDup(one_byte_string))); |
| 657 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 657 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
| 658 // Trigger GCs so that the newly allocated string moves to old gen. | 658 // Trigger GCs so that the newly allocated string moves to old gen. |
| 659 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 659 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now |
| 660 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 660 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now |
| 661 i::Handle<i::String> isymbol = | 661 i::Handle<i::String> isymbol = |
| 662 factory->InternalizeString(istring); | 662 factory->InternalizeString(istring); |
| 663 CHECK(isymbol->IsInternalizedString()); | 663 CHECK(isymbol->IsInternalizedString()); |
| 664 } | 664 } |
| 665 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 665 CcTest::heap()->CollectAllGarbage(); |
| 666 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 666 CcTest::heap()->CollectAllGarbage(); |
| 667 } | 667 } |
| 668 | 668 |
| 669 | 669 |
| 670 class RandomLengthResource : public v8::String::ExternalStringResource { | 670 class RandomLengthResource : public v8::String::ExternalStringResource { |
| 671 public: | 671 public: |
| 672 explicit RandomLengthResource(int length) : length_(length) {} | 672 explicit RandomLengthResource(int length) : length_(length) {} |
| 673 virtual const uint16_t* data() const { return string_; } | 673 virtual const uint16_t* data() const { return string_; } |
| 674 virtual size_t length() const { return length_; } | 674 virtual size_t length() const { return length_; } |
| 675 | 675 |
| 676 private: | 676 private: |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 right = String::NewExternal( | 863 right = String::NewExternal( |
| 864 env->GetIsolate(), | 864 env->GetIsolate(), |
| 865 new TestResource(AsciiToTwoByteString(two_byte_extern_2))); | 865 new TestResource(AsciiToTwoByteString(two_byte_extern_2))); |
| 866 source = String::Concat(source, right); | 866 source = String::Concat(source, right); |
| 867 Local<Script> script = v8_compile(source); | 867 Local<Script> script = v8_compile(source); |
| 868 Local<Value> value = script->Run(); | 868 Local<Value> value = script->Run(); |
| 869 CHECK(value->IsNumber()); | 869 CHECK(value->IsNumber()); |
| 870 CHECK_EQ(68, value->Int32Value()); | 870 CHECK_EQ(68, value->Int32Value()); |
| 871 } | 871 } |
| 872 CcTest::i_isolate()->compilation_cache()->Clear(); | 872 CcTest::i_isolate()->compilation_cache()->Clear(); |
| 873 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 873 CcTest::heap()->CollectAllGarbage(); |
| 874 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 874 CcTest::heap()->CollectAllGarbage(); |
| 875 } | 875 } |
| 876 | 876 |
| 877 | 877 |
| 878 THREADED_TEST(GlobalProperties) { | 878 THREADED_TEST(GlobalProperties) { |
| 879 LocalContext env; | 879 LocalContext env; |
| 880 v8::HandleScope scope(env->GetIsolate()); | 880 v8::HandleScope scope(env->GetIsolate()); |
| 881 v8::Handle<v8::Object> global = env->Global(); | 881 v8::Handle<v8::Object> global = env->Global(); |
| 882 global->Set(v8_str("pi"), v8_num(3.1415926)); | 882 global->Set(v8_str("pi"), v8_num(3.1415926)); |
| 883 Local<Value> pi = global->Get(v8_str("pi")); | 883 Local<Value> pi = global->Get(v8_str("pi")); |
| 884 CHECK_EQ(3.1415926, pi->NumberValue()); | 884 CHECK_EQ(3.1415926, pi->NumberValue()); |
| (...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2084 v8::Local<v8::Object> global = env->Global(); | 2084 v8::Local<v8::Object> global = env->Global(); |
| 2085 global->Set(0, v8::String::NewFromUtf8(CcTest::isolate(), "value")); | 2085 global->Set(0, v8::String::NewFromUtf8(CcTest::isolate(), "value")); |
| 2086 CHECK(global->HasRealIndexedProperty(0)); | 2086 CHECK(global->HasRealIndexedProperty(0)); |
| 2087 } | 2087 } |
| 2088 | 2088 |
| 2089 | 2089 |
| 2090 static void CheckAlignedPointerInInternalField(Handle<v8::Object> obj, | 2090 static void CheckAlignedPointerInInternalField(Handle<v8::Object> obj, |
| 2091 void* value) { | 2091 void* value) { |
| 2092 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); | 2092 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); |
| 2093 obj->SetAlignedPointerInInternalField(0, value); | 2093 obj->SetAlignedPointerInInternalField(0, value); |
| 2094 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 2094 CcTest::heap()->CollectAllGarbage(); |
| 2095 CHECK_EQ(value, obj->GetAlignedPointerFromInternalField(0)); | 2095 CHECK_EQ(value, obj->GetAlignedPointerFromInternalField(0)); |
| 2096 } | 2096 } |
| 2097 | 2097 |
| 2098 | 2098 |
| 2099 THREADED_TEST(InternalFieldsAlignedPointers) { | 2099 THREADED_TEST(InternalFieldsAlignedPointers) { |
| 2100 LocalContext env; | 2100 LocalContext env; |
| 2101 v8::Isolate* isolate = env->GetIsolate(); | 2101 v8::Isolate* isolate = env->GetIsolate(); |
| 2102 v8::HandleScope scope(isolate); | 2102 v8::HandleScope scope(isolate); |
| 2103 | 2103 |
| 2104 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); | 2104 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2122 v8::Global<v8::Object> persistent(isolate, obj); | 2122 v8::Global<v8::Object> persistent(isolate, obj); |
| 2123 CHECK_EQ(1, Object::InternalFieldCount(persistent)); | 2123 CHECK_EQ(1, Object::InternalFieldCount(persistent)); |
| 2124 CHECK_EQ(huge, Object::GetAlignedPointerFromInternalField(persistent, 0)); | 2124 CHECK_EQ(huge, Object::GetAlignedPointerFromInternalField(persistent, 0)); |
| 2125 } | 2125 } |
| 2126 | 2126 |
| 2127 | 2127 |
| 2128 static void CheckAlignedPointerInEmbedderData(LocalContext* env, int index, | 2128 static void CheckAlignedPointerInEmbedderData(LocalContext* env, int index, |
| 2129 void* value) { | 2129 void* value) { |
| 2130 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); | 2130 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); |
| 2131 (*env)->SetAlignedPointerInEmbedderData(index, value); | 2131 (*env)->SetAlignedPointerInEmbedderData(index, value); |
| 2132 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 2132 CcTest::heap()->CollectAllGarbage(); |
| 2133 CHECK_EQ(value, (*env)->GetAlignedPointerFromEmbedderData(index)); | 2133 CHECK_EQ(value, (*env)->GetAlignedPointerFromEmbedderData(index)); |
| 2134 } | 2134 } |
| 2135 | 2135 |
| 2136 | 2136 |
| 2137 static void* AlignedTestPointer(int i) { | 2137 static void* AlignedTestPointer(int i) { |
| 2138 return reinterpret_cast<void*>(i * 1234); | 2138 return reinterpret_cast<void*>(i * 1234); |
| 2139 } | 2139 } |
| 2140 | 2140 |
| 2141 | 2141 |
| 2142 THREADED_TEST(EmbedderDataAlignedPointers) { | 2142 THREADED_TEST(EmbedderDataAlignedPointers) { |
| 2143 LocalContext env; | 2143 LocalContext env; |
| 2144 v8::HandleScope scope(env->GetIsolate()); | 2144 v8::HandleScope scope(env->GetIsolate()); |
| 2145 | 2145 |
| 2146 CheckAlignedPointerInEmbedderData(&env, 0, NULL); | 2146 CheckAlignedPointerInEmbedderData(&env, 0, NULL); |
| 2147 | 2147 |
| 2148 int* heap_allocated = new int[100]; | 2148 int* heap_allocated = new int[100]; |
| 2149 CheckAlignedPointerInEmbedderData(&env, 1, heap_allocated); | 2149 CheckAlignedPointerInEmbedderData(&env, 1, heap_allocated); |
| 2150 delete[] heap_allocated; | 2150 delete[] heap_allocated; |
| 2151 | 2151 |
| 2152 int stack_allocated[100]; | 2152 int stack_allocated[100]; |
| 2153 CheckAlignedPointerInEmbedderData(&env, 2, stack_allocated); | 2153 CheckAlignedPointerInEmbedderData(&env, 2, stack_allocated); |
| 2154 | 2154 |
| 2155 void* huge = reinterpret_cast<void*>(~static_cast<uintptr_t>(1)); | 2155 void* huge = reinterpret_cast<void*>(~static_cast<uintptr_t>(1)); |
| 2156 CheckAlignedPointerInEmbedderData(&env, 3, huge); | 2156 CheckAlignedPointerInEmbedderData(&env, 3, huge); |
| 2157 | 2157 |
| 2158 // Test growing of the embedder data's backing store. | 2158 // Test growing of the embedder data's backing store. |
| 2159 for (int i = 0; i < 100; i++) { | 2159 for (int i = 0; i < 100; i++) { |
| 2160 env->SetAlignedPointerInEmbedderData(i, AlignedTestPointer(i)); | 2160 env->SetAlignedPointerInEmbedderData(i, AlignedTestPointer(i)); |
| 2161 } | 2161 } |
| 2162 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 2162 CcTest::heap()->CollectAllGarbage(); |
| 2163 for (int i = 0; i < 100; i++) { | 2163 for (int i = 0; i < 100; i++) { |
| 2164 CHECK_EQ(AlignedTestPointer(i), env->GetAlignedPointerFromEmbedderData(i)); | 2164 CHECK_EQ(AlignedTestPointer(i), env->GetAlignedPointerFromEmbedderData(i)); |
| 2165 } | 2165 } |
| 2166 } | 2166 } |
| 2167 | 2167 |
| 2168 | 2168 |
| 2169 static void CheckEmbedderData(LocalContext* env, int index, | 2169 static void CheckEmbedderData(LocalContext* env, int index, |
| 2170 v8::Handle<Value> data) { | 2170 v8::Handle<Value> data) { |
| 2171 (*env)->SetEmbedderData(index, data); | 2171 (*env)->SetEmbedderData(index, data); |
| 2172 CHECK((*env)->GetEmbedderData(index)->StrictEquals(data)); | 2172 CHECK((*env)->GetEmbedderData(index)->StrictEquals(data)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2197 } | 2197 } |
| 2198 | 2198 |
| 2199 | 2199 |
| 2200 THREADED_TEST(IdentityHash) { | 2200 THREADED_TEST(IdentityHash) { |
| 2201 LocalContext env; | 2201 LocalContext env; |
| 2202 v8::Isolate* isolate = env->GetIsolate(); | 2202 v8::Isolate* isolate = env->GetIsolate(); |
| 2203 v8::HandleScope scope(isolate); | 2203 v8::HandleScope scope(isolate); |
| 2204 | 2204 |
| 2205 // Ensure that the test starts with an fresh heap to test whether the hash | 2205 // Ensure that the test starts with an fresh heap to test whether the hash |
| 2206 // code is based on the address. | 2206 // code is based on the address. |
| 2207 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 2207 CcTest::heap()->CollectAllGarbage(); |
| 2208 Local<v8::Object> obj = v8::Object::New(isolate); | 2208 Local<v8::Object> obj = v8::Object::New(isolate); |
| 2209 int hash = obj->GetIdentityHash(); | 2209 int hash = obj->GetIdentityHash(); |
| 2210 int hash1 = obj->GetIdentityHash(); | 2210 int hash1 = obj->GetIdentityHash(); |
| 2211 CHECK_EQ(hash, hash1); | 2211 CHECK_EQ(hash, hash1); |
| 2212 int hash2 = v8::Object::New(isolate)->GetIdentityHash(); | 2212 int hash2 = v8::Object::New(isolate)->GetIdentityHash(); |
| 2213 // Since the identity hash is essentially a random number two consecutive | 2213 // Since the identity hash is essentially a random number two consecutive |
| 2214 // objects should not be assigned the same hash code. If the test below fails | 2214 // objects should not be assigned the same hash code. If the test below fails |
| 2215 // the random number generator should be evaluated. | 2215 // the random number generator should be evaluated. |
| 2216 CHECK_NE(hash, hash2); | 2216 CHECK_NE(hash, hash2); |
| 2217 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 2217 CcTest::heap()->CollectAllGarbage(); |
| 2218 int hash3 = v8::Object::New(isolate)->GetIdentityHash(); | 2218 int hash3 = v8::Object::New(isolate)->GetIdentityHash(); |
| 2219 // Make sure that the identity hash is not based on the initial address of | 2219 // Make sure that the identity hash is not based on the initial address of |
| 2220 // the object alone. If the test below fails the random number generator | 2220 // the object alone. If the test below fails the random number generator |
| 2221 // should be evaluated. | 2221 // should be evaluated. |
| 2222 CHECK_NE(hash, hash3); | 2222 CHECK_NE(hash, hash3); |
| 2223 int hash4 = obj->GetIdentityHash(); | 2223 int hash4 = obj->GetIdentityHash(); |
| 2224 CHECK_EQ(hash, hash4); | 2224 CHECK_EQ(hash, hash4); |
| 2225 | 2225 |
| 2226 // Check identity hashes behaviour in the presence of JS accessors. | 2226 // Check identity hashes behaviour in the presence of JS accessors. |
| 2227 // Put a getter for 'v8::IdentityHash' on the Object's prototype: | 2227 // Put a getter for 'v8::IdentityHash' on the Object's prototype: |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2264 TEST(SymbolIdentityHash) { | 2264 TEST(SymbolIdentityHash) { |
| 2265 LocalContext env; | 2265 LocalContext env; |
| 2266 v8::Isolate* isolate = env->GetIsolate(); | 2266 v8::Isolate* isolate = env->GetIsolate(); |
| 2267 v8::HandleScope scope(isolate); | 2267 v8::HandleScope scope(isolate); |
| 2268 | 2268 |
| 2269 { | 2269 { |
| 2270 Local<v8::Symbol> symbol = v8::Symbol::New(isolate); | 2270 Local<v8::Symbol> symbol = v8::Symbol::New(isolate); |
| 2271 int hash = symbol->GetIdentityHash(); | 2271 int hash = symbol->GetIdentityHash(); |
| 2272 int hash1 = symbol->GetIdentityHash(); | 2272 int hash1 = symbol->GetIdentityHash(); |
| 2273 CHECK_EQ(hash, hash1); | 2273 CHECK_EQ(hash, hash1); |
| 2274 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 2274 CcTest::heap()->CollectAllGarbage(); |
| 2275 int hash3 = symbol->GetIdentityHash(); | 2275 int hash3 = symbol->GetIdentityHash(); |
| 2276 CHECK_EQ(hash, hash3); | 2276 CHECK_EQ(hash, hash3); |
| 2277 } | 2277 } |
| 2278 | 2278 |
| 2279 { | 2279 { |
| 2280 v8::Handle<v8::Symbol> js_symbol = | 2280 v8::Handle<v8::Symbol> js_symbol = |
| 2281 CompileRun("Symbol('foo')").As<v8::Symbol>(); | 2281 CompileRun("Symbol('foo')").As<v8::Symbol>(); |
| 2282 int hash = js_symbol->GetIdentityHash(); | 2282 int hash = js_symbol->GetIdentityHash(); |
| 2283 int hash1 = js_symbol->GetIdentityHash(); | 2283 int hash1 = js_symbol->GetIdentityHash(); |
| 2284 CHECK_EQ(hash, hash1); | 2284 CHECK_EQ(hash, hash1); |
| 2285 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 2285 CcTest::heap()->CollectAllGarbage(); |
| 2286 int hash3 = js_symbol->GetIdentityHash(); | 2286 int hash3 = js_symbol->GetIdentityHash(); |
| 2287 CHECK_EQ(hash, hash3); | 2287 CHECK_EQ(hash, hash3); |
| 2288 } | 2288 } |
| 2289 } | 2289 } |
| 2290 | 2290 |
| 2291 | 2291 |
| 2292 TEST(StringIdentityHash) { | 2292 TEST(StringIdentityHash) { |
| 2293 LocalContext env; | 2293 LocalContext env; |
| 2294 v8::Isolate* isolate = env->GetIsolate(); | 2294 v8::Isolate* isolate = env->GetIsolate(); |
| 2295 v8::HandleScope scope(isolate); | 2295 v8::HandleScope scope(isolate); |
| 2296 | 2296 |
| 2297 Local<v8::String> str = v8::String::NewFromUtf8(isolate, "str1"); | 2297 Local<v8::String> str = v8::String::NewFromUtf8(isolate, "str1"); |
| 2298 int hash = str->GetIdentityHash(); | 2298 int hash = str->GetIdentityHash(); |
| 2299 int hash1 = str->GetIdentityHash(); | 2299 int hash1 = str->GetIdentityHash(); |
| 2300 CHECK_EQ(hash, hash1); | 2300 CHECK_EQ(hash, hash1); |
| 2301 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 2301 CcTest::heap()->CollectAllGarbage(); |
| 2302 int hash3 = str->GetIdentityHash(); | 2302 int hash3 = str->GetIdentityHash(); |
| 2303 CHECK_EQ(hash, hash3); | 2303 CHECK_EQ(hash, hash3); |
| 2304 | 2304 |
| 2305 Local<v8::String> str2 = v8::String::NewFromUtf8(isolate, "str1"); | 2305 Local<v8::String> str2 = v8::String::NewFromUtf8(isolate, "str1"); |
| 2306 int hash4 = str2->GetIdentityHash(); | 2306 int hash4 = str2->GetIdentityHash(); |
| 2307 CHECK_EQ(hash, hash4); | 2307 CHECK_EQ(hash, hash4); |
| 2308 } | 2308 } |
| 2309 | 2309 |
| 2310 | 2310 |
| 2311 THREADED_TEST(SymbolProperties) { | 2311 THREADED_TEST(SymbolProperties) { |
| 2312 LocalContext env; | 2312 LocalContext env; |
| 2313 v8::Isolate* isolate = env->GetIsolate(); | 2313 v8::Isolate* isolate = env->GetIsolate(); |
| 2314 v8::HandleScope scope(isolate); | 2314 v8::HandleScope scope(isolate); |
| 2315 | 2315 |
| 2316 v8::Local<v8::Object> obj = v8::Object::New(isolate); | 2316 v8::Local<v8::Object> obj = v8::Object::New(isolate); |
| 2317 v8::Local<v8::Symbol> sym1 = v8::Symbol::New(isolate); | 2317 v8::Local<v8::Symbol> sym1 = v8::Symbol::New(isolate); |
| 2318 v8::Local<v8::Symbol> sym2 = v8::Symbol::New(isolate, v8_str("my-symbol")); | 2318 v8::Local<v8::Symbol> sym2 = v8::Symbol::New(isolate, v8_str("my-symbol")); |
| 2319 v8::Local<v8::Symbol> sym3 = v8::Symbol::New(isolate, v8_str("sym3")); | 2319 v8::Local<v8::Symbol> sym3 = v8::Symbol::New(isolate, v8_str("sym3")); |
| 2320 | 2320 |
| 2321 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 2321 CcTest::heap()->CollectAllGarbage(); |
| 2322 | 2322 |
| 2323 // Check basic symbol functionality. | 2323 // Check basic symbol functionality. |
| 2324 CHECK(sym1->IsSymbol()); | 2324 CHECK(sym1->IsSymbol()); |
| 2325 CHECK(sym2->IsSymbol()); | 2325 CHECK(sym2->IsSymbol()); |
| 2326 CHECK(!obj->IsSymbol()); | 2326 CHECK(!obj->IsSymbol()); |
| 2327 | 2327 |
| 2328 CHECK(sym1->Equals(sym1)); | 2328 CHECK(sym1->Equals(sym1)); |
| 2329 CHECK(sym2->Equals(sym2)); | 2329 CHECK(sym2->Equals(sym2)); |
| 2330 CHECK(!sym1->Equals(sym2)); | 2330 CHECK(!sym1->Equals(sym2)); |
| 2331 CHECK(!sym2->Equals(sym1)); | 2331 CHECK(!sym2->Equals(sym1)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2363 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); | 2363 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); |
| 2364 CHECK_EQ(v8::None, obj->GetPropertyAttributes(sym1)); | 2364 CHECK_EQ(v8::None, obj->GetPropertyAttributes(sym1)); |
| 2365 | 2365 |
| 2366 CHECK_EQ(0u, obj->GetOwnPropertyNames()->Length()); | 2366 CHECK_EQ(0u, obj->GetOwnPropertyNames()->Length()); |
| 2367 unsigned num_props = obj->GetPropertyNames()->Length(); | 2367 unsigned num_props = obj->GetPropertyNames()->Length(); |
| 2368 CHECK(obj->Set(v8::String::NewFromUtf8(isolate, "bla"), | 2368 CHECK(obj->Set(v8::String::NewFromUtf8(isolate, "bla"), |
| 2369 v8::Integer::New(isolate, 20))); | 2369 v8::Integer::New(isolate, 20))); |
| 2370 CHECK_EQ(1u, obj->GetOwnPropertyNames()->Length()); | 2370 CHECK_EQ(1u, obj->GetOwnPropertyNames()->Length()); |
| 2371 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length()); | 2371 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length()); |
| 2372 | 2372 |
| 2373 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 2373 CcTest::heap()->CollectAllGarbage(); |
| 2374 | 2374 |
| 2375 CHECK(obj->SetAccessor(sym3, SymbolAccessorGetter, SymbolAccessorSetter)); | 2375 CHECK(obj->SetAccessor(sym3, SymbolAccessorGetter, SymbolAccessorSetter)); |
| 2376 CHECK(obj->Get(sym3)->IsUndefined()); | 2376 CHECK(obj->Get(sym3)->IsUndefined()); |
| 2377 CHECK(obj->Set(sym3, v8::Integer::New(isolate, 42))); | 2377 CHECK(obj->Set(sym3, v8::Integer::New(isolate, 42))); |
| 2378 CHECK(obj->Get(sym3)->Equals(v8::Integer::New(isolate, 42))); | 2378 CHECK(obj->Get(sym3)->Equals(v8::Integer::New(isolate, 42))); |
| 2379 CHECK(obj->Get(v8::String::NewFromUtf8(isolate, "accessor_sym3")) | 2379 CHECK(obj->Get(v8::String::NewFromUtf8(isolate, "accessor_sym3")) |
| 2380 ->Equals(v8::Integer::New(isolate, 42))); | 2380 ->Equals(v8::Integer::New(isolate, 42))); |
| 2381 | 2381 |
| 2382 // Add another property and delete it afterwards to force the object in | 2382 // Add another property and delete it afterwards to force the object in |
| 2383 // slow case. | 2383 // slow case. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2431 THREADED_TEST(PrivateProperties) { | 2431 THREADED_TEST(PrivateProperties) { |
| 2432 LocalContext env; | 2432 LocalContext env; |
| 2433 v8::Isolate* isolate = env->GetIsolate(); | 2433 v8::Isolate* isolate = env->GetIsolate(); |
| 2434 v8::HandleScope scope(isolate); | 2434 v8::HandleScope scope(isolate); |
| 2435 | 2435 |
| 2436 v8::Local<v8::Object> obj = v8::Object::New(isolate); | 2436 v8::Local<v8::Object> obj = v8::Object::New(isolate); |
| 2437 v8::Local<v8::Private> priv1 = v8::Private::New(isolate); | 2437 v8::Local<v8::Private> priv1 = v8::Private::New(isolate); |
| 2438 v8::Local<v8::Private> priv2 = | 2438 v8::Local<v8::Private> priv2 = |
| 2439 v8::Private::New(isolate, v8_str("my-private")); | 2439 v8::Private::New(isolate, v8_str("my-private")); |
| 2440 | 2440 |
| 2441 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 2441 CcTest::heap()->CollectAllGarbage(); |
| 2442 | 2442 |
| 2443 CHECK(priv2->Name()->Equals(v8::String::NewFromUtf8(isolate, "my-private"))); | 2443 CHECK(priv2->Name()->Equals(v8::String::NewFromUtf8(isolate, "my-private"))); |
| 2444 | 2444 |
| 2445 // Make sure delete of a non-existent private symbol property works. | 2445 // Make sure delete of a non-existent private symbol property works. |
| 2446 CHECK(obj->DeletePrivate(priv1)); | 2446 CHECK(obj->DeletePrivate(priv1)); |
| 2447 CHECK(!obj->HasPrivate(priv1)); | 2447 CHECK(!obj->HasPrivate(priv1)); |
| 2448 | 2448 |
| 2449 CHECK(obj->SetPrivate(priv1, v8::Integer::New(isolate, 1503))); | 2449 CHECK(obj->SetPrivate(priv1, v8::Integer::New(isolate, 1503))); |
| 2450 CHECK(obj->HasPrivate(priv1)); | 2450 CHECK(obj->HasPrivate(priv1)); |
| 2451 CHECK_EQ(1503, obj->GetPrivate(priv1)->Int32Value()); | 2451 CHECK_EQ(1503, obj->GetPrivate(priv1)->Int32Value()); |
| 2452 CHECK(obj->SetPrivate(priv1, v8::Integer::New(isolate, 2002))); | 2452 CHECK(obj->SetPrivate(priv1, v8::Integer::New(isolate, 2002))); |
| 2453 CHECK(obj->HasPrivate(priv1)); | 2453 CHECK(obj->HasPrivate(priv1)); |
| 2454 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value()); | 2454 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value()); |
| 2455 | 2455 |
| 2456 CHECK_EQ(0u, obj->GetOwnPropertyNames()->Length()); | 2456 CHECK_EQ(0u, obj->GetOwnPropertyNames()->Length()); |
| 2457 unsigned num_props = obj->GetPropertyNames()->Length(); | 2457 unsigned num_props = obj->GetPropertyNames()->Length(); |
| 2458 CHECK(obj->Set(v8::String::NewFromUtf8(isolate, "bla"), | 2458 CHECK(obj->Set(v8::String::NewFromUtf8(isolate, "bla"), |
| 2459 v8::Integer::New(isolate, 20))); | 2459 v8::Integer::New(isolate, 20))); |
| 2460 CHECK_EQ(1u, obj->GetOwnPropertyNames()->Length()); | 2460 CHECK_EQ(1u, obj->GetOwnPropertyNames()->Length()); |
| 2461 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length()); | 2461 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length()); |
| 2462 | 2462 |
| 2463 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 2463 CcTest::heap()->CollectAllGarbage(); |
| 2464 | 2464 |
| 2465 // Add another property and delete it afterwards to force the object in | 2465 // Add another property and delete it afterwards to force the object in |
| 2466 // slow case. | 2466 // slow case. |
| 2467 CHECK(obj->SetPrivate(priv2, v8::Integer::New(isolate, 2008))); | 2467 CHECK(obj->SetPrivate(priv2, v8::Integer::New(isolate, 2008))); |
| 2468 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value()); | 2468 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value()); |
| 2469 CHECK_EQ(2008, obj->GetPrivate(priv2)->Int32Value()); | 2469 CHECK_EQ(2008, obj->GetPrivate(priv2)->Int32Value()); |
| 2470 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value()); | 2470 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value()); |
| 2471 CHECK_EQ(1u, obj->GetOwnPropertyNames()->Length()); | 2471 CHECK_EQ(1u, obj->GetOwnPropertyNames()->Length()); |
| 2472 | 2472 |
| 2473 CHECK(obj->HasPrivate(priv1)); | 2473 CHECK(obj->HasPrivate(priv1)); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2580 | 2580 |
| 2581 THREADED_TEST(ArrayBuffer_ApiInternalToExternal) { | 2581 THREADED_TEST(ArrayBuffer_ApiInternalToExternal) { |
| 2582 LocalContext env; | 2582 LocalContext env; |
| 2583 v8::Isolate* isolate = env->GetIsolate(); | 2583 v8::Isolate* isolate = env->GetIsolate(); |
| 2584 v8::HandleScope handle_scope(isolate); | 2584 v8::HandleScope handle_scope(isolate); |
| 2585 | 2585 |
| 2586 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, 1024); | 2586 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, 1024); |
| 2587 CheckInternalFieldsAreZero(ab); | 2587 CheckInternalFieldsAreZero(ab); |
| 2588 CHECK_EQ(1024, static_cast<int>(ab->ByteLength())); | 2588 CHECK_EQ(1024, static_cast<int>(ab->ByteLength())); |
| 2589 CHECK(!ab->IsExternal()); | 2589 CHECK(!ab->IsExternal()); |
| 2590 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 2590 CcTest::heap()->CollectAllGarbage(); |
| 2591 | 2591 |
| 2592 ScopedArrayBufferContents ab_contents(ab->Externalize()); | 2592 ScopedArrayBufferContents ab_contents(ab->Externalize()); |
| 2593 CHECK(ab->IsExternal()); | 2593 CHECK(ab->IsExternal()); |
| 2594 | 2594 |
| 2595 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength())); | 2595 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength())); |
| 2596 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data()); | 2596 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data()); |
| 2597 DCHECK(data != NULL); | 2597 DCHECK(data != NULL); |
| 2598 env->Global()->Set(v8_str("ab"), ab); | 2598 env->Global()->Set(v8_str("ab"), ab); |
| 2599 | 2599 |
| 2600 v8::Handle<v8::Value> result = CompileRun("ab.byteLength"); | 2600 v8::Handle<v8::Value> result = CompileRun("ab.byteLength"); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2843 THREADED_TEST(HiddenProperties) { | 2843 THREADED_TEST(HiddenProperties) { |
| 2844 LocalContext env; | 2844 LocalContext env; |
| 2845 v8::Isolate* isolate = env->GetIsolate(); | 2845 v8::Isolate* isolate = env->GetIsolate(); |
| 2846 v8::HandleScope scope(isolate); | 2846 v8::HandleScope scope(isolate); |
| 2847 | 2847 |
| 2848 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate()); | 2848 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate()); |
| 2849 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); | 2849 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); |
| 2850 v8::Local<v8::String> empty = v8_str(""); | 2850 v8::Local<v8::String> empty = v8_str(""); |
| 2851 v8::Local<v8::String> prop_name = v8_str("prop_name"); | 2851 v8::Local<v8::String> prop_name = v8_str("prop_name"); |
| 2852 | 2852 |
| 2853 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 2853 CcTest::heap()->CollectAllGarbage(); |
| 2854 | 2854 |
| 2855 // Make sure delete of a non-existent hidden value works | 2855 // Make sure delete of a non-existent hidden value works |
| 2856 CHECK(obj->DeleteHiddenValue(key)); | 2856 CHECK(obj->DeleteHiddenValue(key)); |
| 2857 | 2857 |
| 2858 CHECK(obj->SetHiddenValue(key, v8::Integer::New(isolate, 1503))); | 2858 CHECK(obj->SetHiddenValue(key, v8::Integer::New(isolate, 1503))); |
| 2859 CHECK_EQ(1503, obj->GetHiddenValue(key)->Int32Value()); | 2859 CHECK_EQ(1503, obj->GetHiddenValue(key)->Int32Value()); |
| 2860 CHECK(obj->SetHiddenValue(key, v8::Integer::New(isolate, 2002))); | 2860 CHECK(obj->SetHiddenValue(key, v8::Integer::New(isolate, 2002))); |
| 2861 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); | 2861 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); |
| 2862 | 2862 |
| 2863 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 2863 CcTest::heap()->CollectAllGarbage(); |
| 2864 | 2864 |
| 2865 // Make sure we do not find the hidden property. | 2865 // Make sure we do not find the hidden property. |
| 2866 CHECK(!obj->Has(empty)); | 2866 CHECK(!obj->Has(empty)); |
| 2867 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); | 2867 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); |
| 2868 CHECK(obj->Get(empty)->IsUndefined()); | 2868 CHECK(obj->Get(empty)->IsUndefined()); |
| 2869 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); | 2869 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); |
| 2870 CHECK(obj->Set(empty, v8::Integer::New(isolate, 2003))); | 2870 CHECK(obj->Set(empty, v8::Integer::New(isolate, 2003))); |
| 2871 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); | 2871 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); |
| 2872 CHECK_EQ(2003, obj->Get(empty)->Int32Value()); | 2872 CHECK_EQ(2003, obj->Get(empty)->Int32Value()); |
| 2873 | 2873 |
| 2874 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 2874 CcTest::heap()->CollectAllGarbage(); |
| 2875 | 2875 |
| 2876 // Add another property and delete it afterwards to force the object in | 2876 // Add another property and delete it afterwards to force the object in |
| 2877 // slow case. | 2877 // slow case. |
| 2878 CHECK(obj->Set(prop_name, v8::Integer::New(isolate, 2008))); | 2878 CHECK(obj->Set(prop_name, v8::Integer::New(isolate, 2008))); |
| 2879 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); | 2879 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); |
| 2880 CHECK_EQ(2008, obj->Get(prop_name)->Int32Value()); | 2880 CHECK_EQ(2008, obj->Get(prop_name)->Int32Value()); |
| 2881 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); | 2881 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); |
| 2882 CHECK(obj->Delete(prop_name)); | 2882 CHECK(obj->Delete(prop_name)); |
| 2883 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); | 2883 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); |
| 2884 | 2884 |
| 2885 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 2885 CcTest::heap()->CollectAllGarbage(); |
| 2886 | 2886 |
| 2887 CHECK(obj->SetHiddenValue(key, Handle<Value>())); | 2887 CHECK(obj->SetHiddenValue(key, Handle<Value>())); |
| 2888 CHECK(obj->GetHiddenValue(key).IsEmpty()); | 2888 CHECK(obj->GetHiddenValue(key).IsEmpty()); |
| 2889 | 2889 |
| 2890 CHECK(obj->SetHiddenValue(key, v8::Integer::New(isolate, 2002))); | 2890 CHECK(obj->SetHiddenValue(key, v8::Integer::New(isolate, 2002))); |
| 2891 CHECK(obj->DeleteHiddenValue(key)); | 2891 CHECK(obj->DeleteHiddenValue(key)); |
| 2892 CHECK(obj->GetHiddenValue(key).IsEmpty()); | 2892 CHECK(obj->GetHiddenValue(key).IsEmpty()); |
| 2893 } | 2893 } |
| 2894 | 2894 |
| 2895 | 2895 |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3162 | 3162 |
| 3163 | 3163 |
| 3164 void SecondPassCallback(const v8::WeakCallbackInfo<TwoPassCallbackData>& data) { | 3164 void SecondPassCallback(const v8::WeakCallbackInfo<TwoPassCallbackData>& data) { |
| 3165 ApiTestFuzzer::Fuzz(); | 3165 ApiTestFuzzer::Fuzz(); |
| 3166 bool trigger_gc = data.GetParameter()->trigger_gc(); | 3166 bool trigger_gc = data.GetParameter()->trigger_gc(); |
| 3167 int* instance_counter = data.GetParameter()->instance_counter(); | 3167 int* instance_counter = data.GetParameter()->instance_counter(); |
| 3168 data.GetParameter()->SecondPass(); | 3168 data.GetParameter()->SecondPass(); |
| 3169 if (!trigger_gc) return; | 3169 if (!trigger_gc) return; |
| 3170 auto data_2 = new TwoPassCallbackData(data.GetIsolate(), instance_counter); | 3170 auto data_2 = new TwoPassCallbackData(data.GetIsolate(), instance_counter); |
| 3171 data_2->SetWeak(); | 3171 data_2->SetWeak(); |
| 3172 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3172 CcTest::heap()->CollectAllGarbage(); |
| 3173 } | 3173 } |
| 3174 | 3174 |
| 3175 | 3175 |
| 3176 void FirstPassCallback(const v8::WeakCallbackInfo<TwoPassCallbackData>& data) { | 3176 void FirstPassCallback(const v8::WeakCallbackInfo<TwoPassCallbackData>& data) { |
| 3177 data.GetParameter()->FirstPass(); | 3177 data.GetParameter()->FirstPass(); |
| 3178 data.SetSecondPassCallback(SecondPassCallback); | 3178 data.SetSecondPassCallback(SecondPassCallback); |
| 3179 } | 3179 } |
| 3180 | 3180 |
| 3181 } // namespace | 3181 } // namespace |
| 3182 | 3182 |
| 3183 | 3183 |
| 3184 TEST(TwoPassPhantomCallbacks) { | 3184 TEST(TwoPassPhantomCallbacks) { |
| 3185 auto isolate = CcTest::isolate(); | 3185 auto isolate = CcTest::isolate(); |
| 3186 const size_t kLength = 20; | 3186 const size_t kLength = 20; |
| 3187 int instance_counter = 0; | 3187 int instance_counter = 0; |
| 3188 for (size_t i = 0; i < kLength; ++i) { | 3188 for (size_t i = 0; i < kLength; ++i) { |
| 3189 auto data = new TwoPassCallbackData(isolate, &instance_counter); | 3189 auto data = new TwoPassCallbackData(isolate, &instance_counter); |
| 3190 data->SetWeak(); | 3190 data->SetWeak(); |
| 3191 } | 3191 } |
| 3192 CHECK_EQ(static_cast<int>(kLength), instance_counter); | 3192 CHECK_EQ(static_cast<int>(kLength), instance_counter); |
| 3193 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3193 CcTest::heap()->CollectAllGarbage(); |
| 3194 CHECK_EQ(0, instance_counter); | 3194 CHECK_EQ(0, instance_counter); |
| 3195 } | 3195 } |
| 3196 | 3196 |
| 3197 | 3197 |
| 3198 TEST(TwoPassPhantomCallbacksNestedGc) { | 3198 TEST(TwoPassPhantomCallbacksNestedGc) { |
| 3199 auto isolate = CcTest::isolate(); | 3199 auto isolate = CcTest::isolate(); |
| 3200 const size_t kLength = 20; | 3200 const size_t kLength = 20; |
| 3201 TwoPassCallbackData* array[kLength]; | 3201 TwoPassCallbackData* array[kLength]; |
| 3202 int instance_counter = 0; | 3202 int instance_counter = 0; |
| 3203 for (size_t i = 0; i < kLength; ++i) { | 3203 for (size_t i = 0; i < kLength; ++i) { |
| 3204 array[i] = new TwoPassCallbackData(isolate, &instance_counter); | 3204 array[i] = new TwoPassCallbackData(isolate, &instance_counter); |
| 3205 array[i]->SetWeak(); | 3205 array[i]->SetWeak(); |
| 3206 } | 3206 } |
| 3207 array[5]->MarkTriggerGc(); | 3207 array[5]->MarkTriggerGc(); |
| 3208 array[10]->MarkTriggerGc(); | 3208 array[10]->MarkTriggerGc(); |
| 3209 array[15]->MarkTriggerGc(); | 3209 array[15]->MarkTriggerGc(); |
| 3210 CHECK_EQ(static_cast<int>(kLength), instance_counter); | 3210 CHECK_EQ(static_cast<int>(kLength), instance_counter); |
| 3211 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3211 CcTest::heap()->CollectAllGarbage(); |
| 3212 CHECK_EQ(0, instance_counter); | 3212 CHECK_EQ(0, instance_counter); |
| 3213 } | 3213 } |
| 3214 | 3214 |
| 3215 | 3215 |
| 3216 template <typename K, typename V> | 3216 template <typename K, typename V> |
| 3217 class WeakStdMapTraits : public v8::StdMapTraits<K, V> { | 3217 class WeakStdMapTraits : public v8::StdMapTraits<K, V> { |
| 3218 public: | 3218 public: |
| 3219 typedef typename v8::PersistentValueMap<K, V, WeakStdMapTraits<K, V>> MapType; | 3219 typedef typename v8::PersistentValueMap<K, V, WeakStdMapTraits<K, V>> MapType; |
| 3220 static const v8::PersistentContainerCallbackType kCallbackType = v8::kWeak; | 3220 static const v8::PersistentContainerCallbackType kCallbackType = v8::kWeak; |
| 3221 struct WeakCallbackDataType { | 3221 struct WeakCallbackDataType { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3279 removed = map.Set(8, v8::Global<v8::Object>(isolate, expected2), &ref); | 3279 removed = map.Set(8, v8::Global<v8::Object>(isolate, expected2), &ref); |
| 3280 CHECK_EQ(1, static_cast<int>(map.Size())); | 3280 CHECK_EQ(1, static_cast<int>(map.Size())); |
| 3281 CHECK(expected == removed); | 3281 CHECK(expected == removed); |
| 3282 CHECK(expected2->Equals(ref.NewLocal(isolate))); | 3282 CHECK(expected2->Equals(ref.NewLocal(isolate))); |
| 3283 } | 3283 } |
| 3284 } | 3284 } |
| 3285 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count()); | 3285 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count()); |
| 3286 if (map.IsWeak()) { | 3286 if (map.IsWeak()) { |
| 3287 reinterpret_cast<v8::internal::Isolate*>(isolate) | 3287 reinterpret_cast<v8::internal::Isolate*>(isolate) |
| 3288 ->heap() | 3288 ->heap() |
| 3289 ->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3289 ->CollectAllGarbage(); |
| 3290 } else { | 3290 } else { |
| 3291 map.Clear(); | 3291 map.Clear(); |
| 3292 } | 3292 } |
| 3293 CHECK_EQ(0, static_cast<int>(map.Size())); | 3293 CHECK_EQ(0, static_cast<int>(map.Size())); |
| 3294 CHECK_EQ(initial_handle_count, global_handles->global_handles_count()); | 3294 CHECK_EQ(initial_handle_count, global_handles->global_handles_count()); |
| 3295 } | 3295 } |
| 3296 | 3296 |
| 3297 | 3297 |
| 3298 TEST(PersistentValueMap) { | 3298 TEST(PersistentValueMap) { |
| 3299 // Default case, w/o weak callbacks: | 3299 // Default case, w/o weak callbacks: |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3615 iso->SetObjectGroupId(g1s1.handle, id1); | 3615 iso->SetObjectGroupId(g1s1.handle, id1); |
| 3616 iso->SetObjectGroupId(g1s2.handle, id1); | 3616 iso->SetObjectGroupId(g1s2.handle, id1); |
| 3617 iso->SetReferenceFromGroup(id1, g1c1.handle); | 3617 iso->SetReferenceFromGroup(id1, g1c1.handle); |
| 3618 iso->SetObjectGroupId(g2s1.handle, id2); | 3618 iso->SetObjectGroupId(g2s1.handle, id2); |
| 3619 iso->SetObjectGroupId(g2s2.handle, id2); | 3619 iso->SetObjectGroupId(g2s2.handle, id2); |
| 3620 iso->SetReferenceFromGroup(id2, g2c1.handle); | 3620 iso->SetReferenceFromGroup(id2, g2c1.handle); |
| 3621 } | 3621 } |
| 3622 // Do a single full GC, ensure incremental marking is stopped. | 3622 // Do a single full GC, ensure incremental marking is stopped. |
| 3623 v8::internal::Heap* heap = | 3623 v8::internal::Heap* heap = |
| 3624 reinterpret_cast<v8::internal::Isolate*>(iso)->heap(); | 3624 reinterpret_cast<v8::internal::Isolate*>(iso)->heap(); |
| 3625 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3625 heap->CollectAllGarbage(); |
| 3626 | 3626 |
| 3627 // All object should be alive. | 3627 // All object should be alive. |
| 3628 CHECK_EQ(0, counter.NumberOfWeakCalls()); | 3628 CHECK_EQ(0, counter.NumberOfWeakCalls()); |
| 3629 | 3629 |
| 3630 // Weaken the root. | 3630 // Weaken the root. |
| 3631 root.handle.SetWeak(&root, &WeakPointerCallback); | 3631 root.handle.SetWeak(&root, &WeakPointerCallback); |
| 3632 // But make children strong roots---all the objects (except for children) | 3632 // But make children strong roots---all the objects (except for children) |
| 3633 // should be collectable now. | 3633 // should be collectable now. |
| 3634 g1c1.handle.ClearWeak(); | 3634 g1c1.handle.ClearWeak(); |
| 3635 g2c1.handle.ClearWeak(); | 3635 g2c1.handle.ClearWeak(); |
| 3636 | 3636 |
| 3637 // Groups are deleted, rebuild groups. | 3637 // Groups are deleted, rebuild groups. |
| 3638 { | 3638 { |
| 3639 UniqueId id1 = MakeUniqueId(g1s1.handle); | 3639 UniqueId id1 = MakeUniqueId(g1s1.handle); |
| 3640 UniqueId id2 = MakeUniqueId(g2s2.handle); | 3640 UniqueId id2 = MakeUniqueId(g2s2.handle); |
| 3641 iso->SetObjectGroupId(g1s1.handle, id1); | 3641 iso->SetObjectGroupId(g1s1.handle, id1); |
| 3642 iso->SetObjectGroupId(g1s2.handle, id1); | 3642 iso->SetObjectGroupId(g1s2.handle, id1); |
| 3643 iso->SetReferenceFromGroup(id1, g1c1.handle); | 3643 iso->SetReferenceFromGroup(id1, g1c1.handle); |
| 3644 iso->SetObjectGroupId(g2s1.handle, id2); | 3644 iso->SetObjectGroupId(g2s1.handle, id2); |
| 3645 iso->SetObjectGroupId(g2s2.handle, id2); | 3645 iso->SetObjectGroupId(g2s2.handle, id2); |
| 3646 iso->SetReferenceFromGroup(id2, g2c1.handle); | 3646 iso->SetReferenceFromGroup(id2, g2c1.handle); |
| 3647 } | 3647 } |
| 3648 | 3648 |
| 3649 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3649 heap->CollectAllGarbage(); |
| 3650 | 3650 |
| 3651 // All objects should be gone. 5 global handles in total. | 3651 // All objects should be gone. 5 global handles in total. |
| 3652 CHECK_EQ(5, counter.NumberOfWeakCalls()); | 3652 CHECK_EQ(5, counter.NumberOfWeakCalls()); |
| 3653 | 3653 |
| 3654 // And now make children weak again and collect them. | 3654 // And now make children weak again and collect them. |
| 3655 g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback); | 3655 g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback); |
| 3656 g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback); | 3656 g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback); |
| 3657 | 3657 |
| 3658 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3658 heap->CollectAllGarbage(); |
| 3659 CHECK_EQ(7, counter.NumberOfWeakCalls()); | 3659 CHECK_EQ(7, counter.NumberOfWeakCalls()); |
| 3660 } | 3660 } |
| 3661 | 3661 |
| 3662 | 3662 |
| 3663 THREADED_TEST(ApiObjectGroupsForSubtypes) { | 3663 THREADED_TEST(ApiObjectGroupsForSubtypes) { |
| 3664 LocalContext env; | 3664 LocalContext env; |
| 3665 v8::Isolate* iso = env->GetIsolate(); | 3665 v8::Isolate* iso = env->GetIsolate(); |
| 3666 HandleScope scope(iso); | 3666 HandleScope scope(iso); |
| 3667 | 3667 |
| 3668 WeakCallCounter counter(1234); | 3668 WeakCallCounter counter(1234); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3709 iso->SetObjectGroupId(g1s1.handle, id1); | 3709 iso->SetObjectGroupId(g1s1.handle, id1); |
| 3710 iso->SetObjectGroupId(g1s2.handle, id1); | 3710 iso->SetObjectGroupId(g1s2.handle, id1); |
| 3711 iso->SetReference(g1s1.handle, g1c1.handle); | 3711 iso->SetReference(g1s1.handle, g1c1.handle); |
| 3712 iso->SetObjectGroupId(g2s1.handle, id2); | 3712 iso->SetObjectGroupId(g2s1.handle, id2); |
| 3713 iso->SetObjectGroupId(g2s2.handle, id2); | 3713 iso->SetObjectGroupId(g2s2.handle, id2); |
| 3714 iso->SetReferenceFromGroup(id2, g2c1.handle); | 3714 iso->SetReferenceFromGroup(id2, g2c1.handle); |
| 3715 } | 3715 } |
| 3716 // Do a single full GC, ensure incremental marking is stopped. | 3716 // Do a single full GC, ensure incremental marking is stopped. |
| 3717 v8::internal::Heap* heap = | 3717 v8::internal::Heap* heap = |
| 3718 reinterpret_cast<v8::internal::Isolate*>(iso)->heap(); | 3718 reinterpret_cast<v8::internal::Isolate*>(iso)->heap(); |
| 3719 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3719 heap->CollectAllGarbage(); |
| 3720 | 3720 |
| 3721 // All object should be alive. | 3721 // All object should be alive. |
| 3722 CHECK_EQ(0, counter.NumberOfWeakCalls()); | 3722 CHECK_EQ(0, counter.NumberOfWeakCalls()); |
| 3723 | 3723 |
| 3724 // Weaken the root. | 3724 // Weaken the root. |
| 3725 root.handle.SetWeak(&root, &WeakPointerCallback); | 3725 root.handle.SetWeak(&root, &WeakPointerCallback); |
| 3726 // But make children strong roots---all the objects (except for children) | 3726 // But make children strong roots---all the objects (except for children) |
| 3727 // should be collectable now. | 3727 // should be collectable now. |
| 3728 g1c1.handle.ClearWeak(); | 3728 g1c1.handle.ClearWeak(); |
| 3729 g2c1.handle.ClearWeak(); | 3729 g2c1.handle.ClearWeak(); |
| 3730 | 3730 |
| 3731 // Groups are deleted, rebuild groups. | 3731 // Groups are deleted, rebuild groups. |
| 3732 { | 3732 { |
| 3733 UniqueId id1 = MakeUniqueId(g1s1.handle); | 3733 UniqueId id1 = MakeUniqueId(g1s1.handle); |
| 3734 UniqueId id2 = MakeUniqueId(g2s2.handle); | 3734 UniqueId id2 = MakeUniqueId(g2s2.handle); |
| 3735 iso->SetObjectGroupId(g1s1.handle, id1); | 3735 iso->SetObjectGroupId(g1s1.handle, id1); |
| 3736 iso->SetObjectGroupId(g1s2.handle, id1); | 3736 iso->SetObjectGroupId(g1s2.handle, id1); |
| 3737 iso->SetReference(g1s1.handle, g1c1.handle); | 3737 iso->SetReference(g1s1.handle, g1c1.handle); |
| 3738 iso->SetObjectGroupId(g2s1.handle, id2); | 3738 iso->SetObjectGroupId(g2s1.handle, id2); |
| 3739 iso->SetObjectGroupId(g2s2.handle, id2); | 3739 iso->SetObjectGroupId(g2s2.handle, id2); |
| 3740 iso->SetReferenceFromGroup(id2, g2c1.handle); | 3740 iso->SetReferenceFromGroup(id2, g2c1.handle); |
| 3741 } | 3741 } |
| 3742 | 3742 |
| 3743 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3743 heap->CollectAllGarbage(); |
| 3744 | 3744 |
| 3745 // All objects should be gone. 5 global handles in total. | 3745 // All objects should be gone. 5 global handles in total. |
| 3746 CHECK_EQ(5, counter.NumberOfWeakCalls()); | 3746 CHECK_EQ(5, counter.NumberOfWeakCalls()); |
| 3747 | 3747 |
| 3748 // And now make children weak again and collect them. | 3748 // And now make children weak again and collect them. |
| 3749 g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback); | 3749 g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback); |
| 3750 g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback); | 3750 g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback); |
| 3751 | 3751 |
| 3752 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3752 heap->CollectAllGarbage(); |
| 3753 CHECK_EQ(7, counter.NumberOfWeakCalls()); | 3753 CHECK_EQ(7, counter.NumberOfWeakCalls()); |
| 3754 } | 3754 } |
| 3755 | 3755 |
| 3756 | 3756 |
| 3757 THREADED_TEST(ApiObjectGroupsCycle) { | 3757 THREADED_TEST(ApiObjectGroupsCycle) { |
| 3758 LocalContext env; | 3758 LocalContext env; |
| 3759 v8::Isolate* iso = env->GetIsolate(); | 3759 v8::Isolate* iso = env->GetIsolate(); |
| 3760 HandleScope scope(iso); | 3760 HandleScope scope(iso); |
| 3761 | 3761 |
| 3762 WeakCallCounter counter(1234); | 3762 WeakCallCounter counter(1234); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3821 iso->SetObjectGroupId(g3s1.handle, id3); | 3821 iso->SetObjectGroupId(g3s1.handle, id3); |
| 3822 iso->SetObjectGroupId(g3s2.handle, id3); | 3822 iso->SetObjectGroupId(g3s2.handle, id3); |
| 3823 iso->SetReferenceFromGroup(id3, g4s1.handle); | 3823 iso->SetReferenceFromGroup(id3, g4s1.handle); |
| 3824 iso->SetObjectGroupId(g4s1.handle, id4); | 3824 iso->SetObjectGroupId(g4s1.handle, id4); |
| 3825 iso->SetObjectGroupId(g4s2.handle, id4); | 3825 iso->SetObjectGroupId(g4s2.handle, id4); |
| 3826 iso->SetReferenceFromGroup(id4, g1s1.handle); | 3826 iso->SetReferenceFromGroup(id4, g1s1.handle); |
| 3827 } | 3827 } |
| 3828 // Do a single full GC | 3828 // Do a single full GC |
| 3829 v8::internal::Heap* heap = | 3829 v8::internal::Heap* heap = |
| 3830 reinterpret_cast<v8::internal::Isolate*>(iso)->heap(); | 3830 reinterpret_cast<v8::internal::Isolate*>(iso)->heap(); |
| 3831 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3831 heap->CollectAllGarbage(); |
| 3832 | 3832 |
| 3833 // All object should be alive. | 3833 // All object should be alive. |
| 3834 CHECK_EQ(0, counter.NumberOfWeakCalls()); | 3834 CHECK_EQ(0, counter.NumberOfWeakCalls()); |
| 3835 | 3835 |
| 3836 // Weaken the root. | 3836 // Weaken the root. |
| 3837 root.handle.SetWeak(&root, &WeakPointerCallback); | 3837 root.handle.SetWeak(&root, &WeakPointerCallback); |
| 3838 | 3838 |
| 3839 // Groups are deleted, rebuild groups. | 3839 // Groups are deleted, rebuild groups. |
| 3840 { | 3840 { |
| 3841 UniqueId id1 = MakeUniqueId(g1s1.handle); | 3841 UniqueId id1 = MakeUniqueId(g1s1.handle); |
| 3842 UniqueId id2 = MakeUniqueId(g2s1.handle); | 3842 UniqueId id2 = MakeUniqueId(g2s1.handle); |
| 3843 UniqueId id3 = MakeUniqueId(g3s1.handle); | 3843 UniqueId id3 = MakeUniqueId(g3s1.handle); |
| 3844 UniqueId id4 = MakeUniqueId(g4s1.handle); | 3844 UniqueId id4 = MakeUniqueId(g4s1.handle); |
| 3845 iso->SetObjectGroupId(g1s1.handle, id1); | 3845 iso->SetObjectGroupId(g1s1.handle, id1); |
| 3846 iso->SetObjectGroupId(g1s2.handle, id1); | 3846 iso->SetObjectGroupId(g1s2.handle, id1); |
| 3847 iso->SetReferenceFromGroup(id1, g2s1.handle); | 3847 iso->SetReferenceFromGroup(id1, g2s1.handle); |
| 3848 iso->SetObjectGroupId(g2s1.handle, id2); | 3848 iso->SetObjectGroupId(g2s1.handle, id2); |
| 3849 iso->SetObjectGroupId(g2s2.handle, id2); | 3849 iso->SetObjectGroupId(g2s2.handle, id2); |
| 3850 iso->SetReferenceFromGroup(id2, g3s1.handle); | 3850 iso->SetReferenceFromGroup(id2, g3s1.handle); |
| 3851 iso->SetObjectGroupId(g3s1.handle, id3); | 3851 iso->SetObjectGroupId(g3s1.handle, id3); |
| 3852 iso->SetObjectGroupId(g3s2.handle, id3); | 3852 iso->SetObjectGroupId(g3s2.handle, id3); |
| 3853 iso->SetReferenceFromGroup(id3, g4s1.handle); | 3853 iso->SetReferenceFromGroup(id3, g4s1.handle); |
| 3854 iso->SetObjectGroupId(g4s1.handle, id4); | 3854 iso->SetObjectGroupId(g4s1.handle, id4); |
| 3855 iso->SetObjectGroupId(g4s2.handle, id4); | 3855 iso->SetObjectGroupId(g4s2.handle, id4); |
| 3856 iso->SetReferenceFromGroup(id4, g1s1.handle); | 3856 iso->SetReferenceFromGroup(id4, g1s1.handle); |
| 3857 } | 3857 } |
| 3858 | 3858 |
| 3859 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3859 heap->CollectAllGarbage(); |
| 3860 | 3860 |
| 3861 // All objects should be gone. 9 global handles in total. | 3861 // All objects should be gone. 9 global handles in total. |
| 3862 CHECK_EQ(9, counter.NumberOfWeakCalls()); | 3862 CHECK_EQ(9, counter.NumberOfWeakCalls()); |
| 3863 } | 3863 } |
| 3864 | 3864 |
| 3865 | 3865 |
| 3866 THREADED_TEST(WeakRootsSurviveTwoRoundsOfGC) { | 3866 THREADED_TEST(WeakRootsSurviveTwoRoundsOfGC) { |
| 3867 LocalContext env; | 3867 LocalContext env; |
| 3868 v8::Isolate* iso = env->GetIsolate(); | 3868 v8::Isolate* iso = env->GetIsolate(); |
| 3869 HandleScope scope(iso); | 3869 HandleScope scope(iso); |
| 3870 | 3870 |
| 3871 WeakCallCounter counter(1234); | 3871 WeakCallCounter counter(1234); |
| 3872 | 3872 |
| 3873 WeakCallCounterAndPersistent<Value> weak_obj(&counter); | 3873 WeakCallCounterAndPersistent<Value> weak_obj(&counter); |
| 3874 | 3874 |
| 3875 // Create a weak object that references a internalized string. | 3875 // Create a weak object that references a internalized string. |
| 3876 { | 3876 { |
| 3877 HandleScope scope(iso); | 3877 HandleScope scope(iso); |
| 3878 weak_obj.handle.Reset(iso, Object::New(iso)); | 3878 weak_obj.handle.Reset(iso, Object::New(iso)); |
| 3879 weak_obj.handle.SetWeak(&weak_obj, &WeakPointerCallback); | 3879 weak_obj.handle.SetWeak(&weak_obj, &WeakPointerCallback); |
| 3880 CHECK(weak_obj.handle.IsWeak()); | 3880 CHECK(weak_obj.handle.IsWeak()); |
| 3881 Local<Object>::New(iso, weak_obj.handle.As<Object>()) | 3881 Local<Object>::New(iso, weak_obj.handle.As<Object>()) |
| 3882 ->Set(v8_str("x"), String::NewFromUtf8(iso, "magic cookie", | 3882 ->Set(v8_str("x"), String::NewFromUtf8(iso, "magic cookie", |
| 3883 String::kInternalizedString)); | 3883 String::kInternalizedString)); |
| 3884 } | 3884 } |
| 3885 // Do a single full GC | 3885 // Do a single full GC |
| 3886 i::Isolate* i_iso = reinterpret_cast<v8::internal::Isolate*>(iso); | 3886 i::Isolate* i_iso = reinterpret_cast<v8::internal::Isolate*>(iso); |
| 3887 i::Heap* heap = i_iso->heap(); | 3887 i::Heap* heap = i_iso->heap(); |
| 3888 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3888 heap->CollectAllGarbage(); |
| 3889 | 3889 |
| 3890 // We should have received the weak callback. | 3890 // We should have received the weak callback. |
| 3891 CHECK_EQ(1, counter.NumberOfWeakCalls()); | 3891 CHECK_EQ(1, counter.NumberOfWeakCalls()); |
| 3892 | 3892 |
| 3893 // Check that the string is still alive. | 3893 // Check that the string is still alive. |
| 3894 { | 3894 { |
| 3895 HandleScope scope(iso); | 3895 HandleScope scope(iso); |
| 3896 i::MaybeHandle<i::String> magic_string = | 3896 i::MaybeHandle<i::String> magic_string = |
| 3897 i::StringTable::LookupStringIfExists( | 3897 i::StringTable::LookupStringIfExists( |
| 3898 i_iso, | 3898 i_iso, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3963 Local<Object>::New(iso, g2s1.handle.As<Object>()) | 3963 Local<Object>::New(iso, g2s1.handle.As<Object>()) |
| 3964 ->Set(v8_str("x"), Local<Value>::New(iso, g3s1.handle)); | 3964 ->Set(v8_str("x"), Local<Value>::New(iso, g3s1.handle)); |
| 3965 iso->SetObjectGroupId(g3s1.handle, UniqueId(3)); | 3965 iso->SetObjectGroupId(g3s1.handle, UniqueId(3)); |
| 3966 iso->SetObjectGroupId(g3s2.handle, UniqueId(3)); | 3966 iso->SetObjectGroupId(g3s2.handle, UniqueId(3)); |
| 3967 Local<Object>::New(iso, g3s1.handle.As<Object>()) | 3967 Local<Object>::New(iso, g3s1.handle.As<Object>()) |
| 3968 ->Set(v8_str("x"), Local<Value>::New(iso, g1s1.handle)); | 3968 ->Set(v8_str("x"), Local<Value>::New(iso, g1s1.handle)); |
| 3969 } | 3969 } |
| 3970 | 3970 |
| 3971 v8::internal::Heap* heap = | 3971 v8::internal::Heap* heap = |
| 3972 reinterpret_cast<v8::internal::Isolate*>(iso)->heap(); | 3972 reinterpret_cast<v8::internal::Isolate*>(iso)->heap(); |
| 3973 heap->CollectAllGarbage(i::Heap::kNoGCFlags); | 3973 heap->CollectAllGarbage(); |
| 3974 | 3974 |
| 3975 // All objects should be alive. | 3975 // All objects should be alive. |
| 3976 CHECK_EQ(0, counter.NumberOfWeakCalls()); | 3976 CHECK_EQ(0, counter.NumberOfWeakCalls()); |
| 3977 | 3977 |
| 3978 // Weaken the root. | 3978 // Weaken the root. |
| 3979 root.handle.SetWeak(&root, &WeakPointerCallback); | 3979 root.handle.SetWeak(&root, &WeakPointerCallback); |
| 3980 root.handle.MarkPartiallyDependent(); | 3980 root.handle.MarkPartiallyDependent(); |
| 3981 | 3981 |
| 3982 // Groups are deleted, rebuild groups. | 3982 // Groups are deleted, rebuild groups. |
| 3983 { | 3983 { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3995 iso->SetObjectGroupId(g2s1.handle, UniqueId(2)); | 3995 iso->SetObjectGroupId(g2s1.handle, UniqueId(2)); |
| 3996 iso->SetObjectGroupId(g2s2.handle, UniqueId(2)); | 3996 iso->SetObjectGroupId(g2s2.handle, UniqueId(2)); |
| 3997 Local<Object>::New(iso, g2s1.handle.As<Object>()) | 3997 Local<Object>::New(iso, g2s1.handle.As<Object>()) |
| 3998 ->Set(v8_str("x"), Local<Value>::New(iso, g3s1.handle)); | 3998 ->Set(v8_str("x"), Local<Value>::New(iso, g3s1.handle)); |
| 3999 iso->SetObjectGroupId(g3s1.handle, UniqueId(3)); | 3999 iso->SetObjectGroupId(g3s1.handle, UniqueId(3)); |
| 4000 iso->SetObjectGroupId(g3s2.handle, UniqueId(3)); | 4000 iso->SetObjectGroupId(g3s2.handle, UniqueId(3)); |
| 4001 Local<Object>::New(iso, g3s1.handle.As<Object>()) | 4001 Local<Object>::New(iso, g3s1.handle.As<Object>()) |
| 4002 ->Set(v8_str("x"), Local<Value>::New(iso, g1s1.handle)); | 4002 ->Set(v8_str("x"), Local<Value>::New(iso, g1s1.handle)); |
| 4003 } | 4003 } |
| 4004 | 4004 |
| 4005 heap->CollectAllGarbage(i::Heap::kNoGCFlags); | 4005 heap->CollectAllGarbage(); |
| 4006 | 4006 |
| 4007 // All objects should be gone. 7 global handles in total. | 4007 // All objects should be gone. 7 global handles in total. |
| 4008 CHECK_EQ(7, counter.NumberOfWeakCalls()); | 4008 CHECK_EQ(7, counter.NumberOfWeakCalls()); |
| 4009 } | 4009 } |
| 4010 | 4010 |
| 4011 | 4011 |
| 4012 THREADED_TEST(ScriptException) { | 4012 THREADED_TEST(ScriptException) { |
| 4013 LocalContext env; | 4013 LocalContext env; |
| 4014 v8::HandleScope scope(env->GetIsolate()); | 4014 v8::HandleScope scope(env->GetIsolate()); |
| 4015 Local<Script> script = v8_compile("throw 'panama!';"); | 4015 Local<Script> script = v8_compile("throw 'panama!';"); |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4255 CHECK(weak_map->Has(local1)); | 4255 CHECK(weak_map->Has(local1)); |
| 4256 CHECK(weak_map->Has(obj1)); | 4256 CHECK(weak_map->Has(obj1)); |
| 4257 CHECK(weak_map->Has(obj2)); | 4257 CHECK(weak_map->Has(obj2)); |
| 4258 CHECK(weak_map->Has(sym1)); | 4258 CHECK(weak_map->Has(sym1)); |
| 4259 | 4259 |
| 4260 CHECK(value->Equals(weak_map->Get(local1))); | 4260 CHECK(value->Equals(weak_map->Get(local1))); |
| 4261 CHECK(value->Equals(weak_map->Get(obj1))); | 4261 CHECK(value->Equals(weak_map->Get(obj1))); |
| 4262 CHECK(value->Equals(weak_map->Get(obj2))); | 4262 CHECK(value->Equals(weak_map->Get(obj2))); |
| 4263 CHECK(value->Equals(weak_map->Get(sym1))); | 4263 CHECK(value->Equals(weak_map->Get(sym1))); |
| 4264 } | 4264 } |
| 4265 CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags); | 4265 CcTest::heap()->CollectAllGarbage(); |
| 4266 { | 4266 { |
| 4267 HandleScope scope(isolate); | 4267 HandleScope scope(isolate); |
| 4268 CHECK(value->Equals(weak_map->Get(local1))); | 4268 CHECK(value->Equals(weak_map->Get(local1))); |
| 4269 CHECK(value->Equals(weak_map->Get(Local<Value>::New(isolate, o1.handle)))); | 4269 CHECK(value->Equals(weak_map->Get(Local<Value>::New(isolate, o1.handle)))); |
| 4270 CHECK(value->Equals(weak_map->Get(Local<Value>::New(isolate, o2.handle)))); | 4270 CHECK(value->Equals(weak_map->Get(Local<Value>::New(isolate, o2.handle)))); |
| 4271 CHECK(value->Equals(weak_map->Get(Local<Value>::New(isolate, s1.handle)))); | 4271 CHECK(value->Equals(weak_map->Get(Local<Value>::New(isolate, s1.handle)))); |
| 4272 } | 4272 } |
| 4273 | 4273 |
| 4274 o1.handle.SetWeak(&o1, &WeakPointerCallback); | 4274 o1.handle.SetWeak(&o1, &WeakPointerCallback); |
| 4275 o2.handle.SetWeak(&o2, &WeakPointerCallback); | 4275 o2.handle.SetWeak(&o2, &WeakPointerCallback); |
| 4276 s1.handle.SetWeak(&s1, &WeakPointerCallback); | 4276 s1.handle.SetWeak(&s1, &WeakPointerCallback); |
| 4277 | 4277 |
| 4278 CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags); | 4278 CcTest::heap()->CollectAllGarbage(); |
| 4279 CHECK_EQ(3, counter.NumberOfWeakCalls()); | 4279 CHECK_EQ(3, counter.NumberOfWeakCalls()); |
| 4280 | 4280 |
| 4281 CHECK(o1.handle.IsEmpty()); | 4281 CHECK(o1.handle.IsEmpty()); |
| 4282 CHECK(o2.handle.IsEmpty()); | 4282 CHECK(o2.handle.IsEmpty()); |
| 4283 CHECK(s1.handle.IsEmpty()); | 4283 CHECK(s1.handle.IsEmpty()); |
| 4284 | 4284 |
| 4285 CHECK(value->Equals(weak_map->Get(local1))); | 4285 CHECK(value->Equals(weak_map->Get(local1))); |
| 4286 CHECK(weak_map->Delete(local1)); | 4286 CHECK(weak_map->Delete(local1)); |
| 4287 CHECK(!weak_map->Has(local1)); | 4287 CHECK(!weak_map->Has(local1)); |
| 4288 CHECK(weak_map->Get(local1)->IsUndefined()); | 4288 CHECK(weak_map->Get(local1)->IsUndefined()); |
| (...skipping 2232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6521 v8::HandleScope handle_scope(iso); | 6521 v8::HandleScope handle_scope(iso); |
| 6522 Local<Object> a(v8::Object::New(iso)); | 6522 Local<Object> a(v8::Object::New(iso)); |
| 6523 Local<Object> b(v8::Object::New(iso)); | 6523 Local<Object> b(v8::Object::New(iso)); |
| 6524 object_a.handle.Reset(iso, a); | 6524 object_a.handle.Reset(iso, a); |
| 6525 object_b.handle.Reset(iso, b); | 6525 object_b.handle.Reset(iso, b); |
| 6526 if (interlinked) { | 6526 if (interlinked) { |
| 6527 a->Set(v8_str("x"), b); | 6527 a->Set(v8_str("x"), b); |
| 6528 b->Set(v8_str("x"), a); | 6528 b->Set(v8_str("x"), a); |
| 6529 } | 6529 } |
| 6530 if (global_gc) { | 6530 if (global_gc) { |
| 6531 CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags); | 6531 CcTest::heap()->CollectAllGarbage(); |
| 6532 } else { | 6532 } else { |
| 6533 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 6533 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
| 6534 } | 6534 } |
| 6535 // We are relying on this creating a big flag array and reserving the space | 6535 // We are relying on this creating a big flag array and reserving the space |
| 6536 // up front. | 6536 // up front. |
| 6537 v8::Handle<Value> big_array = CompileRun("new Array(50000)"); | 6537 v8::Handle<Value> big_array = CompileRun("new Array(50000)"); |
| 6538 a->Set(v8_str("y"), big_array); | 6538 a->Set(v8_str("y"), big_array); |
| 6539 big_heap_size = CcTest::heap()->SizeOfObjects(); | 6539 big_heap_size = CcTest::heap()->SizeOfObjects(); |
| 6540 } | 6540 } |
| 6541 | 6541 |
| 6542 object_a.flag = false; | 6542 object_a.flag = false; |
| 6543 object_b.flag = false; | 6543 object_b.flag = false; |
| 6544 object_a.handle.SetWeak(&object_a, &SetFlag, | 6544 object_a.handle.SetWeak(&object_a, &SetFlag, |
| 6545 v8::WeakCallbackType::kParameter); | 6545 v8::WeakCallbackType::kParameter); |
| 6546 object_b.handle.SetWeak(&object_b, &SetFlag, | 6546 object_b.handle.SetWeak(&object_b, &SetFlag, |
| 6547 v8::WeakCallbackType::kParameter); | 6547 v8::WeakCallbackType::kParameter); |
| 6548 CHECK(!object_b.handle.IsIndependent()); | 6548 CHECK(!object_b.handle.IsIndependent()); |
| 6549 object_a.handle.MarkIndependent(); | 6549 object_a.handle.MarkIndependent(); |
| 6550 object_b.handle.MarkIndependent(); | 6550 object_b.handle.MarkIndependent(); |
| 6551 CHECK(object_b.handle.IsIndependent()); | 6551 CHECK(object_b.handle.IsIndependent()); |
| 6552 if (global_gc) { | 6552 if (global_gc) { |
| 6553 CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags); | 6553 CcTest::heap()->CollectAllGarbage(); |
| 6554 } else { | 6554 } else { |
| 6555 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 6555 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
| 6556 } | 6556 } |
| 6557 // A single GC should be enough to reclaim the memory, since we are using | 6557 // A single GC should be enough to reclaim the memory, since we are using |
| 6558 // phantom handles. | 6558 // phantom handles. |
| 6559 CHECK_LT(CcTest::heap()->SizeOfObjects(), big_heap_size - 200000); | 6559 CHECK_LT(CcTest::heap()->SizeOfObjects(), big_heap_size - 200000); |
| 6560 CHECK(object_a.flag); | 6560 CHECK(object_a.flag); |
| 6561 CHECK(object_b.flag); | 6561 CHECK(object_b.flag); |
| 6562 } | 6562 } |
| 6563 | 6563 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6639 reinterpret_cast<Trivial2*>(obj->GetAlignedPointerFromInternalField(1)); | 6639 reinterpret_cast<Trivial2*>(obj->GetAlignedPointerFromInternalField(1)); |
| 6640 CHECK_EQ(103, t2->x()); | 6640 CHECK_EQ(103, t2->x()); |
| 6641 | 6641 |
| 6642 handle.SetWeak<v8::Persistent<v8::Object>>( | 6642 handle.SetWeak<v8::Persistent<v8::Object>>( |
| 6643 &handle, CheckInternalFields, v8::WeakCallbackType::kInternalFields); | 6643 &handle, CheckInternalFields, v8::WeakCallbackType::kInternalFields); |
| 6644 if (!global_gc) { | 6644 if (!global_gc) { |
| 6645 handle.MarkIndependent(); | 6645 handle.MarkIndependent(); |
| 6646 } | 6646 } |
| 6647 } | 6647 } |
| 6648 if (global_gc) { | 6648 if (global_gc) { |
| 6649 CcTest::heap()->CollectAllGarbage( | 6649 CcTest::heap()->CollectAllGarbage(); |
| 6650 TestHeap::Heap::kAbortIncrementalMarkingMask); | |
| 6651 } else { | 6650 } else { |
| 6652 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 6651 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
| 6653 } | 6652 } |
| 6654 | 6653 |
| 6655 CHECK_EQ(1729, t1->x()); | 6654 CHECK_EQ(1729, t1->x()); |
| 6656 CHECK_EQ(33550336, t2->x()); | 6655 CHECK_EQ(33550336, t2->x()); |
| 6657 | 6656 |
| 6658 delete t1; | 6657 delete t1; |
| 6659 delete t2; | 6658 delete t2; |
| 6660 } | 6659 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6720 | 6719 |
| 6721 THREADED_TEST(ResetWeakHandle) { | 6720 THREADED_TEST(ResetWeakHandle) { |
| 6722 ResetWeakHandle(false); | 6721 ResetWeakHandle(false); |
| 6723 ResetWeakHandle(true); | 6722 ResetWeakHandle(true); |
| 6724 } | 6723 } |
| 6725 | 6724 |
| 6726 | 6725 |
| 6727 static void InvokeScavenge() { CcTest::heap()->CollectGarbage(i::NEW_SPACE); } | 6726 static void InvokeScavenge() { CcTest::heap()->CollectGarbage(i::NEW_SPACE); } |
| 6728 | 6727 |
| 6729 | 6728 |
| 6730 static void InvokeMarkSweep() { | 6729 static void InvokeMarkSweep() { CcTest::heap()->CollectAllGarbage(); } |
| 6731 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | |
| 6732 } | |
| 6733 | 6730 |
| 6734 | 6731 |
| 6735 static void ForceScavenge( | 6732 static void ForceScavenge( |
| 6736 const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) { | 6733 const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) { |
| 6737 data.GetParameter()->handle.Reset(); | 6734 data.GetParameter()->handle.Reset(); |
| 6738 data.GetParameter()->flag = true; | 6735 data.GetParameter()->flag = true; |
| 6739 InvokeScavenge(); | 6736 InvokeScavenge(); |
| 6740 } | 6737 } |
| 6741 | 6738 |
| 6742 | 6739 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6800 object.handle.Reset(isolate, o); | 6797 object.handle.Reset(isolate, o); |
| 6801 o->Set(v8_str("x"), v8::Integer::New(isolate, 1)); | 6798 o->Set(v8_str("x"), v8::Integer::New(isolate, 1)); |
| 6802 v8::Local<String> y_str = v8_str("y"); | 6799 v8::Local<String> y_str = v8_str("y"); |
| 6803 o->Set(y_str, y_str); | 6800 o->Set(y_str, y_str); |
| 6804 } | 6801 } |
| 6805 object.flag = false; | 6802 object.flag = false; |
| 6806 object.handle.SetWeak(&object, &RevivingCallback); | 6803 object.handle.SetWeak(&object, &RevivingCallback); |
| 6807 object.handle.MarkIndependent(); | 6804 object.handle.MarkIndependent(); |
| 6808 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 6805 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
| 6809 CHECK(object.flag); | 6806 CHECK(object.flag); |
| 6810 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 6807 CcTest::heap()->CollectAllGarbage(); |
| 6811 { | 6808 { |
| 6812 v8::HandleScope handle_scope(isolate); | 6809 v8::HandleScope handle_scope(isolate); |
| 6813 v8::Local<v8::Object> o = | 6810 v8::Local<v8::Object> o = |
| 6814 v8::Local<v8::Object>::New(isolate, object.handle); | 6811 v8::Local<v8::Object>::New(isolate, object.handle); |
| 6815 v8::Local<String> y_str = v8_str("y"); | 6812 v8::Local<String> y_str = v8_str("y"); |
| 6816 CHECK(v8::Integer::New(isolate, 1)->Equals(o->Get(v8_str("x")))); | 6813 CHECK(v8::Integer::New(isolate, 1)->Equals(o->Get(v8_str("x")))); |
| 6817 CHECK(o->Get(y_str)->Equals(y_str)); | 6814 CHECK(o->Get(y_str)->Equals(y_str)); |
| 6818 } | 6815 } |
| 6819 } | 6816 } |
| 6820 | 6817 |
| 6821 | 6818 |
| 6822 v8::Handle<Function> args_fun; | 6819 v8::Handle<Function> args_fun; |
| 6823 | 6820 |
| 6824 | 6821 |
| 6825 static void ArgumentsTestCallback( | 6822 static void ArgumentsTestCallback( |
| 6826 const v8::FunctionCallbackInfo<v8::Value>& args) { | 6823 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 6827 ApiTestFuzzer::Fuzz(); | 6824 ApiTestFuzzer::Fuzz(); |
| 6828 v8::Isolate* isolate = args.GetIsolate(); | 6825 v8::Isolate* isolate = args.GetIsolate(); |
| 6829 CHECK(args_fun->Equals(args.Callee())); | 6826 CHECK(args_fun->Equals(args.Callee())); |
| 6830 CHECK_EQ(3, args.Length()); | 6827 CHECK_EQ(3, args.Length()); |
| 6831 CHECK(v8::Integer::New(isolate, 1)->Equals(args[0])); | 6828 CHECK(v8::Integer::New(isolate, 1)->Equals(args[0])); |
| 6832 CHECK(v8::Integer::New(isolate, 2)->Equals(args[1])); | 6829 CHECK(v8::Integer::New(isolate, 2)->Equals(args[1])); |
| 6833 CHECK(v8::Integer::New(isolate, 3)->Equals(args[2])); | 6830 CHECK(v8::Integer::New(isolate, 3)->Equals(args[2])); |
| 6834 CHECK(v8::Undefined(isolate)->Equals(args[3])); | 6831 CHECK(v8::Undefined(isolate)->Equals(args[3])); |
| 6835 v8::HandleScope scope(args.GetIsolate()); | 6832 v8::HandleScope scope(args.GetIsolate()); |
| 6836 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 6833 CcTest::heap()->CollectAllGarbage(); |
| 6837 } | 6834 } |
| 6838 | 6835 |
| 6839 | 6836 |
| 6840 THREADED_TEST(Arguments) { | 6837 THREADED_TEST(Arguments) { |
| 6841 v8::Isolate* isolate = CcTest::isolate(); | 6838 v8::Isolate* isolate = CcTest::isolate(); |
| 6842 v8::HandleScope scope(isolate); | 6839 v8::HandleScope scope(isolate); |
| 6843 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(isolate); | 6840 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(isolate); |
| 6844 global->Set(v8_str("f"), | 6841 global->Set(v8_str("f"), |
| 6845 v8::FunctionTemplate::New(isolate, ArgumentsTestCallback)); | 6842 v8::FunctionTemplate::New(isolate, ArgumentsTestCallback)); |
| 6846 LocalContext context(NULL, global); | 6843 LocalContext context(NULL, global); |
| (...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8078 CHECK(access_f3->Run().IsEmpty()); | 8075 CHECK(access_f3->Run().IsEmpty()); |
| 8079 } | 8076 } |
| 8080 } | 8077 } |
| 8081 | 8078 |
| 8082 | 8079 |
| 8083 static bool security_check_with_gc_called; | 8080 static bool security_check_with_gc_called; |
| 8084 | 8081 |
| 8085 static bool SecurityTestCallbackWithGC(Local<v8::Object> global, | 8082 static bool SecurityTestCallbackWithGC(Local<v8::Object> global, |
| 8086 Local<v8::Value> name, | 8083 Local<v8::Value> name, |
| 8087 v8::AccessType type, Local<Value> data) { | 8084 v8::AccessType type, Local<Value> data) { |
| 8088 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 8085 CcTest::heap()->CollectAllGarbage(); |
| 8089 security_check_with_gc_called = true; | 8086 security_check_with_gc_called = true; |
| 8090 return true; | 8087 return true; |
| 8091 } | 8088 } |
| 8092 | 8089 |
| 8093 | 8090 |
| 8094 TEST(SecurityTestGCAllowed) { | 8091 TEST(SecurityTestGCAllowed) { |
| 8095 v8::Isolate* isolate = CcTest::isolate(); | 8092 v8::Isolate* isolate = CcTest::isolate(); |
| 8096 v8::HandleScope handle_scope(isolate); | 8093 v8::HandleScope handle_scope(isolate); |
| 8097 v8::Handle<v8::ObjectTemplate> object_template = | 8094 v8::Handle<v8::ObjectTemplate> object_template = |
| 8098 v8::ObjectTemplate::New(isolate); | 8095 v8::ObjectTemplate::New(isolate); |
| (...skipping 2266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10365 | 10362 |
| 10366 | 10363 |
| 10367 static void InterceptorCallICFastApi( | 10364 static void InterceptorCallICFastApi( |
| 10368 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { | 10365 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 10369 ApiTestFuzzer::Fuzz(); | 10366 ApiTestFuzzer::Fuzz(); |
| 10370 CheckReturnValue(info, FUNCTION_ADDR(InterceptorCallICFastApi)); | 10367 CheckReturnValue(info, FUNCTION_ADDR(InterceptorCallICFastApi)); |
| 10371 int* call_count = | 10368 int* call_count = |
| 10372 reinterpret_cast<int*>(v8::External::Cast(*info.Data())->Value()); | 10369 reinterpret_cast<int*>(v8::External::Cast(*info.Data())->Value()); |
| 10373 ++(*call_count); | 10370 ++(*call_count); |
| 10374 if ((*call_count) % 20 == 0) { | 10371 if ((*call_count) % 20 == 0) { |
| 10375 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 10372 CcTest::heap()->CollectAllGarbage(); |
| 10376 } | 10373 } |
| 10377 } | 10374 } |
| 10378 | 10375 |
| 10379 static void FastApiCallback_TrivialSignature( | 10376 static void FastApiCallback_TrivialSignature( |
| 10380 const v8::FunctionCallbackInfo<v8::Value>& args) { | 10377 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 10381 ApiTestFuzzer::Fuzz(); | 10378 ApiTestFuzzer::Fuzz(); |
| 10382 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_TrivialSignature)); | 10379 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_TrivialSignature)); |
| 10383 v8::Isolate* isolate = CcTest::isolate(); | 10380 v8::Isolate* isolate = CcTest::isolate(); |
| 10384 CHECK_EQ(isolate, args.GetIsolate()); | 10381 CHECK_EQ(isolate, args.GetIsolate()); |
| 10385 CHECK(args.This()->Equals(args.Holder())); | 10382 CHECK(args.This()->Equals(args.Holder())); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 10409 "for (var i = 0; i < 1000; i++) {" | 10406 "for (var i = 0; i < 1000; i++) {" |
| 10410 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];" | 10407 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];" |
| 10411 "}" | 10408 "}" |
| 10412 "garbage = undefined;"); | 10409 "garbage = undefined;"); |
| 10413 } | 10410 } |
| 10414 | 10411 |
| 10415 | 10412 |
| 10416 void DirectApiCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { | 10413 void DirectApiCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 10417 static int count = 0; | 10414 static int count = 0; |
| 10418 if (count++ % 3 == 0) { | 10415 if (count++ % 3 == 0) { |
| 10419 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 10416 CcTest::heap()->CollectAllGarbage(); |
| 10420 // This should move the stub | 10417 // This should move the stub |
| 10421 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed | 10418 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed |
| 10422 } | 10419 } |
| 10423 } | 10420 } |
| 10424 | 10421 |
| 10425 | 10422 |
| 10426 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { | 10423 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { |
| 10427 LocalContext context; | 10424 LocalContext context; |
| 10428 v8::Isolate* isolate = context->GetIsolate(); | 10425 v8::Isolate* isolate = context->GetIsolate(); |
| 10429 v8::HandleScope scope(isolate); | 10426 v8::HandleScope scope(isolate); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10473 "f(); result;"); | 10470 "f(); result;"); |
| 10474 CHECK(v8_str("ggggg")->Equals(result)); | 10471 CHECK(v8_str("ggggg")->Equals(result)); |
| 10475 } | 10472 } |
| 10476 | 10473 |
| 10477 | 10474 |
| 10478 static int p_getter_count_3; | 10475 static int p_getter_count_3; |
| 10479 | 10476 |
| 10480 | 10477 |
| 10481 static Handle<Value> DoDirectGetter() { | 10478 static Handle<Value> DoDirectGetter() { |
| 10482 if (++p_getter_count_3 % 3 == 0) { | 10479 if (++p_getter_count_3 % 3 == 0) { |
| 10483 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 10480 CcTest::heap()->CollectAllGarbage(); |
| 10484 GenerateSomeGarbage(); | 10481 GenerateSomeGarbage(); |
| 10485 } | 10482 } |
| 10486 return v8_str("Direct Getter Result"); | 10483 return v8_str("Direct Getter Result"); |
| 10487 } | 10484 } |
| 10488 | 10485 |
| 10489 | 10486 |
| 10490 static void DirectGetterCallback( | 10487 static void DirectGetterCallback( |
| 10491 Local<String> name, | 10488 Local<String> name, |
| 10492 const v8::PropertyCallbackInfo<v8::Value>& info) { | 10489 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 10493 CheckReturnValue(info, FUNCTION_ADDR(DirectGetterCallback)); | 10490 CheckReturnValue(info, FUNCTION_ADDR(DirectGetterCallback)); |
| (...skipping 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11712 return count; | 11709 return count; |
| 11713 } | 11710 } |
| 11714 | 11711 |
| 11715 | 11712 |
| 11716 static void CheckSurvivingGlobalObjectsCount(int expected) { | 11713 static void CheckSurvivingGlobalObjectsCount(int expected) { |
| 11717 // We need to collect all garbage twice to be sure that everything | 11714 // We need to collect all garbage twice to be sure that everything |
| 11718 // has been collected. This is because inline caches are cleared in | 11715 // has been collected. This is because inline caches are cleared in |
| 11719 // the first garbage collection but some of the maps have already | 11716 // the first garbage collection but some of the maps have already |
| 11720 // been marked at that point. Therefore some of the maps are not | 11717 // been marked at that point. Therefore some of the maps are not |
| 11721 // collected until the second garbage collection. | 11718 // collected until the second garbage collection. |
| 11722 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 11719 CcTest::heap()->CollectAllGarbage(); |
| 11723 CcTest::heap()->CollectAllGarbage(i::Heap::kMakeHeapIterableMask); | 11720 CcTest::heap()->CollectAllGarbage(i::Heap::kMakeHeapIterableMask); |
| 11724 int count = GetGlobalObjectsCount(); | 11721 int count = GetGlobalObjectsCount(); |
| 11725 #ifdef DEBUG | 11722 #ifdef DEBUG |
| 11726 if (count != expected) CcTest::heap()->TracePathToGlobal(); | 11723 if (count != expected) CcTest::heap()->TracePathToGlobal(); |
| 11727 #endif | 11724 #endif |
| 11728 CHECK_EQ(expected, count); | 11725 CHECK_EQ(expected, count); |
| 11729 } | 11726 } |
| 11730 | 11727 |
| 11731 | 11728 |
| 11732 TEST(DontLeakGlobalObjects) { | 11729 TEST(DontLeakGlobalObjects) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11813 int initial_handles = globals->global_handles_count(); | 11810 int initial_handles = globals->global_handles_count(); |
| 11814 { | 11811 { |
| 11815 v8::HandleScope scope(isolate); | 11812 v8::HandleScope scope(isolate); |
| 11816 v8::Local<v8::Object> obj = v8::Object::New(isolate); | 11813 v8::Local<v8::Object> obj = v8::Object::New(isolate); |
| 11817 obj->Set(v8_str("key"), v8::Integer::New(isolate, 231)); | 11814 obj->Set(v8_str("key"), v8::Integer::New(isolate, 231)); |
| 11818 v8::Persistent<v8::Object>* handle = | 11815 v8::Persistent<v8::Object>* handle = |
| 11819 new v8::Persistent<v8::Object>(isolate, obj); | 11816 new v8::Persistent<v8::Object>(isolate, obj); |
| 11820 handle->SetWeak<v8::Object, v8::Persistent<v8::Object> >(handle, | 11817 handle->SetWeak<v8::Object, v8::Persistent<v8::Object> >(handle, |
| 11821 WeakApiCallback); | 11818 WeakApiCallback); |
| 11822 } | 11819 } |
| 11823 reinterpret_cast<i::Isolate*>(isolate)->heap()-> | 11820 reinterpret_cast<i::Isolate*>(isolate)->heap()->CollectAllGarbage( |
| 11824 CollectAllGarbage(i::Heap::kNoGCFlags); | 11821 i::Heap::kAbortIncrementalMarkingMask); |
| 11825 // Verify disposed. | 11822 // Verify disposed. |
| 11826 CHECK_EQ(initial_handles, globals->global_handles_count()); | 11823 CHECK_EQ(initial_handles, globals->global_handles_count()); |
| 11827 } | 11824 } |
| 11828 | 11825 |
| 11829 | 11826 |
| 11830 v8::Persistent<v8::Object> some_object; | 11827 v8::Persistent<v8::Object> some_object; |
| 11831 v8::Persistent<v8::Object> bad_handle; | 11828 v8::Persistent<v8::Object> bad_handle; |
| 11832 | 11829 |
| 11833 void NewPersistentHandleCallback( | 11830 void NewPersistentHandleCallback( |
| 11834 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { | 11831 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 11848 some_object.Reset(isolate, v8::Object::New(isolate)); | 11845 some_object.Reset(isolate, v8::Object::New(isolate)); |
| 11849 handle1.Reset(isolate, v8::Object::New(isolate)); | 11846 handle1.Reset(isolate, v8::Object::New(isolate)); |
| 11850 handle2.Reset(isolate, v8::Object::New(isolate)); | 11847 handle2.Reset(isolate, v8::Object::New(isolate)); |
| 11851 } | 11848 } |
| 11852 // Note: order is implementation dependent alas: currently | 11849 // Note: order is implementation dependent alas: currently |
| 11853 // global handle nodes are processed by PostGarbageCollectionProcessing | 11850 // global handle nodes are processed by PostGarbageCollectionProcessing |
| 11854 // in reverse allocation order, so if second allocated handle is deleted, | 11851 // in reverse allocation order, so if second allocated handle is deleted, |
| 11855 // weak callback of the first handle would be able to 'reallocate' it. | 11852 // weak callback of the first handle would be able to 'reallocate' it. |
| 11856 handle1.SetWeak(&handle1, NewPersistentHandleCallback); | 11853 handle1.SetWeak(&handle1, NewPersistentHandleCallback); |
| 11857 handle2.Reset(); | 11854 handle2.Reset(); |
| 11858 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 11855 CcTest::heap()->CollectAllGarbage(); |
| 11859 } | 11856 } |
| 11860 | 11857 |
| 11861 | 11858 |
| 11862 v8::Persistent<v8::Object> to_be_disposed; | 11859 v8::Persistent<v8::Object> to_be_disposed; |
| 11863 | 11860 |
| 11864 void DisposeAndForceGcCallback( | 11861 void DisposeAndForceGcCallback( |
| 11865 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { | 11862 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { |
| 11866 to_be_disposed.Reset(); | 11863 to_be_disposed.Reset(); |
| 11867 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 11864 CcTest::heap()->CollectAllGarbage(); |
| 11868 data.GetParameter()->Reset(); | 11865 data.GetParameter()->Reset(); |
| 11869 } | 11866 } |
| 11870 | 11867 |
| 11871 | 11868 |
| 11872 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) { | 11869 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) { |
| 11873 LocalContext context; | 11870 LocalContext context; |
| 11874 v8::Isolate* isolate = context->GetIsolate(); | 11871 v8::Isolate* isolate = context->GetIsolate(); |
| 11875 | 11872 |
| 11876 v8::Persistent<v8::Object> handle1, handle2; | 11873 v8::Persistent<v8::Object> handle1, handle2; |
| 11877 { | 11874 { |
| 11878 v8::HandleScope scope(isolate); | 11875 v8::HandleScope scope(isolate); |
| 11879 handle1.Reset(isolate, v8::Object::New(isolate)); | 11876 handle1.Reset(isolate, v8::Object::New(isolate)); |
| 11880 handle2.Reset(isolate, v8::Object::New(isolate)); | 11877 handle2.Reset(isolate, v8::Object::New(isolate)); |
| 11881 } | 11878 } |
| 11882 handle1.SetWeak(&handle1, DisposeAndForceGcCallback); | 11879 handle1.SetWeak(&handle1, DisposeAndForceGcCallback); |
| 11883 to_be_disposed.Reset(isolate, handle2); | 11880 to_be_disposed.Reset(isolate, handle2); |
| 11884 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 11881 CcTest::heap()->CollectAllGarbage(); |
| 11885 } | 11882 } |
| 11886 | 11883 |
| 11887 void DisposingCallback( | 11884 void DisposingCallback( |
| 11888 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { | 11885 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { |
| 11889 data.GetParameter()->Reset(); | 11886 data.GetParameter()->Reset(); |
| 11890 } | 11887 } |
| 11891 | 11888 |
| 11892 void HandleCreatingCallback( | 11889 void HandleCreatingCallback( |
| 11893 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { | 11890 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { |
| 11894 v8::HandleScope scope(data.GetIsolate()); | 11891 v8::HandleScope scope(data.GetIsolate()); |
| 11895 v8::Persistent<v8::Object>(data.GetIsolate(), | 11892 v8::Persistent<v8::Object>(data.GetIsolate(), |
| 11896 v8::Object::New(data.GetIsolate())); | 11893 v8::Object::New(data.GetIsolate())); |
| 11897 data.GetParameter()->Reset(); | 11894 data.GetParameter()->Reset(); |
| 11898 } | 11895 } |
| 11899 | 11896 |
| 11900 | 11897 |
| 11901 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) { | 11898 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) { |
| 11902 LocalContext context; | 11899 LocalContext context; |
| 11903 v8::Isolate* isolate = context->GetIsolate(); | 11900 v8::Isolate* isolate = context->GetIsolate(); |
| 11904 | 11901 |
| 11905 v8::Persistent<v8::Object> handle1, handle2, handle3; | 11902 v8::Persistent<v8::Object> handle1, handle2, handle3; |
| 11906 { | 11903 { |
| 11907 v8::HandleScope scope(isolate); | 11904 v8::HandleScope scope(isolate); |
| 11908 handle3.Reset(isolate, v8::Object::New(isolate)); | 11905 handle3.Reset(isolate, v8::Object::New(isolate)); |
| 11909 handle2.Reset(isolate, v8::Object::New(isolate)); | 11906 handle2.Reset(isolate, v8::Object::New(isolate)); |
| 11910 handle1.Reset(isolate, v8::Object::New(isolate)); | 11907 handle1.Reset(isolate, v8::Object::New(isolate)); |
| 11911 } | 11908 } |
| 11912 handle2.SetWeak(&handle2, DisposingCallback); | 11909 handle2.SetWeak(&handle2, DisposingCallback); |
| 11913 handle3.SetWeak(&handle3, HandleCreatingCallback); | 11910 handle3.SetWeak(&handle3, HandleCreatingCallback); |
| 11914 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 11911 CcTest::heap()->CollectAllGarbage(); |
| 11915 } | 11912 } |
| 11916 | 11913 |
| 11917 | 11914 |
| 11918 THREADED_TEST(CheckForCrossContextObjectLiterals) { | 11915 THREADED_TEST(CheckForCrossContextObjectLiterals) { |
| 11919 v8::V8::Initialize(); | 11916 v8::V8::Initialize(); |
| 11920 | 11917 |
| 11921 const int nof = 2; | 11918 const int nof = 2; |
| 11922 const char* sources[nof] = { | 11919 const char* sources[nof] = { |
| 11923 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }", | 11920 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }", |
| 11924 "Object()" | 11921 "Object()" |
| (...skipping 1599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13524 i::Factory* factory = isolate->factory(); | 13521 i::Factory* factory = isolate->factory(); |
| 13525 v8::HandleScope scope(context->GetIsolate()); | 13522 v8::HandleScope scope(context->GetIsolate()); |
| 13526 const int kElementCount = 260; | 13523 const int kElementCount = 260; |
| 13527 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); | 13524 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); |
| 13528 i::Handle<i::ExternalUint8ClampedArray> pixels = | 13525 i::Handle<i::ExternalUint8ClampedArray> pixels = |
| 13529 i::Handle<i::ExternalUint8ClampedArray>::cast( | 13526 i::Handle<i::ExternalUint8ClampedArray>::cast( |
| 13530 factory->NewExternalArray(kElementCount, | 13527 factory->NewExternalArray(kElementCount, |
| 13531 v8::kExternalUint8ClampedArray, | 13528 v8::kExternalUint8ClampedArray, |
| 13532 pixel_data)); | 13529 pixel_data)); |
| 13533 // Force GC to trigger verification. | 13530 // Force GC to trigger verification. |
| 13534 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 13531 CcTest::heap()->CollectAllGarbage(); |
| 13535 for (int i = 0; i < kElementCount; i++) { | 13532 for (int i = 0; i < kElementCount; i++) { |
| 13536 pixels->set(i, i % 256); | 13533 pixels->set(i, i % 256); |
| 13537 } | 13534 } |
| 13538 // Force GC to trigger verification. | 13535 // Force GC to trigger verification. |
| 13539 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 13536 CcTest::heap()->CollectAllGarbage(); |
| 13540 for (int i = 0; i < kElementCount; i++) { | 13537 for (int i = 0; i < kElementCount; i++) { |
| 13541 CHECK_EQ(i % 256, pixels->get_scalar(i)); | 13538 CHECK_EQ(i % 256, pixels->get_scalar(i)); |
| 13542 CHECK_EQ(i % 256, pixel_data[i]); | 13539 CHECK_EQ(i % 256, pixel_data[i]); |
| 13543 } | 13540 } |
| 13544 | 13541 |
| 13545 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate()); | 13542 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate()); |
| 13546 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); | 13543 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); |
| 13547 // Set the elements to be the pixels. | 13544 // Set the elements to be the pixels. |
| 13548 // jsobj->set_elements(*pixels); | 13545 // jsobj->set_elements(*pixels); |
| 13549 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); | 13546 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14104 "var sum = 0;" | 14101 "var sum = 0;" |
| 14105 "for (var i = 0; i < 8; i++) {" | 14102 "for (var i = 0; i < 8; i++) {" |
| 14106 " tmp_array[i] = i;" | 14103 " tmp_array[i] = i;" |
| 14107 " sum += tmp_array[i];" | 14104 " sum += tmp_array[i];" |
| 14108 " if (i == 4) {" | 14105 " if (i == 4) {" |
| 14109 " tmp_array = {};" | 14106 " tmp_array = {};" |
| 14110 " }" | 14107 " }" |
| 14111 "}" | 14108 "}" |
| 14112 "sum;"); | 14109 "sum;"); |
| 14113 // Force GC to trigger verification. | 14110 // Force GC to trigger verification. |
| 14114 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 14111 CcTest::heap()->CollectAllGarbage(); |
| 14115 CHECK_EQ(28, result->Int32Value()); | 14112 CHECK_EQ(28, result->Int32Value()); |
| 14116 | 14113 |
| 14117 // Make sure out-of-range loads do not throw. | 14114 // Make sure out-of-range loads do not throw. |
| 14118 i::SNPrintF(test_buf, | 14115 i::SNPrintF(test_buf, |
| 14119 "var caught_exception = false;" | 14116 "var caught_exception = false;" |
| 14120 "try {" | 14117 "try {" |
| 14121 " ext_array[%d];" | 14118 " ext_array[%d];" |
| 14122 "} catch (e) {" | 14119 "} catch (e) {" |
| 14123 " caught_exception = true;" | 14120 " caught_exception = true;" |
| 14124 "}" | 14121 "}" |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14311 i::Isolate* isolate = CcTest::i_isolate(); | 14308 i::Isolate* isolate = CcTest::i_isolate(); |
| 14312 i::Factory* factory = isolate->factory(); | 14309 i::Factory* factory = isolate->factory(); |
| 14313 v8::HandleScope scope(context->GetIsolate()); | 14310 v8::HandleScope scope(context->GetIsolate()); |
| 14314 const int kElementCount = 260; | 14311 const int kElementCount = 260; |
| 14315 i::Handle<FixedTypedArrayClass> fixed_array = | 14312 i::Handle<FixedTypedArrayClass> fixed_array = |
| 14316 i::Handle<FixedTypedArrayClass>::cast( | 14313 i::Handle<FixedTypedArrayClass>::cast( |
| 14317 factory->NewFixedTypedArray(kElementCount, array_type)); | 14314 factory->NewFixedTypedArray(kElementCount, array_type)); |
| 14318 CHECK_EQ(FixedTypedArrayClass::kInstanceType, | 14315 CHECK_EQ(FixedTypedArrayClass::kInstanceType, |
| 14319 fixed_array->map()->instance_type()); | 14316 fixed_array->map()->instance_type()); |
| 14320 CHECK_EQ(kElementCount, fixed_array->length()); | 14317 CHECK_EQ(kElementCount, fixed_array->length()); |
| 14321 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 14318 CcTest::heap()->CollectAllGarbage(); |
| 14322 for (int i = 0; i < kElementCount; i++) { | 14319 for (int i = 0; i < kElementCount; i++) { |
| 14323 fixed_array->set(i, static_cast<ElementType>(i)); | 14320 fixed_array->set(i, static_cast<ElementType>(i)); |
| 14324 } | 14321 } |
| 14325 // Force GC to trigger verification. | 14322 // Force GC to trigger verification. |
| 14326 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 14323 CcTest::heap()->CollectAllGarbage(); |
| 14327 for (int i = 0; i < kElementCount; i++) { | 14324 for (int i = 0; i < kElementCount; i++) { |
| 14328 CHECK_EQ(static_cast<int64_t>(static_cast<ElementType>(i)), | 14325 CHECK_EQ(static_cast<int64_t>(static_cast<ElementType>(i)), |
| 14329 static_cast<int64_t>(fixed_array->get_scalar(i))); | 14326 static_cast<int64_t>(fixed_array->get_scalar(i))); |
| 14330 } | 14327 } |
| 14331 v8::Handle<v8::Object> obj = v8::Object::New(CcTest::isolate()); | 14328 v8::Handle<v8::Object> obj = v8::Object::New(CcTest::isolate()); |
| 14332 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); | 14329 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); |
| 14333 i::Handle<i::Map> fixed_array_map = | 14330 i::Handle<i::Map> fixed_array_map = |
| 14334 i::JSObject::GetElementsTransitionMap(jsobj, elements_kind); | 14331 i::JSObject::GetElementsTransitionMap(jsobj, elements_kind); |
| 14335 jsobj->set_map(*fixed_array_map); | 14332 jsobj->set_map(*fixed_array_map); |
| 14336 jsobj->set_elements(*fixed_array); | 14333 jsobj->set_elements(*fixed_array); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14415 i::Factory* factory = isolate->factory(); | 14412 i::Factory* factory = isolate->factory(); |
| 14416 v8::HandleScope scope(context->GetIsolate()); | 14413 v8::HandleScope scope(context->GetIsolate()); |
| 14417 const int kElementCount = 40; | 14414 const int kElementCount = 40; |
| 14418 int element_size = ExternalArrayElementSize(array_type); | 14415 int element_size = ExternalArrayElementSize(array_type); |
| 14419 ElementType* array_data = | 14416 ElementType* array_data = |
| 14420 static_cast<ElementType*>(malloc(kElementCount * element_size)); | 14417 static_cast<ElementType*>(malloc(kElementCount * element_size)); |
| 14421 i::Handle<ExternalArrayClass> array = | 14418 i::Handle<ExternalArrayClass> array = |
| 14422 i::Handle<ExternalArrayClass>::cast( | 14419 i::Handle<ExternalArrayClass>::cast( |
| 14423 factory->NewExternalArray(kElementCount, array_type, array_data)); | 14420 factory->NewExternalArray(kElementCount, array_type, array_data)); |
| 14424 // Force GC to trigger verification. | 14421 // Force GC to trigger verification. |
| 14425 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 14422 CcTest::heap()->CollectAllGarbage(); |
| 14426 for (int i = 0; i < kElementCount; i++) { | 14423 for (int i = 0; i < kElementCount; i++) { |
| 14427 array->set(i, static_cast<ElementType>(i)); | 14424 array->set(i, static_cast<ElementType>(i)); |
| 14428 } | 14425 } |
| 14429 // Force GC to trigger verification. | 14426 // Force GC to trigger verification. |
| 14430 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 14427 CcTest::heap()->CollectAllGarbage(); |
| 14431 for (int i = 0; i < kElementCount; i++) { | 14428 for (int i = 0; i < kElementCount; i++) { |
| 14432 CHECK_EQ(static_cast<int64_t>(i), | 14429 CHECK_EQ(static_cast<int64_t>(i), |
| 14433 static_cast<int64_t>(array->get_scalar(i))); | 14430 static_cast<int64_t>(array->get_scalar(i))); |
| 14434 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(array_data[i])); | 14431 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(array_data[i])); |
| 14435 } | 14432 } |
| 14436 | 14433 |
| 14437 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate()); | 14434 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate()); |
| 14438 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); | 14435 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); |
| 14439 // Set the elements to be the external array. | 14436 // Set the elements to be the external array. |
| 14440 obj->SetIndexedPropertiesToExternalArrayData(array_data, | 14437 obj->SetIndexedPropertiesToExternalArrayData(array_data, |
| (...skipping 2034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16475 Local<v8::String> obj = v8::String::NewFromUtf8(isolate, ""); | 16472 Local<v8::String> obj = v8::String::NewFromUtf8(isolate, ""); |
| 16476 context->SetEmbedderData(0, obj); | 16473 context->SetEmbedderData(0, obj); |
| 16477 CompileRun(source_simple); | 16474 CompileRun(source_simple); |
| 16478 context->Exit(); | 16475 context->Exit(); |
| 16479 } | 16476 } |
| 16480 isolate->ContextDisposedNotification(); | 16477 isolate->ContextDisposedNotification(); |
| 16481 for (gc_count = 1; gc_count < 10; gc_count++) { | 16478 for (gc_count = 1; gc_count < 10; gc_count++) { |
| 16482 other_context->Enter(); | 16479 other_context->Enter(); |
| 16483 CompileRun(source_simple); | 16480 CompileRun(source_simple); |
| 16484 other_context->Exit(); | 16481 other_context->Exit(); |
| 16485 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 16482 CcTest::heap()->CollectAllGarbage(); |
| 16486 if (GetGlobalObjectsCount() == 1) break; | 16483 if (GetGlobalObjectsCount() == 1) break; |
| 16487 } | 16484 } |
| 16488 CHECK_GE(2, gc_count); | 16485 CHECK_GE(2, gc_count); |
| 16489 CHECK_EQ(1, GetGlobalObjectsCount()); | 16486 CHECK_EQ(1, GetGlobalObjectsCount()); |
| 16490 | 16487 |
| 16491 // Eval in a function creates reference from the compilation cache to the | 16488 // Eval in a function creates reference from the compilation cache to the |
| 16492 // global object. | 16489 // global object. |
| 16493 const char* source_eval = "function f(){eval('1')}; f()"; | 16490 const char* source_eval = "function f(){eval('1')}; f()"; |
| 16494 { | 16491 { |
| 16495 v8::HandleScope scope(isolate); | 16492 v8::HandleScope scope(isolate); |
| 16496 v8::Local<Context> context = Context::New(isolate); | 16493 v8::Local<Context> context = Context::New(isolate); |
| 16497 | 16494 |
| 16498 context->Enter(); | 16495 context->Enter(); |
| 16499 CompileRun(source_eval); | 16496 CompileRun(source_eval); |
| 16500 context->Exit(); | 16497 context->Exit(); |
| 16501 } | 16498 } |
| 16502 isolate->ContextDisposedNotification(); | 16499 isolate->ContextDisposedNotification(); |
| 16503 for (gc_count = 1; gc_count < 10; gc_count++) { | 16500 for (gc_count = 1; gc_count < 10; gc_count++) { |
| 16504 other_context->Enter(); | 16501 other_context->Enter(); |
| 16505 CompileRun(source_eval); | 16502 CompileRun(source_eval); |
| 16506 other_context->Exit(); | 16503 other_context->Exit(); |
| 16507 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 16504 CcTest::heap()->CollectAllGarbage(); |
| 16508 if (GetGlobalObjectsCount() == 1) break; | 16505 if (GetGlobalObjectsCount() == 1) break; |
| 16509 } | 16506 } |
| 16510 CHECK_GE(2, gc_count); | 16507 CHECK_GE(2, gc_count); |
| 16511 CHECK_EQ(1, GetGlobalObjectsCount()); | 16508 CHECK_EQ(1, GetGlobalObjectsCount()); |
| 16512 | 16509 |
| 16513 // Looking up the line number for an exception creates reference from the | 16510 // Looking up the line number for an exception creates reference from the |
| 16514 // compilation cache to the global object. | 16511 // compilation cache to the global object. |
| 16515 const char* source_exception = "function f(){throw 1;} f()"; | 16512 const char* source_exception = "function f(){throw 1;} f()"; |
| 16516 { | 16513 { |
| 16517 v8::HandleScope scope(isolate); | 16514 v8::HandleScope scope(isolate); |
| 16518 v8::Local<Context> context = Context::New(isolate); | 16515 v8::Local<Context> context = Context::New(isolate); |
| 16519 | 16516 |
| 16520 context->Enter(); | 16517 context->Enter(); |
| 16521 v8::TryCatch try_catch; | 16518 v8::TryCatch try_catch; |
| 16522 CompileRun(source_exception); | 16519 CompileRun(source_exception); |
| 16523 CHECK(try_catch.HasCaught()); | 16520 CHECK(try_catch.HasCaught()); |
| 16524 v8::Handle<v8::Message> message = try_catch.Message(); | 16521 v8::Handle<v8::Message> message = try_catch.Message(); |
| 16525 CHECK(!message.IsEmpty()); | 16522 CHECK(!message.IsEmpty()); |
| 16526 CHECK_EQ(1, message->GetLineNumber()); | 16523 CHECK_EQ(1, message->GetLineNumber()); |
| 16527 context->Exit(); | 16524 context->Exit(); |
| 16528 } | 16525 } |
| 16529 isolate->ContextDisposedNotification(); | 16526 isolate->ContextDisposedNotification(); |
| 16530 for (gc_count = 1; gc_count < 10; gc_count++) { | 16527 for (gc_count = 1; gc_count < 10; gc_count++) { |
| 16531 other_context->Enter(); | 16528 other_context->Enter(); |
| 16532 CompileRun(source_exception); | 16529 CompileRun(source_exception); |
| 16533 other_context->Exit(); | 16530 other_context->Exit(); |
| 16534 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 16531 CcTest::heap()->CollectAllGarbage(); |
| 16535 if (GetGlobalObjectsCount() == 1) break; | 16532 if (GetGlobalObjectsCount() == 1) break; |
| 16536 } | 16533 } |
| 16537 CHECK_GE(2, gc_count); | 16534 CHECK_GE(2, gc_count); |
| 16538 CHECK_EQ(1, GetGlobalObjectsCount()); | 16535 CHECK_EQ(1, GetGlobalObjectsCount()); |
| 16539 | 16536 |
| 16540 isolate->ContextDisposedNotification(); | 16537 isolate->ContextDisposedNotification(); |
| 16541 } | 16538 } |
| 16542 | 16539 |
| 16543 | 16540 |
| 16544 THREADED_TEST(ScriptOrigin) { | 16541 THREADED_TEST(ScriptOrigin) { |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17044 } | 17041 } |
| 17045 | 17042 |
| 17046 | 17043 |
| 17047 TEST(GCCallbacksOld) { | 17044 TEST(GCCallbacksOld) { |
| 17048 LocalContext context; | 17045 LocalContext context; |
| 17049 | 17046 |
| 17050 v8::V8::AddGCPrologueCallback(PrologueCallback); | 17047 v8::V8::AddGCPrologueCallback(PrologueCallback); |
| 17051 v8::V8::AddGCEpilogueCallback(EpilogueCallback); | 17048 v8::V8::AddGCEpilogueCallback(EpilogueCallback); |
| 17052 CHECK_EQ(0, prologue_call_count); | 17049 CHECK_EQ(0, prologue_call_count); |
| 17053 CHECK_EQ(0, epilogue_call_count); | 17050 CHECK_EQ(0, epilogue_call_count); |
| 17054 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 17051 CcTest::heap()->CollectAllGarbage(); |
| 17055 CHECK_EQ(1, prologue_call_count); | 17052 CHECK_EQ(1, prologue_call_count); |
| 17056 CHECK_EQ(1, epilogue_call_count); | 17053 CHECK_EQ(1, epilogue_call_count); |
| 17057 v8::V8::AddGCPrologueCallback(PrologueCallbackSecond); | 17054 v8::V8::AddGCPrologueCallback(PrologueCallbackSecond); |
| 17058 v8::V8::AddGCEpilogueCallback(EpilogueCallbackSecond); | 17055 v8::V8::AddGCEpilogueCallback(EpilogueCallbackSecond); |
| 17059 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 17056 CcTest::heap()->CollectAllGarbage(); |
| 17060 CHECK_EQ(2, prologue_call_count); | 17057 CHECK_EQ(2, prologue_call_count); |
| 17061 CHECK_EQ(2, epilogue_call_count); | 17058 CHECK_EQ(2, epilogue_call_count); |
| 17062 CHECK_EQ(1, prologue_call_count_second); | 17059 CHECK_EQ(1, prologue_call_count_second); |
| 17063 CHECK_EQ(1, epilogue_call_count_second); | 17060 CHECK_EQ(1, epilogue_call_count_second); |
| 17064 v8::V8::RemoveGCPrologueCallback(PrologueCallback); | 17061 v8::V8::RemoveGCPrologueCallback(PrologueCallback); |
| 17065 v8::V8::RemoveGCEpilogueCallback(EpilogueCallback); | 17062 v8::V8::RemoveGCEpilogueCallback(EpilogueCallback); |
| 17066 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 17063 CcTest::heap()->CollectAllGarbage(); |
| 17067 CHECK_EQ(2, prologue_call_count); | 17064 CHECK_EQ(2, prologue_call_count); |
| 17068 CHECK_EQ(2, epilogue_call_count); | 17065 CHECK_EQ(2, epilogue_call_count); |
| 17069 CHECK_EQ(2, prologue_call_count_second); | 17066 CHECK_EQ(2, prologue_call_count_second); |
| 17070 CHECK_EQ(2, epilogue_call_count_second); | 17067 CHECK_EQ(2, epilogue_call_count_second); |
| 17071 v8::V8::RemoveGCPrologueCallback(PrologueCallbackSecond); | 17068 v8::V8::RemoveGCPrologueCallback(PrologueCallbackSecond); |
| 17072 v8::V8::RemoveGCEpilogueCallback(EpilogueCallbackSecond); | 17069 v8::V8::RemoveGCEpilogueCallback(EpilogueCallbackSecond); |
| 17073 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 17070 CcTest::heap()->CollectAllGarbage(); |
| 17074 CHECK_EQ(2, prologue_call_count); | 17071 CHECK_EQ(2, prologue_call_count); |
| 17075 CHECK_EQ(2, epilogue_call_count); | 17072 CHECK_EQ(2, epilogue_call_count); |
| 17076 CHECK_EQ(2, prologue_call_count_second); | 17073 CHECK_EQ(2, prologue_call_count_second); |
| 17077 CHECK_EQ(2, epilogue_call_count_second); | 17074 CHECK_EQ(2, epilogue_call_count_second); |
| 17078 } | 17075 } |
| 17079 | 17076 |
| 17080 | 17077 |
| 17081 TEST(GCCallbacks) { | 17078 TEST(GCCallbacks) { |
| 17082 LocalContext context; | 17079 LocalContext context; |
| 17083 v8::Isolate* isolate = context->GetIsolate(); | 17080 v8::Isolate* isolate = context->GetIsolate(); |
| 17084 gc_callbacks_isolate = isolate; | 17081 gc_callbacks_isolate = isolate; |
| 17085 isolate->AddGCPrologueCallback(PrologueCallback); | 17082 isolate->AddGCPrologueCallback(PrologueCallback); |
| 17086 isolate->AddGCEpilogueCallback(EpilogueCallback); | 17083 isolate->AddGCEpilogueCallback(EpilogueCallback); |
| 17087 CHECK_EQ(0, prologue_call_count); | 17084 CHECK_EQ(0, prologue_call_count); |
| 17088 CHECK_EQ(0, epilogue_call_count); | 17085 CHECK_EQ(0, epilogue_call_count); |
| 17089 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 17086 CcTest::heap()->CollectAllGarbage(); |
| 17090 CHECK_EQ(1, prologue_call_count); | 17087 CHECK_EQ(1, prologue_call_count); |
| 17091 CHECK_EQ(1, epilogue_call_count); | 17088 CHECK_EQ(1, epilogue_call_count); |
| 17092 isolate->AddGCPrologueCallback(PrologueCallbackSecond); | 17089 isolate->AddGCPrologueCallback(PrologueCallbackSecond); |
| 17093 isolate->AddGCEpilogueCallback(EpilogueCallbackSecond); | 17090 isolate->AddGCEpilogueCallback(EpilogueCallbackSecond); |
| 17094 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 17091 CcTest::heap()->CollectAllGarbage(); |
| 17095 CHECK_EQ(2, prologue_call_count); | 17092 CHECK_EQ(2, prologue_call_count); |
| 17096 CHECK_EQ(2, epilogue_call_count); | 17093 CHECK_EQ(2, epilogue_call_count); |
| 17097 CHECK_EQ(1, prologue_call_count_second); | 17094 CHECK_EQ(1, prologue_call_count_second); |
| 17098 CHECK_EQ(1, epilogue_call_count_second); | 17095 CHECK_EQ(1, epilogue_call_count_second); |
| 17099 isolate->RemoveGCPrologueCallback(PrologueCallback); | 17096 isolate->RemoveGCPrologueCallback(PrologueCallback); |
| 17100 isolate->RemoveGCEpilogueCallback(EpilogueCallback); | 17097 isolate->RemoveGCEpilogueCallback(EpilogueCallback); |
| 17101 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 17098 CcTest::heap()->CollectAllGarbage(); |
| 17102 CHECK_EQ(2, prologue_call_count); | 17099 CHECK_EQ(2, prologue_call_count); |
| 17103 CHECK_EQ(2, epilogue_call_count); | 17100 CHECK_EQ(2, epilogue_call_count); |
| 17104 CHECK_EQ(2, prologue_call_count_second); | 17101 CHECK_EQ(2, prologue_call_count_second); |
| 17105 CHECK_EQ(2, epilogue_call_count_second); | 17102 CHECK_EQ(2, epilogue_call_count_second); |
| 17106 isolate->RemoveGCPrologueCallback(PrologueCallbackSecond); | 17103 isolate->RemoveGCPrologueCallback(PrologueCallbackSecond); |
| 17107 isolate->RemoveGCEpilogueCallback(EpilogueCallbackSecond); | 17104 isolate->RemoveGCEpilogueCallback(EpilogueCallbackSecond); |
| 17108 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 17105 CcTest::heap()->CollectAllGarbage(); |
| 17109 CHECK_EQ(2, prologue_call_count); | 17106 CHECK_EQ(2, prologue_call_count); |
| 17110 CHECK_EQ(2, epilogue_call_count); | 17107 CHECK_EQ(2, epilogue_call_count); |
| 17111 CHECK_EQ(2, prologue_call_count_second); | 17108 CHECK_EQ(2, prologue_call_count_second); |
| 17112 CHECK_EQ(2, epilogue_call_count_second); | 17109 CHECK_EQ(2, epilogue_call_count_second); |
| 17113 | 17110 |
| 17114 CHECK_EQ(0, prologue_call_count_alloc); | 17111 CHECK_EQ(0, prologue_call_count_alloc); |
| 17115 CHECK_EQ(0, epilogue_call_count_alloc); | 17112 CHECK_EQ(0, epilogue_call_count_alloc); |
| 17116 isolate->AddGCPrologueCallback(PrologueCallbackAlloc); | 17113 isolate->AddGCPrologueCallback(PrologueCallbackAlloc); |
| 17117 isolate->AddGCEpilogueCallback(EpilogueCallbackAlloc); | 17114 isolate->AddGCEpilogueCallback(EpilogueCallbackAlloc); |
| 17118 CcTest::heap()->CollectAllGarbage( | 17115 CcTest::heap()->CollectAllGarbage( |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17394 string_contents[zero_offset] = 0x41; | 17391 string_contents[zero_offset] = 0x41; |
| 17395 } | 17392 } |
| 17396 } | 17393 } |
| 17397 } | 17394 } |
| 17398 | 17395 |
| 17399 | 17396 |
| 17400 // Failed access check callback that performs a GC on each invocation. | 17397 // Failed access check callback that performs a GC on each invocation. |
| 17401 void FailedAccessCheckCallbackGC(Local<v8::Object> target, | 17398 void FailedAccessCheckCallbackGC(Local<v8::Object> target, |
| 17402 v8::AccessType type, | 17399 v8::AccessType type, |
| 17403 Local<v8::Value> data) { | 17400 Local<v8::Value> data) { |
| 17404 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 17401 CcTest::heap()->CollectAllGarbage(); |
| 17405 } | 17402 } |
| 17406 | 17403 |
| 17407 | 17404 |
| 17408 TEST(GCInFailedAccessCheckCallback) { | 17405 TEST(GCInFailedAccessCheckCallback) { |
| 17409 // Install a failed access check callback that performs a GC on each | 17406 // Install a failed access check callback that performs a GC on each |
| 17410 // invocation. Then force the callback to be called from va | 17407 // invocation. Then force the callback to be called from va |
| 17411 | 17408 |
| 17412 v8::V8::Initialize(); | 17409 v8::V8::Initialize(); |
| 17413 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckCallbackGC); | 17410 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckCallbackGC); |
| 17414 | 17411 |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17913 ExpectBoolean("delete cell", true); | 17910 ExpectBoolean("delete cell", true); |
| 17914 ExpectString("(function() {" | 17911 ExpectString("(function() {" |
| 17915 " try {" | 17912 " try {" |
| 17916 " return readCell();" | 17913 " return readCell();" |
| 17917 " } catch(e) {" | 17914 " } catch(e) {" |
| 17918 " return e.toString();" | 17915 " return e.toString();" |
| 17919 " }" | 17916 " }" |
| 17920 "})()", | 17917 "})()", |
| 17921 "ReferenceError: cell is not defined"); | 17918 "ReferenceError: cell is not defined"); |
| 17922 CompileRun("cell = \"new_second\";"); | 17919 CompileRun("cell = \"new_second\";"); |
| 17923 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 17920 CcTest::heap()->CollectAllGarbage(); |
| 17924 ExpectString("readCell()", "new_second"); | 17921 ExpectString("readCell()", "new_second"); |
| 17925 ExpectString("readCell()", "new_second"); | 17922 ExpectString("readCell()", "new_second"); |
| 17926 } | 17923 } |
| 17927 } | 17924 } |
| 17928 | 17925 |
| 17929 | 17926 |
| 17930 class Visitor42 : public v8::PersistentHandleVisitor { | 17927 class Visitor42 : public v8::PersistentHandleVisitor { |
| 17931 public: | 17928 public: |
| 17932 explicit Visitor42(v8::Persistent<v8::Object>* object) | 17929 explicit Visitor42(v8::Persistent<v8::Object>* object) |
| 17933 : counter_(0), object_(object) { } | 17930 : counter_(0), object_(object) { } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17982 | 17979 |
| 17983 TEST(PersistentHandleInNewSpaceVisitor) { | 17980 TEST(PersistentHandleInNewSpaceVisitor) { |
| 17984 LocalContext context; | 17981 LocalContext context; |
| 17985 v8::Isolate* isolate = context->GetIsolate(); | 17982 v8::Isolate* isolate = context->GetIsolate(); |
| 17986 v8::HandleScope scope(isolate); | 17983 v8::HandleScope scope(isolate); |
| 17987 v8::Persistent<v8::Object> object1(isolate, v8::Object::New(isolate)); | 17984 v8::Persistent<v8::Object> object1(isolate, v8::Object::New(isolate)); |
| 17988 CHECK_EQ(0, object1.WrapperClassId()); | 17985 CHECK_EQ(0, object1.WrapperClassId()); |
| 17989 object1.SetWrapperClassId(42); | 17986 object1.SetWrapperClassId(42); |
| 17990 CHECK_EQ(42, object1.WrapperClassId()); | 17987 CHECK_EQ(42, object1.WrapperClassId()); |
| 17991 | 17988 |
| 17992 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 17989 CcTest::heap()->CollectAllGarbage(); |
| 17993 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 17990 CcTest::heap()->CollectAllGarbage(); |
| 17994 | 17991 |
| 17995 v8::Persistent<v8::Object> object2(isolate, v8::Object::New(isolate)); | 17992 v8::Persistent<v8::Object> object2(isolate, v8::Object::New(isolate)); |
| 17996 CHECK_EQ(0, object2.WrapperClassId()); | 17993 CHECK_EQ(0, object2.WrapperClassId()); |
| 17997 object2.SetWrapperClassId(42); | 17994 object2.SetWrapperClassId(42); |
| 17998 CHECK_EQ(42, object2.WrapperClassId()); | 17995 CHECK_EQ(42, object2.WrapperClassId()); |
| 17999 | 17996 |
| 18000 Visitor42 visitor(&object2); | 17997 Visitor42 visitor(&object2); |
| 18001 v8::V8::VisitHandlesForPartialDependence(isolate, &visitor); | 17998 v8::V8::VisitHandlesForPartialDependence(isolate, &visitor); |
| 18002 CHECK_EQ(1, visitor.counter_); | 17999 CHECK_EQ(1, visitor.counter_); |
| 18003 | 18000 |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18549 "'a00': 0, 'a01': 0, 'a02': 0, 'a03': 0, 'a04': 0, " | 18546 "'a00': 0, 'a01': 0, 'a02': 0, 'a03': 0, 'a04': 0, " |
| 18550 "'a05': 0, 'a06': 0, 'a07': 0, 'a08': 0, 'a09': 0, " | 18547 "'a05': 0, 'a06': 0, 'a07': 0, 'a08': 0, 'a09': 0, " |
| 18551 "'a10': 0, 'a11': 0, 'a12': 0, 'a13': 0, 'a14': 0, " | 18548 "'a10': 0, 'a11': 0, 'a12': 0, 'a13': 0, 'a14': 0, " |
| 18552 "'a15': 0, 'a16': 0, 'a17': 0, 'a18': 0, 'a19': 0, " | 18549 "'a15': 0, 'a16': 0, 'a17': 0, 'a18': 0, 'a19': 0, " |
| 18553 "})"); | 18550 "})"); |
| 18554 } | 18551 } |
| 18555 | 18552 |
| 18556 int elements = CountLiveMapsInMapCache(CcTest::i_isolate()->context()); | 18553 int elements = CountLiveMapsInMapCache(CcTest::i_isolate()->context()); |
| 18557 CHECK_LE(1, elements); | 18554 CHECK_LE(1, elements); |
| 18558 | 18555 |
| 18559 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 18556 CcTest::heap()->CollectAllGarbage(); |
| 18560 | 18557 |
| 18561 CHECK_GT(elements, CountLiveMapsInMapCache(CcTest::i_isolate()->context())); | 18558 CHECK_GT(elements, CountLiveMapsInMapCache(CcTest::i_isolate()->context())); |
| 18562 } | 18559 } |
| 18563 | 18560 |
| 18564 | 18561 |
| 18565 THREADED_TEST(Regress93759) { | 18562 THREADED_TEST(Regress93759) { |
| 18566 v8::Isolate* isolate = CcTest::isolate(); | 18563 v8::Isolate* isolate = CcTest::isolate(); |
| 18567 HandleScope scope(isolate); | 18564 HandleScope scope(isolate); |
| 18568 | 18565 |
| 18569 // Template for object with security check. | 18566 // Template for object with security check. |
| (...skipping 3341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21911 | 21908 |
| 21912 { | 21909 { |
| 21913 v8::HandleScope handle_scope(isolate); | 21910 v8::HandleScope handle_scope(isolate); |
| 21914 | 21911 |
| 21915 // Should work | 21912 // Should work |
| 21916 v8::Local<v8::Object> obj = v8::Object::New(isolate); | 21913 v8::Local<v8::Object> obj = v8::Object::New(isolate); |
| 21917 | 21914 |
| 21918 USE(obj); | 21915 USE(obj); |
| 21919 } | 21916 } |
| 21920 } | 21917 } |
| OLD | NEW |