From 9f301e13c5d8f057e6e9308e23cba7ecc27dab09 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Tue, 20 Jun 2023 00:31:07 -0700 Subject: Cleanup fs.utimesSync (#3363) * Fix UB in fs.utimesSync when passing a number with an integer greater than i32 * Fix make headers --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> --- src/bun.js/bindings/bindings.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/bun.js/bindings/bindings.cpp') diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp index 74357f225..2ec1bd902 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -3111,6 +3111,19 @@ int32_t JSC__JSValue__toInt32(JSC__JSValue JSValue0) return JSC::JSValue::decode(JSValue0).asInt32(); } +CPP_DECL double JSC__JSValue__coerceToDouble(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1) +{ + JSC::JSValue value = JSC::JSValue::decode(JSValue0); + auto catchScope = DECLARE_CATCH_SCOPE(arg1->vm()); + double result = value.toNumber(arg1); + if (catchScope.exception()) { + result = PNaN; + catchScope.clearException(); + } + + return result; +} + // truncates values larger than int32 int32_t JSC__JSValue__coerceToInt32(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1) { @@ -4374,6 +4387,16 @@ extern "C" JSC__JSValue WebCore__AbortSignal__createTimeoutError(const ZigString return JSC::JSValue::encode(error); } +CPP_DECL double JSC__JSValue__getUnixTimestamp(JSC__JSValue timeValue) +{ + JSC::JSValue decodedValue = JSC::JSValue::decode(timeValue); + JSC::DateInstance* date = JSC::jsDynamicCast(decodedValue); + if (!date) + return PNaN; + + return date->internalNumber(); +} + #pragma mark - WebCore::DOMFormData CPP_DECL void WebCore__DOMFormData__append(WebCore__DOMFormData* arg0, ZigString* arg1, ZigString* arg2) -- cgit v1.2.3