Skip to content

Instantly share code, notes, and snippets.

@misterdjules
Last active February 6, 2016 07:29
Show Gist options
  • Save misterdjules/eaf1322d90048ad2125c to your computer and use it in GitHub Desktop.
Save misterdjules/eaf1322d90048ad2125c to your computer and use it in GitHub Desktop.
Prototype of support for --abort-on-uncaught-exception with uncaught errors thrown from within promises
[root@00-0c-29-44-bf-9f ~]# mdb /zones/e1a453d7-9b7b-4721-aea6-791d38603cee/cores/core.node.16030
Loading modules: [ libumem.so.1 libc.so.1 ld.so.1 ]
> ::load /root/mdb_v8_amd64.so
mdb_v8 version: 1.1.1 (release, from 28cedf2)
V8 version: 4.8.271.17
Autoconfigured V8 support from target
C++ symbol demangling enabled
> ::jsstack
native: v8::base::OS::Abort+9
native: v8::internal::Runtime_Throw+0x30
(1 internal frame elided)
js: foo
js: boom
js: <anonymous> (as <anon>)
js: Promise
(1 internal frame elided)
js: <anonymous> (as <anon>)
(1 internal frame elided)
js: <anonymous> (as Module._compile)
js: <anonymous> (as Module._extensions..js)
js: <anonymous> (as Module.load)
js: <anonymous> (as Module._load)
js: <anonymous> (as Module.runMain)
js: startup
js: <anonymous> (as <anon>)
(1 internal frame elided)
(1 internal frame elided)
native: v8::internal::_GLOBAL__N_1::Invoke+0xb3
native: v8::internal::Execution::Call+0x62
native: v8::Function::Call+0xf6
native: v8::Function::Call+0x41
native: node::LoadEnvironment+0x1e8
native: node::Start+0x508
native: _start+0x6c
>
[jgilli@dev ~/node]$ ./node --abort-on-uncaught-exception test-promise-throw-in-resolver.js
Runtime_IsAbortOnUncaughtException
Uncaught Error: boom
FROM
foo (/home/jgilli/node/test-promise-throw-in-resolver.js:2:3)
boom (/home/jgilli/node/test-promise-throw-in-resolver.js:6:3)
/home/jgilli/node/test-promise-throw-in-resolver.js:10:3
Object.<anonymous> (/home/jgilli/node/test-promise-throw-in-resolver.js:9:19)
Module._compile (module.js:417:34)
Object.Module._extensions..js (module.js:426:10)
Module.load (module.js:357:32)
Function.Module._load (module.js:314:12)
Function.Module.runMain (module.js:451:10)
startup (node.js:140:18)
node.js:1004:3
Illegal Instruction (core dumped)
[jgilli@dev ~/node]$
diff --git a/deps/v8/src/js/promise.js b/deps/v8/src/js/promise.js
index d7e9a5c..a05f9a1 100644
--- a/deps/v8/src/js/promise.js
+++ b/deps/v8/src/js/promise.js
@@ -40,14 +40,24 @@ var GlobalPromise = function Promise(resolver) {
if (!IS_CALLABLE(resolver))
throw MakeTypeError(kResolverNotAFunction, resolver);
var promise = PromiseInit(this);
- try {
- %DebugPushPromise(promise, Promise, resolver);
- resolver(function(x) { PromiseResolve(promise, x) },
- function(r) { PromiseReject(promise, r) });
- } catch (e) {
- PromiseReject(promise, e);
- } finally {
- %DebugPopPromise();
+ if (%IsAbortOnUncaughtException()) {
+ try {
+ %DebugPushPromise(promise, Promise, resolver);
+ resolver(function(x) { PromiseResolve(promise, x) },
+ function(r) { PromiseReject(promise, r) });
+ } finally {
+ %DebugPopPromise();
+ }
+ } else {
+ try {
+ %DebugPushPromise(promise, Promise, resolver);
+ resolver(function(x) { PromiseResolve(promise, x) },
+ function(r) { PromiseReject(promise, r) });
+ } catch (e) {
+ PromiseReject(promise, e);
+ } finally {
+ %DebugPopPromise();
+ }
}
}
diff --git a/deps/v8/src/runtime/runtime-internal.cc b/deps/v8/src/runtime/runtime-internal.cc
index 478a954..874dad1 100644
--- a/deps/v8/src/runtime/runtime-internal.cc
+++ b/deps/v8/src/runtime/runtime-internal.cc
@@ -187,6 +187,15 @@ RUNTIME_FUNCTION(Runtime_PromiseRejectEvent) {
return isolate->heap()->undefined_value();
}
+RUNTIME_FUNCTION(Runtime_IsAbortOnUncaughtException) {
+ HandleScope scope(isolate);
+
+ if (FLAG_abort_on_uncaught_exception) {
+ return isolate->heap()->true_value();
+ }
+
+ return isolate->heap()->false_value();
+}
RUNTIME_FUNCTION(Runtime_PromiseRevokeReject) {
DCHECK(args.length() == 1);
diff --git a/deps/v8/src/runtime/runtime.h b/deps/v8/src/runtime/runtime.h
index 23f9bdc..467d42c 100644
--- a/deps/v8/src/runtime/runtime.h
+++ b/deps/v8/src/runtime/runtime.h
@@ -311,6 +311,7 @@ namespace internal {
#define FOR_EACH_INTRINSIC_INTERNAL(F) \
+ F(IsAbortOnUncaughtException, 0, 1) \
F(CheckIsBootstrapping, 0, 1) \
F(ExportFromRuntime, 1, 1) \
F(ExportExperimentalFromRuntime, 1, 1) \
function foo() {
throw new Error('boom');
}
function boom() {
foo();
}
var boomPromise = new Promise(function (resolve, reject) {
boom();
});
boomPromise();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment