summaryrefslogtreecommitdiff
path: root/ext/web/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ext/web/lib.rs')
-rw-r--r--ext/web/lib.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/ext/web/lib.rs b/ext/web/lib.rs
index 2f59636fe..76095810e 100644
--- a/ext/web/lib.rs
+++ b/ext/web/lib.rs
@@ -350,7 +350,28 @@ impl Resource for TextDecoderResource {
}
}
-#[op]
+#[op(v8)]
+fn op_encoding_encode_into_fallback(
+ scope: &mut v8::HandleScope,
+ input: serde_v8::Value,
+ buffer: &mut [u8],
+ out_buf: &mut [u32],
+) -> Result<(), AnyError> {
+ let s = v8::Local::<v8::String>::try_from(input.v8_value)?;
+
+ let mut nchars = 0;
+ out_buf[1] = s.write_utf8(
+ scope,
+ buffer,
+ Some(&mut nchars),
+ v8::WriteOptions::NO_NULL_TERMINATION
+ | v8::WriteOptions::REPLACE_INVALID_UTF8,
+ ) as u32;
+ out_buf[0] = nchars as u32;
+ Ok(())
+}
+
+#[op(fast, slow = op_encoding_encode_into_fallback)]
fn op_encoding_encode_into(
input: Cow<'_, str>,
buffer: &mut [u8],