         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)
+    }
+}

            let val: AnyObject = value ?? NSNull()
            //properties.updateValue(val, forKey: name)
            let json = JSON(val).rawString()!
            webView.evaluateJavaScript("\(self.name).\(name) = \(json); \(self.name).\(name);", completionHandler: { (obj, err) -> Void in
                if err == nil {
                    self.properties.updateValue(obj, forKey: name)
                } else {
                    println("ERROR: Failed to execute script, \(err)")
                }
            })
        }
    }

    }

    public func invokeCallback(callID: Int32, key: String?, arguments: [AnyObject]?) {
        var arg : [AnyObject] = [ NSNumber(int: callID), key ?? NSNull(), arguments ?? [] ]
        invokeJavaScript(".invokeCallback", arguments: arg)
    }

    public func invokeJavaScript(function: String, arguments: [AnyObject] = []) {
        var f: String = function
        if f[f.startIndex] == "." {
            // Invoke a method of this object
            f = name + function
        }
        if let json = JSON(arguments).rawString() {
            // Remove the top level brackets
            let a = json[Range<String.Index>(start: json.startIndex.successor(), end: json.endIndex.predecessor())]
            evaluate("\(f)(\(a));")
        } else {
            println("ERROR: Invalid argument list: \(arguments)")
        }
    }

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