Skip to content

Commit

Permalink
Merge 6816087 into 9cd9a39
Browse files Browse the repository at this point in the history
  • Loading branch information
Razican authored May 11, 2020
2 parents 9cd9a39 + 6816087 commit 3567431
Show file tree
Hide file tree
Showing 29 changed files with 715 additions and 436 deletions.
23 changes: 11 additions & 12 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"type": "lldb",
"request": "launch",
Expand Down Expand Up @@ -37,16 +36,16 @@
"symbolSearchPath": "https://msdl.microsoft.com/download/symbols"
},
{
"name": "(Windows) Run Test Debugger",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/target/debug/boa-ea5ed1ef3ee0cbe1.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"preLaunchTask": "Cargo Test Build",
}
"name": "(Windows) Run Test Debugger",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/target/debug/boa-ea5ed1ef3ee0cbe1.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"preLaunchTask": "Cargo Test Build",
}
]
}
33 changes: 22 additions & 11 deletions boa/src/builtins/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@ use crate::{
property::Property,
value::{ResultValue, Value, ValueData},
},
exec::Interpreter,
exec::{Executor, Interpreter},
};
use std::{
borrow::Borrow,
cmp::{max, min},
ops::Deref,
};
use std::borrow::Borrow;
use std::cmp::{max, min};
use std::ops::Deref;

