Skip to content

Commit

Permalink
Merge b1e4f25 into dd0f967
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonwilliams authored May 1, 2020
2 parents dd0f967 + b1e4f25 commit 19ff051
Show file tree
Hide file tree
Showing 21 changed files with 931 additions and 701 deletions.
66 changes: 16 additions & 50 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
"type": "process",
"label": "Cargo Run",
"command": "cargo",
"args": [
"run",
"./tests/js/test.js"
],
"problemMatcher": [
"$rustc"
],
"args": ["run", "./tests/js/test.js"],
"problemMatcher": ["$rustc"],
"group": {
"kind": "build",
"isDefault": true
},
"options": {
"env": { "RUST_BACKTRACE": "full" }
},
"presentation": {
"clear": true
}
Expand All @@ -26,19 +24,9 @@
"type": "process",
"label": "Get Tokens",
"command": "cargo",
"args": [
"run",
"--",
"-t=Debug",
"./tests/js/test.js"
],
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "build",
"isDefault": true
},
"args": ["run", "--", "-t=Debug", "./tests/js/test.js"],
"problemMatcher": ["$rustc"],
"group": "build",
"presentation": {
"clear": true
}
Expand All @@ -47,19 +35,9 @@
"type": "process",
"label": "Get AST",
"command": "cargo",
"args": [
"run",
"--",
"-a=Debug",
"./tests/js/test.js"
],
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "build",
"isDefault": true
},
"args": ["run", "--", "-a=Debug", "./tests/js/test.js"],
"problemMatcher": ["$rustc"],
"group": "build",
"presentation": {
"clear": true
}
Expand All @@ -68,12 +46,8 @@
"type": "process",
"label": "Cargo Test",
"command": "cargo",
"args": [
"test"
],
"problemMatcher": [
"$rustc"
],
"args": ["test"],
"problemMatcher": ["$rustc"],
"group": {
"kind": "test",
"isDefault": true
Expand All @@ -86,17 +60,9 @@
"type": "process",
"label": "Cargo Test Build",
"command": "cargo",
"args": [
"test",
"--no-run"
],
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "build",
"isDefault": true
}
"args": ["test", "--no-run"],
"problemMatcher": ["$rustc"],
"group": "build"
}
]
}
92 changes: 43 additions & 49 deletions boa/src/builtins/array/mod.rs

Large diffs are not rendered by default.

18 changes: 5 additions & 13 deletions boa/src/builtins/boolean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ mod tests;

