0 Replies
      Latest reply on Feb 13, 2020 5:43 AM by jessegrosjean
      jessegrosjean Level 1 Level 1 (0 points)

        I'm using JavascriptCore in a Swift app. For years I've had this logic:

         

        public func doit(_ options: [String : Any]?) {
            jsValueOutline.invokeMethod("doit", withArguments: [options ?? [:]])
        }
        

         

        In particular the logic to turn nil options into a dictionary like this `options ?? [:]`.

         

        Now this has started crashing for me. Seems maybe related to 10.15.4 ... though not entirely sure about that. Also is very odd in that I couldn't reproduce the problem for a few days... and now I can't not reproduce the problem. The crash stack looks like this:

         

        Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
        0   libobjc.A.dylib               0x00007fff6eb583c9 class_conformsToProtocol + 170
        1   com.apple.JavaScriptCore       0x00007fff3858d6bd objectToValueWithoutCopy(JSContext*, objc_object*) + 77
        2   com.apple.JavaScriptCore       0x00007fff3858cf3a objectToValue(JSContext*, objc_object*) + 74
        3   com.apple.JavaScriptCore       0x00007fff3858ed17 -[JSValue invokeMethod:withArguments:] + 151

         

        Good news is I can work around the problem by chaning my above code to:

         

        publicfunc doit(_ options: [String : Any]?) {
            jsValueOutline.invokeMethod("doit", withArguments: [options as Any])
        }

         

        Note the change is to replace `options ?? [:]` with `options as Any`.

         

        My question... what happened. Was I don't something wrong initially and it just happened to work? What changed to cause it stop working. Is my "fix" correct?

         

        Thanks,
        Jesse