Browse Source

Rename `GcObject` to `JsObject` (#1489)

* Rename `GcObject` to `JsObject`

* fmt
pull/1495/head
Bartek Iwańczuk 3 years ago committed by GitHub
parent
commit
26e149795a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      boa/src/builtins/array/array_iterator.rs
  2. 26
      boa/src/builtins/array/mod.rs
  3. 6
      boa/src/builtins/function/mod.rs
  4. 32
      boa/src/builtins/iterable/mod.rs
  5. 4
      boa/src/builtins/map/map_iterator.rs
  6. 6
      boa/src/builtins/map/ordered_map.rs
  7. 4
      boa/src/builtins/object/for_in_iterator.rs
  8. 12
      boa/src/builtins/regexp/mod.rs
  9. 4
      boa/src/builtins/regexp/regexp_string_iterator.rs
  10. 4
      boa/src/builtins/set/set_iterator.rs
  11. 4
      boa/src/builtins/string/string_iterator.rs
  12. 12
      boa/src/class.rs
  13. 26
      boa/src/context.rs
  14. 4
      boa/src/environment/declarative_environment_record.rs
  15. 4
      boa/src/environment/environment_record_trait.rs
  16. 8
      boa/src/environment/function_environment_record.rs
  17. 8
      boa/src/environment/global_environment_record.rs
  18. 4
      boa/src/environment/lexical_environment.rs
  19. 4
      boa/src/environment/object_environment_record.rs
  20. 2
      boa/src/lib.rs
  21. 46
      boa/src/object/gcobject.rs
  22. 6
      boa/src/object/internal_methods.rs
  23. 30
      boa/src/object/mod.rs
  24. 6
      boa/src/realm.rs
  25. 8
      boa/src/value/conversions.rs
  26. 2
      boa/src/value/equality.rs
  27. 22
      boa/src/value/mod.rs
  28. 4
      boa/src/value/tests.rs
  29. 4
      boa_tester/src/exec/js262.rs

4
boa/src/builtins/array/array_iterator.rs

@ -1,7 +1,7 @@
use crate::{ use crate::{
builtins::{function::make_builtin_fn, iterable::create_iter_result_object, Array, JsValue}, builtins::{function::make_builtin_fn, iterable::create_iter_result_object, Array, JsValue},
gc::{Finalize, Trace}, gc::{Finalize, Trace},
object::{GcObject, ObjectData}, object::{JsObject, ObjectData},
property::{PropertyDescriptor, PropertyNameKind}, property::{PropertyDescriptor, PropertyNameKind},
symbol::WellKnownSymbols, symbol::WellKnownSymbols,
BoaProfiler, Context, JsResult, BoaProfiler, Context, JsResult,
@ -117,7 +117,7 @@ impl ArrayIterator {
/// - [ECMA reference][spec] /// - [ECMA reference][spec]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-%arrayiteratorprototype%-object /// [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"); let _timer = BoaProfiler::global().start_event(Self::NAME, "init");
// Create prototype // Create prototype

26
boa/src/builtins/array/mod.rs

@ -17,7 +17,7 @@ use crate::{
builtins::array::array_iterator::ArrayIterator, builtins::array::array_iterator::ArrayIterator,
builtins::BuiltIn, builtins::BuiltIn,
builtins::Number, builtins::Number,
object::{ConstructorBuilder, FunctionBuilder, GcObject, ObjectData, PROTOTYPE}, object::{ConstructorBuilder, FunctionBuilder, JsObject, ObjectData, PROTOTYPE},
property::{Attribute, PropertyDescriptor, PropertyNameKind}, property::{Attribute, PropertyDescriptor, PropertyNameKind},
symbol::WellKnownSymbols, symbol::WellKnownSymbols,
value::{IntegerOrInfinity, JsValue}, value::{IntegerOrInfinity, JsValue},
@ -206,9 +206,9 @@ impl Array {
/// [spec]: https://tc39.es/ecma262/#sec-arraycreate /// [spec]: https://tc39.es/ecma262/#sec-arraycreate
pub(crate) fn array_create( pub(crate) fn array_create(
length: usize, length: usize,
prototype: Option<GcObject>, prototype: Option<JsObject>,
context: &mut Context, context: &mut Context,
) -> JsResult<GcObject> { ) -> JsResult<JsObject> {
// 1. If length > 2^32 - 1, throw a RangeError exception. // 1. If length > 2^32 - 1, throw a RangeError exception.
if length > 2usize.pow(32) - 1 { if length > 2usize.pow(32) - 1 {
return Err(context.construct_range_error("array exceeded max size")); return Err(context.construct_range_error("array exceeded max size"));
@ -250,7 +250,7 @@ impl Array {
/// - [ECMAScript reference][spec] /// - [ECMAScript reference][spec]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-createarrayfromlist /// [spec]: https://tc39.es/ecma262/#sec-createarrayfromlist
pub(crate) fn create_array_from_list<I>(elements: I, context: &mut Context) -> GcObject pub(crate) fn create_array_from_list<I>(elements: I, context: &mut Context) -> JsObject
where where
I: IntoIterator<Item = JsValue>, I: IntoIterator<Item = JsValue>,
{ {
@ -335,10 +335,10 @@ impl Array {
/// ///
/// see: <https://tc39.es/ecma262/#sec-arrayspeciescreate> /// see: <https://tc39.es/ecma262/#sec-arrayspeciescreate>
pub(crate) fn array_species_create( pub(crate) fn array_species_create(
original_array: &GcObject, original_array: &JsObject,
length: usize, length: usize,
context: &mut Context, context: &mut Context,
) -> JsResult<GcObject> { ) -> JsResult<JsObject> {
// 1. Let isArray be ? IsArray(originalArray). // 1. Let isArray be ? IsArray(originalArray).
// 2. If isArray is false, return ? ArrayCreate(length). // 2. If isArray is false, return ? ArrayCreate(length).
if !original_array.is_array() { if !original_array.is_array() {
@ -667,7 +667,7 @@ impl Array {
let callback = if let Some(arg) = args let callback = if let Some(arg) = args
.get(0) .get(0)
.and_then(JsValue::as_object) .and_then(JsValue::as_object)
.filter(GcObject::is_callable) .filter(JsObject::is_callable)
{ {
arg arg
} else { } else {
@ -772,7 +772,7 @@ impl Array {
let func = array.get("join", context)?; let func = array.get("join", context)?;
// 3. If IsCallable(func) is false, set func to the intrinsic function %Object.prototype.toString%. // 3. If IsCallable(func) is false, set func to the intrinsic function %Object.prototype.toString%.
// 4. Return ? Call(func, array). // 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) func.call(&array.into(), &[], context)
} else { } else {
crate::builtins::object::Object::to_string(&array.into(), &[], context) crate::builtins::object::Object::to_string(&array.into(), &[], context)
@ -1013,7 +1013,7 @@ impl Array {
let callback = if let Some(arg) = args let callback = if let Some(arg) = args
.get(0) .get(0)
.and_then(JsValue::as_object) .and_then(JsValue::as_object)
.filter(GcObject::is_callable) .filter(JsObject::is_callable)
{ {
arg arg
} else { } else {
@ -1481,12 +1481,12 @@ impl Array {
/// [spec]: https://tc39.es/ecma262/#sec-flattenintoarray /// [spec]: https://tc39.es/ecma262/#sec-flattenintoarray
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn flatten_into_array( fn flatten_into_array(
target: &GcObject, target: &JsObject,
source: &GcObject, source: &JsObject,
source_len: u64, source_len: u64,
start: u64, start: u64,
depth: u64, depth: u64,
mapper_function: Option<GcObject>, mapper_function: Option<JsObject>,
this_arg: &JsValue, this_arg: &JsValue,
context: &mut Context, context: &mut Context,
) -> JsResult<u64> { ) -> JsResult<u64> {
@ -1879,7 +1879,7 @@ impl Array {
let callback = if let Some(arg) = args let callback = if let Some(arg) = args
.get(0) .get(0)
.and_then(JsValue::as_object) .and_then(JsValue::as_object)
.filter(GcObject::is_callable) .filter(JsObject::is_callable)
{ {
arg arg
} else { } else {

6
boa/src/builtins/function/mod.rs

@ -16,7 +16,7 @@ use crate::{
builtins::{Array, BuiltIn}, builtins::{Array, BuiltIn},
environment::lexical_environment::Environment, environment::lexical_environment::Environment,
gc::{custom_trace, empty_trace, Finalize, Trace}, gc::{custom_trace, empty_trace, Finalize, Trace},
object::{ConstructorBuilder, FunctionBuilder, GcObject, Object, ObjectData}, object::{ConstructorBuilder, FunctionBuilder, JsObject, Object, ObjectData},
property::{Attribute, PropertyDescriptor}, property::{Attribute, PropertyDescriptor},
syntax::ast::node::{FormalParameter, RcStatementList}, syntax::ast::node::{FormalParameter, RcStatementList},
BoaProfiler, Context, JsResult, JsValue, BoaProfiler, Context, JsResult, JsValue,
@ -179,7 +179,7 @@ impl Function {
/// <https://tc39.es/ecma262/#sec-createunmappedargumentsobject> /// <https://tc39.es/ecma262/#sec-createunmappedargumentsobject>
pub fn create_unmapped_arguments_object(arguments_list: &[JsValue]) -> JsValue { pub fn create_unmapped_arguments_object(arguments_list: &[JsValue]) -> JsValue {
let len = arguments_list.len(); let len = arguments_list.len();
let obj = GcObject::new(Object::default()); let obj = JsObject::new(Object::default());
// Set length // Set length
let length = PropertyDescriptor::builder() let length = PropertyDescriptor::builder()
.value(len) .value(len)
@ -225,7 +225,7 @@ pub fn create_unmapped_arguments_object(arguments_list: &[JsValue]) -> JsValue {
pub fn make_builtin_fn<N>( pub fn make_builtin_fn<N>(
function: NativeFunction, function: NativeFunction,
name: N, name: N,
parent: &GcObject, parent: &JsObject,
length: usize, length: usize,
interpreter: &Context, interpreter: &Context,
) where ) where

32
boa/src/builtins/iterable/mod.rs

@ -4,20 +4,20 @@ use crate::{
string::string_iterator::StringIterator, ArrayIterator, ForInIterator, MapIterator, string::string_iterator::StringIterator, ArrayIterator, ForInIterator, MapIterator,
SetIterator, SetIterator,
}, },
object::{GcObject, ObjectInitializer}, object::{JsObject, ObjectInitializer},
symbol::WellKnownSymbols, symbol::WellKnownSymbols,
BoaProfiler, Context, JsResult, JsValue, BoaProfiler, Context, JsResult, JsValue,
}; };
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct IteratorPrototypes { pub struct IteratorPrototypes {
iterator_prototype: GcObject, iterator_prototype: JsObject,
array_iterator: GcObject, array_iterator: JsObject,
set_iterator: GcObject, set_iterator: JsObject,
string_iterator: GcObject, string_iterator: JsObject,
regexp_string_iterator: GcObject, regexp_string_iterator: JsObject,
map_iterator: GcObject, map_iterator: JsObject,
for_in_iterator: GcObject, for_in_iterator: JsObject,
} }
impl IteratorPrototypes { impl IteratorPrototypes {
@ -47,37 +47,37 @@ impl IteratorPrototypes {
} }
#[inline] #[inline]
pub fn array_iterator(&self) -> GcObject { pub fn array_iterator(&self) -> JsObject {
self.array_iterator.clone() self.array_iterator.clone()
} }
#[inline] #[inline]
pub fn iterator_prototype(&self) -> GcObject { pub fn iterator_prototype(&self) -> JsObject {
self.iterator_prototype.clone() self.iterator_prototype.clone()
} }
#[inline] #[inline]
pub fn set_iterator(&self) -> GcObject { pub fn set_iterator(&self) -> JsObject {
self.set_iterator.clone() self.set_iterator.clone()
} }
#[inline] #[inline]
pub fn string_iterator(&self) -> GcObject { pub fn string_iterator(&self) -> JsObject {
self.string_iterator.clone() self.string_iterator.clone()
} }
#[inline] #[inline]
pub fn regexp_string_iterator(&self) -> GcObject { pub fn regexp_string_iterator(&self) -> JsObject {
self.regexp_string_iterator.clone() self.regexp_string_iterator.clone()
} }
#[inline] #[inline]
pub fn map_iterator(&self) -> GcObject { pub fn map_iterator(&self) -> JsObject {
self.map_iterator.clone() self.map_iterator.clone()
} }
#[inline] #[inline]
pub fn for_in_iterator(&self) -> GcObject { pub fn for_in_iterator(&self) -> JsObject {
self.for_in_iterator.clone() self.for_in_iterator.clone()
} }
} }
@ -120,7 +120,7 @@ pub fn get_iterator(context: &mut Context, iterable: JsValue) -> JsResult<Iterat
/// - [ECMA reference][spec] /// - [ECMA reference][spec]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-%iteratorprototype%-object /// [spec]: https://tc39.es/ecma262/#sec-%iteratorprototype%-object
fn create_iterator_prototype(context: &mut Context) -> GcObject { fn create_iterator_prototype(context: &mut Context) -> JsObject {
let _timer = BoaProfiler::global().start_event("Iterator Prototype", "init"); let _timer = BoaProfiler::global().start_event("Iterator Prototype", "init");
let symbol_iterator = WellKnownSymbols::iterator(); let symbol_iterator = WellKnownSymbols::iterator();

4
boa/src/builtins/map/map_iterator.rs

@ -1,6 +1,6 @@
use crate::{ use crate::{
builtins::{function::make_builtin_fn, iterable::create_iter_result_object, Array, JsValue}, builtins::{function::make_builtin_fn, iterable::create_iter_result_object, Array, JsValue},
object::{GcObject, ObjectData}, object::{JsObject, ObjectData},
property::{PropertyDescriptor, PropertyNameKind}, property::{PropertyDescriptor, PropertyNameKind},
symbol::WellKnownSymbols, symbol::WellKnownSymbols,
BoaProfiler, Context, JsResult, BoaProfiler, Context, JsResult,
@ -146,7 +146,7 @@ impl MapIterator {
/// - [ECMA reference][spec] /// - [ECMA reference][spec]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-%mapiteratorprototype%-object /// [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"); let _timer = BoaProfiler::global().start_event(Self::NAME, "init");
// Create prototype // Create prototype

6
boa/src/builtins/map/ordered_map.rs

@ -1,6 +1,6 @@
use crate::{ use crate::{
gc::{custom_trace, Finalize, Trace}, gc::{custom_trace, Finalize, Trace},
object::GcObject, object::JsObject,
JsValue, JsValue,
}; };
use indexmap::{Equivalent, IndexMap}; use indexmap::{Equivalent, IndexMap};
@ -182,7 +182,7 @@ impl<V> OrderedMap<V> {
/// Increases the lock counter and returns a lock object that will decrement the counter when dropped. /// 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. /// 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; self.lock += 1;
MapLock(map) MapLock(map)
} }
@ -199,7 +199,7 @@ impl<V> OrderedMap<V> {
/// Increases the lock count of the map for the lifetime of the guard. This should not be dropped until iteration has completed. /// 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)] #[derive(Debug, Trace)]
pub(crate) struct MapLock(GcObject); pub(crate) struct MapLock(JsObject);
impl Clone for MapLock { impl Clone for MapLock {
fn clone(&self) -> Self { fn clone(&self) -> Self {

4
boa/src/builtins/object/for_in_iterator.rs

@ -1,7 +1,7 @@
use crate::{ use crate::{
builtins::{function::make_builtin_fn, iterable::create_iter_result_object}, builtins::{function::make_builtin_fn, iterable::create_iter_result_object},
gc::{Finalize, Trace}, gc::{Finalize, Trace},
object::{GcObject, ObjectData}, object::{JsObject, ObjectData},
property::PropertyDescriptor, property::PropertyDescriptor,
property::PropertyKey, property::PropertyKey,
symbol::WellKnownSymbols, symbol::WellKnownSymbols,
@ -129,7 +129,7 @@ impl ForInIterator {
/// - [ECMA reference][spec] /// - [ECMA reference][spec]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-%foriniteratorprototype%-object /// [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"); let _timer = BoaProfiler::global().start_event(Self::NAME, "init");
// Create prototype // Create prototype

12
boa/src/builtins/regexp/mod.rs

@ -14,7 +14,7 @@ pub mod regexp_string_iterator;
use crate::{ use crate::{
builtins::{array::Array, string, BuiltIn}, builtins::{array::Array, string, BuiltIn},
gc::{empty_trace, Finalize, Trace}, gc::{empty_trace, Finalize, Trace},
object::{ConstructorBuilder, FunctionBuilder, GcObject, Object, ObjectData, PROTOTYPE}, object::{ConstructorBuilder, FunctionBuilder, JsObject, Object, ObjectData, PROTOTYPE},
property::Attribute, property::Attribute,
symbol::WellKnownSymbols, symbol::WellKnownSymbols,
value::{IntegerOrInfinity, JsValue}, value::{IntegerOrInfinity, JsValue},
@ -265,7 +265,7 @@ impl RegExp {
.into() .into()
}; };
Ok(GcObject::new(Object::create(proto)).into()) Ok(JsObject::new(Object::create(proto)).into())
} }
/// `22.2.3.2.2 RegExpInitialize ( obj, pattern, flags )` /// `22.2.3.2.2 RegExpInitialize ( obj, pattern, flags )`
@ -415,7 +415,7 @@ impl RegExp {
})); }));
} }
if GcObject::equals( if JsObject::equals(
&object, &object,
&context.standard_objects().regexp_object().prototype, &context.standard_objects().regexp_object().prototype,
) { ) {
@ -779,7 +779,7 @@ impl RegExp {
this: &JsValue, this: &JsValue,
input: JsString, input: JsString,
context: &mut Context, context: &mut Context,
) -> JsResult<Option<GcObject>> { ) -> JsResult<Option<JsObject>> {
// 1. Assert: Type(R) is Object. // 1. Assert: Type(R) is Object.
let object = this let object = this
.as_object() .as_object()
@ -821,10 +821,10 @@ impl RegExp {
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-regexpbuiltinexec /// [spec]: https://tc39.es/ecma262/#sec-regexpbuiltinexec
pub(crate) fn abstract_builtin_exec( pub(crate) fn abstract_builtin_exec(
this: GcObject, this: JsObject,
input: JsString, input: JsString,
context: &mut Context, context: &mut Context,
) -> JsResult<Option<GcObject>> { ) -> JsResult<Option<JsObject>> {
// 1. Assert: R is an initialized RegExp instance. // 1. Assert: R is an initialized RegExp instance.
let rx = { let rx = {
let obj = this.borrow(); let obj = this.borrow();

4
boa/src/builtins/regexp/regexp_string_iterator.rs

@ -14,7 +14,7 @@ use regexp::{advance_string_index, RegExp};
use crate::{ use crate::{
builtins::{function::make_builtin_fn, iterable::create_iter_result_object, regexp}, builtins::{function::make_builtin_fn, iterable::create_iter_result_object, regexp},
gc::{Finalize, Trace}, gc::{Finalize, Trace},
object::{GcObject, ObjectData}, object::{JsObject, ObjectData},
property::PropertyDescriptor, property::PropertyDescriptor,
symbol::WellKnownSymbols, symbol::WellKnownSymbols,
BoaProfiler, Context, JsResult, JsString, JsValue, BoaProfiler, Context, JsResult, JsString, JsValue,
@ -161,7 +161,7 @@ impl RegExpStringIterator {
/// - [ECMA reference][spec] /// - [ECMA reference][spec]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-%arrayiteratorprototype%-object /// [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"); let _timer = BoaProfiler::global().start_event("RegExp String Iterator", "init");
// Create prototype // Create prototype

4
boa/src/builtins/set/set_iterator.rs

@ -3,7 +3,7 @@ use crate::{
builtins::iterable::create_iter_result_object, builtins::iterable::create_iter_result_object,
builtins::Array, builtins::Array,
builtins::JsValue, builtins::JsValue,
object::{GcObject, ObjectData}, object::{JsObject, ObjectData},
property::{PropertyDescriptor, PropertyNameKind}, property::{PropertyDescriptor, PropertyNameKind},
symbol::WellKnownSymbols, symbol::WellKnownSymbols,
BoaProfiler, Context, JsResult, BoaProfiler, Context, JsResult,
@ -141,7 +141,7 @@ impl SetIterator {
/// - [ECMA reference][spec] /// - [ECMA reference][spec]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-%setiteratorprototype%-object /// [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"); let _timer = BoaProfiler::global().start_event(Self::NAME, "init");
// Create prototype // Create prototype

4
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, function::make_builtin_fn, iterable::create_iter_result_object, string::code_point_at,
}, },
gc::{Finalize, Trace}, gc::{Finalize, Trace},
object::{GcObject, ObjectData}, object::{JsObject, ObjectData},
property::PropertyDescriptor, property::PropertyDescriptor,
symbol::WellKnownSymbols, symbol::WellKnownSymbols,
BoaProfiler, Context, JsResult, JsValue, BoaProfiler, Context, JsResult, JsValue,
@ -78,7 +78,7 @@ impl StringIterator {
/// - [ECMA reference][spec] /// - [ECMA reference][spec]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-%arrayiteratorprototype%-object /// [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"); let _timer = BoaProfiler::global().start_event("String Iterator", "init");
// Create prototype // Create prototype

12
boa/src/class.rs

@ -62,7 +62,7 @@
use crate::{ use crate::{
builtins::function::NativeFunction, builtins::function::NativeFunction,
object::{ConstructorBuilder, GcObject, NativeObject, ObjectData, PROTOTYPE}, object::{ConstructorBuilder, JsObject, NativeObject, ObjectData, PROTOTYPE},
property::{Attribute, PropertyDescriptor, PropertyKey}, property::{Attribute, PropertyDescriptor, PropertyKey},
Context, JsResult, JsValue, Context, JsResult, JsValue,
}; };
@ -165,7 +165,7 @@ impl<'context> ClassBuilder<'context> {
} }
#[inline] #[inline]
pub(crate) fn build(mut self) -> GcObject { pub(crate) fn build(mut self) -> JsObject {
self.builder.build() self.builder.build()
} }
@ -231,8 +231,8 @@ impl<'context> ClassBuilder<'context> {
pub fn accessor<K>( pub fn accessor<K>(
&mut self, &mut self,
key: K, key: K,
get: Option<GcObject>, get: Option<JsObject>,
set: Option<GcObject>, set: Option<JsObject>,
attribute: Attribute, attribute: Attribute,
) -> &mut Self ) -> &mut Self
where where
@ -249,8 +249,8 @@ impl<'context> ClassBuilder<'context> {
pub fn static_accessor<K>( pub fn static_accessor<K>(
&mut self, &mut self,
key: K, key: K,
get: Option<GcObject>, get: Option<JsObject>,
set: Option<GcObject>, set: Option<JsObject>,
attribute: Attribute, attribute: Attribute,
) -> &mut Self ) -> &mut Self
where where

26
boa/src/context.rs

@ -8,7 +8,7 @@ use crate::{
}, },
class::{Class, ClassBuilder}, class::{Class, ClassBuilder},
exec::Interpreter, exec::Interpreter,
object::{FunctionBuilder, GcObject, Object, PROTOTYPE}, object::{FunctionBuilder, JsObject, Object, PROTOTYPE},
property::{Attribute, PropertyDescriptor, PropertyKey}, property::{Attribute, PropertyDescriptor, PropertyKey},
realm::Realm, realm::Realm,
syntax::{ syntax::{
@ -33,15 +33,15 @@ use crate::vm::Vm;
/// Store a builtin constructor (such as `Object`) and its corresponding prototype. /// Store a builtin constructor (such as `Object`) and its corresponding prototype.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct StandardConstructor { pub struct StandardConstructor {
pub(crate) constructor: GcObject, pub(crate) constructor: JsObject,
pub(crate) prototype: GcObject, pub(crate) prototype: JsObject,
} }
impl Default for StandardConstructor { impl Default for StandardConstructor {
fn default() -> Self { fn default() -> Self {
Self { Self {
constructor: GcObject::new(Object::default()), constructor: JsObject::new(Object::default()),
prototype: GcObject::new(Object::default()), prototype: JsObject::new(Object::default()),
} }
} }
} }
@ -50,8 +50,8 @@ impl StandardConstructor {
/// Build a constructor with a defined prototype. /// Build a constructor with a defined prototype.
fn with_prototype(prototype: Object) -> Self { fn with_prototype(prototype: Object) -> Self {
Self { Self {
constructor: GcObject::new(Object::default()), constructor: JsObject::new(Object::default()),
prototype: GcObject::new(prototype), prototype: JsObject::new(prototype),
} }
} }
@ -59,7 +59,7 @@ impl StandardConstructor {
/// ///
/// This is the same as `Object`, `Array`, etc. /// This is the same as `Object`, `Array`, etc.
#[inline] #[inline]
pub fn constructor(&self) -> GcObject { pub fn constructor(&self) -> JsObject {
self.constructor.clone() self.constructor.clone()
} }
@ -67,7 +67,7 @@ impl StandardConstructor {
/// ///
/// This is the same as `Object.prototype`, `Array.prototype`, etc /// This is the same as `Object.prototype`, `Array.prototype`, etc
#[inline] #[inline]
pub fn prototype(&self) -> GcObject { pub fn prototype(&self) -> JsObject {
self.prototype.clone() self.prototype.clone()
} }
} }
@ -333,9 +333,9 @@ impl Context {
/// Construct an empty object. /// Construct an empty object.
#[inline] #[inline]
pub fn construct_object(&self) -> GcObject { pub fn construct_object(&self) -> JsObject {
let object_prototype: JsValue = self.standard_objects().object_object().prototype().into(); let object_prototype: JsValue = self.standard_objects().object_object().prototype().into();
GcObject::new(Object::create(object_prototype)) JsObject::new(Object::create(object_prototype))
} }
/// <https://tc39.es/ecma262/#sec-call> /// <https://tc39.es/ecma262/#sec-call>
@ -354,7 +354,7 @@ impl Context {
/// Return the global object. /// Return the global object.
#[inline] #[inline]
pub fn global_object(&self) -> GcObject { pub fn global_object(&self) -> JsObject {
self.realm.global_object.clone() self.realm.global_object.clone()
} }
@ -547,7 +547,7 @@ impl Context {
environment: self.get_current_environment().clone(), 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) // Set constructor field to the newly created Value (function object)
let constructor = PropertyDescriptor::builder() let constructor = PropertyDescriptor::builder()

4
boa/src/environment/declarative_environment_record.rs

@ -11,7 +11,7 @@ use crate::{
lexical_environment::{Environment, EnvironmentType}, lexical_environment::{Environment, EnvironmentType},
}, },
gc::{Finalize, Trace}, gc::{Finalize, Trace},
object::GcObject, object::JsObject,
BoaProfiler, Context, JsResult, JsValue, BoaProfiler, Context, JsResult, JsValue,
}; };
use gc::{Gc, GcCell}; use gc::{Gc, GcCell};
@ -207,7 +207,7 @@ impl EnvironmentRecordTrait for DeclarativeEnvironmentRecord {
false false
} }
fn with_base_object(&self) -> Option<GcObject> { fn with_base_object(&self) -> Option<JsObject> {
None None
} }

4
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` //! 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::{ use crate::{
environment::lexical_environment::{Environment, EnvironmentType}, environment::lexical_environment::{Environment, EnvironmentType},
gc::{Finalize, Trace}, 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. /// If this Environment Record is associated with a with statement, return the with object.
/// Otherwise, return None. /// Otherwise, return None.
fn with_base_object(&self) -> Option<GcObject>; fn with_base_object(&self) -> Option<JsObject>;
/// Get the next environment up /// Get the next environment up
fn get_outer_environment_ref(&self) -> Option<&Environment>; fn get_outer_environment_ref(&self) -> Option<&Environment>;

8
boa/src/environment/function_environment_record.rs

@ -17,7 +17,7 @@ use crate::{
lexical_environment::{Environment, EnvironmentType, VariableScope}, lexical_environment::{Environment, EnvironmentType, VariableScope},
}, },
gc::{empty_trace, Finalize, Trace}, gc::{empty_trace, Finalize, Trace},
object::GcObject, object::JsObject,
Context, JsResult, JsValue, 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. /// If the value is "lexical", this is an ArrowFunction and does not have a local this value.
pub this_binding_status: BindingStatus, pub this_binding_status: BindingStatus,
/// The function object whose invocation caused this Environment Record to be created. /// 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, /// 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. /// `[[HomeObject]]` is the object that the function is bound to as a method.
/// The default value for `[[HomeObject]]` is undefined. /// The default value for `[[HomeObject]]` is undefined.
@ -59,7 +59,7 @@ pub struct FunctionEnvironmentRecord {
impl FunctionEnvironmentRecord { impl FunctionEnvironmentRecord {
pub fn new( pub fn new(
f: GcObject, f: JsObject,
this: Option<JsValue>, this: Option<JsValue>,
outer: Option<Environment>, outer: Option<Environment>,
binding_status: BindingStatus, binding_status: BindingStatus,
@ -197,7 +197,7 @@ impl EnvironmentRecordTrait for FunctionEnvironmentRecord {
} }
} }
fn with_base_object(&self) -> Option<GcObject> { fn with_base_object(&self) -> Option<JsObject> {
None None
} }

8
boa/src/environment/global_environment_record.rs

@ -15,7 +15,7 @@ use crate::{
object_environment_record::ObjectEnvironmentRecord, object_environment_record::ObjectEnvironmentRecord,
}, },
gc::{Finalize, Trace}, gc::{Finalize, Trace},
object::GcObject, object::JsObject,
property::PropertyDescriptor, property::PropertyDescriptor,
Context, JsResult, JsValue, Context, JsResult, JsValue,
}; };
@ -25,13 +25,13 @@ use rustc_hash::FxHashSet;
#[derive(Debug, Trace, Finalize, Clone)] #[derive(Debug, Trace, Finalize, Clone)]
pub struct GlobalEnvironmentRecord { pub struct GlobalEnvironmentRecord {
pub object_record: ObjectEnvironmentRecord, pub object_record: ObjectEnvironmentRecord,
pub global_this_binding: GcObject, pub global_this_binding: JsObject,
pub declarative_record: DeclarativeEnvironmentRecord, pub declarative_record: DeclarativeEnvironmentRecord,
pub var_names: GcCell<FxHashSet<Box<str>>>, pub var_names: GcCell<FxHashSet<Box<str>>>,
} }
impl GlobalEnvironmentRecord { impl GlobalEnvironmentRecord {
pub fn new(global: GcObject, this_value: GcObject) -> GlobalEnvironmentRecord { pub fn new(global: JsObject, this_value: JsObject) -> GlobalEnvironmentRecord {
let obj_rec = ObjectEnvironmentRecord { let obj_rec = ObjectEnvironmentRecord {
bindings: global.into(), bindings: global.into(),
outer_env: None, outer_env: None,
@ -264,7 +264,7 @@ impl EnvironmentRecordTrait for GlobalEnvironmentRecord {
false false
} }
fn with_base_object(&self) -> Option<GcObject> { fn with_base_object(&self) -> Option<JsObject> {
None None
} }

4
boa/src/environment/lexical_environment.rs

@ -7,7 +7,7 @@
use super::global_environment_record::GlobalEnvironmentRecord; use super::global_environment_record::GlobalEnvironmentRecord;
use crate::{ use crate::{
environment::environment_record_trait::EnvironmentRecordTrait, object::GcObject, BoaProfiler, environment::environment_record_trait::EnvironmentRecordTrait, object::JsObject, BoaProfiler,
Context, JsResult, JsValue, Context, JsResult, JsValue,
}; };
use gc::Gc; use gc::Gc;
@ -63,7 +63,7 @@ impl fmt::Display for EnvironmentError {
impl error::Error for EnvironmentError {} impl error::Error for EnvironmentError {}
impl LexicalEnvironment { impl LexicalEnvironment {
pub fn new(global: GcObject) -> Self { pub fn new(global: JsObject) -> Self {
let _timer = BoaProfiler::global().start_event("LexicalEnvironment::new", "env"); let _timer = BoaProfiler::global().start_event("LexicalEnvironment::new", "env");
let global_env = GlobalEnvironmentRecord::new(global.clone(), global); let global_env = GlobalEnvironmentRecord::new(global.clone(), global);
let mut lexical_env = Self { let mut lexical_env = Self {

4
boa/src/environment/object_environment_record.rs

@ -14,7 +14,7 @@ use crate::{
lexical_environment::{Environment, EnvironmentType}, lexical_environment::{Environment, EnvironmentType},
}, },
gc::{Finalize, Trace}, gc::{Finalize, Trace},
object::GcObject, object::JsObject,
property::PropertyDescriptor, property::PropertyDescriptor,
Context, JsResult, JsValue, Context, JsResult, JsValue,
}; };
@ -153,7 +153,7 @@ impl EnvironmentRecordTrait for ObjectEnvironmentRecord {
false false
} }
fn with_base_object(&self) -> Option<GcObject> { fn with_base_object(&self) -> Option<JsObject> {
// Object Environment Records return undefined as their // Object Environment Records return undefined as their
// WithBaseObject unless their withEnvironment flag is true. // WithBaseObject unless their withEnvironment flag is true.
if self.with_environment { if self.with_environment {

2
boa/src/lib.rs

@ -64,7 +64,7 @@ pub mod vm;
/// A convenience module that re-exports the most commonly-used Boa APIs /// A convenience module that re-exports the most commonly-used Boa APIs
pub mod prelude { 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; use std::result::Result as StdResult;

46
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 super::{NativeObject, Object, PROTOTYPE};
use crate::{ use crate::{
@ -38,7 +38,7 @@ pub type RefMut<'a, T, U> = GcCellRefMut<'a, T, U>;
/// Garbage collected `Object`. /// Garbage collected `Object`.
#[derive(Trace, Finalize, Clone, Default)] #[derive(Trace, Finalize, Clone, Default)]
pub struct GcObject(Gc<GcCell<Object>>); pub struct JsObject(Gc<GcCell<Object>>);
/// The body of a JavaScript function. /// The body of a JavaScript function.
/// ///
@ -51,8 +51,8 @@ enum FunctionBody {
Ordinary(RcStatementList), Ordinary(RcStatementList),
} }
impl GcObject { impl JsObject {
/// Create a new `GcObject` from a `Object`. /// Create a new `JsObject` from a `Object`.
#[inline] #[inline]
pub fn new(object: Object) -> Self { pub fn new(object: Object) -> Self {
Self(Gc::new(GcCell::new(object))) Self(Gc::new(GcCell::new(object)))
@ -395,7 +395,7 @@ impl GcObject {
hint: PreferredType, hint: PreferredType,
) -> JsResult<JsValue> { ) -> JsResult<JsValue> {
// 1. Assert: Type(O) is Object. // 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". // 2. Assert: Type(hint) is String and its value is either "string" or "number".
debug_assert!(hint == PreferredType::String || hint == PreferredType::Number); debug_assert!(hint == PreferredType::String || hint == PreferredType::Number);
@ -709,7 +709,7 @@ impl GcObject {
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-getmethod /// [spec]: https://tc39.es/ecma262/#sec-getmethod
#[inline] #[inline]
pub fn get_method<K>(&self, context: &mut Context, key: K) -> JsResult<Option<GcObject>> pub fn get_method<K>(&self, context: &mut Context, key: K) -> JsResult<Option<JsObject>>
where where
K: Into<PropertyKey>, K: Into<PropertyKey>,
{ {
@ -763,7 +763,7 @@ impl GcObject {
let mut object = object.__get_prototype_of__(); let mut object = object.__get_prototype_of__();
while let Some(object_prototype) = object.as_object() { while let Some(object_prototype) = object.as_object() {
// c. If SameValue(P, O) is true, return true. // c. If SameValue(P, O) is true, return true.
if GcObject::equals(&prototype, &object_prototype) { if JsObject::equals(&prototype, &object_prototype) {
return Ok(true); return Ok(true);
} }
// a. Set O to ? O.[[GetPrototypeOf]](). // a. Set O to ? O.[[GetPrototypeOf]]().
@ -994,14 +994,14 @@ impl GcObject {
} }
} }
impl AsRef<GcCell<Object>> for GcObject { impl AsRef<GcCell<Object>> for JsObject {
#[inline] #[inline]
fn as_ref(&self) -> &GcCell<Object> { fn as_ref(&self) -> &GcCell<Object> {
&*self.0 &*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)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct BorrowError; pub struct BorrowError;
@ -1014,7 +1014,7 @@ impl Display for BorrowError {
impl Error 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)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct BorrowMutError; pub struct BorrowMutError;
@ -1036,8 +1036,8 @@ enum RecursionValueState {
/// ```javascript /// ```javascript
/// let b = []; /// let b = [];
/// JSON.stringify([ // Create a recursion limiter for the root here /// JSON.stringify([ // Create a recursion limiter for the root here
/// b, // state for b's &GcObject here is None /// b, // state for b's &JsObject here is None
/// b, // state for b's &GcObject here is Visited /// b, // state for b's &JsObject here is Visited
/// ]); /// ]);
/// ``` /// ```
Visited, Visited,
@ -1048,13 +1048,13 @@ enum RecursionValueState {
/// multiple threads! /// multiple threads!
#[derive(Debug)] #[derive(Debug)]
pub struct RecursionLimiter { pub struct RecursionLimiter {
/// If this was the first `GcObject` in the tree. /// If this was the first `JsObject` in the tree.
top_level: bool, top_level: bool,
/// The ptr being kept in the HashSet, so we can delete it when we drop. /// The ptr being kept in the HashSet, so we can delete it when we drop.
ptr: usize, 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, 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, pub live: bool,
} }
@ -1075,17 +1075,17 @@ impl Drop for RecursionLimiter {
impl RecursionLimiter { impl RecursionLimiter {
thread_local! { 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`) /// and the current state of their RecursionLimiter (dropped or live -- see `RecursionValueState`)
static SEEN: RefCell<HashMap<usize, RecursionValueState>> = RefCell::new(HashMap::new()); static SEEN: RefCell<HashMap<usize, RecursionValueState>> = 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 /// This is done by maintaining a thread-local hashset containing the pointers of `JsObject` values that have been
/// visited. The first `GcObject` visited will clear the hashset, while any others will check if they are contained /// visited. The first `JsObject` visited will clear the hashset, while any others will check if they are contained
/// by the hashset. /// 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. // 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 ptr = (o.as_ref() as *const _) as usize;
let (top_level, visited, live) = Self::SEEN.with(|hm| { 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 { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
let limiter = RecursionLimiter::new(self); 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 // 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. // at most once, hopefully making things a bit clearer.
if !limiter.visited && !limiter.live { if !limiter.visited && !limiter.live {
f.debug_tuple("GcObject").field(&self.0).finish() f.debug_tuple("JsObject").field(&self.0).finish()
} else { } else {
f.write_str("{ ... }") f.write_str("{ ... }")
} }

6
boa/src/object/internal_methods.rs

@ -7,13 +7,13 @@
use crate::{ use crate::{
builtins::Array, builtins::Array,
object::{GcObject, Object, ObjectData}, object::{JsObject, Object, ObjectData},
property::{DescriptorKind, PropertyDescriptor, PropertyKey, PropertyNameKind}, property::{DescriptorKind, PropertyDescriptor, PropertyKey, PropertyNameKind},
value::{JsValue, Type}, value::{JsValue, Type},
BoaProfiler, Context, JsResult, BoaProfiler, Context, JsResult,
}; };
impl GcObject { impl JsObject {
/// Check if object has property. /// Check if object has property.
/// ///
/// More information: /// More information:
@ -822,7 +822,7 @@ impl GcObject {
self.borrow().is_constructable() 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 { pub fn is_global(&self) -> bool {
matches!(self.borrow().data, ObjectData::Global) matches!(self.borrow().data, ObjectData::Global)
} }

30
boa/src/object/mod.rs

@ -32,7 +32,7 @@ mod internal_methods;
mod property_map; mod property_map;
use crate::builtins::object::for_in_iterator::ForInIterator; 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::*; pub use property_map::*;
/// Static `prototype`, usually set on constructors as a key to point to their respective prototype object. /// 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. /// Build the function object.
#[inline] #[inline]
pub fn build(&mut self) -> GcObject { pub fn build(&mut self) -> JsObject {
let mut function = Object::function( let mut function = Object::function(
self.function.take().unwrap(), self.function.take().unwrap(),
self.context self.context
@ -764,11 +764,11 @@ impl<'context> FunctionBuilder<'context> {
function.insert_property("name", property.clone().value(self.name.clone())); function.insert_property("name", property.clone().value(self.name.clone()));
function.insert_property("length", property.value(self.length)); function.insert_property("length", property.value(self.length));
GcObject::new(function) JsObject::new(function)
} }
/// Initializes the `Function.prototype` function object. /// 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(); let mut object = object.borrow_mut();
object.data = ObjectData::Function(self.function.take().unwrap()); object.data = ObjectData::Function(self.function.take().unwrap());
object.set_prototype_instance( object.set_prototype_instance(
@ -821,7 +821,7 @@ impl<'context> FunctionBuilder<'context> {
#[derive(Debug)] #[derive(Debug)]
pub struct ObjectInitializer<'context> { pub struct ObjectInitializer<'context> {
context: &'context mut Context, context: &'context mut Context,
object: GcObject, object: JsObject,
} }
impl<'context> ObjectInitializer<'context> { impl<'context> ObjectInitializer<'context> {
@ -874,7 +874,7 @@ impl<'context> ObjectInitializer<'context> {
/// Build the object. /// Build the object.
#[inline] #[inline]
pub fn build(&mut self) -> GcObject { pub fn build(&mut self) -> JsObject {
self.object.clone() self.object.clone()
} }
} }
@ -883,8 +883,8 @@ impl<'context> ObjectInitializer<'context> {
pub struct ConstructorBuilder<'context> { pub struct ConstructorBuilder<'context> {
context: &'context mut Context, context: &'context mut Context,
constructor_function: NativeFunction, constructor_function: NativeFunction,
constructor_object: GcObject, constructor_object: JsObject,
prototype: GcObject, prototype: JsObject,
name: JsString, name: JsString,
length: usize, length: usize,
callable: bool, callable: bool,
@ -913,8 +913,8 @@ impl<'context> ConstructorBuilder<'context> {
Self { Self {
context, context,
constructor_function: constructor, constructor_function: constructor,
constructor_object: GcObject::new(Object::default()), constructor_object: JsObject::new(Object::default()),
prototype: GcObject::new(Object::default()), prototype: JsObject::new(Object::default()),
length: 0, length: 0,
name: JsString::default(), name: JsString::default(),
callable: true, callable: true,
@ -1032,8 +1032,8 @@ impl<'context> ConstructorBuilder<'context> {
pub fn accessor<K>( pub fn accessor<K>(
&mut self, &mut self,
key: K, key: K,
get: Option<GcObject>, get: Option<JsObject>,
set: Option<GcObject>, set: Option<JsObject>,
attribute: Attribute, attribute: Attribute,
) -> &mut Self ) -> &mut Self
where where
@ -1053,8 +1053,8 @@ impl<'context> ConstructorBuilder<'context> {
pub fn static_accessor<K>( pub fn static_accessor<K>(
&mut self, &mut self,
key: K, key: K,
get: Option<GcObject>, get: Option<JsObject>,
set: Option<GcObject>, set: Option<JsObject>,
attribute: Attribute, attribute: Attribute,
) -> &mut Self ) -> &mut Self
where where
@ -1149,7 +1149,7 @@ impl<'context> ConstructorBuilder<'context> {
} }
/// Build the constructor function object. /// Build the constructor function object.
pub fn build(&mut self) -> GcObject { pub fn build(&mut self) -> JsObject {
// Create the native function // Create the native function
let function = Function::Native { let function = Function::Native {
function: self.constructor_function.into(), function: self.constructor_function.into(),

6
boa/src/realm.rs

@ -8,7 +8,7 @@ use crate::{
environment::{ environment::{
global_environment_record::GlobalEnvironmentRecord, lexical_environment::LexicalEnvironment, global_environment_record::GlobalEnvironmentRecord, lexical_environment::LexicalEnvironment,
}, },
object::{GcObject, Object, ObjectData}, object::{JsObject, Object, ObjectData},
BoaProfiler, BoaProfiler,
}; };
use gc::Gc; use gc::Gc;
@ -18,7 +18,7 @@ use gc::Gc;
/// In the specification these are called Realm Records. /// In the specification these are called Realm Records.
#[derive(Debug)] #[derive(Debug)]
pub struct Realm { pub struct Realm {
pub global_object: GcObject, pub global_object: JsObject,
pub global_env: Gc<GlobalEnvironmentRecord>, pub global_env: Gc<GlobalEnvironmentRecord>,
pub environment: LexicalEnvironment, pub environment: LexicalEnvironment,
} }
@ -34,7 +34,7 @@ impl Realm {
// Allow identification of the global object easily // Allow identification of the global object easily
global.data = ObjectData::Global; 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) // 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()); let global_env = GlobalEnvironmentRecord::new(gc_global.clone(), gc_global.clone());

8
boa/src/value/conversions.rs

@ -164,14 +164,14 @@ impl From<Object> for JsValue {
#[inline] #[inline]
fn from(object: Object) -> Self { fn from(object: Object) -> Self {
let _timer = BoaProfiler::global().start_event("From<Object>", "value"); let _timer = BoaProfiler::global().start_event("From<Object>", "value");
JsValue::Object(GcObject::new(object)) JsValue::Object(JsObject::new(object))
} }
} }
impl From<GcObject> for JsValue { impl From<JsObject> for JsValue {
#[inline] #[inline]
fn from(object: GcObject) -> Self { fn from(object: JsObject) -> Self {
let _timer = BoaProfiler::global().start_event("From<GcObject>", "value"); let _timer = BoaProfiler::global().start_event("From<JsObject>", "value");
JsValue::Object(object) JsValue::Object(object)
} }
} }

2
boa/src/value/equality.rs

@ -178,7 +178,7 @@ impl JsValue {
(JsValue::Null, JsValue::Null) | (JsValue::Undefined, JsValue::Undefined) => true, (JsValue::Null, JsValue::Null) | (JsValue::Undefined, JsValue::Undefined) => true,
(JsValue::String(ref x), JsValue::String(ref y)) => x == y, (JsValue::String(ref x), JsValue::String(ref y)) => x == y,
(JsValue::Boolean(x), JsValue::Boolean(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, (JsValue::Symbol(ref x), JsValue::Symbol(ref y)) => x == y,
_ => false, _ => false,
} }

22
boa/src/value/mod.rs

@ -11,7 +11,7 @@ use crate::{
string::is_trimmable_whitespace, string::is_trimmable_whitespace,
Number, Number,
}, },
object::{GcObject, Object, ObjectData}, object::{JsObject, Object, ObjectData},
property::{PropertyDescriptor, PropertyKey}, property::{PropertyDescriptor, PropertyKey},
symbol::{JsSymbol, WellKnownSymbols}, symbol::{JsSymbol, WellKnownSymbols},
BoaProfiler, Context, JsBigInt, JsResult, JsString, BoaProfiler, Context, JsBigInt, JsResult, JsString,
@ -57,7 +57,7 @@ pub enum JsValue {
/// `BigInt` - holds any arbitrary large signed integer. /// `BigInt` - holds any arbitrary large signed integer.
BigInt(JsBigInt), BigInt(JsBigInt),
/// `Object` - An object, such as `Math`, represented by a binary tree of string keys to Javascript values. /// `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` - A Symbol Primitive type.
Symbol(JsSymbol), Symbol(JsSymbol),
} }
@ -228,7 +228,7 @@ impl JsValue {
} }
#[inline] #[inline]
pub fn as_object(&self) -> Option<GcObject> { pub fn as_object(&self) -> Option<JsObject> {
match *self { match *self {
Self::Object(ref o) => Some(o.clone()), Self::Object(ref o) => Some(o.clone()),
_ => None, _ => None,
@ -623,28 +623,28 @@ impl JsValue {
/// This function is equivalent to `Object(value)` in JavaScript /// This function is equivalent to `Object(value)` in JavaScript
/// ///
/// See: <https://tc39.es/ecma262/#sec-toobject> /// See: <https://tc39.es/ecma262/#sec-toobject>
pub fn to_object(&self, context: &mut Context) -> JsResult<GcObject> { pub fn to_object(&self, context: &mut Context) -> JsResult<JsObject> {
match self { match self {
JsValue::Undefined | JsValue::Null => { JsValue::Undefined | JsValue::Null => {
Err(context.construct_type_error("cannot convert 'null' or 'undefined' to object")) Err(context.construct_type_error("cannot convert 'null' or 'undefined' to object"))
} }
JsValue::Boolean(boolean) => { JsValue::Boolean(boolean) => {
let prototype = context.standard_objects().boolean_object().prototype(); let prototype = context.standard_objects().boolean_object().prototype();
Ok(GcObject::new(Object::with_prototype( Ok(JsObject::new(Object::with_prototype(
prototype.into(), prototype.into(),
ObjectData::Boolean(*boolean), ObjectData::Boolean(*boolean),
))) )))
} }
JsValue::Integer(integer) => { JsValue::Integer(integer) => {
let prototype = context.standard_objects().number_object().prototype(); let prototype = context.standard_objects().number_object().prototype();
Ok(GcObject::new(Object::with_prototype( Ok(JsObject::new(Object::with_prototype(
prototype.into(), prototype.into(),
ObjectData::Number(f64::from(*integer)), ObjectData::Number(f64::from(*integer)),
))) )))
} }
JsValue::Rational(rational) => { JsValue::Rational(rational) => {
let prototype = context.standard_objects().number_object().prototype(); let prototype = context.standard_objects().number_object().prototype();
Ok(GcObject::new(Object::with_prototype( Ok(JsObject::new(Object::with_prototype(
prototype.into(), prototype.into(),
ObjectData::Number(*rational), ObjectData::Number(*rational),
))) )))
@ -652,7 +652,7 @@ impl JsValue {
JsValue::String(ref string) => { JsValue::String(ref string) => {
let prototype = context.standard_objects().string_object().prototype(); let prototype = context.standard_objects().string_object().prototype();
let object = GcObject::new(Object::with_prototype( let object = JsObject::new(Object::with_prototype(
prototype.into(), prototype.into(),
ObjectData::String(string.clone()), ObjectData::String(string.clone()),
)); ));
@ -669,19 +669,19 @@ impl JsValue {
} }
JsValue::Symbol(ref symbol) => { JsValue::Symbol(ref symbol) => {
let prototype = context.standard_objects().symbol_object().prototype(); let prototype = context.standard_objects().symbol_object().prototype();
Ok(GcObject::new(Object::with_prototype( Ok(JsObject::new(Object::with_prototype(
prototype.into(), prototype.into(),
ObjectData::Symbol(symbol.clone()), ObjectData::Symbol(symbol.clone()),
))) )))
} }
JsValue::BigInt(ref bigint) => { JsValue::BigInt(ref bigint) => {
let prototype = context.standard_objects().bigint_object().prototype(); let prototype = context.standard_objects().bigint_object().prototype();
Ok(GcObject::new(Object::with_prototype( Ok(JsObject::new(Object::with_prototype(
prototype.into(), prototype.into(),
ObjectData::BigInt(bigint.clone()), ObjectData::BigInt(bigint.clone()),
))) )))
} }
JsValue::Object(gcobject) => Ok(gcobject.clone()), JsValue::Object(jsobject) => Ok(jsobject.clone()),
} }
} }

4
boa/src/value/tests.rs

@ -618,8 +618,8 @@ fn to_primitive() {
} }
/// Test cyclic conversions that previously caused stack overflows /// Test cyclic conversions that previously caused stack overflows
/// Relevant mitigations for these are in `GcObject::ordinary_to_primitive` and /// Relevant mitigations for these are in `JsObject::ordinary_to_primitive` and
/// `GcObject::to_json` /// `JsObject::to_json`
mod cyclic_conversions { mod cyclic_conversions {
use super::*; use super::*;

4
boa_tester/src/exec/js262.rs

@ -1,12 +1,12 @@
use boa::{ use boa::{
exec::Executable, exec::Executable,
object::{GcObject, ObjectInitializer}, object::{JsObject, ObjectInitializer},
property::Attribute, property::Attribute,
Context, JsResult, JsValue, Context, JsResult, JsValue,
}; };
/// Initializes the object in the context. /// 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 global_obj = context.global_object();
let obj = ObjectInitializer::new(context) let obj = ObjectInitializer::new(context)

Loading…
Cancel
Save