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

Unified Diff: test/cctest/test-api.cc

Issue 178073002: Raise StackOverflow during bootstrapping (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Raise StackOverflow during bootstrapping 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/isolate.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index c5c932b7516cc70738ad918a9311dabe1e985427..56a7f600718443590bf195c9560f6b0a06ddf347 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -4986,6 +4986,67 @@ TEST(APIStackOverflowAndVerboseTryCatch) {
v8::V8::RemoveMessageListeners(receive_message);
}
+void APIStackOverflowNestedContextsHelper(bool is_bottom_call);
Jarin 2014/03/25 15:28:33 In v8, bools as arguments are normally frowned upo
+
+void APIStackOverflowNestedContextsCallback(
+ const v8::FunctionCallbackInfo<Value>& args) {
+ APIStackOverflowNestedContextsHelper(false);
+}
+
+
+void APIStackOverflowNestedContextsHelper(bool is_bottom_call) {
+ v8::Isolate* isolate = CcTest::isolate();
+ TryCatch try_catch;
+
+ Local<ObjectTemplate> global = ObjectTemplate::New();
+ global->Set(String::NewFromUtf8(isolate, "recur"),
+ FunctionTemplate::New(isolate, APIStackOverflowNestedContextsCallback));
+
+ Local<Context> innerContext = Context::New(isolate, NULL, global);
+ if (try_catch.HasCaught()) {
+ try_catch.ReThrow();
+ return;
+ }
+ if (innerContext.IsEmpty()) return;
+
+ Context::Scope context_scope(innerContext);
+ Local<Script> script = v8::Script::Compile(v8::String::NewFromUtf8(
+ isolate,
+ "function f() { "
+ " try { recur(); } catch(e) { throw e; } "
+ " return 'bad'; "
+ "} f(); "));
+
+ Local<Value> result = script->Run();
+ CHECK(result.IsEmpty());
+ if (try_catch.HasCaught()) {
+ if (is_bottom_call) {
+ String::Utf8Value ex_value(try_catch.Exception());
+ CHECK_EQ("RangeError: Maximum call stack size exceeded", *ex_value);
+ }
+ try_catch.ReThrow();
+ }
+}
+
+
+void APIStackOverflowNestedContexts(int extra_stack_bytes) {
+ if (extra_stack_bytes) alloca(extra_stack_bytes);
+ LocalContext context;
+ v8::HandleScope scope(context->GetIsolate());
+ v8::TryCatch try_catch;
+ APIStackOverflowNestedContextsHelper(true);
+ CHECK(try_catch.HasCaught());
+}
+
+
+TEST(APIStackOverflowNestedContexts) {
+ // The place where a stack overflow can occur is not completely deterministic
+ // so probe a few different depths
+ APIStackOverflowNestedContexts(2500);
+ APIStackOverflowNestedContexts(2800);
+ APIStackOverflowNestedContexts(30000);
+}
+
THREADED_TEST(ExternalScriptException) {
v8::Isolate* isolate = CcTest::isolate();
« no previous file with comments | « src/isolate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698