Skip to content

Commit b1de06b

Browse files
committed
ref: Safer way of overwriting global promise handlers
1 parent 604785e commit b1de06b

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/js/integrations/reactnativeerrorhandlers.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,21 @@ export class ReactNativeErrorHandlers implements Integration {
8787
8888
If the global promise is the same as the imported promise (expected in RN <0.63), we do nothing.
8989
*/
90+
const _onHandle = Promise._onHandle ?? Promise._Y;
91+
const _onReject = Promise._onReject ?? Promise._Z;
92+
9093
if (
9194
Promise !== _global.Promise &&
92-
"_Y" in _global.Promise &&
93-
"_Z" in _global.Promise
95+
typeof _onHandle !== "undefined" &&
96+
typeof _onReject !== "undefined"
9497
) {
95-
_global.Promise._Y = Promise._Y;
96-
_global.Promise._Z = Promise._Z;
98+
if ("_onHandle" in _global.Promise && "_onReject" in _global.Promise) {
99+
_global.Promise._onHandle = _onHandle;
100+
_global.Promise._onReject = _onReject;
101+
} else if ("_Y" in _global.Promise && "_Z" in _global.Promise) {
102+
_global.Promise._Y = _onHandle;
103+
_global.Promise._Z = _onReject;
104+
}
97105
}
98106
/* eslint-enable
99107
@typescript-eslint/no-var-requires,

0 commit comments

Comments
 (0)