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

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

Issue 6672029: [Isolates] Enter default isolate in initializing API. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: [Isolates] Enter default isolate in initializing API. Created 9 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 | « src/api.cc ('k') | no next file » | 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-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 2063 matching lines...) Expand 10 before | Expand all | Expand 10 after
2074 "}"); 2074 "}");
2075 // Check for out of memory state. 2075 // Check for out of memory state.
2076 CHECK(result.IsEmpty()); 2076 CHECK(result.IsEmpty());
2077 CHECK(context->HasOutOfMemoryException()); 2077 CHECK(context->HasOutOfMemoryException());
2078 } 2078 }
2079 2079
2080 2080
2081 TEST(HugeConsStringOutOfMemory) { 2081 TEST(HugeConsStringOutOfMemory) {
2082 // It's not possible to read a snapshot into a heap with different dimensions. 2082 // It's not possible to read a snapshot into a heap with different dimensions.
2083 if (i::Snapshot::IsEnabled()) return; 2083 if (i::Snapshot::IsEnabled()) return;
2084 v8::HandleScope scope;
2085 LocalContext context;
2086 // Set heap limits. 2084 // Set heap limits.
2087 static const int K = 1024; 2085 static const int K = 1024;
2088 v8::ResourceConstraints constraints; 2086 v8::ResourceConstraints constraints;
2089 constraints.set_max_young_space_size(256 * K); 2087 constraints.set_max_young_space_size(256 * K);
2090 constraints.set_max_old_space_size(2 * K * K); 2088 constraints.set_max_old_space_size(2 * K * K);
2091 v8::SetResourceConstraints(&constraints); 2089 v8::SetResourceConstraints(&constraints);
2092 2090
2093 // Execute a script that causes out of memory. 2091 // Execute a script that causes out of memory.
2094 v8::V8::IgnoreOutOfMemoryException(); 2092 v8::V8::IgnoreOutOfMemoryException();
2095 2093
2094 v8::HandleScope scope;
2095 LocalContext context;
2096
2096 // Build huge string. This should fail with out of memory exception. 2097 // Build huge string. This should fail with out of memory exception.
2097 Local<Value> result = CompileRun( 2098 Local<Value> result = CompileRun(
2098 "var str = Array.prototype.join.call({length: 513}, \"A\").toUpperCase();" 2099 "var str = Array.prototype.join.call({length: 513}, \"A\").toUpperCase();"
2099 "for (var i = 0; i < 22; i++) { str = str + str; }"); 2100 "for (var i = 0; i < 22; i++) { str = str + str; }");
2100 2101
2101 // Check for out of memory state. 2102 // Check for out of memory state.
2102 CHECK(result.IsEmpty()); 2103 CHECK(result.IsEmpty());
2103 CHECK(context->HasOutOfMemoryException()); 2104 CHECK(context->HasOutOfMemoryException());
2104 } 2105 }
2105 2106
(...skipping 10774 matching lines...) Expand 10 before | Expand all | Expand 10 after
12880 CHECK_EQ(result1, 10946); 12881 CHECK_EQ(result1, 10946);
12881 CHECK_EQ(result2, 144); 12882 CHECK_EQ(result2, 144);
12882 CHECK_EQ(result1, thread1.result()); 12883 CHECK_EQ(result1, thread1.result());
12883 CHECK_EQ(result2, thread2.result()); 12884 CHECK_EQ(result2, thread2.result());
12884 12885
12885 isolate1->Dispose(); 12886 isolate1->Dispose();
12886 isolate2->Dispose(); 12887 isolate2->Dispose();
12887 } 12888 }
12888 12889
12889 12890
12891 class InitDefaultIsolateThread : public v8::internal::Thread {
12892 public:
12893 enum TestCase { IgnoreOOM, SetResourceConstraints, SetFatalHandler };
12894
12895 explicit InitDefaultIsolateThread(TestCase testCase)
12896 : Thread(NULL),
12897 testCase_(testCase),
12898 result_(false) { }
12899
12900 void Run() {
12901 switch (testCase_) {
12902 case IgnoreOOM:
12903 v8::V8::IgnoreOutOfMemoryException();
12904 break;
12905
12906 case SetResourceConstraints: {
12907 static const int K = 1024;
12908 v8::ResourceConstraints constraints;
12909 constraints.set_max_young_space_size(256 * K);
12910 constraints.set_max_old_space_size(4 * K * K);
12911 v8::SetResourceConstraints(&constraints);
12912 break;
12913 }
12914
12915 case SetFatalHandler:
12916 v8::V8::SetFatalErrorHandler(NULL);
12917 break;
12918
12919 }
12920 result_ = true;
12921 }
12922
12923 bool result() { return result_; }
12924
12925 private:
12926 TestCase testCase_;
12927 bool result_;
12928 };
12929
12930
12931 static void InitializeTestHelper(InitDefaultIsolateThread::TestCase testCase) {
12932 InitDefaultIsolateThread thread(testCase);
12933 thread.Start();
12934 thread.Join();
12935 CHECK_EQ(thread.result(), true);
12936 }
12937
12938 TEST(InitializeDefaultIsolateOnSecondaryThread1) {
12939 InitializeTestHelper(InitDefaultIsolateThread::IgnoreOOM);
12940 }
12941
12942 TEST(InitializeDefaultIsolateOnSecondaryThread2) {
12943 InitializeTestHelper(InitDefaultIsolateThread::SetResourceConstraints);
12944 }
12945
12946 TEST(InitializeDefaultIsolateOnSecondaryThread3) {
12947 InitializeTestHelper(InitDefaultIsolateThread::SetFatalHandler);
12948 }
12949
12950
12890 TEST(StringCheckMultipleContexts) { 12951 TEST(StringCheckMultipleContexts) {
12891 const char* code = 12952 const char* code =
12892 "(function() { return \"a\".charAt(0); })()"; 12953 "(function() { return \"a\".charAt(0); })()";
12893 12954
12894 { 12955 {
12895 // Run the code twice in the first context to initialize the call IC. 12956 // Run the code twice in the first context to initialize the call IC.
12896 v8::HandleScope scope; 12957 v8::HandleScope scope;
12897 LocalContext context1; 12958 LocalContext context1;
12898 ExpectString(code, "a"); 12959 ExpectString(code, "a");
12899 ExpectString(code, "a"); 12960 ExpectString(code, "a");
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
13213 v8::Handle<v8::Function> define_property = 13274 v8::Handle<v8::Function> define_property =
13214 CompileRun("(function() {" 13275 CompileRun("(function() {"
13215 " Object.defineProperty(" 13276 " Object.defineProperty("
13216 " this," 13277 " this,"
13217 " 1," 13278 " 1,"
13218 " { configurable: true, enumerable: true, value: 3 });" 13279 " { configurable: true, enumerable: true, value: 3 });"
13219 "})").As<Function>(); 13280 "})").As<Function>();
13220 context->DetachGlobal(); 13281 context->DetachGlobal();
13221 define_property->Call(proxy, 0, NULL); 13282 define_property->Call(proxy, 0, NULL);
13222 } 13283 }
OLDNEW
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698