Browse Source

fix(boa): bitwise not operation (#1384)

pull/1438/head
neeldug 3 years ago committed by GitHub
parent
commit
330839d972
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      boa/src/bigint.rs
  2. 6
      boa/src/builtins/number/mod.rs
  3. 17
      boa/src/syntax/ast/node/operator/unary_op/mod.rs

5
boa/src/bigint.rs

@ -260,6 +260,11 @@ impl JsBigInt {
Self::new(x.as_inner().neg())
}
#[inline]
pub fn not(x: &Self) -> Self {
Self::new(!x.as_inner())
}
#[inline]
pub(crate) fn as_inner(&self) -> &RawBigInt {
&self.inner

6
boa/src/builtins/number/mod.rs

@ -1094,4 +1094,10 @@ impl Number {
}
(x < y).into()
}
#[inline]
pub(crate) fn not(x: f64) -> i32 {
let x = f64_to_int32(x);
!x
}
}

17
boa/src/syntax/ast/node/operator/unary_op/mod.rs

@ -2,10 +2,12 @@ use crate::{
exec::Executable,
gc::{Finalize, Trace},
syntax::ast::{node::Node, op},
Context, Result, Value,
Context, JsBigInt, Result, Value,
};
use std::fmt;
use crate::builtins::Number;
use crate::value::Numeric;
#[cfg(feature = "deser")]
use serde::{Deserialize, Serialize};
@ -76,13 +78,12 @@ impl Executable for UnaryOp {
}
op::UnaryOp::Not => self.target().run(context)?.not(context)?.into(),
op::UnaryOp::Tilde => {
let num_v_a = self.target().run(context)?.to_number(context)?;
Value::from(if num_v_a.is_nan() {
-1
} else {
// TODO: this is not spec compliant.
!(num_v_a as i32)
})
let expr = self.target().run(context)?;
let old_v = expr.to_numeric(context)?;
match old_v {
Numeric::Number(x) => Value::from(Number::not(x)),
Numeric::BigInt(x) => Value::from(JsBigInt::not(&x)),
}
}
op::UnaryOp::Void => {
self.target().run(context)?;

Loading…
Cancel
Save