dawn_node: Add binding/Errors.[cpp,h]

Errors contains static helper methods for creating DOMException error messages as documented at:
https://heycam.github.io/webidl/#idl-DOMException-error-names

Bug: dawn:1123
Change-Id: I5fcf4e146c91cde37f5514d8a4a426b17de6a701
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/64904
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Ben Clayton 2021-09-28 11:59:10 +00:00 committed by Dawn LUCI CQ
parent 51791e0409
commit af48bbc460
4 changed files with 278 additions and 0 deletions

View File

@ -55,4 +55,5 @@ function(idlgen)
) )
endfunction() endfunction()
add_subdirectory(binding)
add_subdirectory(interop) add_subdirectory(interop)

View File

@ -0,0 +1,38 @@
# Copyright 2021 The Dawn Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
add_library(dawn_node_binding STATIC
"Errors.cpp"
"Errors.h"
)
target_include_directories(dawn_node_binding
PRIVATE
${CMAKE_SOURCE_DIR}
${NODE_API_HEADERS_DIR}
${NODE_ADDON_API_DIR}
${GEN_DIR}
)
target_link_libraries(dawn_node_binding
PRIVATE
dawncpp
dawn_node_interop
)
# dawn_node targets require C++17
set_property(
TARGET dawn_node_binding
PROPERTY CXX_STANDARD 17
)

View File

@ -0,0 +1,179 @@
// Copyright 2021 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/dawn_node/binding/Errors.h"
namespace wgpu { namespace binding {
namespace {
constexpr char kHierarchyRequestError[] = "HierarchyRequestError";
constexpr char kWrongDocumentError[] = "WrongDocumentError";
constexpr char kInvalidCharacterError[] = "InvalidCharacterError";
constexpr char kNoModificationAllowedError[] = "NoModificationAllowedError";
constexpr char kNotFoundError[] = "NotFoundError";
constexpr char kNotSupportedError[] = "NotSupportedError";
constexpr char kInUseAttributeError[] = "InUseAttributeError";
constexpr char kInvalidStateError[] = "InvalidStateError";
constexpr char kSyntaxError[] = "SyntaxError";
constexpr char kInvalidModificationError[] = "InvalidModificationError";
constexpr char kNamespaceError[] = "NamespaceError";
constexpr char kSecurityError[] = "SecurityError";
constexpr char kNetworkError[] = "NetworkError";
constexpr char kAbortError[] = "AbortError";
constexpr char kURLMismatchError[] = "URLMismatchError";
constexpr char kQuotaExceededError[] = "QuotaExceededError";
constexpr char kTimeoutError[] = "TimeoutError";
constexpr char kInvalidNodeTypeError[] = "InvalidNodeTypeError";
constexpr char kDataCloneError[] = "DataCloneError";
constexpr char kEncodingError[] = "EncodingError";
constexpr char kNotReadableError[] = "NotReadableError";
constexpr char kUnknownError[] = "UnknownError";
constexpr char kConstraintError[] = "ConstraintError";
constexpr char kDataError[] = "DataError";
constexpr char kTransactionInactiveError[] = "TransactionInactiveError";
constexpr char kReadOnlyError[] = "ReadOnlyError";
constexpr char kVersionError[] = "VersionError";
constexpr char kOperationError[] = "OperationError";
constexpr char kNotAllowedError[] = "NotAllowedError";
static Napi::Error New(Napi::Env env,
std::string name,
std::string message = {},
unsigned short code = 0) {
auto err = Napi::Error::New(env);
err.Set("name", name);
err.Set("message", message.empty() ? name : message);
err.Set("code", static_cast<double>(code));
return err;
}
} // namespace
Napi::Error Errors::HierarchyRequestError(Napi::Env env) {
return New(env, kHierarchyRequestError);
}
Napi::Error Errors::WrongDocumentError(Napi::Env env) {
return New(env, kWrongDocumentError);
}
Napi::Error Errors::InvalidCharacterError(Napi::Env env) {
return New(env, kInvalidCharacterError);
}
Napi::Error Errors::NoModificationAllowedError(Napi::Env env) {
return New(env, kNoModificationAllowedError);
}
Napi::Error Errors::NotFoundError(Napi::Env env) {
return New(env, kNotFoundError);
}
Napi::Error Errors::NotSupportedError(Napi::Env env) {
return New(env, kNotSupportedError);
}
Napi::Error Errors::InUseAttributeError(Napi::Env env) {
return New(env, kInUseAttributeError);
}
Napi::Error Errors::InvalidStateError(Napi::Env env) {
return New(env, kInvalidStateError);
}
Napi::Error Errors::SyntaxError(Napi::Env env) {
return New(env, kSyntaxError);
}
Napi::Error Errors::InvalidModificationError(Napi::Env env) {
return New(env, kInvalidModificationError);
}
Napi::Error Errors::NamespaceError(Napi::Env env) {
return New(env, kNamespaceError);
}
Napi::Error Errors::SecurityError(Napi::Env env) {
return New(env, kSecurityError);
}
Napi::Error Errors::NetworkError(Napi::Env env) {
return New(env, kNetworkError);
}
Napi::Error Errors::AbortError(Napi::Env env) {
return New(env, kAbortError);
}
Napi::Error Errors::URLMismatchError(Napi::Env env) {
return New(env, kURLMismatchError);
}
Napi::Error Errors::QuotaExceededError(Napi::Env env) {
return New(env, kQuotaExceededError);
}
Napi::Error Errors::TimeoutError(Napi::Env env) {
return New(env, kTimeoutError);
}
Napi::Error Errors::InvalidNodeTypeError(Napi::Env env) {
return New(env, kInvalidNodeTypeError);
}
Napi::Error Errors::DataCloneError(Napi::Env env) {
return New(env, kDataCloneError);
}
Napi::Error Errors::EncodingError(Napi::Env env) {
return New(env, kEncodingError);
}
Napi::Error Errors::NotReadableError(Napi::Env env) {
return New(env, kNotReadableError);
}
Napi::Error Errors::UnknownError(Napi::Env env) {
return New(env, kUnknownError);
}
Napi::Error Errors::ConstraintError(Napi::Env env) {
return New(env, kConstraintError);
}
Napi::Error Errors::DataError(Napi::Env env) {
return New(env, kDataError);
}
Napi::Error Errors::TransactionInactiveError(Napi::Env env) {
return New(env, kTransactionInactiveError);
}
Napi::Error Errors::ReadOnlyError(Napi::Env env) {
return New(env, kReadOnlyError);
}
Napi::Error Errors::VersionError(Napi::Env env) {
return New(env, kVersionError);
}
Napi::Error Errors::OperationError(Napi::Env env) {
return New(env, kOperationError);
}
Napi::Error Errors::NotAllowedError(Napi::Env env) {
return New(env, kNotAllowedError);
}
}} // namespace wgpu::binding

