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

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

Issue 12033011: Add Isolate parameter to Persistent class. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added explicit Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/cctest.h ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 CHECK(!env->InContext()); 175 CHECK(!env->InContext());
176 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); 176 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent());
177 env->Enter(); 177 env->Enter();
178 CHECK(env->InContext()); 178 CHECK(env->InContext());
179 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); 179 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent());
180 env->Exit(); 180 env->Exit();
181 CHECK(!env->InContext()); 181 CHECK(!env->InContext());
182 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); 182 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent());
183 183
184 env.Dispose(); 184 env.Dispose(env->GetIsolate());
185 } 185 }
186 186
187 187
188 THREADED_TEST(ReceiverSignature) { 188 THREADED_TEST(ReceiverSignature) {
189 v8::HandleScope scope; 189 v8::HandleScope scope;
190 LocalContext env; 190 LocalContext env;
191 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(); 191 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New();
192 v8::Handle<v8::Signature> sig = v8::Signature::New(fun); 192 v8::Handle<v8::Signature> sig = v8::Signature::New(fun);
193 fun->PrototypeTemplate()->Set( 193 fun->PrototypeTemplate()->Set(
194 v8_str("m"), 194 v8_str("m"),
(...skipping 2115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2310 CHECK_EQ('1', *char_ptr); 2310 CHECK_EQ('1', *char_ptr);
2311 char_ptr = reinterpret_cast<char*>(v8::External::Cast(*two)->Value()); 2311 char_ptr = reinterpret_cast<char*>(v8::External::Cast(*two)->Value());
2312 CHECK_EQ('2', *char_ptr); 2312 CHECK_EQ('2', *char_ptr);
2313 char_ptr = reinterpret_cast<char*>(v8::External::Cast(*three)->Value()); 2313 char_ptr = reinterpret_cast<char*>(v8::External::Cast(*three)->Value());
2314 CHECK_EQ('3', *char_ptr); 2314 CHECK_EQ('3', *char_ptr);
2315 i::DeleteArray(data); 2315 i::DeleteArray(data);
2316 } 2316 }
2317 2317
2318 2318
2319 THREADED_TEST(GlobalHandle) { 2319 THREADED_TEST(GlobalHandle) {
2320 v8::Isolate* isolate = v8::Isolate::GetCurrent();
2320 v8::Persistent<String> global; 2321 v8::Persistent<String> global;
2321 { 2322 {
2322 v8::HandleScope scope; 2323 v8::HandleScope scope;
2323 Local<String> str = v8_str("str"); 2324 Local<String> str = v8_str("str");
2324 global = v8::Persistent<String>::New(str); 2325 global = v8::Persistent<String>::New(isolate, str);
2325 } 2326 }
2326 CHECK_EQ(global->Length(), 3); 2327 CHECK_EQ(global->Length(), 3);
2327 global.Dispose(); 2328 global.Dispose(isolate);
2328 2329
2329 { 2330 {
2330 v8::HandleScope scope; 2331 v8::HandleScope scope;
2331 Local<String> str = v8_str("str"); 2332 Local<String> str = v8_str("str");
2332 global = v8::Persistent<String>::New(str); 2333 global = v8::Persistent<String>::New(isolate, str);
2333 } 2334 }
2334 CHECK_EQ(global->Length(), 3); 2335 CHECK_EQ(global->Length(), 3);
2335 global.Dispose(v8::Isolate::GetCurrent()); 2336 global.Dispose(isolate);
2336 } 2337 }
2337 2338
2338 2339
2339 THREADED_TEST(LocalHandle) { 2340 THREADED_TEST(LocalHandle) {
2340 v8::HandleScope scope; 2341 v8::HandleScope scope;
2341 v8::Local<String> local = v8::Local<String>::New(v8_str("str")); 2342 v8::Local<String> local = v8::Local<String>::New(v8_str("str"));
2342 CHECK_EQ(local->Length(), 3); 2343 CHECK_EQ(local->Length(), 3);
2343 2344
2344 local = v8::Local<String>::New(v8::Isolate::GetCurrent(), v8_str("str")); 2345 local = v8::Local<String>::New(v8::Isolate::GetCurrent(), v8_str("str"));
2345 CHECK_EQ(local->Length(), 3); 2346 CHECK_EQ(local->Length(), 3);
2346 } 2347 }
2347 2348
2348 2349
2349 class WeakCallCounter { 2350 class WeakCallCounter {
2350 public: 2351 public:
2351 explicit WeakCallCounter(int id) : id_(id), number_of_weak_calls_(0) { } 2352 explicit WeakCallCounter(int id) : id_(id), number_of_weak_calls_(0) { }
2352 int id() { return id_; } 2353 int id() { return id_; }
2353 void increment() { number_of_weak_calls_++; } 2354 void increment() { number_of_weak_calls_++; }
2354 int NumberOfWeakCalls() { return number_of_weak_calls_; } 2355 int NumberOfWeakCalls() { return number_of_weak_calls_; }
2355 private: 2356 private:
2356 int id_; 2357 int id_;
2357 int number_of_weak_calls_; 2358 int number_of_weak_calls_;
2358 }; 2359 };
2359 2360
2360 2361
2361 static void WeakPointerCallback(Persistent<Value> handle, void* id) { 2362 static void WeakPointerCallback(v8::Isolate* isolate,
2363 Persistent<Value> handle,
2364 void* id) {
2362 WeakCallCounter* counter = reinterpret_cast<WeakCallCounter*>(id); 2365 WeakCallCounter* counter = reinterpret_cast<WeakCallCounter*>(id);
2363 CHECK_EQ(1234, counter->id()); 2366 CHECK_EQ(1234, counter->id());
2364 counter->increment(); 2367 counter->increment();
2365 handle.Dispose(); 2368 handle.Dispose(isolate);
2366 } 2369 }
2367 2370
2368 2371
2369 THREADED_TEST(ApiObjectGroups) { 2372 THREADED_TEST(ApiObjectGroups) {
2370 HandleScope scope; 2373 HandleScope scope;
2371 LocalContext env; 2374 LocalContext env;
2375 v8::Isolate* iso = env->GetIsolate();
2372 2376
2373 Persistent<Object> g1s1; 2377 Persistent<Object> g1s1;
2374 Persistent<Object> g1s2; 2378 Persistent<Object> g1s2;
2375 Persistent<Object> g1c1; 2379 Persistent<Object> g1c1;
2376 Persistent<Object> g2s1; 2380 Persistent<Object> g2s1;
2377 Persistent<Object> g2s2; 2381 Persistent<Object> g2s2;
2378 Persistent<Object> g2c1; 2382 Persistent<Object> g2c1;
2379 2383
2380 WeakCallCounter counter(1234); 2384 WeakCallCounter counter(1234);
2381 2385
2382 { 2386 {
2383 HandleScope scope; 2387 HandleScope scope;
2384 g1s1 = Persistent<Object>::New(Object::New()); 2388 g1s1 = Persistent<Object>::New(iso, Object::New());
2385 g1s2 = Persistent<Object>::New(Object::New()); 2389 g1s2 = Persistent<Object>::New(iso, Object::New());
2386 g1c1 = Persistent<Object>::New(Object::New()); 2390 g1c1 = Persistent<Object>::New(iso, Object::New());
2387 g1s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2391 g1s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2388 g1s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2392 g1s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2389 g1c1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2393 g1c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2390 2394
2391 g2s1 = Persistent<Object>::New(Object::New()); 2395 g2s1 = Persistent<Object>::New(iso, Object::New());
2392 g2s2 = Persistent<Object>::New(Object::New()); 2396 g2s2 = Persistent<Object>::New(iso, Object::New());
2393 g2c1 = Persistent<Object>::New(Object::New()); 2397 g2c1 = Persistent<Object>::New(iso, Object::New());
2394 g2s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2398 g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2395 g2s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2399 g2s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2396 g2c1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2400 g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2397 } 2401 }
2398 2402
2399 Persistent<Object> root = Persistent<Object>::New(g1s1); // make a root. 2403 Persistent<Object> root = Persistent<Object>::New(iso, g1s1); // make a root.
2400 2404
2401 // Connect group 1 and 2, make a cycle. 2405 // Connect group 1 and 2, make a cycle.
2402 CHECK(g1s2->Set(0, g2s2)); 2406 CHECK(g1s2->Set(0, g2s2));
2403 CHECK(g2s1->Set(0, g1s1)); 2407 CHECK(g2s1->Set(0, g1s1));
2404 2408
2405 { 2409 {
2406 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; 2410 Persistent<Value> g1_objects[] = { g1s1, g1s2 };
2407 Persistent<Value> g1_children[] = { g1c1 }; 2411 Persistent<Value> g1_children[] = { g1c1 };
2408 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; 2412 Persistent<Value> g2_objects[] = { g2s1, g2s2 };
2409 Persistent<Value> g2_children[] = { g2c1 }; 2413 Persistent<Value> g2_children[] = { g2c1 };
2410 V8::AddObjectGroup(g1_objects, 2); 2414 V8::AddObjectGroup(g1_objects, 2);
2411 V8::AddImplicitReferences(g1s1, g1_children, 1); 2415 V8::AddImplicitReferences(g1s1, g1_children, 1);
2412 V8::AddObjectGroup(g2_objects, 2); 2416 V8::AddObjectGroup(g2_objects, 2);
2413 V8::AddImplicitReferences(g2s2, g2_children, 1); 2417 V8::AddImplicitReferences(g2s2, g2_children, 1);
2414 } 2418 }
2415 // Do a single full GC, ensure incremental marking is stopped. 2419 // Do a single full GC, ensure incremental marking is stopped.
2416 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 2420 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
2417 2421
2418 // All object should be alive. 2422 // All object should be alive.
2419 CHECK_EQ(0, counter.NumberOfWeakCalls()); 2423 CHECK_EQ(0, counter.NumberOfWeakCalls());
2420 2424
2421 // Weaken the root. 2425 // Weaken the root.
2422 root.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2426 root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2423 // But make children strong roots---all the objects (except for children) 2427 // But make children strong roots---all the objects (except for children)
2424 // should be collectable now. 2428 // should be collectable now.
2425 g1c1.ClearWeak(); 2429 g1c1.ClearWeak(iso);
2426 g2c1.ClearWeak(); 2430 g2c1.ClearWeak(iso);
2427 2431
2428 // Groups are deleted, rebuild groups. 2432 // Groups are deleted, rebuild groups.
2429 { 2433 {
2430 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; 2434 Persistent<Value> g1_objects[] = { g1s1, g1s2 };
2431 Persistent<Value> g1_children[] = { g1c1 }; 2435 Persistent<Value> g1_children[] = { g1c1 };
2432 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; 2436 Persistent<Value> g2_objects[] = { g2s1, g2s2 };
2433 Persistent<Value> g2_children[] = { g2c1 }; 2437 Persistent<Value> g2_children[] = { g2c1 };
2434 V8::AddObjectGroup(g1_objects, 2); 2438 V8::AddObjectGroup(g1_objects, 2);
2435 V8::AddImplicitReferences(g1s1, g1_children, 1); 2439 V8::AddImplicitReferences(g1s1, g1_children, 1);
2436 V8::AddObjectGroup(g2_objects, 2); 2440 V8::AddObjectGroup(g2_objects, 2);
2437 V8::AddImplicitReferences(g2s2, g2_children, 1); 2441 V8::AddImplicitReferences(g2s2, g2_children, 1);
2438 } 2442 }
2439 2443
2440 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 2444 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
2441 2445
2442 // All objects should be gone. 5 global handles in total. 2446 // All objects should be gone. 5 global handles in total.
2443 CHECK_EQ(5, counter.NumberOfWeakCalls()); 2447 CHECK_EQ(5, counter.NumberOfWeakCalls());
2444 2448
2445 // And now make children weak again and collect them. 2449 // And now make children weak again and collect them.
2446 g1c1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2450 g1c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2447 g2c1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2451 g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2448 2452
2449 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 2453 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
2450 CHECK_EQ(7, counter.NumberOfWeakCalls()); 2454 CHECK_EQ(7, counter.NumberOfWeakCalls());
2451 } 2455 }
2452 2456
2453 2457
2454 THREADED_TEST(ApiObjectGroupsCycle) { 2458 THREADED_TEST(ApiObjectGroupsCycle) {
2455 HandleScope scope; 2459 HandleScope scope;
2456 LocalContext env; 2460 LocalContext env;
2461 v8::Isolate* iso = env->GetIsolate();
2457 2462
2458 WeakCallCounter counter(1234); 2463 WeakCallCounter counter(1234);
2459 2464
2460 Persistent<Object> g1s1; 2465 Persistent<Object> g1s1;
2461 Persistent<Object> g1s2; 2466 Persistent<Object> g1s2;
2462 Persistent<Object> g2s1; 2467 Persistent<Object> g2s1;
2463 Persistent<Object> g2s2; 2468 Persistent<Object> g2s2;
2464 Persistent<Object> g3s1; 2469 Persistent<Object> g3s1;
2465 Persistent<Object> g3s2; 2470 Persistent<Object> g3s2;
2466 Persistent<Object> g4s1; 2471 Persistent<Object> g4s1;
2467 Persistent<Object> g4s2; 2472 Persistent<Object> g4s2;
2468 2473
2469 v8::Isolate* isolate = v8::Isolate::GetCurrent();
2470 { 2474 {
2471 HandleScope scope; 2475 HandleScope scope;
2472 g1s1 = Persistent<Object>::New(Object::New()); 2476 g1s1 = Persistent<Object>::New(iso, Object::New());
2473 g1s2 = Persistent<Object>::New(Object::New()); 2477 g1s2 = Persistent<Object>::New(iso, Object::New());
2474 g1s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2478 g1s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2475 g1s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2479 g1s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2476 CHECK(g1s1.IsWeak()); 2480 CHECK(g1s1.IsWeak(iso));
2477 CHECK(g1s2.IsWeak()); 2481 CHECK(g1s2.IsWeak(iso));
2478 2482
2479 g2s1 = Persistent<Object>::New(Object::New()); 2483 g2s1 = Persistent<Object>::New(iso, Object::New());
2480 g2s2 = Persistent<Object>::New(Object::New()); 2484 g2s2 = Persistent<Object>::New(iso, Object::New());
2481 g2s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2485 g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2482 g2s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2486 g2s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2483 CHECK(g2s1.IsWeak()); 2487 CHECK(g2s1.IsWeak(iso));
2484 CHECK(g2s2.IsWeak()); 2488 CHECK(g2s2.IsWeak(iso));
2485 2489
2486 g3s1 = Persistent<Object>::New(Object::New()); 2490 g3s1 = Persistent<Object>::New(iso, Object::New());
2487 g3s2 = Persistent<Object>::New(Object::New()); 2491 g3s2 = Persistent<Object>::New(iso, Object::New());
2488 g3s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2492 g3s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2489 g3s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2493 g3s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2490 CHECK(g3s1.IsWeak()); 2494 CHECK(g3s1.IsWeak(iso));
2491 CHECK(g3s2.IsWeak()); 2495 CHECK(g3s2.IsWeak(iso));
2492 2496
2493 g4s1 = Persistent<Object>::New(Object::New()); 2497 g4s1 = Persistent<Object>::New(iso, Object::New());
2494 g4s2 = Persistent<Object>::New(Object::New()); 2498 g4s2 = Persistent<Object>::New(iso, Object::New());
2495 g4s1.MakeWeak(isolate, 2499 g4s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2496 reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2500 g4s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2497 g4s2.MakeWeak(isolate, 2501 CHECK(g4s1.IsWeak(iso));
2498 reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2502 CHECK(g4s2.IsWeak(iso));
2499 CHECK(g4s1.IsWeak(isolate));
2500 CHECK(g4s2.IsWeak(isolate));
2501 } 2503 }
2502 2504
2503 Persistent<Object> root = Persistent<Object>::New(g1s1); // make a root. 2505 Persistent<Object> root = Persistent<Object>::New(iso, g1s1); // make a root.
2504 2506
2505 // Connect groups. We're building the following cycle: 2507 // Connect groups. We're building the following cycle:
2506 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other 2508 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other
2507 // groups. 2509 // groups.
2508 { 2510 {
2509 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; 2511 Persistent<Value> g1_objects[] = { g1s1, g1s2 };
2510 Persistent<Value> g1_children[] = { g2s1 }; 2512 Persistent<Value> g1_children[] = { g2s1 };
2511 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; 2513 Persistent<Value> g2_objects[] = { g2s1, g2s2 };
2512 Persistent<Value> g2_children[] = { g3s1 }; 2514 Persistent<Value> g2_children[] = { g3s1 };
2513 Persistent<Value> g3_objects[] = { g3s1, g3s2 }; 2515 Persistent<Value> g3_objects[] = { g3s1, g3s2 };
2514 Persistent<Value> g3_children[] = { g4s1 }; 2516 Persistent<Value> g3_children[] = { g4s1 };
2515 Persistent<Value> g4_objects[] = { g4s1, g4s2 }; 2517 Persistent<Value> g4_objects[] = { g4s1, g4s2 };
2516 Persistent<Value> g4_children[] = { g1s1 }; 2518 Persistent<Value> g4_children[] = { g1s1 };
2517 V8::AddObjectGroup(g1_objects, 2); 2519 V8::AddObjectGroup(g1_objects, 2);
2518 V8::AddImplicitReferences(g1s1, g1_children, 1); 2520 V8::AddImplicitReferences(g1s1, g1_children, 1);
2519 V8::AddObjectGroup(g2_objects, 2); 2521 V8::AddObjectGroup(g2_objects, 2);
2520 V8::AddImplicitReferences(g2s1, g2_children, 1); 2522 V8::AddImplicitReferences(g2s1, g2_children, 1);
2521 V8::AddObjectGroup(g3_objects, 2); 2523 V8::AddObjectGroup(g3_objects, 2);
2522 V8::AddImplicitReferences(g3s1, g3_children, 1); 2524 V8::AddImplicitReferences(g3s1, g3_children, 1);
2523 V8::AddObjectGroup(isolate, g4_objects, 2); 2525 V8::AddObjectGroup(iso, g4_objects, 2);
2524 V8::AddImplicitReferences(g4s1, g4_children, 1); 2526 V8::AddImplicitReferences(g4s1, g4_children, 1);
2525 } 2527 }
2526 // Do a single full GC 2528 // Do a single full GC
2527 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 2529 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
2528 2530
2529 // All object should be alive. 2531 // All object should be alive.
2530 CHECK_EQ(0, counter.NumberOfWeakCalls()); 2532 CHECK_EQ(0, counter.NumberOfWeakCalls());
2531 2533
2532 // Weaken the root. 2534 // Weaken the root.
2533 root.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2535 root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2534 2536
2535 // Groups are deleted, rebuild groups. 2537 // Groups are deleted, rebuild groups.
2536 { 2538 {
2537 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; 2539 Persistent<Value> g1_objects[] = { g1s1, g1s2 };
2538 Persistent<Value> g1_children[] = { g2s1 }; 2540 Persistent<Value> g1_children[] = { g2s1 };
2539 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; 2541 Persistent<Value> g2_objects[] = { g2s1, g2s2 };
2540 Persistent<Value> g2_children[] = { g3s1 }; 2542 Persistent<Value> g2_children[] = { g3s1 };
2541 Persistent<Value> g3_objects[] = { g3s1, g3s2 }; 2543 Persistent<Value> g3_objects[] = { g3s1, g3s2 };
2542 Persistent<Value> g3_children[] = { g4s1 }; 2544 Persistent<Value> g3_children[] = { g4s1 };
2543 Persistent<Value> g4_objects[] = { g4s1, g4s2 }; 2545 Persistent<Value> g4_objects[] = { g4s1, g4s2 };
(...skipping 15 matching lines...) Expand all
2559 } 2561 }
2560 2562
2561 2563
2562 // TODO(mstarzinger): This should be a THREADED_TEST but causes failures 2564 // TODO(mstarzinger): This should be a THREADED_TEST but causes failures
2563 // on the buildbots, so was made non-threaded for the time being. 2565 // on the buildbots, so was made non-threaded for the time being.
2564 TEST(ApiObjectGroupsCycleForScavenger) { 2566 TEST(ApiObjectGroupsCycleForScavenger) {
2565 i::FLAG_stress_compaction = false; 2567 i::FLAG_stress_compaction = false;
2566 i::FLAG_gc_global = false; 2568 i::FLAG_gc_global = false;
2567 HandleScope scope; 2569 HandleScope scope;
2568 LocalContext env; 2570 LocalContext env;
2571 v8::Isolate* iso = env->GetIsolate();
2569 2572
2570 WeakCallCounter counter(1234); 2573 WeakCallCounter counter(1234);
2571 2574
2572 Persistent<Object> g1s1; 2575 Persistent<Object> g1s1;
2573 Persistent<Object> g1s2; 2576 Persistent<Object> g1s2;
2574 Persistent<Object> g2s1; 2577 Persistent<Object> g2s1;
2575 Persistent<Object> g2s2; 2578 Persistent<Object> g2s2;
2576 Persistent<Object> g3s1; 2579 Persistent<Object> g3s1;
2577 Persistent<Object> g3s2; 2580 Persistent<Object> g3s2;
2578 2581
2579 { 2582 {
2580 HandleScope scope; 2583 HandleScope scope;
2581 g1s1 = Persistent<Object>::New(Object::New()); 2584 g1s1 = Persistent<Object>::New(iso, Object::New());
2582 g1s2 = Persistent<Object>::New(Object::New()); 2585 g1s2 = Persistent<Object>::New(iso, Object::New());
2583 g1s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2586 g1s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2584 g1s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2587 g1s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2585 2588
2586 g2s1 = Persistent<Object>::New(Object::New()); 2589 g2s1 = Persistent<Object>::New(iso, Object::New());
2587 g2s2 = Persistent<Object>::New(Object::New()); 2590 g2s2 = Persistent<Object>::New(iso, Object::New());
2588 g2s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2591 g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2589 g2s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2592 g2s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2590 2593
2591 g3s1 = Persistent<Object>::New(Object::New()); 2594 g3s1 = Persistent<Object>::New(iso, Object::New());
2592 g3s2 = Persistent<Object>::New(Object::New()); 2595 g3s2 = Persistent<Object>::New(iso, Object::New());
2593 g3s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2596 g3s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2594 g3s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2597 g3s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2595 } 2598 }
2596 2599
2597 // Make a root. 2600 // Make a root.
2598 Persistent<Object> root = Persistent<Object>::New(g1s1); 2601 Persistent<Object> root = Persistent<Object>::New(iso, g1s1);
2599 root.MarkPartiallyDependent(); 2602 root.MarkPartiallyDependent(iso);
2600 2603
2601 // Connect groups. We're building the following cycle: 2604 // Connect groups. We're building the following cycle:
2602 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other 2605 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other
2603 // groups. 2606 // groups.
2604 { 2607 {
2605 g1s1.MarkPartiallyDependent(); 2608 g1s1.MarkPartiallyDependent(iso);
2606 g1s2.MarkPartiallyDependent(); 2609 g1s2.MarkPartiallyDependent(iso);
2607 g2s1.MarkPartiallyDependent(); 2610 g2s1.MarkPartiallyDependent(iso);
2608 g2s2.MarkPartiallyDependent(); 2611 g2s2.MarkPartiallyDependent(iso);
2609 g3s1.MarkPartiallyDependent(); 2612 g3s1.MarkPartiallyDependent(iso);
2610 g3s2.MarkPartiallyDependent(); 2613 g3s2.MarkPartiallyDependent(iso);
2611 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; 2614 Persistent<Value> g1_objects[] = { g1s1, g1s2 };
2612 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; 2615 Persistent<Value> g2_objects[] = { g2s1, g2s2 };
2613 Persistent<Value> g3_objects[] = { g3s1, g3s2 }; 2616 Persistent<Value> g3_objects[] = { g3s1, g3s2 };
2614 V8::AddObjectGroup(g1_objects, 2); 2617 V8::AddObjectGroup(g1_objects, 2);
2615 g1s1->Set(v8_str("x"), g2s1); 2618 g1s1->Set(v8_str("x"), g2s1);
2616 V8::AddObjectGroup(g2_objects, 2); 2619 V8::AddObjectGroup(g2_objects, 2);
2617 g2s1->Set(v8_str("x"), g3s1); 2620 g2s1->Set(v8_str("x"), g3s1);
2618 V8::AddObjectGroup(g3_objects, 2); 2621 V8::AddObjectGroup(g3_objects, 2);
2619 g3s1->Set(v8_str("x"), g1s1); 2622 g3s1->Set(v8_str("x"), g1s1);
2620 } 2623 }
2621 2624
2622 HEAP->CollectGarbage(i::NEW_SPACE); 2625 HEAP->CollectGarbage(i::NEW_SPACE);
2623 2626
2624 // All objects should be alive. 2627 // All objects should be alive.
2625 CHECK_EQ(0, counter.NumberOfWeakCalls()); 2628 CHECK_EQ(0, counter.NumberOfWeakCalls());
2626 2629
2627 // Weaken the root. 2630 // Weaken the root.
2628 root.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2631 root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2629 root.MarkPartiallyDependent(); 2632 root.MarkPartiallyDependent(iso);
2630 2633
2631 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 2634 v8::Isolate* isolate = v8::Isolate::GetCurrent();
2632 // Groups are deleted, rebuild groups. 2635 // Groups are deleted, rebuild groups.
2633 { 2636 {
2634 g1s1.MarkPartiallyDependent(isolate); 2637 g1s1.MarkPartiallyDependent(isolate);
2635 g1s2.MarkPartiallyDependent(isolate); 2638 g1s2.MarkPartiallyDependent(isolate);
2636 g2s1.MarkPartiallyDependent(isolate); 2639 g2s1.MarkPartiallyDependent(isolate);
2637 g2s2.MarkPartiallyDependent(isolate); 2640 g2s2.MarkPartiallyDependent(isolate);
2638 g3s1.MarkPartiallyDependent(isolate); 2641 g3s1.MarkPartiallyDependent(isolate);
2639 g3s2.MarkPartiallyDependent(isolate); 2642 g3s2.MarkPartiallyDependent(isolate);
(...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after
3752 v8::TryCatch try_catch; 3755 v8::TryCatch try_catch;
3753 TryCatchNestedHelper(5); 3756 TryCatchNestedHelper(5);
3754 CHECK(try_catch.HasCaught()); 3757 CHECK(try_catch.HasCaught());
3755 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(try_catch.Exception()), "back")); 3758 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(try_catch.Exception()), "back"));
3756 } 3759 }
3757 3760
3758 3761
3759 THREADED_TEST(Equality) { 3762 THREADED_TEST(Equality) {
3760 v8::HandleScope scope; 3763 v8::HandleScope scope;
3761 LocalContext context; 3764 LocalContext context;
3765 v8::Isolate* isolate = context->GetIsolate();
3762 // Check that equality works at all before relying on CHECK_EQ 3766 // Check that equality works at all before relying on CHECK_EQ
3763 CHECK(v8_str("a")->Equals(v8_str("a"))); 3767 CHECK(v8_str("a")->Equals(v8_str("a")));
3764 CHECK(!v8_str("a")->Equals(v8_str("b"))); 3768 CHECK(!v8_str("a")->Equals(v8_str("b")));
3765 3769
3766 CHECK_EQ(v8_str("a"), v8_str("a")); 3770 CHECK_EQ(v8_str("a"), v8_str("a"));
3767 CHECK_NE(v8_str("a"), v8_str("b")); 3771 CHECK_NE(v8_str("a"), v8_str("b"));
3768 CHECK_EQ(v8_num(1), v8_num(1)); 3772 CHECK_EQ(v8_num(1), v8_num(1));
3769 CHECK_EQ(v8_num(1.00), v8_num(1)); 3773 CHECK_EQ(v8_num(1.00), v8_num(1));
3770 CHECK_NE(v8_num(1), v8_num(2)); 3774 CHECK_NE(v8_num(1), v8_num(2));
3771 3775
3772 // Assume String is not symbol. 3776 // Assume String is not symbol.
3773 CHECK(v8_str("a")->StrictEquals(v8_str("a"))); 3777 CHECK(v8_str("a")->StrictEquals(v8_str("a")));
3774 CHECK(!v8_str("a")->StrictEquals(v8_str("b"))); 3778 CHECK(!v8_str("a")->StrictEquals(v8_str("b")));
3775 CHECK(!v8_str("5")->StrictEquals(v8_num(5))); 3779 CHECK(!v8_str("5")->StrictEquals(v8_num(5)));
3776 CHECK(v8_num(1)->StrictEquals(v8_num(1))); 3780 CHECK(v8_num(1)->StrictEquals(v8_num(1)));
3777 CHECK(!v8_num(1)->StrictEquals(v8_num(2))); 3781 CHECK(!v8_num(1)->StrictEquals(v8_num(2)));
3778 CHECK(v8_num(0)->StrictEquals(v8_num(-0))); 3782 CHECK(v8_num(0)->StrictEquals(v8_num(-0)));
3779 Local<Value> not_a_number = v8_num(i::OS::nan_value()); 3783 Local<Value> not_a_number = v8_num(i::OS::nan_value());
3780 CHECK(!not_a_number->StrictEquals(not_a_number)); 3784 CHECK(!not_a_number->StrictEquals(not_a_number));
3781 CHECK(v8::False()->StrictEquals(v8::False())); 3785 CHECK(v8::False()->StrictEquals(v8::False()));
3782 CHECK(!v8::False()->StrictEquals(v8::Undefined())); 3786 CHECK(!v8::False()->StrictEquals(v8::Undefined()));
3783 3787
3784 v8::Handle<v8::Object> obj = v8::Object::New(); 3788 v8::Handle<v8::Object> obj = v8::Object::New();
3785 v8::Persistent<v8::Object> alias = v8::Persistent<v8::Object>::New(obj); 3789 v8::Persistent<v8::Object> alias =
3790 v8::Persistent<v8::Object>::New(isolate, obj);
3786 CHECK(alias->StrictEquals(obj)); 3791 CHECK(alias->StrictEquals(obj));
3787 alias.Dispose(); 3792 alias.Dispose(isolate);
3788 } 3793 }
3789 3794
3790 3795
3791 THREADED_TEST(MultiRun) { 3796 THREADED_TEST(MultiRun) {
3792 v8::HandleScope scope; 3797 v8::HandleScope scope;
3793 LocalContext context; 3798 LocalContext context;
3794 Local<Script> script = Script::Compile(v8_str("x")); 3799 Local<Script> script = Script::Compile(v8_str("x"));
3795 for (int i = 0; i < 10; i++) 3800 for (int i = 0; i < 10; i++)
3796 script->Run(); 3801 script->Run();
3797 } 3802 }
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
4075 v8::Persistent<Value> xValue; 4080 v8::Persistent<Value> xValue;
4076 4081
4077 4082
4078 static void SetXValue(Local<String> name, 4083 static void SetXValue(Local<String> name,
4079 Local<Value> value, 4084 Local<Value> value,
4080 const AccessorInfo& info) { 4085 const AccessorInfo& info) {
4081 CHECK_EQ(value, v8_num(4)); 4086 CHECK_EQ(value, v8_num(4));
4082 CHECK_EQ(info.Data(), v8_str("donut")); 4087 CHECK_EQ(info.Data(), v8_str("donut"));
4083 CHECK_EQ(name, v8_str("x")); 4088 CHECK_EQ(name, v8_str("x"));
4084 CHECK(xValue.IsEmpty()); 4089 CHECK(xValue.IsEmpty());
4085 xValue = v8::Persistent<Value>::New(value); 4090 xValue = v8::Persistent<Value>::New(info.GetIsolate(), value);
4086 } 4091 }
4087 4092
4088 4093
4089 THREADED_TEST(SimplePropertyWrite) { 4094 THREADED_TEST(SimplePropertyWrite) {
4090 v8::HandleScope scope; 4095 v8::HandleScope scope;
4091 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4096 Local<ObjectTemplate> templ = ObjectTemplate::New();
4092 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut")); 4097 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut"));
4093 LocalContext context; 4098 LocalContext context;
4094 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 4099 context->Global()->Set(v8_str("obj"), templ->NewInstance());
4095 Local<Script> script = Script::Compile(v8_str("obj.x = 4")); 4100 Local<Script> script = Script::Compile(v8_str("obj.x = 4"));
4096 for (int i = 0; i < 10; i++) { 4101 for (int i = 0; i < 10; i++) {
4097 CHECK(xValue.IsEmpty()); 4102 CHECK(xValue.IsEmpty());
4098 script->Run(); 4103 script->Run();
4099 CHECK_EQ(v8_num(4), xValue); 4104 CHECK_EQ(v8_num(4), xValue);
4100 xValue.Dispose(); 4105 xValue.Dispose(context->GetIsolate());
4101 xValue = v8::Persistent<Value>(); 4106 xValue = v8::Persistent<Value>();
4102 } 4107 }
4103 } 4108 }
4104 4109
4105 4110
4106 THREADED_TEST(SetterOnly) { 4111 THREADED_TEST(SetterOnly) {
4107 v8::HandleScope scope; 4112 v8::HandleScope scope;
4108 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4113 Local<ObjectTemplate> templ = ObjectTemplate::New();
4109 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut")); 4114 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut"));
4110 LocalContext context; 4115 LocalContext context;
4111 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 4116 context->Global()->Set(v8_str("obj"), templ->NewInstance());
4112 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); 4117 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x"));
4113 for (int i = 0; i < 10; i++) { 4118 for (int i = 0; i < 10; i++) {
4114 CHECK(xValue.IsEmpty()); 4119 CHECK(xValue.IsEmpty());
4115 script->Run(); 4120 script->Run();
4116 CHECK_EQ(v8_num(4), xValue); 4121 CHECK_EQ(v8_num(4), xValue);
4117 xValue.Dispose(); 4122 xValue.Dispose(context->GetIsolate());
4118 xValue = v8::Persistent<Value>(); 4123 xValue = v8::Persistent<Value>();
4119 } 4124 }
4120 } 4125 }
4121 4126
4122 4127
4123 THREADED_TEST(NoAccessors) { 4128 THREADED_TEST(NoAccessors) {
4124 v8::HandleScope scope; 4129 v8::HandleScope scope;
4125 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4130 Local<ObjectTemplate> templ = ObjectTemplate::New();
4126 templ->SetAccessor(v8_str("x"), NULL, NULL, v8_str("donut")); 4131 templ->SetAccessor(v8_str("x"), NULL, NULL, v8_str("donut"));
4127 LocalContext context; 4132 LocalContext context;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
4217 // Check that the interceptor was actually invoked. 4222 // Check that the interceptor was actually invoked.
4218 CHECK_EQ(result, v8_str("x")); 4223 CHECK_EQ(result, v8_str("x"));
4219 } 4224 }
4220 4225
4221 // Return to the original context and force some object to the slow case 4226 // Return to the original context and force some object to the slow case
4222 // to cause the NormalizedMapCache to verify. 4227 // to cause the NormalizedMapCache to verify.
4223 context1->Enter(); 4228 context1->Enter();
4224 CompileRun("var obj = { x : 0 }; delete obj.x;"); 4229 CompileRun("var obj = { x : 0 }; delete obj.x;");
4225 context1->Exit(); 4230 context1->Exit();
4226 4231
4227 context1.Dispose(); 4232 context1.Dispose(context1->GetIsolate());
4228 } 4233 }
4229 4234
4230 4235
4231 static v8::Handle<Value> SetXOnPrototypeGetter(Local<String> property, 4236 static v8::Handle<Value> SetXOnPrototypeGetter(Local<String> property,
4232 const AccessorInfo& info) { 4237 const AccessorInfo& info) {
4233 // Set x on the prototype object and do not handle the get request. 4238 // Set x on the prototype object and do not handle the get request.
4234 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype(); 4239 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype();
4235 proto.As<v8::Object>()->Set(v8_str("x"), v8::Integer::New(23)); 4240 proto.As<v8::Object>()->Set(v8_str("x"), v8::Integer::New(23));
4236 return v8::Handle<Value>(); 4241 return v8::Handle<Value>();
4237 } 4242 }
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
4970 "}\n" 4975 "}\n"
4971 "\"PASS\"", 4976 "\"PASS\"",
4972 "PASS"); 4977 "PASS");
4973 } 4978 }
4974 4979
4975 4980
4976 template <typename T> static void USE(T) { } 4981 template <typename T> static void USE(T) { }
4977 4982
4978 4983
4979 // This test is not intended to be run, just type checked. 4984 // This test is not intended to be run, just type checked.
4980 static inline void PersistentHandles() { 4985 static inline void PersistentHandles(v8::Isolate* isolate) {
4981 USE(PersistentHandles); 4986 USE(PersistentHandles);
4982 Local<String> str = v8_str("foo"); 4987 Local<String> str = v8_str("foo");
4983 v8::Persistent<String> p_str = v8::Persistent<String>::New(str); 4988 v8::Persistent<String> p_str = v8::Persistent<String>::New(isolate, str);
4984 USE(p_str); 4989 USE(p_str);
4985 Local<Script> scr = Script::Compile(v8_str("")); 4990 Local<Script> scr = Script::Compile(v8_str(""));
4986 v8::Persistent<Script> p_scr = v8::Persistent<Script>::New(scr); 4991 v8::Persistent<Script> p_scr = v8::Persistent<Script>::New(isolate, scr);
4987 USE(p_scr); 4992 USE(p_scr);
4988 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4993 Local<ObjectTemplate> templ = ObjectTemplate::New();
4989 v8::Persistent<ObjectTemplate> p_templ = 4994 v8::Persistent<ObjectTemplate> p_templ =
4990 v8::Persistent<ObjectTemplate>::New(templ); 4995 v8::Persistent<ObjectTemplate>::New(isolate, templ);
4991 USE(p_templ); 4996 USE(p_templ);
4992 } 4997 }
4993 4998
4994 4999
4995 static v8::Handle<Value> HandleLogDelegator(const v8::Arguments& args) { 5000 static v8::Handle<Value> HandleLogDelegator(const v8::Arguments& args) {
4996 ApiTestFuzzer::Fuzz(); 5001 ApiTestFuzzer::Fuzz();
4997 return v8::Undefined(); 5002 return v8::Undefined();
4998 } 5003 }
4999 5004
5000 5005
5001 THREADED_TEST(GlobalObjectTemplate) { 5006 THREADED_TEST(GlobalObjectTemplate) {
5002 v8::HandleScope handle_scope; 5007 v8::HandleScope handle_scope;
5003 Local<ObjectTemplate> global_template = ObjectTemplate::New(); 5008 Local<ObjectTemplate> global_template = ObjectTemplate::New();
5004 global_template->Set(v8_str("JSNI_Log"), 5009 global_template->Set(v8_str("JSNI_Log"),
5005 v8::FunctionTemplate::New(HandleLogDelegator)); 5010 v8::FunctionTemplate::New(HandleLogDelegator));
5006 v8::Persistent<Context> context = Context::New(0, global_template); 5011 v8::Persistent<Context> context = Context::New(0, global_template);
5007 Context::Scope context_scope(context); 5012 Context::Scope context_scope(context);
5008 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run(); 5013 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run();
5009 context.Dispose(); 5014 context.Dispose(context->GetIsolate());
5010 } 5015 }
5011 5016
5012 5017
5013 static const char* kSimpleExtensionSource = 5018 static const char* kSimpleExtensionSource =
5014 "function Foo() {" 5019 "function Foo() {"
5015 " return 4;" 5020 " return 4;"
5016 "}"; 5021 "}";
5017 5022
5018 5023
5019 THREADED_TEST(SimpleExtensions) { 5024 THREADED_TEST(SimpleExtensions) {
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
5468 int global_index = 0; 5473 int global_index = 0;
5469 5474
5470 class Snorkel { 5475 class Snorkel {
5471 public: 5476 public:
5472 Snorkel() { index_ = global_index++; } 5477 Snorkel() { index_ = global_index++; }
5473 int index_; 5478 int index_;
5474 }; 5479 };
5475 5480
5476 class Whammy { 5481 class Whammy {
5477 public: 5482 public:
5478 Whammy() { 5483 explicit Whammy(v8::Isolate* isolate) : cursor_(0), isolate_(isolate) { }
5479 cursor_ = 0; 5484 ~Whammy() { script_.Dispose(isolate_); }
5480 }
5481 ~Whammy() {
5482 script_.Dispose();
5483 }
5484 v8::Handle<Script> getScript() { 5485 v8::Handle<Script> getScript() {
5485 if (script_.IsEmpty()) 5486 if (script_.IsEmpty()) {
5486 script_ = v8::Persistent<Script>::New(v8_compile("({}).blammo")); 5487 script_ = v8::Persistent<Script>::New(isolate_,
5488 v8_compile("({}).blammo"));
5489 }
5487 return Local<Script>(*script_); 5490 return Local<Script>(*script_);
5488 } 5491 }
5489 5492
5490 public: 5493 public:
5491 static const int kObjectCount = 256; 5494 static const int kObjectCount = 256;
5492 int cursor_; 5495 int cursor_;
5496 v8::Isolate* isolate_;
5493 v8::Persistent<v8::Object> objects_[kObjectCount]; 5497 v8::Persistent<v8::Object> objects_[kObjectCount];
5494 v8::Persistent<Script> script_; 5498 v8::Persistent<Script> script_;
5495 }; 5499 };
5496 5500
5497 static void HandleWeakReference(v8::Persistent<v8::Value> obj, void* data) { 5501 static void HandleWeakReference(v8::Isolate* isolate,
5502 v8::Persistent<v8::Value> obj,
5503 void* data) {
5498 Snorkel* snorkel = reinterpret_cast<Snorkel*>(data); 5504 Snorkel* snorkel = reinterpret_cast<Snorkel*>(data);
5499 delete snorkel; 5505 delete snorkel;
5500 obj.ClearWeak(); 5506 obj.ClearWeak(isolate);
5501 } 5507 }
5502 5508
5503 v8::Handle<Value> WhammyPropertyGetter(Local<String> name, 5509 v8::Handle<Value> WhammyPropertyGetter(Local<String> name,
5504 const AccessorInfo& info) { 5510 const AccessorInfo& info) {
5505 Whammy* whammy = 5511 Whammy* whammy =
5506 static_cast<Whammy*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); 5512 static_cast<Whammy*>(v8::Handle<v8::External>::Cast(info.Data())->Value());
5507 5513
5508 v8::Persistent<v8::Object> prev = whammy->objects_[whammy->cursor_]; 5514 v8::Persistent<v8::Object> prev = whammy->objects_[whammy->cursor_];
5509 5515
5510 v8::Handle<v8::Object> obj = v8::Object::New(); 5516 v8::Handle<v8::Object> obj = v8::Object::New();
5511 v8::Persistent<v8::Object> global = v8::Persistent<v8::Object>::New(obj); 5517 v8::Persistent<v8::Object> global =
5518 v8::Persistent<v8::Object>::New(info.GetIsolate(), obj);
5512 if (!prev.IsEmpty()) { 5519 if (!prev.IsEmpty()) {
5513 prev->Set(v8_str("next"), obj); 5520 prev->Set(v8_str("next"), obj);
5514 prev.MakeWeak(new Snorkel(), &HandleWeakReference); 5521 prev.MakeWeak(info.GetIsolate(), new Snorkel(), &HandleWeakReference);
5515 whammy->objects_[whammy->cursor_].Clear(); 5522 whammy->objects_[whammy->cursor_].Clear();
5516 } 5523 }
5517 whammy->objects_[whammy->cursor_] = global; 5524 whammy->objects_[whammy->cursor_] = global;
5518 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount; 5525 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount;
5519 return whammy->getScript()->Run(); 5526 return whammy->getScript()->Run();
5520 } 5527 }
5521 5528
5522 THREADED_TEST(WeakReference) { 5529 THREADED_TEST(WeakReference) {
5523 v8::HandleScope handle_scope; 5530 v8::HandleScope handle_scope;
5524 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New(); 5531 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New();
5525 Whammy* whammy = new Whammy(); 5532 Whammy* whammy = new Whammy(v8::Isolate::GetCurrent());
5526 templ->SetNamedPropertyHandler(WhammyPropertyGetter, 5533 templ->SetNamedPropertyHandler(WhammyPropertyGetter,
5527 0, 0, 0, 0, 5534 0, 0, 0, 0,
5528 v8::External::New(whammy)); 5535 v8::External::New(whammy));
5529 const char* extension_list[] = { "v8/gc" }; 5536 const char* extension_list[] = { "v8/gc" };
5530 v8::ExtensionConfiguration extensions(1, extension_list); 5537 v8::ExtensionConfiguration extensions(1, extension_list);
5531 v8::Persistent<Context> context = Context::New(&extensions); 5538 v8::Persistent<Context> context = Context::New(&extensions);
5532 Context::Scope context_scope(context); 5539 Context::Scope context_scope(context);
5533 5540
5534 v8::Handle<v8::Object> interceptor = templ->NewInstance(); 5541 v8::Handle<v8::Object> interceptor = templ->NewInstance();
5535 context->Global()->Set(v8_str("whammy"), interceptor); 5542 context->Global()->Set(v8_str("whammy"), interceptor);
5536 const char* code = 5543 const char* code =
5537 "var last;" 5544 "var last;"
5538 "for (var i = 0; i < 10000; i++) {" 5545 "for (var i = 0; i < 10000; i++) {"
5539 " var obj = whammy.length;" 5546 " var obj = whammy.length;"
5540 " if (last) last.next = obj;" 5547 " if (last) last.next = obj;"
5541 " last = obj;" 5548 " last = obj;"
5542 "}" 5549 "}"
5543 "gc();" 5550 "gc();"
5544 "4"; 5551 "4";
5545 v8::Handle<Value> result = CompileRun(code); 5552 v8::Handle<Value> result = CompileRun(code);
5546 CHECK_EQ(4.0, result->NumberValue()); 5553 CHECK_EQ(4.0, result->NumberValue());
5547 delete whammy; 5554 delete whammy;
5548 context.Dispose(); 5555 context.Dispose(context->GetIsolate());
5549 } 5556 }
5550 5557
5551 5558
5552 static void DisposeAndSetFlag(v8::Persistent<v8::Value> obj, void* data) { 5559 static void DisposeAndSetFlag(v8::Isolate* isolate,
5553 obj.Dispose(); 5560 v8::Persistent<v8::Value> obj,
5561 void* data) {
5562 obj.Dispose(isolate);
5554 obj.Clear(); 5563 obj.Clear();
5555 *(reinterpret_cast<bool*>(data)) = true; 5564 *(reinterpret_cast<bool*>(data)) = true;
5556 } 5565 }
5557 5566
5558 5567
5559 THREADED_TEST(IndependentWeakHandle) { 5568 THREADED_TEST(IndependentWeakHandle) {
5560 v8::Persistent<Context> context = Context::New(); 5569 v8::Persistent<Context> context = Context::New();
5570 v8::Isolate* iso = context->GetIsolate();
5561 Context::Scope context_scope(context); 5571 Context::Scope context_scope(context);
5562 5572
5563 v8::Persistent<v8::Object> object_a, object_b; 5573 v8::Persistent<v8::Object> object_a, object_b;
5564 5574
5565 { 5575 {
5566 v8::HandleScope handle_scope; 5576 v8::HandleScope handle_scope;
5567 object_a = v8::Persistent<v8::Object>::New(v8::Object::New()); 5577 object_a = v8::Persistent<v8::Object>::New(iso, v8::Object::New());
5568 object_b = v8::Persistent<v8::Object>::New(v8::Object::New()); 5578 object_b = v8::Persistent<v8::Object>::New(iso, v8::Object::New());
5569 } 5579 }
5570 5580
5571 v8::Isolate* isolate = v8::Isolate::GetCurrent();
5572 bool object_a_disposed = false; 5581 bool object_a_disposed = false;
5573 bool object_b_disposed = false; 5582 bool object_b_disposed = false;
5574 object_a.MakeWeak(&object_a_disposed, &DisposeAndSetFlag); 5583 object_a.MakeWeak(iso, &object_a_disposed, &DisposeAndSetFlag);
5575 object_b.MakeWeak(&object_b_disposed, &DisposeAndSetFlag); 5584 object_b.MakeWeak(iso, &object_b_disposed, &DisposeAndSetFlag);
5576 CHECK(!object_a.IsIndependent()); 5585 CHECK(!object_b.IsIndependent(iso));
5577 CHECK(!object_b.IsIndependent(isolate)); 5586 object_a.MarkIndependent(iso);
5578 object_a.MarkIndependent(); 5587 object_b.MarkIndependent(iso);
5579 object_b.MarkIndependent(isolate); 5588 CHECK(object_b.IsIndependent(iso));
5580 CHECK(object_a.IsIndependent());
5581 CHECK(object_b.IsIndependent(isolate));
5582 HEAP->PerformScavenge(); 5589 HEAP->PerformScavenge();
5583 CHECK(object_a_disposed); 5590 CHECK(object_a_disposed);
5584 CHECK(object_b_disposed); 5591 CHECK(object_b_disposed);
5585 } 5592 }
5586 5593
5587 5594
5588 static void InvokeScavenge() { 5595 static void InvokeScavenge() {
5589 HEAP->PerformScavenge(); 5596 HEAP->PerformScavenge();
5590 } 5597 }
5591 5598
5592 5599
5593 static void InvokeMarkSweep() { 5600 static void InvokeMarkSweep() {
5594 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 5601 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
5595 } 5602 }
5596 5603
5597 5604
5598 static void ForceScavenge(v8::Persistent<v8::Value> obj, void* data) { 5605 static void ForceScavenge(v8::Isolate* isolate,
5599 obj.Dispose(); 5606 v8::Persistent<v8::Value> obj,
5607 void* data) {
5608 obj.Dispose(isolate);
5600 obj.Clear(); 5609 obj.Clear();
5601 *(reinterpret_cast<bool*>(data)) = true; 5610 *(reinterpret_cast<bool*>(data)) = true;
5602 InvokeScavenge(); 5611 InvokeScavenge();
5603 } 5612 }
5604 5613
5605 5614
5606 static void ForceMarkSweep(v8::Persistent<v8::Value> obj, void* data) { 5615 static void ForceMarkSweep(v8::Isolate* isolate,
5607 obj.Dispose(); 5616 v8::Persistent<v8::Value> obj,
5617 void* data) {
5618 obj.Dispose(isolate);
5608 obj.Clear(); 5619 obj.Clear();
5609 *(reinterpret_cast<bool*>(data)) = true; 5620 *(reinterpret_cast<bool*>(data)) = true;
5610 InvokeMarkSweep(); 5621 InvokeMarkSweep();
5611 } 5622 }
5612 5623
5613 5624
5614 THREADED_TEST(GCFromWeakCallbacks) { 5625 THREADED_TEST(GCFromWeakCallbacks) {
5615 v8::Persistent<Context> context = Context::New(); 5626 v8::Persistent<Context> context = Context::New();
5627 v8::Isolate* isolate = context->GetIsolate();
5616 Context::Scope context_scope(context); 5628 Context::Scope context_scope(context);
5617 5629
5618 static const int kNumberOfGCTypes = 2; 5630 static const int kNumberOfGCTypes = 2;
5619 v8::WeakReferenceCallback gc_forcing_callback[kNumberOfGCTypes] = 5631 v8::NearDeathCallback gc_forcing_callback[kNumberOfGCTypes] =
5620 {&ForceScavenge, &ForceMarkSweep}; 5632 {&ForceScavenge, &ForceMarkSweep};
5621 5633
5622 typedef void (*GCInvoker)(); 5634 typedef void (*GCInvoker)();
5623 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep}; 5635 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep};
5624 5636
5625 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) { 5637 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) {
5626 for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) { 5638 for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) {
5627 v8::Persistent<v8::Object> object; 5639 v8::Persistent<v8::Object> object;
5628 { 5640 {
5629 v8::HandleScope handle_scope; 5641 v8::HandleScope handle_scope;
5630 object = v8::Persistent<v8::Object>::New(v8::Object::New()); 5642 object = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
5631 } 5643 }
5632 bool disposed = false; 5644 bool disposed = false;
5633 object.MakeWeak(&disposed, gc_forcing_callback[inner_gc]); 5645 object.MakeWeak(isolate, &disposed, gc_forcing_callback[inner_gc]);
5634 object.MarkIndependent(); 5646 object.MarkIndependent(isolate);
5635 invoke_gc[outer_gc](); 5647 invoke_gc[outer_gc]();
5636 CHECK(disposed); 5648 CHECK(disposed);
5637 } 5649 }
5638 } 5650 }
5639 } 5651 }
5640 5652
5641 5653
5642 static void RevivingCallback(v8::Persistent<v8::Value> obj, void* data) { 5654 static void RevivingCallback(v8::Isolate* isolate,
5643 obj.ClearWeak(); 5655 v8::Persistent<v8::Value> obj,
5656 void* data) {
5657 obj.ClearWeak(isolate);
5644 *(reinterpret_cast<bool*>(data)) = true; 5658 *(reinterpret_cast<bool*>(data)) = true;
5645 } 5659 }
5646 5660
5647 5661
5648 THREADED_TEST(IndependentHandleRevival) { 5662 THREADED_TEST(IndependentHandleRevival) {
5649 v8::Persistent<Context> context = Context::New(); 5663 v8::Persistent<Context> context = Context::New();
5650 Context::Scope context_scope(context); 5664 Context::Scope context_scope(context);
5665 v8::Isolate* isolate = context->GetIsolate();
5651 5666
5652 v8::Persistent<v8::Object> object; 5667 v8::Persistent<v8::Object> object;
5653 { 5668 {
5654 v8::HandleScope handle_scope; 5669 v8::HandleScope handle_scope;
5655 object = v8::Persistent<v8::Object>::New(v8::Object::New()); 5670 object = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
5656 object->Set(v8_str("x"), v8::Integer::New(1)); 5671 object->Set(v8_str("x"), v8::Integer::New(1));
5657 v8::Local<String> y_str = v8_str("y"); 5672 v8::Local<String> y_str = v8_str("y");
5658 object->Set(y_str, y_str); 5673 object->Set(y_str, y_str);
5659 } 5674 }
5660 bool revived = false; 5675 bool revived = false;
5661 object.MakeWeak(&revived, &RevivingCallback); 5676 object.MakeWeak(isolate, &revived, &RevivingCallback);
5662 object.MarkIndependent(); 5677 object.MarkIndependent(isolate);
5663 HEAP->PerformScavenge(); 5678 HEAP->PerformScavenge();
5664 CHECK(revived); 5679 CHECK(revived);
5665 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 5680 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
5666 { 5681 {
5667 v8::HandleScope handle_scope; 5682 v8::HandleScope handle_scope;
5668 v8::Local<String> y_str = v8_str("y"); 5683 v8::Local<String> y_str = v8_str("y");
5669 CHECK_EQ(v8::Integer::New(1), object->Get(v8_str("x"))); 5684 CHECK_EQ(v8::Integer::New(1), object->Get(v8_str("x")));
5670 CHECK(object->Get(y_str)->Equals(y_str)); 5685 CHECK(object->Get(y_str)->Equals(y_str));
5671 } 5686 }
5672 } 5687 }
(...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after
6748 v8::Handle<Script> script2 = 6763 v8::Handle<Script> script2 =
6749 v8_compile("othercontext.foo = 333; othercontext[0] = 888;"); 6764 v8_compile("othercontext.foo = 333; othercontext[0] = 888;");
6750 script2->Run(); 6765 script2->Run();
6751 v8::Handle<Value> foo2 = global0->Get(v8_str("foo")); 6766 v8::Handle<Value> foo2 = global0->Get(v8_str("foo"));
6752 CHECK_EQ(333, foo2->Int32Value()); 6767 CHECK_EQ(333, foo2->Int32Value());
6753 v8::Handle<Value> z2 = global0->Get(v8_str("0")); 6768 v8::Handle<Value> z2 = global0->Get(v8_str("0"));
6754 CHECK_EQ(888, z2->Int32Value()); 6769 CHECK_EQ(888, z2->Int32Value());
6755 } 6770 }
6756 6771
6757 context1->Exit(); 6772 context1->Exit();
6758 context1.Dispose(); 6773 context1.Dispose(context1->GetIsolate());
6759 6774
6760 context0->Exit(); 6775 context0->Exit();
6761 context0.Dispose(); 6776 context0.Dispose(context0->GetIsolate());
6762 } 6777 }
6763 6778
6764 6779
6765 THREADED_TEST(SecurityChecks) { 6780 THREADED_TEST(SecurityChecks) {
6766 v8::HandleScope handle_scope; 6781 v8::HandleScope handle_scope;
6767 LocalContext env1; 6782 LocalContext env1;
6768 v8::Persistent<Context> env2 = Context::New(); 6783 v8::Persistent<Context> env2 = Context::New();
6769 6784
6770 Local<Value> foo = v8_str("foo"); 6785 Local<Value> foo = v8_str("foo");
6771 Local<Value> bar = v8_str("bar"); 6786 Local<Value> bar = v8_str("bar");
(...skipping 23 matching lines...) Expand all
6795 { 6810 {
6796 env2->SetSecurityToken(bar); 6811 env2->SetSecurityToken(bar);
6797 Context::Scope scope_env2(env2); 6812 Context::Scope scope_env2(env2);
6798 6813
6799 // Call cross_domain_call, it should throw an exception 6814 // Call cross_domain_call, it should throw an exception
6800 v8::TryCatch try_catch; 6815 v8::TryCatch try_catch;
6801 Function::Cast(*spy2)->Call(env2->Global(), 0, NULL); 6816 Function::Cast(*spy2)->Call(env2->Global(), 0, NULL);
6802 CHECK(try_catch.HasCaught()); 6817 CHECK(try_catch.HasCaught());
6803 } 6818 }
6804 6819
6805 env2.Dispose(); 6820 env2.Dispose(env2->GetIsolate());
6806 } 6821 }
6807 6822
6808 6823
6809 // Regression test case for issue 1183439. 6824 // Regression test case for issue 1183439.
6810 THREADED_TEST(SecurityChecksForPrototypeChain) { 6825 THREADED_TEST(SecurityChecksForPrototypeChain) {
6811 v8::HandleScope scope; 6826 v8::HandleScope scope;
6812 LocalContext current; 6827 LocalContext current;
6813 v8::Persistent<Context> other = Context::New(); 6828 v8::Persistent<Context> other = Context::New();
6814 6829
6815 // Change context to be able to get to the Object function in the 6830 // Change context to be able to get to the Object function in the
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
6864 // Try to read the properties from f and make sure that the access 6879 // Try to read the properties from f and make sure that the access
6865 // gets stopped by the security checks on the other global object. 6880 // gets stopped by the security checks on the other global object.
6866 Local<Script> access_f2 = v8_compile("f.foo"); 6881 Local<Script> access_f2 = v8_compile("f.foo");
6867 Local<Script> access_f3 = v8_compile("f[99]"); 6882 Local<Script> access_f3 = v8_compile("f[99]");
6868 for (int k = 0; k < 5; k++) { 6883 for (int k = 0; k < 5; k++) {
6869 CHECK(!access_f2->Run()->Equals(v8_num(100))); 6884 CHECK(!access_f2->Run()->Equals(v8_num(100)));
6870 CHECK(access_f2->Run()->IsUndefined()); 6885 CHECK(access_f2->Run()->IsUndefined());
6871 CHECK(!access_f3->Run()->Equals(v8_num(101))); 6886 CHECK(!access_f3->Run()->Equals(v8_num(101)));
6872 CHECK(access_f3->Run()->IsUndefined()); 6887 CHECK(access_f3->Run()->IsUndefined());
6873 } 6888 }
6874 other.Dispose(); 6889 other.Dispose(other->GetIsolate());
6875 } 6890 }
6876 6891
6877 6892
6878 THREADED_TEST(CrossDomainDelete) { 6893 THREADED_TEST(CrossDomainDelete) {
6879 v8::HandleScope handle_scope; 6894 v8::HandleScope handle_scope;
6880 LocalContext env1; 6895 LocalContext env1;
6881 v8::Persistent<Context> env2 = Context::New(); 6896 v8::Persistent<Context> env2 = Context::New();
6882 6897
6883 Local<Value> foo = v8_str("foo"); 6898 Local<Value> foo = v8_str("foo");
6884 Local<Value> bar = v8_str("bar"); 6899 Local<Value> bar = v8_str("bar");
(...skipping 12 matching lines...) Expand all
6897 Local<Value> result = 6912 Local<Value> result =
6898 Script::Compile(v8_str("delete env1.prop"))->Run(); 6913 Script::Compile(v8_str("delete env1.prop"))->Run();
6899 CHECK(result->IsFalse()); 6914 CHECK(result->IsFalse());
6900 } 6915 }
6901 6916
6902 // Check that env1.prop still exists. 6917 // Check that env1.prop still exists.
6903 Local<Value> v = env1->Global()->Get(v8_str("prop")); 6918 Local<Value> v = env1->Global()->Get(v8_str("prop"));
6904 CHECK(v->IsNumber()); 6919 CHECK(v->IsNumber());
6905 CHECK_EQ(3, v->Int32Value()); 6920 CHECK_EQ(3, v->Int32Value());
6906 6921
6907 env2.Dispose(); 6922 env2.Dispose(env2->GetIsolate());
6908 } 6923 }
6909 6924
6910 6925
6911 THREADED_TEST(CrossDomainIsPropertyEnumerable) { 6926 THREADED_TEST(CrossDomainIsPropertyEnumerable) {
6912 v8::HandleScope handle_scope; 6927 v8::HandleScope handle_scope;
6913 LocalContext env1; 6928 LocalContext env1;
6914 v8::Persistent<Context> env2 = Context::New(); 6929 v8::Persistent<Context> env2 = Context::New();
6915 6930
6916 Local<Value> foo = v8_str("foo"); 6931 Local<Value> foo = v8_str("foo");
6917 Local<Value> bar = v8_str("bar"); 6932 Local<Value> bar = v8_str("bar");
(...skipping 14 matching lines...) Expand all
6932 } 6947 }
6933 6948
6934 // Change env2 to a different domain and test again. 6949 // Change env2 to a different domain and test again.
6935 env2->SetSecurityToken(bar); 6950 env2->SetSecurityToken(bar);
6936 { 6951 {
6937 Context::Scope scope_env2(env2); 6952 Context::Scope scope_env2(env2);
6938 Local<Value> result = Script::Compile(test)->Run(); 6953 Local<Value> result = Script::Compile(test)->Run();
6939 CHECK(result->IsFalse()); 6954 CHECK(result->IsFalse());
6940 } 6955 }
6941 6956
6942 env2.Dispose(); 6957 env2.Dispose(env2->GetIsolate());
6943 } 6958 }
6944 6959
6945 6960
6946 THREADED_TEST(CrossDomainForIn) { 6961 THREADED_TEST(CrossDomainForIn) {
6947 v8::HandleScope handle_scope; 6962 v8::HandleScope handle_scope;
6948 LocalContext env1; 6963 LocalContext env1;
6949 v8::Persistent<Context> env2 = Context::New(); 6964 v8::Persistent<Context> env2 = Context::New();
6950 6965
6951 Local<Value> foo = v8_str("foo"); 6966 Local<Value> foo = v8_str("foo");
6952 Local<Value> bar = v8_str("bar"); 6967 Local<Value> bar = v8_str("bar");
(...skipping 12 matching lines...) Expand all
6965 env2->SetSecurityToken(bar); 6980 env2->SetSecurityToken(bar);
6966 { 6981 {
6967 Context::Scope scope_env2(env2); 6982 Context::Scope scope_env2(env2);
6968 Local<Value> result = 6983 Local<Value> result =
6969 CompileRun("(function(){var obj = {'__proto__':env1};" 6984 CompileRun("(function(){var obj = {'__proto__':env1};"
6970 "for (var p in obj)" 6985 "for (var p in obj)"
6971 " if (p == 'prop') return false;" 6986 " if (p == 'prop') return false;"
6972 "return true;})()"); 6987 "return true;})()");
6973 CHECK(result->IsTrue()); 6988 CHECK(result->IsTrue());
6974 } 6989 }
6975 env2.Dispose(); 6990 env2.Dispose(env2->GetIsolate());
6976 } 6991 }
6977 6992
6978 6993
6979 TEST(ContextDetachGlobal) { 6994 TEST(ContextDetachGlobal) {
6980 v8::HandleScope handle_scope; 6995 v8::HandleScope handle_scope;
6981 LocalContext env1; 6996 LocalContext env1;
6982 v8::Persistent<Context> env2 = Context::New(); 6997 v8::Persistent<Context> env2 = Context::New();
6983 6998
6984 Local<v8::Object> global1 = env1->Global(); 6999 Local<v8::Object> global1 = env1->Global();
6985 7000
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
7028 CHECK(!try_catch.HasCaught()); 7043 CHECK(!try_catch.HasCaught());
7029 CHECK_EQ(1, r->Int32Value()); 7044 CHECK_EQ(1, r->Int32Value());
7030 } 7045 }
7031 7046
7032 // Check that env3 is not accessible from env1 7047 // Check that env3 is not accessible from env1
7033 { 7048 {
7034 Local<Value> r = global3->Get(v8_str("prop2")); 7049 Local<Value> r = global3->Get(v8_str("prop2"));
7035 CHECK(r->IsUndefined()); 7050 CHECK(r->IsUndefined());
7036 } 7051 }
7037 7052
7038 env2.Dispose(); 7053 env2.Dispose(env2->GetIsolate());
7039 env3.Dispose(); 7054 env3.Dispose(env3->GetIsolate());
7040 } 7055 }
7041 7056
7042 7057
7043 TEST(DetachAndReattachGlobal) { 7058 TEST(DetachAndReattachGlobal) {
7044 v8::HandleScope scope; 7059 v8::HandleScope scope;
7045 LocalContext env1; 7060 LocalContext env1;
7046 7061
7047 // Create second environment. 7062 // Create second environment.
7048 v8::Persistent<Context> env2 = Context::New(); 7063 v8::Persistent<Context> env2 = Context::New();
7049 7064
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
7107 // Detach the global for env3 and reattach it to env2. 7122 // Detach the global for env3 and reattach it to env2.
7108 env3->DetachGlobal(); 7123 env3->DetachGlobal();
7109 env2->ReattachGlobal(global2); 7124 env2->ReattachGlobal(global2);
7110 7125
7111 // Check that we have access to other.p again in env1. |other| is now 7126 // Check that we have access to other.p again in env1. |other| is now
7112 // the global object for env2 which has the same security token as env1. 7127 // the global object for env2 which has the same security token as env1.
7113 result = CompileRun("other.p"); 7128 result = CompileRun("other.p");
7114 CHECK(result->IsInt32()); 7129 CHECK(result->IsInt32());
7115 CHECK_EQ(42, result->Int32Value()); 7130 CHECK_EQ(42, result->Int32Value());
7116 7131
7117 env2.Dispose(); 7132 env2.Dispose(env2->GetIsolate());
7118 env3.Dispose(); 7133 env3.Dispose(env3->GetIsolate());
7119 } 7134 }
7120 7135
7121 7136
7122 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false }; 7137 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false };
7123 static bool NamedAccessBlocker(Local<v8::Object> global, 7138 static bool NamedAccessBlocker(Local<v8::Object> global,
7124 Local<Value> name, 7139 Local<Value> name,
7125 v8::AccessType type, 7140 v8::AccessType type,
7126 Local<Value> data) { 7141 Local<Value> data) {
7127 return Context::GetCurrent()->Global()->Equals(global) || 7142 return Context::GetCurrent()->Global()->Equals(global) ||
7128 allowed_access_type[type]; 7143 allowed_access_type[type];
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
7398 CompileRun("(function(){var obj = {'__proto__':other};" 7413 CompileRun("(function(){var obj = {'__proto__':other};"
7399 "for (var p in obj)" 7414 "for (var p in obj)"
7400 " if (p == 'accessible_prop' || p == 'blocked_prop') {" 7415 " if (p == 'accessible_prop' || p == 'blocked_prop') {"
7401 " return false;" 7416 " return false;"
7402 " }" 7417 " }"
7403 "return true;})()"); 7418 "return true;})()");
7404 CHECK(value->IsTrue()); 7419 CHECK(value->IsTrue());
7405 7420
7406 context1->Exit(); 7421 context1->Exit();
7407 context0->Exit(); 7422 context0->Exit();
7408 context1.Dispose(); 7423 context1.Dispose(context1->GetIsolate());
7409 context0.Dispose(); 7424 context0.Dispose(context0->GetIsolate());
7410 } 7425 }
7411 7426
7412 7427
7413 TEST(AccessControlES5) { 7428 TEST(AccessControlES5) {
7414 v8::HandleScope handle_scope; 7429 v8::HandleScope handle_scope;
7415 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 7430 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
7416 7431
7417 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, 7432 global_template->SetAccessCheckCallbacks(NamedAccessBlocker,
7418 IndexedAccessBlocker); 7433 IndexedAccessBlocker);
7419 7434
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
7527 // proxy object. Accessing the object that requires access checks 7542 // proxy object. Accessing the object that requires access checks
7528 // is blocked by the access checks on the object itself. 7543 // is blocked by the access checks on the object itself.
7529 value = CompileRun("Object.getOwnPropertyNames(other).length == 0"); 7544 value = CompileRun("Object.getOwnPropertyNames(other).length == 0");
7530 CHECK(value->IsTrue()); 7545 CHECK(value->IsTrue());
7531 7546
7532 value = CompileRun("Object.getOwnPropertyNames(object).length == 0"); 7547 value = CompileRun("Object.getOwnPropertyNames(object).length == 0");
7533 CHECK(value->IsTrue()); 7548 CHECK(value->IsTrue());
7534 7549
7535 context1->Exit(); 7550 context1->Exit();
7536 context0->Exit(); 7551 context0->Exit();
7537 context1.Dispose(); 7552 context1.Dispose(context1->GetIsolate());
7538 context0.Dispose(); 7553 context0.Dispose(context0->GetIsolate());
7539 } 7554 }
7540 7555
7541 7556
7542 static v8::Handle<v8::Array> NamedPropertyEnumerator(const AccessorInfo& info) { 7557 static v8::Handle<v8::Array> NamedPropertyEnumerator(const AccessorInfo& info) {
7543 v8::Handle<v8::Array> result = v8::Array::New(1); 7558 v8::Handle<v8::Array> result = v8::Array::New(1);
7544 result->Set(0, v8_str("x")); 7559 result->Set(0, v8_str("x"));
7545 return result; 7560 return result;
7546 } 7561 }
7547 7562
7548 7563
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
7611 // Should return 10, instead of 11 7626 // Should return 10, instead of 11
7612 v8::Handle<Value> value = v8_compile("other.accessible")->Run(); 7627 v8::Handle<Value> value = v8_compile("other.accessible")->Run();
7613 CHECK(value->IsNumber()); 7628 CHECK(value->IsNumber());
7614 CHECK_EQ(10, value->Int32Value()); 7629 CHECK_EQ(10, value->Int32Value());
7615 7630
7616 value = v8_compile("other.unreachable")->Run(); 7631 value = v8_compile("other.unreachable")->Run();
7617 CHECK(value->IsUndefined()); 7632 CHECK(value->IsUndefined());
7618 7633
7619 context1->Exit(); 7634 context1->Exit();
7620 context0->Exit(); 7635 context0->Exit();
7621 context1.Dispose(); 7636 context1.Dispose(context1->GetIsolate());
7622 context0.Dispose(); 7637 context0.Dispose(context0->GetIsolate());
7623 } 7638 }
7624 7639
7625 7640
7626 static int named_access_count = 0; 7641 static int named_access_count = 0;
7627 static int indexed_access_count = 0; 7642 static int indexed_access_count = 0;
7628 7643
7629 static bool NamedAccessCounter(Local<v8::Object> global, 7644 static bool NamedAccessCounter(Local<v8::Object> global,
7630 Local<Value> name, 7645 Local<Value> name,
7631 v8::AccessType type, 7646 v8::AccessType type,
7632 Local<Value> data) { 7647 Local<Value> data) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
7746 7761
7747 // Force the call inline cache into dictionary probing mode. 7762 // Force the call inline cache into dictionary probing mode.
7748 CompileRun("o.f = function() {}; testCallNormal(o)"); 7763 CompileRun("o.f = function() {}; testCallNormal(o)");
7749 // Test that the named access check is still called for each 7764 // Test that the named access check is still called for each
7750 // invocation of the function. 7765 // invocation of the function.
7751 value = CompileRun("testCallNormal(obj)"); 7766 value = CompileRun("testCallNormal(obj)");
7752 CHECK_EQ(106, named_access_count); 7767 CHECK_EQ(106, named_access_count);
7753 7768
7754 context1->Exit(); 7769 context1->Exit();
7755 context0->Exit(); 7770 context0->Exit();
7756 context1.Dispose(); 7771 context1.Dispose(context1->GetIsolate());
7757 context0.Dispose(); 7772 context0.Dispose(context0->GetIsolate());
7758 } 7773 }
7759 7774
7760 7775
7761 static bool NamedAccessFlatten(Local<v8::Object> global, 7776 static bool NamedAccessFlatten(Local<v8::Object> global,
7762 Local<Value> name, 7777 Local<Value> name,
7763 v8::AccessType type, 7778 v8::AccessType type,
7764 Local<Value> data) { 7779 Local<Value> data) {
7765 char buf[100]; 7780 char buf[100];
7766 int len; 7781 int len;
7767 7782
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
7821 v8::Handle<v8::Object> global1 = context1->Global(); 7836 v8::Handle<v8::Object> global1 = context1->Global();
7822 global1->Set(v8_str("obj"), object); 7837 global1->Set(v8_str("obj"), object);
7823 7838
7824 v8::Handle<Value> value; 7839 v8::Handle<Value> value;
7825 7840
7826 value = v8_compile("var p = 'as' + 'df';")->Run(); 7841 value = v8_compile("var p = 'as' + 'df';")->Run();
7827 value = v8_compile("obj[p];")->Run(); 7842 value = v8_compile("obj[p];")->Run();
7828 7843
7829 context1->Exit(); 7844 context1->Exit();
7830 context0->Exit(); 7845 context0->Exit();
7831 context1.Dispose(); 7846 context1.Dispose(context1->GetIsolate());
7832 context0.Dispose(); 7847 context0.Dispose(context0->GetIsolate());
7833 } 7848 }
7834 7849
7835 7850
7836 static v8::Handle<Value> AccessControlNamedGetter( 7851 static v8::Handle<Value> AccessControlNamedGetter(
7837 Local<String>, const AccessorInfo&) { 7852 Local<String>, const AccessorInfo&) {
7838 return v8::Integer::New(42); 7853 return v8::Integer::New(42);
7839 } 7854 }
7840 7855
7841 7856
7842 static v8::Handle<Value> AccessControlNamedSetter( 7857 static v8::Handle<Value> AccessControlNamedSetter(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
7913 // time eventhough there is an interceptor on the object. 7928 // time eventhough there is an interceptor on the object.
7914 value = v8_compile("for (var i = 0; i < 10; i++) obj[0] = 1;")->Run(); 7929 value = v8_compile("for (var i = 0; i < 10; i++) obj[0] = 1;")->Run();
7915 value = v8_compile("for (var i = 0; i < 10; i++) obj[0];" 7930 value = v8_compile("for (var i = 0; i < 10; i++) obj[0];"
7916 "obj[0]")->Run(); 7931 "obj[0]")->Run();
7917 CHECK(value->IsNumber()); 7932 CHECK(value->IsNumber());
7918 CHECK_EQ(42, value->Int32Value()); 7933 CHECK_EQ(42, value->Int32Value());
7919 CHECK_EQ(21, indexed_access_count); 7934 CHECK_EQ(21, indexed_access_count);
7920 7935
7921 context1->Exit(); 7936 context1->Exit();
7922 context0->Exit(); 7937 context0->Exit();
7923 context1.Dispose(); 7938 context1.Dispose(context1->GetIsolate());
7924 context0.Dispose(); 7939 context0.Dispose(context0->GetIsolate());
7925 } 7940 }
7926 7941
7927 7942
7928 THREADED_TEST(Version) { 7943 THREADED_TEST(Version) {
7929 v8::V8::GetVersion(); 7944 v8::V8::GetVersion();
7930 } 7945 }
7931 7946
7932 7947
7933 static v8::Handle<Value> InstanceFunctionCallback(const v8::Arguments& args) { 7948 static v8::Handle<Value> InstanceFunctionCallback(const v8::Arguments& args) {
7934 ApiTestFuzzer::Fuzz(); 7949 ApiTestFuzzer::Fuzz();
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after
8804 context1->Global()->Set(v8_str("fun"), fun); 8819 context1->Global()->Set(v8_str("fun"), fun);
8805 v8::Handle<v8::Value> x_value = CompileRun("fun('x')"); 8820 v8::Handle<v8::Value> x_value = CompileRun("fun('x')");
8806 CHECK_EQ(42, x_value->Int32Value()); 8821 CHECK_EQ(42, x_value->Int32Value());
8807 context0->DetachGlobal(); 8822 context0->DetachGlobal();
8808 v8::TryCatch catcher; 8823 v8::TryCatch catcher;
8809 x_value = CompileRun("fun('x')"); 8824 x_value = CompileRun("fun('x')");
8810 CHECK(x_value.IsEmpty()); 8825 CHECK(x_value.IsEmpty());
8811 CHECK(catcher.HasCaught()); 8826 CHECK(catcher.HasCaught());
8812 context1->Exit(); 8827 context1->Exit();
8813 8828
8814 context1.Dispose(); 8829 context1.Dispose(context1->GetIsolate());
8815 context0.Dispose(); 8830 context0.Dispose(context0->GetIsolate());
8816 } 8831 }
8817 8832
8818 8833
8819 THREADED_TEST(CrossLazyLoad) { 8834 THREADED_TEST(CrossLazyLoad) {
8820 v8::HandleScope scope; 8835 v8::HandleScope scope;
8821 LocalContext other; 8836 LocalContext other;
8822 LocalContext current; 8837 LocalContext current;
8823 8838
8824 Local<String> token = v8_str("<security token>"); 8839 Local<String> token = v8_str("<security token>");
8825 other->SetSecurityToken(token); 8840 other->SetSecurityToken(token);
(...skipping 2496 matching lines...) Expand 10 before | Expand all | Expand 10 after
11322 } 11337 }
11323 v8::V8::ContextDisposedNotification(); 11338 v8::V8::ContextDisposedNotification();
11324 CheckSurvivingGlobalObjectsCount(0); 11339 CheckSurvivingGlobalObjectsCount(0);
11325 } 11340 }
11326 } 11341 }
11327 11342
11328 11343
11329 v8::Persistent<v8::Object> some_object; 11344 v8::Persistent<v8::Object> some_object;
11330 v8::Persistent<v8::Object> bad_handle; 11345 v8::Persistent<v8::Object> bad_handle;
11331 11346
11332 void NewPersistentHandleCallback(v8::Persistent<v8::Value> handle, void*) { 11347 void NewPersistentHandleCallback(v8::Isolate* isolate,
11348 v8::Persistent<v8::Value> handle,
11349 void*) {
11333 v8::HandleScope scope; 11350 v8::HandleScope scope;
11334 bad_handle = v8::Persistent<v8::Object>::New(some_object); 11351 bad_handle = v8::Persistent<v8::Object>::New(isolate, some_object);
11335 handle.Dispose(); 11352 handle.Dispose(isolate);
11336 } 11353 }
11337 11354
11338 11355
11339 THREADED_TEST(NewPersistentHandleFromWeakCallback) { 11356 THREADED_TEST(NewPersistentHandleFromWeakCallback) {
11340 LocalContext context; 11357 LocalContext context;
11358 v8::Isolate* isolate = context->GetIsolate();
11341 11359
11342 v8::Persistent<v8::Object> handle1, handle2; 11360 v8::Persistent<v8::Object> handle1, handle2;
11343 { 11361 {
11344 v8::HandleScope scope; 11362 v8::HandleScope scope;
11345 some_object = v8::Persistent<v8::Object>::New(v8::Object::New()); 11363 some_object = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11346 handle1 = v8::Persistent<v8::Object>::New(v8::Object::New()); 11364 handle1 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11347 handle2 = v8::Persistent<v8::Object>::New(v8::Object::New()); 11365 handle2 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11348 } 11366 }
11349 // Note: order is implementation dependent alas: currently 11367 // Note: order is implementation dependent alas: currently
11350 // global handle nodes are processed by PostGarbageCollectionProcessing 11368 // global handle nodes are processed by PostGarbageCollectionProcessing
11351 // in reverse allocation order, so if second allocated handle is deleted, 11369 // in reverse allocation order, so if second allocated handle is deleted,
11352 // weak callback of the first handle would be able to 'reallocate' it. 11370 // weak callback of the first handle would be able to 'reallocate' it.
11353 handle1.MakeWeak(NULL, NewPersistentHandleCallback); 11371 handle1.MakeWeak(isolate, NULL, NewPersistentHandleCallback);
11354 handle2.Dispose(); 11372 handle2.Dispose(isolate);
11355 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 11373 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
11356 } 11374 }
11357 11375
11358 11376
11359 v8::Persistent<v8::Object> to_be_disposed; 11377 v8::Persistent<v8::Object> to_be_disposed;
11360 11378
11361 void DisposeAndForceGcCallback(v8::Persistent<v8::Value> handle, void*) { 11379 void DisposeAndForceGcCallback(v8::Isolate* isolate,
11362 to_be_disposed.Dispose(); 11380 v8::Persistent<v8::Value> handle,
11381 void*) {
11382 to_be_disposed.Dispose(isolate);
11363 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 11383 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
11364 handle.Dispose(); 11384 handle.Dispose(isolate);
11365 } 11385 }
11366 11386
11367 11387
11368 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) { 11388 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) {
11369 LocalContext context; 11389 LocalContext context;
11390 v8::Isolate* isolate = context->GetIsolate();
11370 11391
11371 v8::Persistent<v8::Object> handle1, handle2; 11392 v8::Persistent<v8::Object> handle1, handle2;
11372 { 11393 {
11373 v8::HandleScope scope; 11394 v8::HandleScope scope;
11374 handle1 = v8::Persistent<v8::Object>::New(v8::Object::New()); 11395 handle1 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11375 handle2 = v8::Persistent<v8::Object>::New(v8::Object::New()); 11396 handle2 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11376 } 11397 }
11377 handle1.MakeWeak(NULL, DisposeAndForceGcCallback); 11398 handle1.MakeWeak(isolate, NULL, DisposeAndForceGcCallback);
11378 to_be_disposed = handle2; 11399 to_be_disposed = handle2;
11379 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 11400 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
11380 } 11401 }
11381 11402
11382 void DisposingCallback(v8::Persistent<v8::Value> handle, void*) { 11403 void DisposingCallback(v8::Isolate* isolate,
11383 handle.Dispose(); 11404 v8::Persistent<v8::Value> handle,
11405 void*) {
11406 handle.Dispose(isolate);
11384 } 11407 }
11385 11408
11386 void HandleCreatingCallback(v8::Persistent<v8::Value> handle, void*) { 11409 void HandleCreatingCallback(v8::Isolate* isolate,
11410 v8::Persistent<v8::Value> handle,
11411 void*) {
11387 v8::HandleScope scope; 11412 v8::HandleScope scope;
11388 v8::Persistent<v8::Object>::New(v8::Object::New()); 11413 v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11389 handle.Dispose(); 11414 handle.Dispose(isolate);
11390 } 11415 }
11391 11416
11392 11417
11393 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) { 11418 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) {
11394 LocalContext context; 11419 LocalContext context;
11420 v8::Isolate* isolate = context->GetIsolate();
11395 11421
11396 v8::Persistent<v8::Object> handle1, handle2, handle3; 11422 v8::Persistent<v8::Object> handle1, handle2, handle3;
11397 { 11423 {
11398 v8::HandleScope scope; 11424 v8::HandleScope scope;
11399 handle3 = v8::Persistent<v8::Object>::New(v8::Object::New()); 11425 handle3 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11400 handle2 = v8::Persistent<v8::Object>::New(v8::Object::New()); 11426 handle2 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11401 handle1 = v8::Persistent<v8::Object>::New(v8::Object::New()); 11427 handle1 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11402 } 11428 }
11403 handle2.MakeWeak(NULL, DisposingCallback); 11429 handle2.MakeWeak(isolate, NULL, DisposingCallback);
11404 handle3.MakeWeak(NULL, HandleCreatingCallback); 11430 handle3.MakeWeak(isolate, NULL, HandleCreatingCallback);
11405 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 11431 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
11406 } 11432 }
11407 11433
11408 11434
11409 THREADED_TEST(CheckForCrossContextObjectLiterals) { 11435 THREADED_TEST(CheckForCrossContextObjectLiterals) {
11410 v8::V8::Initialize(); 11436 v8::V8::Initialize();
11411 11437
11412 const int nof = 2; 11438 const int nof = 2;
11413 const char* sources[nof] = { 11439 const char* sources[nof] = {
11414 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }", 11440 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }",
(...skipping 25 matching lines...) Expand all
11440 11466
11441 11467
11442 THREADED_TEST(NestedHandleScopeAndContexts) { 11468 THREADED_TEST(NestedHandleScopeAndContexts) {
11443 v8::HandleScope outer; 11469 v8::HandleScope outer;
11444 v8::Persistent<Context> env = Context::New(); 11470 v8::Persistent<Context> env = Context::New();
11445 env->Enter(); 11471 env->Enter();
11446 v8::Handle<Value> value = NestedScope(env); 11472 v8::Handle<Value> value = NestedScope(env);
11447 v8::Handle<String> str(value->ToString()); 11473 v8::Handle<String> str(value->ToString());
11448 CHECK(!str.IsEmpty()); 11474 CHECK(!str.IsEmpty());
11449 env->Exit(); 11475 env->Exit();
11450 env.Dispose(); 11476 env.Dispose(env->GetIsolate());
11451 } 11477 }
11452 11478
11453 11479
11454 static i::Handle<i::JSFunction>* foo_ptr = NULL; 11480 static i::Handle<i::JSFunction>* foo_ptr = NULL;
11455 static int foo_count = 0; 11481 static int foo_count = 0;
11456 static i::Handle<i::JSFunction>* bar_ptr = NULL; 11482 static i::Handle<i::JSFunction>* bar_ptr = NULL;
11457 static int bar_count = 0; 11483 static int bar_count = 0;
11458 11484
11459 11485
11460 static void entry_hook(uintptr_t function, 11486 static void entry_hook(uintptr_t function,
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
11762 CHECK_EQ(cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(-kSize)), 11788 CHECK_EQ(cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(-kSize)),
11763 cast(0)); 11789 cast(0));
11764 } 11790 }
11765 11791
11766 11792
11767 THREADED_TEST(DisposeEnteredContext) { 11793 THREADED_TEST(DisposeEnteredContext) {
11768 v8::HandleScope scope; 11794 v8::HandleScope scope;
11769 LocalContext outer; 11795 LocalContext outer;
11770 { v8::Persistent<v8::Context> inner = v8::Context::New(); 11796 { v8::Persistent<v8::Context> inner = v8::Context::New();
11771 inner->Enter(); 11797 inner->Enter();
11772 inner.Dispose(); 11798 inner.Dispose(inner->GetIsolate());
11773 inner.Clear(); 11799 inner.Clear();
11774 inner->Exit(); 11800 inner->Exit();
11775 } 11801 }
11776 } 11802 }
11777 11803
11778 11804
11779 // Regression test for issue 54, object templates with internal fields 11805 // Regression test for issue 54, object templates with internal fields
11780 // but no accessors or interceptors did not get their internal field 11806 // but no accessors or interceptors did not get their internal field
11781 // count set on instances. 11807 // count set on instances.
11782 THREADED_TEST(Regress54) { 11808 THREADED_TEST(Regress54) {
11783 v8::HandleScope outer; 11809 v8::HandleScope outer;
11784 LocalContext context; 11810 LocalContext context;
11811 v8::Isolate* isolate = context->GetIsolate();
11785 static v8::Persistent<v8::ObjectTemplate> templ; 11812 static v8::Persistent<v8::ObjectTemplate> templ;
11786 if (templ.IsEmpty()) { 11813 if (templ.IsEmpty()) {
11787 v8::HandleScope inner; 11814 v8::HandleScope inner;
11788 v8::Handle<v8::ObjectTemplate> local = v8::ObjectTemplate::New(); 11815 v8::Handle<v8::ObjectTemplate> local = v8::ObjectTemplate::New();
11789 local->SetInternalFieldCount(1); 11816 local->SetInternalFieldCount(1);
11790 templ = v8::Persistent<v8::ObjectTemplate>::New(inner.Close(local)); 11817 templ =
11818 v8::Persistent<v8::ObjectTemplate>::New(isolate, inner.Close(local));
11791 } 11819 }
11792 v8::Handle<v8::Object> result = templ->NewInstance(); 11820 v8::Handle<v8::Object> result = templ->NewInstance();
11793 CHECK_EQ(1, result->InternalFieldCount()); 11821 CHECK_EQ(1, result->InternalFieldCount());
11794 } 11822 }
11795 11823
11796 11824
11797 // If part of the threaded tests, this test makes ThreadingTest fail 11825 // If part of the threaded tests, this test makes ThreadingTest fail
11798 // on mac. 11826 // on mac.
11799 TEST(CatchStackOverflow) { 11827 TEST(CatchStackOverflow) {
11800 v8::HandleScope scope; 11828 v8::HandleScope scope;
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
12469 // Call the constructor function from context0 and check that the 12497 // Call the constructor function from context0 and check that the
12470 // result has the 'x' property. 12498 // result has the 'x' property.
12471 context1->Enter(); 12499 context1->Enter();
12472 context1->Global()->Set(v8_str("other"), context0->Global()); 12500 context1->Global()->Set(v8_str("other"), context0->Global());
12473 Local<Value> value = CompileRun("var instance = new other.C(); instance.x"); 12501 Local<Value> value = CompileRun("var instance = new other.C(); instance.x");
12474 CHECK(value->IsInt32()); 12502 CHECK(value->IsInt32());
12475 CHECK_EQ(42, value->Int32Value()); 12503 CHECK_EQ(42, value->Int32Value());
12476 context1->Exit(); 12504 context1->Exit();
12477 12505
12478 // Dispose the contexts to allow them to be garbage collected. 12506 // Dispose the contexts to allow them to be garbage collected.
12479 context0.Dispose(); 12507 context0.Dispose(context0->GetIsolate());
12480 context1.Dispose(); 12508 context1.Dispose(context1->GetIsolate());
12481 } 12509 }
12482 12510
12483 12511
12484 class RegExpInterruptTest { 12512 class RegExpInterruptTest {
12485 public: 12513 public:
12486 RegExpInterruptTest() : block_(NULL) {} 12514 RegExpInterruptTest() : block_(NULL) {}
12487 ~RegExpInterruptTest() { delete block_; } 12515 ~RegExpInterruptTest() { delete block_; }
12488 void RunTest() { 12516 void RunTest() {
12489 block_ = i::OS::CreateSemaphore(0); 12517 block_ = i::OS::CreateSemaphore(0);
12490 gc_count_ = 0; 12518 gc_count_ = 0;
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
13285 "(function() {" 13313 "(function() {"
13286 " try {" 13314 " try {"
13287 " return f();" 13315 " return f();"
13288 " } catch(e) {" 13316 " } catch(e) {"
13289 " return e.toString();" 13317 " return e.toString();"
13290 " }" 13318 " }"
13291 " })()", 13319 " })()",
13292 "ReferenceError: G is not defined"); 13320 "ReferenceError: G is not defined");
13293 ctx2->Exit(); 13321 ctx2->Exit();
13294 ctx1->Exit(); 13322 ctx1->Exit();
13295 ctx1.Dispose(); 13323 ctx1.Dispose(ctx1->GetIsolate());
13296 } 13324 }
13297 ctx2.Dispose(); 13325 ctx2.Dispose(ctx2->GetIsolate());
13298 } 13326 }
13299 13327
13300 13328
13301 v8::Persistent<Context> calling_context0; 13329 v8::Persistent<Context> calling_context0;
13302 v8::Persistent<Context> calling_context1; 13330 v8::Persistent<Context> calling_context1;
13303 v8::Persistent<Context> calling_context2; 13331 v8::Persistent<Context> calling_context2;
13304 13332
13305 13333
13306 // Check that the call to the callback is initiated in 13334 // Check that the call to the callback is initiated in
13307 // calling_context2, the directly calling context is calling_context1 13335 // calling_context2, the directly calling context is calling_context1
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
13346 13374
13347 // Expose context1 in context2 and call the callback function in 13375 // Expose context1 in context2 and call the callback function in
13348 // context0 indirectly through f in context1. 13376 // context0 indirectly through f in context1.
13349 calling_context2->Enter(); 13377 calling_context2->Enter();
13350 calling_context2->Global()->Set(v8_str("context1"), 13378 calling_context2->Global()->Set(v8_str("context1"),
13351 calling_context1->Global()); 13379 calling_context1->Global());
13352 CompileRun("context1.f()"); 13380 CompileRun("context1.f()");
13353 calling_context2->Exit(); 13381 calling_context2->Exit();
13354 13382
13355 // Dispose the contexts to allow them to be garbage collected. 13383 // Dispose the contexts to allow them to be garbage collected.
13356 calling_context0.Dispose(); 13384 calling_context0.Dispose(calling_context0->GetIsolate());
13357 calling_context1.Dispose(); 13385 calling_context1.Dispose(calling_context1->GetIsolate());
13358 calling_context2.Dispose(); 13386 calling_context2.Dispose(calling_context2->GetIsolate());
13359 calling_context0.Clear(); 13387 calling_context0.Clear();
13360 calling_context1.Clear(); 13388 calling_context1.Clear();
13361 calling_context2.Clear(); 13389 calling_context2.Clear();
13362 } 13390 }
13363 13391
13364 13392
13365 // Check that a variable declaration with no explicit initialization 13393 // Check that a variable declaration with no explicit initialization
13366 // value does shadow an existing property in the prototype chain. 13394 // value does shadow an existing property in the prototype chain.
13367 THREADED_TEST(InitGlobalVarInProtoChain) { 13395 THREADED_TEST(InitGlobalVarInProtoChain) {
13368 i::FLAG_es52_globals = true; 13396 i::FLAG_es52_globals = true;
(...skipping 1701 matching lines...) Expand 10 before | Expand all | Expand 10 after
15070 LocalContext env; 15098 LocalContext env;
15071 intptr_t initial_size = HEAP->SizeOfObjects(); 15099 intptr_t initial_size = HEAP->SizeOfObjects();
15072 // Send idle notification to start a round of incremental GCs. 15100 // Send idle notification to start a round of incremental GCs.
15073 v8::V8::IdleNotification(kShortIdlePauseInMs); 15101 v8::V8::IdleNotification(kShortIdlePauseInMs);
15074 // Emulate 7 page reloads. 15102 // Emulate 7 page reloads.
15075 for (int i = 0; i < 7; i++) { 15103 for (int i = 0; i < 7; i++) {
15076 v8::Persistent<v8::Context> ctx = v8::Context::New(); 15104 v8::Persistent<v8::Context> ctx = v8::Context::New();
15077 ctx->Enter(); 15105 ctx->Enter();
15078 CreateGarbageInOldSpace(); 15106 CreateGarbageInOldSpace();
15079 ctx->Exit(); 15107 ctx->Exit();
15080 ctx.Dispose(); 15108 ctx.Dispose(ctx->GetIsolate());
15081 v8::V8::ContextDisposedNotification(); 15109 v8::V8::ContextDisposedNotification();
15082 v8::V8::IdleNotification(kLongIdlePauseInMs); 15110 v8::V8::IdleNotification(kLongIdlePauseInMs);
15083 } 15111 }
15084 // Create garbage and check that idle notification still collects it. 15112 // Create garbage and check that idle notification still collects it.
15085 CreateGarbageInOldSpace(); 15113 CreateGarbageInOldSpace();
15086 intptr_t size_with_garbage = HEAP->SizeOfObjects(); 15114 intptr_t size_with_garbage = HEAP->SizeOfObjects();
15087 CHECK_GT(size_with_garbage, initial_size + MB); 15115 CHECK_GT(size_with_garbage, initial_size + MB);
15088 bool finished = false; 15116 bool finished = false;
15089 for (int i = 0; i < 200 && !finished; i++) { 15117 for (int i = 0; i < 200 && !finished; i++) {
15090 finished = v8::V8::IdleNotification(kShortIdlePauseInMs); 15118 finished = v8::V8::IdleNotification(kShortIdlePauseInMs);
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
15422 context = Context::New(); 15450 context = Context::New();
15423 { 15451 {
15424 v8::HandleScope scope; 15452 v8::HandleScope scope;
15425 15453
15426 context->Enter(); 15454 context->Enter();
15427 Local<v8::String> obj = v8::String::New(""); 15455 Local<v8::String> obj = v8::String::New("");
15428 context->SetEmbedderData(0, obj); 15456 context->SetEmbedderData(0, obj);
15429 CompileRun(source_simple); 15457 CompileRun(source_simple);
15430 context->Exit(); 15458 context->Exit();
15431 } 15459 }
15432 context.Dispose(); 15460 context.Dispose(context->GetIsolate());
15433 v8::V8::ContextDisposedNotification(); 15461 v8::V8::ContextDisposedNotification();
15434 for (gc_count = 1; gc_count < 10; gc_count++) { 15462 for (gc_count = 1; gc_count < 10; gc_count++) {
15435 other_context->Enter(); 15463 other_context->Enter();
15436 CompileRun(source_simple); 15464 CompileRun(source_simple);
15437 other_context->Exit(); 15465 other_context->Exit();
15438 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 15466 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
15439 if (GetGlobalObjectsCount() == 1) break; 15467 if (GetGlobalObjectsCount() == 1) break;
15440 } 15468 }
15441 CHECK_GE(2, gc_count); 15469 CHECK_GE(2, gc_count);
15442 CHECK_EQ(1, GetGlobalObjectsCount()); 15470 CHECK_EQ(1, GetGlobalObjectsCount());
15443 15471
15444 // Eval in a function creates reference from the compilation cache to the 15472 // Eval in a function creates reference from the compilation cache to the
15445 // global object. 15473 // global object.
15446 const char* source_eval = "function f(){eval('1')}; f()"; 15474 const char* source_eval = "function f(){eval('1')}; f()";
15447 context = Context::New(); 15475 context = Context::New();
15448 { 15476 {
15449 v8::HandleScope scope; 15477 v8::HandleScope scope;
15450 15478
15451 context->Enter(); 15479 context->Enter();
15452 CompileRun(source_eval); 15480 CompileRun(source_eval);
15453 context->Exit(); 15481 context->Exit();
15454 } 15482 }
15455 context.Dispose(); 15483 context.Dispose(context->GetIsolate());
15456 v8::V8::ContextDisposedNotification(); 15484 v8::V8::ContextDisposedNotification();
15457 for (gc_count = 1; gc_count < 10; gc_count++) { 15485 for (gc_count = 1; gc_count < 10; gc_count++) {
15458 other_context->Enter(); 15486 other_context->Enter();
15459 CompileRun(source_eval); 15487 CompileRun(source_eval);
15460 other_context->Exit(); 15488 other_context->Exit();
15461 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 15489 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
15462 if (GetGlobalObjectsCount() == 1) break; 15490 if (GetGlobalObjectsCount() == 1) break;
15463 } 15491 }
15464 CHECK_GE(2, gc_count); 15492 CHECK_GE(2, gc_count);
15465 CHECK_EQ(1, GetGlobalObjectsCount()); 15493 CHECK_EQ(1, GetGlobalObjectsCount());
15466 15494
15467 // Looking up the line number for an exception creates reference from the 15495 // Looking up the line number for an exception creates reference from the
15468 // compilation cache to the global object. 15496 // compilation cache to the global object.
15469 const char* source_exception = "function f(){throw 1;} f()"; 15497 const char* source_exception = "function f(){throw 1;} f()";
15470 context = Context::New(); 15498 context = Context::New();
15471 { 15499 {
15472 v8::HandleScope scope; 15500 v8::HandleScope scope;
15473 15501
15474 context->Enter(); 15502 context->Enter();
15475 v8::TryCatch try_catch; 15503 v8::TryCatch try_catch;
15476 CompileRun(source_exception); 15504 CompileRun(source_exception);
15477 CHECK(try_catch.HasCaught()); 15505 CHECK(try_catch.HasCaught());
15478 v8::Handle<v8::Message> message = try_catch.Message(); 15506 v8::Handle<v8::Message> message = try_catch.Message();
15479 CHECK(!message.IsEmpty()); 15507 CHECK(!message.IsEmpty());
15480 CHECK_EQ(1, message->GetLineNumber()); 15508 CHECK_EQ(1, message->GetLineNumber());
15481 context->Exit(); 15509 context->Exit();
15482 } 15510 }
15483 context.Dispose(); 15511 context.Dispose(context->GetIsolate());
15484 v8::V8::ContextDisposedNotification(); 15512 v8::V8::ContextDisposedNotification();
15485 for (gc_count = 1; gc_count < 10; gc_count++) { 15513 for (gc_count = 1; gc_count < 10; gc_count++) {
15486 other_context->Enter(); 15514 other_context->Enter();
15487 CompileRun(source_exception); 15515 CompileRun(source_exception);
15488 other_context->Exit(); 15516 other_context->Exit();
15489 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 15517 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
15490 if (GetGlobalObjectsCount() == 1) break; 15518 if (GetGlobalObjectsCount() == 1) break;
15491 } 15519 }
15492 CHECK_GE(2, gc_count); 15520 CHECK_GE(2, gc_count);
15493 CHECK_EQ(1, GetGlobalObjectsCount()); 15521 CHECK_EQ(1, GetGlobalObjectsCount());
15494 15522
15495 other_context.Dispose(); 15523 other_context.Dispose(other_context->GetIsolate());
15496 v8::V8::ContextDisposedNotification(); 15524 v8::V8::ContextDisposedNotification();
15497 } 15525 }
15498 15526
15499 15527
15500 THREADED_TEST(ScriptOrigin) { 15528 THREADED_TEST(ScriptOrigin) {
15501 v8::HandleScope scope; 15529 v8::HandleScope scope;
15502 LocalContext env; 15530 LocalContext env;
15503 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); 15531 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"));
15504 v8::Handle<v8::String> script = v8::String::New( 15532 v8::Handle<v8::String> script = v8::String::New(
15505 "function f() {}\n\nfunction g() {}"); 15533 "function f() {}\n\nfunction g() {}");
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
16275 } 16303 }
16276 16304
16277 { 16305 {
16278 v8::Context::Scope cscope(context1); 16306 v8::Context::Scope cscope(context1);
16279 v8::HandleScope scope; 16307 v8::HandleScope scope;
16280 ExpectString("function f() { return foo; }; f()", "isolate 1"); 16308 ExpectString("function f() { return foo; }; f()", "isolate 1");
16281 } 16309 }
16282 16310
16283 { 16311 {
16284 v8::Isolate::Scope iscope(isolate2); 16312 v8::Isolate::Scope iscope(isolate2);
16285 context2.Dispose(); 16313 context2.Dispose(context2->GetIsolate());
16286 } 16314 }
16287 16315
16288 context1.Dispose(); 16316 context1.Dispose(context1->GetIsolate());
16289 isolate1->Exit(); 16317 isolate1->Exit();
16290 16318
16291 v8::V8::SetFatalErrorHandler(StoringErrorCallback); 16319 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
16292 last_location = last_message = NULL; 16320 last_location = last_message = NULL;
16293 16321
16294 isolate1->Dispose(); 16322 isolate1->Dispose();
16295 CHECK_EQ(last_location, NULL); 16323 CHECK_EQ(last_location, NULL);
16296 CHECK_EQ(last_message, NULL); 16324 CHECK_EQ(last_message, NULL);
16297 16325
16298 isolate2->Dispose(); 16326 isolate2->Dispose();
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
16652 public: 16680 public:
16653 explicit Visitor42(v8::Persistent<v8::Object> object) 16681 explicit Visitor42(v8::Persistent<v8::Object> object)
16654 : counter_(0), object_(object) { } 16682 : counter_(0), object_(object) { }
16655 16683
16656 virtual void VisitPersistentHandle(Persistent<Value> value, 16684 virtual void VisitPersistentHandle(Persistent<Value> value,
16657 uint16_t class_id) { 16685 uint16_t class_id) {
16658 if (class_id == 42) { 16686 if (class_id == 42) {
16659 CHECK(value->IsObject()); 16687 CHECK(value->IsObject());
16660 v8::Persistent<v8::Object> visited = 16688 v8::Persistent<v8::Object> visited =
16661 v8::Persistent<v8::Object>::Cast(value); 16689 v8::Persistent<v8::Object>::Cast(value);
16662 CHECK_EQ(42, visited.WrapperClassId()); 16690 CHECK_EQ(42, visited.WrapperClassId(v8::Isolate::GetCurrent()));
16663 CHECK_EQ(object_, visited); 16691 CHECK_EQ(object_, visited);
16664 ++counter_; 16692 ++counter_;
16665 } 16693 }
16666 } 16694 }
16667 16695
16668 int counter_; 16696 int counter_;
16669 v8::Persistent<v8::Object> object_; 16697 v8::Persistent<v8::Object> object_;
16670 }; 16698 };
16671 16699
16672 16700
16673 TEST(PersistentHandleVisitor) { 16701 TEST(PersistentHandleVisitor) {
16674 v8::HandleScope scope; 16702 v8::HandleScope scope;
16675 LocalContext context; 16703 LocalContext context;
16704 v8::Isolate* isolate = context->GetIsolate();
16676 v8::Persistent<v8::Object> object = 16705 v8::Persistent<v8::Object> object =
16677 v8::Persistent<v8::Object>::New(v8::Object::New()); 16706 v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
16678 CHECK_EQ(0, object.WrapperClassId()); 16707 CHECK_EQ(0, object.WrapperClassId(isolate));
16679 object.SetWrapperClassId(42); 16708 object.SetWrapperClassId(isolate, 42);
16680 CHECK_EQ(42, object.WrapperClassId()); 16709 CHECK_EQ(42, object.WrapperClassId(isolate));
16681 16710
16682 Visitor42 visitor(object); 16711 Visitor42 visitor(object);
16683 v8::V8::VisitHandlesWithClassIds(&visitor); 16712 v8::V8::VisitHandlesWithClassIds(&visitor);
16684 CHECK_EQ(1, visitor.counter_); 16713 CHECK_EQ(1, visitor.counter_);
16685 16714
16686 object.Dispose(); 16715 object.Dispose(isolate);
16687 } 16716 }
16688 16717
16689 16718
16690 TEST(WrapperClassId) { 16719 TEST(WrapperClassId) {
16691 v8::HandleScope scope; 16720 v8::HandleScope scope;
16692 LocalContext context; 16721 LocalContext context;
16722 v8::Isolate* isolate = context->GetIsolate();
16693 v8::Persistent<v8::Object> object = 16723 v8::Persistent<v8::Object> object =
16694 v8::Persistent<v8::Object>::New(v8::Object::New()); 16724 v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
16695 CHECK_EQ(0, object.WrapperClassId()); 16725 CHECK_EQ(0, object.WrapperClassId(isolate));
16696 object.SetWrapperClassId(65535); 16726 object.SetWrapperClassId(isolate, 65535);
16697 CHECK_EQ(65535, object.WrapperClassId()); 16727 CHECK_EQ(65535, object.WrapperClassId(isolate));
16698 object.Dispose(); 16728 object.Dispose(isolate);
16699 } 16729 }
16700 16730
16701 16731
16702 TEST(PersistentHandleInNewSpaceVisitor) { 16732 TEST(PersistentHandleInNewSpaceVisitor) {
16703 v8::HandleScope scope; 16733 v8::HandleScope scope;
16704 LocalContext context; 16734 LocalContext context;
16735 v8::Isolate* isolate = context->GetIsolate();
16705 v8::Persistent<v8::Object> object1 = 16736 v8::Persistent<v8::Object> object1 =
16706 v8::Persistent<v8::Object>::New(v8::Object::New()); 16737 v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
16707 CHECK_EQ(0, object1.WrapperClassId()); 16738 CHECK_EQ(0, object1.WrapperClassId(isolate));
16708 object1.SetWrapperClassId(42); 16739 object1.SetWrapperClassId(isolate, 42);
16709 CHECK_EQ(42, object1.WrapperClassId()); 16740 CHECK_EQ(42, object1.WrapperClassId(isolate));
16710 16741
16711 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 16742 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
16712 16743
16713 v8::Persistent<v8::Object> object2 = 16744 v8::Persistent<v8::Object> object2 =
16714 v8::Persistent<v8::Object>::New(v8::Object::New()); 16745 v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
16715 CHECK_EQ(0, object2.WrapperClassId()); 16746 CHECK_EQ(0, object2.WrapperClassId(isolate));
16716 object2.SetWrapperClassId(42); 16747 object2.SetWrapperClassId(isolate, 42);
16717 CHECK_EQ(42, object2.WrapperClassId()); 16748 CHECK_EQ(42, object2.WrapperClassId(isolate));
16718 16749
16719 Visitor42 visitor(object2); 16750 Visitor42 visitor(object2);
16720 v8::V8::VisitHandlesForPartialDependence(v8::Isolate::GetCurrent(), &visitor); 16751 v8::V8::VisitHandlesForPartialDependence(isolate, &visitor);
16721 CHECK_EQ(1, visitor.counter_); 16752 CHECK_EQ(1, visitor.counter_);
16722 16753
16723 object1.Dispose(); 16754 object1.Dispose(isolate);
16724 object2.Dispose(); 16755 object2.Dispose(isolate);
16725 } 16756 }
16726 16757
16727 16758
16728 TEST(RegExp) { 16759 TEST(RegExp) {
16729 v8::HandleScope scope; 16760 v8::HandleScope scope;
16730 LocalContext context; 16761 LocalContext context;
16731 16762
16732 v8::Handle<v8::RegExp> re = v8::RegExp::New(v8_str("foo"), v8::RegExp::kNone); 16763 v8::Handle<v8::RegExp> re = v8::RegExp::New(v8_str("foo"), v8::RegExp::kNone);
16733 CHECK(re->IsRegExp()); 16764 CHECK(re->IsRegExp());
16734 CHECK(re->GetSource()->Equals(v8_str("foo"))); 16765 CHECK(re->GetSource()->Equals(v8_str("foo")));
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
16944 CHECK(instance1->CreationContext() == context1); 16975 CHECK(instance1->CreationContext() == context1);
16945 CheckContextId(instance1, 1); 16976 CheckContextId(instance1, 1);
16946 CHECK(object2->CreationContext() == context2); 16977 CHECK(object2->CreationContext() == context2);
16947 CheckContextId(object2, 2); 16978 CheckContextId(object2, 2);
16948 CHECK(func2->CreationContext() == context2); 16979 CHECK(func2->CreationContext() == context2);
16949 CheckContextId(func2, 2); 16980 CheckContextId(func2, 2);
16950 CHECK(instance2->CreationContext() == context2); 16981 CHECK(instance2->CreationContext() == context2);
16951 CheckContextId(instance2, 2); 16982 CheckContextId(instance2, 2);
16952 } 16983 }
16953 16984
16954 context1.Dispose(); 16985 context1.Dispose(context1->GetIsolate());
16955 context2.Dispose(); 16986 context2.Dispose(context2->GetIsolate());
16956 context3.Dispose(); 16987 context3.Dispose(context3->GetIsolate());
16957 } 16988 }
16958 16989
16959 16990
16960 THREADED_TEST(CreationContextOfJsFunction) { 16991 THREADED_TEST(CreationContextOfJsFunction) {
16961 HandleScope handle_scope; 16992 HandleScope handle_scope;
16962 Persistent<Context> context = Context::New(); 16993 Persistent<Context> context = Context::New();
16963 InstallContextId(context, 1); 16994 InstallContextId(context, 1);
16964 16995
16965 Local<Object> function; 16996 Local<Object> function;
16966 { 16997 {
16967 Context::Scope scope(context); 16998 Context::Scope scope(context);
16968 function = CompileRun("function foo() {}; foo").As<Object>(); 16999 function = CompileRun("function foo() {}; foo").As<Object>();
16969 } 17000 }
16970 17001
16971 CHECK(function->CreationContext() == context); 17002 CHECK(function->CreationContext() == context);
16972 CheckContextId(function, 1); 17003 CheckContextId(function, 1);
16973 17004
16974 context.Dispose(); 17005 context.Dispose(context->GetIsolate());
16975 } 17006 }
16976 17007
16977 17008
16978 Handle<Value> HasOwnPropertyIndexedPropertyGetter(uint32_t index, 17009 Handle<Value> HasOwnPropertyIndexedPropertyGetter(uint32_t index,
16979 const AccessorInfo& info) { 17010 const AccessorInfo& info) {
16980 if (index == 42) return v8_str("yes"); 17011 if (index == 42) return v8_str("yes");
16981 return Handle<v8::Integer>(); 17012 return Handle<v8::Integer>();
16982 } 17013 }
16983 17014
16984 17015
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
17340 Local<Value> result4 = CompileRun("Object.getPrototypeOf(proxy)"); 17371 Local<Value> result4 = CompileRun("Object.getPrototypeOf(proxy)");
17341 CHECK(result4->Equals(Undefined())); 17372 CHECK(result4->Equals(Undefined()));
17342 17373
17343 Local<Value> result5 = CompileRun("Object.getPrototypeOf(hidden)"); 17374 Local<Value> result5 = CompileRun("Object.getPrototypeOf(hidden)");
17344 CHECK(result5->Equals( 17375 CHECK(result5->Equals(
17345 object_with_hidden->GetPrototype()->ToObject()->GetPrototype())); 17376 object_with_hidden->GetPrototype()->ToObject()->GetPrototype()));
17346 17377
17347 Local<Value> result6 = CompileRun("Object.getPrototypeOf(phidden)"); 17378 Local<Value> result6 = CompileRun("Object.getPrototypeOf(phidden)");
17348 CHECK(result6->Equals(Undefined())); 17379 CHECK(result6->Equals(Undefined()));
17349 17380
17350 context.Dispose(); 17381 context.Dispose(context->GetIsolate());
17351 } 17382 }
17352 17383
17353 17384
17354 THREADED_TEST(Regress125988) { 17385 THREADED_TEST(Regress125988) {
17355 v8::HandleScope scope; 17386 v8::HandleScope scope;
17356 Handle<FunctionTemplate> intercept = FunctionTemplate::New(); 17387 Handle<FunctionTemplate> intercept = FunctionTemplate::New();
17357 AddInterceptor(intercept, EmptyInterceptorGetter, EmptyInterceptorSetter); 17388 AddInterceptor(intercept, EmptyInterceptorGetter, EmptyInterceptorSetter);
17358 LocalContext env; 17389 LocalContext env;
17359 env->Global()->Set(v8_str("Intercept"), intercept->GetFunction()); 17390 env->Global()->Set(v8_str("Intercept"), intercept->GetFunction());
17360 CompileRun("var a = new Object();" 17391 CompileRun("var a = new Object();"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
17468 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/,func)[1]"))); 17499 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/,func)[1]")));
17469 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[1]"))); 17500 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[1]")));
17470 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); 17501 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]")));
17471 17502
17472 // TODO(1547): Make the following also return "i". 17503 // TODO(1547): Make the following also return "i".
17473 // Calling with environment record as base. 17504 // Calling with environment record as base.
17474 TestReceiver(o, context->Global(), "func()"); 17505 TestReceiver(o, context->Global(), "func()");
17475 // Calling with no base. 17506 // Calling with no base.
17476 TestReceiver(o, context->Global(), "(1,func)()"); 17507 TestReceiver(o, context->Global(), "(1,func)()");
17477 17508
17478 foreign_context.Dispose(); 17509 foreign_context.Dispose(foreign_context->GetIsolate());
17479 } 17510 }
17480 17511
17481 17512
17482 uint8_t callback_fired = 0; 17513 uint8_t callback_fired = 0;
17483 17514
17484 17515
17485 void CallCompletedCallback1() { 17516 void CallCompletedCallback1() {
17486 i::OS::Print("Firing callback 1.\n"); 17517 i::OS::Print("Firing callback 1.\n");
17487 callback_fired ^= 1; // Toggle first bit. 17518 callback_fired ^= 1; // Toggle first bit.
17488 } 17519 }
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
18181 i::Semaphore* sem_; 18212 i::Semaphore* sem_;
18182 volatile int sem_value_; 18213 volatile int sem_value_;
18183 }; 18214 };
18184 18215
18185 18216
18186 THREADED_TEST(SemaphoreInterruption) { 18217 THREADED_TEST(SemaphoreInterruption) {
18187 ThreadInterruptTest().RunTest(); 18218 ThreadInterruptTest().RunTest();
18188 } 18219 }
18189 18220
18190 #endif // WIN32 18221 #endif // WIN32
OLDNEW
« no previous file with comments | « test/cctest/cctest.h ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698