Revision: 5490
Author:   [email protected]
Date:     Mon Jul 15 10:32:27 2013
Log:      Less runtime work in Style accessors.
https://codereview.appspot.com/11231043

* Remove redundant computations from inside TameStyle accessors.
* Don't construct a URI rewriter function inside every call to
  sanitizeStyleProperty.
* Unify URI rewriting for domicile.cssUri and sanitizeStyleProperty.

Fixes <https://code.google.com/p/google-caja/issues/detail?id=1793>.

[email protected]

http://code.google.com/p/google-caja/source/detail?r=5490

Modified:
 /trunk/src/com/google/caja/plugin/domado.js

=======================================
--- /trunk/src/com/google/caja/plugin/domado.js Thu Jul 11 15:50:37 2013
+++ /trunk/src/com/google/caja/plugin/domado.js Mon Jul 15 10:32:27 2013
@@ -1938,6 +1938,18 @@

         return node;
       }
+
+      var uriRewriterForCss = !naiveUriPolicy ? null :
+          function uriRewriterForCss_(url, prop) {
+            return uriRewrite(
+                    naiveUriPolicy,
+                    url, html4.ueffects.SAME_DOCUMENT,
+                    html4.ltypes.SANDBOXED,
+                    {
+                      "TYPE": "CSS",
+                      "CSS_PROP": prop
+                    });
+          };

       /**
        * Sanitizes the value of a CSS property, the {@code red} in
@@ -1954,18 +1966,7 @@
         sanitizeCssProperty(
             cssPropertyName,
             schema, tokens,
-            naiveUriPolicy
-            ? function (url) {
-                return uriRewrite(
-                    naiveUriPolicy,
-                    url, html4.ueffects.SAME_DOCUMENT,
-                    html4.ltypes.SANDBOXED,
-                    {
-                      "TYPE": "CSS",
-                      "CSS_PROP": cssPropertyName
-                    });
-              }
-            : null,
+            uriRewriterForCss,
             domicile.pseudoLocation.href);
         return tokens.length !== 0;
       }
@@ -6429,16 +6430,8 @@
       // note: referenced reflectively by HtmlEmitter
       domicile.cssUri = cajaVM.constFunc(function(uri, mimeType, prop) {
         uri = String(uri);
-        if (!naiveUriPolicy) { return null; }
-        return uriRewrite(
-            naiveUriPolicy,
-            uri,
-            html4.ueffects.SAME_DOCUMENT,
-            html4.ltypes.SANDBOXED,
-            {
-              "TYPE": "CSS",
-              "CSS_PROP": prop
-            });
+        if (!uriRewriterForCss) { return null; }
+        return uriRewriterForCss(uri, prop);
       });
       // TODO(kpreid): Consider moving domicile.suffix into the
       // domicile.virtualization object. Used by caja-flash.js only.
@@ -6560,32 +6553,25 @@
             })
           }
         });
-        allCssProperties.forEachCanonical(function (stylePropertyName) {
-          // TODO(kpreid): make each of these generated accessors more
-          // specialized for this name to reduce runtime cost.
+        allCssProperties.forEachCanonical(function(stylePropertyName) {
+ // TODO(kpreid): Refactor this to be clearer about what is going on;
+          // particularly what role each "name" plays.
+          var cssPropertyName =
+              allCssProperties.getCssPropFromCanonical(stylePropertyName);
+          var canonName =
+              allCssProperties.getCanonicalPropFromCss(cssPropertyName);
+          var allowed = allowProperty(cssPropertyName);
           Object.defineProperty(TameStyle.prototype, stylePropertyName, {
             enumerable: canHaveEnumerableAccessors,
             get: TameStyleConf.amplifying(function(privates) {
-              if (!privates.feral
- || !allCssProperties.isCanonicalProp(stylePropertyName)) {
+              if (!(privates.feral && allowed)) {
                 return void 0;
               }
-              var cssPropertyName =
- allCssProperties.getCssPropFromCanonical(stylePropertyName);
-              if (!allowProperty(cssPropertyName)) { return void 0; }
-              var canonName =
- allCssProperties.getCanonicalPropFromCss(cssPropertyName);
               return privates.readByCanonicalName(canonName);
             }),
             set: TameStyleConf.amplifying(function(privates, value) {
if (!privates.editable) { throw new Error('style not editable'); }
-              stylePropertyName = String(stylePropertyName);
-              if (!allCssProperties.isCanonicalProp(stylePropertyName)) {
- throw new Error('Unknown CSS property name ' + stylePropertyName);
-              }
-              var cssPropertyName =
- allCssProperties.getCssPropFromCanonical(stylePropertyName);
-              if (!allowProperty(cssPropertyName)) { return void 0; }
+              if (!allowed) { return; }
               var tokens = lexCss(value);
               if (tokens.length === 0
                  || (tokens.length === 1 && tokens[0] === ' ')) {
@@ -6597,10 +6583,7 @@
                 }
                 value = tokens.join(' ');
               }
-              var canonName =
- allCssProperties.getCanonicalPropFromCss(cssPropertyName);
               privates.writeByCanonicalName(canonName, value);
-              return true;
             })
           });
         });

--

--- You received this message because you are subscribed to the Google Groups "Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to