-
Notifications
You must be signed in to change notification settings - Fork 315
处理value引用问题 #1141 #1147
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
Merged
处理value引用问题 #1141 #1147
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
此 PR 修复了 GM_getValue、GM_setValue 和 GM_getValues API 中的对象引用问题(#1141)。当存储和检索对象类型的值时,原实现会导致返回的对象与内部存储共享引用,使得对返回对象的修改会意外影响存储的数据。
Changes:
- 将
GM_setValue中的JSON.parse(JSON.stringify(value))替换为structuredClone(value)进行深拷贝 - 在
GM_getValue中添加了对象类型检查,返回前使用structuredClone创建副本 - 在
GM_getValues的数组参数分支中添加了对象深拷贝逻辑 - 添加了完整的测试用例验证引用隔离行为
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/app/service/content/gm_api/gm_api.ts | 在 GM_getValue、GM_setValue 和 GM_getValues 中实现对象深拷贝,防止引用泄漏 |
| src/app/service/content/gm_api/gm_api.test.ts | 添加测试用例验证对象值的引用隔离,确保修改返回值不影响存储的数据 |
Comments suppressed due to low confidence (1)
src/app/service/content/gm_api/gm_api.ts:373
- 当
keysOrDefaults为 null 或 undefined 时,直接返回this.scriptRes.value会暴露内部存储的引用。这与本 PR 修复的引用问题相同。应该对返回的对象进行深拷贝,或者遍历所有键并逐个克隆对象类型的值。
if (!keysOrDefaults) {
// Returns all values
return this.scriptRes.value;
}
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
cyfung1031
reviewed
Jan 17, 2026
cyfung1031
approved these changes
Jan 17, 2026
CodFrm
commented
Jan 19, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
概述 Descriptions
close #1141
变更内容 Changes
截图 Screenshots