Skip to content

Commit

Permalink
Merge 4d84f7d into ff151cc
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 authored Sep 15, 2022
2 parents ff151cc + 4d84f7d commit 1b283bd
Show file tree
Hide file tree
Showing 88 changed files with 2,729 additions and 1,808 deletions.
8 changes: 2 additions & 6 deletions boa_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ pub fn main() -> Result<(), io::Error> {
} else {
match context.eval(&buffer) {
Ok(v) => println!("{}", v.display()),
Err(v) => eprintln!("Uncaught {}", v.display()),
Err(v) => eprintln!("Uncaught {v}"),
}
}
}
Expand Down Expand Up @@ -245,11 +245,7 @@ pub fn main() -> Result<(), io::Error> {
match context.eval(line.trim_end()) {
Ok(v) => println!("{}", v.display()),
Err(v) => {
eprintln!(
"{}: {}",
"Uncaught".red(),
v.display().to_string().red()
);
eprintln!("{}: {}", "Uncaught".red(), v.to_string().red());
}
}
}
Expand Down
24 changes: 16 additions & 8 deletions boa_engine/src/bigint.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! This module implements the JavaScript bigint primitive rust type.
use crate::{builtins::Number, Context, JsValue};
use crate::{builtins::Number, error::JsNativeError, JsResult};
use num_integer::Integer;
use num_traits::{pow::Pow, FromPrimitive, One, ToPrimitive, Zero};
use std::{
Expand Down Expand Up @@ -148,11 +148,13 @@ impl JsBigInt {
}

#[inline]
pub fn pow(x: &Self, y: &Self, context: &mut Context) -> Result<Self, JsValue> {
pub fn pow(x: &Self, y: &Self) -> JsResult<Self> {
let y = if let Some(y) = y.inner.to_biguint() {
y
} else {
return context.throw_range_error("BigInt negative exponent");
return Err(JsNativeError::range()
.with_message("BigInt negative exponent")
.into());
};

let num_bits = (x.inner.bits() as f64
Expand All @@ -161,14 +163,16 @@ impl JsBigInt {
+ 1f64;

if num_bits > 1_000_000_000f64 {
return context.throw_range_error("Maximum BigInt size exceeded");
return Err(JsNativeError::range()
.with_message("Maximum BigInt size exceeded")
.into());
}

Ok(Self::new(x.inner.as_ref().clone().pow(y)))
}

#[inline]
pub fn shift_right(x: &Self, y: &Self, context: &mut Context) -> Result<Self, JsValue> {
pub fn shift_right(x: &Self, y: &Self) -> JsResult<Self> {
if let Some(n) = y.inner.to_i32() {
let inner = if n > 0 {
x.inner.as_ref().clone().shr(n as usize)
Expand All @@ -178,12 +182,14 @@ impl JsBigInt {

Ok(Self::new(inner))
} else {
context.throw_range_error("Maximum BigInt size exceeded")
Err(JsNativeError::range()
.with_message("Maximum BigInt size exceeded")
.into())
}
}

#[inline]
pub fn shift_left(x: &Self, y: &Self, context: &mut Context) -> Result<Self, JsValue> {
pub fn shift_left(x: &Self, y: &Self) -> JsResult<Self> {
if let Some(n) = y.inner.to_i32() {
let inner = if n > 0 {
x.inner.as_ref().clone().shl(n as usize)
Expand All @@ -193,7 +199,9 @@ impl JsBigInt {

Ok(Self::new(inner))
} else {
context.throw_range_error("Maximum BigInt size exceeded")
Err(JsNativeError::range()
.with_message("Maximum BigInt size exceeded")
.into())
}
}

Expand Down
11 changes: 7 additions & 4 deletions boa_engine/src/builtins/array/array_iterator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{
builtins::{function::make_builtin_fn, iterable::create_iter_result_object, Array, JsValue},
error::JsNativeError,
object::{JsObject, ObjectData},
property::{PropertyDescriptor, PropertyNameKind},
symbol::WellKnownSymbols,
Expand Down Expand Up @@ -72,7 +73,7 @@ impl ArrayIterator {
let array_iterator = array_iterator
.as_mut()
.and_then(|obj| obj.as_array_iterator_mut())
.ok_or_else(|| context.construct_type_error("`this` is not an ArrayIterator"))?;
.ok_or_else(|| JsNativeError::typ().with_message("`this` is not an ArrayIterator"))?;
let index = array_iterator.next_index;
if array_iterator.done {
return Ok(create_iter_result_object(
Expand All @@ -84,9 +85,11 @@ impl ArrayIterator {

let len = if let Some(f) = array_iterator.array.borrow().as_typed_array() {
if f.is_detached() {
return context.throw_type_error(
"Cannot get value from typed array that has a detached array buffer",
);
return Err(JsNativeError::typ()
.with_message(
"Cannot get value from typed array that has a detached array buffer",
)
.into());
}

f.array_length()
Expand Down
Loading

0 comments on commit 1b283bd

Please sign in to comment.