Skip to content

Commit

Permalink
Fix failing src tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Sep 18, 2021
1 parent 3bad9b2 commit 3d7d6a9
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 42 deletions.
3 changes: 2 additions & 1 deletion boa/src/builtins/array/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,8 @@ fn array_spread_non_iterable() {
try {
const array2 = [...5];
} catch (err) {
err.name === "TypeError" && err.message === "Not an iterable"
console.log(err.message);
err.name === "TypeError" && err.message === "Value is not callable"
}
"#;
assert_eq!(forward(&mut context, init), "true");
Expand Down
2 changes: 1 addition & 1 deletion boa/src/builtins/date/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,7 @@ impl Date {

// 4. Return ? Invoke(O, "toISOString").
let func = o.get("toISOString", context)?;
o.call(&func, &[], context)
context.call(&func, &o.into(), &[])
}

/// `Date.prototype.toString()`
Expand Down
51 changes: 24 additions & 27 deletions boa/src/builtins/map/map_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,37 +79,34 @@ impl MapIterator {
.as_map_iterator_mut()
.expect("checked that obj was a map iterator");

let mut index = map_iterator.map_next_index;
let item_kind = map_iterator.map_iteration_kind;

if let Some(obj) = map_iterator.iterated_map.take() {
let map = obj.borrow();
let entries = map.as_map_ref().expect("iterator should only iterate maps");
let num_entries = entries.full_len();
while index < num_entries {
let e = entries.get_index(index);
index += 1;
map_iterator.map_next_index = index;
if let Some((key, value)) = e {
let item = match item_kind {
PropertyNameKind::Key => {
Ok(create_iter_result_object(key.clone(), false, context))
}
PropertyNameKind::Value => {
Ok(create_iter_result_object(value.clone(), false, context))
}
PropertyNameKind::KeyAndValue => {
let result = Array::create_array_from_list(
[key.clone(), value.clone()],
context,
);
Ok(create_iter_result_object(result.into(), false, context))
}
};
drop(map);
map_iterator.iterated_map = Some(obj);
return item;
let e = {
let map = obj.borrow();
let entries = map.as_map_ref().expect("iterator should only iterate maps");
let len = entries.full_len();
loop {
let element = entries
.get_index(map_iterator.map_next_index)
.map(|(v, k)| (v.clone(), k.clone()));
map_iterator.map_next_index += 1;
if element.is_some() || map_iterator.map_next_index >= len {
break element;
}
}
};
if let Some((key, value)) = e {
let item = match item_kind {
PropertyNameKind::Key => Ok(create_iter_result_object(key, false, context)),
PropertyNameKind::Value => Ok(create_iter_result_object(value, false, context)),
PropertyNameKind::KeyAndValue => {
let result = Array::create_array_from_list([key, value], context);
Ok(create_iter_result_object(result.into(), false, context))
}
};
map_iterator.iterated_map = Some(obj);
return item;
}
}

Expand Down
2 changes: 1 addition & 1 deletion boa/src/builtins/regexp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl BuiltIn for RegExp {
.method(Self::to_string, "toString", 0)
.method(
Self::r#match,
(WellKnownSymbols::match_(), "[Symbol.match]"),
(WellKnownSymbols::r#match(), "[Symbol.match]"),
1,
)
.method(
Expand Down
8 changes: 4 additions & 4 deletions boa/src/builtins/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ impl String {
let regexp = args.get_or_undefined(0);
if !regexp.is_null_or_undefined() {
// a. Let matcher be ? GetMethod(regexp, @@match).
let matcher = regexp.get_method(context, WellKnownSymbols::match_())?;
let matcher = regexp.get_method(context, WellKnownSymbols::r#match())?;
// b. If matcher is not undefined, then
if !matcher.is_undefined() {
// i. Return ? Call(matcher, regexp, « O »).
Expand All @@ -1112,9 +1112,9 @@ impl String {
let rx = RegExp::create(regexp.clone(), JsValue::undefined(), context)?;

// 5. Return ? Invoke(rx, @@match, « S »).
let obj = rx.as_object().expect("RegExpCreate must return Object");
let func = obj.get(WellKnownSymbols::match_(), context)?;
obj.call(&func, &[JsValue::new(s)], context)
let obj = rx.to_object(context)?;
let func = obj.get(WellKnownSymbols::r#match(), context)?;
context.call(&func, &obj.into(), &[JsValue::new(s)])
}

/// Abstract method `StringPad`.
Expand Down
2 changes: 1 addition & 1 deletion boa/src/builtins/symbol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl BuiltIn for Symbol {
let symbol_has_instance = WellKnownSymbols::has_instance();
let symbol_is_concat_spreadable = WellKnownSymbols::is_concat_spreadable();
let symbol_iterator = WellKnownSymbols::iterator();
let symbol_match = WellKnownSymbols::match_();
let symbol_match = WellKnownSymbols::r#match();
let symbol_match_all = WellKnownSymbols::match_all();
let symbol_replace = WellKnownSymbols::replace();
let symbol_search = WellKnownSymbols::search();
Expand Down
4 changes: 2 additions & 2 deletions boa/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@ impl Context {
args: &[JsValue],
) -> JsResult<JsValue> {
match *f {
JsValue::Object(ref object) => object.call(this, args, self),
_ => self.throw_type_error("not a function"),
JsValue::Object(ref object) if object.is_callable() => object.call(this, args, self),
_ => self.throw_type_error("Value is not callable"),
}
}

Expand Down
8 changes: 4 additions & 4 deletions boa/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct WellKnownSymbols {
has_instance: JsSymbol,
is_concat_spreadable: JsSymbol,
iterator: JsSymbol,
match_: JsSymbol,
r#match: JsSymbol,
match_all: JsSymbol,
replace: JsSymbol,
search: JsSymbol,
Expand Down Expand Up @@ -106,7 +106,7 @@ impl WellKnownSymbols {
has_instance,
is_concat_spreadable,
iterator,
match_,
r#match: match_,
match_all,
replace,
search,
Expand Down Expand Up @@ -161,8 +161,8 @@ impl WellKnownSymbols {
/// A regular expression method that matches the regular expression
/// against a string. Called by the `String.prototype.match` method.
#[inline]
pub fn match_() -> JsSymbol {
WELL_KNOW_SYMBOLS.with(|symbols| symbols.match_.clone())
pub fn r#match() -> JsSymbol {
WELL_KNOW_SYMBOLS.with(|symbols| symbols.r#match.clone())
}

/// The `Symbol.matchAll` well known symbol.
Expand Down
2 changes: 1 addition & 1 deletion boa/src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ impl JsValue {
let o = self.to_object(context)?;

// 2. Return ? O.[[Get]](P, V).
o.get(key, context)
o.__get__(&key.into(), self.clone(), context)
}

/// It determines if the value is a callable function with a `[[Call]]` internal method.
Expand Down

0 comments on commit 3d7d6a9

Please sign in to comment.