chore: replace __proto__ by getPrototypeOf (#17386)
This commit is contained in:
parent
df143031e7
commit
840a1f6436
|
|
@ -71,6 +71,7 @@ module.exports = {
|
||||||
"valid-typeof": 2,
|
"valid-typeof": 2,
|
||||||
"no-implicit-globals": [2],
|
"no-implicit-globals": [2],
|
||||||
"no-unused-expressions": [2, { "allowShortCircuit": true, "allowTernary": true, "allowTaggedTemplates": true}],
|
"no-unused-expressions": [2, { "allowShortCircuit": true, "allowTernary": true, "allowTaggedTemplates": true}],
|
||||||
|
"no-proto": 2,
|
||||||
|
|
||||||
// es2015 features
|
// es2015 features
|
||||||
"require-yield": 2,
|
"require-yield": 2,
|
||||||
|
|
|
||||||
|
|
@ -184,5 +184,6 @@ function isURL(obj: any): obj is URL {
|
||||||
}
|
}
|
||||||
|
|
||||||
function isError(obj: any): obj is Error {
|
function isError(obj: any): obj is Error {
|
||||||
return obj instanceof Error || obj?.__proto__?.name === 'Error' || (obj?.__proto__ && isError(obj.__proto__));
|
const proto = obj ? Object.getPrototypeOf(obj) : null;
|
||||||
|
return obj instanceof Error || proto?.name === 'Error' || (proto && isError(proto));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ export function source() {
|
||||||
|
|
||||||
function isError(obj: any): obj is Error {
|
function isError(obj: any): obj is Error {
|
||||||
try {
|
try {
|
||||||
return obj instanceof Error || (obj && obj.__proto__ && obj.__proto__.name === 'Error');
|
return obj instanceof Error || (obj && Object.getPrototypeOf(obj)?.name === 'Error');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ export function isObject(obj: any): obj is NonNullable<object> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isError(obj: any): obj is Error {
|
export function isError(obj: any): obj is Error {
|
||||||
return obj instanceof Error || (obj && obj.__proto__ && obj.__proto__.name === 'Error');
|
return obj instanceof Error || (obj && Object.getPrototypeOf(obj)?.name === 'Error');
|
||||||
}
|
}
|
||||||
|
|
||||||
const debugEnv = getFromENV('PWDEBUG') || '';
|
const debugEnv = getFromENV('PWDEBUG') || '';
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue