Skip to content

Commit

Permalink
feat(core): native binding names (#12290)
Browse files Browse the repository at this point in the history
Makes native builtin functions easier to recognize when debugging/profiling, they would otherwise appear as "(anonymous)" functions
  • Loading branch information
AaronO authored Oct 5, 2021
1 parent 678a881 commit 22328f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
14 changes: 14 additions & 0 deletions core/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2303,4 +2303,18 @@ assertEquals(1, notify_return_value);
let all_true = v8::Local::<v8::Value>::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<v8::Value> = 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::<v8::Value>::new(&mut scope, &all_true);
assert!(all_true.is_true());
}
}

0 comments on commit 22328f8

Please sign in to comment.