bool apply_cache_override(JSContext *cx, HandleObject self) {
  MOZ_ASSERT(is_instance(self));
  RootedObject override(cx, JS::GetReservedSlot(self, Slots::CacheOverride).toObjectOrNull());
  if (!override) {
    return true;
  }

  uint32_t tag = builtins::CacheOverride::abi_tag(override);
  RootedValue val(cx, builtins::CacheOverride::ttl(override));
  uint32_t ttl = val.isUndefined() ? 0 : val.toInt32();
  val = builtins::CacheOverride::swr(override);
  uint32_t swr = val.isUndefined() ? 0 : val.toInt32();
  val = builtins::CacheOverride::surrogate_key(override);
  UniqueChars sk_chars;
  size_t sk_len = 0;
  if (!val.isUndefined()) {
    sk_chars = encode(cx, val, &sk_len);
    if (!sk_chars)
      return false;
  }

  return HANDLE_RESULT(cx, xqd_req_cache_override_v2_set(request_handle(self), tag, ttl, swr,
                                                         sk_chars.get(), sk_len));
}
bool apply_cache_override(JSContext *cx, HandleObject self) {
  MOZ_ASSERT(is_instance(self));
  RootedObject override(cx, JS::GetReservedSlot(self, Slots::CacheOverride).toObjectOrNull());
  if (!override) {
    return true;
  }

  uint32_t tag = builtins::CacheOverride::abi_tag(override);
  RootedValue val(cx, builtins::CacheOverride::ttl(override));
  uint32_t ttl = val.isUndefined() ? 0 : val.toInt32();
  val = builtins::CacheOverride::swr(override);
  uint32_t swr = val.isUndefined() ? 0 : val.toInt32();
  val = builtins::CacheOverride::surrogate_key(override);
  UniqueChars sk_chars;
  size_t sk_len = 0;
  if (!val.isUndefined()) {
    sk_chars = encode(cx, val, &sk_len);
    if (!sk_chars)
      return false;
  }

  return HANDLE_RESULT(cx, xqd_req_cache_override_v2_set(request_handle(self), tag, ttl, swr,
                                                         sk_chars.get(), sk_len));
}