Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/node_errors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -163,6 +162,7 @@ static std::string GetErrorSource(Isolate* isolate,

if (start > end ||
start < 0 ||
end < 0 ||
static_cast<size_t>(end) > sourceline.size()) {
return buf;
}
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-cli-eval-invalid-using.js
Original file line number Diff line number Diff line change
@@ -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; } }',
Comment on lines +10 to +11
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'async function f() { { await using x=null, []=null; } }',
'async function f() { { await using x=null, {}=null; } }',
'async function f() { await using x=null, []=null; }',
'async function f() { await using x=null, {}=null; }',

or even

Suggested change
'async function f() { { await using x=null, []=null; } }',
'async function f() { { await using x=null, {}=null; } }',
'{ await using x=null, []=null; }',
'{ 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: '',
});
});
Loading