Skip to content

Commit

Permalink
Merge f34a290 into 24f4155
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 authored Sep 16, 2022
2 parents 24f4155 + f34a290 commit f7ecaa4
Show file tree
Hide file tree
Showing 94 changed files with 3,314 additions and 2,004 deletions.
229 changes: 120 additions & 109 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions boa_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ impl Opt {
#[derive(Debug, Clone, ArgEnum)]
enum DumpFormat {
/// The different types of format available for dumping.
///
// NOTE: This can easily support other formats just by
// adding a field to this enum and adding the necessary
// implementation. Example: Toml, Html, etc.
Expand Down Expand Up @@ -198,7 +197,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 +244,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
1 change: 1 addition & 0 deletions boa_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ unicode-normalization = "0.1.21"
dyn-clone = "1.0.9"
once_cell = "1.14.0"
tap = "1.0.1"
thiserror = "1.0.35"
icu_locale_canonicalizer = { version = "0.6.0", features = ["serde"], optional = true }
icu_locid = { version = "0.6.0", features = ["serde"], optional = true }
icu_datetime = { version = "0.6.0", features = ["serde"], optional = true }
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 f7ecaa4

Please sign in to comment.