         println("Error: Method '\(method)' not found in extension '\(name)'")
     }
 }
+
+extension XWalkExtension {
+    // Helper functions to evaluate JavaScript
+    public func evaluate(string: String) {
+        evaluate(string, success: nil)
+    }
+    public func evaluate(string: String, error: ((NSError)->Void)?) {
+        evaluate(string, completionHandler: { (obj, err)->Void in
+            if err != nil { error?(err) }
+        })
+    }
+    public func evaluate(string: String, success: ((AnyObject!)->Void)?) {
+        evaluate(string, completionHandler: { (obj, err) -> Void in
+            err == nil ? success?(obj) : println("ERROR: Failed to execute script, \(err)")
+            return    // To make compiler happy
+        })
+    }
+    public func evaluate(string: String, success: ((AnyObject!)->Void)?, error: ((NSError!)->Void)?) {
+        evaluate(string, completionHandler: { (obj, err)->Void in
+            err == nil ? success?(obj) : error?(err)
+            return    // To make compiler happy
+        })
+    }
+    public func evaluate(string: String, completionHandler: ((AnyObject!, NSError!)->Void)?) {
+        webView.evaluateJavaScript(string, completionHandler: completionHandler)
+    }
+}

    }

    public func invokeCallback(callID: Int32, key: String?, arguments: [AnyObject]?) {
        var args = (key != nil) ? ("'" + key! + "'") : "null"
        if arguments != nil && arguments!.count > 0 {
            args += ", " + JSON(arguments!).rawString()!
        }
        var cmd = "\(name).invokeCallback(\(callID), \(args));"
        webView.evaluateJavaScript(cmd, completionHandler: { (obj, err) -> Void in
            if err != nil {
                println("ERROR: Failed to execute script, \(err)")
            }
        })
    }

    public subscript(name: String) -> AnyObject? {

            let val: AnyObject = value ?? NSNull()
            //properties.updateValue(val, forKey: name)
            let json = JSON(val).rawString()!
            let cmd = "\(self.name).\(name) = \(json); \(self.name).\(name);"
            self.evaluate(cmd, success: { (obj)->Void in
                self.properties.updateValue(obj, forKey: name)
                return
            })
        }
    }
