summaryrefslogtreecommitdiff
path: root/ext/web/08_text_encoding.js
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2022-01-27 13:36:36 +0100
committerGitHub <noreply@github.com>2022-01-27 13:36:36 +0100
commit884143218fad0e18f7553aaf079d52de703f7601 (patch)
tree9b9e9d30ea647041438ef8fa974b8d4234cabf73 /ext/web/08_text_encoding.js
parentdcf8f144ab0516936bfa4e93357d71f1732d880e (diff)
refactor: update runtime code for primordial checks for "instanceof" (#13497)
Diffstat (limited to 'ext/web/08_text_encoding.js')
-rw-r--r--ext/web/08_text_encoding.js42
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",