Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions nova_vm/src/builtin_strings
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ fromCharCode
fromCodePoint
fromEntries
#[cfg(feature = "math")]fround
fulfilled
function
Function
Generator
Expand Down Expand Up @@ -320,6 +321,7 @@ race
#[cfg(feature = "math")]random
RangeError
raw
reason
reduce
reduceRight
ReferenceError
Expand All @@ -328,6 +330,7 @@ Reflect
#[cfg(feature = "regexp")]RegExp String Iterator
register
reject
rejected
repeat
replace
replaceAll
Expand Down Expand Up @@ -389,6 +392,7 @@ split
#[cfg(feature = "math")]SQRT1_2
#[cfg(feature = "math")]SQRT2
startsWith
status
#[cfg(feature = "regexp")]sticky
#[cfg(feature = "atomics")]store
#[cfg(feature = "annex-b-string")]strike
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

pub(crate) mod promise_all;
pub(crate) mod promise_all_record;
pub(crate) mod promise_all_settled_record;
pub mod promise_capability_records;
pub(crate) mod promise_finally_functions;
pub(crate) mod promise_jobs;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use crate::{
ecmascript::{
builtins::{
Array,
promise_objects::promise_abstract_operations::promise_reaction_records::PromiseReactionHandler,
},
execution::Agent,
types::Value,
},
engine::{
context::{Bindable, GcScope, NoGcScope, bindable_handle},
rootable::Rootable,
},
};

pub(crate) trait PromiseAllReactionHandler<'a>: Rootable + Bindable {
fn get_result_array(self, agent: &Agent, gc: NoGcScope<'a, '_>) -> Array<'a>;
fn increase_remaining_elements_count(self, agent: &mut Agent, gc: NoGcScope<'a, '_>);
fn decrease_remaining_elements_count(self, agent: &mut Agent, gc: NoGcScope<'a, '_>);
fn get_remaining_elements_count(self, agent: &Agent, gc: NoGcScope<'a, '_>) -> u32;
fn on_promise_fulfilled(
self,
agent: &mut Agent,
index: u32,
value: Value<'a>,
gc: GcScope<'a, '_>,
);
fn on_promise_rejected(
self,
agent: &mut Agent,
index: u32,
value: Value<'a>,
gc: GcScope<'a, '_>,
);
fn to_reaction_handler(self, index: u32, gc: NoGcScope<'a, '_>) -> PromiseReactionHandler<'a>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
use crate::{
ecmascript::{
builtins::{
Array, promise::Promise,
promise_objects::promise_abstract_operations::promise_capability_records::PromiseCapability,
Array,
promise::Promise,
promise_objects::promise_abstract_operations::{
promise_all::PromiseAllReactionHandler,
promise_capability_records::PromiseCapability,
promise_reaction_records::PromiseReactionHandler,
},
},
execution::Agent,
types::{IntoValue, Value},
Expand All @@ -32,7 +37,38 @@ pub struct PromiseAllRecord<'a> {
pub struct PromiseAll<'a>(BaseIndex<'a, PromiseAllRecord<'static>>);

impl<'a> PromiseAll<'a> {
pub(crate) fn on_promise_fulfilled(
// pub(crate) fn get_result_array(self, agent: &Agent, gc: NoGcScope<'a, '_>) -> Array<'a> {
// let data = self.get(agent);
// data.result_array.bind(gc).unbind()
// }

pub(crate) const fn get_index(self) -> usize {
self.0.into_index()
}

pub fn get(self, agent: &Agent) -> &PromiseAllRecord<'a> {
agent
.heap
.promise_all_records
.get(self.get_index())
.expect("PromiseAllRecord not found")
}

pub fn get_mut(self, agent: &mut Agent) -> &mut PromiseAllRecord<'static> {
agent
.heap
.promise_all_records
.get_mut(self.get_index())
.expect("PromiseAllRecord not found")
}

pub(crate) const fn _def() -> Self {
Self(BaseIndex::from_u32_index(0))
}
}

impl<'a> PromiseAllReactionHandler<'a> for PromiseAll<'a> {
fn on_promise_fulfilled(
self,
agent: &mut Agent,
index: u32,
Expand Down Expand Up @@ -61,47 +97,49 @@ impl<'a> PromiseAll<'a> {
}
}

pub(crate) fn on_promise_rejected(
fn on_promise_rejected(
self,
agent: &mut Agent,
_index: u32,
value: Value<'a>,
gc: NoGcScope<'a, '_>,
gc: GcScope<'a, '_>,
) {
let value = value.bind(gc);
let promise_all = self.bind(gc);
let value = value.bind(gc.nogc());
let promise_all = self.bind(gc.nogc());
let data = promise_all.get_mut(agent);

let capability = PromiseCapability::from_promise(data.promise, true);
capability.reject(agent, value.unbind(), gc);
capability.reject(agent, value.unbind(), gc.nogc());
}

pub(crate) fn get_result_array(self, agent: &Agent, gc: NoGcScope<'a, '_>) -> Array<'a> {
fn get_result_array(self, agent: &Agent, gc: NoGcScope<'a, '_>) -> Array<'a> {
let data = self.get(agent);
data.result_array.bind(gc).unbind()
}

pub(crate) const fn get_index(self) -> usize {
self.0.into_index()
fn increase_remaining_elements_count(self, agent: &mut Agent, gc: NoGcScope<'a, '_>) {
let promise_all = self.bind(gc);
let data = promise_all.get_mut(agent);
data.remaining_elements_count = data.remaining_elements_count.saturating_add(1);
}

pub fn get(self, agent: &Agent) -> &PromiseAllRecord<'a> {
agent
.heap
.promise_all_records
.get(self.get_index())
.expect("PromiseAllRecord not found")
fn decrease_remaining_elements_count(self, agent: &mut Agent, gc: NoGcScope<'a, '_>) {
let promise_all = self.bind(gc);
let data = promise_all.get_mut(agent);
data.remaining_elements_count = data.remaining_elements_count.saturating_sub(1);
}

pub fn get_mut(self, agent: &mut Agent) -> &mut PromiseAllRecord<'static> {
agent
.heap
.promise_all_records
.get_mut(self.get_index())
.expect("PromiseAllRecord not found")
fn get_remaining_elements_count(self, agent: &Agent, gc: NoGcScope<'a, '_>) -> u32 {
let promise_all = self.bind(gc);
promise_all.get(agent).remaining_elements_count
}

pub(crate) const fn _def() -> Self {
Self(BaseIndex::from_u32_index(0))
fn to_reaction_handler(self, index: u32, gc: NoGcScope<'a, '_>) -> PromiseReactionHandler<'a> {
let promise_all = self.bind(gc);
PromiseReactionHandler::PromiseAll {
index,
promise_all: promise_all.unbind(),
}
}
}

Expand Down
Loading
Loading