Chromium Code Reviews| 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 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 CHECK(source->IsExternal()); | 483 CHECK(source->IsExternal()); |
| 484 CHECK_EQ(resource, | 484 CHECK_EQ(resource, |
| 485 static_cast<TestResource*>(source->GetExternalStringResource())); | 485 static_cast<TestResource*>(source->GetExternalStringResource())); |
| 486 String::Encoding encoding = String::UNKNOWN_ENCODING; | 486 String::Encoding encoding = String::UNKNOWN_ENCODING; |
| 487 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), | 487 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), |
| 488 source->GetExternalStringResourceBase(&encoding)); | 488 source->GetExternalStringResourceBase(&encoding)); |
| 489 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding); | 489 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding); |
| 490 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 490 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 491 CHECK_EQ(0, dispose_count); | 491 CHECK_EQ(0, dispose_count); |
| 492 } | 492 } |
| 493 CcTest::i_isolate()->compilation_cache()->Clear(); | 493 CcTest::heap()->CollectAllAvailableGarbage("test external string", 1); |
| 494 CcTest::heap()->CollectAllAvailableGarbage(); | |
| 495 CHECK_EQ(1, dispose_count); | 494 CHECK_EQ(1, dispose_count); |
| 496 } | 495 } |
| 497 | 496 |
| 498 | 497 |
| 499 THREADED_TEST(ScriptUsingOneByteStringResource) { | 498 THREADED_TEST(ScriptUsingOneByteStringResource) { |
| 500 int dispose_count = 0; | 499 int dispose_count = 0; |
| 501 const char* c_source = "1 + 2 * 3"; | 500 const char* c_source = "1 + 2 * 3"; |
| 502 { | 501 { |
| 503 LocalContext env; | 502 LocalContext env; |
| 504 v8::HandleScope scope(env->GetIsolate()); | 503 v8::HandleScope scope(env->GetIsolate()); |
| 505 TestOneByteResource* resource = | 504 TestOneByteResource* resource = |
| 506 new TestOneByteResource(i::StrDup(c_source), &dispose_count); | 505 new TestOneByteResource(i::StrDup(c_source), &dispose_count); |
| 507 Local<String> source = String::NewExternal(env->GetIsolate(), resource); | 506 Local<String> source = String::NewExternal(env->GetIsolate(), resource); |
| 508 CHECK(source->IsExternalOneByte()); | 507 CHECK(source->IsExternalOneByte()); |
| 509 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), | 508 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), |
| 510 source->GetExternalOneByteStringResource()); | 509 source->GetExternalOneByteStringResource()); |
| 511 String::Encoding encoding = String::UNKNOWN_ENCODING; | 510 String::Encoding encoding = String::UNKNOWN_ENCODING; |
| 512 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), | 511 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), |
| 513 source->GetExternalStringResourceBase(&encoding)); | 512 source->GetExternalStringResourceBase(&encoding)); |
| 514 CHECK_EQ(String::ONE_BYTE_ENCODING, encoding); | 513 CHECK_EQ(String::ONE_BYTE_ENCODING, encoding); |
| 515 Local<Script> script = v8_compile(source); | 514 Local<Script> script = v8_compile(source); |
| 516 Local<Value> value = script->Run(); | 515 Local<Value> value = script->Run(); |
| 517 CHECK(value->IsNumber()); | 516 CHECK(value->IsNumber()); |
| 518 CHECK_EQ(7, value->Int32Value()); | 517 CHECK_EQ(7, value->Int32Value()); |
| 519 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 518 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 520 CHECK_EQ(0, dispose_count); | 519 CHECK_EQ(0, dispose_count); |
| 521 } | 520 } |
| 522 CcTest::i_isolate()->compilation_cache()->Clear(); | 521 CcTest::heap()->CollectAllAvailableGarbage("test external string", 1); |
| 523 CcTest::heap()->CollectAllAvailableGarbage(); | |
| 524 CHECK_EQ(1, dispose_count); | 522 CHECK_EQ(1, dispose_count); |
| 525 } | 523 } |
| 526 | 524 |
| 527 | 525 |
| 528 THREADED_TEST(ScriptMakingExternalString) { | 526 THREADED_TEST(ScriptMakingExternalString) { |
| 529 int dispose_count = 0; | 527 int dispose_count = 0; |
| 530 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); | 528 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); |
| 531 { | 529 { |
| 532 LocalContext env; | 530 LocalContext env; |
| 533 v8::HandleScope scope(env->GetIsolate()); | 531 v8::HandleScope scope(env->GetIsolate()); |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 867 LocalContext env; | 865 LocalContext env; |
| 868 v8::HandleScope scope(env->GetIsolate()); | 866 v8::HandleScope scope(env->GetIsolate()); |
| 869 Local<String> source = String::NewExternal(env->GetIsolate(), &res_stack); | 867 Local<String> source = String::NewExternal(env->GetIsolate(), &res_stack); |
| 870 Local<Script> script = v8_compile(source); | 868 Local<Script> script = v8_compile(source); |
| 871 Local<Value> value = script->Run(); | 869 Local<Value> value = script->Run(); |
| 872 CHECK(value->IsNumber()); | 870 CHECK(value->IsNumber()); |
| 873 CHECK_EQ(7, value->Int32Value()); | 871 CHECK_EQ(7, value->Int32Value()); |
| 874 CcTest::heap()->CollectAllAvailableGarbage(); | 872 CcTest::heap()->CollectAllAvailableGarbage(); |
| 875 CHECK_EQ(0, TestOneByteResourceWithDisposeControl::dispose_count); | 873 CHECK_EQ(0, TestOneByteResourceWithDisposeControl::dispose_count); |
| 876 } | 874 } |
| 877 CcTest::i_isolate()->compilation_cache()->Clear(); | 875 CcTest::heap()->CollectAllAvailableGarbage("test external string", 1); |
| 878 CcTest::heap()->CollectAllAvailableGarbage(); | |
| 879 CHECK_EQ(1, TestOneByteResourceWithDisposeControl::dispose_calls); | 876 CHECK_EQ(1, TestOneByteResourceWithDisposeControl::dispose_calls); |
| 880 CHECK_EQ(0, TestOneByteResourceWithDisposeControl::dispose_count); | 877 CHECK_EQ(0, TestOneByteResourceWithDisposeControl::dispose_count); |
| 881 | 878 |
| 882 // Use a heap allocated external string resource allocated object. | 879 // Use a heap allocated external string resource allocated object. |
| 883 TestOneByteResourceWithDisposeControl::dispose_count = 0; | 880 TestOneByteResourceWithDisposeControl::dispose_count = 0; |
| 884 TestOneByteResourceWithDisposeControl::dispose_calls = 0; | 881 TestOneByteResourceWithDisposeControl::dispose_calls = 0; |
| 885 TestOneByteResource* res_heap = | 882 TestOneByteResource* res_heap = |
| 886 new TestOneByteResourceWithDisposeControl(i::StrDup(c_source), true); | 883 new TestOneByteResourceWithDisposeControl(i::StrDup(c_source), true); |
| 887 { | 884 { |
| 888 LocalContext env; | 885 LocalContext env; |
| 889 v8::HandleScope scope(env->GetIsolate()); | 886 v8::HandleScope scope(env->GetIsolate()); |
| 890 Local<String> source = String::NewExternal(env->GetIsolate(), res_heap); | 887 Local<String> source = String::NewExternal(env->GetIsolate(), res_heap); |
| 891 Local<Script> script = v8_compile(source); | 888 Local<Script> script = v8_compile(source); |
| 892 Local<Value> value = script->Run(); | 889 Local<Value> value = script->Run(); |
| 893 CHECK(value->IsNumber()); | 890 CHECK(value->IsNumber()); |
| 894 CHECK_EQ(7, value->Int32Value()); | 891 CHECK_EQ(7, value->Int32Value()); |
| 895 CcTest::heap()->CollectAllAvailableGarbage(); | 892 CcTest::heap()->CollectAllAvailableGarbage(); |
| 896 CHECK_EQ(0, TestOneByteResourceWithDisposeControl::dispose_count); | 893 CHECK_EQ(0, TestOneByteResourceWithDisposeControl::dispose_count); |
| 897 } | 894 } |
| 898 CcTest::i_isolate()->compilation_cache()->Clear(); | 895 CcTest::heap()->CollectAllAvailableGarbage("test external string", 1); |
| 899 CcTest::heap()->CollectAllAvailableGarbage(); | |
| 900 CHECK_EQ(1, TestOneByteResourceWithDisposeControl::dispose_calls); | 896 CHECK_EQ(1, TestOneByteResourceWithDisposeControl::dispose_calls); |
| 901 CHECK_EQ(1, TestOneByteResourceWithDisposeControl::dispose_count); | 897 CHECK_EQ(1, TestOneByteResourceWithDisposeControl::dispose_count); |
| 902 } | 898 } |
| 903 | 899 |
| 904 | 900 |
| 905 THREADED_TEST(StringConcat) { | 901 THREADED_TEST(StringConcat) { |
| 906 { | 902 { |
| 907 LocalContext env; | 903 LocalContext env; |
| 908 v8::HandleScope scope(env->GetIsolate()); | 904 v8::HandleScope scope(env->GetIsolate()); |
| 909 const char* one_byte_string_1 = "function a_times_t"; | 905 const char* one_byte_string_1 = "function a_times_t"; |
| (...skipping 17822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 18732 new TestOneByteResource(i::StrDup(s), &destroyed); | 18728 new TestOneByteResource(i::StrDup(s), &destroyed); |
| 18733 v8::Local<v8::String> ring = CompileRun("ring")->ToString(); | 18729 v8::Local<v8::String> ring = CompileRun("ring")->ToString(); |
| 18734 CHECK(v8::Utils::OpenHandle(*ring)->IsInternalizedString()); | 18730 CHECK(v8::Utils::OpenHandle(*ring)->IsInternalizedString()); |
| 18735 ring->MakeExternal(inscription); | 18731 ring->MakeExternal(inscription); |
| 18736 // Ring is still alive. Orcs are roaming freely across our lands. | 18732 // Ring is still alive. Orcs are roaming freely across our lands. |
| 18737 CHECK_EQ(0, destroyed); | 18733 CHECK_EQ(0, destroyed); |
| 18738 USE(ring); | 18734 USE(ring); |
| 18739 } | 18735 } |
| 18740 | 18736 |
| 18741 // Garbage collector deals swift blows to evil. | 18737 // Garbage collector deals swift blows to evil. |
| 18742 CcTest::i_isolate()->compilation_cache()->Clear(); | 18738 CcTest::heap()->CollectAllAvailableGarbage("Swift blow to evil", 1); |
|
rmcilroy
2014/10/24 11:46:07
:)
| |
| 18743 CcTest::heap()->CollectAllAvailableGarbage(); | |
| 18744 | 18739 |
| 18745 // Ring has been destroyed. Free Peoples of Middle-earth Rejoice. | 18740 // Ring has been destroyed. Free Peoples of Middle-earth Rejoice. |
| 18746 CHECK_EQ(1, destroyed); | 18741 CHECK_EQ(1, destroyed); |
| 18747 } | 18742 } |
| 18748 | 18743 |
| 18749 | 18744 |
| 18750 static double DoubleFromBits(uint64_t value) { | 18745 static double DoubleFromBits(uint64_t value) { |
| 18751 double target; | 18746 double target; |
| 18752 i::MemCopy(&target, &value, sizeof(target)); | 18747 i::MemCopy(&target, &value, sizeof(target)); |
| 18753 return target; | 18748 return target; |
| (...skipping 5231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 23985 char chunk2[] = | 23980 char chunk2[] = |
| 23986 "XX\xec\x92\x81r = 13;\n" | 23981 "XX\xec\x92\x81r = 13;\n" |
| 23987 " return foob\xec\x92\x81\xec\x92\x81r;\n" | 23982 " return foob\xec\x92\x81\xec\x92\x81r;\n" |
| 23988 "}\n"; | 23983 "}\n"; |
| 23989 chunk1[strlen(chunk1) - 1] = reference[0]; | 23984 chunk1[strlen(chunk1) - 1] = reference[0]; |
| 23990 chunk2[0] = reference[1]; | 23985 chunk2[0] = reference[1]; |
| 23991 chunk2[1] = reference[2]; | 23986 chunk2[1] = reference[2]; |
| 23992 const char* chunks[] = {chunk1, chunk2, "foo();", NULL}; | 23987 const char* chunks[] = {chunk1, chunk2, "foo();", NULL}; |
| 23993 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8); | 23988 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8); |
| 23994 } | 23989 } |
| OLD | NEW |