diff --git a/CHANGELOG.md b/CHANGELOG.md index 2823afb32d..8f1f6e0d7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,11 @@ Bug fixes: Unassigned variables have default of undefined (@pop) - Tidy up Globals being added to Global Object. Thanks @DomParfitt +Bug fixes: + +- [BUG #113](https://github.com/jasonwilliams/boa/issues/113): + Unassigned variables have default of undefined (@pop) + # 0.4.0 (2019-09-25) v0.4.0 brings quite a big release. The biggest feature to land is the support of regular expressions. diff --git a/src/lib/js/json.rs b/src/lib/js/json.rs index 7f1bcf7f2d..a44a05ee7b 100644 --- a/src/lib/js/json.rs +++ b/src/lib/js/json.rs @@ -1,5 +1,6 @@ use crate::exec::Interpreter; use crate::js::function::NativeFunctionData; +use crate::js::object::{Object, ObjectKind, PROTOTYPE}; /// The JSON Object /// use crate::js::value::{to_value, ResultValue, Value, ValueData}; @@ -27,14 +28,15 @@ pub fn stringify(_: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue } /// Create a new `JSON` object -pub fn _create(global: &Value) -> Value { - let object = ValueData::new_obj(Some(global)); - object.set_field_slice("stringify", to_value(stringify as NativeFunctionData)); - object.set_field_slice("parse", to_value(parse as NativeFunctionData)); - object -} +pub fn create_constructor(global: &Value) -> Value { + let mut json = Object::default(); + json.kind = ObjectKind::Ordinary; + + let prototype = ValueData::new_obj(Some(global)); + prototype.set_field_slice("parse", to_value(parse as NativeFunctionData)); + prototype.set_field_slice("stringify", to_value(stringify as NativeFunctionData)); -/// Initialise the global object with the `JSON` object -pub fn init(global: &Value) { - global.set_field_slice("JSON", _create(global)); + let json_value = to_value(json); + json_value.set_field_slice(PROTOTYPE, prototype); + json_value } diff --git a/src/lib/realm.rs b/src/lib/realm.rs index 9aa75babe6..76eb52eaff 100644 --- a/src/lib/realm.rs +++ b/src/lib/realm.rs @@ -54,12 +54,12 @@ impl Realm { // Create intrinsics, add global objects here object::init(global); function::init(global); - json::init(global); global.set_field_slice("String", string::create_constructor(global)); global.set_field_slice("RegExp", regexp::create_constructor(global)); global.set_field_slice("Array", array::create_constructor(global)); global.set_field_slice("Boolean", boolean::create_constructor(global)); + global.set_field_slice("JSON", json::create_constructor(global)); global.set_field_slice("Math", math::create_constructor(global)); global.set_field_slice("console", console::create_constructor(global)); }