mirror of
https://github.com/bellard/quickjs.git
synced 2025-09-30 15:04:24 +03:00
fixed module cyclic imports (#329)
This commit is contained in:
49
tests/assert.js
Normal file
49
tests/assert.js
Normal file
@@ -0,0 +1,49 @@
|
||||
export function assert(actual, expected, message) {
|
||||
if (arguments.length === 1)
|
||||
expected = true;
|
||||
|
||||
if (typeof actual === typeof expected) {
|
||||
if (actual === expected) {
|
||||
if (actual !== 0 || (1 / actual) === (1 / expected))
|
||||
return;
|
||||
}
|
||||
if (typeof actual === 'number') {
|
||||
if (isNaN(actual) && isNaN(expected))
|
||||
return;
|
||||
}
|
||||
if (typeof actual === 'object') {
|
||||
if (actual !== null && expected !== null
|
||||
&& actual.constructor === expected.constructor
|
||||
&& actual.toString() === expected.toString())
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw Error("assertion failed: got |" + actual + "|" +
|
||||
", expected |" + expected + "|" +
|
||||
(message ? " (" + message + ")" : ""));
|
||||
}
|
||||
|
||||
export function assertThrows(err, func)
|
||||
{
|
||||
var ex;
|
||||
ex = false;
|
||||
try {
|
||||
func();
|
||||
} catch(e) {
|
||||
ex = true;
|
||||
assert(e instanceof err);
|
||||
}
|
||||
assert(ex, true, "exception expected");
|
||||
}
|
||||
|
||||
export function assertArrayEquals(a, b)
|
||||
{
|
||||
if (!Array.isArray(a) || !Array.isArray(b))
|
||||
return assert(false);
|
||||
|
||||
assert(a.length, b.length);
|
||||
|
||||
a.forEach((value, idx) => {
|
||||
assert(b[idx], value);
|
||||
});
|
||||
}
|
2
tests/fixture_cyclic_import.js
Normal file
2
tests/fixture_cyclic_import.js
Normal file
@@ -0,0 +1,2 @@
|
||||
import * as a from "./test_cyclic_import.js"
|
||||
export function f(x) { return 2 * a.g(x) }
|
12
tests/test_cyclic_import.js
Normal file
12
tests/test_cyclic_import.js
Normal file
@@ -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)
|
Reference in New Issue
Block a user