OLD | NEW |
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 8391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8402 " i++;" | 8402 " i++;" |
8403 " return s(o);" | 8403 " return s(o);" |
8404 " }" | 8404 " }" |
8405 " }" | 8405 " }" |
8406 "};" | 8406 "};" |
8407 "s(o);"); | 8407 "s(o);"); |
8408 CHECK(try_catch.HasCaught()); | 8408 CHECK(try_catch.HasCaught()); |
8409 v8::String::Utf8Value value(try_catch.Exception()); | 8409 v8::String::Utf8Value value(try_catch.Exception()); |
8410 CHECK_EQ(0, strcmp(*value, "Hey!")); | 8410 CHECK_EQ(0, strcmp(*value, "Hey!")); |
8411 } | 8411 } |
| 8412 |
| 8413 |
| 8414 static int GetGlobalObjectsCount() { |
| 8415 int count = 0; |
| 8416 v8::internal::HeapIterator it; |
| 8417 while (it.has_next()) { |
| 8418 v8::internal::HeapObject* object = it.next(); |
| 8419 if (object->IsJSGlobalObject()) { |
| 8420 count++; |
| 8421 } |
| 8422 } |
| 8423 #ifdef DEBUG |
| 8424 if (count > 0) v8::internal::Heap::TracePathToGlobal(); |
| 8425 #endif |
| 8426 return count; |
| 8427 } |
| 8428 |
| 8429 |
| 8430 TEST(Bug528) { |
| 8431 v8::V8::Initialize(); |
| 8432 |
| 8433 v8::HandleScope scope; |
| 8434 v8::Persistent<Context> context; |
| 8435 int gc_count; |
| 8436 |
| 8437 // Context-dependent context data creates reference from the compilation |
| 8438 // cache to the global object. |
| 8439 context = Context::New(); |
| 8440 { |
| 8441 v8::HandleScope scope; |
| 8442 |
| 8443 context->Enter(); |
| 8444 Local<v8::String> obj = v8::String::New(""); |
| 8445 context->SetData(obj); |
| 8446 CompileRun("1"); |
| 8447 context->Exit(); |
| 8448 } |
| 8449 context.Dispose(); |
| 8450 for (gc_count = 1; gc_count < 10; gc_count++) { |
| 8451 v8::internal::Heap::CollectAllGarbage(false); |
| 8452 if (GetGlobalObjectsCount() == 0) break; |
| 8453 } |
| 8454 CHECK_EQ(0, GetGlobalObjectsCount()); |
| 8455 CHECK_EQ(2, gc_count); |
| 8456 |
| 8457 // Eval in a function creates reference from the compilation cache to the |
| 8458 // global object. |
| 8459 context = Context::New(); |
| 8460 { |
| 8461 v8::HandleScope scope; |
| 8462 |
| 8463 context->Enter(); |
| 8464 CompileRun("function f(){eval('1')}; f()"); |
| 8465 context->Exit(); |
| 8466 } |
| 8467 context.Dispose(); |
| 8468 for (gc_count = 1; gc_count < 10; gc_count++) { |
| 8469 v8::internal::Heap::CollectAllGarbage(false); |
| 8470 if (GetGlobalObjectsCount() == 0) break; |
| 8471 } |
| 8472 CHECK_EQ(0, GetGlobalObjectsCount()); |
| 8473 CHECK_EQ(2, gc_count); |
| 8474 |
| 8475 // Looking up the line number for an exception creates reference from the |
| 8476 // compilation cache to the global object. |
| 8477 context = Context::New(); |
| 8478 { |
| 8479 v8::HandleScope scope; |
| 8480 |
| 8481 context->Enter(); |
| 8482 v8::TryCatch try_catch; |
| 8483 CompileRun("function f(){throw 1;}; f()"); |
| 8484 CHECK(try_catch.HasCaught()); |
| 8485 v8::Handle<v8::Message> message = try_catch.Message(); |
| 8486 CHECK(!message.IsEmpty()); |
| 8487 CHECK_EQ(1, message->GetLineNumber()); |
| 8488 context->Exit(); |
| 8489 } |
| 8490 context.Dispose(); |
| 8491 for (gc_count = 1; gc_count < 10; gc_count++) { |
| 8492 v8::internal::Heap::CollectAllGarbage(false); |
| 8493 if (GetGlobalObjectsCount() == 0) break; |
| 8494 } |
| 8495 CHECK_EQ(0, GetGlobalObjectsCount()); |
| 8496 CHECK_EQ(2, gc_count); |
| 8497 } |
OLD | NEW |