diff options
author | 2022-05-04 18:40:09 -0700 | |
---|---|---|
committer | 2022-05-05 21:35:08 -0700 | |
commit | 5b2d9f81288ed1601c97d70bb86d14cbb445d8c4 (patch) | |
tree | 3413ad83219ed80466afa16503f0346b570519d2 /src/javascript | |
parent | d629cfafd6fd148c985b5cd051cc5ec48395dc16 (diff) | |
download | bun-5b2d9f81288ed1601c97d70bb86d14cbb445d8c4.tar.gz bun-5b2d9f81288ed1601c97d70bb86d14cbb445d8c4.tar.zst bun-5b2d9f81288ed1601c97d70bb86d14cbb445d8c4.zip |
Begin napi
Diffstat (limited to 'src/javascript')
-rw-r--r-- | src/javascript/jsc/bindings/bindings.zig | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/javascript/jsc/bindings/bindings.zig b/src/javascript/jsc/bindings/bindings.zig index 5c1d2c0cc..0738fe4bf 100644 --- a/src/javascript/jsc/bindings/bindings.zig +++ b/src/javascript/jsc/bindings/bindings.zig @@ -170,6 +170,10 @@ pub const ZigString = extern struct { return @ptrCast([*]align(1) const u16, untagged(this.ptr))[0..this.len]; } + pub inline fn utf16SliceAligned(this: *const ZigString) []const u16 { + return @ptrCast([*]const u16, @alignCast(@alignOf(u16), untagged(this.ptr)))[0..this.len]; + } + pub inline fn isEmpty(this: *const ZigString) bool { return this.len == 0; } @@ -205,6 +209,12 @@ pub const ZigString = extern struct { return JSC.JSValue.fromRef(slice_).getZigString(ctx.ptr()); } + pub fn from16(slice_: [*]const u16, len: usize) ZigString { + var str = init(@ptrCast([*]const u8, slice_)[0..len]); + str.markUTF16(); + return str; + } + pub fn toBase64DataURL(this: ZigString, allocator: std.mem.Allocator) ![]const u8 { const slice_ = this.slice(); const size = std.base64.standard.Encoder.calcSize(slice_.len); @@ -2003,6 +2013,7 @@ pub const String = extern struct { }; pub const JSValue = enum(u64) { + @"undefined" = 0xa, _, pub const shim = Shimmer("JSC", "JSValue", @This()); @@ -2230,6 +2241,7 @@ pub const JSValue = enum(u64) { u52 => @truncate(u52, this.to(u64)), u64 => @intCast(u64, @maximum(toInt64(this), 0)), + f64 => asNUmber(this), u8 => @truncate(u8, toU32(this)), i16 => @truncate(i16, toInt32(this)), @@ -2238,6 +2250,7 @@ pub const JSValue = enum(u64) { // TODO: BigInt64 i64 => @as(i64, toInt32(this)), + bool => this.toBoolean(), else => @compileError("Not implemented yet"), }; } @@ -2374,8 +2387,8 @@ pub const JSValue = enum(u64) { pub fn jsNull() JSValue { return cppFn("jsNull", .{}); } - pub fn jsUndefined() JSValue { - return cppFn("jsUndefined", .{}); + pub inline fn jsUndefined() JSValue { + return JSValue.@"undefined"; } pub fn jsTDZValue() JSValue { return cppFn("jsTDZValue", .{}); @@ -2603,7 +2616,7 @@ pub const JSValue = enum(u64) { } // On exception, this returns null, to make exception checks faster. - pub fn toStringOrNull(this: JSValue, globalThis: *JSGlobalObject) *JSString { + pub fn toStringOrNull(this: JSValue, globalThis: *JSGlobalObject) ?*JSString { return cppFn("toStringOrNull", .{ this, globalThis }); } pub fn toPropertyKey(this: JSValue, globalThis: *JSGlobalObject) Identifier { |