Skip to content

Commit

Permalink
fixup non-own function hiding
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Mar 3, 2023
1 parent 1a1ffa0 commit f323795
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions c-dependencies/js-compute-runtime/builtins/shared/console.cpp
Expand Up @@ -173,13 +173,22 @@ JS::Result<mozilla::Ok> ObjectToSource(JSContext *cx, std::string &sourceOut, JS
JS::Rooted<mozilla::Maybe<JS::PropertyDescriptor>> desc(cx);
JS_GetOwnPropertyDescriptorById(cx, obj, id, &desc);

bool getter_setter = !desc.isNothing() && (desc->hasGetter() || desc->hasSetter());

// retrive the value if not a getter or setter
if (!getter_setter) {
if (!JS_GetPropertyById(cx, obj, id, &value)) {
return JS::Result<mozilla::Ok>(JS::Error());
}
}

// Skip logging non-own function or getter and setter keys
if (desc.isNothing() || desc->hasGetter() || desc->hasSetter()) {
bool found;
if (!JS_HasOwnPropertyById(cx, obj, id, &found)) {
if (getter_setter || (value.isObject() && JS_ObjectIsFunction(&value.toObject()))) {
bool own_prop;
if (!JS_HasOwnPropertyById(cx, obj, id, &own_prop)) {
return JS::Result<mozilla::Ok>(JS::Error());
}
if (found) {
if (!own_prop) {
continue;
}
}
Expand Down Expand Up @@ -208,16 +217,11 @@ JS::Result<mozilla::Ok> ObjectToSource(JSContext *cx, std::string &sourceOut, JS
sourceOut += ": ";

// Getters and Setters
if (!desc.isNothing() && (desc->hasGetter() || desc->hasSetter())) {
if (getter_setter) {
sourceOut += "[Getter]";
continue;
}

if (!JS_GetPropertyById(cx, obj, id, &value)) {
return JS::Result<mozilla::Ok>(JS::Error());
} else {
MOZ_TRY(ToSource(cx, sourceOut, value, visitedObjects));
}

MOZ_TRY(ToSource(cx, sourceOut, value, visitedObjects));
}

if (!firstValue) {
Expand Down

0 comments on commit f323795

Please sign in to comment.