1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

perf(core): avoid creating global handles in op_queue_microtask (#16359)

This commit is contained in:
Divy Srivastava 2022-10-20 16:03:47 +05:30 committed by GitHub
parent e2be70b035
commit d3736f12b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -64,6 +64,14 @@ fn to_v8_fn(
.map_err(|err| type_error(err.to_string())) .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)] #[op(v8)]
fn op_ref_op(scope: &mut v8::HandleScope, promise_id: i32) { fn op_ref_op(scope: &mut v8::HandleScope, promise_id: i32) {
let context_state = JsRealm::state_from_scope(scope); let context_state = JsRealm::state_from_scope(scope);
@ -196,9 +204,7 @@ fn op_queue_microtask(
scope: &mut v8::HandleScope, scope: &mut v8::HandleScope,
cb: serde_v8::Value, cb: serde_v8::Value,
) -> Result<(), Error> { ) -> Result<(), Error> {
let cb = to_v8_fn(scope, cb)?; scope.enqueue_microtask(to_v8_local_fn(cb)?);
let cb = v8::Local::new(scope, cb);
scope.enqueue_microtask(cb);
Ok(()) Ok(())
} }