Skip to content
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

Make JSObject.id getter inlinable #306

Merged
merged 1 commit into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/JavaScriptKit/FundamentalObjects/JSClosure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class JSOneshotClosure: JSObject, JSClosureProtocol {

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

Expand Down Expand Up @@ -105,7 +105,7 @@ public class JSClosure: JSFunction, JSClosureProtocol {

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

Expand Down
10 changes: 7 additions & 3 deletions Sources/JavaScriptKit/FundamentalObjects/JSObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ public class JSObject: Equatable {
internal static var constructor: JSFunction { _constructor.wrappedValue }
private static let _constructor = LazyThreadLocal(initialize: { JSObject.global.Object.function! })

@_spi(JSObject_id)
public var id: JavaScriptObjectRef
@usableFromInline
internal var _id: JavaScriptObjectRef

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

@_spi(JSObject_id)
@inlinable
public var id: JavaScriptObjectRef { _id }

@_spi(JSObject_id)
public init(id: JavaScriptObjectRef) {
self.id = id
self._id = id
#if compiler(>=6.1) && _runtime(_multithreaded)
self.ownerTid = swjs_get_worker_thread_id_cached()
#endif
Expand Down