Skip to content

Commit

Permalink
Latest review
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Nov 22, 2024
1 parent 2e0982e commit dd44fcb
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ assert.sameValue(Reflect.setPrototypeOf(ns, {}), false, "Deferred namespaces' pr
assert.sameValue(Reflect.setPrototypeOf(ns, null), true, "Deferred namespaces' prototype can be 'set' to null");

assert.throws(TypeError, () => Reflect.apply(ns, null, []), "Deferred namespaces are not callable");
assert.throws(TypeError, () => Reflect.construct(ns, null, []), "Deferred namespaces are not constructable");
assert.throws(TypeError, () => Reflect.construct(ns, [], ns), "Deferred namespaces are not constructable");

assert.compareArray(
Reflect.ownKeys(ns),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ flags: [module, async]
features: [import-defer, top-level-await]
---*/

/*
`./dep_FIXTURE.js` is _not_ deferred, because it contains top-level await. So what is happening in this test is that:
- the deferred module is not actually deferred, so `dep_FIXTURE.js` starts executing and goes in its `evaluating` state
- it has access to a deferred namespace of itself
- once it reaches the `await`, the state changes to `evaluating-async`
- the test tries then to access a property from the deferred namespace while it's `evaluating-async` (which is what this test it testing). It should throw.
- `dep_FIXTURE.js` is done, and becomes `evaluated`
- `main.js` starts evaluating, and the error is already there
- `ns.foo` now works, because `ns` is `evaluated` and not `evaluating-async`
*/

import defer * as ns from "./dep_FIXTURE.js";

assert(globalThis["error on ns.foo"] instanceof TypeError, "ns.foo while evaluating throws a TypeError");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ info: |
flags: [module, async]
features: [import-defer]
includes: [asyncHelpers.js, deepEqual.js]
includes: [asyncHelpers.js]
---*/

asyncTest(async () => {
let err1;
await import("./throws_FIXTURE.js").catch((e) => { err1 = e });
assert.deepEqual(err1, { someError: "the error from throws_FIXTURE" });
assert.sameValue(err1.someError, "the error from throws_FIXTURE");

const { ns } = await import("./import-defer-throws_FIXTURE.js");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ info: |
flags: [module, async]
features: [import-defer]
includes: [asyncHelpers.js, deepEqual.js]
includes: [asyncHelpers.js]
---*/

import defer * as ns from "./throws_FIXTURE.js";

asyncTest(async () => {
let err1;
await import("./throws_FIXTURE.js").catch((e) => { err1 = e });
assert.deepEqual(err1, { someError: "the error from throws_FIXTURE" });
assert.sameValue(err1.someError, "the error from throws_FIXTURE");

let err2;
try { ns.foo } catch (e) { err2 = e };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ info: |
flags: [module]
features: [import-defer]
includes: [deepEqual.js]
---*/

import defer * as ns from "./throws_FIXTURE.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ features: [import-defer]
---*/

import defer from "./dep_FIXTURE.js";

asserts.sameValue(defer, 1, "`defer` is the default export binding");

0 comments on commit dd44fcb

Please sign in to comment.