Browse Source

Added create_constructor method (#144)

pull/147/head
Dom Parfitt 5 years ago committed by Jason Williams
parent
commit
44d92c9220
  1. 6
      src/lib/js/math.rs
  2. 2
      src/lib/realm.rs

6
src/lib/js/math.rs

@ -191,7 +191,7 @@ pub fn tan(_: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
})) }))
} }
/// Create a new `Math` object /// Create a new `Math` object
pub fn _create(global: &Value) -> Value { pub fn create_constructor(global: &Value) -> Value {
let math = ValueData::new_obj(Some(global)); let math = ValueData::new_obj(Some(global));
math.set_field_slice("E", to_value(f64::consts::E)); math.set_field_slice("E", to_value(f64::consts::E));
math.set_field_slice("LN2", to_value(f64::consts::LN_2)); math.set_field_slice("LN2", to_value(f64::consts::LN_2));
@ -222,7 +222,3 @@ pub fn _create(global: &Value) -> Value {
math.set_field_slice("tan", to_value(tan as NativeFunctionData)); math.set_field_slice("tan", to_value(tan as NativeFunctionData));
math math
} }
/// Initialise the `Math` object on the global object
pub fn init(global: &Value) {
global.set_field_slice("Math", _create(global));
}

2
src/lib/realm.rs

@ -53,7 +53,6 @@ impl Realm {
let global = &self.global_obj; let global = &self.global_obj;
// Create intrinsics, add global objects here // Create intrinsics, add global objects here
object::init(global); object::init(global);
math::init(global);
function::init(global); function::init(global);
json::init(global); json::init(global);
@ -61,6 +60,7 @@ impl Realm {
global.set_field_slice("RegExp", regexp::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("Array", array::create_constructor(global));
global.set_field_slice("Boolean", boolean::create_constructor(global)); global.set_field_slice("Boolean", boolean::create_constructor(global));
global.set_field_slice("Math", math::create_constructor(global));
global.set_field_slice("console", console::create_constructor(global)); global.set_field_slice("console", console::create_constructor(global));
} }
} }

Loading…
Cancel
Save