Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: onUnhandledRejection 支持core-js promise polyfill #1822

Merged
merged 5 commits into from
Jan 17, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/core/src/platform/env/index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,15 @@ function initGlobalErrorHandling () {
}
}

// 支持 core-js promise polyfill
const oldOnUnhandledRejection = global.onunhandledrejection
global.onunhandledrejection = function onunhandledrejection (event) {
// event = { promise, reason }
rejectionTrackingOptions.onUnhandled(null, event.reason)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

把promise作为三个参数传过去,然后onUnhandled中做一下兼容处理

oldOnUnhandledRejection.apply(this, event)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这应该是call吧

}
if (global?.HermesInternal?.hasPromise?.()) {
global.HermesInternal?.enablePromiseRejectionTracker?.(rejectionTrackingOptions)
global.HermesInternal.enablePromiseRejectionTracker?.(rejectionTrackingOptions)
} else {
require('promise/setimmediate/rejection-tracking').enable(rejectionTrackingOptions)
}
Expand Down
Loading