Skip to content
Closed
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
4 changes: 2 additions & 2 deletions src/jsc/ConsoleObject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4790,7 +4790,7 @@ pub mod formatter {
let length_value = value
.get(self.global_this, "size")?
.unwrap_or_else(|| JSValue::js_number_from_int32(0));
let length = length_value.coerce_to_i32(self.global_this)?;
let length = length_value.coerce::<i32>(self.global_this)?;

let prev_quote_strings = self.quote_strings;
self.quote_strings = true;
Expand Down Expand Up @@ -4932,7 +4932,7 @@ pub mod formatter {
let length_value = value
.get(self.global_this, "size")?
.unwrap_or_else(|| JSValue::js_number_from_int32(0));
let length = length_value.coerce_to_i32(self.global_this)?;
let length = length_value.coerce::<i32>(self.global_this)?;

let prev_quote_strings = self.quote_strings;
self.quote_strings = true;
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/crypto/PasswordObject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl AlgorithmValue {
.throw_invalid_argument_type("hash", "cost", "number"));
}

let rounds = rounds_value.coerce_to_i32(global_object)?;
let rounds = rounds_value.coerce::<i32>(global_object)?;

if rounds < 4 || rounds > 31 {
return Err(global_object.throw_invalid_arguments(format_args!(
Expand All @@ -117,7 +117,7 @@ impl AlgorithmValue {
.throw_invalid_argument_type("hash", "timeCost", "number"));
}

let time_cost = time_value.coerce_to_i32(global_object)?;
let time_cost = time_value.coerce::<i32>(global_object)?;
Comment thread
robobun marked this conversation as resolved.
Resolved

if time_cost < 1 {
return Err(global_object.throw_invalid_arguments(format_args!(
Expand All @@ -137,7 +137,7 @@ impl AlgorithmValue {
));
}

let memory_cost = memory_value.coerce_to_i32(global_object)?;
let memory_cost = memory_value.coerce::<i32>(global_object)?;

// argon2 requires `memoryCost >= 8 * parallelism`;
// Bun hard-codes `parallelism = 1` (see
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/server/ServerWebSocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ impl ServerWebSocket {
)));
}

break 'brk args.ptr[0].coerce_to_i32(global_this)?;
break 'brk args.ptr[0].coerce::<i32>(global_this)?;
};

let message_value: ZigStringSlice = 'brk: {
Expand Down
4 changes: 2 additions & 2 deletions src/sourcemap_jsc/JSSourceMap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ fn get_line_column(global: &JSGlobalObject, frame: &CallFrame) -> JsResult<[i32;

Ok([
// Node.js does no validations.
line_number_value.coerce_to_i32(global)?,
column_number_value.coerce_to_i32(global)?,
line_number_value.coerce::<i32>(global)?,
column_number_value.coerce::<i32>(global)?,
])
}

Expand Down
17 changes: 17 additions & 0 deletions test/js/bun/util/inspect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,23 @@ it("inspect", () => {
value: "not a number",
});
expect(Bun.inspect(mapWithOverriddenSize)).toBe("Map {}");

// Size values >= 2^31 saturate to i32::MAX instead of wrapping negative.
const mapWithHugeSize = new Map([[1, 1]]);
Object.defineProperty(mapWithHugeSize, "size", { value: 3000000000 });
expect(Bun.inspect(mapWithHugeSize)).toBe("Map(2147483647) {\n 1: 1,\n}");

const setWithHugeSize = new Set([1]);
Object.defineProperty(setWithHugeSize, "size", { value: 3000000000 });
expect(Bun.inspect(setWithHugeSize)).toBe("Set(2147483647) {\n 1,\n}");

const mapWithInfiniteSize = new Map([[1, 1]]);
Object.defineProperty(mapWithInfiniteSize, "size", { value: Infinity });
expect(Bun.inspect(mapWithInfiniteSize)).toBe("Map(2147483647) {\n 1: 1,\n}");
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

const setWithInfiniteSize = new Set([1]);
Object.defineProperty(setWithInfiniteSize, "size", { value: Infinity });
expect(Bun.inspect(setWithInfiniteSize)).toBe("Set(2147483647) {\n 1,\n}");
expect(Bun.inspect(<div>foo</div>)).toBe("<div>foo</div>");
expect(Bun.inspect(<div hello>foo</div>)).toBe("<div hello=true>foo</div>");
expect(Bun.inspect(<div hello={1}>foo</div>)).toBe("<div hello=1>foo</div>");
Expand Down
Loading