Skip to content

Commit

Permalink
Add negative zero handling for Map.delete
Browse files Browse the repository at this point in the history
  • Loading branch information
raskad committed Mar 23, 2023
1 parent 9b53859 commit 638d8c0
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions boa_engine/src/builtins/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,12 @@ impl Map {
args: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
const JS_ZERO: &JsValue = &JsValue::Integer(0);
let key = args.get_or_undefined(0);
let key = match key.as_number() {
Some(n) if n.is_zero() => JS_ZERO,
_ => key,
};

// 1. Let M be the this value.
if let Some(object) = this.as_object() {
Expand Down Expand Up @@ -334,17 +339,10 @@ impl Map {
/// [spec]: https://tc39.es/ecma262/#sec-map.prototype.get
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get
pub(crate) fn get(this: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
const JS_ZERO: &JsValue = &JsValue::Rational(0f64);

const JS_ZERO: &JsValue = &JsValue::Integer(0);
let key = args.get_or_undefined(0);
let key = match key {
JsValue::Rational(r) => {
if r.is_zero() {
JS_ZERO
} else {
key
}
}
let key = match key.as_number() {
Some(n) if n.is_zero() => JS_ZERO,
_ => key,
};

Expand Down Expand Up @@ -406,17 +404,10 @@ impl Map {
/// [spec]: https://tc39.es/ecma262/#sec-map.prototype.has
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has
pub(crate) fn has(this: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
const JS_ZERO: &JsValue = &JsValue::Rational(0f64);

const JS_ZERO: &JsValue = &JsValue::Integer(0);
let key = args.get_or_undefined(0);
let key = match key {
JsValue::Rational(r) => {
if r.is_zero() {
JS_ZERO
} else {
key
}
}
let key = match key.as_number() {
Some(n) if n.is_zero() => JS_ZERO,
_ => key,
};

Expand Down

0 comments on commit 638d8c0

Please sign in to comment.