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

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

Issue 443021: Add test to expose bug 528... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years 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 | « src/objects-debug.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 2007-2009 the V8 project authors. All rights reserved. 1 // Copyright 2007-2009 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 8477 matching lines...) Expand 10 before | Expand all | Expand 10 after
8488 " i++;" 8488 " i++;"
8489 " return s(o);" 8489 " return s(o);"
8490 " }" 8490 " }"
8491 " }" 8491 " }"
8492 "};" 8492 "};"
8493 "s(o);"); 8493 "s(o);");
8494 CHECK(try_catch.HasCaught()); 8494 CHECK(try_catch.HasCaught());
8495 v8::String::Utf8Value value(try_catch.Exception()); 8495 v8::String::Utf8Value value(try_catch.Exception());
8496 CHECK_EQ(0, strcmp(*value, "Hey!")); 8496 CHECK_EQ(0, strcmp(*value, "Hey!"));
8497 } 8497 }
8498
8499
8500 static int GetGlobalObjectsCount() {
8501 int count = 0;
8502 v8::internal::HeapIterator it;
8503 while (it.has_next()) {
8504 v8::internal::HeapObject* object = it.next();
8505 if (object->IsJSGlobalObject()) {
8506 count++;
8507 }
8508 }
8509 #ifdef DEBUG
8510 if (count > 0) v8::internal::Heap::TracePathToGlobal();
8511 #endif
8512 return count;
8513 }
8514
8515
8516 TEST(Bug528) {
8517 v8::V8::Initialize();
8518
8519 v8::HandleScope scope;
8520 v8::Persistent<Context> context;
8521 int gc_count;
8522
8523 // Context-dependent context data creates reference from the compilation
8524 // cache to the global object.
8525 context = Context::New();
8526 {
8527 v8::HandleScope scope;
8528
8529 context->Enter();
8530 Local<v8::Object> obj = v8::Object::New();
8531 context->SetData(obj);
8532 CompileRun("1");
8533 context->Exit();
8534 }
8535 context.Dispose();
8536 for (gc_count = 1; gc_count < 10; gc_count++) {
8537 v8::internal::Heap::CollectAllGarbage(false);
8538 if (GetGlobalObjectsCount() == 0) break;
8539 }
8540 CHECK_EQ(0, GetGlobalObjectsCount());
8541
8542 // Compilation cache size is different for Android.
8543 #if defined(ANDROID)
8544 CHECK_EQ(1, gc_count);
8545 #else
8546 CHECK_EQ(5, gc_count);
8547 #endif
8548
8549 // Eval in a function creates reference from the compilation cache to the
8550 // global object.
8551 context = Context::New();
8552 {
8553 v8::HandleScope scope;
8554
8555 context->Enter();
8556 CompileRun("function f(){eval('1')}; f()");
8557 context->Exit();
8558 }
8559 context.Dispose();
8560 for (gc_count = 1; gc_count < 10; gc_count++) {
8561 v8::internal::Heap::CollectAllGarbage(false);
8562 if (GetGlobalObjectsCount() == 0) break;
8563 }
8564 CHECK_EQ(0, GetGlobalObjectsCount());
8565
8566 // Compilation cache size is different for Android.
8567 #if defined(ANDROID)
8568 CHECK_EQ(1, gc_count);
8569 #else
8570 CHECK_EQ(2, gc_count);
8571 #endif
8572
8573 // Looking up the line number for an exception creates reference from the
8574 // compilation cache to the global object.
8575 context = Context::New();
8576 {
8577 v8::HandleScope scope;
8578
8579 context->Enter();
8580 v8::TryCatch try_catch;
8581 CompileRun("function f(){throw 1;}; f()");
8582 CHECK(try_catch.HasCaught());
8583 v8::Handle<v8::Message> message = try_catch.Message();
8584 CHECK(!message.IsEmpty());
8585 CHECK_EQ(1, message->GetLineNumber());
8586 context->Exit();
8587 }
8588 context.Dispose();
8589 for (gc_count = 1; gc_count < 10; gc_count++) {
8590 v8::internal::Heap::CollectAllGarbage(false);
8591 if (GetGlobalObjectsCount() == 0) break;
8592 }
8593 CHECK_EQ(0, GetGlobalObjectsCount());
8594
8595 // Compilation cache size is different for Android.
8596 #if defined(ANDROID)
8597 CHECK_EQ(2, gc_count);
8598 #else
8599 CHECK_EQ(5, gc_count);
8600 #endif
8601 }
OLDNEW
« no previous file with comments | « src/objects-debug.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698