Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-38844

Eventing only partially supports BigInt

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Fixed
    • Critical
    • 7.0.0
    • 6.6.0, 6.5.0
    • eventing
    • None
    • 1

    Description

      In JavaScript, the Number type cannot safely represent integer values larger than 2^53^. This limitation has forced developers to use inefficient workarounds and third-party libraries. BigInt is a new data type intended to fix that.

      This can be very useful to sport exact precision currency.

      Also with the pending introduction of CAS and Atomic counters which both use 64 bit values the use of BigInt seems to a natural fit.  However ti appear that the Eventing transpiler will not allow syntax like :

      function OnUpdate(doc, meta) {
       var mybigint = 2n;
       log('docId', meta.id);
      }

      If we trigger on mutation on the above we get an "Unexpected Illegal Token".

      Yet the Eventing JavaScript Google V8 engine does indeed support BigInt operations like:

       

      function OnUpdate(doc, meta) {
       var max = BigInt(2) ** BigInt(64) - BigInt(1);
       log('E1 max unsigned 64-bit number',max.toString());
       // 18446744073709551615n
      }

      The above works as expected with the new BigInt extension e.g. in the V8 runner

       

      2020-04-18T08:46:33.902-07:00 [INFO] "E1 max unsigned 64-bit number" "18446744073709551615"

      Important Fix Note:
      The bugfix for this issue is intertwined with MB-38843 fix. These two bugs must be handled together as a single unit
       

      Attachments

        Issue Links

          For Gerrit Dashboard: MB-38844
          # Subject Branch Project Status CR V

          Activity

            People

              ankit.prabhu Ankit Prabhu
              jon.strabala Jon Strabala
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty