Skip to content

Commit

Permalink
New parser fixes tests failing against #281 (#283)
Browse files Browse the repository at this point in the history
* Ported #261 to the new parser

* Fixed some comments

* More comment improvements

* Fixed one error in the parser, and improved error messages

* Fix the `next_if` function

Also, update documentation.

Co-Authored-By: HalidOdat <halidodat@gmail.com>

* Improved one particular error

* Fixed function declaration parsing

Co-authored-by: HalidOdat <halidodat@gmail.com>
  • Loading branch information
Razican and HalidOdat committed Mar 27, 2020
1 parent 326a13e commit 1b57811
Show file tree
Hide file tree
Showing 22 changed files with 259 additions and 205 deletions.
4 changes: 2 additions & 2 deletions boa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ gc = "0.3.3"
gc_derive = "0.3.2"
serde_json = "1.0.48"
rand = "0.7.3"
regex = "1.3.5"
regex = "1.3.6"

# Optional Dependencies
wasm-bindgen = { version = "0.2.59", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
serde = { version = "1.0.105", features = ["derive"], optional = true }

[dev-dependencies]
criterion = "0.3.1"
Expand Down
36 changes: 18 additions & 18 deletions boa/src/builtins/array/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn is_array() {
var new_arr = new Array();
var many = ["a", "b", "c"];
"#;
forward(&mut engine, init);
eprintln!("{}", forward(&mut engine, init));
assert_eq!(forward(&mut engine, "Array.isArray(empty)"), "true");
assert_eq!(forward(&mut engine, "Array.isArray(new_arr)"), "true");
assert_eq!(forward(&mut engine, "Array.isArray(many)"), "true");
Expand Down Expand Up @@ -51,7 +51,7 @@ fn concat() {
// var empty = new Array();
// var one = new Array(1);
// "#;
// forward(&mut engine, init);
// eprintln!("{}", forward(&mut engine, init));
// // Empty ++ Empty
// let ee = forward(&mut engine, "empty.concat(empty)");
// assert_eq!(ee, String::from("[]"));
Expand All @@ -75,7 +75,7 @@ fn join() {
var one = ["a"];
var many = ["a", "b", "c"];
"#;
forward(&mut engine, init);
eprintln!("{}", forward(&mut engine, init));
// Empty
let empty = forward(&mut engine, "empty.join('.')");
assert_eq!(empty, String::from(""));
Expand All @@ -96,7 +96,7 @@ fn to_string() {
var one = ["a"];
var many = ["a", "b", "c"];
"#;
forward(&mut engine, init);
eprintln!("{}", forward(&mut engine, init));
// Empty
let empty = forward(&mut engine, "empty.toString()");
assert_eq!(empty, String::from(""));
Expand Down Expand Up @@ -136,7 +136,7 @@ fn every() {
return elem < 3;
}
"#;
forward(&mut engine, init);
eprintln!("{}", forward(&mut engine, init));
let result = forward(&mut engine, "array.every(callback);");
assert_eq!(result, "true");

Expand All @@ -163,7 +163,7 @@ fn find() {
}
var many = ["a", "b", "c"];
"#;
forward(&mut engine, init);
eprintln!("{}", forward(&mut engine, init));
let found = forward(&mut engine, "many.find(comp)");
assert_eq!(found, String::from("a"));
}
Expand Down Expand Up @@ -201,7 +201,7 @@ fn push() {
let init = r#"
var arr = [1, 2];
"#;
forward(&mut engine, init);
eprintln!("{}", forward(&mut engine, init));

assert_eq!(forward(&mut engine, "arr.push()"), "2");
assert_eq!(forward(&mut engine, "arr.push(3, 4)"), "4");
Expand All @@ -218,7 +218,7 @@ fn pop() {
var one = [1];
var many = [1, 2, 3, 4];
"#;
forward(&mut engine, init);
eprintln!("{}", forward(&mut engine, init));

assert_eq!(
forward(&mut engine, "empty.pop()"),
Expand All @@ -240,7 +240,7 @@ fn shift() {
var one = [1];
var many = [1, 2, 3, 4];
"#;
forward(&mut engine, init);
eprintln!("{}", forward(&mut engine, init));

assert_eq!(
forward(&mut engine, "empty.shift()"),
Expand All @@ -260,7 +260,7 @@ fn unshift() {
let init = r#"
var arr = [3, 4];
"#;
forward(&mut engine, init);
eprintln!("{}", forward(&mut engine, init));

assert_eq!(forward(&mut engine, "arr.unshift()"), "2");
assert_eq!(forward(&mut engine, "arr.unshift(1, 2)"), "4");
Expand All @@ -276,7 +276,7 @@ fn reverse() {
var arr = [1, 2];
var reversed = arr.reverse();
"#;
forward(&mut engine, init);
eprintln!("{}", forward(&mut engine, init));
assert_eq!(forward(&mut engine, "reversed[0]"), "2");
assert_eq!(forward(&mut engine, "reversed[1]"), "1");
assert_eq!(forward(&mut engine, "arr[0]"), "2");
Expand All @@ -293,7 +293,7 @@ fn index_of() {
var many = ["a", "b", "c"];
var duplicates = ["a", "b", "c", "a", "b"];
"#;
forward(&mut engine, init);
eprintln!("{}", forward(&mut engine, init));

// Empty
let empty = forward(&mut engine, "empty.indexOf('a')");
Expand Down Expand Up @@ -357,7 +357,7 @@ fn last_index_of() {
var many = ["a", "b", "c"];
var duplicates = ["a", "b", "c", "a", "b"];
"#;
forward(&mut engine, init);
eprintln!("{}", forward(&mut engine, init));

// Empty
let empty = forward(&mut engine, "empty.lastIndexOf('a')");
Expand Down Expand Up @@ -509,7 +509,7 @@ fn fill() {
}

#[test]
fn inclues_value() {
fn includes_value() {
let realm = Realm::create();
let mut engine = Executor::new(realm);
let init = r#"
Expand All @@ -519,7 +519,7 @@ fn inclues_value() {
var duplicates = ["a", "b", "c", "a", "b"];
var undefined = [undefined];
"#;
forward(&mut engine, init);
eprintln!("{}", forward(&mut engine, init));

// Empty
let empty = forward(&mut engine, "empty.includes('a')");
Expand Down Expand Up @@ -619,7 +619,7 @@ fn slice() {
var many2 = ["a", "b", "c", "d"].slice(2, 3);
var many3 = ["a", "b", "c", "d"].slice(7);
"#;
forward(&mut engine, init);
eprintln!("{}", forward(&mut engine, init));

assert_eq!(forward(&mut engine, "empty.length"), "0");
assert_eq!(forward(&mut engine, "one[0]"), "a");
Expand Down Expand Up @@ -648,7 +648,7 @@ fn for_each() {
}
a.forEach(callingCallback);
"#;
forward(&mut engine, init);
eprintln!("{}", forward(&mut engine, init));

assert_eq!(forward(&mut engine, "sum"), "14");
assert_eq!(forward(&mut engine, "indexSum"), "6");
Expand All @@ -666,7 +666,7 @@ fn for_each_push_value() {
}
a.forEach(callingCallback);
"#;
forward(&mut engine, init);
eprintln!("{}", forward(&mut engine, init));

// [ 1, 2, 3, 4, 2, 4, 6, 8 ]
assert_eq!(forward(&mut engine, "a.length"), "8");
Expand Down
6 changes: 3 additions & 3 deletions boa/src/builtins/boolean/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn construct_and_call() {
var one = new Boolean(1);
var zero = Boolean(0);
"#;
forward(&mut engine, init);
eprintln!("{}", forward(&mut engine, init));
let one = forward_val(&mut engine, "one").unwrap();
let zero = forward_val(&mut engine, "zero").unwrap();

Expand All @@ -39,7 +39,7 @@ fn constructor_gives_true_instance() {
var trueBool = new Boolean(trueVal);
"#;

forward(&mut engine, init);
eprintln!("{}", forward(&mut engine, init));
let true_val = forward_val(&mut engine, "trueVal").expect("value expected");
let true_num = forward_val(&mut engine, "trueNum").expect("value expected");
let true_string = forward_val(&mut engine, "trueString").expect("value expected");
Expand Down Expand Up @@ -67,7 +67,7 @@ fn instances_have_correct_proto_set() {
var boolProto = Boolean.prototype;
"#;

forward(&mut engine, init);
eprintln!("{}", forward(&mut engine, init));
let bool_instance = forward_val(&mut engine, "boolInstance").expect("value expected");
let bool_prototype = forward_val(&mut engine, "boolProto").expect("value expected");

Expand Down
2 changes: 1 addition & 1 deletion boa/src/builtins/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ impl RegularFunction {
}
}

#[derive(Finalize, Clone)]
/// Represents a native javascript function in memory
#[derive(Finalize, Clone)]
pub struct NativeFunction {
/// The fields associated with the function
pub object: Object,
Expand Down
2 changes: 1 addition & 1 deletion boa/src/builtins/function/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn check_arguments_object() {
var val = jason(100, 6);
"#;

forward(&mut engine, init);
eprintln!("{}", forward(&mut engine, init));
let expected_return_val: f64 = 100.0;
let return_val = forward_val(&mut engine, "val").expect("value expected");
assert_eq!(return_val.is_double(), true);
Expand Down

0 comments on commit 1b57811

Please sign in to comment.