summaryrefslogtreecommitdiff
path: root/core/runtime.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-05-21 22:23:28 +0200
committerGitHub <noreply@github.com>2023-05-21 20:23:28 +0000
commit9ec49897766d9c22f6c7bafabdd3e3f3a4b68ab1 (patch)
treee618fc4b47a720ce2392794a73735c7e28c3ca4c /core/runtime.rs
parentaddfb0c546f3cd911514591a91a9eef2ce5e3cec (diff)
refactor(core): set function names for ops in JavaScript (#19208)
This commit ensures that JavaScript functions generated for registered ops have proper names set up - the function name matches the name of the op. A test was added in `core/runtime.rs` that verifies this. Closes https://github.com/denoland/deno/issues/19206
Diffstat (limited to 'core/runtime.rs')
-rw-r--r--core/runtime.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/core/runtime.rs b/core/runtime.rs
index b56ef5d65..fd95bb0b3 100644
--- a/core/runtime.rs
+++ b/core/runtime.rs
@@ -4871,4 +4871,39 @@ Deno.core.opAsync("op_async_serialize_object_with_numbers_as_keys", {
..Default::default()
});
}
+
+ #[test]
+ fn ops_in_js_have_proper_names() {
+ #[op]
+ fn op_test_sync() -> Result<String, Error> {
+ Ok(String::from("Test"))
+ }
+
+ #[op]
+ async fn op_test_async() -> Result<String, Error> {
+ Ok(String::from("Test"))
+ }
+
+ deno_core::extension!(test_ext, ops = [op_test_sync, op_test_async]);
+ let mut runtime = JsRuntime::new(RuntimeOptions {
+ extensions: vec![test_ext::init_ops()],
+ ..Default::default()
+ });
+
+ let src = r#"
+ if (Deno.core.ops.op_test_sync.name !== "op_test_sync") {
+ throw new Error();
+ }
+
+ if (Deno.core.ops.op_test_async.name !== "op_test_async") {
+ throw new Error();
+ }
+
+ const { op_test_async } = Deno.core.generateAsyncOpHandler("op_test_async");
+ if (op_test_async.name !== "op_test_async") {
+ throw new Error();
+ }
+ "#;
+ runtime.execute_script_static("test", src).unwrap();
+ }
}