Skip to content

Commit dbf7a88

Browse files
Prefer UInt(bitPattern:) for object id to guarantee uniqueness (#219)
Prefer UInt(bitPattern:) for object id to guarantee uniqueness Close #218
1 parent 99c9965 commit dbf7a88

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Sources/JavaScriptKit/FundamentalObjects/JSClosure.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class JSOneshotClosure: JSObject, JSClosureProtocol {
2020
super.init(id: 0)
2121

2222
// 2. Create a new JavaScript function which calls the given Swift function.
23-
hostFuncRef = JavaScriptHostFuncRef(bitPattern: Int32(ObjectIdentifier(self).hashValue))
23+
hostFuncRef = JavaScriptHostFuncRef(bitPattern: ObjectIdentifier(self))
2424
id = withExtendedLifetime(JSString(file)) { file in
2525
_create_function(hostFuncRef, line, file.asInternalJSRef())
2626
}
@@ -86,7 +86,7 @@ public class JSClosure: JSObject, JSClosureProtocol {
8686
super.init(id: 0)
8787

8888
// 2. Create a new JavaScript function which calls the given Swift function.
89-
hostFuncRef = JavaScriptHostFuncRef(bitPattern: Int32(ObjectIdentifier(self).hashValue))
89+
hostFuncRef = JavaScriptHostFuncRef(bitPattern: ObjectIdentifier(self))
9090
id = withExtendedLifetime(JSString(file)) { file in
9191
_create_function(hostFuncRef, line, file.asInternalJSRef())
9292
}

Sources/_CJavaScriptKit/include/_CJavaScriptKit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
typedef unsigned int JavaScriptObjectRef;
1111
/// `JavaScriptHostFuncRef` represents Swift closure that is referenced by JavaScript side.
1212
/// This value is produced by `JSClosure`.
13-
typedef unsigned int JavaScriptHostFuncRef;
13+
typedef uintptr_t JavaScriptHostFuncRef;
1414

1515
/// `JavaScriptValueKind` represents the kind of JavaScript primitive value.
1616
typedef enum __attribute__((enum_extensibility(closed))) {

0 commit comments

Comments
 (0)