@@ -6,7 +6,7 @@ const common = require('../common');
6
6
7
7
const assert = require ( 'assert' ) ;
8
8
9
- const { SourceTextModule, createContext } = require ( 'vm' ) ;
9
+ const { SourceTextModule, createContext, Module } = require ( 'vm' ) ;
10
10
11
11
async function createEmptyLinkedModule ( ) {
12
12
const m = new SourceTextModule ( '' ) ;
@@ -205,6 +205,17 @@ async function checkInvalidOptionForEvaluate() {
205
205
"Received type string ('a-string')" ,
206
206
code : 'ERR_INVALID_ARG_TYPE'
207
207
} ) ;
208
+
209
+ {
210
+ [ 'link' , 'evaluate' ] . forEach ( async ( method ) => {
211
+ await assert . rejects ( async ( ) => {
212
+ await Module . prototype [ method ] ( ) ;
213
+ } , {
214
+ code : 'ERR_VM_MODULE_NOT_MODULE' ,
215
+ message : / P r o v i d e d m o d u l e i s n o t a n i n s t a n c e o f M o d u l e /
216
+ } ) ;
217
+ } ) ;
218
+ }
208
219
}
209
220
210
221
function checkInvalidCachedData ( ) {
@@ -223,6 +234,19 @@ function checkInvalidCachedData() {
223
234
} ) ;
224
235
}
225
236
237
+ function checkGettersErrors ( ) {
238
+ const getters = [ 'identifier' , 'context' , 'namespace' , 'status' , 'error' ] ;
239
+ getters . forEach ( ( getter ) => {
240
+ assert . throws ( ( ) => {
241
+ // eslint-disable-next-line no-unused-expressions
242
+ Module . prototype [ getter ] ;
243
+ } , {
244
+ code : 'ERR_VM_MODULE_NOT_MODULE' ,
245
+ message : / P r o v i d e d m o d u l e i s n o t a n i n s t a n c e o f M o d u l e /
246
+ } ) ;
247
+ } ) ;
248
+ }
249
+
226
250
const finished = common . mustCall ( ) ;
227
251
228
252
( async function main ( ) {
@@ -232,5 +256,6 @@ const finished = common.mustCall();
232
256
await checkExecution ( ) ;
233
257
await checkInvalidOptionForEvaluate ( ) ;
234
258
checkInvalidCachedData ( ) ;
259
+ checkGettersErrors ( ) ;
235
260
finished ( ) ;
236
261
} ) ( ) . then ( common . mustCall ( ) ) ;
0 commit comments