Skip to content

Commit 36227a5

Browse files
authored
Fix cyclic import/export segfault (#568)
Before this commit it segfaulted, now it throws a SyntaxError. That's still not correct behavior but better than segfaulting. To be continued. Includes a small run-test262 fix to handle Windows line endings. Refs: #567
1 parent d9d6939 commit 36227a5

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

quickjs.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26774,6 +26774,11 @@ static JSValue js_build_module_ns(JSContext *ctx, JSModuleDef *m)
2677426774
case EXPORTED_NAME_NORMAL:
2677526775
{
2677626776
JSVarRef *var_ref = en->u.var_ref;
26777+
if (!var_ref) {
26778+
js_resolve_export_throw_error(ctx, JS_RESOLVE_RES_CIRCULAR,
26779+
m, en->export_name);
26780+
goto fail;
26781+
}
2677726782
pr = add_property(ctx, p, en->export_name,
2677826783
JS_PROP_ENUMERABLE | JS_PROP_WRITABLE |
2677926784
JS_PROP_VARREF);

run-test262.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1836,7 +1836,7 @@ int run_test(const char *filename, int *msec)
18361836
if (q) {
18371837
while (isspace((unsigned char)*q))
18381838
q++;
1839-
error_type = strdup_len(q, strcspn(q, " \n"));
1839+
error_type = strdup_len(q, strcspn(q, " \r\n"));
18401840
}
18411841
is_negative = TRUE;
18421842
}

tests.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ verbose=yes
44
testdir=tests
55

66
[exclude]
7+
tests/fixture_cyclic_import.js
78
tests/microbench.js
89
tests/test_worker_module.js

tests/fixture_cyclic_import.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import * as a from "./test_cyclic_import.js"
2+
export function f(x) { return 2 * a.g(x) }

tests/test_cyclic_import.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*---
2+
negative:
3+
phase: resolution
4+
type: SyntaxError
5+
---*/
6+
// FIXME(bnoordhuis) shouldn't throw SyntaxError but that's still better
7+
// than segfaulting, see https://github.com/quickjs-ng/quickjs/issues/567
8+
import {assert} from "./assert.js"
9+
import {f} from "./fixture_cyclic_import.js"
10+
export {f}
11+
export function g(x) { return x + 1 }
12+
assert(f(1), 4)

0 commit comments

Comments
 (0)