v8/include
julien.gilli 1ee712ab86 Add SetAbortOnUncaughtExceptionCallback API
The --abort-on-uncaught-exception command line switch makes
Isolate::Throw abort if the error being thrown cannot be caught by a
try/catch block.

Embedders may want to use other mechanisms than try/catch blocks to
handle uncaught exceptions. For instance, Node.js has "domain" objects
that have error handlers that can handle uncaught exception like
following:

var d = domain.create();

d.on('error', function onError(err) {
  console.log('Handling error');
});

d.run(function() {
  throw new Error("boom");
});

These error handlers are called by isolates' message listeners.

If --abort-on-uncaught-exception is *not* used, the isolate's
message listener will be called, which will in turn call the domain's
error handler. The process will output 'Handling error' and will exit
successfully (not due to an uncaught exception). This is the behavior
that Node.js users expect.

However, if --abort-on-uncaught-exception is used and when throwing an
error within a domain that has an error handler, the process will abort
and the domain's error handler will not be called. This is not the
behavior that Node.js users expect.

Having a SetAbortOnUncaughtExceptionCallback API allows embedders to
determine when it's not appropriate to abort and instead handle the
exception via the isolate's message listener.

In the example above, Node.js would set a custom callback with
SetAbortOnUncaughtExceptionCallback that would be implemented as
following (the sample code has been simplified to remove what's not
relevant to this change):

bool ShouldAbortOnUncaughtException(Isolate* isolate) {
  return !IsDomainActive();
}

Now when --abort-on-uncaught-exception is used, Isolate::Throw would
call that callback and determine that it should not abort if a domain
with an error handler is active. Instead, the isolate's message listener
would be called and the error would be handled by the domain's error
handler.

I believe this can also be useful for other embedders.

BUG=

R=bmeurer@chromium.org

Review URL: https://codereview.chromium.org/1375933003

Cr-Commit-Position: refs/heads/master@{#31111}
2015-10-05 18:55:15 +00:00
..
libplatform Revert "Forward declaration for Isolate / Platform in libplatform.h." and "Fixes d8 on windows following.". 2014-11-19 07:28:07 +00:00
OWNERS Add myself to include/OWNERS 2015-04-21 10:05:59 +00:00
v8-debug.h [presubmit] Fix build/include linter violations. 2015-09-03 07:56:14 +00:00
v8-platform.h Add IdleTask API to v8::Platform. 2015-07-15 11:51:03 +00:00
v8-profiler.h [presubmit] Fix build/include linter violations. 2015-09-03 07:56:14 +00:00
v8-testing.h [presubmit] Fix build/include linter violations. 2015-09-03 07:56:14 +00:00
v8-util.h [presubmit] Fix build/include linter violations. 2015-09-03 07:56:14 +00:00
v8-version.h Update version to 4.8 2015-10-03 21:48:18 +00:00
v8.h Add SetAbortOnUncaughtExceptionCallback API 2015-10-05 18:55:15 +00:00
v8config.h Reland: Introduce a V8_NORETURN macro and use it to make GCC 4.9.2 happy again. 2015-10-05 16:34:54 +00:00