Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make .get() ignore Object.prototype instead of using getOwn #14322

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/bun.js/api/BunObject.zig
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,11 @@ pub fn braces(
if (arguments.nextEat()) |opts_val| {
if (opts_val.isObject()) {
if (comptime bun.Environment.allow_assert) {
if (opts_val.getOwnTruthy(globalThis, "tokenize")) |tokenize_val| {
if (opts_val.getTruthy(globalThis, "tokenize")) |tokenize_val| {
tokenize = if (tokenize_val.isBoolean()) tokenize_val.asBoolean() else false;
}

if (opts_val.getOwnTruthy(globalThis, "parse")) |tokenize_val| {
if (opts_val.getTruthy(globalThis, "parse")) |tokenize_val| {
parse = if (tokenize_val.isBoolean()) tokenize_val.asBoolean() else false;
}
}
Expand Down Expand Up @@ -461,11 +461,11 @@ pub fn which(

if (arguments.nextEat()) |arg| {
if (!arg.isEmptyOrUndefinedOrNull() and arg.isObject()) {
if (arg.getOwn(globalThis, "PATH")) |str_| {
if (arg.get(globalThis, "PATH")) |str_| {
path_str = str_.toSlice(globalThis, globalThis.bunVM().allocator);
}

if (arg.getOwn(globalThis, "cwd")) |str_| {
if (arg.get(globalThis, "cwd")) |str_| {
cwd_str = str_.toSlice(globalThis, globalThis.bunVM().allocator);
}
}
Expand Down Expand Up @@ -514,7 +514,7 @@ pub fn inspect(
const arg1 = arguments[1];

if (arg1.isObject()) {
if (arg1.getOwnTruthy(globalThis, "depth")) |opt| {
if (arg1.getTruthy(globalThis, "depth")) |opt| {
if (opt.isInt32()) {
const arg = opt.toInt32();
if (arg < 0) {
Expand Down Expand Up @@ -779,7 +779,7 @@ pub fn openInEditor(

if (arguments.nextEat()) |opts| {
if (!opts.isUndefinedOrNull()) {
if (opts.getOwnTruthy(globalThis, "editor")) |editor_val| {
if (opts.getTruthy(globalThis, "editor")) |editor_val| {
var sliced = editor_val.toSlice(globalThis, arguments.arena.allocator());
const prev_name = edit.name;

Expand All @@ -799,11 +799,11 @@ pub fn openInEditor(
}
}

if (opts.getOwnTruthy(globalThis, "line")) |line_| {
if (opts.getTruthy(globalThis, "line")) |line_| {
line = line_.toSlice(globalThis, arguments.arena.allocator()).slice();
}

if (opts.getOwnTruthy(globalThis, "column")) |column_| {
if (opts.getTruthy(globalThis, "column")) |column_| {
column = column_.toSlice(globalThis, arguments.arena.allocator()).slice();
}
}
Expand Down Expand Up @@ -1711,7 +1711,7 @@ pub const Crypto = struct {

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

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

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

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

if (options_object.isObject()) {
if (options_object.getOwnTruthy(globalObject, "countAnsiEscapeCodes")) |count_ansi_escapes_value| {
if (options_object.getTruthy(globalObject, "countAnsiEscapeCodes")) |count_ansi_escapes_value| {
if (count_ansi_escapes_value.isBoolean())
count_ansi_escapes = count_ansi_escapes_value.toBoolean();
}
if (options_object.getOwnTruthy(globalObject, "ambiguousIsNarrow")) |ambiguous_is_narrow| {
if (options_object.getTruthy(globalObject, "ambiguousIsNarrow")) |ambiguous_is_narrow| {
if (ambiguous_is_narrow.isBoolean())
ambiguous_as_wide = !ambiguous_is_narrow.toBoolean();
}
Expand Down Expand Up @@ -4784,7 +4784,7 @@ pub const JSZlib = struct {
library = .zlib;
}

if (options_val.getOwnTruthy(globalThis, "library")) |library_value| {
if (options_val.getTruthy(globalThis, "library")) |library_value| {
if (!library_value.isString()) {
globalThis.throwInvalidArguments("Expected library to be a string", .{});
return .zero;
Expand Down Expand Up @@ -4911,7 +4911,7 @@ pub const JSZlib = struct {
library = .zlib;
}

if (options_val.getOwnTruthy(globalThis, "library")) |library_value| {
if (options_val.getTruthy(globalThis, "library")) |library_value| {
if (!library_value.isString()) {
globalThis.throwInvalidArguments("Expected library to be a string", .{});
return .zero;
Expand Down
52 changes: 26 additions & 26 deletions src/bun.js/api/JSBundler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub const JSBundler = struct {
return error.JSError;
}

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

if (config.getOwnTruthy(globalThis, "macros")) |macros_flag| {
if (config.getTruthy(globalThis, "macros")) |macros_flag| {
if (!macros_flag.coerce(bool, globalThis)) {
this.no_macros = true;
}
}

if (try config.getOwnOptional(globalThis, "bytecode", bool)) |bytecode| {
if (try config.getOptional(globalThis, "bytecode", bool)) |bytecode| {
this.bytecode = bytecode;

if (bytecode) {
Expand All @@ -169,7 +169,7 @@ pub const JSBundler = struct {
}
}

if (try config.getOwnOptionalEnum(globalThis, "target", options.Target)) |target| {
if (try config.getOptionalEnum(globalThis, "target", options.Target)) |target| {
this.target = target;

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

var has_out_dir = false;
if (try config.getOwnOptional(globalThis, "outdir", ZigString.Slice)) |slice| {
if (try config.getOptional(globalThis, "outdir", ZigString.Slice)) |slice| {
defer slice.deinit();
try this.outdir.appendSliceExact(slice.slice());
has_out_dir = true;
}

if (try config.getOwnOptional(globalThis, "banner", ZigString.Slice)) |slice| {
if (try config.getOptional(globalThis, "banner", ZigString.Slice)) |slice| {
defer slice.deinit();
try this.banner.appendSliceExact(slice.slice());
}

if (config.getOwnTruthy(globalThis, "sourcemap")) |source_map_js| {
if (config.getTruthy(globalThis, "sourcemap")) |source_map_js| {
if (bun.FeatureFlags.breaking_changes_1_2 and config.isBoolean()) {
if (source_map_js == .true) {
this.source_map = if (has_out_dir)
Expand All @@ -207,11 +207,11 @@ pub const JSBundler = struct {
}
}

if (try config.getOwnOptionalEnum(globalThis, "packages", options.PackagesOption)) |packages| {
if (try config.getOptionalEnum(globalThis, "packages", options.PackagesOption)) |packages| {
this.packages = packages;
}

if (try config.getOwnOptionalEnum(globalThis, "format", options.Format)) |format| {
if (try config.getOptionalEnum(globalThis, "format", options.Format)) |format| {
this.format = format;

if (this.bytecode and format != .cjs) {
Expand All @@ -220,28 +220,28 @@ pub const JSBundler = struct {
}
}

// if (try config.getOwnOptional(globalThis, "hot", bool)) |hot| {
// if (try config.getOptional(globalThis, "hot", bool)) |hot| {
// this.hot = hot;
// }

if (try config.getOwnOptional(globalThis, "splitting", bool)) |hot| {
if (try config.getOptional(globalThis, "splitting", bool)) |hot| {
this.code_splitting = hot;
}

if (config.getOwnTruthy(globalThis, "minify")) |hot| {
if (config.getTruthy(globalThis, "minify")) |hot| {
if (hot.isBoolean()) {
const value = hot.coerce(bool, globalThis);
this.minify.whitespace = value;
this.minify.syntax = value;
this.minify.identifiers = value;
} else if (hot.isObject()) {
if (try hot.getOwnOptional(globalThis, "whitespace", bool)) |whitespace| {
if (try hot.getOptional(globalThis, "whitespace", bool)) |whitespace| {
this.minify.whitespace = whitespace;
}
if (try hot.getOwnOptional(globalThis, "syntax", bool)) |syntax| {
if (try hot.getOptional(globalThis, "syntax", bool)) |syntax| {
this.minify.syntax = syntax;
}
if (try hot.getOwnOptional(globalThis, "identifiers", bool)) |syntax| {
if (try hot.getOptional(globalThis, "identifiers", bool)) |syntax| {
this.minify.identifiers = syntax;
}
} else {
Expand All @@ -265,19 +265,19 @@ pub const JSBundler = struct {
return error.JSError;
}

if (config.getOwnTruthy(globalThis, "emitDCEAnnotations")) |flag| {
if (config.getTruthy(globalThis, "emitDCEAnnotations")) |flag| {
if (flag.coerce(bool, globalThis)) {
this.emit_dce_annotations = true;
}
}

if (config.getOwnTruthy(globalThis, "ignoreDCEAnnotations")) |flag| {
if (config.getTruthy(globalThis, "ignoreDCEAnnotations")) |flag| {
if (flag.coerce(bool, globalThis)) {
this.ignore_dce_annotations = true;
}
}

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

{
const path: ZigString.Slice = brk: {
if (try config.getOwnOptional(globalThis, "root", ZigString.Slice)) |slice| {
if (try config.getOptional(globalThis, "root", ZigString.Slice)) |slice| {
break :brk slice;
}

Expand Down Expand Up @@ -344,21 +344,21 @@ pub const JSBundler = struct {
}
}

// if (try config.getOwnOptional(globalThis, "dir", ZigString.Slice)) |slice| {
// if (try config.getOptional(globalThis, "dir", ZigString.Slice)) |slice| {
// defer slice.deinit();
// this.appendSliceExact(slice.slice()) catch unreachable;
// } else {
// this.appendSliceExact(globalThis.bunVM().bundler.fs.top_level_dir) catch unreachable;
// }

if (try config.getOwnOptional(globalThis, "publicPath", ZigString.Slice)) |slice| {
if (try config.getOptional(globalThis, "publicPath", ZigString.Slice)) |slice| {
defer slice.deinit();
try this.public_path.appendSliceExact(slice.slice());
}

if (config.getOwnTruthy(globalThis, "naming")) |naming| {
if (config.getTruthy(globalThis, "naming")) |naming| {
if (naming.isString()) {
if (try config.getOwnOptional(globalThis, "naming", ZigString.Slice)) |slice| {
if (try config.getOptional(globalThis, "naming", ZigString.Slice)) |slice| {
defer slice.deinit();
if (!strings.hasPrefixComptime(slice.slice(), "./")) {
try this.names.owned_entry_point.appendSliceExact("./");
Expand All @@ -367,7 +367,7 @@ pub const JSBundler = struct {
this.names.entry_point.data = this.names.owned_entry_point.list.items;
}
} else if (naming.isObject()) {
if (try naming.getOwnOptional(globalThis, "entry", ZigString.Slice)) |slice| {
if (try naming.getOptional(globalThis, "entry", ZigString.Slice)) |slice| {
defer slice.deinit();
if (!strings.hasPrefixComptime(slice.slice(), "./")) {
try this.names.owned_entry_point.appendSliceExact("./");
Expand All @@ -376,7 +376,7 @@ pub const JSBundler = struct {
this.names.entry_point.data = this.names.owned_entry_point.list.items;
}

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

if (try naming.getOwnOptional(globalThis, "asset", ZigString.Slice)) |slice| {
if (try naming.getOptional(globalThis, "asset", ZigString.Slice)) |slice| {
defer slice.deinit();
if (!strings.hasPrefixComptime(slice.slice(), "./")) {
try this.names.owned_asset.appendSliceExact("./");
Expand Down
Loading