Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to reassign negative zero object property to positive zero #27784

Closed
dlevs opened this issue May 20, 2019 · 3 comments
Closed

Unable to reassign negative zero object property to positive zero #27784

dlevs opened this issue May 20, 2019 · 3 comments
Labels
confirmed-bug Issues with confirmed bugs. v8 engine Issues and PRs related to the V8 dependency.

Comments

@dlevs
Copy link

dlevs commented May 20, 2019

  • Version: v12.2.0
  • Platform: Darwin Kernel Version 18.5.0: Mon Mar 11 20:40:32 PDT 2019; root:xnu-4903.251.3~3/RELEASE_X86_64 x86_64

Some object properties cannot be assigned to 0 if they currently have a value of -0, without being first set to a non-zero value.

const duration = {
	years: -0,
	months: -0,
	weeks: -0,
	days: -0,
	hours: -0,
	minutes: -0,
	seconds: -0,
	milliseconds: -0
};

Object.keys(duration).forEach(key => {
	duration[key] = 0;
});

console.log(duration);
/* ✅ For node v11.11.0, all values on `duration` are logged as positive 0.
 * ❌ For node v12.2.0, the logged output is consistently as follows:
 * {
 *   years: 0,
 *   months: 0,
 *   weeks: 0,
 *   days: -0,
 *   hours: -0,
 *   minutes: -0,
 *   seconds: -0,
 *   milliseconds: -0
 * }
 */

// Expected behaviour can be achieved by changing the value to a non-zero value first:
Object.keys(duration).forEach(key => {
	duration[key] = 1;
	duration[key] = 0;
});

console.log(duration);
// ✅ Correct for both v11.11.0 and v12.2.0
@addaleax addaleax added confirmed-bug Issues with confirmed bugs. v8 engine Issues and PRs related to the V8 dependency. labels May 20, 2019
@addaleax
Copy link
Member

/cc @nodejs/v8

@devsnek
Copy link
Member

devsnek commented May 20, 2019

doesn't reproduce on V8 7.5, so it seems like there is a fix of some sort

@targos
Copy link
Member

targos commented May 21, 2019

Fix in #27792

BridgeAR pushed a commit that referenced this issue May 22, 2019
Original commit message:

    [ic] Fix handling of +0/-0 when constant field tracking is enabled

    ... and ensure that runtime behaviour is in sync with the IC code.

    Bug: chromium:950747, v8:9113
    Change-Id: Ied66c9514cbe3a4d75fc71d4fc3b19ea1538f9b2
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1561319
    Reviewed-by: Toon Verwaest <verwaest@chromium.org>
    Commit-Queue: Igor Sheludko <ishell@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#60768}

PR-URL: #27792
Fixes: #27784
Refs: v8/v8@94c87fe
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. v8 engine Issues and PRs related to the V8 dependency.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants