diff options
author | Moonchild <moonchild@palemoon.org> | 2023-02-21 20:29:35 +0100 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2023-02-21 20:29:35 +0100 |
commit | b2af611dc1558023ad29438c543af227bcd4d52a (patch) | |
tree | 18a7019a550809a9b37f9045ebb8e517428a8a77 /js/src | |
parent | 9b1b294e294374cc6ccde925ca040e019c2daf39 (diff) | |
download | uxp-b2af611dc1558023ad29438c543af227bcd4d52a.tar.gz |
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.
Diffstat (limited to 'js/src')
-rw-r--r-- | js/src/vm/ErrorObject.cpp | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/js/src/vm/ErrorObject.cpp b/js/src/vm/ErrorObject.cpp index 2fa36089ed..7c966e0fe5 100644 --- a/js/src/vm/ErrorObject.cpp +++ b/js/src/vm/ErrorObject.cpp @@ -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); + 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; + } - target = CheckedUnwrap(proto); - if (!target) { - JS_ReportErrorASCII(cx, "Permission denied to access object"); + if (!GetPrototype(cx, target, &curr)) { return false; } - } + } while (curr); - result.set(target); - return true; + // 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; } |