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