| 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 8701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8712 v8::String::Utf8Value value(try_catch.Exception()); | 8712 v8::String::Utf8Value value(try_catch.Exception()); |
| 8713 CHECK_EQ(0, strcmp(*value, "Hey!")); | 8713 CHECK_EQ(0, strcmp(*value, "Hey!")); |
| 8714 } | 8714 } |
| 8715 | 8715 |
| 8716 | 8716 |
| 8717 static int GetGlobalObjectsCount() { | 8717 static int GetGlobalObjectsCount() { |
| 8718 int count = 0; | 8718 int count = 0; |
| 8719 v8::internal::HeapIterator it; | 8719 v8::internal::HeapIterator it; |
| 8720 while (it.has_next()) { | 8720 while (it.has_next()) { |
| 8721 v8::internal::HeapObject* object = it.next(); | 8721 v8::internal::HeapObject* object = it.next(); |
| 8722 if (object->IsJSGlobalObject()) { | 8722 if (object->IsJSGlobalObject()) count++; |
| 8723 count++; | |
| 8724 } | |
| 8725 } | 8723 } |
| 8726 #ifdef DEBUG | |
| 8727 if (count > 0) v8::internal::Heap::TracePathToGlobal(); | |
| 8728 #endif | |
| 8729 return count; | 8724 return count; |
| 8730 } | 8725 } |
| 8731 | 8726 |
| 8732 | 8727 |
| 8733 TEST(Bug528) { | 8728 TEST(Regress528) { |
| 8734 v8::V8::Initialize(); | 8729 v8::V8::Initialize(); |
| 8735 | 8730 |
| 8736 v8::HandleScope scope; | 8731 v8::HandleScope scope; |
| 8737 v8::Persistent<Context> context; | 8732 v8::Persistent<Context> context; |
| 8733 v8::Persistent<Context> other_context; |
| 8738 int gc_count; | 8734 int gc_count; |
| 8739 | 8735 |
| 8736 // Create a context used to keep the code from aging in the compilation |
| 8737 // cache. |
| 8738 other_context = Context::New(); |
| 8739 |
| 8740 // Context-dependent context data creates reference from the compilation | 8740 // Context-dependent context data creates reference from the compilation |
| 8741 // cache to the global object. | 8741 // cache to the global object. |
| 8742 const char* source_simple = "1"; |
| 8742 context = Context::New(); | 8743 context = Context::New(); |
| 8743 { | 8744 { |
| 8744 v8::HandleScope scope; | 8745 v8::HandleScope scope; |
| 8745 | 8746 |
| 8746 context->Enter(); | 8747 context->Enter(); |
| 8747 Local<v8::String> obj = v8::String::New(""); | 8748 Local<v8::String> obj = v8::String::New(""); |
| 8748 context->SetData(obj); | 8749 context->SetData(obj); |
| 8749 CompileRun("1"); | 8750 CompileRun(source_simple); |
| 8750 context->Exit(); | 8751 context->Exit(); |
| 8751 } | 8752 } |
| 8752 context.Dispose(); | 8753 context.Dispose(); |
| 8753 for (gc_count = 1; gc_count < 10; gc_count++) { | 8754 for (gc_count = 1; gc_count < 10; gc_count++) { |
| 8755 other_context->Enter(); |
| 8756 CompileRun(source_simple); |
| 8757 other_context->Exit(); |
| 8754 v8::internal::Heap::CollectAllGarbage(false); | 8758 v8::internal::Heap::CollectAllGarbage(false); |
| 8755 if (GetGlobalObjectsCount() == 0) break; | 8759 if (GetGlobalObjectsCount() == 1) break; |
| 8756 } | 8760 } |
| 8757 CHECK_EQ(0, GetGlobalObjectsCount()); | 8761 CHECK_GE(2, gc_count); |
| 8758 CHECK_EQ(2, gc_count); | 8762 CHECK_EQ(1, GetGlobalObjectsCount()); |
| 8759 | 8763 |
| 8760 // Eval in a function creates reference from the compilation cache to the | 8764 // Eval in a function creates reference from the compilation cache to the |
| 8761 // global object. | 8765 // global object. |
| 8766 const char* source_eval = "function f(){eval('1')}; f()"; |
| 8762 context = Context::New(); | 8767 context = Context::New(); |
| 8763 { | 8768 { |
| 8764 v8::HandleScope scope; | 8769 v8::HandleScope scope; |
| 8765 | 8770 |
| 8766 context->Enter(); | 8771 context->Enter(); |
| 8767 CompileRun("function f(){eval('1')}; f()"); | 8772 CompileRun(source_eval); |
| 8768 context->Exit(); | 8773 context->Exit(); |
| 8769 } | 8774 } |
| 8770 context.Dispose(); | 8775 context.Dispose(); |
| 8771 for (gc_count = 1; gc_count < 10; gc_count++) { | 8776 for (gc_count = 1; gc_count < 10; gc_count++) { |
| 8777 other_context->Enter(); |
| 8778 CompileRun(source_eval); |
| 8779 other_context->Exit(); |
| 8772 v8::internal::Heap::CollectAllGarbage(false); | 8780 v8::internal::Heap::CollectAllGarbage(false); |
| 8773 if (GetGlobalObjectsCount() == 0) break; | 8781 if (GetGlobalObjectsCount() == 1) break; |
| 8774 } | 8782 } |
| 8775 CHECK_EQ(0, GetGlobalObjectsCount()); | 8783 CHECK_GE(2, gc_count); |
| 8776 CHECK_EQ(2, gc_count); | 8784 CHECK_EQ(1, GetGlobalObjectsCount()); |
| 8777 | 8785 |
| 8778 // Looking up the line number for an exception creates reference from the | 8786 // Looking up the line number for an exception creates reference from the |
| 8779 // compilation cache to the global object. | 8787 // compilation cache to the global object. |
| 8788 const char* source_exception = "function f(){throw 1;} f()"; |
| 8780 context = Context::New(); | 8789 context = Context::New(); |
| 8781 { | 8790 { |
| 8782 v8::HandleScope scope; | 8791 v8::HandleScope scope; |
| 8783 | 8792 |
| 8784 context->Enter(); | 8793 context->Enter(); |
| 8785 v8::TryCatch try_catch; | 8794 v8::TryCatch try_catch; |
| 8786 CompileRun("function f(){throw 1;}; f()"); | 8795 CompileRun(source_exception); |
| 8787 CHECK(try_catch.HasCaught()); | 8796 CHECK(try_catch.HasCaught()); |
| 8788 v8::Handle<v8::Message> message = try_catch.Message(); | 8797 v8::Handle<v8::Message> message = try_catch.Message(); |
| 8789 CHECK(!message.IsEmpty()); | 8798 CHECK(!message.IsEmpty()); |
| 8790 CHECK_EQ(1, message->GetLineNumber()); | 8799 CHECK_EQ(1, message->GetLineNumber()); |
| 8791 context->Exit(); | 8800 context->Exit(); |
| 8792 } | 8801 } |
| 8793 context.Dispose(); | 8802 context.Dispose(); |
| 8794 for (gc_count = 1; gc_count < 10; gc_count++) { | 8803 for (gc_count = 1; gc_count < 10; gc_count++) { |
| 8804 other_context->Enter(); |
| 8805 CompileRun(source_exception); |
| 8806 other_context->Exit(); |
| 8795 v8::internal::Heap::CollectAllGarbage(false); | 8807 v8::internal::Heap::CollectAllGarbage(false); |
| 8796 if (GetGlobalObjectsCount() == 0) break; | 8808 if (GetGlobalObjectsCount() == 1) break; |
| 8797 } | 8809 } |
| 8798 CHECK_EQ(0, GetGlobalObjectsCount()); | 8810 CHECK_GE(2, gc_count); |
| 8799 CHECK_EQ(2, gc_count); | 8811 CHECK_EQ(1, GetGlobalObjectsCount()); |
| 8812 |
| 8813 other_context.Dispose(); |
| 8800 } | 8814 } |
| OLD | NEW |