Browse Source

Fix prototypes for Number, String and Boolean (#981)

* Fix prototype for Number, String and Boolean

* Fix formatting issue

Co-authored-by: tofpie <tofpie@users.noreply.github.com>
pull/991/head
tofpie 3 years ago committed by GitHub
parent
commit
395a28c2ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 33
      boa/src/context.rs

33
boa/src/context.rs

@ -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.
@ -65,7 +73,7 @@ impl StandardConstructor {
}
/// Cached core standard objects.
#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone)]
pub struct StandardObjects {
object: StandardConstructor,
function: StandardConstructor,
@ -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 {

Loading…
Cancel
Save