diff --git a/lib/assert.js b/lib/assert.js index da92c02f640e46..47c0e3c1402bdd 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -153,6 +153,10 @@ function getBuffer(fd, assertLine) { function getErrMessage(call) { const filename = call.getFileName(); + if (!filename) { + return; + } + const line = call.getLineNumber() - 1; const column = call.getColumnNumber() - 1; const identifier = `${filename}${line}${column}`; diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index eb084e9b01cb2b..661ba9d3cfa0df 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -783,6 +783,16 @@ common.expectsError( } ); +// works in eval +common.expectsError( + () => new Function('assert', 'assert(1 === 2);')(assert), + { + code: 'ERR_ASSERTION', + type: assert.AssertionError, + message: 'false == true' + } +); + // Do not try to check Node.js modules. { const e = new EventEmitter();