diff --git a/README.md b/README.md index 523bc26a..72586569 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ will generate a JavaScript wrapper class file roughly like this: ```js const conversions = require("webidl-conversions"); const impl = require("./utils.js").implSymbol; +const ctorRegistry = require("./utils.js").ctorRegistrySymbol; const Impl = require("./SomeInterface-impl.js").implementation; @@ -64,10 +65,9 @@ Object.defineProperties(SomeInterface.prototype, { [Symbol.toStringTag]: { value: "SomeInterface", configurable: true } }); -exports.interface = SomeInterface; - -exports.create = (constructorArgs = [], privateData = {}) => { - const obj = Object.create(SomeInterface.prototype); +exports.create = (globalObject, constructorArgs = [], privateData = {}) => { + const ctor = globalObject[ctorRegistry].SomeInterface; + const obj = Object.create(ctor.prototype); obj[impl] = new Impl(constructorArgs, privateData); return obj; }; @@ -151,46 +151,28 @@ Performs the Web IDL conversion algorithm for this interface, converting _value_ In practice, this means doing a type-check equivalent to `is(value)`, and if it passes, returns the corresponding impl. If the type-check fails, it throws an informative exception. _context_ can be used to describe the provided value in any resulting error message. -#### `create(constructorArgs, privateData)` +#### `install(globalObject)` + +This method creates a brand new wrapper constructor and prototype and attach it to the passed `globalObject`. It also registers the created constructor with the `globalObject`'s global constructor registry, which makes `create()`, `createImpl()`, and `setup()` work. (Thus, it is important to invoke `install()` before invoking those methods, as otherwise they will throw.) -Creates a new instance of the wrapper class and corresponding implementation class, passing in the `constructorArgs` array and `privateData` object to the implementation class constructor. Then returns the wrapper class. +#### `create(globalObject, constructorArgs, privateData)` + +Creates a new instance of the wrapper class and corresponding implementation class, passing in the `globalObject`, the `constructorArgs` array and `privateData` object to the implementation class constructor. Then returns the wrapper class. This is useful in other parts of your program that are not implementation class files, but instead want to interface with them from the outside. It's also mostly useful when creating instances of classes that do not have a `[Constructor]`, i.e. are not constructible via their wrapper class constructor. -#### `createImpl(constructorArgs, privateData)` +#### `createImpl(globalObject, constructorArgs, privateData)` -Creates a new instance of the wrapper class and corresponding implementation class, passing in the `constructorArgs` array and `privateData` object to the implementation class constructor. Then returns the implementation class. +Creates a new instance of the wrapper class and corresponding implementation class, passing in the `globalObject`, the `constructorArgs` array and `privateData` object to the implementation class constructor. Then returns the implementation class. This is useful inside implementation class files, where it is easiest to only deal with impls, not wrappers. -#### `setup(obj, constructorArgs, privateData)` +#### `setup(obj, globalObject, constructorArgs, privateData)` -This function is mostly used internally, and almost never should be called by your code. The one exception is if you need to inherit from a wrapper class corresponding to an interface without a `[Constructor]`, from a non-webidl2js-generated class. Then, you can call `SuperClass.setup(this, [], privateData)` as a substitute for doing `super()` (which would throw). +This function is mostly used internally, and almost never should be called by your code. The one exception is if you need to inherit from a wrapper class corresponding to an interface without a `[Constructor]`, from a non-webidl2js-generated class. Then, you can call `SuperClass.setup(this, globalObject, [], privateData)` as a substitute for doing `super()` (which would throw). jsdom does this for `Window`, which is written in custom, non-webidl2js-generated code, but inherits from `EventTarget`, which is generated by webidl2js. -#### `interface` - -This export is the wrapper class interface, suitable for example for putting on a global scope or exporting to module consumers who don't know anything about webidl2js. - -#### `expose` - -This export contains information about where an interface is supposed to be exposed as a property. It takes into account the Web IDL extended attribute `[Exposed]` to generate a data structure of the form: - -```js -{ - nameOfGlobal1: { - nameOfInterface: InterfaceClass - }, - nameOfGlobal2: { - nameOfInterface: InterfaceClass - }, - // etc. -} -``` - -This format may seem a bit verbose, but eventually when we support `[NamedConstructor]`, there will be potentially more than one key/value pair per global, and it will show its worth. - ### For dictionaries #### `convert(value, { context })` @@ -207,9 +189,10 @@ Implementation class files contain a single export, `implementation`, whose valu ### The constructor -A constructor for your implementation class, with signature `(constructorArgs, privateData)` can serve several purposes: +A constructor for your implementation class, with signature `(globalObject, constructorArgs, privateData)` can serve several purposes: - Setting up initial state that will always be used, such as caches or default values +- Keep a reference to the relevant `globalObject` for later consumption. - Processing constructor arguments `constructorArgs` passed to the wrapper class constructor, if the interface in question has a `[Constructor]` extended attribute. - Processing any private data `privateData` which is provided when other parts of your program use the generated `create()` or `createImpl()` exports of the wrapper class file. This is useful for constructing instances with specific state that cannot be constructed via the wrapper class constructor. @@ -247,7 +230,7 @@ Note that for IDL attributes that are `readonly`, these properties do not need t #### Static attributes -Just like static operations, static attributes are defined as properties on the constructor of the implementation class. And just like other attributes, the attribute can either be implemented as an accessor attribute or (if it is readonly) a data attribute. Note that, unless the `[WebIDL2JSFactory]` extended attribute is specified on the interface, any mutations to writable static attributes of the class will reflect on other places that use the same interface. +Just like static operations, static attributes are defined as properties on the constructor of the implementation class. And just like other attributes, the attribute can either be implemented as an accessor attribute or (if it is readonly) a data attribute. ### toString method implementing IDL stringifier @@ -386,12 +369,6 @@ Note that only the basics of the reflect algorithm are implemented so far: `bool In the future we may move this extended attribute out into some sort of plugin, since it is more related to HTML than to Web IDL. -### `[WebIDL2JSFactory]` - -This extended attribute can be applied to interfaces to cause them to generate a factory that generates wrapper classes, instead of generating a single wrapper class. - -It is currently used by [jsdom](https://github.com/tmpvar/jsdom) for classes which need to specialize their behavior per `Window` object; by default [jsdom shares classes across all `Window`s](https://github.com/tmpvar/jsdom#shared-constructors-and-prototypes), but with `[WebIDL2JSFactory]`, an exception can be made for certain classes that need it. - ### `[WebIDL2JSValueAsUnsupported=value]` This extended attribute can be applied to named or indexed getters or setters. It says that whether the interface supports a given property name/index can be automatically derived by looking at the return value of its indexed getter/setter: whenever `value` is returned, the name/index is unsupported. Typically, `value` is either `undefined` or `_null`. diff --git a/lib/constructs/interface.js b/lib/constructs/interface.js index 7e100670..e4b89b4b 100644 --- a/lib/constructs/interface.js +++ b/lib/constructs/interface.js @@ -66,7 +66,6 @@ class Interface { this.ctx = ctx; this.idl = idl; this.name = idl.name; - this.factory = Boolean(utils.getExtAttr(this.idl.extAttrs, "WebIDL2JSFactory")); for (const member of this.idl.members) { member.definingInterface = this.name; } @@ -496,6 +495,7 @@ class Interface { generateRequires() { this.requires.addRaw("impl", "utils.implSymbol"); + this.requires.addRaw("ctorRegistry", "utils.ctorRegistrySymbol"); if (this.idl.inheritance !== null) { this.requires.add(this.idl.inheritance); @@ -1093,40 +1093,23 @@ class Interface { } generateIface() { - const exposedAttrs = this.idl.extAttrs - .filter(attr => attr.name === "Exposed"); - if (exposedAttrs.length === 0) { - throw new Error(`Missing [Exposed] extended attribute on ${this.name}`); - } - if (exposedAttrs.length > 1) { - throw new Error(`Too many [Exposed] extended attributes on ${this.name}`); - } - - const rhs = exposedAttrs[0].rhs.value; - const exposedOn = typeof rhs === "string" ? [rhs] : rhs.map(arg => arg.value); - - const exposedMap = {}; - for (let i = 0; i < exposedOn.length; ++i) { - if (!exposedMap[exposedOn[i]]) { - exposedMap[exposedOn[i]] = []; - } - exposedMap[exposedOn[i]].push(this.name); - } + this.str += ` + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error('Internal error: invalid global object'); + } - const exposers = []; - for (let keys = Object.keys(exposedMap), i = 0; i < keys.length; ++i) { - exposers.push(keys[i] + ": { " + exposedMap[keys[i]].join(", ") + " }"); - } + const ctor = globalObject[ctorRegistry]["${this.name}"]; + if (ctor === undefined) { + throw new Error('Internal error: constructor ${this.name} is not installed on the passed global object'); + } - this.str += ` - create(constructorArgs, privateData) { - let obj = Object.create(${this.name}.prototype); - obj = this.setup(obj, constructorArgs, privateData); + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(${this.name}.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) { @@ -1142,26 +1125,12 @@ class Interface { this.str += ` }, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - `; - - if (this.factory) { - this.str += ` - for (var prop in defaultPrivateData) { - if (!(prop in privateData)) { - privateData[prop] = defaultPrivateData[prop]; - } - } - `; - } - - this.str += ` + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); `; @@ -1177,10 +1146,6 @@ class Interface { } return obj; }, - interface: ${this.name}, - expose: { - ${exposers.join(",\n ")} - } `; } @@ -1203,10 +1168,15 @@ class Interface { this.ctx, "constructor", this.name, this, `Failed to construct '${this.name}': `); this.requires.merge(conversions.requires); - const passArgs = conversions.hasArgs ? ", args" : ""; + const setupArgs = [ + "Object.create(new.target.prototype)", + "globalObject", + conversions.hasArgs ? "args" : "undefined" + ]; + body = ` ${conversions.body} - return iface.setup(Object.create(new.target.prototype)${passArgs}); + return iface.setup(${formatArgs(setupArgs)}); `; } else { body = ` @@ -1279,7 +1249,7 @@ class Interface { continue; } - const propName = utils.stringifyPropertyName(name); + const propName = utils.stringifyPropertyKey(name); if (type === "regular") { addOne(propName, args, body); } else { @@ -1293,7 +1263,7 @@ class Interface { } for (const [name, { type, args, body }] of this._outputStaticMethods) { - const propName = utils.stringifyPropertyName(name); + const propName = utils.stringifyPropertyKey(name); if (type === "regular") { addOne(`static ${propName}`, args, body); } else { @@ -1330,7 +1300,7 @@ class Interface { if (descriptorModifier === undefined) { continue; } - protoProps.set(utils.stringifyPropertyName(name), descriptorModifier); + protoProps.set(utils.stringifyPropertyKey(name), descriptorModifier); } for (const [name, { type, descriptor }] of this._outputStaticMethods) { @@ -1338,7 +1308,7 @@ class Interface { if (descriptorModifier === undefined) { continue; } - classProps.set(utils.stringifyPropertyName(name), descriptorModifier); + classProps.set(utils.stringifyPropertyKey(name), descriptorModifier); } for (const [name, { whence, body, descriptor }] of this._outputProperties) { @@ -1348,13 +1318,13 @@ class Interface { const descriptorModifier = getPropertyDescriptorModifier(defaultDefinePropertyDescriptor, descriptor, "regular", body); - protoProps.set(utils.stringifyPropertyName(name), descriptorModifier); + protoProps.set(utils.stringifyPropertyKey(name), descriptorModifier); } for (const [name, { body, descriptor }] of this._outputStaticProperties) { const descriptorModifier = getPropertyDescriptorModifier(defaultDefinePropertyDescriptor, descriptor, "regular", body); - classProps.set(utils.stringifyPropertyName(name), descriptorModifier); + classProps.set(utils.stringifyPropertyKey(name), descriptorModifier); } if (protoProps.size > 0) { @@ -1383,7 +1353,7 @@ class Interface { continue; } - const propName = utils.stringifyPropertyName(name); + const propName = utils.stringifyPropertyKey(name); if (type === "regular") { addOne(propName, args, body); } else { @@ -1399,7 +1369,7 @@ class Interface { if (descriptorModifier === undefined) { continue; } - props.set(utils.stringifyPropertyName(name), descriptorModifier); + props.set(utils.stringifyPropertyKey(name), descriptorModifier); } for (const [name, { whence, body, descriptor }] of this._outputProperties) { @@ -1407,7 +1377,7 @@ class Interface { continue; } - const propName = utils.stringifyPropertyName(name); + const propName = utils.stringifyPropertyKey(name); methods.push(`${propName}: ${body}`); const descriptorModifier = getPropertyDescriptorModifier(defaultObjectLiteralDescriptor, descriptor, "regular"); @@ -1436,48 +1406,59 @@ class Interface { } } - generate() { - this.generateIterator(); + generateInstall() { + const { idl, name } = this; - if (this.factory) { + this.str += ` + install(globalObject) { + `; + + if (idl.inheritance) { this.str += ` - module.exports = { - createInterface: function (defaultPrivateData = {}) { + if (globalObject.${idl.inheritance} === undefined) { + throw new Error('Internal error: attempting to evaluate ${name} before ${idl.inheritance}'); + } `; } - const ext = this.idl.inheritance ? ` extends ${this.idl.inheritance}.interface` : ""; - this.str += `class ${this.name}${ext} {`; + const ext = idl.inheritance ? ` extends globalObject.${idl.inheritance}` : ""; + this.str += `class ${name}${ext} {`; this.generateOffInstanceMethods(); - this.str += "}"; this.generateOffInstanceAfterClass(); + this.str += ` + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry]["${name}"] = ${name}; + + Object.defineProperty(globalObject, "${name}", { + configurable: true, + writable: true, + value: ${name} + }); + }, + `; + } + + generate() { + this.generateIterator(); + this.str += ` const iface = { `; - if (this.factory) { - this.generateIface(); - this.str += ` - }; // iface - return iface; - }, // createInterface - `; - this.generateExport(); - this.str += ` - }; // module.exports - `; - } else { - this.generateExport(); - this.generateIface(); - this.str += ` - }; // iface - module.exports = iface; - `; - } + this.generateExport(); + this.generateIface(); + this.generateInstall(); + + this.str += ` + }; // iface + module.exports = iface; + `; this.generateMixins(); this.generateRequires(); diff --git a/lib/output/utils.js b/lib/output/utils.js index 0b0b0d49..3618315d 100644 --- a/lib/output/utils.js +++ b/lib/output/utils.js @@ -12,6 +12,7 @@ function hasOwn(obj, prop) { const wrapperSymbol = Symbol("wrapper"); const implSymbol = Symbol("impl"); const sameObjectCaches = Symbol("SameObject caches"); +const ctorRegistrySymbol = Symbol.for("[webidl2js] constructor registry"); function getSameObject(wrapper, prop, creator) { if (!wrapper[sameObjectCaches]) { @@ -80,6 +81,7 @@ module.exports = exports = { wrapperSymbol, implSymbol, getSameObject, + ctorRegistrySymbol, wrapperForImpl, implForWrapper, tryWrapperForImpl, diff --git a/lib/utils.js b/lib/utils.js index 9c1f95b1..423fcfcc 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -36,21 +36,29 @@ function isOnInstance(memberIDL, interfaceIDL) { return memberIDL.special !== "static" && (getExtAttr(memberIDL.extAttrs, "Unforgeable") || isGlobal(interfaceIDL)); } -function stringifyPropertyName(propName) { - if (typeof propName === "symbol") { - const desc = String(propName).replace(/^Symbol\((.*)\)$/, "$1"); - if (!desc.startsWith("Symbol.")) { - throw new Error(`Internal error: Unsupported property name ${String(propName)}`); - } - return `[${desc}]`; +function symbolName(symbol) { + const desc = String(symbol).replace(/^Symbol\((.*)\)$/, "$1"); + if (!desc.startsWith("Symbol.")) { + throw new Error(`Internal error: Unsupported property name ${String(symbol)}`); } + return desc; +} +function propertyName(name) { // All Web IDL identifiers are valid JavaScript PropertyNames, other than those with '-'. - const isJSIdentifier = !propName.includes("-"); + const isJSIdentifier = !name.includes("-"); if (isJSIdentifier) { - return propName; + return name; } - return JSON.stringify(propName); + return JSON.stringify(name); +} + +function stringifyPropertyKey(prop) { + return typeof prop === "symbol" ? `[${symbolName(prop)}]` : propertyName(prop); +} + +function stringifyPropertyName(prop) { + return typeof prop === "symbol" ? symbolName(prop) : JSON.stringify(propertyName(prop)); } class RequiresMap extends Map { @@ -94,6 +102,7 @@ module.exports = { getExtAttr, isGlobal, isOnInstance, + stringifyPropertyKey, stringifyPropertyName, RequiresMap }; diff --git a/test/__snapshots__/test.js.snap b/test/__snapshots__/test.js.snap index 8f0bf689..aaf336f5 100644 --- a/test/__snapshots__/test.js.snap +++ b/test/__snapshots__/test.js.snap @@ -7,129 +7,8 @@ const conversions = require(\\"webidl-conversions\\"); const utils = require(\\"./utils.js\\"); const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; -class DOMImplementation { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } - - createDocumentType(qualifiedName, publicId, systemId) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - if (arguments.length < 3) { - throw new TypeError( - \\"Failed to execute 'createDocumentType' on 'DOMImplementation': 3 arguments required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'createDocumentType' on 'DOMImplementation': parameter 1\\" - }); - args.push(curArg); - } - { - let curArg = arguments[1]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'createDocumentType' on 'DOMImplementation': parameter 2\\" - }); - args.push(curArg); - } - { - let curArg = arguments[2]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'createDocumentType' on 'DOMImplementation': parameter 3\\" - }); - args.push(curArg); - } - return utils.tryWrapperForImpl(this[impl].createDocumentType(...args)); - } - - createDocument(namespace, qualifiedName) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - if (arguments.length < 2) { - throw new TypeError( - \\"Failed to execute 'createDocument' on 'DOMImplementation': 2 arguments required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - if (curArg === null || curArg === undefined) { - curArg = null; - } else { - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'createDocument' on 'DOMImplementation': parameter 1\\" - }); - } - args.push(curArg); - } - { - let curArg = arguments[1]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'createDocument' on 'DOMImplementation': parameter 2\\", - treatNullAsEmptyString: true - }); - args.push(curArg); - } - { - let curArg = arguments[2]; - if (curArg !== undefined) { - if (curArg === null || curArg === undefined) { - curArg = null; - } else { - curArg = utils.tryImplForWrapper(curArg); - } - } else { - curArg = null; - } - args.push(curArg); - } - return utils.tryWrapperForImpl(this[impl].createDocument(...args)); - } - - createHTMLDocument() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - const args = []; - { - let curArg = arguments[0]; - if (curArg !== undefined) { - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'createHTMLDocument' on 'DOMImplementation': parameter 1\\" - }); - } - args.push(curArg); - } - return utils.tryWrapperForImpl(this[impl].createHTMLDocument(...args)); - } - - hasFeature() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - return this[impl].hasFeature(); - } -} -Object.defineProperties(DOMImplementation.prototype, { - createDocumentType: { enumerable: true }, - createDocument: { enumerable: true }, - createHTMLDocument: { enumerable: true }, - hasFeature: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"DOMImplementation\\", configurable: true } -}); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -170,25 +49,31 @@ const iface = { throw new TypeError(\`\${context} is not of type 'DOMImplementation'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(DOMImplementation.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"DOMImplementation\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor DOMImplementation is not installed on the passed global object\\"); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(DOMImplementation.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -198,9 +83,140 @@ const iface = { } return obj; }, - interface: DOMImplementation, - expose: { - Window: { DOMImplementation } + + install(globalObject) { + class DOMImplementation { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } + + createDocumentType(qualifiedName, publicId, systemId) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 3) { + throw new TypeError( + \\"Failed to execute 'createDocumentType' on 'DOMImplementation': 3 arguments required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'createDocumentType' on 'DOMImplementation': parameter 1\\" + }); + args.push(curArg); + } + { + let curArg = arguments[1]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'createDocumentType' on 'DOMImplementation': parameter 2\\" + }); + args.push(curArg); + } + { + let curArg = arguments[2]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'createDocumentType' on 'DOMImplementation': parameter 3\\" + }); + args.push(curArg); + } + return utils.tryWrapperForImpl(this[impl].createDocumentType(...args)); + } + + createDocument(namespace, qualifiedName) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 2) { + throw new TypeError( + \\"Failed to execute 'createDocument' on 'DOMImplementation': 2 arguments required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + if (curArg === null || curArg === undefined) { + curArg = null; + } else { + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'createDocument' on 'DOMImplementation': parameter 1\\" + }); + } + args.push(curArg); + } + { + let curArg = arguments[1]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'createDocument' on 'DOMImplementation': parameter 2\\", + treatNullAsEmptyString: true + }); + args.push(curArg); + } + { + let curArg = arguments[2]; + if (curArg !== undefined) { + if (curArg === null || curArg === undefined) { + curArg = null; + } else { + curArg = utils.tryImplForWrapper(curArg); + } + } else { + curArg = null; + } + args.push(curArg); + } + return utils.tryWrapperForImpl(this[impl].createDocument(...args)); + } + + createHTMLDocument() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + const args = []; + { + let curArg = arguments[0]; + if (curArg !== undefined) { + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'createHTMLDocument' on 'DOMImplementation': parameter 1\\" + }); + } + args.push(curArg); + } + return utils.tryWrapperForImpl(this[impl].createHTMLDocument(...args)); + } + + hasFeature() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return this[impl].hasFeature(); + } + } + Object.defineProperties(DOMImplementation.prototype, { + createDocumentType: { enumerable: true }, + createDocument: { enumerable: true }, + createHTMLDocument: { enumerable: true }, + hasFeature: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"DOMImplementation\\", configurable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"DOMImplementation\\"] = DOMImplementation; + + Object.defineProperty(globalObject, \\"DOMImplementation\\", { + configurable: true, + writable: true, + value: DOMImplementation + }); } }; // iface module.exports = iface; @@ -297,38 +313,8 @@ const utils = require(\\"./utils.js\\"); const convertDictionary = require(\\"./Dictionary.js\\").convert; const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; -class DictionaryConvert { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } - - op() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - const args = []; - { - let curArg = arguments[0]; - if (curArg !== undefined) { - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'op' on 'DictionaryConvert': parameter 1\\" - }); - } - args.push(curArg); - } - { - let curArg = arguments[1]; - curArg = convertDictionary(curArg, { context: \\"Failed to execute 'op' on 'DictionaryConvert': parameter 2\\" }); - args.push(curArg); - } - return this[impl].op(...args); - } -} -Object.defineProperties(DictionaryConvert.prototype, { - op: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"DictionaryConvert\\", configurable: true } -}); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -369,25 +355,31 @@ const iface = { throw new TypeError(\`\${context} is not of type 'DictionaryConvert'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(DictionaryConvert.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"DictionaryConvert\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor DictionaryConvert is not installed on the passed global object\\"); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(DictionaryConvert.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -397,9 +389,49 @@ const iface = { } return obj; }, - interface: DictionaryConvert, - expose: { - Window: { DictionaryConvert } + + install(globalObject) { + class DictionaryConvert { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } + + op() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + const args = []; + { + let curArg = arguments[0]; + if (curArg !== undefined) { + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'op' on 'DictionaryConvert': parameter 1\\" + }); + } + args.push(curArg); + } + { + let curArg = arguments[1]; + curArg = convertDictionary(curArg, { context: \\"Failed to execute 'op' on 'DictionaryConvert': parameter 2\\" }); + args.push(curArg); + } + return this[impl].op(...args); + } + } + Object.defineProperties(DictionaryConvert.prototype, { + op: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"DictionaryConvert\\", configurable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"DictionaryConvert\\"] = DictionaryConvert; + + Object.defineProperty(globalObject, \\"DictionaryConvert\\", { + configurable: true, + writable: true, + value: DictionaryConvert + }); } }; // iface module.exports = iface; @@ -417,57 +449,8 @@ const utils = require(\\"./utils.js\\"); const convertRequestDestination = require(\\"./RequestDestination.js\\").convert; const RequestDestination = require(\\"./RequestDestination.js\\"); const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; -class Enum { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } - - op(destination) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'op' on 'Enum': 1 argument required, but only \\" + arguments.length + \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - curArg = convertRequestDestination(curArg, { context: \\"Failed to execute 'op' on 'Enum': parameter 1\\" }); - args.push(curArg); - } - return this[impl].op(...args); - } - - get attr() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - return utils.tryWrapperForImpl(this[impl][\\"attr\\"]); - } - - set attr(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - V = \`\${V}\`; - if (!RequestDestination.enumerationValues.has(V)) { - return; - } - - this[impl][\\"attr\\"] = V; - } -} -Object.defineProperties(Enum.prototype, { - op: { enumerable: true }, - attr: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"Enum\\", configurable: true } -}); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -508,25 +491,31 @@ const iface = { throw new TypeError(\`\${context} is not of type 'Enum'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(Enum.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"Enum\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor Enum is not installed on the passed global object\\"); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(Enum.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -536,110 +525,86 @@ const iface = { } return obj; }, - interface: Enum, - expose: { - Window: { Enum } - } -}; // iface -module.exports = iface; - -const Impl = require(\\"../implementations/Enum.js\\"); -" -`; - -exports[`Factory.webidl 1`] = ` -"\\"use strict\\"; - -const conversions = require(\\"webidl-conversions\\"); -const utils = require(\\"./utils.js\\"); - -const impl = utils.implSymbol; -module.exports = { - createInterface: function(defaultPrivateData = {}) { - class Factory { + install(globalObject) { + class Enum { constructor() { throw new TypeError(\\"Illegal constructor\\"); } - method() { + op(destination) { if (!this || !module.exports.is(this)) { throw new TypeError(\\"Illegal invocation\\"); } - return this[impl].method(); + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'op' on 'Enum': 1 argument required, but only \\" + arguments.length + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = convertRequestDestination(curArg, { context: \\"Failed to execute 'op' on 'Enum': parameter 1\\" }); + args.push(curArg); + } + return this[impl].op(...args); } - get attribute() { + get attr() { if (!this || !module.exports.is(this)) { throw new TypeError(\\"Illegal invocation\\"); } - return this[impl][\\"attribute\\"]; + return utils.tryWrapperForImpl(this[impl][\\"attr\\"]); } - set attribute(V) { + set attr(V) { if (!this || !module.exports.is(this)) { throw new TypeError(\\"Illegal invocation\\"); } - V = conversions[\\"double\\"](V, { - context: \\"Failed to set the 'attribute' property on 'Factory': The provided value\\" - }); + V = \`\${V}\`; + if (!RequestDestination.enumerationValues.has(V)) { + return; + } - this[impl][\\"attribute\\"] = V; + this[impl][\\"attr\\"] = V; } } - Object.defineProperties(Factory.prototype, { - method: { enumerable: true }, - attribute: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"Factory\\", configurable: true }, - constant: { value: 42, enumerable: true } + Object.defineProperties(Enum.prototype, { + op: { enumerable: true }, + attr: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"Enum\\", configurable: true } }); - Object.defineProperties(Factory, { constant: { value: 42, enumerable: true } }); - const iface = { - create(constructorArgs, privateData) { - let obj = Object.create(Factory.prototype); - obj = this.setup(obj, constructorArgs, privateData); - return obj; - }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(Factory.prototype); - obj = this.setup(obj, constructorArgs, privateData); - return utils.implForWrapper(obj); - }, - _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"Enum\\"] = Enum; - for (var prop in defaultPrivateData) { - if (!(prop in privateData)) { - privateData[prop] = defaultPrivateData[prop]; - } - } + Object.defineProperty(globalObject, \\"Enum\\", { + configurable: true, + writable: true, + value: Enum + }); + } +}; // iface +module.exports = iface; - privateData.wrapper = obj; +const Impl = require(\\"../implementations/Enum.js\\"); +" +`; - this._internalSetup(obj); - Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), - configurable: true - }); +exports[`Global.webidl 1`] = ` +"\\"use strict\\"; - obj[impl][utils.wrapperSymbol] = obj; - if (Impl.init) { - Impl.init(obj[impl], privateData); - } - return obj; - }, - interface: Factory, - expose: { - Window: { Factory } - } - }; // iface - return iface; - }, // createInterface +const conversions = require(\\"webidl-conversions\\"); +const utils = require(\\"./utils.js\\"); +const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; + +const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as // implementing this mixin interface. @@ -676,76 +641,25 @@ module.exports = { if (module.exports.is(obj)) { return utils.implForWrapper(obj); } - throw new TypeError(\`\${context} is not of type 'Factory'.\`); - } -}; // module.exports - -const Impl = require(\\"../implementations/Factory.js\\"); -" -`; - -exports[`Global.webidl 1`] = ` -"\\"use strict\\"; - -const conversions = require(\\"webidl-conversions\\"); -const utils = require(\\"./utils.js\\"); - -const impl = utils.implSymbol; - -class Global { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } -} -Object.defineProperties(Global.prototype, { [Symbol.toStringTag]: { value: \\"Global\\", configurable: true } }); -const iface = { - // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` - // method into this array. It allows objects that directly implements *those* interfaces to be recognized as - // implementing this mixin interface. - _mixedIntoPredicates: [], - is(obj) { - if (obj) { - if (utils.hasOwn(obj, impl) && obj[impl] instanceof Impl.implementation) { - return true; - } - for (const isMixedInto of module.exports._mixedIntoPredicates) { - if (isMixedInto(obj)) { - return true; - } - } - } - return false; + throw new TypeError(\`\${context} is not of type 'Global'.\`); }, - isImpl(obj) { - if (obj) { - if (obj instanceof Impl.implementation) { - return true; - } - const wrapper = utils.wrapperForImpl(obj); - for (const isMixedInto of module.exports._mixedIntoPredicates) { - if (isMixedInto(wrapper)) { - return true; - } - } + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); } - return false; - }, - convert(obj, { context = \\"The provided value\\" } = {}) { - if (module.exports.is(obj)) { - return utils.implForWrapper(obj); + + const ctor = globalObject[ctorRegistry][\\"Global\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor Global is not installed on the passed global object\\"); } - throw new TypeError(\`\${context} is not of type 'Global'.\`); - }, - create(constructorArgs, privateData) { - let obj = Object.create(Global.prototype); - obj = this.setup(obj, constructorArgs, privateData); + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(Global.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) { @@ -834,14 +748,12 @@ const iface = { [Symbol.iterator]: { enumerable: false } }); }, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -851,9 +763,24 @@ const iface = { } return obj; }, - interface: Global, - expose: { - Window: { Global } + + install(globalObject) { + class Global { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } + } + Object.defineProperties(Global.prototype, { [Symbol.toStringTag]: { value: \\"Global\\", configurable: true } }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"Global\\"] = Global; + + Object.defineProperty(globalObject, \\"Global\\", { + configurable: true, + writable: true, + value: Global + }); } }; // iface module.exports = iface; @@ -869,25 +796,8 @@ const conversions = require(\\"webidl-conversions\\"); const utils = require(\\"./utils.js\\"); const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; -class LegacyArrayClass { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } - - get length() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - return this[impl][\\"length\\"]; - } -} -Object.setPrototypeOf(LegacyArrayClass.prototype, Array.prototype); -Object.defineProperties(LegacyArrayClass.prototype, { - length: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"LegacyArrayClass\\", configurable: true } -}); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -928,25 +838,31 @@ const iface = { throw new TypeError(\`\${context} is not of type 'LegacyArrayClass'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(LegacyArrayClass.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"LegacyArrayClass\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor LegacyArrayClass is not installed on the passed global object\\"); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(LegacyArrayClass.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -956,9 +872,36 @@ const iface = { } return obj; }, - interface: LegacyArrayClass, - expose: { - Window: { LegacyArrayClass } + + install(globalObject) { + class LegacyArrayClass { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } + + get length() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return this[impl][\\"length\\"]; + } + } + Object.setPrototypeOf(LegacyArrayClass.prototype, Array.prototype); + Object.defineProperties(LegacyArrayClass.prototype, { + length: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"LegacyArrayClass\\", configurable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"LegacyArrayClass\\"] = LegacyArrayClass; + + Object.defineProperty(globalObject, \\"LegacyArrayClass\\", { + configurable: true, + writable: true, + value: LegacyArrayClass + }); } }; // iface module.exports = iface; @@ -974,81 +917,8 @@ const conversions = require(\\"webidl-conversions\\"); const utils = require(\\"./utils.js\\"); const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; -class MixedIn { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } - - mixedInOp() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - return this[impl].mixedInOp(); - } - - ifaceMixinOp() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - return this[impl].ifaceMixinOp(); - } - - get mixedInAttr() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - return this[impl][\\"mixedInAttr\\"]; - } - - set mixedInAttr(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - V = conversions[\\"DOMString\\"](V, { - context: \\"Failed to set the 'mixedInAttr' property on 'MixedIn': The provided value\\" - }); - - this[impl][\\"mixedInAttr\\"] = V; - } - - get ifaceMixinAttr() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - return this[impl][\\"ifaceMixinAttr\\"]; - } - - set ifaceMixinAttr(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - V = conversions[\\"DOMString\\"](V, { - context: \\"Failed to set the 'ifaceMixinAttr' property on 'MixedIn': The provided value\\" - }); - - this[impl][\\"ifaceMixinAttr\\"] = V; - } -} -Object.defineProperties(MixedIn.prototype, { - mixedInOp: { enumerable: true }, - ifaceMixinOp: { enumerable: true }, - mixedInAttr: { enumerable: true }, - ifaceMixinAttr: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"MixedIn\\", configurable: true }, - mixedInConst: { value: 43, enumerable: true }, - ifaceMixinConst: { value: 42, enumerable: true } -}); -Object.defineProperties(MixedIn, { - mixedInConst: { value: 43, enumerable: true }, - ifaceMixinConst: { value: 42, enumerable: true } -}); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -1089,25 +959,31 @@ const iface = { throw new TypeError(\`\${context} is not of type 'MixedIn'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(MixedIn.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"MixedIn\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor MixedIn is not installed on the passed global object\\"); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(MixedIn.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -1117,9 +993,92 @@ const iface = { } return obj; }, - interface: MixedIn, - expose: { - Window: { MixedIn } + + install(globalObject) { + class MixedIn { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } + + mixedInOp() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return this[impl].mixedInOp(); + } + + ifaceMixinOp() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return this[impl].ifaceMixinOp(); + } + + get mixedInAttr() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return this[impl][\\"mixedInAttr\\"]; + } + + set mixedInAttr(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + V = conversions[\\"DOMString\\"](V, { + context: \\"Failed to set the 'mixedInAttr' property on 'MixedIn': The provided value\\" + }); + + this[impl][\\"mixedInAttr\\"] = V; + } + + get ifaceMixinAttr() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return this[impl][\\"ifaceMixinAttr\\"]; + } + + set ifaceMixinAttr(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + V = conversions[\\"DOMString\\"](V, { + context: \\"Failed to set the 'ifaceMixinAttr' property on 'MixedIn': The provided value\\" + }); + + this[impl][\\"ifaceMixinAttr\\"] = V; + } + } + Object.defineProperties(MixedIn.prototype, { + mixedInOp: { enumerable: true }, + ifaceMixinOp: { enumerable: true }, + mixedInAttr: { enumerable: true }, + ifaceMixinAttr: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"MixedIn\\", configurable: true }, + mixedInConst: { value: 43, enumerable: true }, + ifaceMixinConst: { value: 42, enumerable: true } + }); + Object.defineProperties(MixedIn, { + mixedInConst: { value: 43, enumerable: true }, + ifaceMixinConst: { value: 42, enumerable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"MixedIn\\"] = MixedIn; + + Object.defineProperty(globalObject, \\"MixedIn\\", { + configurable: true, + writable: true, + value: MixedIn + }); } }; // iface module.exports = iface; @@ -1137,324 +1096,430 @@ const utils = require(\\"./utils.js\\"); const isURL = require(\\"./URL.js\\").is; const convertURL = require(\\"./URL.js\\").convert; const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; -class Overloads { - constructor() { - const args = []; - switch (arguments.length) { - case 0: - break; - default: { - let curArg = arguments[0]; - if (isURL(curArg)) { - { - let curArg = arguments[0]; - curArg = convertURL(curArg, { context: \\"Failed to construct 'Overloads': parameter 1\\" }); - args.push(curArg); - } - } else { - { - let curArg = arguments[0]; - curArg = conversions[\\"DOMString\\"](curArg, { context: \\"Failed to construct 'Overloads': parameter 1\\" }); - args.push(curArg); - } +const iface = { + // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` + // method into this array. It allows objects that directly implements *those* interfaces to be recognized as + // implementing this mixin interface. + _mixedIntoPredicates: [], + is(obj) { + if (obj) { + if (utils.hasOwn(obj, impl) && obj[impl] instanceof Impl.implementation) { + return true; + } + for (const isMixedInto of module.exports._mixedIntoPredicates) { + if (isMixedInto(obj)) { + return true; } } } - return iface.setup(Object.create(new.target.prototype), args); - } + return false; + }, + isImpl(obj) { + if (obj) { + if (obj instanceof Impl.implementation) { + return true; + } - compatible(arg1) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); + const wrapper = utils.wrapperForImpl(obj); + for (const isMixedInto of module.exports._mixedIntoPredicates) { + if (isMixedInto(wrapper)) { + return true; + } + } } - - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'compatible' on 'Overloads': 1 argument required, but only \\" + arguments.length + \\" present.\\" - ); + return false; + }, + convert(obj, { context = \\"The provided value\\" } = {}) { + if (module.exports.is(obj)) { + return utils.implForWrapper(obj); } - const args = []; - switch (arguments.length) { - case 1: - { - let curArg = arguments[0]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'compatible' on 'Overloads': parameter 1\\" - }); - args.push(curArg); - } - break; - case 2: - { - let curArg = arguments[0]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'compatible' on 'Overloads': parameter 1\\" - }); - args.push(curArg); - } - { - let curArg = arguments[1]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'compatible' on 'Overloads': parameter 2\\" - }); - args.push(curArg); - } - break; - default: - { - let curArg = arguments[0]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'compatible' on 'Overloads': parameter 1\\" - }); - args.push(curArg); - } - { - let curArg = arguments[1]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'compatible' on 'Overloads': parameter 2\\" - }); - args.push(curArg); - } - { - let curArg = arguments[2]; - if (curArg !== undefined) { - curArg = conversions[\\"long\\"](curArg, { - context: \\"Failed to execute 'compatible' on 'Overloads': parameter 3\\" - }); - } else { - curArg = 0; - } - args.push(curArg); - } + throw new TypeError(\`\${context} is not of type 'Overloads'.\`); + }, + + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); } - return utils.tryWrapperForImpl(this[impl].compatible(...args)); - } - incompatible1(arg1) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); + const ctor = globalObject[ctorRegistry][\\"Overloads\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor Overloads is not installed on the passed global object\\"); } - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'incompatible1' on 'Overloads': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); + return obj; + }, + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); + return utils.implForWrapper(obj); + }, + _internalSetup(obj) {}, + setup(obj, globalObject, constructorArgs = [], privateData = {}) { + privateData.wrapper = obj; + + iface._internalSetup(obj); + Object.defineProperty(obj, impl, { + value: new Impl.implementation(globalObject, constructorArgs, privateData), + configurable: true + }); + + obj[impl][utils.wrapperSymbol] = obj; + if (Impl.init) { + Impl.init(obj[impl], privateData); } - const args = []; - { - let curArg = arguments[0]; - if (typeof curArg === \\"number\\") { - { - let curArg = arguments[0]; - curArg = conversions[\\"long\\"](curArg, { - context: \\"Failed to execute 'incompatible1' on 'Overloads': parameter 1\\" - }); - args.push(curArg); + return obj; + }, + + install(globalObject) { + class Overloads { + constructor() { + const args = []; + switch (arguments.length) { + case 0: + break; + default: { + let curArg = arguments[0]; + if (isURL(curArg)) { + { + let curArg = arguments[0]; + curArg = convertURL(curArg, { context: \\"Failed to construct 'Overloads': parameter 1\\" }); + args.push(curArg); + } + } else { + { + let curArg = arguments[0]; + curArg = conversions[\\"DOMString\\"](curArg, { context: \\"Failed to construct 'Overloads': parameter 1\\" }); + args.push(curArg); + } + } + } } - } else { - { - let curArg = arguments[0]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'incompatible1' on 'Overloads': parameter 1\\" - }); - args.push(curArg); + return iface.setup(Object.create(new.target.prototype), globalObject, args); + } + + compatible(arg1) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'compatible' on 'Overloads': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + switch (arguments.length) { + case 1: + { + let curArg = arguments[0]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'compatible' on 'Overloads': parameter 1\\" + }); + args.push(curArg); + } + break; + case 2: + { + let curArg = arguments[0]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'compatible' on 'Overloads': parameter 1\\" + }); + args.push(curArg); + } + { + let curArg = arguments[1]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'compatible' on 'Overloads': parameter 2\\" + }); + args.push(curArg); + } + break; + default: + { + let curArg = arguments[0]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'compatible' on 'Overloads': parameter 1\\" + }); + args.push(curArg); + } + { + let curArg = arguments[1]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'compatible' on 'Overloads': parameter 2\\" + }); + args.push(curArg); + } + { + let curArg = arguments[2]; + if (curArg !== undefined) { + curArg = conversions[\\"long\\"](curArg, { + context: \\"Failed to execute 'compatible' on 'Overloads': parameter 3\\" + }); + } else { + curArg = 0; + } + args.push(curArg); + } } + return utils.tryWrapperForImpl(this[impl].compatible(...args)); } - } - return this[impl].incompatible1(...args); - } - incompatible2(arg1) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + incompatible1(arg1) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'incompatible2' on 'Overloads': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - switch (arguments.length) { - case 1: - { - let curArg = arguments[0]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'incompatible2' on 'Overloads': parameter 1\\" - }); - args.push(curArg); + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'incompatible1' on 'Overloads': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); } - break; - default: + const args = []; { let curArg = arguments[0]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'incompatible2' on 'Overloads': parameter 1\\" - }); - args.push(curArg); + if (typeof curArg === \\"number\\") { + { + let curArg = arguments[0]; + curArg = conversions[\\"long\\"](curArg, { + context: \\"Failed to execute 'incompatible1' on 'Overloads': parameter 1\\" + }); + args.push(curArg); + } + } else { + { + let curArg = arguments[0]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'incompatible1' on 'Overloads': parameter 1\\" + }); + args.push(curArg); + } + } } - { - let curArg = arguments[1]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'incompatible2' on 'Overloads': parameter 2\\" - }); - args.push(curArg); + return this[impl].incompatible1(...args); + } + + incompatible2(arg1) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); } - } - return this[impl].incompatible2(...args); - } - incompatible3(arg1) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'incompatible2' on 'Overloads': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + switch (arguments.length) { + case 1: + { + let curArg = arguments[0]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'incompatible2' on 'Overloads': parameter 1\\" + }); + args.push(curArg); + } + break; + default: + { + let curArg = arguments[0]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'incompatible2' on 'Overloads': parameter 1\\" + }); + args.push(curArg); + } + { + let curArg = arguments[1]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'incompatible2' on 'Overloads': parameter 2\\" + }); + args.push(curArg); + } + } + return this[impl].incompatible2(...args); + } - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'incompatible3' on 'Overloads': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - switch (arguments.length) { - case 1: - { - let curArg = arguments[0]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'incompatible3' on 'Overloads': parameter 1\\" - }); - args.push(curArg); + incompatible3(arg1) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); } - break; - case 2: - { - let curArg = arguments[0]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'incompatible3' on 'Overloads': parameter 1\\" - }); - args.push(curArg); + + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'incompatible3' on 'Overloads': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); } - { - let curArg = arguments[1]; - if (curArg === undefined) { + const args = []; + switch (arguments.length) { + case 1: { - let curArg = arguments[1]; - if (curArg !== undefined) { - curArg = convertURL(curArg, { - context: \\"Failed to execute 'incompatible3' on 'Overloads': parameter 2\\" - }); - } + let curArg = arguments[0]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'incompatible3' on 'Overloads': parameter 1\\" + }); + args.push(curArg); + } + break; + case 2: + { + let curArg = arguments[0]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'incompatible3' on 'Overloads': parameter 1\\" + }); args.push(curArg); } - } else if (isURL(curArg)) { { let curArg = arguments[1]; - if (curArg !== undefined) { - curArg = convertURL(curArg, { - context: \\"Failed to execute 'incompatible3' on 'Overloads': parameter 2\\" - }); + if (curArg === undefined) { + { + let curArg = arguments[1]; + if (curArg !== undefined) { + curArg = convertURL(curArg, { + context: \\"Failed to execute 'incompatible3' on 'Overloads': parameter 2\\" + }); + } + args.push(curArg); + } + } else if (isURL(curArg)) { + { + let curArg = arguments[1]; + if (curArg !== undefined) { + curArg = convertURL(curArg, { + context: \\"Failed to execute 'incompatible3' on 'Overloads': parameter 2\\" + }); + } + args.push(curArg); + } + } else if ( + curArg instanceof ArrayBuffer || + (typeof SharedArrayBuffer !== \\"undefined\\" && curArg instanceof SharedArrayBuffer) + ) { + { + let curArg = arguments[1]; + if (curArg instanceof ArrayBuffer) { + } else if (ArrayBuffer.isView(curArg)) { + } else { + throw new TypeError( + \\"Failed to execute 'incompatible3' on 'Overloads': parameter 2\\" + \\" is not of any supported type.\\" + ); + } + args.push(curArg); + } + } else if (ArrayBuffer.isView(curArg)) { + { + let curArg = arguments[1]; + if (curArg instanceof ArrayBuffer) { + } else if (ArrayBuffer.isView(curArg)) { + } else { + throw new TypeError( + \\"Failed to execute 'incompatible3' on 'Overloads': parameter 2\\" + \\" is not of any supported type.\\" + ); + } + args.push(curArg); + } + } else { + { + let curArg = arguments[1]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'incompatible3' on 'Overloads': parameter 2\\" + }); + args.push(curArg); + } } + } + break; + case 3: + throw new TypeError( + \\"Failed to execute 'incompatible3' on 'Overloads': only \\" + arguments.length + \\" arguments present.\\" + ); + break; + default: + { + let curArg = arguments[0]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'incompatible3' on 'Overloads': parameter 1\\" + }); args.push(curArg); } - } else if ( - curArg instanceof ArrayBuffer || - (typeof SharedArrayBuffer !== \\"undefined\\" && curArg instanceof SharedArrayBuffer) - ) { { let curArg = arguments[1]; + curArg = conversions[\\"long\\"](curArg, { + context: \\"Failed to execute 'incompatible3' on 'Overloads': parameter 2\\" + }); + args.push(curArg); + } + { + let curArg = arguments[2]; if (curArg instanceof ArrayBuffer) { } else if (ArrayBuffer.isView(curArg)) { } else { throw new TypeError( - \\"Failed to execute 'incompatible3' on 'Overloads': parameter 2\\" + \\" is not of any supported type.\\" + \\"Failed to execute 'incompatible3' on 'Overloads': parameter 3\\" + \\" is not of any supported type.\\" ); } args.push(curArg); } - } else if (ArrayBuffer.isView(curArg)) { { - let curArg = arguments[1]; + let curArg = arguments[3]; if (curArg instanceof ArrayBuffer) { } else if (ArrayBuffer.isView(curArg)) { } else { throw new TypeError( - \\"Failed to execute 'incompatible3' on 'Overloads': parameter 2\\" + \\" is not of any supported type.\\" + \\"Failed to execute 'incompatible3' on 'Overloads': parameter 4\\" + \\" is not of any supported type.\\" ); } args.push(curArg); } - } else { - { - let curArg = arguments[1]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'incompatible3' on 'Overloads': parameter 2\\" - }); - args.push(curArg); - } - } - } - break; - case 3: - throw new TypeError( - \\"Failed to execute 'incompatible3' on 'Overloads': only \\" + arguments.length + \\" arguments present.\\" - ); - break; - default: - { - let curArg = arguments[0]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'incompatible3' on 'Overloads': parameter 1\\" - }); - args.push(curArg); - } - { - let curArg = arguments[1]; - curArg = conversions[\\"long\\"](curArg, { - context: \\"Failed to execute 'incompatible3' on 'Overloads': parameter 2\\" - }); - args.push(curArg); - } - { - let curArg = arguments[2]; - if (curArg instanceof ArrayBuffer) { - } else if (ArrayBuffer.isView(curArg)) { - } else { - throw new TypeError( - \\"Failed to execute 'incompatible3' on 'Overloads': parameter 3\\" + \\" is not of any supported type.\\" - ); - } - args.push(curArg); - } - { - let curArg = arguments[3]; - if (curArg instanceof ArrayBuffer) { - } else if (ArrayBuffer.isView(curArg)) { - } else { - throw new TypeError( - \\"Failed to execute 'incompatible3' on 'Overloads': parameter 4\\" + \\" is not of any supported type.\\" - ); - } - args.push(curArg); } + return this[impl].incompatible3(...args); + } + } + Object.defineProperties(Overloads.prototype, { + compatible: { enumerable: true }, + incompatible1: { enumerable: true }, + incompatible2: { enumerable: true }, + incompatible3: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"Overloads\\", configurable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); } - return this[impl].incompatible3(...args); + globalObject[ctorRegistry][\\"Overloads\\"] = Overloads; + + Object.defineProperty(globalObject, \\"Overloads\\", { + configurable: true, + writable: true, + value: Overloads + }); } -} -Object.defineProperties(Overloads.prototype, { - compatible: { enumerable: true }, - incompatible1: { enumerable: true }, - incompatible2: { enumerable: true }, - incompatible3: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"Overloads\\", configurable: true } -}); -const iface = { - // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` +}; // iface +module.exports = iface; + +const Impl = require(\\"../implementations/Overloads.js\\"); +" +`; + +exports[`PromiseTypes.webidl 1`] = ` +"\\"use strict\\"; + +const conversions = require(\\"webidl-conversions\\"); +const utils = require(\\"./utils.js\\"); + +const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; + +const iface = { + // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as // implementing this mixin interface. _mixedIntoPredicates: [], @@ -1490,28 +1555,34 @@ const iface = { if (module.exports.is(obj)) { return utils.implForWrapper(obj); } - throw new TypeError(\`\${context} is not of type 'Overloads'.\`); + throw new TypeError(\`\${context} is not of type 'PromiseTypes'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(Overloads.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"PromiseTypes\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor PromiseTypes is not installed on the passed global object\\"); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(Overloads.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -1521,86 +1592,96 @@ const iface = { } return obj; }, - interface: Overloads, - expose: { - Window: { Overloads } + + install(globalObject) { + class PromiseTypes { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } + + voidPromiseConsumer(p) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'voidPromiseConsumer' on 'PromiseTypes': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = Promise.resolve(curArg).then(value => {}, reason => reason); + args.push(curArg); + } + return this[impl].voidPromiseConsumer(...args); + } + + promiseConsumer(p) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'promiseConsumer' on 'PromiseTypes': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = Promise.resolve(curArg).then( + value => { + value = conversions[\\"double\\"](value, { + context: \\"Failed to execute 'promiseConsumer' on 'PromiseTypes': parameter 1\\" + \\" promise value\\" + }); + + return value; + }, + reason => reason + ); + args.push(curArg); + } + return this[impl].promiseConsumer(...args); + } + } + Object.defineProperties(PromiseTypes.prototype, { + voidPromiseConsumer: { enumerable: true }, + promiseConsumer: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"PromiseTypes\\", configurable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"PromiseTypes\\"] = PromiseTypes; + + Object.defineProperty(globalObject, \\"PromiseTypes\\", { + configurable: true, + writable: true, + value: PromiseTypes + }); } }; // iface module.exports = iface; -const Impl = require(\\"../implementations/Overloads.js\\"); +const Impl = require(\\"../implementations/PromiseTypes.js\\"); " `; -exports[`PromiseTypes.webidl 1`] = ` +exports[`Reflect.webidl 1`] = ` "\\"use strict\\"; const conversions = require(\\"webidl-conversions\\"); const utils = require(\\"./utils.js\\"); const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; -class PromiseTypes { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } - - voidPromiseConsumer(p) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'voidPromiseConsumer' on 'PromiseTypes': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - curArg = Promise.resolve(curArg).then(value => {}, reason => reason); - args.push(curArg); - } - return this[impl].voidPromiseConsumer(...args); - } - - promiseConsumer(p) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'promiseConsumer' on 'PromiseTypes': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - curArg = Promise.resolve(curArg).then( - value => { - value = conversions[\\"double\\"](value, { - context: \\"Failed to execute 'promiseConsumer' on 'PromiseTypes': parameter 1\\" + \\" promise value\\" - }); - - return value; - }, - reason => reason - ); - args.push(curArg); - } - return this[impl].promiseConsumer(...args); - } -} -Object.defineProperties(PromiseTypes.prototype, { - voidPromiseConsumer: { enumerable: true }, - promiseConsumer: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"PromiseTypes\\", configurable: true } -}); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -1638,28 +1719,34 @@ const iface = { if (module.exports.is(obj)) { return utils.implForWrapper(obj); } - throw new TypeError(\`\${context} is not of type 'PromiseTypes'.\`); + throw new TypeError(\`\${context} is not of type 'Reflect'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(PromiseTypes.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"Reflect\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor Reflect is not installed on the passed global object\\"); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(PromiseTypes.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -1669,168 +1756,213 @@ const iface = { } return obj; }, - interface: PromiseTypes, - expose: { - Window: { PromiseTypes } - } -}; // iface -module.exports = iface; -const Impl = require(\\"../implementations/PromiseTypes.js\\"); -" -`; + install(globalObject) { + class Reflect { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } -exports[`Reflect.webidl 1`] = ` -"\\"use strict\\"; + get ReflectedBoolean() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } -const conversions = require(\\"webidl-conversions\\"); -const utils = require(\\"./utils.js\\"); + return this[impl].hasAttributeNS(null, \\"reflectedboolean\\"); + } -const impl = utils.implSymbol; + set ReflectedBoolean(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } -class Reflect { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } + V = conversions[\\"boolean\\"](V, { + context: \\"Failed to set the 'ReflectedBoolean' property on 'Reflect': The provided value\\" + }); - get ReflectedBoolean() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + if (V) { + this[impl].setAttributeNS(null, \\"reflectedboolean\\", \\"\\"); + } else { + this[impl].removeAttributeNS(null, \\"reflectedboolean\\"); + } + } - return this[impl].hasAttributeNS(null, \\"reflectedboolean\\"); - } + get ReflectedDOMString() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - set ReflectedBoolean(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + const value = this[impl].getAttributeNS(null, \\"reflecteddomstring\\"); + return value === null ? \\"\\" : value; + } - V = conversions[\\"boolean\\"](V, { - context: \\"Failed to set the 'ReflectedBoolean' property on 'Reflect': The provided value\\" - }); + set ReflectedDOMString(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - if (V) { - this[impl].setAttributeNS(null, \\"reflectedboolean\\", \\"\\"); - } else { - this[impl].removeAttributeNS(null, \\"reflectedboolean\\"); - } - } + V = conversions[\\"DOMString\\"](V, { + context: \\"Failed to set the 'ReflectedDOMString' property on 'Reflect': The provided value\\" + }); - get ReflectedDOMString() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + this[impl].setAttributeNS(null, \\"reflecteddomstring\\", V); + } - const value = this[impl].getAttributeNS(null, \\"reflecteddomstring\\"); - return value === null ? \\"\\" : value; - } + get ReflectedLong() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - set ReflectedDOMString(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + const value = parseInt(this[impl].getAttributeNS(null, \\"reflectedlong\\")); + return isNaN(value) || value < -2147483648 || value > 2147483647 ? 0 : value; + } - V = conversions[\\"DOMString\\"](V, { - context: \\"Failed to set the 'ReflectedDOMString' property on 'Reflect': The provided value\\" - }); + set ReflectedLong(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - this[impl].setAttributeNS(null, \\"reflecteddomstring\\", V); - } + V = conversions[\\"long\\"](V, { + context: \\"Failed to set the 'ReflectedLong' property on 'Reflect': The provided value\\" + }); - get ReflectedLong() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + this[impl].setAttributeNS(null, \\"reflectedlong\\", String(V)); + } - const value = parseInt(this[impl].getAttributeNS(null, \\"reflectedlong\\")); - return isNaN(value) || value < -2147483648 || value > 2147483647 ? 0 : value; - } + get ReflectedUnsignedLong() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - set ReflectedLong(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + const value = parseInt(this[impl].getAttributeNS(null, \\"reflectedunsignedlong\\")); + return isNaN(value) || value < 0 || value > 2147483647 ? 0 : value; + } - V = conversions[\\"long\\"](V, { - context: \\"Failed to set the 'ReflectedLong' property on 'Reflect': The provided value\\" - }); + set ReflectedUnsignedLong(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - this[impl].setAttributeNS(null, \\"reflectedlong\\", String(V)); - } + V = conversions[\\"unsigned long\\"](V, { + context: \\"Failed to set the 'ReflectedUnsignedLong' property on 'Reflect': The provided value\\" + }); - get ReflectedUnsignedLong() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + this[impl].setAttributeNS(null, \\"reflectedunsignedlong\\", String(V > 2147483647 ? 0 : V)); + } - const value = parseInt(this[impl].getAttributeNS(null, \\"reflectedunsignedlong\\")); - return isNaN(value) || value < 0 || value > 2147483647 ? 0 : value; - } + get ReflectionTest() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - set ReflectedUnsignedLong(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + const value = this[impl].getAttributeNS(null, \\"reflection\\"); + return value === null ? \\"\\" : value; + } - V = conversions[\\"unsigned long\\"](V, { - context: \\"Failed to set the 'ReflectedUnsignedLong' property on 'Reflect': The provided value\\" - }); + set ReflectionTest(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - this[impl].setAttributeNS(null, \\"reflectedunsignedlong\\", String(V > 2147483647 ? 0 : V)); - } + V = conversions[\\"DOMString\\"](V, { + context: \\"Failed to set the 'ReflectionTest' property on 'Reflect': The provided value\\" + }); - get ReflectionTest() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + this[impl].setAttributeNS(null, \\"reflection\\", V); + } - const value = this[impl].getAttributeNS(null, \\"reflection\\"); - return value === null ? \\"\\" : value; - } + get withUnderscore() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - set ReflectionTest(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + const value = this[impl].getAttributeNS(null, \\"with-underscore\\"); + return value === null ? \\"\\" : value; + } - V = conversions[\\"DOMString\\"](V, { - context: \\"Failed to set the 'ReflectionTest' property on 'Reflect': The provided value\\" - }); + set withUnderscore(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - this[impl].setAttributeNS(null, \\"reflection\\", V); - } + V = conversions[\\"DOMString\\"](V, { + context: \\"Failed to set the 'withUnderscore' property on 'Reflect': The provided value\\" + }); - get withUnderscore() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); + this[impl].setAttributeNS(null, \\"with-underscore\\", V); + } } + Object.defineProperties(Reflect.prototype, { + ReflectedBoolean: { enumerable: true }, + ReflectedDOMString: { enumerable: true }, + ReflectedLong: { enumerable: true }, + ReflectedUnsignedLong: { enumerable: true }, + ReflectionTest: { enumerable: true }, + withUnderscore: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"Reflect\\", configurable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"Reflect\\"] = Reflect; - const value = this[impl].getAttributeNS(null, \\"with-underscore\\"); - return value === null ? \\"\\" : value; + Object.defineProperty(globalObject, \\"Reflect\\", { + configurable: true, + writable: true, + value: Reflect + }); } +}; // iface +module.exports = iface; - set withUnderscore(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } +const Impl = require(\\"../implementations/Reflect.js\\"); +" +`; - V = conversions[\\"DOMString\\"](V, { - context: \\"Failed to set the 'withUnderscore' property on 'Reflect': The provided value\\" - }); +exports[`RequestDestination.webidl 1`] = ` +"\\"use strict\\"; - this[impl].setAttributeNS(null, \\"with-underscore\\", V); +const enumerationValues = new Set([ + \\"\\", + \\"audio\\", + \\"document\\", + \\"embed\\", + \\"font\\", + \\"image\\", + \\"manifest\\", + \\"object\\", + \\"report\\", + \\"script\\", + \\"sharedworker\\", + \\"style\\", + \\"track\\", + \\"video\\", + \\"worker\\", + \\"xslt\\" +]); +module.exports = { + enumerationValues, + convert(value, { context = \\"The provided value\\" } = {}) { + const string = \`\${value}\`; + if (!enumerationValues.has(value)) { + throw new TypeError(\`\${context} '\${value}' is not a valid enumeration value for RequestDestination\`); + } + return string; } -} -Object.defineProperties(Reflect.prototype, { - ReflectedBoolean: { enumerable: true }, - ReflectedDOMString: { enumerable: true }, - ReflectedLong: { enumerable: true }, - ReflectedUnsignedLong: { enumerable: true }, - ReflectionTest: { enumerable: true }, - withUnderscore: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"Reflect\\", configurable: true } -}); +}; +" +`; + +exports[`SeqAndRec.webidl 1`] = ` +"\\"use strict\\"; + +const conversions = require(\\"webidl-conversions\\"); +const utils = require(\\"./utils.js\\"); + +const convertURL = require(\\"./URL.js\\").convert; +const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; + const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -1868,28 +2000,34 @@ const iface = { if (module.exports.is(obj)) { return utils.implForWrapper(obj); } - throw new TypeError(\`\${context} is not of type 'Reflect'.\`); + throw new TypeError(\`\${context} is not of type 'SeqAndRec'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(Reflect.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"SeqAndRec\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor SeqAndRec is not installed on the passed global object\\"); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(Reflect.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -1899,268 +2037,247 @@ const iface = { } return obj; }, - interface: Reflect, - expose: { - Window: { Reflect } - } -}; // iface -module.exports = iface; -const Impl = require(\\"../implementations/Reflect.js\\"); -" -`; + install(globalObject) { + class SeqAndRec { + constructor() { + return iface.setup(Object.create(new.target.prototype), globalObject, undefined); + } -exports[`RequestDestination.webidl 1`] = ` -"\\"use strict\\"; + recordConsumer(rec) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } -const enumerationValues = new Set([ - \\"\\", - \\"audio\\", - \\"document\\", - \\"embed\\", - \\"font\\", - \\"image\\", - \\"manifest\\", - \\"object\\", - \\"report\\", - \\"script\\", - \\"sharedworker\\", - \\"style\\", - \\"track\\", - \\"video\\", - \\"worker\\", - \\"xslt\\" -]); -module.exports = { - enumerationValues, - convert(value, { context = \\"The provided value\\" } = {}) { - const string = \`\${value}\`; - if (!enumerationValues.has(value)) { - throw new TypeError(\`\${context} '\${value}' is not a valid enumeration value for RequestDestination\`); - } - return string; - } -}; -" -`; + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'recordConsumer' on 'SeqAndRec': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + if (!utils.isObject(curArg)) { + throw new TypeError( + \\"Failed to execute 'recordConsumer' on 'SeqAndRec': parameter 1\\" + \\" is not an object.\\" + ); + } else { + const result = Object.create(null); + for (const key of Reflect.ownKeys(curArg)) { + const desc = Object.getOwnPropertyDescriptor(curArg, key); + if (desc && desc.enumerable) { + let typedKey = key; -exports[`SeqAndRec.webidl 1`] = ` -"\\"use strict\\"; + typedKey = conversions[\\"USVString\\"](typedKey, { + context: \\"Failed to execute 'recordConsumer' on 'SeqAndRec': parameter 1\\" + \\"'s key\\" + }); -const conversions = require(\\"webidl-conversions\\"); -const utils = require(\\"./utils.js\\"); + let typedValue = curArg[key]; -const convertURL = require(\\"./URL.js\\").convert; -const impl = utils.implSymbol; + typedValue = conversions[\\"double\\"](typedValue, { + context: \\"Failed to execute 'recordConsumer' on 'SeqAndRec': parameter 1\\" + \\"'s value\\" + }); -class SeqAndRec { - constructor() { - return iface.setup(Object.create(new.target.prototype)); - } + result[typedKey] = typedValue; + } + } + curArg = result; + } + args.push(curArg); + } + return this[impl].recordConsumer(...args); + } - recordConsumer(rec) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + recordConsumer2(rec) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'recordConsumer' on 'SeqAndRec': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - if (!utils.isObject(curArg)) { - throw new TypeError(\\"Failed to execute 'recordConsumer' on 'SeqAndRec': parameter 1\\" + \\" is not an object.\\"); - } else { - const result = Object.create(null); - for (const key of Reflect.ownKeys(curArg)) { - const desc = Object.getOwnPropertyDescriptor(curArg, key); - if (desc && desc.enumerable) { - let typedKey = key; - - typedKey = conversions[\\"USVString\\"](typedKey, { - context: \\"Failed to execute 'recordConsumer' on 'SeqAndRec': parameter 1\\" + \\"'s key\\" - }); + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'recordConsumer2' on 'SeqAndRec': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + if (!utils.isObject(curArg)) { + throw new TypeError( + \\"Failed to execute 'recordConsumer2' on 'SeqAndRec': parameter 1\\" + \\" is not an object.\\" + ); + } else { + const result = Object.create(null); + for (const key of Reflect.ownKeys(curArg)) { + const desc = Object.getOwnPropertyDescriptor(curArg, key); + if (desc && desc.enumerable) { + let typedKey = key; + + typedKey = conversions[\\"USVString\\"](typedKey, { + context: \\"Failed to execute 'recordConsumer2' on 'SeqAndRec': parameter 1\\" + \\"'s key\\" + }); - let typedValue = curArg[key]; + let typedValue = curArg[key]; - typedValue = conversions[\\"double\\"](typedValue, { - context: \\"Failed to execute 'recordConsumer' on 'SeqAndRec': parameter 1\\" + \\"'s value\\" - }); + typedValue = convertURL(typedValue, { + context: \\"Failed to execute 'recordConsumer2' on 'SeqAndRec': parameter 1\\" + \\"'s value\\" + }); - result[typedKey] = typedValue; + result[typedKey] = typedValue; + } + } + curArg = result; } + args.push(curArg); } - curArg = result; + return this[impl].recordConsumer2(...args); } - args.push(curArg); - } - return this[impl].recordConsumer(...args); - } - - recordConsumer2(rec) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'recordConsumer2' on 'SeqAndRec': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - if (!utils.isObject(curArg)) { - throw new TypeError(\\"Failed to execute 'recordConsumer2' on 'SeqAndRec': parameter 1\\" + \\" is not an object.\\"); - } else { - const result = Object.create(null); - for (const key of Reflect.ownKeys(curArg)) { - const desc = Object.getOwnPropertyDescriptor(curArg, key); - if (desc && desc.enumerable) { - let typedKey = key; - - typedKey = conversions[\\"USVString\\"](typedKey, { - context: \\"Failed to execute 'recordConsumer2' on 'SeqAndRec': parameter 1\\" + \\"'s key\\" - }); - let typedValue = curArg[key]; + sequenceConsumer(seq) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - typedValue = convertURL(typedValue, { - context: \\"Failed to execute 'recordConsumer2' on 'SeqAndRec': parameter 1\\" + \\"'s value\\" - }); + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'sequenceConsumer' on 'SeqAndRec': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + if (!utils.isObject(curArg)) { + throw new TypeError( + \\"Failed to execute 'sequenceConsumer' on 'SeqAndRec': parameter 1\\" + \\" is not an iterable object.\\" + ); + } else { + const V = []; + const tmp = curArg; + for (let nextItem of tmp) { + nextItem = conversions[\\"USVString\\"](nextItem, { + context: \\"Failed to execute 'sequenceConsumer' on 'SeqAndRec': parameter 1\\" + \\"'s element\\" + }); - result[typedKey] = typedValue; + V.push(nextItem); + } + curArg = V; } + args.push(curArg); } - curArg = result; + return this[impl].sequenceConsumer(...args); } - args.push(curArg); - } - return this[impl].recordConsumer2(...args); - } - sequenceConsumer(seq) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + sequenceConsumer2(seq) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'sequenceConsumer' on 'SeqAndRec': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - if (!utils.isObject(curArg)) { - throw new TypeError( - \\"Failed to execute 'sequenceConsumer' on 'SeqAndRec': parameter 1\\" + \\" is not an iterable object.\\" - ); - } else { - const V = []; - const tmp = curArg; - for (let nextItem of tmp) { - nextItem = conversions[\\"USVString\\"](nextItem, { - context: \\"Failed to execute 'sequenceConsumer' on 'SeqAndRec': parameter 1\\" + \\"'s element\\" - }); + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'sequenceConsumer2' on 'SeqAndRec': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + if (!utils.isObject(curArg)) { + throw new TypeError( + \\"Failed to execute 'sequenceConsumer2' on 'SeqAndRec': parameter 1\\" + \\" is not an iterable object.\\" + ); + } else { + const V = []; + const tmp = curArg; + for (let nextItem of tmp) { + nextItem = utils.tryImplForWrapper(nextItem); - V.push(nextItem); + V.push(nextItem); + } + curArg = V; + } + args.push(curArg); } - curArg = V; + return this[impl].sequenceConsumer2(...args); } - args.push(curArg); - } - return this[impl].sequenceConsumer(...args); - } - sequenceConsumer2(seq) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + frozenArrayConsumer(arr) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'sequenceConsumer2' on 'SeqAndRec': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - if (!utils.isObject(curArg)) { - throw new TypeError( - \\"Failed to execute 'sequenceConsumer2' on 'SeqAndRec': parameter 1\\" + \\" is not an iterable object.\\" - ); - } else { - const V = []; - const tmp = curArg; - for (let nextItem of tmp) { - nextItem = utils.tryImplForWrapper(nextItem); + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'frozenArrayConsumer' on 'SeqAndRec': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + if (!utils.isObject(curArg)) { + throw new TypeError( + \\"Failed to execute 'frozenArrayConsumer' on 'SeqAndRec': parameter 1\\" + \\" is not an iterable object.\\" + ); + } else { + const V = []; + const tmp = curArg; + for (let nextItem of tmp) { + nextItem = conversions[\\"double\\"](nextItem, { + context: \\"Failed to execute 'frozenArrayConsumer' on 'SeqAndRec': parameter 1\\" + \\"'s element\\" + }); - V.push(nextItem); + V.push(nextItem); + } + curArg = V; + } + curArg = Object.freeze(curArg); + args.push(curArg); } - curArg = V; + return this[impl].frozenArrayConsumer(...args); } - args.push(curArg); } - return this[impl].sequenceConsumer2(...args); + Object.defineProperties(SeqAndRec.prototype, { + recordConsumer: { enumerable: true }, + recordConsumer2: { enumerable: true }, + sequenceConsumer: { enumerable: true }, + sequenceConsumer2: { enumerable: true }, + frozenArrayConsumer: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"SeqAndRec\\", configurable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"SeqAndRec\\"] = SeqAndRec; + + Object.defineProperty(globalObject, \\"SeqAndRec\\", { + configurable: true, + writable: true, + value: SeqAndRec + }); } +}; // iface +module.exports = iface; - frozenArrayConsumer(arr) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } +const Impl = require(\\"../implementations/SeqAndRec.js\\"); +" +`; - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'frozenArrayConsumer' on 'SeqAndRec': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - if (!utils.isObject(curArg)) { - throw new TypeError( - \\"Failed to execute 'frozenArrayConsumer' on 'SeqAndRec': parameter 1\\" + \\" is not an iterable object.\\" - ); - } else { - const V = []; - const tmp = curArg; - for (let nextItem of tmp) { - nextItem = conversions[\\"double\\"](nextItem, { - context: \\"Failed to execute 'frozenArrayConsumer' on 'SeqAndRec': parameter 1\\" + \\"'s element\\" - }); +exports[`Static.webidl 1`] = ` +"\\"use strict\\"; + +const conversions = require(\\"webidl-conversions\\"); +const utils = require(\\"./utils.js\\"); + +const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; - V.push(nextItem); - } - curArg = V; - } - curArg = Object.freeze(curArg); - args.push(curArg); - } - return this[impl].frozenArrayConsumer(...args); - } -} -Object.defineProperties(SeqAndRec.prototype, { - recordConsumer: { enumerable: true }, - recordConsumer2: { enumerable: true }, - sequenceConsumer: { enumerable: true }, - sequenceConsumer2: { enumerable: true }, - frozenArrayConsumer: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"SeqAndRec\\", configurable: true } -}); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -2198,28 +2315,34 @@ const iface = { if (module.exports.is(obj)) { return utils.implForWrapper(obj); } - throw new TypeError(\`\${context} is not of type 'SeqAndRec'.\`); + throw new TypeError(\`\${context} is not of type 'Static'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(SeqAndRec.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"Static\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor Static is not installed on the passed global object\\"); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(SeqAndRec.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -2229,148 +2352,72 @@ const iface = { } return obj; }, - interface: SeqAndRec, - expose: { - Window: { SeqAndRec } - } -}; // iface -module.exports = iface; - -const Impl = require(\\"../implementations/SeqAndRec.js\\"); -" -`; -exports[`Static.webidl 1`] = ` -"\\"use strict\\"; + install(globalObject) { + class Static { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } -const conversions = require(\\"webidl-conversions\\"); -const utils = require(\\"./utils.js\\"); + def() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } -const impl = utils.implSymbol; + return this[impl].def(); + } -class Static { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } + get abc() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - def() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + return this[impl][\\"abc\\"]; + } - return this[impl].def(); - } + set abc(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - get abc() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + V = conversions[\\"DOMString\\"](V, { + context: \\"Failed to set the 'abc' property on 'Static': The provided value\\" + }); - return this[impl][\\"abc\\"]; - } + this[impl][\\"abc\\"] = V; + } - set abc(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + static def() { + return Impl.implementation.def(); + } - V = conversions[\\"DOMString\\"](V, { context: \\"Failed to set the 'abc' property on 'Static': The provided value\\" }); + static get abc() { + return Impl.implementation[\\"abc\\"]; + } - this[impl][\\"abc\\"] = V; - } + static set abc(V) { + return Impl.implementation[\\"abc\\"]; + } + } + Object.defineProperties(Static.prototype, { + def: { enumerable: true }, + abc: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"Static\\", configurable: true } + }); + Object.defineProperties(Static, { def: { enumerable: true }, abc: { enumerable: true } }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"Static\\"] = Static; - static def() { - return Impl.implementation.def(); + Object.defineProperty(globalObject, \\"Static\\", { + configurable: true, + writable: true, + value: Static + }); } - - static get abc() { - return Impl.implementation[\\"abc\\"]; - } - - static set abc(V) { - return Impl.implementation[\\"abc\\"]; - } -} -Object.defineProperties(Static.prototype, { - def: { enumerable: true }, - abc: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"Static\\", configurable: true } -}); -Object.defineProperties(Static, { def: { enumerable: true }, abc: { enumerable: true } }); -const iface = { - // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` - // method into this array. It allows objects that directly implements *those* interfaces to be recognized as - // implementing this mixin interface. - _mixedIntoPredicates: [], - is(obj) { - if (obj) { - if (utils.hasOwn(obj, impl) && obj[impl] instanceof Impl.implementation) { - return true; - } - for (const isMixedInto of module.exports._mixedIntoPredicates) { - if (isMixedInto(obj)) { - return true; - } - } - } - return false; - }, - isImpl(obj) { - if (obj) { - if (obj instanceof Impl.implementation) { - return true; - } - - const wrapper = utils.wrapperForImpl(obj); - for (const isMixedInto of module.exports._mixedIntoPredicates) { - if (isMixedInto(wrapper)) { - return true; - } - } - } - return false; - }, - convert(obj, { context = \\"The provided value\\" } = {}) { - if (module.exports.is(obj)) { - return utils.implForWrapper(obj); - } - throw new TypeError(\`\${context} is not of type 'Static'.\`); - }, - - create(constructorArgs, privateData) { - let obj = Object.create(Static.prototype); - obj = this.setup(obj, constructorArgs, privateData); - return obj; - }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(Static.prototype); - obj = this.setup(obj, constructorArgs, privateData); - return utils.implForWrapper(obj); - }, - _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - - privateData.wrapper = obj; - - this._internalSetup(obj); - Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), - configurable: true - }); - - obj[impl][utils.wrapperSymbol] = obj; - if (Impl.init) { - Impl.init(obj[impl], privateData); - } - return obj; - }, - interface: Static, - expose: { - Window: { Static } - } -}; // iface -module.exports = iface; +}; // iface +module.exports = iface; const Impl = require(\\"../implementations/Static.js\\"); " @@ -2383,120 +2430,8 @@ const conversions = require(\\"webidl-conversions\\"); const utils = require(\\"./utils.js\\"); const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; -class Storage { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } - - key(index) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'key' on 'Storage': 1 argument required, but only \\" + arguments.length + \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - curArg = conversions[\\"unsigned long\\"](curArg, { context: \\"Failed to execute 'key' on 'Storage': parameter 1\\" }); - args.push(curArg); - } - return this[impl].key(...args); - } - - getItem(key) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'getItem' on 'Storage': 1 argument required, but only \\" + arguments.length + \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - curArg = conversions[\\"DOMString\\"](curArg, { context: \\"Failed to execute 'getItem' on 'Storage': parameter 1\\" }); - args.push(curArg); - } - return this[impl].getItem(...args); - } - - setItem(key, value) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - if (arguments.length < 2) { - throw new TypeError( - \\"Failed to execute 'setItem' on 'Storage': 2 arguments required, but only \\" + arguments.length + \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - curArg = conversions[\\"DOMString\\"](curArg, { context: \\"Failed to execute 'setItem' on 'Storage': parameter 1\\" }); - args.push(curArg); - } - { - let curArg = arguments[1]; - curArg = conversions[\\"DOMString\\"](curArg, { context: \\"Failed to execute 'setItem' on 'Storage': parameter 2\\" }); - args.push(curArg); - } - return this[impl].setItem(...args); - } - - removeItem(key) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'removeItem' on 'Storage': 1 argument required, but only \\" + arguments.length + \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'removeItem' on 'Storage': parameter 1\\" - }); - args.push(curArg); - } - return this[impl].removeItem(...args); - } - - clear() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - return this[impl].clear(); - } - - get length() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - return this[impl][\\"length\\"]; - } -} -Object.defineProperties(Storage.prototype, { - key: { enumerable: true }, - getItem: { enumerable: true }, - setItem: { enumerable: true }, - removeItem: { enumerable: true }, - clear: { enumerable: true }, - length: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"Storage\\", configurable: true } -}); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -2537,25 +2472,31 @@ const iface = { throw new TypeError(\`\${context} is not of type 'Storage'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(Storage.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"Storage\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor Storage is not installed on the passed global object\\"); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(Storage.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -2729,9 +2670,141 @@ const iface = { } return obj; }, - interface: Storage, - expose: { - Window: { Storage } + + install(globalObject) { + class Storage { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } + + key(index) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'key' on 'Storage': 1 argument required, but only \\" + arguments.length + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions[\\"unsigned long\\"](curArg, { + context: \\"Failed to execute 'key' on 'Storage': parameter 1\\" + }); + args.push(curArg); + } + return this[impl].key(...args); + } + + getItem(key) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'getItem' on 'Storage': 1 argument required, but only \\" + arguments.length + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'getItem' on 'Storage': parameter 1\\" + }); + args.push(curArg); + } + return this[impl].getItem(...args); + } + + setItem(key, value) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 2) { + throw new TypeError( + \\"Failed to execute 'setItem' on 'Storage': 2 arguments required, but only \\" + arguments.length + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'setItem' on 'Storage': parameter 1\\" + }); + args.push(curArg); + } + { + let curArg = arguments[1]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'setItem' on 'Storage': parameter 2\\" + }); + args.push(curArg); + } + return this[impl].setItem(...args); + } + + removeItem(key) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'removeItem' on 'Storage': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'removeItem' on 'Storage': parameter 1\\" + }); + args.push(curArg); + } + return this[impl].removeItem(...args); + } + + clear() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return this[impl].clear(); + } + + get length() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return this[impl][\\"length\\"]; + } + } + Object.defineProperties(Storage.prototype, { + key: { enumerable: true }, + getItem: { enumerable: true }, + setItem: { enumerable: true }, + removeItem: { enumerable: true }, + clear: { enumerable: true }, + length: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"Storage\\", configurable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"Storage\\"] = Storage; + + Object.defineProperty(globalObject, \\"Storage\\", { + configurable: true, + writable: true, + value: Storage + }); } }; // iface module.exports = iface; @@ -2747,32 +2820,8 @@ const conversions = require(\\"webidl-conversions\\"); const utils = require(\\"./utils.js\\"); const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; -class StringifierAttribute { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } - - get attr() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - return this[impl][\\"attr\\"]; - } - - toString() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - return this[impl][\\"attr\\"]; - } -} -Object.defineProperties(StringifierAttribute.prototype, { - attr: { enumerable: true }, - toString: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"StringifierAttribute\\", configurable: true } -}); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -2813,25 +2862,31 @@ const iface = { throw new TypeError(\`\${context} is not of type 'StringifierAttribute'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(StringifierAttribute.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"StringifierAttribute\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor StringifierAttribute is not installed on the passed global object\\"); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(StringifierAttribute.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -2841,9 +2896,43 @@ const iface = { } return obj; }, - interface: StringifierAttribute, - expose: { - Window: { StringifierAttribute } + + install(globalObject) { + class StringifierAttribute { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } + + get attr() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return this[impl][\\"attr\\"]; + } + + toString() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + return this[impl][\\"attr\\"]; + } + } + Object.defineProperties(StringifierAttribute.prototype, { + attr: { enumerable: true }, + toString: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"StringifierAttribute\\", configurable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"StringifierAttribute\\"] = StringifierAttribute; + + Object.defineProperty(globalObject, \\"StringifierAttribute\\", { + configurable: true, + writable: true, + value: StringifierAttribute + }); } }; // iface module.exports = iface; @@ -2859,24 +2948,8 @@ const conversions = require(\\"webidl-conversions\\"); const utils = require(\\"./utils.js\\"); const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; -class StringifierDefaultOperation { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } - - toString() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - return this[impl].toString(); - } -} -Object.defineProperties(StringifierDefaultOperation.prototype, { - toString: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"StringifierDefaultOperation\\", configurable: true } -}); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -2917,25 +2990,33 @@ const iface = { throw new TypeError(\`\${context} is not of type 'StringifierDefaultOperation'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(StringifierDefaultOperation.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"StringifierDefaultOperation\\"]; + if (ctor === undefined) { + throw new Error( + \\"Internal error: constructor StringifierDefaultOperation is not installed on the passed global object\\" + ); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(StringifierDefaultOperation.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -2945,16 +3026,42 @@ const iface = { } return obj; }, - interface: StringifierDefaultOperation, - expose: { - Window: { StringifierDefaultOperation } - } -}; // iface -module.exports = iface; -const Impl = require(\\"../implementations/StringifierDefaultOperation.js\\"); -" -`; + install(globalObject) { + class StringifierDefaultOperation { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } + + toString() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return this[impl].toString(); + } + } + Object.defineProperties(StringifierDefaultOperation.prototype, { + toString: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"StringifierDefaultOperation\\", configurable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"StringifierDefaultOperation\\"] = StringifierDefaultOperation; + + Object.defineProperty(globalObject, \\"StringifierDefaultOperation\\", { + configurable: true, + writable: true, + value: StringifierDefaultOperation + }); + } +}; // iface +module.exports = iface; + +const Impl = require(\\"../implementations/StringifierDefaultOperation.js\\"); +" +`; exports[`StringifierNamedOperation.webidl 1`] = ` "\\"use strict\\"; @@ -2963,33 +3070,8 @@ const conversions = require(\\"webidl-conversions\\"); const utils = require(\\"./utils.js\\"); const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; -class StringifierNamedOperation { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } - - operation() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - return this[impl].operation(); - } - - toString() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - return this[impl].operation(); - } -} -Object.defineProperties(StringifierNamedOperation.prototype, { - operation: { enumerable: true }, - toString: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"StringifierNamedOperation\\", configurable: true } -}); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -3030,25 +3112,33 @@ const iface = { throw new TypeError(\`\${context} is not of type 'StringifierNamedOperation'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(StringifierNamedOperation.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"StringifierNamedOperation\\"]; + if (ctor === undefined) { + throw new Error( + \\"Internal error: constructor StringifierNamedOperation is not installed on the passed global object\\" + ); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(StringifierNamedOperation.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -3058,9 +3148,44 @@ const iface = { } return obj; }, - interface: StringifierNamedOperation, - expose: { - Window: { StringifierNamedOperation } + + install(globalObject) { + class StringifierNamedOperation { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } + + operation() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return this[impl].operation(); + } + + toString() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return this[impl].operation(); + } + } + Object.defineProperties(StringifierNamedOperation.prototype, { + operation: { enumerable: true }, + toString: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"StringifierNamedOperation\\", configurable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"StringifierNamedOperation\\"] = StringifierNamedOperation; + + Object.defineProperty(globalObject, \\"StringifierNamedOperation\\", { + configurable: true, + writable: true, + value: StringifierNamedOperation + }); } }; // iface module.exports = iface; @@ -3076,24 +3201,8 @@ const conversions = require(\\"webidl-conversions\\"); const utils = require(\\"./utils.js\\"); const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; -class StringifierOperation { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } - - toString() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - return this[impl].toString(); - } -} -Object.defineProperties(StringifierOperation.prototype, { - toString: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"StringifierOperation\\", configurable: true } -}); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -3134,25 +3243,31 @@ const iface = { throw new TypeError(\`\${context} is not of type 'StringifierOperation'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(StringifierOperation.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"StringifierOperation\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor StringifierOperation is not installed on the passed global object\\"); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(StringifierOperation.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -3162,9 +3277,35 @@ const iface = { } return obj; }, - interface: StringifierOperation, - expose: { - Window: { StringifierOperation } + + install(globalObject) { + class StringifierOperation { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } + + toString() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return this[impl].toString(); + } + } + Object.defineProperties(StringifierOperation.prototype, { + toString: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"StringifierOperation\\", configurable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"StringifierOperation\\"] = StringifierOperation; + + Object.defineProperty(globalObject, \\"StringifierOperation\\", { + configurable: true, + writable: true, + value: StringifierOperation + }); } }; // iface module.exports = iface; @@ -3183,322 +3324,260 @@ const convertRequestDestination = require(\\"./RequestDestination.js\\").convert const isURL = require(\\"./URL.js\\").is; const convertURL = require(\\"./URL.js\\").convert; const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; -class TypedefsAndUnions { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } - - numOrStrConsumer(a) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'numOrStrConsumer' on 'TypedefsAndUnions': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - if (typeof curArg === \\"number\\") { - curArg = conversions[\\"double\\"](curArg, { - context: \\"Failed to execute 'numOrStrConsumer' on 'TypedefsAndUnions': parameter 1\\", - clamp: true - }); - } else { - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'numOrStrConsumer' on 'TypedefsAndUnions': parameter 1\\" - }); +const iface = { + // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` + // method into this array. It allows objects that directly implements *those* interfaces to be recognized as + // implementing this mixin interface. + _mixedIntoPredicates: [], + is(obj) { + if (obj) { + if (utils.hasOwn(obj, impl) && obj[impl] instanceof Impl.implementation) { + return true; } - args.push(curArg); - } - return this[impl].numOrStrConsumer(...args); - } - - numOrEnumConsumer(a) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'numOrEnumConsumer' on 'TypedefsAndUnions': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - if (curArg === null || curArg === undefined) { - curArg = null; - } else { - if (typeof curArg === \\"number\\") { - curArg = conversions[\\"double\\"](curArg, { - context: \\"Failed to execute 'numOrEnumConsumer' on 'TypedefsAndUnions': parameter 1\\" - }); - } else { - curArg = convertRequestDestination(curArg, { - context: \\"Failed to execute 'numOrEnumConsumer' on 'TypedefsAndUnions': parameter 1\\" - }); + for (const isMixedInto of module.exports._mixedIntoPredicates) { + if (isMixedInto(obj)) { + return true; } } - args.push(curArg); - } - return this[impl].numOrEnumConsumer(...args); - } - - numOrStrOrNullConsumer(a) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); } + return false; + }, + isImpl(obj) { + if (obj) { + if (obj instanceof Impl.implementation) { + return true; + } - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'numOrStrOrNullConsumer' on 'TypedefsAndUnions': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - if (curArg === null || curArg === undefined) { - curArg = null; - } else { - if (typeof curArg === \\"number\\") { - curArg = conversions[\\"double\\"](curArg, { - context: \\"Failed to execute 'numOrStrOrNullConsumer' on 'TypedefsAndUnions': parameter 1\\", - clamp: true, - enforceRange: true - }); - } else { - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'numOrStrOrNullConsumer' on 'TypedefsAndUnions': parameter 1\\", - enforceRange: true - }); + const wrapper = utils.wrapperForImpl(obj); + for (const isMixedInto of module.exports._mixedIntoPredicates) { + if (isMixedInto(wrapper)) { + return true; } } - args.push(curArg); } - return this[impl].numOrStrOrNullConsumer(...args); - } - - numOrStrOrURLOrNullConsumer(a) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); + return false; + }, + convert(obj, { context = \\"The provided value\\" } = {}) { + if (module.exports.is(obj)) { + return utils.implForWrapper(obj); } + throw new TypeError(\`\${context} is not of type 'TypedefsAndUnions'.\`); + }, - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'numOrStrOrURLOrNullConsumer' on 'TypedefsAndUnions': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - if (curArg === null || curArg === undefined) { - curArg = null; - } else { - if (isURL(curArg)) { - curArg = utils.implForWrapper(curArg); - } else if (typeof curArg === \\"number\\") { - curArg = conversions[\\"double\\"](curArg, { - context: \\"Failed to execute 'numOrStrOrURLOrNullConsumer' on 'TypedefsAndUnions': parameter 1\\", - clamp: true, - enforceRange: true - }); - } else { - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'numOrStrOrURLOrNullConsumer' on 'TypedefsAndUnions': parameter 1\\", - enforceRange: true - }); - } - } - args.push(curArg); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); } - return this[impl].numOrStrOrURLOrNullConsumer(...args); - } - urlMapInnerConsumer(a) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); + const ctor = globalObject[ctorRegistry][\\"TypedefsAndUnions\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor TypedefsAndUnions is not installed on the passed global object\\"); } - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'urlMapInnerConsumer' on 'TypedefsAndUnions': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); + return obj; + }, + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); + return utils.implForWrapper(obj); + }, + _internalSetup(obj) {}, + setup(obj, globalObject, constructorArgs = [], privateData = {}) { + privateData.wrapper = obj; + + iface._internalSetup(obj); + Object.defineProperty(obj, impl, { + value: new Impl.implementation(globalObject, constructorArgs, privateData), + configurable: true + }); + + obj[impl][utils.wrapperSymbol] = obj; + if (Impl.init) { + Impl.init(obj[impl], privateData); } - const args = []; - { - let curArg = arguments[0]; - if (!utils.isObject(curArg)) { - throw new TypeError( - \\"Failed to execute 'urlMapInnerConsumer' on 'TypedefsAndUnions': parameter 1\\" + \\" is not an object.\\" - ); - } else { - const result = Object.create(null); - for (const key of Reflect.ownKeys(curArg)) { - const desc = Object.getOwnPropertyDescriptor(curArg, key); - if (desc && desc.enumerable) { - let typedKey = key; - - typedKey = conversions[\\"USVString\\"](typedKey, { - context: \\"Failed to execute 'urlMapInnerConsumer' on 'TypedefsAndUnions': parameter 1\\" + \\"'s key\\" - }); + return obj; + }, - let typedValue = curArg[key]; + install(globalObject) { + class TypedefsAndUnions { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } - typedValue = convertURL(typedValue, { - context: \\"Failed to execute 'urlMapInnerConsumer' on 'TypedefsAndUnions': parameter 1\\" + \\"'s value\\" - }); + numOrStrConsumer(a) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - result[typedKey] = typedValue; + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'numOrStrConsumer' on 'TypedefsAndUnions': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + if (typeof curArg === \\"number\\") { + curArg = conversions[\\"double\\"](curArg, { + context: \\"Failed to execute 'numOrStrConsumer' on 'TypedefsAndUnions': parameter 1\\", + clamp: true + }); + } else { + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'numOrStrConsumer' on 'TypedefsAndUnions': parameter 1\\" + }); } + args.push(curArg); } - curArg = result; + return this[impl].numOrStrConsumer(...args); } - args.push(curArg); - } - return this[impl].urlMapInnerConsumer(...args); - } - urlMapConsumer(a) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + numOrEnumConsumer(a) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'urlMapConsumer' on 'TypedefsAndUnions': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - if (curArg === null || curArg === undefined) { - curArg = null; - } else { - if (!utils.isObject(curArg)) { + if (arguments.length < 1) { throw new TypeError( - \\"Failed to execute 'urlMapConsumer' on 'TypedefsAndUnions': parameter 1\\" + \\" is not an object.\\" + \\"Failed to execute 'numOrEnumConsumer' on 'TypedefsAndUnions': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" ); - } else { - const result = Object.create(null); - for (const key of Reflect.ownKeys(curArg)) { - const desc = Object.getOwnPropertyDescriptor(curArg, key); - if (desc && desc.enumerable) { - let typedKey = key; - - typedKey = conversions[\\"USVString\\"](typedKey, { - context: \\"Failed to execute 'urlMapConsumer' on 'TypedefsAndUnions': parameter 1\\" + \\"'s key\\" + } + const args = []; + { + let curArg = arguments[0]; + if (curArg === null || curArg === undefined) { + curArg = null; + } else { + if (typeof curArg === \\"number\\") { + curArg = conversions[\\"double\\"](curArg, { + context: \\"Failed to execute 'numOrEnumConsumer' on 'TypedefsAndUnions': parameter 1\\" }); - - let typedValue = curArg[key]; - - typedValue = convertURL(typedValue, { - context: \\"Failed to execute 'urlMapConsumer' on 'TypedefsAndUnions': parameter 1\\" + \\"'s value\\" + } else { + curArg = convertRequestDestination(curArg, { + context: \\"Failed to execute 'numOrEnumConsumer' on 'TypedefsAndUnions': parameter 1\\" }); - - result[typedKey] = typedValue; } } - curArg = result; + args.push(curArg); } + return this[impl].numOrEnumConsumer(...args); } - args.push(curArg); - } - return this[impl].urlMapConsumer(...args); - } - bufferSourceOrURLConsumer(b) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + numOrStrOrNullConsumer(a) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'bufferSourceOrURLConsumer' on 'TypedefsAndUnions': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - if (isURL(curArg)) { - curArg = utils.implForWrapper(curArg); - } else if (curArg instanceof ArrayBuffer) { - } else if (ArrayBuffer.isView(curArg)) { - } else { - throw new TypeError( - \\"Failed to execute 'bufferSourceOrURLConsumer' on 'TypedefsAndUnions': parameter 1\\" + - \\" is not of any supported type.\\" - ); + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'numOrStrOrNullConsumer' on 'TypedefsAndUnions': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + if (curArg === null || curArg === undefined) { + curArg = null; + } else { + if (typeof curArg === \\"number\\") { + curArg = conversions[\\"double\\"](curArg, { + context: \\"Failed to execute 'numOrStrOrNullConsumer' on 'TypedefsAndUnions': parameter 1\\", + clamp: true, + enforceRange: true + }); + } else { + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'numOrStrOrNullConsumer' on 'TypedefsAndUnions': parameter 1\\", + enforceRange: true + }); + } + } + args.push(curArg); + } + return this[impl].numOrStrOrNullConsumer(...args); } - args.push(curArg); - } - return this[impl].bufferSourceOrURLConsumer(...args); - } - arrayBufferViewOrURLMapConsumer(b) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + numOrStrOrURLOrNullConsumer(a) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'arrayBufferViewOrURLMapConsumer' on 'TypedefsAndUnions': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - if (curArg === null || curArg === undefined) { - curArg = null; - } else { - if (ArrayBuffer.isView(curArg)) { - } else if (utils.isObject(curArg)) { - if (!utils.isObject(curArg)) { - throw new TypeError( - \\"Failed to execute 'arrayBufferViewOrURLMapConsumer' on 'TypedefsAndUnions': parameter 1\\" + - \\" record\\" + - \\" is not an object.\\" - ); - } else { - const result = Object.create(null); - for (const key of Reflect.ownKeys(curArg)) { - const desc = Object.getOwnPropertyDescriptor(curArg, key); + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'numOrStrOrURLOrNullConsumer' on 'TypedefsAndUnions': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + if (curArg === null || curArg === undefined) { + curArg = null; + } else { + if (isURL(curArg)) { + curArg = utils.implForWrapper(curArg); + } else if (typeof curArg === \\"number\\") { + curArg = conversions[\\"double\\"](curArg, { + context: \\"Failed to execute 'numOrStrOrURLOrNullConsumer' on 'TypedefsAndUnions': parameter 1\\", + clamp: true, + enforceRange: true + }); + } else { + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'numOrStrOrURLOrNullConsumer' on 'TypedefsAndUnions': parameter 1\\", + enforceRange: true + }); + } + } + args.push(curArg); + } + return this[impl].numOrStrOrURLOrNullConsumer(...args); + } + + urlMapInnerConsumer(a) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'urlMapInnerConsumer' on 'TypedefsAndUnions': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + if (!utils.isObject(curArg)) { + throw new TypeError( + \\"Failed to execute 'urlMapInnerConsumer' on 'TypedefsAndUnions': parameter 1\\" + \\" is not an object.\\" + ); + } else { + const result = Object.create(null); + for (const key of Reflect.ownKeys(curArg)) { + const desc = Object.getOwnPropertyDescriptor(curArg, key); if (desc && desc.enumerable) { let typedKey = key; typedKey = conversions[\\"USVString\\"](typedKey, { - context: - \\"Failed to execute 'arrayBufferViewOrURLMapConsumer' on 'TypedefsAndUnions': parameter 1\\" + - \\" record\\" + - \\"'s key\\" + context: \\"Failed to execute 'urlMapInnerConsumer' on 'TypedefsAndUnions': parameter 1\\" + \\"'s key\\" }); let typedValue = curArg[key]; typedValue = convertURL(typedValue, { - context: - \\"Failed to execute 'arrayBufferViewOrURLMapConsumer' on 'TypedefsAndUnions': parameter 1\\" + - \\" record\\" + - \\"'s value\\" + context: \\"Failed to execute 'urlMapInnerConsumer' on 'TypedefsAndUnions': parameter 1\\" + \\"'s value\\" }); result[typedKey] = typedValue; @@ -3506,102 +3585,269 @@ class TypedefsAndUnions { } curArg = result; } + args.push(curArg); + } + return this[impl].urlMapInnerConsumer(...args); + } + + urlMapConsumer(a) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'urlMapConsumer' on 'TypedefsAndUnions': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + if (curArg === null || curArg === undefined) { + curArg = null; + } else { + if (!utils.isObject(curArg)) { + throw new TypeError( + \\"Failed to execute 'urlMapConsumer' on 'TypedefsAndUnions': parameter 1\\" + \\" is not an object.\\" + ); + } else { + const result = Object.create(null); + for (const key of Reflect.ownKeys(curArg)) { + const desc = Object.getOwnPropertyDescriptor(curArg, key); + if (desc && desc.enumerable) { + let typedKey = key; + + typedKey = conversions[\\"USVString\\"](typedKey, { + context: \\"Failed to execute 'urlMapConsumer' on 'TypedefsAndUnions': parameter 1\\" + \\"'s key\\" + }); + + let typedValue = curArg[key]; + + typedValue = convertURL(typedValue, { + context: \\"Failed to execute 'urlMapConsumer' on 'TypedefsAndUnions': parameter 1\\" + \\"'s value\\" + }); + + result[typedKey] = typedValue; + } + } + curArg = result; + } + } + args.push(curArg); + } + return this[impl].urlMapConsumer(...args); + } + + bufferSourceOrURLConsumer(b) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'bufferSourceOrURLConsumer' on 'TypedefsAndUnions': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + if (isURL(curArg)) { + curArg = utils.implForWrapper(curArg); + } else if (curArg instanceof ArrayBuffer) { + } else if (ArrayBuffer.isView(curArg)) { + } else { + throw new TypeError( + \\"Failed to execute 'bufferSourceOrURLConsumer' on 'TypedefsAndUnions': parameter 1\\" + + \\" is not of any supported type.\\" + ); + } + args.push(curArg); + } + return this[impl].bufferSourceOrURLConsumer(...args); + } + + arrayBufferViewOrURLMapConsumer(b) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'arrayBufferViewOrURLMapConsumer' on 'TypedefsAndUnions': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + if (curArg === null || curArg === undefined) { + curArg = null; + } else { + if (ArrayBuffer.isView(curArg)) { + } else if (utils.isObject(curArg)) { + if (!utils.isObject(curArg)) { + throw new TypeError( + \\"Failed to execute 'arrayBufferViewOrURLMapConsumer' on 'TypedefsAndUnions': parameter 1\\" + + \\" record\\" + + \\" is not an object.\\" + ); + } else { + const result = Object.create(null); + for (const key of Reflect.ownKeys(curArg)) { + const desc = Object.getOwnPropertyDescriptor(curArg, key); + if (desc && desc.enumerable) { + let typedKey = key; + + typedKey = conversions[\\"USVString\\"](typedKey, { + context: + \\"Failed to execute 'arrayBufferViewOrURLMapConsumer' on 'TypedefsAndUnions': parameter 1\\" + + \\" record\\" + + \\"'s key\\" + }); + + let typedValue = curArg[key]; + + typedValue = convertURL(typedValue, { + context: + \\"Failed to execute 'arrayBufferViewOrURLMapConsumer' on 'TypedefsAndUnions': parameter 1\\" + + \\" record\\" + + \\"'s value\\" + }); + + result[typedKey] = typedValue; + } + } + curArg = result; + } + } else { + throw new TypeError( + \\"Failed to execute 'arrayBufferViewOrURLMapConsumer' on 'TypedefsAndUnions': parameter 1\\" + + \\" is not of any supported type.\\" + ); + } + } + args.push(curArg); + } + return this[impl].arrayBufferViewOrURLMapConsumer(...args); + } + + arrayBufferViewDupConsumer(b) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'arrayBufferViewDupConsumer' on 'TypedefsAndUnions': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + if (ArrayBuffer.isView(curArg)) { + } else { + throw new TypeError( + \\"Failed to execute 'arrayBufferViewDupConsumer' on 'TypedefsAndUnions': parameter 1\\" + + \\" is not of any supported type.\\" + ); + } + args.push(curArg); + } + return this[impl].arrayBufferViewDupConsumer(...args); + } + + get buf() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return utils.tryWrapperForImpl(this[impl][\\"buf\\"]); + } + + set buf(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (V instanceof ArrayBuffer) { + } else if (ArrayBuffer.isView(V) && (V instanceof Uint8Array || V instanceof Uint16Array)) { } else { throw new TypeError( - \\"Failed to execute 'arrayBufferViewOrURLMapConsumer' on 'TypedefsAndUnions': parameter 1\\" + + \\"Failed to set the 'buf' property on 'TypedefsAndUnions': The provided value\\" + \\" is not of any supported type.\\" ); } + this[impl][\\"buf\\"] = V; } - args.push(curArg); - } - return this[impl].arrayBufferViewOrURLMapConsumer(...args); - } - arrayBufferViewDupConsumer(b) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + get time() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'arrayBufferViewDupConsumer' on 'TypedefsAndUnions': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - if (ArrayBuffer.isView(curArg)) { - } else { - throw new TypeError( - \\"Failed to execute 'arrayBufferViewDupConsumer' on 'TypedefsAndUnions': parameter 1\\" + - \\" is not of any supported type.\\" - ); + return this[impl][\\"time\\"]; } - args.push(curArg); - } - return this[impl].arrayBufferViewDupConsumer(...args); - } - get buf() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + set time(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - return utils.tryWrapperForImpl(this[impl][\\"buf\\"]); - } + V = conversions[\\"unsigned long long\\"](V, { + context: \\"Failed to set the 'time' property on 'TypedefsAndUnions': The provided value\\" + }); - set buf(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); + this[impl][\\"time\\"] = V; + } + } + Object.defineProperties(TypedefsAndUnions.prototype, { + numOrStrConsumer: { enumerable: true }, + numOrEnumConsumer: { enumerable: true }, + numOrStrOrNullConsumer: { enumerable: true }, + numOrStrOrURLOrNullConsumer: { enumerable: true }, + urlMapInnerConsumer: { enumerable: true }, + urlMapConsumer: { enumerable: true }, + bufferSourceOrURLConsumer: { enumerable: true }, + arrayBufferViewOrURLMapConsumer: { enumerable: true }, + arrayBufferViewDupConsumer: { enumerable: true }, + buf: { enumerable: true }, + time: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"TypedefsAndUnions\\", configurable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); } + globalObject[ctorRegistry][\\"TypedefsAndUnions\\"] = TypedefsAndUnions; - if (V instanceof ArrayBuffer) { - } else if (ArrayBuffer.isView(V) && (V instanceof Uint8Array || V instanceof Uint16Array)) { - } else { - throw new TypeError( - \\"Failed to set the 'buf' property on 'TypedefsAndUnions': The provided value\\" + \\" is not of any supported type.\\" - ); - } - this[impl][\\"buf\\"] = V; + Object.defineProperty(globalObject, \\"TypedefsAndUnions\\", { + configurable: true, + writable: true, + value: TypedefsAndUnions + }); } +}; // iface +module.exports = iface; - get time() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } +const Impl = require(\\"../implementations/TypedefsAndUnions.js\\"); +" +`; - return this[impl][\\"time\\"]; - } +exports[`URL.webidl 1`] = ` +"\\"use strict\\"; - set time(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } +const conversions = require(\\"webidl-conversions\\"); +const utils = require(\\"./utils.js\\"); - V = conversions[\\"unsigned long long\\"](V, { - context: \\"Failed to set the 'time' property on 'TypedefsAndUnions': The provided value\\" - }); +const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; - this[impl][\\"time\\"] = V; - } -} -Object.defineProperties(TypedefsAndUnions.prototype, { - numOrStrConsumer: { enumerable: true }, - numOrEnumConsumer: { enumerable: true }, - numOrStrOrNullConsumer: { enumerable: true }, - numOrStrOrURLOrNullConsumer: { enumerable: true }, - urlMapInnerConsumer: { enumerable: true }, - urlMapConsumer: { enumerable: true }, - bufferSourceOrURLConsumer: { enumerable: true }, - arrayBufferViewOrURLMapConsumer: { enumerable: true }, - arrayBufferViewDupConsumer: { enumerable: true }, - buf: { enumerable: true }, - time: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"TypedefsAndUnions\\", configurable: true } -}); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -3639,28 +3885,34 @@ const iface = { if (module.exports.is(obj)) { return utils.implForWrapper(obj); } - throw new TypeError(\`\${context} is not of type 'TypedefsAndUnions'.\`); + throw new TypeError(\`\${context} is not of type 'URL'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(TypedefsAndUnions.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"URL\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor URL is not installed on the passed global object\\"); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(TypedefsAndUnions.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -3670,348 +3922,283 @@ const iface = { } return obj; }, - interface: TypedefsAndUnions, - expose: { - Window: { TypedefsAndUnions } - } -}; // iface -module.exports = iface; -const Impl = require(\\"../implementations/TypedefsAndUnions.js\\"); -" -`; + install(globalObject) { + class URL { + constructor(url) { + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to construct 'URL': 1 argument required, but only \\" + arguments.length + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions[\\"USVString\\"](curArg, { context: \\"Failed to construct 'URL': parameter 1\\" }); + args.push(curArg); + } + { + let curArg = arguments[1]; + if (curArg !== undefined) { + curArg = conversions[\\"USVString\\"](curArg, { context: \\"Failed to construct 'URL': parameter 2\\" }); + } + args.push(curArg); + } + return iface.setup(Object.create(new.target.prototype), globalObject, args); + } -exports[`URL.webidl 1`] = ` -"\\"use strict\\"; + toJSON() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } -const conversions = require(\\"webidl-conversions\\"); -const utils = require(\\"./utils.js\\"); + return this[impl].toJSON(); + } -const impl = utils.implSymbol; + get href() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } -class URL { - constructor(url) { - if (arguments.length < 1) { - throw new TypeError(\\"Failed to construct 'URL': 1 argument required, but only \\" + arguments.length + \\" present.\\"); - } - const args = []; - { - let curArg = arguments[0]; - curArg = conversions[\\"USVString\\"](curArg, { context: \\"Failed to construct 'URL': parameter 1\\" }); - args.push(curArg); - } - { - let curArg = arguments[1]; - if (curArg !== undefined) { - curArg = conversions[\\"USVString\\"](curArg, { context: \\"Failed to construct 'URL': parameter 2\\" }); + return this[impl][\\"href\\"]; } - args.push(curArg); - } - return iface.setup(Object.create(new.target.prototype), args); - } - - toJSON() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - return this[impl].toJSON(); - } + set href(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - get href() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + V = conversions[\\"USVString\\"](V, { context: \\"Failed to set the 'href' property on 'URL': The provided value\\" }); - return this[impl][\\"href\\"]; - } + this[impl][\\"href\\"] = V; + } - set href(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + toString() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + return this[impl][\\"href\\"]; + } - V = conversions[\\"USVString\\"](V, { context: \\"Failed to set the 'href' property on 'URL': The provided value\\" }); + get origin() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - this[impl][\\"href\\"] = V; - } + return this[impl][\\"origin\\"]; + } - toString() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - return this[impl][\\"href\\"]; - } - - get origin() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - return this[impl][\\"origin\\"]; - } - - get protocol() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - return this[impl][\\"protocol\\"]; - } - - set protocol(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - V = conversions[\\"USVString\\"](V, { context: \\"Failed to set the 'protocol' property on 'URL': The provided value\\" }); - - this[impl][\\"protocol\\"] = V; - } - - get username() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + get protocol() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - return this[impl][\\"username\\"]; - } + return this[impl][\\"protocol\\"]; + } - set username(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + set protocol(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - V = conversions[\\"USVString\\"](V, { context: \\"Failed to set the 'username' property on 'URL': The provided value\\" }); + V = conversions[\\"USVString\\"](V, { + context: \\"Failed to set the 'protocol' property on 'URL': The provided value\\" + }); - this[impl][\\"username\\"] = V; - } + this[impl][\\"protocol\\"] = V; + } - get password() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + get username() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - return this[impl][\\"password\\"]; - } + return this[impl][\\"username\\"]; + } - set password(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + set username(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - V = conversions[\\"USVString\\"](V, { context: \\"Failed to set the 'password' property on 'URL': The provided value\\" }); + V = conversions[\\"USVString\\"](V, { + context: \\"Failed to set the 'username' property on 'URL': The provided value\\" + }); - this[impl][\\"password\\"] = V; - } + this[impl][\\"username\\"] = V; + } - get host() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + get password() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - return this[impl][\\"host\\"]; - } + return this[impl][\\"password\\"]; + } - set host(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + set password(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - V = conversions[\\"USVString\\"](V, { context: \\"Failed to set the 'host' property on 'URL': The provided value\\" }); + V = conversions[\\"USVString\\"](V, { + context: \\"Failed to set the 'password' property on 'URL': The provided value\\" + }); - this[impl][\\"host\\"] = V; - } + this[impl][\\"password\\"] = V; + } - get hostname() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + get host() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - return this[impl][\\"hostname\\"]; - } + return this[impl][\\"host\\"]; + } - set hostname(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + set host(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - V = conversions[\\"USVString\\"](V, { context: \\"Failed to set the 'hostname' property on 'URL': The provided value\\" }); + V = conversions[\\"USVString\\"](V, { context: \\"Failed to set the 'host' property on 'URL': The provided value\\" }); - this[impl][\\"hostname\\"] = V; - } + this[impl][\\"host\\"] = V; + } - get port() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + get hostname() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - return this[impl][\\"port\\"]; - } + return this[impl][\\"hostname\\"]; + } - set port(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + set hostname(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - V = conversions[\\"USVString\\"](V, { context: \\"Failed to set the 'port' property on 'URL': The provided value\\" }); + V = conversions[\\"USVString\\"](V, { + context: \\"Failed to set the 'hostname' property on 'URL': The provided value\\" + }); - this[impl][\\"port\\"] = V; - } + this[impl][\\"hostname\\"] = V; + } - get pathname() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + get port() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - return this[impl][\\"pathname\\"]; - } + return this[impl][\\"port\\"]; + } - set pathname(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + set port(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - V = conversions[\\"USVString\\"](V, { context: \\"Failed to set the 'pathname' property on 'URL': The provided value\\" }); + V = conversions[\\"USVString\\"](V, { context: \\"Failed to set the 'port' property on 'URL': The provided value\\" }); - this[impl][\\"pathname\\"] = V; - } + this[impl][\\"port\\"] = V; + } - get search() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + get pathname() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - return this[impl][\\"search\\"]; - } + return this[impl][\\"pathname\\"]; + } - set search(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + set pathname(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - V = conversions[\\"USVString\\"](V, { context: \\"Failed to set the 'search' property on 'URL': The provided value\\" }); + V = conversions[\\"USVString\\"](V, { + context: \\"Failed to set the 'pathname' property on 'URL': The provided value\\" + }); - this[impl][\\"search\\"] = V; - } + this[impl][\\"pathname\\"] = V; + } - get searchParams() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + get search() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - return utils.getSameObject(this, \\"searchParams\\", () => { - return utils.tryWrapperForImpl(this[impl][\\"searchParams\\"]); - }); - } + return this[impl][\\"search\\"]; + } - get hash() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + set search(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - return this[impl][\\"hash\\"]; - } + V = conversions[\\"USVString\\"](V, { + context: \\"Failed to set the 'search' property on 'URL': The provided value\\" + }); - set hash(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + this[impl][\\"search\\"] = V; + } - V = conversions[\\"USVString\\"](V, { context: \\"Failed to set the 'hash' property on 'URL': The provided value\\" }); + get searchParams() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - this[impl][\\"hash\\"] = V; - } -} -Object.defineProperties(URL.prototype, { - toJSON: { enumerable: true }, - href: { enumerable: true }, - toString: { enumerable: true }, - origin: { enumerable: true }, - protocol: { enumerable: true }, - username: { enumerable: true }, - password: { enumerable: true }, - host: { enumerable: true }, - hostname: { enumerable: true }, - port: { enumerable: true }, - pathname: { enumerable: true }, - search: { enumerable: true }, - searchParams: { enumerable: true }, - hash: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"URL\\", configurable: true } -}); -const iface = { - // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` - // method into this array. It allows objects that directly implements *those* interfaces to be recognized as - // implementing this mixin interface. - _mixedIntoPredicates: [], - is(obj) { - if (obj) { - if (utils.hasOwn(obj, impl) && obj[impl] instanceof Impl.implementation) { - return true; + return utils.getSameObject(this, \\"searchParams\\", () => { + return utils.tryWrapperForImpl(this[impl][\\"searchParams\\"]); + }); } - for (const isMixedInto of module.exports._mixedIntoPredicates) { - if (isMixedInto(obj)) { - return true; + + get hash() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); } - } - } - return false; - }, - isImpl(obj) { - if (obj) { - if (obj instanceof Impl.implementation) { - return true; + + return this[impl][\\"hash\\"]; } - const wrapper = utils.wrapperForImpl(obj); - for (const isMixedInto of module.exports._mixedIntoPredicates) { - if (isMixedInto(wrapper)) { - return true; + set hash(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); } + + V = conversions[\\"USVString\\"](V, { context: \\"Failed to set the 'hash' property on 'URL': The provided value\\" }); + + this[impl][\\"hash\\"] = V; } } - return false; - }, - convert(obj, { context = \\"The provided value\\" } = {}) { - if (module.exports.is(obj)) { - return utils.implForWrapper(obj); + Object.defineProperties(URL.prototype, { + toJSON: { enumerable: true }, + href: { enumerable: true }, + toString: { enumerable: true }, + origin: { enumerable: true }, + protocol: { enumerable: true }, + username: { enumerable: true }, + password: { enumerable: true }, + host: { enumerable: true }, + hostname: { enumerable: true }, + port: { enumerable: true }, + pathname: { enumerable: true }, + search: { enumerable: true }, + searchParams: { enumerable: true }, + hash: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"URL\\", configurable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); } - throw new TypeError(\`\${context} is not of type 'URL'.\`); - }, - - create(constructorArgs, privateData) { - let obj = Object.create(URL.prototype); - obj = this.setup(obj, constructorArgs, privateData); - return obj; - }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(URL.prototype); - obj = this.setup(obj, constructorArgs, privateData); - return utils.implForWrapper(obj); - }, - _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; + globalObject[ctorRegistry][\\"URL\\"] = URL; - privateData.wrapper = obj; - - this._internalSetup(obj); - Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), - configurable: true + Object.defineProperty(globalObject, \\"URL\\", { + configurable: true, + writable: true, + value: URL }); - - obj[impl][utils.wrapperSymbol] = obj; - if (Impl.init) { - Impl.init(obj[impl], privateData); - } - return obj; - }, - interface: URL, - expose: { - Window: { URL }, - Worker: { URL } } }; // iface module.exports = iface; @@ -4027,49 +4214,8 @@ const conversions = require(\\"webidl-conversions\\"); const utils = require(\\"./utils.js\\"); const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; -class URLList { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } - - item(index) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'item' on 'URLList': 1 argument required, but only \\" + arguments.length + \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - curArg = conversions[\\"unsigned long\\"](curArg, { context: \\"Failed to execute 'item' on 'URLList': parameter 1\\" }); - args.push(curArg); - } - return utils.tryWrapperForImpl(this[impl].item(...args)); - } - - get length() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - return this[impl][\\"length\\"]; - } -} -Object.defineProperties(URLList.prototype, { - item: { enumerable: true }, - length: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"URLList\\", configurable: true }, - [Symbol.iterator]: { value: Array.prototype[Symbol.iterator], configurable: true, writable: true }, - keys: { value: Array.prototype.keys, configurable: true, enumerable: true, writable: true }, - values: { value: Array.prototype[Symbol.iterator], configurable: true, enumerable: true, writable: true }, - entries: { value: Array.prototype.entries, configurable: true, enumerable: true, writable: true }, - forEach: { value: Array.prototype.forEach, configurable: true, enumerable: true, writable: true } -}); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -4110,25 +4256,31 @@ const iface = { throw new TypeError(\`\${context} is not of type 'URLList'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(URLList.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"URLList\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor URLList is not installed on the passed global object\\"); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(URLList.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -4298,9 +4450,62 @@ const iface = { } return obj; }, - interface: URLList, - expose: { - Window: { URLList } + + install(globalObject) { + class URLList { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } + + item(index) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'item' on 'URLList': 1 argument required, but only \\" + arguments.length + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions[\\"unsigned long\\"](curArg, { + context: \\"Failed to execute 'item' on 'URLList': parameter 1\\" + }); + args.push(curArg); + } + return utils.tryWrapperForImpl(this[impl].item(...args)); + } + + get length() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return this[impl][\\"length\\"]; + } + } + Object.defineProperties(URLList.prototype, { + item: { enumerable: true }, + length: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"URLList\\", configurable: true }, + [Symbol.iterator]: { value: Array.prototype[Symbol.iterator], configurable: true, writable: true }, + keys: { value: Array.prototype.keys, configurable: true, enumerable: true, writable: true }, + values: { value: Array.prototype[Symbol.iterator], configurable: true, enumerable: true, writable: true }, + entries: { value: Array.prototype.entries, configurable: true, enumerable: true, writable: true }, + forEach: { value: Array.prototype.forEach, configurable: true, enumerable: true, writable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"URLList\\"] = URLList; + + Object.defineProperty(globalObject, \\"URLList\\", { + configurable: true, + writable: true, + value: URLList + }); } }; // iface module.exports = iface; @@ -4316,6 +4521,7 @@ const conversions = require(\\"webidl-conversions\\"); const utils = require(\\"./utils.js\\"); const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; const IteratorPrototype = Object.create(utils.IteratorPrototype, { next: { @@ -4355,389 +4561,417 @@ const IteratorPrototype = Object.create(utils.IteratorPrototype, { configurable: true } }); -class URLSearchParams { - constructor() { - const args = []; - { - let curArg = arguments[0]; - if (curArg !== undefined) { - if (utils.isObject(curArg)) { - if (curArg[Symbol.iterator] !== undefined) { - if (!utils.isObject(curArg)) { - throw new TypeError( - \\"Failed to construct 'URLSearchParams': parameter 1\\" + \\" sequence\\" + \\" is not an iterable object.\\" - ); - } else { - const V = []; - const tmp = curArg; - for (let nextItem of tmp) { - if (!utils.isObject(nextItem)) { - throw new TypeError( - \\"Failed to construct 'URLSearchParams': parameter 1\\" + - \\" sequence\\" + - \\"'s element\\" + - \\" is not an iterable object.\\" - ); - } else { - const V = []; - const tmp = nextItem; - for (let nextItem of tmp) { - nextItem = conversions[\\"USVString\\"](nextItem, { - context: - \\"Failed to construct 'URLSearchParams': parameter 1\\" + \\" sequence\\" + \\"'s element\\" + \\"'s element\\" - }); - - V.push(nextItem); - } - nextItem = V; - } - V.push(nextItem); - } - curArg = V; - } - } else { - if (!utils.isObject(curArg)) { - throw new TypeError( - \\"Failed to construct 'URLSearchParams': parameter 1\\" + \\" record\\" + \\" is not an object.\\" - ); - } else { - const result = Object.create(null); - for (const key of Reflect.ownKeys(curArg)) { - const desc = Object.getOwnPropertyDescriptor(curArg, key); - if (desc && desc.enumerable) { - let typedKey = key; - - typedKey = conversions[\\"USVString\\"](typedKey, { - context: \\"Failed to construct 'URLSearchParams': parameter 1\\" + \\" record\\" + \\"'s key\\" - }); - - let typedValue = curArg[key]; - - typedValue = conversions[\\"USVString\\"](typedValue, { - context: \\"Failed to construct 'URLSearchParams': parameter 1\\" + \\" record\\" + \\"'s value\\" - }); - - result[typedKey] = typedValue; - } - } - curArg = result; - } - } - } else { - curArg = conversions[\\"USVString\\"](curArg, { context: \\"Failed to construct 'URLSearchParams': parameter 1\\" }); +const iface = { + // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` + // method into this array. It allows objects that directly implements *those* interfaces to be recognized as + // implementing this mixin interface. + _mixedIntoPredicates: [], + is(obj) { + if (obj) { + if (utils.hasOwn(obj, impl) && obj[impl] instanceof Impl.implementation) { + return true; + } + for (const isMixedInto of module.exports._mixedIntoPredicates) { + if (isMixedInto(obj)) { + return true; } - } else { - curArg = \\"\\"; } - args.push(curArg); - } - return iface.setup(Object.create(new.target.prototype), args); - } - - append(name, value) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); } + return false; + }, + isImpl(obj) { + if (obj) { + if (obj instanceof Impl.implementation) { + return true; + } - if (arguments.length < 2) { - throw new TypeError( - \\"Failed to execute 'append' on 'URLSearchParams': 2 arguments required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - curArg = conversions[\\"USVString\\"](curArg, { - context: \\"Failed to execute 'append' on 'URLSearchParams': parameter 1\\" - }); - args.push(curArg); + const wrapper = utils.wrapperForImpl(obj); + for (const isMixedInto of module.exports._mixedIntoPredicates) { + if (isMixedInto(wrapper)) { + return true; + } + } } - { - let curArg = arguments[1]; - curArg = conversions[\\"USVString\\"](curArg, { - context: \\"Failed to execute 'append' on 'URLSearchParams': parameter 2\\" - }); - args.push(curArg); + return false; + }, + convert(obj, { context = \\"The provided value\\" } = {}) { + if (module.exports.is(obj)) { + return utils.implForWrapper(obj); } - return this[impl].append(...args); - } + throw new TypeError(\`\${context} is not of type 'URLSearchParams'.\`); + }, - delete(name) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + createDefaultIterator(target, kind) { + const iterator = Object.create(IteratorPrototype); + Object.defineProperty(iterator, utils.iterInternalSymbol, { + value: { target, kind, index: 0 }, + configurable: true + }); + return iterator; + }, - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'delete' on 'URLSearchParams': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - curArg = conversions[\\"USVString\\"](curArg, { - context: \\"Failed to execute 'delete' on 'URLSearchParams': parameter 1\\" - }); - args.push(curArg); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); } - return this[impl].delete(...args); - } - get(name) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); + const ctor = globalObject[ctorRegistry][\\"URLSearchParams\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor URLSearchParams is not installed on the passed global object\\"); } - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'get' on 'URLSearchParams': 1 argument required, but only \\" + arguments.length + \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - curArg = conversions[\\"USVString\\"](curArg, { - context: \\"Failed to execute 'get' on 'URLSearchParams': parameter 1\\" - }); - args.push(curArg); - } - return this[impl].get(...args); - } + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); + return obj; + }, + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); + return utils.implForWrapper(obj); + }, + _internalSetup(obj) {}, + setup(obj, globalObject, constructorArgs = [], privateData = {}) { + privateData.wrapper = obj; - getAll(name) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + iface._internalSetup(obj); + Object.defineProperty(obj, impl, { + value: new Impl.implementation(globalObject, constructorArgs, privateData), + configurable: true + }); - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'getAll' on 'URLSearchParams': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - curArg = conversions[\\"USVString\\"](curArg, { - context: \\"Failed to execute 'getAll' on 'URLSearchParams': parameter 1\\" - }); - args.push(curArg); + obj[impl][utils.wrapperSymbol] = obj; + if (Impl.init) { + Impl.init(obj[impl], privateData); } - return utils.tryWrapperForImpl(this[impl].getAll(...args)); - } + return obj; + }, - has(name) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + install(globalObject) { + class URLSearchParams { + constructor() { + const args = []; + { + let curArg = arguments[0]; + if (curArg !== undefined) { + if (utils.isObject(curArg)) { + if (curArg[Symbol.iterator] !== undefined) { + if (!utils.isObject(curArg)) { + throw new TypeError( + \\"Failed to construct 'URLSearchParams': parameter 1\\" + \\" sequence\\" + \\" is not an iterable object.\\" + ); + } else { + const V = []; + const tmp = curArg; + for (let nextItem of tmp) { + if (!utils.isObject(nextItem)) { + throw new TypeError( + \\"Failed to construct 'URLSearchParams': parameter 1\\" + + \\" sequence\\" + + \\"'s element\\" + + \\" is not an iterable object.\\" + ); + } else { + const V = []; + const tmp = nextItem; + for (let nextItem of tmp) { + nextItem = conversions[\\"USVString\\"](nextItem, { + context: + \\"Failed to construct 'URLSearchParams': parameter 1\\" + + \\" sequence\\" + + \\"'s element\\" + + \\"'s element\\" + }); + + V.push(nextItem); + } + nextItem = V; + } - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'has' on 'URLSearchParams': 1 argument required, but only \\" + arguments.length + \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - curArg = conversions[\\"USVString\\"](curArg, { - context: \\"Failed to execute 'has' on 'URLSearchParams': parameter 1\\" - }); - args.push(curArg); - } - return this[impl].has(...args); - } + V.push(nextItem); + } + curArg = V; + } + } else { + if (!utils.isObject(curArg)) { + throw new TypeError( + \\"Failed to construct 'URLSearchParams': parameter 1\\" + \\" record\\" + \\" is not an object.\\" + ); + } else { + const result = Object.create(null); + for (const key of Reflect.ownKeys(curArg)) { + const desc = Object.getOwnPropertyDescriptor(curArg, key); + if (desc && desc.enumerable) { + let typedKey = key; - set(name, value) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + typedKey = conversions[\\"USVString\\"](typedKey, { + context: \\"Failed to construct 'URLSearchParams': parameter 1\\" + \\" record\\" + \\"'s key\\" + }); - if (arguments.length < 2) { - throw new TypeError( - \\"Failed to execute 'set' on 'URLSearchParams': 2 arguments required, but only \\" + arguments.length + \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - curArg = conversions[\\"USVString\\"](curArg, { - context: \\"Failed to execute 'set' on 'URLSearchParams': parameter 1\\" - }); - args.push(curArg); - } - { - let curArg = arguments[1]; - curArg = conversions[\\"USVString\\"](curArg, { - context: \\"Failed to execute 'set' on 'URLSearchParams': parameter 2\\" - }); - args.push(curArg); - } - return this[impl].set(...args); - } + let typedValue = curArg[key]; - sort() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + typedValue = conversions[\\"USVString\\"](typedValue, { + context: \\"Failed to construct 'URLSearchParams': parameter 1\\" + \\" record\\" + \\"'s value\\" + }); - return this[impl].sort(); - } + result[typedKey] = typedValue; + } + } + curArg = result; + } + } + } else { + curArg = conversions[\\"USVString\\"](curArg, { + context: \\"Failed to construct 'URLSearchParams': parameter 1\\" + }); + } + } else { + curArg = \\"\\"; + } + args.push(curArg); + } + return iface.setup(Object.create(new.target.prototype), globalObject, args); + } - toString() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } + append(name, value) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - return this[impl].toString(); - } + if (arguments.length < 2) { + throw new TypeError( + \\"Failed to execute 'append' on 'URLSearchParams': 2 arguments required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions[\\"USVString\\"](curArg, { + context: \\"Failed to execute 'append' on 'URLSearchParams': parameter 1\\" + }); + args.push(curArg); + } + { + let curArg = arguments[1]; + curArg = conversions[\\"USVString\\"](curArg, { + context: \\"Failed to execute 'append' on 'URLSearchParams': parameter 2\\" + }); + args.push(curArg); + } + return this[impl].append(...args); + } - keys() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - return module.exports.createDefaultIterator(this, \\"key\\"); - } + delete(name) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - values() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - return module.exports.createDefaultIterator(this, \\"value\\"); - } + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'delete' on 'URLSearchParams': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions[\\"USVString\\"](curArg, { + context: \\"Failed to execute 'delete' on 'URLSearchParams': parameter 1\\" + }); + args.push(curArg); + } + return this[impl].delete(...args); + } - entries() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - return module.exports.createDefaultIterator(this, \\"key+value\\"); - } + get(name) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } - forEach(callback) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - if (arguments.length < 1) { - throw new TypeError(\\"Failed to execute 'forEach' on 'iterable': 1 argument required, \\" + \\"but only 0 present.\\"); - } - if (typeof callback !== \\"function\\") { - throw new TypeError( - \\"Failed to execute 'forEach' on 'iterable': The callback provided \\" + \\"as parameter 1 is not a function.\\" - ); - } - const thisArg = arguments[1]; - let pairs = Array.from(this[impl]); - let i = 0; - while (i < pairs.length) { - const [key, value] = pairs[i].map(utils.tryWrapperForImpl); - callback.call(thisArg, value, key, this); - pairs = Array.from(this[impl]); - i++; - } - } -} -Object.defineProperties(URLSearchParams.prototype, { - append: { enumerable: true }, - delete: { enumerable: true }, - get: { enumerable: true }, - getAll: { enumerable: true }, - has: { enumerable: true }, - set: { enumerable: true }, - sort: { enumerable: true }, - toString: { enumerable: true }, - keys: { enumerable: true }, - values: { enumerable: true }, - entries: { enumerable: true }, - forEach: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"URLSearchParams\\", configurable: true }, - [Symbol.iterator]: { value: URLSearchParams.prototype.entries, configurable: true, writable: true } -}); -const iface = { - // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` - // method into this array. It allows objects that directly implements *those* interfaces to be recognized as - // implementing this mixin interface. - _mixedIntoPredicates: [], - is(obj) { - if (obj) { - if (utils.hasOwn(obj, impl) && obj[impl] instanceof Impl.implementation) { - return true; + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'get' on 'URLSearchParams': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions[\\"USVString\\"](curArg, { + context: \\"Failed to execute 'get' on 'URLSearchParams': parameter 1\\" + }); + args.push(curArg); + } + return this[impl].get(...args); } - for (const isMixedInto of module.exports._mixedIntoPredicates) { - if (isMixedInto(obj)) { - return true; + + getAll(name) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'getAll' on 'URLSearchParams': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions[\\"USVString\\"](curArg, { + context: \\"Failed to execute 'getAll' on 'URLSearchParams': parameter 1\\" + }); + args.push(curArg); } + return utils.tryWrapperForImpl(this[impl].getAll(...args)); } - } - return false; - }, - isImpl(obj) { - if (obj) { - if (obj instanceof Impl.implementation) { - return true; + + has(name) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'has' on 'URLSearchParams': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions[\\"USVString\\"](curArg, { + context: \\"Failed to execute 'has' on 'URLSearchParams': parameter 1\\" + }); + args.push(curArg); + } + return this[impl].has(...args); + } + + set(name, value) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 2) { + throw new TypeError( + \\"Failed to execute 'set' on 'URLSearchParams': 2 arguments required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions[\\"USVString\\"](curArg, { + context: \\"Failed to execute 'set' on 'URLSearchParams': parameter 1\\" + }); + args.push(curArg); + } + { + let curArg = arguments[1]; + curArg = conversions[\\"USVString\\"](curArg, { + context: \\"Failed to execute 'set' on 'URLSearchParams': parameter 2\\" + }); + args.push(curArg); + } + return this[impl].set(...args); + } + + sort() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return this[impl].sort(); + } + + toString() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return this[impl].toString(); + } + + keys() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + return module.exports.createDefaultIterator(this, \\"key\\"); + } + + values() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + return module.exports.createDefaultIterator(this, \\"value\\"); } - const wrapper = utils.wrapperForImpl(obj); - for (const isMixedInto of module.exports._mixedIntoPredicates) { - if (isMixedInto(wrapper)) { - return true; + entries() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); } + return module.exports.createDefaultIterator(this, \\"key+value\\"); } - } - return false; - }, - convert(obj, { context = \\"The provided value\\" } = {}) { - if (module.exports.is(obj)) { - return utils.implForWrapper(obj); - } - throw new TypeError(\`\${context} is not of type 'URLSearchParams'.\`); - }, - createDefaultIterator(target, kind) { - const iterator = Object.create(IteratorPrototype); - Object.defineProperty(iterator, utils.iterInternalSymbol, { - value: { target, kind, index: 0 }, - configurable: true + forEach(callback) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'forEach' on 'iterable': 1 argument required, \\" + \\"but only 0 present.\\" + ); + } + if (typeof callback !== \\"function\\") { + throw new TypeError( + \\"Failed to execute 'forEach' on 'iterable': The callback provided \\" + \\"as parameter 1 is not a function.\\" + ); + } + const thisArg = arguments[1]; + let pairs = Array.from(this[impl]); + let i = 0; + while (i < pairs.length) { + const [key, value] = pairs[i].map(utils.tryWrapperForImpl); + callback.call(thisArg, value, key, this); + pairs = Array.from(this[impl]); + i++; + } + } + } + Object.defineProperties(URLSearchParams.prototype, { + append: { enumerable: true }, + delete: { enumerable: true }, + get: { enumerable: true }, + getAll: { enumerable: true }, + has: { enumerable: true }, + set: { enumerable: true }, + sort: { enumerable: true }, + toString: { enumerable: true }, + keys: { enumerable: true }, + values: { enumerable: true }, + entries: { enumerable: true }, + forEach: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"URLSearchParams\\", configurable: true }, + [Symbol.iterator]: { value: URLSearchParams.prototype.entries, configurable: true, writable: true } }); - return iterator; - }, - - create(constructorArgs, privateData) { - let obj = Object.create(URLSearchParams.prototype); - obj = this.setup(obj, constructorArgs, privateData); - return obj; - }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(URLSearchParams.prototype); - obj = this.setup(obj, constructorArgs, privateData); - return utils.implForWrapper(obj); - }, - _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - - privateData.wrapper = obj; + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"URLSearchParams\\"] = URLSearchParams; - this._internalSetup(obj); - Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), - configurable: true + Object.defineProperty(globalObject, \\"URLSearchParams\\", { + configurable: true, + writable: true, + value: URLSearchParams }); - - obj[impl][utils.wrapperSymbol] = obj; - if (Impl.init) { - Impl.init(obj[impl], privateData); - } - return obj; - }, - interface: URLSearchParams, - expose: { - Window: { URLSearchParams }, - Worker: { URLSearchParams } } }; // iface module.exports = iface; @@ -4753,73 +4987,8 @@ const conversions = require(\\"webidl-conversions\\"); const utils = require(\\"./utils.js\\"); const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; -class URLSearchParamsCollection { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } - - item(index) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'item' on 'URLSearchParamsCollection': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - curArg = conversions[\\"unsigned long\\"](curArg, { - context: \\"Failed to execute 'item' on 'URLSearchParamsCollection': parameter 1\\" - }); - args.push(curArg); - } - return utils.tryWrapperForImpl(this[impl].item(...args)); - } - - namedItem(name) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'namedItem' on 'URLSearchParamsCollection': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'namedItem' on 'URLSearchParamsCollection': parameter 1\\" - }); - args.push(curArg); - } - return utils.tryWrapperForImpl(this[impl].namedItem(...args)); - } - - get length() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - return this[impl][\\"length\\"]; - } -} -Object.defineProperties(URLSearchParamsCollection.prototype, { - item: { enumerable: true }, - namedItem: { enumerable: true }, - length: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"URLSearchParamsCollection\\", configurable: true }, - [Symbol.iterator]: { value: Array.prototype[Symbol.iterator], configurable: true, writable: true } -}); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -4860,25 +5029,33 @@ const iface = { throw new TypeError(\`\${context} is not of type 'URLSearchParamsCollection'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(URLSearchParamsCollection.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"URLSearchParamsCollection\\"]; + if (ctor === undefined) { + throw new Error( + \\"Internal error: constructor URLSearchParamsCollection is not installed on the passed global object\\" + ); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(URLSearchParamsCollection.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -5074,9 +5251,84 @@ const iface = { } return obj; }, - interface: URLSearchParamsCollection, - expose: { - Window: { URLSearchParamsCollection } + + install(globalObject) { + class URLSearchParamsCollection { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } + + item(index) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'item' on 'URLSearchParamsCollection': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions[\\"unsigned long\\"](curArg, { + context: \\"Failed to execute 'item' on 'URLSearchParamsCollection': parameter 1\\" + }); + args.push(curArg); + } + return utils.tryWrapperForImpl(this[impl].item(...args)); + } + + namedItem(name) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'namedItem' on 'URLSearchParamsCollection': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'namedItem' on 'URLSearchParamsCollection': parameter 1\\" + }); + args.push(curArg); + } + return utils.tryWrapperForImpl(this[impl].namedItem(...args)); + } + + get length() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return this[impl][\\"length\\"]; + } + } + Object.defineProperties(URLSearchParamsCollection.prototype, { + item: { enumerable: true }, + namedItem: { enumerable: true }, + length: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"URLSearchParamsCollection\\", configurable: true }, + [Symbol.iterator]: { value: Array.prototype[Symbol.iterator], configurable: true, writable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"URLSearchParamsCollection\\"] = URLSearchParamsCollection; + + Object.defineProperty(globalObject, \\"URLSearchParamsCollection\\", { + configurable: true, + writable: true, + value: URLSearchParamsCollection + }); } }; // iface module.exports = iface; @@ -5093,17 +5345,9 @@ const utils = require(\\"./utils.js\\"); const convertURL = require(\\"./URL.js\\").convert; const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; const URLSearchParamsCollection = require(\\"./URLSearchParamsCollection.js\\"); -class URLSearchParamsCollection2 extends URLSearchParamsCollection.interface { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } -} -Object.defineProperties(URLSearchParamsCollection2.prototype, { - [Symbol.toStringTag]: { value: \\"URLSearchParamsCollection2\\", configurable: true }, - [Symbol.iterator]: { value: Array.prototype[Symbol.iterator], configurable: true, writable: true } -}); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -5144,27 +5388,35 @@ const iface = { throw new TypeError(\`\${context} is not of type 'URLSearchParamsCollection2'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(URLSearchParamsCollection2.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"URLSearchParamsCollection2\\"]; + if (ctor === undefined) { + throw new Error( + \\"Internal error: constructor URLSearchParamsCollection2 is not installed on the passed global object\\" + ); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(URLSearchParamsCollection2.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) { URLSearchParamsCollection._internalSetup(obj); }, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -5389,9 +5641,32 @@ const iface = { } return obj; }, - interface: URLSearchParamsCollection2, - expose: { - Window: { URLSearchParamsCollection2 } + + install(globalObject) { + if (globalObject.URLSearchParamsCollection === undefined) { + throw new Error( + \\"Internal error: attempting to evaluate URLSearchParamsCollection2 before URLSearchParamsCollection\\" + ); + } + class URLSearchParamsCollection2 extends globalObject.URLSearchParamsCollection { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } + } + Object.defineProperties(URLSearchParamsCollection2.prototype, { + [Symbol.toStringTag]: { value: \\"URLSearchParamsCollection2\\", configurable: true }, + [Symbol.iterator]: { value: Array.prototype[Symbol.iterator], configurable: true, writable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"URLSearchParamsCollection2\\"] = URLSearchParamsCollection2; + + Object.defineProperty(globalObject, \\"URLSearchParamsCollection2\\", { + configurable: true, + writable: true, + value: URLSearchParamsCollection2 + }); } }; // iface module.exports = iface; @@ -5407,97 +5682,8 @@ const conversions = require(\\"webidl-conversions\\"); const utils = require(\\"./utils.js\\"); const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; -class UnderscoredProperties { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } - - operation(sequence) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'operation' on 'UnderscoredProperties': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - if (!utils.isObject(curArg)) { - throw new TypeError( - \\"Failed to execute 'operation' on 'UnderscoredProperties': parameter 1\\" + \\" is not an iterable object.\\" - ); - } else { - const V = []; - const tmp = curArg; - for (let nextItem of tmp) { - nextItem = conversions[\\"DOMString\\"](nextItem, { - context: \\"Failed to execute 'operation' on 'UnderscoredProperties': parameter 1\\" + \\"'s element\\" - }); - - V.push(nextItem); - } - curArg = V; - } - args.push(curArg); - } - return this[impl].operation(...args); - } - - get attribute() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - return this[impl][\\"attribute\\"]; - } - - set attribute(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - V = conversions[\\"byte\\"](V, { - context: \\"Failed to set the 'attribute' property on 'UnderscoredProperties': The provided value\\" - }); - - this[impl][\\"attribute\\"] = V; - } - - static static(void_) { - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'static' on 'UnderscoredProperties': 1 argument required, but only \\" + - arguments.length + - \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'static' on 'UnderscoredProperties': parameter 1\\" - }); - args.push(curArg); - } - return Impl.implementation.static(...args); - } -} -Object.defineProperties(UnderscoredProperties.prototype, { - operation: { enumerable: true }, - attribute: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"UnderscoredProperties\\", configurable: true }, - const: { value: 42, enumerable: true } -}); -Object.defineProperties(UnderscoredProperties, { - static: { enumerable: true }, - const: { value: 42, enumerable: true } -}); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -5538,25 +5724,31 @@ const iface = { throw new TypeError(\`\${context} is not of type 'UnderscoredProperties'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(UnderscoredProperties.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"UnderscoredProperties\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor UnderscoredProperties is not installed on the passed global object\\"); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(UnderscoredProperties.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -5566,9 +5758,108 @@ const iface = { } return obj; }, - interface: UnderscoredProperties, - expose: { - Window: { UnderscoredProperties } + + install(globalObject) { + class UnderscoredProperties { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } + + operation(sequence) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'operation' on 'UnderscoredProperties': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + if (!utils.isObject(curArg)) { + throw new TypeError( + \\"Failed to execute 'operation' on 'UnderscoredProperties': parameter 1\\" + \\" is not an iterable object.\\" + ); + } else { + const V = []; + const tmp = curArg; + for (let nextItem of tmp) { + nextItem = conversions[\\"DOMString\\"](nextItem, { + context: \\"Failed to execute 'operation' on 'UnderscoredProperties': parameter 1\\" + \\"'s element\\" + }); + + V.push(nextItem); + } + curArg = V; + } + args.push(curArg); + } + return this[impl].operation(...args); + } + + get attribute() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return this[impl][\\"attribute\\"]; + } + + set attribute(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + V = conversions[\\"byte\\"](V, { + context: \\"Failed to set the 'attribute' property on 'UnderscoredProperties': The provided value\\" + }); + + this[impl][\\"attribute\\"] = V; + } + + static static(void_) { + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'static' on 'UnderscoredProperties': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'static' on 'UnderscoredProperties': parameter 1\\" + }); + args.push(curArg); + } + return Impl.implementation.static(...args); + } + } + Object.defineProperties(UnderscoredProperties.prototype, { + operation: { enumerable: true }, + attribute: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"UnderscoredProperties\\", configurable: true }, + const: { value: 42, enumerable: true } + }); + Object.defineProperties(UnderscoredProperties, { + static: { enumerable: true }, + const: { value: 42, enumerable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"UnderscoredProperties\\"] = UnderscoredProperties; + + Object.defineProperty(globalObject, \\"UnderscoredProperties\\", { + configurable: true, + writable: true, + value: UnderscoredProperties + }); } }; // iface module.exports = iface; @@ -5584,13 +5875,8 @@ const conversions = require(\\"webidl-conversions\\"); const utils = require(\\"./utils.js\\"); const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; -class Unforgeable { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } -} -Object.defineProperties(Unforgeable.prototype, { [Symbol.toStringTag]: { value: \\"Unforgeable\\", configurable: true } }); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -5631,14 +5917,22 @@ const iface = { throw new TypeError(\`\${context} is not of type 'Unforgeable'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(Unforgeable.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"Unforgeable\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor Unforgeable is not installed on the passed global object\\"); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(Unforgeable.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) { @@ -5727,14 +6021,12 @@ const iface = { protocol: { configurable: false } }); }, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -5744,9 +6036,26 @@ const iface = { } return obj; }, - interface: Unforgeable, - expose: { - Window: { Unforgeable } + + install(globalObject) { + class Unforgeable { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } + } + Object.defineProperties(Unforgeable.prototype, { + [Symbol.toStringTag]: { value: \\"Unforgeable\\", configurable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"Unforgeable\\"] = Unforgeable; + + Object.defineProperty(globalObject, \\"Unforgeable\\", { + configurable: true, + writable: true, + value: Unforgeable + }); } }; // iface module.exports = iface; @@ -5762,15 +6071,8 @@ const conversions = require(\\"webidl-conversions\\"); const utils = require(\\"./utils.js\\"); const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; -class UnforgeableMap { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } -} -Object.defineProperties(UnforgeableMap.prototype, { - [Symbol.toStringTag]: { value: \\"UnforgeableMap\\", configurable: true } -}); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -5811,14 +6113,22 @@ const iface = { throw new TypeError(\`\${context} is not of type 'UnforgeableMap'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(UnforgeableMap.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"UnforgeableMap\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor UnforgeableMap is not installed on the passed global object\\"); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(UnforgeableMap.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) { @@ -5837,14 +6147,12 @@ const iface = { Object.defineProperties(obj, { a: { configurable: false } }); }, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -6029,9 +6337,26 @@ const iface = { } return obj; }, - interface: UnforgeableMap, - expose: { - Window: { UnforgeableMap } + + install(globalObject) { + class UnforgeableMap { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } + } + Object.defineProperties(UnforgeableMap.prototype, { + [Symbol.toStringTag]: { value: \\"UnforgeableMap\\", configurable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"UnforgeableMap\\"] = UnforgeableMap; + + Object.defineProperty(globalObject, \\"UnforgeableMap\\", { + configurable: true, + writable: true, + value: UnforgeableMap + }); } }; // iface module.exports = iface; @@ -6047,58 +6372,8 @@ const conversions = require(\\"webidl-conversions\\"); const utils = require(\\"./utils.js\\"); const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; -class Unscopable { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } - - get unscopableTest() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - return this[impl][\\"unscopableTest\\"]; - } - - set unscopableTest(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - V = conversions[\\"boolean\\"](V, { - context: \\"Failed to set the 'unscopableTest' property on 'Unscopable': The provided value\\" - }); - - this[impl][\\"unscopableTest\\"] = V; - } - - get unscopableMixin() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - return this[impl][\\"unscopableMixin\\"]; - } - - set unscopableMixin(V) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - V = conversions[\\"boolean\\"](V, { - context: \\"Failed to set the 'unscopableMixin' property on 'Unscopable': The provided value\\" - }); - - this[impl][\\"unscopableMixin\\"] = V; - } -} -Object.defineProperties(Unscopable.prototype, { - unscopableTest: { enumerable: true }, - unscopableMixin: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"Unscopable\\", configurable: true }, - [Symbol.unscopables]: { value: { unscopableTest: true, unscopableMixin: true, __proto__: null }, configurable: true } -}); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -6139,25 +6414,31 @@ const iface = { throw new TypeError(\`\${context} is not of type 'Unscopable'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(Unscopable.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"Unscopable\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor Unscopable is not installed on the passed global object\\"); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(Unscopable.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -6167,9 +6448,72 @@ const iface = { } return obj; }, - interface: Unscopable, - expose: { - Window: { Unscopable } + + install(globalObject) { + class Unscopable { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } + + get unscopableTest() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return this[impl][\\"unscopableTest\\"]; + } + + set unscopableTest(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + V = conversions[\\"boolean\\"](V, { + context: \\"Failed to set the 'unscopableTest' property on 'Unscopable': The provided value\\" + }); + + this[impl][\\"unscopableTest\\"] = V; + } + + get unscopableMixin() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return this[impl][\\"unscopableMixin\\"]; + } + + set unscopableMixin(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + V = conversions[\\"boolean\\"](V, { + context: \\"Failed to set the 'unscopableMixin' property on 'Unscopable': The provided value\\" + }); + + this[impl][\\"unscopableMixin\\"] = V; + } + } + Object.defineProperties(Unscopable.prototype, { + unscopableTest: { enumerable: true }, + unscopableMixin: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"Unscopable\\", configurable: true }, + [Symbol.unscopables]: { + value: { unscopableTest: true, unscopableMixin: true, __proto__: null }, + configurable: true + } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"Unscopable\\"] = Unscopable; + + Object.defineProperty(globalObject, \\"Unscopable\\", { + configurable: true, + writable: true, + value: Unscopable + }); } }; // iface module.exports = iface; @@ -6186,162 +6530,8 @@ const utils = require(\\"./utils.js\\"); const convertURL = require(\\"./URL.js\\").convert; const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; -class Variadic { - constructor() { - throw new TypeError(\\"Illegal constructor\\"); - } - - simple1() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - const args = []; - for (let i = 0; i < arguments.length; i++) { - let curArg = arguments[i]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'simple1' on 'Variadic': parameter \\" + (i + 1) - }); - args.push(curArg); - } - return this[impl].simple1(...args); - } - - simple2(first) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'simple2' on 'Variadic': 1 argument required, but only \\" + arguments.length + \\" present.\\" - ); - } - const args = []; - { - let curArg = arguments[0]; - curArg = conversions[\\"DOMString\\"](curArg, { context: \\"Failed to execute 'simple2' on 'Variadic': parameter 1\\" }); - args.push(curArg); - } - for (let i = 1; i < arguments.length; i++) { - let curArg = arguments[i]; - curArg = convertURL(curArg, { context: \\"Failed to execute 'simple2' on 'Variadic': parameter \\" + (i + 1) }); - args.push(curArg); - } - return this[impl].simple2(...args); - } - - overloaded1() { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - const args = []; - switch (arguments.length) { - case 0: - break; - default: { - let curArg = arguments[0]; - if (typeof curArg === \\"number\\") { - for (let i = 0; i < arguments.length; i++) { - let curArg = arguments[i]; - curArg = conversions[\\"unsigned long\\"](curArg, { - context: \\"Failed to execute 'overloaded1' on 'Variadic': parameter \\" + (i + 1) - }); - args.push(curArg); - } - } else { - for (let i = 0; i < arguments.length; i++) { - let curArg = arguments[i]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'overloaded1' on 'Variadic': parameter \\" + (i + 1) - }); - args.push(curArg); - } - } - } - } - return this[impl].overloaded1(...args); - } - - overloaded2(first) { - if (!this || !module.exports.is(this)) { - throw new TypeError(\\"Illegal invocation\\"); - } - - if (arguments.length < 1) { - throw new TypeError( - \\"Failed to execute 'overloaded2' on 'Variadic': 1 argument required, but only \\" + arguments.length + \\" present.\\" - ); - } - const args = []; - switch (arguments.length) { - case 1: - { - let curArg = arguments[0]; - if (typeof curArg === \\"number\\") { - { - let curArg = arguments[0]; - curArg = conversions[\\"unsigned long\\"](curArg, { - context: \\"Failed to execute 'overloaded2' on 'Variadic': parameter 1\\" - }); - args.push(curArg); - } - } else { - { - let curArg = arguments[0]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'overloaded2' on 'Variadic': parameter 1\\" - }); - args.push(curArg); - } - } - } - break; - default: { - let curArg = arguments[0]; - if (typeof curArg === \\"number\\") { - { - let curArg = arguments[0]; - curArg = conversions[\\"unsigned long\\"](curArg, { - context: \\"Failed to execute 'overloaded2' on 'Variadic': parameter 1\\" - }); - args.push(curArg); - } - for (let i = 1; i < arguments.length; i++) { - let curArg = arguments[i]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'overloaded2' on 'Variadic': parameter \\" + (i + 1) - }); - args.push(curArg); - } - } else { - { - let curArg = arguments[0]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'overloaded2' on 'Variadic': parameter 1\\" - }); - args.push(curArg); - } - for (let i = 1; i < arguments.length; i++) { - let curArg = arguments[i]; - curArg = conversions[\\"DOMString\\"](curArg, { - context: \\"Failed to execute 'overloaded2' on 'Variadic': parameter \\" + (i + 1) - }); - args.push(curArg); - } - } - } - } - return this[impl].overloaded2(...args); - } -} -Object.defineProperties(Variadic.prototype, { - simple1: { enumerable: true }, - simple2: { enumerable: true }, - overloaded1: { enumerable: true }, - overloaded2: { enumerable: true }, - [Symbol.toStringTag]: { value: \\"Variadic\\", configurable: true } -}); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -6382,25 +6572,31 @@ const iface = { throw new TypeError(\`\${context} is not of type 'Variadic'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(Variadic.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"Variadic\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor Variadic is not installed on the passed global object\\"); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(Variadic.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -6410,9 +6606,177 @@ const iface = { } return obj; }, - interface: Variadic, - expose: { - Window: { Variadic } + + install(globalObject) { + class Variadic { + constructor() { + throw new TypeError(\\"Illegal constructor\\"); + } + + simple1() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + const args = []; + for (let i = 0; i < arguments.length; i++) { + let curArg = arguments[i]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'simple1' on 'Variadic': parameter \\" + (i + 1) + }); + args.push(curArg); + } + return this[impl].simple1(...args); + } + + simple2(first) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'simple2' on 'Variadic': 1 argument required, but only \\" + arguments.length + \\" present.\\" + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'simple2' on 'Variadic': parameter 1\\" + }); + args.push(curArg); + } + for (let i = 1; i < arguments.length; i++) { + let curArg = arguments[i]; + curArg = convertURL(curArg, { context: \\"Failed to execute 'simple2' on 'Variadic': parameter \\" + (i + 1) }); + args.push(curArg); + } + return this[impl].simple2(...args); + } + + overloaded1() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + const args = []; + switch (arguments.length) { + case 0: + break; + default: { + let curArg = arguments[0]; + if (typeof curArg === \\"number\\") { + for (let i = 0; i < arguments.length; i++) { + let curArg = arguments[i]; + curArg = conversions[\\"unsigned long\\"](curArg, { + context: \\"Failed to execute 'overloaded1' on 'Variadic': parameter \\" + (i + 1) + }); + args.push(curArg); + } + } else { + for (let i = 0; i < arguments.length; i++) { + let curArg = arguments[i]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'overloaded1' on 'Variadic': parameter \\" + (i + 1) + }); + args.push(curArg); + } + } + } + } + return this[impl].overloaded1(...args); + } + + overloaded2(first) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + if (arguments.length < 1) { + throw new TypeError( + \\"Failed to execute 'overloaded2' on 'Variadic': 1 argument required, but only \\" + + arguments.length + + \\" present.\\" + ); + } + const args = []; + switch (arguments.length) { + case 1: + { + let curArg = arguments[0]; + if (typeof curArg === \\"number\\") { + { + let curArg = arguments[0]; + curArg = conversions[\\"unsigned long\\"](curArg, { + context: \\"Failed to execute 'overloaded2' on 'Variadic': parameter 1\\" + }); + args.push(curArg); + } + } else { + { + let curArg = arguments[0]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'overloaded2' on 'Variadic': parameter 1\\" + }); + args.push(curArg); + } + } + } + break; + default: { + let curArg = arguments[0]; + if (typeof curArg === \\"number\\") { + { + let curArg = arguments[0]; + curArg = conversions[\\"unsigned long\\"](curArg, { + context: \\"Failed to execute 'overloaded2' on 'Variadic': parameter 1\\" + }); + args.push(curArg); + } + for (let i = 1; i < arguments.length; i++) { + let curArg = arguments[i]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'overloaded2' on 'Variadic': parameter \\" + (i + 1) + }); + args.push(curArg); + } + } else { + { + let curArg = arguments[0]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'overloaded2' on 'Variadic': parameter 1\\" + }); + args.push(curArg); + } + for (let i = 1; i < arguments.length; i++) { + let curArg = arguments[i]; + curArg = conversions[\\"DOMString\\"](curArg, { + context: \\"Failed to execute 'overloaded2' on 'Variadic': parameter \\" + (i + 1) + }); + args.push(curArg); + } + } + } + } + return this[impl].overloaded2(...args); + } + } + Object.defineProperties(Variadic.prototype, { + simple1: { enumerable: true }, + simple2: { enumerable: true }, + overloaded1: { enumerable: true }, + overloaded2: { enumerable: true }, + [Symbol.toStringTag]: { value: \\"Variadic\\", configurable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"Variadic\\"] = Variadic; + + Object.defineProperty(globalObject, \\"Variadic\\", { + configurable: true, + writable: true, + value: Variadic + }); } }; // iface module.exports = iface; @@ -6428,15 +6792,8 @@ const conversions = require(\\"webidl-conversions\\"); const utils = require(\\"./utils.js\\"); const impl = utils.implSymbol; +const ctorRegistry = utils.ctorRegistrySymbol; -class ZeroArgConstructor { - constructor() { - return iface.setup(Object.create(new.target.prototype)); - } -} -Object.defineProperties(ZeroArgConstructor.prototype, { - [Symbol.toStringTag]: { value: \\"ZeroArgConstructor\\", configurable: true } -}); const iface = { // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` // method into this array. It allows objects that directly implements *those* interfaces to be recognized as @@ -6477,25 +6834,31 @@ const iface = { throw new TypeError(\`\${context} is not of type 'ZeroArgConstructor'.\`); }, - create(constructorArgs, privateData) { - let obj = Object.create(ZeroArgConstructor.prototype); - obj = this.setup(obj, constructorArgs, privateData); + create(globalObject, constructorArgs, privateData) { + if (globalObject[ctorRegistry] === undefined) { + throw new Error(\\"Internal error: invalid global object\\"); + } + + const ctor = globalObject[ctorRegistry][\\"ZeroArgConstructor\\"]; + if (ctor === undefined) { + throw new Error(\\"Internal error: constructor ZeroArgConstructor is not installed on the passed global object\\"); + } + + let obj = Object.create(ctor.prototype); + obj = iface.setup(obj, globalObject, constructorArgs, privateData); return obj; }, - createImpl(constructorArgs, privateData) { - let obj = Object.create(ZeroArgConstructor.prototype); - obj = this.setup(obj, constructorArgs, privateData); + createImpl(globalObject, constructorArgs, privateData) { + const obj = iface.create(globalObject, constructorArgs, privateData); return utils.implForWrapper(obj); }, _internalSetup(obj) {}, - setup(obj, constructorArgs, privateData) { - if (!privateData) privateData = {}; - + setup(obj, globalObject, constructorArgs = [], privateData = {}) { privateData.wrapper = obj; - this._internalSetup(obj); + iface._internalSetup(obj); Object.defineProperty(obj, impl, { - value: new Impl.implementation(constructorArgs, privateData), + value: new Impl.implementation(globalObject, constructorArgs, privateData), configurable: true }); @@ -6505,9 +6868,26 @@ const iface = { } return obj; }, - interface: ZeroArgConstructor, - expose: { - Window: { ZeroArgConstructor } + + install(globalObject) { + class ZeroArgConstructor { + constructor() { + return iface.setup(Object.create(new.target.prototype), globalObject, undefined); + } + } + Object.defineProperties(ZeroArgConstructor.prototype, { + [Symbol.toStringTag]: { value: \\"ZeroArgConstructor\\", configurable: true } + }); + if (globalObject[ctorRegistry] === undefined) { + globalObject[ctorRegistry] = Object.create(null); + } + globalObject[ctorRegistry][\\"ZeroArgConstructor\\"] = ZeroArgConstructor; + + Object.defineProperty(globalObject, \\"ZeroArgConstructor\\", { + configurable: true, + writable: true, + value: ZeroArgConstructor + }); } }; // iface module.exports = iface; diff --git a/test/cases/Factory.webidl b/test/cases/Factory.webidl deleted file mode 100644 index 3fae11b5..00000000 --- a/test/cases/Factory.webidl +++ /dev/null @@ -1,6 +0,0 @@ -[WebIDL2JSFactory,Exposed=Window] -interface Factory { - DOMString method(); - attribute double _attribute; - const unsigned short constant = 42; -};