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

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

Issue 190503002: Refactor script compilation / running & use of helper funcs in test-api.cc. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/cctest.h ('k') | no next file » | 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 197 }
198 198
199 // Local context should still be live. 199 // Local context should still be live.
200 CHECK(!local_env.IsEmpty()); 200 CHECK(!local_env.IsEmpty());
201 local_env->Enter(); 201 local_env->Enter();
202 202
203 v8::Handle<v8::Primitive> undef = v8::Undefined(CcTest::isolate()); 203 v8::Handle<v8::Primitive> undef = v8::Undefined(CcTest::isolate());
204 CHECK(!undef.IsEmpty()); 204 CHECK(!undef.IsEmpty());
205 CHECK(undef->IsUndefined()); 205 CHECK(undef->IsUndefined());
206 206
207 const char* c_source = "1 + 2 + 3"; 207 const char* source = "1 + 2 + 3";
208 Local<String> source = String::NewFromUtf8(CcTest::isolate(), c_source); 208 Local<Script> script = v8_compile(source);
209 Local<Script> script = Script::Compile(source);
210 CHECK_EQ(6, script->Run()->Int32Value()); 209 CHECK_EQ(6, script->Run()->Int32Value());
211 210
212 local_env->Exit(); 211 local_env->Exit();
213 } 212 }
214 213
215 214
216 THREADED_TEST(IsolateOfContext) { 215 THREADED_TEST(IsolateOfContext) {
217 v8::HandleScope scope(CcTest::isolate()); 216 v8::HandleScope scope(CcTest::isolate());
218 v8::Handle<Context> env = Context::New(CcTest::isolate()); 217 v8::Handle<Context> env = Context::New(CcTest::isolate());
219 218
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 437
439 Local<v8::Array> value = CompileRun("[\"a\", \"b\"]").As<v8::Array>(); 438 Local<v8::Array> value = CompileRun("[\"a\", \"b\"]").As<v8::Array>();
440 CHECK_EQ(v8_str("a"), value->Get(0)); 439 CHECK_EQ(v8_str("a"), value->Get(0));
441 CHECK_EQ(v8_str("b"), value->Get(1)); 440 CHECK_EQ(v8_str("b"), value->Get(1));
442 } 441 }
443 442
444 443
445 THREADED_TEST(Script) { 444 THREADED_TEST(Script) {
446 LocalContext env; 445 LocalContext env;
447 v8::HandleScope scope(env->GetIsolate()); 446 v8::HandleScope scope(env->GetIsolate());
448 const char* c_source = "1 + 2 + 3"; 447 const char* source = "1 + 2 + 3";
449 Local<String> source = String::NewFromUtf8(env->GetIsolate(), c_source); 448 Local<Script> script = v8_compile(source);
450 Local<Script> script = Script::Compile(source);
451 CHECK_EQ(6, script->Run()->Int32Value()); 449 CHECK_EQ(6, script->Run()->Int32Value());
452 } 450 }
453 451
454 452
455 static uint16_t* AsciiToTwoByteString(const char* source) { 453 static uint16_t* AsciiToTwoByteString(const char* source) {
456 int array_length = i::StrLength(source) + 1; 454 int array_length = i::StrLength(source) + 1;
457 uint16_t* converted = i::NewArray<uint16_t>(array_length); 455 uint16_t* converted = i::NewArray<uint16_t>(array_length);
458 for (int i = 0; i < array_length; i++) converted[i] = source[i]; 456 for (int i = 0; i < array_length; i++) converted[i] = source[i];
459 return converted; 457 return converted;
460 } 458 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 517
520 THREADED_TEST(ScriptUsingStringResource) { 518 THREADED_TEST(ScriptUsingStringResource) {
521 int dispose_count = 0; 519 int dispose_count = 0;
522 const char* c_source = "1 + 2 * 3"; 520 const char* c_source = "1 + 2 * 3";
523 uint16_t* two_byte_source = AsciiToTwoByteString(c_source); 521 uint16_t* two_byte_source = AsciiToTwoByteString(c_source);
524 { 522 {
525 LocalContext env; 523 LocalContext env;
526 v8::HandleScope scope(env->GetIsolate()); 524 v8::HandleScope scope(env->GetIsolate());
527 TestResource* resource = new TestResource(two_byte_source, &dispose_count); 525 TestResource* resource = new TestResource(two_byte_source, &dispose_count);
528 Local<String> source = String::NewExternal(env->GetIsolate(), resource); 526 Local<String> source = String::NewExternal(env->GetIsolate(), resource);
529 Local<Script> script = Script::Compile(source); 527 Local<Script> script = v8_compile(source);
530 Local<Value> value = script->Run(); 528 Local<Value> value = script->Run();
531 CHECK(value->IsNumber()); 529 CHECK(value->IsNumber());
532 CHECK_EQ(7, value->Int32Value()); 530 CHECK_EQ(7, value->Int32Value());
533 CHECK(source->IsExternal()); 531 CHECK(source->IsExternal());
534 CHECK_EQ(resource, 532 CHECK_EQ(resource,
535 static_cast<TestResource*>(source->GetExternalStringResource())); 533 static_cast<TestResource*>(source->GetExternalStringResource()));
536 String::Encoding encoding = String::UNKNOWN_ENCODING; 534 String::Encoding encoding = String::UNKNOWN_ENCODING;
537 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), 535 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
538 source->GetExternalStringResourceBase(&encoding)); 536 source->GetExternalStringResourceBase(&encoding));
539 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding); 537 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding);
(...skipping 15 matching lines...) Expand all
555 TestAsciiResource* resource = new TestAsciiResource(i::StrDup(c_source), 553 TestAsciiResource* resource = new TestAsciiResource(i::StrDup(c_source),
556 &dispose_count); 554 &dispose_count);
557 Local<String> source = String::NewExternal(env->GetIsolate(), resource); 555 Local<String> source = String::NewExternal(env->GetIsolate(), resource);
558 CHECK(source->IsExternalAscii()); 556 CHECK(source->IsExternalAscii());
559 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), 557 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
560 source->GetExternalAsciiStringResource()); 558 source->GetExternalAsciiStringResource());
561 String::Encoding encoding = String::UNKNOWN_ENCODING; 559 String::Encoding encoding = String::UNKNOWN_ENCODING;
562 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), 560 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
563 source->GetExternalStringResourceBase(&encoding)); 561 source->GetExternalStringResourceBase(&encoding));
564 CHECK_EQ(String::ASCII_ENCODING, encoding); 562 CHECK_EQ(String::ASCII_ENCODING, encoding);
565 Local<Script> script = Script::Compile(source); 563 Local<Script> script = v8_compile(source);
566 Local<Value> value = script->Run(); 564 Local<Value> value = script->Run();
567 CHECK(value->IsNumber()); 565 CHECK(value->IsNumber());
568 CHECK_EQ(7, value->Int32Value()); 566 CHECK_EQ(7, value->Int32Value());
569 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 567 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
570 CHECK_EQ(0, dispose_count); 568 CHECK_EQ(0, dispose_count);
571 } 569 }
572 CcTest::i_isolate()->compilation_cache()->Clear(); 570 CcTest::i_isolate()->compilation_cache()->Clear();
573 CcTest::heap()->CollectAllAvailableGarbage(); 571 CcTest::heap()->CollectAllAvailableGarbage();
574 CHECK_EQ(1, dispose_count); 572 CHECK_EQ(1, dispose_count);
575 } 573 }
(...skipping 11 matching lines...) Expand all
587 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now 585 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now
588 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now 586 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
589 CHECK_EQ(source->IsExternal(), false); 587 CHECK_EQ(source->IsExternal(), false);
590 CHECK_EQ(source->IsExternalAscii(), false); 588 CHECK_EQ(source->IsExternalAscii(), false);
591 String::Encoding encoding = String::UNKNOWN_ENCODING; 589 String::Encoding encoding = String::UNKNOWN_ENCODING;
592 CHECK_EQ(NULL, source->GetExternalStringResourceBase(&encoding)); 590 CHECK_EQ(NULL, source->GetExternalStringResourceBase(&encoding));
593 CHECK_EQ(String::ASCII_ENCODING, encoding); 591 CHECK_EQ(String::ASCII_ENCODING, encoding);
594 bool success = source->MakeExternal(new TestResource(two_byte_source, 592 bool success = source->MakeExternal(new TestResource(two_byte_source,
595 &dispose_count)); 593 &dispose_count));
596 CHECK(success); 594 CHECK(success);
597 Local<Script> script = Script::Compile(source); 595 Local<Script> script = v8_compile(source);
598 Local<Value> value = script->Run(); 596 Local<Value> value = script->Run();
599 CHECK(value->IsNumber()); 597 CHECK(value->IsNumber());
600 CHECK_EQ(7, value->Int32Value()); 598 CHECK_EQ(7, value->Int32Value());
601 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 599 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
602 CHECK_EQ(0, dispose_count); 600 CHECK_EQ(0, dispose_count);
603 } 601 }
604 CcTest::i_isolate()->compilation_cache()->Clear(); 602 CcTest::i_isolate()->compilation_cache()->Clear();
605 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 603 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
606 CHECK_EQ(1, dispose_count); 604 CHECK_EQ(1, dispose_count);
607 } 605 }
608 606
609 607
610 THREADED_TEST(ScriptMakingExternalAsciiString) { 608 THREADED_TEST(ScriptMakingExternalAsciiString) {
611 int dispose_count = 0; 609 int dispose_count = 0;
612 const char* c_source = "1 + 2 * 3"; 610 const char* c_source = "1 + 2 * 3";
613 { 611 {
614 LocalContext env; 612 LocalContext env;
615 v8::HandleScope scope(env->GetIsolate()); 613 v8::HandleScope scope(env->GetIsolate());
616 Local<String> source = v8_str(c_source); 614 Local<String> source = v8_str(c_source);
617 // Trigger GCs so that the newly allocated string moves to old gen. 615 // Trigger GCs so that the newly allocated string moves to old gen.
618 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now 616 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now
619 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now 617 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
620 bool success = source->MakeExternal( 618 bool success = source->MakeExternal(
621 new TestAsciiResource(i::StrDup(c_source), &dispose_count)); 619 new TestAsciiResource(i::StrDup(c_source), &dispose_count));
622 CHECK(success); 620 CHECK(success);
623 Local<Script> script = Script::Compile(source); 621 Local<Script> script = v8_compile(source);
624 Local<Value> value = script->Run(); 622 Local<Value> value = script->Run();
625 CHECK(value->IsNumber()); 623 CHECK(value->IsNumber());
626 CHECK_EQ(7, value->Int32Value()); 624 CHECK_EQ(7, value->Int32Value());
627 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 625 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
628 CHECK_EQ(0, dispose_count); 626 CHECK_EQ(0, dispose_count);
629 } 627 }
630 CcTest::i_isolate()->compilation_cache()->Clear(); 628 CcTest::i_isolate()->compilation_cache()->Clear();
631 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 629 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
632 CHECK_EQ(1, dispose_count); 630 CHECK_EQ(1, dispose_count);
633 } 631 }
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 const char* c_source = "1 + 2 * 3"; 862 const char* c_source = "1 + 2 * 3";
865 863
866 // Use a stack allocated external string resource allocated object. 864 // Use a stack allocated external string resource allocated object.
867 TestAsciiResourceWithDisposeControl::dispose_count = 0; 865 TestAsciiResourceWithDisposeControl::dispose_count = 0;
868 TestAsciiResourceWithDisposeControl::dispose_calls = 0; 866 TestAsciiResourceWithDisposeControl::dispose_calls = 0;
869 TestAsciiResourceWithDisposeControl res_stack(i::StrDup(c_source), false); 867 TestAsciiResourceWithDisposeControl res_stack(i::StrDup(c_source), false);
870 { 868 {
871 LocalContext env; 869 LocalContext env;
872 v8::HandleScope scope(env->GetIsolate()); 870 v8::HandleScope scope(env->GetIsolate());
873 Local<String> source = String::NewExternal(env->GetIsolate(), &res_stack); 871 Local<String> source = String::NewExternal(env->GetIsolate(), &res_stack);
874 Local<Script> script = Script::Compile(source); 872 Local<Script> script = v8_compile(source);
875 Local<Value> value = script->Run(); 873 Local<Value> value = script->Run();
876 CHECK(value->IsNumber()); 874 CHECK(value->IsNumber());
877 CHECK_EQ(7, value->Int32Value()); 875 CHECK_EQ(7, value->Int32Value());
878 CcTest::heap()->CollectAllAvailableGarbage(); 876 CcTest::heap()->CollectAllAvailableGarbage();
879 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count); 877 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count);
880 } 878 }
881 CcTest::i_isolate()->compilation_cache()->Clear(); 879 CcTest::i_isolate()->compilation_cache()->Clear();
882 CcTest::heap()->CollectAllAvailableGarbage(); 880 CcTest::heap()->CollectAllAvailableGarbage();
883 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls); 881 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls);
884 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count); 882 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count);
885 883
886 // Use a heap allocated external string resource allocated object. 884 // Use a heap allocated external string resource allocated object.
887 TestAsciiResourceWithDisposeControl::dispose_count = 0; 885 TestAsciiResourceWithDisposeControl::dispose_count = 0;
888 TestAsciiResourceWithDisposeControl::dispose_calls = 0; 886 TestAsciiResourceWithDisposeControl::dispose_calls = 0;
889 TestAsciiResource* res_heap = 887 TestAsciiResource* res_heap =
890 new TestAsciiResourceWithDisposeControl(i::StrDup(c_source), true); 888 new TestAsciiResourceWithDisposeControl(i::StrDup(c_source), true);
891 { 889 {
892 LocalContext env; 890 LocalContext env;
893 v8::HandleScope scope(env->GetIsolate()); 891 v8::HandleScope scope(env->GetIsolate());
894 Local<String> source = String::NewExternal(env->GetIsolate(), res_heap); 892 Local<String> source = String::NewExternal(env->GetIsolate(), res_heap);
895 Local<Script> script = Script::Compile(source); 893 Local<Script> script = v8_compile(source);
896 Local<Value> value = script->Run(); 894 Local<Value> value = script->Run();
897 CHECK(value->IsNumber()); 895 CHECK(value->IsNumber());
898 CHECK_EQ(7, value->Int32Value()); 896 CHECK_EQ(7, value->Int32Value());
899 CcTest::heap()->CollectAllAvailableGarbage(); 897 CcTest::heap()->CollectAllAvailableGarbage();
900 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count); 898 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count);
901 } 899 }
902 CcTest::i_isolate()->compilation_cache()->Clear(); 900 CcTest::i_isolate()->compilation_cache()->Clear();
903 CcTest::heap()->CollectAllAvailableGarbage(); 901 CcTest::heap()->CollectAllAvailableGarbage();
904 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls); 902 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls);
905 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_count); 903 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_count);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 935
938 two_byte_source = AsciiToTwoByteString(two_byte_string_2); 936 two_byte_source = AsciiToTwoByteString(two_byte_string_2);
939 right = String::NewFromTwoByte(env->GetIsolate(), two_byte_source); 937 right = String::NewFromTwoByte(env->GetIsolate(), two_byte_source);
940 i::DeleteArray(two_byte_source); 938 i::DeleteArray(two_byte_source);
941 939
942 source = String::Concat(source, right); 940 source = String::Concat(source, right);
943 right = String::NewExternal( 941 right = String::NewExternal(
944 env->GetIsolate(), 942 env->GetIsolate(),
945 new TestResource(AsciiToTwoByteString(two_byte_extern_2))); 943 new TestResource(AsciiToTwoByteString(two_byte_extern_2)));
946 source = String::Concat(source, right); 944 source = String::Concat(source, right);
947 Local<Script> script = Script::Compile(source); 945 Local<Script> script = v8_compile(source);
948 Local<Value> value = script->Run(); 946 Local<Value> value = script->Run();
949 CHECK(value->IsNumber()); 947 CHECK(value->IsNumber());
950 CHECK_EQ(68, value->Int32Value()); 948 CHECK_EQ(68, value->Int32Value());
951 } 949 }
952 CcTest::i_isolate()->compilation_cache()->Clear(); 950 CcTest::i_isolate()->compilation_cache()->Clear();
953 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 951 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
954 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 952 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
955 } 953 }
956 954
957 955
(...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after
2390 2388
2391 bottom = templ->GetFunction()->NewInstance(); 2389 bottom = templ->GetFunction()->NewInstance();
2392 Local<v8::Object> top = templ->GetFunction()->NewInstance(); 2390 Local<v8::Object> top = templ->GetFunction()->NewInstance();
2393 Local<v8::Object> middle = templ->GetFunction()->NewInstance(); 2391 Local<v8::Object> middle = templ->GetFunction()->NewInstance();
2394 2392
2395 bottom->SetPrototype(middle); 2393 bottom->SetPrototype(middle);
2396 middle->SetPrototype(top); 2394 middle->SetPrototype(top);
2397 env->Global()->Set(v8_str("obj"), bottom); 2395 env->Global()->Set(v8_str("obj"), bottom);
2398 2396
2399 // Indexed and named get. 2397 // Indexed and named get.
2400 Script::Compile(v8_str("obj[0]"))->Run(); 2398 CompileRun("obj[0]");
2401 Script::Compile(v8_str("obj.x"))->Run(); 2399 CompileRun("obj.x");
2402 2400
2403 // Indexed and named set. 2401 // Indexed and named set.
2404 Script::Compile(v8_str("obj[1] = 42"))->Run(); 2402 CompileRun("obj[1] = 42");
2405 Script::Compile(v8_str("obj.y = 42"))->Run(); 2403 CompileRun("obj.y = 42");
2406 2404
2407 // Indexed and named query. 2405 // Indexed and named query.
2408 Script::Compile(v8_str("0 in obj"))->Run(); 2406 CompileRun("0 in obj");
2409 Script::Compile(v8_str("'x' in obj"))->Run(); 2407 CompileRun("'x' in obj");
2410 2408
2411 // Indexed and named deleter. 2409 // Indexed and named deleter.
2412 Script::Compile(v8_str("delete obj[0]"))->Run(); 2410 CompileRun("delete obj[0]");
2413 Script::Compile(v8_str("delete obj.x"))->Run(); 2411 CompileRun("delete obj.x");
2414 2412
2415 // Enumerators. 2413 // Enumerators.
2416 Script::Compile(v8_str("for (var p in obj) ;"))->Run(); 2414 CompileRun("for (var p in obj) ;");
2417 } 2415 }
2418 2416
2419 2417
2420 static void PrePropertyHandlerGet( 2418 static void PrePropertyHandlerGet(
2421 Local<String> key, 2419 Local<String> key,
2422 const v8::PropertyCallbackInfo<v8::Value>& info) { 2420 const v8::PropertyCallbackInfo<v8::Value>& info) {
2423 ApiTestFuzzer::Fuzz(); 2421 ApiTestFuzzer::Fuzz();
2424 if (v8_str("pre")->Equals(key)) { 2422 if (v8_str("pre")->Equals(key)) {
2425 info.GetReturnValue().Set(v8_str("PrePropertyHandler: pre")); 2423 info.GetReturnValue().Set(v8_str("PrePropertyHandler: pre"));
2426 } 2424 }
(...skipping 10 matching lines...) Expand all
2437 2435
2438 2436
2439 THREADED_TEST(PrePropertyHandler) { 2437 THREADED_TEST(PrePropertyHandler) {
2440 v8::Isolate* isolate = CcTest::isolate(); 2438 v8::Isolate* isolate = CcTest::isolate();
2441 v8::HandleScope scope(isolate); 2439 v8::HandleScope scope(isolate);
2442 v8::Handle<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate); 2440 v8::Handle<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate);
2443 desc->InstanceTemplate()->SetNamedPropertyHandler(PrePropertyHandlerGet, 2441 desc->InstanceTemplate()->SetNamedPropertyHandler(PrePropertyHandlerGet,
2444 0, 2442 0,
2445 PrePropertyHandlerQuery); 2443 PrePropertyHandlerQuery);
2446 LocalContext env(NULL, desc->InstanceTemplate()); 2444 LocalContext env(NULL, desc->InstanceTemplate());
2447 Script::Compile(v8_str( 2445 CompileRun("var pre = 'Object: pre'; var on = 'Object: on';");
2448 "var pre = 'Object: pre'; var on = 'Object: on';"))->Run(); 2446 v8::Handle<Value> result_pre = CompileRun("pre");
2449 v8::Handle<Value> result_pre = Script::Compile(v8_str("pre"))->Run();
2450 CHECK_EQ(v8_str("PrePropertyHandler: pre"), result_pre); 2447 CHECK_EQ(v8_str("PrePropertyHandler: pre"), result_pre);
2451 v8::Handle<Value> result_on = Script::Compile(v8_str("on"))->Run(); 2448 v8::Handle<Value> result_on = CompileRun("on");
2452 CHECK_EQ(v8_str("Object: on"), result_on); 2449 CHECK_EQ(v8_str("Object: on"), result_on);
2453 v8::Handle<Value> result_post = Script::Compile(v8_str("post"))->Run(); 2450 v8::Handle<Value> result_post = CompileRun("post");
2454 CHECK(result_post.IsEmpty()); 2451 CHECK(result_post.IsEmpty());
2455 } 2452 }
2456 2453
2457 2454
2458 THREADED_TEST(UndefinedIsNotEnumerable) { 2455 THREADED_TEST(UndefinedIsNotEnumerable) {
2459 LocalContext env; 2456 LocalContext env;
2460 v8::HandleScope scope(env->GetIsolate()); 2457 v8::HandleScope scope(env->GetIsolate());
2461 v8::Handle<Value> result = Script::Compile(v8_str( 2458 v8::Handle<Value> result = CompileRun("this.propertyIsEnumerable(undefined)");
2462 "this.propertyIsEnumerable(undefined)"))->Run();
2463 CHECK(result->IsFalse()); 2459 CHECK(result->IsFalse());
2464 } 2460 }
2465 2461
2466 2462
2467 v8::Handle<Script> call_recursively_script; 2463 v8::Handle<Script> call_recursively_script;
2468 static const int kTargetRecursionDepth = 200; // near maximum 2464 static const int kTargetRecursionDepth = 200; // near maximum
2469 2465
2470 2466
2471 static void CallScriptRecursivelyCall( 2467 static void CallScriptRecursivelyCall(
2472 const v8::FunctionCallbackInfo<v8::Value>& args) { 2468 const v8::FunctionCallbackInfo<v8::Value>& args) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2505 global->Set(v8_str("callFunctionRecursively"), 2501 global->Set(v8_str("callFunctionRecursively"),
2506 v8::FunctionTemplate::New(isolate, CallFunctionRecursivelyCall)); 2502 v8::FunctionTemplate::New(isolate, CallFunctionRecursivelyCall));
2507 LocalContext env(NULL, global); 2503 LocalContext env(NULL, global);
2508 2504
2509 env->Global()->Set(v8_str("depth"), v8::Integer::New(isolate, 0)); 2505 env->Global()->Set(v8_str("depth"), v8::Integer::New(isolate, 0));
2510 call_recursively_script = v8_compile("callScriptRecursively()"); 2506 call_recursively_script = v8_compile("callScriptRecursively()");
2511 call_recursively_script->Run(); 2507 call_recursively_script->Run();
2512 call_recursively_script = v8::Handle<Script>(); 2508 call_recursively_script = v8::Handle<Script>();
2513 2509
2514 env->Global()->Set(v8_str("depth"), v8::Integer::New(isolate, 0)); 2510 env->Global()->Set(v8_str("depth"), v8::Integer::New(isolate, 0));
2515 Script::Compile(v8_str("callFunctionRecursively()"))->Run(); 2511 CompileRun("callFunctionRecursively()");
2516 } 2512 }
2517 2513
2518 2514
2519 static void ThrowingPropertyHandlerGet( 2515 static void ThrowingPropertyHandlerGet(
2520 Local<String> key, 2516 Local<String> key,
2521 const v8::PropertyCallbackInfo<v8::Value>& info) { 2517 const v8::PropertyCallbackInfo<v8::Value>& info) {
2522 ApiTestFuzzer::Fuzz(); 2518 ApiTestFuzzer::Fuzz();
2523 info.GetReturnValue().Set(info.GetIsolate()->ThrowException(key)); 2519 info.GetReturnValue().Set(info.GetIsolate()->ThrowException(key));
2524 } 2520 }
2525 2521
2526 2522
2527 static void ThrowingPropertyHandlerSet( 2523 static void ThrowingPropertyHandlerSet(
2528 Local<String> key, 2524 Local<String> key,
2529 Local<Value>, 2525 Local<Value>,
2530 const v8::PropertyCallbackInfo<v8::Value>& info) { 2526 const v8::PropertyCallbackInfo<v8::Value>& info) {
2531 info.GetIsolate()->ThrowException(key); 2527 info.GetIsolate()->ThrowException(key);
2532 info.GetReturnValue().SetUndefined(); // not the same as empty handle 2528 info.GetReturnValue().SetUndefined(); // not the same as empty handle
2533 } 2529 }
2534 2530
2535 2531
2536 THREADED_TEST(CallbackExceptionRegression) { 2532 THREADED_TEST(CallbackExceptionRegression) {
2537 v8::Isolate* isolate = CcTest::isolate(); 2533 v8::Isolate* isolate = CcTest::isolate();
2538 v8::HandleScope scope(isolate); 2534 v8::HandleScope scope(isolate);
2539 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); 2535 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
2540 obj->SetNamedPropertyHandler(ThrowingPropertyHandlerGet, 2536 obj->SetNamedPropertyHandler(ThrowingPropertyHandlerGet,
2541 ThrowingPropertyHandlerSet); 2537 ThrowingPropertyHandlerSet);
2542 LocalContext env; 2538 LocalContext env;
2543 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 2539 env->Global()->Set(v8_str("obj"), obj->NewInstance());
2544 v8::Handle<Value> otto = Script::Compile(v8_str( 2540 v8::Handle<Value> otto = CompileRun(
2545 "try { with (obj) { otto; } } catch (e) { e; }"))->Run(); 2541 "try { with (obj) { otto; } } catch (e) { e; }");
2546 CHECK_EQ(v8_str("otto"), otto); 2542 CHECK_EQ(v8_str("otto"), otto);
2547 v8::Handle<Value> netto = Script::Compile(v8_str( 2543 v8::Handle<Value> netto = CompileRun(
2548 "try { with (obj) { netto = 4; } } catch (e) { e; }"))->Run(); 2544 "try { with (obj) { netto = 4; } } catch (e) { e; }");
2549 CHECK_EQ(v8_str("netto"), netto); 2545 CHECK_EQ(v8_str("netto"), netto);
2550 } 2546 }
2551 2547
2552 2548
2553 THREADED_TEST(FunctionPrototype) { 2549 THREADED_TEST(FunctionPrototype) {
2554 v8::Isolate* isolate = CcTest::isolate(); 2550 v8::Isolate* isolate = CcTest::isolate();
2555 v8::HandleScope scope(isolate); 2551 v8::HandleScope scope(isolate);
2556 Local<v8::FunctionTemplate> Foo = v8::FunctionTemplate::New(isolate); 2552 Local<v8::FunctionTemplate> Foo = v8::FunctionTemplate::New(isolate);
2557 Foo->PrototypeTemplate()->Set(v8_str("plak"), v8_num(321)); 2553 Foo->PrototypeTemplate()->Set(v8_str("plak"), v8_num(321));
2558 LocalContext env; 2554 LocalContext env;
2559 env->Global()->Set(v8_str("Foo"), Foo->GetFunction()); 2555 env->Global()->Set(v8_str("Foo"), Foo->GetFunction());
2560 Local<Script> script = Script::Compile(v8_str("Foo.prototype.plak")); 2556 Local<Script> script = v8_compile("Foo.prototype.plak");
2561 CHECK_EQ(script->Run()->Int32Value(), 321); 2557 CHECK_EQ(script->Run()->Int32Value(), 321);
2562 } 2558 }
2563 2559
2564 2560
2565 THREADED_TEST(InternalFields) { 2561 THREADED_TEST(InternalFields) {
2566 LocalContext env; 2562 LocalContext env;
2567 v8::Isolate* isolate = env->GetIsolate(); 2563 v8::Isolate* isolate = env->GetIsolate();
2568 v8::HandleScope scope(isolate); 2564 v8::HandleScope scope(isolate);
2569 2565
2570 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); 2566 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
3272 CHECK(!interceptor_for_hidden_properties_called); 3268 CHECK(!interceptor_for_hidden_properties_called);
3273 } 3269 }
3274 3270
3275 3271
3276 THREADED_TEST(External) { 3272 THREADED_TEST(External) {
3277 v8::HandleScope scope(CcTest::isolate()); 3273 v8::HandleScope scope(CcTest::isolate());
3278 int x = 3; 3274 int x = 3;
3279 Local<v8::External> ext = v8::External::New(CcTest::isolate(), &x); 3275 Local<v8::External> ext = v8::External::New(CcTest::isolate(), &x);
3280 LocalContext env; 3276 LocalContext env;
3281 env->Global()->Set(v8_str("ext"), ext); 3277 env->Global()->Set(v8_str("ext"), ext);
3282 Local<Value> reext_obj = Script::Compile(v8_str("this.ext"))->Run(); 3278 Local<Value> reext_obj = CompileRun("this.ext");
3283 v8::Handle<v8::External> reext = reext_obj.As<v8::External>(); 3279 v8::Handle<v8::External> reext = reext_obj.As<v8::External>();
3284 int* ptr = static_cast<int*>(reext->Value()); 3280 int* ptr = static_cast<int*>(reext->Value());
3285 CHECK_EQ(x, 3); 3281 CHECK_EQ(x, 3);
3286 *ptr = 10; 3282 *ptr = 10;
3287 CHECK_EQ(x, 10); 3283 CHECK_EQ(x, 10);
3288 3284
3289 // Make sure unaligned pointers are wrapped properly. 3285 // Make sure unaligned pointers are wrapped properly.
3290 char* data = i::StrDup("0123456789"); 3286 char* data = i::StrDup("0123456789");
3291 Local<v8::Value> zero = v8::External::New(CcTest::isolate(), &data[0]); 3287 Local<v8::Value> zero = v8::External::New(CcTest::isolate(), &data[0]);
3292 Local<v8::Value> one = v8::External::New(CcTest::isolate(), &data[1]); 3288 Local<v8::Value> one = v8::External::New(CcTest::isolate(), &data[1]);
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
3943 heap->CollectGarbage(i::NEW_SPACE); 3939 heap->CollectGarbage(i::NEW_SPACE);
3944 3940
3945 // All objects should be gone. 7 global handles in total. 3941 // All objects should be gone. 7 global handles in total.
3946 CHECK_EQ(7, counter.NumberOfWeakCalls()); 3942 CHECK_EQ(7, counter.NumberOfWeakCalls());
3947 } 3943 }
3948 3944
3949 3945
3950 THREADED_TEST(ScriptException) { 3946 THREADED_TEST(ScriptException) {
3951 LocalContext env; 3947 LocalContext env;
3952 v8::HandleScope scope(env->GetIsolate()); 3948 v8::HandleScope scope(env->GetIsolate());
3953 Local<Script> script = Script::Compile(v8_str("throw 'panama!';")); 3949 Local<Script> script = v8_compile("throw 'panama!';");
3954 v8::TryCatch try_catch; 3950 v8::TryCatch try_catch;
3955 Local<Value> result = script->Run(); 3951 Local<Value> result = script->Run();
3956 CHECK(result.IsEmpty()); 3952 CHECK(result.IsEmpty());
3957 CHECK(try_catch.HasCaught()); 3953 CHECK(try_catch.HasCaught());
3958 String::Utf8Value exception_value(try_catch.Exception()); 3954 String::Utf8Value exception_value(try_catch.Exception());
3959 CHECK_EQ(*exception_value, "panama!"); 3955 CHECK_EQ(*exception_value, "panama!");
3960 } 3956 }
3961 3957
3962 3958
3963 TEST(TryCatchCustomException) { 3959 TEST(TryCatchCustomException) {
(...skipping 19 matching lines...) Expand all
3983 message_received = true; 3979 message_received = true;
3984 } 3980 }
3985 3981
3986 3982
3987 THREADED_TEST(MessageHandler0) { 3983 THREADED_TEST(MessageHandler0) {
3988 message_received = false; 3984 message_received = false;
3989 v8::HandleScope scope(CcTest::isolate()); 3985 v8::HandleScope scope(CcTest::isolate());
3990 CHECK(!message_received); 3986 CHECK(!message_received);
3991 LocalContext context; 3987 LocalContext context;
3992 v8::V8::AddMessageListener(check_message_0, v8_num(5.76)); 3988 v8::V8::AddMessageListener(check_message_0, v8_num(5.76));
3993 v8::ScriptOrigin origin = 3989 v8::Handle<v8::Script> script = CompileWithOrigin("throw 'error'", "6.75");
3994 v8::ScriptOrigin(v8_str("6.75"));
3995 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"),
3996 &origin);
3997 script->Run(); 3990 script->Run();
3998 CHECK(message_received); 3991 CHECK(message_received);
3999 // clear out the message listener 3992 // clear out the message listener
4000 v8::V8::RemoveMessageListeners(check_message_0); 3993 v8::V8::RemoveMessageListeners(check_message_0);
4001 } 3994 }
4002 3995
4003 3996
4004 static void check_message_1(v8::Handle<v8::Message> message, 3997 static void check_message_1(v8::Handle<v8::Message> message,
4005 v8::Handle<Value> data) { 3998 v8::Handle<Value> data) {
4006 CHECK(data->IsNumber()); 3999 CHECK(data->IsNumber());
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
4162 4155
4163 4156
4164 THREADED_TEST(GetSetProperty) { 4157 THREADED_TEST(GetSetProperty) {
4165 LocalContext context; 4158 LocalContext context;
4166 v8::Isolate* isolate = context->GetIsolate(); 4159 v8::Isolate* isolate = context->GetIsolate();
4167 v8::HandleScope scope(isolate); 4160 v8::HandleScope scope(isolate);
4168 context->Global()->Set(v8_str("foo"), v8_num(14)); 4161 context->Global()->Set(v8_str("foo"), v8_num(14));
4169 context->Global()->Set(v8_str("12"), v8_num(92)); 4162 context->Global()->Set(v8_str("12"), v8_num(92));
4170 context->Global()->Set(v8::Integer::New(isolate, 16), v8_num(32)); 4163 context->Global()->Set(v8::Integer::New(isolate, 16), v8_num(32));
4171 context->Global()->Set(v8_num(13), v8_num(56)); 4164 context->Global()->Set(v8_num(13), v8_num(56));
4172 Local<Value> foo = Script::Compile(v8_str("this.foo"))->Run(); 4165 Local<Value> foo = CompileRun("this.foo");
4173 CHECK_EQ(14, foo->Int32Value()); 4166 CHECK_EQ(14, foo->Int32Value());
4174 Local<Value> twelve = Script::Compile(v8_str("this[12]"))->Run(); 4167 Local<Value> twelve = CompileRun("this[12]");
4175 CHECK_EQ(92, twelve->Int32Value()); 4168 CHECK_EQ(92, twelve->Int32Value());
4176 Local<Value> sixteen = Script::Compile(v8_str("this[16]"))->Run(); 4169 Local<Value> sixteen = CompileRun("this[16]");
4177 CHECK_EQ(32, sixteen->Int32Value()); 4170 CHECK_EQ(32, sixteen->Int32Value());
4178 Local<Value> thirteen = Script::Compile(v8_str("this[13]"))->Run(); 4171 Local<Value> thirteen = CompileRun("this[13]");
4179 CHECK_EQ(56, thirteen->Int32Value()); 4172 CHECK_EQ(56, thirteen->Int32Value());
4180 CHECK_EQ(92, 4173 CHECK_EQ(92,
4181 context->Global()->Get(v8::Integer::New(isolate, 12))->Int32Value()); 4174 context->Global()->Get(v8::Integer::New(isolate, 12))->Int32Value());
4182 CHECK_EQ(92, context->Global()->Get(v8_str("12"))->Int32Value()); 4175 CHECK_EQ(92, context->Global()->Get(v8_str("12"))->Int32Value());
4183 CHECK_EQ(92, context->Global()->Get(v8_num(12))->Int32Value()); 4176 CHECK_EQ(92, context->Global()->Get(v8_num(12))->Int32Value());
4184 CHECK_EQ(32, 4177 CHECK_EQ(32,
4185 context->Global()->Get(v8::Integer::New(isolate, 16))->Int32Value()); 4178 context->Global()->Get(v8::Integer::New(isolate, 16))->Int32Value());
4186 CHECK_EQ(32, context->Global()->Get(v8_str("16"))->Int32Value()); 4179 CHECK_EQ(32, context->Global()->Get(v8_str("16"))->Int32Value());
4187 CHECK_EQ(32, context->Global()->Get(v8_num(16))->Int32Value()); 4180 CHECK_EQ(32, context->Global()->Get(v8_num(16))->Int32Value());
4188 CHECK_EQ(56, 4181 CHECK_EQ(56,
4189 context->Global()->Get(v8::Integer::New(isolate, 13))->Int32Value()); 4182 context->Global()->Get(v8::Integer::New(isolate, 13))->Int32Value());
4190 CHECK_EQ(56, context->Global()->Get(v8_str("13"))->Int32Value()); 4183 CHECK_EQ(56, context->Global()->Get(v8_str("13"))->Int32Value());
4191 CHECK_EQ(56, context->Global()->Get(v8_num(13))->Int32Value()); 4184 CHECK_EQ(56, context->Global()->Get(v8_num(13))->Int32Value());
4192 } 4185 }
4193 4186
4194 4187
4195 THREADED_TEST(PropertyAttributes) { 4188 THREADED_TEST(PropertyAttributes) {
4196 LocalContext context; 4189 LocalContext context;
4197 v8::HandleScope scope(context->GetIsolate()); 4190 v8::HandleScope scope(context->GetIsolate());
4198 // none 4191 // none
4199 Local<String> prop = v8_str("none"); 4192 Local<String> prop = v8_str("none");
4200 context->Global()->Set(prop, v8_num(7)); 4193 context->Global()->Set(prop, v8_num(7));
4201 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(prop)); 4194 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(prop));
4202 // read-only 4195 // read-only
4203 prop = v8_str("read_only"); 4196 prop = v8_str("read_only");
4204 context->Global()->Set(prop, v8_num(7), v8::ReadOnly); 4197 context->Global()->Set(prop, v8_num(7), v8::ReadOnly);
4205 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value()); 4198 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value());
4206 CHECK_EQ(v8::ReadOnly, context->Global()->GetPropertyAttributes(prop)); 4199 CHECK_EQ(v8::ReadOnly, context->Global()->GetPropertyAttributes(prop));
4207 Script::Compile(v8_str("read_only = 9"))->Run(); 4200 CompileRun("read_only = 9");
4208 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value()); 4201 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value());
4209 context->Global()->Set(prop, v8_num(10)); 4202 context->Global()->Set(prop, v8_num(10));
4210 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value()); 4203 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value());
4211 // dont-delete 4204 // dont-delete
4212 prop = v8_str("dont_delete"); 4205 prop = v8_str("dont_delete");
4213 context->Global()->Set(prop, v8_num(13), v8::DontDelete); 4206 context->Global()->Set(prop, v8_num(13), v8::DontDelete);
4214 CHECK_EQ(13, context->Global()->Get(prop)->Int32Value()); 4207 CHECK_EQ(13, context->Global()->Get(prop)->Int32Value());
4215 Script::Compile(v8_str("delete dont_delete"))->Run(); 4208 CompileRun("delete dont_delete");
4216 CHECK_EQ(13, context->Global()->Get(prop)->Int32Value()); 4209 CHECK_EQ(13, context->Global()->Get(prop)->Int32Value());
4217 CHECK_EQ(v8::DontDelete, context->Global()->GetPropertyAttributes(prop)); 4210 CHECK_EQ(v8::DontDelete, context->Global()->GetPropertyAttributes(prop));
4218 // dont-enum 4211 // dont-enum
4219 prop = v8_str("dont_enum"); 4212 prop = v8_str("dont_enum");
4220 context->Global()->Set(prop, v8_num(28), v8::DontEnum); 4213 context->Global()->Set(prop, v8_num(28), v8::DontEnum);
4221 CHECK_EQ(v8::DontEnum, context->Global()->GetPropertyAttributes(prop)); 4214 CHECK_EQ(v8::DontEnum, context->Global()->GetPropertyAttributes(prop));
4222 // absent 4215 // absent
4223 prop = v8_str("absent"); 4216 prop = v8_str("absent");
4224 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(prop)); 4217 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(prop));
4225 Local<Value> fake_prop = v8_num(1); 4218 Local<Value> fake_prop = v8_num(1);
(...skipping 18 matching lines...) Expand all
4244 CHECK(array->Get(0)->IsUndefined()); 4237 CHECK(array->Get(0)->IsUndefined());
4245 CHECK(!array->Has(0)); 4238 CHECK(!array->Has(0));
4246 CHECK(array->Get(100)->IsUndefined()); 4239 CHECK(array->Get(100)->IsUndefined());
4247 CHECK(!array->Has(100)); 4240 CHECK(!array->Has(100));
4248 array->Set(2, v8_num(7)); 4241 array->Set(2, v8_num(7));
4249 CHECK_EQ(3, array->Length()); 4242 CHECK_EQ(3, array->Length());
4250 CHECK(!array->Has(0)); 4243 CHECK(!array->Has(0));
4251 CHECK(!array->Has(1)); 4244 CHECK(!array->Has(1));
4252 CHECK(array->Has(2)); 4245 CHECK(array->Has(2));
4253 CHECK_EQ(7, array->Get(2)->Int32Value()); 4246 CHECK_EQ(7, array->Get(2)->Int32Value());
4254 Local<Value> obj = Script::Compile(v8_str("[1, 2, 3]"))->Run(); 4247 Local<Value> obj = CompileRun("[1, 2, 3]");
4255 Local<v8::Array> arr = obj.As<v8::Array>(); 4248 Local<v8::Array> arr = obj.As<v8::Array>();
4256 CHECK_EQ(3, arr->Length()); 4249 CHECK_EQ(3, arr->Length());
4257 CHECK_EQ(1, arr->Get(0)->Int32Value()); 4250 CHECK_EQ(1, arr->Get(0)->Int32Value());
4258 CHECK_EQ(2, arr->Get(1)->Int32Value()); 4251 CHECK_EQ(2, arr->Get(1)->Int32Value());
4259 CHECK_EQ(3, arr->Get(2)->Int32Value()); 4252 CHECK_EQ(3, arr->Get(2)->Int32Value());
4260 array = v8::Array::New(context->GetIsolate(), 27); 4253 array = v8::Array::New(context->GetIsolate(), 27);
4261 CHECK_EQ(27, array->Length()); 4254 CHECK_EQ(27, array->Length());
4262 array = v8::Array::New(context->GetIsolate(), -27); 4255 array = v8::Array::New(context->GetIsolate(), -27);
4263 CHECK_EQ(0, array->Length()); 4256 CHECK_EQ(0, array->Length());
4264 } 4257 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
4415 static const int K = 1024; 4408 static const int K = 1024;
4416 v8::ResourceConstraints constraints; 4409 v8::ResourceConstraints constraints;
4417 constraints.set_max_young_space_size(256 * K); 4410 constraints.set_max_young_space_size(256 * K);
4418 constraints.set_max_old_space_size(5 * K * K); 4411 constraints.set_max_old_space_size(5 * K * K);
4419 v8::SetResourceConstraints(CcTest::isolate(), &constraints); 4412 v8::SetResourceConstraints(CcTest::isolate(), &constraints);
4420 4413
4421 // Execute a script that causes out of memory. 4414 // Execute a script that causes out of memory.
4422 LocalContext context; 4415 LocalContext context;
4423 v8::HandleScope scope(context->GetIsolate()); 4416 v8::HandleScope scope(context->GetIsolate());
4424 v8::V8::IgnoreOutOfMemoryException(); 4417 v8::V8::IgnoreOutOfMemoryException();
4425 Local<Script> script = Script::Compile(String::NewFromUtf8( 4418 Local<Value> result = CompileRun(js_code_causing_out_of_memory);
4426 context->GetIsolate(), js_code_causing_out_of_memory));
4427 Local<Value> result = script->Run();
4428 4419
4429 // Check for out of memory state. 4420 // Check for out of memory state.
4430 CHECK(result.IsEmpty()); 4421 CHECK(result.IsEmpty());
4431 CHECK(context->HasOutOfMemoryException()); 4422 CHECK(context->HasOutOfMemoryException());
4432 } 4423 }
4433 4424
4434 4425
4435 void ProvokeOutOfMemory(const v8::FunctionCallbackInfo<v8::Value>& args) { 4426 void ProvokeOutOfMemory(const v8::FunctionCallbackInfo<v8::Value>& args) {
4436 ApiTestFuzzer::Fuzz(); 4427 ApiTestFuzzer::Fuzz();
4437 4428
4438 LocalContext context; 4429 LocalContext context;
4439 v8::HandleScope scope(context->GetIsolate()); 4430 v8::HandleScope scope(context->GetIsolate());
4440 Local<Script> script = Script::Compile(String::NewFromUtf8( 4431 Local<Value> result = CompileRun(js_code_causing_out_of_memory);
4441 context->GetIsolate(), js_code_causing_out_of_memory));
4442 Local<Value> result = script->Run();
4443 4432
4444 // Check for out of memory state. 4433 // Check for out of memory state.
4445 CHECK(result.IsEmpty()); 4434 CHECK(result.IsEmpty());
4446 CHECK(context->HasOutOfMemoryException()); 4435 CHECK(context->HasOutOfMemoryException());
4447 4436
4448 args.GetReturnValue().Set(result); 4437 args.GetReturnValue().Set(result);
4449 } 4438 }
4450 4439
4451 4440
4452 TEST(OutOfMemoryNested) { 4441 TEST(OutOfMemoryNested) {
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
4730 } 4719 }
4731 4720
4732 4721
4733 void CCatcher(const v8::FunctionCallbackInfo<v8::Value>& args) { 4722 void CCatcher(const v8::FunctionCallbackInfo<v8::Value>& args) {
4734 if (args.Length() < 1) { 4723 if (args.Length() < 1) {
4735 args.GetReturnValue().Set(false); 4724 args.GetReturnValue().Set(false);
4736 return; 4725 return;
4737 } 4726 }
4738 v8::HandleScope scope(args.GetIsolate()); 4727 v8::HandleScope scope(args.GetIsolate());
4739 v8::TryCatch try_catch; 4728 v8::TryCatch try_catch;
4740 Local<Value> result = v8::Script::Compile(args[0]->ToString())->Run(); 4729 Local<Value> result = CompileRun(args[0]->ToString());
4741 CHECK(!try_catch.HasCaught() || result.IsEmpty()); 4730 CHECK(!try_catch.HasCaught() || result.IsEmpty());
4742 args.GetReturnValue().Set(try_catch.HasCaught()); 4731 args.GetReturnValue().Set(try_catch.HasCaught());
4743 } 4732 }
4744 4733
4745 4734
4746 THREADED_TEST(APICatch) { 4735 THREADED_TEST(APICatch) {
4747 v8::Isolate* isolate = CcTest::isolate(); 4736 v8::Isolate* isolate = CcTest::isolate();
4748 v8::HandleScope scope(isolate); 4737 v8::HandleScope scope(isolate);
4749 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 4738 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
4750 templ->Set(v8_str("ThrowFromC"), 4739 templ->Set(v8_str("ThrowFromC"),
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
4992 4981
4993 THREADED_TEST(ExternalScriptException) { 4982 THREADED_TEST(ExternalScriptException) {
4994 v8::Isolate* isolate = CcTest::isolate(); 4983 v8::Isolate* isolate = CcTest::isolate();
4995 v8::HandleScope scope(isolate); 4984 v8::HandleScope scope(isolate);
4996 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 4985 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
4997 templ->Set(v8_str("ThrowFromC"), 4986 templ->Set(v8_str("ThrowFromC"),
4998 v8::FunctionTemplate::New(isolate, ThrowFromC)); 4987 v8::FunctionTemplate::New(isolate, ThrowFromC));
4999 LocalContext context(0, templ); 4988 LocalContext context(0, templ);
5000 4989
5001 v8::TryCatch try_catch; 4990 v8::TryCatch try_catch;
5002 Local<Script> script 4991 Local<Value> result = CompileRun("ThrowFromC(); throw 'panama';");
5003 = Script::Compile(v8_str("ThrowFromC(); throw 'panama';"));
5004 Local<Value> result = script->Run();
5005 CHECK(result.IsEmpty()); 4992 CHECK(result.IsEmpty());
5006 CHECK(try_catch.HasCaught()); 4993 CHECK(try_catch.HasCaught());
5007 String::Utf8Value exception_value(try_catch.Exception()); 4994 String::Utf8Value exception_value(try_catch.Exception());
5008 CHECK_EQ("konto", *exception_value); 4995 CHECK_EQ("konto", *exception_value);
5009 } 4996 }
5010 4997
5011 4998
5012 4999
5013 void CThrowCountDown(const v8::FunctionCallbackInfo<v8::Value>& args) { 5000 void CThrowCountDown(const v8::FunctionCallbackInfo<v8::Value>& args) {
5014 ApiTestFuzzer::Fuzz(); 5001 ApiTestFuzzer::Fuzz();
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
5186 CHECK(result->Get(v8::Integer::New(isolate, 3))->IsNull()); 5173 CHECK(result->Get(v8::Integer::New(isolate, 3))->IsNull());
5187 CHECK(result->Get(v8::Integer::New(isolate, 4))->IsUndefined()); 5174 CHECK(result->Get(v8::Integer::New(isolate, 4))->IsUndefined());
5188 } 5175 }
5189 5176
5190 5177
5191 THREADED_TEST(CatchZero) { 5178 THREADED_TEST(CatchZero) {
5192 LocalContext context; 5179 LocalContext context;
5193 v8::HandleScope scope(context->GetIsolate()); 5180 v8::HandleScope scope(context->GetIsolate());
5194 v8::TryCatch try_catch; 5181 v8::TryCatch try_catch;
5195 CHECK(!try_catch.HasCaught()); 5182 CHECK(!try_catch.HasCaught());
5196 Script::Compile(v8_str("throw 10"))->Run(); 5183 CompileRun("throw 10");
5197 CHECK(try_catch.HasCaught()); 5184 CHECK(try_catch.HasCaught());
5198 CHECK_EQ(10, try_catch.Exception()->Int32Value()); 5185 CHECK_EQ(10, try_catch.Exception()->Int32Value());
5199 try_catch.Reset(); 5186 try_catch.Reset();
5200 CHECK(!try_catch.HasCaught()); 5187 CHECK(!try_catch.HasCaught());
5201 Script::Compile(v8_str("throw 0"))->Run(); 5188 CompileRun("throw 0");
5202 CHECK(try_catch.HasCaught()); 5189 CHECK(try_catch.HasCaught());
5203 CHECK_EQ(0, try_catch.Exception()->Int32Value()); 5190 CHECK_EQ(0, try_catch.Exception()->Int32Value());
5204 } 5191 }
5205 5192
5206 5193
5207 THREADED_TEST(CatchExceptionFromWith) { 5194 THREADED_TEST(CatchExceptionFromWith) {
5208 LocalContext context; 5195 LocalContext context;
5209 v8::HandleScope scope(context->GetIsolate()); 5196 v8::HandleScope scope(context->GetIsolate());
5210 v8::TryCatch try_catch; 5197 v8::TryCatch try_catch;
5211 CHECK(!try_catch.HasCaught()); 5198 CHECK(!try_catch.HasCaught());
5212 Script::Compile(v8_str("var o = {}; with (o) { throw 42; }"))->Run(); 5199 CompileRun("var o = {}; with (o) { throw 42; }");
5213 CHECK(try_catch.HasCaught()); 5200 CHECK(try_catch.HasCaught());
5214 } 5201 }
5215 5202
5216 5203
5217 THREADED_TEST(TryCatchAndFinallyHidingException) { 5204 THREADED_TEST(TryCatchAndFinallyHidingException) {
5218 LocalContext context; 5205 LocalContext context;
5219 v8::HandleScope scope(context->GetIsolate()); 5206 v8::HandleScope scope(context->GetIsolate());
5220 v8::TryCatch try_catch; 5207 v8::TryCatch try_catch;
5221 CHECK(!try_catch.HasCaught()); 5208 CHECK(!try_catch.HasCaught());
5222 CompileRun("function f(k) { try { this[k]; } finally { return 0; } };"); 5209 CompileRun("function f(k) { try { this[k]; } finally { return 0; } };");
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
5354 CHECK(!v8_num(0.0)->SameValue(v8_num(-0.0))); 5341 CHECK(!v8_num(0.0)->SameValue(v8_num(-0.0)));
5355 CHECK(not_a_number->SameValue(not_a_number)); 5342 CHECK(not_a_number->SameValue(not_a_number));
5356 CHECK(v8::False(isolate)->SameValue(v8::False(isolate))); 5343 CHECK(v8::False(isolate)->SameValue(v8::False(isolate)));
5357 CHECK(!v8::False(isolate)->SameValue(v8::Undefined(isolate))); 5344 CHECK(!v8::False(isolate)->SameValue(v8::Undefined(isolate)));
5358 } 5345 }
5359 5346
5360 5347
5361 THREADED_TEST(MultiRun) { 5348 THREADED_TEST(MultiRun) {
5362 LocalContext context; 5349 LocalContext context;
5363 v8::HandleScope scope(context->GetIsolate()); 5350 v8::HandleScope scope(context->GetIsolate());
5364 Local<Script> script = Script::Compile(v8_str("x")); 5351 Local<Script> script = v8_compile("x");
5365 for (int i = 0; i < 10; i++) 5352 for (int i = 0; i < 10; i++)
5366 script->Run(); 5353 script->Run();
5367 } 5354 }
5368 5355
5369 5356
5370 static void GetXValue(Local<String> name, 5357 static void GetXValue(Local<String> name,
5371 const v8::PropertyCallbackInfo<v8::Value>& info) { 5358 const v8::PropertyCallbackInfo<v8::Value>& info) {
5372 ApiTestFuzzer::Fuzz(); 5359 ApiTestFuzzer::Fuzz();
5373 CHECK_EQ(info.Data(), v8_str("donut")); 5360 CHECK_EQ(info.Data(), v8_str("donut"));
5374 CHECK_EQ(name, v8_str("x")); 5361 CHECK_EQ(name, v8_str("x"));
5375 info.GetReturnValue().Set(name); 5362 info.GetReturnValue().Set(name);
5376 } 5363 }
5377 5364
5378 5365
5379 THREADED_TEST(SimplePropertyRead) { 5366 THREADED_TEST(SimplePropertyRead) {
5380 LocalContext context; 5367 LocalContext context;
5381 v8::Isolate* isolate = context->GetIsolate(); 5368 v8::Isolate* isolate = context->GetIsolate();
5382 v8::HandleScope scope(isolate); 5369 v8::HandleScope scope(isolate);
5383 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 5370 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5384 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); 5371 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"));
5385 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5372 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5386 Local<Script> script = Script::Compile(v8_str("obj.x")); 5373 Local<Script> script = v8_compile("obj.x");
5387 for (int i = 0; i < 10; i++) { 5374 for (int i = 0; i < 10; i++) {
5388 Local<Value> result = script->Run(); 5375 Local<Value> result = script->Run();
5389 CHECK_EQ(result, v8_str("x")); 5376 CHECK_EQ(result, v8_str("x"));
5390 } 5377 }
5391 } 5378 }
5392 5379
5393 5380
5394 THREADED_TEST(DefinePropertyOnAPIAccessor) { 5381 THREADED_TEST(DefinePropertyOnAPIAccessor) {
5395 LocalContext context; 5382 LocalContext context;
5396 v8::Isolate* isolate = context->GetIsolate(); 5383 v8::Isolate* isolate = context->GetIsolate();
5397 v8::HandleScope scope(isolate); 5384 v8::HandleScope scope(isolate);
5398 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 5385 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5399 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); 5386 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"));
5400 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5387 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5401 5388
5402 // Uses getOwnPropertyDescriptor to check the configurable status 5389 // Uses getOwnPropertyDescriptor to check the configurable status
5403 Local<Script> script_desc 5390 Local<Script> script_desc = v8_compile(
5404 = Script::Compile(v8_str("var prop = Object.getOwnPropertyDescriptor( " 5391 "var prop = Object.getOwnPropertyDescriptor( "
5405 "obj, 'x');" 5392 "obj, 'x');"
5406 "prop.configurable;")); 5393 "prop.configurable;");
5407 Local<Value> result = script_desc->Run(); 5394 Local<Value> result = script_desc->Run();
5408 CHECK_EQ(result->BooleanValue(), true); 5395 CHECK_EQ(result->BooleanValue(), true);
5409 5396
5410 // Redefine get - but still configurable 5397 // Redefine get - but still configurable
5411 Local<Script> script_define 5398 Local<Script> script_define = v8_compile(
5412 = Script::Compile(v8_str("var desc = { get: function(){return 42; }," 5399 "var desc = { get: function(){return 42; },"
5413 " configurable: true };" 5400 " configurable: true };"
5414 "Object.defineProperty(obj, 'x', desc);" 5401 "Object.defineProperty(obj, 'x', desc);"
5415 "obj.x")); 5402 "obj.x");
5416 result = script_define->Run(); 5403 result = script_define->Run();
5417 CHECK_EQ(result, v8_num(42)); 5404 CHECK_EQ(result, v8_num(42));
5418 5405
5419 // Check that the accessor is still configurable 5406 // Check that the accessor is still configurable
5420 result = script_desc->Run(); 5407 result = script_desc->Run();
5421 CHECK_EQ(result->BooleanValue(), true); 5408 CHECK_EQ(result->BooleanValue(), true);
5422 5409
5423 // Redefine to a non-configurable 5410 // Redefine to a non-configurable
5424 script_define 5411 script_define = v8_compile(
5425 = Script::Compile(v8_str("var desc = { get: function(){return 43; }," 5412 "var desc = { get: function(){return 43; },"
5426 " configurable: false };" 5413 " configurable: false };"
5427 "Object.defineProperty(obj, 'x', desc);" 5414 "Object.defineProperty(obj, 'x', desc);"
5428 "obj.x")); 5415 "obj.x");
5429 result = script_define->Run(); 5416 result = script_define->Run();
5430 CHECK_EQ(result, v8_num(43)); 5417 CHECK_EQ(result, v8_num(43));
5431 result = script_desc->Run(); 5418 result = script_desc->Run();
5432 CHECK_EQ(result->BooleanValue(), false); 5419 CHECK_EQ(result->BooleanValue(), false);
5433 5420
5434 // Make sure that it is not possible to redefine again 5421 // Make sure that it is not possible to redefine again
5435 v8::TryCatch try_catch; 5422 v8::TryCatch try_catch;
5436 result = script_define->Run(); 5423 result = script_define->Run();
5437 CHECK(try_catch.HasCaught()); 5424 CHECK(try_catch.HasCaught());
5438 String::Utf8Value exception_value(try_catch.Exception()); 5425 String::Utf8Value exception_value(try_catch.Exception());
5439 CHECK_EQ(*exception_value, "TypeError: Cannot redefine property: x"); 5426 CHECK_EQ(*exception_value, "TypeError: Cannot redefine property: x");
5440 } 5427 }
5441 5428
5442 5429
5443 THREADED_TEST(DefinePropertyOnDefineGetterSetter) { 5430 THREADED_TEST(DefinePropertyOnDefineGetterSetter) {
5444 v8::Isolate* isolate = CcTest::isolate(); 5431 v8::Isolate* isolate = CcTest::isolate();
5445 v8::HandleScope scope(isolate); 5432 v8::HandleScope scope(isolate);
5446 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 5433 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5447 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); 5434 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"));
5448 LocalContext context; 5435 LocalContext context;
5449 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5436 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5450 5437
5451 Local<Script> script_desc = Script::Compile(v8_str("var prop =" 5438 Local<Script> script_desc = v8_compile(
5452 "Object.getOwnPropertyDescriptor( " 5439 "var prop ="
5453 "obj, 'x');" 5440 "Object.getOwnPropertyDescriptor( "
5454 "prop.configurable;")); 5441 "obj, 'x');"
5442 "prop.configurable;");
5455 Local<Value> result = script_desc->Run(); 5443 Local<Value> result = script_desc->Run();
5456 CHECK_EQ(result->BooleanValue(), true); 5444 CHECK_EQ(result->BooleanValue(), true);
5457 5445
5458 Local<Script> script_define = 5446 Local<Script> script_define = v8_compile(
5459 Script::Compile(v8_str("var desc = {get: function(){return 42; }," 5447 "var desc = {get: function(){return 42; },"
5460 " configurable: true };" 5448 " configurable: true };"
5461 "Object.defineProperty(obj, 'x', desc);" 5449 "Object.defineProperty(obj, 'x', desc);"
5462 "obj.x")); 5450 "obj.x");
5463 result = script_define->Run(); 5451 result = script_define->Run();
5464 CHECK_EQ(result, v8_num(42)); 5452 CHECK_EQ(result, v8_num(42));
5465 5453
5466 5454
5467 result = script_desc->Run(); 5455 result = script_desc->Run();
5468 CHECK_EQ(result->BooleanValue(), true); 5456 CHECK_EQ(result->BooleanValue(), true);
5469 5457
5470 5458
5471 script_define = 5459 script_define = v8_compile(
5472 Script::Compile(v8_str("var desc = {get: function(){return 43; }," 5460 "var desc = {get: function(){return 43; },"
5473 " configurable: false };" 5461 " configurable: false };"
5474 "Object.defineProperty(obj, 'x', desc);" 5462 "Object.defineProperty(obj, 'x', desc);"
5475 "obj.x")); 5463 "obj.x");
5476 result = script_define->Run(); 5464 result = script_define->Run();
5477 CHECK_EQ(result, v8_num(43)); 5465 CHECK_EQ(result, v8_num(43));
5478 result = script_desc->Run(); 5466 result = script_desc->Run();
5479 5467
5480 CHECK_EQ(result->BooleanValue(), false); 5468 CHECK_EQ(result->BooleanValue(), false);
5481 5469
5482 v8::TryCatch try_catch; 5470 v8::TryCatch try_catch;
5483 result = script_define->Run(); 5471 result = script_define->Run();
5484 CHECK(try_catch.HasCaught()); 5472 CHECK(try_catch.HasCaught());
5485 String::Utf8Value exception_value(try_catch.Exception()); 5473 String::Utf8Value exception_value(try_catch.Exception());
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
5664 } 5652 }
5665 5653
5666 5654
5667 THREADED_TEST(SimplePropertyWrite) { 5655 THREADED_TEST(SimplePropertyWrite) {
5668 v8::Isolate* isolate = CcTest::isolate(); 5656 v8::Isolate* isolate = CcTest::isolate();
5669 v8::HandleScope scope(isolate); 5657 v8::HandleScope scope(isolate);
5670 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 5658 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5671 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut")); 5659 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut"));
5672 LocalContext context; 5660 LocalContext context;
5673 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5661 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5674 Local<Script> script = Script::Compile(v8_str("obj.x = 4")); 5662 Local<Script> script = v8_compile("obj.x = 4");
5675 for (int i = 0; i < 10; i++) { 5663 for (int i = 0; i < 10; i++) {
5676 CHECK(xValue.IsEmpty()); 5664 CHECK(xValue.IsEmpty());
5677 script->Run(); 5665 script->Run();
5678 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue)); 5666 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue));
5679 xValue.Reset(); 5667 xValue.Reset();
5680 } 5668 }
5681 } 5669 }
5682 5670
5683 5671
5684 THREADED_TEST(SetterOnly) { 5672 THREADED_TEST(SetterOnly) {
5685 v8::Isolate* isolate = CcTest::isolate(); 5673 v8::Isolate* isolate = CcTest::isolate();
5686 v8::HandleScope scope(isolate); 5674 v8::HandleScope scope(isolate);
5687 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 5675 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5688 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut")); 5676 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut"));
5689 LocalContext context; 5677 LocalContext context;
5690 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5678 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5691 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); 5679 Local<Script> script = v8_compile("obj.x = 4; obj.x");
5692 for (int i = 0; i < 10; i++) { 5680 for (int i = 0; i < 10; i++) {
5693 CHECK(xValue.IsEmpty()); 5681 CHECK(xValue.IsEmpty());
5694 script->Run(); 5682 script->Run();
5695 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue)); 5683 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue));
5696 xValue.Reset(); 5684 xValue.Reset();
5697 } 5685 }
5698 } 5686 }
5699 5687
5700 5688
5701 THREADED_TEST(NoAccessors) { 5689 THREADED_TEST(NoAccessors) {
5702 v8::Isolate* isolate = CcTest::isolate(); 5690 v8::Isolate* isolate = CcTest::isolate();
5703 v8::HandleScope scope(isolate); 5691 v8::HandleScope scope(isolate);
5704 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 5692 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5705 templ->SetAccessor(v8_str("x"), 5693 templ->SetAccessor(v8_str("x"),
5706 static_cast<v8::AccessorGetterCallback>(NULL), 5694 static_cast<v8::AccessorGetterCallback>(NULL),
5707 NULL, 5695 NULL,
5708 v8_str("donut")); 5696 v8_str("donut"));
5709 LocalContext context; 5697 LocalContext context;
5710 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5698 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5711 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); 5699 Local<Script> script = v8_compile("obj.x = 4; obj.x");
5712 for (int i = 0; i < 10; i++) { 5700 for (int i = 0; i < 10; i++) {
5713 script->Run(); 5701 script->Run();
5714 } 5702 }
5715 } 5703 }
5716 5704
5717 5705
5718 static void XPropertyGetter(Local<String> property, 5706 static void XPropertyGetter(Local<String> property,
5719 const v8::PropertyCallbackInfo<v8::Value>& info) { 5707 const v8::PropertyCallbackInfo<v8::Value>& info) {
5720 ApiTestFuzzer::Fuzz(); 5708 ApiTestFuzzer::Fuzz();
5721 CHECK(info.Data()->IsUndefined()); 5709 CHECK(info.Data()->IsUndefined());
5722 info.GetReturnValue().Set(property); 5710 info.GetReturnValue().Set(property);
5723 } 5711 }
5724 5712
5725 5713
5726 THREADED_TEST(NamedInterceptorPropertyRead) { 5714 THREADED_TEST(NamedInterceptorPropertyRead) {
5727 v8::Isolate* isolate = CcTest::isolate(); 5715 v8::Isolate* isolate = CcTest::isolate();
5728 v8::HandleScope scope(isolate); 5716 v8::HandleScope scope(isolate);
5729 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 5717 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5730 templ->SetNamedPropertyHandler(XPropertyGetter); 5718 templ->SetNamedPropertyHandler(XPropertyGetter);
5731 LocalContext context; 5719 LocalContext context;
5732 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5720 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5733 Local<Script> script = Script::Compile(v8_str("obj.x")); 5721 Local<Script> script = v8_compile("obj.x");
5734 for (int i = 0; i < 10; i++) { 5722 for (int i = 0; i < 10; i++) {
5735 Local<Value> result = script->Run(); 5723 Local<Value> result = script->Run();
5736 CHECK_EQ(result, v8_str("x")); 5724 CHECK_EQ(result, v8_str("x"));
5737 } 5725 }
5738 } 5726 }
5739 5727
5740 5728
5741 THREADED_TEST(NamedInterceptorDictionaryIC) { 5729 THREADED_TEST(NamedInterceptorDictionaryIC) {
5742 v8::Isolate* isolate = CcTest::isolate(); 5730 v8::Isolate* isolate = CcTest::isolate();
5743 v8::HandleScope scope(isolate); 5731 v8::HandleScope scope(isolate);
5744 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 5732 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5745 templ->SetNamedPropertyHandler(XPropertyGetter); 5733 templ->SetNamedPropertyHandler(XPropertyGetter);
5746 LocalContext context; 5734 LocalContext context;
5747 // Create an object with a named interceptor. 5735 // Create an object with a named interceptor.
5748 context->Global()->Set(v8_str("interceptor_obj"), templ->NewInstance()); 5736 context->Global()->Set(v8_str("interceptor_obj"), templ->NewInstance());
5749 Local<Script> script = Script::Compile(v8_str("interceptor_obj.x")); 5737 Local<Script> script = v8_compile("interceptor_obj.x");
5750 for (int i = 0; i < 10; i++) { 5738 for (int i = 0; i < 10; i++) {
5751 Local<Value> result = script->Run(); 5739 Local<Value> result = script->Run();
5752 CHECK_EQ(result, v8_str("x")); 5740 CHECK_EQ(result, v8_str("x"));
5753 } 5741 }
5754 // Create a slow case object and a function accessing a property in 5742 // Create a slow case object and a function accessing a property in
5755 // that slow case object (with dictionary probing in generated 5743 // that slow case object (with dictionary probing in generated
5756 // code). Then force object with a named interceptor into slow-case, 5744 // code). Then force object with a named interceptor into slow-case,
5757 // pass it to the function, and check that the interceptor is called 5745 // pass it to the function, and check that the interceptor is called
5758 // instead of accessing the local property. 5746 // instead of accessing the local property.
5759 Local<Value> result = 5747 Local<Value> result =
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
5862 5850
5863 5851
5864 THREADED_TEST(IndexedInterceptorWithIndexedAccessor) { 5852 THREADED_TEST(IndexedInterceptorWithIndexedAccessor) {
5865 v8::Isolate* isolate = CcTest::isolate(); 5853 v8::Isolate* isolate = CcTest::isolate();
5866 v8::HandleScope scope(isolate); 5854 v8::HandleScope scope(isolate);
5867 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 5855 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5868 templ->SetIndexedPropertyHandler(IndexedPropertyGetter, 5856 templ->SetIndexedPropertyHandler(IndexedPropertyGetter,
5869 IndexedPropertySetter); 5857 IndexedPropertySetter);
5870 LocalContext context; 5858 LocalContext context;
5871 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5859 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5872 Local<Script> getter_script = Script::Compile(v8_str( 5860 Local<Script> getter_script = v8_compile(
5873 "obj.__defineGetter__(\"3\", function(){return 5;});obj[3];")); 5861 "obj.__defineGetter__(\"3\", function(){return 5;});obj[3];");
5874 Local<Script> setter_script = Script::Compile(v8_str( 5862 Local<Script> setter_script = v8_compile(
5875 "obj.__defineSetter__(\"17\", function(val){this.foo = val;});" 5863 "obj.__defineSetter__(\"17\", function(val){this.foo = val;});"
5876 "obj[17] = 23;" 5864 "obj[17] = 23;"
5877 "obj.foo;")); 5865 "obj.foo;");
5878 Local<Script> interceptor_setter_script = Script::Compile(v8_str( 5866 Local<Script> interceptor_setter_script = v8_compile(
5879 "obj.__defineSetter__(\"39\", function(val){this.foo = \"hit\";});" 5867 "obj.__defineSetter__(\"39\", function(val){this.foo = \"hit\";});"
5880 "obj[39] = 47;" 5868 "obj[39] = 47;"
5881 "obj.foo;")); // This setter should not run, due to the interceptor. 5869 "obj.foo;"); // This setter should not run, due to the interceptor.
5882 Local<Script> interceptor_getter_script = Script::Compile(v8_str( 5870 Local<Script> interceptor_getter_script = v8_compile(
5883 "obj[37];")); 5871 "obj[37];");
5884 Local<Value> result = getter_script->Run(); 5872 Local<Value> result = getter_script->Run();
5885 CHECK_EQ(v8_num(5), result); 5873 CHECK_EQ(v8_num(5), result);
5886 result = setter_script->Run(); 5874 result = setter_script->Run();
5887 CHECK_EQ(v8_num(23), result); 5875 CHECK_EQ(v8_num(23), result);
5888 result = interceptor_setter_script->Run(); 5876 result = interceptor_setter_script->Run();
5889 CHECK_EQ(v8_num(23), result); 5877 CHECK_EQ(v8_num(23), result);
5890 result = interceptor_getter_script->Run(); 5878 result = interceptor_getter_script->Run();
5891 CHECK_EQ(v8_num(625), result); 5879 CHECK_EQ(v8_num(625), result);
5892 } 5880 }
5893 5881
(...skipping 15 matching lines...) Expand all
5909 ApiTestFuzzer::Fuzz(); 5897 ApiTestFuzzer::Fuzz();
5910 if (index < 25) { 5898 if (index < 25) {
5911 info.GetReturnValue().Set(v8_num(index)); 5899 info.GetReturnValue().Set(v8_num(index));
5912 } 5900 }
5913 } 5901 }
5914 5902
5915 5903
5916 void UnboxedDoubleIndexedPropertyEnumerator( 5904 void UnboxedDoubleIndexedPropertyEnumerator(
5917 const v8::PropertyCallbackInfo<v8::Array>& info) { 5905 const v8::PropertyCallbackInfo<v8::Array>& info) {
5918 // Force the list of returned keys to be stored in a FastDoubleArray. 5906 // Force the list of returned keys to be stored in a FastDoubleArray.
5919 Local<Script> indexed_property_names_script = Script::Compile(v8_str( 5907 Local<Script> indexed_property_names_script = v8_compile(
5920 "keys = new Array(); keys[125000] = 1;" 5908 "keys = new Array(); keys[125000] = 1;"
5921 "for(i = 0; i < 80000; i++) { keys[i] = i; };" 5909 "for(i = 0; i < 80000; i++) { keys[i] = i; };"
5922 "keys.length = 25; keys;")); 5910 "keys.length = 25; keys;");
5923 Local<Value> result = indexed_property_names_script->Run(); 5911 Local<Value> result = indexed_property_names_script->Run();
5924 info.GetReturnValue().Set(Local<v8::Array>::Cast(result)); 5912 info.GetReturnValue().Set(Local<v8::Array>::Cast(result));
5925 } 5913 }
5926 5914
5927 5915
5928 // Make sure that the the interceptor code in the runtime properly handles 5916 // Make sure that the the interceptor code in the runtime properly handles
5929 // merging property name lists for double-array-backed arrays. 5917 // merging property name lists for double-array-backed arrays.
5930 THREADED_TEST(IndexedInterceptorUnboxedDoubleWithIndexedAccessor) { 5918 THREADED_TEST(IndexedInterceptorUnboxedDoubleWithIndexedAccessor) {
5931 v8::Isolate* isolate = CcTest::isolate(); 5919 v8::Isolate* isolate = CcTest::isolate();
5932 v8::HandleScope scope(isolate); 5920 v8::HandleScope scope(isolate);
5933 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 5921 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5934 templ->SetIndexedPropertyHandler(UnboxedDoubleIndexedPropertyGetter, 5922 templ->SetIndexedPropertyHandler(UnboxedDoubleIndexedPropertyGetter,
5935 UnboxedDoubleIndexedPropertySetter, 5923 UnboxedDoubleIndexedPropertySetter,
5936 0, 5924 0,
5937 0, 5925 0,
5938 UnboxedDoubleIndexedPropertyEnumerator); 5926 UnboxedDoubleIndexedPropertyEnumerator);
5939 LocalContext context; 5927 LocalContext context;
5940 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5928 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5941 // When obj is created, force it to be Stored in a FastDoubleArray. 5929 // When obj is created, force it to be Stored in a FastDoubleArray.
5942 Local<Script> create_unboxed_double_script = Script::Compile(v8_str( 5930 Local<Script> create_unboxed_double_script = v8_compile(
5943 "obj[125000] = 1; for(i = 0; i < 80000; i+=2) { obj[i] = i; } " 5931 "obj[125000] = 1; for(i = 0; i < 80000; i+=2) { obj[i] = i; } "
5944 "key_count = 0; " 5932 "key_count = 0; "
5945 "for (x in obj) {key_count++;};" 5933 "for (x in obj) {key_count++;};"
5946 "obj;")); 5934 "obj;");
5947 Local<Value> result = create_unboxed_double_script->Run(); 5935 Local<Value> result = create_unboxed_double_script->Run();
5948 CHECK(result->ToObject()->HasRealIndexedProperty(2000)); 5936 CHECK(result->ToObject()->HasRealIndexedProperty(2000));
5949 Local<Script> key_count_check = Script::Compile(v8_str( 5937 Local<Script> key_count_check = v8_compile("key_count;");
5950 "key_count;"));
5951 result = key_count_check->Run(); 5938 result = key_count_check->Run();
5952 CHECK_EQ(v8_num(40013), result); 5939 CHECK_EQ(v8_num(40013), result);
5953 } 5940 }
5954 5941
5955 5942
5956 void NonStrictArgsIndexedPropertyEnumerator( 5943 void NonStrictArgsIndexedPropertyEnumerator(
5957 const v8::PropertyCallbackInfo<v8::Array>& info) { 5944 const v8::PropertyCallbackInfo<v8::Array>& info) {
5958 // Force the list of returned keys to be stored in a Arguments object. 5945 // Force the list of returned keys to be stored in a Arguments object.
5959 Local<Script> indexed_property_names_script = Script::Compile(v8_str( 5946 Local<Script> indexed_property_names_script = v8_compile(
5960 "function f(w,x) {" 5947 "function f(w,x) {"
5961 " return arguments;" 5948 " return arguments;"
5962 "}" 5949 "}"
5963 "keys = f(0, 1, 2, 3);" 5950 "keys = f(0, 1, 2, 3);"
5964 "keys;")); 5951 "keys;");
5965 Local<Object> result = 5952 Local<Object> result =
5966 Local<Object>::Cast(indexed_property_names_script->Run()); 5953 Local<Object>::Cast(indexed_property_names_script->Run());
5967 // Have to populate the handle manually, as it's not Cast-able. 5954 // Have to populate the handle manually, as it's not Cast-able.
5968 i::Handle<i::JSObject> o = 5955 i::Handle<i::JSObject> o =
5969 v8::Utils::OpenHandle<Object, i::JSObject>(result); 5956 v8::Utils::OpenHandle<Object, i::JSObject>(result);
5970 i::Handle<i::JSArray> array(reinterpret_cast<i::JSArray*>(*o)); 5957 i::Handle<i::JSArray> array(reinterpret_cast<i::JSArray*>(*o));
5971 info.GetReturnValue().Set(v8::Utils::ToLocal(array)); 5958 info.GetReturnValue().Set(v8::Utils::ToLocal(array));
5972 } 5959 }
5973 5960
5974 5961
(...skipping 13 matching lines...) Expand all
5988 v8::Isolate* isolate = CcTest::isolate(); 5975 v8::Isolate* isolate = CcTest::isolate();
5989 v8::HandleScope scope(isolate); 5976 v8::HandleScope scope(isolate);
5990 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 5977 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5991 templ->SetIndexedPropertyHandler(NonStrictIndexedPropertyGetter, 5978 templ->SetIndexedPropertyHandler(NonStrictIndexedPropertyGetter,
5992 0, 5979 0,
5993 0, 5980 0,
5994 0, 5981 0,
5995 NonStrictArgsIndexedPropertyEnumerator); 5982 NonStrictArgsIndexedPropertyEnumerator);
5996 LocalContext context; 5983 LocalContext context;
5997 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5984 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5998 Local<Script> create_args_script = 5985 Local<Script> create_args_script = v8_compile(
5999 Script::Compile(v8_str( 5986 "var key_count = 0;"
6000 "var key_count = 0;" 5987 "for (x in obj) {key_count++;} key_count;");
6001 "for (x in obj) {key_count++;} key_count;"));
6002 Local<Value> result = create_args_script->Run(); 5988 Local<Value> result = create_args_script->Run();
6003 CHECK_EQ(v8_num(4), result); 5989 CHECK_EQ(v8_num(4), result);
6004 } 5990 }
6005 5991
6006 5992
6007 static void IdentityIndexedPropertyGetter( 5993 static void IdentityIndexedPropertyGetter(
6008 uint32_t index, 5994 uint32_t index,
6009 const v8::PropertyCallbackInfo<v8::Value>& info) { 5995 const v8::PropertyCallbackInfo<v8::Value>& info) {
6010 info.GetReturnValue().Set(index); 5996 info.GetReturnValue().Set(index);
6011 } 5997 }
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
6366 // to Object.prototype and Array.prototype and create a new 6352 // to Object.prototype and Array.prototype and create a new
6367 // environment. This should succeed. 6353 // environment. This should succeed.
6368 6354
6369 v8::HandleScope scope(CcTest::isolate()); 6355 v8::HandleScope scope(CcTest::isolate());
6370 6356
6371 Local<String> source = v8_str("Object.prototype.obj = 1234;" 6357 Local<String> source = v8_str("Object.prototype.obj = 1234;"
6372 "Array.prototype.arr = 4567;" 6358 "Array.prototype.arr = 4567;"
6373 "8901"); 6359 "8901");
6374 6360
6375 LocalContext env0; 6361 LocalContext env0;
6376 Local<Script> script0 = Script::Compile(source); 6362 Local<Script> script0 = v8_compile(source);
6377 CHECK_EQ(8901.0, script0->Run()->NumberValue()); 6363 CHECK_EQ(8901.0, script0->Run()->NumberValue());
6378 6364
6379 LocalContext env1; 6365 LocalContext env1;
6380 Local<Script> script1 = Script::Compile(source); 6366 Local<Script> script1 = v8_compile(source);
6381 CHECK_EQ(8901.0, script1->Run()->NumberValue()); 6367 CHECK_EQ(8901.0, script1->Run()->NumberValue());
6382 } 6368 }
6383 6369
6384 6370
6385 THREADED_TEST(UndetectableObject) { 6371 THREADED_TEST(UndetectableObject) {
6386 LocalContext env; 6372 LocalContext env;
6387 v8::HandleScope scope(env->GetIsolate()); 6373 v8::HandleScope scope(env->GetIsolate());
6388 6374
6389 Local<v8::FunctionTemplate> desc = 6375 Local<v8::FunctionTemplate> desc =
6390 v8::FunctionTemplate::New(env->GetIsolate()); 6376 v8::FunctionTemplate::New(env->GetIsolate());
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
6477 6463
6478 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate); 6464 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate);
6479 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable 6465 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable
6480 6466
6481 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); 6467 Local<v8::Object> obj = desc->GetFunction()->NewInstance();
6482 env->Global()->Set(v8_str("undetectable"), obj); 6468 env->Global()->Set(v8_str("undetectable"), obj);
6483 6469
6484 Local<String> source = v8_str("undetectable.x = 42;" 6470 Local<String> source = v8_str("undetectable.x = 42;"
6485 "undetectable.x"); 6471 "undetectable.x");
6486 6472
6487 Local<Script> script = Script::Compile(source); 6473 Local<Script> script = v8_compile(source);
6488 6474
6489 CHECK_EQ(v8::Integer::New(isolate, 42), script->Run()); 6475 CHECK_EQ(v8::Integer::New(isolate, 42), script->Run());
6490 6476
6491 ExpectBoolean("Object.isExtensible(undetectable)", true); 6477 ExpectBoolean("Object.isExtensible(undetectable)", true);
6492 6478
6493 source = v8_str("Object.preventExtensions(undetectable);"); 6479 source = v8_str("Object.preventExtensions(undetectable);");
6494 script = Script::Compile(source); 6480 script = v8_compile(source);
6495 script->Run(); 6481 script->Run();
6496 ExpectBoolean("Object.isExtensible(undetectable)", false); 6482 ExpectBoolean("Object.isExtensible(undetectable)", false);
6497 6483
6498 source = v8_str("undetectable.y = 2000;"); 6484 source = v8_str("undetectable.y = 2000;");
6499 script = Script::Compile(source); 6485 script = v8_compile(source);
6500 script->Run(); 6486 script->Run();
6501 ExpectBoolean("undetectable.y == undefined", true); 6487 ExpectBoolean("undetectable.y == undefined", true);
6502 } 6488 }
6503 6489
6504 6490
6505 6491
6506 THREADED_TEST(UndetectableString) { 6492 THREADED_TEST(UndetectableString) {
6507 LocalContext env; 6493 LocalContext env;
6508 v8::HandleScope scope(env->GetIsolate()); 6494 v8::HandleScope scope(env->GetIsolate());
6509 6495
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
6582 6568
6583 // The point of this test is type checking. We run it only so compilers 6569 // The point of this test is type checking. We run it only so compilers
6584 // don't complain about an unused function. 6570 // don't complain about an unused function.
6585 TEST(PersistentHandles) { 6571 TEST(PersistentHandles) {
6586 LocalContext env; 6572 LocalContext env;
6587 v8::Isolate* isolate = CcTest::isolate(); 6573 v8::Isolate* isolate = CcTest::isolate();
6588 v8::HandleScope scope(isolate); 6574 v8::HandleScope scope(isolate);
6589 Local<String> str = v8_str("foo"); 6575 Local<String> str = v8_str("foo");
6590 v8::Persistent<String> p_str(isolate, str); 6576 v8::Persistent<String> p_str(isolate, str);
6591 p_str.Reset(); 6577 p_str.Reset();
6592 Local<Script> scr = Script::Compile(v8_str("")); 6578 Local<Script> scr = v8_compile("");
6593 v8::Persistent<Script> p_scr(isolate, scr); 6579 v8::Persistent<Script> p_scr(isolate, scr);
6594 p_scr.Reset(); 6580 p_scr.Reset();
6595 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 6581 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6596 v8::Persistent<ObjectTemplate> p_templ(isolate, templ); 6582 v8::Persistent<ObjectTemplate> p_templ(isolate, templ);
6597 p_templ.Reset(); 6583 p_templ.Reset();
6598 } 6584 }
6599 6585
6600 6586
6601 static void HandleLogDelegator( 6587 static void HandleLogDelegator(
6602 const v8::FunctionCallbackInfo<v8::Value>& args) { 6588 const v8::FunctionCallbackInfo<v8::Value>& args) {
6603 ApiTestFuzzer::Fuzz(); 6589 ApiTestFuzzer::Fuzz();
6604 } 6590 }
6605 6591
6606 6592
6607 THREADED_TEST(GlobalObjectTemplate) { 6593 THREADED_TEST(GlobalObjectTemplate) {
6608 v8::Isolate* isolate = CcTest::isolate(); 6594 v8::Isolate* isolate = CcTest::isolate();
6609 v8::HandleScope handle_scope(isolate); 6595 v8::HandleScope handle_scope(isolate);
6610 Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate); 6596 Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate);
6611 global_template->Set(v8_str("JSNI_Log"), 6597 global_template->Set(v8_str("JSNI_Log"),
6612 v8::FunctionTemplate::New(isolate, HandleLogDelegator)); 6598 v8::FunctionTemplate::New(isolate, HandleLogDelegator));
6613 v8::Local<Context> context = Context::New(isolate, 0, global_template); 6599 v8::Local<Context> context = Context::New(isolate, 0, global_template);
6614 Context::Scope context_scope(context); 6600 Context::Scope context_scope(context);
6615 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run(); 6601 CompileRun("JSNI_Log('LOG')");
6616 } 6602 }
6617 6603
6618 6604
6619 static const char* kSimpleExtensionSource = 6605 static const char* kSimpleExtensionSource =
6620 "function Foo() {" 6606 "function Foo() {"
6621 " return 4;" 6607 " return 4;"
6622 "}"; 6608 "}";
6623 6609
6624 6610
6625 TEST(SimpleExtensions) { 6611 TEST(SimpleExtensions) {
6626 v8::HandleScope handle_scope(CcTest::isolate()); 6612 v8::HandleScope handle_scope(CcTest::isolate());
6627 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource)); 6613 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource));
6628 const char* extension_names[] = { "simpletest" }; 6614 const char* extension_names[] = { "simpletest" };
6629 v8::ExtensionConfiguration extensions(1, extension_names); 6615 v8::ExtensionConfiguration extensions(1, extension_names);
6630 v8::Handle<Context> context = 6616 v8::Handle<Context> context =
6631 Context::New(CcTest::isolate(), &extensions); 6617 Context::New(CcTest::isolate(), &extensions);
6632 Context::Scope lock(context); 6618 Context::Scope lock(context);
6633 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); 6619 v8::Handle<Value> result = CompileRun("Foo()");
6634 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 4)); 6620 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 4));
6635 } 6621 }
6636 6622
6637 6623
6638 TEST(NullExtensions) { 6624 TEST(NullExtensions) {
6639 v8::HandleScope handle_scope(CcTest::isolate()); 6625 v8::HandleScope handle_scope(CcTest::isolate());
6640 v8::RegisterExtension(new Extension("nulltest", NULL)); 6626 v8::RegisterExtension(new Extension("nulltest", NULL));
6641 const char* extension_names[] = { "nulltest" }; 6627 const char* extension_names[] = { "nulltest" };
6642 v8::ExtensionConfiguration extensions(1, extension_names); 6628 v8::ExtensionConfiguration extensions(1, extension_names);
6643 v8::Handle<Context> context = 6629 v8::Handle<Context> context =
6644 Context::New(CcTest::isolate(), &extensions); 6630 Context::New(CcTest::isolate(), &extensions);
6645 Context::Scope lock(context); 6631 Context::Scope lock(context);
6646 v8::Handle<Value> result = Script::Compile(v8_str("1+3"))->Run(); 6632 v8::Handle<Value> result = CompileRun("1+3");
6647 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 4)); 6633 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 4));
6648 } 6634 }
6649 6635
6650 6636
6651 static const char* kEmbeddedExtensionSource = 6637 static const char* kEmbeddedExtensionSource =
6652 "function Ret54321(){return 54321;}~~@@$" 6638 "function Ret54321(){return 54321;}~~@@$"
6653 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS."; 6639 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS.";
6654 static const int kEmbeddedExtensionSourceValidLen = 34; 6640 static const int kEmbeddedExtensionSourceValidLen = 34;
6655 6641
6656 6642
(...skipping 17 matching lines...) Expand all
6674 i::OS::SNPrintF(extension_name, "ext #%d", source_len); 6660 i::OS::SNPrintF(extension_name, "ext #%d", source_len);
6675 v8::RegisterExtension(new Extension(extension_name.start(), 6661 v8::RegisterExtension(new Extension(extension_name.start(),
6676 kEmbeddedExtensionSource, 0, 0, 6662 kEmbeddedExtensionSource, 0, 0,
6677 source_len)); 6663 source_len));
6678 const char* extension_names[1] = { extension_name.start() }; 6664 const char* extension_names[1] = { extension_name.start() };
6679 v8::ExtensionConfiguration extensions(1, extension_names); 6665 v8::ExtensionConfiguration extensions(1, extension_names);
6680 v8::Handle<Context> context = 6666 v8::Handle<Context> context =
6681 Context::New(CcTest::isolate(), &extensions); 6667 Context::New(CcTest::isolate(), &extensions);
6682 if (source_len == kEmbeddedExtensionSourceValidLen) { 6668 if (source_len == kEmbeddedExtensionSourceValidLen) {
6683 Context::Scope lock(context); 6669 Context::Scope lock(context);
6684 v8::Handle<Value> result = Script::Compile(v8_str("Ret54321()"))->Run(); 6670 v8::Handle<Value> result = CompileRun("Ret54321()");
6685 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 54321), result); 6671 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 54321), result);
6686 } else { 6672 } else {
6687 // Anything but exactly the right length should fail to compile. 6673 // Anything but exactly the right length should fail to compile.
6688 CHECK_EQ(0, *context); 6674 CHECK_EQ(0, *context);
6689 } 6675 }
6690 } 6676 }
6691 } 6677 }
6692 6678
6693 6679
6694 static const char* kEvalExtensionSource1 = 6680 static const char* kEvalExtensionSource1 =
(...skipping 15 matching lines...) Expand all
6710 6696
6711 TEST(UseEvalFromExtension) { 6697 TEST(UseEvalFromExtension) {
6712 v8::HandleScope handle_scope(CcTest::isolate()); 6698 v8::HandleScope handle_scope(CcTest::isolate());
6713 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1)); 6699 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1));
6714 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2)); 6700 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2));
6715 const char* extension_names[] = { "evaltest1", "evaltest2" }; 6701 const char* extension_names[] = { "evaltest1", "evaltest2" };
6716 v8::ExtensionConfiguration extensions(2, extension_names); 6702 v8::ExtensionConfiguration extensions(2, extension_names);
6717 v8::Handle<Context> context = 6703 v8::Handle<Context> context =
6718 Context::New(CcTest::isolate(), &extensions); 6704 Context::New(CcTest::isolate(), &extensions);
6719 Context::Scope lock(context); 6705 Context::Scope lock(context);
6720 v8::Handle<Value> result = Script::Compile(v8_str("UseEval1()"))->Run(); 6706 v8::Handle<Value> result = CompileRun("UseEval1()");
6721 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 42)); 6707 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 42));
6722 result = Script::Compile(v8_str("UseEval2()"))->Run(); 6708 result = CompileRun("UseEval2()");
6723 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 42)); 6709 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 42));
6724 } 6710 }
6725 6711
6726 6712
6727 static const char* kWithExtensionSource1 = 6713 static const char* kWithExtensionSource1 =
6728 "function UseWith1() {" 6714 "function UseWith1() {"
6729 " var x = 42;" 6715 " var x = 42;"
6730 " with({x:87}) { return x; }" 6716 " with({x:87}) { return x; }"
6731 "}"; 6717 "}";
6732 6718
(...skipping 11 matching lines...) Expand all
6744 6730
6745 TEST(UseWithFromExtension) { 6731 TEST(UseWithFromExtension) {
6746 v8::HandleScope handle_scope(CcTest::isolate()); 6732 v8::HandleScope handle_scope(CcTest::isolate());
6747 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1)); 6733 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1));
6748 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2)); 6734 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2));
6749 const char* extension_names[] = { "withtest1", "withtest2" }; 6735 const char* extension_names[] = { "withtest1", "withtest2" };
6750 v8::ExtensionConfiguration extensions(2, extension_names); 6736 v8::ExtensionConfiguration extensions(2, extension_names);
6751 v8::Handle<Context> context = 6737 v8::Handle<Context> context =
6752 Context::New(CcTest::isolate(), &extensions); 6738 Context::New(CcTest::isolate(), &extensions);
6753 Context::Scope lock(context); 6739 Context::Scope lock(context);
6754 v8::Handle<Value> result = Script::Compile(v8_str("UseWith1()"))->Run(); 6740 v8::Handle<Value> result = CompileRun("UseWith1()");
6755 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 87)); 6741 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 87));
6756 result = Script::Compile(v8_str("UseWith2()"))->Run(); 6742 result = CompileRun("UseWith2()");
6757 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 87)); 6743 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 87));
6758 } 6744 }
6759 6745
6760 6746
6761 TEST(AutoExtensions) { 6747 TEST(AutoExtensions) {
6762 v8::HandleScope handle_scope(CcTest::isolate()); 6748 v8::HandleScope handle_scope(CcTest::isolate());
6763 Extension* extension = new Extension("autotest", kSimpleExtensionSource); 6749 Extension* extension = new Extension("autotest", kSimpleExtensionSource);
6764 extension->set_auto_enable(true); 6750 extension->set_auto_enable(true);
6765 v8::RegisterExtension(extension); 6751 v8::RegisterExtension(extension);
6766 v8::Handle<Context> context = 6752 v8::Handle<Context> context =
6767 Context::New(CcTest::isolate()); 6753 Context::New(CcTest::isolate());
6768 Context::Scope lock(context); 6754 Context::Scope lock(context);
6769 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); 6755 v8::Handle<Value> result = CompileRun("Foo()");
6770 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 4)); 6756 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 4));
6771 } 6757 }
6772 6758
6773 6759
6774 static const char* kSyntaxErrorInExtensionSource = 6760 static const char* kSyntaxErrorInExtensionSource =
6775 "["; 6761 "[";
6776 6762
6777 6763
6778 // Test that a syntax error in an extension does not cause a fatal 6764 // Test that a syntax error in an extension does not cause a fatal
6779 // error but results in an empty context. 6765 // error but results in an empty context.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
6819 // Test that a native runtime calls are supported in extensions. 6805 // Test that a native runtime calls are supported in extensions.
6820 TEST(NativeCallInExtensions) { 6806 TEST(NativeCallInExtensions) {
6821 v8::HandleScope handle_scope(CcTest::isolate()); 6807 v8::HandleScope handle_scope(CcTest::isolate());
6822 v8::RegisterExtension(new Extension("nativecall", 6808 v8::RegisterExtension(new Extension("nativecall",
6823 kNativeCallInExtensionSource)); 6809 kNativeCallInExtensionSource));
6824 const char* extension_names[] = { "nativecall" }; 6810 const char* extension_names[] = { "nativecall" };
6825 v8::ExtensionConfiguration extensions(1, extension_names); 6811 v8::ExtensionConfiguration extensions(1, extension_names);
6826 v8::Handle<Context> context = 6812 v8::Handle<Context> context =
6827 Context::New(CcTest::isolate(), &extensions); 6813 Context::New(CcTest::isolate(), &extensions);
6828 Context::Scope lock(context); 6814 Context::Scope lock(context);
6829 v8::Handle<Value> result = Script::Compile(v8_str(kNativeCallTest))->Run(); 6815 v8::Handle<Value> result = CompileRun(kNativeCallTest);
6830 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 3)); 6816 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 3));
6831 } 6817 }
6832 6818
6833 6819
6834 class NativeFunctionExtension : public Extension { 6820 class NativeFunctionExtension : public Extension {
6835 public: 6821 public:
6836 NativeFunctionExtension(const char* name, 6822 NativeFunctionExtension(const char* name,
6837 const char* source, 6823 const char* source,
6838 v8::FunctionCallback fun = &Echo) 6824 v8::FunctionCallback fun = &Echo)
6839 : Extension(name, source), 6825 : Extension(name, source),
(...skipping 16 matching lines...) Expand all
6856 TEST(NativeFunctionDeclaration) { 6842 TEST(NativeFunctionDeclaration) {
6857 v8::HandleScope handle_scope(CcTest::isolate()); 6843 v8::HandleScope handle_scope(CcTest::isolate());
6858 const char* name = "nativedecl"; 6844 const char* name = "nativedecl";
6859 v8::RegisterExtension(new NativeFunctionExtension(name, 6845 v8::RegisterExtension(new NativeFunctionExtension(name,
6860 "native function foo();")); 6846 "native function foo();"));
6861 const char* extension_names[] = { name }; 6847 const char* extension_names[] = { name };
6862 v8::ExtensionConfiguration extensions(1, extension_names); 6848 v8::ExtensionConfiguration extensions(1, extension_names);
6863 v8::Handle<Context> context = 6849 v8::Handle<Context> context =
6864 Context::New(CcTest::isolate(), &extensions); 6850 Context::New(CcTest::isolate(), &extensions);
6865 Context::Scope lock(context); 6851 Context::Scope lock(context);
6866 v8::Handle<Value> result = Script::Compile(v8_str("foo(42);"))->Run(); 6852 v8::Handle<Value> result = CompileRun("foo(42);");
6867 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 42)); 6853 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 42));
6868 } 6854 }
6869 6855
6870 6856
6871 TEST(NativeFunctionDeclarationError) { 6857 TEST(NativeFunctionDeclarationError) {
6872 v8::HandleScope handle_scope(CcTest::isolate()); 6858 v8::HandleScope handle_scope(CcTest::isolate());
6873 const char* name = "nativedeclerr"; 6859 const char* name = "nativedeclerr";
6874 // Syntax error in extension code. 6860 // Syntax error in extension code.
6875 v8::RegisterExtension(new NativeFunctionExtension(name, 6861 v8::RegisterExtension(new NativeFunctionExtension(name,
6876 "native\nfunction foo();")); 6862 "native\nfunction foo();"));
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
6987 6973
6988 6974
6989 THREADED_TEST(FunctionLookup) { 6975 THREADED_TEST(FunctionLookup) {
6990 v8::RegisterExtension(new FunctionExtension()); 6976 v8::RegisterExtension(new FunctionExtension());
6991 v8::HandleScope handle_scope(CcTest::isolate()); 6977 v8::HandleScope handle_scope(CcTest::isolate());
6992 static const char* exts[1] = { "functiontest" }; 6978 static const char* exts[1] = { "functiontest" };
6993 v8::ExtensionConfiguration config(1, exts); 6979 v8::ExtensionConfiguration config(1, exts);
6994 LocalContext context(&config); 6980 LocalContext context(&config);
6995 CHECK_EQ(3, lookup_count); 6981 CHECK_EQ(3, lookup_count);
6996 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 8), 6982 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 8),
6997 Script::Compile(v8_str("Foo(0)"))->Run()); 6983 CompileRun("Foo(0)"));
6998 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 7), 6984 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 7),
6999 Script::Compile(v8_str("Foo(1)"))->Run()); 6985 CompileRun("Foo(1)"));
7000 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 6), 6986 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 6),
7001 Script::Compile(v8_str("Foo(2)"))->Run()); 6987 CompileRun("Foo(2)"));
7002 } 6988 }
7003 6989
7004 6990
7005 THREADED_TEST(NativeFunctionConstructCall) { 6991 THREADED_TEST(NativeFunctionConstructCall) {
7006 v8::RegisterExtension(new FunctionExtension()); 6992 v8::RegisterExtension(new FunctionExtension());
7007 v8::HandleScope handle_scope(CcTest::isolate()); 6993 v8::HandleScope handle_scope(CcTest::isolate());
7008 static const char* exts[1] = { "functiontest" }; 6994 static const char* exts[1] = { "functiontest" };
7009 v8::ExtensionConfiguration config(1, exts); 6995 v8::ExtensionConfiguration config(1, exts);
7010 LocalContext context(&config); 6996 LocalContext context(&config);
7011 for (int i = 0; i < 10; i++) { 6997 for (int i = 0; i < 10; i++) {
7012 // Run a few times to ensure that allocation of objects doesn't 6998 // Run a few times to ensure that allocation of objects doesn't
7013 // change behavior of a constructor function. 6999 // change behavior of a constructor function.
7014 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 8), 7000 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 8),
7015 Script::Compile(v8_str("(new A()).data"))->Run()); 7001 CompileRun("(new A()).data"));
7016 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 7), 7002 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 7),
7017 Script::Compile(v8_str("(new B()).data"))->Run()); 7003 CompileRun("(new B()).data"));
7018 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 6), 7004 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 6),
7019 Script::Compile(v8_str("(new C()).data"))->Run()); 7005 CompileRun("(new C()).data"));
7020 } 7006 }
7021 } 7007 }
7022 7008
7023 7009
7024 static const char* last_location; 7010 static const char* last_location;
7025 static const char* last_message; 7011 static const char* last_message;
7026 void StoringErrorCallback(const char* location, const char* message) { 7012 void StoringErrorCallback(const char* location, const char* message) {
7027 if (last_location == NULL) { 7013 if (last_location == NULL) {
7028 last_location = location; 7014 last_location = location;
7029 last_message = message; 7015 last_message = message;
(...skipping 25 matching lines...) Expand all
7055 CHECK_EQ(v8::Undefined(CcTest::isolate()), message->GetScriptResourceName()); 7041 CHECK_EQ(v8::Undefined(CcTest::isolate()), message->GetScriptResourceName());
7056 message->GetLineNumber(); 7042 message->GetLineNumber();
7057 message->GetSourceLine(); 7043 message->GetSourceLine();
7058 } 7044 }
7059 7045
7060 7046
7061 THREADED_TEST(ErrorWithMissingScriptInfo) { 7047 THREADED_TEST(ErrorWithMissingScriptInfo) {
7062 LocalContext context; 7048 LocalContext context;
7063 v8::HandleScope scope(context->GetIsolate()); 7049 v8::HandleScope scope(context->GetIsolate());
7064 v8::V8::AddMessageListener(MissingScriptInfoMessageListener); 7050 v8::V8::AddMessageListener(MissingScriptInfoMessageListener);
7065 Script::Compile(v8_str("throw Error()"))->Run(); 7051 CompileRun("throw Error()");
7066 v8::V8::RemoveMessageListeners(MissingScriptInfoMessageListener); 7052 v8::V8::RemoveMessageListeners(MissingScriptInfoMessageListener);
7067 } 7053 }
7068 7054
7069 7055
7070 struct FlagAndPersistent { 7056 struct FlagAndPersistent {
7071 bool flag; 7057 bool flag;
7072 v8::Persistent<v8::Object> handle; 7058 v8::Persistent<v8::Object> handle;
7073 }; 7059 };
7074 7060
7075 7061
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
7476 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); 7462 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
7477 templ->SetAccessor(v8_str("t"), PGetter2); 7463 templ->SetAccessor(v8_str("t"), PGetter2);
7478 LocalContext context; 7464 LocalContext context;
7479 context->Global()->Set(v8_str("o"), templ->NewInstance()); 7465 context->Global()->Set(v8_str("o"), templ->NewInstance());
7480 for (int i = 0; i < 100; i++) { 7466 for (int i = 0; i < 100; i++) {
7481 v8::HandleScope inner_scope(CcTest::isolate()); 7467 v8::HandleScope inner_scope(CcTest::isolate());
7482 v8::Handle<v8::Object> obj = templ->NewInstance(); 7468 v8::Handle<v8::Object> obj = templ->NewInstance();
7483 CHECK_NE(obj, context->Global()->Get(v8_str("o"))); 7469 CHECK_NE(obj, context->Global()->Get(v8_str("o")));
7484 context->Global()->Set(v8_str("o2"), obj); 7470 context->Global()->Set(v8_str("o2"), obj);
7485 v8::Handle<Value> value = 7471 v8::Handle<Value> value =
7486 Script::Compile(v8_str("o.__proto__ === o2.__proto__"))->Run(); 7472 CompileRun("o.__proto__ === o2.__proto__");
7487 CHECK_EQ(v8::True(isolate), value); 7473 CHECK_EQ(v8::True(isolate), value);
7488 context->Global()->Set(v8_str("o"), obj); 7474 context->Global()->Set(v8_str("o"), obj);
7489 } 7475 }
7490 } 7476 }
7491 7477
7492 7478
7493 static int StrCmp16(uint16_t* a, uint16_t* b) { 7479 static int StrCmp16(uint16_t* a, uint16_t* b) {
7494 while (true) { 7480 while (true) {
7495 if (*a == 0 && *b == 0) return 0; 7481 if (*a == 0 && *b == 0) return 0;
7496 if (*a != *b) return 0 + *a - *b; 7482 if (*a != *b) return 0 + *a - *b;
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
8237 LocalContext env; 8223 LocalContext env;
8238 v8::Isolate* isolate = env->GetIsolate(); 8224 v8::Isolate* isolate = env->GetIsolate();
8239 v8::HandleScope scope(isolate); 8225 v8::HandleScope scope(isolate);
8240 v8::V8::AddMessageListener(ApiUncaughtExceptionTestListener); 8226 v8::V8::AddMessageListener(ApiUncaughtExceptionTestListener);
8241 8227
8242 Local<v8::FunctionTemplate> fun = 8228 Local<v8::FunctionTemplate> fun =
8243 v8::FunctionTemplate::New(isolate, TroubleCallback); 8229 v8::FunctionTemplate::New(isolate, TroubleCallback);
8244 v8::Local<v8::Object> global = env->Global(); 8230 v8::Local<v8::Object> global = env->Global();
8245 global->Set(v8_str("trouble"), fun->GetFunction()); 8231 global->Set(v8_str("trouble"), fun->GetFunction());
8246 8232
8247 Script::Compile(v8_str("function trouble_callee() {" 8233 CompileRun(
8248 " var x = null;" 8234 "function trouble_callee() {"
8249 " return x.foo;" 8235 " var x = null;"
8250 "};" 8236 " return x.foo;"
8251 "function trouble_caller() {" 8237 "};"
8252 " trouble();" 8238 "function trouble_caller() {"
8253 "};"))->Run(); 8239 " trouble();"
8240 "};");
8254 Local<Value> trouble = global->Get(v8_str("trouble")); 8241 Local<Value> trouble = global->Get(v8_str("trouble"));
8255 CHECK(trouble->IsFunction()); 8242 CHECK(trouble->IsFunction());
8256 Local<Value> trouble_callee = global->Get(v8_str("trouble_callee")); 8243 Local<Value> trouble_callee = global->Get(v8_str("trouble_callee"));
8257 CHECK(trouble_callee->IsFunction()); 8244 CHECK(trouble_callee->IsFunction());
8258 Local<Value> trouble_caller = global->Get(v8_str("trouble_caller")); 8245 Local<Value> trouble_caller = global->Get(v8_str("trouble_caller"));
8259 CHECK(trouble_caller->IsFunction()); 8246 CHECK(trouble_caller->IsFunction());
8260 Function::Cast(*trouble_caller)->Call(global, 0, NULL); 8247 Function::Cast(*trouble_caller)->Call(global, 0, NULL);
8261 CHECK_EQ(1, report_count); 8248 CHECK_EQ(1, report_count);
8262 v8::V8::RemoveMessageListeners(ApiUncaughtExceptionTestListener); 8249 v8::V8::RemoveMessageListeners(ApiUncaughtExceptionTestListener);
8263 } 8250 }
(...skipping 15 matching lines...) Expand all
8279 LocalContext env; 8266 LocalContext env;
8280 v8::Isolate* isolate = env->GetIsolate(); 8267 v8::Isolate* isolate = env->GetIsolate();
8281 v8::HandleScope scope(isolate); 8268 v8::HandleScope scope(isolate);
8282 v8::V8::AddMessageListener(ExceptionInNativeScriptTestListener); 8269 v8::V8::AddMessageListener(ExceptionInNativeScriptTestListener);
8283 8270
8284 Local<v8::FunctionTemplate> fun = 8271 Local<v8::FunctionTemplate> fun =
8285 v8::FunctionTemplate::New(isolate, TroubleCallback); 8272 v8::FunctionTemplate::New(isolate, TroubleCallback);
8286 v8::Local<v8::Object> global = env->Global(); 8273 v8::Local<v8::Object> global = env->Global();
8287 global->Set(v8_str("trouble"), fun->GetFunction()); 8274 global->Set(v8_str("trouble"), fun->GetFunction());
8288 8275
8289 Script::Compile( 8276 CompileRunWithOrigin(
8290 v8_str( 8277 "function trouble() {\n"
8291 "function trouble() {\n" 8278 " var o = {};\n"
8292 " var o = {};\n" 8279 " new o.foo();\n"
8293 " new o.foo();\n" 8280 "};",
8294 "};"), 8281 script_resource_name);
8295 v8::String::NewFromUtf8(isolate, script_resource_name))->Run();
8296 Local<Value> trouble = global->Get(v8_str("trouble")); 8282 Local<Value> trouble = global->Get(v8_str("trouble"));
8297 CHECK(trouble->IsFunction()); 8283 CHECK(trouble->IsFunction());
8298 Function::Cast(*trouble)->Call(global, 0, NULL); 8284 Function::Cast(*trouble)->Call(global, 0, NULL);
8299 v8::V8::RemoveMessageListeners(ExceptionInNativeScriptTestListener); 8285 v8::V8::RemoveMessageListeners(ExceptionInNativeScriptTestListener);
8300 } 8286 }
8301 8287
8302 8288
8303 TEST(CompilationErrorUsingTryCatchHandler) { 8289 TEST(CompilationErrorUsingTryCatchHandler) {
8304 LocalContext env; 8290 LocalContext env;
8305 v8::HandleScope scope(env->GetIsolate()); 8291 v8::HandleScope scope(env->GetIsolate());
8306 v8::TryCatch try_catch; 8292 v8::TryCatch try_catch;
8307 Script::Compile(v8_str("This doesn't &*&@#$&*^ compile.")); 8293 v8_compile("This doesn't &*&@#$&*^ compile.");
8308 CHECK_NE(NULL, *try_catch.Exception()); 8294 CHECK_NE(NULL, *try_catch.Exception());
8309 CHECK(try_catch.HasCaught()); 8295 CHECK(try_catch.HasCaught());
8310 } 8296 }
8311 8297
8312 8298
8313 TEST(TryCatchFinallyUsingTryCatchHandler) { 8299 TEST(TryCatchFinallyUsingTryCatchHandler) {
8314 LocalContext env; 8300 LocalContext env;
8315 v8::HandleScope scope(env->GetIsolate()); 8301 v8::HandleScope scope(env->GetIsolate());
8316 v8::TryCatch try_catch; 8302 v8::TryCatch try_catch;
8317 Script::Compile(v8_str("try { throw ''; } catch (e) {}"))->Run(); 8303 CompileRun("try { throw ''; } catch (e) {}");
8318 CHECK(!try_catch.HasCaught()); 8304 CHECK(!try_catch.HasCaught());
8319 Script::Compile(v8_str("try { throw ''; } finally {}"))->Run(); 8305 CompileRun("try { throw ''; } finally {}");
8320 CHECK(try_catch.HasCaught()); 8306 CHECK(try_catch.HasCaught());
8321 try_catch.Reset(); 8307 try_catch.Reset();
8322 Script::Compile(v8_str("(function() {" 8308 CompileRun(
8323 "try { throw ''; } finally { return; }" 8309 "(function() {"
8324 "})()"))->Run(); 8310 "try { throw ''; } finally { return; }"
8311 "})()");
8325 CHECK(!try_catch.HasCaught()); 8312 CHECK(!try_catch.HasCaught());
8326 Script::Compile(v8_str("(function()" 8313 CompileRun(
8327 " { try { throw ''; } finally { throw 0; }" 8314 "(function()"
8328 "})()"))->Run(); 8315 " { try { throw ''; } finally { throw 0; }"
8316 "})()");
8329 CHECK(try_catch.HasCaught()); 8317 CHECK(try_catch.HasCaught());
8330 } 8318 }
8331 8319
8332 8320
8333 // SecurityHandler can't be run twice 8321 // SecurityHandler can't be run twice
8334 TEST(SecurityHandler) { 8322 TEST(SecurityHandler) {
8335 v8::Isolate* isolate = CcTest::isolate(); 8323 v8::Isolate* isolate = CcTest::isolate();
8336 v8::HandleScope scope0(isolate); 8324 v8::HandleScope scope0(isolate);
8337 v8::Handle<v8::ObjectTemplate> global_template = 8325 v8::Handle<v8::ObjectTemplate> global_template =
8338 v8::ObjectTemplate::New(isolate); 8326 v8::ObjectTemplate::New(isolate);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
8396 v8::HandleScope handle_scope(env1->GetIsolate()); 8384 v8::HandleScope handle_scope(env1->GetIsolate());
8397 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); 8385 v8::Handle<Context> env2 = Context::New(env1->GetIsolate());
8398 8386
8399 Local<Value> foo = v8_str("foo"); 8387 Local<Value> foo = v8_str("foo");
8400 Local<Value> bar = v8_str("bar"); 8388 Local<Value> bar = v8_str("bar");
8401 8389
8402 // Set to the same domain. 8390 // Set to the same domain.
8403 env1->SetSecurityToken(foo); 8391 env1->SetSecurityToken(foo);
8404 8392
8405 // Create a function in env1. 8393 // Create a function in env1.
8406 Script::Compile(v8_str("spy=function(){return spy;}"))->Run(); 8394 CompileRun("spy=function(){return spy;}");
8407 Local<Value> spy = env1->Global()->Get(v8_str("spy")); 8395 Local<Value> spy = env1->Global()->Get(v8_str("spy"));
8408 CHECK(spy->IsFunction()); 8396 CHECK(spy->IsFunction());
8409 8397
8410 // Create another function accessing global objects. 8398 // Create another function accessing global objects.
8411 Script::Compile(v8_str("spy2=function(){return new this.Array();}"))->Run(); 8399 CompileRun("spy2=function(){return new this.Array();}");
8412 Local<Value> spy2 = env1->Global()->Get(v8_str("spy2")); 8400 Local<Value> spy2 = env1->Global()->Get(v8_str("spy2"));
8413 CHECK(spy2->IsFunction()); 8401 CHECK(spy2->IsFunction());
8414 8402
8415 // Switch to env2 in the same domain and invoke spy on env2. 8403 // Switch to env2 in the same domain and invoke spy on env2.
8416 { 8404 {
8417 env2->SetSecurityToken(foo); 8405 env2->SetSecurityToken(foo);
8418 // Enter env2 8406 // Enter env2
8419 Context::Scope scope_env2(env2); 8407 Context::Scope scope_env2(env2);
8420 Local<Value> result = Function::Cast(*spy)->Call(env2->Global(), 0, NULL); 8408 Local<Value> result = Function::Cast(*spy)->Call(env2->Global(), 0, NULL);
8421 CHECK(result->IsFunction()); 8409 CHECK(result->IsFunction());
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
8514 env2->SetSecurityToken(foo); 8502 env2->SetSecurityToken(foo);
8515 8503
8516 env1->Global()->Set(v8_str("prop"), v8_num(3)); 8504 env1->Global()->Set(v8_str("prop"), v8_num(3));
8517 env2->Global()->Set(v8_str("env1"), env1->Global()); 8505 env2->Global()->Set(v8_str("env1"), env1->Global());
8518 8506
8519 // Change env2 to a different domain and delete env1.prop. 8507 // Change env2 to a different domain and delete env1.prop.
8520 env2->SetSecurityToken(bar); 8508 env2->SetSecurityToken(bar);
8521 { 8509 {
8522 Context::Scope scope_env2(env2); 8510 Context::Scope scope_env2(env2);
8523 Local<Value> result = 8511 Local<Value> result =
8524 Script::Compile(v8_str("delete env1.prop"))->Run(); 8512 CompileRun("delete env1.prop");
8525 CHECK(result->IsFalse()); 8513 CHECK(result->IsFalse());
8526 } 8514 }
8527 8515
8528 // Check that env1.prop still exists. 8516 // Check that env1.prop still exists.
8529 Local<Value> v = env1->Global()->Get(v8_str("prop")); 8517 Local<Value> v = env1->Global()->Get(v8_str("prop"));
8530 CHECK(v->IsNumber()); 8518 CHECK(v->IsNumber());
8531 CHECK_EQ(3, v->Int32Value()); 8519 CHECK_EQ(3, v->Int32Value());
8532 } 8520 }
8533 8521
8534 8522
8535 THREADED_TEST(CrossDomainIsPropertyEnumerable) { 8523 THREADED_TEST(CrossDomainIsPropertyEnumerable) {
8536 LocalContext env1; 8524 LocalContext env1;
8537 v8::HandleScope handle_scope(env1->GetIsolate()); 8525 v8::HandleScope handle_scope(env1->GetIsolate());
8538 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); 8526 v8::Handle<Context> env2 = Context::New(env1->GetIsolate());
8539 8527
8540 Local<Value> foo = v8_str("foo"); 8528 Local<Value> foo = v8_str("foo");
8541 Local<Value> bar = v8_str("bar"); 8529 Local<Value> bar = v8_str("bar");
8542 8530
8543 // Set to the same domain. 8531 // Set to the same domain.
8544 env1->SetSecurityToken(foo); 8532 env1->SetSecurityToken(foo);
8545 env2->SetSecurityToken(foo); 8533 env2->SetSecurityToken(foo);
8546 8534
8547 env1->Global()->Set(v8_str("prop"), v8_num(3)); 8535 env1->Global()->Set(v8_str("prop"), v8_num(3));
8548 env2->Global()->Set(v8_str("env1"), env1->Global()); 8536 env2->Global()->Set(v8_str("env1"), env1->Global());
8549 8537
8550 // env1.prop is enumerable in env2. 8538 // env1.prop is enumerable in env2.
8551 Local<String> test = v8_str("propertyIsEnumerable.call(env1, 'prop')"); 8539 Local<String> test = v8_str("propertyIsEnumerable.call(env1, 'prop')");
8552 { 8540 {
8553 Context::Scope scope_env2(env2); 8541 Context::Scope scope_env2(env2);
8554 Local<Value> result = Script::Compile(test)->Run(); 8542 Local<Value> result = CompileRun(test);
8555 CHECK(result->IsTrue()); 8543 CHECK(result->IsTrue());
8556 } 8544 }
8557 8545
8558 // Change env2 to a different domain and test again. 8546 // Change env2 to a different domain and test again.
8559 env2->SetSecurityToken(bar); 8547 env2->SetSecurityToken(bar);
8560 { 8548 {
8561 Context::Scope scope_env2(env2); 8549 Context::Scope scope_env2(env2);
8562 Local<Value> result = Script::Compile(test)->Run(); 8550 Local<Value> result = CompileRun(test);
8563 CHECK(result->IsFalse()); 8551 CHECK(result->IsFalse());
8564 } 8552 }
8565 } 8553 }
8566 8554
8567 8555
8568 THREADED_TEST(CrossDomainForIn) { 8556 THREADED_TEST(CrossDomainForIn) {
8569 LocalContext env1; 8557 LocalContext env1;
8570 v8::HandleScope handle_scope(env1->GetIsolate()); 8558 v8::HandleScope handle_scope(env1->GetIsolate());
8571 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); 8559 v8::Handle<Context> env2 = Context::New(env1->GetIsolate());
8572 8560
(...skipping 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after
9764 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); 9752 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
9765 Local<ObjectTemplate> instance = t->InstanceTemplate(); 9753 Local<ObjectTemplate> instance = t->InstanceTemplate();
9766 9754
9767 instance->Set(v8_str("x"), v8_num(42)); 9755 instance->Set(v8_str("x"), v8_num(42));
9768 instance->Set(v8_str("f"), 9756 instance->Set(v8_str("f"),
9769 v8::FunctionTemplate::New(isolate, InstanceFunctionCallback)); 9757 v8::FunctionTemplate::New(isolate, InstanceFunctionCallback));
9770 9758
9771 Local<Value> o = t->GetFunction()->NewInstance(); 9759 Local<Value> o = t->GetFunction()->NewInstance();
9772 9760
9773 context->Global()->Set(v8_str("i"), o); 9761 context->Global()->Set(v8_str("i"), o);
9774 Local<Value> value = Script::Compile(v8_str("i.x"))->Run(); 9762 Local<Value> value = CompileRun("i.x");
9775 CHECK_EQ(42, value->Int32Value()); 9763 CHECK_EQ(42, value->Int32Value());
9776 9764
9777 value = Script::Compile(v8_str("i.f()"))->Run(); 9765 value = CompileRun("i.f()");
9778 CHECK_EQ(12, value->Int32Value()); 9766 CHECK_EQ(12, value->Int32Value());
9779 } 9767 }
9780 9768
9781 9769
9782 static void GlobalObjectInstancePropertiesGet( 9770 static void GlobalObjectInstancePropertiesGet(
9783 Local<String> key, 9771 Local<String> key,
9784 const v8::PropertyCallbackInfo<v8::Value>&) { 9772 const v8::PropertyCallbackInfo<v8::Value>&) {
9785 ApiTestFuzzer::Fuzz(); 9773 ApiTestFuzzer::Fuzz();
9786 } 9774 }
9787 9775
(...skipping 28 matching lines...) Expand all
9816 "var thrown = 0;" 9804 "var thrown = 0;"
9817 "try { wrapper(true); } catch (e) { thrown = 1; };" 9805 "try { wrapper(true); } catch (e) { thrown = 1; };"
9818 "thrown"; 9806 "thrown";
9819 9807
9820 { 9808 {
9821 LocalContext env(NULL, instance_template); 9809 LocalContext env(NULL, instance_template);
9822 // Hold on to the global object so it can be used again in another 9810 // Hold on to the global object so it can be used again in another
9823 // environment initialization. 9811 // environment initialization.
9824 global_object = env->Global(); 9812 global_object = env->Global();
9825 9813
9826 Local<Value> value = Script::Compile(v8_str("x"))->Run(); 9814 Local<Value> value = CompileRun("x");
9827 CHECK_EQ(42, value->Int32Value()); 9815 CHECK_EQ(42, value->Int32Value());
9828 value = Script::Compile(v8_str("f()"))->Run(); 9816 value = CompileRun("f()");
9829 CHECK_EQ(12, value->Int32Value()); 9817 CHECK_EQ(12, value->Int32Value());
9830 value = Script::Compile(v8_str(script))->Run(); 9818 value = CompileRun(script);
9831 CHECK_EQ(1, value->Int32Value()); 9819 CHECK_EQ(1, value->Int32Value());
9832 } 9820 }
9833 9821
9834 { 9822 {
9835 // Create new environment reusing the global object. 9823 // Create new environment reusing the global object.
9836 LocalContext env(NULL, instance_template, global_object); 9824 LocalContext env(NULL, instance_template, global_object);
9837 Local<Value> value = Script::Compile(v8_str("x"))->Run(); 9825 Local<Value> value = CompileRun("x");
9838 CHECK_EQ(42, value->Int32Value()); 9826 CHECK_EQ(42, value->Int32Value());
9839 value = Script::Compile(v8_str("f()"))->Run(); 9827 value = CompileRun("f()");
9840 CHECK_EQ(12, value->Int32Value()); 9828 CHECK_EQ(12, value->Int32Value());
9841 value = Script::Compile(v8_str(script))->Run(); 9829 value = CompileRun(script);
9842 CHECK_EQ(1, value->Int32Value()); 9830 CHECK_EQ(1, value->Int32Value());
9843 } 9831 }
9844 } 9832 }
9845 9833
9846 9834
9847 THREADED_TEST(CallKnownGlobalReceiver) { 9835 THREADED_TEST(CallKnownGlobalReceiver) {
9848 v8::Isolate* isolate = CcTest::isolate(); 9836 v8::Isolate* isolate = CcTest::isolate();
9849 v8::HandleScope handle_scope(isolate); 9837 v8::HandleScope handle_scope(isolate);
9850 9838
9851 Local<Value> global_object; 9839 Local<Value> global_object;
(...skipping 14 matching lines...) Expand all
9866 "function foo(x) { bar([x], bom(2)); }" 9854 "function foo(x) { bar([x], bom(2)); }"
9867 "for (var i = 0; i < 10000; i++) foo(1);" 9855 "for (var i = 0; i < 10000; i++) foo(1);"
9868 "foo"; 9856 "foo";
9869 9857
9870 Local<Value> foo; 9858 Local<Value> foo;
9871 { 9859 {
9872 LocalContext env(NULL, instance_template); 9860 LocalContext env(NULL, instance_template);
9873 // Hold on to the global object so it can be used again in another 9861 // Hold on to the global object so it can be used again in another
9874 // environment initialization. 9862 // environment initialization.
9875 global_object = env->Global(); 9863 global_object = env->Global();
9876 foo = Script::Compile(v8_str(script))->Run(); 9864 foo = CompileRun(script);
9877 } 9865 }
9878 9866
9879 { 9867 {
9880 // Create new environment reusing the global object. 9868 // Create new environment reusing the global object.
9881 LocalContext env(NULL, instance_template, global_object); 9869 LocalContext env(NULL, instance_template, global_object);
9882 env->Global()->Set(v8_str("foo"), foo); 9870 env->Global()->Set(v8_str("foo"), foo);
9883 Script::Compile(v8_str("foo()"))->Run(); 9871 CompileRun("foo()");
9884 } 9872 }
9885 } 9873 }
9886 9874
9887 9875
9888 static void ShadowFunctionCallback( 9876 static void ShadowFunctionCallback(
9889 const v8::FunctionCallbackInfo<v8::Value>& args) { 9877 const v8::FunctionCallbackInfo<v8::Value>& args) {
9890 ApiTestFuzzer::Fuzz(); 9878 ApiTestFuzzer::Fuzz();
9891 args.GetReturnValue().Set(v8_num(42)); 9879 args.GetReturnValue().Set(v8_num(42));
9892 } 9880 }
9893 9881
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
9942 ShadowFunctionCallback, 9930 ShadowFunctionCallback,
9943 Local<Value>())); 9931 Local<Value>()));
9944 proto->Set(v8_str("x"), v8_num(12)); 9932 proto->Set(v8_str("x"), v8_num(12));
9945 9933
9946 instance->SetAccessor(v8_str("y"), ShadowYGetter, ShadowYSetter); 9934 instance->SetAccessor(v8_str("y"), ShadowYGetter, ShadowYSetter);
9947 9935
9948 Local<Value> o = t->GetFunction()->NewInstance(); 9936 Local<Value> o = t->GetFunction()->NewInstance();
9949 context->Global()->Set(v8_str("__proto__"), o); 9937 context->Global()->Set(v8_str("__proto__"), o);
9950 9938
9951 Local<Value> value = 9939 Local<Value> value =
9952 Script::Compile(v8_str("this.propertyIsEnumerable(0)"))->Run(); 9940 CompileRun("this.propertyIsEnumerable(0)");
9953 CHECK(value->IsBoolean()); 9941 CHECK(value->IsBoolean());
9954 CHECK(!value->BooleanValue()); 9942 CHECK(!value->BooleanValue());
9955 9943
9956 value = Script::Compile(v8_str("x"))->Run(); 9944 value = CompileRun("x");
9957 CHECK_EQ(12, value->Int32Value()); 9945 CHECK_EQ(12, value->Int32Value());
9958 9946
9959 value = Script::Compile(v8_str("f()"))->Run(); 9947 value = CompileRun("f()");
9960 CHECK_EQ(42, value->Int32Value()); 9948 CHECK_EQ(42, value->Int32Value());
9961 9949
9962 Script::Compile(v8_str("y = 43"))->Run(); 9950 CompileRun("y = 43");
9963 CHECK_EQ(1, shadow_y_setter_call_count); 9951 CHECK_EQ(1, shadow_y_setter_call_count);
9964 value = Script::Compile(v8_str("y"))->Run(); 9952 value = CompileRun("y");
9965 CHECK_EQ(1, shadow_y_getter_call_count); 9953 CHECK_EQ(1, shadow_y_getter_call_count);
9966 CHECK_EQ(42, value->Int32Value()); 9954 CHECK_EQ(42, value->Int32Value());
9967 } 9955 }
9968 9956
9969 9957
9970 THREADED_TEST(HiddenPrototype) { 9958 THREADED_TEST(HiddenPrototype) {
9971 LocalContext context; 9959 LocalContext context;
9972 v8::Isolate* isolate = context->GetIsolate(); 9960 v8::Isolate* isolate = context->GetIsolate();
9973 v8::HandleScope handle_scope(isolate); 9961 v8::HandleScope handle_scope(isolate);
9974 9962
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
10578 "test();"); 10566 "test();");
10579 CHECK_EQ(0, value->Int32Value()); 10567 CHECK_EQ(0, value->Int32Value());
10580 } 10568 }
10581 10569
10582 10570
10583 THREADED_TEST(EvalAliasedDynamic) { 10571 THREADED_TEST(EvalAliasedDynamic) {
10584 LocalContext current; 10572 LocalContext current;
10585 v8::HandleScope scope(current->GetIsolate()); 10573 v8::HandleScope scope(current->GetIsolate());
10586 10574
10587 // Tests where aliased eval can only be resolved dynamically. 10575 // Tests where aliased eval can only be resolved dynamically.
10588 Local<Script> script = 10576 Local<Script> script = v8_compile(
10589 Script::Compile(v8_str("function f(x) { " 10577 "function f(x) { "
10590 " var foo = 2;" 10578 " var foo = 2;"
10591 " with (x) { return eval('foo'); }" 10579 " with (x) { return eval('foo'); }"
10592 "}" 10580 "}"
10593 "foo = 0;" 10581 "foo = 0;"
10594 "result1 = f(new Object());" 10582 "result1 = f(new Object());"
10595 "result2 = f(this);" 10583 "result2 = f(this);"
10596 "var x = new Object();" 10584 "var x = new Object();"
10597 "x.eval = function(x) { return 1; };" 10585 "x.eval = function(x) { return 1; };"
10598 "result3 = f(x);")); 10586 "result3 = f(x);");
10599 script->Run(); 10587 script->Run();
10600 CHECK_EQ(2, current->Global()->Get(v8_str("result1"))->Int32Value()); 10588 CHECK_EQ(2, current->Global()->Get(v8_str("result1"))->Int32Value());
10601 CHECK_EQ(0, current->Global()->Get(v8_str("result2"))->Int32Value()); 10589 CHECK_EQ(0, current->Global()->Get(v8_str("result2"))->Int32Value());
10602 CHECK_EQ(1, current->Global()->Get(v8_str("result3"))->Int32Value()); 10590 CHECK_EQ(1, current->Global()->Get(v8_str("result3"))->Int32Value());
10603 10591
10604 v8::TryCatch try_catch; 10592 v8::TryCatch try_catch;
10605 script = 10593 script = v8_compile(
10606 Script::Compile(v8_str("function f(x) { " 10594 "function f(x) { "
10607 " var bar = 2;" 10595 " var bar = 2;"
10608 " with (x) { return eval('bar'); }" 10596 " with (x) { return eval('bar'); }"
10609 "}" 10597 "}"
10610 "result4 = f(this)")); 10598 "result4 = f(this)");
10611 script->Run(); 10599 script->Run();
10612 CHECK(!try_catch.HasCaught()); 10600 CHECK(!try_catch.HasCaught());
10613 CHECK_EQ(2, current->Global()->Get(v8_str("result4"))->Int32Value()); 10601 CHECK_EQ(2, current->Global()->Get(v8_str("result4"))->Int32Value());
10614 10602
10615 try_catch.Reset(); 10603 try_catch.Reset();
10616 } 10604 }
10617 10605
10618 10606
10619 THREADED_TEST(CrossEval) { 10607 THREADED_TEST(CrossEval) {
10620 v8::HandleScope scope(CcTest::isolate()); 10608 v8::HandleScope scope(CcTest::isolate());
10621 LocalContext other; 10609 LocalContext other;
10622 LocalContext current; 10610 LocalContext current;
10623 10611
10624 Local<String> token = v8_str("<security token>"); 10612 Local<String> token = v8_str("<security token>");
10625 other->SetSecurityToken(token); 10613 other->SetSecurityToken(token);
10626 current->SetSecurityToken(token); 10614 current->SetSecurityToken(token);
10627 10615
10628 // Set up reference from current to other. 10616 // Set up reference from current to other.
10629 current->Global()->Set(v8_str("other"), other->Global()); 10617 current->Global()->Set(v8_str("other"), other->Global());
10630 10618
10631 // Check that new variables are introduced in other context. 10619 // Check that new variables are introduced in other context.
10632 Local<Script> script = 10620 Local<Script> script = v8_compile("other.eval('var foo = 1234')");
10633 Script::Compile(v8_str("other.eval('var foo = 1234')"));
10634 script->Run(); 10621 script->Run();
10635 Local<Value> foo = other->Global()->Get(v8_str("foo")); 10622 Local<Value> foo = other->Global()->Get(v8_str("foo"));
10636 CHECK_EQ(1234, foo->Int32Value()); 10623 CHECK_EQ(1234, foo->Int32Value());
10637 CHECK(!current->Global()->Has(v8_str("foo"))); 10624 CHECK(!current->Global()->Has(v8_str("foo")));
10638 10625
10639 // Check that writing to non-existing properties introduces them in 10626 // Check that writing to non-existing properties introduces them in
10640 // the other context. 10627 // the other context.
10641 script = 10628 script = v8_compile("other.eval('na = 1234')");
10642 Script::Compile(v8_str("other.eval('na = 1234')"));
10643 script->Run(); 10629 script->Run();
10644 CHECK_EQ(1234, other->Global()->Get(v8_str("na"))->Int32Value()); 10630 CHECK_EQ(1234, other->Global()->Get(v8_str("na"))->Int32Value());
10645 CHECK(!current->Global()->Has(v8_str("na"))); 10631 CHECK(!current->Global()->Has(v8_str("na")));
10646 10632
10647 // Check that global variables in current context are not visible in other 10633 // Check that global variables in current context are not visible in other
10648 // context. 10634 // context.
10649 v8::TryCatch try_catch; 10635 v8::TryCatch try_catch;
10650 script = 10636 script = v8_compile("var bar = 42; other.eval('bar');");
10651 Script::Compile(v8_str("var bar = 42; other.eval('bar');"));
10652 Local<Value> result = script->Run(); 10637 Local<Value> result = script->Run();
10653 CHECK(try_catch.HasCaught()); 10638 CHECK(try_catch.HasCaught());
10654 try_catch.Reset(); 10639 try_catch.Reset();
10655 10640
10656 // Check that local variables in current context are not visible in other 10641 // Check that local variables in current context are not visible in other
10657 // context. 10642 // context.
10658 script = 10643 script = v8_compile(
10659 Script::Compile(v8_str("(function() { " 10644 "(function() { "
10660 " var baz = 87;" 10645 " var baz = 87;"
10661 " return other.eval('baz');" 10646 " return other.eval('baz');"
10662 "})();")); 10647 "})();");
10663 result = script->Run(); 10648 result = script->Run();
10664 CHECK(try_catch.HasCaught()); 10649 CHECK(try_catch.HasCaught());
10665 try_catch.Reset(); 10650 try_catch.Reset();
10666 10651
10667 // Check that global variables in the other environment are visible 10652 // Check that global variables in the other environment are visible
10668 // when evaluting code. 10653 // when evaluting code.
10669 other->Global()->Set(v8_str("bis"), v8_num(1234)); 10654 other->Global()->Set(v8_str("bis"), v8_num(1234));
10670 script = Script::Compile(v8_str("other.eval('bis')")); 10655 script = v8_compile("other.eval('bis')");
10671 CHECK_EQ(1234, script->Run()->Int32Value()); 10656 CHECK_EQ(1234, script->Run()->Int32Value());
10672 CHECK(!try_catch.HasCaught()); 10657 CHECK(!try_catch.HasCaught());
10673 10658
10674 // Check that the 'this' pointer points to the global object evaluating 10659 // Check that the 'this' pointer points to the global object evaluating
10675 // code. 10660 // code.
10676 other->Global()->Set(v8_str("t"), other->Global()); 10661 other->Global()->Set(v8_str("t"), other->Global());
10677 script = Script::Compile(v8_str("other.eval('this == t')")); 10662 script = v8_compile("other.eval('this == t')");
10678 result = script->Run(); 10663 result = script->Run();
10679 CHECK(result->IsTrue()); 10664 CHECK(result->IsTrue());
10680 CHECK(!try_catch.HasCaught()); 10665 CHECK(!try_catch.HasCaught());
10681 10666
10682 // Check that variables introduced in with-statement are not visible in 10667 // Check that variables introduced in with-statement are not visible in
10683 // other context. 10668 // other context.
10684 script = 10669 script = v8_compile("with({x:2}){other.eval('x')}");
10685 Script::Compile(v8_str("with({x:2}){other.eval('x')}"));
10686 result = script->Run(); 10670 result = script->Run();
10687 CHECK(try_catch.HasCaught()); 10671 CHECK(try_catch.HasCaught());
10688 try_catch.Reset(); 10672 try_catch.Reset();
10689 10673
10690 // Check that you cannot use 'eval.call' with another object than the 10674 // Check that you cannot use 'eval.call' with another object than the
10691 // current global object. 10675 // current global object.
10692 script = 10676 script = v8_compile("other.y = 1; eval.call(other, 'y')");
10693 Script::Compile(v8_str("other.y = 1; eval.call(other, 'y')"));
10694 result = script->Run(); 10677 result = script->Run();
10695 CHECK(try_catch.HasCaught()); 10678 CHECK(try_catch.HasCaught());
10696 } 10679 }
10697 10680
10698 10681
10699 // Test that calling eval in a context which has been detached from 10682 // Test that calling eval in a context which has been detached from
10700 // its global throws an exception. This behavior is consistent with 10683 // its global throws an exception. This behavior is consistent with
10701 // other JavaScript implementations. 10684 // other JavaScript implementations.
10702 THREADED_TEST(EvalInDetachedGlobal) { 10685 THREADED_TEST(EvalInDetachedGlobal) {
10703 v8::Isolate* isolate = CcTest::isolate(); 10686 v8::Isolate* isolate = CcTest::isolate();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
10738 LocalContext current; 10721 LocalContext current;
10739 10722
10740 Local<String> token = v8_str("<security token>"); 10723 Local<String> token = v8_str("<security token>");
10741 other->SetSecurityToken(token); 10724 other->SetSecurityToken(token);
10742 current->SetSecurityToken(token); 10725 current->SetSecurityToken(token);
10743 10726
10744 // Set up reference from current to other. 10727 // Set up reference from current to other.
10745 current->Global()->Set(v8_str("other"), other->Global()); 10728 current->Global()->Set(v8_str("other"), other->Global());
10746 10729
10747 // Trigger lazy loading in other context. 10730 // Trigger lazy loading in other context.
10748 Local<Script> script = 10731 Local<Script> script = v8_compile("other.eval('new Date(42)')");
10749 Script::Compile(v8_str("other.eval('new Date(42)')"));
10750 Local<Value> value = script->Run(); 10732 Local<Value> value = script->Run();
10751 CHECK_EQ(42.0, value->NumberValue()); 10733 CHECK_EQ(42.0, value->NumberValue());
10752 } 10734 }
10753 10735
10754 10736
10755 static void call_as_function(const v8::FunctionCallbackInfo<v8::Value>& args) { 10737 static void call_as_function(const v8::FunctionCallbackInfo<v8::Value>& args) {
10756 ApiTestFuzzer::Fuzz(); 10738 ApiTestFuzzer::Fuzz();
10757 if (args.IsConstructCall()) { 10739 if (args.IsConstructCall()) {
10758 if (args[0]->IsInt32()) { 10740 if (args[0]->IsInt32()) {
10759 args.GetReturnValue().Set(v8_num(-args[0]->Int32Value())); 10741 args.GetReturnValue().Set(v8_num(-args[0]->Int32Value()));
(...skipping 3483 matching lines...) Expand 10 before | Expand all | Expand 10 after
14243 CHECK_EQ(1, result->InternalFieldCount()); 14225 CHECK_EQ(1, result->InternalFieldCount());
14244 } 14226 }
14245 14227
14246 14228
14247 // If part of the threaded tests, this test makes ThreadingTest fail 14229 // If part of the threaded tests, this test makes ThreadingTest fail
14248 // on mac. 14230 // on mac.
14249 TEST(CatchStackOverflow) { 14231 TEST(CatchStackOverflow) {
14250 LocalContext context; 14232 LocalContext context;
14251 v8::HandleScope scope(context->GetIsolate()); 14233 v8::HandleScope scope(context->GetIsolate());
14252 v8::TryCatch try_catch; 14234 v8::TryCatch try_catch;
14253 v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::NewFromUtf8( 14235 v8::Handle<v8::Value> result = CompileRun(
14254 context->GetIsolate(),
14255 "function f() {" 14236 "function f() {"
14256 " return f();" 14237 " return f();"
14257 "}" 14238 "}"
14258 "" 14239 ""
14259 "f();")); 14240 "f();");
14260 v8::Handle<v8::Value> result = script->Run();
14261 CHECK(result.IsEmpty()); 14241 CHECK(result.IsEmpty());
14262 } 14242 }
14263 14243
14264 14244
14265 static void CheckTryCatchSourceInfo(v8::Handle<v8::Script> script, 14245 static void CheckTryCatchSourceInfo(v8::Handle<v8::Script> script,
14266 const char* resource_name, 14246 const char* resource_name,
14267 int line_offset) { 14247 int line_offset) {
14268 v8::HandleScope scope(CcTest::isolate()); 14248 v8::HandleScope scope(CcTest::isolate());
14269 v8::TryCatch try_catch; 14249 v8::TryCatch try_catch;
14270 v8::Handle<v8::Value> result = script->Run(); 14250 v8::Handle<v8::Value> result = script->Run();
14271 CHECK(result.IsEmpty()); 14251 CHECK(result.IsEmpty());
14272 CHECK(try_catch.HasCaught()); 14252 CHECK(try_catch.HasCaught());
14273 v8::Handle<v8::Message> message = try_catch.Message(); 14253 v8::Handle<v8::Message> message = try_catch.Message();
14274 CHECK(!message.IsEmpty()); 14254 CHECK(!message.IsEmpty());
14275 CHECK_EQ(10 + line_offset, message->GetLineNumber()); 14255 CHECK_EQ(10 + line_offset, message->GetLineNumber());
14276 CHECK_EQ(91, message->GetStartPosition()); 14256 CHECK_EQ(91, message->GetStartPosition());
14277 CHECK_EQ(92, message->GetEndPosition()); 14257 CHECK_EQ(92, message->GetEndPosition());
14278 CHECK_EQ(2, message->GetStartColumn()); 14258 CHECK_EQ(2, message->GetStartColumn());
14279 CHECK_EQ(3, message->GetEndColumn()); 14259 CHECK_EQ(3, message->GetEndColumn());
14280 v8::String::Utf8Value line(message->GetSourceLine()); 14260 v8::String::Utf8Value line(message->GetSourceLine());
14281 CHECK_EQ(" throw 'nirk';", *line); 14261 CHECK_EQ(" throw 'nirk';", *line);
14282 v8::String::Utf8Value name(message->GetScriptResourceName()); 14262 v8::String::Utf8Value name(message->GetScriptResourceName());
14283 CHECK_EQ(resource_name, *name); 14263 CHECK_EQ(resource_name, *name);
14284 } 14264 }
14285 14265
14286 14266
14287 THREADED_TEST(TryCatchSourceInfo) { 14267 THREADED_TEST(TryCatchSourceInfo) {
14288 LocalContext context; 14268 LocalContext context;
14289 v8::HandleScope scope(context->GetIsolate()); 14269 v8::HandleScope scope(context->GetIsolate());
14290 v8::Handle<v8::String> source = v8::String::NewFromUtf8( 14270 v8::Local<v8::String> source = v8_str(
14291 context->GetIsolate(),
14292 "function Foo() {\n" 14271 "function Foo() {\n"
14293 " return Bar();\n" 14272 " return Bar();\n"
14294 "}\n" 14273 "}\n"
14295 "\n" 14274 "\n"
14296 "function Bar() {\n" 14275 "function Bar() {\n"
14297 " return Baz();\n" 14276 " return Baz();\n"
14298 "}\n" 14277 "}\n"
14299 "\n" 14278 "\n"
14300 "function Baz() {\n" 14279 "function Baz() {\n"
14301 " throw 'nirk';\n" 14280 " throw 'nirk';\n"
14302 "}\n" 14281 "}\n"
14303 "\n" 14282 "\n"
14304 "Foo();\n"); 14283 "Foo();\n");
14305 14284
14306 const char* resource_name; 14285 const char* resource_name;
14307 v8::Handle<v8::Script> script; 14286 v8::Handle<v8::Script> script;
14308 resource_name = "test.js"; 14287 resource_name = "test.js";
14309 script = v8::Script::Compile( 14288 script = CompileWithOrigin(source, resource_name);
14310 source, v8::String::NewFromUtf8(context->GetIsolate(), resource_name));
14311 CheckTryCatchSourceInfo(script, resource_name, 0); 14289 CheckTryCatchSourceInfo(script, resource_name, 0);
14312 14290
14313 resource_name = "test1.js"; 14291 resource_name = "test1.js";
14314 v8::ScriptOrigin origin1( 14292 v8::ScriptOrigin origin1(
14315 v8::String::NewFromUtf8(context->GetIsolate(), resource_name)); 14293 v8::String::NewFromUtf8(context->GetIsolate(), resource_name));
14316 script = v8::Script::Compile(source, &origin1); 14294 script = v8::Script::Compile(source, &origin1);
14317 CheckTryCatchSourceInfo(script, resource_name, 0); 14295 CheckTryCatchSourceInfo(script, resource_name, 0);
14318 14296
14319 resource_name = "test2.js"; 14297 resource_name = "test2.js";
14320 v8::ScriptOrigin origin2( 14298 v8::ScriptOrigin origin2(
14321 v8::String::NewFromUtf8(context->GetIsolate(), resource_name), 14299 v8::String::NewFromUtf8(context->GetIsolate(), resource_name),
14322 v8::Integer::New(context->GetIsolate(), 7)); 14300 v8::Integer::New(context->GetIsolate(), 7));
14323 script = v8::Script::Compile(source, &origin2); 14301 script = v8::Script::Compile(source, &origin2);
14324 CheckTryCatchSourceInfo(script, resource_name, 7); 14302 CheckTryCatchSourceInfo(script, resource_name, 7);
14325 } 14303 }
14326 14304
14327 14305
14328 THREADED_TEST(CompilationCache) { 14306 THREADED_TEST(CompilationCache) {
14329 LocalContext context; 14307 LocalContext context;
14330 v8::HandleScope scope(context->GetIsolate()); 14308 v8::HandleScope scope(context->GetIsolate());
14331 v8::Handle<v8::String> source0 = 14309 v8::Handle<v8::String> source0 =
14332 v8::String::NewFromUtf8(context->GetIsolate(), "1234"); 14310 v8::String::NewFromUtf8(context->GetIsolate(), "1234");
14333 v8::Handle<v8::String> source1 = 14311 v8::Handle<v8::String> source1 =
14334 v8::String::NewFromUtf8(context->GetIsolate(), "1234"); 14312 v8::String::NewFromUtf8(context->GetIsolate(), "1234");
14335 v8::Handle<v8::Script> script0 = v8::Script::Compile( 14313 v8::Handle<v8::Script> script0 = CompileWithOrigin(source0, "test.js");
14336 source0, v8::String::NewFromUtf8(context->GetIsolate(), "test.js")); 14314 v8::Handle<v8::Script> script1 = CompileWithOrigin(source1, "test.js");
14337 v8::Handle<v8::Script> script1 = v8::Script::Compile(
14338 source1, v8::String::NewFromUtf8(context->GetIsolate(), "test.js"));
14339 v8::Handle<v8::Script> script2 = 14315 v8::Handle<v8::Script> script2 =
14340 v8::Script::Compile(source0); // different origin 14316 v8::Script::Compile(source0); // different origin
14341 CHECK_EQ(1234, script0->Run()->Int32Value()); 14317 CHECK_EQ(1234, script0->Run()->Int32Value());
14342 CHECK_EQ(1234, script1->Run()->Int32Value()); 14318 CHECK_EQ(1234, script1->Run()->Int32Value());
14343 CHECK_EQ(1234, script2->Run()->Int32Value()); 14319 CHECK_EQ(1234, script2->Run()->Int32Value());
14344 } 14320 }
14345 14321
14346 14322
14347 static void FunctionNameCallback( 14323 static void FunctionNameCallback(
14348 const v8::FunctionCallbackInfo<v8::Value>& args) { 14324 const v8::FunctionCallbackInfo<v8::Value>& args) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
14401 v8::String::Utf8Value elm(props->Get(v8::Integer::New(isolate, i))); 14377 v8::String::Utf8Value elm(props->Get(v8::Integer::New(isolate, i)));
14402 CHECK_EQ(elmv[i], *elm); 14378 CHECK_EQ(elmv[i], *elm);
14403 } 14379 }
14404 } 14380 }
14405 14381
14406 14382
14407 THREADED_TEST(PropertyEnumeration) { 14383 THREADED_TEST(PropertyEnumeration) {
14408 LocalContext context; 14384 LocalContext context;
14409 v8::Isolate* isolate = context->GetIsolate(); 14385 v8::Isolate* isolate = context->GetIsolate();
14410 v8::HandleScope scope(isolate); 14386 v8::HandleScope scope(isolate);
14411 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::NewFromUtf8( 14387 v8::Handle<v8::Value> obj = CompileRun(
14412 context->GetIsolate(),
14413 "var result = [];" 14388 "var result = [];"
14414 "result[0] = {};" 14389 "result[0] = {};"
14415 "result[1] = {a: 1, b: 2};" 14390 "result[1] = {a: 1, b: 2};"
14416 "result[2] = [1, 2, 3];" 14391 "result[2] = [1, 2, 3];"
14417 "var proto = {x: 1, y: 2, z: 3};" 14392 "var proto = {x: 1, y: 2, z: 3};"
14418 "var x = { __proto__: proto, w: 0, z: 1 };" 14393 "var x = { __proto__: proto, w: 0, z: 1 };"
14419 "result[3] = x;" 14394 "result[3] = x;"
14420 "result;"))->Run(); 14395 "result;");
14421 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); 14396 v8::Handle<v8::Array> elms = obj.As<v8::Array>();
14422 CHECK_EQ(4, elms->Length()); 14397 CHECK_EQ(4, elms->Length());
14423 int elmc0 = 0; 14398 int elmc0 = 0;
14424 const char** elmv0 = NULL; 14399 const char** elmv0 = NULL;
14425 CheckProperties( 14400 CheckProperties(
14426 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); 14401 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0);
14427 CheckOwnProperties( 14402 CheckOwnProperties(
14428 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); 14403 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0);
14429 int elmc1 = 2; 14404 int elmc1 = 2;
14430 const char* elmv1[] = {"a", "b"}; 14405 const char* elmv1[] = {"a", "b"};
(...skipping 15 matching lines...) Expand all
14446 const char* elmv4[] = {"w", "z"}; 14421 const char* elmv4[] = {"w", "z"};
14447 CheckOwnProperties( 14422 CheckOwnProperties(
14448 isolate, elms->Get(v8::Integer::New(isolate, 3)), elmc4, elmv4); 14423 isolate, elms->Get(v8::Integer::New(isolate, 3)), elmc4, elmv4);
14449 } 14424 }
14450 14425
14451 14426
14452 THREADED_TEST(PropertyEnumeration2) { 14427 THREADED_TEST(PropertyEnumeration2) {
14453 LocalContext context; 14428 LocalContext context;
14454 v8::Isolate* isolate = context->GetIsolate(); 14429 v8::Isolate* isolate = context->GetIsolate();
14455 v8::HandleScope scope(isolate); 14430 v8::HandleScope scope(isolate);
14456 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::NewFromUtf8( 14431 v8::Handle<v8::Value> obj = CompileRun(
14457 context->GetIsolate(),
14458 "var result = [];" 14432 "var result = [];"
14459 "result[0] = {};" 14433 "result[0] = {};"
14460 "result[1] = {a: 1, b: 2};" 14434 "result[1] = {a: 1, b: 2};"
14461 "result[2] = [1, 2, 3];" 14435 "result[2] = [1, 2, 3];"
14462 "var proto = {x: 1, y: 2, z: 3};" 14436 "var proto = {x: 1, y: 2, z: 3};"
14463 "var x = { __proto__: proto, w: 0, z: 1 };" 14437 "var x = { __proto__: proto, w: 0, z: 1 };"
14464 "result[3] = x;" 14438 "result[3] = x;"
14465 "result;"))->Run(); 14439 "result;");
14466 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); 14440 v8::Handle<v8::Array> elms = obj.As<v8::Array>();
14467 CHECK_EQ(4, elms->Length()); 14441 CHECK_EQ(4, elms->Length());
14468 int elmc0 = 0; 14442 int elmc0 = 0;
14469 const char** elmv0 = NULL; 14443 const char** elmv0 = NULL;
14470 CheckProperties(isolate, 14444 CheckProperties(isolate,
14471 elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); 14445 elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0);
14472 14446
14473 v8::Handle<v8::Value> val = elms->Get(v8::Integer::New(isolate, 0)); 14447 v8::Handle<v8::Value> val = elms->Get(v8::Integer::New(isolate, 0));
14474 v8::Handle<v8::Array> props = val.As<v8::Object>()->GetPropertyNames(); 14448 v8::Handle<v8::Array> props = val.As<v8::Object>()->GetPropertyNames();
14475 CHECK_EQ(0, props->Length()); 14449 CHECK_EQ(0, props->Length());
(...skipping 2516 matching lines...) Expand 10 before | Expand all | Expand 10 after
16992 16966
16993 #undef IS_ARRAY_BUFFER_VIEW_TEST 16967 #undef IS_ARRAY_BUFFER_VIEW_TEST
16994 16968
16995 16969
16996 16970
16997 THREADED_TEST(ScriptContextDependence) { 16971 THREADED_TEST(ScriptContextDependence) {
16998 LocalContext c1; 16972 LocalContext c1;
16999 v8::HandleScope scope(c1->GetIsolate()); 16973 v8::HandleScope scope(c1->GetIsolate());
17000 const char *source = "foo"; 16974 const char *source = "foo";
17001 v8::Handle<v8::Script> dep = 16975 v8::Handle<v8::Script> dep =
17002 v8::Script::Compile(v8::String::NewFromUtf8(c1->GetIsolate(), source)); 16976 v8_compile(source);
17003 v8::Handle<v8::Script> indep = 16977 v8::Handle<v8::Script> indep =
17004 v8::Script::New(v8::String::NewFromUtf8(c1->GetIsolate(), source)); 16978 v8::Script::New(v8::String::NewFromUtf8(c1->GetIsolate(), source));
17005 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"), 16979 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"),
17006 v8::Integer::New(c1->GetIsolate(), 100)); 16980 v8::Integer::New(c1->GetIsolate(), 100));
17007 CHECK_EQ(dep->Run()->Int32Value(), 100); 16981 CHECK_EQ(dep->Run()->Int32Value(), 100);
17008 CHECK_EQ(indep->Run()->Int32Value(), 100); 16982 CHECK_EQ(indep->Run()->Int32Value(), 100);
17009 LocalContext c2; 16983 LocalContext c2;
17010 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"), 16984 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"),
17011 v8::Integer::New(c2->GetIsolate(), 101)); 16985 v8::Integer::New(c2->GetIsolate(), 101));
17012 CHECK_EQ(dep->Run()->Int32Value(), 100); 16986 CHECK_EQ(dep->Run()->Int32Value(), 100);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
17169 } 17143 }
17170 17144
17171 17145
17172 TEST(CaptureStackTraceForUncaughtException) { 17146 TEST(CaptureStackTraceForUncaughtException) {
17173 report_count = 0; 17147 report_count = 0;
17174 LocalContext env; 17148 LocalContext env;
17175 v8::HandleScope scope(env->GetIsolate()); 17149 v8::HandleScope scope(env->GetIsolate());
17176 v8::V8::AddMessageListener(StackTraceForUncaughtExceptionListener); 17150 v8::V8::AddMessageListener(StackTraceForUncaughtExceptionListener);
17177 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); 17151 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
17178 17152
17179 Script::Compile(v8_str("function foo() {\n" 17153 CompileRunWithOrigin(
17180 " throw 1;\n" 17154 "function foo() {\n"
17181 "};\n" 17155 " throw 1;\n"
17182 "function bar() {\n" 17156 "};\n"
17183 " foo();\n" 17157 "function bar() {\n"
17184 "};"), 17158 " foo();\n"
17185 v8_str("origin"))->Run(); 17159 "};",
17160 "origin");
17186 v8::Local<v8::Object> global = env->Global(); 17161 v8::Local<v8::Object> global = env->Global();
17187 Local<Value> trouble = global->Get(v8_str("bar")); 17162 Local<Value> trouble = global->Get(v8_str("bar"));
17188 CHECK(trouble->IsFunction()); 17163 CHECK(trouble->IsFunction());
17189 Function::Cast(*trouble)->Call(global, 0, NULL); 17164 Function::Cast(*trouble)->Call(global, 0, NULL);
17190 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 17165 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
17191 v8::V8::RemoveMessageListeners(StackTraceForUncaughtExceptionListener); 17166 v8::V8::RemoveMessageListeners(StackTraceForUncaughtExceptionListener);
17192 } 17167 }
17193 17168
17194 17169
17195 TEST(CaptureStackTraceForUncaughtExceptionAndSetters) { 17170 TEST(CaptureStackTraceForUncaughtExceptionAndSetters) {
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
17410 templ->Set(v8_str("AnalyzeScriptIdInStack"), 17385 templ->Set(v8_str("AnalyzeScriptIdInStack"),
17411 v8::FunctionTemplate::New(isolate, AnalyzeScriptIdInStack)); 17386 v8::FunctionTemplate::New(isolate, AnalyzeScriptIdInStack));
17412 LocalContext context(0, templ); 17387 LocalContext context(0, templ);
17413 17388
17414 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8( 17389 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8(
17415 isolate, 17390 isolate,
17416 "function foo() {\n" 17391 "function foo() {\n"
17417 " AnalyzeScriptIdInStack();" 17392 " AnalyzeScriptIdInStack();"
17418 "}\n" 17393 "}\n"
17419 "foo();\n"); 17394 "foo();\n");
17420 v8::ScriptOrigin origin = 17395 v8::Local<v8::Script> script = CompileWithOrigin(scriptSource, "test");
17421 v8::ScriptOrigin(v8::String::NewFromUtf8(isolate, "test"));
17422 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin));
17423 script->Run(); 17396 script->Run();
17424 for (int i = 0; i < 2; i++) { 17397 for (int i = 0; i < 2; i++) {
17425 CHECK(scriptIdInStack[i] != v8::Message::kNoScriptIdInfo); 17398 CHECK(scriptIdInStack[i] != v8::Message::kNoScriptIdInfo);
17426 CHECK_EQ(scriptIdInStack[i], script->GetId()); 17399 CHECK_EQ(scriptIdInStack[i], script->GetId());
17427 } 17400 }
17428 } 17401 }
17429 17402
17430 17403
17431 void AnalyzeStackOfInlineScriptWithSourceURL( 17404 void AnalyzeStackOfInlineScriptWithSourceURL(
17432 const v8::FunctionCallbackInfo<v8::Value>& args) { 17405 const v8::FunctionCallbackInfo<v8::Value>& args) {
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after
18437 " this.x = 23;" 18410 " this.x = 23;"
18438 "};" 18411 "};"
18439 "C1.prototype = P;" 18412 "C1.prototype = P;"
18440 "function C2() {" 18413 "function C2() {"
18441 " this.x = 23" 18414 " this.x = 23"
18442 "};" 18415 "};"
18443 "C2.prototype = { };" 18416 "C2.prototype = { };"
18444 "C2.prototype.__proto__ = P;"); 18417 "C2.prototype.__proto__ = P;");
18445 18418
18446 v8::Local<v8::Script> script; 18419 v8::Local<v8::Script> script;
18447 script = v8::Script::Compile(v8_str("new C1();")); 18420 script = v8_compile("new C1();");
18448 for (int i = 0; i < 10; i++) { 18421 for (int i = 0; i < 10; i++) {
18449 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); 18422 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run());
18450 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value()); 18423 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value());
18451 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value()); 18424 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value());
18452 } 18425 }
18453 18426
18454 script = v8::Script::Compile(v8_str("new C2();")); 18427 script = v8_compile("new C2();");
18455 for (int i = 0; i < 10; i++) { 18428 for (int i = 0; i < 10; i++) {
18456 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); 18429 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run());
18457 CHECK_EQ(42, c2->Get(v8_str("x"))->Int32Value()); 18430 CHECK_EQ(42, c2->Get(v8_str("x"))->Int32Value());
18458 CHECK_EQ(23, c2->Get(v8_str("y"))->Int32Value()); 18431 CHECK_EQ(23, c2->Get(v8_str("y"))->Int32Value());
18459 } 18432 }
18460 } 18433 }
18461 18434
18462 18435
18463 static void NamedPropertyGetterWhichReturns42( 18436 static void NamedPropertyGetterWhichReturns42(
18464 Local<String> name, 18437 Local<String> name,
(...skipping 24 matching lines...) Expand all
18489 " this.x = 23;" 18462 " this.x = 23;"
18490 "};" 18463 "};"
18491 "C1.prototype = P;" 18464 "C1.prototype = P;"
18492 "function C2() {" 18465 "function C2() {"
18493 " this.x = 23" 18466 " this.x = 23"
18494 "};" 18467 "};"
18495 "C2.prototype = { };" 18468 "C2.prototype = { };"
18496 "C2.prototype.__proto__ = P;"); 18469 "C2.prototype.__proto__ = P;");
18497 18470
18498 v8::Local<v8::Script> script; 18471 v8::Local<v8::Script> script;
18499 script = v8::Script::Compile(v8_str("new C1();")); 18472 script = v8_compile("new C1();");
18500 for (int i = 0; i < 10; i++) { 18473 for (int i = 0; i < 10; i++) {
18501 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); 18474 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run());
18502 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value()); 18475 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value());
18503 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); 18476 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value());
18504 } 18477 }
18505 18478
18506 script = v8::Script::Compile(v8_str("new C2();")); 18479 script = v8_compile("new C2();");
18507 for (int i = 0; i < 10; i++) { 18480 for (int i = 0; i < 10; i++) {
18508 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); 18481 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run());
18509 CHECK_EQ(23, c2->Get(v8_str("x"))->Int32Value()); 18482 CHECK_EQ(23, c2->Get(v8_str("x"))->Int32Value());
18510 CHECK_EQ(42, c2->Get(v8_str("y"))->Int32Value()); 18483 CHECK_EQ(42, c2->Get(v8_str("y"))->Int32Value());
18511 } 18484 }
18512 } 18485 }
18513 18486
18514 18487
18515 TEST(Regress618) { 18488 TEST(Regress618) {
18516 const char* source = "function C1() {" 18489 const char* source = "function C1() {"
18517 " this.x = 23;" 18490 " this.x = 23;"
18518 "};" 18491 "};"
18519 "C1.prototype = P;"; 18492 "C1.prototype = P;";
18520 18493
18521 LocalContext context; 18494 LocalContext context;
18522 v8::Isolate* isolate = context->GetIsolate(); 18495 v8::Isolate* isolate = context->GetIsolate();
18523 v8::HandleScope scope(isolate); 18496 v8::HandleScope scope(isolate);
18524 v8::Local<v8::Script> script; 18497 v8::Local<v8::Script> script;
18525 18498
18526 // Use a simple object as prototype. 18499 // Use a simple object as prototype.
18527 v8::Local<v8::Object> prototype = v8::Object::New(isolate); 18500 v8::Local<v8::Object> prototype = v8::Object::New(isolate);
18528 prototype->Set(v8_str("y"), v8_num(42)); 18501 prototype->Set(v8_str("y"), v8_num(42));
18529 context->Global()->Set(v8_str("P"), prototype); 18502 context->Global()->Set(v8_str("P"), prototype);
18530 18503
18531 // This compile will add the code to the compilation cache. 18504 // This compile will add the code to the compilation cache.
18532 CompileRun(source); 18505 CompileRun(source);
18533 18506
18534 script = v8::Script::Compile(v8_str("new C1();")); 18507 script = v8_compile("new C1();");
18535 // Allow enough iterations for the inobject slack tracking logic 18508 // Allow enough iterations for the inobject slack tracking logic
18536 // to finalize instance size and install the fast construct stub. 18509 // to finalize instance size and install the fast construct stub.
18537 for (int i = 0; i < 256; i++) { 18510 for (int i = 0; i < 256; i++) {
18538 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); 18511 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run());
18539 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value()); 18512 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value());
18540 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); 18513 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value());
18541 } 18514 }
18542 18515
18543 // Use an API object with accessors as prototype. 18516 // Use an API object with accessors as prototype.
18544 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 18517 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
18545 templ->SetAccessor(v8_str("x"), 18518 templ->SetAccessor(v8_str("x"),
18546 GetterWhichReturns42, 18519 GetterWhichReturns42,
18547 SetterWhichSetsYOnThisTo23); 18520 SetterWhichSetsYOnThisTo23);
18548 context->Global()->Set(v8_str("P"), templ->NewInstance()); 18521 context->Global()->Set(v8_str("P"), templ->NewInstance());
18549 18522
18550 // This compile will get the code from the compilation cache. 18523 // This compile will get the code from the compilation cache.
18551 CompileRun(source); 18524 CompileRun(source);
18552 18525
18553 script = v8::Script::Compile(v8_str("new C1();")); 18526 script = v8_compile("new C1();");
18554 for (int i = 0; i < 10; i++) { 18527 for (int i = 0; i < 10; i++) {
18555 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); 18528 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run());
18556 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value()); 18529 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value());
18557 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value()); 18530 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value());
18558 } 18531 }
18559 } 18532 }
18560 18533
18561 v8::Isolate* gc_callbacks_isolate = NULL; 18534 v8::Isolate* gc_callbacks_isolate = NULL;
18562 int prologue_call_count = 0; 18535 int prologue_call_count = 0;
18563 int epilogue_call_count = 0; 18536 int epilogue_call_count = 0;
(...skipping 3569 matching lines...) Expand 10 before | Expand all | Expand 10 after
22133 new v8::internal::HistogramTimer( 22106 new v8::internal::HistogramTimer(
22134 "V8.Test", 0, 10000, 50, 22107 "V8.Test", 0, 10000, 50,
22135 reinterpret_cast<v8::internal::Isolate*>(isolate)); 22108 reinterpret_cast<v8::internal::Isolate*>(isolate));
22136 histogramTimer->Start(); 22109 histogramTimer->Start();
22137 CHECK_EQ("V8.Test", last_event_message); 22110 CHECK_EQ("V8.Test", last_event_message);
22138 CHECK_EQ(0, last_event_status); 22111 CHECK_EQ(0, last_event_status);
22139 histogramTimer->Stop(); 22112 histogramTimer->Stop();
22140 CHECK_EQ("V8.Test", last_event_message); 22113 CHECK_EQ("V8.Test", last_event_message);
22141 CHECK_EQ(1, last_event_status); 22114 CHECK_EQ(1, last_event_status);
22142 } 22115 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698