mirror of
https://github.com/oven-sh/bun
synced 2026-02-16 05:42:43 +00:00
Fix console.table for numeric keys (#14484)
This commit is contained in:
@@ -342,7 +342,7 @@ const TablePrinter = struct {
|
||||
// - otherwise: iterate the object properties, and create the columns on-demand
|
||||
if (!this.properties.isUndefined()) {
|
||||
for (columns.items[1..]) |*column| {
|
||||
if (row_value.getWithString(this.globalObject, column.name)) |value| {
|
||||
if (row_value.getOwn(this.globalObject, column.name)) |value| {
|
||||
column.width = @max(column.width, this.getWidthForValue(value));
|
||||
}
|
||||
}
|
||||
@@ -436,7 +436,7 @@ const TablePrinter = struct {
|
||||
value = row_value;
|
||||
}
|
||||
} else if (row_value.isObject()) {
|
||||
value = row_value.getWithString(this.globalObject, col.name) orelse JSValue.zero;
|
||||
value = row_value.getOwn(this.globalObject, col.name) orelse JSValue.zero;
|
||||
}
|
||||
|
||||
if (value.isEmpty()) {
|
||||
|
||||
@@ -3712,23 +3712,6 @@ JSC__JSValue JSC__JSValue__getIfPropertyExistsImpl(JSC__JSValue JSValue0,
|
||||
return JSC::JSValue::encode(Bun::getIfPropertyExistsPrototypePollutionMitigation(vm, globalObject, object, property));
|
||||
}
|
||||
|
||||
extern "C" JSC__JSValue JSC__JSValue__getIfPropertyExistsImplString(JSC__JSValue JSValue0, JSC__JSGlobalObject* globalObject, BunString* propertyName)
|
||||
{
|
||||
ASSERT_NO_PENDING_EXCEPTION(globalObject);
|
||||
JSValue value = JSC::JSValue::decode(JSValue0);
|
||||
JSC::JSObject* object = value.getObject();
|
||||
if (UNLIKELY(!object))
|
||||
return JSValue::encode({});
|
||||
|
||||
JSC::VM& vm = globalObject->vm();
|
||||
|
||||
WTF::String propertyNameString = propertyName->tag == BunStringTag::Empty ? WTF::String(""_s) : propertyName->toWTFString(BunString::ZeroCopy);
|
||||
auto identifier = JSC::Identifier::fromString(vm, propertyNameString);
|
||||
auto property = JSC::PropertyName(identifier);
|
||||
|
||||
return JSC::JSValue::encode(Bun::getIfPropertyExistsPrototypePollutionMitigation(vm, globalObject, object, property));
|
||||
}
|
||||
|
||||
extern "C" JSC__JSValue JSC__JSValue__getOwn(JSC__JSValue JSValue0, JSC__JSGlobalObject* globalObject, BunString* propertyName)
|
||||
{
|
||||
ASSERT_NO_PENDING_EXCEPTION(globalObject);
|
||||
|
||||
@@ -5275,14 +5275,6 @@ pub const JSValue = enum(JSValueReprInt) {
|
||||
return if (value.isEmpty()) null else value;
|
||||
}
|
||||
|
||||
extern fn JSC__JSValue__getIfPropertyExistsImplString(value: JSValue, globalObject: *JSGlobalObject, propertyName: [*c]const bun.String) JSValue;
|
||||
|
||||
pub fn getWithString(this: JSValue, global: *JSGlobalObject, property_name: anytype) ?JSValue {
|
||||
var property_name_str = bun.String.init(property_name);
|
||||
const value = JSC__JSValue__getIfPropertyExistsImplString(this, global, &property_name_str);
|
||||
return if (@intFromEnum(value) != 0) value else return null;
|
||||
}
|
||||
|
||||
extern fn JSC__JSValue__getOwn(value: JSValue, globalObject: *JSGlobalObject, propertyName: [*c]const bun.String) JSValue;
|
||||
|
||||
/// Get *own* property value (i.e. does not resolve property in the prototype chain)
|
||||
|
||||
@@ -194,3 +194,12 @@ exports[`console.table expected output for: properties - interesting character 1
|
||||
└───┴────────┘
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`console.table expected output for: number keys 1`] = `
|
||||
"┌──────┬─────┬─────┐
|
||||
│ │ 10 │ 100 │
|
||||
├──────┼─────┼─────┤
|
||||
│ test │ 123 │ 154 │
|
||||
└──────┴─────┴─────┘
|
||||
"
|
||||
`;
|
||||
|
||||
@@ -134,6 +134,14 @@ describe("console.table", () => {
|
||||
],
|
||||
},
|
||||
],
|
||||
[
|
||||
"number keys",
|
||||
{
|
||||
args: () => [
|
||||
{test: {"10": 123, "100": 154}},
|
||||
],
|
||||
},
|
||||
],
|
||||
])("expected output for: %s", (label, { args }) => {
|
||||
const { stdout } = spawnSync({
|
||||
cmd: [bunExe(), `${import.meta.dir}/console-table-run.ts`, args.toString()],
|
||||
|
||||
Reference in New Issue
Block a user