From 54df5c032dd06fbe85fa66ea22aebb1ffb529242 Mon Sep 17 00:00:00 2001 From: Dylan Conway Date: Thu, 30 Nov 2023 16:48:53 -0800 Subject: [PATCH] `createEmptyObjectWithNullPrototype` --- src/bun.js/bindings/bindings.cpp | 11 +++-------- src/bun.js/bindings/bindings.zig | 7 +++---- src/bun.js/node/util/parse_args.zig | 2 +- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp index 7b24356abe..cb4f7769c0 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -1601,15 +1601,10 @@ JSC__JSObject__create(JSC__JSGlobalObject* globalObject, size_t initialCapacity, return JSC::JSValue::encode(object); } -JSC__JSValue JSC__JSValue__constructEmptyObject(JSC__JSGlobalObject* globalObject, - JSC__JSObject* prototype, - size_t initialCapacity) +JSC__JSValue JSC__JSValue__createEmptyObjectWithNullPrototype(JSC__JSGlobalObject* globalObject) { - if (prototype == nullptr) { - return JSC::JSValue::encode(JSC::constructEmptyObject(globalObject->vm(), globalObject->nullPrototypeObjectStructure())); - } else { - return JSC::JSValue::encode(JSC::constructEmptyObject(globalObject, prototype, std::min(static_cast(initialCapacity), JSFinalObject::maxInlineCapacity))); - } + return JSValue::encode( + JSC::constructEmptyObject(globalObject->vm(), globalObject->nullPrototypeObjectStructure())); } JSC__JSValue JSC__JSValue__createEmptyObject(JSC__JSGlobalObject* globalObject, diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index ce9b0f4732..f4b90fc099 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -3555,11 +3555,10 @@ pub const JSValue = enum(JSValueReprInt) { return JSC__jsTypeStringForValue(globalObject, this); } - extern fn JSC__JSValue__constructEmptyObject(globalObject: *JSGlobalObject, prototype: [*c]JSC.JSObject, len: usize) JSValue; + extern fn JSC__JSValue__createEmptyObjectWithNullPrototype(globalObject: *JSGlobalObject) JSValue; - /// Creates a new empty object with the specified prototype, or no prototype if null - pub fn constructEmptyObject(global: *JSGlobalObject, prototype: ?*JSC.JSObject, len: usize) JSValue { - return JSC__JSValue__constructEmptyObject(global, prototype, len); + pub fn createEmptyObjectWithNullPrototype(global: *JSGlobalObject) JSValue { + return JSC__JSValue__createEmptyObjectWithNullPrototype(global); } /// Creates a new empty object, with Object as its prototype diff --git a/src/bun.js/node/util/parse_args.zig b/src/bun.js/node/util/parse_args.zig index 13c34a2ebe..bddeff6282 100644 --- a/src/bun.js/node/util/parse_args.zig +++ b/src/bun.js/node/util/parse_args.zig @@ -622,7 +622,7 @@ pub fn parseArgs(globalThis: *JSGlobalObject, config_obj: JSValue) !JSValue { log("Phase 2: parse options from tokens (tokens.len={d})", .{tokens.items.len}); // note that "values" needs to have a null prototype instead of Object, to avoid issues such as "values.toString"` being defined - var result_values = JSValue.constructEmptyObject(globalThis, null, 0); + var result_values = JSValue.createEmptyObjectWithNullPrototype(globalThis); var result_positionals = JSC.JSValue.createEmptyArray(globalThis, 0); var result_positionals_len: u32 = 0; for (tokens.items) |t| {