Skip to content

Commit

Permalink
chore: replace __proto__ by getPrototypeOf (#17386)
Browse files Browse the repository at this point in the history
  • Loading branch information
kapouer committed Sep 21, 2022
1 parent df14303 commit 840a1f6
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -71,6 +71,7 @@ module.exports = {
"valid-typeof": 2,
"no-implicit-globals": [2],
"no-unused-expressions": [2, { "allowShortCircuit": true, "allowTernary": true, "allowTaggedTemplates": true}],
"no-proto": 2,

// es2015 features
"require-yield": 2,
Expand Down
3 changes: 2 additions & 1 deletion packages/playwright-core/src/protocol/serializers.ts
Expand Up @@ -184,5 +184,6 @@ function isURL(obj: any): obj is URL {
}

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));
}
Expand Up @@ -48,7 +48,7 @@ export function source() {

function isError(obj: any): obj is Error {
try {
return obj instanceof Error || (obj && obj.__proto__ && obj.__proto__.name === 'Error');
return obj instanceof Error || (obj && Object.getPrototypeOf(obj)?.name === 'Error');
} catch (error) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/utils/index.ts
Expand Up @@ -87,7 +87,7 @@ export function isObject(obj: any): obj is NonNullable<object> {
}

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') || '';
Expand Down

0 comments on commit 840a1f6

Please sign in to comment.