| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 const char* c_source = "1 + 2 + 3"; | 160 const char* c_source = "1 + 2 + 3"; |
| 156 Local<String> source = String::New(c_source); | 161 Local<String> source = String::New(c_source); |
| 157 Local<Script> script = Script::Compile(source); | 162 Local<Script> script = Script::Compile(source); |
| 158 CHECK_EQ(6, script->Run()->Int32Value()); | 163 CHECK_EQ(6, script->Run()->Int32Value()); |
| 159 | 164 |
| 160 local_env->Exit(); | 165 local_env->Exit(); |
| 161 } | 166 } |
| 162 | 167 |
| 163 | 168 |
| 164 THREADED_TEST(IsolateOfContext) { | 169 THREADED_TEST(IsolateOfContext) { |
| 165 v8::Persistent<Context> env = Context::New(); | 170 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 166 v8::HandleScope scope(env->GetIsolate()); | 171 v8::Handle<Context> env = Context::New(v8::Isolate::GetCurrent()); |
| 167 | 172 |
| 168 CHECK(!env->InContext()); | 173 CHECK(!env->InContext()); |
| 169 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); | 174 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); |
| 170 env->Enter(); | 175 env->Enter(); |
| 171 CHECK(env->InContext()); | 176 CHECK(env->InContext()); |
| 172 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); | 177 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); |
| 173 env->Exit(); | 178 env->Exit(); |
| 174 CHECK(!env->InContext()); | 179 CHECK(!env->InContext()); |
| 175 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); | 180 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); |
| 176 | |
| 177 env.Dispose(env->GetIsolate()); | |
| 178 } | 181 } |
| 179 | 182 |
| 180 | 183 |
| 181 THREADED_TEST(ReceiverSignature) { | 184 THREADED_TEST(ReceiverSignature) { |
| 182 LocalContext env; | 185 LocalContext env; |
| 183 v8::HandleScope scope(env->GetIsolate()); | 186 v8::HandleScope scope(env->GetIsolate()); |
| 184 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(); | 187 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(); |
| 185 v8::Handle<v8::Signature> sig = v8::Signature::New(fun); | 188 v8::Handle<v8::Signature> sig = v8::Signature::New(fun); |
| 186 fun->PrototypeTemplate()->Set( | 189 fun->PrototypeTemplate()->Set( |
| 187 v8_str("m"), | 190 v8_str("m"), |
| (...skipping 2124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2312 CHECK_EQ(0xCC, my_data[1]); | 2315 CHECK_EQ(0xCC, my_data[1]); |
| 2313 my_data[0] = 0xCC; | 2316 my_data[0] = 0xCC; |
| 2314 my_data[1] = 0x11; | 2317 my_data[1] = 0x11; |
| 2315 result = CompileRun("u8_b[0] + u8_b[1]"); | 2318 result = CompileRun("u8_b[0] + u8_b[1]"); |
| 2316 CHECK_EQ(0xDD, result->Int32Value()); | 2319 CHECK_EQ(0xDD, result->Int32Value()); |
| 2317 | 2320 |
| 2318 delete[] my_data; | 2321 delete[] my_data; |
| 2319 } | 2322 } |
| 2320 | 2323 |
| 2321 | 2324 |
| 2325 |
| 2326 |
| 2327 |
| 2322 THREADED_TEST(HiddenProperties) { | 2328 THREADED_TEST(HiddenProperties) { |
| 2323 LocalContext env; | 2329 LocalContext env; |
| 2324 v8::HandleScope scope(env->GetIsolate()); | 2330 v8::HandleScope scope(env->GetIsolate()); |
| 2325 | 2331 |
| 2326 v8::Local<v8::Object> obj = v8::Object::New(); | 2332 v8::Local<v8::Object> obj = v8::Object::New(); |
| 2327 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); | 2333 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); |
| 2328 v8::Local<v8::String> empty = v8_str(""); | 2334 v8::Local<v8::String> empty = v8_str(""); |
| 2329 v8::Local<v8::String> prop_name = v8_str("prop_name"); | 2335 v8::Local<v8::String> prop_name = v8_str("prop_name"); |
| 2330 | 2336 |
| 2331 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 2337 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2539 g2s2 = Persistent<Object>::New(iso, Object::New()); | 2545 g2s2 = Persistent<Object>::New(iso, Object::New()); |
| 2540 g2c1 = Persistent<Object>::New(iso, Object::New()); | 2546 g2c1 = Persistent<Object>::New(iso, Object::New()); |
| 2541 g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); | 2547 g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); |
| 2542 g2s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); | 2548 g2s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); |
| 2543 g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); | 2549 g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); |
| 2544 } | 2550 } |
| 2545 | 2551 |
| 2546 Persistent<Object> root = Persistent<Object>::New(iso, g1s1); // make a root. | 2552 Persistent<Object> root = Persistent<Object>::New(iso, g1s1); // make a root. |
| 2547 | 2553 |
| 2548 // Connect group 1 and 2, make a cycle. | 2554 // Connect group 1 and 2, make a cycle. |
| 2549 CHECK(g1s2->Set(0, g2s2)); | 2555 CHECK(g1s2->Set(0, Handle<Object>(*g2s2))); |
| 2550 CHECK(g2s1->Set(0, g1s1)); | 2556 CHECK(g2s1->Set(0, Handle<Object>(*g1s1))); |
| 2551 | 2557 |
| 2552 { | 2558 { |
| 2553 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; | 2559 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; |
| 2554 Persistent<Value> g1_children[] = { g1c1 }; | 2560 Persistent<Value> g1_children[] = { g1c1 }; |
| 2555 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; | 2561 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; |
| 2556 Persistent<Value> g2_children[] = { g2c1 }; | 2562 Persistent<Value> g2_children[] = { g2c1 }; |
| 2557 V8::AddObjectGroup(g1_objects, 2); | 2563 V8::AddObjectGroup(g1_objects, 2); |
| 2558 V8::AddImplicitReferences(g1s1, g1_children, 1); | 2564 V8::AddImplicitReferences(g1s1, g1_children, 1); |
| 2559 V8::AddObjectGroup(g2_objects, 2); | 2565 V8::AddObjectGroup(g2_objects, 2); |
| 2560 V8::AddImplicitReferences(g2s1, g2_children, 1); | 2566 V8::AddImplicitReferences(g2s1, g2_children, 1); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2625 g2s2 = Persistent<Object>::New(iso, Object::New()); | 2631 g2s2 = Persistent<Object>::New(iso, Object::New()); |
| 2626 g2c1 = Persistent<Object>::New(iso, Object::New()); | 2632 g2c1 = Persistent<Object>::New(iso, Object::New()); |
| 2627 g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); | 2633 g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); |
| 2628 g2s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); | 2634 g2s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); |
| 2629 g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); | 2635 g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); |
| 2630 } | 2636 } |
| 2631 | 2637 |
| 2632 Persistent<Object> root = Persistent<Object>::New(iso, g1s1); // make a root. | 2638 Persistent<Object> root = Persistent<Object>::New(iso, g1s1); // make a root. |
| 2633 | 2639 |
| 2634 // Connect group 1 and 2, make a cycle. | 2640 // Connect group 1 and 2, make a cycle. |
| 2635 CHECK(g1s2->Set(0, g2s2)); | 2641 CHECK(g1s2->Set(0, Local<Value>(*g2s2))); |
| 2636 CHECK(g2s1->Set(0, g1s1)); | 2642 CHECK(g2s1->Set(0, Local<Value>(*g1s1))); |
| 2637 | 2643 |
| 2638 { | 2644 { |
| 2639 UniqueId id1(reinterpret_cast<intptr_t>(*g1s1)); | 2645 UniqueId id1(reinterpret_cast<intptr_t>(*g1s1)); |
| 2640 UniqueId id2(reinterpret_cast<intptr_t>(*g2s2)); | 2646 UniqueId id2(reinterpret_cast<intptr_t>(*g2s2)); |
| 2641 iso->SetObjectGroupId(g1s1, id1); | 2647 iso->SetObjectGroupId(g1s1, id1); |
| 2642 iso->SetObjectGroupId(g1s2, id1); | 2648 iso->SetObjectGroupId(g1s2, id1); |
| 2643 iso->SetReferenceFromGroup(id1, g1c1); | 2649 iso->SetReferenceFromGroup(id1, g1c1); |
| 2644 iso->SetObjectGroupId(g2s1, id2); | 2650 iso->SetObjectGroupId(g2s1, id2); |
| 2645 iso->SetObjectGroupId(g2s2, id2); | 2651 iso->SetObjectGroupId(g2s2, id2); |
| 2646 iso->SetReferenceFromGroup(id2, g2c1); | 2652 iso->SetReferenceFromGroup(id2, g2c1); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2947 g1s1.MarkPartiallyDependent(iso); | 2953 g1s1.MarkPartiallyDependent(iso); |
| 2948 g1s2.MarkPartiallyDependent(iso); | 2954 g1s2.MarkPartiallyDependent(iso); |
| 2949 g2s1.MarkPartiallyDependent(iso); | 2955 g2s1.MarkPartiallyDependent(iso); |
| 2950 g2s2.MarkPartiallyDependent(iso); | 2956 g2s2.MarkPartiallyDependent(iso); |
| 2951 g3s1.MarkPartiallyDependent(iso); | 2957 g3s1.MarkPartiallyDependent(iso); |
| 2952 g3s2.MarkPartiallyDependent(iso); | 2958 g3s2.MarkPartiallyDependent(iso); |
| 2953 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; | 2959 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; |
| 2954 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; | 2960 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; |
| 2955 Persistent<Value> g3_objects[] = { g3s1, g3s2 }; | 2961 Persistent<Value> g3_objects[] = { g3s1, g3s2 }; |
| 2956 V8::AddObjectGroup(g1_objects, 2); | 2962 V8::AddObjectGroup(g1_objects, 2); |
| 2957 g1s1->Set(v8_str("x"), g2s1); | 2963 g1s1->Set(v8_str("x"), Handle<Object>(*g2s1)); |
| 2958 V8::AddObjectGroup(g2_objects, 2); | 2964 V8::AddObjectGroup(g2_objects, 2); |
| 2959 g2s1->Set(v8_str("x"), g3s1); | 2965 g2s1->Set(v8_str("x"), Handle<Object>(*g3s1)); |
| 2960 V8::AddObjectGroup(g3_objects, 2); | 2966 V8::AddObjectGroup(g3_objects, 2); |
| 2961 g3s1->Set(v8_str("x"), g1s1); | 2967 g3s1->Set(v8_str("x"), Handle<Object>(*g1s1)); |
| 2962 } | 2968 } |
| 2963 | 2969 |
| 2964 HEAP->CollectGarbage(i::NEW_SPACE); | 2970 HEAP->CollectGarbage(i::NEW_SPACE); |
| 2965 | 2971 |
| 2966 // All objects should be alive. | 2972 // All objects should be alive. |
| 2967 CHECK_EQ(0, counter.NumberOfWeakCalls()); | 2973 CHECK_EQ(0, counter.NumberOfWeakCalls()); |
| 2968 | 2974 |
| 2969 // Weaken the root. | 2975 // Weaken the root. |
| 2970 root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); | 2976 root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); |
| 2971 root.MarkPartiallyDependent(iso); | 2977 root.MarkPartiallyDependent(iso); |
| 2972 | 2978 |
| 2973 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 2979 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 2974 // Groups are deleted, rebuild groups. | 2980 // Groups are deleted, rebuild groups. |
| 2975 { | 2981 { |
| 2976 g1s1.MarkPartiallyDependent(isolate); | 2982 g1s1.MarkPartiallyDependent(isolate); |
| 2977 g1s2.MarkPartiallyDependent(isolate); | 2983 g1s2.MarkPartiallyDependent(isolate); |
| 2978 g2s1.MarkPartiallyDependent(isolate); | 2984 g2s1.MarkPartiallyDependent(isolate); |
| 2979 g2s2.MarkPartiallyDependent(isolate); | 2985 g2s2.MarkPartiallyDependent(isolate); |
| 2980 g3s1.MarkPartiallyDependent(isolate); | 2986 g3s1.MarkPartiallyDependent(isolate); |
| 2981 g3s2.MarkPartiallyDependent(isolate); | 2987 g3s2.MarkPartiallyDependent(isolate); |
| 2982 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; | 2988 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; |
| 2983 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; | 2989 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; |
| 2984 Persistent<Value> g3_objects[] = { g3s1, g3s2 }; | 2990 Persistent<Value> g3_objects[] = { g3s1, g3s2 }; |
| 2985 V8::AddObjectGroup(g1_objects, 2); | 2991 V8::AddObjectGroup(g1_objects, 2); |
| 2986 g1s1->Set(v8_str("x"), g2s1); | 2992 g1s1->Set(v8_str("x"), Handle<Object>(*g2s1)); |
| 2987 V8::AddObjectGroup(g2_objects, 2); | 2993 V8::AddObjectGroup(g2_objects, 2); |
| 2988 g2s1->Set(v8_str("x"), g3s1); | 2994 g2s1->Set(v8_str("x"), Handle<Object>(*g3s1)); |
| 2989 V8::AddObjectGroup(g3_objects, 2); | 2995 V8::AddObjectGroup(g3_objects, 2); |
| 2990 g3s1->Set(v8_str("x"), g1s1); | 2996 g3s1->Set(v8_str("x"), Handle<Object>(*g1s1)); |
| 2991 } | 2997 } |
| 2992 | 2998 |
| 2993 HEAP->CollectGarbage(i::NEW_SPACE); | 2999 HEAP->CollectGarbage(i::NEW_SPACE); |
| 2994 | 3000 |
| 2995 // All objects should be gone. 7 global handles in total. | 3001 // All objects should be gone. 7 global handles in total. |
| 2996 CHECK_EQ(7, counter.NumberOfWeakCalls()); | 3002 CHECK_EQ(7, counter.NumberOfWeakCalls()); |
| 2997 } | 3003 } |
| 2998 | 3004 |
| 2999 | 3005 |
| 3000 // TODO(mstarzinger): This should be a THREADED_TEST but causes failures | 3006 // TODO(mstarzinger): This should be a THREADED_TEST but causes failures |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3042 // groups. | 3048 // groups. |
| 3043 { | 3049 { |
| 3044 g1s1.MarkPartiallyDependent(iso); | 3050 g1s1.MarkPartiallyDependent(iso); |
| 3045 g1s2.MarkPartiallyDependent(iso); | 3051 g1s2.MarkPartiallyDependent(iso); |
| 3046 g2s1.MarkPartiallyDependent(iso); | 3052 g2s1.MarkPartiallyDependent(iso); |
| 3047 g2s2.MarkPartiallyDependent(iso); | 3053 g2s2.MarkPartiallyDependent(iso); |
| 3048 g3s1.MarkPartiallyDependent(iso); | 3054 g3s1.MarkPartiallyDependent(iso); |
| 3049 g3s2.MarkPartiallyDependent(iso); | 3055 g3s2.MarkPartiallyDependent(iso); |
| 3050 iso->SetObjectGroupId(g1s1, UniqueId(1)); | 3056 iso->SetObjectGroupId(g1s1, UniqueId(1)); |
| 3051 iso->SetObjectGroupId(g1s2, UniqueId(1)); | 3057 iso->SetObjectGroupId(g1s2, UniqueId(1)); |
| 3052 g1s1->Set(v8_str("x"), g2s1); | 3058 g1s1->Set(v8_str("x"), Local<Value>(*g2s1)); |
| 3053 iso->SetObjectGroupId(g2s1, UniqueId(2)); | 3059 iso->SetObjectGroupId(g2s1, UniqueId(2)); |
| 3054 iso->SetObjectGroupId(g2s2, UniqueId(2)); | 3060 iso->SetObjectGroupId(g2s2, UniqueId(2)); |
| 3055 g2s1->Set(v8_str("x"), g3s1); | 3061 g2s1->Set(v8_str("x"), Local<Value>(*g3s1)); |
| 3056 iso->SetObjectGroupId(g3s1, UniqueId(3)); | 3062 iso->SetObjectGroupId(g3s1, UniqueId(3)); |
| 3057 iso->SetObjectGroupId(g3s2, UniqueId(3)); | 3063 iso->SetObjectGroupId(g3s2, UniqueId(3)); |
| 3058 g3s1->Set(v8_str("x"), g1s1); | 3064 g3s1->Set(v8_str("x"), Local<Value>(*g1s1)); |
| 3059 } | 3065 } |
| 3060 | 3066 |
| 3061 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( | 3067 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( |
| 3062 iso)->heap(); | 3068 iso)->heap(); |
| 3063 heap->CollectGarbage(i::NEW_SPACE); | 3069 heap->CollectGarbage(i::NEW_SPACE); |
| 3064 | 3070 |
| 3065 // All objects should be alive. | 3071 // All objects should be alive. |
| 3066 CHECK_EQ(0, counter.NumberOfWeakCalls()); | 3072 CHECK_EQ(0, counter.NumberOfWeakCalls()); |
| 3067 | 3073 |
| 3068 // Weaken the root. | 3074 // Weaken the root. |
| 3069 root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); | 3075 root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); |
| 3070 root.MarkPartiallyDependent(iso); | 3076 root.MarkPartiallyDependent(iso); |
| 3071 | 3077 |
| 3072 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 3078 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 3073 // Groups are deleted, rebuild groups. | 3079 // Groups are deleted, rebuild groups. |
| 3074 { | 3080 { |
| 3075 g1s1.MarkPartiallyDependent(isolate); | 3081 g1s1.MarkPartiallyDependent(isolate); |
| 3076 g1s2.MarkPartiallyDependent(isolate); | 3082 g1s2.MarkPartiallyDependent(isolate); |
| 3077 g2s1.MarkPartiallyDependent(isolate); | 3083 g2s1.MarkPartiallyDependent(isolate); |
| 3078 g2s2.MarkPartiallyDependent(isolate); | 3084 g2s2.MarkPartiallyDependent(isolate); |
| 3079 g3s1.MarkPartiallyDependent(isolate); | 3085 g3s1.MarkPartiallyDependent(isolate); |
| 3080 g3s2.MarkPartiallyDependent(isolate); | 3086 g3s2.MarkPartiallyDependent(isolate); |
| 3081 iso->SetObjectGroupId(g1s1, UniqueId(1)); | 3087 iso->SetObjectGroupId(g1s1, UniqueId(1)); |
| 3082 iso->SetObjectGroupId(g1s2, UniqueId(1)); | 3088 iso->SetObjectGroupId(g1s2, UniqueId(1)); |
| 3083 g1s1->Set(v8_str("x"), g2s1); | 3089 g1s1->Set(v8_str("x"), Local<Value>(*g2s1)); |
| 3084 iso->SetObjectGroupId(g2s1, UniqueId(2)); | 3090 iso->SetObjectGroupId(g2s1, UniqueId(2)); |
| 3085 iso->SetObjectGroupId(g2s2, UniqueId(2)); | 3091 iso->SetObjectGroupId(g2s2, UniqueId(2)); |
| 3086 g2s1->Set(v8_str("x"), g3s1); | 3092 g2s1->Set(v8_str("x"), Local<Value>(*g3s1)); |
| 3087 iso->SetObjectGroupId(g3s1, UniqueId(3)); | 3093 iso->SetObjectGroupId(g3s1, UniqueId(3)); |
| 3088 iso->SetObjectGroupId(g3s2, UniqueId(3)); | 3094 iso->SetObjectGroupId(g3s2, UniqueId(3)); |
| 3089 g3s1->Set(v8_str("x"), g1s1); | 3095 g3s1->Set(v8_str("x"), Local<Value>(*g1s1)); |
| 3090 } | 3096 } |
| 3091 | 3097 |
| 3092 heap->CollectGarbage(i::NEW_SPACE); | 3098 heap->CollectGarbage(i::NEW_SPACE); |
| 3093 | 3099 |
| 3094 // All objects should be gone. 7 global handles in total. | 3100 // All objects should be gone. 7 global handles in total. |
| 3095 CHECK_EQ(7, counter.NumberOfWeakCalls()); | 3101 CHECK_EQ(7, counter.NumberOfWeakCalls()); |
| 3096 } | 3102 } |
| 3097 | 3103 |
| 3098 | 3104 |
| 3099 THREADED_TEST(ScriptException) { | 3105 THREADED_TEST(ScriptException) { |
| (...skipping 1433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4533 THREADED_TEST(SimplePropertyWrite) { | 4539 THREADED_TEST(SimplePropertyWrite) { |
| 4534 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 4540 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 4535 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4541 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 4536 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut")); | 4542 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut")); |
| 4537 LocalContext context; | 4543 LocalContext context; |
| 4538 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 4544 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
| 4539 Local<Script> script = Script::Compile(v8_str("obj.x = 4")); | 4545 Local<Script> script = Script::Compile(v8_str("obj.x = 4")); |
| 4540 for (int i = 0; i < 10; i++) { | 4546 for (int i = 0; i < 10; i++) { |
| 4541 CHECK(xValue.IsEmpty()); | 4547 CHECK(xValue.IsEmpty()); |
| 4542 script->Run(); | 4548 script->Run(); |
| 4543 CHECK_EQ(v8_num(4), xValue); | 4549 CHECK_EQ(v8_num(4), Handle<Value>(*xValue)); |
| 4544 xValue.Dispose(context->GetIsolate()); | 4550 xValue.Dispose(context->GetIsolate()); |
| 4545 xValue = v8::Persistent<Value>(); | 4551 xValue = v8::Persistent<Value>(); |
| 4546 } | 4552 } |
| 4547 } | 4553 } |
| 4548 | 4554 |
| 4549 | 4555 |
| 4550 THREADED_TEST(SetterOnly) { | 4556 THREADED_TEST(SetterOnly) { |
| 4551 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 4557 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 4552 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4558 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 4553 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut")); | 4559 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut")); |
| 4554 LocalContext context; | 4560 LocalContext context; |
| 4555 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 4561 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
| 4556 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); | 4562 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); |
| 4557 for (int i = 0; i < 10; i++) { | 4563 for (int i = 0; i < 10; i++) { |
| 4558 CHECK(xValue.IsEmpty()); | 4564 CHECK(xValue.IsEmpty()); |
| 4559 script->Run(); | 4565 script->Run(); |
| 4560 CHECK_EQ(v8_num(4), xValue); | 4566 CHECK_EQ(v8_num(4), Handle<Value>(*xValue)); |
| 4561 xValue.Dispose(context->GetIsolate()); | 4567 xValue.Dispose(context->GetIsolate()); |
| 4562 xValue = v8::Persistent<Value>(); | 4568 xValue = v8::Persistent<Value>(); |
| 4563 } | 4569 } |
| 4564 } | 4570 } |
| 4565 | 4571 |
| 4566 | 4572 |
| 4567 THREADED_TEST(NoAccessors) { | 4573 THREADED_TEST(NoAccessors) { |
| 4568 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 4574 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 4569 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4575 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 4570 templ->SetAccessor(v8_str("x"), NULL, NULL, v8_str("donut")); | 4576 templ->SetAccessor(v8_str("x"), NULL, NULL, v8_str("donut")); |
| (...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5441 return v8::Undefined(); | 5447 return v8::Undefined(); |
| 5442 } | 5448 } |
| 5443 | 5449 |
| 5444 | 5450 |
| 5445 THREADED_TEST(GlobalObjectTemplate) { | 5451 THREADED_TEST(GlobalObjectTemplate) { |
| 5446 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5452 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 5447 Local<ObjectTemplate> global_template = ObjectTemplate::New(); | 5453 Local<ObjectTemplate> global_template = ObjectTemplate::New(); |
| 5448 global_template->Set(v8_str("JSNI_Log"), | 5454 global_template->Set(v8_str("JSNI_Log"), |
| 5449 v8::FunctionTemplate::New(HandleLogDelegator)); | 5455 v8::FunctionTemplate::New(HandleLogDelegator)); |
| 5450 v8::Persistent<Context> context = Context::New(0, global_template); | 5456 v8::Persistent<Context> context = Context::New(0, global_template); |
| 5451 Context::Scope context_scope(context); | 5457 Context::Scope context_scope(v8::Isolate::GetCurrent(), context); |
| 5452 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run(); | 5458 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run(); |
| 5453 context.Dispose(context->GetIsolate()); | 5459 context.Dispose(context->GetIsolate()); |
| 5454 } | 5460 } |
| 5455 | 5461 |
| 5456 | 5462 |
| 5457 static const char* kSimpleExtensionSource = | 5463 static const char* kSimpleExtensionSource = |
| 5458 "function Foo() {" | 5464 "function Foo() {" |
| 5459 " return 4;" | 5465 " return 4;" |
| 5460 "}"; | 5466 "}"; |
| 5461 | 5467 |
| 5462 | 5468 |
| 5463 THREADED_TEST(SimpleExtensions) { | 5469 THREADED_TEST(SimpleExtensions) { |
| 5464 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5470 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 5465 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource)); | 5471 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource)); |
| 5466 const char* extension_names[] = { "simpletest" }; | 5472 const char* extension_names[] = { "simpletest" }; |
| 5467 v8::ExtensionConfiguration extensions(1, extension_names); | 5473 v8::ExtensionConfiguration extensions(1, extension_names); |
| 5468 v8::Handle<Context> context = Context::New(&extensions); | 5474 v8::Handle<Context> context = |
| 5475 Context::New(v8::Isolate::GetCurrent(), &extensions); |
| 5469 Context::Scope lock(context); | 5476 Context::Scope lock(context); |
| 5470 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); | 5477 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); |
| 5471 CHECK_EQ(result, v8::Integer::New(4)); | 5478 CHECK_EQ(result, v8::Integer::New(4)); |
| 5472 } | 5479 } |
| 5473 | 5480 |
| 5474 | 5481 |
| 5475 THREADED_TEST(NullExtensions) { | 5482 THREADED_TEST(NullExtensions) { |
| 5476 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5483 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 5477 v8::RegisterExtension(new Extension("nulltest", NULL)); | 5484 v8::RegisterExtension(new Extension("nulltest", NULL)); |
| 5478 const char* extension_names[] = { "nulltest" }; | 5485 const char* extension_names[] = { "nulltest" }; |
| 5479 v8::ExtensionConfiguration extensions(1, extension_names); | 5486 v8::ExtensionConfiguration extensions(1, extension_names); |
| 5480 v8::Handle<Context> context = Context::New(&extensions); | 5487 v8::Handle<Context> context = |
| 5488 Context::New(v8::Isolate::GetCurrent(), &extensions); |
| 5481 Context::Scope lock(context); | 5489 Context::Scope lock(context); |
| 5482 v8::Handle<Value> result = Script::Compile(v8_str("1+3"))->Run(); | 5490 v8::Handle<Value> result = Script::Compile(v8_str("1+3"))->Run(); |
| 5483 CHECK_EQ(result, v8::Integer::New(4)); | 5491 CHECK_EQ(result, v8::Integer::New(4)); |
| 5484 } | 5492 } |
| 5485 | 5493 |
| 5486 | 5494 |
| 5487 static const char* kEmbeddedExtensionSource = | 5495 static const char* kEmbeddedExtensionSource = |
| 5488 "function Ret54321(){return 54321;}~~@@$" | 5496 "function Ret54321(){return 54321;}~~@@$" |
| 5489 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS."; | 5497 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS."; |
| 5490 static const int kEmbeddedExtensionSourceValidLen = 34; | 5498 static const int kEmbeddedExtensionSourceValidLen = 34; |
| 5491 | 5499 |
| 5492 | 5500 |
| 5493 THREADED_TEST(ExtensionMissingSourceLength) { | 5501 THREADED_TEST(ExtensionMissingSourceLength) { |
| 5494 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5502 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 5495 v8::RegisterExtension(new Extension("srclentest_fail", | 5503 v8::RegisterExtension(new Extension("srclentest_fail", |
| 5496 kEmbeddedExtensionSource)); | 5504 kEmbeddedExtensionSource)); |
| 5497 const char* extension_names[] = { "srclentest_fail" }; | 5505 const char* extension_names[] = { "srclentest_fail" }; |
| 5498 v8::ExtensionConfiguration extensions(1, extension_names); | 5506 v8::ExtensionConfiguration extensions(1, extension_names); |
| 5499 v8::Handle<Context> context = Context::New(&extensions); | 5507 v8::Handle<Context> context = |
| 5508 Context::New(v8::Isolate::GetCurrent(), &extensions); |
| 5500 CHECK_EQ(0, *context); | 5509 CHECK_EQ(0, *context); |
| 5501 } | 5510 } |
| 5502 | 5511 |
| 5503 | 5512 |
| 5504 THREADED_TEST(ExtensionWithSourceLength) { | 5513 THREADED_TEST(ExtensionWithSourceLength) { |
| 5505 for (int source_len = kEmbeddedExtensionSourceValidLen - 1; | 5514 for (int source_len = kEmbeddedExtensionSourceValidLen - 1; |
| 5506 source_len <= kEmbeddedExtensionSourceValidLen + 1; ++source_len) { | 5515 source_len <= kEmbeddedExtensionSourceValidLen + 1; ++source_len) { |
| 5507 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5516 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 5508 i::ScopedVector<char> extension_name(32); | 5517 i::ScopedVector<char> extension_name(32); |
| 5509 i::OS::SNPrintF(extension_name, "ext #%d", source_len); | 5518 i::OS::SNPrintF(extension_name, "ext #%d", source_len); |
| 5510 v8::RegisterExtension(new Extension(extension_name.start(), | 5519 v8::RegisterExtension(new Extension(extension_name.start(), |
| 5511 kEmbeddedExtensionSource, 0, 0, | 5520 kEmbeddedExtensionSource, 0, 0, |
| 5512 source_len)); | 5521 source_len)); |
| 5513 const char* extension_names[1] = { extension_name.start() }; | 5522 const char* extension_names[1] = { extension_name.start() }; |
| 5514 v8::ExtensionConfiguration extensions(1, extension_names); | 5523 v8::ExtensionConfiguration extensions(1, extension_names); |
| 5515 v8::Handle<Context> context = Context::New(&extensions); | 5524 v8::Handle<Context> context = |
| 5525 Context::New(v8::Isolate::GetCurrent(), &extensions); |
| 5516 if (source_len == kEmbeddedExtensionSourceValidLen) { | 5526 if (source_len == kEmbeddedExtensionSourceValidLen) { |
| 5517 Context::Scope lock(context); | 5527 Context::Scope lock(context); |
| 5518 v8::Handle<Value> result = Script::Compile(v8_str("Ret54321()"))->Run(); | 5528 v8::Handle<Value> result = Script::Compile(v8_str("Ret54321()"))->Run(); |
| 5519 CHECK_EQ(v8::Integer::New(54321), result); | 5529 CHECK_EQ(v8::Integer::New(54321), result); |
| 5520 } else { | 5530 } else { |
| 5521 // Anything but exactly the right length should fail to compile. | 5531 // Anything but exactly the right length should fail to compile. |
| 5522 CHECK_EQ(0, *context); | 5532 CHECK_EQ(0, *context); |
| 5523 } | 5533 } |
| 5524 } | 5534 } |
| 5525 } | 5535 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 5541 " this.UseEval2 = e;" | 5551 " this.UseEval2 = e;" |
| 5542 "})()"; | 5552 "})()"; |
| 5543 | 5553 |
| 5544 | 5554 |
| 5545 THREADED_TEST(UseEvalFromExtension) { | 5555 THREADED_TEST(UseEvalFromExtension) { |
| 5546 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5556 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 5547 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1)); | 5557 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1)); |
| 5548 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2)); | 5558 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2)); |
| 5549 const char* extension_names[] = { "evaltest1", "evaltest2" }; | 5559 const char* extension_names[] = { "evaltest1", "evaltest2" }; |
| 5550 v8::ExtensionConfiguration extensions(2, extension_names); | 5560 v8::ExtensionConfiguration extensions(2, extension_names); |
| 5551 v8::Handle<Context> context = Context::New(&extensions); | 5561 v8::Handle<Context> context = |
| 5562 Context::New(v8::Isolate::GetCurrent(), &extensions); |
| 5552 Context::Scope lock(context); | 5563 Context::Scope lock(context); |
| 5553 v8::Handle<Value> result = Script::Compile(v8_str("UseEval1()"))->Run(); | 5564 v8::Handle<Value> result = Script::Compile(v8_str("UseEval1()"))->Run(); |
| 5554 CHECK_EQ(result, v8::Integer::New(42)); | 5565 CHECK_EQ(result, v8::Integer::New(42)); |
| 5555 result = Script::Compile(v8_str("UseEval2()"))->Run(); | 5566 result = Script::Compile(v8_str("UseEval2()"))->Run(); |
| 5556 CHECK_EQ(result, v8::Integer::New(42)); | 5567 CHECK_EQ(result, v8::Integer::New(42)); |
| 5557 } | 5568 } |
| 5558 | 5569 |
| 5559 | 5570 |
| 5560 static const char* kWithExtensionSource1 = | 5571 static const char* kWithExtensionSource1 = |
| 5561 "function UseWith1() {" | 5572 "function UseWith1() {" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 5574 " this.UseWith2 = e;" | 5585 " this.UseWith2 = e;" |
| 5575 "})()"; | 5586 "})()"; |
| 5576 | 5587 |
| 5577 | 5588 |
| 5578 THREADED_TEST(UseWithFromExtension) { | 5589 THREADED_TEST(UseWithFromExtension) { |
| 5579 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5590 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 5580 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1)); | 5591 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1)); |
| 5581 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2)); | 5592 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2)); |
| 5582 const char* extension_names[] = { "withtest1", "withtest2" }; | 5593 const char* extension_names[] = { "withtest1", "withtest2" }; |
| 5583 v8::ExtensionConfiguration extensions(2, extension_names); | 5594 v8::ExtensionConfiguration extensions(2, extension_names); |
| 5584 v8::Handle<Context> context = Context::New(&extensions); | 5595 v8::Handle<Context> context = |
| 5596 Context::New(v8::Isolate::GetCurrent(), &extensions); |
| 5585 Context::Scope lock(context); | 5597 Context::Scope lock(context); |
| 5586 v8::Handle<Value> result = Script::Compile(v8_str("UseWith1()"))->Run(); | 5598 v8::Handle<Value> result = Script::Compile(v8_str("UseWith1()"))->Run(); |
| 5587 CHECK_EQ(result, v8::Integer::New(87)); | 5599 CHECK_EQ(result, v8::Integer::New(87)); |
| 5588 result = Script::Compile(v8_str("UseWith2()"))->Run(); | 5600 result = Script::Compile(v8_str("UseWith2()"))->Run(); |
| 5589 CHECK_EQ(result, v8::Integer::New(87)); | 5601 CHECK_EQ(result, v8::Integer::New(87)); |
| 5590 } | 5602 } |
| 5591 | 5603 |
| 5592 | 5604 |
| 5593 THREADED_TEST(AutoExtensions) { | 5605 THREADED_TEST(AutoExtensions) { |
| 5594 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5606 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 5595 Extension* extension = new Extension("autotest", kSimpleExtensionSource); | 5607 Extension* extension = new Extension("autotest", kSimpleExtensionSource); |
| 5596 extension->set_auto_enable(true); | 5608 extension->set_auto_enable(true); |
| 5597 v8::RegisterExtension(extension); | 5609 v8::RegisterExtension(extension); |
| 5598 v8::Handle<Context> context = Context::New(); | 5610 v8::Handle<Context> context = |
| 5611 Context::New(v8::Isolate::GetCurrent()); |
| 5599 Context::Scope lock(context); | 5612 Context::Scope lock(context); |
| 5600 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); | 5613 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); |
| 5601 CHECK_EQ(result, v8::Integer::New(4)); | 5614 CHECK_EQ(result, v8::Integer::New(4)); |
| 5602 } | 5615 } |
| 5603 | 5616 |
| 5604 | 5617 |
| 5605 static const char* kSyntaxErrorInExtensionSource = | 5618 static const char* kSyntaxErrorInExtensionSource = |
| 5606 "["; | 5619 "["; |
| 5607 | 5620 |
| 5608 | 5621 |
| 5609 // Test that a syntax error in an extension does not cause a fatal | 5622 // Test that a syntax error in an extension does not cause a fatal |
| 5610 // error but results in an empty context. | 5623 // error but results in an empty context. |
| 5611 THREADED_TEST(SyntaxErrorExtensions) { | 5624 THREADED_TEST(SyntaxErrorExtensions) { |
| 5612 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5625 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 5613 v8::RegisterExtension(new Extension("syntaxerror", | 5626 v8::RegisterExtension(new Extension("syntaxerror", |
| 5614 kSyntaxErrorInExtensionSource)); | 5627 kSyntaxErrorInExtensionSource)); |
| 5615 const char* extension_names[] = { "syntaxerror" }; | 5628 const char* extension_names[] = { "syntaxerror" }; |
| 5616 v8::ExtensionConfiguration extensions(1, extension_names); | 5629 v8::ExtensionConfiguration extensions(1, extension_names); |
| 5617 v8::Handle<Context> context = Context::New(&extensions); | 5630 v8::Handle<Context> context = |
| 5631 Context::New(v8::Isolate::GetCurrent(), &extensions); |
| 5618 CHECK(context.IsEmpty()); | 5632 CHECK(context.IsEmpty()); |
| 5619 } | 5633 } |
| 5620 | 5634 |
| 5621 | 5635 |
| 5622 static const char* kExceptionInExtensionSource = | 5636 static const char* kExceptionInExtensionSource = |
| 5623 "throw 42"; | 5637 "throw 42"; |
| 5624 | 5638 |
| 5625 | 5639 |
| 5626 // Test that an exception when installing an extension does not cause | 5640 // Test that an exception when installing an extension does not cause |
| 5627 // a fatal error but results in an empty context. | 5641 // a fatal error but results in an empty context. |
| 5628 THREADED_TEST(ExceptionExtensions) { | 5642 THREADED_TEST(ExceptionExtensions) { |
| 5629 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5643 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 5630 v8::RegisterExtension(new Extension("exception", | 5644 v8::RegisterExtension(new Extension("exception", |
| 5631 kExceptionInExtensionSource)); | 5645 kExceptionInExtensionSource)); |
| 5632 const char* extension_names[] = { "exception" }; | 5646 const char* extension_names[] = { "exception" }; |
| 5633 v8::ExtensionConfiguration extensions(1, extension_names); | 5647 v8::ExtensionConfiguration extensions(1, extension_names); |
| 5634 v8::Handle<Context> context = Context::New(&extensions); | 5648 v8::Handle<Context> context = |
| 5649 Context::New(v8::Isolate::GetCurrent(), &extensions); |
| 5635 CHECK(context.IsEmpty()); | 5650 CHECK(context.IsEmpty()); |
| 5636 } | 5651 } |
| 5637 | 5652 |
| 5638 | 5653 |
| 5639 static const char* kNativeCallInExtensionSource = | 5654 static const char* kNativeCallInExtensionSource = |
| 5640 "function call_runtime_last_index_of(x) {" | 5655 "function call_runtime_last_index_of(x) {" |
| 5641 " return %StringLastIndexOf(x, 'bob', 10);" | 5656 " return %StringLastIndexOf(x, 'bob', 10);" |
| 5642 "}"; | 5657 "}"; |
| 5643 | 5658 |
| 5644 | 5659 |
| 5645 static const char* kNativeCallTest = | 5660 static const char* kNativeCallTest = |
| 5646 "call_runtime_last_index_of('bobbobboellebobboellebobbob');"; | 5661 "call_runtime_last_index_of('bobbobboellebobboellebobbob');"; |
| 5647 | 5662 |
| 5648 // Test that a native runtime calls are supported in extensions. | 5663 // Test that a native runtime calls are supported in extensions. |
| 5649 THREADED_TEST(NativeCallInExtensions) { | 5664 THREADED_TEST(NativeCallInExtensions) { |
| 5650 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5665 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 5651 v8::RegisterExtension(new Extension("nativecall", | 5666 v8::RegisterExtension(new Extension("nativecall", |
| 5652 kNativeCallInExtensionSource)); | 5667 kNativeCallInExtensionSource)); |
| 5653 const char* extension_names[] = { "nativecall" }; | 5668 const char* extension_names[] = { "nativecall" }; |
| 5654 v8::ExtensionConfiguration extensions(1, extension_names); | 5669 v8::ExtensionConfiguration extensions(1, extension_names); |
| 5655 v8::Handle<Context> context = Context::New(&extensions); | 5670 v8::Handle<Context> context = |
| 5671 Context::New(v8::Isolate::GetCurrent(), &extensions); |
| 5656 Context::Scope lock(context); | 5672 Context::Scope lock(context); |
| 5657 v8::Handle<Value> result = Script::Compile(v8_str(kNativeCallTest))->Run(); | 5673 v8::Handle<Value> result = Script::Compile(v8_str(kNativeCallTest))->Run(); |
| 5658 CHECK_EQ(result, v8::Integer::New(3)); | 5674 CHECK_EQ(result, v8::Integer::New(3)); |
| 5659 } | 5675 } |
| 5660 | 5676 |
| 5661 | 5677 |
| 5662 class NativeFunctionExtension : public Extension { | 5678 class NativeFunctionExtension : public Extension { |
| 5663 public: | 5679 public: |
| 5664 NativeFunctionExtension(const char* name, | 5680 NativeFunctionExtension(const char* name, |
| 5665 const char* source, | 5681 const char* source, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 5681 }; | 5697 }; |
| 5682 | 5698 |
| 5683 | 5699 |
| 5684 THREADED_TEST(NativeFunctionDeclaration) { | 5700 THREADED_TEST(NativeFunctionDeclaration) { |
| 5685 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5701 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 5686 const char* name = "nativedecl"; | 5702 const char* name = "nativedecl"; |
| 5687 v8::RegisterExtension(new NativeFunctionExtension(name, | 5703 v8::RegisterExtension(new NativeFunctionExtension(name, |
| 5688 "native function foo();")); | 5704 "native function foo();")); |
| 5689 const char* extension_names[] = { name }; | 5705 const char* extension_names[] = { name }; |
| 5690 v8::ExtensionConfiguration extensions(1, extension_names); | 5706 v8::ExtensionConfiguration extensions(1, extension_names); |
| 5691 v8::Handle<Context> context = Context::New(&extensions); | 5707 v8::Handle<Context> context = |
| 5708 Context::New(v8::Isolate::GetCurrent(), &extensions); |
| 5692 Context::Scope lock(context); | 5709 Context::Scope lock(context); |
| 5693 v8::Handle<Value> result = Script::Compile(v8_str("foo(42);"))->Run(); | 5710 v8::Handle<Value> result = Script::Compile(v8_str("foo(42);"))->Run(); |
| 5694 CHECK_EQ(result, v8::Integer::New(42)); | 5711 CHECK_EQ(result, v8::Integer::New(42)); |
| 5695 } | 5712 } |
| 5696 | 5713 |
| 5697 | 5714 |
| 5698 THREADED_TEST(NativeFunctionDeclarationError) { | 5715 THREADED_TEST(NativeFunctionDeclarationError) { |
| 5699 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5716 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 5700 const char* name = "nativedeclerr"; | 5717 const char* name = "nativedeclerr"; |
| 5701 // Syntax error in extension code. | 5718 // Syntax error in extension code. |
| 5702 v8::RegisterExtension(new NativeFunctionExtension(name, | 5719 v8::RegisterExtension(new NativeFunctionExtension(name, |
| 5703 "native\nfunction foo();")); | 5720 "native\nfunction foo();")); |
| 5704 const char* extension_names[] = { name }; | 5721 const char* extension_names[] = { name }; |
| 5705 v8::ExtensionConfiguration extensions(1, extension_names); | 5722 v8::ExtensionConfiguration extensions(1, extension_names); |
| 5706 v8::Handle<Context> context(Context::New(&extensions)); | 5723 v8::Handle<Context> context = |
| 5724 Context::New(v8::Isolate::GetCurrent(), &extensions); |
| 5707 CHECK(context.IsEmpty()); | 5725 CHECK(context.IsEmpty()); |
| 5708 } | 5726 } |
| 5709 | 5727 |
| 5710 | 5728 |
| 5711 THREADED_TEST(NativeFunctionDeclarationErrorEscape) { | 5729 THREADED_TEST(NativeFunctionDeclarationErrorEscape) { |
| 5712 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5730 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 5713 const char* name = "nativedeclerresc"; | 5731 const char* name = "nativedeclerresc"; |
| 5714 // Syntax error in extension code - escape code in "native" means that | 5732 // Syntax error in extension code - escape code in "native" means that |
| 5715 // it's not treated as a keyword. | 5733 // it's not treated as a keyword. |
| 5716 v8::RegisterExtension(new NativeFunctionExtension( | 5734 v8::RegisterExtension(new NativeFunctionExtension( |
| 5717 name, | 5735 name, |
| 5718 "nativ\\u0065 function foo();")); | 5736 "nativ\\u0065 function foo();")); |
| 5719 const char* extension_names[] = { name }; | 5737 const char* extension_names[] = { name }; |
| 5720 v8::ExtensionConfiguration extensions(1, extension_names); | 5738 v8::ExtensionConfiguration extensions(1, extension_names); |
| 5721 v8::Handle<Context> context(Context::New(&extensions)); | 5739 v8::Handle<Context> context = |
| 5740 Context::New(v8::Isolate::GetCurrent(), &extensions); |
| 5722 CHECK(context.IsEmpty()); | 5741 CHECK(context.IsEmpty()); |
| 5723 } | 5742 } |
| 5724 | 5743 |
| 5725 | 5744 |
| 5726 static void CheckDependencies(const char* name, const char* expected) { | 5745 static void CheckDependencies(const char* name, const char* expected) { |
| 5727 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5746 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 5728 v8::ExtensionConfiguration config(1, &name); | 5747 v8::ExtensionConfiguration config(1, &name); |
| 5729 LocalContext context(&config); | 5748 LocalContext context(&config); |
| 5730 CHECK_EQ(String::New(expected), context->Global()->Get(v8_str("loaded"))); | 5749 CHECK_EQ(String::New(expected), context->Global()->Get(v8_str("loaded"))); |
| 5731 } | 5750 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5851 // tests that the fatal error handler gets called. This renders V8 | 5870 // tests that the fatal error handler gets called. This renders V8 |
| 5852 // unusable and therefore this test cannot be run in parallel. | 5871 // unusable and therefore this test cannot be run in parallel. |
| 5853 TEST(ErrorReporting) { | 5872 TEST(ErrorReporting) { |
| 5854 v8::V8::SetFatalErrorHandler(StoringErrorCallback); | 5873 v8::V8::SetFatalErrorHandler(StoringErrorCallback); |
| 5855 static const char* aDeps[] = { "B" }; | 5874 static const char* aDeps[] = { "B" }; |
| 5856 v8::RegisterExtension(new Extension("A", "", 1, aDeps)); | 5875 v8::RegisterExtension(new Extension("A", "", 1, aDeps)); |
| 5857 static const char* bDeps[] = { "A" }; | 5876 static const char* bDeps[] = { "A" }; |
| 5858 v8::RegisterExtension(new Extension("B", "", 1, bDeps)); | 5877 v8::RegisterExtension(new Extension("B", "", 1, bDeps)); |
| 5859 last_location = NULL; | 5878 last_location = NULL; |
| 5860 v8::ExtensionConfiguration config(1, bDeps); | 5879 v8::ExtensionConfiguration config(1, bDeps); |
| 5861 v8::Handle<Context> context = Context::New(&config); | 5880 v8::Handle<Context> context = |
| 5881 Context::New(v8::Isolate::GetCurrent(), &config); |
| 5862 CHECK(context.IsEmpty()); | 5882 CHECK(context.IsEmpty()); |
| 5863 CHECK_NE(last_location, NULL); | 5883 CHECK_NE(last_location, NULL); |
| 5864 } | 5884 } |
| 5865 | 5885 |
| 5866 | 5886 |
| 5867 static const char* js_code_causing_huge_string_flattening = | 5887 static const char* js_code_causing_huge_string_flattening = |
| 5868 "var str = 'X';" | 5888 "var str = 'X';" |
| 5869 "for (var i = 0; i < 30; i++) {" | 5889 "for (var i = 0; i < 30; i++) {" |
| 5870 " str = str + str;" | 5890 " str = str + str;" |
| 5871 "}" | 5891 "}" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5967 | 5987 |
| 5968 THREADED_TEST(WeakReference) { | 5988 THREADED_TEST(WeakReference) { |
| 5969 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 5989 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 5970 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New(); | 5990 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New(); |
| 5971 Whammy* whammy = new Whammy(v8::Isolate::GetCurrent()); | 5991 Whammy* whammy = new Whammy(v8::Isolate::GetCurrent()); |
| 5972 templ->SetNamedPropertyHandler(WhammyPropertyGetter, | 5992 templ->SetNamedPropertyHandler(WhammyPropertyGetter, |
| 5973 0, 0, 0, 0, | 5993 0, 0, 0, 0, |
| 5974 v8::External::New(whammy)); | 5994 v8::External::New(whammy)); |
| 5975 const char* extension_list[] = { "v8/gc" }; | 5995 const char* extension_list[] = { "v8/gc" }; |
| 5976 v8::ExtensionConfiguration extensions(1, extension_list); | 5996 v8::ExtensionConfiguration extensions(1, extension_list); |
| 5977 v8::Persistent<Context> context = Context::New(&extensions); | 5997 v8::Handle<Context> context = |
| 5998 Context::New(v8::Isolate::GetCurrent(), &extensions); |
| 5978 Context::Scope context_scope(context); | 5999 Context::Scope context_scope(context); |
| 5979 | 6000 |
| 5980 v8::Handle<v8::Object> interceptor = templ->NewInstance(); | 6001 v8::Handle<v8::Object> interceptor = templ->NewInstance(); |
| 5981 context->Global()->Set(v8_str("whammy"), interceptor); | 6002 context->Global()->Set(v8_str("whammy"), interceptor); |
| 5982 const char* code = | 6003 const char* code = |
| 5983 "var last;" | 6004 "var last;" |
| 5984 "for (var i = 0; i < 10000; i++) {" | 6005 "for (var i = 0; i < 10000; i++) {" |
| 5985 " var obj = whammy.length;" | 6006 " var obj = whammy.length;" |
| 5986 " if (last) last.next = obj;" | 6007 " if (last) last.next = obj;" |
| 5987 " last = obj;" | 6008 " last = obj;" |
| 5988 "}" | 6009 "}" |
| 5989 "gc();" | 6010 "gc();" |
| 5990 "4"; | 6011 "4"; |
| 5991 v8::Handle<Value> result = CompileRun(code); | 6012 v8::Handle<Value> result = CompileRun(code); |
| 5992 CHECK_EQ(4.0, result->NumberValue()); | 6013 CHECK_EQ(4.0, result->NumberValue()); |
| 5993 delete whammy; | 6014 delete whammy; |
| 5994 context.Dispose(context->GetIsolate()); | |
| 5995 } | 6015 } |
| 5996 | 6016 |
| 5997 | 6017 |
| 5998 static void DisposeAndSetFlag(v8::Isolate* isolate, | 6018 static void DisposeAndSetFlag(v8::Isolate* isolate, |
| 5999 v8::Persistent<v8::Value> obj, | 6019 v8::Persistent<v8::Value> obj, |
| 6000 void* data) { | 6020 void* data) { |
| 6001 obj.Dispose(isolate); | 6021 obj.Dispose(isolate); |
| 6002 obj.Clear(); | 6022 obj.Clear(); |
| 6003 *(reinterpret_cast<bool*>(data)) = true; | 6023 *(reinterpret_cast<bool*>(data)) = true; |
| 6004 } | 6024 } |
| 6005 | 6025 |
| 6006 | 6026 |
| 6007 THREADED_TEST(IndependentWeakHandle) { | 6027 THREADED_TEST(IndependentWeakHandle) { |
| 6008 v8::Persistent<Context> context = Context::New(); | 6028 v8::Isolate* iso = v8::Isolate::GetCurrent(); |
| 6009 v8::Isolate* iso = context->GetIsolate(); | 6029 v8::HandleScope scope(iso); |
| 6030 v8::Handle<Context> context = Context::New(iso); |
| 6010 Context::Scope context_scope(context); | 6031 Context::Scope context_scope(context); |
| 6011 | 6032 |
| 6012 v8::Persistent<v8::Object> object_a, object_b; | 6033 v8::Persistent<v8::Object> object_a, object_b; |
| 6013 | 6034 |
| 6014 { | 6035 { |
| 6015 v8::HandleScope handle_scope(iso); | 6036 v8::HandleScope handle_scope(iso); |
| 6016 object_a = v8::Persistent<v8::Object>::New(iso, v8::Object::New()); | 6037 object_a = v8::Persistent<v8::Object>::New(iso, v8::Object::New()); |
| 6017 object_b = v8::Persistent<v8::Object>::New(iso, v8::Object::New()); | 6038 object_b = v8::Persistent<v8::Object>::New(iso, v8::Object::New()); |
| 6018 } | 6039 } |
| 6019 | 6040 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6055 v8::Persistent<v8::Value> obj, | 6076 v8::Persistent<v8::Value> obj, |
| 6056 void* data) { | 6077 void* data) { |
| 6057 obj.Dispose(isolate); | 6078 obj.Dispose(isolate); |
| 6058 obj.Clear(); | 6079 obj.Clear(); |
| 6059 *(reinterpret_cast<bool*>(data)) = true; | 6080 *(reinterpret_cast<bool*>(data)) = true; |
| 6060 InvokeMarkSweep(); | 6081 InvokeMarkSweep(); |
| 6061 } | 6082 } |
| 6062 | 6083 |
| 6063 | 6084 |
| 6064 THREADED_TEST(GCFromWeakCallbacks) { | 6085 THREADED_TEST(GCFromWeakCallbacks) { |
| 6065 v8::Persistent<Context> context = Context::New(); | 6086 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 6066 v8::Isolate* isolate = context->GetIsolate(); | 6087 v8::HandleScope scope(isolate); |
| 6088 v8::Handle<Context> context = Context::New(isolate); |
| 6067 Context::Scope context_scope(context); | 6089 Context::Scope context_scope(context); |
| 6068 | 6090 |
| 6069 static const int kNumberOfGCTypes = 2; | 6091 static const int kNumberOfGCTypes = 2; |
| 6070 v8::NearDeathCallback gc_forcing_callback[kNumberOfGCTypes] = | 6092 v8::NearDeathCallback gc_forcing_callback[kNumberOfGCTypes] = |
| 6071 {&ForceScavenge, &ForceMarkSweep}; | 6093 {&ForceScavenge, &ForceMarkSweep}; |
| 6072 | 6094 |
| 6073 typedef void (*GCInvoker)(); | 6095 typedef void (*GCInvoker)(); |
| 6074 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep}; | 6096 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep}; |
| 6075 | 6097 |
| 6076 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) { | 6098 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 6092 | 6114 |
| 6093 static void RevivingCallback(v8::Isolate* isolate, | 6115 static void RevivingCallback(v8::Isolate* isolate, |
| 6094 v8::Persistent<v8::Value> obj, | 6116 v8::Persistent<v8::Value> obj, |
| 6095 void* data) { | 6117 void* data) { |
| 6096 obj.ClearWeak(isolate); | 6118 obj.ClearWeak(isolate); |
| 6097 *(reinterpret_cast<bool*>(data)) = true; | 6119 *(reinterpret_cast<bool*>(data)) = true; |
| 6098 } | 6120 } |
| 6099 | 6121 |
| 6100 | 6122 |
| 6101 THREADED_TEST(IndependentHandleRevival) { | 6123 THREADED_TEST(IndependentHandleRevival) { |
| 6102 v8::Persistent<Context> context = Context::New(); | 6124 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 6125 v8::HandleScope scope(isolate); |
| 6126 v8::Handle<Context> context = Context::New(isolate); |
| 6103 Context::Scope context_scope(context); | 6127 Context::Scope context_scope(context); |
| 6104 v8::Isolate* isolate = context->GetIsolate(); | |
| 6105 | 6128 |
| 6106 v8::Persistent<v8::Object> object; | 6129 v8::Persistent<v8::Object> object; |
| 6107 { | 6130 { |
| 6108 v8::HandleScope handle_scope(isolate); | 6131 v8::HandleScope handle_scope(isolate); |
| 6109 object = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); | 6132 object = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); |
| 6110 object->Set(v8_str("x"), v8::Integer::New(1)); | 6133 object->Set(v8_str("x"), v8::Integer::New(1)); |
| 6111 v8::Local<String> y_str = v8_str("y"); | 6134 v8::Local<String> y_str = v8_str("y"); |
| 6112 object->Set(y_str, y_str); | 6135 object->Set(y_str, y_str); |
| 6113 } | 6136 } |
| 6114 bool revived = false; | 6137 bool revived = false; |
| (...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7149 } | 7172 } |
| 7150 | 7173 |
| 7151 | 7174 |
| 7152 // SecurityHandler can't be run twice | 7175 // SecurityHandler can't be run twice |
| 7153 TEST(SecurityHandler) { | 7176 TEST(SecurityHandler) { |
| 7154 v8::HandleScope scope0(v8::Isolate::GetCurrent()); | 7177 v8::HandleScope scope0(v8::Isolate::GetCurrent()); |
| 7155 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 7178 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
| 7156 global_template->SetAccessCheckCallbacks(NamedSecurityTestCallback, | 7179 global_template->SetAccessCheckCallbacks(NamedSecurityTestCallback, |
| 7157 IndexedSecurityTestCallback); | 7180 IndexedSecurityTestCallback); |
| 7158 // Create an environment | 7181 // Create an environment |
| 7159 v8::Persistent<Context> context0 = | 7182 v8::Handle<Context> context0 = |
| 7160 Context::New(NULL, global_template); | 7183 Context::New(v8::Isolate::GetCurrent(), NULL, global_template); |
| 7161 context0->Enter(); | 7184 context0->Enter(); |
| 7162 | 7185 |
| 7163 v8::Handle<v8::Object> global0 = context0->Global(); | 7186 v8::Handle<v8::Object> global0 = context0->Global(); |
| 7164 v8::Handle<Script> script0 = v8_compile("foo = 111"); | 7187 v8::Handle<Script> script0 = v8_compile("foo = 111"); |
| 7165 script0->Run(); | 7188 script0->Run(); |
| 7166 global0->Set(v8_str("0"), v8_num(999)); | 7189 global0->Set(v8_str("0"), v8_num(999)); |
| 7167 v8::Handle<Value> foo0 = global0->Get(v8_str("foo")); | 7190 v8::Handle<Value> foo0 = global0->Get(v8_str("foo")); |
| 7168 CHECK_EQ(111, foo0->Int32Value()); | 7191 CHECK_EQ(111, foo0->Int32Value()); |
| 7169 v8::Handle<Value> z0 = global0->Get(v8_str("0")); | 7192 v8::Handle<Value> z0 = global0->Get(v8_str("0")); |
| 7170 CHECK_EQ(999, z0->Int32Value()); | 7193 CHECK_EQ(999, z0->Int32Value()); |
| 7171 | 7194 |
| 7172 // Create another environment, should fail security checks. | 7195 // Create another environment, should fail security checks. |
| 7173 v8::HandleScope scope1(v8::Isolate::GetCurrent()); | 7196 v8::HandleScope scope1(v8::Isolate::GetCurrent()); |
| 7174 | 7197 |
| 7175 v8::Persistent<Context> context1 = | 7198 v8::Handle<Context> context1 = |
| 7176 Context::New(NULL, global_template); | 7199 Context::New(v8::Isolate::GetCurrent(), NULL, global_template); |
| 7177 context1->Enter(); | 7200 context1->Enter(); |
| 7178 | 7201 |
| 7179 v8::Handle<v8::Object> global1 = context1->Global(); | 7202 v8::Handle<v8::Object> global1 = context1->Global(); |
| 7180 global1->Set(v8_str("othercontext"), global0); | 7203 global1->Set(v8_str("othercontext"), global0); |
| 7181 // This set will fail the security check. | 7204 // This set will fail the security check. |
| 7182 v8::Handle<Script> script1 = | 7205 v8::Handle<Script> script1 = |
| 7183 v8_compile("othercontext.foo = 222; othercontext[0] = 888;"); | 7206 v8_compile("othercontext.foo = 222; othercontext[0] = 888;"); |
| 7184 script1->Run(); | 7207 script1->Run(); |
| 7185 // This read will pass the security check. | 7208 // This read will pass the security check. |
| 7186 v8::Handle<Value> foo1 = global0->Get(v8_str("foo")); | 7209 v8::Handle<Value> foo1 = global0->Get(v8_str("foo")); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 7198 v8::Handle<Script> script2 = | 7221 v8::Handle<Script> script2 = |
| 7199 v8_compile("othercontext.foo = 333; othercontext[0] = 888;"); | 7222 v8_compile("othercontext.foo = 333; othercontext[0] = 888;"); |
| 7200 script2->Run(); | 7223 script2->Run(); |
| 7201 v8::Handle<Value> foo2 = global0->Get(v8_str("foo")); | 7224 v8::Handle<Value> foo2 = global0->Get(v8_str("foo")); |
| 7202 CHECK_EQ(333, foo2->Int32Value()); | 7225 CHECK_EQ(333, foo2->Int32Value()); |
| 7203 v8::Handle<Value> z2 = global0->Get(v8_str("0")); | 7226 v8::Handle<Value> z2 = global0->Get(v8_str("0")); |
| 7204 CHECK_EQ(888, z2->Int32Value()); | 7227 CHECK_EQ(888, z2->Int32Value()); |
| 7205 } | 7228 } |
| 7206 | 7229 |
| 7207 context1->Exit(); | 7230 context1->Exit(); |
| 7208 context1.Dispose(context1->GetIsolate()); | |
| 7209 | |
| 7210 context0->Exit(); | 7231 context0->Exit(); |
| 7211 context0.Dispose(context0->GetIsolate()); | |
| 7212 } | 7232 } |
| 7213 | 7233 |
| 7214 | 7234 |
| 7215 THREADED_TEST(SecurityChecks) { | 7235 THREADED_TEST(SecurityChecks) { |
| 7216 LocalContext env1; | 7236 LocalContext env1; |
| 7217 v8::HandleScope handle_scope(env1->GetIsolate()); | 7237 v8::HandleScope handle_scope(env1->GetIsolate()); |
| 7218 v8::Persistent<Context> env2 = Context::New(); | 7238 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); |
| 7219 | 7239 |
| 7220 Local<Value> foo = v8_str("foo"); | 7240 Local<Value> foo = v8_str("foo"); |
| 7221 Local<Value> bar = v8_str("bar"); | 7241 Local<Value> bar = v8_str("bar"); |
| 7222 | 7242 |
| 7223 // Set to the same domain. | 7243 // Set to the same domain. |
| 7224 env1->SetSecurityToken(foo); | 7244 env1->SetSecurityToken(foo); |
| 7225 | 7245 |
| 7226 // Create a function in env1. | 7246 // Create a function in env1. |
| 7227 Script::Compile(v8_str("spy=function(){return spy;}"))->Run(); | 7247 Script::Compile(v8_str("spy=function(){return spy;}"))->Run(); |
| 7228 Local<Value> spy = env1->Global()->Get(v8_str("spy")); | 7248 Local<Value> spy = env1->Global()->Get(v8_str("spy")); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 7244 | 7264 |
| 7245 { | 7265 { |
| 7246 env2->SetSecurityToken(bar); | 7266 env2->SetSecurityToken(bar); |
| 7247 Context::Scope scope_env2(env2); | 7267 Context::Scope scope_env2(env2); |
| 7248 | 7268 |
| 7249 // Call cross_domain_call, it should throw an exception | 7269 // Call cross_domain_call, it should throw an exception |
| 7250 v8::TryCatch try_catch; | 7270 v8::TryCatch try_catch; |
| 7251 Function::Cast(*spy2)->Call(env2->Global(), 0, NULL); | 7271 Function::Cast(*spy2)->Call(env2->Global(), 0, NULL); |
| 7252 CHECK(try_catch.HasCaught()); | 7272 CHECK(try_catch.HasCaught()); |
| 7253 } | 7273 } |
| 7254 | |
| 7255 env2.Dispose(env2->GetIsolate()); | |
| 7256 } | 7274 } |
| 7257 | 7275 |
| 7258 | 7276 |
| 7259 // Regression test case for issue 1183439. | 7277 // Regression test case for issue 1183439. |
| 7260 THREADED_TEST(SecurityChecksForPrototypeChain) { | 7278 THREADED_TEST(SecurityChecksForPrototypeChain) { |
| 7261 LocalContext current; | 7279 LocalContext current; |
| 7262 v8::HandleScope scope(current->GetIsolate()); | 7280 v8::HandleScope scope(current->GetIsolate()); |
| 7263 v8::Persistent<Context> other = Context::New(); | 7281 v8::Handle<Context> other = Context::New(current->GetIsolate()); |
| 7264 | 7282 |
| 7265 // Change context to be able to get to the Object function in the | 7283 // Change context to be able to get to the Object function in the |
| 7266 // other context without hitting the security checks. | 7284 // other context without hitting the security checks. |
| 7267 v8::Local<Value> other_object; | 7285 v8::Local<Value> other_object; |
| 7268 { Context::Scope scope(other); | 7286 { Context::Scope scope(other); |
| 7269 other_object = other->Global()->Get(v8_str("Object")); | 7287 other_object = other->Global()->Get(v8_str("Object")); |
| 7270 other->Global()->Set(v8_num(42), v8_num(87)); | 7288 other->Global()->Set(v8_num(42), v8_num(87)); |
| 7271 } | 7289 } |
| 7272 | 7290 |
| 7273 current->Global()->Set(v8_str("other"), other->Global()); | 7291 current->Global()->Set(v8_str("other"), other->Global()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7314 // Try to read the properties from f and make sure that the access | 7332 // Try to read the properties from f and make sure that the access |
| 7315 // gets stopped by the security checks on the other global object. | 7333 // gets stopped by the security checks on the other global object. |
| 7316 Local<Script> access_f2 = v8_compile("f.foo"); | 7334 Local<Script> access_f2 = v8_compile("f.foo"); |
| 7317 Local<Script> access_f3 = v8_compile("f[99]"); | 7335 Local<Script> access_f3 = v8_compile("f[99]"); |
| 7318 for (int k = 0; k < 5; k++) { | 7336 for (int k = 0; k < 5; k++) { |
| 7319 CHECK(!access_f2->Run()->Equals(v8_num(100))); | 7337 CHECK(!access_f2->Run()->Equals(v8_num(100))); |
| 7320 CHECK(access_f2->Run()->IsUndefined()); | 7338 CHECK(access_f2->Run()->IsUndefined()); |
| 7321 CHECK(!access_f3->Run()->Equals(v8_num(101))); | 7339 CHECK(!access_f3->Run()->Equals(v8_num(101))); |
| 7322 CHECK(access_f3->Run()->IsUndefined()); | 7340 CHECK(access_f3->Run()->IsUndefined()); |
| 7323 } | 7341 } |
| 7324 other.Dispose(other->GetIsolate()); | |
| 7325 } | 7342 } |
| 7326 | 7343 |
| 7327 | 7344 |
| 7328 THREADED_TEST(CrossDomainDelete) { | 7345 THREADED_TEST(CrossDomainDelete) { |
| 7329 LocalContext env1; | 7346 LocalContext env1; |
| 7330 v8::HandleScope handle_scope(env1->GetIsolate()); | 7347 v8::HandleScope handle_scope(env1->GetIsolate()); |
| 7331 v8::Persistent<Context> env2 = Context::New(); | 7348 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); |
| 7332 | 7349 |
| 7333 Local<Value> foo = v8_str("foo"); | 7350 Local<Value> foo = v8_str("foo"); |
| 7334 Local<Value> bar = v8_str("bar"); | 7351 Local<Value> bar = v8_str("bar"); |
| 7335 | 7352 |
| 7336 // Set to the same domain. | 7353 // Set to the same domain. |
| 7337 env1->SetSecurityToken(foo); | 7354 env1->SetSecurityToken(foo); |
| 7338 env2->SetSecurityToken(foo); | 7355 env2->SetSecurityToken(foo); |
| 7339 | 7356 |
| 7340 env1->Global()->Set(v8_str("prop"), v8_num(3)); | 7357 env1->Global()->Set(v8_str("prop"), v8_num(3)); |
| 7341 env2->Global()->Set(v8_str("env1"), env1->Global()); | 7358 env2->Global()->Set(v8_str("env1"), env1->Global()); |
| 7342 | 7359 |
| 7343 // Change env2 to a different domain and delete env1.prop. | 7360 // Change env2 to a different domain and delete env1.prop. |
| 7344 env2->SetSecurityToken(bar); | 7361 env2->SetSecurityToken(bar); |
| 7345 { | 7362 { |
| 7346 Context::Scope scope_env2(env2); | 7363 Context::Scope scope_env2(env2); |
| 7347 Local<Value> result = | 7364 Local<Value> result = |
| 7348 Script::Compile(v8_str("delete env1.prop"))->Run(); | 7365 Script::Compile(v8_str("delete env1.prop"))->Run(); |
| 7349 CHECK(result->IsFalse()); | 7366 CHECK(result->IsFalse()); |
| 7350 } | 7367 } |
| 7351 | 7368 |
| 7352 // Check that env1.prop still exists. | 7369 // Check that env1.prop still exists. |
| 7353 Local<Value> v = env1->Global()->Get(v8_str("prop")); | 7370 Local<Value> v = env1->Global()->Get(v8_str("prop")); |
| 7354 CHECK(v->IsNumber()); | 7371 CHECK(v->IsNumber()); |
| 7355 CHECK_EQ(3, v->Int32Value()); | 7372 CHECK_EQ(3, v->Int32Value()); |
| 7356 | |
| 7357 env2.Dispose(env2->GetIsolate()); | |
| 7358 } | 7373 } |
| 7359 | 7374 |
| 7360 | 7375 |
| 7361 THREADED_TEST(CrossDomainIsPropertyEnumerable) { | 7376 THREADED_TEST(CrossDomainIsPropertyEnumerable) { |
| 7362 LocalContext env1; | 7377 LocalContext env1; |
| 7363 v8::HandleScope handle_scope(env1->GetIsolate()); | 7378 v8::HandleScope handle_scope(env1->GetIsolate()); |
| 7364 v8::Persistent<Context> env2 = Context::New(); | 7379 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); |
| 7365 | 7380 |
| 7366 Local<Value> foo = v8_str("foo"); | 7381 Local<Value> foo = v8_str("foo"); |
| 7367 Local<Value> bar = v8_str("bar"); | 7382 Local<Value> bar = v8_str("bar"); |
| 7368 | 7383 |
| 7369 // Set to the same domain. | 7384 // Set to the same domain. |
| 7370 env1->SetSecurityToken(foo); | 7385 env1->SetSecurityToken(foo); |
| 7371 env2->SetSecurityToken(foo); | 7386 env2->SetSecurityToken(foo); |
| 7372 | 7387 |
| 7373 env1->Global()->Set(v8_str("prop"), v8_num(3)); | 7388 env1->Global()->Set(v8_str("prop"), v8_num(3)); |
| 7374 env2->Global()->Set(v8_str("env1"), env1->Global()); | 7389 env2->Global()->Set(v8_str("env1"), env1->Global()); |
| 7375 | 7390 |
| 7376 // env1.prop is enumerable in env2. | 7391 // env1.prop is enumerable in env2. |
| 7377 Local<String> test = v8_str("propertyIsEnumerable.call(env1, 'prop')"); | 7392 Local<String> test = v8_str("propertyIsEnumerable.call(env1, 'prop')"); |
| 7378 { | 7393 { |
| 7379 Context::Scope scope_env2(env2); | 7394 Context::Scope scope_env2(env2); |
| 7380 Local<Value> result = Script::Compile(test)->Run(); | 7395 Local<Value> result = Script::Compile(test)->Run(); |
| 7381 CHECK(result->IsTrue()); | 7396 CHECK(result->IsTrue()); |
| 7382 } | 7397 } |
| 7383 | 7398 |
| 7384 // Change env2 to a different domain and test again. | 7399 // Change env2 to a different domain and test again. |
| 7385 env2->SetSecurityToken(bar); | 7400 env2->SetSecurityToken(bar); |
| 7386 { | 7401 { |
| 7387 Context::Scope scope_env2(env2); | 7402 Context::Scope scope_env2(env2); |
| 7388 Local<Value> result = Script::Compile(test)->Run(); | 7403 Local<Value> result = Script::Compile(test)->Run(); |
| 7389 CHECK(result->IsFalse()); | 7404 CHECK(result->IsFalse()); |
| 7390 } | 7405 } |
| 7391 | |
| 7392 env2.Dispose(env2->GetIsolate()); | |
| 7393 } | 7406 } |
| 7394 | 7407 |
| 7395 | 7408 |
| 7396 THREADED_TEST(CrossDomainForIn) { | 7409 THREADED_TEST(CrossDomainForIn) { |
| 7397 LocalContext env1; | 7410 LocalContext env1; |
| 7398 v8::HandleScope handle_scope(env1->GetIsolate()); | 7411 v8::HandleScope handle_scope(env1->GetIsolate()); |
| 7399 v8::Persistent<Context> env2 = Context::New(); | 7412 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); |
| 7400 | 7413 |
| 7401 Local<Value> foo = v8_str("foo"); | 7414 Local<Value> foo = v8_str("foo"); |
| 7402 Local<Value> bar = v8_str("bar"); | 7415 Local<Value> bar = v8_str("bar"); |
| 7403 | 7416 |
| 7404 // Set to the same domain. | 7417 // Set to the same domain. |
| 7405 env1->SetSecurityToken(foo); | 7418 env1->SetSecurityToken(foo); |
| 7406 env2->SetSecurityToken(foo); | 7419 env2->SetSecurityToken(foo); |
| 7407 | 7420 |
| 7408 env1->Global()->Set(v8_str("prop"), v8_num(3)); | 7421 env1->Global()->Set(v8_str("prop"), v8_num(3)); |
| 7409 env2->Global()->Set(v8_str("env1"), env1->Global()); | 7422 env2->Global()->Set(v8_str("env1"), env1->Global()); |
| 7410 | 7423 |
| 7411 // Change env2 to a different domain and set env1's global object | 7424 // Change env2 to a different domain and set env1's global object |
| 7412 // as the __proto__ of an object in env2 and enumerate properties | 7425 // as the __proto__ of an object in env2 and enumerate properties |
| 7413 // in for-in. It shouldn't enumerate properties on env1's global | 7426 // in for-in. It shouldn't enumerate properties on env1's global |
| 7414 // object. | 7427 // object. |
| 7415 env2->SetSecurityToken(bar); | 7428 env2->SetSecurityToken(bar); |
| 7416 { | 7429 { |
| 7417 Context::Scope scope_env2(env2); | 7430 Context::Scope scope_env2(env2); |
| 7418 Local<Value> result = | 7431 Local<Value> result = |
| 7419 CompileRun("(function(){var obj = {'__proto__':env1};" | 7432 CompileRun("(function(){var obj = {'__proto__':env1};" |
| 7420 "for (var p in obj)" | 7433 "for (var p in obj)" |
| 7421 " if (p == 'prop') return false;" | 7434 " if (p == 'prop') return false;" |
| 7422 "return true;})()"); | 7435 "return true;})()"); |
| 7423 CHECK(result->IsTrue()); | 7436 CHECK(result->IsTrue()); |
| 7424 } | 7437 } |
| 7425 env2.Dispose(env2->GetIsolate()); | |
| 7426 } | 7438 } |
| 7427 | 7439 |
| 7428 | 7440 |
| 7429 TEST(ContextDetachGlobal) { | 7441 TEST(ContextDetachGlobal) { |
| 7430 LocalContext env1; | 7442 LocalContext env1; |
| 7431 v8::HandleScope handle_scope(env1->GetIsolate()); | 7443 v8::HandleScope handle_scope(env1->GetIsolate()); |
| 7432 v8::Persistent<Context> env2 = Context::New(); | 7444 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); |
| 7433 | 7445 |
| 7434 Local<v8::Object> global1 = env1->Global(); | 7446 Local<v8::Object> global1 = env1->Global(); |
| 7435 | 7447 |
| 7436 Local<Value> foo = v8_str("foo"); | 7448 Local<Value> foo = v8_str("foo"); |
| 7437 | 7449 |
| 7438 // Set to the same domain. | 7450 // Set to the same domain. |
| 7439 env1->SetSecurityToken(foo); | 7451 env1->SetSecurityToken(foo); |
| 7440 env2->SetSecurityToken(foo); | 7452 env2->SetSecurityToken(foo); |
| 7441 | 7453 |
| 7442 // Enter env2 | 7454 // Enter env2 |
| 7443 env2->Enter(); | 7455 env2->Enter(); |
| 7444 | 7456 |
| 7445 // Create a function in env2 and add a reference to it in env1. | 7457 // Create a function in env2 and add a reference to it in env1. |
| 7446 Local<v8::Object> global2 = env2->Global(); | 7458 Local<v8::Object> global2 = env2->Global(); |
| 7447 global2->Set(v8_str("prop"), v8::Integer::New(1)); | 7459 global2->Set(v8_str("prop"), v8::Integer::New(1)); |
| 7448 CompileRun("function getProp() {return prop;}"); | 7460 CompileRun("function getProp() {return prop;}"); |
| 7449 | 7461 |
| 7450 env1->Global()->Set(v8_str("getProp"), | 7462 env1->Global()->Set(v8_str("getProp"), |
| 7451 global2->Get(v8_str("getProp"))); | 7463 global2->Get(v8_str("getProp"))); |
| 7452 | 7464 |
| 7453 // Detach env2's global, and reuse the global object of env2 | 7465 // Detach env2's global, and reuse the global object of env2 |
| 7454 env2->Exit(); | 7466 env2->Exit(); |
| 7455 env2->DetachGlobal(); | 7467 env2->DetachGlobal(); |
| 7456 // env2 has a new global object. | 7468 // env2 has a new global object. |
| 7457 CHECK(!env2->Global()->Equals(global2)); | 7469 CHECK(!env2->Global()->Equals(global2)); |
| 7458 | 7470 |
| 7459 v8::Persistent<Context> env3 = | 7471 v8::Handle<Context> env3 = Context::New(env1->GetIsolate(), |
| 7460 Context::New(0, v8::Handle<v8::ObjectTemplate>(), global2); | 7472 0, |
| 7473 v8::Handle<v8::ObjectTemplate>(), |
| 7474 global2); |
| 7461 env3->SetSecurityToken(v8_str("bar")); | 7475 env3->SetSecurityToken(v8_str("bar")); |
| 7462 env3->Enter(); | 7476 env3->Enter(); |
| 7463 | 7477 |
| 7464 Local<v8::Object> global3 = env3->Global(); | 7478 Local<v8::Object> global3 = env3->Global(); |
| 7465 CHECK_EQ(global2, global3); | 7479 CHECK_EQ(global2, global3); |
| 7466 CHECK(global3->Get(v8_str("prop"))->IsUndefined()); | 7480 CHECK(global3->Get(v8_str("prop"))->IsUndefined()); |
| 7467 CHECK(global3->Get(v8_str("getProp"))->IsUndefined()); | 7481 CHECK(global3->Get(v8_str("getProp"))->IsUndefined()); |
| 7468 global3->Set(v8_str("prop"), v8::Integer::New(-1)); | 7482 global3->Set(v8_str("prop"), v8::Integer::New(-1)); |
| 7469 global3->Set(v8_str("prop2"), v8::Integer::New(2)); | 7483 global3->Set(v8_str("prop2"), v8::Integer::New(2)); |
| 7470 env3->Exit(); | 7484 env3->Exit(); |
| 7471 | 7485 |
| 7472 // Call getProp in env1, and it should return the value 1 | 7486 // Call getProp in env1, and it should return the value 1 |
| 7473 { | 7487 { |
| 7474 Local<Value> get_prop = global1->Get(v8_str("getProp")); | 7488 Local<Value> get_prop = global1->Get(v8_str("getProp")); |
| 7475 CHECK(get_prop->IsFunction()); | 7489 CHECK(get_prop->IsFunction()); |
| 7476 v8::TryCatch try_catch; | 7490 v8::TryCatch try_catch; |
| 7477 Local<Value> r = Function::Cast(*get_prop)->Call(global1, 0, NULL); | 7491 Local<Value> r = Function::Cast(*get_prop)->Call(global1, 0, NULL); |
| 7478 CHECK(!try_catch.HasCaught()); | 7492 CHECK(!try_catch.HasCaught()); |
| 7479 CHECK_EQ(1, r->Int32Value()); | 7493 CHECK_EQ(1, r->Int32Value()); |
| 7480 } | 7494 } |
| 7481 | 7495 |
| 7482 // Check that env3 is not accessible from env1 | 7496 // Check that env3 is not accessible from env1 |
| 7483 { | 7497 { |
| 7484 Local<Value> r = global3->Get(v8_str("prop2")); | 7498 Local<Value> r = global3->Get(v8_str("prop2")); |
| 7485 CHECK(r->IsUndefined()); | 7499 CHECK(r->IsUndefined()); |
| 7486 } | 7500 } |
| 7487 | |
| 7488 env2.Dispose(env2->GetIsolate()); | |
| 7489 env3.Dispose(env3->GetIsolate()); | |
| 7490 } | 7501 } |
| 7491 | 7502 |
| 7492 | 7503 |
| 7493 TEST(DetachAndReattachGlobal) { | 7504 TEST(DetachAndReattachGlobal) { |
| 7494 LocalContext env1; | 7505 LocalContext env1; |
| 7495 v8::HandleScope scope(env1->GetIsolate()); | 7506 v8::HandleScope scope(env1->GetIsolate()); |
| 7496 | 7507 |
| 7497 // Create second environment. | 7508 // Create second environment. |
| 7498 v8::Persistent<Context> env2 = Context::New(); | 7509 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); |
| 7499 | 7510 |
| 7500 Local<Value> foo = v8_str("foo"); | 7511 Local<Value> foo = v8_str("foo"); |
| 7501 | 7512 |
| 7502 // Set same security token for env1 and env2. | 7513 // Set same security token for env1 and env2. |
| 7503 env1->SetSecurityToken(foo); | 7514 env1->SetSecurityToken(foo); |
| 7504 env2->SetSecurityToken(foo); | 7515 env2->SetSecurityToken(foo); |
| 7505 | 7516 |
| 7506 // Create a property on the global object in env2. | 7517 // Create a property on the global object in env2. |
| 7507 { | 7518 { |
| 7508 v8::Context::Scope scope(env2); | 7519 v8::Context::Scope scope(env2); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 7520 // Hold on to global from env2 and detach global from env2. | 7531 // Hold on to global from env2 and detach global from env2. |
| 7521 Local<v8::Object> global2 = env2->Global(); | 7532 Local<v8::Object> global2 = env2->Global(); |
| 7522 env2->DetachGlobal(); | 7533 env2->DetachGlobal(); |
| 7523 | 7534 |
| 7524 // Check that the global has been detached. No other.p property can | 7535 // Check that the global has been detached. No other.p property can |
| 7525 // be found. | 7536 // be found. |
| 7526 result = CompileRun("other.p"); | 7537 result = CompileRun("other.p"); |
| 7527 CHECK(result->IsUndefined()); | 7538 CHECK(result->IsUndefined()); |
| 7528 | 7539 |
| 7529 // Reuse global2 for env3. | 7540 // Reuse global2 for env3. |
| 7530 v8::Persistent<Context> env3 = | 7541 v8::Handle<Context> env3 = Context::New(env1->GetIsolate(), |
| 7531 Context::New(0, v8::Handle<v8::ObjectTemplate>(), global2); | 7542 0, |
| 7543 v8::Handle<v8::ObjectTemplate>(), |
| 7544 global2); |
| 7532 CHECK_EQ(global2, env3->Global()); | 7545 CHECK_EQ(global2, env3->Global()); |
| 7533 | 7546 |
| 7534 // Start by using the same security token for env3 as for env1 and env2. | 7547 // Start by using the same security token for env3 as for env1 and env2. |
| 7535 env3->SetSecurityToken(foo); | 7548 env3->SetSecurityToken(foo); |
| 7536 | 7549 |
| 7537 // Create a property on the global object in env3. | 7550 // Create a property on the global object in env3. |
| 7538 { | 7551 { |
| 7539 v8::Context::Scope scope(env3); | 7552 v8::Context::Scope scope(env3); |
| 7540 env3->Global()->Set(v8_str("p"), v8::Integer::New(24)); | 7553 env3->Global()->Set(v8_str("p"), v8::Integer::New(24)); |
| 7541 } | 7554 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 7556 | 7569 |
| 7557 // Detach the global for env3 and reattach it to env2. | 7570 // Detach the global for env3 and reattach it to env2. |
| 7558 env3->DetachGlobal(); | 7571 env3->DetachGlobal(); |
| 7559 env2->ReattachGlobal(global2); | 7572 env2->ReattachGlobal(global2); |
| 7560 | 7573 |
| 7561 // Check that we have access to other.p again in env1. |other| is now | 7574 // Check that we have access to other.p again in env1. |other| is now |
| 7562 // the global object for env2 which has the same security token as env1. | 7575 // the global object for env2 which has the same security token as env1. |
| 7563 result = CompileRun("other.p"); | 7576 result = CompileRun("other.p"); |
| 7564 CHECK(result->IsInt32()); | 7577 CHECK(result->IsInt32()); |
| 7565 CHECK_EQ(42, result->Int32Value()); | 7578 CHECK_EQ(42, result->Int32Value()); |
| 7566 | |
| 7567 env2.Dispose(env2->GetIsolate()); | |
| 7568 env3.Dispose(env3->GetIsolate()); | |
| 7569 } | 7579 } |
| 7570 | 7580 |
| 7571 | 7581 |
| 7572 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false }; | 7582 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false }; |
| 7573 static bool NamedAccessBlocker(Local<v8::Object> global, | 7583 static bool NamedAccessBlocker(Local<v8::Object> global, |
| 7574 Local<Value> name, | 7584 Local<Value> name, |
| 7575 v8::AccessType type, | 7585 v8::AccessType type, |
| 7576 Local<Value> data) { | 7586 Local<Value> data) { |
| 7577 return Context::GetCurrent()->Global()->Equals(global) || | 7587 return Context::GetCurrent()->Global()->Equals(global) || |
| 7578 allowed_access_type[type]; | 7588 allowed_access_type[type]; |
| (...skipping 2048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9627 | 9637 |
| 9628 | 9638 |
| 9629 // Below go several tests which verify that JITing for various | 9639 // Below go several tests which verify that JITing for various |
| 9630 // configurations of interceptor and explicit fields works fine | 9640 // configurations of interceptor and explicit fields works fine |
| 9631 // (those cases are special cased to get better performance). | 9641 // (those cases are special cased to get better performance). |
| 9632 | 9642 |
| 9633 static v8::Handle<Value> InterceptorLoadXICGetter(Local<String> name, | 9643 static v8::Handle<Value> InterceptorLoadXICGetter(Local<String> name, |
| 9634 const AccessorInfo& info) { | 9644 const AccessorInfo& info) { |
| 9635 ApiTestFuzzer::Fuzz(); | 9645 ApiTestFuzzer::Fuzz(); |
| 9636 return v8_str("x")->Equals(name) | 9646 return v8_str("x")->Equals(name) |
| 9637 ? v8::Integer::New(42) : v8::Handle<v8::Value>(); | 9647 ? v8::Handle<v8::Value>(v8::Integer::New(42)) : v8::Handle<v8::Value>(); |
| 9638 } | 9648 } |
| 9639 | 9649 |
| 9640 | 9650 |
| 9641 THREADED_TEST(InterceptorLoadICWithFieldOnHolder) { | 9651 THREADED_TEST(InterceptorLoadICWithFieldOnHolder) { |
| 9642 CheckInterceptorLoadIC(InterceptorLoadXICGetter, | 9652 CheckInterceptorLoadIC(InterceptorLoadXICGetter, |
| 9643 "var result = 0;" | 9653 "var result = 0;" |
| 9644 "o.y = 239;" | 9654 "o.y = 239;" |
| 9645 "for (var i = 0; i < 1000; i++) {" | 9655 "for (var i = 0; i < 1000; i++) {" |
| 9646 " result = o.y;" | 9656 " result = o.y;" |
| 9647 "}", | 9657 "}", |
| (...skipping 2997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12645 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 12655 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 12646 | 12656 |
| 12647 // Create an environment with access check to the global object disabled by | 12657 // Create an environment with access check to the global object disabled by |
| 12648 // default. | 12658 // default. |
| 12649 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 12659 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
| 12650 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker, | 12660 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker, |
| 12651 IndexedGetAccessBlocker, | 12661 IndexedGetAccessBlocker, |
| 12652 v8::Handle<v8::Value>(), | 12662 v8::Handle<v8::Value>(), |
| 12653 false); | 12663 false); |
| 12654 v8::Persistent<Context> context = Context::New(NULL, global_template); | 12664 v8::Persistent<Context> context = Context::New(NULL, global_template); |
| 12655 Context::Scope context_scope(context); | 12665 Context::Scope context_scope(v8::Isolate::GetCurrent(), context); |
| 12656 | 12666 |
| 12657 // Set up a property and a number of functions. | 12667 // Set up a property and a number of functions. |
| 12658 context->Global()->Set(v8_str("a"), v8_num(1)); | 12668 context->Global()->Set(v8_str("a"), v8_num(1)); |
| 12659 CompileRun("function f1() {return a;}" | 12669 CompileRun("function f1() {return a;}" |
| 12660 "function f2() {return a;}" | 12670 "function f2() {return a;}" |
| 12661 "function g1() {return h();}" | 12671 "function g1() {return h();}" |
| 12662 "function g2() {return h();}" | 12672 "function g2() {return h();}" |
| 12663 "function h() {return 1;}"); | 12673 "function h() {return 1;}"); |
| 12664 Local<Function> f1 = | 12674 Local<Function> f1 = |
| 12665 Local<Function>::Cast(context->Global()->Get(v8_str("f1"))); | 12675 Local<Function>::Cast(context->Global()->Get(v8_str("f1"))); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12726 | 12736 |
| 12727 // Create an environment with access check to the global object disabled by | 12737 // Create an environment with access check to the global object disabled by |
| 12728 // default. When the registered access checker will block access to properties | 12738 // default. When the registered access checker will block access to properties |
| 12729 // a and h. | 12739 // a and h. |
| 12730 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 12740 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
| 12731 global_template->SetAccessCheckCallbacks(NamedGetAccessBlockAandH, | 12741 global_template->SetAccessCheckCallbacks(NamedGetAccessBlockAandH, |
| 12732 IndexedGetAccessBlocker, | 12742 IndexedGetAccessBlocker, |
| 12733 v8::Handle<v8::Value>(), | 12743 v8::Handle<v8::Value>(), |
| 12734 false); | 12744 false); |
| 12735 v8::Persistent<Context> context = Context::New(NULL, global_template); | 12745 v8::Persistent<Context> context = Context::New(NULL, global_template); |
| 12736 Context::Scope context_scope(context); | 12746 Context::Scope context_scope(v8::Isolate::GetCurrent(), context); |
| 12737 | 12747 |
| 12738 // Set up a property and a number of functions. | 12748 // Set up a property and a number of functions. |
| 12739 context->Global()->Set(v8_str("a"), v8_num(1)); | 12749 context->Global()->Set(v8_str("a"), v8_num(1)); |
| 12740 static const char* source = "function f1() {return a;}" | 12750 static const char* source = "function f1() {return a;}" |
| 12741 "function f2() {return a;}" | 12751 "function f2() {return a;}" |
| 12742 "function g1() {return h();}" | 12752 "function g1() {return h();}" |
| 12743 "function g2() {return h();}" | 12753 "function g2() {return h();}" |
| 12744 "function h() {return 1;}"; | 12754 "function h() {return 1;}"; |
| 12745 | 12755 |
| 12746 CompileRun(source); | 12756 CompileRun(source); |
| (...skipping 4098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16845 CHECK_NE(last_message, NULL); | 16855 CHECK_NE(last_message, NULL); |
| 16846 } | 16856 } |
| 16847 | 16857 |
| 16848 TEST(RunTwoIsolatesOnSingleThread) { | 16858 TEST(RunTwoIsolatesOnSingleThread) { |
| 16849 // Run isolate 1. | 16859 // Run isolate 1. |
| 16850 v8::Isolate* isolate1 = v8::Isolate::New(); | 16860 v8::Isolate* isolate1 = v8::Isolate::New(); |
| 16851 isolate1->Enter(); | 16861 isolate1->Enter(); |
| 16852 v8::Persistent<v8::Context> context1 = v8::Context::New(); | 16862 v8::Persistent<v8::Context> context1 = v8::Context::New(); |
| 16853 | 16863 |
| 16854 { | 16864 { |
| 16855 v8::Context::Scope cscope(context1); | |
| 16856 v8::HandleScope scope(isolate1); | 16865 v8::HandleScope scope(isolate1); |
| 16866 v8::Context::Scope cscope(isolate1, context1); |
| 16857 // Run something in new isolate. | 16867 // Run something in new isolate. |
| 16858 CompileRun("var foo = 'isolate 1';"); | 16868 CompileRun("var foo = 'isolate 1';"); |
| 16859 ExpectString("function f() { return foo; }; f()", "isolate 1"); | 16869 ExpectString("function f() { return foo; }; f()", "isolate 1"); |
| 16860 } | 16870 } |
| 16861 | 16871 |
| 16862 // Run isolate 2. | 16872 // Run isolate 2. |
| 16863 v8::Isolate* isolate2 = v8::Isolate::New(); | 16873 v8::Isolate* isolate2 = v8::Isolate::New(); |
| 16864 v8::Persistent<v8::Context> context2; | 16874 v8::Persistent<v8::Context> context2; |
| 16865 | 16875 |
| 16866 { | 16876 { |
| 16867 v8::Isolate::Scope iscope(isolate2); | 16877 v8::Isolate::Scope iscope(isolate2); |
| 16868 context2 = v8::Context::New(); | 16878 context2 = v8::Context::New(); |
| 16869 v8::Context::Scope cscope(context2); | |
| 16870 v8::HandleScope scope(isolate2); | 16879 v8::HandleScope scope(isolate2); |
| 16880 v8::Context::Scope cscope(isolate2, context2); |
| 16871 | 16881 |
| 16872 // Run something in new isolate. | 16882 // Run something in new isolate. |
| 16873 CompileRun("var foo = 'isolate 2';"); | 16883 CompileRun("var foo = 'isolate 2';"); |
| 16874 ExpectString("function f() { return foo; }; f()", "isolate 2"); | 16884 ExpectString("function f() { return foo; }; f()", "isolate 2"); |
| 16875 } | 16885 } |
| 16876 | 16886 |
| 16877 { | 16887 { |
| 16878 v8::Context::Scope cscope(context1); | |
| 16879 v8::HandleScope scope(isolate1); | 16888 v8::HandleScope scope(isolate1); |
| 16889 v8::Context::Scope cscope(isolate1, context1); |
| 16880 // Now again in isolate 1 | 16890 // Now again in isolate 1 |
| 16881 ExpectString("function f() { return foo; }; f()", "isolate 1"); | 16891 ExpectString("function f() { return foo; }; f()", "isolate 1"); |
| 16882 } | 16892 } |
| 16883 | 16893 |
| 16884 isolate1->Exit(); | 16894 isolate1->Exit(); |
| 16885 | 16895 |
| 16886 // Run some stuff in default isolate. | 16896 // Run some stuff in default isolate. |
| 16887 v8::Persistent<v8::Context> context_default = v8::Context::New(); | 16897 v8::Persistent<v8::Context> context_default = v8::Context::New(); |
| 16888 | 16898 |
| 16889 { | 16899 { |
| 16890 v8::Context::Scope cscope(context_default); | |
| 16891 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 16900 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 16901 v8::Context::Scope cscope(v8::Isolate::GetCurrent(), context_default); |
| 16892 // Variables in other isolates should be not available, verify there | 16902 // Variables in other isolates should be not available, verify there |
| 16893 // is an exception. | 16903 // is an exception. |
| 16894 ExpectTrue("function f() {" | 16904 ExpectTrue("function f() {" |
| 16895 " try {" | 16905 " try {" |
| 16896 " foo;" | 16906 " foo;" |
| 16897 " return false;" | 16907 " return false;" |
| 16898 " } catch(e) {" | 16908 " } catch(e) {" |
| 16899 " return true;" | 16909 " return true;" |
| 16900 " }" | 16910 " }" |
| 16901 "};" | 16911 "};" |
| 16902 "var isDefaultIsolate = true;" | 16912 "var isDefaultIsolate = true;" |
| 16903 "f()"); | 16913 "f()"); |
| 16904 } | 16914 } |
| 16905 | 16915 |
| 16906 isolate1->Enter(); | 16916 isolate1->Enter(); |
| 16907 | 16917 |
| 16908 { | 16918 { |
| 16909 v8::Isolate::Scope iscope(isolate2); | 16919 v8::Isolate::Scope iscope(isolate2); |
| 16910 v8::Context::Scope cscope(context2); | |
| 16911 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 16920 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 16921 v8::Context::Scope cscope(isolate2, context2); |
| 16912 ExpectString("function f() { return foo; }; f()", "isolate 2"); | 16922 ExpectString("function f() { return foo; }; f()", "isolate 2"); |
| 16913 } | 16923 } |
| 16914 | 16924 |
| 16915 { | 16925 { |
| 16916 v8::Context::Scope cscope(context1); | |
| 16917 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 16926 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 16927 v8::Context::Scope cscope(v8::Isolate::GetCurrent(), context1); |
| 16918 ExpectString("function f() { return foo; }; f()", "isolate 1"); | 16928 ExpectString("function f() { return foo; }; f()", "isolate 1"); |
| 16919 } | 16929 } |
| 16920 | 16930 |
| 16921 { | 16931 { |
| 16922 v8::Isolate::Scope iscope(isolate2); | 16932 v8::Isolate::Scope iscope(isolate2); |
| 16923 context2.Dispose(context2->GetIsolate()); | 16933 context2.Dispose(context2->GetIsolate()); |
| 16924 } | 16934 } |
| 16925 | 16935 |
| 16926 context1.Dispose(context1->GetIsolate()); | 16936 context1.Dispose(context1->GetIsolate()); |
| 16927 isolate1->Exit(); | 16937 isolate1->Exit(); |
| 16928 | 16938 |
| 16929 v8::V8::SetFatalErrorHandler(StoringErrorCallback); | 16939 v8::V8::SetFatalErrorHandler(StoringErrorCallback); |
| 16930 last_location = last_message = NULL; | 16940 last_location = last_message = NULL; |
| 16931 | 16941 |
| 16932 isolate1->Dispose(); | 16942 isolate1->Dispose(); |
| 16933 CHECK_EQ(last_location, NULL); | 16943 CHECK_EQ(last_location, NULL); |
| 16934 CHECK_EQ(last_message, NULL); | 16944 CHECK_EQ(last_message, NULL); |
| 16935 | 16945 |
| 16936 isolate2->Dispose(); | 16946 isolate2->Dispose(); |
| 16937 CHECK_EQ(last_location, NULL); | 16947 CHECK_EQ(last_location, NULL); |
| 16938 CHECK_EQ(last_message, NULL); | 16948 CHECK_EQ(last_message, NULL); |
| 16939 | 16949 |
| 16940 // Check that default isolate still runs. | 16950 // Check that default isolate still runs. |
| 16941 { | 16951 { |
| 16942 v8::Context::Scope cscope(context_default); | |
| 16943 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 16952 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 16953 v8::Context::Scope cscope(v8::Isolate::GetCurrent(), context_default); |
| 16944 ExpectTrue("function f() { return isDefaultIsolate; }; f()"); | 16954 ExpectTrue("function f() { return isDefaultIsolate; }; f()"); |
| 16945 } | 16955 } |
| 16946 } | 16956 } |
| 16947 | 16957 |
| 16948 static int CalcFibonacci(v8::Isolate* isolate, int limit) { | 16958 static int CalcFibonacci(v8::Isolate* isolate, int limit) { |
| 16949 v8::Isolate::Scope isolate_scope(isolate); | 16959 v8::Isolate::Scope isolate_scope(isolate); |
| 16950 v8::HandleScope scope(isolate); | 16960 v8::HandleScope scope(isolate); |
| 16951 LocalContext context; | 16961 LocalContext context; |
| 16952 i::ScopedVector<char> code(1024); | 16962 i::ScopedVector<char> code(1024); |
| 16953 i::OS::SNPrintF(code, "function fib(n) {" | 16963 i::OS::SNPrintF(code, "function fib(n) {" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17008 isolate2->Dispose(); | 17018 isolate2->Dispose(); |
| 17009 } | 17019 } |
| 17010 | 17020 |
| 17011 TEST(IsolateDifferentContexts) { | 17021 TEST(IsolateDifferentContexts) { |
| 17012 v8::Isolate* isolate = v8::Isolate::New(); | 17022 v8::Isolate* isolate = v8::Isolate::New(); |
| 17013 Persistent<v8::Context> context; | 17023 Persistent<v8::Context> context; |
| 17014 { | 17024 { |
| 17015 v8::Isolate::Scope isolate_scope(isolate); | 17025 v8::Isolate::Scope isolate_scope(isolate); |
| 17016 v8::HandleScope handle_scope(isolate); | 17026 v8::HandleScope handle_scope(isolate); |
| 17017 context = v8::Context::New(); | 17027 context = v8::Context::New(); |
| 17018 v8::Context::Scope context_scope(context); | 17028 v8::Context::Scope context_scope(isolate, context); |
| 17019 Local<Value> v = CompileRun("2"); | 17029 Local<Value> v = CompileRun("2"); |
| 17020 CHECK(v->IsNumber()); | 17030 CHECK(v->IsNumber()); |
| 17021 CHECK_EQ(2, static_cast<int>(v->NumberValue())); | 17031 CHECK_EQ(2, static_cast<int>(v->NumberValue())); |
| 17022 } | 17032 } |
| 17023 { | 17033 { |
| 17024 v8::Isolate::Scope isolate_scope(isolate); | 17034 v8::Isolate::Scope isolate_scope(isolate); |
| 17025 v8::HandleScope handle_scope(isolate); | 17035 v8::HandleScope handle_scope(isolate); |
| 17026 context = v8::Context::New(); | 17036 context = v8::Context::New(); |
| 17027 v8::Context::Scope context_scope(context); | 17037 v8::Context::Scope context_scope(isolate, context); |
| 17028 Local<Value> v = CompileRun("22"); | 17038 Local<Value> v = CompileRun("22"); |
| 17029 CHECK(v->IsNumber()); | 17039 CHECK(v->IsNumber()); |
| 17030 CHECK_EQ(22, static_cast<int>(v->NumberValue())); | 17040 CHECK_EQ(22, static_cast<int>(v->NumberValue())); |
| 17031 } | 17041 } |
| 17032 isolate->Dispose(); | 17042 isolate->Dispose(); |
| 17033 } | 17043 } |
| 17034 | 17044 |
| 17035 class InitDefaultIsolateThread : public v8::internal::Thread { | 17045 class InitDefaultIsolateThread : public v8::internal::Thread { |
| 17036 public: | 17046 public: |
| 17037 enum TestCase { | 17047 enum TestCase { |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17292 explicit Visitor42(v8::Persistent<v8::Object> object) | 17302 explicit Visitor42(v8::Persistent<v8::Object> object) |
| 17293 : counter_(0), object_(object) { } | 17303 : counter_(0), object_(object) { } |
| 17294 | 17304 |
| 17295 virtual void VisitPersistentHandle(Persistent<Value> value, | 17305 virtual void VisitPersistentHandle(Persistent<Value> value, |
| 17296 uint16_t class_id) { | 17306 uint16_t class_id) { |
| 17297 if (class_id == 42) { | 17307 if (class_id == 42) { |
| 17298 CHECK(value->IsObject()); | 17308 CHECK(value->IsObject()); |
| 17299 v8::Persistent<v8::Object> visited = | 17309 v8::Persistent<v8::Object> visited = |
| 17300 v8::Persistent<v8::Object>::Cast(value); | 17310 v8::Persistent<v8::Object>::Cast(value); |
| 17301 CHECK_EQ(42, visited.WrapperClassId(v8::Isolate::GetCurrent())); | 17311 CHECK_EQ(42, visited.WrapperClassId(v8::Isolate::GetCurrent())); |
| 17302 CHECK_EQ(object_, visited); | 17312 CHECK_EQ(Handle<Value>(*object_), Handle<Value>(*visited)); |
| 17303 ++counter_; | 17313 ++counter_; |
| 17304 } | 17314 } |
| 17305 } | 17315 } |
| 17306 | 17316 |
| 17307 int counter_; | 17317 int counter_; |
| 17308 v8::Persistent<v8::Object> object_; | 17318 v8::Persistent<v8::Object> object_; |
| 17309 }; | 17319 }; |
| 17310 | 17320 |
| 17311 | 17321 |
| 17312 TEST(PersistentHandleVisitor) { | 17322 TEST(PersistentHandleVisitor) { |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17507 } | 17517 } |
| 17508 | 17518 |
| 17509 | 17519 |
| 17510 static void CheckContextId(v8::Handle<Object> object, int expected) { | 17520 static void CheckContextId(v8::Handle<Object> object, int expected) { |
| 17511 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value()); | 17521 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value()); |
| 17512 } | 17522 } |
| 17513 | 17523 |
| 17514 | 17524 |
| 17515 THREADED_TEST(CreationContext) { | 17525 THREADED_TEST(CreationContext) { |
| 17516 HandleScope handle_scope(v8::Isolate::GetCurrent()); | 17526 HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 17517 Persistent<Context> context1 = Context::New(); | 17527 Handle<Context> context1 = Context::New(v8::Isolate::GetCurrent()); |
| 17518 InstallContextId(context1, 1); | 17528 InstallContextId(context1, 1); |
| 17519 Persistent<Context> context2 = Context::New(); | 17529 Handle<Context> context2 = Context::New(v8::Isolate::GetCurrent()); |
| 17520 InstallContextId(context2, 2); | 17530 InstallContextId(context2, 2); |
| 17521 Persistent<Context> context3 = Context::New(); | 17531 Handle<Context> context3 = Context::New(v8::Isolate::GetCurrent()); |
| 17522 InstallContextId(context3, 3); | 17532 InstallContextId(context3, 3); |
| 17523 | 17533 |
| 17524 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); | 17534 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); |
| 17525 | 17535 |
| 17526 Local<Object> object1; | 17536 Local<Object> object1; |
| 17527 Local<Function> func1; | 17537 Local<Function> func1; |
| 17528 { | 17538 { |
| 17529 Context::Scope scope(context1); | 17539 Context::Scope scope(context1); |
| 17530 object1 = Object::New(); | 17540 object1 = Object::New(); |
| 17531 func1 = tmpl->GetFunction(); | 17541 func1 = tmpl->GetFunction(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17585 CheckContextId(func1, 1); | 17595 CheckContextId(func1, 1); |
| 17586 CHECK(instance1->CreationContext() == context1); | 17596 CHECK(instance1->CreationContext() == context1); |
| 17587 CheckContextId(instance1, 1); | 17597 CheckContextId(instance1, 1); |
| 17588 CHECK(object2->CreationContext() == context2); | 17598 CHECK(object2->CreationContext() == context2); |
| 17589 CheckContextId(object2, 2); | 17599 CheckContextId(object2, 2); |
| 17590 CHECK(func2->CreationContext() == context2); | 17600 CHECK(func2->CreationContext() == context2); |
| 17591 CheckContextId(func2, 2); | 17601 CheckContextId(func2, 2); |
| 17592 CHECK(instance2->CreationContext() == context2); | 17602 CHECK(instance2->CreationContext() == context2); |
| 17593 CheckContextId(instance2, 2); | 17603 CheckContextId(instance2, 2); |
| 17594 } | 17604 } |
| 17595 | |
| 17596 context1.Dispose(context1->GetIsolate()); | |
| 17597 context2.Dispose(context2->GetIsolate()); | |
| 17598 context3.Dispose(context3->GetIsolate()); | |
| 17599 } | 17605 } |
| 17600 | 17606 |
| 17601 | 17607 |
| 17602 THREADED_TEST(CreationContextOfJsFunction) { | 17608 THREADED_TEST(CreationContextOfJsFunction) { |
| 17603 HandleScope handle_scope(v8::Isolate::GetCurrent()); | 17609 HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 17604 Persistent<Context> context = Context::New(); | 17610 Handle<Context> context = Context::New(v8::Isolate::GetCurrent()); |
| 17605 InstallContextId(context, 1); | 17611 InstallContextId(context, 1); |
| 17606 | 17612 |
| 17607 Local<Object> function; | 17613 Local<Object> function; |
| 17608 { | 17614 { |
| 17609 Context::Scope scope(context); | 17615 Context::Scope scope(context); |
| 17610 function = CompileRun("function foo() {}; foo").As<Object>(); | 17616 function = CompileRun("function foo() {}; foo").As<Object>(); |
| 17611 } | 17617 } |
| 17612 | 17618 |
| 17613 CHECK(function->CreationContext() == context); | 17619 CHECK(function->CreationContext() == context); |
| 17614 CheckContextId(function, 1); | 17620 CheckContextId(function, 1); |
| 17615 | |
| 17616 context.Dispose(context->GetIsolate()); | |
| 17617 } | 17621 } |
| 17618 | 17622 |
| 17619 | 17623 |
| 17620 Handle<Value> HasOwnPropertyIndexedPropertyGetter(uint32_t index, | 17624 Handle<Value> HasOwnPropertyIndexedPropertyGetter(uint32_t index, |
| 17621 const AccessorInfo& info) { | 17625 const AccessorInfo& info) { |
| 17622 if (index == 42) return v8_str("yes"); | 17626 if (index == 42) return v8_str("yes"); |
| 17623 return Handle<v8::Integer>(); | 17627 return Handle<v8::Integer>(); |
| 17624 } | 17628 } |
| 17625 | 17629 |
| 17626 | 17630 |
| (...skipping 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18857 i::Semaphore* sem_; | 18861 i::Semaphore* sem_; |
| 18858 volatile int sem_value_; | 18862 volatile int sem_value_; |
| 18859 }; | 18863 }; |
| 18860 | 18864 |
| 18861 | 18865 |
| 18862 THREADED_TEST(SemaphoreInterruption) { | 18866 THREADED_TEST(SemaphoreInterruption) { |
| 18863 ThreadInterruptTest().RunTest(); | 18867 ThreadInterruptTest().RunTest(); |
| 18864 } | 18868 } |
| 18865 | 18869 |
| 18866 #endif // WIN32 | 18870 #endif // WIN32 |
| OLD | NEW |