From 696d528641ed6e03cf64daaee48bcc7c3fc8b89f Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Tue, 6 Aug 2024 00:40:17 -0700 Subject: fix(ext/web): make TextDecoderResource use cppgc (#24888) Fixes https://github.com/denoland/deno/issues/24878 --- ext/web/lib.rs | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'ext/web/lib.rs') diff --git a/ext/web/lib.rs b/ext/web/lib.rs index 89f1197e7..3977379a5 100644 --- a/ext/web/lib.rs +++ b/ext/web/lib.rs @@ -13,9 +13,6 @@ use deno_core::op2; use deno_core::url::Url; use deno_core::v8; use deno_core::ByteString; -use deno_core::OpState; -use deno_core::Resource; -use deno_core::ResourceId; use deno_core::ToJsBuffer; use deno_core::U16String; @@ -277,14 +274,13 @@ fn op_encoding_decode_single( } } -#[op2(fast)] -#[smi] +#[op2] +#[cppgc] fn op_encoding_new_decoder( - state: &mut OpState, #[string] label: &str, fatal: bool, ignore_bom: bool, -) -> Result { +) -> Result { let encoding = Encoding::for_label(label.as_bytes()).ok_or_else(|| { range_error(format!( "The encoding label provided ('{label}') is invalid." @@ -297,24 +293,19 @@ fn op_encoding_new_decoder( encoding.new_decoder_with_bom_removal() }; - let rid = state.resource_table.add(TextDecoderResource { + Ok(TextDecoderResource { decoder: RefCell::new(decoder), fatal, - }); - - Ok(rid) + }) } #[op2] #[serde] fn op_encoding_decode( - state: &mut OpState, #[anybuffer] data: &[u8], - #[smi] rid: ResourceId, + #[cppgc] resource: &TextDecoderResource, stream: bool, ) -> Result { - let resource = state.resource_table.get::(rid)?; - let mut decoder = resource.decoder.borrow_mut(); let fatal = resource.fatal; @@ -357,11 +348,7 @@ struct TextDecoderResource { fatal: bool, } -impl Resource for TextDecoderResource { - fn name(&self) -> Cow { - "textDecoder".into() - } -} +impl deno_core::GarbageCollected for TextDecoderResource {} #[op2(fast(op_encoding_encode_into_fast))] fn op_encoding_encode_into( -- cgit v1.2.3