Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Generic JsResult<R> in context.throw_ methods #1734

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions boa/src/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl JsBigInt {
let y = if let Some(y) = y.inner.to_biguint() {
y
} else {
return Err(context.construct_range_error("BigInt negative exponent"));
return context.throw_range_error("BigInt negative exponent");
};

let num_bits = (x.inner.bits() as f64
Expand All @@ -175,7 +175,7 @@ impl JsBigInt {
+ 1f64;

if num_bits > 1_000_000_000f64 {
return Err(context.construct_range_error("Maximum BigInt size exceeded"));
return context.throw_range_error("Maximum BigInt size exceeded");
}

Ok(Self::new(x.inner.as_ref().clone().pow(y)))
Expand All @@ -192,7 +192,7 @@ impl JsBigInt {

Ok(Self::new(inner))
} else {
Err(context.construct_range_error("Maximum BigInt size exceeded"))
context.throw_range_error("Maximum BigInt size exceeded")
}
}

Expand All @@ -207,7 +207,7 @@ impl JsBigInt {

Ok(Self::new(inner))
} else {
Err(context.construct_range_error("Maximum BigInt size exceeded"))
context.throw_range_error("Maximum BigInt size exceeded")
}
}

Expand Down
10 changes: 5 additions & 5 deletions boa/src/builtins/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl Array {
let int_len = len.to_u32(context).unwrap();
// ii. If SameValueZero(intLen, len) is false, throw a RangeError exception.
if !JsValue::same_value_zero(&int_len.into(), len) {
return Err(context.construct_range_error("invalid array length"));
return context.throw_range_error("invalid array length");
}
int_len
};
Expand Down Expand Up @@ -210,7 +210,7 @@ impl Array {
) -> JsResult<JsObject> {
// 1. If length > 2^32 - 1, throw a RangeError exception.
if length > 2usize.pow(32) - 1 {
return Err(context.construct_range_error("array exceeded max size"));
return context.throw_range_error("array exceeded max size");
}
// 7. Return A.
// 2. If proto is not present, set proto to %Array.prototype%.
Expand Down Expand Up @@ -365,7 +365,7 @@ impl Array {
.unwrap(),
)
} else {
Err(context.construct_type_error("Symbol.species must be a constructor"))
context.throw_type_error("Symbol.species must be a constructor")
}
}

