From d57f9d560d7b675bda3cf3ba0ac69201b73467b3 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Wed, 7 Sep 2022 16:21:30 +0530 Subject: fix(ext/flash): use utf8 length as Content-Length (#15793) --- core/ops_builtin.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'core/ops_builtin.rs') diff --git a/core/ops_builtin.rs b/core/ops_builtin.rs index bd19b74f6..26ab4bed5 100644 --- a/core/ops_builtin.rs +++ b/core/ops_builtin.rs @@ -39,6 +39,7 @@ pub(crate) fn init_builtins() -> Extension { op_metrics::decl(), op_format_file_name::decl(), op_is_proxy::decl(), + op_str_byte_length::decl(), ]) .ops(crate::ops_builtin_v8::init_builtins_v8()) .build() @@ -195,3 +196,15 @@ fn op_format_file_name(file_name: String) -> String { fn op_is_proxy(value: serde_v8::Value) -> bool { value.v8_value.is_proxy() } + +#[op(v8)] +fn op_str_byte_length( + scope: &mut v8::HandleScope, + value: serde_v8::Value, +) -> u32 { + if let Ok(string) = v8::Local::::try_from(value.v8_value) { + string.utf8_length(scope) as u32 + } else { + 0 + } +} -- cgit v1.2.3