Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-7991 WKWebView integration
  3. CB-8207

[WKWebView][iOS 8] Unnecessary JSON conversion and possible leak

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.5.0
    • 4.0.0
    • cordova-ios, cordova-js
    • None

    Description

      The WKWebView bridge is calling JSON.stringify and adding the result to the command queue which appears to be unnecessary.

      The JSON conversion negates part of the performance gain of letting WKScriptMessage marshal the array.

      Additionally, since commands with WKWebView are processed immediately, it's unclear what will happen to the queued commands. Something will either process them resulting in duplicate command execution, or the queue will continue to grow and allocate memory.

      See ios/exec.js:

          // FIXME: This call may be unnecessary depending on how 
          // WKScriptMesssage marshals ArrayBuffer
          actionArgs = massageArgsJsToNative(actionArgs);
      
          var command = [callbackId, service, action, actionArgs];
      
          // FIXME: This is unnecessary with WKWebView binding
          // and should move into the else below
          commandQueue.push(JSON.stringify(command));
          
          if (bridgeMode === jsToNativeModes.WK_WEBVIEW_BINDING) {
              window.webkit.messageHandlers.cordova.postMessage(command);
          } else {
              if (!isInContextOfEvalJs && commandQueue.length == 1) {
                  pokeNative();
              }
          }
      

      Attachments

        Activity

          People

            shazron Shazron Abdullah
            aaron.oneal Incarnadine
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: