diff options
author | punteek <prateek1@ucla.edu> | 2018-03-06 19:46:39 -0800 |
---|---|---|
committer | Gus Caplan <me@gus.host> | 2018-03-31 19:55:50 -0500 |
commit | 07ba9141e475ec63f6ef56b67ec5f98077cd3446 (patch) | |
tree | 99f36abde8cd6fd8b4a074fdfe8b1d8fe7fa6388 /test/parallel | |
parent | 28b622cb08602d77512fa3d659451cd317dfcc41 (diff) | |
download | android-node-v8-07ba9141e475ec63f6ef56b67ec5f98077cd3446.tar.gz android-node-v8-07ba9141e475ec63f6ef56b67ec5f98077cd3446.tar.bz2 android-node-v8-07ba9141e475ec63f6ef56b67ec5f98077cd3446.zip |
vm: add support for import.meta to Module
Fixes: https://github.com/nodejs/node/issues/18570
PR-URL: https://github.com/nodejs/node/pull/19277
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Diffstat (limited to 'test/parallel')
-rw-r--r-- | test/parallel/test-vm-module-import-meta.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/parallel/test-vm-module-import-meta.js b/test/parallel/test-vm-module-import-meta.js new file mode 100644 index 0000000000..835ef5b6eb --- /dev/null +++ b/test/parallel/test-vm-module-import-meta.js @@ -0,0 +1,45 @@ +'use strict'; + +// Flags: --experimental-vm-modules --harmony-import-meta + +const common = require('../common'); +const assert = require('assert'); +const { Module } = require('vm'); + +common.crashOnUnhandledRejection(); + +async function testBasic() { + const m = new Module('import.meta;', { + initializeImportMeta: common.mustCall((meta, module) => { + assert.strictEqual(module, m); + meta.prop = 42; + }) + }); + await m.link(common.mustNotCall()); + m.instantiate(); + const { result } = await m.evaluate(); + assert.strictEqual(typeof result, 'object'); + assert.strictEqual(Object.getPrototypeOf(result), null); + assert.strictEqual(result.prop, 42); + assert.deepStrictEqual(Reflect.ownKeys(result), ['prop']); +} + +async function testInvalid() { + for (const invalidValue of [ + null, {}, 0, Symbol.iterator, [], 'string', false + ]) { + common.expectsError(() => { + new Module('', { + initializeImportMeta: invalidValue + }); + }, { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError + }); + } +} + +(async () => { + await testBasic(); + await testInvalid(); +})(); |