Sam
03/04/2019, 4:15 AM.def
file for JavaScriptCore
is disabled. Does this not work at all? Or was it disabled a long time ago and nobody had checked it out since?Sam
03/04/2019, 5:53 AMJSExports
and extending it in Swift.
@objc protocol SecretTellerExports: JSExport {
var platform: String { get }
func tell() -> String
static func create() -> SecretTeller
}
extension SecretTeller: SecretTellerExports {
static func create() -> SecretTeller {
return SecretTeller.Companion().createAndFreeze()
}
}
Everything looked like it worked until the JS garbage collector tried to access the SecretTeller
object I had instantiated in a script. Freezing the object appears to work.
In my simple test this is ok. I'm just not sure how restricting these limitations will be for more complicated projects.olonho
03/04/2019, 9:42 AMSam
03/04/2019, 12:05 PMnapperley
03/04/2019, 8:26 PMSam
03/04/2019, 8:28 PMsvyatoslav.scherbina
03/05/2019, 6:50 AMEverything looked like it worked until the JS garbage collector tried to access theCould you share the backtrace?object I had instantiated in a script.SecretTeller
Sam
03/05/2019, 12:19 PMSam
03/05/2019, 3:10 PMf7dfb5cc83a1223f4618a5c7a04252b537b24db0
is where I changed it to call freeze
on the Kotlin/Native object that is passed into the JavaScript engine.Sam
03/05/2019, 3:10 PMUncaught Kotlin exception: kotlin.native.IncorrectDereferenceException: illegal attempt to access non-shared com.synappticlabs.knjstest.SecretTeller@3b823e8 from other thread
at 0 app 0x00000001061efa76 kfun:kotlin.Exception.<init>(kotlin.String?)kotlin.Exception + 70 (/opt/teamcity-agent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/Exceptions.kt:23:5)
at 1 app 0x00000001061ef996 kfun:kotlin.RuntimeException.<init>(kotlin.String?)kotlin.RuntimeException + 70 (/opt/teamcity-agent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/Exceptions.kt:34:5)
at 2 app 0x0000000106224606 kfun:kotlin.native.IncorrectDereferenceException.<init>(kotlin.String)kotlin.native.IncorrectDereferenceException + 70 (/opt/teamcity-agent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/native/Runtime.kt:28:5)
at 3 app 0x0000000106224c71 ThrowIllegalObjectSharingException + 289 (/opt/teamcity-agent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:84:11)
at 4 app 0x000000010622e479 _ZNK16KRefSharedHolder14verifyRefOwnerEv + 105
svyatoslav.scherbina
03/06/2019, 9:00 AMJSExport
requires freezing them. Note that you can still have mutable state in these objects by wrapping it in StableRef
and ensuring that it is accessed from proper thread.svyatoslav.scherbina
03/07/2019, 6:48 AMStableRef
must be disposed manually using .dispose()
on it.