@@ -6,7 +6,7 @@ const common = require('../common');
66
77const assert = require ( 'assert' ) ;
88
9- const { SourceTextModule, createContext } = require ( 'vm' ) ;
9+ const { SourceTextModule, createContext, Module } = require ( 'vm' ) ;
1010
1111async function createEmptyLinkedModule ( ) {
1212 const m = new SourceTextModule ( '' ) ;
@@ -205,6 +205,17 @@ async function checkInvalidOptionForEvaluate() {
205205 "Received type string ('a-string')" ,
206206 code : 'ERR_INVALID_ARG_TYPE'
207207 } ) ;
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+ }
208219}
209220
210221function checkInvalidCachedData ( ) {
@@ -223,6 +234,19 @@ function checkInvalidCachedData() {
223234 } ) ;
224235}
225236
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+
226250const finished = common . mustCall ( ) ;
227251
228252( async function main ( ) {
@@ -232,5 +256,6 @@ const finished = common.mustCall();
232256 await checkExecution ( ) ;
233257 await checkInvalidOptionForEvaluate ( ) ;
234258 checkInvalidCachedData ( ) ;
259+ checkGettersErrors ( ) ;
235260 finished ( ) ;
236261} ) ( ) . then ( common . mustCall ( ) ) ;
0 commit comments