// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/platform/text/icu_error.h"

#include <ostream>

#include "base/notreached.h"
#include "partition_alloc/oom.h"

namespace blink {

// Distinguish memory allocation failures from other errors.
// https://groups.google.com/a/chromium.org/d/msg/platform-architecture-dev/MP0k9WGnCjA/zIBiJtilBwAJ
NOINLINE static void IcuOutOfMemory() {
  OOM_CRASH(0);
}

void IcuError::HandleFailure() {
  switch (error_) {
    case U_MEMORY_ALLOCATION_ERROR:
      IcuOutOfMemory();
      break;
    case U_ILLEGAL_ARGUMENT_ERROR:
      NOTREACHED() << error_;
    default:
      break;
  }
}

}  // namespace blink
