Browse Source

Add negative zero handling for `Map.delete` (#2726)

This Pull Request changes the following:

- Add negative zero handling for `Map.delete`
pull/2729/head
raskad 2 years ago
parent
commit
f025e6fc92
  1. 31
      boa_engine/src/builtins/map/mod.rs

31
boa_engine/src/builtins/map/mod.rs

@ -303,7 +303,12 @@ impl Map {
args: &[JsValue], args: &[JsValue],
_: &mut Context<'_>, _: &mut Context<'_>,
) -> JsResult<JsValue> { ) -> JsResult<JsValue> {
const JS_ZERO: &JsValue = &JsValue::Integer(0);
let key = args.get_or_undefined(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. // 1. Let M be the this value.
if let Some(object) = this.as_object() { if let Some(object) = this.as_object() {
@ -334,17 +339,10 @@ impl Map {
/// [spec]: https://tc39.es/ecma262/#sec-map.prototype.get /// [spec]: https://tc39.es/ecma262/#sec-map.prototype.get
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/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> { 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 = args.get_or_undefined(0);
let key = match key { let key = match key.as_number() {
JsValue::Rational(r) => { Some(n) if n.is_zero() => JS_ZERO,
if r.is_zero() {
JS_ZERO
} else {
key
}
}
_ => key, _ => key,
}; };
@ -406,17 +404,10 @@ impl Map {
/// [spec]: https://tc39.es/ecma262/#sec-map.prototype.has /// [spec]: https://tc39.es/ecma262/#sec-map.prototype.has
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/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> { 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 = args.get_or_undefined(0);
let key = match key { let key = match key.as_number() {
JsValue::Rational(r) => { Some(n) if n.is_zero() => JS_ZERO,
if r.is_zero() {
JS_ZERO
} else {
key
}
}
_ => key, _ => key,
}; };

Loading…
Cancel
Save