Expand Down Expand Up @@ -1669,8 +1669,8 @@ impl Array {
} else {
// 1. If targetIndex >= 2^53 - 1, throw a TypeError exception
if target_index >= Number::MAX_SAFE_INTEGER as u64 {
return Err(context
.construct_type_error("Target index exceeded max safe integer value"));
return context
.throw_type_error("Target index exceeded max safe integer value");
}

// 2. Perform ? CreateDataPropertyOrThrow(target, targetIndex, element)
Expand Down
2 changes: 1 addition & 1 deletion boa/src/builtins/array_buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ impl ArrayBuffer {
let src_block = if let Some(b) = &self.array_buffer_data {
b
} else {
return Err(context.construct_syntax_error("Cannot clone detached array buffer"));
return context.throw_syntax_error("Cannot clone detached array buffer");
};

{
Expand Down
4 changes: 1 addition & 3 deletions boa/src/builtins/intl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ impl Intl {
let k_value = o.get(k, context)?;
// ii. If Type(kValue) is not String or Object, throw a TypeError exception.
if !(k_value.is_object() || k_value.is_string()) {
return Err(context
.throw_type_error("locale should be a String or Object")
.unwrap_err());
return context.throw_type_error("locale should be a String or Object");
}
// iii. If Type(kValue) is Object and kValue has an [[InitializedLocale]] internal slot, then
// TODO: handle checks for InitializedLocale internal slot (there should be an if statement here)
Expand Down
2 changes: 1 addition & 1 deletion boa/src/builtins/iterable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl JsValue {

// 4. If Type(iterator) is not Object, throw a TypeError exception.
if !iterator.is_object() {
return Err(context.construct_type_error("the iterator is not an object"));
return context.throw_type_error("the iterator is not an object");
}

// 5. Let nextMethod be ? GetV(iterator, "next").
Expand Down
6 changes: 3 additions & 3 deletions boa/src/builtins/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ impl Json {

// 10. If Type(value) is BigInt, throw a TypeError exception.
if value.is_bigint() {
return Err(context.construct_type_error("cannot serialize bigint to JSON"));
return context.throw_type_error("cannot serialize bigint to JSON");
}

// 11. If Type(value) is Object and IsCallable(value) is false, then
Expand Down Expand Up @@ -531,7 +531,7 @@ impl Json {
// 1. If state.[[Stack]] contains value, throw a TypeError exception because the structure is cyclical.
let limiter = RecursionLimiter::new(value);
if limiter.live {
return Err(context.construct_type_error("cyclic object value"));
return context.throw_type_error("cyclic object value");
}

// 2. Append value to state.[[Stack]].
Expand Down Expand Up @@ -644,7 +644,7 @@ impl Json {
// 1. If state.[[Stack]] contains value, throw a TypeError exception because the structure is cyclical.
let limiter = RecursionLimiter::new(value);
if limiter.live {
return Err(context.construct_type_error("cyclic object value"));
return context.throw_type_error("cyclic object value");
}

// 2. Append value to state.[[Stack]].
Expand Down
9 changes: 4 additions & 5 deletions boa/src/builtins/number/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ impl Number {
let this_str_num = if let Some(precision) = precision {
// 5. If f < 0 or f > 100, throw a RangeError exception.
if !(0..=100).contains(&precision) {
return Err(context
.construct_range_error("toExponential() argument must be between 0 and 100"));
return context
.throw_range_error("toExponential() argument must be between 0 and 100");
}
f64_to_exponential_with_precision(this_num, precision as usize)
} else {
Expand Down Expand Up @@ -256,9 +256,8 @@ impl Number {
0..=100 => n.to_integer(context)? as usize,
// 4, 5. If f < 0 or f > 100, throw a RangeError exception.
_ => {
return Err(context.construct_range_error(
"toFixed() digits argument must be between 0 and 100",
))
return context
.throw_range_error("toFixed() digits argument must be between 0 and 100")
}
},
// 3. If fractionDigits is undefined, then f is 0.
Expand Down
33 changes: 13 additions & 20 deletions boa/src/builtins/regexp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ impl RegExp {
// 14. Set obj.[[RegExpMatcher]] to the Abstract Closure that evaluates parseResult by applying the semantics provided in 22.2.2 using patternCharacters as the pattern's List of SourceCharacter values and F as the flag parameters.
let matcher = match Regex::with_flags(&p, f.as_ref()) {
Err(error) => {
return Err(context
.construct_syntax_error(format!("failed to create matcher: {}", error.text)));
return context
.throw_syntax_error(format!("failed to create matcher: {}", error.text));
}
Ok(val) => val,
};
Expand Down Expand Up @@ -779,9 +779,7 @@ impl RegExp {

// b. If Type(result) is neither Object nor Null, throw a TypeError exception.
if !result.is_object() && !result.is_null() {
return Err(
context.construct_type_error("regexp exec returned neither object nor null")
);
return context.throw_type_error("regexp exec returned neither object nor null");
}

// c. Return result.
Expand All @@ -790,7 +788,7 @@ impl RegExp {

// 5. Perform ? RequireInternalSlot(R, [[RegExpMatcher]]).
if !this.is_regexp() {
return Err(context.construct_type_error("RegExpExec called with invalid value"));
return context.throw_type_error("RegExpExec called with invalid value");
}

// 6. Return ? RegExpBuiltinExec(R, S).
Expand All @@ -814,9 +812,7 @@ impl RegExp {
if let Some(rx) = obj.as_regexp() {
rx.clone()
} else {
return Err(
context.construct_type_error("RegExpBuiltinExec called with invalid value")
);
return context.throw_type_error("RegExpBuiltinExec called with invalid value");
}
};

Expand Down Expand Up @@ -870,9 +866,8 @@ impl RegExp {
) {
Ok(s) => s.len(),
Err(_) => {
return Err(context.construct_type_error(
"Failed to get byte index from utf16 encoded string",
))
return context
.throw_type_error("Failed to get byte index from utf16 encoded string")
}
};
let r = matcher.find_from(&input, last_byte_index).next();
Expand Down Expand Up @@ -1046,9 +1041,8 @@ impl RegExp {
let rx = if let Some(rx) = this.as_object() {
rx
} else {
return Err(context.construct_type_error(
"RegExp.prototype.match method called on incompatible value",
));
return context
.throw_type_error("RegExp.prototype.match method called on incompatible value");
};

// 3. Let S be ? ToString(string).
Expand Down Expand Up @@ -1495,9 +1489,9 @@ impl RegExp {
let rx = if let Some(rx) = this.as_object() {
rx
} else {
return Err(context.construct_type_error(
return context.throw_type_error(
"RegExp.prototype[Symbol.search] method called on incompatible value",
));
);
};

// 3. Let S be ? ToString(string).
Expand Down Expand Up @@ -1557,9 +1551,8 @@ impl RegExp {
let rx = if let Some(rx) = this.as_object() {
rx
} else {
return Err(context.construct_type_error(
"RegExp.prototype.split method called on incompatible value",
));
return context
.throw_type_error("RegExp.prototype.split method called on incompatible value");
};

// 3. Let S be ? ToString(string).
Expand Down