|
|
@ -15,7 +15,6 @@ use crate::{ |
|
|
|
builtins::{BuiltIn, JsArgs}, |
|
|
|
builtins::{BuiltIn, JsArgs}, |
|
|
|
context::StandardObjects, |
|
|
|
context::StandardObjects, |
|
|
|
environments::DeclarativeEnvironmentStack, |
|
|
|
environments::DeclarativeEnvironmentStack, |
|
|
|
gc::{self, Finalize, Gc, Trace}, |
|
|
|
|
|
|
|
object::{ |
|
|
|
object::{ |
|
|
|
internal_methods::get_prototype_from_constructor, JsObject, NativeObject, Object, |
|
|
|
internal_methods::get_prototype_from_constructor, JsObject, NativeObject, Object, |
|
|
|
ObjectData, |
|
|
|
ObjectData, |
|
|
@ -24,8 +23,10 @@ use crate::{ |
|
|
|
property::{Attribute, PropertyDescriptor, PropertyKey}, |
|
|
|
property::{Attribute, PropertyDescriptor, PropertyKey}, |
|
|
|
symbol::WellKnownSymbols, |
|
|
|
symbol::WellKnownSymbols, |
|
|
|
value::IntegerOrInfinity, |
|
|
|
value::IntegerOrInfinity, |
|
|
|
BoaProfiler, Context, JsResult, JsString, JsValue, |
|
|
|
Context, JsResult, JsString, JsValue, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
use boa_gc::{self, Finalize, Gc, Trace}; |
|
|
|
|
|
|
|
use boa_profiler::Profiler; |
|
|
|
use dyn_clone::DynClone; |
|
|
|
use dyn_clone::DynClone; |
|
|
|
use std::{ |
|
|
|
use std::{ |
|
|
|
any::Any, |
|
|
|
any::Any, |
|
|
@ -125,7 +126,7 @@ impl ConstructorKind { |
|
|
|
/// with `Any::downcast_ref` and `Any::downcast_mut` to recover the original
|
|
|
|
/// with `Any::downcast_ref` and `Any::downcast_mut` to recover the original
|
|
|
|
/// type.
|
|
|
|
/// type.
|
|
|
|
#[derive(Clone, Debug, Trace, Finalize)] |
|
|
|
#[derive(Clone, Debug, Trace, Finalize)] |
|
|
|
pub struct Captures(Gc<gc::Cell<Box<dyn NativeObject>>>); |
|
|
|
pub struct Captures(Gc<boa_gc::Cell<Box<dyn NativeObject>>>); |
|
|
|
|
|
|
|
|
|
|
|
impl Captures { |
|
|
|
impl Captures { |
|
|
|
/// Creates a new capture context.
|
|
|
|
/// Creates a new capture context.
|
|
|
@ -133,7 +134,7 @@ impl Captures { |
|
|
|
where |
|
|
|
where |
|
|
|
T: NativeObject, |
|
|
|
T: NativeObject, |
|
|
|
{ |
|
|
|
{ |
|
|
|
Self(Gc::new(gc::Cell::new(Box::new(captures)))) |
|
|
|
Self(Gc::new(boa_gc::Cell::new(Box::new(captures)))) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Casts `Captures` to `Any`
|
|
|
|
/// Casts `Captures` to `Any`
|
|
|
@ -141,7 +142,7 @@ impl Captures { |
|
|
|
/// # Panics
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// Panics if it's already borrowed as `&mut Any`
|
|
|
|
/// Panics if it's already borrowed as `&mut Any`
|
|
|
|
pub fn as_any(&self) -> gc::Ref<'_, dyn Any> { |
|
|
|
pub fn as_any(&self) -> boa_gc::Ref<'_, dyn Any> { |
|
|
|
Ref::map(self.0.borrow(), |data| data.deref().as_any()) |
|
|
|
Ref::map(self.0.borrow(), |data| data.deref().as_any()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -150,7 +151,7 @@ impl Captures { |
|
|
|
/// # Panics
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// Panics if it's already borrowed as `&mut Any`
|
|
|
|
/// Panics if it's already borrowed as `&mut Any`
|
|
|
|
pub fn as_mut_any(&self) -> gc::RefMut<'_, Box<dyn NativeObject>, dyn Any> { |
|
|
|
pub fn as_mut_any(&self) -> boa_gc::RefMut<'_, Box<dyn NativeObject>, dyn Any> { |
|
|
|
RefMut::map(self.0.borrow_mut(), |data| data.deref_mut().as_mut_any()) |
|
|
|
RefMut::map(self.0.borrow_mut(), |data| data.deref_mut().as_mut_any()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -225,7 +226,7 @@ pub(crate) fn make_builtin_fn<N>( |
|
|
|
N: Into<String>, |
|
|
|
N: Into<String>, |
|
|
|
{ |
|
|
|
{ |
|
|
|
let name = name.into(); |
|
|
|
let name = name.into(); |
|
|
|
let _timer = BoaProfiler::global().start_event(&format!("make_builtin_fn: {name}"), "init"); |
|
|
|
let _timer = Profiler::global().start_event(&format!("make_builtin_fn: {name}"), "init"); |
|
|
|
|
|
|
|
|
|
|
|
let function = JsObject::from_proto_and_data( |
|
|
|
let function = JsObject::from_proto_and_data( |
|
|
|
interpreter.standard_objects().function_object().prototype(), |
|
|
|
interpreter.standard_objects().function_object().prototype(), |
|
|
@ -488,7 +489,7 @@ impl BuiltIn for BuiltInFunctionObject { |
|
|
|
.union(Attribute::CONFIGURABLE); |
|
|
|
.union(Attribute::CONFIGURABLE); |
|
|
|
|
|
|
|
|
|
|
|
fn init(context: &mut Context) -> JsValue { |
|
|
|
fn init(context: &mut Context) -> JsValue { |
|
|
|
let _timer = BoaProfiler::global().start_event("function", "init"); |
|
|
|
let _timer = Profiler::global().start_event("function", "init"); |
|
|
|
|
|
|
|
|
|
|
|
let function_prototype = context.standard_objects().function_object().prototype(); |
|
|
|
let function_prototype = context.standard_objects().function_object().prototype(); |
|
|
|
FunctionBuilder::native(context, Self::prototype) |
|
|
|
FunctionBuilder::native(context, Self::prototype) |