promise-then-ns-define-own-property.js (7052B)
1 // |reftest| async 2 // This file was procedurally generated from the following sources: 3 // - src/dynamic-import/ns-define-own-property.case 4 // - src/dynamic-import/namespace/promise.template 5 /*--- 6 description: The [[DefineOwnProperty]] internal method returns `true` if no change is requested, and `false` otherwise. (value from promise then) 7 esid: sec-finishdynamicimport 8 features: [Symbol.iterator, Reflect, Symbol, Symbol.toStringTag, dynamic-import] 9 flags: [generated, async] 10 info: | 11 Runtime Semantics: FinishDynamicImport ( referencingScriptOrModule, specifier, promiseCapability, completion ) 12 13 1. If completion is an abrupt completion, ... 14 2. Otherwise, 15 ... 16 d. Let namespace be GetModuleNamespace(moduleRecord). 17 e. If namespace is an abrupt completion, perform ! Call(promiseCapability.[[Reject]], undefined, « namespace.[[Value]] »). 18 f. Otherwise, perform ! Call(promiseCapability.[[Resolve]], undefined, « namespace.[[Value]] »). 19 20 Runtime Semantics: GetModuleNamespace ( module ) 21 22 ... 23 3. Let namespace be module.[[Namespace]]. 24 4. If namespace is undefined, then 25 a. Let exportedNames be ? module.GetExportedNames(« »). 26 b. Let unambiguousNames be a new empty List. 27 c. For each name that is an element of exportedNames, do 28 i. Let resolution be ? module.ResolveExport(name, « »). 29 ii. If resolution is a ResolvedBinding Record, append name to unambiguousNames. 30 d. Set namespace to ModuleNamespaceCreate(module, unambiguousNames). 31 5. Return namespace. 32 33 ModuleNamespaceCreate ( module, exports ) 34 35 ... 36 4. Let M be a newly created object. 37 5. Set M's essential internal methods to the definitions specified in 9.4.6. 38 7. Let sortedExports be a new List containing the same values as the list exports where the 39 values are ordered as if an Array of the same values had been sorted using Array.prototype.sort 40 using undefined as comparefn. 41 8. Set M.[[Exports]] to sortedExports. 42 9. Create own properties of M corresponding to the definitions in 26.3. 43 10. Set module.[[Namespace]] to M. 44 11. Return M. 45 46 26.3 Module Namespace Objects 47 48 A Module Namespace Object is a module namespace exotic object that provides runtime 49 property-based access to a module's exported bindings. There is no constructor function for 50 Module Namespace Objects. Instead, such an object is created for each module that is imported 51 by an ImportDeclaration that includes a NameSpaceImport. 52 53 In addition to the properties specified in 9.4.6 each Module Namespace Object has the 54 following own property: 55 56 26.3.1 @@toStringTag 57 58 The initial value of the @@toStringTag property is the String value "Module". 59 60 This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. 61 62 Module Namespace Exotic Objects 63 64 A module namespace object is an exotic object that exposes the bindings exported from an 65 ECMAScript Module (See 15.2.3). There is a one-to-one correspondence between the String-keyed 66 own properties of a module namespace exotic object and the binding names exported by the 67 Module. The exported bindings include any bindings that are indirectly exported using export * 68 export items. Each String-valued own property key is the StringValue of the corresponding 69 exported binding name. These are the only String-keyed properties of a module namespace exotic 70 object. Each such property has the attributes { [[Writable]]: true, [[Enumerable]]: true, 71 [[Configurable]]: false }. Module namespace objects are not extensible. 72 73 ---*/ 74 var sym = Symbol('test262'); 75 76 const exported = ['local1', 'renamed', 'indirect']; 77 78 79 import('./define-own-property_FIXTURE.js').then(ns => { 80 81 // Non-existant properties. 82 83 for (const key of ['local2', 0, sym, Symbol.iterator]) { 84 assert.sameValue( 85 Reflect.defineProperty(ns, key, {}), 86 false, 87 'Reflect.defineProperty: ' + key.toString() 88 ); 89 assert.throws(TypeError, function() { 90 Object.defineProperty(ns, key, {}); 91 }, 'Object.defineProperty: ' + key.toString()); 92 } 93 94 // Own properties. No change requested. 95 96 for (const key of ([...exported, Symbol.toStringTag])) { 97 assert.sameValue( 98 Reflect.defineProperty(ns, key, {}), 99 true, 100 `No change requested, Reflect.defineProperty: ${key.toString()}` 101 ); 102 assert.sameValue( 103 Object.defineProperty(ns, key, {}), 104 ns, 105 `No change requested, Object.defineProperty: ${key.toString()}` 106 ); 107 108 } 109 110 assert.sameValue( 111 Reflect.defineProperty(ns, 'indirect', 112 {writable: true, enumerable: true, configurable: false}), 113 true, 114 'Reflect.defineProperty: indirect' 115 ); 116 assert.sameValue( 117 Object.defineProperty(ns, 'indirect', 118 {writable: true, enumerable: true, configurable: false}), 119 ns, 120 'Object.defineProperty: indirect' 121 ); 122 123 assert.sameValue( 124 Reflect.defineProperty(ns, Symbol.toStringTag, 125 {value: "Module", writable: false, enumerable: false, 126 configurable: false}), 127 true, 128 'Reflect.defineProperty: Symbol.toStringTag' 129 ); 130 assert.sameValue( 131 Object.defineProperty(ns, Symbol.toStringTag, 132 {value: "Module", writable: false, enumerable: false, 133 configurable: false}), 134 ns, 135 'Object.defineProperty: Symbol.toStringTag' 136 ); 137 138 139 // Own properties. Change requested. 140 141 for (const key of ([...exported, Symbol.toStringTag])) { 142 assert.sameValue( 143 Reflect.defineProperty(ns, key, {value: 123}), 144 false, 145 `Change requested, Reflect.defineProperty: ${key.toString()}` 146 ); 147 assert.throws(TypeError, function() { 148 Object.defineProperty(ns, key, {value: 123}); 149 }, `Change requested, Object.defineProperty: ${key.toString()}`); 150 } 151 152 assert.sameValue( 153 Reflect.defineProperty(ns, 'indirect', 154 {writable: true, enumerable: true, configurable: true}), 155 false, 156 'Reflect.defineProperty: indirect' 157 ); 158 assert.throws(TypeError, function() { 159 Object.defineProperty(ns, 'indirect', 160 {writable: true, enumerable: true, configurable: true}); 161 }, 'Object.defineProperty: indirect'); 162 163 assert.sameValue( 164 Reflect.defineProperty(ns, Symbol.toStringTag, 165 {value: "module", writable: false, enumerable: false, 166 configurable: false}), 167 false, 168 'Reflect.defineProperty: Symbol.toStringTag' 169 ); 170 assert.throws(TypeError, function() { 171 Object.defineProperty(ns, Symbol.toStringTag, 172 {value: "module", writable: false, enumerable: false, 173 configurable: false}); 174 }, 'Object.defineProperty: Symbol.toStringTag'); 175 176 }).then($DONE, $DONE).catch($DONE);