Commit eee9fcbc authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[d8] Report errors in setTimeout

If an error is thrown in a setTimeout callback, exit d8 with an error
code.
This will allow us to test asynchronous failures better, see linked bug.

R=yangguo@chromium.org
CC=mathias@chromium.org

Bug: v8:6981
Change-Id: Ifad152e6039f12dc4ceaac0bdc4b87f709898087
Reviewed-on: https://chromium-review.googlesource.com/738372Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49104}
parent c61f9171
...@@ -595,6 +595,7 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source, ...@@ -595,6 +595,7 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
try_catch.SetVerbose(true); try_catch.SetVerbose(true);
MaybeLocal<Value> maybe_result; MaybeLocal<Value> maybe_result;
bool success = true;
{ {
PerIsolateData* data = PerIsolateData::Get(isolate); PerIsolateData* data = PerIsolateData::Get(isolate);
Local<Context> realm = Local<Context> realm =
...@@ -608,7 +609,7 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source, ...@@ -608,7 +609,7 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
return false; return false;
} }
maybe_result = script->Run(realm); maybe_result = script->Run(realm);
EmptyMessageQueues(isolate); if (!EmptyMessageQueues(isolate)) success = false;
data->realm_current_ = data->realm_switch_; data->realm_current_ = data->realm_switch_;
} }
Local<Value> result; Local<Value> result;
...@@ -634,7 +635,7 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source, ...@@ -634,7 +635,7 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
printf("\n"); printf("\n");
} }
} }
return true; return success;
} }
namespace { namespace {
...@@ -2910,7 +2911,7 @@ void Shell::SetWaitUntilDone(Isolate* isolate, bool value) { ...@@ -2910,7 +2911,7 @@ void Shell::SetWaitUntilDone(Isolate* isolate, bool value) {
} }
namespace { namespace {
void ProcessMessages(Isolate* isolate, bool ProcessMessages(Isolate* isolate,
std::function<platform::MessageLoopBehavior()> behavior) { std::function<platform::MessageLoopBehavior()> behavior) {
Platform* platform = GetDefaultPlatform(); Platform* platform = GetDefaultPlatform();
while (true) { while (true) {
...@@ -2932,9 +2933,10 @@ void ProcessMessages(Isolate* isolate, ...@@ -2932,9 +2933,10 @@ void ProcessMessages(Isolate* isolate,
Context::Scope context_scope(context); Context::Scope context_scope(context);
if (callback->Call(context, Undefined(isolate), 0, nullptr).IsEmpty()) { if (callback->Call(context, Undefined(isolate), 0, nullptr).IsEmpty()) {
Shell::ReportException(isolate, &try_catch); Shell::ReportException(isolate, &try_catch);
return; return false;
} }
} }
return true;
} }
} // anonymous namespace } // anonymous namespace
...@@ -2948,9 +2950,9 @@ void Shell::CompleteMessageLoop(Isolate* isolate) { ...@@ -2948,9 +2950,9 @@ void Shell::CompleteMessageLoop(Isolate* isolate) {
}); });
} }
void Shell::EmptyMessageQueues(Isolate* isolate) { bool Shell::EmptyMessageQueues(Isolate* isolate) {
ProcessMessages(isolate, return ProcessMessages(
[]() { return platform::MessageLoopBehavior::kDoNotWait; }); isolate, []() { return platform::MessageLoopBehavior::kDoNotWait; });
} }
class Serializer : public ValueSerializer::Delegate { class Serializer : public ValueSerializer::Delegate {
......
...@@ -358,7 +358,7 @@ class Shell : public i::AllStatic { ...@@ -358,7 +358,7 @@ class Shell : public i::AllStatic {
static void Exit(int exit_code); static void Exit(int exit_code);
static void OnExit(Isolate* isolate); static void OnExit(Isolate* isolate);
static void CollectGarbage(Isolate* isolate); static void CollectGarbage(Isolate* isolate);
static void EmptyMessageQueues(Isolate* isolate); static bool EmptyMessageQueues(Isolate* isolate);
static void EnsureEventLoopInitialized(Isolate* isolate); static void EnsureEventLoopInitialized(Isolate* isolate);
static void CompleteMessageLoop(Isolate* isolate); static void CompleteMessageLoop(Isolate* isolate);
......
...@@ -305,6 +305,9 @@ ...@@ -305,6 +305,9 @@
'js1_5/Regress/regress-317476': [FAIL], 'js1_5/Regress/regress-317476': [FAIL],
'js1_5/Regress/regress-314401': [FAIL], 'js1_5/Regress/regress-314401': [FAIL],
# d8 implements setTimeout, but not clearTimeout.
'js1_5/GC/regress-319980-01': [FAIL],
# Any local 'arguments' variable should not be allowed to shadow the value # Any local 'arguments' variable should not be allowed to shadow the value
# returned via the indirect 'arguments' property accessor. # returned via the indirect 'arguments' property accessor.
'js1_4/Functions/function-001': [FAIL_OK], 'js1_4/Functions/function-001': [FAIL_OK],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment