Infinity conversion discrepancy between Node versions (14 vs 16)

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

XMLWordPrintableJSON

      How frequently does the bug occur?

      Always

      Description

      While I was upgrading to the newer Node version, I found an interesting but minor bug.

      When using Node 14, Infinity will be converted into -9223372036854776000.
      When using Node 16, Infinity will be converted into 9223372036854776000.

      I haven't experimented with whether the behavior also differs also inside different platforms, e.g. iOS vs Android.

      This happens with both Realm 10 & 11.

      Demo:

      Unable to find source-code formatter for language: ts. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      import Realm from "realm";
      
      describe("Realm's corner-cases", () => {
        it("Int field accepts Infinity", async () => {
          const ExampleSchema = {
            name: "Example",
            properties: {
              id: "int",
              number: "int",
            },
            primaryKey: "id",
          };
      
          const realm = await Realm.open({
            inMemory: true,
            schema: [ExampleSchema],
          });
      
          let obj;
          realm.write(() => {
            obj = realm.create("Example", {
              id: 1,
              number: Infinity,
            });
          });
      
          // passes with Node >= 16
          expect(obj.number).toBe(9223372036854776000);
          // passes with Node 14
          expect(obj.number).toBe(-9223372036854776000);
        });
      });
      
      

      Note that this could be also Node's breaking change, which just happens inside Realm.

      Can you reproduce the bug?

      Always

      Version

      Realm 10, 11

      Platform OS and version(s)

      Node, at least.

      Build environment

      MacOs 12.5 (M1 Pro)

            Assignee:
            Kenneth Geisshirt (Inactive)
            Reporter:
            Unito Sync Bot
            Archiver:
            Marc Greenfield

              Created:
              Updated:
              Archived: