Fixed exception handling in Realm.create().
authorishell <ishell@chromium.org>
Tue, 23 Jun 2015 15:08:42 +0000 (08:08 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 23 Jun 2015 15:08:50 +0000 (15:08 +0000)
BUG=chromium:501711
LOG=N

Review URL: https://codereview.chromium.org/1207453002

Cr-Commit-Position: refs/heads/master@{#29236}

src/api.cc
src/d8.cc
test/mjsunit/regress/regress-crbug-501711.js [new file with mode: 0644]

index 4b0ec63..ea1da69 100644 (file)
@@ -5584,7 +5584,12 @@ Local<Context> v8::Context::New(
   if (extensions == NULL) extensions = &no_extensions;
   i::Handle<i::Context> env =
       CreateEnvironment(isolate, extensions, global_template, global_object);
-  if (env.is_null()) return Local<Context>();
+  if (env.is_null()) {
+    if (isolate->has_pending_exception()) {
+      isolate->OptionalRescheduleException(true);
+    }
+    return Local<Context>();
+  }
   return Utils::ToLocal(scope.CloseAndEscape(env));
 }
 
index 0199c9c..b9b2294 100644 (file)
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -490,6 +490,7 @@ void Shell::RealmGlobal(const v8::FunctionCallbackInfo<v8::Value>& args) {
 // Realm.create() creates a new realm and returns its index.
 void Shell::RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args) {
   Isolate* isolate = args.GetIsolate();
+  TryCatch try_catch(isolate);
   PerIsolateData* data = PerIsolateData::Get(isolate);
   Persistent<Context>* old_realms = data->realms_;
   int index = data->realm_count_;
@@ -500,8 +501,13 @@ void Shell::RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args) {
   }
   delete[] old_realms;
   Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
-  data->realms_[index].Reset(
-      isolate, Context::New(isolate, NULL, global_template));
+  Local<Context> context = Context::New(isolate, NULL, global_template);
+  if (context.IsEmpty()) {
+    DCHECK(try_catch.HasCaught());
+    try_catch.ReThrow();
+    return;
+  }
+  data->realms_[index].Reset(isolate, context);
   args.GetReturnValue().Set(index);
 }
 
diff --git a/test/mjsunit/regress/regress-crbug-501711.js b/test/mjsunit/regress/regress-crbug-501711.js
new file mode 100644 (file)
index 0000000..f8eda6e
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --stack-size=100
+
+function f() {
+  try {
+    f();
+  } catch(e) {
+    Realm.create();
+  }
+}
+f();