diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-03-07 15:45:31 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-03-15 16:54:19 +0100 |
commit | b0de48e85441ff710aab240fdfa8a34adbbee976 (patch) | |
tree | 9b0d0ee1ca888a2d0db99d6350044d6095a84570 /test/wpt/test-url.js | |
parent | 7e2088f773d97e00e29cacdc20e1a36b80528be0 (diff) | |
download | android-node-v8-b0de48e85441ff710aab240fdfa8a34adbbee976.tar.gz android-node-v8-b0de48e85441ff710aab240fdfa8a34adbbee976.tar.bz2 android-node-v8-b0de48e85441ff710aab240fdfa8a34adbbee976.zip |
src,lib: make DOMException available in all Contexts
This allows using `DOMException` from Node.js code for any
`vm.Context`.
PR-URL: https://github.com/nodejs/node/pull/26497
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/wpt/test-url.js')
-rw-r--r-- | test/wpt/test-url.js | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/test/wpt/test-url.js b/test/wpt/test-url.js index 8734452940..4b909988dd 100644 --- a/test/wpt/test-url.js +++ b/test/wpt/test-url.js @@ -3,6 +3,7 @@ // Flags: --expose-internals require('../common'); +const assert = require('assert'); const { WPTRunner } = require('../common/wpt'); const runner = new WPTRunner('url'); @@ -10,9 +11,22 @@ const runner = new WPTRunner('url'); // Copy global descriptors from the global object runner.copyGlobalsFromObject(global, ['URL', 'URLSearchParams']); // Needed by urlsearchparams-constructor.any.js +let DOMException; runner.defineGlobal('DOMException', { get() { - return require('internal/domexception'); + // A 'hack' to get the DOMException constructor since we don't have it + // on the global object. + if (DOMException === undefined) { + const port = new (require('worker_threads').MessagePort)(); + const ab = new ArrayBuffer(1); + try { + port.postMessage(ab, [ab, ab]); + } catch (err) { + DOMException = err.constructor; + } + assert.strictEqual(DOMException.name, 'DOMException'); + } + return DOMException; } }); |