mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
refactor: don't call Context::Global in async_op_response (#9971)
This commit is contained in:
parent
105c0ee3b4
commit
d2fbbfbbf3
1 changed files with 9 additions and 15 deletions
|
@ -1405,11 +1405,6 @@ impl JsRuntime {
|
||||||
|
|
||||||
let context = self.global_context();
|
let context = self.global_context();
|
||||||
let scope = &mut v8::HandleScope::with_context(self.v8_isolate(), context);
|
let scope = &mut v8::HandleScope::with_context(self.v8_isolate(), context);
|
||||||
let context = scope.get_current_context();
|
|
||||||
let global: v8::Local<v8::Value> = context.global(scope).into();
|
|
||||||
let js_recv_cb = js_recv_cb_handle.get(scope);
|
|
||||||
|
|
||||||
let tc_scope = &mut v8::TryCatch::new(scope);
|
|
||||||
|
|
||||||
// We return async responses to JS in unbounded batches (may change),
|
// We return async responses to JS in unbounded batches (may change),
|
||||||
// each batch is a flat vector of tuples:
|
// each batch is a flat vector of tuples:
|
||||||
|
@ -1422,18 +1417,19 @@ impl JsRuntime {
|
||||||
Vec::with_capacity(2 * async_responses_size);
|
Vec::with_capacity(2 * async_responses_size);
|
||||||
for overflown_response in async_responses {
|
for overflown_response in async_responses {
|
||||||
let (promise_id, resp) = overflown_response;
|
let (promise_id, resp) = overflown_response;
|
||||||
args.push(v8::Integer::new(tc_scope, promise_id as i32).into());
|
args.push(v8::Integer::new(scope, promise_id as i32).into());
|
||||||
args.push(match resp {
|
args.push(match resp {
|
||||||
OpResponse::Value(value) => serde_v8::to_v8(tc_scope, value).unwrap(),
|
OpResponse::Value(value) => serde_v8::to_v8(scope, value).unwrap(),
|
||||||
OpResponse::Buffer(buf) => {
|
OpResponse::Buffer(buf) => {
|
||||||
bindings::boxed_slice_to_uint8array(tc_scope, buf).into()
|
bindings::boxed_slice_to_uint8array(scope, buf).into()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if async_responses_size > 0 {
|
let tc_scope = &mut v8::TryCatch::new(scope);
|
||||||
js_recv_cb.call(tc_scope, global, args.as_slice());
|
let js_recv_cb = js_recv_cb_handle.get(tc_scope);
|
||||||
}
|
let this = v8::undefined(tc_scope).into();
|
||||||
|
js_recv_cb.call(tc_scope, this, args.as_slice());
|
||||||
|
|
||||||
match tc_scope.exception() {
|
match tc_scope.exception() {
|
||||||
None => Ok(()),
|
None => Ok(()),
|
||||||
|
@ -1450,17 +1446,15 @@ impl JsRuntime {
|
||||||
|
|
||||||
let context = self.global_context();
|
let context = self.global_context();
|
||||||
let scope = &mut v8::HandleScope::with_context(self.v8_isolate(), context);
|
let scope = &mut v8::HandleScope::with_context(self.v8_isolate(), context);
|
||||||
let context = scope.get_current_context();
|
|
||||||
let global: v8::Local<v8::Value> = context.global(scope).into();
|
|
||||||
let js_macrotask_cb = js_macrotask_cb_handle.get(scope);
|
let js_macrotask_cb = js_macrotask_cb_handle.get(scope);
|
||||||
|
|
||||||
// Repeatedly invoke macrotask callback until it returns true (done),
|
// Repeatedly invoke macrotask callback until it returns true (done),
|
||||||
// such that ready microtasks would be automatically run before
|
// such that ready microtasks would be automatically run before
|
||||||
// next macrotask is processed.
|
// next macrotask is processed.
|
||||||
let tc_scope = &mut v8::TryCatch::new(scope);
|
let tc_scope = &mut v8::TryCatch::new(scope);
|
||||||
|
let this = v8::undefined(tc_scope).into();
|
||||||
loop {
|
loop {
|
||||||
let is_done = js_macrotask_cb.call(tc_scope, global, &[]);
|
let is_done = js_macrotask_cb.call(tc_scope, this, &[]);
|
||||||
|
|
||||||
if let Some(exception) = tc_scope.exception() {
|
if let Some(exception) = tc_scope.exception() {
|
||||||
return exception_to_err_result(tc_scope, exception, false);
|
return exception_to_err_result(tc_scope, exception, false);
|
||||||
|
|
Loading…
Add table
Reference in a new issue