Commit 2e2020b
Add
Summary:
Add a JSI API to get the length of a JavaScript string in UTF-16 code
units. This is equivalent to the "length" property of a JS string.
New API:
- `IRuntime::length(const String&)`: Returns the number of UTF-16 code
units in the string.
Default implementation:
The default implementation in `jsi::Runtime` calls `utf16()` then
returns the size. Note that the default `utf16()` implementation first
converts the JS string to UTF-8, then converts that to UTF-16. This
intermediate UTF-8 step does not handle lone surrogates correctly,
causing code units to be "lost" in the conversion. Runtimes should
provide optimized implementations when possible.
The following optimized implementations are provided:
JSC implementation:
Uses the `JSStringGetLength` API for efficient retrieval.
V8 implementation:
Uses the `v8::String::Length()` API for efficient retrieval.
Differential Revision: D96030262String::length API1 parent 4307394 commit 2e2020b
4 files changed
Lines changed: 60 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
| 182 | + | |
182 | 183 | | |
183 | 184 | | |
184 | 185 | | |
| |||
745 | 746 | | |
746 | 747 | | |
747 | 748 | | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
748 | 753 | | |
749 | 754 | | |
750 | 755 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
602 | 602 | | |
603 | 603 | | |
604 | 604 | | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
605 | 609 | | |
606 | 610 | | |
607 | 611 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
675 | 675 | | |
676 | 676 | | |
677 | 677 | | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
678 | 682 | | |
679 | 683 | | |
680 | 684 | | |
| |||
786 | 790 | | |
787 | 791 | | |
788 | 792 | | |
| 793 | + | |
| 794 | + | |
789 | 795 | | |
790 | 796 | | |
791 | 797 | | |
| |||
1105 | 1111 | | |
1106 | 1112 | | |
1107 | 1113 | | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
1108 | 1119 | | |
1109 | 1120 | | |
1110 | 1121 | | |
| |||
Lines changed: 40 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
101 | 141 | | |
102 | 142 | | |
103 | 143 | | |
| |||
0 commit comments