diff --git a/config2.h.in b/config2.h.in index 9fbd0f69b..5687d35ae 100644 --- a/config2.h.in +++ b/config2.h.in @@ -821,6 +821,9 @@ /* The size of `short', as computed by sizeof. */ #define SIZEOF_SHORT @SIZEOF_SHORT@ +/* The size of `intptr_t`, as computed by sizeof. */ +#define SIZEOF_INTPTR_T @SIZEOF_INTPTR_T@ + /* If using the C implementation of alloca, define if you know the direction of stack growth for your system; otherwise it will be automatically deduced at runtime. diff --git a/meson.build b/meson.build index 7977d852b..ff2bea554 100644 --- a/meson.build +++ b/meson.build @@ -1148,6 +1148,7 @@ conf_data.set('SIZEOF_INT', compiler.sizeof('int')) conf_data.set('SIZEOF_LONG', compiler.sizeof('long')) conf_data.set('SIZEOF_LONG_LONG', compiler.sizeof('long long')) conf_data.set('SIZEOF_OFF_T', compiler.sizeof('off_t')) +conf_data.set('SIZEOF_INTPTR_T', compiler.sizeof('intptr_t', prefix: '#include ')) conf_data.set('CONFIG_GNUTLS_OPENSSL_COMPAT', false) diff --git a/src/ecmascript/quickjs/window.c b/src/ecmascript/quickjs/window.c index 6f4dd2528..d4a04e701 100644 --- a/src/ecmascript/quickjs/window.c +++ b/src/ecmascript/quickjs/window.c @@ -273,7 +273,11 @@ js_window_setInterval(JSContext *ctx, JSValueConst this_val, int argc, JSValueCo if (JS_IsFunction(ctx, func)) { struct ecmascript_timeout *id = ecmascript_set_timeout2q(ctx, func, timeout, timeout); - return JS_NewInt64(ctx, (int64_t)(id)); +#if SIZEOF_UINTPTR_T == 4 + return JS_NewInt32(ctx, (intptr_t)(id)); +#else + return JS_NewInt64(ctx, (intptr_t)(id)); +#endif } if (JS_IsString(func)) { @@ -288,7 +292,11 @@ js_window_setInterval(JSContext *ctx, JSValueConst this_val, int argc, JSValueCo if (code2) { struct ecmascript_timeout *id = ecmascript_set_timeout(ctx, code2, timeout, timeout); - return JS_NewInt64(ctx, (int64_t)(id)); +#if SIZEOF_UINTPTR_T == 4 + return JS_NewInt32(ctx, (intptr_t)(id)); +#else + return JS_NewInt64(ctx, (intptr_t)(id)); +#endif } } @@ -325,8 +333,11 @@ js_window_setTimeout(JSContext *ctx, JSValueConst this_val, int argc, JSValueCon if (JS_IsFunction(ctx, func)) { struct ecmascript_timeout *id = ecmascript_set_timeout2q(ctx, func, timeout, -1); - - return JS_NewInt64(ctx, (int64_t)(id)); +#if SIZEOF_UINTPTR_T == 4 + return JS_NewInt32(ctx, (intptr_t)(id)); +#else + return JS_NewInt64(ctx, (intptr_t)(id)); +#endif } if (JS_IsString(func)) { @@ -340,8 +351,11 @@ js_window_setTimeout(JSContext *ctx, JSValueConst this_val, int argc, JSValueCon if (code2) { struct ecmascript_timeout *id = ecmascript_set_timeout(ctx, code2, timeout, -1); - - return JS_NewInt64(ctx, (int64_t)(id)); +#if SIZEOF_UINTPTR_T == 4 + return JS_NewInt32(ctx, (intptr_t)(id)); +#else + return JS_NewInt64(ctx, (intptr_t)(id)); +#endif } } @@ -360,12 +374,17 @@ js_window_clearInterval(JSContext *ctx, JSValueConst this_val, int argc, JSValue if (argc != 1) { return JS_UNDEFINED; } - int64_t number; + intptr_t number; +#if SIZEOF_UINTPTR_T == 4 + if (JS_ToInt32(ctx, &number, argv[0])) { + return JS_UNDEFINED; + } +#else if (JS_ToInt64(ctx, &number, argv[0])) { return JS_UNDEFINED; } - +#endif struct ecmascript_timeout *t = (struct ecmascript_timeout *)(number); if (t && found_in_map_timer(t->tid)) { @@ -391,11 +410,17 @@ js_window_clearTimeout(JSContext *ctx, JSValueConst this_val, int argc, JSValueC if (argc != 1) { return JS_UNDEFINED; } - int64_t number; + intptr_t number; +#if SIZEOF_UINTPTR_T == 4 + if (JS_ToInt32(ctx, &number, argv[0])) { + return JS_UNDEFINED; + } +#else if (JS_ToInt64(ctx, &number, argv[0])) { return JS_UNDEFINED; } +#endif struct ecmascript_timeout *t = (struct ecmascript_timeout *)(number); if (t && found_in_map_timer(t->tid)) {