diff --git a/src/node_errors.cc b/src/node_errors.cc index 23ca0bc50f68c6..068b1a7c6d83fb 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -150,8 +150,7 @@ static std::string GetErrorSource(Isolate* isolate, : 0; int start = message->GetStartColumn(context).FromMaybe(0); int end = message->GetEndColumn(context).FromMaybe(0); - if (start >= script_start) { - CHECK_GE(end, start); + if (start >= script_start && end >= script_start) { start -= script_start; end -= script_start; } @@ -163,6 +162,7 @@ static std::string GetErrorSource(Isolate* isolate, if (start > end || start < 0 || + end < 0 || static_cast(end) > sourceline.size()) { return buf; } diff --git a/test/parallel/test-cli-eval-invalid-using.js b/test/parallel/test-cli-eval-invalid-using.js new file mode 100644 index 00000000000000..59a8cf8b6e588f --- /dev/null +++ b/test/parallel/test-cli-eval-invalid-using.js @@ -0,0 +1,23 @@ +'use strict'; + +require('../common'); +const assert = require('assert'); +const { spawnSyncAndAssert } = require('../common/child_process'); + +[ + '{using x=null, []=null;}', + '{using x=null, {}=null;}', + 'async function f() { { await using x=null, []=null; } }', + 'async function f() { { await using x=null, {}=null; } }', +].forEach((script) => { + spawnSyncAndAssert(process.execPath, ['--eval', script], { + status: 1, + signal: null, + stderr(output) { + assert.match(output, /SyntaxError/); + assert.doesNotMatch(output, /Assertion failed/); + assert.doesNotMatch(output, /Native stack trace/); + }, + stdout: '', + }); +});