@@ -168,6 +168,46 @@ metatests.test('Syntax error', async (test) => {
168168 test . end ( ) ;
169169} ) ;
170170
171+ metatests . test ( 'Reference error' , async ( test ) => {
172+ const filePath = path . join ( examples , 'referenceError.js' ) ;
173+ try {
174+ const script = await metavm . readScript ( filePath ) ;
175+ await script . exports ( ) ;
176+ test . fail ( ) ;
177+ } catch ( err ) {
178+ test . strictSame ( err . constructor . name , 'ReferenceError' ) ;
179+ }
180+ test . end ( ) ;
181+ } ) ;
182+
183+ metatests . test ( 'Line number' , async ( test ) => {
184+ {
185+ const filePath = path . join ( examples , 'referenceError.js' ) ;
186+ try {
187+ const script = await metavm . readScript ( filePath ) ;
188+ await script . exports ( ) ;
189+ test . fail ( ) ;
190+ } catch ( err ) {
191+ const [ , firstLine ] = err . stack . split ( '\n' ) ;
192+ const [ , lineNumber ] = firstLine . split ( ':' ) ;
193+ test . strictSame ( parseInt ( lineNumber , 10 ) , 2 ) ;
194+ }
195+ }
196+ {
197+ const filePath = path . join ( examples , 'useStrict.cjs' ) ;
198+ try {
199+ const script = await metavm . readScript ( filePath ) ;
200+ await script . exports ( ) ;
201+ test . fail ( ) ;
202+ } catch ( err ) {
203+ const [ , firstLine ] = err . stack . split ( '\n' ) ;
204+ const [ , lineNumber ] = firstLine . split ( ':' ) ;
205+ test . strictSame ( parseInt ( lineNumber , 10 ) , 4 ) ;
206+ }
207+ }
208+ test . end ( ) ;
209+ } ) ;
210+
171211metatests . test ( 'Create default context' , async ( test ) => {
172212 const context = metavm . createContext ( ) ;
173213 test . strictSame ( Object . keys ( context ) , [ ] ) ;
0 commit comments