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

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

Issue 198253004: Introduce per-isolate assert scopes and API to guard JS execution. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: add missing file Created 6 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 14200 matching lines...) Expand 10 before | Expand all | Expand 10 after
14211 " sum = foo(i);" 14211 " sum = foo(i);"
14212 " return sum;" 14212 " return sum;"
14213 "}" 14213 "}"
14214 "function foo(i) { return i * i; };" 14214 "function foo(i) { return i * i; };"
14215 "bar();"; 14215 "bar();";
14216 14216
14217 // Run this test in a new isolate to make sure we don't 14217 // Run this test in a new isolate to make sure we don't
14218 // have remnants of state from other code. 14218 // have remnants of state from other code.
14219 v8::Isolate* isolate = v8::Isolate::New(); 14219 v8::Isolate* isolate = v8::Isolate::New();
14220 isolate->Enter(); 14220 isolate->Enter();
14221 i::Heap* heap = reinterpret_cast<i::Isolate*>(isolate)->heap(); 14221 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
14222 i::Heap* heap = i_isolate->heap();
14222 14223
14223 { 14224 {
14224 v8::HandleScope scope(isolate); 14225 v8::HandleScope scope(isolate);
14225 i::HashMap code(MatchPointers); 14226 i::HashMap code(MatchPointers);
14226 code_map = &code; 14227 code_map = &code;
14227 14228
14228 i::HashMap lineinfo(MatchPointers); 14229 i::HashMap lineinfo(MatchPointers);
14229 jitcode_line_info = &lineinfo; 14230 jitcode_line_info = &lineinfo;
14230 14231
14231 saw_bar = 0; 14232 saw_bar = 0;
14232 move_events = 0; 14233 move_events = 0;
14233 14234
14234 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler); 14235 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler);
14235 14236
14236 // Generate new code objects sparsely distributed across several 14237 // Generate new code objects sparsely distributed across several
14237 // different fragmented code-space pages. 14238 // different fragmented code-space pages.
14238 const int kIterations = 10; 14239 const int kIterations = 10;
14239 for (int i = 0; i < kIterations; ++i) { 14240 for (int i = 0; i < kIterations; ++i) {
14240 LocalContext env(isolate); 14241 LocalContext env(isolate);
14241 i::AlwaysAllocateScope always_allocate; 14242 i::AlwaysAllocateScope always_allocate(i_isolate);
14242 SimulateFullSpace(heap->code_space()); 14243 SimulateFullSpace(heap->code_space());
14243 CompileRun(script); 14244 CompileRun(script);
14244 14245
14245 // Keep a strong reference to the code object in the handle scope. 14246 // Keep a strong reference to the code object in the handle scope.
14246 i::Handle<i::Code> bar_code(i::Handle<i::JSFunction>::cast( 14247 i::Handle<i::Code> bar_code(i::Handle<i::JSFunction>::cast(
14247 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("bar"))))->code()); 14248 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("bar"))))->code());
14248 i::Handle<i::Code> foo_code(i::Handle<i::JSFunction>::cast( 14249 i::Handle<i::Code> foo_code(i::Handle<i::JSFunction>::cast(
14249 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("foo"))))->code()); 14250 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("foo"))))->code());
14250 14251
14251 // Clear the compilation cache to get more wastage. 14252 // Clear the compilation cache to get more wastage.
(...skipping 3390 matching lines...) Expand 10 before | Expand all | Expand 10 after
17642 CompileRunWithOrigin(code.start(), "", 0, 0); 17643 CompileRunWithOrigin(code.start(), "", 0, 0);
17643 CHECK(try_catch.HasCaught()); 17644 CHECK(try_catch.HasCaught());
17644 v8::String::Utf8Value stack(try_catch.StackTrace()); 17645 v8::String::Utf8Value stack(try_catch.StackTrace());
17645 CHECK(strstr(*stack, "at foo (source_url:3:5)") != NULL); 17646 CHECK(strstr(*stack, "at foo (source_url:3:5)") != NULL);
17646 } 17647 }
17647 17648
17648 17649
17649 static void CreateGarbageInOldSpace() { 17650 static void CreateGarbageInOldSpace() {
17650 i::Factory* factory = CcTest::i_isolate()->factory(); 17651 i::Factory* factory = CcTest::i_isolate()->factory();
17651 v8::HandleScope scope(CcTest::isolate()); 17652 v8::HandleScope scope(CcTest::isolate());
17652 i::AlwaysAllocateScope always_allocate; 17653 i::AlwaysAllocateScope always_allocate(CcTest::i_isolate());
17653 for (int i = 0; i < 1000; i++) { 17654 for (int i = 0; i < 1000; i++) {
17654 factory->NewFixedArray(1000, i::TENURED); 17655 factory->NewFixedArray(1000, i::TENURED);
17655 } 17656 }
17656 } 17657 }
17657 17658
17658 17659
17659 // Test that idle notification can be handled and eventually returns true. 17660 // Test that idle notification can be handled and eventually returns true.
17660 TEST(IdleNotification) { 17661 TEST(IdleNotification) {
17661 const intptr_t MB = 1024 * 1024; 17662 const intptr_t MB = 1024 * 1024;
17662 LocalContext env; 17663 LocalContext env;
(...skipping 4667 matching lines...) Expand 10 before | Expand all | Expand 10 after
22330 CompileRun("x1 = x2 = 0;"); 22331 CompileRun("x1 = x2 = 0;");
22331 r = v8::Promise::New(isolate); 22332 r = v8::Promise::New(isolate);
22332 r->Catch(f1)->Chain(f2); 22333 r->Catch(f1)->Chain(f2);
22333 r->Reject(v8::Integer::New(isolate, 3)); 22334 r->Reject(v8::Integer::New(isolate, 3));
22334 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); 22335 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
22335 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); 22336 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
22336 V8::RunMicrotasks(isolate); 22337 V8::RunMicrotasks(isolate);
22337 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value()); 22338 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value());
22338 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value()); 22339 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value());
22339 } 22340 }
22341
22342
22343 TEST(DisallowJavascriptExecutionScope) {
22344 LocalContext context;
22345 v8::Isolate* isolate = context->GetIsolate();
22346 v8::HandleScope scope(isolate);
22347 v8::Isolate::DisallowJavascriptExecutionScope no_js(isolate);
22348 CompileRun("2+2");
22349 }
22350
22351
22352 TEST(AllowJavascriptExecutionScope) {
22353 LocalContext context;
22354 v8::Isolate* isolate = context->GetIsolate();
22355 v8::HandleScope scope(isolate);
22356 v8::Isolate::DisallowJavascriptExecutionScope no_js(isolate);
22357 { v8::Isolate::AllowJavascriptExecutionScope yes_js(isolate);
22358 CompileRun("1+1");
22359 }
22360 }
OLDNEW
« include/v8.h ('K') | « test/cctest/cctest.status ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698