Skip to content

Commit

Permalink
Merge 1450788 into d46080d
Browse files Browse the repository at this point in the history
  • Loading branch information
tofpie authored Dec 18, 2020
2 parents d46080d + 1450788 commit 964eaed
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion boa/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ impl Default for StandardConstructor {
}

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),
}
}

/// Return the constructor object.
///
/// This is the same as `Object`, `Array`, etc.
Expand All @@ -65,7 +73,7 @@ impl StandardConstructor {
}

/// Cached core standard objects.
#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone)]
pub struct StandardObjects {
object: StandardConstructor,
function: StandardConstructor,
Expand All @@ -85,6 +93,29 @@ pub struct StandardObjects {
uri_error: StandardConstructor,
}

impl Default for StandardObjects {
fn default() -> Self {
Self {
object: StandardConstructor::default(),
function: StandardConstructor::default(),
array: StandardConstructor::default(),
bigint: StandardConstructor::default(),
number: StandardConstructor::with_prototype(Object::number(0.0)),
boolean: StandardConstructor::with_prototype(Object::boolean(false)),
string: StandardConstructor::with_prototype(Object::string("")),
regexp: StandardConstructor::default(),
symbol: StandardConstructor::default(),
error: StandardConstructor::default(),
type_error: StandardConstructor::default(),
referece_error: StandardConstructor::default(),
range_error: StandardConstructor::default(),
syntax_error: StandardConstructor::default(),
eval_error: StandardConstructor::default(),
uri_error: StandardConstructor::default(),
}
}
}

impl StandardObjects {
#[inline]
pub fn object_object(&self) -> &StandardConstructor {
Expand Down

0 comments on commit 964eaed

Please sign in to comment.