You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
Checklist / 检查清单
背景
對應 issue #1701:Firefox 的
USER_SCRIPTworld 中,globalThis與頁面window屬於不同 JavaScript realm。原有 sandbox 建模隱含global === window,因此會把 JavaScript realm 的 intrinsic、頁面 Window 的 DOM/WebIDL 成員,以及 userscript 自己的 global 混在同一條 descriptor chain 中。這會造成
window/self/globalThisalias 不一致、DOM/EventTarget method receiver 錯誤,以及Node、NodeFilter、XMLHttpRequest等 constructor/interface 的 prototype 或 static properties 在 bind 後遺失。本次改動
realmGlobal:保留 userscript realm 的 JavaScript intrinsics,且只收集 own properties。hostWindow:提供 DOM、Window accessor、EventTarget method 與必要的 host constructor。scriptGlobal:userscript 實際看到的 sandbox global。window、self、globalThis、top、parent、frames維持 sandbox identity。hostWindow,同時保留 constructor/interface 的 prototype 與 static properties,避免 brand check 與 static constant 失效。globalThis !== window的實際結構來決定 split-realm 行為,不依賴瀏覽器名稱判斷。實現考慮
descriptor 的來源順序固定為:
realmGlobal own properties→hostWindow prototype chain→host event properties→明確 whitelist forwarding先處理的 realm/子類 descriptor 優先,避免後續父類 descriptor 覆蓋;host Window 的一般 own properties 不會被批量複製。需要 receiver 的 host function 會使用
hostWindow,而 interface/constructor 則保留原本的 callable、prototype 與 static surface。事件 property 維持既有 lifecycle 契約:註冊與移除作用在同一個
hostWindow,callback 的this仍然是 sandbox;primitive handler、function 替換/清除與 object handler 都有測試覆蓋。已知限制
createProxyContext()的 dual-source sandbox model;沒有改變@grant none是否建立 sandbox 的既有 policy。Cu.Sandbox/ Xray runtime 中手動驗證。tests/verification-tools.test.mjs嘗試監聽127.0.0.1時收到listen EPERM,結果為 343/344 test files、4316/4317 tests 通過。onurlchangecustom roots 與所有 host whitelist 成員尚未各自建立完整 browser coverage。建議審查重點
on*event property 的 register/remove/replace lifecycle。參考
src/app/service/content/create_context.tssrc/app/service/content/create_context.test.ts驗證
pnpm exec vitest run src/app/service/content/create_context.test.ts src/app/service/content/exec_script.test.ts src/app/service/content/exec_warp.test.ts --reporter=dot— 3 files / 72 tests passedpnpm run typecheck— passedpnpm run lint— passedpnpm exec eslint . --cache --cache-location .eslintcache— passedpnpm exec prettier --check src/app/service/content/create_context.ts— passedpnpm run test:ci— 343/344 files、4316/4317 tests passed;唯一失敗為上述 localhostEPERM環境限制