summaryrefslogtreecommitdiff
path: root/core/ops_builtin.rs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2022-09-07 16:21:30 +0530
committerGitHub <noreply@github.com>2022-09-07 16:21:30 +0530
commitd57f9d560d7b675bda3cf3ba0ac69201b73467b3 (patch)
tree4103a67ede48f3ab0a7be55a91de492e8f096631 /core/ops_builtin.rs
parent7f4b043f322f87110251ce7d7e52f444ad1f0940 (diff)
fix(ext/flash): use utf8 length as Content-Length (#15793)
Diffstat (limited to 'core/ops_builtin.rs')
-rw-r--r--core/ops_builtin.rs13
1 files changed, 13 insertions, 0 deletions
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::<v8::String>::try_from(value.v8_value) {
+ string.utf8_length(scope) as u32
+ } else {
+ 0
+ }
+}