Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement erased objects #3494

Merged
merged 15 commits into from
Dec 5, 2023
11 changes: 4 additions & 7 deletions boa_cli/src/debug/function.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use boa_engine::{
builtins::function::OrdinaryFunction,
js_string,
object::ObjectInitializer,
vm::flowgraph::{Direction, Graph},
Expand Down Expand Up @@ -80,9 +81,7 @@ fn flowgraph(_this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResu
}
}

let object = object.borrow();

let Some(function) = object.as_function() else {
let Some(function) = object.downcast_ref::<OrdinaryFunction>() else {
return Err(JsNativeError::typ()
.with_message("expected an ordinary function object")
.into());
Expand Down Expand Up @@ -112,8 +111,7 @@ fn bytecode(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue>
.with_message(format!("expected object, got {}", value.type_of()))
.into());
};
let object = object.borrow();
let Some(function) = object.as_function() else {
let Some(function) = object.downcast_ref::<OrdinaryFunction>() else {
return Err(JsNativeError::typ()
.with_message("expected an ordinary function object")
.into());
Expand All @@ -124,8 +122,7 @@ fn bytecode(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue>
}

fn set_trace_flag_in_function_object(object: &JsObject, value: bool) -> JsResult<()> {
let object = object.borrow();
let Some(function) = object.as_function() else {
let Some(function) = object.downcast_ref::<OrdinaryFunction>() else {
return Err(JsNativeError::typ()
.with_message("expected an ordinary function object")
.into());
Expand Down
2 changes: 1 addition & 1 deletion boa_cli/src/debug/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn id(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
};

let ptr: *const _ = object.as_ref();
Ok(js_string!(format!("0x{:X}", ptr as usize)).into())
Ok(js_string!(format!("0x{:X}", ptr.cast::<()>() as usize)).into())
}

pub(super) fn create_object(context: &mut Context) -> JsObject {
Expand Down
7 changes: 5 additions & 2 deletions boa_engine/src/bigint.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Boa's implementation of ECMAScript's bigint primitive type.

use crate::{builtins::Number, error::JsNativeError, JsResult};
use crate::{builtins::Number, error::JsNativeError, JsData, JsResult};
use boa_gc::{Finalize, Trace};
use num_integer::Integer;
use num_traits::{pow::Pow, FromPrimitive, One, ToPrimitive, Zero};
use std::{
Expand All @@ -17,7 +18,9 @@ use serde::{Deserialize, Serialize};

/// JavaScript bigint primitive rust type.
#[cfg_attr(feature = "deser", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Trace, Finalize, JsData)]
// Safety: `JsBigInt` doesn't contain any traceable types.
#[boa_gc(unsafe_empty_trace)]
pub struct JsBigInt {
inner: Rc<RawBigInt>,
}
Expand Down
22 changes: 11 additions & 11 deletions boa_engine/src/builtins/array/array_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@

use crate::{
builtins::{
iterable::create_iter_result_object, Array, BuiltInBuilder, IntrinsicObject, JsValue,
iterable::create_iter_result_object, typed_array::TypedArray, Array, BuiltInBuilder,
IntrinsicObject, JsValue,
},
context::intrinsics::Intrinsics,
error::JsNativeError,
js_string,
object::{JsObject, ObjectData},
object::JsObject,
property::{Attribute, PropertyNameKind},
realm::Realm,
symbol::JsSymbol,
Context, JsResult,
Context, JsData, JsResult,
};
use boa_gc::{Finalize, Trace};
use boa_profiler::Profiler;
Expand All @@ -27,8 +28,8 @@ use boa_profiler::Profiler;
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-array-iterator-objects
#[derive(Debug, Clone, Finalize, Trace)]
pub struct ArrayIterator {
#[derive(Debug, Clone, Finalize, Trace, JsData)]
pub(crate) struct ArrayIterator {
array: JsObject,
next_index: u64,
#[unsafe_ignore_trace]
Expand Down Expand Up @@ -88,7 +89,7 @@ impl ArrayIterator {
let array_iterator = JsObject::from_proto_and_data_with_shared_shape(
context.root_shape(),
context.intrinsics().objects().iterator_prototypes().array(),
ObjectData::array_iterator(Self::new(array, kind)),
Self::new(array, kind),
);
array_iterator.into()
}
Expand All @@ -102,10 +103,9 @@ impl ArrayIterator {
///
/// [spec]: https://tc39.es/ecma262/#sec-%arrayiteratorprototype%.next
pub(crate) fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let mut array_iterator = this.as_object().map(JsObject::borrow_mut);
let array_iterator = array_iterator
.as_mut()
.and_then(|obj| obj.as_array_iterator_mut())
let mut array_iterator = this
.as_object()
.and_then(JsObject::downcast_mut::<Self>)
.ok_or_else(|| JsNativeError::typ().with_message("`this` is not an ArrayIterator"))?;
let index = array_iterator.next_index;
if array_iterator.done {
Expand All @@ -116,7 +116,7 @@ impl ArrayIterator {
));
}

let len = if let Some(f) = array_iterator.array.borrow().as_typed_array() {
let len = if let Some(f) = array_iterator.array.downcast_ref::<TypedArray>() {
if f.is_detached() {
return Err(JsNativeError::typ()
.with_message(
Expand Down
Loading
Loading