From 173f465fbe027934b4276dfe531d37608ea97331 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Wed, 11 Sep 2024 22:04:32 -0700 Subject: [PATCH] :scissors: dead code --- src/bun.js/node/types.zig | 98 --------------------------------------- 1 file changed, 98 deletions(-) diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index 81cb9031ee..c7cc352c4f 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -1835,104 +1835,6 @@ pub const Dirent = struct { } }; -pub const Emitter = struct { - pub const Listener = struct { - once: bool = false, - callback: JSC.JSValue, - - pub const List = struct { - pub const ArrayList = std.MultiArrayList(Listener); - list: ArrayList = ArrayList{}, - once_count: u32 = 0, - - pub fn append(this: *List, allocator: std.mem.Allocator, ctx: JSC.C.JSContextRef, listener: Listener) !void { - JSC.C.JSValueProtect(ctx, listener.callback.asObjectRef()); - try this.list.append(allocator, listener); - this.once_count +|= @as(u32, @intFromBool(listener.once)); - } - - pub fn prepend(this: *List, allocator: std.mem.Allocator, ctx: JSC.C.JSContextRef, listener: Listener) !void { - JSC.C.JSValueProtect(ctx, listener.callback.asObjectRef()); - try this.list.ensureUnusedCapacity(allocator, 1); - this.list.insertAssumeCapacity(0, listener); - this.once_count +|= @as(u32, @intFromBool(listener.once)); - } - - // removeListener() will remove, at most, one instance of a listener from the - // listener array. If any single listener has been added multiple times to the - // listener array for the specified eventName, then removeListener() must be - // called multiple times to remove each instance. - pub fn remove(this: *List, ctx: JSC.C.JSContextRef, callback: JSC.JSValue) bool { - const callbacks = this.list.items(.callback); - - for (callbacks, 0..) |item, i| { - if (callback.eqlValue(item)) { - JSC.C.JSValueUnprotect(ctx, callback.asObjectRef()); - this.once_count -|= @as(u32, @intFromBool(this.list.items(.once)[i])); - this.list.orderedRemove(i); - return true; - } - } - - return false; - } - - pub fn emit(this: *List, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) void { - var i: usize = 0; - outer: while (true) { - var slice = this.list.slice(); - var callbacks = slice.items(.callback); - var once = slice.items(.once); - while (i < callbacks.len) : (i += 1) { - const callback = callbacks[i]; - - globalObject.enqueueMicrotask1( - callback, - value, - ); - - if (once[i]) { - this.once_count -= 1; - JSC.C.JSValueUnprotect(globalObject, callback.asObjectRef()); - this.list.orderedRemove(i); - slice = this.list.slice(); - callbacks = slice.items(.callback); - once = slice.items(.once); - continue :outer; - } - } - - return; - } - } - }; - }; - - pub fn New(comptime EventType: type) type { - return struct { - const EventEmitter = @This(); - pub const Map = std.enums.EnumArray(EventType, Listener.List); - listeners: Map = Map.initFill(Listener.List{}), - - pub fn addListener(this: *EventEmitter, ctx: JSC.C.JSContextRef, event: EventType, listener: Emitter.Listener) !void { - try this.listeners.getPtr(event).append(bun.default_allocator, ctx, listener); - } - - pub fn prependListener(this: *EventEmitter, ctx: JSC.C.JSContextRef, event: EventType, listener: Emitter.Listener) !void { - try this.listeners.getPtr(event).prepend(bun.default_allocator, ctx, listener); - } - - pub fn emit(this: *EventEmitter, event: EventType, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) void { - this.listeners.getPtr(event).emit(globalObject, value); - } - - pub fn removeListener(this: *EventEmitter, ctx: JSC.C.JSContextRef, event: EventType, callback: JSC.JSValue) bool { - return this.listeners.getPtr(event).remove(ctx, callback); - } - }; - } -}; - pub const Process = struct { pub fn getArgv0(globalObject: *JSC.JSGlobalObject) callconv(.C) JSC.JSValue { return JSC.ZigString.fromUTF8(bun.argv[0]).toJS(globalObject);