Skip to content

Commit

Permalink
Fix internal vm tests (#1718)
Browse files Browse the repository at this point in the history
This PR fixes some vm implementation code. All our internal tests should now pass with the vm enabled.

There are only a few (~100) 262 tests left that currently break with the vm, that previously worked.
  • Loading branch information
raskad committed Dec 11, 2021
1 parent c673714 commit d8a71bc
Show file tree
Hide file tree
Showing 15 changed files with 1,149 additions and 465 deletions.
13 changes: 12 additions & 1 deletion boa/src/builtins/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ impl fmt::Debug for Function {

impl Function {
// Adds the final rest parameters to the Environment as an array
#[cfg(not(feature = "vm"))]
pub(crate) fn add_rest_param(
param: &FormalParameter,
index: usize,
Expand Down Expand Up @@ -240,6 +241,7 @@ impl Function {
}

// Adds an argument to the environment
#[cfg(not(feature = "vm"))]
pub(crate) fn add_arguments_to_environment(
param: &FormalParameter,
value: JsValue,
Expand Down Expand Up @@ -580,7 +582,16 @@ impl BuiltInFunctionObject {
.into())
}
}

#[cfg(feature = "vm")]
(Function::VmOrdinary { .. }, Some(name)) if name.is_empty() => {
Ok("[Function (anonymous)]".into())
}
#[cfg(feature = "vm")]
(Function::VmOrdinary { .. }, Some(name)) => {
Ok(format!("[Function: {}]", &name).into())
}
#[cfg(feature = "vm")]
(Function::VmOrdinary { .. }, None) => Ok("[Function (anonymous)]".into()),
_ => Ok("TODO".into()),
}
}
Expand Down
45 changes: 29 additions & 16 deletions boa/src/builtins/iterable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,30 +230,43 @@ impl IteratorRecord {
completion: JsResult<JsValue>,
context: &mut Context,
) -> JsResult<JsValue> {
let mut inner_result = self.iterator_object.get_field("return", context);
// 1. Assert: Type(iteratorRecord.[[Iterator]]) is Object.
// 2. Let iterator be iteratorRecord.[[Iterator]].
// 3. Let innerResult be GetMethod(iterator, "return").
let inner_result = self.iterator_object.get_method("return", context);
//let mut inner_result = self.iterator_object.get_field("return", context);

// 5
// 4. If innerResult.[[Type]] is normal, then
if let Ok(inner_value) = inner_result {
// b
if inner_value.is_undefined() {
return completion;
// a. Let return be innerResult.[[Value]].
match inner_value {
// b. If return is undefined, return Completion(completion).
None => return completion,
// c. Set innerResult to Call(return, iterator).
Some(value) => {
let inner_result = value.call(&self.iterator_object, &[], context);

// 5. If completion.[[Type]] is throw, return Completion(completion).
let completion = completion?;

// 6. If innerResult.[[Type]] is throw, return Completion(innerResult).
inner_result?;

// 7. If Type(innerResult.[[Value]]) is not Object, throw a TypeError exception.
// 8. Return Completion(completion).
return Ok(completion);
}
}
// c
inner_result = context.call(&inner_value, &self.iterator_object, &[]);
}

// 6
// 5. If completion.[[Type]] is throw, return Completion(completion).
let completion = completion?;

// 7
let inner_result = inner_result?;

// 8
if !inner_result.is_object() {
return context.throw_type_error("`return` method of iterator didn't return an Object");
}
// 6. If innerResult.[[Type]] is throw, return Completion(innerResult).
inner_result?;

// 9
// 7. If Type(innerResult.[[Value]]) is not Object, throw a TypeError exception.
// 8. Return Completion(completion).
Ok(completion)
}
}
Expand Down
2 changes: 2 additions & 0 deletions boa/src/builtins/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ impl Json {
// 9. Let unfiltered be completion.[[Value]].
// 10. Assert: unfiltered is either a String, Number, Boolean, Null, or an Object that is defined by either an ArrayLiteral or an ObjectLiteral.
let unfiltered = context.eval(script_string.as_bytes())?;
#[cfg(feature = "vm")]
context.vm.pop_frame();

// 11. If IsCallable(reviver) is true, then
if let Some(obj) = args.get_or_undefined(1).as_callable() {
Expand Down
4 changes: 0 additions & 4 deletions boa/src/builtins/regexp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ pub struct RegExp {
/// Regex matcher.
matcher: Regex,

/// Update last_index, set if global or sticky flags are set.
use_last_index: bool,

/// Flag 's' - dot matches newline characters.
dot_all: bool,

Expand Down Expand Up @@ -340,7 +337,6 @@ impl RegExp {

let regexp = RegExp {
matcher,
use_last_index: global || sticky,
dot_all,
global,
ignore_case,
Expand Down
Loading

0 comments on commit d8a71bc

Please sign in to comment.