Reviewers: jasvir,

Description:
THe replacement, plugin/capture-valija.js, also restores the original
new module handler.

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

Affected files:
  M     build.xml
  A     src/com/google/caja/plugin/capture-valija.js


Index: src/com/google/caja/plugin/capture-valija.js
===================================================================
--- src/com/google/caja/plugin/capture-valija.js        (revision 0)
+++ src/com/google/caja/plugin/capture-valija.js        (revision 0)
@@ -0,0 +1,37 @@
+/**
+ * @fileoverview
+ * Given that the next script executed is the cajoled Valija module, make
+ * valijaMaker available in the global scope.
+ *
+ * @author [email protected]
+ * @author [email protected]
+ * @requires ___
+ * @provides valijaMaker
+ */
+
+var valijaMaker = undefined;
+(function(){
+  // Save and restore
+  var originalNewModuleHandler = ___.getNewModuleHandler();
+
+  // Set up a fresh handler
+  var ourHandler = ___.makeNormalNewModuleHandler();
+
+  // ... which captures Valija
+  var imports = ourHandler.getImports();
+  imports.loader = {
+    provide: ___.markFuncFreeze(function (v) {
+      valijaMaker = v;
+    })
+  };
+  imports.outers = imports;
+
+  // ... and removes itself.
+  var normalHandle = ourHandler.handle;
+  ourHandler.handle = ___.markFuncFreeze(function (module) {
+    ___.setNewModuleHandler(originalNewModuleHandler);
+    normalHandle.call(ourHandler, module);
+  });
+
+  ___.setNewModuleHandler(ourHandler);
+})();
Index: build.xml
===================================================================
--- build.xml   (revision 4218)
+++ build.xml   (working copy)
@@ -657,7 +657,7 @@
       <input file="${src}/com/google/caja/plugin/html-emitter.js"/>
       <input file="${src}/com/google/caja/plugin/bridal.js"/>
       <input file="${src}/com/google/caja/plugin/domita.js"/>
- <input file="${src}/com/google/caja/demos/playground/setup-valija.js"/>
+      <input file="${src}/com/google/caja/plugin/capture-valija.js"/>
       <input file="${lib}/com/google/caja/plugin/valija.out.js"/>
       <input file="${src}/com/google/caja/plugin/uri.js"/>
       <input file="${src}/com/google/caja/cajita-module.js"/>
@@ -678,7 +678,7 @@
        <input file="${src}/com/google/caja/plugin/html-emitter.js"/>
        <input file="${src}/com/google/caja/plugin/bridal.js"/>
        <input file="${src}/com/google/caja/plugin/domita.js"/>
- <input file="${src}/com/google/caja/demos/playground/setup-valija.js"/>
+       <input file="${src}/com/google/caja/plugin/capture-valija.js"/>
        <input file="${lib}/com/google/caja/plugin/valija.out.js"/>
        <input file="${src}/com/google/caja/plugin/uri.js"/>
        <input file="${src}/com/google/caja/cajita-module.js"/>


Reply via email to