| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #include "cpu-profiler.h" | 43 #include "cpu-profiler.h" |
| 44 #include "execution.h" | 44 #include "execution.h" |
| 45 #include "isolate.h" | 45 #include "isolate.h" |
| 46 #include "objects.h" | 46 #include "objects.h" |
| 47 #include "parser.h" | 47 #include "parser.h" |
| 48 #include "platform.h" | 48 #include "platform.h" |
| 49 #include "snapshot.h" | 49 #include "snapshot.h" |
| 50 #include "unicode-inl.h" | 50 #include "unicode-inl.h" |
| 51 #include "utils.h" | 51 #include "utils.h" |
| 52 #include "vm-state.h" | 52 #include "vm-state.h" |
| 53 #include "../include/v8-util.h" |
| 53 | 54 |
| 54 static const bool kLogThreading = false; | 55 static const bool kLogThreading = false; |
| 55 | 56 |
| 56 using ::v8::Boolean; | 57 using ::v8::Boolean; |
| 57 using ::v8::BooleanObject; | 58 using ::v8::BooleanObject; |
| 58 using ::v8::Context; | 59 using ::v8::Context; |
| 59 using ::v8::Extension; | 60 using ::v8::Extension; |
| 60 using ::v8::Function; | 61 using ::v8::Function; |
| 61 using ::v8::FunctionTemplate; | 62 using ::v8::FunctionTemplate; |
| 62 using ::v8::Handle; | 63 using ::v8::Handle; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 } | 198 } |
| 198 | 199 |
| 199 // Local context should still be live. | 200 // Local context should still be live. |
| 200 CHECK(!local_env.IsEmpty()); | 201 CHECK(!local_env.IsEmpty()); |
| 201 local_env->Enter(); | 202 local_env->Enter(); |
| 202 | 203 |
| 203 v8::Handle<v8::Primitive> undef = v8::Undefined(CcTest::isolate()); | 204 v8::Handle<v8::Primitive> undef = v8::Undefined(CcTest::isolate()); |
| 204 CHECK(!undef.IsEmpty()); | 205 CHECK(!undef.IsEmpty()); |
| 205 CHECK(undef->IsUndefined()); | 206 CHECK(undef->IsUndefined()); |
| 206 | 207 |
| 207 const char* c_source = "1 + 2 + 3"; | 208 const char* source = "1 + 2 + 3"; |
| 208 Local<String> source = String::NewFromUtf8(CcTest::isolate(), c_source); | 209 Local<Script> script = v8_compile(source); |
| 209 Local<Script> script = Script::Compile(source); | |
| 210 CHECK_EQ(6, script->Run()->Int32Value()); | 210 CHECK_EQ(6, script->Run()->Int32Value()); |
| 211 | 211 |
| 212 local_env->Exit(); | 212 local_env->Exit(); |
| 213 } | 213 } |
| 214 | 214 |
| 215 | 215 |
| 216 THREADED_TEST(IsolateOfContext) { | 216 THREADED_TEST(IsolateOfContext) { |
| 217 v8::HandleScope scope(CcTest::isolate()); | 217 v8::HandleScope scope(CcTest::isolate()); |
| 218 v8::Handle<Context> env = Context::New(CcTest::isolate()); | 218 v8::Handle<Context> env = Context::New(CcTest::isolate()); |
| 219 | 219 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 | 438 |
| 439 Local<v8::Array> value = CompileRun("[\"a\", \"b\"]").As<v8::Array>(); | 439 Local<v8::Array> value = CompileRun("[\"a\", \"b\"]").As<v8::Array>(); |
| 440 CHECK_EQ(v8_str("a"), value->Get(0)); | 440 CHECK_EQ(v8_str("a"), value->Get(0)); |
| 441 CHECK_EQ(v8_str("b"), value->Get(1)); | 441 CHECK_EQ(v8_str("b"), value->Get(1)); |
| 442 } | 442 } |
| 443 | 443 |
| 444 | 444 |
| 445 THREADED_TEST(Script) { | 445 THREADED_TEST(Script) { |
| 446 LocalContext env; | 446 LocalContext env; |
| 447 v8::HandleScope scope(env->GetIsolate()); | 447 v8::HandleScope scope(env->GetIsolate()); |
| 448 const char* c_source = "1 + 2 + 3"; | 448 const char* source = "1 + 2 + 3"; |
| 449 Local<String> source = String::NewFromUtf8(env->GetIsolate(), c_source); | 449 Local<Script> script = v8_compile(source); |
| 450 Local<Script> script = Script::Compile(source); | |
| 451 CHECK_EQ(6, script->Run()->Int32Value()); | 450 CHECK_EQ(6, script->Run()->Int32Value()); |
| 452 } | 451 } |
| 453 | 452 |
| 454 | 453 |
| 455 static uint16_t* AsciiToTwoByteString(const char* source) { | 454 static uint16_t* AsciiToTwoByteString(const char* source) { |
| 456 int array_length = i::StrLength(source) + 1; | 455 int array_length = i::StrLength(source) + 1; |
| 457 uint16_t* converted = i::NewArray<uint16_t>(array_length); | 456 uint16_t* converted = i::NewArray<uint16_t>(array_length); |
| 458 for (int i = 0; i < array_length; i++) converted[i] = source[i]; | 457 for (int i = 0; i < array_length; i++) converted[i] = source[i]; |
| 459 return converted; | 458 return converted; |
| 460 } | 459 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 | 518 |
| 520 THREADED_TEST(ScriptUsingStringResource) { | 519 THREADED_TEST(ScriptUsingStringResource) { |
| 521 int dispose_count = 0; | 520 int dispose_count = 0; |
| 522 const char* c_source = "1 + 2 * 3"; | 521 const char* c_source = "1 + 2 * 3"; |
| 523 uint16_t* two_byte_source = AsciiToTwoByteString(c_source); | 522 uint16_t* two_byte_source = AsciiToTwoByteString(c_source); |
| 524 { | 523 { |
| 525 LocalContext env; | 524 LocalContext env; |
| 526 v8::HandleScope scope(env->GetIsolate()); | 525 v8::HandleScope scope(env->GetIsolate()); |
| 527 TestResource* resource = new TestResource(two_byte_source, &dispose_count); | 526 TestResource* resource = new TestResource(two_byte_source, &dispose_count); |
| 528 Local<String> source = String::NewExternal(env->GetIsolate(), resource); | 527 Local<String> source = String::NewExternal(env->GetIsolate(), resource); |
| 529 Local<Script> script = Script::Compile(source); | 528 Local<Script> script = v8_compile(source); |
| 530 Local<Value> value = script->Run(); | 529 Local<Value> value = script->Run(); |
| 531 CHECK(value->IsNumber()); | 530 CHECK(value->IsNumber()); |
| 532 CHECK_EQ(7, value->Int32Value()); | 531 CHECK_EQ(7, value->Int32Value()); |
| 533 CHECK(source->IsExternal()); | 532 CHECK(source->IsExternal()); |
| 534 CHECK_EQ(resource, | 533 CHECK_EQ(resource, |
| 535 static_cast<TestResource*>(source->GetExternalStringResource())); | 534 static_cast<TestResource*>(source->GetExternalStringResource())); |
| 536 String::Encoding encoding = String::UNKNOWN_ENCODING; | 535 String::Encoding encoding = String::UNKNOWN_ENCODING; |
| 537 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), | 536 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), |
| 538 source->GetExternalStringResourceBase(&encoding)); | 537 source->GetExternalStringResourceBase(&encoding)); |
| 539 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding); | 538 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 555 TestAsciiResource* resource = new TestAsciiResource(i::StrDup(c_source), | 554 TestAsciiResource* resource = new TestAsciiResource(i::StrDup(c_source), |
| 556 &dispose_count); | 555 &dispose_count); |
| 557 Local<String> source = String::NewExternal(env->GetIsolate(), resource); | 556 Local<String> source = String::NewExternal(env->GetIsolate(), resource); |
| 558 CHECK(source->IsExternalAscii()); | 557 CHECK(source->IsExternalAscii()); |
| 559 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), | 558 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), |
| 560 source->GetExternalAsciiStringResource()); | 559 source->GetExternalAsciiStringResource()); |
| 561 String::Encoding encoding = String::UNKNOWN_ENCODING; | 560 String::Encoding encoding = String::UNKNOWN_ENCODING; |
| 562 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), | 561 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), |
| 563 source->GetExternalStringResourceBase(&encoding)); | 562 source->GetExternalStringResourceBase(&encoding)); |
| 564 CHECK_EQ(String::ASCII_ENCODING, encoding); | 563 CHECK_EQ(String::ASCII_ENCODING, encoding); |
| 565 Local<Script> script = Script::Compile(source); | 564 Local<Script> script = v8_compile(source); |
| 566 Local<Value> value = script->Run(); | 565 Local<Value> value = script->Run(); |
| 567 CHECK(value->IsNumber()); | 566 CHECK(value->IsNumber()); |
| 568 CHECK_EQ(7, value->Int32Value()); | 567 CHECK_EQ(7, value->Int32Value()); |
| 569 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 568 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 570 CHECK_EQ(0, dispose_count); | 569 CHECK_EQ(0, dispose_count); |
| 571 } | 570 } |
| 572 CcTest::i_isolate()->compilation_cache()->Clear(); | 571 CcTest::i_isolate()->compilation_cache()->Clear(); |
| 573 CcTest::heap()->CollectAllAvailableGarbage(); | 572 CcTest::heap()->CollectAllAvailableGarbage(); |
| 574 CHECK_EQ(1, dispose_count); | 573 CHECK_EQ(1, dispose_count); |
| 575 } | 574 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 587 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 586 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now |
| 588 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 587 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now |
| 589 CHECK_EQ(source->IsExternal(), false); | 588 CHECK_EQ(source->IsExternal(), false); |
| 590 CHECK_EQ(source->IsExternalAscii(), false); | 589 CHECK_EQ(source->IsExternalAscii(), false); |
| 591 String::Encoding encoding = String::UNKNOWN_ENCODING; | 590 String::Encoding encoding = String::UNKNOWN_ENCODING; |
| 592 CHECK_EQ(NULL, source->GetExternalStringResourceBase(&encoding)); | 591 CHECK_EQ(NULL, source->GetExternalStringResourceBase(&encoding)); |
| 593 CHECK_EQ(String::ASCII_ENCODING, encoding); | 592 CHECK_EQ(String::ASCII_ENCODING, encoding); |
| 594 bool success = source->MakeExternal(new TestResource(two_byte_source, | 593 bool success = source->MakeExternal(new TestResource(two_byte_source, |
| 595 &dispose_count)); | 594 &dispose_count)); |
| 596 CHECK(success); | 595 CHECK(success); |
| 597 Local<Script> script = Script::Compile(source); | 596 Local<Script> script = v8_compile(source); |
| 598 Local<Value> value = script->Run(); | 597 Local<Value> value = script->Run(); |
| 599 CHECK(value->IsNumber()); | 598 CHECK(value->IsNumber()); |
| 600 CHECK_EQ(7, value->Int32Value()); | 599 CHECK_EQ(7, value->Int32Value()); |
| 601 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 600 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 602 CHECK_EQ(0, dispose_count); | 601 CHECK_EQ(0, dispose_count); |
| 603 } | 602 } |
| 604 CcTest::i_isolate()->compilation_cache()->Clear(); | 603 CcTest::i_isolate()->compilation_cache()->Clear(); |
| 605 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 604 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
| 606 CHECK_EQ(1, dispose_count); | 605 CHECK_EQ(1, dispose_count); |
| 607 } | 606 } |
| 608 | 607 |
| 609 | 608 |
| 610 THREADED_TEST(ScriptMakingExternalAsciiString) { | 609 THREADED_TEST(ScriptMakingExternalAsciiString) { |
| 611 int dispose_count = 0; | 610 int dispose_count = 0; |
| 612 const char* c_source = "1 + 2 * 3"; | 611 const char* c_source = "1 + 2 * 3"; |
| 613 { | 612 { |
| 614 LocalContext env; | 613 LocalContext env; |
| 615 v8::HandleScope scope(env->GetIsolate()); | 614 v8::HandleScope scope(env->GetIsolate()); |
| 616 Local<String> source = v8_str(c_source); | 615 Local<String> source = v8_str(c_source); |
| 617 // Trigger GCs so that the newly allocated string moves to old gen. | 616 // Trigger GCs so that the newly allocated string moves to old gen. |
| 618 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 617 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now |
| 619 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 618 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now |
| 620 bool success = source->MakeExternal( | 619 bool success = source->MakeExternal( |
| 621 new TestAsciiResource(i::StrDup(c_source), &dispose_count)); | 620 new TestAsciiResource(i::StrDup(c_source), &dispose_count)); |
| 622 CHECK(success); | 621 CHECK(success); |
| 623 Local<Script> script = Script::Compile(source); | 622 Local<Script> script = v8_compile(source); |
| 624 Local<Value> value = script->Run(); | 623 Local<Value> value = script->Run(); |
| 625 CHECK(value->IsNumber()); | 624 CHECK(value->IsNumber()); |
| 626 CHECK_EQ(7, value->Int32Value()); | 625 CHECK_EQ(7, value->Int32Value()); |
| 627 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 626 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 628 CHECK_EQ(0, dispose_count); | 627 CHECK_EQ(0, dispose_count); |
| 629 } | 628 } |
| 630 CcTest::i_isolate()->compilation_cache()->Clear(); | 629 CcTest::i_isolate()->compilation_cache()->Clear(); |
| 631 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 630 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
| 632 CHECK_EQ(1, dispose_count); | 631 CHECK_EQ(1, dispose_count); |
| 633 } | 632 } |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 const char* c_source = "1 + 2 * 3"; | 863 const char* c_source = "1 + 2 * 3"; |
| 865 | 864 |
| 866 // Use a stack allocated external string resource allocated object. | 865 // Use a stack allocated external string resource allocated object. |
| 867 TestAsciiResourceWithDisposeControl::dispose_count = 0; | 866 TestAsciiResourceWithDisposeControl::dispose_count = 0; |
| 868 TestAsciiResourceWithDisposeControl::dispose_calls = 0; | 867 TestAsciiResourceWithDisposeControl::dispose_calls = 0; |
| 869 TestAsciiResourceWithDisposeControl res_stack(i::StrDup(c_source), false); | 868 TestAsciiResourceWithDisposeControl res_stack(i::StrDup(c_source), false); |
| 870 { | 869 { |
| 871 LocalContext env; | 870 LocalContext env; |
| 872 v8::HandleScope scope(env->GetIsolate()); | 871 v8::HandleScope scope(env->GetIsolate()); |
| 873 Local<String> source = String::NewExternal(env->GetIsolate(), &res_stack); | 872 Local<String> source = String::NewExternal(env->GetIsolate(), &res_stack); |
| 874 Local<Script> script = Script::Compile(source); | 873 Local<Script> script = v8_compile(source); |
| 875 Local<Value> value = script->Run(); | 874 Local<Value> value = script->Run(); |
| 876 CHECK(value->IsNumber()); | 875 CHECK(value->IsNumber()); |
| 877 CHECK_EQ(7, value->Int32Value()); | 876 CHECK_EQ(7, value->Int32Value()); |
| 878 CcTest::heap()->CollectAllAvailableGarbage(); | 877 CcTest::heap()->CollectAllAvailableGarbage(); |
| 879 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count); | 878 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count); |
| 880 } | 879 } |
| 881 CcTest::i_isolate()->compilation_cache()->Clear(); | 880 CcTest::i_isolate()->compilation_cache()->Clear(); |
| 882 CcTest::heap()->CollectAllAvailableGarbage(); | 881 CcTest::heap()->CollectAllAvailableGarbage(); |
| 883 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls); | 882 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls); |
| 884 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count); | 883 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count); |
| 885 | 884 |
| 886 // Use a heap allocated external string resource allocated object. | 885 // Use a heap allocated external string resource allocated object. |
| 887 TestAsciiResourceWithDisposeControl::dispose_count = 0; | 886 TestAsciiResourceWithDisposeControl::dispose_count = 0; |
| 888 TestAsciiResourceWithDisposeControl::dispose_calls = 0; | 887 TestAsciiResourceWithDisposeControl::dispose_calls = 0; |
| 889 TestAsciiResource* res_heap = | 888 TestAsciiResource* res_heap = |
| 890 new TestAsciiResourceWithDisposeControl(i::StrDup(c_source), true); | 889 new TestAsciiResourceWithDisposeControl(i::StrDup(c_source), true); |
| 891 { | 890 { |
| 892 LocalContext env; | 891 LocalContext env; |
| 893 v8::HandleScope scope(env->GetIsolate()); | 892 v8::HandleScope scope(env->GetIsolate()); |
| 894 Local<String> source = String::NewExternal(env->GetIsolate(), res_heap); | 893 Local<String> source = String::NewExternal(env->GetIsolate(), res_heap); |
| 895 Local<Script> script = Script::Compile(source); | 894 Local<Script> script = v8_compile(source); |
| 896 Local<Value> value = script->Run(); | 895 Local<Value> value = script->Run(); |
| 897 CHECK(value->IsNumber()); | 896 CHECK(value->IsNumber()); |
| 898 CHECK_EQ(7, value->Int32Value()); | 897 CHECK_EQ(7, value->Int32Value()); |
| 899 CcTest::heap()->CollectAllAvailableGarbage(); | 898 CcTest::heap()->CollectAllAvailableGarbage(); |
| 900 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count); | 899 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count); |
| 901 } | 900 } |
| 902 CcTest::i_isolate()->compilation_cache()->Clear(); | 901 CcTest::i_isolate()->compilation_cache()->Clear(); |
| 903 CcTest::heap()->CollectAllAvailableGarbage(); | 902 CcTest::heap()->CollectAllAvailableGarbage(); |
| 904 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls); | 903 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls); |
| 905 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_count); | 904 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_count); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 | 936 |
| 938 two_byte_source = AsciiToTwoByteString(two_byte_string_2); | 937 two_byte_source = AsciiToTwoByteString(two_byte_string_2); |
| 939 right = String::NewFromTwoByte(env->GetIsolate(), two_byte_source); | 938 right = String::NewFromTwoByte(env->GetIsolate(), two_byte_source); |
| 940 i::DeleteArray(two_byte_source); | 939 i::DeleteArray(two_byte_source); |
| 941 | 940 |
| 942 source = String::Concat(source, right); | 941 source = String::Concat(source, right); |
| 943 right = String::NewExternal( | 942 right = String::NewExternal( |
| 944 env->GetIsolate(), | 943 env->GetIsolate(), |
| 945 new TestResource(AsciiToTwoByteString(two_byte_extern_2))); | 944 new TestResource(AsciiToTwoByteString(two_byte_extern_2))); |
| 946 source = String::Concat(source, right); | 945 source = String::Concat(source, right); |
| 947 Local<Script> script = Script::Compile(source); | 946 Local<Script> script = v8_compile(source); |
| 948 Local<Value> value = script->Run(); | 947 Local<Value> value = script->Run(); |
| 949 CHECK(value->IsNumber()); | 948 CHECK(value->IsNumber()); |
| 950 CHECK_EQ(68, value->Int32Value()); | 949 CHECK_EQ(68, value->Int32Value()); |
| 951 } | 950 } |
| 952 CcTest::i_isolate()->compilation_cache()->Clear(); | 951 CcTest::i_isolate()->compilation_cache()->Clear(); |
| 953 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 952 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 954 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 953 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 955 } | 954 } |
| 956 | 955 |
| 957 | 956 |
| (...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2390 | 2389 |
| 2391 bottom = templ->GetFunction()->NewInstance(); | 2390 bottom = templ->GetFunction()->NewInstance(); |
| 2392 Local<v8::Object> top = templ->GetFunction()->NewInstance(); | 2391 Local<v8::Object> top = templ->GetFunction()->NewInstance(); |
| 2393 Local<v8::Object> middle = templ->GetFunction()->NewInstance(); | 2392 Local<v8::Object> middle = templ->GetFunction()->NewInstance(); |
| 2394 | 2393 |
| 2395 bottom->SetPrototype(middle); | 2394 bottom->SetPrototype(middle); |
| 2396 middle->SetPrototype(top); | 2395 middle->SetPrototype(top); |
| 2397 env->Global()->Set(v8_str("obj"), bottom); | 2396 env->Global()->Set(v8_str("obj"), bottom); |
| 2398 | 2397 |
| 2399 // Indexed and named get. | 2398 // Indexed and named get. |
| 2400 Script::Compile(v8_str("obj[0]"))->Run(); | 2399 CompileRun("obj[0]"); |
| 2401 Script::Compile(v8_str("obj.x"))->Run(); | 2400 CompileRun("obj.x"); |
| 2402 | 2401 |
| 2403 // Indexed and named set. | 2402 // Indexed and named set. |
| 2404 Script::Compile(v8_str("obj[1] = 42"))->Run(); | 2403 CompileRun("obj[1] = 42"); |
| 2405 Script::Compile(v8_str("obj.y = 42"))->Run(); | 2404 CompileRun("obj.y = 42"); |
| 2406 | 2405 |
| 2407 // Indexed and named query. | 2406 // Indexed and named query. |
| 2408 Script::Compile(v8_str("0 in obj"))->Run(); | 2407 CompileRun("0 in obj"); |
| 2409 Script::Compile(v8_str("'x' in obj"))->Run(); | 2408 CompileRun("'x' in obj"); |
| 2410 | 2409 |
| 2411 // Indexed and named deleter. | 2410 // Indexed and named deleter. |
| 2412 Script::Compile(v8_str("delete obj[0]"))->Run(); | 2411 CompileRun("delete obj[0]"); |
| 2413 Script::Compile(v8_str("delete obj.x"))->Run(); | 2412 CompileRun("delete obj.x"); |
| 2414 | 2413 |
| 2415 // Enumerators. | 2414 // Enumerators. |
| 2416 Script::Compile(v8_str("for (var p in obj) ;"))->Run(); | 2415 CompileRun("for (var p in obj) ;"); |
| 2417 } | 2416 } |
| 2418 | 2417 |
| 2419 | 2418 |
| 2420 static void PrePropertyHandlerGet( | 2419 static void PrePropertyHandlerGet( |
| 2421 Local<String> key, | 2420 Local<String> key, |
| 2422 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2421 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 2423 ApiTestFuzzer::Fuzz(); | 2422 ApiTestFuzzer::Fuzz(); |
| 2424 if (v8_str("pre")->Equals(key)) { | 2423 if (v8_str("pre")->Equals(key)) { |
| 2425 info.GetReturnValue().Set(v8_str("PrePropertyHandler: pre")); | 2424 info.GetReturnValue().Set(v8_str("PrePropertyHandler: pre")); |
| 2426 } | 2425 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2437 | 2436 |
| 2438 | 2437 |
| 2439 THREADED_TEST(PrePropertyHandler) { | 2438 THREADED_TEST(PrePropertyHandler) { |
| 2440 v8::Isolate* isolate = CcTest::isolate(); | 2439 v8::Isolate* isolate = CcTest::isolate(); |
| 2441 v8::HandleScope scope(isolate); | 2440 v8::HandleScope scope(isolate); |
| 2442 v8::Handle<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate); | 2441 v8::Handle<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate); |
| 2443 desc->InstanceTemplate()->SetNamedPropertyHandler(PrePropertyHandlerGet, | 2442 desc->InstanceTemplate()->SetNamedPropertyHandler(PrePropertyHandlerGet, |
| 2444 0, | 2443 0, |
| 2445 PrePropertyHandlerQuery); | 2444 PrePropertyHandlerQuery); |
| 2446 LocalContext env(NULL, desc->InstanceTemplate()); | 2445 LocalContext env(NULL, desc->InstanceTemplate()); |
| 2447 Script::Compile(v8_str( | 2446 CompileRun("var pre = 'Object: pre'; var on = 'Object: on';"); |
| 2448 "var pre = 'Object: pre'; var on = 'Object: on';"))->Run(); | 2447 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); | 2448 CHECK_EQ(v8_str("PrePropertyHandler: pre"), result_pre); |
| 2451 v8::Handle<Value> result_on = Script::Compile(v8_str("on"))->Run(); | 2449 v8::Handle<Value> result_on = CompileRun("on"); |
| 2452 CHECK_EQ(v8_str("Object: on"), result_on); | 2450 CHECK_EQ(v8_str("Object: on"), result_on); |
| 2453 v8::Handle<Value> result_post = Script::Compile(v8_str("post"))->Run(); | 2451 v8::Handle<Value> result_post = CompileRun("post"); |
| 2454 CHECK(result_post.IsEmpty()); | 2452 CHECK(result_post.IsEmpty()); |
| 2455 } | 2453 } |
| 2456 | 2454 |
| 2457 | 2455 |
| 2458 THREADED_TEST(UndefinedIsNotEnumerable) { | 2456 THREADED_TEST(UndefinedIsNotEnumerable) { |
| 2459 LocalContext env; | 2457 LocalContext env; |
| 2460 v8::HandleScope scope(env->GetIsolate()); | 2458 v8::HandleScope scope(env->GetIsolate()); |
| 2461 v8::Handle<Value> result = Script::Compile(v8_str( | 2459 v8::Handle<Value> result = CompileRun("this.propertyIsEnumerable(undefined)"); |
| 2462 "this.propertyIsEnumerable(undefined)"))->Run(); | |
| 2463 CHECK(result->IsFalse()); | 2460 CHECK(result->IsFalse()); |
| 2464 } | 2461 } |
| 2465 | 2462 |
| 2466 | 2463 |
| 2467 v8::Handle<Script> call_recursively_script; | 2464 v8::Handle<Script> call_recursively_script; |
| 2468 static const int kTargetRecursionDepth = 200; // near maximum | 2465 static const int kTargetRecursionDepth = 200; // near maximum |
| 2469 | 2466 |
| 2470 | 2467 |
| 2471 static void CallScriptRecursivelyCall( | 2468 static void CallScriptRecursivelyCall( |
| 2472 const v8::FunctionCallbackInfo<v8::Value>& args) { | 2469 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2505 global->Set(v8_str("callFunctionRecursively"), | 2502 global->Set(v8_str("callFunctionRecursively"), |
| 2506 v8::FunctionTemplate::New(isolate, CallFunctionRecursivelyCall)); | 2503 v8::FunctionTemplate::New(isolate, CallFunctionRecursivelyCall)); |
| 2507 LocalContext env(NULL, global); | 2504 LocalContext env(NULL, global); |
| 2508 | 2505 |
| 2509 env->Global()->Set(v8_str("depth"), v8::Integer::New(isolate, 0)); | 2506 env->Global()->Set(v8_str("depth"), v8::Integer::New(isolate, 0)); |
| 2510 call_recursively_script = v8_compile("callScriptRecursively()"); | 2507 call_recursively_script = v8_compile("callScriptRecursively()"); |
| 2511 call_recursively_script->Run(); | 2508 call_recursively_script->Run(); |
| 2512 call_recursively_script = v8::Handle<Script>(); | 2509 call_recursively_script = v8::Handle<Script>(); |
| 2513 | 2510 |
| 2514 env->Global()->Set(v8_str("depth"), v8::Integer::New(isolate, 0)); | 2511 env->Global()->Set(v8_str("depth"), v8::Integer::New(isolate, 0)); |
| 2515 Script::Compile(v8_str("callFunctionRecursively()"))->Run(); | 2512 CompileRun("callFunctionRecursively()"); |
| 2516 } | 2513 } |
| 2517 | 2514 |
| 2518 | 2515 |
| 2519 static void ThrowingPropertyHandlerGet( | 2516 static void ThrowingPropertyHandlerGet( |
| 2520 Local<String> key, | 2517 Local<String> key, |
| 2521 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2518 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 2522 ApiTestFuzzer::Fuzz(); | 2519 ApiTestFuzzer::Fuzz(); |
| 2523 info.GetReturnValue().Set(info.GetIsolate()->ThrowException(key)); | 2520 info.GetReturnValue().Set(info.GetIsolate()->ThrowException(key)); |
| 2524 } | 2521 } |
| 2525 | 2522 |
| 2526 | 2523 |
| 2527 static void ThrowingPropertyHandlerSet( | 2524 static void ThrowingPropertyHandlerSet( |
| 2528 Local<String> key, | 2525 Local<String> key, |
| 2529 Local<Value>, | 2526 Local<Value>, |
| 2530 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2527 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 2531 info.GetIsolate()->ThrowException(key); | 2528 info.GetIsolate()->ThrowException(key); |
| 2532 info.GetReturnValue().SetUndefined(); // not the same as empty handle | 2529 info.GetReturnValue().SetUndefined(); // not the same as empty handle |
| 2533 } | 2530 } |
| 2534 | 2531 |
| 2535 | 2532 |
| 2536 THREADED_TEST(CallbackExceptionRegression) { | 2533 THREADED_TEST(CallbackExceptionRegression) { |
| 2537 v8::Isolate* isolate = CcTest::isolate(); | 2534 v8::Isolate* isolate = CcTest::isolate(); |
| 2538 v8::HandleScope scope(isolate); | 2535 v8::HandleScope scope(isolate); |
| 2539 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 2536 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
| 2540 obj->SetNamedPropertyHandler(ThrowingPropertyHandlerGet, | 2537 obj->SetNamedPropertyHandler(ThrowingPropertyHandlerGet, |
| 2541 ThrowingPropertyHandlerSet); | 2538 ThrowingPropertyHandlerSet); |
| 2542 LocalContext env; | 2539 LocalContext env; |
| 2543 env->Global()->Set(v8_str("obj"), obj->NewInstance()); | 2540 env->Global()->Set(v8_str("obj"), obj->NewInstance()); |
| 2544 v8::Handle<Value> otto = Script::Compile(v8_str( | 2541 v8::Handle<Value> otto = CompileRun( |
| 2545 "try { with (obj) { otto; } } catch (e) { e; }"))->Run(); | 2542 "try { with (obj) { otto; } } catch (e) { e; }"); |
| 2546 CHECK_EQ(v8_str("otto"), otto); | 2543 CHECK_EQ(v8_str("otto"), otto); |
| 2547 v8::Handle<Value> netto = Script::Compile(v8_str( | 2544 v8::Handle<Value> netto = CompileRun( |
| 2548 "try { with (obj) { netto = 4; } } catch (e) { e; }"))->Run(); | 2545 "try { with (obj) { netto = 4; } } catch (e) { e; }"); |
| 2549 CHECK_EQ(v8_str("netto"), netto); | 2546 CHECK_EQ(v8_str("netto"), netto); |
| 2550 } | 2547 } |
| 2551 | 2548 |
| 2552 | 2549 |
| 2553 THREADED_TEST(FunctionPrototype) { | 2550 THREADED_TEST(FunctionPrototype) { |
| 2554 v8::Isolate* isolate = CcTest::isolate(); | 2551 v8::Isolate* isolate = CcTest::isolate(); |
| 2555 v8::HandleScope scope(isolate); | 2552 v8::HandleScope scope(isolate); |
| 2556 Local<v8::FunctionTemplate> Foo = v8::FunctionTemplate::New(isolate); | 2553 Local<v8::FunctionTemplate> Foo = v8::FunctionTemplate::New(isolate); |
| 2557 Foo->PrototypeTemplate()->Set(v8_str("plak"), v8_num(321)); | 2554 Foo->PrototypeTemplate()->Set(v8_str("plak"), v8_num(321)); |
| 2558 LocalContext env; | 2555 LocalContext env; |
| 2559 env->Global()->Set(v8_str("Foo"), Foo->GetFunction()); | 2556 env->Global()->Set(v8_str("Foo"), Foo->GetFunction()); |
| 2560 Local<Script> script = Script::Compile(v8_str("Foo.prototype.plak")); | 2557 Local<Script> script = v8_compile("Foo.prototype.plak"); |
| 2561 CHECK_EQ(script->Run()->Int32Value(), 321); | 2558 CHECK_EQ(script->Run()->Int32Value(), 321); |
| 2562 } | 2559 } |
| 2563 | 2560 |
| 2564 | 2561 |
| 2565 THREADED_TEST(InternalFields) { | 2562 THREADED_TEST(InternalFields) { |
| 2566 LocalContext env; | 2563 LocalContext env; |
| 2567 v8::Isolate* isolate = env->GetIsolate(); | 2564 v8::Isolate* isolate = env->GetIsolate(); |
| 2568 v8::HandleScope scope(isolate); | 2565 v8::HandleScope scope(isolate); |
| 2569 | 2566 |
| 2570 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); | 2567 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2627 | 2624 |
| 2628 int* heap_allocated = new int[100]; | 2625 int* heap_allocated = new int[100]; |
| 2629 CheckAlignedPointerInInternalField(obj, heap_allocated); | 2626 CheckAlignedPointerInInternalField(obj, heap_allocated); |
| 2630 delete[] heap_allocated; | 2627 delete[] heap_allocated; |
| 2631 | 2628 |
| 2632 int stack_allocated[100]; | 2629 int stack_allocated[100]; |
| 2633 CheckAlignedPointerInInternalField(obj, stack_allocated); | 2630 CheckAlignedPointerInInternalField(obj, stack_allocated); |
| 2634 | 2631 |
| 2635 void* huge = reinterpret_cast<void*>(~static_cast<uintptr_t>(1)); | 2632 void* huge = reinterpret_cast<void*>(~static_cast<uintptr_t>(1)); |
| 2636 CheckAlignedPointerInInternalField(obj, huge); | 2633 CheckAlignedPointerInInternalField(obj, huge); |
| 2634 |
| 2635 v8::UniquePersistent<v8::Object> persistent(isolate, obj); |
| 2636 CHECK_EQ(1, Object::InternalFieldCount(persistent)); |
| 2637 CHECK_EQ(huge, Object::GetAlignedPointerFromInternalField(persistent, 0)); |
| 2637 } | 2638 } |
| 2638 | 2639 |
| 2639 | 2640 |
| 2640 static void CheckAlignedPointerInEmbedderData(LocalContext* env, | 2641 static void CheckAlignedPointerInEmbedderData(LocalContext* env, |
| 2641 int index, | 2642 int index, |
| 2642 void* value) { | 2643 void* value) { |
| 2643 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); | 2644 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); |
| 2644 (*env)->SetAlignedPointerInEmbedderData(index, value); | 2645 (*env)->SetAlignedPointerInEmbedderData(index, value); |
| 2645 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 2646 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 2646 CHECK_EQ(value, (*env)->GetAlignedPointerFromEmbedderData(index)); | 2647 CHECK_EQ(value, (*env)->GetAlignedPointerFromEmbedderData(index)); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2837 } | 2838 } |
| 2838 | 2839 |
| 2839 | 2840 |
| 2840 THREADED_TEST(PrivateProperties) { | 2841 THREADED_TEST(PrivateProperties) { |
| 2841 LocalContext env; | 2842 LocalContext env; |
| 2842 v8::Isolate* isolate = env->GetIsolate(); | 2843 v8::Isolate* isolate = env->GetIsolate(); |
| 2843 v8::HandleScope scope(isolate); | 2844 v8::HandleScope scope(isolate); |
| 2844 | 2845 |
| 2845 v8::Local<v8::Object> obj = v8::Object::New(isolate); | 2846 v8::Local<v8::Object> obj = v8::Object::New(isolate); |
| 2846 v8::Local<v8::Private> priv1 = v8::Private::New(isolate); | 2847 v8::Local<v8::Private> priv1 = v8::Private::New(isolate); |
| 2847 v8::Local<v8::Private> priv2 = v8::Private::New(isolate, "my-private"); | 2848 v8::Local<v8::Private> priv2 = v8::Private::New(isolate, |
| 2849 v8_str("my-private")); |
| 2848 | 2850 |
| 2849 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 2851 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 2850 | 2852 |
| 2851 CHECK(priv2->Name()->Equals(v8::String::NewFromUtf8(isolate, "my-private"))); | 2853 CHECK(priv2->Name()->Equals(v8::String::NewFromUtf8(isolate, "my-private"))); |
| 2852 | 2854 |
| 2853 // Make sure delete of a non-existent private symbol property works. | 2855 // Make sure delete of a non-existent private symbol property works. |
| 2854 CHECK(obj->DeletePrivate(priv1)); | 2856 CHECK(obj->DeletePrivate(priv1)); |
| 2855 CHECK(!obj->HasPrivate(priv1)); | 2857 CHECK(!obj->HasPrivate(priv1)); |
| 2856 | 2858 |
| 2857 CHECK(obj->SetPrivate(priv1, v8::Integer::New(isolate, 1503))); | 2859 CHECK(obj->SetPrivate(priv1, v8::Integer::New(isolate, 1503))); |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3267 CHECK(!interceptor_for_hidden_properties_called); | 3269 CHECK(!interceptor_for_hidden_properties_called); |
| 3268 } | 3270 } |
| 3269 | 3271 |
| 3270 | 3272 |
| 3271 THREADED_TEST(External) { | 3273 THREADED_TEST(External) { |
| 3272 v8::HandleScope scope(CcTest::isolate()); | 3274 v8::HandleScope scope(CcTest::isolate()); |
| 3273 int x = 3; | 3275 int x = 3; |
| 3274 Local<v8::External> ext = v8::External::New(CcTest::isolate(), &x); | 3276 Local<v8::External> ext = v8::External::New(CcTest::isolate(), &x); |
| 3275 LocalContext env; | 3277 LocalContext env; |
| 3276 env->Global()->Set(v8_str("ext"), ext); | 3278 env->Global()->Set(v8_str("ext"), ext); |
| 3277 Local<Value> reext_obj = Script::Compile(v8_str("this.ext"))->Run(); | 3279 Local<Value> reext_obj = CompileRun("this.ext"); |
| 3278 v8::Handle<v8::External> reext = reext_obj.As<v8::External>(); | 3280 v8::Handle<v8::External> reext = reext_obj.As<v8::External>(); |
| 3279 int* ptr = static_cast<int*>(reext->Value()); | 3281 int* ptr = static_cast<int*>(reext->Value()); |
| 3280 CHECK_EQ(x, 3); | 3282 CHECK_EQ(x, 3); |
| 3281 *ptr = 10; | 3283 *ptr = 10; |
| 3282 CHECK_EQ(x, 10); | 3284 CHECK_EQ(x, 10); |
| 3283 | 3285 |
| 3284 // Make sure unaligned pointers are wrapped properly. | 3286 // Make sure unaligned pointers are wrapped properly. |
| 3285 char* data = i::StrDup("0123456789"); | 3287 char* data = i::StrDup("0123456789"); |
| 3286 Local<v8::Value> zero = v8::External::New(CcTest::isolate(), &data[0]); | 3288 Local<v8::Value> zero = v8::External::New(CcTest::isolate(), &data[0]); |
| 3287 Local<v8::Value> one = v8::External::New(CcTest::isolate(), &data[1]); | 3289 Local<v8::Value> one = v8::External::New(CcTest::isolate(), &data[1]); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3436 { | 3438 { |
| 3437 v8::UniquePersistent<String> unique = ReturnUnique(isolate, global); | 3439 v8::UniquePersistent<String> unique = ReturnUnique(isolate, global); |
| 3438 CHECK(unique == global); | 3440 CHECK(unique == global); |
| 3439 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count()); | 3441 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count()); |
| 3440 } | 3442 } |
| 3441 CHECK_EQ(initial_handle_count, global_handles->global_handles_count()); | 3443 CHECK_EQ(initial_handle_count, global_handles->global_handles_count()); |
| 3442 global.Reset(); | 3444 global.Reset(); |
| 3443 } | 3445 } |
| 3444 | 3446 |
| 3445 | 3447 |
| 3448 template<typename K, typename V, bool is_weak> |
| 3449 class StdPersistentValueMapTraits { |
| 3450 public: |
| 3451 static const bool kIsWeak = is_weak; |
| 3452 typedef v8::PersistentContainerValue VInt; |
| 3453 typedef std::map<K, VInt> Impl; |
| 3454 struct WeakCallbackDataType { |
| 3455 Impl* impl; |
| 3456 K key; |
| 3457 }; |
| 3458 typedef typename Impl::iterator Iterator; |
| 3459 static bool Empty(Impl* impl) { return impl->empty(); } |
| 3460 static size_t Size(Impl* impl) { return impl->size(); } |
| 3461 static void Swap(Impl& a, Impl& b) { std::swap(a, b); } // NOLINT |
| 3462 static Iterator Begin(Impl* impl) { return impl->begin(); } |
| 3463 static Iterator End(Impl* impl) { return impl->end(); } |
| 3464 static K Key(Iterator it) { return it->first; } |
| 3465 static VInt Value(Iterator it) { return it->second; } |
| 3466 static VInt Set(Impl* impl, K key, VInt value) { |
| 3467 std::pair<Iterator, bool> res = impl->insert(std::make_pair(key, value)); |
| 3468 VInt old_value = v8::kPersistentContainerNotFound; |
| 3469 if (!res.second) { |
| 3470 old_value = res.first->second; |
| 3471 res.first->second = value; |
| 3472 } |
| 3473 return old_value; |
| 3474 } |
| 3475 static VInt Get(Impl* impl, K key) { |
| 3476 Iterator it = impl->find(key); |
| 3477 if (it == impl->end()) return v8::kPersistentContainerNotFound; |
| 3478 return it->second; |
| 3479 } |
| 3480 static VInt Remove(Impl* impl, K key) { |
| 3481 Iterator it = impl->find(key); |
| 3482 if (it == impl->end()) return v8::kPersistentContainerNotFound; |
| 3483 VInt value = it->second; |
| 3484 impl->erase(it); |
| 3485 return value; |
| 3486 } |
| 3487 static void Dispose(v8::Isolate* isolate, v8::UniquePersistent<V> value, |
| 3488 Impl* impl, K key) {} |
| 3489 static WeakCallbackDataType* WeakCallbackParameter( |
| 3490 Impl* impl, const K& key, Local<V> value) { |
| 3491 WeakCallbackDataType* data = new WeakCallbackDataType; |
| 3492 data->impl = impl; |
| 3493 data->key = key; |
| 3494 return data; |
| 3495 } |
| 3496 static Impl* ImplFromWeakCallbackData( |
| 3497 const v8::WeakCallbackData<V, WeakCallbackDataType>& data) { |
| 3498 return data.GetParameter()->impl; |
| 3499 } |
| 3500 static K KeyFromWeakCallbackData( |
| 3501 const v8::WeakCallbackData<V, WeakCallbackDataType>& data) { |
| 3502 return data.GetParameter()->key; |
| 3503 } |
| 3504 static void DisposeCallbackData(WeakCallbackDataType* data) { |
| 3505 delete data; |
| 3506 } |
| 3507 }; |
| 3508 |
| 3509 |
| 3510 template<bool is_weak> |
| 3511 static void TestPersistentValueMap() { |
| 3512 LocalContext env; |
| 3513 v8::Isolate* isolate = env->GetIsolate(); |
| 3514 typedef v8::PersistentValueMap<int, v8::Object, |
| 3515 StdPersistentValueMapTraits<int, v8::Object, is_weak> > Map; |
| 3516 Map map(isolate); |
| 3517 v8::internal::GlobalHandles* global_handles = |
| 3518 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles(); |
| 3519 int initial_handle_count = global_handles->global_handles_count(); |
| 3520 CHECK_EQ(0, static_cast<int>(map.Size())); |
| 3521 { |
| 3522 HandleScope scope(isolate); |
| 3523 Local<v8::Object> obj = map.Get(7); |
| 3524 CHECK(obj.IsEmpty()); |
| 3525 Local<v8::Object> expected = v8::Object::New(isolate); |
| 3526 map.Set(7, expected); |
| 3527 CHECK_EQ(1, static_cast<int>(map.Size())); |
| 3528 obj = map.Get(7); |
| 3529 CHECK_EQ(expected, obj); |
| 3530 v8::UniquePersistent<v8::Object> removed = map.Remove(7); |
| 3531 CHECK_EQ(0, static_cast<int>(map.Size())); |
| 3532 CHECK(expected == removed); |
| 3533 removed = map.Remove(7); |
| 3534 CHECK(removed.IsEmpty()); |
| 3535 map.Set(8, expected); |
| 3536 CHECK_EQ(1, static_cast<int>(map.Size())); |
| 3537 map.Set(8, expected); |
| 3538 CHECK_EQ(1, static_cast<int>(map.Size())); |
| 3539 } |
| 3540 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count()); |
| 3541 if (is_weak) { |
| 3542 reinterpret_cast<v8::internal::Isolate*>(isolate)->heap()-> |
| 3543 CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
| 3544 } else { |
| 3545 map.Clear(); |
| 3546 } |
| 3547 CHECK_EQ(0, static_cast<int>(map.Size())); |
| 3548 CHECK_EQ(initial_handle_count, global_handles->global_handles_count()); |
| 3549 } |
| 3550 |
| 3551 |
| 3552 TEST(PersistentValueMap) { |
| 3553 TestPersistentValueMap<false>(); |
| 3554 TestPersistentValueMap<true>(); |
| 3555 } |
| 3556 |
| 3557 |
| 3446 THREADED_TEST(GlobalHandleUpcast) { | 3558 THREADED_TEST(GlobalHandleUpcast) { |
| 3447 v8::Isolate* isolate = CcTest::isolate(); | 3559 v8::Isolate* isolate = CcTest::isolate(); |
| 3448 v8::HandleScope scope(isolate); | 3560 v8::HandleScope scope(isolate); |
| 3449 v8::Local<String> local = v8::Local<String>::New(isolate, v8_str("str")); | 3561 v8::Local<String> local = v8::Local<String>::New(isolate, v8_str("str")); |
| 3450 v8::Persistent<String> global_string(isolate, local); | 3562 v8::Persistent<String> global_string(isolate, local); |
| 3451 v8::Persistent<Value>& global_value = | 3563 v8::Persistent<Value>& global_value = |
| 3452 v8::Persistent<Value>::Cast(global_string); | 3564 v8::Persistent<Value>::Cast(global_string); |
| 3453 CHECK(v8::Local<v8::Value>::New(isolate, global_value)->IsString()); | 3565 CHECK(v8::Local<v8::Value>::New(isolate, global_value)->IsString()); |
| 3454 CHECK(global_string == v8::Persistent<String>::Cast(global_value)); | 3566 CHECK(global_string == v8::Persistent<String>::Cast(global_value)); |
| 3455 global_string.Reset(); | 3567 global_string.Reset(); |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3938 heap->CollectGarbage(i::NEW_SPACE); | 4050 heap->CollectGarbage(i::NEW_SPACE); |
| 3939 | 4051 |
| 3940 // All objects should be gone. 7 global handles in total. | 4052 // All objects should be gone. 7 global handles in total. |
| 3941 CHECK_EQ(7, counter.NumberOfWeakCalls()); | 4053 CHECK_EQ(7, counter.NumberOfWeakCalls()); |
| 3942 } | 4054 } |
| 3943 | 4055 |
| 3944 | 4056 |
| 3945 THREADED_TEST(ScriptException) { | 4057 THREADED_TEST(ScriptException) { |
| 3946 LocalContext env; | 4058 LocalContext env; |
| 3947 v8::HandleScope scope(env->GetIsolate()); | 4059 v8::HandleScope scope(env->GetIsolate()); |
| 3948 Local<Script> script = Script::Compile(v8_str("throw 'panama!';")); | 4060 Local<Script> script = v8_compile("throw 'panama!';"); |
| 3949 v8::TryCatch try_catch; | 4061 v8::TryCatch try_catch; |
| 3950 Local<Value> result = script->Run(); | 4062 Local<Value> result = script->Run(); |
| 3951 CHECK(result.IsEmpty()); | 4063 CHECK(result.IsEmpty()); |
| 3952 CHECK(try_catch.HasCaught()); | 4064 CHECK(try_catch.HasCaught()); |
| 3953 String::Utf8Value exception_value(try_catch.Exception()); | 4065 String::Utf8Value exception_value(try_catch.Exception()); |
| 3954 CHECK_EQ(*exception_value, "panama!"); | 4066 CHECK_EQ(*exception_value, "panama!"); |
| 3955 } | 4067 } |
| 3956 | 4068 |
| 3957 | 4069 |
| 3958 TEST(TryCatchCustomException) { | 4070 TEST(TryCatchCustomException) { |
| 3959 LocalContext env; | 4071 LocalContext env; |
| 3960 v8::HandleScope scope(env->GetIsolate()); | 4072 v8::HandleScope scope(env->GetIsolate()); |
| 3961 v8::TryCatch try_catch; | 4073 v8::TryCatch try_catch; |
| 3962 CompileRun("function CustomError() { this.a = 'b'; }" | 4074 CompileRun("function CustomError() { this.a = 'b'; }" |
| 3963 "(function f() { throw new CustomError(); })();"); | 4075 "(function f() { throw new CustomError(); })();"); |
| 3964 CHECK(try_catch.HasCaught()); | 4076 CHECK(try_catch.HasCaught()); |
| 3965 CHECK(try_catch.Exception()->ToObject()-> | 4077 CHECK(try_catch.Exception()->ToObject()-> |
| 3966 Get(v8_str("a"))->Equals(v8_str("b"))); | 4078 Get(v8_str("a"))->Equals(v8_str("b"))); |
| 3967 } | 4079 } |
| 3968 | 4080 |
| 3969 | 4081 |
| 3970 bool message_received; | 4082 bool message_received; |
| 3971 | 4083 |
| 3972 | 4084 |
| 3973 static void check_message_0(v8::Handle<v8::Message> message, | 4085 static void check_message_0(v8::Handle<v8::Message> message, |
| 3974 v8::Handle<Value> data) { | 4086 v8::Handle<Value> data) { |
| 3975 CHECK_EQ(5.76, data->NumberValue()); | 4087 CHECK_EQ(5.76, data->NumberValue()); |
| 3976 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue()); | 4088 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue()); |
| 3977 CHECK_EQ(7.56, message->GetScriptData()->NumberValue()); | |
| 3978 CHECK(!message->IsSharedCrossOrigin()); | 4089 CHECK(!message->IsSharedCrossOrigin()); |
| 3979 message_received = true; | 4090 message_received = true; |
| 3980 } | 4091 } |
| 3981 | 4092 |
| 3982 | 4093 |
| 3983 THREADED_TEST(MessageHandler0) { | 4094 THREADED_TEST(MessageHandler0) { |
| 3984 message_received = false; | 4095 message_received = false; |
| 3985 v8::HandleScope scope(CcTest::isolate()); | 4096 v8::HandleScope scope(CcTest::isolate()); |
| 3986 CHECK(!message_received); | 4097 CHECK(!message_received); |
| 3987 LocalContext context; | 4098 LocalContext context; |
| 3988 v8::V8::AddMessageListener(check_message_0, v8_num(5.76)); | 4099 v8::V8::AddMessageListener(check_message_0, v8_num(5.76)); |
| 3989 v8::ScriptOrigin origin = | 4100 v8::Handle<v8::Script> script = CompileWithOrigin("throw 'error'", "6.75"); |
| 3990 v8::ScriptOrigin(v8_str("6.75")); | |
| 3991 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), | |
| 3992 &origin); | |
| 3993 script->SetData(v8_str("7.56")); | |
| 3994 script->Run(); | 4101 script->Run(); |
| 3995 CHECK(message_received); | 4102 CHECK(message_received); |
| 3996 // clear out the message listener | 4103 // clear out the message listener |
| 3997 v8::V8::RemoveMessageListeners(check_message_0); | 4104 v8::V8::RemoveMessageListeners(check_message_0); |
| 3998 } | 4105 } |
| 3999 | 4106 |
| 4000 | 4107 |
| 4001 static void check_message_1(v8::Handle<v8::Message> message, | 4108 static void check_message_1(v8::Handle<v8::Message> message, |
| 4002 v8::Handle<Value> data) { | 4109 v8::Handle<Value> data) { |
| 4003 CHECK(data->IsNumber()); | 4110 CHECK(data->IsNumber()); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4159 | 4266 |
| 4160 | 4267 |
| 4161 THREADED_TEST(GetSetProperty) { | 4268 THREADED_TEST(GetSetProperty) { |
| 4162 LocalContext context; | 4269 LocalContext context; |
| 4163 v8::Isolate* isolate = context->GetIsolate(); | 4270 v8::Isolate* isolate = context->GetIsolate(); |
| 4164 v8::HandleScope scope(isolate); | 4271 v8::HandleScope scope(isolate); |
| 4165 context->Global()->Set(v8_str("foo"), v8_num(14)); | 4272 context->Global()->Set(v8_str("foo"), v8_num(14)); |
| 4166 context->Global()->Set(v8_str("12"), v8_num(92)); | 4273 context->Global()->Set(v8_str("12"), v8_num(92)); |
| 4167 context->Global()->Set(v8::Integer::New(isolate, 16), v8_num(32)); | 4274 context->Global()->Set(v8::Integer::New(isolate, 16), v8_num(32)); |
| 4168 context->Global()->Set(v8_num(13), v8_num(56)); | 4275 context->Global()->Set(v8_num(13), v8_num(56)); |
| 4169 Local<Value> foo = Script::Compile(v8_str("this.foo"))->Run(); | 4276 Local<Value> foo = CompileRun("this.foo"); |
| 4170 CHECK_EQ(14, foo->Int32Value()); | 4277 CHECK_EQ(14, foo->Int32Value()); |
| 4171 Local<Value> twelve = Script::Compile(v8_str("this[12]"))->Run(); | 4278 Local<Value> twelve = CompileRun("this[12]"); |
| 4172 CHECK_EQ(92, twelve->Int32Value()); | 4279 CHECK_EQ(92, twelve->Int32Value()); |
| 4173 Local<Value> sixteen = Script::Compile(v8_str("this[16]"))->Run(); | 4280 Local<Value> sixteen = CompileRun("this[16]"); |
| 4174 CHECK_EQ(32, sixteen->Int32Value()); | 4281 CHECK_EQ(32, sixteen->Int32Value()); |
| 4175 Local<Value> thirteen = Script::Compile(v8_str("this[13]"))->Run(); | 4282 Local<Value> thirteen = CompileRun("this[13]"); |
| 4176 CHECK_EQ(56, thirteen->Int32Value()); | 4283 CHECK_EQ(56, thirteen->Int32Value()); |
| 4177 CHECK_EQ(92, | 4284 CHECK_EQ(92, |
| 4178 context->Global()->Get(v8::Integer::New(isolate, 12))->Int32Value()); | 4285 context->Global()->Get(v8::Integer::New(isolate, 12))->Int32Value()); |
| 4179 CHECK_EQ(92, context->Global()->Get(v8_str("12"))->Int32Value()); | 4286 CHECK_EQ(92, context->Global()->Get(v8_str("12"))->Int32Value()); |
| 4180 CHECK_EQ(92, context->Global()->Get(v8_num(12))->Int32Value()); | 4287 CHECK_EQ(92, context->Global()->Get(v8_num(12))->Int32Value()); |
| 4181 CHECK_EQ(32, | 4288 CHECK_EQ(32, |
| 4182 context->Global()->Get(v8::Integer::New(isolate, 16))->Int32Value()); | 4289 context->Global()->Get(v8::Integer::New(isolate, 16))->Int32Value()); |
| 4183 CHECK_EQ(32, context->Global()->Get(v8_str("16"))->Int32Value()); | 4290 CHECK_EQ(32, context->Global()->Get(v8_str("16"))->Int32Value()); |
| 4184 CHECK_EQ(32, context->Global()->Get(v8_num(16))->Int32Value()); | 4291 CHECK_EQ(32, context->Global()->Get(v8_num(16))->Int32Value()); |
| 4185 CHECK_EQ(56, | 4292 CHECK_EQ(56, |
| 4186 context->Global()->Get(v8::Integer::New(isolate, 13))->Int32Value()); | 4293 context->Global()->Get(v8::Integer::New(isolate, 13))->Int32Value()); |
| 4187 CHECK_EQ(56, context->Global()->Get(v8_str("13"))->Int32Value()); | 4294 CHECK_EQ(56, context->Global()->Get(v8_str("13"))->Int32Value()); |
| 4188 CHECK_EQ(56, context->Global()->Get(v8_num(13))->Int32Value()); | 4295 CHECK_EQ(56, context->Global()->Get(v8_num(13))->Int32Value()); |
| 4189 } | 4296 } |
| 4190 | 4297 |
| 4191 | 4298 |
| 4192 THREADED_TEST(PropertyAttributes) { | 4299 THREADED_TEST(PropertyAttributes) { |
| 4193 LocalContext context; | 4300 LocalContext context; |
| 4194 v8::HandleScope scope(context->GetIsolate()); | 4301 v8::HandleScope scope(context->GetIsolate()); |
| 4195 // none | 4302 // none |
| 4196 Local<String> prop = v8_str("none"); | 4303 Local<String> prop = v8_str("none"); |
| 4197 context->Global()->Set(prop, v8_num(7)); | 4304 context->Global()->Set(prop, v8_num(7)); |
| 4198 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(prop)); | 4305 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(prop)); |
| 4199 // read-only | 4306 // read-only |
| 4200 prop = v8_str("read_only"); | 4307 prop = v8_str("read_only"); |
| 4201 context->Global()->Set(prop, v8_num(7), v8::ReadOnly); | 4308 context->Global()->Set(prop, v8_num(7), v8::ReadOnly); |
| 4202 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value()); | 4309 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value()); |
| 4203 CHECK_EQ(v8::ReadOnly, context->Global()->GetPropertyAttributes(prop)); | 4310 CHECK_EQ(v8::ReadOnly, context->Global()->GetPropertyAttributes(prop)); |
| 4204 Script::Compile(v8_str("read_only = 9"))->Run(); | 4311 CompileRun("read_only = 9"); |
| 4205 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value()); | 4312 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value()); |
| 4206 context->Global()->Set(prop, v8_num(10)); | 4313 context->Global()->Set(prop, v8_num(10)); |
| 4207 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value()); | 4314 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value()); |
| 4208 // dont-delete | 4315 // dont-delete |
| 4209 prop = v8_str("dont_delete"); | 4316 prop = v8_str("dont_delete"); |
| 4210 context->Global()->Set(prop, v8_num(13), v8::DontDelete); | 4317 context->Global()->Set(prop, v8_num(13), v8::DontDelete); |
| 4211 CHECK_EQ(13, context->Global()->Get(prop)->Int32Value()); | 4318 CHECK_EQ(13, context->Global()->Get(prop)->Int32Value()); |
| 4212 Script::Compile(v8_str("delete dont_delete"))->Run(); | 4319 CompileRun("delete dont_delete"); |
| 4213 CHECK_EQ(13, context->Global()->Get(prop)->Int32Value()); | 4320 CHECK_EQ(13, context->Global()->Get(prop)->Int32Value()); |
| 4214 CHECK_EQ(v8::DontDelete, context->Global()->GetPropertyAttributes(prop)); | 4321 CHECK_EQ(v8::DontDelete, context->Global()->GetPropertyAttributes(prop)); |
| 4215 // dont-enum | 4322 // dont-enum |
| 4216 prop = v8_str("dont_enum"); | 4323 prop = v8_str("dont_enum"); |
| 4217 context->Global()->Set(prop, v8_num(28), v8::DontEnum); | 4324 context->Global()->Set(prop, v8_num(28), v8::DontEnum); |
| 4218 CHECK_EQ(v8::DontEnum, context->Global()->GetPropertyAttributes(prop)); | 4325 CHECK_EQ(v8::DontEnum, context->Global()->GetPropertyAttributes(prop)); |
| 4219 // absent | 4326 // absent |
| 4220 prop = v8_str("absent"); | 4327 prop = v8_str("absent"); |
| 4221 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(prop)); | 4328 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(prop)); |
| 4222 Local<Value> fake_prop = v8_num(1); | 4329 Local<Value> fake_prop = v8_num(1); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 4241 CHECK(array->Get(0)->IsUndefined()); | 4348 CHECK(array->Get(0)->IsUndefined()); |
| 4242 CHECK(!array->Has(0)); | 4349 CHECK(!array->Has(0)); |
| 4243 CHECK(array->Get(100)->IsUndefined()); | 4350 CHECK(array->Get(100)->IsUndefined()); |
| 4244 CHECK(!array->Has(100)); | 4351 CHECK(!array->Has(100)); |
| 4245 array->Set(2, v8_num(7)); | 4352 array->Set(2, v8_num(7)); |
| 4246 CHECK_EQ(3, array->Length()); | 4353 CHECK_EQ(3, array->Length()); |
| 4247 CHECK(!array->Has(0)); | 4354 CHECK(!array->Has(0)); |
| 4248 CHECK(!array->Has(1)); | 4355 CHECK(!array->Has(1)); |
| 4249 CHECK(array->Has(2)); | 4356 CHECK(array->Has(2)); |
| 4250 CHECK_EQ(7, array->Get(2)->Int32Value()); | 4357 CHECK_EQ(7, array->Get(2)->Int32Value()); |
| 4251 Local<Value> obj = Script::Compile(v8_str("[1, 2, 3]"))->Run(); | 4358 Local<Value> obj = CompileRun("[1, 2, 3]"); |
| 4252 Local<v8::Array> arr = obj.As<v8::Array>(); | 4359 Local<v8::Array> arr = obj.As<v8::Array>(); |
| 4253 CHECK_EQ(3, arr->Length()); | 4360 CHECK_EQ(3, arr->Length()); |
| 4254 CHECK_EQ(1, arr->Get(0)->Int32Value()); | 4361 CHECK_EQ(1, arr->Get(0)->Int32Value()); |
| 4255 CHECK_EQ(2, arr->Get(1)->Int32Value()); | 4362 CHECK_EQ(2, arr->Get(1)->Int32Value()); |
| 4256 CHECK_EQ(3, arr->Get(2)->Int32Value()); | 4363 CHECK_EQ(3, arr->Get(2)->Int32Value()); |
| 4257 array = v8::Array::New(context->GetIsolate(), 27); | 4364 array = v8::Array::New(context->GetIsolate(), 27); |
| 4258 CHECK_EQ(27, array->Length()); | 4365 CHECK_EQ(27, array->Length()); |
| 4259 array = v8::Array::New(context->GetIsolate(), -27); | 4366 array = v8::Array::New(context->GetIsolate(), -27); |
| 4260 CHECK_EQ(0, array->Length()); | 4367 CHECK_EQ(0, array->Length()); |
| 4261 } | 4368 } |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4412 static const int K = 1024; | 4519 static const int K = 1024; |
| 4413 v8::ResourceConstraints constraints; | 4520 v8::ResourceConstraints constraints; |
| 4414 constraints.set_max_young_space_size(256 * K); | 4521 constraints.set_max_young_space_size(256 * K); |
| 4415 constraints.set_max_old_space_size(5 * K * K); | 4522 constraints.set_max_old_space_size(5 * K * K); |
| 4416 v8::SetResourceConstraints(CcTest::isolate(), &constraints); | 4523 v8::SetResourceConstraints(CcTest::isolate(), &constraints); |
| 4417 | 4524 |
| 4418 // Execute a script that causes out of memory. | 4525 // Execute a script that causes out of memory. |
| 4419 LocalContext context; | 4526 LocalContext context; |
| 4420 v8::HandleScope scope(context->GetIsolate()); | 4527 v8::HandleScope scope(context->GetIsolate()); |
| 4421 v8::V8::IgnoreOutOfMemoryException(); | 4528 v8::V8::IgnoreOutOfMemoryException(); |
| 4422 Local<Script> script = Script::Compile(String::NewFromUtf8( | 4529 Local<Value> result = CompileRun(js_code_causing_out_of_memory); |
| 4423 context->GetIsolate(), js_code_causing_out_of_memory)); | |
| 4424 Local<Value> result = script->Run(); | |
| 4425 | 4530 |
| 4426 // Check for out of memory state. | 4531 // Check for out of memory state. |
| 4427 CHECK(result.IsEmpty()); | 4532 CHECK(result.IsEmpty()); |
| 4428 CHECK(context->HasOutOfMemoryException()); | 4533 CHECK(context->HasOutOfMemoryException()); |
| 4429 } | 4534 } |
| 4430 | 4535 |
| 4431 | 4536 |
| 4432 void ProvokeOutOfMemory(const v8::FunctionCallbackInfo<v8::Value>& args) { | 4537 void ProvokeOutOfMemory(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 4433 ApiTestFuzzer::Fuzz(); | 4538 ApiTestFuzzer::Fuzz(); |
| 4434 | 4539 |
| 4435 LocalContext context; | 4540 LocalContext context; |
| 4436 v8::HandleScope scope(context->GetIsolate()); | 4541 v8::HandleScope scope(context->GetIsolate()); |
| 4437 Local<Script> script = Script::Compile(String::NewFromUtf8( | 4542 Local<Value> result = CompileRun(js_code_causing_out_of_memory); |
| 4438 context->GetIsolate(), js_code_causing_out_of_memory)); | |
| 4439 Local<Value> result = script->Run(); | |
| 4440 | 4543 |
| 4441 // Check for out of memory state. | 4544 // Check for out of memory state. |
| 4442 CHECK(result.IsEmpty()); | 4545 CHECK(result.IsEmpty()); |
| 4443 CHECK(context->HasOutOfMemoryException()); | 4546 CHECK(context->HasOutOfMemoryException()); |
| 4444 | 4547 |
| 4445 args.GetReturnValue().Set(result); | 4548 args.GetReturnValue().Set(result); |
| 4446 } | 4549 } |
| 4447 | 4550 |
| 4448 | 4551 |
| 4449 TEST(OutOfMemoryNested) { | 4552 TEST(OutOfMemoryNested) { |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4727 } | 4830 } |
| 4728 | 4831 |
| 4729 | 4832 |
| 4730 void CCatcher(const v8::FunctionCallbackInfo<v8::Value>& args) { | 4833 void CCatcher(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 4731 if (args.Length() < 1) { | 4834 if (args.Length() < 1) { |
| 4732 args.GetReturnValue().Set(false); | 4835 args.GetReturnValue().Set(false); |
| 4733 return; | 4836 return; |
| 4734 } | 4837 } |
| 4735 v8::HandleScope scope(args.GetIsolate()); | 4838 v8::HandleScope scope(args.GetIsolate()); |
| 4736 v8::TryCatch try_catch; | 4839 v8::TryCatch try_catch; |
| 4737 Local<Value> result = v8::Script::Compile(args[0]->ToString())->Run(); | 4840 Local<Value> result = CompileRun(args[0]->ToString()); |
| 4738 CHECK(!try_catch.HasCaught() || result.IsEmpty()); | 4841 CHECK(!try_catch.HasCaught() || result.IsEmpty()); |
| 4739 args.GetReturnValue().Set(try_catch.HasCaught()); | 4842 args.GetReturnValue().Set(try_catch.HasCaught()); |
| 4740 } | 4843 } |
| 4741 | 4844 |
| 4742 | 4845 |
| 4743 THREADED_TEST(APICatch) { | 4846 THREADED_TEST(APICatch) { |
| 4744 v8::Isolate* isolate = CcTest::isolate(); | 4847 v8::Isolate* isolate = CcTest::isolate(); |
| 4745 v8::HandleScope scope(isolate); | 4848 v8::HandleScope scope(isolate); |
| 4746 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 4849 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
| 4747 templ->Set(v8_str("ThrowFromC"), | 4850 templ->Set(v8_str("ThrowFromC"), |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4989 | 5092 |
| 4990 THREADED_TEST(ExternalScriptException) { | 5093 THREADED_TEST(ExternalScriptException) { |
| 4991 v8::Isolate* isolate = CcTest::isolate(); | 5094 v8::Isolate* isolate = CcTest::isolate(); |
| 4992 v8::HandleScope scope(isolate); | 5095 v8::HandleScope scope(isolate); |
| 4993 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 5096 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
| 4994 templ->Set(v8_str("ThrowFromC"), | 5097 templ->Set(v8_str("ThrowFromC"), |
| 4995 v8::FunctionTemplate::New(isolate, ThrowFromC)); | 5098 v8::FunctionTemplate::New(isolate, ThrowFromC)); |
| 4996 LocalContext context(0, templ); | 5099 LocalContext context(0, templ); |
| 4997 | 5100 |
| 4998 v8::TryCatch try_catch; | 5101 v8::TryCatch try_catch; |
| 4999 Local<Script> script | 5102 Local<Value> result = CompileRun("ThrowFromC(); throw 'panama';"); |
| 5000 = Script::Compile(v8_str("ThrowFromC(); throw 'panama';")); | |
| 5001 Local<Value> result = script->Run(); | |
| 5002 CHECK(result.IsEmpty()); | 5103 CHECK(result.IsEmpty()); |
| 5003 CHECK(try_catch.HasCaught()); | 5104 CHECK(try_catch.HasCaught()); |
| 5004 String::Utf8Value exception_value(try_catch.Exception()); | 5105 String::Utf8Value exception_value(try_catch.Exception()); |
| 5005 CHECK_EQ("konto", *exception_value); | 5106 CHECK_EQ("konto", *exception_value); |
| 5006 } | 5107 } |
| 5007 | 5108 |
| 5008 | 5109 |
| 5009 | 5110 |
| 5010 void CThrowCountDown(const v8::FunctionCallbackInfo<v8::Value>& args) { | 5111 void CThrowCountDown(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 5011 ApiTestFuzzer::Fuzz(); | 5112 ApiTestFuzzer::Fuzz(); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5183 CHECK(result->Get(v8::Integer::New(isolate, 3))->IsNull()); | 5284 CHECK(result->Get(v8::Integer::New(isolate, 3))->IsNull()); |
| 5184 CHECK(result->Get(v8::Integer::New(isolate, 4))->IsUndefined()); | 5285 CHECK(result->Get(v8::Integer::New(isolate, 4))->IsUndefined()); |
| 5185 } | 5286 } |
| 5186 | 5287 |
| 5187 | 5288 |
| 5188 THREADED_TEST(CatchZero) { | 5289 THREADED_TEST(CatchZero) { |
| 5189 LocalContext context; | 5290 LocalContext context; |
| 5190 v8::HandleScope scope(context->GetIsolate()); | 5291 v8::HandleScope scope(context->GetIsolate()); |
| 5191 v8::TryCatch try_catch; | 5292 v8::TryCatch try_catch; |
| 5192 CHECK(!try_catch.HasCaught()); | 5293 CHECK(!try_catch.HasCaught()); |
| 5193 Script::Compile(v8_str("throw 10"))->Run(); | 5294 CompileRun("throw 10"); |
| 5194 CHECK(try_catch.HasCaught()); | 5295 CHECK(try_catch.HasCaught()); |
| 5195 CHECK_EQ(10, try_catch.Exception()->Int32Value()); | 5296 CHECK_EQ(10, try_catch.Exception()->Int32Value()); |
| 5196 try_catch.Reset(); | 5297 try_catch.Reset(); |
| 5197 CHECK(!try_catch.HasCaught()); | 5298 CHECK(!try_catch.HasCaught()); |
| 5198 Script::Compile(v8_str("throw 0"))->Run(); | 5299 CompileRun("throw 0"); |
| 5199 CHECK(try_catch.HasCaught()); | 5300 CHECK(try_catch.HasCaught()); |
| 5200 CHECK_EQ(0, try_catch.Exception()->Int32Value()); | 5301 CHECK_EQ(0, try_catch.Exception()->Int32Value()); |
| 5201 } | 5302 } |
| 5202 | 5303 |
| 5203 | 5304 |
| 5204 THREADED_TEST(CatchExceptionFromWith) { | 5305 THREADED_TEST(CatchExceptionFromWith) { |
| 5205 LocalContext context; | 5306 LocalContext context; |
| 5206 v8::HandleScope scope(context->GetIsolate()); | 5307 v8::HandleScope scope(context->GetIsolate()); |
| 5207 v8::TryCatch try_catch; | 5308 v8::TryCatch try_catch; |
| 5208 CHECK(!try_catch.HasCaught()); | 5309 CHECK(!try_catch.HasCaught()); |
| 5209 Script::Compile(v8_str("var o = {}; with (o) { throw 42; }"))->Run(); | 5310 CompileRun("var o = {}; with (o) { throw 42; }"); |
| 5210 CHECK(try_catch.HasCaught()); | 5311 CHECK(try_catch.HasCaught()); |
| 5211 } | 5312 } |
| 5212 | 5313 |
| 5213 | 5314 |
| 5214 THREADED_TEST(TryCatchAndFinallyHidingException) { | 5315 THREADED_TEST(TryCatchAndFinallyHidingException) { |
| 5215 LocalContext context; | 5316 LocalContext context; |
| 5216 v8::HandleScope scope(context->GetIsolate()); | 5317 v8::HandleScope scope(context->GetIsolate()); |
| 5217 v8::TryCatch try_catch; | 5318 v8::TryCatch try_catch; |
| 5218 CHECK(!try_catch.HasCaught()); | 5319 CHECK(!try_catch.HasCaught()); |
| 5219 CompileRun("function f(k) { try { this[k]; } finally { return 0; } };"); | 5320 CompileRun("function f(k) { try { this[k]; } finally { return 0; } };"); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5351 CHECK(!v8_num(0.0)->SameValue(v8_num(-0.0))); | 5452 CHECK(!v8_num(0.0)->SameValue(v8_num(-0.0))); |
| 5352 CHECK(not_a_number->SameValue(not_a_number)); | 5453 CHECK(not_a_number->SameValue(not_a_number)); |
| 5353 CHECK(v8::False(isolate)->SameValue(v8::False(isolate))); | 5454 CHECK(v8::False(isolate)->SameValue(v8::False(isolate))); |
| 5354 CHECK(!v8::False(isolate)->SameValue(v8::Undefined(isolate))); | 5455 CHECK(!v8::False(isolate)->SameValue(v8::Undefined(isolate))); |
| 5355 } | 5456 } |
| 5356 | 5457 |
| 5357 | 5458 |
| 5358 THREADED_TEST(MultiRun) { | 5459 THREADED_TEST(MultiRun) { |
| 5359 LocalContext context; | 5460 LocalContext context; |
| 5360 v8::HandleScope scope(context->GetIsolate()); | 5461 v8::HandleScope scope(context->GetIsolate()); |
| 5361 Local<Script> script = Script::Compile(v8_str("x")); | 5462 Local<Script> script = v8_compile("x"); |
| 5362 for (int i = 0; i < 10; i++) | 5463 for (int i = 0; i < 10; i++) |
| 5363 script->Run(); | 5464 script->Run(); |
| 5364 } | 5465 } |
| 5365 | 5466 |
| 5366 | 5467 |
| 5367 static void GetXValue(Local<String> name, | 5468 static void GetXValue(Local<String> name, |
| 5368 const v8::PropertyCallbackInfo<v8::Value>& info) { | 5469 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 5369 ApiTestFuzzer::Fuzz(); | 5470 ApiTestFuzzer::Fuzz(); |
| 5370 CHECK_EQ(info.Data(), v8_str("donut")); | 5471 CHECK_EQ(info.Data(), v8_str("donut")); |
| 5371 CHECK_EQ(name, v8_str("x")); | 5472 CHECK_EQ(name, v8_str("x")); |
| 5372 info.GetReturnValue().Set(name); | 5473 info.GetReturnValue().Set(name); |
| 5373 } | 5474 } |
| 5374 | 5475 |
| 5375 | 5476 |
| 5376 THREADED_TEST(SimplePropertyRead) { | 5477 THREADED_TEST(SimplePropertyRead) { |
| 5377 LocalContext context; | 5478 LocalContext context; |
| 5378 v8::Isolate* isolate = context->GetIsolate(); | 5479 v8::Isolate* isolate = context->GetIsolate(); |
| 5379 v8::HandleScope scope(isolate); | 5480 v8::HandleScope scope(isolate); |
| 5380 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 5481 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
| 5381 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); | 5482 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); |
| 5382 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 5483 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
| 5383 Local<Script> script = Script::Compile(v8_str("obj.x")); | 5484 Local<Script> script = v8_compile("obj.x"); |
| 5384 for (int i = 0; i < 10; i++) { | 5485 for (int i = 0; i < 10; i++) { |
| 5385 Local<Value> result = script->Run(); | 5486 Local<Value> result = script->Run(); |
| 5386 CHECK_EQ(result, v8_str("x")); | 5487 CHECK_EQ(result, v8_str("x")); |
| 5387 } | 5488 } |
| 5388 } | 5489 } |
| 5389 | 5490 |
| 5390 | 5491 |
| 5391 THREADED_TEST(DefinePropertyOnAPIAccessor) { | 5492 THREADED_TEST(DefinePropertyOnAPIAccessor) { |
| 5392 LocalContext context; | 5493 LocalContext context; |
| 5393 v8::Isolate* isolate = context->GetIsolate(); | 5494 v8::Isolate* isolate = context->GetIsolate(); |
| 5394 v8::HandleScope scope(isolate); | 5495 v8::HandleScope scope(isolate); |
| 5395 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 5496 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
| 5396 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); | 5497 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); |
| 5397 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 5498 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
| 5398 | 5499 |
| 5399 // Uses getOwnPropertyDescriptor to check the configurable status | 5500 // Uses getOwnPropertyDescriptor to check the configurable status |
| 5400 Local<Script> script_desc | 5501 Local<Script> script_desc = v8_compile( |
| 5401 = Script::Compile(v8_str("var prop = Object.getOwnPropertyDescriptor( " | 5502 "var prop = Object.getOwnPropertyDescriptor( " |
| 5402 "obj, 'x');" | 5503 "obj, 'x');" |
| 5403 "prop.configurable;")); | 5504 "prop.configurable;"); |
| 5404 Local<Value> result = script_desc->Run(); | 5505 Local<Value> result = script_desc->Run(); |
| 5405 CHECK_EQ(result->BooleanValue(), true); | 5506 CHECK_EQ(result->BooleanValue(), true); |
| 5406 | 5507 |
| 5407 // Redefine get - but still configurable | 5508 // Redefine get - but still configurable |
| 5408 Local<Script> script_define | 5509 Local<Script> script_define = v8_compile( |
| 5409 = Script::Compile(v8_str("var desc = { get: function(){return 42; }," | 5510 "var desc = { get: function(){return 42; }," |
| 5410 " configurable: true };" | 5511 " configurable: true };" |
| 5411 "Object.defineProperty(obj, 'x', desc);" | 5512 "Object.defineProperty(obj, 'x', desc);" |
| 5412 "obj.x")); | 5513 "obj.x"); |
| 5413 result = script_define->Run(); | 5514 result = script_define->Run(); |
| 5414 CHECK_EQ(result, v8_num(42)); | 5515 CHECK_EQ(result, v8_num(42)); |
| 5415 | 5516 |
| 5416 // Check that the accessor is still configurable | 5517 // Check that the accessor is still configurable |
| 5417 result = script_desc->Run(); | 5518 result = script_desc->Run(); |
| 5418 CHECK_EQ(result->BooleanValue(), true); | 5519 CHECK_EQ(result->BooleanValue(), true); |
| 5419 | 5520 |
| 5420 // Redefine to a non-configurable | 5521 // Redefine to a non-configurable |
| 5421 script_define | 5522 script_define = v8_compile( |
| 5422 = Script::Compile(v8_str("var desc = { get: function(){return 43; }," | 5523 "var desc = { get: function(){return 43; }," |
| 5423 " configurable: false };" | 5524 " configurable: false };" |
| 5424 "Object.defineProperty(obj, 'x', desc);" | 5525 "Object.defineProperty(obj, 'x', desc);" |
| 5425 "obj.x")); | 5526 "obj.x"); |
| 5426 result = script_define->Run(); | 5527 result = script_define->Run(); |
| 5427 CHECK_EQ(result, v8_num(43)); | 5528 CHECK_EQ(result, v8_num(43)); |
| 5428 result = script_desc->Run(); | 5529 result = script_desc->Run(); |
| 5429 CHECK_EQ(result->BooleanValue(), false); | 5530 CHECK_EQ(result->BooleanValue(), false); |
| 5430 | 5531 |
| 5431 // Make sure that it is not possible to redefine again | 5532 // Make sure that it is not possible to redefine again |
| 5432 v8::TryCatch try_catch; | 5533 v8::TryCatch try_catch; |
| 5433 result = script_define->Run(); | 5534 result = script_define->Run(); |
| 5434 CHECK(try_catch.HasCaught()); | 5535 CHECK(try_catch.HasCaught()); |
| 5435 String::Utf8Value exception_value(try_catch.Exception()); | 5536 String::Utf8Value exception_value(try_catch.Exception()); |
| 5436 CHECK_EQ(*exception_value, "TypeError: Cannot redefine property: x"); | 5537 CHECK_EQ(*exception_value, "TypeError: Cannot redefine property: x"); |
| 5437 } | 5538 } |
| 5438 | 5539 |
| 5439 | 5540 |
| 5440 THREADED_TEST(DefinePropertyOnDefineGetterSetter) { | 5541 THREADED_TEST(DefinePropertyOnDefineGetterSetter) { |
| 5441 v8::Isolate* isolate = CcTest::isolate(); | 5542 v8::Isolate* isolate = CcTest::isolate(); |
| 5442 v8::HandleScope scope(isolate); | 5543 v8::HandleScope scope(isolate); |
| 5443 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 5544 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
| 5444 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); | 5545 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); |
| 5445 LocalContext context; | 5546 LocalContext context; |
| 5446 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 5547 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
| 5447 | 5548 |
| 5448 Local<Script> script_desc = Script::Compile(v8_str("var prop =" | 5549 Local<Script> script_desc = v8_compile( |
| 5449 "Object.getOwnPropertyDescriptor( " | 5550 "var prop =" |
| 5450 "obj, 'x');" | 5551 "Object.getOwnPropertyDescriptor( " |
| 5451 "prop.configurable;")); | 5552 "obj, 'x');" |
| 5553 "prop.configurable;"); |
| 5452 Local<Value> result = script_desc->Run(); | 5554 Local<Value> result = script_desc->Run(); |
| 5453 CHECK_EQ(result->BooleanValue(), true); | 5555 CHECK_EQ(result->BooleanValue(), true); |
| 5454 | 5556 |
| 5455 Local<Script> script_define = | 5557 Local<Script> script_define = v8_compile( |
| 5456 Script::Compile(v8_str("var desc = {get: function(){return 42; }," | 5558 "var desc = {get: function(){return 42; }," |
| 5457 " configurable: true };" | 5559 " configurable: true };" |
| 5458 "Object.defineProperty(obj, 'x', desc);" | 5560 "Object.defineProperty(obj, 'x', desc);" |
| 5459 "obj.x")); | 5561 "obj.x"); |
| 5460 result = script_define->Run(); | 5562 result = script_define->Run(); |
| 5461 CHECK_EQ(result, v8_num(42)); | 5563 CHECK_EQ(result, v8_num(42)); |
| 5462 | 5564 |
| 5463 | 5565 |
| 5464 result = script_desc->Run(); | 5566 result = script_desc->Run(); |
| 5465 CHECK_EQ(result->BooleanValue(), true); | 5567 CHECK_EQ(result->BooleanValue(), true); |
| 5466 | 5568 |
| 5467 | 5569 |
| 5468 script_define = | 5570 script_define = v8_compile( |
| 5469 Script::Compile(v8_str("var desc = {get: function(){return 43; }," | 5571 "var desc = {get: function(){return 43; }," |
| 5470 " configurable: false };" | 5572 " configurable: false };" |
| 5471 "Object.defineProperty(obj, 'x', desc);" | 5573 "Object.defineProperty(obj, 'x', desc);" |
| 5472 "obj.x")); | 5574 "obj.x"); |
| 5473 result = script_define->Run(); | 5575 result = script_define->Run(); |
| 5474 CHECK_EQ(result, v8_num(43)); | 5576 CHECK_EQ(result, v8_num(43)); |
| 5475 result = script_desc->Run(); | 5577 result = script_desc->Run(); |
| 5476 | 5578 |
| 5477 CHECK_EQ(result->BooleanValue(), false); | 5579 CHECK_EQ(result->BooleanValue(), false); |
| 5478 | 5580 |
| 5479 v8::TryCatch try_catch; | 5581 v8::TryCatch try_catch; |
| 5480 result = script_define->Run(); | 5582 result = script_define->Run(); |
| 5481 CHECK(try_catch.HasCaught()); | 5583 CHECK(try_catch.HasCaught()); |
| 5482 String::Utf8Value exception_value(try_catch.Exception()); | 5584 String::Utf8Value exception_value(try_catch.Exception()); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5661 } | 5763 } |
| 5662 | 5764 |
| 5663 | 5765 |
| 5664 THREADED_TEST(SimplePropertyWrite) { | 5766 THREADED_TEST(SimplePropertyWrite) { |
| 5665 v8::Isolate* isolate = CcTest::isolate(); | 5767 v8::Isolate* isolate = CcTest::isolate(); |
| 5666 v8::HandleScope scope(isolate); | 5768 v8::HandleScope scope(isolate); |
| 5667 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 5769 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
| 5668 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut")); | 5770 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut")); |
| 5669 LocalContext context; | 5771 LocalContext context; |
| 5670 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 5772 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
| 5671 Local<Script> script = Script::Compile(v8_str("obj.x = 4")); | 5773 Local<Script> script = v8_compile("obj.x = 4"); |
| 5672 for (int i = 0; i < 10; i++) { | 5774 for (int i = 0; i < 10; i++) { |
| 5673 CHECK(xValue.IsEmpty()); | 5775 CHECK(xValue.IsEmpty()); |
| 5674 script->Run(); | 5776 script->Run(); |
| 5675 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue)); | 5777 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue)); |
| 5676 xValue.Reset(); | 5778 xValue.Reset(); |
| 5677 } | 5779 } |
| 5678 } | 5780 } |
| 5679 | 5781 |
| 5680 | 5782 |
| 5681 THREADED_TEST(SetterOnly) { | 5783 THREADED_TEST(SetterOnly) { |
| 5682 v8::Isolate* isolate = CcTest::isolate(); | 5784 v8::Isolate* isolate = CcTest::isolate(); |
| 5683 v8::HandleScope scope(isolate); | 5785 v8::HandleScope scope(isolate); |
| 5684 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 5786 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
| 5685 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut")); | 5787 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut")); |
| 5686 LocalContext context; | 5788 LocalContext context; |
| 5687 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 5789 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
| 5688 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); | 5790 Local<Script> script = v8_compile("obj.x = 4; obj.x"); |
| 5689 for (int i = 0; i < 10; i++) { | 5791 for (int i = 0; i < 10; i++) { |
| 5690 CHECK(xValue.IsEmpty()); | 5792 CHECK(xValue.IsEmpty()); |
| 5691 script->Run(); | 5793 script->Run(); |
| 5692 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue)); | 5794 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue)); |
| 5693 xValue.Reset(); | 5795 xValue.Reset(); |
| 5694 } | 5796 } |
| 5695 } | 5797 } |
| 5696 | 5798 |
| 5697 | 5799 |
| 5698 THREADED_TEST(NoAccessors) { | 5800 THREADED_TEST(NoAccessors) { |
| 5699 v8::Isolate* isolate = CcTest::isolate(); | 5801 v8::Isolate* isolate = CcTest::isolate(); |
| 5700 v8::HandleScope scope(isolate); | 5802 v8::HandleScope scope(isolate); |
| 5701 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 5803 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
| 5702 templ->SetAccessor(v8_str("x"), | 5804 templ->SetAccessor(v8_str("x"), |
| 5703 static_cast<v8::AccessorGetterCallback>(NULL), | 5805 static_cast<v8::AccessorGetterCallback>(NULL), |
| 5704 NULL, | 5806 NULL, |
| 5705 v8_str("donut")); | 5807 v8_str("donut")); |
| 5706 LocalContext context; | 5808 LocalContext context; |
| 5707 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 5809 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
| 5708 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); | 5810 Local<Script> script = v8_compile("obj.x = 4; obj.x"); |
| 5709 for (int i = 0; i < 10; i++) { | 5811 for (int i = 0; i < 10; i++) { |
| 5710 script->Run(); | 5812 script->Run(); |
| 5711 } | 5813 } |
| 5712 } | 5814 } |
| 5713 | 5815 |
| 5714 | 5816 |
| 5715 static void XPropertyGetter(Local<String> property, | 5817 static void XPropertyGetter(Local<String> property, |
| 5716 const v8::PropertyCallbackInfo<v8::Value>& info) { | 5818 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 5717 ApiTestFuzzer::Fuzz(); | 5819 ApiTestFuzzer::Fuzz(); |
| 5718 CHECK(info.Data()->IsUndefined()); | 5820 CHECK(info.Data()->IsUndefined()); |
| 5719 info.GetReturnValue().Set(property); | 5821 info.GetReturnValue().Set(property); |
| 5720 } | 5822 } |
| 5721 | 5823 |
| 5722 | 5824 |
| 5723 THREADED_TEST(NamedInterceptorPropertyRead) { | 5825 THREADED_TEST(NamedInterceptorPropertyRead) { |
| 5724 v8::Isolate* isolate = CcTest::isolate(); | 5826 v8::Isolate* isolate = CcTest::isolate(); |
| 5725 v8::HandleScope scope(isolate); | 5827 v8::HandleScope scope(isolate); |
| 5726 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 5828 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
| 5727 templ->SetNamedPropertyHandler(XPropertyGetter); | 5829 templ->SetNamedPropertyHandler(XPropertyGetter); |
| 5728 LocalContext context; | 5830 LocalContext context; |
| 5729 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 5831 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
| 5730 Local<Script> script = Script::Compile(v8_str("obj.x")); | 5832 Local<Script> script = v8_compile("obj.x"); |
| 5731 for (int i = 0; i < 10; i++) { | 5833 for (int i = 0; i < 10; i++) { |
| 5732 Local<Value> result = script->Run(); | 5834 Local<Value> result = script->Run(); |
| 5733 CHECK_EQ(result, v8_str("x")); | 5835 CHECK_EQ(result, v8_str("x")); |
| 5734 } | 5836 } |
| 5735 } | 5837 } |
| 5736 | 5838 |
| 5737 | 5839 |
| 5738 THREADED_TEST(NamedInterceptorDictionaryIC) { | 5840 THREADED_TEST(NamedInterceptorDictionaryIC) { |
| 5739 v8::Isolate* isolate = CcTest::isolate(); | 5841 v8::Isolate* isolate = CcTest::isolate(); |
| 5740 v8::HandleScope scope(isolate); | 5842 v8::HandleScope scope(isolate); |
| 5741 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 5843 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
| 5742 templ->SetNamedPropertyHandler(XPropertyGetter); | 5844 templ->SetNamedPropertyHandler(XPropertyGetter); |
| 5743 LocalContext context; | 5845 LocalContext context; |
| 5744 // Create an object with a named interceptor. | 5846 // Create an object with a named interceptor. |
| 5745 context->Global()->Set(v8_str("interceptor_obj"), templ->NewInstance()); | 5847 context->Global()->Set(v8_str("interceptor_obj"), templ->NewInstance()); |
| 5746 Local<Script> script = Script::Compile(v8_str("interceptor_obj.x")); | 5848 Local<Script> script = v8_compile("interceptor_obj.x"); |
| 5747 for (int i = 0; i < 10; i++) { | 5849 for (int i = 0; i < 10; i++) { |
| 5748 Local<Value> result = script->Run(); | 5850 Local<Value> result = script->Run(); |
| 5749 CHECK_EQ(result, v8_str("x")); | 5851 CHECK_EQ(result, v8_str("x")); |
| 5750 } | 5852 } |
| 5751 // Create a slow case object and a function accessing a property in | 5853 // Create a slow case object and a function accessing a property in |
| 5752 // that slow case object (with dictionary probing in generated | 5854 // that slow case object (with dictionary probing in generated |
| 5753 // code). Then force object with a named interceptor into slow-case, | 5855 // code). Then force object with a named interceptor into slow-case, |
| 5754 // pass it to the function, and check that the interceptor is called | 5856 // pass it to the function, and check that the interceptor is called |
| 5755 // instead of accessing the local property. | 5857 // instead of accessing the local property. |
| 5756 Local<Value> result = | 5858 Local<Value> result = |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5859 | 5961 |
| 5860 | 5962 |
| 5861 THREADED_TEST(IndexedInterceptorWithIndexedAccessor) { | 5963 THREADED_TEST(IndexedInterceptorWithIndexedAccessor) { |
| 5862 v8::Isolate* isolate = CcTest::isolate(); | 5964 v8::Isolate* isolate = CcTest::isolate(); |
| 5863 v8::HandleScope scope(isolate); | 5965 v8::HandleScope scope(isolate); |
| 5864 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 5966 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
| 5865 templ->SetIndexedPropertyHandler(IndexedPropertyGetter, | 5967 templ->SetIndexedPropertyHandler(IndexedPropertyGetter, |
| 5866 IndexedPropertySetter); | 5968 IndexedPropertySetter); |
| 5867 LocalContext context; | 5969 LocalContext context; |
| 5868 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 5970 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
| 5869 Local<Script> getter_script = Script::Compile(v8_str( | 5971 Local<Script> getter_script = v8_compile( |
| 5870 "obj.__defineGetter__(\"3\", function(){return 5;});obj[3];")); | 5972 "obj.__defineGetter__(\"3\", function(){return 5;});obj[3];"); |
| 5871 Local<Script> setter_script = Script::Compile(v8_str( | 5973 Local<Script> setter_script = v8_compile( |
| 5872 "obj.__defineSetter__(\"17\", function(val){this.foo = val;});" | 5974 "obj.__defineSetter__(\"17\", function(val){this.foo = val;});" |
| 5873 "obj[17] = 23;" | 5975 "obj[17] = 23;" |
| 5874 "obj.foo;")); | 5976 "obj.foo;"); |
| 5875 Local<Script> interceptor_setter_script = Script::Compile(v8_str( | 5977 Local<Script> interceptor_setter_script = v8_compile( |
| 5876 "obj.__defineSetter__(\"39\", function(val){this.foo = \"hit\";});" | 5978 "obj.__defineSetter__(\"39\", function(val){this.foo = \"hit\";});" |
| 5877 "obj[39] = 47;" | 5979 "obj[39] = 47;" |
| 5878 "obj.foo;")); // This setter should not run, due to the interceptor. | 5980 "obj.foo;"); // This setter should not run, due to the interceptor. |
| 5879 Local<Script> interceptor_getter_script = Script::Compile(v8_str( | 5981 Local<Script> interceptor_getter_script = v8_compile( |
| 5880 "obj[37];")); | 5982 "obj[37];"); |
| 5881 Local<Value> result = getter_script->Run(); | 5983 Local<Value> result = getter_script->Run(); |
| 5882 CHECK_EQ(v8_num(5), result); | 5984 CHECK_EQ(v8_num(5), result); |
| 5883 result = setter_script->Run(); | 5985 result = setter_script->Run(); |
| 5884 CHECK_EQ(v8_num(23), result); | 5986 CHECK_EQ(v8_num(23), result); |
| 5885 result = interceptor_setter_script->Run(); | 5987 result = interceptor_setter_script->Run(); |
| 5886 CHECK_EQ(v8_num(23), result); | 5988 CHECK_EQ(v8_num(23), result); |
| 5887 result = interceptor_getter_script->Run(); | 5989 result = interceptor_getter_script->Run(); |
| 5888 CHECK_EQ(v8_num(625), result); | 5990 CHECK_EQ(v8_num(625), result); |
| 5889 } | 5991 } |
| 5890 | 5992 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 5906 ApiTestFuzzer::Fuzz(); | 6008 ApiTestFuzzer::Fuzz(); |
| 5907 if (index < 25) { | 6009 if (index < 25) { |
| 5908 info.GetReturnValue().Set(v8_num(index)); | 6010 info.GetReturnValue().Set(v8_num(index)); |
| 5909 } | 6011 } |
| 5910 } | 6012 } |
| 5911 | 6013 |
| 5912 | 6014 |
| 5913 void UnboxedDoubleIndexedPropertyEnumerator( | 6015 void UnboxedDoubleIndexedPropertyEnumerator( |
| 5914 const v8::PropertyCallbackInfo<v8::Array>& info) { | 6016 const v8::PropertyCallbackInfo<v8::Array>& info) { |
| 5915 // Force the list of returned keys to be stored in a FastDoubleArray. | 6017 // Force the list of returned keys to be stored in a FastDoubleArray. |
| 5916 Local<Script> indexed_property_names_script = Script::Compile(v8_str( | 6018 Local<Script> indexed_property_names_script = v8_compile( |
| 5917 "keys = new Array(); keys[125000] = 1;" | 6019 "keys = new Array(); keys[125000] = 1;" |
| 5918 "for(i = 0; i < 80000; i++) { keys[i] = i; };" | 6020 "for(i = 0; i < 80000; i++) { keys[i] = i; };" |
| 5919 "keys.length = 25; keys;")); | 6021 "keys.length = 25; keys;"); |
| 5920 Local<Value> result = indexed_property_names_script->Run(); | 6022 Local<Value> result = indexed_property_names_script->Run(); |
| 5921 info.GetReturnValue().Set(Local<v8::Array>::Cast(result)); | 6023 info.GetReturnValue().Set(Local<v8::Array>::Cast(result)); |
| 5922 } | 6024 } |
| 5923 | 6025 |
| 5924 | 6026 |
| 5925 // Make sure that the the interceptor code in the runtime properly handles | 6027 // Make sure that the the interceptor code in the runtime properly handles |
| 5926 // merging property name lists for double-array-backed arrays. | 6028 // merging property name lists for double-array-backed arrays. |
| 5927 THREADED_TEST(IndexedInterceptorUnboxedDoubleWithIndexedAccessor) { | 6029 THREADED_TEST(IndexedInterceptorUnboxedDoubleWithIndexedAccessor) { |
| 5928 v8::Isolate* isolate = CcTest::isolate(); | 6030 v8::Isolate* isolate = CcTest::isolate(); |
| 5929 v8::HandleScope scope(isolate); | 6031 v8::HandleScope scope(isolate); |
| 5930 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 6032 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
| 5931 templ->SetIndexedPropertyHandler(UnboxedDoubleIndexedPropertyGetter, | 6033 templ->SetIndexedPropertyHandler(UnboxedDoubleIndexedPropertyGetter, |
| 5932 UnboxedDoubleIndexedPropertySetter, | 6034 UnboxedDoubleIndexedPropertySetter, |
| 5933 0, | 6035 0, |
| 5934 0, | 6036 0, |
| 5935 UnboxedDoubleIndexedPropertyEnumerator); | 6037 UnboxedDoubleIndexedPropertyEnumerator); |
| 5936 LocalContext context; | 6038 LocalContext context; |
| 5937 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 6039 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
| 5938 // When obj is created, force it to be Stored in a FastDoubleArray. | 6040 // When obj is created, force it to be Stored in a FastDoubleArray. |
| 5939 Local<Script> create_unboxed_double_script = Script::Compile(v8_str( | 6041 Local<Script> create_unboxed_double_script = v8_compile( |
| 5940 "obj[125000] = 1; for(i = 0; i < 80000; i+=2) { obj[i] = i; } " | 6042 "obj[125000] = 1; for(i = 0; i < 80000; i+=2) { obj[i] = i; } " |
| 5941 "key_count = 0; " | 6043 "key_count = 0; " |
| 5942 "for (x in obj) {key_count++;};" | 6044 "for (x in obj) {key_count++;};" |
| 5943 "obj;")); | 6045 "obj;"); |
| 5944 Local<Value> result = create_unboxed_double_script->Run(); | 6046 Local<Value> result = create_unboxed_double_script->Run(); |
| 5945 CHECK(result->ToObject()->HasRealIndexedProperty(2000)); | 6047 CHECK(result->ToObject()->HasRealIndexedProperty(2000)); |
| 5946 Local<Script> key_count_check = Script::Compile(v8_str( | 6048 Local<Script> key_count_check = v8_compile("key_count;"); |
| 5947 "key_count;")); | |
| 5948 result = key_count_check->Run(); | 6049 result = key_count_check->Run(); |
| 5949 CHECK_EQ(v8_num(40013), result); | 6050 CHECK_EQ(v8_num(40013), result); |
| 5950 } | 6051 } |
| 5951 | 6052 |
| 5952 | 6053 |
| 5953 void NonStrictArgsIndexedPropertyEnumerator( | 6054 void SloppyArgsIndexedPropertyEnumerator( |
| 5954 const v8::PropertyCallbackInfo<v8::Array>& info) { | 6055 const v8::PropertyCallbackInfo<v8::Array>& info) { |
| 5955 // Force the list of returned keys to be stored in a Arguments object. | 6056 // Force the list of returned keys to be stored in a Arguments object. |
| 5956 Local<Script> indexed_property_names_script = Script::Compile(v8_str( | 6057 Local<Script> indexed_property_names_script = v8_compile( |
| 5957 "function f(w,x) {" | 6058 "function f(w,x) {" |
| 5958 " return arguments;" | 6059 " return arguments;" |
| 5959 "}" | 6060 "}" |
| 5960 "keys = f(0, 1, 2, 3);" | 6061 "keys = f(0, 1, 2, 3);" |
| 5961 "keys;")); | 6062 "keys;"); |
| 5962 Local<Object> result = | 6063 Local<Object> result = |
| 5963 Local<Object>::Cast(indexed_property_names_script->Run()); | 6064 Local<Object>::Cast(indexed_property_names_script->Run()); |
| 5964 // Have to populate the handle manually, as it's not Cast-able. | 6065 // Have to populate the handle manually, as it's not Cast-able. |
| 5965 i::Handle<i::JSObject> o = | 6066 i::Handle<i::JSObject> o = |
| 5966 v8::Utils::OpenHandle<Object, i::JSObject>(result); | 6067 v8::Utils::OpenHandle<Object, i::JSObject>(result); |
| 5967 i::Handle<i::JSArray> array(reinterpret_cast<i::JSArray*>(*o)); | 6068 i::Handle<i::JSArray> array(reinterpret_cast<i::JSArray*>(*o)); |
| 5968 info.GetReturnValue().Set(v8::Utils::ToLocal(array)); | 6069 info.GetReturnValue().Set(v8::Utils::ToLocal(array)); |
| 5969 } | 6070 } |
| 5970 | 6071 |
| 5971 | 6072 |
| 5972 static void NonStrictIndexedPropertyGetter( | 6073 static void SloppyIndexedPropertyGetter( |
| 5973 uint32_t index, | 6074 uint32_t index, |
| 5974 const v8::PropertyCallbackInfo<v8::Value>& info) { | 6075 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 5975 ApiTestFuzzer::Fuzz(); | 6076 ApiTestFuzzer::Fuzz(); |
| 5976 if (index < 4) { | 6077 if (index < 4) { |
| 5977 info.GetReturnValue().Set(v8_num(index)); | 6078 info.GetReturnValue().Set(v8_num(index)); |
| 5978 } | 6079 } |
| 5979 } | 6080 } |
| 5980 | 6081 |
| 5981 | 6082 |
| 5982 // Make sure that the the interceptor code in the runtime properly handles | 6083 // Make sure that the the interceptor code in the runtime properly handles |
| 5983 // merging property name lists for non-string arguments arrays. | 6084 // merging property name lists for non-string arguments arrays. |
| 5984 THREADED_TEST(IndexedInterceptorNonStrictArgsWithIndexedAccessor) { | 6085 THREADED_TEST(IndexedInterceptorSloppyArgsWithIndexedAccessor) { |
| 5985 v8::Isolate* isolate = CcTest::isolate(); | 6086 v8::Isolate* isolate = CcTest::isolate(); |
| 5986 v8::HandleScope scope(isolate); | 6087 v8::HandleScope scope(isolate); |
| 5987 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 6088 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
| 5988 templ->SetIndexedPropertyHandler(NonStrictIndexedPropertyGetter, | 6089 templ->SetIndexedPropertyHandler(SloppyIndexedPropertyGetter, |
| 5989 0, | 6090 0, |
| 5990 0, | 6091 0, |
| 5991 0, | 6092 0, |
| 5992 NonStrictArgsIndexedPropertyEnumerator); | 6093 SloppyArgsIndexedPropertyEnumerator); |
| 5993 LocalContext context; | 6094 LocalContext context; |
| 5994 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 6095 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
| 5995 Local<Script> create_args_script = | 6096 Local<Script> create_args_script = v8_compile( |
| 5996 Script::Compile(v8_str( | 6097 "var key_count = 0;" |
| 5997 "var key_count = 0;" | 6098 "for (x in obj) {key_count++;} key_count;"); |
| 5998 "for (x in obj) {key_count++;} key_count;")); | |
| 5999 Local<Value> result = create_args_script->Run(); | 6099 Local<Value> result = create_args_script->Run(); |
| 6000 CHECK_EQ(v8_num(4), result); | 6100 CHECK_EQ(v8_num(4), result); |
| 6001 } | 6101 } |
| 6002 | 6102 |
| 6003 | 6103 |
| 6004 static void IdentityIndexedPropertyGetter( | 6104 static void IdentityIndexedPropertyGetter( |
| 6005 uint32_t index, | 6105 uint32_t index, |
| 6006 const v8::PropertyCallbackInfo<v8::Value>& info) { | 6106 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 6007 info.GetReturnValue().Set(index); | 6107 info.GetReturnValue().Set(index); |
| 6008 } | 6108 } |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6363 // to Object.prototype and Array.prototype and create a new | 6463 // to Object.prototype and Array.prototype and create a new |
| 6364 // environment. This should succeed. | 6464 // environment. This should succeed. |
| 6365 | 6465 |
| 6366 v8::HandleScope scope(CcTest::isolate()); | 6466 v8::HandleScope scope(CcTest::isolate()); |
| 6367 | 6467 |
| 6368 Local<String> source = v8_str("Object.prototype.obj = 1234;" | 6468 Local<String> source = v8_str("Object.prototype.obj = 1234;" |
| 6369 "Array.prototype.arr = 4567;" | 6469 "Array.prototype.arr = 4567;" |
| 6370 "8901"); | 6470 "8901"); |
| 6371 | 6471 |
| 6372 LocalContext env0; | 6472 LocalContext env0; |
| 6373 Local<Script> script0 = Script::Compile(source); | 6473 Local<Script> script0 = v8_compile(source); |
| 6374 CHECK_EQ(8901.0, script0->Run()->NumberValue()); | 6474 CHECK_EQ(8901.0, script0->Run()->NumberValue()); |
| 6375 | 6475 |
| 6376 LocalContext env1; | 6476 LocalContext env1; |
| 6377 Local<Script> script1 = Script::Compile(source); | 6477 Local<Script> script1 = v8_compile(source); |
| 6378 CHECK_EQ(8901.0, script1->Run()->NumberValue()); | 6478 CHECK_EQ(8901.0, script1->Run()->NumberValue()); |
| 6379 } | 6479 } |
| 6380 | 6480 |
| 6381 | 6481 |
| 6382 THREADED_TEST(UndetectableObject) { | 6482 THREADED_TEST(UndetectableObject) { |
| 6383 LocalContext env; | 6483 LocalContext env; |
| 6384 v8::HandleScope scope(env->GetIsolate()); | 6484 v8::HandleScope scope(env->GetIsolate()); |
| 6385 | 6485 |
| 6386 Local<v8::FunctionTemplate> desc = | 6486 Local<v8::FunctionTemplate> desc = |
| 6387 v8::FunctionTemplate::New(env->GetIsolate()); | 6487 v8::FunctionTemplate::New(env->GetIsolate()); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6474 | 6574 |
| 6475 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate); | 6575 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate); |
| 6476 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable | 6576 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable |
| 6477 | 6577 |
| 6478 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); | 6578 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); |
| 6479 env->Global()->Set(v8_str("undetectable"), obj); | 6579 env->Global()->Set(v8_str("undetectable"), obj); |
| 6480 | 6580 |
| 6481 Local<String> source = v8_str("undetectable.x = 42;" | 6581 Local<String> source = v8_str("undetectable.x = 42;" |
| 6482 "undetectable.x"); | 6582 "undetectable.x"); |
| 6483 | 6583 |
| 6484 Local<Script> script = Script::Compile(source); | 6584 Local<Script> script = v8_compile(source); |
| 6485 | 6585 |
| 6486 CHECK_EQ(v8::Integer::New(isolate, 42), script->Run()); | 6586 CHECK_EQ(v8::Integer::New(isolate, 42), script->Run()); |
| 6487 | 6587 |
| 6488 ExpectBoolean("Object.isExtensible(undetectable)", true); | 6588 ExpectBoolean("Object.isExtensible(undetectable)", true); |
| 6489 | 6589 |
| 6490 source = v8_str("Object.preventExtensions(undetectable);"); | 6590 source = v8_str("Object.preventExtensions(undetectable);"); |
| 6491 script = Script::Compile(source); | 6591 script = v8_compile(source); |
| 6492 script->Run(); | 6592 script->Run(); |
| 6493 ExpectBoolean("Object.isExtensible(undetectable)", false); | 6593 ExpectBoolean("Object.isExtensible(undetectable)", false); |
| 6494 | 6594 |
| 6495 source = v8_str("undetectable.y = 2000;"); | 6595 source = v8_str("undetectable.y = 2000;"); |
| 6496 script = Script::Compile(source); | 6596 script = v8_compile(source); |
| 6497 script->Run(); | 6597 script->Run(); |
| 6498 ExpectBoolean("undetectable.y == undefined", true); | 6598 ExpectBoolean("undetectable.y == undefined", true); |
| 6499 } | 6599 } |
| 6500 | 6600 |
| 6501 | 6601 |
| 6502 | 6602 |
| 6503 THREADED_TEST(UndetectableString) { | 6603 THREADED_TEST(UndetectableString) { |
| 6504 LocalContext env; | 6604 LocalContext env; |
| 6505 v8::HandleScope scope(env->GetIsolate()); | 6605 v8::HandleScope scope(env->GetIsolate()); |
| 6506 | 6606 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6579 | 6679 |
| 6580 // The point of this test is type checking. We run it only so compilers | 6680 // The point of this test is type checking. We run it only so compilers |
| 6581 // don't complain about an unused function. | 6681 // don't complain about an unused function. |
| 6582 TEST(PersistentHandles) { | 6682 TEST(PersistentHandles) { |
| 6583 LocalContext env; | 6683 LocalContext env; |
| 6584 v8::Isolate* isolate = CcTest::isolate(); | 6684 v8::Isolate* isolate = CcTest::isolate(); |
| 6585 v8::HandleScope scope(isolate); | 6685 v8::HandleScope scope(isolate); |
| 6586 Local<String> str = v8_str("foo"); | 6686 Local<String> str = v8_str("foo"); |
| 6587 v8::Persistent<String> p_str(isolate, str); | 6687 v8::Persistent<String> p_str(isolate, str); |
| 6588 p_str.Reset(); | 6688 p_str.Reset(); |
| 6589 Local<Script> scr = Script::Compile(v8_str("")); | 6689 Local<Script> scr = v8_compile(""); |
| 6590 v8::Persistent<Script> p_scr(isolate, scr); | 6690 v8::Persistent<Script> p_scr(isolate, scr); |
| 6591 p_scr.Reset(); | 6691 p_scr.Reset(); |
| 6592 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 6692 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
| 6593 v8::Persistent<ObjectTemplate> p_templ(isolate, templ); | 6693 v8::Persistent<ObjectTemplate> p_templ(isolate, templ); |
| 6594 p_templ.Reset(); | 6694 p_templ.Reset(); |
| 6595 } | 6695 } |
| 6596 | 6696 |
| 6597 | 6697 |
| 6598 static void HandleLogDelegator( | 6698 static void HandleLogDelegator( |
| 6599 const v8::FunctionCallbackInfo<v8::Value>& args) { | 6699 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 6600 ApiTestFuzzer::Fuzz(); | 6700 ApiTestFuzzer::Fuzz(); |
| 6601 } | 6701 } |
| 6602 | 6702 |
| 6603 | 6703 |
| 6604 THREADED_TEST(GlobalObjectTemplate) { | 6704 THREADED_TEST(GlobalObjectTemplate) { |
| 6605 v8::Isolate* isolate = CcTest::isolate(); | 6705 v8::Isolate* isolate = CcTest::isolate(); |
| 6606 v8::HandleScope handle_scope(isolate); | 6706 v8::HandleScope handle_scope(isolate); |
| 6607 Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate); | 6707 Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate); |
| 6608 global_template->Set(v8_str("JSNI_Log"), | 6708 global_template->Set(v8_str("JSNI_Log"), |
| 6609 v8::FunctionTemplate::New(isolate, HandleLogDelegator)); | 6709 v8::FunctionTemplate::New(isolate, HandleLogDelegator)); |
| 6610 v8::Local<Context> context = Context::New(isolate, 0, global_template); | 6710 v8::Local<Context> context = Context::New(isolate, 0, global_template); |
| 6611 Context::Scope context_scope(context); | 6711 Context::Scope context_scope(context); |
| 6612 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run(); | 6712 CompileRun("JSNI_Log('LOG')"); |
| 6613 } | 6713 } |
| 6614 | 6714 |
| 6615 | 6715 |
| 6616 static const char* kSimpleExtensionSource = | 6716 static const char* kSimpleExtensionSource = |
| 6617 "function Foo() {" | 6717 "function Foo() {" |
| 6618 " return 4;" | 6718 " return 4;" |
| 6619 "}"; | 6719 "}"; |
| 6620 | 6720 |
| 6621 | 6721 |
| 6622 TEST(SimpleExtensions) { | 6722 TEST(SimpleExtensions) { |
| 6623 v8::HandleScope handle_scope(CcTest::isolate()); | 6723 v8::HandleScope handle_scope(CcTest::isolate()); |
| 6624 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource)); | 6724 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource)); |
| 6625 const char* extension_names[] = { "simpletest" }; | 6725 const char* extension_names[] = { "simpletest" }; |
| 6626 v8::ExtensionConfiguration extensions(1, extension_names); | 6726 v8::ExtensionConfiguration extensions(1, extension_names); |
| 6627 v8::Handle<Context> context = | 6727 v8::Handle<Context> context = |
| 6628 Context::New(CcTest::isolate(), &extensions); | 6728 Context::New(CcTest::isolate(), &extensions); |
| 6629 Context::Scope lock(context); | 6729 Context::Scope lock(context); |
| 6630 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); | 6730 v8::Handle<Value> result = CompileRun("Foo()"); |
| 6631 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 4)); | 6731 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 4)); |
| 6632 } | 6732 } |
| 6633 | 6733 |
| 6634 | 6734 |
| 6635 TEST(NullExtensions) { | 6735 TEST(NullExtensions) { |
| 6636 v8::HandleScope handle_scope(CcTest::isolate()); | 6736 v8::HandleScope handle_scope(CcTest::isolate()); |
| 6637 v8::RegisterExtension(new Extension("nulltest", NULL)); | 6737 v8::RegisterExtension(new Extension("nulltest", NULL)); |
| 6638 const char* extension_names[] = { "nulltest" }; | 6738 const char* extension_names[] = { "nulltest" }; |
| 6639 v8::ExtensionConfiguration extensions(1, extension_names); | 6739 v8::ExtensionConfiguration extensions(1, extension_names); |
| 6640 v8::Handle<Context> context = | 6740 v8::Handle<Context> context = |
| 6641 Context::New(CcTest::isolate(), &extensions); | 6741 Context::New(CcTest::isolate(), &extensions); |
| 6642 Context::Scope lock(context); | 6742 Context::Scope lock(context); |
| 6643 v8::Handle<Value> result = Script::Compile(v8_str("1+3"))->Run(); | 6743 v8::Handle<Value> result = CompileRun("1+3"); |
| 6644 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 4)); | 6744 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 4)); |
| 6645 } | 6745 } |
| 6646 | 6746 |
| 6647 | 6747 |
| 6648 static const char* kEmbeddedExtensionSource = | 6748 static const char* kEmbeddedExtensionSource = |
| 6649 "function Ret54321(){return 54321;}~~@@$" | 6749 "function Ret54321(){return 54321;}~~@@$" |
| 6650 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS."; | 6750 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS."; |
| 6651 static const int kEmbeddedExtensionSourceValidLen = 34; | 6751 static const int kEmbeddedExtensionSourceValidLen = 34; |
| 6652 | 6752 |
| 6653 | 6753 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 6671 i::OS::SNPrintF(extension_name, "ext #%d", source_len); | 6771 i::OS::SNPrintF(extension_name, "ext #%d", source_len); |
| 6672 v8::RegisterExtension(new Extension(extension_name.start(), | 6772 v8::RegisterExtension(new Extension(extension_name.start(), |
| 6673 kEmbeddedExtensionSource, 0, 0, | 6773 kEmbeddedExtensionSource, 0, 0, |
| 6674 source_len)); | 6774 source_len)); |
| 6675 const char* extension_names[1] = { extension_name.start() }; | 6775 const char* extension_names[1] = { extension_name.start() }; |
| 6676 v8::ExtensionConfiguration extensions(1, extension_names); | 6776 v8::ExtensionConfiguration extensions(1, extension_names); |
| 6677 v8::Handle<Context> context = | 6777 v8::Handle<Context> context = |
| 6678 Context::New(CcTest::isolate(), &extensions); | 6778 Context::New(CcTest::isolate(), &extensions); |
| 6679 if (source_len == kEmbeddedExtensionSourceValidLen) { | 6779 if (source_len == kEmbeddedExtensionSourceValidLen) { |
| 6680 Context::Scope lock(context); | 6780 Context::Scope lock(context); |
| 6681 v8::Handle<Value> result = Script::Compile(v8_str("Ret54321()"))->Run(); | 6781 v8::Handle<Value> result = CompileRun("Ret54321()"); |
| 6682 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 54321), result); | 6782 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 54321), result); |
| 6683 } else { | 6783 } else { |
| 6684 // Anything but exactly the right length should fail to compile. | 6784 // Anything but exactly the right length should fail to compile. |
| 6685 CHECK_EQ(0, *context); | 6785 CHECK_EQ(0, *context); |
| 6686 } | 6786 } |
| 6687 } | 6787 } |
| 6688 } | 6788 } |
| 6689 | 6789 |
| 6690 | 6790 |
| 6691 static const char* kEvalExtensionSource1 = | 6791 static const char* kEvalExtensionSource1 = |
| (...skipping 15 matching lines...) Expand all Loading... |
| 6707 | 6807 |
| 6708 TEST(UseEvalFromExtension) { | 6808 TEST(UseEvalFromExtension) { |
| 6709 v8::HandleScope handle_scope(CcTest::isolate()); | 6809 v8::HandleScope handle_scope(CcTest::isolate()); |
| 6710 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1)); | 6810 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1)); |
| 6711 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2)); | 6811 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2)); |
| 6712 const char* extension_names[] = { "evaltest1", "evaltest2" }; | 6812 const char* extension_names[] = { "evaltest1", "evaltest2" }; |
| 6713 v8::ExtensionConfiguration extensions(2, extension_names); | 6813 v8::ExtensionConfiguration extensions(2, extension_names); |
| 6714 v8::Handle<Context> context = | 6814 v8::Handle<Context> context = |
| 6715 Context::New(CcTest::isolate(), &extensions); | 6815 Context::New(CcTest::isolate(), &extensions); |
| 6716 Context::Scope lock(context); | 6816 Context::Scope lock(context); |
| 6717 v8::Handle<Value> result = Script::Compile(v8_str("UseEval1()"))->Run(); | 6817 v8::Handle<Value> result = CompileRun("UseEval1()"); |
| 6718 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 42)); | 6818 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 42)); |
| 6719 result = Script::Compile(v8_str("UseEval2()"))->Run(); | 6819 result = CompileRun("UseEval2()"); |
| 6720 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 42)); | 6820 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 42)); |
| 6721 } | 6821 } |
| 6722 | 6822 |
| 6723 | 6823 |
| 6724 static const char* kWithExtensionSource1 = | 6824 static const char* kWithExtensionSource1 = |
| 6725 "function UseWith1() {" | 6825 "function UseWith1() {" |
| 6726 " var x = 42;" | 6826 " var x = 42;" |
| 6727 " with({x:87}) { return x; }" | 6827 " with({x:87}) { return x; }" |
| 6728 "}"; | 6828 "}"; |
| 6729 | 6829 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 6741 | 6841 |
| 6742 TEST(UseWithFromExtension) { | 6842 TEST(UseWithFromExtension) { |
| 6743 v8::HandleScope handle_scope(CcTest::isolate()); | 6843 v8::HandleScope handle_scope(CcTest::isolate()); |
| 6744 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1)); | 6844 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1)); |
| 6745 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2)); | 6845 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2)); |
| 6746 const char* extension_names[] = { "withtest1", "withtest2" }; | 6846 const char* extension_names[] = { "withtest1", "withtest2" }; |
| 6747 v8::ExtensionConfiguration extensions(2, extension_names); | 6847 v8::ExtensionConfiguration extensions(2, extension_names); |
| 6748 v8::Handle<Context> context = | 6848 v8::Handle<Context> context = |
| 6749 Context::New(CcTest::isolate(), &extensions); | 6849 Context::New(CcTest::isolate(), &extensions); |
| 6750 Context::Scope lock(context); | 6850 Context::Scope lock(context); |
| 6751 v8::Handle<Value> result = Script::Compile(v8_str("UseWith1()"))->Run(); | 6851 v8::Handle<Value> result = CompileRun("UseWith1()"); |
| 6752 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 87)); | 6852 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 87)); |
| 6753 result = Script::Compile(v8_str("UseWith2()"))->Run(); | 6853 result = CompileRun("UseWith2()"); |
| 6754 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 87)); | 6854 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 87)); |
| 6755 } | 6855 } |
| 6756 | 6856 |
| 6757 | 6857 |
| 6758 TEST(AutoExtensions) { | 6858 TEST(AutoExtensions) { |
| 6759 v8::HandleScope handle_scope(CcTest::isolate()); | 6859 v8::HandleScope handle_scope(CcTest::isolate()); |
| 6760 Extension* extension = new Extension("autotest", kSimpleExtensionSource); | 6860 Extension* extension = new Extension("autotest", kSimpleExtensionSource); |
| 6761 extension->set_auto_enable(true); | 6861 extension->set_auto_enable(true); |
| 6762 v8::RegisterExtension(extension); | 6862 v8::RegisterExtension(extension); |
| 6763 v8::Handle<Context> context = | 6863 v8::Handle<Context> context = |
| 6764 Context::New(CcTest::isolate()); | 6864 Context::New(CcTest::isolate()); |
| 6765 Context::Scope lock(context); | 6865 Context::Scope lock(context); |
| 6766 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); | 6866 v8::Handle<Value> result = CompileRun("Foo()"); |
| 6767 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 4)); | 6867 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 4)); |
| 6768 } | 6868 } |
| 6769 | 6869 |
| 6770 | 6870 |
| 6771 static const char* kSyntaxErrorInExtensionSource = | 6871 static const char* kSyntaxErrorInExtensionSource = |
| 6772 "["; | 6872 "["; |
| 6773 | 6873 |
| 6774 | 6874 |
| 6775 // Test that a syntax error in an extension does not cause a fatal | 6875 // Test that a syntax error in an extension does not cause a fatal |
| 6776 // error but results in an empty context. | 6876 // error but results in an empty context. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6816 // Test that a native runtime calls are supported in extensions. | 6916 // Test that a native runtime calls are supported in extensions. |
| 6817 TEST(NativeCallInExtensions) { | 6917 TEST(NativeCallInExtensions) { |
| 6818 v8::HandleScope handle_scope(CcTest::isolate()); | 6918 v8::HandleScope handle_scope(CcTest::isolate()); |
| 6819 v8::RegisterExtension(new Extension("nativecall", | 6919 v8::RegisterExtension(new Extension("nativecall", |
| 6820 kNativeCallInExtensionSource)); | 6920 kNativeCallInExtensionSource)); |
| 6821 const char* extension_names[] = { "nativecall" }; | 6921 const char* extension_names[] = { "nativecall" }; |
| 6822 v8::ExtensionConfiguration extensions(1, extension_names); | 6922 v8::ExtensionConfiguration extensions(1, extension_names); |
| 6823 v8::Handle<Context> context = | 6923 v8::Handle<Context> context = |
| 6824 Context::New(CcTest::isolate(), &extensions); | 6924 Context::New(CcTest::isolate(), &extensions); |
| 6825 Context::Scope lock(context); | 6925 Context::Scope lock(context); |
| 6826 v8::Handle<Value> result = Script::Compile(v8_str(kNativeCallTest))->Run(); | 6926 v8::Handle<Value> result = CompileRun(kNativeCallTest); |
| 6827 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 3)); | 6927 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 3)); |
| 6828 } | 6928 } |
| 6829 | 6929 |
| 6830 | 6930 |
| 6831 class NativeFunctionExtension : public Extension { | 6931 class NativeFunctionExtension : public Extension { |
| 6832 public: | 6932 public: |
| 6833 NativeFunctionExtension(const char* name, | 6933 NativeFunctionExtension(const char* name, |
| 6834 const char* source, | 6934 const char* source, |
| 6835 v8::FunctionCallback fun = &Echo) | 6935 v8::FunctionCallback fun = &Echo) |
| 6836 : Extension(name, source), | 6936 : Extension(name, source), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 6853 TEST(NativeFunctionDeclaration) { | 6953 TEST(NativeFunctionDeclaration) { |
| 6854 v8::HandleScope handle_scope(CcTest::isolate()); | 6954 v8::HandleScope handle_scope(CcTest::isolate()); |
| 6855 const char* name = "nativedecl"; | 6955 const char* name = "nativedecl"; |
| 6856 v8::RegisterExtension(new NativeFunctionExtension(name, | 6956 v8::RegisterExtension(new NativeFunctionExtension(name, |
| 6857 "native function foo();")); | 6957 "native function foo();")); |
| 6858 const char* extension_names[] = { name }; | 6958 const char* extension_names[] = { name }; |
| 6859 v8::ExtensionConfiguration extensions(1, extension_names); | 6959 v8::ExtensionConfiguration extensions(1, extension_names); |
| 6860 v8::Handle<Context> context = | 6960 v8::Handle<Context> context = |
| 6861 Context::New(CcTest::isolate(), &extensions); | 6961 Context::New(CcTest::isolate(), &extensions); |
| 6862 Context::Scope lock(context); | 6962 Context::Scope lock(context); |
| 6863 v8::Handle<Value> result = Script::Compile(v8_str("foo(42);"))->Run(); | 6963 v8::Handle<Value> result = CompileRun("foo(42);"); |
| 6864 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 42)); | 6964 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 42)); |
| 6865 } | 6965 } |
| 6866 | 6966 |
| 6867 | 6967 |
| 6868 TEST(NativeFunctionDeclarationError) { | 6968 TEST(NativeFunctionDeclarationError) { |
| 6869 v8::HandleScope handle_scope(CcTest::isolate()); | 6969 v8::HandleScope handle_scope(CcTest::isolate()); |
| 6870 const char* name = "nativedeclerr"; | 6970 const char* name = "nativedeclerr"; |
| 6871 // Syntax error in extension code. | 6971 // Syntax error in extension code. |
| 6872 v8::RegisterExtension(new NativeFunctionExtension(name, | 6972 v8::RegisterExtension(new NativeFunctionExtension(name, |
| 6873 "native\nfunction foo();")); | 6973 "native\nfunction foo();")); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6984 | 7084 |
| 6985 | 7085 |
| 6986 THREADED_TEST(FunctionLookup) { | 7086 THREADED_TEST(FunctionLookup) { |
| 6987 v8::RegisterExtension(new FunctionExtension()); | 7087 v8::RegisterExtension(new FunctionExtension()); |
| 6988 v8::HandleScope handle_scope(CcTest::isolate()); | 7088 v8::HandleScope handle_scope(CcTest::isolate()); |
| 6989 static const char* exts[1] = { "functiontest" }; | 7089 static const char* exts[1] = { "functiontest" }; |
| 6990 v8::ExtensionConfiguration config(1, exts); | 7090 v8::ExtensionConfiguration config(1, exts); |
| 6991 LocalContext context(&config); | 7091 LocalContext context(&config); |
| 6992 CHECK_EQ(3, lookup_count); | 7092 CHECK_EQ(3, lookup_count); |
| 6993 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 8), | 7093 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 8), |
| 6994 Script::Compile(v8_str("Foo(0)"))->Run()); | 7094 CompileRun("Foo(0)")); |
| 6995 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 7), | 7095 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 7), |
| 6996 Script::Compile(v8_str("Foo(1)"))->Run()); | 7096 CompileRun("Foo(1)")); |
| 6997 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 6), | 7097 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 6), |
| 6998 Script::Compile(v8_str("Foo(2)"))->Run()); | 7098 CompileRun("Foo(2)")); |
| 6999 } | 7099 } |
| 7000 | 7100 |
| 7001 | 7101 |
| 7002 THREADED_TEST(NativeFunctionConstructCall) { | 7102 THREADED_TEST(NativeFunctionConstructCall) { |
| 7003 v8::RegisterExtension(new FunctionExtension()); | 7103 v8::RegisterExtension(new FunctionExtension()); |
| 7004 v8::HandleScope handle_scope(CcTest::isolate()); | 7104 v8::HandleScope handle_scope(CcTest::isolate()); |
| 7005 static const char* exts[1] = { "functiontest" }; | 7105 static const char* exts[1] = { "functiontest" }; |
| 7006 v8::ExtensionConfiguration config(1, exts); | 7106 v8::ExtensionConfiguration config(1, exts); |
| 7007 LocalContext context(&config); | 7107 LocalContext context(&config); |
| 7008 for (int i = 0; i < 10; i++) { | 7108 for (int i = 0; i < 10; i++) { |
| 7009 // Run a few times to ensure that allocation of objects doesn't | 7109 // Run a few times to ensure that allocation of objects doesn't |
| 7010 // change behavior of a constructor function. | 7110 // change behavior of a constructor function. |
| 7011 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 8), | 7111 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 8), |
| 7012 Script::Compile(v8_str("(new A()).data"))->Run()); | 7112 CompileRun("(new A()).data")); |
| 7013 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 7), | 7113 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 7), |
| 7014 Script::Compile(v8_str("(new B()).data"))->Run()); | 7114 CompileRun("(new B()).data")); |
| 7015 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 6), | 7115 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 6), |
| 7016 Script::Compile(v8_str("(new C()).data"))->Run()); | 7116 CompileRun("(new C()).data")); |
| 7017 } | 7117 } |
| 7018 } | 7118 } |
| 7019 | 7119 |
| 7020 | 7120 |
| 7021 static const char* last_location; | 7121 static const char* last_location; |
| 7022 static const char* last_message; | 7122 static const char* last_message; |
| 7023 void StoringErrorCallback(const char* location, const char* message) { | 7123 void StoringErrorCallback(const char* location, const char* message) { |
| 7024 if (last_location == NULL) { | 7124 if (last_location == NULL) { |
| 7025 last_location = location; | 7125 last_location = location; |
| 7026 last_message = message; | 7126 last_message = message; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 7052 CHECK_EQ(v8::Undefined(CcTest::isolate()), message->GetScriptResourceName()); | 7152 CHECK_EQ(v8::Undefined(CcTest::isolate()), message->GetScriptResourceName()); |
| 7053 message->GetLineNumber(); | 7153 message->GetLineNumber(); |
| 7054 message->GetSourceLine(); | 7154 message->GetSourceLine(); |
| 7055 } | 7155 } |
| 7056 | 7156 |
| 7057 | 7157 |
| 7058 THREADED_TEST(ErrorWithMissingScriptInfo) { | 7158 THREADED_TEST(ErrorWithMissingScriptInfo) { |
| 7059 LocalContext context; | 7159 LocalContext context; |
| 7060 v8::HandleScope scope(context->GetIsolate()); | 7160 v8::HandleScope scope(context->GetIsolate()); |
| 7061 v8::V8::AddMessageListener(MissingScriptInfoMessageListener); | 7161 v8::V8::AddMessageListener(MissingScriptInfoMessageListener); |
| 7062 Script::Compile(v8_str("throw Error()"))->Run(); | 7162 CompileRun("throw Error()"); |
| 7063 v8::V8::RemoveMessageListeners(MissingScriptInfoMessageListener); | 7163 v8::V8::RemoveMessageListeners(MissingScriptInfoMessageListener); |
| 7064 } | 7164 } |
| 7065 | 7165 |
| 7066 | 7166 |
| 7067 struct FlagAndPersistent { | 7167 struct FlagAndPersistent { |
| 7068 bool flag; | 7168 bool flag; |
| 7069 v8::Persistent<v8::Object> handle; | 7169 v8::Persistent<v8::Object> handle; |
| 7070 }; | 7170 }; |
| 7071 | 7171 |
| 7072 | 7172 |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7473 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 7573 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
| 7474 templ->SetAccessor(v8_str("t"), PGetter2); | 7574 templ->SetAccessor(v8_str("t"), PGetter2); |
| 7475 LocalContext context; | 7575 LocalContext context; |
| 7476 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 7576 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
| 7477 for (int i = 0; i < 100; i++) { | 7577 for (int i = 0; i < 100; i++) { |
| 7478 v8::HandleScope inner_scope(CcTest::isolate()); | 7578 v8::HandleScope inner_scope(CcTest::isolate()); |
| 7479 v8::Handle<v8::Object> obj = templ->NewInstance(); | 7579 v8::Handle<v8::Object> obj = templ->NewInstance(); |
| 7480 CHECK_NE(obj, context->Global()->Get(v8_str("o"))); | 7580 CHECK_NE(obj, context->Global()->Get(v8_str("o"))); |
| 7481 context->Global()->Set(v8_str("o2"), obj); | 7581 context->Global()->Set(v8_str("o2"), obj); |
| 7482 v8::Handle<Value> value = | 7582 v8::Handle<Value> value = |
| 7483 Script::Compile(v8_str("o.__proto__ === o2.__proto__"))->Run(); | 7583 CompileRun("o.__proto__ === o2.__proto__"); |
| 7484 CHECK_EQ(v8::True(isolate), value); | 7584 CHECK_EQ(v8::True(isolate), value); |
| 7485 context->Global()->Set(v8_str("o"), obj); | 7585 context->Global()->Set(v8_str("o"), obj); |
| 7486 } | 7586 } |
| 7487 } | 7587 } |
| 7488 | 7588 |
| 7489 | 7589 |
| 7490 static int StrCmp16(uint16_t* a, uint16_t* b) { | 7590 static int StrCmp16(uint16_t* a, uint16_t* b) { |
| 7491 while (true) { | 7591 while (true) { |
| 7492 if (*a == 0 && *b == 0) return 0; | 7592 if (*a == 0 && *b == 0) return 0; |
| 7493 if (*a != *b) return 0 + *a - *b; | 7593 if (*a != *b) return 0 + *a - *b; |
| (...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8234 LocalContext env; | 8334 LocalContext env; |
| 8235 v8::Isolate* isolate = env->GetIsolate(); | 8335 v8::Isolate* isolate = env->GetIsolate(); |
| 8236 v8::HandleScope scope(isolate); | 8336 v8::HandleScope scope(isolate); |
| 8237 v8::V8::AddMessageListener(ApiUncaughtExceptionTestListener); | 8337 v8::V8::AddMessageListener(ApiUncaughtExceptionTestListener); |
| 8238 | 8338 |
| 8239 Local<v8::FunctionTemplate> fun = | 8339 Local<v8::FunctionTemplate> fun = |
| 8240 v8::FunctionTemplate::New(isolate, TroubleCallback); | 8340 v8::FunctionTemplate::New(isolate, TroubleCallback); |
| 8241 v8::Local<v8::Object> global = env->Global(); | 8341 v8::Local<v8::Object> global = env->Global(); |
| 8242 global->Set(v8_str("trouble"), fun->GetFunction()); | 8342 global->Set(v8_str("trouble"), fun->GetFunction()); |
| 8243 | 8343 |
| 8244 Script::Compile(v8_str("function trouble_callee() {" | 8344 CompileRun( |
| 8245 " var x = null;" | 8345 "function trouble_callee() {" |
| 8246 " return x.foo;" | 8346 " var x = null;" |
| 8247 "};" | 8347 " return x.foo;" |
| 8248 "function trouble_caller() {" | 8348 "};" |
| 8249 " trouble();" | 8349 "function trouble_caller() {" |
| 8250 "};"))->Run(); | 8350 " trouble();" |
| 8351 "};"); |
| 8251 Local<Value> trouble = global->Get(v8_str("trouble")); | 8352 Local<Value> trouble = global->Get(v8_str("trouble")); |
| 8252 CHECK(trouble->IsFunction()); | 8353 CHECK(trouble->IsFunction()); |
| 8253 Local<Value> trouble_callee = global->Get(v8_str("trouble_callee")); | 8354 Local<Value> trouble_callee = global->Get(v8_str("trouble_callee")); |
| 8254 CHECK(trouble_callee->IsFunction()); | 8355 CHECK(trouble_callee->IsFunction()); |
| 8255 Local<Value> trouble_caller = global->Get(v8_str("trouble_caller")); | 8356 Local<Value> trouble_caller = global->Get(v8_str("trouble_caller")); |
| 8256 CHECK(trouble_caller->IsFunction()); | 8357 CHECK(trouble_caller->IsFunction()); |
| 8257 Function::Cast(*trouble_caller)->Call(global, 0, NULL); | 8358 Function::Cast(*trouble_caller)->Call(global, 0, NULL); |
| 8258 CHECK_EQ(1, report_count); | 8359 CHECK_EQ(1, report_count); |
| 8259 v8::V8::RemoveMessageListeners(ApiUncaughtExceptionTestListener); | 8360 v8::V8::RemoveMessageListeners(ApiUncaughtExceptionTestListener); |
| 8260 } | 8361 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 8276 LocalContext env; | 8377 LocalContext env; |
| 8277 v8::Isolate* isolate = env->GetIsolate(); | 8378 v8::Isolate* isolate = env->GetIsolate(); |
| 8278 v8::HandleScope scope(isolate); | 8379 v8::HandleScope scope(isolate); |
| 8279 v8::V8::AddMessageListener(ExceptionInNativeScriptTestListener); | 8380 v8::V8::AddMessageListener(ExceptionInNativeScriptTestListener); |
| 8280 | 8381 |
| 8281 Local<v8::FunctionTemplate> fun = | 8382 Local<v8::FunctionTemplate> fun = |
| 8282 v8::FunctionTemplate::New(isolate, TroubleCallback); | 8383 v8::FunctionTemplate::New(isolate, TroubleCallback); |
| 8283 v8::Local<v8::Object> global = env->Global(); | 8384 v8::Local<v8::Object> global = env->Global(); |
| 8284 global->Set(v8_str("trouble"), fun->GetFunction()); | 8385 global->Set(v8_str("trouble"), fun->GetFunction()); |
| 8285 | 8386 |
| 8286 Script::Compile( | 8387 CompileRunWithOrigin( |
| 8287 v8_str( | 8388 "function trouble() {\n" |
| 8288 "function trouble() {\n" | 8389 " var o = {};\n" |
| 8289 " var o = {};\n" | 8390 " new o.foo();\n" |
| 8290 " new o.foo();\n" | 8391 "};", |
| 8291 "};"), | 8392 script_resource_name); |
| 8292 v8::String::NewFromUtf8(isolate, script_resource_name))->Run(); | |
| 8293 Local<Value> trouble = global->Get(v8_str("trouble")); | 8393 Local<Value> trouble = global->Get(v8_str("trouble")); |
| 8294 CHECK(trouble->IsFunction()); | 8394 CHECK(trouble->IsFunction()); |
| 8295 Function::Cast(*trouble)->Call(global, 0, NULL); | 8395 Function::Cast(*trouble)->Call(global, 0, NULL); |
| 8296 v8::V8::RemoveMessageListeners(ExceptionInNativeScriptTestListener); | 8396 v8::V8::RemoveMessageListeners(ExceptionInNativeScriptTestListener); |
| 8297 } | 8397 } |
| 8298 | 8398 |
| 8299 | 8399 |
| 8300 TEST(CompilationErrorUsingTryCatchHandler) { | 8400 TEST(CompilationErrorUsingTryCatchHandler) { |
| 8301 LocalContext env; | 8401 LocalContext env; |
| 8302 v8::HandleScope scope(env->GetIsolate()); | 8402 v8::HandleScope scope(env->GetIsolate()); |
| 8303 v8::TryCatch try_catch; | 8403 v8::TryCatch try_catch; |
| 8304 Script::Compile(v8_str("This doesn't &*&@#$&*^ compile.")); | 8404 v8_compile("This doesn't &*&@#$&*^ compile."); |
| 8305 CHECK_NE(NULL, *try_catch.Exception()); | 8405 CHECK_NE(NULL, *try_catch.Exception()); |
| 8306 CHECK(try_catch.HasCaught()); | 8406 CHECK(try_catch.HasCaught()); |
| 8307 } | 8407 } |
| 8308 | 8408 |
| 8309 | 8409 |
| 8310 TEST(TryCatchFinallyUsingTryCatchHandler) { | 8410 TEST(TryCatchFinallyUsingTryCatchHandler) { |
| 8311 LocalContext env; | 8411 LocalContext env; |
| 8312 v8::HandleScope scope(env->GetIsolate()); | 8412 v8::HandleScope scope(env->GetIsolate()); |
| 8313 v8::TryCatch try_catch; | 8413 v8::TryCatch try_catch; |
| 8314 Script::Compile(v8_str("try { throw ''; } catch (e) {}"))->Run(); | 8414 CompileRun("try { throw ''; } catch (e) {}"); |
| 8315 CHECK(!try_catch.HasCaught()); | 8415 CHECK(!try_catch.HasCaught()); |
| 8316 Script::Compile(v8_str("try { throw ''; } finally {}"))->Run(); | 8416 CompileRun("try { throw ''; } finally {}"); |
| 8317 CHECK(try_catch.HasCaught()); | 8417 CHECK(try_catch.HasCaught()); |
| 8318 try_catch.Reset(); | 8418 try_catch.Reset(); |
| 8319 Script::Compile(v8_str("(function() {" | 8419 CompileRun( |
| 8320 "try { throw ''; } finally { return; }" | 8420 "(function() {" |
| 8321 "})()"))->Run(); | 8421 "try { throw ''; } finally { return; }" |
| 8422 "})()"); |
| 8322 CHECK(!try_catch.HasCaught()); | 8423 CHECK(!try_catch.HasCaught()); |
| 8323 Script::Compile(v8_str("(function()" | 8424 CompileRun( |
| 8324 " { try { throw ''; } finally { throw 0; }" | 8425 "(function()" |
| 8325 "})()"))->Run(); | 8426 " { try { throw ''; } finally { throw 0; }" |
| 8427 "})()"); |
| 8326 CHECK(try_catch.HasCaught()); | 8428 CHECK(try_catch.HasCaught()); |
| 8327 } | 8429 } |
| 8328 | 8430 |
| 8329 | 8431 |
| 8330 // SecurityHandler can't be run twice | 8432 // SecurityHandler can't be run twice |
| 8331 TEST(SecurityHandler) { | 8433 TEST(SecurityHandler) { |
| 8332 v8::Isolate* isolate = CcTest::isolate(); | 8434 v8::Isolate* isolate = CcTest::isolate(); |
| 8333 v8::HandleScope scope0(isolate); | 8435 v8::HandleScope scope0(isolate); |
| 8334 v8::Handle<v8::ObjectTemplate> global_template = | 8436 v8::Handle<v8::ObjectTemplate> global_template = |
| 8335 v8::ObjectTemplate::New(isolate); | 8437 v8::ObjectTemplate::New(isolate); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8393 v8::HandleScope handle_scope(env1->GetIsolate()); | 8495 v8::HandleScope handle_scope(env1->GetIsolate()); |
| 8394 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); | 8496 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); |
| 8395 | 8497 |
| 8396 Local<Value> foo = v8_str("foo"); | 8498 Local<Value> foo = v8_str("foo"); |
| 8397 Local<Value> bar = v8_str("bar"); | 8499 Local<Value> bar = v8_str("bar"); |
| 8398 | 8500 |
| 8399 // Set to the same domain. | 8501 // Set to the same domain. |
| 8400 env1->SetSecurityToken(foo); | 8502 env1->SetSecurityToken(foo); |
| 8401 | 8503 |
| 8402 // Create a function in env1. | 8504 // Create a function in env1. |
| 8403 Script::Compile(v8_str("spy=function(){return spy;}"))->Run(); | 8505 CompileRun("spy=function(){return spy;}"); |
| 8404 Local<Value> spy = env1->Global()->Get(v8_str("spy")); | 8506 Local<Value> spy = env1->Global()->Get(v8_str("spy")); |
| 8405 CHECK(spy->IsFunction()); | 8507 CHECK(spy->IsFunction()); |
| 8406 | 8508 |
| 8407 // Create another function accessing global objects. | 8509 // Create another function accessing global objects. |
| 8408 Script::Compile(v8_str("spy2=function(){return new this.Array();}"))->Run(); | 8510 CompileRun("spy2=function(){return new this.Array();}"); |
| 8409 Local<Value> spy2 = env1->Global()->Get(v8_str("spy2")); | 8511 Local<Value> spy2 = env1->Global()->Get(v8_str("spy2")); |
| 8410 CHECK(spy2->IsFunction()); | 8512 CHECK(spy2->IsFunction()); |
| 8411 | 8513 |
| 8412 // Switch to env2 in the same domain and invoke spy on env2. | 8514 // Switch to env2 in the same domain and invoke spy on env2. |
| 8413 { | 8515 { |
| 8414 env2->SetSecurityToken(foo); | 8516 env2->SetSecurityToken(foo); |
| 8415 // Enter env2 | 8517 // Enter env2 |
| 8416 Context::Scope scope_env2(env2); | 8518 Context::Scope scope_env2(env2); |
| 8417 Local<Value> result = Function::Cast(*spy)->Call(env2->Global(), 0, NULL); | 8519 Local<Value> result = Function::Cast(*spy)->Call(env2->Global(), 0, NULL); |
| 8418 CHECK(result->IsFunction()); | 8520 CHECK(result->IsFunction()); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8511 env2->SetSecurityToken(foo); | 8613 env2->SetSecurityToken(foo); |
| 8512 | 8614 |
| 8513 env1->Global()->Set(v8_str("prop"), v8_num(3)); | 8615 env1->Global()->Set(v8_str("prop"), v8_num(3)); |
| 8514 env2->Global()->Set(v8_str("env1"), env1->Global()); | 8616 env2->Global()->Set(v8_str("env1"), env1->Global()); |
| 8515 | 8617 |
| 8516 // Change env2 to a different domain and delete env1.prop. | 8618 // Change env2 to a different domain and delete env1.prop. |
| 8517 env2->SetSecurityToken(bar); | 8619 env2->SetSecurityToken(bar); |
| 8518 { | 8620 { |
| 8519 Context::Scope scope_env2(env2); | 8621 Context::Scope scope_env2(env2); |
| 8520 Local<Value> result = | 8622 Local<Value> result = |
| 8521 Script::Compile(v8_str("delete env1.prop"))->Run(); | 8623 CompileRun("delete env1.prop"); |
| 8522 CHECK(result->IsFalse()); | 8624 CHECK(result->IsFalse()); |
| 8523 } | 8625 } |
| 8524 | 8626 |
| 8525 // Check that env1.prop still exists. | 8627 // Check that env1.prop still exists. |
| 8526 Local<Value> v = env1->Global()->Get(v8_str("prop")); | 8628 Local<Value> v = env1->Global()->Get(v8_str("prop")); |
| 8527 CHECK(v->IsNumber()); | 8629 CHECK(v->IsNumber()); |
| 8528 CHECK_EQ(3, v->Int32Value()); | 8630 CHECK_EQ(3, v->Int32Value()); |
| 8529 } | 8631 } |
| 8530 | 8632 |
| 8531 | 8633 |
| 8532 THREADED_TEST(CrossDomainIsPropertyEnumerable) { | 8634 THREADED_TEST(CrossDomainIsPropertyEnumerable) { |
| 8533 LocalContext env1; | 8635 LocalContext env1; |
| 8534 v8::HandleScope handle_scope(env1->GetIsolate()); | 8636 v8::HandleScope handle_scope(env1->GetIsolate()); |
| 8535 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); | 8637 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); |
| 8536 | 8638 |
| 8537 Local<Value> foo = v8_str("foo"); | 8639 Local<Value> foo = v8_str("foo"); |
| 8538 Local<Value> bar = v8_str("bar"); | 8640 Local<Value> bar = v8_str("bar"); |
| 8539 | 8641 |
| 8540 // Set to the same domain. | 8642 // Set to the same domain. |
| 8541 env1->SetSecurityToken(foo); | 8643 env1->SetSecurityToken(foo); |
| 8542 env2->SetSecurityToken(foo); | 8644 env2->SetSecurityToken(foo); |
| 8543 | 8645 |
| 8544 env1->Global()->Set(v8_str("prop"), v8_num(3)); | 8646 env1->Global()->Set(v8_str("prop"), v8_num(3)); |
| 8545 env2->Global()->Set(v8_str("env1"), env1->Global()); | 8647 env2->Global()->Set(v8_str("env1"), env1->Global()); |
| 8546 | 8648 |
| 8547 // env1.prop is enumerable in env2. | 8649 // env1.prop is enumerable in env2. |
| 8548 Local<String> test = v8_str("propertyIsEnumerable.call(env1, 'prop')"); | 8650 Local<String> test = v8_str("propertyIsEnumerable.call(env1, 'prop')"); |
| 8549 { | 8651 { |
| 8550 Context::Scope scope_env2(env2); | 8652 Context::Scope scope_env2(env2); |
| 8551 Local<Value> result = Script::Compile(test)->Run(); | 8653 Local<Value> result = CompileRun(test); |
| 8552 CHECK(result->IsTrue()); | 8654 CHECK(result->IsTrue()); |
| 8553 } | 8655 } |
| 8554 | 8656 |
| 8555 // Change env2 to a different domain and test again. | 8657 // Change env2 to a different domain and test again. |
| 8556 env2->SetSecurityToken(bar); | 8658 env2->SetSecurityToken(bar); |
| 8557 { | 8659 { |
| 8558 Context::Scope scope_env2(env2); | 8660 Context::Scope scope_env2(env2); |
| 8559 Local<Value> result = Script::Compile(test)->Run(); | 8661 Local<Value> result = CompileRun(test); |
| 8560 CHECK(result->IsFalse()); | 8662 CHECK(result->IsFalse()); |
| 8561 } | 8663 } |
| 8562 } | 8664 } |
| 8563 | 8665 |
| 8564 | 8666 |
| 8565 THREADED_TEST(CrossDomainForIn) { | 8667 THREADED_TEST(CrossDomainForIn) { |
| 8566 LocalContext env1; | 8668 LocalContext env1; |
| 8567 v8::HandleScope handle_scope(env1->GetIsolate()); | 8669 v8::HandleScope handle_scope(env1->GetIsolate()); |
| 8568 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); | 8670 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); |
| 8569 | 8671 |
| (...skipping 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9761 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); | 9863 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
| 9762 Local<ObjectTemplate> instance = t->InstanceTemplate(); | 9864 Local<ObjectTemplate> instance = t->InstanceTemplate(); |
| 9763 | 9865 |
| 9764 instance->Set(v8_str("x"), v8_num(42)); | 9866 instance->Set(v8_str("x"), v8_num(42)); |
| 9765 instance->Set(v8_str("f"), | 9867 instance->Set(v8_str("f"), |
| 9766 v8::FunctionTemplate::New(isolate, InstanceFunctionCallback)); | 9868 v8::FunctionTemplate::New(isolate, InstanceFunctionCallback)); |
| 9767 | 9869 |
| 9768 Local<Value> o = t->GetFunction()->NewInstance(); | 9870 Local<Value> o = t->GetFunction()->NewInstance(); |
| 9769 | 9871 |
| 9770 context->Global()->Set(v8_str("i"), o); | 9872 context->Global()->Set(v8_str("i"), o); |
| 9771 Local<Value> value = Script::Compile(v8_str("i.x"))->Run(); | 9873 Local<Value> value = CompileRun("i.x"); |
| 9772 CHECK_EQ(42, value->Int32Value()); | 9874 CHECK_EQ(42, value->Int32Value()); |
| 9773 | 9875 |
| 9774 value = Script::Compile(v8_str("i.f()"))->Run(); | 9876 value = CompileRun("i.f()"); |
| 9775 CHECK_EQ(12, value->Int32Value()); | 9877 CHECK_EQ(12, value->Int32Value()); |
| 9776 } | 9878 } |
| 9777 | 9879 |
| 9778 | 9880 |
| 9779 static void GlobalObjectInstancePropertiesGet( | 9881 static void GlobalObjectInstancePropertiesGet( |
| 9780 Local<String> key, | 9882 Local<String> key, |
| 9781 const v8::PropertyCallbackInfo<v8::Value>&) { | 9883 const v8::PropertyCallbackInfo<v8::Value>&) { |
| 9782 ApiTestFuzzer::Fuzz(); | 9884 ApiTestFuzzer::Fuzz(); |
| 9783 } | 9885 } |
| 9784 | 9886 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 9813 "var thrown = 0;" | 9915 "var thrown = 0;" |
| 9814 "try { wrapper(true); } catch (e) { thrown = 1; };" | 9916 "try { wrapper(true); } catch (e) { thrown = 1; };" |
| 9815 "thrown"; | 9917 "thrown"; |
| 9816 | 9918 |
| 9817 { | 9919 { |
| 9818 LocalContext env(NULL, instance_template); | 9920 LocalContext env(NULL, instance_template); |
| 9819 // Hold on to the global object so it can be used again in another | 9921 // Hold on to the global object so it can be used again in another |
| 9820 // environment initialization. | 9922 // environment initialization. |
| 9821 global_object = env->Global(); | 9923 global_object = env->Global(); |
| 9822 | 9924 |
| 9823 Local<Value> value = Script::Compile(v8_str("x"))->Run(); | 9925 Local<Value> value = CompileRun("x"); |
| 9824 CHECK_EQ(42, value->Int32Value()); | 9926 CHECK_EQ(42, value->Int32Value()); |
| 9825 value = Script::Compile(v8_str("f()"))->Run(); | 9927 value = CompileRun("f()"); |
| 9826 CHECK_EQ(12, value->Int32Value()); | 9928 CHECK_EQ(12, value->Int32Value()); |
| 9827 value = Script::Compile(v8_str(script))->Run(); | 9929 value = CompileRun(script); |
| 9828 CHECK_EQ(1, value->Int32Value()); | 9930 CHECK_EQ(1, value->Int32Value()); |
| 9829 } | 9931 } |
| 9830 | 9932 |
| 9831 { | 9933 { |
| 9832 // Create new environment reusing the global object. | 9934 // Create new environment reusing the global object. |
| 9833 LocalContext env(NULL, instance_template, global_object); | 9935 LocalContext env(NULL, instance_template, global_object); |
| 9834 Local<Value> value = Script::Compile(v8_str("x"))->Run(); | 9936 Local<Value> value = CompileRun("x"); |
| 9835 CHECK_EQ(42, value->Int32Value()); | 9937 CHECK_EQ(42, value->Int32Value()); |
| 9836 value = Script::Compile(v8_str("f()"))->Run(); | 9938 value = CompileRun("f()"); |
| 9837 CHECK_EQ(12, value->Int32Value()); | 9939 CHECK_EQ(12, value->Int32Value()); |
| 9838 value = Script::Compile(v8_str(script))->Run(); | 9940 value = CompileRun(script); |
| 9839 CHECK_EQ(1, value->Int32Value()); | 9941 CHECK_EQ(1, value->Int32Value()); |
| 9840 } | 9942 } |
| 9841 } | 9943 } |
| 9842 | 9944 |
| 9843 | 9945 |
| 9844 THREADED_TEST(CallKnownGlobalReceiver) { | 9946 THREADED_TEST(CallKnownGlobalReceiver) { |
| 9845 v8::Isolate* isolate = CcTest::isolate(); | 9947 v8::Isolate* isolate = CcTest::isolate(); |
| 9846 v8::HandleScope handle_scope(isolate); | 9948 v8::HandleScope handle_scope(isolate); |
| 9847 | 9949 |
| 9848 Local<Value> global_object; | 9950 Local<Value> global_object; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 9863 "function foo(x) { bar([x], bom(2)); }" | 9965 "function foo(x) { bar([x], bom(2)); }" |
| 9864 "for (var i = 0; i < 10000; i++) foo(1);" | 9966 "for (var i = 0; i < 10000; i++) foo(1);" |
| 9865 "foo"; | 9967 "foo"; |
| 9866 | 9968 |
| 9867 Local<Value> foo; | 9969 Local<Value> foo; |
| 9868 { | 9970 { |
| 9869 LocalContext env(NULL, instance_template); | 9971 LocalContext env(NULL, instance_template); |
| 9870 // Hold on to the global object so it can be used again in another | 9972 // Hold on to the global object so it can be used again in another |
| 9871 // environment initialization. | 9973 // environment initialization. |
| 9872 global_object = env->Global(); | 9974 global_object = env->Global(); |
| 9873 foo = Script::Compile(v8_str(script))->Run(); | 9975 foo = CompileRun(script); |
| 9874 } | 9976 } |
| 9875 | 9977 |
| 9876 { | 9978 { |
| 9877 // Create new environment reusing the global object. | 9979 // Create new environment reusing the global object. |
| 9878 LocalContext env(NULL, instance_template, global_object); | 9980 LocalContext env(NULL, instance_template, global_object); |
| 9879 env->Global()->Set(v8_str("foo"), foo); | 9981 env->Global()->Set(v8_str("foo"), foo); |
| 9880 Script::Compile(v8_str("foo()"))->Run(); | 9982 CompileRun("foo()"); |
| 9881 } | 9983 } |
| 9882 } | 9984 } |
| 9883 | 9985 |
| 9884 | 9986 |
| 9885 static void ShadowFunctionCallback( | 9987 static void ShadowFunctionCallback( |
| 9886 const v8::FunctionCallbackInfo<v8::Value>& args) { | 9988 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 9887 ApiTestFuzzer::Fuzz(); | 9989 ApiTestFuzzer::Fuzz(); |
| 9888 args.GetReturnValue().Set(v8_num(42)); | 9990 args.GetReturnValue().Set(v8_num(42)); |
| 9889 } | 9991 } |
| 9890 | 9992 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9939 ShadowFunctionCallback, | 10041 ShadowFunctionCallback, |
| 9940 Local<Value>())); | 10042 Local<Value>())); |
| 9941 proto->Set(v8_str("x"), v8_num(12)); | 10043 proto->Set(v8_str("x"), v8_num(12)); |
| 9942 | 10044 |
| 9943 instance->SetAccessor(v8_str("y"), ShadowYGetter, ShadowYSetter); | 10045 instance->SetAccessor(v8_str("y"), ShadowYGetter, ShadowYSetter); |
| 9944 | 10046 |
| 9945 Local<Value> o = t->GetFunction()->NewInstance(); | 10047 Local<Value> o = t->GetFunction()->NewInstance(); |
| 9946 context->Global()->Set(v8_str("__proto__"), o); | 10048 context->Global()->Set(v8_str("__proto__"), o); |
| 9947 | 10049 |
| 9948 Local<Value> value = | 10050 Local<Value> value = |
| 9949 Script::Compile(v8_str("this.propertyIsEnumerable(0)"))->Run(); | 10051 CompileRun("this.propertyIsEnumerable(0)"); |
| 9950 CHECK(value->IsBoolean()); | 10052 CHECK(value->IsBoolean()); |
| 9951 CHECK(!value->BooleanValue()); | 10053 CHECK(!value->BooleanValue()); |
| 9952 | 10054 |
| 9953 value = Script::Compile(v8_str("x"))->Run(); | 10055 value = CompileRun("x"); |
| 9954 CHECK_EQ(12, value->Int32Value()); | 10056 CHECK_EQ(12, value->Int32Value()); |
| 9955 | 10057 |
| 9956 value = Script::Compile(v8_str("f()"))->Run(); | 10058 value = CompileRun("f()"); |
| 9957 CHECK_EQ(42, value->Int32Value()); | 10059 CHECK_EQ(42, value->Int32Value()); |
| 9958 | 10060 |
| 9959 Script::Compile(v8_str("y = 43"))->Run(); | 10061 CompileRun("y = 43"); |
| 9960 CHECK_EQ(1, shadow_y_setter_call_count); | 10062 CHECK_EQ(1, shadow_y_setter_call_count); |
| 9961 value = Script::Compile(v8_str("y"))->Run(); | 10063 value = CompileRun("y"); |
| 9962 CHECK_EQ(1, shadow_y_getter_call_count); | 10064 CHECK_EQ(1, shadow_y_getter_call_count); |
| 9963 CHECK_EQ(42, value->Int32Value()); | 10065 CHECK_EQ(42, value->Int32Value()); |
| 9964 } | 10066 } |
| 9965 | 10067 |
| 9966 | 10068 |
| 9967 THREADED_TEST(HiddenPrototype) { | 10069 THREADED_TEST(HiddenPrototype) { |
| 9968 LocalContext context; | 10070 LocalContext context; |
| 9969 v8::Isolate* isolate = context->GetIsolate(); | 10071 v8::Isolate* isolate = context->GetIsolate(); |
| 9970 v8::HandleScope handle_scope(isolate); | 10072 v8::HandleScope handle_scope(isolate); |
| 9971 | 10073 |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10575 "test();"); | 10677 "test();"); |
| 10576 CHECK_EQ(0, value->Int32Value()); | 10678 CHECK_EQ(0, value->Int32Value()); |
| 10577 } | 10679 } |
| 10578 | 10680 |
| 10579 | 10681 |
| 10580 THREADED_TEST(EvalAliasedDynamic) { | 10682 THREADED_TEST(EvalAliasedDynamic) { |
| 10581 LocalContext current; | 10683 LocalContext current; |
| 10582 v8::HandleScope scope(current->GetIsolate()); | 10684 v8::HandleScope scope(current->GetIsolate()); |
| 10583 | 10685 |
| 10584 // Tests where aliased eval can only be resolved dynamically. | 10686 // Tests where aliased eval can only be resolved dynamically. |
| 10585 Local<Script> script = | 10687 Local<Script> script = v8_compile( |
| 10586 Script::Compile(v8_str("function f(x) { " | 10688 "function f(x) { " |
| 10587 " var foo = 2;" | 10689 " var foo = 2;" |
| 10588 " with (x) { return eval('foo'); }" | 10690 " with (x) { return eval('foo'); }" |
| 10589 "}" | 10691 "}" |
| 10590 "foo = 0;" | 10692 "foo = 0;" |
| 10591 "result1 = f(new Object());" | 10693 "result1 = f(new Object());" |
| 10592 "result2 = f(this);" | 10694 "result2 = f(this);" |
| 10593 "var x = new Object();" | 10695 "var x = new Object();" |
| 10594 "x.eval = function(x) { return 1; };" | 10696 "x.eval = function(x) { return 1; };" |
| 10595 "result3 = f(x);")); | 10697 "result3 = f(x);"); |
| 10596 script->Run(); | 10698 script->Run(); |
| 10597 CHECK_EQ(2, current->Global()->Get(v8_str("result1"))->Int32Value()); | 10699 CHECK_EQ(2, current->Global()->Get(v8_str("result1"))->Int32Value()); |
| 10598 CHECK_EQ(0, current->Global()->Get(v8_str("result2"))->Int32Value()); | 10700 CHECK_EQ(0, current->Global()->Get(v8_str("result2"))->Int32Value()); |
| 10599 CHECK_EQ(1, current->Global()->Get(v8_str("result3"))->Int32Value()); | 10701 CHECK_EQ(1, current->Global()->Get(v8_str("result3"))->Int32Value()); |
| 10600 | 10702 |
| 10601 v8::TryCatch try_catch; | 10703 v8::TryCatch try_catch; |
| 10602 script = | 10704 script = v8_compile( |
| 10603 Script::Compile(v8_str("function f(x) { " | 10705 "function f(x) { " |
| 10604 " var bar = 2;" | 10706 " var bar = 2;" |
| 10605 " with (x) { return eval('bar'); }" | 10707 " with (x) { return eval('bar'); }" |
| 10606 "}" | 10708 "}" |
| 10607 "result4 = f(this)")); | 10709 "result4 = f(this)"); |
| 10608 script->Run(); | 10710 script->Run(); |
| 10609 CHECK(!try_catch.HasCaught()); | 10711 CHECK(!try_catch.HasCaught()); |
| 10610 CHECK_EQ(2, current->Global()->Get(v8_str("result4"))->Int32Value()); | 10712 CHECK_EQ(2, current->Global()->Get(v8_str("result4"))->Int32Value()); |
| 10611 | 10713 |
| 10612 try_catch.Reset(); | 10714 try_catch.Reset(); |
| 10613 } | 10715 } |
| 10614 | 10716 |
| 10615 | 10717 |
| 10616 THREADED_TEST(CrossEval) { | 10718 THREADED_TEST(CrossEval) { |
| 10617 v8::HandleScope scope(CcTest::isolate()); | 10719 v8::HandleScope scope(CcTest::isolate()); |
| 10618 LocalContext other; | 10720 LocalContext other; |
| 10619 LocalContext current; | 10721 LocalContext current; |
| 10620 | 10722 |
| 10621 Local<String> token = v8_str("<security token>"); | 10723 Local<String> token = v8_str("<security token>"); |
| 10622 other->SetSecurityToken(token); | 10724 other->SetSecurityToken(token); |
| 10623 current->SetSecurityToken(token); | 10725 current->SetSecurityToken(token); |
| 10624 | 10726 |
| 10625 // Set up reference from current to other. | 10727 // Set up reference from current to other. |
| 10626 current->Global()->Set(v8_str("other"), other->Global()); | 10728 current->Global()->Set(v8_str("other"), other->Global()); |
| 10627 | 10729 |
| 10628 // Check that new variables are introduced in other context. | 10730 // Check that new variables are introduced in other context. |
| 10629 Local<Script> script = | 10731 Local<Script> script = v8_compile("other.eval('var foo = 1234')"); |
| 10630 Script::Compile(v8_str("other.eval('var foo = 1234')")); | |
| 10631 script->Run(); | 10732 script->Run(); |
| 10632 Local<Value> foo = other->Global()->Get(v8_str("foo")); | 10733 Local<Value> foo = other->Global()->Get(v8_str("foo")); |
| 10633 CHECK_EQ(1234, foo->Int32Value()); | 10734 CHECK_EQ(1234, foo->Int32Value()); |
| 10634 CHECK(!current->Global()->Has(v8_str("foo"))); | 10735 CHECK(!current->Global()->Has(v8_str("foo"))); |
| 10635 | 10736 |
| 10636 // Check that writing to non-existing properties introduces them in | 10737 // Check that writing to non-existing properties introduces them in |
| 10637 // the other context. | 10738 // the other context. |
| 10638 script = | 10739 script = v8_compile("other.eval('na = 1234')"); |
| 10639 Script::Compile(v8_str("other.eval('na = 1234')")); | |
| 10640 script->Run(); | 10740 script->Run(); |
| 10641 CHECK_EQ(1234, other->Global()->Get(v8_str("na"))->Int32Value()); | 10741 CHECK_EQ(1234, other->Global()->Get(v8_str("na"))->Int32Value()); |
| 10642 CHECK(!current->Global()->Has(v8_str("na"))); | 10742 CHECK(!current->Global()->Has(v8_str("na"))); |
| 10643 | 10743 |
| 10644 // Check that global variables in current context are not visible in other | 10744 // Check that global variables in current context are not visible in other |
| 10645 // context. | 10745 // context. |
| 10646 v8::TryCatch try_catch; | 10746 v8::TryCatch try_catch; |
| 10647 script = | 10747 script = v8_compile("var bar = 42; other.eval('bar');"); |
| 10648 Script::Compile(v8_str("var bar = 42; other.eval('bar');")); | |
| 10649 Local<Value> result = script->Run(); | 10748 Local<Value> result = script->Run(); |
| 10650 CHECK(try_catch.HasCaught()); | 10749 CHECK(try_catch.HasCaught()); |
| 10651 try_catch.Reset(); | 10750 try_catch.Reset(); |
| 10652 | 10751 |
| 10653 // Check that local variables in current context are not visible in other | 10752 // Check that local variables in current context are not visible in other |
| 10654 // context. | 10753 // context. |
| 10655 script = | 10754 script = v8_compile( |
| 10656 Script::Compile(v8_str("(function() { " | 10755 "(function() { " |
| 10657 " var baz = 87;" | 10756 " var baz = 87;" |
| 10658 " return other.eval('baz');" | 10757 " return other.eval('baz');" |
| 10659 "})();")); | 10758 "})();"); |
| 10660 result = script->Run(); | 10759 result = script->Run(); |
| 10661 CHECK(try_catch.HasCaught()); | 10760 CHECK(try_catch.HasCaught()); |
| 10662 try_catch.Reset(); | 10761 try_catch.Reset(); |
| 10663 | 10762 |
| 10664 // Check that global variables in the other environment are visible | 10763 // Check that global variables in the other environment are visible |
| 10665 // when evaluting code. | 10764 // when evaluting code. |
| 10666 other->Global()->Set(v8_str("bis"), v8_num(1234)); | 10765 other->Global()->Set(v8_str("bis"), v8_num(1234)); |
| 10667 script = Script::Compile(v8_str("other.eval('bis')")); | 10766 script = v8_compile("other.eval('bis')"); |
| 10668 CHECK_EQ(1234, script->Run()->Int32Value()); | 10767 CHECK_EQ(1234, script->Run()->Int32Value()); |
| 10669 CHECK(!try_catch.HasCaught()); | 10768 CHECK(!try_catch.HasCaught()); |
| 10670 | 10769 |
| 10671 // Check that the 'this' pointer points to the global object evaluating | 10770 // Check that the 'this' pointer points to the global object evaluating |
| 10672 // code. | 10771 // code. |
| 10673 other->Global()->Set(v8_str("t"), other->Global()); | 10772 other->Global()->Set(v8_str("t"), other->Global()); |
| 10674 script = Script::Compile(v8_str("other.eval('this == t')")); | 10773 script = v8_compile("other.eval('this == t')"); |
| 10675 result = script->Run(); | 10774 result = script->Run(); |
| 10676 CHECK(result->IsTrue()); | 10775 CHECK(result->IsTrue()); |
| 10677 CHECK(!try_catch.HasCaught()); | 10776 CHECK(!try_catch.HasCaught()); |
| 10678 | 10777 |
| 10679 // Check that variables introduced in with-statement are not visible in | 10778 // Check that variables introduced in with-statement are not visible in |
| 10680 // other context. | 10779 // other context. |
| 10681 script = | 10780 script = v8_compile("with({x:2}){other.eval('x')}"); |
| 10682 Script::Compile(v8_str("with({x:2}){other.eval('x')}")); | |
| 10683 result = script->Run(); | 10781 result = script->Run(); |
| 10684 CHECK(try_catch.HasCaught()); | 10782 CHECK(try_catch.HasCaught()); |
| 10685 try_catch.Reset(); | 10783 try_catch.Reset(); |
| 10686 | 10784 |
| 10687 // Check that you cannot use 'eval.call' with another object than the | 10785 // Check that you cannot use 'eval.call' with another object than the |
| 10688 // current global object. | 10786 // current global object. |
| 10689 script = | 10787 script = v8_compile("other.y = 1; eval.call(other, 'y')"); |
| 10690 Script::Compile(v8_str("other.y = 1; eval.call(other, 'y')")); | |
| 10691 result = script->Run(); | 10788 result = script->Run(); |
| 10692 CHECK(try_catch.HasCaught()); | 10789 CHECK(try_catch.HasCaught()); |
| 10693 } | 10790 } |
| 10694 | 10791 |
| 10695 | 10792 |
| 10696 // Test that calling eval in a context which has been detached from | 10793 // Test that calling eval in a context which has been detached from |
| 10697 // its global throws an exception. This behavior is consistent with | 10794 // its global throws an exception. This behavior is consistent with |
| 10698 // other JavaScript implementations. | 10795 // other JavaScript implementations. |
| 10699 THREADED_TEST(EvalInDetachedGlobal) { | 10796 THREADED_TEST(EvalInDetachedGlobal) { |
| 10700 v8::Isolate* isolate = CcTest::isolate(); | 10797 v8::Isolate* isolate = CcTest::isolate(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10735 LocalContext current; | 10832 LocalContext current; |
| 10736 | 10833 |
| 10737 Local<String> token = v8_str("<security token>"); | 10834 Local<String> token = v8_str("<security token>"); |
| 10738 other->SetSecurityToken(token); | 10835 other->SetSecurityToken(token); |
| 10739 current->SetSecurityToken(token); | 10836 current->SetSecurityToken(token); |
| 10740 | 10837 |
| 10741 // Set up reference from current to other. | 10838 // Set up reference from current to other. |
| 10742 current->Global()->Set(v8_str("other"), other->Global()); | 10839 current->Global()->Set(v8_str("other"), other->Global()); |
| 10743 | 10840 |
| 10744 // Trigger lazy loading in other context. | 10841 // Trigger lazy loading in other context. |
| 10745 Local<Script> script = | 10842 Local<Script> script = v8_compile("other.eval('new Date(42)')"); |
| 10746 Script::Compile(v8_str("other.eval('new Date(42)')")); | |
| 10747 Local<Value> value = script->Run(); | 10843 Local<Value> value = script->Run(); |
| 10748 CHECK_EQ(42.0, value->NumberValue()); | 10844 CHECK_EQ(42.0, value->NumberValue()); |
| 10749 } | 10845 } |
| 10750 | 10846 |
| 10751 | 10847 |
| 10752 static void call_as_function(const v8::FunctionCallbackInfo<v8::Value>& args) { | 10848 static void call_as_function(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 10753 ApiTestFuzzer::Fuzz(); | 10849 ApiTestFuzzer::Fuzz(); |
| 10754 if (args.IsConstructCall()) { | 10850 if (args.IsConstructCall()) { |
| 10755 if (args[0]->IsInt32()) { | 10851 if (args[0]->IsInt32()) { |
| 10756 args.GetReturnValue().Set(v8_num(-args[0]->Int32Value())); | 10852 args.GetReturnValue().Set(v8_num(-args[0]->Int32Value())); |
| (...skipping 2165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12922 | 13018 |
| 12923 | 13019 |
| 12924 static void ChildGetter(Local<String> name, | 13020 static void ChildGetter(Local<String> name, |
| 12925 const v8::PropertyCallbackInfo<v8::Value>& info) { | 13021 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 12926 ApiTestFuzzer::Fuzz(); | 13022 ApiTestFuzzer::Fuzz(); |
| 12927 info.GetReturnValue().Set(v8_num(42)); | 13023 info.GetReturnValue().Set(v8_num(42)); |
| 12928 } | 13024 } |
| 12929 | 13025 |
| 12930 | 13026 |
| 12931 THREADED_TEST(Overriding) { | 13027 THREADED_TEST(Overriding) { |
| 12932 i::FLAG_es5_readonly = true; | |
| 12933 LocalContext context; | 13028 LocalContext context; |
| 12934 v8::Isolate* isolate = context->GetIsolate(); | 13029 v8::Isolate* isolate = context->GetIsolate(); |
| 12935 v8::HandleScope scope(isolate); | 13030 v8::HandleScope scope(isolate); |
| 12936 | 13031 |
| 12937 // Parent template. | 13032 // Parent template. |
| 12938 Local<v8::FunctionTemplate> parent_templ = v8::FunctionTemplate::New(isolate); | 13033 Local<v8::FunctionTemplate> parent_templ = v8::FunctionTemplate::New(isolate); |
| 12939 Local<ObjectTemplate> parent_instance_templ = | 13034 Local<ObjectTemplate> parent_instance_templ = |
| 12940 parent_templ->InstanceTemplate(); | 13035 parent_templ->InstanceTemplate(); |
| 12941 parent_instance_templ->SetAccessor(v8_str("f"), ParentGetter); | 13036 parent_instance_templ->SetAccessor(v8_str("f"), ParentGetter); |
| 12942 | 13037 |
| (...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14241 CHECK_EQ(1, result->InternalFieldCount()); | 14336 CHECK_EQ(1, result->InternalFieldCount()); |
| 14242 } | 14337 } |
| 14243 | 14338 |
| 14244 | 14339 |
| 14245 // If part of the threaded tests, this test makes ThreadingTest fail | 14340 // If part of the threaded tests, this test makes ThreadingTest fail |
| 14246 // on mac. | 14341 // on mac. |
| 14247 TEST(CatchStackOverflow) { | 14342 TEST(CatchStackOverflow) { |
| 14248 LocalContext context; | 14343 LocalContext context; |
| 14249 v8::HandleScope scope(context->GetIsolate()); | 14344 v8::HandleScope scope(context->GetIsolate()); |
| 14250 v8::TryCatch try_catch; | 14345 v8::TryCatch try_catch; |
| 14251 v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::NewFromUtf8( | 14346 v8::Handle<v8::Value> result = CompileRun( |
| 14252 context->GetIsolate(), | |
| 14253 "function f() {" | 14347 "function f() {" |
| 14254 " return f();" | 14348 " return f();" |
| 14255 "}" | 14349 "}" |
| 14256 "" | 14350 "" |
| 14257 "f();")); | 14351 "f();"); |
| 14258 v8::Handle<v8::Value> result = script->Run(); | |
| 14259 CHECK(result.IsEmpty()); | 14352 CHECK(result.IsEmpty()); |
| 14260 } | 14353 } |
| 14261 | 14354 |
| 14262 | 14355 |
| 14263 static void CheckTryCatchSourceInfo(v8::Handle<v8::Script> script, | 14356 static void CheckTryCatchSourceInfo(v8::Handle<v8::Script> script, |
| 14264 const char* resource_name, | 14357 const char* resource_name, |
| 14265 int line_offset) { | 14358 int line_offset) { |
| 14266 v8::HandleScope scope(CcTest::isolate()); | 14359 v8::HandleScope scope(CcTest::isolate()); |
| 14267 v8::TryCatch try_catch; | 14360 v8::TryCatch try_catch; |
| 14268 v8::Handle<v8::Value> result = script->Run(); | 14361 v8::Handle<v8::Value> result = script->Run(); |
| 14269 CHECK(result.IsEmpty()); | 14362 CHECK(result.IsEmpty()); |
| 14270 CHECK(try_catch.HasCaught()); | 14363 CHECK(try_catch.HasCaught()); |
| 14271 v8::Handle<v8::Message> message = try_catch.Message(); | 14364 v8::Handle<v8::Message> message = try_catch.Message(); |
| 14272 CHECK(!message.IsEmpty()); | 14365 CHECK(!message.IsEmpty()); |
| 14273 CHECK_EQ(10 + line_offset, message->GetLineNumber()); | 14366 CHECK_EQ(10 + line_offset, message->GetLineNumber()); |
| 14274 CHECK_EQ(91, message->GetStartPosition()); | 14367 CHECK_EQ(91, message->GetStartPosition()); |
| 14275 CHECK_EQ(92, message->GetEndPosition()); | 14368 CHECK_EQ(92, message->GetEndPosition()); |
| 14276 CHECK_EQ(2, message->GetStartColumn()); | 14369 CHECK_EQ(2, message->GetStartColumn()); |
| 14277 CHECK_EQ(3, message->GetEndColumn()); | 14370 CHECK_EQ(3, message->GetEndColumn()); |
| 14278 v8::String::Utf8Value line(message->GetSourceLine()); | 14371 v8::String::Utf8Value line(message->GetSourceLine()); |
| 14279 CHECK_EQ(" throw 'nirk';", *line); | 14372 CHECK_EQ(" throw 'nirk';", *line); |
| 14280 v8::String::Utf8Value name(message->GetScriptResourceName()); | 14373 v8::String::Utf8Value name(message->GetScriptResourceName()); |
| 14281 CHECK_EQ(resource_name, *name); | 14374 CHECK_EQ(resource_name, *name); |
| 14282 } | 14375 } |
| 14283 | 14376 |
| 14284 | 14377 |
| 14285 THREADED_TEST(TryCatchSourceInfo) { | 14378 THREADED_TEST(TryCatchSourceInfo) { |
| 14286 LocalContext context; | 14379 LocalContext context; |
| 14287 v8::HandleScope scope(context->GetIsolate()); | 14380 v8::HandleScope scope(context->GetIsolate()); |
| 14288 v8::Handle<v8::String> source = v8::String::NewFromUtf8( | 14381 v8::Local<v8::String> source = v8_str( |
| 14289 context->GetIsolate(), | |
| 14290 "function Foo() {\n" | 14382 "function Foo() {\n" |
| 14291 " return Bar();\n" | 14383 " return Bar();\n" |
| 14292 "}\n" | 14384 "}\n" |
| 14293 "\n" | 14385 "\n" |
| 14294 "function Bar() {\n" | 14386 "function Bar() {\n" |
| 14295 " return Baz();\n" | 14387 " return Baz();\n" |
| 14296 "}\n" | 14388 "}\n" |
| 14297 "\n" | 14389 "\n" |
| 14298 "function Baz() {\n" | 14390 "function Baz() {\n" |
| 14299 " throw 'nirk';\n" | 14391 " throw 'nirk';\n" |
| 14300 "}\n" | 14392 "}\n" |
| 14301 "\n" | 14393 "\n" |
| 14302 "Foo();\n"); | 14394 "Foo();\n"); |
| 14303 | 14395 |
| 14304 const char* resource_name; | 14396 const char* resource_name; |
| 14305 v8::Handle<v8::Script> script; | 14397 v8::Handle<v8::Script> script; |
| 14306 resource_name = "test.js"; | 14398 resource_name = "test.js"; |
| 14307 script = v8::Script::Compile( | 14399 script = CompileWithOrigin(source, resource_name); |
| 14308 source, v8::String::NewFromUtf8(context->GetIsolate(), resource_name)); | |
| 14309 CheckTryCatchSourceInfo(script, resource_name, 0); | 14400 CheckTryCatchSourceInfo(script, resource_name, 0); |
| 14310 | 14401 |
| 14311 resource_name = "test1.js"; | 14402 resource_name = "test1.js"; |
| 14312 v8::ScriptOrigin origin1( | 14403 v8::ScriptOrigin origin1( |
| 14313 v8::String::NewFromUtf8(context->GetIsolate(), resource_name)); | 14404 v8::String::NewFromUtf8(context->GetIsolate(), resource_name)); |
| 14314 script = v8::Script::Compile(source, &origin1); | 14405 script = v8::Script::Compile(source, &origin1); |
| 14315 CheckTryCatchSourceInfo(script, resource_name, 0); | 14406 CheckTryCatchSourceInfo(script, resource_name, 0); |
| 14316 | 14407 |
| 14317 resource_name = "test2.js"; | 14408 resource_name = "test2.js"; |
| 14318 v8::ScriptOrigin origin2( | 14409 v8::ScriptOrigin origin2( |
| 14319 v8::String::NewFromUtf8(context->GetIsolate(), resource_name), | 14410 v8::String::NewFromUtf8(context->GetIsolate(), resource_name), |
| 14320 v8::Integer::New(context->GetIsolate(), 7)); | 14411 v8::Integer::New(context->GetIsolate(), 7)); |
| 14321 script = v8::Script::Compile(source, &origin2); | 14412 script = v8::Script::Compile(source, &origin2); |
| 14322 CheckTryCatchSourceInfo(script, resource_name, 7); | 14413 CheckTryCatchSourceInfo(script, resource_name, 7); |
| 14323 } | 14414 } |
| 14324 | 14415 |
| 14325 | 14416 |
| 14326 THREADED_TEST(CompilationCache) { | 14417 THREADED_TEST(CompilationCache) { |
| 14327 LocalContext context; | 14418 LocalContext context; |
| 14328 v8::HandleScope scope(context->GetIsolate()); | 14419 v8::HandleScope scope(context->GetIsolate()); |
| 14329 v8::Handle<v8::String> source0 = | 14420 v8::Handle<v8::String> source0 = |
| 14330 v8::String::NewFromUtf8(context->GetIsolate(), "1234"); | 14421 v8::String::NewFromUtf8(context->GetIsolate(), "1234"); |
| 14331 v8::Handle<v8::String> source1 = | 14422 v8::Handle<v8::String> source1 = |
| 14332 v8::String::NewFromUtf8(context->GetIsolate(), "1234"); | 14423 v8::String::NewFromUtf8(context->GetIsolate(), "1234"); |
| 14333 v8::Handle<v8::Script> script0 = v8::Script::Compile( | 14424 v8::Handle<v8::Script> script0 = CompileWithOrigin(source0, "test.js"); |
| 14334 source0, v8::String::NewFromUtf8(context->GetIsolate(), "test.js")); | 14425 v8::Handle<v8::Script> script1 = CompileWithOrigin(source1, "test.js"); |
| 14335 v8::Handle<v8::Script> script1 = v8::Script::Compile( | |
| 14336 source1, v8::String::NewFromUtf8(context->GetIsolate(), "test.js")); | |
| 14337 v8::Handle<v8::Script> script2 = | 14426 v8::Handle<v8::Script> script2 = |
| 14338 v8::Script::Compile(source0); // different origin | 14427 v8::Script::Compile(source0); // different origin |
| 14339 CHECK_EQ(1234, script0->Run()->Int32Value()); | 14428 CHECK_EQ(1234, script0->Run()->Int32Value()); |
| 14340 CHECK_EQ(1234, script1->Run()->Int32Value()); | 14429 CHECK_EQ(1234, script1->Run()->Int32Value()); |
| 14341 CHECK_EQ(1234, script2->Run()->Int32Value()); | 14430 CHECK_EQ(1234, script2->Run()->Int32Value()); |
| 14342 } | 14431 } |
| 14343 | 14432 |
| 14344 | 14433 |
| 14345 static void FunctionNameCallback( | 14434 static void FunctionNameCallback( |
| 14346 const v8::FunctionCallbackInfo<v8::Value>& args) { | 14435 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14399 v8::String::Utf8Value elm(props->Get(v8::Integer::New(isolate, i))); | 14488 v8::String::Utf8Value elm(props->Get(v8::Integer::New(isolate, i))); |
| 14400 CHECK_EQ(elmv[i], *elm); | 14489 CHECK_EQ(elmv[i], *elm); |
| 14401 } | 14490 } |
| 14402 } | 14491 } |
| 14403 | 14492 |
| 14404 | 14493 |
| 14405 THREADED_TEST(PropertyEnumeration) { | 14494 THREADED_TEST(PropertyEnumeration) { |
| 14406 LocalContext context; | 14495 LocalContext context; |
| 14407 v8::Isolate* isolate = context->GetIsolate(); | 14496 v8::Isolate* isolate = context->GetIsolate(); |
| 14408 v8::HandleScope scope(isolate); | 14497 v8::HandleScope scope(isolate); |
| 14409 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::NewFromUtf8( | 14498 v8::Handle<v8::Value> obj = CompileRun( |
| 14410 context->GetIsolate(), | |
| 14411 "var result = [];" | 14499 "var result = [];" |
| 14412 "result[0] = {};" | 14500 "result[0] = {};" |
| 14413 "result[1] = {a: 1, b: 2};" | 14501 "result[1] = {a: 1, b: 2};" |
| 14414 "result[2] = [1, 2, 3];" | 14502 "result[2] = [1, 2, 3];" |
| 14415 "var proto = {x: 1, y: 2, z: 3};" | 14503 "var proto = {x: 1, y: 2, z: 3};" |
| 14416 "var x = { __proto__: proto, w: 0, z: 1 };" | 14504 "var x = { __proto__: proto, w: 0, z: 1 };" |
| 14417 "result[3] = x;" | 14505 "result[3] = x;" |
| 14418 "result;"))->Run(); | 14506 "result;"); |
| 14419 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); | 14507 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); |
| 14420 CHECK_EQ(4, elms->Length()); | 14508 CHECK_EQ(4, elms->Length()); |
| 14421 int elmc0 = 0; | 14509 int elmc0 = 0; |
| 14422 const char** elmv0 = NULL; | 14510 const char** elmv0 = NULL; |
| 14423 CheckProperties( | 14511 CheckProperties( |
| 14424 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); | 14512 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); |
| 14425 CheckOwnProperties( | 14513 CheckOwnProperties( |
| 14426 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); | 14514 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); |
| 14427 int elmc1 = 2; | 14515 int elmc1 = 2; |
| 14428 const char* elmv1[] = {"a", "b"}; | 14516 const char* elmv1[] = {"a", "b"}; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 14444 const char* elmv4[] = {"w", "z"}; | 14532 const char* elmv4[] = {"w", "z"}; |
| 14445 CheckOwnProperties( | 14533 CheckOwnProperties( |
| 14446 isolate, elms->Get(v8::Integer::New(isolate, 3)), elmc4, elmv4); | 14534 isolate, elms->Get(v8::Integer::New(isolate, 3)), elmc4, elmv4); |
| 14447 } | 14535 } |
| 14448 | 14536 |
| 14449 | 14537 |
| 14450 THREADED_TEST(PropertyEnumeration2) { | 14538 THREADED_TEST(PropertyEnumeration2) { |
| 14451 LocalContext context; | 14539 LocalContext context; |
| 14452 v8::Isolate* isolate = context->GetIsolate(); | 14540 v8::Isolate* isolate = context->GetIsolate(); |
| 14453 v8::HandleScope scope(isolate); | 14541 v8::HandleScope scope(isolate); |
| 14454 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::NewFromUtf8( | 14542 v8::Handle<v8::Value> obj = CompileRun( |
| 14455 context->GetIsolate(), | |
| 14456 "var result = [];" | 14543 "var result = [];" |
| 14457 "result[0] = {};" | 14544 "result[0] = {};" |
| 14458 "result[1] = {a: 1, b: 2};" | 14545 "result[1] = {a: 1, b: 2};" |
| 14459 "result[2] = [1, 2, 3];" | 14546 "result[2] = [1, 2, 3];" |
| 14460 "var proto = {x: 1, y: 2, z: 3};" | 14547 "var proto = {x: 1, y: 2, z: 3};" |
| 14461 "var x = { __proto__: proto, w: 0, z: 1 };" | 14548 "var x = { __proto__: proto, w: 0, z: 1 };" |
| 14462 "result[3] = x;" | 14549 "result[3] = x;" |
| 14463 "result;"))->Run(); | 14550 "result;"); |
| 14464 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); | 14551 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); |
| 14465 CHECK_EQ(4, elms->Length()); | 14552 CHECK_EQ(4, elms->Length()); |
| 14466 int elmc0 = 0; | 14553 int elmc0 = 0; |
| 14467 const char** elmv0 = NULL; | 14554 const char** elmv0 = NULL; |
| 14468 CheckProperties(isolate, | 14555 CheckProperties(isolate, |
| 14469 elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); | 14556 elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); |
| 14470 | 14557 |
| 14471 v8::Handle<v8::Value> val = elms->Get(v8::Integer::New(isolate, 0)); | 14558 v8::Handle<v8::Value> val = elms->Get(v8::Integer::New(isolate, 0)); |
| 14472 v8::Handle<v8::Array> props = val.As<v8::Object>()->GetPropertyNames(); | 14559 v8::Handle<v8::Array> props = val.As<v8::Object>()->GetPropertyNames(); |
| 14473 CHECK_EQ(0, props->Length()); | 14560 CHECK_EQ(0, props->Length()); |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14859 const int kFunctionEntrySize = i::FunctionEntry::kSize; | 14946 const int kFunctionEntrySize = i::FunctionEntry::kSize; |
| 14860 const int kFunctionEntryStartOffset = 0; | 14947 const int kFunctionEntryStartOffset = 0; |
| 14861 const int kFunctionEntryEndOffset = 1; | 14948 const int kFunctionEntryEndOffset = 1; |
| 14862 unsigned* sd_data = | 14949 unsigned* sd_data = |
| 14863 reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); | 14950 reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); |
| 14864 | 14951 |
| 14865 // Overwrite function bar's end position with 0. | 14952 // Overwrite function bar's end position with 0. |
| 14866 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryEndOffset] = 0; | 14953 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryEndOffset] = 0; |
| 14867 v8::TryCatch try_catch; | 14954 v8::TryCatch try_catch; |
| 14868 | 14955 |
| 14869 Local<String> source = String::NewFromUtf8(isolate, script); | 14956 v8::ScriptCompiler::Source script_source( |
| 14870 Local<Script> compiled_script = Script::New(source, NULL, sd); | 14957 String::NewFromUtf8(isolate, script), |
| 14958 v8::ScriptCompiler::CachedData( |
| 14959 reinterpret_cast<const uint8_t*>(sd->Data()), sd->Length())); |
| 14960 Local<v8::UnboundScript> compiled_script = |
| 14961 v8::ScriptCompiler::CompileUnbound(isolate, script_source); |
| 14962 |
| 14871 CHECK(try_catch.HasCaught()); | 14963 CHECK(try_catch.HasCaught()); |
| 14872 String::Utf8Value exception_value(try_catch.Message()->Get()); | 14964 String::Utf8Value exception_value(try_catch.Message()->Get()); |
| 14873 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar", | 14965 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar", |
| 14874 *exception_value); | 14966 *exception_value); |
| 14875 | 14967 |
| 14876 try_catch.Reset(); | 14968 try_catch.Reset(); |
| 14877 delete sd; | 14969 delete sd; |
| 14878 | 14970 |
| 14879 // Overwrite function bar's start position with 200. The function entry | 14971 // Overwrite function bar's start position with 200. The function entry |
| 14880 // will not be found when searching for it by position and we should fall | 14972 // will not be found when searching for it by position and we should fall |
| 14881 // back on eager compilation. | 14973 // back on eager compilation. |
| 14882 sd = v8::ScriptData::PreCompile(v8::String::NewFromUtf8( | 14974 sd = v8::ScriptData::PreCompile(v8::String::NewFromUtf8( |
| 14883 isolate, script, v8::String::kNormalString, i::StrLength(script))); | 14975 isolate, script, v8::String::kNormalString, i::StrLength(script))); |
| 14884 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); | 14976 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); |
| 14885 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] = | 14977 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] = |
| 14886 200; | 14978 200; |
| 14887 compiled_script = Script::New(source, NULL, sd); | 14979 v8::ScriptCompiler::Source script_source2( |
| 14980 String::NewFromUtf8(isolate, script), |
| 14981 v8::ScriptCompiler::CachedData( |
| 14982 reinterpret_cast<const uint8_t*>(sd->Data()), sd->Length())); |
| 14983 compiled_script = |
| 14984 v8::ScriptCompiler::CompileUnbound(isolate, script_source2); |
| 14888 CHECK(!try_catch.HasCaught()); | 14985 CHECK(!try_catch.HasCaught()); |
| 14889 | 14986 |
| 14890 delete sd; | 14987 delete sd; |
| 14891 } | 14988 } |
| 14892 | 14989 |
| 14893 | 14990 |
| 14894 // This tests that we do not allow dictionary load/call inline caches | 14991 // This tests that we do not allow dictionary load/call inline caches |
| 14895 // to use functions that have not yet been compiled. The potential | 14992 // to use functions that have not yet been compiled. The potential |
| 14896 // problem of loading a function that has not yet been compiled can | 14993 // problem of loading a function that has not yet been compiled can |
| 14897 // arise because we share code between contexts via the compilation | 14994 // arise because we share code between contexts via the compilation |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15193 regexp_interruption_data.string.Reset(); | 15290 regexp_interruption_data.string.Reset(); |
| 15194 i::DeleteArray(uc16_content); | 15291 i::DeleteArray(uc16_content); |
| 15195 } | 15292 } |
| 15196 | 15293 |
| 15197 #endif // V8_INTERPRETED_REGEXP | 15294 #endif // V8_INTERPRETED_REGEXP |
| 15198 | 15295 |
| 15199 | 15296 |
| 15200 // Test that we cannot set a property on the global object if there | 15297 // Test that we cannot set a property on the global object if there |
| 15201 // is a read-only property in the prototype chain. | 15298 // is a read-only property in the prototype chain. |
| 15202 TEST(ReadOnlyPropertyInGlobalProto) { | 15299 TEST(ReadOnlyPropertyInGlobalProto) { |
| 15203 i::FLAG_es5_readonly = true; | |
| 15204 v8::Isolate* isolate = CcTest::isolate(); | 15300 v8::Isolate* isolate = CcTest::isolate(); |
| 15205 v8::HandleScope scope(isolate); | 15301 v8::HandleScope scope(isolate); |
| 15206 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); | 15302 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); |
| 15207 LocalContext context(0, templ); | 15303 LocalContext context(0, templ); |
| 15208 v8::Handle<v8::Object> global = context->Global(); | 15304 v8::Handle<v8::Object> global = context->Global(); |
| 15209 v8::Handle<v8::Object> global_proto = | 15305 v8::Handle<v8::Object> global_proto = |
| 15210 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__"))); | 15306 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__"))); |
| 15211 global_proto->Set(v8_str("x"), v8::Integer::New(isolate, 0), v8::ReadOnly); | 15307 global_proto->Set(v8_str("x"), v8::Integer::New(isolate, 0), v8::ReadOnly); |
| 15212 global_proto->Set(v8_str("y"), v8::Integer::New(isolate, 0), v8::ReadOnly); | 15308 global_proto->Set(v8_str("y"), v8::Integer::New(isolate, 0), v8::ReadOnly); |
| 15213 // Check without 'eval' or 'with'. | 15309 // Check without 'eval' or 'with'. |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15548 calling_context2->Exit(); | 15644 calling_context2->Exit(); |
| 15549 ::calling_context0.Clear(); | 15645 ::calling_context0.Clear(); |
| 15550 ::calling_context1.Clear(); | 15646 ::calling_context1.Clear(); |
| 15551 ::calling_context2.Clear(); | 15647 ::calling_context2.Clear(); |
| 15552 } | 15648 } |
| 15553 | 15649 |
| 15554 | 15650 |
| 15555 // Check that a variable declaration with no explicit initialization | 15651 // Check that a variable declaration with no explicit initialization |
| 15556 // value does shadow an existing property in the prototype chain. | 15652 // value does shadow an existing property in the prototype chain. |
| 15557 THREADED_TEST(InitGlobalVarInProtoChain) { | 15653 THREADED_TEST(InitGlobalVarInProtoChain) { |
| 15558 i::FLAG_es52_globals = true; | |
| 15559 LocalContext context; | 15654 LocalContext context; |
| 15560 v8::HandleScope scope(context->GetIsolate()); | 15655 v8::HandleScope scope(context->GetIsolate()); |
| 15561 // Introduce a variable in the prototype chain. | 15656 // Introduce a variable in the prototype chain. |
| 15562 CompileRun("__proto__.x = 42"); | 15657 CompileRun("__proto__.x = 42"); |
| 15563 v8::Handle<v8::Value> result = CompileRun("var x = 43; x"); | 15658 v8::Handle<v8::Value> result = CompileRun("var x = 43; x"); |
| 15564 CHECK(!result->IsUndefined()); | 15659 CHECK(!result->IsUndefined()); |
| 15565 CHECK_EQ(43, result->Int32Value()); | 15660 CHECK_EQ(43, result->Int32Value()); |
| 15566 } | 15661 } |
| 15567 | 15662 |
| 15568 | 15663 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15672 result = CompileRun("var sum = 0;" | 15767 result = CompileRun("var sum = 0;" |
| 15673 "for (var i = 0; i < 8; i++) {" | 15768 "for (var i = 0; i < 8; i++) {" |
| 15674 " sum += pixels[i];" | 15769 " sum += pixels[i];" |
| 15675 "}" | 15770 "}" |
| 15676 "sum;"); | 15771 "sum;"); |
| 15677 CHECK_EQ(28, result->Int32Value()); | 15772 CHECK_EQ(28, result->Int32Value()); |
| 15678 | 15773 |
| 15679 i::Handle<i::Smi> value(i::Smi::FromInt(2), | 15774 i::Handle<i::Smi> value(i::Smi::FromInt(2), |
| 15680 reinterpret_cast<i::Isolate*>(context->GetIsolate())); | 15775 reinterpret_cast<i::Isolate*>(context->GetIsolate())); |
| 15681 i::Handle<i::Object> no_failure; | 15776 i::Handle<i::Object> no_failure; |
| 15682 no_failure = | 15777 no_failure = i::JSObject::SetElement(jsobj, 1, value, NONE, i::SLOPPY); |
| 15683 i::JSObject::SetElement(jsobj, 1, value, NONE, i::kNonStrictMode); | |
| 15684 ASSERT(!no_failure.is_null()); | 15778 ASSERT(!no_failure.is_null()); |
| 15685 i::USE(no_failure); | 15779 i::USE(no_failure); |
| 15686 CheckElementValue(isolate, 2, jsobj, 1); | 15780 CheckElementValue(isolate, 2, jsobj, 1); |
| 15687 *value.location() = i::Smi::FromInt(256); | 15781 *value.location() = i::Smi::FromInt(256); |
| 15688 no_failure = | 15782 no_failure = i::JSObject::SetElement(jsobj, 1, value, NONE, i::SLOPPY); |
| 15689 i::JSObject::SetElement(jsobj, 1, value, NONE, i::kNonStrictMode); | |
| 15690 ASSERT(!no_failure.is_null()); | 15783 ASSERT(!no_failure.is_null()); |
| 15691 i::USE(no_failure); | 15784 i::USE(no_failure); |
| 15692 CheckElementValue(isolate, 255, jsobj, 1); | 15785 CheckElementValue(isolate, 255, jsobj, 1); |
| 15693 *value.location() = i::Smi::FromInt(-1); | 15786 *value.location() = i::Smi::FromInt(-1); |
| 15694 no_failure = | 15787 no_failure = i::JSObject::SetElement(jsobj, 1, value, NONE, i::SLOPPY); |
| 15695 i::JSObject::SetElement(jsobj, 1, value, NONE, i::kNonStrictMode); | |
| 15696 ASSERT(!no_failure.is_null()); | 15788 ASSERT(!no_failure.is_null()); |
| 15697 i::USE(no_failure); | 15789 i::USE(no_failure); |
| 15698 CheckElementValue(isolate, 0, jsobj, 1); | 15790 CheckElementValue(isolate, 0, jsobj, 1); |
| 15699 | 15791 |
| 15700 result = CompileRun("for (var i = 0; i < 8; i++) {" | 15792 result = CompileRun("for (var i = 0; i < 8; i++) {" |
| 15701 " pixels[i] = (i * 65) - 109;" | 15793 " pixels[i] = (i * 65) - 109;" |
| 15702 "}" | 15794 "}" |
| 15703 "pixels[1] + pixels[6];"); | 15795 "pixels[1] + pixels[6];"); |
| 15704 CHECK_EQ(255, result->Int32Value()); | 15796 CHECK_EQ(255, result->Int32Value()); |
| 15705 CheckElementValue(isolate, 0, jsobj, 0); | 15797 CheckElementValue(isolate, 0, jsobj, 0); |
| (...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16992 | 17084 |
| 16993 #undef IS_ARRAY_BUFFER_VIEW_TEST | 17085 #undef IS_ARRAY_BUFFER_VIEW_TEST |
| 16994 | 17086 |
| 16995 | 17087 |
| 16996 | 17088 |
| 16997 THREADED_TEST(ScriptContextDependence) { | 17089 THREADED_TEST(ScriptContextDependence) { |
| 16998 LocalContext c1; | 17090 LocalContext c1; |
| 16999 v8::HandleScope scope(c1->GetIsolate()); | 17091 v8::HandleScope scope(c1->GetIsolate()); |
| 17000 const char *source = "foo"; | 17092 const char *source = "foo"; |
| 17001 v8::Handle<v8::Script> dep = | 17093 v8::Handle<v8::Script> dep = |
| 17002 v8::Script::Compile(v8::String::NewFromUtf8(c1->GetIsolate(), source)); | 17094 v8_compile(source); |
| 17003 v8::Handle<v8::Script> indep = | 17095 v8::Handle<v8::UnboundScript> indep = |
| 17004 v8::Script::New(v8::String::NewFromUtf8(c1->GetIsolate(), source)); | 17096 v8::ScriptCompiler::CompileUnbound( |
| 17097 c1->GetIsolate(), v8::ScriptCompiler::Source(v8::String::NewFromUtf8( |
| 17098 c1->GetIsolate(), source))); |
| 17005 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"), | 17099 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"), |
| 17006 v8::Integer::New(c1->GetIsolate(), 100)); | 17100 v8::Integer::New(c1->GetIsolate(), 100)); |
| 17007 CHECK_EQ(dep->Run()->Int32Value(), 100); | 17101 CHECK_EQ(dep->Run()->Int32Value(), 100); |
| 17008 CHECK_EQ(indep->Run()->Int32Value(), 100); | 17102 CHECK_EQ(indep->BindToCurrentContext()->Run()->Int32Value(), 100); |
| 17009 LocalContext c2; | 17103 LocalContext c2; |
| 17010 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"), | 17104 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"), |
| 17011 v8::Integer::New(c2->GetIsolate(), 101)); | 17105 v8::Integer::New(c2->GetIsolate(), 101)); |
| 17012 CHECK_EQ(dep->Run()->Int32Value(), 100); | 17106 CHECK_EQ(dep->Run()->Int32Value(), 100); |
| 17013 CHECK_EQ(indep->Run()->Int32Value(), 101); | 17107 CHECK_EQ(indep->BindToCurrentContext()->Run()->Int32Value(), 101); |
| 17014 } | 17108 } |
| 17015 | 17109 |
| 17016 | 17110 |
| 17017 THREADED_TEST(StackTrace) { | 17111 THREADED_TEST(StackTrace) { |
| 17018 LocalContext context; | 17112 LocalContext context; |
| 17019 v8::HandleScope scope(context->GetIsolate()); | 17113 v8::HandleScope scope(context->GetIsolate()); |
| 17020 v8::TryCatch try_catch; | 17114 v8::TryCatch try_catch; |
| 17021 const char *source = "function foo() { FAIL.FAIL; }; foo();"; | 17115 const char *source = "function foo() { FAIL.FAIL; }; foo();"; |
| 17022 v8::Handle<v8::String> src = | 17116 v8::Handle<v8::String> src = |
| 17023 v8::String::NewFromUtf8(context->GetIsolate(), source); | 17117 v8::String::NewFromUtf8(context->GetIsolate(), source); |
| 17024 v8::Handle<v8::String> origin = | 17118 v8::Handle<v8::String> origin = |
| 17025 v8::String::NewFromUtf8(context->GetIsolate(), "stack-trace-test"); | 17119 v8::String::NewFromUtf8(context->GetIsolate(), "stack-trace-test"); |
| 17026 v8::Script::New(src, origin)->Run(); | 17120 v8::ScriptCompiler::CompileUnbound( |
| 17121 context->GetIsolate(), |
| 17122 v8::ScriptCompiler::Source(src, v8::ScriptOrigin(origin))) |
| 17123 ->BindToCurrentContext() |
| 17124 ->Run(); |
| 17027 CHECK(try_catch.HasCaught()); | 17125 CHECK(try_catch.HasCaught()); |
| 17028 v8::String::Utf8Value stack(try_catch.StackTrace()); | 17126 v8::String::Utf8Value stack(try_catch.StackTrace()); |
| 17029 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); | 17127 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); |
| 17030 } | 17128 } |
| 17031 | 17129 |
| 17032 | 17130 |
| 17033 // Checks that a StackFrame has certain expected values. | 17131 // Checks that a StackFrame has certain expected values. |
| 17034 void checkStackFrame(const char* expected_script_name, | 17132 void checkStackFrame(const char* expected_script_name, |
| 17035 const char* expected_func_name, int expected_line_number, | 17133 const char* expected_func_name, int expected_line_number, |
| 17036 int expected_column, bool is_eval, bool is_constructor, | 17134 int expected_column, bool is_eval, bool is_constructor, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17123 " var y; AnalyzeStackInNativeCode(1);\n" | 17221 " var y; AnalyzeStackInNativeCode(1);\n" |
| 17124 "}\n" | 17222 "}\n" |
| 17125 "function foo() {\n" | 17223 "function foo() {\n" |
| 17126 "\n" | 17224 "\n" |
| 17127 " bar();\n" | 17225 " bar();\n" |
| 17128 "}\n" | 17226 "}\n" |
| 17129 "var x;eval('new foo();');"; | 17227 "var x;eval('new foo();');"; |
| 17130 v8::Handle<v8::String> overview_src = | 17228 v8::Handle<v8::String> overview_src = |
| 17131 v8::String::NewFromUtf8(isolate, overview_source); | 17229 v8::String::NewFromUtf8(isolate, overview_source); |
| 17132 v8::Handle<Value> overview_result( | 17230 v8::Handle<Value> overview_result( |
| 17133 v8::Script::New(overview_src, origin)->Run()); | 17231 v8::ScriptCompiler::CompileUnbound( |
| 17232 isolate, |
| 17233 v8::ScriptCompiler::Source(overview_src, v8::ScriptOrigin(origin))) |
| 17234 ->BindToCurrentContext() |
| 17235 ->Run()); |
| 17134 CHECK(!overview_result.IsEmpty()); | 17236 CHECK(!overview_result.IsEmpty()); |
| 17135 CHECK(overview_result->IsObject()); | 17237 CHECK(overview_result->IsObject()); |
| 17136 | 17238 |
| 17137 // Test getting DETAILED information. | 17239 // Test getting DETAILED information. |
| 17138 const char *detailed_source = | 17240 const char *detailed_source = |
| 17139 "function bat() {AnalyzeStackInNativeCode(2);\n" | 17241 "function bat() {AnalyzeStackInNativeCode(2);\n" |
| 17140 "}\n" | 17242 "}\n" |
| 17141 "\n" | 17243 "\n" |
| 17142 "function baz() {\n" | 17244 "function baz() {\n" |
| 17143 " bat();\n" | 17245 " bat();\n" |
| 17144 "}\n" | 17246 "}\n" |
| 17145 "eval('new baz();');"; | 17247 "eval('new baz();');"; |
| 17146 v8::Handle<v8::String> detailed_src = | 17248 v8::Handle<v8::String> detailed_src = |
| 17147 v8::String::NewFromUtf8(isolate, detailed_source); | 17249 v8::String::NewFromUtf8(isolate, detailed_source); |
| 17148 // Make the script using a non-zero line and column offset. | 17250 // Make the script using a non-zero line and column offset. |
| 17149 v8::Handle<v8::Integer> line_offset = v8::Integer::New(isolate, 3); | 17251 v8::Handle<v8::Integer> line_offset = v8::Integer::New(isolate, 3); |
| 17150 v8::Handle<v8::Integer> column_offset = v8::Integer::New(isolate, 5); | 17252 v8::Handle<v8::Integer> column_offset = v8::Integer::New(isolate, 5); |
| 17151 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); | 17253 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); |
| 17152 v8::Handle<v8::Script> detailed_script( | 17254 v8::Handle<v8::UnboundScript> detailed_script( |
| 17153 v8::Script::New(detailed_src, &detailed_origin)); | 17255 v8::ScriptCompiler::CompileUnbound( |
| 17154 v8::Handle<Value> detailed_result(detailed_script->Run()); | 17256 isolate, v8::ScriptCompiler::Source(detailed_src, detailed_origin))); |
| 17257 v8::Handle<Value> detailed_result( |
| 17258 detailed_script->BindToCurrentContext()->Run()); |
| 17155 CHECK(!detailed_result.IsEmpty()); | 17259 CHECK(!detailed_result.IsEmpty()); |
| 17156 CHECK(detailed_result->IsObject()); | 17260 CHECK(detailed_result->IsObject()); |
| 17157 } | 17261 } |
| 17158 | 17262 |
| 17159 | 17263 |
| 17160 static void StackTraceForUncaughtExceptionListener( | 17264 static void StackTraceForUncaughtExceptionListener( |
| 17161 v8::Handle<v8::Message> message, | 17265 v8::Handle<v8::Message> message, |
| 17162 v8::Handle<Value>) { | 17266 v8::Handle<Value>) { |
| 17163 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); | 17267 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); |
| 17164 CHECK_EQ(2, stack_trace->GetFrameCount()); | 17268 CHECK_EQ(2, stack_trace->GetFrameCount()); |
| 17165 checkStackFrame("origin", "foo", 2, 3, false, false, | 17269 checkStackFrame("origin", "foo", 2, 3, false, false, |
| 17166 stack_trace->GetFrame(0)); | 17270 stack_trace->GetFrame(0)); |
| 17167 checkStackFrame("origin", "bar", 5, 3, false, false, | 17271 checkStackFrame("origin", "bar", 5, 3, false, false, |
| 17168 stack_trace->GetFrame(1)); | 17272 stack_trace->GetFrame(1)); |
| 17169 } | 17273 } |
| 17170 | 17274 |
| 17171 | 17275 |
| 17172 TEST(CaptureStackTraceForUncaughtException) { | 17276 TEST(CaptureStackTraceForUncaughtException) { |
| 17173 report_count = 0; | 17277 report_count = 0; |
| 17174 LocalContext env; | 17278 LocalContext env; |
| 17175 v8::HandleScope scope(env->GetIsolate()); | 17279 v8::HandleScope scope(env->GetIsolate()); |
| 17176 v8::V8::AddMessageListener(StackTraceForUncaughtExceptionListener); | 17280 v8::V8::AddMessageListener(StackTraceForUncaughtExceptionListener); |
| 17177 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); | 17281 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); |
| 17178 | 17282 |
| 17179 Script::Compile(v8_str("function foo() {\n" | 17283 CompileRunWithOrigin( |
| 17180 " throw 1;\n" | 17284 "function foo() {\n" |
| 17181 "};\n" | 17285 " throw 1;\n" |
| 17182 "function bar() {\n" | 17286 "};\n" |
| 17183 " foo();\n" | 17287 "function bar() {\n" |
| 17184 "};"), | 17288 " foo();\n" |
| 17185 v8_str("origin"))->Run(); | 17289 "};", |
| 17290 "origin"); |
| 17186 v8::Local<v8::Object> global = env->Global(); | 17291 v8::Local<v8::Object> global = env->Global(); |
| 17187 Local<Value> trouble = global->Get(v8_str("bar")); | 17292 Local<Value> trouble = global->Get(v8_str("bar")); |
| 17188 CHECK(trouble->IsFunction()); | 17293 CHECK(trouble->IsFunction()); |
| 17189 Function::Cast(*trouble)->Call(global, 0, NULL); | 17294 Function::Cast(*trouble)->Call(global, 0, NULL); |
| 17190 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); | 17295 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); |
| 17191 v8::V8::RemoveMessageListeners(StackTraceForUncaughtExceptionListener); | 17296 v8::V8::RemoveMessageListeners(StackTraceForUncaughtExceptionListener); |
| 17192 } | 17297 } |
| 17193 | 17298 |
| 17194 | 17299 |
| 17195 TEST(CaptureStackTraceForUncaughtExceptionAndSetters) { | 17300 TEST(CaptureStackTraceForUncaughtExceptionAndSetters) { |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17410 templ->Set(v8_str("AnalyzeScriptIdInStack"), | 17515 templ->Set(v8_str("AnalyzeScriptIdInStack"), |
| 17411 v8::FunctionTemplate::New(isolate, AnalyzeScriptIdInStack)); | 17516 v8::FunctionTemplate::New(isolate, AnalyzeScriptIdInStack)); |
| 17412 LocalContext context(0, templ); | 17517 LocalContext context(0, templ); |
| 17413 | 17518 |
| 17414 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8( | 17519 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8( |
| 17415 isolate, | 17520 isolate, |
| 17416 "function foo() {\n" | 17521 "function foo() {\n" |
| 17417 " AnalyzeScriptIdInStack();" | 17522 " AnalyzeScriptIdInStack();" |
| 17418 "}\n" | 17523 "}\n" |
| 17419 "foo();\n"); | 17524 "foo();\n"); |
| 17420 v8::ScriptOrigin origin = | 17525 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(); | 17526 script->Run(); |
| 17424 for (int i = 0; i < 2; i++) { | 17527 for (int i = 0; i < 2; i++) { |
| 17425 CHECK(scriptIdInStack[i] != v8::Message::kNoScriptIdInfo); | 17528 CHECK(scriptIdInStack[i] != v8::Message::kNoScriptIdInfo); |
| 17426 CHECK_EQ(scriptIdInStack[i], script->GetId()); | 17529 CHECK_EQ(scriptIdInStack[i], script->GetId()); |
| 17427 } | 17530 } |
| 17428 } | 17531 } |
| 17429 | 17532 |
| 17430 | 17533 |
| 17431 void AnalyzeStackOfInlineScriptWithSourceURL( | 17534 void AnalyzeStackOfInlineScriptWithSourceURL( |
| 17432 const v8::FunctionCallbackInfo<v8::Value>& args) { | 17535 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| (...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18437 " this.x = 23;" | 18540 " this.x = 23;" |
| 18438 "};" | 18541 "};" |
| 18439 "C1.prototype = P;" | 18542 "C1.prototype = P;" |
| 18440 "function C2() {" | 18543 "function C2() {" |
| 18441 " this.x = 23" | 18544 " this.x = 23" |
| 18442 "};" | 18545 "};" |
| 18443 "C2.prototype = { };" | 18546 "C2.prototype = { };" |
| 18444 "C2.prototype.__proto__ = P;"); | 18547 "C2.prototype.__proto__ = P;"); |
| 18445 | 18548 |
| 18446 v8::Local<v8::Script> script; | 18549 v8::Local<v8::Script> script; |
| 18447 script = v8::Script::Compile(v8_str("new C1();")); | 18550 script = v8_compile("new C1();"); |
| 18448 for (int i = 0; i < 10; i++) { | 18551 for (int i = 0; i < 10; i++) { |
| 18449 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); | 18552 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); |
| 18450 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value()); | 18553 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value()); |
| 18451 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value()); | 18554 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value()); |
| 18452 } | 18555 } |
| 18453 | 18556 |
| 18454 script = v8::Script::Compile(v8_str("new C2();")); | 18557 script = v8_compile("new C2();"); |
| 18455 for (int i = 0; i < 10; i++) { | 18558 for (int i = 0; i < 10; i++) { |
| 18456 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); | 18559 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); |
| 18457 CHECK_EQ(42, c2->Get(v8_str("x"))->Int32Value()); | 18560 CHECK_EQ(42, c2->Get(v8_str("x"))->Int32Value()); |
| 18458 CHECK_EQ(23, c2->Get(v8_str("y"))->Int32Value()); | 18561 CHECK_EQ(23, c2->Get(v8_str("y"))->Int32Value()); |
| 18459 } | 18562 } |
| 18460 } | 18563 } |
| 18461 | 18564 |
| 18462 | 18565 |
| 18463 static void NamedPropertyGetterWhichReturns42( | 18566 static void NamedPropertyGetterWhichReturns42( |
| 18464 Local<String> name, | 18567 Local<String> name, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 18489 " this.x = 23;" | 18592 " this.x = 23;" |
| 18490 "};" | 18593 "};" |
| 18491 "C1.prototype = P;" | 18594 "C1.prototype = P;" |
| 18492 "function C2() {" | 18595 "function C2() {" |
| 18493 " this.x = 23" | 18596 " this.x = 23" |
| 18494 "};" | 18597 "};" |
| 18495 "C2.prototype = { };" | 18598 "C2.prototype = { };" |
| 18496 "C2.prototype.__proto__ = P;"); | 18599 "C2.prototype.__proto__ = P;"); |
| 18497 | 18600 |
| 18498 v8::Local<v8::Script> script; | 18601 v8::Local<v8::Script> script; |
| 18499 script = v8::Script::Compile(v8_str("new C1();")); | 18602 script = v8_compile("new C1();"); |
| 18500 for (int i = 0; i < 10; i++) { | 18603 for (int i = 0; i < 10; i++) { |
| 18501 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); | 18604 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); |
| 18502 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value()); | 18605 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value()); |
| 18503 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); | 18606 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); |
| 18504 } | 18607 } |
| 18505 | 18608 |
| 18506 script = v8::Script::Compile(v8_str("new C2();")); | 18609 script = v8_compile("new C2();"); |
| 18507 for (int i = 0; i < 10; i++) { | 18610 for (int i = 0; i < 10; i++) { |
| 18508 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); | 18611 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); |
| 18509 CHECK_EQ(23, c2->Get(v8_str("x"))->Int32Value()); | 18612 CHECK_EQ(23, c2->Get(v8_str("x"))->Int32Value()); |
| 18510 CHECK_EQ(42, c2->Get(v8_str("y"))->Int32Value()); | 18613 CHECK_EQ(42, c2->Get(v8_str("y"))->Int32Value()); |
| 18511 } | 18614 } |
| 18512 } | 18615 } |
| 18513 | 18616 |
| 18514 | 18617 |
| 18515 TEST(Regress618) { | 18618 TEST(Regress618) { |
| 18516 const char* source = "function C1() {" | 18619 const char* source = "function C1() {" |
| 18517 " this.x = 23;" | 18620 " this.x = 23;" |
| 18518 "};" | 18621 "};" |
| 18519 "C1.prototype = P;"; | 18622 "C1.prototype = P;"; |
| 18520 | 18623 |
| 18521 LocalContext context; | 18624 LocalContext context; |
| 18522 v8::Isolate* isolate = context->GetIsolate(); | 18625 v8::Isolate* isolate = context->GetIsolate(); |
| 18523 v8::HandleScope scope(isolate); | 18626 v8::HandleScope scope(isolate); |
| 18524 v8::Local<v8::Script> script; | 18627 v8::Local<v8::Script> script; |
| 18525 | 18628 |
| 18526 // Use a simple object as prototype. | 18629 // Use a simple object as prototype. |
| 18527 v8::Local<v8::Object> prototype = v8::Object::New(isolate); | 18630 v8::Local<v8::Object> prototype = v8::Object::New(isolate); |
| 18528 prototype->Set(v8_str("y"), v8_num(42)); | 18631 prototype->Set(v8_str("y"), v8_num(42)); |
| 18529 context->Global()->Set(v8_str("P"), prototype); | 18632 context->Global()->Set(v8_str("P"), prototype); |
| 18530 | 18633 |
| 18531 // This compile will add the code to the compilation cache. | 18634 // This compile will add the code to the compilation cache. |
| 18532 CompileRun(source); | 18635 CompileRun(source); |
| 18533 | 18636 |
| 18534 script = v8::Script::Compile(v8_str("new C1();")); | 18637 script = v8_compile("new C1();"); |
| 18535 // Allow enough iterations for the inobject slack tracking logic | 18638 // Allow enough iterations for the inobject slack tracking logic |
| 18536 // to finalize instance size and install the fast construct stub. | 18639 // to finalize instance size and install the fast construct stub. |
| 18537 for (int i = 0; i < 256; i++) { | 18640 for (int i = 0; i < 256; i++) { |
| 18538 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); | 18641 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); |
| 18539 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value()); | 18642 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value()); |
| 18540 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); | 18643 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); |
| 18541 } | 18644 } |
| 18542 | 18645 |
| 18543 // Use an API object with accessors as prototype. | 18646 // Use an API object with accessors as prototype. |
| 18544 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 18647 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
| 18545 templ->SetAccessor(v8_str("x"), | 18648 templ->SetAccessor(v8_str("x"), |
| 18546 GetterWhichReturns42, | 18649 GetterWhichReturns42, |
| 18547 SetterWhichSetsYOnThisTo23); | 18650 SetterWhichSetsYOnThisTo23); |
| 18548 context->Global()->Set(v8_str("P"), templ->NewInstance()); | 18651 context->Global()->Set(v8_str("P"), templ->NewInstance()); |
| 18549 | 18652 |
| 18550 // This compile will get the code from the compilation cache. | 18653 // This compile will get the code from the compilation cache. |
| 18551 CompileRun(source); | 18654 CompileRun(source); |
| 18552 | 18655 |
| 18553 script = v8::Script::Compile(v8_str("new C1();")); | 18656 script = v8_compile("new C1();"); |
| 18554 for (int i = 0; i < 10; i++) { | 18657 for (int i = 0; i < 10; i++) { |
| 18555 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); | 18658 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); |
| 18556 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value()); | 18659 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value()); |
| 18557 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value()); | 18660 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value()); |
| 18558 } | 18661 } |
| 18559 } | 18662 } |
| 18560 | 18663 |
| 18561 v8::Isolate* gc_callbacks_isolate = NULL; | 18664 v8::Isolate* gc_callbacks_isolate = NULL; |
| 18562 int prologue_call_count = 0; | 18665 int prologue_call_count = 0; |
| 18563 int epilogue_call_count = 0; | 18666 int epilogue_call_count = 0; |
| (...skipping 3545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 22109 Local<Object> ApiCallOptimizationChecker::holder; | 22212 Local<Object> ApiCallOptimizationChecker::holder; |
| 22110 Local<Object> ApiCallOptimizationChecker::callee; | 22213 Local<Object> ApiCallOptimizationChecker::callee; |
| 22111 int ApiCallOptimizationChecker::count = 0; | 22214 int ApiCallOptimizationChecker::count = 0; |
| 22112 | 22215 |
| 22113 | 22216 |
| 22114 TEST(TestFunctionCallOptimization) { | 22217 TEST(TestFunctionCallOptimization) { |
| 22115 i::FLAG_allow_natives_syntax = true; | 22218 i::FLAG_allow_natives_syntax = true; |
| 22116 ApiCallOptimizationChecker checker; | 22219 ApiCallOptimizationChecker checker; |
| 22117 checker.RunAll(); | 22220 checker.RunAll(); |
| 22118 } | 22221 } |
| 22222 |
| 22223 |
| 22224 static const char* last_event_message; |
| 22225 static int last_event_status; |
| 22226 void StoringEventLoggerCallback(const char* message, int status) { |
| 22227 last_event_message = message; |
| 22228 last_event_status = status; |
| 22229 } |
| 22230 |
| 22231 |
| 22232 TEST(EventLogging) { |
| 22233 v8::Isolate* isolate = CcTest::isolate(); |
| 22234 isolate->SetEventLogger(StoringEventLoggerCallback); |
| 22235 v8::internal::HistogramTimer* histogramTimer = |
| 22236 new v8::internal::HistogramTimer( |
| 22237 "V8.Test", 0, 10000, 50, |
| 22238 reinterpret_cast<v8::internal::Isolate*>(isolate)); |
| 22239 histogramTimer->Start(); |
| 22240 CHECK_EQ("V8.Test", last_event_message); |
| 22241 CHECK_EQ(0, last_event_status); |
| 22242 histogramTimer->Stop(); |
| 22243 CHECK_EQ("V8.Test", last_event_message); |
| 22244 CHECK_EQ(1, last_event_status); |
| 22245 } |
| 22246 |
| 22247 |
| 22248 TEST(Promises) { |
| 22249 i::FLAG_harmony_promises = true; |
| 22250 |
| 22251 LocalContext context; |
| 22252 v8::Isolate* isolate = context->GetIsolate(); |
| 22253 v8::HandleScope scope(isolate); |
| 22254 Handle<Object> global = context->Global(); |
| 22255 |
| 22256 // Creation. |
| 22257 Handle<v8::Promise> p = v8::Promise::New(isolate); |
| 22258 Handle<v8::Promise> r = v8::Promise::New(isolate); |
| 22259 |
| 22260 // IsPromise predicate. |
| 22261 CHECK(p->IsPromise()); |
| 22262 CHECK(r->IsPromise()); |
| 22263 Handle<Value> o = v8::Object::New(isolate); |
| 22264 CHECK(!o->IsPromise()); |
| 22265 |
| 22266 // Resolution and rejection. |
| 22267 p->Resolve(v8::Integer::New(isolate, 1)); |
| 22268 CHECK(p->IsPromise()); |
| 22269 r->Reject(v8::Integer::New(isolate, 2)); |
| 22270 CHECK(r->IsPromise()); |
| 22271 |
| 22272 // Chaining non-pending promises. |
| 22273 CompileRun( |
| 22274 "var x1 = 0;\n" |
| 22275 "var x2 = 0;\n" |
| 22276 "function f1(x) { x1 = x; return x+1 };\n" |
| 22277 "function f2(x) { x2 = x; return x+1 };\n"); |
| 22278 Handle<Function> f1 = Handle<Function>::Cast(global->Get(v8_str("f1"))); |
| 22279 Handle<Function> f2 = Handle<Function>::Cast(global->Get(v8_str("f2"))); |
| 22280 |
| 22281 p->Chain(f1); |
| 22282 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); |
| 22283 V8::RunMicrotasks(isolate); |
| 22284 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value()); |
| 22285 |
| 22286 p->Catch(f2); |
| 22287 V8::RunMicrotasks(isolate); |
| 22288 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); |
| 22289 |
| 22290 r->Catch(f2); |
| 22291 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); |
| 22292 V8::RunMicrotasks(isolate); |
| 22293 CHECK_EQ(2, global->Get(v8_str("x2"))->Int32Value()); |
| 22294 |
| 22295 r->Chain(f1); |
| 22296 V8::RunMicrotasks(isolate); |
| 22297 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value()); |
| 22298 |
| 22299 // Chaining pending promises. |
| 22300 CompileRun("x1 = x2 = 0;"); |
| 22301 p = v8::Promise::New(isolate); |
| 22302 r = v8::Promise::New(isolate); |
| 22303 |
| 22304 p->Chain(f1); |
| 22305 r->Catch(f2); |
| 22306 V8::RunMicrotasks(isolate); |
| 22307 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); |
| 22308 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); |
| 22309 |
| 22310 p->Resolve(v8::Integer::New(isolate, 1)); |
| 22311 r->Reject(v8::Integer::New(isolate, 2)); |
| 22312 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); |
| 22313 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); |
| 22314 |
| 22315 V8::RunMicrotasks(isolate); |
| 22316 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value()); |
| 22317 CHECK_EQ(2, global->Get(v8_str("x2"))->Int32Value()); |
| 22318 |
| 22319 // Multi-chaining. |
| 22320 CompileRun("x1 = x2 = 0;"); |
| 22321 p = v8::Promise::New(isolate); |
| 22322 p->Chain(f1)->Chain(f2); |
| 22323 p->Resolve(v8::Integer::New(isolate, 3)); |
| 22324 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); |
| 22325 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); |
| 22326 V8::RunMicrotasks(isolate); |
| 22327 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value()); |
| 22328 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value()); |
| 22329 |
| 22330 CompileRun("x1 = x2 = 0;"); |
| 22331 r = v8::Promise::New(isolate); |
| 22332 r->Catch(f1)->Chain(f2); |
| 22333 r->Reject(v8::Integer::New(isolate, 3)); |
| 22334 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); |
| 22335 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); |
| 22336 V8::RunMicrotasks(isolate); |
| 22337 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value()); |
| 22338 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value()); |
| 22339 } |
| OLD | NEW |