Exemple #1
0
 const T& get() const
 {
   if (!isSome()) {
     std::string errorMessage = "Result::get() but state == ";
     if (isError()) {
       errorMessage += "ERROR: " + data.error();
     } else if (isNone()) {
       errorMessage += "NONE";
     }
     ABORT(errorMessage);
   }
   return data.get().get();
 }
Exemple #2
0
  Option<T>& operator=(Option<T>&& that)
  {
    if (this != &that) {
      if (isSome()) {
        t.~T();
      }
      state = std::move(that.state);
      if (that.isSome()) {
        new (&t) T(std::move(that.t));
      }
    }

    return *this;
  }
Exemple #3
0
  Option<T>& operator=(const Option<T>& that)
  {
    if (this != &that) {
      if (isSome()) {
        t.~T();
      }
      state = that.state;
      if (that.isSome()) {
        new (&t) T(that.t);
      }
    }

    return *this;
  }
static void
getString(CacheAndIndex* cacheAndIndex)
{
    for (int i = 0; i < NUM_ITERATIONS; i++) {
        auto str = STRINGS[cacheAndIndex->index % NUM_STRINGS];

        auto dupe = js::DuplicateString(str);
        MOZ_RELEASE_ASSERT(dupe);

        auto deduped = cacheAndIndex->cache->getOrCreate(mozilla::Move(dupe), js_strlen(str));
        MOZ_RELEASE_ASSERT(deduped.isSome());
        MOZ_RELEASE_ASSERT(js_strcmp(str, deduped->chars()) == 0);

        {
            auto cloned = deduped->clone();
            // We should be de-duplicating and giving back the same string.
            MOZ_RELEASE_ASSERT(deduped->chars() == cloned.chars());
        }
    }

    js_delete(cacheAndIndex);
}
Exemple #5
0
 ~Option()
 {
   if (isSome()) {
     t.~T();
   }
 }
Exemple #6
0
 bool operator==(const T& that) const
 {
   return isSome() && t == that;
 }
Exemple #7
0
 bool operator==(const Option<T>& that) const
 {
   return (isNone() && that.isNone()) ||
     (isSome() && that.isSome() && t == that.t);
 }
Exemple #8
0
 const T&& get() const && { assert(isSome()); return std::move(t); }
Exemple #9
0
 T& get() & { assert(isSome()); return t; }
Exemple #10
0
 const T& get() const & { assert(isSome()); return t; }