diff options
Diffstat (limited to 'ext/web/08_text_encoding.js')
-rw-r--r-- | ext/web/08_text_encoding.js | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/ext/web/08_text_encoding.js b/ext/web/08_text_encoding.js index cf7b7e12f..4f26089b1 100644 --- a/ext/web/08_text_encoding.js +++ b/ext/web/08_text_encoding.js @@ -16,6 +16,7 @@ const webidl = window.__bootstrap.webidl; const { ArrayBufferIsView, + ObjectPrototypeIsPrototypeOf, PromiseReject, PromiseResolve, StringPrototypeCharCodeAt, @@ -59,19 +60,19 @@ /** @returns {string} */ get encoding() { - webidl.assertBranded(this, TextDecoder); + webidl.assertBranded(this, TextDecoderPrototype); return this.#encoding; } /** @returns {boolean} */ get fatal() { - webidl.assertBranded(this, TextDecoder); + webidl.assertBranded(this, TextDecoderPrototype); return this.#fatal; } /** @returns {boolean} */ get ignoreBOM() { - webidl.assertBranded(this, TextDecoder); + webidl.assertBranded(this, TextDecoderPrototype); return this.#ignoreBOM; } @@ -80,7 +81,7 @@ * @param {TextDecodeOptions} options */ decode(input = new Uint8Array(), options = {}) { - webidl.assertBranded(this, TextDecoder); + webidl.assertBranded(this, TextDecoderPrototype); const prefix = "Failed to execute 'decode' on 'TextDecoder'"; if (input !== undefined) { input = webidl.converters.BufferSource(input, { @@ -119,7 +120,12 @@ // If the buffer is detached, just create a new empty Uint8Array. input = new Uint8Array(); } - if (input.buffer instanceof SharedArrayBuffer) { + if ( + ObjectPrototypeIsPrototypeOf( + SharedArrayBuffer.prototype, + input.buffer, + ) + ) { // We clone the data into a non-shared ArrayBuffer so we can pass it // to Rust. // `input` is now a Uint8Array, and calling the TypedArray constructor @@ -140,6 +146,7 @@ } webidl.configurePrototype(TextDecoder); + const TextDecoderPrototype = TextDecoder.prototype; class TextEncoder { constructor() { @@ -148,7 +155,7 @@ /** @returns {string} */ get encoding() { - webidl.assertBranded(this, TextEncoder); + webidl.assertBranded(this, TextEncoderPrototype); return "utf-8"; } @@ -157,7 +164,7 @@ * @returns {Uint8Array} */ encode(input = "") { - webidl.assertBranded(this, TextEncoder); + 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. @@ -174,7 +181,7 @@ * @returns {TextEncoderEncodeIntoResult} */ encodeInto(source, destination) { - webidl.assertBranded(this, TextEncoder); + webidl.assertBranded(this, TextEncoderPrototype); 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. @@ -192,6 +199,7 @@ } webidl.configurePrototype(TextEncoder); + const TextEncoderPrototype = TextEncoder.prototype; class TextDecoderStream { /** @type {TextDecoder} */ @@ -248,36 +256,37 @@ /** @returns {string} */ get encoding() { - webidl.assertBranded(this, TextDecoderStream); + webidl.assertBranded(this, TextDecoderStreamPrototype); return this.#decoder.encoding; } /** @returns {boolean} */ get fatal() { - webidl.assertBranded(this, TextDecoderStream); + webidl.assertBranded(this, TextDecoderStreamPrototype); return this.#decoder.fatal; } /** @returns {boolean} */ get ignoreBOM() { - webidl.assertBranded(this, TextDecoderStream); + webidl.assertBranded(this, TextDecoderStreamPrototype); return this.#decoder.ignoreBOM; } /** @returns {ReadableStream<string>} */ get readable() { - webidl.assertBranded(this, TextDecoderStream); + webidl.assertBranded(this, TextDecoderStreamPrototype); return this.#transform.readable; } /** @returns {WritableStream<BufferSource>} */ get writable() { - webidl.assertBranded(this, TextDecoderStream); + webidl.assertBranded(this, TextDecoderStreamPrototype); return this.#transform.writable; } } webidl.configurePrototype(TextDecoderStream); + const TextDecoderStreamPrototype = TextDecoderStream.prototype; class TextEncoderStream { /** @type {string | null} */ @@ -332,24 +341,25 @@ /** @returns {string} */ get encoding() { - webidl.assertBranded(this, TextEncoderStream); + webidl.assertBranded(this, TextEncoderStreamPrototype); return "utf-8"; } /** @returns {ReadableStream<Uint8Array>} */ get readable() { - webidl.assertBranded(this, TextEncoderStream); + webidl.assertBranded(this, TextEncoderStreamPrototype); return this.#transform.readable; } /** @returns {WritableStream<string>} */ get writable() { - webidl.assertBranded(this, TextEncoderStream); + webidl.assertBranded(this, TextEncoderStreamPrototype); return this.#transform.writable; } } webidl.configurePrototype(TextEncoderStream); + const TextEncoderStreamPrototype = TextEncoderStream.prototype; webidl.converters.TextDecoderOptions = webidl.createDictionaryConverter( "TextDecoderOptions", |