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: 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; + }); + })() +};