Truly independent web browser
LibWeb: Allow shared buffers in TextDecoder.decode()
Callum Law2ad935739ddf
diff --git a/Libraries/LibWeb/Bindings/Rust/src/encoding/text_decoder.rs b/Libraries/LibWeb/Bindings/Rust/src/encoding/text_decoder.rsindex 046f714fc8b..d2c5b2621b3 100644--- a/Libraries/LibWeb/Bindings/Rust/src/encoding/text_decoder.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/encoding/text_decoder.rs@@ -15,6 +15,7 @@ use libtextcodec_rust::{DecodingFailed, StreamingDecoder, encoding_for_label};use crate::bindings::conversions::{BufferSource, UsvString};use crate::bindings::interface::Wrappable;use crate::bindings::{CallContext, Exception, WebIdlResult};+use crate::webidl::buffers::AllowSharedBufferSource;/// The dictionary TextDecoderOptions of Encoding/TextDecoder.idl, whose members the bindings convert.pub(crate) struct TextDecoderOptions {@@ -86,7 +87,7 @@ impl TextDecoder {pub(crate) fn decode(&self,_: &mut CallContext,- input: Option<BufferSource>,+ input: Option<AllowSharedBufferSource>,options: TextDecodeOptions,) -> WebIdlResult<UsvString> {// 1. If this's do not flush is false, then set this's decoder to a new instance of this's encoding's decoder,@@ -107,6 +108,7 @@ impl TextDecoder {// NB: The decoder holds the I/O queue and whether the BOM was seen, and is replaced when a call that does not// stream returns, where step 1 replaces it in the next call.let mut decoder = self.decoder.borrow_mut();+ let input = input.map(BufferSource::from);let decoded = match &input {// SAFETY: Decoding runs no script and allocates no cell, so nothing detaches, resizes or frees the// buffer of the input while its bytes are read.diff --git a/Libraries/LibWeb/Encoding/TextDecoder.idl b/Libraries/LibWeb/Encoding/TextDecoder.idlindex 45fc709f9a2..a85cd7af85c 100644--- a/Libraries/LibWeb/Encoding/TextDecoder.idl+++ b/Libraries/LibWeb/Encoding/TextDecoder.idl@@ -14,7 +14,6 @@ dictionary TextDecodeOptions {interface TextDecoder {constructor(optional DOMString label = "utf-8", optional TextDecoderOptions options = {});- // FIXME: BufferSource is really a AllowSharedBufferSource- USVString decode(optional BufferSource input, optional TextDecodeOptions options = {});+ USVString decode(optional AllowSharedBufferSource input, optional TextDecodeOptions options = {});};TextDecoder includes TextDecoderCommon;diff --git a/Tests/LibWeb/Text/expected/wpt-import/encoding/textdecoder-copy.any.txt b/Tests/LibWeb/Text/expected/wpt-import/encoding/textdecoder-copy.any.txtindex 162375198bf..d3632973817 100644--- a/Tests/LibWeb/Text/expected/wpt-import/encoding/textdecoder-copy.any.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/encoding/textdecoder-copy.any.txt@@ -2,7 +2,6 @@ Harness status: OKFound 2 tests-1 Pass-1 Fail+2 PassPass Modify buffer after passing it in (ArrayBuffer)-Fail Modify buffer after passing it in (SharedArrayBuffer)\ No newline at end of file+Pass Modify buffer after passing it in (SharedArrayBuffer)\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/encoding/textdecoder-streaming.any.txt b/Tests/LibWeb/Text/expected/wpt-import/encoding/textdecoder-streaming.any.txtindex 334818014a8..5262a7ac0a9 100644--- a/Tests/LibWeb/Text/expected/wpt-import/encoding/textdecoder-streaming.any.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/encoding/textdecoder-streaming.any.txt@@ -2,8 +2,7 @@ Harness status: OKFound 32 tests-16 Pass-16 Fail+32 PassPass Streaming decode: utf-8, 1 byte window (ArrayBuffer)Pass Streaming decode: utf-8, 2 byte window (ArrayBuffer)Pass Streaming decode: utf-8, 3 byte window (ArrayBuffer)@@ -20,19 +19,19 @@ Pass Streaming decode: utf-16be, 3 byte window (ArrayBuffer)Pass Streaming decode: utf-16be, 4 byte window (ArrayBuffer)Pass Streaming decode: utf-16be, 5 byte window (ArrayBuffer)Pass Streaming decode: UTF-8 chunk tests (ArrayBuffer)-Fail Streaming decode: utf-8, 1 byte window (SharedArrayBuffer)-Fail Streaming decode: utf-8, 2 byte window (SharedArrayBuffer)-Fail Streaming decode: utf-8, 3 byte window (SharedArrayBuffer)-Fail Streaming decode: utf-8, 4 byte window (SharedArrayBuffer)-Fail Streaming decode: utf-8, 5 byte window (SharedArrayBuffer)-Fail Streaming decode: utf-16le, 1 byte window (SharedArrayBuffer)-Fail Streaming decode: utf-16le, 2 byte window (SharedArrayBuffer)-Fail Streaming decode: utf-16le, 3 byte window (SharedArrayBuffer)-Fail Streaming decode: utf-16le, 4 byte window (SharedArrayBuffer)-Fail Streaming decode: utf-16le, 5 byte window (SharedArrayBuffer)-Fail Streaming decode: utf-16be, 1 byte window (SharedArrayBuffer)-Fail Streaming decode: utf-16be, 2 byte window (SharedArrayBuffer)-Fail Streaming decode: utf-16be, 3 byte window (SharedArrayBuffer)-Fail Streaming decode: utf-16be, 4 byte window (SharedArrayBuffer)-Fail Streaming decode: utf-16be, 5 byte window (SharedArrayBuffer)-Fail Streaming decode: UTF-8 chunk tests (SharedArrayBuffer)\ No newline at end of file+Pass Streaming decode: utf-8, 1 byte window (SharedArrayBuffer)+Pass Streaming decode: utf-8, 2 byte window (SharedArrayBuffer)+Pass Streaming decode: utf-8, 3 byte window (SharedArrayBuffer)+Pass Streaming decode: utf-8, 4 byte window (SharedArrayBuffer)+Pass Streaming decode: utf-8, 5 byte window (SharedArrayBuffer)+Pass Streaming decode: utf-16le, 1 byte window (SharedArrayBuffer)+Pass Streaming decode: utf-16le, 2 byte window (SharedArrayBuffer)+Pass Streaming decode: utf-16le, 3 byte window (SharedArrayBuffer)+Pass Streaming decode: utf-16le, 4 byte window (SharedArrayBuffer)+Pass Streaming decode: utf-16le, 5 byte window (SharedArrayBuffer)+Pass Streaming decode: utf-16be, 1 byte window (SharedArrayBuffer)+Pass Streaming decode: utf-16be, 2 byte window (SharedArrayBuffer)+Pass Streaming decode: utf-16be, 3 byte window (SharedArrayBuffer)+Pass Streaming decode: utf-16be, 4 byte window (SharedArrayBuffer)+Pass Streaming decode: utf-16be, 5 byte window (SharedArrayBuffer)+Pass Streaming decode: UTF-8 chunk tests (SharedArrayBuffer)\ No newline at end of file