diff --git a/lib/context.js b/lib/context.js index facd25ae..09a1004e 100644 --- a/lib/context.js +++ b/lib/context.js @@ -8,6 +8,7 @@ const builtinTypes = webidl.parse(` Uint8Array or Uint16Array or Uint32Array or Uint8ClampedArray or Float32Array or Float64Array or DataView) ArrayBufferView; typedef (ArrayBufferView or ArrayBuffer) BufferSource; + typedef (ArrayBuffer or SharedArrayBuffer or [AllowShared] ArrayBufferView) AllowSharedBufferSource; typedef unsigned long long DOMTimeStamp; callback Function = any (any... arguments); diff --git a/lib/output/utils.js b/lib/output/utils.js index fafd6a71..5e509791 100644 --- a/lib/output/utils.js +++ b/lib/output/utils.js @@ -110,11 +110,22 @@ function isArrayIndexPropName(P) { return true; } -const byteLengthGetter = +const arrayBufferByteLengthGetter = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get; function isArrayBuffer(value) { try { - byteLengthGetter.call(value); + arrayBufferByteLengthGetter.call(value); + return true; + } catch { + return false; + } +} + +const sharedArrayBufferByteLengthGetter = + Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, "byteLength").get; +function isSharedArrayBuffer(value) { + try { + sharedArrayBufferByteLengthGetter.call(value); return true; } catch { return false; @@ -219,6 +230,7 @@ module.exports = exports = { tryImplForWrapper, iterInternalSymbol, isArrayBuffer, + isSharedArrayBuffer, isArrayIndexPropName, supportsPropertyIndex, supportedPropertyIndices, diff --git a/lib/parameters.js b/lib/parameters.js index ca525259..0df2ebfc 100644 --- a/lib/parameters.js +++ b/lib/parameters.js @@ -205,6 +205,17 @@ module.exports.generateOverloadConversions = function (ctx, typeOfOp, name, pare `); } + const sharedArrayBuffers = S.filter(o => { + return isOrIncludes(ctx, o.typeList[d], t => t.idlType === "SharedArrayBuffer"); + }); + if (sharedArrayBuffers.length) { + possibilities.push(` + if (utils.isSharedArrayBuffer(curArg)) { + ${continued(sharedArrayBuffers[0], i)} + } + `); + } + const arrayBufferViews = new Map(); for (const o of S) { const type = Types.resolveType(ctx, o.typeList[d]); diff --git a/lib/types.js b/lib/types.js index c5ea476e..f90b5edb 100644 --- a/lib/types.js +++ b/lib/types.js @@ -36,6 +36,16 @@ function mergeExtAttrs(a = [], b = []) { return [...a, ...b]; } +function mergeExtAttrsOfTypes(idlTypes) { + const extAttrs = []; + for (const idlType of idlTypes) { + if (idlType.extAttrs !== undefined) { + extAttrs.push(...idlType.extAttrs); + } + } + return extAttrs; +} + // Types of types that generate an output file. const resolvedTypes = new Set(["callback", "callback interface", "dictionary", "enumeration", "interface"]); @@ -142,7 +152,7 @@ function generateTypeConversion( generateFrozenArray(); } else if (conversions[idlType.idlType]) { // string or number type compatible with webidl-conversions - generateWebIDLConversions(`conversions["${idlType.idlType}"]`); + str += generateWebIDLConversions(`conversions["${idlType.idlType}"]`, extAttrs); } else if (resolvedTypes.has(ctx.typeOf(idlType.idlType))) { // callback functions, callback interfaces, dictionaries, enumerations, and interfaces let fn; @@ -192,9 +202,13 @@ function generateTypeConversion( } if (union.object) { - output.push(`if (utils.isObject(${name}) && ${name}[utils.implSymbol]) { - ${name} = utils.implForWrapper(${name}); - }`); + output.push(` + if (utils.isObject(${name})) { + if (${name}[utils.implSymbol]) { + ${name} = utils.implForWrapper(${name}); + } + } + `); } else if (union.interfaces.size > 0) { const exprs = [...union.interfaces].map(iface => { let fn; @@ -214,44 +228,53 @@ function generateTypeConversion( `); } - // Do not convert buffer source types as the impl code can either "get a reference" or "get a copy" to the bytes. - if (union.ArrayBuffer || union.object) { - output.push(`if (utils.isArrayBuffer(${name})) {}`); + if (union.ArrayBuffer) { + output.push(`if (utils.isArrayBuffer(${name})) { + ${generateTypeConversion(ctx, name, union.ArrayBuffer, [], parentName, errPrefix).body} + }`); + } + if (union.SharedArrayBuffer) { + output.push(`if (utils.isSharedArrayBuffer(${name})) { + ${generateTypeConversion(ctx, name, union.SharedArrayBuffer, [], parentName, errPrefix).body} + }`); } - if (union.ArrayBufferViews.size > 0 || union.object) { - let condition = `ArrayBuffer.isView(${name})`; + if (union.ArrayBufferViews.size > 0) { + const viewIdlTypes = new Set([...union.ArrayBufferViews].map(item => item.idlType)); // Skip specific type check if all ArrayBufferView member types are allowed. - if (union.ArrayBufferViews.size !== arrayBufferViewTypes.size) { - const exprs = [...union.ArrayBufferViews].map(a => `${name}.constructor.name === "${a}"`); - condition += ` && (${exprs.join(" || ")})`; + if (viewIdlTypes.size === arrayBufferViewTypes.size) { + const viewExtAttrs = mergeExtAttrsOfTypes(union.ArrayBufferViews); + // We can't call generateTypeConversion since that will just expand the union again and recurse back to here, + // so instead we call generateWebIDLConversions directly. + output.push(`if (ArrayBuffer.isView(${name})) { + ${generateWebIDLConversions(`conversions["ArrayBufferView"]`, viewExtAttrs)} + }`); + } else { + for (const viewType of union.ArrayBufferViews) { + output.push(`if (ArrayBuffer.isView(${name}) && ${name}.constructor.name === "${viewType.idlType}") { + ${generateTypeConversion(ctx, name, viewType, [], parentName, errPrefix).body} + }`); + } } - output.push(`if (${condition}) {}`); } - if (union.callbackFunction || union.object) { - let code = `if (typeof ${name} === "function") {`; - - if (union.callbackFunction) { - const conv = generateTypeConversion( - ctx, - name, - union.callbackFunction, - [], - parentName, - `${errPrefix} + " callback function"` - ); - requires.merge(conv.requires); - code += conv.body; - } else if (union.object) { - // noop - } - - code += "}"; - - output.push(code); + if (union.callbackFunction) { + const conv = generateTypeConversion( + ctx, + name, + union.callbackFunction, + [], + parentName, + `${errPrefix} + " callback function"` + ); + requires.merge(conv.requires); + output.push(` + if (typeof ${name} === "function") { + ${conv.body} + } + `); } - if (union.sequenceLike || union.dictionary || union.record || union.object || union.callbackInterface) { + if (union.sequenceLike || union.dictionary || union.record || union.callbackInterface) { let code = `if (utils.isObject(${name})) {`; if (union.sequenceLike) { @@ -295,8 +318,6 @@ function generateTypeConversion( ); requires.merge(conv.requires); code += conv.body; - } else if (union.object) { - // noop } if (union.sequenceLike) { @@ -417,10 +438,12 @@ function generateTypeConversion( str += `${name} = Object.freeze(${name});`; } - function generateWebIDLConversions(conversionFn) { - const enforceRange = utils.getExtAttr(extAttrs, "EnforceRange"); - const clamp = utils.getExtAttr(extAttrs, "Clamp"); - const nullToEmptyString = utils.getExtAttr(extAttrs, "LegacyNullToEmptyString"); + function generateWebIDLConversions(conversionFn, attrs) { + const enforceRange = utils.getExtAttr(attrs, "EnforceRange"); + const clamp = utils.getExtAttr(attrs, "Clamp"); + const nullToEmptyString = utils.getExtAttr(attrs, "LegacyNullToEmptyString"); + const allowResizable = utils.getExtAttr(attrs, "AllowResizable"); + const allowShared = utils.getExtAttr(attrs, "AllowShared"); let optString = `context: ${errPrefix}, globals: globalObject,`; if (clamp) { @@ -432,17 +455,22 @@ function generateTypeConversion( if (nullToEmptyString) { optString += "treatNullAsEmptyString: true,"; } + if (allowResizable) { + optString += "allowResizable: true,"; + } + if (allowShared) { + optString += "allowShared: true,"; + } if (idlType.array) { - str += ` + return ` for (let i = 0; i < ${name}.length; ++i) { ${name}[i] = ${conversionFn}(${name}[i], { ${optString} }); } `; - } else { - str += ` - ${name} = ${conversionFn}(${name}, { ${optString} }); - `; } + return ` + ${name} = ${conversionFn}(${name}, { ${optString} }); + `; } function generateWebIDL2JS(conversionFn) { @@ -472,10 +500,11 @@ function extractUnionInfo(ctx, idlType, errPrefix) { get dictionaryLike() { return this.dictionary !== null || this.record !== null || this.callbackInterface !== null; }, - ArrayBuffer: false, + ArrayBuffer: null, + SharedArrayBuffer: null, ArrayBufferViews: new Set(), get BufferSource() { - return this.ArrayBuffer || this.ArrayBufferViews.size > 0; + return this.ArrayBuffer || this.SharedArrayBuffer || this.ArrayBufferViews.size > 0; }, object: false, string: null, @@ -517,12 +546,17 @@ function extractUnionInfo(ctx, idlType, errPrefix) { if (seen.object) { error("ArrayBuffer is not distinguishable with object type"); } - seen.ArrayBuffer = true; + seen.ArrayBuffer = item; + } else if (item.idlType === "SharedArrayBuffer") { + if (seen.object) { + error("SharedArrayBuffer is not distinguishable with object type"); + } + seen.SharedArrayBuffer = item; } else if (arrayBufferViewTypes.has(item.idlType)) { if (seen.object) { error(`${item.idlType} is not distinguishable with object type`); } - seen.ArrayBufferViews.add(item.idlType); + seen.ArrayBufferViews.add(item); } else if (stringTypes.has(item.idlType) || ctx.enumerations.has(item.idlType)) { if (seen.string) { error("There can only be one string type in a union type"); @@ -556,7 +590,7 @@ function extractUnionInfo(ctx, idlType, errPrefix) { if (seen.dictionaryLike) { error("Callback functions are not distinguishable with dictionary-like types"); } - seen.callbackFunction = item.idlType; + seen.callbackFunction = item; } else if (ctx.dictionaries.has(item.idlType)) { if (seen.object) { error("Dictionary-like types are not distinguishable with object type"); @@ -578,7 +612,7 @@ function extractUnionInfo(ctx, idlType, errPrefix) { if (seen.dictionaryLike) { error("There can only be one dictionary-like type in a union type"); } - seen.callbackInterface = item.idlType; + seen.callbackInterface = item; } else if (ctx.interfaces.has(item.idlType)) { if (seen.object) { error("Interface types are not distinguishable with object type"); @@ -664,21 +698,29 @@ function sameType(ctx, type1, type2) { const extracted2 = extractUnionInfo(ctx, type2, `""`); return sameType(ctx, extracted1.sequenceLike, extracted2.sequenceLike) && sameType(ctx, extracted1.record, extracted2.record) && - extracted1.ArrayBuffer !== extracted2.ArrayBuffer && - JSON.stringify([...extracted1.ArrayBufferViews].sort()) === - JSON.stringify([...extracted2.ArrayBufferViews].sort()) && + sameType(ctx, extracted1.ArrayBuffer, extracted2.ArrayBuffer) && + sameType(ctx, extracted1.SharedArrayBuffer, extracted2.SharedArrayBuffer) && + sameTypeArray(ctx, [...extracted1.ArrayBufferViews].sort(), [...extracted2.ArrayBufferViews].sort()) && extracted1.object === extracted2.object && sameType(ctx, extracted1.string, extracted2.string) && sameType(ctx, extracted1.numeric, extracted2.numeric) && sameType(ctx, extracted1.boolean, extracted2.boolean) && extracted1.callback === extracted2.callback && + sameType(ctx, extracted1.callbackFunction, extracted2.callbackFunction) && sameType(ctx, extracted1.dictionary, extracted2.dictionary) && - JSON.stringify([...extracted1.interfaces].sort()) === - JSON.stringify([...extracted2.interfaces].sort()) && - extracted1.callbackInterface === extracted2.callbackInterface && + sameArray([...extracted1.interfaces].sort(), [...extracted2.interfaces].sort()) && + sameType(ctx, extracted1.callbackInterface, extracted2.callbackInterface) && extracted1.unknown === extracted2.unknown; } +function sameTypeArray(ctx, types1, types2) { + return sameArray(types1, types2, (type1, type2) => sameType(ctx, type1, type2)); +} + +function sameArray(array1, array2, comparator = (x, y) => x === y) { + return array1.length === array2.length && array1.every((element1, index) => comparator(element1, array2[index])); +} + function areDistinguishable(ctx, type1, type2) { const resolved1 = resolveType(ctx, type1); const resolved2 = resolveType(ctx, type2); diff --git a/test/__snapshots__/test.js.snap b/test/__snapshots__/test.js.snap index 1c707a65..4362fead 100644 --- a/test/__snapshots__/test.js.snap +++ b/test/__snapshots__/test.js.snap @@ -1381,7 +1381,15 @@ exports.install = (globalObject, globalNames) => { { let curArg = arguments[0]; if (utils.isArrayBuffer(curArg)) { + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'bs' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); } else if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'bs' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); } else { throw new globalObject.TypeError( "Failed to execute 'bs' on 'BufferSourceTypes': parameter 1" + " is not of any supported type." @@ -1415,6 +1423,31 @@ exports.install = (globalObject, globalNames) => { return esValue[implSymbol].ab(...args); } + sab(sab) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'sab' called on an object that is not a valid instance of BufferSourceTypes." + ); + } + + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'sab' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions["SharedArrayBuffer"](curArg, { + context: "Failed to execute 'sab' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); + args.push(curArg); + } + return esValue[implSymbol].sab(...args); + } + abv(abv) { const esValue = this !== null && this !== undefined ? this : globalObject; if (!exports.is(esValue)) { @@ -1432,6 +1465,10 @@ exports.install = (globalObject, globalNames) => { { let curArg = arguments[0]; if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'abv' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); } else { throw new globalObject.TypeError( "Failed to execute 'abv' on 'BufferSourceTypes': parameter 1" + " is not of any supported type." @@ -1484,6 +1521,10 @@ exports.install = (globalObject, globalNames) => { { let curArg = arguments[0]; if (utils.isArrayBuffer(curArg)) { + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'abUnion' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); } else { curArg = conversions["DOMString"](curArg, { context: "Failed to execute 'abUnion' on 'BufferSourceTypes': parameter 1", @@ -1495,6 +1536,38 @@ exports.install = (globalObject, globalNames) => { return esValue[implSymbol].abUnion(...args); } + sabUnion(ab) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'sabUnion' called on an object that is not a valid instance of BufferSourceTypes." + ); + } + + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'sabUnion' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + if (utils.isSharedArrayBuffer(curArg)) { + curArg = conversions["SharedArrayBuffer"](curArg, { + context: "Failed to execute 'sabUnion' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); + } else { + curArg = conversions["DOMString"](curArg, { + context: "Failed to execute 'sabUnion' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); + } + args.push(curArg); + } + return esValue[implSymbol].sabUnion(...args); + } + u8aUnion(ab) { const esValue = this !== null && this !== undefined ? this : globalObject; if (!exports.is(esValue)) { @@ -1512,6 +1585,10 @@ exports.install = (globalObject, globalNames) => { { let curArg = arguments[0]; if (ArrayBuffer.isView(curArg) && curArg.constructor.name === "Uint8Array") { + curArg = conversions["Uint8Array"](curArg, { + context: "Failed to execute 'u8aUnion' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); } else { curArg = conversions["DOMString"](curArg, { context: "Failed to execute 'u8aUnion' on 'BufferSourceTypes': parameter 1", @@ -1522,515 +1599,410 @@ exports.install = (globalObject, globalNames) => { } return esValue[implSymbol].u8aUnion(...args); } - } - Object.defineProperties(BufferSourceTypes.prototype, { - bs: { enumerable: true }, - ab: { enumerable: true }, - abv: { enumerable: true }, - u8a: { enumerable: true }, - abUnion: { enumerable: true }, - u8aUnion: { enumerable: true }, - [Symbol.toStringTag]: { value: "BufferSourceTypes", configurable: true } - }); - ctorRegistry[interfaceName] = BufferSourceTypes; - - Object.defineProperty(globalObject, interfaceName, { - configurable: true, - writable: true, - value: BufferSourceTypes - }); -}; - -const Impl = require("../implementations/BufferSourceTypes.js"); -" -`; - -exports[`generation with processors CEReactions.webidl 1`] = ` -""use strict"; - -const conversions = require("webidl-conversions"); -const utils = require("./utils.js"); - -const CEReactions = require("../CEReactions.js"); -const implSymbol = utils.implSymbol; -const ctorRegistrySymbol = utils.ctorRegistrySymbol; - -const interfaceName = "CEReactions"; - -exports.is = value => { - return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; -}; -exports.isImpl = value => { - return utils.isObject(value) && value instanceof Impl.implementation; -}; -exports.convert = (globalObject, value, { context = "The provided value" } = {}) => { - if (exports.is(value)) { - return utils.implForWrapper(value); - } - throw new globalObject.TypeError(\`\${context} is not of type 'CEReactions'.\`); -}; - -function makeWrapper(globalObject, newTarget) { - let proto; - if (newTarget !== undefined) { - proto = newTarget.prototype; - } - - if (!utils.isObject(proto)) { - proto = globalObject[ctorRegistrySymbol]["CEReactions"].prototype; - } - - return Object.create(proto); -} - -function makeProxy(wrapper, globalObject) { - let proxyHandler = proxyHandlerCache.get(globalObject); - if (proxyHandler === undefined) { - proxyHandler = new ProxyHandler(globalObject); - proxyHandlerCache.set(globalObject, proxyHandler); - } - return new Proxy(wrapper, proxyHandler); -} - -exports.create = (globalObject, constructorArgs, privateData) => { - const wrapper = makeWrapper(globalObject); - return exports.setup(wrapper, globalObject, constructorArgs, privateData); -}; - -exports.createImpl = (globalObject, constructorArgs, privateData) => { - const wrapper = exports.create(globalObject, constructorArgs, privateData); - return utils.implForWrapper(wrapper); -}; - -exports._internalSetup = (wrapper, globalObject) => {}; - -exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => { - privateData.wrapper = wrapper; - - exports._internalSetup(wrapper, globalObject); - Object.defineProperty(wrapper, implSymbol, { - value: new Impl.implementation(globalObject, constructorArgs, privateData), - configurable: true - }); - - wrapper = makeProxy(wrapper, globalObject); - - wrapper[implSymbol][utils.wrapperSymbol] = wrapper; - if (Impl.init) { - Impl.init(wrapper[implSymbol]); - } - return wrapper; -}; - -exports.new = (globalObject, newTarget) => { - let wrapper = makeWrapper(globalObject, newTarget); - - exports._internalSetup(wrapper, globalObject); - Object.defineProperty(wrapper, implSymbol, { - value: Object.create(Impl.implementation.prototype), - configurable: true - }); - - wrapper = makeProxy(wrapper, globalObject); - - wrapper[implSymbol][utils.wrapperSymbol] = wrapper; - if (Impl.init) { - Impl.init(wrapper[implSymbol]); - } - return wrapper[implSymbol]; -}; - -const exposed = new Set(["Window"]); - -exports.install = (globalObject, globalNames) => { - if (!globalNames.some(globalName => exposed.has(globalName))) { - return; - } - - const ctorRegistry = utils.initCtorRegistry(globalObject); - class CEReactions { - constructor() { - throw new globalObject.TypeError("Illegal constructor"); - } - method() { + asbs(source) { const esValue = this !== null && this !== undefined ? this : globalObject; if (!exports.is(esValue)) { - throw new globalObject.TypeError("'method' called on an object that is not a valid instance of CEReactions."); + throw new globalObject.TypeError( + "'asbs' called on an object that is not a valid instance of BufferSourceTypes." + ); } - CEReactions.preSteps(globalObject); - try { - return esValue[implSymbol].method(); - } finally { - CEReactions.postSteps(globalObject); + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'asbs' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); } - } - - promiseOperation() { - try { - const esValue = this !== null && this !== undefined ? this : globalObject; - if (!exports.is(esValue)) { + const args = []; + { + let curArg = arguments[0]; + if (utils.isArrayBuffer(curArg)) { + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'asbs' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); + } else if (utils.isSharedArrayBuffer(curArg)) { + curArg = conversions["SharedArrayBuffer"](curArg, { + context: "Failed to execute 'asbs' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); + } else if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'asbs' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowShared: true + }); + } else { throw new globalObject.TypeError( - "'promiseOperation' called on an object that is not a valid instance of CEReactions." + "Failed to execute 'asbs' on 'BufferSourceTypes': parameter 1" + " is not of any supported type." ); } - - CEReactions.preSteps(globalObject); - try { - return utils.tryWrapperForImpl(esValue[implSymbol].promiseOperation()); - } finally { - CEReactions.postSteps(globalObject); - } - } catch (e) { - return globalObject.Promise.reject(e); + args.push(curArg); } + return esValue[implSymbol].asbs(...args); } - get attr() { + abvAllowShared(abv) { const esValue = this !== null && this !== undefined ? this : globalObject; - if (!exports.is(esValue)) { - throw new globalObject.TypeError("'get attr' called on an object that is not a valid instance of CEReactions."); + throw new globalObject.TypeError( + "'abvAllowShared' called on an object that is not a valid instance of BufferSourceTypes." + ); } - CEReactions.preSteps(globalObject); - try { - return esValue[implSymbol]["attr"]; - } finally { - CEReactions.postSteps(globalObject); + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'abvAllowShared' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'abvAllowShared' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowShared: true + }); + } else { + throw new globalObject.TypeError( + "Failed to execute 'abvAllowShared' on 'BufferSourceTypes': parameter 1" + " is not of any supported type." + ); + } + args.push(curArg); } + return esValue[implSymbol].abvAllowShared(...args); } - set attr(V) { + u8aAllowShared(u8) { const esValue = this !== null && this !== undefined ? this : globalObject; - if (!exports.is(esValue)) { - throw new globalObject.TypeError("'set attr' called on an object that is not a valid instance of CEReactions."); + throw new globalObject.TypeError( + "'u8aAllowShared' called on an object that is not a valid instance of BufferSourceTypes." + ); } - V = conversions["DOMString"](V, { - context: "Failed to set the 'attr' property on 'CEReactions': The provided value", - globals: globalObject - }); - - CEReactions.preSteps(globalObject); - try { - esValue[implSymbol]["attr"] = V; - } finally { - CEReactions.postSteps(globalObject); + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'u8aAllowShared' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions["Uint8Array"](curArg, { + context: "Failed to execute 'u8aAllowShared' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowShared: true + }); + args.push(curArg); } + return esValue[implSymbol].u8aAllowShared(...args); } - get promiseAttribute() { - try { - const esValue = this !== null && this !== undefined ? this : globalObject; + bsAllowResizable(source) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'bsAllowResizable' called on an object that is not a valid instance of BufferSourceTypes." + ); + } - if (!exports.is(esValue)) { + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'bsAllowResizable' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + if (utils.isArrayBuffer(curArg)) { + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'bsAllowResizable' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true + }); + } else if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'bsAllowResizable' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true + }); + } else { throw new globalObject.TypeError( - "'get promiseAttribute' called on an object that is not a valid instance of CEReactions." + "Failed to execute 'bsAllowResizable' on 'BufferSourceTypes': parameter 1" + + " is not of any supported type." ); } - - CEReactions.preSteps(globalObject); - try { - return utils.tryWrapperForImpl(esValue[implSymbol]["promiseAttribute"]); - } finally { - CEReactions.postSteps(globalObject); - } - } catch (e) { - return globalObject.Promise.reject(e); + args.push(curArg); } + return esValue[implSymbol].bsAllowResizable(...args); } - } - Object.defineProperties(CEReactions.prototype, { - method: { enumerable: true }, - promiseOperation: { enumerable: true }, - attr: { enumerable: true }, - promiseAttribute: { enumerable: true }, - [Symbol.toStringTag]: { value: "CEReactions", configurable: true } - }); - ctorRegistry[interfaceName] = CEReactions; - - Object.defineProperty(globalObject, interfaceName, { - configurable: true, - writable: true, - value: CEReactions - }); -}; -const proxyHandlerCache = new WeakMap(); -class ProxyHandler { - constructor(globalObject) { - this._globalObject = globalObject; - } - - get(target, P, receiver) { - if (typeof P === "symbol") { - return Reflect.get(target, P, receiver); - } - const desc = this.getOwnPropertyDescriptor(target, P); - if (desc === undefined) { - const parent = Object.getPrototypeOf(target); - if (parent === null) { - return undefined; + abAllowResizable(ab) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'abAllowResizable' called on an object that is not a valid instance of BufferSourceTypes." + ); } - return Reflect.get(target, P, receiver); - } - if (!desc.get && !desc.set) { - return desc.value; - } - const getter = desc.get; - if (getter === undefined) { - return undefined; - } - return Reflect.apply(getter, receiver, []); - } - - has(target, P) { - if (typeof P === "symbol") { - return Reflect.has(target, P); - } - const desc = this.getOwnPropertyDescriptor(target, P); - if (desc !== undefined) { - return true; - } - const parent = Object.getPrototypeOf(target); - if (parent !== null) { - return Reflect.has(parent, P); - } - return false; - } - - ownKeys(target) { - const keys = new Set(); - for (const key of target[implSymbol][utils.supportedPropertyNames]) { - if (!(key in target)) { - keys.add(\`\${key}\`); + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'abAllowResizable' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'abAllowResizable' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true + }); + args.push(curArg); + } + return esValue[implSymbol].abAllowResizable(...args); } - for (const key of Reflect.ownKeys(target)) { - keys.add(key); - } - return [...keys]; - } - - getOwnPropertyDescriptor(target, P) { - if (typeof P === "symbol") { - return Reflect.getOwnPropertyDescriptor(target, P); - } - let ignoreNamedProps = false; - - if (target[implSymbol][utils.supportsPropertyName](P) && !(P in target) && !ignoreNamedProps) { - const namedValue = target[implSymbol][utils.namedGet](P); - - return { - writable: true, - enumerable: true, - configurable: true, - value: utils.tryWrapperForImpl(namedValue) - }; - } - - return Reflect.getOwnPropertyDescriptor(target, P); - } + sabAllowResizable(sab) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'sabAllowResizable' called on an object that is not a valid instance of BufferSourceTypes." + ); + } - set(target, P, V, receiver) { - if (typeof P === "symbol") { - return Reflect.set(target, P, V, receiver); + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'sabAllowResizable' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions["SharedArrayBuffer"](curArg, { + context: "Failed to execute 'sabAllowResizable' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true + }); + args.push(curArg); + } + return esValue[implSymbol].sabAllowResizable(...args); } - // The \`receiver\` argument refers to the Proxy exotic object or an object - // that inherits from it, whereas \`target\` refers to the Proxy target: - if (target[implSymbol][utils.wrapperSymbol] === receiver) { - const globalObject = this._globalObject; - - if (typeof P === "string") { - let namedValue = V; - namedValue = conversions["DOMString"](namedValue, { - context: "Failed to set the '" + P + "' property on 'CEReactions': The provided value", - globals: globalObject - }); + abvAllowResizable(abv) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'abvAllowResizable' called on an object that is not a valid instance of BufferSourceTypes." + ); + } - CEReactions.preSteps(globalObject); - try { - const creating = !target[implSymbol][utils.supportsPropertyName](P); - if (creating) { - target[implSymbol][utils.namedSetNew](P, namedValue); - } else { - target[implSymbol][utils.namedSetExisting](P, namedValue); - } - } finally { - CEReactions.postSteps(globalObject); + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'abvAllowResizable' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'abvAllowResizable' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true + }); + } else { + throw new globalObject.TypeError( + "Failed to execute 'abvAllowResizable' on 'BufferSourceTypes': parameter 1" + + " is not of any supported type." + ); } - - return true; + args.push(curArg); } + return esValue[implSymbol].abvAllowResizable(...args); } - let ownDesc; - if (ownDesc === undefined) { - ownDesc = Reflect.getOwnPropertyDescriptor(target, P); - } - return utils.ordinarySetWithOwnDescriptor(target, P, V, receiver, ownDesc); - } + u8aAllowResizable(u8) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'u8aAllowResizable' called on an object that is not a valid instance of BufferSourceTypes." + ); + } - defineProperty(target, P, desc) { - if (typeof P === "symbol") { - return Reflect.defineProperty(target, P, desc); + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'u8aAllowResizable' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions["Uint8Array"](curArg, { + context: "Failed to execute 'u8aAllowResizable' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true + }); + args.push(curArg); + } + return esValue[implSymbol].u8aAllowResizable(...args); } - const globalObject = this._globalObject; - if (!Object.hasOwn(target, P)) { - if (desc.get || desc.set) { - return false; + asbsAllowResizable(source) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'asbsAllowResizable' called on an object that is not a valid instance of BufferSourceTypes." + ); } - let namedValue = desc.value; - - namedValue = conversions["DOMString"](namedValue, { - context: "Failed to set the '" + P + "' property on 'CEReactions': The provided value", - globals: globalObject - }); - - CEReactions.preSteps(globalObject); - try { - const creating = !target[implSymbol][utils.supportsPropertyName](P); - if (creating) { - target[implSymbol][utils.namedSetNew](P, namedValue); + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'asbsAllowResizable' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + if (utils.isArrayBuffer(curArg)) { + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'asbsAllowResizable' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true + }); + } else if (utils.isSharedArrayBuffer(curArg)) { + curArg = conversions["SharedArrayBuffer"](curArg, { + context: "Failed to execute 'asbsAllowResizable' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true + }); + } else if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'asbsAllowResizable' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true, + allowShared: true + }); } else { - target[implSymbol][utils.namedSetExisting](P, namedValue); + throw new globalObject.TypeError( + "Failed to execute 'asbsAllowResizable' on 'BufferSourceTypes': parameter 1" + + " is not of any supported type." + ); } - } finally { - CEReactions.postSteps(globalObject); + args.push(curArg); } - - return true; - } - return Reflect.defineProperty(target, P, desc); - } - - deleteProperty(target, P) { - if (typeof P === "symbol") { - return Reflect.deleteProperty(target, P); + return esValue[implSymbol].asbsAllowResizable(...args); } - const globalObject = this._globalObject; - - if (target[implSymbol][utils.supportsPropertyName](P) && !(P in target)) { - CEReactions.preSteps(globalObject); - try { - target[implSymbol][utils.namedDelete](P); - return true; - } finally { - CEReactions.postSteps(globalObject); + abvAllowResizableShared(abv) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'abvAllowResizableShared' called on an object that is not a valid instance of BufferSourceTypes." + ); } - } - - return Reflect.deleteProperty(target, P); - } - - preventExtensions() { - return false; - } -} -const Impl = require("../implementations/CEReactions.js"); -" -`; - -exports[`generation with processors CallbackUsage.webidl 1`] = ` -""use strict"; - -const conversions = require("webidl-conversions"); -const utils = require("./utils.js"); - -const Function = require("./Function.js"); -const URLCallback = require("./URLCallback.js"); -const URLHandlerNonNull = require("./URLHandlerNonNull.js"); -const VoidFunction = require("./VoidFunction.js"); - -exports._convertInherit = (globalObject, obj, ret, { context = "The provided value" } = {}) => { - { - const key = "function"; - let value = obj === undefined || obj === null ? undefined : obj[key]; - if (value !== undefined) { - value = Function.convert(globalObject, value, { context: context + " has member 'function' that" }); - - ret[key] = value; - } - } - - { - const key = "urlCallback"; - let value = obj === undefined || obj === null ? undefined : obj[key]; - if (value !== undefined) { - value = URLCallback.convert(globalObject, value, { context: context + " has member 'urlCallback' that" }); - - ret[key] = value; - } - } - - { - const key = "urlHandler"; - let value = obj === undefined || obj === null ? undefined : obj[key]; - if (value !== undefined) { - if (!utils.isObject(value)) { - value = null; - } else { - value = URLHandlerNonNull.convert(globalObject, value, { context: context + " has member 'urlHandler' that" }); + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'abvAllowResizableShared' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); } - ret[key] = value; + const args = []; + { + let curArg = arguments[0]; + if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'abvAllowResizableShared' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true, + allowShared: true + }); + } else { + throw new globalObject.TypeError( + "Failed to execute 'abvAllowResizableShared' on 'BufferSourceTypes': parameter 1" + + " is not of any supported type." + ); + } + args.push(curArg); + } + return esValue[implSymbol].abvAllowResizableShared(...args); } - } - { - const key = "urlHandlerNonNull"; - let value = obj === undefined || obj === null ? undefined : obj[key]; - if (value !== undefined) { - value = URLHandlerNonNull.convert(globalObject, value, { - context: context + " has member 'urlHandlerNonNull' that" - }); + u8aAllowResizableShared(u8) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'u8aAllowResizableShared' called on an object that is not a valid instance of BufferSourceTypes." + ); + } - ret[key] = value; + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'u8aAllowResizableShared' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions["Uint8Array"](curArg, { + context: "Failed to execute 'u8aAllowResizableShared' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true, + allowShared: true + }); + args.push(curArg); + } + return esValue[implSymbol].u8aAllowResizableShared(...args); } } + Object.defineProperties(BufferSourceTypes.prototype, { + bs: { enumerable: true }, + ab: { enumerable: true }, + sab: { enumerable: true }, + abv: { enumerable: true }, + u8a: { enumerable: true }, + abUnion: { enumerable: true }, + sabUnion: { enumerable: true }, + u8aUnion: { enumerable: true }, + asbs: { enumerable: true }, + abvAllowShared: { enumerable: true }, + u8aAllowShared: { enumerable: true }, + bsAllowResizable: { enumerable: true }, + abAllowResizable: { enumerable: true }, + sabAllowResizable: { enumerable: true }, + abvAllowResizable: { enumerable: true }, + u8aAllowResizable: { enumerable: true }, + asbsAllowResizable: { enumerable: true }, + abvAllowResizableShared: { enumerable: true }, + u8aAllowResizableShared: { enumerable: true }, + [Symbol.toStringTag]: { value: "BufferSourceTypes", configurable: true } + }); + ctorRegistry[interfaceName] = BufferSourceTypes; - { - const key = "voidFunction"; - let value = obj === undefined || obj === null ? undefined : obj[key]; - if (value !== undefined) { - value = VoidFunction.convert(globalObject, value, { context: context + " has member 'voidFunction' that" }); - - ret[key] = value; - } - } + Object.defineProperty(globalObject, interfaceName, { + configurable: true, + writable: true, + value: BufferSourceTypes + }); }; -exports.convert = (globalObject, obj, { context = "The provided value" } = {}) => { - if (obj !== undefined && typeof obj !== "object" && typeof obj !== "function") { - throw new globalObject.TypeError(\`\${context} is not an object.\`); - } - - const ret = Object.create(null); - exports._convertInherit(globalObject, obj, ret, { context }); - return ret; -}; +const Impl = require("../implementations/BufferSourceTypes.js"); " `; -exports[`generation with processors DOMImplementation.webidl 1`] = ` +exports[`generation with processors CEReactions.webidl 1`] = ` ""use strict"; const conversions = require("webidl-conversions"); const utils = require("./utils.js"); +const CEReactions = require("../CEReactions.js"); const implSymbol = utils.implSymbol; const ctorRegistrySymbol = utils.ctorRegistrySymbol; -const interfaceName = "DOMImplementation"; +const interfaceName = "CEReactions"; exports.is = value => { return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; @@ -2042,7 +2014,7 @@ exports.convert = (globalObject, value, { context = "The provided value" } = {}) if (exports.is(value)) { return utils.implForWrapper(value); } - throw new globalObject.TypeError(\`\${context} is not of type 'DOMImplementation'.\`); + throw new globalObject.TypeError(\`\${context} is not of type 'CEReactions'.\`); }; function makeWrapper(globalObject, newTarget) { @@ -2052,12 +2024,21 @@ function makeWrapper(globalObject, newTarget) { } if (!utils.isObject(proto)) { - proto = globalObject[ctorRegistrySymbol]["DOMImplementation"].prototype; + proto = globalObject[ctorRegistrySymbol]["CEReactions"].prototype; } return Object.create(proto); } +function makeProxy(wrapper, globalObject) { + let proxyHandler = proxyHandlerCache.get(globalObject); + if (proxyHandler === undefined) { + proxyHandler = new ProxyHandler(globalObject); + proxyHandlerCache.set(globalObject, proxyHandler); + } + return new Proxy(wrapper, proxyHandler); +} + exports.create = (globalObject, constructorArgs, privateData) => { const wrapper = makeWrapper(globalObject); return exports.setup(wrapper, globalObject, constructorArgs, privateData); @@ -2079,6 +2060,8 @@ exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) configurable: true }); + wrapper = makeProxy(wrapper, globalObject); + wrapper[implSymbol][utils.wrapperSymbol] = wrapper; if (Impl.init) { Impl.init(wrapper[implSymbol]); @@ -2087,7 +2070,7 @@ exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) }; exports.new = (globalObject, newTarget) => { - const wrapper = makeWrapper(globalObject, newTarget); + let wrapper = makeWrapper(globalObject, newTarget); exports._internalSetup(wrapper, globalObject); Object.defineProperty(wrapper, implSymbol, { @@ -2095,6 +2078,8 @@ exports.new = (globalObject, newTarget) => { configurable: true }); + wrapper = makeProxy(wrapper, globalObject); + wrapper[implSymbol][utils.wrapperSymbol] = wrapper; if (Impl.init) { Impl.init(wrapper[implSymbol]); @@ -2110,510 +2095,363 @@ exports.install = (globalObject, globalNames) => { } const ctorRegistry = utils.initCtorRegistry(globalObject); - class DOMImplementation { + class CEReactions { constructor() { throw new globalObject.TypeError("Illegal constructor"); } - createDocumentType(qualifiedName, publicId, systemId) { + method() { const esValue = this !== null && this !== undefined ? this : globalObject; if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'createDocumentType' called on an object that is not a valid instance of DOMImplementation." - ); + throw new globalObject.TypeError("'method' called on an object that is not a valid instance of CEReactions."); } - if (arguments.length < 3) { - throw new globalObject.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", - globals: globalObject - }); - args.push(curArg); - } - { - let curArg = arguments[1]; - curArg = conversions["DOMString"](curArg, { - context: "Failed to execute 'createDocumentType' on 'DOMImplementation': parameter 2", - globals: globalObject - }); - args.push(curArg); - } - { - let curArg = arguments[2]; - curArg = conversions["DOMString"](curArg, { - context: "Failed to execute 'createDocumentType' on 'DOMImplementation': parameter 3", - globals: globalObject - }); - args.push(curArg); + CEReactions.preSteps(globalObject); + try { + return esValue[implSymbol].method(); + } finally { + CEReactions.postSteps(globalObject); } - return utils.tryWrapperForImpl(esValue[implSymbol].createDocumentType(...args)); } - createDocument(namespace, qualifiedName) { - const esValue = this !== null && this !== undefined ? this : globalObject; - if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'createDocument' called on an object that is not a valid instance of DOMImplementation." - ); - } - - if (arguments.length < 2) { - throw new globalObject.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", - globals: globalObject - }); + promiseOperation() { + try { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'promiseOperation' called on an object that is not a valid instance of CEReactions." + ); } - args.push(curArg); - } - { - let curArg = arguments[1]; - curArg = conversions["DOMString"](curArg, { - context: "Failed to execute 'createDocument' on 'DOMImplementation': parameter 2", - globals: globalObject, - 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; + + CEReactions.preSteps(globalObject); + try { + return utils.tryWrapperForImpl(esValue[implSymbol].promiseOperation()); + } finally { + CEReactions.postSteps(globalObject); } - args.push(curArg); + } catch (e) { + return globalObject.Promise.reject(e); } - return utils.tryWrapperForImpl(esValue[implSymbol].createDocument(...args)); } - createHTMLDocument() { + get attr() { const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'createHTMLDocument' called on an object that is not a valid instance of DOMImplementation." - ); + throw new globalObject.TypeError("'get attr' called on an object that is not a valid instance of CEReactions."); } - const args = []; - { - let curArg = arguments[0]; - if (curArg !== undefined) { - curArg = conversions["DOMString"](curArg, { - context: "Failed to execute 'createHTMLDocument' on 'DOMImplementation': parameter 1", - globals: globalObject - }); - } - args.push(curArg); + + CEReactions.preSteps(globalObject); + try { + return esValue[implSymbol]["attr"]; + } finally { + CEReactions.postSteps(globalObject); } - return utils.tryWrapperForImpl(esValue[implSymbol].createHTMLDocument(...args)); } - hasFeature() { + set attr(V) { const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'hasFeature' called on an object that is not a valid instance of DOMImplementation." - ); + throw new globalObject.TypeError("'set attr' called on an object that is not a valid instance of CEReactions."); } - return esValue[implSymbol].hasFeature(); + V = conversions["DOMString"](V, { + context: "Failed to set the 'attr' property on 'CEReactions': The provided value", + globals: globalObject + }); + + CEReactions.preSteps(globalObject); + try { + esValue[implSymbol]["attr"] = V; + } finally { + CEReactions.postSteps(globalObject); + } + } + + get promiseAttribute() { + try { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'get promiseAttribute' called on an object that is not a valid instance of CEReactions." + ); + } + + CEReactions.preSteps(globalObject); + try { + return utils.tryWrapperForImpl(esValue[implSymbol]["promiseAttribute"]); + } finally { + CEReactions.postSteps(globalObject); + } + } catch (e) { + return globalObject.Promise.reject(e); + } } } - Object.defineProperties(DOMImplementation.prototype, { - createDocumentType: { enumerable: true }, - createDocument: { enumerable: true }, - createHTMLDocument: { enumerable: true }, - hasFeature: { enumerable: true }, - [Symbol.toStringTag]: { value: "DOMImplementation", configurable: true } + Object.defineProperties(CEReactions.prototype, { + method: { enumerable: true }, + promiseOperation: { enumerable: true }, + attr: { enumerable: true }, + promiseAttribute: { enumerable: true }, + [Symbol.toStringTag]: { value: "CEReactions", configurable: true } }); - ctorRegistry[interfaceName] = DOMImplementation; + ctorRegistry[interfaceName] = CEReactions; Object.defineProperty(globalObject, interfaceName, { configurable: true, writable: true, - value: DOMImplementation + value: CEReactions }); }; -const Impl = require("../implementations/DOMImplementation.js"); -" -`; - -exports[`generation with processors DOMRect.webidl 1`] = ` -""use strict"; - -const conversions = require("webidl-conversions"); -const utils = require("./utils.js"); - -const Dictionary = require("./Dictionary.js"); -const implSymbol = utils.implSymbol; -const ctorRegistrySymbol = utils.ctorRegistrySymbol; - -const interfaceName = "DOMRect"; - -exports.is = value => { - return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; -}; -exports.isImpl = value => { - return utils.isObject(value) && value instanceof Impl.implementation; -}; -exports.convert = (globalObject, value, { context = "The provided value" } = {}) => { - if (exports.is(value)) { - return utils.implForWrapper(value); +const proxyHandlerCache = new WeakMap(); +class ProxyHandler { + constructor(globalObject) { + this._globalObject = globalObject; } - throw new globalObject.TypeError(\`\${context} is not of type 'DOMRect'.\`); -}; -function makeWrapper(globalObject, newTarget) { - let proto; - if (newTarget !== undefined) { - proto = newTarget.prototype; + get(target, P, receiver) { + if (typeof P === "symbol") { + return Reflect.get(target, P, receiver); + } + const desc = this.getOwnPropertyDescriptor(target, P); + if (desc === undefined) { + const parent = Object.getPrototypeOf(target); + if (parent === null) { + return undefined; + } + return Reflect.get(target, P, receiver); + } + if (!desc.get && !desc.set) { + return desc.value; + } + const getter = desc.get; + if (getter === undefined) { + return undefined; + } + return Reflect.apply(getter, receiver, []); } - if (!utils.isObject(proto)) { - proto = globalObject[ctorRegistrySymbol]["DOMRect"].prototype; + has(target, P) { + if (typeof P === "symbol") { + return Reflect.has(target, P); + } + const desc = this.getOwnPropertyDescriptor(target, P); + if (desc !== undefined) { + return true; + } + const parent = Object.getPrototypeOf(target); + if (parent !== null) { + return Reflect.has(parent, P); + } + return false; } - return Object.create(proto); -} + ownKeys(target) { + const keys = new Set(); -exports.create = (globalObject, constructorArgs, privateData) => { - const wrapper = makeWrapper(globalObject); - return exports.setup(wrapper, globalObject, constructorArgs, privateData); -}; + for (const key of target[implSymbol][utils.supportedPropertyNames]) { + if (!(key in target)) { + keys.add(\`\${key}\`); + } + } -exports.createImpl = (globalObject, constructorArgs, privateData) => { - const wrapper = exports.create(globalObject, constructorArgs, privateData); - return utils.implForWrapper(wrapper); -}; + for (const key of Reflect.ownKeys(target)) { + keys.add(key); + } + return [...keys]; + } -exports._internalSetup = (wrapper, globalObject) => {}; + getOwnPropertyDescriptor(target, P) { + if (typeof P === "symbol") { + return Reflect.getOwnPropertyDescriptor(target, P); + } + let ignoreNamedProps = false; -exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => { - privateData.wrapper = wrapper; + if (target[implSymbol][utils.supportsPropertyName](P) && !(P in target) && !ignoreNamedProps) { + const namedValue = target[implSymbol][utils.namedGet](P); - exports._internalSetup(wrapper, globalObject); - Object.defineProperty(wrapper, implSymbol, { - value: new Impl.implementation(globalObject, constructorArgs, privateData), - configurable: true - }); + return { + writable: true, + enumerable: true, + configurable: true, + value: utils.tryWrapperForImpl(namedValue) + }; + } - wrapper[implSymbol][utils.wrapperSymbol] = wrapper; - if (Impl.init) { - Impl.init(wrapper[implSymbol]); + return Reflect.getOwnPropertyDescriptor(target, P); } - return wrapper; -}; - -exports.new = (globalObject, newTarget) => { - const wrapper = makeWrapper(globalObject, newTarget); - - exports._internalSetup(wrapper, globalObject); - Object.defineProperty(wrapper, implSymbol, { - value: Object.create(Impl.implementation.prototype), - configurable: true - }); - wrapper[implSymbol][utils.wrapperSymbol] = wrapper; - if (Impl.init) { - Impl.init(wrapper[implSymbol]); - } - return wrapper[implSymbol]; -}; + set(target, P, V, receiver) { + if (typeof P === "symbol") { + return Reflect.set(target, P, V, receiver); + } + // The \`receiver\` argument refers to the Proxy exotic object or an object + // that inherits from it, whereas \`target\` refers to the Proxy target: + if (target[implSymbol][utils.wrapperSymbol] === receiver) { + const globalObject = this._globalObject; -const exposed = new Set(["Window", "Worker"]); + if (typeof P === "string") { + let namedValue = V; -exports.install = (globalObject, globalNames) => { - if (!globalNames.some(globalName => exposed.has(globalName))) { - return; - } + namedValue = conversions["DOMString"](namedValue, { + context: "Failed to set the '" + P + "' property on 'CEReactions': The provided value", + globals: globalObject + }); - const ctorRegistry = utils.initCtorRegistry(globalObject); - class DOMRect { - constructor() { - const args = []; - { - let curArg = arguments[0]; - if (curArg !== undefined) { - curArg = conversions["unrestricted double"](curArg, { - context: "Failed to construct 'DOMRect': parameter 1", - globals: globalObject - }); - } else { - curArg = 0; - } - args.push(curArg); - } - { - let curArg = arguments[1]; - if (curArg !== undefined) { - curArg = conversions["unrestricted double"](curArg, { - context: "Failed to construct 'DOMRect': parameter 2", - globals: globalObject - }); - } else { - curArg = 0; - } - args.push(curArg); - } - { - let curArg = arguments[2]; - if (curArg !== undefined) { - curArg = conversions["unrestricted double"](curArg, { - context: "Failed to construct 'DOMRect': parameter 3", - globals: globalObject - }); - } else { - curArg = 0; - } - args.push(curArg); - } - { - let curArg = arguments[3]; - if (curArg !== undefined) { - curArg = conversions["unrestricted double"](curArg, { - context: "Failed to construct 'DOMRect': parameter 4", - globals: globalObject - }); - } else { - curArg = 0; + CEReactions.preSteps(globalObject); + try { + const creating = !target[implSymbol][utils.supportsPropertyName](P); + if (creating) { + target[implSymbol][utils.namedSetNew](P, namedValue); + } else { + target[implSymbol][utils.namedSetExisting](P, namedValue); + } + } finally { + CEReactions.postSteps(globalObject); } - args.push(curArg); - } - return exports.setup(Object.create(new.target.prototype), globalObject, args); - } - - get x() { - const esValue = this !== null && this !== undefined ? this : globalObject; - if (!exports.is(esValue)) { - throw new globalObject.TypeError("'get x' called on an object that is not a valid instance of DOMRect."); + return true; } + } + let ownDesc; - return esValue[implSymbol]["x"]; + if (ownDesc === undefined) { + ownDesc = Reflect.getOwnPropertyDescriptor(target, P); } + return utils.ordinarySetWithOwnDescriptor(target, P, V, receiver, ownDesc); + } - set x(V) { - const esValue = this !== null && this !== undefined ? this : globalObject; + defineProperty(target, P, desc) { + if (typeof P === "symbol") { + return Reflect.defineProperty(target, P, desc); + } - if (!exports.is(esValue)) { - throw new globalObject.TypeError("'set x' called on an object that is not a valid instance of DOMRect."); + const globalObject = this._globalObject; + if (!Object.hasOwn(target, P)) { + if (desc.get || desc.set) { + return false; } - V = conversions["unrestricted double"](V, { - context: "Failed to set the 'x' property on 'DOMRect': The provided value", + let namedValue = desc.value; + + namedValue = conversions["DOMString"](namedValue, { + context: "Failed to set the '" + P + "' property on 'CEReactions': The provided value", globals: globalObject }); - esValue[implSymbol]["x"] = V; + CEReactions.preSteps(globalObject); + try { + const creating = !target[implSymbol][utils.supportsPropertyName](P); + if (creating) { + target[implSymbol][utils.namedSetNew](P, namedValue); + } else { + target[implSymbol][utils.namedSetExisting](P, namedValue); + } + } finally { + CEReactions.postSteps(globalObject); + } + + return true; } + return Reflect.defineProperty(target, P, desc); + } - get y() { - const esValue = this !== null && this !== undefined ? this : globalObject; + deleteProperty(target, P) { + if (typeof P === "symbol") { + return Reflect.deleteProperty(target, P); + } - if (!exports.is(esValue)) { - throw new globalObject.TypeError("'get y' called on an object that is not a valid instance of DOMRect."); - } + const globalObject = this._globalObject; - return esValue[implSymbol]["y"]; + if (target[implSymbol][utils.supportsPropertyName](P) && !(P in target)) { + CEReactions.preSteps(globalObject); + try { + target[implSymbol][utils.namedDelete](P); + return true; + } finally { + CEReactions.postSteps(globalObject); + } } - set y(V) { - const esValue = this !== null && this !== undefined ? this : globalObject; + return Reflect.deleteProperty(target, P); + } - if (!exports.is(esValue)) { - throw new globalObject.TypeError("'set y' called on an object that is not a valid instance of DOMRect."); - } + preventExtensions() { + return false; + } +} - V = conversions["unrestricted double"](V, { - context: "Failed to set the 'y' property on 'DOMRect': The provided value", - globals: globalObject - }); +const Impl = require("../implementations/CEReactions.js"); +" +`; - esValue[implSymbol]["y"] = V; - } +exports[`generation with processors CallbackUsage.webidl 1`] = ` +""use strict"; - get width() { - const esValue = this !== null && this !== undefined ? this : globalObject; +const conversions = require("webidl-conversions"); +const utils = require("./utils.js"); - if (!exports.is(esValue)) { - throw new globalObject.TypeError("'get width' called on an object that is not a valid instance of DOMRect."); - } +const Function = require("./Function.js"); +const URLCallback = require("./URLCallback.js"); +const URLHandlerNonNull = require("./URLHandlerNonNull.js"); +const VoidFunction = require("./VoidFunction.js"); - return esValue[implSymbol]["width"]; +exports._convertInherit = (globalObject, obj, ret, { context = "The provided value" } = {}) => { + { + const key = "function"; + let value = obj === undefined || obj === null ? undefined : obj[key]; + if (value !== undefined) { + value = Function.convert(globalObject, value, { context: context + " has member 'function' that" }); + + ret[key] = value; } + } - set width(V) { - const esValue = this !== null && this !== undefined ? this : globalObject; + { + const key = "urlCallback"; + let value = obj === undefined || obj === null ? undefined : obj[key]; + if (value !== undefined) { + value = URLCallback.convert(globalObject, value, { context: context + " has member 'urlCallback' that" }); - if (!exports.is(esValue)) { - throw new globalObject.TypeError("'set width' called on an object that is not a valid instance of DOMRect."); + ret[key] = value; + } + } + + { + const key = "urlHandler"; + let value = obj === undefined || obj === null ? undefined : obj[key]; + if (value !== undefined) { + if (!utils.isObject(value)) { + value = null; + } else { + value = URLHandlerNonNull.convert(globalObject, value, { context: context + " has member 'urlHandler' that" }); } + ret[key] = value; + } + } - V = conversions["unrestricted double"](V, { - context: "Failed to set the 'width' property on 'DOMRect': The provided value", - globals: globalObject + { + const key = "urlHandlerNonNull"; + let value = obj === undefined || obj === null ? undefined : obj[key]; + if (value !== undefined) { + value = URLHandlerNonNull.convert(globalObject, value, { + context: context + " has member 'urlHandlerNonNull' that" }); - esValue[implSymbol]["width"] = V; + ret[key] = value; } + } - get height() { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - throw new globalObject.TypeError("'get height' called on an object that is not a valid instance of DOMRect."); - } + { + const key = "voidFunction"; + let value = obj === undefined || obj === null ? undefined : obj[key]; + if (value !== undefined) { + value = VoidFunction.convert(globalObject, value, { context: context + " has member 'voidFunction' that" }); - return esValue[implSymbol]["height"]; - } - - set height(V) { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - throw new globalObject.TypeError("'set height' called on an object that is not a valid instance of DOMRect."); - } - - V = conversions["unrestricted double"](V, { - context: "Failed to set the 'height' property on 'DOMRect': The provided value", - globals: globalObject - }); - - esValue[implSymbol]["height"] = V; - } - - static fromRect() { - const args = []; - { - let curArg = arguments[0]; - curArg = Dictionary.convert(globalObject, curArg, { - context: "Failed to execute 'fromRect' on 'DOMRect': parameter 1" - }); - args.push(curArg); - } - return utils.tryWrapperForImpl(Impl.implementation.fromRect(globalObject, ...args)); - } - } - Object.defineProperties(DOMRect.prototype, { - x: { enumerable: true }, - y: { enumerable: true }, - width: { enumerable: true }, - height: { enumerable: true }, - [Symbol.toStringTag]: { value: "DOMRect", configurable: true } - }); - Object.defineProperties(DOMRect, { fromRect: { enumerable: true } }); - ctorRegistry[interfaceName] = DOMRect; - - Object.defineProperty(globalObject, interfaceName, { - configurable: true, - writable: true, - value: DOMRect - }); - - if (globalNames.includes("Window")) { - Object.defineProperty(globalObject, "SVGRect", { - configurable: true, - writable: true, - value: DOMRect - }); - } -}; - -const Impl = require("../implementations/DOMRect.js"); -" -`; - -exports[`generation with processors Dictionary.webidl 1`] = ` -""use strict"; - -const conversions = require("webidl-conversions"); -const utils = require("./utils.js"); - -const URL = require("./URL.js"); -const URLSearchParams = require("./URLSearchParams.js"); - -exports._convertInherit = (globalObject, obj, ret, { context = "The provided value" } = {}) => { - { - const key = "boolWithDefault"; - let value = obj === undefined || obj === null ? undefined : obj[key]; - if (value !== undefined) { - value = conversions["boolean"](value, { - context: context + " has member 'boolWithDefault' that", - globals: globalObject - }); - - ret[key] = value; - } else { - ret[key] = false; - } - } - - { - const key = "requiredInterface"; - let value = obj === undefined || obj === null ? undefined : obj[key]; - if (value !== undefined) { - value = URL.convert(globalObject, value, { context: context + " has member 'requiredInterface' that" }); - - ret[key] = value; - } else { - throw new globalObject.TypeError("requiredInterface is required in 'Dictionary'"); - } - } - - { - const key = "seq"; - let value = obj === undefined || obj === null ? undefined : obj[key]; - if (value !== undefined) { - if (!utils.isObject(value)) { - throw new globalObject.TypeError(context + " has member 'seq' that" + " is not an iterable object."); - } else { - const V = []; - const tmp = value; - for (let nextItem of tmp) { - nextItem = URLSearchParams.convert(globalObject, nextItem, { - context: context + " has member 'seq' that" + "'s element" - }); - - V.push(nextItem); - } - value = V; - } - - ret[key] = value; - } - } - - { - const key = "vanillaString"; - let value = obj === undefined || obj === null ? undefined : obj[key]; - if (value !== undefined) { - value = conversions["DOMString"](value, { - context: context + " has member 'vanillaString' that", - globals: globalObject - }); - - ret[key] = value; + ret[key] = value; } } }; @@ -2630,17 +2468,16 @@ exports.convert = (globalObject, obj, { context = "The provided value" } = {}) = " `; -exports[`generation with processors DictionaryConvert.webidl 1`] = ` +exports[`generation with processors DOMImplementation.webidl 1`] = ` ""use strict"; const conversions = require("webidl-conversions"); const utils = require("./utils.js"); -const Dictionary = require("./Dictionary.js"); const implSymbol = utils.implSymbol; const ctorRegistrySymbol = utils.ctorRegistrySymbol; -const interfaceName = "DictionaryConvert"; +const interfaceName = "DOMImplementation"; exports.is = value => { return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; @@ -2652,7 +2489,7 @@ exports.convert = (globalObject, value, { context = "The provided value" } = {}) if (exports.is(value)) { return utils.implForWrapper(value); } - throw new globalObject.TypeError(\`\${context} is not of type 'DictionaryConvert'.\`); + throw new globalObject.TypeError(\`\${context} is not of type 'DOMImplementation'.\`); }; function makeWrapper(globalObject, newTarget) { @@ -2662,7 +2499,7 @@ function makeWrapper(globalObject, newTarget) { } if (!utils.isObject(proto)) { - proto = globalObject[ctorRegistrySymbol]["DictionaryConvert"].prototype; + proto = globalObject[ctorRegistrySymbol]["DOMImplementation"].prototype; } return Object.create(proto); @@ -2720,22 +2557,73 @@ exports.install = (globalObject, globalNames) => { } const ctorRegistry = utils.initCtorRegistry(globalObject); - class DictionaryConvert { + class DOMImplementation { constructor() { throw new globalObject.TypeError("Illegal constructor"); } - op() { + createDocumentType(qualifiedName, publicId, systemId) { const esValue = this !== null && this !== undefined ? this : globalObject; if (!exports.is(esValue)) { - throw new globalObject.TypeError("'op' called on an object that is not a valid instance of DictionaryConvert."); + throw new globalObject.TypeError( + "'createDocumentType' called on an object that is not a valid instance of DOMImplementation." + ); + } + + if (arguments.length < 3) { + throw new globalObject.TypeError( + \`Failed to execute 'createDocumentType' on 'DOMImplementation': 3 arguments required, but only \${arguments.length} present.\` + ); } const args = []; { let curArg = arguments[0]; - if (curArg !== undefined) { + curArg = conversions["DOMString"](curArg, { + context: "Failed to execute 'createDocumentType' on 'DOMImplementation': parameter 1", + globals: globalObject + }); + args.push(curArg); + } + { + let curArg = arguments[1]; + curArg = conversions["DOMString"](curArg, { + context: "Failed to execute 'createDocumentType' on 'DOMImplementation': parameter 2", + globals: globalObject + }); + args.push(curArg); + } + { + let curArg = arguments[2]; + curArg = conversions["DOMString"](curArg, { + context: "Failed to execute 'createDocumentType' on 'DOMImplementation': parameter 3", + globals: globalObject + }); + args.push(curArg); + } + return utils.tryWrapperForImpl(esValue[implSymbol].createDocumentType(...args)); + } + + createDocument(namespace, qualifiedName) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'createDocument' called on an object that is not a valid instance of DOMImplementation." + ); + } + + if (arguments.length < 2) { + throw new globalObject.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 'op' on 'DictionaryConvert': parameter 1", + context: "Failed to execute 'createDocument' on 'DOMImplementation': parameter 1", globals: globalObject }); } @@ -2743,42 +2631,92 @@ exports.install = (globalObject, globalNames) => { } { let curArg = arguments[1]; - curArg = Dictionary.convert(globalObject, curArg, { - context: "Failed to execute 'op' on 'DictionaryConvert': parameter 2" + curArg = conversions["DOMString"](curArg, { + context: "Failed to execute 'createDocument' on 'DOMImplementation': parameter 2", + globals: globalObject, + treatNullAsEmptyString: true }); args.push(curArg); } - return esValue[implSymbol].op(...args); + { + 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(esValue[implSymbol].createDocument(...args)); } - } - Object.defineProperties(DictionaryConvert.prototype, { - op: { enumerable: true }, - [Symbol.toStringTag]: { value: "DictionaryConvert", configurable: true } - }); - ctorRegistry[interfaceName] = DictionaryConvert; - - Object.defineProperty(globalObject, interfaceName, { - configurable: true, - writable: true, - value: DictionaryConvert - }); -}; -const Impl = require("../implementations/DictionaryConvert.js"); -" -`; + createHTMLDocument() { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'createHTMLDocument' called on an object that is not a valid instance of DOMImplementation." + ); + } + const args = []; + { + let curArg = arguments[0]; + if (curArg !== undefined) { + curArg = conversions["DOMString"](curArg, { + context: "Failed to execute 'createHTMLDocument' on 'DOMImplementation': parameter 1", + globals: globalObject + }); + } + args.push(curArg); + } + return utils.tryWrapperForImpl(esValue[implSymbol].createHTMLDocument(...args)); + } -exports[`generation with processors Enum.webidl 1`] = ` + hasFeature() { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'hasFeature' called on an object that is not a valid instance of DOMImplementation." + ); + } + + return esValue[implSymbol].hasFeature(); + } + } + Object.defineProperties(DOMImplementation.prototype, { + createDocumentType: { enumerable: true }, + createDocument: { enumerable: true }, + createHTMLDocument: { enumerable: true }, + hasFeature: { enumerable: true }, + [Symbol.toStringTag]: { value: "DOMImplementation", configurable: true } + }); + ctorRegistry[interfaceName] = DOMImplementation; + + Object.defineProperty(globalObject, interfaceName, { + configurable: true, + writable: true, + value: DOMImplementation + }); +}; + +const Impl = require("../implementations/DOMImplementation.js"); +" +`; + +exports[`generation with processors DOMRect.webidl 1`] = ` ""use strict"; const conversions = require("webidl-conversions"); const utils = require("./utils.js"); -const RequestDestination = require("./RequestDestination.js"); +const Dictionary = require("./Dictionary.js"); const implSymbol = utils.implSymbol; const ctorRegistrySymbol = utils.ctorRegistrySymbol; -const interfaceName = "Enum"; +const interfaceName = "DOMRect"; exports.is = value => { return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; @@ -2790,7 +2728,7 @@ exports.convert = (globalObject, value, { context = "The provided value" } = {}) if (exports.is(value)) { return utils.implForWrapper(value); } - throw new globalObject.TypeError(\`\${context} is not of type 'Enum'.\`); + throw new globalObject.TypeError(\`\${context} is not of type 'DOMRect'.\`); }; function makeWrapper(globalObject, newTarget) { @@ -2800,7 +2738,7 @@ function makeWrapper(globalObject, newTarget) { } if (!utils.isObject(proto)) { - proto = globalObject[ctorRegistrySymbol]["Enum"].prototype; + proto = globalObject[ctorRegistrySymbol]["DOMRect"].prototype; } return Object.create(proto); @@ -2850,7 +2788,7 @@ exports.new = (globalObject, newTarget) => { return wrapper[implSymbol]; }; -const exposed = new Set(["Window"]); +const exposed = new Set(["Window", "Worker"]); exports.install = (globalObject, globalNames) => { if (!globalNames.some(globalName => exposed.has(globalName))) { @@ -2858,126 +2796,298 @@ exports.install = (globalObject, globalNames) => { } const ctorRegistry = utils.initCtorRegistry(globalObject); - class Enum { + class DOMRect { constructor() { - throw new globalObject.TypeError("Illegal constructor"); + const args = []; + { + let curArg = arguments[0]; + if (curArg !== undefined) { + curArg = conversions["unrestricted double"](curArg, { + context: "Failed to construct 'DOMRect': parameter 1", + globals: globalObject + }); + } else { + curArg = 0; + } + args.push(curArg); + } + { + let curArg = arguments[1]; + if (curArg !== undefined) { + curArg = conversions["unrestricted double"](curArg, { + context: "Failed to construct 'DOMRect': parameter 2", + globals: globalObject + }); + } else { + curArg = 0; + } + args.push(curArg); + } + { + let curArg = arguments[2]; + if (curArg !== undefined) { + curArg = conversions["unrestricted double"](curArg, { + context: "Failed to construct 'DOMRect': parameter 3", + globals: globalObject + }); + } else { + curArg = 0; + } + args.push(curArg); + } + { + let curArg = arguments[3]; + if (curArg !== undefined) { + curArg = conversions["unrestricted double"](curArg, { + context: "Failed to construct 'DOMRect': parameter 4", + globals: globalObject + }); + } else { + curArg = 0; + } + args.push(curArg); + } + return exports.setup(Object.create(new.target.prototype), globalObject, args); } - op(destination) { + get x() { const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { - throw new globalObject.TypeError("'op' called on an object that is not a valid instance of Enum."); + throw new globalObject.TypeError("'get x' called on an object that is not a valid instance of DOMRect."); } - if (arguments.length < 1) { - throw new globalObject.TypeError( - \`Failed to execute 'op' on 'Enum': 1 argument required, but only \${arguments.length} present.\` - ); + return esValue[implSymbol]["x"]; + } + + set x(V) { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError("'set x' called on an object that is not a valid instance of DOMRect."); } - const args = []; - { - let curArg = arguments[0]; - curArg = RequestDestination.convert(globalObject, curArg, { - context: "Failed to execute 'op' on 'Enum': parameter 1" - }); - args.push(curArg); + + V = conversions["unrestricted double"](V, { + context: "Failed to set the 'x' property on 'DOMRect': The provided value", + globals: globalObject + }); + + esValue[implSymbol]["x"] = V; + } + + get y() { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError("'get y' called on an object that is not a valid instance of DOMRect."); } - return esValue[implSymbol].op(...args); + + return esValue[implSymbol]["y"]; } - get attr() { + set y(V) { const esValue = this !== null && this !== undefined ? this : globalObject; if (!exports.is(esValue)) { - throw new globalObject.TypeError("'get attr' called on an object that is not a valid instance of Enum."); + throw new globalObject.TypeError("'set y' called on an object that is not a valid instance of DOMRect."); } - return utils.tryWrapperForImpl(esValue[implSymbol]["attr"]); + V = conversions["unrestricted double"](V, { + context: "Failed to set the 'y' property on 'DOMRect': The provided value", + globals: globalObject + }); + + esValue[implSymbol]["y"] = V; } - set attr(V) { + get width() { const esValue = this !== null && this !== undefined ? this : globalObject; if (!exports.is(esValue)) { - throw new globalObject.TypeError("'set attr' called on an object that is not a valid instance of Enum."); + throw new globalObject.TypeError("'get width' called on an object that is not a valid instance of DOMRect."); } - V = \`\${V}\`; - if (!RequestDestination.enumerationValues.has(V)) { - return; + return esValue[implSymbol]["width"]; + } + + set width(V) { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError("'set width' called on an object that is not a valid instance of DOMRect."); } - esValue[implSymbol]["attr"] = V; + V = conversions["unrestricted double"](V, { + context: "Failed to set the 'width' property on 'DOMRect': The provided value", + globals: globalObject + }); + + esValue[implSymbol]["width"] = V; + } + + get height() { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError("'get height' called on an object that is not a valid instance of DOMRect."); + } + + return esValue[implSymbol]["height"]; + } + + set height(V) { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError("'set height' called on an object that is not a valid instance of DOMRect."); + } + + V = conversions["unrestricted double"](V, { + context: "Failed to set the 'height' property on 'DOMRect': The provided value", + globals: globalObject + }); + + esValue[implSymbol]["height"] = V; + } + + static fromRect() { + const args = []; + { + let curArg = arguments[0]; + curArg = Dictionary.convert(globalObject, curArg, { + context: "Failed to execute 'fromRect' on 'DOMRect': parameter 1" + }); + args.push(curArg); + } + return utils.tryWrapperForImpl(Impl.implementation.fromRect(globalObject, ...args)); } } - Object.defineProperties(Enum.prototype, { - op: { enumerable: true }, - attr: { enumerable: true }, - [Symbol.toStringTag]: { value: "Enum", configurable: true } + Object.defineProperties(DOMRect.prototype, { + x: { enumerable: true }, + y: { enumerable: true }, + width: { enumerable: true }, + height: { enumerable: true }, + [Symbol.toStringTag]: { value: "DOMRect", configurable: true } }); - ctorRegistry[interfaceName] = Enum; + Object.defineProperties(DOMRect, { fromRect: { enumerable: true } }); + ctorRegistry[interfaceName] = DOMRect; Object.defineProperty(globalObject, interfaceName, { configurable: true, writable: true, - value: Enum + value: DOMRect }); + + if (globalNames.includes("Window")) { + Object.defineProperty(globalObject, "SVGRect", { + configurable: true, + writable: true, + value: DOMRect + }); + } }; -const Impl = require("../implementations/Enum.js"); +const Impl = require("../implementations/DOMRect.js"); " `; -exports[`generation with processors EventListener.webidl 1`] = ` +exports[`generation with processors Dictionary.webidl 1`] = ` ""use strict"; const conversions = require("webidl-conversions"); const utils = require("./utils.js"); -exports.convert = (globalObject, value, { context = "The provided value" } = {}) => { - if (!utils.isObject(value)) { - throw new globalObject.TypeError(\`\${context} is not an object.\`); - } +const URL = require("./URL.js"); +const URLSearchParams = require("./URLSearchParams.js"); - function callTheUserObjectsOperation(event) { - let thisArg = utils.tryWrapperForImpl(this); - let O = value; - let X = O; +exports._convertInherit = (globalObject, obj, ret, { context = "The provided value" } = {}) => { + { + const key = "boolWithDefault"; + let value = obj === undefined || obj === null ? undefined : obj[key]; + if (value !== undefined) { + value = conversions["boolean"](value, { + context: context + " has member 'boolWithDefault' that", + globals: globalObject + }); - if (typeof O !== "function") { - X = O["handleEvent"]; - if (typeof X !== "function") { - throw new globalObject.TypeError(\`\${context} does not correctly implement EventListener.\`); - } - thisArg = O; + ret[key] = value; + } else { + ret[key] = false; } + } - event = utils.tryWrapperForImpl(event); + { + const key = "requiredInterface"; + let value = obj === undefined || obj === null ? undefined : obj[key]; + if (value !== undefined) { + value = URL.convert(globalObject, value, { context: context + " has member 'requiredInterface' that" }); - let callResult = Reflect.apply(X, thisArg, [event]); + ret[key] = value; + } else { + throw new globalObject.TypeError("requiredInterface is required in 'Dictionary'"); + } } - callTheUserObjectsOperation[utils.wrapperSymbol] = value; - callTheUserObjectsOperation.objectReference = value; + { + const key = "seq"; + let value = obj === undefined || obj === null ? undefined : obj[key]; + if (value !== undefined) { + if (!utils.isObject(value)) { + throw new globalObject.TypeError(context + " has member 'seq' that" + " is not an iterable object."); + } else { + const V = []; + const tmp = value; + for (let nextItem of tmp) { + nextItem = URLSearchParams.convert(globalObject, nextItem, { + context: context + " has member 'seq' that" + "'s element" + }); - return callTheUserObjectsOperation; + V.push(nextItem); + } + value = V; + } + + ret[key] = value; + } + } + + { + const key = "vanillaString"; + let value = obj === undefined || obj === null ? undefined : obj[key]; + if (value !== undefined) { + value = conversions["DOMString"](value, { + context: context + " has member 'vanillaString' that", + globals: globalObject + }); + + ret[key] = value; + } + } }; -exports.install = (globalObject, globalNames) => {}; +exports.convert = (globalObject, obj, { context = "The provided value" } = {}) => { + if (obj !== undefined && typeof obj !== "object" && typeof obj !== "function") { + throw new globalObject.TypeError(\`\${context} is not an object.\`); + } + + const ret = Object.create(null); + exports._convertInherit(globalObject, obj, ret, { context }); + return ret; +}; " `; -exports[`generation with processors EventTarget.webidl 1`] = ` +exports[`generation with processors DictionaryConvert.webidl 1`] = ` ""use strict"; const conversions = require("webidl-conversions"); const utils = require("./utils.js"); -const EventListener = require("./EventListener.js"); +const Dictionary = require("./Dictionary.js"); const implSymbol = utils.implSymbol; const ctorRegistrySymbol = utils.ctorRegistrySymbol; -const interfaceName = "EventTarget"; +const interfaceName = "DictionaryConvert"; exports.is = value => { return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; @@ -2989,7 +3099,7 @@ exports.convert = (globalObject, value, { context = "The provided value" } = {}) if (exports.is(value)) { return utils.implForWrapper(value); } - throw new globalObject.TypeError(\`\${context} is not of type 'EventTarget'.\`); + throw new globalObject.TypeError(\`\${context} is not of type 'DictionaryConvert'.\`); }; function makeWrapper(globalObject, newTarget) { @@ -2999,7 +3109,7 @@ function makeWrapper(globalObject, newTarget) { } if (!utils.isObject(proto)) { - proto = globalObject[ctorRegistrySymbol]["EventTarget"].prototype; + proto = globalObject[ctorRegistrySymbol]["DictionaryConvert"].prototype; } return Object.create(proto); @@ -3049,7 +3159,7 @@ exports.new = (globalObject, newTarget) => { return wrapper[implSymbol]; }; -const exposed = new Set(["Window", "Worker", "AudioWorklet"]); +const exposed = new Set(["Window"]); exports.install = (globalObject, globalNames) => { if (!globalNames.some(globalName => exposed.has(globalName))) { @@ -3057,74 +3167,65 @@ exports.install = (globalObject, globalNames) => { } const ctorRegistry = utils.initCtorRegistry(globalObject); - class EventTarget { + class DictionaryConvert { constructor() { - return exports.setup(Object.create(new.target.prototype), globalObject, undefined); + throw new globalObject.TypeError("Illegal constructor"); } - addEventListener(type, callback) { + op() { const esValue = this !== null && this !== undefined ? this : globalObject; if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'addEventListener' called on an object that is not a valid instance of EventTarget." - ); - } - - if (arguments.length < 2) { - throw new globalObject.TypeError( - \`Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only \${arguments.length} present.\` - ); + throw new globalObject.TypeError("'op' called on an object that is not a valid instance of DictionaryConvert."); } const args = []; { let curArg = arguments[0]; - curArg = conversions["DOMString"](curArg, { - context: "Failed to execute 'addEventListener' on 'EventTarget': parameter 1", - globals: globalObject - }); + if (curArg !== undefined) { + curArg = conversions["DOMString"](curArg, { + context: "Failed to execute 'op' on 'DictionaryConvert': parameter 1", + globals: globalObject + }); + } args.push(curArg); } { let curArg = arguments[1]; - if (curArg === null || curArg === undefined) { - curArg = null; - } else { - curArg = EventListener.convert(globalObject, curArg, { - context: "Failed to execute 'addEventListener' on 'EventTarget': parameter 2" - }); - } + curArg = Dictionary.convert(globalObject, curArg, { + context: "Failed to execute 'op' on 'DictionaryConvert': parameter 2" + }); args.push(curArg); } - return esValue[implSymbol].addEventListener(...args); + return esValue[implSymbol].op(...args); } } - Object.defineProperties(EventTarget.prototype, { - addEventListener: { enumerable: true }, - [Symbol.toStringTag]: { value: "EventTarget", configurable: true } + Object.defineProperties(DictionaryConvert.prototype, { + op: { enumerable: true }, + [Symbol.toStringTag]: { value: "DictionaryConvert", configurable: true } }); - ctorRegistry[interfaceName] = EventTarget; + ctorRegistry[interfaceName] = DictionaryConvert; Object.defineProperty(globalObject, interfaceName, { configurable: true, writable: true, - value: EventTarget + value: DictionaryConvert }); }; -const Impl = require("../implementations/EventTarget.js"); +const Impl = require("../implementations/DictionaryConvert.js"); " `; -exports[`generation with processors Global.webidl 1`] = ` +exports[`generation with processors Enum.webidl 1`] = ` ""use strict"; const conversions = require("webidl-conversions"); const utils = require("./utils.js"); +const RequestDestination = require("./RequestDestination.js"); const implSymbol = utils.implSymbol; const ctorRegistrySymbol = utils.ctorRegistrySymbol; -const interfaceName = "Global"; +const interfaceName = "Enum"; exports.is = value => { return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; @@ -3136,7 +3237,7 @@ exports.convert = (globalObject, value, { context = "The provided value" } = {}) if (exports.is(value)) { return utils.implForWrapper(value); } - throw new globalObject.TypeError(\`\${context} is not of type 'Global'.\`); + throw new globalObject.TypeError(\`\${context} is not of type 'Enum'.\`); }; function makeWrapper(globalObject, newTarget) { @@ -3146,7 +3247,7 @@ function makeWrapper(globalObject, newTarget) { } if (!utils.isObject(proto)) { - proto = globalObject[ctorRegistrySymbol]["Global"].prototype; + proto = globalObject[ctorRegistrySymbol]["Enum"].prototype; } return Object.create(proto); @@ -3162,110 +3263,7 @@ exports.createImpl = (globalObject, constructorArgs, privateData) => { return utils.implForWrapper(wrapper); }; -exports._internalSetup = (wrapper, globalObject) => { - utils.define(wrapper, { - op() { - const esValue = this !== null && this !== undefined ? this : globalObject; - if (!exports.is(esValue)) { - throw new globalObject.TypeError("'op' called on an object that is not a valid instance of Global."); - } - - return esValue[implSymbol].op(); - }, - unforgeableOp() { - const esValue = this !== null && this !== undefined ? this : globalObject; - if (!exports.is(esValue)) { - throw new globalObject.TypeError("'unforgeableOp' called on an object that is not a valid instance of Global."); - } - - return esValue[implSymbol].unforgeableOp(); - }, - get attr() { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - throw new globalObject.TypeError("'get attr' called on an object that is not a valid instance of Global."); - } - - return esValue[implSymbol]["attr"]; - }, - set attr(V) { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - throw new globalObject.TypeError("'set attr' called on an object that is not a valid instance of Global."); - } - - V = conversions["DOMString"](V, { - context: "Failed to set the 'attr' property on 'Global': The provided value", - globals: globalObject - }); - - esValue[implSymbol]["attr"] = V; - }, - get unforgeableAttr() { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'get unforgeableAttr' called on an object that is not a valid instance of Global." - ); - } - - return esValue[implSymbol]["unforgeableAttr"]; - }, - set unforgeableAttr(V) { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'set unforgeableAttr' called on an object that is not a valid instance of Global." - ); - } - - V = conversions["DOMString"](V, { - context: "Failed to set the 'unforgeableAttr' property on 'Global': The provided value", - globals: globalObject - }); - - esValue[implSymbol]["unforgeableAttr"] = V; - }, - get length() { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - throw new globalObject.TypeError("'get length' called on an object that is not a valid instance of Global."); - } - - return esValue[implSymbol]["length"]; - }, - set length(V) { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - throw new globalObject.TypeError("'set length' called on an object that is not a valid instance of Global."); - } - - V = conversions["unsigned long"](V, { - context: "Failed to set the 'length' property on 'Global': The provided value", - globals: globalObject - }); - - esValue[implSymbol]["length"] = V; - }, - [Symbol.iterator]: globalObject.Array.prototype[Symbol.iterator], - keys: globalObject.Array.prototype.keys, - values: globalObject.Array.prototype.values, - entries: globalObject.Array.prototype.entries, - forEach: globalObject.Array.prototype.forEach - }); - - Object.defineProperties(wrapper, { - unforgeableOp: { configurable: false, writable: false }, - unforgeableAttr: { configurable: false }, - [Symbol.iterator]: { enumerable: false } - }); -}; +exports._internalSetup = (wrapper, globalObject) => {}; exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => { privateData.wrapper = wrapper; @@ -3299,7 +3297,7 @@ exports.new = (globalObject, newTarget) => { return wrapper[implSymbol]; }; -const exposed = new Set(["Global"]); +const exposed = new Set(["Window"]); exports.install = (globalObject, globalNames) => { if (!globalNames.some(globalName => exposed.has(globalName))) { @@ -3307,57 +3305,126 @@ exports.install = (globalObject, globalNames) => { } const ctorRegistry = utils.initCtorRegistry(globalObject); - class Global { + class Enum { constructor() { throw new globalObject.TypeError("Illegal constructor"); } - static staticOp() { - return Impl.implementation.staticOp(); - } - - static get staticAttr() { + op(destination) { const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError("'op' called on an object that is not a valid instance of Enum."); + } - return Impl.implementation["staticAttr"]; - } - - static set staticAttr(V) { + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'op' on 'Enum': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = RequestDestination.convert(globalObject, curArg, { + context: "Failed to execute 'op' on 'Enum': parameter 1" + }); + args.push(curArg); + } + return esValue[implSymbol].op(...args); + } + + get attr() { const esValue = this !== null && this !== undefined ? this : globalObject; - V = conversions["DOMString"](V, { - context: "Failed to set the 'staticAttr' property on 'Global': The provided value", - globals: globalObject - }); + if (!exports.is(esValue)) { + throw new globalObject.TypeError("'get attr' called on an object that is not a valid instance of Enum."); + } - Impl.implementation["staticAttr"] = V; + return utils.tryWrapperForImpl(esValue[implSymbol]["attr"]); + } + + set attr(V) { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError("'set attr' called on an object that is not a valid instance of Enum."); + } + + V = \`\${V}\`; + if (!RequestDestination.enumerationValues.has(V)) { + return; + } + + esValue[implSymbol]["attr"] = V; } } - Object.defineProperties(Global.prototype, { [Symbol.toStringTag]: { value: "Global", configurable: true } }); - Object.defineProperties(Global, { staticOp: { enumerable: true }, staticAttr: { enumerable: true } }); - ctorRegistry[interfaceName] = Global; + Object.defineProperties(Enum.prototype, { + op: { enumerable: true }, + attr: { enumerable: true }, + [Symbol.toStringTag]: { value: "Enum", configurable: true } + }); + ctorRegistry[interfaceName] = Enum; Object.defineProperty(globalObject, interfaceName, { configurable: true, writable: true, - value: Global + value: Enum }); }; -const Impl = require("../implementations/Global.js"); +const Impl = require("../implementations/Enum.js"); " `; -exports[`generation with processors HTMLCollection.webidl 1`] = ` +exports[`generation with processors EventListener.webidl 1`] = ` +""use strict"; + +const conversions = require("webidl-conversions"); +const utils = require("./utils.js"); + +exports.convert = (globalObject, value, { context = "The provided value" } = {}) => { + if (!utils.isObject(value)) { + throw new globalObject.TypeError(\`\${context} is not an object.\`); + } + + function callTheUserObjectsOperation(event) { + let thisArg = utils.tryWrapperForImpl(this); + let O = value; + let X = O; + + if (typeof O !== "function") { + X = O["handleEvent"]; + if (typeof X !== "function") { + throw new globalObject.TypeError(\`\${context} does not correctly implement EventListener.\`); + } + thisArg = O; + } + + event = utils.tryWrapperForImpl(event); + + let callResult = Reflect.apply(X, thisArg, [event]); + } + + callTheUserObjectsOperation[utils.wrapperSymbol] = value; + callTheUserObjectsOperation.objectReference = value; + + return callTheUserObjectsOperation; +}; + +exports.install = (globalObject, globalNames) => {}; +" +`; + +exports[`generation with processors EventTarget.webidl 1`] = ` ""use strict"; const conversions = require("webidl-conversions"); const utils = require("./utils.js"); +const EventListener = require("./EventListener.js"); const implSymbol = utils.implSymbol; const ctorRegistrySymbol = utils.ctorRegistrySymbol; -const interfaceName = "HTMLCollection"; +const interfaceName = "EventTarget"; exports.is = value => { return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; @@ -3369,7 +3436,7 @@ exports.convert = (globalObject, value, { context = "The provided value" } = {}) if (exports.is(value)) { return utils.implForWrapper(value); } - throw new globalObject.TypeError(\`\${context} is not of type 'HTMLCollection'.\`); + throw new globalObject.TypeError(\`\${context} is not of type 'EventTarget'.\`); }; function makeWrapper(globalObject, newTarget) { @@ -3379,21 +3446,12 @@ function makeWrapper(globalObject, newTarget) { } if (!utils.isObject(proto)) { - proto = globalObject[ctorRegistrySymbol]["HTMLCollection"].prototype; + proto = globalObject[ctorRegistrySymbol]["EventTarget"].prototype; } return Object.create(proto); } -function makeProxy(wrapper, globalObject) { - let proxyHandler = proxyHandlerCache.get(globalObject); - if (proxyHandler === undefined) { - proxyHandler = new ProxyHandler(globalObject); - proxyHandlerCache.set(globalObject, proxyHandler); - } - return new Proxy(wrapper, proxyHandler); -} - exports.create = (globalObject, constructorArgs, privateData) => { const wrapper = makeWrapper(globalObject); return exports.setup(wrapper, globalObject, constructorArgs, privateData); @@ -3415,8 +3473,6 @@ exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) configurable: true }); - wrapper = makeProxy(wrapper, globalObject); - wrapper[implSymbol][utils.wrapperSymbol] = wrapper; if (Impl.init) { Impl.init(wrapper[implSymbol]); @@ -3425,7 +3481,7 @@ exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) }; exports.new = (globalObject, newTarget) => { - let wrapper = makeWrapper(globalObject, newTarget); + const wrapper = makeWrapper(globalObject, newTarget); exports._internalSetup(wrapper, globalObject); Object.defineProperty(wrapper, implSymbol, { @@ -3433,8 +3489,6 @@ exports.new = (globalObject, newTarget) => { configurable: true }); - wrapper = makeProxy(wrapper, globalObject); - wrapper[implSymbol][utils.wrapperSymbol] = wrapper; if (Impl.init) { Impl.init(wrapper[implSymbol]); @@ -3442,7 +3496,7 @@ exports.new = (globalObject, newTarget) => { return wrapper[implSymbol]; }; -const exposed = new Set(["Window"]); +const exposed = new Set(["Window", "Worker", "AudioWorklet"]); exports.install = (globalObject, globalNames) => { if (!globalNames.some(globalName => exposed.has(globalName))) { @@ -3450,271 +3504,74 @@ exports.install = (globalObject, globalNames) => { } const ctorRegistry = utils.initCtorRegistry(globalObject); - class HTMLCollection { + class EventTarget { constructor() { - throw new globalObject.TypeError("Illegal constructor"); - } - - item(index) { - const esValue = this !== null && this !== undefined ? this : globalObject; - if (!exports.is(esValue)) { - throw new globalObject.TypeError("'item' called on an object that is not a valid instance of HTMLCollection."); - } - - if (arguments.length < 1) { - throw new globalObject.TypeError( - \`Failed to execute 'item' on 'HTMLCollection': 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 'HTMLCollection': parameter 1", - globals: globalObject - }); - args.push(curArg); - } - return utils.tryWrapperForImpl(esValue[implSymbol].item(...args)); + return exports.setup(Object.create(new.target.prototype), globalObject, undefined); } - namedItem(name) { + addEventListener(type, callback) { const esValue = this !== null && this !== undefined ? this : globalObject; if (!exports.is(esValue)) { throw new globalObject.TypeError( - "'namedItem' called on an object that is not a valid instance of HTMLCollection." + "'addEventListener' called on an object that is not a valid instance of EventTarget." ); } - if (arguments.length < 1) { + if (arguments.length < 2) { throw new globalObject.TypeError( - \`Failed to execute 'namedItem' on 'HTMLCollection': 1 argument required, but only \${arguments.length} present.\` + \`Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only \${arguments.length} present.\` ); } const args = []; { let curArg = arguments[0]; curArg = conversions["DOMString"](curArg, { - context: "Failed to execute 'namedItem' on 'HTMLCollection': parameter 1", + context: "Failed to execute 'addEventListener' on 'EventTarget': parameter 1", globals: globalObject }); args.push(curArg); } - return utils.tryWrapperForImpl(esValue[implSymbol].namedItem(...args)); - } - - get length() { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'get length' called on an object that is not a valid instance of HTMLCollection." - ); + { + let curArg = arguments[1]; + if (curArg === null || curArg === undefined) { + curArg = null; + } else { + curArg = EventListener.convert(globalObject, curArg, { + context: "Failed to execute 'addEventListener' on 'EventTarget': parameter 2" + }); + } + args.push(curArg); } - - return esValue[implSymbol]["length"]; + return esValue[implSymbol].addEventListener(...args); } } - Object.defineProperties(HTMLCollection.prototype, { - item: { enumerable: true }, - namedItem: { enumerable: true }, - length: { enumerable: true }, - [Symbol.toStringTag]: { value: "HTMLCollection", configurable: true }, - [Symbol.iterator]: { value: globalObject.Array.prototype[Symbol.iterator], configurable: true, writable: true } + Object.defineProperties(EventTarget.prototype, { + addEventListener: { enumerable: true }, + [Symbol.toStringTag]: { value: "EventTarget", configurable: true } }); - ctorRegistry[interfaceName] = HTMLCollection; + ctorRegistry[interfaceName] = EventTarget; Object.defineProperty(globalObject, interfaceName, { configurable: true, writable: true, - value: HTMLCollection + value: EventTarget }); }; -const proxyHandlerCache = new WeakMap(); -class ProxyHandler { - constructor(globalObject) { - this._globalObject = globalObject; - } - - get(target, P, receiver) { - if (typeof P === "symbol") { - return Reflect.get(target, P, receiver); - } - const desc = this.getOwnPropertyDescriptor(target, P); - if (desc === undefined) { - const parent = Object.getPrototypeOf(target); - if (parent === null) { - return undefined; - } - return Reflect.get(target, P, receiver); - } - if (!desc.get && !desc.set) { - return desc.value; - } - const getter = desc.get; - if (getter === undefined) { - return undefined; - } - return Reflect.apply(getter, receiver, []); - } +const Impl = require("../implementations/EventTarget.js"); +" +`; - has(target, P) { - if (typeof P === "symbol") { - return Reflect.has(target, P); - } - const desc = this.getOwnPropertyDescriptor(target, P); - if (desc !== undefined) { - return true; - } - const parent = Object.getPrototypeOf(target); - if (parent !== null) { - return Reflect.has(parent, P); - } - return false; - } +exports[`generation with processors Global.webidl 1`] = ` +""use strict"; - ownKeys(target) { - const keys = new Set(); +const conversions = require("webidl-conversions"); +const utils = require("./utils.js"); - for (const key of target[implSymbol][utils.supportedPropertyIndices]) { - keys.add(\`\${key}\`); - } +const implSymbol = utils.implSymbol; +const ctorRegistrySymbol = utils.ctorRegistrySymbol; - for (const key of target[implSymbol][utils.supportedPropertyNames]) { - if (!(key in target)) { - keys.add(\`\${key}\`); - } - } - - for (const key of Reflect.ownKeys(target)) { - keys.add(key); - } - return [...keys]; - } - - getOwnPropertyDescriptor(target, P) { - if (typeof P === "symbol") { - return Reflect.getOwnPropertyDescriptor(target, P); - } - let ignoreNamedProps = false; - - if (utils.isArrayIndexPropName(P)) { - const index = P >>> 0; - const indexedValue = target[implSymbol].item(index); - if (indexedValue !== null) { - return { - writable: false, - enumerable: true, - configurable: true, - value: utils.tryWrapperForImpl(indexedValue) - }; - } - ignoreNamedProps = true; - } - - const namedValue = target[implSymbol].namedItem(P); - - if (namedValue !== null && !(P in target) && !ignoreNamedProps) { - return { - writable: false, - enumerable: false, - configurable: true, - value: utils.tryWrapperForImpl(namedValue) - }; - } - - return Reflect.getOwnPropertyDescriptor(target, P); - } - - set(target, P, V, receiver) { - if (typeof P === "symbol") { - return Reflect.set(target, P, V, receiver); - } - // The \`receiver\` argument refers to the Proxy exotic object or an object - // that inherits from it, whereas \`target\` refers to the Proxy target: - if (target[implSymbol][utils.wrapperSymbol] === receiver) { - const globalObject = this._globalObject; - } - let ownDesc; - - if (utils.isArrayIndexPropName(P)) { - const index = P >>> 0; - const indexedValue = target[implSymbol].item(index); - if (indexedValue !== null) { - ownDesc = { - writable: false, - enumerable: true, - configurable: true, - value: utils.tryWrapperForImpl(indexedValue) - }; - } - } - - if (ownDesc === undefined) { - ownDesc = Reflect.getOwnPropertyDescriptor(target, P); - } - return utils.ordinarySetWithOwnDescriptor(target, P, V, receiver, ownDesc); - } - - defineProperty(target, P, desc) { - if (typeof P === "symbol") { - return Reflect.defineProperty(target, P, desc); - } - - const globalObject = this._globalObject; - - if (utils.isArrayIndexPropName(P)) { - return false; - } - if (!Object.hasOwn(target, P)) { - const creating = !(target[implSymbol].namedItem(P) !== null); - if (!creating) { - return false; - } - } - return Reflect.defineProperty(target, P, desc); - } - - deleteProperty(target, P) { - if (typeof P === "symbol") { - return Reflect.deleteProperty(target, P); - } - - const globalObject = this._globalObject; - - if (utils.isArrayIndexPropName(P)) { - const index = P >>> 0; - return !(target[implSymbol].item(index) !== null); - } - - if (target[implSymbol].namedItem(P) !== null && !(P in target)) { - return false; - } - - return Reflect.deleteProperty(target, P); - } - - preventExtensions() { - return false; - } -} - -const Impl = require("../implementations/HTMLCollection.js"); -" -`; - -exports[`generation with processors HTMLConstructor.webidl 1`] = ` -""use strict"; - -const conversions = require("webidl-conversions"); -const utils = require("./utils.js"); - -const HTMLConstructor_HTMLConstructor = require("../HTMLConstructor.js").HTMLConstructor; -const implSymbol = utils.implSymbol; -const ctorRegistrySymbol = utils.ctorRegistrySymbol; - -const interfaceName = "HTMLConstructor"; +const interfaceName = "Global"; exports.is = value => { return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; @@ -3726,7 +3583,7 @@ exports.convert = (globalObject, value, { context = "The provided value" } = {}) if (exports.is(value)) { return utils.implForWrapper(value); } - throw new globalObject.TypeError(\`\${context} is not of type 'HTMLConstructor'.\`); + throw new globalObject.TypeError(\`\${context} is not of type 'Global'.\`); }; function makeWrapper(globalObject, newTarget) { @@ -3736,7 +3593,7 @@ function makeWrapper(globalObject, newTarget) { } if (!utils.isObject(proto)) { - proto = globalObject[ctorRegistrySymbol]["HTMLConstructor"].prototype; + proto = globalObject[ctorRegistrySymbol]["Global"].prototype; } return Object.create(proto); @@ -3752,7 +3609,110 @@ exports.createImpl = (globalObject, constructorArgs, privateData) => { return utils.implForWrapper(wrapper); }; -exports._internalSetup = (wrapper, globalObject) => {}; +exports._internalSetup = (wrapper, globalObject) => { + utils.define(wrapper, { + op() { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError("'op' called on an object that is not a valid instance of Global."); + } + + return esValue[implSymbol].op(); + }, + unforgeableOp() { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError("'unforgeableOp' called on an object that is not a valid instance of Global."); + } + + return esValue[implSymbol].unforgeableOp(); + }, + get attr() { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError("'get attr' called on an object that is not a valid instance of Global."); + } + + return esValue[implSymbol]["attr"]; + }, + set attr(V) { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError("'set attr' called on an object that is not a valid instance of Global."); + } + + V = conversions["DOMString"](V, { + context: "Failed to set the 'attr' property on 'Global': The provided value", + globals: globalObject + }); + + esValue[implSymbol]["attr"] = V; + }, + get unforgeableAttr() { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'get unforgeableAttr' called on an object that is not a valid instance of Global." + ); + } + + return esValue[implSymbol]["unforgeableAttr"]; + }, + set unforgeableAttr(V) { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'set unforgeableAttr' called on an object that is not a valid instance of Global." + ); + } + + V = conversions["DOMString"](V, { + context: "Failed to set the 'unforgeableAttr' property on 'Global': The provided value", + globals: globalObject + }); + + esValue[implSymbol]["unforgeableAttr"] = V; + }, + get length() { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError("'get length' called on an object that is not a valid instance of Global."); + } + + return esValue[implSymbol]["length"]; + }, + set length(V) { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError("'set length' called on an object that is not a valid instance of Global."); + } + + V = conversions["unsigned long"](V, { + context: "Failed to set the 'length' property on 'Global': The provided value", + globals: globalObject + }); + + esValue[implSymbol]["length"] = V; + }, + [Symbol.iterator]: globalObject.Array.prototype[Symbol.iterator], + keys: globalObject.Array.prototype.keys, + values: globalObject.Array.prototype.values, + entries: globalObject.Array.prototype.entries, + forEach: globalObject.Array.prototype.forEach + }); + + Object.defineProperties(wrapper, { + unforgeableOp: { configurable: false, writable: false }, + unforgeableAttr: { configurable: false }, + [Symbol.iterator]: { enumerable: false } + }); +}; exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => { privateData.wrapper = wrapper; @@ -3786,7 +3746,7 @@ exports.new = (globalObject, newTarget) => { return wrapper[implSymbol]; }; -const exposed = new Set(["Window"]); +const exposed = new Set(["Global"]); exports.install = (globalObject, globalNames) => { if (!globalNames.some(globalName => exposed.has(globalName))) { @@ -3794,28 +3754,48 @@ exports.install = (globalObject, globalNames) => { } const ctorRegistry = utils.initCtorRegistry(globalObject); - class HTMLConstructor { + class Global { constructor() { - return HTMLConstructor_HTMLConstructor(globalObject, interfaceName); + throw new globalObject.TypeError("Illegal constructor"); } - } - Object.defineProperties(HTMLConstructor.prototype, { - [Symbol.toStringTag]: { value: "HTMLConstructor", configurable: true } - }); - ctorRegistry[interfaceName] = HTMLConstructor; - Object.defineProperty(globalObject, interfaceName, { - configurable: true, - writable: true, - value: HTMLConstructor - }); -}; + static staticOp() { + return Impl.implementation.staticOp(); + } -const Impl = require("../implementations/HTMLConstructor.js"); + static get staticAttr() { + const esValue = this !== null && this !== undefined ? this : globalObject; + + return Impl.implementation["staticAttr"]; + } + + static set staticAttr(V) { + const esValue = this !== null && this !== undefined ? this : globalObject; + + V = conversions["DOMString"](V, { + context: "Failed to set the 'staticAttr' property on 'Global': The provided value", + globals: globalObject + }); + + Impl.implementation["staticAttr"] = V; + } + } + Object.defineProperties(Global.prototype, { [Symbol.toStringTag]: { value: "Global", configurable: true } }); + Object.defineProperties(Global, { staticOp: { enumerable: true }, staticAttr: { enumerable: true } }); + ctorRegistry[interfaceName] = Global; + + Object.defineProperty(globalObject, interfaceName, { + configurable: true, + writable: true, + value: Global + }); +}; + +const Impl = require("../implementations/Global.js"); " `; -exports[`generation with processors HTMLFormControlsCollection.webidl 1`] = ` +exports[`generation with processors HTMLCollection.webidl 1`] = ` ""use strict"; const conversions = require("webidl-conversions"); @@ -3823,9 +3803,8 @@ const utils = require("./utils.js"); const implSymbol = utils.implSymbol; const ctorRegistrySymbol = utils.ctorRegistrySymbol; -const HTMLCollection = require("./HTMLCollection.js"); -const interfaceName = "HTMLFormControlsCollection"; +const interfaceName = "HTMLCollection"; exports.is = value => { return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; @@ -3837,7 +3816,7 @@ exports.convert = (globalObject, value, { context = "The provided value" } = {}) if (exports.is(value)) { return utils.implForWrapper(value); } - throw new globalObject.TypeError(\`\${context} is not of type 'HTMLFormControlsCollection'.\`); + throw new globalObject.TypeError(\`\${context} is not of type 'HTMLCollection'.\`); }; function makeWrapper(globalObject, newTarget) { @@ -3847,7 +3826,7 @@ function makeWrapper(globalObject, newTarget) { } if (!utils.isObject(proto)) { - proto = globalObject[ctorRegistrySymbol]["HTMLFormControlsCollection"].prototype; + proto = globalObject[ctorRegistrySymbol]["HTMLCollection"].prototype; } return Object.create(proto); @@ -3872,9 +3851,7 @@ exports.createImpl = (globalObject, constructorArgs, privateData) => { return utils.implForWrapper(wrapper); }; -exports._internalSetup = (wrapper, globalObject) => { - HTMLCollection._internalSetup(wrapper, globalObject); -}; +exports._internalSetup = (wrapper, globalObject) => {}; exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => { privateData.wrapper = wrapper; @@ -3920,47 +3897,84 @@ exports.install = (globalObject, globalNames) => { } const ctorRegistry = utils.initCtorRegistry(globalObject); - class HTMLFormControlsCollection extends globalObject.HTMLCollection { + class HTMLCollection { constructor() { throw new globalObject.TypeError("Illegal constructor"); } + item(index) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError("'item' called on an object that is not a valid instance of HTMLCollection."); + } + + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'item' on 'HTMLCollection': 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 'HTMLCollection': parameter 1", + globals: globalObject + }); + args.push(curArg); + } + return utils.tryWrapperForImpl(esValue[implSymbol].item(...args)); + } + namedItem(name) { const esValue = this !== null && this !== undefined ? this : globalObject; if (!exports.is(esValue)) { throw new globalObject.TypeError( - "'namedItem' called on an object that is not a valid instance of HTMLFormControlsCollection." + "'namedItem' called on an object that is not a valid instance of HTMLCollection." ); } if (arguments.length < 1) { throw new globalObject.TypeError( - \`Failed to execute 'namedItem' on 'HTMLFormControlsCollection': 1 argument required, but only \${arguments.length} present.\` + \`Failed to execute 'namedItem' on 'HTMLCollection': 1 argument required, but only \${arguments.length} present.\` ); } const args = []; { let curArg = arguments[0]; curArg = conversions["DOMString"](curArg, { - context: "Failed to execute 'namedItem' on 'HTMLFormControlsCollection': parameter 1", + context: "Failed to execute 'namedItem' on 'HTMLCollection': parameter 1", globals: globalObject }); args.push(curArg); } return utils.tryWrapperForImpl(esValue[implSymbol].namedItem(...args)); } + + get length() { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'get length' called on an object that is not a valid instance of HTMLCollection." + ); + } + + return esValue[implSymbol]["length"]; + } } - Object.defineProperties(HTMLFormControlsCollection.prototype, { + Object.defineProperties(HTMLCollection.prototype, { + item: { enumerable: true }, namedItem: { enumerable: true }, - [Symbol.toStringTag]: { value: "HTMLFormControlsCollection", configurable: true }, + length: { enumerable: true }, + [Symbol.toStringTag]: { value: "HTMLCollection", configurable: true }, [Symbol.iterator]: { value: globalObject.Array.prototype[Symbol.iterator], configurable: true, writable: true } }); - ctorRegistry[interfaceName] = HTMLFormControlsCollection; + ctorRegistry[interfaceName] = HTMLCollection; Object.defineProperty(globalObject, interfaceName, { configurable: true, writable: true, - value: HTMLFormControlsCollection + value: HTMLCollection }); }; @@ -4051,7 +4065,7 @@ class ProxyHandler { if (namedValue !== null && !(P in target) && !ignoreNamedProps) { return { writable: false, - enumerable: true, + enumerable: false, configurable: true, value: utils.tryWrapperForImpl(namedValue) }; @@ -4133,20 +4147,21 @@ class ProxyHandler { } } -const Impl = require("../implementations/HTMLFormControlsCollection.js"); +const Impl = require("../implementations/HTMLCollection.js"); " `; -exports[`generation with processors LegacyLenientAttributes.webidl 1`] = ` +exports[`generation with processors HTMLConstructor.webidl 1`] = ` ""use strict"; const conversions = require("webidl-conversions"); const utils = require("./utils.js"); +const HTMLConstructor_HTMLConstructor = require("../HTMLConstructor.js").HTMLConstructor; const implSymbol = utils.implSymbol; const ctorRegistrySymbol = utils.ctorRegistrySymbol; -const interfaceName = "LegacyLenientAttributes"; +const interfaceName = "HTMLConstructor"; exports.is = value => { return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; @@ -4158,7 +4173,7 @@ exports.convert = (globalObject, value, { context = "The provided value" } = {}) if (exports.is(value)) { return utils.implForWrapper(value); } - throw new globalObject.TypeError(\`\${context} is not of type 'LegacyLenientAttributes'.\`); + throw new globalObject.TypeError(\`\${context} is not of type 'HTMLConstructor'.\`); }; function makeWrapper(globalObject, newTarget) { @@ -4168,7 +4183,7 @@ function makeWrapper(globalObject, newTarget) { } if (!utils.isObject(proto)) { - proto = globalObject[ctorRegistrySymbol]["LegacyLenientAttributes"].prototype; + proto = globalObject[ctorRegistrySymbol]["HTMLConstructor"].prototype; } return Object.create(proto); @@ -4226,123 +4241,28 @@ exports.install = (globalObject, globalNames) => { } const ctorRegistry = utils.initCtorRegistry(globalObject); - class LegacyLenientAttributes { + class HTMLConstructor { constructor() { - throw new globalObject.TypeError("Illegal constructor"); - } - - get lenientSetter() { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'get lenientSetter' called on an object that is not a valid instance of LegacyLenientAttributes." - ); - } - - return esValue[implSymbol]["lenientSetter"]; - } - - set lenientSetter(V) { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'set lenientSetter' called on an object that is not a valid instance of LegacyLenientAttributes." - ); - } - } - - get lenientThisSetter() { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - return; - } - - return esValue[implSymbol]["lenientThisSetter"]; - } - - set lenientThisSetter(V) {} - - get lenientThis() { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - return; - } - - return esValue[implSymbol]["lenientThis"]; - } - - set lenientThis(V) { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - return; - } - - V = conversions["DOMString"](V, { - context: "Failed to set the 'lenientThis' property on 'LegacyLenientAttributes': The provided value", - globals: globalObject - }); - - esValue[implSymbol]["lenientThis"] = V; - } - - get readonlyLenientThis() { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - return; - } - - return esValue[implSymbol]["readonlyLenientThis"]; - } - - get replaceableLenientThis() { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - return; - } - - return esValue[implSymbol]["replaceableLenientThis"]; - } - - set replaceableLenientThis(V) { - const esValue = this !== null && this !== undefined ? this : globalObject; - - Object.defineProperty(esValue, "replaceableLenientThis", { - configurable: true, - enumerable: true, - value: V, - writable: true - }); + return HTMLConstructor_HTMLConstructor(globalObject, interfaceName); } } - Object.defineProperties(LegacyLenientAttributes.prototype, { - lenientSetter: { enumerable: true }, - lenientThisSetter: { enumerable: true }, - lenientThis: { enumerable: true }, - readonlyLenientThis: { enumerable: true }, - replaceableLenientThis: { enumerable: true }, - [Symbol.toStringTag]: { value: "LegacyLenientAttributes", configurable: true } + Object.defineProperties(HTMLConstructor.prototype, { + [Symbol.toStringTag]: { value: "HTMLConstructor", configurable: true } }); - ctorRegistry[interfaceName] = LegacyLenientAttributes; + ctorRegistry[interfaceName] = HTMLConstructor; Object.defineProperty(globalObject, interfaceName, { configurable: true, writable: true, - value: LegacyLenientAttributes + value: HTMLConstructor }); }; -const Impl = require("../implementations/LegacyLenientAttributes.js"); +const Impl = require("../implementations/HTMLConstructor.js"); " `; -exports[`generation with processors LegacyNoInterfaceObject.webidl 1`] = ` +exports[`generation with processors HTMLFormControlsCollection.webidl 1`] = ` ""use strict"; const conversions = require("webidl-conversions"); @@ -4350,8 +4270,9 @@ const utils = require("./utils.js"); const implSymbol = utils.implSymbol; const ctorRegistrySymbol = utils.ctorRegistrySymbol; +const HTMLCollection = require("./HTMLCollection.js"); -const interfaceName = "LegacyNoInterfaceObject"; +const interfaceName = "HTMLFormControlsCollection"; exports.is = value => { return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; @@ -4363,7 +4284,7 @@ exports.convert = (globalObject, value, { context = "The provided value" } = {}) if (exports.is(value)) { return utils.implForWrapper(value); } - throw new globalObject.TypeError(\`\${context} is not of type 'LegacyNoInterfaceObject'.\`); + throw new globalObject.TypeError(\`\${context} is not of type 'HTMLFormControlsCollection'.\`); }; function makeWrapper(globalObject, newTarget) { @@ -4373,12 +4294,21 @@ function makeWrapper(globalObject, newTarget) { } if (!utils.isObject(proto)) { - proto = globalObject[ctorRegistrySymbol]["LegacyNoInterfaceObject"].prototype; + proto = globalObject[ctorRegistrySymbol]["HTMLFormControlsCollection"].prototype; } return Object.create(proto); } +function makeProxy(wrapper, globalObject) { + let proxyHandler = proxyHandlerCache.get(globalObject); + if (proxyHandler === undefined) { + proxyHandler = new ProxyHandler(globalObject); + proxyHandlerCache.set(globalObject, proxyHandler); + } + return new Proxy(wrapper, proxyHandler); +} + exports.create = (globalObject, constructorArgs, privateData) => { const wrapper = makeWrapper(globalObject); return exports.setup(wrapper, globalObject, constructorArgs, privateData); @@ -4389,7 +4319,9 @@ exports.createImpl = (globalObject, constructorArgs, privateData) => { return utils.implForWrapper(wrapper); }; -exports._internalSetup = (wrapper, globalObject) => {}; +exports._internalSetup = (wrapper, globalObject) => { + HTMLCollection._internalSetup(wrapper, globalObject); +}; exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => { privateData.wrapper = wrapper; @@ -4400,6 +4332,8 @@ exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) configurable: true }); + wrapper = makeProxy(wrapper, globalObject); + wrapper[implSymbol][utils.wrapperSymbol] = wrapper; if (Impl.init) { Impl.init(wrapper[implSymbol]); @@ -4408,7 +4342,7 @@ exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) }; exports.new = (globalObject, newTarget) => { - const wrapper = makeWrapper(globalObject, newTarget); + let wrapper = makeWrapper(globalObject, newTarget); exports._internalSetup(wrapper, globalObject); Object.defineProperty(wrapper, implSymbol, { @@ -4416,6 +4350,8 @@ exports.new = (globalObject, newTarget) => { configurable: true }); + wrapper = makeProxy(wrapper, globalObject); + wrapper[implSymbol][utils.wrapperSymbol] = wrapper; if (Impl.init) { Impl.init(wrapper[implSymbol]); @@ -4431,65 +4367,224 @@ exports.install = (globalObject, globalNames) => { } const ctorRegistry = utils.initCtorRegistry(globalObject); - class LegacyNoInterfaceObject { + class HTMLFormControlsCollection extends globalObject.HTMLCollection { constructor() { throw new globalObject.TypeError("Illegal constructor"); } - def() { + namedItem(name) { const esValue = this !== null && this !== undefined ? this : globalObject; if (!exports.is(esValue)) { throw new globalObject.TypeError( - "'def' called on an object that is not a valid instance of LegacyNoInterfaceObject." + "'namedItem' called on an object that is not a valid instance of HTMLFormControlsCollection." ); } - return esValue[implSymbol].def(); - } - - get abc() { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { + if (arguments.length < 1) { throw new globalObject.TypeError( - "'get abc' called on an object that is not a valid instance of LegacyNoInterfaceObject." + \`Failed to execute 'namedItem' on 'HTMLFormControlsCollection': 1 argument required, but only \${arguments.length} present.\` ); } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions["DOMString"](curArg, { + context: "Failed to execute 'namedItem' on 'HTMLFormControlsCollection': parameter 1", + globals: globalObject + }); + args.push(curArg); + } + return utils.tryWrapperForImpl(esValue[implSymbol].namedItem(...args)); + } + } + Object.defineProperties(HTMLFormControlsCollection.prototype, { + namedItem: { enumerable: true }, + [Symbol.toStringTag]: { value: "HTMLFormControlsCollection", configurable: true }, + [Symbol.iterator]: { value: globalObject.Array.prototype[Symbol.iterator], configurable: true, writable: true } + }); + ctorRegistry[interfaceName] = HTMLFormControlsCollection; - return esValue[implSymbol]["abc"]; + Object.defineProperty(globalObject, interfaceName, { + configurable: true, + writable: true, + value: HTMLFormControlsCollection + }); +}; + +const proxyHandlerCache = new WeakMap(); +class ProxyHandler { + constructor(globalObject) { + this._globalObject = globalObject; + } + + get(target, P, receiver) { + if (typeof P === "symbol") { + return Reflect.get(target, P, receiver); + } + const desc = this.getOwnPropertyDescriptor(target, P); + if (desc === undefined) { + const parent = Object.getPrototypeOf(target); + if (parent === null) { + return undefined; + } + return Reflect.get(target, P, receiver); + } + if (!desc.get && !desc.set) { + return desc.value; + } + const getter = desc.get; + if (getter === undefined) { + return undefined; } + return Reflect.apply(getter, receiver, []); + } - set abc(V) { - const esValue = this !== null && this !== undefined ? this : globalObject; + has(target, P) { + if (typeof P === "symbol") { + return Reflect.has(target, P); + } + const desc = this.getOwnPropertyDescriptor(target, P); + if (desc !== undefined) { + return true; + } + const parent = Object.getPrototypeOf(target); + if (parent !== null) { + return Reflect.has(parent, P); + } + return false; + } - if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'set abc' called on an object that is not a valid instance of LegacyNoInterfaceObject." - ); + ownKeys(target) { + const keys = new Set(); + + for (const key of target[implSymbol][utils.supportedPropertyIndices]) { + keys.add(\`\${key}\`); + } + + for (const key of target[implSymbol][utils.supportedPropertyNames]) { + if (!(key in target)) { + keys.add(\`\${key}\`); } + } - V = conversions["DOMString"](V, { - context: "Failed to set the 'abc' property on 'LegacyNoInterfaceObject': The provided value", - globals: globalObject - }); + for (const key of Reflect.ownKeys(target)) { + keys.add(key); + } + return [...keys]; + } - esValue[implSymbol]["abc"] = V; + getOwnPropertyDescriptor(target, P) { + if (typeof P === "symbol") { + return Reflect.getOwnPropertyDescriptor(target, P); + } + let ignoreNamedProps = false; + + if (utils.isArrayIndexPropName(P)) { + const index = P >>> 0; + const indexedValue = target[implSymbol].item(index); + if (indexedValue !== null) { + return { + writable: false, + enumerable: true, + configurable: true, + value: utils.tryWrapperForImpl(indexedValue) + }; + } + ignoreNamedProps = true; + } + + const namedValue = target[implSymbol].namedItem(P); + + if (namedValue !== null && !(P in target) && !ignoreNamedProps) { + return { + writable: false, + enumerable: true, + configurable: true, + value: utils.tryWrapperForImpl(namedValue) + }; } + + return Reflect.getOwnPropertyDescriptor(target, P); } - delete LegacyNoInterfaceObject.constructor; - Object.defineProperties(LegacyNoInterfaceObject.prototype, { - def: { enumerable: true }, - abc: { enumerable: true }, - [Symbol.toStringTag]: { value: "LegacyNoInterfaceObject", configurable: true } - }); - ctorRegistry[interfaceName] = LegacyNoInterfaceObject; -}; -const Impl = require("../implementations/LegacyNoInterfaceObject.js"); + set(target, P, V, receiver) { + if (typeof P === "symbol") { + return Reflect.set(target, P, V, receiver); + } + // The \`receiver\` argument refers to the Proxy exotic object or an object + // that inherits from it, whereas \`target\` refers to the Proxy target: + if (target[implSymbol][utils.wrapperSymbol] === receiver) { + const globalObject = this._globalObject; + } + let ownDesc; + + if (utils.isArrayIndexPropName(P)) { + const index = P >>> 0; + const indexedValue = target[implSymbol].item(index); + if (indexedValue !== null) { + ownDesc = { + writable: false, + enumerable: true, + configurable: true, + value: utils.tryWrapperForImpl(indexedValue) + }; + } + } + + if (ownDesc === undefined) { + ownDesc = Reflect.getOwnPropertyDescriptor(target, P); + } + return utils.ordinarySetWithOwnDescriptor(target, P, V, receiver, ownDesc); + } + + defineProperty(target, P, desc) { + if (typeof P === "symbol") { + return Reflect.defineProperty(target, P, desc); + } + + const globalObject = this._globalObject; + + if (utils.isArrayIndexPropName(P)) { + return false; + } + if (!Object.hasOwn(target, P)) { + const creating = !(target[implSymbol].namedItem(P) !== null); + if (!creating) { + return false; + } + } + return Reflect.defineProperty(target, P, desc); + } + + deleteProperty(target, P) { + if (typeof P === "symbol") { + return Reflect.deleteProperty(target, P); + } + + const globalObject = this._globalObject; + + if (utils.isArrayIndexPropName(P)) { + const index = P >>> 0; + return !(target[implSymbol].item(index) !== null); + } + + if (target[implSymbol].namedItem(P) !== null && !(P in target)) { + return false; + } + + return Reflect.deleteProperty(target, P); + } + + preventExtensions() { + return false; + } +} + +const Impl = require("../implementations/HTMLFormControlsCollection.js"); " `; -exports[`generation with processors LegacyUnforgeable.webidl 1`] = ` +exports[`generation with processors LegacyLenientAttributes.webidl 1`] = ` ""use strict"; const conversions = require("webidl-conversions"); @@ -4498,7 +4593,7 @@ const utils = require("./utils.js"); const implSymbol = utils.implSymbol; const ctorRegistrySymbol = utils.ctorRegistrySymbol; -const interfaceName = "LegacyUnforgeable"; +const interfaceName = "LegacyLenientAttributes"; exports.is = value => { return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; @@ -4510,7 +4605,7 @@ exports.convert = (globalObject, value, { context = "The provided value" } = {}) if (exports.is(value)) { return utils.implForWrapper(value); } - throw new globalObject.TypeError(\`\${context} is not of type 'LegacyUnforgeable'.\`); + throw new globalObject.TypeError(\`\${context} is not of type 'LegacyLenientAttributes'.\`); }; function makeWrapper(globalObject, newTarget) { @@ -4520,7 +4615,7 @@ function makeWrapper(globalObject, newTarget) { } if (!utils.isObject(proto)) { - proto = globalObject[ctorRegistrySymbol]["LegacyUnforgeable"].prototype; + proto = globalObject[ctorRegistrySymbol]["LegacyLenientAttributes"].prototype; } return Object.create(proto); @@ -4536,129 +4631,10 @@ exports.createImpl = (globalObject, constructorArgs, privateData) => { return utils.implForWrapper(wrapper); }; -function getUnforgeables(globalObject) { - let unforgeables = unforgeablesMap.get(globalObject); - if (unforgeables === undefined) { - unforgeables = Object.create(null); - utils.define(unforgeables, { - assign(url) { - const esValue = this !== null && this !== undefined ? this : globalObject; - if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'assign' called on an object that is not a valid instance of LegacyUnforgeable." - ); - } +exports._internalSetup = (wrapper, globalObject) => {}; - if (arguments.length < 1) { - throw new globalObject.TypeError( - \`Failed to execute 'assign' on 'LegacyUnforgeable': 1 argument required, but only \${arguments.length} present.\` - ); - } - const args = []; - { - let curArg = arguments[0]; - curArg = conversions["USVString"](curArg, { - context: "Failed to execute 'assign' on 'LegacyUnforgeable': parameter 1", - globals: globalObject - }); - args.push(curArg); - } - return esValue[implSymbol].assign(...args); - }, - get href() { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'get href' called on an object that is not a valid instance of LegacyUnforgeable." - ); - } - - return esValue[implSymbol]["href"]; - }, - set href(V) { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'set href' called on an object that is not a valid instance of LegacyUnforgeable." - ); - } - - V = conversions["USVString"](V, { - context: "Failed to set the 'href' property on 'LegacyUnforgeable': The provided value", - globals: globalObject - }); - - esValue[implSymbol]["href"] = V; - }, - toString() { - const esValue = this; - if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'toString' called on an object that is not a valid instance of LegacyUnforgeable." - ); - } - - return esValue[implSymbol]["href"]; - }, - get origin() { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'get origin' called on an object that is not a valid instance of LegacyUnforgeable." - ); - } - - return esValue[implSymbol]["origin"]; - }, - get protocol() { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'get protocol' called on an object that is not a valid instance of LegacyUnforgeable." - ); - } - - return esValue[implSymbol]["protocol"]; - }, - set protocol(V) { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'set protocol' called on an object that is not a valid instance of LegacyUnforgeable." - ); - } - - V = conversions["USVString"](V, { - context: "Failed to set the 'protocol' property on 'LegacyUnforgeable': The provided value", - globals: globalObject - }); - - esValue[implSymbol]["protocol"] = V; - } - }); - Object.defineProperties(unforgeables, { - assign: { configurable: false, writable: false }, - href: { configurable: false }, - toString: { configurable: false, writable: false }, - origin: { configurable: false }, - protocol: { configurable: false } - }); - unforgeablesMap.set(globalObject, unforgeables); - } - return unforgeables; -} - -exports._internalSetup = (wrapper, globalObject) => { - utils.define(wrapper, getUnforgeables(globalObject)); -}; - -exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => { - privateData.wrapper = wrapper; +exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => { + privateData.wrapper = wrapper; exports._internalSetup(wrapper, globalObject); Object.defineProperty(wrapper, implSymbol, { @@ -4689,7 +4665,6 @@ exports.new = (globalObject, newTarget) => { return wrapper[implSymbol]; }; -const unforgeablesMap = new WeakMap(); const exposed = new Set(["Window"]); exports.install = (globalObject, globalNames) => { @@ -4698,28 +4673,123 @@ exports.install = (globalObject, globalNames) => { } const ctorRegistry = utils.initCtorRegistry(globalObject); - class LegacyUnforgeable { + class LegacyLenientAttributes { constructor() { throw new globalObject.TypeError("Illegal constructor"); } + + get lenientSetter() { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'get lenientSetter' called on an object that is not a valid instance of LegacyLenientAttributes." + ); + } + + return esValue[implSymbol]["lenientSetter"]; + } + + set lenientSetter(V) { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'set lenientSetter' called on an object that is not a valid instance of LegacyLenientAttributes." + ); + } + } + + get lenientThisSetter() { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + return; + } + + return esValue[implSymbol]["lenientThisSetter"]; + } + + set lenientThisSetter(V) {} + + get lenientThis() { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + return; + } + + return esValue[implSymbol]["lenientThis"]; + } + + set lenientThis(V) { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + return; + } + + V = conversions["DOMString"](V, { + context: "Failed to set the 'lenientThis' property on 'LegacyLenientAttributes': The provided value", + globals: globalObject + }); + + esValue[implSymbol]["lenientThis"] = V; + } + + get readonlyLenientThis() { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + return; + } + + return esValue[implSymbol]["readonlyLenientThis"]; + } + + get replaceableLenientThis() { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + return; + } + + return esValue[implSymbol]["replaceableLenientThis"]; + } + + set replaceableLenientThis(V) { + const esValue = this !== null && this !== undefined ? this : globalObject; + + Object.defineProperty(esValue, "replaceableLenientThis", { + configurable: true, + enumerable: true, + value: V, + writable: true + }); + } } - Object.defineProperties(LegacyUnforgeable.prototype, { - [Symbol.toStringTag]: { value: "LegacyUnforgeable", configurable: true } + Object.defineProperties(LegacyLenientAttributes.prototype, { + lenientSetter: { enumerable: true }, + lenientThisSetter: { enumerable: true }, + lenientThis: { enumerable: true }, + readonlyLenientThis: { enumerable: true }, + replaceableLenientThis: { enumerable: true }, + [Symbol.toStringTag]: { value: "LegacyLenientAttributes", configurable: true } }); - ctorRegistry[interfaceName] = LegacyUnforgeable; + ctorRegistry[interfaceName] = LegacyLenientAttributes; Object.defineProperty(globalObject, interfaceName, { configurable: true, writable: true, - value: LegacyUnforgeable + value: LegacyLenientAttributes }); }; -const Impl = require("../implementations/LegacyUnforgeable.js"); +const Impl = require("../implementations/LegacyLenientAttributes.js"); " `; -exports[`generation with processors LegacyUnforgeableMap.webidl 1`] = ` +exports[`generation with processors LegacyNoInterfaceObject.webidl 1`] = ` ""use strict"; const conversions = require("webidl-conversions"); @@ -4728,7 +4798,7 @@ const utils = require("./utils.js"); const implSymbol = utils.implSymbol; const ctorRegistrySymbol = utils.ctorRegistrySymbol; -const interfaceName = "LegacyUnforgeableMap"; +const interfaceName = "LegacyNoInterfaceObject"; exports.is = value => { return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; @@ -4740,7 +4810,7 @@ exports.convert = (globalObject, value, { context = "The provided value" } = {}) if (exports.is(value)) { return utils.implForWrapper(value); } - throw new globalObject.TypeError(\`\${context} is not of type 'LegacyUnforgeableMap'.\`); + throw new globalObject.TypeError(\`\${context} is not of type 'LegacyNoInterfaceObject'.\`); }; function makeWrapper(globalObject, newTarget) { @@ -4750,21 +4820,12 @@ function makeWrapper(globalObject, newTarget) { } if (!utils.isObject(proto)) { - proto = globalObject[ctorRegistrySymbol]["LegacyUnforgeableMap"].prototype; + proto = globalObject[ctorRegistrySymbol]["LegacyNoInterfaceObject"].prototype; } return Object.create(proto); } -function makeProxy(wrapper, globalObject) { - let proxyHandler = proxyHandlerCache.get(globalObject); - if (proxyHandler === undefined) { - proxyHandler = new ProxyHandler(globalObject); - proxyHandlerCache.set(globalObject, proxyHandler); - } - return new Proxy(wrapper, proxyHandler); -} - exports.create = (globalObject, constructorArgs, privateData) => { const wrapper = makeWrapper(globalObject); return exports.setup(wrapper, globalObject, constructorArgs, privateData); @@ -4775,34 +4836,7 @@ exports.createImpl = (globalObject, constructorArgs, privateData) => { return utils.implForWrapper(wrapper); }; -function getUnforgeables(globalObject) { - let unforgeables = unforgeablesMap.get(globalObject); - if (unforgeables === undefined) { - unforgeables = Object.create(null); - utils.define(unforgeables, { - get a() { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'get a' called on an object that is not a valid instance of LegacyUnforgeableMap." - ); - } - - return esValue[implSymbol]["a"]; - } - }); - Object.defineProperties(unforgeables, { - a: { configurable: false } - }); - unforgeablesMap.set(globalObject, unforgeables); - } - return unforgeables; -} - -exports._internalSetup = (wrapper, globalObject) => { - utils.define(wrapper, getUnforgeables(globalObject)); -}; +exports._internalSetup = (wrapper, globalObject) => {}; exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => { privateData.wrapper = wrapper; @@ -4813,8 +4847,6 @@ exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) configurable: true }); - wrapper = makeProxy(wrapper, globalObject); - wrapper[implSymbol][utils.wrapperSymbol] = wrapper; if (Impl.init) { Impl.init(wrapper[implSymbol]); @@ -4823,7 +4855,7 @@ exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) }; exports.new = (globalObject, newTarget) => { - let wrapper = makeWrapper(globalObject, newTarget); + const wrapper = makeWrapper(globalObject, newTarget); exports._internalSetup(wrapper, globalObject); Object.defineProperty(wrapper, implSymbol, { @@ -4831,8 +4863,6 @@ exports.new = (globalObject, newTarget) => { configurable: true }); - wrapper = makeProxy(wrapper, globalObject); - wrapper[implSymbol][utils.wrapperSymbol] = wrapper; if (Impl.init) { Impl.init(wrapper[implSymbol]); @@ -4840,7 +4870,6 @@ exports.new = (globalObject, newTarget) => { return wrapper[implSymbol]; }; -const unforgeablesMap = new WeakMap(); const exposed = new Set(["Window"]); exports.install = (globalObject, globalNames) => { @@ -4849,192 +4878,65 @@ exports.install = (globalObject, globalNames) => { } const ctorRegistry = utils.initCtorRegistry(globalObject); - class LegacyUnforgeableMap { + class LegacyNoInterfaceObject { constructor() { throw new globalObject.TypeError("Illegal constructor"); } - } - Object.defineProperties(LegacyUnforgeableMap.prototype, { - [Symbol.toStringTag]: { value: "LegacyUnforgeableMap", configurable: true } - }); - ctorRegistry[interfaceName] = LegacyUnforgeableMap; - - Object.defineProperty(globalObject, interfaceName, { - configurable: true, - writable: true, - value: LegacyUnforgeableMap - }); -}; - -const proxyHandlerCache = new WeakMap(); -class ProxyHandler { - constructor(globalObject) { - this._globalObject = globalObject; - } - - get(target, P, receiver) { - if (typeof P === "symbol") { - return Reflect.get(target, P, receiver); - } - const desc = this.getOwnPropertyDescriptor(target, P); - if (desc === undefined) { - const parent = Object.getPrototypeOf(target); - if (parent === null) { - return undefined; - } - return Reflect.get(target, P, receiver); - } - if (!desc.get && !desc.set) { - return desc.value; - } - const getter = desc.get; - if (getter === undefined) { - return undefined; - } - return Reflect.apply(getter, receiver, []); - } - - has(target, P) { - if (typeof P === "symbol") { - return Reflect.has(target, P); - } - const desc = this.getOwnPropertyDescriptor(target, P); - if (desc !== undefined) { - return true; - } - const parent = Object.getPrototypeOf(target); - if (parent !== null) { - return Reflect.has(parent, P); - } - return false; - } - ownKeys(target) { - const keys = new Set(); - - for (const key of target[implSymbol][utils.supportedPropertyNames]) { - if (!(key in target)) { - keys.add(\`\${key}\`); + def() { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'def' called on an object that is not a valid instance of LegacyNoInterfaceObject." + ); } - } - - for (const key of Reflect.ownKeys(target)) { - keys.add(key); - } - return [...keys]; - } - - getOwnPropertyDescriptor(target, P) { - if (typeof P === "symbol") { - return Reflect.getOwnPropertyDescriptor(target, P); - } - let ignoreNamedProps = false; - - if (target[implSymbol][utils.supportsPropertyName](P) && !(P in target) && !ignoreNamedProps) { - const namedValue = target[implSymbol][utils.namedGet](P); - return { - writable: true, - enumerable: true, - configurable: true, - value: utils.tryWrapperForImpl(namedValue) - }; - } - - return Reflect.getOwnPropertyDescriptor(target, P); - } - - set(target, P, V, receiver) { - if (typeof P === "symbol") { - return Reflect.set(target, P, V, receiver); + return esValue[implSymbol].def(); } - // The \`receiver\` argument refers to the Proxy exotic object or an object - // that inherits from it, whereas \`target\` refers to the Proxy target: - if (target[implSymbol][utils.wrapperSymbol] === receiver) { - const globalObject = this._globalObject; - - if (typeof P === "string") { - let namedValue = V; - - namedValue = conversions["DOMString"](namedValue, { - context: "Failed to set the '" + P + "' property on 'LegacyUnforgeableMap': The provided value", - globals: globalObject - }); - const creating = !target[implSymbol][utils.supportsPropertyName](P); - if (creating) { - target[implSymbol][utils.namedSetNew](P, namedValue); - } else { - target[implSymbol][utils.namedSetExisting](P, namedValue); - } + get abc() { + const esValue = this !== null && this !== undefined ? this : globalObject; - return true; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'get abc' called on an object that is not a valid instance of LegacyNoInterfaceObject." + ); } - } - let ownDesc; - - if (ownDesc === undefined) { - ownDesc = Reflect.getOwnPropertyDescriptor(target, P); - } - return utils.ordinarySetWithOwnDescriptor(target, P, V, receiver, ownDesc); - } - defineProperty(target, P, desc) { - if (typeof P === "symbol") { - return Reflect.defineProperty(target, P, desc); + return esValue[implSymbol]["abc"]; } - const globalObject = this._globalObject; - if (!["a"].includes(P)) { - if (!Object.hasOwn(target, P)) { - if (desc.get || desc.set) { - return false; - } - - let namedValue = desc.value; - - namedValue = conversions["DOMString"](namedValue, { - context: "Failed to set the '" + P + "' property on 'LegacyUnforgeableMap': The provided value", - globals: globalObject - }); - - const creating = !target[implSymbol][utils.supportsPropertyName](P); - if (creating) { - target[implSymbol][utils.namedSetNew](P, namedValue); - } else { - target[implSymbol][utils.namedSetExisting](P, namedValue); - } + set abc(V) { + const esValue = this !== null && this !== undefined ? this : globalObject; - return true; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'set abc' called on an object that is not a valid instance of LegacyNoInterfaceObject." + ); } - } - return Reflect.defineProperty(target, P, desc); - } - - deleteProperty(target, P) { - if (typeof P === "symbol") { - return Reflect.deleteProperty(target, P); - } - const globalObject = this._globalObject; + V = conversions["DOMString"](V, { + context: "Failed to set the 'abc' property on 'LegacyNoInterfaceObject': The provided value", + globals: globalObject + }); - if (target[implSymbol][utils.supportsPropertyName](P) && !(P in target)) { - return false; + esValue[implSymbol]["abc"] = V; } - - return Reflect.deleteProperty(target, P); - } - - preventExtensions() { - return false; } -} + delete LegacyNoInterfaceObject.constructor; + Object.defineProperties(LegacyNoInterfaceObject.prototype, { + def: { enumerable: true }, + abc: { enumerable: true }, + [Symbol.toStringTag]: { value: "LegacyNoInterfaceObject", configurable: true } + }); + ctorRegistry[interfaceName] = LegacyNoInterfaceObject; +}; -const Impl = require("../implementations/LegacyUnforgeableMap.js"); +const Impl = require("../implementations/LegacyNoInterfaceObject.js"); " `; -exports[`generation with processors MixedIn.webidl 1`] = ` +exports[`generation with processors LegacyUnforgeable.webidl 1`] = ` ""use strict"; const conversions = require("webidl-conversions"); @@ -5043,7 +4945,7 @@ const utils = require("./utils.js"); const implSymbol = utils.implSymbol; const ctorRegistrySymbol = utils.ctorRegistrySymbol; -const interfaceName = "MixedIn"; +const interfaceName = "LegacyUnforgeable"; exports.is = value => { return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; @@ -5055,7 +4957,7 @@ exports.convert = (globalObject, value, { context = "The provided value" } = {}) if (exports.is(value)) { return utils.implForWrapper(value); } - throw new globalObject.TypeError(\`\${context} is not of type 'MixedIn'.\`); + throw new globalObject.TypeError(\`\${context} is not of type 'LegacyUnforgeable'.\`); }; function makeWrapper(globalObject, newTarget) { @@ -5065,7 +4967,7 @@ function makeWrapper(globalObject, newTarget) { } if (!utils.isObject(proto)) { - proto = globalObject[ctorRegistrySymbol]["MixedIn"].prototype; + proto = globalObject[ctorRegistrySymbol]["LegacyUnforgeable"].prototype; } return Object.create(proto); @@ -5081,26 +4983,145 @@ exports.createImpl = (globalObject, constructorArgs, privateData) => { return utils.implForWrapper(wrapper); }; -exports._internalSetup = (wrapper, globalObject) => {}; - -exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => { - privateData.wrapper = wrapper; +function getUnforgeables(globalObject) { + let unforgeables = unforgeablesMap.get(globalObject); + if (unforgeables === undefined) { + unforgeables = Object.create(null); + utils.define(unforgeables, { + assign(url) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'assign' called on an object that is not a valid instance of LegacyUnforgeable." + ); + } - exports._internalSetup(wrapper, globalObject); - Object.defineProperty(wrapper, implSymbol, { - value: new Impl.implementation(globalObject, constructorArgs, privateData), - configurable: true - }); + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'assign' on 'LegacyUnforgeable': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions["USVString"](curArg, { + context: "Failed to execute 'assign' on 'LegacyUnforgeable': parameter 1", + globals: globalObject + }); + args.push(curArg); + } + return esValue[implSymbol].assign(...args); + }, + get href() { + const esValue = this !== null && this !== undefined ? this : globalObject; - wrapper[implSymbol][utils.wrapperSymbol] = wrapper; - if (Impl.init) { - Impl.init(wrapper[implSymbol]); - } - return wrapper; -}; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'get href' called on an object that is not a valid instance of LegacyUnforgeable." + ); + } -exports.new = (globalObject, newTarget) => { - const wrapper = makeWrapper(globalObject, newTarget); + return esValue[implSymbol]["href"]; + }, + set href(V) { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'set href' called on an object that is not a valid instance of LegacyUnforgeable." + ); + } + + V = conversions["USVString"](V, { + context: "Failed to set the 'href' property on 'LegacyUnforgeable': The provided value", + globals: globalObject + }); + + esValue[implSymbol]["href"] = V; + }, + toString() { + const esValue = this; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'toString' called on an object that is not a valid instance of LegacyUnforgeable." + ); + } + + return esValue[implSymbol]["href"]; + }, + get origin() { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'get origin' called on an object that is not a valid instance of LegacyUnforgeable." + ); + } + + return esValue[implSymbol]["origin"]; + }, + get protocol() { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'get protocol' called on an object that is not a valid instance of LegacyUnforgeable." + ); + } + + return esValue[implSymbol]["protocol"]; + }, + set protocol(V) { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'set protocol' called on an object that is not a valid instance of LegacyUnforgeable." + ); + } + + V = conversions["USVString"](V, { + context: "Failed to set the 'protocol' property on 'LegacyUnforgeable': The provided value", + globals: globalObject + }); + + esValue[implSymbol]["protocol"] = V; + } + }); + Object.defineProperties(unforgeables, { + assign: { configurable: false, writable: false }, + href: { configurable: false }, + toString: { configurable: false, writable: false }, + origin: { configurable: false }, + protocol: { configurable: false } + }); + unforgeablesMap.set(globalObject, unforgeables); + } + return unforgeables; +} + +exports._internalSetup = (wrapper, globalObject) => { + utils.define(wrapper, getUnforgeables(globalObject)); +}; + +exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => { + privateData.wrapper = wrapper; + + exports._internalSetup(wrapper, globalObject); + Object.defineProperty(wrapper, implSymbol, { + value: new Impl.implementation(globalObject, constructorArgs, privateData), + configurable: true + }); + + wrapper[implSymbol][utils.wrapperSymbol] = wrapper; + if (Impl.init) { + Impl.init(wrapper[implSymbol]); + } + return wrapper; +}; + +exports.new = (globalObject, newTarget) => { + const wrapper = makeWrapper(globalObject, newTarget); exports._internalSetup(wrapper, globalObject); Object.defineProperty(wrapper, implSymbol, { @@ -5115,6 +5136,7 @@ exports.new = (globalObject, newTarget) => { return wrapper[implSymbol]; }; +const unforgeablesMap = new WeakMap(); const exposed = new Set(["Window"]); exports.install = (globalObject, globalNames) => { @@ -5123,242 +5145,112 @@ exports.install = (globalObject, globalNames) => { } const ctorRegistry = utils.initCtorRegistry(globalObject); - class MixedIn { + class LegacyUnforgeable { constructor() { throw new globalObject.TypeError("Illegal constructor"); } - - mixedInOp() { - const esValue = this !== null && this !== undefined ? this : globalObject; - if (!exports.is(esValue)) { - throw new globalObject.TypeError("'mixedInOp' called on an object that is not a valid instance of MixedIn."); - } - - return esValue[implSymbol].mixedInOp(); - } - - ifaceMixinOp() { - const esValue = this !== null && this !== undefined ? this : globalObject; - if (!exports.is(esValue)) { - throw new globalObject.TypeError("'ifaceMixinOp' called on an object that is not a valid instance of MixedIn."); - } - - return esValue[implSymbol].ifaceMixinOp(); - } - - get mixedInAttr() { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'get mixedInAttr' called on an object that is not a valid instance of MixedIn." - ); - } - - return esValue[implSymbol]["mixedInAttr"]; - } - - set mixedInAttr(V) { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'set mixedInAttr' called on an object that is not a valid instance of MixedIn." - ); - } - - V = conversions["DOMString"](V, { - context: "Failed to set the 'mixedInAttr' property on 'MixedIn': The provided value", - globals: globalObject - }); - - esValue[implSymbol]["mixedInAttr"] = V; - } - - get ifaceMixinAttr() { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'get ifaceMixinAttr' called on an object that is not a valid instance of MixedIn." - ); - } - - return esValue[implSymbol]["ifaceMixinAttr"]; - } - - set ifaceMixinAttr(V) { - const esValue = this !== null && this !== undefined ? this : globalObject; - - if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'set ifaceMixinAttr' called on an object that is not a valid instance of MixedIn." - ); - } - - V = conversions["DOMString"](V, { - context: "Failed to set the 'ifaceMixinAttr' property on 'MixedIn': The provided value", - globals: globalObject - }); - - esValue[implSymbol]["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 } + Object.defineProperties(LegacyUnforgeable.prototype, { + [Symbol.toStringTag]: { value: "LegacyUnforgeable", configurable: true } }); - ctorRegistry[interfaceName] = MixedIn; + ctorRegistry[interfaceName] = LegacyUnforgeable; Object.defineProperty(globalObject, interfaceName, { configurable: true, writable: true, - value: MixedIn + value: LegacyUnforgeable }); }; -const Impl = require("../implementations/MixedIn.js"); +const Impl = require("../implementations/LegacyUnforgeable.js"); " `; -exports[`generation with processors NodeFilter.webidl 1`] = ` +exports[`generation with processors LegacyUnforgeableMap.webidl 1`] = ` ""use strict"; const conversions = require("webidl-conversions"); const utils = require("./utils.js"); -exports.convert = (globalObject, value, { context = "The provided value" } = {}) => { - if (!utils.isObject(value)) { - throw new globalObject.TypeError(\`\${context} is not an object.\`); - } +const implSymbol = utils.implSymbol; +const ctorRegistrySymbol = utils.ctorRegistrySymbol; - function callTheUserObjectsOperation(node) { - let thisArg = utils.tryWrapperForImpl(this); - let O = value; - let X = O; +const interfaceName = "LegacyUnforgeableMap"; - if (typeof O !== "function") { - X = O["acceptNode"]; - if (typeof X !== "function") { - throw new globalObject.TypeError(\`\${context} does not correctly implement NodeFilter.\`); - } - thisArg = O; - } +exports.is = value => { + return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; +}; +exports.isImpl = value => { + return utils.isObject(value) && value instanceof Impl.implementation; +}; +exports.convert = (globalObject, value, { context = "The provided value" } = {}) => { + if (exports.is(value)) { + return utils.implForWrapper(value); + } + throw new globalObject.TypeError(\`\${context} is not of type 'LegacyUnforgeableMap'.\`); +}; - node = utils.tryWrapperForImpl(node); +function makeWrapper(globalObject, newTarget) { + let proto; + if (newTarget !== undefined) { + proto = newTarget.prototype; + } - let callResult = Reflect.apply(X, thisArg, [node]); + if (!utils.isObject(proto)) { + proto = globalObject[ctorRegistrySymbol]["LegacyUnforgeableMap"].prototype; + } - callResult = conversions["unsigned short"](callResult, { context: context, globals: globalObject }); + return Object.create(proto); +} - return callResult; +function makeProxy(wrapper, globalObject) { + let proxyHandler = proxyHandlerCache.get(globalObject); + if (proxyHandler === undefined) { + proxyHandler = new ProxyHandler(globalObject); + proxyHandlerCache.set(globalObject, proxyHandler); } + return new Proxy(wrapper, proxyHandler); +} - callTheUserObjectsOperation[utils.wrapperSymbol] = value; - callTheUserObjectsOperation.objectReference = value; - - return callTheUserObjectsOperation; +exports.create = (globalObject, constructorArgs, privateData) => { + const wrapper = makeWrapper(globalObject); + return exports.setup(wrapper, globalObject, constructorArgs, privateData); }; -const exposed = new Set(["Window"]); - -exports.install = (globalObject, globalNames) => { - if (!globalNames.some(globalName => exposed.has(globalName))) { - return; - } - - const ctorRegistry = utils.initCtorRegistry(globalObject); - const NodeFilter = () => { - throw new globalObject.TypeError("Illegal invocation"); - }; - - Object.defineProperties(NodeFilter, { - FILTER_ACCEPT: { value: 1, enumerable: true }, - FILTER_REJECT: { value: 2, enumerable: true }, - FILTER_SKIP: { value: 3, enumerable: true }, - SHOW_ALL: { value: 0xffffffff, enumerable: true }, - SHOW_ELEMENT: { value: 0x1, enumerable: true }, - SHOW_ATTRIBUTE: { value: 0x2, enumerable: true }, - SHOW_TEXT: { value: 0x4, enumerable: true }, - SHOW_CDATA_SECTION: { value: 0x8, enumerable: true }, - SHOW_ENTITY_REFERENCE: { value: 0x10, enumerable: true }, - SHOW_ENTITY: { value: 0x20, enumerable: true }, - SHOW_PROCESSING_INSTRUCTION: { value: 0x40, enumerable: true }, - SHOW_COMMENT: { value: 0x80, enumerable: true }, - SHOW_DOCUMENT: { value: 0x100, enumerable: true }, - SHOW_DOCUMENT_TYPE: { value: 0x200, enumerable: true }, - SHOW_DOCUMENT_FRAGMENT: { value: 0x400, enumerable: true }, - SHOW_NOTATION: { value: 0x800, enumerable: true } - }); - - Object.defineProperty(globalObject, "NodeFilter", { - configurable: true, - writable: true, - value: NodeFilter - }); +exports.createImpl = (globalObject, constructorArgs, privateData) => { + const wrapper = exports.create(globalObject, constructorArgs, privateData); + return utils.implForWrapper(wrapper); }; -" -`; - -exports[`generation with processors Overloads.webidl 1`] = ` -""use strict"; - -const conversions = require("webidl-conversions"); -const utils = require("./utils.js"); - -const URL = require("./URL.js"); -const implSymbol = utils.implSymbol; -const ctorRegistrySymbol = utils.ctorRegistrySymbol; - -const interfaceName = "Overloads"; -exports.is = value => { - return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; -}; -exports.isImpl = value => { - return utils.isObject(value) && value instanceof Impl.implementation; -}; -exports.convert = (globalObject, value, { context = "The provided value" } = {}) => { - if (exports.is(value)) { - return utils.implForWrapper(value); - } - throw new globalObject.TypeError(\`\${context} is not of type 'Overloads'.\`); -}; +function getUnforgeables(globalObject) { + let unforgeables = unforgeablesMap.get(globalObject); + if (unforgeables === undefined) { + unforgeables = Object.create(null); + utils.define(unforgeables, { + get a() { + const esValue = this !== null && this !== undefined ? this : globalObject; -function makeWrapper(globalObject, newTarget) { - let proto; - if (newTarget !== undefined) { - proto = newTarget.prototype; - } + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'get a' called on an object that is not a valid instance of LegacyUnforgeableMap." + ); + } - if (!utils.isObject(proto)) { - proto = globalObject[ctorRegistrySymbol]["Overloads"].prototype; + return esValue[implSymbol]["a"]; + } + }); + Object.defineProperties(unforgeables, { + a: { configurable: false } + }); + unforgeablesMap.set(globalObject, unforgeables); } - - return Object.create(proto); + return unforgeables; } -exports.create = (globalObject, constructorArgs, privateData) => { - const wrapper = makeWrapper(globalObject); - return exports.setup(wrapper, globalObject, constructorArgs, privateData); -}; - -exports.createImpl = (globalObject, constructorArgs, privateData) => { - const wrapper = exports.create(globalObject, constructorArgs, privateData); - return utils.implForWrapper(wrapper); +exports._internalSetup = (wrapper, globalObject) => { + utils.define(wrapper, getUnforgeables(globalObject)); }; -exports._internalSetup = (wrapper, globalObject) => {}; - exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => { privateData.wrapper = wrapper; @@ -5368,6 +5260,8 @@ exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) configurable: true }); + wrapper = makeProxy(wrapper, globalObject); + wrapper[implSymbol][utils.wrapperSymbol] = wrapper; if (Impl.init) { Impl.init(wrapper[implSymbol]); @@ -5376,7 +5270,7 @@ exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) }; exports.new = (globalObject, newTarget) => { - const wrapper = makeWrapper(globalObject, newTarget); + let wrapper = makeWrapper(globalObject, newTarget); exports._internalSetup(wrapper, globalObject); Object.defineProperty(wrapper, implSymbol, { @@ -5384,6 +5278,8 @@ exports.new = (globalObject, newTarget) => { configurable: true }); + wrapper = makeProxy(wrapper, globalObject); + wrapper[implSymbol][utils.wrapperSymbol] = wrapper; if (Impl.init) { Impl.init(wrapper[implSymbol]); @@ -5391,6 +5287,7 @@ exports.new = (globalObject, newTarget) => { return wrapper[implSymbol]; }; +const unforgeablesMap = new WeakMap(); const exposed = new Set(["Window"]); exports.install = (globalObject, globalNames) => { @@ -5399,118 +5296,668 @@ exports.install = (globalObject, globalNames) => { } const ctorRegistry = utils.initCtorRegistry(globalObject); - class Overloads { + class LegacyUnforgeableMap { constructor() { - const args = []; - switch (arguments.length) { - case 0: - break; - default: { - let curArg = arguments[0]; - if (URL.is(curArg)) { - { - let curArg = arguments[0]; - curArg = URL.convert(globalObject, 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", - globals: globalObject - }); - args.push(curArg); - } - } - } - } - return exports.setup(Object.create(new.target.prototype), globalObject, args); + throw new globalObject.TypeError("Illegal constructor"); } + } + Object.defineProperties(LegacyUnforgeableMap.prototype, { + [Symbol.toStringTag]: { value: "LegacyUnforgeableMap", configurable: true } + }); + ctorRegistry[interfaceName] = LegacyUnforgeableMap; - compatible(arg1) { - const esValue = this !== null && this !== undefined ? this : globalObject; - if (!exports.is(esValue)) { - throw new globalObject.TypeError("'compatible' called on an object that is not a valid instance of Overloads."); - } + Object.defineProperty(globalObject, interfaceName, { + configurable: true, + writable: true, + value: LegacyUnforgeableMap + }); +}; - if (arguments.length < 1) { - throw new globalObject.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", - globals: globalObject - }); - args.push(curArg); - } - break; - case 2: - { - let curArg = arguments[0]; - curArg = conversions["DOMString"](curArg, { - context: "Failed to execute 'compatible' on 'Overloads': parameter 1", - globals: globalObject - }); - args.push(curArg); - } - { - let curArg = arguments[1]; - curArg = conversions["DOMString"](curArg, { - context: "Failed to execute 'compatible' on 'Overloads': parameter 2", - globals: globalObject - }); - args.push(curArg); - } - break; - default: - { - let curArg = arguments[0]; - curArg = conversions["DOMString"](curArg, { - context: "Failed to execute 'compatible' on 'Overloads': parameter 1", - globals: globalObject - }); - args.push(curArg); - } - { - let curArg = arguments[1]; - curArg = conversions["DOMString"](curArg, { - context: "Failed to execute 'compatible' on 'Overloads': parameter 2", - globals: globalObject - }); - args.push(curArg); - } - { - let curArg = arguments[2]; - if (curArg !== undefined) { - curArg = conversions["long"](curArg, { - context: "Failed to execute 'compatible' on 'Overloads': parameter 3", - globals: globalObject - }); - } else { - curArg = 0; - } - args.push(curArg); - } - } - return utils.tryWrapperForImpl(esValue[implSymbol].compatible(...args)); - } +const proxyHandlerCache = new WeakMap(); +class ProxyHandler { + constructor(globalObject) { + this._globalObject = globalObject; + } - incompatible1(arg1) { - const esValue = this !== null && this !== undefined ? this : globalObject; - if (!exports.is(esValue)) { - throw new globalObject.TypeError( - "'incompatible1' called on an object that is not a valid instance of Overloads." - ); + get(target, P, receiver) { + if (typeof P === "symbol") { + return Reflect.get(target, P, receiver); + } + const desc = this.getOwnPropertyDescriptor(target, P); + if (desc === undefined) { + const parent = Object.getPrototypeOf(target); + if (parent === null) { + return undefined; } + return Reflect.get(target, P, receiver); + } + if (!desc.get && !desc.set) { + return desc.value; + } + const getter = desc.get; + if (getter === undefined) { + return undefined; + } + return Reflect.apply(getter, receiver, []); + } - if (arguments.length < 1) { + has(target, P) { + if (typeof P === "symbol") { + return Reflect.has(target, P); + } + const desc = this.getOwnPropertyDescriptor(target, P); + if (desc !== undefined) { + return true; + } + const parent = Object.getPrototypeOf(target); + if (parent !== null) { + return Reflect.has(parent, P); + } + return false; + } + + ownKeys(target) { + const keys = new Set(); + + for (const key of target[implSymbol][utils.supportedPropertyNames]) { + if (!(key in target)) { + keys.add(\`\${key}\`); + } + } + + for (const key of Reflect.ownKeys(target)) { + keys.add(key); + } + return [...keys]; + } + + getOwnPropertyDescriptor(target, P) { + if (typeof P === "symbol") { + return Reflect.getOwnPropertyDescriptor(target, P); + } + let ignoreNamedProps = false; + + if (target[implSymbol][utils.supportsPropertyName](P) && !(P in target) && !ignoreNamedProps) { + const namedValue = target[implSymbol][utils.namedGet](P); + + return { + writable: true, + enumerable: true, + configurable: true, + value: utils.tryWrapperForImpl(namedValue) + }; + } + + return Reflect.getOwnPropertyDescriptor(target, P); + } + + set(target, P, V, receiver) { + if (typeof P === "symbol") { + return Reflect.set(target, P, V, receiver); + } + // The \`receiver\` argument refers to the Proxy exotic object or an object + // that inherits from it, whereas \`target\` refers to the Proxy target: + if (target[implSymbol][utils.wrapperSymbol] === receiver) { + const globalObject = this._globalObject; + + if (typeof P === "string") { + let namedValue = V; + + namedValue = conversions["DOMString"](namedValue, { + context: "Failed to set the '" + P + "' property on 'LegacyUnforgeableMap': The provided value", + globals: globalObject + }); + + const creating = !target[implSymbol][utils.supportsPropertyName](P); + if (creating) { + target[implSymbol][utils.namedSetNew](P, namedValue); + } else { + target[implSymbol][utils.namedSetExisting](P, namedValue); + } + + return true; + } + } + let ownDesc; + + if (ownDesc === undefined) { + ownDesc = Reflect.getOwnPropertyDescriptor(target, P); + } + return utils.ordinarySetWithOwnDescriptor(target, P, V, receiver, ownDesc); + } + + defineProperty(target, P, desc) { + if (typeof P === "symbol") { + return Reflect.defineProperty(target, P, desc); + } + + const globalObject = this._globalObject; + if (!["a"].includes(P)) { + if (!Object.hasOwn(target, P)) { + if (desc.get || desc.set) { + return false; + } + + let namedValue = desc.value; + + namedValue = conversions["DOMString"](namedValue, { + context: "Failed to set the '" + P + "' property on 'LegacyUnforgeableMap': The provided value", + globals: globalObject + }); + + const creating = !target[implSymbol][utils.supportsPropertyName](P); + if (creating) { + target[implSymbol][utils.namedSetNew](P, namedValue); + } else { + target[implSymbol][utils.namedSetExisting](P, namedValue); + } + + return true; + } + } + return Reflect.defineProperty(target, P, desc); + } + + deleteProperty(target, P) { + if (typeof P === "symbol") { + return Reflect.deleteProperty(target, P); + } + + const globalObject = this._globalObject; + + if (target[implSymbol][utils.supportsPropertyName](P) && !(P in target)) { + return false; + } + + return Reflect.deleteProperty(target, P); + } + + preventExtensions() { + return false; + } +} + +const Impl = require("../implementations/LegacyUnforgeableMap.js"); +" +`; + +exports[`generation with processors MixedIn.webidl 1`] = ` +""use strict"; + +const conversions = require("webidl-conversions"); +const utils = require("./utils.js"); + +const implSymbol = utils.implSymbol; +const ctorRegistrySymbol = utils.ctorRegistrySymbol; + +const interfaceName = "MixedIn"; + +exports.is = value => { + return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; +}; +exports.isImpl = value => { + return utils.isObject(value) && value instanceof Impl.implementation; +}; +exports.convert = (globalObject, value, { context = "The provided value" } = {}) => { + if (exports.is(value)) { + return utils.implForWrapper(value); + } + throw new globalObject.TypeError(\`\${context} is not of type 'MixedIn'.\`); +}; + +function makeWrapper(globalObject, newTarget) { + let proto; + if (newTarget !== undefined) { + proto = newTarget.prototype; + } + + if (!utils.isObject(proto)) { + proto = globalObject[ctorRegistrySymbol]["MixedIn"].prototype; + } + + return Object.create(proto); +} + +exports.create = (globalObject, constructorArgs, privateData) => { + const wrapper = makeWrapper(globalObject); + return exports.setup(wrapper, globalObject, constructorArgs, privateData); +}; + +exports.createImpl = (globalObject, constructorArgs, privateData) => { + const wrapper = exports.create(globalObject, constructorArgs, privateData); + return utils.implForWrapper(wrapper); +}; + +exports._internalSetup = (wrapper, globalObject) => {}; + +exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => { + privateData.wrapper = wrapper; + + exports._internalSetup(wrapper, globalObject); + Object.defineProperty(wrapper, implSymbol, { + value: new Impl.implementation(globalObject, constructorArgs, privateData), + configurable: true + }); + + wrapper[implSymbol][utils.wrapperSymbol] = wrapper; + if (Impl.init) { + Impl.init(wrapper[implSymbol]); + } + return wrapper; +}; + +exports.new = (globalObject, newTarget) => { + const wrapper = makeWrapper(globalObject, newTarget); + + exports._internalSetup(wrapper, globalObject); + Object.defineProperty(wrapper, implSymbol, { + value: Object.create(Impl.implementation.prototype), + configurable: true + }); + + wrapper[implSymbol][utils.wrapperSymbol] = wrapper; + if (Impl.init) { + Impl.init(wrapper[implSymbol]); + } + return wrapper[implSymbol]; +}; + +const exposed = new Set(["Window"]); + +exports.install = (globalObject, globalNames) => { + if (!globalNames.some(globalName => exposed.has(globalName))) { + return; + } + + const ctorRegistry = utils.initCtorRegistry(globalObject); + class MixedIn { + constructor() { + throw new globalObject.TypeError("Illegal constructor"); + } + + mixedInOp() { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError("'mixedInOp' called on an object that is not a valid instance of MixedIn."); + } + + return esValue[implSymbol].mixedInOp(); + } + + ifaceMixinOp() { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError("'ifaceMixinOp' called on an object that is not a valid instance of MixedIn."); + } + + return esValue[implSymbol].ifaceMixinOp(); + } + + get mixedInAttr() { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'get mixedInAttr' called on an object that is not a valid instance of MixedIn." + ); + } + + return esValue[implSymbol]["mixedInAttr"]; + } + + set mixedInAttr(V) { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'set mixedInAttr' called on an object that is not a valid instance of MixedIn." + ); + } + + V = conversions["DOMString"](V, { + context: "Failed to set the 'mixedInAttr' property on 'MixedIn': The provided value", + globals: globalObject + }); + + esValue[implSymbol]["mixedInAttr"] = V; + } + + get ifaceMixinAttr() { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'get ifaceMixinAttr' called on an object that is not a valid instance of MixedIn." + ); + } + + return esValue[implSymbol]["ifaceMixinAttr"]; + } + + set ifaceMixinAttr(V) { + const esValue = this !== null && this !== undefined ? this : globalObject; + + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'set ifaceMixinAttr' called on an object that is not a valid instance of MixedIn." + ); + } + + V = conversions["DOMString"](V, { + context: "Failed to set the 'ifaceMixinAttr' property on 'MixedIn': The provided value", + globals: globalObject + }); + + esValue[implSymbol]["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 } + }); + ctorRegistry[interfaceName] = MixedIn; + + Object.defineProperty(globalObject, interfaceName, { + configurable: true, + writable: true, + value: MixedIn + }); +}; + +const Impl = require("../implementations/MixedIn.js"); +" +`; + +exports[`generation with processors NodeFilter.webidl 1`] = ` +""use strict"; + +const conversions = require("webidl-conversions"); +const utils = require("./utils.js"); + +exports.convert = (globalObject, value, { context = "The provided value" } = {}) => { + if (!utils.isObject(value)) { + throw new globalObject.TypeError(\`\${context} is not an object.\`); + } + + function callTheUserObjectsOperation(node) { + let thisArg = utils.tryWrapperForImpl(this); + let O = value; + let X = O; + + if (typeof O !== "function") { + X = O["acceptNode"]; + if (typeof X !== "function") { + throw new globalObject.TypeError(\`\${context} does not correctly implement NodeFilter.\`); + } + thisArg = O; + } + + node = utils.tryWrapperForImpl(node); + + let callResult = Reflect.apply(X, thisArg, [node]); + + callResult = conversions["unsigned short"](callResult, { context: context, globals: globalObject }); + + return callResult; + } + + callTheUserObjectsOperation[utils.wrapperSymbol] = value; + callTheUserObjectsOperation.objectReference = value; + + return callTheUserObjectsOperation; +}; + +const exposed = new Set(["Window"]); + +exports.install = (globalObject, globalNames) => { + if (!globalNames.some(globalName => exposed.has(globalName))) { + return; + } + + const ctorRegistry = utils.initCtorRegistry(globalObject); + const NodeFilter = () => { + throw new globalObject.TypeError("Illegal invocation"); + }; + + Object.defineProperties(NodeFilter, { + FILTER_ACCEPT: { value: 1, enumerable: true }, + FILTER_REJECT: { value: 2, enumerable: true }, + FILTER_SKIP: { value: 3, enumerable: true }, + SHOW_ALL: { value: 0xffffffff, enumerable: true }, + SHOW_ELEMENT: { value: 0x1, enumerable: true }, + SHOW_ATTRIBUTE: { value: 0x2, enumerable: true }, + SHOW_TEXT: { value: 0x4, enumerable: true }, + SHOW_CDATA_SECTION: { value: 0x8, enumerable: true }, + SHOW_ENTITY_REFERENCE: { value: 0x10, enumerable: true }, + SHOW_ENTITY: { value: 0x20, enumerable: true }, + SHOW_PROCESSING_INSTRUCTION: { value: 0x40, enumerable: true }, + SHOW_COMMENT: { value: 0x80, enumerable: true }, + SHOW_DOCUMENT: { value: 0x100, enumerable: true }, + SHOW_DOCUMENT_TYPE: { value: 0x200, enumerable: true }, + SHOW_DOCUMENT_FRAGMENT: { value: 0x400, enumerable: true }, + SHOW_NOTATION: { value: 0x800, enumerable: true } + }); + + Object.defineProperty(globalObject, "NodeFilter", { + configurable: true, + writable: true, + value: NodeFilter + }); +}; +" +`; + +exports[`generation with processors Overloads.webidl 1`] = ` +""use strict"; + +const conversions = require("webidl-conversions"); +const utils = require("./utils.js"); + +const URL = require("./URL.js"); +const implSymbol = utils.implSymbol; +const ctorRegistrySymbol = utils.ctorRegistrySymbol; + +const interfaceName = "Overloads"; + +exports.is = value => { + return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; +}; +exports.isImpl = value => { + return utils.isObject(value) && value instanceof Impl.implementation; +}; +exports.convert = (globalObject, value, { context = "The provided value" } = {}) => { + if (exports.is(value)) { + return utils.implForWrapper(value); + } + throw new globalObject.TypeError(\`\${context} is not of type 'Overloads'.\`); +}; + +function makeWrapper(globalObject, newTarget) { + let proto; + if (newTarget !== undefined) { + proto = newTarget.prototype; + } + + if (!utils.isObject(proto)) { + proto = globalObject[ctorRegistrySymbol]["Overloads"].prototype; + } + + return Object.create(proto); +} + +exports.create = (globalObject, constructorArgs, privateData) => { + const wrapper = makeWrapper(globalObject); + return exports.setup(wrapper, globalObject, constructorArgs, privateData); +}; + +exports.createImpl = (globalObject, constructorArgs, privateData) => { + const wrapper = exports.create(globalObject, constructorArgs, privateData); + return utils.implForWrapper(wrapper); +}; + +exports._internalSetup = (wrapper, globalObject) => {}; + +exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => { + privateData.wrapper = wrapper; + + exports._internalSetup(wrapper, globalObject); + Object.defineProperty(wrapper, implSymbol, { + value: new Impl.implementation(globalObject, constructorArgs, privateData), + configurable: true + }); + + wrapper[implSymbol][utils.wrapperSymbol] = wrapper; + if (Impl.init) { + Impl.init(wrapper[implSymbol]); + } + return wrapper; +}; + +exports.new = (globalObject, newTarget) => { + const wrapper = makeWrapper(globalObject, newTarget); + + exports._internalSetup(wrapper, globalObject); + Object.defineProperty(wrapper, implSymbol, { + value: Object.create(Impl.implementation.prototype), + configurable: true + }); + + wrapper[implSymbol][utils.wrapperSymbol] = wrapper; + if (Impl.init) { + Impl.init(wrapper[implSymbol]); + } + return wrapper[implSymbol]; +}; + +const exposed = new Set(["Window"]); + +exports.install = (globalObject, globalNames) => { + if (!globalNames.some(globalName => exposed.has(globalName))) { + return; + } + + const ctorRegistry = utils.initCtorRegistry(globalObject); + class Overloads { + constructor() { + const args = []; + switch (arguments.length) { + case 0: + break; + default: { + let curArg = arguments[0]; + if (URL.is(curArg)) { + { + let curArg = arguments[0]; + curArg = URL.convert(globalObject, 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", + globals: globalObject + }); + args.push(curArg); + } + } + } + } + return exports.setup(Object.create(new.target.prototype), globalObject, args); + } + + compatible(arg1) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError("'compatible' called on an object that is not a valid instance of Overloads."); + } + + if (arguments.length < 1) { + throw new globalObject.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", + globals: globalObject + }); + args.push(curArg); + } + break; + case 2: + { + let curArg = arguments[0]; + curArg = conversions["DOMString"](curArg, { + context: "Failed to execute 'compatible' on 'Overloads': parameter 1", + globals: globalObject + }); + args.push(curArg); + } + { + let curArg = arguments[1]; + curArg = conversions["DOMString"](curArg, { + context: "Failed to execute 'compatible' on 'Overloads': parameter 2", + globals: globalObject + }); + args.push(curArg); + } + break; + default: + { + let curArg = arguments[0]; + curArg = conversions["DOMString"](curArg, { + context: "Failed to execute 'compatible' on 'Overloads': parameter 1", + globals: globalObject + }); + args.push(curArg); + } + { + let curArg = arguments[1]; + curArg = conversions["DOMString"](curArg, { + context: "Failed to execute 'compatible' on 'Overloads': parameter 2", + globals: globalObject + }); + args.push(curArg); + } + { + let curArg = arguments[2]; + if (curArg !== undefined) { + curArg = conversions["long"](curArg, { + context: "Failed to execute 'compatible' on 'Overloads': parameter 3", + globals: globalObject + }); + } else { + curArg = 0; + } + args.push(curArg); + } + } + return utils.tryWrapperForImpl(esValue[implSymbol].compatible(...args)); + } + + incompatible1(arg1) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'incompatible1' called on an object that is not a valid instance of Overloads." + ); + } + + if (arguments.length < 1) { throw new globalObject.TypeError( \`Failed to execute 'incompatible1' on 'Overloads': 1 argument required, but only \${arguments.length} present.\` ); @@ -5647,7 +6094,15 @@ exports.install = (globalObject, globalNames) => { { let curArg = arguments[1]; if (utils.isArrayBuffer(curArg)) { + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'incompatible3' on 'Overloads': parameter 2", + globals: globalObject + }); } else if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'incompatible3' on 'Overloads': parameter 2", + globals: globalObject + }); } else { throw new globalObject.TypeError( "Failed to execute 'incompatible3' on 'Overloads': parameter 2" + " is not of any supported type." @@ -5659,7 +6114,15 @@ exports.install = (globalObject, globalNames) => { { let curArg = arguments[1]; if (utils.isArrayBuffer(curArg)) { + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'incompatible3' on 'Overloads': parameter 2", + globals: globalObject + }); } else if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'incompatible3' on 'Overloads': parameter 2", + globals: globalObject + }); } else { throw new globalObject.TypeError( "Failed to execute 'incompatible3' on 'Overloads': parameter 2" + " is not of any supported type." @@ -5704,7 +6167,15 @@ exports.install = (globalObject, globalNames) => { { let curArg = arguments[2]; if (utils.isArrayBuffer(curArg)) { + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'incompatible3' on 'Overloads': parameter 3", + globals: globalObject + }); } else if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'incompatible3' on 'Overloads': parameter 3", + globals: globalObject + }); } else { throw new globalObject.TypeError( "Failed to execute 'incompatible3' on 'Overloads': parameter 3" + " is not of any supported type." @@ -5715,7 +6186,15 @@ exports.install = (globalObject, globalNames) => { { let curArg = arguments[3]; if (utils.isArrayBuffer(curArg)) { + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'incompatible3' on 'Overloads': parameter 4", + globals: globalObject + }); } else if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'incompatible3' on 'Overloads': parameter 4", + globals: globalObject + }); } else { throw new globalObject.TypeError( "Failed to execute 'incompatible3' on 'Overloads': parameter 4" + " is not of any supported type." @@ -7928,6 +8407,8 @@ const utils = require("./utils.js"); const RequestDestination = require("./RequestDestination.js"); const URL = require("./URL.js"); +const AsyncCallbackFunction = require("./AsyncCallbackFunction.js"); +const AsyncCallbackInterface = require("./AsyncCallbackInterface.js"); const implSymbol = utils.implSymbol; const ctorRegistrySymbol = utils.ctorRegistrySymbol; @@ -8164,6 +8645,42 @@ exports.install = (globalObject, globalNames) => { return esValue[implSymbol].numOrStrOrURLOrNullConsumer(...args); } + numOrObjConsumer(a) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'numOrObjConsumer' called on an object that is not a valid instance of TypedefsAndUnions." + ); + } + + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'numOrObjConsumer' on 'TypedefsAndUnions': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + if (utils.isObject(curArg)) { + if (curArg[utils.implSymbol]) { + curArg = utils.implForWrapper(curArg); + } + } else if (typeof curArg === "number") { + curArg = conversions["double"](curArg, { + context: "Failed to execute 'numOrObjConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); + } else { + curArg = conversions["double"](curArg, { + context: "Failed to execute 'numOrObjConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); + } + args.push(curArg); + } + return esValue[implSymbol].numOrObjConsumer(...args); + } + urlMapInnerConsumer(a) { const esValue = this !== null && this !== undefined ? this : globalObject; if (!exports.is(esValue)) { @@ -8283,7 +8800,15 @@ exports.install = (globalObject, globalNames) => { if (URL.is(curArg)) { curArg = utils.implForWrapper(curArg); } else if (utils.isArrayBuffer(curArg)) { + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'bufferSourceOrURLConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); } else if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'bufferSourceOrURLConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); } else { throw new globalObject.TypeError( "Failed to execute 'bufferSourceOrURLConsumer' on 'TypedefsAndUnions': parameter 1" + @@ -8315,6 +8840,10 @@ exports.install = (globalObject, globalNames) => { curArg = null; } else { if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'arrayBufferViewOrURLMapConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); } else if (utils.isObject(curArg)) { if (!utils.isObject(curArg)) { throw new globalObject.TypeError( @@ -8339,56 +8868,173 @@ exports.install = (globalObject, globalNames) => { let typedValue = curArg[key]; - typedValue = URL.convert(globalObject, typedValue, { - context: - "Failed to execute 'arrayBufferViewOrURLMapConsumer' on 'TypedefsAndUnions': parameter 1" + - " record" + - "'s value" - }); + typedValue = URL.convert(globalObject, typedValue, { + context: + "Failed to execute 'arrayBufferViewOrURLMapConsumer' on 'TypedefsAndUnions': parameter 1" + + " record" + + "'s value" + }); + + result[typedKey] = typedValue; + } + } + curArg = result; + } + } else { + throw new globalObject.TypeError( + "Failed to execute 'arrayBufferViewOrURLMapConsumer' on 'TypedefsAndUnions': parameter 1" + + " is not of any supported type." + ); + } + } + args.push(curArg); + } + return esValue[implSymbol].arrayBufferViewOrURLMapConsumer(...args); + } + + arrayBufferViewDupConsumer(b) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'arrayBufferViewDupConsumer' called on an object that is not a valid instance of TypedefsAndUnions." + ); + } + + if (arguments.length < 1) { + throw new globalObject.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)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'arrayBufferViewDupConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); + } else { + throw new globalObject.TypeError( + "Failed to execute 'arrayBufferViewDupConsumer' on 'TypedefsAndUnions': parameter 1" + + " is not of any supported type." + ); + } + args.push(curArg); + } + return esValue[implSymbol].arrayBufferViewDupConsumer(...args); + } + + arrayBufferOrSharedArrayBufferConsumer(b) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'arrayBufferOrSharedArrayBufferConsumer' called on an object that is not a valid instance of TypedefsAndUnions." + ); + } + + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'arrayBufferOrSharedArrayBufferConsumer' on 'TypedefsAndUnions': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + if (utils.isArrayBuffer(curArg)) { + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'arrayBufferOrSharedArrayBufferConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); + } else if (utils.isSharedArrayBuffer(curArg)) { + curArg = conversions["SharedArrayBuffer"](curArg, { + context: "Failed to execute 'arrayBufferOrSharedArrayBufferConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); + } else { + throw new globalObject.TypeError( + "Failed to execute 'arrayBufferOrSharedArrayBufferConsumer' on 'TypedefsAndUnions': parameter 1" + + " is not of any supported type." + ); + } + args.push(curArg); + } + return esValue[implSymbol].arrayBufferOrSharedArrayBufferConsumer(...args); + } + + callbackFunctionOrNumConsumer(cb) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'callbackFunctionOrNumConsumer' called on an object that is not a valid instance of TypedefsAndUnions." + ); + } - result[typedKey] = typedValue; - } - } - curArg = result; - } - } else { - throw new globalObject.TypeError( - "Failed to execute 'arrayBufferViewOrURLMapConsumer' on 'TypedefsAndUnions': parameter 1" + - " is not of any supported type." - ); - } + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'callbackFunctionOrNumConsumer' on 'TypedefsAndUnions': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + if (typeof curArg === "function") { + curArg = AsyncCallbackFunction.convert(globalObject, curArg, { + context: + "Failed to execute 'callbackFunctionOrNumConsumer' on 'TypedefsAndUnions': parameter 1" + + " callback function" + }); + } else if (typeof curArg === "number") { + curArg = conversions["double"](curArg, { + context: "Failed to execute 'callbackFunctionOrNumConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); + } else { + curArg = conversions["double"](curArg, { + context: "Failed to execute 'callbackFunctionOrNumConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); } args.push(curArg); } - return esValue[implSymbol].arrayBufferViewOrURLMapConsumer(...args); + return esValue[implSymbol].callbackFunctionOrNumConsumer(...args); } - arrayBufferViewDupConsumer(b) { + callbackInterfaceOrNumConsumer(cb) { const esValue = this !== null && this !== undefined ? this : globalObject; if (!exports.is(esValue)) { throw new globalObject.TypeError( - "'arrayBufferViewDupConsumer' called on an object that is not a valid instance of TypedefsAndUnions." + "'callbackInterfaceOrNumConsumer' called on an object that is not a valid instance of TypedefsAndUnions." ); } if (arguments.length < 1) { throw new globalObject.TypeError( - \`Failed to execute 'arrayBufferViewDupConsumer' on 'TypedefsAndUnions': 1 argument required, but only \${arguments.length} present.\` + \`Failed to execute 'callbackInterfaceOrNumConsumer' on 'TypedefsAndUnions': 1 argument required, but only \${arguments.length} present.\` ); } const args = []; { let curArg = arguments[0]; - if (ArrayBuffer.isView(curArg)) { + if (utils.isObject(curArg)) { + curArg = AsyncCallbackInterface.convert(globalObject, curArg, { + context: + "Failed to execute 'callbackInterfaceOrNumConsumer' on 'TypedefsAndUnions': parameter 1" + + " callback interface" + }); + } else if (typeof curArg === "number") { + curArg = conversions["double"](curArg, { + context: "Failed to execute 'callbackInterfaceOrNumConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); } else { - throw new globalObject.TypeError( - "Failed to execute 'arrayBufferViewDupConsumer' on 'TypedefsAndUnions': parameter 1" + - " is not of any supported type." - ); + curArg = conversions["double"](curArg, { + context: "Failed to execute 'callbackInterfaceOrNumConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); } args.push(curArg); } - return esValue[implSymbol].arrayBufferViewDupConsumer(...args); + return esValue[implSymbol].callbackInterfaceOrNumConsumer(...args); } get buf() { @@ -8413,10 +9059,20 @@ exports.install = (globalObject, globalNames) => { } if (utils.isArrayBuffer(V)) { - } else if ( - ArrayBuffer.isView(V) && - (V.constructor.name === "Uint8Array" || V.constructor.name === "Uint16Array") - ) { + V = conversions["ArrayBuffer"](V, { + context: "Failed to set the 'buf' property on 'TypedefsAndUnions': The provided value", + globals: globalObject + }); + } else if (ArrayBuffer.isView(V) && V.constructor.name === "Uint8Array") { + V = conversions["Uint8Array"](V, { + context: "Failed to set the 'buf' property on 'TypedefsAndUnions': The provided value", + globals: globalObject + }); + } else if (ArrayBuffer.isView(V) && V.constructor.name === "Uint16Array") { + V = conversions["Uint16Array"](V, { + context: "Failed to set the 'buf' property on 'TypedefsAndUnions': The provided value", + globals: globalObject + }); } else { throw new globalObject.TypeError( "Failed to set the 'buf' property on 'TypedefsAndUnions': The provided value" + @@ -8460,11 +9116,15 @@ exports.install = (globalObject, globalNames) => { numOrEnumConsumer: { enumerable: true }, numOrStrOrNullConsumer: { enumerable: true }, numOrStrOrURLOrNullConsumer: { enumerable: true }, + numOrObjConsumer: { enumerable: true }, urlMapInnerConsumer: { enumerable: true }, urlMapConsumer: { enumerable: true }, bufferSourceOrURLConsumer: { enumerable: true }, arrayBufferViewOrURLMapConsumer: { enumerable: true }, arrayBufferViewDupConsumer: { enumerable: true }, + arrayBufferOrSharedArrayBufferConsumer: { enumerable: true }, + callbackFunctionOrNumConsumer: { enumerable: true }, + callbackInterfaceOrNumConsumer: { enumerable: true }, buf: { enumerable: true }, time: { enumerable: true }, [Symbol.toStringTag]: { value: "TypedefsAndUnions", configurable: true } @@ -12063,7 +12723,195 @@ exports.convert = (globalObject, value, { context = "The provided value" } = {}) exports.createDefaultAsyncIterator = (globalObject, target, kind) => { const ctorRegistry = globalObject[ctorRegistrySymbol]; - const asyncIteratorPrototype = ctorRegistry["AsyncIterableValueNoArgs AsyncIterator"]; + const asyncIteratorPrototype = ctorRegistry["AsyncIterableValueNoArgs AsyncIterator"]; + const iterator = Object.create(asyncIteratorPrototype); + Object.defineProperty(iterator, utils.iterInternalSymbol, { + value: { target, kind, ongoingPromise: null, isFinished: false }, + configurable: true + }); + return iterator; +}; + +function makeWrapper(globalObject, newTarget) { + let proto; + if (newTarget !== undefined) { + proto = newTarget.prototype; + } + + if (!utils.isObject(proto)) { + proto = globalObject[ctorRegistrySymbol]["AsyncIterableValueNoArgs"].prototype; + } + + return Object.create(proto); +} + +exports.create = (globalObject, constructorArgs, privateData) => { + const wrapper = makeWrapper(globalObject); + return exports.setup(wrapper, globalObject, constructorArgs, privateData); +}; + +exports.createImpl = (globalObject, constructorArgs, privateData) => { + const wrapper = exports.create(globalObject, constructorArgs, privateData); + return utils.implForWrapper(wrapper); +}; + +exports._internalSetup = (wrapper, globalObject) => {}; + +exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => { + privateData.wrapper = wrapper; + + exports._internalSetup(wrapper, globalObject); + Object.defineProperty(wrapper, implSymbol, { + value: new Impl.implementation(globalObject, constructorArgs, privateData), + configurable: true + }); + + wrapper[implSymbol][utils.wrapperSymbol] = wrapper; + if (Impl.init) { + Impl.init(wrapper[implSymbol]); + } + return wrapper; +}; + +exports.new = (globalObject, newTarget) => { + const wrapper = makeWrapper(globalObject, newTarget); + + exports._internalSetup(wrapper, globalObject); + Object.defineProperty(wrapper, implSymbol, { + value: Object.create(Impl.implementation.prototype), + configurable: true + }); + + wrapper[implSymbol][utils.wrapperSymbol] = wrapper; + if (Impl.init) { + Impl.init(wrapper[implSymbol]); + } + return wrapper[implSymbol]; +}; + +const exposed = new Set(["Window"]); + +exports.install = (globalObject, globalNames) => { + if (!globalNames.some(globalName => exposed.has(globalName))) { + return; + } + + const ctorRegistry = utils.initCtorRegistry(globalObject); + class AsyncIterableValueNoArgs { + constructor() { + throw new globalObject.TypeError("Illegal constructor"); + } + + values() { + if (!exports.is(this)) { + throw new globalObject.TypeError( + "'values' called on an object that is not a valid instance of AsyncIterableValueNoArgs." + ); + } + + const args = []; + + const asyncIterator = exports.createDefaultAsyncIterator(globalObject, this, "value"); + if (this[implSymbol][utils.asyncIteratorInit]) { + this[implSymbol][utils.asyncIteratorInit](asyncIterator, args); + } + return asyncIterator; + } + } + Object.defineProperties(AsyncIterableValueNoArgs.prototype, { + values: { enumerable: true }, + [Symbol.toStringTag]: { value: "AsyncIterableValueNoArgs", configurable: true }, + [Symbol.asyncIterator]: { value: AsyncIterableValueNoArgs.prototype.values, configurable: true, writable: true } + }); + ctorRegistry[interfaceName] = AsyncIterableValueNoArgs; + + ctorRegistry["AsyncIterableValueNoArgs AsyncIterator"] = Object.create(ctorRegistry["%AsyncIteratorPrototype%"], { + [Symbol.toStringTag]: { + value: "AsyncIterableValueNoArgs AsyncIterator", + configurable: true + } + }); + utils.define(ctorRegistry["AsyncIterableValueNoArgs AsyncIterator"], { + next() { + const internal = this && this[utils.iterInternalSymbol]; + if (!internal) { + return globalObject.Promise.reject( + new globalObject.TypeError( + "next() called on a value that is not a AsyncIterableValueNoArgs async iterator object" + ) + ); + } + + const nextSteps = () => { + if (internal.isFinished) { + return globalObject.Promise.resolve(newObjectInRealm(globalObject, { value: undefined, done: true })); + } + + const nextPromise = internal.target[implSymbol][utils.asyncIteratorNext](this); + return nextPromise.then( + next => { + internal.ongoingPromise = null; + if (next === utils.asyncIteratorEOI) { + internal.isFinished = true; + return newObjectInRealm(globalObject, { value: undefined, done: true }); + } + return newObjectInRealm(globalObject, { value: utils.tryWrapperForImpl(next), done: false }); + }, + reason => { + internal.ongoingPromise = null; + internal.isFinished = true; + throw reason; + } + ); + }; + + internal.ongoingPromise = internal.ongoingPromise + ? internal.ongoingPromise.then(nextSteps, nextSteps) + : nextSteps(); + return internal.ongoingPromise; + } + }); + + Object.defineProperty(globalObject, interfaceName, { + configurable: true, + writable: true, + value: AsyncIterableValueNoArgs + }); +}; + +const Impl = require("../implementations/AsyncIterableValueNoArgs.js"); +" +`; + +exports[`generation without processors AsyncIterableWithReturn.webidl 1`] = ` +""use strict"; + +const conversions = require("webidl-conversions"); +const utils = require("./utils.js"); + +const Dictionary = require("./Dictionary.js"); +const newObjectInRealm = utils.newObjectInRealm; +const implSymbol = utils.implSymbol; +const ctorRegistrySymbol = utils.ctorRegistrySymbol; + +const interfaceName = "AsyncIterableWithReturn"; + +exports.is = value => { + return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; +}; +exports.isImpl = value => { + return utils.isObject(value) && value instanceof Impl.implementation; +}; +exports.convert = (globalObject, value, { context = "The provided value" } = {}) => { + if (exports.is(value)) { + return utils.implForWrapper(value); + } + throw new globalObject.TypeError(\`\${context} is not of type 'AsyncIterableWithReturn'.\`); +}; + +exports.createDefaultAsyncIterator = (globalObject, target, kind) => { + const ctorRegistry = globalObject[ctorRegistrySymbol]; + const asyncIteratorPrototype = ctorRegistry["AsyncIterableWithReturn AsyncIterator"]; const iterator = Object.create(asyncIteratorPrototype); Object.defineProperty(iterator, utils.iterInternalSymbol, { value: { target, kind, ongoingPromise: null, isFinished: false }, @@ -12079,7 +12927,7 @@ function makeWrapper(globalObject, newTarget) { } if (!utils.isObject(proto)) { - proto = globalObject[ctorRegistrySymbol]["AsyncIterableValueNoArgs"].prototype; + proto = globalObject[ctorRegistrySymbol]["AsyncIterableWithReturn"].prototype; } return Object.create(proto); @@ -12137,7 +12985,7 @@ exports.install = (globalObject, globalNames) => { } const ctorRegistry = utils.initCtorRegistry(globalObject); - class AsyncIterableValueNoArgs { + class AsyncIterableWithReturn { constructor() { throw new globalObject.TypeError("Illegal constructor"); } @@ -12145,11 +12993,15 @@ exports.install = (globalObject, globalNames) => { values() { if (!exports.is(this)) { throw new globalObject.TypeError( - "'values' called on an object that is not a valid instance of AsyncIterableValueNoArgs." + "'values' called on an object that is not a valid instance of AsyncIterableWithReturn." ); } const args = []; + args[0] = arguments[0]; + args[0] = Dictionary.convert(globalObject, args[0], { + context: "Failed to execute 'values' on 'AsyncIterableWithReturn': parameter 1" + }); const asyncIterator = exports.createDefaultAsyncIterator(globalObject, this, "value"); if (this[implSymbol][utils.asyncIteratorInit]) { @@ -12158,26 +13010,26 @@ exports.install = (globalObject, globalNames) => { return asyncIterator; } } - Object.defineProperties(AsyncIterableValueNoArgs.prototype, { + Object.defineProperties(AsyncIterableWithReturn.prototype, { values: { enumerable: true }, - [Symbol.toStringTag]: { value: "AsyncIterableValueNoArgs", configurable: true }, - [Symbol.asyncIterator]: { value: AsyncIterableValueNoArgs.prototype.values, configurable: true, writable: true } + [Symbol.toStringTag]: { value: "AsyncIterableWithReturn", configurable: true }, + [Symbol.asyncIterator]: { value: AsyncIterableWithReturn.prototype.values, configurable: true, writable: true } }); - ctorRegistry[interfaceName] = AsyncIterableValueNoArgs; + ctorRegistry[interfaceName] = AsyncIterableWithReturn; - ctorRegistry["AsyncIterableValueNoArgs AsyncIterator"] = Object.create(ctorRegistry["%AsyncIteratorPrototype%"], { + ctorRegistry["AsyncIterableWithReturn AsyncIterator"] = Object.create(ctorRegistry["%AsyncIteratorPrototype%"], { [Symbol.toStringTag]: { - value: "AsyncIterableValueNoArgs AsyncIterator", + value: "AsyncIterableWithReturn AsyncIterator", configurable: true } }); - utils.define(ctorRegistry["AsyncIterableValueNoArgs AsyncIterator"], { + utils.define(ctorRegistry["AsyncIterableWithReturn AsyncIterator"], { next() { const internal = this && this[utils.iterInternalSymbol]; if (!internal) { return globalObject.Promise.reject( new globalObject.TypeError( - "next() called on a value that is not a AsyncIterableValueNoArgs async iterator object" + "next() called on a value that is not a AsyncIterableWithReturn async iterator object" ) ); } @@ -12209,32 +13061,55 @@ exports.install = (globalObject, globalNames) => { ? internal.ongoingPromise.then(nextSteps, nextSteps) : nextSteps(); return internal.ongoingPromise; + }, + + return(value) { + const internal = this && this[utils.iterInternalSymbol]; + if (!internal) { + return globalObject.Promise.reject( + new globalObject.TypeError( + "return() called on a value that is not a AsyncIterableWithReturn async iterator object" + ) + ); + } + + const returnSteps = () => { + if (internal.isFinished) { + return globalObject.Promise.resolve(newObjectInRealm(globalObject, { value, done: true })); + } + internal.isFinished = true; + + return internal.target[implSymbol][utils.asyncIteratorReturn](this, value); + }; + + internal.ongoingPromise = internal.ongoingPromise + ? internal.ongoingPromise.then(returnSteps, returnSteps) + : returnSteps(); + return internal.ongoingPromise.then(() => newObjectInRealm(globalObject, { value, done: true })); } }); Object.defineProperty(globalObject, interfaceName, { configurable: true, writable: true, - value: AsyncIterableValueNoArgs + value: AsyncIterableWithReturn }); }; -const Impl = require("../implementations/AsyncIterableValueNoArgs.js"); +const Impl = require("../implementations/AsyncIterableWithReturn.js"); " `; -exports[`generation without processors AsyncIterableWithReturn.webidl 1`] = ` +exports[`generation without processors BufferSourceTypes.webidl 1`] = ` ""use strict"; const conversions = require("webidl-conversions"); const utils = require("./utils.js"); -const Dictionary = require("./Dictionary.js"); -const newObjectInRealm = utils.newObjectInRealm; const implSymbol = utils.implSymbol; const ctorRegistrySymbol = utils.ctorRegistrySymbol; -const interfaceName = "AsyncIterableWithReturn"; +const interfaceName = "BufferSourceTypes"; exports.is = value => { return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; @@ -12246,18 +13121,7 @@ exports.convert = (globalObject, value, { context = "The provided value" } = {}) if (exports.is(value)) { return utils.implForWrapper(value); } - throw new globalObject.TypeError(\`\${context} is not of type 'AsyncIterableWithReturn'.\`); -}; - -exports.createDefaultAsyncIterator = (globalObject, target, kind) => { - const ctorRegistry = globalObject[ctorRegistrySymbol]; - const asyncIteratorPrototype = ctorRegistry["AsyncIterableWithReturn AsyncIterator"]; - const iterator = Object.create(asyncIteratorPrototype); - Object.defineProperty(iterator, utils.iterInternalSymbol, { - value: { target, kind, ongoingPromise: null, isFinished: false }, - configurable: true - }); - return iterator; + throw new globalObject.TypeError(\`\${context} is not of type 'BufferSourceTypes'.\`); }; function makeWrapper(globalObject, newTarget) { @@ -12267,7 +13131,7 @@ function makeWrapper(globalObject, newTarget) { } if (!utils.isObject(proto)) { - proto = globalObject[ctorRegistrySymbol]["AsyncIterableWithReturn"].prototype; + proto = globalObject[ctorRegistrySymbol]["BufferSourceTypes"].prototype; } return Object.create(proto); @@ -12325,379 +13189,622 @@ exports.install = (globalObject, globalNames) => { } const ctorRegistry = utils.initCtorRegistry(globalObject); - class AsyncIterableWithReturn { + class BufferSourceTypes { constructor() { throw new globalObject.TypeError("Illegal constructor"); } - values() { - if (!exports.is(this)) { + bs(source) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError("'bs' called on an object that is not a valid instance of BufferSourceTypes."); + } + + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'bs' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + if (utils.isArrayBuffer(curArg)) { + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'bs' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); + } else if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'bs' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); + } else { + throw new globalObject.TypeError( + "Failed to execute 'bs' on 'BufferSourceTypes': parameter 1" + " is not of any supported type." + ); + } + args.push(curArg); + } + return esValue[implSymbol].bs(...args); + } + + ab(ab) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError("'ab' called on an object that is not a valid instance of BufferSourceTypes."); + } + + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'ab' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'ab' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); + args.push(curArg); + } + return esValue[implSymbol].ab(...args); + } + + sab(sab) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'sab' called on an object that is not a valid instance of BufferSourceTypes." + ); + } + + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'sab' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions["SharedArrayBuffer"](curArg, { + context: "Failed to execute 'sab' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); + args.push(curArg); + } + return esValue[implSymbol].sab(...args); + } + + abv(abv) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'abv' called on an object that is not a valid instance of BufferSourceTypes." + ); + } + + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'abv' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'abv' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); + } else { + throw new globalObject.TypeError( + "Failed to execute 'abv' on 'BufferSourceTypes': parameter 1" + " is not of any supported type." + ); + } + args.push(curArg); + } + return esValue[implSymbol].abv(...args); + } + + u8a(u8) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'u8a' called on an object that is not a valid instance of BufferSourceTypes." + ); + } + + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'u8a' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions["Uint8Array"](curArg, { + context: "Failed to execute 'u8a' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); + args.push(curArg); + } + return esValue[implSymbol].u8a(...args); + } + + abUnion(ab) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'abUnion' called on an object that is not a valid instance of BufferSourceTypes." + ); + } + + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'abUnion' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + if (utils.isArrayBuffer(curArg)) { + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'abUnion' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); + } else { + curArg = conversions["DOMString"](curArg, { + context: "Failed to execute 'abUnion' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); + } + args.push(curArg); + } + return esValue[implSymbol].abUnion(...args); + } + + sabUnion(ab) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'sabUnion' called on an object that is not a valid instance of BufferSourceTypes." + ); + } + + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'sabUnion' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + if (utils.isSharedArrayBuffer(curArg)) { + curArg = conversions["SharedArrayBuffer"](curArg, { + context: "Failed to execute 'sabUnion' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); + } else { + curArg = conversions["DOMString"](curArg, { + context: "Failed to execute 'sabUnion' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); + } + args.push(curArg); + } + return esValue[implSymbol].sabUnion(...args); + } + + u8aUnion(ab) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { throw new globalObject.TypeError( - "'values' called on an object that is not a valid instance of AsyncIterableWithReturn." + "'u8aUnion' called on an object that is not a valid instance of BufferSourceTypes." ); } + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'u8aUnion' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } const args = []; - args[0] = arguments[0]; - args[0] = Dictionary.convert(globalObject, args[0], { - context: "Failed to execute 'values' on 'AsyncIterableWithReturn': parameter 1" - }); - - const asyncIterator = exports.createDefaultAsyncIterator(globalObject, this, "value"); - if (this[implSymbol][utils.asyncIteratorInit]) { - this[implSymbol][utils.asyncIteratorInit](asyncIterator, args); + { + let curArg = arguments[0]; + if (ArrayBuffer.isView(curArg) && curArg.constructor.name === "Uint8Array") { + curArg = conversions["Uint8Array"](curArg, { + context: "Failed to execute 'u8aUnion' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); + } else { + curArg = conversions["DOMString"](curArg, { + context: "Failed to execute 'u8aUnion' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); + } + args.push(curArg); } - return asyncIterator; + return esValue[implSymbol].u8aUnion(...args); } - } - Object.defineProperties(AsyncIterableWithReturn.prototype, { - values: { enumerable: true }, - [Symbol.toStringTag]: { value: "AsyncIterableWithReturn", configurable: true }, - [Symbol.asyncIterator]: { value: AsyncIterableWithReturn.prototype.values, configurable: true, writable: true } - }); - ctorRegistry[interfaceName] = AsyncIterableWithReturn; - ctorRegistry["AsyncIterableWithReturn AsyncIterator"] = Object.create(ctorRegistry["%AsyncIteratorPrototype%"], { - [Symbol.toStringTag]: { - value: "AsyncIterableWithReturn AsyncIterator", - configurable: true - } - }); - utils.define(ctorRegistry["AsyncIterableWithReturn AsyncIterator"], { - next() { - const internal = this && this[utils.iterInternalSymbol]; - if (!internal) { - return globalObject.Promise.reject( - new globalObject.TypeError( - "next() called on a value that is not a AsyncIterableWithReturn async iterator object" - ) + asbs(source) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'asbs' called on an object that is not a valid instance of BufferSourceTypes." ); } - const nextSteps = () => { - if (internal.isFinished) { - return globalObject.Promise.resolve(newObjectInRealm(globalObject, { value: undefined, done: true })); + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'asbs' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + if (utils.isArrayBuffer(curArg)) { + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'asbs' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); + } else if (utils.isSharedArrayBuffer(curArg)) { + curArg = conversions["SharedArrayBuffer"](curArg, { + context: "Failed to execute 'asbs' on 'BufferSourceTypes': parameter 1", + globals: globalObject + }); + } else if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'asbs' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowShared: true + }); + } else { + throw new globalObject.TypeError( + "Failed to execute 'asbs' on 'BufferSourceTypes': parameter 1" + " is not of any supported type." + ); } + args.push(curArg); + } + return esValue[implSymbol].asbs(...args); + } - const nextPromise = internal.target[implSymbol][utils.asyncIteratorNext](this); - return nextPromise.then( - next => { - internal.ongoingPromise = null; - if (next === utils.asyncIteratorEOI) { - internal.isFinished = true; - return newObjectInRealm(globalObject, { value: undefined, done: true }); - } - return newObjectInRealm(globalObject, { value: utils.tryWrapperForImpl(next), done: false }); - }, - reason => { - internal.ongoingPromise = null; - internal.isFinished = true; - throw reason; - } + abvAllowShared(abv) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'abvAllowShared' called on an object that is not a valid instance of BufferSourceTypes." ); - }; - - internal.ongoingPromise = internal.ongoingPromise - ? internal.ongoingPromise.then(nextSteps, nextSteps) - : nextSteps(); - return internal.ongoingPromise; - }, + } - return(value) { - const internal = this && this[utils.iterInternalSymbol]; - if (!internal) { - return globalObject.Promise.reject( - new globalObject.TypeError( - "return() called on a value that is not a AsyncIterableWithReturn async iterator object" - ) + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'abvAllowShared' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` ); } - - const returnSteps = () => { - if (internal.isFinished) { - return globalObject.Promise.resolve(newObjectInRealm(globalObject, { value, done: true })); + const args = []; + { + let curArg = arguments[0]; + if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'abvAllowShared' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowShared: true + }); + } else { + throw new globalObject.TypeError( + "Failed to execute 'abvAllowShared' on 'BufferSourceTypes': parameter 1" + " is not of any supported type." + ); } - internal.isFinished = true; - - return internal.target[implSymbol][utils.asyncIteratorReturn](this, value); - }; - - internal.ongoingPromise = internal.ongoingPromise - ? internal.ongoingPromise.then(returnSteps, returnSteps) - : returnSteps(); - return internal.ongoingPromise.then(() => newObjectInRealm(globalObject, { value, done: true })); + args.push(curArg); + } + return esValue[implSymbol].abvAllowShared(...args); } - }); - - Object.defineProperty(globalObject, interfaceName, { - configurable: true, - writable: true, - value: AsyncIterableWithReturn - }); -}; - -const Impl = require("../implementations/AsyncIterableWithReturn.js"); -" -`; - -exports[`generation without processors BufferSourceTypes.webidl 1`] = ` -""use strict"; - -const conversions = require("webidl-conversions"); -const utils = require("./utils.js"); - -const implSymbol = utils.implSymbol; -const ctorRegistrySymbol = utils.ctorRegistrySymbol; - -const interfaceName = "BufferSourceTypes"; - -exports.is = value => { - return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; -}; -exports.isImpl = value => { - return utils.isObject(value) && value instanceof Impl.implementation; -}; -exports.convert = (globalObject, value, { context = "The provided value" } = {}) => { - if (exports.is(value)) { - return utils.implForWrapper(value); - } - throw new globalObject.TypeError(\`\${context} is not of type 'BufferSourceTypes'.\`); -}; - -function makeWrapper(globalObject, newTarget) { - let proto; - if (newTarget !== undefined) { - proto = newTarget.prototype; - } - - if (!utils.isObject(proto)) { - proto = globalObject[ctorRegistrySymbol]["BufferSourceTypes"].prototype; - } - - return Object.create(proto); -} - -exports.create = (globalObject, constructorArgs, privateData) => { - const wrapper = makeWrapper(globalObject); - return exports.setup(wrapper, globalObject, constructorArgs, privateData); -}; - -exports.createImpl = (globalObject, constructorArgs, privateData) => { - const wrapper = exports.create(globalObject, constructorArgs, privateData); - return utils.implForWrapper(wrapper); -}; - -exports._internalSetup = (wrapper, globalObject) => {}; - -exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => { - privateData.wrapper = wrapper; - - exports._internalSetup(wrapper, globalObject); - Object.defineProperty(wrapper, implSymbol, { - value: new Impl.implementation(globalObject, constructorArgs, privateData), - configurable: true - }); - - wrapper[implSymbol][utils.wrapperSymbol] = wrapper; - if (Impl.init) { - Impl.init(wrapper[implSymbol]); - } - return wrapper; -}; - -exports.new = (globalObject, newTarget) => { - const wrapper = makeWrapper(globalObject, newTarget); - - exports._internalSetup(wrapper, globalObject); - Object.defineProperty(wrapper, implSymbol, { - value: Object.create(Impl.implementation.prototype), - configurable: true - }); - - wrapper[implSymbol][utils.wrapperSymbol] = wrapper; - if (Impl.init) { - Impl.init(wrapper[implSymbol]); - } - return wrapper[implSymbol]; -}; - -const exposed = new Set(["Window"]); -exports.install = (globalObject, globalNames) => { - if (!globalNames.some(globalName => exposed.has(globalName))) { - return; - } + u8aAllowShared(u8) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'u8aAllowShared' called on an object that is not a valid instance of BufferSourceTypes." + ); + } - const ctorRegistry = utils.initCtorRegistry(globalObject); - class BufferSourceTypes { - constructor() { - throw new globalObject.TypeError("Illegal constructor"); + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'u8aAllowShared' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions["Uint8Array"](curArg, { + context: "Failed to execute 'u8aAllowShared' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowShared: true + }); + args.push(curArg); + } + return esValue[implSymbol].u8aAllowShared(...args); } - bs(source) { + bsAllowResizable(source) { const esValue = this !== null && this !== undefined ? this : globalObject; if (!exports.is(esValue)) { - throw new globalObject.TypeError("'bs' called on an object that is not a valid instance of BufferSourceTypes."); + throw new globalObject.TypeError( + "'bsAllowResizable' called on an object that is not a valid instance of BufferSourceTypes." + ); } if (arguments.length < 1) { throw new globalObject.TypeError( - \`Failed to execute 'bs' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + \`Failed to execute 'bsAllowResizable' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` ); } const args = []; { let curArg = arguments[0]; if (utils.isArrayBuffer(curArg)) { + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'bsAllowResizable' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true + }); } else if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'bsAllowResizable' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true + }); } else { throw new globalObject.TypeError( - "Failed to execute 'bs' on 'BufferSourceTypes': parameter 1" + " is not of any supported type." + "Failed to execute 'bsAllowResizable' on 'BufferSourceTypes': parameter 1" + + " is not of any supported type." ); } args.push(curArg); } - return esValue[implSymbol].bs(...args); + return esValue[implSymbol].bsAllowResizable(...args); } - ab(ab) { + abAllowResizable(ab) { const esValue = this !== null && this !== undefined ? this : globalObject; if (!exports.is(esValue)) { - throw new globalObject.TypeError("'ab' called on an object that is not a valid instance of BufferSourceTypes."); + throw new globalObject.TypeError( + "'abAllowResizable' called on an object that is not a valid instance of BufferSourceTypes." + ); } if (arguments.length < 1) { throw new globalObject.TypeError( - \`Failed to execute 'ab' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + \`Failed to execute 'abAllowResizable' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` ); } const args = []; { let curArg = arguments[0]; curArg = conversions["ArrayBuffer"](curArg, { - context: "Failed to execute 'ab' on 'BufferSourceTypes': parameter 1", - globals: globalObject + context: "Failed to execute 'abAllowResizable' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true }); args.push(curArg); } - return esValue[implSymbol].ab(...args); + return esValue[implSymbol].abAllowResizable(...args); } - abv(abv) { + sabAllowResizable(sab) { const esValue = this !== null && this !== undefined ? this : globalObject; if (!exports.is(esValue)) { throw new globalObject.TypeError( - "'abv' called on an object that is not a valid instance of BufferSourceTypes." + "'sabAllowResizable' called on an object that is not a valid instance of BufferSourceTypes." ); } if (arguments.length < 1) { throw new globalObject.TypeError( - \`Failed to execute 'abv' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + \`Failed to execute 'sabAllowResizable' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions["SharedArrayBuffer"](curArg, { + context: "Failed to execute 'sabAllowResizable' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true + }); + args.push(curArg); + } + return esValue[implSymbol].sabAllowResizable(...args); + } + + abvAllowResizable(abv) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'abvAllowResizable' called on an object that is not a valid instance of BufferSourceTypes." + ); + } + + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'abvAllowResizable' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` ); } const args = []; { let curArg = arguments[0]; if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'abvAllowResizable' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true + }); } else { throw new globalObject.TypeError( - "Failed to execute 'abv' on 'BufferSourceTypes': parameter 1" + " is not of any supported type." + "Failed to execute 'abvAllowResizable' on 'BufferSourceTypes': parameter 1" + + " is not of any supported type." ); } args.push(curArg); } - return esValue[implSymbol].abv(...args); + return esValue[implSymbol].abvAllowResizable(...args); } - u8a(u8) { + u8aAllowResizable(u8) { const esValue = this !== null && this !== undefined ? this : globalObject; if (!exports.is(esValue)) { throw new globalObject.TypeError( - "'u8a' called on an object that is not a valid instance of BufferSourceTypes." + "'u8aAllowResizable' called on an object that is not a valid instance of BufferSourceTypes." ); } if (arguments.length < 1) { throw new globalObject.TypeError( - \`Failed to execute 'u8a' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + \`Failed to execute 'u8aAllowResizable' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` ); } const args = []; { let curArg = arguments[0]; curArg = conversions["Uint8Array"](curArg, { - context: "Failed to execute 'u8a' on 'BufferSourceTypes': parameter 1", - globals: globalObject + context: "Failed to execute 'u8aAllowResizable' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true }); args.push(curArg); } - return esValue[implSymbol].u8a(...args); + return esValue[implSymbol].u8aAllowResizable(...args); } - abUnion(ab) { + asbsAllowResizable(source) { const esValue = this !== null && this !== undefined ? this : globalObject; if (!exports.is(esValue)) { throw new globalObject.TypeError( - "'abUnion' called on an object that is not a valid instance of BufferSourceTypes." + "'asbsAllowResizable' called on an object that is not a valid instance of BufferSourceTypes." ); } if (arguments.length < 1) { throw new globalObject.TypeError( - \`Failed to execute 'abUnion' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + \`Failed to execute 'asbsAllowResizable' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` ); } const args = []; { let curArg = arguments[0]; if (utils.isArrayBuffer(curArg)) { - } else { - curArg = conversions["DOMString"](curArg, { - context: "Failed to execute 'abUnion' on 'BufferSourceTypes': parameter 1", - globals: globalObject + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'asbsAllowResizable' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true + }); + } else if (utils.isSharedArrayBuffer(curArg)) { + curArg = conversions["SharedArrayBuffer"](curArg, { + context: "Failed to execute 'asbsAllowResizable' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true + }); + } else if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'asbsAllowResizable' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true, + allowShared: true }); + } else { + throw new globalObject.TypeError( + "Failed to execute 'asbsAllowResizable' on 'BufferSourceTypes': parameter 1" + + " is not of any supported type." + ); } args.push(curArg); } - return esValue[implSymbol].abUnion(...args); + return esValue[implSymbol].asbsAllowResizable(...args); } - u8aUnion(ab) { + abvAllowResizableShared(abv) { const esValue = this !== null && this !== undefined ? this : globalObject; if (!exports.is(esValue)) { throw new globalObject.TypeError( - "'u8aUnion' called on an object that is not a valid instance of BufferSourceTypes." + "'abvAllowResizableShared' called on an object that is not a valid instance of BufferSourceTypes." ); } if (arguments.length < 1) { throw new globalObject.TypeError( - \`Failed to execute 'u8aUnion' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + \`Failed to execute 'abvAllowResizableShared' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` ); } const args = []; { let curArg = arguments[0]; - if (ArrayBuffer.isView(curArg) && curArg.constructor.name === "Uint8Array") { - } else { - curArg = conversions["DOMString"](curArg, { - context: "Failed to execute 'u8aUnion' on 'BufferSourceTypes': parameter 1", - globals: globalObject + if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'abvAllowResizableShared' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true, + allowShared: true }); + } else { + throw new globalObject.TypeError( + "Failed to execute 'abvAllowResizableShared' on 'BufferSourceTypes': parameter 1" + + " is not of any supported type." + ); } args.push(curArg); } - return esValue[implSymbol].u8aUnion(...args); + return esValue[implSymbol].abvAllowResizableShared(...args); + } + + u8aAllowResizableShared(u8) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'u8aAllowResizableShared' called on an object that is not a valid instance of BufferSourceTypes." + ); + } + + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'u8aAllowResizableShared' on 'BufferSourceTypes': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + curArg = conversions["Uint8Array"](curArg, { + context: "Failed to execute 'u8aAllowResizableShared' on 'BufferSourceTypes': parameter 1", + globals: globalObject, + allowResizable: true, + allowShared: true + }); + args.push(curArg); + } + return esValue[implSymbol].u8aAllowResizableShared(...args); } } Object.defineProperties(BufferSourceTypes.prototype, { bs: { enumerable: true }, ab: { enumerable: true }, + sab: { enumerable: true }, abv: { enumerable: true }, u8a: { enumerable: true }, abUnion: { enumerable: true }, + sabUnion: { enumerable: true }, u8aUnion: { enumerable: true }, + asbs: { enumerable: true }, + abvAllowShared: { enumerable: true }, + u8aAllowShared: { enumerable: true }, + bsAllowResizable: { enumerable: true }, + abAllowResizable: { enumerable: true }, + sabAllowResizable: { enumerable: true }, + abvAllowResizable: { enumerable: true }, + u8aAllowResizable: { enumerable: true }, + asbsAllowResizable: { enumerable: true }, + abvAllowResizableShared: { enumerable: true }, + u8aAllowResizableShared: { enumerable: true }, [Symbol.toStringTag]: { value: "BufferSourceTypes", configurable: true } }); ctorRegistry[interfaceName] = BufferSourceTypes; @@ -16773,7 +17880,15 @@ exports.install = (globalObject, globalNames) => { { let curArg = arguments[1]; if (utils.isArrayBuffer(curArg)) { + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'incompatible3' on 'Overloads': parameter 2", + globals: globalObject + }); } else if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'incompatible3' on 'Overloads': parameter 2", + globals: globalObject + }); } else { throw new globalObject.TypeError( "Failed to execute 'incompatible3' on 'Overloads': parameter 2" + " is not of any supported type." @@ -16785,7 +17900,15 @@ exports.install = (globalObject, globalNames) => { { let curArg = arguments[1]; if (utils.isArrayBuffer(curArg)) { + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'incompatible3' on 'Overloads': parameter 2", + globals: globalObject + }); } else if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'incompatible3' on 'Overloads': parameter 2", + globals: globalObject + }); } else { throw new globalObject.TypeError( "Failed to execute 'incompatible3' on 'Overloads': parameter 2" + " is not of any supported type." @@ -16830,7 +17953,15 @@ exports.install = (globalObject, globalNames) => { { let curArg = arguments[2]; if (utils.isArrayBuffer(curArg)) { + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'incompatible3' on 'Overloads': parameter 3", + globals: globalObject + }); } else if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'incompatible3' on 'Overloads': parameter 3", + globals: globalObject + }); } else { throw new globalObject.TypeError( "Failed to execute 'incompatible3' on 'Overloads': parameter 3" + " is not of any supported type." @@ -16841,7 +17972,15 @@ exports.install = (globalObject, globalNames) => { { let curArg = arguments[3]; if (utils.isArrayBuffer(curArg)) { + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'incompatible3' on 'Overloads': parameter 4", + globals: globalObject + }); } else if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'incompatible3' on 'Overloads': parameter 4", + globals: globalObject + }); } else { throw new globalObject.TypeError( "Failed to execute 'incompatible3' on 'Overloads': parameter 4" + " is not of any supported type." @@ -19039,6 +20178,8 @@ const utils = require("./utils.js"); const RequestDestination = require("./RequestDestination.js"); const URL = require("./URL.js"); +const AsyncCallbackFunction = require("./AsyncCallbackFunction.js"); +const AsyncCallbackInterface = require("./AsyncCallbackInterface.js"); const implSymbol = utils.implSymbol; const ctorRegistrySymbol = utils.ctorRegistrySymbol; @@ -19275,6 +20416,42 @@ exports.install = (globalObject, globalNames) => { return esValue[implSymbol].numOrStrOrURLOrNullConsumer(...args); } + numOrObjConsumer(a) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'numOrObjConsumer' called on an object that is not a valid instance of TypedefsAndUnions." + ); + } + + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'numOrObjConsumer' on 'TypedefsAndUnions': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + if (utils.isObject(curArg)) { + if (curArg[utils.implSymbol]) { + curArg = utils.implForWrapper(curArg); + } + } else if (typeof curArg === "number") { + curArg = conversions["double"](curArg, { + context: "Failed to execute 'numOrObjConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); + } else { + curArg = conversions["double"](curArg, { + context: "Failed to execute 'numOrObjConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); + } + args.push(curArg); + } + return esValue[implSymbol].numOrObjConsumer(...args); + } + urlMapInnerConsumer(a) { const esValue = this !== null && this !== undefined ? this : globalObject; if (!exports.is(esValue)) { @@ -19394,7 +20571,15 @@ exports.install = (globalObject, globalNames) => { if (URL.is(curArg)) { curArg = utils.implForWrapper(curArg); } else if (utils.isArrayBuffer(curArg)) { + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'bufferSourceOrURLConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); } else if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'bufferSourceOrURLConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); } else { throw new globalObject.TypeError( "Failed to execute 'bufferSourceOrURLConsumer' on 'TypedefsAndUnions': parameter 1" + @@ -19426,6 +20611,10 @@ exports.install = (globalObject, globalNames) => { curArg = null; } else { if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'arrayBufferViewOrURLMapConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); } else if (utils.isObject(curArg)) { if (!utils.isObject(curArg)) { throw new globalObject.TypeError( @@ -19491,6 +20680,10 @@ exports.install = (globalObject, globalNames) => { { let curArg = arguments[0]; if (ArrayBuffer.isView(curArg)) { + curArg = conversions["ArrayBufferView"](curArg, { + context: "Failed to execute 'arrayBufferViewDupConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); } else { throw new globalObject.TypeError( "Failed to execute 'arrayBufferViewDupConsumer' on 'TypedefsAndUnions': parameter 1" + @@ -19502,6 +20695,119 @@ exports.install = (globalObject, globalNames) => { return esValue[implSymbol].arrayBufferViewDupConsumer(...args); } + arrayBufferOrSharedArrayBufferConsumer(b) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'arrayBufferOrSharedArrayBufferConsumer' called on an object that is not a valid instance of TypedefsAndUnions." + ); + } + + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'arrayBufferOrSharedArrayBufferConsumer' on 'TypedefsAndUnions': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + if (utils.isArrayBuffer(curArg)) { + curArg = conversions["ArrayBuffer"](curArg, { + context: "Failed to execute 'arrayBufferOrSharedArrayBufferConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); + } else if (utils.isSharedArrayBuffer(curArg)) { + curArg = conversions["SharedArrayBuffer"](curArg, { + context: "Failed to execute 'arrayBufferOrSharedArrayBufferConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); + } else { + throw new globalObject.TypeError( + "Failed to execute 'arrayBufferOrSharedArrayBufferConsumer' on 'TypedefsAndUnions': parameter 1" + + " is not of any supported type." + ); + } + args.push(curArg); + } + return esValue[implSymbol].arrayBufferOrSharedArrayBufferConsumer(...args); + } + + callbackFunctionOrNumConsumer(cb) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'callbackFunctionOrNumConsumer' called on an object that is not a valid instance of TypedefsAndUnions." + ); + } + + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'callbackFunctionOrNumConsumer' on 'TypedefsAndUnions': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + if (typeof curArg === "function") { + curArg = AsyncCallbackFunction.convert(globalObject, curArg, { + context: + "Failed to execute 'callbackFunctionOrNumConsumer' on 'TypedefsAndUnions': parameter 1" + + " callback function" + }); + } else if (typeof curArg === "number") { + curArg = conversions["double"](curArg, { + context: "Failed to execute 'callbackFunctionOrNumConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); + } else { + curArg = conversions["double"](curArg, { + context: "Failed to execute 'callbackFunctionOrNumConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); + } + args.push(curArg); + } + return esValue[implSymbol].callbackFunctionOrNumConsumer(...args); + } + + callbackInterfaceOrNumConsumer(cb) { + const esValue = this !== null && this !== undefined ? this : globalObject; + if (!exports.is(esValue)) { + throw new globalObject.TypeError( + "'callbackInterfaceOrNumConsumer' called on an object that is not a valid instance of TypedefsAndUnions." + ); + } + + if (arguments.length < 1) { + throw new globalObject.TypeError( + \`Failed to execute 'callbackInterfaceOrNumConsumer' on 'TypedefsAndUnions': 1 argument required, but only \${arguments.length} present.\` + ); + } + const args = []; + { + let curArg = arguments[0]; + if (utils.isObject(curArg)) { + curArg = AsyncCallbackInterface.convert(globalObject, curArg, { + context: + "Failed to execute 'callbackInterfaceOrNumConsumer' on 'TypedefsAndUnions': parameter 1" + + " callback interface" + }); + } else if (typeof curArg === "number") { + curArg = conversions["double"](curArg, { + context: "Failed to execute 'callbackInterfaceOrNumConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); + } else { + curArg = conversions["double"](curArg, { + context: "Failed to execute 'callbackInterfaceOrNumConsumer' on 'TypedefsAndUnions': parameter 1", + globals: globalObject + }); + } + args.push(curArg); + } + return esValue[implSymbol].callbackInterfaceOrNumConsumer(...args); + } + get buf() { const esValue = this !== null && this !== undefined ? this : globalObject; @@ -19524,10 +20830,20 @@ exports.install = (globalObject, globalNames) => { } if (utils.isArrayBuffer(V)) { - } else if ( - ArrayBuffer.isView(V) && - (V.constructor.name === "Uint8Array" || V.constructor.name === "Uint16Array") - ) { + V = conversions["ArrayBuffer"](V, { + context: "Failed to set the 'buf' property on 'TypedefsAndUnions': The provided value", + globals: globalObject + }); + } else if (ArrayBuffer.isView(V) && V.constructor.name === "Uint8Array") { + V = conversions["Uint8Array"](V, { + context: "Failed to set the 'buf' property on 'TypedefsAndUnions': The provided value", + globals: globalObject + }); + } else if (ArrayBuffer.isView(V) && V.constructor.name === "Uint16Array") { + V = conversions["Uint16Array"](V, { + context: "Failed to set the 'buf' property on 'TypedefsAndUnions': The provided value", + globals: globalObject + }); } else { throw new globalObject.TypeError( "Failed to set the 'buf' property on 'TypedefsAndUnions': The provided value" + @@ -19571,11 +20887,15 @@ exports.install = (globalObject, globalNames) => { numOrEnumConsumer: { enumerable: true }, numOrStrOrNullConsumer: { enumerable: true }, numOrStrOrURLOrNullConsumer: { enumerable: true }, + numOrObjConsumer: { enumerable: true }, urlMapInnerConsumer: { enumerable: true }, urlMapConsumer: { enumerable: true }, bufferSourceOrURLConsumer: { enumerable: true }, arrayBufferViewOrURLMapConsumer: { enumerable: true }, arrayBufferViewDupConsumer: { enumerable: true }, + arrayBufferOrSharedArrayBufferConsumer: { enumerable: true }, + callbackFunctionOrNumConsumer: { enumerable: true }, + callbackInterfaceOrNumConsumer: { enumerable: true }, buf: { enumerable: true }, time: { enumerable: true }, [Symbol.toStringTag]: { value: "TypedefsAndUnions", configurable: true } diff --git a/test/cases/BufferSourceTypes.webidl b/test/cases/BufferSourceTypes.webidl index 26d7ef9b..6651551e 100644 --- a/test/cases/BufferSourceTypes.webidl +++ b/test/cases/BufferSourceTypes.webidl @@ -2,9 +2,25 @@ interface BufferSourceTypes { undefined bs(BufferSource source); undefined ab(ArrayBuffer ab); + undefined sab(SharedArrayBuffer sab); undefined abv(ArrayBufferView abv); undefined u8a(Uint8Array u8); undefined abUnion((ArrayBuffer or DOMString) ab); + undefined sabUnion((SharedArrayBuffer or DOMString) ab); undefined u8aUnion((Uint8Array or DOMString) ab); + + undefined asbs(AllowSharedBufferSource source); + undefined abvAllowShared([AllowShared] ArrayBufferView abv); + undefined u8aAllowShared([AllowShared] Uint8Array u8); + + undefined bsAllowResizable([AllowResizable] BufferSource source); + undefined abAllowResizable([AllowResizable] ArrayBuffer ab); + undefined sabAllowResizable([AllowResizable] SharedArrayBuffer sab); + undefined abvAllowResizable([AllowResizable] ArrayBufferView abv); + undefined u8aAllowResizable([AllowResizable] Uint8Array u8); + + undefined asbsAllowResizable([AllowResizable] AllowSharedBufferSource source); + undefined abvAllowResizableShared([AllowResizable, AllowShared] ArrayBufferView abv); + undefined u8aAllowResizableShared([AllowResizable, AllowShared] Uint8Array u8); }; diff --git a/test/cases/TypedefsAndUnions.webidl b/test/cases/TypedefsAndUnions.webidl index 35420208..7e08630d 100644 --- a/test/cases/TypedefsAndUnions.webidl +++ b/test/cases/TypedefsAndUnions.webidl @@ -4,11 +4,15 @@ interface TypedefsAndUnions { undefined numOrEnumConsumer((double or RequestDestination)? a); undefined numOrStrOrNullConsumer(NumOrStrOrNull a); undefined numOrStrOrURLOrNullConsumer(NumOrStrOrURLOrNull? a); + undefined numOrObjConsumer((double or object) a); undefined urlMapInnerConsumer(URLMapInner a); undefined urlMapConsumer(URLMap a); undefined bufferSourceOrURLConsumer((BufferSource or URL) b); undefined arrayBufferViewOrURLMapConsumer((ArrayBufferView or URLMap) b); undefined arrayBufferViewDupConsumer((ArrayBufferView or Uint8ClampedArray) b); + undefined arrayBufferOrSharedArrayBufferConsumer((ArrayBuffer or SharedArrayBuffer) b); + undefined callbackFunctionOrNumConsumer((AsyncCallbackFunction or double) cb); + undefined callbackInterfaceOrNumConsumer((AsyncCallbackInterface or double) cb); attribute (ArrayBuffer or Uint8Array or Uint16Array) buf; attribute DOMTimeStamp time;