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

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

Issue 11959031: Add a new weak handle callback that passes an Isolate to an embedder (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Created 7 years, 11 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
« src/global-handles.cc ('K') | « src/global-handles.cc ('k') | no next file » | 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 5531 matching lines...) Expand 10 before | Expand all | Expand 10 after
5542 "}" 5542 "}"
5543 "gc();" 5543 "gc();"
5544 "4"; 5544 "4";
5545 v8::Handle<Value> result = CompileRun(code); 5545 v8::Handle<Value> result = CompileRun(code);
5546 CHECK_EQ(4.0, result->NumberValue()); 5546 CHECK_EQ(4.0, result->NumberValue());
5547 delete whammy; 5547 delete whammy;
5548 context.Dispose(); 5548 context.Dispose();
5549 } 5549 }
5550 5550
5551 5551
5552 static void DisposeAndSetFlag(v8::Persistent<v8::Value> obj, void* data) { 5552 static void DisposeAndSetFlag(v8::Isolate* isolate,
5553 v8::Persistent<v8::Value> obj, void* data) {
5553 obj.Dispose(); 5554 obj.Dispose();
5554 obj.Clear(); 5555 obj.Clear();
5555 *(reinterpret_cast<bool*>(data)) = true; 5556 *(reinterpret_cast<bool*>(data)) = true;
5556 } 5557 }
5557 5558
5558 5559
5559 THREADED_TEST(IndependentWeakHandle) { 5560 THREADED_TEST(IndependentWeakHandle) {
5560 v8::Persistent<Context> context = Context::New(); 5561 v8::Persistent<Context> context = Context::New();
5561 Context::Scope context_scope(context); 5562 Context::Scope context_scope(context);
5562 5563
5563 v8::Persistent<v8::Object> object_a, object_b; 5564 v8::Persistent<v8::Object> object_a, object_b;
5564 5565
5565 { 5566 {
5566 v8::HandleScope handle_scope; 5567 v8::HandleScope handle_scope;
5567 object_a = v8::Persistent<v8::Object>::New(v8::Object::New()); 5568 object_a = v8::Persistent<v8::Object>::New(v8::Object::New());
5568 object_b = v8::Persistent<v8::Object>::New(v8::Object::New()); 5569 object_b = v8::Persistent<v8::Object>::New(v8::Object::New());
5569 } 5570 }
5570 5571
5571 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 5572 v8::Isolate* isolate = v8::Isolate::GetCurrent();
5572 bool object_a_disposed = false; 5573 bool object_a_disposed = false;
5573 bool object_b_disposed = false; 5574 bool object_b_disposed = false;
5574 object_a.MakeWeak(&object_a_disposed, &DisposeAndSetFlag); 5575 object_a.Weaken(isolate, &object_a_disposed, &DisposeAndSetFlag);
5575 object_b.MakeWeak(&object_b_disposed, &DisposeAndSetFlag); 5576 object_b.Weaken(isolate, &object_b_disposed, &DisposeAndSetFlag);
5576 CHECK(!object_a.IsIndependent()); 5577 CHECK(!object_a.IsIndependent());
5577 CHECK(!object_b.IsIndependent(isolate)); 5578 CHECK(!object_b.IsIndependent(isolate));
5578 object_a.MarkIndependent(); 5579 object_a.MarkIndependent();
5579 object_b.MarkIndependent(isolate); 5580 object_b.MarkIndependent(isolate);
5580 CHECK(object_a.IsIndependent()); 5581 CHECK(object_a.IsIndependent());
5581 CHECK(object_b.IsIndependent(isolate)); 5582 CHECK(object_b.IsIndependent(isolate));
5582 HEAP->PerformScavenge(); 5583 HEAP->PerformScavenge();
5583 CHECK(object_a_disposed); 5584 CHECK(object_a_disposed);
5584 CHECK(object_b_disposed); 5585 CHECK(object_b_disposed);
5585 } 5586 }
(...skipping 12569 matching lines...) Expand 10 before | Expand all | Expand 10 after
18155 i::Semaphore* sem_; 18156 i::Semaphore* sem_;
18156 volatile int sem_value_; 18157 volatile int sem_value_;
18157 }; 18158 };
18158 18159
18159 18160
18160 THREADED_TEST(SemaphoreInterruption) { 18161 THREADED_TEST(SemaphoreInterruption) {
18161 ThreadInterruptTest().RunTest(); 18162 ThreadInterruptTest().RunTest();
18162 } 18163 }
18163 18164
18164 #endif // WIN32 18165 #endif // WIN32
OLDNEW
« src/global-handles.cc ('K') | « src/global-handles.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698