sebastienros / jint

Javascript Interpreter for .NET
BSD 2-Clause "Simplified" License
4.13k stars 560 forks source link

Jint version used by Salesforce Marketing Cloud returns wrong Bitwise left result #1400

Closed attilah closed 1 year ago

attilah commented 1 year ago

Tried to implement hmac sha-256 for marketing cloud in SSJS which is powered by some old version of Jint and it turns out that most of the bitwise operations are either returning wrong result or throwing ArithmeticOverflowException.

Simplest issue I ran into is this:

1359893119 << 26

Returns: 9.12608823775068e+16

Correct value would be: -67108864

Do you recall any issue around this Sebastien?

This shows the issue in more detail: https://salesforce.stackexchange.com/questions/363226/ssjs-left-shift-operator-and-2s-complement-different-behaviour-than-in-j

lahma commented 1 year ago

Latest Jint 3 beta seems to work correctly:

jint> 1359893119 << 26
-67108864

So the library should be updated or some custom JS function to be used (can also be CLR function if this SSJS thing allows registering those).

attilah commented 1 year ago

@lahma unfortunately CLR is not enabled (for obvious security reasons) in SFMC :-( I doubt that Salesforce will update the JS runtime engine if they haven't done it in years :-( stuck at ES3...I think it says it all.

Trying to get a workaround with custom JS but it is far from ideal.

lahma commented 1 year ago

I don't know if Salesforce has any issue tracker to file an issue about updating. They would benefit in many ways, like new syntax support, manyfold performance increase in some scenarios.

As there's not much that we can do on Jint side, I'll convert this to discussion.