Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
util: support inspecting namespaces of unevaluated modules
PR-URL: #20782 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
Showing
with
64 additions
and 11 deletions.
- +42 −11 lib/util.js
- +22 −0 test/parallel/test-util-inspect-namespace.js
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
// Flags: --experimental-vm-modules | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
common.crashOnUnhandledRejection(); | ||
|
||
const { Module } = require('vm'); | ||
const { inspect } = require('util'); | ||
|
||
(async () => { | ||
const m = new Module('export const a = 1; export var b = 2'); | ||
await m.link(() => 0); | ||
m.instantiate(); | ||
assert.strictEqual( | ||
inspect(m.namespace), | ||
'[Module] { a: <uninitialized>, b: undefined }'); | ||
await m.evaluate(); | ||
assert.strictEqual(inspect(m.namespace), '[Module] { a: 1, b: 2 }'); | ||
})(); |