|
6 | 6 |
|
7 | 7 | @_spi(JSObject_id) import JavaScriptKit |
8 | 8 |
|
| 9 | +#if arch(wasm32) |
9 | 10 | @_extern(wasm, module: "bjs", name: "make_jsstring") |
10 | | -private func _make_jsstring(_ ptr: UnsafePointer<UInt8>?, _ len: Int32) -> Int32 |
| 11 | +func _make_jsstring(_ ptr: UnsafePointer<UInt8>?, _ len: Int32) -> Int32 |
| 12 | +#else |
| 13 | +func _make_jsstring(_ ptr: UnsafePointer<UInt8>?, _ len: Int32) -> Int32 { |
| 14 | + fatalError("Only available on WebAssembly") |
| 15 | +} |
| 16 | +#endif |
11 | 17 |
|
| 18 | +#if arch(wasm32) |
12 | 19 | @_extern(wasm, module: "bjs", name: "init_memory_with_result") |
13 | | -private func _init_memory_with_result(_ ptr: UnsafePointer<UInt8>?, _ len: Int32) |
| 20 | +func _init_memory_with_result(_ ptr: UnsafePointer<UInt8>?, _ len: Int32) |
| 21 | +#else |
| 22 | +func _init_memory_with_result(_ ptr: UnsafePointer<UInt8>?, _ len: Int32) { |
| 23 | + fatalError("Only available on WebAssembly") |
| 24 | +} |
| 25 | +#endif |
14 | 26 |
|
15 | 27 | func benchmarkHelperNoop() -> Void { |
| 28 | + #if arch(wasm32) |
16 | 29 | @_extern(wasm, module: "Benchmarks", name: "bjs_benchmarkHelperNoop") |
17 | 30 | func bjs_benchmarkHelperNoop() -> Void |
| 31 | + #else |
| 32 | + func bjs_benchmarkHelperNoop() -> Void { |
| 33 | + fatalError("Only available on WebAssembly") |
| 34 | + } |
| 35 | + #endif |
18 | 36 | bjs_benchmarkHelperNoop() |
19 | 37 | } |
20 | 38 |
|
21 | 39 | func benchmarkHelperNoopWithNumber(_ n: Double) -> Void { |
| 40 | + #if arch(wasm32) |
22 | 41 | @_extern(wasm, module: "Benchmarks", name: "bjs_benchmarkHelperNoopWithNumber") |
23 | 42 | func bjs_benchmarkHelperNoopWithNumber(_ n: Float64) -> Void |
| 43 | + #else |
| 44 | + func bjs_benchmarkHelperNoopWithNumber(_ n: Float64) -> Void { |
| 45 | + fatalError("Only available on WebAssembly") |
| 46 | + } |
| 47 | + #endif |
24 | 48 | bjs_benchmarkHelperNoopWithNumber(n) |
25 | 49 | } |
26 | 50 |
|
27 | 51 | func benchmarkRunner(_ name: String, _ body: JSObject) -> Void { |
| 52 | + #if arch(wasm32) |
28 | 53 | @_extern(wasm, module: "Benchmarks", name: "bjs_benchmarkRunner") |
29 | 54 | func bjs_benchmarkRunner(_ name: Int32, _ body: Int32) -> Void |
| 55 | + #else |
| 56 | + func bjs_benchmarkRunner(_ name: Int32, _ body: Int32) -> Void { |
| 57 | + fatalError("Only available on WebAssembly") |
| 58 | + } |
| 59 | + #endif |
30 | 60 | var name = name |
31 | 61 | let nameId = name.withUTF8 { b in |
32 | 62 | _make_jsstring(b.baseAddress.unsafelyUnwrapped, Int32(b.count)) |
|
0 commit comments