Commit b1137d5
committed
Introduce a CheckedBehavior for StringIndexOutOfBoundsException.
Fundamentally, the primitive operation that causes language-
mandated `StringIndexOutOfBoundsException`s is `String.charAt`.
In order for the linker to recognize it and conditionally apply
checked behavior semantics to it, we introduce a new IR
`BinaryOp.String_charAt` for that operation.
We use a compiler back-end hack to inject that IR node as the body
of `String.charAt`. Using a dedicated primitive method in
`scalajs.runtime`, like we did for `identityHashCode`, would not
work so well here, as we want the binary operator to manipulate a
*primitive* `StringType`, not a `ClassType(BoxedStringClass)`.
For derived methods that are implemented on top of JS primitives,
namely `codePointAt` and `substring`, we use a trick similar to
what we did in `j.u.Arrays`: we introduce carefully-chosen no-op
calls to `charAt`, with the only purpose of checking bounds, before
delegating to the JS methods. Since `s.length()` is not known to be
pure by the optimizer, we use clever tricks not to call it in the
bounds checks of `substring`.1 parent 8e6e6db commit b1137d5
File tree
21 files changed
+286
-43
lines changed- compiler/src/main/scala/org/scalajs/nscplugin
- javalib/src/main/scala/java/lang
- partest/src/main/scala/scala/tools/nsc
- project
- test-suite
- js/src/main
- scala-ide-stubs/org/scalajs/testsuite/utils
- scala/org/scalajs/testsuite/utils
- jvm/src/main/scala/org/scalajs/testsuite/utils
21 files changed
+286
-43
lines changedLines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2236 | 2236 | | |
2237 | 2237 | | |
2238 | 2238 | | |
2239 | | - | |
| 2239 | + | |
| 2240 | + | |
| 2241 | + | |
| 2242 | + | |
2240 | 2243 | | |
2241 | 2244 | | |
2242 | 2245 | | |
| |||
7059 | 7062 | | |
7060 | 7063 | | |
7061 | 7064 | | |
| 7065 | + | |
| 7066 | + | |
| 7067 | + | |
7062 | 7068 | | |
7063 | 7069 | | |
7064 | 7070 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
501 | 501 | | |
502 | 502 | | |
503 | 503 | | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
504 | 508 | | |
505 | 509 | | |
506 | 510 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
411 | 411 | | |
412 | 412 | | |
413 | 413 | | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
414 | 420 | | |
415 | 421 | | |
416 | 422 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
420 | 420 | | |
421 | 421 | | |
422 | 422 | | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
423 | 426 | | |
424 | 427 | | |
425 | 428 | | |
| |||
439 | 442 | | |
440 | 443 | | |
441 | 444 | | |
| 445 | + | |
| 446 | + | |
442 | 447 | | |
443 | 448 | | |
444 | 449 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
538 | 538 | | |
539 | 539 | | |
540 | 540 | | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
541 | 544 | | |
542 | 545 | | |
543 | 546 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
372 | 373 | | |
373 | 374 | | |
374 | 375 | | |
375 | | - | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
376 | 381 | | |
| 382 | + | |
377 | 383 | | |
378 | 384 | | |
379 | | - | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
380 | 394 | | |
| 395 | + | |
381 | 396 | | |
382 | 397 | | |
383 | 398 | | |
| |||
Lines changed: 18 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
34 | 38 | | |
35 | 39 | | |
36 | 40 | | |
| |||
53 | 57 | | |
54 | 58 | | |
55 | 59 | | |
| 60 | + | |
56 | 61 | | |
57 | 62 | | |
58 | 63 | | |
| |||
61 | 66 | | |
62 | 67 | | |
63 | 68 | | |
| 69 | + | |
64 | 70 | | |
65 | 71 | | |
66 | 72 | | |
| |||
74 | 80 | | |
75 | 81 | | |
76 | 82 | | |
| 83 | + | |
77 | 84 | | |
78 | 85 | | |
79 | 86 | | |
80 | 87 | | |
81 | | - | |
| 88 | + | |
82 | 89 | | |
83 | 90 | | |
84 | 91 | | |
85 | 92 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
91 | 99 | | |
92 | 100 | | |
93 | 101 | | |
94 | 102 | | |
95 | 103 | | |
96 | 104 | | |
| 105 | + | |
97 | 106 | | |
98 | 107 | | |
99 | 108 | | |
| |||
102 | 111 | | |
103 | 112 | | |
104 | 113 | | |
| 114 | + | |
105 | 115 | | |
106 | 116 | | |
107 | 117 | | |
| |||
217 | 227 | | |
218 | 228 | | |
219 | 229 | | |
| 230 | + | |
220 | 231 | | |
221 | 232 | | |
222 | 233 | | |
| |||
228 | 239 | | |
229 | 240 | | |
230 | 241 | | |
| 242 | + | |
231 | 243 | | |
232 | 244 | | |
233 | 245 | | |
| |||
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
892 | 892 | | |
893 | 893 | | |
894 | 894 | | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
895 | 911 | | |
896 | 912 | | |
897 | 913 | | |
| |||
Lines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
828 | 828 | | |
829 | 829 | | |
830 | 830 | | |
831 | | - | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
832 | 837 | | |
833 | 838 | | |
834 | 839 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
0 commit comments