-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
src: fix domains + --abort-on-uncaught-exception #922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
chrisdickinson
wants to merge
7
commits into
nodejs:v1.x
from
chrisdickinson:fix-abort-on-uncaught-plus-domains
Closed
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7ccdd2c
src: fix domains + --abort-on-uncaught-exception
chrisdickinson 10e8bc6
add netServer test
chrisdickinson b67ed52
rename test
chrisdickinson 43bed4d
preserve original context
chrisdickinson 6c55bae
fix typo
chrisdickinson ecc033a
actually execute the code!
chrisdickinson 2e1332b
fix per @bnoordhuis review
chrisdickinson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
|
|
||
| #include "v8.h" | ||
|
|
||
| using v8::Array; | ||
| using v8::Context; | ||
| using v8::Function; | ||
| using v8::FunctionCallbackInfo; | ||
|
|
@@ -81,6 +82,7 @@ Handle<Value> AsyncWrap::MakeCallback(const Handle<Function> cb, | |
| Local<Object> process = env()->process_object(); | ||
| Local<Object> domain; | ||
| bool has_domain = false; | ||
| bool has_abort_on_uncaught_and_domains = false; | ||
|
|
||
| if (env()->using_domains()) { | ||
| Local<Value> domain_v = context->Get(env()->domain_string()); | ||
|
|
@@ -89,6 +91,7 @@ Handle<Value> AsyncWrap::MakeCallback(const Handle<Function> cb, | |
| domain = domain_v.As<Object>(); | ||
| if (domain->Get(env()->disposed_string())->IsTrue()) | ||
| return Undefined(env()->isolate()); | ||
| has_abort_on_uncaught_and_domains = env()->using_abort_on_uncaught_exc(); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -112,7 +115,21 @@ Handle<Value> AsyncWrap::MakeCallback(const Handle<Function> cb, | |
| try_catch.SetVerbose(true); | ||
| } | ||
|
|
||
| Local<Value> ret = cb->Call(context, argc, argv); | ||
| Local<Value> ret; | ||
|
|
||
| if (has_abort_on_uncaught_and_domains) { | ||
| Local<Value> fn = process->Get(env()->domain_abort_uncaught_exc_string()); | ||
| if (fn->IsFunction()) { | ||
| Local<Array> specialContext = Array::New(env()->isolate(), 2); | ||
| specialContext->Set(0, context); | ||
| specialContext->Set(1, cb); | ||
| ret = fn.As<Function>()->Call(specialContext.As<Object>(), argc, argv); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Array is-a Object, you don't have to cast it. |
||
| } else { | ||
| ret = cb->Call(context, argc, argv); | ||
| } | ||
| } else { | ||
| ret = cb->Call(context, argc, argv); | ||
| } | ||
|
|
||
| if (try_catch.HasCaught()) { | ||
| return Undefined(env()->isolate()); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| var common = require('../common'); | ||
| var assert = require('assert'); | ||
| var spawn = require('child_process').spawn; | ||
|
|
||
| var tests = [ | ||
| nextTick, | ||
| timer, | ||
| timerPlusNextTick, | ||
| firstRun, | ||
| netServer | ||
| ] | ||
|
|
||
| tests.forEach(function(test) { | ||
| console.log(test.name); | ||
| var child = spawn(process.execPath, [ | ||
| '--abort-on-uncaught-exception', | ||
| '-e', | ||
| '(' + test+ ')()', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Teeny style issue: space before operator. |
||
| common.PORT | ||
| ]); | ||
| child.stderr.pipe(process.stderr); | ||
| child.stdout.pipe(process.stdout); | ||
| child.on('exit', function(code) { | ||
| assert.strictEqual(code, 0); | ||
| }); | ||
| }); | ||
|
|
||
| function nextTick() { | ||
| var domain = require('domain'); | ||
| var d = domain.create(); | ||
|
|
||
| d.on('error', function(err) { | ||
| console.log('ok'); | ||
| process.exit(0); | ||
| }); | ||
| d.run(function() { | ||
| process.nextTick(function() { | ||
| throw new Error('exceptional!'); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| function timer() { | ||
| var domain = require('domain'); | ||
| var d = domain.create(); | ||
|
|
||
| d.on('error', function(err) { | ||
| console.log('ok'); | ||
| process.exit(0); | ||
| }); | ||
| d.run(function() { | ||
| setTimeout(function() { | ||
| throw new Error('exceptional!'); | ||
| }, 33); | ||
| }); | ||
| } | ||
|
|
||
| function timerPlusNextTick() { | ||
| var domain = require('domain'); | ||
| var d = domain.create(); | ||
|
|
||
| d.on('error', function(err) { | ||
| console.log('ok'); | ||
| process.exit(0); | ||
| }); | ||
| d.run(function() { | ||
| setTimeout(function() { | ||
| process.nextTick(function() { | ||
| throw new Error('exceptional!'); | ||
| }); | ||
| }, 33); | ||
| }); | ||
| } | ||
|
|
||
| function firstRun() { | ||
| var domain = require('domain'); | ||
| var d = domain.create(); | ||
|
|
||
| d.on('error', function(err) { | ||
| console.log('ok'); | ||
| process.exit(0); | ||
| }); | ||
| d.run(function() { | ||
| throw new Error('exceptional!'); | ||
| }); | ||
| } | ||
|
|
||
| function netServer() { | ||
| var domain = require('domain'); | ||
| var net = require('net'); | ||
| var d = domain.create(); | ||
|
|
||
| d.on('error', function(err) { | ||
| console.log('ok'); | ||
| process.exit(0); | ||
| }); | ||
| d.run(function() { | ||
| var server = net.createServer(function(conn) { | ||
| conn.pipe(conn); | ||
| }); | ||
| server.listen(Number(process.argv[1]), '0.0.0.0', function() { | ||
| var conn = net.connect(Number(process.argv[1]), '0.0.0.0') | ||
| conn.once('data', function() { | ||
| throw new Error('ok'); | ||
| }) | ||
| conn.end('ok'); | ||
| }); | ||
| }); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor style nit: snake_case, not camelCase.