Repository navigation
Commit be567d2
Forward String::length in RuntimeDecorator and WithRuntimeDecorator (#58936)
Summary:
Pull Request resolved: #58936
`IRuntime::length(const String&)` came in with "Add `String::length` API" (590396bd4 on static_h, D96030262), and that commit didn't touch `decorator.h`. Neither `RuntimeDecorator` nor `WithRuntimeDecorator` overrides it, so on a decorated runtime `length()` falls back to the default `utf16(str).size()` and never reaches the wrapped runtime.
It looks like an oversight. The same stack added `push`, `tryGetMutableBuffer`, `detached` and the TypedArray methods, and each of those commits added decorator overrides, including one for this method's overload `length(const TypedArray&)`. The `createError*` commit (meta/hermes#2203) and this one didn't.
For Hermes-backed decorators the value is already right, because Hermes' `utf16()` is exact, but every call copies the whole string instead of reading the length. Runtimes with a native `length()` and the default `utf16()` get wrong answers. React Native's `JSCRuntime` is one: built against the system JavaScriptCore and wrapped in a `RuntimeDecorator`, `'a\uD800b'` has length 1 instead of 3 and `'x\uDC00yz'` has 1 instead of 4. With this change both match the undecorated runtime. That setup lives outside this repo, so it isn't a test here.
`WithRuntimeDecorator` needs the override too. Otherwise it would inherit the plain forward and `length()` would skip `Around`, which it currently goes through via `utf16()`.
`TracingRuntime` no longer records an incidental `Utf16Record` when `length()` is called. That record only came from the `utf16()` fallback. I didn't add a record for `length()`: strings are immutable, and `TracingRuntime` already leaves pure queries like `size(Array)` untraced.
X-link: meta/hermes#2205
Test Plan:
Added `JSITest.DecoratorForwardsStringLength`. An inner decorator returns a sentinel from `length()` and counts `length()` and `utf16()` calls. The test checks that a `RuntimeDecorator` and a `WithRuntimeDecorator` over it both reach that `length()` without calling `utf16()`, and that `Around` runs once. It fails without the change (it gets 5 from the `utf16()` fallback) and passes with it. The full `APITests` binary passes (357 tests) in a Debug + ASan build, including the SynthTrace and TraceInterpreter tests.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Reviewed By: avp
Differential Revision: D123943189
Pulled By: lavenzg
fbshipit-source-id: 519fdde9f2ad46ce906567bfd1d94d787015915c1 parent 4fec40e commit be567d2
11 files changed
Lines changed: 82 additions & 0 deletions
File tree
- packages/react-native/ReactCommon/jsi/jsi
- test
- scripts/cxx-api/api-snapshots
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
246 | 250 | | |
247 | 251 | | |
248 | 252 | | |
| |||
822 | 826 | | |
823 | 827 | | |
824 | 828 | | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
825 | 834 | | |
826 | 835 | | |
827 | 836 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
141 | 196 | | |
142 | 197 | | |
143 | 198 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12784 | 12784 | | |
12785 | 12785 | | |
12786 | 12786 | | |
| 12787 | + | |
12787 | 12788 | | |
12788 | 12789 | | |
12789 | 12790 | | |
| |||
12902 | 12903 | | |
12903 | 12904 | | |
12904 | 12905 | | |
| 12906 | + | |
12905 | 12907 | | |
12906 | 12908 | | |
12907 | 12909 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12400 | 12400 | | |
12401 | 12401 | | |
12402 | 12402 | | |
| 12403 | + | |
12403 | 12404 | | |
12404 | 12405 | | |
12405 | 12406 | | |
| |||
12518 | 12519 | | |
12519 | 12520 | | |
12520 | 12521 | | |
| 12522 | + | |
12521 | 12523 | | |
12522 | 12524 | | |
12523 | 12525 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12631 | 12631 | | |
12632 | 12632 | | |
12633 | 12633 | | |
| 12634 | + | |
12634 | 12635 | | |
12635 | 12636 | | |
12636 | 12637 | | |
| |||
12749 | 12750 | | |
12750 | 12751 | | |
12751 | 12752 | | |
| 12753 | + | |
12752 | 12754 | | |
12753 | 12755 | | |
12754 | 12756 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14545 | 14545 | | |
14546 | 14546 | | |
14547 | 14547 | | |
| 14548 | + | |
14548 | 14549 | | |
14549 | 14550 | | |
14550 | 14551 | | |
| |||
14663 | 14664 | | |
14664 | 14665 | | |
14665 | 14666 | | |
| 14667 | + | |
14666 | 14668 | | |
14667 | 14669 | | |
14668 | 14670 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14227 | 14227 | | |
14228 | 14228 | | |
14229 | 14229 | | |
| 14230 | + | |
14230 | 14231 | | |
14231 | 14232 | | |
14232 | 14233 | | |
| |||
14345 | 14346 | | |
14346 | 14347 | | |
14347 | 14348 | | |
| 14349 | + | |
14348 | 14350 | | |
14349 | 14351 | | |
14350 | 14352 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14402 | 14402 | | |
14403 | 14403 | | |
14404 | 14404 | | |
| 14405 | + | |
14405 | 14406 | | |
14406 | 14407 | | |
14407 | 14408 | | |
| |||
14520 | 14521 | | |
14521 | 14522 | | |
14522 | 14523 | | |
| 14524 | + | |
14523 | 14525 | | |
14524 | 14526 | | |
14525 | 14527 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9731 | 9731 | | |
9732 | 9732 | | |
9733 | 9733 | | |
| 9734 | + | |
9734 | 9735 | | |
9735 | 9736 | | |
9736 | 9737 | | |
| |||
9849 | 9850 | | |
9850 | 9851 | | |
9851 | 9852 | | |
| 9853 | + | |
9852 | 9854 | | |
9853 | 9855 | | |
9854 | 9856 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9555 | 9555 | | |
9556 | 9556 | | |
9557 | 9557 | | |
| 9558 | + | |
9558 | 9559 | | |
9559 | 9560 | | |
9560 | 9561 | | |
| |||
9673 | 9674 | | |
9674 | 9675 | | |
9675 | 9676 | | |
| 9677 | + | |
9676 | 9678 | | |
9677 | 9679 | | |
9678 | 9680 | | |
| |||
0 commit comments