summaryrefslogtreecommitdiff
path: root/ops/optimizer_tests
diff options
context:
space:
mode:
Diffstat (limited to 'ops/optimizer_tests')
-rw-r--r--ops/optimizer_tests/cow_str.expected11
-rw-r--r--ops/optimizer_tests/cow_str.out87
-rw-r--r--ops/optimizer_tests/cow_str.rs3
-rw-r--r--ops/optimizer_tests/op_blob_revoke_object_url.expected12
-rw-r--r--ops/optimizer_tests/op_blob_revoke_object_url.out2
-rw-r--r--ops/optimizer_tests/op_blob_revoke_object_url.rs3
-rw-r--r--ops/optimizer_tests/op_print.expected11
-rw-r--r--ops/optimizer_tests/op_print.out82
-rw-r--r--ops/optimizer_tests/op_print.rs7
-rw-r--r--ops/optimizer_tests/owned_string.expected11
-rw-r--r--ops/optimizer_tests/owned_string.out99
-rw-r--r--ops/optimizer_tests/owned_string.rs3
-rw-r--r--ops/optimizer_tests/strings.expected11
-rw-r--r--ops/optimizer_tests/strings.out100
-rw-r--r--ops/optimizer_tests/strings.rs3
-rw-r--r--ops/optimizer_tests/strings_result.expected11
-rw-r--r--ops/optimizer_tests/strings_result.out71
-rw-r--r--ops/optimizer_tests/strings_result.rs4
18 files changed, 528 insertions, 3 deletions
diff --git a/ops/optimizer_tests/cow_str.expected b/ops/optimizer_tests/cow_str.expected
new file mode 100644
index 000000000..8b28965ba
--- /dev/null
+++ b/ops/optimizer_tests/cow_str.expected
@@ -0,0 +1,11 @@
+=== Optimizer Dump ===
+returns_result: false
+has_ref_opstate: false
+has_rc_opstate: false
+has_fast_callback_option: false
+needs_fast_callback_option: false
+fast_result: Some(Void)
+fast_parameters: [V8Value, SeqOneByteString]
+transforms: {0: Transform { kind: SeqOneByteString(Cow), index: 0 }}
+is_async: false
+fast_compatible: true
diff --git a/ops/optimizer_tests/cow_str.out b/ops/optimizer_tests/cow_str.out
new file mode 100644
index 000000000..da405f451
--- /dev/null
+++ b/ops/optimizer_tests/cow_str.out
@@ -0,0 +1,87 @@
+#[allow(non_camel_case_types)]
+///Auto-generated by `deno_ops`, i.e: `#[op]`
+///
+///Use `op_cow_str::decl()` to get an op-declaration
+///you can include in a `deno_core::Extension`.
+pub struct op_cow_str;
+#[doc(hidden)]
+impl op_cow_str {
+ pub fn name() -> &'static str {
+ stringify!(op_cow_str)
+ }
+ pub fn v8_fn_ptr<'scope>() -> deno_core::v8::FunctionCallback {
+ use deno_core::v8::MapFnTo;
+ Self::v8_func.map_fn_to()
+ }
+ pub fn decl<'scope>() -> deno_core::OpDecl {
+ deno_core::OpDecl {
+ name: Self::name(),
+ v8_fn_ptr: Self::v8_fn_ptr(),
+ enabled: true,
+ fast_fn: Some(
+ Box::new(op_cow_str_fast {
+ _phantom: ::std::marker::PhantomData,
+ }),
+ ),
+ is_async: false,
+ is_unstable: false,
+ is_v8: false,
+ argc: 1usize,
+ }
+ }
+ #[inline]
+ #[allow(clippy::too_many_arguments)]
+ fn call(c: Cow<'_, str>) {}
+ pub fn v8_func<'scope>(
+ scope: &mut deno_core::v8::HandleScope<'scope>,
+ args: deno_core::v8::FunctionCallbackArguments,
+ mut rv: deno_core::v8::ReturnValue,
+ ) {
+ let ctx = unsafe {
+ &*(deno_core::v8::Local::<deno_core::v8::External>::cast(args.data()).value()
+ as *const deno_core::_ops::OpCtx)
+ };
+ let arg_0 = match deno_core::v8::Local::<
+ deno_core::v8::String,
+ >::try_from(args.get(0usize as i32)) {
+ Ok(v8_string) => {
+ ::std::borrow::Cow::Owned(deno_core::serde_v8::to_utf8(v8_string, scope))
+ }
+ Err(_) => {
+ return deno_core::_ops::throw_type_error(
+ scope,
+ format!("Expected string at position {}", 0usize),
+ );
+ }
+ };
+ let result = Self::call(arg_0);
+ let op_state = ::std::cell::RefCell::borrow(&*ctx.state);
+ op_state.tracker.track_sync(ctx.id);
+ }
+}
+struct op_cow_str_fast {
+ _phantom: ::std::marker::PhantomData<()>,
+}
+impl<'scope> deno_core::v8::fast_api::FastFunction for op_cow_str_fast {
+ fn function(&self) -> *const ::std::ffi::c_void {
+ op_cow_str_fast_fn as *const ::std::ffi::c_void
+ }
+ fn args(&self) -> &'static [deno_core::v8::fast_api::Type] {
+ use deno_core::v8::fast_api::Type::*;
+ use deno_core::v8::fast_api::CType;
+ &[V8Value, SeqOneByteString]
+ }
+ fn return_type(&self) -> deno_core::v8::fast_api::CType {
+ deno_core::v8::fast_api::CType::Void
+ }
+}
+fn op_cow_str_fast_fn<'scope>(
+ _: deno_core::v8::Local<deno_core::v8::Object>,
+ c: *const deno_core::v8::fast_api::FastApiOneByteString,
+) -> () {
+ use deno_core::v8;
+ use deno_core::_ops;
+ let c = ::std::borrow::Cow::Borrowed(unsafe { &*c }.as_str());
+ let result = op_cow_str::call(c);
+ result
+}
diff --git a/ops/optimizer_tests/cow_str.rs b/ops/optimizer_tests/cow_str.rs
new file mode 100644
index 000000000..b7214bdc7
--- /dev/null
+++ b/ops/optimizer_tests/cow_str.rs
@@ -0,0 +1,3 @@
+fn op_cow_str(c: Cow<'_, str>) {
+ // ...
+}
diff --git a/ops/optimizer_tests/op_blob_revoke_object_url.expected b/ops/optimizer_tests/op_blob_revoke_object_url.expected
index 0fae25e86..00a896433 100644
--- a/ops/optimizer_tests/op_blob_revoke_object_url.expected
+++ b/ops/optimizer_tests/op_blob_revoke_object_url.expected
@@ -1 +1,11 @@
-MustBeSingleSegment \ No newline at end of file
+=== Optimizer Dump ===
+returns_result: true
+has_ref_opstate: true
+has_rc_opstate: false
+has_fast_callback_option: false
+needs_fast_callback_option: false
+fast_result: Some(Void)
+fast_parameters: [V8Value, SeqOneByteString]
+transforms: {1: Transform { kind: SeqOneByteString(Owned), index: 1 }}
+is_async: false
+fast_compatible: false
diff --git a/ops/optimizer_tests/op_blob_revoke_object_url.out b/ops/optimizer_tests/op_blob_revoke_object_url.out
index 72bc75e05..ac51c0de7 100644
--- a/ops/optimizer_tests/op_blob_revoke_object_url.out
+++ b/ops/optimizer_tests/op_blob_revoke_object_url.out
@@ -27,7 +27,7 @@ impl op_blob_revoke_object_url {
}
#[inline]
#[allow(clippy::too_many_arguments)]
- pub fn call(state: &mut deno_core::OpState, url: String) -> Result<(), AnyError> {
+ pub fn call(state: &mut OpState, url: String) -> Result<(), AnyError> {
let url = Url::parse(&url)?;
let blob_store = state.borrow::<BlobStore>();
blob_store.remove_object_url(&url);
diff --git a/ops/optimizer_tests/op_blob_revoke_object_url.rs b/ops/optimizer_tests/op_blob_revoke_object_url.rs
index 8e139da06..4ef79386e 100644
--- a/ops/optimizer_tests/op_blob_revoke_object_url.rs
+++ b/ops/optimizer_tests/op_blob_revoke_object_url.rs
@@ -1,7 +1,8 @@
pub fn op_blob_revoke_object_url(
- state: &mut deno_core::OpState,
+ state: &mut OpState,
url: String,
) -> Result<(), AnyError> {
+ // TODO(@littledivy): fast compatible https://github.com/denoland/deno/issues/17159
let url = Url::parse(&url)?;
let blob_store = state.borrow::<BlobStore>();
blob_store.remove_object_url(&url);
diff --git a/ops/optimizer_tests/op_print.expected b/ops/optimizer_tests/op_print.expected
new file mode 100644
index 000000000..0390be396
--- /dev/null
+++ b/ops/optimizer_tests/op_print.expected
@@ -0,0 +1,11 @@
+=== Optimizer Dump ===
+returns_result: true
+has_ref_opstate: true
+has_rc_opstate: false
+has_fast_callback_option: false
+needs_fast_callback_option: false
+fast_result: Some(Void)
+fast_parameters: [V8Value, SeqOneByteString, Bool]
+transforms: {1: Transform { kind: SeqOneByteString(Ref), index: 1 }}
+is_async: false
+fast_compatible: false
diff --git a/ops/optimizer_tests/op_print.out b/ops/optimizer_tests/op_print.out
new file mode 100644
index 000000000..bafa0b9f8
--- /dev/null
+++ b/ops/optimizer_tests/op_print.out
@@ -0,0 +1,82 @@
+#[allow(non_camel_case_types)]
+///Auto-generated by `deno_ops`, i.e: `#[op]`
+///
+///Use `op_print::decl()` to get an op-declaration
+///you can include in a `deno_core::Extension`.
+pub struct op_print;
+#[doc(hidden)]
+impl op_print {
+ pub fn name() -> &'static str {
+ stringify!(op_print)
+ }
+ pub fn v8_fn_ptr<'scope>() -> deno_core::v8::FunctionCallback {
+ use deno_core::v8::MapFnTo;
+ Self::v8_func.map_fn_to()
+ }
+ pub fn decl<'scope>() -> deno_core::OpDecl {
+ deno_core::OpDecl {
+ name: Self::name(),
+ v8_fn_ptr: Self::v8_fn_ptr(),
+ enabled: true,
+ fast_fn: None,
+ is_async: false,
+ is_unstable: false,
+ is_v8: false,
+ argc: 2usize,
+ }
+ }
+ #[inline]
+ #[allow(clippy::too_many_arguments)]
+ fn call(state: &mut OpState, msg: &str, is_err: bool) -> Result<(), AnyError> {}
+ pub fn v8_func<'scope>(
+ scope: &mut deno_core::v8::HandleScope<'scope>,
+ args: deno_core::v8::FunctionCallbackArguments,
+ mut rv: deno_core::v8::ReturnValue,
+ ) {
+ let ctx = unsafe {
+ &*(deno_core::v8::Local::<deno_core::v8::External>::cast(args.data()).value()
+ as *const deno_core::_ops::OpCtx)
+ };
+ let arg_0 = match deno_core::v8::Local::<
+ deno_core::v8::String,
+ >::try_from(args.get(0usize as i32)) {
+ Ok(v8_string) => deno_core::serde_v8::to_utf8(v8_string, scope),
+ Err(_) => {
+ return deno_core::_ops::throw_type_error(
+ scope,
+ format!("Expected string at position {}", 0usize),
+ );
+ }
+ };
+ let arg_0 = arg_0.as_ref();
+ let arg_1 = args.get(1usize as i32);
+ let arg_1 = match deno_core::serde_v8::from_v8(scope, arg_1) {
+ Ok(v) => v,
+ Err(err) => {
+ let msg = format!(
+ "Error parsing args at position {}: {}", 1usize,
+ deno_core::anyhow::Error::from(err)
+ );
+ return deno_core::_ops::throw_type_error(scope, msg);
+ }
+ };
+ let result = Self::call(
+ &mut std::cell::RefCell::borrow_mut(&ctx.state),
+ arg_0,
+ arg_1,
+ );
+ let op_state = ::std::cell::RefCell::borrow(&*ctx.state);
+ op_state.tracker.track_sync(ctx.id);
+ match result {
+ Ok(result) => {}
+ Err(err) => {
+ let exception = deno_core::error::to_v8_error(
+ scope,
+ op_state.get_error_class_fn,
+ &err,
+ );
+ scope.throw_exception(exception);
+ }
+ };
+ }
+}
diff --git a/ops/optimizer_tests/op_print.rs b/ops/optimizer_tests/op_print.rs
new file mode 100644
index 000000000..776ee8418
--- /dev/null
+++ b/ops/optimizer_tests/op_print.rs
@@ -0,0 +1,7 @@
+fn op_print(
+ state: &mut OpState,
+ msg: &str,
+ is_err: bool,
+) -> Result<(), AnyError> {
+ // TODO(@littledivy): fast compatible https://github.com/denoland/deno/issues/17159
+}
diff --git a/ops/optimizer_tests/owned_string.expected b/ops/optimizer_tests/owned_string.expected
new file mode 100644
index 000000000..a15275412
--- /dev/null
+++ b/ops/optimizer_tests/owned_string.expected
@@ -0,0 +1,11 @@
+=== Optimizer Dump ===
+returns_result: false
+has_ref_opstate: false
+has_rc_opstate: false
+has_fast_callback_option: false
+needs_fast_callback_option: false
+fast_result: Some(U32)
+fast_parameters: [V8Value, SeqOneByteString]
+transforms: {0: Transform { kind: SeqOneByteString(Owned), index: 0 }}
+is_async: false
+fast_compatible: true
diff --git a/ops/optimizer_tests/owned_string.out b/ops/optimizer_tests/owned_string.out
new file mode 100644
index 000000000..4892221f8
--- /dev/null
+++ b/ops/optimizer_tests/owned_string.out
@@ -0,0 +1,99 @@
+#[allow(non_camel_case_types)]
+///Auto-generated by `deno_ops`, i.e: `#[op]`
+///
+///Use `op_string_length::decl()` to get an op-declaration
+///you can include in a `deno_core::Extension`.
+pub struct op_string_length;
+#[doc(hidden)]
+impl op_string_length {
+ pub fn name() -> &'static str {
+ stringify!(op_string_length)
+ }
+ pub fn v8_fn_ptr<'scope>() -> deno_core::v8::FunctionCallback {
+ use deno_core::v8::MapFnTo;
+ Self::v8_func.map_fn_to()
+ }
+ pub fn decl<'scope>() -> deno_core::OpDecl {
+ deno_core::OpDecl {
+ name: Self::name(),
+ v8_fn_ptr: Self::v8_fn_ptr(),
+ enabled: true,
+ fast_fn: Some(
+ Box::new(op_string_length_fast {
+ _phantom: ::std::marker::PhantomData,
+ }),
+ ),
+ is_async: false,
+ is_unstable: false,
+ is_v8: false,
+ argc: 1usize,
+ }
+ }
+ #[inline]
+ #[allow(clippy::too_many_arguments)]
+ fn call(string: String) -> u32 {
+ string.len() as u32
+ }
+ pub fn v8_func<'scope>(
+ scope: &mut deno_core::v8::HandleScope<'scope>,
+ args: deno_core::v8::FunctionCallbackArguments,
+ mut rv: deno_core::v8::ReturnValue,
+ ) {
+ let ctx = unsafe {
+ &*(deno_core::v8::Local::<deno_core::v8::External>::cast(args.data()).value()
+ as *const deno_core::_ops::OpCtx)
+ };
+ let arg_0 = match deno_core::v8::Local::<
+ deno_core::v8::String,
+ >::try_from(args.get(0usize as i32)) {
+ Ok(v8_string) => deno_core::serde_v8::to_utf8(v8_string, scope),
+ Err(_) => {
+ return deno_core::_ops::throw_type_error(
+ scope,
+ format!("Expected string at position {}", 0usize),
+ );
+ }
+ };
+ let result = Self::call(arg_0);
+ let op_state = ::std::cell::RefCell::borrow(&*ctx.state);
+ op_state.tracker.track_sync(ctx.id);
+ match deno_core::serde_v8::to_v8(scope, result) {
+ Ok(ret) => rv.set(ret),
+ Err(err) => {
+ deno_core::_ops::throw_type_error(
+ scope,
+ format!(
+ "Error serializing return: {}",
+ deno_core::anyhow::Error::from(err)
+ ),
+ )
+ }
+ };
+ }
+}
+struct op_string_length_fast {
+ _phantom: ::std::marker::PhantomData<()>,
+}
+impl<'scope> deno_core::v8::fast_api::FastFunction for op_string_length_fast {
+ fn function(&self) -> *const ::std::ffi::c_void {
+ op_string_length_fast_fn as *const ::std::ffi::c_void
+ }
+ fn args(&self) -> &'static [deno_core::v8::fast_api::Type] {
+ use deno_core::v8::fast_api::Type::*;
+ use deno_core::v8::fast_api::CType;
+ &[V8Value, SeqOneByteString]
+ }
+ fn return_type(&self) -> deno_core::v8::fast_api::CType {
+ deno_core::v8::fast_api::CType::Uint32
+ }
+}
+fn op_string_length_fast_fn<'scope>(
+ _: deno_core::v8::Local<deno_core::v8::Object>,
+ string: *const deno_core::v8::fast_api::FastApiOneByteString,
+) -> u32 {
+ use deno_core::v8;
+ use deno_core::_ops;
+ let string = unsafe { &*string }.as_str().to_owned();
+ let result = op_string_length::call(string);
+ result
+}
diff --git a/ops/optimizer_tests/owned_string.rs b/ops/optimizer_tests/owned_string.rs
new file mode 100644
index 000000000..102cf00fb
--- /dev/null
+++ b/ops/optimizer_tests/owned_string.rs
@@ -0,0 +1,3 @@
+fn op_string_length(string: String) -> u32 {
+ string.len() as u32
+}
diff --git a/ops/optimizer_tests/strings.expected b/ops/optimizer_tests/strings.expected
new file mode 100644
index 000000000..ead741054
--- /dev/null
+++ b/ops/optimizer_tests/strings.expected
@@ -0,0 +1,11 @@
+=== Optimizer Dump ===
+returns_result: false
+has_ref_opstate: false
+has_rc_opstate: false
+has_fast_callback_option: false
+needs_fast_callback_option: false
+fast_result: Some(U32)
+fast_parameters: [V8Value, SeqOneByteString]
+transforms: {0: Transform { kind: SeqOneByteString(Ref), index: 0 }}
+is_async: false
+fast_compatible: true
diff --git a/ops/optimizer_tests/strings.out b/ops/optimizer_tests/strings.out
new file mode 100644
index 000000000..41f09c4f8
--- /dev/null
+++ b/ops/optimizer_tests/strings.out
@@ -0,0 +1,100 @@
+#[allow(non_camel_case_types)]
+///Auto-generated by `deno_ops`, i.e: `#[op]`
+///
+///Use `op_string_length::decl()` to get an op-declaration
+///you can include in a `deno_core::Extension`.
+pub struct op_string_length;
+#[doc(hidden)]
+impl op_string_length {
+ pub fn name() -> &'static str {
+ stringify!(op_string_length)
+ }
+ pub fn v8_fn_ptr<'scope>() -> deno_core::v8::FunctionCallback {
+ use deno_core::v8::MapFnTo;
+ Self::v8_func.map_fn_to()
+ }
+ pub fn decl<'scope>() -> deno_core::OpDecl {
+ deno_core::OpDecl {
+ name: Self::name(),
+ v8_fn_ptr: Self::v8_fn_ptr(),
+ enabled: true,
+ fast_fn: Some(
+ Box::new(op_string_length_fast {
+ _phantom: ::std::marker::PhantomData,
+ }),
+ ),
+ is_async: false,
+ is_unstable: false,
+ is_v8: false,
+ argc: 1usize,
+ }
+ }
+ #[inline]
+ #[allow(clippy::too_many_arguments)]
+ fn call(string: &str) -> u32 {
+ string.len() as u32
+ }
+ pub fn v8_func<'scope>(
+ scope: &mut deno_core::v8::HandleScope<'scope>,
+ args: deno_core::v8::FunctionCallbackArguments,
+ mut rv: deno_core::v8::ReturnValue,
+ ) {
+ let ctx = unsafe {
+ &*(deno_core::v8::Local::<deno_core::v8::External>::cast(args.data()).value()
+ as *const deno_core::_ops::OpCtx)
+ };
+ let arg_0 = match deno_core::v8::Local::<
+ deno_core::v8::String,
+ >::try_from(args.get(0usize as i32)) {
+ Ok(v8_string) => deno_core::serde_v8::to_utf8(v8_string, scope),
+ Err(_) => {
+ return deno_core::_ops::throw_type_error(
+ scope,
+ format!("Expected string at position {}", 0usize),
+ );
+ }
+ };
+ let arg_0 = arg_0.as_ref();
+ let result = Self::call(arg_0);
+ let op_state = ::std::cell::RefCell::borrow(&*ctx.state);
+ op_state.tracker.track_sync(ctx.id);
+ match deno_core::serde_v8::to_v8(scope, result) {
+ Ok(ret) => rv.set(ret),
+ Err(err) => {
+ deno_core::_ops::throw_type_error(
+ scope,
+ format!(
+ "Error serializing return: {}",
+ deno_core::anyhow::Error::from(err)
+ ),
+ )
+ }
+ };
+ }
+}
+struct op_string_length_fast {
+ _phantom: ::std::marker::PhantomData<()>,
+}
+impl<'scope> deno_core::v8::fast_api::FastFunction for op_string_length_fast {
+ fn function(&self) -> *const ::std::ffi::c_void {
+ op_string_length_fast_fn as *const ::std::ffi::c_void
+ }
+ fn args(&self) -> &'static [deno_core::v8::fast_api::Type] {
+ use deno_core::v8::fast_api::Type::*;
+ use deno_core::v8::fast_api::CType;
+ &[V8Value, SeqOneByteString]
+ }
+ fn return_type(&self) -> deno_core::v8::fast_api::CType {
+ deno_core::v8::fast_api::CType::Uint32
+ }
+}
+fn op_string_length_fast_fn<'scope>(
+ _: deno_core::v8::Local<deno_core::v8::Object>,
+ string: *const deno_core::v8::fast_api::FastApiOneByteString,
+) -> u32 {
+ use deno_core::v8;
+ use deno_core::_ops;
+ let string = unsafe { &*string }.as_str();
+ let result = op_string_length::call(string);
+ result
+}
diff --git a/ops/optimizer_tests/strings.rs b/ops/optimizer_tests/strings.rs
new file mode 100644
index 000000000..860f1e8ec
--- /dev/null
+++ b/ops/optimizer_tests/strings.rs
@@ -0,0 +1,3 @@
+fn op_string_length(string: &str) -> u32 {
+ string.len() as u32
+}
diff --git a/ops/optimizer_tests/strings_result.expected b/ops/optimizer_tests/strings_result.expected
new file mode 100644
index 000000000..68c753cab
--- /dev/null
+++ b/ops/optimizer_tests/strings_result.expected
@@ -0,0 +1,11 @@
+=== Optimizer Dump ===
+returns_result: true
+has_ref_opstate: false
+has_rc_opstate: false
+has_fast_callback_option: false
+needs_fast_callback_option: false
+fast_result: Some(U32)
+fast_parameters: [V8Value, SeqOneByteString]
+transforms: {0: Transform { kind: SeqOneByteString(Ref), index: 0 }}
+is_async: false
+fast_compatible: false
diff --git a/ops/optimizer_tests/strings_result.out b/ops/optimizer_tests/strings_result.out
new file mode 100644
index 000000000..8446a603b
--- /dev/null
+++ b/ops/optimizer_tests/strings_result.out
@@ -0,0 +1,71 @@
+#[allow(non_camel_case_types)]
+///Auto-generated by `deno_ops`, i.e: `#[op]`
+///
+///Use `op_string_length::decl()` to get an op-declaration
+///you can include in a `deno_core::Extension`.
+pub struct op_string_length;
+#[doc(hidden)]
+impl op_string_length {
+ pub fn name() -> &'static str {
+ stringify!(op_string_length)
+ }
+ pub fn v8_fn_ptr<'scope>() -> deno_core::v8::FunctionCallback {
+ use deno_core::v8::MapFnTo;
+ Self::v8_func.map_fn_to()
+ }
+ pub fn decl<'scope>() -> deno_core::OpDecl {
+ deno_core::OpDecl {
+ name: Self::name(),
+ v8_fn_ptr: Self::v8_fn_ptr(),
+ enabled: true,
+ fast_fn: None,
+ is_async: false,
+ is_unstable: false,
+ is_v8: false,
+ argc: 1usize,
+ }
+ }
+ #[inline]
+ #[allow(clippy::too_many_arguments)]
+ fn call(string: &str) -> Result<u32, AnyError> {
+ Ok(string.len() as u32)
+ }
+ pub fn v8_func<'scope>(
+ scope: &mut deno_core::v8::HandleScope<'scope>,
+ args: deno_core::v8::FunctionCallbackArguments,
+ mut rv: deno_core::v8::ReturnValue,
+ ) {
+ let ctx = unsafe {
+ &*(deno_core::v8::Local::<deno_core::v8::External>::cast(args.data()).value()
+ as *const deno_core::_ops::OpCtx)
+ };
+ let arg_0 = match deno_core::v8::Local::<
+ deno_core::v8::String,
+ >::try_from(args.get(0usize as i32)) {
+ Ok(v8_string) => deno_core::serde_v8::to_utf8(v8_string, scope),
+ Err(_) => {
+ return deno_core::_ops::throw_type_error(
+ scope,
+ format!("Expected string at position {}", 0usize),
+ );
+ }
+ };
+ let arg_0 = arg_0.as_ref();
+ let result = Self::call(arg_0);
+ let op_state = ::std::cell::RefCell::borrow(&*ctx.state);
+ op_state.tracker.track_sync(ctx.id);
+ match result {
+ Ok(result) => {
+ rv.set_uint32(result as u32);
+ }
+ Err(err) => {
+ let exception = deno_core::error::to_v8_error(
+ scope,
+ op_state.get_error_class_fn,
+ &err,
+ );
+ scope.throw_exception(exception);
+ }
+ };
+ }
+}
diff --git a/ops/optimizer_tests/strings_result.rs b/ops/optimizer_tests/strings_result.rs
new file mode 100644
index 000000000..f89efaab1
--- /dev/null
+++ b/ops/optimizer_tests/strings_result.rs
@@ -0,0 +1,4 @@
+// https://github.com/denoland/deno/issues/16979
+fn op_string_length(string: &str) -> Result<u32, AnyError> {
+ Ok(string.len() as u32)
+}