View File

@ -0,0 +1,60 @@
// Copyright 2021 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef DAWN_NODE_BINDING_ERRORS_H_
#define DAWN_NODE_BINDING_ERRORS_H_
#include "napi.h"
namespace wgpu { namespace binding {
// Errors contains static helper methods for creating DOMException error
// messages as documented at:
// https://heycam.github.io/webidl/#idl-DOMException-error-names
class Errors {
public:
static Napi::Error HierarchyRequestError(Napi::Env);
static Napi::Error WrongDocumentError(Napi::Env);
static Napi::Error InvalidCharacterError(Napi::Env);
static Napi::Error NoModificationAllowedError(Napi::Env);
static Napi::Error NotFoundError(Napi::Env);
static Napi::Error NotSupportedError(Napi::Env);
static Napi::Error InUseAttributeError(Napi::Env);
static Napi::Error InvalidStateError(Napi::Env);
static Napi::Error SyntaxError(Napi::Env);
static Napi::Error InvalidModificationError(Napi::Env);
static Napi::Error NamespaceError(Napi::Env);
static Napi::Error SecurityError(Napi::Env);
static Napi::Error NetworkError(Napi::Env);
static Napi::Error AbortError(Napi::Env);
static Napi::Error URLMismatchError(Napi::Env);
static Napi::Error QuotaExceededError(Napi::Env);
static Napi::Error TimeoutError(Napi::Env);
static Napi::Error InvalidNodeTypeError(Napi::Env);
static Napi::Error DataCloneError(Napi::Env);
static Napi::Error EncodingError(Napi::Env);
static Napi::Error NotReadableError(Napi::Env);
static Napi::Error UnknownError(Napi::Env);
static Napi::Error ConstraintError(Napi::Env);
static Napi::Error DataError(Napi::Env);
static Napi::Error TransactionInactiveError(Napi::Env);
static Napi::Error ReadOnlyError(Napi::Env);
static Napi::Error VersionError(Napi::Env);
static Napi::Error OperationError(Napi::Env);
static Napi::Error NotAllowedError(Napi::Env);
};
}} // namespace wgpu::binding
#endif // DAWN_NODE_BINDING_ERRORS_H_