File: exception_code.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (183 lines) | stat: -rw-r--r-- 7,007 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_EXCEPTION_CODE_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_EXCEPTION_CODE_H_

namespace blink {

// DOMException uses |unsigned short| for exception codes.
// https://webidl.spec.whatwg.org/#idl-DOMException
// In our DOM implementation we use |int| instead, and use different numerical
// ranges for different types of exceptions (not limited to DOMException), so
// that an exception of any type can be expressed with a single integer.
//
// Zero value in ExceptionCode means no exception being thrown.
using ExceptionCode = int;

// DOMException's error code
// https://webidl.spec.whatwg.org/#idl-DOMException-error-names
enum class DOMExceptionCode : ExceptionCode {
  // DOMExceptions with the legacy error code.

  // Zero value is used for representing no exception.
  kNoError = 0,

  // The minimum value of the legacy error code of DOMException defined in
  // Web IDL.
  // https://webidl.spec.whatwg.org/#idl-DOMException
  kLegacyErrorCodeMin = 1,

  kIndexSizeError = 1,  // Deprecated. Use ECMAScript RangeError instead.
  // DOMStringSizeError (= 2) is deprecated and no longer supported.
  kHierarchyRequestError = 3,
  kWrongDocumentError = 4,
  kInvalidCharacterError = 5,
  // NoDataAllowedError (= 6) is deprecated and no longer supported.
  kNoModificationAllowedError = 7,
  kNotFoundError = 8,
  kNotSupportedError = 9,
  kInUseAttributeError = 10,  // Historical. Only used in setAttributeNode etc
                              // which have been removed from the DOM specs.
  kInvalidStateError = 11,
  // Web IDL 2.7.1 Error names
  // https://webidl.spec.whatwg.org/#idl-DOMException-error-names
  // Note: Don't confuse the "SyntaxError" DOMException defined here with
  // ECMAScript's SyntaxError. "SyntaxError" DOMException is used to report
  // parsing errors in web APIs, for example when parsing selectors, while
  // the ECMAScript SyntaxError is reserved for the ECMAScript parser.
  kSyntaxError = 12,
  kInvalidModificationError = 13,
  kNamespaceError = 14,
  // kInvalidAccessError is deprecated. Use ECMAScript TypeError for invalid
  // arguments, |kNotSupportedError| for unsupported operations, and
  // |kNotAllowedError| for denied requests instead.
  kInvalidAccessError = 15,  // Deprecated.
  // ValidationError (= 16) is deprecated and no longer supported.
  kTypeMismatchError = 17,  // Deprecated. Use ECMAScript TypeError instead.
  // SecurityError should be thrown with ExceptionState::ThrowSecurityError
  // with careful consideration about the message that is observable by web
  // author. Avoid using this error code unless it's really SecurityError.
  //
  // "NotAllowedError" is often a better choice because the error represetnts
  // "The request is not allowed by the user agent or the platform in the
  // current context, possibly because the user denied permission."
  // https://webidl.spec.whatwg.org/#idl-DOMException-error-names
  kSecurityError = 18,
  kNetworkError = 19,
  kAbortError = 20,
  kURLMismatchError = 21,
  kTimeoutError = 23,
  kInvalidNodeTypeError = 24,
  kDataCloneError = 25,

  // The maximum value of the legacy error code of DOMException defined in
  // Web IDL.
  // https://webidl.spec.whatwg.org/#idl-DOMException
  kLegacyErrorCodeMax = 25,

  // DOMExceptions without the legacy error code.
  kEncodingError,
  kNotReadableError,
  kUnknownError,
  kConstraintError,
  kDataError,
  kTransactionInactiveError,
  kReadOnlyError,
  kVersionError,
  kOperationError,
  kNotAllowedError,
  kOptOutError,
  kQuotaExceededError,

  // The rest of entries are defined out of scope of Web IDL.

  // DOMError (obsolete, not DOMException) defined in File system (obsolete).
  // https://www.w3.org/TR/2012/WD-file-system-api-20120417/
  kPathExistsError,

  // Push API
  //
  // PermissionDeniedError (obsolete) was replaced with NotAllowedError in the
  // standard.
  // https://github.com/WICG/BackgroundSync/issues/124
  kPermissionDeniedError,

  // Serial API - https://wicg.github.io/serial
  kBreakError,
  kBufferOverrunError,
  kFramingError,
  kParityError,

  // WebTransport - https://w3c.github.io/webtransport/
  kWebTransportError,

  // Smart Card API
  // https://wicg.github.io/web-smart-card/#smartcarderror-interface
  kSmartCardError,

  // WebGPU https://www.w3.org/TR/webgpu/
  kGPUPipelineError,

  // Media Capture and Streams API
  // https://w3c.github.io/mediacapture-main/#overconstrainederror-interface
  kOverconstrainedError,

  // FedCM API
  // https://fedidcg.github.io/FedCM/#browser-api-identity-credential-error-interface
  kIdentityCredentialError,

  // WebSocketStream - https://websocket.spec.whatwg.org/
  kWebSocketError,

  kNumOfCodes,
};

inline bool IsDOMExceptionCode(ExceptionCode exception_code) {
  return static_cast<ExceptionCode>(1) <= exception_code &&
         exception_code <
             static_cast<ExceptionCode>(DOMExceptionCode::kNumOfCodes);
}

// Exception codes that correspond to ECMAScript Error objects and
// other errors derived from ECMAScript's NativeError class like
// WebAssembly errors.
// https://tc39.github.io/ecma262/#sec-error-objects
enum class ESErrorType : ExceptionCode {
  kError = 1000,    // ECMAScript Error object
  kRangeError,      // ECMAScript RangeError object
  kReferenceError,  // ECMAScript ReferenceError object
  // Note that ECMAScript SyntaxError object is different from DOMException's
  // SyntaxError. See also the comment at |DOMExceptionCode::kSyntaxError|.
  kSyntaxError,       // ECMAScript SyntaxError object
  kTypeError,         // ECMAScript TypeError object
  kWasmCompileError,  // WebAssembly.CompileError object
  kWasmLinkError,     // WebAssembly.LinkError object
  kWasmRuntimeError,  // WebAssembly.RuntimeError object
};

// Exception codes used only inside ExceptionState implementation.
enum class InternalExceptionType : ExceptionCode {
  // An exception code that is used when rethrowing a v8::Value as an
  // exception where there is no way to determine an exception code.
  kRethrownException = 2000,
};

// Upcast from DOMExceptionCode to ExceptionCode as ExceptionCode is considered
// as an union of DOMExceptionCode and ESErrorType.
// Downcast should be performed with explicit static_cast with a range check.
inline ExceptionCode ToExceptionCode(DOMExceptionCode exception_code) {
  return static_cast<ExceptionCode>(exception_code);
}

// Upcast from ESErrorType to ExceptionCode as ExceptionCode is considered
// as an union of DOMExceptionCode and ESErrorType.
// Downcast should be performed with explicit static_cast with a range check.
inline ExceptionCode ToExceptionCode(ESErrorType exception_code) {
  return static_cast<ExceptionCode>(exception_code);
}

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_EXCEPTION_CODE_H_