From 562d9e4a21177e640a4e0e09bf16a4e2e69f7f72 Mon Sep 17 00:00:00 2001 From: minghuaw Date: Wed, 9 Jul 2025 20:42:36 +0800 Subject: [PATCH] Update webidl files for TextEncoder and TextDecoder (#37952) This PR updates the webidl files for `TextEncoder` and `TextDecoder`. For `TextDecoder.webidl`, the type `AllowSharedBufferSource`, as defined in the latest spec, is replaced with `BufferSource` as servo currently does not support `ShareArrayBuffer` Testing: This update does not introduce any change to the generated rust binding, so the existing testing would suffice --------- Signed-off-by: Minghua Wu Signed-off-by: Xiaocheng Hu Co-authored-by: Xiaocheng Hu --- components/script_bindings/webidls/TextDecoder.webidl | 7 +++---- .../script_bindings/webidls/TextDecoderCommon.webidl | 11 +++++++++++ components/script_bindings/webidls/TextEncoder.webidl | 5 +++-- .../script_bindings/webidls/TextEncoderCommon.webidl | 9 +++++++++ 4 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 components/script_bindings/webidls/TextDecoderCommon.webidl create mode 100644 components/script_bindings/webidls/TextEncoderCommon.webidl diff --git a/components/script_bindings/webidls/TextDecoder.webidl b/components/script_bindings/webidls/TextDecoder.webidl index cc9cf5506db..0cf8694efde 100644 --- a/components/script_bindings/webidls/TextDecoder.webidl +++ b/components/script_bindings/webidls/TextDecoder.webidl @@ -12,12 +12,11 @@ dictionary TextDecodeOptions { boolean stream = false; }; -[Exposed=(Window,Worker)] +[Exposed=*] interface TextDecoder { [Throws] constructor(optional DOMString label = "utf-8", optional TextDecoderOptions options = {}); - readonly attribute DOMString encoding; - readonly attribute boolean fatal; - readonly attribute boolean ignoreBOM; + [Throws] USVString decode(optional BufferSource input, optional TextDecodeOptions options = {}); }; +TextDecoder includes TextDecoderCommon; diff --git a/components/script_bindings/webidls/TextDecoderCommon.webidl b/components/script_bindings/webidls/TextDecoderCommon.webidl new file mode 100644 index 00000000000..a23fb0be3f9 --- /dev/null +++ b/components/script_bindings/webidls/TextDecoderCommon.webidl @@ -0,0 +1,11 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +// https://encoding.spec.whatwg.org/#textdecodercommon + +interface mixin TextDecoderCommon { + readonly attribute DOMString encoding; + readonly attribute boolean fatal; + readonly attribute boolean ignoreBOM; +}; diff --git a/components/script_bindings/webidls/TextEncoder.webidl b/components/script_bindings/webidls/TextEncoder.webidl index 7028bb19172..44dad409969 100644 --- a/components/script_bindings/webidls/TextEncoder.webidl +++ b/components/script_bindings/webidls/TextEncoder.webidl @@ -9,11 +9,12 @@ dictionary TextEncoderEncodeIntoResult { unsigned long long written; }; -[Exposed=(Window,Worker)] +[Exposed=*] interface TextEncoder { [Throws] constructor(); - readonly attribute DOMString encoding; + [NewObject] Uint8Array encode(optional USVString input = ""); TextEncoderEncodeIntoResult encodeInto(USVString source, [AllowShared] Uint8Array destination); }; +TextEncoder includes TextEncoderCommon; diff --git a/components/script_bindings/webidls/TextEncoderCommon.webidl b/components/script_bindings/webidls/TextEncoderCommon.webidl new file mode 100644 index 00000000000..de39fa3ba1b --- /dev/null +++ b/components/script_bindings/webidls/TextEncoderCommon.webidl @@ -0,0 +1,9 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +// https://encoding.spec.whatwg.org/#textencodercommon + +interface mixin TextEncoderCommon { + readonly attribute DOMString encoding; +};