|
3 | 3 | const { |
4 | 4 | Error, |
5 | 5 | ErrorPrototype, |
| 6 | + NumberIsFinite, |
| 7 | + NumberIsNaN, |
6 | 8 | ObjectDefineProperties, |
7 | 9 | ObjectDefineProperty, |
8 | 10 | ObjectSetPrototypeOf, |
| 11 | + RangeError, |
9 | 12 | SafeMap, |
10 | 13 | SafeSet, |
11 | 14 | SafeWeakMap, |
@@ -203,3 +206,91 @@ for (const { 0: name, 1: codeName, 2: value } of [ |
203 | 206 | } |
204 | 207 |
|
205 | 208 | exports.DOMException = DOMException; |
| 209 | + |
| 210 | +// https://webidl.spec.whatwg.org/#quotaexceedederror |
| 211 | +class QuotaExceededError extends DOMException { |
| 212 | + #quota; |
| 213 | + #requested; |
| 214 | + |
| 215 | + constructor(message = '', options = { __proto__: null }) { |
| 216 | + super(message, 'QuotaExceededError'); |
| 217 | + this[transfer_mode_private_symbol] = kCloneable; |
| 218 | + |
| 219 | + let quota = null; |
| 220 | + let requested = null; |
| 221 | + |
| 222 | + if (options !== null && options !== undefined) { |
| 223 | + if ('quota' in options) { |
| 224 | + quota = +options.quota; |
| 225 | + if (!NumberIsFinite(quota)) { |
| 226 | + // eslint-disable-next-line no-restricted-syntax |
| 227 | + throw new TypeError( |
| 228 | + `Cannot convert options.quota to a double: the value is ${NumberIsNaN(quota) ? 'NaN' : 'Infinity'}`, |
| 229 | + ); |
| 230 | + } |
| 231 | + if (quota < 0) { |
| 232 | + // eslint-disable-next-line no-restricted-syntax |
| 233 | + throw new RangeError('options.quota must not be negative'); |
| 234 | + } |
| 235 | + } |
| 236 | + |
| 237 | + if ('requested' in options) { |
| 238 | + requested = +options.requested; |
| 239 | + if (!NumberIsFinite(requested)) { |
| 240 | + // eslint-disable-next-line no-restricted-syntax |
| 241 | + throw new TypeError( |
| 242 | + `Cannot convert options.requested to a double: the value is ${NumberIsNaN(requested) ? 'NaN' : 'Infinity'}`, |
| 243 | + ); |
| 244 | + } |
| 245 | + if (requested < 0) { |
| 246 | + // eslint-disable-next-line no-restricted-syntax |
| 247 | + throw new RangeError('options.requested must not be negative'); |
| 248 | + } |
| 249 | + } |
| 250 | + } |
| 251 | + |
| 252 | + if (quota !== null && requested !== null && requested < quota) { |
| 253 | + // eslint-disable-next-line no-restricted-syntax |
| 254 | + throw new RangeError('options.requested must not be less than options.quota'); |
| 255 | + } |
| 256 | + |
| 257 | + this.#quota = quota; |
| 258 | + this.#requested = requested; |
| 259 | + } |
| 260 | + |
| 261 | + [messaging_clone_symbol]() { |
| 262 | + const domExceptionClone = DOMExceptionPrototype[messaging_clone_symbol].call(this); |
| 263 | + domExceptionClone.data.quota = this.#quota; |
| 264 | + domExceptionClone.data.requested = this.#requested; |
| 265 | + domExceptionClone.deserializeInfo = 'internal/worker/clone_dom_exception:QuotaExceededError'; |
| 266 | + return domExceptionClone; |
| 267 | + } |
| 268 | + |
| 269 | + [messaging_deserialize_symbol](data) { |
| 270 | + DOMExceptionPrototype[messaging_deserialize_symbol].call(this, data); |
| 271 | + this.#quota = data.quota; |
| 272 | + this.#requested = data.requested; |
| 273 | + } |
| 274 | + |
| 275 | + get quota() { |
| 276 | + if (!(#quota in this)) { |
| 277 | + throwInvalidThisError(TypeError, 'QuotaExceededError'); |
| 278 | + } |
| 279 | + return this.#quota; |
| 280 | + } |
| 281 | + |
| 282 | + get requested() { |
| 283 | + if (!(#requested in this)) { |
| 284 | + throwInvalidThisError(TypeError, 'QuotaExceededError'); |
| 285 | + } |
| 286 | + return this.#requested; |
| 287 | + } |
| 288 | +} |
| 289 | + |
| 290 | +ObjectDefineProperties(QuotaExceededError.prototype, { |
| 291 | + [SymbolToStringTag]: { __proto__: null, configurable: true, value: 'QuotaExceededError' }, |
| 292 | + quota: { __proto__: null, enumerable: true, configurable: true }, |
| 293 | + requested: { __proto__: null, enumerable: true, configurable: true }, |
| 294 | +}); |
| 295 | + |
| 296 | +exports.QuotaExceededError = QuotaExceededError; |
0 commit comments