summaryrefslogtreecommitdiff
path: root/core/ops_builtin_v8.rs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2022-10-20 16:03:47 +0530
committerGitHub <noreply@github.com>2022-10-20 16:03:47 +0530
commitd3736f12b5be1879d38e860bb94b975d566b0aa7 (patch)
tree6d189dbc611ae9c5b25456e149bb165d83aaefeb /core/ops_builtin_v8.rs
parente2be70b035459cb534360b72ece4ff2abaa09cd7 (diff)
perf(core): avoid creating global handles in `op_queue_microtask` (#16359)
Diffstat (limited to 'core/ops_builtin_v8.rs')
-rw-r--r--core/ops_builtin_v8.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/core/ops_builtin_v8.rs b/core/ops_builtin_v8.rs
index e626c03c1..8629bbdbe 100644
--- a/core/ops_builtin_v8.rs
+++ b/core/ops_builtin_v8.rs
@@ -64,6 +64,14 @@ fn to_v8_fn(
.map_err(|err| type_error(err.to_string()))
}
+#[inline]
+fn to_v8_local_fn(
+ value: serde_v8::Value,
+) -> Result<v8::Local<v8::Function>, Error> {
+ v8::Local::<v8::Function>::try_from(value.v8_value)
+ .map_err(|err| type_error(err.to_string()))
+}
+
#[op(v8)]
fn op_ref_op(scope: &mut v8::HandleScope, promise_id: i32) {
let context_state = JsRealm::state_from_scope(scope);
@@ -196,9 +204,7 @@ fn op_queue_microtask(
scope: &mut v8::HandleScope,
cb: serde_v8::Value,
) -> Result<(), Error> {
- let cb = to_v8_fn(scope, cb)?;
- let cb = v8::Local::new(scope, cb);
- scope.enqueue_microtask(cb);
+ scope.enqueue_microtask(to_v8_local_fn(cb)?);
Ok(())
}