Skip to content

Commit a234e06

Browse files
Make .get() ignore Object.prototype instead of using getOwn (#14322)
1 parent c20901f commit a234e06

21 files changed

+283
-194
lines changed

src/bun.js/api/BunObject.zig

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,11 @@ pub fn braces(
329329
if (arguments.nextEat()) |opts_val| {
330330
if (opts_val.isObject()) {
331331
if (comptime bun.Environment.allow_assert) {
332-
if (opts_val.getOwnTruthy(globalThis, "tokenize")) |tokenize_val| {
332+
if (opts_val.getTruthy(globalThis, "tokenize")) |tokenize_val| {
333333
tokenize = if (tokenize_val.isBoolean()) tokenize_val.asBoolean() else false;
334334
}
335335

336-
if (opts_val.getOwnTruthy(globalThis, "parse")) |tokenize_val| {
336+
if (opts_val.getTruthy(globalThis, "parse")) |tokenize_val| {
337337
parse = if (tokenize_val.isBoolean()) tokenize_val.asBoolean() else false;
338338
}
339339
}
@@ -461,11 +461,11 @@ pub fn which(
461461

462462
if (arguments.nextEat()) |arg| {
463463
if (!arg.isEmptyOrUndefinedOrNull() and arg.isObject()) {
464-
if (arg.getOwn(globalThis, "PATH")) |str_| {
464+
if (arg.get(globalThis, "PATH")) |str_| {
465465
path_str = str_.toSlice(globalThis, globalThis.bunVM().allocator);
466466
}
467467

468-
if (arg.getOwn(globalThis, "cwd")) |str_| {
468+
if (arg.get(globalThis, "cwd")) |str_| {
469469
cwd_str = str_.toSlice(globalThis, globalThis.bunVM().allocator);
470470
}
471471
}
@@ -514,7 +514,7 @@ pub fn inspect(
514514
const arg1 = arguments[1];
515515

516516
if (arg1.isObject()) {
517-
if (arg1.getOwnTruthy(globalThis, "depth")) |opt| {
517+
if (arg1.getTruthy(globalThis, "depth")) |opt| {
518518
if (opt.isInt32()) {
519519
const arg = opt.toInt32();
520520
if (arg < 0) {
@@ -779,7 +779,7 @@ pub fn openInEditor(
779779

780780
if (arguments.nextEat()) |opts| {
781781
if (!opts.isUndefinedOrNull()) {
782-
if (opts.getOwnTruthy(globalThis, "editor")) |editor_val| {
782+
if (opts.getTruthy(globalThis, "editor")) |editor_val| {
783783
var sliced = editor_val.toSlice(globalThis, arguments.arena.allocator());
784784
const prev_name = edit.name;
785785

@@ -799,11 +799,11 @@ pub fn openInEditor(
799799
}
800800
}
801801

802-
if (opts.getOwnTruthy(globalThis, "line")) |line_| {
802+
if (opts.getTruthy(globalThis, "line")) |line_| {
803803
line = line_.toSlice(globalThis, arguments.arena.allocator()).slice();
804804
}
805805

806-
if (opts.getOwnTruthy(globalThis, "column")) |column_| {
806+
if (opts.getTruthy(globalThis, "column")) |column_| {
807807
column = column_.toSlice(globalThis, arguments.arena.allocator()).slice();
808808
}
809809
}
@@ -1711,7 +1711,7 @@ pub const Crypto = struct {
17111711

17121712
pub fn fromJS(globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) ?Value {
17131713
if (value.isObject()) {
1714-
if (value.getOwnTruthy(globalObject, "algorithm")) |algorithm_value| {
1714+
if (value.getTruthy(globalObject, "algorithm")) |algorithm_value| {
17151715
if (!algorithm_value.isString()) {
17161716
globalObject.throwInvalidArgumentType("hash", "algorithm", "string");
17171717
return null;
@@ -1728,7 +1728,7 @@ pub const Crypto = struct {
17281728
.bcrypt = PasswordObject.Algorithm.Value.bcrpyt_default,
17291729
};
17301730

1731-
if (value.getOwnTruthy(globalObject, "cost")) |rounds_value| {
1731+
if (value.getTruthy(globalObject, "cost")) |rounds_value| {
17321732
if (!rounds_value.isNumber()) {
17331733
globalObject.throwInvalidArgumentType("hash", "cost", "number");
17341734
return null;
@@ -1749,7 +1749,7 @@ pub const Crypto = struct {
17491749
inline .argon2id, .argon2d, .argon2i => |tag| {
17501750
var argon = Algorithm.Argon2Params{};
17511751

1752-
if (value.getOwnTruthy(globalObject, "timeCost")) |time_value| {
1752+
if (value.getTruthy(globalObject, "timeCost")) |time_value| {
17531753
if (!time_value.isNumber()) {
17541754
globalObject.throwInvalidArgumentType("hash", "timeCost", "number");
17551755
return null;
@@ -1765,7 +1765,7 @@ pub const Crypto = struct {
17651765
argon.time_cost = @as(u32, @intCast(time_cost));
17661766
}
17671767

1768-
if (value.getOwnTruthy(globalObject, "memoryCost")) |memory_value| {
1768+
if (value.getTruthy(globalObject, "memoryCost")) |memory_value| {
17691769
if (!memory_value.isNumber()) {
17701770
globalObject.throwInvalidArgumentType("hash", "memoryCost", "number");
17711771
return null;
@@ -4599,11 +4599,11 @@ fn stringWidth(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) JSC
45994599
var ambiguous_as_wide = false;
46004600

46014601
if (options_object.isObject()) {
4602-
if (options_object.getOwnTruthy(globalObject, "countAnsiEscapeCodes")) |count_ansi_escapes_value| {
4602+
if (options_object.getTruthy(globalObject, "countAnsiEscapeCodes")) |count_ansi_escapes_value| {
46034603
if (count_ansi_escapes_value.isBoolean())
46044604
count_ansi_escapes = count_ansi_escapes_value.toBoolean();
46054605
}
4606-
if (options_object.getOwnTruthy(globalObject, "ambiguousIsNarrow")) |ambiguous_is_narrow| {
4606+
if (options_object.getTruthy(globalObject, "ambiguousIsNarrow")) |ambiguous_is_narrow| {
46074607
if (ambiguous_is_narrow.isBoolean())
46084608
ambiguous_as_wide = !ambiguous_is_narrow.toBoolean();
46094609
}
@@ -4784,7 +4784,7 @@ pub const JSZlib = struct {
47844784
library = .zlib;
47854785
}
47864786

4787-
if (options_val.getOwnTruthy(globalThis, "library")) |library_value| {
4787+
if (options_val.getTruthy(globalThis, "library")) |library_value| {
47884788
if (!library_value.isString()) {
47894789
globalThis.throwInvalidArguments("Expected library to be a string", .{});
47904790
return .zero;
@@ -4911,7 +4911,7 @@ pub const JSZlib = struct {
49114911
library = .zlib;
49124912
}
49134913

4914-
if (options_val.getOwnTruthy(globalThis, "library")) |library_value| {
4914+
if (options_val.getTruthy(globalThis, "library")) |library_value| {
49154915
if (!library_value.isString()) {
49164916
globalThis.throwInvalidArguments("Expected library to be a string", .{});
49174917
return .zero;

src/bun.js/api/JSBundler.zig

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub const JSBundler = struct {
109109
return error.JSError;
110110
}
111111

112-
if (plugin.getOwnOptional(globalThis, "name", ZigString.Slice) catch null) |slice| {
112+
if (plugin.getOptional(globalThis, "name", ZigString.Slice) catch null) |slice| {
113113
defer slice.deinit();
114114
if (slice.len == 0) {
115115
globalThis.throwInvalidArguments("Expected plugin to have a non-empty name", .{});
@@ -153,13 +153,13 @@ pub const JSBundler = struct {
153153
}
154154
}
155155

156-
if (config.getOwnTruthy(globalThis, "macros")) |macros_flag| {
156+
if (config.getTruthy(globalThis, "macros")) |macros_flag| {
157157
if (!macros_flag.coerce(bool, globalThis)) {
158158
this.no_macros = true;
159159
}
160160
}
161161

162-
if (try config.getOwnOptional(globalThis, "bytecode", bool)) |bytecode| {
162+
if (try config.getOptional(globalThis, "bytecode", bool)) |bytecode| {
163163
this.bytecode = bytecode;
164164

165165
if (bytecode) {
@@ -169,7 +169,7 @@ pub const JSBundler = struct {
169169
}
170170
}
171171

172-
if (try config.getOwnOptionalEnum(globalThis, "target", options.Target)) |target| {
172+
if (try config.getOptionalEnum(globalThis, "target", options.Target)) |target| {
173173
this.target = target;
174174

175175
if (target != .bun and this.bytecode) {
@@ -179,18 +179,18 @@ pub const JSBundler = struct {
179179
}
180180

181181
var has_out_dir = false;
182-
if (try config.getOwnOptional(globalThis, "outdir", ZigString.Slice)) |slice| {
182+
if (try config.getOptional(globalThis, "outdir", ZigString.Slice)) |slice| {
183183
defer slice.deinit();
184184
try this.outdir.appendSliceExact(slice.slice());
185185
has_out_dir = true;
186186
}
187187

188-
if (try config.getOwnOptional(globalThis, "banner", ZigString.Slice)) |slice| {
188+
if (try config.getOptional(globalThis, "banner", ZigString.Slice)) |slice| {
189189
defer slice.deinit();
190190
try this.banner.appendSliceExact(slice.slice());
191191
}
192192

193-
if (config.getOwnTruthy(globalThis, "sourcemap")) |source_map_js| {
193+
if (config.getTruthy(globalThis, "sourcemap")) |source_map_js| {
194194
if (bun.FeatureFlags.breaking_changes_1_2 and config.isBoolean()) {
195195
if (source_map_js == .true) {
196196
this.source_map = if (has_out_dir)
@@ -207,11 +207,11 @@ pub const JSBundler = struct {
207207
}
208208
}
209209

210-
if (try config.getOwnOptionalEnum(globalThis, "packages", options.PackagesOption)) |packages| {
210+
if (try config.getOptionalEnum(globalThis, "packages", options.PackagesOption)) |packages| {
211211
this.packages = packages;
212212
}
213213

214-
if (try config.getOwnOptionalEnum(globalThis, "format", options.Format)) |format| {
214+
if (try config.getOptionalEnum(globalThis, "format", options.Format)) |format| {
215215
this.format = format;
216216

217217
if (this.bytecode and format != .cjs) {
@@ -220,28 +220,28 @@ pub const JSBundler = struct {
220220
}
221221
}
222222

223-
// if (try config.getOwnOptional(globalThis, "hot", bool)) |hot| {
223+
// if (try config.getOptional(globalThis, "hot", bool)) |hot| {
224224
// this.hot = hot;
225225
// }
226226

227-
if (try config.getOwnOptional(globalThis, "splitting", bool)) |hot| {
227+
if (try config.getOptional(globalThis, "splitting", bool)) |hot| {
228228
this.code_splitting = hot;
229229
}
230230

231-
if (config.getOwnTruthy(globalThis, "minify")) |hot| {
231+
if (config.getTruthy(globalThis, "minify")) |hot| {
232232
if (hot.isBoolean()) {
233233
const value = hot.coerce(bool, globalThis);
234234
this.minify.whitespace = value;
235235
this.minify.syntax = value;
236236
this.minify.identifiers = value;
237237
} else if (hot.isObject()) {
238-
if (try hot.getOwnOptional(globalThis, "whitespace", bool)) |whitespace| {
238+
if (try hot.getOptional(globalThis, "whitespace", bool)) |whitespace| {
239239
this.minify.whitespace = whitespace;
240240
}
241-
if (try hot.getOwnOptional(globalThis, "syntax", bool)) |syntax| {
241+
if (try hot.getOptional(globalThis, "syntax", bool)) |syntax| {
242242
this.minify.syntax = syntax;
243243
}
244-
if (try hot.getOwnOptional(globalThis, "identifiers", bool)) |syntax| {
244+
if (try hot.getOptional(globalThis, "identifiers", bool)) |syntax| {
245245
this.minify.identifiers = syntax;
246246
}
247247
} else {
@@ -265,19 +265,19 @@ pub const JSBundler = struct {
265265
return error.JSError;
266266
}
267267

268-
if (config.getOwnTruthy(globalThis, "emitDCEAnnotations")) |flag| {
268+
if (config.getTruthy(globalThis, "emitDCEAnnotations")) |flag| {
269269
if (flag.coerce(bool, globalThis)) {
270270
this.emit_dce_annotations = true;
271271
}
272272
}
273273

274-
if (config.getOwnTruthy(globalThis, "ignoreDCEAnnotations")) |flag| {
274+
if (config.getTruthy(globalThis, "ignoreDCEAnnotations")) |flag| {
275275
if (flag.coerce(bool, globalThis)) {
276276
this.ignore_dce_annotations = true;
277277
}
278278
}
279279

280-
if (config.getOwnTruthy(globalThis, "conditions")) |conditions_value| {
280+
if (config.getTruthy(globalThis, "conditions")) |conditions_value| {
281281
if (conditions_value.isString()) {
282282
var slice = conditions_value.toSliceOrNull(globalThis) orelse {
283283
globalThis.throwInvalidArguments("Expected conditions to be an array of strings", .{});
@@ -303,7 +303,7 @@ pub const JSBundler = struct {
303303

304304
{
305305
const path: ZigString.Slice = brk: {
306-
if (try config.getOwnOptional(globalThis, "root", ZigString.Slice)) |slice| {
306+
if (try config.getOptional(globalThis, "root", ZigString.Slice)) |slice| {
307307
break :brk slice;
308308
}
309309

@@ -344,21 +344,21 @@ pub const JSBundler = struct {
344344
}
345345
}
346346

347-
// if (try config.getOwnOptional(globalThis, "dir", ZigString.Slice)) |slice| {
347+
// if (try config.getOptional(globalThis, "dir", ZigString.Slice)) |slice| {
348348
// defer slice.deinit();
349349
// this.appendSliceExact(slice.slice()) catch unreachable;
350350
// } else {
351351
// this.appendSliceExact(globalThis.bunVM().bundler.fs.top_level_dir) catch unreachable;
352352
// }
353353

354-
if (try config.getOwnOptional(globalThis, "publicPath", ZigString.Slice)) |slice| {
354+
if (try config.getOptional(globalThis, "publicPath", ZigString.Slice)) |slice| {
355355
defer slice.deinit();
356356
try this.public_path.appendSliceExact(slice.slice());
357357
}
358358

359-
if (config.getOwnTruthy(globalThis, "naming")) |naming| {
359+
if (config.getTruthy(globalThis, "naming")) |naming| {
360360
if (naming.isString()) {
361-
if (try config.getOwnOptional(globalThis, "naming", ZigString.Slice)) |slice| {
361+
if (try config.getOptional(globalThis, "naming", ZigString.Slice)) |slice| {
362362
defer slice.deinit();
363363
if (!strings.hasPrefixComptime(slice.slice(), "./")) {
364364
try this.names.owned_entry_point.appendSliceExact("./");
@@ -367,7 +367,7 @@ pub const JSBundler = struct {
367367
this.names.entry_point.data = this.names.owned_entry_point.list.items;
368368
}
369369
} else if (naming.isObject()) {
370-
if (try naming.getOwnOptional(globalThis, "entry", ZigString.Slice)) |slice| {
370+
if (try naming.getOptional(globalThis, "entry", ZigString.Slice)) |slice| {
371371
defer slice.deinit();
372372
if (!strings.hasPrefixComptime(slice.slice(), "./")) {
373373
try this.names.owned_entry_point.appendSliceExact("./");
@@ -376,7 +376,7 @@ pub const JSBundler = struct {
376376
this.names.entry_point.data = this.names.owned_entry_point.list.items;
377377
}
378378

379-
if (try naming.getOwnOptional(globalThis, "chunk", ZigString.Slice)) |slice| {
379+
if (try naming.getOptional(globalThis, "chunk", ZigString.Slice)) |slice| {
380380
defer slice.deinit();
381381
if (!strings.hasPrefixComptime(slice.slice(), "./")) {
382382
try this.names.owned_chunk.appendSliceExact("./");
@@ -385,7 +385,7 @@ pub const JSBundler = struct {
385385
this.names.chunk.data = this.names.owned_chunk.list.items;
386386
}
387387

388-
if (try naming.getOwnOptional(globalThis, "asset", ZigString.Slice)) |slice| {
388+
if (try naming.getOptional(globalThis, "asset", ZigString.Slice)) |slice| {
389389
defer slice.deinit();
390390
if (!strings.hasPrefixComptime(slice.slice(), "./")) {
391391
try this.names.owned_asset.appendSliceExact("./");

0 commit comments

Comments
 (0)