diff --git a/ext/fetch/20_headers.js b/ext/fetch/20_headers.js index a96d0da3b8..29b4540f94 100644 --- a/ext/fetch/20_headers.js +++ b/ext/fetch/20_headers.js @@ -431,7 +431,8 @@ webidl.converters["HeadersInit"] = (V, opts) => { throw webidl.makeException( TypeError, "The provided value is not of type '(sequence> or record)'", - opts, + opts.prefix, + opts.context, ); }; webidl.converters["Headers"] = webidl.createInterfaceConverter( diff --git a/ext/fetch/23_request.js b/ext/fetch/23_request.js index 798346ae62..ae3edffd47 100644 --- a/ext/fetch/23_request.js +++ b/ext/fetch/23_request.js @@ -341,7 +341,8 @@ class Request { throw webidl.makeException( TypeError, "`client` must be a Deno.HttpClient", - { prefix, context: "Argument 2" }, + prefix, + "Argument 2", ); } request.clientRid = init.client?.rid ?? null; diff --git a/ext/web/06_streams.js b/ext/web/06_streams.js index c516063658..ac626a209d 100644 --- a/ext/web/06_streams.js +++ b/ext/web/06_streams.js @@ -508,7 +508,7 @@ function extractSizeAlgorithm(strategy) { [chunk], undefined, webidl.converters["unrestricted double"], - { prefix: "Failed to call `sizeAlgorithm`" }, + "Failed to call `sizeAlgorithm`", ); } @@ -3315,10 +3315,7 @@ function setUpReadableByteStreamControllerFromUnderlyingSource( [controller], underlyingSource, webidl.converters.any, - { - prefix: - "Failed to call 'startAlgorithm' on 'ReadableByteStreamController'", - }, + "Failed to call 'startAlgorithm' on 'ReadableByteStreamController'", ); } if (underlyingSourceDict.pull !== undefined) { @@ -3328,11 +3325,8 @@ function setUpReadableByteStreamControllerFromUnderlyingSource( [controller], underlyingSource, webidl.converters["Promise"], - { - prefix: - "Failed to call 'pullAlgorithm' on 'ReadableByteStreamController'", - returnsPromise: true, - }, + "Failed to call 'pullAlgorithm' on 'ReadableByteStreamController'", + true, ); } if (underlyingSourceDict.cancel !== undefined) { @@ -3342,11 +3336,8 @@ function setUpReadableByteStreamControllerFromUnderlyingSource( [reason], underlyingSource, webidl.converters["Promise"], - { - prefix: - "Failed to call 'cancelAlgorithm' on 'ReadableByteStreamController'", - returnsPromise: true, - }, + "Failed to call 'cancelAlgorithm' on 'ReadableByteStreamController'", + true, ); } const autoAllocateChunkSize = underlyingSourceDict["autoAllocateChunkSize"]; @@ -3437,10 +3428,7 @@ function setUpReadableStreamDefaultControllerFromUnderlyingSource( [controller], underlyingSource, webidl.converters.any, - { - prefix: - "Failed to call 'startAlgorithm' on 'ReadableStreamDefaultController'", - }, + "Failed to call 'startAlgorithm' on 'ReadableStreamDefaultController'", ); } if (underlyingSourceDict.pull !== undefined) { @@ -3450,11 +3438,8 @@ function setUpReadableStreamDefaultControllerFromUnderlyingSource( [controller], underlyingSource, webidl.converters["Promise"], - { - prefix: - "Failed to call 'pullAlgorithm' on 'ReadableStreamDefaultController'", - returnsPromise: true, - }, + "Failed to call 'pullAlgorithm' on 'ReadableStreamDefaultController'", + true, ); } if (underlyingSourceDict.cancel !== undefined) { @@ -3464,11 +3449,8 @@ function setUpReadableStreamDefaultControllerFromUnderlyingSource( [reason], underlyingSource, webidl.converters["Promise"], - { - prefix: - "Failed to call 'cancelAlgorithm' on 'ReadableStreamDefaultController'", - returnsPromise: true, - }, + "Failed to call 'cancelAlgorithm' on 'ReadableStreamDefaultController'", + true, ); } setUpReadableStreamDefaultController( @@ -3569,11 +3551,8 @@ function setUpTransformStreamDefaultControllerFromTransformer( [chunk, controller], transformer, webidl.converters["Promise"], - { - prefix: - "Failed to call 'transformAlgorithm' on 'TransformStreamDefaultController'", - returnsPromise: true, - }, + "Failed to call 'transformAlgorithm' on 'TransformStreamDefaultController'", + true, ); } if (transformerDict.flush !== undefined) { @@ -3583,11 +3562,8 @@ function setUpTransformStreamDefaultControllerFromTransformer( [controller], transformer, webidl.converters["Promise"], - { - prefix: - "Failed to call 'flushAlgorithm' on 'TransformStreamDefaultController'", - returnsPromise: true, - }, + "Failed to call 'flushAlgorithm' on 'TransformStreamDefaultController'", + true, ); } setUpTransformStreamDefaultController( @@ -3679,10 +3655,7 @@ function setUpWritableStreamDefaultControllerFromUnderlyingSink( [controller], underlyingSink, webidl.converters.any, - { - prefix: - "Failed to call 'startAlgorithm' on 'WritableStreamDefaultController'", - }, + "Failed to call 'startAlgorithm' on 'WritableStreamDefaultController'", ); } if (underlyingSinkDict.write !== undefined) { @@ -3692,11 +3665,8 @@ function setUpWritableStreamDefaultControllerFromUnderlyingSink( [chunk, controller], underlyingSink, webidl.converters["Promise"], - { - prefix: - "Failed to call 'writeAlgorithm' on 'WritableStreamDefaultController'", - returnsPromise: true, - }, + "Failed to call 'writeAlgorithm' on 'WritableStreamDefaultController'", + true, ); } if (underlyingSinkDict.close !== undefined) { @@ -3706,11 +3676,8 @@ function setUpWritableStreamDefaultControllerFromUnderlyingSink( [], underlyingSink, webidl.converters["Promise"], - { - prefix: - "Failed to call 'closeAlgorithm' on 'WritableStreamDefaultController'", - returnsPromise: true, - }, + "Failed to call 'closeAlgorithm' on 'WritableStreamDefaultController'", + true, ); } if (underlyingSinkDict.abort !== undefined) { @@ -3720,11 +3687,8 @@ function setUpWritableStreamDefaultControllerFromUnderlyingSink( [reason], underlyingSink, webidl.converters["Promise"], - { - prefix: - "Failed to call 'abortAlgorithm' on 'WritableStreamDefaultController'", - returnsPromise: true, - }, + "Failed to call 'abortAlgorithm' on 'WritableStreamDefaultController'", + true, ); } setUpWritableStreamDefaultController( @@ -5467,16 +5431,19 @@ class ReadableByteStreamController { ); } if (byteLength === 0) { - throw webidl.makeException(TypeError, "length must be non-zero", { + throw webidl.makeException( + TypeError, + "length must be non-zero", prefix, - context: arg1, - }); + arg1, + ); } if (getArrayBufferByteLength(buffer) === 0) { throw webidl.makeException( TypeError, "buffer length must be non-zero", - { prefix, context: arg1 }, + prefix, + arg1, ); } if (this[_closeRequested] === true) { @@ -5790,10 +5757,7 @@ class TransformStream { [this[_controller]], transformer, webidl.converters.any, - { - prefix: - "Failed to call 'start' on 'TransformStreamDefaultController'", - }, + "Failed to call 'start' on 'TransformStreamDefaultController'", ), ); } else { diff --git a/ext/webidl/00_webidl.js b/ext/webidl/00_webidl.js index 4398609e52..7788741048 100644 --- a/ext/webidl/00_webidl.js +++ b/ext/webidl/00_webidl.js @@ -86,11 +86,9 @@ const { Uint8ClampedArray, } = primordials; -function makeException(ErrorType, message, opts = {}) { +function makeException(ErrorType, message, prefix, context) { return new ErrorType( - `${opts.prefix ? opts.prefix + ": " : ""}${ - opts.context ? opts.context : "Value" - } ${message}`, + `${prefix ? prefix + ": " : ""}${context ? context : "Value"} ${message}`, ); } @@ -199,7 +197,12 @@ function createIntegerConversion(bitLength, typeOpts) { if (opts.enforceRange) { if (!NumberIsFinite(x)) { - throw makeException(TypeError, "is not a finite number", opts); + throw makeException( + TypeError, + "is not a finite number", + opts.prefix, + opts.context, + ); } x = integerPart(x); @@ -208,7 +211,8 @@ function createIntegerConversion(bitLength, typeOpts) { throw makeException( TypeError, `is outside the accepted range of ${lowerBound} to ${upperBound}, inclusive`, - opts, + opts.prefix, + opts.context, ); } @@ -252,7 +256,12 @@ function createLongLongConversion(bitLength, { unsigned }) { if (opts.enforceRange) { if (!NumberIsFinite(x)) { - throw makeException(TypeError, "is not a finite number", opts); + throw makeException( + TypeError, + "is not a finite number", + opts.prefix, + opts.context, + ); } x = integerPart(x); @@ -261,7 +270,8 @@ function createLongLongConversion(bitLength, { unsigned }) { throw makeException( TypeError, `is outside the accepted range of ${lowerBound} to ${upperBound}, inclusive`, - opts, + opts.prefix, + opts.context, ); } @@ -317,7 +327,8 @@ converters.float = (V, opts) => { throw makeException( TypeError, "is not a finite floating-point value", - opts, + opts.prefix, + opts.context, ); } @@ -331,7 +342,8 @@ converters.float = (V, opts) => { throw makeException( TypeError, "is outside the range of a single-precision floating-point value", - opts, + opts.prefix, + opts.context, ); } @@ -359,7 +371,8 @@ converters.double = (V, opts) => { throw makeException( TypeError, "is not a finite floating-point value", - opts, + opts.prefix, + opts.context, ); } @@ -381,7 +394,8 @@ converters.DOMString = function (V, opts = {}) { throw makeException( TypeError, "is a symbol, which cannot be converted to a string", - opts, + opts.prefix, + opts.context, ); } @@ -393,7 +407,12 @@ const IS_BYTE_STRING = new SafeRegExp(/^[\x00-\xFF]*$/); converters.ByteString = (V, opts) => { const x = converters.DOMString(V, opts); if (!RegExpPrototypeTest(IS_BYTE_STRING, x)) { - throw makeException(TypeError, "is not a valid ByteString", opts); + throw makeException( + TypeError, + "is not a valid ByteString", + opts.prefix, + opts.context, + ); } return x; }; @@ -427,7 +446,12 @@ converters.USVString = (V, opts) => { converters.object = (V, opts) => { if (type(V) !== "Object") { - throw makeException(TypeError, "is not an object", opts); + throw makeException( + TypeError, + "is not an object", + opts.prefix, + opts.context, + ); } return V; @@ -439,7 +463,12 @@ converters.object = (V, opts) => { // handling for that is omitted. function convertCallbackFunction(V, opts) { if (typeof V !== "function") { - throw makeException(TypeError, "is not a function", opts); + throw makeException( + TypeError, + "is not a function", + opts.prefix, + opts.context, + ); } return V; } @@ -464,10 +493,16 @@ converters.ArrayBuffer = (V, opts = {}) => { throw makeException( TypeError, "is not an ArrayBuffer or SharedArrayBuffer", - opts, + opts.prefix, + opts.context, ); } - throw makeException(TypeError, "is not an ArrayBuffer", opts); + throw makeException( + TypeError, + "is not an ArrayBuffer", + opts.prefix, + opts.context, + ); } return V; @@ -475,14 +510,20 @@ converters.ArrayBuffer = (V, opts = {}) => { converters.DataView = (V, opts = {}) => { if (!isDataView(V)) { - throw makeException(TypeError, "is not a DataView", opts); + throw makeException( + TypeError, + "is not a DataView", + opts.prefix, + opts.context, + ); } if (!opts.allowShared && isSharedArrayBuffer(DataViewPrototypeGetBuffer(V))) { throw makeException( TypeError, "is backed by a SharedArrayBuffer, which is not allowed", - opts, + opts.prefix, + opts.context, ); } @@ -511,7 +552,8 @@ ArrayPrototypeForEach( throw makeException( TypeError, `is not ${article} ${name} object`, - opts, + opts.prefix, + opts.context, ); } if ( @@ -521,7 +563,8 @@ ArrayPrototypeForEach( throw makeException( TypeError, "is a view on a SharedArrayBuffer, which is not allowed", - opts, + opts.prefix, + opts.context, ); } @@ -537,7 +580,8 @@ converters.ArrayBufferView = (V, opts = {}) => { throw makeException( TypeError, "is not a view on an ArrayBuffer or SharedArrayBuffer", - opts, + opts.prefix, + opts.context, ); } let buffer; @@ -550,7 +594,8 @@ converters.ArrayBufferView = (V, opts = {}) => { throw makeException( TypeError, "is a view on a SharedArrayBuffer, which is not allowed", - opts, + opts.prefix, + opts.context, ); } @@ -569,7 +614,8 @@ converters.BufferSource = (V, opts = {}) => { throw makeException( TypeError, "is a view on a SharedArrayBuffer, which is not allowed", - opts, + opts.prefix, + opts.context, ); } @@ -580,7 +626,8 @@ converters.BufferSource = (V, opts = {}) => { throw makeException( TypeError, "is not an ArrayBuffer or a view on one", - opts, + opts.prefix, + opts.context, ); } if ( @@ -591,7 +638,8 @@ converters.BufferSource = (V, opts = {}) => { throw makeException( TypeError, "is not an ArrayBuffer, SharedArrayBuffer, or a view on one", - opts, + opts.prefix, + opts.context, ); } @@ -707,7 +755,8 @@ function createDictionaryConverter(name, ...dictionaries) { throw makeException( TypeError, "can not be converted to a dictionary", - opts, + opts.prefix, + opts.context, ); } const esDict = V; @@ -741,7 +790,8 @@ function createDictionaryConverter(name, ...dictionaries) { throw makeException( TypeError, `can not be converted to '${name}' because '${key}' is required in '${name}'.`, - opts, + opts.prefix, + opts.context, ); } } @@ -789,7 +839,8 @@ function createSequenceConverter(converter) { throw makeException( TypeError, "can not be converted to sequence.", - opts, + opts.prefix, + opts.context, ); } const iter = V?.[SymbolIterator]?.(); @@ -797,7 +848,8 @@ function createSequenceConverter(converter) { throw makeException( TypeError, "can not be converted to sequence.", - opts, + opts.prefix, + opts.context, ); } const array = []; @@ -807,7 +859,8 @@ function createSequenceConverter(converter) { throw makeException( TypeError, "can not be converted to sequence.", - opts, + opts.prefix, + opts.context, ); } if (res.done === true) break; @@ -827,7 +880,8 @@ function createRecordConverter(keyConverter, valueConverter) { throw makeException( TypeError, "can not be converted to dictionary.", - opts, + opts.prefix, + opts.context, ); } const result = {}; @@ -870,16 +924,17 @@ function invokeCallbackFunction( args, thisArg, returnValueConverter, - opts, + prefix, + returnsPromise, ) { try { const rv = ReflectApply(callable, thisArg, args); return returnValueConverter(rv, { - prefix: opts.prefix, + prefix, context: "return value", }); } catch (err) { - if (opts.returnsPromise === true) { + if (returnsPromise === true) { return PromiseReject(err); } throw err; @@ -891,7 +946,12 @@ const brand = Symbol("[[webidl.brand]]"); function createInterfaceConverter(name, prototype) { return (V, opts) => { if (!ObjectPrototypeIsPrototypeOf(prototype, V) || V[brand] !== brand) { - throw makeException(TypeError, `is not of type ${name}.`, opts); + throw makeException( + TypeError, + `is not of type ${name}.`, + opts.prefix, + opts.context, + ); } return V; }; diff --git a/ext/webidl/internal.d.ts b/ext/webidl/internal.d.ts index 110031ae73..095e5ab91d 100644 --- a/ext/webidl/internal.d.ts +++ b/ext/webidl/internal.d.ts @@ -5,7 +5,7 @@ /// declare module "ext:deno_webidl/00_webidl.js" { - interface ConverterOpts { + interface ValueConverterOpts { /** * The prefix for error messages created by this converter. * Examples: @@ -13,8 +13,6 @@ declare module "ext:deno_webidl/00_webidl.js" { * - `Failed to execute 'removeEventListener' on 'EventTarget'` */ prefix: string; - } - interface ValueConverterOpts extends ConverterOpts { /** * The context of this value error messages created by this converter. * Examples: @@ -26,7 +24,8 @@ declare module "ext:deno_webidl/00_webidl.js" { function makeException( ErrorType: any, message: string, - opts: ValueConverterOpts, + prefix: string, + context: string, ): any; interface IntConverterOpts extends ValueConverterOpts { /** @@ -261,7 +260,8 @@ declare module "ext:deno_webidl/00_webidl.js" { args: any[], thisArg: any, returnValueConverter: (v: any, opts: ValueConverterOpts) => T, - opts: ConverterOpts & { returnsPromise?: boolean }, + prefix: string, + returnsPromise?: boolean, ): T; /**