BigInt appears to Fail in Apps Script New IDE debugger

233 views
Skip to first unread message

Steve Bolman

unread,
Mar 16, 2022, 4:29:16 PM3/16/22
to Google Apps Script Community
Strange Behavior, but...
BigInt seems to execute "Run" ok but when run in debugging and placing a break on the last line of code, things are ok for about one second and then V8 kicks out the below error.

Error  --  The JavaScript runtime exited unexpectedly.

Note; This is NOT the observed behavior in the "OLD IDE".

<code>
function bigIntTestFunction() {
  const maxInt = Number.MAX_SAFE_INTEGER
  console.log(maxInt);
  const bigString = BigInt(Number.MAX_SAFE_INTEGER * 123).toString(); // + 'n';
  console.log(bigString);
  //  BUT
  const bigInt = BigInt(Number.MAX_SAFE_INTEGER * 123); // + 'n';
  console.log(bigInt.toString());
  console.log("HOLD HERE"); 
}
</code>
Current learning, BigInt works but if used REQUIRES the old IDE.

If / When I am mistaken please let me know.

Steve Bolman

unread,
Mar 16, 2022, 4:56:59 PM3/16/22
to Google Apps Script Community
In reviewing the V8 documentation (https://v8.dev/blog/bigint) , I found the note below... 
  1.  Mixing BigInt and Number operand types is generally not allowed. That’s somewhat unusual for JavaScript, but there is an explanation for this decision. ↩︎

Apologies for adding complexity to the discussion but in the example below the problem is made very clear.  It is not a V8 issue, I believe it is limited to the "new IDE" but then who am I?

<code>
function bigIntSimpleTestFunction() {
  const bigInt = BigInt(Number.MAX_SAFE_INTEGER);
  console.log("HOLD HERE");
}
</code>

Curator at Equalation

unread,
Aug 2, 2022, 5:29:04 PM8/2/22
to Google Apps Script Community
I found a work around.  To restate the problem is limited to the 'New' IDE (Or maybe V8 as an alternate candidate for blame, I don' t know).
If it BigInt works for you 'great I am happy' but it still doesn't for me and as I had a pretty significant use case for BigInt I came back to trying things.

A helpful hint came in from Mozilla (below) where this use of wrapping BigInts in an Object 

"A BigInt value can also be wrapped in an Object:"

Also that BigInt Operators can work on BigInts wrapped within objects as mentioned
"The following operators may be used with BigInt values or object-wrapped BigInt values:"


SO the code work around looks like this...

  let bigIntInObj = new Object(BigInt(12345678910111213141516))
  let tenInObj = new Object(BigInt(100))
  bigIntInObj = new Object(bigIntInObj * tenInObj);

  console.log((bigIntInObj.valueOf() ).toString())

Just keep the BigInts wrapped in an object,  This includes the operations (e.g.  bigIntInObj * tenInObj).  

Sorry I have no idea what this does or what it tells us about the problem.
Good Luck :)

Reply all
Reply to author
Forward
0 new messages