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

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

Issue 146213004: A64: Synchronize with r16849. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 months 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
« no previous file with comments | « test/cctest/test-alloc.cc ('k') | test/cctest/test-assembler-arm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 using ::v8::Script; 70 using ::v8::Script;
71 using ::v8::StackTrace; 71 using ::v8::StackTrace;
72 using ::v8::String; 72 using ::v8::String;
73 using ::v8::TryCatch; 73 using ::v8::TryCatch;
74 using ::v8::Undefined; 74 using ::v8::Undefined;
75 using ::v8::UniqueId; 75 using ::v8::UniqueId;
76 using ::v8::V8; 76 using ::v8::V8;
77 using ::v8::Value; 77 using ::v8::Value;
78 78
79 79
80 // TODO(bmeurer): Don't run profiled tests when using the simulator.
81 // This is a temporary work-around, until the profiler is fixed.
82 #if USE_SIMULATOR
83 #define THREADED_PROFILED_TEST(Name) \
84 THREADED_TEST(Name)
85 #else
80 #define THREADED_PROFILED_TEST(Name) \ 86 #define THREADED_PROFILED_TEST(Name) \
81 static void Test##Name(); \ 87 static void Test##Name(); \
82 TEST(Name##WithProfiler) { \ 88 TEST(Name##WithProfiler) { \
83 RunWithProfiler(&Test##Name); \ 89 RunWithProfiler(&Test##Name); \
84 } \ 90 } \
85 THREADED_TEST(Name) 91 THREADED_TEST(Name)
92 #endif
93
86 94
87 void RunWithProfiler(void (*test)()) { 95 void RunWithProfiler(void (*test)()) {
88 LocalContext env; 96 LocalContext env;
89 v8::HandleScope scope(env->GetIsolate()); 97 v8::HandleScope scope(env->GetIsolate());
90 v8::Local<v8::String> profile_name = v8::String::New("my_profile1"); 98 v8::Local<v8::String> profile_name = v8::String::New("my_profile1");
91 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 99 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
92 100
93 cpu_profiler->StartCpuProfiling(profile_name); 101 cpu_profiler->StartCpuProfiling(profile_name);
94 (*test)(); 102 (*test)();
95 cpu_profiler->DeleteAllCpuProfiles(); 103 cpu_profiler->DeleteAllCpuProfiles();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 for (int i = 0; i < 3; ++i) CHECK(v8::V8::Dispose()); 186 for (int i = 0; i < 3; ++i) CHECK(v8::V8::Dispose());
179 for (int i = 0; i < 3; ++i) CHECK(v8::V8::Initialize()); 187 for (int i = 0; i < 3; ++i) CHECK(v8::V8::Initialize());
180 for (int i = 0; i < 3; ++i) CHECK(v8::V8::Dispose()); 188 for (int i = 0; i < 3; ++i) CHECK(v8::V8::Dispose());
181 // TODO(mstarzinger): This should fail gracefully instead of asserting. 189 // TODO(mstarzinger): This should fail gracefully instead of asserting.
182 // for (int i = 0; i < 3; ++i) CHECK(v8::V8::Initialize()); 190 // for (int i = 0; i < 3; ++i) CHECK(v8::V8::Initialize());
183 for (int i = 0; i < 3; ++i) CHECK(v8::V8::Dispose()); 191 for (int i = 0; i < 3; ++i) CHECK(v8::V8::Dispose());
184 } 192 }
185 193
186 194
187 THREADED_TEST(Handles) { 195 THREADED_TEST(Handles) {
188 v8::HandleScope scope(v8::Isolate::GetCurrent()); 196 v8::HandleScope scope(CcTest::isolate());
189 Local<Context> local_env; 197 Local<Context> local_env;
190 { 198 {
191 LocalContext env; 199 LocalContext env;
192 local_env = env.local(); 200 local_env = env.local();
193 } 201 }
194 202
195 // Local context should still be live. 203 // Local context should still be live.
196 CHECK(!local_env.IsEmpty()); 204 CHECK(!local_env.IsEmpty());
197 local_env->Enter(); 205 local_env->Enter();
198 206
199 v8::Handle<v8::Primitive> undef = v8::Undefined(); 207 v8::Handle<v8::Primitive> undef = v8::Undefined();
200 CHECK(!undef.IsEmpty()); 208 CHECK(!undef.IsEmpty());
201 CHECK(undef->IsUndefined()); 209 CHECK(undef->IsUndefined());
202 210
203 const char* c_source = "1 + 2 + 3"; 211 const char* c_source = "1 + 2 + 3";
204 Local<String> source = String::New(c_source); 212 Local<String> source = String::New(c_source);
205 Local<Script> script = Script::Compile(source); 213 Local<Script> script = Script::Compile(source);
206 CHECK_EQ(6, script->Run()->Int32Value()); 214 CHECK_EQ(6, script->Run()->Int32Value());
207 215
208 local_env->Exit(); 216 local_env->Exit();
209 } 217 }
210 218
211 219
212 THREADED_TEST(IsolateOfContext) { 220 THREADED_TEST(IsolateOfContext) {
213 v8::HandleScope scope(v8::Isolate::GetCurrent()); 221 v8::HandleScope scope(CcTest::isolate());
214 v8::Handle<Context> env = Context::New(v8::Isolate::GetCurrent()); 222 v8::Handle<Context> env = Context::New(CcTest::isolate());
215 223
216 CHECK(!env->InContext()); 224 CHECK(!env->InContext());
217 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); 225 CHECK(env->GetIsolate() == CcTest::isolate());
218 env->Enter(); 226 env->Enter();
219 CHECK(env->InContext()); 227 CHECK(env->InContext());
220 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); 228 CHECK(env->GetIsolate() == CcTest::isolate());
221 env->Exit(); 229 env->Exit();
222 CHECK(!env->InContext()); 230 CHECK(!env->InContext());
223 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); 231 CHECK(env->GetIsolate() == CcTest::isolate());
224 } 232 }
225 233
226 234
227 static void TestSignature(const char* loop_js, Local<Value> receiver) { 235 static void TestSignature(const char* loop_js, Local<Value> receiver) {
228 i::ScopedVector<char> source(200); 236 i::ScopedVector<char> source(200);
229 i::OS::SNPrintF(source, 237 i::OS::SNPrintF(source,
230 "for (var i = 0; i < 10; i++) {" 238 "for (var i = 0; i < 10; i++) {"
231 " %s" 239 " %s"
232 "}", 240 "}",
233 loop_js); 241 loop_js);
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 Local<Value> value = script->Run(); 516 Local<Value> value = script->Run();
509 CHECK(value->IsNumber()); 517 CHECK(value->IsNumber());
510 CHECK_EQ(7, value->Int32Value()); 518 CHECK_EQ(7, value->Int32Value());
511 CHECK(source->IsExternal()); 519 CHECK(source->IsExternal());
512 CHECK_EQ(resource, 520 CHECK_EQ(resource,
513 static_cast<TestResource*>(source->GetExternalStringResource())); 521 static_cast<TestResource*>(source->GetExternalStringResource()));
514 String::Encoding encoding = String::UNKNOWN_ENCODING; 522 String::Encoding encoding = String::UNKNOWN_ENCODING;
515 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), 523 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
516 source->GetExternalStringResourceBase(&encoding)); 524 source->GetExternalStringResourceBase(&encoding));
517 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding); 525 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding);
518 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 526 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
519 CHECK_EQ(0, dispose_count); 527 CHECK_EQ(0, dispose_count);
520 } 528 }
521 v8::internal::Isolate::Current()->compilation_cache()->Clear(); 529 CcTest::i_isolate()->compilation_cache()->Clear();
522 HEAP->CollectAllAvailableGarbage(); 530 CcTest::heap()->CollectAllAvailableGarbage();
523 CHECK_EQ(1, dispose_count); 531 CHECK_EQ(1, dispose_count);
524 } 532 }
525 533
526 534
527 THREADED_TEST(ScriptUsingAsciiStringResource) { 535 THREADED_TEST(ScriptUsingAsciiStringResource) {
528 int dispose_count = 0; 536 int dispose_count = 0;
529 const char* c_source = "1 + 2 * 3"; 537 const char* c_source = "1 + 2 * 3";
530 { 538 {
531 LocalContext env; 539 LocalContext env;
532 v8::HandleScope scope(env->GetIsolate()); 540 v8::HandleScope scope(env->GetIsolate());
533 TestAsciiResource* resource = new TestAsciiResource(i::StrDup(c_source), 541 TestAsciiResource* resource = new TestAsciiResource(i::StrDup(c_source),
534 &dispose_count); 542 &dispose_count);
535 Local<String> source = String::NewExternal(resource); 543 Local<String> source = String::NewExternal(resource);
536 CHECK(source->IsExternalAscii()); 544 CHECK(source->IsExternalAscii());
537 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), 545 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
538 source->GetExternalAsciiStringResource()); 546 source->GetExternalAsciiStringResource());
539 String::Encoding encoding = String::UNKNOWN_ENCODING; 547 String::Encoding encoding = String::UNKNOWN_ENCODING;
540 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), 548 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
541 source->GetExternalStringResourceBase(&encoding)); 549 source->GetExternalStringResourceBase(&encoding));
542 CHECK_EQ(String::ASCII_ENCODING, encoding); 550 CHECK_EQ(String::ASCII_ENCODING, encoding);
543 Local<Script> script = Script::Compile(source); 551 Local<Script> script = Script::Compile(source);
544 Local<Value> value = script->Run(); 552 Local<Value> value = script->Run();
545 CHECK(value->IsNumber()); 553 CHECK(value->IsNumber());
546 CHECK_EQ(7, value->Int32Value()); 554 CHECK_EQ(7, value->Int32Value());
547 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 555 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
548 CHECK_EQ(0, dispose_count); 556 CHECK_EQ(0, dispose_count);
549 } 557 }
550 i::Isolate::Current()->compilation_cache()->Clear(); 558 CcTest::i_isolate()->compilation_cache()->Clear();
551 HEAP->CollectAllAvailableGarbage(); 559 CcTest::heap()->CollectAllAvailableGarbage();
552 CHECK_EQ(1, dispose_count); 560 CHECK_EQ(1, dispose_count);
553 } 561 }
554 562
555 563
556 THREADED_TEST(ScriptMakingExternalString) { 564 THREADED_TEST(ScriptMakingExternalString) {
557 int dispose_count = 0; 565 int dispose_count = 0;
558 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); 566 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3");
559 { 567 {
560 LocalContext env; 568 LocalContext env;
561 v8::HandleScope scope(env->GetIsolate()); 569 v8::HandleScope scope(env->GetIsolate());
562 Local<String> source = String::New(two_byte_source); 570 Local<String> source = String::New(two_byte_source);
563 // Trigger GCs so that the newly allocated string moves to old gen. 571 // Trigger GCs so that the newly allocated string moves to old gen.
564 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now 572 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now
565 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now 573 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
566 CHECK_EQ(source->IsExternal(), false); 574 CHECK_EQ(source->IsExternal(), false);
567 CHECK_EQ(source->IsExternalAscii(), false); 575 CHECK_EQ(source->IsExternalAscii(), false);
568 String::Encoding encoding = String::UNKNOWN_ENCODING; 576 String::Encoding encoding = String::UNKNOWN_ENCODING;
569 CHECK_EQ(NULL, source->GetExternalStringResourceBase(&encoding)); 577 CHECK_EQ(NULL, source->GetExternalStringResourceBase(&encoding));
570 CHECK_EQ(String::ASCII_ENCODING, encoding); 578 CHECK_EQ(String::ASCII_ENCODING, encoding);
571 bool success = source->MakeExternal(new TestResource(two_byte_source, 579 bool success = source->MakeExternal(new TestResource(two_byte_source,
572 &dispose_count)); 580 &dispose_count));
573 CHECK(success); 581 CHECK(success);
574 Local<Script> script = Script::Compile(source); 582 Local<Script> script = Script::Compile(source);
575 Local<Value> value = script->Run(); 583 Local<Value> value = script->Run();
576 CHECK(value->IsNumber()); 584 CHECK(value->IsNumber());
577 CHECK_EQ(7, value->Int32Value()); 585 CHECK_EQ(7, value->Int32Value());
578 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 586 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
579 CHECK_EQ(0, dispose_count); 587 CHECK_EQ(0, dispose_count);
580 } 588 }
581 i::Isolate::Current()->compilation_cache()->Clear(); 589 CcTest::i_isolate()->compilation_cache()->Clear();
582 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 590 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
583 CHECK_EQ(1, dispose_count); 591 CHECK_EQ(1, dispose_count);
584 } 592 }
585 593
586 594
587 THREADED_TEST(ScriptMakingExternalAsciiString) { 595 THREADED_TEST(ScriptMakingExternalAsciiString) {
588 int dispose_count = 0; 596 int dispose_count = 0;
589 const char* c_source = "1 + 2 * 3"; 597 const char* c_source = "1 + 2 * 3";
590 { 598 {
591 LocalContext env; 599 LocalContext env;
592 v8::HandleScope scope(env->GetIsolate()); 600 v8::HandleScope scope(env->GetIsolate());
593 Local<String> source = v8_str(c_source); 601 Local<String> source = v8_str(c_source);
594 // Trigger GCs so that the newly allocated string moves to old gen. 602 // Trigger GCs so that the newly allocated string moves to old gen.
595 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now 603 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now
596 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now 604 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
597 bool success = source->MakeExternal( 605 bool success = source->MakeExternal(
598 new TestAsciiResource(i::StrDup(c_source), &dispose_count)); 606 new TestAsciiResource(i::StrDup(c_source), &dispose_count));
599 CHECK(success); 607 CHECK(success);
600 Local<Script> script = Script::Compile(source); 608 Local<Script> script = Script::Compile(source);
601 Local<Value> value = script->Run(); 609 Local<Value> value = script->Run();
602 CHECK(value->IsNumber()); 610 CHECK(value->IsNumber());
603 CHECK_EQ(7, value->Int32Value()); 611 CHECK_EQ(7, value->Int32Value());
604 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 612 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
605 CHECK_EQ(0, dispose_count); 613 CHECK_EQ(0, dispose_count);
606 } 614 }
607 i::Isolate::Current()->compilation_cache()->Clear(); 615 CcTest::i_isolate()->compilation_cache()->Clear();
608 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 616 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
609 CHECK_EQ(1, dispose_count); 617 CHECK_EQ(1, dispose_count);
610 } 618 }
611 619
612 620
613 TEST(MakingExternalStringConditions) { 621 TEST(MakingExternalStringConditions) {
614 LocalContext env; 622 LocalContext env;
615 v8::HandleScope scope(env->GetIsolate()); 623 v8::HandleScope scope(env->GetIsolate());
616 624
617 // Free some space in the new space so that we can check freshness. 625 // Free some space in the new space so that we can check freshness.
618 HEAP->CollectGarbage(i::NEW_SPACE); 626 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
619 HEAP->CollectGarbage(i::NEW_SPACE); 627 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
620 628
621 uint16_t* two_byte_string = AsciiToTwoByteString("s1"); 629 uint16_t* two_byte_string = AsciiToTwoByteString("s1");
622 Local<String> small_string = String::New(two_byte_string); 630 Local<String> small_string = String::New(two_byte_string);
623 i::DeleteArray(two_byte_string); 631 i::DeleteArray(two_byte_string);
624 632
625 // We should refuse to externalize newly created small string. 633 // We should refuse to externalize newly created small string.
626 CHECK(!small_string->CanMakeExternal()); 634 CHECK(!small_string->CanMakeExternal());
627 // Trigger GCs so that the newly allocated string moves to old gen. 635 // Trigger GCs so that the newly allocated string moves to old gen.
628 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now 636 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now
629 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now 637 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
630 // Old space strings should be accepted. 638 // Old space strings should be accepted.
631 CHECK(small_string->CanMakeExternal()); 639 CHECK(small_string->CanMakeExternal());
632 640
633 two_byte_string = AsciiToTwoByteString("small string 2"); 641 two_byte_string = AsciiToTwoByteString("small string 2");
634 small_string = String::New(two_byte_string); 642 small_string = String::New(two_byte_string);
635 i::DeleteArray(two_byte_string); 643 i::DeleteArray(two_byte_string);
636 644
637 // We should refuse externalizing newly created small string. 645 // We should refuse externalizing newly created small string.
638 CHECK(!small_string->CanMakeExternal()); 646 CHECK(!small_string->CanMakeExternal());
639 for (int i = 0; i < 100; i++) { 647 for (int i = 0; i < 100; i++) {
(...skipping 14 matching lines...) Expand all
654 // Large strings should be immediately accepted. 662 // Large strings should be immediately accepted.
655 CHECK(large_string->CanMakeExternal()); 663 CHECK(large_string->CanMakeExternal());
656 } 664 }
657 665
658 666
659 TEST(MakingExternalAsciiStringConditions) { 667 TEST(MakingExternalAsciiStringConditions) {
660 LocalContext env; 668 LocalContext env;
661 v8::HandleScope scope(env->GetIsolate()); 669 v8::HandleScope scope(env->GetIsolate());
662 670
663 // Free some space in the new space so that we can check freshness. 671 // Free some space in the new space so that we can check freshness.
664 HEAP->CollectGarbage(i::NEW_SPACE); 672 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
665 HEAP->CollectGarbage(i::NEW_SPACE); 673 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
666 674
667 Local<String> small_string = String::New("s1"); 675 Local<String> small_string = String::New("s1");
668 // We should refuse to externalize newly created small string. 676 // We should refuse to externalize newly created small string.
669 CHECK(!small_string->CanMakeExternal()); 677 CHECK(!small_string->CanMakeExternal());
670 // Trigger GCs so that the newly allocated string moves to old gen. 678 // Trigger GCs so that the newly allocated string moves to old gen.
671 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now 679 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now
672 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now 680 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
673 // Old space strings should be accepted. 681 // Old space strings should be accepted.
674 CHECK(small_string->CanMakeExternal()); 682 CHECK(small_string->CanMakeExternal());
675 683
676 small_string = String::New("small string 2"); 684 small_string = String::New("small string 2");
677 // We should refuse externalizing newly created small string. 685 // We should refuse externalizing newly created small string.
678 CHECK(!small_string->CanMakeExternal()); 686 CHECK(!small_string->CanMakeExternal());
679 for (int i = 0; i < 100; i++) { 687 for (int i = 0; i < 100; i++) {
680 String::Value value(small_string); 688 String::Value value(small_string);
681 } 689 }
682 // Frequently used strings should be accepted. 690 // Frequently used strings should be accepted.
(...skipping 17 matching lines...) Expand all
700 CompileRun("function cons(a, b) { return a + b; }" 708 CompileRun("function cons(a, b) { return a + b; }"
701 "function slice(a) { return a.substring(1); }"); 709 "function slice(a) { return a.substring(1); }");
702 // Create a cons string that will land in old pointer space. 710 // Create a cons string that will land in old pointer space.
703 Local<String> cons = Local<String>::Cast(CompileRun( 711 Local<String> cons = Local<String>::Cast(CompileRun(
704 "cons('abcdefghijklm', 'nopqrstuvwxyz');")); 712 "cons('abcdefghijklm', 'nopqrstuvwxyz');"));
705 // Create a sliced string that will land in old pointer space. 713 // Create a sliced string that will land in old pointer space.
706 Local<String> slice = Local<String>::Cast(CompileRun( 714 Local<String> slice = Local<String>::Cast(CompileRun(
707 "slice('abcdefghijklmnopqrstuvwxyz');")); 715 "slice('abcdefghijklmnopqrstuvwxyz');"));
708 716
709 // Trigger GCs so that the newly allocated string moves to old gen. 717 // Trigger GCs so that the newly allocated string moves to old gen.
710 SimulateFullSpace(HEAP->old_pointer_space()); 718 SimulateFullSpace(CcTest::heap()->old_pointer_space());
711 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now 719 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now
712 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now 720 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
713 721
714 // Turn into external string with unaligned resource data. 722 // Turn into external string with unaligned resource data.
715 int dispose_count = 0; 723 int dispose_count = 0;
716 const char* c_cons = "_abcdefghijklmnopqrstuvwxyz"; 724 const char* c_cons = "_abcdefghijklmnopqrstuvwxyz";
717 bool success = cons->MakeExternal( 725 bool success = cons->MakeExternal(
718 new TestAsciiResource(i::StrDup(c_cons) + 1, &dispose_count)); 726 new TestAsciiResource(i::StrDup(c_cons) + 1, &dispose_count));
719 CHECK(success); 727 CHECK(success);
720 const char* c_slice = "_bcdefghijklmnopqrstuvwxyz"; 728 const char* c_slice = "_bcdefghijklmnopqrstuvwxyz";
721 success = slice->MakeExternal( 729 success = slice->MakeExternal(
722 new TestAsciiResource(i::StrDup(c_slice) + 1, &dispose_count)); 730 new TestAsciiResource(i::StrDup(c_slice) + 1, &dispose_count));
723 CHECK(success); 731 CHECK(success);
724 732
725 // Trigger GCs and force evacuation. 733 // Trigger GCs and force evacuation.
726 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 734 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
727 HEAP->CollectAllGarbage(i::Heap::kReduceMemoryFootprintMask); 735 CcTest::heap()->CollectAllGarbage(i::Heap::kReduceMemoryFootprintMask);
728 } 736 }
729 737
730 738
731 THREADED_TEST(UsingExternalString) { 739 THREADED_TEST(UsingExternalString) {
732 i::Factory* factory = i::Isolate::Current()->factory(); 740 i::Factory* factory = CcTest::i_isolate()->factory();
733 { 741 {
734 v8::HandleScope scope(v8::Isolate::GetCurrent()); 742 v8::HandleScope scope(CcTest::isolate());
735 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); 743 uint16_t* two_byte_string = AsciiToTwoByteString("test string");
736 Local<String> string = 744 Local<String> string =
737 String::NewExternal(new TestResource(two_byte_string)); 745 String::NewExternal(new TestResource(two_byte_string));
738 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); 746 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string);
739 // Trigger GCs so that the newly allocated string moves to old gen. 747 // Trigger GCs so that the newly allocated string moves to old gen.
740 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now 748 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now
741 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now 749 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
742 i::Handle<i::String> isymbol = 750 i::Handle<i::String> isymbol =
743 factory->InternalizedStringFromString(istring); 751 factory->InternalizedStringFromString(istring);
744 CHECK(isymbol->IsInternalizedString()); 752 CHECK(isymbol->IsInternalizedString());
745 } 753 }
746 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 754 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
747 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 755 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
748 } 756 }
749 757
750 758
751 THREADED_TEST(UsingExternalAsciiString) { 759 THREADED_TEST(UsingExternalAsciiString) {
752 i::Factory* factory = i::Isolate::Current()->factory(); 760 i::Factory* factory = CcTest::i_isolate()->factory();
753 { 761 {
754 v8::HandleScope scope(v8::Isolate::GetCurrent()); 762 v8::HandleScope scope(CcTest::isolate());
755 const char* one_byte_string = "test string"; 763 const char* one_byte_string = "test string";
756 Local<String> string = String::NewExternal( 764 Local<String> string = String::NewExternal(
757 new TestAsciiResource(i::StrDup(one_byte_string))); 765 new TestAsciiResource(i::StrDup(one_byte_string)));
758 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); 766 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string);
759 // Trigger GCs so that the newly allocated string moves to old gen. 767 // Trigger GCs so that the newly allocated string moves to old gen.
760 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now 768 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now
761 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now 769 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
762 i::Handle<i::String> isymbol = 770 i::Handle<i::String> isymbol =
763 factory->InternalizedStringFromString(istring); 771 factory->InternalizedStringFromString(istring);
764 CHECK(isymbol->IsInternalizedString()); 772 CHECK(isymbol->IsInternalizedString());
765 } 773 }
766 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 774 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
767 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 775 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
768 } 776 }
769 777
770 778
771 THREADED_TEST(ScavengeExternalString) { 779 THREADED_TEST(ScavengeExternalString) {
772 i::FLAG_stress_compaction = false; 780 i::FLAG_stress_compaction = false;
773 i::FLAG_gc_global = false; 781 i::FLAG_gc_global = false;
774 int dispose_count = 0; 782 int dispose_count = 0;
775 bool in_new_space = false; 783 bool in_new_space = false;
776 { 784 {
777 v8::HandleScope scope(v8::Isolate::GetCurrent()); 785 v8::HandleScope scope(CcTest::isolate());
778 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); 786 uint16_t* two_byte_string = AsciiToTwoByteString("test string");
779 Local<String> string = 787 Local<String> string =
780 String::NewExternal(new TestResource(two_byte_string, 788 String::NewExternal(new TestResource(two_byte_string,
781 &dispose_count)); 789 &dispose_count));
782 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); 790 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string);
783 HEAP->CollectGarbage(i::NEW_SPACE); 791 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
784 in_new_space = HEAP->InNewSpace(*istring); 792 in_new_space = CcTest::heap()->InNewSpace(*istring);
785 CHECK(in_new_space || HEAP->old_data_space()->Contains(*istring)); 793 CHECK(in_new_space || CcTest::heap()->old_data_space()->Contains(*istring));
786 CHECK_EQ(0, dispose_count); 794 CHECK_EQ(0, dispose_count);
787 } 795 }
788 HEAP->CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_DATA_SPACE); 796 CcTest::heap()->CollectGarbage(
797 in_new_space ? i::NEW_SPACE : i::OLD_DATA_SPACE);
789 CHECK_EQ(1, dispose_count); 798 CHECK_EQ(1, dispose_count);
790 } 799 }
791 800
792 801
793 THREADED_TEST(ScavengeExternalAsciiString) { 802 THREADED_TEST(ScavengeExternalAsciiString) {
794 i::FLAG_stress_compaction = false; 803 i::FLAG_stress_compaction = false;
795 i::FLAG_gc_global = false; 804 i::FLAG_gc_global = false;
796 int dispose_count = 0; 805 int dispose_count = 0;
797 bool in_new_space = false; 806 bool in_new_space = false;
798 { 807 {
799 v8::HandleScope scope(v8::Isolate::GetCurrent()); 808 v8::HandleScope scope(CcTest::isolate());
800 const char* one_byte_string = "test string"; 809 const char* one_byte_string = "test string";
801 Local<String> string = String::NewExternal( 810 Local<String> string = String::NewExternal(
802 new TestAsciiResource(i::StrDup(one_byte_string), &dispose_count)); 811 new TestAsciiResource(i::StrDup(one_byte_string), &dispose_count));
803 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); 812 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string);
804 HEAP->CollectGarbage(i::NEW_SPACE); 813 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
805 in_new_space = HEAP->InNewSpace(*istring); 814 in_new_space = CcTest::heap()->InNewSpace(*istring);
806 CHECK(in_new_space || HEAP->old_data_space()->Contains(*istring)); 815 CHECK(in_new_space || CcTest::heap()->old_data_space()->Contains(*istring));
807 CHECK_EQ(0, dispose_count); 816 CHECK_EQ(0, dispose_count);
808 } 817 }
809 HEAP->CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_DATA_SPACE); 818 CcTest::heap()->CollectGarbage(
819 in_new_space ? i::NEW_SPACE : i::OLD_DATA_SPACE);
810 CHECK_EQ(1, dispose_count); 820 CHECK_EQ(1, dispose_count);
811 } 821 }
812 822
813 823
814 class TestAsciiResourceWithDisposeControl: public TestAsciiResource { 824 class TestAsciiResourceWithDisposeControl: public TestAsciiResource {
815 public: 825 public:
816 // Only used by non-threaded tests, so it can use static fields. 826 // Only used by non-threaded tests, so it can use static fields.
817 static int dispose_calls; 827 static int dispose_calls;
818 static int dispose_count; 828 static int dispose_count;
819 829
(...skipping 22 matching lines...) Expand all
842 TestAsciiResourceWithDisposeControl::dispose_calls = 0; 852 TestAsciiResourceWithDisposeControl::dispose_calls = 0;
843 TestAsciiResourceWithDisposeControl res_stack(i::StrDup(c_source), false); 853 TestAsciiResourceWithDisposeControl res_stack(i::StrDup(c_source), false);
844 { 854 {
845 LocalContext env; 855 LocalContext env;
846 v8::HandleScope scope(env->GetIsolate()); 856 v8::HandleScope scope(env->GetIsolate());
847 Local<String> source = String::NewExternal(&res_stack); 857 Local<String> source = String::NewExternal(&res_stack);
848 Local<Script> script = Script::Compile(source); 858 Local<Script> script = Script::Compile(source);
849 Local<Value> value = script->Run(); 859 Local<Value> value = script->Run();
850 CHECK(value->IsNumber()); 860 CHECK(value->IsNumber());
851 CHECK_EQ(7, value->Int32Value()); 861 CHECK_EQ(7, value->Int32Value());
852 HEAP->CollectAllAvailableGarbage(); 862 CcTest::heap()->CollectAllAvailableGarbage();
853 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count); 863 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count);
854 } 864 }
855 i::Isolate::Current()->compilation_cache()->Clear(); 865 CcTest::i_isolate()->compilation_cache()->Clear();
856 HEAP->CollectAllAvailableGarbage(); 866 CcTest::heap()->CollectAllAvailableGarbage();
857 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls); 867 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls);
858 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count); 868 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count);
859 869
860 // Use a heap allocated external string resource allocated object. 870 // Use a heap allocated external string resource allocated object.
861 TestAsciiResourceWithDisposeControl::dispose_count = 0; 871 TestAsciiResourceWithDisposeControl::dispose_count = 0;
862 TestAsciiResourceWithDisposeControl::dispose_calls = 0; 872 TestAsciiResourceWithDisposeControl::dispose_calls = 0;
863 TestAsciiResource* res_heap = 873 TestAsciiResource* res_heap =
864 new TestAsciiResourceWithDisposeControl(i::StrDup(c_source), true); 874 new TestAsciiResourceWithDisposeControl(i::StrDup(c_source), true);
865 { 875 {
866 LocalContext env; 876 LocalContext env;
867 v8::HandleScope scope(env->GetIsolate()); 877 v8::HandleScope scope(env->GetIsolate());
868 Local<String> source = String::NewExternal(res_heap); 878 Local<String> source = String::NewExternal(res_heap);
869 Local<Script> script = Script::Compile(source); 879 Local<Script> script = Script::Compile(source);
870 Local<Value> value = script->Run(); 880 Local<Value> value = script->Run();
871 CHECK(value->IsNumber()); 881 CHECK(value->IsNumber());
872 CHECK_EQ(7, value->Int32Value()); 882 CHECK_EQ(7, value->Int32Value());
873 HEAP->CollectAllAvailableGarbage(); 883 CcTest::heap()->CollectAllAvailableGarbage();
874 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count); 884 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count);
875 } 885 }
876 i::Isolate::Current()->compilation_cache()->Clear(); 886 CcTest::i_isolate()->compilation_cache()->Clear();
877 HEAP->CollectAllAvailableGarbage(); 887 CcTest::heap()->CollectAllAvailableGarbage();
878 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls); 888 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls);
879 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_count); 889 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_count);
880 } 890 }
881 891
882 892
883 THREADED_TEST(StringConcat) { 893 THREADED_TEST(StringConcat) {
884 { 894 {
885 LocalContext env; 895 LocalContext env;
886 v8::HandleScope scope(env->GetIsolate()); 896 v8::HandleScope scope(env->GetIsolate());
887 const char* one_byte_string_1 = "function a_times_t"; 897 const char* one_byte_string_1 = "function a_times_t";
(...skipping 25 matching lines...) Expand all
913 923
914 source = String::Concat(source, right); 924 source = String::Concat(source, right);
915 right = String::NewExternal( 925 right = String::NewExternal(
916 new TestResource(AsciiToTwoByteString(two_byte_extern_2))); 926 new TestResource(AsciiToTwoByteString(two_byte_extern_2)));
917 source = String::Concat(source, right); 927 source = String::Concat(source, right);
918 Local<Script> script = Script::Compile(source); 928 Local<Script> script = Script::Compile(source);
919 Local<Value> value = script->Run(); 929 Local<Value> value = script->Run();
920 CHECK(value->IsNumber()); 930 CHECK(value->IsNumber());
921 CHECK_EQ(68, value->Int32Value()); 931 CHECK_EQ(68, value->Int32Value());
922 } 932 }
923 i::Isolate::Current()->compilation_cache()->Clear(); 933 CcTest::i_isolate()->compilation_cache()->Clear();
924 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 934 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
925 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 935 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
926 } 936 }
927 937
928 938
929 THREADED_TEST(GlobalProperties) { 939 THREADED_TEST(GlobalProperties) {
930 LocalContext env; 940 LocalContext env;
931 v8::HandleScope scope(env->GetIsolate()); 941 v8::HandleScope scope(env->GetIsolate());
932 v8::Handle<v8::Object> global = env->Global(); 942 v8::Handle<v8::Object> global = env->Global();
933 global->Set(v8_str("pi"), v8_num(3.1415926)); 943 global->Set(v8_str("pi"), v8_num(3.1415926));
934 Local<Value> pi = global->Get(v8_str("pi")); 944 Local<Value> pi = global->Get(v8_str("pi"));
935 CHECK_EQ(3.1415926, pi->NumberValue()); 945 CHECK_EQ(3.1415926, pi->NumberValue());
936 } 946 }
937 947
938 948
939 template<typename T> 949 template<typename T>
940 static void CheckReturnValue(const T& t, i::Address callback) { 950 static void CheckReturnValue(const T& t, i::Address callback) {
941 v8::ReturnValue<v8::Value> rv = t.GetReturnValue(); 951 v8::ReturnValue<v8::Value> rv = t.GetReturnValue();
942 i::Object** o = *reinterpret_cast<i::Object***>(&rv); 952 i::Object** o = *reinterpret_cast<i::Object***>(&rv);
943 CHECK_EQ(v8::Isolate::GetCurrent(), t.GetIsolate()); 953 CHECK_EQ(CcTest::isolate(), t.GetIsolate());
944 CHECK_EQ(t.GetIsolate(), rv.GetIsolate()); 954 CHECK_EQ(t.GetIsolate(), rv.GetIsolate());
945 CHECK((*o)->IsTheHole() || (*o)->IsUndefined()); 955 CHECK((*o)->IsTheHole() || (*o)->IsUndefined());
946 // Verify reset 956 // Verify reset
947 bool is_runtime = (*o)->IsTheHole(); 957 bool is_runtime = (*o)->IsTheHole();
948 rv.Set(true); 958 rv.Set(true);
949 CHECK(!(*o)->IsTheHole() && !(*o)->IsUndefined()); 959 CHECK(!(*o)->IsTheHole() && !(*o)->IsUndefined());
950 rv.Set(v8::Handle<v8::Object>()); 960 rv.Set(v8::Handle<v8::Object>());
951 CHECK((*o)->IsTheHole() || (*o)->IsUndefined()); 961 CHECK((*o)->IsTheHole() || (*o)->IsUndefined());
952 CHECK_EQ(is_runtime, (*o)->IsTheHole()); 962 CHECK_EQ(is_runtime, (*o)->IsTheHole());
953 963
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 v8::FunctionCallback callback = &FastReturnValueCallback<T>; 1195 v8::FunctionCallback callback = &FastReturnValueCallback<T>;
1186 object_template->Set("callback", v8::FunctionTemplate::New(callback)); 1196 object_template->Set("callback", v8::FunctionTemplate::New(callback));
1187 v8::Local<v8::Object> object = object_template->NewInstance(); 1197 v8::Local<v8::Object> object = object_template->NewInstance();
1188 (*env)->Global()->Set(v8_str("callback_object"), object); 1198 (*env)->Global()->Set(v8_str("callback_object"), object);
1189 return scope.Close(CompileRun("callback_object.callback()")); 1199 return scope.Close(CompileRun("callback_object.callback()"));
1190 } 1200 }
1191 1201
1192 1202
1193 THREADED_PROFILED_TEST(FastReturnValues) { 1203 THREADED_PROFILED_TEST(FastReturnValues) {
1194 LocalContext env; 1204 LocalContext env;
1195 v8::HandleScope scope(v8::Isolate::GetCurrent()); 1205 v8::HandleScope scope(CcTest::isolate());
1196 v8::Handle<v8::Value> value; 1206 v8::Handle<v8::Value> value;
1197 // check int32_t and uint32_t 1207 // check int32_t and uint32_t
1198 int32_t int_values[] = { 1208 int32_t int_values[] = {
1199 0, 234, -723, 1209 0, 234, -723,
1200 i::Smi::kMinValue, i::Smi::kMaxValue 1210 i::Smi::kMinValue, i::Smi::kMaxValue
1201 }; 1211 };
1202 for (size_t i = 0; i < ARRAY_SIZE(int_values); i++) { 1212 for (size_t i = 0; i < ARRAY_SIZE(int_values); i++) {
1203 for (int modifier = -1; modifier <= 1; modifier++) { 1213 for (int modifier = -1; modifier <= 1; modifier++) {
1204 int int_value = int_values[i] + modifier; 1214 int int_value = int_values[i] + modifier;
1205 // check int32_t 1215 // check int32_t
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 CHECK_EQ(derived_instance2, 1415 CHECK_EQ(derived_instance2,
1406 other_instance->FindInstanceInPrototypeChain(derived)); 1416 other_instance->FindInstanceInPrototypeChain(derived));
1407 CHECK_EQ(other_instance, 1417 CHECK_EQ(other_instance,
1408 other_instance->FindInstanceInPrototypeChain(other)); 1418 other_instance->FindInstanceInPrototypeChain(other));
1409 } 1419 }
1410 1420
1411 1421
1412 THREADED_TEST(TinyInteger) { 1422 THREADED_TEST(TinyInteger) {
1413 LocalContext env; 1423 LocalContext env;
1414 v8::HandleScope scope(env->GetIsolate()); 1424 v8::HandleScope scope(env->GetIsolate());
1415 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 1425 v8::Isolate* isolate = CcTest::isolate();
1416 1426
1417 int32_t value = 239; 1427 int32_t value = 239;
1418 Local<v8::Integer> value_obj = v8::Integer::New(value); 1428 Local<v8::Integer> value_obj = v8::Integer::New(value);
1419 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1429 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1420 1430
1421 value_obj = v8::Integer::New(value, isolate); 1431 value_obj = v8::Integer::New(value, isolate);
1422 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1432 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1423 } 1433 }
1424 1434
1425 1435
1426 THREADED_TEST(BigSmiInteger) { 1436 THREADED_TEST(BigSmiInteger) {
1427 LocalContext env; 1437 LocalContext env;
1428 v8::HandleScope scope(env->GetIsolate()); 1438 v8::HandleScope scope(env->GetIsolate());
1429 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 1439 v8::Isolate* isolate = CcTest::isolate();
1430 1440
1431 int32_t value = i::Smi::kMaxValue; 1441 int32_t value = i::Smi::kMaxValue;
1432 // We cannot add one to a Smi::kMaxValue without wrapping. 1442 // We cannot add one to a Smi::kMaxValue without wrapping.
1433 if (i::SmiValuesAre31Bits()) { 1443 if (i::SmiValuesAre31Bits()) {
1434 CHECK(i::Smi::IsValid(value)); 1444 CHECK(i::Smi::IsValid(value));
1435 CHECK(!i::Smi::IsValid(value + 1)); 1445 CHECK(!i::Smi::IsValid(value + 1));
1436 1446
1437 Local<v8::Integer> value_obj = v8::Integer::New(value); 1447 Local<v8::Integer> value_obj = v8::Integer::New(value);
1438 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1448 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1439 1449
1440 value_obj = v8::Integer::New(value, isolate); 1450 value_obj = v8::Integer::New(value, isolate);
1441 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1451 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1442 } 1452 }
1443 } 1453 }
1444 1454
1445 1455
1446 THREADED_TEST(BigInteger) { 1456 THREADED_TEST(BigInteger) {
1447 LocalContext env; 1457 LocalContext env;
1448 v8::HandleScope scope(env->GetIsolate()); 1458 v8::HandleScope scope(env->GetIsolate());
1449 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 1459 v8::Isolate* isolate = CcTest::isolate();
1450 1460
1451 // We cannot add one to a Smi::kMaxValue without wrapping. 1461 // We cannot add one to a Smi::kMaxValue without wrapping.
1452 if (i::SmiValuesAre31Bits()) { 1462 if (i::SmiValuesAre31Bits()) {
1453 // The casts allow this to compile, even if Smi::kMaxValue is 2^31-1. 1463 // The casts allow this to compile, even if Smi::kMaxValue is 2^31-1.
1454 // The code will not be run in that case, due to the "if" guard. 1464 // The code will not be run in that case, due to the "if" guard.
1455 int32_t value = 1465 int32_t value =
1456 static_cast<int32_t>(static_cast<uint32_t>(i::Smi::kMaxValue) + 1); 1466 static_cast<int32_t>(static_cast<uint32_t>(i::Smi::kMaxValue) + 1);
1457 CHECK(value > i::Smi::kMaxValue); 1467 CHECK(value > i::Smi::kMaxValue);
1458 CHECK(!i::Smi::IsValid(value)); 1468 CHECK(!i::Smi::IsValid(value));
1459 1469
1460 Local<v8::Integer> value_obj = v8::Integer::New(value); 1470 Local<v8::Integer> value_obj = v8::Integer::New(value);
1461 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1471 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1462 1472
1463 value_obj = v8::Integer::New(value, isolate); 1473 value_obj = v8::Integer::New(value, isolate);
1464 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1474 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1465 } 1475 }
1466 } 1476 }
1467 1477
1468 1478
1469 THREADED_TEST(TinyUnsignedInteger) { 1479 THREADED_TEST(TinyUnsignedInteger) {
1470 LocalContext env; 1480 LocalContext env;
1471 v8::HandleScope scope(env->GetIsolate()); 1481 v8::HandleScope scope(env->GetIsolate());
1472 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 1482 v8::Isolate* isolate = CcTest::isolate();
1473 1483
1474 uint32_t value = 239; 1484 uint32_t value = 239;
1475 1485
1476 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value); 1486 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value);
1477 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1487 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1478 1488
1479 value_obj = v8::Integer::NewFromUnsigned(value, isolate); 1489 value_obj = v8::Integer::NewFromUnsigned(value, isolate);
1480 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1490 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1481 } 1491 }
1482 1492
1483 1493
1484 THREADED_TEST(BigUnsignedSmiInteger) { 1494 THREADED_TEST(BigUnsignedSmiInteger) {
1485 LocalContext env; 1495 LocalContext env;
1486 v8::HandleScope scope(env->GetIsolate()); 1496 v8::HandleScope scope(env->GetIsolate());
1487 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 1497 v8::Isolate* isolate = CcTest::isolate();
1488 1498
1489 uint32_t value = static_cast<uint32_t>(i::Smi::kMaxValue); 1499 uint32_t value = static_cast<uint32_t>(i::Smi::kMaxValue);
1490 CHECK(i::Smi::IsValid(value)); 1500 CHECK(i::Smi::IsValid(value));
1491 CHECK(!i::Smi::IsValid(value + 1)); 1501 CHECK(!i::Smi::IsValid(value + 1));
1492 1502
1493 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value); 1503 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value);
1494 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1504 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1495 1505
1496 value_obj = v8::Integer::NewFromUnsigned(value, isolate); 1506 value_obj = v8::Integer::NewFromUnsigned(value, isolate);
1497 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1507 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1498 } 1508 }
1499 1509
1500 1510
1501 THREADED_TEST(BigUnsignedInteger) { 1511 THREADED_TEST(BigUnsignedInteger) {
1502 LocalContext env; 1512 LocalContext env;
1503 v8::HandleScope scope(env->GetIsolate()); 1513 v8::HandleScope scope(env->GetIsolate());
1504 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 1514 v8::Isolate* isolate = CcTest::isolate();
1505 1515
1506 uint32_t value = static_cast<uint32_t>(i::Smi::kMaxValue) + 1; 1516 uint32_t value = static_cast<uint32_t>(i::Smi::kMaxValue) + 1;
1507 CHECK(value > static_cast<uint32_t>(i::Smi::kMaxValue)); 1517 CHECK(value > static_cast<uint32_t>(i::Smi::kMaxValue));
1508 CHECK(!i::Smi::IsValid(value)); 1518 CHECK(!i::Smi::IsValid(value));
1509 1519
1510 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value); 1520 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value);
1511 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1521 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1512 1522
1513 value_obj = v8::Integer::NewFromUnsigned(value, isolate); 1523 value_obj = v8::Integer::NewFromUnsigned(value, isolate);
1514 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1524 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1515 } 1525 }
1516 1526
1517 1527
1518 THREADED_TEST(OutOfSignedRangeUnsignedInteger) { 1528 THREADED_TEST(OutOfSignedRangeUnsignedInteger) {
1519 LocalContext env; 1529 LocalContext env;
1520 v8::HandleScope scope(env->GetIsolate()); 1530 v8::HandleScope scope(env->GetIsolate());
1521 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 1531 v8::Isolate* isolate = CcTest::isolate();
1522 1532
1523 uint32_t INT32_MAX_AS_UINT = (1U << 31) - 1; 1533 uint32_t INT32_MAX_AS_UINT = (1U << 31) - 1;
1524 uint32_t value = INT32_MAX_AS_UINT + 1; 1534 uint32_t value = INT32_MAX_AS_UINT + 1;
1525 CHECK(value > INT32_MAX_AS_UINT); // No overflow. 1535 CHECK(value > INT32_MAX_AS_UINT); // No overflow.
1526 1536
1527 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value); 1537 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value);
1528 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1538 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1529 1539
1530 value_obj = v8::Integer::NewFromUnsigned(value, isolate); 1540 value_obj = v8::Integer::NewFromUnsigned(value, isolate);
1531 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1541 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1730 1740
1731 1741
1732 static void GetM(Local<String> name, 1742 static void GetM(Local<String> name,
1733 const v8::PropertyCallbackInfo<v8::Value>& info) { 1743 const v8::PropertyCallbackInfo<v8::Value>& info) {
1734 ApiTestFuzzer::Fuzz(); 1744 ApiTestFuzzer::Fuzz();
1735 info.GetReturnValue().Set(v8_num(876)); 1745 info.GetReturnValue().Set(v8_num(876));
1736 } 1746 }
1737 1747
1738 1748
1739 THREADED_TEST(GlobalPrototype) { 1749 THREADED_TEST(GlobalPrototype) {
1740 v8::HandleScope scope(v8::Isolate::GetCurrent()); 1750 v8::HandleScope scope(CcTest::isolate());
1741 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New(); 1751 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New();
1742 func_templ->PrototypeTemplate()->Set( 1752 func_templ->PrototypeTemplate()->Set(
1743 "dummy", 1753 "dummy",
1744 v8::FunctionTemplate::New(DummyCallHandler)); 1754 v8::FunctionTemplate::New(DummyCallHandler));
1745 v8::Handle<ObjectTemplate> templ = func_templ->InstanceTemplate(); 1755 v8::Handle<ObjectTemplate> templ = func_templ->InstanceTemplate();
1746 templ->Set("x", v8_num(200)); 1756 templ->Set("x", v8_num(200));
1747 templ->SetAccessor(v8_str("m"), GetM); 1757 templ->SetAccessor(v8_str("m"), GetM);
1748 LocalContext env(0, templ); 1758 LocalContext env(0, templ);
1749 v8::Handle<Script> script(v8_compile("dummy()")); 1759 v8::Handle<Script> script(v8_compile("dummy()"));
1750 v8::Handle<Value> result(script->Run()); 1760 v8::Handle<Value> result(script->Run());
1751 CHECK_EQ(13.4, result->NumberValue()); 1761 CHECK_EQ(13.4, result->NumberValue());
1752 CHECK_EQ(200, v8_compile("x")->Run()->Int32Value()); 1762 CHECK_EQ(200, v8_compile("x")->Run()->Int32Value());
1753 CHECK_EQ(876, v8_compile("m")->Run()->Int32Value()); 1763 CHECK_EQ(876, v8_compile("m")->Run()->Int32Value());
1754 } 1764 }
1755 1765
1756 1766
1757 THREADED_TEST(ObjectTemplate) { 1767 THREADED_TEST(ObjectTemplate) {
1758 v8::HandleScope scope(v8::Isolate::GetCurrent()); 1768 v8::HandleScope scope(CcTest::isolate());
1759 Local<ObjectTemplate> templ1 = ObjectTemplate::New(); 1769 Local<ObjectTemplate> templ1 = ObjectTemplate::New();
1760 templ1->Set("x", v8_num(10)); 1770 templ1->Set("x", v8_num(10));
1761 templ1->Set("y", v8_num(13)); 1771 templ1->Set("y", v8_num(13));
1762 LocalContext env; 1772 LocalContext env;
1763 Local<v8::Object> instance1 = templ1->NewInstance(); 1773 Local<v8::Object> instance1 = templ1->NewInstance();
1764 env->Global()->Set(v8_str("p"), instance1); 1774 env->Global()->Set(v8_str("p"), instance1);
1765 CHECK(v8_compile("(p.x == 10)")->Run()->BooleanValue()); 1775 CHECK(v8_compile("(p.x == 10)")->Run()->BooleanValue());
1766 CHECK(v8_compile("(p.y == 13)")->Run()->BooleanValue()); 1776 CHECK(v8_compile("(p.y == 13)")->Run()->BooleanValue());
1767 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(); 1777 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New();
1768 fun->PrototypeTemplate()->Set("nirk", v8_num(123)); 1778 fun->PrototypeTemplate()->Set("nirk", v8_num(123));
(...skipping 16 matching lines...) Expand all
1785 1795
1786 1796
1787 static void GetKnurd(Local<String> property, 1797 static void GetKnurd(Local<String> property,
1788 const v8::PropertyCallbackInfo<v8::Value>& info) { 1798 const v8::PropertyCallbackInfo<v8::Value>& info) {
1789 ApiTestFuzzer::Fuzz(); 1799 ApiTestFuzzer::Fuzz();
1790 info.GetReturnValue().Set(v8_num(15.2)); 1800 info.GetReturnValue().Set(v8_num(15.2));
1791 } 1801 }
1792 1802
1793 1803
1794 THREADED_TEST(DescriptorInheritance) { 1804 THREADED_TEST(DescriptorInheritance) {
1795 v8::HandleScope scope(v8::Isolate::GetCurrent()); 1805 v8::HandleScope scope(CcTest::isolate());
1796 v8::Handle<v8::FunctionTemplate> super = v8::FunctionTemplate::New(); 1806 v8::Handle<v8::FunctionTemplate> super = v8::FunctionTemplate::New();
1797 super->PrototypeTemplate()->Set("flabby", 1807 super->PrototypeTemplate()->Set("flabby",
1798 v8::FunctionTemplate::New(GetFlabby)); 1808 v8::FunctionTemplate::New(GetFlabby));
1799 super->PrototypeTemplate()->Set("PI", v8_num(3.14)); 1809 super->PrototypeTemplate()->Set("PI", v8_num(3.14));
1800 1810
1801 super->InstanceTemplate()->SetAccessor(v8_str("knurd"), GetKnurd); 1811 super->InstanceTemplate()->SetAccessor(v8_str("knurd"), GetKnurd);
1802 1812
1803 v8::Handle<v8::FunctionTemplate> base1 = v8::FunctionTemplate::New(); 1813 v8::Handle<v8::FunctionTemplate> base1 = v8::FunctionTemplate::New();
1804 base1->Inherit(super); 1814 base1->Inherit(super);
1805 base1->PrototypeTemplate()->Set("v1", v8_num(20.1)); 1815 base1->PrototypeTemplate()->Set("v1", v8_num(20.1));
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1926 } 1936 }
1927 1937
1928 void AddInterceptor(Handle<FunctionTemplate> templ, 1938 void AddInterceptor(Handle<FunctionTemplate> templ,
1929 v8::NamedPropertyGetterCallback getter, 1939 v8::NamedPropertyGetterCallback getter,
1930 v8::NamedPropertySetterCallback setter) { 1940 v8::NamedPropertySetterCallback setter) {
1931 templ->InstanceTemplate()->SetNamedPropertyHandler(getter, setter); 1941 templ->InstanceTemplate()->SetNamedPropertyHandler(getter, setter);
1932 } 1942 }
1933 1943
1934 1944
1935 THREADED_TEST(EmptyInterceptorDoesNotShadowAccessors) { 1945 THREADED_TEST(EmptyInterceptorDoesNotShadowAccessors) {
1936 v8::HandleScope scope(v8::Isolate::GetCurrent()); 1946 v8::HandleScope scope(CcTest::isolate());
1937 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 1947 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1938 Handle<FunctionTemplate> child = FunctionTemplate::New(); 1948 Handle<FunctionTemplate> child = FunctionTemplate::New();
1939 child->Inherit(parent); 1949 child->Inherit(parent);
1940 AddAccessor(parent, v8_str("age"), 1950 AddAccessor(parent, v8_str("age"),
1941 SimpleAccessorGetter, SimpleAccessorSetter); 1951 SimpleAccessorGetter, SimpleAccessorSetter);
1942 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter); 1952 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter);
1943 LocalContext env; 1953 LocalContext env;
1944 env->Global()->Set(v8_str("Child"), child->GetFunction()); 1954 env->Global()->Set(v8_str("Child"), child->GetFunction());
1945 CompileRun("var child = new Child;" 1955 CompileRun("var child = new Child;"
1946 "child.age = 10;"); 1956 "child.age = 10;");
1947 ExpectBoolean("child.hasOwnProperty('age')", false); 1957 ExpectBoolean("child.hasOwnProperty('age')", false);
1948 ExpectInt32("child.age", 10); 1958 ExpectInt32("child.age", 10);
1949 ExpectInt32("child.accessor_age", 10); 1959 ExpectInt32("child.accessor_age", 10);
1950 } 1960 }
1951 1961
1952 1962
1953 THREADED_TEST(EmptyInterceptorDoesNotShadowJSAccessors) { 1963 THREADED_TEST(EmptyInterceptorDoesNotShadowJSAccessors) {
1954 v8::HandleScope scope(v8::Isolate::GetCurrent()); 1964 v8::HandleScope scope(CcTest::isolate());
1955 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 1965 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1956 Handle<FunctionTemplate> child = FunctionTemplate::New(); 1966 Handle<FunctionTemplate> child = FunctionTemplate::New();
1957 child->Inherit(parent); 1967 child->Inherit(parent);
1958 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter); 1968 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter);
1959 LocalContext env; 1969 LocalContext env;
1960 env->Global()->Set(v8_str("Child"), child->GetFunction()); 1970 env->Global()->Set(v8_str("Child"), child->GetFunction());
1961 CompileRun("var child = new Child;" 1971 CompileRun("var child = new Child;"
1962 "var parent = child.__proto__;" 1972 "var parent = child.__proto__;"
1963 "Object.defineProperty(parent, 'age', " 1973 "Object.defineProperty(parent, 'age', "
1964 " {get: function(){ return this.accessor_age; }, " 1974 " {get: function(){ return this.accessor_age; }, "
1965 " set: function(v){ this.accessor_age = v; }, " 1975 " set: function(v){ this.accessor_age = v; }, "
1966 " enumerable: true, configurable: true});" 1976 " enumerable: true, configurable: true});"
1967 "child.age = 10;"); 1977 "child.age = 10;");
1968 ExpectBoolean("child.hasOwnProperty('age')", false); 1978 ExpectBoolean("child.hasOwnProperty('age')", false);
1969 ExpectInt32("child.age", 10); 1979 ExpectInt32("child.age", 10);
1970 ExpectInt32("child.accessor_age", 10); 1980 ExpectInt32("child.accessor_age", 10);
1971 } 1981 }
1972 1982
1973 1983
1974 THREADED_TEST(EmptyInterceptorDoesNotAffectJSProperties) { 1984 THREADED_TEST(EmptyInterceptorDoesNotAffectJSProperties) {
1975 v8::HandleScope scope(v8::Isolate::GetCurrent()); 1985 v8::HandleScope scope(CcTest::isolate());
1976 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 1986 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1977 Handle<FunctionTemplate> child = FunctionTemplate::New(); 1987 Handle<FunctionTemplate> child = FunctionTemplate::New();
1978 child->Inherit(parent); 1988 child->Inherit(parent);
1979 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter); 1989 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter);
1980 LocalContext env; 1990 LocalContext env;
1981 env->Global()->Set(v8_str("Child"), child->GetFunction()); 1991 env->Global()->Set(v8_str("Child"), child->GetFunction());
1982 CompileRun("var child = new Child;" 1992 CompileRun("var child = new Child;"
1983 "var parent = child.__proto__;" 1993 "var parent = child.__proto__;"
1984 "parent.name = 'Alice';"); 1994 "parent.name = 'Alice';");
1985 ExpectBoolean("child.hasOwnProperty('name')", false); 1995 ExpectBoolean("child.hasOwnProperty('name')", false);
1986 ExpectString("child.name", "Alice"); 1996 ExpectString("child.name", "Alice");
1987 CompileRun("child.name = 'Bob';"); 1997 CompileRun("child.name = 'Bob';");
1988 ExpectString("child.name", "Bob"); 1998 ExpectString("child.name", "Bob");
1989 ExpectBoolean("child.hasOwnProperty('name')", true); 1999 ExpectBoolean("child.hasOwnProperty('name')", true);
1990 ExpectString("parent.name", "Alice"); 2000 ExpectString("parent.name", "Alice");
1991 } 2001 }
1992 2002
1993 2003
1994 THREADED_TEST(SwitchFromInterceptorToAccessor) { 2004 THREADED_TEST(SwitchFromInterceptorToAccessor) {
1995 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2005 v8::HandleScope scope(CcTest::isolate());
1996 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 2006 Handle<FunctionTemplate> templ = FunctionTemplate::New();
1997 AddAccessor(templ, v8_str("age"), 2007 AddAccessor(templ, v8_str("age"),
1998 SimpleAccessorGetter, SimpleAccessorSetter); 2008 SimpleAccessorGetter, SimpleAccessorSetter);
1999 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 2009 AddInterceptor(templ, InterceptorGetter, InterceptorSetter);
2000 LocalContext env; 2010 LocalContext env;
2001 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); 2011 env->Global()->Set(v8_str("Obj"), templ->GetFunction());
2002 CompileRun("var obj = new Obj;" 2012 CompileRun("var obj = new Obj;"
2003 "function setAge(i){ obj.age = i; };" 2013 "function setAge(i){ obj.age = i; };"
2004 "for(var i = 0; i <= 10000; i++) setAge(i);"); 2014 "for(var i = 0; i <= 10000; i++) setAge(i);");
2005 // All i < 10000 go to the interceptor. 2015 // All i < 10000 go to the interceptor.
2006 ExpectInt32("obj.interceptor_age", 9999); 2016 ExpectInt32("obj.interceptor_age", 9999);
2007 // The last i goes to the accessor. 2017 // The last i goes to the accessor.
2008 ExpectInt32("obj.accessor_age", 10000); 2018 ExpectInt32("obj.accessor_age", 10000);
2009 } 2019 }
2010 2020
2011 2021
2012 THREADED_TEST(SwitchFromAccessorToInterceptor) { 2022 THREADED_TEST(SwitchFromAccessorToInterceptor) {
2013 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2023 v8::HandleScope scope(CcTest::isolate());
2014 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 2024 Handle<FunctionTemplate> templ = FunctionTemplate::New();
2015 AddAccessor(templ, v8_str("age"), 2025 AddAccessor(templ, v8_str("age"),
2016 SimpleAccessorGetter, SimpleAccessorSetter); 2026 SimpleAccessorGetter, SimpleAccessorSetter);
2017 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 2027 AddInterceptor(templ, InterceptorGetter, InterceptorSetter);
2018 LocalContext env; 2028 LocalContext env;
2019 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); 2029 env->Global()->Set(v8_str("Obj"), templ->GetFunction());
2020 CompileRun("var obj = new Obj;" 2030 CompileRun("var obj = new Obj;"
2021 "function setAge(i){ obj.age = i; };" 2031 "function setAge(i){ obj.age = i; };"
2022 "for(var i = 20000; i >= 9999; i--) setAge(i);"); 2032 "for(var i = 20000; i >= 9999; i--) setAge(i);");
2023 // All i >= 10000 go to the accessor. 2033 // All i >= 10000 go to the accessor.
2024 ExpectInt32("obj.accessor_age", 10000); 2034 ExpectInt32("obj.accessor_age", 10000);
2025 // The last i goes to the interceptor. 2035 // The last i goes to the interceptor.
2026 ExpectInt32("obj.interceptor_age", 9999); 2036 ExpectInt32("obj.interceptor_age", 9999);
2027 } 2037 }
2028 2038
2029 2039
2030 THREADED_TEST(SwitchFromInterceptorToAccessorWithInheritance) { 2040 THREADED_TEST(SwitchFromInterceptorToAccessorWithInheritance) {
2031 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2041 v8::HandleScope scope(CcTest::isolate());
2032 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 2042 Handle<FunctionTemplate> parent = FunctionTemplate::New();
2033 Handle<FunctionTemplate> child = FunctionTemplate::New(); 2043 Handle<FunctionTemplate> child = FunctionTemplate::New();
2034 child->Inherit(parent); 2044 child->Inherit(parent);
2035 AddAccessor(parent, v8_str("age"), 2045 AddAccessor(parent, v8_str("age"),
2036 SimpleAccessorGetter, SimpleAccessorSetter); 2046 SimpleAccessorGetter, SimpleAccessorSetter);
2037 AddInterceptor(child, InterceptorGetter, InterceptorSetter); 2047 AddInterceptor(child, InterceptorGetter, InterceptorSetter);
2038 LocalContext env; 2048 LocalContext env;
2039 env->Global()->Set(v8_str("Child"), child->GetFunction()); 2049 env->Global()->Set(v8_str("Child"), child->GetFunction());
2040 CompileRun("var child = new Child;" 2050 CompileRun("var child = new Child;"
2041 "function setAge(i){ child.age = i; };" 2051 "function setAge(i){ child.age = i; };"
2042 "for(var i = 0; i <= 10000; i++) setAge(i);"); 2052 "for(var i = 0; i <= 10000; i++) setAge(i);");
2043 // All i < 10000 go to the interceptor. 2053 // All i < 10000 go to the interceptor.
2044 ExpectInt32("child.interceptor_age", 9999); 2054 ExpectInt32("child.interceptor_age", 9999);
2045 // The last i goes to the accessor. 2055 // The last i goes to the accessor.
2046 ExpectInt32("child.accessor_age", 10000); 2056 ExpectInt32("child.accessor_age", 10000);
2047 } 2057 }
2048 2058
2049 2059
2050 THREADED_TEST(SwitchFromAccessorToInterceptorWithInheritance) { 2060 THREADED_TEST(SwitchFromAccessorToInterceptorWithInheritance) {
2051 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2061 v8::HandleScope scope(CcTest::isolate());
2052 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 2062 Handle<FunctionTemplate> parent = FunctionTemplate::New();
2053 Handle<FunctionTemplate> child = FunctionTemplate::New(); 2063 Handle<FunctionTemplate> child = FunctionTemplate::New();
2054 child->Inherit(parent); 2064 child->Inherit(parent);
2055 AddAccessor(parent, v8_str("age"), 2065 AddAccessor(parent, v8_str("age"),
2056 SimpleAccessorGetter, SimpleAccessorSetter); 2066 SimpleAccessorGetter, SimpleAccessorSetter);
2057 AddInterceptor(child, InterceptorGetter, InterceptorSetter); 2067 AddInterceptor(child, InterceptorGetter, InterceptorSetter);
2058 LocalContext env; 2068 LocalContext env;
2059 env->Global()->Set(v8_str("Child"), child->GetFunction()); 2069 env->Global()->Set(v8_str("Child"), child->GetFunction());
2060 CompileRun("var child = new Child;" 2070 CompileRun("var child = new Child;"
2061 "function setAge(i){ child.age = i; };" 2071 "function setAge(i){ child.age = i; };"
2062 "for(var i = 20000; i >= 9999; i--) setAge(i);"); 2072 "for(var i = 20000; i >= 9999; i--) setAge(i);");
2063 // All i >= 10000 go to the accessor. 2073 // All i >= 10000 go to the accessor.
2064 ExpectInt32("child.accessor_age", 10000); 2074 ExpectInt32("child.accessor_age", 10000);
2065 // The last i goes to the interceptor. 2075 // The last i goes to the interceptor.
2066 ExpectInt32("child.interceptor_age", 9999); 2076 ExpectInt32("child.interceptor_age", 9999);
2067 } 2077 }
2068 2078
2069 2079
2070 THREADED_TEST(SwitchFromInterceptorToJSAccessor) { 2080 THREADED_TEST(SwitchFromInterceptorToJSAccessor) {
2071 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2081 v8::HandleScope scope(CcTest::isolate());
2072 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 2082 Handle<FunctionTemplate> templ = FunctionTemplate::New();
2073 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 2083 AddInterceptor(templ, InterceptorGetter, InterceptorSetter);
2074 LocalContext env; 2084 LocalContext env;
2075 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); 2085 env->Global()->Set(v8_str("Obj"), templ->GetFunction());
2076 CompileRun("var obj = new Obj;" 2086 CompileRun("var obj = new Obj;"
2077 "function setter(i) { this.accessor_age = i; };" 2087 "function setter(i) { this.accessor_age = i; };"
2078 "function getter() { return this.accessor_age; };" 2088 "function getter() { return this.accessor_age; };"
2079 "function setAge(i) { obj.age = i; };" 2089 "function setAge(i) { obj.age = i; };"
2080 "Object.defineProperty(obj, 'age', { get:getter, set:setter });" 2090 "Object.defineProperty(obj, 'age', { get:getter, set:setter });"
2081 "for(var i = 0; i <= 10000; i++) setAge(i);"); 2091 "for(var i = 0; i <= 10000; i++) setAge(i);");
2082 // All i < 10000 go to the interceptor. 2092 // All i < 10000 go to the interceptor.
2083 ExpectInt32("obj.interceptor_age", 9999); 2093 ExpectInt32("obj.interceptor_age", 9999);
2084 // The last i goes to the JavaScript accessor. 2094 // The last i goes to the JavaScript accessor.
2085 ExpectInt32("obj.accessor_age", 10000); 2095 ExpectInt32("obj.accessor_age", 10000);
2086 // The installed JavaScript getter is still intact. 2096 // The installed JavaScript getter is still intact.
2087 // This last part is a regression test for issue 1651 and relies on the fact 2097 // This last part is a regression test for issue 1651 and relies on the fact
2088 // that both interceptor and accessor are being installed on the same object. 2098 // that both interceptor and accessor are being installed on the same object.
2089 ExpectInt32("obj.age", 10000); 2099 ExpectInt32("obj.age", 10000);
2090 ExpectBoolean("obj.hasOwnProperty('age')", true); 2100 ExpectBoolean("obj.hasOwnProperty('age')", true);
2091 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value"); 2101 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value");
2092 } 2102 }
2093 2103
2094 2104
2095 THREADED_TEST(SwitchFromJSAccessorToInterceptor) { 2105 THREADED_TEST(SwitchFromJSAccessorToInterceptor) {
2096 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2106 v8::HandleScope scope(CcTest::isolate());
2097 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 2107 Handle<FunctionTemplate> templ = FunctionTemplate::New();
2098 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 2108 AddInterceptor(templ, InterceptorGetter, InterceptorSetter);
2099 LocalContext env; 2109 LocalContext env;
2100 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); 2110 env->Global()->Set(v8_str("Obj"), templ->GetFunction());
2101 CompileRun("var obj = new Obj;" 2111 CompileRun("var obj = new Obj;"
2102 "function setter(i) { this.accessor_age = i; };" 2112 "function setter(i) { this.accessor_age = i; };"
2103 "function getter() { return this.accessor_age; };" 2113 "function getter() { return this.accessor_age; };"
2104 "function setAge(i) { obj.age = i; };" 2114 "function setAge(i) { obj.age = i; };"
2105 "Object.defineProperty(obj, 'age', { get:getter, set:setter });" 2115 "Object.defineProperty(obj, 'age', { get:getter, set:setter });"
2106 "for(var i = 20000; i >= 9999; i--) setAge(i);"); 2116 "for(var i = 20000; i >= 9999; i--) setAge(i);");
2107 // All i >= 10000 go to the accessor. 2117 // All i >= 10000 go to the accessor.
2108 ExpectInt32("obj.accessor_age", 10000); 2118 ExpectInt32("obj.accessor_age", 10000);
2109 // The last i goes to the interceptor. 2119 // The last i goes to the interceptor.
2110 ExpectInt32("obj.interceptor_age", 9999); 2120 ExpectInt32("obj.interceptor_age", 9999);
2111 // The installed JavaScript getter is still intact. 2121 // The installed JavaScript getter is still intact.
2112 // This last part is a regression test for issue 1651 and relies on the fact 2122 // This last part is a regression test for issue 1651 and relies on the fact
2113 // that both interceptor and accessor are being installed on the same object. 2123 // that both interceptor and accessor are being installed on the same object.
2114 ExpectInt32("obj.age", 10000); 2124 ExpectInt32("obj.age", 10000);
2115 ExpectBoolean("obj.hasOwnProperty('age')", true); 2125 ExpectBoolean("obj.hasOwnProperty('age')", true);
2116 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value"); 2126 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value");
2117 } 2127 }
2118 2128
2119 2129
2120 THREADED_TEST(SwitchFromInterceptorToProperty) { 2130 THREADED_TEST(SwitchFromInterceptorToProperty) {
2121 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2131 v8::HandleScope scope(CcTest::isolate());
2122 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 2132 Handle<FunctionTemplate> parent = FunctionTemplate::New();
2123 Handle<FunctionTemplate> child = FunctionTemplate::New(); 2133 Handle<FunctionTemplate> child = FunctionTemplate::New();
2124 child->Inherit(parent); 2134 child->Inherit(parent);
2125 AddInterceptor(child, InterceptorGetter, InterceptorSetter); 2135 AddInterceptor(child, InterceptorGetter, InterceptorSetter);
2126 LocalContext env; 2136 LocalContext env;
2127 env->Global()->Set(v8_str("Child"), child->GetFunction()); 2137 env->Global()->Set(v8_str("Child"), child->GetFunction());
2128 CompileRun("var child = new Child;" 2138 CompileRun("var child = new Child;"
2129 "function setAge(i){ child.age = i; };" 2139 "function setAge(i){ child.age = i; };"
2130 "for(var i = 0; i <= 10000; i++) setAge(i);"); 2140 "for(var i = 0; i <= 10000; i++) setAge(i);");
2131 // All i < 10000 go to the interceptor. 2141 // All i < 10000 go to the interceptor.
2132 ExpectInt32("child.interceptor_age", 9999); 2142 ExpectInt32("child.interceptor_age", 9999);
2133 // The last i goes to child's own property. 2143 // The last i goes to child's own property.
2134 ExpectInt32("child.age", 10000); 2144 ExpectInt32("child.age", 10000);
2135 } 2145 }
2136 2146
2137 2147
2138 THREADED_TEST(SwitchFromPropertyToInterceptor) { 2148 THREADED_TEST(SwitchFromPropertyToInterceptor) {
2139 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2149 v8::HandleScope scope(CcTest::isolate());
2140 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 2150 Handle<FunctionTemplate> parent = FunctionTemplate::New();
2141 Handle<FunctionTemplate> child = FunctionTemplate::New(); 2151 Handle<FunctionTemplate> child = FunctionTemplate::New();
2142 child->Inherit(parent); 2152 child->Inherit(parent);
2143 AddInterceptor(child, InterceptorGetter, InterceptorSetter); 2153 AddInterceptor(child, InterceptorGetter, InterceptorSetter);
2144 LocalContext env; 2154 LocalContext env;
2145 env->Global()->Set(v8_str("Child"), child->GetFunction()); 2155 env->Global()->Set(v8_str("Child"), child->GetFunction());
2146 CompileRun("var child = new Child;" 2156 CompileRun("var child = new Child;"
2147 "function setAge(i){ child.age = i; };" 2157 "function setAge(i){ child.age = i; };"
2148 "for(var i = 20000; i >= 9999; i--) setAge(i);"); 2158 "for(var i = 20000; i >= 9999; i--) setAge(i);");
2149 // All i >= 10000 go to child's own property. 2159 // All i >= 10000 go to child's own property.
2150 ExpectInt32("child.age", 10000); 2160 ExpectInt32("child.age", 10000);
2151 // The last i goes to the interceptor. 2161 // The last i goes to the interceptor.
2152 ExpectInt32("child.interceptor_age", 9999); 2162 ExpectInt32("child.interceptor_age", 9999);
2153 } 2163 }
2154 2164
2155 2165
2156 THREADED_TEST(NamedPropertyHandlerGetter) { 2166 THREADED_TEST(NamedPropertyHandlerGetter) {
2157 echo_named_call_count = 0; 2167 echo_named_call_count = 0;
2158 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2168 v8::HandleScope scope(CcTest::isolate());
2159 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 2169 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
2160 templ->InstanceTemplate()->SetNamedPropertyHandler(EchoNamedProperty, 2170 templ->InstanceTemplate()->SetNamedPropertyHandler(EchoNamedProperty,
2161 0, 0, 0, 0, 2171 0, 0, 0, 0,
2162 v8_str("data")); 2172 v8_str("data"));
2163 LocalContext env; 2173 LocalContext env;
2164 env->Global()->Set(v8_str("obj"), 2174 env->Global()->Set(v8_str("obj"),
2165 templ->GetFunction()->NewInstance()); 2175 templ->GetFunction()->NewInstance());
2166 CHECK_EQ(echo_named_call_count, 0); 2176 CHECK_EQ(echo_named_call_count, 0);
2167 v8_compile("obj.x")->Run(); 2177 v8_compile("obj.x")->Run();
2168 CHECK_EQ(echo_named_call_count, 1); 2178 CHECK_EQ(echo_named_call_count, 1);
(...skipping 15 matching lines...) Expand all
2184 uint32_t index, 2194 uint32_t index,
2185 const v8::PropertyCallbackInfo<v8::Value>& info) { 2195 const v8::PropertyCallbackInfo<v8::Value>& info) {
2186 ApiTestFuzzer::Fuzz(); 2196 ApiTestFuzzer::Fuzz();
2187 CHECK_EQ(v8_num(637), info.Data()); 2197 CHECK_EQ(v8_num(637), info.Data());
2188 echo_indexed_call_count++; 2198 echo_indexed_call_count++;
2189 info.GetReturnValue().Set(v8_num(index)); 2199 info.GetReturnValue().Set(v8_num(index));
2190 } 2200 }
2191 2201
2192 2202
2193 THREADED_TEST(IndexedPropertyHandlerGetter) { 2203 THREADED_TEST(IndexedPropertyHandlerGetter) {
2194 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2204 v8::HandleScope scope(CcTest::isolate());
2195 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 2205 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
2196 templ->InstanceTemplate()->SetIndexedPropertyHandler(EchoIndexedProperty, 2206 templ->InstanceTemplate()->SetIndexedPropertyHandler(EchoIndexedProperty,
2197 0, 0, 0, 0, 2207 0, 0, 0, 0,
2198 v8_num(637)); 2208 v8_num(637));
2199 LocalContext env; 2209 LocalContext env;
2200 env->Global()->Set(v8_str("obj"), 2210 env->Global()->Set(v8_str("obj"),
2201 templ->GetFunction()->NewInstance()); 2211 templ->GetFunction()->NewInstance());
2202 Local<Script> script = v8_compile("obj[900]"); 2212 Local<Script> script = v8_compile("obj[900]");
2203 CHECK_EQ(script->Run()->Int32Value(), 900); 2213 CHECK_EQ(script->Run()->Int32Value(), 900);
2204 } 2214 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
2355 static void PrePropertyHandlerQuery( 2365 static void PrePropertyHandlerQuery(
2356 Local<String> key, 2366 Local<String> key,
2357 const v8::PropertyCallbackInfo<v8::Integer>& info) { 2367 const v8::PropertyCallbackInfo<v8::Integer>& info) {
2358 if (v8_str("pre")->Equals(key)) { 2368 if (v8_str("pre")->Equals(key)) {
2359 info.GetReturnValue().Set(static_cast<int32_t>(v8::None)); 2369 info.GetReturnValue().Set(static_cast<int32_t>(v8::None));
2360 } 2370 }
2361 } 2371 }
2362 2372
2363 2373
2364 THREADED_TEST(PrePropertyHandler) { 2374 THREADED_TEST(PrePropertyHandler) {
2365 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2375 v8::HandleScope scope(CcTest::isolate());
2366 v8::Handle<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(); 2376 v8::Handle<v8::FunctionTemplate> desc = v8::FunctionTemplate::New();
2367 desc->InstanceTemplate()->SetNamedPropertyHandler(PrePropertyHandlerGet, 2377 desc->InstanceTemplate()->SetNamedPropertyHandler(PrePropertyHandlerGet,
2368 0, 2378 0,
2369 PrePropertyHandlerQuery); 2379 PrePropertyHandlerQuery);
2370 LocalContext env(NULL, desc->InstanceTemplate()); 2380 LocalContext env(NULL, desc->InstanceTemplate());
2371 Script::Compile(v8_str( 2381 Script::Compile(v8_str(
2372 "var pre = 'Object: pre'; var on = 'Object: on';"))->Run(); 2382 "var pre = 'Object: pre'; var on = 'Object: on';"))->Run();
2373 v8::Handle<Value> result_pre = Script::Compile(v8_str("pre"))->Run(); 2383 v8::Handle<Value> result_pre = Script::Compile(v8_str("pre"))->Run();
2374 CHECK_EQ(v8_str("PrePropertyHandler: pre"), result_pre); 2384 CHECK_EQ(v8_str("PrePropertyHandler: pre"), result_pre);
2375 v8::Handle<Value> result_on = Script::Compile(v8_str("on"))->Run(); 2385 v8::Handle<Value> result_on = Script::Compile(v8_str("on"))->Run();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2412 } 2422 }
2413 args.This()->Set(v8_str("depth"), v8::Integer::New(depth + 1)); 2423 args.This()->Set(v8_str("depth"), v8::Integer::New(depth + 1));
2414 v8::Handle<Value> function = 2424 v8::Handle<Value> function =
2415 args.This()->Get(v8_str("callFunctionRecursively")); 2425 args.This()->Get(v8_str("callFunctionRecursively"));
2416 args.GetReturnValue().Set( 2426 args.GetReturnValue().Set(
2417 function.As<Function>()->Call(args.This(), 0, NULL)); 2427 function.As<Function>()->Call(args.This(), 0, NULL));
2418 } 2428 }
2419 2429
2420 2430
2421 THREADED_TEST(DeepCrossLanguageRecursion) { 2431 THREADED_TEST(DeepCrossLanguageRecursion) {
2422 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2432 v8::HandleScope scope(CcTest::isolate());
2423 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); 2433 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New();
2424 global->Set(v8_str("callScriptRecursively"), 2434 global->Set(v8_str("callScriptRecursively"),
2425 v8::FunctionTemplate::New(CallScriptRecursivelyCall)); 2435 v8::FunctionTemplate::New(CallScriptRecursivelyCall));
2426 global->Set(v8_str("callFunctionRecursively"), 2436 global->Set(v8_str("callFunctionRecursively"),
2427 v8::FunctionTemplate::New(CallFunctionRecursivelyCall)); 2437 v8::FunctionTemplate::New(CallFunctionRecursivelyCall));
2428 LocalContext env(NULL, global); 2438 LocalContext env(NULL, global);
2429 2439
2430 env->Global()->Set(v8_str("depth"), v8::Integer::New(0)); 2440 env->Global()->Set(v8_str("depth"), v8::Integer::New(0));
2431 call_recursively_script = v8_compile("callScriptRecursively()"); 2441 call_recursively_script = v8_compile("callScriptRecursively()");
2432 call_recursively_script->Run(); 2442 call_recursively_script->Run();
(...skipping 15 matching lines...) Expand all
2448 static void ThrowingPropertyHandlerSet( 2458 static void ThrowingPropertyHandlerSet(
2449 Local<String> key, 2459 Local<String> key,
2450 Local<Value>, 2460 Local<Value>,
2451 const v8::PropertyCallbackInfo<v8::Value>& info) { 2461 const v8::PropertyCallbackInfo<v8::Value>& info) {
2452 v8::ThrowException(key); 2462 v8::ThrowException(key);
2453 info.GetReturnValue().SetUndefined(); // not the same as empty handle 2463 info.GetReturnValue().SetUndefined(); // not the same as empty handle
2454 } 2464 }
2455 2465
2456 2466
2457 THREADED_TEST(CallbackExceptionRegression) { 2467 THREADED_TEST(CallbackExceptionRegression) {
2458 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2468 v8::HandleScope scope(CcTest::isolate());
2459 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 2469 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
2460 obj->SetNamedPropertyHandler(ThrowingPropertyHandlerGet, 2470 obj->SetNamedPropertyHandler(ThrowingPropertyHandlerGet,
2461 ThrowingPropertyHandlerSet); 2471 ThrowingPropertyHandlerSet);
2462 LocalContext env; 2472 LocalContext env;
2463 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 2473 env->Global()->Set(v8_str("obj"), obj->NewInstance());
2464 v8::Handle<Value> otto = Script::Compile(v8_str( 2474 v8::Handle<Value> otto = Script::Compile(v8_str(
2465 "try { with (obj) { otto; } } catch (e) { e; }"))->Run(); 2475 "try { with (obj) { otto; } } catch (e) { e; }"))->Run();
2466 CHECK_EQ(v8_str("otto"), otto); 2476 CHECK_EQ(v8_str("otto"), otto);
2467 v8::Handle<Value> netto = Script::Compile(v8_str( 2477 v8::Handle<Value> netto = Script::Compile(v8_str(
2468 "try { with (obj) { netto = 4; } } catch (e) { e; }"))->Run(); 2478 "try { with (obj) { netto = 4; } } catch (e) { e; }"))->Run();
2469 CHECK_EQ(v8_str("netto"), netto); 2479 CHECK_EQ(v8_str("netto"), netto);
2470 } 2480 }
2471 2481
2472 2482
2473 THREADED_TEST(FunctionPrototype) { 2483 THREADED_TEST(FunctionPrototype) {
2474 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2484 v8::HandleScope scope(CcTest::isolate());
2475 Local<v8::FunctionTemplate> Foo = v8::FunctionTemplate::New(); 2485 Local<v8::FunctionTemplate> Foo = v8::FunctionTemplate::New();
2476 Foo->PrototypeTemplate()->Set(v8_str("plak"), v8_num(321)); 2486 Foo->PrototypeTemplate()->Set(v8_str("plak"), v8_num(321));
2477 LocalContext env; 2487 LocalContext env;
2478 env->Global()->Set(v8_str("Foo"), Foo->GetFunction()); 2488 env->Global()->Set(v8_str("Foo"), Foo->GetFunction());
2479 Local<Script> script = Script::Compile(v8_str("Foo.prototype.plak")); 2489 Local<Script> script = Script::Compile(v8_str("Foo.prototype.plak"));
2480 CHECK_EQ(script->Run()->Int32Value(), 321); 2490 CHECK_EQ(script->Run()->Int32Value(), 321);
2481 } 2491 }
2482 2492
2483 2493
2484 THREADED_TEST(InternalFields) { 2494 THREADED_TEST(InternalFields) {
2485 LocalContext env; 2495 LocalContext env;
2486 v8::HandleScope scope(env->GetIsolate()); 2496 v8::HandleScope scope(env->GetIsolate());
2487 2497
2488 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 2498 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
2489 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); 2499 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate();
2490 instance_templ->SetInternalFieldCount(1); 2500 instance_templ->SetInternalFieldCount(1);
2491 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); 2501 Local<v8::Object> obj = templ->GetFunction()->NewInstance();
2492 CHECK_EQ(1, obj->InternalFieldCount()); 2502 CHECK_EQ(1, obj->InternalFieldCount());
2493 CHECK(obj->GetInternalField(0)->IsUndefined()); 2503 CHECK(obj->GetInternalField(0)->IsUndefined());
2494 obj->SetInternalField(0, v8_num(17)); 2504 obj->SetInternalField(0, v8_num(17));
2495 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value()); 2505 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value());
2496 } 2506 }
2497 2507
2498 2508
2499 THREADED_TEST(GlobalObjectInternalFields) { 2509 THREADED_TEST(GlobalObjectInternalFields) {
2500 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2510 v8::HandleScope scope(CcTest::isolate());
2501 Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 2511 Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
2502 global_template->SetInternalFieldCount(1); 2512 global_template->SetInternalFieldCount(1);
2503 LocalContext env(NULL, global_template); 2513 LocalContext env(NULL, global_template);
2504 v8::Handle<v8::Object> global_proxy = env->Global(); 2514 v8::Handle<v8::Object> global_proxy = env->Global();
2505 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); 2515 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>();
2506 CHECK_EQ(1, global->InternalFieldCount()); 2516 CHECK_EQ(1, global->InternalFieldCount());
2507 CHECK(global->GetInternalField(0)->IsUndefined()); 2517 CHECK(global->GetInternalField(0)->IsUndefined());
2508 global->SetInternalField(0, v8_num(17)); 2518 global->SetInternalField(0, v8_num(17));
2509 CHECK_EQ(17, global->GetInternalField(0)->Int32Value()); 2519 CHECK_EQ(17, global->GetInternalField(0)->Int32Value());
2510 } 2520 }
2511 2521
2512 2522
2513 THREADED_TEST(GlobalObjectHasRealIndexedProperty) { 2523 THREADED_TEST(GlobalObjectHasRealIndexedProperty) {
2514 LocalContext env; 2524 LocalContext env;
2515 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2525 v8::HandleScope scope(CcTest::isolate());
2516 2526
2517 v8::Local<v8::Object> global = env->Global(); 2527 v8::Local<v8::Object> global = env->Global();
2518 global->Set(0, v8::String::New("value")); 2528 global->Set(0, v8::String::New("value"));
2519 CHECK(global->HasRealIndexedProperty(0)); 2529 CHECK(global->HasRealIndexedProperty(0));
2520 } 2530 }
2521 2531
2522 2532
2523 static void CheckAlignedPointerInInternalField(Handle<v8::Object> obj, 2533 static void CheckAlignedPointerInInternalField(Handle<v8::Object> obj,
2524 void* value) { 2534 void* value) {
2525 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); 2535 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1));
2526 obj->SetAlignedPointerInInternalField(0, value); 2536 obj->SetAlignedPointerInInternalField(0, value);
2527 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 2537 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2528 CHECK_EQ(value, obj->GetAlignedPointerFromInternalField(0)); 2538 CHECK_EQ(value, obj->GetAlignedPointerFromInternalField(0));
2529 } 2539 }
2530 2540
2531 2541
2532 THREADED_TEST(InternalFieldsAlignedPointers) { 2542 THREADED_TEST(InternalFieldsAlignedPointers) {
2533 LocalContext env; 2543 LocalContext env;
2534 v8::HandleScope scope(env->GetIsolate()); 2544 v8::HandleScope scope(env->GetIsolate());
2535 2545
2536 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 2546 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
2537 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); 2547 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate();
(...skipping 13 matching lines...) Expand all
2551 void* huge = reinterpret_cast<void*>(~static_cast<uintptr_t>(1)); 2561 void* huge = reinterpret_cast<void*>(~static_cast<uintptr_t>(1));
2552 CheckAlignedPointerInInternalField(obj, huge); 2562 CheckAlignedPointerInInternalField(obj, huge);
2553 } 2563 }
2554 2564
2555 2565
2556 static void CheckAlignedPointerInEmbedderData(LocalContext* env, 2566 static void CheckAlignedPointerInEmbedderData(LocalContext* env,
2557 int index, 2567 int index,
2558 void* value) { 2568 void* value) {
2559 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); 2569 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1));
2560 (*env)->SetAlignedPointerInEmbedderData(index, value); 2570 (*env)->SetAlignedPointerInEmbedderData(index, value);
2561 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 2571 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2562 CHECK_EQ(value, (*env)->GetAlignedPointerFromEmbedderData(index)); 2572 CHECK_EQ(value, (*env)->GetAlignedPointerFromEmbedderData(index));
2563 } 2573 }
2564 2574
2565 2575
2566 static void* AlignedTestPointer(int i) { 2576 static void* AlignedTestPointer(int i) {
2567 return reinterpret_cast<void*>(i * 1234); 2577 return reinterpret_cast<void*>(i * 1234);
2568 } 2578 }
2569 2579
2570 2580
2571 THREADED_TEST(EmbedderDataAlignedPointers) { 2581 THREADED_TEST(EmbedderDataAlignedPointers) {
2572 LocalContext env; 2582 LocalContext env;
2573 v8::HandleScope scope(env->GetIsolate()); 2583 v8::HandleScope scope(env->GetIsolate());
2574 2584
2575 CheckAlignedPointerInEmbedderData(&env, 0, NULL); 2585 CheckAlignedPointerInEmbedderData(&env, 0, NULL);
2576 2586
2577 int* heap_allocated = new int[100]; 2587 int* heap_allocated = new int[100];
2578 CheckAlignedPointerInEmbedderData(&env, 1, heap_allocated); 2588 CheckAlignedPointerInEmbedderData(&env, 1, heap_allocated);
2579 delete[] heap_allocated; 2589 delete[] heap_allocated;
2580 2590
2581 int stack_allocated[100]; 2591 int stack_allocated[100];
2582 CheckAlignedPointerInEmbedderData(&env, 2, stack_allocated); 2592 CheckAlignedPointerInEmbedderData(&env, 2, stack_allocated);
2583 2593
2584 void* huge = reinterpret_cast<void*>(~static_cast<uintptr_t>(1)); 2594 void* huge = reinterpret_cast<void*>(~static_cast<uintptr_t>(1));
2585 CheckAlignedPointerInEmbedderData(&env, 3, huge); 2595 CheckAlignedPointerInEmbedderData(&env, 3, huge);
2586 2596
2587 // Test growing of the embedder data's backing store. 2597 // Test growing of the embedder data's backing store.
2588 for (int i = 0; i < 100; i++) { 2598 for (int i = 0; i < 100; i++) {
2589 env->SetAlignedPointerInEmbedderData(i, AlignedTestPointer(i)); 2599 env->SetAlignedPointerInEmbedderData(i, AlignedTestPointer(i));
2590 } 2600 }
2591 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 2601 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2592 for (int i = 0; i < 100; i++) { 2602 for (int i = 0; i < 100; i++) {
2593 CHECK_EQ(AlignedTestPointer(i), env->GetAlignedPointerFromEmbedderData(i)); 2603 CHECK_EQ(AlignedTestPointer(i), env->GetAlignedPointerFromEmbedderData(i));
2594 } 2604 }
2595 } 2605 }
2596 2606
2597 2607
2598 static void CheckEmbedderData(LocalContext* env, 2608 static void CheckEmbedderData(LocalContext* env,
2599 int index, 2609 int index,
2600 v8::Handle<Value> data) { 2610 v8::Handle<Value> data) {
2601 (*env)->SetEmbedderData(index, data); 2611 (*env)->SetEmbedderData(index, data);
(...skipping 11 matching lines...) Expand all
2613 CheckEmbedderData(&env, 0, v8::Boolean::New(true)); 2623 CheckEmbedderData(&env, 0, v8::Boolean::New(true));
2614 } 2624 }
2615 2625
2616 2626
2617 THREADED_TEST(IdentityHash) { 2627 THREADED_TEST(IdentityHash) {
2618 LocalContext env; 2628 LocalContext env;
2619 v8::HandleScope scope(env->GetIsolate()); 2629 v8::HandleScope scope(env->GetIsolate());
2620 2630
2621 // Ensure that the test starts with an fresh heap to test whether the hash 2631 // Ensure that the test starts with an fresh heap to test whether the hash
2622 // code is based on the address. 2632 // code is based on the address.
2623 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 2633 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2624 Local<v8::Object> obj = v8::Object::New(); 2634 Local<v8::Object> obj = v8::Object::New();
2625 int hash = obj->GetIdentityHash(); 2635 int hash = obj->GetIdentityHash();
2626 int hash1 = obj->GetIdentityHash(); 2636 int hash1 = obj->GetIdentityHash();
2627 CHECK_EQ(hash, hash1); 2637 CHECK_EQ(hash, hash1);
2628 int hash2 = v8::Object::New()->GetIdentityHash(); 2638 int hash2 = v8::Object::New()->GetIdentityHash();
2629 // Since the identity hash is essentially a random number two consecutive 2639 // Since the identity hash is essentially a random number two consecutive
2630 // objects should not be assigned the same hash code. If the test below fails 2640 // objects should not be assigned the same hash code. If the test below fails
2631 // the random number generator should be evaluated. 2641 // the random number generator should be evaluated.
2632 CHECK_NE(hash, hash2); 2642 CHECK_NE(hash, hash2);
2633 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 2643 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2634 int hash3 = v8::Object::New()->GetIdentityHash(); 2644 int hash3 = v8::Object::New()->GetIdentityHash();
2635 // Make sure that the identity hash is not based on the initial address of 2645 // Make sure that the identity hash is not based on the initial address of
2636 // the object alone. If the test below fails the random number generator 2646 // the object alone. If the test below fails the random number generator
2637 // should be evaluated. 2647 // should be evaluated.
2638 CHECK_NE(hash, hash3); 2648 CHECK_NE(hash, hash3);
2639 int hash4 = obj->GetIdentityHash(); 2649 int hash4 = obj->GetIdentityHash();
2640 CHECK_EQ(hash, hash4); 2650 CHECK_EQ(hash, hash4);
2641 2651
2642 // Check identity hashes behaviour in the presence of JS accessors. 2652 // Check identity hashes behaviour in the presence of JS accessors.
2643 // Put a getter for 'v8::IdentityHash' on the Object's prototype: 2653 // Put a getter for 'v8::IdentityHash' on the Object's prototype:
(...skipping 18 matching lines...) Expand all
2662 i::FLAG_harmony_symbols = true; 2672 i::FLAG_harmony_symbols = true;
2663 2673
2664 LocalContext env; 2674 LocalContext env;
2665 v8::Isolate* isolate = env->GetIsolate(); 2675 v8::Isolate* isolate = env->GetIsolate();
2666 v8::HandleScope scope(isolate); 2676 v8::HandleScope scope(isolate);
2667 2677
2668 v8::Local<v8::Object> obj = v8::Object::New(); 2678 v8::Local<v8::Object> obj = v8::Object::New();
2669 v8::Local<v8::Symbol> sym1 = v8::Symbol::New(isolate); 2679 v8::Local<v8::Symbol> sym1 = v8::Symbol::New(isolate);
2670 v8::Local<v8::Symbol> sym2 = v8::Symbol::New(isolate, "my-symbol"); 2680 v8::Local<v8::Symbol> sym2 = v8::Symbol::New(isolate, "my-symbol");
2671 2681
2672 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 2682 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2673 2683
2674 // Check basic symbol functionality. 2684 // Check basic symbol functionality.
2675 CHECK(sym1->IsSymbol()); 2685 CHECK(sym1->IsSymbol());
2676 CHECK(sym2->IsSymbol()); 2686 CHECK(sym2->IsSymbol());
2677 CHECK(!obj->IsSymbol()); 2687 CHECK(!obj->IsSymbol());
2678 2688
2679 CHECK(sym1->Equals(sym1)); 2689 CHECK(sym1->Equals(sym1));
2680 CHECK(sym2->Equals(sym2)); 2690 CHECK(sym2->Equals(sym2));
2681 CHECK(!sym1->Equals(sym2)); 2691 CHECK(!sym1->Equals(sym2));
2682 CHECK(!sym2->Equals(sym1)); 2692 CHECK(!sym2->Equals(sym1));
(...skipping 30 matching lines...) Expand all
2713 CHECK(obj->Has(sym1)); 2723 CHECK(obj->Has(sym1));
2714 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); 2724 CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
2715 CHECK_EQ(v8::None, obj->GetPropertyAttributes(sym1)); 2725 CHECK_EQ(v8::None, obj->GetPropertyAttributes(sym1));
2716 2726
2717 CHECK_EQ(0, obj->GetOwnPropertyNames()->Length()); 2727 CHECK_EQ(0, obj->GetOwnPropertyNames()->Length());
2718 int num_props = obj->GetPropertyNames()->Length(); 2728 int num_props = obj->GetPropertyNames()->Length();
2719 CHECK(obj->Set(v8::String::New("bla"), v8::Integer::New(20))); 2729 CHECK(obj->Set(v8::String::New("bla"), v8::Integer::New(20)));
2720 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); 2730 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
2721 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length()); 2731 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length());
2722 2732
2723 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 2733 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2724 2734
2725 // Add another property and delete it afterwards to force the object in 2735 // Add another property and delete it afterwards to force the object in
2726 // slow case. 2736 // slow case.
2727 CHECK(obj->Set(sym2, v8::Integer::New(2008))); 2737 CHECK(obj->Set(sym2, v8::Integer::New(2008)));
2728 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); 2738 CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
2729 CHECK_EQ(2008, obj->Get(sym2)->Int32Value()); 2739 CHECK_EQ(2008, obj->Get(sym2)->Int32Value());
2730 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); 2740 CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
2731 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); 2741 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
2732 2742
2733 CHECK(obj->Has(sym1)); 2743 CHECK(obj->Has(sym1));
(...skipping 29 matching lines...) Expand all
2763 2773
2764 THREADED_TEST(ArrayBuffer_ApiInternalToExternal) { 2774 THREADED_TEST(ArrayBuffer_ApiInternalToExternal) {
2765 LocalContext env; 2775 LocalContext env;
2766 v8::Isolate* isolate = env->GetIsolate(); 2776 v8::Isolate* isolate = env->GetIsolate();
2767 v8::HandleScope handle_scope(isolate); 2777 v8::HandleScope handle_scope(isolate);
2768 2778
2769 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(1024); 2779 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(1024);
2770 CheckInternalFieldsAreZero(ab); 2780 CheckInternalFieldsAreZero(ab);
2771 CHECK_EQ(1024, static_cast<int>(ab->ByteLength())); 2781 CHECK_EQ(1024, static_cast<int>(ab->ByteLength()));
2772 CHECK(!ab->IsExternal()); 2782 CHECK(!ab->IsExternal());
2773 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 2783 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2774 2784
2775 ScopedArrayBufferContents ab_contents(ab->Externalize()); 2785 ScopedArrayBufferContents ab_contents(ab->Externalize());
2776 CHECK(ab->IsExternal()); 2786 CHECK(ab->IsExternal());
2777 2787
2778 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength())); 2788 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength()));
2779 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data()); 2789 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data());
2780 ASSERT(data != NULL); 2790 ASSERT(data != NULL);
2781 env->Global()->Set(v8_str("ab"), ab); 2791 env->Global()->Set(v8_str("ab"), ab);
2782 2792
2783 v8::Handle<v8::Value> result = CompileRun("ab.byteLength"); 2793 v8::Handle<v8::Value> result = CompileRun("ab.byteLength");
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
3005 3015
3006 THREADED_TEST(HiddenProperties) { 3016 THREADED_TEST(HiddenProperties) {
3007 LocalContext env; 3017 LocalContext env;
3008 v8::HandleScope scope(env->GetIsolate()); 3018 v8::HandleScope scope(env->GetIsolate());
3009 3019
3010 v8::Local<v8::Object> obj = v8::Object::New(); 3020 v8::Local<v8::Object> obj = v8::Object::New();
3011 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); 3021 v8::Local<v8::String> key = v8_str("api-test::hidden-key");
3012 v8::Local<v8::String> empty = v8_str(""); 3022 v8::Local<v8::String> empty = v8_str("");
3013 v8::Local<v8::String> prop_name = v8_str("prop_name"); 3023 v8::Local<v8::String> prop_name = v8_str("prop_name");
3014 3024
3015 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 3025 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
3016 3026
3017 // Make sure delete of a non-existent hidden value works 3027 // Make sure delete of a non-existent hidden value works
3018 CHECK(obj->DeleteHiddenValue(key)); 3028 CHECK(obj->DeleteHiddenValue(key));
3019 3029
3020 CHECK(obj->SetHiddenValue(key, v8::Integer::New(1503))); 3030 CHECK(obj->SetHiddenValue(key, v8::Integer::New(1503)));
3021 CHECK_EQ(1503, obj->GetHiddenValue(key)->Int32Value()); 3031 CHECK_EQ(1503, obj->GetHiddenValue(key)->Int32Value());
3022 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2002))); 3032 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2002)));
3023 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3033 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
3024 3034
3025 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 3035 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
3026 3036
3027 // Make sure we do not find the hidden property. 3037 // Make sure we do not find the hidden property.
3028 CHECK(!obj->Has(empty)); 3038 CHECK(!obj->Has(empty));
3029 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3039 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
3030 CHECK(obj->Get(empty)->IsUndefined()); 3040 CHECK(obj->Get(empty)->IsUndefined());
3031 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3041 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
3032 CHECK(obj->Set(empty, v8::Integer::New(2003))); 3042 CHECK(obj->Set(empty, v8::Integer::New(2003)));
3033 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3043 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
3034 CHECK_EQ(2003, obj->Get(empty)->Int32Value()); 3044 CHECK_EQ(2003, obj->Get(empty)->Int32Value());
3035 3045
3036 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 3046 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
3037 3047
3038 // Add another property and delete it afterwards to force the object in 3048 // Add another property and delete it afterwards to force the object in
3039 // slow case. 3049 // slow case.
3040 CHECK(obj->Set(prop_name, v8::Integer::New(2008))); 3050 CHECK(obj->Set(prop_name, v8::Integer::New(2008)));
3041 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3051 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
3042 CHECK_EQ(2008, obj->Get(prop_name)->Int32Value()); 3052 CHECK_EQ(2008, obj->Get(prop_name)->Int32Value());
3043 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3053 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
3044 CHECK(obj->Delete(prop_name)); 3054 CHECK(obj->Delete(prop_name));
3045 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3055 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
3046 3056
3047 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 3057 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
3048 3058
3049 CHECK(obj->SetHiddenValue(key, Handle<Value>())); 3059 CHECK(obj->SetHiddenValue(key, Handle<Value>()));
3050 CHECK(obj->GetHiddenValue(key).IsEmpty()); 3060 CHECK(obj->GetHiddenValue(key).IsEmpty());
3051 3061
3052 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2002))); 3062 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2002)));
3053 CHECK(obj->DeleteHiddenValue(key)); 3063 CHECK(obj->DeleteHiddenValue(key));
3054 CHECK(obj->GetHiddenValue(key).IsEmpty()); 3064 CHECK(obj->GetHiddenValue(key).IsEmpty());
3055 } 3065 }
3056 3066
3057 3067
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3104 instance_templ->SetNamedPropertyHandler(InterceptorForHiddenProperties); 3114 instance_templ->SetNamedPropertyHandler(InterceptorForHiddenProperties);
3105 Local<v8::Function> function = fun_templ->GetFunction(); 3115 Local<v8::Function> function = fun_templ->GetFunction();
3106 Local<v8::Object> obj = function->NewInstance(); 3116 Local<v8::Object> obj = function->NewInstance();
3107 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2302))); 3117 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2302)));
3108 CHECK_EQ(2302, obj->GetHiddenValue(key)->Int32Value()); 3118 CHECK_EQ(2302, obj->GetHiddenValue(key)->Int32Value());
3109 CHECK(!interceptor_for_hidden_properties_called); 3119 CHECK(!interceptor_for_hidden_properties_called);
3110 } 3120 }
3111 3121
3112 3122
3113 THREADED_TEST(External) { 3123 THREADED_TEST(External) {
3114 v8::HandleScope scope(v8::Isolate::GetCurrent()); 3124 v8::HandleScope scope(CcTest::isolate());
3115 int x = 3; 3125 int x = 3;
3116 Local<v8::External> ext = v8::External::New(&x); 3126 Local<v8::External> ext = v8::External::New(&x);
3117 LocalContext env; 3127 LocalContext env;
3118 env->Global()->Set(v8_str("ext"), ext); 3128 env->Global()->Set(v8_str("ext"), ext);
3119 Local<Value> reext_obj = Script::Compile(v8_str("this.ext"))->Run(); 3129 Local<Value> reext_obj = Script::Compile(v8_str("this.ext"))->Run();
3120 v8::Handle<v8::External> reext = reext_obj.As<v8::External>(); 3130 v8::Handle<v8::External> reext = reext_obj.As<v8::External>();
3121 int* ptr = static_cast<int*>(reext->Value()); 3131 int* ptr = static_cast<int*>(reext->Value());
3122 CHECK_EQ(x, 3); 3132 CHECK_EQ(x, 3);
3123 *ptr = 10; 3133 *ptr = 10;
3124 CHECK_EQ(x, 10); 3134 CHECK_EQ(x, 10);
(...skipping 11 matching lines...) Expand all
3136 CHECK_EQ('1', *char_ptr); 3146 CHECK_EQ('1', *char_ptr);
3137 char_ptr = reinterpret_cast<char*>(v8::External::Cast(*two)->Value()); 3147 char_ptr = reinterpret_cast<char*>(v8::External::Cast(*two)->Value());
3138 CHECK_EQ('2', *char_ptr); 3148 CHECK_EQ('2', *char_ptr);
3139 char_ptr = reinterpret_cast<char*>(v8::External::Cast(*three)->Value()); 3149 char_ptr = reinterpret_cast<char*>(v8::External::Cast(*three)->Value());
3140 CHECK_EQ('3', *char_ptr); 3150 CHECK_EQ('3', *char_ptr);
3141 i::DeleteArray(data); 3151 i::DeleteArray(data);
3142 } 3152 }
3143 3153
3144 3154
3145 THREADED_TEST(GlobalHandle) { 3155 THREADED_TEST(GlobalHandle) {
3146 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 3156 v8::Isolate* isolate = CcTest::isolate();
3147 v8::Persistent<String> global; 3157 v8::Persistent<String> global;
3148 { 3158 {
3149 v8::HandleScope scope(isolate); 3159 v8::HandleScope scope(isolate);
3150 global.Reset(isolate, v8_str("str")); 3160 global.Reset(isolate, v8_str("str"));
3151 } 3161 }
3152 { 3162 {
3153 v8::HandleScope scope(isolate); 3163 v8::HandleScope scope(isolate);
3154 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 3); 3164 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 3);
3155 } 3165 }
3156 global.Dispose(); 3166 global.Dispose();
3157 global.Clear(); 3167 global.Clear();
3158 { 3168 {
3159 v8::HandleScope scope(isolate); 3169 v8::HandleScope scope(isolate);
3160 global.Reset(isolate, v8_str("str")); 3170 global.Reset(isolate, v8_str("str"));
3161 } 3171 }
3162 { 3172 {
3163 v8::HandleScope scope(isolate); 3173 v8::HandleScope scope(isolate);
3164 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 3); 3174 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 3);
3165 } 3175 }
3166 global.Dispose(); 3176 global.Dispose();
3167 } 3177 }
3168 3178
3169 3179
3170 THREADED_TEST(ResettingGlobalHandle) { 3180 THREADED_TEST(ResettingGlobalHandle) {
3171 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 3181 v8::Isolate* isolate = CcTest::isolate();
3172 v8::Persistent<String> global; 3182 v8::Persistent<String> global;
3173 { 3183 {
3174 v8::HandleScope scope(isolate); 3184 v8::HandleScope scope(isolate);
3175 global.Reset(isolate, v8_str("str")); 3185 global.Reset(isolate, v8_str("str"));
3176 } 3186 }
3177 v8::internal::GlobalHandles* global_handles = 3187 v8::internal::GlobalHandles* global_handles =
3178 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles(); 3188 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles();
3179 int initial_handle_count = global_handles->global_handles_count(); 3189 int initial_handle_count = global_handles->global_handles_count();
3180 { 3190 {
3181 v8::HandleScope scope(isolate); 3191 v8::HandleScope scope(isolate);
3182 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 3); 3192 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 3);
3183 } 3193 }
3184 { 3194 {
3185 v8::HandleScope scope(isolate); 3195 v8::HandleScope scope(isolate);
3186 global.Reset(isolate, v8_str("longer")); 3196 global.Reset(isolate, v8_str("longer"));
3187 } 3197 }
3188 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count); 3198 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count);
3189 { 3199 {
3190 v8::HandleScope scope(isolate); 3200 v8::HandleScope scope(isolate);
3191 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 6); 3201 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 6);
3192 } 3202 }
3193 global.Dispose(); 3203 global.Dispose();
3194 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count - 1); 3204 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count - 1);
3195 } 3205 }
3196 3206
3197 3207
3198 THREADED_TEST(ResettingGlobalHandleToEmpty) { 3208 THREADED_TEST(ResettingGlobalHandleToEmpty) {
3199 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 3209 v8::Isolate* isolate = CcTest::isolate();
3200 v8::Persistent<String> global; 3210 v8::Persistent<String> global;
3201 { 3211 {
3202 v8::HandleScope scope(isolate); 3212 v8::HandleScope scope(isolate);
3203 global.Reset(isolate, v8_str("str")); 3213 global.Reset(isolate, v8_str("str"));
3204 } 3214 }
3205 v8::internal::GlobalHandles* global_handles = 3215 v8::internal::GlobalHandles* global_handles =
3206 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles(); 3216 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles();
3207 int initial_handle_count = global_handles->global_handles_count(); 3217 int initial_handle_count = global_handles->global_handles_count();
3208 { 3218 {
3209 v8::HandleScope scope(isolate); 3219 v8::HandleScope scope(isolate);
3210 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 3); 3220 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 3);
3211 } 3221 }
3212 { 3222 {
3213 v8::HandleScope scope(isolate); 3223 v8::HandleScope scope(isolate);
3214 Local<String> empty; 3224 Local<String> empty;
3215 global.Reset(isolate, empty); 3225 global.Reset(isolate, empty);
3216 } 3226 }
3217 CHECK(global.IsEmpty()); 3227 CHECK(global.IsEmpty());
3218 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count - 1); 3228 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count - 1);
3219 } 3229 }
3220 3230
3221 3231
3222 THREADED_TEST(ClearAndLeakGlobal) { 3232 THREADED_TEST(ClearAndLeakGlobal) {
3223 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 3233 v8::Isolate* isolate = CcTest::isolate();
3224 v8::internal::GlobalHandles* global_handles = NULL; 3234 v8::internal::GlobalHandles* global_handles = NULL;
3225 int initial_handle_count = 0; 3235 int initial_handle_count = 0;
3226 v8::Persistent<String> global; 3236 v8::Persistent<String> global;
3227 { 3237 {
3228 v8::HandleScope scope(isolate); 3238 v8::HandleScope scope(isolate);
3229 Local<String> str = v8_str("str"); 3239 Local<String> str = v8_str("str");
3230 global_handles = 3240 global_handles =
3231 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles(); 3241 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles();
3232 initial_handle_count = global_handles->global_handles_count(); 3242 initial_handle_count = global_handles->global_handles_count();
3233 global.Reset(isolate, str); 3243 global.Reset(isolate, str);
3234 } 3244 }
3235 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count + 1); 3245 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count + 1);
3236 String* str = global.ClearAndLeak(); 3246 String* str = global.ClearAndLeak();
3237 CHECK(global.IsEmpty()); 3247 CHECK(global.IsEmpty());
3238 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count + 1); 3248 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count + 1);
3239 global_handles->Destroy(reinterpret_cast<i::Object**>(str)); 3249 global_handles->Destroy(reinterpret_cast<i::Object**>(str));
3240 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count); 3250 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count);
3241 } 3251 }
3242 3252
3243 3253
3244 THREADED_TEST(GlobalHandleUpcast) { 3254 THREADED_TEST(GlobalHandleUpcast) {
3245 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 3255 v8::Isolate* isolate = CcTest::isolate();
3246 v8::HandleScope scope(isolate); 3256 v8::HandleScope scope(isolate);
3247 v8::Local<String> local = v8::Local<String>::New(v8_str("str")); 3257 v8::Local<String> local = v8::Local<String>::New(v8_str("str"));
3248 v8::Persistent<String> global_string(isolate, local); 3258 v8::Persistent<String> global_string(isolate, local);
3249 v8::Persistent<Value>& global_value = 3259 v8::Persistent<Value>& global_value =
3250 v8::Persistent<Value>::Cast(global_string); 3260 v8::Persistent<Value>::Cast(global_string);
3251 CHECK(v8::Local<v8::Value>::New(isolate, global_value)->IsString()); 3261 CHECK(v8::Local<v8::Value>::New(isolate, global_value)->IsString());
3252 CHECK(global_string == v8::Persistent<String>::Cast(global_value)); 3262 CHECK(global_string == v8::Persistent<String>::Cast(global_value));
3253 global_string.Dispose(); 3263 global_string.Dispose();
3254 } 3264 }
3255 3265
3256 3266
3257 THREADED_TEST(HandleEquality) { 3267 THREADED_TEST(HandleEquality) {
3258 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 3268 v8::Isolate* isolate = CcTest::isolate();
3259 v8::Persistent<String> global1; 3269 v8::Persistent<String> global1;
3260 v8::Persistent<String> global2; 3270 v8::Persistent<String> global2;
3261 { 3271 {
3262 v8::HandleScope scope(isolate); 3272 v8::HandleScope scope(isolate);
3263 global1.Reset(isolate, v8_str("str")); 3273 global1.Reset(isolate, v8_str("str"));
3264 global2.Reset(isolate, v8_str("str2")); 3274 global2.Reset(isolate, v8_str("str2"));
3265 } 3275 }
3266 CHECK_EQ(global1 == global1, true); 3276 CHECK_EQ(global1 == global1, true);
3267 CHECK_EQ(global1 != global1, false); 3277 CHECK_EQ(global1 != global1, false);
3268 { 3278 {
(...skipping 17 matching lines...) Expand all
3286 Local<String> anotherLocal1 = Local<String>::New(isolate, global1); 3296 Local<String> anotherLocal1 = Local<String>::New(isolate, global1);
3287 CHECK_EQ(local1 == anotherLocal1, true); 3297 CHECK_EQ(local1 == anotherLocal1, true);
3288 CHECK_EQ(local1 != anotherLocal1, false); 3298 CHECK_EQ(local1 != anotherLocal1, false);
3289 } 3299 }
3290 global1.Dispose(); 3300 global1.Dispose();
3291 global2.Dispose(); 3301 global2.Dispose();
3292 } 3302 }
3293 3303
3294 3304
3295 THREADED_TEST(LocalHandle) { 3305 THREADED_TEST(LocalHandle) {
3296 v8::HandleScope scope(v8::Isolate::GetCurrent()); 3306 v8::HandleScope scope(CcTest::isolate());
3297 v8::Local<String> local = v8::Local<String>::New(v8_str("str")); 3307 v8::Local<String> local = v8::Local<String>::New(v8_str("str"));
3298 CHECK_EQ(local->Length(), 3); 3308 CHECK_EQ(local->Length(), 3);
3299 3309
3300 local = v8::Local<String>::New(v8::Isolate::GetCurrent(), v8_str("str")); 3310 local = v8::Local<String>::New(CcTest::isolate(), v8_str("str"));
3301 CHECK_EQ(local->Length(), 3); 3311 CHECK_EQ(local->Length(), 3);
3302 } 3312 }
3303 3313
3304 3314
3305 class WeakCallCounter { 3315 class WeakCallCounter {
3306 public: 3316 public:
3307 explicit WeakCallCounter(int id) : id_(id), number_of_weak_calls_(0) { } 3317 explicit WeakCallCounter(int id) : id_(id), number_of_weak_calls_(0) { }
3308 int id() { return id_; } 3318 int id() { return id_; }
3309 void increment() { number_of_weak_calls_++; } 3319 void increment() { number_of_weak_calls_++; }
3310 int NumberOfWeakCalls() { return number_of_weak_calls_; } 3320 int NumberOfWeakCalls() { return number_of_weak_calls_; }
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
3668 CHECK_EQ(5.76, data->NumberValue()); 3678 CHECK_EQ(5.76, data->NumberValue());
3669 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue()); 3679 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue());
3670 CHECK_EQ(7.56, message->GetScriptData()->NumberValue()); 3680 CHECK_EQ(7.56, message->GetScriptData()->NumberValue());
3671 CHECK(!message->IsSharedCrossOrigin()); 3681 CHECK(!message->IsSharedCrossOrigin());
3672 message_received = true; 3682 message_received = true;
3673 } 3683 }
3674 3684
3675 3685
3676 THREADED_TEST(MessageHandler0) { 3686 THREADED_TEST(MessageHandler0) {
3677 message_received = false; 3687 message_received = false;
3678 v8::HandleScope scope(v8::Isolate::GetCurrent()); 3688 v8::HandleScope scope(CcTest::isolate());
3679 CHECK(!message_received); 3689 CHECK(!message_received);
3680 v8::V8::AddMessageListener(check_message_0, v8_num(5.76)); 3690 v8::V8::AddMessageListener(check_message_0, v8_num(5.76));
3681 LocalContext context; 3691 LocalContext context;
3682 v8::ScriptOrigin origin = 3692 v8::ScriptOrigin origin =
3683 v8::ScriptOrigin(v8_str("6.75")); 3693 v8::ScriptOrigin(v8_str("6.75"));
3684 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), 3694 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"),
3685 &origin); 3695 &origin);
3686 script->SetData(v8_str("7.56")); 3696 script->SetData(v8_str("7.56"));
3687 script->Run(); 3697 script->Run();
3688 CHECK(message_received); 3698 CHECK(message_received);
3689 // clear out the message listener 3699 // clear out the message listener
3690 v8::V8::RemoveMessageListeners(check_message_0); 3700 v8::V8::RemoveMessageListeners(check_message_0);
3691 } 3701 }
3692 3702
3693 3703
3694 static void check_message_1(v8::Handle<v8::Message> message, 3704 static void check_message_1(v8::Handle<v8::Message> message,
3695 v8::Handle<Value> data) { 3705 v8::Handle<Value> data) {
3696 CHECK(data->IsNumber()); 3706 CHECK(data->IsNumber());
3697 CHECK_EQ(1337, data->Int32Value()); 3707 CHECK_EQ(1337, data->Int32Value());
3698 CHECK(!message->IsSharedCrossOrigin()); 3708 CHECK(!message->IsSharedCrossOrigin());
3699 message_received = true; 3709 message_received = true;
3700 } 3710 }
3701 3711
3702 3712
3703 TEST(MessageHandler1) { 3713 TEST(MessageHandler1) {
3704 message_received = false; 3714 message_received = false;
3705 v8::HandleScope scope(v8::Isolate::GetCurrent()); 3715 v8::HandleScope scope(CcTest::isolate());
3706 CHECK(!message_received); 3716 CHECK(!message_received);
3707 v8::V8::AddMessageListener(check_message_1); 3717 v8::V8::AddMessageListener(check_message_1);
3708 LocalContext context; 3718 LocalContext context;
3709 CompileRun("throw 1337;"); 3719 CompileRun("throw 1337;");
3710 CHECK(message_received); 3720 CHECK(message_received);
3711 // clear out the message listener 3721 // clear out the message listener
3712 v8::V8::RemoveMessageListeners(check_message_1); 3722 v8::V8::RemoveMessageListeners(check_message_1);
3713 } 3723 }
3714 3724
3715 3725
3716 static void check_message_2(v8::Handle<v8::Message> message, 3726 static void check_message_2(v8::Handle<v8::Message> message,
3717 v8::Handle<Value> data) { 3727 v8::Handle<Value> data) {
3718 LocalContext context; 3728 LocalContext context;
3719 CHECK(data->IsObject()); 3729 CHECK(data->IsObject());
3720 v8::Local<v8::Value> hidden_property = 3730 v8::Local<v8::Value> hidden_property =
3721 v8::Object::Cast(*data)->GetHiddenValue(v8_str("hidden key")); 3731 v8::Object::Cast(*data)->GetHiddenValue(v8_str("hidden key"));
3722 CHECK(v8_str("hidden value")->Equals(hidden_property)); 3732 CHECK(v8_str("hidden value")->Equals(hidden_property));
3723 CHECK(!message->IsSharedCrossOrigin()); 3733 CHECK(!message->IsSharedCrossOrigin());
3724 message_received = true; 3734 message_received = true;
3725 } 3735 }
3726 3736
3727 3737
3728 TEST(MessageHandler2) { 3738 TEST(MessageHandler2) {
3729 message_received = false; 3739 message_received = false;
3730 v8::HandleScope scope(v8::Isolate::GetCurrent()); 3740 v8::HandleScope scope(CcTest::isolate());
3731 CHECK(!message_received); 3741 CHECK(!message_received);
3732 v8::V8::AddMessageListener(check_message_2); 3742 v8::V8::AddMessageListener(check_message_2);
3733 LocalContext context; 3743 LocalContext context;
3734 v8::Local<v8::Value> error = v8::Exception::Error(v8_str("custom error")); 3744 v8::Local<v8::Value> error = v8::Exception::Error(v8_str("custom error"));
3735 v8::Object::Cast(*error)->SetHiddenValue(v8_str("hidden key"), 3745 v8::Object::Cast(*error)->SetHiddenValue(v8_str("hidden key"),
3736 v8_str("hidden value")); 3746 v8_str("hidden value"));
3737 context->Global()->Set(v8_str("error"), error); 3747 context->Global()->Set(v8_str("error"), error);
3738 CompileRun("throw error;"); 3748 CompileRun("throw error;");
3739 CHECK(message_received); 3749 CHECK(message_received);
3740 // clear out the message listener 3750 // clear out the message listener
3741 v8::V8::RemoveMessageListeners(check_message_2); 3751 v8::V8::RemoveMessageListeners(check_message_2);
3742 } 3752 }
3743 3753
3744 3754
3745 static void check_message_3(v8::Handle<v8::Message> message, 3755 static void check_message_3(v8::Handle<v8::Message> message,
3746 v8::Handle<Value> data) { 3756 v8::Handle<Value> data) {
3747 CHECK(message->IsSharedCrossOrigin()); 3757 CHECK(message->IsSharedCrossOrigin());
3748 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue()); 3758 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue());
3749 message_received = true; 3759 message_received = true;
3750 } 3760 }
3751 3761
3752 3762
3753 TEST(MessageHandler3) { 3763 TEST(MessageHandler3) {
3754 message_received = false; 3764 message_received = false;
3755 v8::HandleScope scope(v8::Isolate::GetCurrent()); 3765 v8::HandleScope scope(CcTest::isolate());
3756 CHECK(!message_received); 3766 CHECK(!message_received);
3757 v8::V8::AddMessageListener(check_message_3); 3767 v8::V8::AddMessageListener(check_message_3);
3758 LocalContext context; 3768 LocalContext context;
3759 v8::ScriptOrigin origin = 3769 v8::ScriptOrigin origin =
3760 v8::ScriptOrigin(v8_str("6.75"), 3770 v8::ScriptOrigin(v8_str("6.75"),
3761 v8::Integer::New(1), 3771 v8::Integer::New(1),
3762 v8::Integer::New(2), 3772 v8::Integer::New(2),
3763 v8::True()); 3773 v8::True());
3764 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), 3774 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"),
3765 &origin); 3775 &origin);
3766 script->Run(); 3776 script->Run();
3767 CHECK(message_received); 3777 CHECK(message_received);
3768 // clear out the message listener 3778 // clear out the message listener
3769 v8::V8::RemoveMessageListeners(check_message_3); 3779 v8::V8::RemoveMessageListeners(check_message_3);
3770 } 3780 }
3771 3781
3772 3782
3773 static void check_message_4(v8::Handle<v8::Message> message, 3783 static void check_message_4(v8::Handle<v8::Message> message,
3774 v8::Handle<Value> data) { 3784 v8::Handle<Value> data) {
3775 CHECK(!message->IsSharedCrossOrigin()); 3785 CHECK(!message->IsSharedCrossOrigin());
3776 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue()); 3786 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue());
3777 message_received = true; 3787 message_received = true;
3778 } 3788 }
3779 3789
3780 3790
3781 TEST(MessageHandler4) { 3791 TEST(MessageHandler4) {
3782 message_received = false; 3792 message_received = false;
3783 v8::HandleScope scope(v8::Isolate::GetCurrent()); 3793 v8::HandleScope scope(CcTest::isolate());
3784 CHECK(!message_received); 3794 CHECK(!message_received);
3785 v8::V8::AddMessageListener(check_message_4); 3795 v8::V8::AddMessageListener(check_message_4);
3786 LocalContext context; 3796 LocalContext context;
3787 v8::ScriptOrigin origin = 3797 v8::ScriptOrigin origin =
3788 v8::ScriptOrigin(v8_str("6.75"), 3798 v8::ScriptOrigin(v8_str("6.75"),
3789 v8::Integer::New(1), 3799 v8::Integer::New(1),
3790 v8::Integer::New(2), 3800 v8::Integer::New(2),
3791 v8::False()); 3801 v8::False());
3792 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), 3802 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"),
3793 &origin); 3803 &origin);
(...skipping 15 matching lines...) Expand all
3809 static void check_message_5b(v8::Handle<v8::Message> message, 3819 static void check_message_5b(v8::Handle<v8::Message> message,
3810 v8::Handle<Value> data) { 3820 v8::Handle<Value> data) {
3811 CHECK(!message->IsSharedCrossOrigin()); 3821 CHECK(!message->IsSharedCrossOrigin());
3812 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue()); 3822 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue());
3813 message_received = true; 3823 message_received = true;
3814 } 3824 }
3815 3825
3816 3826
3817 TEST(MessageHandler5) { 3827 TEST(MessageHandler5) {
3818 message_received = false; 3828 message_received = false;
3819 v8::HandleScope scope(v8::Isolate::GetCurrent()); 3829 v8::HandleScope scope(CcTest::isolate());
3820 CHECK(!message_received); 3830 CHECK(!message_received);
3821 v8::V8::AddMessageListener(check_message_5a); 3831 v8::V8::AddMessageListener(check_message_5a);
3822 LocalContext context; 3832 LocalContext context;
3823 v8::ScriptOrigin origin = 3833 v8::ScriptOrigin origin =
3824 v8::ScriptOrigin(v8_str("6.75"), 3834 v8::ScriptOrigin(v8_str("6.75"),
3825 v8::Integer::New(1), 3835 v8::Integer::New(1),
3826 v8::Integer::New(2), 3836 v8::Integer::New(2),
3827 v8::True()); 3837 v8::True());
3828 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), 3838 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"),
3829 &origin); 3839 &origin);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
3951 v8::HandleScope scope(args.GetIsolate()); 3961 v8::HandleScope scope(args.GetIsolate());
3952 ApiTestFuzzer::Fuzz(); 3962 ApiTestFuzzer::Fuzz();
3953 Local<v8::Array> result = v8::Array::New(args.Length()); 3963 Local<v8::Array> result = v8::Array::New(args.Length());
3954 for (int i = 0; i < args.Length(); i++) 3964 for (int i = 0; i < args.Length(); i++)
3955 result->Set(i, args[i]); 3965 result->Set(i, args[i]);
3956 args.GetReturnValue().Set(scope.Close(result)); 3966 args.GetReturnValue().Set(scope.Close(result));
3957 } 3967 }
3958 3968
3959 3969
3960 THREADED_TEST(Vector) { 3970 THREADED_TEST(Vector) {
3961 v8::HandleScope scope(v8::Isolate::GetCurrent()); 3971 v8::HandleScope scope(CcTest::isolate());
3962 Local<ObjectTemplate> global = ObjectTemplate::New(); 3972 Local<ObjectTemplate> global = ObjectTemplate::New();
3963 global->Set(v8_str("f"), v8::FunctionTemplate::New(HandleF)); 3973 global->Set(v8_str("f"), v8::FunctionTemplate::New(HandleF));
3964 LocalContext context(0, global); 3974 LocalContext context(0, global);
3965 3975
3966 const char* fun = "f()"; 3976 const char* fun = "f()";
3967 Local<v8::Array> a0 = CompileRun(fun).As<v8::Array>(); 3977 Local<v8::Array> a0 = CompileRun(fun).As<v8::Array>();
3968 CHECK_EQ(0, a0->Length()); 3978 CHECK_EQ(0, a0->Length());
3969 3979
3970 const char* fun2 = "f(11)"; 3980 const char* fun2 = "f(11)";
3971 Local<v8::Array> a1 = CompileRun(fun2).As<v8::Array>(); 3981 Local<v8::Array> a1 = CompileRun(fun2).As<v8::Array>();
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
4097 TEST(OutOfMemoryNested) { 4107 TEST(OutOfMemoryNested) {
4098 // It's not possible to read a snapshot into a heap with different dimensions. 4108 // It's not possible to read a snapshot into a heap with different dimensions.
4099 if (i::Snapshot::IsEnabled()) return; 4109 if (i::Snapshot::IsEnabled()) return;
4100 // Set heap limits. 4110 // Set heap limits.
4101 static const int K = 1024; 4111 static const int K = 1024;
4102 v8::ResourceConstraints constraints; 4112 v8::ResourceConstraints constraints;
4103 constraints.set_max_young_space_size(256 * K); 4113 constraints.set_max_young_space_size(256 * K);
4104 constraints.set_max_old_space_size(5 * K * K); 4114 constraints.set_max_old_space_size(5 * K * K);
4105 v8::SetResourceConstraints(&constraints); 4115 v8::SetResourceConstraints(&constraints);
4106 4116
4107 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4117 v8::HandleScope scope(CcTest::isolate());
4108 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4118 Local<ObjectTemplate> templ = ObjectTemplate::New();
4109 templ->Set(v8_str("ProvokeOutOfMemory"), 4119 templ->Set(v8_str("ProvokeOutOfMemory"),
4110 v8::FunctionTemplate::New(ProvokeOutOfMemory)); 4120 v8::FunctionTemplate::New(ProvokeOutOfMemory));
4111 LocalContext context(0, templ); 4121 LocalContext context(0, templ);
4112 v8::V8::IgnoreOutOfMemoryException(); 4122 v8::V8::IgnoreOutOfMemoryException();
4113 Local<Value> result = CompileRun( 4123 Local<Value> result = CompileRun(
4114 "var thrown = false;" 4124 "var thrown = false;"
4115 "try {" 4125 "try {"
4116 " ProvokeOutOfMemory();" 4126 " ProvokeOutOfMemory();"
4117 "} catch (e) {" 4127 "} catch (e) {"
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
4376 } 4386 }
4377 v8::HandleScope scope(args.GetIsolate()); 4387 v8::HandleScope scope(args.GetIsolate());
4378 v8::TryCatch try_catch; 4388 v8::TryCatch try_catch;
4379 Local<Value> result = v8::Script::Compile(args[0]->ToString())->Run(); 4389 Local<Value> result = v8::Script::Compile(args[0]->ToString())->Run();
4380 CHECK(!try_catch.HasCaught() || result.IsEmpty()); 4390 CHECK(!try_catch.HasCaught() || result.IsEmpty());
4381 args.GetReturnValue().Set(try_catch.HasCaught()); 4391 args.GetReturnValue().Set(try_catch.HasCaught());
4382 } 4392 }
4383 4393
4384 4394
4385 THREADED_TEST(APICatch) { 4395 THREADED_TEST(APICatch) {
4386 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4396 v8::HandleScope scope(CcTest::isolate());
4387 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4397 Local<ObjectTemplate> templ = ObjectTemplate::New();
4388 templ->Set(v8_str("ThrowFromC"), 4398 templ->Set(v8_str("ThrowFromC"),
4389 v8::FunctionTemplate::New(ThrowFromC)); 4399 v8::FunctionTemplate::New(ThrowFromC));
4390 LocalContext context(0, templ); 4400 LocalContext context(0, templ);
4391 CompileRun( 4401 CompileRun(
4392 "var thrown = false;" 4402 "var thrown = false;"
4393 "try {" 4403 "try {"
4394 " ThrowFromC();" 4404 " ThrowFromC();"
4395 "} catch (e) {" 4405 "} catch (e) {"
4396 " thrown = true;" 4406 " thrown = true;"
4397 "}"); 4407 "}");
4398 Local<Value> thrown = context->Global()->Get(v8_str("thrown")); 4408 Local<Value> thrown = context->Global()->Get(v8_str("thrown"));
4399 CHECK(thrown->BooleanValue()); 4409 CHECK(thrown->BooleanValue());
4400 } 4410 }
4401 4411
4402 4412
4403 THREADED_TEST(APIThrowTryCatch) { 4413 THREADED_TEST(APIThrowTryCatch) {
4404 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4414 v8::HandleScope scope(CcTest::isolate());
4405 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4415 Local<ObjectTemplate> templ = ObjectTemplate::New();
4406 templ->Set(v8_str("ThrowFromC"), 4416 templ->Set(v8_str("ThrowFromC"),
4407 v8::FunctionTemplate::New(ThrowFromC)); 4417 v8::FunctionTemplate::New(ThrowFromC));
4408 LocalContext context(0, templ); 4418 LocalContext context(0, templ);
4409 v8::TryCatch try_catch; 4419 v8::TryCatch try_catch;
4410 CompileRun("ThrowFromC();"); 4420 CompileRun("ThrowFromC();");
4411 CHECK(try_catch.HasCaught()); 4421 CHECK(try_catch.HasCaught());
4412 } 4422 }
4413 4423
4414 4424
4415 // Test that a try-finally block doesn't shadow a try-catch block 4425 // Test that a try-finally block doesn't shadow a try-catch block
4416 // when setting up an external handler. 4426 // when setting up an external handler.
4417 // 4427 //
4418 // BUG(271): Some of the exception propagation does not work on the 4428 // BUG(271): Some of the exception propagation does not work on the
4419 // ARM simulator because the simulator separates the C++ stack and the 4429 // ARM simulator because the simulator separates the C++ stack and the
4420 // JS stack. This test therefore fails on the simulator. The test is 4430 // JS stack. This test therefore fails on the simulator. The test is
4421 // not threaded to allow the threading tests to run on the simulator. 4431 // not threaded to allow the threading tests to run on the simulator.
4422 TEST(TryCatchInTryFinally) { 4432 TEST(TryCatchInTryFinally) {
4423 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4433 v8::HandleScope scope(CcTest::isolate());
4424 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4434 Local<ObjectTemplate> templ = ObjectTemplate::New();
4425 templ->Set(v8_str("CCatcher"), 4435 templ->Set(v8_str("CCatcher"),
4426 v8::FunctionTemplate::New(CCatcher)); 4436 v8::FunctionTemplate::New(CCatcher));
4427 LocalContext context(0, templ); 4437 LocalContext context(0, templ);
4428 Local<Value> result = CompileRun("try {" 4438 Local<Value> result = CompileRun("try {"
4429 " try {" 4439 " try {"
4430 " CCatcher('throw 7;');" 4440 " CCatcher('throw 7;');"
4431 " } finally {" 4441 " } finally {"
4432 " }" 4442 " }"
4433 "} catch (e) {" 4443 "} catch (e) {"
(...skipping 13 matching lines...) Expand all
4447 static void Fail(const v8::FunctionCallbackInfo<v8::Value>& args) { 4457 static void Fail(const v8::FunctionCallbackInfo<v8::Value>& args) {
4448 ApiTestFuzzer::Fuzz(); 4458 ApiTestFuzzer::Fuzz();
4449 CHECK(false); 4459 CHECK(false);
4450 } 4460 }
4451 4461
4452 4462
4453 // Test that overwritten methods are not invoked on uncaught exception 4463 // Test that overwritten methods are not invoked on uncaught exception
4454 // formatting. However, they are invoked when performing normal error 4464 // formatting. However, they are invoked when performing normal error
4455 // string conversions. 4465 // string conversions.
4456 TEST(APIThrowMessageOverwrittenToString) { 4466 TEST(APIThrowMessageOverwrittenToString) {
4457 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4467 v8::HandleScope scope(CcTest::isolate());
4458 v8::V8::AddMessageListener(check_reference_error_message); 4468 v8::V8::AddMessageListener(check_reference_error_message);
4459 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4469 Local<ObjectTemplate> templ = ObjectTemplate::New();
4460 templ->Set(v8_str("fail"), v8::FunctionTemplate::New(Fail)); 4470 templ->Set(v8_str("fail"), v8::FunctionTemplate::New(Fail));
4461 LocalContext context(NULL, templ); 4471 LocalContext context(NULL, templ);
4462 CompileRun("asdf;"); 4472 CompileRun("asdf;");
4463 CompileRun("var limit = {};" 4473 CompileRun("var limit = {};"
4464 "limit.valueOf = fail;" 4474 "limit.valueOf = fail;"
4465 "Error.stackTraceLimit = limit;"); 4475 "Error.stackTraceLimit = limit;");
4466 CompileRun("asdf"); 4476 CompileRun("asdf");
4467 CompileRun("Array.prototype.pop = fail;"); 4477 CompileRun("Array.prototype.pop = fail;");
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
4571 4581
4572 static void receive_message(v8::Handle<v8::Message> message, 4582 static void receive_message(v8::Handle<v8::Message> message,
4573 v8::Handle<v8::Value> data) { 4583 v8::Handle<v8::Value> data) {
4574 message->Get(); 4584 message->Get();
4575 message_received = true; 4585 message_received = true;
4576 } 4586 }
4577 4587
4578 4588
4579 TEST(APIThrowMessage) { 4589 TEST(APIThrowMessage) {
4580 message_received = false; 4590 message_received = false;
4581 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4591 v8::HandleScope scope(CcTest::isolate());
4582 v8::V8::AddMessageListener(receive_message); 4592 v8::V8::AddMessageListener(receive_message);
4583 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4593 Local<ObjectTemplate> templ = ObjectTemplate::New();
4584 templ->Set(v8_str("ThrowFromC"), 4594 templ->Set(v8_str("ThrowFromC"),
4585 v8::FunctionTemplate::New(ThrowFromC)); 4595 v8::FunctionTemplate::New(ThrowFromC));
4586 LocalContext context(0, templ); 4596 LocalContext context(0, templ);
4587 CompileRun("ThrowFromC();"); 4597 CompileRun("ThrowFromC();");
4588 CHECK(message_received); 4598 CHECK(message_received);
4589 v8::V8::RemoveMessageListeners(receive_message); 4599 v8::V8::RemoveMessageListeners(receive_message);
4590 } 4600 }
4591 4601
4592 4602
4593 TEST(APIThrowMessageAndVerboseTryCatch) { 4603 TEST(APIThrowMessageAndVerboseTryCatch) {
4594 message_received = false; 4604 message_received = false;
4595 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4605 v8::HandleScope scope(CcTest::isolate());
4596 v8::V8::AddMessageListener(receive_message); 4606 v8::V8::AddMessageListener(receive_message);
4597 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4607 Local<ObjectTemplate> templ = ObjectTemplate::New();
4598 templ->Set(v8_str("ThrowFromC"), 4608 templ->Set(v8_str("ThrowFromC"),
4599 v8::FunctionTemplate::New(ThrowFromC)); 4609 v8::FunctionTemplate::New(ThrowFromC));
4600 LocalContext context(0, templ); 4610 LocalContext context(0, templ);
4601 v8::TryCatch try_catch; 4611 v8::TryCatch try_catch;
4602 try_catch.SetVerbose(true); 4612 try_catch.SetVerbose(true);
4603 Local<Value> result = CompileRun("ThrowFromC();"); 4613 Local<Value> result = CompileRun("ThrowFromC();");
4604 CHECK(try_catch.HasCaught()); 4614 CHECK(try_catch.HasCaught());
4605 CHECK(result.IsEmpty()); 4615 CHECK(result.IsEmpty());
(...skipping 11 matching lines...) Expand all
4617 try_catch.SetVerbose(true); 4627 try_catch.SetVerbose(true);
4618 Local<Value> result = CompileRun("function foo() { foo(); } foo();"); 4628 Local<Value> result = CompileRun("function foo() { foo(); } foo();");
4619 CHECK(try_catch.HasCaught()); 4629 CHECK(try_catch.HasCaught());
4620 CHECK(result.IsEmpty()); 4630 CHECK(result.IsEmpty());
4621 CHECK(message_received); 4631 CHECK(message_received);
4622 v8::V8::RemoveMessageListeners(receive_message); 4632 v8::V8::RemoveMessageListeners(receive_message);
4623 } 4633 }
4624 4634
4625 4635
4626 THREADED_TEST(ExternalScriptException) { 4636 THREADED_TEST(ExternalScriptException) {
4627 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4637 v8::HandleScope scope(CcTest::isolate());
4628 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4638 Local<ObjectTemplate> templ = ObjectTemplate::New();
4629 templ->Set(v8_str("ThrowFromC"), 4639 templ->Set(v8_str("ThrowFromC"),
4630 v8::FunctionTemplate::New(ThrowFromC)); 4640 v8::FunctionTemplate::New(ThrowFromC));
4631 LocalContext context(0, templ); 4641 LocalContext context(0, templ);
4632 4642
4633 v8::TryCatch try_catch; 4643 v8::TryCatch try_catch;
4634 Local<Script> script 4644 Local<Script> script
4635 = Script::Compile(v8_str("ThrowFromC(); throw 'panama';")); 4645 = Script::Compile(v8_str("ThrowFromC(); throw 'panama';"));
4636 Local<Value> result = script->Run(); 4646 Local<Value> result = script->Run();
4637 CHECK(result.IsEmpty()); 4647 CHECK(result.IsEmpty());
(...skipping 19 matching lines...) Expand all
4657 args[1], 4667 args[1],
4658 args[2], 4668 args[2],
4659 args[3] }; 4669 args[3] };
4660 if (count % cInterval == 0) { 4670 if (count % cInterval == 0) {
4661 v8::TryCatch try_catch; 4671 v8::TryCatch try_catch;
4662 Local<Value> result = fun.As<Function>()->Call(global, 4, argv); 4672 Local<Value> result = fun.As<Function>()->Call(global, 4, argv);
4663 int expected = args[3]->Int32Value(); 4673 int expected = args[3]->Int32Value();
4664 if (try_catch.HasCaught()) { 4674 if (try_catch.HasCaught()) {
4665 CHECK_EQ(expected, count); 4675 CHECK_EQ(expected, count);
4666 CHECK(result.IsEmpty()); 4676 CHECK(result.IsEmpty());
4667 CHECK(!i::Isolate::Current()->has_scheduled_exception()); 4677 CHECK(!CcTest::i_isolate()->has_scheduled_exception());
4668 } else { 4678 } else {
4669 CHECK_NE(expected, count); 4679 CHECK_NE(expected, count);
4670 } 4680 }
4671 args.GetReturnValue().Set(result); 4681 args.GetReturnValue().Set(result);
4672 return; 4682 return;
4673 } else { 4683 } else {
4674 args.GetReturnValue().Set(fun.As<Function>()->Call(global, 4, argv)); 4684 args.GetReturnValue().Set(fun.As<Function>()->Call(global, 4, argv));
4675 return; 4685 return;
4676 } 4686 }
4677 } 4687 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
4721 // 4731 //
4722 // Each entry is an activation, either JS or C. The index is the count at that 4732 // Each entry is an activation, either JS or C. The index is the count at that
4723 // level. Stars identify activations with exception handlers, the @ identifies 4733 // level. Stars identify activations with exception handlers, the @ identifies
4724 // the exception handler that should catch the exception. 4734 // the exception handler that should catch the exception.
4725 // 4735 //
4726 // BUG(271): Some of the exception propagation does not work on the 4736 // BUG(271): Some of the exception propagation does not work on the
4727 // ARM simulator because the simulator separates the C++ stack and the 4737 // ARM simulator because the simulator separates the C++ stack and the
4728 // JS stack. This test therefore fails on the simulator. The test is 4738 // JS stack. This test therefore fails on the simulator. The test is
4729 // not threaded to allow the threading tests to run on the simulator. 4739 // not threaded to allow the threading tests to run on the simulator.
4730 TEST(ExceptionOrder) { 4740 TEST(ExceptionOrder) {
4731 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4741 v8::HandleScope scope(CcTest::isolate());
4732 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4742 Local<ObjectTemplate> templ = ObjectTemplate::New();
4733 templ->Set(v8_str("check"), v8::FunctionTemplate::New(JSCheck)); 4743 templ->Set(v8_str("check"), v8::FunctionTemplate::New(JSCheck));
4734 templ->Set(v8_str("CThrowCountDown"), 4744 templ->Set(v8_str("CThrowCountDown"),
4735 v8::FunctionTemplate::New(CThrowCountDown)); 4745 v8::FunctionTemplate::New(CThrowCountDown));
4736 LocalContext context(0, templ); 4746 LocalContext context(0, templ);
4737 CompileRun( 4747 CompileRun(
4738 "function JSThrowCountDown(count, jsInterval, cInterval, expected) {" 4748 "function JSThrowCountDown(count, jsInterval, cInterval, expected) {"
4739 " if (count == 0) throw 'FromJS';" 4749 " if (count == 0) throw 'FromJS';"
4740 " if (count % jsInterval == 0) {" 4750 " if (count % jsInterval == 0) {"
4741 " try {" 4751 " try {"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
4785 4795
4786 4796
4787 void ThrowValue(const v8::FunctionCallbackInfo<v8::Value>& args) { 4797 void ThrowValue(const v8::FunctionCallbackInfo<v8::Value>& args) {
4788 ApiTestFuzzer::Fuzz(); 4798 ApiTestFuzzer::Fuzz();
4789 CHECK_EQ(1, args.Length()); 4799 CHECK_EQ(1, args.Length());
4790 v8::ThrowException(args[0]); 4800 v8::ThrowException(args[0]);
4791 } 4801 }
4792 4802
4793 4803
4794 THREADED_TEST(ThrowValues) { 4804 THREADED_TEST(ThrowValues) {
4795 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4805 v8::HandleScope scope(CcTest::isolate());
4796 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4806 Local<ObjectTemplate> templ = ObjectTemplate::New();
4797 templ->Set(v8_str("Throw"), v8::FunctionTemplate::New(ThrowValue)); 4807 templ->Set(v8_str("Throw"), v8::FunctionTemplate::New(ThrowValue));
4798 LocalContext context(0, templ); 4808 LocalContext context(0, templ);
4799 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 4809 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun(
4800 "function Run(obj) {" 4810 "function Run(obj) {"
4801 " try {" 4811 " try {"
4802 " Throw(obj);" 4812 " Throw(obj);"
4803 " } catch (e) {" 4813 " } catch (e) {"
4804 " return e;" 4814 " return e;"
4805 " }" 4815 " }"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
4923 try_catch.ReThrow(); 4933 try_catch.ReThrow();
4924 } 4934 }
4925 4935
4926 4936
4927 // This test ensures that an outer TryCatch in the following situation: 4937 // This test ensures that an outer TryCatch in the following situation:
4928 // C++/TryCatch -> JS -> C++/TryCatch -> JS w/ SyntaxError 4938 // C++/TryCatch -> JS -> C++/TryCatch -> JS w/ SyntaxError
4929 // does not clobber the Message object generated for the inner TryCatch. 4939 // does not clobber the Message object generated for the inner TryCatch.
4930 // This exercises the ability of TryCatch.ReThrow() to restore the 4940 // This exercises the ability of TryCatch.ReThrow() to restore the
4931 // inner pending Message before throwing the exception again. 4941 // inner pending Message before throwing the exception again.
4932 TEST(TryCatchMixedNesting) { 4942 TEST(TryCatchMixedNesting) {
4933 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4943 v8::HandleScope scope(CcTest::isolate());
4934 v8::V8::Initialize(); 4944 v8::V8::Initialize();
4935 v8::TryCatch try_catch; 4945 v8::TryCatch try_catch;
4936 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4946 Local<ObjectTemplate> templ = ObjectTemplate::New();
4937 templ->Set(v8_str("TryCatchMixedNestingHelper"), 4947 templ->Set(v8_str("TryCatchMixedNestingHelper"),
4938 v8::FunctionTemplate::New(TryCatchMixedNestingHelper)); 4948 v8::FunctionTemplate::New(TryCatchMixedNestingHelper));
4939 LocalContext context(0, templ); 4949 LocalContext context(0, templ);
4940 CompileRunWithOrigin("TryCatchMixedNestingHelper();\n", "outer", 1, 1); 4950 CompileRunWithOrigin("TryCatchMixedNestingHelper();\n", "outer", 1, 1);
4941 TryCatchMixedNestingCheck(&try_catch); 4951 TryCatchMixedNestingCheck(&try_catch);
4942 } 4952 }
4943 4953
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
5049 // Make sure that it is not possible to redefine again 5059 // Make sure that it is not possible to redefine again
5050 v8::TryCatch try_catch; 5060 v8::TryCatch try_catch;
5051 result = script_define->Run(); 5061 result = script_define->Run();
5052 CHECK(try_catch.HasCaught()); 5062 CHECK(try_catch.HasCaught());
5053 String::Utf8Value exception_value(try_catch.Exception()); 5063 String::Utf8Value exception_value(try_catch.Exception());
5054 CHECK_EQ(*exception_value, "TypeError: Cannot redefine property: x"); 5064 CHECK_EQ(*exception_value, "TypeError: Cannot redefine property: x");
5055 } 5065 }
5056 5066
5057 5067
5058 THREADED_TEST(DefinePropertyOnDefineGetterSetter) { 5068 THREADED_TEST(DefinePropertyOnDefineGetterSetter) {
5059 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5069 v8::HandleScope scope(CcTest::isolate());
5060 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5070 Local<ObjectTemplate> templ = ObjectTemplate::New();
5061 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); 5071 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"));
5062 LocalContext context; 5072 LocalContext context;
5063 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5073 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5064 5074
5065 Local<Script> script_desc = Script::Compile(v8_str("var prop =" 5075 Local<Script> script_desc = Script::Compile(v8_str("var prop ="
5066 "Object.getOwnPropertyDescriptor( " 5076 "Object.getOwnPropertyDescriptor( "
5067 "obj, 'x');" 5077 "obj, 'x');"
5068 "prop.configurable;")); 5078 "prop.configurable;"));
5069 Local<Value> result = script_desc->Run(); 5079 Local<Value> result = script_desc->Run();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
5101 } 5111 }
5102 5112
5103 5113
5104 static v8::Handle<v8::Object> GetGlobalProperty(LocalContext* context, 5114 static v8::Handle<v8::Object> GetGlobalProperty(LocalContext* context,
5105 char const* name) { 5115 char const* name) {
5106 return v8::Handle<v8::Object>::Cast((*context)->Global()->Get(v8_str(name))); 5116 return v8::Handle<v8::Object>::Cast((*context)->Global()->Get(v8_str(name)));
5107 } 5117 }
5108 5118
5109 5119
5110 THREADED_TEST(DefineAPIAccessorOnObject) { 5120 THREADED_TEST(DefineAPIAccessorOnObject) {
5111 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5121 v8::HandleScope scope(CcTest::isolate());
5112 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5122 Local<ObjectTemplate> templ = ObjectTemplate::New();
5113 LocalContext context; 5123 LocalContext context;
5114 5124
5115 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); 5125 context->Global()->Set(v8_str("obj1"), templ->NewInstance());
5116 CompileRun("var obj2 = {};"); 5126 CompileRun("var obj2 = {};");
5117 5127
5118 CHECK(CompileRun("obj1.x")->IsUndefined()); 5128 CHECK(CompileRun("obj1.x")->IsUndefined());
5119 CHECK(CompileRun("obj2.x")->IsUndefined()); 5129 CHECK(CompileRun("obj2.x")->IsUndefined());
5120 5130
5121 CHECK(GetGlobalProperty(&context, "obj1")-> 5131 CHECK(GetGlobalProperty(&context, "obj1")->
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
5175 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); 5185 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")));
5176 CHECK(!GetGlobalProperty(&context, "obj2")-> 5186 CHECK(!GetGlobalProperty(&context, "obj2")->
5177 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); 5187 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")));
5178 5188
5179 ExpectString("obj1.x", "z"); 5189 ExpectString("obj1.x", "z");
5180 ExpectString("obj2.x", "z"); 5190 ExpectString("obj2.x", "z");
5181 } 5191 }
5182 5192
5183 5193
5184 THREADED_TEST(DontDeleteAPIAccessorsCannotBeOverriden) { 5194 THREADED_TEST(DontDeleteAPIAccessorsCannotBeOverriden) {
5185 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5195 v8::HandleScope scope(CcTest::isolate());
5186 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5196 Local<ObjectTemplate> templ = ObjectTemplate::New();
5187 LocalContext context; 5197 LocalContext context;
5188 5198
5189 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); 5199 context->Global()->Set(v8_str("obj1"), templ->NewInstance());
5190 CompileRun("var obj2 = {};"); 5200 CompileRun("var obj2 = {};");
5191 5201
5192 CHECK(GetGlobalProperty(&context, "obj1")->SetAccessor( 5202 CHECK(GetGlobalProperty(&context, "obj1")->SetAccessor(
5193 v8_str("x"), 5203 v8_str("x"),
5194 GetXValue, NULL, 5204 GetXValue, NULL,
5195 v8_str("donut"), v8::DEFAULT, v8::DontDelete)); 5205 v8_str("donut"), v8::DEFAULT, v8::DontDelete));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
5231 static void Get239Value(Local<String> name, 5241 static void Get239Value(Local<String> name,
5232 const v8::PropertyCallbackInfo<v8::Value>& info) { 5242 const v8::PropertyCallbackInfo<v8::Value>& info) {
5233 ApiTestFuzzer::Fuzz(); 5243 ApiTestFuzzer::Fuzz();
5234 CHECK_EQ(info.Data(), v8_str("donut")); 5244 CHECK_EQ(info.Data(), v8_str("donut"));
5235 CHECK_EQ(name, v8_str("239")); 5245 CHECK_EQ(name, v8_str("239"));
5236 info.GetReturnValue().Set(name); 5246 info.GetReturnValue().Set(name);
5237 } 5247 }
5238 5248
5239 5249
5240 THREADED_TEST(ElementAPIAccessor) { 5250 THREADED_TEST(ElementAPIAccessor) {
5241 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5251 v8::HandleScope scope(CcTest::isolate());
5242 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5252 Local<ObjectTemplate> templ = ObjectTemplate::New();
5243 LocalContext context; 5253 LocalContext context;
5244 5254
5245 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); 5255 context->Global()->Set(v8_str("obj1"), templ->NewInstance());
5246 CompileRun("var obj2 = {};"); 5256 CompileRun("var obj2 = {};");
5247 5257
5248 CHECK(GetGlobalProperty(&context, "obj1")->SetAccessor( 5258 CHECK(GetGlobalProperty(&context, "obj1")->SetAccessor(
5249 v8_str("239"), 5259 v8_str("239"),
5250 Get239Value, NULL, 5260 Get239Value, NULL,
5251 v8_str("donut"))); 5261 v8_str("donut")));
(...skipping 17 matching lines...) Expand all
5269 const v8::PropertyCallbackInfo<void>& info) { 5279 const v8::PropertyCallbackInfo<void>& info) {
5270 CHECK_EQ(value, v8_num(4)); 5280 CHECK_EQ(value, v8_num(4));
5271 CHECK_EQ(info.Data(), v8_str("donut")); 5281 CHECK_EQ(info.Data(), v8_str("donut"));
5272 CHECK_EQ(name, v8_str("x")); 5282 CHECK_EQ(name, v8_str("x"));
5273 CHECK(xValue.IsEmpty()); 5283 CHECK(xValue.IsEmpty());
5274 xValue.Reset(info.GetIsolate(), value); 5284 xValue.Reset(info.GetIsolate(), value);
5275 } 5285 }
5276 5286
5277 5287
5278 THREADED_TEST(SimplePropertyWrite) { 5288 THREADED_TEST(SimplePropertyWrite) {
5279 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5289 v8::HandleScope scope(CcTest::isolate());
5280 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5290 Local<ObjectTemplate> templ = ObjectTemplate::New();
5281 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut")); 5291 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut"));
5282 LocalContext context; 5292 LocalContext context;
5283 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5293 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5284 Local<Script> script = Script::Compile(v8_str("obj.x = 4")); 5294 Local<Script> script = Script::Compile(v8_str("obj.x = 4"));
5285 for (int i = 0; i < 10; i++) { 5295 for (int i = 0; i < 10; i++) {
5286 CHECK(xValue.IsEmpty()); 5296 CHECK(xValue.IsEmpty());
5287 script->Run(); 5297 script->Run();
5288 CHECK_EQ(v8_num(4), Local<Value>::New(v8::Isolate::GetCurrent(), xValue)); 5298 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue));
5289 xValue.Dispose(); 5299 xValue.Dispose();
5290 xValue.Clear(); 5300 xValue.Clear();
5291 } 5301 }
5292 } 5302 }
5293 5303
5294 5304
5295 THREADED_TEST(SetterOnly) { 5305 THREADED_TEST(SetterOnly) {
5296 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5306 v8::HandleScope scope(CcTest::isolate());
5297 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5307 Local<ObjectTemplate> templ = ObjectTemplate::New();
5298 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut")); 5308 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut"));
5299 LocalContext context; 5309 LocalContext context;
5300 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5310 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5301 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); 5311 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x"));
5302 for (int i = 0; i < 10; i++) { 5312 for (int i = 0; i < 10; i++) {
5303 CHECK(xValue.IsEmpty()); 5313 CHECK(xValue.IsEmpty());
5304 script->Run(); 5314 script->Run();
5305 CHECK_EQ(v8_num(4), Local<Value>::New(v8::Isolate::GetCurrent(), xValue)); 5315 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue));
5306 xValue.Dispose(); 5316 xValue.Dispose();
5307 xValue.Clear(); 5317 xValue.Clear();
5308 } 5318 }
5309 } 5319 }
5310 5320
5311 5321
5312 THREADED_TEST(NoAccessors) { 5322 THREADED_TEST(NoAccessors) {
5313 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5323 v8::HandleScope scope(CcTest::isolate());
5314 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5324 Local<ObjectTemplate> templ = ObjectTemplate::New();
5315 templ->SetAccessor(v8_str("x"), 5325 templ->SetAccessor(v8_str("x"),
5316 static_cast<v8::AccessorGetterCallback>(NULL), 5326 static_cast<v8::AccessorGetterCallback>(NULL),
5317 NULL, 5327 NULL,
5318 v8_str("donut")); 5328 v8_str("donut"));
5319 LocalContext context; 5329 LocalContext context;
5320 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5330 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5321 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); 5331 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x"));
5322 for (int i = 0; i < 10; i++) { 5332 for (int i = 0; i < 10; i++) {
5323 script->Run(); 5333 script->Run();
5324 } 5334 }
5325 } 5335 }
5326 5336
5327 5337
5328 static void XPropertyGetter(Local<String> property, 5338 static void XPropertyGetter(Local<String> property,
5329 const v8::PropertyCallbackInfo<v8::Value>& info) { 5339 const v8::PropertyCallbackInfo<v8::Value>& info) {
5330 ApiTestFuzzer::Fuzz(); 5340 ApiTestFuzzer::Fuzz();
5331 CHECK(info.Data()->IsUndefined()); 5341 CHECK(info.Data()->IsUndefined());
5332 info.GetReturnValue().Set(property); 5342 info.GetReturnValue().Set(property);
5333 } 5343 }
5334 5344
5335 5345
5336 THREADED_TEST(NamedInterceptorPropertyRead) { 5346 THREADED_TEST(NamedInterceptorPropertyRead) {
5337 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5347 v8::HandleScope scope(CcTest::isolate());
5338 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5348 Local<ObjectTemplate> templ = ObjectTemplate::New();
5339 templ->SetNamedPropertyHandler(XPropertyGetter); 5349 templ->SetNamedPropertyHandler(XPropertyGetter);
5340 LocalContext context; 5350 LocalContext context;
5341 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5351 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5342 Local<Script> script = Script::Compile(v8_str("obj.x")); 5352 Local<Script> script = Script::Compile(v8_str("obj.x"));
5343 for (int i = 0; i < 10; i++) { 5353 for (int i = 0; i < 10; i++) {
5344 Local<Value> result = script->Run(); 5354 Local<Value> result = script->Run();
5345 CHECK_EQ(result, v8_str("x")); 5355 CHECK_EQ(result, v8_str("x"));
5346 } 5356 }
5347 } 5357 }
5348 5358
5349 5359
5350 THREADED_TEST(NamedInterceptorDictionaryIC) { 5360 THREADED_TEST(NamedInterceptorDictionaryIC) {
5351 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5361 v8::HandleScope scope(CcTest::isolate());
5352 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5362 Local<ObjectTemplate> templ = ObjectTemplate::New();
5353 templ->SetNamedPropertyHandler(XPropertyGetter); 5363 templ->SetNamedPropertyHandler(XPropertyGetter);
5354 LocalContext context; 5364 LocalContext context;
5355 // Create an object with a named interceptor. 5365 // Create an object with a named interceptor.
5356 context->Global()->Set(v8_str("interceptor_obj"), templ->NewInstance()); 5366 context->Global()->Set(v8_str("interceptor_obj"), templ->NewInstance());
5357 Local<Script> script = Script::Compile(v8_str("interceptor_obj.x")); 5367 Local<Script> script = Script::Compile(v8_str("interceptor_obj.x"));
5358 for (int i = 0; i < 10; i++) { 5368 for (int i = 0; i < 10; i++) {
5359 Local<Value> result = script->Run(); 5369 Local<Value> result = script->Run();
5360 CHECK_EQ(result, v8_str("x")); 5370 CHECK_EQ(result, v8_str("x"));
5361 } 5371 }
5362 // Create a slow case object and a function accessing a property in 5372 // Create a slow case object and a function accessing a property in
5363 // that slow case object (with dictionary probing in generated 5373 // that slow case object (with dictionary probing in generated
5364 // code). Then force object with a named interceptor into slow-case, 5374 // code). Then force object with a named interceptor into slow-case,
5365 // pass it to the function, and check that the interceptor is called 5375 // pass it to the function, and check that the interceptor is called
5366 // instead of accessing the local property. 5376 // instead of accessing the local property.
5367 Local<Value> result = 5377 Local<Value> result =
5368 CompileRun("function get_x(o) { return o.x; };" 5378 CompileRun("function get_x(o) { return o.x; };"
5369 "var obj = { x : 42, y : 0 };" 5379 "var obj = { x : 42, y : 0 };"
5370 "delete obj.y;" 5380 "delete obj.y;"
5371 "for (var i = 0; i < 10; i++) get_x(obj);" 5381 "for (var i = 0; i < 10; i++) get_x(obj);"
5372 "interceptor_obj.x = 42;" 5382 "interceptor_obj.x = 42;"
5373 "interceptor_obj.y = 10;" 5383 "interceptor_obj.y = 10;"
5374 "delete interceptor_obj.y;" 5384 "delete interceptor_obj.y;"
5375 "get_x(interceptor_obj)"); 5385 "get_x(interceptor_obj)");
5376 CHECK_EQ(result, v8_str("x")); 5386 CHECK_EQ(result, v8_str("x"));
5377 } 5387 }
5378 5388
5379 5389
5380 THREADED_TEST(NamedInterceptorDictionaryICMultipleContext) { 5390 THREADED_TEST(NamedInterceptorDictionaryICMultipleContext) {
5381 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 5391 v8::Isolate* isolate = CcTest::isolate();
5382 v8::HandleScope scope(isolate); 5392 v8::HandleScope scope(isolate);
5383 v8::Local<Context> context1 = Context::New(isolate); 5393 v8::Local<Context> context1 = Context::New(isolate);
5384 5394
5385 context1->Enter(); 5395 context1->Enter();
5386 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5396 Local<ObjectTemplate> templ = ObjectTemplate::New();
5387 templ->SetNamedPropertyHandler(XPropertyGetter); 5397 templ->SetNamedPropertyHandler(XPropertyGetter);
5388 // Create an object with a named interceptor. 5398 // Create an object with a named interceptor.
5389 v8::Local<v8::Object> object = templ->NewInstance(); 5399 v8::Local<v8::Object> object = templ->NewInstance();
5390 context1->Global()->Set(v8_str("interceptor_obj"), object); 5400 context1->Global()->Set(v8_str("interceptor_obj"), object);
5391 5401
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
5423 const v8::PropertyCallbackInfo<v8::Value>& info) { 5433 const v8::PropertyCallbackInfo<v8::Value>& info) {
5424 // Set x on the prototype object and do not handle the get request. 5434 // Set x on the prototype object and do not handle the get request.
5425 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype(); 5435 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype();
5426 proto.As<v8::Object>()->Set(v8_str("x"), v8::Integer::New(23)); 5436 proto.As<v8::Object>()->Set(v8_str("x"), v8::Integer::New(23));
5427 } 5437 }
5428 5438
5429 5439
5430 // This is a regression test for http://crbug.com/20104. Map 5440 // This is a regression test for http://crbug.com/20104. Map
5431 // transitions should not interfere with post interceptor lookup. 5441 // transitions should not interfere with post interceptor lookup.
5432 THREADED_TEST(NamedInterceptorMapTransitionRead) { 5442 THREADED_TEST(NamedInterceptorMapTransitionRead) {
5433 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5443 v8::HandleScope scope(CcTest::isolate());
5434 Local<v8::FunctionTemplate> function_template = v8::FunctionTemplate::New(); 5444 Local<v8::FunctionTemplate> function_template = v8::FunctionTemplate::New();
5435 Local<v8::ObjectTemplate> instance_template 5445 Local<v8::ObjectTemplate> instance_template
5436 = function_template->InstanceTemplate(); 5446 = function_template->InstanceTemplate();
5437 instance_template->SetNamedPropertyHandler(SetXOnPrototypeGetter); 5447 instance_template->SetNamedPropertyHandler(SetXOnPrototypeGetter);
5438 LocalContext context; 5448 LocalContext context;
5439 context->Global()->Set(v8_str("F"), function_template->GetFunction()); 5449 context->Global()->Set(v8_str("F"), function_template->GetFunction());
5440 // Create an instance of F and introduce a map transition for x. 5450 // Create an instance of F and introduce a map transition for x.
5441 CompileRun("var o = new F(); o.x = 23;"); 5451 CompileRun("var o = new F(); o.x = 23;");
5442 // Create an instance of F and invoke the getter. The result should be 23. 5452 // Create an instance of F and invoke the getter. The result should be 23.
5443 Local<Value> result = CompileRun("o = new F(); o.x"); 5453 Local<Value> result = CompileRun("o = new F(); o.x");
(...skipping 16 matching lines...) Expand all
5460 Local<Value> value, 5470 Local<Value> value,
5461 const v8::PropertyCallbackInfo<v8::Value>& info) { 5471 const v8::PropertyCallbackInfo<v8::Value>& info) {
5462 ApiTestFuzzer::Fuzz(); 5472 ApiTestFuzzer::Fuzz();
5463 if (index == 39) { 5473 if (index == 39) {
5464 info.GetReturnValue().Set(value); 5474 info.GetReturnValue().Set(value);
5465 } 5475 }
5466 } 5476 }
5467 5477
5468 5478
5469 THREADED_TEST(IndexedInterceptorWithIndexedAccessor) { 5479 THREADED_TEST(IndexedInterceptorWithIndexedAccessor) {
5470 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5480 v8::HandleScope scope(CcTest::isolate());
5471 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5481 Local<ObjectTemplate> templ = ObjectTemplate::New();
5472 templ->SetIndexedPropertyHandler(IndexedPropertyGetter, 5482 templ->SetIndexedPropertyHandler(IndexedPropertyGetter,
5473 IndexedPropertySetter); 5483 IndexedPropertySetter);
5474 LocalContext context; 5484 LocalContext context;
5475 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5485 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5476 Local<Script> getter_script = Script::Compile(v8_str( 5486 Local<Script> getter_script = Script::Compile(v8_str(
5477 "obj.__defineGetter__(\"3\", function(){return 5;});obj[3];")); 5487 "obj.__defineGetter__(\"3\", function(){return 5;});obj[3];"));
5478 Local<Script> setter_script = Script::Compile(v8_str( 5488 Local<Script> setter_script = Script::Compile(v8_str(
5479 "obj.__defineSetter__(\"17\", function(val){this.foo = val;});" 5489 "obj.__defineSetter__(\"17\", function(val){this.foo = val;});"
5480 "obj[17] = 23;" 5490 "obj[17] = 23;"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
5525 "for(i = 0; i < 80000; i++) { keys[i] = i; };" 5535 "for(i = 0; i < 80000; i++) { keys[i] = i; };"
5526 "keys.length = 25; keys;")); 5536 "keys.length = 25; keys;"));
5527 Local<Value> result = indexed_property_names_script->Run(); 5537 Local<Value> result = indexed_property_names_script->Run();
5528 info.GetReturnValue().Set(Local<v8::Array>::Cast(result)); 5538 info.GetReturnValue().Set(Local<v8::Array>::Cast(result));
5529 } 5539 }
5530 5540
5531 5541
5532 // Make sure that the the interceptor code in the runtime properly handles 5542 // Make sure that the the interceptor code in the runtime properly handles
5533 // merging property name lists for double-array-backed arrays. 5543 // merging property name lists for double-array-backed arrays.
5534 THREADED_TEST(IndexedInterceptorUnboxedDoubleWithIndexedAccessor) { 5544 THREADED_TEST(IndexedInterceptorUnboxedDoubleWithIndexedAccessor) {
5535 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5545 v8::HandleScope scope(CcTest::isolate());
5536 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5546 Local<ObjectTemplate> templ = ObjectTemplate::New();
5537 templ->SetIndexedPropertyHandler(UnboxedDoubleIndexedPropertyGetter, 5547 templ->SetIndexedPropertyHandler(UnboxedDoubleIndexedPropertyGetter,
5538 UnboxedDoubleIndexedPropertySetter, 5548 UnboxedDoubleIndexedPropertySetter,
5539 0, 5549 0,
5540 0, 5550 0,
5541 UnboxedDoubleIndexedPropertyEnumerator); 5551 UnboxedDoubleIndexedPropertyEnumerator);
5542 LocalContext context; 5552 LocalContext context;
5543 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5553 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5544 // When obj is created, force it to be Stored in a FastDoubleArray. 5554 // When obj is created, force it to be Stored in a FastDoubleArray.
5545 Local<Script> create_unboxed_double_script = Script::Compile(v8_str( 5555 Local<Script> create_unboxed_double_script = Script::Compile(v8_str(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
5581 ApiTestFuzzer::Fuzz(); 5591 ApiTestFuzzer::Fuzz();
5582 if (index < 4) { 5592 if (index < 4) {
5583 info.GetReturnValue().Set(v8_num(index)); 5593 info.GetReturnValue().Set(v8_num(index));
5584 } 5594 }
5585 } 5595 }
5586 5596
5587 5597
5588 // Make sure that the the interceptor code in the runtime properly handles 5598 // Make sure that the the interceptor code in the runtime properly handles
5589 // merging property name lists for non-string arguments arrays. 5599 // merging property name lists for non-string arguments arrays.
5590 THREADED_TEST(IndexedInterceptorNonStrictArgsWithIndexedAccessor) { 5600 THREADED_TEST(IndexedInterceptorNonStrictArgsWithIndexedAccessor) {
5591 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5601 v8::HandleScope scope(CcTest::isolate());
5592 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5602 Local<ObjectTemplate> templ = ObjectTemplate::New();
5593 templ->SetIndexedPropertyHandler(NonStrictIndexedPropertyGetter, 5603 templ->SetIndexedPropertyHandler(NonStrictIndexedPropertyGetter,
5594 0, 5604 0,
5595 0, 5605 0,
5596 0, 5606 0,
5597 NonStrictArgsIndexedPropertyEnumerator); 5607 NonStrictArgsIndexedPropertyEnumerator);
5598 LocalContext context; 5608 LocalContext context;
5599 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5609 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5600 Local<Script> create_args_script = 5610 Local<Script> create_args_script =
5601 Script::Compile(v8_str( 5611 Script::Compile(v8_str(
5602 "var key_count = 0;" 5612 "var key_count = 0;"
5603 "for (x in obj) {key_count++;} key_count;")); 5613 "for (x in obj) {key_count++;} key_count;"));
5604 Local<Value> result = create_args_script->Run(); 5614 Local<Value> result = create_args_script->Run();
5605 CHECK_EQ(v8_num(4), result); 5615 CHECK_EQ(v8_num(4), result);
5606 } 5616 }
5607 5617
5608 5618
5609 static void IdentityIndexedPropertyGetter( 5619 static void IdentityIndexedPropertyGetter(
5610 uint32_t index, 5620 uint32_t index,
5611 const v8::PropertyCallbackInfo<v8::Value>& info) { 5621 const v8::PropertyCallbackInfo<v8::Value>& info) {
5612 info.GetReturnValue().Set(index); 5622 info.GetReturnValue().Set(index);
5613 } 5623 }
5614 5624
5615 5625
5616 THREADED_TEST(IndexedInterceptorWithGetOwnPropertyDescriptor) { 5626 THREADED_TEST(IndexedInterceptorWithGetOwnPropertyDescriptor) {
5617 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5627 v8::HandleScope scope(CcTest::isolate());
5618 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5628 Local<ObjectTemplate> templ = ObjectTemplate::New();
5619 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 5629 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
5620 5630
5621 LocalContext context; 5631 LocalContext context;
5622 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5632 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5623 5633
5624 // Check fast object case. 5634 // Check fast object case.
5625 const char* fast_case_code = 5635 const char* fast_case_code =
5626 "Object.getOwnPropertyDescriptor(obj, 0).value.toString()"; 5636 "Object.getOwnPropertyDescriptor(obj, 0).value.toString()";
5627 ExpectString(fast_case_code, "0"); 5637 ExpectString(fast_case_code, "0");
5628 5638
5629 // Check slow case. 5639 // Check slow case.
5630 const char* slow_case_code = 5640 const char* slow_case_code =
5631 "obj.x = 1; delete obj.x;" 5641 "obj.x = 1; delete obj.x;"
5632 "Object.getOwnPropertyDescriptor(obj, 1).value.toString()"; 5642 "Object.getOwnPropertyDescriptor(obj, 1).value.toString()";
5633 ExpectString(slow_case_code, "1"); 5643 ExpectString(slow_case_code, "1");
5634 } 5644 }
5635 5645
5636 5646
5637 THREADED_TEST(IndexedInterceptorWithNoSetter) { 5647 THREADED_TEST(IndexedInterceptorWithNoSetter) {
5638 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5648 v8::HandleScope scope(CcTest::isolate());
5639 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5649 Local<ObjectTemplate> templ = ObjectTemplate::New();
5640 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 5650 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
5641 5651
5642 LocalContext context; 5652 LocalContext context;
5643 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5653 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5644 5654
5645 const char* code = 5655 const char* code =
5646 "try {" 5656 "try {"
5647 " obj[0] = 239;" 5657 " obj[0] = 239;"
5648 " for (var i = 0; i < 100; i++) {" 5658 " for (var i = 0; i < 100; i++) {"
5649 " var v = obj[0];" 5659 " var v = obj[0];"
5650 " if (v != 0) throw 'Wrong value ' + v + ' at iteration ' + i;" 5660 " if (v != 0) throw 'Wrong value ' + v + ' at iteration ' + i;"
5651 " }" 5661 " }"
5652 " 'PASSED'" 5662 " 'PASSED'"
5653 "} catch(e) {" 5663 "} catch(e) {"
5654 " e" 5664 " e"
5655 "}"; 5665 "}";
5656 ExpectString(code, "PASSED"); 5666 ExpectString(code, "PASSED");
5657 } 5667 }
5658 5668
5659 5669
5660 THREADED_TEST(IndexedInterceptorWithAccessorCheck) { 5670 THREADED_TEST(IndexedInterceptorWithAccessorCheck) {
5661 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5671 v8::HandleScope scope(CcTest::isolate());
5662 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5672 Local<ObjectTemplate> templ = ObjectTemplate::New();
5663 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 5673 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
5664 5674
5665 LocalContext context; 5675 LocalContext context;
5666 Local<v8::Object> obj = templ->NewInstance(); 5676 Local<v8::Object> obj = templ->NewInstance();
5667 obj->TurnOnAccessCheck(); 5677 obj->TurnOnAccessCheck();
5668 context->Global()->Set(v8_str("obj"), obj); 5678 context->Global()->Set(v8_str("obj"), obj);
5669 5679
5670 const char* code = 5680 const char* code =
5671 "try {" 5681 "try {"
5672 " for (var i = 0; i < 100; i++) {" 5682 " for (var i = 0; i < 100; i++) {"
5673 " var v = obj[0];" 5683 " var v = obj[0];"
5674 " if (v != undefined) throw 'Wrong value ' + v + ' at iteration ' + i;" 5684 " if (v != undefined) throw 'Wrong value ' + v + ' at iteration ' + i;"
5675 " }" 5685 " }"
5676 " 'PASSED'" 5686 " 'PASSED'"
5677 "} catch(e) {" 5687 "} catch(e) {"
5678 " e" 5688 " e"
5679 "}"; 5689 "}";
5680 ExpectString(code, "PASSED"); 5690 ExpectString(code, "PASSED");
5681 } 5691 }
5682 5692
5683 5693
5684 THREADED_TEST(IndexedInterceptorWithAccessorCheckSwitchedOn) { 5694 THREADED_TEST(IndexedInterceptorWithAccessorCheckSwitchedOn) {
5685 i::FLAG_allow_natives_syntax = true; 5695 i::FLAG_allow_natives_syntax = true;
5686 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5696 v8::HandleScope scope(CcTest::isolate());
5687 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5697 Local<ObjectTemplate> templ = ObjectTemplate::New();
5688 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 5698 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
5689 5699
5690 LocalContext context; 5700 LocalContext context;
5691 Local<v8::Object> obj = templ->NewInstance(); 5701 Local<v8::Object> obj = templ->NewInstance();
5692 context->Global()->Set(v8_str("obj"), obj); 5702 context->Global()->Set(v8_str("obj"), obj);
5693 5703
5694 const char* code = 5704 const char* code =
5695 "try {" 5705 "try {"
5696 " for (var i = 0; i < 100; i++) {" 5706 " for (var i = 0; i < 100; i++) {"
5697 " var expected = i;" 5707 " var expected = i;"
5698 " if (i == 5) {" 5708 " if (i == 5) {"
5699 " %EnableAccessChecks(obj);" 5709 " %EnableAccessChecks(obj);"
5700 " expected = undefined;" 5710 " expected = undefined;"
5701 " }" 5711 " }"
5702 " var v = obj[i];" 5712 " var v = obj[i];"
5703 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" 5713 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
5704 " if (i == 5) %DisableAccessChecks(obj);" 5714 " if (i == 5) %DisableAccessChecks(obj);"
5705 " }" 5715 " }"
5706 " 'PASSED'" 5716 " 'PASSED'"
5707 "} catch(e) {" 5717 "} catch(e) {"
5708 " e" 5718 " e"
5709 "}"; 5719 "}";
5710 ExpectString(code, "PASSED"); 5720 ExpectString(code, "PASSED");
5711 } 5721 }
5712 5722
5713 5723
5714 THREADED_TEST(IndexedInterceptorWithDifferentIndices) { 5724 THREADED_TEST(IndexedInterceptorWithDifferentIndices) {
5715 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5725 v8::HandleScope scope(CcTest::isolate());
5716 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5726 Local<ObjectTemplate> templ = ObjectTemplate::New();
5717 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 5727 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
5718 5728
5719 LocalContext context; 5729 LocalContext context;
5720 Local<v8::Object> obj = templ->NewInstance(); 5730 Local<v8::Object> obj = templ->NewInstance();
5721 context->Global()->Set(v8_str("obj"), obj); 5731 context->Global()->Set(v8_str("obj"), obj);
5722 5732
5723 const char* code = 5733 const char* code =
5724 "try {" 5734 "try {"
5725 " for (var i = 0; i < 100; i++) {" 5735 " for (var i = 0; i < 100; i++) {"
5726 " var v = obj[i];" 5736 " var v = obj[i];"
5727 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;" 5737 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;"
5728 " }" 5738 " }"
5729 " 'PASSED'" 5739 " 'PASSED'"
5730 "} catch(e) {" 5740 "} catch(e) {"
5731 " e" 5741 " e"
5732 "}"; 5742 "}";
5733 ExpectString(code, "PASSED"); 5743 ExpectString(code, "PASSED");
5734 } 5744 }
5735 5745
5736 5746
5737 THREADED_TEST(IndexedInterceptorWithNegativeIndices) { 5747 THREADED_TEST(IndexedInterceptorWithNegativeIndices) {
5738 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5748 v8::HandleScope scope(CcTest::isolate());
5739 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5749 Local<ObjectTemplate> templ = ObjectTemplate::New();
5740 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 5750 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
5741 5751
5742 LocalContext context; 5752 LocalContext context;
5743 Local<v8::Object> obj = templ->NewInstance(); 5753 Local<v8::Object> obj = templ->NewInstance();
5744 context->Global()->Set(v8_str("obj"), obj); 5754 context->Global()->Set(v8_str("obj"), obj);
5745 5755
5746 const char* code = 5756 const char* code =
5747 "try {" 5757 "try {"
5748 " for (var i = 0; i < 100; i++) {" 5758 " for (var i = 0; i < 100; i++) {"
(...skipping 18 matching lines...) Expand all
5767 " }" 5777 " }"
5768 " 'PASSED'" 5778 " 'PASSED'"
5769 "} catch(e) {" 5779 "} catch(e) {"
5770 " e" 5780 " e"
5771 "}"; 5781 "}";
5772 ExpectString(code, "PASSED"); 5782 ExpectString(code, "PASSED");
5773 } 5783 }
5774 5784
5775 5785
5776 THREADED_TEST(IndexedInterceptorWithNotSmiLookup) { 5786 THREADED_TEST(IndexedInterceptorWithNotSmiLookup) {
5777 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5787 v8::HandleScope scope(CcTest::isolate());
5778 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5788 Local<ObjectTemplate> templ = ObjectTemplate::New();
5779 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 5789 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
5780 5790
5781 LocalContext context; 5791 LocalContext context;
5782 Local<v8::Object> obj = templ->NewInstance(); 5792 Local<v8::Object> obj = templ->NewInstance();
5783 context->Global()->Set(v8_str("obj"), obj); 5793 context->Global()->Set(v8_str("obj"), obj);
5784 5794
5785 const char* code = 5795 const char* code =
5786 "try {" 5796 "try {"
5787 " for (var i = 0; i < 100; i++) {" 5797 " for (var i = 0; i < 100; i++) {"
5788 " var expected = i;" 5798 " var expected = i;"
5789 " var key = i;" 5799 " var key = i;"
5790 " if (i == 50) {" 5800 " if (i == 50) {"
5791 " key = 'foobar';" 5801 " key = 'foobar';"
5792 " expected = undefined;" 5802 " expected = undefined;"
5793 " }" 5803 " }"
5794 " var v = obj[key];" 5804 " var v = obj[key];"
5795 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" 5805 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
5796 " }" 5806 " }"
5797 " 'PASSED'" 5807 " 'PASSED'"
5798 "} catch(e) {" 5808 "} catch(e) {"
5799 " e" 5809 " e"
5800 "}"; 5810 "}";
5801 ExpectString(code, "PASSED"); 5811 ExpectString(code, "PASSED");
5802 } 5812 }
5803 5813
5804 5814
5805 THREADED_TEST(IndexedInterceptorGoingMegamorphic) { 5815 THREADED_TEST(IndexedInterceptorGoingMegamorphic) {
5806 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5816 v8::HandleScope scope(CcTest::isolate());
5807 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5817 Local<ObjectTemplate> templ = ObjectTemplate::New();
5808 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 5818 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
5809 5819
5810 LocalContext context; 5820 LocalContext context;
5811 Local<v8::Object> obj = templ->NewInstance(); 5821 Local<v8::Object> obj = templ->NewInstance();
5812 context->Global()->Set(v8_str("obj"), obj); 5822 context->Global()->Set(v8_str("obj"), obj);
5813 5823
5814 const char* code = 5824 const char* code =
5815 "var original = obj;" 5825 "var original = obj;"
5816 "try {" 5826 "try {"
5817 " for (var i = 0; i < 100; i++) {" 5827 " for (var i = 0; i < 100; i++) {"
5818 " var expected = i;" 5828 " var expected = i;"
5819 " if (i == 50) {" 5829 " if (i == 50) {"
5820 " obj = {50: 'foobar'};" 5830 " obj = {50: 'foobar'};"
5821 " expected = 'foobar';" 5831 " expected = 'foobar';"
5822 " }" 5832 " }"
5823 " var v = obj[i];" 5833 " var v = obj[i];"
5824 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" 5834 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
5825 " if (i == 50) obj = original;" 5835 " if (i == 50) obj = original;"
5826 " }" 5836 " }"
5827 " 'PASSED'" 5837 " 'PASSED'"
5828 "} catch(e) {" 5838 "} catch(e) {"
5829 " e" 5839 " e"
5830 "}"; 5840 "}";
5831 ExpectString(code, "PASSED"); 5841 ExpectString(code, "PASSED");
5832 } 5842 }
5833 5843
5834 5844
5835 THREADED_TEST(IndexedInterceptorReceiverTurningSmi) { 5845 THREADED_TEST(IndexedInterceptorReceiverTurningSmi) {
5836 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5846 v8::HandleScope scope(CcTest::isolate());
5837 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5847 Local<ObjectTemplate> templ = ObjectTemplate::New();
5838 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 5848 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
5839 5849
5840 LocalContext context; 5850 LocalContext context;
5841 Local<v8::Object> obj = templ->NewInstance(); 5851 Local<v8::Object> obj = templ->NewInstance();
5842 context->Global()->Set(v8_str("obj"), obj); 5852 context->Global()->Set(v8_str("obj"), obj);
5843 5853
5844 const char* code = 5854 const char* code =
5845 "var original = obj;" 5855 "var original = obj;"
5846 "try {" 5856 "try {"
5847 " for (var i = 0; i < 100; i++) {" 5857 " for (var i = 0; i < 100; i++) {"
5848 " var expected = i;" 5858 " var expected = i;"
5849 " if (i == 5) {" 5859 " if (i == 5) {"
5850 " obj = 239;" 5860 " obj = 239;"
5851 " expected = undefined;" 5861 " expected = undefined;"
5852 " }" 5862 " }"
5853 " var v = obj[i];" 5863 " var v = obj[i];"
5854 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" 5864 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
5855 " if (i == 5) obj = original;" 5865 " if (i == 5) obj = original;"
5856 " }" 5866 " }"
5857 " 'PASSED'" 5867 " 'PASSED'"
5858 "} catch(e) {" 5868 "} catch(e) {"
5859 " e" 5869 " e"
5860 "}"; 5870 "}";
5861 ExpectString(code, "PASSED"); 5871 ExpectString(code, "PASSED");
5862 } 5872 }
5863 5873
5864 5874
5865 THREADED_TEST(IndexedInterceptorOnProto) { 5875 THREADED_TEST(IndexedInterceptorOnProto) {
5866 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5876 v8::HandleScope scope(CcTest::isolate());
5867 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5877 Local<ObjectTemplate> templ = ObjectTemplate::New();
5868 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 5878 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
5869 5879
5870 LocalContext context; 5880 LocalContext context;
5871 Local<v8::Object> obj = templ->NewInstance(); 5881 Local<v8::Object> obj = templ->NewInstance();
5872 context->Global()->Set(v8_str("obj"), obj); 5882 context->Global()->Set(v8_str("obj"), obj);
5873 5883
5874 const char* code = 5884 const char* code =
5875 "var o = {__proto__: obj};" 5885 "var o = {__proto__: obj};"
5876 "try {" 5886 "try {"
5877 " for (var i = 0; i < 100; i++) {" 5887 " for (var i = 0; i < 100; i++) {"
5878 " var v = o[i];" 5888 " var v = o[i];"
5879 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;" 5889 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;"
5880 " }" 5890 " }"
5881 " 'PASSED'" 5891 " 'PASSED'"
5882 "} catch(e) {" 5892 "} catch(e) {"
5883 " e" 5893 " e"
5884 "}"; 5894 "}";
5885 ExpectString(code, "PASSED"); 5895 ExpectString(code, "PASSED");
5886 } 5896 }
5887 5897
5888 5898
5889 THREADED_TEST(MultiContexts) { 5899 THREADED_TEST(MultiContexts) {
5890 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5900 v8::HandleScope scope(CcTest::isolate());
5891 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New(); 5901 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New();
5892 templ->Set(v8_str("dummy"), v8::FunctionTemplate::New(DummyCallHandler)); 5902 templ->Set(v8_str("dummy"), v8::FunctionTemplate::New(DummyCallHandler));
5893 5903
5894 Local<String> password = v8_str("Password"); 5904 Local<String> password = v8_str("Password");
5895 5905
5896 // Create an environment 5906 // Create an environment
5897 LocalContext context0(0, templ); 5907 LocalContext context0(0, templ);
5898 context0->SetSecurityToken(password); 5908 context0->SetSecurityToken(password);
5899 v8::Handle<v8::Object> global0 = context0->Global(); 5909 v8::Handle<v8::Object> global0 = context0->Global();
5900 global0->Set(v8_str("custom"), v8_num(1234)); 5910 global0->Set(v8_str("custom"), v8_num(1234));
(...skipping 15 matching lines...) Expand all
5916 CHECK_EQ(global1, global2); 5926 CHECK_EQ(global1, global2);
5917 CHECK_EQ(0, global1->Get(v8_str("custom"))->Int32Value()); 5927 CHECK_EQ(0, global1->Get(v8_str("custom"))->Int32Value());
5918 CHECK_EQ(0, global2->Get(v8_str("custom"))->Int32Value()); 5928 CHECK_EQ(0, global2->Get(v8_str("custom"))->Int32Value());
5919 } 5929 }
5920 5930
5921 5931
5922 THREADED_TEST(FunctionPrototypeAcrossContexts) { 5932 THREADED_TEST(FunctionPrototypeAcrossContexts) {
5923 // Make sure that functions created by cloning boilerplates cannot 5933 // Make sure that functions created by cloning boilerplates cannot
5924 // communicate through their __proto__ field. 5934 // communicate through their __proto__ field.
5925 5935
5926 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5936 v8::HandleScope scope(CcTest::isolate());
5927 5937
5928 LocalContext env0; 5938 LocalContext env0;
5929 v8::Handle<v8::Object> global0 = 5939 v8::Handle<v8::Object> global0 =
5930 env0->Global(); 5940 env0->Global();
5931 v8::Handle<v8::Object> object0 = 5941 v8::Handle<v8::Object> object0 =
5932 global0->Get(v8_str("Object")).As<v8::Object>(); 5942 global0->Get(v8_str("Object")).As<v8::Object>();
5933 v8::Handle<v8::Object> tostring0 = 5943 v8::Handle<v8::Object> tostring0 =
5934 object0->Get(v8_str("toString")).As<v8::Object>(); 5944 object0->Get(v8_str("toString")).As<v8::Object>();
5935 v8::Handle<v8::Object> proto0 = 5945 v8::Handle<v8::Object> proto0 =
5936 tostring0->Get(v8_str("__proto__")).As<v8::Object>(); 5946 tostring0->Get(v8_str("__proto__")).As<v8::Object>();
(...skipping 12 matching lines...) Expand all
5949 } 5959 }
5950 5960
5951 5961
5952 THREADED_TEST(Regress892105) { 5962 THREADED_TEST(Regress892105) {
5953 // Make sure that object and array literals created by cloning 5963 // Make sure that object and array literals created by cloning
5954 // boilerplates cannot communicate through their __proto__ 5964 // boilerplates cannot communicate through their __proto__
5955 // field. This is rather difficult to check, but we try to add stuff 5965 // field. This is rather difficult to check, but we try to add stuff
5956 // to Object.prototype and Array.prototype and create a new 5966 // to Object.prototype and Array.prototype and create a new
5957 // environment. This should succeed. 5967 // environment. This should succeed.
5958 5968
5959 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5969 v8::HandleScope scope(CcTest::isolate());
5960 5970
5961 Local<String> source = v8_str("Object.prototype.obj = 1234;" 5971 Local<String> source = v8_str("Object.prototype.obj = 1234;"
5962 "Array.prototype.arr = 4567;" 5972 "Array.prototype.arr = 4567;"
5963 "8901"); 5973 "8901");
5964 5974
5965 LocalContext env0; 5975 LocalContext env0;
5966 Local<Script> script0 = Script::Compile(source); 5976 Local<Script> script0 = Script::Compile(source);
5967 CHECK_EQ(8901.0, script0->Run()->NumberValue()); 5977 CHECK_EQ(8901.0, script0->Run()->NumberValue());
5968 5978
5969 LocalContext env1; 5979 LocalContext env1;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
6180 } 6190 }
6181 6191
6182 6192
6183 static void HandleLogDelegator( 6193 static void HandleLogDelegator(
6184 const v8::FunctionCallbackInfo<v8::Value>& args) { 6194 const v8::FunctionCallbackInfo<v8::Value>& args) {
6185 ApiTestFuzzer::Fuzz(); 6195 ApiTestFuzzer::Fuzz();
6186 } 6196 }
6187 6197
6188 6198
6189 THREADED_TEST(GlobalObjectTemplate) { 6199 THREADED_TEST(GlobalObjectTemplate) {
6190 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 6200 v8::Isolate* isolate = CcTest::isolate();
6191 v8::HandleScope handle_scope(isolate); 6201 v8::HandleScope handle_scope(isolate);
6192 Local<ObjectTemplate> global_template = ObjectTemplate::New(); 6202 Local<ObjectTemplate> global_template = ObjectTemplate::New();
6193 global_template->Set(v8_str("JSNI_Log"), 6203 global_template->Set(v8_str("JSNI_Log"),
6194 v8::FunctionTemplate::New(HandleLogDelegator)); 6204 v8::FunctionTemplate::New(HandleLogDelegator));
6195 v8::Local<Context> context = Context::New(isolate, 0, global_template); 6205 v8::Local<Context> context = Context::New(isolate, 0, global_template);
6196 Context::Scope context_scope(context); 6206 Context::Scope context_scope(context);
6197 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run(); 6207 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run();
6198 } 6208 }
6199 6209
6200 6210
6201 static const char* kSimpleExtensionSource = 6211 static const char* kSimpleExtensionSource =
6202 "function Foo() {" 6212 "function Foo() {"
6203 " return 4;" 6213 " return 4;"
6204 "}"; 6214 "}";
6205 6215
6206 6216
6207 THREADED_TEST(SimpleExtensions) { 6217 THREADED_TEST(SimpleExtensions) {
6208 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 6218 v8::HandleScope handle_scope(CcTest::isolate());
6209 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource)); 6219 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource));
6210 const char* extension_names[] = { "simpletest" }; 6220 const char* extension_names[] = { "simpletest" };
6211 v8::ExtensionConfiguration extensions(1, extension_names); 6221 v8::ExtensionConfiguration extensions(1, extension_names);
6212 v8::Handle<Context> context = 6222 v8::Handle<Context> context =
6213 Context::New(v8::Isolate::GetCurrent(), &extensions); 6223 Context::New(CcTest::isolate(), &extensions);
6214 Context::Scope lock(context); 6224 Context::Scope lock(context);
6215 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); 6225 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run();
6216 CHECK_EQ(result, v8::Integer::New(4)); 6226 CHECK_EQ(result, v8::Integer::New(4));
6217 } 6227 }
6218 6228
6219 6229
6220 THREADED_TEST(NullExtensions) { 6230 THREADED_TEST(NullExtensions) {
6221 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 6231 v8::HandleScope handle_scope(CcTest::isolate());
6222 v8::RegisterExtension(new Extension("nulltest", NULL)); 6232 v8::RegisterExtension(new Extension("nulltest", NULL));
6223 const char* extension_names[] = { "nulltest" }; 6233 const char* extension_names[] = { "nulltest" };
6224 v8::ExtensionConfiguration extensions(1, extension_names); 6234 v8::ExtensionConfiguration extensions(1, extension_names);
6225 v8::Handle<Context> context = 6235 v8::Handle<Context> context =
6226 Context::New(v8::Isolate::GetCurrent(), &extensions); 6236 Context::New(CcTest::isolate(), &extensions);
6227 Context::Scope lock(context); 6237 Context::Scope lock(context);
6228 v8::Handle<Value> result = Script::Compile(v8_str("1+3"))->Run(); 6238 v8::Handle<Value> result = Script::Compile(v8_str("1+3"))->Run();
6229 CHECK_EQ(result, v8::Integer::New(4)); 6239 CHECK_EQ(result, v8::Integer::New(4));
6230 } 6240 }
6231 6241
6232 6242
6233 static const char* kEmbeddedExtensionSource = 6243 static const char* kEmbeddedExtensionSource =
6234 "function Ret54321(){return 54321;}~~@@$" 6244 "function Ret54321(){return 54321;}~~@@$"
6235 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS."; 6245 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS.";
6236 static const int kEmbeddedExtensionSourceValidLen = 34; 6246 static const int kEmbeddedExtensionSourceValidLen = 34;
6237 6247
6238 6248
6239 THREADED_TEST(ExtensionMissingSourceLength) { 6249 THREADED_TEST(ExtensionMissingSourceLength) {
6240 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 6250 v8::HandleScope handle_scope(CcTest::isolate());
6241 v8::RegisterExtension(new Extension("srclentest_fail", 6251 v8::RegisterExtension(new Extension("srclentest_fail",
6242 kEmbeddedExtensionSource)); 6252 kEmbeddedExtensionSource));
6243 const char* extension_names[] = { "srclentest_fail" }; 6253 const char* extension_names[] = { "srclentest_fail" };
6244 v8::ExtensionConfiguration extensions(1, extension_names); 6254 v8::ExtensionConfiguration extensions(1, extension_names);
6245 v8::Handle<Context> context = 6255 v8::Handle<Context> context =
6246 Context::New(v8::Isolate::GetCurrent(), &extensions); 6256 Context::New(CcTest::isolate(), &extensions);
6247 CHECK_EQ(0, *context); 6257 CHECK_EQ(0, *context);
6248 } 6258 }
6249 6259
6250 6260
6251 THREADED_TEST(ExtensionWithSourceLength) { 6261 THREADED_TEST(ExtensionWithSourceLength) {
6252 for (int source_len = kEmbeddedExtensionSourceValidLen - 1; 6262 for (int source_len = kEmbeddedExtensionSourceValidLen - 1;
6253 source_len <= kEmbeddedExtensionSourceValidLen + 1; ++source_len) { 6263 source_len <= kEmbeddedExtensionSourceValidLen + 1; ++source_len) {
6254 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 6264 v8::HandleScope handle_scope(CcTest::isolate());
6255 i::ScopedVector<char> extension_name(32); 6265 i::ScopedVector<char> extension_name(32);
6256 i::OS::SNPrintF(extension_name, "ext #%d", source_len); 6266 i::OS::SNPrintF(extension_name, "ext #%d", source_len);
6257 v8::RegisterExtension(new Extension(extension_name.start(), 6267 v8::RegisterExtension(new Extension(extension_name.start(),
6258 kEmbeddedExtensionSource, 0, 0, 6268 kEmbeddedExtensionSource, 0, 0,
6259 source_len)); 6269 source_len));
6260 const char* extension_names[1] = { extension_name.start() }; 6270 const char* extension_names[1] = { extension_name.start() };
6261 v8::ExtensionConfiguration extensions(1, extension_names); 6271 v8::ExtensionConfiguration extensions(1, extension_names);
6262 v8::Handle<Context> context = 6272 v8::Handle<Context> context =
6263 Context::New(v8::Isolate::GetCurrent(), &extensions); 6273 Context::New(CcTest::isolate(), &extensions);
6264 if (source_len == kEmbeddedExtensionSourceValidLen) { 6274 if (source_len == kEmbeddedExtensionSourceValidLen) {
6265 Context::Scope lock(context); 6275 Context::Scope lock(context);
6266 v8::Handle<Value> result = Script::Compile(v8_str("Ret54321()"))->Run(); 6276 v8::Handle<Value> result = Script::Compile(v8_str("Ret54321()"))->Run();
6267 CHECK_EQ(v8::Integer::New(54321), result); 6277 CHECK_EQ(v8::Integer::New(54321), result);
6268 } else { 6278 } else {
6269 // Anything but exactly the right length should fail to compile. 6279 // Anything but exactly the right length should fail to compile.
6270 CHECK_EQ(0, *context); 6280 CHECK_EQ(0, *context);
6271 } 6281 }
6272 } 6282 }
6273 } 6283 }
(...skipping 10 matching lines...) Expand all
6284 "(function() {" 6294 "(function() {"
6285 " var x = 42;" 6295 " var x = 42;"
6286 " function e() {" 6296 " function e() {"
6287 " return eval('x');" 6297 " return eval('x');"
6288 " }" 6298 " }"
6289 " this.UseEval2 = e;" 6299 " this.UseEval2 = e;"
6290 "})()"; 6300 "})()";
6291 6301
6292 6302
6293 THREADED_TEST(UseEvalFromExtension) { 6303 THREADED_TEST(UseEvalFromExtension) {
6294 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 6304 v8::HandleScope handle_scope(CcTest::isolate());
6295 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1)); 6305 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1));
6296 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2)); 6306 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2));
6297 const char* extension_names[] = { "evaltest1", "evaltest2" }; 6307 const char* extension_names[] = { "evaltest1", "evaltest2" };
6298 v8::ExtensionConfiguration extensions(2, extension_names); 6308 v8::ExtensionConfiguration extensions(2, extension_names);
6299 v8::Handle<Context> context = 6309 v8::Handle<Context> context =
6300 Context::New(v8::Isolate::GetCurrent(), &extensions); 6310 Context::New(CcTest::isolate(), &extensions);
6301 Context::Scope lock(context); 6311 Context::Scope lock(context);
6302 v8::Handle<Value> result = Script::Compile(v8_str("UseEval1()"))->Run(); 6312 v8::Handle<Value> result = Script::Compile(v8_str("UseEval1()"))->Run();
6303 CHECK_EQ(result, v8::Integer::New(42)); 6313 CHECK_EQ(result, v8::Integer::New(42));
6304 result = Script::Compile(v8_str("UseEval2()"))->Run(); 6314 result = Script::Compile(v8_str("UseEval2()"))->Run();
6305 CHECK_EQ(result, v8::Integer::New(42)); 6315 CHECK_EQ(result, v8::Integer::New(42));
6306 } 6316 }
6307 6317
6308 6318
6309 static const char* kWithExtensionSource1 = 6319 static const char* kWithExtensionSource1 =
6310 "function UseWith1() {" 6320 "function UseWith1() {"
6311 " var x = 42;" 6321 " var x = 42;"
6312 " with({x:87}) { return x; }" 6322 " with({x:87}) { return x; }"
6313 "}"; 6323 "}";
6314 6324
6315 6325
6316 6326
6317 static const char* kWithExtensionSource2 = 6327 static const char* kWithExtensionSource2 =
6318 "(function() {" 6328 "(function() {"
6319 " var x = 42;" 6329 " var x = 42;"
6320 " function e() {" 6330 " function e() {"
6321 " with ({x:87}) { return x; }" 6331 " with ({x:87}) { return x; }"
6322 " }" 6332 " }"
6323 " this.UseWith2 = e;" 6333 " this.UseWith2 = e;"
6324 "})()"; 6334 "})()";
6325 6335
6326 6336
6327 THREADED_TEST(UseWithFromExtension) { 6337 THREADED_TEST(UseWithFromExtension) {
6328 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 6338 v8::HandleScope handle_scope(CcTest::isolate());
6329 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1)); 6339 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1));
6330 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2)); 6340 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2));
6331 const char* extension_names[] = { "withtest1", "withtest2" }; 6341 const char* extension_names[] = { "withtest1", "withtest2" };
6332 v8::ExtensionConfiguration extensions(2, extension_names); 6342 v8::ExtensionConfiguration extensions(2, extension_names);
6333 v8::Handle<Context> context = 6343 v8::Handle<Context> context =
6334 Context::New(v8::Isolate::GetCurrent(), &extensions); 6344 Context::New(CcTest::isolate(), &extensions);
6335 Context::Scope lock(context); 6345 Context::Scope lock(context);
6336 v8::Handle<Value> result = Script::Compile(v8_str("UseWith1()"))->Run(); 6346 v8::Handle<Value> result = Script::Compile(v8_str("UseWith1()"))->Run();
6337 CHECK_EQ(result, v8::Integer::New(87)); 6347 CHECK_EQ(result, v8::Integer::New(87));
6338 result = Script::Compile(v8_str("UseWith2()"))->Run(); 6348 result = Script::Compile(v8_str("UseWith2()"))->Run();
6339 CHECK_EQ(result, v8::Integer::New(87)); 6349 CHECK_EQ(result, v8::Integer::New(87));
6340 } 6350 }
6341 6351
6342 6352
6343 THREADED_TEST(AutoExtensions) { 6353 THREADED_TEST(AutoExtensions) {
6344 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 6354 v8::HandleScope handle_scope(CcTest::isolate());
6345 Extension* extension = new Extension("autotest", kSimpleExtensionSource); 6355 Extension* extension = new Extension("autotest", kSimpleExtensionSource);
6346 extension->set_auto_enable(true); 6356 extension->set_auto_enable(true);
6347 v8::RegisterExtension(extension); 6357 v8::RegisterExtension(extension);
6348 v8::Handle<Context> context = 6358 v8::Handle<Context> context =
6349 Context::New(v8::Isolate::GetCurrent()); 6359 Context::New(CcTest::isolate());
6350 Context::Scope lock(context); 6360 Context::Scope lock(context);
6351 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); 6361 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run();
6352 CHECK_EQ(result, v8::Integer::New(4)); 6362 CHECK_EQ(result, v8::Integer::New(4));
6353 } 6363 }
6354 6364
6355 6365
6356 static const char* kSyntaxErrorInExtensionSource = 6366 static const char* kSyntaxErrorInExtensionSource =
6357 "["; 6367 "[";
6358 6368
6359 6369
6360 // Test that a syntax error in an extension does not cause a fatal 6370 // Test that a syntax error in an extension does not cause a fatal
6361 // error but results in an empty context. 6371 // error but results in an empty context.
6362 THREADED_TEST(SyntaxErrorExtensions) { 6372 THREADED_TEST(SyntaxErrorExtensions) {
6363 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 6373 v8::HandleScope handle_scope(CcTest::isolate());
6364 v8::RegisterExtension(new Extension("syntaxerror", 6374 v8::RegisterExtension(new Extension("syntaxerror",
6365 kSyntaxErrorInExtensionSource)); 6375 kSyntaxErrorInExtensionSource));
6366 const char* extension_names[] = { "syntaxerror" }; 6376 const char* extension_names[] = { "syntaxerror" };
6367 v8::ExtensionConfiguration extensions(1, extension_names); 6377 v8::ExtensionConfiguration extensions(1, extension_names);
6368 v8::Handle<Context> context = 6378 v8::Handle<Context> context =
6369 Context::New(v8::Isolate::GetCurrent(), &extensions); 6379 Context::New(CcTest::isolate(), &extensions);
6370 CHECK(context.IsEmpty()); 6380 CHECK(context.IsEmpty());
6371 } 6381 }
6372 6382
6373 6383
6374 static const char* kExceptionInExtensionSource = 6384 static const char* kExceptionInExtensionSource =
6375 "throw 42"; 6385 "throw 42";
6376 6386
6377 6387
6378 // Test that an exception when installing an extension does not cause 6388 // Test that an exception when installing an extension does not cause
6379 // a fatal error but results in an empty context. 6389 // a fatal error but results in an empty context.
6380 THREADED_TEST(ExceptionExtensions) { 6390 THREADED_TEST(ExceptionExtensions) {
6381 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 6391 v8::HandleScope handle_scope(CcTest::isolate());
6382 v8::RegisterExtension(new Extension("exception", 6392 v8::RegisterExtension(new Extension("exception",
6383 kExceptionInExtensionSource)); 6393 kExceptionInExtensionSource));
6384 const char* extension_names[] = { "exception" }; 6394 const char* extension_names[] = { "exception" };
6385 v8::ExtensionConfiguration extensions(1, extension_names); 6395 v8::ExtensionConfiguration extensions(1, extension_names);
6386 v8::Handle<Context> context = 6396 v8::Handle<Context> context =
6387 Context::New(v8::Isolate::GetCurrent(), &extensions); 6397 Context::New(CcTest::isolate(), &extensions);
6388 CHECK(context.IsEmpty()); 6398 CHECK(context.IsEmpty());
6389 } 6399 }
6390 6400
6391 6401
6392 static const char* kNativeCallInExtensionSource = 6402 static const char* kNativeCallInExtensionSource =
6393 "function call_runtime_last_index_of(x) {" 6403 "function call_runtime_last_index_of(x) {"
6394 " return %StringLastIndexOf(x, 'bob', 10);" 6404 " return %StringLastIndexOf(x, 'bob', 10);"
6395 "}"; 6405 "}";
6396 6406
6397 6407
6398 static const char* kNativeCallTest = 6408 static const char* kNativeCallTest =
6399 "call_runtime_last_index_of('bobbobboellebobboellebobbob');"; 6409 "call_runtime_last_index_of('bobbobboellebobboellebobbob');";
6400 6410
6401 // Test that a native runtime calls are supported in extensions. 6411 // Test that a native runtime calls are supported in extensions.
6402 THREADED_TEST(NativeCallInExtensions) { 6412 THREADED_TEST(NativeCallInExtensions) {
6403 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 6413 v8::HandleScope handle_scope(CcTest::isolate());
6404 v8::RegisterExtension(new Extension("nativecall", 6414 v8::RegisterExtension(new Extension("nativecall",
6405 kNativeCallInExtensionSource)); 6415 kNativeCallInExtensionSource));
6406 const char* extension_names[] = { "nativecall" }; 6416 const char* extension_names[] = { "nativecall" };
6407 v8::ExtensionConfiguration extensions(1, extension_names); 6417 v8::ExtensionConfiguration extensions(1, extension_names);
6408 v8::Handle<Context> context = 6418 v8::Handle<Context> context =
6409 Context::New(v8::Isolate::GetCurrent(), &extensions); 6419 Context::New(CcTest::isolate(), &extensions);
6410 Context::Scope lock(context); 6420 Context::Scope lock(context);
6411 v8::Handle<Value> result = Script::Compile(v8_str(kNativeCallTest))->Run(); 6421 v8::Handle<Value> result = Script::Compile(v8_str(kNativeCallTest))->Run();
6412 CHECK_EQ(result, v8::Integer::New(3)); 6422 CHECK_EQ(result, v8::Integer::New(3));
6413 } 6423 }
6414 6424
6415 6425
6416 class NativeFunctionExtension : public Extension { 6426 class NativeFunctionExtension : public Extension {
6417 public: 6427 public:
6418 NativeFunctionExtension(const char* name, 6428 NativeFunctionExtension(const char* name,
6419 const char* source, 6429 const char* source,
6420 v8::FunctionCallback fun = &Echo) 6430 v8::FunctionCallback fun = &Echo)
6421 : Extension(name, source), 6431 : Extension(name, source),
6422 function_(fun) { } 6432 function_(fun) { }
6423 6433
6424 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 6434 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
6425 v8::Handle<v8::String> name) { 6435 v8::Handle<v8::String> name) {
6426 return v8::FunctionTemplate::New(function_); 6436 return v8::FunctionTemplate::New(function_);
6427 } 6437 }
6428 6438
6429 static void Echo(const v8::FunctionCallbackInfo<v8::Value>& args) { 6439 static void Echo(const v8::FunctionCallbackInfo<v8::Value>& args) {
6430 if (args.Length() >= 1) args.GetReturnValue().Set(args[0]); 6440 if (args.Length() >= 1) args.GetReturnValue().Set(args[0]);
6431 } 6441 }
6432 private: 6442 private:
6433 v8::FunctionCallback function_; 6443 v8::FunctionCallback function_;
6434 }; 6444 };
6435 6445
6436 6446
6437 THREADED_TEST(NativeFunctionDeclaration) { 6447 THREADED_TEST(NativeFunctionDeclaration) {
6438 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 6448 v8::HandleScope handle_scope(CcTest::isolate());
6439 const char* name = "nativedecl"; 6449 const char* name = "nativedecl";
6440 v8::RegisterExtension(new NativeFunctionExtension(name, 6450 v8::RegisterExtension(new NativeFunctionExtension(name,
6441 "native function foo();")); 6451 "native function foo();"));
6442 const char* extension_names[] = { name }; 6452 const char* extension_names[] = { name };
6443 v8::ExtensionConfiguration extensions(1, extension_names); 6453 v8::ExtensionConfiguration extensions(1, extension_names);
6444 v8::Handle<Context> context = 6454 v8::Handle<Context> context =
6445 Context::New(v8::Isolate::GetCurrent(), &extensions); 6455 Context::New(CcTest::isolate(), &extensions);
6446 Context::Scope lock(context); 6456 Context::Scope lock(context);
6447 v8::Handle<Value> result = Script::Compile(v8_str("foo(42);"))->Run(); 6457 v8::Handle<Value> result = Script::Compile(v8_str("foo(42);"))->Run();
6448 CHECK_EQ(result, v8::Integer::New(42)); 6458 CHECK_EQ(result, v8::Integer::New(42));
6449 } 6459 }
6450 6460
6451 6461
6452 THREADED_TEST(NativeFunctionDeclarationError) { 6462 THREADED_TEST(NativeFunctionDeclarationError) {
6453 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 6463 v8::HandleScope handle_scope(CcTest::isolate());
6454 const char* name = "nativedeclerr"; 6464 const char* name = "nativedeclerr";
6455 // Syntax error in extension code. 6465 // Syntax error in extension code.
6456 v8::RegisterExtension(new NativeFunctionExtension(name, 6466 v8::RegisterExtension(new NativeFunctionExtension(name,
6457 "native\nfunction foo();")); 6467 "native\nfunction foo();"));
6458 const char* extension_names[] = { name }; 6468 const char* extension_names[] = { name };
6459 v8::ExtensionConfiguration extensions(1, extension_names); 6469 v8::ExtensionConfiguration extensions(1, extension_names);
6460 v8::Handle<Context> context = 6470 v8::Handle<Context> context =
6461 Context::New(v8::Isolate::GetCurrent(), &extensions); 6471 Context::New(CcTest::isolate(), &extensions);
6462 CHECK(context.IsEmpty()); 6472 CHECK(context.IsEmpty());
6463 } 6473 }
6464 6474
6465 6475
6466 THREADED_TEST(NativeFunctionDeclarationErrorEscape) { 6476 THREADED_TEST(NativeFunctionDeclarationErrorEscape) {
6467 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 6477 v8::HandleScope handle_scope(CcTest::isolate());
6468 const char* name = "nativedeclerresc"; 6478 const char* name = "nativedeclerresc";
6469 // Syntax error in extension code - escape code in "native" means that 6479 // Syntax error in extension code - escape code in "native" means that
6470 // it's not treated as a keyword. 6480 // it's not treated as a keyword.
6471 v8::RegisterExtension(new NativeFunctionExtension( 6481 v8::RegisterExtension(new NativeFunctionExtension(
6472 name, 6482 name,
6473 "nativ\\u0065 function foo();")); 6483 "nativ\\u0065 function foo();"));
6474 const char* extension_names[] = { name }; 6484 const char* extension_names[] = { name };
6475 v8::ExtensionConfiguration extensions(1, extension_names); 6485 v8::ExtensionConfiguration extensions(1, extension_names);
6476 v8::Handle<Context> context = 6486 v8::Handle<Context> context =
6477 Context::New(v8::Isolate::GetCurrent(), &extensions); 6487 Context::New(CcTest::isolate(), &extensions);
6478 CHECK(context.IsEmpty()); 6488 CHECK(context.IsEmpty());
6479 } 6489 }
6480 6490
6481 6491
6482 static void CheckDependencies(const char* name, const char* expected) { 6492 static void CheckDependencies(const char* name, const char* expected) {
6483 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 6493 v8::HandleScope handle_scope(CcTest::isolate());
6484 v8::ExtensionConfiguration config(1, &name); 6494 v8::ExtensionConfiguration config(1, &name);
6485 LocalContext context(&config); 6495 LocalContext context(&config);
6486 CHECK_EQ(String::New(expected), context->Global()->Get(v8_str("loaded"))); 6496 CHECK_EQ(String::New(expected), context->Global()->Get(v8_str("loaded")));
6487 } 6497 }
6488 6498
6489 6499
6490 /* 6500 /*
6491 * Configuration: 6501 * Configuration:
6492 * 6502 *
6493 * /-- B <--\ 6503 * /-- B <--\
6494 * A <- -- D <-- E 6504 * A <- -- D <-- E
6495 * \-- C <--/ 6505 * \-- C <--/
6496 */ 6506 */
6497 THREADED_TEST(ExtensionDependency) { 6507 THREADED_TEST(ExtensionDependency) {
6498 static const char* kEDeps[] = { "D" }; 6508 static const char* kEDeps[] = { "D" };
6499 v8::RegisterExtension(new Extension("E", "this.loaded += 'E';", 1, kEDeps)); 6509 v8::RegisterExtension(new Extension("E", "this.loaded += 'E';", 1, kEDeps));
6500 static const char* kDDeps[] = { "B", "C" }; 6510 static const char* kDDeps[] = { "B", "C" };
6501 v8::RegisterExtension(new Extension("D", "this.loaded += 'D';", 2, kDDeps)); 6511 v8::RegisterExtension(new Extension("D", "this.loaded += 'D';", 2, kDDeps));
6502 static const char* kBCDeps[] = { "A" }; 6512 static const char* kBCDeps[] = { "A" };
6503 v8::RegisterExtension(new Extension("B", "this.loaded += 'B';", 1, kBCDeps)); 6513 v8::RegisterExtension(new Extension("B", "this.loaded += 'B';", 1, kBCDeps));
6504 v8::RegisterExtension(new Extension("C", "this.loaded += 'C';", 1, kBCDeps)); 6514 v8::RegisterExtension(new Extension("C", "this.loaded += 'C';", 1, kBCDeps));
6505 v8::RegisterExtension(new Extension("A", "this.loaded += 'A';")); 6515 v8::RegisterExtension(new Extension("A", "this.loaded += 'A';"));
6506 CheckDependencies("A", "undefinedA"); 6516 CheckDependencies("A", "undefinedA");
6507 CheckDependencies("B", "undefinedAB"); 6517 CheckDependencies("B", "undefinedAB");
6508 CheckDependencies("C", "undefinedAC"); 6518 CheckDependencies("C", "undefinedAC");
6509 CheckDependencies("D", "undefinedABCD"); 6519 CheckDependencies("D", "undefinedABCD");
6510 CheckDependencies("E", "undefinedABCDE"); 6520 CheckDependencies("E", "undefinedABCDE");
6511 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 6521 v8::HandleScope handle_scope(CcTest::isolate());
6512 static const char* exts[2] = { "C", "E" }; 6522 static const char* exts[2] = { "C", "E" };
6513 v8::ExtensionConfiguration config(2, exts); 6523 v8::ExtensionConfiguration config(2, exts);
6514 LocalContext context(&config); 6524 LocalContext context(&config);
6515 CHECK_EQ(v8_str("undefinedACBDE"), context->Global()->Get(v8_str("loaded"))); 6525 CHECK_EQ(v8_str("undefinedACBDE"), context->Global()->Get(v8_str("loaded")));
6516 } 6526 }
6517 6527
6518 6528
6519 static const char* kExtensionTestScript = 6529 static const char* kExtensionTestScript =
6520 "native function A();" 6530 "native function A();"
6521 "native function B();" 6531 "native function B();"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
6557 } else if (name->Equals(v8_str("C"))) { 6567 } else if (name->Equals(v8_str("C"))) {
6558 return v8::FunctionTemplate::New(CallFun, v8::Integer::New(6)); 6568 return v8::FunctionTemplate::New(CallFun, v8::Integer::New(6));
6559 } else { 6569 } else {
6560 return v8::Handle<v8::FunctionTemplate>(); 6570 return v8::Handle<v8::FunctionTemplate>();
6561 } 6571 }
6562 } 6572 }
6563 6573
6564 6574
6565 THREADED_TEST(FunctionLookup) { 6575 THREADED_TEST(FunctionLookup) {
6566 v8::RegisterExtension(new FunctionExtension()); 6576 v8::RegisterExtension(new FunctionExtension());
6567 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 6577 v8::HandleScope handle_scope(CcTest::isolate());
6568 static const char* exts[1] = { "functiontest" }; 6578 static const char* exts[1] = { "functiontest" };
6569 v8::ExtensionConfiguration config(1, exts); 6579 v8::ExtensionConfiguration config(1, exts);
6570 LocalContext context(&config); 6580 LocalContext context(&config);
6571 CHECK_EQ(3, lookup_count); 6581 CHECK_EQ(3, lookup_count);
6572 CHECK_EQ(v8::Integer::New(8), Script::Compile(v8_str("Foo(0)"))->Run()); 6582 CHECK_EQ(v8::Integer::New(8), Script::Compile(v8_str("Foo(0)"))->Run());
6573 CHECK_EQ(v8::Integer::New(7), Script::Compile(v8_str("Foo(1)"))->Run()); 6583 CHECK_EQ(v8::Integer::New(7), Script::Compile(v8_str("Foo(1)"))->Run());
6574 CHECK_EQ(v8::Integer::New(6), Script::Compile(v8_str("Foo(2)"))->Run()); 6584 CHECK_EQ(v8::Integer::New(6), Script::Compile(v8_str("Foo(2)"))->Run());
6575 } 6585 }
6576 6586
6577 6587
6578 THREADED_TEST(NativeFunctionConstructCall) { 6588 THREADED_TEST(NativeFunctionConstructCall) {
6579 v8::RegisterExtension(new FunctionExtension()); 6589 v8::RegisterExtension(new FunctionExtension());
6580 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 6590 v8::HandleScope handle_scope(CcTest::isolate());
6581 static const char* exts[1] = { "functiontest" }; 6591 static const char* exts[1] = { "functiontest" };
6582 v8::ExtensionConfiguration config(1, exts); 6592 v8::ExtensionConfiguration config(1, exts);
6583 LocalContext context(&config); 6593 LocalContext context(&config);
6584 for (int i = 0; i < 10; i++) { 6594 for (int i = 0; i < 10; i++) {
6585 // Run a few times to ensure that allocation of objects doesn't 6595 // Run a few times to ensure that allocation of objects doesn't
6586 // change behavior of a constructor function. 6596 // change behavior of a constructor function.
6587 CHECK_EQ(v8::Integer::New(8), 6597 CHECK_EQ(v8::Integer::New(8),
6588 Script::Compile(v8_str("(new A()).data"))->Run()); 6598 Script::Compile(v8_str("(new A()).data"))->Run());
6589 CHECK_EQ(v8::Integer::New(7), 6599 CHECK_EQ(v8::Integer::New(7),
6590 Script::Compile(v8_str("(new B()).data"))->Run()); 6600 Script::Compile(v8_str("(new B()).data"))->Run());
(...skipping 18 matching lines...) Expand all
6609 // unusable and therefore this test cannot be run in parallel. 6619 // unusable and therefore this test cannot be run in parallel.
6610 TEST(ErrorReporting) { 6620 TEST(ErrorReporting) {
6611 v8::V8::SetFatalErrorHandler(StoringErrorCallback); 6621 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
6612 static const char* aDeps[] = { "B" }; 6622 static const char* aDeps[] = { "B" };
6613 v8::RegisterExtension(new Extension("A", "", 1, aDeps)); 6623 v8::RegisterExtension(new Extension("A", "", 1, aDeps));
6614 static const char* bDeps[] = { "A" }; 6624 static const char* bDeps[] = { "A" };
6615 v8::RegisterExtension(new Extension("B", "", 1, bDeps)); 6625 v8::RegisterExtension(new Extension("B", "", 1, bDeps));
6616 last_location = NULL; 6626 last_location = NULL;
6617 v8::ExtensionConfiguration config(1, bDeps); 6627 v8::ExtensionConfiguration config(1, bDeps);
6618 v8::Handle<Context> context = 6628 v8::Handle<Context> context =
6619 Context::New(v8::Isolate::GetCurrent(), &config); 6629 Context::New(CcTest::isolate(), &config);
6620 CHECK(context.IsEmpty()); 6630 CHECK(context.IsEmpty());
6621 CHECK_NE(last_location, NULL); 6631 CHECK_NE(last_location, NULL);
6622 } 6632 }
6623 6633
6624 6634
6625 static const char* js_code_causing_huge_string_flattening = 6635 static const char* js_code_causing_huge_string_flattening =
6626 "var str = 'X';" 6636 "var str = 'X';"
6627 "for (var i = 0; i < 30; i++) {" 6637 "for (var i = 0; i < 30; i++) {"
6628 " str = str + str;" 6638 " str = str + str;"
6629 "}" 6639 "}"
6630 "str.match(/X/);"; 6640 "str.match(/X/);";
6631 6641
6632 6642
6633 void OOMCallback(const char* location, const char* message) { 6643 void OOMCallback(const char* location, const char* message) {
6634 exit(0); 6644 exit(0);
6635 } 6645 }
6636 6646
6637 6647
6638 TEST(RegexpOutOfMemory) { 6648 TEST(RegexpOutOfMemory) {
6639 // Execute a script that causes out of memory when flattening a string. 6649 // Execute a script that causes out of memory when flattening a string.
6640 v8::HandleScope scope(v8::Isolate::GetCurrent()); 6650 v8::HandleScope scope(CcTest::isolate());
6641 v8::V8::SetFatalErrorHandler(OOMCallback); 6651 v8::V8::SetFatalErrorHandler(OOMCallback);
6642 LocalContext context; 6652 LocalContext context;
6643 Local<Script> script = 6653 Local<Script> script =
6644 Script::Compile(String::New(js_code_causing_huge_string_flattening)); 6654 Script::Compile(String::New(js_code_causing_huge_string_flattening));
6645 last_location = NULL; 6655 last_location = NULL;
6646 script->Run(); 6656 script->Run();
6647 6657
6648 CHECK(false); // Should not return. 6658 CHECK(false); // Should not return.
6649 } 6659 }
6650 6660
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
6713 prev.MakeWeak<Value, Snorkel>(new Snorkel(), &HandleWeakReference); 6723 prev.MakeWeak<Value, Snorkel>(new Snorkel(), &HandleWeakReference);
6714 whammy->objects_[whammy->cursor_].Clear(); 6724 whammy->objects_[whammy->cursor_].Clear();
6715 } 6725 }
6716 whammy->objects_[whammy->cursor_].Reset(info.GetIsolate(), obj); 6726 whammy->objects_[whammy->cursor_].Reset(info.GetIsolate(), obj);
6717 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount; 6727 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount;
6718 info.GetReturnValue().Set(whammy->getScript()->Run()); 6728 info.GetReturnValue().Set(whammy->getScript()->Run());
6719 } 6729 }
6720 6730
6721 6731
6722 THREADED_TEST(WeakReference) { 6732 THREADED_TEST(WeakReference) {
6723 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 6733 v8::HandleScope handle_scope(CcTest::isolate());
6724 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New(); 6734 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New();
6725 Whammy* whammy = new Whammy(v8::Isolate::GetCurrent()); 6735 Whammy* whammy = new Whammy(CcTest::isolate());
6726 templ->SetNamedPropertyHandler(WhammyPropertyGetter, 6736 templ->SetNamedPropertyHandler(WhammyPropertyGetter,
6727 0, 0, 0, 0, 6737 0, 0, 0, 0,
6728 v8::External::New(whammy)); 6738 v8::External::New(whammy));
6729 const char* extension_list[] = { "v8/gc" }; 6739 const char* extension_list[] = { "v8/gc" };
6730 v8::ExtensionConfiguration extensions(1, extension_list); 6740 v8::ExtensionConfiguration extensions(1, extension_list);
6731 v8::Handle<Context> context = 6741 v8::Handle<Context> context =
6732 Context::New(v8::Isolate::GetCurrent(), &extensions); 6742 Context::New(CcTest::isolate(), &extensions);
6733 Context::Scope context_scope(context); 6743 Context::Scope context_scope(context);
6734 6744
6735 v8::Handle<v8::Object> interceptor = templ->NewInstance(); 6745 v8::Handle<v8::Object> interceptor = templ->NewInstance();
6736 context->Global()->Set(v8_str("whammy"), interceptor); 6746 context->Global()->Set(v8_str("whammy"), interceptor);
6737 const char* code = 6747 const char* code =
6738 "var last;" 6748 "var last;"
6739 "for (var i = 0; i < 10000; i++) {" 6749 "for (var i = 0; i < 10000; i++) {"
6740 " var obj = whammy.length;" 6750 " var obj = whammy.length;"
6741 " if (last) last.next = obj;" 6751 " if (last) last.next = obj;"
6742 " last = obj;" 6752 " last = obj;"
6743 "}" 6753 "}"
6744 "gc();" 6754 "gc();"
6745 "4"; 6755 "4";
6746 v8::Handle<Value> result = CompileRun(code); 6756 v8::Handle<Value> result = CompileRun(code);
6747 CHECK_EQ(4.0, result->NumberValue()); 6757 CHECK_EQ(4.0, result->NumberValue());
6748 delete whammy; 6758 delete whammy;
6749 } 6759 }
6750 6760
6751 6761
6752 static void DisposeAndSetFlag(v8::Isolate* isolate, 6762 static void DisposeAndSetFlag(v8::Isolate* isolate,
6753 v8::Persistent<v8::Object>* obj, 6763 v8::Persistent<v8::Object>* obj,
6754 bool* data) { 6764 bool* data) {
6755 obj->Dispose(); 6765 obj->Dispose();
6756 *(data) = true; 6766 *(data) = true;
6757 } 6767 }
6758 6768
6759 6769
6760 THREADED_TEST(IndependentWeakHandle) { 6770 THREADED_TEST(IndependentWeakHandle) {
6761 v8::Isolate* iso = v8::Isolate::GetCurrent(); 6771 v8::Isolate* iso = CcTest::isolate();
6762 v8::HandleScope scope(iso); 6772 v8::HandleScope scope(iso);
6763 v8::Handle<Context> context = Context::New(iso); 6773 v8::Handle<Context> context = Context::New(iso);
6764 Context::Scope context_scope(context); 6774 Context::Scope context_scope(context);
6765 6775
6766 v8::Persistent<v8::Object> object_a, object_b; 6776 v8::Persistent<v8::Object> object_a, object_b;
6767 6777
6768 { 6778 {
6769 v8::HandleScope handle_scope(iso); 6779 v8::HandleScope handle_scope(iso);
6770 object_a.Reset(iso, v8::Object::New()); 6780 object_a.Reset(iso, v8::Object::New());
6771 object_b.Reset(iso, v8::Object::New()); 6781 object_b.Reset(iso, v8::Object::New());
6772 } 6782 }
6773 6783
6774 bool object_a_disposed = false; 6784 bool object_a_disposed = false;
6775 bool object_b_disposed = false; 6785 bool object_b_disposed = false;
6776 object_a.MakeWeak(&object_a_disposed, &DisposeAndSetFlag); 6786 object_a.MakeWeak(&object_a_disposed, &DisposeAndSetFlag);
6777 object_b.MakeWeak(&object_b_disposed, &DisposeAndSetFlag); 6787 object_b.MakeWeak(&object_b_disposed, &DisposeAndSetFlag);
6778 CHECK(!object_b.IsIndependent()); 6788 CHECK(!object_b.IsIndependent());
6779 object_a.MarkIndependent(); 6789 object_a.MarkIndependent();
6780 object_b.MarkIndependent(); 6790 object_b.MarkIndependent();
6781 CHECK(object_b.IsIndependent()); 6791 CHECK(object_b.IsIndependent());
6782 HEAP->PerformScavenge(); 6792 CcTest::heap()->PerformScavenge();
6783 CHECK(object_a_disposed); 6793 CHECK(object_a_disposed);
6784 CHECK(object_b_disposed); 6794 CHECK(object_b_disposed);
6785 } 6795 }
6786 6796
6787 6797
6788 static void InvokeScavenge() { 6798 static void InvokeScavenge() {
6789 HEAP->PerformScavenge(); 6799 CcTest::heap()->PerformScavenge();
6790 } 6800 }
6791 6801
6792 6802
6793 static void InvokeMarkSweep() { 6803 static void InvokeMarkSweep() {
6794 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 6804 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
6795 } 6805 }
6796 6806
6797 6807
6798 static void ForceScavenge(v8::Isolate* isolate, 6808 static void ForceScavenge(v8::Isolate* isolate,
6799 v8::Persistent<v8::Object>* obj, 6809 v8::Persistent<v8::Object>* obj,
6800 bool* data) { 6810 bool* data) {
6801 obj->Dispose(); 6811 obj->Dispose();
6802 *(data) = true; 6812 *(data) = true;
6803 InvokeScavenge(); 6813 InvokeScavenge();
6804 } 6814 }
6805 6815
6806 6816
6807 static void ForceMarkSweep(v8::Isolate* isolate, 6817 static void ForceMarkSweep(v8::Isolate* isolate,
6808 v8::Persistent<v8::Object>* obj, 6818 v8::Persistent<v8::Object>* obj,
6809 bool* data) { 6819 bool* data) {
6810 obj->Dispose(); 6820 obj->Dispose();
6811 *(data) = true; 6821 *(data) = true;
6812 InvokeMarkSweep(); 6822 InvokeMarkSweep();
6813 } 6823 }
6814 6824
6815 6825
6816 THREADED_TEST(GCFromWeakCallbacks) { 6826 THREADED_TEST(GCFromWeakCallbacks) {
6817 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 6827 v8::Isolate* isolate = CcTest::isolate();
6818 v8::HandleScope scope(isolate); 6828 v8::HandleScope scope(isolate);
6819 v8::Handle<Context> context = Context::New(isolate); 6829 v8::Handle<Context> context = Context::New(isolate);
6820 Context::Scope context_scope(context); 6830 Context::Scope context_scope(context);
6821 6831
6822 static const int kNumberOfGCTypes = 2; 6832 static const int kNumberOfGCTypes = 2;
6823 typedef v8::WeakReferenceCallbacks<v8::Object, bool>::Revivable Callback; 6833 typedef v8::WeakReferenceCallbacks<v8::Object, bool>::Revivable Callback;
6824 Callback gc_forcing_callback[kNumberOfGCTypes] = 6834 Callback gc_forcing_callback[kNumberOfGCTypes] =
6825 {&ForceScavenge, &ForceMarkSweep}; 6835 {&ForceScavenge, &ForceMarkSweep};
6826 6836
6827 typedef void (*GCInvoker)(); 6837 typedef void (*GCInvoker)();
(...skipping 18 matching lines...) Expand all
6846 6856
6847 static void RevivingCallback(v8::Isolate* isolate, 6857 static void RevivingCallback(v8::Isolate* isolate,
6848 v8::Persistent<v8::Object>* obj, 6858 v8::Persistent<v8::Object>* obj,
6849 bool* data) { 6859 bool* data) {
6850 obj->ClearWeak(); 6860 obj->ClearWeak();
6851 *(data) = true; 6861 *(data) = true;
6852 } 6862 }
6853 6863
6854 6864
6855 THREADED_TEST(IndependentHandleRevival) { 6865 THREADED_TEST(IndependentHandleRevival) {
6856 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 6866 v8::Isolate* isolate = CcTest::isolate();
6857 v8::HandleScope scope(isolate); 6867 v8::HandleScope scope(isolate);
6858 v8::Handle<Context> context = Context::New(isolate); 6868 v8::Handle<Context> context = Context::New(isolate);
6859 Context::Scope context_scope(context); 6869 Context::Scope context_scope(context);
6860 6870
6861 v8::Persistent<v8::Object> object; 6871 v8::Persistent<v8::Object> object;
6862 { 6872 {
6863 v8::HandleScope handle_scope(isolate); 6873 v8::HandleScope handle_scope(isolate);
6864 v8::Local<v8::Object> o = v8::Object::New(); 6874 v8::Local<v8::Object> o = v8::Object::New();
6865 object.Reset(isolate, o); 6875 object.Reset(isolate, o);
6866 o->Set(v8_str("x"), v8::Integer::New(1)); 6876 o->Set(v8_str("x"), v8::Integer::New(1));
6867 v8::Local<String> y_str = v8_str("y"); 6877 v8::Local<String> y_str = v8_str("y");
6868 o->Set(y_str, y_str); 6878 o->Set(y_str, y_str);
6869 } 6879 }
6870 bool revived = false; 6880 bool revived = false;
6871 object.MakeWeak(&revived, &RevivingCallback); 6881 object.MakeWeak(&revived, &RevivingCallback);
6872 object.MarkIndependent(); 6882 object.MarkIndependent();
6873 HEAP->PerformScavenge(); 6883 CcTest::heap()->PerformScavenge();
6874 CHECK(revived); 6884 CHECK(revived);
6875 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 6885 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
6876 { 6886 {
6877 v8::HandleScope handle_scope(isolate); 6887 v8::HandleScope handle_scope(isolate);
6878 v8::Local<v8::Object> o = v8::Local<v8::Object>::New(isolate, object); 6888 v8::Local<v8::Object> o = v8::Local<v8::Object>::New(isolate, object);
6879 v8::Local<String> y_str = v8_str("y"); 6889 v8::Local<String> y_str = v8_str("y");
6880 CHECK_EQ(v8::Integer::New(1), o->Get(v8_str("x"))); 6890 CHECK_EQ(v8::Integer::New(1), o->Get(v8_str("x")));
6881 CHECK(o->Get(y_str)->Equals(y_str)); 6891 CHECK(o->Get(y_str)->Equals(y_str));
6882 } 6892 }
6883 } 6893 }
6884 6894
6885 6895
6886 v8::Handle<Function> args_fun; 6896 v8::Handle<Function> args_fun;
6887 6897
6888 6898
6889 static void ArgumentsTestCallback( 6899 static void ArgumentsTestCallback(
6890 const v8::FunctionCallbackInfo<v8::Value>& args) { 6900 const v8::FunctionCallbackInfo<v8::Value>& args) {
6891 ApiTestFuzzer::Fuzz(); 6901 ApiTestFuzzer::Fuzz();
6892 CHECK_EQ(args_fun, args.Callee()); 6902 CHECK_EQ(args_fun, args.Callee());
6893 CHECK_EQ(3, args.Length()); 6903 CHECK_EQ(3, args.Length());
6894 CHECK_EQ(v8::Integer::New(1), args[0]); 6904 CHECK_EQ(v8::Integer::New(1), args[0]);
6895 CHECK_EQ(v8::Integer::New(2), args[1]); 6905 CHECK_EQ(v8::Integer::New(2), args[1]);
6896 CHECK_EQ(v8::Integer::New(3), args[2]); 6906 CHECK_EQ(v8::Integer::New(3), args[2]);
6897 CHECK_EQ(v8::Undefined(), args[3]); 6907 CHECK_EQ(v8::Undefined(), args[3]);
6898 v8::HandleScope scope(args.GetIsolate()); 6908 v8::HandleScope scope(args.GetIsolate());
6899 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 6909 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
6900 } 6910 }
6901 6911
6902 6912
6903 THREADED_TEST(Arguments) { 6913 THREADED_TEST(Arguments) {
6904 v8::HandleScope scope(v8::Isolate::GetCurrent()); 6914 v8::HandleScope scope(CcTest::isolate());
6905 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); 6915 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New();
6906 global->Set(v8_str("f"), v8::FunctionTemplate::New(ArgumentsTestCallback)); 6916 global->Set(v8_str("f"), v8::FunctionTemplate::New(ArgumentsTestCallback));
6907 LocalContext context(NULL, global); 6917 LocalContext context(NULL, global);
6908 args_fun = context->Global()->Get(v8_str("f")).As<Function>(); 6918 args_fun = context->Global()->Get(v8_str("f")).As<Function>();
6909 v8_compile("f(1, 2, 3)")->Run(); 6919 v8_compile("f(1, 2, 3)")->Run();
6910 } 6920 }
6911 6921
6912 6922
6913 static void NoBlockGetterX(Local<String> name, 6923 static void NoBlockGetterX(Local<String> name,
6914 const v8::PropertyCallbackInfo<v8::Value>&) { 6924 const v8::PropertyCallbackInfo<v8::Value>&) {
(...skipping 19 matching lines...) Expand all
6934 const v8::PropertyCallbackInfo<v8::Boolean>& info) { 6944 const v8::PropertyCallbackInfo<v8::Boolean>& info) {
6935 if (index != 2) { 6945 if (index != 2) {
6936 return; // not intercepted 6946 return; // not intercepted
6937 } 6947 }
6938 6948
6939 info.GetReturnValue().Set(false); // intercepted, don't delete the property 6949 info.GetReturnValue().Set(false); // intercepted, don't delete the property
6940 } 6950 }
6941 6951
6942 6952
6943 THREADED_TEST(Deleter) { 6953 THREADED_TEST(Deleter) {
6944 v8::HandleScope scope(v8::Isolate::GetCurrent()); 6954 v8::HandleScope scope(CcTest::isolate());
6945 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 6955 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
6946 obj->SetNamedPropertyHandler(NoBlockGetterX, NULL, NULL, PDeleter, NULL); 6956 obj->SetNamedPropertyHandler(NoBlockGetterX, NULL, NULL, PDeleter, NULL);
6947 obj->SetIndexedPropertyHandler(NoBlockGetterI, NULL, NULL, IDeleter, NULL); 6957 obj->SetIndexedPropertyHandler(NoBlockGetterI, NULL, NULL, IDeleter, NULL);
6948 LocalContext context; 6958 LocalContext context;
6949 context->Global()->Set(v8_str("k"), obj->NewInstance()); 6959 context->Global()->Set(v8_str("k"), obj->NewInstance());
6950 CompileRun( 6960 CompileRun(
6951 "k.foo = 'foo';" 6961 "k.foo = 'foo';"
6952 "k.bar = 'bar';" 6962 "k.bar = 'bar';"
6953 "k[2] = 2;" 6963 "k[2] = 2;"
6954 "k[4] = 4;"); 6964 "k[4] = 4;");
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
6997 static void IndexedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) { 7007 static void IndexedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) {
6998 ApiTestFuzzer::Fuzz(); 7008 ApiTestFuzzer::Fuzz();
6999 v8::Handle<v8::Array> result = v8::Array::New(2); 7009 v8::Handle<v8::Array> result = v8::Array::New(2);
7000 result->Set(v8::Integer::New(0), v8_str("0")); 7010 result->Set(v8::Integer::New(0), v8_str("0"));
7001 result->Set(v8::Integer::New(1), v8_str("1")); 7011 result->Set(v8::Integer::New(1), v8_str("1"));
7002 info.GetReturnValue().Set(result); 7012 info.GetReturnValue().Set(result);
7003 } 7013 }
7004 7014
7005 7015
7006 THREADED_TEST(Enumerators) { 7016 THREADED_TEST(Enumerators) {
7007 v8::HandleScope scope(v8::Isolate::GetCurrent()); 7017 v8::HandleScope scope(CcTest::isolate());
7008 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 7018 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
7009 obj->SetNamedPropertyHandler(GetK, NULL, NULL, NULL, NamedEnum); 7019 obj->SetNamedPropertyHandler(GetK, NULL, NULL, NULL, NamedEnum);
7010 obj->SetIndexedPropertyHandler(IndexedGetK, NULL, NULL, NULL, IndexedEnum); 7020 obj->SetIndexedPropertyHandler(IndexedGetK, NULL, NULL, NULL, IndexedEnum);
7011 LocalContext context; 7021 LocalContext context;
7012 context->Global()->Set(v8_str("k"), obj->NewInstance()); 7022 context->Global()->Set(v8_str("k"), obj->NewInstance());
7013 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 7023 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun(
7014 "k[10] = 0;" 7024 "k[10] = 0;"
7015 "k.a = 0;" 7025 "k.a = 0;"
7016 "k[5] = 0;" 7026 "k[5] = 0;"
7017 "k.b = 0;" 7027 "k.b = 0;"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
7110 CHECK_EQ(info.This(), global->Get(v8_str("o2"))); 7120 CHECK_EQ(info.This(), global->Get(v8_str("o2")));
7111 } else if (name->Equals(v8_str("p3"))) { 7121 } else if (name->Equals(v8_str("p3"))) {
7112 CHECK_EQ(info.This(), global->Get(v8_str("o3"))); 7122 CHECK_EQ(info.This(), global->Get(v8_str("o3")));
7113 } else if (name->Equals(v8_str("p4"))) { 7123 } else if (name->Equals(v8_str("p4"))) {
7114 CHECK_EQ(info.This(), global->Get(v8_str("o4"))); 7124 CHECK_EQ(info.This(), global->Get(v8_str("o4")));
7115 } 7125 }
7116 } 7126 }
7117 7127
7118 7128
7119 THREADED_TEST(GetterHolders) { 7129 THREADED_TEST(GetterHolders) {
7120 v8::HandleScope scope(v8::Isolate::GetCurrent()); 7130 v8::HandleScope scope(CcTest::isolate());
7121 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 7131 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
7122 obj->SetAccessor(v8_str("p1"), PGetter); 7132 obj->SetAccessor(v8_str("p1"), PGetter);
7123 obj->SetAccessor(v8_str("p2"), PGetter); 7133 obj->SetAccessor(v8_str("p2"), PGetter);
7124 obj->SetAccessor(v8_str("p3"), PGetter); 7134 obj->SetAccessor(v8_str("p3"), PGetter);
7125 obj->SetAccessor(v8_str("p4"), PGetter); 7135 obj->SetAccessor(v8_str("p4"), PGetter);
7126 p_getter_count = 0; 7136 p_getter_count = 0;
7127 RunHolderTest(obj); 7137 RunHolderTest(obj);
7128 CHECK_EQ(40, p_getter_count); 7138 CHECK_EQ(40, p_getter_count);
7129 } 7139 }
7130 7140
7131 7141
7132 THREADED_TEST(PreInterceptorHolders) { 7142 THREADED_TEST(PreInterceptorHolders) {
7133 v8::HandleScope scope(v8::Isolate::GetCurrent()); 7143 v8::HandleScope scope(CcTest::isolate());
7134 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 7144 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
7135 obj->SetNamedPropertyHandler(PGetter2); 7145 obj->SetNamedPropertyHandler(PGetter2);
7136 p_getter_count2 = 0; 7146 p_getter_count2 = 0;
7137 RunHolderTest(obj); 7147 RunHolderTest(obj);
7138 CHECK_EQ(40, p_getter_count2); 7148 CHECK_EQ(40, p_getter_count2);
7139 } 7149 }
7140 7150
7141 7151
7142 THREADED_TEST(ObjectInstantiation) { 7152 THREADED_TEST(ObjectInstantiation) {
7143 v8::HandleScope scope(v8::Isolate::GetCurrent()); 7153 v8::HandleScope scope(CcTest::isolate());
7144 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 7154 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
7145 templ->SetAccessor(v8_str("t"), PGetter2); 7155 templ->SetAccessor(v8_str("t"), PGetter2);
7146 LocalContext context; 7156 LocalContext context;
7147 context->Global()->Set(v8_str("o"), templ->NewInstance()); 7157 context->Global()->Set(v8_str("o"), templ->NewInstance());
7148 for (int i = 0; i < 100; i++) { 7158 for (int i = 0; i < 100; i++) {
7149 v8::HandleScope inner_scope(v8::Isolate::GetCurrent()); 7159 v8::HandleScope inner_scope(CcTest::isolate());
7150 v8::Handle<v8::Object> obj = templ->NewInstance(); 7160 v8::Handle<v8::Object> obj = templ->NewInstance();
7151 CHECK_NE(obj, context->Global()->Get(v8_str("o"))); 7161 CHECK_NE(obj, context->Global()->Get(v8_str("o")));
7152 context->Global()->Set(v8_str("o2"), obj); 7162 context->Global()->Set(v8_str("o2"), obj);
7153 v8::Handle<Value> value = 7163 v8::Handle<Value> value =
7154 Script::Compile(v8_str("o.__proto__ === o2.__proto__"))->Run(); 7164 Script::Compile(v8_str("o.__proto__ === o2.__proto__"))->Run();
7155 CHECK_EQ(v8::True(), value); 7165 CHECK_EQ(v8::True(), value);
7156 context->Global()->Set(v8_str("o"), obj); 7166 context->Global()->Set(v8_str("o"), obj);
7157 } 7167 }
7158 } 7168 }
7159 7169
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
7717 Local<Value> value, 7727 Local<Value> value,
7718 const v8::PropertyCallbackInfo<void>& info) { 7728 const v8::PropertyCallbackInfo<void>& info) {
7719 if (info.This()->Has(name)) { 7729 if (info.This()->Has(name)) {
7720 info.This()->Delete(name); 7730 info.This()->Delete(name);
7721 } 7731 }
7722 info.This()->Set(name, value); 7732 info.This()->Set(name, value);
7723 } 7733 }
7724 7734
7725 7735
7726 THREADED_TEST(DeleteAccessor) { 7736 THREADED_TEST(DeleteAccessor) {
7727 v8::HandleScope scope(v8::Isolate::GetCurrent()); 7737 v8::HandleScope scope(CcTest::isolate());
7728 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 7738 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
7729 obj->SetAccessor(v8_str("y"), YGetter, YSetter); 7739 obj->SetAccessor(v8_str("y"), YGetter, YSetter);
7730 LocalContext context; 7740 LocalContext context;
7731 v8::Handle<v8::Object> holder = obj->NewInstance(); 7741 v8::Handle<v8::Object> holder = obj->NewInstance();
7732 context->Global()->Set(v8_str("holder"), holder); 7742 context->Global()->Set(v8_str("holder"), holder);
7733 v8::Handle<Value> result = CompileRun( 7743 v8::Handle<Value> result = CompileRun(
7734 "holder.y = 11; holder.y = 12; holder.y"); 7744 "holder.y = 11; holder.y = 12; holder.y");
7735 CHECK_EQ(12, result->Uint32Value()); 7745 CHECK_EQ(12, result->Uint32Value());
7736 } 7746 }
7737 7747
7738 7748
7739 THREADED_TEST(TypeSwitch) { 7749 THREADED_TEST(TypeSwitch) {
7740 v8::HandleScope scope(v8::Isolate::GetCurrent()); 7750 v8::HandleScope scope(CcTest::isolate());
7741 v8::Handle<v8::FunctionTemplate> templ1 = v8::FunctionTemplate::New(); 7751 v8::Handle<v8::FunctionTemplate> templ1 = v8::FunctionTemplate::New();
7742 v8::Handle<v8::FunctionTemplate> templ2 = v8::FunctionTemplate::New(); 7752 v8::Handle<v8::FunctionTemplate> templ2 = v8::FunctionTemplate::New();
7743 v8::Handle<v8::FunctionTemplate> templ3 = v8::FunctionTemplate::New(); 7753 v8::Handle<v8::FunctionTemplate> templ3 = v8::FunctionTemplate::New();
7744 v8::Handle<v8::FunctionTemplate> templs[3] = { templ1, templ2, templ3 }; 7754 v8::Handle<v8::FunctionTemplate> templs[3] = { templ1, templ2, templ3 };
7745 v8::Handle<v8::TypeSwitch> type_switch = v8::TypeSwitch::New(3, templs); 7755 v8::Handle<v8::TypeSwitch> type_switch = v8::TypeSwitch::New(3, templs);
7746 LocalContext context; 7756 LocalContext context;
7747 v8::Handle<v8::Object> obj0 = v8::Object::New(); 7757 v8::Handle<v8::Object> obj0 = v8::Object::New();
7748 v8::Handle<v8::Object> obj1 = templ1->GetFunction()->NewInstance(); 7758 v8::Handle<v8::Object> obj1 = templ1->GetFunction()->NewInstance();
7749 v8::Handle<v8::Object> obj2 = templ2->GetFunction()->NewInstance(); 7759 v8::Handle<v8::Object> obj2 = templ2->GetFunction()->NewInstance();
7750 v8::Handle<v8::Object> obj3 = templ3->GetFunction()->NewInstance(); 7760 v8::Handle<v8::Object> obj3 = templ3->GetFunction()->NewInstance();
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
7900 CHECK(!try_catch.HasCaught()); 7910 CHECK(!try_catch.HasCaught());
7901 Script::Compile(v8_str("(function()" 7911 Script::Compile(v8_str("(function()"
7902 " { try { throw ''; } finally { throw 0; }" 7912 " { try { throw ''; } finally { throw 0; }"
7903 "})()"))->Run(); 7913 "})()"))->Run();
7904 CHECK(try_catch.HasCaught()); 7914 CHECK(try_catch.HasCaught());
7905 } 7915 }
7906 7916
7907 7917
7908 // SecurityHandler can't be run twice 7918 // SecurityHandler can't be run twice
7909 TEST(SecurityHandler) { 7919 TEST(SecurityHandler) {
7910 v8::HandleScope scope0(v8::Isolate::GetCurrent()); 7920 v8::HandleScope scope0(CcTest::isolate());
7911 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 7921 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
7912 global_template->SetAccessCheckCallbacks(NamedSecurityTestCallback, 7922 global_template->SetAccessCheckCallbacks(NamedSecurityTestCallback,
7913 IndexedSecurityTestCallback); 7923 IndexedSecurityTestCallback);
7914 // Create an environment 7924 // Create an environment
7915 v8::Handle<Context> context0 = 7925 v8::Handle<Context> context0 =
7916 Context::New(v8::Isolate::GetCurrent(), NULL, global_template); 7926 Context::New(CcTest::isolate(), NULL, global_template);
7917 context0->Enter(); 7927 context0->Enter();
7918 7928
7919 v8::Handle<v8::Object> global0 = context0->Global(); 7929 v8::Handle<v8::Object> global0 = context0->Global();
7920 v8::Handle<Script> script0 = v8_compile("foo = 111"); 7930 v8::Handle<Script> script0 = v8_compile("foo = 111");
7921 script0->Run(); 7931 script0->Run();
7922 global0->Set(v8_str("0"), v8_num(999)); 7932 global0->Set(v8_str("0"), v8_num(999));
7923 v8::Handle<Value> foo0 = global0->Get(v8_str("foo")); 7933 v8::Handle<Value> foo0 = global0->Get(v8_str("foo"));
7924 CHECK_EQ(111, foo0->Int32Value()); 7934 CHECK_EQ(111, foo0->Int32Value());
7925 v8::Handle<Value> z0 = global0->Get(v8_str("0")); 7935 v8::Handle<Value> z0 = global0->Get(v8_str("0"));
7926 CHECK_EQ(999, z0->Int32Value()); 7936 CHECK_EQ(999, z0->Int32Value());
7927 7937
7928 // Create another environment, should fail security checks. 7938 // Create another environment, should fail security checks.
7929 v8::HandleScope scope1(v8::Isolate::GetCurrent()); 7939 v8::HandleScope scope1(CcTest::isolate());
7930 7940
7931 v8::Handle<Context> context1 = 7941 v8::Handle<Context> context1 =
7932 Context::New(v8::Isolate::GetCurrent(), NULL, global_template); 7942 Context::New(CcTest::isolate(), NULL, global_template);
7933 context1->Enter(); 7943 context1->Enter();
7934 7944
7935 v8::Handle<v8::Object> global1 = context1->Global(); 7945 v8::Handle<v8::Object> global1 = context1->Global();
7936 global1->Set(v8_str("othercontext"), global0); 7946 global1->Set(v8_str("othercontext"), global0);
7937 // This set will fail the security check. 7947 // This set will fail the security check.
7938 v8::Handle<Script> script1 = 7948 v8::Handle<Script> script1 =
7939 v8_compile("othercontext.foo = 222; othercontext[0] = 888;"); 7949 v8_compile("othercontext.foo = 222; othercontext[0] = 888;");
7940 script1->Run(); 7950 script1->Run();
7941 // This read will pass the security check. 7951 // This read will pass the security check.
7942 v8::Handle<Value> foo1 = global0->Get(v8_str("foo")); 7952 v8::Handle<Value> foo1 = global0->Get(v8_str("foo"));
7943 CHECK_EQ(111, foo1->Int32Value()); 7953 CHECK_EQ(111, foo1->Int32Value());
7944 // This read will pass the security check. 7954 // This read will pass the security check.
7945 v8::Handle<Value> z1 = global0->Get(v8_str("0")); 7955 v8::Handle<Value> z1 = global0->Get(v8_str("0"));
7946 CHECK_EQ(999, z1->Int32Value()); 7956 CHECK_EQ(999, z1->Int32Value());
7947 7957
7948 // Create another environment, should pass security checks. 7958 // Create another environment, should pass security checks.
7949 { g_security_callback_result = true; // allow security handler to pass. 7959 { g_security_callback_result = true; // allow security handler to pass.
7950 v8::HandleScope scope2(v8::Isolate::GetCurrent()); 7960 v8::HandleScope scope2(CcTest::isolate());
7951 LocalContext context2; 7961 LocalContext context2;
7952 v8::Handle<v8::Object> global2 = context2->Global(); 7962 v8::Handle<v8::Object> global2 = context2->Global();
7953 global2->Set(v8_str("othercontext"), global0); 7963 global2->Set(v8_str("othercontext"), global0);
7954 v8::Handle<Script> script2 = 7964 v8::Handle<Script> script2 =
7955 v8_compile("othercontext.foo = 333; othercontext[0] = 888;"); 7965 v8_compile("othercontext.foo = 333; othercontext[0] = 888;");
7956 script2->Run(); 7966 script2->Run();
7957 v8::Handle<Value> foo2 = global0->Get(v8_str("foo")); 7967 v8::Handle<Value> foo2 = global0->Get(v8_str("foo"));
7958 CHECK_EQ(333, foo2->Int32Value()); 7968 CHECK_EQ(333, foo2->Int32Value());
7959 v8::Handle<Value> z2 = global0->Get(v8_str("0")); 7969 v8::Handle<Value> z2 = global0->Get(v8_str("0"));
7960 CHECK_EQ(888, z2->Int32Value()); 7970 CHECK_EQ(888, z2->Int32Value());
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
8376 } 8386 }
8377 8387
8378 8388
8379 static void UnreachableFunction( 8389 static void UnreachableFunction(
8380 const v8::FunctionCallbackInfo<v8::Value>& info) { 8390 const v8::FunctionCallbackInfo<v8::Value>& info) {
8381 CHECK(false); // This function should not be called.. 8391 CHECK(false); // This function should not be called..
8382 } 8392 }
8383 8393
8384 8394
8385 TEST(AccessControl) { 8395 TEST(AccessControl) {
8386 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 8396 v8::Isolate* isolate = CcTest::isolate();
8387 v8::HandleScope handle_scope(isolate); 8397 v8::HandleScope handle_scope(isolate);
8388 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 8398 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
8389 8399
8390 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, 8400 global_template->SetAccessCheckCallbacks(NamedAccessBlocker,
8391 IndexedAccessBlocker); 8401 IndexedAccessBlocker);
8392 8402
8393 // Add an accessor accessible by cross-domain JS code. 8403 // Add an accessor accessible by cross-domain JS code.
8394 global_template->SetAccessor( 8404 global_template->SetAccessor(
8395 v8_str("accessible_prop"), 8405 v8_str("accessible_prop"),
8396 EchoGetter, EchoSetter, 8406 EchoGetter, EchoSetter,
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
8655 " }" 8665 " }"
8656 "return true;})()"); 8666 "return true;})()");
8657 CHECK(value->IsTrue()); 8667 CHECK(value->IsTrue());
8658 8668
8659 context1->Exit(); 8669 context1->Exit();
8660 context0->Exit(); 8670 context0->Exit();
8661 } 8671 }
8662 8672
8663 8673
8664 TEST(AccessControlES5) { 8674 TEST(AccessControlES5) {
8665 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 8675 v8::Isolate* isolate = CcTest::isolate();
8666 v8::HandleScope handle_scope(isolate); 8676 v8::HandleScope handle_scope(isolate);
8667 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 8677 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
8668 8678
8669 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, 8679 global_template->SetAccessCheckCallbacks(NamedAccessBlocker,
8670 IndexedAccessBlocker); 8680 IndexedAccessBlocker);
8671 8681
8672 // Add accessible accessor. 8682 // Add accessible accessor.
8673 global_template->SetAccessor( 8683 global_template->SetAccessor(
8674 v8_str("accessible_prop"), 8684 v8_str("accessible_prop"),
8675 EchoGetter, EchoSetter, 8685 EchoGetter, EchoSetter,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
8742 8752
8743 static bool GetOwnPropertyNamesIndexedBlocker(Local<v8::Object> global, 8753 static bool GetOwnPropertyNamesIndexedBlocker(Local<v8::Object> global,
8744 uint32_t key, 8754 uint32_t key,
8745 v8::AccessType type, 8755 v8::AccessType type,
8746 Local<Value> data) { 8756 Local<Value> data) {
8747 return false; 8757 return false;
8748 } 8758 }
8749 8759
8750 8760
8751 THREADED_TEST(AccessControlGetOwnPropertyNames) { 8761 THREADED_TEST(AccessControlGetOwnPropertyNames) {
8752 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 8762 v8::Isolate* isolate = CcTest::isolate();
8753 v8::HandleScope handle_scope(isolate); 8763 v8::HandleScope handle_scope(isolate);
8754 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(); 8764 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New();
8755 8765
8756 obj_template->Set(v8_str("x"), v8::Integer::New(42)); 8766 obj_template->Set(v8_str("x"), v8::Integer::New(42));
8757 obj_template->SetAccessCheckCallbacks(GetOwnPropertyNamesNamedBlocker, 8767 obj_template->SetAccessCheckCallbacks(GetOwnPropertyNamesNamedBlocker,
8758 GetOwnPropertyNamesIndexedBlocker); 8768 GetOwnPropertyNamesIndexedBlocker);
8759 8769
8760 // Create an environment 8770 // Create an environment
8761 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template); 8771 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template);
8762 context0->Enter(); 8772 context0->Enter();
8763 8773
8764 v8::Handle<v8::Object> global0 = context0->Global(); 8774 v8::Handle<v8::Object> global0 = context0->Global();
8765 8775
8766 v8::HandleScope scope1(v8::Isolate::GetCurrent()); 8776 v8::HandleScope scope1(CcTest::isolate());
8767 8777
8768 v8::Local<Context> context1 = Context::New(isolate); 8778 v8::Local<Context> context1 = Context::New(isolate);
8769 context1->Enter(); 8779 context1->Enter();
8770 8780
8771 v8::Handle<v8::Object> global1 = context1->Global(); 8781 v8::Handle<v8::Object> global1 = context1->Global();
8772 global1->Set(v8_str("other"), global0); 8782 global1->Set(v8_str("other"), global0);
8773 global1->Set(v8_str("object"), obj_template->NewInstance()); 8783 global1->Set(v8_str("object"), obj_template->NewInstance());
8774 8784
8775 v8::Handle<Value> value; 8785 v8::Handle<Value> value;
8776 8786
(...skipping 25 matching lines...) Expand all
8802 static void NamedPropertyEnumerator( 8812 static void NamedPropertyEnumerator(
8803 const v8::PropertyCallbackInfo<v8::Array>& info) { 8813 const v8::PropertyCallbackInfo<v8::Array>& info) {
8804 v8::Handle<v8::Array> result = v8::Array::New(2); 8814 v8::Handle<v8::Array> result = v8::Array::New(2);
8805 result->Set(0, v8_str("x")); 8815 result->Set(0, v8_str("x"));
8806 result->Set(1, v8::Object::New()); 8816 result->Set(1, v8::Object::New());
8807 info.GetReturnValue().Set(result); 8817 info.GetReturnValue().Set(result);
8808 } 8818 }
8809 8819
8810 8820
8811 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) { 8821 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) {
8812 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 8822 v8::HandleScope handle_scope(CcTest::isolate());
8813 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(); 8823 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New();
8814 8824
8815 obj_template->Set(v8_str("7"), v8::Integer::New(7)); 8825 obj_template->Set(v8_str("7"), v8::Integer::New(7));
8816 obj_template->Set(v8_str("x"), v8::Integer::New(42)); 8826 obj_template->Set(v8_str("x"), v8::Integer::New(42));
8817 obj_template->SetIndexedPropertyHandler(NULL, NULL, NULL, NULL, 8827 obj_template->SetIndexedPropertyHandler(NULL, NULL, NULL, NULL,
8818 IndexedPropertyEnumerator); 8828 IndexedPropertyEnumerator);
8819 obj_template->SetNamedPropertyHandler(NULL, NULL, NULL, NULL, 8829 obj_template->SetNamedPropertyHandler(NULL, NULL, NULL, NULL,
8820 NamedPropertyEnumerator); 8830 NamedPropertyEnumerator);
8821 8831
8822 LocalContext context; 8832 LocalContext context;
(...skipping 14 matching lines...) Expand all
8837 } 8847 }
8838 8848
8839 8849
8840 static void ConstTenGetter(Local<String> name, 8850 static void ConstTenGetter(Local<String> name,
8841 const v8::PropertyCallbackInfo<v8::Value>& info) { 8851 const v8::PropertyCallbackInfo<v8::Value>& info) {
8842 info.GetReturnValue().Set(v8_num(10)); 8852 info.GetReturnValue().Set(v8_num(10));
8843 } 8853 }
8844 8854
8845 8855
8846 THREADED_TEST(CrossDomainAccessors) { 8856 THREADED_TEST(CrossDomainAccessors) {
8847 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 8857 v8::Isolate* isolate = CcTest::isolate();
8848 v8::HandleScope handle_scope(isolate); 8858 v8::HandleScope handle_scope(isolate);
8849 8859
8850 v8::Handle<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); 8860 v8::Handle<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New();
8851 8861
8852 v8::Handle<v8::ObjectTemplate> global_template = 8862 v8::Handle<v8::ObjectTemplate> global_template =
8853 func_template->InstanceTemplate(); 8863 func_template->InstanceTemplate();
8854 8864
8855 v8::Handle<v8::ObjectTemplate> proto_template = 8865 v8::Handle<v8::ObjectTemplate> proto_template =
8856 func_template->PrototypeTemplate(); 8866 func_template->PrototypeTemplate();
8857 8867
(...skipping 10 matching lines...) Expand all
8868 v8::DEFAULT); 8878 v8::DEFAULT);
8869 8879
8870 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template); 8880 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template);
8871 context0->Enter(); 8881 context0->Enter();
8872 8882
8873 Local<v8::Object> global = context0->Global(); 8883 Local<v8::Object> global = context0->Global();
8874 // Add a normal property that shadows 'accessible' 8884 // Add a normal property that shadows 'accessible'
8875 global->Set(v8_str("accessible"), v8_num(11)); 8885 global->Set(v8_str("accessible"), v8_num(11));
8876 8886
8877 // Enter a new context. 8887 // Enter a new context.
8878 v8::HandleScope scope1(v8::Isolate::GetCurrent()); 8888 v8::HandleScope scope1(CcTest::isolate());
8879 v8::Local<Context> context1 = Context::New(isolate); 8889 v8::Local<Context> context1 = Context::New(isolate);
8880 context1->Enter(); 8890 context1->Enter();
8881 8891
8882 v8::Handle<v8::Object> global1 = context1->Global(); 8892 v8::Handle<v8::Object> global1 = context1->Global();
8883 global1->Set(v8_str("other"), global); 8893 global1->Set(v8_str("other"), global);
8884 8894
8885 // Should return 10, instead of 11 8895 // Should return 10, instead of 11
8886 v8::Handle<Value> value = v8_compile("other.accessible")->Run(); 8896 v8::Handle<Value> value = v8_compile("other.accessible")->Run();
8887 CHECK(value->IsNumber()); 8897 CHECK(value->IsNumber());
8888 CHECK_EQ(10, value->Int32Value()); 8898 CHECK_EQ(10, value->Int32Value());
(...skipping 25 matching lines...) Expand all
8914 indexed_access_count++; 8924 indexed_access_count++;
8915 return true; 8925 return true;
8916 } 8926 }
8917 8927
8918 8928
8919 // This one is too easily disturbed by other tests. 8929 // This one is too easily disturbed by other tests.
8920 TEST(AccessControlIC) { 8930 TEST(AccessControlIC) {
8921 named_access_count = 0; 8931 named_access_count = 0;
8922 indexed_access_count = 0; 8932 indexed_access_count = 0;
8923 8933
8924 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 8934 v8::Isolate* isolate = CcTest::isolate();
8925 v8::HandleScope handle_scope(isolate); 8935 v8::HandleScope handle_scope(isolate);
8926 8936
8927 // Create an environment. 8937 // Create an environment.
8928 v8::Local<Context> context0 = Context::New(isolate); 8938 v8::Local<Context> context0 = Context::New(isolate);
8929 context0->Enter(); 8939 context0->Enter();
8930 8940
8931 // Create an object that requires access-check functions to be 8941 // Create an object that requires access-check functions to be
8932 // called for cross-domain access. 8942 // called for cross-domain access.
8933 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 8943 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
8934 object_template->SetAccessCheckCallbacks(NamedAccessCounter, 8944 object_template->SetAccessCheckCallbacks(NamedAccessCounter,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
9062 9072
9063 // Regression test. In access checks, operations that may cause 9073 // Regression test. In access checks, operations that may cause
9064 // garbage collection are not allowed. It used to be the case that 9074 // garbage collection are not allowed. It used to be the case that
9065 // using the Write operation on a string could cause a garbage 9075 // using the Write operation on a string could cause a garbage
9066 // collection due to flattening of the string. This is no longer the 9076 // collection due to flattening of the string. This is no longer the
9067 // case. 9077 // case.
9068 THREADED_TEST(AccessControlFlatten) { 9078 THREADED_TEST(AccessControlFlatten) {
9069 named_access_count = 0; 9079 named_access_count = 0;
9070 indexed_access_count = 0; 9080 indexed_access_count = 0;
9071 9081
9072 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 9082 v8::Isolate* isolate = CcTest::isolate();
9073 v8::HandleScope handle_scope(isolate); 9083 v8::HandleScope handle_scope(isolate);
9074 9084
9075 // Create an environment. 9085 // Create an environment.
9076 v8::Local<Context> context0 = Context::New(isolate); 9086 v8::Local<Context> context0 = Context::New(isolate);
9077 context0->Enter(); 9087 context0->Enter();
9078 9088
9079 // Create an object that requires access-check functions to be 9089 // Create an object that requires access-check functions to be
9080 // called for cross-domain access. 9090 // called for cross-domain access.
9081 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 9091 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
9082 object_template->SetAccessCheckCallbacks(NamedAccessFlatten, 9092 object_template->SetAccessCheckCallbacks(NamedAccessFlatten,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
9130 Local<Value> value, 9140 Local<Value> value,
9131 const v8::PropertyCallbackInfo<v8::Value>& info) { 9141 const v8::PropertyCallbackInfo<v8::Value>& info) {
9132 info.GetReturnValue().Set(value); 9142 info.GetReturnValue().Set(value);
9133 } 9143 }
9134 9144
9135 9145
9136 THREADED_TEST(AccessControlInterceptorIC) { 9146 THREADED_TEST(AccessControlInterceptorIC) {
9137 named_access_count = 0; 9147 named_access_count = 0;
9138 indexed_access_count = 0; 9148 indexed_access_count = 0;
9139 9149
9140 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 9150 v8::Isolate* isolate = CcTest::isolate();
9141 v8::HandleScope handle_scope(isolate); 9151 v8::HandleScope handle_scope(isolate);
9142 9152
9143 // Create an environment. 9153 // Create an environment.
9144 v8::Local<Context> context0 = Context::New(isolate); 9154 v8::Local<Context> context0 = Context::New(isolate);
9145 context0->Enter(); 9155 context0->Enter();
9146 9156
9147 // Create an object that requires access-check functions to be 9157 // Create an object that requires access-check functions to be
9148 // called for cross-domain access. The object also has interceptors 9158 // called for cross-domain access. The object also has interceptors
9149 // interceptor. 9159 // interceptor.
9150 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 9160 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
9234 9244
9235 9245
9236 static void GlobalObjectInstancePropertiesGet( 9246 static void GlobalObjectInstancePropertiesGet(
9237 Local<String> key, 9247 Local<String> key,
9238 const v8::PropertyCallbackInfo<v8::Value>&) { 9248 const v8::PropertyCallbackInfo<v8::Value>&) {
9239 ApiTestFuzzer::Fuzz(); 9249 ApiTestFuzzer::Fuzz();
9240 } 9250 }
9241 9251
9242 9252
9243 THREADED_TEST(GlobalObjectInstanceProperties) { 9253 THREADED_TEST(GlobalObjectInstanceProperties) {
9244 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 9254 v8::HandleScope handle_scope(CcTest::isolate());
9245 9255
9246 Local<Value> global_object; 9256 Local<Value> global_object;
9247 9257
9248 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 9258 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
9249 t->InstanceTemplate()->SetNamedPropertyHandler( 9259 t->InstanceTemplate()->SetNamedPropertyHandler(
9250 GlobalObjectInstancePropertiesGet); 9260 GlobalObjectInstancePropertiesGet);
9251 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); 9261 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
9252 instance_template->Set(v8_str("x"), v8_num(42)); 9262 instance_template->Set(v8_str("x"), v8_num(42));
9253 instance_template->Set(v8_str("f"), 9263 instance_template->Set(v8_str("f"),
9254 v8::FunctionTemplate::New(InstanceFunctionCallback)); 9264 v8::FunctionTemplate::New(InstanceFunctionCallback));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
9290 CHECK_EQ(42, value->Int32Value()); 9300 CHECK_EQ(42, value->Int32Value());
9291 value = Script::Compile(v8_str("f()"))->Run(); 9301 value = Script::Compile(v8_str("f()"))->Run();
9292 CHECK_EQ(12, value->Int32Value()); 9302 CHECK_EQ(12, value->Int32Value());
9293 value = Script::Compile(v8_str(script))->Run(); 9303 value = Script::Compile(v8_str(script))->Run();
9294 CHECK_EQ(1, value->Int32Value()); 9304 CHECK_EQ(1, value->Int32Value());
9295 } 9305 }
9296 } 9306 }
9297 9307
9298 9308
9299 THREADED_TEST(CallKnownGlobalReceiver) { 9309 THREADED_TEST(CallKnownGlobalReceiver) {
9300 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 9310 v8::HandleScope handle_scope(CcTest::isolate());
9301 9311
9302 Local<Value> global_object; 9312 Local<Value> global_object;
9303 9313
9304 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 9314 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
9305 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); 9315 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
9306 9316
9307 // The script to check that we leave global object not 9317 // The script to check that we leave global object not
9308 // global object proxy on stack when we deoptimize from inside 9318 // global object proxy on stack when we deoptimize from inside
9309 // arguments evaluation. 9319 // arguments evaluation.
9310 // To provoke error we need to both force deoptimization 9320 // To provoke error we need to both force deoptimization
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
9369 } 9379 }
9370 9380
9371 9381
9372 static void ShadowNamedGet(Local<String> key, 9382 static void ShadowNamedGet(Local<String> key,
9373 const v8::PropertyCallbackInfo<v8::Value>&) { 9383 const v8::PropertyCallbackInfo<v8::Value>&) {
9374 } 9384 }
9375 9385
9376 9386
9377 THREADED_TEST(ShadowObject) { 9387 THREADED_TEST(ShadowObject) {
9378 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0; 9388 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0;
9379 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 9389 v8::HandleScope handle_scope(CcTest::isolate());
9380 9390
9381 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New(); 9391 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New();
9382 LocalContext context(NULL, global_template); 9392 LocalContext context(NULL, global_template);
9383 9393
9384 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 9394 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
9385 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet); 9395 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet);
9386 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet); 9396 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet);
9387 Local<ObjectTemplate> proto = t->PrototypeTemplate(); 9397 Local<ObjectTemplate> proto = t->PrototypeTemplate();
9388 Local<ObjectTemplate> instance = t->InstanceTemplate(); 9398 Local<ObjectTemplate> instance = t->InstanceTemplate();
9389 9399
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
9669 9679
9670 Local<v8::Object> o0 = t->GetFunction()->NewInstance(); 9680 Local<v8::Object> o0 = t->GetFunction()->NewInstance();
9671 Local<v8::Object> o1 = t->GetFunction()->NewInstance(); 9681 Local<v8::Object> o1 = t->GetFunction()->NewInstance();
9672 9682
9673 CHECK(o0->SetPrototype(o1)); 9683 CHECK(o0->SetPrototype(o1));
9674 // If setting the prototype leads to the cycle, SetPrototype should 9684 // If setting the prototype leads to the cycle, SetPrototype should
9675 // return false and keep VM in sane state. 9685 // return false and keep VM in sane state.
9676 v8::TryCatch try_catch; 9686 v8::TryCatch try_catch;
9677 CHECK(!o1->SetPrototype(o0)); 9687 CHECK(!o1->SetPrototype(o0));
9678 CHECK(!try_catch.HasCaught()); 9688 CHECK(!try_catch.HasCaught());
9679 ASSERT(!i::Isolate::Current()->has_pending_exception()); 9689 ASSERT(!CcTest::i_isolate()->has_pending_exception());
9680 9690
9681 CHECK_EQ(42, CompileRun("function f() { return 42; }; f()")->Int32Value()); 9691 CHECK_EQ(42, CompileRun("function f() { return 42; }; f()")->Int32Value());
9682 } 9692 }
9683 9693
9684 9694
9685 THREADED_TEST(FunctionRemovePrototype) { 9695 THREADED_TEST(FunctionRemovePrototype) {
9686 LocalContext context; 9696 LocalContext context;
9687 v8::HandleScope handle_scope(context->GetIsolate()); 9697 v8::HandleScope handle_scope(context->GetIsolate());
9688 9698
9689 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); 9699 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New();
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
9990 "result4 = f(this)")); 10000 "result4 = f(this)"));
9991 script->Run(); 10001 script->Run();
9992 CHECK(!try_catch.HasCaught()); 10002 CHECK(!try_catch.HasCaught());
9993 CHECK_EQ(2, current->Global()->Get(v8_str("result4"))->Int32Value()); 10003 CHECK_EQ(2, current->Global()->Get(v8_str("result4"))->Int32Value());
9994 10004
9995 try_catch.Reset(); 10005 try_catch.Reset();
9996 } 10006 }
9997 10007
9998 10008
9999 THREADED_TEST(CrossEval) { 10009 THREADED_TEST(CrossEval) {
10000 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10010 v8::HandleScope scope(CcTest::isolate());
10001 LocalContext other; 10011 LocalContext other;
10002 LocalContext current; 10012 LocalContext current;
10003 10013
10004 Local<String> token = v8_str("<security token>"); 10014 Local<String> token = v8_str("<security token>");
10005 other->SetSecurityToken(token); 10015 other->SetSecurityToken(token);
10006 current->SetSecurityToken(token); 10016 current->SetSecurityToken(token);
10007 10017
10008 // Set up reference from current to other. 10018 // Set up reference from current to other.
10009 current->Global()->Set(v8_str("other"), other->Global()); 10019 current->Global()->Set(v8_str("other"), other->Global());
10010 10020
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
10073 Script::Compile(v8_str("other.y = 1; eval.call(other, 'y')")); 10083 Script::Compile(v8_str("other.y = 1; eval.call(other, 'y')"));
10074 result = script->Run(); 10084 result = script->Run();
10075 CHECK(try_catch.HasCaught()); 10085 CHECK(try_catch.HasCaught());
10076 } 10086 }
10077 10087
10078 10088
10079 // Test that calling eval in a context which has been detached from 10089 // Test that calling eval in a context which has been detached from
10080 // its global throws an exception. This behavior is consistent with 10090 // its global throws an exception. This behavior is consistent with
10081 // other JavaScript implementations. 10091 // other JavaScript implementations.
10082 THREADED_TEST(EvalInDetachedGlobal) { 10092 THREADED_TEST(EvalInDetachedGlobal) {
10083 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 10093 v8::Isolate* isolate = CcTest::isolate();
10084 v8::HandleScope scope(isolate); 10094 v8::HandleScope scope(isolate);
10085 10095
10086 v8::Local<Context> context0 = Context::New(isolate); 10096 v8::Local<Context> context0 = Context::New(isolate);
10087 v8::Local<Context> context1 = Context::New(isolate); 10097 v8::Local<Context> context1 = Context::New(isolate);
10088 10098
10089 // Set up function in context0 that uses eval from context0. 10099 // Set up function in context0 that uses eval from context0.
10090 context0->Enter(); 10100 context0->Enter();
10091 v8::Handle<v8::Value> fun = 10101 v8::Handle<v8::Value> fun =
10092 CompileRun("var x = 42;" 10102 CompileRun("var x = 42;"
10093 "(function() {" 10103 "(function() {"
(...skipping 12 matching lines...) Expand all
10106 context0->DetachGlobal(); 10116 context0->DetachGlobal();
10107 v8::TryCatch catcher; 10117 v8::TryCatch catcher;
10108 x_value = CompileRun("fun('x')"); 10118 x_value = CompileRun("fun('x')");
10109 CHECK(x_value.IsEmpty()); 10119 CHECK(x_value.IsEmpty());
10110 CHECK(catcher.HasCaught()); 10120 CHECK(catcher.HasCaught());
10111 context1->Exit(); 10121 context1->Exit();
10112 } 10122 }
10113 10123
10114 10124
10115 THREADED_TEST(CrossLazyLoad) { 10125 THREADED_TEST(CrossLazyLoad) {
10116 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10126 v8::HandleScope scope(CcTest::isolate());
10117 LocalContext other; 10127 LocalContext other;
10118 LocalContext current; 10128 LocalContext current;
10119 10129
10120 Local<String> token = v8_str("<security token>"); 10130 Local<String> token = v8_str("<security token>");
10121 other->SetSecurityToken(token); 10131 other->SetSecurityToken(token);
10122 current->SetSecurityToken(token); 10132 current->SetSecurityToken(token);
10123 10133
10124 // Set up reference from current to other. 10134 // Set up reference from current to other.
10125 current->Global()->Set(v8_str("other"), other->Global()); 10135 current->Global()->Set(v8_str("other"), other->Global());
10126 10136
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
10302 } 10312 }
10303 } 10313 }
10304 10314
10305 10315
10306 static int CountHandles() { 10316 static int CountHandles() {
10307 return v8::HandleScope::NumberOfHandles(); 10317 return v8::HandleScope::NumberOfHandles();
10308 } 10318 }
10309 10319
10310 10320
10311 static int Recurse(int depth, int iterations) { 10321 static int Recurse(int depth, int iterations) {
10312 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10322 v8::HandleScope scope(CcTest::isolate());
10313 if (depth == 0) return CountHandles(); 10323 if (depth == 0) return CountHandles();
10314 for (int i = 0; i < iterations; i++) { 10324 for (int i = 0; i < iterations; i++) {
10315 Local<v8::Number> n(v8::Integer::New(42)); 10325 Local<v8::Number> n(v8::Integer::New(42));
10316 } 10326 }
10317 return Recurse(depth - 1, iterations); 10327 return Recurse(depth - 1, iterations);
10318 } 10328 }
10319 10329
10320 10330
10321 THREADED_TEST(HandleIteration) { 10331 THREADED_TEST(HandleIteration) {
10322 static const int kIterations = 500; 10332 static const int kIterations = 500;
10323 static const int kNesting = 200; 10333 static const int kNesting = 200;
10324 CHECK_EQ(0, CountHandles()); 10334 CHECK_EQ(0, CountHandles());
10325 { 10335 {
10326 v8::HandleScope scope1(v8::Isolate::GetCurrent()); 10336 v8::HandleScope scope1(CcTest::isolate());
10327 CHECK_EQ(0, CountHandles()); 10337 CHECK_EQ(0, CountHandles());
10328 for (int i = 0; i < kIterations; i++) { 10338 for (int i = 0; i < kIterations; i++) {
10329 Local<v8::Number> n(v8::Integer::New(42)); 10339 Local<v8::Number> n(v8::Integer::New(42));
10330 CHECK_EQ(i + 1, CountHandles()); 10340 CHECK_EQ(i + 1, CountHandles());
10331 } 10341 }
10332 10342
10333 CHECK_EQ(kIterations, CountHandles()); 10343 CHECK_EQ(kIterations, CountHandles());
10334 { 10344 {
10335 v8::HandleScope scope2(v8::Isolate::GetCurrent()); 10345 v8::HandleScope scope2(CcTest::isolate());
10336 for (int j = 0; j < kIterations; j++) { 10346 for (int j = 0; j < kIterations; j++) {
10337 Local<v8::Number> n(v8::Integer::New(42)); 10347 Local<v8::Number> n(v8::Integer::New(42));
10338 CHECK_EQ(j + 1 + kIterations, CountHandles()); 10348 CHECK_EQ(j + 1 + kIterations, CountHandles());
10339 } 10349 }
10340 } 10350 }
10341 CHECK_EQ(kIterations, CountHandles()); 10351 CHECK_EQ(kIterations, CountHandles());
10342 } 10352 }
10343 CHECK_EQ(0, CountHandles()); 10353 CHECK_EQ(0, CountHandles());
10344 CHECK_EQ(kNesting * kIterations, Recurse(kNesting, kIterations)); 10354 CHECK_EQ(kNesting * kIterations, Recurse(kNesting, kIterations));
10345 } 10355 }
(...skipping 26 matching lines...) Expand all
10372 "var p = new constructor();" 10382 "var p = new constructor();"
10373 "p.hasOwnProperty('ostehaps');"); 10383 "p.hasOwnProperty('ostehaps');");
10374 CHECK_EQ(false, value->BooleanValue()); 10384 CHECK_EQ(false, value->BooleanValue());
10375 } 10385 }
10376 10386
10377 10387
10378 static void InterceptorHasOwnPropertyGetterGC( 10388 static void InterceptorHasOwnPropertyGetterGC(
10379 Local<String> name, 10389 Local<String> name,
10380 const v8::PropertyCallbackInfo<v8::Value>& info) { 10390 const v8::PropertyCallbackInfo<v8::Value>& info) {
10381 ApiTestFuzzer::Fuzz(); 10391 ApiTestFuzzer::Fuzz();
10382 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 10392 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
10383 } 10393 }
10384 10394
10385 10395
10386 THREADED_TEST(InterceptorHasOwnPropertyCausingGC) { 10396 THREADED_TEST(InterceptorHasOwnPropertyCausingGC) {
10387 LocalContext context; 10397 LocalContext context;
10388 v8::HandleScope scope(context->GetIsolate()); 10398 v8::HandleScope scope(context->GetIsolate());
10389 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10399 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10390 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); 10400 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
10391 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetterGC); 10401 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetterGC);
10392 Local<Function> function = fun_templ->GetFunction(); 10402 Local<Function> function = fun_templ->GetFunction();
(...skipping 20 matching lines...) Expand all
10413 10423
10414 10424
10415 typedef void (*NamedPropertyGetter)( 10425 typedef void (*NamedPropertyGetter)(
10416 Local<String> property, 10426 Local<String> property,
10417 const v8::PropertyCallbackInfo<v8::Value>& info); 10427 const v8::PropertyCallbackInfo<v8::Value>& info);
10418 10428
10419 10429
10420 static void CheckInterceptorLoadIC(NamedPropertyGetter getter, 10430 static void CheckInterceptorLoadIC(NamedPropertyGetter getter,
10421 const char* source, 10431 const char* source,
10422 int expected) { 10432 int expected) {
10423 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10433 v8::HandleScope scope(CcTest::isolate());
10424 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10434 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10425 templ->SetNamedPropertyHandler(getter, 0, 0, 0, 0, v8_str("data")); 10435 templ->SetNamedPropertyHandler(getter, 0, 0, 0, 0, v8_str("data"));
10426 LocalContext context; 10436 LocalContext context;
10427 context->Global()->Set(v8_str("o"), templ->NewInstance()); 10437 context->Global()->Set(v8_str("o"), templ->NewInstance());
10428 v8::Handle<Value> value = CompileRun(source); 10438 v8::Handle<Value> value = CompileRun(source);
10429 CHECK_EQ(expected, value->Int32Value()); 10439 CHECK_EQ(expected, value->Int32Value());
10430 } 10440 }
10431 10441
10432 10442
10433 static void InterceptorLoadICGetter( 10443 static void InterceptorLoadICGetter(
10434 Local<String> name, 10444 Local<String> name,
10435 const v8::PropertyCallbackInfo<v8::Value>& info) { 10445 const v8::PropertyCallbackInfo<v8::Value>& info) {
10436 ApiTestFuzzer::Fuzz(); 10446 ApiTestFuzzer::Fuzz();
10437 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 10447 v8::Isolate* isolate = CcTest::isolate();
10438 CHECK_EQ(isolate, info.GetIsolate()); 10448 CHECK_EQ(isolate, info.GetIsolate());
10439 CHECK_EQ(v8_str("data"), info.Data()); 10449 CHECK_EQ(v8_str("data"), info.Data());
10440 CHECK_EQ(v8_str("x"), name); 10450 CHECK_EQ(v8_str("x"), name);
10441 info.GetReturnValue().Set(v8::Integer::New(42)); 10451 info.GetReturnValue().Set(v8::Integer::New(42));
10442 } 10452 }
10443 10453
10444 10454
10445 // This test should hit the load IC for the interceptor case. 10455 // This test should hit the load IC for the interceptor case.
10446 THREADED_TEST(InterceptorLoadIC) { 10456 THREADED_TEST(InterceptorLoadIC) {
10447 CheckInterceptorLoadIC(InterceptorLoadICGetter, 10457 CheckInterceptorLoadIC(InterceptorLoadICGetter,
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
10626 10636
10627 10637
10628 static void SetOnThis(Local<String> name, 10638 static void SetOnThis(Local<String> name,
10629 Local<Value> value, 10639 Local<Value> value,
10630 const v8::PropertyCallbackInfo<void>& info) { 10640 const v8::PropertyCallbackInfo<void>& info) {
10631 info.This()->ForceSet(name, value); 10641 info.This()->ForceSet(name, value);
10632 } 10642 }
10633 10643
10634 10644
10635 THREADED_TEST(InterceptorLoadICWithCallbackOnHolder) { 10645 THREADED_TEST(InterceptorLoadICWithCallbackOnHolder) {
10636 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10646 v8::HandleScope scope(CcTest::isolate());
10637 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10647 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10638 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); 10648 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter);
10639 templ->SetAccessor(v8_str("y"), Return239Callback); 10649 templ->SetAccessor(v8_str("y"), Return239Callback);
10640 LocalContext context; 10650 LocalContext context;
10641 context->Global()->Set(v8_str("o"), templ->NewInstance()); 10651 context->Global()->Set(v8_str("o"), templ->NewInstance());
10642 10652
10643 // Check the case when receiver and interceptor's holder 10653 // Check the case when receiver and interceptor's holder
10644 // are the same objects. 10654 // are the same objects.
10645 v8::Handle<Value> value = CompileRun( 10655 v8::Handle<Value> value = CompileRun(
10646 "var result = 0;" 10656 "var result = 0;"
10647 "for (var i = 0; i < 7; i++) {" 10657 "for (var i = 0; i < 7; i++) {"
10648 " result = o.y;" 10658 " result = o.y;"
10649 "}"); 10659 "}");
10650 CHECK_EQ(239, value->Int32Value()); 10660 CHECK_EQ(239, value->Int32Value());
10651 10661
10652 // Check the case when interceptor's holder is in proto chain 10662 // Check the case when interceptor's holder is in proto chain
10653 // of receiver. 10663 // of receiver.
10654 value = CompileRun( 10664 value = CompileRun(
10655 "r = { __proto__: o };" 10665 "r = { __proto__: o };"
10656 "var result = 0;" 10666 "var result = 0;"
10657 "for (var i = 0; i < 7; i++) {" 10667 "for (var i = 0; i < 7; i++) {"
10658 " result = r.y;" 10668 " result = r.y;"
10659 "}"); 10669 "}");
10660 CHECK_EQ(239, value->Int32Value()); 10670 CHECK_EQ(239, value->Int32Value());
10661 } 10671 }
10662 10672
10663 10673
10664 THREADED_TEST(InterceptorLoadICWithCallbackOnProto) { 10674 THREADED_TEST(InterceptorLoadICWithCallbackOnProto) {
10665 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10675 v8::HandleScope scope(CcTest::isolate());
10666 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 10676 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
10667 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); 10677 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter);
10668 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); 10678 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New();
10669 templ_p->SetAccessor(v8_str("y"), Return239Callback); 10679 templ_p->SetAccessor(v8_str("y"), Return239Callback);
10670 10680
10671 LocalContext context; 10681 LocalContext context;
10672 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 10682 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
10673 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); 10683 context->Global()->Set(v8_str("p"), templ_p->NewInstance());
10674 10684
10675 // Check the case when receiver and interceptor's holder 10685 // Check the case when receiver and interceptor's holder
(...skipping 12 matching lines...) Expand all
10688 "r = { __proto__: o };" 10698 "r = { __proto__: o };"
10689 "var result = 0;" 10699 "var result = 0;"
10690 "for (var i = 0; i < 7; i++) {" 10700 "for (var i = 0; i < 7; i++) {"
10691 " result = r.x + r.y;" 10701 " result = r.x + r.y;"
10692 "}"); 10702 "}");
10693 CHECK_EQ(239 + 42, value->Int32Value()); 10703 CHECK_EQ(239 + 42, value->Int32Value());
10694 } 10704 }
10695 10705
10696 10706
10697 THREADED_TEST(InterceptorLoadICForCallbackWithOverride) { 10707 THREADED_TEST(InterceptorLoadICForCallbackWithOverride) {
10698 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10708 v8::HandleScope scope(CcTest::isolate());
10699 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10709 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10700 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); 10710 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter);
10701 templ->SetAccessor(v8_str("y"), Return239Callback); 10711 templ->SetAccessor(v8_str("y"), Return239Callback);
10702 10712
10703 LocalContext context; 10713 LocalContext context;
10704 context->Global()->Set(v8_str("o"), templ->NewInstance()); 10714 context->Global()->Set(v8_str("o"), templ->NewInstance());
10705 10715
10706 v8::Handle<Value> value = CompileRun( 10716 v8::Handle<Value> value = CompileRun(
10707 "fst = new Object(); fst.__proto__ = o;" 10717 "fst = new Object(); fst.__proto__ = o;"
10708 "snd = new Object(); snd.__proto__ = fst;" 10718 "snd = new Object(); snd.__proto__ = fst;"
10709 "var result1 = 0;" 10719 "var result1 = 0;"
10710 "for (var i = 0; i < 7; i++) {" 10720 "for (var i = 0; i < 7; i++) {"
10711 " result1 = snd.x;" 10721 " result1 = snd.x;"
10712 "}" 10722 "}"
10713 "fst.x = 239;" 10723 "fst.x = 239;"
10714 "var result = 0;" 10724 "var result = 0;"
10715 "for (var i = 0; i < 7; i++) {" 10725 "for (var i = 0; i < 7; i++) {"
10716 " result = snd.x;" 10726 " result = snd.x;"
10717 "}" 10727 "}"
10718 "result + result1"); 10728 "result + result1");
10719 CHECK_EQ(239 + 42, value->Int32Value()); 10729 CHECK_EQ(239 + 42, value->Int32Value());
10720 } 10730 }
10721 10731
10722 10732
10723 // Test the case when we stored callback into 10733 // Test the case when we stored callback into
10724 // a stub, but interceptor produced value on its own. 10734 // a stub, but interceptor produced value on its own.
10725 THREADED_TEST(InterceptorLoadICCallbackNotNeeded) { 10735 THREADED_TEST(InterceptorLoadICCallbackNotNeeded) {
10726 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10736 v8::HandleScope scope(CcTest::isolate());
10727 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 10737 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
10728 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); 10738 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter);
10729 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); 10739 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New();
10730 templ_p->SetAccessor(v8_str("y"), Return239Callback); 10740 templ_p->SetAccessor(v8_str("y"), Return239Callback);
10731 10741
10732 LocalContext context; 10742 LocalContext context;
10733 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 10743 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
10734 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); 10744 context->Global()->Set(v8_str("p"), templ_p->NewInstance());
10735 10745
10736 v8::Handle<Value> value = CompileRun( 10746 v8::Handle<Value> value = CompileRun(
10737 "o.__proto__ = p;" 10747 "o.__proto__ = p;"
10738 "for (var i = 0; i < 7; i++) {" 10748 "for (var i = 0; i < 7; i++) {"
10739 " o.x;" 10749 " o.x;"
10740 // Now it should be ICed and keep a reference to x defined on p 10750 // Now it should be ICed and keep a reference to x defined on p
10741 "}" 10751 "}"
10742 "var result = 0;" 10752 "var result = 0;"
10743 "for (var i = 0; i < 7; i++) {" 10753 "for (var i = 0; i < 7; i++) {"
10744 " result += o.x;" 10754 " result += o.x;"
10745 "}" 10755 "}"
10746 "result"); 10756 "result");
10747 CHECK_EQ(42 * 7, value->Int32Value()); 10757 CHECK_EQ(42 * 7, value->Int32Value());
10748 } 10758 }
10749 10759
10750 10760
10751 // Test the case when we stored callback into 10761 // Test the case when we stored callback into
10752 // a stub, but it got invalidated later on. 10762 // a stub, but it got invalidated later on.
10753 THREADED_TEST(InterceptorLoadICInvalidatedCallback) { 10763 THREADED_TEST(InterceptorLoadICInvalidatedCallback) {
10754 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10764 v8::HandleScope scope(CcTest::isolate());
10755 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 10765 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
10756 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); 10766 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter);
10757 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); 10767 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New();
10758 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis); 10768 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis);
10759 10769
10760 LocalContext context; 10770 LocalContext context;
10761 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 10771 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
10762 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); 10772 context->Global()->Set(v8_str("p"), templ_p->NewInstance());
10763 10773
10764 v8::Handle<Value> value = CompileRun( 10774 v8::Handle<Value> value = CompileRun(
(...skipping 11 matching lines...) Expand all
10776 "}" 10786 "}"
10777 "result"); 10787 "result");
10778 CHECK_EQ(42 * 10, value->Int32Value()); 10788 CHECK_EQ(42 * 10, value->Int32Value());
10779 } 10789 }
10780 10790
10781 10791
10782 // Test the case when we stored callback into 10792 // Test the case when we stored callback into
10783 // a stub, but it got invalidated later on due to override on 10793 // a stub, but it got invalidated later on due to override on
10784 // global object which is between interceptor and callbacks' holders. 10794 // global object which is between interceptor and callbacks' holders.
10785 THREADED_TEST(InterceptorLoadICInvalidatedCallbackViaGlobal) { 10795 THREADED_TEST(InterceptorLoadICInvalidatedCallbackViaGlobal) {
10786 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10796 v8::HandleScope scope(CcTest::isolate());
10787 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 10797 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
10788 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); 10798 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter);
10789 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); 10799 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New();
10790 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis); 10800 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis);
10791 10801
10792 LocalContext context; 10802 LocalContext context;
10793 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 10803 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
10794 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); 10804 context->Global()->Set(v8_str("p"), templ_p->NewInstance());
10795 10805
10796 v8::Handle<Value> value = CompileRun( 10806 v8::Handle<Value> value = CompileRun(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
10831 Local<Value> value, 10841 Local<Value> value,
10832 const v8::PropertyCallbackInfo<v8::Value>& info) { 10842 const v8::PropertyCallbackInfo<v8::Value>& info) {
10833 CHECK(v8_str("x")->Equals(key)); 10843 CHECK(v8_str("x")->Equals(key));
10834 CHECK_EQ(42, value->Int32Value()); 10844 CHECK_EQ(42, value->Int32Value());
10835 info.GetReturnValue().Set(value); 10845 info.GetReturnValue().Set(value);
10836 } 10846 }
10837 10847
10838 10848
10839 // This test should hit the store IC for the interceptor case. 10849 // This test should hit the store IC for the interceptor case.
10840 THREADED_TEST(InterceptorStoreIC) { 10850 THREADED_TEST(InterceptorStoreIC) {
10841 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10851 v8::HandleScope scope(CcTest::isolate());
10842 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10852 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10843 templ->SetNamedPropertyHandler(InterceptorLoadICGetter, 10853 templ->SetNamedPropertyHandler(InterceptorLoadICGetter,
10844 InterceptorStoreICSetter, 10854 InterceptorStoreICSetter,
10845 0, 0, 0, v8_str("data")); 10855 0, 0, 0, v8_str("data"));
10846 LocalContext context; 10856 LocalContext context;
10847 context->Global()->Set(v8_str("o"), templ->NewInstance()); 10857 context->Global()->Set(v8_str("o"), templ->NewInstance());
10848 CompileRun( 10858 CompileRun(
10849 "for (var i = 0; i < 1000; i++) {" 10859 "for (var i = 0; i < 1000; i++) {"
10850 " o.x = 42;" 10860 " o.x = 42;"
10851 "}"); 10861 "}");
10852 } 10862 }
10853 10863
10854 10864
10855 THREADED_TEST(InterceptorStoreICWithNoSetter) { 10865 THREADED_TEST(InterceptorStoreICWithNoSetter) {
10856 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10866 v8::HandleScope scope(CcTest::isolate());
10857 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10867 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10858 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); 10868 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter);
10859 LocalContext context; 10869 LocalContext context;
10860 context->Global()->Set(v8_str("o"), templ->NewInstance()); 10870 context->Global()->Set(v8_str("o"), templ->NewInstance());
10861 v8::Handle<Value> value = CompileRun( 10871 v8::Handle<Value> value = CompileRun(
10862 "for (var i = 0; i < 1000; i++) {" 10872 "for (var i = 0; i < 1000; i++) {"
10863 " o.y = 239;" 10873 " o.y = 239;"
10864 "}" 10874 "}"
10865 "42 + o.y"); 10875 "42 + o.y");
10866 CHECK_EQ(239 + 42, value->Int32Value()); 10876 CHECK_EQ(239 + 42, value->Int32Value());
(...skipping 10 matching lines...) Expand all
10877 Local<String> name, 10887 Local<String> name,
10878 const v8::PropertyCallbackInfo<v8::Value>& info) { 10888 const v8::PropertyCallbackInfo<v8::Value>& info) {
10879 ApiTestFuzzer::Fuzz(); 10889 ApiTestFuzzer::Fuzz();
10880 CHECK(v8_str("x")->Equals(name)); 10890 CHECK(v8_str("x")->Equals(name));
10881 info.GetReturnValue().Set(call_ic_function); 10891 info.GetReturnValue().Set(call_ic_function);
10882 } 10892 }
10883 10893
10884 10894
10885 // This test should hit the call IC for the interceptor case. 10895 // This test should hit the call IC for the interceptor case.
10886 THREADED_TEST(InterceptorCallIC) { 10896 THREADED_TEST(InterceptorCallIC) {
10887 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10897 v8::HandleScope scope(CcTest::isolate());
10888 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10898 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10889 templ->SetNamedPropertyHandler(InterceptorCallICGetter); 10899 templ->SetNamedPropertyHandler(InterceptorCallICGetter);
10890 LocalContext context; 10900 LocalContext context;
10891 context->Global()->Set(v8_str("o"), templ->NewInstance()); 10901 context->Global()->Set(v8_str("o"), templ->NewInstance());
10892 call_ic_function = 10902 call_ic_function =
10893 v8_compile("function f(x) { return x + 1; }; f")->Run(); 10903 v8_compile("function f(x) { return x + 1; }; f")->Run();
10894 v8::Handle<Value> value = CompileRun( 10904 v8::Handle<Value> value = CompileRun(
10895 "var result = 0;" 10905 "var result = 0;"
10896 "for (var i = 0; i < 1000; i++) {" 10906 "for (var i = 0; i < 1000; i++) {"
10897 " result = o.x(41);" 10907 " result = o.x(41);"
10898 "}"); 10908 "}");
10899 CHECK_EQ(42, value->Int32Value()); 10909 CHECK_EQ(42, value->Int32Value());
10900 } 10910 }
10901 10911
10902 10912
10903 // This test checks that if interceptor doesn't provide 10913 // This test checks that if interceptor doesn't provide
10904 // a value, we can fetch regular value. 10914 // a value, we can fetch regular value.
10905 THREADED_TEST(InterceptorCallICSeesOthers) { 10915 THREADED_TEST(InterceptorCallICSeesOthers) {
10906 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10916 v8::HandleScope scope(CcTest::isolate());
10907 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10917 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10908 templ->SetNamedPropertyHandler(NoBlockGetterX); 10918 templ->SetNamedPropertyHandler(NoBlockGetterX);
10909 LocalContext context; 10919 LocalContext context;
10910 context->Global()->Set(v8_str("o"), templ->NewInstance()); 10920 context->Global()->Set(v8_str("o"), templ->NewInstance());
10911 v8::Handle<Value> value = CompileRun( 10921 v8::Handle<Value> value = CompileRun(
10912 "o.x = function f(x) { return x + 1; };" 10922 "o.x = function f(x) { return x + 1; };"
10913 "var result = 0;" 10923 "var result = 0;"
10914 "for (var i = 0; i < 7; i++) {" 10924 "for (var i = 0; i < 7; i++) {"
10915 " result = o.x(41);" 10925 " result = o.x(41);"
10916 "}"); 10926 "}");
10917 CHECK_EQ(42, value->Int32Value()); 10927 CHECK_EQ(42, value->Int32Value());
10918 } 10928 }
10919 10929
10920 10930
10921 static v8::Handle<Value> call_ic_function4; 10931 static v8::Handle<Value> call_ic_function4;
10922 static void InterceptorCallICGetter4( 10932 static void InterceptorCallICGetter4(
10923 Local<String> name, 10933 Local<String> name,
10924 const v8::PropertyCallbackInfo<v8::Value>& info) { 10934 const v8::PropertyCallbackInfo<v8::Value>& info) {
10925 ApiTestFuzzer::Fuzz(); 10935 ApiTestFuzzer::Fuzz();
10926 CHECK(v8_str("x")->Equals(name)); 10936 CHECK(v8_str("x")->Equals(name));
10927 info.GetReturnValue().Set(call_ic_function4); 10937 info.GetReturnValue().Set(call_ic_function4);
10928 } 10938 }
10929 10939
10930 10940
10931 // This test checks that if interceptor provides a function, 10941 // This test checks that if interceptor provides a function,
10932 // even if we cached shadowed variant, interceptor's function 10942 // even if we cached shadowed variant, interceptor's function
10933 // is invoked 10943 // is invoked
10934 THREADED_TEST(InterceptorCallICCacheableNotNeeded) { 10944 THREADED_TEST(InterceptorCallICCacheableNotNeeded) {
10935 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10945 v8::HandleScope scope(CcTest::isolate());
10936 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10946 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10937 templ->SetNamedPropertyHandler(InterceptorCallICGetter4); 10947 templ->SetNamedPropertyHandler(InterceptorCallICGetter4);
10938 LocalContext context; 10948 LocalContext context;
10939 context->Global()->Set(v8_str("o"), templ->NewInstance()); 10949 context->Global()->Set(v8_str("o"), templ->NewInstance());
10940 call_ic_function4 = 10950 call_ic_function4 =
10941 v8_compile("function f(x) { return x - 1; }; f")->Run(); 10951 v8_compile("function f(x) { return x - 1; }; f")->Run();
10942 v8::Handle<Value> value = CompileRun( 10952 v8::Handle<Value> value = CompileRun(
10943 "Object.getPrototypeOf(o).x = function(x) { return x + 1; };" 10953 "Object.getPrototypeOf(o).x = function(x) { return x + 1; };"
10944 "var result = 0;" 10954 "var result = 0;"
10945 "for (var i = 0; i < 1000; i++) {" 10955 "for (var i = 0; i < 1000; i++) {"
10946 " result = o.x(42);" 10956 " result = o.x(42);"
10947 "}"); 10957 "}");
10948 CHECK_EQ(41, value->Int32Value()); 10958 CHECK_EQ(41, value->Int32Value());
10949 } 10959 }
10950 10960
10951 10961
10952 // Test the case when we stored cacheable lookup into 10962 // Test the case when we stored cacheable lookup into
10953 // a stub, but it got invalidated later on 10963 // a stub, but it got invalidated later on
10954 THREADED_TEST(InterceptorCallICInvalidatedCacheable) { 10964 THREADED_TEST(InterceptorCallICInvalidatedCacheable) {
10955 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10965 v8::HandleScope scope(CcTest::isolate());
10956 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10966 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10957 templ->SetNamedPropertyHandler(NoBlockGetterX); 10967 templ->SetNamedPropertyHandler(NoBlockGetterX);
10958 LocalContext context; 10968 LocalContext context;
10959 context->Global()->Set(v8_str("o"), templ->NewInstance()); 10969 context->Global()->Set(v8_str("o"), templ->NewInstance());
10960 v8::Handle<Value> value = CompileRun( 10970 v8::Handle<Value> value = CompileRun(
10961 "proto1 = new Object();" 10971 "proto1 = new Object();"
10962 "proto2 = new Object();" 10972 "proto2 = new Object();"
10963 "o.__proto__ = proto1;" 10973 "o.__proto__ = proto1;"
10964 "proto1.__proto__ = proto2;" 10974 "proto1.__proto__ = proto2;"
10965 "proto2.y = function(x) { return x + 1; };" 10975 "proto2.y = function(x) { return x + 1; };"
10966 // Invoke it many times to compile a stub 10976 // Invoke it many times to compile a stub
10967 "for (var i = 0; i < 7; i++) {" 10977 "for (var i = 0; i < 7; i++) {"
10968 " o.y(42);" 10978 " o.y(42);"
10969 "}" 10979 "}"
10970 "proto1.y = function(x) { return x - 1; };" 10980 "proto1.y = function(x) { return x - 1; };"
10971 "var result = 0;" 10981 "var result = 0;"
10972 "for (var i = 0; i < 7; i++) {" 10982 "for (var i = 0; i < 7; i++) {"
10973 " result += o.y(42);" 10983 " result += o.y(42);"
10974 "}"); 10984 "}");
10975 CHECK_EQ(41 * 7, value->Int32Value()); 10985 CHECK_EQ(41 * 7, value->Int32Value());
10976 } 10986 }
10977 10987
10978 10988
10979 // This test checks that if interceptor doesn't provide a function, 10989 // This test checks that if interceptor doesn't provide a function,
10980 // cached constant function is used 10990 // cached constant function is used
10981 THREADED_TEST(InterceptorCallICConstantFunctionUsed) { 10991 THREADED_TEST(InterceptorCallICConstantFunctionUsed) {
10982 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10992 v8::HandleScope scope(CcTest::isolate());
10983 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10993 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10984 templ->SetNamedPropertyHandler(NoBlockGetterX); 10994 templ->SetNamedPropertyHandler(NoBlockGetterX);
10985 LocalContext context; 10995 LocalContext context;
10986 context->Global()->Set(v8_str("o"), templ->NewInstance()); 10996 context->Global()->Set(v8_str("o"), templ->NewInstance());
10987 v8::Handle<Value> value = CompileRun( 10997 v8::Handle<Value> value = CompileRun(
10988 "function inc(x) { return x + 1; };" 10998 "function inc(x) { return x + 1; };"
10989 "inc(1);" 10999 "inc(1);"
10990 "o.x = inc;" 11000 "o.x = inc;"
10991 "var result = 0;" 11001 "var result = 0;"
10992 "for (var i = 0; i < 1000; i++) {" 11002 "for (var i = 0; i < 1000; i++) {"
(...skipping 10 matching lines...) Expand all
11003 ApiTestFuzzer::Fuzz(); 11013 ApiTestFuzzer::Fuzz();
11004 if (v8_str("x")->Equals(name)) 11014 if (v8_str("x")->Equals(name))
11005 info.GetReturnValue().Set(call_ic_function5); 11015 info.GetReturnValue().Set(call_ic_function5);
11006 } 11016 }
11007 11017
11008 11018
11009 // This test checks that if interceptor provides a function, 11019 // This test checks that if interceptor provides a function,
11010 // even if we cached constant function, interceptor's function 11020 // even if we cached constant function, interceptor's function
11011 // is invoked 11021 // is invoked
11012 THREADED_TEST(InterceptorCallICConstantFunctionNotNeeded) { 11022 THREADED_TEST(InterceptorCallICConstantFunctionNotNeeded) {
11013 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11023 v8::HandleScope scope(CcTest::isolate());
11014 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11024 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
11015 templ->SetNamedPropertyHandler(InterceptorCallICGetter5); 11025 templ->SetNamedPropertyHandler(InterceptorCallICGetter5);
11016 LocalContext context; 11026 LocalContext context;
11017 context->Global()->Set(v8_str("o"), templ->NewInstance()); 11027 context->Global()->Set(v8_str("o"), templ->NewInstance());
11018 call_ic_function5 = 11028 call_ic_function5 =
11019 v8_compile("function f(x) { return x - 1; }; f")->Run(); 11029 v8_compile("function f(x) { return x - 1; }; f")->Run();
11020 v8::Handle<Value> value = CompileRun( 11030 v8::Handle<Value> value = CompileRun(
11021 "function inc(x) { return x + 1; };" 11031 "function inc(x) { return x + 1; };"
11022 "inc(1);" 11032 "inc(1);"
11023 "o.x = inc;" 11033 "o.x = inc;"
(...skipping 12 matching lines...) Expand all
11036 ApiTestFuzzer::Fuzz(); 11046 ApiTestFuzzer::Fuzz();
11037 if (v8_str("x")->Equals(name)) 11047 if (v8_str("x")->Equals(name))
11038 info.GetReturnValue().Set(call_ic_function6); 11048 info.GetReturnValue().Set(call_ic_function6);
11039 } 11049 }
11040 11050
11041 11051
11042 // Same test as above, except the code is wrapped in a function 11052 // Same test as above, except the code is wrapped in a function
11043 // to test the optimized compiler. 11053 // to test the optimized compiler.
11044 THREADED_TEST(InterceptorCallICConstantFunctionNotNeededWrapped) { 11054 THREADED_TEST(InterceptorCallICConstantFunctionNotNeededWrapped) {
11045 i::FLAG_allow_natives_syntax = true; 11055 i::FLAG_allow_natives_syntax = true;
11046 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11056 v8::HandleScope scope(CcTest::isolate());
11047 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11057 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
11048 templ->SetNamedPropertyHandler(InterceptorCallICGetter6); 11058 templ->SetNamedPropertyHandler(InterceptorCallICGetter6);
11049 LocalContext context; 11059 LocalContext context;
11050 context->Global()->Set(v8_str("o"), templ->NewInstance()); 11060 context->Global()->Set(v8_str("o"), templ->NewInstance());
11051 call_ic_function6 = 11061 call_ic_function6 =
11052 v8_compile("function f(x) { return x - 1; }; f")->Run(); 11062 v8_compile("function f(x) { return x - 1; }; f")->Run();
11053 v8::Handle<Value> value = CompileRun( 11063 v8::Handle<Value> value = CompileRun(
11054 "function inc(x) { return x + 1; };" 11064 "function inc(x) { return x + 1; };"
11055 "inc(1);" 11065 "inc(1);"
11056 "o.x = inc;" 11066 "o.x = inc;"
11057 "function test() {" 11067 "function test() {"
11058 " var result = 0;" 11068 " var result = 0;"
11059 " for (var i = 0; i < 1000; i++) {" 11069 " for (var i = 0; i < 1000; i++) {"
11060 " result = o.x(42);" 11070 " result = o.x(42);"
11061 " }" 11071 " }"
11062 " return result;" 11072 " return result;"
11063 "};" 11073 "};"
11064 "test();" 11074 "test();"
11065 "test();" 11075 "test();"
11066 "test();" 11076 "test();"
11067 "%OptimizeFunctionOnNextCall(test);" 11077 "%OptimizeFunctionOnNextCall(test);"
11068 "test()"); 11078 "test()");
11069 CHECK_EQ(41, value->Int32Value()); 11079 CHECK_EQ(41, value->Int32Value());
11070 } 11080 }
11071 11081
11072 11082
11073 // Test the case when we stored constant function into 11083 // Test the case when we stored constant function into
11074 // a stub, but it got invalidated later on 11084 // a stub, but it got invalidated later on
11075 THREADED_TEST(InterceptorCallICInvalidatedConstantFunction) { 11085 THREADED_TEST(InterceptorCallICInvalidatedConstantFunction) {
11076 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11086 v8::HandleScope scope(CcTest::isolate());
11077 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11087 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
11078 templ->SetNamedPropertyHandler(NoBlockGetterX); 11088 templ->SetNamedPropertyHandler(NoBlockGetterX);
11079 LocalContext context; 11089 LocalContext context;
11080 context->Global()->Set(v8_str("o"), templ->NewInstance()); 11090 context->Global()->Set(v8_str("o"), templ->NewInstance());
11081 v8::Handle<Value> value = CompileRun( 11091 v8::Handle<Value> value = CompileRun(
11082 "function inc(x) { return x + 1; };" 11092 "function inc(x) { return x + 1; };"
11083 "inc(1);" 11093 "inc(1);"
11084 "proto1 = new Object();" 11094 "proto1 = new Object();"
11085 "proto2 = new Object();" 11095 "proto2 = new Object();"
11086 "o.__proto__ = proto1;" 11096 "o.__proto__ = proto1;"
11087 "proto1.__proto__ = proto2;" 11097 "proto1.__proto__ = proto2;"
11088 "proto2.y = inc;" 11098 "proto2.y = inc;"
11089 // Invoke it many times to compile a stub 11099 // Invoke it many times to compile a stub
11090 "for (var i = 0; i < 7; i++) {" 11100 "for (var i = 0; i < 7; i++) {"
11091 " o.y(42);" 11101 " o.y(42);"
11092 "}" 11102 "}"
11093 "proto1.y = function(x) { return x - 1; };" 11103 "proto1.y = function(x) { return x - 1; };"
11094 "var result = 0;" 11104 "var result = 0;"
11095 "for (var i = 0; i < 7; i++) {" 11105 "for (var i = 0; i < 7; i++) {"
11096 " result += o.y(42);" 11106 " result += o.y(42);"
11097 "}"); 11107 "}");
11098 CHECK_EQ(41 * 7, value->Int32Value()); 11108 CHECK_EQ(41 * 7, value->Int32Value());
11099 } 11109 }
11100 11110
11101 11111
11102 // Test the case when we stored constant function into 11112 // Test the case when we stored constant function into
11103 // a stub, but it got invalidated later on due to override on 11113 // a stub, but it got invalidated later on due to override on
11104 // global object which is between interceptor and constant function' holders. 11114 // global object which is between interceptor and constant function' holders.
11105 THREADED_TEST(InterceptorCallICInvalidatedConstantFunctionViaGlobal) { 11115 THREADED_TEST(InterceptorCallICInvalidatedConstantFunctionViaGlobal) {
11106 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11116 v8::HandleScope scope(CcTest::isolate());
11107 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11117 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
11108 templ->SetNamedPropertyHandler(NoBlockGetterX); 11118 templ->SetNamedPropertyHandler(NoBlockGetterX);
11109 LocalContext context; 11119 LocalContext context;
11110 context->Global()->Set(v8_str("o"), templ->NewInstance()); 11120 context->Global()->Set(v8_str("o"), templ->NewInstance());
11111 v8::Handle<Value> value = CompileRun( 11121 v8::Handle<Value> value = CompileRun(
11112 "function inc(x) { return x + 1; };" 11122 "function inc(x) { return x + 1; };"
11113 "inc(1);" 11123 "inc(1);"
11114 "o.__proto__ = this;" 11124 "o.__proto__ = this;"
11115 "this.__proto__.y = inc;" 11125 "this.__proto__.y = inc;"
11116 // Invoke it many times to compile a stub 11126 // Invoke it many times to compile a stub
11117 "for (var i = 0; i < 7; i++) {" 11127 "for (var i = 0; i < 7; i++) {"
11118 " if (o.y(42) != 43) throw 'oops: ' + o.y(42);" 11128 " if (o.y(42) != 43) throw 'oops: ' + o.y(42);"
11119 "}" 11129 "}"
11120 "this.y = function(x) { return x - 1; };" 11130 "this.y = function(x) { return x - 1; };"
11121 "var result = 0;" 11131 "var result = 0;"
11122 "for (var i = 0; i < 7; i++) {" 11132 "for (var i = 0; i < 7; i++) {"
11123 " result += o.y(42);" 11133 " result += o.y(42);"
11124 "}"); 11134 "}");
11125 CHECK_EQ(41 * 7, value->Int32Value()); 11135 CHECK_EQ(41 * 7, value->Int32Value());
11126 } 11136 }
11127 11137
11128 11138
11129 // Test the case when actual function to call sits on global object. 11139 // Test the case when actual function to call sits on global object.
11130 THREADED_TEST(InterceptorCallICCachedFromGlobal) { 11140 THREADED_TEST(InterceptorCallICCachedFromGlobal) {
11131 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11141 v8::HandleScope scope(CcTest::isolate());
11132 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 11142 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
11133 templ_o->SetNamedPropertyHandler(NoBlockGetterX); 11143 templ_o->SetNamedPropertyHandler(NoBlockGetterX);
11134 11144
11135 LocalContext context; 11145 LocalContext context;
11136 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 11146 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
11137 11147
11138 v8::Handle<Value> value = CompileRun( 11148 v8::Handle<Value> value = CompileRun(
11139 "try {" 11149 "try {"
11140 " o.__proto__ = this;" 11150 " o.__proto__ = this;"
11141 " for (var i = 0; i < 10; i++) {" 11151 " for (var i = 0; i < 10; i++) {"
(...skipping 14 matching lines...) Expand all
11156 11166
11157 static void InterceptorCallICFastApi( 11167 static void InterceptorCallICFastApi(
11158 Local<String> name, 11168 Local<String> name,
11159 const v8::PropertyCallbackInfo<v8::Value>& info) { 11169 const v8::PropertyCallbackInfo<v8::Value>& info) {
11160 ApiTestFuzzer::Fuzz(); 11170 ApiTestFuzzer::Fuzz();
11161 CheckReturnValue(info, FUNCTION_ADDR(InterceptorCallICFastApi)); 11171 CheckReturnValue(info, FUNCTION_ADDR(InterceptorCallICFastApi));
11162 int* call_count = 11172 int* call_count =
11163 reinterpret_cast<int*>(v8::External::Cast(*info.Data())->Value()); 11173 reinterpret_cast<int*>(v8::External::Cast(*info.Data())->Value());
11164 ++(*call_count); 11174 ++(*call_count);
11165 if ((*call_count) % 20 == 0) { 11175 if ((*call_count) % 20 == 0) {
11166 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 11176 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
11167 } 11177 }
11168 } 11178 }
11169 11179
11170 static void FastApiCallback_TrivialSignature( 11180 static void FastApiCallback_TrivialSignature(
11171 const v8::FunctionCallbackInfo<v8::Value>& args) { 11181 const v8::FunctionCallbackInfo<v8::Value>& args) {
11172 ApiTestFuzzer::Fuzz(); 11182 ApiTestFuzzer::Fuzz();
11173 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_TrivialSignature)); 11183 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_TrivialSignature));
11174 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 11184 v8::Isolate* isolate = CcTest::isolate();
11175 CHECK_EQ(isolate, args.GetIsolate()); 11185 CHECK_EQ(isolate, args.GetIsolate());
11176 CHECK_EQ(args.This(), args.Holder()); 11186 CHECK_EQ(args.This(), args.Holder());
11177 CHECK(args.Data()->Equals(v8_str("method_data"))); 11187 CHECK(args.Data()->Equals(v8_str("method_data")));
11178 args.GetReturnValue().Set(args[0]->Int32Value() + 1); 11188 args.GetReturnValue().Set(args[0]->Int32Value() + 1);
11179 } 11189 }
11180 11190
11181 static void FastApiCallback_SimpleSignature( 11191 static void FastApiCallback_SimpleSignature(
11182 const v8::FunctionCallbackInfo<v8::Value>& args) { 11192 const v8::FunctionCallbackInfo<v8::Value>& args) {
11183 ApiTestFuzzer::Fuzz(); 11193 ApiTestFuzzer::Fuzz();
11184 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_SimpleSignature)); 11194 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_SimpleSignature));
11185 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 11195 v8::Isolate* isolate = CcTest::isolate();
11186 CHECK_EQ(isolate, args.GetIsolate()); 11196 CHECK_EQ(isolate, args.GetIsolate());
11187 CHECK_EQ(args.This()->GetPrototype(), args.Holder()); 11197 CHECK_EQ(args.This()->GetPrototype(), args.Holder());
11188 CHECK(args.Data()->Equals(v8_str("method_data"))); 11198 CHECK(args.Data()->Equals(v8_str("method_data")));
11189 // Note, we're using HasRealNamedProperty instead of Has to avoid 11199 // Note, we're using HasRealNamedProperty instead of Has to avoid
11190 // invoking the interceptor again. 11200 // invoking the interceptor again.
11191 CHECK(args.Holder()->HasRealNamedProperty(v8_str("foo"))); 11201 CHECK(args.Holder()->HasRealNamedProperty(v8_str("foo")));
11192 args.GetReturnValue().Set(args[0]->Int32Value() + 1); 11202 args.GetReturnValue().Set(args[0]->Int32Value() + 1);
11193 } 11203 }
11194 11204
11195 11205
11196 // Helper to maximize the odds of object moving. 11206 // Helper to maximize the odds of object moving.
11197 static void GenerateSomeGarbage() { 11207 static void GenerateSomeGarbage() {
11198 CompileRun( 11208 CompileRun(
11199 "var garbage;" 11209 "var garbage;"
11200 "for (var i = 0; i < 1000; i++) {" 11210 "for (var i = 0; i < 1000; i++) {"
11201 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];" 11211 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];"
11202 "}" 11212 "}"
11203 "garbage = undefined;"); 11213 "garbage = undefined;");
11204 } 11214 }
11205 11215
11206 11216
11207 void DirectApiCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { 11217 void DirectApiCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
11208 static int count = 0; 11218 static int count = 0;
11209 if (count++ % 3 == 0) { 11219 if (count++ % 3 == 0) {
11210 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 11220 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
11211 // This should move the stub 11221 // This should move the stub
11212 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed 11222 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed
11213 } 11223 }
11214 } 11224 }
11215 11225
11216 11226
11217 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { 11227 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) {
11218 LocalContext context; 11228 LocalContext context;
11219 v8::HandleScope scope(context->GetIsolate()); 11229 v8::HandleScope scope(context->GetIsolate());
11220 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); 11230 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
11255 " try { nativeobject.callback(); } catch (e) { result += e; }" 11265 " try { nativeobject.callback(); } catch (e) { result += e; }"
11256 " }" 11266 " }"
11257 "}" 11267 "}"
11258 "f(); result;"); 11268 "f(); result;");
11259 CHECK_EQ(v8_str("ggggg"), result); 11269 CHECK_EQ(v8_str("ggggg"), result);
11260 } 11270 }
11261 11271
11262 11272
11263 static Handle<Value> DoDirectGetter() { 11273 static Handle<Value> DoDirectGetter() {
11264 if (++p_getter_count % 3 == 0) { 11274 if (++p_getter_count % 3 == 0) {
11265 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 11275 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
11266 GenerateSomeGarbage(); 11276 GenerateSomeGarbage();
11267 } 11277 }
11268 return v8_str("Direct Getter Result"); 11278 return v8_str("Direct Getter Result");
11269 } 11279 }
11270 11280
11271 static void DirectGetterCallback( 11281 static void DirectGetterCallback(
11272 Local<String> name, 11282 Local<String> name,
11273 const v8::PropertyCallbackInfo<v8::Value>& info) { 11283 const v8::PropertyCallbackInfo<v8::Value>& info) {
11274 CheckReturnValue(info, FUNCTION_ADDR(DirectGetterCallback)); 11284 CheckReturnValue(info, FUNCTION_ADDR(DirectGetterCallback));
11275 info.GetReturnValue().Set(DoDirectGetter()); 11285 info.GetReturnValue().Set(DoDirectGetter());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
11318 "for (var i = 0; i < 5; i++) {" 11328 "for (var i = 0; i < 5; i++) {"
11319 " try { o1.p1; } catch (e) { result += e; }" 11329 " try { o1.p1; } catch (e) { result += e; }"
11320 "}" 11330 "}"
11321 "result;"); 11331 "result;");
11322 CHECK_EQ(v8_str("ggggg"), result); 11332 CHECK_EQ(v8_str("ggggg"), result);
11323 } 11333 }
11324 11334
11325 11335
11326 THREADED_PROFILED_TEST(InterceptorCallICFastApi_TrivialSignature) { 11336 THREADED_PROFILED_TEST(InterceptorCallICFastApi_TrivialSignature) {
11327 int interceptor_call_count = 0; 11337 int interceptor_call_count = 0;
11328 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11338 v8::HandleScope scope(CcTest::isolate());
11329 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11339 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11330 v8::Handle<v8::FunctionTemplate> method_templ = 11340 v8::Handle<v8::FunctionTemplate> method_templ =
11331 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, 11341 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature,
11332 v8_str("method_data"), 11342 v8_str("method_data"),
11333 v8::Handle<v8::Signature>()); 11343 v8::Handle<v8::Signature>());
11334 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11344 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11335 proto_templ->Set(v8_str("method"), method_templ); 11345 proto_templ->Set(v8_str("method"), method_templ);
11336 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 11346 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
11337 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, 11347 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
11338 NULL, NULL, NULL, NULL, 11348 NULL, NULL, NULL, NULL,
11339 v8::External::New(&interceptor_call_count)); 11349 v8::External::New(&interceptor_call_count));
11340 LocalContext context; 11350 LocalContext context;
11341 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 11351 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
11342 GenerateSomeGarbage(); 11352 GenerateSomeGarbage();
11343 context->Global()->Set(v8_str("o"), fun->NewInstance()); 11353 context->Global()->Set(v8_str("o"), fun->NewInstance());
11344 CompileRun( 11354 CompileRun(
11345 "var result = 0;" 11355 "var result = 0;"
11346 "for (var i = 0; i < 100; i++) {" 11356 "for (var i = 0; i < 100; i++) {"
11347 " result = o.method(41);" 11357 " result = o.method(41);"
11348 "}"); 11358 "}");
11349 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 11359 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
11350 CHECK_EQ(100, interceptor_call_count); 11360 CHECK_EQ(100, interceptor_call_count);
11351 } 11361 }
11352 11362
11353 11363
11354 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature) { 11364 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature) {
11355 int interceptor_call_count = 0; 11365 int interceptor_call_count = 0;
11356 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11366 v8::HandleScope scope(CcTest::isolate());
11357 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11367 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11358 v8::Handle<v8::FunctionTemplate> method_templ = 11368 v8::Handle<v8::FunctionTemplate> method_templ =
11359 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 11369 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
11360 v8_str("method_data"), 11370 v8_str("method_data"),
11361 v8::Signature::New(fun_templ)); 11371 v8::Signature::New(fun_templ));
11362 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11372 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11363 proto_templ->Set(v8_str("method"), method_templ); 11373 proto_templ->Set(v8_str("method"), method_templ);
11364 fun_templ->SetHiddenPrototype(true); 11374 fun_templ->SetHiddenPrototype(true);
11365 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 11375 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
11366 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, 11376 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
(...skipping 11 matching lines...) Expand all
11378 "for (var i = 0; i < 100; i++) {" 11388 "for (var i = 0; i < 100; i++) {"
11379 " result = receiver.method(41);" 11389 " result = receiver.method(41);"
11380 "}"); 11390 "}");
11381 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 11391 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
11382 CHECK_EQ(100, interceptor_call_count); 11392 CHECK_EQ(100, interceptor_call_count);
11383 } 11393 }
11384 11394
11385 11395
11386 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) { 11396 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) {
11387 int interceptor_call_count = 0; 11397 int interceptor_call_count = 0;
11388 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11398 v8::HandleScope scope(CcTest::isolate());
11389 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11399 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11390 v8::Handle<v8::FunctionTemplate> method_templ = 11400 v8::Handle<v8::FunctionTemplate> method_templ =
11391 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 11401 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
11392 v8_str("method_data"), 11402 v8_str("method_data"),
11393 v8::Signature::New(fun_templ)); 11403 v8::Signature::New(fun_templ));
11394 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11404 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11395 proto_templ->Set(v8_str("method"), method_templ); 11405 proto_templ->Set(v8_str("method"), method_templ);
11396 fun_templ->SetHiddenPrototype(true); 11406 fun_templ->SetHiddenPrototype(true);
11397 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 11407 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
11398 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, 11408 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
(...skipping 17 matching lines...) Expand all
11416 " }" 11426 " }"
11417 "}"); 11427 "}");
11418 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 11428 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
11419 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 11429 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11420 CHECK_GE(interceptor_call_count, 50); 11430 CHECK_GE(interceptor_call_count, 50);
11421 } 11431 }
11422 11432
11423 11433
11424 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) { 11434 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) {
11425 int interceptor_call_count = 0; 11435 int interceptor_call_count = 0;
11426 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11436 v8::HandleScope scope(CcTest::isolate());
11427 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11437 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11428 v8::Handle<v8::FunctionTemplate> method_templ = 11438 v8::Handle<v8::FunctionTemplate> method_templ =
11429 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 11439 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
11430 v8_str("method_data"), 11440 v8_str("method_data"),
11431 v8::Signature::New(fun_templ)); 11441 v8::Signature::New(fun_templ));
11432 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11442 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11433 proto_templ->Set(v8_str("method"), method_templ); 11443 proto_templ->Set(v8_str("method"), method_templ);
11434 fun_templ->SetHiddenPrototype(true); 11444 fun_templ->SetHiddenPrototype(true);
11435 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 11445 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
11436 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, 11446 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
(...skipping 17 matching lines...) Expand all
11454 " }" 11464 " }"
11455 "}"); 11465 "}");
11456 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 11466 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
11457 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 11467 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11458 CHECK_GE(interceptor_call_count, 50); 11468 CHECK_GE(interceptor_call_count, 50);
11459 } 11469 }
11460 11470
11461 11471
11462 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) { 11472 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) {
11463 int interceptor_call_count = 0; 11473 int interceptor_call_count = 0;
11464 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11474 v8::HandleScope scope(CcTest::isolate());
11465 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11475 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11466 v8::Handle<v8::FunctionTemplate> method_templ = 11476 v8::Handle<v8::FunctionTemplate> method_templ =
11467 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 11477 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
11468 v8_str("method_data"), 11478 v8_str("method_data"),
11469 v8::Signature::New(fun_templ)); 11479 v8::Signature::New(fun_templ));
11470 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11480 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11471 proto_templ->Set(v8_str("method"), method_templ); 11481 proto_templ->Set(v8_str("method"), method_templ);
11472 fun_templ->SetHiddenPrototype(true); 11482 fun_templ->SetHiddenPrototype(true);
11473 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 11483 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
11474 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, 11484 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
(...skipping 20 matching lines...) Expand all
11495 CHECK(try_catch.HasCaught()); 11505 CHECK(try_catch.HasCaught());
11496 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), 11506 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"),
11497 try_catch.Exception()->ToString()); 11507 try_catch.Exception()->ToString());
11498 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 11508 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11499 CHECK_GE(interceptor_call_count, 50); 11509 CHECK_GE(interceptor_call_count, 50);
11500 } 11510 }
11501 11511
11502 11512
11503 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) { 11513 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) {
11504 int interceptor_call_count = 0; 11514 int interceptor_call_count = 0;
11505 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11515 v8::HandleScope scope(CcTest::isolate());
11506 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11516 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11507 v8::Handle<v8::FunctionTemplate> method_templ = 11517 v8::Handle<v8::FunctionTemplate> method_templ =
11508 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 11518 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
11509 v8_str("method_data"), 11519 v8_str("method_data"),
11510 v8::Signature::New(fun_templ)); 11520 v8::Signature::New(fun_templ));
11511 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11521 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11512 proto_templ->Set(v8_str("method"), method_templ); 11522 proto_templ->Set(v8_str("method"), method_templ);
11513 fun_templ->SetHiddenPrototype(true); 11523 fun_templ->SetHiddenPrototype(true);
11514 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 11524 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
11515 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, 11525 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
(...skipping 19 matching lines...) Expand all
11535 "}"); 11545 "}");
11536 CHECK(try_catch.HasCaught()); 11546 CHECK(try_catch.HasCaught());
11537 CHECK_EQ(v8_str("TypeError: Illegal invocation"), 11547 CHECK_EQ(v8_str("TypeError: Illegal invocation"),
11538 try_catch.Exception()->ToString()); 11548 try_catch.Exception()->ToString());
11539 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 11549 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11540 CHECK_GE(interceptor_call_count, 50); 11550 CHECK_GE(interceptor_call_count, 50);
11541 } 11551 }
11542 11552
11543 11553
11544 THREADED_PROFILED_TEST(CallICFastApi_TrivialSignature) { 11554 THREADED_PROFILED_TEST(CallICFastApi_TrivialSignature) {
11545 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11555 v8::HandleScope scope(CcTest::isolate());
11546 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11556 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11547 v8::Handle<v8::FunctionTemplate> method_templ = 11557 v8::Handle<v8::FunctionTemplate> method_templ =
11548 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, 11558 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature,
11549 v8_str("method_data"), 11559 v8_str("method_data"),
11550 v8::Handle<v8::Signature>()); 11560 v8::Handle<v8::Signature>());
11551 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11561 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11552 proto_templ->Set(v8_str("method"), method_templ); 11562 proto_templ->Set(v8_str("method"), method_templ);
11553 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 11563 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
11554 USE(templ); 11564 USE(templ);
11555 LocalContext context; 11565 LocalContext context;
11556 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 11566 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
11557 GenerateSomeGarbage(); 11567 GenerateSomeGarbage();
11558 context->Global()->Set(v8_str("o"), fun->NewInstance()); 11568 context->Global()->Set(v8_str("o"), fun->NewInstance());
11559 CompileRun( 11569 CompileRun(
11560 "var result = 0;" 11570 "var result = 0;"
11561 "for (var i = 0; i < 100; i++) {" 11571 "for (var i = 0; i < 100; i++) {"
11562 " result = o.method(41);" 11572 " result = o.method(41);"
11563 "}"); 11573 "}");
11564 11574
11565 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 11575 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
11566 } 11576 }
11567 11577
11568 11578
11569 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature) { 11579 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature) {
11570 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11580 v8::HandleScope scope(CcTest::isolate());
11571 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11581 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11572 v8::Handle<v8::FunctionTemplate> method_templ = 11582 v8::Handle<v8::FunctionTemplate> method_templ =
11573 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 11583 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
11574 v8_str("method_data"), 11584 v8_str("method_data"),
11575 v8::Signature::New(fun_templ)); 11585 v8::Signature::New(fun_templ));
11576 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11586 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11577 proto_templ->Set(v8_str("method"), method_templ); 11587 proto_templ->Set(v8_str("method"), method_templ);
11578 fun_templ->SetHiddenPrototype(true); 11588 fun_templ->SetHiddenPrototype(true);
11579 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 11589 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
11580 CHECK(!templ.IsEmpty()); 11590 CHECK(!templ.IsEmpty());
11581 LocalContext context; 11591 LocalContext context;
11582 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 11592 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
11583 GenerateSomeGarbage(); 11593 GenerateSomeGarbage();
11584 context->Global()->Set(v8_str("o"), fun->NewInstance()); 11594 context->Global()->Set(v8_str("o"), fun->NewInstance());
11585 CompileRun( 11595 CompileRun(
11586 "o.foo = 17;" 11596 "o.foo = 17;"
11587 "var receiver = {};" 11597 "var receiver = {};"
11588 "receiver.__proto__ = o;" 11598 "receiver.__proto__ = o;"
11589 "var result = 0;" 11599 "var result = 0;"
11590 "for (var i = 0; i < 100; i++) {" 11600 "for (var i = 0; i < 100; i++) {"
11591 " result = receiver.method(41);" 11601 " result = receiver.method(41);"
11592 "}"); 11602 "}");
11593 11603
11594 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 11604 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
11595 } 11605 }
11596 11606
11597 11607
11598 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss1) { 11608 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss1) {
11599 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11609 v8::HandleScope scope(CcTest::isolate());
11600 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11610 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11601 v8::Handle<v8::FunctionTemplate> method_templ = 11611 v8::Handle<v8::FunctionTemplate> method_templ =
11602 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 11612 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
11603 v8_str("method_data"), 11613 v8_str("method_data"),
11604 v8::Signature::New(fun_templ)); 11614 v8::Signature::New(fun_templ));
11605 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11615 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11606 proto_templ->Set(v8_str("method"), method_templ); 11616 proto_templ->Set(v8_str("method"), method_templ);
11607 fun_templ->SetHiddenPrototype(true); 11617 fun_templ->SetHiddenPrototype(true);
11608 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 11618 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
11609 CHECK(!templ.IsEmpty()); 11619 CHECK(!templ.IsEmpty());
(...skipping 13 matching lines...) Expand all
11623 " saved_result = result;" 11633 " saved_result = result;"
11624 " receiver = {method: function(x) { return x - 1 }};" 11634 " receiver = {method: function(x) { return x - 1 }};"
11625 " }" 11635 " }"
11626 "}"); 11636 "}");
11627 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 11637 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
11628 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 11638 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11629 } 11639 }
11630 11640
11631 11641
11632 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss2) { 11642 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss2) {
11633 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11643 v8::HandleScope scope(CcTest::isolate());
11634 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11644 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11635 v8::Handle<v8::FunctionTemplate> method_templ = 11645 v8::Handle<v8::FunctionTemplate> method_templ =
11636 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 11646 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
11637 v8_str("method_data"), 11647 v8_str("method_data"),
11638 v8::Signature::New(fun_templ)); 11648 v8::Signature::New(fun_templ));
11639 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11649 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11640 proto_templ->Set(v8_str("method"), method_templ); 11650 proto_templ->Set(v8_str("method"), method_templ);
11641 fun_templ->SetHiddenPrototype(true); 11651 fun_templ->SetHiddenPrototype(true);
11642 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 11652 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
11643 CHECK(!templ.IsEmpty()); 11653 CHECK(!templ.IsEmpty());
(...skipping 16 matching lines...) Expand all
11660 " }" 11670 " }"
11661 "}"); 11671 "}");
11662 CHECK(try_catch.HasCaught()); 11672 CHECK(try_catch.HasCaught());
11663 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), 11673 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"),
11664 try_catch.Exception()->ToString()); 11674 try_catch.Exception()->ToString());
11665 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 11675 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11666 } 11676 }
11667 11677
11668 11678
11669 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_TypeError) { 11679 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_TypeError) {
11670 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11680 v8::HandleScope scope(CcTest::isolate());
11671 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11681 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11672 v8::Handle<v8::FunctionTemplate> method_templ = 11682 v8::Handle<v8::FunctionTemplate> method_templ =
11673 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 11683 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
11674 v8_str("method_data"), 11684 v8_str("method_data"),
11675 v8::Signature::New(fun_templ)); 11685 v8::Signature::New(fun_templ));
11676 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11686 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11677 proto_templ->Set(v8_str("method"), method_templ); 11687 proto_templ->Set(v8_str("method"), method_templ);
11678 fun_templ->SetHiddenPrototype(true); 11688 fun_templ->SetHiddenPrototype(true);
11679 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 11689 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
11680 CHECK(!templ.IsEmpty()); 11690 CHECK(!templ.IsEmpty());
(...skipping 30 matching lines...) Expand all
11711 ApiTestFuzzer::Fuzz(); 11721 ApiTestFuzzer::Fuzz();
11712 if (v8_str("x")->Equals(name)) { 11722 if (v8_str("x")->Equals(name)) {
11713 info.GetReturnValue().Set(keyed_call_ic_function); 11723 info.GetReturnValue().Set(keyed_call_ic_function);
11714 } 11724 }
11715 } 11725 }
11716 11726
11717 11727
11718 // Test the case when we stored cacheable lookup into 11728 // Test the case when we stored cacheable lookup into
11719 // a stub, but the function name changed (to another cacheable function). 11729 // a stub, but the function name changed (to another cacheable function).
11720 THREADED_TEST(InterceptorKeyedCallICKeyChange1) { 11730 THREADED_TEST(InterceptorKeyedCallICKeyChange1) {
11721 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11731 v8::HandleScope scope(CcTest::isolate());
11722 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11732 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
11723 templ->SetNamedPropertyHandler(NoBlockGetterX); 11733 templ->SetNamedPropertyHandler(NoBlockGetterX);
11724 LocalContext context; 11734 LocalContext context;
11725 context->Global()->Set(v8_str("o"), templ->NewInstance()); 11735 context->Global()->Set(v8_str("o"), templ->NewInstance());
11726 CompileRun( 11736 CompileRun(
11727 "proto = new Object();" 11737 "proto = new Object();"
11728 "proto.y = function(x) { return x + 1; };" 11738 "proto.y = function(x) { return x + 1; };"
11729 "proto.z = function(x) { return x - 1; };" 11739 "proto.z = function(x) { return x - 1; };"
11730 "o.__proto__ = proto;" 11740 "o.__proto__ = proto;"
11731 "var result = 0;" 11741 "var result = 0;"
11732 "var method = 'y';" 11742 "var method = 'y';"
11733 "for (var i = 0; i < 10; i++) {" 11743 "for (var i = 0; i < 10; i++) {"
11734 " if (i == 5) { method = 'z'; };" 11744 " if (i == 5) { method = 'z'; };"
11735 " result += o[method](41);" 11745 " result += o[method](41);"
11736 "}"); 11746 "}");
11737 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); 11747 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value());
11738 } 11748 }
11739 11749
11740 11750
11741 // Test the case when we stored cacheable lookup into 11751 // Test the case when we stored cacheable lookup into
11742 // a stub, but the function name changed (and the new function is present 11752 // a stub, but the function name changed (and the new function is present
11743 // both before and after the interceptor in the prototype chain). 11753 // both before and after the interceptor in the prototype chain).
11744 THREADED_TEST(InterceptorKeyedCallICKeyChange2) { 11754 THREADED_TEST(InterceptorKeyedCallICKeyChange2) {
11745 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11755 v8::HandleScope scope(CcTest::isolate());
11746 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11756 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
11747 templ->SetNamedPropertyHandler(InterceptorKeyedCallICGetter); 11757 templ->SetNamedPropertyHandler(InterceptorKeyedCallICGetter);
11748 LocalContext context; 11758 LocalContext context;
11749 context->Global()->Set(v8_str("proto1"), templ->NewInstance()); 11759 context->Global()->Set(v8_str("proto1"), templ->NewInstance());
11750 keyed_call_ic_function = 11760 keyed_call_ic_function =
11751 v8_compile("function f(x) { return x - 1; }; f")->Run(); 11761 v8_compile("function f(x) { return x - 1; }; f")->Run();
11752 CompileRun( 11762 CompileRun(
11753 "o = new Object();" 11763 "o = new Object();"
11754 "proto2 = new Object();" 11764 "proto2 = new Object();"
11755 "o.y = function(x) { return x + 1; };" 11765 "o.y = function(x) { return x + 1; };"
11756 "proto2.y = function(x) { return x + 2; };" 11766 "proto2.y = function(x) { return x + 2; };"
11757 "o.__proto__ = proto1;" 11767 "o.__proto__ = proto1;"
11758 "proto1.__proto__ = proto2;" 11768 "proto1.__proto__ = proto2;"
11759 "var result = 0;" 11769 "var result = 0;"
11760 "var method = 'x';" 11770 "var method = 'x';"
11761 "for (var i = 0; i < 10; i++) {" 11771 "for (var i = 0; i < 10; i++) {"
11762 " if (i == 5) { method = 'y'; };" 11772 " if (i == 5) { method = 'y'; };"
11763 " result += o[method](41);" 11773 " result += o[method](41);"
11764 "}"); 11774 "}");
11765 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); 11775 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value());
11766 } 11776 }
11767 11777
11768 11778
11769 // Same as InterceptorKeyedCallICKeyChange1 only the cacheable function sit 11779 // Same as InterceptorKeyedCallICKeyChange1 only the cacheable function sit
11770 // on the global object. 11780 // on the global object.
11771 THREADED_TEST(InterceptorKeyedCallICKeyChangeOnGlobal) { 11781 THREADED_TEST(InterceptorKeyedCallICKeyChangeOnGlobal) {
11772 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11782 v8::HandleScope scope(CcTest::isolate());
11773 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11783 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
11774 templ->SetNamedPropertyHandler(NoBlockGetterX); 11784 templ->SetNamedPropertyHandler(NoBlockGetterX);
11775 LocalContext context; 11785 LocalContext context;
11776 context->Global()->Set(v8_str("o"), templ->NewInstance()); 11786 context->Global()->Set(v8_str("o"), templ->NewInstance());
11777 CompileRun( 11787 CompileRun(
11778 "function inc(x) { return x + 1; };" 11788 "function inc(x) { return x + 1; };"
11779 "inc(1);" 11789 "inc(1);"
11780 "function dec(x) { return x - 1; };" 11790 "function dec(x) { return x - 1; };"
11781 "dec(1);" 11791 "dec(1);"
11782 "o.__proto__ = this;" 11792 "o.__proto__ = this;"
11783 "this.__proto__.x = inc;" 11793 "this.__proto__.x = inc;"
11784 "this.__proto__.y = dec;" 11794 "this.__proto__.y = dec;"
11785 "var result = 0;" 11795 "var result = 0;"
11786 "var method = 'x';" 11796 "var method = 'x';"
11787 "for (var i = 0; i < 10; i++) {" 11797 "for (var i = 0; i < 10; i++) {"
11788 " if (i == 5) { method = 'y'; };" 11798 " if (i == 5) { method = 'y'; };"
11789 " result += o[method](41);" 11799 " result += o[method](41);"
11790 "}"); 11800 "}");
11791 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); 11801 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value());
11792 } 11802 }
11793 11803
11794 11804
11795 // Test the case when actual function to call sits on global object. 11805 // Test the case when actual function to call sits on global object.
11796 THREADED_TEST(InterceptorKeyedCallICFromGlobal) { 11806 THREADED_TEST(InterceptorKeyedCallICFromGlobal) {
11797 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11807 v8::HandleScope scope(CcTest::isolate());
11798 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 11808 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
11799 templ_o->SetNamedPropertyHandler(NoBlockGetterX); 11809 templ_o->SetNamedPropertyHandler(NoBlockGetterX);
11800 LocalContext context; 11810 LocalContext context;
11801 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 11811 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
11802 11812
11803 CompileRun( 11813 CompileRun(
11804 "function len(x) { return x.length; };" 11814 "function len(x) { return x.length; };"
11805 "o.__proto__ = this;" 11815 "o.__proto__ = this;"
11806 "var m = 'parseFloat';" 11816 "var m = 'parseFloat';"
11807 "var result = 0;" 11817 "var result = 0;"
11808 "for (var i = 0; i < 10; i++) {" 11818 "for (var i = 0; i < 10; i++) {"
11809 " if (i == 5) {" 11819 " if (i == 5) {"
11810 " m = 'len';" 11820 " m = 'len';"
11811 " saved_result = result;" 11821 " saved_result = result;"
11812 " };" 11822 " };"
11813 " result = o[m]('239');" 11823 " result = o[m]('239');"
11814 "}"); 11824 "}");
11815 CHECK_EQ(3, context->Global()->Get(v8_str("result"))->Int32Value()); 11825 CHECK_EQ(3, context->Global()->Get(v8_str("result"))->Int32Value());
11816 CHECK_EQ(239, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 11826 CHECK_EQ(239, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11817 } 11827 }
11818 11828
11819 11829
11820 // Test the map transition before the interceptor. 11830 // Test the map transition before the interceptor.
11821 THREADED_TEST(InterceptorKeyedCallICMapChangeBefore) { 11831 THREADED_TEST(InterceptorKeyedCallICMapChangeBefore) {
11822 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11832 v8::HandleScope scope(CcTest::isolate());
11823 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 11833 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
11824 templ_o->SetNamedPropertyHandler(NoBlockGetterX); 11834 templ_o->SetNamedPropertyHandler(NoBlockGetterX);
11825 LocalContext context; 11835 LocalContext context;
11826 context->Global()->Set(v8_str("proto"), templ_o->NewInstance()); 11836 context->Global()->Set(v8_str("proto"), templ_o->NewInstance());
11827 11837
11828 CompileRun( 11838 CompileRun(
11829 "var o = new Object();" 11839 "var o = new Object();"
11830 "o.__proto__ = proto;" 11840 "o.__proto__ = proto;"
11831 "o.method = function(x) { return x + 1; };" 11841 "o.method = function(x) { return x + 1; };"
11832 "var m = 'method';" 11842 "var m = 'method';"
11833 "var result = 0;" 11843 "var result = 0;"
11834 "for (var i = 0; i < 10; i++) {" 11844 "for (var i = 0; i < 10; i++) {"
11835 " if (i == 5) { o.method = function(x) { return x - 1; }; };" 11845 " if (i == 5) { o.method = function(x) { return x - 1; }; };"
11836 " result += o[m](41);" 11846 " result += o[m](41);"
11837 "}"); 11847 "}");
11838 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); 11848 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value());
11839 } 11849 }
11840 11850
11841 11851
11842 // Test the map transition after the interceptor. 11852 // Test the map transition after the interceptor.
11843 THREADED_TEST(InterceptorKeyedCallICMapChangeAfter) { 11853 THREADED_TEST(InterceptorKeyedCallICMapChangeAfter) {
11844 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11854 v8::HandleScope scope(CcTest::isolate());
11845 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 11855 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
11846 templ_o->SetNamedPropertyHandler(NoBlockGetterX); 11856 templ_o->SetNamedPropertyHandler(NoBlockGetterX);
11847 LocalContext context; 11857 LocalContext context;
11848 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 11858 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
11849 11859
11850 CompileRun( 11860 CompileRun(
11851 "var proto = new Object();" 11861 "var proto = new Object();"
11852 "o.__proto__ = proto;" 11862 "o.__proto__ = proto;"
11853 "proto.method = function(x) { return x + 1; };" 11863 "proto.method = function(x) { return x + 1; };"
11854 "var m = 'method';" 11864 "var m = 'method';"
(...skipping 15 matching lines...) Expand all
11870 if (v8_str("x")->Equals(name) && interceptor_call_count++ < 20) { 11880 if (v8_str("x")->Equals(name) && interceptor_call_count++ < 20) {
11871 info.GetReturnValue().Set(call_ic_function2); 11881 info.GetReturnValue().Set(call_ic_function2);
11872 } 11882 }
11873 } 11883 }
11874 11884
11875 11885
11876 // This test should hit load and call ICs for the interceptor case. 11886 // This test should hit load and call ICs for the interceptor case.
11877 // Once in a while, the interceptor will reply that a property was not 11887 // Once in a while, the interceptor will reply that a property was not
11878 // found in which case we should get a reference error. 11888 // found in which case we should get a reference error.
11879 THREADED_TEST(InterceptorICReferenceErrors) { 11889 THREADED_TEST(InterceptorICReferenceErrors) {
11880 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11890 v8::HandleScope scope(CcTest::isolate());
11881 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11891 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
11882 templ->SetNamedPropertyHandler(InterceptorICRefErrorGetter); 11892 templ->SetNamedPropertyHandler(InterceptorICRefErrorGetter);
11883 LocalContext context(0, templ, v8::Handle<Value>()); 11893 LocalContext context(0, templ, v8::Handle<Value>());
11884 call_ic_function2 = v8_compile("function h(x) { return x; }; h")->Run(); 11894 call_ic_function2 = v8_compile("function h(x) { return x; }; h")->Run();
11885 v8::Handle<Value> value = CompileRun( 11895 v8::Handle<Value> value = CompileRun(
11886 "function f() {" 11896 "function f() {"
11887 " for (var i = 0; i < 1000; i++) {" 11897 " for (var i = 0; i < 1000; i++) {"
11888 " try { x; } catch(e) { return true; }" 11898 " try { x; } catch(e) { return true; }"
11889 " }" 11899 " }"
11890 " return false;" 11900 " return false;"
(...skipping 26 matching lines...) Expand all
11917 v8::ThrowException(v8_num(42)); 11927 v8::ThrowException(v8_num(42));
11918 return; 11928 return;
11919 } 11929 }
11920 } 11930 }
11921 11931
11922 11932
11923 // Test interceptor load/call IC where the interceptor throws an 11933 // Test interceptor load/call IC where the interceptor throws an
11924 // exception once in a while. 11934 // exception once in a while.
11925 THREADED_TEST(InterceptorICGetterExceptions) { 11935 THREADED_TEST(InterceptorICGetterExceptions) {
11926 interceptor_ic_exception_get_count = 0; 11936 interceptor_ic_exception_get_count = 0;
11927 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11937 v8::HandleScope scope(CcTest::isolate());
11928 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11938 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
11929 templ->SetNamedPropertyHandler(InterceptorICExceptionGetter); 11939 templ->SetNamedPropertyHandler(InterceptorICExceptionGetter);
11930 LocalContext context(0, templ, v8::Handle<Value>()); 11940 LocalContext context(0, templ, v8::Handle<Value>());
11931 call_ic_function3 = v8_compile("function h(x) { return x; }; h")->Run(); 11941 call_ic_function3 = v8_compile("function h(x) { return x; }; h")->Run();
11932 v8::Handle<Value> value = CompileRun( 11942 v8::Handle<Value> value = CompileRun(
11933 "function f() {" 11943 "function f() {"
11934 " for (var i = 0; i < 100; i++) {" 11944 " for (var i = 0; i < 100; i++) {"
11935 " try { x; } catch(e) { return true; }" 11945 " try { x; } catch(e) { return true; }"
11936 " }" 11946 " }"
11937 " return false;" 11947 " return false;"
(...skipping 23 matching lines...) Expand all
11961 if (++interceptor_ic_exception_set_count > 20) { 11971 if (++interceptor_ic_exception_set_count > 20) {
11962 v8::ThrowException(v8_num(42)); 11972 v8::ThrowException(v8_num(42));
11963 } 11973 }
11964 } 11974 }
11965 11975
11966 11976
11967 // Test interceptor store IC where the interceptor throws an exception 11977 // Test interceptor store IC where the interceptor throws an exception
11968 // once in a while. 11978 // once in a while.
11969 THREADED_TEST(InterceptorICSetterExceptions) { 11979 THREADED_TEST(InterceptorICSetterExceptions) {
11970 interceptor_ic_exception_set_count = 0; 11980 interceptor_ic_exception_set_count = 0;
11971 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11981 v8::HandleScope scope(CcTest::isolate());
11972 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11982 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
11973 templ->SetNamedPropertyHandler(0, InterceptorICExceptionSetter); 11983 templ->SetNamedPropertyHandler(0, InterceptorICExceptionSetter);
11974 LocalContext context(0, templ, v8::Handle<Value>()); 11984 LocalContext context(0, templ, v8::Handle<Value>());
11975 v8::Handle<Value> value = CompileRun( 11985 v8::Handle<Value> value = CompileRun(
11976 "function f() {" 11986 "function f() {"
11977 " for (var i = 0; i < 100; i++) {" 11987 " for (var i = 0; i < 100; i++) {"
11978 " try { x = 42; } catch(e) { return true; }" 11988 " try { x = 42; } catch(e) { return true; }"
11979 " }" 11989 " }"
11980 " return false;" 11990 " return false;"
11981 "};" 11991 "};"
11982 "f();"); 11992 "f();");
11983 CHECK_EQ(true, value->BooleanValue()); 11993 CHECK_EQ(true, value->BooleanValue());
11984 } 11994 }
11985 11995
11986 11996
11987 // Test that we ignore null interceptors. 11997 // Test that we ignore null interceptors.
11988 THREADED_TEST(NullNamedInterceptor) { 11998 THREADED_TEST(NullNamedInterceptor) {
11989 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11999 v8::HandleScope scope(CcTest::isolate());
11990 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 12000 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
11991 templ->SetNamedPropertyHandler( 12001 templ->SetNamedPropertyHandler(
11992 static_cast<v8::NamedPropertyGetterCallback>(0)); 12002 static_cast<v8::NamedPropertyGetterCallback>(0));
11993 LocalContext context; 12003 LocalContext context;
11994 templ->Set("x", v8_num(42)); 12004 templ->Set("x", v8_num(42));
11995 v8::Handle<v8::Object> obj = templ->NewInstance(); 12005 v8::Handle<v8::Object> obj = templ->NewInstance();
11996 context->Global()->Set(v8_str("obj"), obj); 12006 context->Global()->Set(v8_str("obj"), obj);
11997 v8::Handle<Value> value = CompileRun("obj.x"); 12007 v8::Handle<Value> value = CompileRun("obj.x");
11998 CHECK(value->IsInt32()); 12008 CHECK(value->IsInt32());
11999 CHECK_EQ(42, value->Int32Value()); 12009 CHECK_EQ(42, value->Int32Value());
12000 } 12010 }
12001 12011
12002 12012
12003 // Test that we ignore null interceptors. 12013 // Test that we ignore null interceptors.
12004 THREADED_TEST(NullIndexedInterceptor) { 12014 THREADED_TEST(NullIndexedInterceptor) {
12005 v8::HandleScope scope(v8::Isolate::GetCurrent()); 12015 v8::HandleScope scope(CcTest::isolate());
12006 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 12016 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
12007 templ->SetIndexedPropertyHandler( 12017 templ->SetIndexedPropertyHandler(
12008 static_cast<v8::IndexedPropertyGetterCallback>(0)); 12018 static_cast<v8::IndexedPropertyGetterCallback>(0));
12009 LocalContext context; 12019 LocalContext context;
12010 templ->Set("42", v8_num(42)); 12020 templ->Set("42", v8_num(42));
12011 v8::Handle<v8::Object> obj = templ->NewInstance(); 12021 v8::Handle<v8::Object> obj = templ->NewInstance();
12012 context->Global()->Set(v8_str("obj"), obj); 12022 context->Global()->Set(v8_str("obj"), obj);
12013 v8::Handle<Value> value = CompileRun("obj[42]"); 12023 v8::Handle<Value> value = CompileRun("obj[42]");
12014 CHECK(value->IsInt32()); 12024 CHECK(value->IsInt32());
12015 CHECK_EQ(42, value->Int32Value()); 12025 CHECK_EQ(42, value->Int32Value());
12016 } 12026 }
12017 12027
12018 12028
12019 THREADED_TEST(NamedPropertyHandlerGetterAttributes) { 12029 THREADED_TEST(NamedPropertyHandlerGetterAttributes) {
12020 v8::HandleScope scope(v8::Isolate::GetCurrent()); 12030 v8::HandleScope scope(CcTest::isolate());
12021 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 12031 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
12022 templ->InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter); 12032 templ->InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter);
12023 LocalContext env; 12033 LocalContext env;
12024 env->Global()->Set(v8_str("obj"), 12034 env->Global()->Set(v8_str("obj"),
12025 templ->GetFunction()->NewInstance()); 12035 templ->GetFunction()->NewInstance());
12026 ExpectTrue("obj.x === 42"); 12036 ExpectTrue("obj.x === 42");
12027 ExpectTrue("!obj.propertyIsEnumerable('x')"); 12037 ExpectTrue("!obj.propertyIsEnumerable('x')");
12028 } 12038 }
12029 12039
12030 12040
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
12090 12100
12091 12101
12092 static void ThrowingCallbackWithTryCatch( 12102 static void ThrowingCallbackWithTryCatch(
12093 const v8::FunctionCallbackInfo<v8::Value>& args) { 12103 const v8::FunctionCallbackInfo<v8::Value>& args) {
12094 TryCatch try_catch; 12104 TryCatch try_catch;
12095 // Verboseness is important: it triggers message delivery which can call into 12105 // Verboseness is important: it triggers message delivery which can call into
12096 // external code. 12106 // external code.
12097 try_catch.SetVerbose(true); 12107 try_catch.SetVerbose(true);
12098 CompileRun("throw 'from JS';"); 12108 CompileRun("throw 'from JS';");
12099 CHECK(try_catch.HasCaught()); 12109 CHECK(try_catch.HasCaught());
12100 CHECK(!i::Isolate::Current()->has_pending_exception()); 12110 CHECK(!CcTest::i_isolate()->has_pending_exception());
12101 CHECK(!i::Isolate::Current()->has_scheduled_exception()); 12111 CHECK(!CcTest::i_isolate()->has_scheduled_exception());
12102 } 12112 }
12103 12113
12104 12114
12105 static int call_depth; 12115 static int call_depth;
12106 12116
12107 12117
12108 static void WithTryCatch(Handle<Message> message, Handle<Value> data) { 12118 static void WithTryCatch(Handle<Message> message, Handle<Value> data) {
12109 TryCatch try_catch; 12119 TryCatch try_catch;
12110 } 12120 }
12111 12121
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
12230 12240
12231 12241
12232 static void IsConstructHandler( 12242 static void IsConstructHandler(
12233 const v8::FunctionCallbackInfo<v8::Value>& args) { 12243 const v8::FunctionCallbackInfo<v8::Value>& args) {
12234 ApiTestFuzzer::Fuzz(); 12244 ApiTestFuzzer::Fuzz();
12235 args.GetReturnValue().Set(args.IsConstructCall()); 12245 args.GetReturnValue().Set(args.IsConstructCall());
12236 } 12246 }
12237 12247
12238 12248
12239 THREADED_TEST(IsConstructCall) { 12249 THREADED_TEST(IsConstructCall) {
12240 v8::HandleScope scope(v8::Isolate::GetCurrent()); 12250 v8::HandleScope scope(CcTest::isolate());
12241 12251
12242 // Function template with call handler. 12252 // Function template with call handler.
12243 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 12253 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
12244 templ->SetCallHandler(IsConstructHandler); 12254 templ->SetCallHandler(IsConstructHandler);
12245 12255
12246 LocalContext context; 12256 LocalContext context;
12247 12257
12248 context->Global()->Set(v8_str("f"), templ->GetFunction()); 12258 context->Global()->Set(v8_str("f"), templ->GetFunction());
12249 Local<Value> value = v8_compile("f()")->Run(); 12259 Local<Value> value = v8_compile("f()")->Run();
12250 CHECK(!value->BooleanValue()); 12260 CHECK(!value->BooleanValue());
12251 value = v8_compile("new f()")->Run(); 12261 value = v8_compile("new f()")->Run();
12252 CHECK(value->BooleanValue()); 12262 CHECK(value->BooleanValue());
12253 } 12263 }
12254 12264
12255 12265
12256 THREADED_TEST(ObjectProtoToString) { 12266 THREADED_TEST(ObjectProtoToString) {
12257 v8::HandleScope scope(v8::Isolate::GetCurrent()); 12267 v8::HandleScope scope(CcTest::isolate());
12258 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 12268 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
12259 templ->SetClassName(v8_str("MyClass")); 12269 templ->SetClassName(v8_str("MyClass"));
12260 12270
12261 LocalContext context; 12271 LocalContext context;
12262 12272
12263 Local<String> customized_tostring = v8_str("customized toString"); 12273 Local<String> customized_tostring = v8_str("customized toString");
12264 12274
12265 // Replace Object.prototype.toString 12275 // Replace Object.prototype.toString
12266 v8_compile("Object.prototype.toString = function() {" 12276 v8_compile("Object.prototype.toString = function() {"
12267 " return 'customized toString';" 12277 " return 'customized toString';"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
12347 RegisterThreadedTest::nth(current_)->fuzzer_->gate_.Signal(); 12357 RegisterThreadedTest::nth(current_)->fuzzer_->gate_.Signal();
12348 return true; 12358 return true;
12349 } 12359 }
12350 12360
12351 12361
12352 void ApiTestFuzzer::Run() { 12362 void ApiTestFuzzer::Run() {
12353 // When it is our turn... 12363 // When it is our turn...
12354 gate_.Wait(); 12364 gate_.Wait();
12355 { 12365 {
12356 // ... get the V8 lock and start running the test. 12366 // ... get the V8 lock and start running the test.
12357 v8::Locker locker(CcTest::default_isolate()); 12367 v8::Locker locker(CcTest::isolate());
12358 CallTest(); 12368 CallTest();
12359 } 12369 }
12360 // This test finished. 12370 // This test finished.
12361 active_ = false; 12371 active_ = false;
12362 active_tests_--; 12372 active_tests_--;
12363 // If it was the last then signal that fact. 12373 // If it was the last then signal that fact.
12364 if (active_tests_ == 0) { 12374 if (active_tests_ == 0) {
12365 all_tests_done_.Signal(); 12375 all_tests_done_.Signal();
12366 } else { 12376 } else {
12367 // Otherwise select a new test and start that. 12377 // Otherwise select a new test and start that.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
12411 linear_congruential_generator += 1013904223u; 12421 linear_congruential_generator += 1013904223u;
12412 } while (!RegisterThreadedTest::nth(next_test)->fuzzer_->active_); 12422 } while (!RegisterThreadedTest::nth(next_test)->fuzzer_->active_);
12413 return next_test; 12423 return next_test;
12414 } 12424 }
12415 12425
12416 12426
12417 void ApiTestFuzzer::ContextSwitch() { 12427 void ApiTestFuzzer::ContextSwitch() {
12418 // If the new thread is the same as the current thread there is nothing to do. 12428 // If the new thread is the same as the current thread there is nothing to do.
12419 if (NextThread()) { 12429 if (NextThread()) {
12420 // Now it can start. 12430 // Now it can start.
12421 v8::Unlocker unlocker(CcTest::default_isolate()); 12431 v8::Unlocker unlocker(CcTest::isolate());
12422 // Wait till someone starts us again. 12432 // Wait till someone starts us again.
12423 gate_.Wait(); 12433 gate_.Wait();
12424 // And we're off. 12434 // And we're off.
12425 } 12435 }
12426 } 12436 }
12427 12437
12428 12438
12429 void ApiTestFuzzer::TearDown() { 12439 void ApiTestFuzzer::TearDown() {
12430 fuzzing_ = false; 12440 fuzzing_ = false;
12431 for (int i = 0; i < RegisterThreadedTest::count(); i++) { 12441 for (int i = 0; i < RegisterThreadedTest::count(); i++) {
12432 ApiTestFuzzer *fuzzer = RegisterThreadedTest::nth(i)->fuzzer_; 12442 ApiTestFuzzer *fuzzer = RegisterThreadedTest::nth(i)->fuzzer_;
12433 if (fuzzer != NULL) fuzzer->Join(); 12443 if (fuzzer != NULL) fuzzer->Join();
12434 } 12444 }
12435 } 12445 }
12436 12446
12437 12447
12438 // Lets not be needlessly self-referential. 12448 // Lets not be needlessly self-referential.
12439 TEST(Threading1) { 12449 UNINITIALIZED_TEST(Threading1) {
12440 ApiTestFuzzer::SetUp(ApiTestFuzzer::FIRST_PART); 12450 ApiTestFuzzer::SetUp(ApiTestFuzzer::FIRST_PART);
12441 ApiTestFuzzer::RunAllTests(); 12451 ApiTestFuzzer::RunAllTests();
12442 ApiTestFuzzer::TearDown(); 12452 ApiTestFuzzer::TearDown();
12443 } 12453 }
12444 12454
12445 12455
12446 TEST(Threading2) { 12456 UNINITIALIZED_TEST(Threading2) {
12447 ApiTestFuzzer::SetUp(ApiTestFuzzer::SECOND_PART); 12457 ApiTestFuzzer::SetUp(ApiTestFuzzer::SECOND_PART);
12448 ApiTestFuzzer::RunAllTests(); 12458 ApiTestFuzzer::RunAllTests();
12449 ApiTestFuzzer::TearDown(); 12459 ApiTestFuzzer::TearDown();
12450 } 12460 }
12451 12461
12452 12462
12453 TEST(Threading3) { 12463 UNINITIALIZED_TEST(Threading3) {
12454 ApiTestFuzzer::SetUp(ApiTestFuzzer::THIRD_PART); 12464 ApiTestFuzzer::SetUp(ApiTestFuzzer::THIRD_PART);
12455 ApiTestFuzzer::RunAllTests(); 12465 ApiTestFuzzer::RunAllTests();
12456 ApiTestFuzzer::TearDown(); 12466 ApiTestFuzzer::TearDown();
12457 } 12467 }
12458 12468
12459 12469
12460 TEST(Threading4) { 12470 UNINITIALIZED_TEST(Threading4) {
12461 ApiTestFuzzer::SetUp(ApiTestFuzzer::FOURTH_PART); 12471 ApiTestFuzzer::SetUp(ApiTestFuzzer::FOURTH_PART);
12462 ApiTestFuzzer::RunAllTests(); 12472 ApiTestFuzzer::RunAllTests();
12463 ApiTestFuzzer::TearDown(); 12473 ApiTestFuzzer::TearDown();
12464 } 12474 }
12465 12475
12466 12476
12467 void ApiTestFuzzer::CallTest() { 12477 void ApiTestFuzzer::CallTest() {
12468 if (kLogThreading) 12478 if (kLogThreading)
12469 printf("Start test %d\n", test_number_); 12479 printf("Start test %d\n", test_number_);
12470 CallTestNumber(test_number_); 12480 CallTestNumber(test_number_);
12471 if (kLogThreading) 12481 if (kLogThreading)
12472 printf("End test %d\n", test_number_); 12482 printf("End test %d\n", test_number_);
12473 } 12483 }
12474 12484
12475 12485
12476 static void ThrowInJS(const v8::FunctionCallbackInfo<v8::Value>& args) { 12486 static void ThrowInJS(const v8::FunctionCallbackInfo<v8::Value>& args) {
12477 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); 12487 CHECK(v8::Locker::IsLocked(CcTest::isolate()));
12478 ApiTestFuzzer::Fuzz(); 12488 ApiTestFuzzer::Fuzz();
12479 v8::Unlocker unlocker(CcTest::default_isolate()); 12489 v8::Unlocker unlocker(CcTest::isolate());
12480 const char* code = "throw 7;"; 12490 const char* code = "throw 7;";
12481 { 12491 {
12482 v8::Locker nested_locker(CcTest::default_isolate()); 12492 v8::Locker nested_locker(CcTest::isolate());
12483 v8::HandleScope scope(args.GetIsolate()); 12493 v8::HandleScope scope(args.GetIsolate());
12484 v8::Handle<Value> exception; 12494 v8::Handle<Value> exception;
12485 { v8::TryCatch try_catch; 12495 { v8::TryCatch try_catch;
12486 v8::Handle<Value> value = CompileRun(code); 12496 v8::Handle<Value> value = CompileRun(code);
12487 CHECK(value.IsEmpty()); 12497 CHECK(value.IsEmpty());
12488 CHECK(try_catch.HasCaught()); 12498 CHECK(try_catch.HasCaught());
12489 // Make sure to wrap the exception in a new handle because 12499 // Make sure to wrap the exception in a new handle because
12490 // the handle returned from the TryCatch is destroyed 12500 // the handle returned from the TryCatch is destroyed
12491 // when the TryCatch is destroyed. 12501 // when the TryCatch is destroyed.
12492 exception = Local<Value>::New(try_catch.Exception()); 12502 exception = Local<Value>::New(try_catch.Exception());
12493 } 12503 }
12494 v8::ThrowException(exception); 12504 v8::ThrowException(exception);
12495 } 12505 }
12496 } 12506 }
12497 12507
12498 12508
12499 static void ThrowInJSNoCatch(const v8::FunctionCallbackInfo<v8::Value>& args) { 12509 static void ThrowInJSNoCatch(const v8::FunctionCallbackInfo<v8::Value>& args) {
12500 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); 12510 CHECK(v8::Locker::IsLocked(CcTest::isolate()));
12501 ApiTestFuzzer::Fuzz(); 12511 ApiTestFuzzer::Fuzz();
12502 v8::Unlocker unlocker(CcTest::default_isolate()); 12512 v8::Unlocker unlocker(CcTest::isolate());
12503 const char* code = "throw 7;"; 12513 const char* code = "throw 7;";
12504 { 12514 {
12505 v8::Locker nested_locker(CcTest::default_isolate()); 12515 v8::Locker nested_locker(CcTest::isolate());
12506 v8::HandleScope scope(args.GetIsolate()); 12516 v8::HandleScope scope(args.GetIsolate());
12507 v8::Handle<Value> value = CompileRun(code); 12517 v8::Handle<Value> value = CompileRun(code);
12508 CHECK(value.IsEmpty()); 12518 CHECK(value.IsEmpty());
12509 args.GetReturnValue().Set(v8_str("foo")); 12519 args.GetReturnValue().Set(v8_str("foo"));
12510 } 12520 }
12511 } 12521 }
12512 12522
12513 12523
12514 // These are locking tests that don't need to be run again 12524 // These are locking tests that don't need to be run again
12515 // as part of the locking aggregation tests. 12525 // as part of the locking aggregation tests.
12516 TEST(NestedLockers) { 12526 TEST(NestedLockers) {
12517 v8::Locker locker(CcTest::default_isolate()); 12527 v8::Locker locker(CcTest::isolate());
12518 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); 12528 CHECK(v8::Locker::IsLocked(CcTest::isolate()));
12519 LocalContext env; 12529 LocalContext env;
12520 v8::HandleScope scope(env->GetIsolate()); 12530 v8::HandleScope scope(env->GetIsolate());
12521 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(ThrowInJS); 12531 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(ThrowInJS);
12522 Local<Function> fun = fun_templ->GetFunction(); 12532 Local<Function> fun = fun_templ->GetFunction();
12523 env->Global()->Set(v8_str("throw_in_js"), fun); 12533 env->Global()->Set(v8_str("throw_in_js"), fun);
12524 Local<Script> script = v8_compile("(function () {" 12534 Local<Script> script = v8_compile("(function () {"
12525 " try {" 12535 " try {"
12526 " throw_in_js();" 12536 " throw_in_js();"
12527 " return 42;" 12537 " return 42;"
12528 " } catch (e) {" 12538 " } catch (e) {"
12529 " return e * 13;" 12539 " return e * 13;"
12530 " }" 12540 " }"
12531 "})();"); 12541 "})();");
12532 CHECK_EQ(91, script->Run()->Int32Value()); 12542 CHECK_EQ(91, script->Run()->Int32Value());
12533 } 12543 }
12534 12544
12535 12545
12536 // These are locking tests that don't need to be run again 12546 // These are locking tests that don't need to be run again
12537 // as part of the locking aggregation tests. 12547 // as part of the locking aggregation tests.
12538 TEST(NestedLockersNoTryCatch) { 12548 TEST(NestedLockersNoTryCatch) {
12539 v8::Locker locker(CcTest::default_isolate()); 12549 v8::Locker locker(CcTest::isolate());
12540 LocalContext env; 12550 LocalContext env;
12541 v8::HandleScope scope(env->GetIsolate()); 12551 v8::HandleScope scope(env->GetIsolate());
12542 Local<v8::FunctionTemplate> fun_templ = 12552 Local<v8::FunctionTemplate> fun_templ =
12543 v8::FunctionTemplate::New(ThrowInJSNoCatch); 12553 v8::FunctionTemplate::New(ThrowInJSNoCatch);
12544 Local<Function> fun = fun_templ->GetFunction(); 12554 Local<Function> fun = fun_templ->GetFunction();
12545 env->Global()->Set(v8_str("throw_in_js"), fun); 12555 env->Global()->Set(v8_str("throw_in_js"), fun);
12546 Local<Script> script = v8_compile("(function () {" 12556 Local<Script> script = v8_compile("(function () {"
12547 " try {" 12557 " try {"
12548 " throw_in_js();" 12558 " throw_in_js();"
12549 " return 42;" 12559 " return 42;"
12550 " } catch (e) {" 12560 " } catch (e) {"
12551 " return e * 13;" 12561 " return e * 13;"
12552 " }" 12562 " }"
12553 "})();"); 12563 "})();");
12554 CHECK_EQ(91, script->Run()->Int32Value()); 12564 CHECK_EQ(91, script->Run()->Int32Value());
12555 } 12565 }
12556 12566
12557 12567
12558 THREADED_TEST(RecursiveLocking) { 12568 THREADED_TEST(RecursiveLocking) {
12559 v8::Locker locker(CcTest::default_isolate()); 12569 v8::Locker locker(CcTest::isolate());
12560 { 12570 {
12561 v8::Locker locker2(CcTest::default_isolate()); 12571 v8::Locker locker2(CcTest::isolate());
12562 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); 12572 CHECK(v8::Locker::IsLocked(CcTest::isolate()));
12563 } 12573 }
12564 } 12574 }
12565 12575
12566 12576
12567 static void UnlockForAMoment(const v8::FunctionCallbackInfo<v8::Value>& args) { 12577 static void UnlockForAMoment(const v8::FunctionCallbackInfo<v8::Value>& args) {
12568 ApiTestFuzzer::Fuzz(); 12578 ApiTestFuzzer::Fuzz();
12569 v8::Unlocker unlocker(CcTest::default_isolate()); 12579 v8::Unlocker unlocker(CcTest::isolate());
12570 } 12580 }
12571 12581
12572 12582
12573 THREADED_TEST(LockUnlockLock) { 12583 THREADED_TEST(LockUnlockLock) {
12574 { 12584 {
12575 v8::Locker locker(CcTest::default_isolate()); 12585 v8::Locker locker(CcTest::isolate());
12576 v8::HandleScope scope(CcTest::default_isolate()); 12586 v8::HandleScope scope(CcTest::isolate());
12577 LocalContext env; 12587 LocalContext env;
12578 Local<v8::FunctionTemplate> fun_templ = 12588 Local<v8::FunctionTemplate> fun_templ =
12579 v8::FunctionTemplate::New(UnlockForAMoment); 12589 v8::FunctionTemplate::New(UnlockForAMoment);
12580 Local<Function> fun = fun_templ->GetFunction(); 12590 Local<Function> fun = fun_templ->GetFunction();
12581 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); 12591 env->Global()->Set(v8_str("unlock_for_a_moment"), fun);
12582 Local<Script> script = v8_compile("(function () {" 12592 Local<Script> script = v8_compile("(function () {"
12583 " unlock_for_a_moment();" 12593 " unlock_for_a_moment();"
12584 " return 42;" 12594 " return 42;"
12585 "})();"); 12595 "})();");
12586 CHECK_EQ(42, script->Run()->Int32Value()); 12596 CHECK_EQ(42, script->Run()->Int32Value());
12587 } 12597 }
12588 { 12598 {
12589 v8::Locker locker(CcTest::default_isolate()); 12599 v8::Locker locker(CcTest::isolate());
12590 v8::HandleScope scope(CcTest::default_isolate()); 12600 v8::HandleScope scope(CcTest::isolate());
12591 LocalContext env; 12601 LocalContext env;
12592 Local<v8::FunctionTemplate> fun_templ = 12602 Local<v8::FunctionTemplate> fun_templ =
12593 v8::FunctionTemplate::New(UnlockForAMoment); 12603 v8::FunctionTemplate::New(UnlockForAMoment);
12594 Local<Function> fun = fun_templ->GetFunction(); 12604 Local<Function> fun = fun_templ->GetFunction();
12595 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); 12605 env->Global()->Set(v8_str("unlock_for_a_moment"), fun);
12596 Local<Script> script = v8_compile("(function () {" 12606 Local<Script> script = v8_compile("(function () {"
12597 " unlock_for_a_moment();" 12607 " unlock_for_a_moment();"
12598 " return 42;" 12608 " return 42;"
12599 "})();"); 12609 "})();");
12600 CHECK_EQ(42, script->Run()->Int32Value()); 12610 CHECK_EQ(42, script->Run()->Int32Value());
12601 } 12611 }
12602 } 12612 }
12603 12613
12604 12614
12605 static int GetGlobalObjectsCount() { 12615 static int GetGlobalObjectsCount() {
12606 i::Isolate::Current()->heap()->EnsureHeapIsIterable(); 12616 CcTest::heap()->EnsureHeapIsIterable();
12607 int count = 0; 12617 int count = 0;
12608 i::HeapIterator it(HEAP); 12618 i::HeapIterator it(CcTest::heap());
12609 for (i::HeapObject* object = it.next(); object != NULL; object = it.next()) 12619 for (i::HeapObject* object = it.next(); object != NULL; object = it.next())
12610 if (object->IsJSGlobalObject()) count++; 12620 if (object->IsJSGlobalObject()) count++;
12611 return count; 12621 return count;
12612 } 12622 }
12613 12623
12614 12624
12615 static void CheckSurvivingGlobalObjectsCount(int expected) { 12625 static void CheckSurvivingGlobalObjectsCount(int expected) {
12616 // We need to collect all garbage twice to be sure that everything 12626 // We need to collect all garbage twice to be sure that everything
12617 // has been collected. This is because inline caches are cleared in 12627 // has been collected. This is because inline caches are cleared in
12618 // the first garbage collection but some of the maps have already 12628 // the first garbage collection but some of the maps have already
12619 // been marked at that point. Therefore some of the maps are not 12629 // been marked at that point. Therefore some of the maps are not
12620 // collected until the second garbage collection. 12630 // collected until the second garbage collection.
12621 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 12631 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
12622 HEAP->CollectAllGarbage(i::Heap::kMakeHeapIterableMask); 12632 CcTest::heap()->CollectAllGarbage(i::Heap::kMakeHeapIterableMask);
12623 int count = GetGlobalObjectsCount(); 12633 int count = GetGlobalObjectsCount();
12624 #ifdef DEBUG 12634 #ifdef DEBUG
12625 if (count != expected) HEAP->TracePathToGlobal(); 12635 if (count != expected) CcTest::heap()->TracePathToGlobal();
12626 #endif 12636 #endif
12627 CHECK_EQ(expected, count); 12637 CHECK_EQ(expected, count);
12628 } 12638 }
12629 12639
12630 12640
12631 TEST(DontLeakGlobalObjects) { 12641 TEST(DontLeakGlobalObjects) {
12632 // Regression test for issues 1139850 and 1174891. 12642 // Regression test for issues 1139850 and 1174891.
12633 12643
12634 v8::V8::Initialize(); 12644 v8::V8::Initialize();
12635 12645
12636 for (int i = 0; i < 5; i++) { 12646 for (int i = 0; i < 5; i++) {
12637 { v8::HandleScope scope(v8::Isolate::GetCurrent()); 12647 { v8::HandleScope scope(CcTest::isolate());
12638 LocalContext context; 12648 LocalContext context;
12639 } 12649 }
12640 v8::V8::ContextDisposedNotification(); 12650 v8::V8::ContextDisposedNotification();
12641 CheckSurvivingGlobalObjectsCount(0); 12651 CheckSurvivingGlobalObjectsCount(0);
12642 12652
12643 { v8::HandleScope scope(v8::Isolate::GetCurrent()); 12653 { v8::HandleScope scope(CcTest::isolate());
12644 LocalContext context; 12654 LocalContext context;
12645 v8_compile("Date")->Run(); 12655 v8_compile("Date")->Run();
12646 } 12656 }
12647 v8::V8::ContextDisposedNotification(); 12657 v8::V8::ContextDisposedNotification();
12648 CheckSurvivingGlobalObjectsCount(0); 12658 CheckSurvivingGlobalObjectsCount(0);
12649 12659
12650 { v8::HandleScope scope(v8::Isolate::GetCurrent()); 12660 { v8::HandleScope scope(CcTest::isolate());
12651 LocalContext context; 12661 LocalContext context;
12652 v8_compile("/aaa/")->Run(); 12662 v8_compile("/aaa/")->Run();
12653 } 12663 }
12654 v8::V8::ContextDisposedNotification(); 12664 v8::V8::ContextDisposedNotification();
12655 CheckSurvivingGlobalObjectsCount(0); 12665 CheckSurvivingGlobalObjectsCount(0);
12656 12666
12657 { v8::HandleScope scope(v8::Isolate::GetCurrent()); 12667 { v8::HandleScope scope(CcTest::isolate());
12658 const char* extension_list[] = { "v8/gc" }; 12668 const char* extension_list[] = { "v8/gc" };
12659 v8::ExtensionConfiguration extensions(1, extension_list); 12669 v8::ExtensionConfiguration extensions(1, extension_list);
12660 LocalContext context(&extensions); 12670 LocalContext context(&extensions);
12661 v8_compile("gc();")->Run(); 12671 v8_compile("gc();")->Run();
12662 } 12672 }
12663 v8::V8::ContextDisposedNotification(); 12673 v8::V8::ContextDisposedNotification();
12664 CheckSurvivingGlobalObjectsCount(0); 12674 CheckSurvivingGlobalObjectsCount(0);
12665 } 12675 }
12666 } 12676 }
12667 12677
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
12757 some_object.Reset(isolate, v8::Object::New()); 12767 some_object.Reset(isolate, v8::Object::New());
12758 handle1.Reset(isolate, v8::Object::New()); 12768 handle1.Reset(isolate, v8::Object::New());
12759 handle2.Reset(isolate, v8::Object::New()); 12769 handle2.Reset(isolate, v8::Object::New());
12760 } 12770 }
12761 // Note: order is implementation dependent alas: currently 12771 // Note: order is implementation dependent alas: currently
12762 // global handle nodes are processed by PostGarbageCollectionProcessing 12772 // global handle nodes are processed by PostGarbageCollectionProcessing
12763 // in reverse allocation order, so if second allocated handle is deleted, 12773 // in reverse allocation order, so if second allocated handle is deleted,
12764 // weak callback of the first handle would be able to 'reallocate' it. 12774 // weak callback of the first handle would be able to 'reallocate' it.
12765 handle1.MakeWeak<v8::Value, void>(NULL, NewPersistentHandleCallback); 12775 handle1.MakeWeak<v8::Value, void>(NULL, NewPersistentHandleCallback);
12766 handle2.Dispose(); 12776 handle2.Dispose();
12767 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 12777 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
12768 } 12778 }
12769 12779
12770 12780
12771 v8::Persistent<v8::Object> to_be_disposed; 12781 v8::Persistent<v8::Object> to_be_disposed;
12772 12782
12773 void DisposeAndForceGcCallback(v8::Isolate* isolate, 12783 void DisposeAndForceGcCallback(v8::Isolate* isolate,
12774 v8::Persistent<v8::Value>* handle, 12784 v8::Persistent<v8::Value>* handle,
12775 void*) { 12785 void*) {
12776 to_be_disposed.Dispose(); 12786 to_be_disposed.Dispose();
12777 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 12787 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
12778 handle->Dispose(); 12788 handle->Dispose();
12779 } 12789 }
12780 12790
12781 12791
12782 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) { 12792 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) {
12783 LocalContext context; 12793 LocalContext context;
12784 v8::Isolate* isolate = context->GetIsolate(); 12794 v8::Isolate* isolate = context->GetIsolate();
12785 12795
12786 v8::Persistent<v8::Object> handle1, handle2; 12796 v8::Persistent<v8::Object> handle1, handle2;
12787 { 12797 {
12788 v8::HandleScope scope(isolate); 12798 v8::HandleScope scope(isolate);
12789 handle1.Reset(isolate, v8::Object::New()); 12799 handle1.Reset(isolate, v8::Object::New());
12790 handle2.Reset(isolate, v8::Object::New()); 12800 handle2.Reset(isolate, v8::Object::New());
12791 } 12801 }
12792 handle1.MakeWeak<v8::Value, void>(NULL, DisposeAndForceGcCallback); 12802 handle1.MakeWeak<v8::Value, void>(NULL, DisposeAndForceGcCallback);
12793 to_be_disposed.Reset(isolate, handle2); 12803 to_be_disposed.Reset(isolate, handle2);
12794 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 12804 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
12795 } 12805 }
12796 12806
12797 void DisposingCallback(v8::Isolate* isolate, 12807 void DisposingCallback(v8::Isolate* isolate,
12798 v8::Persistent<v8::Value>* handle, 12808 v8::Persistent<v8::Value>* handle,
12799 void*) { 12809 void*) {
12800 handle->Dispose(); 12810 handle->Dispose();
12801 } 12811 }
12802 12812
12803 void HandleCreatingCallback(v8::Isolate* isolate, 12813 void HandleCreatingCallback(v8::Isolate* isolate,
12804 v8::Persistent<v8::Value>* handle, 12814 v8::Persistent<v8::Value>* handle,
(...skipping 10 matching lines...) Expand all
12815 12825
12816 v8::Persistent<v8::Object> handle1, handle2, handle3; 12826 v8::Persistent<v8::Object> handle1, handle2, handle3;
12817 { 12827 {
12818 v8::HandleScope scope(isolate); 12828 v8::HandleScope scope(isolate);
12819 handle3.Reset(isolate, v8::Object::New()); 12829 handle3.Reset(isolate, v8::Object::New());
12820 handle2.Reset(isolate, v8::Object::New()); 12830 handle2.Reset(isolate, v8::Object::New());
12821 handle1.Reset(isolate, v8::Object::New()); 12831 handle1.Reset(isolate, v8::Object::New());
12822 } 12832 }
12823 handle2.MakeWeak<v8::Value, void>(NULL, DisposingCallback); 12833 handle2.MakeWeak<v8::Value, void>(NULL, DisposingCallback);
12824 handle3.MakeWeak<v8::Value, void>(NULL, HandleCreatingCallback); 12834 handle3.MakeWeak<v8::Value, void>(NULL, HandleCreatingCallback);
12825 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 12835 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
12826 } 12836 }
12827 12837
12828 12838
12829 THREADED_TEST(CheckForCrossContextObjectLiterals) { 12839 THREADED_TEST(CheckForCrossContextObjectLiterals) {
12830 v8::V8::Initialize(); 12840 v8::V8::Initialize();
12831 12841
12832 const int nof = 2; 12842 const int nof = 2;
12833 const char* sources[nof] = { 12843 const char* sources[nof] = {
12834 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }", 12844 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }",
12835 "Object()" 12845 "Object()"
12836 }; 12846 };
12837 12847
12838 for (int i = 0; i < nof; i++) { 12848 for (int i = 0; i < nof; i++) {
12839 const char* source = sources[i]; 12849 const char* source = sources[i];
12840 { v8::HandleScope scope(v8::Isolate::GetCurrent()); 12850 { v8::HandleScope scope(CcTest::isolate());
12841 LocalContext context; 12851 LocalContext context;
12842 CompileRun(source); 12852 CompileRun(source);
12843 } 12853 }
12844 { v8::HandleScope scope(v8::Isolate::GetCurrent()); 12854 { v8::HandleScope scope(CcTest::isolate());
12845 LocalContext context; 12855 LocalContext context;
12846 CompileRun(source); 12856 CompileRun(source);
12847 } 12857 }
12848 } 12858 }
12849 } 12859 }
12850 12860
12851 12861
12852 static v8::Handle<Value> NestedScope(v8::Local<Context> env) { 12862 static v8::Handle<Value> NestedScope(v8::Local<Context> env) {
12853 v8::HandleScope inner(env->GetIsolate()); 12863 v8::HandleScope inner(env->GetIsolate());
12854 env->Enter(); 12864 env->Enter();
12855 v8::Handle<Value> three = v8_num(3); 12865 v8::Handle<Value> three = v8_num(3);
12856 v8::Handle<Value> value = inner.Close(three); 12866 v8::Handle<Value> value = inner.Close(three);
12857 env->Exit(); 12867 env->Exit();
12858 return value; 12868 return value;
12859 } 12869 }
12860 12870
12861 12871
12862 THREADED_TEST(NestedHandleScopeAndContexts) { 12872 THREADED_TEST(NestedHandleScopeAndContexts) {
12863 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 12873 v8::Isolate* isolate = CcTest::isolate();
12864 v8::HandleScope outer(isolate); 12874 v8::HandleScope outer(isolate);
12865 v8::Local<Context> env = Context::New(isolate); 12875 v8::Local<Context> env = Context::New(isolate);
12866 env->Enter(); 12876 env->Enter();
12867 v8::Handle<Value> value = NestedScope(env); 12877 v8::Handle<Value> value = NestedScope(env);
12868 v8::Handle<String> str(value->ToString()); 12878 v8::Handle<String> str(value->ToString());
12869 CHECK(!str.IsEmpty()); 12879 CHECK(!str.IsEmpty());
12870 env->Exit(); 12880 env->Exit();
12871 } 12881 }
12872 12882
12873 12883
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
13347 break; 13357 break;
13348 13358
13349 default: 13359 default:
13350 // Impossible event. 13360 // Impossible event.
13351 CHECK(false); 13361 CHECK(false);
13352 break; 13362 break;
13353 } 13363 }
13354 } 13364 }
13355 13365
13356 13366
13357 TEST(SetJitCodeEventHandler) { 13367 UNINITIALIZED_TEST(SetJitCodeEventHandler) {
13358 i::FLAG_stress_compaction = true; 13368 i::FLAG_stress_compaction = true;
13359 i::FLAG_incremental_marking = false; 13369 i::FLAG_incremental_marking = false;
13360 const char* script = 13370 const char* script =
13361 "function bar() {" 13371 "function bar() {"
13362 " var sum = 0;" 13372 " var sum = 0;"
13363 " for (i = 0; i < 100; ++i)" 13373 " for (i = 0; i < 100; ++i)"
13364 " sum = foo(i);" 13374 " sum = foo(i);"
13365 " return sum;" 13375 " return sum;"
13366 "}" 13376 "}"
13367 "function foo(i) { return i * i; };" 13377 "function foo(i) { return i * i; };"
13368 "bar();"; 13378 "bar();";
13369 13379
13370 // Run this test in a new isolate to make sure we don't 13380 // Run this test in a new isolate to make sure we don't
13371 // have remnants of state from other code. 13381 // have remnants of state from other code.
13372 v8::Isolate* isolate = v8::Isolate::New(); 13382 v8::Isolate* isolate = v8::Isolate::New();
13373 isolate->Enter(); 13383 isolate->Enter();
13384 i::Heap* heap = reinterpret_cast<i::Isolate*>(isolate)->heap();
13374 13385
13375 { 13386 {
13376 v8::HandleScope scope(isolate); 13387 v8::HandleScope scope(isolate);
13377 i::HashMap code(MatchPointers); 13388 i::HashMap code(MatchPointers);
13378 code_map = &code; 13389 code_map = &code;
13379 13390
13380 i::HashMap lineinfo(MatchPointers); 13391 i::HashMap lineinfo(MatchPointers);
13381 jitcode_line_info = &lineinfo; 13392 jitcode_line_info = &lineinfo;
13382 13393
13383 saw_bar = 0; 13394 saw_bar = 0;
13384 move_events = 0; 13395 move_events = 0;
13385 13396
13386 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler); 13397 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler);
13387 13398
13388 // Generate new code objects sparsely distributed across several 13399 // Generate new code objects sparsely distributed across several
13389 // different fragmented code-space pages. 13400 // different fragmented code-space pages.
13390 const int kIterations = 10; 13401 const int kIterations = 10;
13391 for (int i = 0; i < kIterations; ++i) { 13402 for (int i = 0; i < kIterations; ++i) {
13392 LocalContext env; 13403 LocalContext env(isolate);
13393 i::AlwaysAllocateScope always_allocate; 13404 i::AlwaysAllocateScope always_allocate;
13394 SimulateFullSpace(HEAP->code_space()); 13405 SimulateFullSpace(heap->code_space());
13395 CompileRun(script); 13406 CompileRun(script);
13396 13407
13397 // Keep a strong reference to the code object in the handle scope. 13408 // Keep a strong reference to the code object in the handle scope.
13398 i::Handle<i::Code> bar_code(i::Handle<i::JSFunction>::cast( 13409 i::Handle<i::Code> bar_code(i::Handle<i::JSFunction>::cast(
13399 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("bar"))))->code()); 13410 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("bar"))))->code());
13400 i::Handle<i::Code> foo_code(i::Handle<i::JSFunction>::cast( 13411 i::Handle<i::Code> foo_code(i::Handle<i::JSFunction>::cast(
13401 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("foo"))))->code()); 13412 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("foo"))))->code());
13402 13413
13403 // Clear the compilation cache to get more wastage. 13414 // Clear the compilation cache to get more wastage.
13404 reinterpret_cast<i::Isolate*>(isolate)->compilation_cache()->Clear(); 13415 reinterpret_cast<i::Isolate*>(isolate)->compilation_cache()->Clear();
13405 } 13416 }
13406 13417
13407 // Force code movement. 13418 // Force code movement.
13408 HEAP->CollectAllAvailableGarbage("TestSetJitCodeEventHandler"); 13419 heap->CollectAllAvailableGarbage("TestSetJitCodeEventHandler");
13409 13420
13410 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL); 13421 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL);
13411 13422
13412 CHECK_LE(kIterations, saw_bar); 13423 CHECK_LE(kIterations, saw_bar);
13413 CHECK_LT(0, move_events); 13424 CHECK_LT(0, move_events);
13414 13425
13415 code_map = NULL; 13426 code_map = NULL;
13416 jitcode_line_info = NULL; 13427 jitcode_line_info = NULL;
13417 } 13428 }
13418 13429
13419 isolate->Exit(); 13430 isolate->Exit();
13420 isolate->Dispose(); 13431 isolate->Dispose();
13421 13432
13422 // Do this in a new isolate. 13433 // Do this in a new isolate.
13423 isolate = v8::Isolate::New(); 13434 isolate = v8::Isolate::New();
13424 isolate->Enter(); 13435 isolate->Enter();
13425 13436
13426 // Verify that we get callbacks for existing code objects when we 13437 // Verify that we get callbacks for existing code objects when we
13427 // request enumeration of existing code. 13438 // request enumeration of existing code.
13428 { 13439 {
13429 v8::HandleScope scope(isolate); 13440 v8::HandleScope scope(isolate);
13430 LocalContext env; 13441 LocalContext env(isolate);
13431 CompileRun(script); 13442 CompileRun(script);
13432 13443
13433 // Now get code through initial iteration. 13444 // Now get code through initial iteration.
13434 i::HashMap code(MatchPointers); 13445 i::HashMap code(MatchPointers);
13435 code_map = &code; 13446 code_map = &code;
13436 13447
13437 i::HashMap lineinfo(MatchPointers); 13448 i::HashMap lineinfo(MatchPointers);
13438 jitcode_line_info = &lineinfo; 13449 jitcode_line_info = &lineinfo;
13439 13450
13440 V8::SetJitCodeEventHandler(v8::kJitCodeEventEnumExisting, event_handler); 13451 V8::SetJitCodeEventHandler(v8::kJitCodeEventEnumExisting, event_handler);
(...skipping 11 matching lines...) Expand all
13452 13463
13453 isolate->Exit(); 13464 isolate->Exit();
13454 isolate->Dispose(); 13465 isolate->Dispose();
13455 } 13466 }
13456 13467
13457 13468
13458 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); } 13469 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); }
13459 13470
13460 13471
13461 THREADED_TEST(ExternalAllocatedMemory) { 13472 THREADED_TEST(ExternalAllocatedMemory) {
13462 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 13473 v8::Isolate* isolate = CcTest::isolate();
13463 v8::HandleScope outer(isolate); 13474 v8::HandleScope outer(isolate);
13464 v8::Local<Context> env(Context::New(isolate)); 13475 v8::Local<Context> env(Context::New(isolate));
13465 CHECK(!env.IsEmpty()); 13476 CHECK(!env.IsEmpty());
13466 const intptr_t kSize = 1024*1024; 13477 const intptr_t kSize = 1024*1024;
13467 int64_t baseline = cast(isolate->AdjustAmountOfExternalAllocatedMemory(0)); 13478 int64_t baseline = cast(isolate->AdjustAmountOfExternalAllocatedMemory(0));
13468 CHECK_EQ(baseline + cast(kSize), 13479 CHECK_EQ(baseline + cast(kSize),
13469 cast(isolate->AdjustAmountOfExternalAllocatedMemory(kSize))); 13480 cast(isolate->AdjustAmountOfExternalAllocatedMemory(kSize)));
13470 CHECK_EQ(baseline, 13481 CHECK_EQ(baseline,
13471 cast(isolate->AdjustAmountOfExternalAllocatedMemory(-kSize))); 13482 cast(isolate->AdjustAmountOfExternalAllocatedMemory(-kSize)));
13472 } 13483 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
13527 "" 13538 ""
13528 "f();")); 13539 "f();"));
13529 v8::Handle<v8::Value> result = script->Run(); 13540 v8::Handle<v8::Value> result = script->Run();
13530 CHECK(result.IsEmpty()); 13541 CHECK(result.IsEmpty());
13531 } 13542 }
13532 13543
13533 13544
13534 static void CheckTryCatchSourceInfo(v8::Handle<v8::Script> script, 13545 static void CheckTryCatchSourceInfo(v8::Handle<v8::Script> script,
13535 const char* resource_name, 13546 const char* resource_name,
13536 int line_offset) { 13547 int line_offset) {
13537 v8::HandleScope scope(v8::Isolate::GetCurrent()); 13548 v8::HandleScope scope(CcTest::isolate());
13538 v8::TryCatch try_catch; 13549 v8::TryCatch try_catch;
13539 v8::Handle<v8::Value> result = script->Run(); 13550 v8::Handle<v8::Value> result = script->Run();
13540 CHECK(result.IsEmpty()); 13551 CHECK(result.IsEmpty());
13541 CHECK(try_catch.HasCaught()); 13552 CHECK(try_catch.HasCaught());
13542 v8::Handle<v8::Message> message = try_catch.Message(); 13553 v8::Handle<v8::Message> message = try_catch.Message();
13543 CHECK(!message.IsEmpty()); 13554 CHECK(!message.IsEmpty());
13544 CHECK_EQ(10 + line_offset, message->GetLineNumber()); 13555 CHECK_EQ(10 + line_offset, message->GetLineNumber());
13545 CHECK_EQ(91, message->GetStartPosition()); 13556 CHECK_EQ(91, message->GetStartPosition());
13546 CHECK_EQ(92, message->GetEndPosition()); 13557 CHECK_EQ(92, message->GetEndPosition());
13547 CHECK_EQ(2, message->GetStartColumn()); 13558 CHECK_EQ(2, message->GetStartColumn());
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
13800 context->Global()->Set(v8_str("obj_2"), instance_2); 13811 context->Global()->Set(v8_str("obj_2"), instance_2);
13801 13812
13802 Local<Value> value_2 = CompileRun("obj_2.a"); 13813 Local<Value> value_2 = CompileRun("obj_2.a");
13803 CHECK(value_2->IsUndefined()); 13814 CHECK(value_2->IsUndefined());
13804 } 13815 }
13805 13816
13806 13817
13807 // This tests that access check information remains on the global 13818 // This tests that access check information remains on the global
13808 // object template when creating contexts. 13819 // object template when creating contexts.
13809 THREADED_TEST(AccessControlRepeatedContextCreation) { 13820 THREADED_TEST(AccessControlRepeatedContextCreation) {
13810 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 13821 v8::Isolate* isolate = CcTest::isolate();
13811 v8::HandleScope handle_scope(isolate); 13822 v8::HandleScope handle_scope(isolate);
13812 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 13823 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
13813 global_template->SetAccessCheckCallbacks(NamedSetAccessBlocker, 13824 global_template->SetAccessCheckCallbacks(NamedSetAccessBlocker,
13814 IndexedSetAccessBlocker); 13825 IndexedSetAccessBlocker);
13815 i::Handle<i::ObjectTemplateInfo> internal_template = 13826 i::Handle<i::ObjectTemplateInfo> internal_template =
13816 v8::Utils::OpenHandle(*global_template); 13827 v8::Utils::OpenHandle(*global_template);
13817 CHECK(!internal_template->constructor()->IsUndefined()); 13828 CHECK(!internal_template->constructor()->IsUndefined());
13818 i::Handle<i::FunctionTemplateInfo> constructor( 13829 i::Handle<i::FunctionTemplateInfo> constructor(
13819 i::FunctionTemplateInfo::cast(internal_template->constructor())); 13830 i::FunctionTemplateInfo::cast(internal_template->constructor()));
13820 CHECK(!constructor->access_check_info()->IsUndefined()); 13831 CHECK(!constructor->access_check_info()->IsUndefined());
13821 v8::Local<Context> context0(Context::New(isolate, NULL, global_template)); 13832 v8::Local<Context> context0(Context::New(isolate, NULL, global_template));
13822 CHECK(!context0.IsEmpty()); 13833 CHECK(!context0.IsEmpty());
13823 CHECK(!constructor->access_check_info()->IsUndefined()); 13834 CHECK(!constructor->access_check_info()->IsUndefined());
13824 } 13835 }
13825 13836
13826 13837
13827 THREADED_TEST(TurnOnAccessCheck) { 13838 THREADED_TEST(TurnOnAccessCheck) {
13828 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 13839 v8::Isolate* isolate = CcTest::isolate();
13829 v8::HandleScope handle_scope(isolate); 13840 v8::HandleScope handle_scope(isolate);
13830 13841
13831 // Create an environment with access check to the global object disabled by 13842 // Create an environment with access check to the global object disabled by
13832 // default. 13843 // default.
13833 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 13844 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
13834 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker, 13845 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker,
13835 IndexedGetAccessBlocker, 13846 IndexedGetAccessBlocker,
13836 v8::Handle<v8::Value>(), 13847 v8::Handle<v8::Value>(),
13837 false); 13848 false);
13838 v8::Local<Context> context = Context::New(isolate, NULL, global_template); 13849 v8::Local<Context> context = Context::New(isolate, NULL, global_template);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
13899 Local<Value> data) { 13910 Local<Value> data) {
13900 if (!name->IsString()) return false; 13911 if (!name->IsString()) return false;
13901 i::Handle<i::String> name_handle = 13912 i::Handle<i::String> name_handle =
13902 v8::Utils::OpenHandle(String::Cast(*name)); 13913 v8::Utils::OpenHandle(String::Cast(*name));
13903 return !name_handle->IsUtf8EqualTo(i::CStrVector(kPropertyA)) 13914 return !name_handle->IsUtf8EqualTo(i::CStrVector(kPropertyA))
13904 && !name_handle->IsUtf8EqualTo(i::CStrVector(kPropertyH)); 13915 && !name_handle->IsUtf8EqualTo(i::CStrVector(kPropertyH));
13905 } 13916 }
13906 13917
13907 13918
13908 THREADED_TEST(TurnOnAccessCheckAndRecompile) { 13919 THREADED_TEST(TurnOnAccessCheckAndRecompile) {
13909 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 13920 v8::Isolate* isolate = CcTest::isolate();
13910 v8::HandleScope handle_scope(isolate); 13921 v8::HandleScope handle_scope(isolate);
13911 13922
13912 // Create an environment with access check to the global object disabled by 13923 // Create an environment with access check to the global object disabled by
13913 // default. When the registered access checker will block access to properties 13924 // default. When the registered access checker will block access to properties
13914 // a and h. 13925 // a and h.
13915 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 13926 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
13916 global_template->SetAccessCheckCallbacks(NamedGetAccessBlockAandH, 13927 global_template->SetAccessCheckCallbacks(NamedGetAccessBlockAandH,
13917 IndexedGetAccessBlocker, 13928 IndexedGetAccessBlocker,
13918 v8::Handle<v8::Value>(), 13929 v8::Handle<v8::Value>(),
13919 false); 13930 false);
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
14111 CHECK(!try_catch.HasCaught()); 14122 CHECK(!try_catch.HasCaught());
14112 14123
14113 delete sd; 14124 delete sd;
14114 } 14125 }
14115 14126
14116 14127
14117 // Verifies that the Handle<String> and const char* versions of the API produce 14128 // Verifies that the Handle<String> and const char* versions of the API produce
14118 // the same results (at least for one trivial case). 14129 // the same results (at least for one trivial case).
14119 TEST(PreCompileAPIVariationsAreSame) { 14130 TEST(PreCompileAPIVariationsAreSame) {
14120 v8::V8::Initialize(); 14131 v8::V8::Initialize();
14121 v8::HandleScope scope(v8::Isolate::GetCurrent()); 14132 v8::HandleScope scope(CcTest::isolate());
14122 14133
14123 const char* cstring = "function foo(a) { return a+1; }"; 14134 const char* cstring = "function foo(a) { return a+1; }";
14124 14135
14125 v8::ScriptData* sd_from_cstring = 14136 v8::ScriptData* sd_from_cstring =
14126 v8::ScriptData::PreCompile(cstring, i::StrLength(cstring)); 14137 v8::ScriptData::PreCompile(cstring, i::StrLength(cstring));
14127 14138
14128 TestAsciiResource* resource = new TestAsciiResource(cstring); 14139 TestAsciiResource* resource = new TestAsciiResource(cstring);
14129 v8::ScriptData* sd_from_external_string = v8::ScriptData::PreCompile( 14140 v8::ScriptData* sd_from_external_string = v8::ScriptData::PreCompile(
14130 v8::String::NewExternal(resource)); 14141 v8::String::NewExternal(resource));
14131 14142
(...skipping 16 matching lines...) Expand all
14148 delete sd_from_string; 14159 delete sd_from_string;
14149 } 14160 }
14150 14161
14151 14162
14152 // This tests that we do not allow dictionary load/call inline caches 14163 // This tests that we do not allow dictionary load/call inline caches
14153 // to use functions that have not yet been compiled. The potential 14164 // to use functions that have not yet been compiled. The potential
14154 // problem of loading a function that has not yet been compiled can 14165 // problem of loading a function that has not yet been compiled can
14155 // arise because we share code between contexts via the compilation 14166 // arise because we share code between contexts via the compilation
14156 // cache. 14167 // cache.
14157 THREADED_TEST(DictionaryICLoadedFunction) { 14168 THREADED_TEST(DictionaryICLoadedFunction) {
14158 v8::HandleScope scope(v8::Isolate::GetCurrent()); 14169 v8::HandleScope scope(CcTest::isolate());
14159 // Test LoadIC. 14170 // Test LoadIC.
14160 for (int i = 0; i < 2; i++) { 14171 for (int i = 0; i < 2; i++) {
14161 LocalContext context; 14172 LocalContext context;
14162 context->Global()->Set(v8_str("tmp"), v8::True()); 14173 context->Global()->Set(v8_str("tmp"), v8::True());
14163 context->Global()->Delete(v8_str("tmp")); 14174 context->Global()->Delete(v8_str("tmp"));
14164 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');"); 14175 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');");
14165 } 14176 }
14166 // Test CallIC. 14177 // Test CallIC.
14167 for (int i = 0; i < 2; i++) { 14178 for (int i = 0; i < 2; i++) {
14168 LocalContext context; 14179 LocalContext context;
14169 context->Global()->Set(v8_str("tmp"), v8::True()); 14180 context->Global()->Set(v8_str("tmp"), v8::True());
14170 context->Global()->Delete(v8_str("tmp")); 14181 context->Global()->Delete(v8_str("tmp"));
14171 CompileRun("for (var j = 0; j < 10; j++) RegExp('')"); 14182 CompileRun("for (var j = 0; j < 10; j++) RegExp('')");
14172 } 14183 }
14173 } 14184 }
14174 14185
14175 14186
14176 // Test that cross-context new calls use the context of the callee to 14187 // Test that cross-context new calls use the context of the callee to
14177 // create the new JavaScript object. 14188 // create the new JavaScript object.
14178 THREADED_TEST(CrossContextNew) { 14189 THREADED_TEST(CrossContextNew) {
14179 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 14190 v8::Isolate* isolate = CcTest::isolate();
14180 v8::HandleScope scope(isolate); 14191 v8::HandleScope scope(isolate);
14181 v8::Local<Context> context0 = Context::New(isolate); 14192 v8::Local<Context> context0 = Context::New(isolate);
14182 v8::Local<Context> context1 = Context::New(isolate); 14193 v8::Local<Context> context1 = Context::New(isolate);
14183 14194
14184 // Allow cross-domain access. 14195 // Allow cross-domain access.
14185 Local<String> token = v8_str("<security token>"); 14196 Local<String> token = v8_str("<security token>");
14186 context0->SetSecurityToken(token); 14197 context0->SetSecurityToken(token);
14187 context1->SetSecurityToken(token); 14198 context1->SetSecurityToken(token);
14188 14199
14189 // Set an 'x' property on the Object prototype and define a 14200 // Set an 'x' property on the Object prototype and define a
(...skipping 21 matching lines...) Expand all
14211 gc_count_ = 0; 14222 gc_count_ = 0;
14212 gc_during_regexp_ = 0; 14223 gc_during_regexp_ = 0;
14213 regexp_success_ = false; 14224 regexp_success_ = false;
14214 gc_success_ = false; 14225 gc_success_ = false;
14215 GCThread gc_thread(this); 14226 GCThread gc_thread(this);
14216 gc_thread.Start(); 14227 gc_thread.Start();
14217 v8::Locker::StartPreemption(1); 14228 v8::Locker::StartPreemption(1);
14218 14229
14219 LongRunningRegExp(); 14230 LongRunningRegExp();
14220 { 14231 {
14221 v8::Unlocker unlock(CcTest::default_isolate()); 14232 v8::Unlocker unlock(CcTest::isolate());
14222 gc_thread.Join(); 14233 gc_thread.Join();
14223 } 14234 }
14224 v8::Locker::StopPreemption(); 14235 v8::Locker::StopPreemption();
14225 CHECK(regexp_success_); 14236 CHECK(regexp_success_);
14226 CHECK(gc_success_); 14237 CHECK(gc_success_);
14227 } 14238 }
14228 14239
14229 private: 14240 private:
14230 // Number of garbage collections required. 14241 // Number of garbage collections required.
14231 static const int kRequiredGCs = 5; 14242 static const int kRequiredGCs = 5;
14232 14243
14233 class GCThread : public i::Thread { 14244 class GCThread : public i::Thread {
14234 public: 14245 public:
14235 explicit GCThread(RegExpInterruptTest* test) 14246 explicit GCThread(RegExpInterruptTest* test)
14236 : Thread("GCThread"), test_(test) {} 14247 : Thread("GCThread"), test_(test) {}
14237 virtual void Run() { 14248 virtual void Run() {
14238 test_->CollectGarbage(); 14249 test_->CollectGarbage();
14239 } 14250 }
14240 private: 14251 private:
14241 RegExpInterruptTest* test_; 14252 RegExpInterruptTest* test_;
14242 }; 14253 };
14243 14254
14244 void CollectGarbage() { 14255 void CollectGarbage() {
14245 block_.Wait(); 14256 block_.Wait();
14246 while (gc_during_regexp_ < kRequiredGCs) { 14257 while (gc_during_regexp_ < kRequiredGCs) {
14247 { 14258 {
14248 v8::Locker lock(CcTest::default_isolate()); 14259 v8::Locker lock(CcTest::isolate());
14249 // TODO(lrn): Perhaps create some garbage before collecting. 14260 // TODO(lrn): Perhaps create some garbage before collecting.
14250 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 14261 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
14251 gc_count_++; 14262 gc_count_++;
14252 } 14263 }
14253 i::OS::Sleep(1); 14264 i::OS::Sleep(1);
14254 } 14265 }
14255 gc_success_ = true; 14266 gc_success_ = true;
14256 } 14267 }
14257 14268
14258 void LongRunningRegExp() { 14269 void LongRunningRegExp() {
14259 block_.Signal(); // Enable garbage collection thread on next preemption. 14270 block_.Signal(); // Enable garbage collection thread on next preemption.
14260 int rounds = 0; 14271 int rounds = 0;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
14297 i::Semaphore block_; 14308 i::Semaphore block_;
14298 int gc_count_; 14309 int gc_count_;
14299 int gc_during_regexp_; 14310 int gc_during_regexp_;
14300 bool regexp_success_; 14311 bool regexp_success_;
14301 bool gc_success_; 14312 bool gc_success_;
14302 }; 14313 };
14303 14314
14304 14315
14305 // Test that a regular expression execution can be interrupted and 14316 // Test that a regular expression execution can be interrupted and
14306 // survive a garbage collection. 14317 // survive a garbage collection.
14307 TEST(RegExpInterruption) { 14318 UNINITIALIZED_TEST(RegExpInterruption) {
14308 v8::Locker lock(CcTest::default_isolate()); 14319 v8::Locker lock(CcTest::isolate());
14309 v8::V8::Initialize(); 14320 v8::V8::Initialize();
14310 v8::HandleScope scope(CcTest::default_isolate()); 14321 v8::HandleScope scope(CcTest::isolate());
14311 Local<Context> local_env; 14322 Local<Context> local_env;
14312 { 14323 {
14313 LocalContext env; 14324 LocalContext env;
14314 local_env = env.local(); 14325 local_env = env.local();
14315 } 14326 }
14316 14327
14317 // Local context should still be live. 14328 // Local context should still be live.
14318 CHECK(!local_env.IsEmpty()); 14329 CHECK(!local_env.IsEmpty());
14319 local_env->Enter(); 14330 local_env->Enter();
14320 14331
(...skipping 12 matching lines...) Expand all
14333 gc_count_ = 0; 14344 gc_count_ = 0;
14334 gc_during_apply_ = 0; 14345 gc_during_apply_ = 0;
14335 apply_success_ = false; 14346 apply_success_ = false;
14336 gc_success_ = false; 14347 gc_success_ = false;
14337 GCThread gc_thread(this); 14348 GCThread gc_thread(this);
14338 gc_thread.Start(); 14349 gc_thread.Start();
14339 v8::Locker::StartPreemption(1); 14350 v8::Locker::StartPreemption(1);
14340 14351
14341 LongRunningApply(); 14352 LongRunningApply();
14342 { 14353 {
14343 v8::Unlocker unlock(CcTest::default_isolate()); 14354 v8::Unlocker unlock(CcTest::isolate());
14344 gc_thread.Join(); 14355 gc_thread.Join();
14345 } 14356 }
14346 v8::Locker::StopPreemption(); 14357 v8::Locker::StopPreemption();
14347 CHECK(apply_success_); 14358 CHECK(apply_success_);
14348 CHECK(gc_success_); 14359 CHECK(gc_success_);
14349 } 14360 }
14350 14361
14351 private: 14362 private:
14352 // Number of garbage collections required. 14363 // Number of garbage collections required.
14353 static const int kRequiredGCs = 2; 14364 static const int kRequiredGCs = 2;
14354 14365
14355 class GCThread : public i::Thread { 14366 class GCThread : public i::Thread {
14356 public: 14367 public:
14357 explicit GCThread(ApplyInterruptTest* test) 14368 explicit GCThread(ApplyInterruptTest* test)
14358 : Thread("GCThread"), test_(test) {} 14369 : Thread("GCThread"), test_(test) {}
14359 virtual void Run() { 14370 virtual void Run() {
14360 test_->CollectGarbage(); 14371 test_->CollectGarbage();
14361 } 14372 }
14362 private: 14373 private:
14363 ApplyInterruptTest* test_; 14374 ApplyInterruptTest* test_;
14364 }; 14375 };
14365 14376
14366 void CollectGarbage() { 14377 void CollectGarbage() {
14367 block_.Wait(); 14378 block_.Wait();
14368 while (gc_during_apply_ < kRequiredGCs) { 14379 while (gc_during_apply_ < kRequiredGCs) {
14369 { 14380 {
14370 v8::Locker lock(CcTest::default_isolate()); 14381 v8::Locker lock(CcTest::isolate());
14371 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 14382 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
14372 gc_count_++; 14383 gc_count_++;
14373 } 14384 }
14374 i::OS::Sleep(1); 14385 i::OS::Sleep(1);
14375 } 14386 }
14376 gc_success_ = true; 14387 gc_success_ = true;
14377 } 14388 }
14378 14389
14379 void LongRunningApply() { 14390 void LongRunningApply() {
14380 block_.Signal(); 14391 block_.Signal();
14381 int rounds = 0; 14392 int rounds = 0;
(...skipping 23 matching lines...) Expand all
14405 i::Semaphore block_; 14416 i::Semaphore block_;
14406 int gc_count_; 14417 int gc_count_;
14407 int gc_during_apply_; 14418 int gc_during_apply_;
14408 bool apply_success_; 14419 bool apply_success_;
14409 bool gc_success_; 14420 bool gc_success_;
14410 }; 14421 };
14411 14422
14412 14423
14413 // Test that nothing bad happens if we get a preemption just when we were 14424 // Test that nothing bad happens if we get a preemption just when we were
14414 // about to do an apply(). 14425 // about to do an apply().
14415 TEST(ApplyInterruption) { 14426 UNINITIALIZED_TEST(ApplyInterruption) {
14416 v8::Locker lock(CcTest::default_isolate()); 14427 v8::Locker lock(CcTest::isolate());
14417 v8::V8::Initialize(); 14428 v8::V8::Initialize();
14418 v8::HandleScope scope(CcTest::default_isolate()); 14429 v8::HandleScope scope(CcTest::isolate());
14419 Local<Context> local_env; 14430 Local<Context> local_env;
14420 { 14431 {
14421 LocalContext env; 14432 LocalContext env;
14422 local_env = env.local(); 14433 local_env = env.local();
14423 } 14434 }
14424 14435
14425 // Local context should still be live. 14436 // Local context should still be live.
14426 CHECK(!local_env.IsEmpty()); 14437 CHECK(!local_env.IsEmpty());
14427 local_env->Enter(); 14438 local_env->Enter();
14428 14439
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
14490 i::Vector<const i::uc16> data_; 14501 i::Vector<const i::uc16> data_;
14491 }; 14502 };
14492 14503
14493 14504
14494 static void MorphAString(i::String* string, 14505 static void MorphAString(i::String* string,
14495 AsciiVectorResource* ascii_resource, 14506 AsciiVectorResource* ascii_resource,
14496 UC16VectorResource* uc16_resource) { 14507 UC16VectorResource* uc16_resource) {
14497 CHECK(i::StringShape(string).IsExternal()); 14508 CHECK(i::StringShape(string).IsExternal());
14498 if (string->IsOneByteRepresentation()) { 14509 if (string->IsOneByteRepresentation()) {
14499 // Check old map is not internalized or long. 14510 // Check old map is not internalized or long.
14500 CHECK(string->map() == HEAP->external_ascii_string_map()); 14511 CHECK(string->map() == CcTest::heap()->external_ascii_string_map());
14501 // Morph external string to be TwoByte string. 14512 // Morph external string to be TwoByte string.
14502 string->set_map(HEAP->external_string_map()); 14513 string->set_map(CcTest::heap()->external_string_map());
14503 i::ExternalTwoByteString* morphed = 14514 i::ExternalTwoByteString* morphed =
14504 i::ExternalTwoByteString::cast(string); 14515 i::ExternalTwoByteString::cast(string);
14505 morphed->set_resource(uc16_resource); 14516 morphed->set_resource(uc16_resource);
14506 } else { 14517 } else {
14507 // Check old map is not internalized or long. 14518 // Check old map is not internalized or long.
14508 CHECK(string->map() == HEAP->external_string_map()); 14519 CHECK(string->map() == CcTest::heap()->external_string_map());
14509 // Morph external string to be ASCII string. 14520 // Morph external string to be ASCII string.
14510 string->set_map(HEAP->external_ascii_string_map()); 14521 string->set_map(CcTest::heap()->external_ascii_string_map());
14511 i::ExternalAsciiString* morphed = 14522 i::ExternalAsciiString* morphed =
14512 i::ExternalAsciiString::cast(string); 14523 i::ExternalAsciiString::cast(string);
14513 morphed->set_resource(ascii_resource); 14524 morphed->set_resource(ascii_resource);
14514 } 14525 }
14515 } 14526 }
14516 14527
14517 14528
14518 // Test that we can still flatten a string if the components it is built up 14529 // Test that we can still flatten a string if the components it is built up
14519 // from have been turned into 16 bit strings in the mean time. 14530 // from have been turned into 16 bit strings in the mean time.
14520 THREADED_TEST(MorphCompositeStringTest) { 14531 THREADED_TEST(MorphCompositeStringTest) {
14521 char utf_buffer[129]; 14532 char utf_buffer[129];
14522 const char* c_string = "Now is the time for all good men" 14533 const char* c_string = "Now is the time for all good men"
14523 " to come to the aid of the party"; 14534 " to come to the aid of the party";
14524 uint16_t* two_byte_string = AsciiToTwoByteString(c_string); 14535 uint16_t* two_byte_string = AsciiToTwoByteString(c_string);
14525 { 14536 {
14526 LocalContext env; 14537 LocalContext env;
14527 i::Factory* factory = i::Isolate::Current()->factory(); 14538 i::Factory* factory = CcTest::i_isolate()->factory();
14528 v8::HandleScope scope(env->GetIsolate()); 14539 v8::HandleScope scope(env->GetIsolate());
14529 AsciiVectorResource ascii_resource( 14540 AsciiVectorResource ascii_resource(
14530 i::Vector<const char>(c_string, i::StrLength(c_string))); 14541 i::Vector<const char>(c_string, i::StrLength(c_string)));
14531 UC16VectorResource uc16_resource( 14542 UC16VectorResource uc16_resource(
14532 i::Vector<const uint16_t>(two_byte_string, 14543 i::Vector<const uint16_t>(two_byte_string,
14533 i::StrLength(c_string))); 14544 i::StrLength(c_string)));
14534 14545
14535 Local<String> lhs(v8::Utils::ToLocal( 14546 Local<String> lhs(v8::Utils::ToLocal(
14536 factory->NewExternalStringFromAscii(&ascii_resource))); 14547 factory->NewExternalStringFromAscii(&ascii_resource)));
14537 Local<String> rhs(v8::Utils::ToLocal( 14548 Local<String> rhs(v8::Utils::ToLocal(
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
14615 class RegExpStringModificationTest { 14626 class RegExpStringModificationTest {
14616 public: 14627 public:
14617 RegExpStringModificationTest() 14628 RegExpStringModificationTest()
14618 : block_(0), 14629 : block_(0),
14619 morphs_(0), 14630 morphs_(0),
14620 morphs_during_regexp_(0), 14631 morphs_during_regexp_(0),
14621 ascii_resource_(i::Vector<const char>("aaaaaaaaaaaaaab", 15)), 14632 ascii_resource_(i::Vector<const char>("aaaaaaaaaaaaaab", 15)),
14622 uc16_resource_(i::Vector<const uint16_t>(two_byte_content_, 15)) {} 14633 uc16_resource_(i::Vector<const uint16_t>(two_byte_content_, 15)) {}
14623 ~RegExpStringModificationTest() {} 14634 ~RegExpStringModificationTest() {}
14624 void RunTest() { 14635 void RunTest() {
14625 i::Factory* factory = i::Isolate::Current()->factory(); 14636 i::Factory* factory = CcTest::i_isolate()->factory();
14626 14637
14627 regexp_success_ = false; 14638 regexp_success_ = false;
14628 morph_success_ = false; 14639 morph_success_ = false;
14629 14640
14630 // Initialize the contents of two_byte_content_ to be a uc16 representation 14641 // Initialize the contents of two_byte_content_ to be a uc16 representation
14631 // of "aaaaaaaaaaaaaab". 14642 // of "aaaaaaaaaaaaaab".
14632 for (int i = 0; i < 14; i++) { 14643 for (int i = 0; i < 14; i++) {
14633 two_byte_content_[i] = 'a'; 14644 two_byte_content_[i] = 'a';
14634 } 14645 }
14635 two_byte_content_[14] = 'b'; 14646 two_byte_content_[14] = 'b';
14636 14647
14637 // Create the input string for the regexp - the one we are going to change 14648 // Create the input string for the regexp - the one we are going to change
14638 // properties of. 14649 // properties of.
14639 input_ = factory->NewExternalStringFromAscii(&ascii_resource_); 14650 input_ = factory->NewExternalStringFromAscii(&ascii_resource_);
14640 14651
14641 // Inject the input as a global variable. 14652 // Inject the input as a global variable.
14642 i::Handle<i::String> input_name = 14653 i::Handle<i::String> input_name =
14643 factory->NewStringFromAscii(i::Vector<const char>("input", 5)); 14654 factory->NewStringFromAscii(i::Vector<const char>("input", 5));
14644 i::Isolate::Current()->native_context()->global_object()->SetProperty( 14655 i::JSReceiver::SetProperty(
14645 *input_name, 14656 i::handle(CcTest::i_isolate()->native_context()->global_object()),
14646 *input_, 14657 input_name,
14658 input_,
14647 NONE, 14659 NONE,
14648 i::kNonStrictMode)->ToObjectChecked(); 14660 i::kNonStrictMode);
14649 14661
14650 MorphThread morph_thread(this); 14662 MorphThread morph_thread(this);
14651 morph_thread.Start(); 14663 morph_thread.Start();
14652 v8::Locker::StartPreemption(1); 14664 v8::Locker::StartPreemption(1);
14653 LongRunningRegExp(); 14665 LongRunningRegExp();
14654 { 14666 {
14655 v8::Unlocker unlock(CcTest::default_isolate()); 14667 v8::Unlocker unlock(CcTest::isolate());
14656 morph_thread.Join(); 14668 morph_thread.Join();
14657 } 14669 }
14658 v8::Locker::StopPreemption(); 14670 v8::Locker::StopPreemption();
14659 CHECK(regexp_success_); 14671 CHECK(regexp_success_);
14660 CHECK(morph_success_); 14672 CHECK(morph_success_);
14661 } 14673 }
14662 14674
14663 private: 14675 private:
14664 // Number of string modifications required. 14676 // Number of string modifications required.
14665 static const int kRequiredModifications = 5; 14677 static const int kRequiredModifications = 5;
14666 static const int kMaxModifications = 100; 14678 static const int kMaxModifications = 100;
14667 14679
14668 class MorphThread : public i::Thread { 14680 class MorphThread : public i::Thread {
14669 public: 14681 public:
14670 explicit MorphThread(RegExpStringModificationTest* test) 14682 explicit MorphThread(RegExpStringModificationTest* test)
14671 : Thread("MorphThread"), test_(test) {} 14683 : Thread("MorphThread"), test_(test) {}
14672 virtual void Run() { 14684 virtual void Run() {
14673 test_->MorphString(); 14685 test_->MorphString();
14674 } 14686 }
14675 private: 14687 private:
14676 RegExpStringModificationTest* test_; 14688 RegExpStringModificationTest* test_;
14677 }; 14689 };
14678 14690
14679 void MorphString() { 14691 void MorphString() {
14680 block_.Wait(); 14692 block_.Wait();
14681 while (morphs_during_regexp_ < kRequiredModifications && 14693 while (morphs_during_regexp_ < kRequiredModifications &&
14682 morphs_ < kMaxModifications) { 14694 morphs_ < kMaxModifications) {
14683 { 14695 {
14684 v8::Locker lock(CcTest::default_isolate()); 14696 v8::Locker lock(CcTest::isolate());
14685 // Swap string between ascii and two-byte representation. 14697 // Swap string between ascii and two-byte representation.
14686 i::String* string = *input_; 14698 i::String* string = *input_;
14687 MorphAString(string, &ascii_resource_, &uc16_resource_); 14699 MorphAString(string, &ascii_resource_, &uc16_resource_);
14688 morphs_++; 14700 morphs_++;
14689 } 14701 }
14690 i::OS::Sleep(1); 14702 i::OS::Sleep(1);
14691 } 14703 }
14692 morph_success_ = true; 14704 morph_success_ = true;
14693 } 14705 }
14694 14706
14695 void LongRunningRegExp() { 14707 void LongRunningRegExp() {
14696 block_.Signal(); // Enable morphing thread on next preemption. 14708 block_.Signal(); // Enable morphing thread on next preemption.
14697 while (morphs_during_regexp_ < kRequiredModifications && 14709 while (morphs_during_regexp_ < kRequiredModifications &&
14698 morphs_ < kMaxModifications) { 14710 morphs_ < kMaxModifications) {
14699 int morphs_before = morphs_; 14711 int morphs_before = morphs_;
14700 { 14712 {
14701 v8::HandleScope scope(v8::Isolate::GetCurrent()); 14713 v8::HandleScope scope(CcTest::isolate());
14702 // Match 15-30 "a"'s against 14 and a "b". 14714 // Match 15-30 "a"'s against 14 and a "b".
14703 const char* c_source = 14715 const char* c_source =
14704 "/a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaa/" 14716 "/a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaa/"
14705 ".exec(input) === null"; 14717 ".exec(input) === null";
14706 Local<String> source = String::New(c_source); 14718 Local<String> source = String::New(c_source);
14707 Local<Script> script = Script::Compile(source); 14719 Local<Script> script = Script::Compile(source);
14708 Local<Value> result = script->Run(); 14720 Local<Value> result = script->Run();
14709 CHECK(result->IsTrue()); 14721 CHECK(result->IsTrue());
14710 } 14722 }
14711 int morphs_after = morphs_; 14723 int morphs_after = morphs_;
14712 morphs_during_regexp_ += morphs_after - morphs_before; 14724 morphs_during_regexp_ += morphs_after - morphs_before;
14713 } 14725 }
14714 regexp_success_ = true; 14726 regexp_success_ = true;
14715 } 14727 }
14716 14728
14717 i::uc16 two_byte_content_[15]; 14729 i::uc16 two_byte_content_[15];
14718 i::Semaphore block_; 14730 i::Semaphore block_;
14719 int morphs_; 14731 int morphs_;
14720 int morphs_during_regexp_; 14732 int morphs_during_regexp_;
14721 bool regexp_success_; 14733 bool regexp_success_;
14722 bool morph_success_; 14734 bool morph_success_;
14723 i::Handle<i::String> input_; 14735 i::Handle<i::String> input_;
14724 AsciiVectorResource ascii_resource_; 14736 AsciiVectorResource ascii_resource_;
14725 UC16VectorResource uc16_resource_; 14737 UC16VectorResource uc16_resource_;
14726 }; 14738 };
14727 14739
14728 14740
14729 // Test that a regular expression execution can be interrupted and 14741 // Test that a regular expression execution can be interrupted and
14730 // the string changed without failing. 14742 // the string changed without failing.
14731 TEST(RegExpStringModification) { 14743 UNINITIALIZED_TEST(RegExpStringModification) {
14732 v8::Locker lock(CcTest::default_isolate()); 14744 v8::Locker lock(CcTest::isolate());
14733 v8::V8::Initialize(); 14745 v8::V8::Initialize();
14734 v8::HandleScope scope(CcTest::default_isolate()); 14746 v8::HandleScope scope(CcTest::isolate());
14735 Local<Context> local_env; 14747 Local<Context> local_env;
14736 { 14748 {
14737 LocalContext env; 14749 LocalContext env;
14738 local_env = env.local(); 14750 local_env = env.local();
14739 } 14751 }
14740 14752
14741 // Local context should still be live. 14753 // Local context should still be live.
14742 CHECK(!local_env.IsEmpty()); 14754 CHECK(!local_env.IsEmpty());
14743 local_env->Enter(); 14755 local_env->Enter();
14744 14756
14745 // Should complete without problems. 14757 // Should complete without problems.
14746 RegExpStringModificationTest().RunTest(); 14758 RegExpStringModificationTest().RunTest();
14747 14759
14748 local_env->Exit(); 14760 local_env->Exit();
14749 } 14761 }
14750 14762
14751 14763
14752 // Test that we cannot set a property on the global object if there 14764 // Test that we cannot set a property on the global object if there
14753 // is a read-only property in the prototype chain. 14765 // is a read-only property in the prototype chain.
14754 TEST(ReadOnlyPropertyInGlobalProto) { 14766 TEST(ReadOnlyPropertyInGlobalProto) {
14755 i::FLAG_es5_readonly = true; 14767 i::FLAG_es5_readonly = true;
14756 v8::HandleScope scope(v8::Isolate::GetCurrent()); 14768 v8::HandleScope scope(CcTest::isolate());
14757 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 14769 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
14758 LocalContext context(0, templ); 14770 LocalContext context(0, templ);
14759 v8::Handle<v8::Object> global = context->Global(); 14771 v8::Handle<v8::Object> global = context->Global();
14760 v8::Handle<v8::Object> global_proto = 14772 v8::Handle<v8::Object> global_proto =
14761 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__"))); 14773 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__")));
14762 global_proto->Set(v8_str("x"), v8::Integer::New(0), v8::ReadOnly); 14774 global_proto->Set(v8_str("x"), v8::Integer::New(0), v8::ReadOnly);
14763 global_proto->Set(v8_str("y"), v8::Integer::New(0), v8::ReadOnly); 14775 global_proto->Set(v8_str("y"), v8::Integer::New(0), v8::ReadOnly);
14764 // Check without 'eval' or 'with'. 14776 // Check without 'eval' or 'with'.
14765 v8::Handle<v8::Value> res = 14777 v8::Handle<v8::Value> res =
14766 CompileRun("function f() { x = 42; return x; }; f()"); 14778 CompileRun("function f() { x = 42; return x; }; f()");
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
14799 force_set_set_count++; 14811 force_set_set_count++;
14800 info.GetReturnValue().SetUndefined(); 14812 info.GetReturnValue().SetUndefined();
14801 } 14813 }
14802 14814
14803 14815
14804 TEST(ForceSet) { 14816 TEST(ForceSet) {
14805 force_set_get_count = 0; 14817 force_set_get_count = 0;
14806 force_set_set_count = 0; 14818 force_set_set_count = 0;
14807 pass_on_get = false; 14819 pass_on_get = false;
14808 14820
14809 v8::HandleScope scope(v8::Isolate::GetCurrent()); 14821 v8::HandleScope scope(CcTest::isolate());
14810 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 14822 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
14811 v8::Handle<v8::String> access_property = v8::String::New("a"); 14823 v8::Handle<v8::String> access_property = v8::String::New("a");
14812 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter); 14824 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter);
14813 LocalContext context(NULL, templ); 14825 LocalContext context(NULL, templ);
14814 v8::Handle<v8::Object> global = context->Global(); 14826 v8::Handle<v8::Object> global = context->Global();
14815 14827
14816 // Ordinary properties 14828 // Ordinary properties
14817 v8::Handle<v8::String> simple_property = v8::String::New("p"); 14829 v8::Handle<v8::String> simple_property = v8::String::New("p");
14818 global->Set(simple_property, v8::Int32::New(4), v8::ReadOnly); 14830 global->Set(simple_property, v8::Int32::New(4), v8::ReadOnly);
14819 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 14831 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
(...skipping 21 matching lines...) Expand all
14841 CHECK_EQ(1, force_set_set_count); 14853 CHECK_EQ(1, force_set_set_count);
14842 CHECK_EQ(2, force_set_get_count); 14854 CHECK_EQ(2, force_set_get_count);
14843 } 14855 }
14844 14856
14845 14857
14846 TEST(ForceSetWithInterceptor) { 14858 TEST(ForceSetWithInterceptor) {
14847 force_set_get_count = 0; 14859 force_set_get_count = 0;
14848 force_set_set_count = 0; 14860 force_set_set_count = 0;
14849 pass_on_get = false; 14861 pass_on_get = false;
14850 14862
14851 v8::HandleScope scope(v8::Isolate::GetCurrent()); 14863 v8::HandleScope scope(CcTest::isolate());
14852 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 14864 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
14853 templ->SetNamedPropertyHandler(ForceSetGetter, ForceSetInterceptSetter); 14865 templ->SetNamedPropertyHandler(ForceSetGetter, ForceSetInterceptSetter);
14854 LocalContext context(NULL, templ); 14866 LocalContext context(NULL, templ);
14855 v8::Handle<v8::Object> global = context->Global(); 14867 v8::Handle<v8::Object> global = context->Global();
14856 14868
14857 v8::Handle<v8::String> some_property = v8::String::New("a"); 14869 v8::Handle<v8::String> some_property = v8::String::New("a");
14858 CHECK_EQ(0, force_set_set_count); 14870 CHECK_EQ(0, force_set_set_count);
14859 CHECK_EQ(0, force_set_get_count); 14871 CHECK_EQ(0, force_set_get_count);
14860 CHECK_EQ(3, global->Get(some_property)->Int32Value()); 14872 CHECK_EQ(3, global->Get(some_property)->Int32Value());
14861 // Setting the property shouldn't override it, just call the setter 14873 // Setting the property shouldn't override it, just call the setter
(...skipping 22 matching lines...) Expand all
14884 CHECK_EQ(1, force_set_set_count); 14896 CHECK_EQ(1, force_set_set_count);
14885 CHECK_EQ(5, force_set_get_count); 14897 CHECK_EQ(5, force_set_get_count);
14886 // The interceptor should also work for other properties 14898 // The interceptor should also work for other properties
14887 CHECK_EQ(3, global->Get(v8::String::New("b"))->Int32Value()); 14899 CHECK_EQ(3, global->Get(v8::String::New("b"))->Int32Value());
14888 CHECK_EQ(1, force_set_set_count); 14900 CHECK_EQ(1, force_set_set_count);
14889 CHECK_EQ(6, force_set_get_count); 14901 CHECK_EQ(6, force_set_get_count);
14890 } 14902 }
14891 14903
14892 14904
14893 THREADED_TEST(ForceDelete) { 14905 THREADED_TEST(ForceDelete) {
14894 v8::HandleScope scope(v8::Isolate::GetCurrent()); 14906 v8::HandleScope scope(CcTest::isolate());
14895 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 14907 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
14896 LocalContext context(NULL, templ); 14908 LocalContext context(NULL, templ);
14897 v8::Handle<v8::Object> global = context->Global(); 14909 v8::Handle<v8::Object> global = context->Global();
14898 14910
14899 // Ordinary properties 14911 // Ordinary properties
14900 v8::Handle<v8::String> simple_property = v8::String::New("p"); 14912 v8::Handle<v8::String> simple_property = v8::String::New("p");
14901 global->Set(simple_property, v8::Int32::New(4), v8::DontDelete); 14913 global->Set(simple_property, v8::Int32::New(4), v8::DontDelete);
14902 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 14914 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
14903 // This should fail because the property is dont-delete. 14915 // This should fail because the property is dont-delete.
14904 CHECK(!global->Delete(simple_property)); 14916 CHECK(!global->Delete(simple_property));
(...skipping 14 matching lines...) Expand all
14919 force_delete_interceptor_count++; 14931 force_delete_interceptor_count++;
14920 if (pass_on_delete) return; 14932 if (pass_on_delete) return;
14921 info.GetReturnValue().Set(true); 14933 info.GetReturnValue().Set(true);
14922 } 14934 }
14923 14935
14924 14936
14925 THREADED_TEST(ForceDeleteWithInterceptor) { 14937 THREADED_TEST(ForceDeleteWithInterceptor) {
14926 force_delete_interceptor_count = 0; 14938 force_delete_interceptor_count = 0;
14927 pass_on_delete = false; 14939 pass_on_delete = false;
14928 14940
14929 v8::HandleScope scope(v8::Isolate::GetCurrent()); 14941 v8::HandleScope scope(CcTest::isolate());
14930 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 14942 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
14931 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter); 14943 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter);
14932 LocalContext context(NULL, templ); 14944 LocalContext context(NULL, templ);
14933 v8::Handle<v8::Object> global = context->Global(); 14945 v8::Handle<v8::Object> global = context->Global();
14934 14946
14935 v8::Handle<v8::String> some_property = v8::String::New("a"); 14947 v8::Handle<v8::String> some_property = v8::String::New("a");
14936 global->Set(some_property, v8::Integer::New(42), v8::DontDelete); 14948 global->Set(some_property, v8::Integer::New(42), v8::DontDelete);
14937 14949
14938 // Deleting a property should get intercepted and nothing should 14950 // Deleting a property should get intercepted and nothing should
14939 // happen. 14951 // happen.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
14972 CHECK(context->Global()->ForceDelete(v8_str("foo"))); 14984 CHECK(context->Global()->ForceDelete(v8_str("foo")));
14973 // Make sure the value for foo is read from the prototype, and that 14985 // Make sure the value for foo is read from the prototype, and that
14974 // we don't get in trouble with reading the deleted cell value 14986 // we don't get in trouble with reading the deleted cell value
14975 // sentinel. 14987 // sentinel.
14976 CHECK_EQ(5, CompileRun("f()")->Int32Value()); 14988 CHECK_EQ(5, CompileRun("f()")->Int32Value());
14977 } 14989 }
14978 14990
14979 14991
14980 TEST(InlinedFunctionAcrossContexts) { 14992 TEST(InlinedFunctionAcrossContexts) {
14981 i::FLAG_allow_natives_syntax = true; 14993 i::FLAG_allow_natives_syntax = true;
14982 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 14994 v8::Isolate* isolate = CcTest::isolate();
14983 v8::HandleScope outer_scope(isolate); 14995 v8::HandleScope outer_scope(isolate);
14984 v8::Local<v8::Context> ctx1 = v8::Context::New(isolate); 14996 v8::Local<v8::Context> ctx1 = v8::Context::New(isolate);
14985 v8::Local<v8::Context> ctx2 = v8::Context::New(isolate); 14997 v8::Local<v8::Context> ctx2 = v8::Context::New(isolate);
14986 ctx1->Enter(); 14998 ctx1->Enter();
14987 14999
14988 { 15000 {
14989 v8::HandleScope inner_scope(v8::Isolate::GetCurrent()); 15001 v8::HandleScope inner_scope(CcTest::isolate());
14990 CompileRun("var G = 42; function foo() { return G; }"); 15002 CompileRun("var G = 42; function foo() { return G; }");
14991 v8::Local<v8::Value> foo = ctx1->Global()->Get(v8_str("foo")); 15003 v8::Local<v8::Value> foo = ctx1->Global()->Get(v8_str("foo"));
14992 ctx2->Enter(); 15004 ctx2->Enter();
14993 ctx2->Global()->Set(v8_str("o"), foo); 15005 ctx2->Global()->Set(v8_str("o"), foo);
14994 v8::Local<v8::Value> res = CompileRun( 15006 v8::Local<v8::Value> res = CompileRun(
14995 "function f() { return o(); }" 15007 "function f() { return o(); }"
14996 "for (var i = 0; i < 10; ++i) f();" 15008 "for (var i = 0; i < 10; ++i) f();"
14997 "%OptimizeFunctionOnNextCall(f);" 15009 "%OptimizeFunctionOnNextCall(f);"
14998 "f();"); 15010 "f();");
14999 CHECK_EQ(42, res->Int32Value()); 15011 CHECK_EQ(42, res->Int32Value());
(...skipping 29 matching lines...) Expand all
15029 ApiTestFuzzer::Fuzz(); 15041 ApiTestFuzzer::Fuzz();
15030 CHECK(Context::GetCurrent() == calling_context0); 15042 CHECK(Context::GetCurrent() == calling_context0);
15031 CHECK(args.GetIsolate()->GetCurrentContext() == calling_context0); 15043 CHECK(args.GetIsolate()->GetCurrentContext() == calling_context0);
15032 CHECK(Context::GetCalling() == calling_context1); 15044 CHECK(Context::GetCalling() == calling_context1);
15033 CHECK(Context::GetEntered() == calling_context2); 15045 CHECK(Context::GetEntered() == calling_context2);
15034 args.GetReturnValue().Set(42); 15046 args.GetReturnValue().Set(42);
15035 } 15047 }
15036 15048
15037 15049
15038 THREADED_TEST(GetCurrentContextWhenNotInContext) { 15050 THREADED_TEST(GetCurrentContextWhenNotInContext) {
15039 i::Isolate* isolate = i::Isolate::Current(); 15051 i::Isolate* isolate = CcTest::i_isolate();
15040 CHECK(isolate != NULL); 15052 CHECK(isolate != NULL);
15041 CHECK(isolate->context() == NULL); 15053 CHECK(isolate->context() == NULL);
15042 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); 15054 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
15043 v8::HandleScope scope(v8_isolate); 15055 v8::HandleScope scope(v8_isolate);
15044 // The following should not crash, but return an empty handle. 15056 // The following should not crash, but return an empty handle.
15045 v8::Local<v8::Context> current = v8_isolate->GetCurrentContext(); 15057 v8::Local<v8::Context> current = v8_isolate->GetCurrentContext();
15046 CHECK(current.IsEmpty()); 15058 CHECK(current.IsEmpty());
15047 } 15059 }
15048 15060
15049 15061
15050 THREADED_TEST(GetCallingContext) { 15062 THREADED_TEST(GetCallingContext) {
15051 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 15063 v8::Isolate* isolate = CcTest::isolate();
15052 v8::HandleScope scope(isolate); 15064 v8::HandleScope scope(isolate);
15053 15065
15054 Local<Context> calling_context0(Context::New(isolate)); 15066 Local<Context> calling_context0(Context::New(isolate));
15055 Local<Context> calling_context1(Context::New(isolate)); 15067 Local<Context> calling_context1(Context::New(isolate));
15056 Local<Context> calling_context2(Context::New(isolate)); 15068 Local<Context> calling_context2(Context::New(isolate));
15057 ::calling_context0 = calling_context0; 15069 ::calling_context0 = calling_context0;
15058 ::calling_context1 = calling_context1; 15070 ::calling_context1 = calling_context1;
15059 ::calling_context2 = calling_context2; 15071 ::calling_context2 = calling_context2;
15060 15072
15061 // Allow cross-domain access. 15073 // Allow cross-domain access.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
15146 int expected, 15158 int expected,
15147 i::Handle<i::Object> obj, 15159 i::Handle<i::Object> obj,
15148 int offset) { 15160 int offset) {
15149 i::Object* element = obj->GetElement(isolate, offset)->ToObjectChecked(); 15161 i::Object* element = obj->GetElement(isolate, offset)->ToObjectChecked();
15150 CHECK_EQ(expected, i::Smi::cast(element)->value()); 15162 CHECK_EQ(expected, i::Smi::cast(element)->value());
15151 } 15163 }
15152 15164
15153 15165
15154 THREADED_TEST(PixelArray) { 15166 THREADED_TEST(PixelArray) {
15155 LocalContext context; 15167 LocalContext context;
15156 i::Isolate* isolate = i::Isolate::Current(); 15168 i::Isolate* isolate = CcTest::i_isolate();
15157 i::Factory* factory = isolate->factory(); 15169 i::Factory* factory = isolate->factory();
15158 v8::HandleScope scope(context->GetIsolate()); 15170 v8::HandleScope scope(context->GetIsolate());
15159 const int kElementCount = 260; 15171 const int kElementCount = 260;
15160 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); 15172 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
15161 i::Handle<i::ExternalPixelArray> pixels = 15173 i::Handle<i::ExternalPixelArray> pixels =
15162 i::Handle<i::ExternalPixelArray>::cast( 15174 i::Handle<i::ExternalPixelArray>::cast(
15163 factory->NewExternalArray(kElementCount, 15175 factory->NewExternalArray(kElementCount,
15164 v8::kExternalPixelArray, 15176 v8::kExternalPixelArray,
15165 pixel_data)); 15177 pixel_data));
15166 // Force GC to trigger verification. 15178 // Force GC to trigger verification.
15167 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 15179 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
15168 for (int i = 0; i < kElementCount; i++) { 15180 for (int i = 0; i < kElementCount; i++) {
15169 pixels->set(i, i % 256); 15181 pixels->set(i, i % 256);
15170 } 15182 }
15171 // Force GC to trigger verification. 15183 // Force GC to trigger verification.
15172 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 15184 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
15173 for (int i = 0; i < kElementCount; i++) { 15185 for (int i = 0; i < kElementCount; i++) {
15174 CHECK_EQ(i % 256, pixels->get_scalar(i)); 15186 CHECK_EQ(i % 256, pixels->get_scalar(i));
15175 CHECK_EQ(i % 256, pixel_data[i]); 15187 CHECK_EQ(i % 256, pixel_data[i]);
15176 } 15188 }
15177 15189
15178 v8::Handle<v8::Object> obj = v8::Object::New(); 15190 v8::Handle<v8::Object> obj = v8::Object::New();
15179 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); 15191 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj);
15180 // Set the elements to be the pixels. 15192 // Set the elements to be the pixels.
15181 // jsobj->set_elements(*pixels); 15193 // jsobj->set_elements(*pixels);
15182 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); 15194 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount);
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
15560 static void NotHandledIndexedPropertySetter( 15572 static void NotHandledIndexedPropertySetter(
15561 uint32_t index, 15573 uint32_t index,
15562 Local<Value> value, 15574 Local<Value> value,
15563 const v8::PropertyCallbackInfo<v8::Value>& info) { 15575 const v8::PropertyCallbackInfo<v8::Value>& info) {
15564 ApiTestFuzzer::Fuzz(); 15576 ApiTestFuzzer::Fuzz();
15565 } 15577 }
15566 15578
15567 15579
15568 THREADED_TEST(PixelArrayWithInterceptor) { 15580 THREADED_TEST(PixelArrayWithInterceptor) {
15569 LocalContext context; 15581 LocalContext context;
15570 i::Factory* factory = i::Isolate::Current()->factory(); 15582 i::Factory* factory = CcTest::i_isolate()->factory();
15571 v8::HandleScope scope(context->GetIsolate()); 15583 v8::HandleScope scope(context->GetIsolate());
15572 const int kElementCount = 260; 15584 const int kElementCount = 260;
15573 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); 15585 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
15574 i::Handle<i::ExternalPixelArray> pixels = 15586 i::Handle<i::ExternalPixelArray> pixels =
15575 i::Handle<i::ExternalPixelArray>::cast( 15587 i::Handle<i::ExternalPixelArray>::cast(
15576 factory->NewExternalArray(kElementCount, 15588 factory->NewExternalArray(kElementCount,
15577 v8::kExternalPixelArray, 15589 v8::kExternalPixelArray,
15578 pixel_data)); 15590 pixel_data));
15579 for (int i = 0; i < kElementCount; i++) { 15591 for (int i = 0; i < kElementCount; i++) {
15580 pixels->set(i, i % 256); 15592 pixels->set(i, i % 256);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
15733 "var sum = 0;" 15745 "var sum = 0;"
15734 "for (var i = 0; i < 8; i++) {" 15746 "for (var i = 0; i < 8; i++) {"
15735 " tmp_array[i] = i;" 15747 " tmp_array[i] = i;"
15736 " sum += tmp_array[i];" 15748 " sum += tmp_array[i];"
15737 " if (i == 4) {" 15749 " if (i == 4) {"
15738 " tmp_array = {};" 15750 " tmp_array = {};"
15739 " }" 15751 " }"
15740 "}" 15752 "}"
15741 "sum;"); 15753 "sum;");
15742 // Force GC to trigger verification. 15754 // Force GC to trigger verification.
15743 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 15755 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
15744 CHECK_EQ(28, result->Int32Value()); 15756 CHECK_EQ(28, result->Int32Value());
15745 15757
15746 // Make sure out-of-range loads do not throw. 15758 // Make sure out-of-range loads do not throw.
15747 i::OS::SNPrintF(test_buf, 15759 i::OS::SNPrintF(test_buf,
15748 "var caught_exception = false;" 15760 "var caught_exception = false;"
15749 "try {" 15761 "try {"
15750 " ext_array[%d];" 15762 " ext_array[%d];"
15751 "} catch (e) {" 15763 "} catch (e) {"
15752 " caught_exception = true;" 15764 " caught_exception = true;"
15753 "}" 15765 "}"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
15926 result = CompileRun("ext_array[1] = 23;"); 15938 result = CompileRun("ext_array[1] = 23;");
15927 CHECK_EQ(23, result->Int32Value()); 15939 CHECK_EQ(23, result->Int32Value());
15928 } 15940 }
15929 15941
15930 15942
15931 template <class ExternalArrayClass, class ElementType> 15943 template <class ExternalArrayClass, class ElementType>
15932 static void ExternalArrayTestHelper(v8::ExternalArrayType array_type, 15944 static void ExternalArrayTestHelper(v8::ExternalArrayType array_type,
15933 int64_t low, 15945 int64_t low,
15934 int64_t high) { 15946 int64_t high) {
15935 LocalContext context; 15947 LocalContext context;
15936 i::Isolate* isolate = i::Isolate::Current(); 15948 i::Isolate* isolate = CcTest::i_isolate();
15937 i::Factory* factory = isolate->factory(); 15949 i::Factory* factory = isolate->factory();
15938 v8::HandleScope scope(context->GetIsolate()); 15950 v8::HandleScope scope(context->GetIsolate());
15939 const int kElementCount = 40; 15951 const int kElementCount = 40;
15940 int element_size = ExternalArrayElementSize(array_type); 15952 int element_size = ExternalArrayElementSize(array_type);
15941 ElementType* array_data = 15953 ElementType* array_data =
15942 static_cast<ElementType*>(malloc(kElementCount * element_size)); 15954 static_cast<ElementType*>(malloc(kElementCount * element_size));
15943 i::Handle<ExternalArrayClass> array = 15955 i::Handle<ExternalArrayClass> array =
15944 i::Handle<ExternalArrayClass>::cast( 15956 i::Handle<ExternalArrayClass>::cast(
15945 factory->NewExternalArray(kElementCount, array_type, array_data)); 15957 factory->NewExternalArray(kElementCount, array_type, array_data));
15946 // Force GC to trigger verification. 15958 // Force GC to trigger verification.
15947 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 15959 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
15948 for (int i = 0; i < kElementCount; i++) { 15960 for (int i = 0; i < kElementCount; i++) {
15949 array->set(i, static_cast<ElementType>(i)); 15961 array->set(i, static_cast<ElementType>(i));
15950 } 15962 }
15951 // Force GC to trigger verification. 15963 // Force GC to trigger verification.
15952 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 15964 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
15953 for (int i = 0; i < kElementCount; i++) { 15965 for (int i = 0; i < kElementCount; i++) {
15954 CHECK_EQ(static_cast<int64_t>(i), 15966 CHECK_EQ(static_cast<int64_t>(i),
15955 static_cast<int64_t>(array->get_scalar(i))); 15967 static_cast<int64_t>(array->get_scalar(i)));
15956 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(array_data[i])); 15968 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(array_data[i]));
15957 } 15969 }
15958 15970
15959 v8::Handle<v8::Object> obj = v8::Object::New(); 15971 v8::Handle<v8::Object> obj = v8::Object::New();
15960 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); 15972 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj);
15961 // Set the elements to be the external array. 15973 // Set the elements to be the external array.
15962 obj->SetIndexedPropertiesToExternalArrayData(array_data, 15974 obj->SetIndexedPropertiesToExternalArrayData(array_data,
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
16453 v8::String::Utf8Value stack(try_catch.StackTrace()); 16465 v8::String::Utf8Value stack(try_catch.StackTrace());
16454 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); 16466 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL);
16455 } 16467 }
16456 16468
16457 16469
16458 // Checks that a StackFrame has certain expected values. 16470 // Checks that a StackFrame has certain expected values.
16459 void checkStackFrame(const char* expected_script_name, 16471 void checkStackFrame(const char* expected_script_name,
16460 const char* expected_func_name, int expected_line_number, 16472 const char* expected_func_name, int expected_line_number,
16461 int expected_column, bool is_eval, bool is_constructor, 16473 int expected_column, bool is_eval, bool is_constructor,
16462 v8::Handle<v8::StackFrame> frame) { 16474 v8::Handle<v8::StackFrame> frame) {
16463 v8::HandleScope scope(v8::Isolate::GetCurrent()); 16475 v8::HandleScope scope(CcTest::isolate());
16464 v8::String::Utf8Value func_name(frame->GetFunctionName()); 16476 v8::String::Utf8Value func_name(frame->GetFunctionName());
16465 v8::String::Utf8Value script_name(frame->GetScriptName()); 16477 v8::String::Utf8Value script_name(frame->GetScriptName());
16466 if (*script_name == NULL) { 16478 if (*script_name == NULL) {
16467 // The situation where there is no associated script, like for evals. 16479 // The situation where there is no associated script, like for evals.
16468 CHECK(expected_script_name == NULL); 16480 CHECK(expected_script_name == NULL);
16469 } else { 16481 } else {
16470 CHECK(strstr(*script_name, expected_script_name) != NULL); 16482 CHECK(strstr(*script_name, expected_script_name) != NULL);
16471 } 16483 }
16472 CHECK(strstr(*func_name, expected_func_name) != NULL); 16484 CHECK(strstr(*func_name, expected_func_name) != NULL);
16473 CHECK_EQ(expected_line_number, frame->GetLineNumber()); 16485 CHECK_EQ(expected_line_number, frame->GetLineNumber());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
16525 16537
16526 CHECK(stackTrace->AsArray()->IsArray()); 16538 CHECK(stackTrace->AsArray()->IsArray());
16527 } 16539 }
16528 } 16540 }
16529 16541
16530 16542
16531 // Tests the C++ StackTrace API. 16543 // Tests the C++ StackTrace API.
16532 // TODO(3074796): Reenable this as a THREADED_TEST once it passes. 16544 // TODO(3074796): Reenable this as a THREADED_TEST once it passes.
16533 // THREADED_TEST(CaptureStackTrace) { 16545 // THREADED_TEST(CaptureStackTrace) {
16534 TEST(CaptureStackTrace) { 16546 TEST(CaptureStackTrace) {
16535 v8::HandleScope scope(v8::Isolate::GetCurrent()); 16547 v8::HandleScope scope(CcTest::isolate());
16536 v8::Handle<v8::String> origin = v8::String::New("capture-stack-trace-test"); 16548 v8::Handle<v8::String> origin = v8::String::New("capture-stack-trace-test");
16537 Local<ObjectTemplate> templ = ObjectTemplate::New(); 16549 Local<ObjectTemplate> templ = ObjectTemplate::New();
16538 templ->Set(v8_str("AnalyzeStackInNativeCode"), 16550 templ->Set(v8_str("AnalyzeStackInNativeCode"),
16539 v8::FunctionTemplate::New(AnalyzeStackInNativeCode)); 16551 v8::FunctionTemplate::New(AnalyzeStackInNativeCode));
16540 LocalContext context(0, templ); 16552 LocalContext context(0, templ);
16541 16553
16542 // Test getting OVERVIEW information. Should ignore information that is not 16554 // Test getting OVERVIEW information. Should ignore information that is not
16543 // script name, function name, line number, and column offset. 16555 // script name, function name, line number, and column offset.
16544 const char *overview_source = 16556 const char *overview_source =
16545 "function bar() {\n" 16557 "function bar() {\n"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
16774 for (int i = 0; i < 3; i++) { 16786 for (int i = 0; i < 3; i++) {
16775 v8::Handle<v8::String> name = 16787 v8::Handle<v8::String> name =
16776 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 16788 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
16777 CHECK(!name.IsEmpty()); 16789 CHECK(!name.IsEmpty());
16778 CHECK_EQ(url, name); 16790 CHECK_EQ(url, name);
16779 } 16791 }
16780 } 16792 }
16781 16793
16782 16794
16783 TEST(SourceURLInStackTrace) { 16795 TEST(SourceURLInStackTrace) {
16784 v8::HandleScope scope(v8::Isolate::GetCurrent()); 16796 v8::HandleScope scope(CcTest::isolate());
16785 Local<ObjectTemplate> templ = ObjectTemplate::New(); 16797 Local<ObjectTemplate> templ = ObjectTemplate::New();
16786 templ->Set(v8_str("AnalyzeStackOfEvalWithSourceURL"), 16798 templ->Set(v8_str("AnalyzeStackOfEvalWithSourceURL"),
16787 v8::FunctionTemplate::New(AnalyzeStackOfEvalWithSourceURL)); 16799 v8::FunctionTemplate::New(AnalyzeStackOfEvalWithSourceURL));
16788 LocalContext context(0, templ); 16800 LocalContext context(0, templ);
16789 16801
16790 const char *source = 16802 const char *source =
16791 "function outer() {\n" 16803 "function outer() {\n"
16792 "function bar() {\n" 16804 "function bar() {\n"
16793 " AnalyzeStackOfEvalWithSourceURL();\n" 16805 " AnalyzeStackOfEvalWithSourceURL();\n"
16794 "}\n" 16806 "}\n"
(...skipping 21 matching lines...) Expand all
16816 v8::Handle<v8::StackTrace> stackTrace = 16828 v8::Handle<v8::StackTrace> stackTrace =
16817 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kScriptId); 16829 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kScriptId);
16818 CHECK_EQ(2, stackTrace->GetFrameCount()); 16830 CHECK_EQ(2, stackTrace->GetFrameCount());
16819 for (int i = 0; i < 2; i++) { 16831 for (int i = 0; i < 2; i++) {
16820 scriptIdInStack[i] = stackTrace->GetFrame(i)->GetScriptId(); 16832 scriptIdInStack[i] = stackTrace->GetFrame(i)->GetScriptId();
16821 } 16833 }
16822 } 16834 }
16823 16835
16824 16836
16825 TEST(ScriptIdInStackTrace) { 16837 TEST(ScriptIdInStackTrace) {
16826 v8::HandleScope scope(v8::Isolate::GetCurrent()); 16838 v8::HandleScope scope(CcTest::isolate());
16827 Local<ObjectTemplate> templ = ObjectTemplate::New(); 16839 Local<ObjectTemplate> templ = ObjectTemplate::New();
16828 templ->Set(v8_str("AnalyzeScriptIdInStack"), 16840 templ->Set(v8_str("AnalyzeScriptIdInStack"),
16829 v8::FunctionTemplate::New(AnalyzeScriptIdInStack)); 16841 v8::FunctionTemplate::New(AnalyzeScriptIdInStack));
16830 LocalContext context(0, templ); 16842 LocalContext context(0, templ);
16831 16843
16832 v8::Handle<v8::String> scriptSource = v8::String::New( 16844 v8::Handle<v8::String> scriptSource = v8::String::New(
16833 "function foo() {\n" 16845 "function foo() {\n"
16834 " AnalyzeScriptIdInStack();" 16846 " AnalyzeScriptIdInStack();"
16835 "}\n" 16847 "}\n"
16836 "foo();\n"); 16848 "foo();\n");
(...skipping 17 matching lines...) Expand all
16854 for (int i = 0; i < 3; i++) { 16866 for (int i = 0; i < 3; i++) {
16855 v8::Handle<v8::String> name = 16867 v8::Handle<v8::String> name =
16856 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 16868 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
16857 CHECK(!name.IsEmpty()); 16869 CHECK(!name.IsEmpty());
16858 CHECK_EQ(url, name); 16870 CHECK_EQ(url, name);
16859 } 16871 }
16860 } 16872 }
16861 16873
16862 16874
16863 TEST(InlineScriptWithSourceURLInStackTrace) { 16875 TEST(InlineScriptWithSourceURLInStackTrace) {
16864 v8::HandleScope scope(v8::Isolate::GetCurrent()); 16876 v8::HandleScope scope(CcTest::isolate());
16865 Local<ObjectTemplate> templ = ObjectTemplate::New(); 16877 Local<ObjectTemplate> templ = ObjectTemplate::New();
16866 templ->Set(v8_str("AnalyzeStackOfInlineScriptWithSourceURL"), 16878 templ->Set(v8_str("AnalyzeStackOfInlineScriptWithSourceURL"),
16867 v8::FunctionTemplate::New( 16879 v8::FunctionTemplate::New(
16868 AnalyzeStackOfInlineScriptWithSourceURL)); 16880 AnalyzeStackOfInlineScriptWithSourceURL));
16869 LocalContext context(0, templ); 16881 LocalContext context(0, templ);
16870 16882
16871 const char *source = 16883 const char *source =
16872 "function outer() {\n" 16884 "function outer() {\n"
16873 "function bar() {\n" 16885 "function bar() {\n"
16874 " AnalyzeStackOfInlineScriptWithSourceURL();\n" 16886 " AnalyzeStackOfInlineScriptWithSourceURL();\n"
(...skipping 24 matching lines...) Expand all
16899 for (int i = 0; i < 3; i++) { 16911 for (int i = 0; i < 3; i++) {
16900 v8::Handle<v8::String> name = 16912 v8::Handle<v8::String> name =
16901 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 16913 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
16902 CHECK(!name.IsEmpty()); 16914 CHECK(!name.IsEmpty());
16903 CHECK_EQ(url, name); 16915 CHECK_EQ(url, name);
16904 } 16916 }
16905 } 16917 }
16906 16918
16907 16919
16908 TEST(DynamicWithSourceURLInStackTrace) { 16920 TEST(DynamicWithSourceURLInStackTrace) {
16909 v8::HandleScope scope(v8::Isolate::GetCurrent()); 16921 v8::HandleScope scope(CcTest::isolate());
16910 Local<ObjectTemplate> templ = ObjectTemplate::New(); 16922 Local<ObjectTemplate> templ = ObjectTemplate::New();
16911 templ->Set(v8_str("AnalyzeStackOfDynamicScriptWithSourceURL"), 16923 templ->Set(v8_str("AnalyzeStackOfDynamicScriptWithSourceURL"),
16912 v8::FunctionTemplate::New( 16924 v8::FunctionTemplate::New(
16913 AnalyzeStackOfDynamicScriptWithSourceURL)); 16925 AnalyzeStackOfDynamicScriptWithSourceURL));
16914 LocalContext context(0, templ); 16926 LocalContext context(0, templ);
16915 16927
16916 const char *source = 16928 const char *source =
16917 "function outer() {\n" 16929 "function outer() {\n"
16918 "function bar() {\n" 16930 "function bar() {\n"
16919 " AnalyzeStackOfDynamicScriptWithSourceURL();\n" 16931 " AnalyzeStackOfDynamicScriptWithSourceURL();\n"
16920 "}\n" 16932 "}\n"
16921 "function foo() {\n" 16933 "function foo() {\n"
16922 "\n" 16934 "\n"
16923 " bar();\n" 16935 " bar();\n"
16924 "}\n" 16936 "}\n"
16925 "foo();\n" 16937 "foo();\n"
16926 "}\n" 16938 "}\n"
16927 "outer()\n%s"; 16939 "outer()\n%s";
16928 16940
16929 i::ScopedVector<char> code(1024); 16941 i::ScopedVector<char> code(1024);
16930 i::OS::SNPrintF(code, source, "//# sourceURL=source_url"); 16942 i::OS::SNPrintF(code, source, "//# sourceURL=source_url");
16931 CHECK(CompileRunWithOrigin(code.start(), "url", 0, 0)->IsUndefined()); 16943 CHECK(CompileRunWithOrigin(code.start(), "url", 0, 0)->IsUndefined());
16932 i::OS::SNPrintF(code, source, "//@ sourceURL=source_url"); 16944 i::OS::SNPrintF(code, source, "//@ sourceURL=source_url");
16933 CHECK(CompileRunWithOrigin(code.start(), "url", 0, 0)->IsUndefined()); 16945 CHECK(CompileRunWithOrigin(code.start(), "url", 0, 0)->IsUndefined());
16934 } 16946 }
16935 16947
16936 16948
16937 static void CreateGarbageInOldSpace() { 16949 static void CreateGarbageInOldSpace() {
16938 i::Factory* factory = i::Isolate::Current()->factory(); 16950 i::Factory* factory = CcTest::i_isolate()->factory();
16939 v8::HandleScope scope(v8::Isolate::GetCurrent()); 16951 v8::HandleScope scope(CcTest::isolate());
16940 i::AlwaysAllocateScope always_allocate; 16952 i::AlwaysAllocateScope always_allocate;
16941 for (int i = 0; i < 1000; i++) { 16953 for (int i = 0; i < 1000; i++) {
16942 factory->NewFixedArray(1000, i::TENURED); 16954 factory->NewFixedArray(1000, i::TENURED);
16943 } 16955 }
16944 } 16956 }
16945 16957
16946 16958
16947 // Test that idle notification can be handled and eventually returns true. 16959 // Test that idle notification can be handled and eventually returns true.
16948 TEST(IdleNotification) { 16960 TEST(IdleNotification) {
16949 const intptr_t MB = 1024 * 1024; 16961 const intptr_t MB = 1024 * 1024;
16950 LocalContext env; 16962 LocalContext env;
16951 v8::HandleScope scope(env->GetIsolate()); 16963 v8::HandleScope scope(env->GetIsolate());
16952 intptr_t initial_size = HEAP->SizeOfObjects(); 16964 intptr_t initial_size = CcTest::heap()->SizeOfObjects();
16953 CreateGarbageInOldSpace(); 16965 CreateGarbageInOldSpace();
16954 intptr_t size_with_garbage = HEAP->SizeOfObjects(); 16966 intptr_t size_with_garbage = CcTest::heap()->SizeOfObjects();
16955 CHECK_GT(size_with_garbage, initial_size + MB); 16967 CHECK_GT(size_with_garbage, initial_size + MB);
16956 bool finished = false; 16968 bool finished = false;
16957 for (int i = 0; i < 200 && !finished; i++) { 16969 for (int i = 0; i < 200 && !finished; i++) {
16958 finished = v8::V8::IdleNotification(); 16970 finished = v8::V8::IdleNotification();
16959 } 16971 }
16960 intptr_t final_size = HEAP->SizeOfObjects(); 16972 intptr_t final_size = CcTest::heap()->SizeOfObjects();
16961 CHECK(finished); 16973 CHECK(finished);
16962 CHECK_LT(final_size, initial_size + 1); 16974 CHECK_LT(final_size, initial_size + 1);
16963 } 16975 }
16964 16976
16965 16977
16966 // Test that idle notification can be handled and eventually collects garbage. 16978 // Test that idle notification can be handled and eventually collects garbage.
16967 TEST(IdleNotificationWithSmallHint) { 16979 TEST(IdleNotificationWithSmallHint) {
16968 const intptr_t MB = 1024 * 1024; 16980 const intptr_t MB = 1024 * 1024;
16969 const int IdlePauseInMs = 900; 16981 const int IdlePauseInMs = 900;
16970 LocalContext env; 16982 LocalContext env;
16971 v8::HandleScope scope(env->GetIsolate()); 16983 v8::HandleScope scope(env->GetIsolate());
16972 intptr_t initial_size = HEAP->SizeOfObjects(); 16984 intptr_t initial_size = CcTest::heap()->SizeOfObjects();
16973 CreateGarbageInOldSpace(); 16985 CreateGarbageInOldSpace();
16974 intptr_t size_with_garbage = HEAP->SizeOfObjects(); 16986 intptr_t size_with_garbage = CcTest::heap()->SizeOfObjects();
16975 CHECK_GT(size_with_garbage, initial_size + MB); 16987 CHECK_GT(size_with_garbage, initial_size + MB);
16976 bool finished = false; 16988 bool finished = false;
16977 for (int i = 0; i < 200 && !finished; i++) { 16989 for (int i = 0; i < 200 && !finished; i++) {
16978 finished = v8::V8::IdleNotification(IdlePauseInMs); 16990 finished = v8::V8::IdleNotification(IdlePauseInMs);
16979 } 16991 }
16980 intptr_t final_size = HEAP->SizeOfObjects(); 16992 intptr_t final_size = CcTest::heap()->SizeOfObjects();
16981 CHECK(finished); 16993 CHECK(finished);
16982 CHECK_LT(final_size, initial_size + 1); 16994 CHECK_LT(final_size, initial_size + 1);
16983 } 16995 }
16984 16996
16985 16997
16986 // Test that idle notification can be handled and eventually collects garbage. 16998 // Test that idle notification can be handled and eventually collects garbage.
16987 TEST(IdleNotificationWithLargeHint) { 16999 TEST(IdleNotificationWithLargeHint) {
16988 const intptr_t MB = 1024 * 1024; 17000 const intptr_t MB = 1024 * 1024;
16989 const int IdlePauseInMs = 900; 17001 const int IdlePauseInMs = 900;
16990 LocalContext env; 17002 LocalContext env;
16991 v8::HandleScope scope(env->GetIsolate()); 17003 v8::HandleScope scope(env->GetIsolate());
16992 intptr_t initial_size = HEAP->SizeOfObjects(); 17004 intptr_t initial_size = CcTest::heap()->SizeOfObjects();
16993 CreateGarbageInOldSpace(); 17005 CreateGarbageInOldSpace();
16994 intptr_t size_with_garbage = HEAP->SizeOfObjects(); 17006 intptr_t size_with_garbage = CcTest::heap()->SizeOfObjects();
16995 CHECK_GT(size_with_garbage, initial_size + MB); 17007 CHECK_GT(size_with_garbage, initial_size + MB);
16996 bool finished = false; 17008 bool finished = false;
16997 for (int i = 0; i < 200 && !finished; i++) { 17009 for (int i = 0; i < 200 && !finished; i++) {
16998 finished = v8::V8::IdleNotification(IdlePauseInMs); 17010 finished = v8::V8::IdleNotification(IdlePauseInMs);
16999 } 17011 }
17000 intptr_t final_size = HEAP->SizeOfObjects(); 17012 intptr_t final_size = CcTest::heap()->SizeOfObjects();
17001 CHECK(finished); 17013 CHECK(finished);
17002 CHECK_LT(final_size, initial_size + 1); 17014 CHECK_LT(final_size, initial_size + 1);
17003 } 17015 }
17004 17016
17005 17017
17006 TEST(Regress2107) { 17018 TEST(Regress2107) {
17007 const intptr_t MB = 1024 * 1024; 17019 const intptr_t MB = 1024 * 1024;
17008 const int kShortIdlePauseInMs = 100; 17020 const int kShortIdlePauseInMs = 100;
17009 const int kLongIdlePauseInMs = 1000; 17021 const int kLongIdlePauseInMs = 1000;
17010 LocalContext env; 17022 LocalContext env;
17011 v8::Isolate* isolate = env->GetIsolate(); 17023 v8::Isolate* isolate = env->GetIsolate();
17012 v8::HandleScope scope(env->GetIsolate()); 17024 v8::HandleScope scope(env->GetIsolate());
17013 intptr_t initial_size = HEAP->SizeOfObjects(); 17025 intptr_t initial_size = CcTest::heap()->SizeOfObjects();
17014 // Send idle notification to start a round of incremental GCs. 17026 // Send idle notification to start a round of incremental GCs.
17015 v8::V8::IdleNotification(kShortIdlePauseInMs); 17027 v8::V8::IdleNotification(kShortIdlePauseInMs);
17016 // Emulate 7 page reloads. 17028 // Emulate 7 page reloads.
17017 for (int i = 0; i < 7; i++) { 17029 for (int i = 0; i < 7; i++) {
17018 { 17030 {
17019 v8::HandleScope inner_scope(env->GetIsolate()); 17031 v8::HandleScope inner_scope(env->GetIsolate());
17020 v8::Local<v8::Context> ctx = v8::Context::New(isolate); 17032 v8::Local<v8::Context> ctx = v8::Context::New(isolate);
17021 ctx->Enter(); 17033 ctx->Enter();
17022 CreateGarbageInOldSpace(); 17034 CreateGarbageInOldSpace();
17023 ctx->Exit(); 17035 ctx->Exit();
17024 } 17036 }
17025 v8::V8::ContextDisposedNotification(); 17037 v8::V8::ContextDisposedNotification();
17026 v8::V8::IdleNotification(kLongIdlePauseInMs); 17038 v8::V8::IdleNotification(kLongIdlePauseInMs);
17027 } 17039 }
17028 // Create garbage and check that idle notification still collects it. 17040 // Create garbage and check that idle notification still collects it.
17029 CreateGarbageInOldSpace(); 17041 CreateGarbageInOldSpace();
17030 intptr_t size_with_garbage = HEAP->SizeOfObjects(); 17042 intptr_t size_with_garbage = CcTest::heap()->SizeOfObjects();
17031 CHECK_GT(size_with_garbage, initial_size + MB); 17043 CHECK_GT(size_with_garbage, initial_size + MB);
17032 bool finished = false; 17044 bool finished = false;
17033 for (int i = 0; i < 200 && !finished; i++) { 17045 for (int i = 0; i < 200 && !finished; i++) {
17034 finished = v8::V8::IdleNotification(kShortIdlePauseInMs); 17046 finished = v8::V8::IdleNotification(kShortIdlePauseInMs);
17035 } 17047 }
17036 intptr_t final_size = HEAP->SizeOfObjects(); 17048 intptr_t final_size = CcTest::heap()->SizeOfObjects();
17037 CHECK_LT(final_size, initial_size + 1); 17049 CHECK_LT(final_size, initial_size + 1);
17038 } 17050 }
17039 17051
17040 static uint32_t* stack_limit; 17052 static uint32_t* stack_limit;
17041 17053
17042 static void GetStackLimitCallback( 17054 static void GetStackLimitCallback(
17043 const v8::FunctionCallbackInfo<v8::Value>& args) { 17055 const v8::FunctionCallbackInfo<v8::Value>& args) {
17044 stack_limit = reinterpret_cast<uint32_t*>( 17056 stack_limit = reinterpret_cast<uint32_t*>(
17045 i::Isolate::Current()->stack_guard()->real_climit()); 17057 CcTest::i_isolate()->stack_guard()->real_climit());
17046 } 17058 }
17047 17059
17048 17060
17049 // Uses the address of a local variable to determine the stack top now. 17061 // Uses the address of a local variable to determine the stack top now.
17050 // Given a size, returns an address that is that far from the current 17062 // Given a size, returns an address that is that far from the current
17051 // top of stack. 17063 // top of stack.
17052 static uint32_t* ComputeStackLimit(uint32_t size) { 17064 static uint32_t* ComputeStackLimit(uint32_t size) {
17053 uint32_t* answer = &size - (size / sizeof(size)); 17065 uint32_t* answer = &size - (size / sizeof(size));
17054 // If the size is very large and the stack is very near the bottom of 17066 // If the size is very large and the stack is very near the bottom of
17055 // memory then the calculation above may wrap around and give an address 17067 // memory then the calculation above may wrap around and give an address
(...skipping 25 matching lines...) Expand all
17081 env->Global()->Set(v8_str("get_stack_limit"), fun); 17093 env->Global()->Set(v8_str("get_stack_limit"), fun);
17082 CompileRun("get_stack_limit();"); 17094 CompileRun("get_stack_limit();");
17083 17095
17084 CHECK(stack_limit == set_limit); 17096 CHECK(stack_limit == set_limit);
17085 } 17097 }
17086 17098
17087 17099
17088 TEST(SetResourceConstraintsInThread) { 17100 TEST(SetResourceConstraintsInThread) {
17089 uint32_t* set_limit; 17101 uint32_t* set_limit;
17090 { 17102 {
17091 v8::Locker locker(CcTest::default_isolate()); 17103 v8::Locker locker(CcTest::isolate());
17092 set_limit = ComputeStackLimit(stack_breathing_room); 17104 set_limit = ComputeStackLimit(stack_breathing_room);
17093 17105
17094 // Set stack limit. 17106 // Set stack limit.
17095 v8::ResourceConstraints constraints; 17107 v8::ResourceConstraints constraints;
17096 constraints.set_stack_limit(set_limit); 17108 constraints.set_stack_limit(set_limit);
17097 CHECK(v8::SetResourceConstraints(&constraints)); 17109 CHECK(v8::SetResourceConstraints(&constraints));
17098 17110
17099 // Execute a script. 17111 // Execute a script.
17100 v8::HandleScope scope(CcTest::default_isolate()); 17112 v8::HandleScope scope(CcTest::isolate());
17101 LocalContext env; 17113 LocalContext env;
17102 Local<v8::FunctionTemplate> fun_templ = 17114 Local<v8::FunctionTemplate> fun_templ =
17103 v8::FunctionTemplate::New(GetStackLimitCallback); 17115 v8::FunctionTemplate::New(GetStackLimitCallback);
17104 Local<Function> fun = fun_templ->GetFunction(); 17116 Local<Function> fun = fun_templ->GetFunction();
17105 env->Global()->Set(v8_str("get_stack_limit"), fun); 17117 env->Global()->Set(v8_str("get_stack_limit"), fun);
17106 CompileRun("get_stack_limit();"); 17118 CompileRun("get_stack_limit();");
17107 17119
17108 CHECK(stack_limit == set_limit); 17120 CHECK(stack_limit == set_limit);
17109 } 17121 }
17110 { 17122 {
17111 v8::Locker locker(CcTest::default_isolate()); 17123 v8::Locker locker(CcTest::isolate());
17112 CHECK(stack_limit == set_limit); 17124 CHECK(stack_limit == set_limit);
17113 } 17125 }
17114 } 17126 }
17115 17127
17116 17128
17117 THREADED_TEST(GetHeapStatistics) { 17129 THREADED_TEST(GetHeapStatistics) {
17118 LocalContext c1; 17130 LocalContext c1;
17119 v8::HandleScope scope(c1->GetIsolate()); 17131 v8::HandleScope scope(c1->GetIsolate());
17120 v8::HeapStatistics heap_statistics; 17132 v8::HeapStatistics heap_statistics;
17121 CHECK_EQ(static_cast<int>(heap_statistics.total_heap_size()), 0); 17133 CHECK_EQ(static_cast<int>(heap_statistics.total_heap_size()), 0);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
17174 v8::Local<v8::String> string1 = v8::String::NewExternal(resource[1]); 17186 v8::Local<v8::String> string1 = v8::String::NewExternal(resource[1]);
17175 17187
17176 // Externalized symbol. 17188 // Externalized symbol.
17177 resource[2] = new TestResource(two_byte_string); 17189 resource[2] = new TestResource(two_byte_string);
17178 v8::Local<v8::String> string2 = v8::String::NewSymbol(string); 17190 v8::Local<v8::String> string2 = v8::String::NewSymbol(string);
17179 CHECK(string2->MakeExternal(resource[2])); 17191 CHECK(string2->MakeExternal(resource[2]));
17180 17192
17181 // Symbolized External. 17193 // Symbolized External.
17182 resource[3] = new TestResource(AsciiToTwoByteString("Some other string")); 17194 resource[3] = new TestResource(AsciiToTwoByteString("Some other string"));
17183 v8::Local<v8::String> string3 = v8::String::NewExternal(resource[3]); 17195 v8::Local<v8::String> string3 = v8::String::NewExternal(resource[3]);
17184 HEAP->CollectAllAvailableGarbage(); // Tenure string. 17196 CcTest::heap()->CollectAllAvailableGarbage(); // Tenure string.
17185 // Turn into a symbol. 17197 // Turn into a symbol.
17186 i::Handle<i::String> string3_i = v8::Utils::OpenHandle(*string3); 17198 i::Handle<i::String> string3_i = v8::Utils::OpenHandle(*string3);
17187 CHECK(!HEAP->InternalizeString(*string3_i)->IsFailure()); 17199 CHECK(!CcTest::heap()->InternalizeString(*string3_i)->IsFailure());
17188 CHECK(string3_i->IsInternalizedString()); 17200 CHECK(string3_i->IsInternalizedString());
17189 17201
17190 // We need to add usages for string* to avoid warnings in GCC 4.7 17202 // We need to add usages for string* to avoid warnings in GCC 4.7
17191 CHECK(string0->IsExternal()); 17203 CHECK(string0->IsExternal());
17192 CHECK(string1->IsExternal()); 17204 CHECK(string1->IsExternal());
17193 CHECK(string2->IsExternal()); 17205 CHECK(string2->IsExternal());
17194 CHECK(string3->IsExternal()); 17206 CHECK(string3->IsExternal());
17195 17207
17196 VisitorImpl visitor(resource); 17208 VisitorImpl visitor(resource);
17197 v8::V8::VisitExternalResources(&visitor); 17209 v8::V8::VisitExternalResources(&visitor);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
17320 v8::Handle<v8::String> str(args[0]->ToString()); 17332 v8::Handle<v8::String> str(args[0]->ToString());
17321 USE(str); 17333 USE(str);
17322 if (tc.HasCaught()) 17334 if (tc.HasCaught())
17323 tc.ReThrow(); 17335 tc.ReThrow();
17324 } 17336 }
17325 17337
17326 17338
17327 // Test that an exception can be propagated down through a spaghetti 17339 // Test that an exception can be propagated down through a spaghetti
17328 // stack using ReThrow. 17340 // stack using ReThrow.
17329 THREADED_TEST(SpaghettiStackReThrow) { 17341 THREADED_TEST(SpaghettiStackReThrow) {
17330 v8::HandleScope scope(v8::Isolate::GetCurrent()); 17342 v8::HandleScope scope(CcTest::isolate());
17331 LocalContext context; 17343 LocalContext context;
17332 context->Global()->Set( 17344 context->Global()->Set(
17333 v8::String::New("s"), 17345 v8::String::New("s"),
17334 v8::FunctionTemplate::New(SpaghettiIncident)->GetFunction()); 17346 v8::FunctionTemplate::New(SpaghettiIncident)->GetFunction());
17335 v8::TryCatch try_catch; 17347 v8::TryCatch try_catch;
17336 CompileRun( 17348 CompileRun(
17337 "var i = 0;" 17349 "var i = 0;"
17338 "var o = {" 17350 "var o = {"
17339 " toString: function () {" 17351 " toString: function () {"
17340 " if (i == 10) {" 17352 " if (i == 10) {"
17341 " throw 'Hey!';" 17353 " throw 'Hey!';"
17342 " } else {" 17354 " } else {"
17343 " i++;" 17355 " i++;"
17344 " return s(o);" 17356 " return s(o);"
17345 " }" 17357 " }"
17346 " }" 17358 " }"
17347 "};" 17359 "};"
17348 "s(o);"); 17360 "s(o);");
17349 CHECK(try_catch.HasCaught()); 17361 CHECK(try_catch.HasCaught());
17350 v8::String::Utf8Value value(try_catch.Exception()); 17362 v8::String::Utf8Value value(try_catch.Exception());
17351 CHECK_EQ(0, strcmp(*value, "Hey!")); 17363 CHECK_EQ(0, strcmp(*value, "Hey!"));
17352 } 17364 }
17353 17365
17354 17366
17355 TEST(Regress528) { 17367 TEST(Regress528) {
17356 v8::V8::Initialize(); 17368 v8::V8::Initialize();
17357 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 17369 v8::Isolate* isolate = CcTest::isolate();
17358 v8::HandleScope scope(isolate); 17370 v8::HandleScope scope(isolate);
17359 v8::Local<Context> other_context; 17371 v8::Local<Context> other_context;
17360 int gc_count; 17372 int gc_count;
17361 17373
17362 // Create a context used to keep the code from aging in the compilation 17374 // Create a context used to keep the code from aging in the compilation
17363 // cache. 17375 // cache.
17364 other_context = Context::New(isolate); 17376 other_context = Context::New(isolate);
17365 17377
17366 // Context-dependent context data creates reference from the compilation 17378 // Context-dependent context data creates reference from the compilation
17367 // cache to the global object. 17379 // cache to the global object.
17368 const char* source_simple = "1"; 17380 const char* source_simple = "1";
17369 { 17381 {
17370 v8::HandleScope scope(isolate); 17382 v8::HandleScope scope(isolate);
17371 v8::Local<Context> context = Context::New(isolate); 17383 v8::Local<Context> context = Context::New(isolate);
17372 17384
17373 context->Enter(); 17385 context->Enter();
17374 Local<v8::String> obj = v8::String::New(""); 17386 Local<v8::String> obj = v8::String::New("");
17375 context->SetEmbedderData(0, obj); 17387 context->SetEmbedderData(0, obj);
17376 CompileRun(source_simple); 17388 CompileRun(source_simple);
17377 context->Exit(); 17389 context->Exit();
17378 } 17390 }
17379 v8::V8::ContextDisposedNotification(); 17391 v8::V8::ContextDisposedNotification();
17380 for (gc_count = 1; gc_count < 10; gc_count++) { 17392 for (gc_count = 1; gc_count < 10; gc_count++) {
17381 other_context->Enter(); 17393 other_context->Enter();
17382 CompileRun(source_simple); 17394 CompileRun(source_simple);
17383 other_context->Exit(); 17395 other_context->Exit();
17384 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 17396 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
17385 if (GetGlobalObjectsCount() == 1) break; 17397 if (GetGlobalObjectsCount() == 1) break;
17386 } 17398 }
17387 CHECK_GE(2, gc_count); 17399 CHECK_GE(2, gc_count);
17388 CHECK_EQ(1, GetGlobalObjectsCount()); 17400 CHECK_EQ(1, GetGlobalObjectsCount());
17389 17401
17390 // Eval in a function creates reference from the compilation cache to the 17402 // Eval in a function creates reference from the compilation cache to the
17391 // global object. 17403 // global object.
17392 const char* source_eval = "function f(){eval('1')}; f()"; 17404 const char* source_eval = "function f(){eval('1')}; f()";
17393 { 17405 {
17394 v8::HandleScope scope(isolate); 17406 v8::HandleScope scope(isolate);
17395 v8::Local<Context> context = Context::New(isolate); 17407 v8::Local<Context> context = Context::New(isolate);
17396 17408
17397 context->Enter(); 17409 context->Enter();
17398 CompileRun(source_eval); 17410 CompileRun(source_eval);
17399 context->Exit(); 17411 context->Exit();
17400 } 17412 }
17401 v8::V8::ContextDisposedNotification(); 17413 v8::V8::ContextDisposedNotification();
17402 for (gc_count = 1; gc_count < 10; gc_count++) { 17414 for (gc_count = 1; gc_count < 10; gc_count++) {
17403 other_context->Enter(); 17415 other_context->Enter();
17404 CompileRun(source_eval); 17416 CompileRun(source_eval);
17405 other_context->Exit(); 17417 other_context->Exit();
17406 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 17418 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
17407 if (GetGlobalObjectsCount() == 1) break; 17419 if (GetGlobalObjectsCount() == 1) break;
17408 } 17420 }
17409 CHECK_GE(2, gc_count); 17421 CHECK_GE(2, gc_count);
17410 CHECK_EQ(1, GetGlobalObjectsCount()); 17422 CHECK_EQ(1, GetGlobalObjectsCount());
17411 17423
17412 // Looking up the line number for an exception creates reference from the 17424 // Looking up the line number for an exception creates reference from the
17413 // compilation cache to the global object. 17425 // compilation cache to the global object.
17414 const char* source_exception = "function f(){throw 1;} f()"; 17426 const char* source_exception = "function f(){throw 1;} f()";
17415 { 17427 {
17416 v8::HandleScope scope(isolate); 17428 v8::HandleScope scope(isolate);
17417 v8::Local<Context> context = Context::New(isolate); 17429 v8::Local<Context> context = Context::New(isolate);
17418 17430
17419 context->Enter(); 17431 context->Enter();
17420 v8::TryCatch try_catch; 17432 v8::TryCatch try_catch;
17421 CompileRun(source_exception); 17433 CompileRun(source_exception);
17422 CHECK(try_catch.HasCaught()); 17434 CHECK(try_catch.HasCaught());
17423 v8::Handle<v8::Message> message = try_catch.Message(); 17435 v8::Handle<v8::Message> message = try_catch.Message();
17424 CHECK(!message.IsEmpty()); 17436 CHECK(!message.IsEmpty());
17425 CHECK_EQ(1, message->GetLineNumber()); 17437 CHECK_EQ(1, message->GetLineNumber());
17426 context->Exit(); 17438 context->Exit();
17427 } 17439 }
17428 v8::V8::ContextDisposedNotification(); 17440 v8::V8::ContextDisposedNotification();
17429 for (gc_count = 1; gc_count < 10; gc_count++) { 17441 for (gc_count = 1; gc_count < 10; gc_count++) {
17430 other_context->Enter(); 17442 other_context->Enter();
17431 CompileRun(source_exception); 17443 CompileRun(source_exception);
17432 other_context->Exit(); 17444 other_context->Exit();
17433 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 17445 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
17434 if (GetGlobalObjectsCount() == 1) break; 17446 if (GetGlobalObjectsCount() == 1) break;
17435 } 17447 }
17436 CHECK_GE(2, gc_count); 17448 CHECK_GE(2, gc_count);
17437 CHECK_EQ(1, GetGlobalObjectsCount()); 17449 CHECK_EQ(1, GetGlobalObjectsCount());
17438 17450
17439 v8::V8::ContextDisposedNotification(); 17451 v8::V8::ContextDisposedNotification();
17440 } 17452 }
17441 17453
17442 17454
17443 THREADED_TEST(ScriptOrigin) { 17455 THREADED_TEST(ScriptOrigin) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
17559 const v8::PropertyCallbackInfo<v8::Value>& info) { 17571 const v8::PropertyCallbackInfo<v8::Value>& info) {
17560 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); 17572 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject());
17561 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); 17573 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject());
17562 if (!name->Equals(v8_str("foo"))) return; 17574 if (!name->Equals(v8_str("foo"))) return;
17563 info.This()->Set(v8_str("y"), v8_num(23)); 17575 info.This()->Set(v8_str("y"), v8_num(23));
17564 info.GetReturnValue().Set(v8_num(23)); 17576 info.GetReturnValue().Set(v8_num(23));
17565 } 17577 }
17566 17578
17567 17579
17568 TEST(SetterOnConstructorPrototype) { 17580 TEST(SetterOnConstructorPrototype) {
17569 v8::HandleScope scope(v8::Isolate::GetCurrent()); 17581 v8::HandleScope scope(CcTest::isolate());
17570 Local<ObjectTemplate> templ = ObjectTemplate::New(); 17582 Local<ObjectTemplate> templ = ObjectTemplate::New();
17571 templ->SetAccessor(v8_str("x"), 17583 templ->SetAccessor(v8_str("x"),
17572 GetterWhichReturns42, 17584 GetterWhichReturns42,
17573 SetterWhichSetsYOnThisTo23); 17585 SetterWhichSetsYOnThisTo23);
17574 LocalContext context; 17586 LocalContext context;
17575 context->Global()->Set(v8_str("P"), templ->NewInstance()); 17587 context->Global()->Set(v8_str("P"), templ->NewInstance());
17576 CompileRun("function C1() {" 17588 CompileRun("function C1() {"
17577 " this.x = 23;" 17589 " this.x = 23;"
17578 "};" 17590 "};"
17579 "C1.prototype = P;" 17591 "C1.prototype = P;"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
17611 Local<String> name, 17623 Local<String> name,
17612 Local<Value> value, 17624 Local<Value> value,
17613 const v8::PropertyCallbackInfo<v8::Value>& info) { 17625 const v8::PropertyCallbackInfo<v8::Value>& info) {
17614 if (name->Equals(v8_str("x"))) { 17626 if (name->Equals(v8_str("x"))) {
17615 info.This()->Set(v8_str("y"), v8_num(23)); 17627 info.This()->Set(v8_str("y"), v8_num(23));
17616 } 17628 }
17617 } 17629 }
17618 17630
17619 17631
17620 THREADED_TEST(InterceptorOnConstructorPrototype) { 17632 THREADED_TEST(InterceptorOnConstructorPrototype) {
17621 v8::HandleScope scope(v8::Isolate::GetCurrent()); 17633 v8::HandleScope scope(CcTest::isolate());
17622 Local<ObjectTemplate> templ = ObjectTemplate::New(); 17634 Local<ObjectTemplate> templ = ObjectTemplate::New();
17623 templ->SetNamedPropertyHandler(NamedPropertyGetterWhichReturns42, 17635 templ->SetNamedPropertyHandler(NamedPropertyGetterWhichReturns42,
17624 NamedPropertySetterWhichSetsYOnThisTo23); 17636 NamedPropertySetterWhichSetsYOnThisTo23);
17625 LocalContext context; 17637 LocalContext context;
17626 context->Global()->Set(v8_str("P"), templ->NewInstance()); 17638 context->Global()->Set(v8_str("P"), templ->NewInstance());
17627 CompileRun("function C1() {" 17639 CompileRun("function C1() {"
17628 " this.x = 23;" 17640 " this.x = 23;"
17629 "};" 17641 "};"
17630 "C1.prototype = P;" 17642 "C1.prototype = P;"
17631 "function C2() {" 17643 "function C2() {"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
17689 CompileRun(source); 17701 CompileRun(source);
17690 17702
17691 script = v8::Script::Compile(v8_str("new C1();")); 17703 script = v8::Script::Compile(v8_str("new C1();"));
17692 for (int i = 0; i < 10; i++) { 17704 for (int i = 0; i < 10; i++) {
17693 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); 17705 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run());
17694 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value()); 17706 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value());
17695 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value()); 17707 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value());
17696 } 17708 }
17697 } 17709 }
17698 17710
17711 v8::Isolate* gc_callbacks_isolate = NULL;
17699 int prologue_call_count = 0; 17712 int prologue_call_count = 0;
17700 int epilogue_call_count = 0; 17713 int epilogue_call_count = 0;
17701 int prologue_call_count_second = 0; 17714 int prologue_call_count_second = 0;
17702 int epilogue_call_count_second = 0; 17715 int epilogue_call_count_second = 0;
17703 17716
17704 void PrologueCallback(v8::GCType, v8::GCCallbackFlags) { 17717 void PrologueCallback(v8::GCType, v8::GCCallbackFlags flags) {
17718 CHECK_EQ(flags, v8::kNoGCCallbackFlags);
17705 ++prologue_call_count; 17719 ++prologue_call_count;
17706 } 17720 }
17707 17721
17708 17722
17709 void EpilogueCallback(v8::GCType, v8::GCCallbackFlags) { 17723 void PrologueCallback(v8::Isolate* isolate,
17724 v8::GCType,
17725 v8::GCCallbackFlags flags) {
17726 CHECK_EQ(flags, v8::kNoGCCallbackFlags);
17727 CHECK_EQ(gc_callbacks_isolate, isolate);
17728 ++prologue_call_count;
17729 }
17730
17731
17732 void EpilogueCallback(v8::GCType, v8::GCCallbackFlags flags) {
17733 CHECK_EQ(flags, v8::kNoGCCallbackFlags);
17710 ++epilogue_call_count; 17734 ++epilogue_call_count;
17711 } 17735 }
17712 17736
17713 17737
17714 void PrologueCallbackSecond(v8::GCType, v8::GCCallbackFlags) { 17738 void EpilogueCallback(v8::Isolate* isolate,
17739 v8::GCType,
17740 v8::GCCallbackFlags flags) {
17741 CHECK_EQ(flags, v8::kNoGCCallbackFlags);
17742 CHECK_EQ(gc_callbacks_isolate, isolate);
17743 ++epilogue_call_count;
17744 }
17745
17746
17747 void PrologueCallbackSecond(v8::GCType, v8::GCCallbackFlags flags) {
17748 CHECK_EQ(flags, v8::kNoGCCallbackFlags);
17715 ++prologue_call_count_second; 17749 ++prologue_call_count_second;
17716 } 17750 }
17717 17751
17718 17752
17719 void EpilogueCallbackSecond(v8::GCType, v8::GCCallbackFlags) { 17753 void PrologueCallbackSecond(v8::Isolate* isolate,
17754 v8::GCType,
17755 v8::GCCallbackFlags flags) {
17756 CHECK_EQ(flags, v8::kNoGCCallbackFlags);
17757 CHECK_EQ(gc_callbacks_isolate, isolate);
17758 ++prologue_call_count_second;
17759 }
17760
17761
17762 void EpilogueCallbackSecond(v8::GCType, v8::GCCallbackFlags flags) {
17763 CHECK_EQ(flags, v8::kNoGCCallbackFlags);
17720 ++epilogue_call_count_second; 17764 ++epilogue_call_count_second;
17721 } 17765 }
17722 17766
17723 17767
17724 TEST(GCCallbacks) { 17768 void EpilogueCallbackSecond(v8::Isolate* isolate,
17769 v8::GCType,
17770 v8::GCCallbackFlags flags) {
17771 CHECK_EQ(flags, v8::kNoGCCallbackFlags);
17772 CHECK_EQ(gc_callbacks_isolate, isolate);
17773 ++epilogue_call_count_second;
17774 }
17775
17776
17777 TEST(GCCallbacksOld) {
17725 LocalContext context; 17778 LocalContext context;
17726 17779
17727 v8::V8::AddGCPrologueCallback(PrologueCallback); 17780 v8::V8::AddGCPrologueCallback(PrologueCallback);
17728 v8::V8::AddGCEpilogueCallback(EpilogueCallback); 17781 v8::V8::AddGCEpilogueCallback(EpilogueCallback);
17729 CHECK_EQ(0, prologue_call_count); 17782 CHECK_EQ(0, prologue_call_count);
17730 CHECK_EQ(0, epilogue_call_count); 17783 CHECK_EQ(0, epilogue_call_count);
17731 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 17784 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
17732 CHECK_EQ(1, prologue_call_count); 17785 CHECK_EQ(1, prologue_call_count);
17733 CHECK_EQ(1, epilogue_call_count); 17786 CHECK_EQ(1, epilogue_call_count);
17734 v8::V8::AddGCPrologueCallback(PrologueCallbackSecond); 17787 v8::V8::AddGCPrologueCallback(PrologueCallbackSecond);
17735 v8::V8::AddGCEpilogueCallback(EpilogueCallbackSecond); 17788 v8::V8::AddGCEpilogueCallback(EpilogueCallbackSecond);
17736 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 17789 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
17737 CHECK_EQ(2, prologue_call_count); 17790 CHECK_EQ(2, prologue_call_count);
17738 CHECK_EQ(2, epilogue_call_count); 17791 CHECK_EQ(2, epilogue_call_count);
17739 CHECK_EQ(1, prologue_call_count_second); 17792 CHECK_EQ(1, prologue_call_count_second);
17740 CHECK_EQ(1, epilogue_call_count_second); 17793 CHECK_EQ(1, epilogue_call_count_second);
17741 v8::V8::RemoveGCPrologueCallback(PrologueCallback); 17794 v8::V8::RemoveGCPrologueCallback(PrologueCallback);
17742 v8::V8::RemoveGCEpilogueCallback(EpilogueCallback); 17795 v8::V8::RemoveGCEpilogueCallback(EpilogueCallback);
17743 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 17796 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
17744 CHECK_EQ(2, prologue_call_count); 17797 CHECK_EQ(2, prologue_call_count);
17745 CHECK_EQ(2, epilogue_call_count); 17798 CHECK_EQ(2, epilogue_call_count);
17746 CHECK_EQ(2, prologue_call_count_second); 17799 CHECK_EQ(2, prologue_call_count_second);
17747 CHECK_EQ(2, epilogue_call_count_second); 17800 CHECK_EQ(2, epilogue_call_count_second);
17748 v8::V8::RemoveGCPrologueCallback(PrologueCallbackSecond); 17801 v8::V8::RemoveGCPrologueCallback(PrologueCallbackSecond);
17749 v8::V8::RemoveGCEpilogueCallback(EpilogueCallbackSecond); 17802 v8::V8::RemoveGCEpilogueCallback(EpilogueCallbackSecond);
17750 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 17803 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
17751 CHECK_EQ(2, prologue_call_count); 17804 CHECK_EQ(2, prologue_call_count);
17752 CHECK_EQ(2, epilogue_call_count); 17805 CHECK_EQ(2, epilogue_call_count);
17753 CHECK_EQ(2, prologue_call_count_second); 17806 CHECK_EQ(2, prologue_call_count_second);
17807 CHECK_EQ(2, epilogue_call_count_second);
17808 }
17809
17810
17811 TEST(GCCallbacks) {
17812 LocalContext context;
17813 v8::Isolate* isolate = context->GetIsolate();
17814 gc_callbacks_isolate = isolate;
17815 isolate->AddGCPrologueCallback(PrologueCallback);
17816 isolate->AddGCEpilogueCallback(EpilogueCallback);
17817 CHECK_EQ(0, prologue_call_count);
17818 CHECK_EQ(0, epilogue_call_count);
17819 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
17820 CHECK_EQ(1, prologue_call_count);
17821 CHECK_EQ(1, epilogue_call_count);
17822 isolate->AddGCPrologueCallback(PrologueCallbackSecond);
17823 isolate->AddGCEpilogueCallback(EpilogueCallbackSecond);
17824 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
17825 CHECK_EQ(2, prologue_call_count);
17826 CHECK_EQ(2, epilogue_call_count);
17827 CHECK_EQ(1, prologue_call_count_second);
17828 CHECK_EQ(1, epilogue_call_count_second);
17829 isolate->RemoveGCPrologueCallback(PrologueCallback);
17830 isolate->RemoveGCEpilogueCallback(EpilogueCallback);
17831 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
17832 CHECK_EQ(2, prologue_call_count);
17833 CHECK_EQ(2, epilogue_call_count);
17834 CHECK_EQ(2, prologue_call_count_second);
17835 CHECK_EQ(2, epilogue_call_count_second);
17836 isolate->RemoveGCPrologueCallback(PrologueCallbackSecond);
17837 isolate->RemoveGCEpilogueCallback(EpilogueCallbackSecond);
17838 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
17839 CHECK_EQ(2, prologue_call_count);
17840 CHECK_EQ(2, epilogue_call_count);
17841 CHECK_EQ(2, prologue_call_count_second);
17754 CHECK_EQ(2, epilogue_call_count_second); 17842 CHECK_EQ(2, epilogue_call_count_second);
17755 } 17843 }
17756 17844
17757 17845
17758 THREADED_TEST(AddToJSFunctionResultCache) { 17846 THREADED_TEST(AddToJSFunctionResultCache) {
17759 i::FLAG_stress_compaction = false; 17847 i::FLAG_stress_compaction = false;
17760 i::FLAG_allow_natives_syntax = true; 17848 i::FLAG_allow_natives_syntax = true;
17761 v8::HandleScope scope(v8::Isolate::GetCurrent()); 17849 v8::HandleScope scope(CcTest::isolate());
17762 17850
17763 LocalContext context; 17851 LocalContext context;
17764 17852
17765 const char* code = 17853 const char* code =
17766 "(function() {" 17854 "(function() {"
17767 " var key0 = 'a';" 17855 " var key0 = 'a';"
17768 " var key1 = 'b';" 17856 " var key1 = 'b';"
17769 " var r0 = %_GetFromCache(0, key0);" 17857 " var r0 = %_GetFromCache(0, key0);"
17770 " var r1 = %_GetFromCache(0, key1);" 17858 " var r1 = %_GetFromCache(0, key1);"
17771 " var r0_ = %_GetFromCache(0, key0);" 17859 " var r0_ = %_GetFromCache(0, key0);"
17772 " if (r0 !== r0_)" 17860 " if (r0 !== r0_)"
17773 " return 'Different results for ' + key0 + ': ' + r0 + ' vs. ' + r0_;" 17861 " return 'Different results for ' + key0 + ': ' + r0 + ' vs. ' + r0_;"
17774 " var r1_ = %_GetFromCache(0, key1);" 17862 " var r1_ = %_GetFromCache(0, key1);"
17775 " if (r1 !== r1_)" 17863 " if (r1 !== r1_)"
17776 " return 'Different results for ' + key1 + ': ' + r1 + ' vs. ' + r1_;" 17864 " return 'Different results for ' + key1 + ': ' + r1 + ' vs. ' + r1_;"
17777 " return 'PASSED';" 17865 " return 'PASSED';"
17778 "})()"; 17866 "})()";
17779 HEAP->ClearJSFunctionResultCaches(); 17867 CcTest::heap()->ClearJSFunctionResultCaches();
17780 ExpectString(code, "PASSED"); 17868 ExpectString(code, "PASSED");
17781 } 17869 }
17782 17870
17783 17871
17784 static const int k0CacheSize = 16; 17872 static const int k0CacheSize = 16;
17785 17873
17786 THREADED_TEST(FillJSFunctionResultCache) { 17874 THREADED_TEST(FillJSFunctionResultCache) {
17787 i::FLAG_allow_natives_syntax = true; 17875 i::FLAG_allow_natives_syntax = true;
17788 LocalContext context; 17876 LocalContext context;
17789 v8::HandleScope scope(context->GetIsolate()); 17877 v8::HandleScope scope(context->GetIsolate());
17790 17878
17791 const char* code = 17879 const char* code =
17792 "(function() {" 17880 "(function() {"
17793 " var k = 'a';" 17881 " var k = 'a';"
17794 " var r = %_GetFromCache(0, k);" 17882 " var r = %_GetFromCache(0, k);"
17795 " for (var i = 0; i < 16; i++) {" 17883 " for (var i = 0; i < 16; i++) {"
17796 " %_GetFromCache(0, 'a' + i);" 17884 " %_GetFromCache(0, 'a' + i);"
17797 " };" 17885 " };"
17798 " if (r === %_GetFromCache(0, k))" 17886 " if (r === %_GetFromCache(0, k))"
17799 " return 'FAILED: k0CacheSize is too small';" 17887 " return 'FAILED: k0CacheSize is too small';"
17800 " return 'PASSED';" 17888 " return 'PASSED';"
17801 "})()"; 17889 "})()";
17802 HEAP->ClearJSFunctionResultCaches(); 17890 CcTest::heap()->ClearJSFunctionResultCaches();
17803 ExpectString(code, "PASSED"); 17891 ExpectString(code, "PASSED");
17804 } 17892 }
17805 17893
17806 17894
17807 THREADED_TEST(RoundRobinGetFromCache) { 17895 THREADED_TEST(RoundRobinGetFromCache) {
17808 i::FLAG_allow_natives_syntax = true; 17896 i::FLAG_allow_natives_syntax = true;
17809 LocalContext context; 17897 LocalContext context;
17810 v8::HandleScope scope(context->GetIsolate()); 17898 v8::HandleScope scope(context->GetIsolate());
17811 17899
17812 const char* code = 17900 const char* code =
17813 "(function() {" 17901 "(function() {"
17814 " var keys = [];" 17902 " var keys = [];"
17815 " for (var i = 0; i < 16; i++) keys.push(i);" 17903 " for (var i = 0; i < 16; i++) keys.push(i);"
17816 " var values = [];" 17904 " var values = [];"
17817 " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);" 17905 " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);"
17818 " for (var i = 0; i < 16; i++) {" 17906 " for (var i = 0; i < 16; i++) {"
17819 " var v = %_GetFromCache(0, keys[i]);" 17907 " var v = %_GetFromCache(0, keys[i]);"
17820 " if (v.toString() !== values[i].toString())" 17908 " if (v.toString() !== values[i].toString())"
17821 " return 'Wrong value for ' + " 17909 " return 'Wrong value for ' + "
17822 " keys[i] + ': ' + v + ' vs. ' + values[i];" 17910 " keys[i] + ': ' + v + ' vs. ' + values[i];"
17823 " };" 17911 " };"
17824 " return 'PASSED';" 17912 " return 'PASSED';"
17825 "})()"; 17913 "})()";
17826 HEAP->ClearJSFunctionResultCaches(); 17914 CcTest::heap()->ClearJSFunctionResultCaches();
17827 ExpectString(code, "PASSED"); 17915 ExpectString(code, "PASSED");
17828 } 17916 }
17829 17917
17830 17918
17831 THREADED_TEST(ReverseGetFromCache) { 17919 THREADED_TEST(ReverseGetFromCache) {
17832 i::FLAG_allow_natives_syntax = true; 17920 i::FLAG_allow_natives_syntax = true;
17833 LocalContext context; 17921 LocalContext context;
17834 v8::HandleScope scope(context->GetIsolate()); 17922 v8::HandleScope scope(context->GetIsolate());
17835 17923
17836 const char* code = 17924 const char* code =
17837 "(function() {" 17925 "(function() {"
17838 " var keys = [];" 17926 " var keys = [];"
17839 " for (var i = 0; i < 16; i++) keys.push(i);" 17927 " for (var i = 0; i < 16; i++) keys.push(i);"
17840 " var values = [];" 17928 " var values = [];"
17841 " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);" 17929 " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);"
17842 " for (var i = 15; i >= 16; i--) {" 17930 " for (var i = 15; i >= 16; i--) {"
17843 " var v = %_GetFromCache(0, keys[i]);" 17931 " var v = %_GetFromCache(0, keys[i]);"
17844 " if (v !== values[i])" 17932 " if (v !== values[i])"
17845 " return 'Wrong value for ' + " 17933 " return 'Wrong value for ' + "
17846 " keys[i] + ': ' + v + ' vs. ' + values[i];" 17934 " keys[i] + ': ' + v + ' vs. ' + values[i];"
17847 " };" 17935 " };"
17848 " return 'PASSED';" 17936 " return 'PASSED';"
17849 "})()"; 17937 "})()";
17850 HEAP->ClearJSFunctionResultCaches(); 17938 CcTest::heap()->ClearJSFunctionResultCaches();
17851 ExpectString(code, "PASSED"); 17939 ExpectString(code, "PASSED");
17852 } 17940 }
17853 17941
17854 17942
17855 THREADED_TEST(TestEviction) { 17943 THREADED_TEST(TestEviction) {
17856 i::FLAG_allow_natives_syntax = true; 17944 i::FLAG_allow_natives_syntax = true;
17857 LocalContext context; 17945 LocalContext context;
17858 v8::HandleScope scope(context->GetIsolate()); 17946 v8::HandleScope scope(context->GetIsolate());
17859 17947
17860 const char* code = 17948 const char* code =
17861 "(function() {" 17949 "(function() {"
17862 " for (var i = 0; i < 2*16; i++) {" 17950 " for (var i = 0; i < 2*16; i++) {"
17863 " %_GetFromCache(0, 'a' + i);" 17951 " %_GetFromCache(0, 'a' + i);"
17864 " };" 17952 " };"
17865 " return 'PASSED';" 17953 " return 'PASSED';"
17866 "})()"; 17954 "})()";
17867 HEAP->ClearJSFunctionResultCaches(); 17955 CcTest::heap()->ClearJSFunctionResultCaches();
17868 ExpectString(code, "PASSED"); 17956 ExpectString(code, "PASSED");
17869 } 17957 }
17870 17958
17871 17959
17872 THREADED_TEST(TwoByteStringInAsciiCons) { 17960 THREADED_TEST(TwoByteStringInAsciiCons) {
17873 // See Chromium issue 47824. 17961 // See Chromium issue 47824.
17874 LocalContext context; 17962 LocalContext context;
17875 v8::HandleScope scope(context->GetIsolate()); 17963 v8::HandleScope scope(context->GetIsolate());
17876 17964
17877 const char* init_code = 17965 const char* init_code =
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
17954 18042
17955 ExpectObject("str2.lastIndexOf('dab');", lastindexof); 18043 ExpectObject("str2.lastIndexOf('dab');", lastindexof);
17956 18044
17957 reresult = CompileRun("str2.charCodeAt(2);"); 18045 reresult = CompileRun("str2.charCodeAt(2);");
17958 CHECK_EQ(static_cast<int32_t>('e'), reresult->Int32Value()); 18046 CHECK_EQ(static_cast<int32_t>('e'), reresult->Int32Value());
17959 } 18047 }
17960 18048
17961 18049
17962 TEST(ContainsOnlyOneByte) { 18050 TEST(ContainsOnlyOneByte) {
17963 v8::V8::Initialize(); 18051 v8::V8::Initialize();
17964 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 18052 v8::Isolate* isolate = CcTest::isolate();
17965 v8::HandleScope scope(isolate); 18053 v8::HandleScope scope(isolate);
17966 // Make a buffer long enough that it won't automatically be converted. 18054 // Make a buffer long enough that it won't automatically be converted.
17967 const int length = 512; 18055 const int length = 512;
17968 // Ensure word aligned assignment. 18056 // Ensure word aligned assignment.
17969 const int aligned_length = length*sizeof(uintptr_t)/sizeof(uint16_t); 18057 const int aligned_length = length*sizeof(uintptr_t)/sizeof(uint16_t);
17970 i::SmartArrayPointer<uintptr_t> 18058 i::SmartArrayPointer<uintptr_t>
17971 aligned_contents(new uintptr_t[aligned_length]); 18059 aligned_contents(new uintptr_t[aligned_length]);
17972 uint16_t* string_contents = reinterpret_cast<uint16_t*>(*aligned_contents); 18060 uint16_t* string_contents = reinterpret_cast<uint16_t*>(*aligned_contents);
17973 // Set to contain only one byte. 18061 // Set to contain only one byte.
17974 for (int i = 0; i < length-1; i++) { 18062 for (int i = 0; i < length-1; i++) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
18023 string_contents[zero_offset] = 0x41; 18111 string_contents[zero_offset] = 0x41;
18024 } 18112 }
18025 } 18113 }
18026 } 18114 }
18027 18115
18028 18116
18029 // Failed access check callback that performs a GC on each invocation. 18117 // Failed access check callback that performs a GC on each invocation.
18030 void FailedAccessCheckCallbackGC(Local<v8::Object> target, 18118 void FailedAccessCheckCallbackGC(Local<v8::Object> target,
18031 v8::AccessType type, 18119 v8::AccessType type,
18032 Local<v8::Value> data) { 18120 Local<v8::Value> data) {
18033 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 18121 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
18034 } 18122 }
18035 18123
18036 18124
18037 TEST(GCInFailedAccessCheckCallback) { 18125 TEST(GCInFailedAccessCheckCallback) {
18038 // Install a failed access check callback that performs a GC on each 18126 // Install a failed access check callback that performs a GC on each
18039 // invocation. Then force the callback to be called from va 18127 // invocation. Then force the callback to be called from va
18040 18128
18041 v8::V8::Initialize(); 18129 v8::V8::Initialize();
18042 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckCallbackGC); 18130 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckCallbackGC);
18043 18131
18044 v8::HandleScope scope(v8::Isolate::GetCurrent()); 18132 v8::HandleScope scope(CcTest::isolate());
18045 18133
18046 // Create an ObjectTemplate for global objects and install access 18134 // Create an ObjectTemplate for global objects and install access
18047 // check callbacks that will block access. 18135 // check callbacks that will block access.
18048 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 18136 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
18049 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker, 18137 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker,
18050 IndexedGetAccessBlocker, 18138 IndexedGetAccessBlocker,
18051 v8::Handle<v8::Value>(), 18139 v8::Handle<v8::Value>(),
18052 false); 18140 false);
18053 18141
18054 // Create a context and set an x property on it's global object. 18142 // Create a context and set an x property on it's global object.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
18105 CHECK_EQ(false, global0->HasRealIndexedProperty(0)); 18193 CHECK_EQ(false, global0->HasRealIndexedProperty(0));
18106 CHECK_EQ(false, global0->HasRealNamedProperty(v8_str("x"))); 18194 CHECK_EQ(false, global0->HasRealNamedProperty(v8_str("x")));
18107 CHECK_EQ(false, global0->HasRealNamedCallbackProperty(v8_str("x"))); 18195 CHECK_EQ(false, global0->HasRealNamedCallbackProperty(v8_str("x")));
18108 18196
18109 // Reset the failed access check callback so it does not influence 18197 // Reset the failed access check callback so it does not influence
18110 // the other tests. 18198 // the other tests.
18111 v8::V8::SetFailedAccessCheckCallbackFunction(NULL); 18199 v8::V8::SetFailedAccessCheckCallbackFunction(NULL);
18112 } 18200 }
18113 18201
18114 18202
18115 TEST(DefaultIsolateGetCurrent) {
18116 CHECK(v8::Isolate::GetCurrent() != NULL);
18117 v8::Isolate* isolate = v8::Isolate::GetCurrent();
18118 CHECK(reinterpret_cast<i::Isolate*>(isolate)->IsDefaultIsolate());
18119 printf("*** %s\n", "DefaultIsolateGetCurrent success");
18120 }
18121
18122
18123 TEST(IsolateNewDispose) { 18203 TEST(IsolateNewDispose) {
18124 v8::Isolate* current_isolate = v8::Isolate::GetCurrent(); 18204 v8::Isolate* current_isolate = CcTest::isolate();
18125 v8::Isolate* isolate = v8::Isolate::New(); 18205 v8::Isolate* isolate = v8::Isolate::New();
18126 CHECK(isolate != NULL); 18206 CHECK(isolate != NULL);
18127 CHECK(!reinterpret_cast<i::Isolate*>(isolate)->IsDefaultIsolate()); 18207 CHECK(!reinterpret_cast<i::Isolate*>(isolate)->IsDefaultIsolate());
18128 CHECK(current_isolate != isolate); 18208 CHECK(current_isolate != isolate);
18129 CHECK(current_isolate == v8::Isolate::GetCurrent()); 18209 CHECK(current_isolate == CcTest::isolate());
18130 18210
18131 v8::V8::SetFatalErrorHandler(StoringErrorCallback); 18211 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
18132 last_location = last_message = NULL; 18212 last_location = last_message = NULL;
18133 isolate->Dispose(); 18213 isolate->Dispose();
18134 CHECK_EQ(last_location, NULL); 18214 CHECK_EQ(last_location, NULL);
18135 CHECK_EQ(last_message, NULL); 18215 CHECK_EQ(last_message, NULL);
18136 } 18216 }
18137 18217
18138 18218
18139 TEST(IsolateEnterExitDefault) { 18219 UNINITIALIZED_TEST(DisposeIsolateWhenInUse) {
18140 v8::Isolate* current_isolate = v8::Isolate::GetCurrent();
18141 CHECK(current_isolate != NULL); // Default isolate.
18142 v8::HandleScope scope(current_isolate);
18143 LocalContext context;
18144 ExpectString("'hello'", "hello");
18145 current_isolate->Enter();
18146 ExpectString("'still working'", "still working");
18147 current_isolate->Exit();
18148 ExpectString("'still working 2'", "still working 2");
18149 current_isolate->Exit();
18150 // Default isolate is always, well, 'default current'.
18151 CHECK_EQ(v8::Isolate::GetCurrent(), current_isolate);
18152 // Still working since default isolate is auto-entering any thread
18153 // that has no isolate and attempts to execute V8 APIs.
18154 ExpectString("'still working 3'", "still working 3");
18155 }
18156
18157
18158 TEST(DisposeDefaultIsolate) {
18159 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
18160
18161 // Run some V8 code to trigger default isolate to become 'current'.
18162 v8::HandleScope scope(v8::Isolate::GetCurrent());
18163 LocalContext context;
18164 ExpectString("'run some V8'", "run some V8");
18165
18166 v8::Isolate* isolate = v8::Isolate::GetCurrent();
18167 CHECK(reinterpret_cast<i::Isolate*>(isolate)->IsDefaultIsolate());
18168 last_location = last_message = NULL;
18169 isolate->Dispose();
18170 // It is not possible to dispose default isolate via Isolate API.
18171 CHECK_NE(last_location, NULL);
18172 CHECK_NE(last_message, NULL);
18173 }
18174
18175
18176 TEST(RunDefaultAndAnotherIsolate) {
18177 v8::HandleScope scope(v8::Isolate::GetCurrent());
18178 LocalContext context;
18179
18180 // Enter new isolate.
18181 v8::Isolate* isolate = v8::Isolate::New();
18182 CHECK(isolate);
18183 isolate->Enter();
18184 { // Need this block because subsequent Exit() will deallocate Heap,
18185 // so we need all scope objects to be deconstructed when it happens.
18186 v8::HandleScope scope_new(isolate);
18187 LocalContext context_new;
18188
18189 // Run something in new isolate.
18190 CompileRun("var foo = 153;");
18191 ExpectTrue("function f() { return foo == 153; }; f()");
18192 }
18193 isolate->Exit();
18194
18195 // This runs automatically in default isolate.
18196 // Variables in another isolate should be not available.
18197 ExpectTrue("function f() {"
18198 " try {"
18199 " foo;"
18200 " return false;"
18201 " } catch(e) {"
18202 " return true;"
18203 " }"
18204 "};"
18205 "var bar = 371;"
18206 "f()");
18207
18208 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
18209 last_location = last_message = NULL;
18210 isolate->Dispose();
18211 CHECK_EQ(last_location, NULL);
18212 CHECK_EQ(last_message, NULL);
18213
18214 // Check that default isolate still runs.
18215 ExpectTrue("function f() { return bar == 371; }; f()");
18216 }
18217
18218
18219 TEST(DisposeIsolateWhenInUse) {
18220 v8::Isolate* isolate = v8::Isolate::New(); 18220 v8::Isolate* isolate = v8::Isolate::New();
18221 CHECK(isolate); 18221 CHECK(isolate);
18222 isolate->Enter(); 18222 isolate->Enter();
18223 v8::HandleScope scope(isolate); 18223 v8::HandleScope scope(isolate);
18224 LocalContext context; 18224 LocalContext context(isolate);
18225 // Run something in this isolate. 18225 // Run something in this isolate.
18226 ExpectTrue("true"); 18226 ExpectTrue("true");
18227 v8::V8::SetFatalErrorHandler(StoringErrorCallback); 18227 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
18228 last_location = last_message = NULL; 18228 last_location = last_message = NULL;
18229 // Still entered, should fail. 18229 // Still entered, should fail.
18230 isolate->Dispose(); 18230 isolate->Dispose();
18231 CHECK_NE(last_location, NULL); 18231 CHECK_NE(last_location, NULL);
18232 CHECK_NE(last_message, NULL); 18232 CHECK_NE(last_message, NULL);
18233 } 18233 }
18234 18234
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
18277 v8::Context::Scope context_scope(context); 18277 v8::Context::Scope context_scope(context);
18278 // Now again in isolate 1 18278 // Now again in isolate 1
18279 ExpectString("function f() { return foo; }; f()", "isolate 1"); 18279 ExpectString("function f() { return foo; }; f()", "isolate 1");
18280 } 18280 }
18281 18281
18282 isolate1->Exit(); 18282 isolate1->Exit();
18283 18283
18284 // Run some stuff in default isolate. 18284 // Run some stuff in default isolate.
18285 v8::Persistent<v8::Context> context_default; 18285 v8::Persistent<v8::Context> context_default;
18286 { 18286 {
18287 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 18287 v8::Isolate* isolate = CcTest::isolate();
18288 v8::Isolate::Scope iscope(isolate); 18288 v8::Isolate::Scope iscope(isolate);
18289 v8::HandleScope scope(isolate); 18289 v8::HandleScope scope(isolate);
18290 context_default.Reset(isolate, Context::New(isolate)); 18290 context_default.Reset(isolate, Context::New(isolate));
18291 } 18291 }
18292 18292
18293 { 18293 {
18294 v8::HandleScope scope(v8::Isolate::GetCurrent()); 18294 v8::HandleScope scope(CcTest::isolate());
18295 v8::Local<v8::Context> context = 18295 v8::Local<v8::Context> context =
18296 v8::Local<v8::Context>::New(v8::Isolate::GetCurrent(), context_default); 18296 v8::Local<v8::Context>::New(CcTest::isolate(), context_default);
18297 v8::Context::Scope context_scope(context); 18297 v8::Context::Scope context_scope(context);
18298 // Variables in other isolates should be not available, verify there 18298 // Variables in other isolates should be not available, verify there
18299 // is an exception. 18299 // is an exception.
18300 ExpectTrue("function f() {" 18300 ExpectTrue("function f() {"
18301 " try {" 18301 " try {"
18302 " foo;" 18302 " foo;"
18303 " return false;" 18303 " return false;"
18304 " } catch(e) {" 18304 " } catch(e) {"
18305 " return true;" 18305 " return true;"
18306 " }" 18306 " }"
18307 "};" 18307 "};"
18308 "var isDefaultIsolate = true;" 18308 "var isDefaultIsolate = true;"
18309 "f()"); 18309 "f()");
18310 } 18310 }
18311 18311
18312 isolate1->Enter(); 18312 isolate1->Enter();
18313 18313
18314 { 18314 {
18315 v8::Isolate::Scope iscope(isolate2); 18315 v8::Isolate::Scope iscope(isolate2);
18316 v8::HandleScope scope(v8::Isolate::GetCurrent()); 18316 v8::HandleScope scope(isolate2);
18317 v8::Local<v8::Context> context = 18317 v8::Local<v8::Context> context =
18318 v8::Local<v8::Context>::New(isolate2, context2); 18318 v8::Local<v8::Context>::New(isolate2, context2);
18319 v8::Context::Scope context_scope(context); 18319 v8::Context::Scope context_scope(context);
18320 ExpectString("function f() { return foo; }; f()", "isolate 2"); 18320 ExpectString("function f() { return foo; }; f()", "isolate 2");
18321 } 18321 }
18322 18322
18323 { 18323 {
18324 v8::HandleScope scope(v8::Isolate::GetCurrent()); 18324 v8::HandleScope scope(v8::Isolate::GetCurrent());
18325 v8::Local<v8::Context> context = 18325 v8::Local<v8::Context> context =
18326 v8::Local<v8::Context>::New(v8::Isolate::GetCurrent(), context1); 18326 v8::Local<v8::Context>::New(v8::Isolate::GetCurrent(), context1);
(...skipping 15 matching lines...) Expand all
18342 isolate1->Dispose(); 18342 isolate1->Dispose();
18343 CHECK_EQ(last_location, NULL); 18343 CHECK_EQ(last_location, NULL);
18344 CHECK_EQ(last_message, NULL); 18344 CHECK_EQ(last_message, NULL);
18345 18345
18346 isolate2->Dispose(); 18346 isolate2->Dispose();
18347 CHECK_EQ(last_location, NULL); 18347 CHECK_EQ(last_location, NULL);
18348 CHECK_EQ(last_message, NULL); 18348 CHECK_EQ(last_message, NULL);
18349 18349
18350 // Check that default isolate still runs. 18350 // Check that default isolate still runs.
18351 { 18351 {
18352 v8::HandleScope scope(v8::Isolate::GetCurrent()); 18352 v8::HandleScope scope(CcTest::isolate());
18353 v8::Local<v8::Context> context = 18353 v8::Local<v8::Context> context =
18354 v8::Local<v8::Context>::New(v8::Isolate::GetCurrent(), context_default); 18354 v8::Local<v8::Context>::New(CcTest::isolate(), context_default);
18355 v8::Context::Scope context_scope(context); 18355 v8::Context::Scope context_scope(context);
18356 ExpectTrue("function f() { return isDefaultIsolate; }; f()"); 18356 ExpectTrue("function f() { return isDefaultIsolate; }; f()");
18357 } 18357 }
18358 } 18358 }
18359 18359
18360 18360
18361 static int CalcFibonacci(v8::Isolate* isolate, int limit) { 18361 static int CalcFibonacci(v8::Isolate* isolate, int limit) {
18362 v8::Isolate::Scope isolate_scope(isolate); 18362 v8::Isolate::Scope isolate_scope(isolate);
18363 v8::HandleScope scope(isolate); 18363 v8::HandleScope scope(isolate);
18364 LocalContext context; 18364 LocalContext context(isolate);
18365 i::ScopedVector<char> code(1024); 18365 i::ScopedVector<char> code(1024);
18366 i::OS::SNPrintF(code, "function fib(n) {" 18366 i::OS::SNPrintF(code, "function fib(n) {"
18367 " if (n <= 2) return 1;" 18367 " if (n <= 2) return 1;"
18368 " return fib(n-1) + fib(n-2);" 18368 " return fib(n-1) + fib(n-2);"
18369 "}" 18369 "}"
18370 "fib(%d)", limit); 18370 "fib(%d)", limit);
18371 Local<Value> value = CompileRun(code.start()); 18371 Local<Value> value = CompileRun(code.start());
18372 CHECK(value->IsNumber()); 18372 CHECK(value->IsNumber());
18373 return static_cast<int>(value->NumberValue()); 18373 return static_cast<int>(value->NumberValue());
18374 } 18374 }
(...skipping 23 matching lines...) Expand all
18398 v8::Isolate* isolate1 = v8::Isolate::New(); 18398 v8::Isolate* isolate1 = v8::Isolate::New();
18399 v8::Isolate* isolate2 = v8::Isolate::New(); 18399 v8::Isolate* isolate2 = v8::Isolate::New();
18400 18400
18401 IsolateThread thread1(isolate1, 21); 18401 IsolateThread thread1(isolate1, 21);
18402 IsolateThread thread2(isolate2, 12); 18402 IsolateThread thread2(isolate2, 12);
18403 18403
18404 // Compute some fibonacci numbers on 3 threads in 3 isolates. 18404 // Compute some fibonacci numbers on 3 threads in 3 isolates.
18405 thread1.Start(); 18405 thread1.Start();
18406 thread2.Start(); 18406 thread2.Start();
18407 18407
18408 int result1 = CalcFibonacci(v8::Isolate::GetCurrent(), 21); 18408 int result1 = CalcFibonacci(CcTest::isolate(), 21);
18409 int result2 = CalcFibonacci(v8::Isolate::GetCurrent(), 12); 18409 int result2 = CalcFibonacci(CcTest::isolate(), 12);
18410 18410
18411 thread1.Join(); 18411 thread1.Join();
18412 thread2.Join(); 18412 thread2.Join();
18413 18413
18414 // Compare results. The actual fibonacci numbers for 12 and 21 are taken 18414 // Compare results. The actual fibonacci numbers for 12 and 21 are taken
18415 // (I'm lazy!) from http://en.wikipedia.org/wiki/Fibonacci_number 18415 // (I'm lazy!) from http://en.wikipedia.org/wiki/Fibonacci_number
18416 CHECK_EQ(result1, 10946); 18416 CHECK_EQ(result1, 10946);
18417 CHECK_EQ(result2, 144); 18417 CHECK_EQ(result2, 144);
18418 CHECK_EQ(result1, thread1.result()); 18418 CHECK_EQ(result1, thread1.result());
18419 CHECK_EQ(result2, thread2.result()); 18419 CHECK_EQ(result2, thread2.result());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
18456 SetCreateHistogramFunction, 18456 SetCreateHistogramFunction,
18457 SetAddHistogramSampleFunction 18457 SetAddHistogramSampleFunction
18458 }; 18458 };
18459 18459
18460 explicit InitDefaultIsolateThread(TestCase testCase) 18460 explicit InitDefaultIsolateThread(TestCase testCase)
18461 : Thread("InitDefaultIsolateThread"), 18461 : Thread("InitDefaultIsolateThread"),
18462 testCase_(testCase), 18462 testCase_(testCase),
18463 result_(false) { } 18463 result_(false) { }
18464 18464
18465 void Run() { 18465 void Run() {
18466 v8::Isolate* isolate = v8::Isolate::New();
18467 isolate->Enter();
18466 switch (testCase_) { 18468 switch (testCase_) {
18467 case IgnoreOOM: 18469 case IgnoreOOM:
18468 v8::V8::IgnoreOutOfMemoryException(); 18470 v8::V8::IgnoreOutOfMemoryException();
18469 break; 18471 break;
18470 18472
18471 case SetResourceConstraints: { 18473 case SetResourceConstraints: {
18472 static const int K = 1024; 18474 static const int K = 1024;
18473 v8::ResourceConstraints constraints; 18475 v8::ResourceConstraints constraints;
18474 constraints.set_max_young_space_size(256 * K); 18476 constraints.set_max_young_space_size(256 * K);
18475 constraints.set_max_old_space_size(4 * K * K); 18477 constraints.set_max_old_space_size(4 * K * K);
(...skipping 10 matching lines...) Expand all
18486 break; 18488 break;
18487 18489
18488 case SetCreateHistogramFunction: 18490 case SetCreateHistogramFunction:
18489 v8::V8::SetCreateHistogramFunction(NULL); 18491 v8::V8::SetCreateHistogramFunction(NULL);
18490 break; 18492 break;
18491 18493
18492 case SetAddHistogramSampleFunction: 18494 case SetAddHistogramSampleFunction:
18493 v8::V8::SetAddHistogramSampleFunction(NULL); 18495 v8::V8::SetAddHistogramSampleFunction(NULL);
18494 break; 18496 break;
18495 } 18497 }
18498 isolate->Exit();
18499 isolate->Dispose();
18496 result_ = true; 18500 result_ = true;
18497 } 18501 }
18498 18502
18499 bool result() { return result_; } 18503 bool result() { return result_; }
18500 18504
18501 private: 18505 private:
18502 TestCase testCase_; 18506 TestCase testCase_;
18503 bool result_; 18507 bool result_;
18504 }; 18508 };
18505 18509
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
18637 ExpectBoolean("delete cell", true); 18641 ExpectBoolean("delete cell", true);
18638 ExpectString("(function() {" 18642 ExpectString("(function() {"
18639 " try {" 18643 " try {"
18640 " return readCell();" 18644 " return readCell();"
18641 " } catch(e) {" 18645 " } catch(e) {"
18642 " return e.toString();" 18646 " return e.toString();"
18643 " }" 18647 " }"
18644 "})()", 18648 "})()",
18645 "ReferenceError: cell is not defined"); 18649 "ReferenceError: cell is not defined");
18646 CompileRun("cell = \"new_second\";"); 18650 CompileRun("cell = \"new_second\";");
18647 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 18651 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
18648 ExpectString("readCell()", "new_second"); 18652 ExpectString("readCell()", "new_second");
18649 ExpectString("readCell()", "new_second"); 18653 ExpectString("readCell()", "new_second");
18650 } 18654 }
18651 } 18655 }
18652 18656
18653 18657
18654 TEST(DontDeleteCellLoadICForceDelete) { 18658 TEST(DontDeleteCellLoadICForceDelete) {
18655 const char* function_code = 18659 const char* function_code =
18656 "function readCell() { while (true) { return cell; } }"; 18660 "function readCell() { while (true) { return cell; } }";
18657 18661
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
18709 18713
18710 class Visitor42 : public v8::PersistentHandleVisitor { 18714 class Visitor42 : public v8::PersistentHandleVisitor {
18711 public: 18715 public:
18712 explicit Visitor42(v8::Persistent<v8::Object>* object) 18716 explicit Visitor42(v8::Persistent<v8::Object>* object)
18713 : counter_(0), object_(object) { } 18717 : counter_(0), object_(object) { }
18714 18718
18715 virtual void VisitPersistentHandle(Persistent<Value>* value, 18719 virtual void VisitPersistentHandle(Persistent<Value>* value,
18716 uint16_t class_id) { 18720 uint16_t class_id) {
18717 if (class_id != 42) return; 18721 if (class_id != 42) return;
18718 CHECK_EQ(42, value->WrapperClassId()); 18722 CHECK_EQ(42, value->WrapperClassId());
18719 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 18723 v8::Isolate* isolate = CcTest::isolate();
18720 v8::HandleScope handle_scope(isolate); 18724 v8::HandleScope handle_scope(isolate);
18721 v8::Handle<v8::Value> handle = v8::Local<v8::Value>::New(isolate, *value); 18725 v8::Handle<v8::Value> handle = v8::Local<v8::Value>::New(isolate, *value);
18722 v8::Handle<v8::Value> object = 18726 v8::Handle<v8::Value> object =
18723 v8::Local<v8::Object>::New(isolate, *object_); 18727 v8::Local<v8::Object>::New(isolate, *object_);
18724 CHECK(handle->IsObject()); 18728 CHECK(handle->IsObject());
18725 CHECK_EQ(Handle<Object>::Cast(handle), object); 18729 CHECK_EQ(Handle<Object>::Cast(handle), object);
18726 ++counter_; 18730 ++counter_;
18727 } 18731 }
18728 18732
18729 int counter_; 18733 int counter_;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
18762 18766
18763 TEST(PersistentHandleInNewSpaceVisitor) { 18767 TEST(PersistentHandleInNewSpaceVisitor) {
18764 LocalContext context; 18768 LocalContext context;
18765 v8::Isolate* isolate = context->GetIsolate(); 18769 v8::Isolate* isolate = context->GetIsolate();
18766 v8::HandleScope scope(isolate); 18770 v8::HandleScope scope(isolate);
18767 v8::Persistent<v8::Object> object1(isolate, v8::Object::New()); 18771 v8::Persistent<v8::Object> object1(isolate, v8::Object::New());
18768 CHECK_EQ(0, object1.WrapperClassId()); 18772 CHECK_EQ(0, object1.WrapperClassId());
18769 object1.SetWrapperClassId(42); 18773 object1.SetWrapperClassId(42);
18770 CHECK_EQ(42, object1.WrapperClassId()); 18774 CHECK_EQ(42, object1.WrapperClassId());
18771 18775
18772 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 18776 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
18773 18777
18774 v8::Persistent<v8::Object> object2(isolate, v8::Object::New()); 18778 v8::Persistent<v8::Object> object2(isolate, v8::Object::New());
18775 CHECK_EQ(0, object2.WrapperClassId()); 18779 CHECK_EQ(0, object2.WrapperClassId());
18776 object2.SetWrapperClassId(42); 18780 object2.SetWrapperClassId(42);
18777 CHECK_EQ(42, object2.WrapperClassId()); 18781 CHECK_EQ(42, object2.WrapperClassId());
18778 18782
18779 Visitor42 visitor(&object2); 18783 Visitor42 visitor(&object2);
18780 v8::V8::VisitHandlesForPartialDependence(isolate, &visitor); 18784 v8::V8::VisitHandlesForPartialDependence(isolate, &visitor);
18781 CHECK_EQ(1, visitor.counter_); 18785 CHECK_EQ(1, visitor.counter_);
18782 18786
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
18924 Set(v8_str("context_id"), v8::Integer::New(id)); 18928 Set(v8_str("context_id"), v8::Integer::New(id));
18925 } 18929 }
18926 18930
18927 18931
18928 static void CheckContextId(v8::Handle<Object> object, int expected) { 18932 static void CheckContextId(v8::Handle<Object> object, int expected) {
18929 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value()); 18933 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value());
18930 } 18934 }
18931 18935
18932 18936
18933 THREADED_TEST(CreationContext) { 18937 THREADED_TEST(CreationContext) {
18934 HandleScope handle_scope(v8::Isolate::GetCurrent()); 18938 HandleScope handle_scope(CcTest::isolate());
18935 Handle<Context> context1 = Context::New(v8::Isolate::GetCurrent()); 18939 Handle<Context> context1 = Context::New(CcTest::isolate());
18936 InstallContextId(context1, 1); 18940 InstallContextId(context1, 1);
18937 Handle<Context> context2 = Context::New(v8::Isolate::GetCurrent()); 18941 Handle<Context> context2 = Context::New(CcTest::isolate());
18938 InstallContextId(context2, 2); 18942 InstallContextId(context2, 2);
18939 Handle<Context> context3 = Context::New(v8::Isolate::GetCurrent()); 18943 Handle<Context> context3 = Context::New(CcTest::isolate());
18940 InstallContextId(context3, 3); 18944 InstallContextId(context3, 3);
18941 18945
18942 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); 18946 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New();
18943 18947
18944 Local<Object> object1; 18948 Local<Object> object1;
18945 Local<Function> func1; 18949 Local<Function> func1;
18946 { 18950 {
18947 Context::Scope scope(context1); 18951 Context::Scope scope(context1);
18948 object1 = Object::New(); 18952 object1 = Object::New();
18949 func1 = tmpl->GetFunction(); 18953 func1 = tmpl->GetFunction();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
19007 CheckContextId(object2, 2); 19011 CheckContextId(object2, 2);
19008 CHECK(func2->CreationContext() == context2); 19012 CHECK(func2->CreationContext() == context2);
19009 CheckContextId(func2, 2); 19013 CheckContextId(func2, 2);
19010 CHECK(instance2->CreationContext() == context2); 19014 CHECK(instance2->CreationContext() == context2);
19011 CheckContextId(instance2, 2); 19015 CheckContextId(instance2, 2);
19012 } 19016 }
19013 } 19017 }
19014 19018
19015 19019
19016 THREADED_TEST(CreationContextOfJsFunction) { 19020 THREADED_TEST(CreationContextOfJsFunction) {
19017 HandleScope handle_scope(v8::Isolate::GetCurrent()); 19021 HandleScope handle_scope(CcTest::isolate());
19018 Handle<Context> context = Context::New(v8::Isolate::GetCurrent()); 19022 Handle<Context> context = Context::New(CcTest::isolate());
19019 InstallContextId(context, 1); 19023 InstallContextId(context, 1);
19020 19024
19021 Local<Object> function; 19025 Local<Object> function;
19022 { 19026 {
19023 Context::Scope scope(context); 19027 Context::Scope scope(context);
19024 function = CompileRun("function foo() {}; foo").As<Object>(); 19028 function = CompileRun("function foo() {}; foo").As<Object>();
19025 } 19029 }
19026 19030
19027 CHECK(function->CreationContext() == context); 19031 CHECK(function->CreationContext() == context);
19028 CheckContextId(function, 1); 19032 CheckContextId(function, 1);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
19137 0, 19141 0,
19138 HasOwnPropertyNamedPropertyQuery2); 19142 HasOwnPropertyNamedPropertyQuery2);
19139 Handle<Object> instance = templ->NewInstance(); 19143 Handle<Object> instance = templ->NewInstance();
19140 CHECK(!instance->HasOwnProperty(v8_str("foo"))); 19144 CHECK(!instance->HasOwnProperty(v8_str("foo")));
19141 CHECK(instance->HasOwnProperty(v8_str("bar"))); 19145 CHECK(instance->HasOwnProperty(v8_str("bar")));
19142 } 19146 }
19143 } 19147 }
19144 19148
19145 19149
19146 TEST(IndexedInterceptorWithStringProto) { 19150 TEST(IndexedInterceptorWithStringProto) {
19147 v8::HandleScope scope(v8::Isolate::GetCurrent()); 19151 v8::HandleScope scope(CcTest::isolate());
19148 Handle<ObjectTemplate> templ = ObjectTemplate::New(); 19152 Handle<ObjectTemplate> templ = ObjectTemplate::New();
19149 templ->SetIndexedPropertyHandler(NULL, 19153 templ->SetIndexedPropertyHandler(NULL,
19150 NULL, 19154 NULL,
19151 HasOwnPropertyIndexedPropertyQuery); 19155 HasOwnPropertyIndexedPropertyQuery);
19152 LocalContext context; 19156 LocalContext context;
19153 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 19157 context->Global()->Set(v8_str("obj"), templ->NewInstance());
19154 CompileRun("var s = new String('foobar'); obj.__proto__ = s;"); 19158 CompileRun("var s = new String('foobar'); obj.__proto__ = s;");
19155 // These should be intercepted. 19159 // These should be intercepted.
19156 CHECK(CompileRun("42 in obj")->BooleanValue()); 19160 CHECK(CompileRun("42 in obj")->BooleanValue());
19157 CHECK(CompileRun("'42' in obj")->BooleanValue()); 19161 CHECK(CompileRun("'42' in obj")->BooleanValue());
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
19263 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis); 19267 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis);
19264 Handle<Function> function = templ->GetFunction(); 19268 Handle<Function> function = templ->GetFunction();
19265 context->Global()->Set(v8_str("f"), function); 19269 context->Global()->Set(v8_str("f"), function);
19266 TryCatch try_catch; 19270 TryCatch try_catch;
19267 CompileRun("f.call(2)"); 19271 CompileRun("f.call(2)");
19268 } 19272 }
19269 19273
19270 19274
19271 // Regression test for issue 1470. 19275 // Regression test for issue 1470.
19272 THREADED_TEST(ReadOnlyIndexedProperties) { 19276 THREADED_TEST(ReadOnlyIndexedProperties) {
19273 v8::HandleScope scope(v8::Isolate::GetCurrent()); 19277 v8::HandleScope scope(CcTest::isolate());
19274 Local<ObjectTemplate> templ = ObjectTemplate::New(); 19278 Local<ObjectTemplate> templ = ObjectTemplate::New();
19275 19279
19276 LocalContext context; 19280 LocalContext context;
19277 Local<v8::Object> obj = templ->NewInstance(); 19281 Local<v8::Object> obj = templ->NewInstance();
19278 context->Global()->Set(v8_str("obj"), obj); 19282 context->Global()->Set(v8_str("obj"), obj);
19279 obj->Set(v8_str("1"), v8_str("DONT_CHANGE"), v8::ReadOnly); 19283 obj->Set(v8_str("1"), v8_str("DONT_CHANGE"), v8::ReadOnly);
19280 obj->Set(v8_str("1"), v8_str("foobar")); 19284 obj->Set(v8_str("1"), v8_str("foobar"));
19281 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("1"))); 19285 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("1")));
19282 obj->Set(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly); 19286 obj->Set(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly);
19283 obj->Set(v8_num(2), v8_str("foobar")); 19287 obj->Set(v8_num(2), v8_str("foobar"));
19284 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_num(2))); 19288 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_num(2)));
19285 19289
19286 // Test non-smi case. 19290 // Test non-smi case.
19287 obj->Set(v8_str("2000000000"), v8_str("DONT_CHANGE"), v8::ReadOnly); 19291 obj->Set(v8_str("2000000000"), v8_str("DONT_CHANGE"), v8::ReadOnly);
19288 obj->Set(v8_str("2000000000"), v8_str("foobar")); 19292 obj->Set(v8_str("2000000000"), v8_str("foobar"));
19289 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("2000000000"))); 19293 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("2000000000")));
19290 } 19294 }
19291 19295
19292 19296
19293 THREADED_TEST(Regress1516) { 19297 THREADED_TEST(Regress1516) {
19294 LocalContext context; 19298 LocalContext context;
19295 v8::HandleScope scope(context->GetIsolate()); 19299 v8::HandleScope scope(context->GetIsolate());
19296 19300
19297 { v8::HandleScope temp_scope(context->GetIsolate()); 19301 { v8::HandleScope temp_scope(context->GetIsolate());
19298 CompileRun("({'a': 0})"); 19302 CompileRun("({'a': 0})");
19299 } 19303 }
19300 19304
19301 int elements; 19305 int elements;
19302 { i::MapCache* map_cache = 19306 { i::MapCache* map_cache =
19303 i::MapCache::cast(i::Isolate::Current()->context()->map_cache()); 19307 i::MapCache::cast(CcTest::i_isolate()->context()->map_cache());
19304 elements = map_cache->NumberOfElements(); 19308 elements = map_cache->NumberOfElements();
19305 CHECK_LE(1, elements); 19309 CHECK_LE(1, elements);
19306 } 19310 }
19307 19311
19308 i::Isolate::Current()->heap()->CollectAllGarbage( 19312 CcTest::heap()->CollectAllGarbage(
19309 i::Heap::kAbortIncrementalMarkingMask); 19313 i::Heap::kAbortIncrementalMarkingMask);
19310 { i::Object* raw_map_cache = i::Isolate::Current()->context()->map_cache(); 19314 { i::Object* raw_map_cache = CcTest::i_isolate()->context()->map_cache();
19311 if (raw_map_cache != i::Isolate::Current()->heap()->undefined_value()) { 19315 if (raw_map_cache != CcTest::heap()->undefined_value()) {
19312 i::MapCache* map_cache = i::MapCache::cast(raw_map_cache); 19316 i::MapCache* map_cache = i::MapCache::cast(raw_map_cache);
19313 CHECK_GT(elements, map_cache->NumberOfElements()); 19317 CHECK_GT(elements, map_cache->NumberOfElements());
19314 } 19318 }
19315 } 19319 }
19316 } 19320 }
19317 19321
19318 19322
19319 static bool BlockProtoNamedSecurityTestCallback(Local<v8::Object> global, 19323 static bool BlockProtoNamedSecurityTestCallback(Local<v8::Object> global,
19320 Local<Value> name, 19324 Local<Value> name,
19321 v8::AccessType type, 19325 v8::AccessType type,
19322 Local<Value> data) { 19326 Local<Value> data) {
19323 // Only block read access to __proto__. 19327 // Only block read access to __proto__.
19324 if (type == v8::ACCESS_GET && 19328 if (type == v8::ACCESS_GET &&
19325 name->IsString() && 19329 name->IsString() &&
19326 name->ToString()->Length() == 9 && 19330 name->ToString()->Length() == 9 &&
19327 name->ToString()->Utf8Length() == 9) { 19331 name->ToString()->Utf8Length() == 9) {
19328 char buffer[10]; 19332 char buffer[10];
19329 CHECK_EQ(10, name->ToString()->WriteUtf8(buffer)); 19333 CHECK_EQ(10, name->ToString()->WriteUtf8(buffer));
19330 return strncmp(buffer, "__proto__", 9) != 0; 19334 return strncmp(buffer, "__proto__", 9) != 0;
19331 } 19335 }
19332 19336
19333 return true; 19337 return true;
19334 } 19338 }
19335 19339
19336 19340
19337 THREADED_TEST(Regress93759) { 19341 THREADED_TEST(Regress93759) {
19338 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 19342 v8::Isolate* isolate = CcTest::isolate();
19339 HandleScope scope(isolate); 19343 HandleScope scope(isolate);
19340 19344
19341 // Template for object with security check. 19345 // Template for object with security check.
19342 Local<ObjectTemplate> no_proto_template = v8::ObjectTemplate::New(); 19346 Local<ObjectTemplate> no_proto_template = v8::ObjectTemplate::New();
19343 // We don't do indexing, so any callback can be used for that. 19347 // We don't do indexing, so any callback can be used for that.
19344 no_proto_template->SetAccessCheckCallbacks( 19348 no_proto_template->SetAccessCheckCallbacks(
19345 BlockProtoNamedSecurityTestCallback, 19349 BlockProtoNamedSecurityTestCallback,
19346 IndexedSecurityTestCallback); 19350 IndexedSecurityTestCallback);
19347 19351
19348 // Templates for objects with hidden prototypes and possibly security check. 19352 // Templates for objects with hidden prototypes and possibly security check.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
19418 Local<Value> result5 = CompileRun("Object.getPrototypeOf(hidden)"); 19422 Local<Value> result5 = CompileRun("Object.getPrototypeOf(hidden)");
19419 CHECK(result5->Equals( 19423 CHECK(result5->Equals(
19420 object_with_hidden->GetPrototype()->ToObject()->GetPrototype())); 19424 object_with_hidden->GetPrototype()->ToObject()->GetPrototype()));
19421 19425
19422 Local<Value> result6 = CompileRun("Object.getPrototypeOf(phidden)"); 19426 Local<Value> result6 = CompileRun("Object.getPrototypeOf(phidden)");
19423 CHECK(result6->Equals(Undefined())); 19427 CHECK(result6->Equals(Undefined()));
19424 } 19428 }
19425 19429
19426 19430
19427 THREADED_TEST(Regress125988) { 19431 THREADED_TEST(Regress125988) {
19428 v8::HandleScope scope(v8::Isolate::GetCurrent()); 19432 v8::HandleScope scope(CcTest::isolate());
19429 Handle<FunctionTemplate> intercept = FunctionTemplate::New(); 19433 Handle<FunctionTemplate> intercept = FunctionTemplate::New();
19430 AddInterceptor(intercept, EmptyInterceptorGetter, EmptyInterceptorSetter); 19434 AddInterceptor(intercept, EmptyInterceptorGetter, EmptyInterceptorSetter);
19431 LocalContext env; 19435 LocalContext env;
19432 env->Global()->Set(v8_str("Intercept"), intercept->GetFunction()); 19436 env->Global()->Set(v8_str("Intercept"), intercept->GetFunction());
19433 CompileRun("var a = new Object();" 19437 CompileRun("var a = new Object();"
19434 "var b = new Intercept();" 19438 "var b = new Intercept();"
19435 "var c = new Object();" 19439 "var c = new Object();"
19436 "c.__proto__ = b;" 19440 "c.__proto__ = b;"
19437 "b.__proto__ = a;" 19441 "b.__proto__ = a;"
19438 "a.x = 23;" 19442 "a.x = 23;"
(...skipping 13 matching lines...) Expand all
19452 Local<Value> expected_receiver, 19456 Local<Value> expected_receiver,
19453 const char* code) { 19457 const char* code) {
19454 Local<Value> result = CompileRun(code); 19458 Local<Value> result = CompileRun(code);
19455 CHECK(result->IsObject()); 19459 CHECK(result->IsObject());
19456 CHECK(expected_receiver->Equals(result->ToObject()->Get(1))); 19460 CHECK(expected_receiver->Equals(result->ToObject()->Get(1)));
19457 CHECK(expected_result->Equals(result->ToObject()->Get(0))); 19461 CHECK(expected_result->Equals(result->ToObject()->Get(0)));
19458 } 19462 }
19459 19463
19460 19464
19461 THREADED_TEST(ForeignFunctionReceiver) { 19465 THREADED_TEST(ForeignFunctionReceiver) {
19462 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 19466 v8::Isolate* isolate = CcTest::isolate();
19463 HandleScope scope(isolate); 19467 HandleScope scope(isolate);
19464 19468
19465 // Create two contexts with different "id" properties ('i' and 'o'). 19469 // Create two contexts with different "id" properties ('i' and 'o').
19466 // Call a function both from its own context and from a the foreign 19470 // Call a function both from its own context and from a the foreign
19467 // context, and see what "this" is bound to (returning both "this" 19471 // context, and see what "this" is bound to (returning both "this"
19468 // and "this.id" for comparison). 19472 // and "this.id" for comparison).
19469 19473
19470 Local<Context> foreign_context = v8::Context::New(isolate); 19474 Local<Context> foreign_context = v8::Context::New(isolate);
19471 foreign_context->Enter(); 19475 foreign_context->Enter();
19472 Local<Value> foreign_function = 19476 Local<Value> foreign_function =
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
19611 callback_fired = 0; 19615 callback_fired = 0;
19612 Local<Function> recursive_function = 19616 Local<Function> recursive_function =
19613 Local<Function>::Cast(env->Global()->Get(v8_str("recursion"))); 19617 Local<Function>::Cast(env->Global()->Get(v8_str("recursion")));
19614 v8::Handle<Value> args[] = { v8_num(0) }; 19618 v8::Handle<Value> args[] = { v8_num(0) };
19615 recursive_function->Call(env->Global(), 1, args); 19619 recursive_function->Call(env->Global(), 1, args);
19616 CHECK_EQ(2, callback_fired); 19620 CHECK_EQ(2, callback_fired);
19617 } 19621 }
19618 19622
19619 19623
19620 void CallCompletedCallbackNoException() { 19624 void CallCompletedCallbackNoException() {
19621 v8::HandleScope scope(v8::Isolate::GetCurrent()); 19625 v8::HandleScope scope(CcTest::isolate());
19622 CompileRun("1+1;"); 19626 CompileRun("1+1;");
19623 } 19627 }
19624 19628
19625 19629
19626 void CallCompletedCallbackException() { 19630 void CallCompletedCallbackException() {
19627 v8::HandleScope scope(v8::Isolate::GetCurrent()); 19631 v8::HandleScope scope(CcTest::isolate());
19628 CompileRun("throw 'second exception';"); 19632 CompileRun("throw 'second exception';");
19629 } 19633 }
19630 19634
19631 19635
19632 TEST(CallCompletedCallbackOneException) { 19636 TEST(CallCompletedCallbackOneException) {
19633 LocalContext env; 19637 LocalContext env;
19634 v8::HandleScope scope(env->GetIsolate()); 19638 v8::HandleScope scope(env->GetIsolate());
19635 v8::V8::AddCallCompletedCallback(CallCompletedCallbackNoException); 19639 v8::V8::AddCallCompletedCallback(CallCompletedCallbackNoException);
19636 CompileRun("throw 'exception';"); 19640 CompileRun("throw 'exception';");
19637 } 19641 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
19708 } 19712 }
19709 19713
19710 19714
19711 TEST(PrimaryStubCache) { 19715 TEST(PrimaryStubCache) {
19712 StubCacheHelper(false); 19716 StubCacheHelper(false);
19713 } 19717 }
19714 19718
19715 19719
19716 TEST(StaticGetters) { 19720 TEST(StaticGetters) {
19717 LocalContext context; 19721 LocalContext context;
19718 i::Factory* factory = i::Isolate::Current()->factory(); 19722 i::Factory* factory = CcTest::i_isolate()->factory();
19719 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 19723 v8::Isolate* isolate = CcTest::isolate();
19720 v8::HandleScope scope(isolate); 19724 v8::HandleScope scope(isolate);
19721 i::Handle<i::Object> undefined_value = factory->undefined_value(); 19725 i::Handle<i::Object> undefined_value = factory->undefined_value();
19722 CHECK(*v8::Utils::OpenHandle(*v8::Undefined()) == *undefined_value); 19726 CHECK(*v8::Utils::OpenHandle(*v8::Undefined()) == *undefined_value);
19723 CHECK(*v8::Utils::OpenHandle(*v8::Undefined(isolate)) == *undefined_value); 19727 CHECK(*v8::Utils::OpenHandle(*v8::Undefined(isolate)) == *undefined_value);
19724 i::Handle<i::Object> null_value = factory->null_value(); 19728 i::Handle<i::Object> null_value = factory->null_value();
19725 CHECK(*v8::Utils::OpenHandle(*v8::Null()) == *null_value); 19729 CHECK(*v8::Utils::OpenHandle(*v8::Null()) == *null_value);
19726 CHECK(*v8::Utils::OpenHandle(*v8::Null(isolate)) == *null_value); 19730 CHECK(*v8::Utils::OpenHandle(*v8::Null(isolate)) == *null_value);
19727 i::Handle<i::Object> true_value = factory->true_value(); 19731 i::Handle<i::Object> true_value = factory->true_value();
19728 CHECK(*v8::Utils::OpenHandle(*v8::True()) == *true_value); 19732 CHECK(*v8::Utils::OpenHandle(*v8::True()) == *true_value);
19729 CHECK(*v8::Utils::OpenHandle(*v8::True(isolate)) == *true_value); 19733 CHECK(*v8::Utils::OpenHandle(*v8::True(isolate)) == *true_value);
19730 i::Handle<i::Object> false_value = factory->false_value(); 19734 i::Handle<i::Object> false_value = factory->false_value();
19731 CHECK(*v8::Utils::OpenHandle(*v8::False()) == *false_value); 19735 CHECK(*v8::Utils::OpenHandle(*v8::False()) == *false_value);
19732 CHECK(*v8::Utils::OpenHandle(*v8::False(isolate)) == *false_value); 19736 CHECK(*v8::Utils::OpenHandle(*v8::False(isolate)) == *false_value);
19733 } 19737 }
19734 19738
19735 19739
19736 TEST(IsolateEmbedderData) { 19740 UNINITIALIZED_TEST(IsolateEmbedderData) {
19737 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 19741 v8::Isolate* isolate = CcTest::isolate();
19738 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 19742 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
19739 CHECK_EQ(NULL, isolate->GetData()); 19743 CHECK_EQ(NULL, isolate->GetData());
19740 CHECK_EQ(NULL, i_isolate->GetData()); 19744 CHECK_EQ(NULL, i_isolate->GetData());
19741 static void* data1 = reinterpret_cast<void*>(0xacce55ed); 19745 static void* data1 = reinterpret_cast<void*>(0xacce55ed);
19742 isolate->SetData(data1); 19746 isolate->SetData(data1);
19743 CHECK_EQ(data1, isolate->GetData()); 19747 CHECK_EQ(data1, isolate->GetData());
19744 CHECK_EQ(data1, i_isolate->GetData()); 19748 CHECK_EQ(data1, i_isolate->GetData());
19745 static void* data2 = reinterpret_cast<void*>(0xdecea5ed); 19749 static void* data2 = reinterpret_cast<void*>(0xdecea5ed);
19746 i_isolate->SetData(data2); 19750 i_isolate->SetData(data2);
19747 CHECK_EQ(data2, isolate->GetData()); 19751 CHECK_EQ(data2, isolate->GetData());
19748 CHECK_EQ(data2, i_isolate->GetData()); 19752 CHECK_EQ(data2, i_isolate->GetData());
19749 i_isolate->TearDown(); 19753 i_isolate->TearDown();
19750 CHECK_EQ(data2, isolate->GetData()); 19754 CHECK_EQ(data2, isolate->GetData());
19751 CHECK_EQ(data2, i_isolate->GetData()); 19755 CHECK_EQ(data2, i_isolate->GetData());
19752 } 19756 }
19753 19757
19754 19758
19755 TEST(StringEmpty) { 19759 TEST(StringEmpty) {
19756 LocalContext context; 19760 LocalContext context;
19757 i::Factory* factory = i::Isolate::Current()->factory(); 19761 i::Factory* factory = CcTest::i_isolate()->factory();
19758 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 19762 v8::Isolate* isolate = CcTest::isolate();
19759 v8::HandleScope scope(isolate); 19763 v8::HandleScope scope(isolate);
19760 i::Handle<i::Object> empty_string = factory->empty_string(); 19764 i::Handle<i::Object> empty_string = factory->empty_string();
19761 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty()) == *empty_string); 19765 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty()) == *empty_string);
19762 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty(isolate)) == *empty_string); 19766 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty(isolate)) == *empty_string);
19763 } 19767 }
19764 19768
19765 19769
19766 static int instance_checked_getter_count = 0; 19770 static int instance_checked_getter_count = 0;
19767 static void InstanceCheckedGetter( 19771 static void InstanceCheckedGetter(
19768 Local<String> name, 19772 Local<String> name,
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
20022 } else { 20026 } else {
20023 CHECK_EQ(do_store ? 23 : 42, 20027 CHECK_EQ(do_store ? 23 : 42,
20024 context->Global()->Get(v8_str("result"))->Int32Value()); 20028 context->Global()->Get(v8_str("result"))->Int32Value());
20025 } 20029 }
20026 } 20030 }
20027 20031
20028 20032
20029 THREADED_TEST(Regress137002a) { 20033 THREADED_TEST(Regress137002a) {
20030 i::FLAG_allow_natives_syntax = true; 20034 i::FLAG_allow_natives_syntax = true;
20031 i::FLAG_compilation_cache = false; 20035 i::FLAG_compilation_cache = false;
20032 v8::HandleScope scope(v8::Isolate::GetCurrent()); 20036 v8::HandleScope scope(CcTest::isolate());
20033 for (int i = 0; i < 16; i++) { 20037 for (int i = 0; i < 16; i++) {
20034 Helper137002(i & 8, i & 4, i & 2, i & 1); 20038 Helper137002(i & 8, i & 4, i & 2, i & 1);
20035 } 20039 }
20036 } 20040 }
20037 20041
20038 20042
20039 THREADED_TEST(Regress137002b) { 20043 THREADED_TEST(Regress137002b) {
20040 i::FLAG_allow_natives_syntax = true; 20044 i::FLAG_allow_natives_syntax = true;
20041 LocalContext context; 20045 LocalContext context;
20042 v8::HandleScope scope(context->GetIsolate()); 20046 v8::HandleScope scope(context->GetIsolate());
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
20290 } 20294 }
20291 20295
20292 20296
20293 void UnreachableCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { 20297 void UnreachableCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
20294 CHECK(false); 20298 CHECK(false);
20295 } 20299 }
20296 20300
20297 20301
20298 TEST(JSONStringifyAccessCheck) { 20302 TEST(JSONStringifyAccessCheck) {
20299 v8::V8::Initialize(); 20303 v8::V8::Initialize();
20300 v8::HandleScope scope(v8::Isolate::GetCurrent()); 20304 v8::HandleScope scope(CcTest::isolate());
20301 20305
20302 // Create an ObjectTemplate for global objects and install access 20306 // Create an ObjectTemplate for global objects and install access
20303 // check callbacks that will block access. 20307 // check callbacks that will block access.
20304 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 20308 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
20305 global_template->SetAccessCheckCallbacks(NamedAccessAlwaysBlocked, 20309 global_template->SetAccessCheckCallbacks(NamedAccessAlwaysBlocked,
20306 IndexAccessAlwaysBlocked); 20310 IndexAccessAlwaysBlocked);
20307 20311
20308 // Create a context and set an x property on it's global object. 20312 // Create a context and set an x property on it's global object.
20309 LocalContext context0(NULL, global_template); 20313 LocalContext context0(NULL, global_template);
20310 v8::Handle<v8::Object> global0 = context0->Global(); 20314 v8::Handle<v8::Object> global0 = context0->Global();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
20387 CompileRun("try { [1, 2, 3].sort(); } catch (e) { catcher(e) };"); 20391 CompileRun("try { [1, 2, 3].sort(); } catch (e) { catcher(e) };");
20388 CHECK(!access_check_fail_thrown); 20392 CHECK(!access_check_fail_thrown);
20389 CHECK(!catch_callback_called); 20393 CHECK(!catch_callback_called);
20390 } 20394 }
20391 20395
20392 20396
20393 TEST(AccessCheckThrows) { 20397 TEST(AccessCheckThrows) {
20394 i::FLAG_allow_natives_syntax = true; 20398 i::FLAG_allow_natives_syntax = true;
20395 v8::V8::Initialize(); 20399 v8::V8::Initialize();
20396 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckThrows); 20400 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckThrows);
20397 v8::HandleScope scope(v8::Isolate::GetCurrent()); 20401 v8::HandleScope scope(CcTest::isolate());
20398 20402
20399 // Create an ObjectTemplate for global objects and install access 20403 // Create an ObjectTemplate for global objects and install access
20400 // check callbacks that will block access. 20404 // check callbacks that will block access.
20401 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 20405 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
20402 global_template->SetAccessCheckCallbacks(NamedAccessAlwaysBlocked, 20406 global_template->SetAccessCheckCallbacks(NamedAccessAlwaysBlocked,
20403 IndexAccessAlwaysBlocked); 20407 IndexAccessAlwaysBlocked);
20404 20408
20405 // Create a context and set an x property on it's global object. 20409 // Create a context and set an x property on it's global object.
20406 LocalContext context0(NULL, global_template); 20410 LocalContext context0(NULL, global_template);
20407 context0->Global()->Set(v8_str("x"), v8_num(42)); 20411 context0->Global()->Set(v8_str("x"), v8_num(42));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
20463 "function f(o) { o.x = 10; };" 20467 "function f(o) { o.x = 10; };"
20464 "f(o); f(o); f(o);" 20468 "f(o); f(o); f(o);"
20465 "%OptimizeFunctionOnNextCall(f);" 20469 "%OptimizeFunctionOnNextCall(f);"
20466 "f(o);"); 20470 "f(o);");
20467 ExpectBoolean("%GetOptimizationStatus(f) != 2", true); 20471 ExpectBoolean("%GetOptimizationStatus(f) != 2", true);
20468 } 20472 }
20469 20473
20470 20474
20471 THREADED_TEST(CrankshaftInterceptorSetter) { 20475 THREADED_TEST(CrankshaftInterceptorSetter) {
20472 i::FLAG_allow_natives_syntax = true; 20476 i::FLAG_allow_natives_syntax = true;
20473 v8::HandleScope scope(v8::Isolate::GetCurrent()); 20477 v8::HandleScope scope(CcTest::isolate());
20474 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 20478 Handle<FunctionTemplate> templ = FunctionTemplate::New();
20475 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 20479 AddInterceptor(templ, InterceptorGetter, InterceptorSetter);
20476 LocalContext env; 20480 LocalContext env;
20477 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); 20481 env->Global()->Set(v8_str("Obj"), templ->GetFunction());
20478 CompileRun("var obj = new Obj;" 20482 CompileRun("var obj = new Obj;"
20479 // Initialize fields to avoid transitions later. 20483 // Initialize fields to avoid transitions later.
20480 "obj.age = 0;" 20484 "obj.age = 0;"
20481 "obj.accessor_age = 42;" 20485 "obj.accessor_age = 42;"
20482 "function setter(i) { this.accessor_age = i; };" 20486 "function setter(i) { this.accessor_age = i; };"
20483 "function getter() { return this.accessor_age; };" 20487 "function getter() { return this.accessor_age; };"
20484 "function setAge(i) { obj.age = i; };" 20488 "function setAge(i) { obj.age = i; };"
20485 "Object.defineProperty(obj, 'age', { get:getter, set:setter });" 20489 "Object.defineProperty(obj, 'age', { get:getter, set:setter });"
20486 "setAge(1);" 20490 "setAge(1);"
20487 "setAge(2);" 20491 "setAge(2);"
20488 "setAge(3);" 20492 "setAge(3);"
20489 "%OptimizeFunctionOnNextCall(setAge);" 20493 "%OptimizeFunctionOnNextCall(setAge);"
20490 "setAge(4);"); 20494 "setAge(4);");
20491 // All stores went through the interceptor. 20495 // All stores went through the interceptor.
20492 ExpectInt32("obj.interceptor_age", 4); 20496 ExpectInt32("obj.interceptor_age", 4);
20493 ExpectInt32("obj.accessor_age", 42); 20497 ExpectInt32("obj.accessor_age", 42);
20494 } 20498 }
20495 20499
20496 20500
20497 THREADED_TEST(CrankshaftInterceptorGetter) { 20501 THREADED_TEST(CrankshaftInterceptorGetter) {
20498 i::FLAG_allow_natives_syntax = true; 20502 i::FLAG_allow_natives_syntax = true;
20499 v8::HandleScope scope(v8::Isolate::GetCurrent()); 20503 v8::HandleScope scope(CcTest::isolate());
20500 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 20504 Handle<FunctionTemplate> templ = FunctionTemplate::New();
20501 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 20505 AddInterceptor(templ, InterceptorGetter, InterceptorSetter);
20502 LocalContext env; 20506 LocalContext env;
20503 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); 20507 env->Global()->Set(v8_str("Obj"), templ->GetFunction());
20504 CompileRun("var obj = new Obj;" 20508 CompileRun("var obj = new Obj;"
20505 // Initialize fields to avoid transitions later. 20509 // Initialize fields to avoid transitions later.
20506 "obj.age = 1;" 20510 "obj.age = 1;"
20507 "obj.accessor_age = 42;" 20511 "obj.accessor_age = 42;"
20508 "function getter() { return this.accessor_age; };" 20512 "function getter() { return this.accessor_age; };"
20509 "function getAge() { return obj.interceptor_age; };" 20513 "function getAge() { return obj.interceptor_age; };"
20510 "Object.defineProperty(obj, 'interceptor_age', { get:getter });" 20514 "Object.defineProperty(obj, 'interceptor_age', { get:getter });"
20511 "getAge();" 20515 "getAge();"
20512 "getAge();" 20516 "getAge();"
20513 "getAge();" 20517 "getAge();"
20514 "%OptimizeFunctionOnNextCall(getAge);"); 20518 "%OptimizeFunctionOnNextCall(getAge);");
20515 // Access through interceptor. 20519 // Access through interceptor.
20516 ExpectInt32("getAge()", 1); 20520 ExpectInt32("getAge()", 1);
20517 } 20521 }
20518 20522
20519 20523
20520 THREADED_TEST(CrankshaftInterceptorFieldRead) { 20524 THREADED_TEST(CrankshaftInterceptorFieldRead) {
20521 i::FLAG_allow_natives_syntax = true; 20525 i::FLAG_allow_natives_syntax = true;
20522 v8::HandleScope scope(v8::Isolate::GetCurrent()); 20526 v8::HandleScope scope(CcTest::isolate());
20523 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 20527 Handle<FunctionTemplate> templ = FunctionTemplate::New();
20524 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 20528 AddInterceptor(templ, InterceptorGetter, InterceptorSetter);
20525 LocalContext env; 20529 LocalContext env;
20526 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); 20530 env->Global()->Set(v8_str("Obj"), templ->GetFunction());
20527 CompileRun("var obj = new Obj;" 20531 CompileRun("var obj = new Obj;"
20528 "obj.__proto__.interceptor_age = 42;" 20532 "obj.__proto__.interceptor_age = 42;"
20529 "obj.age = 100;" 20533 "obj.age = 100;"
20530 "function getAge() { return obj.interceptor_age; };"); 20534 "function getAge() { return obj.interceptor_age; };");
20531 ExpectInt32("getAge();", 100); 20535 ExpectInt32("getAge();", 100);
20532 ExpectInt32("getAge();", 100); 20536 ExpectInt32("getAge();", 100);
20533 ExpectInt32("getAge();", 100); 20537 ExpectInt32("getAge();", 100);
20534 CompileRun("%OptimizeFunctionOnNextCall(getAge);"); 20538 CompileRun("%OptimizeFunctionOnNextCall(getAge);");
20535 // Access through interceptor. 20539 // Access through interceptor.
20536 ExpectInt32("getAge();", 100); 20540 ExpectInt32("getAge();", 100);
20537 } 20541 }
20538 20542
20539 20543
20540 THREADED_TEST(CrankshaftInterceptorFieldWrite) { 20544 THREADED_TEST(CrankshaftInterceptorFieldWrite) {
20541 i::FLAG_allow_natives_syntax = true; 20545 i::FLAG_allow_natives_syntax = true;
20542 v8::HandleScope scope(v8::Isolate::GetCurrent()); 20546 v8::HandleScope scope(CcTest::isolate());
20543 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 20547 Handle<FunctionTemplate> templ = FunctionTemplate::New();
20544 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 20548 AddInterceptor(templ, InterceptorGetter, InterceptorSetter);
20545 LocalContext env; 20549 LocalContext env;
20546 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); 20550 env->Global()->Set(v8_str("Obj"), templ->GetFunction());
20547 CompileRun("var obj = new Obj;" 20551 CompileRun("var obj = new Obj;"
20548 "obj.age = 100000;" 20552 "obj.age = 100000;"
20549 "function setAge(i) { obj.age = i };" 20553 "function setAge(i) { obj.age = i };"
20550 "setAge(100);" 20554 "setAge(100);"
20551 "setAge(101);" 20555 "setAge(101);"
20552 "setAge(102);" 20556 "setAge(102);"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
20589 Local<Object> data2 = v8::Object::New(); 20593 Local<Object> data2 = v8::Object::New();
20590 function_new_expected_env = data2; 20594 function_new_expected_env = data2;
20591 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2); 20595 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2);
20592 CHECK(!func2->IsNull()); 20596 CHECK(!func2->IsNull());
20593 CHECK_NE(func, func2); 20597 CHECK_NE(func, func2);
20594 env->Global()->Set(v8_str("func2"), func2); 20598 env->Global()->Set(v8_str("func2"), func2);
20595 Local<Value> result2 = CompileRun("func2();"); 20599 Local<Value> result2 = CompileRun("func2();");
20596 CHECK_EQ(v8::Integer::New(17, isolate), result2); 20600 CHECK_EQ(v8::Integer::New(17, isolate), result2);
20597 } 20601 }
20598 20602
OLDNEW
« no previous file with comments | « test/cctest/test-alloc.cc ('k') | test/cctest/test-assembler-arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698