aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-10-07 18:55:59 -0700
committerGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-10-07 18:55:59 -0700
commit89d494c5ed21916c266fc07c4a86ddf22e7d195d (patch)
tree2ee46965ee6f55a832b8b50b5d8eaab70be126ae
parentdd7b47a30e4a7321282727b791444118dec6dc89 (diff)
downloadbun-89d494c5ed21916c266fc07c4a86ddf22e7d195d.tar.gz
bun-89d494c5ed21916c266fc07c4a86ddf22e7d195d.tar.zst
bun-89d494c5ed21916c266fc07c4a86ddf22e7d195d.zip
canvas class
-rw-r--r--Makefile8
-rw-r--r--build.zig3
-rw-r--r--src/bun.js/api/JSCanvas.zig89
-rw-r--r--src/bun.js/api/bun.classes.ts19
-rw-r--r--src/bun.js/api/bun.zig9
-rw-r--r--src/bun.js/bindings/BunObject+exports.h1
-rw-r--r--src/bun.js/bindings/BunObject.cpp1
-rw-r--r--src/bun.js/bindings/BunObject.lut.h131
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h3
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h3
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h4
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h7
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses.cpp302
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses.h50
-rw-r--r--src/bun.js/bindings/generated_classes.zig83
-rw-r--r--src/bun.js/bindings/generated_classes_list.zig2
-rw-r--r--src/jsc.zig1
17 files changed, 648 insertions, 68 deletions
diff --git a/Makefile b/Makefile
index 92fac9ec0..77c1b37e0 100644
--- a/Makefile
+++ b/Makefile
@@ -463,6 +463,7 @@ ARCHIVE_FILES_WITHOUT_LIBCRYPTO = $(MINIMUM_ARCHIVE_FILES) \
-lusockets \
-lcares \
-lzstd \
+ -lSDL2 \
$(BUN_DEPS_OUT_DIR)/libuwsockets.o
ARCHIVE_FILES = $(ARCHIVE_FILES_WITHOUT_LIBCRYPTO)
@@ -1883,6 +1884,11 @@ base64:
cd $(BUN_DEPS_DIR)/base64 && make clean && rm -rf CMakeCache.txt CMakeFiles && cmake $(CMAKE_FLAGS) . && make
cp $(BUN_DEPS_DIR)/base64/libbase64.a $(BUN_DEPS_OUT_DIR)/libbase64.a
+.PHONY: sdl
+sdl:
+ cd $(BUN_DEPS_DIR)/SDL && ./configure && make
+ cp $(BUN_DEPS_DIR)/SDL/build/.libs/libSDL2.a $(BUN_DEPS_OUT_DIR)/libSDL2.a
+
.PHONY: cold-jsc-start
cold-jsc-start:
$(CXX_WITH_CCACHE) $(CLANG_FLAGS) \
@@ -1900,7 +1906,7 @@ cold-jsc-start:
misctools/cold-jsc-start.cpp -o cold-jsc-start
.PHONY: vendor-without-npm
-vendor-without-npm: node-fallbacks runtime_js fallback_decoder bun_error mimalloc picohttp zlib boringssl libarchive lolhtml sqlite usockets uws tinycc c-ares zstd base64
+vendor-without-npm: node-fallbacks runtime_js fallback_decoder bun_error mimalloc picohttp zlib boringssl libarchive lolhtml sqlite usockets uws tinycc c-ares zstd base64 sdl
.PHONY: vendor-without-check
diff --git a/build.zig b/build.zig
index 6a860221a..03873131e 100644
--- a/build.zig
+++ b/build.zig
@@ -1,6 +1,7 @@
const std = @import("std");
const pathRel = std.fs.path.relative;
const Wyhash = @import("./src/wyhash.zig").Wyhash;
+const LazyPath = std.Build.LazyPath;
var is_debug_build = false;
fn moduleSource(comptime out: []const u8) FileSource {
if (comptime std.fs.path.dirname(@src().file)) |base| {
@@ -220,6 +221,8 @@ pub fn build_(b: *Build) !void {
.main_pkg_path = .{ .cwd_relative = b.pathFromRoot(".") },
});
+ obj.addIncludePath(LazyPath.relative("./src/deps/SDL/include"));
+
b.reference_trace = 16;
var default_build_options: BunBuildOptions = brk: {
diff --git a/src/bun.js/api/JSCanvas.zig b/src/bun.js/api/JSCanvas.zig
new file mode 100644
index 000000000..f8bbff89e
--- /dev/null
+++ b/src/bun.js/api/JSCanvas.zig
@@ -0,0 +1,89 @@
+const std = @import("std");
+const bun = @import("root").bun;
+const strings = bun.strings;
+const string = bun.string;
+const Output = bun.Output;
+const JSC = bun.JSC;
+const JSValue = JSC.JSValue;
+const JSGlobalObject = JSC.JSGlobalObject;
+const CallFrame = JSC.CallFrame;
+
+// for now cInclude, later add a SDL wrapper
+const c = @cImport({
+ @cInclude("SDL.h");
+});
+
+const Canvas = @This();
+
+const log = Output.scoped(.Canvas, false);
+pub usingnamespace JSC.Codegen.JSCanvas;
+
+running: bool,
+width: i32,
+height: i32,
+
+window: *c.SDL_Window,
+
+pub fn constructor(globalObject: *JSGlobalObject, callFrame: *CallFrame) callconv(.C) ?*Canvas {
+ log("Canvas.constructor", .{});
+
+ const args = callFrame.arguments(4).slice();
+ _ = args;
+
+ _ = c.SDL_Init(c.SDL_INIT_EVERYTHING);
+
+ const window = c.SDL_CreateWindow("bun window", c.SDL_WINDOWPOS_UNDEFINED, c.SDL_WINDOWPOS_UNDEFINED, 640, 480, c.SDL_WINDOW_SHOWN);
+ if (window == null) {
+ globalObject.throw("Failed to create window", .{});
+ return null;
+ }
+
+ var canvas: *Canvas = bun.default_allocator.create(Canvas) catch unreachable;
+
+ canvas.running = true;
+ canvas.height = 1;
+ canvas.width = 1;
+
+ return canvas;
+}
+
+pub fn finalize(this: *Canvas) callconv(.C) void {
+ log("Canvas.finalize", .{});
+ bun.default_allocator.destroy(this);
+}
+
+pub fn getHeight(this: *Canvas, globalObject: *JSGlobalObject) callconv(.C) JSValue {
+ log("Canvas.getHeight: {d}", .{this.height});
+ _ = globalObject;
+
+ return JSValue.jsNumber(this.height);
+}
+
+pub fn setHeight(this: *Canvas, globalObject: *JSGlobalObject, value: JSValue) callconv(.C) bool {
+ log("Canvas.setHeight", .{});
+ _ = this;
+ _ = value;
+ _ = globalObject;
+
+ return true;
+}
+
+pub fn getWidth(this: *Canvas, globalObject: *JSGlobalObject) callconv(.C) JSValue {
+ log("Canvas.getHeight: {d}", .{this.width});
+ _ = globalObject;
+
+ return JSValue.jsNumber(this.width);
+}
+
+pub fn setWidth(this: *Canvas, globalObject: *JSGlobalObject, value: JSValue) callconv(.C) bool {
+ log("Canvas.setWidth", .{});
+ _ = this;
+ _ = value;
+ _ = globalObject;
+
+ return true;
+}
+
+// pub fn hasPendingActivity(this: *Canvas) callconv(.C) bool {
+// return this.running;
+// }
diff --git a/src/bun.js/api/bun.classes.ts b/src/bun.js/api/bun.classes.ts
index 36f48f790..b34a537f9 100644
--- a/src/bun.js/api/bun.classes.ts
+++ b/src/bun.js/api/bun.classes.ts
@@ -2,6 +2,25 @@ import { define } from "../scripts/class-definitions";
export default [
define({
+ name: "Canvas",
+ construct: true,
+ finalize: true,
+ // hasPendingActivity: true,
+ configurable: false,
+ klass: {},
+ JSType: "0b11101110",
+ proto: {
+ width: {
+ getter: "getWidth",
+ setter: "setWidth",
+ },
+ height: {
+ getter: "getHeight",
+ setter: "setHeight",
+ },
+ },
+ }),
+ define({
name: "Subprocess",
construct: true,
noConstructor: true,
diff --git a/src/bun.js/api/bun.zig b/src/bun.js/api/bun.zig
index 949ba402c..3e47fee61 100644
--- a/src/bun.js/api/bun.zig
+++ b/src/bun.js/api/bun.zig
@@ -57,6 +57,7 @@ pub const BunObject = struct {
pub const SHA512_256 = Crypto.SHA512_256.getter;
pub const TOML = Bun.getTOMLObject;
pub const Transpiler = Bun.getTranspilerConstructor;
+ pub const Canvas = Bun.getCanvasConstructor;
pub const argv = Bun.getArgv;
pub const assetPrefix = Bun.getAssetPrefix;
pub const cwd = Bun.getCWD;
@@ -102,6 +103,7 @@ pub const BunObject = struct {
@export(BunObject.SHA512_256, .{ .name = getterName("SHA512_256") });
@export(BunObject.TOML, .{ .name = getterName("TOML") });
@export(BunObject.Transpiler, .{ .name = getterName("Transpiler") });
+ @export(BunObject.Canvas, .{ .name = getterName("Canvas") });
@export(BunObject.argv, .{ .name = getterName("argv") });
@export(BunObject.assetPrefix, .{ .name = getterName("assetPrefix") });
@export(BunObject.cwd, .{ .name = getterName("cwd") });
@@ -2823,6 +2825,13 @@ pub fn getTranspilerConstructor(
return JSC.API.JSTranspiler.getConstructor(globalThis);
}
+pub fn getCanvasConstructor(
+ globalThis: *JSC.JSGlobalObject,
+ _: *JSC.JSObject,
+) callconv(.C) JSC.JSValue {
+ return JSC.API.JSCanvas.getConstructor(globalThis);
+}
+
pub fn getFileSystemRouter(
globalThis: *JSC.JSGlobalObject,
_: *JSC.JSObject,
diff --git a/src/bun.js/bindings/BunObject+exports.h b/src/bun.js/bindings/BunObject+exports.h
index b805b90d8..ac405e9b9 100644
--- a/src/bun.js/bindings/BunObject+exports.h
+++ b/src/bun.js/bindings/BunObject+exports.h
@@ -15,6 +15,7 @@
macro(SHA512_256) \
macro(TOML) \
macro(Transpiler) \
+ macro(Canvas) \
macro(argv) \
macro(assetPrefix) \
macro(cwd) \
diff --git a/src/bun.js/bindings/BunObject.cpp b/src/bun.js/bindings/BunObject.cpp
index 9d8ce6674..2f5811349 100644
--- a/src/bun.js/bindings/BunObject.cpp
+++ b/src/bun.js/bindings/BunObject.cpp
@@ -577,6 +577,7 @@ JSC_DEFINE_HOST_FUNCTION(functionHashCode,
SHA512_256 BunObject_getter_wrap_SHA512_256 DontDelete|PropertyCallback
TOML BunObject_getter_wrap_TOML DontDelete|PropertyCallback
Transpiler BunObject_getter_wrap_Transpiler DontDelete|PropertyCallback
+ Canvas BunObject_getter_wrap_Canvas DontDelete|PropertyCallback
_Os BunObject_callback__Os DontEnum|DontDelete|Function 1
_Path BunObject_callback__Path DontEnum|DontDelete|Function 1
allocUnsafe BunObject_callback_allocUnsafe DontDelete|Function 1
diff --git a/src/bun.js/bindings/BunObject.lut.h b/src/bun.js/bindings/BunObject.lut.h
index a2aa95fda..b6d53472b 100644
--- a/src/bun.js/bindings/BunObject.lut.h
+++ b/src/bun.js/bindings/BunObject.lut.h
@@ -1,6 +1,6 @@
// File generated via `make static-hash-table` / `make cpp`
static const struct CompactHashIndex bunObjectTableIndex[269] = {
- { 75, -1 },
+ { 76, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
@@ -10,21 +10,21 @@ static const struct CompactHashIndex bunObjectTableIndex[269] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 38, -1 },
+ { 39, -1 },
{ -1, -1 },
- { 44, -1 },
+ { 45, -1 },
{ -1, -1 },
{ -1, -1 },
{ 4, -1 },
{ -1, -1 },
{ 2, -1 },
- { 48, -1 },
- { 34, 261 },
+ { 49, -1 },
+ { 35, 261 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 71, -1 },
- { 79, -1 },
+ { 72, -1 },
+ { 80, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
@@ -42,19 +42,18 @@ static const struct CompactHashIndex bunObjectTableIndex[269] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 60, -1 },
+ { 61, -1 },
{ -1, -1 },
{ -1, -1 },
{ 11, 258 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 45, 264 },
- { -1, -1 },
+ { 46, 264 },
{ -1, -1 },
{ -1, -1 },
- { 67, -1 },
{ -1, -1 },
+ { 68, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
@@ -62,17 +61,18 @@ static const struct CompactHashIndex bunObjectTableIndex[269] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 59, -1 },
{ -1, -1 },
+ { 60, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
+ { 15, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 47, 265 },
- { 32, -1 },
+ { 48, 265 },
+ { 33, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
@@ -81,20 +81,20 @@ static const struct CompactHashIndex bunObjectTableIndex[269] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 70, -1 },
- { 65, -1 },
+ { 71, -1 },
+ { 66, -1 },
{ -1, -1 },
{ 14, -1 },
- { 23, -1 },
+ { 24, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 43, -1 },
+ { 44, -1 },
{ -1, -1 },
- { 52, -1 },
+ { 53, -1 },
{ -1, -1 },
{ -1, -1 },
- { 37, -1 },
+ { 38, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
@@ -109,20 +109,20 @@ static const struct CompactHashIndex bunObjectTableIndex[269] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 64, -1 },
+ { 65, -1 },
{ -1, -1 },
- { 20, 256 },
+ { 21, 256 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 73, -1 },
+ { 74, -1 },
{ -1, -1 },
- { 77, -1 },
+ { 78, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 74, -1 },
- { 22, 259 },
+ { 75, -1 },
+ { 23, 259 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
@@ -130,30 +130,30 @@ static const struct CompactHashIndex bunObjectTableIndex[269] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 53, -1 },
+ { 54, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 40, -1 },
+ { 41, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 29, -1 },
+ { 30, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 63, -1 },
- { 35, 266 },
+ { 64, -1 },
+ { 36, 266 },
{ -1, -1 },
- { 33, -1 },
- { 54, -1 },
+ { 34, -1 },
+ { 55, -1 },
{ -1, -1 },
- { 26, -1 },
- { 15, -1 },
+ { 27, -1 },
+ { 16, -1 },
{ -1, -1 },
{ -1, -1 },
{ 6, -1 },
@@ -161,7 +161,7 @@ static const struct CompactHashIndex bunObjectTableIndex[269] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 18, -1 },
+ { 19, -1 },
{ -1, -1 },
{ -1, -1 },
{ 0, -1 },
@@ -173,66 +173,66 @@ static const struct CompactHashIndex bunObjectTableIndex[269] = {
{ -1, -1 },
{ -1, -1 },
{ 5, -1 },
- { 16, -1 },
+ { 17, -1 },
{ -1, -1 },
{ -1, -1 },
- { 24, -1 },
+ { 25, -1 },
{ 1, -1 },
- { 31, 267 },
+ { 32, 267 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 46, -1 },
+ { 47, -1 },
{ -1, -1 },
{ -1, -1 },
{ 8, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 69, -1 },
+ { 70, -1 },
{ -1, -1 },
- { 76, 268 },
+ { 77, 268 },
{ -1, -1 },
- { 36, -1 },
+ { 37, -1 },
{ -1, -1 },
{ -1, -1 },
- { 39, 260 },
+ { 40, 260 },
{ -1, -1 },
{ -1, -1 },
{ 7, 262 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 66, -1 },
+ { 67, -1 },
{ 3, -1 },
{ -1, -1 },
- { 61, -1 },
+ { 62, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 28, -1 },
- { 19, 257 },
+ { 29, -1 },
+ { 20, 257 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 9, -1 },
{ -1, -1 },
{ -1, -1 },
- { 49, -1 },
+ { 50, -1 },
{ 12, -1 },
{ -1, -1 },
- { 80, -1 },
+ { 81, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 17, -1 },
+ { 18, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 27, -1 },
+ { 28, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
@@ -240,10 +240,10 @@ static const struct CompactHashIndex bunObjectTableIndex[269] = {
{ 13, -1 },
{ -1, -1 },
{ -1, -1 },
- { 25, -1 },
+ { 26, -1 },
{ -1, -1 },
{ -1, -1 },
- { 42, 263 },
+ { 43, 263 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
@@ -256,22 +256,22 @@ static const struct CompactHashIndex bunObjectTableIndex[269] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 21, -1 },
- { 30, -1 },
- { 41, -1 },
- { 50, -1 },
+ { 22, -1 },
+ { 31, -1 },
+ { 42, -1 },
{ 51, -1 },
- { 55, -1 },
+ { 52, -1 },
{ 56, -1 },
{ 57, -1 },
{ 58, -1 },
- { 62, -1 },
- { 68, -1 },
- { 72, -1 },
- { 78, -1 },
+ { 59, -1 },
+ { 63, -1 },
+ { 69, -1 },
+ { 73, -1 },
+ { 79, -1 },
};
-static const struct HashTableValue bunObjectTableValues[81] = {
+static const struct HashTableValue bunObjectTableValues[82] = {
{ "ArrayBufferSink"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_ArrayBufferSink } },
{ "CryptoHasher"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_CryptoHasher } },
{ "DO_NOT_USE_OR_YOU_WILL_BE_FIRED_mimalloc_dump"_s, static_cast<unsigned>(PropertyAttribute::DontEnum|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_DO_NOT_USE_OR_YOU_WILL_BE_FIRED_mimalloc_dump, 1 } },
@@ -287,6 +287,7 @@ static const struct HashTableValue bunObjectTableValues[81] = {
{ "SHA512_256"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_SHA512_256 } },
{ "TOML"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_TOML } },
{ "Transpiler"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_Transpiler } },
+ { "Canvas"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_Canvas } },
{ "_Os"_s, static_cast<unsigned>(PropertyAttribute::DontEnum|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback__Os, 1 } },
{ "_Path"_s, static_cast<unsigned>(PropertyAttribute::DontEnum|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback__Path, 1 } },
{ "allocUnsafe"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_allocUnsafe, 1 } },
@@ -356,4 +357,4 @@ static const struct HashTableValue bunObjectTableValues[81] = {
};
static const struct HashTable bunObjectTable =
- { 81, 255, false, nullptr, bunObjectTableValues, bunObjectTableIndex };
+ { 82, 255, false, nullptr, bunObjectTableValues, bunObjectTableIndex };
diff --git a/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h b/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h
index cef5c512a..906831ffb 100644
--- a/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h
+++ b/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h
@@ -3,7 +3,8 @@ std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBigIntStats;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBigIntStatsConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBlob;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBlobConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBuildArtifact;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBuildMessage;
-std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBuildMessageConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForComment;
+std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBuildMessageConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForCanvas;
+std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForCanvasConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForComment;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForCrypto;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForCryptoConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForCryptoHasher;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForCryptoHasherConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForDebugHTTPSServer;
diff --git a/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h b/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h
index d06451eda..dd4f74156 100644
--- a/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h
+++ b/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h
@@ -3,7 +3,8 @@ std::unique_ptr<IsoSubspace> m_subspaceForBigIntStats;
std::unique_ptr<IsoSubspace> m_subspaceForBigIntStatsConstructor;std::unique_ptr<IsoSubspace> m_subspaceForBlob;
std::unique_ptr<IsoSubspace> m_subspaceForBlobConstructor;std::unique_ptr<IsoSubspace> m_subspaceForBuildArtifact;
std::unique_ptr<IsoSubspace> m_subspaceForBuildMessage;
-std::unique_ptr<IsoSubspace> m_subspaceForBuildMessageConstructor;std::unique_ptr<IsoSubspace> m_subspaceForComment;
+std::unique_ptr<IsoSubspace> m_subspaceForBuildMessageConstructor;std::unique_ptr<IsoSubspace> m_subspaceForCanvas;
+std::unique_ptr<IsoSubspace> m_subspaceForCanvasConstructor;std::unique_ptr<IsoSubspace> m_subspaceForComment;
std::unique_ptr<IsoSubspace> m_subspaceForCrypto;
std::unique_ptr<IsoSubspace> m_subspaceForCryptoConstructor;std::unique_ptr<IsoSubspace> m_subspaceForCryptoHasher;
std::unique_ptr<IsoSubspace> m_subspaceForCryptoHasherConstructor;std::unique_ptr<IsoSubspace> m_subspaceForDebugHTTPSServer;
diff --git a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h
index 381378262..b0c80f99a 100644
--- a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h
+++ b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h
@@ -18,6 +18,10 @@ JSC::Structure* JSBuildMessageStructure() { return m_JSBuildMessage.getInitializ
JSC::JSObject* JSBuildMessageConstructor() { return m_JSBuildMessage.constructorInitializedOnMainThread(this); }
JSC::JSValue JSBuildMessagePrototype() { return m_JSBuildMessage.prototypeInitializedOnMainThread(this); }
JSC::LazyClassStructure m_JSBuildMessage;
+JSC::Structure* JSCanvasStructure() { return m_JSCanvas.getInitializedOnMainThread(this); }
+ JSC::JSObject* JSCanvasConstructor() { return m_JSCanvas.constructorInitializedOnMainThread(this); }
+ JSC::JSValue JSCanvasPrototype() { return m_JSCanvas.prototypeInitializedOnMainThread(this); }
+ JSC::LazyClassStructure m_JSCanvas;
JSC::Structure* JSCommentStructure() { return m_JSComment.getInitializedOnMainThread(this); }
JSC::JSObject* JSCommentConstructor() { return m_JSComment.constructorInitializedOnMainThread(this); }
JSC::JSValue JSCommentPrototype() { return m_JSComment.prototypeInitializedOnMainThread(this); }
diff --git a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h
index 84d3df7a0..0a6f536a3 100644
--- a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h
+++ b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h
@@ -29,6 +29,12 @@ ALWAYS_INLINE void GlobalObject::initGeneratedLazyClasses() {
init.setStructure(WebCore::JSBuildMessage::createStructure(init.vm, init.global, init.prototype));
init.setConstructor(WebCore::JSBuildMessage::createConstructor(init.vm, init.global, init.prototype));
});
+ m_JSCanvas.initLater(
+ [](LazyClassStructure::Initializer& init) {
+ init.setPrototype(WebCore::JSCanvas::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global)));
+ init.setStructure(WebCore::JSCanvas::createStructure(init.vm, init.global, init.prototype));
+ init.setConstructor(WebCore::JSCanvas::createConstructor(init.vm, init.global, init.prototype));
+ });
m_JSComment.initLater(
[](LazyClassStructure::Initializer& init) {
init.setPrototype(WebCore::JSComment::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global)));
@@ -314,6 +320,7 @@ void GlobalObject::visitGeneratedLazyClasses(GlobalObject *thisObject, Visitor&
thisObject->m_JSBlob.visit(visitor);
thisObject->m_JSBuildArtifact.visit(visitor);
thisObject->m_JSBuildMessage.visit(visitor);
+ thisObject->m_JSCanvas.visit(visitor);
thisObject->m_JSComment.visit(visitor);
thisObject->m_JSCrypto.visit(visitor);
thisObject->m_JSCryptoHasher.visit(visitor);
diff --git a/src/bun.js/bindings/ZigGeneratedClasses.cpp b/src/bun.js/bindings/ZigGeneratedClasses.cpp
index f8541ac1e..6f64d1437 100644
--- a/src/bun.js/bindings/ZigGeneratedClasses.cpp
+++ b/src/bun.js/bindings/ZigGeneratedClasses.cpp
@@ -2935,6 +2935,308 @@ void JSBuildMessage::visitOutputConstraintsImpl(JSCell* cell, Visitor& visitor)
}
DEFINE_VISIT_OUTPUT_CONSTRAINTS(JSBuildMessage);
+class JSCanvasPrototype final : public JSC::JSNonFinalObject {
+public:
+ using Base = JSC::JSNonFinalObject;
+
+ static JSCanvasPrototype* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure)
+ {
+ JSCanvasPrototype* ptr = new (NotNull, JSC::allocateCell<JSCanvasPrototype>(vm)) JSCanvasPrototype(vm, globalObject, structure);
+ ptr->finishCreation(vm, globalObject);
+ return ptr;
+ }
+
+ DECLARE_INFO;
+ template<typename CellType, JSC::SubspaceAccess>
+ static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ return &vm.plainObjectSpace();
+ }
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
+ }
+
+private:
+ JSCanvasPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
+ : Base(vm, structure)
+ {
+ }
+
+ void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
+};
+
+class JSCanvasConstructor final : public JSC::InternalFunction {
+public:
+ using Base = JSC::InternalFunction;
+ static JSCanvasConstructor* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSCanvasPrototype* prototype);
+
+ static constexpr unsigned StructureFlags = Base::StructureFlags;
+ static constexpr bool needsDestruction = false;
+
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info());
+ }
+
+ template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ if constexpr (mode == JSC::SubspaceAccess::Concurrently)
+ return nullptr;
+ return WebCore::subspaceForImpl<JSCanvasConstructor, WebCore::UseCustomHeapCellType::No>(
+ vm,
+ [](auto& spaces) { return spaces.m_clientSubspaceForCanvasConstructor.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForCanvasConstructor = std::forward<decltype(space)>(space); },
+ [](auto& spaces) { return spaces.m_subspaceForCanvasConstructor.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_subspaceForCanvasConstructor = std::forward<decltype(space)>(space); });
+ }
+
+ void initializeProperties(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSCanvasPrototype* prototype);
+
+ // Must be defined for each specialization class.
+ static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*);
+
+ DECLARE_EXPORT_INFO;
+
+private:
+ JSCanvasConstructor(JSC::VM& vm, JSC::Structure* structure);
+ void finishCreation(JSC::VM&, JSC::JSGlobalObject* globalObject, JSCanvasPrototype* prototype);
+};
+
+extern "C" void* CanvasClass__construct(JSC::JSGlobalObject*, JSC::CallFrame*);
+JSC_DECLARE_CUSTOM_GETTER(jsCanvasConstructor);
+
+extern "C" void CanvasClass__finalize(void*);
+
+extern "C" JSC::EncodedJSValue CanvasPrototype__getHeight(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(CanvasPrototype__heightGetterWrap);
+
+extern "C" bool CanvasPrototype__setHeight(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::EncodedJSValue value);
+JSC_DECLARE_CUSTOM_SETTER(CanvasPrototype__heightSetterWrap);
+
+extern "C" JSC::EncodedJSValue CanvasPrototype__getWidth(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(CanvasPrototype__widthGetterWrap);
+
+extern "C" bool CanvasPrototype__setWidth(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::EncodedJSValue value);
+JSC_DECLARE_CUSTOM_SETTER(CanvasPrototype__widthSetterWrap);
+
+STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSCanvasPrototype, JSCanvasPrototype::Base);
+
+static const HashTableValue JSCanvasPrototypeTableValues[] = {
+ { "height"_s, static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, CanvasPrototype__heightGetterWrap, CanvasPrototype__heightSetterWrap } },
+ { "width"_s, static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, CanvasPrototype__widthGetterWrap, CanvasPrototype__widthSetterWrap } }
+};
+
+const ClassInfo JSCanvasPrototype::s_info = { "Canvas"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCanvasPrototype) };
+
+JSC_DEFINE_CUSTOM_GETTER(jsCanvasConstructor, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName))
+{
+ VM& vm = JSC::getVM(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ auto* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto* prototype = jsDynamicCast<JSCanvasPrototype*>(JSValue::decode(thisValue));
+
+ if (UNLIKELY(!prototype))
+ return throwVMTypeError(lexicalGlobalObject, throwScope, "Cannot get constructor for Canvas"_s);
+ return JSValue::encode(globalObject->JSCanvasConstructor());
+}
+
+JSC_DEFINE_CUSTOM_GETTER(CanvasPrototype__heightGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSCanvas* thisObject = jsCast<JSCanvas*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+ JSC::EncodedJSValue result = CanvasPrototype__getHeight(thisObject->wrapped(), globalObject);
+ RETURN_IF_EXCEPTION(throwScope, {});
+ RELEASE_AND_RETURN(throwScope, result);
+}
+
+JSC_DEFINE_CUSTOM_SETTER(CanvasPrototype__heightSetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSCanvas* thisObject = jsCast<JSCanvas*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+ auto result = CanvasPrototype__setHeight(thisObject->wrapped(), lexicalGlobalObject, encodedValue);
+
+ RELEASE_AND_RETURN(throwScope, result);
+}
+
+JSC_DEFINE_CUSTOM_GETTER(CanvasPrototype__widthGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSCanvas* thisObject = jsCast<JSCanvas*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+ JSC::EncodedJSValue result = CanvasPrototype__getWidth(thisObject->wrapped(), globalObject);
+ RETURN_IF_EXCEPTION(throwScope, {});
+ RELEASE_AND_RETURN(throwScope, result);
+}
+
+JSC_DEFINE_CUSTOM_SETTER(CanvasPrototype__widthSetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSCanvas* thisObject = jsCast<JSCanvas*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+ auto result = CanvasPrototype__setWidth(thisObject->wrapped(), lexicalGlobalObject, encodedValue);
+
+ RELEASE_AND_RETURN(throwScope, result);
+}
+
+void JSCanvasPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
+{
+ Base::finishCreation(vm);
+ reifyStaticProperties(vm, JSCanvas::info(), JSCanvasPrototypeTableValues, *this);
+ JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
+}
+
+void JSCanvasConstructor::finishCreation(VM& vm, JSC::JSGlobalObject* globalObject, JSCanvasPrototype* prototype)
+{
+ Base::finishCreation(vm, 0, "Canvas"_s, PropertyAdditionMode::WithoutStructureTransition);
+
+ putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
+ ASSERT(inherits(info()));
+}
+
+JSCanvasConstructor::JSCanvasConstructor(JSC::VM& vm, JSC::Structure* structure)
+ : Base(vm, structure, construct, construct)
+{
+}
+
+JSCanvasConstructor* JSCanvasConstructor::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSCanvasPrototype* prototype)
+{
+ JSCanvasConstructor* ptr = new (NotNull, JSC::allocateCell<JSCanvasConstructor>(vm)) JSCanvasConstructor(vm, structure);
+ ptr->finishCreation(vm, globalObject, prototype);
+ return ptr;
+}
+
+JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSCanvasConstructor::construct(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame)
+{
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ JSC::VM& vm = globalObject->vm();
+ JSObject* newTarget = asObject(callFrame->newTarget());
+ auto* constructor = globalObject->JSCanvasConstructor();
+ Structure* structure = globalObject->JSCanvasStructure();
+ if (constructor != newTarget) {
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
+ auto* functionGlobalObject = reinterpret_cast<Zig::GlobalObject*>(
+ // ShadowRealm functions belong to a different global object.
+ getFunctionRealm(globalObject, newTarget));
+ RETURN_IF_EXCEPTION(scope, {});
+ structure = InternalFunction::createSubclassStructure(
+ globalObject,
+ newTarget,
+ functionGlobalObject->JSCanvasStructure());
+ }
+
+ void* ptr = CanvasClass__construct(globalObject, callFrame);
+
+ if (UNLIKELY(!ptr)) {
+ return JSValue::encode(JSC::jsUndefined());
+ }
+
+ JSCanvas* instance = JSCanvas::create(vm, globalObject, structure, ptr);
+
+ return JSValue::encode(instance);
+}
+
+void JSCanvasConstructor::initializeProperties(VM& vm, JSC::JSGlobalObject* globalObject, JSCanvasPrototype* prototype)
+{
+}
+
+const ClassInfo JSCanvasConstructor::s_info = { "Function"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCanvasConstructor) };
+
+extern "C" EncodedJSValue Canvas__getConstructor(Zig::GlobalObject* globalObject)
+{
+ return JSValue::encode(globalObject->JSCanvasConstructor());
+}
+
+JSCanvas::~JSCanvas()
+{
+ if (m_ctx) {
+ CanvasClass__finalize(m_ctx);
+ }
+}
+void JSCanvas::destroy(JSCell* cell)
+{
+ static_cast<JSCanvas*>(cell)->JSCanvas::~JSCanvas();
+}
+
+const ClassInfo JSCanvas::s_info = { "Canvas"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCanvas) };
+
+void JSCanvas::finishCreation(VM& vm)
+{
+ Base::finishCreation(vm);
+ ASSERT(inherits(info()));
+}
+
+JSCanvas* JSCanvas::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx)
+{
+ JSCanvas* ptr = new (NotNull, JSC::allocateCell<JSCanvas>(vm)) JSCanvas(vm, structure, ctx);
+ ptr->finishCreation(vm);
+ return ptr;
+}
+
+extern "C" void* Canvas__fromJS(JSC::EncodedJSValue value)
+{
+ JSC::JSValue decodedValue = JSC::JSValue::decode(value);
+ if (decodedValue.isEmpty() || !decodedValue.isCell())
+ return nullptr;
+
+ JSC::JSCell* cell = decodedValue.asCell();
+ JSCanvas* object = JSC::jsDynamicCast<JSCanvas*>(cell);
+
+ if (!object)
+ return nullptr;
+
+ return object->wrapped();
+}
+
+extern "C" bool Canvas__dangerouslySetPtr(JSC::EncodedJSValue value, void* ptr)
+{
+ JSCanvas* object = JSC::jsDynamicCast<JSCanvas*>(JSValue::decode(value));
+ if (!object)
+ return false;
+
+ object->m_ctx = ptr;
+ return true;
+}
+
+extern "C" const size_t Canvas__ptrOffset = JSCanvas::offsetOfWrapped();
+
+void JSCanvas::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer)
+{
+ auto* thisObject = jsCast<JSCanvas*>(cell);
+ if (void* wrapped = thisObject->wrapped()) {
+ // if (thisObject->scriptExecutionContext())
+ // analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
+ }
+ Base::analyzeHeap(cell, analyzer);
+}
+
+JSObject* JSCanvas::createConstructor(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return WebCore::JSCanvasConstructor::create(vm, globalObject, WebCore::JSCanvasConstructor::createStructure(vm, globalObject, globalObject->functionPrototype()), jsCast<WebCore::JSCanvasPrototype*>(prototype));
+}
+
+JSObject* JSCanvas::createPrototype(VM& vm, JSDOMGlobalObject* globalObject)
+{
+ return JSCanvasPrototype::create(vm, globalObject, JSCanvasPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
+}
+
+extern "C" EncodedJSValue Canvas__create(Zig::GlobalObject* globalObject, void* ptr)
+{
+ auto& vm = globalObject->vm();
+ JSC::Structure* structure = globalObject->JSCanvasStructure();
+ JSCanvas* instance = JSCanvas::create(vm, globalObject, structure, ptr);
+
+ return JSValue::encode(instance);
+}
class JSCommentPrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
diff --git a/src/bun.js/bindings/ZigGeneratedClasses.h b/src/bun.js/bindings/ZigGeneratedClasses.h
index 33aa58487..6328aff09 100644
--- a/src/bun.js/bindings/ZigGeneratedClasses.h
+++ b/src/bun.js/bindings/ZigGeneratedClasses.h
@@ -300,6 +300,56 @@ public:
mutable JSC::WriteBarrier<JSC::Unknown> m_position;
};
+class JSCanvas final : public JSC::JSDestructibleObject {
+public:
+ using Base = JSC::JSDestructibleObject;
+ static JSCanvas* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx);
+
+ DECLARE_EXPORT_INFO;
+ template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ if constexpr (mode == JSC::SubspaceAccess::Concurrently)
+ return nullptr;
+ return WebCore::subspaceForImpl<JSCanvas, WebCore::UseCustomHeapCellType::No>(
+ vm,
+ [](auto& spaces) { return spaces.m_clientSubspaceForCanvas.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForCanvas = std::forward<decltype(space)>(space); },
+ [](auto& spaces) { return spaces.m_subspaceForCanvas.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_subspaceForCanvas = std::forward<decltype(space)>(space); });
+ }
+
+ static void destroy(JSC::JSCell*);
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(static_cast<JSC::JSType>(0b11101110), StructureFlags), info());
+ }
+
+ static JSObject* createPrototype(VM& vm, JSDOMGlobalObject* globalObject);
+ static JSObject* createConstructor(VM& vm, JSGlobalObject* globalObject, JSValue prototype);
+
+ ~JSCanvas();
+
+ void* wrapped() const { return m_ctx; }
+
+ void detach()
+ {
+ m_ctx = nullptr;
+ }
+
+ static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&);
+ static ptrdiff_t offsetOfWrapped() { return OBJECT_OFFSETOF(JSCanvas, m_ctx); }
+
+ void* m_ctx { nullptr };
+
+ JSCanvas(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
+ : Base(vm, structure)
+ {
+ m_ctx = sinkPtr;
+ }
+
+ void finishCreation(JSC::VM&);
+};
+
class JSComment final : public JSC::JSDestructibleObject {
public:
using Base = JSC::JSDestructibleObject;
diff --git a/src/bun.js/bindings/generated_classes.zig b/src/bun.js/bindings/generated_classes.zig
index fc1aa2be6..c9dc467f7 100644
--- a/src/bun.js/bindings/generated_classes.zig
+++ b/src/bun.js/bindings/generated_classes.zig
@@ -922,6 +922,88 @@ pub const JSBuildMessage = struct {
}
}
};
+pub const JSCanvas = struct {
+ const Canvas = Classes.Canvas;
+ const GetterType = fn (*Canvas, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue;
+ const GetterTypeWithThisValue = fn (*Canvas, JSC.JSValue, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue;
+ const SetterType = fn (*Canvas, *JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool;
+ const SetterTypeWithThisValue = fn (*Canvas, JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool;
+ const CallbackType = fn (*Canvas, *JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) JSC.JSValue;
+
+ /// Return the pointer to the wrapped object.
+ /// If the object does not match the type, return null.
+ pub fn fromJS(value: JSC.JSValue) ?*Canvas {
+ JSC.markBinding(@src());
+ return Canvas__fromJS(value);
+ }
+
+ /// Get the Canvas constructor value.
+ /// This loads lazily from the global object.
+ pub fn getConstructor(globalObject: *JSC.JSGlobalObject) JSC.JSValue {
+ JSC.markBinding(@src());
+ return Canvas__getConstructor(globalObject);
+ }
+
+ /// Create a new instance of Canvas
+ pub fn toJS(this: *Canvas, globalObject: *JSC.JSGlobalObject) JSC.JSValue {
+ JSC.markBinding(@src());
+ if (comptime Environment.allow_assert) {
+ const value__ = Canvas__create(globalObject, this);
+ std.debug.assert(value__.as(Canvas).? == this); // If this fails, likely a C ABI issue.
+ return value__;
+ } else {
+ return Canvas__create(globalObject, this);
+ }
+ }
+
+ /// Modify the internal ptr to point to a new instance of Canvas.
+ pub fn dangerouslySetPtr(value: JSC.JSValue, ptr: ?*Canvas) bool {
+ JSC.markBinding(@src());
+ return Canvas__dangerouslySetPtr(value, ptr);
+ }
+
+ /// Detach the ptr from the thisValue
+ pub fn detachPtr(_: *Canvas, value: JSC.JSValue) void {
+ JSC.markBinding(@src());
+ std.debug.assert(Canvas__dangerouslySetPtr(value, null));
+ }
+
+ extern fn Canvas__fromJS(JSC.JSValue) ?*Canvas;
+ extern fn Canvas__getConstructor(*JSC.JSGlobalObject) JSC.JSValue;
+
+ extern fn Canvas__create(globalObject: *JSC.JSGlobalObject, ptr: ?*Canvas) JSC.JSValue;
+
+ extern fn Canvas__dangerouslySetPtr(JSC.JSValue, ?*Canvas) bool;
+
+ comptime {
+ if (@TypeOf(Canvas.constructor) != (fn (*JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) ?*Canvas)) {
+ @compileLog("Canvas.constructor is not a constructor");
+ }
+
+ if (@TypeOf(Canvas.finalize) != (fn (*Canvas) callconv(.C) void)) {
+ @compileLog("Canvas.finalize is not a finalizer");
+ }
+
+ if (@TypeOf(Canvas.getHeight) != GetterType)
+ @compileLog("Expected Canvas.getHeight to be a getter");
+
+ if (@TypeOf(Canvas.setHeight) != SetterType)
+ @compileLog("Expected Canvas.setHeight to be a setter");
+ if (@TypeOf(Canvas.getWidth) != GetterType)
+ @compileLog("Expected Canvas.getWidth to be a getter");
+
+ if (@TypeOf(Canvas.setWidth) != SetterType)
+ @compileLog("Expected Canvas.setWidth to be a setter");
+ if (!JSC.is_bindgen) {
+ @export(Canvas.constructor, .{ .name = "CanvasClass__construct" });
+ @export(Canvas.finalize, .{ .name = "CanvasClass__finalize" });
+ @export(Canvas.getHeight, .{ .name = "CanvasPrototype__getHeight" });
+ @export(Canvas.getWidth, .{ .name = "CanvasPrototype__getWidth" });
+ @export(Canvas.setHeight, .{ .name = "CanvasPrototype__setHeight" });
+ @export(Canvas.setWidth, .{ .name = "CanvasPrototype__setWidth" });
+ }
+ }
+};
pub const JSComment = struct {
const Comment = Classes.Comment;
const GetterType = fn (*Comment, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue;
@@ -7090,6 +7172,7 @@ comptime {
_ = JSBlob;
_ = JSBuildArtifact;
_ = JSBuildMessage;
+ _ = JSCanvas;
_ = JSComment;
_ = JSCrypto;
_ = JSCryptoHasher;
diff --git a/src/bun.js/bindings/generated_classes_list.zig b/src/bun.js/bindings/generated_classes_list.zig
index 3b45f33b8..285c10dda 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 Canvas = JSC.API.JSCanvas;
+ pub const JSCanvas = Canvas;
};
diff --git a/src/jsc.zig b/src/jsc.zig
index 5cdf739b3..d7a2798f3 100644
--- a/src/jsc.zig
+++ b/src/jsc.zig
@@ -32,6 +32,7 @@ pub const API = struct {
pub const JSBundler = @import("./bun.js/api/JSBundler.zig").JSBundler;
pub const BuildArtifact = @import("./bun.js/api/JSBundler.zig").BuildArtifact;
pub const JSTranspiler = @import("./bun.js/api/JSTranspiler.zig");
+ pub const JSCanvas = @import("./bun.js/api/JSCanvas.zig");
pub const HTTPServer = @import("./bun.js/api/server.zig").HTTPServer;
pub const ServerConfig = @import("./bun.js/api/server.zig").ServerConfig;
pub const ServerWebSocket = @import("./bun.js/api/server.zig").ServerWebSocket;