Fix js_math_imul (#356)

- follow ECMA specification
- remove implementation defined signed conversion
This commit is contained in:
Charlie Gordon 2024-04-08 22:50:39 +02:00 committed by GitHub
parent 97c918662b
commit 0658d9c3e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -40943,16 +40943,16 @@ static double js_math_fround(double a)
static JSValue js_math_imul(JSContext *ctx, JSValue this_val,
int argc, JSValue *argv)
{
int a, b;
uint32_t a, b, c;
int32_t d;
if (JS_ToInt32(ctx, &a, argv[0]))
if (JS_ToUint32(ctx, &a, argv[0]))
return JS_EXCEPTION;
if (JS_ToInt32(ctx, &b, argv[1]))
if (JS_ToUint32(ctx, &b, argv[1]))
return JS_EXCEPTION;
/* TODO(bnoordhuis) Signed integral narrowing has implementation-defined
* behavior but that's a step up from the undefined behavior it replaced.
*/
return js_int32((int64_t)a * (int64_t)b);
c = a * b;
memcpy(&d, &c, sizeof(d));
return js_int32(d);
}
static JSValue js_math_clz32(JSContext *ctx, JSValue this_val,