From fda523def324d31cc4dc54b4b16940e93ce4b615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Fri, 25 Oct 2024 16:21:57 +0200 Subject: [PATCH 01/13] Add partial tests for `import defer` - syntax - Deferred namespace objects - Behavior of synchronous deferred modules - Errors for synchronous cases I will open another PR (or push another commit here) for tests about async modules, since I still have to finish polishing it up. There are a few details of the proposal that are still in flux because of some bugs, so this PR does not include tests for them: - `Symbol.toStringTag` of deferred namespace objects - `test/language/import/import-defer/evaluation-sync/evaluation-*` for the other object operations - `import.defer`, which currently doesn't actually defer due to a problem with `.then` --- features.txt | 4 ++ .../dep-defer-ns_FIXTURE.js | 6 +++ .../deferred-namespace-object/dep_FIXTURE.js | 5 ++ .../deferred-namespace-object/identity.js | 42 +++++++++++++++ .../object-properties.js | 51 +++++++++++++++++++ .../dep-1_FIXTURE.js | 8 +++ .../dep-2_FIXTURE.js | 5 ++ .../dep-3_FIXTURE.js | 4 ++ .../get-other-while-dep-evaluating/main.js | 37 ++++++++++++++ .../get-other-while-evaluating/dep_FIXTURE.js | 6 +++ .../errors/get-other-while-evaluating/main.js | 37 ++++++++++++++ .../dep_FIXTURE.js | 6 +++ .../get-self-while-defer-evaluating/main.js | 39 ++++++++++++++ .../errors/get-self-while-evaluating.js | 39 ++++++++++++++ .../defer-import-after-evaluation.js | 34 +++++++++++++ .../import-defer-throws_FIXTURE.js | 5 ++ ...ird-party-evaluation-after-defer-import.js | 34 +++++++++++++ .../errors/module-throws/throws_FIXTURE.js | 4 ++ .../module-throws/trigger-evaluation.js | 33 ++++++++++++ .../import-defer-of-syntax-error-fails.js | 19 +++++++ .../resolution-error_FIXTURE.js | 4 ++ .../import-defer-of-syntax-error-fails.js | 19 +++++++ .../syntax-error/syntax-error_FIXTURE.js | 4 ++ .../evaluation-sync/dep-1.1_FIXTURE.js | 4 ++ .../evaluation-sync/dep-1.2_FIXTURE.js | 4 ++ .../evaluation-sync/dep-1_FIXTURE.js | 9 ++++ .../evaluation-sync/dep-2_FIXTURE.js | 4 ++ .../evaluation-ignore-get-symbol.js | 27 ++++++++++ .../evaluation-ignore-getPrototypeOf.js | 23 +++++++++ .../evaluation-ignore-isExtensible.js | 23 +++++++++ .../evaluation-ignore-preventExtensions.js | 23 +++++++++ .../evaluation-sync/evaluation-ignore-set.js | 24 +++++++++ .../evaluation-ignore-setPrototypeOf.js | 24 +++++++++ .../evaluation-trigger-get-string.js | 26 ++++++++++ .../import-defer-does-not-evaluate.js | 45 ++++++++++++++++ .../module-imported-defer-and-eager.js | 49 ++++++++++++++++++ .../evaluation-sync/setup_FIXTURE.js | 4 ++ .../import/import-defer/syntax/dep_FIXTURE.js | 4 ++ .../import-defer/syntax/import-attributes.js | 20 ++++++++ .../invalid-default-and-defer-namespace.js | 31 +++++++++++ .../invalid-defer-as-with-no-asterisk.js | 31 +++++++++++ ...nvalid-defer-default-and-namespace copy.js | 31 +++++++++++ .../syntax/invalid-defer-default.js | 31 +++++++++++ .../syntax/invalid-defer-named.js | 31 +++++++++++ .../syntax/invalid-export-defer-namespace.js | 30 +++++++++++ .../valid-default-binding-named-defer.js | 27 ++++++++++ .../syntax/valid-defer-namespace.js | 20 ++++++++ 47 files changed, 990 insertions(+) create mode 100644 test/language/import/import-defer/deferred-namespace-object/dep-defer-ns_FIXTURE.js create mode 100644 test/language/import/import-defer/deferred-namespace-object/dep_FIXTURE.js create mode 100644 test/language/import/import-defer/deferred-namespace-object/identity.js create mode 100644 test/language/import/import-defer/deferred-namespace-object/object-properties.js create mode 100644 test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-1_FIXTURE.js create mode 100644 test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-2_FIXTURE.js create mode 100644 test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-3_FIXTURE.js create mode 100644 test/language/import/import-defer/errors/get-other-while-dep-evaluating/main.js create mode 100644 test/language/import/import-defer/errors/get-other-while-evaluating/dep_FIXTURE.js create mode 100644 test/language/import/import-defer/errors/get-other-while-evaluating/main.js create mode 100644 test/language/import/import-defer/errors/get-self-while-defer-evaluating/dep_FIXTURE.js create mode 100644 test/language/import/import-defer/errors/get-self-while-defer-evaluating/main.js create mode 100644 test/language/import/import-defer/errors/get-self-while-evaluating.js create mode 100644 test/language/import/import-defer/errors/module-throws/defer-import-after-evaluation.js create mode 100644 test/language/import/import-defer/errors/module-throws/import-defer-throws_FIXTURE.js create mode 100644 test/language/import/import-defer/errors/module-throws/third-party-evaluation-after-defer-import.js create mode 100644 test/language/import/import-defer/errors/module-throws/throws_FIXTURE.js create mode 100644 test/language/import/import-defer/errors/module-throws/trigger-evaluation.js create mode 100644 test/language/import/import-defer/errors/resolution-error/import-defer-of-syntax-error-fails.js create mode 100644 test/language/import/import-defer/errors/resolution-error/resolution-error_FIXTURE.js create mode 100644 test/language/import/import-defer/errors/syntax-error/import-defer-of-syntax-error-fails.js create mode 100644 test/language/import/import-defer/errors/syntax-error/syntax-error_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-sync/dep-1.1_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-sync/dep-1.2_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-sync/dep-1_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-sync/dep-2_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-sync/evaluation-ignore-get-symbol.js create mode 100644 test/language/import/import-defer/evaluation-sync/evaluation-ignore-getPrototypeOf.js create mode 100644 test/language/import/import-defer/evaluation-sync/evaluation-ignore-isExtensible.js create mode 100644 test/language/import/import-defer/evaluation-sync/evaluation-ignore-preventExtensions.js create mode 100644 test/language/import/import-defer/evaluation-sync/evaluation-ignore-set.js create mode 100644 test/language/import/import-defer/evaluation-sync/evaluation-ignore-setPrototypeOf.js create mode 100644 test/language/import/import-defer/evaluation-sync/evaluation-trigger-get-string.js create mode 100644 test/language/import/import-defer/evaluation-sync/import-defer-does-not-evaluate.js create mode 100644 test/language/import/import-defer/evaluation-sync/module-imported-defer-and-eager.js create mode 100644 test/language/import/import-defer/evaluation-sync/setup_FIXTURE.js create mode 100644 test/language/import/import-defer/syntax/dep_FIXTURE.js create mode 100644 test/language/import/import-defer/syntax/import-attributes.js create mode 100644 test/language/import/import-defer/syntax/invalid-default-and-defer-namespace.js create mode 100644 test/language/import/import-defer/syntax/invalid-defer-as-with-no-asterisk.js create mode 100644 test/language/import/import-defer/syntax/invalid-defer-default-and-namespace copy.js create mode 100644 test/language/import/import-defer/syntax/invalid-defer-default.js create mode 100644 test/language/import/import-defer/syntax/invalid-defer-named.js create mode 100644 test/language/import/import-defer/syntax/invalid-export-defer-namespace.js create mode 100644 test/language/import/import-defer/syntax/valid-default-binding-named-defer.js create mode 100644 test/language/import/import-defer/syntax/valid-defer-namespace.js diff --git a/features.txt b/features.txt index dc88a06b8d9..ebc838fb832 100644 --- a/features.txt +++ b/features.txt @@ -84,6 +84,10 @@ Atomics.pause # https://github.com/tc39/proposal-is-error Error.isError +# Deferred import evaluation +# https://tc39.es/proposal-defer-import-eval +import-defer + ## Standard language features # # Language features that have been included in a published version of the diff --git a/test/language/import/import-defer/deferred-namespace-object/dep-defer-ns_FIXTURE.js b/test/language/import/import-defer/deferred-namespace-object/dep-defer-ns_FIXTURE.js new file mode 100644 index 00000000000..fceef1b0553 --- /dev/null +++ b/test/language/import/import-defer/deferred-namespace-object/dep-defer-ns_FIXTURE.js @@ -0,0 +1,6 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import defer * as depDeferredNamespace from "./dep.js"; + +export { depDeferredNamespace }; diff --git a/test/language/import/import-defer/deferred-namespace-object/dep_FIXTURE.js b/test/language/import/import-defer/deferred-namespace-object/dep_FIXTURE.js new file mode 100644 index 00000000000..417ffa70bc5 --- /dev/null +++ b/test/language/import/import-defer/deferred-namespace-object/dep_FIXTURE.js @@ -0,0 +1,5 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export const foo = 1; +export const bar = 2; diff --git a/test/language/import/import-defer/deferred-namespace-object/identity.js b/test/language/import/import-defer/deferred-namespace-object/identity.js new file mode 100644 index 00000000000..f8d459ebc08 --- /dev/null +++ b/test/language/import/import-defer/deferred-namespace-object/identity.js @@ -0,0 +1,42 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-getmodulenamespace +description: > + Deferred namespace objects are created and cached appropriately +info: | + GetModuleNamespace ( _module_, _phase_ ) + 1. ... + 1. If _phase_ is ~defer~, let _namespace_ be _module_.[[DeferredNamespace]], otherwise let _namespace_ be _module_.[[Namespace]]. + 1. If _namespace_ is ~empty~, then + 1. ... + 1. Set _namespace_ to ModuleNamespaceCreate(_module_, _unambiguousNames_, _phase_). + 1. Return _namespace_. + + ModuleNamespaceCreate ( _module_, _exports_, _phase_ ) + 1. ... + 1. Let _M_ be MakeBasicObject(_internalSlotsList_). + 1. ... + 1. If _phase_ is ~defer~, then + 1. Set _module_.[[DeferredNamespace]] to _M_. + 1. ... + 1. Else, + 1. Set _module_.[[Namespace]] to _M_. + 1. ... + 1. Return _M_. + +features: [import-defer] +---*/ + +import * as nsEager from "./dep_FIXTURE.js"; + +import defer * as nsDeferred1 from "./dep_FIXTURE.js"; +import defer * as nsDeferred2 from "./dep_FIXTURE.js"; +import { depDeferredNamespace as nsDeferred3 } from "./dep-defer-ns_FIXTURE.js"; +const nsDeferred4 = await import.defer("./dep_FIXTURE.js"); + +assert(nsDeferred1 === nsDeferred2, "Deferred import of the same module twice gives the same object"); +assert(nsDeferred1 === nsDeferred3, "Deferred import of the same module twice from different files gives the same object"); +assert(nsDeferred1 === nsDeferred4, "Static and dynamic deferred import of the same module gives the same object"); +assert(nsDeferred1 !== nsEager, "Deferred namespaces are distinct from eager namespaces"); diff --git a/test/language/import/import-defer/deferred-namespace-object/object-properties.js b/test/language/import/import-defer/deferred-namespace-object/object-properties.js new file mode 100644 index 00000000000..fd83b62d6a9 --- /dev/null +++ b/test/language/import/import-defer/deferred-namespace-object/object-properties.js @@ -0,0 +1,51 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-modulenamespacecreate +description: > + `defer` is a valid name for default imports +info: | + ModuleNamespaceCreate ( _module_, _exports_, _phase_ ) + 1. Let _internalSlotsList_ be the internal slots listed in . + 1. Let _M_ be MakeBasicObject(_internalSlotsList_). + 1. Set _M_'s essential internal methods to the definitions specified in . + 1. ... + + [[GetPrototypeOf]] ( ) + 1. Return null. + + [[IsExtensible]] ( ) + 1. Return false. + +features: [import-defer] +includes: [propertyHelper.js] +---*/ + +import defer * as ns from "./dep_FIXTURE.js"; + +assert(typeof ns === "object", "Deferred namespaces are objects"); + +assert(Reflect.isExtensible(ns) === false, "Deferred namespaces are not extensible"); +assert(Reflect.preventExtensions(ns) === true, "Deferred namespaces can made non-extensible"); + +assert(Reflect.getPrototypeOf(ns) === null, "Deferred namespaces have a null prototype"); +asserts(Reflect.setPrototypeOf(ns, {}) === false, "Deferred namespaces' prototype cannot be changed"); +asserts(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.deepEqual( + Reflect.ownKeys(ns), + ["bar", "foo", Symbol.toStringTag], + "Deferred namespaces' keys are the exports sorted alphabetically, followed by @@toStringTag" +); + +verifyProperty(ns, "foo", { + value: 1, + writable: true, + enumerable: true, + configurable: false, +}); +assert(Reflect.getOwnPropertyDescriptor(ns, "non-existent") === undefined, "No descriptors for non-exports"); diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-1_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-1_FIXTURE.js new file mode 100644 index 00000000000..b3c639aeffb --- /dev/null +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-1_FIXTURE.js @@ -0,0 +1,8 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import defer * as dep2 from "./dep-2_FIXTURE.js"; + +globalThis.dep3evaluated = false; +assert.throws(TypeError, () => dep2.foo); +assert(globalThis.dep3evaluated === false, "the 'evaluable' dependencies of dep-2 are not evaluated"); diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-2_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-2_FIXTURE.js new file mode 100644 index 00000000000..dde1545135d --- /dev/null +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-2_FIXTURE.js @@ -0,0 +1,5 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import "./dep-3_FIXTURE.js"; +import "./main.js"; diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-3_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-3_FIXTURE.js new file mode 100644 index 00000000000..b8c2449eab9 --- /dev/null +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-3_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +globalThis.dep3evaluated = true; diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating/main.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating/main.js new file mode 100644 index 00000000000..b058095d7d3 --- /dev/null +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating/main.js @@ -0,0 +1,37 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-module-namespace-exotic-objects-get-p-receiver-EnsureDeferredNamespaceEvaluation +description: > + Modules cannot try to trigger their own evaluation +info: | + 10.4.6.8 [[Get]] ( _P_, _Receiver_ ) + 1. ... + 1. If _O_.[[Deferred]] is **true**, perform ? EnsureDeferredNamespaceEvaluation(_O_). + 1. ... + + EnsureDeferredNamespaceEvaluation ( _O_ ) + 1. Assert: _O_.[[Deferred]] is *false*. + 1. Let _m_ be _O_.[[Module]]. + 1. If _m_ is a Cyclic Module Record, _m_.[[Status]] is not ~evaluated~, and ReadyForSyncExecution(_m_) is *false*, throw a *TypeError* exception. + 1. ... + + ReadyForSyncExecution( _module_, _seen_ ) + 1. If _seen_ is not provided, let _seen_ be a new empty List. + 1. If _seen_ contains _module_, return *true*. + 1. Append _module_ to _seen_. + 1. If _module_.[[Status]] is ~evaluated~, return *true*. + 1. If _module_.[[Status]] is ~evaluating~ or ~evaluating-async~, return *false*. + 1. Assert: _module_.[[Status]] is ~linked~. + 1. If _module_.[[HasTLA]] is *true*, return *false*. + 1. For each ModuleRequest Record _required_ of _module_.[[RequestedModules]], do + 1. Let _requiredModule_ be GetImportedModule(_module_, _required_.[[Specifier]]). + 1. If ReadyForSyncExecution(_requiredModule_, _seen_) is *false*, then + 1. Return *false*. + 1. Return *true*. + +features: [import-defer] +---*/ + +import "./dep-1_FIXTURE.js"; diff --git a/test/language/import/import-defer/errors/get-other-while-evaluating/dep_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-evaluating/dep_FIXTURE.js new file mode 100644 index 00000000000..3a232403df0 --- /dev/null +++ b/test/language/import/import-defer/errors/get-other-while-evaluating/dep_FIXTURE.js @@ -0,0 +1,6 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import defer * as main from "./main.js"; + +assert.throws(TypeError, () => main.foo); diff --git a/test/language/import/import-defer/errors/get-other-while-evaluating/main.js b/test/language/import/import-defer/errors/get-other-while-evaluating/main.js new file mode 100644 index 00000000000..250f23b2617 --- /dev/null +++ b/test/language/import/import-defer/errors/get-other-while-evaluating/main.js @@ -0,0 +1,37 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-module-namespace-exotic-objects-get-p-receiver-EnsureDeferredNamespaceEvaluation +description: > + Modules cannot try to trigger their own evaluation +info: | + 10.4.6.8 [[Get]] ( _P_, _Receiver_ ) + 1. ... + 1. If _O_.[[Deferred]] is **true**, perform ? EnsureDeferredNamespaceEvaluation(_O_). + 1. ... + + EnsureDeferredNamespaceEvaluation ( _O_ ) + 1. Assert: _O_.[[Deferred]] is *false*. + 1. Let _m_ be _O_.[[Module]]. + 1. If _m_ is a Cyclic Module Record, _m_.[[Status]] is not ~evaluated~, and ReadyForSyncExecution(_m_) is *false*, throw a *TypeError* exception. + 1. ... + + ReadyForSyncExecution( _module_, _seen_ ) + 1. If _seen_ is not provided, let _seen_ be a new empty List. + 1. If _seen_ contains _module_, return *true*. + 1. Append _module_ to _seen_. + 1. If _module_.[[Status]] is ~evaluated~, return *true*. + 1. If _module_.[[Status]] is ~evaluating~ or ~evaluating-async~, return *false*. + 1. Assert: _module_.[[Status]] is ~linked~. + 1. If _module_.[[HasTLA]] is *true*, return *false*. + 1. For each ModuleRequest Record _required_ of _module_.[[RequestedModules]], do + 1. Let _requiredModule_ be GetImportedModule(_module_, _required_.[[Specifier]]). + 1. If ReadyForSyncExecution(_requiredModule_, _seen_) is *false*, then + 1. Return *false*. + 1. Return *true*. + +features: [import-defer] +---*/ + +import "./dep_FIXTURE.js"; diff --git a/test/language/import/import-defer/errors/get-self-while-defer-evaluating/dep_FIXTURE.js b/test/language/import/import-defer/errors/get-self-while-defer-evaluating/dep_FIXTURE.js new file mode 100644 index 00000000000..69eab4f45f7 --- /dev/null +++ b/test/language/import/import-defer/errors/get-self-while-defer-evaluating/dep_FIXTURE.js @@ -0,0 +1,6 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import defer * as ns from "./dep_FIXTURE.js"; + +assert.throws(TypeError, () => ns.foo); diff --git a/test/language/import/import-defer/errors/get-self-while-defer-evaluating/main.js b/test/language/import/import-defer/errors/get-self-while-defer-evaluating/main.js new file mode 100644 index 00000000000..9828b6783cc --- /dev/null +++ b/test/language/import/import-defer/errors/get-self-while-defer-evaluating/main.js @@ -0,0 +1,39 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-module-namespace-exotic-objects-get-p-receiver-EnsureDeferredNamespaceEvaluation +description: > + Modules cannot try to trigger their own evaluation +info: | + 10.4.6.8 [[Get]] ( _P_, _Receiver_ ) + 1. ... + 1. If _O_.[[Deferred]] is **true**, perform ? EnsureDeferredNamespaceEvaluation(_O_). + 1. ... + + EnsureDeferredNamespaceEvaluation ( _O_ ) + 1. Assert: _O_.[[Deferred]] is *false*. + 1. Let _m_ be _O_.[[Module]]. + 1. If _m_ is a Cyclic Module Record, _m_.[[Status]] is not ~evaluated~, and ReadyForSyncExecution(_m_) is *false*, throw a *TypeError* exception. + 1. ... + + ReadyForSyncExecution( _module_, _seen_ ) + 1. If _seen_ is not provided, let _seen_ be a new empty List. + 1. If _seen_ contains _module_, return *true*. + 1. Append _module_ to _seen_. + 1. If _module_.[[Status]] is ~evaluated~, return *true*. + 1. If _module_.[[Status]] is ~evaluating~ or ~evaluating-async~, return *false*. + 1. Assert: _module_.[[Status]] is ~linked~. + 1. If _module_.[[HasTLA]] is *true*, return *false*. + 1. For each ModuleRequest Record _required_ of _module_.[[RequestedModules]], do + 1. Let _requiredModule_ be GetImportedModule(_module_, _required_.[[Specifier]]). + 1. If ReadyForSyncExecution(_requiredModule_, _seen_) is *false*, then + 1. Return *false*. + 1. Return *true*. + +features: [import-defer] +---*/ + +import defer * as ns from "./dep_FIXTURE.js"; + +ns.foo; diff --git a/test/language/import/import-defer/errors/get-self-while-evaluating.js b/test/language/import/import-defer/errors/get-self-while-evaluating.js new file mode 100644 index 00000000000..4010214eae3 --- /dev/null +++ b/test/language/import/import-defer/errors/get-self-while-evaluating.js @@ -0,0 +1,39 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-module-namespace-exotic-objects-get-p-receiver-EnsureDeferredNamespaceEvaluation +description: > + Modules cannot try to trigger their own evaluation +info: | + 10.4.6.8 [[Get]] ( _P_, _Receiver_ ) + 1. ... + 1. If _O_.[[Deferred]] is **true**, perform ? EnsureDeferredNamespaceEvaluation(_O_). + 1. ... + + EnsureDeferredNamespaceEvaluation ( _O_ ) + 1. Assert: _O_.[[Deferred]] is *false*. + 1. Let _m_ be _O_.[[Module]]. + 1. If _m_ is a Cyclic Module Record, _m_.[[Status]] is not ~evaluated~, and ReadyForSyncExecution(_m_) is *false*, throw a *TypeError* exception. + 1. ... + + ReadyForSyncExecution( _module_, _seen_ ) + 1. If _seen_ is not provided, let _seen_ be a new empty List. + 1. If _seen_ contains _module_, return *true*. + 1. Append _module_ to _seen_. + 1. If _module_.[[Status]] is ~evaluated~, return *true*. + 1. If _module_.[[Status]] is ~evaluating~ or ~evaluating-async~, return *false*. + 1. Assert: _module_.[[Status]] is ~linked~. + 1. If _module_.[[HasTLA]] is *true*, return *false*. + 1. For each ModuleRequest Record _required_ of _module_.[[RequestedModules]], do + 1. Let _requiredModule_ be GetImportedModule(_module_, _required_.[[Specifier]]). + 1. If ReadyForSyncExecution(_requiredModule_, _seen_) is *false*, then + 1. Return *false*. + 1. Return *true*. + +features: [import-defer] +---*/ + +import defer * self from "./get-self-while-evaluating.js"; + +assert.throws(TypeError, () => self.foo); diff --git a/test/language/import/import-defer/errors/module-throws/defer-import-after-evaluation.js b/test/language/import/import-defer/errors/module-throws/defer-import-after-evaluation.js new file mode 100644 index 00000000000..21f81417fda --- /dev/null +++ b/test/language/import/import-defer/errors/module-throws/defer-import-after-evaluation.js @@ -0,0 +1,34 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-module-namespace-exotic-objects-get-p-receiver-EnsureDeferredNamespaceEvaluation +description: > + Module evaluation errors are thrown +info: | + [[Get]] ( _P_, _Receiver_ ) + 1. ... + 1. If _O_.[[Deferred]] is **true**, perform ? EnsureDeferredNamespaceEvaluation(_O_). + 1. ... + + EnsureDeferredNamespaceEvaluation( _O_ ) + 1. ... + 1. Perform ? EvaluateSync(_m_). + 1. ... + + EvaluateSync ( _module_ ) + 1. ... + 1. Let _promise_ be ! _module_.Evaluate(). + 1. Assert: _promise_.[[PromiseState]] is either ~fulfilled~ or ~rejected~. + 1. If _promise_.[[PromiseState]] is ~rejected~, then + 1. Return ThrowCompletion(_promise_.[[PromiseResult]]). + 1. ... + +features: [import-defer, top-level-await] +---*/ + +await import("./throws_FIXTURE.js").catch(() => {}); + +const { ns } = await import("./import-defer-throws_FIXTURE.js"); + +assert.throws(URIError, () => ns.foo, "Evaluation errors are thrown for modules evaluated before getting the deferred namespace"); diff --git a/test/language/import/import-defer/errors/module-throws/import-defer-throws_FIXTURE.js b/test/language/import/import-defer/errors/module-throws/import-defer-throws_FIXTURE.js new file mode 100644 index 00000000000..8049a5263c5 --- /dev/null +++ b/test/language/import/import-defer/errors/module-throws/import-defer-throws_FIXTURE.js @@ -0,0 +1,5 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import defer * as ns from "./import-defer-throws_FIXTURE.js"; +export { ns }; diff --git a/test/language/import/import-defer/errors/module-throws/third-party-evaluation-after-defer-import.js b/test/language/import/import-defer/errors/module-throws/third-party-evaluation-after-defer-import.js new file mode 100644 index 00000000000..f86131c4c05 --- /dev/null +++ b/test/language/import/import-defer/errors/module-throws/third-party-evaluation-after-defer-import.js @@ -0,0 +1,34 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-module-namespace-exotic-objects-get-p-receiver-EnsureDeferredNamespaceEvaluation +description: > + Module evaluation errors are thrown +info: | + [[Get]] ( _P_, _Receiver_ ) + 1. ... + 1. If _O_.[[Deferred]] is **true**, perform ? EnsureDeferredNamespaceEvaluation(_O_). + 1. ... + + EnsureDeferredNamespaceEvaluation( _O_ ) + 1. ... + 1. Perform ? EvaluateSync(_m_). + 1. ... + + EvaluateSync ( _module_ ) + 1. ... + 1. Let _promise_ be ! _module_.Evaluate(). + 1. Assert: _promise_.[[PromiseState]] is either ~fulfilled~ or ~rejected~. + 1. If _promise_.[[PromiseState]] is ~rejected~, then + 1. Return ThrowCompletion(_promise_.[[PromiseResult]]). + 1. ... + +features: [import-defer, top-level-await] +---*/ + +import defer * as ns from "./throws_FIXTURE.js"; + +await import("./throws_FIXTURE.js").catch(() => {}); + +assert.throws(URIError, () => ns.foo, "Evaluation errors are thrown for modules evaluated after getting the deferred namespace"); diff --git a/test/language/import/import-defer/errors/module-throws/throws_FIXTURE.js b/test/language/import/import-defer/errors/module-throws/throws_FIXTURE.js new file mode 100644 index 00000000000..fdcd441a0e5 --- /dev/null +++ b/test/language/import/import-defer/errors/module-throws/throws_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +throw new URIError("hello"); diff --git a/test/language/import/import-defer/errors/module-throws/trigger-evaluation.js b/test/language/import/import-defer/errors/module-throws/trigger-evaluation.js new file mode 100644 index 00000000000..5c0c8991765 --- /dev/null +++ b/test/language/import/import-defer/errors/module-throws/trigger-evaluation.js @@ -0,0 +1,33 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-module-namespace-exotic-objects-get-p-receiver-EnsureDeferredNamespaceEvaluation +description: > + Module evaluation errors are thrown +info: | + [[Get]] ( _P_, _Receiver_ ) + 1. ... + 1. If _O_.[[Deferred]] is **true**, perform ? EnsureDeferredNamespaceEvaluation(_O_). + 1. ... + + EnsureDeferredNamespaceEvaluation( _O_ ) + 1. ... + 1. Perform ? EvaluateSync(_m_). + 1. ... + + EvaluateSync ( _module_ ) + 1. ... + 1. Let _promise_ be ! _module_.Evaluate(). + 1. Assert: _promise_.[[PromiseState]] is either ~fulfilled~ or ~rejected~. + 1. If _promise_.[[PromiseState]] is ~rejected~, then + 1. Return ThrowCompletion(_promise_.[[PromiseResult]]). + 1. ... + +features: [import-defer] +---*/ + +import defer * as ns "./throws_FIXTURE.js"; + +assert.throws(URIError, () => ns.foo, "Evaluation errors are thrown when evaluating"); +assert.throws(URIError, () => ns.foo, "Evaluation errors are thrown for already evaluated modules"); diff --git a/test/language/import/import-defer/errors/resolution-error/import-defer-of-syntax-error-fails.js b/test/language/import/import-defer/errors/resolution-error/import-defer-of-syntax-error-fails.js new file mode 100644 index 00000000000..7766d404922 --- /dev/null +++ b/test/language/import/import-defer/errors/resolution-error/import-defer-of-syntax-error-fails.js @@ -0,0 +1,19 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-module-namespace-exotic-objects-get-p-receiver-EnsureDeferredNamespaceEvaluation +description: > + Module evaluation errors are thrown +info: | + LoadRequestedModules ([ _hostDefined_ ]) + - just notice that it does not check if the module is deferred + +features: [import-defer] + +negative: + phase: resolution + type: SyntaxErrpr +---*/ + +import defer * as ns "./resolution-error_FIXTURE.js"; diff --git a/test/language/import/import-defer/errors/resolution-error/resolution-error_FIXTURE.js b/test/language/import/import-defer/errors/resolution-error/resolution-error_FIXTURE.js new file mode 100644 index 00000000000..1701da4f252 --- /dev/null +++ b/test/language/import/import-defer/errors/resolution-error/resolution-error_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import "./missing.js"; diff --git a/test/language/import/import-defer/errors/syntax-error/import-defer-of-syntax-error-fails.js b/test/language/import/import-defer/errors/syntax-error/import-defer-of-syntax-error-fails.js new file mode 100644 index 00000000000..3272e8daa67 --- /dev/null +++ b/test/language/import/import-defer/errors/syntax-error/import-defer-of-syntax-error-fails.js @@ -0,0 +1,19 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-module-namespace-exotic-objects-get-p-receiver-EnsureDeferredNamespaceEvaluation +description: > + Module evaluation errors are thrown +info: | + LoadRequestedModules ([ _hostDefined_ ]) + - just notice that it does not check if the module is deferred + +features: [import-defer] + +negative: + phase: resolution + type: SyntaxErrpr +---*/ + +import defer * as ns "./syntax-error_FIXTURE.js"; diff --git a/test/language/import/import-defer/errors/syntax-error/syntax-error_FIXTURE.js b/test/language/import/import-defer/errors/syntax-error/syntax-error_FIXTURE.js new file mode 100644 index 00000000000..b7d22175413 --- /dev/null +++ b/test/language/import/import-defer/errors/syntax-error/syntax-error_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +invalid syntax! diff --git a/test/language/import/import-defer/evaluation-sync/dep-1.1_FIXTURE.js b/test/language/import/import-defer/evaluation-sync/dep-1.1_FIXTURE.js new file mode 100644 index 00000000000..a249c2f0088 --- /dev/null +++ b/test/language/import/import-defer/evaluation-sync/dep-1.1_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +globalThis.evaluations.push(1.1); diff --git a/test/language/import/import-defer/evaluation-sync/dep-1.2_FIXTURE.js b/test/language/import/import-defer/evaluation-sync/dep-1.2_FIXTURE.js new file mode 100644 index 00000000000..f2a00d26791 --- /dev/null +++ b/test/language/import/import-defer/evaluation-sync/dep-1.2_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +globalThis.evaluations.push(1.2); diff --git a/test/language/import/import-defer/evaluation-sync/dep-1_FIXTURE.js b/test/language/import/import-defer/evaluation-sync/dep-1_FIXTURE.js new file mode 100644 index 00000000000..4121c65e75c --- /dev/null +++ b/test/language/import/import-defer/evaluation-sync/dep-1_FIXTURE.js @@ -0,0 +1,9 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import "./dep-1.1_FIXTURE.js"; +import defer * as ns_1_2 from "./dep-1.2_FIXTURE.js"; + +globalThis.evaluations.push(1); + +export { ns_1_2 }; diff --git a/test/language/import/import-defer/evaluation-sync/dep-2_FIXTURE.js b/test/language/import/import-defer/evaluation-sync/dep-2_FIXTURE.js new file mode 100644 index 00000000000..7adbcd3bd77 --- /dev/null +++ b/test/language/import/import-defer/evaluation-sync/dep-2_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +globalThis.evaluations.push(2); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-get-symbol.js b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-get-symbol.js new file mode 100644 index 00000000000..56a4121b511 --- /dev/null +++ b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-get-symbol.js @@ -0,0 +1,27 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-module-namespace-exotic-objects-get-p-receiver +description: > + [[Get]] of a symbol does not trigger evaluation of the module +info: | + [[Get]] ( _P_, _Receiver_ ) + 1. If _P_ is a Symbol, then + 1. Return ! OrdinaryGet(_O_, _P_, _Receiver_). + 1. If _O_.[[Deferred]] is **true**, perform ? EnsureDeferredNamespaceEvaluation(_O_). + 1. ... + +features: [import-defer] +---*/ + +import "./setup_FIXTURE.js"; + +import defer * as ns1 "./dep-1_FIXTURE.js"; + +assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); + +ns1[Symbol.toStringTag]; +ns1[Symbol()]; + +assert(globalThis.evaluations.length === 0, "[[Get]] of a symbol does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-getPrototypeOf.js b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-getPrototypeOf.js new file mode 100644 index 00000000000..36eb68d02af --- /dev/null +++ b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-getPrototypeOf.js @@ -0,0 +1,23 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-module-namespace-exotic-objects-getprototypeof +description: > + [[GetPrototypeOf]] does not trigger evaluation of the module +info: | + [[GetPrototypeOf]] ( ) + 1. Return **null**. + +features: [import-defer] +---*/ + +import "./setup_FIXTURE.js"; + +import defer * as ns1 "./dep-1_FIXTURE.js"; + +assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); + +Object.getPrototypeOf(ns1); + +assert(globalThis.evaluations.length === 0, "[[GetPrototypeOf]] does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-isExtensible.js b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-isExtensible.js new file mode 100644 index 00000000000..c4e2dfe4f50 --- /dev/null +++ b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-isExtensible.js @@ -0,0 +1,23 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-module-namespace-exotic-objects-isextensible +description: > + [[IsExtensible]] does not trigger evaluation of the module +info: | + [[IsExtensible]] ( ) + 1. Return **false**. + +features: [import-defer] +---*/ + +import "./setup_FIXTURE.js"; + +import defer * as ns1 "./dep-1_FIXTURE.js"; + +assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); + +Object.isExtensible(ns1); + +assert(globalThis.evaluations.length === 0, "[[GetPrototypeOf]] does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-preventExtensions.js b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-preventExtensions.js new file mode 100644 index 00000000000..c914366a37a --- /dev/null +++ b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-preventExtensions.js @@ -0,0 +1,23 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-module-namespace-exotic-objects-preventextensions +description: > + [[PreventExtensions]] does not trigger evaluation of the module +info: | + [[PreventExtensions]] ( ) + 1. Return **true**. + +features: [import-defer] +---*/ + +import "./setup_FIXTURE.js"; + +import defer * as ns1 "./dep-1_FIXTURE.js"; + +assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); + +Object.preventExtensions(ns1); + +assert(globalThis.evaluations.length === 0, "[[GetPrototypeOf]] does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-set.js b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-set.js new file mode 100644 index 00000000000..6eb92f7e277 --- /dev/null +++ b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-set.js @@ -0,0 +1,24 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-module-namespace-exotic-objects-set-p-v-receiver +description: > + [[Set]] does not trigger evaluation of the module +info: | + [[Set]] ( _P_, _V_, _Receiver_ ) + 1. Return **false**. + +features: [import-defer] +---*/ + +import "./setup_FIXTURE.js"; + +import defer * as ns1 "./dep-1_FIXTURE.js"; + +assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); + +ns1.foo = 2; +ns1.ns_1_2 = 3; + +assert(globalThis.evaluations.length === 0, "[[Get]] of a symbol does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-setPrototypeOf.js b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-setPrototypeOf.js new file mode 100644 index 00000000000..dcb017eadb1 --- /dev/null +++ b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-setPrototypeOf.js @@ -0,0 +1,24 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-module-namespace-exotic-objects-setprototypeof-v +description: > + [[SetPrototypeOf]] does not trigger evaluation of the module +info: | + [[SetPrototypeOf]] ( _V_ ) + 1. Return ! SetImmutablePrototype(_O_, _V_). + +features: [import-defer] +---*/ + +import "./setup_FIXTURE.js"; + +import defer * as ns1 "./dep-1_FIXTURE.js"; + +assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); + +Reflect.setPrototypeOf(ns1, null); +Reflect.setPrototypeOf(ns1, {}); + +assert(globalThis.evaluations.length === 0, "[[GetPrototypeOf]] does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-trigger-get-string.js b/test/language/import/import-defer/evaluation-sync/evaluation-trigger-get-string.js new file mode 100644 index 00000000000..0531d798206 --- /dev/null +++ b/test/language/import/import-defer/evaluation-sync/evaluation-trigger-get-string.js @@ -0,0 +1,26 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-module-namespace-exotic-objects-get-p-receiver +description: > + [[Get]] of a string triggers evaluation of the module +info: | + [[Get]] ( _P_, _Receiver_ ) + 1. If _P_ is a Symbol, then + 1. Return ! OrdinaryGet(_O_, _P_, _Receiver_). + 1. If _O_.[[Deferred]] is **true**, perform ? EnsureDeferredNamespaceEvaluation(_O_). + 1. ... + +features: [import-defer] +---*/ + +import "./setup_FIXTURE.js"; + +import defer * as ns1 "./dep-1_FIXTURE.js"; + +assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); + +ns1.foo; + +assert(globalThis.evaluations.length > 0, "[[Get]] of a string triggers evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/import-defer-does-not-evaluate.js b/test/language/import/import-defer/evaluation-sync/import-defer-does-not-evaluate.js new file mode 100644 index 00000000000..b06ad64c126 --- /dev/null +++ b/test/language/import/import-defer/evaluation-sync/import-defer-does-not-evaluate.js @@ -0,0 +1,45 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-innermoduleevaluation +description: > + `import defer` by itself does not trigger evaluation of sync modules +info: | + 16.2.1.5.3.1 InnerModuleEvaluation ( _module_, _stack_, _index_ ) + 1. ... + 1. Let _evaluationList_ be a new empty List. + 1. For each ModuleRequest Record _required_ of _module_.[[RequestedModules]], do + 1. Let _requiredModule_ be GetImportedModule(_module_, _required_.[[Specifier]]). + 1. If _required_.[[Phase]] is ~defer~, then + i. Let _additionalModules_ be GatherAsynchronousTransitiveDependencies(_requiredModule_). + ii. For each Module Record _additionalModule_ of _additionalModules_, do + 1. If _evaluationList_ does not contain _additionalModule_, then + a. Append _additionalModule_ to _evaluationList_. + 1. Else if _evaluationList_ does not contain _requiredModule_, then + i. Append _requiredModule_ to _evaluationList_. + 1. ... + 1. For each Module Record _requiredModule_ of _evaluationList_, do + 1. Set _index_ to ? InnerModuleEvaluation(_requiredModule_, _stack_, _index_). + 1. ... + +features: [import-defer] +---*/ + +import "./setup_FIXTURE.js"; + +import defer * as ns1 "./dep-1_FIXTURE.js"; + +assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); + +const ns_1_2 = ns1.ns_1_2; + +assert.deepEqual(globalThis.evaluations, [1.1, 1], "when evaluation is triggered, deferred sub-dependencies are not evaluated"); + +ns1.ns_1_2; + +assert.deepEqual(globalThis.evaluations, [1.1, 1], "the module is not re-executed"); + +ns_1_2.foo; + +assert.deepEqual(globalThis.evaluations, [1.1, 1, 1.2]); diff --git a/test/language/import/import-defer/evaluation-sync/module-imported-defer-and-eager.js b/test/language/import/import-defer/evaluation-sync/module-imported-defer-and-eager.js new file mode 100644 index 00000000000..f0361b41052 --- /dev/null +++ b/test/language/import/import-defer/evaluation-sync/module-imported-defer-and-eager.js @@ -0,0 +1,49 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license _found_ in the LICENSE file. + +/*--- +esid: sec-static-semantics-modulerequests +description: > + `import defer` by itself does not trigger evaluation of sync modules +info: | + Static Semantics: ModuleRequests + ModuleItemList : ModuleItemList ModuleItem + 1. Let _requests_ be ModuleRequests of ModuleItemList. + 1. Let _additionalRequests_ be ModuleRequests of ModuleItem. + 1. For each ModuleRequest Record _mr_ of _additionalRequests_, do + 1. Let _found_ be false. + 1. For each ModuleRequest Record _mr2_ of _requests_, do + 1. If _mr_.[[Specifier]] is _mr2_.[[Specifier]] and _mr_.[[Phase]] is _mr2_.[[Phase]], then + 1. Assert: _found_ is false. + 1. Set _found_ to true. + 1. If _found_ is false, then + 1. Append _mr_ to _requests_. + 1. Return _requests_. + + 16.2.1.5.3.1 InnerModuleEvaluation ( _module_, _stack_, _index_ ) + 1. ... + 1. Let _evaluationList_ be a new empty List. + 1. For each ModuleRequest Record _required_ of _module_.[[RequestedModules]], do + 1. Let _requiredModule_ be GetImportedModule(_module_, _required_.[[Specifier]]). + 1. If _required_.[[Phase]] is ~defer~, then + i. Let _additionalModules_ be GatherAsynchronousTransitiveDependencies(_requiredModule_). + ii. For each Module Record _additionalModule_ of _additionalModules_, do + 1. If _evaluationList_ does not contain _additionalModule_, then + a. Append _additionalModule_ to _evaluationList_. + 1. Else if _evaluationList_ does not contain _requiredModule_, then + i. Append _requiredModule_ to _evaluationList_. + 1. ... + 1. For each Module Record _requiredModule_ of _evaluationList_, do + 1. Set _index_ to ? InnerModuleEvaluation(_requiredModule_, _stack_, _index_). + 1. ... + +features: [import-defer] +---*/ + +import "./setup_FIXTURE.js"; + +import defer * as ns1 "./dep-1_FIXTURE.js"; +import "./dep-2_FIXTURE.js"; +import "./dep-1_FIXTURE.js"; + +assert.deepEqual(globalThis.evaluations, [2, 1.1, 1], "the module is evaluated in the order where it's imported as non-deferred"); diff --git a/test/language/import/import-defer/evaluation-sync/setup_FIXTURE.js b/test/language/import/import-defer/evaluation-sync/setup_FIXTURE.js new file mode 100644 index 00000000000..d71b2fa95eb --- /dev/null +++ b/test/language/import/import-defer/evaluation-sync/setup_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +globalThis.evaluations = []; diff --git a/test/language/import/import-defer/syntax/dep_FIXTURE.js b/test/language/import/import-defer/syntax/dep_FIXTURE.js new file mode 100644 index 00000000000..c0a2af180a5 --- /dev/null +++ b/test/language/import/import-defer/syntax/dep_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export default 1; diff --git a/test/language/import/import-defer/syntax/import-attributes.js b/test/language/import/import-defer/syntax/import-attributes.js new file mode 100644 index 00000000000..56f7c8a93df --- /dev/null +++ b/test/language/import/import-defer/syntax/import-attributes.js @@ -0,0 +1,20 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-imports +description: > + `import defer` can be used with namespace imports +info: | + ImportDeclaration : + `import` ImportClause FromClause WithClause? `;` + `import` `defer` NameSpaceImport FromClause WithClause? `;` + `import` ModuleSpecifier WithClause? `;` + + NameSpaceImport : + `*` `as` ImportedBinding + +features: [import-defer] +---*/ + +import defer * as ns from "./dep_FIXTURE.js" with { }; diff --git a/test/language/import/import-defer/syntax/invalid-default-and-defer-namespace.js b/test/language/import/import-defer/syntax/invalid-default-and-defer-namespace.js new file mode 100644 index 00000000000..e2110156353 --- /dev/null +++ b/test/language/import/import-defer/syntax/invalid-default-and-defer-namespace.js @@ -0,0 +1,31 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-imports +description: > + `import defer` cannot be used if there are both a default and namespace bindings +info: | + ImportDeclaration : + `import` ImportClause FromClause `;` + `import` `defer` NameSpaceImport FromClause `;` + `import` ModuleSpecifier `;` + + ImportClause : + ImportedDefaultBinding + NameSpaceImport + NamedImports + ImportedDefaultBinding `,` NameSpaceImport + ImportedDefaultBinding `,` NamedImports + + NameSpaceImport : + `*` `as` ImportedBinding + +features: [import-defer] + +negative: + phase: parse + type: SyntaxError +---*/ + +import defer x, * as ns from "./dep_FIXTURE.js"; diff --git a/test/language/import/import-defer/syntax/invalid-defer-as-with-no-asterisk.js b/test/language/import/import-defer/syntax/invalid-defer-as-with-no-asterisk.js new file mode 100644 index 00000000000..225566fb524 --- /dev/null +++ b/test/language/import/import-defer/syntax/invalid-defer-as-with-no-asterisk.js @@ -0,0 +1,31 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-imports +description: > + `import defer` must be followed by `*` +info: | + ImportDeclaration : + `import` ImportClause FromClause `;` + `import` `defer` NameSpaceImport FromClause `;` + `import` ModuleSpecifier `;` + + ImportClause : + ImportedDefaultBinding + NameSpaceImport + NamedImports + ImportedDefaultBinding `,` NameSpaceImport + ImportedDefaultBinding `,` NamedImports + + NameSpaceImport : + `*` `as` ImportedBinding + +features: [import-defer] + +negative: + phase: parse + type: SyntaxError +---*/ + +import defer as ns from "./dep_FIXTURE.js"; diff --git a/test/language/import/import-defer/syntax/invalid-defer-default-and-namespace copy.js b/test/language/import/import-defer/syntax/invalid-defer-default-and-namespace copy.js new file mode 100644 index 00000000000..a6a957d7d6e --- /dev/null +++ b/test/language/import/import-defer/syntax/invalid-defer-default-and-namespace copy.js @@ -0,0 +1,31 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-imports +description: > + `import defer` cannot be used if there are both a default and namespace bindings +info: | + ImportDeclaration : + `import` ImportClause FromClause `;` + `import` `defer` NameSpaceImport FromClause `;` + `import` ModuleSpecifier `;` + + ImportClause : + ImportedDefaultBinding + NameSpaceImport + NamedImports + ImportedDefaultBinding `,` NameSpaceImport + ImportedDefaultBinding `,` NamedImports + + NameSpaceImport : + `*` `as` ImportedBinding + +features: [import-defer] + +negative: + phase: parse + type: SyntaxError +---*/ + +import x, defer * as ns from "./dep_FIXTURE.js"; diff --git a/test/language/import/import-defer/syntax/invalid-defer-default.js b/test/language/import/import-defer/syntax/invalid-defer-default.js new file mode 100644 index 00000000000..baccd4b9fe8 --- /dev/null +++ b/test/language/import/import-defer/syntax/invalid-defer-default.js @@ -0,0 +1,31 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-imports +description: > + `import defer` cannot be used with default imports +info: | + ImportDeclaration : + `import` ImportClause FromClause `;` + `import` `defer` NameSpaceImport FromClause `;` + `import` ModuleSpecifier `;` + + ImportClause : + ImportedDefaultBinding + NameSpaceImport + NamedImports + ImportedDefaultBinding `,` NameSpaceImport + ImportedDefaultBinding `,` NamedImports + + NameSpaceImport : + `*` `as` ImportedBinding + +features: [import-defer] + +negative: + phase: parse + type: SyntaxError +---*/ + +import defer x from "./dep_FIXTURE.js"; diff --git a/test/language/import/import-defer/syntax/invalid-defer-named.js b/test/language/import/import-defer/syntax/invalid-defer-named.js new file mode 100644 index 00000000000..f076391a53a --- /dev/null +++ b/test/language/import/import-defer/syntax/invalid-defer-named.js @@ -0,0 +1,31 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-imports +description: > + `import defer` cannot be used with named imports +info: | + ImportDeclaration : + `import` ImportClause FromClause `;` + `import` `defer` NameSpaceImport FromClause `;` + `import` ModuleSpecifier `;` + + ImportClause : + ImportedDefaultBinding + NameSpaceImport + NamedImports + ImportedDefaultBinding `,` NameSpaceImport + ImportedDefaultBinding `,` NamedImports + + NameSpaceImport : + `*` `as` ImportedBinding + +features: [import-defer] + +negative: + phase: parse + type: SyntaxError +---*/ + +import defer { default as x } from "./dep_FIXTURE.js"; diff --git a/test/language/import/import-defer/syntax/invalid-export-defer-namespace.js b/test/language/import/import-defer/syntax/invalid-export-defer-namespace.js new file mode 100644 index 00000000000..65a2a2dd1cb --- /dev/null +++ b/test/language/import/import-defer/syntax/invalid-export-defer-namespace.js @@ -0,0 +1,30 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-exports +description: > + `export defer` is not valid +info: | + ExportDeclaration : + `export` ExportFromClause FromClause `;` + `export` NamedExports `;` + `export` VariableStatement + `export` Declaration + `export` `default` HoistableDeclaration + `export` `default` ClassDeclaration + `export` `default` [lookahead ∉ { function, async [no LineTerminator here] function, class }] AssignmentExpression `;` + + ExportFromClause : + `*` + `*` `as` ModuleExportName + NamedExports + +features: [import-defer] + +negative: + phase: parse + type: SyntaxError +---*/ + +export defer * as ns from "./dep_FIXTURE.js"; diff --git a/test/language/import/import-defer/syntax/valid-default-binding-named-defer.js b/test/language/import/import-defer/syntax/valid-default-binding-named-defer.js new file mode 100644 index 00000000000..a604acf2c5d --- /dev/null +++ b/test/language/import/import-defer/syntax/valid-default-binding-named-defer.js @@ -0,0 +1,27 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-imports +description: > + `defer` is a valid name for default imports +info: | + ImportDeclaration : + `import` ImportClause FromClause `;` + `import` `defer` NameSpaceImport FromClause `;` + `import` ModuleSpecifier `;` + + ImportClause : + ImportedDefaultBinding + ... + + ImportedDefaultBinding : + ImportedBinding + + ImportedBinding : + BindingIdentifier[~Yield, +Await] + +features: [import-defer] +---*/ + +import defer from "./dep_FIXTURE.js"; diff --git a/test/language/import/import-defer/syntax/valid-defer-namespace.js b/test/language/import/import-defer/syntax/valid-defer-namespace.js new file mode 100644 index 00000000000..7eab55f62ca --- /dev/null +++ b/test/language/import/import-defer/syntax/valid-defer-namespace.js @@ -0,0 +1,20 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-imports +description: > + `import defer` can be used with namespace imports +info: | + ImportDeclaration : + `import` ImportClause FromClause `;` + `import` `defer` NameSpaceImport FromClause `;` + `import` ModuleSpecifier `;` + + NameSpaceImport : + `*` `as` ImportedBinding + +features: [import-defer] +---*/ + +import defer * as ns from "./dep_FIXTURE.js"; From 79c364c23f98a0fc65f68c20a66eb17e6a0a00bc Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Sun, 27 Oct 2024 17:52:04 -0700 Subject: [PATCH 02/13] Fixes for import-defer tests * Add deepEqual.js include where needed * Add module flag where needed * Fix some typos * In evaluation-ignore-set, add a try block to catch typeerrors from assignment Need the bug URL (OOPS!). Reviewed by NOBODY (OOPS!). Explanation of why this fixes the bug (OOPS!). * test/language/import/import-defer/deferred-namespace-object/dep-defer-ns_FIXTURE.js: * test/language/import/import-defer/deferred-namespace-object/identity.js: * test/language/import/import-defer/deferred-namespace-object/object-properties.js: * test/language/import/import-defer/errors/get-other-while-dep-evaluating/main.js: * test/language/import/import-defer/errors/get-other-while-evaluating/main.js: * test/language/import/import-defer/errors/get-self-while-defer-evaluating/main.js: * test/language/import/import-defer/errors/get-self-while-evaluating.js: * test/language/import/import-defer/errors/module-throws/defer-import-after-evaluation.js: * test/language/import/import-defer/errors/module-throws/third-party-evaluation-after-defer-import.js: * test/language/import/import-defer/errors/module-throws/trigger-evaluation.js: * test/language/import/import-defer/errors/resolution-error/import-defer-of-syntax-error-fails.js: * test/language/import/import-defer/errors/syntax-error/import-defer-of-syntax-error-fails.js: * test/language/import/import-defer/evaluation-sync/evaluation-ignore-get-symbol.js: * test/language/import/import-defer/evaluation-sync/evaluation-ignore-getPrototypeOf.js: * test/language/import/import-defer/evaluation-sync/evaluation-ignore-isExtensible.js: * test/language/import/import-defer/evaluation-sync/evaluation-ignore-preventExtensions.js: * test/language/import/import-defer/evaluation-sync/evaluation-ignore-set.js: * test/language/import/import-defer/evaluation-sync/evaluation-ignore-setPrototypeOf.js: * test/language/import/import-defer/evaluation-sync/evaluation-trigger-get-string.js: * test/language/import/import-defer/evaluation-sync/import-defer-does-not-evaluate.js: * test/language/import/import-defer/evaluation-sync/module-imported-defer-and-eager.js: * test/language/import/import-defer/syntax/import-attributes.js: * test/language/import/import-defer/syntax/valid-default-binding-named-defer.js: * test/language/import/import-defer/syntax/valid-defer-namespace.js: --- .../dep-defer-ns_FIXTURE.js | 2 +- .../deferred-namespace-object/identity.js | 1 + .../deferred-namespace-object/object-properties.js | 7 ++++--- .../errors/get-other-while-dep-evaluating/main.js | 1 + .../errors/get-other-while-evaluating/main.js | 1 + .../errors/get-self-while-defer-evaluating/main.js | 1 + .../errors/get-self-while-evaluating.js | 3 ++- .../module-throws/defer-import-after-evaluation.js | 1 + .../third-party-evaluation-after-defer-import.js | 1 + .../errors/module-throws/trigger-evaluation.js | 3 ++- .../import-defer-of-syntax-error-fails.js | 3 ++- .../import-defer-of-syntax-error-fails.js | 3 ++- .../evaluation-sync/evaluation-ignore-get-symbol.js | 3 ++- .../evaluation-ignore-getPrototypeOf.js | 3 ++- .../evaluation-ignore-isExtensible.js | 3 ++- .../evaluation-ignore-preventExtensions.js | 3 ++- .../evaluation-sync/evaluation-ignore-set.js | 13 +++++++++---- .../evaluation-ignore-setPrototypeOf.js | 3 ++- .../evaluation-trigger-get-string.js | 3 ++- .../import-defer-does-not-evaluate.js | 4 +++- .../module-imported-defer-and-eager.js | 4 +++- .../import/import-defer/syntax/import-attributes.js | 1 + .../syntax/valid-default-binding-named-defer.js | 1 + .../import-defer/syntax/valid-defer-namespace.js | 1 + 24 files changed, 49 insertions(+), 20 deletions(-) diff --git a/test/language/import/import-defer/deferred-namespace-object/dep-defer-ns_FIXTURE.js b/test/language/import/import-defer/deferred-namespace-object/dep-defer-ns_FIXTURE.js index fceef1b0553..fff88eceb56 100644 --- a/test/language/import/import-defer/deferred-namespace-object/dep-defer-ns_FIXTURE.js +++ b/test/language/import/import-defer/deferred-namespace-object/dep-defer-ns_FIXTURE.js @@ -1,6 +1,6 @@ // Copyright (C) 2024 Igalia, S.L. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. -import defer * as depDeferredNamespace from "./dep.js"; +import defer * as depDeferredNamespace from "./dep_FIXTURE.js"; export { depDeferredNamespace }; diff --git a/test/language/import/import-defer/deferred-namespace-object/identity.js b/test/language/import/import-defer/deferred-namespace-object/identity.js index f8d459ebc08..519c96dd84f 100644 --- a/test/language/import/import-defer/deferred-namespace-object/identity.js +++ b/test/language/import/import-defer/deferred-namespace-object/identity.js @@ -26,6 +26,7 @@ info: | 1. ... 1. Return _M_. +flags: [module] features: [import-defer] ---*/ diff --git a/test/language/import/import-defer/deferred-namespace-object/object-properties.js b/test/language/import/import-defer/deferred-namespace-object/object-properties.js index fd83b62d6a9..ad8b7280f0c 100644 --- a/test/language/import/import-defer/deferred-namespace-object/object-properties.js +++ b/test/language/import/import-defer/deferred-namespace-object/object-properties.js @@ -18,8 +18,9 @@ info: | [[IsExtensible]] ( ) 1. Return false. +flags: [module] features: [import-defer] -includes: [propertyHelper.js] +includes: [propertyHelper.js, deepEqual.js] ---*/ import defer * as ns from "./dep_FIXTURE.js"; @@ -30,8 +31,8 @@ assert(Reflect.isExtensible(ns) === false, "Deferred namespaces are not extensib assert(Reflect.preventExtensions(ns) === true, "Deferred namespaces can made non-extensible"); assert(Reflect.getPrototypeOf(ns) === null, "Deferred namespaces have a null prototype"); -asserts(Reflect.setPrototypeOf(ns, {}) === false, "Deferred namespaces' prototype cannot be changed"); -asserts(Reflect.setPrototypeOf(ns, null) === true, "Deferred namespaces' prototype can be 'set' to null"); +assert(Reflect.setPrototypeOf(ns, {}) === false, "Deferred namespaces' prototype cannot be changed"); +assert(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"); diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating/main.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating/main.js index b058095d7d3..d27fefb061a 100644 --- a/test/language/import/import-defer/errors/get-other-while-dep-evaluating/main.js +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating/main.js @@ -31,6 +31,7 @@ info: | 1. Return *false*. 1. Return *true*. +flags: [module] features: [import-defer] ---*/ diff --git a/test/language/import/import-defer/errors/get-other-while-evaluating/main.js b/test/language/import/import-defer/errors/get-other-while-evaluating/main.js index 250f23b2617..5eb76bc5279 100644 --- a/test/language/import/import-defer/errors/get-other-while-evaluating/main.js +++ b/test/language/import/import-defer/errors/get-other-while-evaluating/main.js @@ -31,6 +31,7 @@ info: | 1. Return *false*. 1. Return *true*. +flags: [module] features: [import-defer] ---*/ diff --git a/test/language/import/import-defer/errors/get-self-while-defer-evaluating/main.js b/test/language/import/import-defer/errors/get-self-while-defer-evaluating/main.js index 9828b6783cc..dc5f2b51b89 100644 --- a/test/language/import/import-defer/errors/get-self-while-defer-evaluating/main.js +++ b/test/language/import/import-defer/errors/get-self-while-defer-evaluating/main.js @@ -31,6 +31,7 @@ info: | 1. Return *false*. 1. Return *true*. +flags: [module] features: [import-defer] ---*/ diff --git a/test/language/import/import-defer/errors/get-self-while-evaluating.js b/test/language/import/import-defer/errors/get-self-while-evaluating.js index 4010214eae3..6fbd0c27b3e 100644 --- a/test/language/import/import-defer/errors/get-self-while-evaluating.js +++ b/test/language/import/import-defer/errors/get-self-while-evaluating.js @@ -31,9 +31,10 @@ info: | 1. Return *false*. 1. Return *true*. +flags: [module] features: [import-defer] ---*/ -import defer * self from "./get-self-while-evaluating.js"; +import defer * as self from "./get-self-while-evaluating.js"; assert.throws(TypeError, () => self.foo); diff --git a/test/language/import/import-defer/errors/module-throws/defer-import-after-evaluation.js b/test/language/import/import-defer/errors/module-throws/defer-import-after-evaluation.js index 21f81417fda..af34278238d 100644 --- a/test/language/import/import-defer/errors/module-throws/defer-import-after-evaluation.js +++ b/test/language/import/import-defer/errors/module-throws/defer-import-after-evaluation.js @@ -24,6 +24,7 @@ info: | 1. Return ThrowCompletion(_promise_.[[PromiseResult]]). 1. ... +flags: [module] features: [import-defer, top-level-await] ---*/ diff --git a/test/language/import/import-defer/errors/module-throws/third-party-evaluation-after-defer-import.js b/test/language/import/import-defer/errors/module-throws/third-party-evaluation-after-defer-import.js index f86131c4c05..0c22ef4a576 100644 --- a/test/language/import/import-defer/errors/module-throws/third-party-evaluation-after-defer-import.js +++ b/test/language/import/import-defer/errors/module-throws/third-party-evaluation-after-defer-import.js @@ -24,6 +24,7 @@ info: | 1. Return ThrowCompletion(_promise_.[[PromiseResult]]). 1. ... +flags: [module] features: [import-defer, top-level-await] ---*/ diff --git a/test/language/import/import-defer/errors/module-throws/trigger-evaluation.js b/test/language/import/import-defer/errors/module-throws/trigger-evaluation.js index 5c0c8991765..34b790c6c27 100644 --- a/test/language/import/import-defer/errors/module-throws/trigger-evaluation.js +++ b/test/language/import/import-defer/errors/module-throws/trigger-evaluation.js @@ -24,10 +24,11 @@ info: | 1. Return ThrowCompletion(_promise_.[[PromiseResult]]). 1. ... +flags: [module] features: [import-defer] ---*/ -import defer * as ns "./throws_FIXTURE.js"; +import defer * as ns from "./throws_FIXTURE.js"; assert.throws(URIError, () => ns.foo, "Evaluation errors are thrown when evaluating"); assert.throws(URIError, () => ns.foo, "Evaluation errors are thrown for already evaluated modules"); diff --git a/test/language/import/import-defer/errors/resolution-error/import-defer-of-syntax-error-fails.js b/test/language/import/import-defer/errors/resolution-error/import-defer-of-syntax-error-fails.js index 7766d404922..1104bf6cbba 100644 --- a/test/language/import/import-defer/errors/resolution-error/import-defer-of-syntax-error-fails.js +++ b/test/language/import/import-defer/errors/resolution-error/import-defer-of-syntax-error-fails.js @@ -9,11 +9,12 @@ info: | LoadRequestedModules ([ _hostDefined_ ]) - just notice that it does not check if the module is deferred +flags: [module] features: [import-defer] negative: phase: resolution - type: SyntaxErrpr + type: SyntaxError ---*/ import defer * as ns "./resolution-error_FIXTURE.js"; diff --git a/test/language/import/import-defer/errors/syntax-error/import-defer-of-syntax-error-fails.js b/test/language/import/import-defer/errors/syntax-error/import-defer-of-syntax-error-fails.js index 3272e8daa67..09520de2072 100644 --- a/test/language/import/import-defer/errors/syntax-error/import-defer-of-syntax-error-fails.js +++ b/test/language/import/import-defer/errors/syntax-error/import-defer-of-syntax-error-fails.js @@ -9,11 +9,12 @@ info: | LoadRequestedModules ([ _hostDefined_ ]) - just notice that it does not check if the module is deferred +flags: [module] features: [import-defer] negative: phase: resolution - type: SyntaxErrpr + type: SyntaxError ---*/ import defer * as ns "./syntax-error_FIXTURE.js"; diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-get-symbol.js b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-get-symbol.js index 56a4121b511..e8ed9700c1b 100644 --- a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-get-symbol.js +++ b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-get-symbol.js @@ -12,12 +12,13 @@ info: | 1. If _O_.[[Deferred]] is **true**, perform ? EnsureDeferredNamespaceEvaluation(_O_). 1. ... +flags: [module] features: [import-defer] ---*/ import "./setup_FIXTURE.js"; -import defer * as ns1 "./dep-1_FIXTURE.js"; +import defer * as ns1 from "./dep-1_FIXTURE.js"; assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-getPrototypeOf.js b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-getPrototypeOf.js index 36eb68d02af..c36ac7c5fcc 100644 --- a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-getPrototypeOf.js +++ b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-getPrototypeOf.js @@ -9,12 +9,13 @@ info: | [[GetPrototypeOf]] ( ) 1. Return **null**. +flags: [module] features: [import-defer] ---*/ import "./setup_FIXTURE.js"; -import defer * as ns1 "./dep-1_FIXTURE.js"; +import defer * as ns1 from "./dep-1_FIXTURE.js"; assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-isExtensible.js b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-isExtensible.js index c4e2dfe4f50..ff815565c76 100644 --- a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-isExtensible.js +++ b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-isExtensible.js @@ -9,12 +9,13 @@ info: | [[IsExtensible]] ( ) 1. Return **false**. +flags: [module] features: [import-defer] ---*/ import "./setup_FIXTURE.js"; -import defer * as ns1 "./dep-1_FIXTURE.js"; +import defer * as ns1 from "./dep-1_FIXTURE.js"; assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-preventExtensions.js b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-preventExtensions.js index c914366a37a..5ceb8b3a804 100644 --- a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-preventExtensions.js +++ b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-preventExtensions.js @@ -9,12 +9,13 @@ info: | [[PreventExtensions]] ( ) 1. Return **true**. +flags: [module] features: [import-defer] ---*/ import "./setup_FIXTURE.js"; -import defer * as ns1 "./dep-1_FIXTURE.js"; +import defer * as ns1 from "./dep-1_FIXTURE.js"; assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-set.js b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-set.js index 6eb92f7e277..738a53b747b 100644 --- a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-set.js +++ b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-set.js @@ -9,16 +9,21 @@ info: | [[Set]] ( _P_, _V_, _Receiver_ ) 1. Return **false**. +flags: [module] features: [import-defer] ---*/ import "./setup_FIXTURE.js"; -import defer * as ns1 "./dep-1_FIXTURE.js"; +import defer * as ns1 from "./dep-1_FIXTURE.js"; assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); -ns1.foo = 2; -ns1.ns_1_2 = 3; +try { + ns1.foo = 2; +} catch {} +try { + ns1.ns_1_2 = 3; +} catch {} -assert(globalThis.evaluations.length === 0, "[[Get]] of a symbol does not trigger evaluation"); +assert(globalThis.evaluations.length === 0, "[[Set]] of a symbol does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-setPrototypeOf.js b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-setPrototypeOf.js index dcb017eadb1..a0953218df5 100644 --- a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-setPrototypeOf.js +++ b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-setPrototypeOf.js @@ -9,12 +9,13 @@ info: | [[SetPrototypeOf]] ( _V_ ) 1. Return ! SetImmutablePrototype(_O_, _V_). +flags: [module] features: [import-defer] ---*/ import "./setup_FIXTURE.js"; -import defer * as ns1 "./dep-1_FIXTURE.js"; +import defer * as ns1 from "./dep-1_FIXTURE.js"; assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-trigger-get-string.js b/test/language/import/import-defer/evaluation-sync/evaluation-trigger-get-string.js index 0531d798206..528851ba2ab 100644 --- a/test/language/import/import-defer/evaluation-sync/evaluation-trigger-get-string.js +++ b/test/language/import/import-defer/evaluation-sync/evaluation-trigger-get-string.js @@ -12,12 +12,13 @@ info: | 1. If _O_.[[Deferred]] is **true**, perform ? EnsureDeferredNamespaceEvaluation(_O_). 1. ... +flags: [module] features: [import-defer] ---*/ import "./setup_FIXTURE.js"; -import defer * as ns1 "./dep-1_FIXTURE.js"; +import defer * as ns1 from "./dep-1_FIXTURE.js"; assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/import-defer-does-not-evaluate.js b/test/language/import/import-defer/evaluation-sync/import-defer-does-not-evaluate.js index b06ad64c126..bb49ef0938e 100644 --- a/test/language/import/import-defer/evaluation-sync/import-defer-does-not-evaluate.js +++ b/test/language/import/import-defer/evaluation-sync/import-defer-does-not-evaluate.js @@ -23,12 +23,14 @@ info: | 1. Set _index_ to ? InnerModuleEvaluation(_requiredModule_, _stack_, _index_). 1. ... +flags: [module] features: [import-defer] +includes: [deepEqual.js] ---*/ import "./setup_FIXTURE.js"; -import defer * as ns1 "./dep-1_FIXTURE.js"; +import defer * as ns1 from "./dep-1_FIXTURE.js"; assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/module-imported-defer-and-eager.js b/test/language/import/import-defer/evaluation-sync/module-imported-defer-and-eager.js index f0361b41052..53552052e3b 100644 --- a/test/language/import/import-defer/evaluation-sync/module-imported-defer-and-eager.js +++ b/test/language/import/import-defer/evaluation-sync/module-imported-defer-and-eager.js @@ -37,12 +37,14 @@ info: | 1. Set _index_ to ? InnerModuleEvaluation(_requiredModule_, _stack_, _index_). 1. ... +flags: [module] features: [import-defer] +includes: [deepEqual.js] ---*/ import "./setup_FIXTURE.js"; -import defer * as ns1 "./dep-1_FIXTURE.js"; +import defer * as ns1 from "./dep-1_FIXTURE.js"; import "./dep-2_FIXTURE.js"; import "./dep-1_FIXTURE.js"; diff --git a/test/language/import/import-defer/syntax/import-attributes.js b/test/language/import/import-defer/syntax/import-attributes.js index 56f7c8a93df..56b52d5da04 100644 --- a/test/language/import/import-defer/syntax/import-attributes.js +++ b/test/language/import/import-defer/syntax/import-attributes.js @@ -14,6 +14,7 @@ info: | NameSpaceImport : `*` `as` ImportedBinding +flags: [module] features: [import-defer] ---*/ diff --git a/test/language/import/import-defer/syntax/valid-default-binding-named-defer.js b/test/language/import/import-defer/syntax/valid-default-binding-named-defer.js index a604acf2c5d..16743bac5b6 100644 --- a/test/language/import/import-defer/syntax/valid-default-binding-named-defer.js +++ b/test/language/import/import-defer/syntax/valid-default-binding-named-defer.js @@ -21,6 +21,7 @@ info: | ImportedBinding : BindingIdentifier[~Yield, +Await] +flags: [module] features: [import-defer] ---*/ diff --git a/test/language/import/import-defer/syntax/valid-defer-namespace.js b/test/language/import/import-defer/syntax/valid-defer-namespace.js index 7eab55f62ca..2cf3637e1dc 100644 --- a/test/language/import/import-defer/syntax/valid-defer-namespace.js +++ b/test/language/import/import-defer/syntax/valid-defer-namespace.js @@ -14,6 +14,7 @@ info: | NameSpaceImport : `*` `as` ImportedBinding +flags: [module] features: [import-defer] ---*/ From 8ab7c25f670e641bfc7fc4953dbfa37825003f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Mon, 28 Oct 2024 20:27:55 +0100 Subject: [PATCH 03/13] Add tests for async cases --- .../dep-1-tla_FIXTURE.js | 13 ++++ .../dep-1.1.1_FIXTURE.js | 6 ++ .../dep-1.1_FIXTURE.js | 19 +++++ .../main.js | 41 ++++++++++ .../promises_FIXTURE.js | 14 ++++ .../dep-1-tla_FIXTURE.js | 15 ++++ .../dep-1.1_FIXTURE.js | 19 +++++ .../get-other-while-evaluating-async/main.js | 41 ++++++++++ .../promises_FIXTURE.js | 14 ++++ .../dep_FIXTURE.js | 8 ++ .../get-self-while-evaluating-async/main.js | 36 +++++++++ .../flattening-order/dep-1_FIXTURE.js | 4 + .../flattening-order/dep-2.1.1-tla_FIXTURE.js | 4 + .../flattening-order/dep-2.1_FIXTURE.js | 6 ++ .../flattening-order/dep-2.2-tla_FIXTURE.js | 10 +++ .../flattening-order/dep-2.2.1_FIXTURE.js | 8 ++ .../flattening-order/dep-2_FIXTURE.js | 7 ++ .../flattening-order/dep-3_FIXTURE.js | 4 + .../flattening-order/dep-4.1-tla_FIXTURE.js | 10 +++ .../flattening-order/dep-4_FIXTURE.js | 6 ++ .../flattening-order/dep-5_FIXTURE.js | 4 + .../flattening-order/main.js | 76 +++++++++++++++++++ .../import-defer-async-module/main.js | 54 +++++++++++++ .../import-defer-async-module/tla_FIXTURE.js | 8 ++ .../imports-tla_FIXTURE.js | 6 ++ .../main.js | 54 +++++++++++++ .../tla_FIXTURE.js | 8 ++ .../setup_FIXTURE.js | 4 + .../dep_FIXTURE.js | 4 + .../imports-tla-with-dep_FIXTURE.js | 6 ++ .../main.js | 60 +++++++++++++++ .../tla-with-dep_FIXTURE.js | 10 +++ 32 files changed, 579 insertions(+) create mode 100644 test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1-tla_FIXTURE.js create mode 100644 test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1.1.1_FIXTURE.js create mode 100644 test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1.1_FIXTURE.js create mode 100644 test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/main.js create mode 100644 test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/promises_FIXTURE.js create mode 100644 test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1-tla_FIXTURE.js create mode 100644 test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1.1_FIXTURE.js create mode 100644 test/language/import/import-defer/errors/get-other-while-evaluating-async/main.js create mode 100644 test/language/import/import-defer/errors/get-other-while-evaluating-async/promises_FIXTURE.js create mode 100644 test/language/import/import-defer/errors/get-self-while-evaluating-async/dep_FIXTURE.js create mode 100644 test/language/import/import-defer/errors/get-self-while-evaluating-async/main.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-1_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.1.1-tla_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.1_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.2-tla_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.2.1_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-3_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-4.1-tla_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-4_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-5_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/flattening-order/main.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/import-defer-async-module/main.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/import-defer-async-module/tla_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/imports-tla_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/main.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/tla_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/setup_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/dep_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/imports-tla-with-dep_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/main.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/tla-with-dep_FIXTURE.js diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1-tla_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1-tla_FIXTURE.js new file mode 100644 index 00000000000..67acb62969d --- /dev/null +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1-tla_FIXTURE.js @@ -0,0 +1,13 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import { resolveFirst, resolveThird } from "./promises_FIXTURE.js"; +import "./dep-1.1_FIXTURE.js" + +await Promise.resolve(); + +resolveFirst(); + +await second; + +resolveThird(); diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1.1.1_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1.1.1_FIXTURE.js new file mode 100644 index 00000000000..7b6523f051c --- /dev/null +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1.1.1_FIXTURE.js @@ -0,0 +1,6 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import defer * as ns from "./dep-1-tla_FIXTURE.js"; + +export let foo = 1; diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1.1_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1.1_FIXTURE.js new file mode 100644 index 00000000000..d5a678d1241 --- /dev/null +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1.1_FIXTURE.js @@ -0,0 +1,19 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import { first, third, rejectDone, resolveDone } from "./promises_FIXTURE.js"; +import defer * as ns from "./dep-1.1.1-tla_FIXTURE.js"; + +// dep-1 is now in the ~evaluating~ state +assert.throws(TypeError, () => ns.foo); + +first.then(() => { + // dep-1 is now in the ~evaluating-async~ state + assert.throws(TypeError, () => ns.foo); +}).then(() => { + return third.then(() => { + // dep-1 is now in the ~evaluated~ state + let foo = ns.foo; + assert(foo === 1, "Once it finished evaluating, the module can be accessed"); + }) +}).then(resolveDone, rejectDone); diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/main.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/main.js new file mode 100644 index 00000000000..cdc314884e1 --- /dev/null +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/main.js @@ -0,0 +1,41 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-module-namespace-exotic-objects-get-p-receiver-EnsureDeferredNamespaceEvaluation +description: > + Modules cannot try to trigger evaluation of modules that have dependencies in their ~evaluating-async~ phase +info: | + 10.4.6.8 [[Get]] ( _P_, _Receiver_ ) + 1. ... + 1. If _O_.[[Deferred]] is **true**, perform ? EnsureDeferredNamespaceEvaluation(_O_). + 1. ... + + EnsureDeferredNamespaceEvaluation ( _O_ ) + 1. Assert: _O_.[[Deferred]] is *false*. + 1. Let _m_ be _O_.[[Module]]. + 1. If _m_ is a Cyclic Module Record, _m_.[[Status]] is not ~evaluated~, and ReadyForSyncExecution(_m_) is *false*, throw a *TypeError* exception. + 1. ... + + ReadyForSyncExecution( _module_, _seen_ ) + 1. If _seen_ is not provided, let _seen_ be a new empty List. + 1. If _seen_ contains _module_, return *true*. + 1. Append _module_ to _seen_. + 1. If _module_.[[Status]] is ~evaluated~, return *true*. + 1. If _module_.[[Status]] is ~evaluating~ or ~evaluating-async~, return *false*. + 1. Assert: _module_.[[Status]] is ~linked~. + 1. If _module_.[[HasTLA]] is *true*, return *false*. + 1. For each ModuleRequest Record _required_ of _module_.[[RequestedModules]], do + 1. Let _requiredModule_ be GetImportedModule(_module_, _required_.[[Specifier]]). + 1. If ReadyForSyncExecution(_requiredModule_, _seen_) is *false*, then + 1. Return *false*. + 1. Return *true*. + +flags: [module, async] +features: [import-defer, top-level-await] +---*/ + +import { done } from "./promises_FIXTURE.js"; +import "./dep-1-tla_FIXTURE.js"; + +done.then($DONE, $DONE); diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/promises_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/promises_FIXTURE.js new file mode 100644 index 00000000000..a54c20ffa56 --- /dev/null +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/promises_FIXTURE.js @@ -0,0 +1,14 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export let resolveDone, rejectDone; +export const done = new Promise((r, j) => (resolveDone = r, rejecteDone = j)); + +export let resolveFirst, rejectFirst; +export const first = new Promise((r, j) => (resolveFirst = r, rejectFirst = j)); + +export let resolveSecond, rejectSecond; +export const second = new Promise((r, j) => (resolveSecond = r, rejectSecond = j)); + +export let resolveThird, rejectThird; +export const third = new Promise((r, j) => (resolveThird = r, rejectThird = j)); diff --git a/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1-tla_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1-tla_FIXTURE.js new file mode 100644 index 00000000000..a0c6dcfb979 --- /dev/null +++ b/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1-tla_FIXTURE.js @@ -0,0 +1,15 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import { resolveFirst, resolveThird } from "./promises_FIXTURE.js"; +import "./dep-1.1_FIXTURE.js" + +await Promise.resolve(); + +resolveFirst(); + +await second; + +resolveThird(); + +export let foo = 1; diff --git a/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1.1_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1.1_FIXTURE.js new file mode 100644 index 00000000000..4acd5b51c7e --- /dev/null +++ b/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1.1_FIXTURE.js @@ -0,0 +1,19 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import { first, third, rejectDone, resolveDone } from "./promises_FIXTURE.js"; +import defer * as ns from "./dep-1-tla_FIXTURE.js"; + +// ns is now in the ~evaluating~ state +assert.throws(TypeError, () => ns.foo); + +first.then(() => { + // ns is now in the ~evaluating-async~ state + assert.throws(TypeError, () => ns.foo); +}).then(() => { + return third.then(() => { + // ns is now in the ~evaluated~ state + let foo = ns.foo; + assert(foo === 1, "Once it finished evaluating, the module can be accessed"); + }) +}).then(resolveDone, rejectDone); diff --git a/test/language/import/import-defer/errors/get-other-while-evaluating-async/main.js b/test/language/import/import-defer/errors/get-other-while-evaluating-async/main.js new file mode 100644 index 00000000000..385ee1917ac --- /dev/null +++ b/test/language/import/import-defer/errors/get-other-while-evaluating-async/main.js @@ -0,0 +1,41 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-module-namespace-exotic-objects-get-p-receiver-EnsureDeferredNamespaceEvaluation +description: > + Modules cannot try to trigger evaluation of modules that are in their ~evaluating-async~ phase +info: | + 10.4.6.8 [[Get]] ( _P_, _Receiver_ ) + 1. ... + 1. If _O_.[[Deferred]] is **true**, perform ? EnsureDeferredNamespaceEvaluation(_O_). + 1. ... + + EnsureDeferredNamespaceEvaluation ( _O_ ) + 1. Assert: _O_.[[Deferred]] is *false*. + 1. Let _m_ be _O_.[[Module]]. + 1. If _m_ is a Cyclic Module Record, _m_.[[Status]] is not ~evaluated~, and ReadyForSyncExecution(_m_) is *false*, throw a *TypeError* exception. + 1. ... + + ReadyForSyncExecution( _module_, _seen_ ) + 1. If _seen_ is not provided, let _seen_ be a new empty List. + 1. If _seen_ contains _module_, return *true*. + 1. Append _module_ to _seen_. + 1. If _module_.[[Status]] is ~evaluated~, return *true*. + 1. If _module_.[[Status]] is ~evaluating~ or ~evaluating-async~, return *false*. + 1. Assert: _module_.[[Status]] is ~linked~. + 1. If _module_.[[HasTLA]] is *true*, return *false*. + 1. For each ModuleRequest Record _required_ of _module_.[[RequestedModules]], do + 1. Let _requiredModule_ be GetImportedModule(_module_, _required_.[[Specifier]]). + 1. If ReadyForSyncExecution(_requiredModule_, _seen_) is *false*, then + 1. Return *false*. + 1. Return *true*. + +flags: [module, async] +features: [import-defer, top-level-await] +---*/ + +import { done } from "./promises_FIXTURE.js"; +import "./dep-1-tla_FIXTURE.js"; + +done.then($DONE, $DONE); diff --git a/test/language/import/import-defer/errors/get-other-while-evaluating-async/promises_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-evaluating-async/promises_FIXTURE.js new file mode 100644 index 00000000000..a54c20ffa56 --- /dev/null +++ b/test/language/import/import-defer/errors/get-other-while-evaluating-async/promises_FIXTURE.js @@ -0,0 +1,14 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export let resolveDone, rejectDone; +export const done = new Promise((r, j) => (resolveDone = r, rejecteDone = j)); + +export let resolveFirst, rejectFirst; +export const first = new Promise((r, j) => (resolveFirst = r, rejectFirst = j)); + +export let resolveSecond, rejectSecond; +export const second = new Promise((r, j) => (resolveSecond = r, rejectSecond = j)); + +export let resolveThird, rejectThird; +export const third = new Promise((r, j) => (resolveThird = r, rejectThird = j)); diff --git a/test/language/import/import-defer/errors/get-self-while-evaluating-async/dep_FIXTURE.js b/test/language/import/import-defer/errors/get-self-while-evaluating-async/dep_FIXTURE.js new file mode 100644 index 00000000000..7b75a749cc4 --- /dev/null +++ b/test/language/import/import-defer/errors/get-self-while-evaluating-async/dep_FIXTURE.js @@ -0,0 +1,8 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import defer * as ns from "./dep_FIXTURE.js"; + +await Promise.resolve(0); + +assert.throws(TypeError, () => ns.foo); diff --git a/test/language/import/import-defer/errors/get-self-while-evaluating-async/main.js b/test/language/import/import-defer/errors/get-self-while-evaluating-async/main.js new file mode 100644 index 00000000000..7d2ecef6d7b --- /dev/null +++ b/test/language/import/import-defer/errors/get-self-while-evaluating-async/main.js @@ -0,0 +1,36 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-module-namespace-exotic-objects-get-p-receiver-EnsureDeferredNamespaceEvaluation +description: > + Modules cannot try to trigger their own evaluation +info: | + 10.4.6.8 [[Get]] ( _P_, _Receiver_ ) + 1. ... + 1. If _O_.[[Deferred]] is **true**, perform ? EnsureDeferredNamespaceEvaluation(_O_). + 1. ... + + EnsureDeferredNamespaceEvaluation ( _O_ ) + 1. Assert: _O_.[[Deferred]] is *false*. + 1. Let _m_ be _O_.[[Module]]. + 1. If _m_ is a Cyclic Module Record, _m_.[[Status]] is not ~evaluated~, and ReadyForSyncExecution(_m_) is *false*, throw a *TypeError* exception. + 1. ... + + ReadyForSyncExecution( _module_, _seen_ ) + 1. If _seen_ is not provided, let _seen_ be a new empty List. + 1. If _seen_ contains _module_, return *true*. + 1. Append _module_ to _seen_. + 1. If _module_.[[Status]] is ~evaluated~, return *true*. + 1. If _module_.[[Status]] is ~evaluating~ or ~evaluating-async~, return *false*. + 1. ... + +flags: [module, async] +features: [import-defer, top-level-await] +---*/ + +import defer * as ns from "./dep_FIXTURE.js"; + +ns.foo; + +$DONE(); diff --git a/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-1_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-1_FIXTURE.js new file mode 100644 index 00000000000..1b2d700252c --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-1_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +globalThis.evaluations.push("1"); diff --git a/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.1.1-tla_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.1.1-tla_FIXTURE.js new file mode 100644 index 00000000000..092c022fed0 --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.1.1-tla_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +globalThis.evaluations.push("2.1.1"); diff --git a/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.1_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.1_FIXTURE.js new file mode 100644 index 00000000000..69b1c69da05 --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.1_FIXTURE.js @@ -0,0 +1,6 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import "./dep-2.1.1-tla_FIXTURE.js"; + +globalThis.evaluations.push("2.1"); diff --git a/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.2-tla_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.2-tla_FIXTURE.js new file mode 100644 index 00000000000..5190e547416 --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.2-tla_FIXTURE.js @@ -0,0 +1,10 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import "./dep-2.2.1_FIXTURE.js" + +globalThis.evaluations.push("2.2 start"); + +await Promise.resolve(0); + +globalThis.evaluations.push("2.2 end"); diff --git a/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.2.1_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.2.1_FIXTURE.js new file mode 100644 index 00000000000..9161bb58280 --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.2.1_FIXTURE.js @@ -0,0 +1,8 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +globalThis.evaluations.push("2.2 start"); + +await Promise.resolve(0); + +globalThis.evaluations.push("2.2 end"); diff --git a/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2_FIXTURE.js new file mode 100644 index 00000000000..c449575557d --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2_FIXTURE.js @@ -0,0 +1,7 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import "./dep-2.1_FIXTURE.js"; +import "./dep-2.2-tla_FIXTURE.js"; + +globalThis.evaluations.push("2"); diff --git a/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-3_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-3_FIXTURE.js new file mode 100644 index 00000000000..7517381157d --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-3_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +globalThis.evaluations.push("3"); diff --git a/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-4.1-tla_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-4.1-tla_FIXTURE.js new file mode 100644 index 00000000000..5b17bff7590 --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-4.1-tla_FIXTURE.js @@ -0,0 +1,10 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import "./dep-2.2-tla_FIXTURE.js"; + +globalThis.evaluations.push("4.1 start"); + +await Promise.resolve(0); + +globalThis.evaluations.push("4.1 end"); diff --git a/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-4_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-4_FIXTURE.js new file mode 100644 index 00000000000..9c2219483a7 --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-4_FIXTURE.js @@ -0,0 +1,6 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import "./dep-4.1-tla_FIXTURE.js"; + +globalThis.evaluations.push("4"); diff --git a/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-5_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-5_FIXTURE.js new file mode 100644 index 00000000000..3c62ffc84cc --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-5_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +globalThis.evaluations.push("5"); diff --git a/test/language/import/import-defer/evaluation-top-level-await/flattening-order/main.js b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/main.js new file mode 100644 index 00000000000..18384857832 --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/main.js @@ -0,0 +1,76 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-innermoduleevaluation +description: > + Async dependencies of deferred modules are executed in the right order +info: | + 16.2.1.5.3.1 InnerModuleEvaluation ( _module_, _stack_, _index_ ) + 1. ... + 1. Let _evaluationList_ be a new empty List. + 1. For each ModuleRequest Record _required_ of _module_.[[RequestedModules]], do + 1. Let _requiredModule_ be GetImportedModule(_module_, _required_.[[Specifier]]). + 1. If _required_.[[Phase]] is ~defer~, then + i. Let _additionalModules_ be GatherAsynchronousTransitiveDependencies(_requiredModule_). + ii. For each Module Record _additionalModule_ of _additionalModules_, do + 1. If _evaluationList_ does not contain _additionalModule_, then + a. Append _additionalModule_ to _evaluationList_. + 1. Else if _evaluationList_ does not contain _requiredModule_, then + i. Append _requiredModule_ to _evaluationList_. + 1. ... + 1. For each Module Record _requiredModule_ of _evaluationList_, do + 1. Set _index_ to ? InnerModuleEvaluation(_requiredModule_, _stack_, _index_). + 1. ... + + GatherAsynchronousTransitiveDependencies ( _module_, [ _seen_ ] ) + 1. If _seen_ is not specified, let _seen_ be a new empty List. + 1. Let _result_ be a new empty List. + 1. If _seen_ contains _module_, return _result_. + 1. Append _module_ to _seen_. + 1. If _module_ is not a Cyclic Module Record, return _result_. + 1. If _module_.[[Status]] is either ~evaluating~ or ~evaluated~, return _result_. + 1. If _module_.[[HasTLA]] is *true*, then + 1. Append _module_ to _result_. + 1. Return _result_. + 1. For each ModuleRequest Record _required_ of _module_.[[RequestedModules]], do + 1. Let _requiredModule_ be GetImportedModule(_module_, _required_.[[Specifier]]). + 1. Let _additionalModules_ be GatherAsynchronousTransitiveDependencies(_requiredModule_, _seen_). + 1. For each Module Record _m_ of _additionalModules_, do + 1. If _result_ does not contain _m_, append _m_ to _result_. + 1. Return _result_. + +flags: [module, async] +features: [import-defer, top-level-await] +---*/ + +import "../setup_FIXTURE.js"; + +import "./dep-1.js"; +import defer * as ns2 from "./dep-2.js"; +import "./dep-3.js"; +import defer * as ns4 from "./dep-4.js"; +import "./dep-5.js"; + +assert.deepEqual(globalThis.evaluations, [ + "1", + "2.1.1 start", + "2.2.1", + "2.2 start", + "3", + "5", + "2.1.1 end", + "2.2 end", + "4.1 start", + "4.1 end" +]); + +globalThis.evaluations = []; +ns2.x; +assert.deepEqual(globalThis.evaluations, ["2.1", "2"]); + +globalThis.evaluations = []; +ns4.x; +assert.deepEqual(globalThis.evaluations, ["4"]); + +$DONE(); diff --git a/test/language/import/import-defer/evaluation-top-level-await/import-defer-async-module/main.js b/test/language/import/import-defer/evaluation-top-level-await/import-defer-async-module/main.js new file mode 100644 index 00000000000..c4593df6928 --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/import-defer-async-module/main.js @@ -0,0 +1,54 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-innermoduleevaluation +description: > + `import defer` causes eager evaluation of dependencies with top-level await +info: | + 16.2.1.5.3.1 InnerModuleEvaluation ( _module_, _stack_, _index_ ) + 1. ... + 1. Let _evaluationList_ be a new empty List. + 1. For each ModuleRequest Record _required_ of _module_.[[RequestedModules]], do + 1. Let _requiredModule_ be GetImportedModule(_module_, _required_.[[Specifier]]). + 1. If _required_.[[Phase]] is ~defer~, then + i. Let _additionalModules_ be GatherAsynchronousTransitiveDependencies(_requiredModule_). + ii. For each Module Record _additionalModule_ of _additionalModules_, do + 1. If _evaluationList_ does not contain _additionalModule_, then + a. Append _additionalModule_ to _evaluationList_. + 1. Else if _evaluationList_ does not contain _requiredModule_, then + i. Append _requiredModule_ to _evaluationList_. + 1. ... + 1. For each Module Record _requiredModule_ of _evaluationList_, do + 1. Set _index_ to ? InnerModuleEvaluation(_requiredModule_, _stack_, _index_). + 1. ... + + GatherAsynchronousTransitiveDependencies ( _module_, [ _seen_ ] ) + 1. If _seen_ is not specified, let _seen_ be a new empty List. + 1. Let _result_ be a new empty List. + 1. If _seen_ contains _module_, return _result_. + 1. Append _module_ to _seen_. + 1. If _module_ is not a Cyclic Module Record, return _result_. + 1. If _module_.[[Status]] is either ~evaluating~ or ~evaluated~, return _result_. + 1. If _module_.[[HasTLA]] is *true*, then + 1. Append _module_ to _result_. + 1. Return _result_. + 1. For each ModuleRequest Record _required_ of _module_.[[RequestedModules]], do + 1. Let _requiredModule_ be GetImportedModule(_module_, _required_.[[Specifier]]). + 1. Let _additionalModules_ be GatherAsynchronousTransitiveDependencies(_requiredModule_, _seen_). + 1. For each Module Record _m_ of _additionalModules_, do + 1. If _result_ does not contain _m_, append _m_ to _result_. + 1. Return _result_. + +flags: [module, async] +features: [import-defer, top-level-await] +---*/ + +import "../setup_FIXTURE.js"; +import defer * as ns from "./tla_FIXTURE.js"; + +assert.deepEqual(globalThis.evaluations, ["tla start", "tla end"]); +ns.x; +assert.deepEqual(globalThis.evaluations, ["tla start", "tla end"]); + +$DONE(); diff --git a/test/language/import/import-defer/evaluation-top-level-await/import-defer-async-module/tla_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/import-defer-async-module/tla_FIXTURE.js new file mode 100644 index 00000000000..f6a330837fe --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/import-defer-async-module/tla_FIXTURE.js @@ -0,0 +1,8 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +globalThis.evaluations.push("tla start"); + +await Promise.resolve(0); + +globalThis.evaluations.push("tla end"); diff --git a/test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/imports-tla_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/imports-tla_FIXTURE.js new file mode 100644 index 00000000000..cb87e3fbe32 --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/imports-tla_FIXTURE.js @@ -0,0 +1,6 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import "./tla_FIXTURE.js"; + +globalThis.evaluations.push("imports-tla"); diff --git a/test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/main.js b/test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/main.js new file mode 100644 index 00000000000..1283e8c82c0 --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/main.js @@ -0,0 +1,54 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-innermoduleevaluation +description: > + `import defer` causes eager evaluation of transitive dependencies with top-level await +info: | + 16.2.1.5.3.1 InnerModuleEvaluation ( _module_, _stack_, _index_ ) + 1. ... + 1. Let _evaluationList_ be a new empty List. + 1. For each ModuleRequest Record _required_ of _module_.[[RequestedModules]], do + 1. Let _requiredModule_ be GetImportedModule(_module_, _required_.[[Specifier]]). + 1. If _required_.[[Phase]] is ~defer~, then + i. Let _additionalModules_ be GatherAsynchronousTransitiveDependencies(_requiredModule_). + ii. For each Module Record _additionalModule_ of _additionalModules_, do + 1. If _evaluationList_ does not contain _additionalModule_, then + a. Append _additionalModule_ to _evaluationList_. + 1. Else if _evaluationList_ does not contain _requiredModule_, then + i. Append _requiredModule_ to _evaluationList_. + 1. ... + 1. For each Module Record _requiredModule_ of _evaluationList_, do + 1. Set _index_ to ? InnerModuleEvaluation(_requiredModule_, _stack_, _index_). + 1. ... + + GatherAsynchronousTransitiveDependencies ( _module_, [ _seen_ ] ) + 1. If _seen_ is not specified, let _seen_ be a new empty List. + 1. Let _result_ be a new empty List. + 1. If _seen_ contains _module_, return _result_. + 1. Append _module_ to _seen_. + 1. If _module_ is not a Cyclic Module Record, return _result_. + 1. If _module_.[[Status]] is either ~evaluating~ or ~evaluated~, return _result_. + 1. If _module_.[[HasTLA]] is *true*, then + 1. Append _module_ to _result_. + 1. Return _result_. + 1. For each ModuleRequest Record _required_ of _module_.[[RequestedModules]], do + 1. Let _requiredModule_ be GetImportedModule(_module_, _required_.[[Specifier]]). + 1. Let _additionalModules_ be GatherAsynchronousTransitiveDependencies(_requiredModule_, _seen_). + 1. For each Module Record _m_ of _additionalModules_, do + 1. If _result_ does not contain _m_, append _m_ to _result_. + 1. Return _result_. + +flags: [module, async] +features: [import-defer, top-level-await] +---*/ + +import "../setup_FIXTURE.js"; +import defer * as ns "./imports-tla_FIXTURE.js"; + +assert.deepEqual(globalThis.evaluations, ["tla start", "tla end"]); +ns.x; +assert.deepEqual(globalThis.evaluations, ["imports-dla"]); + +$DONE(); diff --git a/test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/tla_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/tla_FIXTURE.js new file mode 100644 index 00000000000..f6a330837fe --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/tla_FIXTURE.js @@ -0,0 +1,8 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +globalThis.evaluations.push("tla start"); + +await Promise.resolve(0); + +globalThis.evaluations.push("tla end"); diff --git a/test/language/import/import-defer/evaluation-top-level-await/setup_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/setup_FIXTURE.js new file mode 100644 index 00000000000..d71b2fa95eb --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/setup_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +globalThis.evaluations = []; diff --git a/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/dep_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/dep_FIXTURE.js new file mode 100644 index 00000000000..6d225a3c545 --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/dep_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +globalThis.evaluations.push("dep start"); diff --git a/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/imports-tla-with-dep_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/imports-tla-with-dep_FIXTURE.js new file mode 100644 index 00000000000..0c4e34d0c61 --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/imports-tla-with-dep_FIXTURE.js @@ -0,0 +1,6 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import "./tla-with-dep_FIXTURE.js"; + +globalThis.evaluations.push("imports-tla-with-dep"); diff --git a/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/main.js b/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/main.js new file mode 100644 index 00000000000..c861a7ef54f --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/main.js @@ -0,0 +1,60 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-innermoduleevaluation +description: > + `import defer` causes eager evaluation of synchronous dependencies of async dependencies +info: | + 16.2.1.5.3.1 InnerModuleEvaluation ( _module_, _stack_, _index_ ) + 1. ... + 1. Let _evaluationList_ be a new empty List. + 1. For each ModuleRequest Record _required_ of _module_.[[RequestedModules]], do + 1. Let _requiredModule_ be GetImportedModule(_module_, _required_.[[Specifier]]). + 1. If _required_.[[Phase]] is ~defer~, then + i. Let _additionalModules_ be GatherAsynchronousTransitiveDependencies(_requiredModule_). + ii. For each Module Record _additionalModule_ of _additionalModules_, do + 1. If _evaluationList_ does not contain _additionalModule_, then + a. Append _additionalModule_ to _evaluationList_. + 1. Else if _evaluationList_ does not contain _requiredModule_, then + i. Append _requiredModule_ to _evaluationList_. + 1. ... + 1. For each Module Record _requiredModule_ of _evaluationList_, do + 1. Set _index_ to ? InnerModuleEvaluation(_requiredModule_, _stack_, _index_). + 1. ... + + GatherAsynchronousTransitiveDependencies ( _module_, [ _seen_ ] ) + 1. If _seen_ is not specified, let _seen_ be a new empty List. + 1. Let _result_ be a new empty List. + 1. If _seen_ contains _module_, return _result_. + 1. Append _module_ to _seen_. + 1. If _module_ is not a Cyclic Module Record, return _result_. + 1. If _module_.[[Status]] is either ~evaluating~ or ~evaluated~, return _result_. + 1. If _module_.[[HasTLA]] is *true*, then + 1. Append _module_ to _result_. + 1. Return _result_. + 1. For each ModuleRequest Record _required_ of _module_.[[RequestedModules]], do + 1. Let _requiredModule_ be GetImportedModule(_module_, _required_.[[Specifier]]). + 1. Let _additionalModules_ be GatherAsynchronousTransitiveDependencies(_requiredModule_, _seen_). + 1. For each Module Record _m_ of _additionalModules_, do + 1. If _result_ does not contain _m_, append _m_ to _result_. + 1. Return _result_. + +flags: [module, async] +features: [import-defer, top-level-await] +---*/ + +import "../setup_FIXTURE.js"; +import defer * as ns from "./imports-tla-with-dep_FIXTURE.js"; + +assert.deepEqual( + globalThis.evaluations, + ["dep", "tla-with-dep start", "tla-with-dep end"] +); +ns.x; +assert.deepEqual( + globalThis.evaluations, + ["dep", "tla-with-dep start", "tla-with-dep end", "imports-tla-with-dep"] +); + +$DONE(); diff --git a/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/tla-with-dep_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/tla-with-dep_FIXTURE.js new file mode 100644 index 00000000000..fe6946f0e05 --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/tla-with-dep_FIXTURE.js @@ -0,0 +1,10 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import "./dep_FIXTURE.js"; + +globalThis.evaluations.push("tla-with-dep start"); + +await Promise.resolve(0); + +globalThis.evaluations.push("tla-with-dep end"); From d5ea87ee52e12d713e0ab4bd518c5eb861af13ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 31 Oct 2024 12:21:49 +0100 Subject: [PATCH 04/13] Use better assertion functions --- .../deferred-namespace-object/identity.js | 8 ++++---- .../object-properties.js | 18 +++++++++--------- .../dep-1.1_FIXTURE.js | 2 +- .../dep-1_FIXTURE.js | 2 +- .../dep-1.1_FIXTURE.js | 2 +- .../evaluation-ignore-get-symbol.js | 4 ++-- .../evaluation-ignore-getPrototypeOf.js | 4 ++-- .../evaluation-ignore-isExtensible.js | 4 ++-- .../evaluation-ignore-preventExtensions.js | 4 ++-- .../evaluation-sync/evaluation-ignore-set.js | 4 ++-- .../evaluation-ignore-setPrototypeOf.js | 4 ++-- .../evaluation-trigger-get-string.js | 2 +- .../import-defer-does-not-evaluate.js | 10 +++++----- .../module-imported-defer-and-eager.js | 4 ++-- .../flattening-order/main.js | 7 ++++--- .../import-defer-async-module/main.js | 5 +++-- .../main.js | 5 +++-- .../main.js | 5 +++-- 18 files changed, 49 insertions(+), 45 deletions(-) diff --git a/test/language/import/import-defer/deferred-namespace-object/identity.js b/test/language/import/import-defer/deferred-namespace-object/identity.js index 519c96dd84f..0df6955233c 100644 --- a/test/language/import/import-defer/deferred-namespace-object/identity.js +++ b/test/language/import/import-defer/deferred-namespace-object/identity.js @@ -37,7 +37,7 @@ import defer * as nsDeferred2 from "./dep_FIXTURE.js"; import { depDeferredNamespace as nsDeferred3 } from "./dep-defer-ns_FIXTURE.js"; const nsDeferred4 = await import.defer("./dep_FIXTURE.js"); -assert(nsDeferred1 === nsDeferred2, "Deferred import of the same module twice gives the same object"); -assert(nsDeferred1 === nsDeferred3, "Deferred import of the same module twice from different files gives the same object"); -assert(nsDeferred1 === nsDeferred4, "Static and dynamic deferred import of the same module gives the same object"); -assert(nsDeferred1 !== nsEager, "Deferred namespaces are distinct from eager namespaces"); +assert.sameValue(nsDeferred1, nsDeferred2, "Deferred import of the same module twice gives the same object"); +assert.sameValue(nsDeferred1, nsDeferred3, "Deferred import of the same module twice from different files gives the same object"); +assert.sameValue(nsDeferred1, nsDeferred4, "Static and dynamic deferred import of the same module gives the same object"); +assert.notSameValue(nsDeferred1, nsEager, "Deferred namespaces are distinct from eager namespaces"); diff --git a/test/language/import/import-defer/deferred-namespace-object/object-properties.js b/test/language/import/import-defer/deferred-namespace-object/object-properties.js index ad8b7280f0c..1167e623ad9 100644 --- a/test/language/import/import-defer/deferred-namespace-object/object-properties.js +++ b/test/language/import/import-defer/deferred-namespace-object/object-properties.js @@ -20,24 +20,24 @@ info: | flags: [module] features: [import-defer] -includes: [propertyHelper.js, deepEqual.js] +includes: [propertyHelper.js, compareArray.js] ---*/ import defer * as ns from "./dep_FIXTURE.js"; -assert(typeof ns === "object", "Deferred namespaces are objects"); +assert.sameValue(typeof ns, "object", "Deferred namespaces are objects"); -assert(Reflect.isExtensible(ns) === false, "Deferred namespaces are not extensible"); -assert(Reflect.preventExtensions(ns) === true, "Deferred namespaces can made non-extensible"); +assert(!Reflect.isExtensible(ns), "Deferred namespaces are not extensible"); +assert.sameValue(Reflect.preventExtensions(ns), true, "Deferred namespaces can made non-extensible"); -assert(Reflect.getPrototypeOf(ns) === null, "Deferred namespaces have a null prototype"); -assert(Reflect.setPrototypeOf(ns, {}) === false, "Deferred namespaces' prototype cannot be changed"); -assert(Reflect.setPrototypeOf(ns, null) === true, "Deferred namespaces' prototype can be 'set' to null"); +assert.sameValue(Reflect.getPrototypeOf(ns), null, "Deferred namespaces have a null prototype"); +assert.sameValue(Reflect.setPrototypeOf(ns, {}), false, "Deferred namespaces' prototype cannot be changed"); +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.deepEqual( +assert.compareArray( Reflect.ownKeys(ns), ["bar", "foo", Symbol.toStringTag], "Deferred namespaces' keys are the exports sorted alphabetically, followed by @@toStringTag" @@ -49,4 +49,4 @@ verifyProperty(ns, "foo", { enumerable: true, configurable: false, }); -assert(Reflect.getOwnPropertyDescriptor(ns, "non-existent") === undefined, "No descriptors for non-exports"); +assert.sameValue(Reflect.getOwnPropertyDescriptor(ns, "non-existent"), undefined, "No descriptors for non-exports"); diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1.1_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1.1_FIXTURE.js index d5a678d1241..d6a6b311a48 100644 --- a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1.1_FIXTURE.js +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1.1_FIXTURE.js @@ -14,6 +14,6 @@ first.then(() => { return third.then(() => { // dep-1 is now in the ~evaluated~ state let foo = ns.foo; - assert(foo === 1, "Once it finished evaluating, the module can be accessed"); + assert.sameValue(foo, 1, "Once it finished evaluating, the module can be accessed"); }) }).then(resolveDone, rejectDone); diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-1_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-1_FIXTURE.js index b3c639aeffb..e99a1cdf614 100644 --- a/test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-1_FIXTURE.js +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-1_FIXTURE.js @@ -5,4 +5,4 @@ import defer * as dep2 from "./dep-2_FIXTURE.js"; globalThis.dep3evaluated = false; assert.throws(TypeError, () => dep2.foo); -assert(globalThis.dep3evaluated === false, "the 'evaluable' dependencies of dep-2 are not evaluated"); +assert.sameValue(globalThis.dep3evaluated, false, "the 'evaluable' dependencies of dep-2 are not evaluated"); diff --git a/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1.1_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1.1_FIXTURE.js index 4acd5b51c7e..886b663c851 100644 --- a/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1.1_FIXTURE.js +++ b/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1.1_FIXTURE.js @@ -14,6 +14,6 @@ first.then(() => { return third.then(() => { // ns is now in the ~evaluated~ state let foo = ns.foo; - assert(foo === 1, "Once it finished evaluating, the module can be accessed"); + assert.sameValue(foo, 1, "Once it finished evaluating, the module can be accessed"); }) }).then(resolveDone, rejectDone); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-get-symbol.js b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-get-symbol.js index e8ed9700c1b..c7588800e4c 100644 --- a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-get-symbol.js +++ b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-get-symbol.js @@ -20,9 +20,9 @@ import "./setup_FIXTURE.js"; import defer * as ns1 from "./dep-1_FIXTURE.js"; -assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); +assert.sameValue(globalThis.evaluations.length, 0, "import defer does not trigger evaluation"); ns1[Symbol.toStringTag]; ns1[Symbol()]; -assert(globalThis.evaluations.length === 0, "[[Get]] of a symbol does not trigger evaluation"); +assert.sameValue(globalThis.evaluations.length, 0, "[[Get]] of a symbol does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-getPrototypeOf.js b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-getPrototypeOf.js index c36ac7c5fcc..4cd7224c55d 100644 --- a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-getPrototypeOf.js +++ b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-getPrototypeOf.js @@ -17,8 +17,8 @@ import "./setup_FIXTURE.js"; import defer * as ns1 from "./dep-1_FIXTURE.js"; -assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); +assert.sameValue(globalThis.evaluations.length, 0, "import defer does not trigger evaluation"); Object.getPrototypeOf(ns1); -assert(globalThis.evaluations.length === 0, "[[GetPrototypeOf]] does not trigger evaluation"); +assert.sameValue(globalThis.evaluations.length, 0, "[[GetPrototypeOf]] does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-isExtensible.js b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-isExtensible.js index ff815565c76..49e3d67ee4b 100644 --- a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-isExtensible.js +++ b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-isExtensible.js @@ -17,8 +17,8 @@ import "./setup_FIXTURE.js"; import defer * as ns1 from "./dep-1_FIXTURE.js"; -assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); +assert.sameValue(globalThis.evaluations.length, 0, "import defer does not trigger evaluation"); Object.isExtensible(ns1); -assert(globalThis.evaluations.length === 0, "[[GetPrototypeOf]] does not trigger evaluation"); +assert.sameValue(globalThis.evaluations.length, 0, "[[GetPrototypeOf]] does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-preventExtensions.js b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-preventExtensions.js index 5ceb8b3a804..36463c43f34 100644 --- a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-preventExtensions.js +++ b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-preventExtensions.js @@ -17,8 +17,8 @@ import "./setup_FIXTURE.js"; import defer * as ns1 from "./dep-1_FIXTURE.js"; -assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); +assert.sameValue(globalThis.evaluations.length, 0, "import defer does not trigger evaluation"); Object.preventExtensions(ns1); -assert(globalThis.evaluations.length === 0, "[[GetPrototypeOf]] does not trigger evaluation"); +assert.sameValue(globalThis.evaluations.length, 0, "[[GetPrototypeOf]] does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-set.js b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-set.js index 738a53b747b..e2416db5bbc 100644 --- a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-set.js +++ b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-set.js @@ -17,7 +17,7 @@ import "./setup_FIXTURE.js"; import defer * as ns1 from "./dep-1_FIXTURE.js"; -assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); +assert.sameValue(globalThis.evaluations.length, 0, "import defer does not trigger evaluation"); try { ns1.foo = 2; @@ -26,4 +26,4 @@ try { ns1.ns_1_2 = 3; } catch {} -assert(globalThis.evaluations.length === 0, "[[Set]] of a symbol does not trigger evaluation"); +assert.sameValue(globalThis.evaluations.length, 0, "[[Set]] of a symbol does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-setPrototypeOf.js b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-setPrototypeOf.js index a0953218df5..fcbb3e0739e 100644 --- a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-setPrototypeOf.js +++ b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-setPrototypeOf.js @@ -17,9 +17,9 @@ import "./setup_FIXTURE.js"; import defer * as ns1 from "./dep-1_FIXTURE.js"; -assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); +assert.sameValue(globalThis.evaluations.length, 0, "import defer does not trigger evaluation"); Reflect.setPrototypeOf(ns1, null); Reflect.setPrototypeOf(ns1, {}); -assert(globalThis.evaluations.length === 0, "[[GetPrototypeOf]] does not trigger evaluation"); +assert.sameValue(globalThis.evaluations.length, 0, "[[GetPrototypeOf]] does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-trigger-get-string.js b/test/language/import/import-defer/evaluation-sync/evaluation-trigger-get-string.js index 528851ba2ab..21e82b4182f 100644 --- a/test/language/import/import-defer/evaluation-sync/evaluation-trigger-get-string.js +++ b/test/language/import/import-defer/evaluation-sync/evaluation-trigger-get-string.js @@ -20,7 +20,7 @@ import "./setup_FIXTURE.js"; import defer * as ns1 from "./dep-1_FIXTURE.js"; -assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); +assert.sameValue(globalThis.evaluations.length, 0, "import defer does not trigger evaluation"); ns1.foo; diff --git a/test/language/import/import-defer/evaluation-sync/import-defer-does-not-evaluate.js b/test/language/import/import-defer/evaluation-sync/import-defer-does-not-evaluate.js index bb49ef0938e..3afade5801d 100644 --- a/test/language/import/import-defer/evaluation-sync/import-defer-does-not-evaluate.js +++ b/test/language/import/import-defer/evaluation-sync/import-defer-does-not-evaluate.js @@ -25,23 +25,23 @@ info: | flags: [module] features: [import-defer] -includes: [deepEqual.js] +includes: [compareArray.js] ---*/ import "./setup_FIXTURE.js"; import defer * as ns1 from "./dep-1_FIXTURE.js"; -assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation"); +assert.sameValue(globalThis.evaluations.length, 0, "import defer does not trigger evaluation"); const ns_1_2 = ns1.ns_1_2; -assert.deepEqual(globalThis.evaluations, [1.1, 1], "when evaluation is triggered, deferred sub-dependencies are not evaluated"); +assert.compareArray(globalThis.evaluations, [1.1, 1], "when evaluation is triggered, deferred sub-dependencies are not evaluated"); ns1.ns_1_2; -assert.deepEqual(globalThis.evaluations, [1.1, 1], "the module is not re-executed"); +assert.compareArray(globalThis.evaluations, [1.1, 1], "the module is not re-executed"); ns_1_2.foo; -assert.deepEqual(globalThis.evaluations, [1.1, 1, 1.2]); +assert.compareArray(globalThis.evaluations, [1.1, 1, 1.2]); diff --git a/test/language/import/import-defer/evaluation-sync/module-imported-defer-and-eager.js b/test/language/import/import-defer/evaluation-sync/module-imported-defer-and-eager.js index 53552052e3b..a22df19ed29 100644 --- a/test/language/import/import-defer/evaluation-sync/module-imported-defer-and-eager.js +++ b/test/language/import/import-defer/evaluation-sync/module-imported-defer-and-eager.js @@ -39,7 +39,7 @@ info: | flags: [module] features: [import-defer] -includes: [deepEqual.js] +includes: [compareArray.js] ---*/ import "./setup_FIXTURE.js"; @@ -48,4 +48,4 @@ import defer * as ns1 from "./dep-1_FIXTURE.js"; import "./dep-2_FIXTURE.js"; import "./dep-1_FIXTURE.js"; -assert.deepEqual(globalThis.evaluations, [2, 1.1, 1], "the module is evaluated in the order where it's imported as non-deferred"); +assert.compareArray(globalThis.evaluations, [2, 1.1, 1], "the module is evaluated in the order where it's imported as non-deferred"); diff --git a/test/language/import/import-defer/evaluation-top-level-await/flattening-order/main.js b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/main.js index 18384857832..05a97121a00 100644 --- a/test/language/import/import-defer/evaluation-top-level-await/flattening-order/main.js +++ b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/main.js @@ -42,6 +42,7 @@ info: | flags: [module, async] features: [import-defer, top-level-await] +includes: [compareArray.js] ---*/ import "../setup_FIXTURE.js"; @@ -52,7 +53,7 @@ import "./dep-3.js"; import defer * as ns4 from "./dep-4.js"; import "./dep-5.js"; -assert.deepEqual(globalThis.evaluations, [ +assert.compareArray(globalThis.evaluations, [ "1", "2.1.1 start", "2.2.1", @@ -67,10 +68,10 @@ assert.deepEqual(globalThis.evaluations, [ globalThis.evaluations = []; ns2.x; -assert.deepEqual(globalThis.evaluations, ["2.1", "2"]); +assert.compareArray(globalThis.evaluations, ["2.1", "2"]); globalThis.evaluations = []; ns4.x; -assert.deepEqual(globalThis.evaluations, ["4"]); +assert.compareArray(globalThis.evaluations, ["4"]); $DONE(); diff --git a/test/language/import/import-defer/evaluation-top-level-await/import-defer-async-module/main.js b/test/language/import/import-defer/evaluation-top-level-await/import-defer-async-module/main.js index c4593df6928..2809c173721 100644 --- a/test/language/import/import-defer/evaluation-top-level-await/import-defer-async-module/main.js +++ b/test/language/import/import-defer/evaluation-top-level-await/import-defer-async-module/main.js @@ -42,13 +42,14 @@ info: | flags: [module, async] features: [import-defer, top-level-await] +includes: [compareArray.js] ---*/ import "../setup_FIXTURE.js"; import defer * as ns from "./tla_FIXTURE.js"; -assert.deepEqual(globalThis.evaluations, ["tla start", "tla end"]); +assert.compareArray(globalThis.evaluations, ["tla start", "tla end"]); ns.x; -assert.deepEqual(globalThis.evaluations, ["tla start", "tla end"]); +assert.compareArray(globalThis.evaluations, ["tla start", "tla end"]); $DONE(); diff --git a/test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/main.js b/test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/main.js index 1283e8c82c0..4fab87d391d 100644 --- a/test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/main.js +++ b/test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/main.js @@ -42,13 +42,14 @@ info: | flags: [module, async] features: [import-defer, top-level-await] +includes: [compareArray.js] ---*/ import "../setup_FIXTURE.js"; import defer * as ns "./imports-tla_FIXTURE.js"; -assert.deepEqual(globalThis.evaluations, ["tla start", "tla end"]); +assert.compareArray(globalThis.evaluations, ["tla start", "tla end"]); ns.x; -assert.deepEqual(globalThis.evaluations, ["imports-dla"]); +assert.compareArray(globalThis.evaluations, ["imports-dla"]); $DONE(); diff --git a/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/main.js b/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/main.js index c861a7ef54f..a27a49a16c5 100644 --- a/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/main.js +++ b/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/main.js @@ -42,17 +42,18 @@ info: | flags: [module, async] features: [import-defer, top-level-await] +includes: [compareArray.js] ---*/ import "../setup_FIXTURE.js"; import defer * as ns from "./imports-tla-with-dep_FIXTURE.js"; -assert.deepEqual( +assert.compareArray( globalThis.evaluations, ["dep", "tla-with-dep start", "tla-with-dep end"] ); ns.x; -assert.deepEqual( +assert.compareArray( globalThis.evaluations, ["dep", "tla-with-dep start", "tla-with-dep end", "imports-tla-with-dep"] ); From fe7a185bb63126978996bcc7aa06feffc341b8a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 31 Oct 2024 12:22:44 +0100 Subject: [PATCH 05/13] Remove `copy` from filename --- ...d-namespace copy.js => invalid-defer-default-and-namespace.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/language/import/import-defer/syntax/{invalid-defer-default-and-namespace copy.js => invalid-defer-default-and-namespace.js} (100%) diff --git a/test/language/import/import-defer/syntax/invalid-defer-default-and-namespace copy.js b/test/language/import/import-defer/syntax/invalid-defer-default-and-namespace.js similarity index 100% rename from test/language/import/import-defer/syntax/invalid-defer-default-and-namespace copy.js rename to test/language/import/import-defer/syntax/invalid-defer-default-and-namespace.js From fe5db3cb73d60aeb846fefbe195c4feeca675f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 31 Oct 2024 12:25:49 +0100 Subject: [PATCH 06/13] Fix wrong descriptions --- .../import-defer/deferred-namespace-object/object-properties.js | 2 +- .../import-defer/errors/get-other-while-evaluating/main.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/language/import/import-defer/deferred-namespace-object/object-properties.js b/test/language/import/import-defer/deferred-namespace-object/object-properties.js index 1167e623ad9..4274b6e1708 100644 --- a/test/language/import/import-defer/deferred-namespace-object/object-properties.js +++ b/test/language/import/import-defer/deferred-namespace-object/object-properties.js @@ -4,7 +4,7 @@ /*--- esid: sec-modulenamespacecreate description: > - `defer` is a valid name for default imports + Deferred namespace objects have the correct MOP implementation info: | ModuleNamespaceCreate ( _module_, _exports_, _phase_ ) 1. Let _internalSlotsList_ be the internal slots listed in . diff --git a/test/language/import/import-defer/errors/get-other-while-evaluating/main.js b/test/language/import/import-defer/errors/get-other-while-evaluating/main.js index 5eb76bc5279..0c7932fbab9 100644 --- a/test/language/import/import-defer/errors/get-other-while-evaluating/main.js +++ b/test/language/import/import-defer/errors/get-other-while-evaluating/main.js @@ -4,7 +4,7 @@ /*--- esid: sec-module-namespace-exotic-objects-get-p-receiver-EnsureDeferredNamespaceEvaluation description: > - Modules cannot try to trigger their own evaluation + Deferred namespaces' properties cannot be accessed on a module that is being evaluated info: | 10.4.6.8 [[Get]] ( _P_, _Receiver_ ) 1. ... From 0e5df8be9417d9ab209a4891229cab5f43d69c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 31 Oct 2024 13:00:57 +0100 Subject: [PATCH 07/13] Do not use `assert` in `_FIXTURE` files --- .../dep-1.1_FIXTURE.js | 14 +++++++++++--- .../get-other-while-dep-evaluating-async/main.js | 6 +++++- .../dep-1_FIXTURE.js | 10 ++++++++-- .../errors/get-other-while-dep-evaluating/main.js | 3 +++ .../dep-1.1_FIXTURE.js | 14 +++++++++++--- .../get-other-while-evaluating-async/main.js | 6 +++++- .../get-other-while-evaluating/dep_FIXTURE.js | 6 +++++- .../errors/get-other-while-evaluating/main.js | 2 ++ .../get-self-while-defer-evaluating/dep_FIXTURE.js | 6 +++++- .../errors/get-self-while-defer-evaluating/main.js | 2 ++ .../get-self-while-evaluating-async/dep_FIXTURE.js | 6 +++++- .../errors/get-self-while-evaluating-async/main.js | 2 ++ 12 files changed, 64 insertions(+), 13 deletions(-) diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1.1_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1.1_FIXTURE.js index d6a6b311a48..fcb89ab8fed 100644 --- a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1.1_FIXTURE.js +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1.1_FIXTURE.js @@ -5,15 +5,23 @@ import { first, third, rejectDone, resolveDone } from "./promises_FIXTURE.js"; import defer * as ns from "./dep-1.1.1-tla_FIXTURE.js"; // dep-1 is now in the ~evaluating~ state -assert.throws(TypeError, () => ns.foo); +try { + ns.foo; +} catch (error) { + globalThis["error on ns.foo while evaluating"] = error; +} first.then(() => { // dep-1 is now in the ~evaluating-async~ state - assert.throws(TypeError, () => ns.foo); + try { + ns.foo; + } catch (error) { + globalThis["error on ns.foo while evaluating-async"] = error; + } }).then(() => { return third.then(() => { // dep-1 is now in the ~evaluated~ state let foo = ns.foo; - assert.sameValue(foo, 1, "Once it finished evaluating, the module can be accessed"); + globalThis["value of ns.foo when evaluated"] = foo; }) }).then(resolveDone, rejectDone); diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/main.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/main.js index cdc314884e1..f750a3039f8 100644 --- a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/main.js +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/main.js @@ -38,4 +38,8 @@ features: [import-defer, top-level-await] import { done } from "./promises_FIXTURE.js"; import "./dep-1-tla_FIXTURE.js"; -done.then($DONE, $DONE); +done.then(() => { + assert(globalThis["error on ns.foo while evaluating"] instanceof TypeError, "ns.foo while evaluating throws a TypeError"); + assert(globalThis["error on ns.foo while evaluating-async"] instanceof TypeError, "ns.foo while evaluating-async throws a TypeError"); + assert.sameValue(globalThis["value of ns.foo when evaluated"], 1); +}).then($DONE, $DONE); diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-1_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-1_FIXTURE.js index e99a1cdf614..37b9c135002 100644 --- a/test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-1_FIXTURE.js +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-1_FIXTURE.js @@ -4,5 +4,11 @@ import defer * as dep2 from "./dep-2_FIXTURE.js"; globalThis.dep3evaluated = false; -assert.throws(TypeError, () => dep2.foo); -assert.sameValue(globalThis.dep3evaluated, false, "the 'evaluable' dependencies of dep-2 are not evaluated"); + +try { + dep2.foo; +} catch (error) { + globalThis["evaluating dep2.foo error"] = error; +} + +globalThis["evaluating dep2.foo evaluates dep2"] = globalThis.dep3evaluated; diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating/main.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating/main.js index d27fefb061a..dc1e5c39d5e 100644 --- a/test/language/import/import-defer/errors/get-other-while-dep-evaluating/main.js +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating/main.js @@ -36,3 +36,6 @@ features: [import-defer] ---*/ import "./dep-1_FIXTURE.js"; + +assert(globalThis["evaluating dep2.foo error"] instanceof TypeError, "evaluating dep2.foo throws a TypeError"); +assert(!globalThis["evaluating dep2.foo evaluates dep2"], "evaluating dep2.foo does not evaluate dep2"); diff --git a/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1.1_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1.1_FIXTURE.js index 886b663c851..43ba39d3492 100644 --- a/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1.1_FIXTURE.js +++ b/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1.1_FIXTURE.js @@ -5,15 +5,23 @@ import { first, third, rejectDone, resolveDone } from "./promises_FIXTURE.js"; import defer * as ns from "./dep-1-tla_FIXTURE.js"; // ns is now in the ~evaluating~ state -assert.throws(TypeError, () => ns.foo); +try { + ns.foo; +} catch (error) { + globalThis["error on ns.foo while evaluating"] = error; +} first.then(() => { // ns is now in the ~evaluating-async~ state - assert.throws(TypeError, () => ns.foo); + try { + ns.foo; + } catch (error) { + globalThis["error on ns.foo while evaluating-async"] = error; + } }).then(() => { return third.then(() => { // ns is now in the ~evaluated~ state let foo = ns.foo; - assert.sameValue(foo, 1, "Once it finished evaluating, the module can be accessed"); + globalThis["value of ns.foo when evaluated"] = foo; }) }).then(resolveDone, rejectDone); diff --git a/test/language/import/import-defer/errors/get-other-while-evaluating-async/main.js b/test/language/import/import-defer/errors/get-other-while-evaluating-async/main.js index 385ee1917ac..9e8307ff890 100644 --- a/test/language/import/import-defer/errors/get-other-while-evaluating-async/main.js +++ b/test/language/import/import-defer/errors/get-other-while-evaluating-async/main.js @@ -38,4 +38,8 @@ features: [import-defer, top-level-await] import { done } from "./promises_FIXTURE.js"; import "./dep-1-tla_FIXTURE.js"; -done.then($DONE, $DONE); +done.then(() => { + assert(globalThis["error on ns.foo while evaluating"] instanceof TypeError, "ns.foo while evaluating throws a TypeError"); + assert(globalThis["error on ns.foo while evaluating-async"] instanceof TypeError, "ns.foo while evaluating-async throws a TypeError"); + assert.sameValue(globalThis["value of ns.foo when evaluated"], 1); +}).then($DONE, $DONE); diff --git a/test/language/import/import-defer/errors/get-other-while-evaluating/dep_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-evaluating/dep_FIXTURE.js index 3a232403df0..dd9fcdb9e48 100644 --- a/test/language/import/import-defer/errors/get-other-while-evaluating/dep_FIXTURE.js +++ b/test/language/import/import-defer/errors/get-other-while-evaluating/dep_FIXTURE.js @@ -3,4 +3,8 @@ import defer * as main from "./main.js"; -assert.throws(TypeError, () => main.foo); +try { + main.foo; +} catch (error) { + globalThis["error on main.foo"] = error; +} diff --git a/test/language/import/import-defer/errors/get-other-while-evaluating/main.js b/test/language/import/import-defer/errors/get-other-while-evaluating/main.js index 0c7932fbab9..6373afde005 100644 --- a/test/language/import/import-defer/errors/get-other-while-evaluating/main.js +++ b/test/language/import/import-defer/errors/get-other-while-evaluating/main.js @@ -36,3 +36,5 @@ features: [import-defer] ---*/ import "./dep_FIXTURE.js"; + +assert(globalThis["error on main.foo"] instanceof TypeError, "main.foo while evaluating throws a TypeError"); diff --git a/test/language/import/import-defer/errors/get-self-while-defer-evaluating/dep_FIXTURE.js b/test/language/import/import-defer/errors/get-self-while-defer-evaluating/dep_FIXTURE.js index 69eab4f45f7..3052c5c725d 100644 --- a/test/language/import/import-defer/errors/get-self-while-defer-evaluating/dep_FIXTURE.js +++ b/test/language/import/import-defer/errors/get-self-while-defer-evaluating/dep_FIXTURE.js @@ -3,4 +3,8 @@ import defer * as ns from "./dep_FIXTURE.js"; -assert.throws(TypeError, () => ns.foo); +try { + ns.foo; +} catch (error) { + globalThis["error on ns.foo"] = error; +} diff --git a/test/language/import/import-defer/errors/get-self-while-defer-evaluating/main.js b/test/language/import/import-defer/errors/get-self-while-defer-evaluating/main.js index dc5f2b51b89..cfcf4328ce9 100644 --- a/test/language/import/import-defer/errors/get-self-while-defer-evaluating/main.js +++ b/test/language/import/import-defer/errors/get-self-while-defer-evaluating/main.js @@ -37,4 +37,6 @@ features: [import-defer] import defer * as ns from "./dep_FIXTURE.js"; +assert(globalThis["error on ns.foo"] instanceof TypeError, "ns.foo while evaluating throws a TypeError"); + ns.foo; diff --git a/test/language/import/import-defer/errors/get-self-while-evaluating-async/dep_FIXTURE.js b/test/language/import/import-defer/errors/get-self-while-evaluating-async/dep_FIXTURE.js index 7b75a749cc4..a990c9bbbde 100644 --- a/test/language/import/import-defer/errors/get-self-while-evaluating-async/dep_FIXTURE.js +++ b/test/language/import/import-defer/errors/get-self-while-evaluating-async/dep_FIXTURE.js @@ -5,4 +5,8 @@ import defer * as ns from "./dep_FIXTURE.js"; await Promise.resolve(0); -assert.throws(TypeError, () => ns.foo); +try { + ns.foo; +} catch (error) { + globalThis["error on ns.foo"] = error; +} diff --git a/test/language/import/import-defer/errors/get-self-while-evaluating-async/main.js b/test/language/import/import-defer/errors/get-self-while-evaluating-async/main.js index 7d2ecef6d7b..d51ec49f358 100644 --- a/test/language/import/import-defer/errors/get-self-while-evaluating-async/main.js +++ b/test/language/import/import-defer/errors/get-self-while-evaluating-async/main.js @@ -31,6 +31,8 @@ features: [import-defer, top-level-await] import defer * as ns from "./dep_FIXTURE.js"; +assert(globalThis["error on ns.foo"] instanceof TypeError, "ns.foo while evaluating throws a TypeError"); + ns.foo; $DONE(); From 612c920fd484d10811ccbd4225f625dbfb88d3f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 31 Oct 2024 13:22:07 +0100 Subject: [PATCH 08/13] Add missing `$DONOTEVALUATE()` calls --- .../resolution-error/import-defer-of-syntax-error-fails.js | 2 ++ .../errors/syntax-error/import-defer-of-syntax-error-fails.js | 2 ++ .../import-defer/syntax/invalid-default-and-defer-namespace.js | 2 ++ .../import-defer/syntax/invalid-defer-as-with-no-asterisk.js | 2 ++ .../import-defer/syntax/invalid-defer-default-and-namespace.js | 2 ++ .../import/import-defer/syntax/invalid-defer-default.js | 2 ++ test/language/import/import-defer/syntax/invalid-defer-named.js | 2 ++ .../import-defer/syntax/invalid-export-defer-namespace.js | 2 ++ 8 files changed, 16 insertions(+) diff --git a/test/language/import/import-defer/errors/resolution-error/import-defer-of-syntax-error-fails.js b/test/language/import/import-defer/errors/resolution-error/import-defer-of-syntax-error-fails.js index 1104bf6cbba..c8f7f39b8a5 100644 --- a/test/language/import/import-defer/errors/resolution-error/import-defer-of-syntax-error-fails.js +++ b/test/language/import/import-defer/errors/resolution-error/import-defer-of-syntax-error-fails.js @@ -17,4 +17,6 @@ negative: type: SyntaxError ---*/ +$DONOTEVALUATE(); + import defer * as ns "./resolution-error_FIXTURE.js"; diff --git a/test/language/import/import-defer/errors/syntax-error/import-defer-of-syntax-error-fails.js b/test/language/import/import-defer/errors/syntax-error/import-defer-of-syntax-error-fails.js index 09520de2072..f253db952fd 100644 --- a/test/language/import/import-defer/errors/syntax-error/import-defer-of-syntax-error-fails.js +++ b/test/language/import/import-defer/errors/syntax-error/import-defer-of-syntax-error-fails.js @@ -17,4 +17,6 @@ negative: type: SyntaxError ---*/ +$DONOTEVALUATE(); + import defer * as ns "./syntax-error_FIXTURE.js"; diff --git a/test/language/import/import-defer/syntax/invalid-default-and-defer-namespace.js b/test/language/import/import-defer/syntax/invalid-default-and-defer-namespace.js index e2110156353..5a33f20e761 100644 --- a/test/language/import/import-defer/syntax/invalid-default-and-defer-namespace.js +++ b/test/language/import/import-defer/syntax/invalid-default-and-defer-namespace.js @@ -28,4 +28,6 @@ negative: type: SyntaxError ---*/ +$DONOTEVALUATE(); + import defer x, * as ns from "./dep_FIXTURE.js"; diff --git a/test/language/import/import-defer/syntax/invalid-defer-as-with-no-asterisk.js b/test/language/import/import-defer/syntax/invalid-defer-as-with-no-asterisk.js index 225566fb524..008108dee9a 100644 --- a/test/language/import/import-defer/syntax/invalid-defer-as-with-no-asterisk.js +++ b/test/language/import/import-defer/syntax/invalid-defer-as-with-no-asterisk.js @@ -28,4 +28,6 @@ negative: type: SyntaxError ---*/ +$DONOTEVALUATE(); + import defer as ns from "./dep_FIXTURE.js"; diff --git a/test/language/import/import-defer/syntax/invalid-defer-default-and-namespace.js b/test/language/import/import-defer/syntax/invalid-defer-default-and-namespace.js index a6a957d7d6e..b7ba83936fa 100644 --- a/test/language/import/import-defer/syntax/invalid-defer-default-and-namespace.js +++ b/test/language/import/import-defer/syntax/invalid-defer-default-and-namespace.js @@ -28,4 +28,6 @@ negative: type: SyntaxError ---*/ +$DONOTEVALUATE(); + import x, defer * as ns from "./dep_FIXTURE.js"; diff --git a/test/language/import/import-defer/syntax/invalid-defer-default.js b/test/language/import/import-defer/syntax/invalid-defer-default.js index baccd4b9fe8..e3af0bf7846 100644 --- a/test/language/import/import-defer/syntax/invalid-defer-default.js +++ b/test/language/import/import-defer/syntax/invalid-defer-default.js @@ -28,4 +28,6 @@ negative: type: SyntaxError ---*/ +$DONOTEVALUATE(); + import defer x from "./dep_FIXTURE.js"; diff --git a/test/language/import/import-defer/syntax/invalid-defer-named.js b/test/language/import/import-defer/syntax/invalid-defer-named.js index f076391a53a..6f94674dbdc 100644 --- a/test/language/import/import-defer/syntax/invalid-defer-named.js +++ b/test/language/import/import-defer/syntax/invalid-defer-named.js @@ -28,4 +28,6 @@ negative: type: SyntaxError ---*/ +$DONOTEVALUATE(); + import defer { default as x } from "./dep_FIXTURE.js"; diff --git a/test/language/import/import-defer/syntax/invalid-export-defer-namespace.js b/test/language/import/import-defer/syntax/invalid-export-defer-namespace.js index 65a2a2dd1cb..ff797659d07 100644 --- a/test/language/import/import-defer/syntax/invalid-export-defer-namespace.js +++ b/test/language/import/import-defer/syntax/invalid-export-defer-namespace.js @@ -27,4 +27,6 @@ negative: type: SyntaxError ---*/ +$DONOTEVALUATE(); + export defer * as ns from "./dep_FIXTURE.js"; From af3d19b66eeb2c150eb25633c3e0af6c599a851f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 7 Nov 2024 16:28:58 +0100 Subject: [PATCH 09/13] Partial fixes for ptomato review --- .../{object-properties.js => exotic-object-behavior.js} | 0 .../get-other-while-dep-evaluating-async/dep-1.1_FIXTURE.js | 5 +++-- .../errors/get-other-while-dep-evaluating-async/main.js | 6 ++++-- .../promises_FIXTURE.js | 2 +- .../get-other-while-evaluating-async/dep-1.1_FIXTURE.js | 3 ++- .../errors/get-other-while-evaluating-async/main.js | 6 ++++-- .../get-other-while-evaluating-async/promises_FIXTURE.js | 2 +- .../resolution-error/import-defer-of-syntax-error-fails.js | 2 +- .../syntax-error/import-defer-of-syntax-error-fails.js | 2 +- 9 files changed, 17 insertions(+), 11 deletions(-) rename test/language/import/import-defer/deferred-namespace-object/{object-properties.js => exotic-object-behavior.js} (100%) diff --git a/test/language/import/import-defer/deferred-namespace-object/object-properties.js b/test/language/import/import-defer/deferred-namespace-object/exotic-object-behavior.js similarity index 100% rename from test/language/import/import-defer/deferred-namespace-object/object-properties.js rename to test/language/import/import-defer/deferred-namespace-object/exotic-object-behavior.js diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1.1_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1.1_FIXTURE.js index fcb89ab8fed..dada1f27fce 100644 --- a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1.1_FIXTURE.js +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1.1_FIXTURE.js @@ -1,8 +1,8 @@ // Copyright (C) 2024 Igalia, S.L. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. -import { first, third, rejectDone, resolveDone } from "./promises_FIXTURE.js"; -import defer * as ns from "./dep-1.1.1-tla_FIXTURE.js"; +import { first, third, rejectDone, resolveDone, resolveSecond } from "./promises_FIXTURE.js"; +import defer * as ns from "./dep-1.1.1_FIXTURE.js"; // dep-1 is now in the ~evaluating~ state try { @@ -18,6 +18,7 @@ first.then(() => { } catch (error) { globalThis["error on ns.foo while evaluating-async"] = error; } + resolveSecond(); }).then(() => { return third.then(() => { // dep-1 is now in the ~evaluated~ state diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/main.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/main.js index f750a3039f8..6f6a81f48d4 100644 --- a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/main.js +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/main.js @@ -33,13 +33,15 @@ info: | flags: [module, async] features: [import-defer, top-level-await] +include: [asyncHelpers.js] ---*/ import { done } from "./promises_FIXTURE.js"; import "./dep-1-tla_FIXTURE.js"; -done.then(() => { +asyncText(async () => { + await done; assert(globalThis["error on ns.foo while evaluating"] instanceof TypeError, "ns.foo while evaluating throws a TypeError"); assert(globalThis["error on ns.foo while evaluating-async"] instanceof TypeError, "ns.foo while evaluating-async throws a TypeError"); assert.sameValue(globalThis["value of ns.foo when evaluated"], 1); -}).then($DONE, $DONE); +}); diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/promises_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/promises_FIXTURE.js index a54c20ffa56..d58fd54b1e3 100644 --- a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/promises_FIXTURE.js +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/promises_FIXTURE.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. export let resolveDone, rejectDone; -export const done = new Promise((r, j) => (resolveDone = r, rejecteDone = j)); +export const done = new Promise((r, j) => (resolveDone = r, rejectDone = j)); export let resolveFirst, rejectFirst; export const first = new Promise((r, j) => (resolveFirst = r, rejectFirst = j)); diff --git a/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1.1_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1.1_FIXTURE.js index 43ba39d3492..ac916011724 100644 --- a/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1.1_FIXTURE.js +++ b/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1.1_FIXTURE.js @@ -1,7 +1,7 @@ // Copyright (C) 2024 Igalia, S.L. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. -import { first, third, rejectDone, resolveDone } from "./promises_FIXTURE.js"; +import { first, third, resolveSecond, rejectDone, resolveDone } from "./promises_FIXTURE.js"; import defer * as ns from "./dep-1-tla_FIXTURE.js"; // ns is now in the ~evaluating~ state @@ -18,6 +18,7 @@ first.then(() => { } catch (error) { globalThis["error on ns.foo while evaluating-async"] = error; } + resolveSecond(); }).then(() => { return third.then(() => { // ns is now in the ~evaluated~ state diff --git a/test/language/import/import-defer/errors/get-other-while-evaluating-async/main.js b/test/language/import/import-defer/errors/get-other-while-evaluating-async/main.js index 9e8307ff890..094aed69e11 100644 --- a/test/language/import/import-defer/errors/get-other-while-evaluating-async/main.js +++ b/test/language/import/import-defer/errors/get-other-while-evaluating-async/main.js @@ -33,13 +33,15 @@ info: | flags: [module, async] features: [import-defer, top-level-await] +include: [asyncHelpers.js] ---*/ import { done } from "./promises_FIXTURE.js"; import "./dep-1-tla_FIXTURE.js"; -done.then(() => { +asyncTest(async () => { + await done; assert(globalThis["error on ns.foo while evaluating"] instanceof TypeError, "ns.foo while evaluating throws a TypeError"); assert(globalThis["error on ns.foo while evaluating-async"] instanceof TypeError, "ns.foo while evaluating-async throws a TypeError"); assert.sameValue(globalThis["value of ns.foo when evaluated"], 1); -}).then($DONE, $DONE); +}); diff --git a/test/language/import/import-defer/errors/get-other-while-evaluating-async/promises_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-evaluating-async/promises_FIXTURE.js index a54c20ffa56..d58fd54b1e3 100644 --- a/test/language/import/import-defer/errors/get-other-while-evaluating-async/promises_FIXTURE.js +++ b/test/language/import/import-defer/errors/get-other-while-evaluating-async/promises_FIXTURE.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. export let resolveDone, rejectDone; -export const done = new Promise((r, j) => (resolveDone = r, rejecteDone = j)); +export const done = new Promise((r, j) => (resolveDone = r, rejectDone = j)); export let resolveFirst, rejectFirst; export const first = new Promise((r, j) => (resolveFirst = r, rejectFirst = j)); diff --git a/test/language/import/import-defer/errors/resolution-error/import-defer-of-syntax-error-fails.js b/test/language/import/import-defer/errors/resolution-error/import-defer-of-syntax-error-fails.js index c8f7f39b8a5..94cac22af31 100644 --- a/test/language/import/import-defer/errors/resolution-error/import-defer-of-syntax-error-fails.js +++ b/test/language/import/import-defer/errors/resolution-error/import-defer-of-syntax-error-fails.js @@ -4,7 +4,7 @@ /*--- esid: sec-module-namespace-exotic-objects-get-p-receiver-EnsureDeferredNamespaceEvaluation description: > - Module evaluation errors are thrown + Host resolution errors are reported eagerly info: | LoadRequestedModules ([ _hostDefined_ ]) - just notice that it does not check if the module is deferred diff --git a/test/language/import/import-defer/errors/syntax-error/import-defer-of-syntax-error-fails.js b/test/language/import/import-defer/errors/syntax-error/import-defer-of-syntax-error-fails.js index f253db952fd..f3c2ebda9fc 100644 --- a/test/language/import/import-defer/errors/syntax-error/import-defer-of-syntax-error-fails.js +++ b/test/language/import/import-defer/errors/syntax-error/import-defer-of-syntax-error-fails.js @@ -4,7 +4,7 @@ /*--- esid: sec-module-namespace-exotic-objects-get-p-receiver-EnsureDeferredNamespaceEvaluation description: > - Module evaluation errors are thrown + Syntax errors in deferred modules are reported eagerly info: | LoadRequestedModules ([ _hostDefined_ ]) - just notice that it does not check if the module is deferred From acd29244c561c60eaac6f4a2fe24576441641cc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 7 Nov 2024 16:58:41 +0100 Subject: [PATCH 10/13] Rest of review by ptomato and asumu --- .../dep-1_FIXTURE.js | 2 +- .../get-other-while-dep-evaluating/main.js | 3 ++- .../defer-import-after-evaluation.js | 21 ++++++++++++++----- ...ird-party-evaluation-after-defer-import.js | 19 +++++++++++++---- .../errors/module-throws/throws_FIXTURE.js | 2 +- .../module-throws/trigger-evaluation.js | 8 +++++-- .../evaluation-ignore-isExtensible.js | 2 +- .../evaluation-ignore-preventExtensions.js | 2 +- .../evaluation-ignore-setPrototypeOf.js | 2 +- .../flattening-order/main.js | 12 +++++------ .../{ => flattening-order}/setup_FIXTURE.js | 0 .../import-defer-async-module/main.js | 2 +- .../setup_FIXTURE.js | 4 ++++ .../main.js | 6 +++--- .../setup_FIXTURE.js | 4 ++++ .../dep_FIXTURE.js | 2 +- .../main.js | 2 +- .../setup_FIXTURE.js | 4 ++++ 18 files changed, 68 insertions(+), 29 deletions(-) rename test/language/import/import-defer/evaluation-top-level-await/{ => flattening-order}/setup_FIXTURE.js (100%) create mode 100644 test/language/import/import-defer/evaluation-top-level-await/import-defer-async-module/setup_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/setup_FIXTURE.js create mode 100644 test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/setup_FIXTURE.js diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-1_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-1_FIXTURE.js index 37b9c135002..4e39108d296 100644 --- a/test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-1_FIXTURE.js +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating/dep-1_FIXTURE.js @@ -11,4 +11,4 @@ try { globalThis["evaluating dep2.foo error"] = error; } -globalThis["evaluating dep2.foo evaluates dep2"] = globalThis.dep3evaluated; +globalThis["evaluating dep2.foo evaluates dep3"] = globalThis.dep3evaluated; diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating/main.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating/main.js index dc1e5c39d5e..4446fd5cef0 100644 --- a/test/language/import/import-defer/errors/get-other-while-dep-evaluating/main.js +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating/main.js @@ -38,4 +38,5 @@ features: [import-defer] import "./dep-1_FIXTURE.js"; assert(globalThis["evaluating dep2.foo error"] instanceof TypeError, "evaluating dep2.foo throws a TypeError"); -assert(!globalThis["evaluating dep2.foo evaluates dep2"], "evaluating dep2.foo does not evaluate dep2"); +assert(!globalThis["evaluating dep2.foo evaluates dep3"], "evaluating dep2.foo does not evaluate dep3"); +assert(!globalThis.dep3evaluated, "dep3 is not evaluated at all"); diff --git a/test/language/import/import-defer/errors/module-throws/defer-import-after-evaluation.js b/test/language/import/import-defer/errors/module-throws/defer-import-after-evaluation.js index af34278238d..55bb2a8df3c 100644 --- a/test/language/import/import-defer/errors/module-throws/defer-import-after-evaluation.js +++ b/test/language/import/import-defer/errors/module-throws/defer-import-after-evaluation.js @@ -24,12 +24,23 @@ info: | 1. Return ThrowCompletion(_promise_.[[PromiseResult]]). 1. ... -flags: [module] -features: [import-defer, top-level-await] +flags: [module, async] +features: [import-defer] +include: [asyncHelpers.js] ---*/ -await import("./throws_FIXTURE.js").catch(() => {}); +asyncText(async () => { + let err1; + await import("./throws_FIXTURE.js").catch((e) => { err1 = e }); + assert.deepEqual(err1, { someError: "the error from throws_FIXTURE" }); -const { ns } = await import("./import-defer-throws_FIXTURE.js"); + const { ns } = await import("./import-defer-throws_FIXTURE.js"); -assert.throws(URIError, () => ns.foo, "Evaluation errors are thrown for modules evaluated before getting the deferred namespace"); + let err2; + try { ns.foo } catch (e) { err2 = e }; + assert.sameValue( + err1, + err2, + "Evaluation errors are thrown for modules evaluated before getting the deferred namespace" + ); +}); diff --git a/test/language/import/import-defer/errors/module-throws/third-party-evaluation-after-defer-import.js b/test/language/import/import-defer/errors/module-throws/third-party-evaluation-after-defer-import.js index 0c22ef4a576..5500f1cd856 100644 --- a/test/language/import/import-defer/errors/module-throws/third-party-evaluation-after-defer-import.js +++ b/test/language/import/import-defer/errors/module-throws/third-party-evaluation-after-defer-import.js @@ -24,12 +24,23 @@ info: | 1. Return ThrowCompletion(_promise_.[[PromiseResult]]). 1. ... -flags: [module] -features: [import-defer, top-level-await] +flags: [module, async] +features: [import-defer] +include: [asyncHelpers.js] ---*/ import defer * as ns from "./throws_FIXTURE.js"; -await import("./throws_FIXTURE.js").catch(() => {}); +asyncText(async () => { + let err1; + await import("./throws_FIXTURE.js").catch((e) => { err1 = e }); + assert.deepEqual(err1, { someError: "the error from throws_FIXTURE" }); -assert.throws(URIError, () => ns.foo, "Evaluation errors are thrown for modules evaluated after getting the deferred namespace"); + let err2; + try { ns.foo } catch (e) { err2 = e }; + assert.sameValue( + err1, + err2, + "Evaluation errors are thrown for modules evaluated after getting the deferred namespace" + ); +}); diff --git a/test/language/import/import-defer/errors/module-throws/throws_FIXTURE.js b/test/language/import/import-defer/errors/module-throws/throws_FIXTURE.js index fdcd441a0e5..85290878c9c 100644 --- a/test/language/import/import-defer/errors/module-throws/throws_FIXTURE.js +++ b/test/language/import/import-defer/errors/module-throws/throws_FIXTURE.js @@ -1,4 +1,4 @@ // Copyright (C) 2024 Igalia, S.L. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. -throw new URIError("hello"); +throw { someError: "the error from throws_FIXTURE" } diff --git a/test/language/import/import-defer/errors/module-throws/trigger-evaluation.js b/test/language/import/import-defer/errors/module-throws/trigger-evaluation.js index 34b790c6c27..e18d4dec0f8 100644 --- a/test/language/import/import-defer/errors/module-throws/trigger-evaluation.js +++ b/test/language/import/import-defer/errors/module-throws/trigger-evaluation.js @@ -30,5 +30,9 @@ features: [import-defer] import defer * as ns from "./throws_FIXTURE.js"; -assert.throws(URIError, () => ns.foo, "Evaluation errors are thrown when evaluating"); -assert.throws(URIError, () => ns.foo, "Evaluation errors are thrown for already evaluated modules"); +let err1, err2; +try { ns.foo } catch (e) { err1 = e }; +assert.deepEqual(err1, { someError: "the error from throws_FIXTURE" }, "Evaluation errors are thrown when evaluating"); + +try { ns.foo } catch (e) { err2 = e }; +assert.sameValue(err1, err2, "Evaluation errors are thrown for already evaluated modules"); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-isExtensible.js b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-isExtensible.js index 49e3d67ee4b..47f441bffa9 100644 --- a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-isExtensible.js +++ b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-isExtensible.js @@ -21,4 +21,4 @@ assert.sameValue(globalThis.evaluations.length, 0, "import defer does not trigge Object.isExtensible(ns1); -assert.sameValue(globalThis.evaluations.length, 0, "[[GetPrototypeOf]] does not trigger evaluation"); +assert.sameValue(globalThis.evaluations.length, 0, "[[IsExtensible]] does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-preventExtensions.js b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-preventExtensions.js index 36463c43f34..e2438de032e 100644 --- a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-preventExtensions.js +++ b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-preventExtensions.js @@ -21,4 +21,4 @@ assert.sameValue(globalThis.evaluations.length, 0, "import defer does not trigge Object.preventExtensions(ns1); -assert.sameValue(globalThis.evaluations.length, 0, "[[GetPrototypeOf]] does not trigger evaluation"); +assert.sameValue(globalThis.evaluations.length, 0, "[[PreventExtensions]] does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-setPrototypeOf.js b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-setPrototypeOf.js index fcbb3e0739e..d2b82a7b84d 100644 --- a/test/language/import/import-defer/evaluation-sync/evaluation-ignore-setPrototypeOf.js +++ b/test/language/import/import-defer/evaluation-sync/evaluation-ignore-setPrototypeOf.js @@ -22,4 +22,4 @@ assert.sameValue(globalThis.evaluations.length, 0, "import defer does not trigge Reflect.setPrototypeOf(ns1, null); Reflect.setPrototypeOf(ns1, {}); -assert.sameValue(globalThis.evaluations.length, 0, "[[GetPrototypeOf]] does not trigger evaluation"); +assert.sameValue(globalThis.evaluations.length, 0, "[[SetPrototypeOf]] does not trigger evaluation"); diff --git a/test/language/import/import-defer/evaluation-top-level-await/flattening-order/main.js b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/main.js index 05a97121a00..010d0539779 100644 --- a/test/language/import/import-defer/evaluation-top-level-await/flattening-order/main.js +++ b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/main.js @@ -45,13 +45,13 @@ features: [import-defer, top-level-await] includes: [compareArray.js] ---*/ -import "../setup_FIXTURE.js"; +import "./setup_FIXTURE.js"; -import "./dep-1.js"; -import defer * as ns2 from "./dep-2.js"; -import "./dep-3.js"; -import defer * as ns4 from "./dep-4.js"; -import "./dep-5.js"; +import "./dep-1_FIXTURE.js"; +import defer * as ns2 from "./dep-2_FIXTURE.js.js"; +import "./dep-3_FIXTURE.js.js"; +import defer * as ns4 from "./dep-4_FIXTURE.js.js"; +import "./dep-5_FIXTURE.js.js"; assert.compareArray(globalThis.evaluations, [ "1", diff --git a/test/language/import/import-defer/evaluation-top-level-await/setup_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/setup_FIXTURE.js similarity index 100% rename from test/language/import/import-defer/evaluation-top-level-await/setup_FIXTURE.js rename to test/language/import/import-defer/evaluation-top-level-await/flattening-order/setup_FIXTURE.js diff --git a/test/language/import/import-defer/evaluation-top-level-await/import-defer-async-module/main.js b/test/language/import/import-defer/evaluation-top-level-await/import-defer-async-module/main.js index 2809c173721..e130d65e964 100644 --- a/test/language/import/import-defer/evaluation-top-level-await/import-defer-async-module/main.js +++ b/test/language/import/import-defer/evaluation-top-level-await/import-defer-async-module/main.js @@ -45,7 +45,7 @@ features: [import-defer, top-level-await] includes: [compareArray.js] ---*/ -import "../setup_FIXTURE.js"; +import "./setup_FIXTURE.js"; import defer * as ns from "./tla_FIXTURE.js"; assert.compareArray(globalThis.evaluations, ["tla start", "tla end"]); diff --git a/test/language/import/import-defer/evaluation-top-level-await/import-defer-async-module/setup_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/import-defer-async-module/setup_FIXTURE.js new file mode 100644 index 00000000000..d71b2fa95eb --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/import-defer-async-module/setup_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +globalThis.evaluations = []; diff --git a/test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/main.js b/test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/main.js index 4fab87d391d..c4317959b6b 100644 --- a/test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/main.js +++ b/test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/main.js @@ -45,11 +45,11 @@ features: [import-defer, top-level-await] includes: [compareArray.js] ---*/ -import "../setup_FIXTURE.js"; -import defer * as ns "./imports-tla_FIXTURE.js"; +import "./setup_FIXTURE.js"; +import defer * as ns from "./imports-tla_FIXTURE.js"; assert.compareArray(globalThis.evaluations, ["tla start", "tla end"]); ns.x; -assert.compareArray(globalThis.evaluations, ["imports-dla"]); +assert.compareArray(globalThis.evaluations, ["tla start", "tla end", "imports-tla"]); $DONE(); diff --git a/test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/setup_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/setup_FIXTURE.js new file mode 100644 index 00000000000..d71b2fa95eb --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/import-defer-transitive-async-module/setup_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +globalThis.evaluations = []; diff --git a/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/dep_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/dep_FIXTURE.js index 6d225a3c545..a3e50d5d6f2 100644 --- a/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/dep_FIXTURE.js +++ b/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/dep_FIXTURE.js @@ -1,4 +1,4 @@ // Copyright (C) 2024 Igalia, S.L. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. -globalThis.evaluations.push("dep start"); +globalThis.evaluations.push("dep"); diff --git a/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/main.js b/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/main.js index a27a49a16c5..b1a7cb6f9b5 100644 --- a/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/main.js +++ b/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/main.js @@ -45,7 +45,7 @@ features: [import-defer, top-level-await] includes: [compareArray.js] ---*/ -import "../setup_FIXTURE.js"; +import "./setup_FIXTURE.js"; import defer * as ns from "./imports-tla-with-dep_FIXTURE.js"; assert.compareArray( diff --git a/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/setup_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/setup_FIXTURE.js new file mode 100644 index 00000000000..d71b2fa95eb --- /dev/null +++ b/test/language/import/import-defer/evaluation-top-level-await/sync-dependency-of-deferred-async-module/setup_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +globalThis.evaluations = []; From a873634ed78814f4793b2badbe4a7ed0cc5a73fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 7 Nov 2024 17:37:04 +0100 Subject: [PATCH 11/13] Lint --- .../errors/get-other-while-dep-evaluating-async/main.js | 2 +- .../errors/get-other-while-evaluating-async/main.js | 2 +- .../errors/module-throws/defer-import-after-evaluation.js | 2 +- .../module-throws/third-party-evaluation-after-defer-import.js | 2 +- .../evaluation-sync/module-imported-defer-and-eager.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/main.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/main.js index 6f6a81f48d4..9606f1a127c 100644 --- a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/main.js +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/main.js @@ -33,7 +33,7 @@ info: | flags: [module, async] features: [import-defer, top-level-await] -include: [asyncHelpers.js] +includes: [asyncHelpers.js] ---*/ import { done } from "./promises_FIXTURE.js"; diff --git a/test/language/import/import-defer/errors/get-other-while-evaluating-async/main.js b/test/language/import/import-defer/errors/get-other-while-evaluating-async/main.js index 094aed69e11..ca66754aef4 100644 --- a/test/language/import/import-defer/errors/get-other-while-evaluating-async/main.js +++ b/test/language/import/import-defer/errors/get-other-while-evaluating-async/main.js @@ -33,7 +33,7 @@ info: | flags: [module, async] features: [import-defer, top-level-await] -include: [asyncHelpers.js] +includes: [asyncHelpers.js] ---*/ import { done } from "./promises_FIXTURE.js"; diff --git a/test/language/import/import-defer/errors/module-throws/defer-import-after-evaluation.js b/test/language/import/import-defer/errors/module-throws/defer-import-after-evaluation.js index 55bb2a8df3c..865e4397d6c 100644 --- a/test/language/import/import-defer/errors/module-throws/defer-import-after-evaluation.js +++ b/test/language/import/import-defer/errors/module-throws/defer-import-after-evaluation.js @@ -26,7 +26,7 @@ info: | flags: [module, async] features: [import-defer] -include: [asyncHelpers.js] +includes: [asyncHelpers.js] ---*/ asyncText(async () => { diff --git a/test/language/import/import-defer/errors/module-throws/third-party-evaluation-after-defer-import.js b/test/language/import/import-defer/errors/module-throws/third-party-evaluation-after-defer-import.js index 5500f1cd856..4e9780fe329 100644 --- a/test/language/import/import-defer/errors/module-throws/third-party-evaluation-after-defer-import.js +++ b/test/language/import/import-defer/errors/module-throws/third-party-evaluation-after-defer-import.js @@ -26,7 +26,7 @@ info: | flags: [module, async] features: [import-defer] -include: [asyncHelpers.js] +includes: [asyncHelpers.js] ---*/ import defer * as ns from "./throws_FIXTURE.js"; diff --git a/test/language/import/import-defer/evaluation-sync/module-imported-defer-and-eager.js b/test/language/import/import-defer/evaluation-sync/module-imported-defer-and-eager.js index a22df19ed29..d488fc4f980 100644 --- a/test/language/import/import-defer/evaluation-sync/module-imported-defer-and-eager.js +++ b/test/language/import/import-defer/evaluation-sync/module-imported-defer-and-eager.js @@ -1,5 +1,5 @@ // Copyright (C) 2024 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license _found_ in the LICENSE file. +// This code is governed by the BSD license found in the LICENSE file. /*--- esid: sec-static-semantics-modulerequests From 75a6e1ccc1bc8e6e73d1758ee987d5016c036d93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Fri, 8 Nov 2024 10:26:52 +0100 Subject: [PATCH 12/13] Typos and add missing include --- .../errors/get-other-while-dep-evaluating-async/main.js | 2 +- .../errors/module-throws/defer-import-after-evaluation.js | 4 ++-- .../third-party-evaluation-after-defer-import.js | 4 ++-- .../errors/module-throws/trigger-evaluation.js | 1 + .../evaluation-top-level-await/flattening-order/main.js | 8 ++++---- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/main.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/main.js index 9606f1a127c..67f72ff87e3 100644 --- a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/main.js +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/main.js @@ -39,7 +39,7 @@ includes: [asyncHelpers.js] import { done } from "./promises_FIXTURE.js"; import "./dep-1-tla_FIXTURE.js"; -asyncText(async () => { +asyncTest(async () => { await done; assert(globalThis["error on ns.foo while evaluating"] instanceof TypeError, "ns.foo while evaluating throws a TypeError"); assert(globalThis["error on ns.foo while evaluating-async"] instanceof TypeError, "ns.foo while evaluating-async throws a TypeError"); diff --git a/test/language/import/import-defer/errors/module-throws/defer-import-after-evaluation.js b/test/language/import/import-defer/errors/module-throws/defer-import-after-evaluation.js index 865e4397d6c..92b6bdf7402 100644 --- a/test/language/import/import-defer/errors/module-throws/defer-import-after-evaluation.js +++ b/test/language/import/import-defer/errors/module-throws/defer-import-after-evaluation.js @@ -26,10 +26,10 @@ info: | flags: [module, async] features: [import-defer] -includes: [asyncHelpers.js] +includes: [asyncHelpers.js, deepEqual.js] ---*/ -asyncText(async () => { +asyncTest(async () => { let err1; await import("./throws_FIXTURE.js").catch((e) => { err1 = e }); assert.deepEqual(err1, { someError: "the error from throws_FIXTURE" }); diff --git a/test/language/import/import-defer/errors/module-throws/third-party-evaluation-after-defer-import.js b/test/language/import/import-defer/errors/module-throws/third-party-evaluation-after-defer-import.js index 4e9780fe329..42b86f7b443 100644 --- a/test/language/import/import-defer/errors/module-throws/third-party-evaluation-after-defer-import.js +++ b/test/language/import/import-defer/errors/module-throws/third-party-evaluation-after-defer-import.js @@ -26,12 +26,12 @@ info: | flags: [module, async] features: [import-defer] -includes: [asyncHelpers.js] +includes: [asyncHelpers.js, deepEqual.js] ---*/ import defer * as ns from "./throws_FIXTURE.js"; -asyncText(async () => { +asyncTest(async () => { let err1; await import("./throws_FIXTURE.js").catch((e) => { err1 = e }); assert.deepEqual(err1, { someError: "the error from throws_FIXTURE" }); diff --git a/test/language/import/import-defer/errors/module-throws/trigger-evaluation.js b/test/language/import/import-defer/errors/module-throws/trigger-evaluation.js index e18d4dec0f8..337b49c96cd 100644 --- a/test/language/import/import-defer/errors/module-throws/trigger-evaluation.js +++ b/test/language/import/import-defer/errors/module-throws/trigger-evaluation.js @@ -26,6 +26,7 @@ info: | flags: [module] features: [import-defer] +includes: [deepEqual.js] ---*/ import defer * as ns from "./throws_FIXTURE.js"; diff --git a/test/language/import/import-defer/evaluation-top-level-await/flattening-order/main.js b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/main.js index 010d0539779..15b4ad9c9d8 100644 --- a/test/language/import/import-defer/evaluation-top-level-await/flattening-order/main.js +++ b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/main.js @@ -48,10 +48,10 @@ includes: [compareArray.js] import "./setup_FIXTURE.js"; import "./dep-1_FIXTURE.js"; -import defer * as ns2 from "./dep-2_FIXTURE.js.js"; -import "./dep-3_FIXTURE.js.js"; -import defer * as ns4 from "./dep-4_FIXTURE.js.js"; -import "./dep-5_FIXTURE.js.js"; +import defer * as ns2 from "./dep-2_FIXTURE.js"; +import "./dep-3_FIXTURE.js"; +import defer * as ns4 from "./dep-4_FIXTURE.js"; +import "./dep-5_FIXTURE.js"; assert.compareArray(globalThis.evaluations, [ "1", From 2e0982e6ec3659f6afd64cf9e4c12d1d19c32f78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Mon, 11 Nov 2024 10:39:31 +0100 Subject: [PATCH 13/13] More fixes --- .../dep-1-tla_FIXTURE.js | 2 +- .../get-other-while-evaluating-async/dep-1-tla_FIXTURE.js | 2 +- .../flattening-order/dep-2.1.1-tla_FIXTURE.js | 6 +++++- .../flattening-order/dep-2.2.1_FIXTURE.js | 6 +----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1-tla_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1-tla_FIXTURE.js index 67acb62969d..535f9353494 100644 --- a/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1-tla_FIXTURE.js +++ b/test/language/import/import-defer/errors/get-other-while-dep-evaluating-async/dep-1-tla_FIXTURE.js @@ -1,7 +1,7 @@ // Copyright (C) 2024 Igalia, S.L. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. -import { resolveFirst, resolveThird } from "./promises_FIXTURE.js"; +import { resolveFirst, resolveThird, second } from "./promises_FIXTURE.js"; import "./dep-1.1_FIXTURE.js" await Promise.resolve(); diff --git a/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1-tla_FIXTURE.js b/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1-tla_FIXTURE.js index a0c6dcfb979..6e399aa3ccd 100644 --- a/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1-tla_FIXTURE.js +++ b/test/language/import/import-defer/errors/get-other-while-evaluating-async/dep-1-tla_FIXTURE.js @@ -1,7 +1,7 @@ // Copyright (C) 2024 Igalia, S.L. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. -import { resolveFirst, resolveThird } from "./promises_FIXTURE.js"; +import { resolveFirst, resolveThird, second } from "./promises_FIXTURE.js"; import "./dep-1.1_FIXTURE.js" await Promise.resolve(); diff --git a/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.1.1-tla_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.1.1-tla_FIXTURE.js index 092c022fed0..6a4e668524b 100644 --- a/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.1.1-tla_FIXTURE.js +++ b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.1.1-tla_FIXTURE.js @@ -1,4 +1,8 @@ // Copyright (C) 2024 Igalia, S.L. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. -globalThis.evaluations.push("2.1.1"); +globalThis.evaluations.push("2.1.1 start"); + +await Promise.resolve(0); + +globalThis.evaluations.push("2.1.1 end"); diff --git a/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.2.1_FIXTURE.js b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.2.1_FIXTURE.js index 9161bb58280..b04fbc6e931 100644 --- a/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.2.1_FIXTURE.js +++ b/test/language/import/import-defer/evaluation-top-level-await/flattening-order/dep-2.2.1_FIXTURE.js @@ -1,8 +1,4 @@ // Copyright (C) 2024 Igalia, S.L. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. -globalThis.evaluations.push("2.2 start"); - -await Promise.resolve(0); - -globalThis.evaluations.push("2.2 end"); +globalThis.evaluations.push("2.2.1");