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 |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // TODO(jochen/vogelheim): Remove this. | |
29 #undef V8_IMMINENT_DEPRECATION_WARNINGS | |
30 | |
31 #include <climits> | 28 #include <climits> |
32 #include <csignal> | 29 #include <csignal> |
33 #include <map> | 30 #include <map> |
34 #include <string> | 31 #include <string> |
35 | 32 |
36 #include "test/cctest/test-api.h" | 33 #include "test/cctest/test-api.h" |
37 | 34 |
38 #if V8_OS_POSIX | 35 #if V8_OS_POSIX |
39 #include <unistd.h> // NOLINT | 36 #include <unistd.h> // NOLINT |
40 #endif | 37 #endif |
(...skipping 3773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3814 HandleScope scope(isolate); | 3811 HandleScope scope(isolate); |
3815 Local<v8::Object> obj = map.Get(7); | 3812 Local<v8::Object> obj = map.Get(7); |
3816 CHECK(obj.IsEmpty()); | 3813 CHECK(obj.IsEmpty()); |
3817 Local<v8::Object> expected = v8::Object::New(isolate); | 3814 Local<v8::Object> expected = v8::Object::New(isolate); |
3818 map.Set(7, expected); | 3815 map.Set(7, expected); |
3819 CHECK_EQ(1, static_cast<int>(map.Size())); | 3816 CHECK_EQ(1, static_cast<int>(map.Size())); |
3820 obj = map.Get(7); | 3817 obj = map.Get(7); |
3821 CHECK(expected->Equals(env.local(), obj).FromJust()); | 3818 CHECK(expected->Equals(env.local(), obj).FromJust()); |
3822 { | 3819 { |
3823 typename Map::PersistentValueReference ref = map.GetReference(7); | 3820 typename Map::PersistentValueReference ref = map.GetReference(7); |
3824 CHECK(expected->Equals(ref.NewLocal(isolate))); | 3821 CHECK(expected->Equals(env.local(), ref.NewLocal(isolate)).FromJust()); |
3825 } | 3822 } |
3826 v8::Global<v8::Object> removed = map.Remove(7); | 3823 v8::Global<v8::Object> removed = map.Remove(7); |
3827 CHECK_EQ(0, static_cast<int>(map.Size())); | 3824 CHECK_EQ(0, static_cast<int>(map.Size())); |
3828 CHECK(expected == removed); | 3825 CHECK(expected == removed); |
3829 removed = map.Remove(7); | 3826 removed = map.Remove(7); |
3830 CHECK(removed.IsEmpty()); | 3827 CHECK(removed.IsEmpty()); |
3831 map.Set(8, expected); | 3828 map.Set(8, expected); |
3832 CHECK_EQ(1, static_cast<int>(map.Size())); | 3829 CHECK_EQ(1, static_cast<int>(map.Size())); |
3833 map.Set(8, expected); | 3830 map.Set(8, expected); |
3834 CHECK_EQ(1, static_cast<int>(map.Size())); | 3831 CHECK_EQ(1, static_cast<int>(map.Size())); |
3835 { | 3832 { |
3836 typename Map::PersistentValueReference ref; | 3833 typename Map::PersistentValueReference ref; |
3837 Local<v8::Object> expected2 = NewObjectForIntKey(isolate, templ, 8); | 3834 Local<v8::Object> expected2 = NewObjectForIntKey(isolate, templ, 8); |
3838 removed = map.Set(8, v8::Global<v8::Object>(isolate, expected2), &ref); | 3835 removed = map.Set(8, v8::Global<v8::Object>(isolate, expected2), &ref); |
3839 CHECK_EQ(1, static_cast<int>(map.Size())); | 3836 CHECK_EQ(1, static_cast<int>(map.Size())); |
3840 CHECK(expected == removed); | 3837 CHECK(expected == removed); |
3841 CHECK(expected2->Equals(ref.NewLocal(isolate))); | 3838 CHECK(expected2->Equals(env.local(), ref.NewLocal(isolate)).FromJust()); |
3842 } | 3839 } |
3843 } | 3840 } |
3844 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count()); | 3841 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count()); |
3845 if (map.IsWeak()) { | 3842 if (map.IsWeak()) { |
3846 CcTest::i_isolate()->heap()->CollectAllGarbage( | 3843 CcTest::i_isolate()->heap()->CollectAllGarbage( |
3847 i::Heap::kAbortIncrementalMarkingMask); | 3844 i::Heap::kAbortIncrementalMarkingMask); |
3848 } else { | 3845 } else { |
3849 map.Clear(); | 3846 map.Clear(); |
3850 } | 3847 } |
3851 CHECK_EQ(0, static_cast<int>(map.Size())); | 3848 CHECK_EQ(0, static_cast<int>(map.Size())); |
(...skipping 11113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14965 CompileRun("function f() { x = 42; return x; }; f()"); | 14962 CompileRun("function f() { x = 42; return x; }; f()"); |
14966 CHECK(v8::Integer::New(isolate, 0)->Equals(context.local(), res).FromJust()); | 14963 CHECK(v8::Integer::New(isolate, 0)->Equals(context.local(), res).FromJust()); |
14967 // Check with 'eval'. | 14964 // Check with 'eval'. |
14968 res = CompileRun("function f() { eval('1'); y = 43; return y; }; f()"); | 14965 res = CompileRun("function f() { eval('1'); y = 43; return y; }; f()"); |
14969 CHECK(v8::Integer::New(isolate, 0)->Equals(context.local(), res).FromJust()); | 14966 CHECK(v8::Integer::New(isolate, 0)->Equals(context.local(), res).FromJust()); |
14970 // Check with 'with'. | 14967 // Check with 'with'. |
14971 res = CompileRun("function f() { with (this) { y = 44 }; return y; }; f()"); | 14968 res = CompileRun("function f() { with (this) { y = 44 }; return y; }; f()"); |
14972 CHECK(v8::Integer::New(isolate, 0)->Equals(context.local(), res).FromJust()); | 14969 CHECK(v8::Integer::New(isolate, 0)->Equals(context.local(), res).FromJust()); |
14973 } | 14970 } |
14974 | 14971 |
14975 static int force_set_set_count = 0; | |
14976 static int force_set_get_count = 0; | |
14977 bool pass_on_get = false; | |
14978 | |
14979 static void ForceSetGetter(v8::Local<v8::String> name, | |
14980 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
14981 force_set_get_count++; | |
14982 if (pass_on_get) { | |
14983 return; | |
14984 } | |
14985 info.GetReturnValue().Set(3); | |
14986 } | |
14987 | |
14988 static void ForceSetSetter(v8::Local<v8::String> name, | |
14989 v8::Local<v8::Value> value, | |
14990 const v8::PropertyCallbackInfo<void>& info) { | |
14991 force_set_set_count++; | |
14992 } | |
14993 | |
14994 static void ForceSetInterceptGetter( | |
14995 v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { | |
14996 CHECK(name->IsString()); | |
14997 ForceSetGetter(Local<String>::Cast(name), info); | |
14998 } | |
14999 | |
15000 static void ForceSetInterceptSetter( | |
15001 v8::Local<v8::Name> name, v8::Local<v8::Value> value, | |
15002 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
15003 force_set_set_count++; | |
15004 info.GetReturnValue().SetUndefined(); | |
15005 } | |
15006 | |
15007 | |
15008 TEST(ForceSet) { | |
vogelheim
2015/12/11 15:19:03
Well, this is a rather pragmatic solution. :)
jochen (gone - plz use gerrit)
2015/12/11 15:27:41
:)
The test is testing that ForceSet breaks the o
| |
15009 force_set_get_count = 0; | |
15010 force_set_set_count = 0; | |
15011 pass_on_get = false; | |
15012 | |
15013 v8::Isolate* isolate = CcTest::isolate(); | |
15014 v8::HandleScope scope(isolate); | |
15015 v8::Local<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); | |
15016 v8::Local<v8::String> access_property = v8_str("a"); | |
15017 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter); | |
15018 LocalContext context(NULL, templ); | |
15019 v8::Local<v8::Object> global = context->Global(); | |
15020 | |
15021 // Ordinary properties | |
15022 v8::Local<v8::String> simple_property = v8_str("p"); | |
15023 global->DefineOwnProperty(context.local(), simple_property, | |
15024 v8::Int32::New(isolate, 4), v8::ReadOnly) | |
15025 .FromJust(); | |
15026 CHECK_EQ(4, global->Get(context.local(), simple_property) | |
15027 .ToLocalChecked() | |
15028 ->Int32Value(context.local()) | |
15029 .FromJust()); | |
15030 // This should fail because the property is read-only | |
15031 CHECK( | |
15032 global->Set(context.local(), simple_property, v8::Int32::New(isolate, 5)) | |
15033 .FromJust()); | |
15034 CHECK_EQ(4, global->Get(context.local(), simple_property) | |
15035 .ToLocalChecked() | |
15036 ->Int32Value(context.local()) | |
15037 .FromJust()); | |
15038 // This should succeed even though the property is read-only | |
15039 CHECK(global->DefineOwnProperty(context.local(), simple_property, | |
15040 v8::Int32::New(isolate, 6)) | |
15041 .FromJust()); | |
15042 CHECK_EQ(6, global->Get(context.local(), simple_property) | |
15043 .ToLocalChecked() | |
15044 ->Int32Value(context.local()) | |
15045 .FromJust()); | |
15046 | |
15047 // Accessors | |
15048 CHECK_EQ(0, force_set_set_count); | |
15049 CHECK_EQ(0, force_set_get_count); | |
15050 CHECK_EQ(3, global->Get(context.local(), access_property) | |
15051 .ToLocalChecked() | |
15052 ->Int32Value(context.local()) | |
15053 .FromJust()); | |
15054 // CHECK_EQ the property shouldn't override it, just call the setter | |
15055 // which in this case does nothing. | |
15056 CHECK( | |
15057 global->Set(context.local(), access_property, v8::Int32::New(isolate, 7)) | |
15058 .FromJust()); | |
15059 CHECK_EQ(3, global->Get(context.local(), access_property) | |
15060 .ToLocalChecked() | |
15061 ->Int32Value(context.local()) | |
15062 .FromJust()); | |
15063 CHECK_EQ(1, force_set_set_count); | |
15064 CHECK_EQ(2, force_set_get_count); | |
15065 // ForceSet doesn't call the accessors for now. | |
15066 // TODO(verwaest): Update once blink doesn't rely on ForceSet to delete api | |
15067 // accessors. | |
15068 CHECK(global->ForceSet(access_property, v8::Int32::New(isolate, 8))); | |
15069 CHECK_EQ(8, global->Get(context.local(), access_property) | |
15070 .ToLocalChecked() | |
15071 ->Int32Value(context.local()) | |
15072 .FromJust()); | |
15073 CHECK_EQ(1, force_set_set_count); | |
15074 CHECK_EQ(2, force_set_get_count); | |
15075 } | |
15076 | |
15077 | |
15078 TEST(ForceSetWithInterceptor) { | |
15079 v8::Isolate* isolate = CcTest::isolate(); | |
15080 v8::HandleScope scope(isolate); | |
15081 v8::Local<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); | |
15082 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( | |
15083 ForceSetInterceptGetter, ForceSetInterceptSetter)); | |
15084 pass_on_get = true; | |
15085 LocalContext context(NULL, templ); | |
15086 v8::Local<v8::Object> global = context->Global(); | |
15087 | |
15088 force_set_get_count = 0; | |
15089 force_set_set_count = 0; | |
15090 pass_on_get = false; | |
15091 | |
15092 v8::Local<v8::String> some_property = v8_str("a"); | |
15093 CHECK_EQ(0, force_set_set_count); | |
15094 CHECK_EQ(0, force_set_get_count); | |
15095 CHECK_EQ(3, global->Get(context.local(), some_property) | |
15096 .ToLocalChecked() | |
15097 ->Int32Value(context.local()) | |
15098 .FromJust()); | |
15099 // Setting the property shouldn't override it, just call the setter | |
15100 // which in this case does nothing. | |
15101 global->Set(context.local(), some_property, v8::Int32::New(isolate, 7)) | |
15102 .FromJust(); | |
15103 CHECK_EQ(3, global->Get(context.local(), some_property) | |
15104 .ToLocalChecked() | |
15105 ->Int32Value(context.local()) | |
15106 .FromJust()); | |
15107 CHECK_EQ(1, force_set_set_count); | |
15108 CHECK_EQ(2, force_set_get_count); | |
15109 // Getting the property when the interceptor returns an empty handle | |
15110 // should yield undefined, since the property isn't present on the | |
15111 // object itself yet. | |
15112 pass_on_get = true; | |
15113 CHECK(global->Get(context.local(), some_property) | |
15114 .ToLocalChecked() | |
15115 ->IsUndefined()); | |
15116 CHECK_EQ(1, force_set_set_count); | |
15117 CHECK_EQ(3, force_set_get_count); | |
15118 // Forcing the property to be set should cause the value to be | |
15119 // set locally without calling the interceptor. | |
15120 global->ForceSet(some_property, v8::Int32::New(isolate, 8)); | |
15121 CHECK_EQ(8, global->Get(context.local(), some_property) | |
15122 .ToLocalChecked() | |
15123 ->Int32Value(context.local()) | |
15124 .FromJust()); | |
15125 CHECK_EQ(1, force_set_set_count); | |
15126 CHECK_EQ(4, force_set_get_count); | |
15127 // Reenabling the interceptor should cause it to take precedence over | |
15128 // the property | |
15129 pass_on_get = false; | |
15130 CHECK_EQ(3, global->Get(context.local(), some_property) | |
15131 .ToLocalChecked() | |
15132 ->Int32Value(context.local()) | |
15133 .FromJust()); | |
15134 CHECK_EQ(1, force_set_set_count); | |
15135 CHECK_EQ(5, force_set_get_count); | |
15136 // The interceptor should also work for other properties | |
15137 CHECK_EQ(3, global->Get(context.local(), v8_str("b")) | |
15138 .ToLocalChecked() | |
15139 ->Int32Value(context.local()) | |
15140 .FromJust()); | |
15141 CHECK_EQ(1, force_set_set_count); | |
15142 CHECK_EQ(6, force_set_get_count); | |
15143 } | |
15144 | |
15145 | 14972 |
15146 TEST(CreateDataProperty) { | 14973 TEST(CreateDataProperty) { |
15147 LocalContext env; | 14974 LocalContext env; |
15148 v8::Isolate* isolate = env->GetIsolate(); | 14975 v8::Isolate* isolate = env->GetIsolate(); |
15149 v8::HandleScope handle_scope(isolate); | 14976 v8::HandleScope handle_scope(isolate); |
15150 | 14977 |
15151 CompileRun( | 14978 CompileRun( |
15152 "var a = {};" | 14979 "var a = {};" |
15153 "var b = [];" | 14980 "var b = [];" |
15154 "Object.defineProperty(a, 'foo', {value: 23});" | 14981 "Object.defineProperty(a, 'foo', {value: 23});" |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
15841 | 15668 |
15842 Local<ArrayBufferType> ab = | 15669 Local<ArrayBufferType> ab = |
15843 ArrayBufferType::New(isolate, backing_store.start(), | 15670 ArrayBufferType::New(isolate, backing_store.start(), |
15844 (kElementCount + 2) * sizeof(ElementType)); | 15671 (kElementCount + 2) * sizeof(ElementType)); |
15845 Local<TypedArray> ta = | 15672 Local<TypedArray> ta = |
15846 TypedArray::New(ab, 2*sizeof(ElementType), kElementCount); | 15673 TypedArray::New(ab, 2*sizeof(ElementType), kElementCount); |
15847 CheckInternalFieldsAreZero<v8::ArrayBufferView>(ta); | 15674 CheckInternalFieldsAreZero<v8::ArrayBufferView>(ta); |
15848 CHECK_EQ(kElementCount, static_cast<int>(ta->Length())); | 15675 CHECK_EQ(kElementCount, static_cast<int>(ta->Length())); |
15849 CHECK_EQ(2 * sizeof(ElementType), ta->ByteOffset()); | 15676 CHECK_EQ(2 * sizeof(ElementType), ta->ByteOffset()); |
15850 CHECK_EQ(kElementCount * sizeof(ElementType), ta->ByteLength()); | 15677 CHECK_EQ(kElementCount * sizeof(ElementType), ta->ByteLength()); |
15851 CHECK(ab->Equals(ta->Buffer())); | 15678 CHECK(ab->Equals(env.local(), ta->Buffer()).FromJust()); |
15852 | 15679 |
15853 ElementType* data = backing_store.start() + 2; | 15680 ElementType* data = backing_store.start() + 2; |
15854 for (int i = 0; i < kElementCount; i++) { | 15681 for (int i = 0; i < kElementCount; i++) { |
15855 data[i] = static_cast<ElementType>(i); | 15682 data[i] = static_cast<ElementType>(i); |
15856 } | 15683 } |
15857 | 15684 |
15858 ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>( | 15685 ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>( |
15859 env.local(), ta, kElementCount, array_type, low, high); | 15686 env.local(), ta, kElementCount, array_type, low, high); |
15860 } | 15687 } |
15861 | 15688 |
(...skipping 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17048 const v8::FunctionCallbackInfo<v8::Value>& args) { | 16875 const v8::FunctionCallbackInfo<v8::Value>& args) { |
17049 v8::HandleScope scope(args.GetIsolate()); | 16876 v8::HandleScope scope(args.GetIsolate()); |
17050 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( | 16877 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( |
17051 args.GetIsolate(), 10, v8::StackTrace::kDetailed); | 16878 args.GetIsolate(), 10, v8::StackTrace::kDetailed); |
17052 CHECK_EQ(5, stackTrace->GetFrameCount()); | 16879 CHECK_EQ(5, stackTrace->GetFrameCount()); |
17053 v8::Local<v8::String> url = v8_str("eval_url"); | 16880 v8::Local<v8::String> url = v8_str("eval_url"); |
17054 for (int i = 0; i < 3; i++) { | 16881 for (int i = 0; i < 3; i++) { |
17055 v8::Local<v8::String> name = | 16882 v8::Local<v8::String> name = |
17056 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); | 16883 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); |
17057 CHECK(!name.IsEmpty()); | 16884 CHECK(!name.IsEmpty()); |
17058 CHECK(url->Equals(name)); | 16885 CHECK(url->Equals(args.GetIsolate()->GetCurrentContext(), name).FromJust()); |
17059 } | 16886 } |
17060 } | 16887 } |
17061 | 16888 |
17062 | 16889 |
17063 TEST(SourceURLInStackTrace) { | 16890 TEST(SourceURLInStackTrace) { |
17064 v8::Isolate* isolate = CcTest::isolate(); | 16891 v8::Isolate* isolate = CcTest::isolate(); |
17065 v8::HandleScope scope(isolate); | 16892 v8::HandleScope scope(isolate); |
17066 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 16893 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
17067 templ->Set(v8_str("AnalyzeStackOfEvalWithSourceURL"), | 16894 templ->Set(v8_str("AnalyzeStackOfEvalWithSourceURL"), |
17068 v8::FunctionTemplate::New(isolate, | 16895 v8::FunctionTemplate::New(isolate, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17109 templ->Set(v8_str("AnalyzeScriptIdInStack"), | 16936 templ->Set(v8_str("AnalyzeScriptIdInStack"), |
17110 v8::FunctionTemplate::New(isolate, AnalyzeScriptIdInStack)); | 16937 v8::FunctionTemplate::New(isolate, AnalyzeScriptIdInStack)); |
17111 LocalContext context(0, templ); | 16938 LocalContext context(0, templ); |
17112 | 16939 |
17113 v8::Local<v8::String> scriptSource = v8_str( | 16940 v8::Local<v8::String> scriptSource = v8_str( |
17114 "function foo() {\n" | 16941 "function foo() {\n" |
17115 " AnalyzeScriptIdInStack();" | 16942 " AnalyzeScriptIdInStack();" |
17116 "}\n" | 16943 "}\n" |
17117 "foo();\n"); | 16944 "foo();\n"); |
17118 v8::Local<v8::Script> script = CompileWithOrigin(scriptSource, "test"); | 16945 v8::Local<v8::Script> script = CompileWithOrigin(scriptSource, "test"); |
17119 script->Run(); | 16946 script->Run(context.local()).ToLocalChecked(); |
17120 for (int i = 0; i < 2; i++) { | 16947 for (int i = 0; i < 2; i++) { |
17121 CHECK(scriptIdInStack[i] != v8::Message::kNoScriptIdInfo); | 16948 CHECK(scriptIdInStack[i] != v8::Message::kNoScriptIdInfo); |
17122 CHECK_EQ(scriptIdInStack[i], script->GetUnboundScript()->GetId()); | 16949 CHECK_EQ(scriptIdInStack[i], script->GetUnboundScript()->GetId()); |
17123 } | 16950 } |
17124 } | 16951 } |
17125 | 16952 |
17126 | 16953 |
17127 void AnalyzeStackOfInlineScriptWithSourceURL( | 16954 void AnalyzeStackOfInlineScriptWithSourceURL( |
17128 const v8::FunctionCallbackInfo<v8::Value>& args) { | 16955 const v8::FunctionCallbackInfo<v8::Value>& args) { |
17129 v8::HandleScope scope(args.GetIsolate()); | 16956 v8::HandleScope scope(args.GetIsolate()); |
17130 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( | 16957 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( |
17131 args.GetIsolate(), 10, v8::StackTrace::kDetailed); | 16958 args.GetIsolate(), 10, v8::StackTrace::kDetailed); |
17132 CHECK_EQ(4, stackTrace->GetFrameCount()); | 16959 CHECK_EQ(4, stackTrace->GetFrameCount()); |
17133 v8::Local<v8::String> url = v8_str("source_url"); | 16960 v8::Local<v8::String> url = v8_str("source_url"); |
17134 for (int i = 0; i < 3; i++) { | 16961 for (int i = 0; i < 3; i++) { |
17135 v8::Local<v8::String> name = | 16962 v8::Local<v8::String> name = |
17136 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); | 16963 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); |
17137 CHECK(!name.IsEmpty()); | 16964 CHECK(!name.IsEmpty()); |
17138 CHECK(url->Equals(name)); | 16965 CHECK(url->Equals(args.GetIsolate()->GetCurrentContext(), name).FromJust()); |
17139 } | 16966 } |
17140 } | 16967 } |
17141 | 16968 |
17142 | 16969 |
17143 TEST(InlineScriptWithSourceURLInStackTrace) { | 16970 TEST(InlineScriptWithSourceURLInStackTrace) { |
17144 v8::Isolate* isolate = CcTest::isolate(); | 16971 v8::Isolate* isolate = CcTest::isolate(); |
17145 v8::HandleScope scope(isolate); | 16972 v8::HandleScope scope(isolate); |
17146 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 16973 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
17147 templ->Set(v8_str("AnalyzeStackOfInlineScriptWithSourceURL"), | 16974 templ->Set(v8_str("AnalyzeStackOfInlineScriptWithSourceURL"), |
17148 v8::FunctionTemplate::New( | 16975 v8::FunctionTemplate::New( |
(...skipping 23 matching lines...) Expand all Loading... | |
17172 const v8::FunctionCallbackInfo<v8::Value>& args) { | 16999 const v8::FunctionCallbackInfo<v8::Value>& args) { |
17173 v8::HandleScope scope(args.GetIsolate()); | 17000 v8::HandleScope scope(args.GetIsolate()); |
17174 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( | 17001 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( |
17175 args.GetIsolate(), 10, v8::StackTrace::kDetailed); | 17002 args.GetIsolate(), 10, v8::StackTrace::kDetailed); |
17176 CHECK_EQ(4, stackTrace->GetFrameCount()); | 17003 CHECK_EQ(4, stackTrace->GetFrameCount()); |
17177 v8::Local<v8::String> url = v8_str("source_url"); | 17004 v8::Local<v8::String> url = v8_str("source_url"); |
17178 for (int i = 0; i < 3; i++) { | 17005 for (int i = 0; i < 3; i++) { |
17179 v8::Local<v8::String> name = | 17006 v8::Local<v8::String> name = |
17180 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); | 17007 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); |
17181 CHECK(!name.IsEmpty()); | 17008 CHECK(!name.IsEmpty()); |
17182 CHECK(url->Equals(name)); | 17009 CHECK(url->Equals(args.GetIsolate()->GetCurrentContext(), name).FromJust()); |
17183 } | 17010 } |
17184 } | 17011 } |
17185 | 17012 |
17186 | 17013 |
17187 TEST(DynamicWithSourceURLInStackTrace) { | 17014 TEST(DynamicWithSourceURLInStackTrace) { |
17188 v8::Isolate* isolate = CcTest::isolate(); | 17015 v8::Isolate* isolate = CcTest::isolate(); |
17189 v8::HandleScope scope(isolate); | 17016 v8::HandleScope scope(isolate); |
17190 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 17017 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
17191 templ->Set(v8_str("AnalyzeStackOfDynamicScriptWithSourceURL"), | 17018 templ->Set(v8_str("AnalyzeStackOfDynamicScriptWithSourceURL"), |
17192 v8::FunctionTemplate::New( | 17019 v8::FunctionTemplate::New( |
(...skipping 30 matching lines...) Expand all Loading... | |
17223 " }\n" | 17050 " }\n" |
17224 " foo();\n" | 17051 " foo();\n" |
17225 "}\n" | 17052 "}\n" |
17226 "outer()\n%s"; | 17053 "outer()\n%s"; |
17227 | 17054 |
17228 i::ScopedVector<char> code(1024); | 17055 i::ScopedVector<char> code(1024); |
17229 i::SNPrintF(code, source, "//# sourceURL=source_url"); | 17056 i::SNPrintF(code, source, "//# sourceURL=source_url"); |
17230 v8::TryCatch try_catch(context->GetIsolate()); | 17057 v8::TryCatch try_catch(context->GetIsolate()); |
17231 CompileRunWithOrigin(code.start(), "", 0, 0); | 17058 CompileRunWithOrigin(code.start(), "", 0, 0); |
17232 CHECK(try_catch.HasCaught()); | 17059 CHECK(try_catch.HasCaught()); |
17233 v8::String::Utf8Value stack(try_catch.StackTrace()); | 17060 v8::String::Utf8Value stack( |
17061 try_catch.StackTrace(context.local()).ToLocalChecked()); | |
17234 CHECK(strstr(*stack, "at foo (source_url:3:5)") != NULL); | 17062 CHECK(strstr(*stack, "at foo (source_url:3:5)") != NULL); |
17235 } | 17063 } |
17236 | 17064 |
17237 | 17065 |
17238 TEST(EvalWithSourceURLInMessageScriptResourceNameOrSourceURL) { | 17066 TEST(EvalWithSourceURLInMessageScriptResourceNameOrSourceURL) { |
17239 LocalContext context; | 17067 LocalContext context; |
17240 v8::HandleScope scope(context->GetIsolate()); | 17068 v8::HandleScope scope(context->GetIsolate()); |
17241 | 17069 |
17242 const char *source = | 17070 const char *source = |
17243 "function outer() {\n" | 17071 "function outer() {\n" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17451 v8::String::ExternalStringResource* resource_[4]; | 17279 v8::String::ExternalStringResource* resource_[4]; |
17452 bool found_resource_[4]; | 17280 bool found_resource_[4]; |
17453 }; | 17281 }; |
17454 | 17282 |
17455 | 17283 |
17456 TEST(ExternalizeOldSpaceTwoByteCons) { | 17284 TEST(ExternalizeOldSpaceTwoByteCons) { |
17457 v8::Isolate* isolate = CcTest::isolate(); | 17285 v8::Isolate* isolate = CcTest::isolate(); |
17458 LocalContext env; | 17286 LocalContext env; |
17459 v8::HandleScope scope(isolate); | 17287 v8::HandleScope scope(isolate); |
17460 v8::Local<v8::String> cons = | 17288 v8::Local<v8::String> cons = |
17461 CompileRun("'Romeo Montague ' + 'Juliet Capulet'")->ToString(isolate); | 17289 CompileRun("'Romeo Montague ' + 'Juliet Capulet'") |
17290 ->ToString(env.local()) | |
17291 .ToLocalChecked(); | |
17462 CHECK(v8::Utils::OpenHandle(*cons)->IsConsString()); | 17292 CHECK(v8::Utils::OpenHandle(*cons)->IsConsString()); |
17463 CcTest::heap()->CollectAllAvailableGarbage(); | 17293 CcTest::heap()->CollectAllAvailableGarbage(); |
17464 CHECK(CcTest::heap()->old_space()->Contains(*v8::Utils::OpenHandle(*cons))); | 17294 CHECK(CcTest::heap()->old_space()->Contains(*v8::Utils::OpenHandle(*cons))); |
17465 | 17295 |
17466 TestResource* resource = new TestResource( | 17296 TestResource* resource = new TestResource( |
17467 AsciiToTwoByteString("Romeo Montague Juliet Capulet")); | 17297 AsciiToTwoByteString("Romeo Montague Juliet Capulet")); |
17468 cons->MakeExternal(resource); | 17298 cons->MakeExternal(resource); |
17469 | 17299 |
17470 CHECK(cons->IsExternal()); | 17300 CHECK(cons->IsExternal()); |
17471 CHECK_EQ(resource, cons->GetExternalStringResource()); | 17301 CHECK_EQ(resource, cons->GetExternalStringResource()); |
17472 String::Encoding encoding; | 17302 String::Encoding encoding; |
17473 CHECK_EQ(resource, cons->GetExternalStringResourceBase(&encoding)); | 17303 CHECK_EQ(resource, cons->GetExternalStringResourceBase(&encoding)); |
17474 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding); | 17304 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding); |
17475 } | 17305 } |
17476 | 17306 |
17477 | 17307 |
17478 TEST(ExternalizeOldSpaceOneByteCons) { | 17308 TEST(ExternalizeOldSpaceOneByteCons) { |
17479 v8::Isolate* isolate = CcTest::isolate(); | 17309 v8::Isolate* isolate = CcTest::isolate(); |
17480 LocalContext env; | 17310 LocalContext env; |
17481 v8::HandleScope scope(isolate); | 17311 v8::HandleScope scope(isolate); |
17482 v8::Local<v8::String> cons = | 17312 v8::Local<v8::String> cons = |
17483 CompileRun("'Romeo Montague ' + 'Juliet Capulet'")->ToString(isolate); | 17313 CompileRun("'Romeo Montague ' + 'Juliet Capulet'") |
17314 ->ToString(env.local()) | |
17315 .ToLocalChecked(); | |
17484 CHECK(v8::Utils::OpenHandle(*cons)->IsConsString()); | 17316 CHECK(v8::Utils::OpenHandle(*cons)->IsConsString()); |
17485 CcTest::heap()->CollectAllAvailableGarbage(); | 17317 CcTest::heap()->CollectAllAvailableGarbage(); |
17486 CHECK(CcTest::heap()->old_space()->Contains(*v8::Utils::OpenHandle(*cons))); | 17318 CHECK(CcTest::heap()->old_space()->Contains(*v8::Utils::OpenHandle(*cons))); |
17487 | 17319 |
17488 TestOneByteResource* resource = | 17320 TestOneByteResource* resource = |
17489 new TestOneByteResource(i::StrDup("Romeo Montague Juliet Capulet")); | 17321 new TestOneByteResource(i::StrDup("Romeo Montague Juliet Capulet")); |
17490 cons->MakeExternal(resource); | 17322 cons->MakeExternal(resource); |
17491 | 17323 |
17492 CHECK(cons->IsExternalOneByte()); | 17324 CHECK(cons->IsExternalOneByte()); |
17493 CHECK_EQ(resource, cons->GetExternalOneByteStringResource()); | 17325 CHECK_EQ(resource, cons->GetExternalOneByteStringResource()); |
17494 String::Encoding encoding; | 17326 String::Encoding encoding; |
17495 CHECK_EQ(resource, cons->GetExternalStringResourceBase(&encoding)); | 17327 CHECK_EQ(resource, cons->GetExternalStringResourceBase(&encoding)); |
17496 CHECK_EQ(String::ONE_BYTE_ENCODING, encoding); | 17328 CHECK_EQ(String::ONE_BYTE_ENCODING, encoding); |
17497 } | 17329 } |
17498 | 17330 |
17499 | 17331 |
17500 TEST(VisitExternalStrings) { | 17332 TEST(VisitExternalStrings) { |
17501 v8::Isolate* isolate = CcTest::isolate(); | 17333 v8::Isolate* isolate = CcTest::isolate(); |
17502 LocalContext env; | 17334 LocalContext env; |
17503 v8::HandleScope scope(isolate); | 17335 v8::HandleScope scope(isolate); |
17504 const char* string = "Some string"; | 17336 const char* string = "Some string"; |
17505 uint16_t* two_byte_string = AsciiToTwoByteString(string); | 17337 uint16_t* two_byte_string = AsciiToTwoByteString(string); |
17506 TestResource* resource[4]; | 17338 TestResource* resource[4]; |
17507 resource[0] = new TestResource(two_byte_string); | 17339 resource[0] = new TestResource(two_byte_string); |
17508 v8::Local<v8::String> string0 = | 17340 v8::Local<v8::String> string0 = |
17509 v8::String::NewExternal(env->GetIsolate(), resource[0]); | 17341 v8::String::NewExternalTwoByte(env->GetIsolate(), resource[0]) |
17342 .ToLocalChecked(); | |
17510 resource[1] = new TestResource(two_byte_string, NULL, false); | 17343 resource[1] = new TestResource(two_byte_string, NULL, false); |
17511 v8::Local<v8::String> string1 = | 17344 v8::Local<v8::String> string1 = |
17512 v8::String::NewExternal(env->GetIsolate(), resource[1]); | 17345 v8::String::NewExternalTwoByte(env->GetIsolate(), resource[1]) |
17346 .ToLocalChecked(); | |
17513 | 17347 |
17514 // Externalized symbol. | 17348 // Externalized symbol. |
17515 resource[2] = new TestResource(two_byte_string, NULL, false); | 17349 resource[2] = new TestResource(two_byte_string, NULL, false); |
17516 v8::Local<v8::String> string2 = | 17350 v8::Local<v8::String> string2 = |
17517 v8::String::NewFromUtf8(env->GetIsolate(), string, | 17351 v8::String::NewFromUtf8(env->GetIsolate(), string, |
17518 v8::NewStringType::kInternalized) | 17352 v8::NewStringType::kInternalized) |
17519 .ToLocalChecked(); | 17353 .ToLocalChecked(); |
17520 CHECK(string2->MakeExternal(resource[2])); | 17354 CHECK(string2->MakeExternal(resource[2])); |
17521 | 17355 |
17522 // Symbolized External. | 17356 // Symbolized External. |
17523 resource[3] = new TestResource(AsciiToTwoByteString("Some other string")); | 17357 resource[3] = new TestResource(AsciiToTwoByteString("Some other string")); |
17524 v8::Local<v8::String> string3 = | 17358 v8::Local<v8::String> string3 = |
17525 v8::String::NewExternal(env->GetIsolate(), resource[3]); | 17359 v8::String::NewExternalTwoByte(env->GetIsolate(), resource[3]) |
17360 .ToLocalChecked(); | |
17526 CcTest::heap()->CollectAllAvailableGarbage(); // Tenure string. | 17361 CcTest::heap()->CollectAllAvailableGarbage(); // Tenure string. |
17527 // Turn into a symbol. | 17362 // Turn into a symbol. |
17528 i::Handle<i::String> string3_i = v8::Utils::OpenHandle(*string3); | 17363 i::Handle<i::String> string3_i = v8::Utils::OpenHandle(*string3); |
17529 CHECK(!CcTest::i_isolate()->factory()->InternalizeString( | 17364 CHECK(!CcTest::i_isolate()->factory()->InternalizeString( |
17530 string3_i).is_null()); | 17365 string3_i).is_null()); |
17531 CHECK(string3_i->IsInternalizedString()); | 17366 CHECK(string3_i->IsInternalizedString()); |
17532 | 17367 |
17533 // We need to add usages for string* to avoid warnings in GCC 4.7 | 17368 // We need to add usages for string* to avoid warnings in GCC 4.7 |
17534 CHECK(string0->IsExternal()); | 17369 CHECK(string0->IsExternal()); |
17535 CHECK(string1->IsExternal()); | 17370 CHECK(string1->IsExternal()); |
17536 CHECK(string2->IsExternal()); | 17371 CHECK(string2->IsExternal()); |
17537 CHECK(string3->IsExternal()); | 17372 CHECK(string3->IsExternal()); |
17538 | 17373 |
17539 VisitorImpl visitor(resource); | 17374 VisitorImpl visitor(resource); |
17540 v8::V8::VisitExternalResources(&visitor); | 17375 CcTest::isolate()->VisitExternalResources(&visitor); |
vogelheim
2015/12/11 15:19:03
CcTest::isolate() -> isolate
jochen (gone - plz use gerrit)
2015/12/11 15:27:41
done
| |
17541 visitor.CheckVisitedResources(); | 17376 visitor.CheckVisitedResources(); |
17542 } | 17377 } |
17543 | 17378 |
17544 | 17379 |
17545 TEST(ExternalStringCollectedAtTearDown) { | 17380 TEST(ExternalStringCollectedAtTearDown) { |
17546 int destroyed = 0; | 17381 int destroyed = 0; |
17547 v8::Isolate::CreateParams create_params; | 17382 v8::Isolate::CreateParams create_params; |
17548 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 17383 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
17549 v8::Isolate* isolate = v8::Isolate::New(create_params); | 17384 v8::Isolate* isolate = v8::Isolate::New(create_params); |
17550 { v8::Isolate::Scope isolate_scope(isolate); | 17385 { v8::Isolate::Scope isolate_scope(isolate); |
17551 v8::HandleScope handle_scope(isolate); | 17386 v8::HandleScope handle_scope(isolate); |
17552 const char* s = "One string to test them all, one string to find them."; | 17387 const char* s = "One string to test them all, one string to find them."; |
17553 TestOneByteResource* inscription = | 17388 TestOneByteResource* inscription = |
17554 new TestOneByteResource(i::StrDup(s), &destroyed); | 17389 new TestOneByteResource(i::StrDup(s), &destroyed); |
17555 v8::Local<v8::String> ring = v8::String::NewExternal(isolate, inscription); | 17390 v8::Local<v8::String> ring = |
17391 v8::String::NewExternalOneByte(isolate, inscription).ToLocalChecked(); | |
17556 // Ring is still alive. Orcs are roaming freely across our lands. | 17392 // Ring is still alive. Orcs are roaming freely across our lands. |
17557 CHECK_EQ(0, destroyed); | 17393 CHECK_EQ(0, destroyed); |
17558 USE(ring); | 17394 USE(ring); |
17559 } | 17395 } |
17560 | 17396 |
17561 isolate->Dispose(); | 17397 isolate->Dispose(); |
17562 // Ring has been destroyed. Free Peoples of Middle-earth Rejoice. | 17398 // Ring has been destroyed. Free Peoples of Middle-earth Rejoice. |
17563 CHECK_EQ(1, destroyed); | 17399 CHECK_EQ(1, destroyed); |
17564 } | 17400 } |
17565 | 17401 |
17566 | 17402 |
17567 TEST(ExternalInternalizedStringCollectedAtTearDown) { | 17403 TEST(ExternalInternalizedStringCollectedAtTearDown) { |
17568 int destroyed = 0; | 17404 int destroyed = 0; |
17569 v8::Isolate::CreateParams create_params; | 17405 v8::Isolate::CreateParams create_params; |
17570 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 17406 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
17571 v8::Isolate* isolate = v8::Isolate::New(create_params); | 17407 v8::Isolate* isolate = v8::Isolate::New(create_params); |
17572 { v8::Isolate::Scope isolate_scope(isolate); | 17408 { v8::Isolate::Scope isolate_scope(isolate); |
17573 LocalContext env(isolate); | 17409 LocalContext env(isolate); |
17574 v8::HandleScope handle_scope(isolate); | 17410 v8::HandleScope handle_scope(isolate); |
17575 CompileRun("var ring = 'One string to test them all';"); | 17411 CompileRun("var ring = 'One string to test them all';"); |
17576 const char* s = "One string to test them all"; | 17412 const char* s = "One string to test them all"; |
17577 TestOneByteResource* inscription = | 17413 TestOneByteResource* inscription = |
17578 new TestOneByteResource(i::StrDup(s), &destroyed); | 17414 new TestOneByteResource(i::StrDup(s), &destroyed); |
17579 v8::Local<v8::String> ring = CompileRun("ring")->ToString(isolate); | 17415 v8::Local<v8::String> ring = |
17416 CompileRun("ring")->ToString(env.local()).ToLocalChecked(); | |
17580 CHECK(v8::Utils::OpenHandle(*ring)->IsInternalizedString()); | 17417 CHECK(v8::Utils::OpenHandle(*ring)->IsInternalizedString()); |
17581 ring->MakeExternal(inscription); | 17418 ring->MakeExternal(inscription); |
17582 // Ring is still alive. Orcs are roaming freely across our lands. | 17419 // Ring is still alive. Orcs are roaming freely across our lands. |
17583 CHECK_EQ(0, destroyed); | 17420 CHECK_EQ(0, destroyed); |
17584 USE(ring); | 17421 USE(ring); |
17585 } | 17422 } |
17586 | 17423 |
17587 isolate->Dispose(); | 17424 isolate->Dispose(); |
17588 // Ring has been destroyed. Free Peoples of Middle-earth Rejoice. | 17425 // Ring has been destroyed. Free Peoples of Middle-earth Rejoice. |
17589 CHECK_EQ(1, destroyed); | 17426 CHECK_EQ(1, destroyed); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17686 -qnan, | 17523 -qnan, |
17687 -snan | 17524 -snan |
17688 }; | 17525 }; |
17689 int num_test_values = 20; | 17526 int num_test_values = 20; |
17690 | 17527 |
17691 for (int i = 0; i < num_test_values; i++) { | 17528 for (int i = 0; i < num_test_values; i++) { |
17692 double test_value = test_values[i]; | 17529 double test_value = test_values[i]; |
17693 | 17530 |
17694 // Check that Number::New preserves non-NaNs and quiets SNaNs. | 17531 // Check that Number::New preserves non-NaNs and quiets SNaNs. |
17695 v8::Local<v8::Value> number = v8::Number::New(isolate, test_value); | 17532 v8::Local<v8::Value> number = v8::Number::New(isolate, test_value); |
17696 double stored_number = number->NumberValue(); | 17533 double stored_number = number->NumberValue(context.local()).FromJust(); |
17697 if (!std::isnan(test_value)) { | 17534 if (!std::isnan(test_value)) { |
17698 CHECK_EQ(test_value, stored_number); | 17535 CHECK_EQ(test_value, stored_number); |
17699 } else { | 17536 } else { |
17700 uint64_t stored_bits = DoubleToBits(stored_number); | 17537 uint64_t stored_bits = DoubleToBits(stored_number); |
17701 // Check if quiet nan (bits 51..62 all set). | 17538 // Check if quiet nan (bits 51..62 all set). |
17702 #if (defined(V8_TARGET_ARCH_MIPS) || defined(V8_TARGET_ARCH_MIPS64)) && \ | 17539 #if (defined(V8_TARGET_ARCH_MIPS) || defined(V8_TARGET_ARCH_MIPS64)) && \ |
17703 !defined(_MIPS_ARCH_MIPS64R6) && !defined(_MIPS_ARCH_MIPS32R6) && \ | 17540 !defined(_MIPS_ARCH_MIPS64R6) && !defined(_MIPS_ARCH_MIPS32R6) && \ |
17704 !defined(USE_SIMULATOR) | 17541 !defined(USE_SIMULATOR) |
17705 // Most significant fraction bit for quiet nan is set to 0 | 17542 // Most significant fraction bit for quiet nan is set to 0 |
17706 // on MIPS architecture. Allowed by IEEE-754. | 17543 // on MIPS architecture. Allowed by IEEE-754. |
17707 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff)); | 17544 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff)); |
17708 #else | 17545 #else |
17709 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff)); | 17546 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff)); |
17710 #endif | 17547 #endif |
17711 } | 17548 } |
17712 | 17549 |
17713 // Check that Date::New preserves non-NaNs in the date range and | 17550 // Check that Date::New preserves non-NaNs in the date range and |
17714 // quiets SNaNs. | 17551 // quiets SNaNs. |
17715 v8::Local<v8::Value> date = v8::Date::New(isolate, test_value); | 17552 v8::Local<v8::Value> date = |
17553 v8::Date::New(context.local(), test_value).ToLocalChecked(); | |
17716 double expected_stored_date = DoubleToDateTime(test_value); | 17554 double expected_stored_date = DoubleToDateTime(test_value); |
17717 double stored_date = date->NumberValue(); | 17555 double stored_date = date->NumberValue(context.local()).FromJust(); |
17718 if (!std::isnan(expected_stored_date)) { | 17556 if (!std::isnan(expected_stored_date)) { |
17719 CHECK_EQ(expected_stored_date, stored_date); | 17557 CHECK_EQ(expected_stored_date, stored_date); |
17720 } else { | 17558 } else { |
17721 uint64_t stored_bits = DoubleToBits(stored_date); | 17559 uint64_t stored_bits = DoubleToBits(stored_date); |
17722 // Check if quiet nan (bits 51..62 all set). | 17560 // Check if quiet nan (bits 51..62 all set). |
17723 #if (defined(V8_TARGET_ARCH_MIPS) || defined(V8_TARGET_ARCH_MIPS64)) && \ | 17561 #if (defined(V8_TARGET_ARCH_MIPS) || defined(V8_TARGET_ARCH_MIPS64)) && \ |
17724 !defined(_MIPS_ARCH_MIPS64R6) && !defined(_MIPS_ARCH_MIPS32R6) && \ | 17562 !defined(_MIPS_ARCH_MIPS64R6) && !defined(_MIPS_ARCH_MIPS32R6) && \ |
17725 !defined(USE_SIMULATOR) | 17563 !defined(USE_SIMULATOR) |
17726 // Most significant fraction bit for quiet nan is set to 0 | 17564 // Most significant fraction bit for quiet nan is set to 0 |
17727 // on MIPS architecture. Allowed by IEEE-754. | 17565 // on MIPS architecture. Allowed by IEEE-754. |
17728 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff)); | 17566 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff)); |
17729 #else | 17567 #else |
17730 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff)); | 17568 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff)); |
17731 #endif | 17569 #endif |
17732 } | 17570 } |
17733 } | 17571 } |
17734 } | 17572 } |
17735 | 17573 |
17736 | 17574 |
17737 static void SpaghettiIncident( | 17575 static void SpaghettiIncident( |
17738 const v8::FunctionCallbackInfo<v8::Value>& args) { | 17576 const v8::FunctionCallbackInfo<v8::Value>& args) { |
17739 v8::HandleScope scope(args.GetIsolate()); | 17577 v8::HandleScope scope(args.GetIsolate()); |
17740 v8::TryCatch tc(args.GetIsolate()); | 17578 v8::TryCatch tc(args.GetIsolate()); |
17741 v8::Local<v8::String> str(args[0]->ToString(args.GetIsolate())); | 17579 v8::MaybeLocal<v8::String> str( |
17580 args[0]->ToString(args.GetIsolate()->GetCurrentContext())); | |
17742 USE(str); | 17581 USE(str); |
17743 if (tc.HasCaught()) | 17582 if (tc.HasCaught()) |
17744 tc.ReThrow(); | 17583 tc.ReThrow(); |
17745 } | 17584 } |
17746 | 17585 |
17747 | 17586 |
17748 // Test that an exception can be propagated down through a spaghetti | 17587 // Test that an exception can be propagated down through a spaghetti |
17749 // stack using ReThrow. | 17588 // stack using ReThrow. |
17750 THREADED_TEST(SpaghettiStackReThrow) { | 17589 THREADED_TEST(SpaghettiStackReThrow) { |
17751 v8::Isolate* isolate = CcTest::isolate(); | 17590 v8::Isolate* isolate = CcTest::isolate(); |
17752 v8::HandleScope scope(isolate); | 17591 v8::HandleScope scope(isolate); |
17753 LocalContext context; | 17592 LocalContext context; |
17754 context->Global()->Set(v8_str("s"), | 17593 context->Global() |
17755 v8::FunctionTemplate::New(isolate, SpaghettiIncident) | 17594 ->Set(context.local(), v8_str("s"), |
17756 ->GetFunction(context.local()) | 17595 v8::FunctionTemplate::New(isolate, SpaghettiIncident) |
17757 .ToLocalChecked()); | 17596 ->GetFunction(context.local()) |
17597 .ToLocalChecked()) | |
17598 .FromJust(); | |
17758 v8::TryCatch try_catch(isolate); | 17599 v8::TryCatch try_catch(isolate); |
17759 CompileRun( | 17600 CompileRun( |
17760 "var i = 0;" | 17601 "var i = 0;" |
17761 "var o = {" | 17602 "var o = {" |
17762 " toString: function () {" | 17603 " toString: function () {" |
17763 " if (i == 10) {" | 17604 " if (i == 10) {" |
17764 " throw 'Hey!';" | 17605 " throw 'Hey!';" |
17765 " } else {" | 17606 " } else {" |
17766 " i++;" | 17607 " i++;" |
17767 " return s(o);" | 17608 " return s(o);" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17839 { | 17680 { |
17840 v8::HandleScope scope(isolate); | 17681 v8::HandleScope scope(isolate); |
17841 v8::Local<Context> context = Context::New(isolate); | 17682 v8::Local<Context> context = Context::New(isolate); |
17842 | 17683 |
17843 context->Enter(); | 17684 context->Enter(); |
17844 v8::TryCatch try_catch(isolate); | 17685 v8::TryCatch try_catch(isolate); |
17845 CompileRun(source_exception); | 17686 CompileRun(source_exception); |
17846 CHECK(try_catch.HasCaught()); | 17687 CHECK(try_catch.HasCaught()); |
17847 v8::Local<v8::Message> message = try_catch.Message(); | 17688 v8::Local<v8::Message> message = try_catch.Message(); |
17848 CHECK(!message.IsEmpty()); | 17689 CHECK(!message.IsEmpty()); |
17849 CHECK_EQ(1, message->GetLineNumber()); | 17690 CHECK_EQ(1, message->GetLineNumber(context).FromJust()); |
17850 context->Exit(); | 17691 context->Exit(); |
17851 } | 17692 } |
17852 isolate->ContextDisposedNotification(); | 17693 isolate->ContextDisposedNotification(); |
17853 for (gc_count = 1; gc_count < 10; gc_count++) { | 17694 for (gc_count = 1; gc_count < 10; gc_count++) { |
17854 other_context->Enter(); | 17695 other_context->Enter(); |
17855 CompileRun(source_exception); | 17696 CompileRun(source_exception); |
17856 other_context->Exit(); | 17697 other_context->Exit(); |
17857 CcTest::heap()->CollectAllGarbage(); | 17698 CcTest::heap()->CollectAllGarbage(); |
17858 if (GetGlobalObjectsCount() == 1) break; | 17699 if (GetGlobalObjectsCount() == 1) break; |
17859 } | 17700 } |
17860 CHECK_GE(2, gc_count); | 17701 CHECK_GE(2, gc_count); |
17861 CHECK_EQ(1, GetGlobalObjectsCount()); | 17702 CHECK_EQ(1, GetGlobalObjectsCount()); |
17862 | 17703 |
17863 isolate->ContextDisposedNotification(); | 17704 isolate->ContextDisposedNotification(); |
17864 } | 17705 } |
17865 | 17706 |
17866 | 17707 |
17867 THREADED_TEST(ScriptOrigin) { | 17708 THREADED_TEST(ScriptOrigin) { |
17868 LocalContext env; | 17709 LocalContext env; |
17869 v8::HandleScope scope(env->GetIsolate()); | 17710 v8::HandleScope scope(env->GetIsolate()); |
17870 v8::ScriptOrigin origin = v8::ScriptOrigin( | 17711 v8::ScriptOrigin origin = v8::ScriptOrigin( |
17871 v8_str("test"), v8::Integer::New(env->GetIsolate(), 1), | 17712 v8_str("test"), v8::Integer::New(env->GetIsolate(), 1), |
17872 v8::Integer::New(env->GetIsolate(), 1), v8::True(env->GetIsolate()), | 17713 v8::Integer::New(env->GetIsolate(), 1), v8::True(env->GetIsolate()), |
17873 v8::Local<v8::Integer>(), v8::True(env->GetIsolate()), | 17714 v8::Local<v8::Integer>(), v8::True(env->GetIsolate()), |
17874 v8_str("http://sourceMapUrl"), v8::True(env->GetIsolate())); | 17715 v8_str("http://sourceMapUrl"), v8::True(env->GetIsolate())); |
17875 v8::Local<v8::String> script = v8_str("function f() {}\n\nfunction g() {}"); | 17716 v8::Local<v8::String> script = v8_str("function f() {}\n\nfunction g() {}"); |
17876 v8::Script::Compile(script, &origin)->Run(); | 17717 v8::Script::Compile(env.local(), script, &origin) |
17877 v8::Local<v8::Function> f = | 17718 .ToLocalChecked() |
17878 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("f"))); | 17719 ->Run(env.local()) |
17879 v8::Local<v8::Function> g = | 17720 .ToLocalChecked(); |
17880 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("g"))); | 17721 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( |
17722 env->Global()->Get(env.local(), v8_str("f")).ToLocalChecked()); | |
17723 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( | |
17724 env->Global()->Get(env.local(), v8_str("g")).ToLocalChecked()); | |
17881 | 17725 |
17882 v8::ScriptOrigin script_origin_f = f->GetScriptOrigin(); | 17726 v8::ScriptOrigin script_origin_f = f->GetScriptOrigin(); |
17883 CHECK_EQ(0, strcmp("test", | 17727 CHECK_EQ(0, strcmp("test", |
17884 *v8::String::Utf8Value(script_origin_f.ResourceName()))); | 17728 *v8::String::Utf8Value(script_origin_f.ResourceName()))); |
17885 CHECK_EQ( | 17729 CHECK_EQ( |
17886 1, | 17730 1, |
17887 script_origin_f.ResourceLineOffset()->Int32Value(env.local()).FromJust()); | 17731 script_origin_f.ResourceLineOffset()->Int32Value(env.local()).FromJust()); |
17888 CHECK(script_origin_f.Options().IsSharedCrossOrigin()); | 17732 CHECK(script_origin_f.Options().IsSharedCrossOrigin()); |
17889 CHECK(script_origin_f.Options().IsEmbedderDebugScript()); | 17733 CHECK(script_origin_f.Options().IsEmbedderDebugScript()); |
17890 CHECK(script_origin_f.Options().IsOpaque()); | 17734 CHECK(script_origin_f.Options().IsOpaque()); |
(...skipping 15 matching lines...) Expand all Loading... | |
17906 *v8::String::Utf8Value(script_origin_g.SourceMapUrl()))); | 17750 *v8::String::Utf8Value(script_origin_g.SourceMapUrl()))); |
17907 } | 17751 } |
17908 | 17752 |
17909 | 17753 |
17910 THREADED_TEST(FunctionGetInferredName) { | 17754 THREADED_TEST(FunctionGetInferredName) { |
17911 LocalContext env; | 17755 LocalContext env; |
17912 v8::HandleScope scope(env->GetIsolate()); | 17756 v8::HandleScope scope(env->GetIsolate()); |
17913 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str("test")); | 17757 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str("test")); |
17914 v8::Local<v8::String> script = | 17758 v8::Local<v8::String> script = |
17915 v8_str("var foo = { bar : { baz : function() {}}}; var f = foo.bar.baz;"); | 17759 v8_str("var foo = { bar : { baz : function() {}}}; var f = foo.bar.baz;"); |
17916 v8::Script::Compile(script, &origin)->Run(); | 17760 v8::Script::Compile(env.local(), script, &origin) |
17917 v8::Local<v8::Function> f = | 17761 .ToLocalChecked() |
17918 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("f"))); | 17762 ->Run(env.local()) |
17763 .ToLocalChecked(); | |
17764 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( | |
17765 env->Global()->Get(env.local(), v8_str("f")).ToLocalChecked()); | |
17919 CHECK_EQ(0, | 17766 CHECK_EQ(0, |
17920 strcmp("foo.bar.baz", *v8::String::Utf8Value(f->GetInferredName()))); | 17767 strcmp("foo.bar.baz", *v8::String::Utf8Value(f->GetInferredName()))); |
17921 } | 17768 } |
17922 | 17769 |
17923 | 17770 |
17924 THREADED_TEST(FunctionGetDebugName) { | 17771 THREADED_TEST(FunctionGetDebugName) { |
17925 LocalContext env; | 17772 LocalContext env; |
17926 v8::HandleScope scope(env->GetIsolate()); | 17773 v8::HandleScope scope(env->GetIsolate()); |
17927 const char* code = | 17774 const char* code = |
17928 "var error = false;" | 17775 "var error = false;" |
(...skipping 30 matching lines...) Expand all Loading... | |
17959 "}; g();" | 17806 "}; g();" |
17960 "var h = function() {};" | 17807 "var h = function() {};" |
17961 "h.displayName = 'displayName';" | 17808 "h.displayName = 'displayName';" |
17962 "Object.defineProperty(h, 'name', { value: 'function.name' });" | 17809 "Object.defineProperty(h, 'name', { value: 'function.name' });" |
17963 "var i = function() {};" | 17810 "var i = function() {};" |
17964 "i.displayName = 239;" | 17811 "i.displayName = 239;" |
17965 "Object.defineProperty(i, 'name', { value: 'function.name' });" | 17812 "Object.defineProperty(i, 'name', { value: 'function.name' });" |
17966 "var j = function() {};" | 17813 "var j = function() {};" |
17967 "Object.defineProperty(j, 'name', { value: 'function.name' });" | 17814 "Object.defineProperty(j, 'name', { value: 'function.name' });" |
17968 "var foo = { bar : { baz : function() {}}}; var k = foo.bar.baz;"; | 17815 "var foo = { bar : { baz : function() {}}}; var k = foo.bar.baz;"; |
17969 v8::ScriptOrigin origin = | 17816 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str("test")); |
17970 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test")); | 17817 v8::Script::Compile(env.local(), v8_str(code), &origin) |
17971 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), code), &origin) | 17818 .ToLocalChecked() |
17972 ->Run(); | 17819 ->Run(env.local()) |
17820 .ToLocalChecked(); | |
17973 v8::Local<v8::Value> error = | 17821 v8::Local<v8::Value> error = |
17974 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "error")); | 17822 env->Global()->Get(env.local(), v8_str("error")).ToLocalChecked(); |
17975 CHECK_EQ(false, error->BooleanValue()); | 17823 CHECK_EQ(false, error->BooleanValue(env.local()).FromJust()); |
17976 const char* functions[] = {"a", "display_a", | 17824 const char* functions[] = {"a", "display_a", |
17977 "b", "display_b", | 17825 "b", "display_b", |
17978 "c", "c", | 17826 "c", "c", |
17979 "d", "d", | 17827 "d", "d", |
17980 "e", "e", | 17828 "e", "e", |
17981 "f", "f", | 17829 "f", "f", |
17982 "g", "set_in_runtime", | 17830 "g", "set_in_runtime", |
17983 "h", "displayName", | 17831 "h", "displayName", |
17984 "i", "function.name", | 17832 "i", "function.name", |
17985 "j", "function.name", | 17833 "j", "function.name", |
17986 "k", "foo.bar.baz"}; | 17834 "k", "foo.bar.baz"}; |
17987 for (size_t i = 0; i < sizeof(functions) / sizeof(functions[0]) / 2; ++i) { | 17835 for (size_t i = 0; i < sizeof(functions) / sizeof(functions[0]) / 2; ++i) { |
17988 v8::Local<v8::Function> f = | 17836 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( |
17989 v8::Local<v8::Function>::Cast(env->Global()->Get( | 17837 env->Global() |
17990 v8::String::NewFromUtf8(env->GetIsolate(), functions[i * 2]))); | 17838 ->Get(env.local(), |
17839 v8::String::NewFromUtf8(env->GetIsolate(), functions[i * 2], | |
17840 v8::NewStringType::kNormal) | |
17841 .ToLocalChecked()) | |
17842 .ToLocalChecked()); | |
17991 CHECK_EQ(0, strcmp(functions[i * 2 + 1], | 17843 CHECK_EQ(0, strcmp(functions[i * 2 + 1], |
17992 *v8::String::Utf8Value(f->GetDebugName()))); | 17844 *v8::String::Utf8Value(f->GetDebugName()))); |
17993 } | 17845 } |
17994 } | 17846 } |
17995 | 17847 |
17996 | 17848 |
17997 THREADED_TEST(FunctionGetDisplayName) { | 17849 THREADED_TEST(FunctionGetDisplayName) { |
17998 LocalContext env; | 17850 LocalContext env; |
17999 v8::HandleScope scope(env->GetIsolate()); | 17851 v8::HandleScope scope(env->GetIsolate()); |
18000 const char* code = "var error = false;" | 17852 const char* code = "var error = false;" |
(...skipping 22 matching lines...) Expand all Loading... | |
18023 "});" | 17875 "});" |
18024 "function f() {};" | 17876 "function f() {};" |
18025 "f.displayName = { 'foo': 6, toString: function() {" | 17877 "f.displayName = { 'foo': 6, toString: function() {" |
18026 " error = true;" | 17878 " error = true;" |
18027 " return 'wrong_display_name';" | 17879 " return 'wrong_display_name';" |
18028 "}};" | 17880 "}};" |
18029 "var g = function() {" | 17881 "var g = function() {" |
18030 " arguments.callee.displayName = 'set_in_runtime';" | 17882 " arguments.callee.displayName = 'set_in_runtime';" |
18031 "}; g();"; | 17883 "}; g();"; |
18032 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str("test")); | 17884 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str("test")); |
18033 v8::Script::Compile(v8_str(code), &origin)->Run(); | 17885 v8::Script::Compile(env.local(), v8_str(code), &origin) |
18034 v8::Local<v8::Value> error = env->Global()->Get(v8_str("error")); | 17886 .ToLocalChecked() |
18035 v8::Local<v8::Function> a = | 17887 ->Run(env.local()) |
18036 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("a"))); | 17888 .ToLocalChecked(); |
18037 v8::Local<v8::Function> b = | 17889 v8::Local<v8::Value> error = |
18038 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("b"))); | 17890 env->Global()->Get(env.local(), v8_str("error")).ToLocalChecked(); |
18039 v8::Local<v8::Function> c = | 17891 v8::Local<v8::Function> a = v8::Local<v8::Function>::Cast( |
18040 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("c"))); | 17892 env->Global()->Get(env.local(), v8_str("a")).ToLocalChecked()); |
18041 v8::Local<v8::Function> d = | 17893 v8::Local<v8::Function> b = v8::Local<v8::Function>::Cast( |
18042 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("d"))); | 17894 env->Global()->Get(env.local(), v8_str("b")).ToLocalChecked()); |
18043 v8::Local<v8::Function> e = | 17895 v8::Local<v8::Function> c = v8::Local<v8::Function>::Cast( |
18044 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("e"))); | 17896 env->Global()->Get(env.local(), v8_str("c")).ToLocalChecked()); |
18045 v8::Local<v8::Function> f = | 17897 v8::Local<v8::Function> d = v8::Local<v8::Function>::Cast( |
18046 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("f"))); | 17898 env->Global()->Get(env.local(), v8_str("d")).ToLocalChecked()); |
18047 v8::Local<v8::Function> g = | 17899 v8::Local<v8::Function> e = v8::Local<v8::Function>::Cast( |
18048 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("g"))); | 17900 env->Global()->Get(env.local(), v8_str("e")).ToLocalChecked()); |
18049 CHECK_EQ(false, error->BooleanValue()); | 17901 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( |
17902 env->Global()->Get(env.local(), v8_str("f")).ToLocalChecked()); | |
17903 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( | |
17904 env->Global()->Get(env.local(), v8_str("g")).ToLocalChecked()); | |
17905 CHECK_EQ(false, error->BooleanValue(env.local()).FromJust()); | |
18050 CHECK_EQ(0, strcmp("display_a", *v8::String::Utf8Value(a->GetDisplayName()))); | 17906 CHECK_EQ(0, strcmp("display_a", *v8::String::Utf8Value(a->GetDisplayName()))); |
18051 CHECK_EQ(0, strcmp("display_b", *v8::String::Utf8Value(b->GetDisplayName()))); | 17907 CHECK_EQ(0, strcmp("display_b", *v8::String::Utf8Value(b->GetDisplayName()))); |
18052 CHECK(c->GetDisplayName()->IsUndefined()); | 17908 CHECK(c->GetDisplayName()->IsUndefined()); |
18053 CHECK(d->GetDisplayName()->IsUndefined()); | 17909 CHECK(d->GetDisplayName()->IsUndefined()); |
18054 CHECK(e->GetDisplayName()->IsUndefined()); | 17910 CHECK(e->GetDisplayName()->IsUndefined()); |
18055 CHECK(f->GetDisplayName()->IsUndefined()); | 17911 CHECK(f->GetDisplayName()->IsUndefined()); |
18056 CHECK_EQ( | 17912 CHECK_EQ( |
18057 0, strcmp("set_in_runtime", *v8::String::Utf8Value(g->GetDisplayName()))); | 17913 0, strcmp("set_in_runtime", *v8::String::Utf8Value(g->GetDisplayName()))); |
18058 } | 17914 } |
18059 | 17915 |
18060 | 17916 |
18061 THREADED_TEST(ScriptLineNumber) { | 17917 THREADED_TEST(ScriptLineNumber) { |
18062 LocalContext env; | 17918 LocalContext env; |
18063 v8::HandleScope scope(env->GetIsolate()); | 17919 v8::HandleScope scope(env->GetIsolate()); |
18064 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str("test")); | 17920 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str("test")); |
18065 v8::Local<v8::String> script = v8_str("function f() {}\n\nfunction g() {}"); | 17921 v8::Local<v8::String> script = v8_str("function f() {}\n\nfunction g() {}"); |
18066 v8::Script::Compile(script, &origin)->Run(); | 17922 v8::Script::Compile(env.local(), script, &origin) |
18067 v8::Local<v8::Function> f = | 17923 .ToLocalChecked() |
18068 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("f"))); | 17924 ->Run(env.local()) |
18069 v8::Local<v8::Function> g = | 17925 .ToLocalChecked(); |
18070 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("g"))); | 17926 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( |
17927 env->Global()->Get(env.local(), v8_str("f")).ToLocalChecked()); | |
17928 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( | |
17929 env->Global()->Get(env.local(), v8_str("g")).ToLocalChecked()); | |
18071 CHECK_EQ(0, f->GetScriptLineNumber()); | 17930 CHECK_EQ(0, f->GetScriptLineNumber()); |
18072 CHECK_EQ(2, g->GetScriptLineNumber()); | 17931 CHECK_EQ(2, g->GetScriptLineNumber()); |
18073 } | 17932 } |
18074 | 17933 |
18075 | 17934 |
18076 THREADED_TEST(ScriptColumnNumber) { | 17935 THREADED_TEST(ScriptColumnNumber) { |
18077 LocalContext env; | 17936 LocalContext env; |
18078 v8::Isolate* isolate = env->GetIsolate(); | 17937 v8::Isolate* isolate = env->GetIsolate(); |
18079 v8::HandleScope scope(isolate); | 17938 v8::HandleScope scope(isolate); |
18080 v8::ScriptOrigin origin = | 17939 v8::ScriptOrigin origin = |
18081 v8::ScriptOrigin(v8_str("test"), v8::Integer::New(isolate, 3), | 17940 v8::ScriptOrigin(v8_str("test"), v8::Integer::New(isolate, 3), |
18082 v8::Integer::New(isolate, 2)); | 17941 v8::Integer::New(isolate, 2)); |
18083 v8::Local<v8::String> script = | 17942 v8::Local<v8::String> script = |
18084 v8_str("function foo() {}\n\n function bar() {}"); | 17943 v8_str("function foo() {}\n\n function bar() {}"); |
18085 v8::Script::Compile(script, &origin)->Run(); | 17944 v8::Script::Compile(env.local(), script, &origin) |
18086 v8::Local<v8::Function> foo = | 17945 .ToLocalChecked() |
18087 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("foo"))); | 17946 ->Run(env.local()) |
18088 v8::Local<v8::Function> bar = | 17947 .ToLocalChecked(); |
18089 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("bar"))); | 17948 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( |
17949 env->Global()->Get(env.local(), v8_str("foo")).ToLocalChecked()); | |
17950 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( | |
17951 env->Global()->Get(env.local(), v8_str("bar")).ToLocalChecked()); | |
18090 CHECK_EQ(14, foo->GetScriptColumnNumber()); | 17952 CHECK_EQ(14, foo->GetScriptColumnNumber()); |
18091 CHECK_EQ(17, bar->GetScriptColumnNumber()); | 17953 CHECK_EQ(17, bar->GetScriptColumnNumber()); |
18092 } | 17954 } |
18093 | 17955 |
18094 | 17956 |
18095 THREADED_TEST(FunctionIsBuiltin) { | 17957 THREADED_TEST(FunctionIsBuiltin) { |
18096 LocalContext env; | 17958 LocalContext env; |
18097 v8::Isolate* isolate = env->GetIsolate(); | 17959 v8::Isolate* isolate = env->GetIsolate(); |
18098 v8::HandleScope scope(isolate); | 17960 v8::HandleScope scope(isolate); |
18099 v8::Local<v8::Function> f; | 17961 v8::Local<v8::Function> f; |
(...skipping 12 matching lines...) Expand all Loading... | |
18112 | 17974 |
18113 THREADED_TEST(FunctionGetScriptId) { | 17975 THREADED_TEST(FunctionGetScriptId) { |
18114 LocalContext env; | 17976 LocalContext env; |
18115 v8::Isolate* isolate = env->GetIsolate(); | 17977 v8::Isolate* isolate = env->GetIsolate(); |
18116 v8::HandleScope scope(isolate); | 17978 v8::HandleScope scope(isolate); |
18117 v8::ScriptOrigin origin = | 17979 v8::ScriptOrigin origin = |
18118 v8::ScriptOrigin(v8_str("test"), v8::Integer::New(isolate, 3), | 17980 v8::ScriptOrigin(v8_str("test"), v8::Integer::New(isolate, 3), |
18119 v8::Integer::New(isolate, 2)); | 17981 v8::Integer::New(isolate, 2)); |
18120 v8::Local<v8::String> scriptSource = | 17982 v8::Local<v8::String> scriptSource = |
18121 v8_str("function foo() {}\n\n function bar() {}"); | 17983 v8_str("function foo() {}\n\n function bar() {}"); |
18122 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin)); | 17984 v8::Local<v8::Script> script( |
18123 script->Run(); | 17985 v8::Script::Compile(env.local(), scriptSource, &origin).ToLocalChecked()); |
18124 v8::Local<v8::Function> foo = | 17986 script->Run(env.local()).ToLocalChecked(); |
18125 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("foo"))); | 17987 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( |
18126 v8::Local<v8::Function> bar = | 17988 env->Global()->Get(env.local(), v8_str("foo")).ToLocalChecked()); |
18127 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("bar"))); | 17989 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( |
17990 env->Global()->Get(env.local(), v8_str("bar")).ToLocalChecked()); | |
18128 CHECK_EQ(script->GetUnboundScript()->GetId(), foo->ScriptId()); | 17991 CHECK_EQ(script->GetUnboundScript()->GetId(), foo->ScriptId()); |
18129 CHECK_EQ(script->GetUnboundScript()->GetId(), bar->ScriptId()); | 17992 CHECK_EQ(script->GetUnboundScript()->GetId(), bar->ScriptId()); |
18130 } | 17993 } |
18131 | 17994 |
18132 | 17995 |
18133 THREADED_TEST(FunctionGetBoundFunction) { | 17996 THREADED_TEST(FunctionGetBoundFunction) { |
18134 LocalContext env; | 17997 LocalContext env; |
18135 v8::HandleScope scope(env->GetIsolate()); | 17998 v8::HandleScope scope(env->GetIsolate()); |
18136 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str("test")); | 17999 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str("test")); |
18137 v8::Local<v8::String> script = v8_str( | 18000 v8::Local<v8::String> script = v8_str( |
18138 "var a = new Object();\n" | 18001 "var a = new Object();\n" |
18139 "a.x = 1;\n" | 18002 "a.x = 1;\n" |
18140 "function f () { return this.x };\n" | 18003 "function f () { return this.x };\n" |
18141 "var g = f.bind(a);\n" | 18004 "var g = f.bind(a);\n" |
18142 "var b = g();"); | 18005 "var b = g();"); |
18143 v8::Script::Compile(script, &origin)->Run(); | 18006 v8::Script::Compile(env.local(), script, &origin) |
18144 v8::Local<v8::Function> f = | 18007 .ToLocalChecked() |
18145 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("f"))); | 18008 ->Run(env.local()) |
18146 v8::Local<v8::Function> g = | 18009 .ToLocalChecked(); |
18147 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("g"))); | 18010 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( |
18011 env->Global()->Get(env.local(), v8_str("f")).ToLocalChecked()); | |
18012 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( | |
18013 env->Global()->Get(env.local(), v8_str("g")).ToLocalChecked()); | |
18148 CHECK(g->GetBoundFunction()->IsFunction()); | 18014 CHECK(g->GetBoundFunction()->IsFunction()); |
18149 Local<v8::Function> original_function = Local<v8::Function>::Cast( | 18015 Local<v8::Function> original_function = Local<v8::Function>::Cast( |
18150 g->GetBoundFunction()); | 18016 g->GetBoundFunction()); |
18151 CHECK(f->GetName()->Equals(original_function->GetName())); | 18017 CHECK(f->GetName() |
18018 ->Equals(env.local(), original_function->GetName()) | |
18019 .FromJust()); | |
18152 CHECK_EQ(f->GetScriptLineNumber(), original_function->GetScriptLineNumber()); | 18020 CHECK_EQ(f->GetScriptLineNumber(), original_function->GetScriptLineNumber()); |
18153 CHECK_EQ(f->GetScriptColumnNumber(), | 18021 CHECK_EQ(f->GetScriptColumnNumber(), |
18154 original_function->GetScriptColumnNumber()); | 18022 original_function->GetScriptColumnNumber()); |
18155 } | 18023 } |
18156 | 18024 |
18157 | 18025 |
18158 static void GetterWhichReturns42( | 18026 static void GetterWhichReturns42( |
18159 Local<String> name, | 18027 Local<String> name, |
18160 const v8::PropertyCallbackInfo<v8::Value>& info) { | 18028 const v8::PropertyCallbackInfo<v8::Value>& info) { |
18161 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); | 18029 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); |
18162 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); | 18030 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); |
18163 info.GetReturnValue().Set(v8_num(42)); | 18031 info.GetReturnValue().Set(v8_num(42)); |
18164 } | 18032 } |
18165 | 18033 |
18166 | 18034 |
18167 static void SetterWhichSetsYOnThisTo23( | 18035 static void SetterWhichSetsYOnThisTo23( |
18168 Local<String> name, | 18036 Local<String> name, |
18169 Local<Value> value, | 18037 Local<Value> value, |
18170 const v8::PropertyCallbackInfo<void>& info) { | 18038 const v8::PropertyCallbackInfo<void>& info) { |
18171 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); | 18039 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); |
18172 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); | 18040 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); |
18173 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); | 18041 Local<Object>::Cast(info.This()) |
18042 ->Set(info.GetIsolate()->GetCurrentContext(), v8_str("y"), v8_num(23)) | |
18043 .FromJust(); | |
18174 } | 18044 } |
18175 | 18045 |
18176 | 18046 |
18177 void FooGetInterceptor(Local<Name> name, | 18047 void FooGetInterceptor(Local<Name> name, |
18178 const v8::PropertyCallbackInfo<v8::Value>& info) { | 18048 const v8::PropertyCallbackInfo<v8::Value>& info) { |
18179 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); | 18049 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); |
18180 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); | 18050 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); |
18181 if (!name->Equals(v8_str("foo"))) return; | 18051 if (!name->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("foo")) |
18052 .FromJust()) { | |
18053 return; | |
18054 } | |
18182 info.GetReturnValue().Set(v8_num(42)); | 18055 info.GetReturnValue().Set(v8_num(42)); |
18183 } | 18056 } |
18184 | 18057 |
18185 | 18058 |
18186 void FooSetInterceptor(Local<Name> name, Local<Value> value, | 18059 void FooSetInterceptor(Local<Name> name, Local<Value> value, |
18187 const v8::PropertyCallbackInfo<v8::Value>& info) { | 18060 const v8::PropertyCallbackInfo<v8::Value>& info) { |
18188 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); | 18061 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); |
18189 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); | 18062 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); |
18190 if (!name->Equals(v8_str("foo"))) return; | 18063 if (!name->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("foo")) |
18191 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); | 18064 .FromJust()) { |
18065 return; | |
18066 } | |
18067 Local<Object>::Cast(info.This()) | |
18068 ->Set(info.GetIsolate()->GetCurrentContext(), v8_str("y"), v8_num(23)) | |
18069 .FromJust(); | |
18192 info.GetReturnValue().Set(v8_num(23)); | 18070 info.GetReturnValue().Set(v8_num(23)); |
18193 } | 18071 } |
18194 | 18072 |
18195 | 18073 |
18196 TEST(SetterOnConstructorPrototype) { | 18074 TEST(SetterOnConstructorPrototype) { |
18197 v8::Isolate* isolate = CcTest::isolate(); | 18075 v8::Isolate* isolate = CcTest::isolate(); |
18198 v8::HandleScope scope(isolate); | 18076 v8::HandleScope scope(isolate); |
18199 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 18077 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
18200 templ->SetAccessor(v8_str("x"), GetterWhichReturns42, | 18078 templ->SetAccessor(v8_str("x"), GetterWhichReturns42, |
18201 SetterWhichSetsYOnThisTo23); | 18079 SetterWhichSetsYOnThisTo23); |
18202 LocalContext context; | 18080 LocalContext context; |
18203 CHECK(context->Global() | 18081 CHECK(context->Global() |
18204 ->Set(context.local(), v8_str("P"), | 18082 ->Set(context.local(), v8_str("P"), |
18205 templ->NewInstance(context.local()).ToLocalChecked()) | 18083 templ->NewInstance(context.local()).ToLocalChecked()) |
18206 .FromJust()); | 18084 .FromJust()); |
18207 CompileRun("function C1() {" | 18085 CompileRun("function C1() {" |
18208 " this.x = 23;" | 18086 " this.x = 23;" |
18209 "};" | 18087 "};" |
18210 "C1.prototype = P;" | 18088 "C1.prototype = P;" |
18211 "function C2() {" | 18089 "function C2() {" |
18212 " this.x = 23" | 18090 " this.x = 23" |
18213 "};" | 18091 "};" |
18214 "C2.prototype = { };" | 18092 "C2.prototype = { };" |
18215 "C2.prototype.__proto__ = P;"); | 18093 "C2.prototype.__proto__ = P;"); |
18216 | 18094 |
18217 v8::Local<v8::Script> script; | 18095 v8::Local<v8::Script> script; |
18218 script = v8_compile("new C1();"); | 18096 script = v8_compile("new C1();"); |
18219 for (int i = 0; i < 10; i++) { | 18097 for (int i = 0; i < 10; i++) { |
18220 v8::Local<v8::Object> c1 = v8::Local<v8::Object>::Cast(script->Run()); | 18098 v8::Local<v8::Object> c1 = v8::Local<v8::Object>::Cast( |
18221 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value(context.local()).FromJust()); | 18099 script->Run(context.local()).ToLocalChecked()); |
18222 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value(context.local()).FromJust()); | 18100 CHECK_EQ(42, c1->Get(context.local(), v8_str("x")) |
18101 .ToLocalChecked() | |
18102 ->Int32Value(context.local()) | |
18103 .FromJust()); | |
18104 CHECK_EQ(23, c1->Get(context.local(), v8_str("y")) | |
18105 .ToLocalChecked() | |
18106 ->Int32Value(context.local()) | |
18107 .FromJust()); | |
18223 } | 18108 } |
18224 | 18109 |
18225 script = v8_compile("new C2();"); | 18110 script = v8_compile("new C2();"); |
18226 for (int i = 0; i < 10; i++) { | 18111 for (int i = 0; i < 10; i++) { |
18227 v8::Local<v8::Object> c2 = v8::Local<v8::Object>::Cast(script->Run()); | 18112 v8::Local<v8::Object> c2 = v8::Local<v8::Object>::Cast( |
18228 CHECK_EQ(42, c2->Get(v8_str("x"))->Int32Value(context.local()).FromJust()); | 18113 script->Run(context.local()).ToLocalChecked()); |
18229 CHECK_EQ(23, c2->Get(v8_str("y"))->Int32Value(context.local()).FromJust()); | 18114 CHECK_EQ(42, c2->Get(context.local(), v8_str("x")) |
18115 .ToLocalChecked() | |
18116 ->Int32Value(context.local()) | |
18117 .FromJust()); | |
18118 CHECK_EQ(23, c2->Get(context.local(), v8_str("y")) | |
18119 .ToLocalChecked() | |
18120 ->Int32Value(context.local()) | |
18121 .FromJust()); | |
18230 } | 18122 } |
18231 } | 18123 } |
18232 | 18124 |
18233 | 18125 |
18234 static void NamedPropertyGetterWhichReturns42( | 18126 static void NamedPropertyGetterWhichReturns42( |
18235 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { | 18127 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
18236 info.GetReturnValue().Set(v8_num(42)); | 18128 info.GetReturnValue().Set(v8_num(42)); |
18237 } | 18129 } |
18238 | 18130 |
18239 | 18131 |
18240 static void NamedPropertySetterWhichSetsYOnThisTo23( | 18132 static void NamedPropertySetterWhichSetsYOnThisTo23( |
18241 Local<Name> name, Local<Value> value, | 18133 Local<Name> name, Local<Value> value, |
18242 const v8::PropertyCallbackInfo<v8::Value>& info) { | 18134 const v8::PropertyCallbackInfo<v8::Value>& info) { |
18243 if (name->Equals(v8_str("x"))) { | 18135 if (name->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("x")) |
18244 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); | 18136 .FromJust()) { |
18137 Local<Object>::Cast(info.This()) | |
18138 ->Set(info.GetIsolate()->GetCurrentContext(), v8_str("y"), v8_num(23)) | |
18139 .FromJust(); | |
18245 } | 18140 } |
18246 } | 18141 } |
18247 | 18142 |
18248 | 18143 |
18249 THREADED_TEST(InterceptorOnConstructorPrototype) { | 18144 THREADED_TEST(InterceptorOnConstructorPrototype) { |
18250 v8::Isolate* isolate = CcTest::isolate(); | 18145 v8::Isolate* isolate = CcTest::isolate(); |
18251 v8::HandleScope scope(isolate); | 18146 v8::HandleScope scope(isolate); |
18252 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 18147 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
18253 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( | 18148 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
18254 NamedPropertyGetterWhichReturns42, | 18149 NamedPropertyGetterWhichReturns42, |
18255 NamedPropertySetterWhichSetsYOnThisTo23)); | 18150 NamedPropertySetterWhichSetsYOnThisTo23)); |
18256 LocalContext context; | 18151 LocalContext context; |
18257 CHECK(context->Global() | 18152 CHECK(context->Global() |
18258 ->Set(context.local(), v8_str("P"), | 18153 ->Set(context.local(), v8_str("P"), |
18259 templ->NewInstance(context.local()).ToLocalChecked()) | 18154 templ->NewInstance(context.local()).ToLocalChecked()) |
18260 .FromJust()); | 18155 .FromJust()); |
18261 CompileRun("function C1() {" | 18156 CompileRun("function C1() {" |
18262 " this.x = 23;" | 18157 " this.x = 23;" |
18263 "};" | 18158 "};" |
18264 "C1.prototype = P;" | 18159 "C1.prototype = P;" |
18265 "function C2() {" | 18160 "function C2() {" |
18266 " this.x = 23" | 18161 " this.x = 23" |
18267 "};" | 18162 "};" |
18268 "C2.prototype = { };" | 18163 "C2.prototype = { };" |
18269 "C2.prototype.__proto__ = P;"); | 18164 "C2.prototype.__proto__ = P;"); |
18270 | 18165 |
18271 v8::Local<v8::Script> script; | 18166 v8::Local<v8::Script> script; |
18272 script = v8_compile("new C1();"); | 18167 script = v8_compile("new C1();"); |
18273 for (int i = 0; i < 10; i++) { | 18168 for (int i = 0; i < 10; i++) { |
18274 v8::Local<v8::Object> c1 = v8::Local<v8::Object>::Cast(script->Run()); | 18169 v8::Local<v8::Object> c1 = v8::Local<v8::Object>::Cast( |
18275 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value(context.local()).FromJust()); | 18170 script->Run(context.local()).ToLocalChecked()); |
18276 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value(context.local()).FromJust()); | 18171 CHECK_EQ(23, c1->Get(context.local(), v8_str("x")) |
18172 .ToLocalChecked() | |
18173 ->Int32Value(context.local()) | |
18174 .FromJust()); | |
18175 CHECK_EQ(42, c1->Get(context.local(), v8_str("y")) | |
18176 .ToLocalChecked() | |
18177 ->Int32Value(context.local()) | |
18178 .FromJust()); | |
18277 } | 18179 } |
18278 | 18180 |
18279 script = v8_compile("new C2();"); | 18181 script = v8_compile("new C2();"); |
18280 for (int i = 0; i < 10; i++) { | 18182 for (int i = 0; i < 10; i++) { |
18281 v8::Local<v8::Object> c2 = v8::Local<v8::Object>::Cast(script->Run()); | 18183 v8::Local<v8::Object> c2 = v8::Local<v8::Object>::Cast( |
18282 CHECK_EQ(23, c2->Get(v8_str("x"))->Int32Value(context.local()).FromJust()); | 18184 script->Run(context.local()).ToLocalChecked()); |
18283 CHECK_EQ(42, c2->Get(v8_str("y"))->Int32Value(context.local()).FromJust()); | 18185 CHECK_EQ(23, c2->Get(context.local(), v8_str("x")) |
18186 .ToLocalChecked() | |
18187 ->Int32Value(context.local()) | |
18188 .FromJust()); | |
18189 CHECK_EQ(42, c2->Get(context.local(), v8_str("y")) | |
18190 .ToLocalChecked() | |
18191 ->Int32Value(context.local()) | |
18192 .FromJust()); | |
18284 } | 18193 } |
18285 } | 18194 } |
18286 | 18195 |
18287 | 18196 |
18288 TEST(Regress618) { | 18197 TEST(Regress618) { |
18289 const char* source = "function C1() {" | 18198 const char* source = "function C1() {" |
18290 " this.x = 23;" | 18199 " this.x = 23;" |
18291 "};" | 18200 "};" |
18292 "C1.prototype = P;"; | 18201 "C1.prototype = P;"; |
18293 | 18202 |
18294 LocalContext context; | 18203 LocalContext context; |
18295 v8::Isolate* isolate = context->GetIsolate(); | 18204 v8::Isolate* isolate = context->GetIsolate(); |
18296 v8::HandleScope scope(isolate); | 18205 v8::HandleScope scope(isolate); |
18297 v8::Local<v8::Script> script; | 18206 v8::Local<v8::Script> script; |
18298 | 18207 |
18299 // Use a simple object as prototype. | 18208 // Use a simple object as prototype. |
18300 v8::Local<v8::Object> prototype = v8::Object::New(isolate); | 18209 v8::Local<v8::Object> prototype = v8::Object::New(isolate); |
18301 prototype->Set(v8_str("y"), v8_num(42)); | 18210 prototype->Set(context.local(), v8_str("y"), v8_num(42)).FromJust(); |
18302 CHECK(context->Global() | 18211 CHECK(context->Global() |
18303 ->Set(context.local(), v8_str("P"), prototype) | 18212 ->Set(context.local(), v8_str("P"), prototype) |
18304 .FromJust()); | 18213 .FromJust()); |
18305 | 18214 |
18306 // This compile will add the code to the compilation cache. | 18215 // This compile will add the code to the compilation cache. |
18307 CompileRun(source); | 18216 CompileRun(source); |
18308 | 18217 |
18309 script = v8_compile("new C1();"); | 18218 script = v8_compile("new C1();"); |
18310 // Allow enough iterations for the inobject slack tracking logic | 18219 // Allow enough iterations for the inobject slack tracking logic |
18311 // to finalize instance size and install the fast construct stub. | 18220 // to finalize instance size and install the fast construct stub. |
18312 for (int i = 0; i < 256; i++) { | 18221 for (int i = 0; i < 256; i++) { |
18313 v8::Local<v8::Object> c1 = v8::Local<v8::Object>::Cast(script->Run()); | 18222 v8::Local<v8::Object> c1 = v8::Local<v8::Object>::Cast( |
18314 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value(context.local()).FromJust()); | 18223 script->Run(context.local()).ToLocalChecked()); |
18315 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value(context.local()).FromJust()); | 18224 CHECK_EQ(23, c1->Get(context.local(), v8_str("x")) |
18225 .ToLocalChecked() | |
18226 ->Int32Value(context.local()) | |
18227 .FromJust()); | |
18228 CHECK_EQ(42, c1->Get(context.local(), v8_str("y")) | |
18229 .ToLocalChecked() | |
18230 ->Int32Value(context.local()) | |
18231 .FromJust()); | |
18316 } | 18232 } |
18317 | 18233 |
18318 // Use an API object with accessors as prototype. | 18234 // Use an API object with accessors as prototype. |
18319 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 18235 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
18320 templ->SetAccessor(v8_str("x"), GetterWhichReturns42, | 18236 templ->SetAccessor(v8_str("x"), GetterWhichReturns42, |
18321 SetterWhichSetsYOnThisTo23); | 18237 SetterWhichSetsYOnThisTo23); |
18322 CHECK(context->Global() | 18238 CHECK(context->Global() |
18323 ->Set(context.local(), v8_str("P"), | 18239 ->Set(context.local(), v8_str("P"), |
18324 templ->NewInstance(context.local()).ToLocalChecked()) | 18240 templ->NewInstance(context.local()).ToLocalChecked()) |
18325 .FromJust()); | 18241 .FromJust()); |
18326 | 18242 |
18327 // This compile will get the code from the compilation cache. | 18243 // This compile will get the code from the compilation cache. |
18328 CompileRun(source); | 18244 CompileRun(source); |
18329 | 18245 |
18330 script = v8_compile("new C1();"); | 18246 script = v8_compile("new C1();"); |
18331 for (int i = 0; i < 10; i++) { | 18247 for (int i = 0; i < 10; i++) { |
18332 v8::Local<v8::Object> c1 = v8::Local<v8::Object>::Cast(script->Run()); | 18248 v8::Local<v8::Object> c1 = v8::Local<v8::Object>::Cast( |
18333 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value(context.local()).FromJust()); | 18249 script->Run(context.local()).ToLocalChecked()); |
18334 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value(context.local()).FromJust()); | 18250 CHECK_EQ(42, c1->Get(context.local(), v8_str("x")) |
18251 .ToLocalChecked() | |
18252 ->Int32Value(context.local()) | |
18253 .FromJust()); | |
18254 CHECK_EQ(23, c1->Get(context.local(), v8_str("y")) | |
18255 .ToLocalChecked() | |
18256 ->Int32Value(context.local()) | |
18257 .FromJust()); | |
18335 } | 18258 } |
18336 } | 18259 } |
18337 | 18260 |
18338 v8::Isolate* gc_callbacks_isolate = NULL; | 18261 v8::Isolate* gc_callbacks_isolate = NULL; |
18339 int prologue_call_count = 0; | 18262 int prologue_call_count = 0; |
18340 int epilogue_call_count = 0; | 18263 int epilogue_call_count = 0; |
18341 int prologue_call_count_second = 0; | 18264 int prologue_call_count_second = 0; |
18342 int epilogue_call_count_second = 0; | 18265 int epilogue_call_count_second = 0; |
18343 int prologue_call_count_alloc = 0; | 18266 int prologue_call_count_alloc = 0; |
18344 int epilogue_call_count_alloc = 0; | 18267 int epilogue_call_count_alloc = 0; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
18601 v8::base::SmartArrayPointer<uintptr_t> aligned_contents( | 18524 v8::base::SmartArrayPointer<uintptr_t> aligned_contents( |
18602 new uintptr_t[aligned_length]); | 18525 new uintptr_t[aligned_length]); |
18603 uint16_t* string_contents = | 18526 uint16_t* string_contents = |
18604 reinterpret_cast<uint16_t*>(aligned_contents.get()); | 18527 reinterpret_cast<uint16_t*>(aligned_contents.get()); |
18605 // Set to contain only one byte. | 18528 // Set to contain only one byte. |
18606 for (int i = 0; i < length-1; i++) { | 18529 for (int i = 0; i < length-1; i++) { |
18607 string_contents[i] = 0x41; | 18530 string_contents[i] = 0x41; |
18608 } | 18531 } |
18609 string_contents[length-1] = 0; | 18532 string_contents[length-1] = 0; |
18610 // Simple case. | 18533 // Simple case. |
18611 Local<String> string = String::NewExternal( | 18534 Local<String> string = |
18612 isolate, new TestResource(string_contents, NULL, false)); | 18535 String::NewExternalTwoByte(isolate, |
18536 new TestResource(string_contents, NULL, false)) | |
18537 .ToLocalChecked(); | |
18613 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); | 18538 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); |
18614 // Counter example. | 18539 // Counter example. |
18615 string = String::NewFromTwoByte(isolate, string_contents); | 18540 string = String::NewFromTwoByte(isolate, string_contents, |
18541 v8::NewStringType::kNormal) | |
18542 .ToLocalChecked(); | |
18616 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte()); | 18543 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte()); |
18617 // Test left right and balanced cons strings. | 18544 // Test left right and balanced cons strings. |
18618 Local<String> base = v8_str("a"); | 18545 Local<String> base = v8_str("a"); |
18619 Local<String> left = base; | 18546 Local<String> left = base; |
18620 Local<String> right = base; | 18547 Local<String> right = base; |
18621 for (int i = 0; i < 1000; i++) { | 18548 for (int i = 0; i < 1000; i++) { |
18622 left = String::Concat(base, left); | 18549 left = String::Concat(base, left); |
18623 right = String::Concat(right, base); | 18550 right = String::Concat(right, base); |
18624 } | 18551 } |
18625 Local<String> balanced = String::Concat(left, base); | 18552 Local<String> balanced = String::Concat(left, base); |
18626 balanced = String::Concat(balanced, right); | 18553 balanced = String::Concat(balanced, right); |
18627 Local<String> cons_strings[] = {left, balanced, right}; | 18554 Local<String> cons_strings[] = {left, balanced, right}; |
18628 Local<String> two_byte = String::NewExternal( | 18555 Local<String> two_byte = |
18629 isolate, new TestResource(string_contents, NULL, false)); | 18556 String::NewExternalTwoByte(isolate, |
18557 new TestResource(string_contents, NULL, false)) | |
18558 .ToLocalChecked(); | |
18630 USE(two_byte); USE(cons_strings); | 18559 USE(two_byte); USE(cons_strings); |
18631 for (size_t i = 0; i < arraysize(cons_strings); i++) { | 18560 for (size_t i = 0; i < arraysize(cons_strings); i++) { |
18632 // Base assumptions. | 18561 // Base assumptions. |
18633 string = cons_strings[i]; | 18562 string = cons_strings[i]; |
18634 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte()); | 18563 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte()); |
18635 // Test left and right concatentation. | 18564 // Test left and right concatentation. |
18636 string = String::Concat(two_byte, cons_strings[i]); | 18565 string = String::Concat(two_byte, cons_strings[i]); |
18637 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); | 18566 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); |
18638 string = String::Concat(cons_strings[i], two_byte); | 18567 string = String::Concat(cons_strings[i], two_byte); |
18639 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); | 18568 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); |
18640 } | 18569 } |
18641 // Set bits in different positions | 18570 // Set bits in different positions |
18642 // for strings of different lengths and alignments. | 18571 // for strings of different lengths and alignments. |
18643 for (int alignment = 0; alignment < 7; alignment++) { | 18572 for (int alignment = 0; alignment < 7; alignment++) { |
18644 for (int size = 2; alignment + size < length; size *= 2) { | 18573 for (int size = 2; alignment + size < length; size *= 2) { |
18645 int zero_offset = size + alignment; | 18574 int zero_offset = size + alignment; |
18646 string_contents[zero_offset] = 0; | 18575 string_contents[zero_offset] = 0; |
18647 for (int i = 0; i < size; i++) { | 18576 for (int i = 0; i < size; i++) { |
18648 int shift = 8 + (i % 7); | 18577 int shift = 8 + (i % 7); |
18649 string_contents[alignment + i] = 1 << shift; | 18578 string_contents[alignment + i] = 1 << shift; |
18650 string = String::NewExternal( | 18579 string = String::NewExternalTwoByte( |
18651 isolate, | 18580 isolate, |
18652 new TestResource(string_contents + alignment, NULL, false)); | 18581 new TestResource(string_contents + alignment, NULL, false)) |
18582 .ToLocalChecked(); | |
18653 CHECK_EQ(size, string->Length()); | 18583 CHECK_EQ(size, string->Length()); |
18654 CHECK(!string->ContainsOnlyOneByte()); | 18584 CHECK(!string->ContainsOnlyOneByte()); |
18655 string_contents[alignment + i] = 0x41; | 18585 string_contents[alignment + i] = 0x41; |
18656 } | 18586 } |
18657 string_contents[zero_offset] = 0x41; | 18587 string_contents[zero_offset] = 0x41; |
18658 } | 18588 } |
18659 } | 18589 } |
18660 } | 18590 } |
18661 | 18591 |
18662 | 18592 |
18663 // Failed access check callback that performs a GC on each invocation. | 18593 // Failed access check callback that performs a GC on each invocation. |
18664 void FailedAccessCheckCallbackGC(Local<v8::Object> target, | 18594 void FailedAccessCheckCallbackGC(Local<v8::Object> target, |
18665 v8::AccessType type, | 18595 v8::AccessType type, |
18666 Local<v8::Value> data) { | 18596 Local<v8::Value> data) { |
18667 CcTest::heap()->CollectAllGarbage(); | 18597 CcTest::heap()->CollectAllGarbage(); |
18668 CcTest::isolate()->ThrowException( | 18598 CcTest::isolate()->ThrowException( |
18669 v8::Exception::Error(v8_str("cross context"))); | 18599 v8::Exception::Error(v8_str("cross context"))); |
18670 } | 18600 } |
18671 | 18601 |
18672 | 18602 |
18673 TEST(GCInFailedAccessCheckCallback) { | 18603 TEST(GCInFailedAccessCheckCallback) { |
18674 // Install a failed access check callback that performs a GC on each | 18604 // Install a failed access check callback that performs a GC on each |
18675 // invocation. Then force the callback to be called from va | 18605 // invocation. Then force the callback to be called from va |
18676 | 18606 |
18677 v8::V8::Initialize(); | 18607 v8::V8::Initialize(); |
18678 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckCallbackGC); | 18608 v8::Isolate* isolate = CcTest::isolate(); |
18679 | 18609 |
18680 v8::Isolate* isolate = CcTest::isolate(); | 18610 isolate->SetFailedAccessCheckCallbackFunction(&FailedAccessCheckCallbackGC); |
18611 | |
18681 v8::HandleScope scope(isolate); | 18612 v8::HandleScope scope(isolate); |
18682 | 18613 |
18683 // Create an ObjectTemplate for global objects and install access | 18614 // Create an ObjectTemplate for global objects and install access |
18684 // check callbacks that will block access. | 18615 // check callbacks that will block access. |
18685 v8::Local<v8::ObjectTemplate> global_template = | 18616 v8::Local<v8::ObjectTemplate> global_template = |
18686 v8::ObjectTemplate::New(isolate); | 18617 v8::ObjectTemplate::New(isolate); |
18687 global_template->SetAccessCheckCallback(AccessAlwaysBlocked); | 18618 global_template->SetAccessCheckCallback(AccessAlwaysBlocked); |
18688 | 18619 |
18689 // Create a context and set an x property on it's global object. | 18620 // Create a context and set an x property on it's global object. |
18690 LocalContext context0(NULL, global_template); | 18621 LocalContext context0(NULL, global_template); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
18731 CHECK(CompileRun("0 in other").IsEmpty()); | 18662 CHECK(CompileRun("0 in other").IsEmpty()); |
18732 CHECK(try_catch.HasCaught()); | 18663 CHECK(try_catch.HasCaught()); |
18733 try_catch.Reset(); | 18664 try_catch.Reset(); |
18734 | 18665 |
18735 // Delete property. | 18666 // Delete property. |
18736 CHECK(CompileRun("delete other.x").IsEmpty()); | 18667 CHECK(CompileRun("delete other.x").IsEmpty()); |
18737 CHECK(try_catch.HasCaught()); | 18668 CHECK(try_catch.HasCaught()); |
18738 try_catch.Reset(); | 18669 try_catch.Reset(); |
18739 | 18670 |
18740 // Delete element. | 18671 // Delete element. |
18741 CHECK_EQ(false, global0->Delete(0)); | 18672 CHECK(global0->Delete(context1.local(), 0).IsNothing()); |
18673 CHECK(try_catch.HasCaught()); | |
18674 try_catch.Reset(); | |
18742 | 18675 |
18743 // DefineAccessor. | 18676 // DefineAccessor. |
18744 CHECK_EQ(false, | 18677 CHECK(global0->SetAccessor(context1.local(), v8_str("x"), GetXValue, NULL, |
18745 global0->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("x"))); | 18678 v8_str("x")) |
18679 .IsNothing()); | |
18680 CHECK(try_catch.HasCaught()); | |
18681 try_catch.Reset(); | |
18746 | 18682 |
18747 // Define JavaScript accessor. | 18683 // Define JavaScript accessor. |
18748 CHECK(CompileRun( | 18684 CHECK(CompileRun( |
18749 "Object.prototype.__defineGetter__.call(" | 18685 "Object.prototype.__defineGetter__.call(" |
18750 " other, \'x\', function() { return 42; })").IsEmpty()); | 18686 " other, \'x\', function() { return 42; })").IsEmpty()); |
18751 CHECK(try_catch.HasCaught()); | 18687 CHECK(try_catch.HasCaught()); |
18752 try_catch.Reset(); | 18688 try_catch.Reset(); |
18753 | 18689 |
18754 // LookupAccessor. | 18690 // LookupAccessor. |
18755 CHECK(CompileRun( | 18691 CHECK(CompileRun( |
18756 "Object.prototype.__lookupGetter__.call(" | 18692 "Object.prototype.__lookupGetter__.call(" |
18757 " other, \'x\')").IsEmpty()); | 18693 " other, \'x\')").IsEmpty()); |
18758 CHECK(try_catch.HasCaught()); | 18694 CHECK(try_catch.HasCaught()); |
18759 try_catch.Reset(); | 18695 try_catch.Reset(); |
18760 | 18696 |
18761 // HasOwnElement. | 18697 // HasOwnElement. |
18762 CHECK(CompileRun( | 18698 CHECK(CompileRun( |
18763 "Object.prototype.hasOwnProperty.call(" | 18699 "Object.prototype.hasOwnProperty.call(" |
18764 "other, \'0\')").IsEmpty()); | 18700 "other, \'0\')").IsEmpty()); |
18765 CHECK(try_catch.HasCaught()); | 18701 CHECK(try_catch.HasCaught()); |
18766 try_catch.Reset(); | 18702 try_catch.Reset(); |
18767 | 18703 |
18768 CHECK_EQ(false, global0->HasRealIndexedProperty(0)); | 18704 CHECK(global0->HasRealIndexedProperty(context1.local(), 0).IsNothing()); |
18769 CHECK_EQ(false, global0->HasRealNamedProperty(v8_str("x"))); | 18705 CHECK(try_catch.HasCaught()); |
18770 CHECK_EQ(false, global0->HasRealNamedCallbackProperty(v8_str("x"))); | 18706 try_catch.Reset(); |
18707 | |
18708 CHECK( | |
18709 global0->HasRealNamedProperty(context1.local(), v8_str("x")).IsNothing()); | |
18710 CHECK(try_catch.HasCaught()); | |
18711 try_catch.Reset(); | |
18712 | |
18713 CHECK(global0->HasRealNamedCallbackProperty(context1.local(), v8_str("x")) | |
18714 .IsNothing()); | |
18715 CHECK(try_catch.HasCaught()); | |
18716 try_catch.Reset(); | |
18771 | 18717 |
18772 // Reset the failed access check callback so it does not influence | 18718 // Reset the failed access check callback so it does not influence |
18773 // the other tests. | 18719 // the other tests. |
18774 v8::V8::SetFailedAccessCheckCallbackFunction(NULL); | 18720 isolate->SetFailedAccessCheckCallbackFunction(NULL); |
18775 } | 18721 } |
18776 | 18722 |
18777 | 18723 |
18778 TEST(IsolateNewDispose) { | 18724 TEST(IsolateNewDispose) { |
18779 v8::Isolate* current_isolate = CcTest::isolate(); | 18725 v8::Isolate* current_isolate = CcTest::isolate(); |
18780 v8::Isolate::CreateParams create_params; | 18726 v8::Isolate::CreateParams create_params; |
18781 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 18727 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
18782 v8::Isolate* isolate = v8::Isolate::New(create_params); | 18728 v8::Isolate* isolate = v8::Isolate::New(create_params); |
18783 CHECK(isolate != NULL); | 18729 CHECK(isolate != NULL); |
18784 CHECK(current_isolate != isolate); | 18730 CHECK(current_isolate != isolate); |
18785 CHECK(current_isolate == CcTest::isolate()); | 18731 CHECK(current_isolate == CcTest::isolate()); |
18786 | 18732 |
18787 v8::V8::SetFatalErrorHandler(StoringErrorCallback); | 18733 isolate->SetFatalErrorHandler(StoringErrorCallback); |
18788 last_location = last_message = NULL; | 18734 last_location = last_message = NULL; |
18789 isolate->Dispose(); | 18735 isolate->Dispose(); |
18790 CHECK(!last_location); | 18736 CHECK(!last_location); |
18791 CHECK(!last_message); | 18737 CHECK(!last_message); |
18792 } | 18738 } |
18793 | 18739 |
18794 | 18740 |
18795 UNINITIALIZED_TEST(DisposeIsolateWhenInUse) { | 18741 UNINITIALIZED_TEST(DisposeIsolateWhenInUse) { |
18796 v8::Isolate::CreateParams create_params; | 18742 v8::Isolate::CreateParams create_params; |
18797 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 18743 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
18798 v8::Isolate* isolate = v8::Isolate::New(create_params); | 18744 v8::Isolate* isolate = v8::Isolate::New(create_params); |
18799 { | 18745 { |
18800 v8::Isolate::Scope i_scope(isolate); | 18746 v8::Isolate::Scope i_scope(isolate); |
18801 v8::HandleScope scope(isolate); | 18747 v8::HandleScope scope(isolate); |
18802 LocalContext context(isolate); | 18748 LocalContext context(isolate); |
18803 // Run something in this isolate. | 18749 // Run something in this isolate. |
18804 ExpectTrue("true"); | 18750 ExpectTrue("true"); |
18805 v8::V8::SetFatalErrorHandler(StoringErrorCallback); | 18751 isolate->SetFatalErrorHandler(StoringErrorCallback); |
18806 last_location = last_message = NULL; | 18752 last_location = last_message = NULL; |
18807 // Still entered, should fail. | 18753 // Still entered, should fail. |
18808 isolate->Dispose(); | 18754 isolate->Dispose(); |
18809 CHECK(last_location); | 18755 CHECK(last_location); |
18810 CHECK(last_message); | 18756 CHECK(last_message); |
18811 } | 18757 } |
18812 isolate->Dispose(); | 18758 isolate->Dispose(); |
18813 } | 18759 } |
18814 | 18760 |
18815 | 18761 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
18959 } | 18905 } |
18960 | 18906 |
18961 { | 18907 { |
18962 v8::Isolate::Scope iscope(isolate2); | 18908 v8::Isolate::Scope iscope(isolate2); |
18963 context2.Reset(); | 18909 context2.Reset(); |
18964 } | 18910 } |
18965 | 18911 |
18966 context1.Reset(); | 18912 context1.Reset(); |
18967 isolate1->Exit(); | 18913 isolate1->Exit(); |
18968 | 18914 |
18969 v8::V8::SetFatalErrorHandler(StoringErrorCallback); | 18915 isolate2->SetFatalErrorHandler(StoringErrorCallback); |
18970 last_location = last_message = NULL; | 18916 last_location = last_message = NULL; |
18971 | 18917 |
18972 isolate1->Dispose(); | 18918 isolate1->Dispose(); |
18973 CHECK(!last_location); | 18919 CHECK(!last_location); |
18974 CHECK(!last_message); | 18920 CHECK(!last_message); |
18975 | 18921 |
18976 isolate2->Dispose(); | 18922 isolate2->Dispose(); |
18977 CHECK(!last_location); | 18923 CHECK(!last_location); |
18978 CHECK(!last_message); | 18924 CHECK(!last_message); |
18979 | 18925 |
(...skipping 13 matching lines...) Expand all Loading... | |
18993 v8::HandleScope scope(isolate); | 18939 v8::HandleScope scope(isolate); |
18994 LocalContext context(isolate); | 18940 LocalContext context(isolate); |
18995 i::ScopedVector<char> code(1024); | 18941 i::ScopedVector<char> code(1024); |
18996 i::SNPrintF(code, "function fib(n) {" | 18942 i::SNPrintF(code, "function fib(n) {" |
18997 " if (n <= 2) return 1;" | 18943 " if (n <= 2) return 1;" |
18998 " return fib(n-1) + fib(n-2);" | 18944 " return fib(n-1) + fib(n-2);" |
18999 "}" | 18945 "}" |
19000 "fib(%d)", limit); | 18946 "fib(%d)", limit); |
19001 Local<Value> value = CompileRun(code.start()); | 18947 Local<Value> value = CompileRun(code.start()); |
19002 CHECK(value->IsNumber()); | 18948 CHECK(value->IsNumber()); |
19003 return static_cast<int>(value->NumberValue()); | 18949 return static_cast<int>(value->NumberValue(context.local()).FromJust()); |
19004 } | 18950 } |
19005 | 18951 |
19006 class IsolateThread : public v8::base::Thread { | 18952 class IsolateThread : public v8::base::Thread { |
19007 public: | 18953 public: |
19008 explicit IsolateThread(int fib_limit) | 18954 explicit IsolateThread(int fib_limit) |
19009 : Thread(Options("IsolateThread")), fib_limit_(fib_limit), result_(0) {} | 18955 : Thread(Options("IsolateThread")), fib_limit_(fib_limit), result_(0) {} |
19010 | 18956 |
19011 void Run() { | 18957 void Run() { |
19012 v8::Isolate::CreateParams create_params; | 18958 v8::Isolate::CreateParams create_params; |
19013 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 18959 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
19052 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 18998 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
19053 v8::Isolate* isolate = v8::Isolate::New(create_params); | 18999 v8::Isolate* isolate = v8::Isolate::New(create_params); |
19054 Local<v8::Context> context; | 19000 Local<v8::Context> context; |
19055 { | 19001 { |
19056 v8::Isolate::Scope isolate_scope(isolate); | 19002 v8::Isolate::Scope isolate_scope(isolate); |
19057 v8::HandleScope handle_scope(isolate); | 19003 v8::HandleScope handle_scope(isolate); |
19058 context = v8::Context::New(isolate); | 19004 context = v8::Context::New(isolate); |
19059 v8::Context::Scope context_scope(context); | 19005 v8::Context::Scope context_scope(context); |
19060 Local<Value> v = CompileRun("2"); | 19006 Local<Value> v = CompileRun("2"); |
19061 CHECK(v->IsNumber()); | 19007 CHECK(v->IsNumber()); |
19062 CHECK_EQ(2, static_cast<int>(v->NumberValue())); | 19008 CHECK_EQ(2, static_cast<int>(v->NumberValue(context).FromJust())); |
19063 } | 19009 } |
19064 { | 19010 { |
19065 v8::Isolate::Scope isolate_scope(isolate); | 19011 v8::Isolate::Scope isolate_scope(isolate); |
19066 v8::HandleScope handle_scope(isolate); | 19012 v8::HandleScope handle_scope(isolate); |
19067 context = v8::Context::New(isolate); | 19013 context = v8::Context::New(isolate); |
19068 v8::Context::Scope context_scope(context); | 19014 v8::Context::Scope context_scope(context); |
19069 Local<Value> v = CompileRun("22"); | 19015 Local<Value> v = CompileRun("22"); |
19070 CHECK(v->IsNumber()); | 19016 CHECK(v->IsNumber()); |
19071 CHECK_EQ(22, static_cast<int>(v->NumberValue())); | 19017 CHECK_EQ(22, static_cast<int>(v->NumberValue(context).FromJust())); |
19072 } | 19018 } |
19073 isolate->Dispose(); | 19019 isolate->Dispose(); |
19074 } | 19020 } |
19075 | 19021 |
19076 class InitDefaultIsolateThread : public v8::base::Thread { | 19022 class InitDefaultIsolateThread : public v8::base::Thread { |
19077 public: | 19023 public: |
19078 enum TestCase { | 19024 enum TestCase { |
19079 SetResourceConstraints, | 19025 SetResourceConstraints, |
19080 SetFatalHandler, | 19026 SetFatalHandler, |
19081 SetCounterFunction, | 19027 SetCounterFunction, |
(...skipping 21 matching lines...) Expand all Loading... | |
19103 break; | 19049 break; |
19104 } | 19050 } |
19105 v8::Isolate* isolate = v8::Isolate::New(create_params); | 19051 v8::Isolate* isolate = v8::Isolate::New(create_params); |
19106 isolate->Enter(); | 19052 isolate->Enter(); |
19107 switch (testCase_) { | 19053 switch (testCase_) { |
19108 case SetResourceConstraints: | 19054 case SetResourceConstraints: |
19109 // Already handled in pre-Isolate-creation block. | 19055 // Already handled in pre-Isolate-creation block. |
19110 break; | 19056 break; |
19111 | 19057 |
19112 case SetFatalHandler: | 19058 case SetFatalHandler: |
19113 v8::V8::SetFatalErrorHandler(NULL); | 19059 isolate->SetFatalErrorHandler(NULL); |
19114 break; | 19060 break; |
19115 | 19061 |
19116 case SetCounterFunction: | 19062 case SetCounterFunction: |
19117 CcTest::isolate()->SetCounterFunction(NULL); | 19063 CcTest::isolate()->SetCounterFunction(NULL); |
19118 break; | 19064 break; |
19119 | 19065 |
19120 case SetCreateHistogramFunction: | 19066 case SetCreateHistogramFunction: |
19121 CcTest::isolate()->SetCreateHistogramFunction(NULL); | 19067 CcTest::isolate()->SetCreateHistogramFunction(NULL); |
19122 break; | 19068 break; |
19123 | 19069 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
19287 | 19233 |
19288 virtual void VisitPersistentHandle(Persistent<Value>* value, | 19234 virtual void VisitPersistentHandle(Persistent<Value>* value, |
19289 uint16_t class_id) { | 19235 uint16_t class_id) { |
19290 if (class_id != 42) return; | 19236 if (class_id != 42) return; |
19291 CHECK_EQ(42, value->WrapperClassId()); | 19237 CHECK_EQ(42, value->WrapperClassId()); |
19292 v8::Isolate* isolate = CcTest::isolate(); | 19238 v8::Isolate* isolate = CcTest::isolate(); |
19293 v8::HandleScope handle_scope(isolate); | 19239 v8::HandleScope handle_scope(isolate); |
19294 v8::Local<v8::Value> handle = v8::Local<v8::Value>::New(isolate, *value); | 19240 v8::Local<v8::Value> handle = v8::Local<v8::Value>::New(isolate, *value); |
19295 v8::Local<v8::Value> object = v8::Local<v8::Object>::New(isolate, *object_); | 19241 v8::Local<v8::Value> object = v8::Local<v8::Object>::New(isolate, *object_); |
19296 CHECK(handle->IsObject()); | 19242 CHECK(handle->IsObject()); |
19297 CHECK(Local<Object>::Cast(handle)->Equals(object)); | 19243 CHECK(Local<Object>::Cast(handle) |
19244 ->Equals(isolate->GetCurrentContext(), object) | |
19245 .FromJust()); | |
19298 ++counter_; | 19246 ++counter_; |
19299 } | 19247 } |
19300 | 19248 |
19301 int counter_; | 19249 int counter_; |
19302 v8::Persistent<v8::Object>* object_; | 19250 v8::Persistent<v8::Object>* object_; |
19303 }; | 19251 }; |
19304 | 19252 |
19305 | 19253 |
19306 TEST(PersistentHandleVisitor) { | 19254 TEST(PersistentHandleVisitor) { |
19307 LocalContext context; | 19255 LocalContext context; |
19308 v8::Isolate* isolate = context->GetIsolate(); | 19256 v8::Isolate* isolate = context->GetIsolate(); |
19309 v8::HandleScope scope(isolate); | 19257 v8::HandleScope scope(isolate); |
19310 v8::Persistent<v8::Object> object(isolate, v8::Object::New(isolate)); | 19258 v8::Persistent<v8::Object> object(isolate, v8::Object::New(isolate)); |
19311 CHECK_EQ(0, object.WrapperClassId()); | 19259 CHECK_EQ(0, object.WrapperClassId()); |
19312 object.SetWrapperClassId(42); | 19260 object.SetWrapperClassId(42); |
19313 CHECK_EQ(42, object.WrapperClassId()); | 19261 CHECK_EQ(42, object.WrapperClassId()); |
19314 | 19262 |
19315 Visitor42 visitor(&object); | 19263 Visitor42 visitor(&object); |
19316 v8::V8::VisitHandlesWithClassIds(isolate, &visitor); | 19264 isolate->VisitHandlesWithClassIds(&visitor); |
19317 CHECK_EQ(1, visitor.counter_); | 19265 CHECK_EQ(1, visitor.counter_); |
19318 | 19266 |
19319 object.Reset(); | 19267 object.Reset(); |
19320 } | 19268 } |
19321 | 19269 |
19322 | 19270 |
19323 TEST(WrapperClassId) { | 19271 TEST(WrapperClassId) { |
19324 LocalContext context; | 19272 LocalContext context; |
19325 v8::Isolate* isolate = context->GetIsolate(); | 19273 v8::Isolate* isolate = context->GetIsolate(); |
19326 v8::HandleScope scope(isolate); | 19274 v8::HandleScope scope(isolate); |
(...skipping 16 matching lines...) Expand all Loading... | |
19343 | 19291 |
19344 CcTest::heap()->CollectAllGarbage(); | 19292 CcTest::heap()->CollectAllGarbage(); |
19345 CcTest::heap()->CollectAllGarbage(); | 19293 CcTest::heap()->CollectAllGarbage(); |
19346 | 19294 |
19347 v8::Persistent<v8::Object> object2(isolate, v8::Object::New(isolate)); | 19295 v8::Persistent<v8::Object> object2(isolate, v8::Object::New(isolate)); |
19348 CHECK_EQ(0, object2.WrapperClassId()); | 19296 CHECK_EQ(0, object2.WrapperClassId()); |
19349 object2.SetWrapperClassId(42); | 19297 object2.SetWrapperClassId(42); |
19350 CHECK_EQ(42, object2.WrapperClassId()); | 19298 CHECK_EQ(42, object2.WrapperClassId()); |
19351 | 19299 |
19352 Visitor42 visitor(&object2); | 19300 Visitor42 visitor(&object2); |
19353 v8::V8::VisitHandlesForPartialDependence(isolate, &visitor); | 19301 isolate->VisitHandlesForPartialDependence(&visitor); |
19354 CHECK_EQ(1, visitor.counter_); | 19302 CHECK_EQ(1, visitor.counter_); |
19355 | 19303 |
19356 object1.Reset(); | 19304 object1.Reset(); |
19357 object2.Reset(); | 19305 object2.Reset(); |
19358 } | 19306 } |
19359 | 19307 |
19360 | 19308 |
19361 TEST(RegExp) { | 19309 TEST(RegExp) { |
19362 i::FLAG_harmony_regexps = true; | 19310 i::FLAG_harmony_regexps = true; |
19363 i::FLAG_harmony_unicode_regexps = true; | 19311 i::FLAG_harmony_unicode_regexps = true; |
19364 LocalContext context; | 19312 LocalContext context; |
19365 v8::HandleScope scope(context->GetIsolate()); | 19313 v8::HandleScope scope(context->GetIsolate()); |
19366 | 19314 |
19367 v8::Local<v8::RegExp> re = v8::RegExp::New(v8_str("foo"), v8::RegExp::kNone); | 19315 v8::Local<v8::RegExp> re = |
19316 v8::RegExp::New(context.local(), v8_str("foo"), v8::RegExp::kNone) | |
19317 .ToLocalChecked(); | |
19368 CHECK(re->IsRegExp()); | 19318 CHECK(re->IsRegExp()); |
19369 CHECK(re->GetSource()->Equals(v8_str("foo"))); | 19319 CHECK(re->GetSource()->Equals(context.local(), v8_str("foo")).FromJust()); |
19370 CHECK_EQ(v8::RegExp::kNone, re->GetFlags()); | 19320 CHECK_EQ(v8::RegExp::kNone, re->GetFlags()); |
19371 | 19321 |
19372 re = v8::RegExp::New(v8_str("bar"), | 19322 re = v8::RegExp::New(context.local(), v8_str("bar"), |
19373 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase | | 19323 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase | |
19374 v8::RegExp::kGlobal)); | 19324 v8::RegExp::kGlobal)) |
19325 .ToLocalChecked(); | |
19375 CHECK(re->IsRegExp()); | 19326 CHECK(re->IsRegExp()); |
19376 CHECK(re->GetSource()->Equals(v8_str("bar"))); | 19327 CHECK(re->GetSource()->Equals(context.local(), v8_str("bar")).FromJust()); |
19377 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kGlobal, | 19328 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kGlobal, |
19378 static_cast<int>(re->GetFlags())); | 19329 static_cast<int>(re->GetFlags())); |
19379 | 19330 |
19380 re = v8::RegExp::New(v8_str("baz"), | 19331 re = v8::RegExp::New(context.local(), v8_str("baz"), |
19381 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase | | 19332 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase | |
19382 v8::RegExp::kMultiline)); | 19333 v8::RegExp::kMultiline)) |
19334 .ToLocalChecked(); | |
19383 CHECK(re->IsRegExp()); | 19335 CHECK(re->IsRegExp()); |
19384 CHECK(re->GetSource()->Equals(v8_str("baz"))); | 19336 CHECK(re->GetSource()->Equals(context.local(), v8_str("baz")).FromJust()); |
19385 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline, | 19337 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline, |
19386 static_cast<int>(re->GetFlags())); | 19338 static_cast<int>(re->GetFlags())); |
19387 | 19339 |
19388 re = v8::RegExp::New(v8_str("baz"), | 19340 re = v8::RegExp::New(context.local(), v8_str("baz"), |
19389 static_cast<v8::RegExp::Flags>(v8::RegExp::kUnicode | | 19341 static_cast<v8::RegExp::Flags>(v8::RegExp::kUnicode | |
19390 v8::RegExp::kSticky)); | 19342 v8::RegExp::kSticky)) |
19343 .ToLocalChecked(); | |
19391 CHECK(re->IsRegExp()); | 19344 CHECK(re->IsRegExp()); |
19392 CHECK(re->GetSource()->Equals(v8_str("baz"))); | 19345 CHECK(re->GetSource()->Equals(context.local(), v8_str("baz")).FromJust()); |
19393 CHECK_EQ(v8::RegExp::kUnicode | v8::RegExp::kSticky, | 19346 CHECK_EQ(v8::RegExp::kUnicode | v8::RegExp::kSticky, |
19394 static_cast<int>(re->GetFlags())); | 19347 static_cast<int>(re->GetFlags())); |
19395 | 19348 |
19396 re = CompileRun("/quux/").As<v8::RegExp>(); | 19349 re = CompileRun("/quux/").As<v8::RegExp>(); |
19397 CHECK(re->IsRegExp()); | 19350 CHECK(re->IsRegExp()); |
19398 CHECK(re->GetSource()->Equals(v8_str("quux"))); | 19351 CHECK(re->GetSource()->Equals(context.local(), v8_str("quux")).FromJust()); |
19399 CHECK_EQ(v8::RegExp::kNone, re->GetFlags()); | 19352 CHECK_EQ(v8::RegExp::kNone, re->GetFlags()); |
19400 | 19353 |
19401 re = CompileRun("/quux/gm").As<v8::RegExp>(); | 19354 re = CompileRun("/quux/gm").As<v8::RegExp>(); |
19402 CHECK(re->IsRegExp()); | 19355 CHECK(re->IsRegExp()); |
19403 CHECK(re->GetSource()->Equals(v8_str("quux"))); | 19356 CHECK(re->GetSource()->Equals(context.local(), v8_str("quux")).FromJust()); |
19404 CHECK_EQ(v8::RegExp::kGlobal | v8::RegExp::kMultiline, | 19357 CHECK_EQ(v8::RegExp::kGlobal | v8::RegExp::kMultiline, |
19405 static_cast<int>(re->GetFlags())); | 19358 static_cast<int>(re->GetFlags())); |
19406 | 19359 |
19407 // Override the RegExp constructor and check the API constructor | 19360 // Override the RegExp constructor and check the API constructor |
19408 // still works. | 19361 // still works. |
19409 CompileRun("RegExp = function() {}"); | 19362 CompileRun("RegExp = function() {}"); |
19410 | 19363 |
19411 re = v8::RegExp::New(v8_str("foobar"), v8::RegExp::kNone); | 19364 re = v8::RegExp::New(context.local(), v8_str("foobar"), v8::RegExp::kNone) |
19365 .ToLocalChecked(); | |
19412 CHECK(re->IsRegExp()); | 19366 CHECK(re->IsRegExp()); |
19413 CHECK(re->GetSource()->Equals(v8_str("foobar"))); | 19367 CHECK(re->GetSource()->Equals(context.local(), v8_str("foobar")).FromJust()); |
19414 CHECK_EQ(v8::RegExp::kNone, re->GetFlags()); | 19368 CHECK_EQ(v8::RegExp::kNone, re->GetFlags()); |
19415 | 19369 |
19416 re = v8::RegExp::New(v8_str("foobarbaz"), | 19370 re = v8::RegExp::New(context.local(), v8_str("foobarbaz"), |
19417 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase | | 19371 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase | |
19418 v8::RegExp::kMultiline)); | 19372 v8::RegExp::kMultiline)) |
19373 .ToLocalChecked(); | |
19419 CHECK(re->IsRegExp()); | 19374 CHECK(re->IsRegExp()); |
19420 CHECK(re->GetSource()->Equals(v8_str("foobarbaz"))); | 19375 CHECK( |
19376 re->GetSource()->Equals(context.local(), v8_str("foobarbaz")).FromJust()); | |
19421 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline, | 19377 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline, |
19422 static_cast<int>(re->GetFlags())); | 19378 static_cast<int>(re->GetFlags())); |
19423 | 19379 |
19424 CHECK(context->Global()->Set(context.local(), v8_str("re"), re).FromJust()); | 19380 CHECK(context->Global()->Set(context.local(), v8_str("re"), re).FromJust()); |
19425 ExpectTrue("re.test('FoobarbaZ')"); | 19381 ExpectTrue("re.test('FoobarbaZ')"); |
19426 | 19382 |
19427 // RegExps are objects on which you can set properties. | 19383 // RegExps are objects on which you can set properties. |
19428 re->Set(v8_str("property"), v8::Integer::New(context->GetIsolate(), 32)); | 19384 re->Set(context.local(), v8_str("property"), |
19385 v8::Integer::New(context->GetIsolate(), 32)) | |
19386 .FromJust(); | |
19429 v8::Local<v8::Value> value(CompileRun("re.property")); | 19387 v8::Local<v8::Value> value(CompileRun("re.property")); |
19430 CHECK_EQ(32, value->Int32Value(context.local()).FromJust()); | 19388 CHECK_EQ(32, value->Int32Value(context.local()).FromJust()); |
19431 | 19389 |
19432 v8::TryCatch try_catch(context->GetIsolate()); | 19390 v8::TryCatch try_catch(context->GetIsolate()); |
19433 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone); | 19391 CHECK(v8::RegExp::New(context.local(), v8_str("foo["), v8::RegExp::kNone) |
19434 CHECK(re.IsEmpty()); | 19392 .IsEmpty()); |
19435 CHECK(try_catch.HasCaught()); | 19393 CHECK(try_catch.HasCaught()); |
19436 CHECK(context->Global() | 19394 CHECK(context->Global() |
19437 ->Set(context.local(), v8_str("ex"), try_catch.Exception()) | 19395 ->Set(context.local(), v8_str("ex"), try_catch.Exception()) |
19438 .FromJust()); | 19396 .FromJust()); |
19439 ExpectTrue("ex instanceof SyntaxError"); | 19397 ExpectTrue("ex instanceof SyntaxError"); |
19440 } | 19398 } |
19441 | 19399 |
19442 | 19400 |
19443 THREADED_TEST(Equals) { | 19401 THREADED_TEST(Equals) { |
19444 LocalContext localContext; | 19402 LocalContext localContext; |
19445 v8::HandleScope handleScope(localContext->GetIsolate()); | 19403 v8::HandleScope handleScope(localContext->GetIsolate()); |
19446 | 19404 |
19447 v8::Local<v8::Object> globalProxy = localContext->Global(); | 19405 v8::Local<v8::Object> globalProxy = localContext->Global(); |
19448 v8::Local<Value> global = globalProxy->GetPrototype(); | 19406 v8::Local<Value> global = globalProxy->GetPrototype(); |
19449 | 19407 |
19450 CHECK(global->StrictEquals(global)); | 19408 CHECK(global->StrictEquals(global)); |
19451 CHECK(!global->StrictEquals(globalProxy)); | 19409 CHECK(!global->StrictEquals(globalProxy)); |
19452 CHECK(!globalProxy->StrictEquals(global)); | 19410 CHECK(!globalProxy->StrictEquals(global)); |
19453 CHECK(globalProxy->StrictEquals(globalProxy)); | 19411 CHECK(globalProxy->StrictEquals(globalProxy)); |
19454 | 19412 |
19455 CHECK(global->Equals(global)); | 19413 CHECK(global->Equals(localContext.local(), global).FromJust()); |
19456 CHECK(!global->Equals(globalProxy)); | 19414 CHECK(!global->Equals(localContext.local(), globalProxy).FromJust()); |
19457 CHECK(!globalProxy->Equals(global)); | 19415 CHECK(!globalProxy->Equals(localContext.local(), global).FromJust()); |
19458 CHECK(globalProxy->Equals(globalProxy)); | 19416 CHECK(globalProxy->Equals(localContext.local(), globalProxy).FromJust()); |
19459 } | 19417 } |
19460 | 19418 |
19461 | 19419 |
19462 static void Getter(v8::Local<v8::Name> property, | 19420 static void Getter(v8::Local<v8::Name> property, |
19463 const v8::PropertyCallbackInfo<v8::Value>& info) { | 19421 const v8::PropertyCallbackInfo<v8::Value>& info) { |
19464 info.GetReturnValue().Set(v8_str("42!")); | 19422 info.GetReturnValue().Set(v8_str("42!")); |
19465 } | 19423 } |
19466 | 19424 |
19467 | 19425 |
19468 static void Enumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { | 19426 static void Enumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { |
19469 v8::Local<v8::Array> result = v8::Array::New(info.GetIsolate()); | 19427 v8::Local<v8::Array> result = v8::Array::New(info.GetIsolate()); |
19470 result->Set(0, v8_str("universalAnswer")); | 19428 result->Set(info.GetIsolate()->GetCurrentContext(), 0, |
19429 v8_str("universalAnswer")) | |
19430 .FromJust(); | |
19471 info.GetReturnValue().Set(result); | 19431 info.GetReturnValue().Set(result); |
19472 } | 19432 } |
19473 | 19433 |
19474 | 19434 |
19475 TEST(NamedEnumeratorAndForIn) { | 19435 TEST(NamedEnumeratorAndForIn) { |
19476 LocalContext context; | 19436 LocalContext context; |
19477 v8::Isolate* isolate = context->GetIsolate(); | 19437 v8::Isolate* isolate = context->GetIsolate(); |
19478 v8::HandleScope handle_scope(isolate); | 19438 v8::HandleScope handle_scope(isolate); |
19479 v8::Context::Scope context_scope(context.local()); | 19439 v8::Context::Scope context_scope(context.local()); |
19480 | 19440 |
19481 v8::Local<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(isolate); | 19441 v8::Local<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(isolate); |
19482 tmpl->SetHandler(v8::NamedPropertyHandlerConfiguration(Getter, NULL, NULL, | 19442 tmpl->SetHandler(v8::NamedPropertyHandlerConfiguration(Getter, NULL, NULL, |
19483 NULL, Enumerator)); | 19443 NULL, Enumerator)); |
19484 CHECK(context->Global() | 19444 CHECK(context->Global() |
19485 ->Set(context.local(), v8_str("o"), | 19445 ->Set(context.local(), v8_str("o"), |
19486 tmpl->NewInstance(context.local()).ToLocalChecked()) | 19446 tmpl->NewInstance(context.local()).ToLocalChecked()) |
19487 .FromJust()); | 19447 .FromJust()); |
19488 v8::Local<v8::Array> result = v8::Local<v8::Array>::Cast( | 19448 v8::Local<v8::Array> result = v8::Local<v8::Array>::Cast( |
19489 CompileRun("var result = []; for (var k in o) result.push(k); result")); | 19449 CompileRun("var result = []; for (var k in o) result.push(k); result")); |
19490 CHECK_EQ(1u, result->Length()); | 19450 CHECK_EQ(1u, result->Length()); |
19491 CHECK(v8_str("universalAnswer")->Equals(result->Get(0))); | 19451 CHECK(v8_str("universalAnswer") |
19452 ->Equals(context.local(), | |
19453 result->Get(context.local(), 0).ToLocalChecked()) | |
19454 .FromJust()); | |
19492 } | 19455 } |
19493 | 19456 |
19494 | 19457 |
19495 TEST(DefinePropertyPostDetach) { | 19458 TEST(DefinePropertyPostDetach) { |
19496 LocalContext context; | 19459 LocalContext context; |
19497 v8::HandleScope scope(context->GetIsolate()); | 19460 v8::HandleScope scope(context->GetIsolate()); |
19498 v8::Local<v8::Object> proxy = context->Global(); | 19461 v8::Local<v8::Object> proxy = context->Global(); |
19499 v8::Local<v8::Function> define_property = | 19462 v8::Local<v8::Function> define_property = |
19500 CompileRun( | 19463 CompileRun( |
19501 "(function() {" | 19464 "(function() {" |
19502 " Object.defineProperty(" | 19465 " Object.defineProperty(" |
19503 " this," | 19466 " this," |
19504 " 1," | 19467 " 1," |
19505 " { configurable: true, enumerable: true, value: 3 });" | 19468 " { configurable: true, enumerable: true, value: 3 });" |
19506 "})") | 19469 "})") |
19507 .As<Function>(); | 19470 .As<Function>(); |
19508 context->DetachGlobal(); | 19471 context->DetachGlobal(); |
19509 define_property->Call(proxy, 0, NULL); | 19472 CHECK(define_property->Call(context.local(), proxy, 0, NULL).IsEmpty()); |
19510 } | 19473 } |
19511 | 19474 |
19512 | 19475 |
19513 static void InstallContextId(v8::Local<Context> context, int id) { | 19476 static void InstallContextId(v8::Local<Context> context, int id) { |
19514 Context::Scope scope(context); | 19477 Context::Scope scope(context); |
19515 CHECK(CompileRun("Object.prototype") | 19478 CHECK(CompileRun("Object.prototype") |
19516 .As<Object>() | 19479 .As<Object>() |
19517 ->Set(context, v8_str("context_id"), | 19480 ->Set(context, v8_str("context_id"), |
19518 v8::Integer::New(context->GetIsolate(), id)) | 19481 v8::Integer::New(context->GetIsolate(), id)) |
19519 .FromJust()); | 19482 .FromJust()); |
19520 } | 19483 } |
19521 | 19484 |
19522 | 19485 |
19523 static void CheckContextId(v8::Local<Object> object, int expected) { | 19486 static void CheckContextId(v8::Local<Object> object, int expected) { |
19524 CHECK_EQ(expected, object->Get(v8_str("context_id")) | 19487 v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext(); |
19525 ->Int32Value(CcTest::isolate()->GetCurrentContext()) | 19488 CHECK_EQ(expected, object->Get(context, v8_str("context_id")) |
19489 .ToLocalChecked() | |
19490 ->Int32Value(context) | |
19526 .FromJust()); | 19491 .FromJust()); |
19527 } | 19492 } |
19528 | 19493 |
19529 | 19494 |
19530 THREADED_TEST(CreationContext) { | 19495 THREADED_TEST(CreationContext) { |
19531 v8::Isolate* isolate = CcTest::isolate(); | 19496 v8::Isolate* isolate = CcTest::isolate(); |
19532 HandleScope handle_scope(isolate); | 19497 HandleScope handle_scope(isolate); |
19533 Local<Context> context1 = Context::New(isolate); | 19498 Local<Context> context1 = Context::New(isolate); |
19534 InstallContextId(context1, 1); | 19499 InstallContextId(context1, 1); |
19535 Local<Context> context2 = Context::New(isolate); | 19500 Local<Context> context2 = Context::New(isolate); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
19635 | 19600 |
19636 void HasOwnPropertyIndexedPropertyGetter( | 19601 void HasOwnPropertyIndexedPropertyGetter( |
19637 uint32_t index, | 19602 uint32_t index, |
19638 const v8::PropertyCallbackInfo<v8::Value>& info) { | 19603 const v8::PropertyCallbackInfo<v8::Value>& info) { |
19639 if (index == 42) info.GetReturnValue().Set(v8_str("yes")); | 19604 if (index == 42) info.GetReturnValue().Set(v8_str("yes")); |
19640 } | 19605 } |
19641 | 19606 |
19642 | 19607 |
19643 void HasOwnPropertyNamedPropertyGetter( | 19608 void HasOwnPropertyNamedPropertyGetter( |
19644 Local<Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) { | 19609 Local<Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) { |
19645 if (property->Equals(v8_str("foo"))) info.GetReturnValue().Set(v8_str("yes")); | 19610 if (property->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("foo")) |
19611 .FromJust()) { | |
19612 info.GetReturnValue().Set(v8_str("yes")); | |
19613 } | |
19646 } | 19614 } |
19647 | 19615 |
19648 | 19616 |
19649 void HasOwnPropertyIndexedPropertyQuery( | 19617 void HasOwnPropertyIndexedPropertyQuery( |
19650 uint32_t index, const v8::PropertyCallbackInfo<v8::Integer>& info) { | 19618 uint32_t index, const v8::PropertyCallbackInfo<v8::Integer>& info) { |
19651 if (index == 42) info.GetReturnValue().Set(1); | 19619 if (index == 42) info.GetReturnValue().Set(1); |
19652 } | 19620 } |
19653 | 19621 |
19654 | 19622 |
19655 void HasOwnPropertyNamedPropertyQuery( | 19623 void HasOwnPropertyNamedPropertyQuery( |
19656 Local<Name> property, const v8::PropertyCallbackInfo<v8::Integer>& info) { | 19624 Local<Name> property, const v8::PropertyCallbackInfo<v8::Integer>& info) { |
19657 if (property->Equals(v8_str("foo"))) info.GetReturnValue().Set(1); | 19625 if (property->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("foo")) |
19626 .FromJust()) { | |
19627 info.GetReturnValue().Set(1); | |
19628 } | |
19658 } | 19629 } |
19659 | 19630 |
19660 | 19631 |
19661 void HasOwnPropertyNamedPropertyQuery2( | 19632 void HasOwnPropertyNamedPropertyQuery2( |
19662 Local<Name> property, const v8::PropertyCallbackInfo<v8::Integer>& info) { | 19633 Local<Name> property, const v8::PropertyCallbackInfo<v8::Integer>& info) { |
19663 if (property->Equals(v8_str("bar"))) info.GetReturnValue().Set(1); | 19634 if (property->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("bar")) |
19635 .FromJust()) { | |
19636 info.GetReturnValue().Set(1); | |
19637 } | |
19664 } | 19638 } |
19665 | 19639 |
19666 | 19640 |
19667 void HasOwnPropertyAccessorGetter( | 19641 void HasOwnPropertyAccessorGetter( |
19668 Local<String> property, | 19642 Local<String> property, |
19669 const v8::PropertyCallbackInfo<v8::Value>& info) { | 19643 const v8::PropertyCallbackInfo<v8::Value>& info) { |
19670 info.GetReturnValue().Set(v8_str("yes")); | 19644 info.GetReturnValue().Set(v8_str("yes")); |
19671 } | 19645 } |
19672 | 19646 |
19673 | 19647 |
19674 TEST(HasOwnProperty) { | 19648 TEST(HasOwnProperty) { |
19675 LocalContext env; | 19649 LocalContext env; |
19676 v8::Isolate* isolate = env->GetIsolate(); | 19650 v8::Isolate* isolate = env->GetIsolate(); |
19677 v8::HandleScope scope(isolate); | 19651 v8::HandleScope scope(isolate); |
19678 { // Check normal properties and defined getters. | 19652 { // Check normal properties and defined getters. |
19679 Local<Value> value = CompileRun( | 19653 Local<Value> value = CompileRun( |
19680 "function Foo() {" | 19654 "function Foo() {" |
19681 " this.foo = 11;" | 19655 " this.foo = 11;" |
19682 " this.__defineGetter__('baz', function() { return 1; });" | 19656 " this.__defineGetter__('baz', function() { return 1; });" |
19683 "};" | 19657 "};" |
19684 "function Bar() { " | 19658 "function Bar() { " |
19685 " this.bar = 13;" | 19659 " this.bar = 13;" |
19686 " this.__defineGetter__('bla', function() { return 2; });" | 19660 " this.__defineGetter__('bla', function() { return 2; });" |
19687 "};" | 19661 "};" |
19688 "Bar.prototype = new Foo();" | 19662 "Bar.prototype = new Foo();" |
19689 "new Bar();"); | 19663 "new Bar();"); |
19690 CHECK(value->IsObject()); | 19664 CHECK(value->IsObject()); |
19691 Local<Object> object = value->ToObject(isolate); | 19665 Local<Object> object = value->ToObject(env.local()).ToLocalChecked(); |
19692 CHECK(object->Has(v8_str("foo"))); | 19666 CHECK(object->Has(env.local(), v8_str("foo")).FromJust()); |
19693 CHECK(!object->HasOwnProperty(v8_str("foo"))); | 19667 CHECK(!object->HasOwnProperty(env.local(), v8_str("foo")).FromJust()); |
19694 CHECK(object->HasOwnProperty(v8_str("bar"))); | 19668 CHECK(object->HasOwnProperty(env.local(), v8_str("bar")).FromJust()); |
19695 CHECK(object->Has(v8_str("baz"))); | 19669 CHECK(object->Has(env.local(), v8_str("baz")).FromJust()); |
19696 CHECK(!object->HasOwnProperty(v8_str("baz"))); | 19670 CHECK(!object->HasOwnProperty(env.local(), v8_str("baz")).FromJust()); |
19697 CHECK(object->HasOwnProperty(v8_str("bla"))); | 19671 CHECK(object->HasOwnProperty(env.local(), v8_str("bla")).FromJust()); |
19698 } | 19672 } |
19699 { // Check named getter interceptors. | 19673 { // Check named getter interceptors. |
19700 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 19674 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19701 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( | 19675 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
19702 HasOwnPropertyNamedPropertyGetter)); | 19676 HasOwnPropertyNamedPropertyGetter)); |
19703 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked(); | 19677 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked(); |
19704 CHECK(!instance->HasOwnProperty(v8_str("42"))); | 19678 CHECK(!instance->HasOwnProperty(env.local(), v8_str("42")).FromJust()); |
19705 CHECK(instance->HasOwnProperty(v8_str("foo"))); | 19679 CHECK(instance->HasOwnProperty(env.local(), v8_str("foo")).FromJust()); |
19706 CHECK(!instance->HasOwnProperty(v8_str("bar"))); | 19680 CHECK(!instance->HasOwnProperty(env.local(), v8_str("bar")).FromJust()); |
19707 } | 19681 } |
19708 { // Check indexed getter interceptors. | 19682 { // Check indexed getter interceptors. |
19709 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 19683 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19710 templ->SetHandler(v8::IndexedPropertyHandlerConfiguration( | 19684 templ->SetHandler(v8::IndexedPropertyHandlerConfiguration( |
19711 HasOwnPropertyIndexedPropertyGetter)); | 19685 HasOwnPropertyIndexedPropertyGetter)); |
19712 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked(); | 19686 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked(); |
19713 CHECK(instance->HasOwnProperty(v8_str("42"))); | 19687 CHECK(instance->HasOwnProperty(env.local(), v8_str("42")).FromJust()); |
19714 CHECK(!instance->HasOwnProperty(v8_str("43"))); | 19688 CHECK(!instance->HasOwnProperty(env.local(), v8_str("43")).FromJust()); |
19715 CHECK(!instance->HasOwnProperty(v8_str("foo"))); | 19689 CHECK(!instance->HasOwnProperty(env.local(), v8_str("foo")).FromJust()); |
19716 } | 19690 } |
19717 { // Check named query interceptors. | 19691 { // Check named query interceptors. |
19718 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 19692 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19719 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( | 19693 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
19720 0, 0, HasOwnPropertyNamedPropertyQuery)); | 19694 0, 0, HasOwnPropertyNamedPropertyQuery)); |
19721 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked(); | 19695 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked(); |
19722 CHECK(instance->HasOwnProperty(v8_str("foo"))); | 19696 CHECK(instance->HasOwnProperty(env.local(), v8_str("foo")).FromJust()); |
19723 CHECK(!instance->HasOwnProperty(v8_str("bar"))); | 19697 CHECK(!instance->HasOwnProperty(env.local(), v8_str("bar")).FromJust()); |
19724 } | 19698 } |
19725 { // Check indexed query interceptors. | 19699 { // Check indexed query interceptors. |
19726 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 19700 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19727 templ->SetHandler(v8::IndexedPropertyHandlerConfiguration( | 19701 templ->SetHandler(v8::IndexedPropertyHandlerConfiguration( |
19728 0, 0, HasOwnPropertyIndexedPropertyQuery)); | 19702 0, 0, HasOwnPropertyIndexedPropertyQuery)); |
19729 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked(); | 19703 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked(); |
19730 CHECK(instance->HasOwnProperty(v8_str("42"))); | 19704 CHECK(instance->HasOwnProperty(env.local(), v8_str("42")).FromJust()); |
19731 CHECK(!instance->HasOwnProperty(v8_str("41"))); | 19705 CHECK(!instance->HasOwnProperty(env.local(), v8_str("41")).FromJust()); |
19732 } | 19706 } |
19733 { // Check callbacks. | 19707 { // Check callbacks. |
19734 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 19708 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19735 templ->SetAccessor(v8_str("foo"), HasOwnPropertyAccessorGetter); | 19709 templ->SetAccessor(v8_str("foo"), HasOwnPropertyAccessorGetter); |
19736 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked(); | 19710 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked(); |
19737 CHECK(instance->HasOwnProperty(v8_str("foo"))); | 19711 CHECK(instance->HasOwnProperty(env.local(), v8_str("foo")).FromJust()); |
19738 CHECK(!instance->HasOwnProperty(v8_str("bar"))); | 19712 CHECK(!instance->HasOwnProperty(env.local(), v8_str("bar")).FromJust()); |
19739 } | 19713 } |
19740 { // Check that query wins on disagreement. | 19714 { // Check that query wins on disagreement. |
19741 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 19715 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19742 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( | 19716 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
19743 HasOwnPropertyNamedPropertyGetter, 0, | 19717 HasOwnPropertyNamedPropertyGetter, 0, |
19744 HasOwnPropertyNamedPropertyQuery2)); | 19718 HasOwnPropertyNamedPropertyQuery2)); |
19745 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked(); | 19719 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked(); |
19746 CHECK(!instance->HasOwnProperty(v8_str("foo"))); | 19720 CHECK(!instance->HasOwnProperty(env.local(), v8_str("foo")).FromJust()); |
19747 CHECK(instance->HasOwnProperty(v8_str("bar"))); | 19721 CHECK(instance->HasOwnProperty(env.local(), v8_str("bar")).FromJust()); |
19748 } | 19722 } |
19749 } | 19723 } |
19750 | 19724 |
19751 | 19725 |
19752 TEST(IndexedInterceptorWithStringProto) { | 19726 TEST(IndexedInterceptorWithStringProto) { |
19753 v8::Isolate* isolate = CcTest::isolate(); | 19727 v8::Isolate* isolate = CcTest::isolate(); |
19754 v8::HandleScope scope(isolate); | 19728 v8::HandleScope scope(isolate); |
19755 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 19729 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19756 templ->SetHandler(v8::IndexedPropertyHandlerConfiguration( | 19730 templ->SetHandler(v8::IndexedPropertyHandlerConfiguration( |
19757 NULL, NULL, HasOwnPropertyIndexedPropertyQuery)); | 19731 NULL, NULL, HasOwnPropertyIndexedPropertyQuery)); |
19758 LocalContext context; | 19732 LocalContext context; |
19759 CHECK(context->Global() | 19733 CHECK(context->Global() |
19760 ->Set(context.local(), v8_str("obj"), | 19734 ->Set(context.local(), v8_str("obj"), |
19761 templ->NewInstance(context.local()).ToLocalChecked()) | 19735 templ->NewInstance(context.local()).ToLocalChecked()) |
19762 .FromJust()); | 19736 .FromJust()); |
19763 CompileRun("var s = new String('foobar'); obj.__proto__ = s;"); | 19737 CompileRun("var s = new String('foobar'); obj.__proto__ = s;"); |
19764 // These should be intercepted. | 19738 // These should be intercepted. |
19765 CHECK(CompileRun("42 in obj")->BooleanValue()); | 19739 CHECK(CompileRun("42 in obj")->BooleanValue(context.local()).FromJust()); |
19766 CHECK(CompileRun("'42' in obj")->BooleanValue()); | 19740 CHECK(CompileRun("'42' in obj")->BooleanValue(context.local()).FromJust()); |
19767 // These should fall through to the String prototype. | 19741 // These should fall through to the String prototype. |
19768 CHECK(CompileRun("0 in obj")->BooleanValue()); | 19742 CHECK(CompileRun("0 in obj")->BooleanValue(context.local()).FromJust()); |
19769 CHECK(CompileRun("'0' in obj")->BooleanValue()); | 19743 CHECK(CompileRun("'0' in obj")->BooleanValue(context.local()).FromJust()); |
19770 // And these should both fail. | 19744 // And these should both fail. |
19771 CHECK(!CompileRun("32 in obj")->BooleanValue()); | 19745 CHECK(!CompileRun("32 in obj")->BooleanValue(context.local()).FromJust()); |
19772 CHECK(!CompileRun("'32' in obj")->BooleanValue()); | 19746 CHECK(!CompileRun("'32' in obj")->BooleanValue(context.local()).FromJust()); |
19773 } | 19747 } |
19774 | 19748 |
19775 | 19749 |
19776 void CheckCodeGenerationAllowed() { | 19750 void CheckCodeGenerationAllowed() { |
19777 Local<v8::Context> context = CcTest::isolate()->GetCurrentContext(); | 19751 Local<v8::Context> context = CcTest::isolate()->GetCurrentContext(); |
19778 Local<Value> result = CompileRun("eval('42')"); | 19752 Local<Value> result = CompileRun("eval('42')"); |
19779 CHECK_EQ(42, result->Int32Value(context).FromJust()); | 19753 CHECK_EQ(42, result->Int32Value(context).FromJust()); |
19780 result = CompileRun("(function(e) { return e('42'); })(eval)"); | 19754 result = CompileRun("(function(e) { return e('42'); })(eval)"); |
19781 CHECK_EQ(42, result->Int32Value(context).FromJust()); | 19755 CHECK_EQ(42, result->Int32Value(context).FromJust()); |
19782 result = CompileRun("var f = new Function('return 42'); f()"); | 19756 result = CompileRun("var f = new Function('return 42'); f()"); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
19827 context->AllowCodeGenerationFromStrings(false); | 19801 context->AllowCodeGenerationFromStrings(false); |
19828 CHECK(!context->IsCodeGenerationFromStringsAllowed()); | 19802 CHECK(!context->IsCodeGenerationFromStringsAllowed()); |
19829 CheckCodeGenerationDisallowed(); | 19803 CheckCodeGenerationDisallowed(); |
19830 | 19804 |
19831 // Allow again. | 19805 // Allow again. |
19832 context->AllowCodeGenerationFromStrings(true); | 19806 context->AllowCodeGenerationFromStrings(true); |
19833 CheckCodeGenerationAllowed(); | 19807 CheckCodeGenerationAllowed(); |
19834 | 19808 |
19835 // Disallow but setting a global callback that will allow the calls. | 19809 // Disallow but setting a global callback that will allow the calls. |
19836 context->AllowCodeGenerationFromStrings(false); | 19810 context->AllowCodeGenerationFromStrings(false); |
19837 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationAllowed); | 19811 context->GetIsolate()->SetAllowCodeGenerationFromStringsCallback( |
19812 &CodeGenerationAllowed); | |
19838 CHECK(!context->IsCodeGenerationFromStringsAllowed()); | 19813 CHECK(!context->IsCodeGenerationFromStringsAllowed()); |
19839 CheckCodeGenerationAllowed(); | 19814 CheckCodeGenerationAllowed(); |
19840 | 19815 |
19841 // Set a callback that disallows the code generation. | 19816 // Set a callback that disallows the code generation. |
19842 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed); | 19817 context->GetIsolate()->SetAllowCodeGenerationFromStringsCallback( |
19818 &CodeGenerationDisallowed); | |
19843 CHECK(!context->IsCodeGenerationFromStringsAllowed()); | 19819 CHECK(!context->IsCodeGenerationFromStringsAllowed()); |
19844 CheckCodeGenerationDisallowed(); | 19820 CheckCodeGenerationDisallowed(); |
19845 } | 19821 } |
19846 | 19822 |
19847 | 19823 |
19848 TEST(SetErrorMessageForCodeGenFromStrings) { | 19824 TEST(SetErrorMessageForCodeGenFromStrings) { |
19849 LocalContext context; | 19825 LocalContext context; |
19850 v8::HandleScope scope(context->GetIsolate()); | 19826 v8::HandleScope scope(context->GetIsolate()); |
19851 TryCatch try_catch(context->GetIsolate()); | 19827 TryCatch try_catch(context->GetIsolate()); |
19852 | 19828 |
19853 Local<String> message = v8_str("Message"); | 19829 Local<String> message = v8_str("Message"); |
19854 Local<String> expected_message = v8_str("Uncaught EvalError: Message"); | 19830 Local<String> expected_message = v8_str("Uncaught EvalError: Message"); |
19855 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed); | 19831 context->GetIsolate()->SetAllowCodeGenerationFromStringsCallback( |
19832 &CodeGenerationDisallowed); | |
19856 context->AllowCodeGenerationFromStrings(false); | 19833 context->AllowCodeGenerationFromStrings(false); |
19857 context->SetErrorMessageForCodeGenerationFromStrings(message); | 19834 context->SetErrorMessageForCodeGenerationFromStrings(message); |
19858 Local<Value> result = CompileRun("eval('42')"); | 19835 Local<Value> result = CompileRun("eval('42')"); |
19859 CHECK(result.IsEmpty()); | 19836 CHECK(result.IsEmpty()); |
19860 CHECK(try_catch.HasCaught()); | 19837 CHECK(try_catch.HasCaught()); |
19861 Local<String> actual_message = try_catch.Message()->Get(); | 19838 Local<String> actual_message = try_catch.Message()->Get(); |
19862 CHECK(expected_message->Equals(actual_message)); | 19839 CHECK(expected_message->Equals(context.local(), actual_message).FromJust()); |
19863 } | 19840 } |
19864 | 19841 |
19865 | 19842 |
19866 static void NonObjectThis(const v8::FunctionCallbackInfo<v8::Value>& args) { | 19843 static void NonObjectThis(const v8::FunctionCallbackInfo<v8::Value>& args) { |
19867 } | 19844 } |
19868 | 19845 |
19869 | 19846 |
19870 THREADED_TEST(CallAPIFunctionOnNonObject) { | 19847 THREADED_TEST(CallAPIFunctionOnNonObject) { |
19871 LocalContext context; | 19848 LocalContext context; |
19872 v8::Isolate* isolate = context->GetIsolate(); | 19849 v8::Isolate* isolate = context->GetIsolate(); |
(...skipping 12 matching lines...) Expand all Loading... | |
19885 | 19862 |
19886 // Regression test for issue 1470. | 19863 // Regression test for issue 1470. |
19887 THREADED_TEST(ReadOnlyIndexedProperties) { | 19864 THREADED_TEST(ReadOnlyIndexedProperties) { |
19888 v8::Isolate* isolate = CcTest::isolate(); | 19865 v8::Isolate* isolate = CcTest::isolate(); |
19889 v8::HandleScope scope(isolate); | 19866 v8::HandleScope scope(isolate); |
19890 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 19867 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19891 | 19868 |
19892 LocalContext context; | 19869 LocalContext context; |
19893 Local<v8::Object> obj = templ->NewInstance(context.local()).ToLocalChecked(); | 19870 Local<v8::Object> obj = templ->NewInstance(context.local()).ToLocalChecked(); |
19894 CHECK(context->Global()->Set(context.local(), v8_str("obj"), obj).FromJust()); | 19871 CHECK(context->Global()->Set(context.local(), v8_str("obj"), obj).FromJust()); |
19895 obj->ForceSet(v8_str("1"), v8_str("DONT_CHANGE"), v8::ReadOnly); | 19872 obj->DefineOwnProperty(context.local(), v8_str("1"), v8_str("DONT_CHANGE"), |
19896 obj->Set(v8_str("1"), v8_str("foobar")); | 19873 v8::ReadOnly) |
19897 CHECK(v8_str("DONT_CHANGE")->Equals(obj->Get(v8_str("1")))); | 19874 .FromJust(); |
19898 obj->ForceSet(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly); | 19875 obj->Set(context.local(), v8_str("1"), v8_str("foobar")).FromJust(); |
19899 obj->Set(v8_num(2), v8_str("foobar")); | 19876 CHECK(v8_str("DONT_CHANGE") |
19900 CHECK(v8_str("DONT_CHANGE")->Equals(obj->Get(v8_num(2)))); | 19877 ->Equals(context.local(), |
19878 obj->Get(context.local(), v8_str("1")).ToLocalChecked()) | |
19879 .FromJust()); | |
19880 obj->DefineOwnProperty(context.local(), v8_str("2"), v8_str("DONT_CHANGE"), | |
19881 v8::ReadOnly) | |
19882 .FromJust(); | |
19883 obj->Set(context.local(), v8_num(2), v8_str("foobar")).FromJust(); | |
19884 CHECK(v8_str("DONT_CHANGE") | |
19885 ->Equals(context.local(), | |
19886 obj->Get(context.local(), v8_num(2)).ToLocalChecked()) | |
19887 .FromJust()); | |
19901 | 19888 |
19902 // Test non-smi case. | 19889 // Test non-smi case. |
19903 obj->ForceSet(v8_str("2000000000"), v8_str("DONT_CHANGE"), v8::ReadOnly); | 19890 obj->DefineOwnProperty(context.local(), v8_str("2000000000"), |
19904 obj->Set(v8_str("2000000000"), v8_str("foobar")); | 19891 v8_str("DONT_CHANGE"), v8::ReadOnly) |
19905 CHECK(v8_str("DONT_CHANGE")->Equals(obj->Get(v8_str("2000000000")))); | 19892 .FromJust(); |
19893 obj->Set(context.local(), v8_str("2000000000"), v8_str("foobar")).FromJust(); | |
19894 CHECK(v8_str("DONT_CHANGE") | |
19895 ->Equals(context.local(), | |
19896 obj->Get(context.local(), v8_str("2000000000")) | |
19897 .ToLocalChecked()) | |
19898 .FromJust()); | |
19906 } | 19899 } |
19907 | 19900 |
19908 | 19901 |
19909 static int CountLiveMapsInMapCache(i::Context* context) { | 19902 static int CountLiveMapsInMapCache(i::Context* context) { |
19910 i::FixedArray* map_cache = i::FixedArray::cast(context->map_cache()); | 19903 i::FixedArray* map_cache = i::FixedArray::cast(context->map_cache()); |
19911 int length = map_cache->length(); | 19904 int length = map_cache->length(); |
19912 int count = 0; | 19905 int count = 0; |
19913 for (int i = 0; i < length; i++) { | 19906 for (int i = 0; i < length; i++) { |
19914 i::Object* value = map_cache->get(i); | 19907 i::Object* value = map_cache->get(i); |
19915 if (value->IsWeakCell() && !i::WeakCell::cast(value)->cleared()) count++; | 19908 if (value->IsWeakCell() && !i::WeakCell::cast(value)->cleared()) count++; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
19970 Local<Object> simple_object = Object::New(isolate); | 19963 Local<Object> simple_object = Object::New(isolate); |
19971 | 19964 |
19972 // Object with explicit security check. | 19965 // Object with explicit security check. |
19973 Local<Object> protected_object = | 19966 Local<Object> protected_object = |
19974 no_proto_template->NewInstance(context).ToLocalChecked(); | 19967 no_proto_template->NewInstance(context).ToLocalChecked(); |
19975 | 19968 |
19976 // JSGlobalProxy object, always have security check. | 19969 // JSGlobalProxy object, always have security check. |
19977 Local<Object> proxy_object = context->Global(); | 19970 Local<Object> proxy_object = context->Global(); |
19978 | 19971 |
19979 // Global object, the prototype of proxy_object. No security checks. | 19972 // Global object, the prototype of proxy_object. No security checks. |
19980 Local<Object> global_object = proxy_object->GetPrototype()->ToObject(isolate); | 19973 Local<Object> global_object = |
19974 proxy_object->GetPrototype()->ToObject(context).ToLocalChecked(); | |
19981 | 19975 |
19982 // Hidden prototype without security check. | 19976 // Hidden prototype without security check. |
19983 Local<Object> hidden_prototype = hidden_proto_template->GetFunction(context) | 19977 Local<Object> hidden_prototype = hidden_proto_template->GetFunction(context) |
19984 .ToLocalChecked() | 19978 .ToLocalChecked() |
19985 ->NewInstance(context) | 19979 ->NewInstance(context) |
19986 .ToLocalChecked(); | 19980 .ToLocalChecked(); |
19987 Local<Object> object_with_hidden = | 19981 Local<Object> object_with_hidden = |
19988 Object::New(isolate); | 19982 Object::New(isolate); |
19989 object_with_hidden->SetPrototype(hidden_prototype); | 19983 object_with_hidden->SetPrototype(context, hidden_prototype).FromJust(); |
19990 | 19984 |
19991 context->Exit(); | 19985 context->Exit(); |
19992 | 19986 |
19993 // Template for object for second context. Values to test are put on it as | 19987 // Template for object for second context. Values to test are put on it as |
19994 // properties. | 19988 // properties. |
19995 Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate); | 19989 Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate); |
19996 global_template->Set(v8_str("simple"), simple_object); | 19990 global_template->Set(v8_str("simple"), simple_object); |
19997 global_template->Set(v8_str("protected"), protected_object); | 19991 global_template->Set(v8_str("protected"), protected_object); |
19998 global_template->Set(v8_str("global"), global_object); | 19992 global_template->Set(v8_str("global"), global_object); |
19999 global_template->Set(v8_str("proxy"), proxy_object); | 19993 global_template->Set(v8_str("proxy"), proxy_object); |
20000 global_template->Set(v8_str("hidden"), object_with_hidden); | 19994 global_template->Set(v8_str("hidden"), object_with_hidden); |
20001 | 19995 |
20002 LocalContext context2(NULL, global_template); | 19996 LocalContext context2(NULL, global_template); |
20003 | 19997 |
20004 Local<Value> result1 = CompileRun("Object.getPrototypeOf(simple)"); | 19998 Local<Value> result1 = CompileRun("Object.getPrototypeOf(simple)"); |
20005 CHECK(result1->Equals(simple_object->GetPrototype())); | 19999 CHECK(result1->Equals(context2.local(), simple_object->GetPrototype()) |
20000 .FromJust()); | |
20006 | 20001 |
20007 Local<Value> result2 = CompileRun("Object.getPrototypeOf(protected)"); | 20002 Local<Value> result2 = CompileRun("Object.getPrototypeOf(protected)"); |
20008 CHECK(result2->IsNull()); | 20003 CHECK(result2->IsNull()); |
20009 | 20004 |
20010 Local<Value> result3 = CompileRun("Object.getPrototypeOf(global)"); | 20005 Local<Value> result3 = CompileRun("Object.getPrototypeOf(global)"); |
20011 CHECK(result3->Equals(global_object->GetPrototype())); | 20006 CHECK(result3->Equals(context2.local(), global_object->GetPrototype()) |
20007 .FromJust()); | |
20012 | 20008 |
20013 Local<Value> result4 = CompileRun("Object.getPrototypeOf(proxy)"); | 20009 Local<Value> result4 = CompileRun("Object.getPrototypeOf(proxy)"); |
20014 CHECK(result4->IsNull()); | 20010 CHECK(result4->IsNull()); |
20015 | 20011 |
20016 Local<Value> result5 = CompileRun("Object.getPrototypeOf(hidden)"); | 20012 Local<Value> result5 = CompileRun("Object.getPrototypeOf(hidden)"); |
20017 CHECK(result5->Equals( | 20013 CHECK(result5->Equals(context2.local(), object_with_hidden->GetPrototype() |
20018 object_with_hidden->GetPrototype()->ToObject(isolate)->GetPrototype())); | 20014 ->ToObject(context2.local()) |
20015 .ToLocalChecked() | |
20016 ->GetPrototype()) | |
20017 .FromJust()); | |
20019 } | 20018 } |
20020 | 20019 |
20021 | 20020 |
20022 static void TestReceiver(Local<Value> expected_result, | 20021 static void TestReceiver(Local<Value> expected_result, |
20023 Local<Value> expected_receiver, | 20022 Local<Value> expected_receiver, |
20024 const char* code) { | 20023 const char* code) { |
20025 Local<Value> result = CompileRun(code); | 20024 Local<Value> result = CompileRun(code); |
20025 Local<Context> context = CcTest::isolate()->GetCurrentContext(); | |
20026 CHECK(result->IsObject()); | 20026 CHECK(result->IsObject()); |
20027 CHECK(expected_receiver->Equals(result.As<v8::Object>()->Get(1))); | 20027 CHECK(expected_receiver |
20028 CHECK(expected_result->Equals(result.As<v8::Object>()->Get(0))); | 20028 ->Equals(context, |
20029 result.As<v8::Object>()->Get(context, 1).ToLocalChecked()) | |
20030 .FromJust()); | |
20031 CHECK(expected_result | |
20032 ->Equals(context, | |
20033 result.As<v8::Object>()->Get(context, 0).ToLocalChecked()) | |
20034 .FromJust()); | |
20029 } | 20035 } |
20030 | 20036 |
20031 | 20037 |
20032 THREADED_TEST(ForeignFunctionReceiver) { | 20038 THREADED_TEST(ForeignFunctionReceiver) { |
20033 v8::Isolate* isolate = CcTest::isolate(); | 20039 v8::Isolate* isolate = CcTest::isolate(); |
20034 HandleScope scope(isolate); | 20040 HandleScope scope(isolate); |
20035 | 20041 |
20036 // Create two contexts with different "id" properties ('i' and 'o'). | 20042 // Create two contexts with different "id" properties ('i' and 'o'). |
20037 // Call a function both from its own context and from a the foreign | 20043 // Call a function both from its own context and from a the foreign |
20038 // context, and see what "this" is bound to (returning both "this" | 20044 // context, and see what "this" is bound to (returning both "this" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
20072 " }" | 20078 " }" |
20073 " };" | 20079 " };" |
20074 "}" | 20080 "}" |
20075 "var id = 'o';" | 20081 "var id = 'o';" |
20076 "ownfunc"); | 20082 "ownfunc"); |
20077 CHECK(context->Global() | 20083 CHECK(context->Global() |
20078 ->Set(context.local(), v8_str("func"), foreign_function) | 20084 ->Set(context.local(), v8_str("func"), foreign_function) |
20079 .FromJust()); | 20085 .FromJust()); |
20080 | 20086 |
20081 // Sanity check the contexts. | 20087 // Sanity check the contexts. |
20082 CHECK(i->Equals(foreign_context->Global()->Get(id))); | 20088 CHECK( |
20083 CHECK(o->Equals(context->Global()->Get(id))); | 20089 i->Equals( |
20090 context.local(), | |
20091 foreign_context->Global()->Get(context.local(), id).ToLocalChecked()) | |
20092 .FromJust()); | |
20093 CHECK(o->Equals(context.local(), | |
20094 context->Global()->Get(context.local(), id).ToLocalChecked()) | |
20095 .FromJust()); | |
20084 | 20096 |
20085 // Checking local function's receiver. | 20097 // Checking local function's receiver. |
20086 // Calling function using its call/apply methods. | 20098 // Calling function using its call/apply methods. |
20087 TestReceiver(o, context->Global(), "ownfunc.call()"); | 20099 TestReceiver(o, context->Global(), "ownfunc.call()"); |
20088 TestReceiver(o, context->Global(), "ownfunc.apply()"); | 20100 TestReceiver(o, context->Global(), "ownfunc.apply()"); |
20089 // Making calls through built-in functions. | 20101 // Making calls through built-in functions. |
20090 TestReceiver(o, context->Global(), "[1].map(ownfunc)[0]"); | 20102 TestReceiver(o, context->Global(), "[1].map(ownfunc)[0]"); |
20091 CHECK(o->Equals(CompileRun("'abcbd'.replace(/b/,ownfunc)[1]"))); | 20103 CHECK( |
20092 CHECK(o->Equals(CompileRun("'abcbd'.replace(/b/g,ownfunc)[1]"))); | 20104 o->Equals(context.local(), CompileRun("'abcbd'.replace(/b/,ownfunc)[1]")) |
20093 CHECK(o->Equals(CompileRun("'abcbd'.replace(/b/g,ownfunc)[3]"))); | 20105 .FromJust()); |
20106 CHECK( | |
20107 o->Equals(context.local(), CompileRun("'abcbd'.replace(/b/g,ownfunc)[1]")) | |
20108 .FromJust()); | |
20109 CHECK( | |
20110 o->Equals(context.local(), CompileRun("'abcbd'.replace(/b/g,ownfunc)[3]")) | |
20111 .FromJust()); | |
20094 // Calling with environment record as base. | 20112 // Calling with environment record as base. |
20095 TestReceiver(o, context->Global(), "ownfunc()"); | 20113 TestReceiver(o, context->Global(), "ownfunc()"); |
20096 // Calling with no base. | 20114 // Calling with no base. |
20097 TestReceiver(o, context->Global(), "(1,ownfunc)()"); | 20115 TestReceiver(o, context->Global(), "(1,ownfunc)()"); |
20098 | 20116 |
20099 // Checking foreign function return value. | 20117 // Checking foreign function return value. |
20100 // Calling function using its call/apply methods. | 20118 // Calling function using its call/apply methods. |
20101 TestReceiver(i, foreign_context->Global(), "func.call()"); | 20119 TestReceiver(i, foreign_context->Global(), "func.call()"); |
20102 TestReceiver(i, foreign_context->Global(), "func.apply()"); | 20120 TestReceiver(i, foreign_context->Global(), "func.apply()"); |
20103 // Calling function using another context's call/apply methods. | 20121 // Calling function using another context's call/apply methods. |
20104 TestReceiver(i, foreign_context->Global(), | 20122 TestReceiver(i, foreign_context->Global(), |
20105 "Function.prototype.call.call(func)"); | 20123 "Function.prototype.call.call(func)"); |
20106 TestReceiver(i, foreign_context->Global(), | 20124 TestReceiver(i, foreign_context->Global(), |
20107 "Function.prototype.call.apply(func)"); | 20125 "Function.prototype.call.apply(func)"); |
20108 TestReceiver(i, foreign_context->Global(), | 20126 TestReceiver(i, foreign_context->Global(), |
20109 "Function.prototype.apply.call(func)"); | 20127 "Function.prototype.apply.call(func)"); |
20110 TestReceiver(i, foreign_context->Global(), | 20128 TestReceiver(i, foreign_context->Global(), |
20111 "Function.prototype.apply.apply(func)"); | 20129 "Function.prototype.apply.apply(func)"); |
20112 // Making calls through built-in functions. | 20130 // Making calls through built-in functions. |
20113 TestReceiver(i, foreign_context->Global(), "[1].map(func)[0]"); | 20131 TestReceiver(i, foreign_context->Global(), "[1].map(func)[0]"); |
20114 // ToString(func()) is func()[0], i.e., the returned this.id. | 20132 // ToString(func()) is func()[0], i.e., the returned this.id. |
20115 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/,func)[1]"))); | 20133 CHECK(i->Equals(context.local(), CompileRun("'abcbd'.replace(/b/,func)[1]")) |
20116 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[1]"))); | 20134 .FromJust()); |
20117 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); | 20135 CHECK(i->Equals(context.local(), CompileRun("'abcbd'.replace(/b/g,func)[1]")) |
20136 .FromJust()); | |
20137 CHECK(i->Equals(context.local(), CompileRun("'abcbd'.replace(/b/g,func)[3]")) | |
20138 .FromJust()); | |
20118 | 20139 |
20119 // Calling with environment record as base. | 20140 // Calling with environment record as base. |
20120 TestReceiver(i, foreign_context->Global(), "func()"); | 20141 TestReceiver(i, foreign_context->Global(), "func()"); |
20121 // Calling with no base. | 20142 // Calling with no base. |
20122 TestReceiver(i, foreign_context->Global(), "(1,func)()"); | 20143 TestReceiver(i, foreign_context->Global(), "(1,func)()"); |
20123 } | 20144 } |
20124 | 20145 |
20125 | 20146 |
20126 uint8_t callback_fired = 0; | 20147 uint8_t callback_fired = 0; |
20127 | 20148 |
(...skipping 27 matching lines...) Expand all Loading... | |
20155 CHECK_EQ(0, callback_fired); | 20176 CHECK_EQ(0, callback_fired); |
20156 } | 20177 } |
20157 } | 20178 } |
20158 | 20179 |
20159 | 20180 |
20160 TEST(CallCompletedCallback) { | 20181 TEST(CallCompletedCallback) { |
20161 LocalContext env; | 20182 LocalContext env; |
20162 v8::HandleScope scope(env->GetIsolate()); | 20183 v8::HandleScope scope(env->GetIsolate()); |
20163 v8::Local<v8::FunctionTemplate> recursive_runtime = | 20184 v8::Local<v8::FunctionTemplate> recursive_runtime = |
20164 v8::FunctionTemplate::New(env->GetIsolate(), RecursiveCall); | 20185 v8::FunctionTemplate::New(env->GetIsolate(), RecursiveCall); |
20165 env->Global()->Set( | 20186 env->Global() |
20166 v8_str("recursion"), | 20187 ->Set(env.local(), v8_str("recursion"), |
20167 recursive_runtime->GetFunction(env.local()).ToLocalChecked()); | 20188 recursive_runtime->GetFunction(env.local()).ToLocalChecked()) |
20189 .FromJust(); | |
20168 // Adding the same callback a second time has no effect. | 20190 // Adding the same callback a second time has no effect. |
20169 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1); | 20191 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1); |
20170 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1); | 20192 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1); |
20171 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback2); | 20193 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback2); |
20172 v8::base::OS::Print("--- Script (1) ---\n"); | 20194 v8::base::OS::Print("--- Script (1) ---\n"); |
20173 Local<Script> script = v8::Script::Compile(v8_str("recursion(0)")); | 20195 Local<Script> script = |
20174 script->Run(); | 20196 v8::Script::Compile(env.local(), v8_str("recursion(0)")).ToLocalChecked(); |
20197 script->Run(env.local()).ToLocalChecked(); | |
20175 CHECK_EQ(3, callback_fired); | 20198 CHECK_EQ(3, callback_fired); |
20176 | 20199 |
20177 v8::base::OS::Print("\n--- Script (2) ---\n"); | 20200 v8::base::OS::Print("\n--- Script (2) ---\n"); |
20178 callback_fired = 0; | 20201 callback_fired = 0; |
20179 env->GetIsolate()->RemoveCallCompletedCallback(CallCompletedCallback1); | 20202 env->GetIsolate()->RemoveCallCompletedCallback(CallCompletedCallback1); |
20180 script->Run(); | 20203 script->Run(env.local()).ToLocalChecked(); |
20181 CHECK_EQ(2, callback_fired); | 20204 CHECK_EQ(2, callback_fired); |
20182 | 20205 |
20183 v8::base::OS::Print("\n--- Function ---\n"); | 20206 v8::base::OS::Print("\n--- Function ---\n"); |
20184 callback_fired = 0; | 20207 callback_fired = 0; |
20185 Local<Function> recursive_function = | 20208 Local<Function> recursive_function = Local<Function>::Cast( |
20186 Local<Function>::Cast(env->Global()->Get(v8_str("recursion"))); | 20209 env->Global()->Get(env.local(), v8_str("recursion")).ToLocalChecked()); |
20187 v8::Local<Value> args[] = {v8_num(0)}; | 20210 v8::Local<Value> args[] = {v8_num(0)}; |
20188 recursive_function->Call(env->Global(), 1, args); | 20211 recursive_function->Call(env.local(), env->Global(), 1, args) |
20212 .ToLocalChecked(); | |
20189 CHECK_EQ(2, callback_fired); | 20213 CHECK_EQ(2, callback_fired); |
20190 } | 20214 } |
20191 | 20215 |
20192 | 20216 |
20193 void CallCompletedCallbackNoException() { | 20217 void CallCompletedCallbackNoException() { |
20194 v8::HandleScope scope(CcTest::isolate()); | 20218 v8::HandleScope scope(CcTest::isolate()); |
20195 CompileRun("1+1;"); | 20219 CompileRun("1+1;"); |
20196 } | 20220 } |
20197 | 20221 |
20198 | 20222 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
20242 LocalContext env; | 20266 LocalContext env; |
20243 v8::HandleScope scope(env->GetIsolate()); | 20267 v8::HandleScope scope(env->GetIsolate()); |
20244 CompileRun( | 20268 CompileRun( |
20245 "var ext1Calls = 0;" | 20269 "var ext1Calls = 0;" |
20246 "var ext2Calls = 0;"); | 20270 "var ext2Calls = 0;"); |
20247 CompileRun("1+1;"); | 20271 CompileRun("1+1;"); |
20248 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); | 20272 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
20249 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); | 20273 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
20250 | 20274 |
20251 env->GetIsolate()->EnqueueMicrotask( | 20275 env->GetIsolate()->EnqueueMicrotask( |
20252 Function::New(env->GetIsolate(), MicrotaskOne)); | 20276 Function::New(env.local(), MicrotaskOne).ToLocalChecked()); |
20253 CompileRun("1+1;"); | 20277 CompileRun("1+1;"); |
20254 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); | 20278 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
20255 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); | 20279 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
20256 | 20280 |
20257 env->GetIsolate()->EnqueueMicrotask( | 20281 env->GetIsolate()->EnqueueMicrotask( |
20258 Function::New(env->GetIsolate(), MicrotaskOne)); | 20282 Function::New(env.local(), MicrotaskOne).ToLocalChecked()); |
20259 env->GetIsolate()->EnqueueMicrotask( | 20283 env->GetIsolate()->EnqueueMicrotask( |
20260 Function::New(env->GetIsolate(), MicrotaskTwo)); | 20284 Function::New(env.local(), MicrotaskTwo).ToLocalChecked()); |
20261 CompileRun("1+1;"); | 20285 CompileRun("1+1;"); |
20262 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); | 20286 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
20263 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); | 20287 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
20264 | 20288 |
20265 env->GetIsolate()->EnqueueMicrotask( | 20289 env->GetIsolate()->EnqueueMicrotask( |
20266 Function::New(env->GetIsolate(), MicrotaskTwo)); | 20290 Function::New(env.local(), MicrotaskTwo).ToLocalChecked()); |
20267 CompileRun("1+1;"); | 20291 CompileRun("1+1;"); |
20268 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); | 20292 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
20269 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); | 20293 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
20270 | 20294 |
20271 CompileRun("1+1;"); | 20295 CompileRun("1+1;"); |
20272 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); | 20296 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
20273 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); | 20297 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
20274 | 20298 |
20275 g_passed_to_three = NULL; | 20299 g_passed_to_three = NULL; |
20276 env->GetIsolate()->EnqueueMicrotask(MicrotaskThree); | 20300 env->GetIsolate()->EnqueueMicrotask(MicrotaskThree); |
20277 CompileRun("1+1;"); | 20301 CompileRun("1+1;"); |
20278 CHECK(!g_passed_to_three); | 20302 CHECK(!g_passed_to_three); |
20279 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); | 20303 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
20280 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); | 20304 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
20281 | 20305 |
20282 int dummy; | 20306 int dummy; |
20283 env->GetIsolate()->EnqueueMicrotask( | 20307 env->GetIsolate()->EnqueueMicrotask( |
20284 Function::New(env->GetIsolate(), MicrotaskOne)); | 20308 Function::New(env.local(), MicrotaskOne).ToLocalChecked()); |
20285 env->GetIsolate()->EnqueueMicrotask(MicrotaskThree, &dummy); | 20309 env->GetIsolate()->EnqueueMicrotask(MicrotaskThree, &dummy); |
20286 env->GetIsolate()->EnqueueMicrotask( | 20310 env->GetIsolate()->EnqueueMicrotask( |
20287 Function::New(env->GetIsolate(), MicrotaskTwo)); | 20311 Function::New(env.local(), MicrotaskTwo).ToLocalChecked()); |
20288 CompileRun("1+1;"); | 20312 CompileRun("1+1;"); |
20289 CHECK_EQ(&dummy, g_passed_to_three); | 20313 CHECK_EQ(&dummy, g_passed_to_three); |
20290 CHECK_EQ(3, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); | 20314 CHECK_EQ(3, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
20291 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); | 20315 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
20292 g_passed_to_three = NULL; | 20316 g_passed_to_three = NULL; |
20293 } | 20317 } |
20294 | 20318 |
20295 | 20319 |
20296 static void MicrotaskExceptionOne( | 20320 static void MicrotaskExceptionOne( |
20297 const v8::FunctionCallbackInfo<Value>& info) { | 20321 const v8::FunctionCallbackInfo<Value>& info) { |
(...skipping 14 matching lines...) Expand all Loading... | |
20312 | 20336 |
20313 | 20337 |
20314 TEST(RunMicrotasksIgnoresThrownExceptions) { | 20338 TEST(RunMicrotasksIgnoresThrownExceptions) { |
20315 LocalContext env; | 20339 LocalContext env; |
20316 v8::Isolate* isolate = env->GetIsolate(); | 20340 v8::Isolate* isolate = env->GetIsolate(); |
20317 v8::HandleScope scope(isolate); | 20341 v8::HandleScope scope(isolate); |
20318 CompileRun( | 20342 CompileRun( |
20319 "var exception1Calls = 0;" | 20343 "var exception1Calls = 0;" |
20320 "var exception2Calls = 0;"); | 20344 "var exception2Calls = 0;"); |
20321 isolate->EnqueueMicrotask( | 20345 isolate->EnqueueMicrotask( |
20322 Function::New(isolate, MicrotaskExceptionOne)); | 20346 Function::New(env.local(), MicrotaskExceptionOne).ToLocalChecked()); |
20323 isolate->EnqueueMicrotask( | 20347 isolate->EnqueueMicrotask( |
20324 Function::New(isolate, MicrotaskExceptionTwo)); | 20348 Function::New(env.local(), MicrotaskExceptionTwo).ToLocalChecked()); |
20325 TryCatch try_catch(isolate); | 20349 TryCatch try_catch(isolate); |
20326 CompileRun("1+1;"); | 20350 CompileRun("1+1;"); |
20327 CHECK(!try_catch.HasCaught()); | 20351 CHECK(!try_catch.HasCaught()); |
20328 CHECK_EQ(1, | 20352 CHECK_EQ(1, |
20329 CompileRun("exception1Calls")->Int32Value(env.local()).FromJust()); | 20353 CompileRun("exception1Calls")->Int32Value(env.local()).FromJust()); |
20330 CHECK_EQ(1, | 20354 CHECK_EQ(1, |
20331 CompileRun("exception2Calls")->Int32Value(env.local()).FromJust()); | 20355 CompileRun("exception2Calls")->Int32Value(env.local()).FromJust()); |
20332 } | 20356 } |
20333 | 20357 |
20334 | 20358 |
20335 TEST(SetAutorunMicrotasks) { | 20359 TEST(SetAutorunMicrotasks) { |
20336 LocalContext env; | 20360 LocalContext env; |
20337 v8::HandleScope scope(env->GetIsolate()); | 20361 v8::HandleScope scope(env->GetIsolate()); |
20338 CompileRun( | 20362 CompileRun( |
20339 "var ext1Calls = 0;" | 20363 "var ext1Calls = 0;" |
20340 "var ext2Calls = 0;"); | 20364 "var ext2Calls = 0;"); |
20341 CompileRun("1+1;"); | 20365 CompileRun("1+1;"); |
20342 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); | 20366 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
20343 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); | 20367 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
20344 | 20368 |
20345 env->GetIsolate()->EnqueueMicrotask( | 20369 env->GetIsolate()->EnqueueMicrotask( |
20346 Function::New(env->GetIsolate(), MicrotaskOne)); | 20370 Function::New(env.local(), MicrotaskOne).ToLocalChecked()); |
20347 CompileRun("1+1;"); | 20371 CompileRun("1+1;"); |
20348 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); | 20372 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
20349 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); | 20373 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
20350 | 20374 |
20351 env->GetIsolate()->SetAutorunMicrotasks(false); | 20375 env->GetIsolate()->SetAutorunMicrotasks(false); |
20352 env->GetIsolate()->EnqueueMicrotask( | 20376 env->GetIsolate()->EnqueueMicrotask( |
20353 Function::New(env->GetIsolate(), MicrotaskOne)); | 20377 Function::New(env.local(), MicrotaskOne).ToLocalChecked()); |
20354 env->GetIsolate()->EnqueueMicrotask( | 20378 env->GetIsolate()->EnqueueMicrotask( |
20355 Function::New(env->GetIsolate(), MicrotaskTwo)); | 20379 Function::New(env.local(), MicrotaskTwo).ToLocalChecked()); |
20356 CompileRun("1+1;"); | 20380 CompileRun("1+1;"); |
20357 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); | 20381 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
20358 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); | 20382 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
20359 | 20383 |
20360 env->GetIsolate()->RunMicrotasks(); | 20384 env->GetIsolate()->RunMicrotasks(); |
20361 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); | 20385 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
20362 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); | 20386 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
20363 | 20387 |
20364 env->GetIsolate()->EnqueueMicrotask( | 20388 env->GetIsolate()->EnqueueMicrotask( |
20365 Function::New(env->GetIsolate(), MicrotaskTwo)); | 20389 Function::New(env.local(), MicrotaskTwo).ToLocalChecked()); |
20366 CompileRun("1+1;"); | 20390 CompileRun("1+1;"); |
20367 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); | 20391 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
20368 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); | 20392 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
20369 | 20393 |
20370 env->GetIsolate()->RunMicrotasks(); | 20394 env->GetIsolate()->RunMicrotasks(); |
20371 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); | 20395 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
20372 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); | 20396 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
20373 | 20397 |
20374 env->GetIsolate()->SetAutorunMicrotasks(true); | 20398 env->GetIsolate()->SetAutorunMicrotasks(true); |
20375 env->GetIsolate()->EnqueueMicrotask( | 20399 env->GetIsolate()->EnqueueMicrotask( |
20376 Function::New(env->GetIsolate(), MicrotaskTwo)); | 20400 Function::New(env.local(), MicrotaskTwo).ToLocalChecked()); |
20377 CompileRun("1+1;"); | 20401 CompileRun("1+1;"); |
20378 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); | 20402 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
20379 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); | 20403 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
20380 | 20404 |
20381 env->GetIsolate()->EnqueueMicrotask( | 20405 env->GetIsolate()->EnqueueMicrotask( |
20382 Function::New(env->GetIsolate(), MicrotaskTwo)); | 20406 Function::New(env.local(), MicrotaskTwo).ToLocalChecked()); |
20383 { | 20407 { |
20384 v8::Isolate::SuppressMicrotaskExecutionScope scope(env->GetIsolate()); | 20408 v8::Isolate::SuppressMicrotaskExecutionScope scope(env->GetIsolate()); |
20385 CompileRun("1+1;"); | 20409 CompileRun("1+1;"); |
20386 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); | 20410 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
20387 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); | 20411 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
20388 } | 20412 } |
20389 | 20413 |
20390 CompileRun("1+1;"); | 20414 CompileRun("1+1;"); |
20391 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); | 20415 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
20392 CHECK_EQ(4, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); | 20416 CHECK_EQ(4, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
20393 } | 20417 } |
20394 | 20418 |
20395 | 20419 |
20396 TEST(RunMicrotasksWithoutEnteringContext) { | 20420 TEST(RunMicrotasksWithoutEnteringContext) { |
20397 v8::Isolate* isolate = CcTest::isolate(); | 20421 v8::Isolate* isolate = CcTest::isolate(); |
20398 HandleScope handle_scope(isolate); | 20422 HandleScope handle_scope(isolate); |
20399 isolate->SetAutorunMicrotasks(false); | 20423 isolate->SetAutorunMicrotasks(false); |
20400 Local<Context> context = Context::New(isolate); | 20424 Local<Context> context = Context::New(isolate); |
20401 { | 20425 { |
20402 Context::Scope context_scope(context); | 20426 Context::Scope context_scope(context); |
20403 CompileRun("var ext1Calls = 0;"); | 20427 CompileRun("var ext1Calls = 0;"); |
20404 isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskOne)); | 20428 isolate->EnqueueMicrotask( |
20429 Function::New(context, MicrotaskOne).ToLocalChecked()); | |
20405 } | 20430 } |
20406 isolate->RunMicrotasks(); | 20431 isolate->RunMicrotasks(); |
20407 { | 20432 { |
20408 Context::Scope context_scope(context); | 20433 Context::Scope context_scope(context); |
20409 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(context).FromJust()); | 20434 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(context).FromJust()); |
20410 } | 20435 } |
20411 isolate->SetAutorunMicrotasks(true); | 20436 isolate->SetAutorunMicrotasks(true); |
20412 } | 20437 } |
20413 | 20438 |
20414 | 20439 |
20415 static void DebugEventInObserver(const v8::Debug::EventDetails& event_details) { | 20440 static void DebugEventInObserver(const v8::Debug::EventDetails& event_details) { |
20416 v8::DebugEvent event = event_details.GetEvent(); | 20441 v8::DebugEvent event = event_details.GetEvent(); |
20417 if (event != v8::Break) return; | 20442 if (event != v8::Break) return; |
20418 Local<Object> exec_state = event_details.GetExecutionState(); | 20443 Local<Object> exec_state = event_details.GetExecutionState(); |
20419 Local<Value> break_id = exec_state->Get(v8_str("break_id")); | 20444 Local<Context> context = CcTest::isolate()->GetCurrentContext(); |
20445 Local<Value> break_id = | |
20446 exec_state->Get(context, v8_str("break_id")).ToLocalChecked(); | |
20420 CompileRun("function f(id) { new FrameDetails(id, 0); }"); | 20447 CompileRun("function f(id) { new FrameDetails(id, 0); }"); |
20421 Local<Function> fun = | 20448 Local<Function> fun = Local<Function>::Cast( |
20422 Local<Function>::Cast(CcTest::global()->Get(v8_str("f"))); | 20449 CcTest::global()->Get(context, v8_str("f")).ToLocalChecked()); |
20423 fun->Call(CcTest::global(), 1, &break_id); | 20450 fun->Call(context, CcTest::global(), 1, &break_id).ToLocalChecked(); |
20424 } | 20451 } |
20425 | 20452 |
20426 | 20453 |
20427 TEST(Regress385349) { | 20454 TEST(Regress385349) { |
20428 i::FLAG_harmony_object_observe = true; | 20455 i::FLAG_harmony_object_observe = true; |
20429 i::FLAG_allow_natives_syntax = true; | 20456 i::FLAG_allow_natives_syntax = true; |
20430 v8::Isolate* isolate = CcTest::isolate(); | 20457 v8::Isolate* isolate = CcTest::isolate(); |
20431 HandleScope handle_scope(isolate); | 20458 HandleScope handle_scope(isolate); |
20432 isolate->SetAutorunMicrotasks(false); | 20459 isolate->SetAutorunMicrotasks(false); |
20433 Local<Context> context = Context::New(isolate); | 20460 Local<Context> context = Context::New(isolate); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
20604 v8::HandleScope scope(isolate); | 20631 v8::HandleScope scope(isolate); |
20605 i::Handle<i::Object> empty_string = factory->empty_string(); | 20632 i::Handle<i::Object> empty_string = factory->empty_string(); |
20606 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty(isolate)) == *empty_string); | 20633 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty(isolate)) == *empty_string); |
20607 } | 20634 } |
20608 | 20635 |
20609 | 20636 |
20610 static int instance_checked_getter_count = 0; | 20637 static int instance_checked_getter_count = 0; |
20611 static void InstanceCheckedGetter( | 20638 static void InstanceCheckedGetter( |
20612 Local<String> name, | 20639 Local<String> name, |
20613 const v8::PropertyCallbackInfo<v8::Value>& info) { | 20640 const v8::PropertyCallbackInfo<v8::Value>& info) { |
20614 CHECK(name->Equals(v8_str("foo"))); | 20641 CHECK(name->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("foo")) |
20642 .FromJust()); | |
20615 instance_checked_getter_count++; | 20643 instance_checked_getter_count++; |
20616 info.GetReturnValue().Set(v8_num(11)); | 20644 info.GetReturnValue().Set(v8_num(11)); |
20617 } | 20645 } |
20618 | 20646 |
20619 | 20647 |
20620 static int instance_checked_setter_count = 0; | 20648 static int instance_checked_setter_count = 0; |
20621 static void InstanceCheckedSetter(Local<String> name, | 20649 static void InstanceCheckedSetter(Local<String> name, |
20622 Local<Value> value, | 20650 Local<Value> value, |
20623 const v8::PropertyCallbackInfo<void>& info) { | 20651 const v8::PropertyCallbackInfo<void>& info) { |
20624 CHECK(name->Equals(v8_str("foo"))); | 20652 CHECK(name->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("foo")) |
20625 CHECK(value->Equals(v8_num(23))); | 20653 .FromJust()); |
20654 CHECK(value->Equals(info.GetIsolate()->GetCurrentContext(), v8_num(23)) | |
20655 .FromJust()); | |
20626 instance_checked_setter_count++; | 20656 instance_checked_setter_count++; |
20627 } | 20657 } |
20628 | 20658 |
20629 | 20659 |
20630 static void CheckInstanceCheckedResult(int getters, int setters, | 20660 static void CheckInstanceCheckedResult(int getters, int setters, |
20631 bool expects_callbacks, | 20661 bool expects_callbacks, |
20632 TryCatch* try_catch) { | 20662 TryCatch* try_catch) { |
20633 if (expects_callbacks) { | 20663 if (expects_callbacks) { |
20634 CHECK(!try_catch->HasCaught()); | 20664 CHECK(!try_catch->HasCaught()); |
20635 CHECK_EQ(getters, instance_checked_getter_count); | 20665 CHECK_EQ(getters, instance_checked_getter_count); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
20696 inst->SetAccessor(v8_str("foo"), InstanceCheckedGetter, InstanceCheckedSetter, | 20726 inst->SetAccessor(v8_str("foo"), InstanceCheckedGetter, InstanceCheckedSetter, |
20697 Local<Value>(), v8::DEFAULT, v8::None, | 20727 Local<Value>(), v8::DEFAULT, v8::None, |
20698 v8::AccessorSignature::New(context->GetIsolate(), templ)); | 20728 v8::AccessorSignature::New(context->GetIsolate(), templ)); |
20699 CHECK(context->Global() | 20729 CHECK(context->Global() |
20700 ->Set(context.local(), v8_str("f"), | 20730 ->Set(context.local(), v8_str("f"), |
20701 templ->GetFunction(context.local()).ToLocalChecked()) | 20731 templ->GetFunction(context.local()).ToLocalChecked()) |
20702 .FromJust()); | 20732 .FromJust()); |
20703 | 20733 |
20704 printf("Testing positive ...\n"); | 20734 printf("Testing positive ...\n"); |
20705 CompileRun("var obj = new f();"); | 20735 CompileRun("var obj = new f();"); |
20706 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); | 20736 CHECK(templ->HasInstance( |
20737 context->Global()->Get(context.local(), v8_str("obj")).ToLocalChecked())); | |
20707 CheckInstanceCheckedAccessors(true); | 20738 CheckInstanceCheckedAccessors(true); |
20708 | 20739 |
20709 printf("Testing negative ...\n"); | 20740 printf("Testing negative ...\n"); |
20710 CompileRun("var obj = {};" | 20741 CompileRun("var obj = {};" |
20711 "obj.__proto__ = new f();"); | 20742 "obj.__proto__ = new f();"); |
20712 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); | 20743 CHECK(!templ->HasInstance( |
20744 context->Global()->Get(context.local(), v8_str("obj")).ToLocalChecked())); | |
20713 CheckInstanceCheckedAccessors(false); | 20745 CheckInstanceCheckedAccessors(false); |
20714 } | 20746 } |
20715 | 20747 |
20716 | 20748 |
20717 static void EmptyInterceptorGetter( | 20749 static void EmptyInterceptorGetter( |
20718 Local<String> name, const v8::PropertyCallbackInfo<v8::Value>& info) {} | 20750 Local<String> name, const v8::PropertyCallbackInfo<v8::Value>& info) {} |
20719 | 20751 |
20720 | 20752 |
20721 static void EmptyInterceptorSetter( | 20753 static void EmptyInterceptorSetter( |
20722 Local<String> name, Local<Value> value, | 20754 Local<String> name, Local<Value> value, |
(...skipping 12 matching lines...) Expand all Loading... | |
20735 inst->SetAccessor(v8_str("foo"), InstanceCheckedGetter, InstanceCheckedSetter, | 20767 inst->SetAccessor(v8_str("foo"), InstanceCheckedGetter, InstanceCheckedSetter, |
20736 Local<Value>(), v8::DEFAULT, v8::None, | 20768 Local<Value>(), v8::DEFAULT, v8::None, |
20737 v8::AccessorSignature::New(context->GetIsolate(), templ)); | 20769 v8::AccessorSignature::New(context->GetIsolate(), templ)); |
20738 CHECK(context->Global() | 20770 CHECK(context->Global() |
20739 ->Set(context.local(), v8_str("f"), | 20771 ->Set(context.local(), v8_str("f"), |
20740 templ->GetFunction(context.local()).ToLocalChecked()) | 20772 templ->GetFunction(context.local()).ToLocalChecked()) |
20741 .FromJust()); | 20773 .FromJust()); |
20742 | 20774 |
20743 printf("Testing positive ...\n"); | 20775 printf("Testing positive ...\n"); |
20744 CompileRun("var obj = new f();"); | 20776 CompileRun("var obj = new f();"); |
20745 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); | 20777 CHECK(templ->HasInstance( |
20778 context->Global()->Get(context.local(), v8_str("obj")).ToLocalChecked())); | |
20746 CheckInstanceCheckedAccessors(true); | 20779 CheckInstanceCheckedAccessors(true); |
20747 | 20780 |
20748 printf("Testing negative ...\n"); | 20781 printf("Testing negative ...\n"); |
20749 CompileRun("var obj = {};" | 20782 CompileRun("var obj = {};" |
20750 "obj.__proto__ = new f();"); | 20783 "obj.__proto__ = new f();"); |
20751 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); | 20784 CHECK(!templ->HasInstance( |
20785 context->Global()->Get(context.local(), v8_str("obj")).ToLocalChecked())); | |
20752 CheckInstanceCheckedAccessors(false); | 20786 CheckInstanceCheckedAccessors(false); |
20753 } | 20787 } |
20754 | 20788 |
20755 | 20789 |
20756 THREADED_TEST(InstanceCheckOnPrototypeAccessor) { | 20790 THREADED_TEST(InstanceCheckOnPrototypeAccessor) { |
20757 v8::internal::FLAG_allow_natives_syntax = true; | 20791 v8::internal::FLAG_allow_natives_syntax = true; |
20758 LocalContext context; | 20792 LocalContext context; |
20759 v8::HandleScope scope(context->GetIsolate()); | 20793 v8::HandleScope scope(context->GetIsolate()); |
20760 | 20794 |
20761 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); | 20795 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); |
20762 Local<ObjectTemplate> proto = templ->PrototypeTemplate(); | 20796 Local<ObjectTemplate> proto = templ->PrototypeTemplate(); |
20763 proto->SetAccessor(v8_str("foo"), InstanceCheckedGetter, | 20797 proto->SetAccessor(v8_str("foo"), InstanceCheckedGetter, |
20764 InstanceCheckedSetter, Local<Value>(), v8::DEFAULT, | 20798 InstanceCheckedSetter, Local<Value>(), v8::DEFAULT, |
20765 v8::None, | 20799 v8::None, |
20766 v8::AccessorSignature::New(context->GetIsolate(), templ)); | 20800 v8::AccessorSignature::New(context->GetIsolate(), templ)); |
20767 CHECK(context->Global() | 20801 CHECK(context->Global() |
20768 ->Set(context.local(), v8_str("f"), | 20802 ->Set(context.local(), v8_str("f"), |
20769 templ->GetFunction(context.local()).ToLocalChecked()) | 20803 templ->GetFunction(context.local()).ToLocalChecked()) |
20770 .FromJust()); | 20804 .FromJust()); |
20771 | 20805 |
20772 printf("Testing positive ...\n"); | 20806 printf("Testing positive ...\n"); |
20773 CompileRun("var obj = new f();"); | 20807 CompileRun("var obj = new f();"); |
20774 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); | 20808 CHECK(templ->HasInstance( |
20809 context->Global()->Get(context.local(), v8_str("obj")).ToLocalChecked())); | |
20775 CheckInstanceCheckedAccessors(true); | 20810 CheckInstanceCheckedAccessors(true); |
20776 | 20811 |
20777 printf("Testing negative ...\n"); | 20812 printf("Testing negative ...\n"); |
20778 CompileRun("var obj = {};" | 20813 CompileRun("var obj = {};" |
20779 "obj.__proto__ = new f();"); | 20814 "obj.__proto__ = new f();"); |
20780 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); | 20815 CHECK(!templ->HasInstance( |
20816 context->Global()->Get(context.local(), v8_str("obj")).ToLocalChecked())); | |
20781 CheckInstanceCheckedAccessors(false); | 20817 CheckInstanceCheckedAccessors(false); |
20782 | 20818 |
20783 printf("Testing positive with modified prototype chain ...\n"); | 20819 printf("Testing positive with modified prototype chain ...\n"); |
20784 CompileRun("var obj = new f();" | 20820 CompileRun("var obj = new f();" |
20785 "var pro = {};" | 20821 "var pro = {};" |
20786 "pro.__proto__ = obj.__proto__;" | 20822 "pro.__proto__ = obj.__proto__;" |
20787 "obj.__proto__ = pro;"); | 20823 "obj.__proto__ = pro;"); |
20788 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); | 20824 CHECK(templ->HasInstance( |
20825 context->Global()->Get(context.local(), v8_str("obj")).ToLocalChecked())); | |
20789 CheckInstanceCheckedAccessors(true); | 20826 CheckInstanceCheckedAccessors(true); |
20790 } | 20827 } |
20791 | 20828 |
20792 | 20829 |
20793 TEST(TryFinallyMessage) { | 20830 TEST(TryFinallyMessage) { |
20794 LocalContext context; | 20831 LocalContext context; |
20795 v8::HandleScope scope(context->GetIsolate()); | 20832 v8::HandleScope scope(context->GetIsolate()); |
20796 { | 20833 { |
20797 // Test that the original error message is not lost if there is a | 20834 // Test that the original error message is not lost if there is a |
20798 // recursive call into Javascript is done in the finally block, e.g. to | 20835 // recursive call into Javascript is done in the finally block, e.g. to |
20799 // initialize an IC. (crbug.com/129171) | 20836 // initialize an IC. (crbug.com/129171) |
20800 TryCatch try_catch(context->GetIsolate()); | 20837 TryCatch try_catch(context->GetIsolate()); |
20801 const char* trigger_ic = | 20838 const char* trigger_ic = |
20802 "try { \n" | 20839 "try { \n" |
20803 " throw new Error('test'); \n" | 20840 " throw new Error('test'); \n" |
20804 "} finally { \n" | 20841 "} finally { \n" |
20805 " var x = 0; \n" | 20842 " var x = 0; \n" |
20806 " x++; \n" // Trigger an IC initialization here. | 20843 " x++; \n" // Trigger an IC initialization here. |
20807 "} \n"; | 20844 "} \n"; |
20808 CompileRun(trigger_ic); | 20845 CompileRun(trigger_ic); |
20809 CHECK(try_catch.HasCaught()); | 20846 CHECK(try_catch.HasCaught()); |
20810 Local<Message> message = try_catch.Message(); | 20847 Local<Message> message = try_catch.Message(); |
20811 CHECK(!message.IsEmpty()); | 20848 CHECK(!message.IsEmpty()); |
20812 CHECK_EQ(2, message->GetLineNumber()); | 20849 CHECK_EQ(2, message->GetLineNumber(context.local()).FromJust()); |
20813 } | 20850 } |
20814 | 20851 |
20815 { | 20852 { |
20816 // Test that the original exception message is indeed overwritten if | 20853 // Test that the original exception message is indeed overwritten if |
20817 // a new error is thrown in the finally block. | 20854 // a new error is thrown in the finally block. |
20818 TryCatch try_catch(context->GetIsolate()); | 20855 TryCatch try_catch(context->GetIsolate()); |
20819 const char* throw_again = | 20856 const char* throw_again = |
20820 "try { \n" | 20857 "try { \n" |
20821 " throw new Error('test'); \n" | 20858 " throw new Error('test'); \n" |
20822 "} finally { \n" | 20859 "} finally { \n" |
20823 " var x = 0; \n" | 20860 " var x = 0; \n" |
20824 " x++; \n" | 20861 " x++; \n" |
20825 " throw new Error('again'); \n" // This is the new uncaught error. | 20862 " throw new Error('again'); \n" // This is the new uncaught error. |
20826 "} \n"; | 20863 "} \n"; |
20827 CompileRun(throw_again); | 20864 CompileRun(throw_again); |
20828 CHECK(try_catch.HasCaught()); | 20865 CHECK(try_catch.HasCaught()); |
20829 Local<Message> message = try_catch.Message(); | 20866 Local<Message> message = try_catch.Message(); |
20830 CHECK(!message.IsEmpty()); | 20867 CHECK(!message.IsEmpty()); |
20831 CHECK_EQ(6, message->GetLineNumber()); | 20868 CHECK_EQ(6, message->GetLineNumber(context.local()).FromJust()); |
20832 } | 20869 } |
20833 } | 20870 } |
20834 | 20871 |
20835 | 20872 |
20836 static void Helper137002(bool do_store, | 20873 static void Helper137002(bool do_store, |
20837 bool polymorphic, | 20874 bool polymorphic, |
20838 bool remove_accessor, | 20875 bool remove_accessor, |
20839 bool interceptor) { | 20876 bool interceptor) { |
20840 LocalContext context; | 20877 LocalContext context; |
20841 Local<ObjectTemplate> templ = ObjectTemplate::New(context->GetIsolate()); | 20878 Local<ObjectTemplate> templ = ObjectTemplate::New(context->GetIsolate()); |
(...skipping 27 matching lines...) Expand all Loading... | |
20869 CompileRun("obj.y = void 0;" | 20906 CompileRun("obj.y = void 0;" |
20870 "%OptimizeFunctionOnNextCall(f);"); | 20907 "%OptimizeFunctionOnNextCall(f);"); |
20871 if (remove_accessor) { | 20908 if (remove_accessor) { |
20872 CompileRun("delete obj.foo;"); | 20909 CompileRun("delete obj.foo;"); |
20873 } | 20910 } |
20874 CompileRun("var result = f(obj);"); | 20911 CompileRun("var result = f(obj);"); |
20875 if (do_store) { | 20912 if (do_store) { |
20876 CompileRun("result = obj.y;"); | 20913 CompileRun("result = obj.y;"); |
20877 } | 20914 } |
20878 if (remove_accessor && !interceptor) { | 20915 if (remove_accessor && !interceptor) { |
20879 CHECK(context->Global()->Get(v8_str("result"))->IsUndefined()); | 20916 CHECK(context->Global() |
20917 ->Get(context.local(), v8_str("result")) | |
20918 .ToLocalChecked() | |
20919 ->IsUndefined()); | |
20880 } else { | 20920 } else { |
20881 CHECK_EQ(do_store ? 23 : 42, context->Global() | 20921 CHECK_EQ(do_store ? 23 : 42, context->Global() |
20882 ->Get(v8_str("result")) | 20922 ->Get(context.local(), v8_str("result")) |
20923 .ToLocalChecked() | |
20883 ->Int32Value(context.local()) | 20924 ->Int32Value(context.local()) |
20884 .FromJust()); | 20925 .FromJust()); |
20885 } | 20926 } |
20886 } | 20927 } |
20887 | 20928 |
20888 | 20929 |
20889 THREADED_TEST(Regress137002a) { | 20930 THREADED_TEST(Regress137002a) { |
20890 i::FLAG_allow_natives_syntax = true; | 20931 i::FLAG_allow_natives_syntax = true; |
20891 i::FLAG_compilation_cache = false; | 20932 i::FLAG_compilation_cache = false; |
20892 v8::HandleScope scope(CcTest::isolate()); | 20933 v8::HandleScope scope(CcTest::isolate()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
20952 "subobj.y = void 0;" | 20993 "subobj.y = void 0;" |
20953 | 20994 |
20954 "var load_result = load(obj);" | 20995 "var load_result = load(obj);" |
20955 "var load_result2 = load2(subobj);" | 20996 "var load_result2 = load2(subobj);" |
20956 "var keyed_load_result = keyed_load(obj, 'foo');" | 20997 "var keyed_load_result = keyed_load(obj, 'foo');" |
20957 "var keyed_load_result2 = keyed_load2(subobj, 'foo');" | 20998 "var keyed_load_result2 = keyed_load2(subobj, 'foo');" |
20958 "store(obj);" | 20999 "store(obj);" |
20959 "store2(subobj);" | 21000 "store2(subobj);" |
20960 "var y_from_obj = obj.y;" | 21001 "var y_from_obj = obj.y;" |
20961 "var y_from_subobj = subobj.y;"); | 21002 "var y_from_subobj = subobj.y;"); |
20962 CHECK(context->Global()->Get(v8_str("load_result"))->IsUndefined()); | 21003 CHECK(context->Global() |
20963 CHECK(context->Global()->Get(v8_str("load_result2"))->IsUndefined()); | 21004 ->Get(context.local(), v8_str("load_result")) |
20964 CHECK(context->Global()->Get(v8_str("keyed_load_result"))->IsUndefined()); | 21005 .ToLocalChecked() |
20965 CHECK(context->Global()->Get(v8_str("keyed_load_result2"))->IsUndefined()); | 21006 ->IsUndefined()); |
20966 CHECK(context->Global()->Get(v8_str("y_from_obj"))->IsUndefined()); | 21007 CHECK(context->Global() |
20967 CHECK(context->Global()->Get(v8_str("y_from_subobj"))->IsUndefined()); | 21008 ->Get(context.local(), v8_str("load_result2")) |
21009 .ToLocalChecked() | |
21010 ->IsUndefined()); | |
21011 CHECK(context->Global() | |
21012 ->Get(context.local(), v8_str("keyed_load_result")) | |
21013 .ToLocalChecked() | |
21014 ->IsUndefined()); | |
21015 CHECK(context->Global() | |
21016 ->Get(context.local(), v8_str("keyed_load_result2")) | |
21017 .ToLocalChecked() | |
21018 ->IsUndefined()); | |
21019 CHECK(context->Global() | |
21020 ->Get(context.local(), v8_str("y_from_obj")) | |
21021 .ToLocalChecked() | |
21022 ->IsUndefined()); | |
21023 CHECK(context->Global() | |
21024 ->Get(context.local(), v8_str("y_from_subobj")) | |
21025 .ToLocalChecked() | |
21026 ->IsUndefined()); | |
20968 } | 21027 } |
20969 | 21028 |
20970 | 21029 |
20971 THREADED_TEST(Regress142088) { | 21030 THREADED_TEST(Regress142088) { |
20972 i::FLAG_allow_natives_syntax = true; | 21031 i::FLAG_allow_natives_syntax = true; |
20973 LocalContext context; | 21032 LocalContext context; |
20974 v8::Isolate* isolate = context->GetIsolate(); | 21033 v8::Isolate* isolate = context->GetIsolate(); |
20975 v8::HandleScope scope(isolate); | 21034 v8::HandleScope scope(isolate); |
20976 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 21035 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
20977 templ->SetAccessor(v8_str("foo"), | 21036 templ->SetAccessor(v8_str("foo"), |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
21052 Local<Function> function = | 21111 Local<Function> function = |
21053 templ->GetFunction(context.local()).ToLocalChecked(); | 21112 templ->GetFunction(context.local()).ToLocalChecked(); |
21054 CHECK(!function.IsEmpty()); | 21113 CHECK(!function.IsEmpty()); |
21055 CHECK(function->IsFunction()); | 21114 CHECK(function->IsFunction()); |
21056 } | 21115 } |
21057 | 21116 |
21058 | 21117 |
21059 THREADED_TEST(JSONParseObject) { | 21118 THREADED_TEST(JSONParseObject) { |
21060 LocalContext context; | 21119 LocalContext context; |
21061 HandleScope scope(context->GetIsolate()); | 21120 HandleScope scope(context->GetIsolate()); |
21062 Local<Value> obj = v8::JSON::Parse(v8_str("{\"x\":42}")); | 21121 Local<Value> obj = |
21122 v8::JSON::Parse(context->GetIsolate(), v8_str("{\"x\":42}")) | |
21123 .ToLocalChecked(); | |
21063 Local<Object> global = context->Global(); | 21124 Local<Object> global = context->Global(); |
21064 global->Set(v8_str("obj"), obj); | 21125 global->Set(context.local(), v8_str("obj"), obj).FromJust(); |
21065 ExpectString("JSON.stringify(obj)", "{\"x\":42}"); | 21126 ExpectString("JSON.stringify(obj)", "{\"x\":42}"); |
21066 } | 21127 } |
21067 | 21128 |
21068 | 21129 |
21069 THREADED_TEST(JSONParseNumber) { | 21130 THREADED_TEST(JSONParseNumber) { |
21070 LocalContext context; | 21131 LocalContext context; |
21071 HandleScope scope(context->GetIsolate()); | 21132 HandleScope scope(context->GetIsolate()); |
21072 Local<Value> obj = v8::JSON::Parse(v8_str("42")); | 21133 Local<Value> obj = |
21134 v8::JSON::Parse(context->GetIsolate(), v8_str("42")).ToLocalChecked(); | |
21073 Local<Object> global = context->Global(); | 21135 Local<Object> global = context->Global(); |
21074 global->Set(v8_str("obj"), obj); | 21136 global->Set(context.local(), v8_str("obj"), obj).FromJust(); |
21075 ExpectString("JSON.stringify(obj)", "42"); | 21137 ExpectString("JSON.stringify(obj)", "42"); |
21076 } | 21138 } |
21077 | 21139 |
21078 | 21140 |
21079 #if V8_OS_POSIX && !V8_OS_NACL | 21141 #if V8_OS_POSIX && !V8_OS_NACL |
21080 class ThreadInterruptTest { | 21142 class ThreadInterruptTest { |
21081 public: | 21143 public: |
21082 ThreadInterruptTest() : sem_(0), sem_value_(0) { } | 21144 ThreadInterruptTest() : sem_(0), sem_value_(0) { } |
21083 ~ThreadInterruptTest() {} | 21145 ~ThreadInterruptTest() {} |
21084 | 21146 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
21152 | 21214 |
21153 // Create an ObjectTemplate for global objects and install access | 21215 // Create an ObjectTemplate for global objects and install access |
21154 // check callbacks that will block access. | 21216 // check callbacks that will block access. |
21155 v8::Local<v8::ObjectTemplate> global_template = | 21217 v8::Local<v8::ObjectTemplate> global_template = |
21156 v8::ObjectTemplate::New(isolate); | 21218 v8::ObjectTemplate::New(isolate); |
21157 global_template->SetAccessCheckCallback(AccessAlwaysBlocked); | 21219 global_template->SetAccessCheckCallback(AccessAlwaysBlocked); |
21158 | 21220 |
21159 // Create a context and set an x property on it's global object. | 21221 // Create a context and set an x property on it's global object. |
21160 LocalContext context0(NULL, global_template); | 21222 LocalContext context0(NULL, global_template); |
21161 v8::Local<v8::Object> global0 = context0->Global(); | 21223 v8::Local<v8::Object> global0 = context0->Global(); |
21162 global0->Set(v8_str("x"), v8_num(42)); | 21224 global0->Set(context0.local(), v8_str("x"), v8_num(42)).FromJust(); |
21163 ExpectString("JSON.stringify(this)", "{\"x\":42}"); | 21225 ExpectString("JSON.stringify(this)", "{\"x\":42}"); |
21164 | 21226 |
21165 for (int i = 0; i < 2; i++) { | 21227 for (int i = 0; i < 2; i++) { |
21166 if (i == 1) { | 21228 if (i == 1) { |
21167 // Install a toJSON function on the second run. | 21229 // Install a toJSON function on the second run. |
21168 v8::Local<v8::FunctionTemplate> toJSON = | 21230 v8::Local<v8::FunctionTemplate> toJSON = |
21169 v8::FunctionTemplate::New(isolate, UnreachableCallback); | 21231 v8::FunctionTemplate::New(isolate, UnreachableCallback); |
21170 | 21232 |
21171 global0->Set(v8_str("toJSON"), | 21233 global0->Set(context0.local(), v8_str("toJSON"), |
21172 toJSON->GetFunction(context0.local()).ToLocalChecked()); | 21234 toJSON->GetFunction(context0.local()).ToLocalChecked()) |
21235 .FromJust(); | |
21173 } | 21236 } |
21174 // Create a context with a different security token so that the | 21237 // Create a context with a different security token so that the |
21175 // failed access check callback will be called on each access. | 21238 // failed access check callback will be called on each access. |
21176 LocalContext context1(NULL, global_template); | 21239 LocalContext context1(NULL, global_template); |
21177 CHECK(context1->Global() | 21240 CHECK(context1->Global() |
21178 ->Set(context1.local(), v8_str("other"), global0) | 21241 ->Set(context1.local(), v8_str("other"), global0) |
21179 .FromJust()); | 21242 .FromJust()); |
21180 | 21243 |
21181 CHECK(CompileRun("JSON.stringify(other)").IsEmpty()); | 21244 CHECK(CompileRun("JSON.stringify(other)").IsEmpty()); |
21182 CHECK(CompileRun("JSON.stringify({ 'a' : other, 'b' : ['c'] })").IsEmpty()); | 21245 CHECK(CompileRun("JSON.stringify({ 'a' : other, 'b' : ['c'] })").IsEmpty()); |
(...skipping 19 matching lines...) Expand all Loading... | |
21202 | 21265 |
21203 void CatcherCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { | 21266 void CatcherCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { |
21204 for (int i = 0; i < args.Length(); i++) { | 21267 for (int i = 0; i < args.Length(); i++) { |
21205 i::PrintF("%s\n", *String::Utf8Value(args[i])); | 21268 i::PrintF("%s\n", *String::Utf8Value(args[i])); |
21206 } | 21269 } |
21207 catch_callback_called = true; | 21270 catch_callback_called = true; |
21208 } | 21271 } |
21209 | 21272 |
21210 | 21273 |
21211 void HasOwnPropertyCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { | 21274 void HasOwnPropertyCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { |
21212 args[0]->ToObject(args.GetIsolate())->HasOwnProperty( | 21275 v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext(); |
21213 args[1]->ToString(args.GetIsolate())); | 21276 CHECK( |
21277 args[0] | |
21278 ->ToObject(context) | |
21279 .ToLocalChecked() | |
21280 ->HasOwnProperty(context, args[1]->ToString(context).ToLocalChecked()) | |
21281 .IsNothing()); | |
vogelheim
2015/12/11 15:19:03
Why does this CHECK(... IsNothing)?
(I trust it's
jochen (gone - plz use gerrit)
2015/12/11 15:27:41
it's part of a test that installs an access checke
| |
21214 } | 21282 } |
21215 | 21283 |
21216 | 21284 |
21217 void CheckCorrectThrow(const char* script) { | 21285 void CheckCorrectThrow(const char* script) { |
21218 // Test that the script, when wrapped into a try-catch, triggers the catch | 21286 // Test that the script, when wrapped into a try-catch, triggers the catch |
21219 // clause due to failed access check throwing an exception. | 21287 // clause due to failed access check throwing an exception. |
21220 // The subsequent try-catch should run without any exception. | 21288 // The subsequent try-catch should run without any exception. |
21221 access_check_fail_thrown = false; | 21289 access_check_fail_thrown = false; |
21222 catch_callback_called = false; | 21290 catch_callback_called = false; |
21223 i::ScopedVector<char> source(1024); | 21291 i::ScopedVector<char> source(1024); |
21224 i::SNPrintF(source, "try { %s; } catch (e) { catcher(e); }", script); | 21292 i::SNPrintF(source, "try { %s; } catch (e) { catcher(e); }", script); |
21225 CompileRun(source.start()); | 21293 CompileRun(source.start()); |
21226 CHECK(access_check_fail_thrown); | 21294 CHECK(access_check_fail_thrown); |
21227 CHECK(catch_callback_called); | 21295 CHECK(catch_callback_called); |
21228 | 21296 |
21229 access_check_fail_thrown = false; | 21297 access_check_fail_thrown = false; |
21230 catch_callback_called = false; | 21298 catch_callback_called = false; |
21231 CompileRun("try { [1, 2, 3].sort(); } catch (e) { catcher(e) };"); | 21299 CompileRun("try { [1, 2, 3].sort(); } catch (e) { catcher(e) };"); |
21232 CHECK(!access_check_fail_thrown); | 21300 CHECK(!access_check_fail_thrown); |
21233 CHECK(!catch_callback_called); | 21301 CHECK(!catch_callback_called); |
21234 } | 21302 } |
21235 | 21303 |
21236 | 21304 |
21237 TEST(AccessCheckThrows) { | 21305 TEST(AccessCheckThrows) { |
21238 i::FLAG_allow_natives_syntax = true; | 21306 i::FLAG_allow_natives_syntax = true; |
21239 v8::V8::Initialize(); | 21307 v8::V8::Initialize(); |
21240 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckThrows); | |
21241 v8::Isolate* isolate = CcTest::isolate(); | 21308 v8::Isolate* isolate = CcTest::isolate(); |
21309 isolate->SetFailedAccessCheckCallbackFunction(&FailedAccessCheckThrows); | |
21242 v8::HandleScope scope(isolate); | 21310 v8::HandleScope scope(isolate); |
21243 | 21311 |
21244 // Create an ObjectTemplate for global objects and install access | 21312 // Create an ObjectTemplate for global objects and install access |
21245 // check callbacks that will block access. | 21313 // check callbacks that will block access. |
21246 v8::Local<v8::ObjectTemplate> global_template = | 21314 v8::Local<v8::ObjectTemplate> global_template = |
21247 v8::ObjectTemplate::New(isolate); | 21315 v8::ObjectTemplate::New(isolate); |
21248 global_template->SetAccessCheckCallback(AccessAlwaysBlocked); | 21316 global_template->SetAccessCheckCallback(AccessAlwaysBlocked); |
21249 | 21317 |
21250 // Create a context and set an x property on it's global object. | 21318 // Create a context and set an x property on it's global object. |
21251 LocalContext context0(NULL, global_template); | 21319 LocalContext context0(NULL, global_template); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
21294 CheckCorrectThrow("%DeleteProperty_Strict(other, '1')"); | 21362 CheckCorrectThrow("%DeleteProperty_Strict(other, '1')"); |
21295 CheckCorrectThrow("%HasOwnProperty(other, 'x')"); | 21363 CheckCorrectThrow("%HasOwnProperty(other, 'x')"); |
21296 CheckCorrectThrow("%HasProperty('x', other)"); | 21364 CheckCorrectThrow("%HasProperty('x', other)"); |
21297 CheckCorrectThrow("%PropertyIsEnumerable(other, 'x')"); | 21365 CheckCorrectThrow("%PropertyIsEnumerable(other, 'x')"); |
21298 // PROPERTY_ATTRIBUTES_NONE = 0 | 21366 // PROPERTY_ATTRIBUTES_NONE = 0 |
21299 CheckCorrectThrow("%DefineAccessorPropertyUnchecked(" | 21367 CheckCorrectThrow("%DefineAccessorPropertyUnchecked(" |
21300 "other, 'x', null, null, 1)"); | 21368 "other, 'x', null, null, 1)"); |
21301 | 21369 |
21302 // Reset the failed access check callback so it does not influence | 21370 // Reset the failed access check callback so it does not influence |
21303 // the other tests. | 21371 // the other tests. |
21304 v8::V8::SetFailedAccessCheckCallbackFunction(NULL); | 21372 isolate->SetFailedAccessCheckCallbackFunction(NULL); |
21305 } | 21373 } |
21306 | 21374 |
21307 | 21375 |
21308 class RequestInterruptTestBase { | 21376 class RequestInterruptTestBase { |
21309 public: | 21377 public: |
21310 RequestInterruptTestBase() | 21378 RequestInterruptTestBase() |
21311 : env_(), | 21379 : env_(), |
21312 isolate_(env_->GetIsolate()), | 21380 isolate_(env_->GetIsolate()), |
21313 sem_(0), | 21381 sem_(0), |
21314 warmup_(20000), | 21382 warmup_(20000), |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
21395 }; | 21463 }; |
21396 | 21464 |
21397 InterruptThread i_thread; | 21465 InterruptThread i_thread; |
21398 }; | 21466 }; |
21399 | 21467 |
21400 | 21468 |
21401 class RequestInterruptTestWithFunctionCall | 21469 class RequestInterruptTestWithFunctionCall |
21402 : public RequestInterruptTestBaseWithSimpleInterrupt { | 21470 : public RequestInterruptTestBaseWithSimpleInterrupt { |
21403 public: | 21471 public: |
21404 virtual void TestBody() { | 21472 virtual void TestBody() { |
21405 Local<Function> func = Function::New( | 21473 Local<Function> func = Function::New(env_.local(), ShouldContinueCallback, |
21406 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this)); | 21474 v8::External::New(isolate_, this)) |
21475 .ToLocalChecked(); | |
21407 CHECK(env_->Global() | 21476 CHECK(env_->Global() |
21408 ->Set(env_.local(), v8_str("ShouldContinue"), func) | 21477 ->Set(env_.local(), v8_str("ShouldContinue"), func) |
21409 .FromJust()); | 21478 .FromJust()); |
21410 | 21479 |
21411 CompileRun("while (ShouldContinue()) { }"); | 21480 CompileRun("while (ShouldContinue()) { }"); |
21412 } | 21481 } |
21413 }; | 21482 }; |
21414 | 21483 |
21415 | 21484 |
21416 class RequestInterruptTestWithMethodCall | 21485 class RequestInterruptTestWithMethodCall |
21417 : public RequestInterruptTestBaseWithSimpleInterrupt { | 21486 : public RequestInterruptTestBaseWithSimpleInterrupt { |
21418 public: | 21487 public: |
21419 virtual void TestBody() { | 21488 virtual void TestBody() { |
21420 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); | 21489 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); |
21421 v8::Local<v8::Template> proto = t->PrototypeTemplate(); | 21490 v8::Local<v8::Template> proto = t->PrototypeTemplate(); |
21422 proto->Set(v8_str("shouldContinue"), Function::New( | 21491 proto->Set(v8_str("shouldContinue"), |
21423 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); | 21492 Function::New(env_.local(), ShouldContinueCallback, |
21493 v8::External::New(isolate_, this)) | |
21494 .ToLocalChecked()); | |
21424 CHECK(env_->Global() | 21495 CHECK(env_->Global() |
21425 ->Set(env_.local(), v8_str("Klass"), | 21496 ->Set(env_.local(), v8_str("Klass"), |
21426 t->GetFunction(env_.local()).ToLocalChecked()) | 21497 t->GetFunction(env_.local()).ToLocalChecked()) |
21427 .FromJust()); | 21498 .FromJust()); |
21428 | 21499 |
21429 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); | 21500 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); |
21430 } | 21501 } |
21431 }; | 21502 }; |
21432 | 21503 |
21433 | 21504 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
21478 } | 21549 } |
21479 }; | 21550 }; |
21480 | 21551 |
21481 | 21552 |
21482 class RequestInterruptTestWithMethodCallAndInterceptor | 21553 class RequestInterruptTestWithMethodCallAndInterceptor |
21483 : public RequestInterruptTestBaseWithSimpleInterrupt { | 21554 : public RequestInterruptTestBaseWithSimpleInterrupt { |
21484 public: | 21555 public: |
21485 virtual void TestBody() { | 21556 virtual void TestBody() { |
21486 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); | 21557 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); |
21487 v8::Local<v8::Template> proto = t->PrototypeTemplate(); | 21558 v8::Local<v8::Template> proto = t->PrototypeTemplate(); |
21488 proto->Set(v8_str("shouldContinue"), Function::New( | 21559 proto->Set(v8_str("shouldContinue"), |
21489 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); | 21560 Function::New(env_.local(), ShouldContinueCallback, |
21561 v8::External::New(isolate_, this)) | |
21562 .ToLocalChecked()); | |
21490 v8::Local<v8::ObjectTemplate> instance_template = t->InstanceTemplate(); | 21563 v8::Local<v8::ObjectTemplate> instance_template = t->InstanceTemplate(); |
21491 instance_template->SetHandler( | 21564 instance_template->SetHandler( |
21492 v8::NamedPropertyHandlerConfiguration(EmptyInterceptor)); | 21565 v8::NamedPropertyHandlerConfiguration(EmptyInterceptor)); |
21493 | 21566 |
21494 CHECK(env_->Global() | 21567 CHECK(env_->Global() |
21495 ->Set(env_.local(), v8_str("Klass"), | 21568 ->Set(env_.local(), v8_str("Klass"), |
21496 t->GetFunction(env_.local()).ToLocalChecked()) | 21569 t->GetFunction(env_.local()).ToLocalChecked()) |
21497 .FromJust()); | 21570 .FromJust()); |
21498 | 21571 |
21499 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); | 21572 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); |
21500 } | 21573 } |
21501 | 21574 |
21502 private: | 21575 private: |
21503 static void EmptyInterceptor( | 21576 static void EmptyInterceptor( |
21504 Local<Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) {} | 21577 Local<Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) {} |
21505 }; | 21578 }; |
21506 | 21579 |
21507 | 21580 |
21508 class RequestInterruptTestWithMathAbs | 21581 class RequestInterruptTestWithMathAbs |
21509 : public RequestInterruptTestBaseWithSimpleInterrupt { | 21582 : public RequestInterruptTestBaseWithSimpleInterrupt { |
21510 public: | 21583 public: |
21511 virtual void TestBody() { | 21584 virtual void TestBody() { |
21512 env_->Global()->Set(v8_str("WakeUpInterruptor"), Function::New( | 21585 env_->Global() |
21513 isolate_, | 21586 ->Set(env_.local(), v8_str("WakeUpInterruptor"), |
21514 WakeUpInterruptorCallback, | 21587 Function::New(env_.local(), WakeUpInterruptorCallback, |
21515 v8::External::New(isolate_, this))); | 21588 v8::External::New(isolate_, this)) |
21589 .ToLocalChecked()) | |
21590 .FromJust(); | |
21516 | 21591 |
21517 env_->Global()->Set(v8_str("ShouldContinue"), Function::New( | 21592 env_->Global() |
21518 isolate_, | 21593 ->Set(env_.local(), v8_str("ShouldContinue"), |
21519 ShouldContinueCallback, | 21594 Function::New(env_.local(), ShouldContinueCallback, |
21520 v8::External::New(isolate_, this))); | 21595 v8::External::New(isolate_, this)) |
21596 .ToLocalChecked()) | |
21597 .FromJust(); | |
21521 | 21598 |
21522 i::FLAG_allow_natives_syntax = true; | 21599 i::FLAG_allow_natives_syntax = true; |
21523 CompileRun("function loopish(o) {" | 21600 CompileRun("function loopish(o) {" |
21524 " var pre = 10;" | 21601 " var pre = 10;" |
21525 " while (o.abs(1) > 0) {" | 21602 " while (o.abs(1) > 0) {" |
21526 " if (o.abs(1) >= 0 && !ShouldContinue()) break;" | 21603 " if (o.abs(1) >= 0 && !ShouldContinue()) break;" |
21527 " if (pre > 0) {" | 21604 " if (pre > 0) {" |
21528 " if (--pre === 0) WakeUpInterruptor(o === Math);" | 21605 " if (--pre === 0) WakeUpInterruptor(o === Math);" |
21529 " }" | 21606 " }" |
21530 " }" | 21607 " }" |
21531 "}" | 21608 "}" |
21532 "var i = 50;" | 21609 "var i = 50;" |
21533 "var obj = {abs: function () { return i-- }, x: null};" | 21610 "var obj = {abs: function () { return i-- }, x: null};" |
21534 "delete obj.x;" | 21611 "delete obj.x;" |
21535 "loopish(obj);" | 21612 "loopish(obj);" |
21536 "%OptimizeFunctionOnNextCall(loopish);" | 21613 "%OptimizeFunctionOnNextCall(loopish);" |
21537 "loopish(Math);"); | 21614 "loopish(Math);"); |
21538 | 21615 |
21539 i::FLAG_allow_natives_syntax = false; | 21616 i::FLAG_allow_natives_syntax = false; |
21540 } | 21617 } |
21541 | 21618 |
21542 private: | 21619 private: |
21543 static void WakeUpInterruptorCallback( | 21620 static void WakeUpInterruptorCallback( |
21544 const v8::FunctionCallbackInfo<Value>& info) { | 21621 const v8::FunctionCallbackInfo<Value>& info) { |
21545 if (!info[0]->BooleanValue()) return; | 21622 if (!info[0] |
21623 ->BooleanValue(info.GetIsolate()->GetCurrentContext()) | |
21624 .FromJust()) { | |
21625 return; | |
21626 } | |
21546 | 21627 |
21547 RequestInterruptTestBase* test = | 21628 RequestInterruptTestBase* test = |
21548 reinterpret_cast<RequestInterruptTestBase*>( | 21629 reinterpret_cast<RequestInterruptTestBase*>( |
21549 info.Data().As<v8::External>()->Value()); | 21630 info.Data().As<v8::External>()->Value()); |
21550 test->WakeUpInterruptor(); | 21631 test->WakeUpInterruptor(); |
21551 } | 21632 } |
21552 | 21633 |
21553 static void ShouldContinueCallback( | 21634 static void ShouldContinueCallback( |
21554 const v8::FunctionCallbackInfo<Value>& info) { | 21635 const v8::FunctionCallbackInfo<Value>& info) { |
21555 RequestInterruptTestBase* test = | 21636 RequestInterruptTestBase* test = |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
21592 | 21673 |
21593 class RequestMultipleInterrupts : public RequestInterruptTestBase { | 21674 class RequestMultipleInterrupts : public RequestInterruptTestBase { |
21594 public: | 21675 public: |
21595 RequestMultipleInterrupts() : i_thread(this), counter_(0) {} | 21676 RequestMultipleInterrupts() : i_thread(this), counter_(0) {} |
21596 | 21677 |
21597 virtual void StartInterruptThread() { | 21678 virtual void StartInterruptThread() { |
21598 i_thread.Start(); | 21679 i_thread.Start(); |
21599 } | 21680 } |
21600 | 21681 |
21601 virtual void TestBody() { | 21682 virtual void TestBody() { |
21602 Local<Function> func = Function::New( | 21683 Local<Function> func = Function::New(env_.local(), ShouldContinueCallback, |
21603 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this)); | 21684 v8::External::New(isolate_, this)) |
21685 .ToLocalChecked(); | |
21604 CHECK(env_->Global() | 21686 CHECK(env_->Global() |
21605 ->Set(env_.local(), v8_str("ShouldContinue"), func) | 21687 ->Set(env_.local(), v8_str("ShouldContinue"), func) |
21606 .FromJust()); | 21688 .FromJust()); |
21607 | 21689 |
21608 CompileRun("while (ShouldContinue()) { }"); | 21690 CompileRun("while (ShouldContinue()) { }"); |
21609 } | 21691 } |
21610 | 21692 |
21611 private: | 21693 private: |
21612 class InterruptThread : public v8::base::Thread { | 21694 class InterruptThread : public v8::base::Thread { |
21613 public: | 21695 public: |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
21655 | 21737 |
21656 interrupt_was_called = false; | 21738 interrupt_was_called = false; |
21657 isolate->RequestInterrupt(&SmallScriptsInterruptCallback, NULL); | 21739 isolate->RequestInterrupt(&SmallScriptsInterruptCallback, NULL); |
21658 CompileRun("(function(x){return x;})(1);"); | 21740 CompileRun("(function(x){return x;})(1);"); |
21659 CHECK(interrupt_was_called); | 21741 CHECK(interrupt_was_called); |
21660 } | 21742 } |
21661 | 21743 |
21662 | 21744 |
21663 static Local<Value> function_new_expected_env; | 21745 static Local<Value> function_new_expected_env; |
21664 static void FunctionNewCallback(const v8::FunctionCallbackInfo<Value>& info) { | 21746 static void FunctionNewCallback(const v8::FunctionCallbackInfo<Value>& info) { |
21665 CHECK(function_new_expected_env->Equals(info.Data())); | 21747 CHECK( |
21748 function_new_expected_env->Equals(info.GetIsolate()->GetCurrentContext(), | |
21749 info.Data()) | |
21750 .FromJust()); | |
21666 info.GetReturnValue().Set(17); | 21751 info.GetReturnValue().Set(17); |
21667 } | 21752 } |
21668 | 21753 |
21669 | 21754 |
21670 THREADED_TEST(FunctionNew) { | 21755 THREADED_TEST(FunctionNew) { |
21671 LocalContext env; | 21756 LocalContext env; |
21672 v8::Isolate* isolate = env->GetIsolate(); | 21757 v8::Isolate* isolate = env->GetIsolate(); |
21673 v8::HandleScope scope(isolate); | 21758 v8::HandleScope scope(isolate); |
21674 Local<Object> data = v8::Object::New(isolate); | 21759 Local<Object> data = v8::Object::New(isolate); |
21675 function_new_expected_env = data; | 21760 function_new_expected_env = data; |
21676 Local<Function> func = Function::New(isolate, FunctionNewCallback, data); | 21761 Local<Function> func = |
21762 Function::New(env.local(), FunctionNewCallback, data).ToLocalChecked(); | |
21677 CHECK(env->Global()->Set(env.local(), v8_str("func"), func).FromJust()); | 21763 CHECK(env->Global()->Set(env.local(), v8_str("func"), func).FromJust()); |
21678 Local<Value> result = CompileRun("func();"); | 21764 Local<Value> result = CompileRun("func();"); |
21679 CHECK(v8::Integer::New(isolate, 17)->Equals(result)); | 21765 CHECK(v8::Integer::New(isolate, 17)->Equals(env.local(), result).FromJust()); |
21680 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 21766 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
21681 // Verify function not cached | 21767 // Verify function not cached |
21682 auto serial_number = handle( | 21768 auto serial_number = handle( |
21683 i::Smi::cast(i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*func)) | 21769 i::Smi::cast(i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*func)) |
21684 ->shared() | 21770 ->shared() |
21685 ->get_api_func_data() | 21771 ->get_api_func_data() |
21686 ->serial_number()), | 21772 ->serial_number()), |
21687 i_isolate); | 21773 i_isolate); |
21688 auto cache = i_isolate->function_cache(); | 21774 auto cache = i_isolate->function_cache(); |
21689 CHECK(cache->Lookup(serial_number)->IsTheHole()); | 21775 CHECK(cache->Lookup(serial_number)->IsTheHole()); |
21690 // Verify that each Function::New creates a new function instance | 21776 // Verify that each Function::New creates a new function instance |
21691 Local<Object> data2 = v8::Object::New(isolate); | 21777 Local<Object> data2 = v8::Object::New(isolate); |
21692 function_new_expected_env = data2; | 21778 function_new_expected_env = data2; |
21693 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2); | 21779 Local<Function> func2 = |
21780 Function::New(env.local(), FunctionNewCallback, data2).ToLocalChecked(); | |
21694 CHECK(!func2->IsNull()); | 21781 CHECK(!func2->IsNull()); |
21695 CHECK(!func->Equals(func2)); | 21782 CHECK(!func->Equals(env.local(), func2).FromJust()); |
21696 CHECK(env->Global()->Set(env.local(), v8_str("func2"), func2).FromJust()); | 21783 CHECK(env->Global()->Set(env.local(), v8_str("func2"), func2).FromJust()); |
21697 Local<Value> result2 = CompileRun("func2();"); | 21784 Local<Value> result2 = CompileRun("func2();"); |
21698 CHECK(v8::Integer::New(isolate, 17)->Equals(result2)); | 21785 CHECK(v8::Integer::New(isolate, 17)->Equals(env.local(), result2).FromJust()); |
21699 } | 21786 } |
21700 | 21787 |
21701 | 21788 |
21702 TEST(EscapeableHandleScope) { | 21789 TEST(EscapeableHandleScope) { |
21703 HandleScope outer_scope(CcTest::isolate()); | 21790 HandleScope outer_scope(CcTest::isolate()); |
21704 LocalContext context; | 21791 LocalContext context; |
21705 const int runs = 10; | 21792 const int runs = 10; |
21706 Local<String> values[runs]; | 21793 Local<String> values[runs]; |
21707 for (int i = 0; i < runs; i++) { | 21794 for (int i = 0; i < runs; i++) { |
21708 v8::EscapableHandleScope inner_scope(CcTest::isolate()); | 21795 v8::EscapableHandleScope inner_scope(CcTest::isolate()); |
21709 Local<String> value; | 21796 Local<String> value; |
21710 if (i != 0) value = v8_str("escape value"); | 21797 if (i != 0) value = v8_str("escape value"); |
21711 values[i] = inner_scope.Escape(value); | 21798 values[i] = inner_scope.Escape(value); |
21712 } | 21799 } |
21713 for (int i = 0; i < runs; i++) { | 21800 for (int i = 0; i < runs; i++) { |
21714 Local<String> expected; | 21801 Local<String> expected; |
21715 if (i != 0) { | 21802 if (i != 0) { |
21716 CHECK(v8_str("escape value")->Equals(values[i])); | 21803 CHECK(v8_str("escape value") |
21804 ->Equals(context.local(), values[i]) | |
21805 .FromJust()); | |
21717 } else { | 21806 } else { |
21718 CHECK(values[i].IsEmpty()); | 21807 CHECK(values[i].IsEmpty()); |
21719 } | 21808 } |
21720 } | 21809 } |
21721 } | 21810 } |
21722 | 21811 |
21723 | 21812 |
21724 static void SetterWhichExpectsThisAndHolderToDiffer( | 21813 static void SetterWhichExpectsThisAndHolderToDiffer( |
21725 Local<String>, Local<Value>, const v8::PropertyCallbackInfo<void>& info) { | 21814 Local<String>, Local<Value>, const v8::PropertyCallbackInfo<void>& info) { |
21726 CHECK(info.Holder() != info.This()); | 21815 CHECK(info.Holder() != info.This()); |
(...skipping 28 matching lines...) Expand all Loading... | |
21755 static Local<Object> holder; | 21844 static Local<Object> holder; |
21756 static Local<Object> callee; | 21845 static Local<Object> callee; |
21757 static int count; | 21846 static int count; |
21758 | 21847 |
21759 static void OptimizationCallback( | 21848 static void OptimizationCallback( |
21760 const v8::FunctionCallbackInfo<v8::Value>& info) { | 21849 const v8::FunctionCallbackInfo<v8::Value>& info) { |
21761 CHECK(callee == info.Callee()); | 21850 CHECK(callee == info.Callee()); |
21762 CHECK(data == info.Data()); | 21851 CHECK(data == info.Data()); |
21763 CHECK(receiver == info.This()); | 21852 CHECK(receiver == info.This()); |
21764 if (info.Length() == 1) { | 21853 if (info.Length() == 1) { |
21765 CHECK(v8_num(1)->Equals(info[0])); | 21854 CHECK(v8_num(1) |
21855 ->Equals(info.GetIsolate()->GetCurrentContext(), info[0]) | |
21856 .FromJust()); | |
21766 } | 21857 } |
21767 CHECK(holder == info.Holder()); | 21858 CHECK(holder == info.Holder()); |
21768 count++; | 21859 count++; |
21769 info.GetReturnValue().Set(v8_str("returned")); | 21860 info.GetReturnValue().Set(v8_str("returned")); |
21770 } | 21861 } |
21771 | 21862 |
21772 public: | 21863 public: |
21773 enum SignatureType { | 21864 enum SignatureType { |
21774 kNoSignature, | 21865 kNoSignature, |
21775 kSignatureOnReceiver, | 21866 kSignatureOnReceiver, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
21833 Local<FunctionTemplate> function_template = FunctionTemplate::New( | 21924 Local<FunctionTemplate> function_template = FunctionTemplate::New( |
21834 isolate, OptimizationCallback, data, signature); | 21925 isolate, OptimizationCallback, data, signature); |
21835 Local<Function> function = | 21926 Local<Function> function = |
21836 function_template->GetFunction(context).ToLocalChecked(); | 21927 function_template->GetFunction(context).ToLocalChecked(); |
21837 Local<Object> global_holder = inner_global; | 21928 Local<Object> global_holder = inner_global; |
21838 Local<Object> function_holder = function_receiver; | 21929 Local<Object> function_holder = function_receiver; |
21839 if (signature_type == kSignatureOnPrototype) { | 21930 if (signature_type == kSignatureOnPrototype) { |
21840 function_holder = Local<Object>::Cast(function_holder->GetPrototype()); | 21931 function_holder = Local<Object>::Cast(function_holder->GetPrototype()); |
21841 global_holder = Local<Object>::Cast(global_holder->GetPrototype()); | 21932 global_holder = Local<Object>::Cast(global_holder->GetPrototype()); |
21842 } | 21933 } |
21843 global_holder->Set(v8_str("g_f"), function); | 21934 global_holder->Set(context, v8_str("g_f"), function).FromJust(); |
21844 global_holder->SetAccessorProperty(v8_str("g_acc"), function, function); | 21935 global_holder->SetAccessorProperty(v8_str("g_acc"), function, function); |
21845 function_holder->Set(v8_str("f"), function); | 21936 function_holder->Set(context, v8_str("f"), function).FromJust(); |
21846 function_holder->SetAccessorProperty(v8_str("acc"), function, function); | 21937 function_holder->SetAccessorProperty(v8_str("acc"), function, function); |
21847 // Initialize expected values. | 21938 // Initialize expected values. |
21848 callee = function; | 21939 callee = function; |
21849 count = 0; | 21940 count = 0; |
21850 if (global) { | 21941 if (global) { |
21851 receiver = context->Global(); | 21942 receiver = context->Global(); |
21852 holder = inner_global; | 21943 holder = inner_global; |
21853 } else { | 21944 } else { |
21854 holder = function_receiver; | 21945 holder = function_receiver; |
21855 // If not using a signature, add something else to the prototype chain | 21946 // If not using a signature, add something else to the prototype chain |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
21935 checker.RunAll(); | 22026 checker.RunAll(); |
21936 } | 22027 } |
21937 | 22028 |
21938 | 22029 |
21939 TEST(FunctionCallOptimizationMultipleArgs) { | 22030 TEST(FunctionCallOptimizationMultipleArgs) { |
21940 i::FLAG_allow_natives_syntax = true; | 22031 i::FLAG_allow_natives_syntax = true; |
21941 LocalContext context; | 22032 LocalContext context; |
21942 v8::Isolate* isolate = context->GetIsolate(); | 22033 v8::Isolate* isolate = context->GetIsolate(); |
21943 v8::HandleScope scope(isolate); | 22034 v8::HandleScope scope(isolate); |
21944 Local<Object> global = context->Global(); | 22035 Local<Object> global = context->Global(); |
21945 Local<v8::Function> function = Function::New(isolate, Returns42); | 22036 Local<v8::Function> function = |
21946 global->Set(v8_str("x"), function); | 22037 Function::New(context.local(), Returns42).ToLocalChecked(); |
22038 global->Set(context.local(), v8_str("x"), function).FromJust(); | |
21947 CompileRun( | 22039 CompileRun( |
21948 "function x_wrap() {\n" | 22040 "function x_wrap() {\n" |
21949 " for (var i = 0; i < 5; i++) {\n" | 22041 " for (var i = 0; i < 5; i++) {\n" |
21950 " x(1,2,3);\n" | 22042 " x(1,2,3);\n" |
21951 " }\n" | 22043 " }\n" |
21952 "}\n" | 22044 "}\n" |
21953 "x_wrap();\n" | 22045 "x_wrap();\n" |
21954 "%OptimizeFunctionOnNextCall(x_wrap);" | 22046 "%OptimizeFunctionOnNextCall(x_wrap);" |
21955 "x_wrap();\n"); | 22047 "x_wrap();\n"); |
21956 } | 22048 } |
21957 | 22049 |
21958 | 22050 |
21959 static void ReturnsSymbolCallback( | 22051 static void ReturnsSymbolCallback( |
21960 const v8::FunctionCallbackInfo<v8::Value>& info) { | 22052 const v8::FunctionCallbackInfo<v8::Value>& info) { |
21961 info.GetReturnValue().Set(v8::Symbol::New(info.GetIsolate())); | 22053 info.GetReturnValue().Set(v8::Symbol::New(info.GetIsolate())); |
21962 } | 22054 } |
21963 | 22055 |
21964 | 22056 |
21965 TEST(ApiCallbackCanReturnSymbols) { | 22057 TEST(ApiCallbackCanReturnSymbols) { |
21966 i::FLAG_allow_natives_syntax = true; | 22058 i::FLAG_allow_natives_syntax = true; |
21967 LocalContext context; | 22059 LocalContext context; |
21968 v8::Isolate* isolate = context->GetIsolate(); | 22060 v8::Isolate* isolate = context->GetIsolate(); |
21969 v8::HandleScope scope(isolate); | 22061 v8::HandleScope scope(isolate); |
21970 Local<Object> global = context->Global(); | 22062 Local<Object> global = context->Global(); |
21971 Local<v8::Function> function = Function::New(isolate, ReturnsSymbolCallback); | 22063 Local<v8::Function> function = |
21972 global->Set(v8_str("x"), function); | 22064 Function::New(context.local(), ReturnsSymbolCallback).ToLocalChecked(); |
22065 global->Set(context.local(), v8_str("x"), function).FromJust(); | |
21973 CompileRun( | 22066 CompileRun( |
21974 "function x_wrap() {\n" | 22067 "function x_wrap() {\n" |
21975 " for (var i = 0; i < 5; i++) {\n" | 22068 " for (var i = 0; i < 5; i++) {\n" |
21976 " x();\n" | 22069 " x();\n" |
21977 " }\n" | 22070 " }\n" |
21978 "}\n" | 22071 "}\n" |
21979 "x_wrap();\n" | 22072 "x_wrap();\n" |
21980 "%OptimizeFunctionOnNextCall(x_wrap);" | 22073 "%OptimizeFunctionOnNextCall(x_wrap);" |
21981 "x_wrap();\n"); | 22074 "x_wrap();\n"); |
21982 } | 22075 } |
21983 | 22076 |
21984 | 22077 |
21985 TEST(EmptyApiCallback) { | 22078 TEST(EmptyApiCallback) { |
21986 LocalContext context; | 22079 LocalContext context; |
21987 auto isolate = context->GetIsolate(); | 22080 auto isolate = context->GetIsolate(); |
21988 v8::HandleScope scope(isolate); | 22081 v8::HandleScope scope(isolate); |
21989 auto global = context->Global(); | 22082 auto global = context->Global(); |
21990 auto function = FunctionTemplate::New(isolate) | 22083 auto function = FunctionTemplate::New(isolate) |
21991 ->GetFunction(context.local()) | 22084 ->GetFunction(context.local()) |
21992 .ToLocalChecked(); | 22085 .ToLocalChecked(); |
21993 global->Set(v8_str("x"), function); | 22086 global->Set(context.local(), v8_str("x"), function).FromJust(); |
21994 | 22087 |
21995 auto result = CompileRun("x()"); | 22088 auto result = CompileRun("x()"); |
21996 CHECK(v8::Utils::OpenHandle(*result)->IsJSGlobalProxy()); | 22089 CHECK(v8::Utils::OpenHandle(*result)->IsJSGlobalProxy()); |
21997 | 22090 |
21998 result = CompileRun("x(1,2,3)"); | 22091 result = CompileRun("x(1,2,3)"); |
21999 CHECK(v8::Utils::OpenHandle(*result)->IsJSGlobalProxy()); | 22092 CHECK(v8::Utils::OpenHandle(*result)->IsJSGlobalProxy()); |
22000 | 22093 |
22001 result = CompileRun("7 + x.call(3) + 11"); | 22094 result = CompileRun("7 + x.call(3) + 11"); |
22002 CHECK(result->IsInt32()); | 22095 CHECK(result->IsInt32()); |
22003 CHECK_EQ(21, result->Int32Value(context.local()).FromJust()); | 22096 CHECK_EQ(21, result->Int32Value(context.local()).FromJust()); |
(...skipping 11 matching lines...) Expand all Loading... | |
22015 | 22108 |
22016 | 22109 |
22017 TEST(SimpleSignatureCheck) { | 22110 TEST(SimpleSignatureCheck) { |
22018 LocalContext context; | 22111 LocalContext context; |
22019 auto isolate = context->GetIsolate(); | 22112 auto isolate = context->GetIsolate(); |
22020 v8::HandleScope scope(isolate); | 22113 v8::HandleScope scope(isolate); |
22021 auto global = context->Global(); | 22114 auto global = context->Global(); |
22022 auto sig_obj = FunctionTemplate::New(isolate); | 22115 auto sig_obj = FunctionTemplate::New(isolate); |
22023 auto sig = v8::Signature::New(isolate, sig_obj); | 22116 auto sig = v8::Signature::New(isolate, sig_obj); |
22024 auto x = FunctionTemplate::New(isolate, Returns42, Local<Value>(), sig); | 22117 auto x = FunctionTemplate::New(isolate, Returns42, Local<Value>(), sig); |
22025 global->Set(v8_str("sig_obj"), | 22118 global->Set(context.local(), v8_str("sig_obj"), |
22026 sig_obj->GetFunction(context.local()).ToLocalChecked()); | 22119 sig_obj->GetFunction(context.local()).ToLocalChecked()) |
22027 global->Set(v8_str("x"), x->GetFunction(context.local()).ToLocalChecked()); | 22120 .FromJust(); |
22121 global->Set(context.local(), v8_str("x"), | |
22122 x->GetFunction(context.local()).ToLocalChecked()) | |
22123 .FromJust(); | |
22028 CompileRun("var s = new sig_obj();"); | 22124 CompileRun("var s = new sig_obj();"); |
22029 { | 22125 { |
22030 TryCatch try_catch(isolate); | 22126 TryCatch try_catch(isolate); |
22031 CompileRun("x()"); | 22127 CompileRun("x()"); |
22032 CHECK(try_catch.HasCaught()); | 22128 CHECK(try_catch.HasCaught()); |
22033 } | 22129 } |
22034 { | 22130 { |
22035 TryCatch try_catch(isolate); | 22131 TryCatch try_catch(isolate); |
22036 CompileRun("x.call(1)"); | 22132 CompileRun("x.call(1)"); |
22037 CHECK(try_catch.HasCaught()); | 22133 CHECK(try_catch.HasCaught()); |
(...skipping 19 matching lines...) Expand all Loading... | |
22057 v8::HandleScope scope(isolate); | 22153 v8::HandleScope scope(isolate); |
22058 auto global = context->Global(); | 22154 auto global = context->Global(); |
22059 auto sig_obj = FunctionTemplate::New(isolate); | 22155 auto sig_obj = FunctionTemplate::New(isolate); |
22060 auto sig = v8::Signature::New(isolate, sig_obj); | 22156 auto sig = v8::Signature::New(isolate, sig_obj); |
22061 for (int i = 0; i < 4; ++i) { | 22157 for (int i = 0; i < 4; ++i) { |
22062 auto temp = FunctionTemplate::New(isolate); | 22158 auto temp = FunctionTemplate::New(isolate); |
22063 temp->Inherit(sig_obj); | 22159 temp->Inherit(sig_obj); |
22064 sig_obj = temp; | 22160 sig_obj = temp; |
22065 } | 22161 } |
22066 auto x = FunctionTemplate::New(isolate, Returns42, Local<Value>(), sig); | 22162 auto x = FunctionTemplate::New(isolate, Returns42, Local<Value>(), sig); |
22067 global->Set(v8_str("sig_obj"), | 22163 global->Set(context.local(), v8_str("sig_obj"), |
22068 sig_obj->GetFunction(context.local()).ToLocalChecked()); | 22164 sig_obj->GetFunction(context.local()).ToLocalChecked()) |
22069 global->Set(v8_str("x"), x->GetFunction(context.local()).ToLocalChecked()); | 22165 .FromJust(); |
22166 global->Set(context.local(), v8_str("x"), | |
22167 x->GetFunction(context.local()).ToLocalChecked()) | |
22168 .FromJust(); | |
22070 CompileRun("var s = new sig_obj();"); | 22169 CompileRun("var s = new sig_obj();"); |
22071 { | 22170 { |
22072 TryCatch try_catch(isolate); | 22171 TryCatch try_catch(isolate); |
22073 CompileRun("x()"); | 22172 CompileRun("x()"); |
22074 CHECK(try_catch.HasCaught()); | 22173 CHECK(try_catch.HasCaught()); |
22075 } | 22174 } |
22076 { | 22175 { |
22077 TryCatch try_catch(isolate); | 22176 TryCatch try_catch(isolate); |
22078 CompileRun("x.call(1)"); | 22177 CompileRun("x.call(1)"); |
22079 CHECK(try_catch.HasCaught()); | 22178 CHECK(try_catch.HasCaught()); |
(...skipping 15 matching lines...) Expand all Loading... | |
22095 | 22194 |
22096 TEST(PrototypeSignatureCheck) { | 22195 TEST(PrototypeSignatureCheck) { |
22097 LocalContext context; | 22196 LocalContext context; |
22098 auto isolate = context->GetIsolate(); | 22197 auto isolate = context->GetIsolate(); |
22099 v8::HandleScope scope(isolate); | 22198 v8::HandleScope scope(isolate); |
22100 auto global = context->Global(); | 22199 auto global = context->Global(); |
22101 auto sig_obj = FunctionTemplate::New(isolate); | 22200 auto sig_obj = FunctionTemplate::New(isolate); |
22102 sig_obj->SetHiddenPrototype(true); | 22201 sig_obj->SetHiddenPrototype(true); |
22103 auto sig = v8::Signature::New(isolate, sig_obj); | 22202 auto sig = v8::Signature::New(isolate, sig_obj); |
22104 auto x = FunctionTemplate::New(isolate, Returns42, Local<Value>(), sig); | 22203 auto x = FunctionTemplate::New(isolate, Returns42, Local<Value>(), sig); |
22105 global->Set(v8_str("sig_obj"), | 22204 global->Set(context.local(), v8_str("sig_obj"), |
22106 sig_obj->GetFunction(context.local()).ToLocalChecked()); | 22205 sig_obj->GetFunction(context.local()).ToLocalChecked()) |
22107 global->Set(v8_str("x"), x->GetFunction(context.local()).ToLocalChecked()); | 22206 .FromJust(); |
22207 global->Set(context.local(), v8_str("x"), | |
22208 x->GetFunction(context.local()).ToLocalChecked()) | |
22209 .FromJust(); | |
22108 CompileRun("s = {}; s.__proto__ = new sig_obj();"); | 22210 CompileRun("s = {}; s.__proto__ = new sig_obj();"); |
22109 { | 22211 { |
22110 TryCatch try_catch(isolate); | 22212 TryCatch try_catch(isolate); |
22111 CompileRun("x()"); | 22213 CompileRun("x()"); |
22112 CHECK(try_catch.HasCaught()); | 22214 CHECK(try_catch.HasCaught()); |
22113 } | 22215 } |
22114 { | 22216 { |
22115 TryCatch try_catch(isolate); | 22217 TryCatch try_catch(isolate); |
22116 CompileRun("x.call(1)"); | 22218 CompileRun("x.call(1)"); |
22117 CHECK(try_catch.HasCaught()); | 22219 CHECK(try_catch.HasCaught()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
22151 histogramTimer.Stop(); | 22253 histogramTimer.Stop(); |
22152 CHECK_EQ(0, strcmp("V8.Test", last_event_message)); | 22254 CHECK_EQ(0, strcmp("V8.Test", last_event_message)); |
22153 CHECK_EQ(1, last_event_status); | 22255 CHECK_EQ(1, last_event_status); |
22154 } | 22256 } |
22155 | 22257 |
22156 | 22258 |
22157 TEST(Promises) { | 22259 TEST(Promises) { |
22158 LocalContext context; | 22260 LocalContext context; |
22159 v8::Isolate* isolate = context->GetIsolate(); | 22261 v8::Isolate* isolate = context->GetIsolate(); |
22160 v8::HandleScope scope(isolate); | 22262 v8::HandleScope scope(isolate); |
22161 Local<Object> global = context->Global(); | |
22162 | 22263 |
22163 // Creation. | 22264 // Creation. |
22164 Local<v8::Promise::Resolver> pr = v8::Promise::Resolver::New(isolate); | 22265 Local<v8::Promise::Resolver> pr = |
22165 Local<v8::Promise::Resolver> rr = v8::Promise::Resolver::New(isolate); | 22266 v8::Promise::Resolver::New(context.local()).ToLocalChecked(); |
22267 Local<v8::Promise::Resolver> rr = | |
22268 v8::Promise::Resolver::New(context.local()).ToLocalChecked(); | |
22166 Local<v8::Promise> p = pr->GetPromise(); | 22269 Local<v8::Promise> p = pr->GetPromise(); |
22167 Local<v8::Promise> r = rr->GetPromise(); | 22270 Local<v8::Promise> r = rr->GetPromise(); |
22168 CHECK_EQ(isolate, p->GetIsolate()); | |
22169 | 22271 |
22170 // IsPromise predicate. | 22272 // IsPromise predicate. |
22171 CHECK(p->IsPromise()); | 22273 CHECK(p->IsPromise()); |
22172 CHECK(r->IsPromise()); | 22274 CHECK(r->IsPromise()); |
22173 Local<Value> o = v8::Object::New(isolate); | 22275 Local<Value> o = v8::Object::New(isolate); |
22174 CHECK(!o->IsPromise()); | 22276 CHECK(!o->IsPromise()); |
22175 | 22277 |
22176 // Resolution and rejection. | 22278 // Resolution and rejection. |
22177 pr->Resolve(v8::Integer::New(isolate, 1)); | 22279 pr->Resolve(context.local(), v8::Integer::New(isolate, 1)).FromJust(); |
22178 CHECK(p->IsPromise()); | 22280 CHECK(p->IsPromise()); |
22179 rr->Reject(v8::Integer::New(isolate, 2)); | 22281 rr->Reject(context.local(), v8::Integer::New(isolate, 2)).FromJust(); |
22180 CHECK(r->IsPromise()); | 22282 CHECK(r->IsPromise()); |
22181 | |
22182 // Chaining non-pending promises. | |
22183 CompileRun( | |
22184 "var x1 = 0;\n" | |
22185 "var x2 = 0;\n" | |
22186 "function f1(x) { x1 = x; return x+1 };\n" | |
22187 "function f2(x) { x2 = x; return x+1 };\n"); | |
22188 Local<Function> f1 = Local<Function>::Cast(global->Get(v8_str("f1"))); | |
22189 Local<Function> f2 = Local<Function>::Cast(global->Get(v8_str("f2"))); | |
22190 | |
22191 p->Chain(f1); | |
22192 CHECK_EQ(0, | |
22193 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); | |
22194 isolate->RunMicrotasks(); | |
22195 CHECK_EQ(1, | |
22196 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); | |
22197 | |
22198 p->Catch(f2); | |
22199 isolate->RunMicrotasks(); | |
22200 CHECK_EQ(0, | |
22201 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
22202 | |
22203 r->Catch(f2); | |
22204 CHECK_EQ(0, | |
22205 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
22206 isolate->RunMicrotasks(); | |
22207 CHECK_EQ(2, | |
22208 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
22209 | |
22210 r->Chain(f1); | |
22211 isolate->RunMicrotasks(); | |
22212 CHECK_EQ(1, | |
22213 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); | |
22214 | |
22215 // Chaining pending promises. | |
22216 CompileRun("x1 = x2 = 0;"); | |
22217 pr = v8::Promise::Resolver::New(isolate); | |
22218 rr = v8::Promise::Resolver::New(isolate); | |
22219 | |
22220 pr->GetPromise()->Chain(f1); | |
22221 rr->GetPromise()->Catch(f2); | |
22222 isolate->RunMicrotasks(); | |
22223 CHECK_EQ(0, | |
22224 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); | |
22225 CHECK_EQ(0, | |
22226 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
22227 | |
22228 pr->Resolve(v8::Integer::New(isolate, 1)); | |
22229 rr->Reject(v8::Integer::New(isolate, 2)); | |
22230 CHECK_EQ(0, | |
22231 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); | |
22232 CHECK_EQ(0, | |
22233 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
22234 | |
22235 isolate->RunMicrotasks(); | |
22236 CHECK_EQ(1, | |
22237 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); | |
22238 CHECK_EQ(2, | |
22239 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
22240 | |
22241 // Multi-chaining. | |
22242 CompileRun("x1 = x2 = 0;"); | |
22243 pr = v8::Promise::Resolver::New(isolate); | |
22244 pr->GetPromise()->Chain(f1)->Chain(f2); | |
22245 pr->Resolve(v8::Integer::New(isolate, 3)); | |
22246 CHECK_EQ(0, | |
22247 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); | |
22248 CHECK_EQ(0, | |
22249 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
22250 isolate->RunMicrotasks(); | |
22251 CHECK_EQ(3, | |
22252 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); | |
22253 CHECK_EQ(4, | |
22254 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
22255 | |
22256 CompileRun("x1 = x2 = 0;"); | |
22257 rr = v8::Promise::Resolver::New(isolate); | |
22258 rr->GetPromise()->Catch(f1)->Chain(f2); | |
22259 rr->Reject(v8::Integer::New(isolate, 3)); | |
22260 CHECK_EQ(0, | |
22261 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); | |
22262 CHECK_EQ(0, | |
22263 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
22264 isolate->RunMicrotasks(); | |
22265 CHECK_EQ(3, | |
22266 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); | |
22267 CHECK_EQ(4, | |
22268 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
22269 } | 22283 } |
22270 | 22284 |
22271 | 22285 |
22272 TEST(PromiseThen) { | 22286 TEST(PromiseThen) { |
22273 LocalContext context; | 22287 LocalContext context; |
22274 v8::Isolate* isolate = context->GetIsolate(); | 22288 v8::Isolate* isolate = context->GetIsolate(); |
22275 v8::HandleScope scope(isolate); | 22289 v8::HandleScope scope(isolate); |
22276 Local<Object> global = context->Global(); | 22290 Local<Object> global = context->Global(); |
22277 | 22291 |
22278 // Creation. | 22292 // Creation. |
22279 Local<v8::Promise::Resolver> pr = v8::Promise::Resolver::New(isolate); | 22293 Local<v8::Promise::Resolver> pr = |
22280 Local<v8::Promise::Resolver> qr = v8::Promise::Resolver::New(isolate); | 22294 v8::Promise::Resolver::New(context.local()).ToLocalChecked(); |
22295 Local<v8::Promise::Resolver> qr = | |
22296 v8::Promise::Resolver::New(context.local()).ToLocalChecked(); | |
22281 Local<v8::Promise> p = pr->GetPromise(); | 22297 Local<v8::Promise> p = pr->GetPromise(); |
22282 Local<v8::Promise> q = qr->GetPromise(); | 22298 Local<v8::Promise> q = qr->GetPromise(); |
22283 | 22299 |
22284 CHECK(p->IsPromise()); | 22300 CHECK(p->IsPromise()); |
22285 CHECK(q->IsPromise()); | 22301 CHECK(q->IsPromise()); |
22286 | 22302 |
22287 pr->Resolve(v8::Integer::New(isolate, 1)); | 22303 pr->Resolve(context.local(), v8::Integer::New(isolate, 1)).FromJust(); |
22288 qr->Resolve(p); | 22304 qr->Resolve(context.local(), p).FromJust(); |
22289 | 22305 |
22290 // Chaining non-pending promises. | 22306 // Chaining non-pending promises. |
22291 CompileRun( | 22307 CompileRun( |
22292 "var x1 = 0;\n" | 22308 "var x1 = 0;\n" |
22293 "var x2 = 0;\n" | 22309 "var x2 = 0;\n" |
22294 "function f1(x) { x1 = x; return x+1 };\n" | 22310 "function f1(x) { x1 = x; return x+1 };\n" |
22295 "function f2(x) { x2 = x; return x+1 };\n"); | 22311 "function f2(x) { x2 = x; return x+1 };\n"); |
22296 Local<Function> f1 = Local<Function>::Cast(global->Get(v8_str("f1"))); | 22312 Local<Function> f1 = Local<Function>::Cast( |
22297 Local<Function> f2 = Local<Function>::Cast(global->Get(v8_str("f2"))); | 22313 global->Get(context.local(), v8_str("f1")).ToLocalChecked()); |
22298 | 22314 Local<Function> f2 = Local<Function>::Cast( |
22299 // TODO(caitp): remove tests once PromiseChain is removed, per bug 3237 | 22315 global->Get(context.local(), v8_str("f2")).ToLocalChecked()); |
22300 /* q->Chain(f1); | |
22301 CHECK(global->Get(v8_str2("x1"))->IsNumber()); | |
22302 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); | |
22303 isolate->RunMicrotasks(); | |
22304 CHECK(!global->Get(v8_str("x1"))->IsNumber()); | |
22305 CHECK(p->Equals(global->Get(v8_str("x1")))); */ | |
22306 | 22316 |
22307 // Then | 22317 // Then |
22308 CompileRun("x1 = x2 = 0;"); | 22318 CompileRun("x1 = x2 = 0;"); |
22309 q->Then(f1); | 22319 q->Then(context.local(), f1).ToLocalChecked(); |
22310 CHECK_EQ(0, | 22320 CHECK_EQ(0, global->Get(context.local(), v8_str("x1")) |
22311 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); | 22321 .ToLocalChecked() |
22322 ->Int32Value(context.local()) | |
22323 .FromJust()); | |
22312 isolate->RunMicrotasks(); | 22324 isolate->RunMicrotasks(); |
22313 CHECK_EQ(1, | 22325 CHECK_EQ(1, global->Get(context.local(), v8_str("x1")) |
22314 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); | 22326 .ToLocalChecked() |
22327 ->Int32Value(context.local()) | |
22328 .FromJust()); | |
22315 | 22329 |
22316 // Then | 22330 // Then |
22317 CompileRun("x1 = x2 = 0;"); | 22331 CompileRun("x1 = x2 = 0;"); |
22318 pr = v8::Promise::Resolver::New(isolate); | 22332 pr = v8::Promise::Resolver::New(context.local()).ToLocalChecked(); |
22319 qr = v8::Promise::Resolver::New(isolate); | 22333 qr = v8::Promise::Resolver::New(context.local()).ToLocalChecked(); |
22320 | 22334 |
22321 qr->Resolve(pr); | 22335 qr->Resolve(context.local(), pr).FromJust(); |
22322 qr->GetPromise()->Then(f1)->Then(f2); | 22336 qr->GetPromise() |
22337 ->Then(context.local(), f1) | |
22338 .ToLocalChecked() | |
22339 ->Then(context.local(), f2) | |
22340 .ToLocalChecked(); | |
22323 | 22341 |
22324 CHECK_EQ(0, | 22342 CHECK_EQ(0, global->Get(context.local(), v8_str("x1")) |
22325 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); | 22343 .ToLocalChecked() |
22326 CHECK_EQ(0, | 22344 ->Int32Value(context.local()) |
22327 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | 22345 .FromJust()); |
22346 CHECK_EQ(0, global->Get(context.local(), v8_str("x2")) | |
22347 .ToLocalChecked() | |
22348 ->Int32Value(context.local()) | |
22349 .FromJust()); | |
22328 isolate->RunMicrotasks(); | 22350 isolate->RunMicrotasks(); |
22329 CHECK_EQ(0, | 22351 CHECK_EQ(0, global->Get(context.local(), v8_str("x1")) |
22330 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); | 22352 .ToLocalChecked() |
22331 CHECK_EQ(0, | 22353 ->Int32Value(context.local()) |
22332 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | 22354 .FromJust()); |
22355 CHECK_EQ(0, global->Get(context.local(), v8_str("x2")) | |
22356 .ToLocalChecked() | |
22357 ->Int32Value(context.local()) | |
22358 .FromJust()); | |
22333 | 22359 |
22334 pr->Resolve(v8::Integer::New(isolate, 3)); | 22360 pr->Resolve(context.local(), v8::Integer::New(isolate, 3)).FromJust(); |
22335 | 22361 |
22336 CHECK_EQ(0, | 22362 CHECK_EQ(0, global->Get(context.local(), v8_str("x1")) |
22337 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); | 22363 .ToLocalChecked() |
22338 CHECK_EQ(0, | 22364 ->Int32Value(context.local()) |
22339 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | 22365 .FromJust()); |
22366 CHECK_EQ(0, global->Get(context.local(), v8_str("x2")) | |
22367 .ToLocalChecked() | |
22368 ->Int32Value(context.local()) | |
22369 .FromJust()); | |
22340 isolate->RunMicrotasks(); | 22370 isolate->RunMicrotasks(); |
22341 CHECK_EQ(3, | 22371 CHECK_EQ(3, global->Get(context.local(), v8_str("x1")) |
22342 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); | 22372 .ToLocalChecked() |
22343 CHECK_EQ(4, | 22373 ->Int32Value(context.local()) |
22344 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | 22374 .FromJust()); |
22375 CHECK_EQ(4, global->Get(context.local(), v8_str("x2")) | |
22376 .ToLocalChecked() | |
22377 ->Int32Value(context.local()) | |
22378 .FromJust()); | |
22345 } | 22379 } |
22346 | 22380 |
22347 | 22381 |
22348 TEST(DisallowJavascriptExecutionScope) { | 22382 TEST(DisallowJavascriptExecutionScope) { |
22349 LocalContext context; | 22383 LocalContext context; |
22350 v8::Isolate* isolate = context->GetIsolate(); | 22384 v8::Isolate* isolate = context->GetIsolate(); |
22351 v8::HandleScope scope(isolate); | 22385 v8::HandleScope scope(isolate); |
22352 v8::Isolate::DisallowJavascriptExecutionScope no_js( | 22386 v8::Isolate::DisallowJavascriptExecutionScope no_js( |
22353 isolate, v8::Isolate::DisallowJavascriptExecutionScope::CRASH_ON_FAILURE); | 22387 isolate, v8::Isolate::DisallowJavascriptExecutionScope::CRASH_ON_FAILURE); |
22354 CompileRun("2+2"); | 22388 CompileRun("2+2"); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
22427 CompileRun("Object.getPrototypeOf(friend);"); | 22461 CompileRun("Object.getPrototypeOf(friend);"); |
22428 CHECK_EQ(2, access_count); | 22462 CHECK_EQ(2, access_count); |
22429 } | 22463 } |
22430 | 22464 |
22431 | 22465 |
22432 TEST(CaptureStackTraceForStackOverflow) { | 22466 TEST(CaptureStackTraceForStackOverflow) { |
22433 v8::internal::FLAG_stack_size = 150; | 22467 v8::internal::FLAG_stack_size = 150; |
22434 LocalContext current; | 22468 LocalContext current; |
22435 v8::Isolate* isolate = current->GetIsolate(); | 22469 v8::Isolate* isolate = current->GetIsolate(); |
22436 v8::HandleScope scope(isolate); | 22470 v8::HandleScope scope(isolate); |
22437 V8::SetCaptureStackTraceForUncaughtExceptions( | 22471 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, |
22438 true, 10, v8::StackTrace::kDetailed); | 22472 v8::StackTrace::kDetailed); |
22439 v8::TryCatch try_catch(isolate); | 22473 v8::TryCatch try_catch(isolate); |
22440 CompileRun("(function f(x) { f(x+1); })(0)"); | 22474 CompileRun("(function f(x) { f(x+1); })(0)"); |
22441 CHECK(try_catch.HasCaught()); | 22475 CHECK(try_catch.HasCaught()); |
22442 } | 22476 } |
22443 | 22477 |
22444 | 22478 |
22445 TEST(ScriptNameAndLineNumber) { | 22479 TEST(ScriptNameAndLineNumber) { |
22446 LocalContext env; | 22480 LocalContext env; |
22447 v8::Isolate* isolate = env->GetIsolate(); | 22481 v8::Isolate* isolate = env->GetIsolate(); |
22448 v8::HandleScope scope(isolate); | 22482 v8::HandleScope scope(isolate); |
22449 const char* url = "http://www.foo.com/foo.js"; | 22483 const char* url = "http://www.foo.com/foo.js"; |
22450 v8::ScriptOrigin origin(v8_str(url), v8::Integer::New(isolate, 13)); | 22484 v8::ScriptOrigin origin(v8_str(url), v8::Integer::New(isolate, 13)); |
22451 v8::ScriptCompiler::Source script_source(v8_str("var foo;"), origin); | 22485 v8::ScriptCompiler::Source script_source(v8_str("var foo;"), origin); |
22452 Local<Script> script = v8::ScriptCompiler::Compile( | 22486 Local<Script> script = |
22453 isolate, &script_source); | 22487 v8::ScriptCompiler::Compile(env.local(), &script_source).ToLocalChecked(); |
22454 Local<Value> script_name = script->GetUnboundScript()->GetScriptName(); | 22488 Local<Value> script_name = script->GetUnboundScript()->GetScriptName(); |
22455 CHECK(!script_name.IsEmpty()); | 22489 CHECK(!script_name.IsEmpty()); |
22456 CHECK(script_name->IsString()); | 22490 CHECK(script_name->IsString()); |
22457 String::Utf8Value utf8_name(script_name); | 22491 String::Utf8Value utf8_name(script_name); |
22458 CHECK_EQ(0, strcmp(url, *utf8_name)); | 22492 CHECK_EQ(0, strcmp(url, *utf8_name)); |
22459 int line_number = script->GetUnboundScript()->GetLineNumber(0); | 22493 int line_number = script->GetUnboundScript()->GetLineNumber(0); |
22460 CHECK_EQ(13, line_number); | 22494 CHECK_EQ(13, line_number); |
22461 } | 22495 } |
22462 | 22496 |
22463 void CheckMagicComments(Local<Script> script, const char* expected_source_url, | 22497 void CheckMagicComments(Local<Script> script, const char* expected_source_url, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
22551 LocalContext env; | 22585 LocalContext env; |
22552 v8::Isolate* isolate = env->GetIsolate(); | 22586 v8::Isolate* isolate = env->GetIsolate(); |
22553 v8::HandleScope scope(isolate); | 22587 v8::HandleScope scope(isolate); |
22554 CompileRun( | 22588 CompileRun( |
22555 "var x = { value : 13};" | 22589 "var x = { value : 13};" |
22556 "Object.defineProperty(x, 'p0', {value : 12});" | 22590 "Object.defineProperty(x, 'p0', {value : 12});" |
22557 "Object.defineProperty(x, 'p1', {" | 22591 "Object.defineProperty(x, 'p1', {" |
22558 " set : function(value) { this.value = value; }," | 22592 " set : function(value) { this.value = value; }," |
22559 " get : function() { return this.value; }," | 22593 " get : function() { return this.value; }," |
22560 "});"); | 22594 "});"); |
22561 Local<Object> x = Local<Object>::Cast(env->Global()->Get(v8_str("x"))); | 22595 Local<Object> x = Local<Object>::Cast( |
22562 Local<Value> desc = x->GetOwnPropertyDescriptor(v8_str("no_prop")); | 22596 env->Global()->Get(env.local(), v8_str("x")).ToLocalChecked()); |
22597 Local<Value> desc = | |
22598 x->GetOwnPropertyDescriptor(env.local(), v8_str("no_prop")) | |
22599 .ToLocalChecked(); | |
22563 CHECK(desc->IsUndefined()); | 22600 CHECK(desc->IsUndefined()); |
22564 desc = x->GetOwnPropertyDescriptor(v8_str("p0")); | 22601 desc = |
22565 CHECK(v8_num(12)->Equals(Local<Object>::Cast(desc)->Get(v8_str("value")))); | 22602 x->GetOwnPropertyDescriptor(env.local(), v8_str("p0")).ToLocalChecked(); |
22566 desc = x->GetOwnPropertyDescriptor(v8_str("p1")); | 22603 CHECK(v8_num(12) |
22604 ->Equals(env.local(), Local<Object>::Cast(desc) | |
22605 ->Get(env.local(), v8_str("value")) | |
22606 .ToLocalChecked()) | |
22607 .FromJust()); | |
22608 desc = | |
22609 x->GetOwnPropertyDescriptor(env.local(), v8_str("p1")).ToLocalChecked(); | |
22567 Local<Function> set = | 22610 Local<Function> set = |
22568 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("set"))); | 22611 Local<Function>::Cast(Local<Object>::Cast(desc) |
22612 ->Get(env.local(), v8_str("set")) | |
22613 .ToLocalChecked()); | |
22569 Local<Function> get = | 22614 Local<Function> get = |
22570 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("get"))); | 22615 Local<Function>::Cast(Local<Object>::Cast(desc) |
22571 CHECK(v8_num(13)->Equals(get->Call(x, 0, NULL))); | 22616 ->Get(env.local(), v8_str("get")) |
22617 .ToLocalChecked()); | |
22618 CHECK(v8_num(13) | |
22619 ->Equals(env.local(), | |
22620 get->Call(env.local(), x, 0, NULL).ToLocalChecked()) | |
22621 .FromJust()); | |
22572 Local<Value> args[] = {v8_num(14)}; | 22622 Local<Value> args[] = {v8_num(14)}; |
22573 set->Call(x, 1, args); | 22623 set->Call(env.local(), x, 1, args).ToLocalChecked(); |
22574 CHECK(v8_num(14)->Equals(get->Call(x, 0, NULL))); | 22624 CHECK(v8_num(14) |
22625 ->Equals(env.local(), | |
22626 get->Call(env.local(), x, 0, NULL).ToLocalChecked()) | |
22627 .FromJust()); | |
22575 } | 22628 } |
22576 | 22629 |
22577 | 22630 |
22578 TEST(Regress411877) { | 22631 TEST(Regress411877) { |
22579 v8::Isolate* isolate = CcTest::isolate(); | 22632 v8::Isolate* isolate = CcTest::isolate(); |
22580 v8::HandleScope handle_scope(isolate); | 22633 v8::HandleScope handle_scope(isolate); |
22581 v8::Local<v8::ObjectTemplate> object_template = | 22634 v8::Local<v8::ObjectTemplate> object_template = |
22582 v8::ObjectTemplate::New(isolate); | 22635 v8::ObjectTemplate::New(isolate); |
22583 object_template->SetAccessCheckCallback(AccessCounter); | 22636 object_template->SetAccessCheckCallback(AccessCounter); |
22584 | 22637 |
(...skipping 13 matching lines...) Expand all Loading... | |
22598 v8::HandleScope handle_scope(isolate); | 22651 v8::HandleScope handle_scope(isolate); |
22599 v8::Local<v8::ObjectTemplate> object_template = | 22652 v8::Local<v8::ObjectTemplate> object_template = |
22600 v8::ObjectTemplate::New(isolate); | 22653 v8::ObjectTemplate::New(isolate); |
22601 object_template->SetAccessCheckCallback(AccessCounter); | 22654 object_template->SetAccessCheckCallback(AccessCounter); |
22602 | 22655 |
22603 v8::Local<Context> context = Context::New(isolate); | 22656 v8::Local<Context> context = Context::New(isolate); |
22604 v8::Context::Scope context_scope(context); | 22657 v8::Context::Scope context_scope(context); |
22605 | 22658 |
22606 v8::Local<v8::Object> obj = | 22659 v8::Local<v8::Object> obj = |
22607 object_template->NewInstance(context).ToLocalChecked(); | 22660 object_template->NewInstance(context).ToLocalChecked(); |
22608 obj->Set(v8_str("key"), v8_str("value")); | 22661 obj->Set(context, v8_str("key"), v8_str("value")).FromJust(); |
22609 obj->Delete(v8_str("key")); | 22662 obj->Delete(context, v8_str("key")).FromJust(); |
22610 | 22663 |
22611 obj->SetPrivate(context, v8::Private::New(isolate, v8_str("hidden key 2")), | 22664 obj->SetPrivate(context, v8::Private::New(isolate, v8_str("hidden key 2")), |
22612 v8_str("hidden value 2")) | 22665 v8_str("hidden value 2")) |
22613 .FromJust(); | 22666 .FromJust(); |
22614 } | 22667 } |
22615 | 22668 |
22616 | 22669 |
22617 TEST(Regress411793) { | 22670 TEST(Regress411793) { |
22618 v8::Isolate* isolate = CcTest::isolate(); | 22671 v8::Isolate* isolate = CcTest::isolate(); |
22619 v8::HandleScope handle_scope(isolate); | 22672 v8::HandleScope handle_scope(isolate); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
22696 // TestSourceStream::GetMoreData won't block, so it's OK to just run the | 22749 // TestSourceStream::GetMoreData won't block, so it's OK to just run the |
22697 // task here in the main thread. | 22750 // task here in the main thread. |
22698 task->Run(); | 22751 task->Run(); |
22699 delete task; | 22752 delete task; |
22700 | 22753 |
22701 // Possible errors are only produced while compiling. | 22754 // Possible errors are only produced while compiling. |
22702 CHECK_EQ(false, try_catch.HasCaught()); | 22755 CHECK_EQ(false, try_catch.HasCaught()); |
22703 | 22756 |
22704 v8::ScriptOrigin origin(v8_str("http://foo.com")); | 22757 v8::ScriptOrigin origin(v8_str("http://foo.com")); |
22705 char* full_source = TestSourceStream::FullSourceString(chunks); | 22758 char* full_source = TestSourceStream::FullSourceString(chunks); |
22706 v8::Local<Script> script = v8::ScriptCompiler::Compile( | 22759 v8::MaybeLocal<Script> script = v8::ScriptCompiler::Compile( |
22707 isolate, &source, v8_str(full_source), origin); | 22760 env.local(), &source, v8_str(full_source), origin); |
22708 if (expected_success) { | 22761 if (expected_success) { |
22709 CHECK(!script.IsEmpty()); | 22762 CHECK(!script.IsEmpty()); |
22710 v8::Local<Value> result(script->Run()); | 22763 v8::Local<Value> result( |
22764 script.ToLocalChecked()->Run(env.local()).ToLocalChecked()); | |
22711 // All scripts are supposed to return the fixed value 13 when ran. | 22765 // All scripts are supposed to return the fixed value 13 when ran. |
22712 CHECK_EQ(13, result->Int32Value(env.local()).FromJust()); | 22766 CHECK_EQ(13, result->Int32Value(env.local()).FromJust()); |
22713 CheckMagicComments(script, expected_source_url, | 22767 CheckMagicComments(script.ToLocalChecked(), expected_source_url, |
22714 expected_source_mapping_url); | 22768 expected_source_mapping_url); |
22715 } else { | 22769 } else { |
22716 CHECK(script.IsEmpty()); | 22770 CHECK(script.IsEmpty()); |
22717 CHECK(try_catch.HasCaught()); | 22771 CHECK(try_catch.HasCaught()); |
22718 } | 22772 } |
22719 delete[] full_source; | 22773 delete[] full_source; |
22720 } | 22774 } |
22721 | 22775 |
22722 | 22776 |
22723 TEST(StreamingSimpleScript) { | 22777 TEST(StreamingSimpleScript) { |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
22971 task->Run(); | 23025 task->Run(); |
22972 delete task; | 23026 delete task; |
22973 | 23027 |
22974 CHECK(!try_catch.HasCaught()); | 23028 CHECK(!try_catch.HasCaught()); |
22975 | 23029 |
22976 v8::ScriptOrigin origin(v8_str("http://foo.com")); | 23030 v8::ScriptOrigin origin(v8_str("http://foo.com")); |
22977 char* full_source = TestSourceStream::FullSourceString(chunks); | 23031 char* full_source = TestSourceStream::FullSourceString(chunks); |
22978 | 23032 |
22979 EnableDebugger(isolate); | 23033 EnableDebugger(isolate); |
22980 | 23034 |
22981 v8::Local<Script> script = v8::ScriptCompiler::Compile( | 23035 v8::Local<Script> script = |
22982 isolate, &source, v8_str(full_source), origin); | 23036 v8::ScriptCompiler::Compile(env.local(), &source, v8_str(full_source), |
23037 origin) | |
23038 .ToLocalChecked(); | |
22983 | 23039 |
22984 Maybe<uint32_t> result = | 23040 Maybe<uint32_t> result = |
22985 script->Run(env.local()).ToLocalChecked()->Uint32Value(env.local()); | 23041 script->Run(env.local()).ToLocalChecked()->Uint32Value(env.local()); |
22986 CHECK_EQ(3U, result.FromMaybe(0)); | 23042 CHECK_EQ(3U, result.FromMaybe(0)); |
22987 | 23043 |
22988 delete[] full_source; | 23044 delete[] full_source; |
22989 | 23045 |
22990 DisableDebugger(isolate); | 23046 DisableDebugger(isolate); |
22991 } | 23047 } |
22992 | 23048 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
23075 v8::ScriptCompiler::StartStreamingScript(isolate, &source); | 23131 v8::ScriptCompiler::StartStreamingScript(isolate, &source); |
23076 task->Run(); | 23132 task->Run(); |
23077 delete task; | 23133 delete task; |
23078 | 23134 |
23079 // Parsing should succeed (the script will be parsed and compiled in a context | 23135 // Parsing should succeed (the script will be parsed and compiled in a context |
23080 // independent way, so the error is not detected). | 23136 // independent way, so the error is not detected). |
23081 CHECK_EQ(false, try_catch.HasCaught()); | 23137 CHECK_EQ(false, try_catch.HasCaught()); |
23082 | 23138 |
23083 v8::ScriptOrigin origin(v8_str("http://foo.com")); | 23139 v8::ScriptOrigin origin(v8_str("http://foo.com")); |
23084 char* full_source = TestSourceStream::FullSourceString(chunks); | 23140 char* full_source = TestSourceStream::FullSourceString(chunks); |
23085 v8::Local<Script> script = v8::ScriptCompiler::Compile( | 23141 v8::Local<Script> script = |
23086 isolate, &source, v8_str(full_source), origin); | 23142 v8::ScriptCompiler::Compile(env.local(), &source, v8_str(full_source), |
23143 origin) | |
23144 .ToLocalChecked(); | |
23087 CHECK(!script.IsEmpty()); | 23145 CHECK(!script.IsEmpty()); |
23088 CHECK_EQ(false, try_catch.HasCaught()); | 23146 CHECK_EQ(false, try_catch.HasCaught()); |
23089 | 23147 |
23090 // Running the script exposes the error. | 23148 // Running the script exposes the error. |
23091 v8::Local<Value> result(script->Run()); | 23149 CHECK(script->Run(env.local()).IsEmpty()); |
23092 CHECK(result.IsEmpty()); | |
23093 CHECK(try_catch.HasCaught()); | 23150 CHECK(try_catch.HasCaught()); |
23094 delete[] full_source; | 23151 delete[] full_source; |
23095 } | 23152 } |
23096 | 23153 |
23097 | 23154 |
23098 TEST(CodeCache) { | 23155 TEST(CodeCache) { |
23099 v8::Isolate::CreateParams create_params; | 23156 v8::Isolate::CreateParams create_params; |
23100 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 23157 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
23101 | 23158 |
23102 const char* source = "Math.sqrt(4)"; | 23159 const char* source = "Math.sqrt(4)"; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
23134 v8::ScriptCompiler::Source source(source_string, script_origin, cache); | 23191 v8::ScriptCompiler::Source source(source_string, script_origin, cache); |
23135 v8::ScriptCompiler::CompileOptions option = | 23192 v8::ScriptCompiler::CompileOptions option = |
23136 v8::ScriptCompiler::kConsumeCodeCache; | 23193 v8::ScriptCompiler::kConsumeCodeCache; |
23137 v8::Local<v8::Script> script; | 23194 v8::Local<v8::Script> script; |
23138 { | 23195 { |
23139 i::DisallowCompilation no_compile( | 23196 i::DisallowCompilation no_compile( |
23140 reinterpret_cast<i::Isolate*>(isolate2)); | 23197 reinterpret_cast<i::Isolate*>(isolate2)); |
23141 script = v8::ScriptCompiler::Compile(context, &source, option) | 23198 script = v8::ScriptCompiler::Compile(context, &source, option) |
23142 .ToLocalChecked(); | 23199 .ToLocalChecked(); |
23143 } | 23200 } |
23144 CHECK_EQ(2, | 23201 CHECK_EQ(2, script->Run(context) |
23145 script->Run()->ToInt32(isolate2)->Int32Value(context).FromJust()); | 23202 .ToLocalChecked() |
23203 ->ToInt32(context) | |
23204 .ToLocalChecked() | |
23205 ->Int32Value(context) | |
23206 .FromJust()); | |
23146 } | 23207 } |
23147 isolate2->Dispose(); | 23208 isolate2->Dispose(); |
23148 } | 23209 } |
23149 | 23210 |
23150 | 23211 |
23151 void TestInvalidCacheData(v8::ScriptCompiler::CompileOptions option) { | 23212 void TestInvalidCacheData(v8::ScriptCompiler::CompileOptions option) { |
23152 const char* garbage = "garbage garbage garbage garbage garbage garbage"; | 23213 const char* garbage = "garbage garbage garbage garbage garbage garbage"; |
23153 const uint8_t* data = reinterpret_cast<const uint8_t*>(garbage); | 23214 const uint8_t* data = reinterpret_cast<const uint8_t*>(garbage); |
23154 int length = 16; | 23215 int length = 16; |
23155 v8::ScriptCompiler::CachedData* cached_data = | 23216 v8::ScriptCompiler::CachedData* cached_data = |
23156 new v8::ScriptCompiler::CachedData(data, length); | 23217 new v8::ScriptCompiler::CachedData(data, length); |
23157 CHECK(!cached_data->rejected); | 23218 CHECK(!cached_data->rejected); |
23158 v8::ScriptOrigin origin(v8_str("origin")); | 23219 v8::ScriptOrigin origin(v8_str("origin")); |
23159 v8::ScriptCompiler::Source source(v8_str("42"), origin, cached_data); | 23220 v8::ScriptCompiler::Source source(v8_str("42"), origin, cached_data); |
23221 v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext(); | |
23160 v8::Local<v8::Script> script = | 23222 v8::Local<v8::Script> script = |
23161 v8::ScriptCompiler::Compile(CcTest::isolate(), &source, option); | 23223 v8::ScriptCompiler::Compile(context, &source, option).ToLocalChecked(); |
23162 CHECK(cached_data->rejected); | 23224 CHECK(cached_data->rejected); |
23163 CHECK_EQ(42, script->Run() | 23225 CHECK_EQ( |
23164 ->Int32Value(CcTest::isolate()->GetCurrentContext()) | 23226 42, |
23165 .FromJust()); | 23227 script->Run(context).ToLocalChecked()->Int32Value(context).FromJust()); |
23166 } | 23228 } |
23167 | 23229 |
23168 | 23230 |
23169 TEST(InvalidCacheData) { | 23231 TEST(InvalidCacheData) { |
23170 v8::V8::Initialize(); | 23232 v8::V8::Initialize(); |
23171 v8::HandleScope scope(CcTest::isolate()); | 23233 v8::HandleScope scope(CcTest::isolate()); |
23172 LocalContext context; | 23234 LocalContext context; |
23173 TestInvalidCacheData(v8::ScriptCompiler::kConsumeParserCache); | 23235 TestInvalidCacheData(v8::ScriptCompiler::kConsumeParserCache); |
23174 TestInvalidCacheData(v8::ScriptCompiler::kConsumeCodeCache); | 23236 TestInvalidCacheData(v8::ScriptCompiler::kConsumeCodeCache); |
23175 } | 23237 } |
23176 | 23238 |
23177 | 23239 |
23178 TEST(ParserCacheRejectedGracefully) { | 23240 TEST(ParserCacheRejectedGracefully) { |
23179 i::FLAG_min_preparse_length = 0; | 23241 i::FLAG_min_preparse_length = 0; |
23180 v8::V8::Initialize(); | 23242 v8::V8::Initialize(); |
23181 v8::HandleScope scope(CcTest::isolate()); | 23243 v8::HandleScope scope(CcTest::isolate()); |
23182 LocalContext context; | 23244 LocalContext context; |
23183 // Produce valid cached data. | 23245 // Produce valid cached data. |
23184 v8::ScriptOrigin origin(v8_str("origin")); | 23246 v8::ScriptOrigin origin(v8_str("origin")); |
23185 v8::Local<v8::String> source_str = v8_str("function foo() {}"); | 23247 v8::Local<v8::String> source_str = v8_str("function foo() {}"); |
23186 v8::ScriptCompiler::Source source(source_str, origin); | 23248 v8::ScriptCompiler::Source source(source_str, origin); |
23187 v8::Local<v8::Script> script = v8::ScriptCompiler::Compile( | 23249 v8::Local<v8::Script> script = |
23188 CcTest::isolate(), &source, v8::ScriptCompiler::kProduceParserCache); | 23250 v8::ScriptCompiler::Compile(context.local(), &source, |
23189 CHECK(!script.IsEmpty()); | 23251 v8::ScriptCompiler::kProduceParserCache) |
23252 .ToLocalChecked(); | |
23253 USE(script); | |
23190 const v8::ScriptCompiler::CachedData* original_cached_data = | 23254 const v8::ScriptCompiler::CachedData* original_cached_data = |
23191 source.GetCachedData(); | 23255 source.GetCachedData(); |
23192 CHECK(original_cached_data != NULL); | 23256 CHECK(original_cached_data != NULL); |
23193 CHECK(original_cached_data->data != NULL); | 23257 CHECK(original_cached_data->data != NULL); |
23194 CHECK(!original_cached_data->rejected); | 23258 CHECK(!original_cached_data->rejected); |
23195 CHECK_GT(original_cached_data->length, 0); | 23259 CHECK_GT(original_cached_data->length, 0); |
23196 // Recompiling the same script with it won't reject the data. | 23260 // Recompiling the same script with it won't reject the data. |
23197 { | 23261 { |
23198 v8::ScriptCompiler::Source source_with_cached_data( | 23262 v8::ScriptCompiler::Source source_with_cached_data( |
23199 source_str, origin, | 23263 source_str, origin, |
23200 new v8::ScriptCompiler::CachedData(original_cached_data->data, | 23264 new v8::ScriptCompiler::CachedData(original_cached_data->data, |
23201 original_cached_data->length)); | 23265 original_cached_data->length)); |
23202 v8::Local<v8::Script> script = | 23266 v8::Local<v8::Script> script = |
23203 v8::ScriptCompiler::Compile(CcTest::isolate(), &source_with_cached_data, | 23267 v8::ScriptCompiler::Compile(context.local(), &source_with_cached_data, |
23204 v8::ScriptCompiler::kConsumeParserCache); | 23268 v8::ScriptCompiler::kConsumeParserCache) |
23205 CHECK(!script.IsEmpty()); | 23269 .ToLocalChecked(); |
23270 USE(script); | |
23206 const v8::ScriptCompiler::CachedData* new_cached_data = | 23271 const v8::ScriptCompiler::CachedData* new_cached_data = |
23207 source_with_cached_data.GetCachedData(); | 23272 source_with_cached_data.GetCachedData(); |
23208 CHECK(new_cached_data != NULL); | 23273 CHECK(new_cached_data != NULL); |
23209 CHECK(!new_cached_data->rejected); | 23274 CHECK(!new_cached_data->rejected); |
23210 } | 23275 } |
23211 // Compile an incompatible script with the cached data. The new script doesn't | 23276 // Compile an incompatible script with the cached data. The new script doesn't |
23212 // have the same starting position for the function as the old one, so the old | 23277 // have the same starting position for the function as the old one, so the old |
23213 // cached data will be incompatible with it and will be rejected. | 23278 // cached data will be incompatible with it and will be rejected. |
23214 { | 23279 { |
23215 v8::Local<v8::String> incompatible_source_str = | 23280 v8::Local<v8::String> incompatible_source_str = |
23216 v8_str(" function foo() {}"); | 23281 v8_str(" function foo() {}"); |
23217 v8::ScriptCompiler::Source source_with_cached_data( | 23282 v8::ScriptCompiler::Source source_with_cached_data( |
23218 incompatible_source_str, origin, | 23283 incompatible_source_str, origin, |
23219 new v8::ScriptCompiler::CachedData(original_cached_data->data, | 23284 new v8::ScriptCompiler::CachedData(original_cached_data->data, |
23220 original_cached_data->length)); | 23285 original_cached_data->length)); |
23221 v8::Local<v8::Script> script = | 23286 v8::Local<v8::Script> script = |
23222 v8::ScriptCompiler::Compile(CcTest::isolate(), &source_with_cached_data, | 23287 v8::ScriptCompiler::Compile(context.local(), &source_with_cached_data, |
23223 v8::ScriptCompiler::kConsumeParserCache); | 23288 v8::ScriptCompiler::kConsumeParserCache) |
23224 CHECK(!script.IsEmpty()); | 23289 .ToLocalChecked(); |
23290 USE(script); | |
23225 const v8::ScriptCompiler::CachedData* new_cached_data = | 23291 const v8::ScriptCompiler::CachedData* new_cached_data = |
23226 source_with_cached_data.GetCachedData(); | 23292 source_with_cached_data.GetCachedData(); |
23227 CHECK(new_cached_data != NULL); | 23293 CHECK(new_cached_data != NULL); |
23228 CHECK(new_cached_data->rejected); | 23294 CHECK(new_cached_data->rejected); |
23229 } | 23295 } |
23230 } | 23296 } |
23231 | 23297 |
23232 | 23298 |
23233 TEST(StringConcatOverflow) { | 23299 TEST(StringConcatOverflow) { |
23234 v8::V8::Initialize(); | 23300 v8::V8::Initialize(); |
23235 v8::HandleScope scope(CcTest::isolate()); | 23301 v8::HandleScope scope(CcTest::isolate()); |
23236 RandomLengthOneByteResource* r = | 23302 RandomLengthOneByteResource* r = |
23237 new RandomLengthOneByteResource(i::String::kMaxLength); | 23303 new RandomLengthOneByteResource(i::String::kMaxLength); |
23238 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), r); | 23304 v8::Local<v8::String> str = |
23305 v8::String::NewExternalOneByte(CcTest::isolate(), r).ToLocalChecked(); | |
23239 CHECK(!str.IsEmpty()); | 23306 CHECK(!str.IsEmpty()); |
23240 v8::TryCatch try_catch(CcTest::isolate()); | 23307 v8::TryCatch try_catch(CcTest::isolate()); |
23241 v8::Local<v8::String> result = v8::String::Concat(str, str); | 23308 v8::Local<v8::String> result = v8::String::Concat(str, str); |
23242 CHECK(result.IsEmpty()); | 23309 CHECK(result.IsEmpty()); |
23243 CHECK(!try_catch.HasCaught()); | 23310 CHECK(!try_catch.HasCaught()); |
23244 } | 23311 } |
23245 | 23312 |
23246 | 23313 |
23247 TEST(TurboAsmDisablesNeuter) { | 23314 TEST(TurboAsmDisablesNeuter) { |
23248 v8::V8::Initialize(); | 23315 v8::V8::Initialize(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
23309 LocalContext env; | 23376 LocalContext env; |
23310 | 23377 |
23311 Local<FunctionTemplate> t = FunctionTemplate::New(isolate); | 23378 Local<FunctionTemplate> t = FunctionTemplate::New(isolate); |
23312 t->SetHiddenPrototype(true); | 23379 t->SetHiddenPrototype(true); |
23313 Local<Object> proto = t->GetFunction(env.local()) | 23380 Local<Object> proto = t->GetFunction(env.local()) |
23314 .ToLocalChecked() | 23381 .ToLocalChecked() |
23315 ->NewInstance(env.local()) | 23382 ->NewInstance(env.local()) |
23316 .ToLocalChecked(); | 23383 .ToLocalChecked(); |
23317 Local<Object> object = Object::New(isolate); | 23384 Local<Object> object = Object::New(isolate); |
23318 Local<Object> proto2 = Object::New(isolate); | 23385 Local<Object> proto2 = Object::New(isolate); |
23319 object->SetPrototype(proto); | 23386 object->SetPrototype(env.local(), proto).FromJust(); |
23320 proto->SetPrototype(proto2); | 23387 proto->SetPrototype(env.local(), proto2).FromJust(); |
23321 | 23388 |
23322 CHECK(env->Global()->Set(env.local(), v8_str("object"), object).FromJust()); | 23389 CHECK(env->Global()->Set(env.local(), v8_str("object"), object).FromJust()); |
23323 CHECK(env->Global()->Set(env.local(), v8_str("proto"), proto).FromJust()); | 23390 CHECK(env->Global()->Set(env.local(), v8_str("proto"), proto).FromJust()); |
23324 CHECK(env->Global()->Set(env.local(), v8_str("proto2"), proto2).FromJust()); | 23391 CHECK(env->Global()->Set(env.local(), v8_str("proto2"), proto2).FromJust()); |
23325 | 23392 |
23326 v8::Local<v8::Value> result = CompileRun("%_GetPrototype(object)"); | 23393 v8::Local<v8::Value> result = CompileRun("%_GetPrototype(object)"); |
23327 CHECK(result->Equals(proto2)); | 23394 CHECK(result->Equals(env.local(), proto2).FromJust()); |
23328 | 23395 |
23329 result = CompileRun( | 23396 result = CompileRun( |
23330 "function f() { return %_GetPrototype(object); }" | 23397 "function f() { return %_GetPrototype(object); }" |
23331 "%OptimizeFunctionOnNextCall(f);" | 23398 "%OptimizeFunctionOnNextCall(f);" |
23332 "f()"); | 23399 "f()"); |
23333 CHECK(result->Equals(proto2)); | 23400 CHECK(result->Equals(env.local(), proto2).FromJust()); |
23334 } | 23401 } |
23335 | 23402 |
23336 | 23403 |
23337 TEST(ClassPrototypeCreationContext) { | 23404 TEST(ClassPrototypeCreationContext) { |
23338 v8::Isolate* isolate = CcTest::isolate(); | 23405 v8::Isolate* isolate = CcTest::isolate(); |
23339 v8::HandleScope handle_scope(isolate); | 23406 v8::HandleScope handle_scope(isolate); |
23340 LocalContext env; | 23407 LocalContext env; |
23341 | 23408 |
23342 Local<Object> result = Local<Object>::Cast( | 23409 Local<Object> result = Local<Object>::Cast( |
23343 CompileRun("'use strict'; class Example { }; Example.prototype")); | 23410 CompileRun("'use strict'; class Example { }; Example.prototype")); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
23463 | 23530 |
23464 v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate); | 23531 v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate); |
23465 | 23532 |
23466 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42)); | 23533 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42)); |
23467 obj_template->SetAccessCheckCallback(AccessAlwaysAllowedWithFlag); | 23534 obj_template->SetAccessCheckCallback(AccessAlwaysAllowedWithFlag); |
23468 | 23535 |
23469 // Create an environment | 23536 // Create an environment |
23470 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template); | 23537 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template); |
23471 context0->Enter(); | 23538 context0->Enter(); |
23472 v8::Local<v8::Object> global0 = context0->Global(); | 23539 v8::Local<v8::Object> global0 = context0->Global(); |
23473 global0->Set(v8_str("object"), | 23540 global0->Set(context0, v8_str("object"), |
23474 obj_template->NewInstance(context0).ToLocalChecked()); | 23541 obj_template->NewInstance(context0).ToLocalChecked()) |
23542 .FromJust(); | |
23475 { | 23543 { |
23476 v8::TryCatch try_catch(isolate); | 23544 v8::TryCatch try_catch(isolate); |
23477 value = CompileRun("'use strong'; object.x"); | 23545 value = CompileRun("'use strong'; object.x"); |
23478 CHECK(!try_catch.HasCaught()); | 23546 CHECK(!try_catch.HasCaught()); |
23479 CHECK(!access_was_called); | 23547 CHECK(!access_was_called); |
23480 CHECK_EQ(42, value->Int32Value(context0).FromJust()); | 23548 CHECK_EQ(42, value->Int32Value(context0).FromJust()); |
23481 } | 23549 } |
23482 { | 23550 { |
23483 v8::TryCatch try_catch(isolate); | 23551 v8::TryCatch try_catch(isolate); |
23484 value = CompileRun("'use strong'; object.foo"); | 23552 value = CompileRun("'use strong'; object.foo"); |
23485 CHECK(try_catch.HasCaught()); | 23553 CHECK(try_catch.HasCaught()); |
23486 CHECK(!access_was_called); | 23554 CHECK(!access_was_called); |
23487 } | 23555 } |
23488 { | 23556 { |
23489 v8::TryCatch try_catch(isolate); | 23557 v8::TryCatch try_catch(isolate); |
23490 value = CompileRun("'use strong'; object[10]"); | 23558 value = CompileRun("'use strong'; object[10]"); |
23491 CHECK(try_catch.HasCaught()); | 23559 CHECK(try_catch.HasCaught()); |
23492 CHECK(!access_was_called); | 23560 CHECK(!access_was_called); |
23493 } | 23561 } |
23494 | 23562 |
23495 // Create an environment | 23563 // Create an environment |
23496 v8::Local<Context> context1 = Context::New(isolate); | 23564 v8::Local<Context> context1 = Context::New(isolate); |
23497 context1->Enter(); | 23565 context1->Enter(); |
23498 v8::Local<v8::Object> global1 = context1->Global(); | 23566 v8::Local<v8::Object> global1 = context1->Global(); |
23499 global1->Set(v8_str("object"), | 23567 global1->Set(context1, v8_str("object"), |
23500 obj_template->NewInstance(context1).ToLocalChecked()); | 23568 obj_template->NewInstance(context1).ToLocalChecked()) |
23569 .FromJust(); | |
23501 { | 23570 { |
23502 v8::TryCatch try_catch(isolate); | 23571 v8::TryCatch try_catch(isolate); |
23503 value = CompileRun("'use strong'; object.x"); | 23572 value = CompileRun("'use strong'; object.x"); |
23504 CHECK(!try_catch.HasCaught()); | 23573 CHECK(!try_catch.HasCaught()); |
23505 CHECK(access_was_called); | 23574 CHECK(access_was_called); |
23506 CHECK_EQ(42, value->Int32Value(context1).FromJust()); | 23575 CHECK_EQ(42, value->Int32Value(context1).FromJust()); |
23507 } | 23576 } |
23508 access_was_called = false; | 23577 access_was_called = false; |
23509 { | 23578 { |
23510 v8::TryCatch try_catch(isolate); | 23579 v8::TryCatch try_catch(isolate); |
(...skipping 23 matching lines...) Expand all Loading... | |
23534 | 23603 |
23535 v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate); | 23604 v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate); |
23536 | 23605 |
23537 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42)); | 23606 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42)); |
23538 obj_template->SetAccessCheckCallback(AccessAlwaysBlockedWithFlag); | 23607 obj_template->SetAccessCheckCallback(AccessAlwaysBlockedWithFlag); |
23539 | 23608 |
23540 // Create an environment | 23609 // Create an environment |
23541 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template); | 23610 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template); |
23542 context0->Enter(); | 23611 context0->Enter(); |
23543 v8::Local<v8::Object> global0 = context0->Global(); | 23612 v8::Local<v8::Object> global0 = context0->Global(); |
23544 global0->Set(v8_str("object"), | 23613 global0->Set(context0, v8_str("object"), |
23545 obj_template->NewInstance(context0).ToLocalChecked()); | 23614 obj_template->NewInstance(context0).ToLocalChecked()) |
23615 .FromJust(); | |
23546 { | 23616 { |
23547 v8::TryCatch try_catch(isolate); | 23617 v8::TryCatch try_catch(isolate); |
23548 value = CompileRun("'use strong'; object.x"); | 23618 value = CompileRun("'use strong'; object.x"); |
23549 CHECK(!try_catch.HasCaught()); | 23619 CHECK(!try_catch.HasCaught()); |
23550 CHECK(!access_was_called); | 23620 CHECK(!access_was_called); |
23551 CHECK_EQ(42, value->Int32Value(context0).FromJust()); | 23621 CHECK_EQ(42, value->Int32Value(context0).FromJust()); |
23552 } | 23622 } |
23553 { | 23623 { |
23554 v8::TryCatch try_catch(isolate); | 23624 v8::TryCatch try_catch(isolate); |
23555 value = CompileRun("'use strong'; object.foo"); | 23625 value = CompileRun("'use strong'; object.foo"); |
23556 CHECK(try_catch.HasCaught()); | 23626 CHECK(try_catch.HasCaught()); |
23557 CHECK(!access_was_called); | 23627 CHECK(!access_was_called); |
23558 } | 23628 } |
23559 { | 23629 { |
23560 v8::TryCatch try_catch(isolate); | 23630 v8::TryCatch try_catch(isolate); |
23561 value = CompileRun("'use strong'; object[10]"); | 23631 value = CompileRun("'use strong'; object[10]"); |
23562 CHECK(try_catch.HasCaught()); | 23632 CHECK(try_catch.HasCaught()); |
23563 CHECK(!access_was_called); | 23633 CHECK(!access_was_called); |
23564 } | 23634 } |
23565 | 23635 |
23566 // Create an environment | 23636 // Create an environment |
23567 v8::Local<Context> context1 = Context::New(isolate); | 23637 v8::Local<Context> context1 = Context::New(isolate); |
23568 context1->Enter(); | 23638 context1->Enter(); |
23569 v8::Local<v8::Object> global1 = context1->Global(); | 23639 v8::Local<v8::Object> global1 = context1->Global(); |
23570 global1->Set(v8_str("object"), | 23640 global1->Set(context1, v8_str("object"), |
23571 obj_template->NewInstance(context1).ToLocalChecked()); | 23641 obj_template->NewInstance(context1).ToLocalChecked()) |
23642 .FromJust(); | |
23572 { | 23643 { |
23573 v8::TryCatch try_catch(isolate); | 23644 v8::TryCatch try_catch(isolate); |
23574 value = CompileRun("'use strong'; object.x"); | 23645 value = CompileRun("'use strong'; object.x"); |
23575 CHECK(try_catch.HasCaught()); | 23646 CHECK(try_catch.HasCaught()); |
23576 CHECK(access_was_called); | 23647 CHECK(access_was_called); |
23577 } | 23648 } |
23578 access_was_called = false; | 23649 access_was_called = false; |
23579 { | 23650 { |
23580 v8::TryCatch try_catch(isolate); | 23651 v8::TryCatch try_catch(isolate); |
23581 value = CompileRun("'use strong'; object.foo"); | 23652 value = CompileRun("'use strong'; object.foo"); |
(...skipping 23 matching lines...) Expand all Loading... | |
23605 v8::TryCatch try_catch(isolate); | 23676 v8::TryCatch try_catch(isolate); |
23606 fun = Local<Function>::Cast(CompileRun( | 23677 fun = Local<Function>::Cast(CompileRun( |
23607 "function f(x) { 'use strong'; }" | 23678 "function f(x) { 'use strong'; }" |
23608 "f")); | 23679 "f")); |
23609 | 23680 |
23610 CHECK(!try_catch.HasCaught()); | 23681 CHECK(!try_catch.HasCaught()); |
23611 } | 23682 } |
23612 | 23683 |
23613 { | 23684 { |
23614 v8::TryCatch try_catch(isolate); | 23685 v8::TryCatch try_catch(isolate); |
23615 fun->Call(v8::Undefined(isolate), 0, nullptr); | 23686 CHECK(fun->Call(env.local(), v8::Undefined(isolate), 0, nullptr).IsEmpty()); |
23616 CHECK(try_catch.HasCaught()); | 23687 CHECK(try_catch.HasCaught()); |
23617 } | 23688 } |
23618 | 23689 |
23619 { | 23690 { |
23620 v8::TryCatch try_catch(isolate); | 23691 v8::TryCatch try_catch(isolate); |
23621 v8::Local<Value> args[] = {v8_num(42)}; | 23692 v8::Local<Value> args[] = {v8_num(42)}; |
23622 fun->Call(v8::Undefined(isolate), arraysize(args), args); | 23693 fun->Call(env.local(), v8::Undefined(isolate), arraysize(args), args) |
23694 .ToLocalChecked(); | |
23623 CHECK(!try_catch.HasCaught()); | 23695 CHECK(!try_catch.HasCaught()); |
23624 } | 23696 } |
23625 | 23697 |
23626 { | 23698 { |
23627 v8::TryCatch try_catch(isolate); | 23699 v8::TryCatch try_catch(isolate); |
23628 v8::Local<Value> args[] = {v8_num(42), v8_num(555)}; | 23700 v8::Local<Value> args[] = {v8_num(42), v8_num(555)}; |
23629 fun->Call(v8::Undefined(isolate), arraysize(args), args); | 23701 fun->Call(env.local(), v8::Undefined(isolate), arraysize(args), args) |
23702 .ToLocalChecked(); | |
23630 CHECK(!try_catch.HasCaught()); | 23703 CHECK(!try_catch.HasCaught()); |
23631 } | 23704 } |
23632 } | 23705 } |
23633 | 23706 |
23634 | 23707 |
23635 TEST(StrongModeArityCallFromApi2) { | 23708 TEST(StrongModeArityCallFromApi2) { |
23636 i::FLAG_strong_mode = true; | 23709 i::FLAG_strong_mode = true; |
23637 LocalContext env; | 23710 LocalContext env; |
23638 v8::Isolate* isolate = env->GetIsolate(); | 23711 v8::Isolate* isolate = env->GetIsolate(); |
23639 v8::HandleScope scope(isolate); | 23712 v8::HandleScope scope(isolate); |
23640 Local<Function> fun; | 23713 Local<Function> fun; |
23641 { | 23714 { |
23642 v8::TryCatch try_catch(isolate); | 23715 v8::TryCatch try_catch(isolate); |
23643 fun = Local<Function>::Cast(CompileRun( | 23716 fun = Local<Function>::Cast(CompileRun( |
23644 "'use strong';" | 23717 "'use strong';" |
23645 "function f(x) {}" | 23718 "function f(x) {}" |
23646 "f")); | 23719 "f")); |
23647 | 23720 |
23648 CHECK(!try_catch.HasCaught()); | 23721 CHECK(!try_catch.HasCaught()); |
23649 } | 23722 } |
23650 | 23723 |
23651 { | 23724 { |
23652 v8::TryCatch try_catch(isolate); | 23725 v8::TryCatch try_catch(isolate); |
23653 fun->Call(v8::Undefined(isolate), 0, nullptr); | 23726 CHECK(fun->Call(env.local(), v8::Undefined(isolate), 0, nullptr).IsEmpty()); |
23654 CHECK(try_catch.HasCaught()); | 23727 CHECK(try_catch.HasCaught()); |
23655 } | 23728 } |
23656 | 23729 |
23657 { | 23730 { |
23658 v8::TryCatch try_catch(isolate); | 23731 v8::TryCatch try_catch(isolate); |
23659 v8::Local<Value> args[] = {v8_num(42)}; | 23732 v8::Local<Value> args[] = {v8_num(42)}; |
23660 fun->Call(v8::Undefined(isolate), arraysize(args), args); | 23733 fun->Call(env.local(), v8::Undefined(isolate), arraysize(args), args) |
23734 .ToLocalChecked(); | |
23661 CHECK(!try_catch.HasCaught()); | 23735 CHECK(!try_catch.HasCaught()); |
23662 } | 23736 } |
23663 | 23737 |
23664 { | 23738 { |
23665 v8::TryCatch try_catch(isolate); | 23739 v8::TryCatch try_catch(isolate); |
23666 v8::Local<Value> args[] = {v8_num(42), v8_num(555)}; | 23740 v8::Local<Value> args[] = {v8_num(42), v8_num(555)}; |
23667 fun->Call(v8::Undefined(isolate), arraysize(args), args); | 23741 fun->Call(env.local(), v8::Undefined(isolate), arraysize(args), args) |
23742 .ToLocalChecked(); | |
23668 CHECK(!try_catch.HasCaught()); | 23743 CHECK(!try_catch.HasCaught()); |
23669 } | 23744 } |
23670 } | 23745 } |
23671 | 23746 |
23672 | 23747 |
23673 TEST(StrongObjectDelete) { | 23748 TEST(StrongObjectDelete) { |
23674 i::FLAG_strong_mode = true; | 23749 i::FLAG_strong_mode = true; |
23675 LocalContext env; | 23750 LocalContext env; |
23676 v8::Isolate* isolate = env->GetIsolate(); | 23751 v8::Isolate* isolate = env->GetIsolate(); |
23677 v8::HandleScope scope(isolate); | 23752 v8::HandleScope scope(isolate); |
23678 Local<Object> obj; | 23753 Local<Object> obj; |
23679 { | 23754 { |
23680 v8::TryCatch try_catch(isolate); | 23755 v8::TryCatch try_catch(isolate); |
23681 obj = Local<Object>::Cast(CompileRun( | 23756 obj = Local<Object>::Cast(CompileRun( |
23682 "'use strong';" | 23757 "'use strong';" |
23683 "({});")); | 23758 "({});")); |
23684 CHECK(!try_catch.HasCaught()); | 23759 CHECK(!try_catch.HasCaught()); |
23685 } | 23760 } |
23686 obj->ForceSet(v8_str("foo"), v8_num(1), v8::None); | 23761 obj->DefineOwnProperty(env.local(), v8_str("foo"), v8_num(1), v8::None) |
23687 obj->ForceSet(v8_str("2"), v8_num(1), v8::None); | 23762 .FromJust(); |
23688 CHECK(obj->HasOwnProperty(v8_str("foo"))); | 23763 obj->DefineOwnProperty(env.local(), v8_str("2"), v8_num(1), v8::None) |
23689 CHECK(obj->HasOwnProperty(v8_str("2"))); | 23764 .FromJust(); |
23690 CHECK(!obj->Delete(v8_str("foo"))); | 23765 CHECK(obj->HasOwnProperty(env.local(), v8_str("foo")).FromJust()); |
23691 CHECK(!obj->Delete(2)); | 23766 CHECK(obj->HasOwnProperty(env.local(), v8_str("2")).FromJust()); |
23767 CHECK(!obj->Delete(env.local(), v8_str("foo")).FromJust()); | |
23768 CHECK(!obj->Delete(env.local(), 2).FromJust()); | |
23692 } | 23769 } |
23693 | 23770 |
23694 | 23771 |
23695 static void ExtrasBindingTestRuntimeFunction( | 23772 static void ExtrasBindingTestRuntimeFunction( |
23696 const v8::FunctionCallbackInfo<v8::Value>& args) { | 23773 const v8::FunctionCallbackInfo<v8::Value>& args) { |
23697 CHECK_EQ( | 23774 CHECK_EQ( |
23698 3, | 23775 3, |
23699 args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromJust()); | 23776 args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromJust()); |
23700 args.GetReturnValue().Set(v8_num(7)); | 23777 args.GetReturnValue().Set(v8_num(7)); |
23701 } | 23778 } |
23702 | 23779 |
23703 | 23780 |
23704 TEST(ExtrasBindingObject) { | 23781 TEST(ExtrasBindingObject) { |
23705 v8::Isolate* isolate = CcTest::isolate(); | 23782 v8::Isolate* isolate = CcTest::isolate(); |
23706 v8::HandleScope handle_scope(isolate); | 23783 v8::HandleScope handle_scope(isolate); |
23707 LocalContext env; | 23784 LocalContext env; |
23708 | 23785 |
23709 // standalone.gypi ensures we include the test-extra.js file, which should | 23786 // standalone.gypi ensures we include the test-extra.js file, which should |
23710 // export the tested functions. | 23787 // export the tested functions. |
23711 v8::Local<v8::Object> binding = env->GetExtrasBindingObject(); | 23788 v8::Local<v8::Object> binding = env->GetExtrasBindingObject(); |
23712 | 23789 |
23713 auto func = | 23790 auto func = binding->Get(env.local(), v8_str("testExtraShouldReturnFive")) |
23714 binding->Get(v8_str("testExtraShouldReturnFive")).As<v8::Function>(); | 23791 .ToLocalChecked() |
23792 .As<v8::Function>(); | |
23715 auto undefined = v8::Undefined(isolate); | 23793 auto undefined = v8::Undefined(isolate); |
23716 auto result = func->Call(undefined, 0, {}).As<v8::Number>(); | 23794 auto result = func->Call(env.local(), undefined, 0, {}) |
23795 .ToLocalChecked() | |
23796 .As<v8::Number>(); | |
23717 CHECK_EQ(5, result->Int32Value(env.local()).FromJust()); | 23797 CHECK_EQ(5, result->Int32Value(env.local()).FromJust()); |
23718 | 23798 |
23719 v8::Local<v8::FunctionTemplate> runtimeFunction = | 23799 v8::Local<v8::FunctionTemplate> runtimeFunction = |
23720 v8::FunctionTemplate::New(isolate, ExtrasBindingTestRuntimeFunction); | 23800 v8::FunctionTemplate::New(isolate, ExtrasBindingTestRuntimeFunction); |
23721 binding->Set(v8_str("runtime"), | 23801 binding->Set(env.local(), v8_str("runtime"), |
23722 runtimeFunction->GetFunction(env.local()).ToLocalChecked()); | 23802 runtimeFunction->GetFunction(env.local()).ToLocalChecked()) |
23723 func = | 23803 .FromJust(); |
23724 binding->Get(v8_str("testExtraShouldCallToRuntime")).As<v8::Function>(); | 23804 func = binding->Get(env.local(), v8_str("testExtraShouldCallToRuntime")) |
23725 result = func->Call(undefined, 0, {}).As<v8::Number>(); | 23805 .ToLocalChecked() |
23806 .As<v8::Function>(); | |
23807 result = func->Call(env.local(), undefined, 0, {}) | |
23808 .ToLocalChecked() | |
23809 .As<v8::Number>(); | |
23726 CHECK_EQ(7, result->Int32Value(env.local()).FromJust()); | 23810 CHECK_EQ(7, result->Int32Value(env.local()).FromJust()); |
23727 } | 23811 } |
23728 | 23812 |
23729 | 23813 |
23730 TEST(ExperimentalExtras) { | 23814 TEST(ExperimentalExtras) { |
23731 i::FLAG_experimental_extras = true; | 23815 i::FLAG_experimental_extras = true; |
23732 | 23816 |
23733 v8::Isolate* isolate = CcTest::isolate(); | 23817 v8::Isolate* isolate = CcTest::isolate(); |
23734 v8::HandleScope handle_scope(isolate); | 23818 v8::HandleScope handle_scope(isolate); |
23735 LocalContext env; | 23819 LocalContext env; |
23736 | 23820 |
23737 // standalone.gypi ensures we include the test-experimental-extra.js file, | 23821 // standalone.gypi ensures we include the test-experimental-extra.js file, |
23738 // which should export the tested functions. | 23822 // which should export the tested functions. |
23739 v8::Local<v8::Object> binding = env->GetExtrasBindingObject(); | 23823 v8::Local<v8::Object> binding = env->GetExtrasBindingObject(); |
23740 | 23824 |
23741 auto func = binding->Get(v8_str("testExperimentalExtraShouldReturnTen")) | 23825 auto func = |
23742 .As<v8::Function>(); | 23826 binding->Get(env.local(), v8_str("testExperimentalExtraShouldReturnTen")) |
23827 .ToLocalChecked() | |
23828 .As<v8::Function>(); | |
23743 auto undefined = v8::Undefined(isolate); | 23829 auto undefined = v8::Undefined(isolate); |
23744 auto result = func->Call(undefined, 0, {}).As<v8::Number>(); | 23830 auto result = func->Call(env.local(), undefined, 0, {}) |
23831 .ToLocalChecked() | |
23832 .As<v8::Number>(); | |
23745 CHECK_EQ(10, result->Int32Value(env.local()).FromJust()); | 23833 CHECK_EQ(10, result->Int32Value(env.local()).FromJust()); |
23746 | 23834 |
23747 v8::Local<v8::FunctionTemplate> runtimeFunction = | 23835 v8::Local<v8::FunctionTemplate> runtimeFunction = |
23748 v8::FunctionTemplate::New(isolate, ExtrasBindingTestRuntimeFunction); | 23836 v8::FunctionTemplate::New(isolate, ExtrasBindingTestRuntimeFunction); |
23749 binding->Set(v8_str("runtime"), | 23837 binding->Set(env.local(), v8_str("runtime"), |
23750 runtimeFunction->GetFunction(env.local()).ToLocalChecked()); | 23838 runtimeFunction->GetFunction(env.local()).ToLocalChecked()) |
23751 func = binding->Get(v8_str("testExperimentalExtraShouldCallToRuntime")) | 23839 .FromJust(); |
23840 func = binding->Get(env.local(), | |
23841 v8_str("testExperimentalExtraShouldCallToRuntime")) | |
23842 .ToLocalChecked() | |
23752 .As<v8::Function>(); | 23843 .As<v8::Function>(); |
23753 result = func->Call(undefined, 0, {}).As<v8::Number>(); | 23844 result = func->Call(env.local(), undefined, 0, {}) |
23845 .ToLocalChecked() | |
23846 .As<v8::Number>(); | |
23754 CHECK_EQ(7, result->Int32Value(env.local()).FromJust()); | 23847 CHECK_EQ(7, result->Int32Value(env.local()).FromJust()); |
23755 } | 23848 } |
23756 | 23849 |
23757 | 23850 |
23758 TEST(ExtrasUtilsObject) { | 23851 TEST(ExtrasUtilsObject) { |
23759 LocalContext context; | 23852 LocalContext context; |
23760 v8::Isolate* isolate = context->GetIsolate(); | 23853 v8::Isolate* isolate = context->GetIsolate(); |
23761 v8::HandleScope handle_scope(isolate); | 23854 v8::HandleScope handle_scope(isolate); |
23762 | 23855 |
23763 LocalContext env; | 23856 LocalContext env; |
23764 v8::Local<v8::Object> binding = env->GetExtrasBindingObject(); | 23857 v8::Local<v8::Object> binding = env->GetExtrasBindingObject(); |
23765 | 23858 |
23766 auto func = binding->Get(v8_str("testExtraCanUseUtils")).As<v8::Function>(); | 23859 auto func = binding->Get(env.local(), v8_str("testExtraCanUseUtils")) |
23860 .ToLocalChecked() | |
23861 .As<v8::Function>(); | |
23767 auto undefined = v8::Undefined(isolate); | 23862 auto undefined = v8::Undefined(isolate); |
23768 auto result = func->Call(undefined, 0, {}).As<v8::Object>(); | 23863 auto result = func->Call(env.local(), undefined, 0, {}) |
23864 .ToLocalChecked() | |
23865 .As<v8::Object>(); | |
23769 | 23866 |
23770 auto private_symbol = result->Get(v8_str("privateSymbol")).As<v8::Symbol>(); | 23867 auto private_symbol = result->Get(env.local(), v8_str("privateSymbol")) |
23868 .ToLocalChecked() | |
23869 .As<v8::Symbol>(); | |
23771 i::Handle<i::Symbol> ips = v8::Utils::OpenHandle(*private_symbol); | 23870 i::Handle<i::Symbol> ips = v8::Utils::OpenHandle(*private_symbol); |
23772 CHECK_EQ(true, ips->IsPrivate()); | 23871 CHECK_EQ(true, ips->IsPrivate()); |
23773 | 23872 |
23774 CompileRun("var result = 0; function store(x) { result = x; }"); | 23873 CompileRun("var result = 0; function store(x) { result = x; }"); |
23775 auto store = CompileRun("store").As<v8::Function>(); | 23874 auto store = CompileRun("store").As<v8::Function>(); |
23776 | 23875 |
23777 auto fulfilled_promise = | 23876 auto fulfilled_promise = result->Get(env.local(), v8_str("fulfilledPromise")) |
23778 result->Get(v8_str("fulfilledPromise")).As<v8::Promise>(); | 23877 .ToLocalChecked() |
23779 fulfilled_promise->Then(store); | 23878 .As<v8::Promise>(); |
23879 fulfilled_promise->Then(env.local(), store).ToLocalChecked(); | |
23780 isolate->RunMicrotasks(); | 23880 isolate->RunMicrotasks(); |
23781 CHECK_EQ(1, CompileRun("result")->Int32Value(env.local()).FromJust()); | 23881 CHECK_EQ(1, CompileRun("result")->Int32Value(env.local()).FromJust()); |
23782 | 23882 |
23783 auto fulfilled_promise_2 = | 23883 auto fulfilled_promise_2 = |
23784 result->Get(v8_str("fulfilledPromise2")).As<v8::Promise>(); | 23884 result->Get(env.local(), v8_str("fulfilledPromise2")) |
23785 fulfilled_promise_2->Then(store); | 23885 .ToLocalChecked() |
23886 .As<v8::Promise>(); | |
23887 fulfilled_promise_2->Then(env.local(), store).ToLocalChecked(); | |
23786 isolate->RunMicrotasks(); | 23888 isolate->RunMicrotasks(); |
23787 CHECK_EQ(2, CompileRun("result")->Int32Value(env.local()).FromJust()); | 23889 CHECK_EQ(2, CompileRun("result")->Int32Value(env.local()).FromJust()); |
23788 | 23890 |
23789 auto rejected_promise = | 23891 auto rejected_promise = result->Get(env.local(), v8_str("rejectedPromise")) |
23790 result->Get(v8_str("rejectedPromise")).As<v8::Promise>(); | 23892 .ToLocalChecked() |
23791 rejected_promise->Catch(store); | 23893 .As<v8::Promise>(); |
23894 rejected_promise->Catch(env.local(), store).ToLocalChecked(); | |
23792 isolate->RunMicrotasks(); | 23895 isolate->RunMicrotasks(); |
23793 CHECK_EQ(3, CompileRun("result")->Int32Value(env.local()).FromJust()); | 23896 CHECK_EQ(3, CompileRun("result")->Int32Value(env.local()).FromJust()); |
23794 } | 23897 } |
23795 | 23898 |
23796 | 23899 |
23797 TEST(Map) { | 23900 TEST(Map) { |
23798 v8::Isolate* isolate = CcTest::isolate(); | 23901 v8::Isolate* isolate = CcTest::isolate(); |
23799 v8::HandleScope handle_scope(isolate); | 23902 v8::HandleScope handle_scope(isolate); |
23800 LocalContext env; | 23903 LocalContext env; |
23801 | 23904 |
23802 v8::Local<v8::Map> map = v8::Map::New(isolate); | 23905 v8::Local<v8::Map> map = v8::Map::New(isolate); |
23803 CHECK(map->IsObject()); | 23906 CHECK(map->IsObject()); |
23804 CHECK(map->IsMap()); | 23907 CHECK(map->IsMap()); |
23805 CHECK(map->GetPrototype()->StrictEquals(CompileRun("Map.prototype"))); | 23908 CHECK(map->GetPrototype()->StrictEquals(CompileRun("Map.prototype"))); |
23806 CHECK_EQ(0U, map->Size()); | 23909 CHECK_EQ(0U, map->Size()); |
23807 | 23910 |
23808 v8::Local<v8::Value> val = CompileRun("new Map([[1, 2], [3, 4]])"); | 23911 v8::Local<v8::Value> val = CompileRun("new Map([[1, 2], [3, 4]])"); |
23809 CHECK(val->IsMap()); | 23912 CHECK(val->IsMap()); |
23810 map = v8::Local<v8::Map>::Cast(val); | 23913 map = v8::Local<v8::Map>::Cast(val); |
23811 CHECK_EQ(2U, map->Size()); | 23914 CHECK_EQ(2U, map->Size()); |
23812 | 23915 |
23813 v8::Local<v8::Array> contents = map->AsArray(); | 23916 v8::Local<v8::Array> contents = map->AsArray(); |
23814 CHECK_EQ(4U, contents->Length()); | 23917 CHECK_EQ(4U, contents->Length()); |
23815 CHECK_EQ(1, contents->Get(0).As<v8::Int32>()->Value()); | 23918 CHECK_EQ( |
23816 CHECK_EQ(2, contents->Get(1).As<v8::Int32>()->Value()); | 23919 1, |
23817 CHECK_EQ(3, contents->Get(2).As<v8::Int32>()->Value()); | 23920 contents->Get(env.local(), 0).ToLocalChecked().As<v8::Int32>()->Value()); |
23818 CHECK_EQ(4, contents->Get(3).As<v8::Int32>()->Value()); | 23921 CHECK_EQ( |
23922 2, | |
23923 contents->Get(env.local(), 1).ToLocalChecked().As<v8::Int32>()->Value()); | |
23924 CHECK_EQ( | |
23925 3, | |
23926 contents->Get(env.local(), 2).ToLocalChecked().As<v8::Int32>()->Value()); | |
23927 CHECK_EQ( | |
23928 4, | |
23929 contents->Get(env.local(), 3).ToLocalChecked().As<v8::Int32>()->Value()); | |
23819 | 23930 |
23820 CHECK_EQ(2U, map->Size()); | 23931 CHECK_EQ(2U, map->Size()); |
23821 | 23932 |
23822 CHECK(map->Has(env.local(), v8::Integer::New(isolate, 1)).FromJust()); | 23933 CHECK(map->Has(env.local(), v8::Integer::New(isolate, 1)).FromJust()); |
23823 CHECK(map->Has(env.local(), v8::Integer::New(isolate, 3)).FromJust()); | 23934 CHECK(map->Has(env.local(), v8::Integer::New(isolate, 3)).FromJust()); |
23824 | 23935 |
23825 CHECK(!map->Has(env.local(), v8::Integer::New(isolate, 2)).FromJust()); | 23936 CHECK(!map->Has(env.local(), v8::Integer::New(isolate, 2)).FromJust()); |
23826 CHECK(!map->Has(env.local(), map).FromJust()); | 23937 CHECK(!map->Has(env.local(), map).FromJust()); |
23827 | 23938 |
23828 CHECK_EQ(2, map->Get(env.local(), v8::Integer::New(isolate, 1)) | 23939 CHECK_EQ(2, map->Get(env.local(), v8::Integer::New(isolate, 1)) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
23863 CHECK(set->GetPrototype()->StrictEquals(CompileRun("Set.prototype"))); | 23974 CHECK(set->GetPrototype()->StrictEquals(CompileRun("Set.prototype"))); |
23864 CHECK_EQ(0U, set->Size()); | 23975 CHECK_EQ(0U, set->Size()); |
23865 | 23976 |
23866 v8::Local<v8::Value> val = CompileRun("new Set([1, 2])"); | 23977 v8::Local<v8::Value> val = CompileRun("new Set([1, 2])"); |
23867 CHECK(val->IsSet()); | 23978 CHECK(val->IsSet()); |
23868 set = v8::Local<v8::Set>::Cast(val); | 23979 set = v8::Local<v8::Set>::Cast(val); |
23869 CHECK_EQ(2U, set->Size()); | 23980 CHECK_EQ(2U, set->Size()); |
23870 | 23981 |
23871 v8::Local<v8::Array> keys = set->AsArray(); | 23982 v8::Local<v8::Array> keys = set->AsArray(); |
23872 CHECK_EQ(2U, keys->Length()); | 23983 CHECK_EQ(2U, keys->Length()); |
23873 CHECK_EQ(1, keys->Get(0).As<v8::Int32>()->Value()); | 23984 CHECK_EQ(1, |
23874 CHECK_EQ(2, keys->Get(1).As<v8::Int32>()->Value()); | 23985 keys->Get(env.local(), 0).ToLocalChecked().As<v8::Int32>()->Value()); |
23986 CHECK_EQ(2, | |
23987 keys->Get(env.local(), 1).ToLocalChecked().As<v8::Int32>()->Value()); | |
23875 | 23988 |
23876 CHECK_EQ(2U, set->Size()); | 23989 CHECK_EQ(2U, set->Size()); |
23877 | 23990 |
23878 CHECK(set->Has(env.local(), v8::Integer::New(isolate, 1)).FromJust()); | 23991 CHECK(set->Has(env.local(), v8::Integer::New(isolate, 1)).FromJust()); |
23879 CHECK(set->Has(env.local(), v8::Integer::New(isolate, 2)).FromJust()); | 23992 CHECK(set->Has(env.local(), v8::Integer::New(isolate, 2)).FromJust()); |
23880 | 23993 |
23881 CHECK(!set->Has(env.local(), v8::Integer::New(isolate, 3)).FromJust()); | 23994 CHECK(!set->Has(env.local(), v8::Integer::New(isolate, 3)).FromJust()); |
23882 CHECK(!set->Has(env.local(), set).FromJust()); | 23995 CHECK(!set->Has(env.local(), set).FromJust()); |
23883 | 23996 |
23884 CHECK(!set->Add(env.local(), set).IsEmpty()); | 23997 CHECK(!set->Add(env.local(), set).IsEmpty()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
23937 } | 24050 } |
23938 | 24051 |
23939 class FutexInterruptionThread : public v8::base::Thread { | 24052 class FutexInterruptionThread : public v8::base::Thread { |
23940 public: | 24053 public: |
23941 explicit FutexInterruptionThread(v8::Isolate* isolate) | 24054 explicit FutexInterruptionThread(v8::Isolate* isolate) |
23942 : Thread(Options("FutexInterruptionThread")), isolate_(isolate) {} | 24055 : Thread(Options("FutexInterruptionThread")), isolate_(isolate) {} |
23943 | 24056 |
23944 virtual void Run() { | 24057 virtual void Run() { |
23945 // Wait a bit before terminating. | 24058 // Wait a bit before terminating. |
23946 v8::base::OS::Sleep(v8::base::TimeDelta::FromMilliseconds(100)); | 24059 v8::base::OS::Sleep(v8::base::TimeDelta::FromMilliseconds(100)); |
23947 v8::V8::TerminateExecution(isolate_); | 24060 isolate_->TerminateExecution(); |
23948 } | 24061 } |
23949 | 24062 |
23950 private: | 24063 private: |
23951 v8::Isolate* isolate_; | 24064 v8::Isolate* isolate_; |
23952 }; | 24065 }; |
23953 | 24066 |
23954 | 24067 |
23955 TEST(FutexInterruption) { | 24068 TEST(FutexInterruption) { |
23956 i::FLAG_harmony_sharedarraybuffer = true; | 24069 i::FLAG_harmony_sharedarraybuffer = true; |
23957 v8::Isolate* isolate = CcTest::isolate(); | 24070 v8::Isolate* isolate = CcTest::isolate(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
23995 v8::Local<v8::ObjectTemplate> global_template = | 24108 v8::Local<v8::ObjectTemplate> global_template = |
23996 v8::ObjectTemplate::New(isolate); | 24109 v8::ObjectTemplate::New(isolate); |
23997 LocalContext env(NULL, global_template); | 24110 LocalContext env(NULL, global_template); |
23998 | 24111 |
23999 i::FLAG_abort_on_uncaught_exception = true; | 24112 i::FLAG_abort_on_uncaught_exception = true; |
24000 isolate->SetAbortOnUncaughtExceptionCallback(NoAbortOnUncaughtException); | 24113 isolate->SetAbortOnUncaughtExceptionCallback(NoAbortOnUncaughtException); |
24001 | 24114 |
24002 CompileRun("function boom() { throw new Error(\"boom\") }"); | 24115 CompileRun("function boom() { throw new Error(\"boom\") }"); |
24003 | 24116 |
24004 v8::Local<v8::Object> global_object = env->Global(); | 24117 v8::Local<v8::Object> global_object = env->Global(); |
24005 v8::Local<v8::Function> foo = | 24118 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( |
24006 v8::Local<v8::Function>::Cast(global_object->Get(v8_str("boom"))); | 24119 global_object->Get(env.local(), v8_str("boom")).ToLocalChecked()); |
24007 | 24120 |
24008 foo->Call(global_object, 0, NULL); | 24121 CHECK(foo->Call(env.local(), global_object, 0, NULL).IsEmpty()); |
24009 | 24122 |
24010 CHECK_EQ(1, nb_uncaught_exception_callback_calls); | 24123 CHECK_EQ(1, nb_uncaught_exception_callback_calls); |
24011 } | 24124 } |
24012 | 24125 |
24013 | 24126 |
24014 TEST(AccessCheckedIsConcatSpreadable) { | 24127 TEST(AccessCheckedIsConcatSpreadable) { |
24015 i::FLAG_harmony_concat_spreadable = true; | 24128 i::FLAG_harmony_concat_spreadable = true; |
24016 v8::Isolate* isolate = CcTest::isolate(); | 24129 v8::Isolate* isolate = CcTest::isolate(); |
24017 HandleScope scope(isolate); | 24130 HandleScope scope(isolate); |
24018 LocalContext env; | 24131 LocalContext env; |
24019 | 24132 |
24020 // Object with access check | 24133 // Object with access check |
24021 Local<ObjectTemplate> spreadable_template = v8::ObjectTemplate::New(isolate); | 24134 Local<ObjectTemplate> spreadable_template = v8::ObjectTemplate::New(isolate); |
24022 spreadable_template->SetAccessCheckCallback(AccessBlocker); | 24135 spreadable_template->SetAccessCheckCallback(AccessBlocker); |
24023 spreadable_template->Set(v8::Symbol::GetIsConcatSpreadable(isolate), | 24136 spreadable_template->Set(v8::Symbol::GetIsConcatSpreadable(isolate), |
24024 v8::Boolean::New(isolate, true)); | 24137 v8::Boolean::New(isolate, true)); |
24025 Local<Object> object = | 24138 Local<Object> object = |
24026 spreadable_template->NewInstance(env.local()).ToLocalChecked(); | 24139 spreadable_template->NewInstance(env.local()).ToLocalChecked(); |
24027 | 24140 |
24028 allowed_access = true; | 24141 allowed_access = true; |
24029 CHECK(env->Global()->Set(env.local(), v8_str("object"), object).FromJust()); | 24142 CHECK(env->Global()->Set(env.local(), v8_str("object"), object).FromJust()); |
24030 object->Set(v8_str("length"), v8_num(2)); | 24143 object->Set(env.local(), v8_str("length"), v8_num(2)).FromJust(); |
24031 object->Set(0U, v8_str("a")); | 24144 object->Set(env.local(), 0U, v8_str("a")).FromJust(); |
24032 object->Set(1U, v8_str("b")); | 24145 object->Set(env.local(), 1U, v8_str("b")).FromJust(); |
24033 | 24146 |
24034 // Access check is allowed, and the object is spread | 24147 // Access check is allowed, and the object is spread |
24035 CompileRun("var result = [].concat(object)"); | 24148 CompileRun("var result = [].concat(object)"); |
24036 ExpectTrue("Array.isArray(result)"); | 24149 ExpectTrue("Array.isArray(result)"); |
24037 ExpectString("result[0]", "a"); | 24150 ExpectString("result[0]", "a"); |
24038 ExpectString("result[1]", "b"); | 24151 ExpectString("result[1]", "b"); |
24039 ExpectTrue("result.length === 2"); | 24152 ExpectTrue("result.length === 2"); |
24040 ExpectTrue("object[Symbol.isConcatSpreadable]"); | 24153 ExpectTrue("object[Symbol.isConcatSpreadable]"); |
24041 | 24154 |
24042 // If access check fails, the value of @@isConcatSpreadable is ignored | 24155 // If access check fails, the value of @@isConcatSpreadable is ignored |
24043 allowed_access = false; | 24156 allowed_access = false; |
24044 CompileRun("var result = [].concat(object)"); | 24157 CompileRun("var result = [].concat(object)"); |
24045 ExpectTrue("Array.isArray(result)"); | 24158 ExpectTrue("Array.isArray(result)"); |
24046 ExpectTrue("result[0] === object"); | 24159 ExpectTrue("result[0] === object"); |
24047 ExpectTrue("result.length === 1"); | 24160 ExpectTrue("result.length === 1"); |
24048 ExpectTrue("object[Symbol.isConcatSpreadable] === undefined"); | 24161 ExpectTrue("object[Symbol.isConcatSpreadable] === undefined"); |
24049 } | 24162 } |
24050 | 24163 |
24051 | 24164 |
24052 TEST(AccessCheckedToStringTag) { | 24165 TEST(AccessCheckedToStringTag) { |
24053 i::FLAG_harmony_tostring = true; | 24166 i::FLAG_harmony_tostring = true; |
24054 v8::Isolate* isolate = CcTest::isolate(); | 24167 v8::Isolate* isolate = CcTest::isolate(); |
24055 HandleScope scope(isolate); | 24168 HandleScope scope(isolate); |
24056 LocalContext env; | 24169 LocalContext env; |
24057 | 24170 |
24058 // Object with access check | 24171 // Object with access check |
24059 Local<ObjectTemplate> object_template = v8::ObjectTemplate::New(isolate); | 24172 Local<ObjectTemplate> object_template = v8::ObjectTemplate::New(isolate); |
24060 object_template->SetAccessCheckCallback(AccessBlocker); | 24173 object_template->SetAccessCheckCallback(AccessBlocker); |
24061 Local<Object> object = object_template->NewInstance(); | 24174 Local<Object> object = |
24175 object_template->NewInstance(env.local()).ToLocalChecked(); | |
24062 | 24176 |
24063 allowed_access = true; | 24177 allowed_access = true; |
24064 env->Global()->Set(v8_str("object"), object); | 24178 env->Global()->Set(env.local(), v8_str("object"), object).FromJust(); |
24065 object->Set(v8::Symbol::GetToStringTag(isolate), v8_str("hello")); | 24179 object->Set(env.local(), v8::Symbol::GetToStringTag(isolate), v8_str("hello")) |
24180 .FromJust(); | |
24066 | 24181 |
24067 // Access check is allowed, and the toStringTag is read | 24182 // Access check is allowed, and the toStringTag is read |
24068 CompileRun("var result = Object.prototype.toString.call(object)"); | 24183 CompileRun("var result = Object.prototype.toString.call(object)"); |
24069 ExpectString("result", "[object hello]"); | 24184 ExpectString("result", "[object hello]"); |
24070 ExpectString("object[Symbol.toStringTag]", "hello"); | 24185 ExpectString("object[Symbol.toStringTag]", "hello"); |
24071 | 24186 |
24072 // ToString through the API should succeed too. | 24187 // ToString through the API should succeed too. |
24073 String::Utf8Value result_allowed( | 24188 String::Utf8Value result_allowed( |
24074 object->ObjectProtoToString(env.local()).ToLocalChecked()); | 24189 object->ObjectProtoToString(env.local()).ToLocalChecked()); |
24075 CHECK_EQ(0, strcmp(*result_allowed, "[object hello]")); | 24190 CHECK_EQ(0, strcmp(*result_allowed, "[object hello]")); |
(...skipping 18 matching lines...) Expand all Loading... | |
24094 | 24209 |
24095 Local<ObjectTemplate> object_template = v8::ObjectTemplate::New(isolate); | 24210 Local<ObjectTemplate> object_template = v8::ObjectTemplate::New(isolate); |
24096 object_template->SetIntrinsicDataProperty(v8_str("values"), | 24211 object_template->SetIntrinsicDataProperty(v8_str("values"), |
24097 v8::kArrayProto_values); | 24212 v8::kArrayProto_values); |
24098 Local<Object> object = | 24213 Local<Object> object = |
24099 object_template->NewInstance(env.local()).ToLocalChecked(); | 24214 object_template->NewInstance(env.local()).ToLocalChecked(); |
24100 | 24215 |
24101 CHECK(env->Global()->Set(env.local(), v8_str("obj1"), object).FromJust()); | 24216 CHECK(env->Global()->Set(env.local(), v8_str("obj1"), object).FromJust()); |
24102 ExpectString("typeof obj1.values", "function"); | 24217 ExpectString("typeof obj1.values", "function"); |
24103 | 24218 |
24104 auto values = Local<Function>::Cast(object->Get(v8_str("values"))); | 24219 auto values = Local<Function>::Cast( |
24220 object->Get(env.local(), v8_str("values")).ToLocalChecked()); | |
24105 auto fn = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values)); | 24221 auto fn = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values)); |
24106 auto ctx = v8::Utils::OpenHandle(*env.local()); | 24222 auto ctx = v8::Utils::OpenHandle(*env.local()); |
24107 CHECK_EQ(fn->GetCreationContext(), *ctx); | 24223 CHECK_EQ(fn->GetCreationContext(), *ctx); |
24108 | 24224 |
24109 { | 24225 { |
24110 LocalContext env2; | 24226 LocalContext env2; |
24111 Local<Object> object2 = | 24227 Local<Object> object2 = |
24112 object_template->NewInstance(env2.local()).ToLocalChecked(); | 24228 object_template->NewInstance(env2.local()).ToLocalChecked(); |
24113 CHECK( | 24229 CHECK( |
24114 env2->Global()->Set(env2.local(), v8_str("obj2"), object2).FromJust()); | 24230 env2->Global()->Set(env2.local(), v8_str("obj2"), object2).FromJust()); |
24115 ExpectString("typeof obj2.values", "function"); | 24231 ExpectString("typeof obj2.values", "function"); |
24116 CHECK_NE(*object->Get(v8_str("values")), *object2->Get(v8_str("values"))); | 24232 CHECK_NE(*object->Get(env2.local(), v8_str("values")).ToLocalChecked(), |
24233 *object2->Get(env2.local(), v8_str("values")).ToLocalChecked()); | |
24117 | 24234 |
24118 auto values2 = Local<Function>::Cast(object2->Get(v8_str("values"))); | 24235 auto values2 = Local<Function>::Cast( |
24236 object2->Get(env2.local(), v8_str("values")).ToLocalChecked()); | |
24119 auto fn2 = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values2)); | 24237 auto fn2 = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values2)); |
24120 auto ctx2 = v8::Utils::OpenHandle(*env2.local()); | 24238 auto ctx2 = v8::Utils::OpenHandle(*env2.local()); |
24121 CHECK_EQ(fn2->GetCreationContext(), *ctx2); | 24239 CHECK_EQ(fn2->GetCreationContext(), *ctx2); |
24122 } | 24240 } |
24123 } | 24241 } |
OLD | NEW |