From 22328f87585611ae70e555ad7941cc5093b92544 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Tue, 5 Oct 2021 22:55:51 +0200 Subject: [PATCH] feat(core): native binding names (#12290) Makes native builtin functions easier to recognize when debugging/profiling, they would otherwise appear as "(anonymous)" functions --- core/bindings.rs | 1 + core/runtime.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/core/bindings.rs b/core/bindings.rs index 7b3abc60243440..cf4fd07f693738 100644 --- a/core/bindings.rs +++ b/core/bindings.rs @@ -180,6 +180,7 @@ pub fn set_func( let key = v8::String::new(scope, name).unwrap(); let tmpl = v8::FunctionTemplate::new(scope, callback); let val = tmpl.get_function(scope).unwrap(); + val.set_name(key); obj.set(scope, key.into(), val.into()); } diff --git a/core/runtime.rs b/core/runtime.rs index e4fe8cd6c59728..1150746f35ce75 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -2303,4 +2303,18 @@ assertEquals(1, notify_return_value); let all_true = v8::Local::::new(&mut scope, &all_true); assert!(all_true.is_true()); } + + #[test] + fn test_binding_names() { + let mut runtime = JsRuntime::new(RuntimeOptions::default()); + let all_true: v8::Global = runtime + .execute_script( + "binding_names.js", + "Deno.core.encode.toString() === 'function encode() { [native code] }'", + ) + .unwrap(); + let mut scope = runtime.handle_scope(); + let all_true = v8::Local::::new(&mut scope, &all_true); + assert!(all_true.is_true()); + } }