diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2023-05-01 12:47:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-01 10:47:13 +0000 |
commit | b31cf9fde6ad5398c20370c136695db77df6beeb (patch) | |
tree | 23ef5cd5d6e9342abefdc37332cc12d9bce3f245 /ext/web/08_text_encoding.js | |
parent | d856bfd336137e1bcf81a0db9e8ad2b418ba711e (diff) |
refactor(webidl): move prefix & context out of converters options bag (#18931)
Diffstat (limited to 'ext/web/08_text_encoding.js')
-rw-r--r-- | ext/web/08_text_encoding.js | 63 |
1 files changed, 29 insertions, 34 deletions
diff --git a/ext/web/08_text_encoding.js b/ext/web/08_text_encoding.js index 2e19c3d1f..e7e535f90 100644 --- a/ext/web/08_text_encoding.js +++ b/ext/web/08_text_encoding.js @@ -53,14 +53,12 @@ class TextDecoder { */ constructor(label = "utf-8", options = {}) { const prefix = "Failed to construct 'TextDecoder'"; - label = webidl.converters.DOMString(label, { + label = webidl.converters.DOMString(label, prefix, "Argument 1"); + options = webidl.converters.TextDecoderOptions( + options, prefix, - context: "Argument 1", - }); - options = webidl.converters.TextDecoderOptions(options, { - prefix, - context: "Argument 2", - }); + "Argument 2", + ); const encoding = ops.op_encoding_normalize_label(label); this.#encoding = encoding; this.#fatal = options.fatal; @@ -95,18 +93,17 @@ class TextDecoder { webidl.assertBranded(this, TextDecoderPrototype); const prefix = "Failed to execute 'decode' on 'TextDecoder'"; if (input !== undefined) { - input = webidl.converters.BufferSource(input, { - prefix, - context: "Argument 1", + input = webidl.converters.BufferSource(input, prefix, "Argument 1", { allowShared: true, }); } let stream = false; if (options !== undefined) { - options = webidl.converters.TextDecodeOptions(options, { + options = webidl.converters.TextDecodeOptions( + options, prefix, - context: "Argument 2", - }); + "Argument 2", + ); stream = options.stream; } @@ -215,13 +212,13 @@ class TextEncoder { */ encode(input = "") { webidl.assertBranded(this, TextEncoderPrototype); - const prefix = "Failed to execute 'encode' on 'TextEncoder'"; // The WebIDL type of `input` is `USVString`, but `core.encode` already // converts lone surrogates to the replacement character. - input = webidl.converters.DOMString(input, { - prefix, - context: "Argument 1", - }); + input = webidl.converters.DOMString( + input, + "Failed to execute 'encode' on 'TextEncoder'", + "Argument 1", + ); return core.encode(input); } @@ -235,15 +232,15 @@ class TextEncoder { const prefix = "Failed to execute 'encodeInto' on 'TextEncoder'"; // The WebIDL type of `source` is `USVString`, but the ops bindings // already convert lone surrogates to the replacement character. - source = webidl.converters.DOMString(source, { + source = webidl.converters.DOMString(source, prefix, "Argument 1"); + destination = webidl.converters.Uint8Array( + destination, prefix, - context: "Argument 1", - }); - destination = webidl.converters.Uint8Array(destination, { - prefix, - context: "Argument 2", - allowShared: true, - }); + "Argument 2", + { + allowShared: true, + }, + ); ops.op_encoding_encode_into(source, destination, encodeIntoBuf); return { read: encodeIntoBuf[0], @@ -269,21 +266,19 @@ class TextDecoderStream { */ constructor(label = "utf-8", options = {}) { const prefix = "Failed to construct 'TextDecoderStream'"; - label = webidl.converters.DOMString(label, { + label = webidl.converters.DOMString(label, prefix, "Argument 1"); + options = webidl.converters.TextDecoderOptions( + options, prefix, - context: "Argument 1", - }); - options = webidl.converters.TextDecoderOptions(options, { - prefix, - context: "Argument 2", - }); + "Argument 2", + ); this.#decoder = new TextDecoder(label, options); this.#transform = new TransformStream({ // The transform and flush functions need access to TextDecoderStream's // `this`, so they are defined as functions rather than methods. transform: (chunk, controller) => { try { - chunk = webidl.converters.BufferSource(chunk, { + chunk = webidl.converters.BufferSource(chunk, prefix, "chunk", { allowShared: true, }); const decoded = this.#decoder.decode(chunk, { stream: true }); |