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

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

Issue 112863002: Merge bleeding_edge 18021:18297 (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-accessors.cc ('k') | test/cctest/test-assembler-ia32.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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 143
144 144
145 static int signature_callback_count; 145 static int signature_callback_count;
146 static Local<Value> signature_expected_receiver; 146 static Local<Value> signature_expected_receiver;
147 static void IncrementingSignatureCallback( 147 static void IncrementingSignatureCallback(
148 const v8::FunctionCallbackInfo<v8::Value>& args) { 148 const v8::FunctionCallbackInfo<v8::Value>& args) {
149 ApiTestFuzzer::Fuzz(); 149 ApiTestFuzzer::Fuzz();
150 signature_callback_count++; 150 signature_callback_count++;
151 CHECK_EQ(signature_expected_receiver, args.Holder()); 151 CHECK_EQ(signature_expected_receiver, args.Holder());
152 CHECK_EQ(signature_expected_receiver, args.This()); 152 CHECK_EQ(signature_expected_receiver, args.This());
153 v8::Handle<v8::Array> result = v8::Array::New(args.Length()); 153 v8::Handle<v8::Array> result =
154 v8::Array::New(args.GetIsolate(), args.Length());
154 for (int i = 0; i < args.Length(); i++) 155 for (int i = 0; i < args.Length(); i++)
155 result->Set(v8::Integer::New(i), args[i]); 156 result->Set(v8::Integer::New(i), args[i]);
156 args.GetReturnValue().Set(result); 157 args.GetReturnValue().Set(result);
157 } 158 }
158 159
159 160
160 static void SignatureCallback( 161 static void SignatureCallback(
161 const v8::FunctionCallbackInfo<v8::Value>& args) { 162 const v8::FunctionCallbackInfo<v8::Value>& args) {
162 ApiTestFuzzer::Fuzz(); 163 ApiTestFuzzer::Fuzz();
163 v8::Handle<v8::Array> result = v8::Array::New(args.Length()); 164 v8::Handle<v8::Array> result =
165 v8::Array::New(args.GetIsolate(), args.Length());
164 for (int i = 0; i < args.Length(); i++) { 166 for (int i = 0; i < args.Length(); i++) {
165 result->Set(v8::Integer::New(i), args[i]); 167 result->Set(v8::Integer::New(i), args[i]);
166 } 168 }
167 args.GetReturnValue().Set(result); 169 args.GetReturnValue().Set(result);
168 } 170 }
169 171
170 172
171 // Tests that call v8::V8::Dispose() cannot be threaded. 173 // Tests that call v8::V8::Dispose() cannot be threaded.
172 TEST(InitializeAndDisposeOnce) { 174 TEST(InitializeAndDisposeOnce) {
173 CHECK(v8::V8::Initialize()); 175 CHECK(v8::V8::Initialize());
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 try_catch.Exception()->ToString()); 248 try_catch.Exception()->ToString());
247 } 249 }
248 } 250 }
249 251
250 252
251 THREADED_TEST(ReceiverSignature) { 253 THREADED_TEST(ReceiverSignature) {
252 LocalContext env; 254 LocalContext env;
253 v8::HandleScope scope(env->GetIsolate()); 255 v8::HandleScope scope(env->GetIsolate());
254 // Setup templates. 256 // Setup templates.
255 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(); 257 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New();
256 v8::Handle<v8::Signature> sig = v8::Signature::New(fun); 258 v8::Handle<v8::Signature> sig = v8::Signature::New(env->GetIsolate(), fun);
257 v8::Handle<v8::FunctionTemplate> callback_sig = 259 v8::Handle<v8::FunctionTemplate> callback_sig =
258 v8::FunctionTemplate::New( 260 v8::FunctionTemplate::New(
259 IncrementingSignatureCallback, Local<Value>(), sig); 261 IncrementingSignatureCallback, Local<Value>(), sig);
260 v8::Handle<v8::FunctionTemplate> callback = 262 v8::Handle<v8::FunctionTemplate> callback =
261 v8::FunctionTemplate::New(IncrementingSignatureCallback); 263 v8::FunctionTemplate::New(IncrementingSignatureCallback);
262 v8::Handle<v8::FunctionTemplate> sub_fun = v8::FunctionTemplate::New(); 264 v8::Handle<v8::FunctionTemplate> sub_fun = v8::FunctionTemplate::New();
263 sub_fun->Inherit(fun); 265 sub_fun->Inherit(fun);
264 v8::Handle<v8::FunctionTemplate> unrel_fun = v8::FunctionTemplate::New(); 266 v8::Handle<v8::FunctionTemplate> unrel_fun = v8::FunctionTemplate::New();
265 // Install properties. 267 // Install properties.
266 v8::Handle<v8::ObjectTemplate> fun_proto = fun->PrototypeTemplate(); 268 v8::Handle<v8::ObjectTemplate> fun_proto = fun->PrototypeTemplate();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 TestSignature("test_object[accessor_sig_key] = 1;", test_object); 321 TestSignature("test_object[accessor_sig_key] = 1;", test_object);
320 } 322 }
321 } 323 }
322 324
323 325
324 THREADED_TEST(ArgumentSignature) { 326 THREADED_TEST(ArgumentSignature) {
325 LocalContext env; 327 LocalContext env;
326 v8::HandleScope scope(env->GetIsolate()); 328 v8::HandleScope scope(env->GetIsolate());
327 v8::Handle<v8::FunctionTemplate> cons = v8::FunctionTemplate::New(); 329 v8::Handle<v8::FunctionTemplate> cons = v8::FunctionTemplate::New();
328 cons->SetClassName(v8_str("Cons")); 330 cons->SetClassName(v8_str("Cons"));
329 v8::Handle<v8::Signature> sig = 331 v8::Handle<v8::Signature> sig = v8::Signature::New(
330 v8::Signature::New(v8::Handle<v8::FunctionTemplate>(), 1, &cons); 332 env->GetIsolate(), v8::Handle<v8::FunctionTemplate>(), 1, &cons);
331 v8::Handle<v8::FunctionTemplate> fun = 333 v8::Handle<v8::FunctionTemplate> fun =
332 v8::FunctionTemplate::New(SignatureCallback, v8::Handle<Value>(), sig); 334 v8::FunctionTemplate::New(SignatureCallback, v8::Handle<Value>(), sig);
333 env->Global()->Set(v8_str("Cons"), cons->GetFunction()); 335 env->Global()->Set(v8_str("Cons"), cons->GetFunction());
334 env->Global()->Set(v8_str("Fun1"), fun->GetFunction()); 336 env->Global()->Set(v8_str("Fun1"), fun->GetFunction());
335 337
336 v8::Handle<Value> value1 = CompileRun("Fun1(4) == '';"); 338 v8::Handle<Value> value1 = CompileRun("Fun1(4) == '';");
337 CHECK(value1->IsTrue()); 339 CHECK(value1->IsTrue());
338 340
339 v8::Handle<Value> value2 = CompileRun("Fun1(new Cons()) == '[object Cons]';"); 341 v8::Handle<Value> value2 = CompileRun("Fun1(new Cons()) == '[object Cons]';");
340 CHECK(value2->IsTrue()); 342 CHECK(value2->IsTrue());
341 343
342 v8::Handle<Value> value3 = CompileRun("Fun1() == '';"); 344 v8::Handle<Value> value3 = CompileRun("Fun1() == '';");
343 CHECK(value3->IsTrue()); 345 CHECK(value3->IsTrue());
344 346
345 v8::Handle<v8::FunctionTemplate> cons1 = v8::FunctionTemplate::New(); 347 v8::Handle<v8::FunctionTemplate> cons1 = v8::FunctionTemplate::New();
346 cons1->SetClassName(v8_str("Cons1")); 348 cons1->SetClassName(v8_str("Cons1"));
347 v8::Handle<v8::FunctionTemplate> cons2 = v8::FunctionTemplate::New(); 349 v8::Handle<v8::FunctionTemplate> cons2 = v8::FunctionTemplate::New();
348 cons2->SetClassName(v8_str("Cons2")); 350 cons2->SetClassName(v8_str("Cons2"));
349 v8::Handle<v8::FunctionTemplate> cons3 = v8::FunctionTemplate::New(); 351 v8::Handle<v8::FunctionTemplate> cons3 = v8::FunctionTemplate::New();
350 cons3->SetClassName(v8_str("Cons3")); 352 cons3->SetClassName(v8_str("Cons3"));
351 353
352 v8::Handle<v8::FunctionTemplate> args[3] = { cons1, cons2, cons3 }; 354 v8::Handle<v8::FunctionTemplate> args[3] = { cons1, cons2, cons3 };
353 v8::Handle<v8::Signature> wsig = 355 v8::Handle<v8::Signature> wsig = v8::Signature::New(
354 v8::Signature::New(v8::Handle<v8::FunctionTemplate>(), 3, args); 356 env->GetIsolate(), v8::Handle<v8::FunctionTemplate>(), 3, args);
355 v8::Handle<v8::FunctionTemplate> fun2 = 357 v8::Handle<v8::FunctionTemplate> fun2 =
356 v8::FunctionTemplate::New(SignatureCallback, v8::Handle<Value>(), wsig); 358 v8::FunctionTemplate::New(SignatureCallback, v8::Handle<Value>(), wsig);
357 359
358 env->Global()->Set(v8_str("Cons1"), cons1->GetFunction()); 360 env->Global()->Set(v8_str("Cons1"), cons1->GetFunction());
359 env->Global()->Set(v8_str("Cons2"), cons2->GetFunction()); 361 env->Global()->Set(v8_str("Cons2"), cons2->GetFunction());
360 env->Global()->Set(v8_str("Cons3"), cons3->GetFunction()); 362 env->Global()->Set(v8_str("Cons3"), cons3->GetFunction());
361 env->Global()->Set(v8_str("Fun2"), fun2->GetFunction()); 363 env->Global()->Set(v8_str("Fun2"), fun2->GetFunction());
362 v8::Handle<Value> value4 = CompileRun( 364 v8::Handle<Value> value4 = CompileRun(
363 "Fun2(new Cons1(), new Cons2(), new Cons3()) ==" 365 "Fun2(new Cons1(), new Cons2(), new Cons3()) =="
364 "'[object Cons1],[object Cons2],[object Cons3]'"); 366 "'[object Cons1],[object Cons2],[object Cons3]'");
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 502
501 503
502 THREADED_TEST(ScriptUsingStringResource) { 504 THREADED_TEST(ScriptUsingStringResource) {
503 int dispose_count = 0; 505 int dispose_count = 0;
504 const char* c_source = "1 + 2 * 3"; 506 const char* c_source = "1 + 2 * 3";
505 uint16_t* two_byte_source = AsciiToTwoByteString(c_source); 507 uint16_t* two_byte_source = AsciiToTwoByteString(c_source);
506 { 508 {
507 LocalContext env; 509 LocalContext env;
508 v8::HandleScope scope(env->GetIsolate()); 510 v8::HandleScope scope(env->GetIsolate());
509 TestResource* resource = new TestResource(two_byte_source, &dispose_count); 511 TestResource* resource = new TestResource(two_byte_source, &dispose_count);
510 Local<String> source = String::NewExternal(resource); 512 Local<String> source = String::NewExternal(env->GetIsolate(), resource);
511 Local<Script> script = Script::Compile(source); 513 Local<Script> script = Script::Compile(source);
512 Local<Value> value = script->Run(); 514 Local<Value> value = script->Run();
513 CHECK(value->IsNumber()); 515 CHECK(value->IsNumber());
514 CHECK_EQ(7, value->Int32Value()); 516 CHECK_EQ(7, value->Int32Value());
515 CHECK(source->IsExternal()); 517 CHECK(source->IsExternal());
516 CHECK_EQ(resource, 518 CHECK_EQ(resource,
517 static_cast<TestResource*>(source->GetExternalStringResource())); 519 static_cast<TestResource*>(source->GetExternalStringResource()));
518 String::Encoding encoding = String::UNKNOWN_ENCODING; 520 String::Encoding encoding = String::UNKNOWN_ENCODING;
519 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), 521 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
520 source->GetExternalStringResourceBase(&encoding)); 522 source->GetExternalStringResourceBase(&encoding));
521 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding); 523 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding);
522 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 524 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
523 CHECK_EQ(0, dispose_count); 525 CHECK_EQ(0, dispose_count);
524 } 526 }
525 CcTest::i_isolate()->compilation_cache()->Clear(); 527 CcTest::i_isolate()->compilation_cache()->Clear();
526 CcTest::heap()->CollectAllAvailableGarbage(); 528 CcTest::heap()->CollectAllAvailableGarbage();
527 CHECK_EQ(1, dispose_count); 529 CHECK_EQ(1, dispose_count);
528 } 530 }
529 531
530 532
531 THREADED_TEST(ScriptUsingAsciiStringResource) { 533 THREADED_TEST(ScriptUsingAsciiStringResource) {
532 int dispose_count = 0; 534 int dispose_count = 0;
533 const char* c_source = "1 + 2 * 3"; 535 const char* c_source = "1 + 2 * 3";
534 { 536 {
535 LocalContext env; 537 LocalContext env;
536 v8::HandleScope scope(env->GetIsolate()); 538 v8::HandleScope scope(env->GetIsolate());
537 TestAsciiResource* resource = new TestAsciiResource(i::StrDup(c_source), 539 TestAsciiResource* resource = new TestAsciiResource(i::StrDup(c_source),
538 &dispose_count); 540 &dispose_count);
539 Local<String> source = String::NewExternal(resource); 541 Local<String> source = String::NewExternal(env->GetIsolate(), resource);
540 CHECK(source->IsExternalAscii()); 542 CHECK(source->IsExternalAscii());
541 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), 543 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
542 source->GetExternalAsciiStringResource()); 544 source->GetExternalAsciiStringResource());
543 String::Encoding encoding = String::UNKNOWN_ENCODING; 545 String::Encoding encoding = String::UNKNOWN_ENCODING;
544 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), 546 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
545 source->GetExternalStringResourceBase(&encoding)); 547 source->GetExternalStringResourceBase(&encoding));
546 CHECK_EQ(String::ASCII_ENCODING, encoding); 548 CHECK_EQ(String::ASCII_ENCODING, encoding);
547 Local<Script> script = Script::Compile(source); 549 Local<Script> script = Script::Compile(source);
548 Local<Value> value = script->Run(); 550 Local<Value> value = script->Run();
549 CHECK(value->IsNumber()); 551 CHECK(value->IsNumber());
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 735 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
734 CcTest::heap()->CollectAllGarbage(i::Heap::kReduceMemoryFootprintMask); 736 CcTest::heap()->CollectAllGarbage(i::Heap::kReduceMemoryFootprintMask);
735 } 737 }
736 738
737 739
738 THREADED_TEST(UsingExternalString) { 740 THREADED_TEST(UsingExternalString) {
739 i::Factory* factory = CcTest::i_isolate()->factory(); 741 i::Factory* factory = CcTest::i_isolate()->factory();
740 { 742 {
741 v8::HandleScope scope(CcTest::isolate()); 743 v8::HandleScope scope(CcTest::isolate());
742 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); 744 uint16_t* two_byte_string = AsciiToTwoByteString("test string");
743 Local<String> string = 745 Local<String> string = String::NewExternal(
744 String::NewExternal(new TestResource(two_byte_string)); 746 CcTest::isolate(), new TestResource(two_byte_string));
745 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); 747 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string);
746 // Trigger GCs so that the newly allocated string moves to old gen. 748 // Trigger GCs so that the newly allocated string moves to old gen.
747 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now 749 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now
748 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now 750 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
749 i::Handle<i::String> isymbol = 751 i::Handle<i::String> isymbol =
750 factory->InternalizedStringFromString(istring); 752 factory->InternalizedStringFromString(istring);
751 CHECK(isymbol->IsInternalizedString()); 753 CHECK(isymbol->IsInternalizedString());
752 } 754 }
753 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 755 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
754 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 756 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
755 } 757 }
756 758
757 759
758 THREADED_TEST(UsingExternalAsciiString) { 760 THREADED_TEST(UsingExternalAsciiString) {
759 i::Factory* factory = CcTest::i_isolate()->factory(); 761 i::Factory* factory = CcTest::i_isolate()->factory();
760 { 762 {
761 v8::HandleScope scope(CcTest::isolate()); 763 v8::HandleScope scope(CcTest::isolate());
762 const char* one_byte_string = "test string"; 764 const char* one_byte_string = "test string";
763 Local<String> string = String::NewExternal( 765 Local<String> string = String::NewExternal(
764 new TestAsciiResource(i::StrDup(one_byte_string))); 766 CcTest::isolate(), new TestAsciiResource(i::StrDup(one_byte_string)));
765 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); 767 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string);
766 // Trigger GCs so that the newly allocated string moves to old gen. 768 // Trigger GCs so that the newly allocated string moves to old gen.
767 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now 769 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now
768 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now 770 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
769 i::Handle<i::String> isymbol = 771 i::Handle<i::String> isymbol =
770 factory->InternalizedStringFromString(istring); 772 factory->InternalizedStringFromString(istring);
771 CHECK(isymbol->IsInternalizedString()); 773 CHECK(isymbol->IsInternalizedString());
772 } 774 }
773 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 775 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
774 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 776 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
775 } 777 }
776 778
777 779
778 THREADED_TEST(ScavengeExternalString) { 780 THREADED_TEST(ScavengeExternalString) {
779 i::FLAG_stress_compaction = false; 781 i::FLAG_stress_compaction = false;
780 i::FLAG_gc_global = false; 782 i::FLAG_gc_global = false;
781 int dispose_count = 0; 783 int dispose_count = 0;
782 bool in_new_space = false; 784 bool in_new_space = false;
783 { 785 {
784 v8::HandleScope scope(CcTest::isolate()); 786 v8::HandleScope scope(CcTest::isolate());
785 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); 787 uint16_t* two_byte_string = AsciiToTwoByteString("test string");
786 Local<String> string = 788 Local<String> string = String::NewExternal(
787 String::NewExternal(new TestResource(two_byte_string, 789 CcTest::isolate(), new TestResource(two_byte_string, &dispose_count));
788 &dispose_count));
789 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); 790 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string);
790 CcTest::heap()->CollectGarbage(i::NEW_SPACE); 791 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
791 in_new_space = CcTest::heap()->InNewSpace(*istring); 792 in_new_space = CcTest::heap()->InNewSpace(*istring);
792 CHECK(in_new_space || CcTest::heap()->old_data_space()->Contains(*istring)); 793 CHECK(in_new_space || CcTest::heap()->old_data_space()->Contains(*istring));
793 CHECK_EQ(0, dispose_count); 794 CHECK_EQ(0, dispose_count);
794 } 795 }
795 CcTest::heap()->CollectGarbage( 796 CcTest::heap()->CollectGarbage(
796 in_new_space ? i::NEW_SPACE : i::OLD_DATA_SPACE); 797 in_new_space ? i::NEW_SPACE : i::OLD_DATA_SPACE);
797 CHECK_EQ(1, dispose_count); 798 CHECK_EQ(1, dispose_count);
798 } 799 }
799 800
800 801
801 THREADED_TEST(ScavengeExternalAsciiString) { 802 THREADED_TEST(ScavengeExternalAsciiString) {
802 i::FLAG_stress_compaction = false; 803 i::FLAG_stress_compaction = false;
803 i::FLAG_gc_global = false; 804 i::FLAG_gc_global = false;
804 int dispose_count = 0; 805 int dispose_count = 0;
805 bool in_new_space = false; 806 bool in_new_space = false;
806 { 807 {
807 v8::HandleScope scope(CcTest::isolate()); 808 v8::HandleScope scope(CcTest::isolate());
808 const char* one_byte_string = "test string"; 809 const char* one_byte_string = "test string";
809 Local<String> string = String::NewExternal( 810 Local<String> string = String::NewExternal(
811 CcTest::isolate(),
810 new TestAsciiResource(i::StrDup(one_byte_string), &dispose_count)); 812 new TestAsciiResource(i::StrDup(one_byte_string), &dispose_count));
811 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); 813 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string);
812 CcTest::heap()->CollectGarbage(i::NEW_SPACE); 814 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
813 in_new_space = CcTest::heap()->InNewSpace(*istring); 815 in_new_space = CcTest::heap()->InNewSpace(*istring);
814 CHECK(in_new_space || CcTest::heap()->old_data_space()->Contains(*istring)); 816 CHECK(in_new_space || CcTest::heap()->old_data_space()->Contains(*istring));
815 CHECK_EQ(0, dispose_count); 817 CHECK_EQ(0, dispose_count);
816 } 818 }
817 CcTest::heap()->CollectGarbage( 819 CcTest::heap()->CollectGarbage(
818 in_new_space ? i::NEW_SPACE : i::OLD_DATA_SPACE); 820 in_new_space ? i::NEW_SPACE : i::OLD_DATA_SPACE);
819 CHECK_EQ(1, dispose_count); 821 CHECK_EQ(1, dispose_count);
(...skipping 26 matching lines...) Expand all
846 TEST(ExternalStringWithDisposeHandling) { 848 TEST(ExternalStringWithDisposeHandling) {
847 const char* c_source = "1 + 2 * 3"; 849 const char* c_source = "1 + 2 * 3";
848 850
849 // Use a stack allocated external string resource allocated object. 851 // Use a stack allocated external string resource allocated object.
850 TestAsciiResourceWithDisposeControl::dispose_count = 0; 852 TestAsciiResourceWithDisposeControl::dispose_count = 0;
851 TestAsciiResourceWithDisposeControl::dispose_calls = 0; 853 TestAsciiResourceWithDisposeControl::dispose_calls = 0;
852 TestAsciiResourceWithDisposeControl res_stack(i::StrDup(c_source), false); 854 TestAsciiResourceWithDisposeControl res_stack(i::StrDup(c_source), false);
853 { 855 {
854 LocalContext env; 856 LocalContext env;
855 v8::HandleScope scope(env->GetIsolate()); 857 v8::HandleScope scope(env->GetIsolate());
856 Local<String> source = String::NewExternal(&res_stack); 858 Local<String> source = String::NewExternal(env->GetIsolate(), &res_stack);
857 Local<Script> script = Script::Compile(source); 859 Local<Script> script = Script::Compile(source);
858 Local<Value> value = script->Run(); 860 Local<Value> value = script->Run();
859 CHECK(value->IsNumber()); 861 CHECK(value->IsNumber());
860 CHECK_EQ(7, value->Int32Value()); 862 CHECK_EQ(7, value->Int32Value());
861 CcTest::heap()->CollectAllAvailableGarbage(); 863 CcTest::heap()->CollectAllAvailableGarbage();
862 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count); 864 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count);
863 } 865 }
864 CcTest::i_isolate()->compilation_cache()->Clear(); 866 CcTest::i_isolate()->compilation_cache()->Clear();
865 CcTest::heap()->CollectAllAvailableGarbage(); 867 CcTest::heap()->CollectAllAvailableGarbage();
866 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls); 868 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls);
867 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count); 869 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count);
868 870
869 // Use a heap allocated external string resource allocated object. 871 // Use a heap allocated external string resource allocated object.
870 TestAsciiResourceWithDisposeControl::dispose_count = 0; 872 TestAsciiResourceWithDisposeControl::dispose_count = 0;
871 TestAsciiResourceWithDisposeControl::dispose_calls = 0; 873 TestAsciiResourceWithDisposeControl::dispose_calls = 0;
872 TestAsciiResource* res_heap = 874 TestAsciiResource* res_heap =
873 new TestAsciiResourceWithDisposeControl(i::StrDup(c_source), true); 875 new TestAsciiResourceWithDisposeControl(i::StrDup(c_source), true);
874 { 876 {
875 LocalContext env; 877 LocalContext env;
876 v8::HandleScope scope(env->GetIsolate()); 878 v8::HandleScope scope(env->GetIsolate());
877 Local<String> source = String::NewExternal(res_heap); 879 Local<String> source = String::NewExternal(env->GetIsolate(), res_heap);
878 Local<Script> script = Script::Compile(source); 880 Local<Script> script = Script::Compile(source);
879 Local<Value> value = script->Run(); 881 Local<Value> value = script->Run();
880 CHECK(value->IsNumber()); 882 CHECK(value->IsNumber());
881 CHECK_EQ(7, value->Int32Value()); 883 CHECK_EQ(7, value->Int32Value());
882 CcTest::heap()->CollectAllAvailableGarbage(); 884 CcTest::heap()->CollectAllAvailableGarbage();
883 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count); 885 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count);
884 } 886 }
885 CcTest::i_isolate()->compilation_cache()->Clear(); 887 CcTest::i_isolate()->compilation_cache()->Clear();
886 CcTest::heap()->CollectAllAvailableGarbage(); 888 CcTest::heap()->CollectAllAvailableGarbage();
887 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls); 889 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls);
(...skipping 14 matching lines...) Expand all
902 const char* two_byte_extern_2 = "a_times_two_plus_b(1, 2);"; 904 const char* two_byte_extern_2 = "a_times_two_plus_b(1, 2);";
903 Local<String> left = v8_str(one_byte_string_1); 905 Local<String> left = v8_str(one_byte_string_1);
904 906
905 uint16_t* two_byte_source = AsciiToTwoByteString(two_byte_string_1); 907 uint16_t* two_byte_source = AsciiToTwoByteString(two_byte_string_1);
906 Local<String> right = 908 Local<String> right =
907 String::NewFromTwoByte(env->GetIsolate(), two_byte_source); 909 String::NewFromTwoByte(env->GetIsolate(), two_byte_source);
908 i::DeleteArray(two_byte_source); 910 i::DeleteArray(two_byte_source);
909 911
910 Local<String> source = String::Concat(left, right); 912 Local<String> source = String::Concat(left, right);
911 right = String::NewExternal( 913 right = String::NewExternal(
912 new TestAsciiResource(i::StrDup(one_byte_extern_1))); 914 env->GetIsolate(), new TestAsciiResource(i::StrDup(one_byte_extern_1)));
913 source = String::Concat(source, right); 915 source = String::Concat(source, right);
914 right = String::NewExternal( 916 right = String::NewExternal(
917 env->GetIsolate(),
915 new TestResource(AsciiToTwoByteString(two_byte_extern_1))); 918 new TestResource(AsciiToTwoByteString(two_byte_extern_1)));
916 source = String::Concat(source, right); 919 source = String::Concat(source, right);
917 right = v8_str(one_byte_string_2); 920 right = v8_str(one_byte_string_2);
918 source = String::Concat(source, right); 921 source = String::Concat(source, right);
919 922
920 two_byte_source = AsciiToTwoByteString(two_byte_string_2); 923 two_byte_source = AsciiToTwoByteString(two_byte_string_2);
921 right = String::NewFromTwoByte(env->GetIsolate(), two_byte_source); 924 right = String::NewFromTwoByte(env->GetIsolate(), two_byte_source);
922 i::DeleteArray(two_byte_source); 925 i::DeleteArray(two_byte_source);
923 926
924 source = String::Concat(source, right); 927 source = String::Concat(source, right);
925 right = String::NewExternal( 928 right = String::NewExternal(
929 env->GetIsolate(),
926 new TestResource(AsciiToTwoByteString(two_byte_extern_2))); 930 new TestResource(AsciiToTwoByteString(two_byte_extern_2)));
927 source = String::Concat(source, right); 931 source = String::Concat(source, right);
928 Local<Script> script = Script::Compile(source); 932 Local<Script> script = Script::Compile(source);
929 Local<Value> value = script->Run(); 933 Local<Value> value = script->Run();
930 CHECK(value->IsNumber()); 934 CHECK(value->IsNumber());
931 CHECK_EQ(68, value->Int32Value()); 935 CHECK_EQ(68, value->Int32Value());
932 } 936 }
933 CcTest::i_isolate()->compilation_cache()->Clear(); 937 CcTest::i_isolate()->compilation_cache()->Clear();
934 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 938 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
935 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 939 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 info.GetReturnValue().Set(v8_num(51423 + info.Length())); 1088 info.GetReturnValue().Set(v8_num(51423 + info.Length()));
1085 } 1089 }
1086 1090
1087 1091
1088 template<typename Callback> 1092 template<typename Callback>
1089 static void TestSimpleCallback(Callback callback) { 1093 static void TestSimpleCallback(Callback callback) {
1090 LocalContext env; 1094 LocalContext env;
1091 v8::HandleScope scope(env->GetIsolate()); 1095 v8::HandleScope scope(env->GetIsolate());
1092 1096
1093 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 1097 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
1094 object_template->Set("callback", v8::FunctionTemplate::New(callback)); 1098 object_template->Set(env->GetIsolate(), "callback",
1099 v8::FunctionTemplate::New(callback));
1095 v8::Local<v8::Object> object = object_template->NewInstance(); 1100 v8::Local<v8::Object> object = object_template->NewInstance();
1096 (*env)->Global()->Set(v8_str("callback_object"), object); 1101 (*env)->Global()->Set(v8_str("callback_object"), object);
1097 v8::Handle<v8::Script> script; 1102 v8::Handle<v8::Script> script;
1098 script = v8_compile("callback_object.callback(17)"); 1103 script = v8_compile("callback_object.callback(17)");
1099 for (int i = 0; i < 30; i++) { 1104 for (int i = 0; i < 30; i++) {
1100 CHECK_EQ(51424, script->Run()->Int32Value()); 1105 CHECK_EQ(51424, script->Run()->Int32Value());
1101 } 1106 }
1102 script = v8_compile("callback_object.callback(17, 24)"); 1107 script = v8_compile("callback_object.callback(17, 24)");
1103 for (int i = 0; i < 30; i++) { 1108 for (int i = 0; i < 30; i++) {
1104 CHECK_EQ(51425, script->Run()->Int32Value()); 1109 CHECK_EQ(51425, script->Run()->Int32Value());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 void FastReturnValueCallback<Object>( 1188 void FastReturnValueCallback<Object>(
1184 const v8::FunctionCallbackInfo<v8::Value>& info) { 1189 const v8::FunctionCallbackInfo<v8::Value>& info) {
1185 v8::Handle<v8::Object> object; 1190 v8::Handle<v8::Object> object;
1186 if (!fast_return_value_object_is_empty) object = Object::New(); 1191 if (!fast_return_value_object_is_empty) object = Object::New();
1187 info.GetReturnValue().Set(object); 1192 info.GetReturnValue().Set(object);
1188 } 1193 }
1189 1194
1190 template<typename T> 1195 template<typename T>
1191 Handle<Value> TestFastReturnValues() { 1196 Handle<Value> TestFastReturnValues() {
1192 LocalContext env; 1197 LocalContext env;
1193 v8::HandleScope scope(env->GetIsolate()); 1198 v8::EscapableHandleScope scope(env->GetIsolate());
1194 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 1199 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
1195 v8::FunctionCallback callback = &FastReturnValueCallback<T>; 1200 v8::FunctionCallback callback = &FastReturnValueCallback<T>;
1196 object_template->Set("callback", v8::FunctionTemplate::New(callback)); 1201 object_template->Set(env->GetIsolate(), "callback",
1202 v8::FunctionTemplate::New(callback));
1197 v8::Local<v8::Object> object = object_template->NewInstance(); 1203 v8::Local<v8::Object> object = object_template->NewInstance();
1198 (*env)->Global()->Set(v8_str("callback_object"), object); 1204 (*env)->Global()->Set(v8_str("callback_object"), object);
1199 return scope.Close(CompileRun("callback_object.callback()")); 1205 return scope.Escape(CompileRun("callback_object.callback()"));
1200 } 1206 }
1201 1207
1202 1208
1203 THREADED_PROFILED_TEST(FastReturnValues) { 1209 THREADED_PROFILED_TEST(FastReturnValues) {
1204 LocalContext env; 1210 LocalContext env;
1205 v8::HandleScope scope(CcTest::isolate()); 1211 v8::HandleScope scope(CcTest::isolate());
1206 v8::Handle<v8::Value> value; 1212 v8::Handle<v8::Value> value;
1207 // check int32_t and uint32_t 1213 // check int32_t and uint32_t
1208 int32_t int_values[] = { 1214 int32_t int_values[] = {
1209 0, 234, -723, 1215 0, 234, -723,
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 v8::Handle<Value> boxed_number = CompileRun("new Number(42)"); 1593 v8::Handle<Value> boxed_number = CompileRun("new Number(42)");
1588 CHECK(boxed_number->IsNumberObject()); 1594 CHECK(boxed_number->IsNumberObject());
1589 v8::Handle<Value> unboxed_number = CompileRun("42"); 1595 v8::Handle<Value> unboxed_number = CompileRun("42");
1590 CHECK(!unboxed_number->IsNumberObject()); 1596 CHECK(!unboxed_number->IsNumberObject());
1591 v8::Handle<Value> boxed_not_number = CompileRun("new Boolean(false)"); 1597 v8::Handle<Value> boxed_not_number = CompileRun("new Boolean(false)");
1592 CHECK(!boxed_not_number->IsNumberObject()); 1598 CHECK(!boxed_not_number->IsNumberObject());
1593 v8::Handle<v8::NumberObject> as_boxed = boxed_number.As<v8::NumberObject>(); 1599 v8::Handle<v8::NumberObject> as_boxed = boxed_number.As<v8::NumberObject>();
1594 CHECK(!as_boxed.IsEmpty()); 1600 CHECK(!as_boxed.IsEmpty());
1595 double the_number = as_boxed->ValueOf(); 1601 double the_number = as_boxed->ValueOf();
1596 CHECK_EQ(42.0, the_number); 1602 CHECK_EQ(42.0, the_number);
1597 v8::Handle<v8::Value> new_boxed_number = v8::NumberObject::New(43); 1603 v8::Handle<v8::Value> new_boxed_number =
1604 v8::NumberObject::New(env->GetIsolate(), 43);
1598 CHECK(new_boxed_number->IsNumberObject()); 1605 CHECK(new_boxed_number->IsNumberObject());
1599 as_boxed = new_boxed_number.As<v8::NumberObject>(); 1606 as_boxed = new_boxed_number.As<v8::NumberObject>();
1600 the_number = as_boxed->ValueOf(); 1607 the_number = as_boxed->ValueOf();
1601 CHECK_EQ(43.0, the_number); 1608 CHECK_EQ(43.0, the_number);
1602 } 1609 }
1603 1610
1604 1611
1605 THREADED_TEST(BooleanObject) { 1612 THREADED_TEST(BooleanObject) {
1606 LocalContext env; 1613 LocalContext env;
1607 v8::HandleScope scope(env->GetIsolate()); 1614 v8::HandleScope scope(env->GetIsolate());
(...skipping 16 matching lines...) Expand all
1624 CHECK_EQ(true, as_boxed->ValueOf()); 1631 CHECK_EQ(true, as_boxed->ValueOf());
1625 as_boxed = boxed_false.As<v8::BooleanObject>(); 1632 as_boxed = boxed_false.As<v8::BooleanObject>();
1626 CHECK_EQ(false, as_boxed->ValueOf()); 1633 CHECK_EQ(false, as_boxed->ValueOf());
1627 } 1634 }
1628 1635
1629 1636
1630 THREADED_TEST(PrimitiveAndWrappedBooleans) { 1637 THREADED_TEST(PrimitiveAndWrappedBooleans) {
1631 LocalContext env; 1638 LocalContext env;
1632 v8::HandleScope scope(env->GetIsolate()); 1639 v8::HandleScope scope(env->GetIsolate());
1633 1640
1634 Local<Value> primitive_false = Boolean::New(false); 1641 Local<Value> primitive_false = Boolean::New(env->GetIsolate(), false);
1635 CHECK(primitive_false->IsBoolean()); 1642 CHECK(primitive_false->IsBoolean());
1636 CHECK(!primitive_false->IsBooleanObject()); 1643 CHECK(!primitive_false->IsBooleanObject());
1637 CHECK(!primitive_false->BooleanValue()); 1644 CHECK(!primitive_false->BooleanValue());
1638 CHECK(!primitive_false->IsTrue()); 1645 CHECK(!primitive_false->IsTrue());
1639 CHECK(primitive_false->IsFalse()); 1646 CHECK(primitive_false->IsFalse());
1640 1647
1641 Local<Value> false_value = BooleanObject::New(false); 1648 Local<Value> false_value = BooleanObject::New(false);
1642 CHECK(!false_value->IsBoolean()); 1649 CHECK(!false_value->IsBoolean());
1643 CHECK(false_value->IsBooleanObject()); 1650 CHECK(false_value->IsBooleanObject());
1644 CHECK(false_value->BooleanValue()); 1651 CHECK(false_value->BooleanValue());
1645 CHECK(!false_value->IsTrue()); 1652 CHECK(!false_value->IsTrue());
1646 CHECK(!false_value->IsFalse()); 1653 CHECK(!false_value->IsFalse());
1647 1654
1648 Local<BooleanObject> false_boolean_object = false_value.As<BooleanObject>(); 1655 Local<BooleanObject> false_boolean_object = false_value.As<BooleanObject>();
1649 CHECK(!false_boolean_object->IsBoolean()); 1656 CHECK(!false_boolean_object->IsBoolean());
1650 CHECK(false_boolean_object->IsBooleanObject()); 1657 CHECK(false_boolean_object->IsBooleanObject());
1651 // TODO(svenpanne) Uncomment when BooleanObject::BooleanValue() is deleted. 1658 // TODO(svenpanne) Uncomment when BooleanObject::BooleanValue() is deleted.
1652 // CHECK(false_boolean_object->BooleanValue()); 1659 // CHECK(false_boolean_object->BooleanValue());
1653 CHECK(!false_boolean_object->ValueOf()); 1660 CHECK(!false_boolean_object->ValueOf());
1654 CHECK(!false_boolean_object->IsTrue()); 1661 CHECK(!false_boolean_object->IsTrue());
1655 CHECK(!false_boolean_object->IsFalse()); 1662 CHECK(!false_boolean_object->IsFalse());
1656 1663
1657 Local<Value> primitive_true = Boolean::New(true); 1664 Local<Value> primitive_true = Boolean::New(env->GetIsolate(), true);
1658 CHECK(primitive_true->IsBoolean()); 1665 CHECK(primitive_true->IsBoolean());
1659 CHECK(!primitive_true->IsBooleanObject()); 1666 CHECK(!primitive_true->IsBooleanObject());
1660 CHECK(primitive_true->BooleanValue()); 1667 CHECK(primitive_true->BooleanValue());
1661 CHECK(primitive_true->IsTrue()); 1668 CHECK(primitive_true->IsTrue());
1662 CHECK(!primitive_true->IsFalse()); 1669 CHECK(!primitive_true->IsFalse());
1663 1670
1664 Local<Value> true_value = BooleanObject::New(true); 1671 Local<Value> true_value = BooleanObject::New(true);
1665 CHECK(!true_value->IsBoolean()); 1672 CHECK(!true_value->IsBoolean());
1666 CHECK(true_value->IsBooleanObject()); 1673 CHECK(true_value->IsBooleanObject());
1667 CHECK(true_value->BooleanValue()); 1674 CHECK(true_value->BooleanValue());
(...skipping 30 matching lines...) Expand all
1698 CHECK_EQ(1.0, t->NumberValue()); 1705 CHECK_EQ(1.0, t->NumberValue());
1699 v8::Handle<v8::Boolean> f = v8::False(isolate); 1706 v8::Handle<v8::Boolean> f = v8::False(isolate);
1700 CHECK_EQ(0.0, f->NumberValue()); 1707 CHECK_EQ(0.0, f->NumberValue());
1701 } 1708 }
1702 1709
1703 1710
1704 THREADED_TEST(Date) { 1711 THREADED_TEST(Date) {
1705 LocalContext env; 1712 LocalContext env;
1706 v8::HandleScope scope(env->GetIsolate()); 1713 v8::HandleScope scope(env->GetIsolate());
1707 double PI = 3.1415926; 1714 double PI = 3.1415926;
1708 Local<Value> date = v8::Date::New(PI); 1715 Local<Value> date = v8::Date::New(env->GetIsolate(), PI);
1709 CHECK_EQ(3.0, date->NumberValue()); 1716 CHECK_EQ(3.0, date->NumberValue());
1710 date.As<v8::Date>()->Set(v8_str("property"), v8::Integer::New(42)); 1717 date.As<v8::Date>()->Set(v8_str("property"), v8::Integer::New(42));
1711 CHECK_EQ(42, date.As<v8::Date>()->Get(v8_str("property"))->Int32Value()); 1718 CHECK_EQ(42, date.As<v8::Date>()->Get(v8_str("property"))->Int32Value());
1712 } 1719 }
1713 1720
1714 1721
1715 THREADED_TEST(Boolean) { 1722 THREADED_TEST(Boolean) {
1716 LocalContext env; 1723 LocalContext env;
1717 v8::HandleScope scope(env->GetIsolate()); 1724 v8::HandleScope scope(env->GetIsolate());
1718 v8::Handle<v8::Boolean> t = v8::True(CcTest::isolate()); 1725 v8::Handle<v8::Boolean> t = v8::True(CcTest::isolate());
(...skipping 26 matching lines...) Expand all
1745 const v8::PropertyCallbackInfo<v8::Value>& info) { 1752 const v8::PropertyCallbackInfo<v8::Value>& info) {
1746 ApiTestFuzzer::Fuzz(); 1753 ApiTestFuzzer::Fuzz();
1747 info.GetReturnValue().Set(v8_num(876)); 1754 info.GetReturnValue().Set(v8_num(876));
1748 } 1755 }
1749 1756
1750 1757
1751 THREADED_TEST(GlobalPrototype) { 1758 THREADED_TEST(GlobalPrototype) {
1752 v8::HandleScope scope(CcTest::isolate()); 1759 v8::HandleScope scope(CcTest::isolate());
1753 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New(); 1760 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New();
1754 func_templ->PrototypeTemplate()->Set( 1761 func_templ->PrototypeTemplate()->Set(
1755 "dummy", 1762 CcTest::isolate(), "dummy", v8::FunctionTemplate::New(DummyCallHandler));
1756 v8::FunctionTemplate::New(DummyCallHandler));
1757 v8::Handle<ObjectTemplate> templ = func_templ->InstanceTemplate(); 1763 v8::Handle<ObjectTemplate> templ = func_templ->InstanceTemplate();
1758 templ->Set("x", v8_num(200)); 1764 templ->Set(CcTest::isolate(), "x", v8_num(200));
1759 templ->SetAccessor(v8_str("m"), GetM); 1765 templ->SetAccessor(v8_str("m"), GetM);
1760 LocalContext env(0, templ); 1766 LocalContext env(0, templ);
1761 v8::Handle<Script> script(v8_compile("dummy()")); 1767 v8::Handle<Script> script(v8_compile("dummy()"));
1762 v8::Handle<Value> result(script->Run()); 1768 v8::Handle<Value> result(script->Run());
1763 CHECK_EQ(13.4, result->NumberValue()); 1769 CHECK_EQ(13.4, result->NumberValue());
1764 CHECK_EQ(200, v8_compile("x")->Run()->Int32Value()); 1770 CHECK_EQ(200, v8_compile("x")->Run()->Int32Value());
1765 CHECK_EQ(876, v8_compile("m")->Run()->Int32Value()); 1771 CHECK_EQ(876, v8_compile("m")->Run()->Int32Value());
1766 } 1772 }
1767 1773
1768 1774
1769 THREADED_TEST(ObjectTemplate) { 1775 THREADED_TEST(ObjectTemplate) {
1770 v8::HandleScope scope(CcTest::isolate()); 1776 v8::HandleScope scope(CcTest::isolate());
1771 Local<ObjectTemplate> templ1 = ObjectTemplate::New(); 1777 Local<ObjectTemplate> templ1 = ObjectTemplate::New();
1772 templ1->Set("x", v8_num(10)); 1778 templ1->Set(CcTest::isolate(), "x", v8_num(10));
1773 templ1->Set("y", v8_num(13)); 1779 templ1->Set(CcTest::isolate(), "y", v8_num(13));
1774 LocalContext env; 1780 LocalContext env;
1775 Local<v8::Object> instance1 = templ1->NewInstance(); 1781 Local<v8::Object> instance1 = templ1->NewInstance();
1776 env->Global()->Set(v8_str("p"), instance1); 1782 env->Global()->Set(v8_str("p"), instance1);
1777 CHECK(v8_compile("(p.x == 10)")->Run()->BooleanValue()); 1783 CHECK(v8_compile("(p.x == 10)")->Run()->BooleanValue());
1778 CHECK(v8_compile("(p.y == 13)")->Run()->BooleanValue()); 1784 CHECK(v8_compile("(p.y == 13)")->Run()->BooleanValue());
1779 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(); 1785 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New();
1780 fun->PrototypeTemplate()->Set("nirk", v8_num(123)); 1786 fun->PrototypeTemplate()->Set(CcTest::isolate(), "nirk", v8_num(123));
1781 Local<ObjectTemplate> templ2 = fun->InstanceTemplate(); 1787 Local<ObjectTemplate> templ2 = fun->InstanceTemplate();
1782 templ2->Set("a", v8_num(12)); 1788 templ2->Set(CcTest::isolate(), "a", v8_num(12));
1783 templ2->Set("b", templ1); 1789 templ2->Set(CcTest::isolate(), "b", templ1);
1784 Local<v8::Object> instance2 = templ2->NewInstance(); 1790 Local<v8::Object> instance2 = templ2->NewInstance();
1785 env->Global()->Set(v8_str("q"), instance2); 1791 env->Global()->Set(v8_str("q"), instance2);
1786 CHECK(v8_compile("(q.nirk == 123)")->Run()->BooleanValue()); 1792 CHECK(v8_compile("(q.nirk == 123)")->Run()->BooleanValue());
1787 CHECK(v8_compile("(q.a == 12)")->Run()->BooleanValue()); 1793 CHECK(v8_compile("(q.a == 12)")->Run()->BooleanValue());
1788 CHECK(v8_compile("(q.b.x == 10)")->Run()->BooleanValue()); 1794 CHECK(v8_compile("(q.b.x == 10)")->Run()->BooleanValue());
1789 CHECK(v8_compile("(q.b.y == 13)")->Run()->BooleanValue()); 1795 CHECK(v8_compile("(q.b.y == 13)")->Run()->BooleanValue());
1790 } 1796 }
1791 1797
1792 1798
1793 static void GetFlabby(const v8::FunctionCallbackInfo<v8::Value>& args) { 1799 static void GetFlabby(const v8::FunctionCallbackInfo<v8::Value>& args) {
1794 ApiTestFuzzer::Fuzz(); 1800 ApiTestFuzzer::Fuzz();
1795 args.GetReturnValue().Set(v8_num(17.2)); 1801 args.GetReturnValue().Set(v8_num(17.2));
1796 } 1802 }
1797 1803
1798 1804
1799 static void GetKnurd(Local<String> property, 1805 static void GetKnurd(Local<String> property,
1800 const v8::PropertyCallbackInfo<v8::Value>& info) { 1806 const v8::PropertyCallbackInfo<v8::Value>& info) {
1801 ApiTestFuzzer::Fuzz(); 1807 ApiTestFuzzer::Fuzz();
1802 info.GetReturnValue().Set(v8_num(15.2)); 1808 info.GetReturnValue().Set(v8_num(15.2));
1803 } 1809 }
1804 1810
1805 1811
1806 THREADED_TEST(DescriptorInheritance) { 1812 THREADED_TEST(DescriptorInheritance) {
1807 v8::HandleScope scope(CcTest::isolate()); 1813 v8::HandleScope scope(CcTest::isolate());
1808 v8::Handle<v8::FunctionTemplate> super = v8::FunctionTemplate::New(); 1814 v8::Handle<v8::FunctionTemplate> super = v8::FunctionTemplate::New();
1809 super->PrototypeTemplate()->Set("flabby", 1815 super->PrototypeTemplate()->Set(CcTest::isolate(), "flabby",
1810 v8::FunctionTemplate::New(GetFlabby)); 1816 v8::FunctionTemplate::New(GetFlabby));
1811 super->PrototypeTemplate()->Set("PI", v8_num(3.14)); 1817 super->PrototypeTemplate()->Set(CcTest::isolate(), "PI", v8_num(3.14));
1812 1818
1813 super->InstanceTemplate()->SetAccessor(v8_str("knurd"), GetKnurd); 1819 super->InstanceTemplate()->SetAccessor(v8_str("knurd"), GetKnurd);
1814 1820
1815 v8::Handle<v8::FunctionTemplate> base1 = v8::FunctionTemplate::New(); 1821 v8::Handle<v8::FunctionTemplate> base1 = v8::FunctionTemplate::New();
1816 base1->Inherit(super); 1822 base1->Inherit(super);
1817 base1->PrototypeTemplate()->Set("v1", v8_num(20.1)); 1823 base1->PrototypeTemplate()->Set(CcTest::isolate(), "v1", v8_num(20.1));
1818 1824
1819 v8::Handle<v8::FunctionTemplate> base2 = v8::FunctionTemplate::New(); 1825 v8::Handle<v8::FunctionTemplate> base2 = v8::FunctionTemplate::New();
1820 base2->Inherit(super); 1826 base2->Inherit(super);
1821 base2->PrototypeTemplate()->Set("v2", v8_num(10.1)); 1827 base2->PrototypeTemplate()->Set(CcTest::isolate(), "v2", v8_num(10.1));
1822 1828
1823 LocalContext env; 1829 LocalContext env;
1824 1830
1825 env->Global()->Set(v8_str("s"), super->GetFunction()); 1831 env->Global()->Set(v8_str("s"), super->GetFunction());
1826 env->Global()->Set(v8_str("base1"), base1->GetFunction()); 1832 env->Global()->Set(v8_str("base1"), base1->GetFunction());
1827 env->Global()->Set(v8_str("base2"), base2->GetFunction()); 1833 env->Global()->Set(v8_str("base2"), base2->GetFunction());
1828 1834
1829 // Checks right __proto__ chain. 1835 // Checks right __proto__ chain.
1830 CHECK(CompileRun("base1.prototype.__proto__ == s.prototype")->BooleanValue()); 1836 CHECK(CompileRun("base1.prototype.__proto__ == s.prototype")->BooleanValue());
1831 CHECK(CompileRun("base2.prototype.__proto__ == s.prototype")->BooleanValue()); 1837 CHECK(CompileRun("base2.prototype.__proto__ == s.prototype")->BooleanValue());
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
2618 THREADED_TEST(EmbedderData) { 2624 THREADED_TEST(EmbedderData) {
2619 LocalContext env; 2625 LocalContext env;
2620 v8::HandleScope scope(env->GetIsolate()); 2626 v8::HandleScope scope(env->GetIsolate());
2621 2627
2622 CheckEmbedderData( 2628 CheckEmbedderData(
2623 &env, 3, 2629 &env, 3,
2624 v8::String::NewFromUtf8(env->GetIsolate(), "The quick brown fox jumps")); 2630 v8::String::NewFromUtf8(env->GetIsolate(), "The quick brown fox jumps"));
2625 CheckEmbedderData(&env, 2, v8::String::NewFromUtf8(env->GetIsolate(), 2631 CheckEmbedderData(&env, 2, v8::String::NewFromUtf8(env->GetIsolate(),
2626 "over the lazy dog.")); 2632 "over the lazy dog."));
2627 CheckEmbedderData(&env, 1, v8::Number::New(1.2345)); 2633 CheckEmbedderData(&env, 1, v8::Number::New(1.2345));
2628 CheckEmbedderData(&env, 0, v8::Boolean::New(true)); 2634 CheckEmbedderData(&env, 0, v8::Boolean::New(env->GetIsolate(), true));
2629 } 2635 }
2630 2636
2631 2637
2632 THREADED_TEST(IdentityHash) { 2638 THREADED_TEST(IdentityHash) {
2633 LocalContext env; 2639 LocalContext env;
2634 v8::HandleScope scope(env->GetIsolate()); 2640 v8::HandleScope scope(env->GetIsolate());
2635 2641
2636 // Ensure that the test starts with an fresh heap to test whether the hash 2642 // Ensure that the test starts with an fresh heap to test whether the hash
2637 // code is based on the address. 2643 // code is based on the address.
2638 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 2644 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
2840 CHECK_EQ(0, value->GetInternalField(i)->Int32Value()); 2846 CHECK_EQ(0, value->GetInternalField(i)->Int32Value());
2841 } 2847 }
2842 } 2848 }
2843 2849
2844 2850
2845 THREADED_TEST(ArrayBuffer_ApiInternalToExternal) { 2851 THREADED_TEST(ArrayBuffer_ApiInternalToExternal) {
2846 LocalContext env; 2852 LocalContext env;
2847 v8::Isolate* isolate = env->GetIsolate(); 2853 v8::Isolate* isolate = env->GetIsolate();
2848 v8::HandleScope handle_scope(isolate); 2854 v8::HandleScope handle_scope(isolate);
2849 2855
2850 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(1024); 2856 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, 1024);
2851 CheckInternalFieldsAreZero(ab); 2857 CheckInternalFieldsAreZero(ab);
2852 CHECK_EQ(1024, static_cast<int>(ab->ByteLength())); 2858 CHECK_EQ(1024, static_cast<int>(ab->ByteLength()));
2853 CHECK(!ab->IsExternal()); 2859 CHECK(!ab->IsExternal());
2854 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 2860 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2855 2861
2856 ScopedArrayBufferContents ab_contents(ab->Externalize()); 2862 ScopedArrayBufferContents ab_contents(ab->Externalize());
2857 CHECK(ab->IsExternal()); 2863 CHECK(ab->IsExternal());
2858 2864
2859 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength())); 2865 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength()));
2860 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data()); 2866 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2920 } 2926 }
2921 2927
2922 2928
2923 THREADED_TEST(ArrayBuffer_External) { 2929 THREADED_TEST(ArrayBuffer_External) {
2924 LocalContext env; 2930 LocalContext env;
2925 v8::Isolate* isolate = env->GetIsolate(); 2931 v8::Isolate* isolate = env->GetIsolate();
2926 v8::HandleScope handle_scope(isolate); 2932 v8::HandleScope handle_scope(isolate);
2927 2933
2928 i::ScopedVector<uint8_t> my_data(100); 2934 i::ScopedVector<uint8_t> my_data(100);
2929 memset(my_data.start(), 0, 100); 2935 memset(my_data.start(), 0, 100);
2930 Local<v8::ArrayBuffer> ab3 = v8::ArrayBuffer::New(my_data.start(), 100); 2936 Local<v8::ArrayBuffer> ab3 =
2937 v8::ArrayBuffer::New(isolate, my_data.start(), 100);
2931 CheckInternalFieldsAreZero(ab3); 2938 CheckInternalFieldsAreZero(ab3);
2932 CHECK_EQ(100, static_cast<int>(ab3->ByteLength())); 2939 CHECK_EQ(100, static_cast<int>(ab3->ByteLength()));
2933 CHECK(ab3->IsExternal()); 2940 CHECK(ab3->IsExternal());
2934 2941
2935 env->Global()->Set(v8_str("ab3"), ab3); 2942 env->Global()->Set(v8_str("ab3"), ab3);
2936 2943
2937 v8::Handle<v8::Value> result = CompileRun("ab3.byteLength"); 2944 v8::Handle<v8::Value> result = CompileRun("ab3.byteLength");
2938 CHECK_EQ(100, result->Int32Value()); 2945 CHECK_EQ(100, result->Int32Value());
2939 2946
2940 result = CompileRun("var u8_b = new Uint8Array(ab3);" 2947 result = CompileRun("var u8_b = new Uint8Array(ab3);"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2987 CHECK_EQ(length * kElementSize, static_cast<int>(ta->ByteLength())); 2994 CHECK_EQ(length * kElementSize, static_cast<int>(ta->ByteLength()));
2988 return ta; 2995 return ta;
2989 } 2996 }
2990 2997
2991 2998
2992 THREADED_TEST(ArrayBuffer_NeuteringApi) { 2999 THREADED_TEST(ArrayBuffer_NeuteringApi) {
2993 LocalContext env; 3000 LocalContext env;
2994 v8::Isolate* isolate = env->GetIsolate(); 3001 v8::Isolate* isolate = env->GetIsolate();
2995 v8::HandleScope handle_scope(isolate); 3002 v8::HandleScope handle_scope(isolate);
2996 3003
2997 v8::Handle<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New(1024); 3004 v8::Handle<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New(isolate, 1024);
2998 3005
2999 v8::Handle<v8::Uint8Array> u8a = 3006 v8::Handle<v8::Uint8Array> u8a =
3000 CreateAndCheck<v8::Uint8Array, 1>(buffer, 1, 1023); 3007 CreateAndCheck<v8::Uint8Array, 1>(buffer, 1, 1023);
3001 v8::Handle<v8::Uint8ClampedArray> u8c = 3008 v8::Handle<v8::Uint8ClampedArray> u8c =
3002 CreateAndCheck<v8::Uint8ClampedArray, 1>(buffer, 1, 1023); 3009 CreateAndCheck<v8::Uint8ClampedArray, 1>(buffer, 1, 1023);
3003 v8::Handle<v8::Int8Array> i8a = 3010 v8::Handle<v8::Int8Array> i8a =
3004 CreateAndCheck<v8::Int8Array, 1>(buffer, 1, 1023); 3011 CreateAndCheck<v8::Int8Array, 1>(buffer, 1, 1023);
3005 3012
3006 v8::Handle<v8::Uint16Array> u16a = 3013 v8::Handle<v8::Uint16Array> u16a =
3007 CreateAndCheck<v8::Uint16Array, 2>(buffer, 2, 511); 3014 CreateAndCheck<v8::Uint16Array, 2>(buffer, 2, 511);
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
3292 { 3299 {
3293 v8::HandleScope scope(isolate); 3300 v8::HandleScope scope(isolate);
3294 Local<String> empty; 3301 Local<String> empty;
3295 global.Reset(isolate, empty); 3302 global.Reset(isolate, empty);
3296 } 3303 }
3297 CHECK(global.IsEmpty()); 3304 CHECK(global.IsEmpty());
3298 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count - 1); 3305 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count - 1);
3299 } 3306 }
3300 3307
3301 3308
3309 template<class T>
3310 static v8::UniquePersistent<T> PassUnique(v8::UniquePersistent<T> unique) {
3311 return unique.Pass();
3312 }
3313
3314
3315 template<class T>
3316 static v8::UniquePersistent<T> ReturnUnique(v8::Isolate* isolate,
3317 const v8::Persistent<T> & global) {
3318 v8::UniquePersistent<String> unique(isolate, global);
3319 return unique.Pass();
3320 }
3321
3322
3323 THREADED_TEST(UniquePersistent) {
3324 v8::Isolate* isolate = CcTest::isolate();
3325 v8::Persistent<String> global;
3326 {
3327 v8::HandleScope scope(isolate);
3328 global.Reset(isolate, v8_str("str"));
3329 }
3330 v8::internal::GlobalHandles* global_handles =
3331 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles();
3332 int initial_handle_count = global_handles->global_handles_count();
3333 {
3334 v8::UniquePersistent<String> unique(isolate, global);
3335 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count());
3336 // Test assignment via Pass
3337 {
3338 v8::UniquePersistent<String> copy = unique.Pass();
3339 CHECK(unique.IsEmpty());
3340 CHECK(copy == global);
3341 CHECK_EQ(initial_handle_count + 1,
3342 global_handles->global_handles_count());
3343 unique = copy.Pass();
3344 }
3345 // Test ctor via Pass
3346 {
3347 v8::UniquePersistent<String> copy(unique.Pass());
3348 CHECK(unique.IsEmpty());
3349 CHECK(copy == global);
3350 CHECK_EQ(initial_handle_count + 1,
3351 global_handles->global_handles_count());
3352 unique = copy.Pass();
3353 }
3354 // Test pass through function call
3355 {
3356 v8::UniquePersistent<String> copy = PassUnique(unique.Pass());
3357 CHECK(unique.IsEmpty());
3358 CHECK(copy == global);
3359 CHECK_EQ(initial_handle_count + 1,
3360 global_handles->global_handles_count());
3361 unique = copy.Pass();
3362 }
3363 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count());
3364 }
3365 // Test pass from function call
3366 {
3367 v8::UniquePersistent<String> unique = ReturnUnique(isolate, global);
3368 CHECK(unique == global);
3369 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count());
3370 }
3371 CHECK_EQ(initial_handle_count, global_handles->global_handles_count());
3372 global.Reset();
3373 }
3374
3375
3302 THREADED_TEST(GlobalHandleUpcast) { 3376 THREADED_TEST(GlobalHandleUpcast) {
3303 v8::Isolate* isolate = CcTest::isolate(); 3377 v8::Isolate* isolate = CcTest::isolate();
3304 v8::HandleScope scope(isolate); 3378 v8::HandleScope scope(isolate);
3305 v8::Local<String> local = v8::Local<String>::New(isolate, v8_str("str")); 3379 v8::Local<String> local = v8::Local<String>::New(isolate, v8_str("str"));
3306 v8::Persistent<String> global_string(isolate, local); 3380 v8::Persistent<String> global_string(isolate, local);
3307 v8::Persistent<Value>& global_value = 3381 v8::Persistent<Value>& global_value =
3308 v8::Persistent<Value>::Cast(global_string); 3382 v8::Persistent<Value>::Cast(global_string);
3309 CHECK(v8::Local<v8::Value>::New(isolate, global_value)->IsString()); 3383 CHECK(v8::Local<v8::Value>::New(isolate, global_value)->IsString());
3310 CHECK(global_string == v8::Persistent<String>::Cast(global_value)); 3384 CHECK(global_string == v8::Persistent<String>::Cast(global_value));
3311 global_string.Reset(); 3385 global_string.Reset();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
3364 int id() { return id_; } 3438 int id() { return id_; }
3365 void increment() { number_of_weak_calls_++; } 3439 void increment() { number_of_weak_calls_++; }
3366 int NumberOfWeakCalls() { return number_of_weak_calls_; } 3440 int NumberOfWeakCalls() { return number_of_weak_calls_; }
3367 private: 3441 private:
3368 int id_; 3442 int id_;
3369 int number_of_weak_calls_; 3443 int number_of_weak_calls_;
3370 }; 3444 };
3371 3445
3372 3446
3373 template<typename T> 3447 template<typename T>
3374 static void WeakPointerCallback(v8::Isolate* isolate, 3448 struct WeakCallCounterAndPersistent {
3375 Persistent<T>* handle, 3449 explicit WeakCallCounterAndPersistent(WeakCallCounter* counter)
3376 WeakCallCounter* counter) { 3450 : counter(counter) {}
3377 CHECK_EQ(1234, counter->id()); 3451 WeakCallCounter* counter;
3378 counter->increment(); 3452 v8::Persistent<T> handle;
3379 handle->Reset(); 3453 };
3454
3455
3456 template <typename T>
3457 static void WeakPointerCallback(
3458 const v8::WeakCallbackData<T, WeakCallCounterAndPersistent<T> >& data) {
3459 CHECK_EQ(1234, data.GetParameter()->counter->id());
3460 data.GetParameter()->counter->increment();
3461 data.GetParameter()->handle.Reset();
3380 } 3462 }
3381 3463
3382 3464
3383 template<typename T> 3465 template<typename T>
3384 static UniqueId MakeUniqueId(const Persistent<T>& p) { 3466 static UniqueId MakeUniqueId(const Persistent<T>& p) {
3385 return UniqueId(reinterpret_cast<uintptr_t>(*v8::Utils::OpenPersistent(p))); 3467 return UniqueId(reinterpret_cast<uintptr_t>(*v8::Utils::OpenPersistent(p)));
3386 } 3468 }
3387 3469
3388 3470
3389 THREADED_TEST(ApiObjectGroups) { 3471 THREADED_TEST(ApiObjectGroups) {
3390 LocalContext env; 3472 LocalContext env;
3391 v8::Isolate* iso = env->GetIsolate(); 3473 v8::Isolate* iso = env->GetIsolate();
3392 HandleScope scope(iso); 3474 HandleScope scope(iso);
3393 3475
3394 Persistent<Value> g1s1; 3476 WeakCallCounter counter(1234);
3395 Persistent<Value> g1s2;
3396 Persistent<Value> g1c1;
3397 Persistent<Value> g2s1;
3398 Persistent<Value> g2s2;
3399 Persistent<Value> g2c1;
3400 3477
3401 WeakCallCounter counter(1234); 3478 WeakCallCounterAndPersistent<Value> g1s1(&counter);
3479 WeakCallCounterAndPersistent<Value> g1s2(&counter);
3480 WeakCallCounterAndPersistent<Value> g1c1(&counter);
3481 WeakCallCounterAndPersistent<Value> g2s1(&counter);
3482 WeakCallCounterAndPersistent<Value> g2s2(&counter);
3483 WeakCallCounterAndPersistent<Value> g2c1(&counter);
3402 3484
3403 { 3485 {
3404 HandleScope scope(iso); 3486 HandleScope scope(iso);
3405 g1s1.Reset(iso, Object::New()); 3487 g1s1.handle.Reset(iso, Object::New());
3406 g1s2.Reset(iso, Object::New()); 3488 g1s2.handle.Reset(iso, Object::New());
3407 g1c1.Reset(iso, Object::New()); 3489 g1c1.handle.Reset(iso, Object::New());
3408 g1s1.MakeWeak(&counter, &WeakPointerCallback); 3490 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback);
3409 g1s2.MakeWeak(&counter, &WeakPointerCallback); 3491 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback);
3410 g1c1.MakeWeak(&counter, &WeakPointerCallback); 3492 g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback);
3411 3493
3412 g2s1.Reset(iso, Object::New()); 3494 g2s1.handle.Reset(iso, Object::New());
3413 g2s2.Reset(iso, Object::New()); 3495 g2s2.handle.Reset(iso, Object::New());
3414 g2c1.Reset(iso, Object::New()); 3496 g2c1.handle.Reset(iso, Object::New());
3415 g2s1.MakeWeak(&counter, &WeakPointerCallback); 3497 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback);
3416 g2s2.MakeWeak(&counter, &WeakPointerCallback); 3498 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback);
3417 g2c1.MakeWeak(&counter, &WeakPointerCallback); 3499 g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback);
3418 } 3500 }
3419 3501
3420 Persistent<Value> root(iso, g1s1); // make a root. 3502 WeakCallCounterAndPersistent<Value> root(&counter);
3503 root.handle.Reset(iso, g1s1.handle); // make a root.
3421 3504
3422 // Connect group 1 and 2, make a cycle. 3505 // Connect group 1 and 2, make a cycle.
3423 { 3506 {
3424 HandleScope scope(iso); 3507 HandleScope scope(iso);
3425 CHECK(Local<Object>::New(iso, g1s2.As<Object>())-> 3508 CHECK(Local<Object>::New(iso, g1s2.handle.As<Object>())->
3426 Set(0, Local<Value>::New(iso, g2s2))); 3509 Set(0, Local<Value>::New(iso, g2s2.handle)));
3427 CHECK(Local<Object>::New(iso, g2s1.As<Object>())-> 3510 CHECK(Local<Object>::New(iso, g2s1.handle.As<Object>())->
3428 Set(0, Local<Value>::New(iso, g1s1))); 3511 Set(0, Local<Value>::New(iso, g1s1.handle)));
3429 } 3512 }
3430 3513
3431 { 3514 {
3432 UniqueId id1 = MakeUniqueId(g1s1); 3515 UniqueId id1 = MakeUniqueId(g1s1.handle);
3433 UniqueId id2 = MakeUniqueId(g2s2); 3516 UniqueId id2 = MakeUniqueId(g2s2.handle);
3434 iso->SetObjectGroupId(g1s1, id1); 3517 iso->SetObjectGroupId(g1s1.handle, id1);
3435 iso->SetObjectGroupId(g1s2, id1); 3518 iso->SetObjectGroupId(g1s2.handle, id1);
3436 iso->SetReferenceFromGroup(id1, g1c1); 3519 iso->SetReferenceFromGroup(id1, g1c1.handle);
3437 iso->SetObjectGroupId(g2s1, id2); 3520 iso->SetObjectGroupId(g2s1.handle, id2);
3438 iso->SetObjectGroupId(g2s2, id2); 3521 iso->SetObjectGroupId(g2s2.handle, id2);
3439 iso->SetReferenceFromGroup(id2, g2c1); 3522 iso->SetReferenceFromGroup(id2, g2c1.handle);
3440 } 3523 }
3441 // Do a single full GC, ensure incremental marking is stopped. 3524 // Do a single full GC, ensure incremental marking is stopped.
3442 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( 3525 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>(
3443 iso)->heap(); 3526 iso)->heap();
3444 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 3527 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
3445 3528
3446 // All object should be alive. 3529 // All object should be alive.
3447 CHECK_EQ(0, counter.NumberOfWeakCalls()); 3530 CHECK_EQ(0, counter.NumberOfWeakCalls());
3448 3531
3449 // Weaken the root. 3532 // Weaken the root.
3450 root.MakeWeak(&counter, &WeakPointerCallback); 3533 root.handle.SetWeak(&root, &WeakPointerCallback);
3451 // But make children strong roots---all the objects (except for children) 3534 // But make children strong roots---all the objects (except for children)
3452 // should be collectable now. 3535 // should be collectable now.
3453 g1c1.ClearWeak(); 3536 g1c1.handle.ClearWeak();
3454 g2c1.ClearWeak(); 3537 g2c1.handle.ClearWeak();
3455 3538
3456 // Groups are deleted, rebuild groups. 3539 // Groups are deleted, rebuild groups.
3457 { 3540 {
3458 UniqueId id1 = MakeUniqueId(g1s1); 3541 UniqueId id1 = MakeUniqueId(g1s1.handle);
3459 UniqueId id2 = MakeUniqueId(g2s2); 3542 UniqueId id2 = MakeUniqueId(g2s2.handle);
3460 iso->SetObjectGroupId(g1s1, id1); 3543 iso->SetObjectGroupId(g1s1.handle, id1);
3461 iso->SetObjectGroupId(g1s2, id1); 3544 iso->SetObjectGroupId(g1s2.handle, id1);
3462 iso->SetReferenceFromGroup(id1, g1c1); 3545 iso->SetReferenceFromGroup(id1, g1c1.handle);
3463 iso->SetObjectGroupId(g2s1, id2); 3546 iso->SetObjectGroupId(g2s1.handle, id2);
3464 iso->SetObjectGroupId(g2s2, id2); 3547 iso->SetObjectGroupId(g2s2.handle, id2);
3465 iso->SetReferenceFromGroup(id2, g2c1); 3548 iso->SetReferenceFromGroup(id2, g2c1.handle);
3466 } 3549 }
3467 3550
3468 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 3551 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
3469 3552
3470 // All objects should be gone. 5 global handles in total. 3553 // All objects should be gone. 5 global handles in total.
3471 CHECK_EQ(5, counter.NumberOfWeakCalls()); 3554 CHECK_EQ(5, counter.NumberOfWeakCalls());
3472 3555
3473 // And now make children weak again and collect them. 3556 // And now make children weak again and collect them.
3474 g1c1.MakeWeak(&counter, &WeakPointerCallback); 3557 g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback);
3475 g2c1.MakeWeak(&counter, &WeakPointerCallback); 3558 g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback);
3476 3559
3477 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 3560 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
3478 CHECK_EQ(7, counter.NumberOfWeakCalls()); 3561 CHECK_EQ(7, counter.NumberOfWeakCalls());
3479 } 3562 }
3480 3563
3481 3564
3482 THREADED_TEST(ApiObjectGroupsForSubtypes) { 3565 THREADED_TEST(ApiObjectGroupsForSubtypes) {
3483 LocalContext env; 3566 LocalContext env;
3484 v8::Isolate* iso = env->GetIsolate(); 3567 v8::Isolate* iso = env->GetIsolate();
3485 HandleScope scope(iso); 3568 HandleScope scope(iso);
3486 3569
3487 Persistent<Object> g1s1; 3570 WeakCallCounter counter(1234);
3488 Persistent<String> g1s2;
3489 Persistent<String> g1c1;
3490 Persistent<Object> g2s1;
3491 Persistent<String> g2s2;
3492 Persistent<String> g2c1;
3493 3571
3494 WeakCallCounter counter(1234); 3572 WeakCallCounterAndPersistent<Object> g1s1(&counter);
3573 WeakCallCounterAndPersistent<String> g1s2(&counter);
3574 WeakCallCounterAndPersistent<String> g1c1(&counter);
3575 WeakCallCounterAndPersistent<Object> g2s1(&counter);
3576 WeakCallCounterAndPersistent<String> g2s2(&counter);
3577 WeakCallCounterAndPersistent<String> g2c1(&counter);
3495 3578
3496 { 3579 {
3497 HandleScope scope(iso); 3580 HandleScope scope(iso);
3498 g1s1.Reset(iso, Object::New()); 3581 g1s1.handle.Reset(iso, Object::New());
3499 g1s2.Reset(iso, String::NewFromUtf8(iso, "foo1")); 3582 g1s2.handle.Reset(iso, String::NewFromUtf8(iso, "foo1"));
3500 g1c1.Reset(iso, String::NewFromUtf8(iso, "foo2")); 3583 g1c1.handle.Reset(iso, String::NewFromUtf8(iso, "foo2"));
3501 g1s1.MakeWeak(&counter, &WeakPointerCallback); 3584 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback);
3502 g1s2.MakeWeak(&counter, &WeakPointerCallback); 3585 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback);
3503 g1c1.MakeWeak(&counter, &WeakPointerCallback); 3586 g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback);
3504 3587
3505 g2s1.Reset(iso, Object::New()); 3588 g2s1.handle.Reset(iso, Object::New());
3506 g2s2.Reset(iso, String::NewFromUtf8(iso, "foo3")); 3589 g2s2.handle.Reset(iso, String::NewFromUtf8(iso, "foo3"));
3507 g2c1.Reset(iso, String::NewFromUtf8(iso, "foo4")); 3590 g2c1.handle.Reset(iso, String::NewFromUtf8(iso, "foo4"));
3508 g2s1.MakeWeak(&counter, &WeakPointerCallback); 3591 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback);
3509 g2s2.MakeWeak(&counter, &WeakPointerCallback); 3592 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback);
3510 g2c1.MakeWeak(&counter, &WeakPointerCallback); 3593 g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback);
3511 } 3594 }
3512 3595
3513 Persistent<Value> root(iso, g1s1); // make a root. 3596 WeakCallCounterAndPersistent<Value> root(&counter);
3597 root.handle.Reset(iso, g1s1.handle); // make a root.
3514 3598
3515 // Connect group 1 and 2, make a cycle. 3599 // Connect group 1 and 2, make a cycle.
3516 { 3600 {
3517 HandleScope scope(iso); 3601 HandleScope scope(iso);
3518 CHECK(Local<Object>::New(iso, g1s1)->Set(0, Local<Object>::New(iso, g2s1))); 3602 CHECK(Local<Object>::New(iso, g1s1.handle)
3519 CHECK(Local<Object>::New(iso, g2s1)->Set(0, Local<Object>::New(iso, g1s1))); 3603 ->Set(0, Local<Object>::New(iso, g2s1.handle)));
3604 CHECK(Local<Object>::New(iso, g2s1.handle)
3605 ->Set(0, Local<Object>::New(iso, g1s1.handle)));
3520 } 3606 }
3521 3607
3522 { 3608 {
3523 UniqueId id1 = MakeUniqueId(g1s1); 3609 UniqueId id1 = MakeUniqueId(g1s1.handle);
3524 UniqueId id2 = MakeUniqueId(g2s2); 3610 UniqueId id2 = MakeUniqueId(g2s2.handle);
3525 iso->SetObjectGroupId(g1s1, id1); 3611 iso->SetObjectGroupId(g1s1.handle, id1);
3526 iso->SetObjectGroupId(g1s2, id1); 3612 iso->SetObjectGroupId(g1s2.handle, id1);
3527 iso->SetReference(g1s1, g1c1); 3613 iso->SetReference(g1s1.handle, g1c1.handle);
3528 iso->SetObjectGroupId(g2s1, id2); 3614 iso->SetObjectGroupId(g2s1.handle, id2);
3529 iso->SetObjectGroupId(g2s2, id2); 3615 iso->SetObjectGroupId(g2s2.handle, id2);
3530 iso->SetReferenceFromGroup(id2, g2c1); 3616 iso->SetReferenceFromGroup(id2, g2c1.handle);
3531 } 3617 }
3532 // Do a single full GC, ensure incremental marking is stopped. 3618 // Do a single full GC, ensure incremental marking is stopped.
3533 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( 3619 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>(
3534 iso)->heap(); 3620 iso)->heap();
3535 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 3621 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
3536 3622
3537 // All object should be alive. 3623 // All object should be alive.
3538 CHECK_EQ(0, counter.NumberOfWeakCalls()); 3624 CHECK_EQ(0, counter.NumberOfWeakCalls());
3539 3625
3540 // Weaken the root. 3626 // Weaken the root.
3541 root.MakeWeak(&counter, &WeakPointerCallback); 3627 root.handle.SetWeak(&root, &WeakPointerCallback);
3542 // But make children strong roots---all the objects (except for children) 3628 // But make children strong roots---all the objects (except for children)
3543 // should be collectable now. 3629 // should be collectable now.
3544 g1c1.ClearWeak(); 3630 g1c1.handle.ClearWeak();
3545 g2c1.ClearWeak(); 3631 g2c1.handle.ClearWeak();
3546 3632
3547 // Groups are deleted, rebuild groups. 3633 // Groups are deleted, rebuild groups.
3548 { 3634 {
3549 UniqueId id1 = MakeUniqueId(g1s1); 3635 UniqueId id1 = MakeUniqueId(g1s1.handle);
3550 UniqueId id2 = MakeUniqueId(g2s2); 3636 UniqueId id2 = MakeUniqueId(g2s2.handle);
3551 iso->SetObjectGroupId(g1s1, id1); 3637 iso->SetObjectGroupId(g1s1.handle, id1);
3552 iso->SetObjectGroupId(g1s2, id1); 3638 iso->SetObjectGroupId(g1s2.handle, id1);
3553 iso->SetReference(g1s1, g1c1); 3639 iso->SetReference(g1s1.handle, g1c1.handle);
3554 iso->SetObjectGroupId(g2s1, id2); 3640 iso->SetObjectGroupId(g2s1.handle, id2);
3555 iso->SetObjectGroupId(g2s2, id2); 3641 iso->SetObjectGroupId(g2s2.handle, id2);
3556 iso->SetReferenceFromGroup(id2, g2c1); 3642 iso->SetReferenceFromGroup(id2, g2c1.handle);
3557 } 3643 }
3558 3644
3559 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 3645 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
3560 3646
3561 // All objects should be gone. 5 global handles in total. 3647 // All objects should be gone. 5 global handles in total.
3562 CHECK_EQ(5, counter.NumberOfWeakCalls()); 3648 CHECK_EQ(5, counter.NumberOfWeakCalls());
3563 3649
3564 // And now make children weak again and collect them. 3650 // And now make children weak again and collect them.
3565 g1c1.MakeWeak(&counter, &WeakPointerCallback); 3651 g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback);
3566 g2c1.MakeWeak(&counter, &WeakPointerCallback); 3652 g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback);
3567 3653
3568 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 3654 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
3569 CHECK_EQ(7, counter.NumberOfWeakCalls()); 3655 CHECK_EQ(7, counter.NumberOfWeakCalls());
3570 } 3656 }
3571 3657
3572 3658
3573 THREADED_TEST(ApiObjectGroupsCycle) { 3659 THREADED_TEST(ApiObjectGroupsCycle) {
3574 LocalContext env; 3660 LocalContext env;
3575 v8::Isolate* iso = env->GetIsolate(); 3661 v8::Isolate* iso = env->GetIsolate();
3576 HandleScope scope(iso); 3662 HandleScope scope(iso);
3577 3663
3578 WeakCallCounter counter(1234); 3664 WeakCallCounter counter(1234);
3579 3665
3580 Persistent<Value> g1s1; 3666 WeakCallCounterAndPersistent<Value> g1s1(&counter);
3581 Persistent<Value> g1s2; 3667 WeakCallCounterAndPersistent<Value> g1s2(&counter);
3582 Persistent<Value> g2s1; 3668 WeakCallCounterAndPersistent<Value> g2s1(&counter);
3583 Persistent<Value> g2s2; 3669 WeakCallCounterAndPersistent<Value> g2s2(&counter);
3584 Persistent<Value> g3s1; 3670 WeakCallCounterAndPersistent<Value> g3s1(&counter);
3585 Persistent<Value> g3s2; 3671 WeakCallCounterAndPersistent<Value> g3s2(&counter);
3586 Persistent<Value> g4s1; 3672 WeakCallCounterAndPersistent<Value> g4s1(&counter);
3587 Persistent<Value> g4s2; 3673 WeakCallCounterAndPersistent<Value> g4s2(&counter);
3588 3674
3589 { 3675 {
3590 HandleScope scope(iso); 3676 HandleScope scope(iso);
3591 g1s1.Reset(iso, Object::New()); 3677 g1s1.handle.Reset(iso, Object::New());
3592 g1s2.Reset(iso, Object::New()); 3678 g1s2.handle.Reset(iso, Object::New());
3593 g1s1.MakeWeak(&counter, &WeakPointerCallback); 3679 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback);
3594 g1s2.MakeWeak(&counter, &WeakPointerCallback); 3680 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback);
3595 CHECK(g1s1.IsWeak()); 3681 CHECK(g1s1.handle.IsWeak());
3596 CHECK(g1s2.IsWeak()); 3682 CHECK(g1s2.handle.IsWeak());
3597 3683
3598 g2s1.Reset(iso, Object::New()); 3684 g2s1.handle.Reset(iso, Object::New());
3599 g2s2.Reset(iso, Object::New()); 3685 g2s2.handle.Reset(iso, Object::New());
3600 g2s1.MakeWeak(&counter, &WeakPointerCallback); 3686 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback);
3601 g2s2.MakeWeak(&counter, &WeakPointerCallback); 3687 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback);
3602 CHECK(g2s1.IsWeak()); 3688 CHECK(g2s1.handle.IsWeak());
3603 CHECK(g2s2.IsWeak()); 3689 CHECK(g2s2.handle.IsWeak());
3604 3690
3605 g3s1.Reset(iso, Object::New()); 3691 g3s1.handle.Reset(iso, Object::New());
3606 g3s2.Reset(iso, Object::New()); 3692 g3s2.handle.Reset(iso, Object::New());
3607 g3s1.MakeWeak(&counter, &WeakPointerCallback); 3693 g3s1.handle.SetWeak(&g3s1, &WeakPointerCallback);
3608 g3s2.MakeWeak(&counter, &WeakPointerCallback); 3694 g3s2.handle.SetWeak(&g3s2, &WeakPointerCallback);
3609 CHECK(g3s1.IsWeak()); 3695 CHECK(g3s1.handle.IsWeak());
3610 CHECK(g3s2.IsWeak()); 3696 CHECK(g3s2.handle.IsWeak());
3611 3697
3612 g4s1.Reset(iso, Object::New()); 3698 g4s1.handle.Reset(iso, Object::New());
3613 g4s2.Reset(iso, Object::New()); 3699 g4s2.handle.Reset(iso, Object::New());
3614 g4s1.MakeWeak(&counter, &WeakPointerCallback); 3700 g4s1.handle.SetWeak(&g4s1, &WeakPointerCallback);
3615 g4s2.MakeWeak(&counter, &WeakPointerCallback); 3701 g4s2.handle.SetWeak(&g4s2, &WeakPointerCallback);
3616 CHECK(g4s1.IsWeak()); 3702 CHECK(g4s1.handle.IsWeak());
3617 CHECK(g4s2.IsWeak()); 3703 CHECK(g4s2.handle.IsWeak());
3618 } 3704 }
3619 3705
3620 Persistent<Value> root(iso, g1s1); // make a root. 3706 WeakCallCounterAndPersistent<Value> root(&counter);
3707 root.handle.Reset(iso, g1s1.handle); // make a root.
3621 3708
3622 // Connect groups. We're building the following cycle: 3709 // Connect groups. We're building the following cycle:
3623 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other 3710 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other
3624 // groups. 3711 // groups.
3625 { 3712 {
3626 UniqueId id1 = MakeUniqueId(g1s1); 3713 UniqueId id1 = MakeUniqueId(g1s1.handle);
3627 UniqueId id2 = MakeUniqueId(g2s1); 3714 UniqueId id2 = MakeUniqueId(g2s1.handle);
3628 UniqueId id3 = MakeUniqueId(g3s1); 3715 UniqueId id3 = MakeUniqueId(g3s1.handle);
3629 UniqueId id4 = MakeUniqueId(g4s1); 3716 UniqueId id4 = MakeUniqueId(g4s1.handle);
3630 iso->SetObjectGroupId(g1s1, id1); 3717 iso->SetObjectGroupId(g1s1.handle, id1);
3631 iso->SetObjectGroupId(g1s2, id1); 3718 iso->SetObjectGroupId(g1s2.handle, id1);
3632 iso->SetReferenceFromGroup(id1, g2s1); 3719 iso->SetReferenceFromGroup(id1, g2s1.handle);
3633 iso->SetObjectGroupId(g2s1, id2); 3720 iso->SetObjectGroupId(g2s1.handle, id2);
3634 iso->SetObjectGroupId(g2s2, id2); 3721 iso->SetObjectGroupId(g2s2.handle, id2);
3635 iso->SetReferenceFromGroup(id2, g3s1); 3722 iso->SetReferenceFromGroup(id2, g3s1.handle);
3636 iso->SetObjectGroupId(g3s1, id3); 3723 iso->SetObjectGroupId(g3s1.handle, id3);
3637 iso->SetObjectGroupId(g3s2, id3); 3724 iso->SetObjectGroupId(g3s2.handle, id3);
3638 iso->SetReferenceFromGroup(id3, g4s1); 3725 iso->SetReferenceFromGroup(id3, g4s1.handle);
3639 iso->SetObjectGroupId(g4s1, id4); 3726 iso->SetObjectGroupId(g4s1.handle, id4);
3640 iso->SetObjectGroupId(g4s2, id4); 3727 iso->SetObjectGroupId(g4s2.handle, id4);
3641 iso->SetReferenceFromGroup(id4, g1s1); 3728 iso->SetReferenceFromGroup(id4, g1s1.handle);
3642 } 3729 }
3643 // Do a single full GC 3730 // Do a single full GC
3644 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( 3731 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>(
3645 iso)->heap(); 3732 iso)->heap();
3646 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 3733 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
3647 3734
3648 // All object should be alive. 3735 // All object should be alive.
3649 CHECK_EQ(0, counter.NumberOfWeakCalls()); 3736 CHECK_EQ(0, counter.NumberOfWeakCalls());
3650 3737
3651 // Weaken the root. 3738 // Weaken the root.
3652 root.MakeWeak(&counter, &WeakPointerCallback); 3739 root.handle.SetWeak(&root, &WeakPointerCallback);
3653 3740
3654 // Groups are deleted, rebuild groups. 3741 // Groups are deleted, rebuild groups.
3655 { 3742 {
3656 UniqueId id1 = MakeUniqueId(g1s1); 3743 UniqueId id1 = MakeUniqueId(g1s1.handle);
3657 UniqueId id2 = MakeUniqueId(g2s1); 3744 UniqueId id2 = MakeUniqueId(g2s1.handle);
3658 UniqueId id3 = MakeUniqueId(g3s1); 3745 UniqueId id3 = MakeUniqueId(g3s1.handle);
3659 UniqueId id4 = MakeUniqueId(g4s1); 3746 UniqueId id4 = MakeUniqueId(g4s1.handle);
3660 iso->SetObjectGroupId(g1s1, id1); 3747 iso->SetObjectGroupId(g1s1.handle, id1);
3661 iso->SetObjectGroupId(g1s2, id1); 3748 iso->SetObjectGroupId(g1s2.handle, id1);
3662 iso->SetReferenceFromGroup(id1, g2s1); 3749 iso->SetReferenceFromGroup(id1, g2s1.handle);
3663 iso->SetObjectGroupId(g2s1, id2); 3750 iso->SetObjectGroupId(g2s1.handle, id2);
3664 iso->SetObjectGroupId(g2s2, id2); 3751 iso->SetObjectGroupId(g2s2.handle, id2);
3665 iso->SetReferenceFromGroup(id2, g3s1); 3752 iso->SetReferenceFromGroup(id2, g3s1.handle);
3666 iso->SetObjectGroupId(g3s1, id3); 3753 iso->SetObjectGroupId(g3s1.handle, id3);
3667 iso->SetObjectGroupId(g3s2, id3); 3754 iso->SetObjectGroupId(g3s2.handle, id3);
3668 iso->SetReferenceFromGroup(id3, g4s1); 3755 iso->SetReferenceFromGroup(id3, g4s1.handle);
3669 iso->SetObjectGroupId(g4s1, id4); 3756 iso->SetObjectGroupId(g4s1.handle, id4);
3670 iso->SetObjectGroupId(g4s2, id4); 3757 iso->SetObjectGroupId(g4s2.handle, id4);
3671 iso->SetReferenceFromGroup(id4, g1s1); 3758 iso->SetReferenceFromGroup(id4, g1s1.handle);
3672 } 3759 }
3673 3760
3674 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 3761 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
3675 3762
3676 // All objects should be gone. 9 global handles in total. 3763 // All objects should be gone. 9 global handles in total.
3677 CHECK_EQ(9, counter.NumberOfWeakCalls()); 3764 CHECK_EQ(9, counter.NumberOfWeakCalls());
3678 } 3765 }
3679 3766
3680 3767
3681 // TODO(mstarzinger): This should be a THREADED_TEST but causes failures 3768 // TODO(mstarzinger): This should be a THREADED_TEST but causes failures
3682 // on the buildbots, so was made non-threaded for the time being. 3769 // on the buildbots, so was made non-threaded for the time being.
3683 TEST(ApiObjectGroupsCycleForScavenger) { 3770 TEST(ApiObjectGroupsCycleForScavenger) {
3684 i::FLAG_stress_compaction = false; 3771 i::FLAG_stress_compaction = false;
3685 i::FLAG_gc_global = false; 3772 i::FLAG_gc_global = false;
3686 LocalContext env; 3773 LocalContext env;
3687 v8::Isolate* iso = env->GetIsolate(); 3774 v8::Isolate* iso = env->GetIsolate();
3688 HandleScope scope(iso); 3775 HandleScope scope(iso);
3689 3776
3690 WeakCallCounter counter(1234); 3777 WeakCallCounter counter(1234);
3691 3778
3692 Persistent<Value> g1s1; 3779 WeakCallCounterAndPersistent<Value> g1s1(&counter);
3693 Persistent<Value> g1s2; 3780 WeakCallCounterAndPersistent<Value> g1s2(&counter);
3694 Persistent<Value> g2s1; 3781 WeakCallCounterAndPersistent<Value> g2s1(&counter);
3695 Persistent<Value> g2s2; 3782 WeakCallCounterAndPersistent<Value> g2s2(&counter);
3696 Persistent<Value> g3s1; 3783 WeakCallCounterAndPersistent<Value> g3s1(&counter);
3697 Persistent<Value> g3s2; 3784 WeakCallCounterAndPersistent<Value> g3s2(&counter);
3698 3785
3699 { 3786 {
3700 HandleScope scope(iso); 3787 HandleScope scope(iso);
3701 g1s1.Reset(iso, Object::New()); 3788 g1s1.handle.Reset(iso, Object::New());
3702 g1s2.Reset(iso, Object::New()); 3789 g1s2.handle.Reset(iso, Object::New());
3703 g1s1.MakeWeak(&counter, &WeakPointerCallback); 3790 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback);
3704 g1s2.MakeWeak(&counter, &WeakPointerCallback); 3791 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback);
3705 3792
3706 g2s1.Reset(iso, Object::New()); 3793 g2s1.handle.Reset(iso, Object::New());
3707 g2s2.Reset(iso, Object::New()); 3794 g2s2.handle.Reset(iso, Object::New());
3708 g2s1.MakeWeak(&counter, &WeakPointerCallback); 3795 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback);
3709 g2s2.MakeWeak(&counter, &WeakPointerCallback); 3796 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback);
3710 3797
3711 g3s1.Reset(iso, Object::New()); 3798 g3s1.handle.Reset(iso, Object::New());
3712 g3s2.Reset(iso, Object::New()); 3799 g3s2.handle.Reset(iso, Object::New());
3713 g3s1.MakeWeak(&counter, &WeakPointerCallback); 3800 g3s1.handle.SetWeak(&g3s1, &WeakPointerCallback);
3714 g3s2.MakeWeak(&counter, &WeakPointerCallback); 3801 g3s2.handle.SetWeak(&g3s2, &WeakPointerCallback);
3715 } 3802 }
3716 3803
3717 // Make a root. 3804 // Make a root.
3718 Persistent<Value> root(iso, g1s1); 3805 WeakCallCounterAndPersistent<Value> root(&counter);
3719 root.MarkPartiallyDependent(); 3806 root.handle.Reset(iso, g1s1.handle);
3807 root.handle.MarkPartiallyDependent();
3720 3808
3721 // Connect groups. We're building the following cycle: 3809 // Connect groups. We're building the following cycle:
3722 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other 3810 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other
3723 // groups. 3811 // groups.
3724 { 3812 {
3725 HandleScope handle_scope(iso); 3813 HandleScope handle_scope(iso);
3726 g1s1.MarkPartiallyDependent(); 3814 g1s1.handle.MarkPartiallyDependent();
3727 g1s2.MarkPartiallyDependent(); 3815 g1s2.handle.MarkPartiallyDependent();
3728 g2s1.MarkPartiallyDependent(); 3816 g2s1.handle.MarkPartiallyDependent();
3729 g2s2.MarkPartiallyDependent(); 3817 g2s2.handle.MarkPartiallyDependent();
3730 g3s1.MarkPartiallyDependent(); 3818 g3s1.handle.MarkPartiallyDependent();
3731 g3s2.MarkPartiallyDependent(); 3819 g3s2.handle.MarkPartiallyDependent();
3732 iso->SetObjectGroupId(g1s1, UniqueId(1)); 3820 iso->SetObjectGroupId(g1s1.handle, UniqueId(1));
3733 iso->SetObjectGroupId(g1s2, UniqueId(1)); 3821 iso->SetObjectGroupId(g1s2.handle, UniqueId(1));
3734 Local<Object>::New(iso, g1s1.As<Object>())->Set( 3822 Local<Object>::New(iso, g1s1.handle.As<Object>())->Set(
3735 v8_str("x"), Local<Value>::New(iso, g2s1)); 3823 v8_str("x"), Local<Value>::New(iso, g2s1.handle));
3736 iso->SetObjectGroupId(g2s1, UniqueId(2)); 3824 iso->SetObjectGroupId(g2s1.handle, UniqueId(2));
3737 iso->SetObjectGroupId(g2s2, UniqueId(2)); 3825 iso->SetObjectGroupId(g2s2.handle, UniqueId(2));
3738 Local<Object>::New(iso, g2s1.As<Object>())->Set( 3826 Local<Object>::New(iso, g2s1.handle.As<Object>())->Set(
3739 v8_str("x"), Local<Value>::New(iso, g3s1)); 3827 v8_str("x"), Local<Value>::New(iso, g3s1.handle));
3740 iso->SetObjectGroupId(g3s1, UniqueId(3)); 3828 iso->SetObjectGroupId(g3s1.handle, UniqueId(3));
3741 iso->SetObjectGroupId(g3s2, UniqueId(3)); 3829 iso->SetObjectGroupId(g3s2.handle, UniqueId(3));
3742 Local<Object>::New(iso, g3s1.As<Object>())->Set( 3830 Local<Object>::New(iso, g3s1.handle.As<Object>())->Set(
3743 v8_str("x"), Local<Value>::New(iso, g1s1)); 3831 v8_str("x"), Local<Value>::New(iso, g1s1.handle));
3744 } 3832 }
3745 3833
3746 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( 3834 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>(
3747 iso)->heap(); 3835 iso)->heap();
3748 heap->CollectGarbage(i::NEW_SPACE); 3836 heap->CollectGarbage(i::NEW_SPACE);
3749 3837
3750 // All objects should be alive. 3838 // All objects should be alive.
3751 CHECK_EQ(0, counter.NumberOfWeakCalls()); 3839 CHECK_EQ(0, counter.NumberOfWeakCalls());
3752 3840
3753 // Weaken the root. 3841 // Weaken the root.
3754 root.MakeWeak(&counter, &WeakPointerCallback); 3842 root.handle.SetWeak(&root, &WeakPointerCallback);
3755 root.MarkPartiallyDependent(); 3843 root.handle.MarkPartiallyDependent();
3756 3844
3757 // Groups are deleted, rebuild groups. 3845 // Groups are deleted, rebuild groups.
3758 { 3846 {
3759 HandleScope handle_scope(iso); 3847 HandleScope handle_scope(iso);
3760 g1s1.MarkPartiallyDependent(); 3848 g1s1.handle.MarkPartiallyDependent();
3761 g1s2.MarkPartiallyDependent(); 3849 g1s2.handle.MarkPartiallyDependent();
3762 g2s1.MarkPartiallyDependent(); 3850 g2s1.handle.MarkPartiallyDependent();
3763 g2s2.MarkPartiallyDependent(); 3851 g2s2.handle.MarkPartiallyDependent();
3764 g3s1.MarkPartiallyDependent(); 3852 g3s1.handle.MarkPartiallyDependent();
3765 g3s2.MarkPartiallyDependent(); 3853 g3s2.handle.MarkPartiallyDependent();
3766 iso->SetObjectGroupId(g1s1, UniqueId(1)); 3854 iso->SetObjectGroupId(g1s1.handle, UniqueId(1));
3767 iso->SetObjectGroupId(g1s2, UniqueId(1)); 3855 iso->SetObjectGroupId(g1s2.handle, UniqueId(1));
3768 Local<Object>::New(iso, g1s1.As<Object>())->Set( 3856 Local<Object>::New(iso, g1s1.handle.As<Object>())->Set(
3769 v8_str("x"), Local<Value>::New(iso, g2s1)); 3857 v8_str("x"), Local<Value>::New(iso, g2s1.handle));
3770 iso->SetObjectGroupId(g2s1, UniqueId(2)); 3858 iso->SetObjectGroupId(g2s1.handle, UniqueId(2));
3771 iso->SetObjectGroupId(g2s2, UniqueId(2)); 3859 iso->SetObjectGroupId(g2s2.handle, UniqueId(2));
3772 Local<Object>::New(iso, g2s1.As<Object>())->Set( 3860 Local<Object>::New(iso, g2s1.handle.As<Object>())->Set(
3773 v8_str("x"), Local<Value>::New(iso, g3s1)); 3861 v8_str("x"), Local<Value>::New(iso, g3s1.handle));
3774 iso->SetObjectGroupId(g3s1, UniqueId(3)); 3862 iso->SetObjectGroupId(g3s1.handle, UniqueId(3));
3775 iso->SetObjectGroupId(g3s2, UniqueId(3)); 3863 iso->SetObjectGroupId(g3s2.handle, UniqueId(3));
3776 Local<Object>::New(iso, g3s1.As<Object>())->Set( 3864 Local<Object>::New(iso, g3s1.handle.As<Object>())->Set(
3777 v8_str("x"), Local<Value>::New(iso, g1s1)); 3865 v8_str("x"), Local<Value>::New(iso, g1s1.handle));
3778 } 3866 }
3779 3867
3780 heap->CollectGarbage(i::NEW_SPACE); 3868 heap->CollectGarbage(i::NEW_SPACE);
3781 3869
3782 // All objects should be gone. 7 global handles in total. 3870 // All objects should be gone. 7 global handles in total.
3783 CHECK_EQ(7, counter.NumberOfWeakCalls()); 3871 CHECK_EQ(7, counter.NumberOfWeakCalls());
3784 } 3872 }
3785 3873
3786 3874
3787 THREADED_TEST(ScriptException) { 3875 THREADED_TEST(ScriptException) {
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
4067 CHECK(try_catch.HasCaught()); 4155 CHECK(try_catch.HasCaught());
4068 String::Utf8Value exception_value(try_catch.Exception()); 4156 String::Utf8Value exception_value(try_catch.Exception());
4069 CHECK_EQ("exception", *exception_value); 4157 CHECK_EQ("exception", *exception_value);
4070 try_catch.Reset(); 4158 try_catch.Reset();
4071 } 4159 }
4072 4160
4073 4161
4074 THREADED_TEST(Array) { 4162 THREADED_TEST(Array) {
4075 LocalContext context; 4163 LocalContext context;
4076 v8::HandleScope scope(context->GetIsolate()); 4164 v8::HandleScope scope(context->GetIsolate());
4077 Local<v8::Array> array = v8::Array::New(); 4165 Local<v8::Array> array = v8::Array::New(context->GetIsolate());
4078 CHECK_EQ(0, array->Length()); 4166 CHECK_EQ(0, array->Length());
4079 CHECK(array->Get(0)->IsUndefined()); 4167 CHECK(array->Get(0)->IsUndefined());
4080 CHECK(!array->Has(0)); 4168 CHECK(!array->Has(0));
4081 CHECK(array->Get(100)->IsUndefined()); 4169 CHECK(array->Get(100)->IsUndefined());
4082 CHECK(!array->Has(100)); 4170 CHECK(!array->Has(100));
4083 array->Set(2, v8_num(7)); 4171 array->Set(2, v8_num(7));
4084 CHECK_EQ(3, array->Length()); 4172 CHECK_EQ(3, array->Length());
4085 CHECK(!array->Has(0)); 4173 CHECK(!array->Has(0));
4086 CHECK(!array->Has(1)); 4174 CHECK(!array->Has(1));
4087 CHECK(array->Has(2)); 4175 CHECK(array->Has(2));
4088 CHECK_EQ(7, array->Get(2)->Int32Value()); 4176 CHECK_EQ(7, array->Get(2)->Int32Value());
4089 Local<Value> obj = Script::Compile(v8_str("[1, 2, 3]"))->Run(); 4177 Local<Value> obj = Script::Compile(v8_str("[1, 2, 3]"))->Run();
4090 Local<v8::Array> arr = obj.As<v8::Array>(); 4178 Local<v8::Array> arr = obj.As<v8::Array>();
4091 CHECK_EQ(3, arr->Length()); 4179 CHECK_EQ(3, arr->Length());
4092 CHECK_EQ(1, arr->Get(0)->Int32Value()); 4180 CHECK_EQ(1, arr->Get(0)->Int32Value());
4093 CHECK_EQ(2, arr->Get(1)->Int32Value()); 4181 CHECK_EQ(2, arr->Get(1)->Int32Value());
4094 CHECK_EQ(3, arr->Get(2)->Int32Value()); 4182 CHECK_EQ(3, arr->Get(2)->Int32Value());
4095 array = v8::Array::New(27); 4183 array = v8::Array::New(context->GetIsolate(), 27);
4096 CHECK_EQ(27, array->Length()); 4184 CHECK_EQ(27, array->Length());
4097 array = v8::Array::New(-27); 4185 array = v8::Array::New(context->GetIsolate(), -27);
4098 CHECK_EQ(0, array->Length()); 4186 CHECK_EQ(0, array->Length());
4099 } 4187 }
4100 4188
4101 4189
4102 void HandleF(const v8::FunctionCallbackInfo<v8::Value>& args) { 4190 void HandleF(const v8::FunctionCallbackInfo<v8::Value>& args) {
4103 v8::HandleScope scope(args.GetIsolate()); 4191 v8::EscapableHandleScope scope(args.GetIsolate());
4104 ApiTestFuzzer::Fuzz(); 4192 ApiTestFuzzer::Fuzz();
4105 Local<v8::Array> result = v8::Array::New(args.Length()); 4193 Local<v8::Array> result = v8::Array::New(args.GetIsolate(), args.Length());
4106 for (int i = 0; i < args.Length(); i++) 4194 for (int i = 0; i < args.Length(); i++)
4107 result->Set(i, args[i]); 4195 result->Set(i, args[i]);
4108 args.GetReturnValue().Set(scope.Close(result)); 4196 args.GetReturnValue().Set(scope.Escape(result));
4109 } 4197 }
4110 4198
4111 4199
4112 THREADED_TEST(Vector) { 4200 THREADED_TEST(Vector) {
4113 v8::HandleScope scope(CcTest::isolate()); 4201 v8::HandleScope scope(CcTest::isolate());
4114 Local<ObjectTemplate> global = ObjectTemplate::New(); 4202 Local<ObjectTemplate> global = ObjectTemplate::New();
4115 global->Set(v8_str("f"), v8::FunctionTemplate::New(HandleF)); 4203 global->Set(v8_str("f"), v8::FunctionTemplate::New(HandleF));
4116 LocalContext context(0, global); 4204 LocalContext context(0, global);
4117 4205
4118 const char* fun = "f()"; 4206 const char* fun = "f()";
(...skipping 2240 matching lines...) Expand 10 before | Expand all | Expand 10 after
6359 " testBool();" 6447 " testBool();"
6360 "}\n" 6448 "}\n"
6361 "\"PASS\"", 6449 "\"PASS\"",
6362 "PASS"); 6450 "PASS");
6363 } 6451 }
6364 6452
6365 6453
6366 template <typename T> static void USE(T) { } 6454 template <typename T> static void USE(T) { }
6367 6455
6368 6456
6369 // This test is not intended to be run, just type checked. 6457 // The point of this test is type checking. We run it only so compilers
6370 static inline void PersistentHandles(v8::Isolate* isolate) { 6458 // don't complain about an unused function.
6371 USE(PersistentHandles); 6459 TEST(PersistentHandles) {
6460 LocalContext env;
6461 v8::Isolate* isolate = CcTest::isolate();
6462 v8::HandleScope scope(isolate);
6372 Local<String> str = v8_str("foo"); 6463 Local<String> str = v8_str("foo");
6373 v8::Persistent<String> p_str(isolate, str); 6464 v8::Persistent<String> p_str(isolate, str);
6374 p_str.Reset(); 6465 p_str.Reset();
6375 Local<Script> scr = Script::Compile(v8_str("")); 6466 Local<Script> scr = Script::Compile(v8_str(""));
6376 v8::Persistent<Script> p_scr(isolate, scr); 6467 v8::Persistent<Script> p_scr(isolate, scr);
6377 p_scr.Reset(); 6468 p_scr.Reset();
6378 Local<ObjectTemplate> templ = ObjectTemplate::New(); 6469 Local<ObjectTemplate> templ = ObjectTemplate::New();
6379 v8::Persistent<ObjectTemplate> p_templ(isolate, templ); 6470 v8::Persistent<ObjectTemplate> p_templ(isolate, templ);
6380 p_templ.Reset(); 6471 p_templ.Reset();
6381 } 6472 }
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
6615 6706
6616 6707
6617 class NativeFunctionExtension : public Extension { 6708 class NativeFunctionExtension : public Extension {
6618 public: 6709 public:
6619 NativeFunctionExtension(const char* name, 6710 NativeFunctionExtension(const char* name,
6620 const char* source, 6711 const char* source,
6621 v8::FunctionCallback fun = &Echo) 6712 v8::FunctionCallback fun = &Echo)
6622 : Extension(name, source), 6713 : Extension(name, source),
6623 function_(fun) { } 6714 function_(fun) { }
6624 6715
6625 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 6716 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate(
6717 v8::Isolate* isolate,
6626 v8::Handle<v8::String> name) { 6718 v8::Handle<v8::String> name) {
6627 return v8::FunctionTemplate::New(function_); 6719 return v8::FunctionTemplate::New(function_);
6628 } 6720 }
6629 6721
6630 static void Echo(const v8::FunctionCallbackInfo<v8::Value>& args) { 6722 static void Echo(const v8::FunctionCallbackInfo<v8::Value>& args) {
6631 if (args.Length() >= 1) args.GetReturnValue().Set(args[0]); 6723 if (args.Length() >= 1) args.GetReturnValue().Set(args[0]);
6632 } 6724 }
6633 private: 6725 private:
6634 v8::FunctionCallback function_; 6726 v8::FunctionCallback function_;
6635 }; 6727 };
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
6736 args.GetReturnValue().SetNull(); 6828 args.GetReturnValue().SetNull();
6737 return; 6829 return;
6738 } 6830 }
6739 args.GetReturnValue().Set(args.Data()); 6831 args.GetReturnValue().Set(args.Data());
6740 } 6832 }
6741 6833
6742 6834
6743 class FunctionExtension : public Extension { 6835 class FunctionExtension : public Extension {
6744 public: 6836 public:
6745 FunctionExtension() : Extension("functiontest", kExtensionTestScript) { } 6837 FunctionExtension() : Extension("functiontest", kExtensionTestScript) { }
6746 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 6838 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate(
6839 v8::Isolate* isolate,
6747 v8::Handle<String> name); 6840 v8::Handle<String> name);
6748 }; 6841 };
6749 6842
6750 6843
6751 static int lookup_count = 0; 6844 static int lookup_count = 0;
6752 v8::Handle<v8::FunctionTemplate> FunctionExtension::GetNativeFunction( 6845 v8::Handle<v8::FunctionTemplate> FunctionExtension::GetNativeFunctionTemplate(
6753 v8::Handle<String> name) { 6846 v8::Isolate* isolate, v8::Handle<String> name) {
6754 lookup_count++; 6847 lookup_count++;
6755 if (name->Equals(v8_str("A"))) { 6848 if (name->Equals(v8_str("A"))) {
6756 return v8::FunctionTemplate::New(CallFun, v8::Integer::New(8)); 6849 return v8::FunctionTemplate::New(CallFun, v8::Integer::New(8));
6757 } else if (name->Equals(v8_str("B"))) { 6850 } else if (name->Equals(v8_str("B"))) {
6758 return v8::FunctionTemplate::New(CallFun, v8::Integer::New(7)); 6851 return v8::FunctionTemplate::New(CallFun, v8::Integer::New(7));
6759 } else if (name->Equals(v8_str("C"))) { 6852 } else if (name->Equals(v8_str("C"))) {
6760 return v8::FunctionTemplate::New(CallFun, v8::Integer::New(6)); 6853 return v8::FunctionTemplate::New(CallFun, v8::Integer::New(6));
6761 } else { 6854 } else {
6762 return v8::Handle<v8::FunctionTemplate>(); 6855 return v8::Handle<v8::FunctionTemplate>();
6763 } 6856 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
6864 LocalContext context; 6957 LocalContext context;
6865 v8::HandleScope scope(context->GetIsolate()); 6958 v8::HandleScope scope(context->GetIsolate());
6866 v8::V8::AddMessageListener(MissingScriptInfoMessageListener); 6959 v8::V8::AddMessageListener(MissingScriptInfoMessageListener);
6867 Script::Compile(v8_str("throw Error()"))->Run(); 6960 Script::Compile(v8_str("throw Error()"))->Run();
6868 v8::V8::RemoveMessageListeners(MissingScriptInfoMessageListener); 6961 v8::V8::RemoveMessageListeners(MissingScriptInfoMessageListener);
6869 } 6962 }
6870 6963
6871 6964
6872 int global_index = 0; 6965 int global_index = 0;
6873 6966
6967 template<typename T>
6874 class Snorkel { 6968 class Snorkel {
6875 public: 6969 public:
6876 Snorkel() { index_ = global_index++; } 6970 explicit Snorkel(v8::Persistent<T>* handle) : handle_(handle) {
6971 index_ = global_index++;
6972 }
6973 v8::Persistent<T>* handle_;
6877 int index_; 6974 int index_;
6878 }; 6975 };
6879 6976
6880 class Whammy { 6977 class Whammy {
6881 public: 6978 public:
6882 explicit Whammy(v8::Isolate* isolate) : cursor_(0), isolate_(isolate) { } 6979 explicit Whammy(v8::Isolate* isolate) : cursor_(0), isolate_(isolate) { }
6883 ~Whammy() { script_.Reset(); } 6980 ~Whammy() { script_.Reset(); }
6884 v8::Handle<Script> getScript() { 6981 v8::Handle<Script> getScript() {
6885 if (script_.IsEmpty()) script_.Reset(isolate_, v8_compile("({}).blammo")); 6982 if (script_.IsEmpty()) script_.Reset(isolate_, v8_compile("({}).blammo"));
6886 return Local<Script>::New(isolate_, script_); 6983 return Local<Script>::New(isolate_, script_);
6887 } 6984 }
6888 6985
6889 public: 6986 public:
6890 static const int kObjectCount = 256; 6987 static const int kObjectCount = 256;
6891 int cursor_; 6988 int cursor_;
6892 v8::Isolate* isolate_; 6989 v8::Isolate* isolate_;
6893 v8::Persistent<v8::Object> objects_[kObjectCount]; 6990 v8::Persistent<v8::Object> objects_[kObjectCount];
6894 v8::Persistent<Script> script_; 6991 v8::Persistent<Script> script_;
6895 }; 6992 };
6896 6993
6897 static void HandleWeakReference(v8::Isolate* isolate, 6994 static void HandleWeakReference(
6898 v8::Persistent<v8::Value>* obj, 6995 const v8::WeakCallbackData<v8::Value, Snorkel<v8::Value> >& data) {
6899 Snorkel* snorkel) { 6996 data.GetParameter()->handle_->ClearWeak();
6900 delete snorkel; 6997 delete data.GetParameter();
6901 obj->ClearWeak();
6902 } 6998 }
6903 6999
6904 void WhammyPropertyGetter(Local<String> name, 7000 void WhammyPropertyGetter(Local<String> name,
6905 const v8::PropertyCallbackInfo<v8::Value>& info) { 7001 const v8::PropertyCallbackInfo<v8::Value>& info) {
6906 Whammy* whammy = 7002 Whammy* whammy =
6907 static_cast<Whammy*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); 7003 static_cast<Whammy*>(v8::Handle<v8::External>::Cast(info.Data())->Value());
6908 7004
6909 v8::Persistent<v8::Object>& prev = whammy->objects_[whammy->cursor_]; 7005 v8::Persistent<v8::Object>& prev = whammy->objects_[whammy->cursor_];
6910 7006
6911 v8::Handle<v8::Object> obj = v8::Object::New(); 7007 v8::Handle<v8::Object> obj = v8::Object::New();
6912 if (!prev.IsEmpty()) { 7008 if (!prev.IsEmpty()) {
6913 v8::Local<v8::Object>::New(info.GetIsolate(), prev) 7009 v8::Local<v8::Object>::New(info.GetIsolate(), prev)
6914 ->Set(v8_str("next"), obj); 7010 ->Set(v8_str("next"), obj);
6915 prev.MakeWeak<Value, Snorkel>(new Snorkel(), &HandleWeakReference); 7011 prev.SetWeak<Value, Snorkel<Value> >(new Snorkel<Value>(&prev.As<Value>()),
7012 &HandleWeakReference);
6916 } 7013 }
6917 whammy->objects_[whammy->cursor_].Reset(info.GetIsolate(), obj); 7014 whammy->objects_[whammy->cursor_].Reset(info.GetIsolate(), obj);
6918 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount; 7015 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount;
6919 info.GetReturnValue().Set(whammy->getScript()->Run()); 7016 info.GetReturnValue().Set(whammy->getScript()->Run());
6920 } 7017 }
6921 7018
6922 7019
6923 THREADED_TEST(WeakReference) { 7020 THREADED_TEST(WeakReference) {
6924 v8::HandleScope handle_scope(CcTest::isolate()); 7021 v8::HandleScope handle_scope(CcTest::isolate());
6925 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New(); 7022 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New();
(...skipping 17 matching lines...) Expand all
6943 " last = obj;" 7040 " last = obj;"
6944 "}" 7041 "}"
6945 "gc();" 7042 "gc();"
6946 "4"; 7043 "4";
6947 v8::Handle<Value> result = CompileRun(code); 7044 v8::Handle<Value> result = CompileRun(code);
6948 CHECK_EQ(4.0, result->NumberValue()); 7045 CHECK_EQ(4.0, result->NumberValue());
6949 delete whammy; 7046 delete whammy;
6950 } 7047 }
6951 7048
6952 7049
6953 static void DisposeAndSetFlag(v8::Isolate* isolate, 7050 struct FlagAndPersistent {
6954 v8::Persistent<v8::Object>* obj, 7051 bool flag;
6955 bool* data) { 7052 v8::Persistent<v8::Object> handle;
6956 obj->Reset(); 7053 };
6957 *(data) = true; 7054
7055
7056 static void DisposeAndSetFlag(
7057 const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) {
7058 data.GetParameter()->handle.Reset();
7059 data.GetParameter()->flag = true;
6958 } 7060 }
6959 7061
6960 7062
6961 THREADED_TEST(IndependentWeakHandle) { 7063 THREADED_TEST(IndependentWeakHandle) {
6962 v8::Isolate* iso = CcTest::isolate(); 7064 v8::Isolate* iso = CcTest::isolate();
6963 v8::HandleScope scope(iso); 7065 v8::HandleScope scope(iso);
6964 v8::Handle<Context> context = Context::New(iso); 7066 v8::Handle<Context> context = Context::New(iso);
6965 Context::Scope context_scope(context); 7067 Context::Scope context_scope(context);
6966 7068
6967 v8::Persistent<v8::Object> object_a, object_b; 7069 FlagAndPersistent object_a, object_b;
6968 7070
6969 { 7071 {
6970 v8::HandleScope handle_scope(iso); 7072 v8::HandleScope handle_scope(iso);
6971 object_a.Reset(iso, v8::Object::New()); 7073 object_a.handle.Reset(iso, v8::Object::New());
6972 object_b.Reset(iso, v8::Object::New()); 7074 object_b.handle.Reset(iso, v8::Object::New());
6973 } 7075 }
6974 7076
6975 bool object_a_disposed = false; 7077 object_a.flag = false;
6976 bool object_b_disposed = false; 7078 object_b.flag = false;
6977 object_a.MakeWeak(&object_a_disposed, &DisposeAndSetFlag); 7079 object_a.handle.SetWeak(&object_a, &DisposeAndSetFlag);
6978 object_b.MakeWeak(&object_b_disposed, &DisposeAndSetFlag); 7080 object_b.handle.SetWeak(&object_b, &DisposeAndSetFlag);
6979 CHECK(!object_b.IsIndependent()); 7081 CHECK(!object_b.handle.IsIndependent());
6980 object_a.MarkIndependent(); 7082 object_a.handle.MarkIndependent();
6981 object_b.MarkIndependent(); 7083 object_b.handle.MarkIndependent();
6982 CHECK(object_b.IsIndependent()); 7084 CHECK(object_b.handle.IsIndependent());
6983 CcTest::heap()->PerformScavenge(); 7085 CcTest::heap()->PerformScavenge();
6984 CHECK(object_a_disposed); 7086 CHECK(object_a.flag);
6985 CHECK(object_b_disposed); 7087 CHECK(object_b.flag);
6986 } 7088 }
6987 7089
6988 7090
6989 static void InvokeScavenge() { 7091 static void InvokeScavenge() {
6990 CcTest::heap()->PerformScavenge(); 7092 CcTest::heap()->PerformScavenge();
6991 } 7093 }
6992 7094
6993 7095
6994 static void InvokeMarkSweep() { 7096 static void InvokeMarkSweep() {
6995 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 7097 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
6996 } 7098 }
6997 7099
6998 7100
6999 static void ForceScavenge(v8::Isolate* isolate, 7101 static void ForceScavenge(
7000 v8::Persistent<v8::Object>* obj, 7102 const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) {
7001 bool* data) { 7103 data.GetParameter()->handle.Reset();
7002 obj->Reset(); 7104 data.GetParameter()->flag = true;
7003 *(data) = true;
7004 InvokeScavenge(); 7105 InvokeScavenge();
7005 } 7106 }
7006 7107
7007 7108
7008 static void ForceMarkSweep(v8::Isolate* isolate, 7109 static void ForceMarkSweep(
7009 v8::Persistent<v8::Object>* obj, 7110 const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) {
7010 bool* data) { 7111 data.GetParameter()->handle.Reset();
7011 obj->Reset(); 7112 data.GetParameter()->flag = true;
7012 *(data) = true;
7013 InvokeMarkSweep(); 7113 InvokeMarkSweep();
7014 } 7114 }
7015 7115
7016 7116
7017 THREADED_TEST(GCFromWeakCallbacks) { 7117 THREADED_TEST(GCFromWeakCallbacks) {
7018 v8::Isolate* isolate = CcTest::isolate(); 7118 v8::Isolate* isolate = CcTest::isolate();
7019 v8::HandleScope scope(isolate); 7119 v8::HandleScope scope(isolate);
7020 v8::Handle<Context> context = Context::New(isolate); 7120 v8::Handle<Context> context = Context::New(isolate);
7021 Context::Scope context_scope(context); 7121 Context::Scope context_scope(context);
7022 7122
7023 static const int kNumberOfGCTypes = 2; 7123 static const int kNumberOfGCTypes = 2;
7024 typedef v8::WeakReferenceCallbacks<v8::Object, bool>::Revivable Callback; 7124 typedef v8::WeakCallbackData<v8::Object, FlagAndPersistent>::Callback
7125 Callback;
7025 Callback gc_forcing_callback[kNumberOfGCTypes] = 7126 Callback gc_forcing_callback[kNumberOfGCTypes] =
7026 {&ForceScavenge, &ForceMarkSweep}; 7127 {&ForceScavenge, &ForceMarkSweep};
7027 7128
7028 typedef void (*GCInvoker)(); 7129 typedef void (*GCInvoker)();
7029 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep}; 7130 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep};
7030 7131
7031 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) { 7132 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) {
7032 for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) { 7133 for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) {
7033 v8::Persistent<v8::Object> object; 7134 FlagAndPersistent object;
7034 { 7135 {
7035 v8::HandleScope handle_scope(isolate); 7136 v8::HandleScope handle_scope(isolate);
7036 object.Reset(isolate, v8::Object::New()); 7137 object.handle.Reset(isolate, v8::Object::New());
7037 } 7138 }
7038 bool disposed = false; 7139 object.flag = false;
7039 object.MakeWeak(&disposed, gc_forcing_callback[inner_gc]); 7140 object.handle.SetWeak(&object, gc_forcing_callback[inner_gc]);
7040 object.MarkIndependent(); 7141 object.handle.MarkIndependent();
7041 invoke_gc[outer_gc](); 7142 invoke_gc[outer_gc]();
7042 CHECK(disposed); 7143 CHECK(object.flag);
7043 } 7144 }
7044 } 7145 }
7045 } 7146 }
7046 7147
7047 7148
7048 static void RevivingCallback(v8::Isolate* isolate, 7149 static void RevivingCallback(
7049 v8::Persistent<v8::Object>* obj, 7150 const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) {
7050 bool* data) { 7151 data.GetParameter()->handle.ClearWeak();
7051 obj->ClearWeak(); 7152 data.GetParameter()->flag = true;
7052 *(data) = true;
7053 } 7153 }
7054 7154
7055 7155
7056 THREADED_TEST(IndependentHandleRevival) { 7156 THREADED_TEST(IndependentHandleRevival) {
7057 v8::Isolate* isolate = CcTest::isolate(); 7157 v8::Isolate* isolate = CcTest::isolate();
7058 v8::HandleScope scope(isolate); 7158 v8::HandleScope scope(isolate);
7059 v8::Handle<Context> context = Context::New(isolate); 7159 v8::Handle<Context> context = Context::New(isolate);
7060 Context::Scope context_scope(context); 7160 Context::Scope context_scope(context);
7061 7161
7062 v8::Persistent<v8::Object> object; 7162 FlagAndPersistent object;
7063 { 7163 {
7064 v8::HandleScope handle_scope(isolate); 7164 v8::HandleScope handle_scope(isolate);
7065 v8::Local<v8::Object> o = v8::Object::New(); 7165 v8::Local<v8::Object> o = v8::Object::New();
7066 object.Reset(isolate, o); 7166 object.handle.Reset(isolate, o);
7067 o->Set(v8_str("x"), v8::Integer::New(1)); 7167 o->Set(v8_str("x"), v8::Integer::New(1));
7068 v8::Local<String> y_str = v8_str("y"); 7168 v8::Local<String> y_str = v8_str("y");
7069 o->Set(y_str, y_str); 7169 o->Set(y_str, y_str);
7070 } 7170 }
7071 bool revived = false; 7171 object.flag = false;
7072 object.MakeWeak(&revived, &RevivingCallback); 7172 object.handle.SetWeak(&object, &RevivingCallback);
7073 object.MarkIndependent(); 7173 object.handle.MarkIndependent();
7074 CcTest::heap()->PerformScavenge(); 7174 CcTest::heap()->PerformScavenge();
7075 CHECK(revived); 7175 CHECK(object.flag);
7076 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 7176 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
7077 { 7177 {
7078 v8::HandleScope handle_scope(isolate); 7178 v8::HandleScope handle_scope(isolate);
7079 v8::Local<v8::Object> o = v8::Local<v8::Object>::New(isolate, object); 7179 v8::Local<v8::Object> o =
7180 v8::Local<v8::Object>::New(isolate, object.handle);
7080 v8::Local<String> y_str = v8_str("y"); 7181 v8::Local<String> y_str = v8_str("y");
7081 CHECK_EQ(v8::Integer::New(1), o->Get(v8_str("x"))); 7182 CHECK_EQ(v8::Integer::New(1), o->Get(v8_str("x")));
7082 CHECK(o->Get(y_str)->Equals(y_str)); 7183 CHECK(o->Get(y_str)->Equals(y_str));
7083 } 7184 }
7084 } 7185 }
7085 7186
7086 7187
7087 v8::Handle<Function> args_fun; 7188 v8::Handle<Function> args_fun;
7088 7189
7089 7190
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
7181 7282
7182 static void IndexedGetK(uint32_t index, 7283 static void IndexedGetK(uint32_t index,
7183 const v8::PropertyCallbackInfo<v8::Value>& info) { 7284 const v8::PropertyCallbackInfo<v8::Value>& info) {
7184 ApiTestFuzzer::Fuzz(); 7285 ApiTestFuzzer::Fuzz();
7185 if (index == 0 || index == 1) info.GetReturnValue().SetUndefined(); 7286 if (index == 0 || index == 1) info.GetReturnValue().SetUndefined();
7186 } 7287 }
7187 7288
7188 7289
7189 static void NamedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) { 7290 static void NamedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) {
7190 ApiTestFuzzer::Fuzz(); 7291 ApiTestFuzzer::Fuzz();
7191 v8::Handle<v8::Array> result = v8::Array::New(3); 7292 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 3);
7192 result->Set(v8::Integer::New(0), v8_str("foo")); 7293 result->Set(v8::Integer::New(0), v8_str("foo"));
7193 result->Set(v8::Integer::New(1), v8_str("bar")); 7294 result->Set(v8::Integer::New(1), v8_str("bar"));
7194 result->Set(v8::Integer::New(2), v8_str("baz")); 7295 result->Set(v8::Integer::New(2), v8_str("baz"));
7195 info.GetReturnValue().Set(result); 7296 info.GetReturnValue().Set(result);
7196 } 7297 }
7197 7298
7198 7299
7199 static void IndexedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) { 7300 static void IndexedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) {
7200 ApiTestFuzzer::Fuzz(); 7301 ApiTestFuzzer::Fuzz();
7201 v8::Handle<v8::Array> result = v8::Array::New(2); 7302 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2);
7202 result->Set(v8::Integer::New(0), v8_str("0")); 7303 result->Set(v8::Integer::New(0), v8_str("0"));
7203 result->Set(v8::Integer::New(1), v8_str("1")); 7304 result->Set(v8::Integer::New(1), v8_str("1"));
7204 info.GetReturnValue().Set(result); 7305 info.GetReturnValue().Set(result);
7205 } 7306 }
7206 7307
7207 7308
7208 THREADED_TEST(Enumerators) { 7309 THREADED_TEST(Enumerators) {
7209 v8::HandleScope scope(CcTest::isolate()); 7310 v8::HandleScope scope(CcTest::isolate());
7210 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 7311 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
7211 obj->SetNamedPropertyHandler(GetK, NULL, NULL, NULL, NamedEnum); 7312 obj->SetNamedPropertyHandler(GetK, NULL, NULL, NULL, NamedEnum);
(...skipping 1801 matching lines...) Expand 10 before | Expand all | Expand 10 after
9013 value = CompileRun("Object.getOwnPropertyNames(object).length == 0"); 9114 value = CompileRun("Object.getOwnPropertyNames(object).length == 0");
9014 CHECK(value->IsTrue()); 9115 CHECK(value->IsTrue());
9015 9116
9016 context1->Exit(); 9117 context1->Exit();
9017 context0->Exit(); 9118 context0->Exit();
9018 } 9119 }
9019 9120
9020 9121
9021 static void IndexedPropertyEnumerator( 9122 static void IndexedPropertyEnumerator(
9022 const v8::PropertyCallbackInfo<v8::Array>& info) { 9123 const v8::PropertyCallbackInfo<v8::Array>& info) {
9023 v8::Handle<v8::Array> result = v8::Array::New(2); 9124 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2);
9024 result->Set(0, v8::Integer::New(7)); 9125 result->Set(0, v8::Integer::New(7));
9025 result->Set(1, v8::Object::New()); 9126 result->Set(1, v8::Object::New());
9026 info.GetReturnValue().Set(result); 9127 info.GetReturnValue().Set(result);
9027 } 9128 }
9028 9129
9029 9130
9030 static void NamedPropertyEnumerator( 9131 static void NamedPropertyEnumerator(
9031 const v8::PropertyCallbackInfo<v8::Array>& info) { 9132 const v8::PropertyCallbackInfo<v8::Array>& info) {
9032 v8::Handle<v8::Array> result = v8::Array::New(2); 9133 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2);
9033 result->Set(0, v8_str("x")); 9134 result->Set(0, v8_str("x"));
9034 result->Set(1, v8::Object::New()); 9135 result->Set(1, v8::Object::New());
9035 info.GetReturnValue().Set(result); 9136 info.GetReturnValue().Set(result);
9036 } 9137 }
9037 9138
9038 9139
9039 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) { 9140 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) {
9040 v8::HandleScope handle_scope(CcTest::isolate()); 9141 v8::HandleScope handle_scope(CcTest::isolate());
9041 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(); 9142 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New();
9042 9143
(...skipping 2477 matching lines...) Expand 10 before | Expand all | Expand 10 after
11520 // This should move the stub 11621 // This should move the stub
11521 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed 11622 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed
11522 } 11623 }
11523 } 11624 }
11524 11625
11525 11626
11526 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { 11627 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) {
11527 LocalContext context; 11628 LocalContext context;
11528 v8::HandleScope scope(context->GetIsolate()); 11629 v8::HandleScope scope(context->GetIsolate());
11529 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); 11630 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New();
11530 nativeobject_templ->Set("callback", 11631 nativeobject_templ->Set(context->GetIsolate(), "callback",
11531 v8::FunctionTemplate::New(DirectApiCallback)); 11632 v8::FunctionTemplate::New(DirectApiCallback));
11532 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); 11633 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance();
11533 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); 11634 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj);
11534 // call the api function multiple times to ensure direct call stub creation. 11635 // call the api function multiple times to ensure direct call stub creation.
11535 CompileRun( 11636 CompileRun(
11536 "function f() {" 11637 "function f() {"
11537 " for (var i = 1; i <= 30; i++) {" 11638 " for (var i = 1; i <= 30; i++) {"
11538 " nativeobject.callback();" 11639 " nativeobject.callback();"
11539 " }" 11640 " }"
11540 "}" 11641 "}"
11541 "f();"); 11642 "f();");
11542 } 11643 }
11543 11644
11544 11645
11545 void ThrowingDirectApiCallback( 11646 void ThrowingDirectApiCallback(
11546 const v8::FunctionCallbackInfo<v8::Value>& args) { 11647 const v8::FunctionCallbackInfo<v8::Value>& args) {
11547 args.GetIsolate()->ThrowException(v8_str("g")); 11648 args.GetIsolate()->ThrowException(v8_str("g"));
11548 } 11649 }
11549 11650
11550 11651
11551 THREADED_TEST(CallICFastApi_DirectCall_Throw) { 11652 THREADED_TEST(CallICFastApi_DirectCall_Throw) {
11552 LocalContext context; 11653 LocalContext context;
11553 v8::HandleScope scope(context->GetIsolate()); 11654 v8::HandleScope scope(context->GetIsolate());
11554 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); 11655 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New();
11555 nativeobject_templ->Set("callback", 11656 nativeobject_templ->Set(context->GetIsolate(), "callback",
11556 v8::FunctionTemplate::New(ThrowingDirectApiCallback)); 11657 v8::FunctionTemplate::New(ThrowingDirectApiCallback));
11557 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); 11658 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance();
11558 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); 11659 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj);
11559 // call the api function multiple times to ensure direct call stub creation. 11660 // call the api function multiple times to ensure direct call stub creation.
11560 v8::Handle<Value> result = CompileRun( 11661 v8::Handle<Value> result = CompileRun(
11561 "var result = '';" 11662 "var result = '';"
11562 "function f() {" 11663 "function f() {"
11563 " for (var i = 1; i <= 5; i++) {" 11664 " for (var i = 1; i <= 5; i++) {"
11564 " try { nativeobject.callback(); } catch (e) { result += e; }" 11665 " try { nativeobject.callback(); } catch (e) { result += e; }"
11565 " }" 11666 " }"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
11657 "}"); 11758 "}");
11658 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 11759 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
11659 CHECK_EQ(100, interceptor_call_count); 11760 CHECK_EQ(100, interceptor_call_count);
11660 } 11761 }
11661 11762
11662 11763
11663 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature) { 11764 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature) {
11664 int interceptor_call_count = 0; 11765 int interceptor_call_count = 0;
11665 v8::HandleScope scope(CcTest::isolate()); 11766 v8::HandleScope scope(CcTest::isolate());
11666 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11767 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11667 v8::Handle<v8::FunctionTemplate> method_templ = 11768 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
11668 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 11769 FastApiCallback_SimpleSignature, v8_str("method_data"),
11669 v8_str("method_data"), 11770 v8::Signature::New(CcTest::isolate(), fun_templ));
11670 v8::Signature::New(fun_templ));
11671 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11771 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11672 proto_templ->Set(v8_str("method"), method_templ); 11772 proto_templ->Set(v8_str("method"), method_templ);
11673 fun_templ->SetHiddenPrototype(true); 11773 fun_templ->SetHiddenPrototype(true);
11674 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 11774 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
11675 templ->SetNamedPropertyHandler( 11775 templ->SetNamedPropertyHandler(
11676 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, 11776 InterceptorCallICFastApi, NULL, NULL, NULL, NULL,
11677 v8::External::New(CcTest::isolate(), &interceptor_call_count)); 11777 v8::External::New(CcTest::isolate(), &interceptor_call_count));
11678 LocalContext context; 11778 LocalContext context;
11679 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 11779 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
11680 GenerateSomeGarbage(); 11780 GenerateSomeGarbage();
11681 context->Global()->Set(v8_str("o"), fun->NewInstance()); 11781 context->Global()->Set(v8_str("o"), fun->NewInstance());
11682 CompileRun( 11782 CompileRun(
11683 "o.foo = 17;" 11783 "o.foo = 17;"
11684 "var receiver = {};" 11784 "var receiver = {};"
11685 "receiver.__proto__ = o;" 11785 "receiver.__proto__ = o;"
11686 "var result = 0;" 11786 "var result = 0;"
11687 "for (var i = 0; i < 100; i++) {" 11787 "for (var i = 0; i < 100; i++) {"
11688 " result = receiver.method(41);" 11788 " result = receiver.method(41);"
11689 "}"); 11789 "}");
11690 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 11790 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
11691 CHECK_EQ(100, interceptor_call_count); 11791 CHECK_EQ(100, interceptor_call_count);
11692 } 11792 }
11693 11793
11694 11794
11695 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) { 11795 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) {
11696 int interceptor_call_count = 0; 11796 int interceptor_call_count = 0;
11697 v8::HandleScope scope(CcTest::isolate()); 11797 v8::HandleScope scope(CcTest::isolate());
11698 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11798 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11699 v8::Handle<v8::FunctionTemplate> method_templ = 11799 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
11700 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 11800 FastApiCallback_SimpleSignature, v8_str("method_data"),
11701 v8_str("method_data"), 11801 v8::Signature::New(CcTest::isolate(), fun_templ));
11702 v8::Signature::New(fun_templ));
11703 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11802 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11704 proto_templ->Set(v8_str("method"), method_templ); 11803 proto_templ->Set(v8_str("method"), method_templ);
11705 fun_templ->SetHiddenPrototype(true); 11804 fun_templ->SetHiddenPrototype(true);
11706 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 11805 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
11707 templ->SetNamedPropertyHandler( 11806 templ->SetNamedPropertyHandler(
11708 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, 11807 InterceptorCallICFastApi, NULL, NULL, NULL, NULL,
11709 v8::External::New(CcTest::isolate(), &interceptor_call_count)); 11808 v8::External::New(CcTest::isolate(), &interceptor_call_count));
11710 LocalContext context; 11809 LocalContext context;
11711 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 11810 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
11712 GenerateSomeGarbage(); 11811 GenerateSomeGarbage();
(...skipping 14 matching lines...) Expand all
11727 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 11826 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
11728 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 11827 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11729 CHECK_GE(interceptor_call_count, 50); 11828 CHECK_GE(interceptor_call_count, 50);
11730 } 11829 }
11731 11830
11732 11831
11733 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) { 11832 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) {
11734 int interceptor_call_count = 0; 11833 int interceptor_call_count = 0;
11735 v8::HandleScope scope(CcTest::isolate()); 11834 v8::HandleScope scope(CcTest::isolate());
11736 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11835 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11737 v8::Handle<v8::FunctionTemplate> method_templ = 11836 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
11738 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 11837 FastApiCallback_SimpleSignature, v8_str("method_data"),
11739 v8_str("method_data"), 11838 v8::Signature::New(CcTest::isolate(), fun_templ));
11740 v8::Signature::New(fun_templ));
11741 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11839 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11742 proto_templ->Set(v8_str("method"), method_templ); 11840 proto_templ->Set(v8_str("method"), method_templ);
11743 fun_templ->SetHiddenPrototype(true); 11841 fun_templ->SetHiddenPrototype(true);
11744 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 11842 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
11745 templ->SetNamedPropertyHandler( 11843 templ->SetNamedPropertyHandler(
11746 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, 11844 InterceptorCallICFastApi, NULL, NULL, NULL, NULL,
11747 v8::External::New(CcTest::isolate(), &interceptor_call_count)); 11845 v8::External::New(CcTest::isolate(), &interceptor_call_count));
11748 LocalContext context; 11846 LocalContext context;
11749 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 11847 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
11750 GenerateSomeGarbage(); 11848 GenerateSomeGarbage();
(...skipping 14 matching lines...) Expand all
11765 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 11863 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
11766 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 11864 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11767 CHECK_GE(interceptor_call_count, 50); 11865 CHECK_GE(interceptor_call_count, 50);
11768 } 11866 }
11769 11867
11770 11868
11771 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) { 11869 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) {
11772 int interceptor_call_count = 0; 11870 int interceptor_call_count = 0;
11773 v8::HandleScope scope(CcTest::isolate()); 11871 v8::HandleScope scope(CcTest::isolate());
11774 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11872 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11775 v8::Handle<v8::FunctionTemplate> method_templ = 11873 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
11776 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 11874 FastApiCallback_SimpleSignature, v8_str("method_data"),
11777 v8_str("method_data"), 11875 v8::Signature::New(CcTest::isolate(), fun_templ));
11778 v8::Signature::New(fun_templ));
11779 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11876 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11780 proto_templ->Set(v8_str("method"), method_templ); 11877 proto_templ->Set(v8_str("method"), method_templ);
11781 fun_templ->SetHiddenPrototype(true); 11878 fun_templ->SetHiddenPrototype(true);
11782 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 11879 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
11783 templ->SetNamedPropertyHandler( 11880 templ->SetNamedPropertyHandler(
11784 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, 11881 InterceptorCallICFastApi, NULL, NULL, NULL, NULL,
11785 v8::External::New(CcTest::isolate(), &interceptor_call_count)); 11882 v8::External::New(CcTest::isolate(), &interceptor_call_count));
11786 LocalContext context; 11883 LocalContext context;
11787 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 11884 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
11788 GenerateSomeGarbage(); 11885 GenerateSomeGarbage();
(...skipping 17 matching lines...) Expand all
11806 try_catch.Exception()->ToString()); 11903 try_catch.Exception()->ToString());
11807 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 11904 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11808 CHECK_GE(interceptor_call_count, 50); 11905 CHECK_GE(interceptor_call_count, 50);
11809 } 11906 }
11810 11907
11811 11908
11812 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) { 11909 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) {
11813 int interceptor_call_count = 0; 11910 int interceptor_call_count = 0;
11814 v8::HandleScope scope(CcTest::isolate()); 11911 v8::HandleScope scope(CcTest::isolate());
11815 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11912 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11816 v8::Handle<v8::FunctionTemplate> method_templ = 11913 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
11817 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 11914 FastApiCallback_SimpleSignature, v8_str("method_data"),
11818 v8_str("method_data"), 11915 v8::Signature::New(CcTest::isolate(), fun_templ));
11819 v8::Signature::New(fun_templ));
11820 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11916 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11821 proto_templ->Set(v8_str("method"), method_templ); 11917 proto_templ->Set(v8_str("method"), method_templ);
11822 fun_templ->SetHiddenPrototype(true); 11918 fun_templ->SetHiddenPrototype(true);
11823 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 11919 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
11824 templ->SetNamedPropertyHandler( 11920 templ->SetNamedPropertyHandler(
11825 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, 11921 InterceptorCallICFastApi, NULL, NULL, NULL, NULL,
11826 v8::External::New(CcTest::isolate(), &interceptor_call_count)); 11922 v8::External::New(CcTest::isolate(), &interceptor_call_count));
11827 LocalContext context; 11923 LocalContext context;
11828 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 11924 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
11829 GenerateSomeGarbage(); 11925 GenerateSomeGarbage();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
11871 " result = o.method(41);" 11967 " result = o.method(41);"
11872 "}"); 11968 "}");
11873 11969
11874 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 11970 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
11875 } 11971 }
11876 11972
11877 11973
11878 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature) { 11974 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature) {
11879 v8::HandleScope scope(CcTest::isolate()); 11975 v8::HandleScope scope(CcTest::isolate());
11880 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11976 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11881 v8::Handle<v8::FunctionTemplate> method_templ = 11977 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
11882 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 11978 FastApiCallback_SimpleSignature, v8_str("method_data"),
11883 v8_str("method_data"), 11979 v8::Signature::New(CcTest::isolate(), fun_templ));
11884 v8::Signature::New(fun_templ));
11885 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11980 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11886 proto_templ->Set(v8_str("method"), method_templ); 11981 proto_templ->Set(v8_str("method"), method_templ);
11887 fun_templ->SetHiddenPrototype(true); 11982 fun_templ->SetHiddenPrototype(true);
11888 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 11983 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
11889 CHECK(!templ.IsEmpty()); 11984 CHECK(!templ.IsEmpty());
11890 LocalContext context; 11985 LocalContext context;
11891 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 11986 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
11892 GenerateSomeGarbage(); 11987 GenerateSomeGarbage();
11893 context->Global()->Set(v8_str("o"), fun->NewInstance()); 11988 context->Global()->Set(v8_str("o"), fun->NewInstance());
11894 CompileRun( 11989 CompileRun(
11895 "o.foo = 17;" 11990 "o.foo = 17;"
11896 "var receiver = {};" 11991 "var receiver = {};"
11897 "receiver.__proto__ = o;" 11992 "receiver.__proto__ = o;"
11898 "var result = 0;" 11993 "var result = 0;"
11899 "for (var i = 0; i < 100; i++) {" 11994 "for (var i = 0; i < 100; i++) {"
11900 " result = receiver.method(41);" 11995 " result = receiver.method(41);"
11901 "}"); 11996 "}");
11902 11997
11903 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 11998 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
11904 } 11999 }
11905 12000
11906 12001
11907 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss1) { 12002 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss1) {
11908 v8::HandleScope scope(CcTest::isolate()); 12003 v8::HandleScope scope(CcTest::isolate());
11909 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 12004 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11910 v8::Handle<v8::FunctionTemplate> method_templ = 12005 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
11911 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 12006 FastApiCallback_SimpleSignature, v8_str("method_data"),
11912 v8_str("method_data"), 12007 v8::Signature::New(CcTest::isolate(), fun_templ));
11913 v8::Signature::New(fun_templ));
11914 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 12008 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11915 proto_templ->Set(v8_str("method"), method_templ); 12009 proto_templ->Set(v8_str("method"), method_templ);
11916 fun_templ->SetHiddenPrototype(true); 12010 fun_templ->SetHiddenPrototype(true);
11917 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 12011 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
11918 CHECK(!templ.IsEmpty()); 12012 CHECK(!templ.IsEmpty());
11919 LocalContext context; 12013 LocalContext context;
11920 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 12014 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
11921 GenerateSomeGarbage(); 12015 GenerateSomeGarbage();
11922 context->Global()->Set(v8_str("o"), fun->NewInstance()); 12016 context->Global()->Set(v8_str("o"), fun->NewInstance());
11923 CompileRun( 12017 CompileRun(
(...skipping 10 matching lines...) Expand all
11934 " }" 12028 " }"
11935 "}"); 12029 "}");
11936 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 12030 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
11937 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 12031 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11938 } 12032 }
11939 12033
11940 12034
11941 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss2) { 12035 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss2) {
11942 v8::HandleScope scope(CcTest::isolate()); 12036 v8::HandleScope scope(CcTest::isolate());
11943 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 12037 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11944 v8::Handle<v8::FunctionTemplate> method_templ = 12038 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
11945 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 12039 FastApiCallback_SimpleSignature, v8_str("method_data"),
11946 v8_str("method_data"), 12040 v8::Signature::New(CcTest::isolate(), fun_templ));
11947 v8::Signature::New(fun_templ));
11948 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 12041 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11949 proto_templ->Set(v8_str("method"), method_templ); 12042 proto_templ->Set(v8_str("method"), method_templ);
11950 fun_templ->SetHiddenPrototype(true); 12043 fun_templ->SetHiddenPrototype(true);
11951 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 12044 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
11952 CHECK(!templ.IsEmpty()); 12045 CHECK(!templ.IsEmpty());
11953 LocalContext context; 12046 LocalContext context;
11954 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 12047 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
11955 GenerateSomeGarbage(); 12048 GenerateSomeGarbage();
11956 context->Global()->Set(v8_str("o"), fun->NewInstance()); 12049 context->Global()->Set(v8_str("o"), fun->NewInstance());
11957 v8::TryCatch try_catch; 12050 v8::TryCatch try_catch;
(...skipping 13 matching lines...) Expand all
11971 CHECK(try_catch.HasCaught()); 12064 CHECK(try_catch.HasCaught());
11972 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), 12065 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"),
11973 try_catch.Exception()->ToString()); 12066 try_catch.Exception()->ToString());
11974 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 12067 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11975 } 12068 }
11976 12069
11977 12070
11978 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_TypeError) { 12071 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_TypeError) {
11979 v8::HandleScope scope(CcTest::isolate()); 12072 v8::HandleScope scope(CcTest::isolate());
11980 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 12073 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11981 v8::Handle<v8::FunctionTemplate> method_templ = 12074 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
11982 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 12075 FastApiCallback_SimpleSignature, v8_str("method_data"),
11983 v8_str("method_data"), 12076 v8::Signature::New(CcTest::isolate(), fun_templ));
11984 v8::Signature::New(fun_templ));
11985 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 12077 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11986 proto_templ->Set(v8_str("method"), method_templ); 12078 proto_templ->Set(v8_str("method"), method_templ);
11987 fun_templ->SetHiddenPrototype(true); 12079 fun_templ->SetHiddenPrototype(true);
11988 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 12080 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
11989 CHECK(!templ.IsEmpty()); 12081 CHECK(!templ.IsEmpty());
11990 LocalContext context; 12082 LocalContext context;
11991 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 12083 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
11992 GenerateSomeGarbage(); 12084 GenerateSomeGarbage();
11993 context->Global()->Set(v8_str("o"), fun->NewInstance()); 12085 context->Global()->Set(v8_str("o"), fun->NewInstance());
11994 v8::TryCatch try_catch; 12086 v8::TryCatch try_catch;
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
12293 } 12385 }
12294 12386
12295 12387
12296 // Test that we ignore null interceptors. 12388 // Test that we ignore null interceptors.
12297 THREADED_TEST(NullNamedInterceptor) { 12389 THREADED_TEST(NullNamedInterceptor) {
12298 v8::HandleScope scope(CcTest::isolate()); 12390 v8::HandleScope scope(CcTest::isolate());
12299 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 12391 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
12300 templ->SetNamedPropertyHandler( 12392 templ->SetNamedPropertyHandler(
12301 static_cast<v8::NamedPropertyGetterCallback>(0)); 12393 static_cast<v8::NamedPropertyGetterCallback>(0));
12302 LocalContext context; 12394 LocalContext context;
12303 templ->Set("x", v8_num(42)); 12395 templ->Set(CcTest::isolate(), "x", v8_num(42));
12304 v8::Handle<v8::Object> obj = templ->NewInstance(); 12396 v8::Handle<v8::Object> obj = templ->NewInstance();
12305 context->Global()->Set(v8_str("obj"), obj); 12397 context->Global()->Set(v8_str("obj"), obj);
12306 v8::Handle<Value> value = CompileRun("obj.x"); 12398 v8::Handle<Value> value = CompileRun("obj.x");
12307 CHECK(value->IsInt32()); 12399 CHECK(value->IsInt32());
12308 CHECK_EQ(42, value->Int32Value()); 12400 CHECK_EQ(42, value->Int32Value());
12309 } 12401 }
12310 12402
12311 12403
12312 // Test that we ignore null interceptors. 12404 // Test that we ignore null interceptors.
12313 THREADED_TEST(NullIndexedInterceptor) { 12405 THREADED_TEST(NullIndexedInterceptor) {
12314 v8::HandleScope scope(CcTest::isolate()); 12406 v8::HandleScope scope(CcTest::isolate());
12315 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 12407 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
12316 templ->SetIndexedPropertyHandler( 12408 templ->SetIndexedPropertyHandler(
12317 static_cast<v8::IndexedPropertyGetterCallback>(0)); 12409 static_cast<v8::IndexedPropertyGetterCallback>(0));
12318 LocalContext context; 12410 LocalContext context;
12319 templ->Set("42", v8_num(42)); 12411 templ->Set(CcTest::isolate(), "42", v8_num(42));
12320 v8::Handle<v8::Object> obj = templ->NewInstance(); 12412 v8::Handle<v8::Object> obj = templ->NewInstance();
12321 context->Global()->Set(v8_str("obj"), obj); 12413 context->Global()->Set(v8_str("obj"), obj);
12322 v8::Handle<Value> value = CompileRun("obj[42]"); 12414 v8::Handle<Value> value = CompileRun("obj[42]");
12323 CHECK(value->IsInt32()); 12415 CHECK(value->IsInt32());
12324 CHECK_EQ(42, value->Int32Value()); 12416 CHECK_EQ(42, value->Int32Value());
12325 } 12417 }
12326 12418
12327 12419
12328 THREADED_TEST(NamedPropertyHandlerGetterAttributes) { 12420 THREADED_TEST(NamedPropertyHandlerGetterAttributes) {
12329 v8::HandleScope scope(CcTest::isolate()); 12421 v8::HandleScope scope(CcTest::isolate());
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
13032 reinterpret_cast<i::Isolate*>(isolate)->heap()-> 13124 reinterpret_cast<i::Isolate*>(isolate)->heap()->
13033 CollectAllGarbage(i::Heap::kNoGCFlags); 13125 CollectAllGarbage(i::Heap::kNoGCFlags);
13034 // Verify disposed. 13126 // Verify disposed.
13035 CHECK_EQ(initial_handles, globals->global_handles_count()); 13127 CHECK_EQ(initial_handles, globals->global_handles_count());
13036 } 13128 }
13037 13129
13038 13130
13039 v8::Persistent<v8::Object> some_object; 13131 v8::Persistent<v8::Object> some_object;
13040 v8::Persistent<v8::Object> bad_handle; 13132 v8::Persistent<v8::Object> bad_handle;
13041 13133
13042 void NewPersistentHandleCallback(v8::Isolate* isolate, 13134 void NewPersistentHandleCallback(
13043 v8::Persistent<v8::Value>* handle, 13135 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) {
13044 void*) { 13136 v8::HandleScope scope(data.GetIsolate());
13045 v8::HandleScope scope(isolate); 13137 bad_handle.Reset(data.GetIsolate(), some_object);
13046 bad_handle.Reset(isolate, some_object); 13138 data.GetParameter()->Reset();
13047 handle->Reset();
13048 } 13139 }
13049 13140
13050 13141
13051 THREADED_TEST(NewPersistentHandleFromWeakCallback) { 13142 THREADED_TEST(NewPersistentHandleFromWeakCallback) {
13052 LocalContext context; 13143 LocalContext context;
13053 v8::Isolate* isolate = context->GetIsolate(); 13144 v8::Isolate* isolate = context->GetIsolate();
13054 13145
13055 v8::Persistent<v8::Object> handle1, handle2; 13146 v8::Persistent<v8::Object> handle1, handle2;
13056 { 13147 {
13057 v8::HandleScope scope(isolate); 13148 v8::HandleScope scope(isolate);
13058 some_object.Reset(isolate, v8::Object::New()); 13149 some_object.Reset(isolate, v8::Object::New());
13059 handle1.Reset(isolate, v8::Object::New()); 13150 handle1.Reset(isolate, v8::Object::New());
13060 handle2.Reset(isolate, v8::Object::New()); 13151 handle2.Reset(isolate, v8::Object::New());
13061 } 13152 }
13062 // Note: order is implementation dependent alas: currently 13153 // Note: order is implementation dependent alas: currently
13063 // global handle nodes are processed by PostGarbageCollectionProcessing 13154 // global handle nodes are processed by PostGarbageCollectionProcessing
13064 // in reverse allocation order, so if second allocated handle is deleted, 13155 // in reverse allocation order, so if second allocated handle is deleted,
13065 // weak callback of the first handle would be able to 'reallocate' it. 13156 // weak callback of the first handle would be able to 'reallocate' it.
13066 handle1.MakeWeak<v8::Value, void>(NULL, NewPersistentHandleCallback); 13157 handle1.SetWeak(&handle1, NewPersistentHandleCallback);
13067 handle2.Reset(); 13158 handle2.Reset();
13068 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 13159 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
13069 } 13160 }
13070 13161
13071 13162
13072 v8::Persistent<v8::Object> to_be_disposed; 13163 v8::Persistent<v8::Object> to_be_disposed;
13073 13164
13074 void DisposeAndForceGcCallback(v8::Isolate* isolate, 13165 void DisposeAndForceGcCallback(
13075 v8::Persistent<v8::Value>* handle, 13166 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) {
13076 void*) {
13077 to_be_disposed.Reset(); 13167 to_be_disposed.Reset();
13078 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 13168 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
13079 handle->Reset(); 13169 data.GetParameter()->Reset();
13080 } 13170 }
13081 13171
13082 13172
13083 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) { 13173 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) {
13084 LocalContext context; 13174 LocalContext context;
13085 v8::Isolate* isolate = context->GetIsolate(); 13175 v8::Isolate* isolate = context->GetIsolate();
13086 13176
13087 v8::Persistent<v8::Object> handle1, handle2; 13177 v8::Persistent<v8::Object> handle1, handle2;
13088 { 13178 {
13089 v8::HandleScope scope(isolate); 13179 v8::HandleScope scope(isolate);
13090 handle1.Reset(isolate, v8::Object::New()); 13180 handle1.Reset(isolate, v8::Object::New());
13091 handle2.Reset(isolate, v8::Object::New()); 13181 handle2.Reset(isolate, v8::Object::New());
13092 } 13182 }
13093 handle1.MakeWeak<v8::Value, void>(NULL, DisposeAndForceGcCallback); 13183 handle1.SetWeak(&handle1, DisposeAndForceGcCallback);
13094 to_be_disposed.Reset(isolate, handle2); 13184 to_be_disposed.Reset(isolate, handle2);
13095 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 13185 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
13096 } 13186 }
13097 13187
13098 void DisposingCallback(v8::Isolate* isolate, 13188 void DisposingCallback(
13099 v8::Persistent<v8::Value>* handle, 13189 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) {
13100 void*) { 13190 data.GetParameter()->Reset();
13101 handle->Reset();
13102 } 13191 }
13103 13192
13104 void HandleCreatingCallback(v8::Isolate* isolate, 13193 void HandleCreatingCallback(
13105 v8::Persistent<v8::Value>* handle, 13194 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) {
13106 void*) { 13195 v8::HandleScope scope(data.GetIsolate());
13107 v8::HandleScope scope(isolate); 13196 v8::Persistent<v8::Object>(data.GetIsolate(), v8::Object::New());
13108 v8::Persistent<v8::Object>(isolate, v8::Object::New()); 13197 data.GetParameter()->Reset();
13109 handle->Reset();
13110 } 13198 }
13111 13199
13112 13200
13113 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) { 13201 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) {
13114 LocalContext context; 13202 LocalContext context;
13115 v8::Isolate* isolate = context->GetIsolate(); 13203 v8::Isolate* isolate = context->GetIsolate();
13116 13204
13117 v8::Persistent<v8::Object> handle1, handle2, handle3; 13205 v8::Persistent<v8::Object> handle1, handle2, handle3;
13118 { 13206 {
13119 v8::HandleScope scope(isolate); 13207 v8::HandleScope scope(isolate);
13120 handle3.Reset(isolate, v8::Object::New()); 13208 handle3.Reset(isolate, v8::Object::New());
13121 handle2.Reset(isolate, v8::Object::New()); 13209 handle2.Reset(isolate, v8::Object::New());
13122 handle1.Reset(isolate, v8::Object::New()); 13210 handle1.Reset(isolate, v8::Object::New());
13123 } 13211 }
13124 handle2.MakeWeak<v8::Value, void>(NULL, DisposingCallback); 13212 handle2.SetWeak(&handle2, DisposingCallback);
13125 handle3.MakeWeak<v8::Value, void>(NULL, HandleCreatingCallback); 13213 handle3.SetWeak(&handle3, HandleCreatingCallback);
13126 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 13214 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
13127 } 13215 }
13128 13216
13129 13217
13130 THREADED_TEST(CheckForCrossContextObjectLiterals) { 13218 THREADED_TEST(CheckForCrossContextObjectLiterals) {
13131 v8::V8::Initialize(); 13219 v8::V8::Initialize();
13132 13220
13133 const int nof = 2; 13221 const int nof = 2;
13134 const char* sources[nof] = { 13222 const char* sources[nof] = {
13135 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }", 13223 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }",
13136 "Object()" 13224 "Object()"
13137 }; 13225 };
13138 13226
13139 for (int i = 0; i < nof; i++) { 13227 for (int i = 0; i < nof; i++) {
13140 const char* source = sources[i]; 13228 const char* source = sources[i];
13141 { v8::HandleScope scope(CcTest::isolate()); 13229 { v8::HandleScope scope(CcTest::isolate());
13142 LocalContext context; 13230 LocalContext context;
13143 CompileRun(source); 13231 CompileRun(source);
13144 } 13232 }
13145 { v8::HandleScope scope(CcTest::isolate()); 13233 { v8::HandleScope scope(CcTest::isolate());
13146 LocalContext context; 13234 LocalContext context;
13147 CompileRun(source); 13235 CompileRun(source);
13148 } 13236 }
13149 } 13237 }
13150 } 13238 }
13151 13239
13152 13240
13153 static v8::Handle<Value> NestedScope(v8::Local<Context> env) { 13241 static v8::Handle<Value> NestedScope(v8::Local<Context> env) {
13154 v8::HandleScope inner(env->GetIsolate()); 13242 v8::EscapableHandleScope inner(env->GetIsolate());
13155 env->Enter(); 13243 env->Enter();
13156 v8::Handle<Value> three = v8_num(3); 13244 v8::Local<Value> three = v8_num(3);
13157 v8::Handle<Value> value = inner.Close(three); 13245 v8::Local<Value> value = inner.Escape(three);
13158 env->Exit(); 13246 env->Exit();
13159 return value; 13247 return value;
13160 } 13248 }
13161 13249
13162 13250
13163 THREADED_TEST(NestedHandleScopeAndContexts) { 13251 THREADED_TEST(NestedHandleScopeAndContexts) {
13164 v8::Isolate* isolate = CcTest::isolate(); 13252 v8::Isolate* isolate = CcTest::isolate();
13165 v8::HandleScope outer(isolate); 13253 v8::HandleScope outer(isolate);
13166 v8::Local<Context> env = Context::New(isolate); 13254 v8::Local<Context> env = Context::New(isolate);
13167 env->Enter(); 13255 env->Enter();
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
13773 13861
13774 // Regression test for issue 54, object templates with internal fields 13862 // Regression test for issue 54, object templates with internal fields
13775 // but no accessors or interceptors did not get their internal field 13863 // but no accessors or interceptors did not get their internal field
13776 // count set on instances. 13864 // count set on instances.
13777 THREADED_TEST(Regress54) { 13865 THREADED_TEST(Regress54) {
13778 LocalContext context; 13866 LocalContext context;
13779 v8::Isolate* isolate = context->GetIsolate(); 13867 v8::Isolate* isolate = context->GetIsolate();
13780 v8::HandleScope outer(isolate); 13868 v8::HandleScope outer(isolate);
13781 static v8::Persistent<v8::ObjectTemplate> templ; 13869 static v8::Persistent<v8::ObjectTemplate> templ;
13782 if (templ.IsEmpty()) { 13870 if (templ.IsEmpty()) {
13783 v8::HandleScope inner(isolate); 13871 v8::EscapableHandleScope inner(isolate);
13784 v8::Handle<v8::ObjectTemplate> local = v8::ObjectTemplate::New(); 13872 v8::Local<v8::ObjectTemplate> local = v8::ObjectTemplate::New();
13785 local->SetInternalFieldCount(1); 13873 local->SetInternalFieldCount(1);
13786 templ.Reset(isolate, inner.Close(local)); 13874 templ.Reset(isolate, inner.Escape(local));
13787 } 13875 }
13788 v8::Handle<v8::Object> result = 13876 v8::Handle<v8::Object> result =
13789 v8::Local<v8::ObjectTemplate>::New(isolate, templ)->NewInstance(); 13877 v8::Local<v8::ObjectTemplate>::New(isolate, templ)->NewInstance();
13790 CHECK_EQ(1, result->InternalFieldCount()); 13878 CHECK_EQ(1, result->InternalFieldCount());
13791 } 13879 }
13792 13880
13793 13881
13794 // If part of the threaded tests, this test makes ThreadingTest fail 13882 // If part of the threaded tests, this test makes ThreadingTest fail
13795 // on mac. 13883 // on mac.
13796 TEST(CatchStackOverflow) { 13884 TEST(CatchStackOverflow) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
13907 v8::Handle<v8::Value> value = CompileRun("obj.asdf.name"); 13995 v8::Handle<v8::Value> value = CompileRun("obj.asdf.name");
13908 CHECK(value->IsString()); 13996 CHECK(value->IsString());
13909 v8::String::Utf8Value name(value); 13997 v8::String::Utf8Value name(value);
13910 CHECK_EQ("asdf", *name); 13998 CHECK_EQ("asdf", *name);
13911 } 13999 }
13912 14000
13913 14001
13914 THREADED_TEST(DateAccess) { 14002 THREADED_TEST(DateAccess) {
13915 LocalContext context; 14003 LocalContext context;
13916 v8::HandleScope scope(context->GetIsolate()); 14004 v8::HandleScope scope(context->GetIsolate());
13917 v8::Handle<v8::Value> date = v8::Date::New(1224744689038.0); 14005 v8::Handle<v8::Value> date =
14006 v8::Date::New(context->GetIsolate(), 1224744689038.0);
13918 CHECK(date->IsDate()); 14007 CHECK(date->IsDate());
13919 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->ValueOf()); 14008 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->ValueOf());
13920 } 14009 }
13921 14010
13922 14011
13923 void CheckProperties(v8::Handle<v8::Value> val, int elmc, const char* elmv[]) { 14012 void CheckProperties(v8::Handle<v8::Value> val, int elmc, const char* elmv[]) {
13924 v8::Handle<v8::Object> obj = val.As<v8::Object>(); 14013 v8::Handle<v8::Object> obj = val.As<v8::Object>();
13925 v8::Handle<v8::Array> props = obj->GetPropertyNames(); 14014 v8::Handle<v8::Array> props = obj->GetPropertyNames();
13926 CHECK_EQ(elmc, props->Length()); 14015 CHECK_EQ(elmc, props->Length());
13927 for (int i = 0; i < elmc; i++) { 14016 for (int i = 0; i < elmc; i++) {
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
14414 v8::Isolate* isolate = CcTest::isolate(); 14503 v8::Isolate* isolate = CcTest::isolate();
14415 v8::HandleScope scope(isolate); 14504 v8::HandleScope scope(isolate);
14416 14505
14417 const char* cstring = "function foo(a) { return a+1; }"; 14506 const char* cstring = "function foo(a) { return a+1; }";
14418 14507
14419 v8::ScriptData* sd_from_cstring = 14508 v8::ScriptData* sd_from_cstring =
14420 v8::ScriptData::PreCompile(isolate, cstring, i::StrLength(cstring)); 14509 v8::ScriptData::PreCompile(isolate, cstring, i::StrLength(cstring));
14421 14510
14422 TestAsciiResource* resource = new TestAsciiResource(cstring); 14511 TestAsciiResource* resource = new TestAsciiResource(cstring);
14423 v8::ScriptData* sd_from_external_string = v8::ScriptData::PreCompile( 14512 v8::ScriptData* sd_from_external_string = v8::ScriptData::PreCompile(
14424 v8::String::NewExternal(resource)); 14513 v8::String::NewExternal(isolate, resource));
14425 14514
14426 v8::ScriptData* sd_from_string = v8::ScriptData::PreCompile( 14515 v8::ScriptData* sd_from_string = v8::ScriptData::PreCompile(
14427 v8::String::NewFromUtf8(isolate, cstring)); 14516 v8::String::NewFromUtf8(isolate, cstring));
14428 14517
14429 CHECK_EQ(sd_from_cstring->Length(), sd_from_external_string->Length()); 14518 CHECK_EQ(sd_from_cstring->Length(), sd_from_external_string->Length());
14430 CHECK_EQ(0, memcmp(sd_from_cstring->Data(), 14519 CHECK_EQ(0, memcmp(sd_from_cstring->Data(),
14431 sd_from_external_string->Data(), 14520 sd_from_external_string->Data(),
14432 sd_from_cstring->Length())); 14521 sd_from_cstring->Length()));
14433 14522
14434 CHECK_EQ(sd_from_cstring->Length(), sd_from_string->Length()); 14523 CHECK_EQ(sd_from_cstring->Length(), sd_from_string->Length());
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
14662 "--0.5", // This mainly testes PushBack in the Scanner. 14751 "--0.5", // This mainly testes PushBack in the Scanner.
14663 NULL 14752 NULL
14664 }; 14753 };
14665 14754
14666 // Compile the sources as external two byte strings. 14755 // Compile the sources as external two byte strings.
14667 for (int i = 0; ascii_sources[i] != NULL; i++) { 14756 for (int i = 0; ascii_sources[i] != NULL; i++) {
14668 uint16_t* two_byte_string = AsciiToTwoByteString(ascii_sources[i]); 14757 uint16_t* two_byte_string = AsciiToTwoByteString(ascii_sources[i]);
14669 UC16VectorResource uc16_resource( 14758 UC16VectorResource uc16_resource(
14670 i::Vector<const uint16_t>(two_byte_string, 14759 i::Vector<const uint16_t>(two_byte_string,
14671 i::StrLength(ascii_sources[i]))); 14760 i::StrLength(ascii_sources[i])));
14672 v8::Local<v8::String> source = v8::String::NewExternal(&uc16_resource); 14761 v8::Local<v8::String> source =
14762 v8::String::NewExternal(context->GetIsolate(), &uc16_resource);
14673 v8::Script::Compile(source); 14763 v8::Script::Compile(source);
14674 i::DeleteArray(two_byte_string); 14764 i::DeleteArray(two_byte_string);
14675 } 14765 }
14676 } 14766 }
14677 14767
14678 14768
14679 #ifndef V8_INTERPRETED_REGEXP 14769 #ifndef V8_INTERPRETED_REGEXP
14680 14770
14681 struct RegExpInterruptionData { 14771 struct RegExpInterruptionData {
14682 int loop_count; 14772 int loop_count;
(...skipping 1618 matching lines...) Expand 10 before | Expand all | Expand 10 after
16301 void TypedArrayTestHelper(v8::ExternalArrayType array_type, 16391 void TypedArrayTestHelper(v8::ExternalArrayType array_type,
16302 int64_t low, int64_t high) { 16392 int64_t low, int64_t high) {
16303 const int kElementCount = 50; 16393 const int kElementCount = 50;
16304 16394
16305 i::ScopedVector<ElementType> backing_store(kElementCount+2); 16395 i::ScopedVector<ElementType> backing_store(kElementCount+2);
16306 16396
16307 LocalContext env; 16397 LocalContext env;
16308 v8::Isolate* isolate = env->GetIsolate(); 16398 v8::Isolate* isolate = env->GetIsolate();
16309 v8::HandleScope handle_scope(isolate); 16399 v8::HandleScope handle_scope(isolate);
16310 16400
16311 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New( 16401 Local<v8::ArrayBuffer> ab =
16312 backing_store.start(), (kElementCount+2)*sizeof(ElementType)); 16402 v8::ArrayBuffer::New(isolate, backing_store.start(),
16403 (kElementCount + 2) * sizeof(ElementType));
16313 Local<TypedArray> ta = 16404 Local<TypedArray> ta =
16314 TypedArray::New(ab, 2*sizeof(ElementType), kElementCount); 16405 TypedArray::New(ab, 2*sizeof(ElementType), kElementCount);
16315 CheckInternalFieldsAreZero<v8::ArrayBufferView>(ta); 16406 CheckInternalFieldsAreZero<v8::ArrayBufferView>(ta);
16316 CHECK_EQ(kElementCount, static_cast<int>(ta->Length())); 16407 CHECK_EQ(kElementCount, static_cast<int>(ta->Length()));
16317 CHECK_EQ(2*sizeof(ElementType), static_cast<int>(ta->ByteOffset())); 16408 CHECK_EQ(2*sizeof(ElementType), static_cast<int>(ta->ByteOffset()));
16318 CHECK_EQ(kElementCount*sizeof(ElementType), 16409 CHECK_EQ(kElementCount*sizeof(ElementType),
16319 static_cast<int>(ta->ByteLength())); 16410 static_cast<int>(ta->ByteLength()));
16320 CHECK_EQ(ab, ta->Buffer()); 16411 CHECK_EQ(ab, ta->Buffer());
16321 16412
16322 ElementType* data = backing_store.start() + 2; 16413 ElementType* data = backing_store.start() + 2;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
16387 16478
16388 THREADED_TEST(DataView) { 16479 THREADED_TEST(DataView) {
16389 const int kSize = 50; 16480 const int kSize = 50;
16390 16481
16391 i::ScopedVector<uint8_t> backing_store(kSize+2); 16482 i::ScopedVector<uint8_t> backing_store(kSize+2);
16392 16483
16393 LocalContext env; 16484 LocalContext env;
16394 v8::Isolate* isolate = env->GetIsolate(); 16485 v8::Isolate* isolate = env->GetIsolate();
16395 v8::HandleScope handle_scope(isolate); 16486 v8::HandleScope handle_scope(isolate);
16396 16487
16397 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New( 16488 Local<v8::ArrayBuffer> ab =
16398 backing_store.start(), 2 + kSize); 16489 v8::ArrayBuffer::New(isolate, backing_store.start(), 2 + kSize);
16399 Local<v8::DataView> dv = 16490 Local<v8::DataView> dv =
16400 v8::DataView::New(ab, 2, kSize); 16491 v8::DataView::New(ab, 2, kSize);
16401 CheckInternalFieldsAreZero<v8::ArrayBufferView>(dv); 16492 CheckInternalFieldsAreZero<v8::ArrayBufferView>(dv);
16402 CHECK_EQ(2, static_cast<int>(dv->ByteOffset())); 16493 CHECK_EQ(2, static_cast<int>(dv->ByteOffset()));
16403 CHECK_EQ(kSize, static_cast<int>(dv->ByteLength())); 16494 CHECK_EQ(kSize, static_cast<int>(dv->ByteLength()));
16404 CHECK_EQ(ab, dv->Buffer()); 16495 CHECK_EQ(ab, dv->Buffer());
16405 } 16496 }
16406 16497
16407 16498
16408 #define IS_ARRAY_BUFFER_VIEW_TEST(View) \ 16499 #define IS_ARRAY_BUFFER_VIEW_TEST(View) \
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
16495 void AnalyzeStackInNativeCode(const v8::FunctionCallbackInfo<v8::Value>& args) { 16586 void AnalyzeStackInNativeCode(const v8::FunctionCallbackInfo<v8::Value>& args) {
16496 v8::HandleScope scope(args.GetIsolate()); 16587 v8::HandleScope scope(args.GetIsolate());
16497 const char* origin = "capture-stack-trace-test"; 16588 const char* origin = "capture-stack-trace-test";
16498 const int kOverviewTest = 1; 16589 const int kOverviewTest = 1;
16499 const int kDetailedTest = 2; 16590 const int kDetailedTest = 2;
16500 16591
16501 ASSERT(args.Length() == 1); 16592 ASSERT(args.Length() == 1);
16502 16593
16503 int testGroup = args[0]->Int32Value(); 16594 int testGroup = args[0]->Int32Value();
16504 if (testGroup == kOverviewTest) { 16595 if (testGroup == kOverviewTest) {
16505 v8::Handle<v8::StackTrace> stackTrace = 16596 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(
16506 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kOverview); 16597 args.GetIsolate(), 10, v8::StackTrace::kOverview);
16507 CHECK_EQ(4, stackTrace->GetFrameCount()); 16598 CHECK_EQ(4, stackTrace->GetFrameCount());
16508 checkStackFrame(origin, "bar", 2, 10, false, false, 16599 checkStackFrame(origin, "bar", 2, 10, false, false,
16509 stackTrace->GetFrame(0)); 16600 stackTrace->GetFrame(0));
16510 checkStackFrame(origin, "foo", 6, 3, false, false, 16601 checkStackFrame(origin, "foo", 6, 3, false, false,
16511 stackTrace->GetFrame(1)); 16602 stackTrace->GetFrame(1));
16512 // This is the source string inside the eval which has the call to foo. 16603 // This is the source string inside the eval which has the call to foo.
16513 checkStackFrame(NULL, "", 1, 5, false, false, 16604 checkStackFrame(NULL, "", 1, 5, false, false,
16514 stackTrace->GetFrame(2)); 16605 stackTrace->GetFrame(2));
16515 // The last frame is an anonymous function which has the initial eval call. 16606 // The last frame is an anonymous function which has the initial eval call.
16516 checkStackFrame(origin, "", 8, 7, false, false, 16607 checkStackFrame(origin, "", 8, 7, false, false,
16517 stackTrace->GetFrame(3)); 16608 stackTrace->GetFrame(3));
16518 16609
16519 CHECK(stackTrace->AsArray()->IsArray()); 16610 CHECK(stackTrace->AsArray()->IsArray());
16520 } else if (testGroup == kDetailedTest) { 16611 } else if (testGroup == kDetailedTest) {
16521 v8::Handle<v8::StackTrace> stackTrace = 16612 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(
16522 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed); 16613 args.GetIsolate(), 10, v8::StackTrace::kDetailed);
16523 CHECK_EQ(4, stackTrace->GetFrameCount()); 16614 CHECK_EQ(4, stackTrace->GetFrameCount());
16524 checkStackFrame(origin, "bat", 4, 22, false, false, 16615 checkStackFrame(origin, "bat", 4, 22, false, false,
16525 stackTrace->GetFrame(0)); 16616 stackTrace->GetFrame(0));
16526 checkStackFrame(origin, "baz", 8, 3, false, true, 16617 checkStackFrame(origin, "baz", 8, 3, false, true,
16527 stackTrace->GetFrame(1)); 16618 stackTrace->GetFrame(1));
16528 #ifdef ENABLE_DEBUGGER_SUPPORT 16619 #ifdef ENABLE_DEBUGGER_SUPPORT
16529 bool is_eval = true; 16620 bool is_eval = true;
16530 #else // ENABLE_DEBUGGER_SUPPORT 16621 #else // ENABLE_DEBUGGER_SUPPORT
16531 bool is_eval = false; 16622 bool is_eval = false;
16532 #endif // ENABLE_DEBUGGER_SUPPORT 16623 #endif // ENABLE_DEBUGGER_SUPPORT
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
16778 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); 16869 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
16779 CompileRun(source); 16870 CompileRun(source);
16780 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 16871 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
16781 v8::V8::RemoveMessageListeners(RethrowBogusErrorStackTraceHandler); 16872 v8::V8::RemoveMessageListeners(RethrowBogusErrorStackTraceHandler);
16782 } 16873 }
16783 16874
16784 16875
16785 void AnalyzeStackOfEvalWithSourceURL( 16876 void AnalyzeStackOfEvalWithSourceURL(
16786 const v8::FunctionCallbackInfo<v8::Value>& args) { 16877 const v8::FunctionCallbackInfo<v8::Value>& args) {
16787 v8::HandleScope scope(args.GetIsolate()); 16878 v8::HandleScope scope(args.GetIsolate());
16788 v8::Handle<v8::StackTrace> stackTrace = 16879 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(
16789 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed); 16880 args.GetIsolate(), 10, v8::StackTrace::kDetailed);
16790 CHECK_EQ(5, stackTrace->GetFrameCount()); 16881 CHECK_EQ(5, stackTrace->GetFrameCount());
16791 v8::Handle<v8::String> url = v8_str("eval_url"); 16882 v8::Handle<v8::String> url = v8_str("eval_url");
16792 for (int i = 0; i < 3; i++) { 16883 for (int i = 0; i < 3; i++) {
16793 v8::Handle<v8::String> name = 16884 v8::Handle<v8::String> name =
16794 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 16885 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
16795 CHECK(!name.IsEmpty()); 16886 CHECK(!name.IsEmpty());
16796 CHECK_EQ(url, name); 16887 CHECK_EQ(url, name);
16797 } 16888 }
16798 } 16889 }
16799 16890
(...skipping 24 matching lines...) Expand all
16824 i::OS::SNPrintF(code, source, "//@ sourceURL=eval_url"); 16915 i::OS::SNPrintF(code, source, "//@ sourceURL=eval_url");
16825 CHECK(CompileRun(code.start())->IsUndefined()); 16916 CHECK(CompileRun(code.start())->IsUndefined());
16826 } 16917 }
16827 16918
16828 16919
16829 static int scriptIdInStack[2]; 16920 static int scriptIdInStack[2];
16830 16921
16831 void AnalyzeScriptIdInStack( 16922 void AnalyzeScriptIdInStack(
16832 const v8::FunctionCallbackInfo<v8::Value>& args) { 16923 const v8::FunctionCallbackInfo<v8::Value>& args) {
16833 v8::HandleScope scope(args.GetIsolate()); 16924 v8::HandleScope scope(args.GetIsolate());
16834 v8::Handle<v8::StackTrace> stackTrace = 16925 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(
16835 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kScriptId); 16926 args.GetIsolate(), 10, v8::StackTrace::kScriptId);
16836 CHECK_EQ(2, stackTrace->GetFrameCount()); 16927 CHECK_EQ(2, stackTrace->GetFrameCount());
16837 for (int i = 0; i < 2; i++) { 16928 for (int i = 0; i < 2; i++) {
16838 scriptIdInStack[i] = stackTrace->GetFrame(i)->GetScriptId(); 16929 scriptIdInStack[i] = stackTrace->GetFrame(i)->GetScriptId();
16839 } 16930 }
16840 } 16931 }
16841 16932
16842 16933
16843 TEST(ScriptIdInStackTrace) { 16934 TEST(ScriptIdInStackTrace) {
16844 v8::HandleScope scope(CcTest::isolate()); 16935 v8::HandleScope scope(CcTest::isolate());
16845 Local<ObjectTemplate> templ = ObjectTemplate::New(); 16936 Local<ObjectTemplate> templ = ObjectTemplate::New();
(...skipping 14 matching lines...) Expand all
16860 for (int i = 0; i < 2; i++) { 16951 for (int i = 0; i < 2; i++) {
16861 CHECK(scriptIdInStack[i] != v8::Message::kNoScriptIdInfo); 16952 CHECK(scriptIdInStack[i] != v8::Message::kNoScriptIdInfo);
16862 CHECK_EQ(scriptIdInStack[i], script->GetId()); 16953 CHECK_EQ(scriptIdInStack[i], script->GetId());
16863 } 16954 }
16864 } 16955 }
16865 16956
16866 16957
16867 void AnalyzeStackOfInlineScriptWithSourceURL( 16958 void AnalyzeStackOfInlineScriptWithSourceURL(
16868 const v8::FunctionCallbackInfo<v8::Value>& args) { 16959 const v8::FunctionCallbackInfo<v8::Value>& args) {
16869 v8::HandleScope scope(args.GetIsolate()); 16960 v8::HandleScope scope(args.GetIsolate());
16870 v8::Handle<v8::StackTrace> stackTrace = 16961 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(
16871 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed); 16962 args.GetIsolate(), 10, v8::StackTrace::kDetailed);
16872 CHECK_EQ(4, stackTrace->GetFrameCount()); 16963 CHECK_EQ(4, stackTrace->GetFrameCount());
16873 v8::Handle<v8::String> url = v8_str("url"); 16964 v8::Handle<v8::String> url = v8_str("url");
16874 for (int i = 0; i < 3; i++) { 16965 for (int i = 0; i < 3; i++) {
16875 v8::Handle<v8::String> name = 16966 v8::Handle<v8::String> name =
16876 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 16967 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
16877 CHECK(!name.IsEmpty()); 16968 CHECK(!name.IsEmpty());
16878 CHECK_EQ(url, name); 16969 CHECK_EQ(url, name);
16879 } 16970 }
16880 } 16971 }
16881 16972
(...skipping 23 matching lines...) Expand all
16905 i::OS::SNPrintF(code, source, "//# sourceURL=source_url"); 16996 i::OS::SNPrintF(code, source, "//# sourceURL=source_url");
16906 CHECK(CompileRunWithOrigin(code.start(), "url", 0, 1)->IsUndefined()); 16997 CHECK(CompileRunWithOrigin(code.start(), "url", 0, 1)->IsUndefined());
16907 i::OS::SNPrintF(code, source, "//@ sourceURL=source_url"); 16998 i::OS::SNPrintF(code, source, "//@ sourceURL=source_url");
16908 CHECK(CompileRunWithOrigin(code.start(), "url", 0, 1)->IsUndefined()); 16999 CHECK(CompileRunWithOrigin(code.start(), "url", 0, 1)->IsUndefined());
16909 } 17000 }
16910 17001
16911 17002
16912 void AnalyzeStackOfDynamicScriptWithSourceURL( 17003 void AnalyzeStackOfDynamicScriptWithSourceURL(
16913 const v8::FunctionCallbackInfo<v8::Value>& args) { 17004 const v8::FunctionCallbackInfo<v8::Value>& args) {
16914 v8::HandleScope scope(args.GetIsolate()); 17005 v8::HandleScope scope(args.GetIsolate());
16915 v8::Handle<v8::StackTrace> stackTrace = 17006 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(
16916 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed); 17007 args.GetIsolate(), 10, v8::StackTrace::kDetailed);
16917 CHECK_EQ(4, stackTrace->GetFrameCount()); 17008 CHECK_EQ(4, stackTrace->GetFrameCount());
16918 v8::Handle<v8::String> url = v8_str("source_url"); 17009 v8::Handle<v8::String> url = v8_str("source_url");
16919 for (int i = 0; i < 3; i++) { 17010 for (int i = 0; i < 3; i++) {
16920 v8::Handle<v8::String> name = 17011 v8::Handle<v8::String> name =
16921 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 17012 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
16922 CHECK(!name.IsEmpty()); 17013 CHECK(!name.IsEmpty());
16923 CHECK_EQ(url, name); 17014 CHECK_EQ(url, name);
16924 } 17015 }
16925 } 17016 }
16926 17017
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
17190 }; 17281 };
17191 17282
17192 17283
17193 TEST(VisitExternalStrings) { 17284 TEST(VisitExternalStrings) {
17194 LocalContext env; 17285 LocalContext env;
17195 v8::HandleScope scope(env->GetIsolate()); 17286 v8::HandleScope scope(env->GetIsolate());
17196 const char* string = "Some string"; 17287 const char* string = "Some string";
17197 uint16_t* two_byte_string = AsciiToTwoByteString(string); 17288 uint16_t* two_byte_string = AsciiToTwoByteString(string);
17198 TestResource* resource[4]; 17289 TestResource* resource[4];
17199 resource[0] = new TestResource(two_byte_string); 17290 resource[0] = new TestResource(two_byte_string);
17200 v8::Local<v8::String> string0 = v8::String::NewExternal(resource[0]); 17291 v8::Local<v8::String> string0 =
17292 v8::String::NewExternal(env->GetIsolate(), resource[0]);
17201 resource[1] = new TestResource(two_byte_string); 17293 resource[1] = new TestResource(two_byte_string);
17202 v8::Local<v8::String> string1 = v8::String::NewExternal(resource[1]); 17294 v8::Local<v8::String> string1 =
17295 v8::String::NewExternal(env->GetIsolate(), resource[1]);
17203 17296
17204 // Externalized symbol. 17297 // Externalized symbol.
17205 resource[2] = new TestResource(two_byte_string); 17298 resource[2] = new TestResource(two_byte_string);
17206 v8::Local<v8::String> string2 = v8::String::NewFromUtf8( 17299 v8::Local<v8::String> string2 = v8::String::NewFromUtf8(
17207 env->GetIsolate(), string, v8::String::kInternalizedString); 17300 env->GetIsolate(), string, v8::String::kInternalizedString);
17208 CHECK(string2->MakeExternal(resource[2])); 17301 CHECK(string2->MakeExternal(resource[2]));
17209 17302
17210 // Symbolized External. 17303 // Symbolized External.
17211 resource[3] = new TestResource(AsciiToTwoByteString("Some other string")); 17304 resource[3] = new TestResource(AsciiToTwoByteString("Some other string"));
17212 v8::Local<v8::String> string3 = v8::String::NewExternal(resource[3]); 17305 v8::Local<v8::String> string3 =
17306 v8::String::NewExternal(env->GetIsolate(), resource[3]);
17213 CcTest::heap()->CollectAllAvailableGarbage(); // Tenure string. 17307 CcTest::heap()->CollectAllAvailableGarbage(); // Tenure string.
17214 // Turn into a symbol. 17308 // Turn into a symbol.
17215 i::Handle<i::String> string3_i = v8::Utils::OpenHandle(*string3); 17309 i::Handle<i::String> string3_i = v8::Utils::OpenHandle(*string3);
17216 CHECK(!CcTest::heap()->InternalizeString(*string3_i)->IsFailure()); 17310 CHECK(!CcTest::heap()->InternalizeString(*string3_i)->IsFailure());
17217 CHECK(string3_i->IsInternalizedString()); 17311 CHECK(string3_i->IsInternalizedString());
17218 17312
17219 // We need to add usages for string* to avoid warnings in GCC 4.7 17313 // We need to add usages for string* to avoid warnings in GCC 4.7
17220 CHECK(string0->IsExternal()); 17314 CHECK(string0->IsExternal());
17221 CHECK(string1->IsExternal()); 17315 CHECK(string1->IsExternal());
17222 CHECK(string2->IsExternal()); 17316 CHECK(string2->IsExternal());
17223 CHECK(string3->IsExternal()); 17317 CHECK(string3->IsExternal());
17224 17318
17225 VisitorImpl visitor(resource); 17319 VisitorImpl visitor(resource);
17226 v8::V8::VisitExternalResources(&visitor); 17320 v8::V8::VisitExternalResources(&visitor);
17227 visitor.CheckVisitedResources(); 17321 visitor.CheckVisitedResources();
17228 } 17322 }
17229 17323
17230 17324
17231 TEST(ExternalStringCollectedAtTearDown) { 17325 TEST(ExternalStringCollectedAtTearDown) {
17232 int destroyed = 0; 17326 int destroyed = 0;
17233 v8::Isolate* isolate = v8::Isolate::New(); 17327 v8::Isolate* isolate = v8::Isolate::New();
17234 { v8::Isolate::Scope isolate_scope(isolate); 17328 { v8::Isolate::Scope isolate_scope(isolate);
17235 v8::HandleScope handle_scope(isolate); 17329 v8::HandleScope handle_scope(isolate);
17236 const char* s = "One string to test them all, one string to find them."; 17330 const char* s = "One string to test them all, one string to find them.";
17237 TestAsciiResource* inscription = 17331 TestAsciiResource* inscription =
17238 new TestAsciiResource(i::StrDup(s), &destroyed); 17332 new TestAsciiResource(i::StrDup(s), &destroyed);
17239 v8::Local<v8::String> ring = v8::String::NewExternal(inscription); 17333 v8::Local<v8::String> ring = v8::String::NewExternal(isolate, inscription);
17240 // Ring is still alive. Orcs are roaming freely across our lands. 17334 // Ring is still alive. Orcs are roaming freely across our lands.
17241 CHECK_EQ(0, destroyed); 17335 CHECK_EQ(0, destroyed);
17242 USE(ring); 17336 USE(ring);
17243 } 17337 }
17244 17338
17245 isolate->Dispose(); 17339 isolate->Dispose();
17246 // Ring has been destroyed. Free Peoples of Middle-earth Rejoice. 17340 // Ring has been destroyed. Free Peoples of Middle-earth Rejoice.
17247 CHECK_EQ(1, destroyed); 17341 CHECK_EQ(1, destroyed);
17248 } 17342 }
17249 17343
17250 17344
17345 TEST(ExternalInternalizedStringCollectedAtTearDown) {
17346 int destroyed = 0;
17347 v8::Isolate* isolate = v8::Isolate::New();
17348 { v8::Isolate::Scope isolate_scope(isolate);
17349 LocalContext env(isolate);
17350 v8::HandleScope handle_scope(isolate);
17351 CompileRun("var ring = 'One string to test them all';");
17352 const char* s = "One string to test them all";
17353 TestAsciiResource* inscription =
17354 new TestAsciiResource(i::StrDup(s), &destroyed);
17355 v8::Local<v8::String> ring = CompileRun("ring")->ToString();
17356 CHECK(v8::Utils::OpenHandle(*ring)->IsInternalizedString());
17357 ring->MakeExternal(inscription);
17358 // Ring is still alive. Orcs are roaming freely across our lands.
17359 CHECK_EQ(0, destroyed);
17360 USE(ring);
17361 }
17362
17363 isolate->Dispose();
17364 // Ring has been destroyed. Free Peoples of Middle-earth Rejoice.
17365 CHECK_EQ(1, destroyed);
17366 }
17367
17368
17369 TEST(ExternalInternalizedStringCollectedAtGC) {
17370 int destroyed = 0;
17371 { LocalContext env;
17372 v8::HandleScope handle_scope(env->GetIsolate());
17373 CompileRun("var ring = 'One string to test them all';");
17374 const char* s = "One string to test them all";
17375 TestAsciiResource* inscription =
17376 new TestAsciiResource(i::StrDup(s), &destroyed);
17377 v8::Local<v8::String> ring = CompileRun("ring")->ToString();
17378 CHECK(v8::Utils::OpenHandle(*ring)->IsInternalizedString());
17379 ring->MakeExternal(inscription);
17380 // Ring is still alive. Orcs are roaming freely across our lands.
17381 CHECK_EQ(0, destroyed);
17382 USE(ring);
17383 }
17384
17385 // Garbage collector deals swift blows to evil.
17386 CcTest::i_isolate()->compilation_cache()->Clear();
17387 CcTest::heap()->CollectAllAvailableGarbage();
17388
17389 // Ring has been destroyed. Free Peoples of Middle-earth Rejoice.
17390 CHECK_EQ(1, destroyed);
17391 }
17392
17393
17251 static double DoubleFromBits(uint64_t value) { 17394 static double DoubleFromBits(uint64_t value) {
17252 double target; 17395 double target;
17253 i::OS::MemCopy(&target, &value, sizeof(target)); 17396 i::OS::MemCopy(&target, &value, sizeof(target));
17254 return target; 17397 return target;
17255 } 17398 }
17256 17399
17257 17400
17258 static uint64_t DoubleToBits(double value) { 17401 static uint64_t DoubleToBits(double value) {
17259 uint64_t target; 17402 uint64_t target;
17260 i::OS::MemCopy(&target, &value, sizeof(target)); 17403 i::OS::MemCopy(&target, &value, sizeof(target));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
17335 // Most significant fraction bit for quiet nan is set to 0 17478 // Most significant fraction bit for quiet nan is set to 0
17336 // on MIPS architecture. Allowed by IEEE-754. 17479 // on MIPS architecture. Allowed by IEEE-754.
17337 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff)); 17480 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff));
17338 #else 17481 #else
17339 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff)); 17482 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff));
17340 #endif 17483 #endif
17341 } 17484 }
17342 17485
17343 // Check that Date::New preserves non-NaNs in the date range and 17486 // Check that Date::New preserves non-NaNs in the date range and
17344 // quiets SNaNs. 17487 // quiets SNaNs.
17345 v8::Handle<v8::Value> date = v8::Date::New(test_value); 17488 v8::Handle<v8::Value> date =
17489 v8::Date::New(context->GetIsolate(), test_value);
17346 double expected_stored_date = DoubleToDateTime(test_value); 17490 double expected_stored_date = DoubleToDateTime(test_value);
17347 double stored_date = date->NumberValue(); 17491 double stored_date = date->NumberValue();
17348 if (!std::isnan(expected_stored_date)) { 17492 if (!std::isnan(expected_stored_date)) {
17349 CHECK_EQ(expected_stored_date, stored_date); 17493 CHECK_EQ(expected_stored_date, stored_date);
17350 } else { 17494 } else {
17351 uint64_t stored_bits = DoubleToBits(stored_date); 17495 uint64_t stored_bits = DoubleToBits(stored_date);
17352 // Check if quiet nan (bits 51..62 all set). 17496 // Check if quiet nan (bits 51..62 all set).
17353 #if defined(V8_TARGET_ARCH_MIPS) && !defined(USE_SIMULATOR) 17497 #if defined(V8_TARGET_ARCH_MIPS) && !defined(USE_SIMULATOR)
17354 // Most significant fraction bit for quiet nan is set to 0 17498 // Most significant fraction bit for quiet nan is set to 0
17355 // on MIPS architecture. Allowed by IEEE-754. 17499 // on MIPS architecture. Allowed by IEEE-754.
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
17989 " var r1_ = %_GetFromCache(0, key1);" 18133 " var r1_ = %_GetFromCache(0, key1);"
17990 " if (r1 !== r1_)" 18134 " if (r1 !== r1_)"
17991 " return 'Different results for ' + key1 + ': ' + r1 + ' vs. ' + r1_;" 18135 " return 'Different results for ' + key1 + ': ' + r1 + ' vs. ' + r1_;"
17992 " return 'PASSED';" 18136 " return 'PASSED';"
17993 "})()"; 18137 "})()";
17994 CcTest::heap()->ClearJSFunctionResultCaches(); 18138 CcTest::heap()->ClearJSFunctionResultCaches();
17995 ExpectString(code, "PASSED"); 18139 ExpectString(code, "PASSED");
17996 } 18140 }
17997 18141
17998 18142
17999 static const int k0CacheSize = 16;
18000
18001 THREADED_TEST(FillJSFunctionResultCache) { 18143 THREADED_TEST(FillJSFunctionResultCache) {
18002 i::FLAG_allow_natives_syntax = true; 18144 i::FLAG_allow_natives_syntax = true;
18003 LocalContext context; 18145 LocalContext context;
18004 v8::HandleScope scope(context->GetIsolate()); 18146 v8::HandleScope scope(context->GetIsolate());
18005 18147
18006 const char* code = 18148 const char* code =
18007 "(function() {" 18149 "(function() {"
18008 " var k = 'a';" 18150 " var k = 'a';"
18009 " var r = %_GetFromCache(0, k);" 18151 " var r = %_GetFromCache(0, k);"
18010 " for (var i = 0; i < 16; i++) {" 18152 " for (var i = 0; i < 16; i++) {"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
18177 TEST(ContainsOnlyOneByte) { 18319 TEST(ContainsOnlyOneByte) {
18178 v8::V8::Initialize(); 18320 v8::V8::Initialize();
18179 v8::Isolate* isolate = CcTest::isolate(); 18321 v8::Isolate* isolate = CcTest::isolate();
18180 v8::HandleScope scope(isolate); 18322 v8::HandleScope scope(isolate);
18181 // Make a buffer long enough that it won't automatically be converted. 18323 // Make a buffer long enough that it won't automatically be converted.
18182 const int length = 512; 18324 const int length = 512;
18183 // Ensure word aligned assignment. 18325 // Ensure word aligned assignment.
18184 const int aligned_length = length*sizeof(uintptr_t)/sizeof(uint16_t); 18326 const int aligned_length = length*sizeof(uintptr_t)/sizeof(uint16_t);
18185 i::SmartArrayPointer<uintptr_t> 18327 i::SmartArrayPointer<uintptr_t>
18186 aligned_contents(new uintptr_t[aligned_length]); 18328 aligned_contents(new uintptr_t[aligned_length]);
18187 uint16_t* string_contents = reinterpret_cast<uint16_t*>(*aligned_contents); 18329 uint16_t* string_contents =
18330 reinterpret_cast<uint16_t*>(aligned_contents.get());
18188 // Set to contain only one byte. 18331 // Set to contain only one byte.
18189 for (int i = 0; i < length-1; i++) { 18332 for (int i = 0; i < length-1; i++) {
18190 string_contents[i] = 0x41; 18333 string_contents[i] = 0x41;
18191 } 18334 }
18192 string_contents[length-1] = 0; 18335 string_contents[length-1] = 0;
18193 // Simple case. 18336 // Simple case.
18194 Handle<String> string; 18337 Handle<String> string;
18195 string = String::NewExternal(new TestResource(string_contents)); 18338 string = String::NewExternal(isolate, new TestResource(string_contents));
18196 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); 18339 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte());
18197 // Counter example. 18340 // Counter example.
18198 string = String::NewFromTwoByte(isolate, string_contents); 18341 string = String::NewFromTwoByte(isolate, string_contents);
18199 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte()); 18342 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte());
18200 // Test left right and balanced cons strings. 18343 // Test left right and balanced cons strings.
18201 Handle<String> base = String::NewFromUtf8(isolate, "a"); 18344 Handle<String> base = String::NewFromUtf8(isolate, "a");
18202 Handle<String> left = base; 18345 Handle<String> left = base;
18203 Handle<String> right = base; 18346 Handle<String> right = base;
18204 for (int i = 0; i < 1000; i++) { 18347 for (int i = 0; i < 1000; i++) {
18205 left = String::Concat(base, left); 18348 left = String::Concat(base, left);
18206 right = String::Concat(right, base); 18349 right = String::Concat(right, base);
18207 } 18350 }
18208 Handle<String> balanced = String::Concat(left, base); 18351 Handle<String> balanced = String::Concat(left, base);
18209 balanced = String::Concat(balanced, right); 18352 balanced = String::Concat(balanced, right);
18210 Handle<String> cons_strings[] = {left, balanced, right}; 18353 Handle<String> cons_strings[] = {left, balanced, right};
18211 Handle<String> two_byte = 18354 Handle<String> two_byte =
18212 String::NewExternal(new TestResource(string_contents)); 18355 String::NewExternal(isolate, new TestResource(string_contents));
18213 for (size_t i = 0; i < ARRAY_SIZE(cons_strings); i++) { 18356 for (size_t i = 0; i < ARRAY_SIZE(cons_strings); i++) {
18214 // Base assumptions. 18357 // Base assumptions.
18215 string = cons_strings[i]; 18358 string = cons_strings[i];
18216 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte()); 18359 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte());
18217 // Test left and right concatentation. 18360 // Test left and right concatentation.
18218 string = String::Concat(two_byte, cons_strings[i]); 18361 string = String::Concat(two_byte, cons_strings[i]);
18219 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); 18362 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte());
18220 string = String::Concat(cons_strings[i], two_byte); 18363 string = String::Concat(cons_strings[i], two_byte);
18221 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); 18364 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte());
18222 } 18365 }
18223 // Set bits in different positions 18366 // Set bits in different positions
18224 // for strings of different lengths and alignments. 18367 // for strings of different lengths and alignments.
18225 for (int alignment = 0; alignment < 7; alignment++) { 18368 for (int alignment = 0; alignment < 7; alignment++) {
18226 for (int size = 2; alignment + size < length; size *= 2) { 18369 for (int size = 2; alignment + size < length; size *= 2) {
18227 int zero_offset = size + alignment; 18370 int zero_offset = size + alignment;
18228 string_contents[zero_offset] = 0; 18371 string_contents[zero_offset] = 0;
18229 for (int i = 0; i < size; i++) { 18372 for (int i = 0; i < size; i++) {
18230 int shift = 8 + (i % 7); 18373 int shift = 8 + (i % 7);
18231 string_contents[alignment + i] = 1 << shift; 18374 string_contents[alignment + i] = 1 << shift;
18232 string = 18375 string = String::NewExternal(
18233 String::NewExternal(new TestResource(string_contents + alignment)); 18376 isolate, new TestResource(string_contents + alignment));
18234 CHECK_EQ(size, string->Length()); 18377 CHECK_EQ(size, string->Length());
18235 CHECK(!string->ContainsOnlyOneByte()); 18378 CHECK(!string->ContainsOnlyOneByte());
18236 string_contents[alignment + i] = 0x41; 18379 string_contents[alignment + i] = 0x41;
18237 } 18380 }
18238 string_contents[zero_offset] = 0x41; 18381 string_contents[zero_offset] = 0x41;
18239 } 18382 }
18240 } 18383 }
18241 } 18384 }
18242 18385
18243 18386
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
19005 } 19148 }
19006 19149
19007 19150
19008 static void Getter(v8::Local<v8::String> property, 19151 static void Getter(v8::Local<v8::String> property,
19009 const v8::PropertyCallbackInfo<v8::Value>& info ) { 19152 const v8::PropertyCallbackInfo<v8::Value>& info ) {
19010 info.GetReturnValue().Set(v8_str("42!")); 19153 info.GetReturnValue().Set(v8_str("42!"));
19011 } 19154 }
19012 19155
19013 19156
19014 static void Enumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { 19157 static void Enumerator(const v8::PropertyCallbackInfo<v8::Array>& info) {
19015 v8::Handle<v8::Array> result = v8::Array::New(); 19158 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate());
19016 result->Set(0, v8_str("universalAnswer")); 19159 result->Set(0, v8_str("universalAnswer"));
19017 info.GetReturnValue().Set(result); 19160 info.GetReturnValue().Set(result);
19018 } 19161 }
19019 19162
19020 19163
19021 TEST(NamedEnumeratorAndForIn) { 19164 TEST(NamedEnumeratorAndForIn) {
19022 LocalContext context; 19165 LocalContext context;
19023 v8::HandleScope handle_scope(context->GetIsolate()); 19166 v8::HandleScope handle_scope(context->GetIsolate());
19024 v8::Context::Scope context_scope(context.local()); 19167 v8::Context::Scope context_scope(context.local());
19025 19168
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after
20016 LocalContext context; 20159 LocalContext context;
20017 v8::HandleScope scope(context->GetIsolate()); 20160 v8::HandleScope scope(context->GetIsolate());
20018 20161
20019 Local<FunctionTemplate> templ = FunctionTemplate::New(); 20162 Local<FunctionTemplate> templ = FunctionTemplate::New();
20020 Local<ObjectTemplate> inst = templ->InstanceTemplate(); 20163 Local<ObjectTemplate> inst = templ->InstanceTemplate();
20021 inst->SetAccessor(v8_str("foo"), 20164 inst->SetAccessor(v8_str("foo"),
20022 InstanceCheckedGetter, InstanceCheckedSetter, 20165 InstanceCheckedGetter, InstanceCheckedSetter,
20023 Handle<Value>(), 20166 Handle<Value>(),
20024 v8::DEFAULT, 20167 v8::DEFAULT,
20025 v8::None, 20168 v8::None,
20026 v8::AccessorSignature::New(templ)); 20169 v8::AccessorSignature::New(context->GetIsolate(), templ));
20027 context->Global()->Set(v8_str("f"), templ->GetFunction()); 20170 context->Global()->Set(v8_str("f"), templ->GetFunction());
20028 20171
20029 printf("Testing positive ...\n"); 20172 printf("Testing positive ...\n");
20030 CompileRun("var obj = new f();"); 20173 CompileRun("var obj = new f();");
20031 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); 20174 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj"))));
20032 CheckInstanceCheckedAccessors(true); 20175 CheckInstanceCheckedAccessors(true);
20033 20176
20034 printf("Testing negative ...\n"); 20177 printf("Testing negative ...\n");
20035 CompileRun("var obj = {};" 20178 CompileRun("var obj = {};"
20036 "obj.__proto__ = new f();"); 20179 "obj.__proto__ = new f();");
20037 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); 20180 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj"))));
20038 CheckInstanceCheckedAccessors(false); 20181 CheckInstanceCheckedAccessors(false);
20039 } 20182 }
20040 20183
20041 20184
20042 THREADED_TEST(InstanceCheckOnInstanceAccessorWithInterceptor) { 20185 THREADED_TEST(InstanceCheckOnInstanceAccessorWithInterceptor) {
20043 v8::internal::FLAG_allow_natives_syntax = true; 20186 v8::internal::FLAG_allow_natives_syntax = true;
20044 LocalContext context; 20187 LocalContext context;
20045 v8::HandleScope scope(context->GetIsolate()); 20188 v8::HandleScope scope(context->GetIsolate());
20046 20189
20047 Local<FunctionTemplate> templ = FunctionTemplate::New(); 20190 Local<FunctionTemplate> templ = FunctionTemplate::New();
20048 Local<ObjectTemplate> inst = templ->InstanceTemplate(); 20191 Local<ObjectTemplate> inst = templ->InstanceTemplate();
20049 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter); 20192 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter);
20050 inst->SetAccessor(v8_str("foo"), 20193 inst->SetAccessor(v8_str("foo"),
20051 InstanceCheckedGetter, InstanceCheckedSetter, 20194 InstanceCheckedGetter, InstanceCheckedSetter,
20052 Handle<Value>(), 20195 Handle<Value>(),
20053 v8::DEFAULT, 20196 v8::DEFAULT,
20054 v8::None, 20197 v8::None,
20055 v8::AccessorSignature::New(templ)); 20198 v8::AccessorSignature::New(context->GetIsolate(), templ));
20056 context->Global()->Set(v8_str("f"), templ->GetFunction()); 20199 context->Global()->Set(v8_str("f"), templ->GetFunction());
20057 20200
20058 printf("Testing positive ...\n"); 20201 printf("Testing positive ...\n");
20059 CompileRun("var obj = new f();"); 20202 CompileRun("var obj = new f();");
20060 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); 20203 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj"))));
20061 CheckInstanceCheckedAccessors(true); 20204 CheckInstanceCheckedAccessors(true);
20062 20205
20063 printf("Testing negative ...\n"); 20206 printf("Testing negative ...\n");
20064 CompileRun("var obj = {};" 20207 CompileRun("var obj = {};"
20065 "obj.__proto__ = new f();"); 20208 "obj.__proto__ = new f();");
20066 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); 20209 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj"))));
20067 CheckInstanceCheckedAccessors(false); 20210 CheckInstanceCheckedAccessors(false);
20068 } 20211 }
20069 20212
20070 20213
20071 THREADED_TEST(InstanceCheckOnPrototypeAccessor) { 20214 THREADED_TEST(InstanceCheckOnPrototypeAccessor) {
20072 v8::internal::FLAG_allow_natives_syntax = true; 20215 v8::internal::FLAG_allow_natives_syntax = true;
20073 LocalContext context; 20216 LocalContext context;
20074 v8::HandleScope scope(context->GetIsolate()); 20217 v8::HandleScope scope(context->GetIsolate());
20075 20218
20076 Local<FunctionTemplate> templ = FunctionTemplate::New(); 20219 Local<FunctionTemplate> templ = FunctionTemplate::New();
20077 Local<ObjectTemplate> proto = templ->PrototypeTemplate(); 20220 Local<ObjectTemplate> proto = templ->PrototypeTemplate();
20078 proto->SetAccessor(v8_str("foo"), 20221 proto->SetAccessor(v8_str("foo"),
20079 InstanceCheckedGetter, InstanceCheckedSetter, 20222 InstanceCheckedGetter, InstanceCheckedSetter,
20080 Handle<Value>(), 20223 Handle<Value>(),
20081 v8::DEFAULT, 20224 v8::DEFAULT,
20082 v8::None, 20225 v8::None,
20083 v8::AccessorSignature::New(templ)); 20226 v8::AccessorSignature::New(context->GetIsolate(), templ));
20084 context->Global()->Set(v8_str("f"), templ->GetFunction()); 20227 context->Global()->Set(v8_str("f"), templ->GetFunction());
20085 20228
20086 printf("Testing positive ...\n"); 20229 printf("Testing positive ...\n");
20087 CompileRun("var obj = new f();"); 20230 CompileRun("var obj = new f();");
20088 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); 20231 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj"))));
20089 CheckInstanceCheckedAccessors(true); 20232 CheckInstanceCheckedAccessors(true);
20090 20233
20091 printf("Testing negative ...\n"); 20234 printf("Testing negative ...\n");
20092 CompileRun("var obj = {};" 20235 CompileRun("var obj = {};"
20093 "obj.__proto__ = new f();"); 20236 "obj.__proto__ = new f();");
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
20492 // failed access check callback will be called on each access. 20635 // failed access check callback will be called on each access.
20493 LocalContext context1(NULL, global_template); 20636 LocalContext context1(NULL, global_template);
20494 context1->Global()->Set(v8_str("other"), global0); 20637 context1->Global()->Set(v8_str("other"), global0);
20495 20638
20496 ExpectString("JSON.stringify(other)", "{}"); 20639 ExpectString("JSON.stringify(other)", "{}");
20497 ExpectString("JSON.stringify({ 'a' : other, 'b' : ['c'] })", 20640 ExpectString("JSON.stringify({ 'a' : other, 'b' : ['c'] })",
20498 "{\"a\":{},\"b\":[\"c\"]}"); 20641 "{\"a\":{},\"b\":[\"c\"]}");
20499 ExpectString("JSON.stringify([other, 'b', 'c'])", 20642 ExpectString("JSON.stringify([other, 'b', 'c'])",
20500 "[{},\"b\",\"c\"]"); 20643 "[{},\"b\",\"c\"]");
20501 20644
20502 v8::Handle<v8::Array> array = v8::Array::New(2); 20645 v8::Handle<v8::Array> array = v8::Array::New(CcTest::isolate(), 2);
20503 array->Set(0, v8_str("a")); 20646 array->Set(0, v8_str("a"));
20504 array->Set(1, v8_str("b")); 20647 array->Set(1, v8_str("b"));
20505 context1->Global()->Set(v8_str("array"), array); 20648 context1->Global()->Set(v8_str("array"), array);
20506 ExpectString("JSON.stringify(array)", "[\"a\",\"b\"]"); 20649 ExpectString("JSON.stringify(array)", "[\"a\",\"b\"]");
20507 array->TurnOnAccessCheck(); 20650 array->TurnOnAccessCheck();
20508 ExpectString("JSON.stringify(array)", "[]"); 20651 ExpectString("JSON.stringify(array)", "[]");
20509 ExpectString("JSON.stringify([array])", "[[]]"); 20652 ExpectString("JSON.stringify([array])", "[[]]");
20510 ExpectString("JSON.stringify({'a' : array})", "{\"a\":[]}"); 20653 ExpectString("JSON.stringify({'a' : array})", "{\"a\":[]}");
20511 } 20654 }
20512 } 20655 }
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
20780 } 20923 }
20781 for (int i = 0; i < runs; i++) { 20924 for (int i = 0; i < runs; i++) {
20782 Local<String> expected; 20925 Local<String> expected;
20783 if (i != 0) { 20926 if (i != 0) {
20784 CHECK_EQ(v8_str("escape value"), values[i]); 20927 CHECK_EQ(v8_str("escape value"), values[i]);
20785 } else { 20928 } else {
20786 CHECK(values[i].IsEmpty()); 20929 CHECK(values[i].IsEmpty());
20787 } 20930 }
20788 } 20931 }
20789 } 20932 }
OLDNEW
« no previous file with comments | « test/cctest/test-accessors.cc ('k') | test/cctest/test-assembler-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698