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

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

Issue 110573004: Merge bleeding_edge 17696:18016. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 static void Test##Name(); \ 81 static void Test##Name(); \
82 TEST(Name##WithProfiler) { \ 82 TEST(Name##WithProfiler) { \
83 RunWithProfiler(&Test##Name); \ 83 RunWithProfiler(&Test##Name); \
84 } \ 84 } \
85 THREADED_TEST(Name) 85 THREADED_TEST(Name)
86 86
87 87
88 void RunWithProfiler(void (*test)()) { 88 void RunWithProfiler(void (*test)()) {
89 LocalContext env; 89 LocalContext env;
90 v8::HandleScope scope(env->GetIsolate()); 90 v8::HandleScope scope(env->GetIsolate());
91 v8::Local<v8::String> profile_name = v8::String::New("my_profile1"); 91 v8::Local<v8::String> profile_name =
92 v8::String::NewFromUtf8(env->GetIsolate(), "my_profile1");
92 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 93 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
93 94
94 cpu_profiler->StartCpuProfiling(profile_name); 95 cpu_profiler->StartCpuProfiling(profile_name);
95 (*test)(); 96 (*test)();
96 cpu_profiler->DeleteAllCpuProfiles(); 97 cpu_profiler->DeleteAllCpuProfiles();
97 } 98 }
98 99
99 100
100 static void ExpectString(const char* code, const char* expected) { 101 static void ExpectString(const char* code, const char* expected) {
101 Local<Value> result = CompileRun(code); 102 Local<Value> result = CompileRun(code);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 196
196 // Local context should still be live. 197 // Local context should still be live.
197 CHECK(!local_env.IsEmpty()); 198 CHECK(!local_env.IsEmpty());
198 local_env->Enter(); 199 local_env->Enter();
199 200
200 v8::Handle<v8::Primitive> undef = v8::Undefined(CcTest::isolate()); 201 v8::Handle<v8::Primitive> undef = v8::Undefined(CcTest::isolate());
201 CHECK(!undef.IsEmpty()); 202 CHECK(!undef.IsEmpty());
202 CHECK(undef->IsUndefined()); 203 CHECK(undef->IsUndefined());
203 204
204 const char* c_source = "1 + 2 + 3"; 205 const char* c_source = "1 + 2 + 3";
205 Local<String> source = String::New(c_source); 206 Local<String> source = String::NewFromUtf8(CcTest::isolate(), c_source);
206 Local<Script> script = Script::Compile(source); 207 Local<Script> script = Script::Compile(source);
207 CHECK_EQ(6, script->Run()->Int32Value()); 208 CHECK_EQ(6, script->Run()->Int32Value());
208 209
209 local_env->Exit(); 210 local_env->Exit();
210 } 211 }
211 212
212 213
213 THREADED_TEST(IsolateOfContext) { 214 THREADED_TEST(IsolateOfContext) {
214 v8::HandleScope scope(CcTest::isolate()); 215 v8::HandleScope scope(CcTest::isolate());
215 v8::Handle<Context> env = Context::New(CcTest::isolate()); 216 v8::Handle<Context> env = Context::New(CcTest::isolate());
216 217
217 CHECK(!env->InContext()); 218 CHECK(!env->GetIsolate()->InContext());
218 CHECK(env->GetIsolate() == CcTest::isolate()); 219 CHECK(env->GetIsolate() == CcTest::isolate());
219 env->Enter(); 220 env->Enter();
220 CHECK(env->InContext()); 221 CHECK(env->GetIsolate()->InContext());
221 CHECK(env->GetIsolate() == CcTest::isolate()); 222 CHECK(env->GetIsolate() == CcTest::isolate());
222 env->Exit(); 223 env->Exit();
223 CHECK(!env->InContext()); 224 CHECK(!env->GetIsolate()->InContext());
224 CHECK(env->GetIsolate() == CcTest::isolate()); 225 CHECK(env->GetIsolate() == CcTest::isolate());
225 } 226 }
226 227
227 228
228 static void TestSignature(const char* loop_js, Local<Value> receiver) { 229 static void TestSignature(const char* loop_js, Local<Value> receiver) {
229 i::ScopedVector<char> source(200); 230 i::ScopedVector<char> source(200);
230 i::OS::SNPrintF(source, 231 i::OS::SNPrintF(source,
231 "for (var i = 0; i < 10; i++) {" 232 "for (var i = 0; i < 10; i++) {"
232 " %s" 233 " %s"
233 "}", 234 "}",
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 Local<v8::Array> value = CompileRun("[\"a\", \"b\"]").As<v8::Array>(); 428 Local<v8::Array> value = CompileRun("[\"a\", \"b\"]").As<v8::Array>();
428 CHECK_EQ(v8_str("a"), value->Get(0)); 429 CHECK_EQ(v8_str("a"), value->Get(0));
429 CHECK_EQ(v8_str("b"), value->Get(1)); 430 CHECK_EQ(v8_str("b"), value->Get(1));
430 } 431 }
431 432
432 433
433 THREADED_TEST(Script) { 434 THREADED_TEST(Script) {
434 LocalContext env; 435 LocalContext env;
435 v8::HandleScope scope(env->GetIsolate()); 436 v8::HandleScope scope(env->GetIsolate());
436 const char* c_source = "1 + 2 + 3"; 437 const char* c_source = "1 + 2 + 3";
437 Local<String> source = String::New(c_source); 438 Local<String> source = String::NewFromUtf8(env->GetIsolate(), c_source);
438 Local<Script> script = Script::Compile(source); 439 Local<Script> script = Script::Compile(source);
439 CHECK_EQ(6, script->Run()->Int32Value()); 440 CHECK_EQ(6, script->Run()->Int32Value());
440 } 441 }
441 442
442 443
443 static uint16_t* AsciiToTwoByteString(const char* source) { 444 static uint16_t* AsciiToTwoByteString(const char* source) {
444 int array_length = i::StrLength(source) + 1; 445 int array_length = i::StrLength(source) + 1;
445 uint16_t* converted = i::NewArray<uint16_t>(array_length); 446 uint16_t* converted = i::NewArray<uint16_t>(array_length);
446 for (int i = 0; i < array_length; i++) converted[i] = source[i]; 447 for (int i = 0; i < array_length; i++) converted[i] = source[i];
447 return converted; 448 return converted;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 CHECK_EQ(1, dispose_count); 556 CHECK_EQ(1, dispose_count);
556 } 557 }
557 558
558 559
559 THREADED_TEST(ScriptMakingExternalString) { 560 THREADED_TEST(ScriptMakingExternalString) {
560 int dispose_count = 0; 561 int dispose_count = 0;
561 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); 562 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3");
562 { 563 {
563 LocalContext env; 564 LocalContext env;
564 v8::HandleScope scope(env->GetIsolate()); 565 v8::HandleScope scope(env->GetIsolate());
565 Local<String> source = String::New(two_byte_source); 566 Local<String> source =
567 String::NewFromTwoByte(env->GetIsolate(), two_byte_source);
566 // Trigger GCs so that the newly allocated string moves to old gen. 568 // Trigger GCs so that the newly allocated string moves to old gen.
567 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now 569 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now
568 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now 570 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
569 CHECK_EQ(source->IsExternal(), false); 571 CHECK_EQ(source->IsExternal(), false);
570 CHECK_EQ(source->IsExternalAscii(), false); 572 CHECK_EQ(source->IsExternalAscii(), false);
571 String::Encoding encoding = String::UNKNOWN_ENCODING; 573 String::Encoding encoding = String::UNKNOWN_ENCODING;
572 CHECK_EQ(NULL, source->GetExternalStringResourceBase(&encoding)); 574 CHECK_EQ(NULL, source->GetExternalStringResourceBase(&encoding));
573 CHECK_EQ(String::ASCII_ENCODING, encoding); 575 CHECK_EQ(String::ASCII_ENCODING, encoding);
574 bool success = source->MakeExternal(new TestResource(two_byte_source, 576 bool success = source->MakeExternal(new TestResource(two_byte_source,
575 &dispose_count)); 577 &dispose_count));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 617
616 TEST(MakingExternalStringConditions) { 618 TEST(MakingExternalStringConditions) {
617 LocalContext env; 619 LocalContext env;
618 v8::HandleScope scope(env->GetIsolate()); 620 v8::HandleScope scope(env->GetIsolate());
619 621
620 // Free some space in the new space so that we can check freshness. 622 // Free some space in the new space so that we can check freshness.
621 CcTest::heap()->CollectGarbage(i::NEW_SPACE); 623 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
622 CcTest::heap()->CollectGarbage(i::NEW_SPACE); 624 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
623 625
624 uint16_t* two_byte_string = AsciiToTwoByteString("s1"); 626 uint16_t* two_byte_string = AsciiToTwoByteString("s1");
625 Local<String> small_string = String::New(two_byte_string); 627 Local<String> small_string =
628 String::NewFromTwoByte(env->GetIsolate(), two_byte_string);
626 i::DeleteArray(two_byte_string); 629 i::DeleteArray(two_byte_string);
627 630
628 // We should refuse to externalize newly created small string. 631 // We should refuse to externalize newly created small string.
629 CHECK(!small_string->CanMakeExternal()); 632 CHECK(!small_string->CanMakeExternal());
630 // Trigger GCs so that the newly allocated string moves to old gen. 633 // Trigger GCs so that the newly allocated string moves to old gen.
631 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now 634 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now
632 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now 635 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
633 // Old space strings should be accepted. 636 // Old space strings should be accepted.
634 CHECK(small_string->CanMakeExternal()); 637 CHECK(small_string->CanMakeExternal());
635 638
636 two_byte_string = AsciiToTwoByteString("small string 2"); 639 two_byte_string = AsciiToTwoByteString("small string 2");
637 small_string = String::New(two_byte_string); 640 small_string = String::NewFromTwoByte(env->GetIsolate(), two_byte_string);
638 i::DeleteArray(two_byte_string); 641 i::DeleteArray(two_byte_string);
639 642
640 // We should refuse externalizing newly created small string. 643 // We should refuse externalizing newly created small string.
641 CHECK(!small_string->CanMakeExternal()); 644 CHECK(!small_string->CanMakeExternal());
642 for (int i = 0; i < 100; i++) { 645 for (int i = 0; i < 100; i++) {
643 String::Value value(small_string); 646 String::Value value(small_string);
644 } 647 }
645 // Frequently used strings should be accepted. 648 // Frequently used strings should be accepted.
646 CHECK(small_string->CanMakeExternal()); 649 CHECK(small_string->CanMakeExternal());
647 650
648 const int buf_size = 10 * 1024; 651 const int buf_size = 10 * 1024;
649 char* buf = i::NewArray<char>(buf_size); 652 char* buf = i::NewArray<char>(buf_size);
650 memset(buf, 'a', buf_size); 653 memset(buf, 'a', buf_size);
651 buf[buf_size - 1] = '\0'; 654 buf[buf_size - 1] = '\0';
652 655
653 two_byte_string = AsciiToTwoByteString(buf); 656 two_byte_string = AsciiToTwoByteString(buf);
654 Local<String> large_string = String::New(two_byte_string); 657 Local<String> large_string =
658 String::NewFromTwoByte(env->GetIsolate(), two_byte_string);
655 i::DeleteArray(buf); 659 i::DeleteArray(buf);
656 i::DeleteArray(two_byte_string); 660 i::DeleteArray(two_byte_string);
657 // Large strings should be immediately accepted. 661 // Large strings should be immediately accepted.
658 CHECK(large_string->CanMakeExternal()); 662 CHECK(large_string->CanMakeExternal());
659 } 663 }
660 664
661 665
662 TEST(MakingExternalAsciiStringConditions) { 666 TEST(MakingExternalAsciiStringConditions) {
663 LocalContext env; 667 LocalContext env;
664 v8::HandleScope scope(env->GetIsolate()); 668 v8::HandleScope scope(env->GetIsolate());
665 669
666 // Free some space in the new space so that we can check freshness. 670 // Free some space in the new space so that we can check freshness.
667 CcTest::heap()->CollectGarbage(i::NEW_SPACE); 671 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
668 CcTest::heap()->CollectGarbage(i::NEW_SPACE); 672 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
669 673
670 Local<String> small_string = String::New("s1"); 674 Local<String> small_string = String::NewFromUtf8(env->GetIsolate(), "s1");
671 // We should refuse to externalize newly created small string. 675 // We should refuse to externalize newly created small string.
672 CHECK(!small_string->CanMakeExternal()); 676 CHECK(!small_string->CanMakeExternal());
673 // Trigger GCs so that the newly allocated string moves to old gen. 677 // Trigger GCs so that the newly allocated string moves to old gen.
674 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now 678 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now
675 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now 679 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
676 // Old space strings should be accepted. 680 // Old space strings should be accepted.
677 CHECK(small_string->CanMakeExternal()); 681 CHECK(small_string->CanMakeExternal());
678 682
679 small_string = String::New("small string 2"); 683 small_string = String::NewFromUtf8(env->GetIsolate(), "small string 2");
680 // We should refuse externalizing newly created small string. 684 // We should refuse externalizing newly created small string.
681 CHECK(!small_string->CanMakeExternal()); 685 CHECK(!small_string->CanMakeExternal());
682 for (int i = 0; i < 100; i++) { 686 for (int i = 0; i < 100; i++) {
683 String::Value value(small_string); 687 String::Value value(small_string);
684 } 688 }
685 // Frequently used strings should be accepted. 689 // Frequently used strings should be accepted.
686 CHECK(small_string->CanMakeExternal()); 690 CHECK(small_string->CanMakeExternal());
687 691
688 const int buf_size = 10 * 1024; 692 const int buf_size = 10 * 1024;
689 char* buf = i::NewArray<char>(buf_size); 693 char* buf = i::NewArray<char>(buf_size);
690 memset(buf, 'a', buf_size); 694 memset(buf, 'a', buf_size);
691 buf[buf_size - 1] = '\0'; 695 buf[buf_size - 1] = '\0';
692 Local<String> large_string = String::New(buf); 696 Local<String> large_string = String::NewFromUtf8(env->GetIsolate(), buf);
693 i::DeleteArray(buf); 697 i::DeleteArray(buf);
694 // Large strings should be immediately accepted. 698 // Large strings should be immediately accepted.
695 CHECK(large_string->CanMakeExternal()); 699 CHECK(large_string->CanMakeExternal());
696 } 700 }
697 701
698 702
699 TEST(MakingExternalUnalignedAsciiString) { 703 TEST(MakingExternalUnalignedAsciiString) {
700 LocalContext env; 704 LocalContext env;
701 v8::HandleScope scope(env->GetIsolate()); 705 v8::HandleScope scope(env->GetIsolate());
702 706
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 const char* one_byte_string_1 = "function a_times_t"; 896 const char* one_byte_string_1 = "function a_times_t";
893 const char* two_byte_string_1 = "wo_plus_b(a, b) {return "; 897 const char* two_byte_string_1 = "wo_plus_b(a, b) {return ";
894 const char* one_byte_extern_1 = "a * 2 + b;} a_times_two_plus_b(4, 8) + "; 898 const char* one_byte_extern_1 = "a * 2 + b;} a_times_two_plus_b(4, 8) + ";
895 const char* two_byte_extern_1 = "a_times_two_plus_b(4, 8) + "; 899 const char* two_byte_extern_1 = "a_times_two_plus_b(4, 8) + ";
896 const char* one_byte_string_2 = "a_times_two_plus_b(4, 8) + "; 900 const char* one_byte_string_2 = "a_times_two_plus_b(4, 8) + ";
897 const char* two_byte_string_2 = "a_times_two_plus_b(4, 8) + "; 901 const char* two_byte_string_2 = "a_times_two_plus_b(4, 8) + ";
898 const char* two_byte_extern_2 = "a_times_two_plus_b(1, 2);"; 902 const char* two_byte_extern_2 = "a_times_two_plus_b(1, 2);";
899 Local<String> left = v8_str(one_byte_string_1); 903 Local<String> left = v8_str(one_byte_string_1);
900 904
901 uint16_t* two_byte_source = AsciiToTwoByteString(two_byte_string_1); 905 uint16_t* two_byte_source = AsciiToTwoByteString(two_byte_string_1);
902 Local<String> right = String::New(two_byte_source); 906 Local<String> right =
907 String::NewFromTwoByte(env->GetIsolate(), two_byte_source);
903 i::DeleteArray(two_byte_source); 908 i::DeleteArray(two_byte_source);
904 909
905 Local<String> source = String::Concat(left, right); 910 Local<String> source = String::Concat(left, right);
906 right = String::NewExternal( 911 right = String::NewExternal(
907 new TestAsciiResource(i::StrDup(one_byte_extern_1))); 912 new TestAsciiResource(i::StrDup(one_byte_extern_1)));
908 source = String::Concat(source, right); 913 source = String::Concat(source, right);
909 right = String::NewExternal( 914 right = String::NewExternal(
910 new TestResource(AsciiToTwoByteString(two_byte_extern_1))); 915 new TestResource(AsciiToTwoByteString(two_byte_extern_1)));
911 source = String::Concat(source, right); 916 source = String::Concat(source, right);
912 right = v8_str(one_byte_string_2); 917 right = v8_str(one_byte_string_2);
913 source = String::Concat(source, right); 918 source = String::Concat(source, right);
914 919
915 two_byte_source = AsciiToTwoByteString(two_byte_string_2); 920 two_byte_source = AsciiToTwoByteString(two_byte_string_2);
916 right = String::New(two_byte_source); 921 right = String::NewFromTwoByte(env->GetIsolate(), two_byte_source);
917 i::DeleteArray(two_byte_source); 922 i::DeleteArray(two_byte_source);
918 923
919 source = String::Concat(source, right); 924 source = String::Concat(source, right);
920 right = String::NewExternal( 925 right = String::NewExternal(
921 new TestResource(AsciiToTwoByteString(two_byte_extern_2))); 926 new TestResource(AsciiToTwoByteString(two_byte_extern_2)));
922 source = String::Concat(source, right); 927 source = String::Concat(source, right);
923 Local<Script> script = Script::Compile(source); 928 Local<Script> script = Script::Compile(source);
924 Local<Value> value = script->Run(); 929 Local<Value> value = script->Run();
925 CHECK(value->IsNumber()); 930 CHECK(value->IsNumber());
926 CHECK_EQ(68, value->Int32Value()); 931 CHECK_EQ(68, value->Int32Value());
(...skipping 1588 matching lines...) Expand 10 before | Expand all | Expand 10 after
2515 global->SetInternalField(0, v8_num(17)); 2520 global->SetInternalField(0, v8_num(17));
2516 CHECK_EQ(17, global->GetInternalField(0)->Int32Value()); 2521 CHECK_EQ(17, global->GetInternalField(0)->Int32Value());
2517 } 2522 }
2518 2523
2519 2524
2520 THREADED_TEST(GlobalObjectHasRealIndexedProperty) { 2525 THREADED_TEST(GlobalObjectHasRealIndexedProperty) {
2521 LocalContext env; 2526 LocalContext env;
2522 v8::HandleScope scope(CcTest::isolate()); 2527 v8::HandleScope scope(CcTest::isolate());
2523 2528
2524 v8::Local<v8::Object> global = env->Global(); 2529 v8::Local<v8::Object> global = env->Global();
2525 global->Set(0, v8::String::New("value")); 2530 global->Set(0, v8::String::NewFromUtf8(CcTest::isolate(), "value"));
2526 CHECK(global->HasRealIndexedProperty(0)); 2531 CHECK(global->HasRealIndexedProperty(0));
2527 } 2532 }
2528 2533
2529 2534
2530 static void CheckAlignedPointerInInternalField(Handle<v8::Object> obj, 2535 static void CheckAlignedPointerInInternalField(Handle<v8::Object> obj,
2531 void* value) { 2536 void* value) {
2532 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); 2537 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1));
2533 obj->SetAlignedPointerInInternalField(0, value); 2538 obj->SetAlignedPointerInInternalField(0, value);
2534 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 2539 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2535 CHECK_EQ(value, obj->GetAlignedPointerFromInternalField(0)); 2540 CHECK_EQ(value, obj->GetAlignedPointerFromInternalField(0));
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2607 v8::Handle<Value> data) { 2612 v8::Handle<Value> data) {
2608 (*env)->SetEmbedderData(index, data); 2613 (*env)->SetEmbedderData(index, data);
2609 CHECK((*env)->GetEmbedderData(index)->StrictEquals(data)); 2614 CHECK((*env)->GetEmbedderData(index)->StrictEquals(data));
2610 } 2615 }
2611 2616
2612 2617
2613 THREADED_TEST(EmbedderData) { 2618 THREADED_TEST(EmbedderData) {
2614 LocalContext env; 2619 LocalContext env;
2615 v8::HandleScope scope(env->GetIsolate()); 2620 v8::HandleScope scope(env->GetIsolate());
2616 2621
2617 CheckEmbedderData(&env, 3, v8::String::New("The quick brown fox jumps")); 2622 CheckEmbedderData(
2618 CheckEmbedderData(&env, 2, v8::String::New("over the lazy dog.")); 2623 &env, 3,
2624 v8::String::NewFromUtf8(env->GetIsolate(), "The quick brown fox jumps"));
2625 CheckEmbedderData(&env, 2, v8::String::NewFromUtf8(env->GetIsolate(),
2626 "over the lazy dog."));
2619 CheckEmbedderData(&env, 1, v8::Number::New(1.2345)); 2627 CheckEmbedderData(&env, 1, v8::Number::New(1.2345));
2620 CheckEmbedderData(&env, 0, v8::Boolean::New(true)); 2628 CheckEmbedderData(&env, 0, v8::Boolean::New(true));
2621 } 2629 }
2622 2630
2623 2631
2624 THREADED_TEST(IdentityHash) { 2632 THREADED_TEST(IdentityHash) {
2625 LocalContext env; 2633 LocalContext env;
2626 v8::HandleScope scope(env->GetIsolate()); 2634 v8::HandleScope scope(env->GetIsolate());
2627 2635
2628 // Ensure that the test starts with an fresh heap to test whether the hash 2636 // Ensure that the test starts with an fresh heap to test whether the hash
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2685 2693
2686 CHECK(sym1->Equals(sym1)); 2694 CHECK(sym1->Equals(sym1));
2687 CHECK(sym2->Equals(sym2)); 2695 CHECK(sym2->Equals(sym2));
2688 CHECK(!sym1->Equals(sym2)); 2696 CHECK(!sym1->Equals(sym2));
2689 CHECK(!sym2->Equals(sym1)); 2697 CHECK(!sym2->Equals(sym1));
2690 CHECK(sym1->StrictEquals(sym1)); 2698 CHECK(sym1->StrictEquals(sym1));
2691 CHECK(sym2->StrictEquals(sym2)); 2699 CHECK(sym2->StrictEquals(sym2));
2692 CHECK(!sym1->StrictEquals(sym2)); 2700 CHECK(!sym1->StrictEquals(sym2));
2693 CHECK(!sym2->StrictEquals(sym1)); 2701 CHECK(!sym2->StrictEquals(sym1));
2694 2702
2695 CHECK(sym2->Name()->Equals(v8::String::New("my-symbol"))); 2703 CHECK(sym2->Name()->Equals(v8::String::NewFromUtf8(isolate, "my-symbol")));
2696 2704
2697 v8::Local<v8::Value> sym_val = sym2; 2705 v8::Local<v8::Value> sym_val = sym2;
2698 CHECK(sym_val->IsSymbol()); 2706 CHECK(sym_val->IsSymbol());
2699 CHECK(sym_val->Equals(sym2)); 2707 CHECK(sym_val->Equals(sym2));
2700 CHECK(sym_val->StrictEquals(sym2)); 2708 CHECK(sym_val->StrictEquals(sym2));
2701 CHECK(v8::Symbol::Cast(*sym_val)->Equals(sym2)); 2709 CHECK(v8::Symbol::Cast(*sym_val)->Equals(sym2));
2702 2710
2703 v8::Local<v8::Value> sym_obj = v8::SymbolObject::New(isolate, sym2); 2711 v8::Local<v8::Value> sym_obj = v8::SymbolObject::New(isolate, sym2);
2704 CHECK(sym_obj->IsSymbolObject()); 2712 CHECK(sym_obj->IsSymbolObject());
2705 CHECK(!sym2->IsSymbolObject()); 2713 CHECK(!sym2->IsSymbolObject());
(...skipping 10 matching lines...) Expand all
2716 CHECK(obj->Set(sym1, v8::Integer::New(1503))); 2724 CHECK(obj->Set(sym1, v8::Integer::New(1503)));
2717 CHECK(obj->Has(sym1)); 2725 CHECK(obj->Has(sym1));
2718 CHECK_EQ(1503, obj->Get(sym1)->Int32Value()); 2726 CHECK_EQ(1503, obj->Get(sym1)->Int32Value());
2719 CHECK(obj->Set(sym1, v8::Integer::New(2002))); 2727 CHECK(obj->Set(sym1, v8::Integer::New(2002)));
2720 CHECK(obj->Has(sym1)); 2728 CHECK(obj->Has(sym1));
2721 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); 2729 CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
2722 CHECK_EQ(v8::None, obj->GetPropertyAttributes(sym1)); 2730 CHECK_EQ(v8::None, obj->GetPropertyAttributes(sym1));
2723 2731
2724 CHECK_EQ(0, obj->GetOwnPropertyNames()->Length()); 2732 CHECK_EQ(0, obj->GetOwnPropertyNames()->Length());
2725 int num_props = obj->GetPropertyNames()->Length(); 2733 int num_props = obj->GetPropertyNames()->Length();
2726 CHECK(obj->Set(v8::String::New("bla"), v8::Integer::New(20))); 2734 CHECK(
2735 obj->Set(v8::String::NewFromUtf8(isolate, "bla"), v8::Integer::New(20)));
2727 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); 2736 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
2728 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length()); 2737 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length());
2729 2738
2730 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 2739 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2731 2740
2732 // Add another property and delete it afterwards to force the object in 2741 // Add another property and delete it afterwards to force the object in
2733 // slow case. 2742 // slow case.
2734 CHECK(obj->Set(sym2, v8::Integer::New(2008))); 2743 CHECK(obj->Set(sym2, v8::Integer::New(2008)));
2735 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); 2744 CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
2736 CHECK_EQ(2008, obj->Get(sym2)->Int32Value()); 2745 CHECK_EQ(2008, obj->Get(sym2)->Int32Value());
(...skipping 21 matching lines...) Expand all
2758 LocalContext env; 2767 LocalContext env;
2759 v8::Isolate* isolate = env->GetIsolate(); 2768 v8::Isolate* isolate = env->GetIsolate();
2760 v8::HandleScope scope(isolate); 2769 v8::HandleScope scope(isolate);
2761 2770
2762 v8::Local<v8::Object> obj = v8::Object::New(); 2771 v8::Local<v8::Object> obj = v8::Object::New();
2763 v8::Local<v8::Private> priv1 = v8::Private::New(isolate); 2772 v8::Local<v8::Private> priv1 = v8::Private::New(isolate);
2764 v8::Local<v8::Private> priv2 = v8::Private::New(isolate, "my-private"); 2773 v8::Local<v8::Private> priv2 = v8::Private::New(isolate, "my-private");
2765 2774
2766 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 2775 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2767 2776
2768 CHECK(priv2->Name()->Equals(v8::String::New("my-private"))); 2777 CHECK(priv2->Name()->Equals(v8::String::NewFromUtf8(isolate, "my-private")));
2769 2778
2770 // Make sure delete of a non-existent private symbol property works. 2779 // Make sure delete of a non-existent private symbol property works.
2771 CHECK(obj->DeletePrivate(priv1)); 2780 CHECK(obj->DeletePrivate(priv1));
2772 CHECK(!obj->HasPrivate(priv1)); 2781 CHECK(!obj->HasPrivate(priv1));
2773 2782
2774 CHECK(obj->SetPrivate(priv1, v8::Integer::New(1503))); 2783 CHECK(obj->SetPrivate(priv1, v8::Integer::New(1503)));
2775 CHECK(obj->HasPrivate(priv1)); 2784 CHECK(obj->HasPrivate(priv1));
2776 CHECK_EQ(1503, obj->GetPrivate(priv1)->Int32Value()); 2785 CHECK_EQ(1503, obj->GetPrivate(priv1)->Int32Value());
2777 CHECK(obj->SetPrivate(priv1, v8::Integer::New(2002))); 2786 CHECK(obj->SetPrivate(priv1, v8::Integer::New(2002)));
2778 CHECK(obj->HasPrivate(priv1)); 2787 CHECK(obj->HasPrivate(priv1));
2779 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value()); 2788 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value());
2780 2789
2781 CHECK_EQ(0, obj->GetOwnPropertyNames()->Length()); 2790 CHECK_EQ(0, obj->GetOwnPropertyNames()->Length());
2782 int num_props = obj->GetPropertyNames()->Length(); 2791 int num_props = obj->GetPropertyNames()->Length();
2783 CHECK(obj->Set(v8::String::New("bla"), v8::Integer::New(20))); 2792 CHECK(
2793 obj->Set(v8::String::NewFromUtf8(isolate, "bla"), v8::Integer::New(20)));
2784 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); 2794 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
2785 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length()); 2795 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length());
2786 2796
2787 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 2797 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2788 2798
2789 // Add another property and delete it afterwards to force the object in 2799 // Add another property and delete it afterwards to force the object in
2790 // slow case. 2800 // slow case.
2791 CHECK(obj->SetPrivate(priv2, v8::Integer::New(2008))); 2801 CHECK(obj->SetPrivate(priv2, v8::Integer::New(2008)));
2792 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value()); 2802 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value());
2793 CHECK_EQ(2008, obj->GetPrivate(priv2)->Int32Value()); 2803 CHECK_EQ(2008, obj->GetPrivate(priv2)->Int32Value());
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
3217 v8::Isolate* isolate = CcTest::isolate(); 3227 v8::Isolate* isolate = CcTest::isolate();
3218 v8::Persistent<String> global; 3228 v8::Persistent<String> global;
3219 { 3229 {
3220 v8::HandleScope scope(isolate); 3230 v8::HandleScope scope(isolate);
3221 global.Reset(isolate, v8_str("str")); 3231 global.Reset(isolate, v8_str("str"));
3222 } 3232 }
3223 { 3233 {
3224 v8::HandleScope scope(isolate); 3234 v8::HandleScope scope(isolate);
3225 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 3); 3235 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 3);
3226 } 3236 }
3227 global.Dispose(); 3237 global.Reset();
3228 global.Clear();
3229 { 3238 {
3230 v8::HandleScope scope(isolate); 3239 v8::HandleScope scope(isolate);
3231 global.Reset(isolate, v8_str("str")); 3240 global.Reset(isolate, v8_str("str"));
3232 } 3241 }
3233 { 3242 {
3234 v8::HandleScope scope(isolate); 3243 v8::HandleScope scope(isolate);
3235 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 3); 3244 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 3);
3236 } 3245 }
3237 global.Dispose(); 3246 global.Reset();
3238 } 3247 }
3239 3248
3240 3249
3241 THREADED_TEST(ResettingGlobalHandle) { 3250 THREADED_TEST(ResettingGlobalHandle) {
3242 v8::Isolate* isolate = CcTest::isolate(); 3251 v8::Isolate* isolate = CcTest::isolate();
3243 v8::Persistent<String> global; 3252 v8::Persistent<String> global;
3244 { 3253 {
3245 v8::HandleScope scope(isolate); 3254 v8::HandleScope scope(isolate);
3246 global.Reset(isolate, v8_str("str")); 3255 global.Reset(isolate, v8_str("str"));
3247 } 3256 }
3248 v8::internal::GlobalHandles* global_handles = 3257 v8::internal::GlobalHandles* global_handles =
3249 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles(); 3258 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles();
3250 int initial_handle_count = global_handles->global_handles_count(); 3259 int initial_handle_count = global_handles->global_handles_count();
3251 { 3260 {
3252 v8::HandleScope scope(isolate); 3261 v8::HandleScope scope(isolate);
3253 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 3); 3262 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 3);
3254 } 3263 }
3255 { 3264 {
3256 v8::HandleScope scope(isolate); 3265 v8::HandleScope scope(isolate);
3257 global.Reset(isolate, v8_str("longer")); 3266 global.Reset(isolate, v8_str("longer"));
3258 } 3267 }
3259 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count); 3268 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count);
3260 { 3269 {
3261 v8::HandleScope scope(isolate); 3270 v8::HandleScope scope(isolate);
3262 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 6); 3271 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 6);
3263 } 3272 }
3264 global.Dispose(); 3273 global.Reset();
3265 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count - 1); 3274 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count - 1);
3266 } 3275 }
3267 3276
3268 3277
3269 THREADED_TEST(ResettingGlobalHandleToEmpty) { 3278 THREADED_TEST(ResettingGlobalHandleToEmpty) {
3270 v8::Isolate* isolate = CcTest::isolate(); 3279 v8::Isolate* isolate = CcTest::isolate();
3271 v8::Persistent<String> global; 3280 v8::Persistent<String> global;
3272 { 3281 {
3273 v8::HandleScope scope(isolate); 3282 v8::HandleScope scope(isolate);
3274 global.Reset(isolate, v8_str("str")); 3283 global.Reset(isolate, v8_str("str"));
3275 } 3284 }
3276 v8::internal::GlobalHandles* global_handles = 3285 v8::internal::GlobalHandles* global_handles =
3277 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles(); 3286 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles();
3278 int initial_handle_count = global_handles->global_handles_count(); 3287 int initial_handle_count = global_handles->global_handles_count();
3279 { 3288 {
3280 v8::HandleScope scope(isolate); 3289 v8::HandleScope scope(isolate);
3281 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 3); 3290 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 3);
3282 } 3291 }
3283 { 3292 {
3284 v8::HandleScope scope(isolate); 3293 v8::HandleScope scope(isolate);
3285 Local<String> empty; 3294 Local<String> empty;
3286 global.Reset(isolate, empty); 3295 global.Reset(isolate, empty);
3287 } 3296 }
3288 CHECK(global.IsEmpty()); 3297 CHECK(global.IsEmpty());
3289 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count - 1); 3298 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count - 1);
3290 } 3299 }
3291 3300
3292 3301
3293 THREADED_TEST(ClearAndLeakGlobal) {
3294 v8::Isolate* isolate = CcTest::isolate();
3295 v8::internal::GlobalHandles* global_handles = NULL;
3296 int initial_handle_count = 0;
3297 v8::Persistent<String> global;
3298 {
3299 v8::HandleScope scope(isolate);
3300 Local<String> str = v8_str("str");
3301 global_handles =
3302 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles();
3303 initial_handle_count = global_handles->global_handles_count();
3304 global.Reset(isolate, str);
3305 }
3306 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count + 1);
3307 String* str = global.ClearAndLeak();
3308 CHECK(global.IsEmpty());
3309 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count + 1);
3310 global_handles->Destroy(reinterpret_cast<i::Object**>(str));
3311 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count);
3312 }
3313
3314
3315 THREADED_TEST(GlobalHandleUpcast) { 3302 THREADED_TEST(GlobalHandleUpcast) {
3316 v8::Isolate* isolate = CcTest::isolate(); 3303 v8::Isolate* isolate = CcTest::isolate();
3317 v8::HandleScope scope(isolate); 3304 v8::HandleScope scope(isolate);
3318 v8::Local<String> local = v8::Local<String>::New(isolate, v8_str("str")); 3305 v8::Local<String> local = v8::Local<String>::New(isolate, v8_str("str"));
3319 v8::Persistent<String> global_string(isolate, local); 3306 v8::Persistent<String> global_string(isolate, local);
3320 v8::Persistent<Value>& global_value = 3307 v8::Persistent<Value>& global_value =
3321 v8::Persistent<Value>::Cast(global_string); 3308 v8::Persistent<Value>::Cast(global_string);
3322 CHECK(v8::Local<v8::Value>::New(isolate, global_value)->IsString()); 3309 CHECK(v8::Local<v8::Value>::New(isolate, global_value)->IsString());
3323 CHECK(global_string == v8::Persistent<String>::Cast(global_value)); 3310 CHECK(global_string == v8::Persistent<String>::Cast(global_value));
3324 global_string.Dispose(); 3311 global_string.Reset();
3325 } 3312 }
3326 3313
3327 3314
3328 THREADED_TEST(HandleEquality) { 3315 THREADED_TEST(HandleEquality) {
3329 v8::Isolate* isolate = CcTest::isolate(); 3316 v8::Isolate* isolate = CcTest::isolate();
3330 v8::Persistent<String> global1; 3317 v8::Persistent<String> global1;
3331 v8::Persistent<String> global2; 3318 v8::Persistent<String> global2;
3332 { 3319 {
3333 v8::HandleScope scope(isolate); 3320 v8::HandleScope scope(isolate);
3334 global1.Reset(isolate, v8_str("str")); 3321 global1.Reset(isolate, v8_str("str"));
(...skipping 16 matching lines...) Expand all
3351 CHECK_EQ(local2 == global1, false); 3338 CHECK_EQ(local2 == global1, false);
3352 CHECK_EQ(local2 != global1, true); 3339 CHECK_EQ(local2 != global1, true);
3353 3340
3354 CHECK_EQ(local1 == local2, false); 3341 CHECK_EQ(local1 == local2, false);
3355 CHECK_EQ(local1 != local2, true); 3342 CHECK_EQ(local1 != local2, true);
3356 3343
3357 Local<String> anotherLocal1 = Local<String>::New(isolate, global1); 3344 Local<String> anotherLocal1 = Local<String>::New(isolate, global1);
3358 CHECK_EQ(local1 == anotherLocal1, true); 3345 CHECK_EQ(local1 == anotherLocal1, true);
3359 CHECK_EQ(local1 != anotherLocal1, false); 3346 CHECK_EQ(local1 != anotherLocal1, false);
3360 } 3347 }
3361 global1.Dispose(); 3348 global1.Reset();
3362 global2.Dispose(); 3349 global2.Reset();
3363 } 3350 }
3364 3351
3365 3352
3366 THREADED_TEST(LocalHandle) { 3353 THREADED_TEST(LocalHandle) {
3367 v8::HandleScope scope(CcTest::isolate()); 3354 v8::HandleScope scope(CcTest::isolate());
3368 v8::Local<String> local = 3355 v8::Local<String> local =
3369 v8::Local<String>::New(CcTest::isolate(), v8_str("str")); 3356 v8::Local<String>::New(CcTest::isolate(), v8_str("str"));
3370 CHECK_EQ(local->Length(), 3); 3357 CHECK_EQ(local->Length(), 3);
3371 } 3358 }
3372 3359
3373 3360
3374 class WeakCallCounter { 3361 class WeakCallCounter {
3375 public: 3362 public:
3376 explicit WeakCallCounter(int id) : id_(id), number_of_weak_calls_(0) { } 3363 explicit WeakCallCounter(int id) : id_(id), number_of_weak_calls_(0) { }
3377 int id() { return id_; } 3364 int id() { return id_; }
3378 void increment() { number_of_weak_calls_++; } 3365 void increment() { number_of_weak_calls_++; }
3379 int NumberOfWeakCalls() { return number_of_weak_calls_; } 3366 int NumberOfWeakCalls() { return number_of_weak_calls_; }
3380 private: 3367 private:
3381 int id_; 3368 int id_;
3382 int number_of_weak_calls_; 3369 int number_of_weak_calls_;
3383 }; 3370 };
3384 3371
3385 3372
3386 template<typename T> 3373 template<typename T>
3387 static void WeakPointerCallback(v8::Isolate* isolate, 3374 static void WeakPointerCallback(v8::Isolate* isolate,
3388 Persistent<T>* handle, 3375 Persistent<T>* handle,
3389 WeakCallCounter* counter) { 3376 WeakCallCounter* counter) {
3390 CHECK_EQ(1234, counter->id()); 3377 CHECK_EQ(1234, counter->id());
3391 counter->increment(); 3378 counter->increment();
3392 handle->Dispose(); 3379 handle->Reset();
3393 } 3380 }
3394 3381
3395 3382
3396 template<typename T> 3383 template<typename T>
3397 static UniqueId MakeUniqueId(const Persistent<T>& p) { 3384 static UniqueId MakeUniqueId(const Persistent<T>& p) {
3398 return UniqueId(reinterpret_cast<uintptr_t>(*v8::Utils::OpenPersistent(p))); 3385 return UniqueId(reinterpret_cast<uintptr_t>(*v8::Utils::OpenPersistent(p)));
3399 } 3386 }
3400 3387
3401 3388
3402 THREADED_TEST(ApiObjectGroups) { 3389 THREADED_TEST(ApiObjectGroups) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
3502 Persistent<String> g1c1; 3489 Persistent<String> g1c1;
3503 Persistent<Object> g2s1; 3490 Persistent<Object> g2s1;
3504 Persistent<String> g2s2; 3491 Persistent<String> g2s2;
3505 Persistent<String> g2c1; 3492 Persistent<String> g2c1;
3506 3493
3507 WeakCallCounter counter(1234); 3494 WeakCallCounter counter(1234);
3508 3495
3509 { 3496 {
3510 HandleScope scope(iso); 3497 HandleScope scope(iso);
3511 g1s1.Reset(iso, Object::New()); 3498 g1s1.Reset(iso, Object::New());
3512 g1s2.Reset(iso, String::New("foo1")); 3499 g1s2.Reset(iso, String::NewFromUtf8(iso, "foo1"));
3513 g1c1.Reset(iso, String::New("foo2")); 3500 g1c1.Reset(iso, String::NewFromUtf8(iso, "foo2"));
3514 g1s1.MakeWeak(&counter, &WeakPointerCallback); 3501 g1s1.MakeWeak(&counter, &WeakPointerCallback);
3515 g1s2.MakeWeak(&counter, &WeakPointerCallback); 3502 g1s2.MakeWeak(&counter, &WeakPointerCallback);
3516 g1c1.MakeWeak(&counter, &WeakPointerCallback); 3503 g1c1.MakeWeak(&counter, &WeakPointerCallback);
3517 3504
3518 g2s1.Reset(iso, Object::New()); 3505 g2s1.Reset(iso, Object::New());
3519 g2s2.Reset(iso, String::New("foo3")); 3506 g2s2.Reset(iso, String::NewFromUtf8(iso, "foo3"));
3520 g2c1.Reset(iso, String::New("foo4")); 3507 g2c1.Reset(iso, String::NewFromUtf8(iso, "foo4"));
3521 g2s1.MakeWeak(&counter, &WeakPointerCallback); 3508 g2s1.MakeWeak(&counter, &WeakPointerCallback);
3522 g2s2.MakeWeak(&counter, &WeakPointerCallback); 3509 g2s2.MakeWeak(&counter, &WeakPointerCallback);
3523 g2c1.MakeWeak(&counter, &WeakPointerCallback); 3510 g2c1.MakeWeak(&counter, &WeakPointerCallback);
3524 } 3511 }
3525 3512
3526 Persistent<Value> root(iso, g1s1); // make a root. 3513 Persistent<Value> root(iso, g1s1); // make a root.
3527 3514
3528 // Connect group 1 and 2, make a cycle. 3515 // Connect group 1 and 2, make a cycle.
3529 { 3516 {
3530 HandleScope scope(iso); 3517 HandleScope scope(iso);
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
4256 // These tests run for a long time and prevent us from running tests 4243 // These tests run for a long time and prevent us from running tests
4257 // that come after them so they cannot run in parallel. 4244 // that come after them so they cannot run in parallel.
4258 TEST(OutOfMemory) { 4245 TEST(OutOfMemory) {
4259 // It's not possible to read a snapshot into a heap with different dimensions. 4246 // It's not possible to read a snapshot into a heap with different dimensions.
4260 if (i::Snapshot::IsEnabled()) return; 4247 if (i::Snapshot::IsEnabled()) return;
4261 // Set heap limits. 4248 // Set heap limits.
4262 static const int K = 1024; 4249 static const int K = 1024;
4263 v8::ResourceConstraints constraints; 4250 v8::ResourceConstraints constraints;
4264 constraints.set_max_young_space_size(256 * K); 4251 constraints.set_max_young_space_size(256 * K);
4265 constraints.set_max_old_space_size(5 * K * K); 4252 constraints.set_max_old_space_size(5 * K * K);
4266 v8::SetResourceConstraints(&constraints); 4253 v8::SetResourceConstraints(CcTest::isolate(), &constraints);
4267 4254
4268 // Execute a script that causes out of memory. 4255 // Execute a script that causes out of memory.
4269 LocalContext context; 4256 LocalContext context;
4270 v8::HandleScope scope(context->GetIsolate()); 4257 v8::HandleScope scope(context->GetIsolate());
4271 v8::V8::IgnoreOutOfMemoryException(); 4258 v8::V8::IgnoreOutOfMemoryException();
4272 Local<Script> script = 4259 Local<Script> script = Script::Compile(String::NewFromUtf8(
4273 Script::Compile(String::New(js_code_causing_out_of_memory)); 4260 context->GetIsolate(), js_code_causing_out_of_memory));
4274 Local<Value> result = script->Run(); 4261 Local<Value> result = script->Run();
4275 4262
4276 // Check for out of memory state. 4263 // Check for out of memory state.
4277 CHECK(result.IsEmpty()); 4264 CHECK(result.IsEmpty());
4278 CHECK(context->HasOutOfMemoryException()); 4265 CHECK(context->HasOutOfMemoryException());
4279 } 4266 }
4280 4267
4281 4268
4282 void ProvokeOutOfMemory(const v8::FunctionCallbackInfo<v8::Value>& args) { 4269 void ProvokeOutOfMemory(const v8::FunctionCallbackInfo<v8::Value>& args) {
4283 ApiTestFuzzer::Fuzz(); 4270 ApiTestFuzzer::Fuzz();
4284 4271
4285 LocalContext context; 4272 LocalContext context;
4286 v8::HandleScope scope(context->GetIsolate()); 4273 v8::HandleScope scope(context->GetIsolate());
4287 Local<Script> script = 4274 Local<Script> script = Script::Compile(String::NewFromUtf8(
4288 Script::Compile(String::New(js_code_causing_out_of_memory)); 4275 context->GetIsolate(), js_code_causing_out_of_memory));
4289 Local<Value> result = script->Run(); 4276 Local<Value> result = script->Run();
4290 4277
4291 // Check for out of memory state. 4278 // Check for out of memory state.
4292 CHECK(result.IsEmpty()); 4279 CHECK(result.IsEmpty());
4293 CHECK(context->HasOutOfMemoryException()); 4280 CHECK(context->HasOutOfMemoryException());
4294 4281
4295 args.GetReturnValue().Set(result); 4282 args.GetReturnValue().Set(result);
4296 } 4283 }
4297 4284
4298 4285
4299 TEST(OutOfMemoryNested) { 4286 TEST(OutOfMemoryNested) {
4300 // It's not possible to read a snapshot into a heap with different dimensions. 4287 // It's not possible to read a snapshot into a heap with different dimensions.
4301 if (i::Snapshot::IsEnabled()) return; 4288 if (i::Snapshot::IsEnabled()) return;
4302 // Set heap limits. 4289 // Set heap limits.
4303 static const int K = 1024; 4290 static const int K = 1024;
4304 v8::ResourceConstraints constraints; 4291 v8::ResourceConstraints constraints;
4305 constraints.set_max_young_space_size(256 * K); 4292 constraints.set_max_young_space_size(256 * K);
4306 constraints.set_max_old_space_size(5 * K * K); 4293 constraints.set_max_old_space_size(5 * K * K);
4307 v8::SetResourceConstraints(&constraints); 4294 v8::SetResourceConstraints(CcTest::isolate(), &constraints);
4308 4295
4309 v8::HandleScope scope(CcTest::isolate()); 4296 v8::HandleScope scope(CcTest::isolate());
4310 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4297 Local<ObjectTemplate> templ = ObjectTemplate::New();
4311 templ->Set(v8_str("ProvokeOutOfMemory"), 4298 templ->Set(v8_str("ProvokeOutOfMemory"),
4312 v8::FunctionTemplate::New(ProvokeOutOfMemory)); 4299 v8::FunctionTemplate::New(ProvokeOutOfMemory));
4313 LocalContext context(0, templ); 4300 LocalContext context(0, templ);
4314 v8::V8::IgnoreOutOfMemoryException(); 4301 v8::V8::IgnoreOutOfMemoryException();
4315 Local<Value> result = CompileRun( 4302 Local<Value> result = CompileRun(
4316 "var thrown = false;" 4303 "var thrown = false;"
4317 "try {" 4304 "try {"
4318 " ProvokeOutOfMemory();" 4305 " ProvokeOutOfMemory();"
4319 "} catch (e) {" 4306 "} catch (e) {"
4320 " thrown = true;" 4307 " thrown = true;"
4321 "}"); 4308 "}");
4322 // Check for out of memory state. 4309 // Check for out of memory state.
4323 CHECK(result.IsEmpty()); 4310 CHECK(result.IsEmpty());
4324 CHECK(context->HasOutOfMemoryException()); 4311 CHECK(context->HasOutOfMemoryException());
4325 } 4312 }
4326 4313
4327 4314
4328 TEST(HugeConsStringOutOfMemory) { 4315 TEST(HugeConsStringOutOfMemory) {
4329 // It's not possible to read a snapshot into a heap with different dimensions. 4316 // It's not possible to read a snapshot into a heap with different dimensions.
4330 if (i::Snapshot::IsEnabled()) return; 4317 if (i::Snapshot::IsEnabled()) return;
4331 // Set heap limits. 4318 // Set heap limits.
4332 static const int K = 1024; 4319 static const int K = 1024;
4333 v8::ResourceConstraints constraints; 4320 v8::ResourceConstraints constraints;
4334 constraints.set_max_young_space_size(256 * K); 4321 constraints.set_max_young_space_size(256 * K);
4335 constraints.set_max_old_space_size(4 * K * K); 4322 constraints.set_max_old_space_size(4 * K * K);
4336 v8::SetResourceConstraints(&constraints); 4323 v8::SetResourceConstraints(CcTest::isolate(), &constraints);
4337 4324
4338 // Execute a script that causes out of memory. 4325 // Execute a script that causes out of memory.
4339 v8::V8::IgnoreOutOfMemoryException(); 4326 v8::V8::IgnoreOutOfMemoryException();
4340 4327
4341 LocalContext context; 4328 LocalContext context;
4342 v8::HandleScope scope(context->GetIsolate()); 4329 v8::HandleScope scope(context->GetIsolate());
4343 4330
4344 // Build huge string. This should fail with out of memory exception. 4331 // Build huge string. This should fail with out of memory exception.
4345 Local<Value> result = CompileRun( 4332 Local<Value> result = CompileRun(
4346 "var str = Array.prototype.join.call({length: 513}, \"A\").toUpperCase();" 4333 "var str = Array.prototype.join.call({length: 513}, \"A\").toUpperCase();"
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
5168 CHECK(!v8_num(1)->StrictEquals(v8_num(2))); 5155 CHECK(!v8_num(1)->StrictEquals(v8_num(2)));
5169 CHECK(v8_num(0.0)->StrictEquals(v8_num(-0.0))); 5156 CHECK(v8_num(0.0)->StrictEquals(v8_num(-0.0)));
5170 Local<Value> not_a_number = v8_num(i::OS::nan_value()); 5157 Local<Value> not_a_number = v8_num(i::OS::nan_value());
5171 CHECK(!not_a_number->StrictEquals(not_a_number)); 5158 CHECK(!not_a_number->StrictEquals(not_a_number));
5172 CHECK(v8::False(isolate)->StrictEquals(v8::False(isolate))); 5159 CHECK(v8::False(isolate)->StrictEquals(v8::False(isolate)));
5173 CHECK(!v8::False(isolate)->StrictEquals(v8::Undefined(isolate))); 5160 CHECK(!v8::False(isolate)->StrictEquals(v8::Undefined(isolate)));
5174 5161
5175 v8::Handle<v8::Object> obj = v8::Object::New(); 5162 v8::Handle<v8::Object> obj = v8::Object::New();
5176 v8::Persistent<v8::Object> alias(isolate, obj); 5163 v8::Persistent<v8::Object> alias(isolate, obj);
5177 CHECK(v8::Local<v8::Object>::New(isolate, alias)->StrictEquals(obj)); 5164 CHECK(v8::Local<v8::Object>::New(isolate, alias)->StrictEquals(obj));
5178 alias.Dispose(); 5165 alias.Reset();
5179 5166
5180 CHECK(v8_str("a")->SameValue(v8_str("a"))); 5167 CHECK(v8_str("a")->SameValue(v8_str("a")));
5181 CHECK(!v8_str("a")->SameValue(v8_str("b"))); 5168 CHECK(!v8_str("a")->SameValue(v8_str("b")));
5182 CHECK(!v8_str("5")->SameValue(v8_num(5))); 5169 CHECK(!v8_str("5")->SameValue(v8_num(5)));
5183 CHECK(v8_num(1)->SameValue(v8_num(1))); 5170 CHECK(v8_num(1)->SameValue(v8_num(1)));
5184 CHECK(!v8_num(1)->SameValue(v8_num(2))); 5171 CHECK(!v8_num(1)->SameValue(v8_num(2)));
5185 CHECK(!v8_num(0.0)->SameValue(v8_num(-0.0))); 5172 CHECK(!v8_num(0.0)->SameValue(v8_num(-0.0)));
5186 CHECK(not_a_number->SameValue(not_a_number)); 5173 CHECK(not_a_number->SameValue(not_a_number));
5187 CHECK(v8::False(isolate)->SameValue(v8::False(isolate))); 5174 CHECK(v8::False(isolate)->SameValue(v8::False(isolate)));
5188 CHECK(!v8::False(isolate)->SameValue(v8::Undefined(isolate))); 5175 CHECK(!v8::False(isolate)->SameValue(v8::Undefined(isolate)));
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
5493 v8::HandleScope scope(CcTest::isolate()); 5480 v8::HandleScope scope(CcTest::isolate());
5494 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5481 Local<ObjectTemplate> templ = ObjectTemplate::New();
5495 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut")); 5482 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut"));
5496 LocalContext context; 5483 LocalContext context;
5497 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5484 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5498 Local<Script> script = Script::Compile(v8_str("obj.x = 4")); 5485 Local<Script> script = Script::Compile(v8_str("obj.x = 4"));
5499 for (int i = 0; i < 10; i++) { 5486 for (int i = 0; i < 10; i++) {
5500 CHECK(xValue.IsEmpty()); 5487 CHECK(xValue.IsEmpty());
5501 script->Run(); 5488 script->Run();
5502 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue)); 5489 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue));
5503 xValue.Dispose(); 5490 xValue.Reset();
5504 xValue.Clear();
5505 } 5491 }
5506 } 5492 }
5507 5493
5508 5494
5509 THREADED_TEST(SetterOnly) { 5495 THREADED_TEST(SetterOnly) {
5510 v8::HandleScope scope(CcTest::isolate()); 5496 v8::HandleScope scope(CcTest::isolate());
5511 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5497 Local<ObjectTemplate> templ = ObjectTemplate::New();
5512 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut")); 5498 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut"));
5513 LocalContext context; 5499 LocalContext context;
5514 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5500 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5515 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); 5501 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x"));
5516 for (int i = 0; i < 10; i++) { 5502 for (int i = 0; i < 10; i++) {
5517 CHECK(xValue.IsEmpty()); 5503 CHECK(xValue.IsEmpty());
5518 script->Run(); 5504 script->Run();
5519 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue)); 5505 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue));
5520 xValue.Dispose(); 5506 xValue.Reset();
5521 xValue.Clear();
5522 } 5507 }
5523 } 5508 }
5524 5509
5525 5510
5526 THREADED_TEST(NoAccessors) { 5511 THREADED_TEST(NoAccessors) {
5527 v8::HandleScope scope(CcTest::isolate()); 5512 v8::HandleScope scope(CcTest::isolate());
5528 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5513 Local<ObjectTemplate> templ = ObjectTemplate::New();
5529 templ->SetAccessor(v8_str("x"), 5514 templ->SetAccessor(v8_str("x"),
5530 static_cast<v8::AccessorGetterCallback>(NULL), 5515 static_cast<v8::AccessorGetterCallback>(NULL),
5531 NULL, 5516 NULL,
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
6301 script->Run(); 6286 script->Run();
6302 ExpectBoolean("undetectable.y == undefined", true); 6287 ExpectBoolean("undetectable.y == undefined", true);
6303 } 6288 }
6304 6289
6305 6290
6306 6291
6307 THREADED_TEST(UndetectableString) { 6292 THREADED_TEST(UndetectableString) {
6308 LocalContext env; 6293 LocalContext env;
6309 v8::HandleScope scope(env->GetIsolate()); 6294 v8::HandleScope scope(env->GetIsolate());
6310 6295
6311 Local<String> obj = String::NewUndetectable("foo"); 6296 Local<String> obj = String::NewFromUtf8(env->GetIsolate(), "foo",
6297 String::kUndetectableString);
6312 env->Global()->Set(v8_str("undetectable"), obj); 6298 env->Global()->Set(v8_str("undetectable"), obj);
6313 6299
6314 ExpectString("undetectable", "foo"); 6300 ExpectString("undetectable", "foo");
6315 ExpectString("typeof undetectable", "undefined"); 6301 ExpectString("typeof undetectable", "undefined");
6316 ExpectString("typeof(undetectable)", "undefined"); 6302 ExpectString("typeof(undetectable)", "undefined");
6317 ExpectBoolean("typeof undetectable == 'undefined'", true); 6303 ExpectBoolean("typeof undetectable == 'undefined'", true);
6318 ExpectBoolean("typeof undetectable == 'string'", false); 6304 ExpectBoolean("typeof undetectable == 'string'", false);
6319 ExpectBoolean("if (undetectable) { true; } else { false; }", false); 6305 ExpectBoolean("if (undetectable) { true; } else { false; }", false);
6320 ExpectBoolean("!undetectable", true); 6306 ExpectBoolean("!undetectable", true);
6321 6307
(...skipping 20 matching lines...) Expand all
6342 ExpectBoolean("undefined===undetectable", false); 6328 ExpectBoolean("undefined===undetectable", false);
6343 ExpectBoolean("undetectable===undetectable", true); 6329 ExpectBoolean("undetectable===undetectable", true);
6344 } 6330 }
6345 6331
6346 6332
6347 TEST(UndetectableOptimized) { 6333 TEST(UndetectableOptimized) {
6348 i::FLAG_allow_natives_syntax = true; 6334 i::FLAG_allow_natives_syntax = true;
6349 LocalContext env; 6335 LocalContext env;
6350 v8::HandleScope scope(env->GetIsolate()); 6336 v8::HandleScope scope(env->GetIsolate());
6351 6337
6352 Local<String> obj = String::NewUndetectable("foo"); 6338 Local<String> obj = String::NewFromUtf8(env->GetIsolate(), "foo",
6339 String::kUndetectableString);
6353 env->Global()->Set(v8_str("undetectable"), obj); 6340 env->Global()->Set(v8_str("undetectable"), obj);
6354 env->Global()->Set(v8_str("detectable"), v8_str("bar")); 6341 env->Global()->Set(v8_str("detectable"), v8_str("bar"));
6355 6342
6356 ExpectString( 6343 ExpectString(
6357 "function testBranch() {" 6344 "function testBranch() {"
6358 " if (!%_IsUndetectableObject(undetectable)) throw 1;" 6345 " if (!%_IsUndetectableObject(undetectable)) throw 1;"
6359 " if (%_IsUndetectableObject(detectable)) throw 2;" 6346 " if (%_IsUndetectableObject(detectable)) throw 2;"
6360 "}\n" 6347 "}\n"
6361 "function testBool() {" 6348 "function testBool() {"
6362 " var b1 = !%_IsUndetectableObject(undetectable);" 6349 " var b1 = !%_IsUndetectableObject(undetectable);"
(...skipping 14 matching lines...) Expand all
6377 6364
6378 6365
6379 template <typename T> static void USE(T) { } 6366 template <typename T> static void USE(T) { }
6380 6367
6381 6368
6382 // This test is not intended to be run, just type checked. 6369 // This test is not intended to be run, just type checked.
6383 static inline void PersistentHandles(v8::Isolate* isolate) { 6370 static inline void PersistentHandles(v8::Isolate* isolate) {
6384 USE(PersistentHandles); 6371 USE(PersistentHandles);
6385 Local<String> str = v8_str("foo"); 6372 Local<String> str = v8_str("foo");
6386 v8::Persistent<String> p_str(isolate, str); 6373 v8::Persistent<String> p_str(isolate, str);
6387 p_str.Dispose(); 6374 p_str.Reset();
6388 Local<Script> scr = Script::Compile(v8_str("")); 6375 Local<Script> scr = Script::Compile(v8_str(""));
6389 v8::Persistent<Script> p_scr(isolate, scr); 6376 v8::Persistent<Script> p_scr(isolate, scr);
6390 p_scr.Dispose(); 6377 p_scr.Reset();
6391 Local<ObjectTemplate> templ = ObjectTemplate::New(); 6378 Local<ObjectTemplate> templ = ObjectTemplate::New();
6392 v8::Persistent<ObjectTemplate> p_templ(isolate, templ); 6379 v8::Persistent<ObjectTemplate> p_templ(isolate, templ);
6393 p_templ.Dispose(); 6380 p_templ.Reset();
6394 } 6381 }
6395 6382
6396 6383
6397 static void HandleLogDelegator( 6384 static void HandleLogDelegator(
6398 const v8::FunctionCallbackInfo<v8::Value>& args) { 6385 const v8::FunctionCallbackInfo<v8::Value>& args) {
6399 ApiTestFuzzer::Fuzz(); 6386 ApiTestFuzzer::Fuzz();
6400 } 6387 }
6401 6388
6402 6389
6403 THREADED_TEST(GlobalObjectTemplate) { 6390 THREADED_TEST(GlobalObjectTemplate) {
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
6690 v8::Handle<Context> context = 6677 v8::Handle<Context> context =
6691 Context::New(CcTest::isolate(), &extensions); 6678 Context::New(CcTest::isolate(), &extensions);
6692 CHECK(context.IsEmpty()); 6679 CHECK(context.IsEmpty());
6693 } 6680 }
6694 6681
6695 6682
6696 static void CheckDependencies(const char* name, const char* expected) { 6683 static void CheckDependencies(const char* name, const char* expected) {
6697 v8::HandleScope handle_scope(CcTest::isolate()); 6684 v8::HandleScope handle_scope(CcTest::isolate());
6698 v8::ExtensionConfiguration config(1, &name); 6685 v8::ExtensionConfiguration config(1, &name);
6699 LocalContext context(&config); 6686 LocalContext context(&config);
6700 CHECK_EQ(String::New(expected), context->Global()->Get(v8_str("loaded"))); 6687 CHECK_EQ(String::NewFromUtf8(CcTest::isolate(), expected),
6688 context->Global()->Get(v8_str("loaded")));
6701 } 6689 }
6702 6690
6703 6691
6704 /* 6692 /*
6705 * Configuration: 6693 * Configuration:
6706 * 6694 *
6707 * /-- B <--\ 6695 * /-- B <--\
6708 * A <- -- D <-- E 6696 * A <- -- D <-- E
6709 * \-- C <--/ 6697 * \-- C <--/
6710 */ 6698 */
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
6847 void OOMCallback(const char* location, const char* message) { 6835 void OOMCallback(const char* location, const char* message) {
6848 exit(0); 6836 exit(0);
6849 } 6837 }
6850 6838
6851 6839
6852 TEST(RegexpOutOfMemory) { 6840 TEST(RegexpOutOfMemory) {
6853 // Execute a script that causes out of memory when flattening a string. 6841 // Execute a script that causes out of memory when flattening a string.
6854 v8::HandleScope scope(CcTest::isolate()); 6842 v8::HandleScope scope(CcTest::isolate());
6855 v8::V8::SetFatalErrorHandler(OOMCallback); 6843 v8::V8::SetFatalErrorHandler(OOMCallback);
6856 LocalContext context; 6844 LocalContext context;
6857 Local<Script> script = 6845 Local<Script> script = Script::Compile(String::NewFromUtf8(
6858 Script::Compile(String::New(js_code_causing_huge_string_flattening)); 6846 CcTest::isolate(), js_code_causing_huge_string_flattening));
6859 last_location = NULL; 6847 last_location = NULL;
6860 script->Run(); 6848 script->Run();
6861 6849
6862 CHECK(false); // Should not return. 6850 CHECK(false); // Should not return.
6863 } 6851 }
6864 6852
6865 6853
6866 static void MissingScriptInfoMessageListener(v8::Handle<v8::Message> message, 6854 static void MissingScriptInfoMessageListener(v8::Handle<v8::Message> message,
6867 v8::Handle<Value> data) { 6855 v8::Handle<Value> data) {
6868 CHECK(message->GetScriptResourceName()->IsUndefined()); 6856 CHECK(message->GetScriptResourceName()->IsUndefined());
(...skipping 16 matching lines...) Expand all
6885 6873
6886 class Snorkel { 6874 class Snorkel {
6887 public: 6875 public:
6888 Snorkel() { index_ = global_index++; } 6876 Snorkel() { index_ = global_index++; }
6889 int index_; 6877 int index_;
6890 }; 6878 };
6891 6879
6892 class Whammy { 6880 class Whammy {
6893 public: 6881 public:
6894 explicit Whammy(v8::Isolate* isolate) : cursor_(0), isolate_(isolate) { } 6882 explicit Whammy(v8::Isolate* isolate) : cursor_(0), isolate_(isolate) { }
6895 ~Whammy() { script_.Dispose(); } 6883 ~Whammy() { script_.Reset(); }
6896 v8::Handle<Script> getScript() { 6884 v8::Handle<Script> getScript() {
6897 if (script_.IsEmpty()) script_.Reset(isolate_, v8_compile("({}).blammo")); 6885 if (script_.IsEmpty()) script_.Reset(isolate_, v8_compile("({}).blammo"));
6898 return Local<Script>::New(isolate_, script_); 6886 return Local<Script>::New(isolate_, script_);
6899 } 6887 }
6900 6888
6901 public: 6889 public:
6902 static const int kObjectCount = 256; 6890 static const int kObjectCount = 256;
6903 int cursor_; 6891 int cursor_;
6904 v8::Isolate* isolate_; 6892 v8::Isolate* isolate_;
6905 v8::Persistent<v8::Object> objects_[kObjectCount]; 6893 v8::Persistent<v8::Object> objects_[kObjectCount];
(...skipping 12 matching lines...) Expand all
6918 Whammy* whammy = 6906 Whammy* whammy =
6919 static_cast<Whammy*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); 6907 static_cast<Whammy*>(v8::Handle<v8::External>::Cast(info.Data())->Value());
6920 6908
6921 v8::Persistent<v8::Object>& prev = whammy->objects_[whammy->cursor_]; 6909 v8::Persistent<v8::Object>& prev = whammy->objects_[whammy->cursor_];
6922 6910
6923 v8::Handle<v8::Object> obj = v8::Object::New(); 6911 v8::Handle<v8::Object> obj = v8::Object::New();
6924 if (!prev.IsEmpty()) { 6912 if (!prev.IsEmpty()) {
6925 v8::Local<v8::Object>::New(info.GetIsolate(), prev) 6913 v8::Local<v8::Object>::New(info.GetIsolate(), prev)
6926 ->Set(v8_str("next"), obj); 6914 ->Set(v8_str("next"), obj);
6927 prev.MakeWeak<Value, Snorkel>(new Snorkel(), &HandleWeakReference); 6915 prev.MakeWeak<Value, Snorkel>(new Snorkel(), &HandleWeakReference);
6928 whammy->objects_[whammy->cursor_].Clear();
6929 } 6916 }
6930 whammy->objects_[whammy->cursor_].Reset(info.GetIsolate(), obj); 6917 whammy->objects_[whammy->cursor_].Reset(info.GetIsolate(), obj);
6931 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount; 6918 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount;
6932 info.GetReturnValue().Set(whammy->getScript()->Run()); 6919 info.GetReturnValue().Set(whammy->getScript()->Run());
6933 } 6920 }
6934 6921
6935 6922
6936 THREADED_TEST(WeakReference) { 6923 THREADED_TEST(WeakReference) {
6937 v8::HandleScope handle_scope(CcTest::isolate()); 6924 v8::HandleScope handle_scope(CcTest::isolate());
6938 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New(); 6925 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New();
(...skipping 20 matching lines...) Expand all
6959 "4"; 6946 "4";
6960 v8::Handle<Value> result = CompileRun(code); 6947 v8::Handle<Value> result = CompileRun(code);
6961 CHECK_EQ(4.0, result->NumberValue()); 6948 CHECK_EQ(4.0, result->NumberValue());
6962 delete whammy; 6949 delete whammy;
6963 } 6950 }
6964 6951
6965 6952
6966 static void DisposeAndSetFlag(v8::Isolate* isolate, 6953 static void DisposeAndSetFlag(v8::Isolate* isolate,
6967 v8::Persistent<v8::Object>* obj, 6954 v8::Persistent<v8::Object>* obj,
6968 bool* data) { 6955 bool* data) {
6969 obj->Dispose(); 6956 obj->Reset();
6970 *(data) = true; 6957 *(data) = true;
6971 } 6958 }
6972 6959
6973 6960
6974 THREADED_TEST(IndependentWeakHandle) { 6961 THREADED_TEST(IndependentWeakHandle) {
6975 v8::Isolate* iso = CcTest::isolate(); 6962 v8::Isolate* iso = CcTest::isolate();
6976 v8::HandleScope scope(iso); 6963 v8::HandleScope scope(iso);
6977 v8::Handle<Context> context = Context::New(iso); 6964 v8::Handle<Context> context = Context::New(iso);
6978 Context::Scope context_scope(context); 6965 Context::Scope context_scope(context);
6979 6966
(...skipping 25 matching lines...) Expand all
7005 6992
7006 6993
7007 static void InvokeMarkSweep() { 6994 static void InvokeMarkSweep() {
7008 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 6995 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
7009 } 6996 }
7010 6997
7011 6998
7012 static void ForceScavenge(v8::Isolate* isolate, 6999 static void ForceScavenge(v8::Isolate* isolate,
7013 v8::Persistent<v8::Object>* obj, 7000 v8::Persistent<v8::Object>* obj,
7014 bool* data) { 7001 bool* data) {
7015 obj->Dispose(); 7002 obj->Reset();
7016 *(data) = true; 7003 *(data) = true;
7017 InvokeScavenge(); 7004 InvokeScavenge();
7018 } 7005 }
7019 7006
7020 7007
7021 static void ForceMarkSweep(v8::Isolate* isolate, 7008 static void ForceMarkSweep(v8::Isolate* isolate,
7022 v8::Persistent<v8::Object>* obj, 7009 v8::Persistent<v8::Object>* obj,
7023 bool* data) { 7010 bool* data) {
7024 obj->Dispose(); 7011 obj->Reset();
7025 *(data) = true; 7012 *(data) = true;
7026 InvokeMarkSweep(); 7013 InvokeMarkSweep();
7027 } 7014 }
7028 7015
7029 7016
7030 THREADED_TEST(GCFromWeakCallbacks) { 7017 THREADED_TEST(GCFromWeakCallbacks) {
7031 v8::Isolate* isolate = CcTest::isolate(); 7018 v8::Isolate* isolate = CcTest::isolate();
7032 v8::HandleScope scope(isolate); 7019 v8::HandleScope scope(isolate);
7033 v8::Handle<Context> context = Context::New(isolate); 7020 v8::Handle<Context> context = Context::New(isolate);
7034 Context::Scope context_scope(context); 7021 Context::Scope context_scope(context);
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
7407 return len; 7394 return len;
7408 } 7395 }
7409 7396
7410 7397
7411 THREADED_TEST(StringWrite) { 7398 THREADED_TEST(StringWrite) {
7412 LocalContext context; 7399 LocalContext context;
7413 v8::HandleScope scope(context->GetIsolate()); 7400 v8::HandleScope scope(context->GetIsolate());
7414 v8::Handle<String> str = v8_str("abcde"); 7401 v8::Handle<String> str = v8_str("abcde");
7415 // abc<Icelandic eth><Unicode snowman>. 7402 // abc<Icelandic eth><Unicode snowman>.
7416 v8::Handle<String> str2 = v8_str("abc\303\260\342\230\203"); 7403 v8::Handle<String> str2 = v8_str("abc\303\260\342\230\203");
7417 v8::Handle<String> str3 = v8::String::New("abc\0def", 7); 7404 v8::Handle<String> str3 = v8::String::NewFromUtf8(
7405 context->GetIsolate(), "abc\0def", v8::String::kNormalString, 7);
7418 const int kStride = 4; // Must match stride in for loops in JS below. 7406 const int kStride = 4; // Must match stride in for loops in JS below.
7419 CompileRun( 7407 CompileRun(
7420 "var left = '';" 7408 "var left = '';"
7421 "for (var i = 0; i < 0xd800; i += 4) {" 7409 "for (var i = 0; i < 0xd800; i += 4) {"
7422 " left = left + String.fromCharCode(i);" 7410 " left = left + String.fromCharCode(i);"
7423 "}"); 7411 "}");
7424 CompileRun( 7412 CompileRun(
7425 "var right = '';" 7413 "var right = '';"
7426 "for (var i = 0; i < 0xd800; i += 4) {" 7414 "for (var i = 0; i < 0xd800; i += 4) {"
7427 " right = String.fromCharCode(i) + right;" 7415 " right = String.fromCharCode(i) + right;"
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
7801 WriteUtf8Helper(context, "c2", "a2lens", 81); 7789 WriteUtf8Helper(context, "c2", "a2lens", 81);
7802 } 7790 }
7803 7791
7804 7792
7805 static bool SameSymbol(Handle<String> s1, Handle<String> s2) { 7793 static bool SameSymbol(Handle<String> s1, Handle<String> s2) {
7806 i::Handle<i::String> is1(v8::Utils::OpenHandle(*s1)); 7794 i::Handle<i::String> is1(v8::Utils::OpenHandle(*s1));
7807 i::Handle<i::String> is2(v8::Utils::OpenHandle(*s2)); 7795 i::Handle<i::String> is2(v8::Utils::OpenHandle(*s2));
7808 return *is1 == *is2; 7796 return *is1 == *is2;
7809 } 7797 }
7810 7798
7811 7799 static void SameSymbolHelper(v8::Isolate* isolate, const char* a,
7812 static void SameSymbolHelper(const char* a, const char* b) { 7800 const char* b) {
7813 Handle<String> symbol1 = v8::String::NewSymbol(a); 7801 Handle<String> symbol1 =
7814 Handle<String> symbol2 = v8::String::NewSymbol(b); 7802 v8::String::NewFromUtf8(isolate, a, v8::String::kInternalizedString);
7803 Handle<String> symbol2 =
7804 v8::String::NewFromUtf8(isolate, b, v8::String::kInternalizedString);
7815 CHECK(SameSymbol(symbol1, symbol2)); 7805 CHECK(SameSymbol(symbol1, symbol2));
7816 } 7806 }
7817 7807
7818 7808
7819 THREADED_TEST(Utf16Symbol) { 7809 THREADED_TEST(Utf16Symbol) {
7820 LocalContext context; 7810 LocalContext context;
7821 v8::HandleScope scope(context->GetIsolate()); 7811 v8::HandleScope scope(context->GetIsolate());
7822 7812
7823 Handle<String> symbol1 = v8::String::NewSymbol("abc"); 7813 Handle<String> symbol1 = v8::String::NewFromUtf8(
7824 Handle<String> symbol2 = v8::String::NewSymbol("abc"); 7814 context->GetIsolate(), "abc", v8::String::kInternalizedString);
7815 Handle<String> symbol2 = v8::String::NewFromUtf8(
7816 context->GetIsolate(), "abc", v8::String::kInternalizedString);
7825 CHECK(SameSymbol(symbol1, symbol2)); 7817 CHECK(SameSymbol(symbol1, symbol2));
7826 7818
7827 SameSymbolHelper("\360\220\220\205", // 4 byte encoding. 7819 SameSymbolHelper(context->GetIsolate(),
7820 "\360\220\220\205", // 4 byte encoding.
7828 "\355\240\201\355\260\205"); // 2 3-byte surrogates. 7821 "\355\240\201\355\260\205"); // 2 3-byte surrogates.
7829 SameSymbolHelper("\355\240\201\355\260\206", // 2 3-byte surrogates. 7822 SameSymbolHelper(context->GetIsolate(),
7823 "\355\240\201\355\260\206", // 2 3-byte surrogates.
7830 "\360\220\220\206"); // 4 byte encoding. 7824 "\360\220\220\206"); // 4 byte encoding.
7831 SameSymbolHelper("x\360\220\220\205", // 4 byte encoding. 7825 SameSymbolHelper(context->GetIsolate(),
7826 "x\360\220\220\205", // 4 byte encoding.
7832 "x\355\240\201\355\260\205"); // 2 3-byte surrogates. 7827 "x\355\240\201\355\260\205"); // 2 3-byte surrogates.
7833 SameSymbolHelper("x\355\240\201\355\260\206", // 2 3-byte surrogates. 7828 SameSymbolHelper(context->GetIsolate(),
7829 "x\355\240\201\355\260\206", // 2 3-byte surrogates.
7834 "x\360\220\220\206"); // 4 byte encoding. 7830 "x\360\220\220\206"); // 4 byte encoding.
7835 CompileRun( 7831 CompileRun(
7836 "var sym0 = 'benedictus';" 7832 "var sym0 = 'benedictus';"
7837 "var sym0b = 'S\303\270ren';" 7833 "var sym0b = 'S\303\270ren';"
7838 "var sym1 = '\355\240\201\355\260\207';" 7834 "var sym1 = '\355\240\201\355\260\207';"
7839 "var sym2 = '\360\220\220\210';" 7835 "var sym2 = '\360\220\220\210';"
7840 "var sym3 = 'x\355\240\201\355\260\207';" 7836 "var sym3 = 'x\355\240\201\355\260\207';"
7841 "var sym4 = 'x\360\220\220\210';" 7837 "var sym4 = 'x\360\220\220\210';"
7842 "if (sym1.length != 2) throw sym1;" 7838 "if (sym1.length != 2) throw sym1;"
7843 "if (sym1.charCodeAt(1) != 0xdc07) throw sym1.charCodeAt(1);" 7839 "if (sym1.charCodeAt(1) != 0xdc07) throw sym1.charCodeAt(1);"
7844 "if (sym2.length != 2) throw sym2;" 7840 "if (sym2.length != 2) throw sym2;"
7845 "if (sym2.charCodeAt(1) != 0xdc08) throw sym2.charCodeAt(2);" 7841 "if (sym2.charCodeAt(1) != 0xdc08) throw sym2.charCodeAt(2);"
7846 "if (sym3.length != 3) throw sym3;" 7842 "if (sym3.length != 3) throw sym3;"
7847 "if (sym3.charCodeAt(2) != 0xdc07) throw sym1.charCodeAt(2);" 7843 "if (sym3.charCodeAt(2) != 0xdc07) throw sym1.charCodeAt(2);"
7848 "if (sym4.length != 3) throw sym4;" 7844 "if (sym4.length != 3) throw sym4;"
7849 "if (sym4.charCodeAt(2) != 0xdc08) throw sym2.charCodeAt(2);"); 7845 "if (sym4.charCodeAt(2) != 0xdc08) throw sym2.charCodeAt(2);");
7850 Handle<String> sym0 = v8::String::NewSymbol("benedictus"); 7846 Handle<String> sym0 = v8::String::NewFromUtf8(
7851 Handle<String> sym0b = v8::String::NewSymbol("S\303\270ren"); 7847 context->GetIsolate(), "benedictus", v8::String::kInternalizedString);
7852 Handle<String> sym1 = v8::String::NewSymbol("\355\240\201\355\260\207"); 7848 Handle<String> sym0b = v8::String::NewFromUtf8(
7853 Handle<String> sym2 = v8::String::NewSymbol("\360\220\220\210"); 7849 context->GetIsolate(), "S\303\270ren", v8::String::kInternalizedString);
7854 Handle<String> sym3 = v8::String::NewSymbol("x\355\240\201\355\260\207"); 7850 Handle<String> sym1 =
7855 Handle<String> sym4 = v8::String::NewSymbol("x\360\220\220\210"); 7851 v8::String::NewFromUtf8(context->GetIsolate(), "\355\240\201\355\260\207",
7852 v8::String::kInternalizedString);
7853 Handle<String> sym2 =
7854 v8::String::NewFromUtf8(context->GetIsolate(), "\360\220\220\210",
7855 v8::String::kInternalizedString);
7856 Handle<String> sym3 = v8::String::NewFromUtf8(
7857 context->GetIsolate(), "x\355\240\201\355\260\207",
7858 v8::String::kInternalizedString);
7859 Handle<String> sym4 =
7860 v8::String::NewFromUtf8(context->GetIsolate(), "x\360\220\220\210",
7861 v8::String::kInternalizedString);
7856 v8::Local<v8::Object> global = context->Global(); 7862 v8::Local<v8::Object> global = context->Global();
7857 Local<Value> s0 = global->Get(v8_str("sym0")); 7863 Local<Value> s0 = global->Get(v8_str("sym0"));
7858 Local<Value> s0b = global->Get(v8_str("sym0b")); 7864 Local<Value> s0b = global->Get(v8_str("sym0b"));
7859 Local<Value> s1 = global->Get(v8_str("sym1")); 7865 Local<Value> s1 = global->Get(v8_str("sym1"));
7860 Local<Value> s2 = global->Get(v8_str("sym2")); 7866 Local<Value> s2 = global->Get(v8_str("sym2"));
7861 Local<Value> s3 = global->Get(v8_str("sym3")); 7867 Local<Value> s3 = global->Get(v8_str("sym3"));
7862 Local<Value> s4 = global->Get(v8_str("sym4")); 7868 Local<Value> s4 = global->Get(v8_str("sym4"));
7863 CHECK(SameSymbol(sym0, Handle<String>::Cast(s0))); 7869 CHECK(SameSymbol(sym0, Handle<String>::Cast(s0)));
7864 CHECK(SameSymbol(sym0b, Handle<String>::Cast(s0b))); 7870 CHECK(SameSymbol(sym0b, Handle<String>::Cast(s0b)));
7865 CHECK(SameSymbol(sym1, Handle<String>::Cast(s1))); 7871 CHECK(SameSymbol(sym1, Handle<String>::Cast(s1)));
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
8076 8082
8077 TEST(ExceptionInNativeScript) { 8083 TEST(ExceptionInNativeScript) {
8078 LocalContext env; 8084 LocalContext env;
8079 v8::HandleScope scope(env->GetIsolate()); 8085 v8::HandleScope scope(env->GetIsolate());
8080 v8::V8::AddMessageListener(ExceptionInNativeScriptTestListener); 8086 v8::V8::AddMessageListener(ExceptionInNativeScriptTestListener);
8081 8087
8082 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(TroubleCallback); 8088 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(TroubleCallback);
8083 v8::Local<v8::Object> global = env->Global(); 8089 v8::Local<v8::Object> global = env->Global();
8084 global->Set(v8_str("trouble"), fun->GetFunction()); 8090 global->Set(v8_str("trouble"), fun->GetFunction());
8085 8091
8086 Script::Compile(v8_str("function trouble() {\n" 8092 Script::Compile(
8087 " var o = {};\n" 8093 v8_str(
8088 " new o.foo();\n" 8094 "function trouble() {\n"
8089 "};"), v8::String::New(script_resource_name))->Run(); 8095 " var o = {};\n"
8096 " new o.foo();\n"
8097 "};"),
8098 v8::String::NewFromUtf8(env->GetIsolate(), script_resource_name))->Run();
8090 Local<Value> trouble = global->Get(v8_str("trouble")); 8099 Local<Value> trouble = global->Get(v8_str("trouble"));
8091 CHECK(trouble->IsFunction()); 8100 CHECK(trouble->IsFunction());
8092 Function::Cast(*trouble)->Call(global, 0, NULL); 8101 Function::Cast(*trouble)->Call(global, 0, NULL);
8093 v8::V8::RemoveMessageListeners(ExceptionInNativeScriptTestListener); 8102 v8::V8::RemoveMessageListeners(ExceptionInNativeScriptTestListener);
8094 } 8103 }
8095 8104
8096 8105
8097 TEST(CompilationErrorUsingTryCatchHandler) { 8106 TEST(CompilationErrorUsingTryCatchHandler) {
8098 LocalContext env; 8107 LocalContext env;
8099 v8::HandleScope scope(env->GetIsolate()); 8108 v8::HandleScope scope(env->GetIsolate());
(...skipping 4928 matching lines...) Expand 10 before | Expand all | Expand 10 after
13028 13037
13029 13038
13030 v8::Persistent<v8::Object> some_object; 13039 v8::Persistent<v8::Object> some_object;
13031 v8::Persistent<v8::Object> bad_handle; 13040 v8::Persistent<v8::Object> bad_handle;
13032 13041
13033 void NewPersistentHandleCallback(v8::Isolate* isolate, 13042 void NewPersistentHandleCallback(v8::Isolate* isolate,
13034 v8::Persistent<v8::Value>* handle, 13043 v8::Persistent<v8::Value>* handle,
13035 void*) { 13044 void*) {
13036 v8::HandleScope scope(isolate); 13045 v8::HandleScope scope(isolate);
13037 bad_handle.Reset(isolate, some_object); 13046 bad_handle.Reset(isolate, some_object);
13038 handle->Dispose(); 13047 handle->Reset();
13039 } 13048 }
13040 13049
13041 13050
13042 THREADED_TEST(NewPersistentHandleFromWeakCallback) { 13051 THREADED_TEST(NewPersistentHandleFromWeakCallback) {
13043 LocalContext context; 13052 LocalContext context;
13044 v8::Isolate* isolate = context->GetIsolate(); 13053 v8::Isolate* isolate = context->GetIsolate();
13045 13054
13046 v8::Persistent<v8::Object> handle1, handle2; 13055 v8::Persistent<v8::Object> handle1, handle2;
13047 { 13056 {
13048 v8::HandleScope scope(isolate); 13057 v8::HandleScope scope(isolate);
13049 some_object.Reset(isolate, v8::Object::New()); 13058 some_object.Reset(isolate, v8::Object::New());
13050 handle1.Reset(isolate, v8::Object::New()); 13059 handle1.Reset(isolate, v8::Object::New());
13051 handle2.Reset(isolate, v8::Object::New()); 13060 handle2.Reset(isolate, v8::Object::New());
13052 } 13061 }
13053 // Note: order is implementation dependent alas: currently 13062 // Note: order is implementation dependent alas: currently
13054 // global handle nodes are processed by PostGarbageCollectionProcessing 13063 // global handle nodes are processed by PostGarbageCollectionProcessing
13055 // in reverse allocation order, so if second allocated handle is deleted, 13064 // in reverse allocation order, so if second allocated handle is deleted,
13056 // weak callback of the first handle would be able to 'reallocate' it. 13065 // weak callback of the first handle would be able to 'reallocate' it.
13057 handle1.MakeWeak<v8::Value, void>(NULL, NewPersistentHandleCallback); 13066 handle1.MakeWeak<v8::Value, void>(NULL, NewPersistentHandleCallback);
13058 handle2.Dispose(); 13067 handle2.Reset();
13059 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 13068 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
13060 } 13069 }
13061 13070
13062 13071
13063 v8::Persistent<v8::Object> to_be_disposed; 13072 v8::Persistent<v8::Object> to_be_disposed;
13064 13073
13065 void DisposeAndForceGcCallback(v8::Isolate* isolate, 13074 void DisposeAndForceGcCallback(v8::Isolate* isolate,
13066 v8::Persistent<v8::Value>* handle, 13075 v8::Persistent<v8::Value>* handle,
13067 void*) { 13076 void*) {
13068 to_be_disposed.Dispose(); 13077 to_be_disposed.Reset();
13069 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 13078 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
13070 handle->Dispose(); 13079 handle->Reset();
13071 } 13080 }
13072 13081
13073 13082
13074 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) { 13083 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) {
13075 LocalContext context; 13084 LocalContext context;
13076 v8::Isolate* isolate = context->GetIsolate(); 13085 v8::Isolate* isolate = context->GetIsolate();
13077 13086
13078 v8::Persistent<v8::Object> handle1, handle2; 13087 v8::Persistent<v8::Object> handle1, handle2;
13079 { 13088 {
13080 v8::HandleScope scope(isolate); 13089 v8::HandleScope scope(isolate);
13081 handle1.Reset(isolate, v8::Object::New()); 13090 handle1.Reset(isolate, v8::Object::New());
13082 handle2.Reset(isolate, v8::Object::New()); 13091 handle2.Reset(isolate, v8::Object::New());
13083 } 13092 }
13084 handle1.MakeWeak<v8::Value, void>(NULL, DisposeAndForceGcCallback); 13093 handle1.MakeWeak<v8::Value, void>(NULL, DisposeAndForceGcCallback);
13085 to_be_disposed.Reset(isolate, handle2); 13094 to_be_disposed.Reset(isolate, handle2);
13086 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 13095 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
13087 } 13096 }
13088 13097
13089 void DisposingCallback(v8::Isolate* isolate, 13098 void DisposingCallback(v8::Isolate* isolate,
13090 v8::Persistent<v8::Value>* handle, 13099 v8::Persistent<v8::Value>* handle,
13091 void*) { 13100 void*) {
13092 handle->Dispose(); 13101 handle->Reset();
13093 } 13102 }
13094 13103
13095 void HandleCreatingCallback(v8::Isolate* isolate, 13104 void HandleCreatingCallback(v8::Isolate* isolate,
13096 v8::Persistent<v8::Value>* handle, 13105 v8::Persistent<v8::Value>* handle,
13097 void*) { 13106 void*) {
13098 v8::HandleScope scope(isolate); 13107 v8::HandleScope scope(isolate);
13099 v8::Persistent<v8::Object>(isolate, v8::Object::New()); 13108 v8::Persistent<v8::Object>(isolate, v8::Object::New());
13100 handle->Dispose(); 13109 handle->Reset();
13101 } 13110 }
13102 13111
13103 13112
13104 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) { 13113 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) {
13105 LocalContext context; 13114 LocalContext context;
13106 v8::Isolate* isolate = context->GetIsolate(); 13115 v8::Isolate* isolate = context->GetIsolate();
13107 13116
13108 v8::Persistent<v8::Object> handle1, handle2, handle3; 13117 v8::Persistent<v8::Object> handle1, handle2, handle3;
13109 { 13118 {
13110 v8::HandleScope scope(isolate); 13119 v8::HandleScope scope(isolate);
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
13741 CHECK_LT(0, code.occupancy()); 13750 CHECK_LT(0, code.occupancy());
13742 13751
13743 code_map = NULL; 13752 code_map = NULL;
13744 } 13753 }
13745 13754
13746 isolate->Exit(); 13755 isolate->Exit();
13747 isolate->Dispose(); 13756 isolate->Dispose();
13748 } 13757 }
13749 13758
13750 13759
13751 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); }
13752
13753
13754 THREADED_TEST(ExternalAllocatedMemory) { 13760 THREADED_TEST(ExternalAllocatedMemory) {
13755 v8::Isolate* isolate = CcTest::isolate(); 13761 v8::Isolate* isolate = CcTest::isolate();
13756 v8::HandleScope outer(isolate); 13762 v8::HandleScope outer(isolate);
13757 v8::Local<Context> env(Context::New(isolate)); 13763 v8::Local<Context> env(Context::New(isolate));
13758 CHECK(!env.IsEmpty()); 13764 CHECK(!env.IsEmpty());
13759 const intptr_t kSize = 1024*1024; 13765 const int64_t kSize = 1024*1024;
13760 int64_t baseline = cast(isolate->AdjustAmountOfExternalAllocatedMemory(0)); 13766 int64_t baseline = isolate->AdjustAmountOfExternalAllocatedMemory(0);
13761 CHECK_EQ(baseline + cast(kSize), 13767 CHECK_EQ(baseline + kSize,
13762 cast(isolate->AdjustAmountOfExternalAllocatedMemory(kSize))); 13768 isolate->AdjustAmountOfExternalAllocatedMemory(kSize));
13763 CHECK_EQ(baseline, 13769 CHECK_EQ(baseline,
13764 cast(isolate->AdjustAmountOfExternalAllocatedMemory(-kSize))); 13770 isolate->AdjustAmountOfExternalAllocatedMemory(-kSize));
13765 } 13771 }
13766 13772
13767 13773
13768 // Regression test for issue 54, object templates with internal fields 13774 // Regression test for issue 54, object templates with internal fields
13769 // but no accessors or interceptors did not get their internal field 13775 // but no accessors or interceptors did not get their internal field
13770 // count set on instances. 13776 // count set on instances.
13771 THREADED_TEST(Regress54) { 13777 THREADED_TEST(Regress54) {
13772 LocalContext context; 13778 LocalContext context;
13773 v8::Isolate* isolate = context->GetIsolate(); 13779 v8::Isolate* isolate = context->GetIsolate();
13774 v8::HandleScope outer(isolate); 13780 v8::HandleScope outer(isolate);
13775 static v8::Persistent<v8::ObjectTemplate> templ; 13781 static v8::Persistent<v8::ObjectTemplate> templ;
13776 if (templ.IsEmpty()) { 13782 if (templ.IsEmpty()) {
13777 v8::HandleScope inner(isolate); 13783 v8::HandleScope inner(isolate);
13778 v8::Handle<v8::ObjectTemplate> local = v8::ObjectTemplate::New(); 13784 v8::Handle<v8::ObjectTemplate> local = v8::ObjectTemplate::New();
13779 local->SetInternalFieldCount(1); 13785 local->SetInternalFieldCount(1);
13780 templ.Reset(isolate, inner.Close(local)); 13786 templ.Reset(isolate, inner.Close(local));
13781 } 13787 }
13782 v8::Handle<v8::Object> result = 13788 v8::Handle<v8::Object> result =
13783 v8::Local<v8::ObjectTemplate>::New(isolate, templ)->NewInstance(); 13789 v8::Local<v8::ObjectTemplate>::New(isolate, templ)->NewInstance();
13784 CHECK_EQ(1, result->InternalFieldCount()); 13790 CHECK_EQ(1, result->InternalFieldCount());
13785 } 13791 }
13786 13792
13787 13793
13788 // If part of the threaded tests, this test makes ThreadingTest fail 13794 // If part of the threaded tests, this test makes ThreadingTest fail
13789 // on mac. 13795 // on mac.
13790 TEST(CatchStackOverflow) { 13796 TEST(CatchStackOverflow) {
13791 LocalContext context; 13797 LocalContext context;
13792 v8::HandleScope scope(context->GetIsolate()); 13798 v8::HandleScope scope(context->GetIsolate());
13793 v8::TryCatch try_catch; 13799 v8::TryCatch try_catch;
13794 v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New( 13800 v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::NewFromUtf8(
13801 context->GetIsolate(),
13795 "function f() {" 13802 "function f() {"
13796 " return f();" 13803 " return f();"
13797 "}" 13804 "}"
13798 "" 13805 ""
13799 "f();")); 13806 "f();"));
13800 v8::Handle<v8::Value> result = script->Run(); 13807 v8::Handle<v8::Value> result = script->Run();
13801 CHECK(result.IsEmpty()); 13808 CHECK(result.IsEmpty());
13802 } 13809 }
13803 13810
13804 13811
(...skipping 15 matching lines...) Expand all
13820 v8::String::Utf8Value line(message->GetSourceLine()); 13827 v8::String::Utf8Value line(message->GetSourceLine());
13821 CHECK_EQ(" throw 'nirk';", *line); 13828 CHECK_EQ(" throw 'nirk';", *line);
13822 v8::String::Utf8Value name(message->GetScriptResourceName()); 13829 v8::String::Utf8Value name(message->GetScriptResourceName());
13823 CHECK_EQ(resource_name, *name); 13830 CHECK_EQ(resource_name, *name);
13824 } 13831 }
13825 13832
13826 13833
13827 THREADED_TEST(TryCatchSourceInfo) { 13834 THREADED_TEST(TryCatchSourceInfo) {
13828 LocalContext context; 13835 LocalContext context;
13829 v8::HandleScope scope(context->GetIsolate()); 13836 v8::HandleScope scope(context->GetIsolate());
13830 v8::Handle<v8::String> source = v8::String::New( 13837 v8::Handle<v8::String> source = v8::String::NewFromUtf8(
13838 context->GetIsolate(),
13831 "function Foo() {\n" 13839 "function Foo() {\n"
13832 " return Bar();\n" 13840 " return Bar();\n"
13833 "}\n" 13841 "}\n"
13834 "\n" 13842 "\n"
13835 "function Bar() {\n" 13843 "function Bar() {\n"
13836 " return Baz();\n" 13844 " return Baz();\n"
13837 "}\n" 13845 "}\n"
13838 "\n" 13846 "\n"
13839 "function Baz() {\n" 13847 "function Baz() {\n"
13840 " throw 'nirk';\n" 13848 " throw 'nirk';\n"
13841 "}\n" 13849 "}\n"
13842 "\n" 13850 "\n"
13843 "Foo();\n"); 13851 "Foo();\n");
13844 13852
13845 const char* resource_name; 13853 const char* resource_name;
13846 v8::Handle<v8::Script> script; 13854 v8::Handle<v8::Script> script;
13847 resource_name = "test.js"; 13855 resource_name = "test.js";
13848 script = v8::Script::Compile(source, v8::String::New(resource_name)); 13856 script = v8::Script::Compile(
13857 source, v8::String::NewFromUtf8(context->GetIsolate(), resource_name));
13849 CheckTryCatchSourceInfo(script, resource_name, 0); 13858 CheckTryCatchSourceInfo(script, resource_name, 0);
13850 13859
13851 resource_name = "test1.js"; 13860 resource_name = "test1.js";
13852 v8::ScriptOrigin origin1(v8::String::New(resource_name)); 13861 v8::ScriptOrigin origin1(
13862 v8::String::NewFromUtf8(context->GetIsolate(), resource_name));
13853 script = v8::Script::Compile(source, &origin1); 13863 script = v8::Script::Compile(source, &origin1);
13854 CheckTryCatchSourceInfo(script, resource_name, 0); 13864 CheckTryCatchSourceInfo(script, resource_name, 0);
13855 13865
13856 resource_name = "test2.js"; 13866 resource_name = "test2.js";
13857 v8::ScriptOrigin origin2(v8::String::New(resource_name), v8::Integer::New(7)); 13867 v8::ScriptOrigin origin2(
13868 v8::String::NewFromUtf8(context->GetIsolate(), resource_name),
13869 v8::Integer::New(7));
13858 script = v8::Script::Compile(source, &origin2); 13870 script = v8::Script::Compile(source, &origin2);
13859 CheckTryCatchSourceInfo(script, resource_name, 7); 13871 CheckTryCatchSourceInfo(script, resource_name, 7);
13860 } 13872 }
13861 13873
13862 13874
13863 THREADED_TEST(CompilationCache) { 13875 THREADED_TEST(CompilationCache) {
13864 LocalContext context; 13876 LocalContext context;
13865 v8::HandleScope scope(context->GetIsolate()); 13877 v8::HandleScope scope(context->GetIsolate());
13866 v8::Handle<v8::String> source0 = v8::String::New("1234"); 13878 v8::Handle<v8::String> source0 =
13867 v8::Handle<v8::String> source1 = v8::String::New("1234"); 13879 v8::String::NewFromUtf8(context->GetIsolate(), "1234");
13868 v8::Handle<v8::Script> script0 = 13880 v8::Handle<v8::String> source1 =
13869 v8::Script::Compile(source0, v8::String::New("test.js")); 13881 v8::String::NewFromUtf8(context->GetIsolate(), "1234");
13870 v8::Handle<v8::Script> script1 = 13882 v8::Handle<v8::Script> script0 = v8::Script::Compile(
13871 v8::Script::Compile(source1, v8::String::New("test.js")); 13883 source0, v8::String::NewFromUtf8(context->GetIsolate(), "test.js"));
13884 v8::Handle<v8::Script> script1 = v8::Script::Compile(
13885 source1, v8::String::NewFromUtf8(context->GetIsolate(), "test.js"));
13872 v8::Handle<v8::Script> script2 = 13886 v8::Handle<v8::Script> script2 =
13873 v8::Script::Compile(source0); // different origin 13887 v8::Script::Compile(source0); // different origin
13874 CHECK_EQ(1234, script0->Run()->Int32Value()); 13888 CHECK_EQ(1234, script0->Run()->Int32Value());
13875 CHECK_EQ(1234, script1->Run()->Int32Value()); 13889 CHECK_EQ(1234, script1->Run()->Int32Value());
13876 CHECK_EQ(1234, script2->Run()->Int32Value()); 13890 CHECK_EQ(1234, script2->Run()->Int32Value());
13877 } 13891 }
13878 13892
13879 13893
13880 static void FunctionNameCallback( 13894 static void FunctionNameCallback(
13881 const v8::FunctionCallbackInfo<v8::Value>& args) { 13895 const v8::FunctionCallbackInfo<v8::Value>& args) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
13926 for (int i = 0; i < elmc; i++) { 13940 for (int i = 0; i < elmc; i++) {
13927 v8::String::Utf8Value elm(props->Get(v8::Integer::New(i))); 13941 v8::String::Utf8Value elm(props->Get(v8::Integer::New(i)));
13928 CHECK_EQ(elmv[i], *elm); 13942 CHECK_EQ(elmv[i], *elm);
13929 } 13943 }
13930 } 13944 }
13931 13945
13932 13946
13933 THREADED_TEST(PropertyEnumeration) { 13947 THREADED_TEST(PropertyEnumeration) {
13934 LocalContext context; 13948 LocalContext context;
13935 v8::HandleScope scope(context->GetIsolate()); 13949 v8::HandleScope scope(context->GetIsolate());
13936 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::New( 13950 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::NewFromUtf8(
13951 context->GetIsolate(),
13937 "var result = [];" 13952 "var result = [];"
13938 "result[0] = {};" 13953 "result[0] = {};"
13939 "result[1] = {a: 1, b: 2};" 13954 "result[1] = {a: 1, b: 2};"
13940 "result[2] = [1, 2, 3];" 13955 "result[2] = [1, 2, 3];"
13941 "var proto = {x: 1, y: 2, z: 3};" 13956 "var proto = {x: 1, y: 2, z: 3};"
13942 "var x = { __proto__: proto, w: 0, z: 1 };" 13957 "var x = { __proto__: proto, w: 0, z: 1 };"
13943 "result[3] = x;" 13958 "result[3] = x;"
13944 "result;"))->Run(); 13959 "result;"))->Run();
13945 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); 13960 v8::Handle<v8::Array> elms = obj.As<v8::Array>();
13946 CHECK_EQ(4, elms->Length()); 13961 CHECK_EQ(4, elms->Length());
(...skipping 14 matching lines...) Expand all
13961 CheckProperties(elms->Get(v8::Integer::New(3)), elmc3, elmv3); 13976 CheckProperties(elms->Get(v8::Integer::New(3)), elmc3, elmv3);
13962 int elmc4 = 2; 13977 int elmc4 = 2;
13963 const char* elmv4[] = {"w", "z"}; 13978 const char* elmv4[] = {"w", "z"};
13964 CheckOwnProperties(elms->Get(v8::Integer::New(3)), elmc4, elmv4); 13979 CheckOwnProperties(elms->Get(v8::Integer::New(3)), elmc4, elmv4);
13965 } 13980 }
13966 13981
13967 13982
13968 THREADED_TEST(PropertyEnumeration2) { 13983 THREADED_TEST(PropertyEnumeration2) {
13969 LocalContext context; 13984 LocalContext context;
13970 v8::HandleScope scope(context->GetIsolate()); 13985 v8::HandleScope scope(context->GetIsolate());
13971 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::New( 13986 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::NewFromUtf8(
13987 context->GetIsolate(),
13972 "var result = [];" 13988 "var result = [];"
13973 "result[0] = {};" 13989 "result[0] = {};"
13974 "result[1] = {a: 1, b: 2};" 13990 "result[1] = {a: 1, b: 2};"
13975 "result[2] = [1, 2, 3];" 13991 "result[2] = [1, 2, 3];"
13976 "var proto = {x: 1, y: 2, z: 3};" 13992 "var proto = {x: 1, y: 2, z: 3};"
13977 "var x = { __proto__: proto, w: 0, z: 1 };" 13993 "var x = { __proto__: proto, w: 0, z: 1 };"
13978 "result[3] = x;" 13994 "result[3] = x;"
13979 "result;"))->Run(); 13995 "result;"))->Run();
13980 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); 13996 v8::Handle<v8::Array> elms = obj.As<v8::Array>();
13981 CHECK_EQ(4, elms->Length()); 13997 CHECK_EQ(4, elms->Length());
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
14361 const int kFunctionEntrySize = i::FunctionEntry::kSize; 14377 const int kFunctionEntrySize = i::FunctionEntry::kSize;
14362 const int kFunctionEntryStartOffset = 0; 14378 const int kFunctionEntryStartOffset = 0;
14363 const int kFunctionEntryEndOffset = 1; 14379 const int kFunctionEntryEndOffset = 1;
14364 unsigned* sd_data = 14380 unsigned* sd_data =
14365 reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); 14381 reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data()));
14366 14382
14367 // Overwrite function bar's end position with 0. 14383 // Overwrite function bar's end position with 0.
14368 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryEndOffset] = 0; 14384 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryEndOffset] = 0;
14369 v8::TryCatch try_catch; 14385 v8::TryCatch try_catch;
14370 14386
14371 Local<String> source = String::New(script); 14387 Local<String> source = String::NewFromUtf8(isolate, script);
14372 Local<Script> compiled_script = Script::New(source, NULL, sd); 14388 Local<Script> compiled_script = Script::New(source, NULL, sd);
14373 CHECK(try_catch.HasCaught()); 14389 CHECK(try_catch.HasCaught());
14374 String::Utf8Value exception_value(try_catch.Message()->Get()); 14390 String::Utf8Value exception_value(try_catch.Message()->Get());
14375 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar", 14391 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar",
14376 *exception_value); 14392 *exception_value);
14377 14393
14378 try_catch.Reset(); 14394 try_catch.Reset();
14379 14395
14380 // Overwrite function bar's start position with 200. The function entry 14396 // Overwrite function bar's start position with 200. The function entry
14381 // will not be found when searching for it by position and we should fall 14397 // will not be found when searching for it by position and we should fall
(...skipping 19 matching lines...) Expand all
14401 const char* cstring = "function foo(a) { return a+1; }"; 14417 const char* cstring = "function foo(a) { return a+1; }";
14402 14418
14403 v8::ScriptData* sd_from_cstring = 14419 v8::ScriptData* sd_from_cstring =
14404 v8::ScriptData::PreCompile(isolate, cstring, i::StrLength(cstring)); 14420 v8::ScriptData::PreCompile(isolate, cstring, i::StrLength(cstring));
14405 14421
14406 TestAsciiResource* resource = new TestAsciiResource(cstring); 14422 TestAsciiResource* resource = new TestAsciiResource(cstring);
14407 v8::ScriptData* sd_from_external_string = v8::ScriptData::PreCompile( 14423 v8::ScriptData* sd_from_external_string = v8::ScriptData::PreCompile(
14408 v8::String::NewExternal(resource)); 14424 v8::String::NewExternal(resource));
14409 14425
14410 v8::ScriptData* sd_from_string = v8::ScriptData::PreCompile( 14426 v8::ScriptData* sd_from_string = v8::ScriptData::PreCompile(
14411 v8::String::New(cstring)); 14427 v8::String::NewFromUtf8(isolate, cstring));
14412 14428
14413 CHECK_EQ(sd_from_cstring->Length(), sd_from_external_string->Length()); 14429 CHECK_EQ(sd_from_cstring->Length(), sd_from_external_string->Length());
14414 CHECK_EQ(0, memcmp(sd_from_cstring->Data(), 14430 CHECK_EQ(0, memcmp(sd_from_cstring->Data(),
14415 sd_from_external_string->Data(), 14431 sd_from_external_string->Data(),
14416 sd_from_cstring->Length())); 14432 sd_from_cstring->Length()));
14417 14433
14418 CHECK_EQ(sd_from_cstring->Length(), sd_from_string->Length()); 14434 CHECK_EQ(sd_from_cstring->Length(), sd_from_string->Length());
14419 CHECK_EQ(0, memcmp(sd_from_cstring->Data(), 14435 CHECK_EQ(0, memcmp(sd_from_cstring->Data(),
14420 sd_from_string->Data(), 14436 sd_from_string->Data(),
14421 sd_from_cstring->Length())); 14437 sd_from_cstring->Length()));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
14474 // result has the 'x' property. 14490 // result has the 'x' property.
14475 context1->Enter(); 14491 context1->Enter();
14476 context1->Global()->Set(v8_str("other"), context0->Global()); 14492 context1->Global()->Set(v8_str("other"), context0->Global());
14477 Local<Value> value = CompileRun("var instance = new other.C(); instance.x"); 14493 Local<Value> value = CompileRun("var instance = new other.C(); instance.x");
14478 CHECK(value->IsInt32()); 14494 CHECK(value->IsInt32());
14479 CHECK_EQ(42, value->Int32Value()); 14495 CHECK_EQ(42, value->Int32Value());
14480 context1->Exit(); 14496 context1->Exit();
14481 } 14497 }
14482 14498
14483 14499
14484 class ApplyInterruptTest {
14485 public:
14486 ApplyInterruptTest() : block_(0) {}
14487 ~ApplyInterruptTest() {}
14488 void RunTest() {
14489 gc_count_ = 0;
14490 gc_during_apply_ = 0;
14491 apply_success_ = false;
14492 gc_success_ = false;
14493 GCThread gc_thread(this);
14494 gc_thread.Start();
14495 v8::Isolate* isolate = CcTest::isolate();
14496 v8::Locker::StartPreemption(isolate, 1);
14497
14498 LongRunningApply();
14499 {
14500 v8::Unlocker unlock(isolate);
14501 gc_thread.Join();
14502 }
14503 v8::Locker::StopPreemption(isolate);
14504 CHECK(apply_success_);
14505 CHECK(gc_success_);
14506 }
14507
14508 private:
14509 // Number of garbage collections required.
14510 static const int kRequiredGCs = 2;
14511
14512 class GCThread : public i::Thread {
14513 public:
14514 explicit GCThread(ApplyInterruptTest* test)
14515 : Thread("GCThread"), test_(test) {}
14516 virtual void Run() {
14517 test_->CollectGarbage();
14518 }
14519 private:
14520 ApplyInterruptTest* test_;
14521 };
14522
14523 void CollectGarbage() {
14524 block_.Wait();
14525 while (gc_during_apply_ < kRequiredGCs) {
14526 {
14527 v8::Locker lock(CcTest::isolate());
14528 v8::Isolate::Scope isolate_scope(CcTest::isolate());
14529 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
14530 gc_count_++;
14531 }
14532 i::OS::Sleep(1);
14533 }
14534 gc_success_ = true;
14535 }
14536
14537 void LongRunningApply() {
14538 block_.Signal();
14539 int rounds = 0;
14540 while (gc_during_apply_ < kRequiredGCs) {
14541 int gc_before = gc_count_;
14542 {
14543 const char* c_source =
14544 "function do_very_little(bar) {"
14545 " this.foo = bar;"
14546 "}"
14547 "for (var i = 0; i < 100000; i++) {"
14548 " do_very_little.apply(this, ['bar']);"
14549 "}";
14550 Local<String> source = String::New(c_source);
14551 Local<Script> script = Script::Compile(source);
14552 Local<Value> result = script->Run();
14553 // Check that no exception was thrown.
14554 CHECK(!result.IsEmpty());
14555 }
14556 int gc_after = gc_count_;
14557 gc_during_apply_ += gc_after - gc_before;
14558 rounds++;
14559 }
14560 apply_success_ = true;
14561 }
14562
14563 i::Semaphore block_;
14564 int gc_count_;
14565 int gc_during_apply_;
14566 bool apply_success_;
14567 bool gc_success_;
14568 };
14569
14570
14571 // Test that nothing bad happens if we get a preemption just when we were
14572 // about to do an apply().
14573 TEST(ApplyInterruption) {
14574 v8::Locker lock(CcTest::isolate());
14575 v8::V8::Initialize();
14576 v8::HandleScope scope(CcTest::isolate());
14577 Local<Context> local_env;
14578 {
14579 LocalContext env;
14580 local_env = env.local();
14581 }
14582
14583 // Local context should still be live.
14584 CHECK(!local_env.IsEmpty());
14585 local_env->Enter();
14586
14587 // Should complete without problems.
14588 ApplyInterruptTest().RunTest();
14589
14590 local_env->Exit();
14591 }
14592
14593
14594 // Verify that we can clone an object 14500 // Verify that we can clone an object
14595 TEST(ObjectClone) { 14501 TEST(ObjectClone) {
14596 LocalContext env; 14502 LocalContext env;
14597 v8::HandleScope scope(env->GetIsolate()); 14503 v8::HandleScope scope(env->GetIsolate());
14598 14504
14599 const char* sample = 14505 const char* sample =
14600 "var rv = {};" \ 14506 "var rv = {};" \
14601 "rv.alpha = 'hello';" \ 14507 "rv.alpha = 'hello';" \
14602 "rv.beta = 123;" \ 14508 "rv.beta = 123;" \
14603 "rv;"; 14509 "rv;";
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
14726 "/[^a-z]/.test(slice);" 14632 "/[^a-z]/.test(slice);"
14727 "/[^a-z]/.test(slice_on_cons);"); 14633 "/[^a-z]/.test(slice_on_cons);");
14728 const char* expected_cons = 14634 const char* expected_cons =
14729 "Now is the time for all good men to come to the aid of the party" 14635 "Now is the time for all good men to come to the aid of the party"
14730 "Now is the time for all good men to come to the aid of the party"; 14636 "Now is the time for all good men to come to the aid of the party";
14731 const char* expected_slice = 14637 const char* expected_slice =
14732 "ow is the time for all good men to come to the aid of the part"; 14638 "ow is the time for all good men to come to the aid of the part";
14733 const char* expected_slice_on_cons = 14639 const char* expected_slice_on_cons =
14734 "ow is the time for all good men to come to the aid of the party" 14640 "ow is the time for all good men to come to the aid of the party"
14735 "Now is the time for all good men to come to the aid of the part"; 14641 "Now is the time for all good men to come to the aid of the part";
14736 CHECK_EQ(String::New(expected_cons), 14642 CHECK_EQ(String::NewFromUtf8(env->GetIsolate(), expected_cons),
14737 env->Global()->Get(v8_str("cons"))); 14643 env->Global()->Get(v8_str("cons")));
14738 CHECK_EQ(String::New(expected_slice), 14644 CHECK_EQ(String::NewFromUtf8(env->GetIsolate(), expected_slice),
14739 env->Global()->Get(v8_str("slice"))); 14645 env->Global()->Get(v8_str("slice")));
14740 CHECK_EQ(String::New(expected_slice_on_cons), 14646 CHECK_EQ(String::NewFromUtf8(env->GetIsolate(), expected_slice_on_cons),
14741 env->Global()->Get(v8_str("slice_on_cons"))); 14647 env->Global()->Get(v8_str("slice_on_cons")));
14742 } 14648 }
14743 i::DeleteArray(two_byte_string); 14649 i::DeleteArray(two_byte_string);
14744 } 14650 }
14745 14651
14746 14652
14747 TEST(CompileExternalTwoByteSource) { 14653 TEST(CompileExternalTwoByteSource) {
14748 LocalContext context; 14654 LocalContext context;
14749 v8::HandleScope scope(context->GetIsolate()); 14655 v8::HandleScope scope(context->GetIsolate());
14750 14656
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
14831 14737
14832 v8::TryCatch try_catch; 14738 v8::TryCatch try_catch;
14833 timeout_thread.Start(); 14739 timeout_thread.Start();
14834 14740
14835 CompileRun("/((a*)*)*b/.exec(a)"); 14741 CompileRun("/((a*)*)*b/.exec(a)");
14836 CHECK(try_catch.HasTerminated()); 14742 CHECK(try_catch.HasTerminated());
14837 14743
14838 timeout_thread.Join(); 14744 timeout_thread.Join();
14839 14745
14840 delete regexp_interruption_data.string_resource; 14746 delete regexp_interruption_data.string_resource;
14841 regexp_interruption_data.string.Dispose(); 14747 regexp_interruption_data.string.Reset();
14842 } 14748 }
14843 14749
14844 #endif // V8_INTERPRETED_REGEXP 14750 #endif // V8_INTERPRETED_REGEXP
14845 14751
14846 14752
14847 // Test that we cannot set a property on the global object if there 14753 // Test that we cannot set a property on the global object if there
14848 // is a read-only property in the prototype chain. 14754 // is a read-only property in the prototype chain.
14849 TEST(ReadOnlyPropertyInGlobalProto) { 14755 TEST(ReadOnlyPropertyInGlobalProto) {
14850 i::FLAG_es5_readonly = true; 14756 i::FLAG_es5_readonly = true;
14851 v8::HandleScope scope(CcTest::isolate()); 14757 v8::HandleScope scope(CcTest::isolate());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
14896 } 14802 }
14897 14803
14898 14804
14899 TEST(ForceSet) { 14805 TEST(ForceSet) {
14900 force_set_get_count = 0; 14806 force_set_get_count = 0;
14901 force_set_set_count = 0; 14807 force_set_set_count = 0;
14902 pass_on_get = false; 14808 pass_on_get = false;
14903 14809
14904 v8::HandleScope scope(CcTest::isolate()); 14810 v8::HandleScope scope(CcTest::isolate());
14905 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 14811 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
14906 v8::Handle<v8::String> access_property = v8::String::New("a"); 14812 v8::Handle<v8::String> access_property =
14813 v8::String::NewFromUtf8(CcTest::isolate(), "a");
14907 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter); 14814 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter);
14908 LocalContext context(NULL, templ); 14815 LocalContext context(NULL, templ);
14909 v8::Handle<v8::Object> global = context->Global(); 14816 v8::Handle<v8::Object> global = context->Global();
14910 14817
14911 // Ordinary properties 14818 // Ordinary properties
14912 v8::Handle<v8::String> simple_property = v8::String::New("p"); 14819 v8::Handle<v8::String> simple_property =
14820 v8::String::NewFromUtf8(CcTest::isolate(), "p");
14913 global->Set(simple_property, v8::Int32::New(4), v8::ReadOnly); 14821 global->Set(simple_property, v8::Int32::New(4), v8::ReadOnly);
14914 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 14822 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
14915 // This should fail because the property is read-only 14823 // This should fail because the property is read-only
14916 global->Set(simple_property, v8::Int32::New(5)); 14824 global->Set(simple_property, v8::Int32::New(5));
14917 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 14825 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
14918 // This should succeed even though the property is read-only 14826 // This should succeed even though the property is read-only
14919 global->ForceSet(simple_property, v8::Int32::New(6)); 14827 global->ForceSet(simple_property, v8::Int32::New(6));
14920 CHECK_EQ(6, global->Get(simple_property)->Int32Value()); 14828 CHECK_EQ(6, global->Get(simple_property)->Int32Value());
14921 14829
14922 // Accessors 14830 // Accessors
(...skipping 19 matching lines...) Expand all
14942 force_set_get_count = 0; 14850 force_set_get_count = 0;
14943 force_set_set_count = 0; 14851 force_set_set_count = 0;
14944 pass_on_get = false; 14852 pass_on_get = false;
14945 14853
14946 v8::HandleScope scope(CcTest::isolate()); 14854 v8::HandleScope scope(CcTest::isolate());
14947 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 14855 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
14948 templ->SetNamedPropertyHandler(ForceSetGetter, ForceSetInterceptSetter); 14856 templ->SetNamedPropertyHandler(ForceSetGetter, ForceSetInterceptSetter);
14949 LocalContext context(NULL, templ); 14857 LocalContext context(NULL, templ);
14950 v8::Handle<v8::Object> global = context->Global(); 14858 v8::Handle<v8::Object> global = context->Global();
14951 14859
14952 v8::Handle<v8::String> some_property = v8::String::New("a"); 14860 v8::Handle<v8::String> some_property =
14861 v8::String::NewFromUtf8(CcTest::isolate(), "a");
14953 CHECK_EQ(0, force_set_set_count); 14862 CHECK_EQ(0, force_set_set_count);
14954 CHECK_EQ(0, force_set_get_count); 14863 CHECK_EQ(0, force_set_get_count);
14955 CHECK_EQ(3, global->Get(some_property)->Int32Value()); 14864 CHECK_EQ(3, global->Get(some_property)->Int32Value());
14956 // Setting the property shouldn't override it, just call the setter 14865 // Setting the property shouldn't override it, just call the setter
14957 // which in this case does nothing. 14866 // which in this case does nothing.
14958 global->Set(some_property, v8::Int32::New(7)); 14867 global->Set(some_property, v8::Int32::New(7));
14959 CHECK_EQ(3, global->Get(some_property)->Int32Value()); 14868 CHECK_EQ(3, global->Get(some_property)->Int32Value());
14960 CHECK_EQ(1, force_set_set_count); 14869 CHECK_EQ(1, force_set_set_count);
14961 CHECK_EQ(2, force_set_get_count); 14870 CHECK_EQ(2, force_set_get_count);
14962 // Getting the property when the interceptor returns an empty handle 14871 // Getting the property when the interceptor returns an empty handle
14963 // should yield undefined, since the property isn't present on the 14872 // should yield undefined, since the property isn't present on the
14964 // object itself yet. 14873 // object itself yet.
14965 pass_on_get = true; 14874 pass_on_get = true;
14966 CHECK(global->Get(some_property)->IsUndefined()); 14875 CHECK(global->Get(some_property)->IsUndefined());
14967 CHECK_EQ(1, force_set_set_count); 14876 CHECK_EQ(1, force_set_set_count);
14968 CHECK_EQ(3, force_set_get_count); 14877 CHECK_EQ(3, force_set_get_count);
14969 // Forcing the property to be set should cause the value to be 14878 // Forcing the property to be set should cause the value to be
14970 // set locally without calling the interceptor. 14879 // set locally without calling the interceptor.
14971 global->ForceSet(some_property, v8::Int32::New(8)); 14880 global->ForceSet(some_property, v8::Int32::New(8));
14972 CHECK_EQ(8, global->Get(some_property)->Int32Value()); 14881 CHECK_EQ(8, global->Get(some_property)->Int32Value());
14973 CHECK_EQ(1, force_set_set_count); 14882 CHECK_EQ(1, force_set_set_count);
14974 CHECK_EQ(4, force_set_get_count); 14883 CHECK_EQ(4, force_set_get_count);
14975 // Reenabling the interceptor should cause it to take precedence over 14884 // Reenabling the interceptor should cause it to take precedence over
14976 // the property 14885 // the property
14977 pass_on_get = false; 14886 pass_on_get = false;
14978 CHECK_EQ(3, global->Get(some_property)->Int32Value()); 14887 CHECK_EQ(3, global->Get(some_property)->Int32Value());
14979 CHECK_EQ(1, force_set_set_count); 14888 CHECK_EQ(1, force_set_set_count);
14980 CHECK_EQ(5, force_set_get_count); 14889 CHECK_EQ(5, force_set_get_count);
14981 // The interceptor should also work for other properties 14890 // The interceptor should also work for other properties
14982 CHECK_EQ(3, global->Get(v8::String::New("b"))->Int32Value()); 14891 CHECK_EQ(3, global->Get(v8::String::NewFromUtf8(CcTest::isolate(), "b"))
14892 ->Int32Value());
14983 CHECK_EQ(1, force_set_set_count); 14893 CHECK_EQ(1, force_set_set_count);
14984 CHECK_EQ(6, force_set_get_count); 14894 CHECK_EQ(6, force_set_get_count);
14985 } 14895 }
14986 14896
14987 14897
14988 THREADED_TEST(ForceDelete) { 14898 THREADED_TEST(ForceDelete) {
14989 v8::HandleScope scope(CcTest::isolate()); 14899 v8::HandleScope scope(CcTest::isolate());
14990 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 14900 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
14991 LocalContext context(NULL, templ); 14901 LocalContext context(NULL, templ);
14992 v8::Handle<v8::Object> global = context->Global(); 14902 v8::Handle<v8::Object> global = context->Global();
14993 14903
14994 // Ordinary properties 14904 // Ordinary properties
14995 v8::Handle<v8::String> simple_property = v8::String::New("p"); 14905 v8::Handle<v8::String> simple_property =
14906 v8::String::NewFromUtf8(CcTest::isolate(), "p");
14996 global->Set(simple_property, v8::Int32::New(4), v8::DontDelete); 14907 global->Set(simple_property, v8::Int32::New(4), v8::DontDelete);
14997 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 14908 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
14998 // This should fail because the property is dont-delete. 14909 // This should fail because the property is dont-delete.
14999 CHECK(!global->Delete(simple_property)); 14910 CHECK(!global->Delete(simple_property));
15000 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 14911 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
15001 // This should succeed even though the property is dont-delete. 14912 // This should succeed even though the property is dont-delete.
15002 CHECK(global->ForceDelete(simple_property)); 14913 CHECK(global->ForceDelete(simple_property));
15003 CHECK(global->Get(simple_property)->IsUndefined()); 14914 CHECK(global->Get(simple_property)->IsUndefined());
15004 } 14915 }
15005 14916
(...skipping 14 matching lines...) Expand all
15020 THREADED_TEST(ForceDeleteWithInterceptor) { 14931 THREADED_TEST(ForceDeleteWithInterceptor) {
15021 force_delete_interceptor_count = 0; 14932 force_delete_interceptor_count = 0;
15022 pass_on_delete = false; 14933 pass_on_delete = false;
15023 14934
15024 v8::HandleScope scope(CcTest::isolate()); 14935 v8::HandleScope scope(CcTest::isolate());
15025 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 14936 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
15026 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter); 14937 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter);
15027 LocalContext context(NULL, templ); 14938 LocalContext context(NULL, templ);
15028 v8::Handle<v8::Object> global = context->Global(); 14939 v8::Handle<v8::Object> global = context->Global();
15029 14940
15030 v8::Handle<v8::String> some_property = v8::String::New("a"); 14941 v8::Handle<v8::String> some_property =
14942 v8::String::NewFromUtf8(CcTest::isolate(), "a");
15031 global->Set(some_property, v8::Integer::New(42), v8::DontDelete); 14943 global->Set(some_property, v8::Integer::New(42), v8::DontDelete);
15032 14944
15033 // Deleting a property should get intercepted and nothing should 14945 // Deleting a property should get intercepted and nothing should
15034 // happen. 14946 // happen.
15035 CHECK_EQ(0, force_delete_interceptor_count); 14947 CHECK_EQ(0, force_delete_interceptor_count);
15036 CHECK(global->Delete(some_property)); 14948 CHECK(global->Delete(some_property));
15037 CHECK_EQ(1, force_delete_interceptor_count); 14949 CHECK_EQ(1, force_delete_interceptor_count);
15038 CHECK_EQ(42, global->Get(some_property)->Int32Value()); 14950 CHECK_EQ(42, global->Get(some_property)->Int32Value());
15039 // Deleting the property when the interceptor returns an empty 14951 // Deleting the property when the interceptor returns an empty
15040 // handle should not delete the property since it is DontDelete. 14952 // handle should not delete the property since it is DontDelete.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
15086 v8::Local<v8::Value> foo = ctx1->Global()->Get(v8_str("foo")); 14998 v8::Local<v8::Value> foo = ctx1->Global()->Get(v8_str("foo"));
15087 ctx2->Enter(); 14999 ctx2->Enter();
15088 ctx2->Global()->Set(v8_str("o"), foo); 15000 ctx2->Global()->Set(v8_str("o"), foo);
15089 v8::Local<v8::Value> res = CompileRun( 15001 v8::Local<v8::Value> res = CompileRun(
15090 "function f() { return o(); }" 15002 "function f() { return o(); }"
15091 "for (var i = 0; i < 10; ++i) f();" 15003 "for (var i = 0; i < 10; ++i) f();"
15092 "%OptimizeFunctionOnNextCall(f);" 15004 "%OptimizeFunctionOnNextCall(f);"
15093 "f();"); 15005 "f();");
15094 CHECK_EQ(42, res->Int32Value()); 15006 CHECK_EQ(42, res->Int32Value());
15095 ctx2->Exit(); 15007 ctx2->Exit();
15096 v8::Handle<v8::String> G_property = v8::String::New("G"); 15008 v8::Handle<v8::String> G_property =
15009 v8::String::NewFromUtf8(CcTest::isolate(), "G");
15097 CHECK(ctx1->Global()->ForceDelete(G_property)); 15010 CHECK(ctx1->Global()->ForceDelete(G_property));
15098 ctx2->Enter(); 15011 ctx2->Enter();
15099 ExpectString( 15012 ExpectString(
15100 "(function() {" 15013 "(function() {"
15101 " try {" 15014 " try {"
15102 " return f();" 15015 " return f();"
15103 " } catch(e) {" 15016 " } catch(e) {"
15104 " return e.toString();" 15017 " return e.toString();"
15105 " }" 15018 " }"
15106 " })()", 15019 " })()",
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
15204 // Regression test for issue 398. 15117 // Regression test for issue 398.
15205 // If a function is added to an object, creating a constant function 15118 // If a function is added to an object, creating a constant function
15206 // field, and the result is cloned, replacing the constant function on the 15119 // field, and the result is cloned, replacing the constant function on the
15207 // original should not affect the clone. 15120 // original should not affect the clone.
15208 // See http://code.google.com/p/v8/issues/detail?id=398 15121 // See http://code.google.com/p/v8/issues/detail?id=398
15209 THREADED_TEST(ReplaceConstantFunction) { 15122 THREADED_TEST(ReplaceConstantFunction) {
15210 LocalContext context; 15123 LocalContext context;
15211 v8::HandleScope scope(context->GetIsolate()); 15124 v8::HandleScope scope(context->GetIsolate());
15212 v8::Handle<v8::Object> obj = v8::Object::New(); 15125 v8::Handle<v8::Object> obj = v8::Object::New();
15213 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New(); 15126 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New();
15214 v8::Handle<v8::String> foo_string = v8::String::New("foo"); 15127 v8::Handle<v8::String> foo_string =
15128 v8::String::NewFromUtf8(context->GetIsolate(), "foo");
15215 obj->Set(foo_string, func_templ->GetFunction()); 15129 obj->Set(foo_string, func_templ->GetFunction());
15216 v8::Handle<v8::Object> obj_clone = obj->Clone(); 15130 v8::Handle<v8::Object> obj_clone = obj->Clone();
15217 obj_clone->Set(foo_string, v8::String::New("Hello")); 15131 obj_clone->Set(foo_string,
15132 v8::String::NewFromUtf8(context->GetIsolate(), "Hello"));
15218 CHECK(!obj->Get(foo_string)->IsUndefined()); 15133 CHECK(!obj->Get(foo_string)->IsUndefined());
15219 } 15134 }
15220 15135
15221 15136
15222 // Regression test for http://crbug.com/16276. 15137 // Regression test for http://crbug.com/16276.
15223 THREADED_TEST(Regress16276) { 15138 THREADED_TEST(Regress16276) {
15224 LocalContext context; 15139 LocalContext context;
15225 v8::HandleScope scope(context->GetIsolate()); 15140 v8::HandleScope scope(context->GetIsolate());
15226 // Force the IC in f to be a dictionary load IC. 15141 // Force the IC in f to be a dictionary load IC.
15227 CompileRun("function f(obj) { return obj.x; }\n" 15142 CompileRun("function f(obj) { return obj.x; }\n"
(...skipping 1288 matching lines...) Expand 10 before | Expand all | Expand 10 after
16516 IS_ARRAY_BUFFER_VIEW_TEST(DataView) 16431 IS_ARRAY_BUFFER_VIEW_TEST(DataView)
16517 16432
16518 #undef IS_ARRAY_BUFFER_VIEW_TEST 16433 #undef IS_ARRAY_BUFFER_VIEW_TEST
16519 16434
16520 16435
16521 16436
16522 THREADED_TEST(ScriptContextDependence) { 16437 THREADED_TEST(ScriptContextDependence) {
16523 LocalContext c1; 16438 LocalContext c1;
16524 v8::HandleScope scope(c1->GetIsolate()); 16439 v8::HandleScope scope(c1->GetIsolate());
16525 const char *source = "foo"; 16440 const char *source = "foo";
16526 v8::Handle<v8::Script> dep = v8::Script::Compile(v8::String::New(source)); 16441 v8::Handle<v8::Script> dep =
16527 v8::Handle<v8::Script> indep = v8::Script::New(v8::String::New(source)); 16442 v8::Script::Compile(v8::String::NewFromUtf8(c1->GetIsolate(), source));
16528 c1->Global()->Set(v8::String::New("foo"), v8::Integer::New(100)); 16443 v8::Handle<v8::Script> indep =
16444 v8::Script::New(v8::String::NewFromUtf8(c1->GetIsolate(), source));
16445 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"),
16446 v8::Integer::New(100));
16529 CHECK_EQ(dep->Run()->Int32Value(), 100); 16447 CHECK_EQ(dep->Run()->Int32Value(), 100);
16530 CHECK_EQ(indep->Run()->Int32Value(), 100); 16448 CHECK_EQ(indep->Run()->Int32Value(), 100);
16531 LocalContext c2; 16449 LocalContext c2;
16532 c2->Global()->Set(v8::String::New("foo"), v8::Integer::New(101)); 16450 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"),
16451 v8::Integer::New(101));
16533 CHECK_EQ(dep->Run()->Int32Value(), 100); 16452 CHECK_EQ(dep->Run()->Int32Value(), 100);
16534 CHECK_EQ(indep->Run()->Int32Value(), 101); 16453 CHECK_EQ(indep->Run()->Int32Value(), 101);
16535 } 16454 }
16536 16455
16537 16456
16538 THREADED_TEST(StackTrace) { 16457 THREADED_TEST(StackTrace) {
16539 LocalContext context; 16458 LocalContext context;
16540 v8::HandleScope scope(context->GetIsolate()); 16459 v8::HandleScope scope(context->GetIsolate());
16541 v8::TryCatch try_catch; 16460 v8::TryCatch try_catch;
16542 const char *source = "function foo() { FAIL.FAIL; }; foo();"; 16461 const char *source = "function foo() { FAIL.FAIL; }; foo();";
16543 v8::Handle<v8::String> src = v8::String::New(source); 16462 v8::Handle<v8::String> src =
16544 v8::Handle<v8::String> origin = v8::String::New("stack-trace-test"); 16463 v8::String::NewFromUtf8(context->GetIsolate(), source);
16464 v8::Handle<v8::String> origin =
16465 v8::String::NewFromUtf8(context->GetIsolate(), "stack-trace-test");
16545 v8::Script::New(src, origin)->Run(); 16466 v8::Script::New(src, origin)->Run();
16546 CHECK(try_catch.HasCaught()); 16467 CHECK(try_catch.HasCaught());
16547 v8::String::Utf8Value stack(try_catch.StackTrace()); 16468 v8::String::Utf8Value stack(try_catch.StackTrace());
16548 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); 16469 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL);
16549 } 16470 }
16550 16471
16551 16472
16552 // Checks that a StackFrame has certain expected values. 16473 // Checks that a StackFrame has certain expected values.
16553 void checkStackFrame(const char* expected_script_name, 16474 void checkStackFrame(const char* expected_script_name,
16554 const char* expected_func_name, int expected_line_number, 16475 const char* expected_func_name, int expected_line_number,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
16620 CHECK(stackTrace->AsArray()->IsArray()); 16541 CHECK(stackTrace->AsArray()->IsArray());
16621 } 16542 }
16622 } 16543 }
16623 16544
16624 16545
16625 // Tests the C++ StackTrace API. 16546 // Tests the C++ StackTrace API.
16626 // TODO(3074796): Reenable this as a THREADED_TEST once it passes. 16547 // TODO(3074796): Reenable this as a THREADED_TEST once it passes.
16627 // THREADED_TEST(CaptureStackTrace) { 16548 // THREADED_TEST(CaptureStackTrace) {
16628 TEST(CaptureStackTrace) { 16549 TEST(CaptureStackTrace) {
16629 v8::HandleScope scope(CcTest::isolate()); 16550 v8::HandleScope scope(CcTest::isolate());
16630 v8::Handle<v8::String> origin = v8::String::New("capture-stack-trace-test"); 16551 v8::Handle<v8::String> origin =
16552 v8::String::NewFromUtf8(CcTest::isolate(), "capture-stack-trace-test");
16631 Local<ObjectTemplate> templ = ObjectTemplate::New(); 16553 Local<ObjectTemplate> templ = ObjectTemplate::New();
16632 templ->Set(v8_str("AnalyzeStackInNativeCode"), 16554 templ->Set(v8_str("AnalyzeStackInNativeCode"),
16633 v8::FunctionTemplate::New(AnalyzeStackInNativeCode)); 16555 v8::FunctionTemplate::New(AnalyzeStackInNativeCode));
16634 LocalContext context(0, templ); 16556 LocalContext context(0, templ);
16635 16557
16636 // Test getting OVERVIEW information. Should ignore information that is not 16558 // Test getting OVERVIEW information. Should ignore information that is not
16637 // script name, function name, line number, and column offset. 16559 // script name, function name, line number, and column offset.
16638 const char *overview_source = 16560 const char *overview_source =
16639 "function bar() {\n" 16561 "function bar() {\n"
16640 " var y; AnalyzeStackInNativeCode(1);\n" 16562 " var y; AnalyzeStackInNativeCode(1);\n"
16641 "}\n" 16563 "}\n"
16642 "function foo() {\n" 16564 "function foo() {\n"
16643 "\n" 16565 "\n"
16644 " bar();\n" 16566 " bar();\n"
16645 "}\n" 16567 "}\n"
16646 "var x;eval('new foo();');"; 16568 "var x;eval('new foo();');";
16647 v8::Handle<v8::String> overview_src = v8::String::New(overview_source); 16569 v8::Handle<v8::String> overview_src =
16570 v8::String::NewFromUtf8(CcTest::isolate(), overview_source);
16648 v8::Handle<Value> overview_result( 16571 v8::Handle<Value> overview_result(
16649 v8::Script::New(overview_src, origin)->Run()); 16572 v8::Script::New(overview_src, origin)->Run());
16650 CHECK(!overview_result.IsEmpty()); 16573 CHECK(!overview_result.IsEmpty());
16651 CHECK(overview_result->IsObject()); 16574 CHECK(overview_result->IsObject());
16652 16575
16653 // Test getting DETAILED information. 16576 // Test getting DETAILED information.
16654 const char *detailed_source = 16577 const char *detailed_source =
16655 "function bat() {AnalyzeStackInNativeCode(2);\n" 16578 "function bat() {AnalyzeStackInNativeCode(2);\n"
16656 "}\n" 16579 "}\n"
16657 "\n" 16580 "\n"
16658 "function baz() {\n" 16581 "function baz() {\n"
16659 " bat();\n" 16582 " bat();\n"
16660 "}\n" 16583 "}\n"
16661 "eval('new baz();');"; 16584 "eval('new baz();');";
16662 v8::Handle<v8::String> detailed_src = v8::String::New(detailed_source); 16585 v8::Handle<v8::String> detailed_src =
16586 v8::String::NewFromUtf8(CcTest::isolate(), detailed_source);
16663 // Make the script using a non-zero line and column offset. 16587 // Make the script using a non-zero line and column offset.
16664 v8::Handle<v8::Integer> line_offset = v8::Integer::New(3); 16588 v8::Handle<v8::Integer> line_offset = v8::Integer::New(3);
16665 v8::Handle<v8::Integer> column_offset = v8::Integer::New(5); 16589 v8::Handle<v8::Integer> column_offset = v8::Integer::New(5);
16666 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); 16590 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset);
16667 v8::Handle<v8::Script> detailed_script( 16591 v8::Handle<v8::Script> detailed_script(
16668 v8::Script::New(detailed_src, &detailed_origin)); 16592 v8::Script::New(detailed_src, &detailed_origin));
16669 v8::Handle<Value> detailed_result(detailed_script->Run()); 16593 v8::Handle<Value> detailed_result(detailed_script->Run());
16670 CHECK(!detailed_result.IsEmpty()); 16594 CHECK(!detailed_result.IsEmpty());
16671 CHECK(detailed_result->IsObject()); 16595 CHECK(detailed_result->IsObject());
16672 } 16596 }
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
16916 } 16840 }
16917 16841
16918 16842
16919 TEST(ScriptIdInStackTrace) { 16843 TEST(ScriptIdInStackTrace) {
16920 v8::HandleScope scope(CcTest::isolate()); 16844 v8::HandleScope scope(CcTest::isolate());
16921 Local<ObjectTemplate> templ = ObjectTemplate::New(); 16845 Local<ObjectTemplate> templ = ObjectTemplate::New();
16922 templ->Set(v8_str("AnalyzeScriptIdInStack"), 16846 templ->Set(v8_str("AnalyzeScriptIdInStack"),
16923 v8::FunctionTemplate::New(AnalyzeScriptIdInStack)); 16847 v8::FunctionTemplate::New(AnalyzeScriptIdInStack));
16924 LocalContext context(0, templ); 16848 LocalContext context(0, templ);
16925 16849
16926 v8::Handle<v8::String> scriptSource = v8::String::New( 16850 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8(
16851 CcTest::isolate(),
16927 "function foo() {\n" 16852 "function foo() {\n"
16928 " AnalyzeScriptIdInStack();" 16853 " AnalyzeScriptIdInStack();"
16929 "}\n" 16854 "}\n"
16930 "foo();\n"); 16855 "foo();\n");
16931 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); 16856 v8::ScriptOrigin origin =
16857 v8::ScriptOrigin(v8::String::NewFromUtf8(CcTest::isolate(), "test"));
16932 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin)); 16858 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin));
16933 script->Run(); 16859 script->Run();
16934 for (int i = 0; i < 2; i++) { 16860 for (int i = 0; i < 2; i++) {
16935 CHECK(scriptIdInStack[i] != v8::Message::kNoScriptIdInfo); 16861 CHECK(scriptIdInStack[i] != v8::Message::kNoScriptIdInfo);
16936 CHECK_EQ(scriptIdInStack[i], script->GetId()); 16862 CHECK_EQ(scriptIdInStack[i], script->GetId());
16937 } 16863 }
16938 } 16864 }
16939 16865
16940 16866
16941 void AnalyzeStackOfInlineScriptWithSourceURL( 16867 void AnalyzeStackOfInlineScriptWithSourceURL(
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
17124 intptr_t size_with_garbage = CcTest::heap()->SizeOfObjects(); 17050 intptr_t size_with_garbage = CcTest::heap()->SizeOfObjects();
17125 CHECK_GT(size_with_garbage, initial_size + MB); 17051 CHECK_GT(size_with_garbage, initial_size + MB);
17126 bool finished = false; 17052 bool finished = false;
17127 for (int i = 0; i < 200 && !finished; i++) { 17053 for (int i = 0; i < 200 && !finished; i++) {
17128 finished = v8::V8::IdleNotification(kShortIdlePauseInMs); 17054 finished = v8::V8::IdleNotification(kShortIdlePauseInMs);
17129 } 17055 }
17130 intptr_t final_size = CcTest::heap()->SizeOfObjects(); 17056 intptr_t final_size = CcTest::heap()->SizeOfObjects();
17131 CHECK_LT(final_size, initial_size + 1); 17057 CHECK_LT(final_size, initial_size + 1);
17132 } 17058 }
17133 17059
17060
17061 TEST(Regress2333) {
17062 LocalContext env;
17063 for (int i = 0; i < 3; i++) {
17064 CcTest::heap()->PerformScavenge();
17065 }
17066 }
17067
17134 static uint32_t* stack_limit; 17068 static uint32_t* stack_limit;
17135 17069
17136 static void GetStackLimitCallback( 17070 static void GetStackLimitCallback(
17137 const v8::FunctionCallbackInfo<v8::Value>& args) { 17071 const v8::FunctionCallbackInfo<v8::Value>& args) {
17138 stack_limit = reinterpret_cast<uint32_t*>( 17072 stack_limit = reinterpret_cast<uint32_t*>(
17139 CcTest::i_isolate()->stack_guard()->real_climit()); 17073 CcTest::i_isolate()->stack_guard()->real_climit());
17140 } 17074 }
17141 17075
17142 17076
17143 // Uses the address of a local variable to determine the stack top now. 17077 // Uses the address of a local variable to determine the stack top now.
(...skipping 13 matching lines...) Expand all
17157 // We need at least 165kB for an x64 debug build with clang and ASAN. 17091 // We need at least 165kB for an x64 debug build with clang and ASAN.
17158 static const int stack_breathing_room = 256 * i::KB; 17092 static const int stack_breathing_room = 256 * i::KB;
17159 17093
17160 17094
17161 TEST(SetResourceConstraints) { 17095 TEST(SetResourceConstraints) {
17162 uint32_t* set_limit = ComputeStackLimit(stack_breathing_room); 17096 uint32_t* set_limit = ComputeStackLimit(stack_breathing_room);
17163 17097
17164 // Set stack limit. 17098 // Set stack limit.
17165 v8::ResourceConstraints constraints; 17099 v8::ResourceConstraints constraints;
17166 constraints.set_stack_limit(set_limit); 17100 constraints.set_stack_limit(set_limit);
17167 CHECK(v8::SetResourceConstraints(&constraints)); 17101 CHECK(v8::SetResourceConstraints(CcTest::isolate(), &constraints));
17168 17102
17169 // Execute a script. 17103 // Execute a script.
17170 LocalContext env; 17104 LocalContext env;
17171 v8::HandleScope scope(env->GetIsolate()); 17105 v8::HandleScope scope(env->GetIsolate());
17172 Local<v8::FunctionTemplate> fun_templ = 17106 Local<v8::FunctionTemplate> fun_templ =
17173 v8::FunctionTemplate::New(GetStackLimitCallback); 17107 v8::FunctionTemplate::New(GetStackLimitCallback);
17174 Local<Function> fun = fun_templ->GetFunction(); 17108 Local<Function> fun = fun_templ->GetFunction();
17175 env->Global()->Set(v8_str("get_stack_limit"), fun); 17109 env->Global()->Set(v8_str("get_stack_limit"), fun);
17176 CompileRun("get_stack_limit();"); 17110 CompileRun("get_stack_limit();");
17177 17111
17178 CHECK(stack_limit == set_limit); 17112 CHECK(stack_limit == set_limit);
17179 } 17113 }
17180 17114
17181 17115
17182 TEST(SetResourceConstraintsInThread) { 17116 TEST(SetResourceConstraintsInThread) {
17183 uint32_t* set_limit; 17117 uint32_t* set_limit;
17184 { 17118 {
17185 v8::Locker locker(CcTest::isolate()); 17119 v8::Locker locker(CcTest::isolate());
17186 set_limit = ComputeStackLimit(stack_breathing_room); 17120 set_limit = ComputeStackLimit(stack_breathing_room);
17187 17121
17188 // Set stack limit. 17122 // Set stack limit.
17189 v8::ResourceConstraints constraints; 17123 v8::ResourceConstraints constraints;
17190 constraints.set_stack_limit(set_limit); 17124 constraints.set_stack_limit(set_limit);
17191 CHECK(v8::SetResourceConstraints(&constraints)); 17125 CHECK(v8::SetResourceConstraints(CcTest::isolate(), &constraints));
17192 17126
17193 // Execute a script. 17127 // Execute a script.
17194 v8::HandleScope scope(CcTest::isolate()); 17128 v8::HandleScope scope(CcTest::isolate());
17195 LocalContext env; 17129 LocalContext env;
17196 Local<v8::FunctionTemplate> fun_templ = 17130 Local<v8::FunctionTemplate> fun_templ =
17197 v8::FunctionTemplate::New(GetStackLimitCallback); 17131 v8::FunctionTemplate::New(GetStackLimitCallback);
17198 Local<Function> fun = fun_templ->GetFunction(); 17132 Local<Function> fun = fun_templ->GetFunction();
17199 env->Global()->Set(v8_str("get_stack_limit"), fun); 17133 env->Global()->Set(v8_str("get_stack_limit"), fun);
17200 CompileRun("get_stack_limit();"); 17134 CompileRun("get_stack_limit();");
17201 17135
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
17262 const char* string = "Some string"; 17196 const char* string = "Some string";
17263 uint16_t* two_byte_string = AsciiToTwoByteString(string); 17197 uint16_t* two_byte_string = AsciiToTwoByteString(string);
17264 TestResource* resource[4]; 17198 TestResource* resource[4];
17265 resource[0] = new TestResource(two_byte_string); 17199 resource[0] = new TestResource(two_byte_string);
17266 v8::Local<v8::String> string0 = v8::String::NewExternal(resource[0]); 17200 v8::Local<v8::String> string0 = v8::String::NewExternal(resource[0]);
17267 resource[1] = new TestResource(two_byte_string); 17201 resource[1] = new TestResource(two_byte_string);
17268 v8::Local<v8::String> string1 = v8::String::NewExternal(resource[1]); 17202 v8::Local<v8::String> string1 = v8::String::NewExternal(resource[1]);
17269 17203
17270 // Externalized symbol. 17204 // Externalized symbol.
17271 resource[2] = new TestResource(two_byte_string); 17205 resource[2] = new TestResource(two_byte_string);
17272 v8::Local<v8::String> string2 = v8::String::NewSymbol(string); 17206 v8::Local<v8::String> string2 = v8::String::NewFromUtf8(
17207 env->GetIsolate(), string, v8::String::kInternalizedString);
17273 CHECK(string2->MakeExternal(resource[2])); 17208 CHECK(string2->MakeExternal(resource[2]));
17274 17209
17275 // Symbolized External. 17210 // Symbolized External.
17276 resource[3] = new TestResource(AsciiToTwoByteString("Some other string")); 17211 resource[3] = new TestResource(AsciiToTwoByteString("Some other string"));
17277 v8::Local<v8::String> string3 = v8::String::NewExternal(resource[3]); 17212 v8::Local<v8::String> string3 = v8::String::NewExternal(resource[3]);
17278 CcTest::heap()->CollectAllAvailableGarbage(); // Tenure string. 17213 CcTest::heap()->CollectAllAvailableGarbage(); // Tenure string.
17279 // Turn into a symbol. 17214 // Turn into a symbol.
17280 i::Handle<i::String> string3_i = v8::Utils::OpenHandle(*string3); 17215 i::Handle<i::String> string3_i = v8::Utils::OpenHandle(*string3);
17281 CHECK(!CcTest::heap()->InternalizeString(*string3_i)->IsFailure()); 17216 CHECK(!CcTest::heap()->InternalizeString(*string3_i)->IsFailure());
17282 CHECK(string3_i->IsInternalizedString()); 17217 CHECK(string3_i->IsInternalizedString());
17283 17218
17284 // We need to add usages for string* to avoid warnings in GCC 4.7 17219 // We need to add usages for string* to avoid warnings in GCC 4.7
17285 CHECK(string0->IsExternal()); 17220 CHECK(string0->IsExternal());
17286 CHECK(string1->IsExternal()); 17221 CHECK(string1->IsExternal());
17287 CHECK(string2->IsExternal()); 17222 CHECK(string2->IsExternal());
17288 CHECK(string3->IsExternal()); 17223 CHECK(string3->IsExternal());
17289 17224
17290 VisitorImpl visitor(resource); 17225 VisitorImpl visitor(resource);
17291 v8::V8::VisitExternalResources(&visitor); 17226 v8::V8::VisitExternalResources(&visitor);
17292 visitor.CheckVisitedResources(); 17227 visitor.CheckVisitedResources();
17293 } 17228 }
17294 17229
17295 17230
17231 TEST(ExternalStringCollectedAtTearDown) {
17232 int destroyed = 0;
17233 v8::Isolate* isolate = v8::Isolate::New();
17234 { v8::Isolate::Scope isolate_scope(isolate);
17235 v8::HandleScope handle_scope(isolate);
17236 const char* s = "One string to test them all, one string to find them.";
17237 TestAsciiResource* inscription =
17238 new TestAsciiResource(i::StrDup(s), &destroyed);
17239 v8::Local<v8::String> ring = v8::String::NewExternal(inscription);
17240 // Ring is still alive. Orcs are roaming freely across our lands.
17241 CHECK_EQ(0, destroyed);
17242 USE(ring);
17243 }
17244
17245 isolate->Dispose();
17246 // Ring has been destroyed. Free Peoples of Middle-earth Rejoice.
17247 CHECK_EQ(1, destroyed);
17248 }
17249
17250
17296 static double DoubleFromBits(uint64_t value) { 17251 static double DoubleFromBits(uint64_t value) {
17297 double target; 17252 double target;
17298 i::OS::MemCopy(&target, &value, sizeof(target)); 17253 i::OS::MemCopy(&target, &value, sizeof(target));
17299 return target; 17254 return target;
17300 } 17255 }
17301 17256
17302 17257
17303 static uint64_t DoubleToBits(double value) { 17258 static uint64_t DoubleToBits(double value) {
17304 uint64_t target; 17259 uint64_t target;
17305 i::OS::MemCopy(&target, &value, sizeof(target)); 17260 i::OS::MemCopy(&target, &value, sizeof(target));
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
17417 tc.ReThrow(); 17372 tc.ReThrow();
17418 } 17373 }
17419 17374
17420 17375
17421 // Test that an exception can be propagated down through a spaghetti 17376 // Test that an exception can be propagated down through a spaghetti
17422 // stack using ReThrow. 17377 // stack using ReThrow.
17423 THREADED_TEST(SpaghettiStackReThrow) { 17378 THREADED_TEST(SpaghettiStackReThrow) {
17424 v8::HandleScope scope(CcTest::isolate()); 17379 v8::HandleScope scope(CcTest::isolate());
17425 LocalContext context; 17380 LocalContext context;
17426 context->Global()->Set( 17381 context->Global()->Set(
17427 v8::String::New("s"), 17382 v8::String::NewFromUtf8(CcTest::isolate(), "s"),
17428 v8::FunctionTemplate::New(SpaghettiIncident)->GetFunction()); 17383 v8::FunctionTemplate::New(SpaghettiIncident)->GetFunction());
17429 v8::TryCatch try_catch; 17384 v8::TryCatch try_catch;
17430 CompileRun( 17385 CompileRun(
17431 "var i = 0;" 17386 "var i = 0;"
17432 "var o = {" 17387 "var o = {"
17433 " toString: function () {" 17388 " toString: function () {"
17434 " if (i == 10) {" 17389 " if (i == 10) {"
17435 " throw 'Hey!';" 17390 " throw 'Hey!';"
17436 " } else {" 17391 " } else {"
17437 " i++;" 17392 " i++;"
(...skipping 20 matching lines...) Expand all
17458 other_context = Context::New(isolate); 17413 other_context = Context::New(isolate);
17459 17414
17460 // Context-dependent context data creates reference from the compilation 17415 // Context-dependent context data creates reference from the compilation
17461 // cache to the global object. 17416 // cache to the global object.
17462 const char* source_simple = "1"; 17417 const char* source_simple = "1";
17463 { 17418 {
17464 v8::HandleScope scope(isolate); 17419 v8::HandleScope scope(isolate);
17465 v8::Local<Context> context = Context::New(isolate); 17420 v8::Local<Context> context = Context::New(isolate);
17466 17421
17467 context->Enter(); 17422 context->Enter();
17468 Local<v8::String> obj = v8::String::New(""); 17423 Local<v8::String> obj = v8::String::NewFromUtf8(isolate, "");
17469 context->SetEmbedderData(0, obj); 17424 context->SetEmbedderData(0, obj);
17470 CompileRun(source_simple); 17425 CompileRun(source_simple);
17471 context->Exit(); 17426 context->Exit();
17472 } 17427 }
17473 v8::V8::ContextDisposedNotification(); 17428 v8::V8::ContextDisposedNotification();
17474 for (gc_count = 1; gc_count < 10; gc_count++) { 17429 for (gc_count = 1; gc_count < 10; gc_count++) {
17475 other_context->Enter(); 17430 other_context->Enter();
17476 CompileRun(source_simple); 17431 CompileRun(source_simple);
17477 other_context->Exit(); 17432 other_context->Exit();
17478 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 17433 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
17530 CHECK_GE(2, gc_count); 17485 CHECK_GE(2, gc_count);
17531 CHECK_EQ(1, GetGlobalObjectsCount()); 17486 CHECK_EQ(1, GetGlobalObjectsCount());
17532 17487
17533 v8::V8::ContextDisposedNotification(); 17488 v8::V8::ContextDisposedNotification();
17534 } 17489 }
17535 17490
17536 17491
17537 THREADED_TEST(ScriptOrigin) { 17492 THREADED_TEST(ScriptOrigin) {
17538 LocalContext env; 17493 LocalContext env;
17539 v8::HandleScope scope(env->GetIsolate()); 17494 v8::HandleScope scope(env->GetIsolate());
17540 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); 17495 v8::ScriptOrigin origin =
17541 v8::Handle<v8::String> script = v8::String::New( 17496 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test"));
17542 "function f() {}\n\nfunction g() {}"); 17497 v8::Handle<v8::String> script = v8::String::NewFromUtf8(
17498 env->GetIsolate(), "function f() {}\n\nfunction g() {}");
17543 v8::Script::Compile(script, &origin)->Run(); 17499 v8::Script::Compile(script, &origin)->Run();
17544 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 17500 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
17545 env->Global()->Get(v8::String::New("f"))); 17501 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
17546 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( 17502 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast(
17547 env->Global()->Get(v8::String::New("g"))); 17503 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g")));
17548 17504
17549 v8::ScriptOrigin script_origin_f = f->GetScriptOrigin(); 17505 v8::ScriptOrigin script_origin_f = f->GetScriptOrigin();
17550 CHECK_EQ("test", *v8::String::Utf8Value(script_origin_f.ResourceName())); 17506 CHECK_EQ("test", *v8::String::Utf8Value(script_origin_f.ResourceName()));
17551 CHECK_EQ(0, script_origin_f.ResourceLineOffset()->Int32Value()); 17507 CHECK_EQ(0, script_origin_f.ResourceLineOffset()->Int32Value());
17552 17508
17553 v8::ScriptOrigin script_origin_g = g->GetScriptOrigin(); 17509 v8::ScriptOrigin script_origin_g = g->GetScriptOrigin();
17554 CHECK_EQ("test", *v8::String::Utf8Value(script_origin_g.ResourceName())); 17510 CHECK_EQ("test", *v8::String::Utf8Value(script_origin_g.ResourceName()));
17555 CHECK_EQ(0, script_origin_g.ResourceLineOffset()->Int32Value()); 17511 CHECK_EQ(0, script_origin_g.ResourceLineOffset()->Int32Value());
17556 } 17512 }
17557 17513
17558 17514
17559 THREADED_TEST(FunctionGetInferredName) { 17515 THREADED_TEST(FunctionGetInferredName) {
17560 LocalContext env; 17516 LocalContext env;
17561 v8::HandleScope scope(env->GetIsolate()); 17517 v8::HandleScope scope(env->GetIsolate());
17562 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); 17518 v8::ScriptOrigin origin =
17563 v8::Handle<v8::String> script = v8::String::New( 17519 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test"));
17520 v8::Handle<v8::String> script = v8::String::NewFromUtf8(
17521 env->GetIsolate(),
17564 "var foo = { bar : { baz : function() {}}}; var f = foo.bar.baz;"); 17522 "var foo = { bar : { baz : function() {}}}; var f = foo.bar.baz;");
17565 v8::Script::Compile(script, &origin)->Run(); 17523 v8::Script::Compile(script, &origin)->Run();
17566 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 17524 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
17567 env->Global()->Get(v8::String::New("f"))); 17525 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
17568 CHECK_EQ("foo.bar.baz", *v8::String::Utf8Value(f->GetInferredName())); 17526 CHECK_EQ("foo.bar.baz", *v8::String::Utf8Value(f->GetInferredName()));
17569 } 17527 }
17570 17528
17571 17529
17572 THREADED_TEST(FunctionGetDisplayName) { 17530 THREADED_TEST(FunctionGetDisplayName) {
17573 LocalContext env; 17531 LocalContext env;
17574 v8::HandleScope scope(env->GetIsolate()); 17532 v8::HandleScope scope(env->GetIsolate());
17575 const char* code = "var error = false;" 17533 const char* code = "var error = false;"
17576 "function a() { this.x = 1; };" 17534 "function a() { this.x = 1; };"
17577 "a.displayName = 'display_a';" 17535 "a.displayName = 'display_a';"
(...skipping 20 matching lines...) Expand all
17598 "});" 17556 "});"
17599 "function f() {};" 17557 "function f() {};"
17600 "f.displayName = { 'foo': 6, toString: function() {" 17558 "f.displayName = { 'foo': 6, toString: function() {"
17601 " error = true;" 17559 " error = true;"
17602 " return 'wrong_display_name';" 17560 " return 'wrong_display_name';"
17603 "}};" 17561 "}};"
17604 "var g = function() {" 17562 "var g = function() {"
17605 " arguments.callee.displayName = 'set_in_runtime';" 17563 " arguments.callee.displayName = 'set_in_runtime';"
17606 "}; g();" 17564 "}; g();"
17607 ; 17565 ;
17608 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); 17566 v8::ScriptOrigin origin =
17609 v8::Script::Compile(v8::String::New(code), &origin)->Run(); 17567 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test"));
17610 v8::Local<v8::Value> error = env->Global()->Get(v8::String::New("error")); 17568 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), code), &origin)
17569 ->Run();
17570 v8::Local<v8::Value> error =
17571 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "error"));
17611 v8::Local<v8::Function> a = v8::Local<v8::Function>::Cast( 17572 v8::Local<v8::Function> a = v8::Local<v8::Function>::Cast(
17612 env->Global()->Get(v8::String::New("a"))); 17573 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "a")));
17613 v8::Local<v8::Function> b = v8::Local<v8::Function>::Cast( 17574 v8::Local<v8::Function> b = v8::Local<v8::Function>::Cast(
17614 env->Global()->Get(v8::String::New("b"))); 17575 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "b")));
17615 v8::Local<v8::Function> c = v8::Local<v8::Function>::Cast( 17576 v8::Local<v8::Function> c = v8::Local<v8::Function>::Cast(
17616 env->Global()->Get(v8::String::New("c"))); 17577 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "c")));
17617 v8::Local<v8::Function> d = v8::Local<v8::Function>::Cast( 17578 v8::Local<v8::Function> d = v8::Local<v8::Function>::Cast(
17618 env->Global()->Get(v8::String::New("d"))); 17579 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "d")));
17619 v8::Local<v8::Function> e = v8::Local<v8::Function>::Cast( 17580 v8::Local<v8::Function> e = v8::Local<v8::Function>::Cast(
17620 env->Global()->Get(v8::String::New("e"))); 17581 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "e")));
17621 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 17582 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
17622 env->Global()->Get(v8::String::New("f"))); 17583 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
17623 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( 17584 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast(
17624 env->Global()->Get(v8::String::New("g"))); 17585 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g")));
17625 CHECK_EQ(false, error->BooleanValue()); 17586 CHECK_EQ(false, error->BooleanValue());
17626 CHECK_EQ("display_a", *v8::String::Utf8Value(a->GetDisplayName())); 17587 CHECK_EQ("display_a", *v8::String::Utf8Value(a->GetDisplayName()));
17627 CHECK_EQ("display_b", *v8::String::Utf8Value(b->GetDisplayName())); 17588 CHECK_EQ("display_b", *v8::String::Utf8Value(b->GetDisplayName()));
17628 CHECK(c->GetDisplayName()->IsUndefined()); 17589 CHECK(c->GetDisplayName()->IsUndefined());
17629 CHECK(d->GetDisplayName()->IsUndefined()); 17590 CHECK(d->GetDisplayName()->IsUndefined());
17630 CHECK(e->GetDisplayName()->IsUndefined()); 17591 CHECK(e->GetDisplayName()->IsUndefined());
17631 CHECK(f->GetDisplayName()->IsUndefined()); 17592 CHECK(f->GetDisplayName()->IsUndefined());
17632 CHECK_EQ("set_in_runtime", *v8::String::Utf8Value(g->GetDisplayName())); 17593 CHECK_EQ("set_in_runtime", *v8::String::Utf8Value(g->GetDisplayName()));
17633 } 17594 }
17634 17595
17635 17596
17636 THREADED_TEST(ScriptLineNumber) { 17597 THREADED_TEST(ScriptLineNumber) {
17637 LocalContext env; 17598 LocalContext env;
17638 v8::HandleScope scope(env->GetIsolate()); 17599 v8::HandleScope scope(env->GetIsolate());
17639 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); 17600 v8::ScriptOrigin origin =
17640 v8::Handle<v8::String> script = v8::String::New( 17601 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test"));
17641 "function f() {}\n\nfunction g() {}"); 17602 v8::Handle<v8::String> script = v8::String::NewFromUtf8(
17603 env->GetIsolate(), "function f() {}\n\nfunction g() {}");
17642 v8::Script::Compile(script, &origin)->Run(); 17604 v8::Script::Compile(script, &origin)->Run();
17643 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 17605 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
17644 env->Global()->Get(v8::String::New("f"))); 17606 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
17645 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( 17607 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast(
17646 env->Global()->Get(v8::String::New("g"))); 17608 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g")));
17647 CHECK_EQ(0, f->GetScriptLineNumber()); 17609 CHECK_EQ(0, f->GetScriptLineNumber());
17648 CHECK_EQ(2, g->GetScriptLineNumber()); 17610 CHECK_EQ(2, g->GetScriptLineNumber());
17649 } 17611 }
17650 17612
17651 17613
17652 THREADED_TEST(ScriptColumnNumber) { 17614 THREADED_TEST(ScriptColumnNumber) {
17653 LocalContext env; 17615 LocalContext env;
17654 v8::HandleScope scope(env->GetIsolate()); 17616 v8::HandleScope scope(env->GetIsolate());
17655 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"), 17617 v8::ScriptOrigin origin =
17656 v8::Integer::New(3), v8::Integer::New(2)); 17618 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test"),
17657 v8::Handle<v8::String> script = v8::String::New( 17619 v8::Integer::New(3), v8::Integer::New(2));
17658 "function foo() {}\n\n function bar() {}"); 17620 v8::Handle<v8::String> script = v8::String::NewFromUtf8(
17621 env->GetIsolate(), "function foo() {}\n\n function bar() {}");
17659 v8::Script::Compile(script, &origin)->Run(); 17622 v8::Script::Compile(script, &origin)->Run();
17660 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( 17623 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
17661 env->Global()->Get(v8::String::New("foo"))); 17624 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo")));
17662 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( 17625 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast(
17663 env->Global()->Get(v8::String::New("bar"))); 17626 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "bar")));
17664 CHECK_EQ(14, foo->GetScriptColumnNumber()); 17627 CHECK_EQ(14, foo->GetScriptColumnNumber());
17665 CHECK_EQ(17, bar->GetScriptColumnNumber()); 17628 CHECK_EQ(17, bar->GetScriptColumnNumber());
17666 } 17629 }
17667 17630
17668 17631
17669 THREADED_TEST(FunctionIsBuiltin) { 17632 THREADED_TEST(FunctionIsBuiltin) {
17670 LocalContext env; 17633 LocalContext env;
17671 v8::HandleScope scope(env->GetIsolate()); 17634 v8::HandleScope scope(env->GetIsolate());
17672 v8::Local<v8::Function> f; 17635 v8::Local<v8::Function> f;
17673 f = v8::Local<v8::Function>::Cast(CompileRun("Math.floor")); 17636 f = v8::Local<v8::Function>::Cast(CompileRun("Math.floor"));
17674 CHECK(f->IsBuiltin()); 17637 CHECK(f->IsBuiltin());
17675 f = v8::Local<v8::Function>::Cast(CompileRun("Object")); 17638 f = v8::Local<v8::Function>::Cast(CompileRun("Object"));
17676 CHECK(f->IsBuiltin()); 17639 CHECK(f->IsBuiltin());
17677 f = v8::Local<v8::Function>::Cast(CompileRun("Object.__defineSetter__")); 17640 f = v8::Local<v8::Function>::Cast(CompileRun("Object.__defineSetter__"));
17678 CHECK(f->IsBuiltin()); 17641 CHECK(f->IsBuiltin());
17679 f = v8::Local<v8::Function>::Cast(CompileRun("Array.prototype.toString")); 17642 f = v8::Local<v8::Function>::Cast(CompileRun("Array.prototype.toString"));
17680 CHECK(f->IsBuiltin()); 17643 CHECK(f->IsBuiltin());
17681 f = v8::Local<v8::Function>::Cast(CompileRun("function a() {}; a;")); 17644 f = v8::Local<v8::Function>::Cast(CompileRun("function a() {}; a;"));
17682 CHECK(!f->IsBuiltin()); 17645 CHECK(!f->IsBuiltin());
17683 } 17646 }
17684 17647
17685 17648
17686 THREADED_TEST(FunctionGetScriptId) { 17649 THREADED_TEST(FunctionGetScriptId) {
17687 LocalContext env; 17650 LocalContext env;
17688 v8::HandleScope scope(env->GetIsolate()); 17651 v8::HandleScope scope(env->GetIsolate());
17689 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"), 17652 v8::ScriptOrigin origin =
17690 v8::Integer::New(3), v8::Integer::New(2)); 17653 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test"),
17691 v8::Handle<v8::String> scriptSource = v8::String::New( 17654 v8::Integer::New(3), v8::Integer::New(2));
17692 "function foo() {}\n\n function bar() {}"); 17655 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8(
17656 env->GetIsolate(), "function foo() {}\n\n function bar() {}");
17693 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin)); 17657 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin));
17694 script->Run(); 17658 script->Run();
17695 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( 17659 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
17696 env->Global()->Get(v8::String::New("foo"))); 17660 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo")));
17697 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( 17661 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast(
17698 env->Global()->Get(v8::String::New("bar"))); 17662 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "bar")));
17699 CHECK_EQ(script->Id(), foo->GetScriptId()); 17663 CHECK_EQ(script->GetId(), foo->ScriptId());
17700 CHECK_EQ(script->Id(), bar->GetScriptId()); 17664 CHECK_EQ(script->GetId(), bar->ScriptId());
17701 } 17665 }
17702 17666
17703 17667
17704 static void GetterWhichReturns42( 17668 static void GetterWhichReturns42(
17705 Local<String> name, 17669 Local<String> name,
17706 const v8::PropertyCallbackInfo<v8::Value>& info) { 17670 const v8::PropertyCallbackInfo<v8::Value>& info) {
17707 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); 17671 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject());
17708 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); 17672 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject());
17709 info.GetReturnValue().Set(v8_num(42)); 17673 info.GetReturnValue().Set(v8_num(42));
17710 } 17674 }
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
18486 { 18450 {
18487 v8::HandleScope scope(v8::Isolate::GetCurrent()); 18451 v8::HandleScope scope(v8::Isolate::GetCurrent());
18488 v8::Local<v8::Context> context = 18452 v8::Local<v8::Context> context =
18489 v8::Local<v8::Context>::New(v8::Isolate::GetCurrent(), context1); 18453 v8::Local<v8::Context>::New(v8::Isolate::GetCurrent(), context1);
18490 v8::Context::Scope context_scope(context); 18454 v8::Context::Scope context_scope(context);
18491 ExpectString("function f() { return foo; }; f()", "isolate 1"); 18455 ExpectString("function f() { return foo; }; f()", "isolate 1");
18492 } 18456 }
18493 18457
18494 { 18458 {
18495 v8::Isolate::Scope iscope(isolate2); 18459 v8::Isolate::Scope iscope(isolate2);
18496 context2.Dispose(); 18460 context2.Reset();
18497 } 18461 }
18498 18462
18499 context1.Dispose(); 18463 context1.Reset();
18500 isolate1->Exit(); 18464 isolate1->Exit();
18501 18465
18502 v8::V8::SetFatalErrorHandler(StoringErrorCallback); 18466 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
18503 last_location = last_message = NULL; 18467 last_location = last_message = NULL;
18504 18468
18505 isolate1->Dispose(); 18469 isolate1->Dispose();
18506 CHECK_EQ(last_location, NULL); 18470 CHECK_EQ(last_location, NULL);
18507 CHECK_EQ(last_message, NULL); 18471 CHECK_EQ(last_message, NULL);
18508 18472
18509 isolate2->Dispose(); 18473 isolate2->Dispose();
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
18631 switch (testCase_) { 18595 switch (testCase_) {
18632 case IgnoreOOM: 18596 case IgnoreOOM:
18633 v8::V8::IgnoreOutOfMemoryException(); 18597 v8::V8::IgnoreOutOfMemoryException();
18634 break; 18598 break;
18635 18599
18636 case SetResourceConstraints: { 18600 case SetResourceConstraints: {
18637 static const int K = 1024; 18601 static const int K = 1024;
18638 v8::ResourceConstraints constraints; 18602 v8::ResourceConstraints constraints;
18639 constraints.set_max_young_space_size(256 * K); 18603 constraints.set_max_young_space_size(256 * K);
18640 constraints.set_max_old_space_size(4 * K * K); 18604 constraints.set_max_old_space_size(4 * K * K);
18641 v8::SetResourceConstraints(&constraints); 18605 v8::SetResourceConstraints(CcTest::isolate(), &constraints);
18642 break; 18606 break;
18643 } 18607 }
18644 18608
18645 case SetFatalHandler: 18609 case SetFatalHandler:
18646 v8::V8::SetFatalErrorHandler(NULL); 18610 v8::V8::SetFatalErrorHandler(NULL);
18647 break; 18611 break;
18648 18612
18649 case SetCounterFunction: 18613 case SetCounterFunction:
18650 v8::V8::SetCounterFunction(NULL); 18614 v8::V8::SetCounterFunction(NULL);
18651 break; 18615 break;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
18904 v8::HandleScope scope(isolate); 18868 v8::HandleScope scope(isolate);
18905 v8::Persistent<v8::Object> object(isolate, v8::Object::New()); 18869 v8::Persistent<v8::Object> object(isolate, v8::Object::New());
18906 CHECK_EQ(0, object.WrapperClassId()); 18870 CHECK_EQ(0, object.WrapperClassId());
18907 object.SetWrapperClassId(42); 18871 object.SetWrapperClassId(42);
18908 CHECK_EQ(42, object.WrapperClassId()); 18872 CHECK_EQ(42, object.WrapperClassId());
18909 18873
18910 Visitor42 visitor(&object); 18874 Visitor42 visitor(&object);
18911 v8::V8::VisitHandlesWithClassIds(&visitor); 18875 v8::V8::VisitHandlesWithClassIds(&visitor);
18912 CHECK_EQ(1, visitor.counter_); 18876 CHECK_EQ(1, visitor.counter_);
18913 18877
18914 object.Dispose(); 18878 object.Reset();
18915 } 18879 }
18916 18880
18917 18881
18918 TEST(WrapperClassId) { 18882 TEST(WrapperClassId) {
18919 LocalContext context; 18883 LocalContext context;
18920 v8::Isolate* isolate = context->GetIsolate(); 18884 v8::Isolate* isolate = context->GetIsolate();
18921 v8::HandleScope scope(isolate); 18885 v8::HandleScope scope(isolate);
18922 v8::Persistent<v8::Object> object(isolate, v8::Object::New()); 18886 v8::Persistent<v8::Object> object(isolate, v8::Object::New());
18923 CHECK_EQ(0, object.WrapperClassId()); 18887 CHECK_EQ(0, object.WrapperClassId());
18924 object.SetWrapperClassId(65535); 18888 object.SetWrapperClassId(65535);
18925 CHECK_EQ(65535, object.WrapperClassId()); 18889 CHECK_EQ(65535, object.WrapperClassId());
18926 object.Dispose(); 18890 object.Reset();
18927 } 18891 }
18928 18892
18929 18893
18930 TEST(PersistentHandleInNewSpaceVisitor) { 18894 TEST(PersistentHandleInNewSpaceVisitor) {
18931 LocalContext context; 18895 LocalContext context;
18932 v8::Isolate* isolate = context->GetIsolate(); 18896 v8::Isolate* isolate = context->GetIsolate();
18933 v8::HandleScope scope(isolate); 18897 v8::HandleScope scope(isolate);
18934 v8::Persistent<v8::Object> object1(isolate, v8::Object::New()); 18898 v8::Persistent<v8::Object> object1(isolate, v8::Object::New());
18935 CHECK_EQ(0, object1.WrapperClassId()); 18899 CHECK_EQ(0, object1.WrapperClassId());
18936 object1.SetWrapperClassId(42); 18900 object1.SetWrapperClassId(42);
18937 CHECK_EQ(42, object1.WrapperClassId()); 18901 CHECK_EQ(42, object1.WrapperClassId());
18938 18902
18939 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 18903 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
18940 18904
18941 v8::Persistent<v8::Object> object2(isolate, v8::Object::New()); 18905 v8::Persistent<v8::Object> object2(isolate, v8::Object::New());
18942 CHECK_EQ(0, object2.WrapperClassId()); 18906 CHECK_EQ(0, object2.WrapperClassId());
18943 object2.SetWrapperClassId(42); 18907 object2.SetWrapperClassId(42);
18944 CHECK_EQ(42, object2.WrapperClassId()); 18908 CHECK_EQ(42, object2.WrapperClassId());
18945 18909
18946 Visitor42 visitor(&object2); 18910 Visitor42 visitor(&object2);
18947 v8::V8::VisitHandlesForPartialDependence(isolate, &visitor); 18911 v8::V8::VisitHandlesForPartialDependence(isolate, &visitor);
18948 CHECK_EQ(1, visitor.counter_); 18912 CHECK_EQ(1, visitor.counter_);
18949 18913
18950 object1.Dispose(); 18914 object1.Reset();
18951 object2.Dispose(); 18915 object2.Reset();
18952 } 18916 }
18953 18917
18954 18918
18955 TEST(RegExp) { 18919 TEST(RegExp) {
18956 LocalContext context; 18920 LocalContext context;
18957 v8::HandleScope scope(context->GetIsolate()); 18921 v8::HandleScope scope(context->GetIsolate());
18958 18922
18959 v8::Handle<v8::RegExp> re = v8::RegExp::New(v8_str("foo"), v8::RegExp::kNone); 18923 v8::Handle<v8::RegExp> re = v8::RegExp::New(v8_str("foo"), v8::RegExp::kNone);
18960 CHECK(re->IsRegExp()); 18924 CHECK(re->IsRegExp());
18961 CHECK(re->GetSource()->Equals(v8_str("foo"))); 18925 CHECK(re->GetSource()->Equals(v8_str("foo")));
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
19756 v8::HandleScope scope(env->GetIsolate()); 19720 v8::HandleScope scope(env->GetIsolate());
19757 v8::Handle<v8::FunctionTemplate> recursive_runtime = 19721 v8::Handle<v8::FunctionTemplate> recursive_runtime =
19758 v8::FunctionTemplate::New(RecursiveCall); 19722 v8::FunctionTemplate::New(RecursiveCall);
19759 env->Global()->Set(v8_str("recursion"), 19723 env->Global()->Set(v8_str("recursion"),
19760 recursive_runtime->GetFunction()); 19724 recursive_runtime->GetFunction());
19761 // Adding the same callback a second time has no effect. 19725 // Adding the same callback a second time has no effect.
19762 v8::V8::AddCallCompletedCallback(CallCompletedCallback1); 19726 v8::V8::AddCallCompletedCallback(CallCompletedCallback1);
19763 v8::V8::AddCallCompletedCallback(CallCompletedCallback1); 19727 v8::V8::AddCallCompletedCallback(CallCompletedCallback1);
19764 v8::V8::AddCallCompletedCallback(CallCompletedCallback2); 19728 v8::V8::AddCallCompletedCallback(CallCompletedCallback2);
19765 i::OS::Print("--- Script (1) ---\n"); 19729 i::OS::Print("--- Script (1) ---\n");
19766 Local<Script> script = 19730 Local<Script> script = v8::Script::Compile(
19767 v8::Script::Compile(v8::String::New("recursion(0)")); 19731 v8::String::NewFromUtf8(env->GetIsolate(), "recursion(0)"));
19768 script->Run(); 19732 script->Run();
19769 CHECK_EQ(3, callback_fired); 19733 CHECK_EQ(3, callback_fired);
19770 19734
19771 i::OS::Print("\n--- Script (2) ---\n"); 19735 i::OS::Print("\n--- Script (2) ---\n");
19772 callback_fired = 0; 19736 callback_fired = 0;
19773 v8::V8::RemoveCallCompletedCallback(CallCompletedCallback1); 19737 v8::V8::RemoveCallCompletedCallback(CallCompletedCallback1);
19774 script->Run(); 19738 script->Run();
19775 CHECK_EQ(2, callback_fired); 19739 CHECK_EQ(2, callback_fired);
19776 19740
19777 i::OS::Print("\n--- Function ---\n"); 19741 i::OS::Print("\n--- Function ---\n");
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
19922 i::Handle<i::Object> false_value = factory->false_value(); 19886 i::Handle<i::Object> false_value = factory->false_value();
19923 CHECK(*v8::Utils::OpenHandle(*v8::False(isolate)) == *false_value); 19887 CHECK(*v8::Utils::OpenHandle(*v8::False(isolate)) == *false_value);
19924 } 19888 }
19925 19889
19926 19890
19927 UNINITIALIZED_TEST(IsolateEmbedderData) { 19891 UNINITIALIZED_TEST(IsolateEmbedderData) {
19928 CcTest::DisableAutomaticDispose(); 19892 CcTest::DisableAutomaticDispose();
19929 v8::Isolate* isolate = v8::Isolate::New(); 19893 v8::Isolate* isolate = v8::Isolate::New();
19930 isolate->Enter(); 19894 isolate->Enter();
19931 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 19895 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
19932 CHECK_EQ(NULL, isolate->GetData()); 19896 for (uint32_t slot = 0; slot < v8::Isolate::GetNumberOfDataSlots(); ++slot) {
19933 CHECK_EQ(NULL, i_isolate->GetData()); 19897 CHECK_EQ(NULL, isolate->GetData(slot));
19934 static void* data1 = reinterpret_cast<void*>(0xacce55ed); 19898 CHECK_EQ(NULL, i_isolate->GetData(slot));
19935 isolate->SetData(data1); 19899 }
19936 CHECK_EQ(data1, isolate->GetData()); 19900 for (uint32_t slot = 0; slot < v8::Isolate::GetNumberOfDataSlots(); ++slot) {
19937 CHECK_EQ(data1, i_isolate->GetData()); 19901 void* data = reinterpret_cast<void*>(0xacce55ed + slot);
19938 static void* data2 = reinterpret_cast<void*>(0xdecea5ed); 19902 isolate->SetData(slot, data);
19939 i_isolate->SetData(data2); 19903 }
19940 CHECK_EQ(data2, isolate->GetData()); 19904 for (uint32_t slot = 0; slot < v8::Isolate::GetNumberOfDataSlots(); ++slot) {
19941 CHECK_EQ(data2, i_isolate->GetData()); 19905 void* data = reinterpret_cast<void*>(0xacce55ed + slot);
19906 CHECK_EQ(data, isolate->GetData(slot));
19907 CHECK_EQ(data, i_isolate->GetData(slot));
19908 }
19909 for (uint32_t slot = 0; slot < v8::Isolate::GetNumberOfDataSlots(); ++slot) {
19910 void* data = reinterpret_cast<void*>(0xdecea5ed + slot);
19911 isolate->SetData(slot, data);
19912 }
19913 for (uint32_t slot = 0; slot < v8::Isolate::GetNumberOfDataSlots(); ++slot) {
19914 void* data = reinterpret_cast<void*>(0xdecea5ed + slot);
19915 CHECK_EQ(data, isolate->GetData(slot));
19916 CHECK_EQ(data, i_isolate->GetData(slot));
19917 }
19942 isolate->Exit(); 19918 isolate->Exit();
19943 isolate->Dispose(); 19919 isolate->Dispose();
19944 } 19920 }
19945 19921
19946 19922
19947 TEST(StringEmpty) { 19923 TEST(StringEmpty) {
19948 LocalContext context; 19924 LocalContext context;
19949 i::Factory* factory = CcTest::i_isolate()->factory(); 19925 i::Factory* factory = CcTest::i_isolate()->factory();
19950 v8::Isolate* isolate = CcTest::isolate(); 19926 v8::Isolate* isolate = CcTest::isolate();
19951 v8::HandleScope scope(isolate); 19927 v8::HandleScope scope(isolate);
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
20358 Local<Object> map_object(Local<Object>::Cast(map_value)); 20334 Local<Object> map_object(Local<Object>::Cast(map_value));
20359 CHECK_EQ(0, map_object->InternalFieldCount()); 20335 CHECK_EQ(0, map_object->InternalFieldCount());
20360 } 20336 }
20361 20337
20362 20338
20363 THREADED_TEST(Regress2746) { 20339 THREADED_TEST(Regress2746) {
20364 LocalContext context; 20340 LocalContext context;
20365 v8::Isolate* isolate = context->GetIsolate(); 20341 v8::Isolate* isolate = context->GetIsolate();
20366 v8::HandleScope scope(isolate); 20342 v8::HandleScope scope(isolate);
20367 Local<Object> obj = Object::New(); 20343 Local<Object> obj = Object::New();
20368 Local<String> key = String::New("key"); 20344 Local<String> key = String::NewFromUtf8(context->GetIsolate(), "key");
20369 obj->SetHiddenValue(key, v8::Undefined(isolate)); 20345 obj->SetHiddenValue(key, v8::Undefined(isolate));
20370 Local<Value> value = obj->GetHiddenValue(key); 20346 Local<Value> value = obj->GetHiddenValue(key);
20371 CHECK(!value.IsEmpty()); 20347 CHECK(!value.IsEmpty());
20372 CHECK(value->IsUndefined()); 20348 CHECK(value->IsUndefined());
20373 } 20349 }
20374 20350
20375 20351
20376 THREADED_TEST(Regress260106) { 20352 THREADED_TEST(Regress260106) {
20377 LocalContext context; 20353 LocalContext context;
20378 v8::HandleScope scope(context->GetIsolate()); 20354 v8::HandleScope scope(context->GetIsolate());
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
20804 } 20780 }
20805 for (int i = 0; i < runs; i++) { 20781 for (int i = 0; i < runs; i++) {
20806 Local<String> expected; 20782 Local<String> expected;
20807 if (i != 0) { 20783 if (i != 0) {
20808 CHECK_EQ(v8_str("escape value"), values[i]); 20784 CHECK_EQ(v8_str("escape value"), values[i]);
20809 } else { 20785 } else {
20810 CHECK(values[i].IsEmpty()); 20786 CHECK(values[i].IsEmpty());
20811 } 20787 }
20812 } 20788 }
20813 } 20789 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698