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

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

Issue 46103: Fixed some memory leaks in unit tests. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 9 months 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 | « no previous file | test/cctest/test-ast.cc » ('j') | 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-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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // pseudorandomly select a successor thread and switch execution 110 // pseudorandomly select a successor thread and switch execution
111 // to that thread, suspending the current test. 111 // to that thread, suspending the current test.
112 class ApiTestFuzzer: public v8::internal::Thread { 112 class ApiTestFuzzer: public v8::internal::Thread {
113 public: 113 public:
114 void CallTest(); 114 void CallTest();
115 explicit ApiTestFuzzer(int num) 115 explicit ApiTestFuzzer(int num)
116 : test_number_(num), 116 : test_number_(num),
117 gate_(v8::internal::OS::CreateSemaphore(0)), 117 gate_(v8::internal::OS::CreateSemaphore(0)),
118 active_(true) { 118 active_(true) {
119 } 119 }
120 ~ApiTestFuzzer() { delete gate_; }
120 121
121 // The ApiTestFuzzer is also a Thread, so it has a Run method. 122 // The ApiTestFuzzer is also a Thread, so it has a Run method.
122 virtual void Run(); 123 virtual void Run();
123 124
124 enum PartOfTest { FIRST_PART, SECOND_PART }; 125 enum PartOfTest { FIRST_PART, SECOND_PART };
125 126
126 static void Setup(PartOfTest part); 127 static void Setup(PartOfTest part);
127 static void RunAllTests(); 128 static void RunAllTests();
128 static void TearDown(); 129 static void TearDown();
129 // This method switches threads if we are running the Threading test. 130 // This method switches threads if we are running the Threading test.
(...skipping 5429 matching lines...) Expand 10 before | Expand all | Expand 10 after
5559 THREADED_TEST(AccessChecksReenabledCorrectly) { 5560 THREADED_TEST(AccessChecksReenabledCorrectly) {
5560 v8::HandleScope scope; 5561 v8::HandleScope scope;
5561 LocalContext context; 5562 LocalContext context;
5562 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5563 Local<ObjectTemplate> templ = ObjectTemplate::New();
5563 templ->SetAccessCheckCallbacks(NamedGetAccessBlocker, 5564 templ->SetAccessCheckCallbacks(NamedGetAccessBlocker,
5564 IndexedGetAccessBlocker); 5565 IndexedGetAccessBlocker);
5565 templ->Set(v8_str("a"), v8_str("a")); 5566 templ->Set(v8_str("a"), v8_str("a"));
5566 // Add more than 8 (see kMaxFastProperties) properties 5567 // Add more than 8 (see kMaxFastProperties) properties
5567 // so that the constructor will force copying map. 5568 // so that the constructor will force copying map.
5568 // Cannot sprintf, gcc complains unsafety. 5569 // Cannot sprintf, gcc complains unsafety.
5569 char buf[5]; 5570 char buf[4];
5570 for (char i = '0'; i <= '9' ; i++) { 5571 for (char i = '0'; i <= '9' ; i++) {
5571 buf[1] = i; 5572 buf[0] = i;
5572 for (char j = '0'; j <= '9'; j++) { 5573 for (char j = '0'; j <= '9'; j++) {
5573 buf[2] = j; 5574 buf[1] = j;
5574 for (char k = '0'; k <= '9'; k++) { 5575 for (char k = '0'; k <= '9'; k++) {
5575 buf[3] = k; 5576 buf[2] = k;
5576 buf[4] = 0; 5577 buf[3] = 0;
5577 templ->Set(v8_str(buf), v8::Number::New(k)); 5578 templ->Set(v8_str(buf), v8::Number::New(k));
5578 } 5579 }
5579 } 5580 }
5580 } 5581 }
5581 5582
5582 Local<v8::Object> instance_1 = templ->NewInstance(); 5583 Local<v8::Object> instance_1 = templ->NewInstance();
5583 context->Global()->Set(v8_str("obj_1"), instance_1); 5584 context->Global()->Set(v8_str("obj_1"), instance_1);
5584 5585
5585 Local<Value> value_1 = CompileRun("obj_1.a"); 5586 Local<Value> value_1 = CompileRun("obj_1.a");
5586 CHECK(value_1->IsUndefined()); 5587 CHECK(value_1->IsUndefined());
(...skipping 27 matching lines...) Expand all
5614 // without initializing the whole VM. Thus we cannot run this test in a 5615 // without initializing the whole VM. Thus we cannot run this test in a
5615 // multi-threaded setup. 5616 // multi-threaded setup.
5616 TEST(PreCompile) { 5617 TEST(PreCompile) {
5617 // TODO(155): This test would break without the initialization of V8. This is 5618 // TODO(155): This test would break without the initialization of V8. This is
5618 // a workaround for now to make this test not fail. 5619 // a workaround for now to make this test not fail.
5619 v8::V8::Initialize(); 5620 v8::V8::Initialize();
5620 const char *script = "function foo(a) { return a+1; }"; 5621 const char *script = "function foo(a) { return a+1; }";
5621 v8::ScriptData *sd = v8::ScriptData::PreCompile(script, strlen(script)); 5622 v8::ScriptData *sd = v8::ScriptData::PreCompile(script, strlen(script));
5622 CHECK_NE(sd->Length(), 0); 5623 CHECK_NE(sd->Length(), 0);
5623 CHECK_NE(sd->Data(), NULL); 5624 CHECK_NE(sd->Data(), NULL);
5625 delete sd;
5624 } 5626 }
5625 5627
5626 5628
5627 // This tests that we do not allow dictionary load/call inline caches 5629 // This tests that we do not allow dictionary load/call inline caches
5628 // to use functions that have not yet been compiled. The potential 5630 // to use functions that have not yet been compiled. The potential
5629 // problem of loading a function that has not yet been compiled can 5631 // problem of loading a function that has not yet been compiled can
5630 // arise because we share code between contexts via the compilation 5632 // arise because we share code between contexts via the compilation
5631 // cache. 5633 // cache.
5632 THREADED_TEST(DictionaryICLoadedFunction) { 5634 THREADED_TEST(DictionaryICLoadedFunction) {
5633 v8::HandleScope scope; 5635 v8::HandleScope scope;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
5695 5697
5696 LongRunningRegExp(); 5698 LongRunningRegExp();
5697 { 5699 {
5698 v8::Unlocker unlock; 5700 v8::Unlocker unlock;
5699 gc_thread.Join(); 5701 gc_thread.Join();
5700 } 5702 }
5701 v8::Locker::StopPreemption(); 5703 v8::Locker::StopPreemption();
5702 CHECK(regexp_success_); 5704 CHECK(regexp_success_);
5703 CHECK(gc_success_); 5705 CHECK(gc_success_);
5704 } 5706 }
5707 RegExpInterruptTest() : block_(NULL) {}
5708 ~RegExpInterruptTest() { delete block_; }
5705 private: 5709 private:
5706 // Number of garbage collections required. 5710 // Number of garbage collections required.
5707 static const int kRequiredGCs = 5; 5711 static const int kRequiredGCs = 5;
5708 5712
5709 class GCThread : public i::Thread { 5713 class GCThread : public i::Thread {
5710 public: 5714 public:
5711 explicit GCThread(RegExpInterruptTest* test) 5715 explicit GCThread(RegExpInterruptTest* test)
5712 : test_(test) {} 5716 : test_(test) {}
5713 virtual void Run() { 5717 virtual void Run() {
5714 test_->CollectGarbage(); 5718 test_->CollectGarbage();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
5792 5796
5793 // Local context should still be live. 5797 // Local context should still be live.
5794 CHECK(!local_env.IsEmpty()); 5798 CHECK(!local_env.IsEmpty());
5795 local_env->Enter(); 5799 local_env->Enter();
5796 5800
5797 // Should complete without problems. 5801 // Should complete without problems.
5798 RegExpInterruptTest().RunTest(); 5802 RegExpInterruptTest().RunTest();
5799 5803
5800 local_env->Exit(); 5804 local_env->Exit();
5801 } 5805 }
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698