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: support window onerror and global error event #601

Merged
merged 6 commits into from Aug 25, 2021

Conversation

andycall
Copy link
Member

@andycall andycall commented Aug 18, 2021

Fixed #600

answershuto
answershuto previously approved these changes Aug 19, 2021
const ex = new Error('CustomErrorTest');
window.onerror = function(event, sourceURL, line, column, error) {
expect(window.onerror).toBe(arguments.callee);
const ex = new Error('CustomErrorTest');
Copy link
Contributor

Choose a reason for hiding this comment

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

需要把相关测试代码组织在 describe 里

Copy link
Member Author

@andycall andycall Aug 23, 2021

Choose a reason for hiding this comment

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

测试 window.onerror 的代码需要独立在 jasmine 之外,因为 jasmine 也会监听 window.onerror,存在冲突

Copy link
Contributor

Choose a reason for hiding this comment

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

移到外部就不冲突了? 会特征判断?那是否只需要 window.onerror 就可以了,而且最好加注释说明下

Copy link
Member Author

Choose a reason for hiding this comment

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

嗯,因为 onerror 的测试是需要直接给 JS 抛个异常,jasmine 直接就当作是测试失败了。

JSValueRef errorObjectValue = getObjectPropertyValue(ctx, eventType, eventInstance->object, &exception);
JSObjectRef errorObject = JSValueToObject(ctx, errorObjectValue, &exception);
JSValueRef messageValue = getObjectPropertyValue(ctx, "message", errorObject, &exception);
JSValueRef sourceURLValue = getObjectPropertyValue(ctx, "sourceURL", errorObject, &exception);
Copy link
Contributor

Choose a reason for hiding this comment

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

为什么不考虑命名上与 w3c 标准对齐

Copy link
Member Author

Choose a reason for hiding this comment

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

image
因为 w3c 标准在不同的引擎之间就是个摆设,Error 的 prototype 上定义了 fileName,lineNumber,无论是 V8 还是 JSC 都没实现。取而代之的是一些各自特有的 API。

Copy link
Contributor

Choose a reason for hiding this comment

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

image

Copy link
Member Author

Choose a reason for hiding this comment

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

这里的代码是操作 Error 对象,而不是 ErrorEvent

@andycall andycall merged commit 4ad8925 into main Aug 25, 2021
@andycall andycall deleted the feat/window_onerror branch August 25, 2021 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

支持 window.onerror
5 participants