• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16package escompat;
17
18/**
19 * @class Represents an error that occurs when global eval() function fails
20 */
21export class EvalError extends Error {
22    constructor(message?: String, options?: ErrorOptions) {
23        super("EvalError", message, options)
24    }
25
26    static invoke(message?: String, options?: ErrorOptions): EvalError {
27        return new EvalError(message, options)
28    }
29
30    static invoke(message: String): EvalError {
31        return new EvalError(message)
32    }
33}
34
35/**
36 * @class Represents an error that occurs when an operation could not be performed, typically (but not exclusively) when a value is not of the expected type
37 */
38export class TypeError extends Error {
39    constructor(message?: String, options?: ErrorOptions) {
40        super("TypeError", message, options)
41    }
42
43    static invoke(message?: String, options?: ErrorOptions): TypeError {
44        return new TypeError(message, options)
45    }
46
47    static invoke(message: String): TypeError {
48        return new TypeError(message)
49    }
50}
51
52/**
53 * @class Represents an error that occurs when a variable that doesn't exist (or hasn't yet been initialized) in the current scope is referenced
54 */
55export class ReferenceError extends Error {
56    constructor(message?: String, options?: ErrorOptions) {
57        super("ReferenceError", message, options)
58    }
59
60    static invoke(message?: String, options?: ErrorOptions): ReferenceError {
61        return new ReferenceError(message, options)
62    }
63
64    static invoke(message: String): ReferenceError {
65        return new ReferenceError(message)
66    }
67}
68
69/**
70 * @class Represents an error that occurs when a global URI handling function was used in a wrong way
71 */
72export class URIError extends Error {
73    constructor(message?: String, options?: ErrorOptions) {
74        super("URIError", message, options)
75    }
76
77    static invoke(message?: String, options?: ErrorOptions): URIError {
78        return new URIError(message, options)
79    }
80
81    static invoke(message: String): URIError {
82        return new URIError(message)
83    }
84}
85
86/**
87 * The AggregateError object represents an error when several errors
88 * need to be wrapped in a single error.
89 */
90export class AggregateError extends Error {
91    errors: Error[] = [];
92
93    /**
94     * The AggregateError() constructor creates AggregateError
95     * object.
96     *
97     * @param errors An iterable of errors, may not actually be Error
98     * instances.
99     *
100     * @param s An human-readable description of the aggregate error.
101     *
102     * @param cause A property indicating the specific cause of the
103     * error. When catching and re-throwing an error with a
104     * more-specific or useful error message, this property can be
105     * used to pass the original error.
106     *
107     */
108    constructor(errors: Iterable<Error>, message?: String, options?: ErrorOptions) {
109        super("AggregateError", message, options);
110        let iteratorList = new ArrayAsListObject()
111        iteratorForEach<Error>(errors.$_iterator(), (x: Error) : void => {
112            iteratorList.pushBack(x)
113        })
114        this.errors = iteratorList.toArray() as Error[]
115    }
116
117
118    //NOTE(kirill-mitkin): Used in Promise, need to remove
119    constructor(errors: Error[], message: String) {
120        super("AggregateError", message, undefined)
121        this.errors = errors
122    }
123
124    static invoke(errors: Iterable<Error>, message?: String, options?: ErrorOptions): AggregateError {
125        return new AggregateError(errors, message, options)
126    }
127
128}
129
130/**
131 * Represents error that is thrown when Date is malformed
132 */
133export final class InvalidDate extends Error {}
134