diff options
author | 2022-12-28 11:21:21 +0200 | |
---|---|---|
committer | 2022-12-28 01:21:21 -0800 | |
commit | 092b86321c3210b5435deef1d283648eb8ea5a90 (patch) | |
tree | afe3e9f5642a6942ee7dd3895c22b12d246481cb /src | |
parent | da07811427cc10754414c0f1064c4158b8941fa2 (diff) | |
download | bun-092b86321c3210b5435deef1d283648eb8ea5a90.tar.gz bun-092b86321c3210b5435deef1d283648eb8ea5a90.tar.zst bun-092b86321c3210b5435deef1d283648eb8ea5a90.zip |
log object string correctly (#1674)
use `Symbol.toStringTag` of the object or that of its `.prototype`
fixes #1584
Diffstat (limited to 'src')
-rw-r--r-- | src/bun.js/bindings/bindings.cpp | 20 | ||||
-rw-r--r-- | src/bun.js/bindings/exports.zig | 7 |
2 files changed, 13 insertions, 14 deletions
diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp index f37af006b..f6f596fcb 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -3062,10 +3062,9 @@ void JSC__JSValue__getClassName(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1 arg2->len = 0; } -void JSC__JSValue__getNameProperty(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, - ZigString* arg2) -{ +void JSC__JSValue__getNameProperty(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, ZigString* arg2) +{ JSC::JSObject* obj = JSC::JSValue::decode(JSValue0).getObject(); JSC::VM& vm = arg1->vm(); @@ -3074,10 +3073,7 @@ void JSC__JSValue__getNameProperty(JSC__JSValue JSValue0, JSC__JSGlobalObject* a return; } - JSC::JSValue name = obj->getDirect(vm, vm.propertyNames->toStringTagSymbol); - if (name == JSC::JSValue {}) { - name = obj->getDirect(vm, vm.propertyNames->name); - } + JSC::JSValue name = obj->getIfPropertyExists(arg1, vm.propertyNames->toStringTagSymbol); if (name && name.isString()) { auto str = name.toWTFString(arg1); @@ -3412,7 +3408,10 @@ restart: return true; } - if (entry.key() == vm.propertyNames->constructor || entry.key() == vm.propertyNames->length || entry.key() == vm.propertyNames->name || entry.key() == vm.propertyNames->underscoreProto || entry.key() == vm.propertyNames->toStringTagSymbol) + if (entry.key() == vm.propertyNames->constructor + || entry.key() == vm.propertyNames->length + || entry.key() == vm.propertyNames->underscoreProto + || entry.key() == vm.propertyNames->toStringTagSymbol) return true; if (clientData->builtinNames().bunNativePtrPrivateName() == entry.key()) @@ -3488,8 +3487,9 @@ restart: } if ((slot.attributes() & PropertyAttribute::DontEnum) != 0) { - - if (property == vm.propertyNames->length || property == vm.propertyNames->name || property == vm.propertyNames->underscoreProto || property == vm.propertyNames->toStringTagSymbol) + if (property == vm.propertyNames->length + || property == vm.propertyNames->underscoreProto + || property == vm.propertyNames->toStringTagSymbol) continue; } diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig index b2460cc0d..debe1f734 100644 --- a/src/bun.js/bindings/exports.zig +++ b/src/bun.js/bindings/exports.zig @@ -1672,18 +1672,17 @@ pub const ZigConsoleClient = struct { const enable_ansi_colors = enable_ansi_colors_; pub fn handleFirstProperty(this: *@This(), globalThis: *JSC.JSGlobalObject, value: JSValue) void { if (!value.jsType().isFunction() and !value.isClass(globalThis)) { - var name_str = ZigString.init(""); - - value.getPrototype(globalThis).getNameProperty(globalThis, &name_str); var writer = WrappedWriter(Writer){ .ctx = this.writer, .failed = false, }; + var name_str = ZigString.init(""); + value.getNameProperty(globalThis, &name_str); if (name_str.len > 0 and !strings.eqlComptime(name_str.slice(), "Object")) { writer.print("{} ", .{name_str}); } else { - value.getNameProperty(globalThis, &name_str); + value.getPrototype(globalThis).getNameProperty(globalThis, &name_str); if (name_str.len > 0 and !strings.eqlComptime(name_str.slice(), "Object")) { writer.print("{} ", .{name_str}); } |