summaryrefslogtreecommitdiff
path: root/test/addons/repl-domain-abort
diff options
context:
space:
mode:
authorTrevor Norris <trev.norris@gmail.com>2014-09-02 11:30:45 -0700
committerTrevor Norris <trev.norris@gmail.com>2014-09-02 11:30:45 -0700
commit81a9739108bd3959b4b1331d3a2833a18bc2b2b4 (patch)
tree8dc10da5dfd3936922fafec0c295091270712e2a /test/addons/repl-domain-abort
parentcdc01faed2b92f43a58cb86ff3300af1322cfaf6 (diff)
downloadandroid-node-v8-81a9739108bd3959b4b1331d3a2833a18bc2b2b4.tar.gz
android-node-v8-81a9739108bd3959b4b1331d3a2833a18bc2b2b4.tar.bz2
android-node-v8-81a9739108bd3959b4b1331d3a2833a18bc2b2b4.zip
node,async-wrap: verify domain enter/exit are set
The REPL global object lazy loads modules by placing getters for each. This causes MakeDomainCallback() to be run if a native module is loaded from the REPL, but if the domain module hasn't been loaded then there are no enter/exit callbacks to be called. Causing an assert() to fail. Fix the issue by conditionally running the callback instead of asserting it is available. Also add "addon" test to verify the fix. Fixes: #8231 Signed-off-by: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'test/addons/repl-domain-abort')
-rw-r--r--test/addons/repl-domain-abort/binding.cc47
-rw-r--r--test/addons/repl-domain-abort/binding.gyp8
-rw-r--r--test/addons/repl-domain-abort/test.js64
3 files changed, 119 insertions, 0 deletions
diff --git a/test/addons/repl-domain-abort/binding.cc b/test/addons/repl-domain-abort/binding.cc
new file mode 100644
index 0000000000..1337395c1b
--- /dev/null
+++ b/test/addons/repl-domain-abort/binding.cc
@@ -0,0 +1,47 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+#include <node.h>
+#include <v8.h>
+
+using v8::Function;
+using v8::FunctionCallbackInfo;
+using v8::Handle;
+using v8::HandleScope;
+using v8::Isolate;
+using v8::Object;
+using v8::Value;
+
+void Method(const FunctionCallbackInfo<Value>& args) {
+ Isolate* isolate = args.GetIsolate();
+ HandleScope scope(isolate);
+ node::MakeCallback(isolate,
+ isolate->GetCurrentContext()->Global(),
+ args[0].As<Function>(),
+ 0,
+ NULL);
+}
+
+void init(Handle<Object> target) {
+ NODE_SET_METHOD(target, "method", Method);
+}
+
+NODE_MODULE(binding, init);
diff --git a/test/addons/repl-domain-abort/binding.gyp b/test/addons/repl-domain-abort/binding.gyp
new file mode 100644
index 0000000000..3bfb84493f
--- /dev/null
+++ b/test/addons/repl-domain-abort/binding.gyp
@@ -0,0 +1,8 @@
+{
+ 'targets': [
+ {
+ 'target_name': 'binding',
+ 'sources': [ 'binding.cc' ]
+ }
+ ]
+}
diff --git a/test/addons/repl-domain-abort/test.js b/test/addons/repl-domain-abort/test.js
new file mode 100644
index 0000000000..c35faafb45
--- /dev/null
+++ b/test/addons/repl-domain-abort/test.js
@@ -0,0 +1,64 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var assert = require('assert');
+var repl = require('repl');
+var stream = require('stream');
+var buildType = process.config.target_defaults.default_configuration;
+var buildPath = __dirname + '/build/' + buildType + '/binding';
+var cb_ran = false;
+
+process.on('exit', function() {
+ assert(cb_ran);
+ console.log('ok');
+});
+
+var lines = [
+ // This line shouldn't cause an assertion error.
+ 'require(\'' + buildPath + '\')' +
+ // Log output to double check callback ran.
+ '.method(function() { console.log(\'cb_ran\'); });',
+];
+
+var dInput = new stream.Readable();
+var dOutput = new stream.Writable();
+
+dInput._read = function _read(size) {
+ while (lines.length > 0 && this.push(lines.shift()));
+ if (lines.length === 0)
+ this.push(null);
+};
+
+dOutput._write = function _write(chunk, encoding, cb) {
+ if (chunk.toString().indexOf('cb_ran') === 0)
+ cb_ran = true;
+ cb();
+};
+
+var options = {
+ input: dInput,
+ output: dOutput,
+ terminal: false,
+ ignoreUndefined: true
+};
+
+// Run commands from fake REPL.
+var dummy = repl.start(options);