blob: c7fa83c43a088f617e859657c7a450d2ea2e5038 [file] [log] [blame]
// Copyright 2020 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/modules/webcodecs/codec_state_helper.h"
#include "third_party/blink/renderer/platform/wtf/text/strcat.h"
namespace blink {
// static
bool ThrowIfCodecStateClosed(V8CodecState state,
String operation,
ExceptionState& exception_state) {
if (state.AsEnum() != V8CodecState::Enum::kClosed)
return false;
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError,
StrCat({"Cannot call '", operation, "' on a closed codec."}));
return true;
}
// static
bool ThrowIfCodecStateUnconfigured(V8CodecState state,
String operation,
ExceptionState& exception_state) {
if (state.AsEnum() != V8CodecState::Enum::kUnconfigured)
return false;
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError,
StrCat({"Cannot call '", operation, "' on an unconfigured codec."}));
return true;
}
} // namespace blink