From c009dad9820fe3d565f2f8fc7025d24af82d29a4 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 8 Mar 2021 14:22:05 +0100 Subject: 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. --- op_crates/web/00_webidl.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'op_crates/web/00_webidl.js') 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"] = 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, -- cgit v1.2.3