From 750a822430afa8055cd28792ed7ec2d3854b7c00 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 1 Aug 2019 11:29:11 -0400 Subject: [PATCH 1/2] WIP Add test for #2703 ... --- core/libdeno/libdeno_test.cc | 21 +++++++++++++++++++++ core/libdeno/libdeno_test.js | 10 ++++++++++ 2 files changed, 31 insertions(+) diff --git a/core/libdeno/libdeno_test.cc b/core/libdeno/libdeno_test.cc index 16a4a11f61a7c1..7f6402e7a51fb1 100644 --- a/core/libdeno/libdeno_test.cc +++ b/core/libdeno/libdeno_test.cc @@ -281,3 +281,24 @@ TEST(LibDenoTest, WasmInstantiate) { deno_delete(d); } + +/* + + To run this test: + + ./tools/build.py libdeno_test && ./target/debug/libdeno_test + --gtest_filter=LibDenoTest.AsyncException + +*/ +TEST(LibDenoTest, AsyncException) { + Deno* d = deno_new(deno_config{0, snapshot, empty, nullptr, nullptr}); + EXPECT_EQ(deno_last_exception(d), nullptr); + deno_execute(d, nullptr, "a.js", "AsyncException()"); + + deno_check_promise_errors(d); + + // Note that there is only one frame in the JSON output.... + printf("deno_last_exception %s\n", deno_last_exception(d)); + + deno_delete(d); +} diff --git a/core/libdeno/libdeno_test.js b/core/libdeno/libdeno_test.js index 006c71666a570b..97200479a2d913 100644 --- a/core/libdeno/libdeno_test.js +++ b/core/libdeno/libdeno_test.js @@ -253,3 +253,13 @@ global.WasmInstantiate = () => { Deno.core.send(new Uint8Array([42])); })(); }; + +global.AsyncException = () => { + (async () => { + await Promise.resolve().then(() => { + const error = new Error; + Deno.core.print(error.stack + "\n"); + throw error; + }); + })() +}; From a3c898e3f3abf9525ce781ab6777aad7f8aaa348 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 1 Aug 2019 12:30:20 -0400 Subject: [PATCH 2/2] DEBUG PromiseRejectCallback --- core/libdeno/api.cc | 4 ++-- core/libdeno/binding.cc | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/libdeno/api.cc b/core/libdeno/api.cc index 61eeb43ca46703..54dacbc7ca1fc7 100644 --- a/core/libdeno/api.cc +++ b/core/libdeno/api.cc @@ -120,8 +120,8 @@ void deno_init() { // remove this to make it work asynchronously too. But that requires getting // PumpMessageLoop and RunMicrotasks setup correctly. // See https://github.com/denoland/deno/issues/2544 - const char* argv[2] = {"", "--no-wasm-async-compilation"}; - int argc = 2; + const char* argv[3] = {"", "--no-wasm-async-compilation", "--async-stack-traces"}; + int argc = 3; v8::V8::SetFlagsFromCommandLine(&argc, const_cast(argv), false); } } diff --git a/core/libdeno/binding.cc b/core/libdeno/binding.cc index da582a3bfa9d1d..d9fcc4ab50a72d 100644 --- a/core/libdeno/binding.cc +++ b/core/libdeno/binding.cc @@ -69,6 +69,12 @@ void PromiseRejectCallback(v8::PromiseRejectMessage promise_reject_message) { v8::Context::Scope context_scope(context); + auto message = v8::Exception::CreateMessage(isolate, error); + auto stack_trace = message->GetStackTrace(); + uint32_t count = static_cast(stack_trace->GetFrameCount()); + printf("FRAME COUNT %d\n", count); + + int promise_id = promise->GetIdentityHash(); switch (promise_reject_message.GetEvent()) { case v8::kPromiseRejectWithNoHandler: