Repository navigation
Conversation
This comment was marked as duplicate.
This comment was marked as duplicate.
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (5)
src/bun.js/bindings/ZigException.zig (1)
31-50: Fix leak: missing deref for browser_url in deinit()browser_url is a GC-owned String but isn’t deref’d; this leaks when populated.
Apply this diff:
pub fn deinit(this: *ZigException) void { this.syscall.deref(); this.system_code.deref(); this.path.deref(); this.name.deref(); this.message.deref(); + this.browser_url.deref(); for (this.stack.source_lines_ptr[0..this.stack.source_lines_len]) |*line| { line.deref(); }src/bun.js/bindings/webcore/Worker.cpp (1)
517-527: Invalid return in void function.return worker->dispatchErrorWithMessage(...) is ill-formed in a void-returning function. Replace with a call then return.
- case WorkerOptions::Kind::Web: - return worker->dispatchErrorWithMessage(message.toWTFString(BunString::ZeroCopy)); + case WorkerOptions::Kind::Web: + worker->dispatchErrorWithMessage(message.toWTFString(BunString::ZeroCopy)); + return;src/bun.zig (1)
2672-2691: Replace std.meta.trait usages — build will break on Zig ≥0.13rg found usages at src/bun.zig:666 (std.meta.trait.isSingleItemPtr in isHeapMemory) and src/util.zig:207 (std.meta.trait.isSlice). Replace these with @TypeOf/@typeInfo-based checks or pin the project to Zig <0.13.
src/codegen/generate-classes.ts (2)
215-231: Remove duplicatefnin destructuring (SyntaxError)The var destructuring in src/codegen/generate-classes.ts (propRow) lists
fntwice, causing a SyntaxError that will block execution — remove the duplicatefnentry.Location: src/codegen/generate-classes.ts — lines ~215–231 (var { ... fn, accessor, fn, ... } = ...)
Suggested change:
- fn, - accessor, - fn, + fn, + accessor,
1102-1106: Replace invalidproto[name].this!!with!!proto[name].thisproto[name].this!! is invalid JS/TS; use boolean coercion as !!proto[name].this.
File: src/codegen/generate-classes.ts — occurrences to fix: ~1103–1106, ~1148–1152, ~1177–1179, ~1202–1204, ~1227–1229
- proto[name].this!! ? " encodedThisValue, " : "" + !!proto[name].this ? " encodedThisValue, " : ""- proto[name].this!! ? " thisValue, " : "" + !!proto[name].this ? " thisValue, " : ""
🧹 Nitpick comments (9)
src/bun.js/bindings/ZigException.zig (2)
27-29: Optional: align param name with bindings conventionProject convention in src/bun.js/**/*.zig prefers globalObject over global.
Apply:
- pub fn collectSourceLines(this: *ZigException, value: JSValue, global: *JSGlobalObject) void { - bun.cpp.ZigException__collectSourceLines(value, global, this); + pub fn collectSourceLines(this: *ZigException, value: JSValue, globalObject: *JSGlobalObject) void { + bun.cpp.ZigException__collectSourceLines(value, globalObject, this); }
121-123: Consistency: consider routing fromException via bun.cpp as wellFor consistency with this PR’s direction, consider exposing fromException through bun.cpp and re-exporting it here (if the C++ bridge already provides it). Not a blocker.
src/bun.js/web_worker.zig (1)
384-387: Unnecessary fromJSHostCallGeneric wrapper; call nothrow bridge directly.The C++ bridge is marked nothrow. You can simplify and avoid the extra catch path.
- bun.jsc.fromJSHostCallGeneric(vm.global, @src(), bun.cpp.WebWorker__dispatchError, .{ vm.global, this.cpp_worker, str, err }) catch |e| { - _ = vm.global.reportUncaughtException(vm.global.takeException(e).asException(vm.global.vm()).?); - }; + bun.cpp.WebWorker__dispatchError(vm.global, this.cpp_worker, str, err);src/bun.js/SavedSourceMap.zig (2)
18-21: Removed inline keywords from lock/unlock methodsThe
lockandunlockmethods are no longerinline. This changes their linkage and may have performance implications since mutex operations are typically small and benefit from inlining.Consider whether these methods still benefit from being inlined, especially since mutex operations are typically small, frequent operations. If performance is critical, you may want to restore the
inlinekeyword:-pub fn lock(map: *SavedSourceMap) void { +pub inline fn lock(map: *SavedSourceMap) void { map.mutex.lock(); map.map.unlockPointers(); } -pub fn unlock(map: *SavedSourceMap) void { +pub inline fn unlock(map: *SavedSourceMap) void { map.map.lockPointers(); map.mutex.unlock(); }Also applies to: 23-26
38-40: Removed inline from SavedMappings.len methodThe
lenmethod is no longerinline. Given that this method just performs a simple cast and is likely called frequently, it would typically benefit from inlining.Consider restoring the
inlinekeyword for this simple accessor method:-pub fn len(this: SavedMappings) usize { +pub inline fn len(this: SavedMappings) usize { return @as(u64, @bitCast(this.data[0..8].*)); }src/bun.js/bindings/bindings.cpp (2)
3154-3158: Handle tagged UTF‑16 inputs in ZigString__to16BitValueIf a ZigString carries a tagged UTF‑16 pointer, we should avoid interpreting it as UTF‑8. A small guard keeps behavior correct for both encodings while still copying into a JS string.
Apply this diff:
[[ZIG_EXPORT(nothrow)]] JSC::EncodedJSValue ZigString__to16BitValue(const ZigString* arg0, JSC::JSGlobalObject* arg1) { - auto str = WTF::String::fromUTF8(std::span { arg0->ptr, arg0->len }); - return JSC::JSValue::encode(JSC::jsString(arg1->vm(), str)); + if (isTaggedUTF16Ptr(arg0->ptr)) { + // Copy from 16-bit buffer + auto sv = WTF::StringView( + std::span{ reinterpret_cast<const char16_t*>(untag(arg0->ptr)), arg0->len }); + return JSC::JSValue::encode(JSC::jsString(arg1->vm(), WTF::String(sv))); + } + auto s8 = WTF::String::fromUTF8(std::span{ arg0->ptr, arg0->len }); + return JSC::JSValue::encode(JSC::jsString(arg1->vm(), s8)); }
2105-2125: Optional: also mark unwrapBoxedPrimitive as nothrow for consistencyThis wrapper doesn’t throw C++ exceptions and would benefit from the same annotation for consistency across FFI.
Apply this diff:
-extern "C" JSC::EncodedJSValue JSC__JSValue__unwrapBoxedPrimitive(JSGlobalObject* globalObject, EncodedJSValue encodedValue) +extern "C" [[ZIG_EXPORT(nothrow)]] JSC::EncodedJSValue JSC__JSValue__unwrapBoxedPrimitive(JSGlobalObject* globalObject, EncodedJSValue encodedValue)src/bun.js/api/bun/socket.zig (2)
1537-1569: Initialize raw handler VM from the current socket’s handlers, not the new TLS handlers.Using vm from handlers (the new TLS handlers) may be equivalent, but it’s safer to source VM from this.getHandlers() to avoid cross-realm mixups.
Apply:
- const vm = handlers.vm; + const vm = this.getHandlers().vm;
1985-2038: Add errdefer cleanup for duplex upgrade to avoid leaks on later errors; clarify ownership move of ssl_opts.
- If any later try fails (e.g., createEmptyArray, UpgradedDuplex.from), handlers_ptr and tls will leak.
- Make ownership transfer explicit by nulling ssl_opts after copying to socket_config.
Apply:
- const socket_config = ssl_opts.?; + const socket_config = ssl_opts.?; + // Make ownership transfer explicit; DuplexUpgradeContext will deinit it + ssl_opts = null;Add errdefer after allocations:
- var handlers_ptr = bun.new(Handlers, undefined); + var handlers_ptr = bun.new(Handlers, undefined); + errdefer { + // If we fail later, unprotect & destroy handlers + handlers_ptr.unprotect(); + bun.destroy(handlers_ptr); + } @@ - var tls = bun.new(TLSSocket, .{ + var tls = bun.new(TLSSocket, .{ .ref_count = .init(), .handlers = handlers_ptr, .this_value = .zero, .socket = TLSSocket.Socket.detached, .connection = null, .wrapped = .tls, .protos = if (protos) |p| bun.handleOom(bun.default_allocator.dupe(u8, p[0..protos_len])) else null, .server_name = if (socket_config.server_name) |server_name| bun.handleOom(bun.default_allocator.dupe(u8, server_name[0..bun.len(server_name)])) else null, .socket_context = null, // only set after the wrapTLS }); + // Protect against early exit (throws) below this point + errdefer tls.deref();This keeps invariants tight in OOM/throwing paths.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (25)
scripts/build-jsc.ts(2 hunks)src/bun.js/SavedSourceMap.zig(3 hunks)src/bun.js/api/bun/socket.zig(4 hunks)src/bun.js/api/server.zig(1 hunks)src/bun.js/bindings/BunPlugin.cpp(3 hunks)src/bun.js/bindings/BunPlugin.h(2 hunks)src/bun.js/bindings/JSGlobalObject.zig(4 hunks)src/bun.js/bindings/ZigException.zig(1 hunks)src/bun.js/bindings/ZigGlobalObject.cpp(14 hunks)src/bun.js/bindings/ZigSourceProvider.cpp(1 hunks)src/bun.js/bindings/ZigString.zig(8 hunks)src/bun.js/bindings/bindings.cpp(9 hunks)src/bun.js/bindings/webcore/Worker.cpp(2 hunks)src/bun.js/jsc/host_fn.zig(1 hunks)src/bun.js/web_worker.zig(4 hunks)src/bun.js/webcore/Blob.zig(1 hunks)src/bun.js/webcore/ReadableStream.zig(1 hunks)src/bun.js/webcore/S3File.zig(1 hunks)src/bun.zig(3 hunks)src/codegen/cppbind.ts(2 hunks)src/codegen/generate-classes.ts(14 hunks)src/codegen/shared-types.ts(1 hunks)src/js/internal/streams/native-readable.ts(1 hunks)src/sourcemap/sourcemap.zig(1 hunks)src/string.zig(1 hunks)
🧰 Additional context used
📓 Path-based instructions (14)
**/*.{js,ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Format JavaScript/TypeScript files with Prettier (bun run prettier)
Files:
src/codegen/shared-types.tssrc/js/internal/streams/native-readable.tsscripts/build-jsc.tssrc/codegen/generate-classes.tssrc/codegen/cppbind.ts
src/**/*.zig
📄 CodeRabbit inference engine (.cursor/rules/building-bun.mdc)
Implement debug logs in Zig using
const log = bun.Output.scoped(.${SCOPE}, false);and invokinglog("...", .{})
Files:
src/sourcemap/sourcemap.zigsrc/bun.js/jsc/host_fn.zigsrc/bun.js/bindings/ZigException.zigsrc/bun.js/SavedSourceMap.zigsrc/string.zigsrc/bun.js/webcore/ReadableStream.zigsrc/bun.js/api/server.zigsrc/bun.js/web_worker.zigsrc/bun.js/webcore/Blob.zigsrc/bun.zigsrc/bun.js/webcore/S3File.zigsrc/bun.js/bindings/ZigString.zigsrc/bun.js/api/bun/socket.zigsrc/bun.js/bindings/JSGlobalObject.zig
**/*.zig
📄 CodeRabbit inference engine (.cursor/rules/javascriptcore-class.mdc)
**/*.zig: Declare the extern C symbol in Zig and export a Zig-friendly alias for use
Wrap the Bun____toJS extern in a Zig method that takes a JSGlobalObject and returns JSC.JSValue
**/*.zig: Format Zig files with zig-format (bun run zig-format)
In Zig, manage memory carefully with allocators and use defer for cleanup
Files:
src/sourcemap/sourcemap.zigsrc/bun.js/jsc/host_fn.zigsrc/bun.js/bindings/ZigException.zigsrc/bun.js/SavedSourceMap.zigsrc/string.zigsrc/bun.js/webcore/ReadableStream.zigsrc/bun.js/api/server.zigsrc/bun.js/web_worker.zigsrc/bun.js/webcore/Blob.zigsrc/bun.zigsrc/bun.js/webcore/S3File.zigsrc/bun.js/bindings/ZigString.zigsrc/bun.js/api/bun/socket.zigsrc/bun.js/bindings/JSGlobalObject.zig
src/bun.js/**/*.zig
📄 CodeRabbit inference engine (.cursor/rules/zig-javascriptcore-classes.mdc)
src/bun.js/**/*.zig: In Zig binding structs, expose generated bindings via pub const js = JSC.Codegen.JS and re-export toJS/fromJS/fromJSDirect
Constructors and prototype methods should return bun.JSError!JSC.JSValue to integrate Zig error handling with JS exceptions
Use parameter name globalObject (not ctx) and accept (*JSC.JSGlobalObject, *JSC.CallFrame) in binding methods/constructors
Implement getters as get(this, globalObject) returning JSC.JSValue and matching the .classes.ts interface
Provide deinit() for resource cleanup and finalize() that calls deinit(); use bun.destroy(this) or appropriate destroy pattern
Access JS call data via CallFrame (argument(i), argumentCount(), thisValue()) and throw errors with globalObject.throw(...)
For properties marked cache: true, use the generated Zig accessors (NameSetCached/GetCached) to work with GC-owned values
In finalize() for objects holding JS references, release them using .deref() before destroy
Files:
src/bun.js/jsc/host_fn.zigsrc/bun.js/bindings/ZigException.zigsrc/bun.js/SavedSourceMap.zigsrc/bun.js/webcore/ReadableStream.zigsrc/bun.js/api/server.zigsrc/bun.js/web_worker.zigsrc/bun.js/webcore/Blob.zigsrc/bun.js/webcore/S3File.zigsrc/bun.js/bindings/ZigString.zigsrc/bun.js/api/bun/socket.zigsrc/bun.js/bindings/JSGlobalObject.zig
src/js/internal/**/*.{js,ts}
📄 CodeRabbit inference engine (src/js/CLAUDE.md)
Place internal-only modules under
internal/
Files:
src/js/internal/streams/native-readable.ts
src/js/{builtins,node,bun,thirdparty,internal}/**/*.{js,ts}
📄 CodeRabbit inference engine (src/js/CLAUDE.md)
src/js/{builtins,node,bun,thirdparty,internal}/**/*.{js,ts}: Use.$calland.$applyinstead of.callor.applyto avoid user tampering
Use string-literalrequire("...")only (no dynamic or non-literal specifiers)
Author modules as CommonJS-style withrequire(...)and export viaexport default {}(no ESMimport/named exports)
Prefer JSC intrinsics and$-prefixed private APIs for performance and safety (e.g.,$Array,$newArrayWithSize,$putByIdDirectPrivate,$assert,$debug)
Validate function arguments with$isCallableand throw$ERR_INVALID_ARG_TYPEfor invalid callbacks
Use$isObjectand throw appropriate TypeErrors for constructor/initializer inputs that must be objects
Files:
src/js/internal/streams/native-readable.ts
src/js/**/*.{js,ts}
📄 CodeRabbit inference engine (CLAUDE.md)
src/js/**/*.{js,ts}: In built-in modules (src/js), require() must use string literals resolved at compile time
In built-in modules (src/js), use export default (converted to a return statement by the preprocessor)
Files:
src/js/internal/streams/native-readable.ts
**/*.{cpp,h}
📄 CodeRabbit inference engine (.cursor/rules/javascriptcore-class.mdc)
**/*.{cpp,h}: When exposing a JS class with public Constructor and Prototype, define three C++ types: class Foo : public JSC::DestructibleObject (if it has C++ fields), class FooPrototype : public JSC::JSNonFinalObject, and class FooConstructor : public JSC::InternalFunction
If the class has C++ data members, inherit from JSC::DestructibleObject and provide proper destruction; if it has no C++ fields (only JS properties), avoid a class and use JSC::constructEmptyObject(vm, structure) with putDirectOffset
Prefer placing the subspaceFor implementation in the .cpp file rather than the header when possible
Files:
src/bun.js/bindings/ZigSourceProvider.cppsrc/bun.js/bindings/BunPlugin.hsrc/bun.js/bindings/BunPlugin.cppsrc/bun.js/bindings/webcore/Worker.cppsrc/bun.js/bindings/ZigGlobalObject.cppsrc/bun.js/bindings/bindings.cpp
**/*.cpp
📄 CodeRabbit inference engine (.cursor/rules/javascriptcore-class.mdc)
**/*.cpp: Include "root.h" at the top of C++ binding files to satisfy lints
Define prototype properties using a const HashTableValue array and declare accessors/functions with JSC_DECLARE_* macros
Prototype classes should subclass JSC::JSNonFinalObject, provide create/createStructure, DECLARE_INFO, finishCreation that reifies static properties, and set mayBePrototype on the Structure
Custom getters should use JSC_DEFINE_CUSTOM_GETTER, jsDynamicCast to validate this, and throwThisTypeError on mismatch
Custom setters should use JSC_DEFINE_CUSTOM_SETTER, validate this via jsDynamicCast, and store via WriteBarrier/set semantics
Prototype functions should use JSC_DEFINE_HOST_FUNCTION, validate this with jsDynamicCast, and return encoded JSValue
Constructors should subclass JSC::InternalFunction, return internalFunctionSpace in subspaceFor, set the prototype property as non-configurable/non-writable, and provide create/createStructure
Provide a setup function that builds the Prototype, Constructor, and Structure, and assigns them to the LazyClassStructure initializer
Use the cached Structure via globalObject->m_.get(globalObject) when constructing instances
Expose constructors to Zig via an extern "C" function that returns the constructor from the LazyClassStructure
Provide an extern "C" Bun____toJS function that creates an instance using the cached Structure and returns an EncodedJSValue
Files:
src/bun.js/bindings/ZigSourceProvider.cppsrc/bun.js/bindings/BunPlugin.cppsrc/bun.js/bindings/webcore/Worker.cppsrc/bun.js/bindings/ZigGlobalObject.cppsrc/bun.js/bindings/bindings.cpp
**/*.{cpp,cc,cxx,h,hpp,hxx}
📄 CodeRabbit inference engine (CLAUDE.md)
Format C/C++ sources/headers with clang-format (bun run clang-format)
Files:
src/bun.js/bindings/ZigSourceProvider.cppsrc/bun.js/bindings/BunPlugin.hsrc/bun.js/bindings/BunPlugin.cppsrc/bun.js/bindings/webcore/Worker.cppsrc/bun.js/bindings/ZigGlobalObject.cppsrc/bun.js/bindings/bindings.cpp
src/bun.js/bindings/**/*.cpp
📄 CodeRabbit inference engine (CLAUDE.md)
src/bun.js/bindings/**/*.cpp: For JS classes with a public constructor, implement Foo, FooPrototype, and FooConstructor (JSC patterns)
Define class properties using HashTableValue arrays in JSC bindings
Add iso subspaces for classes with C++ fields in JSC bindings
Cache structures in ZigGlobalObject for JSC-bound classes
Files:
src/bun.js/bindings/ZigSourceProvider.cppsrc/bun.js/bindings/BunPlugin.cppsrc/bun.js/bindings/webcore/Worker.cppsrc/bun.js/bindings/ZigGlobalObject.cppsrc/bun.js/bindings/bindings.cpp
src/{**/js_*.zig,bun.js/api/**/*.zig}
📄 CodeRabbit inference engine (.cursor/rules/registering-bun-modules.mdc)
Use bun.JSError!JSValue for proper error propagation in JS-exposed Zig functions
Files:
src/bun.js/api/server.zigsrc/bun.js/api/bun/socket.zig
src/bun.js/bindings/ZigGlobalObject.cpp
📄 CodeRabbit inference engine (.cursor/rules/javascriptcore-class.mdc)
Initialize the LazyClassStructure in GlobalObject::finishCreation and visit it in GlobalObject::visitChildrenImpl
Files:
src/bun.js/bindings/ZigGlobalObject.cpp
src/bun.js/bindings/ZigGlobalObject.{h,cpp}
📄 CodeRabbit inference engine (.cursor/rules/javascriptcore-class.mdc)
If only a class (no public constructor/prototype), use JSC::LazyProperty<JSGlobalObject, Structure>, initialize it in finishCreation, and visit it in visitChildren
Files:
src/bun.js/bindings/ZigGlobalObject.cpp
🧠 Learnings (48)
📓 Common learnings
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/zig-javascriptcore-classes.mdc:0-0
Timestamp: 2025-08-30T00:13:36.815Z
Learning: Applies to src/bun.js/**/*.zig : In Zig binding structs, expose generated bindings via pub const js = JSC.Codegen.JS<ClassName> and re-export toJS/fromJS/fromJSDirect
Learnt from: CR
PR: oven-sh/bun#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-08T04:44:59.101Z
Learning: For platform-specific changes, run bun run zig:check-all to compile on all platforms
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/zig-javascriptcore-classes.mdc:0-0
Timestamp: 2025-08-30T00:13:36.815Z
Learning: Applies to src/bun.js/bindings/generated_classes_list.zig : Update src/bun.js/bindings/generated_classes_list.zig to include new classes
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/registering-bun-modules.mdc:0-0
Timestamp: 2025-08-30T00:11:57.076Z
Learning: Applies to src/{**/js_*.zig,bun.js/api/**/*.zig} : Use bun.JSError!JSValue for proper error propagation in JS-exposed Zig functions
Learnt from: CR
PR: oven-sh/bun#0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-09-08T00:41:12.052Z
Learning: Applies to src/bun.js/bindings/v8/src/napi/napi.zig : Add new V8 API method mangled symbols to the V8API struct in src/napi/napi.zig for both GCC/Clang and MSVC
Learnt from: CR
PR: oven-sh/bun#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-08T04:44:59.101Z
Learning: Applies to src/bun.js/bindings/**/*.cpp : Cache structures in ZigGlobalObject for JSC-bound classes
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/javascriptcore-class.mdc:0-0
Timestamp: 2025-08-30T00:11:00.890Z
Learning: Applies to **/*.zig : Declare the extern C symbol in Zig and export a Zig-friendly alias for use
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/zig-javascriptcore-classes.mdc:0-0
Timestamp: 2025-08-30T00:13:36.815Z
Learning: Applies to src/bun.js/**/*.zig : Constructors and prototype methods should return bun.JSError!JSC.JSValue to integrate Zig error handling with JS exceptions
Learnt from: CR
PR: oven-sh/bun#0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-09-08T00:41:12.052Z
Learning: Applies to src/bun.js/bindings/v8/V8*.h : Ensure all public V8 API functions are marked with BUN_EXPORT for symbol visibility
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/javascriptcore-class.mdc:0-0
Timestamp: 2025-08-30T00:11:00.890Z
Learning: Applies to **/*.zig : Wrap the Bun__<Type>__toJS extern in a Zig method that takes a JSGlobalObject and returns JSC.JSValue
📚 Learning: 2025-09-08T00:41:12.052Z
Learnt from: CR
PR: oven-sh/bun#0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-09-08T00:41:12.052Z
Learning: Applies to src/bun.js/bindings/v8/src/symbols.txt : Add new V8 API mangled symbols (without leading underscore) to src/symbols.txt
Applied to files:
src/codegen/shared-types.tssrc/bun.js/SavedSourceMap.zigsrc/codegen/generate-classes.ts
📚 Learning: 2025-09-08T04:44:59.101Z
Learnt from: CR
PR: oven-sh/bun#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-08T04:44:59.101Z
Learning: Applies to src/bun.js/bindings/**/*.cpp : Add iso subspaces for classes with C++ fields in JSC bindings
Applied to files:
src/codegen/shared-types.tssrc/bun.js/bindings/BunPlugin.hsrc/codegen/generate-classes.tssrc/bun.js/bindings/BunPlugin.cpp
📚 Learning: 2025-08-30T00:13:36.815Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/zig-javascriptcore-classes.mdc:0-0
Timestamp: 2025-08-30T00:13:36.815Z
Learning: Applies to src/bun.js/bindings/generated_classes_list.zig : Update src/bun.js/bindings/generated_classes_list.zig to include new classes
Applied to files:
src/codegen/shared-types.tssrc/sourcemap/sourcemap.zigsrc/bun.js/bindings/ZigSourceProvider.cppsrc/bun.js/bindings/BunPlugin.hsrc/bun.js/bindings/ZigException.zigsrc/bun.js/SavedSourceMap.zigsrc/codegen/generate-classes.tssrc/codegen/cppbind.tssrc/string.zigsrc/bun.js/web_worker.zigsrc/bun.zigsrc/bun.js/bindings/BunPlugin.cppsrc/bun.js/bindings/ZigString.zigsrc/bun.js/api/bun/socket.zigsrc/bun.js/bindings/JSGlobalObject.zigsrc/bun.js/bindings/bindings.cpp
📚 Learning: 2025-09-08T00:41:12.052Z
Learnt from: CR
PR: oven-sh/bun#0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-09-08T00:41:12.052Z
Learning: Applies to src/bun.js/bindings/v8/src/symbols.dyn : Add new V8 API mangled symbols (with leading underscore and semicolons) to src/symbols.dyn
Applied to files:
src/codegen/shared-types.tssrc/codegen/generate-classes.ts
📚 Learning: 2025-09-08T00:41:12.052Z
Learnt from: CR
PR: oven-sh/bun#0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-09-08T00:41:12.052Z
Learning: Applies to src/bun.js/bindings/v8/V8*.h : Ensure all public V8 API functions are marked with BUN_EXPORT for symbol visibility
Applied to files:
src/codegen/shared-types.tssrc/bun.js/bindings/ZigSourceProvider.cppsrc/bun.js/bindings/BunPlugin.hsrc/bun.js/web_worker.zigsrc/bun.js/bindings/BunPlugin.cppsrc/bun.js/bindings/JSGlobalObject.zig
📚 Learning: 2025-09-08T04:44:59.101Z
Learnt from: CR
PR: oven-sh/bun#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-08T04:44:59.101Z
Learning: Applies to src/bun.js/bindings/**/*.cpp : Define class properties using HashTableValue arrays in JSC bindings
Applied to files:
src/codegen/shared-types.ts
📚 Learning: 2025-09-07T05:41:52.563Z
Learnt from: CR
PR: oven-sh/bun#0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-09-07T05:41:52.563Z
Learning: Applies to src/js/{builtins,node,bun,thirdparty,internal}/**/*.{js,ts} : Prefer JSC intrinsics and `$`-prefixed private APIs for performance and safety (e.g., `$Array`, `$newArrayWithSize`, `$putByIdDirectPrivate`, `$assert`, `$debug`)
Applied to files:
src/codegen/shared-types.ts
📚 Learning: 2025-09-08T00:41:12.052Z
Learnt from: CR
PR: oven-sh/bun#0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-09-08T00:41:12.052Z
Learning: Applies to src/bun.js/bindings/v8/src/napi/napi.zig : Add new V8 API method mangled symbols to the V8API struct in src/napi/napi.zig for both GCC/Clang and MSVC
Applied to files:
src/sourcemap/sourcemap.zigsrc/bun.js/bindings/ZigSourceProvider.cppsrc/bun.js/bindings/BunPlugin.hsrc/bun.js/bindings/ZigException.zigsrc/codegen/generate-classes.tssrc/codegen/cppbind.tssrc/string.zigsrc/bun.js/web_worker.zigsrc/bun.js/bindings/BunPlugin.cppsrc/bun.js/bindings/ZigString.zigsrc/bun.js/bindings/JSGlobalObject.zigsrc/bun.js/bindings/ZigGlobalObject.cppsrc/bun.js/bindings/bindings.cpp
📚 Learning: 2025-08-30T00:13:36.815Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/zig-javascriptcore-classes.mdc:0-0
Timestamp: 2025-08-30T00:13:36.815Z
Learning: Applies to src/bun.js/**/*.zig : In Zig binding structs, expose generated bindings via pub const js = JSC.Codegen.JS<ClassName> and re-export toJS/fromJS/fromJSDirect
Applied to files:
src/sourcemap/sourcemap.zigsrc/bun.js/jsc/host_fn.zigsrc/bun.js/bindings/ZigSourceProvider.cppsrc/bun.js/bindings/BunPlugin.hsrc/bun.js/bindings/ZigException.zigsrc/bun.js/SavedSourceMap.zigsrc/codegen/generate-classes.tssrc/codegen/cppbind.tssrc/string.zigsrc/bun.js/webcore/ReadableStream.zigsrc/bun.js/web_worker.zigsrc/bun.zigsrc/bun.js/webcore/S3File.zigsrc/bun.js/bindings/BunPlugin.cppsrc/bun.js/bindings/ZigString.zigsrc/bun.js/bindings/JSGlobalObject.zigsrc/bun.js/bindings/ZigGlobalObject.cppsrc/bun.js/bindings/bindings.cpp
📚 Learning: 2025-08-30T00:11:00.890Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/javascriptcore-class.mdc:0-0
Timestamp: 2025-08-30T00:11:00.890Z
Learning: Applies to **/*.zig : Declare the extern C symbol in Zig and export a Zig-friendly alias for use
Applied to files:
src/sourcemap/sourcemap.zigsrc/bun.js/bindings/ZigSourceProvider.cppsrc/codegen/generate-classes.tssrc/codegen/cppbind.tssrc/bun.js/bindings/ZigString.zigsrc/bun.js/bindings/ZigGlobalObject.cppsrc/bun.js/bindings/bindings.cpp
📚 Learning: 2025-08-30T00:13:36.815Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/zig-javascriptcore-classes.mdc:0-0
Timestamp: 2025-08-30T00:13:36.815Z
Learning: Applies to src/bun.js/**/*.zig : Constructors and prototype methods should return bun.JSError!JSC.JSValue to integrate Zig error handling with JS exceptions
Applied to files:
src/bun.js/jsc/host_fn.zigsrc/bun.js/bindings/ZigSourceProvider.cppsrc/bun.js/bindings/BunPlugin.hsrc/bun.js/bindings/ZigException.zigsrc/codegen/generate-classes.tssrc/codegen/cppbind.tssrc/string.zigsrc/bun.js/webcore/ReadableStream.zigsrc/bun.js/api/server.zigsrc/bun.js/web_worker.zigsrc/bun.js/webcore/Blob.zigsrc/bun.js/webcore/S3File.zigsrc/bun.js/bindings/BunPlugin.cppsrc/bun.js/bindings/ZigString.zigsrc/bun.js/bindings/JSGlobalObject.zigsrc/bun.js/bindings/ZigGlobalObject.cppsrc/bun.js/bindings/bindings.cpp
📚 Learning: 2025-08-30T00:11:57.076Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/registering-bun-modules.mdc:0-0
Timestamp: 2025-08-30T00:11:57.076Z
Learning: Applies to src/{**/js_*.zig,bun.js/api/**/*.zig} : Use bun.JSError!JSValue for proper error propagation in JS-exposed Zig functions
Applied to files:
src/bun.js/jsc/host_fn.zigsrc/bun.js/bindings/ZigSourceProvider.cppsrc/bun.js/bindings/BunPlugin.hsrc/bun.js/bindings/ZigException.zigsrc/codegen/generate-classes.tssrc/codegen/cppbind.tssrc/string.zigsrc/bun.js/webcore/ReadableStream.zigsrc/bun.js/api/server.zigsrc/bun.js/web_worker.zigsrc/bun.js/webcore/Blob.zigsrc/bun.js/webcore/S3File.zigsrc/bun.js/bindings/BunPlugin.cppsrc/bun.js/bindings/ZigString.zigsrc/bun.js/bindings/webcore/Worker.cppsrc/bun.js/bindings/JSGlobalObject.zigsrc/bun.js/bindings/ZigGlobalObject.cppsrc/bun.js/bindings/bindings.cpp
📚 Learning: 2025-08-30T00:13:36.815Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/zig-javascriptcore-classes.mdc:0-0
Timestamp: 2025-08-30T00:13:36.815Z
Learning: Applies to src/bun.js/**/*.zig : Access JS call data via CallFrame (argument(i), argumentCount(), thisValue()) and throw errors with globalObject.throw(...)
Applied to files:
src/bun.js/jsc/host_fn.zigsrc/bun.js/bindings/ZigException.zigsrc/codegen/generate-classes.tssrc/codegen/cppbind.tssrc/string.zigsrc/bun.js/web_worker.zigsrc/bun.js/webcore/Blob.zigsrc/bun.js/webcore/S3File.zigsrc/bun.js/bindings/ZigString.zigsrc/bun.js/bindings/JSGlobalObject.zigsrc/bun.js/bindings/ZigGlobalObject.cppsrc/bun.js/bindings/bindings.cpp
📚 Learning: 2025-08-30T00:13:36.815Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/zig-javascriptcore-classes.mdc:0-0
Timestamp: 2025-08-30T00:13:36.815Z
Learning: Applies to src/bun.js/**/*.zig : Use parameter name globalObject (not ctx) and accept (*JSC.JSGlobalObject, *JSC.CallFrame) in binding methods/constructors
Applied to files:
src/bun.js/jsc/host_fn.zigsrc/bun.js/bindings/BunPlugin.hsrc/bun.js/bindings/ZigException.zigsrc/codegen/generate-classes.tssrc/codegen/cppbind.tssrc/string.zigsrc/bun.js/webcore/ReadableStream.zigsrc/bun.js/web_worker.zigsrc/bun.js/webcore/Blob.zigsrc/bun.js/webcore/S3File.zigsrc/bun.js/bindings/BunPlugin.cppsrc/bun.js/bindings/ZigString.zigsrc/bun.js/bindings/webcore/Worker.cppsrc/bun.js/bindings/JSGlobalObject.zigsrc/bun.js/bindings/ZigGlobalObject.cppsrc/bun.js/bindings/bindings.cpp
📚 Learning: 2025-08-30T00:11:00.890Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/javascriptcore-class.mdc:0-0
Timestamp: 2025-08-30T00:11:00.890Z
Learning: Applies to **/*.zig : Wrap the Bun__<Type>__toJS extern in a Zig method that takes a JSGlobalObject and returns JSC.JSValue
Applied to files:
src/bun.js/jsc/host_fn.zigsrc/bun.js/bindings/ZigSourceProvider.cppsrc/bun.js/bindings/BunPlugin.hsrc/bun.js/bindings/ZigException.zigsrc/codegen/generate-classes.tssrc/codegen/cppbind.tssrc/string.zigsrc/bun.js/webcore/ReadableStream.zigsrc/bun.js/web_worker.zigsrc/bun.js/bindings/BunPlugin.cppsrc/bun.js/bindings/ZigString.zigsrc/bun.js/bindings/webcore/Worker.cppsrc/bun.js/bindings/JSGlobalObject.zigsrc/bun.js/bindings/ZigGlobalObject.cppsrc/bun.js/bindings/bindings.cpp
📚 Learning: 2025-08-30T00:13:36.815Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/zig-javascriptcore-classes.mdc:0-0
Timestamp: 2025-08-30T00:13:36.815Z
Learning: Applies to src/bun.js/**/*.zig : For properties marked cache: true, use the generated Zig accessors (<Prop>NameSetCached/GetCached) to work with GC-owned values
Applied to files:
src/bun.js/jsc/host_fn.zigsrc/bun.js/SavedSourceMap.zigsrc/codegen/generate-classes.ts
📚 Learning: 2025-09-08T04:44:59.101Z
Learnt from: CR
PR: oven-sh/bun#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-08T04:44:59.101Z
Learning: Applies to src/bun.js/bindings/**/*.cpp : Cache structures in ZigGlobalObject for JSC-bound classes
Applied to files:
src/bun.js/jsc/host_fn.zigsrc/bun.js/bindings/BunPlugin.hsrc/bun.js/bindings/ZigException.zigsrc/codegen/generate-classes.tssrc/codegen/cppbind.tssrc/string.zigsrc/bun.js/web_worker.zigsrc/bun.js/bindings/BunPlugin.cppsrc/bun.js/bindings/ZigString.zigsrc/bun.js/bindings/webcore/Worker.cppsrc/bun.js/bindings/JSGlobalObject.zigsrc/bun.js/bindings/ZigGlobalObject.cppsrc/bun.js/bindings/bindings.cpp
📚 Learning: 2025-09-05T19:49:26.188Z
Learnt from: markovejnovic
PR: oven-sh/bun#21728
File: src/valkey/js_valkey_functions.zig:852-867
Timestamp: 2025-09-05T19:49:26.188Z
Learning: In Bun’s Zig code, `.js_undefined` is a valid and preferred JSValue literal for “undefined” (e.g., resolving JSPromise). Do not refactor usages to `jsc.JSValue.jsUndefined()`, especially in src/valkey/js_valkey_functions.zig unsubscribe().
Applied to files:
src/bun.js/jsc/host_fn.zigsrc/bun.js/bindings/ZigException.zigsrc/bun.js/bindings/ZigString.zigsrc/bun.js/bindings/JSGlobalObject.zigsrc/bun.js/bindings/bindings.cpp
📚 Learning: 2025-08-30T00:13:36.815Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/zig-javascriptcore-classes.mdc:0-0
Timestamp: 2025-08-30T00:13:36.815Z
Learning: Applies to src/bun.js/**/*.zig : Implement getters as get<PropertyName>(this, globalObject) returning JSC.JSValue and matching the .classes.ts interface
Applied to files:
src/bun.js/jsc/host_fn.zigsrc/codegen/generate-classes.tssrc/codegen/cppbind.tssrc/string.zigsrc/bun.js/bindings/ZigString.zigsrc/bun.js/bindings/JSGlobalObject.zig
📚 Learning: 2025-09-07T05:41:52.563Z
Learnt from: CR
PR: oven-sh/bun#0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-09-07T05:41:52.563Z
Learning: Applies to src/js/{builtins,node,bun,thirdparty,internal}/**/*.{js,ts} : Author modules as CommonJS-style with `require(...)` and export via `export default {}` (no ESM `import`/named exports)
Applied to files:
scripts/build-jsc.ts
📚 Learning: 2025-08-30T00:12:56.803Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-08-30T00:12:56.803Z
Learning: Applies to test/cli/**/*.{js,ts} : When testing Bun as a CLI, use spawn with bunExe() and bunEnv from harness, and capture stdout/stderr via pipes
Applied to files:
scripts/build-jsc.ts
📚 Learning: 2025-09-03T17:10:13.486Z
Learnt from: CR
PR: oven-sh/bun#0
File: test/CLAUDE.md:0-0
Timestamp: 2025-09-03T17:10:13.486Z
Learning: Applies to test/**/*.test.ts : When spawning Bun in tests, use `bunExe()` and `bunEnv` from `harness`
Applied to files:
scripts/build-jsc.ts
📚 Learning: 2025-09-07T05:41:52.563Z
Learnt from: CR
PR: oven-sh/bun#0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-09-07T05:41:52.563Z
Learning: Applies to src/js/bun/**/*.{js,ts} : Place Bun-specific modules (e.g., `bun:ffi`, `bun:sqlite`) under `bun/`
Applied to files:
scripts/build-jsc.ts
📚 Learning: 2025-09-08T04:44:59.101Z
Learnt from: CR
PR: oven-sh/bun#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-08T04:44:59.101Z
Learning: Applies to test/**/*.test.{ts,tsx} : Avoid shell commands (e.g., find, grep) in tests; use Bun.Glob and built-ins instead
Applied to files:
scripts/build-jsc.ts
📚 Learning: 2025-09-08T04:44:59.101Z
Learnt from: CR
PR: oven-sh/bun#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-08T04:44:59.101Z
Learning: For platform-specific changes, run bun run zig:check-all to compile on all platforms
Applied to files:
src/bun.js/bindings/ZigSourceProvider.cppsrc/codegen/cppbind.ts
📚 Learning: 2025-08-30T00:11:57.076Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/registering-bun-modules.mdc:0-0
Timestamp: 2025-08-30T00:11:57.076Z
Learning: Applies to src/bun.js/api/BunObject.zig : Create a getter function in BunObject.zig (define const Getter with toJSGetter and export it in exportAll)
Applied to files:
src/bun.js/bindings/ZigSourceProvider.cppsrc/codegen/generate-classes.tssrc/bun.js/bindings/ZigString.zig
📚 Learning: 2025-08-30T00:11:57.076Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/registering-bun-modules.mdc:0-0
Timestamp: 2025-08-30T00:11:57.076Z
Learning: Applies to src/**/js_*.zig : Implement JavaScript bindings in a Zig file named with a js_ prefix (e.g., js_smtp.zig, js_your_feature.zig)
Applied to files:
src/bun.js/bindings/ZigException.zigsrc/codegen/generate-classes.tssrc/codegen/cppbind.tssrc/bun.js/bindings/ZigString.zigsrc/bun.js/bindings/ZigGlobalObject.cppsrc/bun.js/bindings/bindings.cpp
📚 Learning: 2025-08-30T00:11:57.076Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/registering-bun-modules.mdc:0-0
Timestamp: 2025-08-30T00:11:57.076Z
Learning: Applies to src/**/js_*.zig : Always implement proper cleanup in deinit() and finalize() for JS-exposed types
Applied to files:
src/bun.js/bindings/ZigException.zigsrc/codegen/generate-classes.tssrc/bun.js/bindings/ZigGlobalObject.cpp
📚 Learning: 2025-08-30T00:11:57.076Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/registering-bun-modules.mdc:0-0
Timestamp: 2025-08-30T00:11:57.076Z
Learning: Applies to src/**/js_*.zig : Handle reference counting correctly with ref()/deref() in JS-facing Zig code
Applied to files:
src/bun.js/bindings/ZigException.zigsrc/bun.js/bindings/ZigString.zig
📚 Learning: 2025-08-30T00:11:00.890Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/javascriptcore-class.mdc:0-0
Timestamp: 2025-08-30T00:11:00.890Z
Learning: Applies to src/bun.js/bindings/ZigGlobalObject.{h,cpp} : If only a class (no public constructor/prototype), use JSC::LazyProperty<JSGlobalObject, Structure>, initialize it in finishCreation, and visit it in visitChildren
Applied to files:
src/bun.js/bindings/ZigException.zigsrc/codegen/generate-classes.tssrc/codegen/cppbind.tssrc/bun.js/bindings/BunPlugin.cppsrc/bun.js/bindings/ZigString.zigsrc/bun.js/bindings/JSGlobalObject.zigsrc/bun.js/bindings/ZigGlobalObject.cppsrc/bun.js/bindings/bindings.cpp
📚 Learning: 2025-08-30T00:11:57.076Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/registering-bun-modules.mdc:0-0
Timestamp: 2025-08-30T00:11:57.076Z
Learning: Applies to src/**/js_bindings.classes.ts : Use JSC.Codegen correctly by defining methods, properties, and metadata in the class definition (define({...}))
Applied to files:
src/codegen/generate-classes.ts
📚 Learning: 2025-08-30T00:11:57.076Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/registering-bun-modules.mdc:0-0
Timestamp: 2025-08-30T00:11:57.076Z
Learning: Applies to src/**/{js_bindings,BunObject}.classes.ts : Add JSDoc comments to JavaScript binding class definitions
Applied to files:
src/codegen/generate-classes.ts
📚 Learning: 2025-09-08T04:44:59.101Z
Learnt from: CR
PR: oven-sh/bun#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-08T04:44:59.101Z
Learning: Applies to src/bun.js/bindings/**/*.cpp : For JS classes with a public constructor, implement Foo, FooPrototype, and FooConstructor (JSC patterns)
Applied to files:
src/codegen/generate-classes.ts
📚 Learning: 2025-09-07T05:41:52.563Z
Learnt from: CR
PR: oven-sh/bun#0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-09-07T05:41:52.563Z
Learning: Applies to src/js/{builtins,node,bun,thirdparty,internal}/**/*.{js,ts} : Use `.$call` and `.$apply` instead of `.call` or `.apply` to avoid user tampering
Applied to files:
src/codegen/generate-classes.ts
📚 Learning: 2025-08-30T00:13:36.815Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/zig-javascriptcore-classes.mdc:0-0
Timestamp: 2025-08-30T00:13:36.815Z
Learning: Applies to src/bun.js/**/*.zig : Provide deinit() for resource cleanup and finalize() that calls deinit(); use bun.destroy(this) or appropriate destroy pattern
Applied to files:
src/codegen/generate-classes.tssrc/bun.js/web_worker.zigsrc/bun.zigsrc/bun.js/bindings/ZigGlobalObject.cpp
📚 Learning: 2025-08-30T00:11:00.890Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/javascriptcore-class.mdc:0-0
Timestamp: 2025-08-30T00:11:00.890Z
Learning: Applies to src/bun.js/bindings/ZigGlobalObject.cpp : Initialize the LazyClassStructure in GlobalObject::finishCreation and visit it in GlobalObject::visitChildrenImpl
Applied to files:
src/codegen/generate-classes.tssrc/bun.js/bindings/JSGlobalObject.zigsrc/bun.js/bindings/ZigGlobalObject.cpp
📚 Learning: 2025-08-30T00:11:00.890Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/javascriptcore-class.mdc:0-0
Timestamp: 2025-08-30T00:11:00.890Z
Learning: Applies to src/bun.js/bindings/ZigGlobalObject.h : When there is a class, prototype, and constructor, add a JSC::LazyClassStructure field for the class to ZigGlobalObject.h
Applied to files:
src/codegen/generate-classes.tssrc/bun.js/bindings/BunPlugin.cppsrc/bun.js/bindings/JSGlobalObject.zigsrc/bun.js/bindings/ZigGlobalObject.cppsrc/bun.js/bindings/bindings.cpp
📚 Learning: 2025-08-30T00:13:36.815Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/zig-javascriptcore-classes.mdc:0-0
Timestamp: 2025-08-30T00:13:36.815Z
Learning: Applies to src/bun.js/**/*.zig : In finalize() for objects holding JS references, release them using .deref() before destroy
Applied to files:
src/codegen/generate-classes.tssrc/bun.js/bindings/ZigGlobalObject.cpp
📚 Learning: 2025-08-30T00:13:36.815Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/zig-javascriptcore-classes.mdc:0-0
Timestamp: 2025-08-30T00:13:36.815Z
Learning: Create Bun JSC class bindings by pairing a TypeScript class interface with a Zig implementation and relying on the generator to produce glue code
Applied to files:
src/codegen/generate-classes.tssrc/codegen/cppbind.ts
📚 Learning: 2025-08-30T00:07:54.573Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/building-bun.mdc:0-0
Timestamp: 2025-08-30T00:07:54.573Z
Learning: Applies to src/**/*.zig : Implement debug logs in Zig using `const log = bun.Output.scoped(.${SCOPE}, false);` and invoking `log("...", .{})`
Applied to files:
src/codegen/generate-classes.ts
📚 Learning: 2025-08-30T00:11:00.890Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/javascriptcore-class.mdc:0-0
Timestamp: 2025-08-30T00:11:00.890Z
Learning: Applies to **/*.cpp : Provide an extern "C" Bun__<Type>__toJS function that creates an instance using the cached Structure and returns an EncodedJSValue
Applied to files:
src/codegen/generate-classes.tssrc/string.zigsrc/bun.js/bindings/BunPlugin.cppsrc/bun.js/bindings/JSGlobalObject.zigsrc/bun.js/bindings/bindings.cpp
📚 Learning: 2025-09-02T19:14:59.734Z
Learnt from: taylordotfish
PR: oven-sh/bun#0
File: :0-0
Timestamp: 2025-09-02T19:14:59.734Z
Learning: In Zig, the `inline` keyword is not a performance optimization hint. It forces inlining at every call site and has semantic implications on types and values involved in function calls. The Zig documentation advises that "it is generally better to let the compiler decide when to inline a function" rather than manually specifying `inline`. Only use `inline` when there are specific semantic requirements, not for performance optimization.
Applied to files:
src/codegen/cppbind.ts
📚 Learning: 2025-09-02T18:32:32.309Z
Learnt from: taylordotfish
PR: oven-sh/bun#22227
File: src/bun.zig:668-675
Timestamp: 2025-09-02T18:32:32.309Z
Learning: The `std.meta.trait` module has been removed from the Zig standard library, which will cause compilation failures in functions that use it like `std.meta.trait.isSingleItemPtr()`. This affects functions like `isHeapMemory()` in `src/bun.zig`.
Applied to files:
src/bun.zig
📚 Learning: 2025-09-02T18:29:58.304Z
Learnt from: taylordotfish
PR: oven-sh/bun#22227
File: src/memory.zig:37-43
Timestamp: 2025-09-02T18:29:58.304Z
Learning: In bun's `src/memory.zig`, the `initDefault` function intentionally calls `T.init()` without parameter validation to cause compile-time errors when `init` requires arguments or returns an error union. This design forces developers to add explicit `initDefault` methods for complex types rather than silently falling back to `{}`. The `{}` fallback is only intended for types that have no `init` function at all.
Applied to files:
src/bun.zig
📚 Learning: 2025-09-05T19:49:26.188Z
Learnt from: markovejnovic
PR: oven-sh/bun#21728
File: src/valkey/js_valkey_functions.zig:852-867
Timestamp: 2025-09-05T19:49:26.188Z
Learning: In Bun's Zig codebase, `.js_undefined` is a valid way to represent JavaScript's undefined value when working with JSPromise.resolve() and similar JavaScript interop functions. This is the correct pattern to use rather than `jsc.JSValue.jsUndefined()`.
Applied to files:
src/bun.js/bindings/ZigString.zigsrc/bun.js/bindings/bindings.cpp
📚 Learning: 2025-08-30T09:09:18.384Z
Learnt from: Jarred-Sumner
PR: oven-sh/bun#22231
File: src/bundler/bundle_v2.zig:48-48
Timestamp: 2025-08-30T09:09:18.384Z
Learning: In Zig, when a module exports a top-level struct, import("./Module.zig") directly returns that struct type and can be used as a type alias without needing to access a field within the module. This is a common pattern in the Bun codebase.
Applied to files:
src/bun.js/bindings/JSGlobalObject.zig
📚 Learning: 2025-08-30T00:11:00.890Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/javascriptcore-class.mdc:0-0
Timestamp: 2025-08-30T00:11:00.890Z
Learning: Applies to **/*.cpp : Prototype functions should use JSC_DEFINE_HOST_FUNCTION, validate this with jsDynamicCast, and return encoded JSValue
Applied to files:
src/bun.js/bindings/bindings.cpp
🧬 Code graph analysis (6)
src/bun.js/bindings/ZigSourceProvider.cpp (1)
src/bun.js/bindings/ZigGlobalObject.cpp (16)
ZIG_EXPORT(936-1076)ZIG_EXPORT(1121-1134)ZIG_EXPORT(1136-1177)ZIG_EXPORT(2218-2233)ZIG_EXPORT(2280-2283)ZIG_EXPORT(2285-2322)ZIG_EXPORT(2324-2342)ZIG_EXPORT(2344-2363)ZIG_EXPORT(2365-2383)ZIG_EXPORT(2385-2403)ZIG_EXPORT(2405-2408)ZIG_EXPORT(3864-3868)ZIG_EXPORT(3984-3994)ZIG_EXPORT(3996-4001)ZIG_EXPORT(4003-4013)ZIG_EXPORT(4139-4143)
src/bun.js/bindings/BunPlugin.h (1)
src/bun.js/bindings/BunPlugin.cpp (4)
run(711-760)run(711-711)run(781-859)run(781-781)
src/bun.js/bindings/BunPlugin.cpp (2)
src/bun.js/bindings/bindings.cpp (18)
globalObject(2529-2533)globalObject(2529-2529)ZIG_EXPORT(2066-2070)ZIG_EXPORT(2071-2076)ZIG_EXPORT(2126-2155)ZIG_EXPORT(3135-3152)ZIG_EXPORT(3154-3158)ZIG_EXPORT(3160-3169)ZIG_EXPORT(3172-3185)ZIG_EXPORT(3187-3190)ZIG_EXPORT(3192-3195)ZIG_EXPORT(3197-3224)ZIG_EXPORT(3226-3235)ZIG_EXPORT(3237-3247)ZIG_EXPORT(3249-3252)ZIG_EXPORT(3254-3257)ZIG_EXPORT(3259-3262)ZIG_EXPORT(3264-3267)src/bun.js/bindings/BunPlugin.h (1)
target(29-38)
src/bun.js/bindings/webcore/Worker.cpp (1)
src/bun.js/bindings/ZigGlobalObject.cpp (16)
ZIG_EXPORT(936-1076)ZIG_EXPORT(1121-1134)ZIG_EXPORT(1136-1177)ZIG_EXPORT(2218-2233)ZIG_EXPORT(2280-2283)ZIG_EXPORT(2285-2322)ZIG_EXPORT(2324-2342)ZIG_EXPORT(2344-2363)ZIG_EXPORT(2365-2383)ZIG_EXPORT(2385-2403)ZIG_EXPORT(2405-2408)ZIG_EXPORT(3864-3868)ZIG_EXPORT(3984-3994)ZIG_EXPORT(3996-4001)ZIG_EXPORT(4003-4013)ZIG_EXPORT(4139-4143)
src/bun.js/bindings/ZigGlobalObject.cpp (1)
src/bun.js/bindings/bindings.cpp (18)
ZIG_EXPORT(2066-2070)ZIG_EXPORT(2071-2076)ZIG_EXPORT(2126-2155)ZIG_EXPORT(3135-3152)ZIG_EXPORT(3154-3158)ZIG_EXPORT(3160-3169)ZIG_EXPORT(3172-3185)ZIG_EXPORT(3187-3190)ZIG_EXPORT(3192-3195)ZIG_EXPORT(3197-3224)ZIG_EXPORT(3226-3235)ZIG_EXPORT(3237-3247)ZIG_EXPORT(3249-3252)ZIG_EXPORT(3254-3257)ZIG_EXPORT(3259-3262)ZIG_EXPORT(3264-3267)globalObject(2529-2533)globalObject(2529-2529)
src/bun.js/bindings/bindings.cpp (1)
src/bun.js/bindings/ZigGlobalObject.cpp (16)
ZIG_EXPORT(936-1076)ZIG_EXPORT(1121-1134)ZIG_EXPORT(1136-1177)ZIG_EXPORT(2218-2233)ZIG_EXPORT(2280-2283)ZIG_EXPORT(2285-2322)ZIG_EXPORT(2324-2342)ZIG_EXPORT(2344-2363)ZIG_EXPORT(2365-2383)ZIG_EXPORT(2385-2403)ZIG_EXPORT(2405-2408)ZIG_EXPORT(3864-3868)ZIG_EXPORT(3984-3994)ZIG_EXPORT(3996-4001)ZIG_EXPORT(4003-4013)ZIG_EXPORT(4139-4143)
| }; | ||
| jsc.markBinding(@src()); | ||
| WebWorker__dispatchError(globalObject, worker.cpp_worker, bun.String.cloneUTF8(array.slice()), error_instance); | ||
| bun.cpp.WebWorker__dispatchError(globalObject, worker.cpp_worker, bun.String.cloneUTF8(array.slice()), error_instance); |
There was a problem hiding this comment.
Potential BunString leak: cloneUTF8 result is not deref’d.
cloneUTF8 allocates; unlike the earlier path (Line 383) there’s no deref here.
- bun.cpp.WebWorker__dispatchError(globalObject, worker.cpp_worker, bun.String.cloneUTF8(array.slice()), error_instance);
+ var msg = bun.String.cloneUTF8(array.slice());
+ defer msg.deref();
+ bun.cpp.WebWorker__dispatchError(globalObject, worker.cpp_worker, msg, error_instance);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| bun.cpp.WebWorker__dispatchError(globalObject, worker.cpp_worker, bun.String.cloneUTF8(array.slice()), error_instance); | |
| var msg = bun.String.cloneUTF8(array.slice()); | |
| defer msg.deref(); | |
| bun.cpp.WebWorker__dispatchError(globalObject, worker.cpp_worker, msg, error_instance); |
🤖 Prompt for AI Agents
In src/bun.js/web_worker.zig around line 431, the result of bun.String.cloneUTF8
passed to WebWorker__dispatchError is allocated but not deref'd, causing a
BunString leak; follow the earlier pattern used at line 383 and ensure the
cloned bun.String is released after use (e.g., call the same deref/release
function used elsewhere or use defer to release it) so the allocation is freed
on all control paths.
| output += ` | ||
| pub fn ${classSymbolName(typeName, "getInternalProperties")}(thisValue: *${typeName}, globalObject: *jsc.JSGlobalObject, thisValue: jsc.JSValue) callconv(jsc.conv) jsc.JSValue { | ||
| if (comptime Environment.enable_logs) log_zig_get_internal_properties("${typeName}"); | ||
| return @call(.always_inline, ${typeName}.getInternalProperties, .{thisValue, globalObject, thisValue}); | ||
| return @call(bun.callmod_inline, ${typeName}.getInternalProperties, .{thisValue, globalObject, thisValue}); | ||
| } | ||
| `; |
There was a problem hiding this comment.
Duplicate parameter name in generated Zig (breaks compile)
In getInternalProperties, the parameter name thisValue is duplicated. Also fix the call site to pass the renamed param.
Apply:
- pub fn ${classSymbolName(typeName, "getInternalProperties")}(thisValue: *${typeName}, globalObject: *jsc.JSGlobalObject, thisValue: jsc.JSValue) callconv(jsc.conv) jsc.JSValue {
+ pub fn ${classSymbolName(typeName, "getInternalProperties")}(thisValue: *${typeName}, globalObject: *jsc.JSGlobalObject, js_this_value: jsc.JSValue) callconv(jsc.conv) jsc.JSValue {
if (comptime Environment.enable_logs) log_zig_get_internal_properties("${typeName}");
- return @call(bun.callmod_inline, ${typeName}.getInternalProperties, .{thisValue, globalObject, thisValue});
+ return @call(bun.callmod_inline, ${typeName}.getInternalProperties, .{thisValue, globalObject, js_this_value});
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| output += ` | |
| pub fn ${classSymbolName(typeName, "getInternalProperties")}(thisValue: *${typeName}, globalObject: *jsc.JSGlobalObject, thisValue: jsc.JSValue) callconv(jsc.conv) jsc.JSValue { | |
| if (comptime Environment.enable_logs) log_zig_get_internal_properties("${typeName}"); | |
| return @call(.always_inline, ${typeName}.getInternalProperties, .{thisValue, globalObject, thisValue}); | |
| return @call(bun.callmod_inline, ${typeName}.getInternalProperties, .{thisValue, globalObject, thisValue}); | |
| } | |
| `; | |
| output += ` | |
| pub fn ${classSymbolName(typeName, "getInternalProperties")}(thisValue: *${typeName}, globalObject: *jsc.JSGlobalObject, js_this_value: jsc.JSValue) callconv(jsc.conv) jsc.JSValue { | |
| if (comptime Environment.enable_logs) log_zig_get_internal_properties("${typeName}"); | |
| return @call(bun.callmod_inline, ${typeName}.getInternalProperties, .{thisValue, globalObject, js_this_value}); | |
| } | |
| `; |
🤖 Prompt for AI Agents
In src/codegen/generate-classes.ts around lines 2086 to 2091, the generated Zig
function for getInternalProperties declares the parameter name thisValue twice
(once as *{typeName} and again as jsc.JSValue) which causes a duplicate
parameter error; rename the second parameter to a unique identifier (e.g.,
thisValue_js or thisValueValue) and update the call site argument list to pass
that renamed identifier instead of the duplicated name so the return @call
invocation becomes .{thisValue, globalObject, <renamedParam>}.
bun.cpp.updates to c++ functionsbun.callmod_inlineusage for better debugging