Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcb3ea6c

Browse files
Merge pull request#423 from swiftwasm/yt/doc-bridgejs
BridgeJS: Standardize lift/lower pattern across Swift and JavaScript
2 parents3c8726e +07c1ef7 commitcb3ea6c

File tree

56 files changed

+1993
-1578
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1993
-1578
lines changed

‎Benchmarks/Sources/Generated/BridgeJS.ImportTS.swift‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func benchmarkHelperNoopWithNumber(_ n: Double) throws(JSException) -> Void {
3030
fatalError("Only available on WebAssembly")
3131
}
3232
#endif
33-
bjs_benchmarkHelperNoopWithNumber(n)
33+
bjs_benchmarkHelperNoopWithNumber(n.bridgeJSLowerParameter())
3434
iflet error=_swift_js_take_exception(){
3535
throw error
3636
}
@@ -45,11 +45,7 @@ func benchmarkRunner(_ name: String, _ body: JSObject) throws(JSException) -> Vo
4545
fatalError("Only available on WebAssembly")
4646
}
4747
#endif
48-
varname= name
49-
letnameId= name.withUTF8{ bin
50-
_swift_js_make_js_string(b.baseAddress.unsafelyUnwrapped,Int32(b.count))
51-
}
52-
bjs_benchmarkRunner(nameId,Int32(bitPattern: body.id))
48+
bjs_benchmarkRunner(name.bridgeJSLowerParameter(), body.bridgeJSLowerParameter())
5349
iflet error=_swift_js_take_exception(){
5450
throw error
5551
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../Plugins/BridgeJS/Sources/BridgeJSUtilities

‎Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.ExportSwift.swift‎

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,19 @@
1111
publicfunc _bjs_PlayBridgeJS_init()->UnsafeMutableRawPointer{
1212
#if arch(wasm32)
1313
letret=PlayBridgeJS()
14-
returnUnmanaged.passRetained(ret).toOpaque()
14+
return ret.bridgeJSLowerReturn()
1515
#else
1616
fatalError("Only available on WebAssembly")
1717
#endif
1818
}
1919

2020
@_expose(wasm,"bjs_PlayBridgeJS_update")
2121
@_cdecl("bjs_PlayBridgeJS_update")
22-
publicfunc _bjs_PlayBridgeJS_update(_self:UnsafeMutableRawPointer, swiftSourceBytes:Int32,swiftSourceLen:Int32, dtsSourceBytes:Int32,dtsSourceLen:Int32)->UnsafeMutableRawPointer{
22+
publicfunc _bjs_PlayBridgeJS_update(_self:UnsafeMutableRawPointer, swiftSourceBytes:Int32,swiftSourceLength:Int32, dtsSourceBytes:Int32,dtsSourceLength:Int32)->UnsafeMutableRawPointer{
2323
#if arch(wasm32)
2424
do{
25-
letswiftSource=String(unsafeUninitializedCapacity:Int(swiftSourceLen)){ bin
26-
_swift_js_init_memory(swiftSourceBytes, b.baseAddress.unsafelyUnwrapped)
27-
returnInt(swiftSourceLen)
28-
}
29-
letdtsSource=String(unsafeUninitializedCapacity:Int(dtsSourceLen)){ bin
30-
_swift_js_init_memory(dtsSourceBytes, b.baseAddress.unsafelyUnwrapped)
31-
returnInt(dtsSourceLen)
32-
}
33-
letret=tryUnmanaged<PlayBridgeJS>.fromOpaque(_self).takeUnretainedValue().update(swiftSource: swiftSource, dtsSource: dtsSource)
34-
returnUnmanaged.passRetained(ret).toOpaque()
25+
letret=tryPlayBridgeJS.bridgeJSLiftParameter(_self).update(swiftSource:String.bridgeJSLiftParameter(swiftSourceBytes, swiftSourceLength), dtsSource:String.bridgeJSLiftParameter(dtsSourceBytes, dtsSourceLength))
26+
return ret.bridgeJSLowerReturn()
3527
}catchlet error{
3628
iflet error= error.thrownValue.object{
3729
withExtendedLifetime(error){
@@ -56,10 +48,16 @@ public func _bjs_PlayBridgeJS_deinit(pointer: UnsafeMutableRawPointer) {
5648
Unmanaged<PlayBridgeJS>.fromOpaque(pointer).release()
5749
}
5850

59-
extensionPlayBridgeJS:ConvertibleToJSValue{
51+
extensionPlayBridgeJS:ConvertibleToJSValue,_BridgedSwiftHeapObject{
6052
varjsValue:JSValue{
53+
#if arch(wasm32)
6154
@_extern(wasm, module:"PlayBridgeJS", name:"bjs_PlayBridgeJS_wrap")
6255
func _bjs_PlayBridgeJS_wrap(_:UnsafeMutableRawPointer)->Int32
56+
#else
57+
func _bjs_PlayBridgeJS_wrap(_:UnsafeMutableRawPointer)->Int32{
58+
fatalError("Only available on WebAssembly")
59+
}
60+
#endif
6361
return.object(JSObject(id:UInt32(bitPattern:_bjs_PlayBridgeJS_wrap(Unmanaged.passRetained(self).toOpaque()))))
6462
}
6563
}
@@ -68,10 +66,8 @@ extension PlayBridgeJS: ConvertibleToJSValue {
6866
@_cdecl("bjs_PlayBridgeJSOutput_outputJs")
6967
publicfunc _bjs_PlayBridgeJSOutput_outputJs(_self:UnsafeMutableRawPointer)->Void{
7068
#if arch(wasm32)
71-
varret=Unmanaged<PlayBridgeJSOutput>.fromOpaque(_self).takeUnretainedValue().outputJs()
72-
return ret.withUTF8{ ptrin
73-
_swift_js_return_string(ptr.baseAddress,Int32(ptr.count))
74-
}
69+
letret=PlayBridgeJSOutput.bridgeJSLiftParameter(_self).outputJs()
70+
return ret.bridgeJSLowerReturn()
7571
#else
7672
fatalError("Only available on WebAssembly")
7773
#endif
@@ -81,10 +77,8 @@ public func _bjs_PlayBridgeJSOutput_outputJs(_self: UnsafeMutableRawPointer) ->
8177
@_cdecl("bjs_PlayBridgeJSOutput_outputDts")
8278
publicfunc _bjs_PlayBridgeJSOutput_outputDts(_self:UnsafeMutableRawPointer)->Void{
8379
#if arch(wasm32)
84-
varret=Unmanaged<PlayBridgeJSOutput>.fromOpaque(_self).takeUnretainedValue().outputDts()
85-
return ret.withUTF8{ ptrin
86-
_swift_js_return_string(ptr.baseAddress,Int32(ptr.count))
87-
}
80+
letret=PlayBridgeJSOutput.bridgeJSLiftParameter(_self).outputDts()
81+
return ret.bridgeJSLowerReturn()
8882
#else
8983
fatalError("Only available on WebAssembly")
9084
#endif
@@ -94,10 +88,8 @@ public func _bjs_PlayBridgeJSOutput_outputDts(_self: UnsafeMutableRawPointer) ->
9488
@_cdecl("bjs_PlayBridgeJSOutput_importSwiftGlue")
9589
publicfunc _bjs_PlayBridgeJSOutput_importSwiftGlue(_self:UnsafeMutableRawPointer)->Void{
9690
#if arch(wasm32)
97-
varret=Unmanaged<PlayBridgeJSOutput>.fromOpaque(_self).takeUnretainedValue().importSwiftGlue()
98-
return ret.withUTF8{ ptrin
99-
_swift_js_return_string(ptr.baseAddress,Int32(ptr.count))
100-
}
91+
letret=PlayBridgeJSOutput.bridgeJSLiftParameter(_self).importSwiftGlue()
92+
return ret.bridgeJSLowerReturn()
10193
#else
10294
fatalError("Only available on WebAssembly")
10395
#endif
@@ -107,10 +99,8 @@ public func _bjs_PlayBridgeJSOutput_importSwiftGlue(_self: UnsafeMutableRawPoint
10799
@_cdecl("bjs_PlayBridgeJSOutput_exportSwiftGlue")
108100
publicfunc _bjs_PlayBridgeJSOutput_exportSwiftGlue(_self:UnsafeMutableRawPointer)->Void{
109101
#if arch(wasm32)
110-
varret=Unmanaged<PlayBridgeJSOutput>.fromOpaque(_self).takeUnretainedValue().exportSwiftGlue()
111-
return ret.withUTF8{ ptrin
112-
_swift_js_return_string(ptr.baseAddress,Int32(ptr.count))
113-
}
102+
letret=PlayBridgeJSOutput.bridgeJSLiftParameter(_self).exportSwiftGlue()
103+
return ret.bridgeJSLowerReturn()
114104
#else
115105
fatalError("Only available on WebAssembly")
116106
#endif
@@ -122,10 +112,16 @@ public func _bjs_PlayBridgeJSOutput_deinit(pointer: UnsafeMutableRawPointer) {
122112
Unmanaged<PlayBridgeJSOutput>.fromOpaque(pointer).release()
123113
}
124114

125-
extensionPlayBridgeJSOutput:ConvertibleToJSValue{
115+
extensionPlayBridgeJSOutput:ConvertibleToJSValue,_BridgedSwiftHeapObject{
126116
varjsValue:JSValue{
117+
#if arch(wasm32)
127118
@_extern(wasm, module:"PlayBridgeJS", name:"bjs_PlayBridgeJSOutput_wrap")
128119
func _bjs_PlayBridgeJSOutput_wrap(_:UnsafeMutableRawPointer)->Int32
120+
#else
121+
func _bjs_PlayBridgeJSOutput_wrap(_:UnsafeMutableRawPointer)->Int32{
122+
fatalError("Only available on WebAssembly")
123+
}
124+
#endif
129125
return.object(JSObject(id:UInt32(bitPattern:_bjs_PlayBridgeJSOutput_wrap(Unmanaged.passRetained(self).toOpaque()))))
130126
}
131127
}

‎Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.ImportTS.swift‎

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,14 @@ func createTS2Skeleton() throws(JSException) -> TS2Skeleton {
1919
iflet error=_swift_js_take_exception(){
2020
throw error
2121
}
22-
returnTS2Skeleton(takingThis:ret)
22+
returnTS2Skeleton.bridgeJSLiftReturn(ret)
2323
}
2424

25-
structTS2Skeleton{
26-
letthis:JSObject
25+
structTS2Skeleton:_JSBridgedClass{
26+
letjsObject:JSObject
2727

28-
init(this:JSObject){
29-
self.this= this
30-
}
31-
32-
init(takingThis this:Int32){
33-
self.this=JSObject(id:UInt32(bitPattern: this))
28+
init(unsafelyWrapping jsObject:JSObject){
29+
self.jsObject= jsObject
3430
}
3531

3632
func convert(_ ts:String)throws(JSException)->String{
@@ -42,18 +38,11 @@ struct TS2Skeleton {
4238
fatalError("Only available on WebAssembly")
4339
}
4440
#endif
45-
varts= ts
46-
lettsId= ts.withUTF8{ bin
47-
_swift_js_make_js_string(b.baseAddress.unsafelyUnwrapped,Int32(b.count))
48-
}
49-
letret=bjs_TS2Skeleton_convert(Int32(bitPattern:self.this.id), tsId)
41+
letret=bjs_TS2Skeleton_convert(self.bridgeJSLowerParameter(), ts.bridgeJSLowerParameter())
5042
iflet error=_swift_js_take_exception(){
5143
throw error
5244
}
53-
returnString(unsafeUninitializedCapacity:Int(ret)){ bin
54-
_swift_js_init_memory_with_result(b.baseAddress.unsafelyUnwrapped,Int32(ret))
55-
returnInt(ret)
56-
}
45+
returnString.bridgeJSLiftReturn(ret)
5746
}
5847

5948
}

‎Plugins/BridgeJS/Package.swift‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,22 @@ let package = Package(
2929
name:"BridgeJSCore",
3030
dependencies:[
3131
"BridgeJSSkeleton",
32+
"BridgeJSUtilities",
3233
.product(name:"SwiftParser",package:"swift-syntax"),
3334
.product(name:"SwiftSyntax",package:"swift-syntax"),
3435
.product(name:"SwiftBasicFormat",package:"swift-syntax"),
3536
.product(name:"SwiftSyntaxBuilder",package:"swift-syntax"),
3637
]
3738
),
3839
.target(name:"BridgeJSSkeleton"),
40+
.target(name:"BridgeJSUtilities"),
3941

4042
.target(
4143
name:"BridgeJSLink",
42-
dependencies:["BridgeJSSkeleton"]
44+
dependencies:[
45+
"BridgeJSSkeleton",
46+
"BridgeJSUtilities",
47+
]
4348
),
4449

4550
.testTarget(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp