diff --git a/boa/src/builtins/array/array_iterator.rs b/boa/src/builtins/array/array_iterator.rs index bcf7ae11749..e20400295e3 100644 --- a/boa/src/builtins/array/array_iterator.rs +++ b/boa/src/builtins/array/array_iterator.rs @@ -1,7 +1,7 @@ use crate::{ builtins::{function::make_builtin_fn, iterable::create_iter_result_object, Array, JsValue}, gc::{Finalize, Trace}, - object::{GcObject, ObjectData}, + object::{JsObject, ObjectData}, property::{PropertyDescriptor, PropertyNameKind}, symbol::WellKnownSymbols, BoaProfiler, Context, JsResult, @@ -117,7 +117,7 @@ impl ArrayIterator { /// - [ECMA reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-%arrayiteratorprototype%-object - pub(crate) fn create_prototype(context: &mut Context, iterator_prototype: JsValue) -> GcObject { + pub(crate) fn create_prototype(context: &mut Context, iterator_prototype: JsValue) -> JsObject { let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); // Create prototype diff --git a/boa/src/builtins/array/mod.rs b/boa/src/builtins/array/mod.rs index ba1b47d0d85..a3fd0f636b7 100644 --- a/boa/src/builtins/array/mod.rs +++ b/boa/src/builtins/array/mod.rs @@ -17,7 +17,7 @@ use crate::{ builtins::array::array_iterator::ArrayIterator, builtins::BuiltIn, builtins::Number, - object::{ConstructorBuilder, FunctionBuilder, GcObject, ObjectData, PROTOTYPE}, + object::{ConstructorBuilder, FunctionBuilder, JsObject, ObjectData, PROTOTYPE}, property::{Attribute, PropertyDescriptor, PropertyNameKind}, symbol::WellKnownSymbols, value::{IntegerOrInfinity, JsValue}, @@ -206,9 +206,9 @@ impl Array { /// [spec]: https://tc39.es/ecma262/#sec-arraycreate pub(crate) fn array_create( length: usize, - prototype: Option, + prototype: Option, context: &mut Context, - ) -> JsResult { + ) -> JsResult { // 1. If length > 2^32 - 1, throw a RangeError exception. if length > 2usize.pow(32) - 1 { return Err(context.construct_range_error("array exceeded max size")); @@ -250,7 +250,7 @@ impl Array { /// - [ECMAScript reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-createarrayfromlist - pub(crate) fn create_array_from_list(elements: I, context: &mut Context) -> GcObject + pub(crate) fn create_array_from_list(elements: I, context: &mut Context) -> JsObject where I: IntoIterator, { @@ -335,10 +335,10 @@ impl Array { /// /// see: pub(crate) fn array_species_create( - original_array: &GcObject, + original_array: &JsObject, length: usize, context: &mut Context, - ) -> JsResult { + ) -> JsResult { // 1. Let isArray be ? IsArray(originalArray). // 2. If isArray is false, return ? ArrayCreate(length). if !original_array.is_array() { @@ -667,7 +667,7 @@ impl Array { let callback = if let Some(arg) = args .get(0) .and_then(JsValue::as_object) - .filter(GcObject::is_callable) + .filter(JsObject::is_callable) { arg } else { @@ -772,7 +772,7 @@ impl Array { let func = array.get("join", context)?; // 3. If IsCallable(func) is false, set func to the intrinsic function %Object.prototype.toString%. // 4. Return ? Call(func, array). - if let Some(func) = func.as_object().filter(GcObject::is_callable) { + if let Some(func) = func.as_object().filter(JsObject::is_callable) { func.call(&array.into(), &[], context) } else { crate::builtins::object::Object::to_string(&array.into(), &[], context) @@ -1013,7 +1013,7 @@ impl Array { let callback = if let Some(arg) = args .get(0) .and_then(JsValue::as_object) - .filter(GcObject::is_callable) + .filter(JsObject::is_callable) { arg } else { @@ -1481,12 +1481,12 @@ impl Array { /// [spec]: https://tc39.es/ecma262/#sec-flattenintoarray #[allow(clippy::too_many_arguments)] fn flatten_into_array( - target: &GcObject, - source: &GcObject, + target: &JsObject, + source: &JsObject, source_len: u64, start: u64, depth: u64, - mapper_function: Option, + mapper_function: Option, this_arg: &JsValue, context: &mut Context, ) -> JsResult { @@ -1879,7 +1879,7 @@ impl Array { let callback = if let Some(arg) = args .get(0) .and_then(JsValue::as_object) - .filter(GcObject::is_callable) + .filter(JsObject::is_callable) { arg } else { diff --git a/boa/src/builtins/function/mod.rs b/boa/src/builtins/function/mod.rs index 9ee1b7567e5..29575f2ba07 100644 --- a/boa/src/builtins/function/mod.rs +++ b/boa/src/builtins/function/mod.rs @@ -16,7 +16,7 @@ use crate::{ builtins::{Array, BuiltIn}, environment::lexical_environment::Environment, gc::{custom_trace, empty_trace, Finalize, Trace}, - object::{ConstructorBuilder, FunctionBuilder, GcObject, Object, ObjectData}, + object::{ConstructorBuilder, FunctionBuilder, JsObject, Object, ObjectData}, property::{Attribute, PropertyDescriptor}, syntax::ast::node::{FormalParameter, RcStatementList}, BoaProfiler, Context, JsResult, JsValue, @@ -179,7 +179,7 @@ impl Function { /// pub fn create_unmapped_arguments_object(arguments_list: &[JsValue]) -> JsValue { let len = arguments_list.len(); - let obj = GcObject::new(Object::default()); + let obj = JsObject::new(Object::default()); // Set length let length = PropertyDescriptor::builder() .value(len) @@ -225,7 +225,7 @@ pub fn create_unmapped_arguments_object(arguments_list: &[JsValue]) -> JsValue { pub fn make_builtin_fn( function: NativeFunction, name: N, - parent: &GcObject, + parent: &JsObject, length: usize, interpreter: &Context, ) where diff --git a/boa/src/builtins/iterable/mod.rs b/boa/src/builtins/iterable/mod.rs index 157137daaf0..b79d129d4e8 100644 --- a/boa/src/builtins/iterable/mod.rs +++ b/boa/src/builtins/iterable/mod.rs @@ -4,20 +4,20 @@ use crate::{ string::string_iterator::StringIterator, ArrayIterator, ForInIterator, MapIterator, SetIterator, }, - object::{GcObject, ObjectInitializer}, + object::{JsObject, ObjectInitializer}, symbol::WellKnownSymbols, BoaProfiler, Context, JsResult, JsValue, }; #[derive(Debug, Default)] pub struct IteratorPrototypes { - iterator_prototype: GcObject, - array_iterator: GcObject, - set_iterator: GcObject, - string_iterator: GcObject, - regexp_string_iterator: GcObject, - map_iterator: GcObject, - for_in_iterator: GcObject, + iterator_prototype: JsObject, + array_iterator: JsObject, + set_iterator: JsObject, + string_iterator: JsObject, + regexp_string_iterator: JsObject, + map_iterator: JsObject, + for_in_iterator: JsObject, } impl IteratorPrototypes { @@ -47,37 +47,37 @@ impl IteratorPrototypes { } #[inline] - pub fn array_iterator(&self) -> GcObject { + pub fn array_iterator(&self) -> JsObject { self.array_iterator.clone() } #[inline] - pub fn iterator_prototype(&self) -> GcObject { + pub fn iterator_prototype(&self) -> JsObject { self.iterator_prototype.clone() } #[inline] - pub fn set_iterator(&self) -> GcObject { + pub fn set_iterator(&self) -> JsObject { self.set_iterator.clone() } #[inline] - pub fn string_iterator(&self) -> GcObject { + pub fn string_iterator(&self) -> JsObject { self.string_iterator.clone() } #[inline] - pub fn regexp_string_iterator(&self) -> GcObject { + pub fn regexp_string_iterator(&self) -> JsObject { self.regexp_string_iterator.clone() } #[inline] - pub fn map_iterator(&self) -> GcObject { + pub fn map_iterator(&self) -> JsObject { self.map_iterator.clone() } #[inline] - pub fn for_in_iterator(&self) -> GcObject { + pub fn for_in_iterator(&self) -> JsObject { self.for_in_iterator.clone() } } @@ -120,7 +120,7 @@ pub fn get_iterator(context: &mut Context, iterable: JsValue) -> JsResult GcObject { +fn create_iterator_prototype(context: &mut Context) -> JsObject { let _timer = BoaProfiler::global().start_event("Iterator Prototype", "init"); let symbol_iterator = WellKnownSymbols::iterator(); diff --git a/boa/src/builtins/map/map_iterator.rs b/boa/src/builtins/map/map_iterator.rs index da2bdbf7d0e..644938fe6c8 100644 --- a/boa/src/builtins/map/map_iterator.rs +++ b/boa/src/builtins/map/map_iterator.rs @@ -1,6 +1,6 @@ use crate::{ builtins::{function::make_builtin_fn, iterable::create_iter_result_object, Array, JsValue}, - object::{GcObject, ObjectData}, + object::{JsObject, ObjectData}, property::{PropertyDescriptor, PropertyNameKind}, symbol::WellKnownSymbols, BoaProfiler, Context, JsResult, @@ -146,7 +146,7 @@ impl MapIterator { /// - [ECMA reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-%mapiteratorprototype%-object - pub(crate) fn create_prototype(context: &mut Context, iterator_prototype: JsValue) -> GcObject { + pub(crate) fn create_prototype(context: &mut Context, iterator_prototype: JsValue) -> JsObject { let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); // Create prototype diff --git a/boa/src/builtins/map/ordered_map.rs b/boa/src/builtins/map/ordered_map.rs index c2581a9d5f8..dc97d5c397d 100644 --- a/boa/src/builtins/map/ordered_map.rs +++ b/boa/src/builtins/map/ordered_map.rs @@ -1,6 +1,6 @@ use crate::{ gc::{custom_trace, Finalize, Trace}, - object::GcObject, + object::JsObject, JsValue, }; use indexmap::{Equivalent, IndexMap}; @@ -182,7 +182,7 @@ impl OrderedMap { /// Increases the lock counter and returns a lock object that will decrement the counter when dropped. /// /// This allows objects to be removed from the map during iteration without affecting the indexes until the iteration has completed. - pub(crate) fn lock(&mut self, map: GcObject) -> MapLock { + pub(crate) fn lock(&mut self, map: JsObject) -> MapLock { self.lock += 1; MapLock(map) } @@ -199,7 +199,7 @@ impl OrderedMap { /// Increases the lock count of the map for the lifetime of the guard. This should not be dropped until iteration has completed. #[derive(Debug, Trace)] -pub(crate) struct MapLock(GcObject); +pub(crate) struct MapLock(JsObject); impl Clone for MapLock { fn clone(&self) -> Self { diff --git a/boa/src/builtins/object/for_in_iterator.rs b/boa/src/builtins/object/for_in_iterator.rs index a7751860474..a5634ed1bfe 100644 --- a/boa/src/builtins/object/for_in_iterator.rs +++ b/boa/src/builtins/object/for_in_iterator.rs @@ -1,7 +1,7 @@ use crate::{ builtins::{function::make_builtin_fn, iterable::create_iter_result_object}, gc::{Finalize, Trace}, - object::{GcObject, ObjectData}, + object::{JsObject, ObjectData}, property::PropertyDescriptor, property::PropertyKey, symbol::WellKnownSymbols, @@ -129,7 +129,7 @@ impl ForInIterator { /// - [ECMA reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-%foriniteratorprototype%-object - pub(crate) fn create_prototype(context: &mut Context, iterator_prototype: JsValue) -> GcObject { + pub(crate) fn create_prototype(context: &mut Context, iterator_prototype: JsValue) -> JsObject { let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); // Create prototype diff --git a/boa/src/builtins/regexp/mod.rs b/boa/src/builtins/regexp/mod.rs index 4eb32d03e98..0fa618191b5 100644 --- a/boa/src/builtins/regexp/mod.rs +++ b/boa/src/builtins/regexp/mod.rs @@ -14,7 +14,7 @@ pub mod regexp_string_iterator; use crate::{ builtins::{array::Array, string, BuiltIn}, gc::{empty_trace, Finalize, Trace}, - object::{ConstructorBuilder, FunctionBuilder, GcObject, Object, ObjectData, PROTOTYPE}, + object::{ConstructorBuilder, FunctionBuilder, JsObject, Object, ObjectData, PROTOTYPE}, property::Attribute, symbol::WellKnownSymbols, value::{IntegerOrInfinity, JsValue}, @@ -265,7 +265,7 @@ impl RegExp { .into() }; - Ok(GcObject::new(Object::create(proto)).into()) + Ok(JsObject::new(Object::create(proto)).into()) } /// `22.2.3.2.2 RegExpInitialize ( obj, pattern, flags )` @@ -415,7 +415,7 @@ impl RegExp { })); } - if GcObject::equals( + if JsObject::equals( &object, &context.standard_objects().regexp_object().prototype, ) { @@ -779,7 +779,7 @@ impl RegExp { this: &JsValue, input: JsString, context: &mut Context, - ) -> JsResult> { + ) -> JsResult> { // 1. Assert: Type(R) is Object. let object = this .as_object() @@ -821,10 +821,10 @@ impl RegExp { /// /// [spec]: https://tc39.es/ecma262/#sec-regexpbuiltinexec pub(crate) fn abstract_builtin_exec( - this: GcObject, + this: JsObject, input: JsString, context: &mut Context, - ) -> JsResult> { + ) -> JsResult> { // 1. Assert: R is an initialized RegExp instance. let rx = { let obj = this.borrow(); diff --git a/boa/src/builtins/regexp/regexp_string_iterator.rs b/boa/src/builtins/regexp/regexp_string_iterator.rs index 292e1c54158..a0b485ee93a 100644 --- a/boa/src/builtins/regexp/regexp_string_iterator.rs +++ b/boa/src/builtins/regexp/regexp_string_iterator.rs @@ -14,7 +14,7 @@ use regexp::{advance_string_index, RegExp}; use crate::{ builtins::{function::make_builtin_fn, iterable::create_iter_result_object, regexp}, gc::{Finalize, Trace}, - object::{GcObject, ObjectData}, + object::{JsObject, ObjectData}, property::PropertyDescriptor, symbol::WellKnownSymbols, BoaProfiler, Context, JsResult, JsString, JsValue, @@ -161,7 +161,7 @@ impl RegExpStringIterator { /// - [ECMA reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-%arrayiteratorprototype%-object - pub(crate) fn create_prototype(context: &mut Context, iterator_prototype: JsValue) -> GcObject { + pub(crate) fn create_prototype(context: &mut Context, iterator_prototype: JsValue) -> JsObject { let _timer = BoaProfiler::global().start_event("RegExp String Iterator", "init"); // Create prototype diff --git a/boa/src/builtins/set/set_iterator.rs b/boa/src/builtins/set/set_iterator.rs index 2b498319953..33742708467 100644 --- a/boa/src/builtins/set/set_iterator.rs +++ b/boa/src/builtins/set/set_iterator.rs @@ -3,7 +3,7 @@ use crate::{ builtins::iterable::create_iter_result_object, builtins::Array, builtins::JsValue, - object::{GcObject, ObjectData}, + object::{JsObject, ObjectData}, property::{PropertyDescriptor, PropertyNameKind}, symbol::WellKnownSymbols, BoaProfiler, Context, JsResult, @@ -141,7 +141,7 @@ impl SetIterator { /// - [ECMA reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-%setiteratorprototype%-object - pub(crate) fn create_prototype(context: &mut Context, iterator_prototype: JsValue) -> GcObject { + pub(crate) fn create_prototype(context: &mut Context, iterator_prototype: JsValue) -> JsObject { let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); // Create prototype diff --git a/boa/src/builtins/string/string_iterator.rs b/boa/src/builtins/string/string_iterator.rs index 3d8e5372a34..8bbe35e57b7 100644 --- a/boa/src/builtins/string/string_iterator.rs +++ b/boa/src/builtins/string/string_iterator.rs @@ -3,7 +3,7 @@ use crate::{ function::make_builtin_fn, iterable::create_iter_result_object, string::code_point_at, }, gc::{Finalize, Trace}, - object::{GcObject, ObjectData}, + object::{JsObject, ObjectData}, property::PropertyDescriptor, symbol::WellKnownSymbols, BoaProfiler, Context, JsResult, JsValue, @@ -78,7 +78,7 @@ impl StringIterator { /// - [ECMA reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-%arrayiteratorprototype%-object - pub(crate) fn create_prototype(context: &mut Context, iterator_prototype: JsValue) -> GcObject { + pub(crate) fn create_prototype(context: &mut Context, iterator_prototype: JsValue) -> JsObject { let _timer = BoaProfiler::global().start_event("String Iterator", "init"); // Create prototype diff --git a/boa/src/class.rs b/boa/src/class.rs index 70959fe85b8..519b504b874 100644 --- a/boa/src/class.rs +++ b/boa/src/class.rs @@ -62,7 +62,7 @@ use crate::{ builtins::function::NativeFunction, - object::{ConstructorBuilder, GcObject, NativeObject, ObjectData, PROTOTYPE}, + object::{ConstructorBuilder, JsObject, NativeObject, ObjectData, PROTOTYPE}, property::{Attribute, PropertyDescriptor, PropertyKey}, Context, JsResult, JsValue, }; @@ -165,7 +165,7 @@ impl<'context> ClassBuilder<'context> { } #[inline] - pub(crate) fn build(mut self) -> GcObject { + pub(crate) fn build(mut self) -> JsObject { self.builder.build() } @@ -231,8 +231,8 @@ impl<'context> ClassBuilder<'context> { pub fn accessor( &mut self, key: K, - get: Option, - set: Option, + get: Option, + set: Option, attribute: Attribute, ) -> &mut Self where @@ -249,8 +249,8 @@ impl<'context> ClassBuilder<'context> { pub fn static_accessor( &mut self, key: K, - get: Option, - set: Option, + get: Option, + set: Option, attribute: Attribute, ) -> &mut Self where diff --git a/boa/src/context.rs b/boa/src/context.rs index 9e1d265d300..0db7c9302cc 100644 --- a/boa/src/context.rs +++ b/boa/src/context.rs @@ -8,7 +8,7 @@ use crate::{ }, class::{Class, ClassBuilder}, exec::Interpreter, - object::{FunctionBuilder, GcObject, Object, PROTOTYPE}, + object::{FunctionBuilder, JsObject, Object, PROTOTYPE}, property::{Attribute, PropertyDescriptor, PropertyKey}, realm::Realm, syntax::{ @@ -33,15 +33,15 @@ use crate::vm::Vm; /// Store a builtin constructor (such as `Object`) and its corresponding prototype. #[derive(Debug, Clone)] pub struct StandardConstructor { - pub(crate) constructor: GcObject, - pub(crate) prototype: GcObject, + pub(crate) constructor: JsObject, + pub(crate) prototype: JsObject, } impl Default for StandardConstructor { fn default() -> Self { Self { - constructor: GcObject::new(Object::default()), - prototype: GcObject::new(Object::default()), + constructor: JsObject::new(Object::default()), + prototype: JsObject::new(Object::default()), } } } @@ -50,8 +50,8 @@ impl StandardConstructor { /// Build a constructor with a defined prototype. fn with_prototype(prototype: Object) -> Self { Self { - constructor: GcObject::new(Object::default()), - prototype: GcObject::new(prototype), + constructor: JsObject::new(Object::default()), + prototype: JsObject::new(prototype), } } @@ -59,7 +59,7 @@ impl StandardConstructor { /// /// This is the same as `Object`, `Array`, etc. #[inline] - pub fn constructor(&self) -> GcObject { + pub fn constructor(&self) -> JsObject { self.constructor.clone() } @@ -67,7 +67,7 @@ impl StandardConstructor { /// /// This is the same as `Object.prototype`, `Array.prototype`, etc #[inline] - pub fn prototype(&self) -> GcObject { + pub fn prototype(&self) -> JsObject { self.prototype.clone() } } @@ -333,9 +333,9 @@ impl Context { /// Construct an empty object. #[inline] - pub fn construct_object(&self) -> GcObject { + pub fn construct_object(&self) -> JsObject { let object_prototype: JsValue = self.standard_objects().object_object().prototype().into(); - GcObject::new(Object::create(object_prototype)) + JsObject::new(Object::create(object_prototype)) } /// @@ -354,7 +354,7 @@ impl Context { /// Return the global object. #[inline] - pub fn global_object(&self) -> GcObject { + pub fn global_object(&self) -> JsObject { self.realm.global_object.clone() } @@ -547,7 +547,7 @@ impl Context { environment: self.get_current_environment().clone(), }; - let function = GcObject::new(Object::function(func, function_prototype)); + let function = JsObject::new(Object::function(func, function_prototype)); // Set constructor field to the newly created Value (function object) let constructor = PropertyDescriptor::builder() diff --git a/boa/src/environment/declarative_environment_record.rs b/boa/src/environment/declarative_environment_record.rs index 242c93f238f..e8337de5120 100644 --- a/boa/src/environment/declarative_environment_record.rs +++ b/boa/src/environment/declarative_environment_record.rs @@ -11,7 +11,7 @@ use crate::{ lexical_environment::{Environment, EnvironmentType}, }, gc::{Finalize, Trace}, - object::GcObject, + object::JsObject, BoaProfiler, Context, JsResult, JsValue, }; use gc::{Gc, GcCell}; @@ -207,7 +207,7 @@ impl EnvironmentRecordTrait for DeclarativeEnvironmentRecord { false } - fn with_base_object(&self) -> Option { + fn with_base_object(&self) -> Option { None } diff --git a/boa/src/environment/environment_record_trait.rs b/boa/src/environment/environment_record_trait.rs index 485baa38613..7c0e788cbce 100644 --- a/boa/src/environment/environment_record_trait.rs +++ b/boa/src/environment/environment_record_trait.rs @@ -9,7 +9,7 @@ //! There are 5 Environment record kinds. They all have methods in common, these are implemented as a the `EnvironmentRecordTrait` //! -use crate::{environment::lexical_environment::VariableScope, object::GcObject}; +use crate::{environment::lexical_environment::VariableScope, object::JsObject}; use crate::{ environment::lexical_environment::{Environment, EnvironmentType}, gc::{Finalize, Trace}, @@ -100,7 +100,7 @@ pub trait EnvironmentRecordTrait: Debug + Trace + Finalize { /// If this Environment Record is associated with a with statement, return the with object. /// Otherwise, return None. - fn with_base_object(&self) -> Option; + fn with_base_object(&self) -> Option; /// Get the next environment up fn get_outer_environment_ref(&self) -> Option<&Environment>; diff --git a/boa/src/environment/function_environment_record.rs b/boa/src/environment/function_environment_record.rs index 1ef0797ac8f..c37d0691ec2 100644 --- a/boa/src/environment/function_environment_record.rs +++ b/boa/src/environment/function_environment_record.rs @@ -17,7 +17,7 @@ use crate::{ lexical_environment::{Environment, EnvironmentType, VariableScope}, }, gc::{empty_trace, Finalize, Trace}, - object::GcObject, + object::JsObject, Context, JsResult, JsValue, }; @@ -46,7 +46,7 @@ pub struct FunctionEnvironmentRecord { /// If the value is "lexical", this is an ArrowFunction and does not have a local this value. pub this_binding_status: BindingStatus, /// The function object whose invocation caused this Environment Record to be created. - pub function: GcObject, + pub function: JsObject, /// If the associated function has super property accesses and is not an ArrowFunction, /// `[[HomeObject]]` is the object that the function is bound to as a method. /// The default value for `[[HomeObject]]` is undefined. @@ -59,7 +59,7 @@ pub struct FunctionEnvironmentRecord { impl FunctionEnvironmentRecord { pub fn new( - f: GcObject, + f: JsObject, this: Option, outer: Option, binding_status: BindingStatus, @@ -197,7 +197,7 @@ impl EnvironmentRecordTrait for FunctionEnvironmentRecord { } } - fn with_base_object(&self) -> Option { + fn with_base_object(&self) -> Option { None } diff --git a/boa/src/environment/global_environment_record.rs b/boa/src/environment/global_environment_record.rs index 524293db8d1..f3908110788 100644 --- a/boa/src/environment/global_environment_record.rs +++ b/boa/src/environment/global_environment_record.rs @@ -15,7 +15,7 @@ use crate::{ object_environment_record::ObjectEnvironmentRecord, }, gc::{Finalize, Trace}, - object::GcObject, + object::JsObject, property::PropertyDescriptor, Context, JsResult, JsValue, }; @@ -25,13 +25,13 @@ use rustc_hash::FxHashSet; #[derive(Debug, Trace, Finalize, Clone)] pub struct GlobalEnvironmentRecord { pub object_record: ObjectEnvironmentRecord, - pub global_this_binding: GcObject, + pub global_this_binding: JsObject, pub declarative_record: DeclarativeEnvironmentRecord, pub var_names: GcCell>>, } impl GlobalEnvironmentRecord { - pub fn new(global: GcObject, this_value: GcObject) -> GlobalEnvironmentRecord { + pub fn new(global: JsObject, this_value: JsObject) -> GlobalEnvironmentRecord { let obj_rec = ObjectEnvironmentRecord { bindings: global.into(), outer_env: None, @@ -264,7 +264,7 @@ impl EnvironmentRecordTrait for GlobalEnvironmentRecord { false } - fn with_base_object(&self) -> Option { + fn with_base_object(&self) -> Option { None } diff --git a/boa/src/environment/lexical_environment.rs b/boa/src/environment/lexical_environment.rs index c690abf0003..69aa271ff87 100644 --- a/boa/src/environment/lexical_environment.rs +++ b/boa/src/environment/lexical_environment.rs @@ -7,7 +7,7 @@ use super::global_environment_record::GlobalEnvironmentRecord; use crate::{ - environment::environment_record_trait::EnvironmentRecordTrait, object::GcObject, BoaProfiler, + environment::environment_record_trait::EnvironmentRecordTrait, object::JsObject, BoaProfiler, Context, JsResult, JsValue, }; use gc::Gc; @@ -63,7 +63,7 @@ impl fmt::Display for EnvironmentError { impl error::Error for EnvironmentError {} impl LexicalEnvironment { - pub fn new(global: GcObject) -> Self { + pub fn new(global: JsObject) -> Self { let _timer = BoaProfiler::global().start_event("LexicalEnvironment::new", "env"); let global_env = GlobalEnvironmentRecord::new(global.clone(), global); let mut lexical_env = Self { diff --git a/boa/src/environment/object_environment_record.rs b/boa/src/environment/object_environment_record.rs index 2c8e40016c4..99be2a51218 100644 --- a/boa/src/environment/object_environment_record.rs +++ b/boa/src/environment/object_environment_record.rs @@ -14,7 +14,7 @@ use crate::{ lexical_environment::{Environment, EnvironmentType}, }, gc::{Finalize, Trace}, - object::GcObject, + object::JsObject, property::PropertyDescriptor, Context, JsResult, JsValue, }; @@ -153,7 +153,7 @@ impl EnvironmentRecordTrait for ObjectEnvironmentRecord { false } - fn with_base_object(&self) -> Option { + fn with_base_object(&self) -> Option { // Object Environment Records return undefined as their // WithBaseObject unless their withEnvironment flag is true. if self.with_environment { diff --git a/boa/src/lib.rs b/boa/src/lib.rs index df08df78726..4027828702e 100644 --- a/boa/src/lib.rs +++ b/boa/src/lib.rs @@ -64,7 +64,7 @@ pub mod vm; /// A convenience module that re-exports the most commonly-used Boa APIs pub mod prelude { - pub use crate::{object::GcObject as JsObject, Context, JsBigInt, JsResult, JsString, JsValue}; + pub use crate::{object::JsObject, Context, JsBigInt, JsResult, JsString, JsValue}; } use std::result::Result as StdResult; diff --git a/boa/src/object/gcobject.rs b/boa/src/object/gcobject.rs index 195e4279038..ffef7c9035e 100644 --- a/boa/src/object/gcobject.rs +++ b/boa/src/object/gcobject.rs @@ -1,6 +1,6 @@ -//! This module implements the `GcObject` structure. +//! This module implements the `JsObject` structure. //! -//! The `GcObject` is a garbage collected Object. +//! The `JsObject` is a garbage collected Object. use super::{NativeObject, Object, PROTOTYPE}; use crate::{ @@ -38,7 +38,7 @@ pub type RefMut<'a, T, U> = GcCellRefMut<'a, T, U>; /// Garbage collected `Object`. #[derive(Trace, Finalize, Clone, Default)] -pub struct GcObject(Gc>); +pub struct JsObject(Gc>); /// The body of a JavaScript function. /// @@ -51,8 +51,8 @@ enum FunctionBody { Ordinary(RcStatementList), } -impl GcObject { - /// Create a new `GcObject` from a `Object`. +impl JsObject { + /// Create a new `JsObject` from a `Object`. #[inline] pub fn new(object: Object) -> Self { Self(Gc::new(GcCell::new(object))) @@ -395,7 +395,7 @@ impl GcObject { hint: PreferredType, ) -> JsResult { // 1. Assert: Type(O) is Object. - // Already is GcObject by type. + // Already is JsObject by type. // 2. Assert: Type(hint) is String and its value is either "string" or "number". debug_assert!(hint == PreferredType::String || hint == PreferredType::Number); @@ -709,7 +709,7 @@ impl GcObject { /// /// [spec]: https://tc39.es/ecma262/#sec-getmethod #[inline] - pub fn get_method(&self, context: &mut Context, key: K) -> JsResult> + pub fn get_method(&self, context: &mut Context, key: K) -> JsResult> where K: Into, { @@ -763,7 +763,7 @@ impl GcObject { let mut object = object.__get_prototype_of__(); while let Some(object_prototype) = object.as_object() { // c. If SameValue(P, O) is true, return true. - if GcObject::equals(&prototype, &object_prototype) { + if JsObject::equals(&prototype, &object_prototype) { return Ok(true); } // a. Set O to ? O.[[GetPrototypeOf]](). @@ -994,14 +994,14 @@ impl GcObject { } } -impl AsRef> for GcObject { +impl AsRef> for JsObject { #[inline] fn as_ref(&self) -> &GcCell { &*self.0 } } -/// An error returned by [`GcObject::try_borrow`](struct.GcObject.html#method.try_borrow). +/// An error returned by [`JsObject::try_borrow`](struct.JsObject.html#method.try_borrow). #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct BorrowError; @@ -1014,7 +1014,7 @@ impl Display for BorrowError { impl Error for BorrowError {} -/// An error returned by [`GcObject::try_borrow_mut`](struct.GcObject.html#method.try_borrow_mut). +/// An error returned by [`JsObject::try_borrow_mut`](struct.JsObject.html#method.try_borrow_mut). #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct BorrowMutError; @@ -1036,8 +1036,8 @@ enum RecursionValueState { /// ```javascript /// let b = []; /// JSON.stringify([ // Create a recursion limiter for the root here - /// b, // state for b's &GcObject here is None - /// b, // state for b's &GcObject here is Visited + /// b, // state for b's &JsObject here is None + /// b, // state for b's &JsObject here is Visited /// ]); /// ``` Visited, @@ -1048,13 +1048,13 @@ enum RecursionValueState { /// multiple threads! #[derive(Debug)] pub struct RecursionLimiter { - /// If this was the first `GcObject` in the tree. + /// If this was the first `JsObject` in the tree. top_level: bool, /// The ptr being kept in the HashSet, so we can delete it when we drop. ptr: usize, - /// If this GcObject has been visited before in the graph, but not in the current branch. + /// If this JsObject has been visited before in the graph, but not in the current branch. pub visited: bool, - /// If this GcObject has been visited in the current branch of the graph. + /// If this JsObject has been visited in the current branch of the graph. pub live: bool, } @@ -1075,17 +1075,17 @@ impl Drop for RecursionLimiter { impl RecursionLimiter { thread_local! { - /// The map of pointers to `GcObject` that have been visited during the current `Debug::fmt` graph, + /// The map of pointers to `JsObject` that have been visited during the current `Debug::fmt` graph, /// and the current state of their RecursionLimiter (dropped or live -- see `RecursionValueState`) static SEEN: RefCell> = RefCell::new(HashMap::new()); } - /// Determines if the specified `GcObject` has been visited, and returns a struct that will free it when dropped. + /// Determines if the specified `JsObject` has been visited, and returns a struct that will free it when dropped. /// - /// This is done by maintaining a thread-local hashset containing the pointers of `GcObject` values that have been - /// visited. The first `GcObject` visited will clear the hashset, while any others will check if they are contained + /// This is done by maintaining a thread-local hashset containing the pointers of `JsObject` values that have been + /// visited. The first `JsObject` visited will clear the hashset, while any others will check if they are contained /// by the hashset. - pub fn new(o: &GcObject) -> Self { + pub fn new(o: &JsObject) -> Self { // We shouldn't have to worry too much about this being moved during Debug::fmt. let ptr = (o.as_ref() as *const _) as usize; let (top_level, visited, live) = Self::SEEN.with(|hm| { @@ -1109,7 +1109,7 @@ impl RecursionLimiter { } } -impl Debug for GcObject { +impl Debug for JsObject { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result { let limiter = RecursionLimiter::new(self); @@ -1120,7 +1120,7 @@ impl Debug for GcObject { // Instead, we check if the object has appeared before in the entire graph. This means that objects will appear // at most once, hopefully making things a bit clearer. if !limiter.visited && !limiter.live { - f.debug_tuple("GcObject").field(&self.0).finish() + f.debug_tuple("JsObject").field(&self.0).finish() } else { f.write_str("{ ... }") } diff --git a/boa/src/object/internal_methods.rs b/boa/src/object/internal_methods.rs index 420c26ab35f..6cd13490a7d 100644 --- a/boa/src/object/internal_methods.rs +++ b/boa/src/object/internal_methods.rs @@ -7,13 +7,13 @@ use crate::{ builtins::Array, - object::{GcObject, Object, ObjectData}, + object::{JsObject, Object, ObjectData}, property::{DescriptorKind, PropertyDescriptor, PropertyKey, PropertyNameKind}, value::{JsValue, Type}, BoaProfiler, Context, JsResult, }; -impl GcObject { +impl JsObject { /// Check if object has property. /// /// More information: @@ -822,7 +822,7 @@ impl GcObject { self.borrow().is_constructable() } - /// Returns true if the GcObject is the global for a Realm + /// Returns true if the JsObject is the global for a Realm pub fn is_global(&self) -> bool { matches!(self.borrow().data, ObjectData::Global) } diff --git a/boa/src/object/mod.rs b/boa/src/object/mod.rs index ce1f61c15a9..d6f58ec6646 100644 --- a/boa/src/object/mod.rs +++ b/boa/src/object/mod.rs @@ -32,7 +32,7 @@ mod internal_methods; mod property_map; use crate::builtins::object::for_in_iterator::ForInIterator; -pub use gcobject::{GcObject, RecursionLimiter, Ref, RefMut}; +pub use gcobject::{JsObject, RecursionLimiter, Ref, RefMut}; pub use property_map::*; /// Static `prototype`, usually set on constructors as a key to point to their respective prototype object. @@ -748,7 +748,7 @@ impl<'context> FunctionBuilder<'context> { /// Build the function object. #[inline] - pub fn build(&mut self) -> GcObject { + pub fn build(&mut self) -> JsObject { let mut function = Object::function( self.function.take().unwrap(), self.context @@ -764,11 +764,11 @@ impl<'context> FunctionBuilder<'context> { function.insert_property("name", property.clone().value(self.name.clone())); function.insert_property("length", property.value(self.length)); - GcObject::new(function) + JsObject::new(function) } /// Initializes the `Function.prototype` function object. - pub(crate) fn build_function_prototype(&mut self, object: &GcObject) { + pub(crate) fn build_function_prototype(&mut self, object: &JsObject) { let mut object = object.borrow_mut(); object.data = ObjectData::Function(self.function.take().unwrap()); object.set_prototype_instance( @@ -821,7 +821,7 @@ impl<'context> FunctionBuilder<'context> { #[derive(Debug)] pub struct ObjectInitializer<'context> { context: &'context mut Context, - object: GcObject, + object: JsObject, } impl<'context> ObjectInitializer<'context> { @@ -874,7 +874,7 @@ impl<'context> ObjectInitializer<'context> { /// Build the object. #[inline] - pub fn build(&mut self) -> GcObject { + pub fn build(&mut self) -> JsObject { self.object.clone() } } @@ -883,8 +883,8 @@ impl<'context> ObjectInitializer<'context> { pub struct ConstructorBuilder<'context> { context: &'context mut Context, constructor_function: NativeFunction, - constructor_object: GcObject, - prototype: GcObject, + constructor_object: JsObject, + prototype: JsObject, name: JsString, length: usize, callable: bool, @@ -913,8 +913,8 @@ impl<'context> ConstructorBuilder<'context> { Self { context, constructor_function: constructor, - constructor_object: GcObject::new(Object::default()), - prototype: GcObject::new(Object::default()), + constructor_object: JsObject::new(Object::default()), + prototype: JsObject::new(Object::default()), length: 0, name: JsString::default(), callable: true, @@ -1032,8 +1032,8 @@ impl<'context> ConstructorBuilder<'context> { pub fn accessor( &mut self, key: K, - get: Option, - set: Option, + get: Option, + set: Option, attribute: Attribute, ) -> &mut Self where @@ -1053,8 +1053,8 @@ impl<'context> ConstructorBuilder<'context> { pub fn static_accessor( &mut self, key: K, - get: Option, - set: Option, + get: Option, + set: Option, attribute: Attribute, ) -> &mut Self where @@ -1149,7 +1149,7 @@ impl<'context> ConstructorBuilder<'context> { } /// Build the constructor function object. - pub fn build(&mut self) -> GcObject { + pub fn build(&mut self) -> JsObject { // Create the native function let function = Function::Native { function: self.constructor_function.into(), diff --git a/boa/src/realm.rs b/boa/src/realm.rs index 4911858b611..e6ef3f7e026 100644 --- a/boa/src/realm.rs +++ b/boa/src/realm.rs @@ -8,7 +8,7 @@ use crate::{ environment::{ global_environment_record::GlobalEnvironmentRecord, lexical_environment::LexicalEnvironment, }, - object::{GcObject, Object, ObjectData}, + object::{JsObject, Object, ObjectData}, BoaProfiler, }; use gc::Gc; @@ -18,7 +18,7 @@ use gc::Gc; /// In the specification these are called Realm Records. #[derive(Debug)] pub struct Realm { - pub global_object: GcObject, + pub global_object: JsObject, pub global_env: Gc, pub environment: LexicalEnvironment, } @@ -34,7 +34,7 @@ impl Realm { // Allow identification of the global object easily global.data = ObjectData::Global; - let gc_global = GcObject::new(global); + let gc_global = JsObject::new(global); // We need to clone the global here because its referenced from separate places (only pointer is cloned) let global_env = GlobalEnvironmentRecord::new(gc_global.clone(), gc_global.clone()); diff --git a/boa/src/value/conversions.rs b/boa/src/value/conversions.rs index 4ef9ffd3c63..be1c97e44e2 100644 --- a/boa/src/value/conversions.rs +++ b/boa/src/value/conversions.rs @@ -164,14 +164,14 @@ impl From for JsValue { #[inline] fn from(object: Object) -> Self { let _timer = BoaProfiler::global().start_event("From", "value"); - JsValue::Object(GcObject::new(object)) + JsValue::Object(JsObject::new(object)) } } -impl From for JsValue { +impl From for JsValue { #[inline] - fn from(object: GcObject) -> Self { - let _timer = BoaProfiler::global().start_event("From", "value"); + fn from(object: JsObject) -> Self { + let _timer = BoaProfiler::global().start_event("From", "value"); JsValue::Object(object) } } diff --git a/boa/src/value/equality.rs b/boa/src/value/equality.rs index a31337a9fbb..89ef68fbc20 100644 --- a/boa/src/value/equality.rs +++ b/boa/src/value/equality.rs @@ -178,7 +178,7 @@ impl JsValue { (JsValue::Null, JsValue::Null) | (JsValue::Undefined, JsValue::Undefined) => true, (JsValue::String(ref x), JsValue::String(ref y)) => x == y, (JsValue::Boolean(x), JsValue::Boolean(y)) => x == y, - (JsValue::Object(ref x), JsValue::Object(ref y)) => GcObject::equals(x, y), + (JsValue::Object(ref x), JsValue::Object(ref y)) => JsObject::equals(x, y), (JsValue::Symbol(ref x), JsValue::Symbol(ref y)) => x == y, _ => false, } diff --git a/boa/src/value/mod.rs b/boa/src/value/mod.rs index 89a97900f68..cb70a598a51 100644 --- a/boa/src/value/mod.rs +++ b/boa/src/value/mod.rs @@ -11,7 +11,7 @@ use crate::{ string::is_trimmable_whitespace, Number, }, - object::{GcObject, Object, ObjectData}, + object::{JsObject, Object, ObjectData}, property::{PropertyDescriptor, PropertyKey}, symbol::{JsSymbol, WellKnownSymbols}, BoaProfiler, Context, JsBigInt, JsResult, JsString, @@ -57,7 +57,7 @@ pub enum JsValue { /// `BigInt` - holds any arbitrary large signed integer. BigInt(JsBigInt), /// `Object` - An object, such as `Math`, represented by a binary tree of string keys to Javascript values. - Object(GcObject), + Object(JsObject), /// `Symbol` - A Symbol Primitive type. Symbol(JsSymbol), } @@ -228,7 +228,7 @@ impl JsValue { } #[inline] - pub fn as_object(&self) -> Option { + pub fn as_object(&self) -> Option { match *self { Self::Object(ref o) => Some(o.clone()), _ => None, @@ -623,28 +623,28 @@ impl JsValue { /// This function is equivalent to `Object(value)` in JavaScript /// /// See: - pub fn to_object(&self, context: &mut Context) -> JsResult { + pub fn to_object(&self, context: &mut Context) -> JsResult { match self { JsValue::Undefined | JsValue::Null => { Err(context.construct_type_error("cannot convert 'null' or 'undefined' to object")) } JsValue::Boolean(boolean) => { let prototype = context.standard_objects().boolean_object().prototype(); - Ok(GcObject::new(Object::with_prototype( + Ok(JsObject::new(Object::with_prototype( prototype.into(), ObjectData::Boolean(*boolean), ))) } JsValue::Integer(integer) => { let prototype = context.standard_objects().number_object().prototype(); - Ok(GcObject::new(Object::with_prototype( + Ok(JsObject::new(Object::with_prototype( prototype.into(), ObjectData::Number(f64::from(*integer)), ))) } JsValue::Rational(rational) => { let prototype = context.standard_objects().number_object().prototype(); - Ok(GcObject::new(Object::with_prototype( + Ok(JsObject::new(Object::with_prototype( prototype.into(), ObjectData::Number(*rational), ))) @@ -652,7 +652,7 @@ impl JsValue { JsValue::String(ref string) => { let prototype = context.standard_objects().string_object().prototype(); - let object = GcObject::new(Object::with_prototype( + let object = JsObject::new(Object::with_prototype( prototype.into(), ObjectData::String(string.clone()), )); @@ -669,19 +669,19 @@ impl JsValue { } JsValue::Symbol(ref symbol) => { let prototype = context.standard_objects().symbol_object().prototype(); - Ok(GcObject::new(Object::with_prototype( + Ok(JsObject::new(Object::with_prototype( prototype.into(), ObjectData::Symbol(symbol.clone()), ))) } JsValue::BigInt(ref bigint) => { let prototype = context.standard_objects().bigint_object().prototype(); - Ok(GcObject::new(Object::with_prototype( + Ok(JsObject::new(Object::with_prototype( prototype.into(), ObjectData::BigInt(bigint.clone()), ))) } - JsValue::Object(gcobject) => Ok(gcobject.clone()), + JsValue::Object(jsobject) => Ok(jsobject.clone()), } } diff --git a/boa/src/value/tests.rs b/boa/src/value/tests.rs index ee44ffcd9ba..fc692a9ab28 100644 --- a/boa/src/value/tests.rs +++ b/boa/src/value/tests.rs @@ -618,8 +618,8 @@ fn to_primitive() { } /// Test cyclic conversions that previously caused stack overflows -/// Relevant mitigations for these are in `GcObject::ordinary_to_primitive` and -/// `GcObject::to_json` +/// Relevant mitigations for these are in `JsObject::ordinary_to_primitive` and +/// `JsObject::to_json` mod cyclic_conversions { use super::*; diff --git a/boa_tester/src/exec/js262.rs b/boa_tester/src/exec/js262.rs index 53c9e14def7..d7d90e050cb 100644 --- a/boa_tester/src/exec/js262.rs +++ b/boa_tester/src/exec/js262.rs @@ -1,12 +1,12 @@ use boa::{ exec::Executable, - object::{GcObject, ObjectInitializer}, + object::{JsObject, ObjectInitializer}, property::Attribute, Context, JsResult, JsValue, }; /// Initializes the object in the context. -pub(super) fn init(context: &mut Context) -> GcObject { +pub(super) fn init(context: &mut Context) -> JsObject { let global_obj = context.global_object(); let obj = ObjectInitializer::new(context)