From 1429ea246946014f91db7bddcf82191a8d624fd7 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sun, 28 Apr 2019 17:30:53 +0900 Subject: [PATCH 1/3] fix compiler error --- src/emitter.ts | 2 +- src/widlprocess.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/emitter.ts b/src/emitter.ts index cc321cfa3..de8846eec 100644 --- a/src/emitter.ts +++ b/src/emitter.ts @@ -689,7 +689,7 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { /// Emit the properties and methods of a given interface function emitMembers(prefix: string, emitScope: EmitScope, i: Browser.Interface) { - const conflictedMembers = extendConflictsBaseTypes[i.name] ? extendConflictsBaseTypes[i.name].memberNames : new Set(); + const conflictedMembers = extendConflictsBaseTypes[i.name] ? extendConflictsBaseTypes[i.name].memberNames : new Set(); emitProperties(prefix, emitScope, i); const methodPrefix = prefix.startsWith("declare var") ? "declare function " : ""; emitMethods(methodPrefix, emitScope, i, conflictedMembers); diff --git a/src/widlprocess.ts b/src/widlprocess.ts index 2f7b7f3f7..dda75c7af 100644 --- a/src/widlprocess.ts +++ b/src/widlprocess.ts @@ -197,7 +197,7 @@ function convertOperation(operation: webidl2.OperationMemberType, inheritedExpos throw new Error("Unexpected anonymous operation"); } return { - name: operation.name, + name: operation.name || undefined, signature: [{ ...convertIdlType(operation.idlType), param: operation.arguments.map(convertArgument) From 9a261a85b2a88f64da372072f8cff3ee84fc9686 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sun, 28 Apr 2019 17:32:41 +0900 Subject: [PATCH 2/3] emit iterable arguments --- baselines/dom.iterable.generated.d.ts | 64 +++++++++++++++++++++++++++ src/emitter.ts | 53 +++++++++++++++++++--- 2 files changed, 112 insertions(+), 5 deletions(-) diff --git a/baselines/dom.iterable.generated.d.ts b/baselines/dom.iterable.generated.d.ts index 3b964900c..bde5f2bb7 100644 --- a/baselines/dom.iterable.generated.d.ts +++ b/baselines/dom.iterable.generated.d.ts @@ -2,6 +2,10 @@ /// DOM Iterable APIs ///////////////////////////// +interface AudioParam { + setValueCurveAtTime(values: Iterable, startTime: number, duration: number): AudioParam; +} + interface AudioParamMap extends ReadonlyMap { } @@ -9,6 +13,11 @@ interface AudioTrackList { [Symbol.iterator](): IterableIterator; } +interface BaseAudioContext { + createIIRFilter(feedforward: Iterable, feedback: Iterable): IIRFilterNode; + createPeriodicWave(real: Iterable, imag: Iterable, constraints?: PeriodicWaveConstraints): PeriodicWave; +} + interface CSSRuleList { [Symbol.iterator](): IterableIterator; } @@ -17,6 +26,14 @@ interface CSSStyleDeclaration { [Symbol.iterator](): IterableIterator; } +interface Cache { + addAll(requests: Iterable): Promise; +} + +interface CanvasPathDrawingStyles { + setLineDash(segments: Iterable): void; +} + interface ClientRectList { [Symbol.iterator](): IterableIterator; } @@ -96,6 +113,15 @@ interface Headers { values(): IterableIterator; } +interface IDBObjectStore { + /** + * Creates a new index in store with the given name, keyPath and options and returns a new IDBIndex. If the keyPath and options define constraints that cannot be satisfied with the data already in store the upgrade transaction will abort with a "ConstraintError" DOMException. + * + * Throws an "InvalidStateError" DOMException if not called within an upgrade transaction. + */ + createIndex(name: string, keyPath: string | Iterable, options?: IDBIndexParameters): IDBIndex; +} + interface MediaKeyStatusMap { [Symbol.iterator](): IterableIterator<[BufferSource, MediaKeyStatus]>; entries(): IterableIterator<[BufferSource, MediaKeyStatus]>; @@ -115,6 +141,10 @@ interface NamedNodeMap { [Symbol.iterator](): IterableIterator; } +interface Navigator { + requestMediaKeySystemAccess(keySystem: string, supportedConfigurations: Iterable): Promise; +} + interface NodeList { [Symbol.iterator](): IterableIterator; /** @@ -155,6 +185,10 @@ interface PluginArray { [Symbol.iterator](): IterableIterator; } +interface RTCRtpTransceiver { + setCodecPreferences(codecs: Iterable): void; +} + interface RTCStatsReport extends ReadonlyMap { } @@ -222,6 +256,36 @@ interface URLSearchParams { values(): IterableIterator; } +interface VRDisplay { + requestPresent(layers: Iterable): Promise; +} + interface VideoTrackList { [Symbol.iterator](): IterableIterator; } + +interface WEBGL_draw_buffers { + drawBuffersWEBGL(buffers: Iterable): void; +} + +interface WebAuthentication { + makeCredential(accountInformation: Account, cryptoParameters: Iterable, attestationChallenge: Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer | null, options?: ScopedCredentialOptions): Promise; +} + +interface WebGLRenderingContextBase { + uniform1fv(location: WebGLUniformLocation | null, v: Iterable): void; + uniform2fv(location: WebGLUniformLocation | null, v: Iterable): void; + uniform3fv(location: WebGLUniformLocation | null, v: Iterable): void; + uniform4fv(location: WebGLUniformLocation | null, v: Iterable): void; + uniform1iv(location: WebGLUniformLocation | null, v: Iterable): void; + uniform2iv(location: WebGLUniformLocation | null, v: Iterable): void; + uniform3iv(location: WebGLUniformLocation | null, v: Iterable): void; + uniform4iv(location: WebGLUniformLocation | null, v: Iterable): void; + uniformMatrix2fv(location: WebGLUniformLocation | null, transpose: GLboolean, value: Iterable): void; + uniformMatrix3fv(location: WebGLUniformLocation | null, transpose: GLboolean, value: Iterable): void; + uniformMatrix4fv(location: WebGLUniformLocation | null, transpose: GLboolean, value: Iterable): void; + vertexAttrib1fv(index: GLuint, values: Iterable): void; + vertexAttrib2fv(index: GLuint, values: Iterable): void; + vertexAttrib3fv(index: GLuint, values: Iterable): void; + vertexAttrib4fv(index: GLuint, values: Iterable): void; +} diff --git a/src/emitter.ts b/src/emitter.ts index de8846eec..5e0f3974b 100644 --- a/src/emitter.ts +++ b/src/emitter.ts @@ -314,6 +314,9 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { } function convertDomTypeToTsTypeSimple(objDomType: string): string { + if (objDomType === "sequence" && flavor === Flavor.ES6Iterators) { + return "Iterable"; + } if (baseTypeConversionMap.has(objDomType)) { return baseTypeConversionMap.get(objDomType)!; } @@ -1194,8 +1197,8 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { }); } - function getIteratorExtends(iterator: Browser.Iterator | undefined, subtypes: string[]) { - if (!iterator) { + function getIteratorExtends(iterator?: Browser.Iterator, subtypes?: string[]) { + if (!iterator || !subtypes) { return ""; } const base = iterator.kind === "maplike" ? `Map<${subtypes[0]}, ${subtypes[1]}>` : @@ -1207,17 +1210,57 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { return `extends ${result} `; } + function hasSequenceArgument(s: Browser.Signature) { + function typeIncludesSequence(type: string | Browser.Typed[]): boolean { + if (Array.isArray(type)) { + return type.some(t => typeIncludesSequence(t.type)) + } + return type === "sequence" || !!sequenceTypedefMap[type]; + } + return !!s.param && s.param.some(p => typeIncludesSequence(p.type)); + } + + function filterSignaturesWithSequence(signature: Browser.Signature[]): Browser.Signature[] { + return signature.filter(hasSequenceArgument).map(s => { + const newParams = s.param!.map(p => { + const typedef = typeof p.type === "string" ? sequenceTypedefMap[p.type]: undefined; + if (!typedef) { + return p; + } + return { ...p, type: typedef.type }; + }) + return { ...s, param: newParams }; + }); + } + + const sequenceTypedefs = !webidl.typedefs ? [] : + webidl.typedefs.typedef + .filter(typedef => Array.isArray(typedef.type)) + .map(typedef => ({ ...typedef, type: (typedef.type as Browser.Typed[]).filter(t => t.type === "sequence") })) + .filter(typedef => typedef.type.length) + const sequenceTypedefMap = arrayToMap(sequenceTypedefs, t => t["new-type"], t => t); + const subtypes = getIteratorSubtypes(); - if (subtypes) { + const methodsWithSequence: Browser.Method[] = + mapToArray(i.methods ? i.methods.method : {}) + .filter(m => m.signature && !m["override-signatures"]) + .map(m => ({ ...m, signature: filterSignaturesWithSequence(m.signature) })) + .filter(m => m.signature.length) + .sort(); + + if (subtypes || methodsWithSequence.length) { const iteratorExtends = getIteratorExtends(i.iterator, subtypes); const name = extendConflictsBaseTypes[i.name] ? `${i.name}Base` : i.name; printer.printLine(""); printer.printLine(`interface ${name} ${iteratorExtends}{`); printer.increaseIndent(); - if (!iteratorExtends) { + + methodsWithSequence.forEach(m => emitMethod("", m, new Set())); + + if (subtypes && !iteratorExtends) { printer.printLine(`[Symbol.iterator](): IterableIterator<${stringifySingleOrTupleTypes(subtypes)}>;`); } - if (i.iterator && i.iterator.kind === "iterable") { + if (i.iterator && i.iterator.kind === "iterable" && subtypes) { emitIterableDeclarationMethods(i, subtypes); } printer.decreaseIndent(); From 7c57339879187deedf2e9485ef1f7e152818a864 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Wed, 5 Jun 2019 11:39:29 +0900 Subject: [PATCH 3/3] apply renamings --- src/emitter.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/emitter.ts b/src/emitter.ts index 5e0f3974b..4543b4cef 100644 --- a/src/emitter.ts +++ b/src/emitter.ts @@ -1220,16 +1220,16 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { return !!s.param && s.param.some(p => typeIncludesSequence(p.type)); } - function filterSignaturesWithSequence(signature: Browser.Signature[]): Browser.Signature[] { - return signature.filter(hasSequenceArgument).map(s => { - const newParams = s.param!.map(p => { - const typedef = typeof p.type === "string" ? sequenceTypedefMap[p.type]: undefined; + function replaceTypedefsInSignatures(signatures: Browser.Signature[]): Browser.Signature[] { + return signatures.map(s => { + const params = s.param!.map(p => { + const typedef = typeof p.type === "string" ? sequenceTypedefMap[p.type] : undefined; if (!typedef) { return p; } return { ...p, type: typedef.type }; }) - return { ...s, param: newParams }; + return { ...s, param: params }; }); } @@ -1244,7 +1244,10 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { const methodsWithSequence: Browser.Method[] = mapToArray(i.methods ? i.methods.method : {}) .filter(m => m.signature && !m["override-signatures"]) - .map(m => ({ ...m, signature: filterSignaturesWithSequence(m.signature) })) + .map(m => ({ + ...m, + signature: replaceTypedefsInSignatures(m.signature.filter(hasSequenceArgument)) + })) .filter(m => m.signature.length) .sort();