Commit fd4667f7 authored by Iain Ireland's avatar Iain Ireland
Browse files

Bug 1810711: Refactor FindErrorInstanceOrPrototype r=jandem a=RyanVM

parent d529bb8c
Loading
Loading
Loading
Loading
+18 −24
Original line number Diff line number Diff line
@@ -647,19 +647,24 @@ static bool FindErrorInstanceOrPrototype(JSContext* cx, HandleObject obj,
  //   (new NYI).stack
  // to continue returning stacks that are useless, but at least don't throw.

  RootedObject target(cx, CheckedUnwrapStatic(obj));
  RootedObject curr(cx, obj);
  RootedObject target(cx);
  do {
    target = CheckedUnwrapStatic(curr);
    if (!target) {
      ReportAccessDenied(cx);
      return false;
    }
    if (IsErrorProtoKey(StandardProtoKeyOrNull(target))) {
      result.set(target);
      return true;
    }

  RootedObject proto(cx);
  while (!IsErrorProtoKey(StandardProtoKeyOrNull(target))) {
    if (!GetPrototype(cx, target, &proto)) {
    if (!GetPrototype(cx, curr, &curr)) {
      return false;
    }
  } while (curr);

    if (!proto) {
  // We walked the whole prototype chain and did not find an Error
  // object.
  JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
@@ -668,17 +673,6 @@ static bool FindErrorInstanceOrPrototype(JSContext* cx, HandleObject obj,
  return false;
}

    target = CheckedUnwrapStatic(proto);
    if (!target) {
      ReportAccessDenied(cx);
      return false;
    }
  }

  result.set(target);
  return true;
}

static MOZ_ALWAYS_INLINE bool IsObject(HandleValue v) { return v.isObject(); }

/* static */