summaryrefslogtreecommitdiff
path: root/test/addons
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2016-10-21 11:57:20 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2016-10-25 13:18:01 +0200
commit921d2b080e810dff89c78db7d7f4c2e9e92f57ec (patch)
tree814a1c738b9d5da7fa45f1b7fc4ebcb24905cf72 /test/addons
parente4290dec2df252cbaaf79098784730924153b182 (diff)
downloadandroid-node-v8-921d2b080e810dff89c78db7d7f4c2e9e92f57ec.tar.gz
android-node-v8-921d2b080e810dff89c78db7d7f4c2e9e92f57ec.tar.bz2
android-node-v8-921d2b080e810dff89c78db7d7f4c2e9e92f57ec.zip
src: make cross-context MakeCallback() calls work
Check that invoking a callback on a receiver from a different context works. It ran afoul of an `env->context() == isolate->GetCurrentContext()` assertion so retrieve the environment from the callback context and the context to enter from the environment's context() method. We could also have retrieved the environment from the receiver's context and that would have made little practical difference. It just seemed more correct to get it from the callback context because that is the actual execution context. PR-URL: https://github.com/nodejs/node/pull/9221 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'test/addons')
-rw-r--r--test/addons/make-callback/test.js4
1 files changed, 4 insertions, 0 deletions
diff --git a/test/addons/make-callback/test.js b/test/addons/make-callback/test.js
index 43ad014c4a..b67d1146a6 100644
--- a/test/addons/make-callback/test.js
+++ b/test/addons/make-callback/test.js
@@ -36,6 +36,10 @@ const recv = {
assert.strictEqual(42, makeCallback(recv, 'one'));
assert.strictEqual(42, makeCallback(recv, 'two', 1337));
+// Check that callbacks on a receiver from a different context works.
+const foreignObject = vm.runInNewContext('({ fortytwo() { return 42; } })');
+assert.strictEqual(42, makeCallback(foreignObject, 'fortytwo'));
+
// Check that the callback is made in the context of the receiver.
const target = vm.runInNewContext(`
(function($Object) {