aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js')
-rw-r--r--src/bun.js/bindings/bindings.cpp34
-rw-r--r--src/bun.js/bindings/bindings.zig10
-rw-r--r--src/bun.js/bindings/generated_classes_list.zig2
-rw-r--r--src/bun.js/rare_data.zig2
4 files changed, 48 insertions, 0 deletions
diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp
index d06e8259e..a61a0221a 100644
--- a/src/bun.js/bindings/bindings.cpp
+++ b/src/bun.js/bindings/bindings.cpp
@@ -4689,6 +4689,40 @@ extern "C" EncodedJSValue JSC__JSValue__dateInstanceFromNullTerminatedString(JSC
return JSValue::encode(date);
}
+// this is largely copied from dateProtoFuncToISOString
+extern "C" int JSC__JSValue__toISOString(JSC::JSGlobalObject* globalObject, EncodedJSValue dateValue, char buffer[28])
+{
+ JSC::DateInstance* thisDateObj = JSC::jsDynamicCast<JSC::DateInstance*>(JSC::JSValue::decode(dateValue));
+ if (!thisDateObj)
+ return -1;
+
+ if (!std::isfinite(thisDateObj->internalNumber()))
+ return -1;
+
+ auto& vm = globalObject->vm();
+
+ const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTimeUTC(vm.dateCache);
+ if (!gregorianDateTime)
+ return -1;
+
+ // If the year is outside the bounds of 0 and 9999 inclusive we want to use the extended year format (ES 15.9.1.15.1).
+ int ms = static_cast<int>(fmod(thisDateObj->internalNumber(), msPerSecond));
+ if (ms < 0)
+ ms += msPerSecond;
+
+ int charactersWritten;
+ if (gregorianDateTime->year() > 9999 || gregorianDateTime->year() < 0)
+ charactersWritten = snprintf(buffer, sizeof(buffer), "%+07d-%02d-%02dT%02d:%02d:%02d.%03dZ", gregorianDateTime->year(), gregorianDateTime->month() + 1, gregorianDateTime->monthDay(), gregorianDateTime->hour(), gregorianDateTime->minute(), gregorianDateTime->second(), ms);
+ else
+ charactersWritten = snprintf(buffer, sizeof(buffer), "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", gregorianDateTime->year(), gregorianDateTime->month() + 1, gregorianDateTime->monthDay(), gregorianDateTime->hour(), gregorianDateTime->minute(), gregorianDateTime->second(), ms);
+
+ ASSERT(charactersWritten > 0 && static_cast<unsigned>(charactersWritten) < sizeof(buffer));
+ if (static_cast<unsigned>(charactersWritten) >= sizeof(buffer))
+ return -1;
+
+ return charactersWritten;
+}
+
#pragma mark - WebCore::DOMFormData
CPP_DECL void WebCore__DOMFormData__append(WebCore__DOMFormData* arg0, ZigString* arg1, ZigString* arg2)
diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig
index e6b218486..278ccd20e 100644
--- a/src/bun.js/bindings/bindings.zig
+++ b/src/bun.js/bindings/bindings.zig
@@ -3557,6 +3557,16 @@ pub const JSValue = enum(JSValueReprInt) {
cppFn("push", .{ value, globalObject, out });
}
+ extern fn JSC__JSValue__toISOString(*JSC.JSGlobalObject, JSC.JSValue, *[28]u8) c_int;
+ pub fn toISOString(this: JSValue, globalObject: *JSC.JSGlobalObject, buf: *[28]u8) []const u8 {
+ const count = JSC__JSValue__toISOString(globalObject, this, buf);
+ if (count < 0) {
+ return "";
+ }
+
+ return buf[0..@as(usize, @intCast(count))];
+ }
+
pub fn as(value: JSValue, comptime ZigType: type) ?*ZigType {
if (value.isEmptyOrUndefinedOrNull())
return null;
diff --git a/src/bun.js/bindings/generated_classes_list.zig b/src/bun.js/bindings/generated_classes_list.zig
index 3b45f33b8..60b0b08c1 100644
--- a/src/bun.js/bindings/generated_classes_list.zig
+++ b/src/bun.js/bindings/generated_classes_list.zig
@@ -55,4 +55,6 @@ pub const Classes = struct {
pub const DebugHTTPSServer = JSC.API.DebugHTTPSServer;
pub const Crypto = JSC.WebCore.Crypto;
pub const FFI = JSC.FFI;
+ pub const PostgresSQLConnection = JSC.Postgres.PostgresSQLConnection;
+ pub const PostgresSQLQuery = JSC.Postgres.PostgresSQLQuery;
};
diff --git a/src/bun.js/rare_data.zig b/src/bun.js/rare_data.zig
index c9d742d96..c9890d2dd 100644
--- a/src/bun.js/rare_data.zig
+++ b/src/bun.js/rare_data.zig
@@ -20,6 +20,8 @@ stderr_store: ?*Blob.Store = null,
stdin_store: ?*Blob.Store = null,
stdout_store: ?*Blob.Store = null,
+postgresql_context: JSC.Postgres.PostgresSQLContext = .{},
+
entropy_cache: ?*EntropyCache = null,
hot_map: ?HotMap = null,