Skip to content

Commit

Permalink
Merge 5793a23 into 8fd5533
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat authored Aug 9, 2020
2 parents 8fd5533 + 5793a23 commit 3e8dd03
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
8 changes: 0 additions & 8 deletions boa/src/builtins/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,6 @@ impl Value {
Self::Symbol(RcSymbol::from(symbol))
}

/// Helper function to convert the `Value` to a number and compute its power.
pub fn as_num_to_power(&self, other: Self) -> Self {
match (self, other) {
(Self::BigInt(ref a), Self::BigInt(ref b)) => Self::bigint(a.as_inner().clone().pow(b)),
(a, b) => Self::rational(a.to_number().powf(b.to_number())),
}
}

/// Returns a new empty object
pub fn new_object(global: Option<&Value>) -> Self {
let _timer = BoaProfiler::global().start_event("new_object", "value");
Expand Down
38 changes: 38 additions & 0 deletions boa/src/builtins/value/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,44 @@ fn bitand_rational_and_rational() {
assert_eq!(value, 255);
}

#[test]
fn pow_number_and_number() {
let realm = Realm::create();
let mut engine = Interpreter::new(realm);

let value = forward_val(&mut engine, "3 ** 3").unwrap();
let value = engine.to_number(&value).unwrap();
assert_eq!(value, 27.0);
}

#[test]
fn pow_number_and_string() {
let realm = Realm::create();
let mut engine = Interpreter::new(realm);

let value = forward_val(&mut engine, "3 ** 'Hello'").unwrap();
let value = engine.to_number(&value).unwrap();
assert!(value.is_nan());
}

#[test]
fn assign_pow_number_and_string() {
let realm = Realm::create();
let mut engine = Interpreter::new(realm);

let value = forward_val(
&mut engine,
r"
let a = 3;
a **= 'Hello'
a
",
)
.unwrap();
let value = engine.to_number(&value).unwrap();
assert!(value.is_nan());
}

#[test]
fn display_string() {
let s = String::from("Hello");
Expand Down

0 comments on commit 3e8dd03

Please sign in to comment.