Commit 6eee80fc authored by Yang Guo's avatar Yang Guo Committed by Commit Bot

[console] correctly propagate exceptions.

R=jgruber@chromium.org

Bug: v8:6774
Change-Id: Ie87306e9d6cc1574f8e1cc9dde38853eda07fd09
Reviewed-on: https://chromium-review.googlesource.com/645127
Commit-Queue: Yang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47745}
parent 4c19fa44
...@@ -61,14 +61,13 @@ void ConsoleCall( ...@@ -61,14 +61,13 @@ void ConsoleCall(
(isolate->console_delegate()->*func)( (isolate->console_delegate()->*func)(
wrapper, wrapper,
v8::debug::ConsoleContext(context_id, Utils::ToLocal(context_name))); v8::debug::ConsoleContext(context_id, Utils::ToLocal(context_name)));
CHECK(!isolate->has_pending_exception());
CHECK(!isolate->has_scheduled_exception());
} }
} // namespace } // namespace
#define CONSOLE_BUILTIN_IMPLEMENTATION(call, name) \ #define CONSOLE_BUILTIN_IMPLEMENTATION(call, name) \
BUILTIN(Console##call) { \ BUILTIN(Console##call) { \
ConsoleCall(isolate, args, &debug::ConsoleDelegate::call); \ ConsoleCall(isolate, args, &debug::ConsoleDelegate::call); \
RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate); \
return isolate->heap()->undefined_value(); \ return isolate->heap()->undefined_value(); \
} }
CONSOLE_METHOD_LIST(CONSOLE_BUILTIN_IMPLEMENTATION) CONSOLE_METHOD_LIST(CONSOLE_BUILTIN_IMPLEMENTATION)
......
...@@ -14,16 +14,11 @@ void WriteToFile(FILE* file, Isolate* isolate, ...@@ -14,16 +14,11 @@ void WriteToFile(FILE* file, Isolate* isolate,
HandleScope handle_scope(isolate); HandleScope handle_scope(isolate);
if (i != 0) fprintf(file, " "); if (i != 0) fprintf(file, " ");
// Explicitly catch potential exceptions in toString().
v8::TryCatch try_catch(isolate);
Local<Value> arg = args[i]; Local<Value> arg = args[i];
Local<String> str_obj; Local<String> str_obj;
if (arg->IsSymbol()) arg = Local<Symbol>::Cast(arg)->Name(); if (arg->IsSymbol()) arg = Local<Symbol>::Cast(arg)->Name();
if (!arg->ToString(isolate->GetCurrentContext()).ToLocal(&str_obj)) { if (!arg->ToString(isolate->GetCurrentContext()).ToLocal(&str_obj)) return;
Shell::ReportException(isolate, &try_catch);
return;
}
v8::String::Utf8Value str(isolate, str_obj); v8::String::Utf8Value str(isolate, str_obj);
int n = static_cast<int>(fwrite(*str, sizeof(**str), str.length(), file)); int n = static_cast<int>(fwrite(*str, sizeof(**str), str.length(), file));
...@@ -73,10 +68,7 @@ void D8Console::Time(const debug::ConsoleCallArguments& args, ...@@ -73,10 +68,7 @@ void D8Console::Time(const debug::ConsoleCallArguments& args,
Local<Value> arg = args[0]; Local<Value> arg = args[0];
Local<String> label; Local<String> label;
v8::TryCatch try_catch(isolate_); v8::TryCatch try_catch(isolate_);
if (!arg->ToString(isolate_->GetCurrentContext()).ToLocal(&label)) { if (!arg->ToString(isolate_->GetCurrentContext()).ToLocal(&label)) return;
Shell::ReportException(isolate_, &try_catch);
return;
}
v8::String::Utf8Value utf8(isolate_, label); v8::String::Utf8Value utf8(isolate_, label);
std::string string(*utf8); std::string string(*utf8);
auto find = timers_.find(string); auto find = timers_.find(string);
...@@ -100,10 +92,7 @@ void D8Console::TimeEnd(const debug::ConsoleCallArguments& args, ...@@ -100,10 +92,7 @@ void D8Console::TimeEnd(const debug::ConsoleCallArguments& args,
Local<Value> arg = args[0]; Local<Value> arg = args[0];
Local<String> label; Local<String> label;
v8::TryCatch try_catch(isolate_); v8::TryCatch try_catch(isolate_);
if (!arg->ToString(isolate_->GetCurrentContext()).ToLocal(&label)) { if (!arg->ToString(isolate_->GetCurrentContext()).ToLocal(&label)) return;
Shell::ReportException(isolate_, &try_catch);
return;
}
v8::String::Utf8Value utf8(isolate_, label); v8::String::Utf8Value utf8(isolate_, label);
std::string string(*utf8); std::string string(*utf8);
auto find = timers_.find(string); auto find = timers_.find(string);
......
...@@ -595,3 +595,29 @@ TEST(TerminateAndTryCall) { ...@@ -595,3 +595,29 @@ TEST(TerminateAndTryCall) {
CHECK_EQ(4, result.FromJust()); CHECK_EQ(4, result.FromJust());
CHECK(!isolate->IsExecutionTerminating()); CHECK(!isolate->IsExecutionTerminating());
} }
class ConsoleImpl : public v8::debug::ConsoleDelegate {
private:
void Log(const v8::debug::ConsoleCallArguments& args,
const v8::debug::ConsoleContext&) override {
CompileRun("1 + 1");
}
};
TEST(TerminateConsole) {
i::FLAG_allow_natives_syntax = true;
v8::Isolate* isolate = CcTest::isolate();
ConsoleImpl console;
v8::debug::SetConsoleDelegate(isolate, &console);
v8::HandleScope scope(isolate);
v8::Local<v8::ObjectTemplate> global = CreateGlobalTemplate(
isolate, TerminateCurrentThread, DoLoopCancelTerminate);
v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global);
v8::Context::Scope context_scope(context);
CHECK(!isolate->IsExecutionTerminating());
v8::TryCatch try_catch(isolate);
CHECK(!isolate->IsExecutionTerminating());
CHECK(CompileRun("terminate(); console.log(); fail();").IsEmpty());
CHECK(try_catch.HasCaught());
CHECK(!isolate->IsExecutionTerminating());
}
...@@ -3,5 +3,5 @@ ...@@ -3,5 +3,5 @@
// found in the LICENSE file. // found in the LICENSE file.
TypeError.prototype.__defineGetter__("name", () => { throw 42; }); TypeError.prototype.__defineGetter__("name", () => { throw 42; });
console.log({ toString: () => { throw new TypeError() }}); try { console.log({ toString: () => { throw new TypeError() }}); } catch (e) {}
try { new WebAssembly.Table({}); } catch (e) {} try { new WebAssembly.Table({}); } catch (e) {}
...@@ -5,6 +5,6 @@ ...@@ -5,6 +5,6 @@
if (this.Intl) { if (this.Intl) {
new Intl.v8BreakIterator(); new Intl.v8BreakIterator();
new Intl.DateTimeFormat(); new Intl.DateTimeFormat();
console.log({ toString: function() { throw 1; }}); try { console.log({ toString: function() { throw 1; }}); } catch (e) {}
new Intl.v8BreakIterator(); new Intl.v8BreakIterator();
} }
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