Skip to content
Merged
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
476 changes: 269 additions & 207 deletions Cargo.lock

Large diffs are not rendered by default.

574 changes: 291 additions & 283 deletions src/agent/mod.rs

Large diffs are not rendered by default.

74 changes: 35 additions & 39 deletions src/agent/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ mod agent {

// All well-known symbols initialized, and different from one another.
let symbols = [
agent.symbols.async_iterator_,
agent.symbols.has_instance_,
agent.symbols.is_concat_spreadable_,
agent.symbols.iterator_,
agent.symbols.async_iterator,
agent.symbols.has_instance,
agent.symbols.is_concat_spreadable,
agent.symbols.iterator,
agent.symbols.match_,
agent.symbols.match_all_,
agent.symbols.replace_,
agent.symbols.search_,
agent.symbols.species_,
agent.symbols.split_,
agent.symbols.to_primitive_,
agent.symbols.to_string_tag_,
agent.symbols.unscopables_,
agent.symbols.match_all,
agent.symbols.replace,
agent.symbols.search,
agent.symbols.species,
agent.symbols.split,
agent.symbols.to_primitive,
agent.symbols.to_string_tag,
agent.symbols.unscopables,
];
let num_symbols = symbols.len();
let symbol_set = symbols.iter().collect::<AHashSet<_>>();
Expand All @@ -57,19 +57,19 @@ mod agent {

// All well-known symbols initialized, and different from one another.
let symbols = [
agent.symbols.async_iterator_,
agent.symbols.has_instance_,
agent.symbols.is_concat_spreadable_,
agent.symbols.iterator_,
agent.symbols.async_iterator,
agent.symbols.has_instance,
agent.symbols.is_concat_spreadable,
agent.symbols.iterator,
agent.symbols.match_,
agent.symbols.match_all_,
agent.symbols.replace_,
agent.symbols.search_,
agent.symbols.species_,
agent.symbols.split_,
agent.symbols.to_primitive_,
agent.symbols.to_string_tag_,
agent.symbols.unscopables_,
agent.symbols.match_all,
agent.symbols.replace,
agent.symbols.search,
agent.symbols.species,
agent.symbols.split,
agent.symbols.to_primitive,
agent.symbols.to_string_tag,
agent.symbols.unscopables,
];
let num_symbols = symbols.len();
let symbol_set = symbols.iter().collect::<AHashSet<_>>();
Expand Down Expand Up @@ -912,15 +912,15 @@ mod top_level_lex_decl {

fn make_class_decl() -> MakerResult {
let cd = Maker::new("class alice {}").class_declaration();
(Some(cd.clone()), None, DeclPart::ClassDeclaration(cd))
(Some(cd.clone()), None, DeclPart::Class(cd))
}
fn make_lex_decl() -> MakerResult {
let ld = Maker::new("let alice = 999;").lexical_declaration();
(None, Some(ld.clone()), DeclPart::LexicalDeclaration(ld))
(None, Some(ld.clone()), DeclPart::Lexical(ld))
}
fn make_func_decl() -> MakerResult {
let fd = Maker::new("function alice(bob) { return charlie(bob); }").function_declaration();
(None, None, DeclPart::FunctionDeclaration(fd))
(None, None, DeclPart::Function(fd))
}
#[test_case(make_class_decl => Ok((true, false)); "class")]
#[test_case(make_lex_decl => Ok((false, true)); "lexical")]
Expand Down Expand Up @@ -1021,27 +1021,27 @@ mod fcn_def {
);
fn decl_func() -> MakerDeclResult {
let fd = Maker::new("function alice(bob) { return charlie(bob); }").function_declaration();
(Some(fd.clone()), None, None, None, DeclPart::FunctionDeclaration(fd))
(Some(fd.clone()), None, None, None, DeclPart::Function(fd))
}
fn decl_gen() -> MakerDeclResult {
let gd = Maker::new("function *alice(bob) { return charlie(bob); }").generator_declaration();
(None, Some(gd.clone()), None, None, DeclPart::GeneratorDeclaration(gd))
(None, Some(gd.clone()), None, None, DeclPart::Generator(gd))
}
fn decl_async() -> MakerDeclResult {
let afd = Maker::new("async function alice(bob) { return charlie(bob); }").async_function_declaration();
(None, None, Some(afd.clone()), None, DeclPart::AsyncFunctionDeclaration(afd))
(None, None, Some(afd.clone()), None, DeclPart::AsyncFunction(afd))
}
fn decl_async_gen() -> MakerDeclResult {
let agd = Maker::new("async function *alice(bob) { return charlie(bob); }").async_generator_declaration();
(None, None, None, Some(agd.clone()), DeclPart::AsyncGeneratorDeclaration(agd))
(None, None, None, Some(agd.clone()), DeclPart::AsyncGenerator(agd))
}
fn decl_class() -> MakerDeclResult {
let cls = Maker::new("class alice {}").class_declaration();
(None, None, None, None, DeclPart::ClassDeclaration(cls))
(None, None, None, None, DeclPart::Class(cls))
}
fn decl_lex() -> MakerDeclResult {
let ld = Maker::new("let alice;").lexical_declaration();
(None, None, None, None, DeclPart::LexicalDeclaration(ld))
(None, None, None, None, DeclPart::Lexical(ld))
}
#[test_case(decl_func => Ok(true); "Function decl")]
#[test_case(decl_gen => Ok(true); "Generator decl")]
Expand Down Expand Up @@ -1213,14 +1213,10 @@ mod process_error {

#[test]
fn debug() {
let s = format!("{:?}", ProcessError::InternalError { reason: "random reason".into() });
let s = format!("{:?}", ProcessError::RuntimeError { error: "random reason".into() });
assert_ne!(s, "");
}

fn internal_err() -> ProcessError {
ProcessError::InternalError { reason: "blue".into() }
}

fn runtime_err_obj() -> ProcessError {
let err = create_type_error_object("test sentinel");
ProcessError::RuntimeError { error: err.into() }
Expand All @@ -1246,7 +1242,7 @@ mod process_error {
],
}
}
#[test_case(internal_err => "blue"; "internal error")]
//#[test_case(internal_err => "blue"; "internal error")]
#[test_case(runtime_err_obj => "Thrown: TypeError: test sentinel"; "error obj runtime")]
#[test_case(runtime_err_value => "Thrown: test sentinel"; "error value runtime")]
#[test_case(runtime_err_non_err_obj => using matches_object; "error obj but not error")]
Expand Down
22 changes: 11 additions & 11 deletions src/arguments_object/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;

pub struct ParameterMap {
pub(crate) struct ParameterMap {
env: Rc<dyn EnvironmentRecord>,
properties: Vec<Option<JSString>>,
}
Expand All @@ -15,11 +15,11 @@ impl std::fmt::Debug for ParameterMap {
}

impl ParameterMap {
pub fn new(env: Rc<dyn EnvironmentRecord>) -> Self {
pub(crate) fn new(env: Rc<dyn EnvironmentRecord>) -> Self {
ParameterMap { env, properties: Vec::new() }
}

pub fn add_mapped_name(&mut self, name: JSString, loc: usize) {
pub(crate) fn add_mapped_name(&mut self, name: JSString, loc: usize) {
if self.properties.len() <= loc {
self.properties.resize_with(loc + 1, Default::default);
}
Expand All @@ -35,29 +35,29 @@ impl ParameterMap {
None
}

pub fn to_index(&self, key: &PropertyKey) -> Option<usize> {
pub(crate) fn to_index(&self, key: &PropertyKey) -> Option<usize> {
ParameterMap::idx_from_key(key).filter(|&idx| idx < self.properties.len() && self.properties[idx].is_some())
}

pub fn delete(&mut self, idx: usize) {
pub(crate) fn delete(&mut self, idx: usize) {
self.properties[idx] = None;
}

pub fn get(&self, idx: usize) -> Completion<ECMAScriptValue> {
pub(crate) fn get(&self, idx: usize) -> Completion<ECMAScriptValue> {
let name = self.properties[idx].as_ref().expect("Get only used on existing values");
self.env.get_binding_value(name, false)
}

pub fn set(&self, idx: usize, value: ECMAScriptValue) -> Completion<()> {
pub(crate) fn set(&self, idx: usize, value: ECMAScriptValue) -> Completion<()> {
let name = self.properties[idx].as_ref().expect("Set only used on existing values").clone();
self.env.set_mutable_binding(name, value, false)
}
}

#[derive(Debug)]
pub struct ArgumentsObject {
pub(crate) struct ArgumentsObject {
common: RefCell<CommonObjectData>,
pub parameter_map: Option<RefCell<ParameterMap>>,
pub(crate) parameter_map: Option<RefCell<ParameterMap>>,
}

impl<'a> From<&'a ArgumentsObject> for &'a dyn ObjectInterface {
Expand Down Expand Up @@ -332,12 +332,12 @@ impl ObjectInterface for ArgumentsObject {
}

impl ArgumentsObject {
pub fn object(parameter_map: Option<ParameterMap>) -> Object {
pub(crate) fn object(parameter_map: Option<ParameterMap>) -> Object {
let prototype = Some(intrinsic(IntrinsicId::ObjectPrototype));
Object { o: Rc::new(Self::new(prototype, parameter_map)) }
}

pub fn new(prototype: Option<Object>, parameter_map: Option<ParameterMap>) -> Self {
pub(crate) fn new(prototype: Option<Object>, parameter_map: Option<ParameterMap>) -> Self {
Self {
common: RefCell::new(CommonObjectData::new(prototype, true, ARGUMENTS_OBJECT_SLOTS)),
parameter_map: parameter_map.map(RefCell::new),
Expand Down
35 changes: 18 additions & 17 deletions src/arrays/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::rc::Rc;
const ARRAY_INDEX_LIMIT: f64 = 9_007_199_254_740_991.0; // (2 ^ 53) - 1

#[derive(Debug)]
pub struct ArrayObject {
pub(crate) struct ArrayObject {
common: RefCell<CommonObjectData>,
}

Expand Down Expand Up @@ -136,6 +136,7 @@ impl ObjectInterface for ArrayObject {
fn is_array_object(&self) -> bool {
true
}
#[cfg(test)]
fn to_array_object(&self) -> Option<&ArrayObject> {
Some(self)
}
Expand Down Expand Up @@ -165,7 +166,7 @@ impl ObjectInterface for ArrayObject {
/// ```rust
/// let array = array_create(5.0, None)?; // Creates array with length 5 and default prototype
/// ```
pub fn array_create(length: f64, proto: Option<Object>) -> Completion<Object> {
pub(crate) fn array_create(length: f64, proto: Option<Object>) -> Completion<Object> {
ArrayObject::create(length, proto)
}

Expand Down Expand Up @@ -200,7 +201,7 @@ impl ArrayObject {
/// * Prototype initialization
/// * Length property setup with attributes { \[\[Value]]: length, \[\[Writable]]: true, \[\[Enumerable]]: false,
/// \[\[Configurable]]: false }
pub fn create(length: f64, proto: Option<Object>) -> Completion<Object> {
pub(crate) fn create(length: f64, proto: Option<Object>) -> Completion<Object> {
// ArrayCreate ( length [ , proto ] )
//
// The abstract operation ArrayCreate takes argument length (a non-negative integer) and optional argument
Expand Down Expand Up @@ -250,7 +251,7 @@ impl ArrayObject {
/// ```rust
/// let array = ArrayObject::new(None); // Creates array with default prototype
/// ```
pub fn new(prototype: Option<Object>) -> Self {
pub(crate) fn new(prototype: Option<Object>) -> Self {
Self { common: RefCell::new(CommonObjectData::new(prototype, true, ARRAY_OBJECT_SLOTS)) }
}
/// Creates a new Array exotic object wrapped in a shared reference.
Expand All @@ -275,7 +276,7 @@ impl ArrayObject {
/// ```rust
/// let array = ArrayObject::object(None); // Creates reference-counted array with default prototype
/// ```
pub fn object(prototype: Option<Object>) -> Object {
pub(crate) fn object(prototype: Option<Object>) -> Object {
Object { o: Rc::new(Self::new(prototype)) }
}

Expand Down Expand Up @@ -457,7 +458,7 @@ impl Object {
/// Note: If the original array was created using the standard Array constructor from a different realm,
/// a new Array is created using the current realm's Array constructor. This maintains compatibility
/// with web browsers' historical behavior for Array.prototype methods.
pub fn array_species_create(&self, length: f64) -> Completion<ECMAScriptValue> {
pub(crate) fn array_species_create(&self, length: f64) -> Completion<ECMAScriptValue> {
// ArraySpeciesCreate ( originalArray, length )
//
// The abstract operation ArraySpeciesCreate takes arguments originalArray and length (a non-negative integer).
Expand Down Expand Up @@ -517,7 +518,7 @@ impl Object {
}
}

pub fn provision_array_intrinsic(realm: &Rc<RefCell<Realm>>) {
pub(crate) fn provision_array_intrinsic(realm: &Rc<RefCell<Realm>>) {
let object_prototype = realm.borrow().intrinsics.object_prototype.clone();
let function_prototype = realm.borrow().intrinsics.function_prototype.clone();

Expand Down Expand Up @@ -725,7 +726,7 @@ pub fn provision_array_intrinsic(realm: &Rc<RefCell<Realm>>) {
Object::try_from(array_prototype_values).expect("values should be an object");
}

pub fn provision_array_iterator_intrinsic(realm: &Rc<RefCell<Realm>>) {
pub(crate) fn provision_array_iterator_intrinsic(realm: &Rc<RefCell<Realm>>) {
// The %ArrayIteratorPrototype% Object
//
// * has properties that are inherited by all Array Iterator Objects.
Expand Down Expand Up @@ -1214,7 +1215,7 @@ fn array_prototype_concat(
}

impl ECMAScriptValue {
pub fn is_concat_spreadable(&self) -> Completion<bool> {
pub(crate) fn is_concat_spreadable(&self) -> Completion<bool> {
// IsConcatSpreadable ( O )
// The abstract operation IsConcatSpreadable takes argument O (an ECMAScript language value) and returns either
// a normal completion containing a Boolean or a throw completion. It performs the following steps when called:
Expand Down Expand Up @@ -1402,7 +1403,7 @@ fn array_prototype_every(
let k_value = o.get(&pk)?;
let test_result =
call(&callback, &this_arg, &[k_value, ECMAScriptValue::from(k), ECMAScriptValue::from(o.clone())])?
.to_boolean();
.into_boolean();
if !test_result {
return Ok(ECMAScriptValue::Boolean(false));
}
Expand Down Expand Up @@ -1538,7 +1539,7 @@ fn array_prototype_filter(
&this_arg,
&[k_value.clone(), ECMAScriptValue::from(k), ECMAScriptValue::from(o.clone())],
)?
.to_boolean();
.into_boolean();
if selected {
a_obj.create_data_property_or_throw(PropertyKey::from(to), k_value)?;
to += 1.0;
Expand Down Expand Up @@ -1754,7 +1755,7 @@ impl Object {
this_arg,
&[k_value.clone(), ECMAScriptValue::from(k), ECMAScriptValue::from(self.clone())],
)?
.to_boolean();
.into_boolean();
if test_result {
return Ok(FindResult { value: k_value, index: k });
}
Expand Down Expand Up @@ -1794,13 +1795,13 @@ fn array_prototype_flat(
}

#[derive(Debug, Copy, Clone)]
pub enum FlattenOpts<'a> {
pub(crate) enum FlattenOpts<'a> {
Depth(f64),
Mapper { mapper_function: &'a ECMAScriptValue, this_arg: &'a ECMAScriptValue },
}

impl Object {
pub fn flatten_into_array(
pub(crate) fn flatten_into_array(
&self,
source: &Object,
source_len: f64,
Expand Down Expand Up @@ -2841,7 +2842,7 @@ fn array_prototype_some(
let k_value = o.get(&pk)?;
let test_result =
call(&callback, &this_arg, &[k_value, ECMAScriptValue::Number(k), ECMAScriptValue::Object(o.clone())])?
.to_boolean();
.into_boolean();
if test_result {
return Ok(ECMAScriptValue::Boolean(true));
}
Expand Down Expand Up @@ -3375,7 +3376,7 @@ fn array_iterator_prototype_next(
}

#[derive(Debug, PartialEq, Copy, Clone)]
pub enum KeyValueKind {
pub(crate) enum KeyValueKind {
Key,
Value,
KeyValue,
Expand Down Expand Up @@ -3431,7 +3432,7 @@ async fn array_iterator(
}
}

pub fn create_array_iterator(array: Object, kind: KeyValueKind) -> Object {
pub(crate) fn create_array_iterator(array: Object, kind: KeyValueKind) -> Object {
// CreateArrayIterator ( array, kind )
// The abstract operation CreateArrayIterator takes arguments array (an Object) and kind (key+value, key,
// or value) and returns a Generator. It is used to create iterator objects for Array methods that return
Expand Down
Loading
Loading