OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 14 matching lines...) Expand all Loading... |
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 #include <limits.h> | 28 #include <limits.h> |
29 | 29 |
30 #ifndef WIN32 | 30 #ifndef WIN32 |
31 #include <signal.h> // kill | 31 #include <signal.h> // kill |
32 #include <unistd.h> // getpid | 32 #include <unistd.h> // getpid |
33 #endif // WIN32 | 33 #endif // WIN32 |
34 | 34 |
| 35 // TODO(dcarney): remove |
| 36 #define V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 37 #define V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT |
| 38 #define V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW |
| 39 |
35 #include "v8.h" | 40 #include "v8.h" |
36 | 41 |
37 #include "api.h" | 42 #include "api.h" |
38 #include "isolate.h" | 43 #include "isolate.h" |
39 #include "compilation-cache.h" | 44 #include "compilation-cache.h" |
40 #include "execution.h" | 45 #include "execution.h" |
41 #include "objects.h" | 46 #include "objects.h" |
42 #include "snapshot.h" | 47 #include "snapshot.h" |
43 #include "platform.h" | 48 #include "platform.h" |
44 #include "utils.h" | 49 #include "utils.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 const char* c_source = "1 + 2 + 3"; | 159 const char* c_source = "1 + 2 + 3"; |
155 Local<String> source = String::New(c_source); | 160 Local<String> source = String::New(c_source); |
156 Local<Script> script = Script::Compile(source); | 161 Local<Script> script = Script::Compile(source); |
157 CHECK_EQ(6, script->Run()->Int32Value()); | 162 CHECK_EQ(6, script->Run()->Int32Value()); |
158 | 163 |
159 local_env->Exit(); | 164 local_env->Exit(); |
160 } | 165 } |
161 | 166 |
162 | 167 |
163 THREADED_TEST(IsolateOfContext) { | 168 THREADED_TEST(IsolateOfContext) { |
164 v8::Persistent<Context> env = Context::New(); | 169 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
165 v8::HandleScope scope(env->GetIsolate()); | 170 v8::Handle<Context> env = Context::New(v8::Isolate::GetCurrent()); |
166 | 171 |
167 CHECK(!env->InContext()); | 172 CHECK(!env->InContext()); |
168 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); | 173 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); |
169 env->Enter(); | 174 env->Enter(); |
170 CHECK(env->InContext()); | 175 CHECK(env->InContext()); |
171 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); | 176 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); |
172 env->Exit(); | 177 env->Exit(); |
173 CHECK(!env->InContext()); | 178 CHECK(!env->InContext()); |
174 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); | 179 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); |
175 | |
176 env.Dispose(env->GetIsolate()); | |
177 } | 180 } |
178 | 181 |
179 | 182 |
180 THREADED_TEST(ReceiverSignature) { | 183 THREADED_TEST(ReceiverSignature) { |
181 LocalContext env; | 184 LocalContext env; |
182 v8::HandleScope scope(env->GetIsolate()); | 185 v8::HandleScope scope(env->GetIsolate()); |
183 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(); | 186 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(); |
184 v8::Handle<v8::Signature> sig = v8::Signature::New(fun); | 187 v8::Handle<v8::Signature> sig = v8::Signature::New(fun); |
185 fun->PrototypeTemplate()->Set( | 188 fun->PrototypeTemplate()->Set( |
186 v8_str("m"), | 189 v8_str("m"), |
(...skipping 2285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2472 g2s2 = Persistent<Object>::New(iso, Object::New()); | 2475 g2s2 = Persistent<Object>::New(iso, Object::New()); |
2473 g2c1 = Persistent<Object>::New(iso, Object::New()); | 2476 g2c1 = Persistent<Object>::New(iso, Object::New()); |
2474 g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); | 2477 g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); |
2475 g2s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); | 2478 g2s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); |
2476 g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); | 2479 g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); |
2477 } | 2480 } |
2478 | 2481 |
2479 Persistent<Object> root = Persistent<Object>::New(iso, g1s1); // make a root. | 2482 Persistent<Object> root = Persistent<Object>::New(iso, g1s1); // make a root. |
2480 | 2483 |
2481 // Connect group 1 and 2, make a cycle. | 2484 // Connect group 1 and 2, make a cycle. |
2482 CHECK(g1s2->Set(0, g2s2)); | 2485 CHECK(g1s2->Set(0, Handle<Object>(*g2s2))); |
2483 CHECK(g2s1->Set(0, g1s1)); | 2486 CHECK(g2s1->Set(0, Handle<Object>(*g1s1))); |
2484 | 2487 |
2485 { | 2488 { |
2486 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; | 2489 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; |
2487 Persistent<Value> g1_children[] = { g1c1 }; | 2490 Persistent<Value> g1_children[] = { g1c1 }; |
2488 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; | 2491 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; |
2489 Persistent<Value> g2_children[] = { g2c1 }; | 2492 Persistent<Value> g2_children[] = { g2c1 }; |
2490 V8::AddObjectGroup(g1_objects, 2); | 2493 V8::AddObjectGroup(g1_objects, 2); |
2491 V8::AddImplicitReferences(g1s1, g1_children, 1); | 2494 V8::AddImplicitReferences(g1s1, g1_children, 1); |
2492 V8::AddObjectGroup(g2_objects, 2); | 2495 V8::AddObjectGroup(g2_objects, 2); |
2493 V8::AddImplicitReferences(g2s2, g2_children, 1); | 2496 V8::AddImplicitReferences(g2s2, g2_children, 1); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2684 g1s1.MarkPartiallyDependent(iso); | 2687 g1s1.MarkPartiallyDependent(iso); |
2685 g1s2.MarkPartiallyDependent(iso); | 2688 g1s2.MarkPartiallyDependent(iso); |
2686 g2s1.MarkPartiallyDependent(iso); | 2689 g2s1.MarkPartiallyDependent(iso); |
2687 g2s2.MarkPartiallyDependent(iso); | 2690 g2s2.MarkPartiallyDependent(iso); |
2688 g3s1.MarkPartiallyDependent(iso); | 2691 g3s1.MarkPartiallyDependent(iso); |
2689 g3s2.MarkPartiallyDependent(iso); | 2692 g3s2.MarkPartiallyDependent(iso); |
2690 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; | 2693 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; |
2691 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; | 2694 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; |
2692 Persistent<Value> g3_objects[] = { g3s1, g3s2 }; | 2695 Persistent<Value> g3_objects[] = { g3s1, g3s2 }; |
2693 V8::AddObjectGroup(g1_objects, 2); | 2696 V8::AddObjectGroup(g1_objects, 2); |
2694 g1s1->Set(v8_str("x"), g2s1); | 2697 g1s1->Set(v8_str("x"), Handle<Object>(*g2s1)); |
2695 V8::AddObjectGroup(g2_objects, 2); | 2698 V8::AddObjectGroup(g2_objects, 2); |
2696 g2s1->Set(v8_str("x"), g3s1); | 2699 g2s1->Set(v8_str("x"), Handle<Object>(*g3s1)); |
2697 V8::AddObjectGroup(g3_objects, 2); | 2700 V8::AddObjectGroup(g3_objects, 2); |
2698 g3s1->Set(v8_str("x"), g1s1); | 2701 g3s1->Set(v8_str("x"), Handle<Object>(*g1s1)); |
2699 } | 2702 } |
2700 | 2703 |
2701 HEAP->CollectGarbage(i::NEW_SPACE); | 2704 HEAP->CollectGarbage(i::NEW_SPACE); |
2702 | 2705 |
2703 // All objects should be alive. | 2706 // All objects should be alive. |
2704 CHECK_EQ(0, counter.NumberOfWeakCalls()); | 2707 CHECK_EQ(0, counter.NumberOfWeakCalls()); |
2705 | 2708 |
2706 // Weaken the root. | 2709 // Weaken the root. |
2707 root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); | 2710 root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); |
2708 root.MarkPartiallyDependent(iso); | 2711 root.MarkPartiallyDependent(iso); |
2709 | 2712 |
2710 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 2713 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
2711 // Groups are deleted, rebuild groups. | 2714 // Groups are deleted, rebuild groups. |
2712 { | 2715 { |
2713 g1s1.MarkPartiallyDependent(isolate); | 2716 g1s1.MarkPartiallyDependent(isolate); |
2714 g1s2.MarkPartiallyDependent(isolate); | 2717 g1s2.MarkPartiallyDependent(isolate); |
2715 g2s1.MarkPartiallyDependent(isolate); | 2718 g2s1.MarkPartiallyDependent(isolate); |
2716 g2s2.MarkPartiallyDependent(isolate); | 2719 g2s2.MarkPartiallyDependent(isolate); |
2717 g3s1.MarkPartiallyDependent(isolate); | 2720 g3s1.MarkPartiallyDependent(isolate); |
2718 g3s2.MarkPartiallyDependent(isolate); | 2721 g3s2.MarkPartiallyDependent(isolate); |
2719 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; | 2722 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; |
2720 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; | 2723 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; |
2721 Persistent<Value> g3_objects[] = { g3s1, g3s2 }; | 2724 Persistent<Value> g3_objects[] = { g3s1, g3s2 }; |
2722 V8::AddObjectGroup(g1_objects, 2); | 2725 V8::AddObjectGroup(g1_objects, 2); |
2723 g1s1->Set(v8_str("x"), g2s1); | 2726 g1s1->Set(v8_str("x"), Handle<Object>(*g2s1)); |
2724 V8::AddObjectGroup(g2_objects, 2); | 2727 V8::AddObjectGroup(g2_objects, 2); |
2725 g2s1->Set(v8_str("x"), g3s1); | 2728 g2s1->Set(v8_str("x"), Handle<Object>(*g3s1)); |
2726 V8::AddObjectGroup(g3_objects, 2); | 2729 V8::AddObjectGroup(g3_objects, 2); |
2727 g3s1->Set(v8_str("x"), g1s1); | 2730 g3s1->Set(v8_str("x"), Handle<Object>(*g1s1)); |
2728 } | 2731 } |
2729 | 2732 |
2730 HEAP->CollectGarbage(i::NEW_SPACE); | 2733 HEAP->CollectGarbage(i::NEW_SPACE); |
2731 | 2734 |
2732 // All objects should be gone. 7 global handles in total. | 2735 // All objects should be gone. 7 global handles in total. |
2733 CHECK_EQ(7, counter.NumberOfWeakCalls()); | 2736 CHECK_EQ(7, counter.NumberOfWeakCalls()); |
2734 } | 2737 } |
2735 | 2738 |
2736 | 2739 |
2737 THREADED_TEST(ScriptException) { | 2740 THREADED_TEST(ScriptException) { |
(...skipping 1433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4171 THREADED_TEST(SimplePropertyWrite) { | 4174 THREADED_TEST(SimplePropertyWrite) { |
4172 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 4175 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
4173 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4176 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
4174 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut")); | 4177 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut")); |
4175 LocalContext context; | 4178 LocalContext context; |
4176 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 4179 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
4177 Local<Script> script = Script::Compile(v8_str("obj.x = 4")); | 4180 Local<Script> script = Script::Compile(v8_str("obj.x = 4")); |
4178 for (int i = 0; i < 10; i++) { | 4181 for (int i = 0; i < 10; i++) { |
4179 CHECK(xValue.IsEmpty()); | 4182 CHECK(xValue.IsEmpty()); |
4180 script->Run(); | 4183 script->Run(); |
4181 CHECK_EQ(v8_num(4), xValue); | 4184 CHECK_EQ(v8_num(4), Handle<Value>(*xValue)); |
4182 xValue.Dispose(context->GetIsolate()); | 4185 xValue.Dispose(context->GetIsolate()); |
4183 xValue = v8::Persistent<Value>(); | 4186 xValue = v8::Persistent<Value>(); |
4184 } | 4187 } |
4185 } | 4188 } |
4186 | 4189 |
4187 | 4190 |
4188 THREADED_TEST(SetterOnly) { | 4191 THREADED_TEST(SetterOnly) { |
4189 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 4192 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
4190 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4193 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
4191 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut")); | 4194 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut")); |
4192 LocalContext context; | 4195 LocalContext context; |
4193 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 4196 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
4194 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); | 4197 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); |
4195 for (int i = 0; i < 10; i++) { | 4198 for (int i = 0; i < 10; i++) { |
4196 CHECK(xValue.IsEmpty()); | 4199 CHECK(xValue.IsEmpty()); |
4197 script->Run(); | 4200 script->Run(); |
4198 CHECK_EQ(v8_num(4), xValue); | 4201 CHECK_EQ(v8_num(4), Handle<Value>(*xValue)); |
4199 xValue.Dispose(context->GetIsolate()); | 4202 xValue.Dispose(context->GetIsolate()); |
4200 xValue = v8::Persistent<Value>(); | 4203 xValue = v8::Persistent<Value>(); |
4201 } | 4204 } |
4202 } | 4205 } |
4203 | 4206 |
4204 | 4207 |
4205 THREADED_TEST(NoAccessors) { | 4208 THREADED_TEST(NoAccessors) { |
4206 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 4209 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
4207 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4210 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
4208 templ->SetAccessor(v8_str("x"), NULL, NULL, v8_str("donut")); | 4211 templ->SetAccessor(v8_str("x"), NULL, NULL, v8_str("donut")); |
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5079 return v8::Undefined(); | 5082 return v8::Undefined(); |
5080 } | 5083 } |
5081 | 5084 |
5082 | 5085 |
5083 THREADED_TEST(GlobalObjectTemplate) { | 5086 THREADED_TEST(GlobalObjectTemplate) { |
5084 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5087 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
5085 Local<ObjectTemplate> global_template = ObjectTemplate::New(); | 5088 Local<ObjectTemplate> global_template = ObjectTemplate::New(); |
5086 global_template->Set(v8_str("JSNI_Log"), | 5089 global_template->Set(v8_str("JSNI_Log"), |
5087 v8::FunctionTemplate::New(HandleLogDelegator)); | 5090 v8::FunctionTemplate::New(HandleLogDelegator)); |
5088 v8::Persistent<Context> context = Context::New(0, global_template); | 5091 v8::Persistent<Context> context = Context::New(0, global_template); |
5089 Context::Scope context_scope(context); | 5092 Context::Scope context_scope(v8::Isolate::GetCurrent(), context); |
5090 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run(); | 5093 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run(); |
5091 context.Dispose(context->GetIsolate()); | 5094 context.Dispose(context->GetIsolate()); |
5092 } | 5095 } |
5093 | 5096 |
5094 | 5097 |
5095 static const char* kSimpleExtensionSource = | 5098 static const char* kSimpleExtensionSource = |
5096 "function Foo() {" | 5099 "function Foo() {" |
5097 " return 4;" | 5100 " return 4;" |
5098 "}"; | 5101 "}"; |
5099 | 5102 |
5100 | 5103 |
5101 THREADED_TEST(SimpleExtensions) { | 5104 THREADED_TEST(SimpleExtensions) { |
5102 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5105 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
5103 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource)); | 5106 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource)); |
5104 const char* extension_names[] = { "simpletest" }; | 5107 const char* extension_names[] = { "simpletest" }; |
5105 v8::ExtensionConfiguration extensions(1, extension_names); | 5108 v8::ExtensionConfiguration extensions(1, extension_names); |
5106 v8::Handle<Context> context = Context::New(&extensions); | 5109 v8::Handle<Context> context = |
| 5110 Context::New(v8::Isolate::GetCurrent(), &extensions); |
5107 Context::Scope lock(context); | 5111 Context::Scope lock(context); |
5108 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); | 5112 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); |
5109 CHECK_EQ(result, v8::Integer::New(4)); | 5113 CHECK_EQ(result, v8::Integer::New(4)); |
5110 } | 5114 } |
5111 | 5115 |
5112 | 5116 |
5113 THREADED_TEST(NullExtensions) { | 5117 THREADED_TEST(NullExtensions) { |
5114 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5118 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
5115 v8::RegisterExtension(new Extension("nulltest", NULL)); | 5119 v8::RegisterExtension(new Extension("nulltest", NULL)); |
5116 const char* extension_names[] = { "nulltest" }; | 5120 const char* extension_names[] = { "nulltest" }; |
5117 v8::ExtensionConfiguration extensions(1, extension_names); | 5121 v8::ExtensionConfiguration extensions(1, extension_names); |
5118 v8::Handle<Context> context = Context::New(&extensions); | 5122 v8::Handle<Context> context = |
| 5123 Context::New(v8::Isolate::GetCurrent(), &extensions); |
5119 Context::Scope lock(context); | 5124 Context::Scope lock(context); |
5120 v8::Handle<Value> result = Script::Compile(v8_str("1+3"))->Run(); | 5125 v8::Handle<Value> result = Script::Compile(v8_str("1+3"))->Run(); |
5121 CHECK_EQ(result, v8::Integer::New(4)); | 5126 CHECK_EQ(result, v8::Integer::New(4)); |
5122 } | 5127 } |
5123 | 5128 |
5124 | 5129 |
5125 static const char* kEmbeddedExtensionSource = | 5130 static const char* kEmbeddedExtensionSource = |
5126 "function Ret54321(){return 54321;}~~@@$" | 5131 "function Ret54321(){return 54321;}~~@@$" |
5127 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS."; | 5132 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS."; |
5128 static const int kEmbeddedExtensionSourceValidLen = 34; | 5133 static const int kEmbeddedExtensionSourceValidLen = 34; |
5129 | 5134 |
5130 | 5135 |
5131 THREADED_TEST(ExtensionMissingSourceLength) { | 5136 THREADED_TEST(ExtensionMissingSourceLength) { |
5132 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5137 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
5133 v8::RegisterExtension(new Extension("srclentest_fail", | 5138 v8::RegisterExtension(new Extension("srclentest_fail", |
5134 kEmbeddedExtensionSource)); | 5139 kEmbeddedExtensionSource)); |
5135 const char* extension_names[] = { "srclentest_fail" }; | 5140 const char* extension_names[] = { "srclentest_fail" }; |
5136 v8::ExtensionConfiguration extensions(1, extension_names); | 5141 v8::ExtensionConfiguration extensions(1, extension_names); |
5137 v8::Handle<Context> context = Context::New(&extensions); | 5142 v8::Handle<Context> context = |
| 5143 Context::New(v8::Isolate::GetCurrent(), &extensions); |
5138 CHECK_EQ(0, *context); | 5144 CHECK_EQ(0, *context); |
5139 } | 5145 } |
5140 | 5146 |
5141 | 5147 |
5142 THREADED_TEST(ExtensionWithSourceLength) { | 5148 THREADED_TEST(ExtensionWithSourceLength) { |
5143 for (int source_len = kEmbeddedExtensionSourceValidLen - 1; | 5149 for (int source_len = kEmbeddedExtensionSourceValidLen - 1; |
5144 source_len <= kEmbeddedExtensionSourceValidLen + 1; ++source_len) { | 5150 source_len <= kEmbeddedExtensionSourceValidLen + 1; ++source_len) { |
5145 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5151 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
5146 i::ScopedVector<char> extension_name(32); | 5152 i::ScopedVector<char> extension_name(32); |
5147 i::OS::SNPrintF(extension_name, "ext #%d", source_len); | 5153 i::OS::SNPrintF(extension_name, "ext #%d", source_len); |
5148 v8::RegisterExtension(new Extension(extension_name.start(), | 5154 v8::RegisterExtension(new Extension(extension_name.start(), |
5149 kEmbeddedExtensionSource, 0, 0, | 5155 kEmbeddedExtensionSource, 0, 0, |
5150 source_len)); | 5156 source_len)); |
5151 const char* extension_names[1] = { extension_name.start() }; | 5157 const char* extension_names[1] = { extension_name.start() }; |
5152 v8::ExtensionConfiguration extensions(1, extension_names); | 5158 v8::ExtensionConfiguration extensions(1, extension_names); |
5153 v8::Handle<Context> context = Context::New(&extensions); | 5159 v8::Handle<Context> context = |
| 5160 Context::New(v8::Isolate::GetCurrent(), &extensions); |
5154 if (source_len == kEmbeddedExtensionSourceValidLen) { | 5161 if (source_len == kEmbeddedExtensionSourceValidLen) { |
5155 Context::Scope lock(context); | 5162 Context::Scope lock(context); |
5156 v8::Handle<Value> result = Script::Compile(v8_str("Ret54321()"))->Run(); | 5163 v8::Handle<Value> result = Script::Compile(v8_str("Ret54321()"))->Run(); |
5157 CHECK_EQ(v8::Integer::New(54321), result); | 5164 CHECK_EQ(v8::Integer::New(54321), result); |
5158 } else { | 5165 } else { |
5159 // Anything but exactly the right length should fail to compile. | 5166 // Anything but exactly the right length should fail to compile. |
5160 CHECK_EQ(0, *context); | 5167 CHECK_EQ(0, *context); |
5161 } | 5168 } |
5162 } | 5169 } |
5163 } | 5170 } |
(...skipping 15 matching lines...) Expand all Loading... |
5179 " this.UseEval2 = e;" | 5186 " this.UseEval2 = e;" |
5180 "})()"; | 5187 "})()"; |
5181 | 5188 |
5182 | 5189 |
5183 THREADED_TEST(UseEvalFromExtension) { | 5190 THREADED_TEST(UseEvalFromExtension) { |
5184 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5191 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
5185 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1)); | 5192 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1)); |
5186 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2)); | 5193 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2)); |
5187 const char* extension_names[] = { "evaltest1", "evaltest2" }; | 5194 const char* extension_names[] = { "evaltest1", "evaltest2" }; |
5188 v8::ExtensionConfiguration extensions(2, extension_names); | 5195 v8::ExtensionConfiguration extensions(2, extension_names); |
5189 v8::Handle<Context> context = Context::New(&extensions); | 5196 v8::Handle<Context> context = |
| 5197 Context::New(v8::Isolate::GetCurrent(), &extensions); |
5190 Context::Scope lock(context); | 5198 Context::Scope lock(context); |
5191 v8::Handle<Value> result = Script::Compile(v8_str("UseEval1()"))->Run(); | 5199 v8::Handle<Value> result = Script::Compile(v8_str("UseEval1()"))->Run(); |
5192 CHECK_EQ(result, v8::Integer::New(42)); | 5200 CHECK_EQ(result, v8::Integer::New(42)); |
5193 result = Script::Compile(v8_str("UseEval2()"))->Run(); | 5201 result = Script::Compile(v8_str("UseEval2()"))->Run(); |
5194 CHECK_EQ(result, v8::Integer::New(42)); | 5202 CHECK_EQ(result, v8::Integer::New(42)); |
5195 } | 5203 } |
5196 | 5204 |
5197 | 5205 |
5198 static const char* kWithExtensionSource1 = | 5206 static const char* kWithExtensionSource1 = |
5199 "function UseWith1() {" | 5207 "function UseWith1() {" |
(...skipping 12 matching lines...) Expand all Loading... |
5212 " this.UseWith2 = e;" | 5220 " this.UseWith2 = e;" |
5213 "})()"; | 5221 "})()"; |
5214 | 5222 |
5215 | 5223 |
5216 THREADED_TEST(UseWithFromExtension) { | 5224 THREADED_TEST(UseWithFromExtension) { |
5217 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5225 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
5218 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1)); | 5226 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1)); |
5219 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2)); | 5227 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2)); |
5220 const char* extension_names[] = { "withtest1", "withtest2" }; | 5228 const char* extension_names[] = { "withtest1", "withtest2" }; |
5221 v8::ExtensionConfiguration extensions(2, extension_names); | 5229 v8::ExtensionConfiguration extensions(2, extension_names); |
5222 v8::Handle<Context> context = Context::New(&extensions); | 5230 v8::Handle<Context> context = |
| 5231 Context::New(v8::Isolate::GetCurrent(), &extensions); |
5223 Context::Scope lock(context); | 5232 Context::Scope lock(context); |
5224 v8::Handle<Value> result = Script::Compile(v8_str("UseWith1()"))->Run(); | 5233 v8::Handle<Value> result = Script::Compile(v8_str("UseWith1()"))->Run(); |
5225 CHECK_EQ(result, v8::Integer::New(87)); | 5234 CHECK_EQ(result, v8::Integer::New(87)); |
5226 result = Script::Compile(v8_str("UseWith2()"))->Run(); | 5235 result = Script::Compile(v8_str("UseWith2()"))->Run(); |
5227 CHECK_EQ(result, v8::Integer::New(87)); | 5236 CHECK_EQ(result, v8::Integer::New(87)); |
5228 } | 5237 } |
5229 | 5238 |
5230 | 5239 |
5231 THREADED_TEST(AutoExtensions) { | 5240 THREADED_TEST(AutoExtensions) { |
5232 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5241 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
5233 Extension* extension = new Extension("autotest", kSimpleExtensionSource); | 5242 Extension* extension = new Extension("autotest", kSimpleExtensionSource); |
5234 extension->set_auto_enable(true); | 5243 extension->set_auto_enable(true); |
5235 v8::RegisterExtension(extension); | 5244 v8::RegisterExtension(extension); |
5236 v8::Handle<Context> context = Context::New(); | 5245 v8::Handle<Context> context = |
| 5246 Context::New(v8::Isolate::GetCurrent()); |
5237 Context::Scope lock(context); | 5247 Context::Scope lock(context); |
5238 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); | 5248 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); |
5239 CHECK_EQ(result, v8::Integer::New(4)); | 5249 CHECK_EQ(result, v8::Integer::New(4)); |
5240 } | 5250 } |
5241 | 5251 |
5242 | 5252 |
5243 static const char* kSyntaxErrorInExtensionSource = | 5253 static const char* kSyntaxErrorInExtensionSource = |
5244 "["; | 5254 "["; |
5245 | 5255 |
5246 | 5256 |
5247 // Test that a syntax error in an extension does not cause a fatal | 5257 // Test that a syntax error in an extension does not cause a fatal |
5248 // error but results in an empty context. | 5258 // error but results in an empty context. |
5249 THREADED_TEST(SyntaxErrorExtensions) { | 5259 THREADED_TEST(SyntaxErrorExtensions) { |
5250 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5260 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
5251 v8::RegisterExtension(new Extension("syntaxerror", | 5261 v8::RegisterExtension(new Extension("syntaxerror", |
5252 kSyntaxErrorInExtensionSource)); | 5262 kSyntaxErrorInExtensionSource)); |
5253 const char* extension_names[] = { "syntaxerror" }; | 5263 const char* extension_names[] = { "syntaxerror" }; |
5254 v8::ExtensionConfiguration extensions(1, extension_names); | 5264 v8::ExtensionConfiguration extensions(1, extension_names); |
5255 v8::Handle<Context> context = Context::New(&extensions); | 5265 v8::Handle<Context> context = |
| 5266 Context::New(v8::Isolate::GetCurrent(), &extensions); |
5256 CHECK(context.IsEmpty()); | 5267 CHECK(context.IsEmpty()); |
5257 } | 5268 } |
5258 | 5269 |
5259 | 5270 |
5260 static const char* kExceptionInExtensionSource = | 5271 static const char* kExceptionInExtensionSource = |
5261 "throw 42"; | 5272 "throw 42"; |
5262 | 5273 |
5263 | 5274 |
5264 // Test that an exception when installing an extension does not cause | 5275 // Test that an exception when installing an extension does not cause |
5265 // a fatal error but results in an empty context. | 5276 // a fatal error but results in an empty context. |
5266 THREADED_TEST(ExceptionExtensions) { | 5277 THREADED_TEST(ExceptionExtensions) { |
5267 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5278 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
5268 v8::RegisterExtension(new Extension("exception", | 5279 v8::RegisterExtension(new Extension("exception", |
5269 kExceptionInExtensionSource)); | 5280 kExceptionInExtensionSource)); |
5270 const char* extension_names[] = { "exception" }; | 5281 const char* extension_names[] = { "exception" }; |
5271 v8::ExtensionConfiguration extensions(1, extension_names); | 5282 v8::ExtensionConfiguration extensions(1, extension_names); |
5272 v8::Handle<Context> context = Context::New(&extensions); | 5283 v8::Handle<Context> context = |
| 5284 Context::New(v8::Isolate::GetCurrent(), &extensions); |
5273 CHECK(context.IsEmpty()); | 5285 CHECK(context.IsEmpty()); |
5274 } | 5286 } |
5275 | 5287 |
5276 | 5288 |
5277 static const char* kNativeCallInExtensionSource = | 5289 static const char* kNativeCallInExtensionSource = |
5278 "function call_runtime_last_index_of(x) {" | 5290 "function call_runtime_last_index_of(x) {" |
5279 " return %StringLastIndexOf(x, 'bob', 10);" | 5291 " return %StringLastIndexOf(x, 'bob', 10);" |
5280 "}"; | 5292 "}"; |
5281 | 5293 |
5282 | 5294 |
5283 static const char* kNativeCallTest = | 5295 static const char* kNativeCallTest = |
5284 "call_runtime_last_index_of('bobbobboellebobboellebobbob');"; | 5296 "call_runtime_last_index_of('bobbobboellebobboellebobbob');"; |
5285 | 5297 |
5286 // Test that a native runtime calls are supported in extensions. | 5298 // Test that a native runtime calls are supported in extensions. |
5287 THREADED_TEST(NativeCallInExtensions) { | 5299 THREADED_TEST(NativeCallInExtensions) { |
5288 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5300 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
5289 v8::RegisterExtension(new Extension("nativecall", | 5301 v8::RegisterExtension(new Extension("nativecall", |
5290 kNativeCallInExtensionSource)); | 5302 kNativeCallInExtensionSource)); |
5291 const char* extension_names[] = { "nativecall" }; | 5303 const char* extension_names[] = { "nativecall" }; |
5292 v8::ExtensionConfiguration extensions(1, extension_names); | 5304 v8::ExtensionConfiguration extensions(1, extension_names); |
5293 v8::Handle<Context> context = Context::New(&extensions); | 5305 v8::Handle<Context> context = |
| 5306 Context::New(v8::Isolate::GetCurrent(), &extensions); |
5294 Context::Scope lock(context); | 5307 Context::Scope lock(context); |
5295 v8::Handle<Value> result = Script::Compile(v8_str(kNativeCallTest))->Run(); | 5308 v8::Handle<Value> result = Script::Compile(v8_str(kNativeCallTest))->Run(); |
5296 CHECK_EQ(result, v8::Integer::New(3)); | 5309 CHECK_EQ(result, v8::Integer::New(3)); |
5297 } | 5310 } |
5298 | 5311 |
5299 | 5312 |
5300 class NativeFunctionExtension : public Extension { | 5313 class NativeFunctionExtension : public Extension { |
5301 public: | 5314 public: |
5302 NativeFunctionExtension(const char* name, | 5315 NativeFunctionExtension(const char* name, |
5303 const char* source, | 5316 const char* source, |
(...skipping 15 matching lines...) Expand all Loading... |
5319 }; | 5332 }; |
5320 | 5333 |
5321 | 5334 |
5322 THREADED_TEST(NativeFunctionDeclaration) { | 5335 THREADED_TEST(NativeFunctionDeclaration) { |
5323 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5336 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
5324 const char* name = "nativedecl"; | 5337 const char* name = "nativedecl"; |
5325 v8::RegisterExtension(new NativeFunctionExtension(name, | 5338 v8::RegisterExtension(new NativeFunctionExtension(name, |
5326 "native function foo();")); | 5339 "native function foo();")); |
5327 const char* extension_names[] = { name }; | 5340 const char* extension_names[] = { name }; |
5328 v8::ExtensionConfiguration extensions(1, extension_names); | 5341 v8::ExtensionConfiguration extensions(1, extension_names); |
5329 v8::Handle<Context> context = Context::New(&extensions); | 5342 v8::Handle<Context> context = |
| 5343 Context::New(v8::Isolate::GetCurrent(), &extensions); |
5330 Context::Scope lock(context); | 5344 Context::Scope lock(context); |
5331 v8::Handle<Value> result = Script::Compile(v8_str("foo(42);"))->Run(); | 5345 v8::Handle<Value> result = Script::Compile(v8_str("foo(42);"))->Run(); |
5332 CHECK_EQ(result, v8::Integer::New(42)); | 5346 CHECK_EQ(result, v8::Integer::New(42)); |
5333 } | 5347 } |
5334 | 5348 |
5335 | 5349 |
5336 THREADED_TEST(NativeFunctionDeclarationError) { | 5350 THREADED_TEST(NativeFunctionDeclarationError) { |
5337 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5351 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
5338 const char* name = "nativedeclerr"; | 5352 const char* name = "nativedeclerr"; |
5339 // Syntax error in extension code. | 5353 // Syntax error in extension code. |
5340 v8::RegisterExtension(new NativeFunctionExtension(name, | 5354 v8::RegisterExtension(new NativeFunctionExtension(name, |
5341 "native\nfunction foo();")); | 5355 "native\nfunction foo();")); |
5342 const char* extension_names[] = { name }; | 5356 const char* extension_names[] = { name }; |
5343 v8::ExtensionConfiguration extensions(1, extension_names); | 5357 v8::ExtensionConfiguration extensions(1, extension_names); |
5344 v8::Handle<Context> context(Context::New(&extensions)); | 5358 v8::Handle<Context> context = |
| 5359 Context::New(v8::Isolate::GetCurrent(), &extensions); |
5345 CHECK(context.IsEmpty()); | 5360 CHECK(context.IsEmpty()); |
5346 } | 5361 } |
5347 | 5362 |
5348 | 5363 |
5349 THREADED_TEST(NativeFunctionDeclarationErrorEscape) { | 5364 THREADED_TEST(NativeFunctionDeclarationErrorEscape) { |
5350 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5365 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
5351 const char* name = "nativedeclerresc"; | 5366 const char* name = "nativedeclerresc"; |
5352 // Syntax error in extension code - escape code in "native" means that | 5367 // Syntax error in extension code - escape code in "native" means that |
5353 // it's not treated as a keyword. | 5368 // it's not treated as a keyword. |
5354 v8::RegisterExtension(new NativeFunctionExtension( | 5369 v8::RegisterExtension(new NativeFunctionExtension( |
5355 name, | 5370 name, |
5356 "nativ\\u0065 function foo();")); | 5371 "nativ\\u0065 function foo();")); |
5357 const char* extension_names[] = { name }; | 5372 const char* extension_names[] = { name }; |
5358 v8::ExtensionConfiguration extensions(1, extension_names); | 5373 v8::ExtensionConfiguration extensions(1, extension_names); |
5359 v8::Handle<Context> context(Context::New(&extensions)); | 5374 v8::Handle<Context> context = |
| 5375 Context::New(v8::Isolate::GetCurrent(), &extensions); |
5360 CHECK(context.IsEmpty()); | 5376 CHECK(context.IsEmpty()); |
5361 } | 5377 } |
5362 | 5378 |
5363 | 5379 |
5364 static void CheckDependencies(const char* name, const char* expected) { | 5380 static void CheckDependencies(const char* name, const char* expected) { |
5365 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5381 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
5366 v8::ExtensionConfiguration config(1, &name); | 5382 v8::ExtensionConfiguration config(1, &name); |
5367 LocalContext context(&config); | 5383 LocalContext context(&config); |
5368 CHECK_EQ(String::New(expected), context->Global()->Get(v8_str("loaded"))); | 5384 CHECK_EQ(String::New(expected), context->Global()->Get(v8_str("loaded"))); |
5369 } | 5385 } |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5489 // tests that the fatal error handler gets called. This renders V8 | 5505 // tests that the fatal error handler gets called. This renders V8 |
5490 // unusable and therefore this test cannot be run in parallel. | 5506 // unusable and therefore this test cannot be run in parallel. |
5491 TEST(ErrorReporting) { | 5507 TEST(ErrorReporting) { |
5492 v8::V8::SetFatalErrorHandler(StoringErrorCallback); | 5508 v8::V8::SetFatalErrorHandler(StoringErrorCallback); |
5493 static const char* aDeps[] = { "B" }; | 5509 static const char* aDeps[] = { "B" }; |
5494 v8::RegisterExtension(new Extension("A", "", 1, aDeps)); | 5510 v8::RegisterExtension(new Extension("A", "", 1, aDeps)); |
5495 static const char* bDeps[] = { "A" }; | 5511 static const char* bDeps[] = { "A" }; |
5496 v8::RegisterExtension(new Extension("B", "", 1, bDeps)); | 5512 v8::RegisterExtension(new Extension("B", "", 1, bDeps)); |
5497 last_location = NULL; | 5513 last_location = NULL; |
5498 v8::ExtensionConfiguration config(1, bDeps); | 5514 v8::ExtensionConfiguration config(1, bDeps); |
5499 v8::Handle<Context> context = Context::New(&config); | 5515 v8::Handle<Context> context = |
| 5516 Context::New(v8::Isolate::GetCurrent(), &config); |
5500 CHECK(context.IsEmpty()); | 5517 CHECK(context.IsEmpty()); |
5501 CHECK_NE(last_location, NULL); | 5518 CHECK_NE(last_location, NULL); |
5502 } | 5519 } |
5503 | 5520 |
5504 | 5521 |
5505 static const char* js_code_causing_huge_string_flattening = | 5522 static const char* js_code_causing_huge_string_flattening = |
5506 "var str = 'X';" | 5523 "var str = 'X';" |
5507 "for (var i = 0; i < 30; i++) {" | 5524 "for (var i = 0; i < 30; i++) {" |
5508 " str = str + str;" | 5525 " str = str + str;" |
5509 "}" | 5526 "}" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5605 | 5622 |
5606 THREADED_TEST(WeakReference) { | 5623 THREADED_TEST(WeakReference) { |
5607 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5624 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
5608 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New(); | 5625 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New(); |
5609 Whammy* whammy = new Whammy(v8::Isolate::GetCurrent()); | 5626 Whammy* whammy = new Whammy(v8::Isolate::GetCurrent()); |
5610 templ->SetNamedPropertyHandler(WhammyPropertyGetter, | 5627 templ->SetNamedPropertyHandler(WhammyPropertyGetter, |
5611 0, 0, 0, 0, | 5628 0, 0, 0, 0, |
5612 v8::External::New(whammy)); | 5629 v8::External::New(whammy)); |
5613 const char* extension_list[] = { "v8/gc" }; | 5630 const char* extension_list[] = { "v8/gc" }; |
5614 v8::ExtensionConfiguration extensions(1, extension_list); | 5631 v8::ExtensionConfiguration extensions(1, extension_list); |
5615 v8::Persistent<Context> context = Context::New(&extensions); | 5632 v8::Handle<Context> context = |
| 5633 Context::New(v8::Isolate::GetCurrent(), &extensions); |
5616 Context::Scope context_scope(context); | 5634 Context::Scope context_scope(context); |
5617 | 5635 |
5618 v8::Handle<v8::Object> interceptor = templ->NewInstance(); | 5636 v8::Handle<v8::Object> interceptor = templ->NewInstance(); |
5619 context->Global()->Set(v8_str("whammy"), interceptor); | 5637 context->Global()->Set(v8_str("whammy"), interceptor); |
5620 const char* code = | 5638 const char* code = |
5621 "var last;" | 5639 "var last;" |
5622 "for (var i = 0; i < 10000; i++) {" | 5640 "for (var i = 0; i < 10000; i++) {" |
5623 " var obj = whammy.length;" | 5641 " var obj = whammy.length;" |
5624 " if (last) last.next = obj;" | 5642 " if (last) last.next = obj;" |
5625 " last = obj;" | 5643 " last = obj;" |
5626 "}" | 5644 "}" |
5627 "gc();" | 5645 "gc();" |
5628 "4"; | 5646 "4"; |
5629 v8::Handle<Value> result = CompileRun(code); | 5647 v8::Handle<Value> result = CompileRun(code); |
5630 CHECK_EQ(4.0, result->NumberValue()); | 5648 CHECK_EQ(4.0, result->NumberValue()); |
5631 delete whammy; | 5649 delete whammy; |
5632 context.Dispose(context->GetIsolate()); | |
5633 } | 5650 } |
5634 | 5651 |
5635 | 5652 |
5636 static void DisposeAndSetFlag(v8::Isolate* isolate, | 5653 static void DisposeAndSetFlag(v8::Isolate* isolate, |
5637 v8::Persistent<v8::Value> obj, | 5654 v8::Persistent<v8::Value> obj, |
5638 void* data) { | 5655 void* data) { |
5639 obj.Dispose(isolate); | 5656 obj.Dispose(isolate); |
5640 obj.Clear(); | 5657 obj.Clear(); |
5641 *(reinterpret_cast<bool*>(data)) = true; | 5658 *(reinterpret_cast<bool*>(data)) = true; |
5642 } | 5659 } |
5643 | 5660 |
5644 | 5661 |
5645 THREADED_TEST(IndependentWeakHandle) { | 5662 THREADED_TEST(IndependentWeakHandle) { |
5646 v8::Persistent<Context> context = Context::New(); | 5663 v8::Isolate* iso = v8::Isolate::GetCurrent(); |
5647 v8::Isolate* iso = context->GetIsolate(); | 5664 v8::HandleScope scope(iso); |
| 5665 v8::Handle<Context> context = Context::New(iso); |
5648 Context::Scope context_scope(context); | 5666 Context::Scope context_scope(context); |
5649 | 5667 |
5650 v8::Persistent<v8::Object> object_a, object_b; | 5668 v8::Persistent<v8::Object> object_a, object_b; |
5651 | 5669 |
5652 { | 5670 { |
5653 v8::HandleScope handle_scope(iso); | 5671 v8::HandleScope handle_scope(iso); |
5654 object_a = v8::Persistent<v8::Object>::New(iso, v8::Object::New()); | 5672 object_a = v8::Persistent<v8::Object>::New(iso, v8::Object::New()); |
5655 object_b = v8::Persistent<v8::Object>::New(iso, v8::Object::New()); | 5673 object_b = v8::Persistent<v8::Object>::New(iso, v8::Object::New()); |
5656 } | 5674 } |
5657 | 5675 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5693 v8::Persistent<v8::Value> obj, | 5711 v8::Persistent<v8::Value> obj, |
5694 void* data) { | 5712 void* data) { |
5695 obj.Dispose(isolate); | 5713 obj.Dispose(isolate); |
5696 obj.Clear(); | 5714 obj.Clear(); |
5697 *(reinterpret_cast<bool*>(data)) = true; | 5715 *(reinterpret_cast<bool*>(data)) = true; |
5698 InvokeMarkSweep(); | 5716 InvokeMarkSweep(); |
5699 } | 5717 } |
5700 | 5718 |
5701 | 5719 |
5702 THREADED_TEST(GCFromWeakCallbacks) { | 5720 THREADED_TEST(GCFromWeakCallbacks) { |
5703 v8::Persistent<Context> context = Context::New(); | 5721 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
5704 v8::Isolate* isolate = context->GetIsolate(); | 5722 v8::HandleScope scope(isolate); |
| 5723 v8::Handle<Context> context = Context::New(isolate); |
5705 Context::Scope context_scope(context); | 5724 Context::Scope context_scope(context); |
5706 | 5725 |
5707 static const int kNumberOfGCTypes = 2; | 5726 static const int kNumberOfGCTypes = 2; |
5708 v8::NearDeathCallback gc_forcing_callback[kNumberOfGCTypes] = | 5727 v8::NearDeathCallback gc_forcing_callback[kNumberOfGCTypes] = |
5709 {&ForceScavenge, &ForceMarkSweep}; | 5728 {&ForceScavenge, &ForceMarkSweep}; |
5710 | 5729 |
5711 typedef void (*GCInvoker)(); | 5730 typedef void (*GCInvoker)(); |
5712 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep}; | 5731 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep}; |
5713 | 5732 |
5714 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) { | 5733 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) { |
(...skipping 15 matching lines...) Expand all Loading... |
5730 | 5749 |
5731 static void RevivingCallback(v8::Isolate* isolate, | 5750 static void RevivingCallback(v8::Isolate* isolate, |
5732 v8::Persistent<v8::Value> obj, | 5751 v8::Persistent<v8::Value> obj, |
5733 void* data) { | 5752 void* data) { |
5734 obj.ClearWeak(isolate); | 5753 obj.ClearWeak(isolate); |
5735 *(reinterpret_cast<bool*>(data)) = true; | 5754 *(reinterpret_cast<bool*>(data)) = true; |
5736 } | 5755 } |
5737 | 5756 |
5738 | 5757 |
5739 THREADED_TEST(IndependentHandleRevival) { | 5758 THREADED_TEST(IndependentHandleRevival) { |
5740 v8::Persistent<Context> context = Context::New(); | 5759 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 5760 v8::HandleScope scope(isolate); |
| 5761 v8::Handle<Context> context = Context::New(isolate); |
5741 Context::Scope context_scope(context); | 5762 Context::Scope context_scope(context); |
5742 v8::Isolate* isolate = context->GetIsolate(); | |
5743 | 5763 |
5744 v8::Persistent<v8::Object> object; | 5764 v8::Persistent<v8::Object> object; |
5745 { | 5765 { |
5746 v8::HandleScope handle_scope(isolate); | 5766 v8::HandleScope handle_scope(isolate); |
5747 object = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); | 5767 object = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); |
5748 object->Set(v8_str("x"), v8::Integer::New(1)); | 5768 object->Set(v8_str("x"), v8::Integer::New(1)); |
5749 v8::Local<String> y_str = v8_str("y"); | 5769 v8::Local<String> y_str = v8_str("y"); |
5750 object->Set(y_str, y_str); | 5770 object->Set(y_str, y_str); |
5751 } | 5771 } |
5752 bool revived = false; | 5772 bool revived = false; |
(...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6787 } | 6807 } |
6788 | 6808 |
6789 | 6809 |
6790 // SecurityHandler can't be run twice | 6810 // SecurityHandler can't be run twice |
6791 TEST(SecurityHandler) { | 6811 TEST(SecurityHandler) { |
6792 v8::HandleScope scope0(v8::Isolate::GetCurrent()); | 6812 v8::HandleScope scope0(v8::Isolate::GetCurrent()); |
6793 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 6813 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
6794 global_template->SetAccessCheckCallbacks(NamedSecurityTestCallback, | 6814 global_template->SetAccessCheckCallbacks(NamedSecurityTestCallback, |
6795 IndexedSecurityTestCallback); | 6815 IndexedSecurityTestCallback); |
6796 // Create an environment | 6816 // Create an environment |
6797 v8::Persistent<Context> context0 = | 6817 v8::Handle<Context> context0 = |
6798 Context::New(NULL, global_template); | 6818 Context::New(v8::Isolate::GetCurrent(), NULL, global_template); |
6799 context0->Enter(); | 6819 context0->Enter(); |
6800 | 6820 |
6801 v8::Handle<v8::Object> global0 = context0->Global(); | 6821 v8::Handle<v8::Object> global0 = context0->Global(); |
6802 v8::Handle<Script> script0 = v8_compile("foo = 111"); | 6822 v8::Handle<Script> script0 = v8_compile("foo = 111"); |
6803 script0->Run(); | 6823 script0->Run(); |
6804 global0->Set(v8_str("0"), v8_num(999)); | 6824 global0->Set(v8_str("0"), v8_num(999)); |
6805 v8::Handle<Value> foo0 = global0->Get(v8_str("foo")); | 6825 v8::Handle<Value> foo0 = global0->Get(v8_str("foo")); |
6806 CHECK_EQ(111, foo0->Int32Value()); | 6826 CHECK_EQ(111, foo0->Int32Value()); |
6807 v8::Handle<Value> z0 = global0->Get(v8_str("0")); | 6827 v8::Handle<Value> z0 = global0->Get(v8_str("0")); |
6808 CHECK_EQ(999, z0->Int32Value()); | 6828 CHECK_EQ(999, z0->Int32Value()); |
6809 | 6829 |
6810 // Create another environment, should fail security checks. | 6830 // Create another environment, should fail security checks. |
6811 v8::HandleScope scope1(v8::Isolate::GetCurrent()); | 6831 v8::HandleScope scope1(v8::Isolate::GetCurrent()); |
6812 | 6832 |
6813 v8::Persistent<Context> context1 = | 6833 v8::Handle<Context> context1 = |
6814 Context::New(NULL, global_template); | 6834 Context::New(v8::Isolate::GetCurrent(), NULL, global_template); |
6815 context1->Enter(); | 6835 context1->Enter(); |
6816 | 6836 |
6817 v8::Handle<v8::Object> global1 = context1->Global(); | 6837 v8::Handle<v8::Object> global1 = context1->Global(); |
6818 global1->Set(v8_str("othercontext"), global0); | 6838 global1->Set(v8_str("othercontext"), global0); |
6819 // This set will fail the security check. | 6839 // This set will fail the security check. |
6820 v8::Handle<Script> script1 = | 6840 v8::Handle<Script> script1 = |
6821 v8_compile("othercontext.foo = 222; othercontext[0] = 888;"); | 6841 v8_compile("othercontext.foo = 222; othercontext[0] = 888;"); |
6822 script1->Run(); | 6842 script1->Run(); |
6823 // This read will pass the security check. | 6843 // This read will pass the security check. |
6824 v8::Handle<Value> foo1 = global0->Get(v8_str("foo")); | 6844 v8::Handle<Value> foo1 = global0->Get(v8_str("foo")); |
(...skipping 11 matching lines...) Expand all Loading... |
6836 v8::Handle<Script> script2 = | 6856 v8::Handle<Script> script2 = |
6837 v8_compile("othercontext.foo = 333; othercontext[0] = 888;"); | 6857 v8_compile("othercontext.foo = 333; othercontext[0] = 888;"); |
6838 script2->Run(); | 6858 script2->Run(); |
6839 v8::Handle<Value> foo2 = global0->Get(v8_str("foo")); | 6859 v8::Handle<Value> foo2 = global0->Get(v8_str("foo")); |
6840 CHECK_EQ(333, foo2->Int32Value()); | 6860 CHECK_EQ(333, foo2->Int32Value()); |
6841 v8::Handle<Value> z2 = global0->Get(v8_str("0")); | 6861 v8::Handle<Value> z2 = global0->Get(v8_str("0")); |
6842 CHECK_EQ(888, z2->Int32Value()); | 6862 CHECK_EQ(888, z2->Int32Value()); |
6843 } | 6863 } |
6844 | 6864 |
6845 context1->Exit(); | 6865 context1->Exit(); |
6846 context1.Dispose(context1->GetIsolate()); | |
6847 | |
6848 context0->Exit(); | 6866 context0->Exit(); |
6849 context0.Dispose(context0->GetIsolate()); | |
6850 } | 6867 } |
6851 | 6868 |
6852 | 6869 |
6853 THREADED_TEST(SecurityChecks) { | 6870 THREADED_TEST(SecurityChecks) { |
6854 LocalContext env1; | 6871 LocalContext env1; |
6855 v8::HandleScope handle_scope(env1->GetIsolate()); | 6872 v8::HandleScope handle_scope(env1->GetIsolate()); |
6856 v8::Persistent<Context> env2 = Context::New(); | 6873 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); |
6857 | 6874 |
6858 Local<Value> foo = v8_str("foo"); | 6875 Local<Value> foo = v8_str("foo"); |
6859 Local<Value> bar = v8_str("bar"); | 6876 Local<Value> bar = v8_str("bar"); |
6860 | 6877 |
6861 // Set to the same domain. | 6878 // Set to the same domain. |
6862 env1->SetSecurityToken(foo); | 6879 env1->SetSecurityToken(foo); |
6863 | 6880 |
6864 // Create a function in env1. | 6881 // Create a function in env1. |
6865 Script::Compile(v8_str("spy=function(){return spy;}"))->Run(); | 6882 Script::Compile(v8_str("spy=function(){return spy;}"))->Run(); |
6866 Local<Value> spy = env1->Global()->Get(v8_str("spy")); | 6883 Local<Value> spy = env1->Global()->Get(v8_str("spy")); |
(...skipping 15 matching lines...) Expand all Loading... |
6882 | 6899 |
6883 { | 6900 { |
6884 env2->SetSecurityToken(bar); | 6901 env2->SetSecurityToken(bar); |
6885 Context::Scope scope_env2(env2); | 6902 Context::Scope scope_env2(env2); |
6886 | 6903 |
6887 // Call cross_domain_call, it should throw an exception | 6904 // Call cross_domain_call, it should throw an exception |
6888 v8::TryCatch try_catch; | 6905 v8::TryCatch try_catch; |
6889 Function::Cast(*spy2)->Call(env2->Global(), 0, NULL); | 6906 Function::Cast(*spy2)->Call(env2->Global(), 0, NULL); |
6890 CHECK(try_catch.HasCaught()); | 6907 CHECK(try_catch.HasCaught()); |
6891 } | 6908 } |
6892 | |
6893 env2.Dispose(env2->GetIsolate()); | |
6894 } | 6909 } |
6895 | 6910 |
6896 | 6911 |
6897 // Regression test case for issue 1183439. | 6912 // Regression test case for issue 1183439. |
6898 THREADED_TEST(SecurityChecksForPrototypeChain) { | 6913 THREADED_TEST(SecurityChecksForPrototypeChain) { |
6899 LocalContext current; | 6914 LocalContext current; |
6900 v8::HandleScope scope(current->GetIsolate()); | 6915 v8::HandleScope scope(current->GetIsolate()); |
6901 v8::Persistent<Context> other = Context::New(); | 6916 v8::Handle<Context> other = Context::New(current->GetIsolate()); |
6902 | 6917 |
6903 // Change context to be able to get to the Object function in the | 6918 // Change context to be able to get to the Object function in the |
6904 // other context without hitting the security checks. | 6919 // other context without hitting the security checks. |
6905 v8::Local<Value> other_object; | 6920 v8::Local<Value> other_object; |
6906 { Context::Scope scope(other); | 6921 { Context::Scope scope(other); |
6907 other_object = other->Global()->Get(v8_str("Object")); | 6922 other_object = other->Global()->Get(v8_str("Object")); |
6908 other->Global()->Set(v8_num(42), v8_num(87)); | 6923 other->Global()->Set(v8_num(42), v8_num(87)); |
6909 } | 6924 } |
6910 | 6925 |
6911 current->Global()->Set(v8_str("other"), other->Global()); | 6926 current->Global()->Set(v8_str("other"), other->Global()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6952 // Try to read the properties from f and make sure that the access | 6967 // Try to read the properties from f and make sure that the access |
6953 // gets stopped by the security checks on the other global object. | 6968 // gets stopped by the security checks on the other global object. |
6954 Local<Script> access_f2 = v8_compile("f.foo"); | 6969 Local<Script> access_f2 = v8_compile("f.foo"); |
6955 Local<Script> access_f3 = v8_compile("f[99]"); | 6970 Local<Script> access_f3 = v8_compile("f[99]"); |
6956 for (int k = 0; k < 5; k++) { | 6971 for (int k = 0; k < 5; k++) { |
6957 CHECK(!access_f2->Run()->Equals(v8_num(100))); | 6972 CHECK(!access_f2->Run()->Equals(v8_num(100))); |
6958 CHECK(access_f2->Run()->IsUndefined()); | 6973 CHECK(access_f2->Run()->IsUndefined()); |
6959 CHECK(!access_f3->Run()->Equals(v8_num(101))); | 6974 CHECK(!access_f3->Run()->Equals(v8_num(101))); |
6960 CHECK(access_f3->Run()->IsUndefined()); | 6975 CHECK(access_f3->Run()->IsUndefined()); |
6961 } | 6976 } |
6962 other.Dispose(other->GetIsolate()); | |
6963 } | 6977 } |
6964 | 6978 |
6965 | 6979 |
6966 THREADED_TEST(CrossDomainDelete) { | 6980 THREADED_TEST(CrossDomainDelete) { |
6967 LocalContext env1; | 6981 LocalContext env1; |
6968 v8::HandleScope handle_scope(env1->GetIsolate()); | 6982 v8::HandleScope handle_scope(env1->GetIsolate()); |
6969 v8::Persistent<Context> env2 = Context::New(); | 6983 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); |
6970 | 6984 |
6971 Local<Value> foo = v8_str("foo"); | 6985 Local<Value> foo = v8_str("foo"); |
6972 Local<Value> bar = v8_str("bar"); | 6986 Local<Value> bar = v8_str("bar"); |
6973 | 6987 |
6974 // Set to the same domain. | 6988 // Set to the same domain. |
6975 env1->SetSecurityToken(foo); | 6989 env1->SetSecurityToken(foo); |
6976 env2->SetSecurityToken(foo); | 6990 env2->SetSecurityToken(foo); |
6977 | 6991 |
6978 env1->Global()->Set(v8_str("prop"), v8_num(3)); | 6992 env1->Global()->Set(v8_str("prop"), v8_num(3)); |
6979 env2->Global()->Set(v8_str("env1"), env1->Global()); | 6993 env2->Global()->Set(v8_str("env1"), env1->Global()); |
6980 | 6994 |
6981 // Change env2 to a different domain and delete env1.prop. | 6995 // Change env2 to a different domain and delete env1.prop. |
6982 env2->SetSecurityToken(bar); | 6996 env2->SetSecurityToken(bar); |
6983 { | 6997 { |
6984 Context::Scope scope_env2(env2); | 6998 Context::Scope scope_env2(env2); |
6985 Local<Value> result = | 6999 Local<Value> result = |
6986 Script::Compile(v8_str("delete env1.prop"))->Run(); | 7000 Script::Compile(v8_str("delete env1.prop"))->Run(); |
6987 CHECK(result->IsFalse()); | 7001 CHECK(result->IsFalse()); |
6988 } | 7002 } |
6989 | 7003 |
6990 // Check that env1.prop still exists. | 7004 // Check that env1.prop still exists. |
6991 Local<Value> v = env1->Global()->Get(v8_str("prop")); | 7005 Local<Value> v = env1->Global()->Get(v8_str("prop")); |
6992 CHECK(v->IsNumber()); | 7006 CHECK(v->IsNumber()); |
6993 CHECK_EQ(3, v->Int32Value()); | 7007 CHECK_EQ(3, v->Int32Value()); |
6994 | |
6995 env2.Dispose(env2->GetIsolate()); | |
6996 } | 7008 } |
6997 | 7009 |
6998 | 7010 |
6999 THREADED_TEST(CrossDomainIsPropertyEnumerable) { | 7011 THREADED_TEST(CrossDomainIsPropertyEnumerable) { |
7000 LocalContext env1; | 7012 LocalContext env1; |
7001 v8::HandleScope handle_scope(env1->GetIsolate()); | 7013 v8::HandleScope handle_scope(env1->GetIsolate()); |
7002 v8::Persistent<Context> env2 = Context::New(); | 7014 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); |
7003 | 7015 |
7004 Local<Value> foo = v8_str("foo"); | 7016 Local<Value> foo = v8_str("foo"); |
7005 Local<Value> bar = v8_str("bar"); | 7017 Local<Value> bar = v8_str("bar"); |
7006 | 7018 |
7007 // Set to the same domain. | 7019 // Set to the same domain. |
7008 env1->SetSecurityToken(foo); | 7020 env1->SetSecurityToken(foo); |
7009 env2->SetSecurityToken(foo); | 7021 env2->SetSecurityToken(foo); |
7010 | 7022 |
7011 env1->Global()->Set(v8_str("prop"), v8_num(3)); | 7023 env1->Global()->Set(v8_str("prop"), v8_num(3)); |
7012 env2->Global()->Set(v8_str("env1"), env1->Global()); | 7024 env2->Global()->Set(v8_str("env1"), env1->Global()); |
7013 | 7025 |
7014 // env1.prop is enumerable in env2. | 7026 // env1.prop is enumerable in env2. |
7015 Local<String> test = v8_str("propertyIsEnumerable.call(env1, 'prop')"); | 7027 Local<String> test = v8_str("propertyIsEnumerable.call(env1, 'prop')"); |
7016 { | 7028 { |
7017 Context::Scope scope_env2(env2); | 7029 Context::Scope scope_env2(env2); |
7018 Local<Value> result = Script::Compile(test)->Run(); | 7030 Local<Value> result = Script::Compile(test)->Run(); |
7019 CHECK(result->IsTrue()); | 7031 CHECK(result->IsTrue()); |
7020 } | 7032 } |
7021 | 7033 |
7022 // Change env2 to a different domain and test again. | 7034 // Change env2 to a different domain and test again. |
7023 env2->SetSecurityToken(bar); | 7035 env2->SetSecurityToken(bar); |
7024 { | 7036 { |
7025 Context::Scope scope_env2(env2); | 7037 Context::Scope scope_env2(env2); |
7026 Local<Value> result = Script::Compile(test)->Run(); | 7038 Local<Value> result = Script::Compile(test)->Run(); |
7027 CHECK(result->IsFalse()); | 7039 CHECK(result->IsFalse()); |
7028 } | 7040 } |
7029 | |
7030 env2.Dispose(env2->GetIsolate()); | |
7031 } | 7041 } |
7032 | 7042 |
7033 | 7043 |
7034 THREADED_TEST(CrossDomainForIn) { | 7044 THREADED_TEST(CrossDomainForIn) { |
7035 LocalContext env1; | 7045 LocalContext env1; |
7036 v8::HandleScope handle_scope(env1->GetIsolate()); | 7046 v8::HandleScope handle_scope(env1->GetIsolate()); |
7037 v8::Persistent<Context> env2 = Context::New(); | 7047 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); |
7038 | 7048 |
7039 Local<Value> foo = v8_str("foo"); | 7049 Local<Value> foo = v8_str("foo"); |
7040 Local<Value> bar = v8_str("bar"); | 7050 Local<Value> bar = v8_str("bar"); |
7041 | 7051 |
7042 // Set to the same domain. | 7052 // Set to the same domain. |
7043 env1->SetSecurityToken(foo); | 7053 env1->SetSecurityToken(foo); |
7044 env2->SetSecurityToken(foo); | 7054 env2->SetSecurityToken(foo); |
7045 | 7055 |
7046 env1->Global()->Set(v8_str("prop"), v8_num(3)); | 7056 env1->Global()->Set(v8_str("prop"), v8_num(3)); |
7047 env2->Global()->Set(v8_str("env1"), env1->Global()); | 7057 env2->Global()->Set(v8_str("env1"), env1->Global()); |
7048 | 7058 |
7049 // Change env2 to a different domain and set env1's global object | 7059 // Change env2 to a different domain and set env1's global object |
7050 // as the __proto__ of an object in env2 and enumerate properties | 7060 // as the __proto__ of an object in env2 and enumerate properties |
7051 // in for-in. It shouldn't enumerate properties on env1's global | 7061 // in for-in. It shouldn't enumerate properties on env1's global |
7052 // object. | 7062 // object. |
7053 env2->SetSecurityToken(bar); | 7063 env2->SetSecurityToken(bar); |
7054 { | 7064 { |
7055 Context::Scope scope_env2(env2); | 7065 Context::Scope scope_env2(env2); |
7056 Local<Value> result = | 7066 Local<Value> result = |
7057 CompileRun("(function(){var obj = {'__proto__':env1};" | 7067 CompileRun("(function(){var obj = {'__proto__':env1};" |
7058 "for (var p in obj)" | 7068 "for (var p in obj)" |
7059 " if (p == 'prop') return false;" | 7069 " if (p == 'prop') return false;" |
7060 "return true;})()"); | 7070 "return true;})()"); |
7061 CHECK(result->IsTrue()); | 7071 CHECK(result->IsTrue()); |
7062 } | 7072 } |
7063 env2.Dispose(env2->GetIsolate()); | |
7064 } | 7073 } |
7065 | 7074 |
7066 | 7075 |
7067 TEST(ContextDetachGlobal) { | 7076 TEST(ContextDetachGlobal) { |
7068 LocalContext env1; | 7077 LocalContext env1; |
7069 v8::HandleScope handle_scope(env1->GetIsolate()); | 7078 v8::HandleScope handle_scope(env1->GetIsolate()); |
7070 v8::Persistent<Context> env2 = Context::New(); | 7079 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); |
7071 | 7080 |
7072 Local<v8::Object> global1 = env1->Global(); | 7081 Local<v8::Object> global1 = env1->Global(); |
7073 | 7082 |
7074 Local<Value> foo = v8_str("foo"); | 7083 Local<Value> foo = v8_str("foo"); |
7075 | 7084 |
7076 // Set to the same domain. | 7085 // Set to the same domain. |
7077 env1->SetSecurityToken(foo); | 7086 env1->SetSecurityToken(foo); |
7078 env2->SetSecurityToken(foo); | 7087 env2->SetSecurityToken(foo); |
7079 | 7088 |
7080 // Enter env2 | 7089 // Enter env2 |
7081 env2->Enter(); | 7090 env2->Enter(); |
7082 | 7091 |
7083 // Create a function in env2 and add a reference to it in env1. | 7092 // Create a function in env2 and add a reference to it in env1. |
7084 Local<v8::Object> global2 = env2->Global(); | 7093 Local<v8::Object> global2 = env2->Global(); |
7085 global2->Set(v8_str("prop"), v8::Integer::New(1)); | 7094 global2->Set(v8_str("prop"), v8::Integer::New(1)); |
7086 CompileRun("function getProp() {return prop;}"); | 7095 CompileRun("function getProp() {return prop;}"); |
7087 | 7096 |
7088 env1->Global()->Set(v8_str("getProp"), | 7097 env1->Global()->Set(v8_str("getProp"), |
7089 global2->Get(v8_str("getProp"))); | 7098 global2->Get(v8_str("getProp"))); |
7090 | 7099 |
7091 // Detach env2's global, and reuse the global object of env2 | 7100 // Detach env2's global, and reuse the global object of env2 |
7092 env2->Exit(); | 7101 env2->Exit(); |
7093 env2->DetachGlobal(); | 7102 env2->DetachGlobal(); |
7094 // env2 has a new global object. | 7103 // env2 has a new global object. |
7095 CHECK(!env2->Global()->Equals(global2)); | 7104 CHECK(!env2->Global()->Equals(global2)); |
7096 | 7105 |
7097 v8::Persistent<Context> env3 = | 7106 v8::Handle<Context> env3 = Context::New(env1->GetIsolate(), |
7098 Context::New(0, v8::Handle<v8::ObjectTemplate>(), global2); | 7107 0, |
| 7108 v8::Handle<v8::ObjectTemplate>(), |
| 7109 global2); |
7099 env3->SetSecurityToken(v8_str("bar")); | 7110 env3->SetSecurityToken(v8_str("bar")); |
7100 env3->Enter(); | 7111 env3->Enter(); |
7101 | 7112 |
7102 Local<v8::Object> global3 = env3->Global(); | 7113 Local<v8::Object> global3 = env3->Global(); |
7103 CHECK_EQ(global2, global3); | 7114 CHECK_EQ(global2, global3); |
7104 CHECK(global3->Get(v8_str("prop"))->IsUndefined()); | 7115 CHECK(global3->Get(v8_str("prop"))->IsUndefined()); |
7105 CHECK(global3->Get(v8_str("getProp"))->IsUndefined()); | 7116 CHECK(global3->Get(v8_str("getProp"))->IsUndefined()); |
7106 global3->Set(v8_str("prop"), v8::Integer::New(-1)); | 7117 global3->Set(v8_str("prop"), v8::Integer::New(-1)); |
7107 global3->Set(v8_str("prop2"), v8::Integer::New(2)); | 7118 global3->Set(v8_str("prop2"), v8::Integer::New(2)); |
7108 env3->Exit(); | 7119 env3->Exit(); |
7109 | 7120 |
7110 // Call getProp in env1, and it should return the value 1 | 7121 // Call getProp in env1, and it should return the value 1 |
7111 { | 7122 { |
7112 Local<Value> get_prop = global1->Get(v8_str("getProp")); | 7123 Local<Value> get_prop = global1->Get(v8_str("getProp")); |
7113 CHECK(get_prop->IsFunction()); | 7124 CHECK(get_prop->IsFunction()); |
7114 v8::TryCatch try_catch; | 7125 v8::TryCatch try_catch; |
7115 Local<Value> r = Function::Cast(*get_prop)->Call(global1, 0, NULL); | 7126 Local<Value> r = Function::Cast(*get_prop)->Call(global1, 0, NULL); |
7116 CHECK(!try_catch.HasCaught()); | 7127 CHECK(!try_catch.HasCaught()); |
7117 CHECK_EQ(1, r->Int32Value()); | 7128 CHECK_EQ(1, r->Int32Value()); |
7118 } | 7129 } |
7119 | 7130 |
7120 // Check that env3 is not accessible from env1 | 7131 // Check that env3 is not accessible from env1 |
7121 { | 7132 { |
7122 Local<Value> r = global3->Get(v8_str("prop2")); | 7133 Local<Value> r = global3->Get(v8_str("prop2")); |
7123 CHECK(r->IsUndefined()); | 7134 CHECK(r->IsUndefined()); |
7124 } | 7135 } |
7125 | |
7126 env2.Dispose(env2->GetIsolate()); | |
7127 env3.Dispose(env3->GetIsolate()); | |
7128 } | 7136 } |
7129 | 7137 |
7130 | 7138 |
7131 TEST(DetachAndReattachGlobal) { | 7139 TEST(DetachAndReattachGlobal) { |
7132 LocalContext env1; | 7140 LocalContext env1; |
7133 v8::HandleScope scope(env1->GetIsolate()); | 7141 v8::HandleScope scope(env1->GetIsolate()); |
7134 | 7142 |
7135 // Create second environment. | 7143 // Create second environment. |
7136 v8::Persistent<Context> env2 = Context::New(); | 7144 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); |
7137 | 7145 |
7138 Local<Value> foo = v8_str("foo"); | 7146 Local<Value> foo = v8_str("foo"); |
7139 | 7147 |
7140 // Set same security token for env1 and env2. | 7148 // Set same security token for env1 and env2. |
7141 env1->SetSecurityToken(foo); | 7149 env1->SetSecurityToken(foo); |
7142 env2->SetSecurityToken(foo); | 7150 env2->SetSecurityToken(foo); |
7143 | 7151 |
7144 // Create a property on the global object in env2. | 7152 // Create a property on the global object in env2. |
7145 { | 7153 { |
7146 v8::Context::Scope scope(env2); | 7154 v8::Context::Scope scope(env2); |
(...skipping 11 matching lines...) Expand all Loading... |
7158 // Hold on to global from env2 and detach global from env2. | 7166 // Hold on to global from env2 and detach global from env2. |
7159 Local<v8::Object> global2 = env2->Global(); | 7167 Local<v8::Object> global2 = env2->Global(); |
7160 env2->DetachGlobal(); | 7168 env2->DetachGlobal(); |
7161 | 7169 |
7162 // Check that the global has been detached. No other.p property can | 7170 // Check that the global has been detached. No other.p property can |
7163 // be found. | 7171 // be found. |
7164 result = CompileRun("other.p"); | 7172 result = CompileRun("other.p"); |
7165 CHECK(result->IsUndefined()); | 7173 CHECK(result->IsUndefined()); |
7166 | 7174 |
7167 // Reuse global2 for env3. | 7175 // Reuse global2 for env3. |
7168 v8::Persistent<Context> env3 = | 7176 v8::Handle<Context> env3 = Context::New(env1->GetIsolate(), |
7169 Context::New(0, v8::Handle<v8::ObjectTemplate>(), global2); | 7177 0, |
| 7178 v8::Handle<v8::ObjectTemplate>(), |
| 7179 global2); |
7170 CHECK_EQ(global2, env3->Global()); | 7180 CHECK_EQ(global2, env3->Global()); |
7171 | 7181 |
7172 // Start by using the same security token for env3 as for env1 and env2. | 7182 // Start by using the same security token for env3 as for env1 and env2. |
7173 env3->SetSecurityToken(foo); | 7183 env3->SetSecurityToken(foo); |
7174 | 7184 |
7175 // Create a property on the global object in env3. | 7185 // Create a property on the global object in env3. |
7176 { | 7186 { |
7177 v8::Context::Scope scope(env3); | 7187 v8::Context::Scope scope(env3); |
7178 env3->Global()->Set(v8_str("p"), v8::Integer::New(24)); | 7188 env3->Global()->Set(v8_str("p"), v8::Integer::New(24)); |
7179 } | 7189 } |
(...skipping 14 matching lines...) Expand all Loading... |
7194 | 7204 |
7195 // Detach the global for env3 and reattach it to env2. | 7205 // Detach the global for env3 and reattach it to env2. |
7196 env3->DetachGlobal(); | 7206 env3->DetachGlobal(); |
7197 env2->ReattachGlobal(global2); | 7207 env2->ReattachGlobal(global2); |
7198 | 7208 |
7199 // Check that we have access to other.p again in env1. |other| is now | 7209 // Check that we have access to other.p again in env1. |other| is now |
7200 // the global object for env2 which has the same security token as env1. | 7210 // the global object for env2 which has the same security token as env1. |
7201 result = CompileRun("other.p"); | 7211 result = CompileRun("other.p"); |
7202 CHECK(result->IsInt32()); | 7212 CHECK(result->IsInt32()); |
7203 CHECK_EQ(42, result->Int32Value()); | 7213 CHECK_EQ(42, result->Int32Value()); |
7204 | |
7205 env2.Dispose(env2->GetIsolate()); | |
7206 env3.Dispose(env3->GetIsolate()); | |
7207 } | 7214 } |
7208 | 7215 |
7209 | 7216 |
7210 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false }; | 7217 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false }; |
7211 static bool NamedAccessBlocker(Local<v8::Object> global, | 7218 static bool NamedAccessBlocker(Local<v8::Object> global, |
7212 Local<Value> name, | 7219 Local<Value> name, |
7213 v8::AccessType type, | 7220 v8::AccessType type, |
7214 Local<Value> data) { | 7221 Local<Value> data) { |
7215 return Context::GetCurrent()->Global()->Equals(global) || | 7222 return Context::GetCurrent()->Global()->Equals(global) || |
7216 allowed_access_type[type]; | 7223 allowed_access_type[type]; |
(...skipping 2048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9265 | 9272 |
9266 | 9273 |
9267 // Below go several tests which verify that JITing for various | 9274 // Below go several tests which verify that JITing for various |
9268 // configurations of interceptor and explicit fields works fine | 9275 // configurations of interceptor and explicit fields works fine |
9269 // (those cases are special cased to get better performance). | 9276 // (those cases are special cased to get better performance). |
9270 | 9277 |
9271 static v8::Handle<Value> InterceptorLoadXICGetter(Local<String> name, | 9278 static v8::Handle<Value> InterceptorLoadXICGetter(Local<String> name, |
9272 const AccessorInfo& info) { | 9279 const AccessorInfo& info) { |
9273 ApiTestFuzzer::Fuzz(); | 9280 ApiTestFuzzer::Fuzz(); |
9274 return v8_str("x")->Equals(name) | 9281 return v8_str("x")->Equals(name) |
9275 ? v8::Integer::New(42) : v8::Handle<v8::Value>(); | 9282 ? v8::Handle<v8::Value>(v8::Integer::New(42)) : v8::Handle<v8::Value>(); |
9276 } | 9283 } |
9277 | 9284 |
9278 | 9285 |
9279 THREADED_TEST(InterceptorLoadICWithFieldOnHolder) { | 9286 THREADED_TEST(InterceptorLoadICWithFieldOnHolder) { |
9280 CheckInterceptorLoadIC(InterceptorLoadXICGetter, | 9287 CheckInterceptorLoadIC(InterceptorLoadXICGetter, |
9281 "var result = 0;" | 9288 "var result = 0;" |
9282 "o.y = 239;" | 9289 "o.y = 239;" |
9283 "for (var i = 0; i < 1000; i++) {" | 9290 "for (var i = 0; i < 1000; i++) {" |
9284 " result = o.y;" | 9291 " result = o.y;" |
9285 "}", | 9292 "}", |
(...skipping 2996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12282 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 12289 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
12283 | 12290 |
12284 // Create an environment with access check to the global object disabled by | 12291 // Create an environment with access check to the global object disabled by |
12285 // default. | 12292 // default. |
12286 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 12293 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
12287 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker, | 12294 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker, |
12288 IndexedGetAccessBlocker, | 12295 IndexedGetAccessBlocker, |
12289 v8::Handle<v8::Value>(), | 12296 v8::Handle<v8::Value>(), |
12290 false); | 12297 false); |
12291 v8::Persistent<Context> context = Context::New(NULL, global_template); | 12298 v8::Persistent<Context> context = Context::New(NULL, global_template); |
12292 Context::Scope context_scope(context); | 12299 Context::Scope context_scope(v8::Isolate::GetCurrent(), context); |
12293 | 12300 |
12294 // Set up a property and a number of functions. | 12301 // Set up a property and a number of functions. |
12295 context->Global()->Set(v8_str("a"), v8_num(1)); | 12302 context->Global()->Set(v8_str("a"), v8_num(1)); |
12296 CompileRun("function f1() {return a;}" | 12303 CompileRun("function f1() {return a;}" |
12297 "function f2() {return a;}" | 12304 "function f2() {return a;}" |
12298 "function g1() {return h();}" | 12305 "function g1() {return h();}" |
12299 "function g2() {return h();}" | 12306 "function g2() {return h();}" |
12300 "function h() {return 1;}"); | 12307 "function h() {return 1;}"); |
12301 Local<Function> f1 = | 12308 Local<Function> f1 = |
12302 Local<Function>::Cast(context->Global()->Get(v8_str("f1"))); | 12309 Local<Function>::Cast(context->Global()->Get(v8_str("f1"))); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12363 | 12370 |
12364 // Create an environment with access check to the global object disabled by | 12371 // Create an environment with access check to the global object disabled by |
12365 // default. When the registered access checker will block access to properties | 12372 // default. When the registered access checker will block access to properties |
12366 // a and h. | 12373 // a and h. |
12367 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 12374 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
12368 global_template->SetAccessCheckCallbacks(NamedGetAccessBlockAandH, | 12375 global_template->SetAccessCheckCallbacks(NamedGetAccessBlockAandH, |
12369 IndexedGetAccessBlocker, | 12376 IndexedGetAccessBlocker, |
12370 v8::Handle<v8::Value>(), | 12377 v8::Handle<v8::Value>(), |
12371 false); | 12378 false); |
12372 v8::Persistent<Context> context = Context::New(NULL, global_template); | 12379 v8::Persistent<Context> context = Context::New(NULL, global_template); |
12373 Context::Scope context_scope(context); | 12380 Context::Scope context_scope(v8::Isolate::GetCurrent(), context); |
12374 | 12381 |
12375 // Set up a property and a number of functions. | 12382 // Set up a property and a number of functions. |
12376 context->Global()->Set(v8_str("a"), v8_num(1)); | 12383 context->Global()->Set(v8_str("a"), v8_num(1)); |
12377 static const char* source = "function f1() {return a;}" | 12384 static const char* source = "function f1() {return a;}" |
12378 "function f2() {return a;}" | 12385 "function f2() {return a;}" |
12379 "function g1() {return h();}" | 12386 "function g1() {return h();}" |
12380 "function g2() {return h();}" | 12387 "function g2() {return h();}" |
12381 "function h() {return 1;}"; | 12388 "function h() {return 1;}"; |
12382 | 12389 |
12383 CompileRun(source); | 12390 CompileRun(source); |
(...skipping 3998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16382 CHECK_NE(last_message, NULL); | 16389 CHECK_NE(last_message, NULL); |
16383 } | 16390 } |
16384 | 16391 |
16385 TEST(RunTwoIsolatesOnSingleThread) { | 16392 TEST(RunTwoIsolatesOnSingleThread) { |
16386 // Run isolate 1. | 16393 // Run isolate 1. |
16387 v8::Isolate* isolate1 = v8::Isolate::New(); | 16394 v8::Isolate* isolate1 = v8::Isolate::New(); |
16388 isolate1->Enter(); | 16395 isolate1->Enter(); |
16389 v8::Persistent<v8::Context> context1 = v8::Context::New(); | 16396 v8::Persistent<v8::Context> context1 = v8::Context::New(); |
16390 | 16397 |
16391 { | 16398 { |
16392 v8::Context::Scope cscope(context1); | |
16393 v8::HandleScope scope(isolate1); | 16399 v8::HandleScope scope(isolate1); |
| 16400 v8::Context::Scope cscope(isolate1, context1); |
16394 // Run something in new isolate. | 16401 // Run something in new isolate. |
16395 CompileRun("var foo = 'isolate 1';"); | 16402 CompileRun("var foo = 'isolate 1';"); |
16396 ExpectString("function f() { return foo; }; f()", "isolate 1"); | 16403 ExpectString("function f() { return foo; }; f()", "isolate 1"); |
16397 } | 16404 } |
16398 | 16405 |
16399 // Run isolate 2. | 16406 // Run isolate 2. |
16400 v8::Isolate* isolate2 = v8::Isolate::New(); | 16407 v8::Isolate* isolate2 = v8::Isolate::New(); |
16401 v8::Persistent<v8::Context> context2; | 16408 v8::Persistent<v8::Context> context2; |
16402 | 16409 |
16403 { | 16410 { |
16404 v8::Isolate::Scope iscope(isolate2); | 16411 v8::Isolate::Scope iscope(isolate2); |
16405 context2 = v8::Context::New(); | 16412 context2 = v8::Context::New(); |
16406 v8::Context::Scope cscope(context2); | |
16407 v8::HandleScope scope(isolate2); | 16413 v8::HandleScope scope(isolate2); |
| 16414 v8::Context::Scope cscope(isolate2, context2); |
16408 | 16415 |
16409 // Run something in new isolate. | 16416 // Run something in new isolate. |
16410 CompileRun("var foo = 'isolate 2';"); | 16417 CompileRun("var foo = 'isolate 2';"); |
16411 ExpectString("function f() { return foo; }; f()", "isolate 2"); | 16418 ExpectString("function f() { return foo; }; f()", "isolate 2"); |
16412 } | 16419 } |
16413 | 16420 |
16414 { | 16421 { |
16415 v8::Context::Scope cscope(context1); | |
16416 v8::HandleScope scope(isolate1); | 16422 v8::HandleScope scope(isolate1); |
| 16423 v8::Context::Scope cscope(isolate1, context1); |
16417 // Now again in isolate 1 | 16424 // Now again in isolate 1 |
16418 ExpectString("function f() { return foo; }; f()", "isolate 1"); | 16425 ExpectString("function f() { return foo; }; f()", "isolate 1"); |
16419 } | 16426 } |
16420 | 16427 |
16421 isolate1->Exit(); | 16428 isolate1->Exit(); |
16422 | 16429 |
16423 // Run some stuff in default isolate. | 16430 // Run some stuff in default isolate. |
16424 v8::Persistent<v8::Context> context_default = v8::Context::New(); | 16431 v8::Persistent<v8::Context> context_default = v8::Context::New(); |
16425 | 16432 |
16426 { | 16433 { |
16427 v8::Context::Scope cscope(context_default); | |
16428 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 16434 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 16435 v8::Context::Scope cscope(v8::Isolate::GetCurrent(), context_default); |
16429 // Variables in other isolates should be not available, verify there | 16436 // Variables in other isolates should be not available, verify there |
16430 // is an exception. | 16437 // is an exception. |
16431 ExpectTrue("function f() {" | 16438 ExpectTrue("function f() {" |
16432 " try {" | 16439 " try {" |
16433 " foo;" | 16440 " foo;" |
16434 " return false;" | 16441 " return false;" |
16435 " } catch(e) {" | 16442 " } catch(e) {" |
16436 " return true;" | 16443 " return true;" |
16437 " }" | 16444 " }" |
16438 "};" | 16445 "};" |
16439 "var isDefaultIsolate = true;" | 16446 "var isDefaultIsolate = true;" |
16440 "f()"); | 16447 "f()"); |
16441 } | 16448 } |
16442 | 16449 |
16443 isolate1->Enter(); | 16450 isolate1->Enter(); |
16444 | 16451 |
16445 { | 16452 { |
16446 v8::Isolate::Scope iscope(isolate2); | 16453 v8::Isolate::Scope iscope(isolate2); |
16447 v8::Context::Scope cscope(context2); | |
16448 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 16454 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 16455 v8::Context::Scope cscope(isolate2, context2); |
16449 ExpectString("function f() { return foo; }; f()", "isolate 2"); | 16456 ExpectString("function f() { return foo; }; f()", "isolate 2"); |
16450 } | 16457 } |
16451 | 16458 |
16452 { | 16459 { |
16453 v8::Context::Scope cscope(context1); | |
16454 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 16460 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 16461 v8::Context::Scope cscope(v8::Isolate::GetCurrent(), context1); |
16455 ExpectString("function f() { return foo; }; f()", "isolate 1"); | 16462 ExpectString("function f() { return foo; }; f()", "isolate 1"); |
16456 } | 16463 } |
16457 | 16464 |
16458 { | 16465 { |
16459 v8::Isolate::Scope iscope(isolate2); | 16466 v8::Isolate::Scope iscope(isolate2); |
16460 context2.Dispose(context2->GetIsolate()); | 16467 context2.Dispose(context2->GetIsolate()); |
16461 } | 16468 } |
16462 | 16469 |
16463 context1.Dispose(context1->GetIsolate()); | 16470 context1.Dispose(context1->GetIsolate()); |
16464 isolate1->Exit(); | 16471 isolate1->Exit(); |
16465 | 16472 |
16466 v8::V8::SetFatalErrorHandler(StoringErrorCallback); | 16473 v8::V8::SetFatalErrorHandler(StoringErrorCallback); |
16467 last_location = last_message = NULL; | 16474 last_location = last_message = NULL; |
16468 | 16475 |
16469 isolate1->Dispose(); | 16476 isolate1->Dispose(); |
16470 CHECK_EQ(last_location, NULL); | 16477 CHECK_EQ(last_location, NULL); |
16471 CHECK_EQ(last_message, NULL); | 16478 CHECK_EQ(last_message, NULL); |
16472 | 16479 |
16473 isolate2->Dispose(); | 16480 isolate2->Dispose(); |
16474 CHECK_EQ(last_location, NULL); | 16481 CHECK_EQ(last_location, NULL); |
16475 CHECK_EQ(last_message, NULL); | 16482 CHECK_EQ(last_message, NULL); |
16476 | 16483 |
16477 // Check that default isolate still runs. | 16484 // Check that default isolate still runs. |
16478 { | 16485 { |
16479 v8::Context::Scope cscope(context_default); | |
16480 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 16486 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 16487 v8::Context::Scope cscope(v8::Isolate::GetCurrent(), context_default); |
16481 ExpectTrue("function f() { return isDefaultIsolate; }; f()"); | 16488 ExpectTrue("function f() { return isDefaultIsolate; }; f()"); |
16482 } | 16489 } |
16483 } | 16490 } |
16484 | 16491 |
16485 static int CalcFibonacci(v8::Isolate* isolate, int limit) { | 16492 static int CalcFibonacci(v8::Isolate* isolate, int limit) { |
16486 v8::Isolate::Scope isolate_scope(isolate); | 16493 v8::Isolate::Scope isolate_scope(isolate); |
16487 v8::HandleScope scope(isolate); | 16494 v8::HandleScope scope(isolate); |
16488 LocalContext context; | 16495 LocalContext context; |
16489 i::ScopedVector<char> code(1024); | 16496 i::ScopedVector<char> code(1024); |
16490 i::OS::SNPrintF(code, "function fib(n) {" | 16497 i::OS::SNPrintF(code, "function fib(n) {" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16545 isolate2->Dispose(); | 16552 isolate2->Dispose(); |
16546 } | 16553 } |
16547 | 16554 |
16548 TEST(IsolateDifferentContexts) { | 16555 TEST(IsolateDifferentContexts) { |
16549 v8::Isolate* isolate = v8::Isolate::New(); | 16556 v8::Isolate* isolate = v8::Isolate::New(); |
16550 Persistent<v8::Context> context; | 16557 Persistent<v8::Context> context; |
16551 { | 16558 { |
16552 v8::Isolate::Scope isolate_scope(isolate); | 16559 v8::Isolate::Scope isolate_scope(isolate); |
16553 v8::HandleScope handle_scope(isolate); | 16560 v8::HandleScope handle_scope(isolate); |
16554 context = v8::Context::New(); | 16561 context = v8::Context::New(); |
16555 v8::Context::Scope context_scope(context); | 16562 v8::Context::Scope context_scope(isolate, context); |
16556 Local<Value> v = CompileRun("2"); | 16563 Local<Value> v = CompileRun("2"); |
16557 CHECK(v->IsNumber()); | 16564 CHECK(v->IsNumber()); |
16558 CHECK_EQ(2, static_cast<int>(v->NumberValue())); | 16565 CHECK_EQ(2, static_cast<int>(v->NumberValue())); |
16559 } | 16566 } |
16560 { | 16567 { |
16561 v8::Isolate::Scope isolate_scope(isolate); | 16568 v8::Isolate::Scope isolate_scope(isolate); |
16562 v8::HandleScope handle_scope(isolate); | 16569 v8::HandleScope handle_scope(isolate); |
16563 context = v8::Context::New(); | 16570 context = v8::Context::New(); |
16564 v8::Context::Scope context_scope(context); | 16571 v8::Context::Scope context_scope(isolate, context); |
16565 Local<Value> v = CompileRun("22"); | 16572 Local<Value> v = CompileRun("22"); |
16566 CHECK(v->IsNumber()); | 16573 CHECK(v->IsNumber()); |
16567 CHECK_EQ(22, static_cast<int>(v->NumberValue())); | 16574 CHECK_EQ(22, static_cast<int>(v->NumberValue())); |
16568 } | 16575 } |
16569 isolate->Dispose(); | 16576 isolate->Dispose(); |
16570 } | 16577 } |
16571 | 16578 |
16572 class InitDefaultIsolateThread : public v8::internal::Thread { | 16579 class InitDefaultIsolateThread : public v8::internal::Thread { |
16573 public: | 16580 public: |
16574 enum TestCase { | 16581 enum TestCase { |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16829 explicit Visitor42(v8::Persistent<v8::Object> object) | 16836 explicit Visitor42(v8::Persistent<v8::Object> object) |
16830 : counter_(0), object_(object) { } | 16837 : counter_(0), object_(object) { } |
16831 | 16838 |
16832 virtual void VisitPersistentHandle(Persistent<Value> value, | 16839 virtual void VisitPersistentHandle(Persistent<Value> value, |
16833 uint16_t class_id) { | 16840 uint16_t class_id) { |
16834 if (class_id == 42) { | 16841 if (class_id == 42) { |
16835 CHECK(value->IsObject()); | 16842 CHECK(value->IsObject()); |
16836 v8::Persistent<v8::Object> visited = | 16843 v8::Persistent<v8::Object> visited = |
16837 v8::Persistent<v8::Object>::Cast(value); | 16844 v8::Persistent<v8::Object>::Cast(value); |
16838 CHECK_EQ(42, visited.WrapperClassId(v8::Isolate::GetCurrent())); | 16845 CHECK_EQ(42, visited.WrapperClassId(v8::Isolate::GetCurrent())); |
16839 CHECK_EQ(object_, visited); | 16846 CHECK_EQ(Handle<Value>(*object_), Handle<Value>(*visited)); |
16840 ++counter_; | 16847 ++counter_; |
16841 } | 16848 } |
16842 } | 16849 } |
16843 | 16850 |
16844 int counter_; | 16851 int counter_; |
16845 v8::Persistent<v8::Object> object_; | 16852 v8::Persistent<v8::Object> object_; |
16846 }; | 16853 }; |
16847 | 16854 |
16848 | 16855 |
16849 TEST(PersistentHandleVisitor) { | 16856 TEST(PersistentHandleVisitor) { |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17044 } | 17051 } |
17045 | 17052 |
17046 | 17053 |
17047 static void CheckContextId(v8::Handle<Object> object, int expected) { | 17054 static void CheckContextId(v8::Handle<Object> object, int expected) { |
17048 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value()); | 17055 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value()); |
17049 } | 17056 } |
17050 | 17057 |
17051 | 17058 |
17052 THREADED_TEST(CreationContext) { | 17059 THREADED_TEST(CreationContext) { |
17053 HandleScope handle_scope(v8::Isolate::GetCurrent()); | 17060 HandleScope handle_scope(v8::Isolate::GetCurrent()); |
17054 Persistent<Context> context1 = Context::New(); | 17061 Handle<Context> context1 = Context::New(v8::Isolate::GetCurrent()); |
17055 InstallContextId(context1, 1); | 17062 InstallContextId(context1, 1); |
17056 Persistent<Context> context2 = Context::New(); | 17063 Handle<Context> context2 = Context::New(v8::Isolate::GetCurrent()); |
17057 InstallContextId(context2, 2); | 17064 InstallContextId(context2, 2); |
17058 Persistent<Context> context3 = Context::New(); | 17065 Handle<Context> context3 = Context::New(v8::Isolate::GetCurrent()); |
17059 InstallContextId(context3, 3); | 17066 InstallContextId(context3, 3); |
17060 | 17067 |
17061 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); | 17068 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); |
17062 | 17069 |
17063 Local<Object> object1; | 17070 Local<Object> object1; |
17064 Local<Function> func1; | 17071 Local<Function> func1; |
17065 { | 17072 { |
17066 Context::Scope scope(context1); | 17073 Context::Scope scope(context1); |
17067 object1 = Object::New(); | 17074 object1 = Object::New(); |
17068 func1 = tmpl->GetFunction(); | 17075 func1 = tmpl->GetFunction(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17122 CheckContextId(func1, 1); | 17129 CheckContextId(func1, 1); |
17123 CHECK(instance1->CreationContext() == context1); | 17130 CHECK(instance1->CreationContext() == context1); |
17124 CheckContextId(instance1, 1); | 17131 CheckContextId(instance1, 1); |
17125 CHECK(object2->CreationContext() == context2); | 17132 CHECK(object2->CreationContext() == context2); |
17126 CheckContextId(object2, 2); | 17133 CheckContextId(object2, 2); |
17127 CHECK(func2->CreationContext() == context2); | 17134 CHECK(func2->CreationContext() == context2); |
17128 CheckContextId(func2, 2); | 17135 CheckContextId(func2, 2); |
17129 CHECK(instance2->CreationContext() == context2); | 17136 CHECK(instance2->CreationContext() == context2); |
17130 CheckContextId(instance2, 2); | 17137 CheckContextId(instance2, 2); |
17131 } | 17138 } |
17132 | |
17133 context1.Dispose(context1->GetIsolate()); | |
17134 context2.Dispose(context2->GetIsolate()); | |
17135 context3.Dispose(context3->GetIsolate()); | |
17136 } | 17139 } |
17137 | 17140 |
17138 | 17141 |
17139 THREADED_TEST(CreationContextOfJsFunction) { | 17142 THREADED_TEST(CreationContextOfJsFunction) { |
17140 HandleScope handle_scope(v8::Isolate::GetCurrent()); | 17143 HandleScope handle_scope(v8::Isolate::GetCurrent()); |
17141 Persistent<Context> context = Context::New(); | 17144 Handle<Context> context = Context::New(v8::Isolate::GetCurrent()); |
17142 InstallContextId(context, 1); | 17145 InstallContextId(context, 1); |
17143 | 17146 |
17144 Local<Object> function; | 17147 Local<Object> function; |
17145 { | 17148 { |
17146 Context::Scope scope(context); | 17149 Context::Scope scope(context); |
17147 function = CompileRun("function foo() {}; foo").As<Object>(); | 17150 function = CompileRun("function foo() {}; foo").As<Object>(); |
17148 } | 17151 } |
17149 | 17152 |
17150 CHECK(function->CreationContext() == context); | 17153 CHECK(function->CreationContext() == context); |
17151 CheckContextId(function, 1); | 17154 CheckContextId(function, 1); |
17152 | |
17153 context.Dispose(context->GetIsolate()); | |
17154 } | 17155 } |
17155 | 17156 |
17156 | 17157 |
17157 Handle<Value> HasOwnPropertyIndexedPropertyGetter(uint32_t index, | 17158 Handle<Value> HasOwnPropertyIndexedPropertyGetter(uint32_t index, |
17158 const AccessorInfo& info) { | 17159 const AccessorInfo& info) { |
17159 if (index == 42) return v8_str("yes"); | 17160 if (index == 42) return v8_str("yes"); |
17160 return Handle<v8::Integer>(); | 17161 return Handle<v8::Integer>(); |
17161 } | 17162 } |
17162 | 17163 |
17163 | 17164 |
(...skipping 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18394 i::Semaphore* sem_; | 18395 i::Semaphore* sem_; |
18395 volatile int sem_value_; | 18396 volatile int sem_value_; |
18396 }; | 18397 }; |
18397 | 18398 |
18398 | 18399 |
18399 THREADED_TEST(SemaphoreInterruption) { | 18400 THREADED_TEST(SemaphoreInterruption) { |
18400 ThreadInterruptTest().RunTest(); | 18401 ThreadInterruptTest().RunTest(); |
18401 } | 18402 } |
18402 | 18403 |
18403 #endif // WIN32 | 18404 #endif // WIN32 |
OLD | NEW |