| 40 | js::SystemAllocPolicy>; |
| 41 | |
| 42 | GJS_JSAPI_RETURN_CONVENTION |
| 43 | static bool get_last_cause(JSContext* cx, JS::HandleValue v_exc, |
| 44 | JS::MutableHandleObject last_cause, |
| 45 | JS::MutableHandle<CauseSet> seen_causes) { |
| 46 | if (!v_exc.isObject()) { |
| 47 | last_cause.set(nullptr); |
| 48 | return true; |
| 49 | } |
| 50 | JS::RootedObject exc(cx, &v_exc.toObject()); |
| 51 | CauseSet::AddPtr entry = seen_causes.lookupForAdd(exc); |
| 52 | if (entry) { |
| 53 | last_cause.set(nullptr); |
| 54 | return true; |
| 55 | } |
| 56 | if (!seen_causes.add(entry, exc)) { |
| 57 | JS_ReportOutOfMemory(cx); |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | JS::RootedValue v_cause(cx); |
| 62 | const GjsAtoms& atoms = GjsContextPrivate::atoms(cx); |
| 63 | if (!JS_GetPropertyById(cx, exc, atoms.cause(), &v_cause)) |
| 64 | return false; |
| 65 | |
| 66 | if (v_cause.isUndefined()) { |
| 67 | last_cause.set(exc); |
| 68 | return true; |
| 69 | } |
| 70 | |
| 71 | return get_last_cause(cx, v_cause, last_cause, seen_causes); |
| 72 | } |
| 73 | |
| 74 | GJS_JSAPI_RETURN_CONVENTION |
| 75 | static bool append_new_cause(JSContext* cx, JS::HandleValue thrown, |
no test coverage detected