Skip to content

Commit

Permalink
Merge 5de9828 into 985f68e
Browse files Browse the repository at this point in the history
  • Loading branch information
Razican authored Jul 15, 2020
2 parents 985f68e + 5de9828 commit 4afee8e
Show file tree
Hide file tree
Showing 9 changed files with 546 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "test262"]
path = test262
url = https://github.com/tc39/test262.git
47 changes: 47 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"boa",
"boa_cli",
"boa_wasm",
"tester",
]

# The release profile, used for `cargo build --release`.
Expand Down
30 changes: 16 additions & 14 deletions boa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ pub use crate::{
exec::{Executable, Interpreter},
profiler::BoaProfiler,
realm::Realm,
syntax::{lexer::Lexer, parser::Parser},
syntax::{
lexer::Lexer,
parser::{error::ParseError, Parser},
},
};

fn parser_expr(src: &str) -> Result<StatementList, String> {
Parser::new(src.as_bytes())
.parse_all()
.map_err(|e| format!("Parsing Error: {}", e))
/// Parses a given expression.
fn parser_expr(src: &str) -> Result<StatementList, ParseError> {
Parser::new(src.as_bytes()).parse_all()
}

/// Execute the code using an existing Interpreter
Expand All @@ -61,10 +63,10 @@ pub fn forward(engine: &mut Interpreter, src: &str) -> String {
// Setup executor
let expr = match parser_expr(src) {
Ok(res) => res,
Err(e) => return e,
Err(e) => return format!("Uncaught {}", e),
};
expr.run(engine)
.map_or_else(|e| format!("Error: {}", e), |v| v.to_string())
.map_or_else(|e| format!("Uncaught {}", e), |v| v.to_string())
}

/// Execute the code using an existing Interpreter.
Expand All @@ -75,13 +77,13 @@ pub fn forward(engine: &mut Interpreter, src: &str) -> String {
pub fn forward_val(engine: &mut Interpreter, src: &str) -> ResultValue {
let main_timer = BoaProfiler::global().start_event("Main", "Main");
// Setup executor
let result = match parser_expr(src) {
Ok(expr) => expr.run(engine),
Err(e) => {
eprintln!("{}", e);
std::process::exit(1);
}
};
let result = parser_expr(src)
.map_err(|e| {
engine
.throw_syntax_error(e.to_string())
.expect_err("interpreter.throw_syntax_error() did not return an error")
})
.and_then(|expr| expr.run(engine));

// The main_timer needs to be dropped before the BoaProfiler is.
drop(main_timer);
Expand Down
4 changes: 2 additions & 2 deletions boa/src/syntax/parser/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ macro_rules! expression { ($name:ident, $lower:ident, [$( $op:path ),*], [$( $lo
TokenKind::Punctuator(op) if $( op == $op )||* => {
let _ = cursor.next().expect("token disappeared");
lhs = BinOp::new(
op.as_binop().expect("Could not get binary operation."),
op.as_binop().unwrap_or_else(|| panic!("could not get binary operation for {:?}", op)),
lhs,
$lower::new($( self.$low_param ),*).parse(cursor)?
).into();
}
TokenKind::Keyword(op) if $( op == $op )||* => {
let _ = cursor.next().expect("token disappeared");
lhs = BinOp::new(
op.as_binop().expect("Could not get binary operation."),
op.as_binop().unwrap_or_else(|| panic!("could not get binary operation for {:?}", op)),
lhs,
$lower::new($( self.$low_param ),*).parse(cursor)?
).into();
Expand Down
1 change: 1 addition & 0 deletions boa/src/syntax/parser/expression/primary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ where
fn parse(self, cursor: &mut Cursor<R>) -> ParseResult {
let _timer = BoaProfiler::global().start_event("PrimaryExpression", "Parsing");

cursor.skip_line_terminators()?;
let tok = cursor.next()?.ok_or(ParseError::AbruptEnd)?;

match tok.kind() {
Expand Down
1 change: 1 addition & 0 deletions test262
Submodule test262 added at 28ec03
17 changes: 17 additions & 0 deletions tester/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "tester"
version = "0.1.0"
authors = ["Iban Eguia Moraza <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Boa = { path = "../boa" }
structopt = "0.3.15"
serde = "1.0.114"
serde_yaml = "0.8.13"
bitflags = "1.2.1"
regex = "1.3.9"
once_cell = "1.4.0"
rayon = "1.3.1"
Loading

0 comments on commit 4afee8e

Please sign in to comment.