diff options
author | Luca Casonato <lucacasonato@yahoo.com> | 2021-03-08 14:22:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-08 14:22:05 +0100 |
commit | c009dad9820fe3d565f2f8fc7025d24af82d29a4 (patch) | |
tree | f3228a873c1be8851e2627504d7c060953bb55ae /op_crates/web | |
parent | 0bc488c85c4bbc5b900cf5ff7b09227345b87763 (diff) |
fix(webgpu): add webidl records and simple unions (#9698)
The only functional user facing difference is that this commit allows the
use SPIRV shaders, not just WGSL. This matches FF and Chrome Canary.
Diffstat (limited to 'op_crates/web')
-rw-r--r-- | op_crates/web/00_webidl.js | 29 | ||||
-rw-r--r-- | op_crates/web/internal.d.ts | 18 |
2 files changed, 47 insertions, 0 deletions
diff --git a/op_crates/web/00_webidl.js b/op_crates/web/00_webidl.js index ab3047391..c00c605e8 100644 --- a/op_crates/web/00_webidl.js +++ b/op_crates/web/00_webidl.js @@ -596,6 +596,13 @@ converters.VoidFunction = convertCallbackFunction; + converters["UVString?"] = createNullableConverter( + converters.USVString, + ); + converters["sequence<double>"] = createSequenceConverter( + converters["double"], + ); + function requiredArguments(length, required, opts = {}) { if (length < required) { const errMsg = `${ @@ -737,6 +744,26 @@ }; } + function createRecordConverter(keyConverter, valueConverter) { + return (V, opts) => { + if (typeof V !== "object") { + throw makeException( + TypeError, + "can not be converted to dictionary.", + opts, + ); + } + const result = {}; + for (const key of V) { + const typedKey = keyConverter(key, opts); + const value = V[key]; + const typedValue = valueConverter(value, opts); + result[typedKey] = typedValue; + } + return result; + }; + } + const brand = Symbol("[[webidl.brand]]"); function createInterfaceConverter(name, prototype) { @@ -766,12 +793,14 @@ window.__bootstrap ??= {}; window.__bootstrap.webidl = { + makeException, converters, requiredArguments, createDictionaryConverter, createEnumConverter, createNullableConverter, createSequenceConverter, + createRecordConverter, createInterfaceConverter, brand, createBranded, diff --git a/op_crates/web/internal.d.ts b/op_crates/web/internal.d.ts index 8be80c8a5..efafee26c 100644 --- a/op_crates/web/internal.d.ts +++ b/op_crates/web/internal.d.ts @@ -25,6 +25,11 @@ declare namespace globalThis { */ context: string; } + declare function makeException( + ErrorType: any, + message: string, + opts: ValueConverterOpts, + ): any; declare interface IntConverterOpts extends ValueConverterOpts { /** * Wether to throw if the number is outside of the acceptable values for @@ -191,6 +196,8 @@ declare namespace globalThis { * Convert a value into a `VoidFunction` (() => void). */ VoidFunction(v: any, opts?: ValueConverterOpts): () => void; + ["UVString?"](v: any, opts?: ValueConverterOpts): string | null; + ["sequence<double>"](v: any, opts?: ValueConverterOpts): number[]; [type: string]: (v: any, opts: ValueConverterOpts) => any; }; @@ -268,6 +275,17 @@ declare namespace globalThis { name: string, prototype: any, ): (v: any, opts: ValueConverterOpts) => any; + + declare function createRecordConverter< + K extends string | number | symbol, + V, + >( + keyConverter: (v: any, opts: ValueConverterOpts) => K, + valueConverter: (v: any, opts: ValueConverterOpts) => V, + ): ( + v: Record<K, V>, + opts: ValueConverterOpts, + ) => any; } declare var eventTarget: { |