fix(polyfill): complete window timer and EventTarget aliases - #151
Conversation
NativeScript may install global.addEventListener before window exists, so the old both-undefined guard left window.addEventListener missing. Browser libraries bind window.setTimeout/clearTimeout/matchMedia and documentElement.dataset / style.setProperty. Fill each alias independently.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The red AudioContext jobs are not from this diff.
The last The relevant job for this change is Build Native / Canvas iOS + visionOS. |
Brings in #150 and #151. #151 (window timer / EventTarget aliases) is TypeScript only and merged clean. #150 (TextMetrics for empty measureText) conflicted on the one line this branch spells differently: master reads the length through its canvas::Utf8Length shim, this branch calls Utf8LengthV2 directly. Kept this branch's call and took master's fix, which is the removal of the `if (text_utf8_len == 0) return;` early exit. The rest of MeasureText is safe at length 0: prefix_len is at least 3, so the scratch buffer is never empty, WriteUtf8V2 with a zero length writes nothing, and the empty string measures to a zero-width TextMetrics rather than returning undefined.
Problem
canvas-polyfillonly installedwindow.addEventListenerwhen bothglobalandwindowlacked it. NativeScript often already hasglobal.addEventListener, sowindow.addEventListenerstayed missing.window.setTimeoutwas set withoutclearTimeout. Games that callwindow.matchMedia,document.documentElement.dataset, orstyle.setPropertythrow at module eval.Change
Fill each missing alias independently. Preserve existing implementations. Add
clearTimeout/clearInterval, amatchMediastub,devicePixelRatio,document.hidden/visibilityState,HTMLElement.dataset, andCSSStyleDeclaration.setProperty.Test plan
Four listener-ownership cases (none / global / window / both) plus
matchMediaare in NEONLEAPnative/tests/window-host.test.ts. They fail on unpatched a2c279b8 and pass with this diff.Independent of the empty-
measureTextPR.