Skip to content

Commit 585d246

Browse files
committed
Fix infinite loop when skipping statements, see AssemblyScript#167
1 parent cc72d02 commit 585d246

File tree

7 files changed

+14
-14
lines changed

7 files changed

+14
-14
lines changed

cli/asc.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ const colorsUtil = require("./util/colors");
2121
const optionsUtil = require("./util/options");
2222
const EOL = process.platform === "win32" ? "\r\n" : "\n";
2323

24+
// Emscripten adds an `uncaughtException` listener to Binaryen that results in an additional
25+
// useless code fragment on top of an actual error. suppress this:
26+
if (process.removeAllListeners) process.removeAllListeners("uncaughtException");
27+
2428
// Use distribution files if present, otherwise run the sources directly
2529
var assemblyscript, isDev = false;
2630
(() => {
@@ -38,9 +42,6 @@ var assemblyscript, isDev = false;
3842
} catch (e) {
3943
// combine both errors that lead us here
4044
e.stack = e_ts.stack + "\n---\n" + e.stack;
41-
// Emscripten adds an `uncaughtException` listener to Binaryen that results in an additional
42-
// useless code fragment on top of the actual error. suppress this:
43-
if (process.removeAllListeners) process.removeAllListeners("uncaughtException");
4445
throw e;
4546
}
4647
}

dist/asc.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/asc.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assemblyscript.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assemblyscript.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tokenizer.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -546,13 +546,11 @@ export class Tokenizer extends DiagnosticEmitter {
546546
let c = text.charCodeAt(this.pos);
547547
switch (c) {
548548
case CharCode.CARRIAGERETURN: {
549-
if (
549+
if (!(
550550
++this.pos < this.end &&
551551
text.charCodeAt(this.pos) == CharCode.LINEFEED
552-
) {
553-
++this.pos;
554-
}
555-
break;
552+
)) break;
553+
// otherwise fall-through
556554
}
557555
case CharCode.LINEFEED:
558556
case CharCode.TAB:
@@ -960,8 +958,8 @@ export class Tokenizer extends DiagnosticEmitter {
960958
this.nextTokenPos = this.tokenPos;
961959
if (checkOnNewLine) {
962960
this.nextTokenOnNewLine = false;
963-
while (--this.tokenPos > posBefore) {
964-
if (isLineBreak(text.charCodeAt(this.tokenPos))) {
961+
for (let pos = posBefore, end = this.nextTokenPos; pos < end; ++pos) {
962+
if (isLineBreak(text.charCodeAt(pos))) {
965963
this.nextTokenOnNewLine = true;
966964
break;
967965
}

tests/parser/regexp.ts.fixture.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/(abc)\//;
33
var re = /(abc)\//ig;
44
var noRe = !/(abc)\//i;
5+
b / ig;
56
/(abc)\//iig;
67
/(abc)\//iX;
78
false && /abc/gX.test(someString) || true;

0 commit comments

Comments
 (0)