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

Fix prototypes for Number, String and Boolean #981

Merged
merged 2 commits into from
Dec 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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