/// Creates a new `Array` instance.
pub(crate) fn new_array(interpreter: &Interpreter) -> ResultValue {
pub(crate) fn new_array<E>(interpreter: &E) -> ResultValue
where
E: Executor,
{
let array = Value::new_object(Some(
&interpreter
.get_realm()
.realm()
.environment
.get_global_object()
.expect("Could not get global object"),
Expand All @@ -37,7 +42,7 @@ pub(crate) fn new_array(interpreter: &Interpreter) -> ResultValue {
array.borrow().set_internal_slot(
INSTANCE_PROTOTYPE,
interpreter
.get_realm()
.realm()
.environment
.get_binding_value("Array")
.borrow()
Expand Down Expand Up @@ -529,7 +534,10 @@ pub fn every(this: &mut Value, args: &[Value], interpreter: &mut Interpreter) ->
///
/// [spec]: https://tc39.es/ecma262/#sec-array.prototype.map
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
pub fn map(this: &mut Value, args: &[Value], interpreter: &mut Interpreter) -> ResultValue {
pub fn map<E>(this: &mut Value, args: &[Value], interpreter: &mut E) -> ResultValue
where
E: Executor,
{
if args.is_empty() {
return Err(Value::from(
"missing argument 0 when calling function Array.prototype.map",
Expand All @@ -541,7 +549,7 @@ pub fn map(this: &mut Value, args: &[Value], interpreter: &mut Interpreter) -> R

let length = i32::from(&this.get_field_slice("length"));

let new = new_array(&interpreter)?;
let new = new_array(interpreter)?;

let values: Vec<Value> = (0..length)
.map(|idx| {
Expand Down Expand Up @@ -867,7 +875,10 @@ pub fn slice(this: &mut Value, args: &[Value], interpreter: &mut Interpreter) ->
///
/// [spec]: https://tc39.es/ecma262/#sec-array.prototype.filter
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
pub fn filter(this: &mut Value, args: &[Value], interpreter: &mut Interpreter) -> ResultValue {
pub fn filter<E>(this: &mut Value, args: &[Value], interpreter: &mut E) -> ResultValue
where
E: Executor,
{
if args.is_empty() {
return Err(Value::from(
"missing argument 0 when calling function Array.prototype.filter",
Expand All @@ -879,7 +890,7 @@ pub fn filter(this: &mut Value, args: &[Value], interpreter: &mut Interpreter) -

let length = i32::from(&this.get_field_slice("length"));

let new = new_array(&interpreter)?;
let new = new_array(interpreter)?;

let values = (0..length)
.filter_map(|idx| {
Expand Down
50 changes: 24 additions & 26 deletions boa/src/builtins/array/tests.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::exec::Executor;
use crate::forward;
use crate::realm::Realm;
use crate::{exec::Interpreter, forward, realm::Realm};

#[test]
fn is_array() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
let init = r#"
var empty = [];
var new_arr = new Array();
Expand Down Expand Up @@ -46,7 +44,7 @@ fn is_array() {
fn concat() {
//TODO: array display formatter
// let realm = Realm::create();
// let mut engine = Executor::new(realm);
// let mut engine = Interpreter::new(realm);
// let init = r#"
// var empty = new Array();
// var one = new Array(1);
Expand All @@ -69,7 +67,7 @@ fn concat() {
#[test]
fn join() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
let init = r#"
var empty = [ ];
var one = ["a"];
Expand All @@ -90,7 +88,7 @@ fn join() {
#[test]
fn to_string() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
let init = r#"
var empty = [ ];
var one = ["a"];
Expand All @@ -111,7 +109,7 @@ fn to_string() {
#[test]
fn every() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
// taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every
let init = r#"
var empty = [];
Expand Down Expand Up @@ -156,7 +154,7 @@ fn every() {
#[test]
fn find() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
let init = r#"
function comp(a) {
return a == "a";
Expand All @@ -171,7 +169,7 @@ fn find() {
#[test]
fn find_index() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);

let code = r#"
function comp(item) {
Expand All @@ -197,7 +195,7 @@ fn find_index() {
#[test]
fn push() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
let init = r#"
var arr = [1, 2];
"#;
Expand All @@ -212,7 +210,7 @@ fn push() {
#[test]
fn pop() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
let init = r#"
var empty = [ ];
var one = [1];
Expand All @@ -234,7 +232,7 @@ fn pop() {
#[test]
fn shift() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
let init = r#"
var empty = [ ];
var one = [1];
Expand All @@ -256,7 +254,7 @@ fn shift() {
#[test]
fn unshift() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
let init = r#"
var arr = [3, 4];
"#;
Expand All @@ -271,7 +269,7 @@ fn unshift() {
#[test]
fn reverse() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
let init = r#"
var arr = [1, 2];
var reversed = arr.reverse();
Expand All @@ -286,7 +284,7 @@ fn reverse() {
#[test]
fn index_of() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
let init = r#"
var empty = [ ];
var one = ["a"];
Expand Down Expand Up @@ -350,7 +348,7 @@ fn index_of() {
#[test]
fn last_index_of() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
let init = r#"
var empty = [ ];
var one = ["a"];
Expand Down Expand Up @@ -414,7 +412,7 @@ fn last_index_of() {
#[test]
fn fill() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);

forward(&mut engine, "var a = [1, 2, 3];");
assert_eq!(
Expand Down Expand Up @@ -511,7 +509,7 @@ fn fill() {
#[test]
fn includes_value() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
let init = r#"
var empty = [ ];
var one = ["a"];
Expand Down Expand Up @@ -550,7 +548,7 @@ fn includes_value() {
#[test]
fn map() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);

let js = r#"
var empty = [];
Expand Down Expand Up @@ -611,7 +609,7 @@ fn map() {
#[test]
fn slice() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
let init = r#"
var empty = [ ].slice();
var one = ["a"].slice();
Expand All @@ -635,7 +633,7 @@ fn slice() {
#[test]
fn for_each() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
let init = r#"
var a = [2, 3, 4, 5];
var sum = 0;
Expand All @@ -658,7 +656,7 @@ fn for_each() {
#[test]
fn for_each_push_value() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
let init = r#"
var a = [1, 2, 3, 4];
function callingCallback(item, index, list) {
Expand All @@ -679,7 +677,7 @@ fn for_each_push_value() {
#[test]
fn filter() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);

let js = r#"
var empty = [];
Expand Down Expand Up @@ -746,7 +744,7 @@ fn filter() {
#[test]
fn some() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
let init = r#"
var empty = [];
Expand Down Expand Up @@ -795,7 +793,7 @@ fn some() {
#[test]
fn call_array_constructor_with_one_argument() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
let init = r#"
var empty = new Array(0);
Expand Down
10 changes: 4 additions & 6 deletions boa/src/builtins/boolean/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use super::*;
use crate::exec::Executor;
use crate::realm::Realm;
use crate::{builtins::value::same_value, forward, forward_val};
use crate::{builtins::value::same_value, exec::Interpreter, forward, forward_val, realm::Realm};

#[test]
fn check_boolean_constructor_is_function() {
Expand All @@ -15,7 +13,7 @@ fn check_boolean_constructor_is_function() {
#[test]
fn construct_and_call() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
let init = r#"
var one = new Boolean(1);
var zero = Boolean(0);
Expand All @@ -31,7 +29,7 @@ fn construct_and_call() {
#[test]
fn constructor_gives_true_instance() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
let init = r#"
var trueVal = new Boolean(true);
var trueNum = new Boolean(1);
Expand Down Expand Up @@ -61,7 +59,7 @@ fn constructor_gives_true_instance() {
#[test]
fn instances_have_correct_proto_set() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
let init = r#"
var boolInstance = new Boolean(true);
var boolProto = Boolean.prototype;
Expand Down
4 changes: 2 additions & 2 deletions boa/src/builtins/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl Function {

// Call body should be set before reaching here
let result = match &self.body {
FunctionBody::Ordinary(ref body) => interpreter.run(body),
FunctionBody::Ordinary(ref body) => interpreter.exec(body),
_ => panic!("Ordinary function should not have BuiltIn Function body"),
};

Expand Down Expand Up @@ -251,7 +251,7 @@ impl Function {

// Call body should be set before reaching here
let result = match &self.body {
FunctionBody::Ordinary(ref body) => interpreter.run(body),
FunctionBody::Ordinary(ref body) => interpreter.exec(body),
_ => panic!("Ordinary function should not have BuiltIn Function body"),
};

Expand Down
4 changes: 2 additions & 2 deletions boa/src/builtins/json/tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{exec::Executor, forward, realm::Realm};
use crate::{exec::Interpreter, forward, realm::Realm};

#[test]
fn json_sanity() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let mut engine = Interpreter::new(realm);
assert_eq!(
forward(&mut engine, r#"JSON.parse('{"aaa":"bbb"}').aaa == 'bbb'"#),
"true"
Expand Down
Loading

0 comments on commit 3567431

Please sign in to comment.