mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 08:39:09 -05:00
refactor(core): rename pending_promise_exception to pending_promise_rejection (#17441)
These are technically rejections - a rejection can then raise an exception.
This commit is contained in:
parent
9d3483d4eb
commit
40134ffc99
4 changed files with 26 additions and 26 deletions
|
@ -505,11 +505,11 @@ pub extern "C" fn promise_reject_callback(message: v8::PromiseRejectMessage) {
|
|||
let error = message.get_value().unwrap();
|
||||
let error_global = v8::Global::new(scope, error);
|
||||
state
|
||||
.pending_promise_exceptions
|
||||
.pending_promise_rejections
|
||||
.insert(promise_global, error_global);
|
||||
}
|
||||
PromiseHandlerAddedAfterReject => {
|
||||
state.pending_promise_exceptions.remove(&promise_global);
|
||||
state.pending_promise_rejections.remove(&promise_global);
|
||||
}
|
||||
PromiseRejectAfterResolved => {}
|
||||
PromiseResolveAfterResolved => {
|
||||
|
|
|
@ -50,9 +50,9 @@ pub(crate) fn init_builtins_v8() -> Vec<OpDecl> {
|
|||
op_apply_source_map::decl(),
|
||||
op_set_format_exception_callback::decl(),
|
||||
op_event_loop_has_more_work::decl(),
|
||||
op_store_pending_promise_exception::decl(),
|
||||
op_remove_pending_promise_exception::decl(),
|
||||
op_has_pending_promise_exception::decl(),
|
||||
op_store_pending_promise_rejection::decl(),
|
||||
op_remove_pending_promise_rejection::decl(),
|
||||
op_has_pending_promise_rejection::decl(),
|
||||
op_arraybuffer_was_detached::decl(),
|
||||
]
|
||||
}
|
||||
|
@ -859,7 +859,7 @@ fn op_event_loop_has_more_work(scope: &mut v8::HandleScope) -> bool {
|
|||
}
|
||||
|
||||
#[op(v8)]
|
||||
fn op_store_pending_promise_exception<'a>(
|
||||
fn op_store_pending_promise_rejection<'a>(
|
||||
scope: &mut v8::HandleScope<'a>,
|
||||
promise: serde_v8::Value<'a>,
|
||||
reason: serde_v8::Value<'a>,
|
||||
|
@ -871,12 +871,12 @@ fn op_store_pending_promise_exception<'a>(
|
|||
let promise_global = v8::Global::new(scope, promise_value);
|
||||
let error_global = v8::Global::new(scope, reason.v8_value);
|
||||
state
|
||||
.pending_promise_exceptions
|
||||
.pending_promise_rejections
|
||||
.insert(promise_global, error_global);
|
||||
}
|
||||
|
||||
#[op(v8)]
|
||||
fn op_remove_pending_promise_exception<'a>(
|
||||
fn op_remove_pending_promise_rejection<'a>(
|
||||
scope: &mut v8::HandleScope<'a>,
|
||||
promise: serde_v8::Value<'a>,
|
||||
) {
|
||||
|
@ -885,11 +885,11 @@ fn op_remove_pending_promise_exception<'a>(
|
|||
let promise_value =
|
||||
v8::Local::<v8::Promise>::try_from(promise.v8_value).unwrap();
|
||||
let promise_global = v8::Global::new(scope, promise_value);
|
||||
state.pending_promise_exceptions.remove(&promise_global);
|
||||
state.pending_promise_rejections.remove(&promise_global);
|
||||
}
|
||||
|
||||
#[op(v8)]
|
||||
fn op_has_pending_promise_exception<'a>(
|
||||
fn op_has_pending_promise_rejection<'a>(
|
||||
scope: &mut v8::HandleScope<'a>,
|
||||
promise: serde_v8::Value<'a>,
|
||||
) -> bool {
|
||||
|
@ -899,7 +899,7 @@ fn op_has_pending_promise_exception<'a>(
|
|||
v8::Local::<v8::Promise>::try_from(promise.v8_value).unwrap();
|
||||
let promise_global = v8::Global::new(scope, promise_value);
|
||||
state
|
||||
.pending_promise_exceptions
|
||||
.pending_promise_rejections
|
||||
.contains_key(&promise_global)
|
||||
}
|
||||
|
||||
|
|
|
@ -169,7 +169,7 @@ pub struct JsRuntimeState {
|
|||
pub(crate) js_macrotask_cbs: Vec<v8::Global<v8::Function>>,
|
||||
pub(crate) js_nexttick_cbs: Vec<v8::Global<v8::Function>>,
|
||||
pub(crate) has_tick_scheduled: bool,
|
||||
pub(crate) pending_promise_exceptions:
|
||||
pub(crate) pending_promise_rejections:
|
||||
HashMap<v8::Global<v8::Promise>, v8::Global<v8::Value>>,
|
||||
pub(crate) pending_dyn_mod_evaluate: Vec<DynImportModEvaluate>,
|
||||
pub(crate) pending_mod_evaluate: Option<ModEvaluate>,
|
||||
|
@ -187,7 +187,7 @@ pub struct JsRuntimeState {
|
|||
/// It will be retrieved by `exception_to_err_result` and used as an error
|
||||
/// instead of any other exceptions.
|
||||
// TODO(nayeemrmn): This is polled in `exception_to_err_result()` which is
|
||||
// flimsy. Try to poll it similarly to `pending_promise_exceptions`.
|
||||
// flimsy. Try to poll it similarly to `pending_promise_rejections`.
|
||||
pub(crate) dispatched_exceptions: VecDeque<v8::Global<v8::Value>>,
|
||||
pub(crate) inspector: Option<Rc<RefCell<JsRuntimeInspector>>>,
|
||||
waker: AtomicWaker,
|
||||
|
@ -384,7 +384,7 @@ impl JsRuntime {
|
|||
unsafe { std::alloc::alloc(layout) as *mut _ };
|
||||
|
||||
let state_rc = Rc::new(RefCell::new(JsRuntimeState {
|
||||
pending_promise_exceptions: HashMap::new(),
|
||||
pending_promise_rejections: HashMap::new(),
|
||||
pending_dyn_mod_evaluate: vec![],
|
||||
pending_mod_evaluate: None,
|
||||
dyn_module_evaluate_idle_counter: 0,
|
||||
|
@ -1169,7 +1169,7 @@ impl JsRuntime {
|
|||
// run in macrotasks callbacks so we need to let them run first).
|
||||
self.drain_nexttick()?;
|
||||
self.drain_macrotasks()?;
|
||||
self.check_promise_exceptions()?;
|
||||
self.check_promise_rejections()?;
|
||||
|
||||
// Event loop middlewares
|
||||
let mut maybe_scheduling = false;
|
||||
|
@ -1688,7 +1688,7 @@ impl JsRuntime {
|
|||
.handled_promise_rejections
|
||||
.contains(&promise_global);
|
||||
if !pending_rejection_was_already_handled {
|
||||
state.pending_promise_exceptions.remove(&promise_global);
|
||||
state.pending_promise_rejections.remove(&promise_global);
|
||||
}
|
||||
}
|
||||
let promise_global = v8::Global::new(tc_scope, promise);
|
||||
|
@ -2126,22 +2126,22 @@ impl JsRuntime {
|
|||
Ok(root_id)
|
||||
}
|
||||
|
||||
fn check_promise_exceptions(&mut self) -> Result<(), Error> {
|
||||
fn check_promise_rejections(&mut self) -> Result<(), Error> {
|
||||
let mut state = self.state.borrow_mut();
|
||||
|
||||
if state.pending_promise_exceptions.is_empty() {
|
||||
if state.pending_promise_rejections.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let key = {
|
||||
state
|
||||
.pending_promise_exceptions
|
||||
.pending_promise_rejections
|
||||
.keys()
|
||||
.next()
|
||||
.unwrap()
|
||||
.clone()
|
||||
};
|
||||
let handle = state.pending_promise_exceptions.remove(&key).unwrap();
|
||||
let handle = state.pending_promise_rejections.remove(&key).unwrap();
|
||||
drop(state);
|
||||
|
||||
let scope = &mut self.handle_scope();
|
||||
|
@ -4046,7 +4046,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
|
|||
if (reason.message !== "reject") {
|
||||
throw Error("unexpected reason: " + reason);
|
||||
}
|
||||
Deno.core.ops.op_store_pending_promise_exception(promise);
|
||||
Deno.core.ops.op_store_pending_promise_rejection(promise);
|
||||
Deno.core.ops.op_promise_reject();
|
||||
});
|
||||
new Promise((_, reject) => reject(Error("reject")));
|
||||
|
|
|
@ -323,13 +323,13 @@ delete Intl.v8BreakIterator;
|
|||
function promiseRejectCallback(type, promise, reason) {
|
||||
switch (type) {
|
||||
case 0: {
|
||||
ops.op_store_pending_promise_exception(promise, reason);
|
||||
ops.op_store_pending_promise_rejection(promise, reason);
|
||||
ArrayPrototypePush(pendingRejections, promise);
|
||||
WeakMapPrototypeSet(pendingRejectionsReasons, promise, reason);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
ops.op_remove_pending_promise_exception(promise);
|
||||
ops.op_remove_pending_promise_rejection(promise);
|
||||
const index = ArrayPrototypeIndexOf(pendingRejections, promise);
|
||||
if (index > -1) {
|
||||
ArrayPrototypeSplice(pendingRejections, index, 1);
|
||||
|
@ -348,7 +348,7 @@ delete Intl.v8BreakIterator;
|
|||
function promiseRejectMacrotaskCallback() {
|
||||
while (pendingRejections.length > 0) {
|
||||
const promise = ArrayPrototypeShift(pendingRejections);
|
||||
const hasPendingException = ops.op_has_pending_promise_exception(
|
||||
const hasPendingException = ops.op_has_pending_promise_rejection(
|
||||
promise,
|
||||
);
|
||||
const reason = WeakMapPrototypeGet(pendingRejectionsReasons, promise);
|
||||
|
@ -369,7 +369,7 @@ delete Intl.v8BreakIterator;
|
|||
|
||||
const errorEventCb = (event) => {
|
||||
if (event.error === reason) {
|
||||
ops.op_remove_pending_promise_exception(promise);
|
||||
ops.op_remove_pending_promise_rejection(promise);
|
||||
}
|
||||
};
|
||||
// Add a callback for "error" event - it will be dispatched
|
||||
|
@ -382,7 +382,7 @@ delete Intl.v8BreakIterator;
|
|||
// If event was not prevented (or "unhandledrejection" listeners didn't
|
||||
// throw) we will let Rust side handle it.
|
||||
if (rejectionEvent.defaultPrevented) {
|
||||
ops.op_remove_pending_promise_exception(promise);
|
||||
ops.op_remove_pending_promise_rejection(promise);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue