mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-08 16:58:38 +09:00
No issue - Refactor FindErrorInstanceOrPrototype
The logic here wasn't very transparent or easy to follow. Doing a positive check to set the result instead of defaulting to it also potentially prevents issues.
This commit is contained in:
parent
9037d5662d
commit
db89c5a05d
1 changed files with 18 additions and 22 deletions
|
|
@ -557,34 +557,30 @@ FindErrorInstanceOrPrototype(JSContext* cx, HandleObject obj, MutableHandleObjec
|
|||
// (new NYI).stack
|
||||
// to continue returning stacks that are useless, but at least don't throw.
|
||||
|
||||
RootedObject target(cx, CheckedUnwrap(obj));
|
||||
if (!target) {
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access object");
|
||||
return false;
|
||||
}
|
||||
|
||||
RootedObject proto(cx);
|
||||
while (!IsErrorProtoKey(StandardProtoKeyOrNull(target))) {
|
||||
if (!GetPrototype(cx, target, &proto))
|
||||
return false;
|
||||
|
||||
if (!proto) {
|
||||
// We walked the whole prototype chain and did not find an Error
|
||||
// object.
|
||||
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
||||
js_Error_str, "(get stack)", obj->getClass()->name);
|
||||
return false;
|
||||
}
|
||||
|
||||
target = CheckedUnwrap(proto);
|
||||
RootedObject curr(cx, obj);
|
||||
RootedObject target(cx);
|
||||
do {
|
||||
target = CheckedUnwrap(curr);
|
||||
if (!target) {
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access object");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsErrorProtoKey(StandardProtoKeyOrNull(target))) {
|
||||
result.set(target);
|
||||
return true;
|
||||
}
|
||||
|
||||
result.set(target);
|
||||
return true;
|
||||
if (!GetPrototype(cx, target, &curr)) {
|
||||
return false;
|
||||
}
|
||||
} while (curr);
|
||||
|
||||
// We walked the whole prototype chain and did not find an Error
|
||||
// object.
|
||||
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
||||
js_Error_str, "(get stack)", obj->getClass()->name);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue