Skip to content

Commit

Permalink
Merge f54a538 into 2f9eec0
Browse files Browse the repository at this point in the history
  • Loading branch information
Razican authored Jul 17, 2020
2 parents 2f9eec0 + f54a538 commit bedb1b0
Show file tree
Hide file tree
Showing 16 changed files with 806 additions and 41 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
100 changes: 84 additions & 16 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
2 changes: 1 addition & 1 deletion boa/src/builtins/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ impl String {
// Push the whole string being examined
results.push(Value::from(primitive_val.to_string()));

let result = ctx.call(&replace_object, this, &results).unwrap();
let result = ctx.call(&replace_object, this, &results)?;

ctx.to_string(&result)?.to_string()
}
Expand Down
6 changes: 2 additions & 4 deletions boa/src/exec/call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ impl Executable for Call {
let (this, func) = match self.expr() {
Node::GetConstField(ref get_const_field) => {
let mut obj = get_const_field.obj().run(interpreter)?;
if obj.get_type() != Type::Object || obj.get_type() != Type::Symbol {
obj = interpreter
.to_object(&obj)
.expect("failed to convert to object");
if obj.get_type() != Type::Object {
obj = interpreter.to_object(&obj)?;
}
(obj.clone(), obj.get_field(get_const_field.field()))
}
Expand Down
5 changes: 2 additions & 3 deletions boa/src/exec/field/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ use crate::{
impl Executable for GetConstField {
fn run(&self, interpreter: &mut Interpreter) -> ResultValue {
let mut obj = self.obj().run(interpreter)?;
if obj.get_type() != Type::Object || obj.get_type() != Type::Symbol {
if obj.get_type() != Type::Object {
obj = interpreter.to_object(&obj)?;
}

Ok(obj.get_field(self.field()))
}
}

impl Executable for GetField {
fn run(&self, interpreter: &mut Interpreter) -> ResultValue {
let mut obj = self.obj().run(interpreter)?;
if obj.get_type() != Type::Object || obj.get_type() != Type::Symbol {
if obj.get_type() != Type::Object {
obj = interpreter.to_object(&obj)?;
}
let field = self.field().run(interpreter)?;
Expand Down
37 changes: 22 additions & 15 deletions boa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,32 @@ 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 the given source code.
///
/// It will return either the statement list AST node for the code, or a parsing error if something
/// goes wrong.
#[inline]
pub fn parse(src: &str) -> Result<StatementList, ParseError> {
Parser::new(src.as_bytes()).parse_all()
}

/// Execute the code using an existing Interpreter
///
/// The str is consumed and the state of the Interpreter is changed
pub fn forward(engine: &mut Interpreter, src: &str) -> String {
// Setup executor
let expr = match parser_expr(src) {
let expr = match parse(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 +82,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 = parse(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 boa_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ categories = ["command-line-utilities"]
license = "Unlicense/MIT"
exclude = ["../.vscode/*", "../Dockerfile", "../Makefile", "../.editorConfig"]
edition = "2018"
default-run = "boa"

[dependencies]
Boa = { path = "../boa", features = ["serde"] }
Expand Down
1 change: 1 addition & 0 deletions test262
Submodule test262 added at 28ec03
Loading

0 comments on commit bedb1b0

Please sign in to comment.