always-create-new-promise.js (1523B)
1 // Copyright (C) 2018 Leo Balter. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 description: > 5 ImportCall returns a new instance of Promise 6 esid: sec-import-call-runtime-semantics-evaluation 7 info: | 8 Import Calls 9 10 Runtime Semantics: Evaluation 11 12 ImportCall : import(AssignmentExpression) 13 14 1. Let referencingScriptOrModule be ! GetActiveScriptOrModule(). 15 2. Let argRef be the result of evaluating AssignmentExpression. 16 3. Let specifier be ? GetValue(argRef). 17 4. Let promiseCapability be ! NewPromiseCapability(%Promise%). 18 5. Let specifierString be ToString(specifier). 19 6. IfAbruptRejectPromise(specifierString, promiseCapability). 20 7. Perform ! HostImportModuleDynamically(referencingScriptOrModule, specifierString, promiseCapability). 21 8. Return promiseCapability.[[Promise]]. 22 features: [dynamic-import] 23 ---*/ 24 25 const p1 = import('./dynamic-import-module_FIXTURE.js'); 26 const p2 = import('./dynamic-import-module_FIXTURE.js'); 27 28 assert.notSameValue(p1, p2, 'the returned promises are not the same, regardless the reference and specifier pair'); 29 30 assert.sameValue(p1.constructor, Promise, 'p1 constructor is %Promise%'); 31 assert.sameValue(Object.getPrototypeOf(p1), Promise.prototype, 'p1 prototype is %PromisePrototype%'); 32 33 assert.sameValue(p2.constructor, Promise, 'p2 constructor is %Promise%'); 34 assert.sameValue(Object.getPrototypeOf(p2), Promise.prototype, 'p2 prototype is %PromisePrototype%'); 35 36 reportCompare(0, 0);