diff --git a/test/language/module-code/dynamic-import/eval-self-once.js b/test/language/module-code/dynamic-import/eval-self-once-module.js similarity index 87% rename from test/language/module-code/dynamic-import/eval-self-once.js rename to test/language/module-code/dynamic-import/eval-self-once-module.js index 28cb8544c6be098c8eb13680682f3864964c1e83..5d158bb927c02e986dcd4c8118da851d8aad77eb 100644 --- a/test/language/module-code/dynamic-import/eval-self-once.js +++ b/test/language/module-code/dynamic-import/eval-self-once-module.js @@ -11,8 +11,11 @@ info: | a. Let requiredModule be ? HostResolveImportedModule(module, required). b. Perform ? requiredModule.ModuleEvaluation(). [...] + + This test is meant to be flagged as module code, it should not initially + run as script code or the result will not be the same. includes: [fnGlobalObject.js] -flags: [async] +flags: [async, module] features: [dynamic-import] ---*/ diff --git a/test/language/module-code/dynamic-import/eval-self-once-script.js b/test/language/module-code/dynamic-import/eval-self-once-script.js new file mode 100644 index 0000000000000000000000000000000000000000..03b1288ecfb369c5d16009f492aa2213444ba013 --- /dev/null +++ b/test/language/module-code/dynamic-import/eval-self-once-script.js @@ -0,0 +1,38 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Script is evaluated exactly once after loaded by import +esid: sec-hostimportmoduledynamically +info: | + Success path + + The completion value of any subsequent call to HostResolveImportedModule after + FinishDynamicImport has completed, given the arguments referencingScriptOrModule + and specifier, must be a module which has already been evaluated, i.e. whose + Evaluate concrete method has already been called and returned a normal completion. + + This test is meant to __not__ be flagged as module code, it should not initially + run as module code or the result will not be the same. +includes: [fnGlobalObject.js] +flags: [async] +features: [dynamic-import] +---*/ + +var global = fnGlobalObject(); + +if (typeof global.evaluated === 'undefined') { + global.evaluated = 0; +} + +global.evaluated++; + +Promise.all([ + import('./eval-self-once-script.js'), + import('./eval-self-once-script.js'), +]).then(async () => { + // Use await to serialize imports + await import('./eval-self-once-script.js'); + await import('./eval-self-once-script.js'); + + assert.sameValue(global.evaluated, 2, 'global property was defined and incremented only once'); +}).then($DONE, $DONE);