From 6e90b74639c5587515d3dbc63cc9b0adb15a27b0 Mon Sep 17 00:00:00 2001 From: Dom Parfitt <11363907+DomParfitt@users.noreply.github.com> Date: Tue, 8 Oct 2019 23:41:29 +0100 Subject: [PATCH] Update console global (#143) * Added create_constructor method * Added new console constructor to realm --- src/lib/js/console.rs | 7 ++----- src/lib/realm.rs | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/lib/js/console.rs b/src/lib/js/console.rs index c15ef22742..a257c28e06 100644 --- a/src/lib/js/console.rs +++ b/src/lib/js/console.rs @@ -118,15 +118,12 @@ pub fn error(_: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue { println!("{}", args.join(" ")); Ok(Gc::new(ValueData::Undefined)) } + /// Create a new `console` object -pub fn _create(global: &Value) -> Value { +pub fn create_constructor(global: &Value) -> Value { let console = ValueData::new_obj(Some(global)); console.set_field_slice("log", to_value(log as NativeFunctionData)); console.set_field_slice("error", to_value(error as NativeFunctionData)); console.set_field_slice("exception", to_value(error as NativeFunctionData)); console } -/// Initialise the global object with the `console` object -pub fn init(global: &Value) { - global.set_field_slice("console", _create(global)); -} diff --git a/src/lib/realm.rs b/src/lib/realm.rs index a6291b4e75..95a3aace6b 100644 --- a/src/lib/realm.rs +++ b/src/lib/realm.rs @@ -53,7 +53,6 @@ impl Realm { let global = &self.global_obj; // Create intrinsics, add global objects here object::init(global); - console::init(global); math::init(global); function::init(global); json::init(global); @@ -62,6 +61,7 @@ impl Realm { 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("console", console::create_constructor(global)); } }