Repository navigation
Commit c3a31ff
committed
BridgeJS: Support @js protocol constraints on generic exports
The same protocol compositions now work on exported generics:
@js public func storeNode<T: BridgedSwiftGenericBridgeable & GraphNode>(_ node: T) -> T { node }
Unlike imports, the Swift compiler cannot check a JavaScript caller, so
the constraint is enforced at the boundary: the link layer records every
@js type's conformed @js protocols (declared on the type or via an
extension) in a token-to-conformances map, and the generated wrapper
resolves the caller's BridgeTypes token against the constraint before
anything is lowered. A non-conforming token throws a catchable TypeError
without entering wasm, keeping the shared value stack balanced; the
Swift-side generic signature then guarantees the constraint holds inside
the thunk. The d.ts wrapper signature carries 'T extends GraphNode', so
TypeScript users get the check at compile time as well.1 parent ec4cef3 commit c3a31ff
31 files changed
Lines changed: 2781 additions & 65 deletions
File tree
- Plugins/BridgeJS
- Sources
- BridgeJSCore
- BridgeJSLink
- BridgeJSSkeleton
- Tests/BridgeJSToolTests
- Inputs/MacroSwift
- __Snapshots__
- BridgeJSCodegenTests
- BridgeJSLinkTests
- Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS
- BridgeJS-Internals
- Exporting-Swift
- Importing-JavaScript
- Tests/BridgeJSRuntimeTests
- Generated
- JavaScript
- JavaScript
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
192 | | - | |
| 192 | + | |
| 193 | + | |
193 | 194 | | |
194 | 195 | | |
195 | | - | |
| 196 | + | |
| 197 | + | |
196 | 198 | | |
197 | 199 | | |
198 | 200 | | |
199 | 201 | | |
200 | 202 | | |
201 | 203 | | |
202 | 204 | | |
203 | | - | |
| 205 | + | |
204 | 206 | | |
205 | | - | |
| 207 | + | |
206 | 208 | | |
207 | | - | |
| 209 | + | |
208 | 210 | | |
209 | 211 | | |
210 | 212 | | |
| |||
528 | 530 | | |
529 | 531 | | |
530 | 532 | | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
531 | 538 | | |
532 | | - | |
| 539 | + | |
533 | 540 | | |
534 | | - | |
| 541 | + | |
535 | 542 | | |
536 | 543 | | |
537 | 544 | | |
538 | | - | |
| 545 | + | |
| 546 | + | |
539 | 547 | | |
540 | | - | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
541 | 553 | | |
542 | 554 | | |
543 | 555 | | |
| |||
591 | 603 | | |
592 | 604 | | |
593 | 605 | | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
594 | 609 | | |
595 | | - | |
| 610 | + | |
596 | 611 | | |
597 | 612 | | |
598 | 613 | | |
599 | 614 | | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
600 | 629 | | |
601 | 630 | | |
602 | 631 | | |
| |||
776 | 805 | | |
777 | 806 | | |
778 | 807 | | |
779 | | - | |
| 808 | + | |
780 | 809 | | |
781 | 810 | | |
782 | 811 | | |
| |||
823 | 852 | | |
824 | 853 | | |
825 | 854 | | |
826 | | - | |
| 855 | + | |
827 | 856 | | |
828 | 857 | | |
829 | 858 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
| 305 | + | |
| 306 | + | |
305 | 307 | | |
306 | 308 | | |
307 | 309 | | |
| |||
420 | 422 | | |
421 | 423 | | |
422 | 424 | | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
423 | 469 | | |
424 | 470 | | |
425 | 471 | | |
| |||
1553 | 1599 | | |
1554 | 1600 | | |
1555 | 1601 | | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
1556 | 1616 | | |
1557 | 1617 | | |
1558 | 1618 | | |
| |||
1668 | 1728 | | |
1669 | 1729 | | |
1670 | 1730 | | |
1671 | | - | |
1672 | | - | |
1673 | | - | |
1674 | | - | |
1675 | | - | |
1676 | | - | |
1677 | | - | |
1678 | | - | |
1679 | 1731 | | |
1680 | 1732 | | |
1681 | 1733 | | |
| |||
2260 | 2312 | | |
2261 | 2313 | | |
2262 | 2314 | | |
2263 | | - | |
| 2315 | + | |
| 2316 | + | |
2264 | 2317 | | |
2265 | 2318 | | |
2266 | 2319 | | |
| |||
2426 | 2479 | | |
2427 | 2480 | | |
2428 | 2481 | | |
2429 | | - | |
| 2482 | + | |
| 2483 | + | |
2430 | 2484 | | |
2431 | 2485 | | |
2432 | 2486 | | |
| |||
2653 | 2707 | | |
2654 | 2708 | | |
2655 | 2709 | | |
2656 | | - | |
| 2710 | + | |
| 2711 | + | |
2657 | 2712 | | |
2658 | 2713 | | |
2659 | 2714 | | |
| |||
4051 | 4106 | | |
4052 | 4107 | | |
4053 | 4108 | | |
| 4109 | + | |
| 4110 | + | |
| 4111 | + | |
| 4112 | + | |
| 4113 | + | |
| 4114 | + | |
| 4115 | + | |
| 4116 | + | |
| 4117 | + | |
| 4118 | + | |
| 4119 | + | |
| 4120 | + | |
| 4121 | + | |
| 4122 | + | |
| 4123 | + | |
| 4124 | + | |
| 4125 | + | |
| 4126 | + | |
| 4127 | + | |
| 4128 | + | |
| 4129 | + | |
| 4130 | + | |
| 4131 | + | |
| 4132 | + | |
0 commit comments