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

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

Issue 7031005: Extend Handle API with MarkIndependent. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 7 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
« src/heap.cc ('K') | « src/v8globals.h ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 4414 matching lines...) Expand 10 before | Expand all | Expand 10 after
4425 "}" 4425 "}"
4426 "gc();" 4426 "gc();"
4427 "4"; 4427 "4";
4428 v8::Handle<Value> result = CompileRun(code); 4428 v8::Handle<Value> result = CompileRun(code);
4429 CHECK_EQ(4.0, result->NumberValue()); 4429 CHECK_EQ(4.0, result->NumberValue());
4430 delete whammy; 4430 delete whammy;
4431 context.Dispose(); 4431 context.Dispose();
4432 } 4432 }
4433 4433
4434 4434
4435 static bool in_scavenge = false; 4435 static void DisposeAndSetFlag(v8::Persistent<v8::Value> obj, void* data) {
4436 static int last = -1;
4437
4438 static void ForceScavenge(v8::Persistent<v8::Value> obj, void* data) {
4439 CHECK_EQ(-1, last);
4440 last = 0;
4441 obj.Dispose(); 4436 obj.Dispose();
4442 obj.Clear(); 4437 obj.Clear();
4443 in_scavenge = true;
4444 HEAP->PerformScavenge();
4445 in_scavenge = false;
4446 *(reinterpret_cast<bool*>(data)) = true; 4438 *(reinterpret_cast<bool*>(data)) = true;
4447 } 4439 }
4448 4440
4449 static void CheckIsNotInvokedInScavenge(v8::Persistent<v8::Value> obj,
4450 void* data) {
4451 CHECK_EQ(0, last);
4452 last = 1;
4453 *(reinterpret_cast<bool*>(data)) = in_scavenge;
4454 obj.Dispose();
4455 obj.Clear();
4456 }
4457 4441
4458 THREADED_TEST(NoWeakRefCallbacksInScavenge) { 4442 THREADED_TEST(IndependentWeakHandle) {
4459 // Test verifies that scavenge cannot invoke WeakReferenceCallbacks.
4460 // Calling callbacks from scavenges is unsafe as objects held by those
4461 // handlers might have become strongly reachable, but scavenge doesn't
4462 // check that.
4463 v8::Persistent<Context> context = Context::New(); 4443 v8::Persistent<Context> context = Context::New();
4464 Context::Scope context_scope(context); 4444 Context::Scope context_scope(context);
4465 4445
4466 v8::Persistent<v8::Object> object_a; 4446 v8::Persistent<v8::Object> object_a;
4467 v8::Persistent<v8::Object> object_b;
4468 4447
4469 { 4448 {
4470 v8::HandleScope handle_scope; 4449 v8::HandleScope handle_scope;
4471 object_b = v8::Persistent<v8::Object>::New(v8::Object::New());
4472 object_a = v8::Persistent<v8::Object>::New(v8::Object::New()); 4450 object_a = v8::Persistent<v8::Object>::New(v8::Object::New());
4473 } 4451 }
4474 4452
4475 bool object_a_disposed = false; 4453 bool object_a_disposed = false;
4476 object_a.MakeWeak(&object_a_disposed, &ForceScavenge); 4454 object_a.MakeWeak(&object_a_disposed, &DisposeAndSetFlag);
4477 bool released_in_scavenge = false; 4455 object_a.MarkIndependent();
antonm 2011/05/16 14:13:19 please, add tests cases for weak callbacks forcing
Vyacheslav Egorov (Chromium) 2011/05/16 14:55:34 Done.
4478 object_b.MakeWeak(&released_in_scavenge, &CheckIsNotInvokedInScavenge); 4456 HEAP->PerformScavenge();
4479 4457 CHECK(object_a_disposed);
4480 while (!object_a_disposed) {
4481 HEAP->CollectAllGarbage(false);
4482 }
4483 CHECK(!released_in_scavenge);
4484 } 4458 }
4485 4459
4486 4460
4487 v8::Handle<Function> args_fun; 4461 v8::Handle<Function> args_fun;
4488 4462
4489 4463
4490 static v8::Handle<Value> ArgumentsTestCallback(const v8::Arguments& args) { 4464 static v8::Handle<Value> ArgumentsTestCallback(const v8::Arguments& args) {
4491 ApiTestFuzzer::Fuzz(); 4465 ApiTestFuzzer::Fuzz();
4492 CHECK_EQ(args_fun, args.Callee()); 4466 CHECK_EQ(args_fun, args.Callee());
4493 CHECK_EQ(3, args.Length()); 4467 CHECK_EQ(3, args.Length());
(...skipping 9952 matching lines...) Expand 10 before | Expand all | Expand 10 after
14446 14420
14447 THREADED_TEST(CallAPIFunctionOnNonObject) { 14421 THREADED_TEST(CallAPIFunctionOnNonObject) {
14448 v8::HandleScope scope; 14422 v8::HandleScope scope;
14449 LocalContext context; 14423 LocalContext context;
14450 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis); 14424 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis);
14451 Handle<Function> function = templ->GetFunction(); 14425 Handle<Function> function = templ->GetFunction();
14452 context->Global()->Set(v8_str("f"), function); 14426 context->Global()->Set(v8_str("f"), function);
14453 TryCatch try_catch; 14427 TryCatch try_catch;
14454 CompileRun("f.call(2)"); 14428 CompileRun("f.call(2)");
14455 } 14429 }
OLDNEW
« src/heap.cc ('K') | « src/v8globals.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698