Skip to content

Commit

Permalink
Fix cyclic import/export segfault
Browse files Browse the repository at this point in the history
Before this commit it segfaulted, now it throws a SyntaxError.
That's still not correct behavior but better than segfaulting.
To be continued.

Refs: quickjs-ng#567
  • Loading branch information
bnoordhuis committed Oct 16, 2024
1 parent d9d6939 commit eec66d3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -26774,6 +26774,11 @@ static JSValue js_build_module_ns(JSContext *ctx, JSModuleDef *m)
case EXPORTED_NAME_NORMAL:
{
JSVarRef *var_ref = en->u.var_ref;
if (!var_ref) {
js_resolve_export_throw_error(ctx, JS_RESOLVE_RES_CIRCULAR,
m, en->export_name);
goto fail;
}
pr = add_property(ctx, p, en->export_name,
JS_PROP_ENUMERABLE | JS_PROP_WRITABLE |
JS_PROP_VARREF);
Expand Down
1 change: 1 addition & 0 deletions tests.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ verbose=yes
testdir=tests

[exclude]
tests/fixture_cyclic_import.js
tests/microbench.js
tests/test_worker_module.js
2 changes: 2 additions & 0 deletions tests/fixture_cyclic_import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * as a from "./test_cyclic_import.js"
export function f(x) { return 2 * a.g(x) }
12 changes: 12 additions & 0 deletions tests/test_cyclic_import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*---
negative:
phase: resolution
type: SyntaxError
---*/
// FIXME(bnoordhuis) shouldn't throw SyntaxError but that's still better
// than segfaulting, see https://github.com/quickjs-ng/quickjs/issues/567
import {assert} from "./assert.js"
import {f} from "./fixture_cyclic_import.js"
export {f}
export function g(x) { return x + 1 }
assert(f(1), 4)

0 comments on commit eec66d3

Please sign in to comment.