Skip to content

Commit e36e93c

Browse files
Merge pull request #306 from swiftwasm/yt/inline-id
Make `JSObject.id` getter inlinable
2 parents a37dfa9 + b787af2 commit e36e93c

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Sources/JavaScriptKit/FundamentalObjects/JSClosure.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class JSOneshotClosure: JSObject, JSClosureProtocol {
2121

2222
// 2. Create a new JavaScript function which calls the given Swift function.
2323
hostFuncRef = JavaScriptHostFuncRef(bitPattern: ObjectIdentifier(self))
24-
id = withExtendedLifetime(JSString(file)) { file in
24+
_id = withExtendedLifetime(JSString(file)) { file in
2525
swjs_create_function(hostFuncRef, line, file.asInternalJSRef())
2626
}
2727

@@ -105,7 +105,7 @@ public class JSClosure: JSFunction, JSClosureProtocol {
105105

106106
// 2. Create a new JavaScript function which calls the given Swift function.
107107
hostFuncRef = JavaScriptHostFuncRef(bitPattern: ObjectIdentifier(self))
108-
id = withExtendedLifetime(JSString(file)) { file in
108+
_id = withExtendedLifetime(JSString(file)) { file in
109109
swjs_create_function(hostFuncRef, line, file.asInternalJSRef())
110110
}
111111

Sources/JavaScriptKit/FundamentalObjects/JSObject.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,20 @@ public class JSObject: Equatable {
1919
internal static var constructor: JSFunction { _constructor.wrappedValue }
2020
private static let _constructor = LazyThreadLocal(initialize: { JSObject.global.Object.function! })
2121

22-
@_spi(JSObject_id)
23-
public var id: JavaScriptObjectRef
22+
@usableFromInline
23+
internal var _id: JavaScriptObjectRef
2424

2525
#if compiler(>=6.1) && _runtime(_multithreaded)
2626
package let ownerTid: Int32
2727
#endif
2828

29+
@_spi(JSObject_id)
30+
@inlinable
31+
public var id: JavaScriptObjectRef { _id }
32+
2933
@_spi(JSObject_id)
3034
public init(id: JavaScriptObjectRef) {
31-
self.id = id
35+
self._id = id
3236
#if compiler(>=6.1) && _runtime(_multithreaded)
3337
self.ownerTid = swjs_get_worker_thread_id_cached()
3438
#endif

0 commit comments

Comments
 (0)