diff options
Diffstat (limited to 'core/ops_builtin.rs')
-rw-r--r-- | core/ops_builtin.rs | 13 |
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 + } +} |