use crate::{
builtins::{
function::NativeFunctionData,
object::{internal_methods_trait::ObjectInternalMethods, Object, ObjectKind, PROTOTYPE},
value::{to_value, ResultValue, Value, ValueData},
},
Expand All @@ -23,7 +22,7 @@ use crate::{
use std::{borrow::Borrow, ops::Deref};

/// Create a new boolean object - [[Construct]]
pub fn construct_boolean(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn construct_boolean(this: &mut Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
this.set_kind(ObjectKind::Boolean);

// Get the argument, if any
Expand All @@ -38,7 +37,7 @@ pub fn construct_boolean(this: &Value, args: &[Value], _: &mut Interpreter) -> R
}

/// Return a boolean literal [[Call]]
pub fn call_boolean(_: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn call_boolean(_: &mut Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
// Get the argument, if any
match args.get(0) {
Some(ref value) => Ok(to_boolean(value)),
Expand All @@ -54,7 +53,7 @@ pub fn call_boolean(_: &Value, args: &[Value], _: &mut Interpreter) -> ResultVal
///
/// [spec]: https://tc39.es/ecma262/#sec-boolean-object
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/toString
pub fn to_string(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn to_string(this: &mut Value, _: &[Value], _: &mut Interpreter) -> ResultValue {
let b = this_boolean_value(this);
Ok(to_value(b.to_string()))
}
Expand All @@ -67,27 +66,20 @@ pub fn to_string(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue
///
/// [spec]: https://tc39.es/ecma262/#sec-boolean.prototype.valueof
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/valueOf
pub fn value_of(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn value_of(this: &mut Value, _: &[Value], _: &mut Interpreter) -> ResultValue {
Ok(this_boolean_value(this))
}

/// Create a new `Boolean` object
pub fn create_constructor(global: &Value) -> Value {
let mut boolean = Object::default();
boolean.kind = ObjectKind::Function;
boolean.set_internal_method("construct", construct_boolean);
boolean.set_internal_method("call", call_boolean);
// Create Prototype
// https://tc39.es/ecma262/#sec-properties-of-the-boolean-prototype-object
let boolean_prototype = ValueData::new_obj(Some(global));
boolean_prototype.set_internal_slot("BooleanData", to_boolean(&to_value(false)));
make_builtin_fn!(to_string, named "toString", of boolean_prototype);
make_builtin_fn!(value_of, named "valueOf", of boolean_prototype);

let boolean_value = to_value(boolean);
boolean_prototype.set_field_slice("constructor", to_value(boolean_value.clone()));
boolean_value.set_field_slice(PROTOTYPE, boolean_prototype);
boolean_value
make_constructor_fn!(construct_boolean, call_boolean, global, boolean_prototype)
}

// === Utility Functions ===
Expand Down
71 changes: 35 additions & 36 deletions boa/src/builtins/console/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ mod tests;

use crate::{
builtins::{
function::NativeFunctionData,
object::InternalState,
value::{display_obj, from_value, to_value, FromValue, ResultValue, Value, ValueData},
},
Expand Down Expand Up @@ -149,7 +148,7 @@ pub fn formatter(data: &[Value]) -> String {
///
/// [spec]: https://console.spec.whatwg.org/#assert
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/assert
pub fn assert(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn assert(this: &mut Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let assertion = get_arg_at_index::<bool>(args, 0).unwrap_or_default();

if !assertion {
Expand Down Expand Up @@ -182,7 +181,7 @@ pub fn assert(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue
///
/// [spec]: https://console.spec.whatwg.org/#clear
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/clear
pub fn clear(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn clear(this: &mut Value, _: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_mut(|state: &mut ConsoleState| {
state.groups.clear();
});
Expand All @@ -200,7 +199,7 @@ pub fn clear(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue {
///
/// [spec]: https://console.spec.whatwg.org/#debug
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/debug
pub fn debug(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn debug(this: &mut Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_ref(|state| logger(LogMessage::Log(formatter(&args[..])), state));
Ok(Gc::new(ValueData::Undefined))
}
Expand All @@ -215,7 +214,7 @@ pub fn debug(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
///
/// [spec]: https://console.spec.whatwg.org/#error
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/error
pub fn error(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn error(this: &mut Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_ref(|state| logger(LogMessage::Error(formatter(&args[..])), state));
Ok(Gc::new(ValueData::Undefined))
}
Expand All @@ -230,7 +229,7 @@ pub fn error(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
///
/// [spec]: https://console.spec.whatwg.org/#info
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/info
pub fn info(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn info(this: &mut Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_ref(|state| logger(LogMessage::Info(formatter(&args[..])), state));
Ok(Gc::new(ValueData::Undefined))
}
Expand All @@ -245,7 +244,7 @@ pub fn info(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
///
/// [spec]: https://console.spec.whatwg.org/#log
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/log
pub fn log(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn log(this: &mut Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_ref(|state| logger(LogMessage::Log(formatter(&args[..])), state));
Ok(Gc::new(ValueData::Undefined))
}
Expand All @@ -260,7 +259,7 @@ pub fn log(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
///
/// [spec]: https://console.spec.whatwg.org/#trace
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/trace
pub fn trace(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn trace(this: &mut Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
if !args.is_empty() {
this.with_internal_state_ref(|state| logger(LogMessage::Log(formatter(&args[..])), state));

Expand All @@ -286,7 +285,7 @@ pub fn trace(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
///
/// [spec]: https://console.spec.whatwg.org/#warn
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/warn
pub fn warn(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn warn(this: &mut Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_ref(|state| logger(LogMessage::Warn(formatter(&args[..])), state));
Ok(Gc::new(ValueData::Undefined))
}
Expand All @@ -301,7 +300,7 @@ pub fn warn(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
///
/// [spec]: https://console.spec.whatwg.org/#count
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/count
pub fn count(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn count(this: &mut Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let label = get_arg_at_index::<String>(args, 0).unwrap_or_else(|| "default".to_string());

this.with_internal_state_mut(|state: &mut ConsoleState| {
Expand All @@ -325,7 +324,7 @@ pub fn count(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
///
/// [spec]: https://console.spec.whatwg.org/#countreset
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/countReset
pub fn count_reset(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn count_reset(this: &mut Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let label = get_arg_at_index::<String>(args, 0).unwrap_or_else(|| "default".to_string());

this.with_internal_state_mut(|state: &mut ConsoleState| {
Expand Down Expand Up @@ -355,7 +354,7 @@ fn system_time_in_ms() -> u128 {
///
/// [spec]: https://console.spec.whatwg.org/#time
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/time
pub fn time(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn time(this: &mut Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let label = get_arg_at_index::<String>(args, 0).unwrap_or_else(|| "default".to_string());

this.with_internal_state_mut(|state: &mut ConsoleState| {
Expand Down Expand Up @@ -383,7 +382,7 @@ pub fn time(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
///
/// [spec]: https://console.spec.whatwg.org/#timelog
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/timeLog
pub fn time_log(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn time_log(this: &mut Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let label = get_arg_at_index::<String>(args, 0).unwrap_or_else(|| "default".to_string());

this.with_internal_state_mut(|state: &mut ConsoleState| {
Expand Down Expand Up @@ -415,7 +414,7 @@ pub fn time_log(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValu
///
/// [spec]: https://console.spec.whatwg.org/#timeend
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/timeEnd
pub fn time_end(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn time_end(this: &mut Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let label = get_arg_at_index::<String>(args, 0).unwrap_or_else(|| "default".to_string());

this.with_internal_state_mut(|state: &mut ConsoleState| {
Expand Down Expand Up @@ -446,7 +445,7 @@ pub fn time_end(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValu
///
/// [spec]: https://console.spec.whatwg.org/#group
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/group
pub fn group(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn group(this: &mut Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let group_label = formatter(args);

this.with_internal_state_mut(|state: &mut ConsoleState| {
Expand All @@ -467,7 +466,7 @@ pub fn group(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
///
/// [spec]: https://console.spec.whatwg.org/#groupend
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/groupEnd
pub fn group_end(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn group_end(this: &mut Value, _: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_mut(|state: &mut ConsoleState| {
state.groups.pop();
});
Expand All @@ -485,7 +484,7 @@ pub fn group_end(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue
///
/// [spec]: https://console.spec.whatwg.org/#dir
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/dir
pub fn dir(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn dir(this: &mut Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_mut(|state: &mut ConsoleState| {
logger(
LogMessage::Info(display_obj(
Expand All @@ -502,25 +501,25 @@ pub fn dir(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
/// Create a new `console` object
pub fn create_constructor(global: &Value) -> Value {
let console = ValueData::new_obj(Some(global));
console.set_field_slice("assert", to_value(assert as NativeFunctionData));
console.set_field_slice("clear", to_value(clear as NativeFunctionData));
console.set_field_slice("debug", to_value(debug as NativeFunctionData));
console.set_field_slice("error", to_value(error as NativeFunctionData));
console.set_field_slice("info", to_value(info as NativeFunctionData));
console.set_field_slice("log", to_value(log as NativeFunctionData));
console.set_field_slice("trace", to_value(trace as NativeFunctionData));
console.set_field_slice("warn", to_value(warn as NativeFunctionData));
console.set_field_slice("exception", to_value(error as NativeFunctionData));
console.set_field_slice("count", to_value(count as NativeFunctionData));
console.set_field_slice("countReset", to_value(count_reset as NativeFunctionData));
console.set_field_slice("group", to_value(group as NativeFunctionData));
console.set_field_slice("groupCollapsed", to_value(group as NativeFunctionData));
console.set_field_slice("groupEnd", to_value(group_end as NativeFunctionData));
console.set_field_slice("time", to_value(time as NativeFunctionData));
console.set_field_slice("timeLog", to_value(time_log as NativeFunctionData));
console.set_field_slice("timeEnd", to_value(time_end as NativeFunctionData));
console.set_field_slice("dir", to_value(dir as NativeFunctionData));
console.set_field_slice("dirxml", to_value(dir as NativeFunctionData));
make_builtin_fn!(assert, named "assert", of console);
make_builtin_fn!(clear, named "clear", of console);
make_builtin_fn!(debug, named "debug", of console);
make_builtin_fn!(error, named "error", of console);
make_builtin_fn!(info, named "info", of console);
make_builtin_fn!(log, named "log", of console);
make_builtin_fn!(trace, named "trace", of console);
make_builtin_fn!(warn, named "warn", of console);
make_builtin_fn!(error, named "exception", of console);
make_builtin_fn!(count, named "count", of console);
make_builtin_fn!(count_reset, named "countReset", of console);
make_builtin_fn!(group, named "group", of console);
make_builtin_fn!(group, named "groupCollapsed", of console);
make_builtin_fn!(group_end , named "groupEnd", of console);
make_builtin_fn!(time, named "time", of console);
make_builtin_fn!(time_log, named "timeLog", of console);
make_builtin_fn!(time_end, named "timeEnd", of console);
make_builtin_fn!(dir, named "dir", of console);
make_builtin_fn!(dir, named "dirxml", of console);
console.set_internal_state(ConsoleState::new());
console
}
Loading

0 comments on commit 19ff051

Please sign in to comment.