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

新增脚本支持顶级await #258

Merged
merged 2 commits into from Feb 1, 2024
Merged

新增脚本支持顶级await #258

merged 2 commits into from Feb 1, 2024

Conversation

DreamNya
Copy link
Contributor

@DreamNya DreamNya commented Feb 1, 2024

简单测试了下没啥问题
不清楚是否会引起蝴蝶效应

@CodFrm
Copy link
Member

CodFrm commented Feb 1, 2024

调用的地方不多,应该没问题不大,先合了,近期有计划修下之前的bug发个fix版本

@CodFrm CodFrm merged commit 3a37af2 into scriptscat:main Feb 1, 2024
1 check passed
@@ -17,7 +17,7 @@ export function compileScriptCode(scriptRes: ScriptRunResouce): string {
});
}
code = require + code;
return `with (context) return (()=>{\n${code}\n//# sourceURL=${chrome.runtime.getURL(
return `with (context) return (async ()=>{\n${code}\n//# sourceURL=${chrome.runtime.getURL(
Copy link
Contributor

Choose a reason for hiding this comment

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

我有个问题,这样相当于把脚本注入做成了异步,在比较严格要求document.start的脚本中会不会出现问题?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

脚本注入是在window上挂载一个闭包函数,然后执行。
这段代码外部还有一个闭包函数,这段代码只是在闭包中把同步改成异步,不影响闭包外代码。

Copy link
Contributor

Choose a reason for hiding this comment

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

我就是指的闭包内的这个代码,整个闭包相当于成为了异步,执行的优先级被拉低了,变成了微任务队列

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image
我试了下没啥问题

Copy link
Contributor

Choose a reason for hiding this comment

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

确实没问题,感觉我得复习下Js基础了

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.

None yet

3 participants