diff --git a/lib/assert.js b/lib/assert.js index 1471ba91c12a52..18e1f6b2a4aef3 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -154,6 +154,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 b731b9a73ea207..64f86c52eefad2 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -742,6 +742,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();