Issue #957

Define console object and set log function to point to our Swift function

import JavaScriptCore

extension JSContext {
    func injectConsoleLog() {
        
        evaluateScript(
        """
            var console = {};
        """
        )

        let consoleLog: @convention(block) (Any) -> Void = {
            print($0)
        }

        objectForKeyedSubscript("console")
            .setObject(consoleLog, forKeyedSubscript: "log" as NSString)
    }
}

Then we can just call

let context = JSContext()!
context.injectConsoleLog()
context.evaluateScript(jsContent)