-
-
Notifications
You must be signed in to change notification settings - Fork 68
BridgeJS: Correctly emit @JS methods in extensions #694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wfltaylor
wants to merge
5
commits into
swiftwasm:main
Choose a base branch
from
wfltaylor:extensions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
86f07ab
BridgeJS: Correctly emit @JS methods in extensions
wfltaylor 6762c6b
BridgeJS: Improve test coverage for @JS methods and properties in ext…
wfltaylor 825f695
Fix formatting
wfltaylor a93a686
Update test code to avoid accidentally introduced failure
wfltaylor 4c1c32c
Fix CI: update snapshots, formatting, runtime test, add docs and revi…
krodak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...ins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Multifile/CrossFileExtension.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| extension Greeter { | ||
| @JS func greetFormally() -> String { | ||
| return "Good day, " + self.name + "." | ||
| } | ||
| } |
4 changes: 4 additions & 0 deletions
4
...ridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Multifile/CrossFileExtensionClass.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| @JS class Greeter { | ||
| @JS init(name: String) {} | ||
| @JS func greet() -> String { return "" } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...idgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileExtension.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| { | ||
| "exported" : { | ||
| "classes" : [ | ||
| { | ||
| "constructor" : { | ||
| "abiName" : "bjs_Greeter_init", | ||
| "effects" : { | ||
| "isAsync" : false, | ||
| "isStatic" : false, | ||
| "isThrows" : false | ||
| }, | ||
| "parameters" : [ | ||
| { | ||
| "label" : "name", | ||
| "name" : "name", | ||
| "type" : { | ||
| "string" : { | ||
|
|
||
| } | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "methods" : [ | ||
| { | ||
| "abiName" : "bjs_Greeter_greet", | ||
| "effects" : { | ||
| "isAsync" : false, | ||
| "isStatic" : false, | ||
| "isThrows" : false | ||
| }, | ||
| "name" : "greet", | ||
| "parameters" : [ | ||
|
|
||
| ], | ||
| "returnType" : { | ||
| "string" : { | ||
|
|
||
| } | ||
| } | ||
| }, | ||
| { | ||
| "abiName" : "bjs_Greeter_greetFormally", | ||
| "effects" : { | ||
| "isAsync" : false, | ||
| "isStatic" : false, | ||
| "isThrows" : false | ||
| }, | ||
| "name" : "greetFormally", | ||
| "parameters" : [ | ||
|
|
||
| ], | ||
| "returnType" : { | ||
| "string" : { | ||
|
|
||
| } | ||
| } | ||
| } | ||
| ], | ||
| "name" : "Greeter", | ||
| "properties" : [ | ||
|
|
||
| ], | ||
| "swiftCallName" : "Greeter" | ||
| } | ||
| ], | ||
| "enums" : [ | ||
|
|
||
| ], | ||
| "exposeToGlobal" : false, | ||
| "functions" : [ | ||
|
|
||
| ], | ||
| "protocols" : [ | ||
|
|
||
| ], | ||
| "structs" : [ | ||
|
|
||
| ] | ||
| }, | ||
| "moduleName" : "TestModule" | ||
| } |
60 changes: 60 additions & 0 deletions
60
...dgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileExtension.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| @_expose(wasm, "bjs_Greeter_init") | ||
| @_cdecl("bjs_Greeter_init") | ||
| public func _bjs_Greeter_init(_ nameBytes: Int32, _ nameLength: Int32) -> UnsafeMutableRawPointer { | ||
| #if arch(wasm32) | ||
| let ret = Greeter(name: String.bridgeJSLiftParameter(nameBytes, nameLength)) | ||
| return ret.bridgeJSLowerReturn() | ||
| #else | ||
| fatalError("Only available on WebAssembly") | ||
| #endif | ||
| } | ||
|
|
||
| @_expose(wasm, "bjs_Greeter_greet") | ||
| @_cdecl("bjs_Greeter_greet") | ||
| public func _bjs_Greeter_greet(_ _self: UnsafeMutableRawPointer) -> Void { | ||
| #if arch(wasm32) | ||
| let ret = Greeter.bridgeJSLiftParameter(_self).greet() | ||
| return ret.bridgeJSLowerReturn() | ||
| #else | ||
| fatalError("Only available on WebAssembly") | ||
| #endif | ||
| } | ||
|
|
||
| @_expose(wasm, "bjs_Greeter_greetFormally") | ||
| @_cdecl("bjs_Greeter_greetFormally") | ||
| public func _bjs_Greeter_greetFormally(_ _self: UnsafeMutableRawPointer) -> Void { | ||
| #if arch(wasm32) | ||
| let ret = Greeter.bridgeJSLiftParameter(_self).greetFormally() | ||
| return ret.bridgeJSLowerReturn() | ||
| #else | ||
| fatalError("Only available on WebAssembly") | ||
| #endif | ||
| } | ||
|
|
||
| @_expose(wasm, "bjs_Greeter_deinit") | ||
| @_cdecl("bjs_Greeter_deinit") | ||
| public func _bjs_Greeter_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { | ||
| #if arch(wasm32) | ||
| Unmanaged<Greeter>.fromOpaque(pointer).release() | ||
| #else | ||
| fatalError("Only available on WebAssembly") | ||
| #endif | ||
| } | ||
|
|
||
| extension Greeter: ConvertibleToJSValue, _BridgedSwiftHeapObject { | ||
| var jsValue: JSValue { | ||
| return .object(JSObject(id: UInt32(bitPattern: _bjs_Greeter_wrap(Unmanaged.passRetained(self).toOpaque())))) | ||
| } | ||
| } | ||
|
|
||
| #if arch(wasm32) | ||
| @_extern(wasm, module: "TestModule", name: "bjs_Greeter_wrap") | ||
| fileprivate func _bjs_Greeter_wrap_extern(_ pointer: UnsafeMutableRawPointer) -> Int32 | ||
| #else | ||
| fileprivate func _bjs_Greeter_wrap_extern(_ pointer: UnsafeMutableRawPointer) -> Int32 { | ||
| fatalError("Only available on WebAssembly") | ||
| } | ||
| #endif | ||
| @inline(never) fileprivate func _bjs_Greeter_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 { | ||
| return _bjs_Greeter_wrap_extern(pointer) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.