Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / v8 / src / execution.cc
index f146c30..7aa4f33 100644 (file)
@@ -150,40 +150,43 @@ MaybeHandle<Object> Execution::New(Handle<JSFunction> func,
 
 
 MaybeHandle<Object> Execution::TryCall(Handle<JSFunction> func,
-                                       Handle<Object> receiver,
-                                       int argc,
+                                       Handle<Object> receiver, int argc,
                                        Handle<Object> args[],
-                                       Handle<Object>* exception_out) {
+                                       MaybeHandle<Object>* exception_out) {
+  bool is_termination = false;
+  Isolate* isolate = func->GetIsolate();
+  MaybeHandle<Object> maybe_result;
+  if (exception_out != NULL) *exception_out = MaybeHandle<Object>();
   // Enter a try-block while executing the JavaScript code. To avoid
   // duplicate error printing it must be non-verbose.  Also, to avoid
   // creating message objects during stack overflow we shouldn't
   // capture messages.
-  v8::TryCatch catcher;
-  catcher.SetVerbose(false);
-  catcher.SetCaptureMessage(false);
-
-  // Get isolate now, because handle might be persistent
-  // and get destroyed in the next call.
-  Isolate* isolate = func->GetIsolate();
-  MaybeHandle<Object> maybe_result = Invoke(false, func, receiver, argc, args);
-
-  if (maybe_result.is_null()) {
-    DCHECK(catcher.HasCaught());
-    DCHECK(isolate->has_pending_exception());
-    DCHECK(isolate->external_caught_exception());
-    if (exception_out != NULL) {
-      if (isolate->pending_exception() ==
-          isolate->heap()->termination_exception()) {
-        *exception_out = isolate->factory()->termination_exception();
-      } else {
-        *exception_out = v8::Utils::OpenHandle(*catcher.Exception());
+  {
+    v8::TryCatch catcher;
+    catcher.SetVerbose(false);
+    catcher.SetCaptureMessage(false);
+
+    maybe_result = Invoke(false, func, receiver, argc, args);
+
+    if (maybe_result.is_null()) {
+      DCHECK(catcher.HasCaught());
+      DCHECK(isolate->has_pending_exception());
+      DCHECK(isolate->external_caught_exception());
+      if (exception_out != NULL) {
+        if (isolate->pending_exception() ==
+            isolate->heap()->termination_exception()) {
+          is_termination = true;
+        } else {
+          *exception_out = v8::Utils::OpenHandle(*catcher.Exception());
+        }
       }
+      isolate->OptionalRescheduleException(true);
     }
-    isolate->OptionalRescheduleException(true);
-  }
 
-  DCHECK(!isolate->has_pending_exception());
-  DCHECK(!isolate->external_caught_exception());
+    DCHECK(!isolate->has_pending_exception());
+    DCHECK(!isolate->external_caught_exception());
+  }
+  if (is_termination) isolate->TerminateExecution();
   return maybe_result;
 }
 
@@ -236,10 +239,9 @@ MaybeHandle<Object> Execution::TryGetFunctionDelegate(Isolate* isolate,
 
   // If the Object doesn't have an instance-call handler we should
   // throw a non-callable exception.
-  i::Handle<i::Object> error_obj = isolate->factory()->NewTypeError(
-      "called_non_callable", i::HandleVector<i::Object>(&object, 1));
-
-  return isolate->Throw<Object>(error_obj);
+  THROW_NEW_ERROR(isolate, NewTypeError("called_non_callable",
+                                        i::HandleVector<i::Object>(&object, 1)),
+                  Object);
 }
 
 
@@ -293,9 +295,9 @@ MaybeHandle<Object> Execution::TryGetConstructorDelegate(
 
   // If the Object doesn't have an instance-call handler we should
   // throw a non-callable exception.
-  i::Handle<i::Object> error_obj = isolate->factory()->NewTypeError(
-      "called_non_callable", i::HandleVector<i::Object>(&object, 1));
-  return isolate->Throw<Object>(error_obj);
+  THROW_NEW_ERROR(isolate, NewTypeError("called_non_callable",
+                                        i::HandleVector<i::Object>(&object, 1)),
+                  Object);
 }
 
 
@@ -484,7 +486,7 @@ void StackGuard::InitThread(const ExecutionAccess& lock) {
     return Call(isolate,                                                \
                 isolate->name##_fun(),                                  \
                 isolate->js_builtins_object(),                          \
-                ARRAY_SIZE(argv), argv);                                \
+                arraysize(argv), argv);                                \
   } while (false)
 
 
@@ -575,7 +577,7 @@ Handle<Object> Execution::CharAt(Handle<String> string, uint32_t index) {
   Handle<Object> result;
   if (!TryCall(Handle<JSFunction>::cast(char_at),
                string,
-               ARRAY_SIZE(index_arg),
+               arraysize(index_arg),
                index_arg).ToHandle(&result)) {
     return factory->undefined_value();
   }
@@ -602,7 +604,7 @@ MaybeHandle<JSFunction> Execution::InstantiateFunction(
       Call(isolate,
            isolate->instantiate_fun(),
            isolate->js_builtins_object(),
-           ARRAY_SIZE(args),
+           arraysize(args),
            args),
       JSFunction);
   return Handle<JSFunction>::cast(result);
@@ -629,7 +631,7 @@ MaybeHandle<JSObject> Execution::InstantiateObject(
         Call(isolate,
              isolate->instantiate_fun(),
              isolate->js_builtins_object(),
-             ARRAY_SIZE(args),
+             arraysize(args),
              args),
         JSObject);
   }
@@ -645,7 +647,7 @@ MaybeHandle<Object> Execution::ConfigureInstance(
   return Execution::Call(isolate,
                          isolate->configure_instance_fun(),
                          isolate->js_builtins_object(),
-                         ARRAY_SIZE(args),
+                         arraysize(args),
                          args);
 }
 
@@ -659,7 +661,7 @@ Handle<String> Execution::GetStackTraceLine(Handle<Object> recv,
   MaybeHandle<Object> maybe_result =
       TryCall(isolate->get_stack_trace_line_fun(),
               isolate->js_builtins_object(),
-              ARRAY_SIZE(args),
+              arraysize(args),
               args);
   Handle<Object> result;
   if (!maybe_result.ToHandle(&result) || !result->IsString()) {