You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by ja...@gmail.com on 2010/03/04 03:12:37 UTC

Taming osapi (issue223109)

Reviewers: chirag,

Description:
* filters out caja properties from native json.stringify
* tames methods created using osapi.registerMethod_
   - the latter should be reviewed particularly carefully

Please review this at http://codereview.appspot.com/223109/show

Affected files:
   M     features/src/main/javascript/features/core.json/json.js
   M     features/src/main/javascript/features/osapi/osapi.js
   M      
java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java


Index:  
java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java
===================================================================
---  
java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java	 
(revision 918319)
+++  
java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java	 
(working copy)
@@ -238,6 +238,13 @@
    }

    @Test
+  public void testOsapiCaja() throws Exception {
+    executeAllPageTests("osapi/personTest", true /* caja */);
+    executeAllPageTests("osapi/appdataTest", true /* caja */);
+    executeAllPageTests("osapi/batchTest", true /* caja */);
+  }
+
+  @Test
    public void testTemplateRewrite() throws Exception {
      HtmlPage page = executePageTest("templateRewriter", null);

Index: features/src/main/javascript/features/core.json/json.js
===================================================================
--- features/src/main/javascript/features/core.json/json.js	(revision  
918319)
+++ features/src/main/javascript/features/core.json/json.js	(working copy)
@@ -52,7 +52,10 @@
      },
      'stringify': function(obj) {
        try {
-        return window.JSON.stringify(obj);
+        return window.JSON.stringify(obj, function(k,v) {
+          if (!/___$/.test(k))
+            return v;
+        });
        } catch (e) {
          return null;
        }
Index: features/src/main/javascript/features/osapi/osapi.js
===================================================================
--- features/src/main/javascript/features/osapi/osapi.js	(revision 918319)
+++ features/src/main/javascript/features/osapi/osapi.js	(working copy)
@@ -17,9 +17,7 @@
   */

  var osapi = osapi || {};
-var tamings___ = tamings___ || [];
  (function() {
-
    /**
     * Called by the transports for each service method that they expose
     * @param {string} method  The method to expose e.g. "people.get"
@@ -38,16 +36,20 @@
        var batch = osapi.newBatch();
        var boundCall = {};
        boundCall.execute = function(callback) {
+        var feralCallback = window.___ ? ___.untame(callback) : callback;
+        var that = window.___ ? ___.USELESS : this;
          batch.add(method, this);
          batch.execute(function(batchResult) {
            if (batchResult.error) {
-            callback(batchResult.error);
+            feralCallback.call(that, batchResult.error);
            } else {
-            callback(batchResult[method]);
+            feralCallback.call(that, batchResult[method]);
            }
          });
        }
-
+      if (window.___) {
+          ___.markInnocent(boundCall.execute, 'execute');
+      }
        // TODO: This shouldnt really be necessary. The spec should be clear  
enough about
        // defaults that we dont have to populate this.
        rpc = rpc || {};