OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 4679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4690 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); | 4690 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); |
4691 Local<Script> script = v8_compile("(function () {" | 4691 Local<Script> script = v8_compile("(function () {" |
4692 " unlock_for_a_moment();" | 4692 " unlock_for_a_moment();" |
4693 " return 42;" | 4693 " return 42;" |
4694 "})();"); | 4694 "})();"); |
4695 CHECK_EQ(42, script->Run()->Int32Value()); | 4695 CHECK_EQ(42, script->Run()->Int32Value()); |
4696 } | 4696 } |
4697 } | 4697 } |
4698 | 4698 |
4699 | 4699 |
4700 static void EnsureNoSurvivingGlobalObjects() { | 4700 static int GetSurvivingGlobalObjectsCount() { |
4701 int count = 0; | 4701 int count = 0; |
4702 v8::internal::Heap::CollectAllGarbage(); | 4702 v8::internal::Heap::CollectAllGarbage(); |
4703 v8::internal::HeapIterator it; | 4703 v8::internal::HeapIterator it; |
4704 while (it.has_next()) { | 4704 while (it.has_next()) { |
4705 v8::internal::HeapObject* object = it.next(); | 4705 v8::internal::HeapObject* object = it.next(); |
4706 if (object->IsJSGlobalObject()) { | 4706 if (object->IsJSGlobalObject()) { |
4707 count++; | 4707 count++; |
4708 } | 4708 } |
4709 } | 4709 } |
4710 #ifdef DEBUG | 4710 #ifdef DEBUG |
4711 if (count > 0) v8::internal::Heap::TracePathToGlobal(); | 4711 if (count > 0) v8::internal::Heap::TracePathToGlobal(); |
4712 #endif | 4712 #endif |
4713 CHECK_EQ(0, count); | 4713 return count; |
4714 } | 4714 } |
4715 | 4715 |
4716 | 4716 |
4717 // This test assumes that there are zero global objects when the | |
4718 // test starts. This is not going to be true if we are using the | |
4719 // API fuzzer. | |
4720 TEST(DontLeakGlobalObjects) { | 4717 TEST(DontLeakGlobalObjects) { |
4721 // Regression test for issues 1139850 and 1174891. | 4718 // Regression test for issues 1139850 and 1174891. |
4722 | 4719 |
4723 v8::internal::V8::Initialize(NULL); | 4720 v8::V8::Initialize(); |
4724 if (v8::internal::Snapshot::IsEnabled()) return; | |
4725 | 4721 |
4726 EnsureNoSurvivingGlobalObjects(); | 4722 int count = GetSurvivingGlobalObjectsCount(); |
4727 | 4723 |
4728 for (int i = 0; i < 5; i++) { | 4724 for (int i = 0; i < 5; i++) { |
4729 { v8::HandleScope scope; | 4725 { v8::HandleScope scope; |
4730 LocalContext context; | 4726 LocalContext context; |
4731 } | 4727 } |
4732 EnsureNoSurvivingGlobalObjects(); | 4728 CHECK_EQ(count, GetSurvivingGlobalObjectsCount()); |
4733 | 4729 |
4734 { v8::HandleScope scope; | 4730 { v8::HandleScope scope; |
4735 LocalContext context; | 4731 LocalContext context; |
4736 v8_compile("Date")->Run(); | 4732 v8_compile("Date")->Run(); |
4737 } | 4733 } |
4738 EnsureNoSurvivingGlobalObjects(); | 4734 CHECK_EQ(count, GetSurvivingGlobalObjectsCount()); |
4739 | 4735 |
4740 { v8::HandleScope scope; | 4736 { v8::HandleScope scope; |
4741 LocalContext context; | 4737 LocalContext context; |
4742 v8_compile("/aaa/")->Run(); | 4738 v8_compile("/aaa/")->Run(); |
4743 } | 4739 } |
4744 EnsureNoSurvivingGlobalObjects(); | 4740 CHECK_EQ(count, GetSurvivingGlobalObjectsCount()); |
4745 | 4741 |
4746 { v8::HandleScope scope; | 4742 { v8::HandleScope scope; |
4747 const char* extension_list[] = { "v8/gc" }; | 4743 const char* extension_list[] = { "v8/gc" }; |
4748 v8::ExtensionConfiguration extensions(1, extension_list); | 4744 v8::ExtensionConfiguration extensions(1, extension_list); |
4749 LocalContext context(&extensions); | 4745 LocalContext context(&extensions); |
4750 v8_compile("gc();")->Run(); | 4746 v8_compile("gc();")->Run(); |
4751 } | 4747 } |
4752 EnsureNoSurvivingGlobalObjects(); | 4748 CHECK_EQ(count, GetSurvivingGlobalObjectsCount()); |
4753 | 4749 |
4754 { v8::HandleScope scope; | 4750 { v8::HandleScope scope; |
4755 const char* extension_list[] = { "v8/print" }; | 4751 const char* extension_list[] = { "v8/print" }; |
4756 v8::ExtensionConfiguration extensions(1, extension_list); | 4752 v8::ExtensionConfiguration extensions(1, extension_list); |
4757 LocalContext context(&extensions); | 4753 LocalContext context(&extensions); |
4758 v8_compile("print('hest');")->Run(); | 4754 v8_compile("print('hest');")->Run(); |
4759 } | 4755 } |
4760 EnsureNoSurvivingGlobalObjects(); | 4756 CHECK_EQ(count, GetSurvivingGlobalObjectsCount()); |
4761 } | 4757 } |
4762 } | 4758 } |
4763 | 4759 |
4764 | 4760 |
4765 THREADED_TEST(CheckForCrossContextObjectLiterals) { | 4761 THREADED_TEST(CheckForCrossContextObjectLiterals) { |
4766 v8::internal::V8::Initialize(NULL); | 4762 v8::V8::Initialize(); |
4767 if (v8::internal::Snapshot::IsEnabled()) return; | |
4768 | 4763 |
4769 const int nof = 2; | 4764 const int nof = 2; |
4770 const char* sources[nof] = { | 4765 const char* sources[nof] = { |
4771 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }", | 4766 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }", |
4772 "Object()" | 4767 "Object()" |
4773 }; | 4768 }; |
4774 | 4769 |
4775 for (int i = 0; i < nof; i++) { | 4770 for (int i = 0; i < nof; i++) { |
4776 const char* source = sources[i]; | 4771 const char* source = sources[i]; |
4777 { v8::HandleScope scope; | 4772 { v8::HandleScope scope; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4890 CHECK_EQ(10, message->GetLineNumber()); | 4885 CHECK_EQ(10, message->GetLineNumber()); |
4891 CHECK_EQ(91, message->GetStartPosition()); | 4886 CHECK_EQ(91, message->GetStartPosition()); |
4892 CHECK_EQ(92, message->GetEndPosition()); | 4887 CHECK_EQ(92, message->GetEndPosition()); |
4893 CHECK_EQ(2, message->GetStartColumn()); | 4888 CHECK_EQ(2, message->GetStartColumn()); |
4894 CHECK_EQ(3, message->GetEndColumn()); | 4889 CHECK_EQ(3, message->GetEndColumn()); |
4895 v8::String::AsciiValue line(message->GetSourceLine()); | 4890 v8::String::AsciiValue line(message->GetSourceLine()); |
4896 CHECK_EQ(" throw 'nirk';", *line); | 4891 CHECK_EQ(" throw 'nirk';", *line); |
4897 v8::String::AsciiValue name(message->GetScriptResourceName()); | 4892 v8::String::AsciiValue name(message->GetScriptResourceName()); |
4898 CHECK_EQ("test.js", *name); | 4893 CHECK_EQ("test.js", *name); |
4899 } | 4894 } |
OLD | NEW |