[google-caja] r3846 committed - Remove Cajita/Valija flag as an input to all cajoling services...

0 views
Skip to first unread message

googl...@googlecode.com

unread,
Nov 13, 2009, 4:38:43 PM11/13/09
to caja....@gmail.com
Revision: 3846
Author: ihab.awad
Date: Fri Nov 13 13:37:15 2009
Log: Remove Cajita/Valija flag as an input to all cajoling services
http://codereview.appspot.com/136053

Remove Cajita/Valija flag as an input to all cajoling services. Rely
only on the source itself to tell us whether it is Valija (the
default) or Cajita (via a "use cajita" pragma). Cajole all files to a
consistent output filename (*.out.js).

These changes allow the (Cajita-level) module loader to predictably
load a module regardless of whether it is Valija or Cajita. Because we
build our Valija module loader on top of Cajita, the Cajita loader did
not have the information of whether a module to be loaded is Cajita or
Valija; as far as it was concerned, everything is Cajita. Which is as
it should be -- Valija is just Cajita with a funky calling convention.

R=meta...@gmail.com

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

Added:
/trunk/src/com/google/caja/parser/js/Directive.java
/trunk/src/com/google/caja/parser/js/DirectivePrologue.java

/trunk/src/com/google/caja/parser/quasiliteral/DirectivePrologueQuasiNode.java
/trunk/tests/com/google/caja/demos/benchmarks/BenchmarkUtils.java
/trunk/tests/com/google/caja/parser/quasiliteral/testModule.out.js
Deleted:
/trunk/src/com/google/caja/parser/js/UseSubset.java
/trunk/src/com/google/caja/parser/js/UseSubsetDirective.java
/trunk/src/com/google/caja/parser/quasiliteral/UseSubsetQuasiNode.java
/trunk/tests/com/google/caja/demos/applet/caja-applet-cajita-golden.js
/trunk/tests/com/google/caja/parser/quasiliteral/testModule.co.js
Modified:
/trunk/build.xml
/trunk/src/com/google/caja/ancillary/linter/VariableLiveness.java
/trunk/src/com/google/caja/cajita-module.js
/trunk/src/com/google/caja/cajita.js
/trunk/src/com/google/caja/commonjs-sandbox.js
/trunk/src/com/google/caja/demos/applet/CajaApplet.java
/trunk/src/com/google/caja/demos/applet/testbed.js
/trunk/src/com/google/caja/demos/calendar/demo-cajoled.html
/trunk/src/com/google/caja/demos/lolcat-search/katTranzlator.js
/trunk/src/com/google/caja/demos/lolcat-search/kittens.js
/trunk/src/com/google/caja/demos/lolcat-search/search.html
/trunk/src/com/google/caja/demos/lolcat-search/searchbox.js
/trunk/src/com/google/caja/demos/lolcat-search/slides.html
/trunk/src/com/google/caja/demos/slides/index.html
/trunk/src/com/google/caja/opensocial/DefaultGadgetRewriter.java
/trunk/src/com/google/caja/opensocial/GadgetRewriterMain.java
/trunk/src/com/google/caja/parser/js/Parser.java
/trunk/src/com/google/caja/parser/quasiliteral/CajitaRewriter.java
/trunk/src/com/google/caja/parser/quasiliteral/DefaultValijaRewriter.java
/trunk/src/com/google/caja/parser/quasiliteral/QuasiBuilder.java
/trunk/src/com/google/caja/plugin/BuildServiceImplementation.java
/trunk/src/com/google/caja/plugin/ExpressionSanitizerCaja.java
/trunk/src/com/google/caja/plugin/PluginCompilerMain.java
/trunk/src/com/google/caja/plugin/PluginMeta.java
/trunk/src/com/google/caja/plugin/bridal.js
/trunk/src/com/google/caja/plugin/stages/ValidateJavascriptStage.java
/trunk/src/com/google/caja/reporting/MessageType.java
/trunk/src/com/google/caja/service/CajolingService.java
/trunk/src/com/google/caja/service/HtmlHandler.java
/trunk/src/com/google/caja/service/JsHandler.java
/trunk/src/com/google/caja/tools/TransformAntTask.java
/trunk/src/com/google/caja/valija-cajita.js
/trunk/tests/com/google/caja/a.js
/trunk/tests/com/google/caja/c.js
/trunk/tests/com/google/caja/commonJsRecursion.js
/trunk/tests/com/google/caja/demos/applet/CajaAppletTest.java
/trunk/tests/com/google/caja/demos/benchmarks/BenchmarkRunner.java
/trunk/tests/com/google/caja/demos/benchmarks/BenchmarkSize.java
/trunk/tests/com/google/caja/foo/b.js
/trunk/tests/com/google/caja/foo/f.js
/trunk/tests/com/google/caja/foo/inc.js
/trunk/tests/com/google/caja/opensocial/DefaultGadgetRewriterTest.java
/trunk/tests/com/google/caja/opensocial/example-rewritten.xml
/trunk/tests/com/google/caja/parser/js/ParserTest.java
/trunk/tests/com/google/caja/parser/js/parsergolden10.txt
/trunk/tests/com/google/caja/parser/js/parsertest10.js
/trunk/tests/com/google/caja/parser/js/parsertest6.js
/trunk/tests/com/google/caja/parser/js/rendergolden6.txt
/trunk/tests/com/google/caja/parser/quasiliteral/MatchTest.java
/trunk/tests/com/google/caja/parser/quasiliteral/ModuleFormatTest.java
/trunk/tests/com/google/caja/parser/quasiliteral/c.js
/trunk/tests/com/google/caja/parser/quasiliteral/foo/b.js
/trunk/tests/com/google/caja/parser/quasiliteral/foo/testPrimordials.js
/trunk/tests/com/google/caja/parser/quasiliteral/taming_test.html
/trunk/tests/com/google/caja/parser/quasiliteral/valija_module_loading.html
/trunk/tests/com/google/caja/plugin/DomitaTest.java
/trunk/tests/com/google/caja/plugin/ExpressionSanitizerTest.java
/trunk/tests/com/google/caja/plugin/HtmlCompiledPluginTest.java
/trunk/tests/com/google/caja/plugin/domita_test.html
/trunk/tests/com/google/caja/plugin/domita_test_untrusted.html
/trunk/tests/com/google/caja/plugin/jsunit.js
/trunk/tests/com/google/caja/plugin/stages/DebuggingSymbolsStageTest.java
/trunk/tests/com/google/caja/recursion.js
/trunk/tests/com/google/caja/service/GadgetHandlerTest.java
/trunk/tests/com/google/caja/service/JsHandlerTest.java
/trunk/tests/com/google/caja/util/RhinoTestBed.java
/trunk/yuitest/yahoo_dom_host.html

=======================================
--- /dev/null
+++ /trunk/src/com/google/caja/parser/js/Directive.java Fri Nov 13 13:37:15
2009
@@ -0,0 +1,115 @@
+// Copyright (C) 2008 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.caja.parser.js;
+
+import com.google.caja.lexer.FilePosition;
+import com.google.caja.lexer.TokenConsumer;
+import com.google.caja.lexer.escaping.Escaping;
+import com.google.caja.parser.AbstractParseTreeNode;
+import com.google.caja.render.Concatenator;
+import com.google.caja.render.JsPrettyPrinter;
+import com.google.caja.reporting.RenderContext;
+import com.google.caja.util.Callback;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * An element of a {@code DirectivePrologue}.
+ *
+ * @author mikes...@gmail.com
+ * @see DirectivePrologue
+ */
+public final class Directive extends AbstractParseTreeNode {
+
+ /**
+ * The directive strings recognized by Caja.
+ */
+ public enum RecognizedValue {
+
+ /**
+ * Directive invoking ES5 "strict" mode.
+ */
+ USE_STRICT("use strict"),
+
+ /**
+ * String value of a directive invoking Cajita mode.
+ */
+ USE_CAJITA("use cajita");
+
+ private final String directiveString;
+
+ RecognizedValue(String directiveString) {
+ this.directiveString = directiveString;
+ }
+
+ /**
+ * @return the representation of this directive in source code.
+ */
+ public String getDirectiveString() { return directiveString; }
+
+ public static boolean isDirectiveStringRecognized(String
directiveString) {
+ for (RecognizedValue v : values()) {
+ if (v.directiveString.equals(directiveString)) { return true; }
+ }
+ return false;
+ }
+ }
+
+ private final String directiveString;
+
+ /** @param children unused. This ctor is provided for reflection. */
+ @ReflectiveCtor
+ public Directive(
+ FilePosition pos, String directiveString, List<NoChildren> children)
{
+ this(pos, directiveString);
+ }
+
+ public Directive(FilePosition pos, String directiveString) {
+ super(pos);
+ if (directiveString == null) { throw new NullPointerException(); }
+ this.directiveString = directiveString;
+ }
+
+ @Override
+ protected void childrenChanged() {
+ super.childrenChanged();
+ if (!children().isEmpty()) { throw new IndexOutOfBoundsException(); }
+ }
+
+ @Override
+ public String getValue() { return directiveString; }
+
+ public String getDirectiveString() { return directiveString; }
+
+ public void render(RenderContext rc) {
+ StringBuilder escaped = new StringBuilder();
+ escaped.append('\''); // Not allowed in JSON so always use single
quotes.
+ Escaping.escapeJsString(directiveString, true, true, escaped);
+ escaped.append('\'');
+ if (!escaped.toString().contains(directiveString)) {
+ // Escaping has modified the directive. Render nothing.
+ // See http://code.google.com/p/google-caja/issues/detail?id=1111
+ return;
+ }
+ rc.getOut().consume(escaped.toString());
+ rc.getOut().consume(";");
+ }
+
+ public final TokenConsumer makeRenderer(
+ Appendable out, Callback<IOException> exHandler) {
+ return new JsPrettyPrinter(new Concatenator(out, exHandler));
+ }
+}
=======================================
--- /dev/null
+++ /trunk/src/com/google/caja/parser/js/DirectivePrologue.java Fri Nov 13
13:37:15 2009
@@ -0,0 +1,109 @@
+// Copyright (C) 2008 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.caja.parser.js;
+
+import com.google.caja.lexer.FilePosition;
+import com.google.caja.parser.ParseTreeNode;
+import com.google.caja.reporting.RenderContext;
+
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * A node which can appear at the beginning of a program or function body
to
+ * place restrictions on code that follows.
+ *
+ * <p>The {@code DirectivePrologue} of a JavaScript {@code Program} or
+ * {@code FunctionBody} is a sequence of zero or more
+ * {@code ExpressionStatement}s each of which consists entirely of a
+ * {@code StringLiteral}. For example:
+ *
+ * <pre>
+ * 'use strict'; 'use cajita';
+ * <em>Remainder of the program...</em>
+ * </pre>
+ *
+ * <p>or:
+ *
+ * <pre>
+ * function foo() {
+ * 'use strict'; 'use cajita';
+ * <em>Remainder of the function body...</em>
+ * }
+ * </pre>
+ *
+ * <p>For more details, see Section 14.1 of
+ * <a
href="http://wiki.ecmascript.org/lib/exe/fetch.php?id=es3.1%3Aes3.1_proposal_working_draft&cache=cache&media=es3.1:es5-tc392008-040.pdf">the
ES5 spec</a>.
+ *
+ * @author mikes...@gmail.com
+ */
+public final class DirectivePrologue extends AbstractStatement {
+ /** @param value unused. This ctor is provided for reflection. */
+ @ReflectiveCtor
+ public DirectivePrologue(
+ FilePosition pos, Void value, List<? extends Directive> children) {
+ this(pos, children);
+ }
+
+ public DirectivePrologue(
+ FilePosition pos, List<? extends Directive> children) {
+ super(pos, Directive.class);
+ createMutation().appendChildren(children).execute();
+ }
+
+ @Override
+ protected void childrenChanged() {
+ super.childrenChanged();
+ if (children().isEmpty()) { throw new IndexOutOfBoundsException(); }
+ for (ParseTreeNode us : children()) {
+ if (!(us instanceof Directive)) {
+ throw new ClassCastException(us.getClass().getName());
+ }
+ }
+ }
+
+ @Override
+ public Object getValue() { return null; }
+
+ @Override
+ public List<? extends Directive> children() {
+ return childrenAs(Directive.class);
+ }
+
+ public boolean hasDirective(String directive) {
+ return getDirectives().contains(directive);
+ }
+
+ public Set<String> getDirectives() {
+ Set<String> directives = new LinkedHashSet<String>();
+ for (Directive us : children()) {
+ directives.add(us.getDirectiveString());
+ }
+ return Collections.unmodifiableSet(directives);
+ }
+
+ public void render(RenderContext rc) {
+ for (Directive d : children()) { d.render(rc); }
+ }
+
+ @Override
+ public boolean isTerminal() {
+ return true;
+ }
+
+ public boolean hasHangingConditional() { return false; }
+}
=======================================
--- /dev/null
+++
/trunk/src/com/google/caja/parser/quasiliteral/DirectivePrologueQuasiNode.java
Fri Nov 13 13:37:15 2009
@@ -0,0 +1,69 @@
+// Copyright (C) 2008 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.caja.parser.quasiliteral;
+
+import com.google.caja.lexer.FilePosition;
+import com.google.caja.parser.ParseTreeNode;
+import com.google.caja.parser.js.Directive;
+import com.google.caja.parser.js.DirectivePrologue;
+
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A quasi mode that matches a use subset node that matches a
+ * {@link com.google.caja.parser.js.DirectivePrologue}
+ * that contains all the subset names as the quasi node.
+ *
+ * <p>
+ * So the quasiliteral {@code 'use strict';} will match {@code 'use
strict';},
+ * and {@code 'use strict'; 'use cajita';}, but not {@code 'use shiny';} or
+ * {@code 'alien directive from outer space';}.
+ *
+ * @author mikes...@gmail.com
+ */
+final class DirectivePrologueQuasiNode extends QuasiNode {
+ private final Set<String> directives;
+
+ public DirectivePrologueQuasiNode(Set<String> directives) {
+ this.directives = new LinkedHashSet<String>(directives);
+ }
+
+ @Override
+ protected boolean consumeSpecimens(
+ List<ParseTreeNode> specimens, Map<String, ParseTreeNode> bindings) {
+ if (specimens.isEmpty()) { return false; }
+ ParseTreeNode specimen = specimens.get(0);
+ if (!(specimen instanceof DirectivePrologue)) { return false; }
+ DirectivePrologue usd = ((DirectivePrologue) specimen);
+ if (!usd.getDirectives().containsAll(directives)) { return false; }
+ specimens.remove(0);
+ return true;
+ }
+
+ @Override
+ protected boolean createSubstitutes(
+ List<ParseTreeNode> substitutes, Map<String, ParseTreeNode>
bindings) {
+ List<Directive> subsets = new ArrayList<Directive>();
+ for (String subsetName : directives) {
+ subsets.add(new Directive(FilePosition.UNKNOWN, subsetName));
+ }
+ substitutes.add(new DirectivePrologue(FilePosition.UNKNOWN, subsets));
+ return true;
+ }
+}
=======================================
--- /dev/null
+++ /trunk/tests/com/google/caja/demos/benchmarks/BenchmarkUtils.java Fri
Nov 13 13:37:15 2009
@@ -0,0 +1,44 @@
+// Copyright (C) 2009 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.caja.demos.benchmarks;
+
+import com.google.caja.parser.js.Block;
+import com.google.caja.parser.quasiliteral.QuasiBuilder;
+import com.google.caja.parser.ParseTreeNodeContainer;
+
+/**
+ * @author ihab...@gmail.com
+ */
+public class BenchmarkUtils {
+
+ /**
+ * Add {@code 'use strict'; 'use cajita';} directive prologue
+ * to the top of a Block.
+ *
+ * @param js a {@code Block} of JavaScript.
+ * @return a new {@code Block} with directives at the beginning.
+ */
+ public static Block addUseCajitaDirective(Block js) {
+ return (Block) QuasiBuilder.substV(
+ " {"
+ + " 'use strict';"
+ + " 'use cajita';"
+ + " @statements*;"
+ + "}",
+ "statements", new ParseTreeNodeContainer(js.children()));
+ }
+
+
+}
=======================================
--- /dev/null
+++ /trunk/tests/com/google/caja/parser/quasiliteral/testModule.out.js Fri
Nov 13 13:37:15 2009
@@ -0,0 +1,34 @@
+{ ___.loadModule({
+'instantiate':
+ function ( ___, IMPORTS___) {
+ var moduleResult___ =
+ ___. NO_RESULT;
+ moduleResult___ = 1 +
+ 1;
+ return moduleResult___;
+}
+,
+'includedModules': [ ],
+'cajolerName': 'com.google.caja',
+'cajolerVersion': 'testBuildVersion',
+'cajoledDate': 0,
+'sourceLocationMap': {
+ 'type': 'content',
+ 'content': [
+ '/** Begin line maps. **/{ file: \'file:///CAJOLED-OUTPUT\', count: 7
}',
+ '[0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,]', '[0,,,,,,,,,,,,,,,,,,,,,]',
+ '[0,,,,,,,,,,,,,,,,,,]', '[0,,,,,,,,,,,,,,,,,,1,,,]', '[2,,3]',
+ '[0,,,,,,,,,,,,,,,,,,,,,,,]', '[0]', '/** Begin file information. **/',
+ '[(void 0)]', '[(void 0)]', '[(void 0)]', '[\'testModule.js\',(void
0)]',
+ '[\'testModule.js\']', '[(void 0)]', '[(void 0)]',
+ '/** Begin mapping definitions. **/', '[(void 0),0,0]',
+ '[\'testModule.js\',1,1]', '[\'testModule.js\',1,5]',
+ '[\'testModule.js\',1,6]' ]
+},
+'originalSource': {
+ 'testModule.js': {
+ 'type': 'content',
+ 'content': [ '1 + 1;' ]
+ }
+}
+}); }
=======================================
--- /trunk/src/com/google/caja/parser/js/UseSubset.java Wed Jul 15 11:24:34
2009
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright (C) 2008 Google Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.caja.parser.js;
-
-import com.google.caja.lexer.FilePosition;
-import com.google.caja.lexer.TokenConsumer;
-import com.google.caja.lexer.escaping.Escaping;
-import com.google.caja.parser.AbstractParseTreeNode;
-import com.google.caja.render.Concatenator;
-import com.google.caja.render.JsPrettyPrinter;
-import com.google.caja.reporting.RenderContext;
-import com.google.caja.util.Callback;
-
-import java.io.IOException;
-import java.util.List;
-
-/**
- * Identifies a fail-stop subset of ECMAScript, e.g. "strict" mode.
- *
- * @author mikes...@gmail.com
- * @see UseSubsetDirective
- */
-public final class UseSubset extends AbstractParseTreeNode {
- private final String subsetName;
-
- /** @param children unused. This ctor is provided for reflection. */
- @ReflectiveCtor
- public UseSubset(
- FilePosition pos, String subsetName, List<NoChildren> children) {
- this(pos, subsetName);
- }
-
- public UseSubset(FilePosition pos, String subsetName) {
- super(pos);
- if (subsetName == null) { throw new NullPointerException(); }
- this.subsetName = subsetName;
- }
-
- @Override
- protected void childrenChanged() {
- super.childrenChanged();
- if (!children().isEmpty()) { throw new IndexOutOfBoundsException(); }
- }
-
- @Override
- public String getValue() { return subsetName; }
-
- public String getSubsetName() { return subsetName; }
-
- public void render(RenderContext rc) {
- StringBuilder escaped = new StringBuilder();
- escaped.append('\''); // Not allowed in JSON so always use single
quotes.
- Escaping.escapeJsString(subsetName, true, true, escaped);
- escaped.append('\'');
- rc.getOut().consume(escaped.toString());
- }
-
- public final TokenConsumer makeRenderer(
- Appendable out, Callback<IOException> exHandler) {
- return new JsPrettyPrinter(new Concatenator(out, exHandler));
- }
-}
=======================================
--- /trunk/src/com/google/caja/parser/js/UseSubsetDirective.java Thu Nov 12
13:05:03 2009
+++ /dev/null
@@ -1,147 +0,0 @@
-// Copyright (C) 2008 Google Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.caja.parser.js;
-
-import com.google.caja.lexer.FilePosition;
-import com.google.caja.lexer.escaping.Escaping;
-import com.google.caja.parser.ParseTreeNode;
-import com.google.caja.reporting.RenderContext;
-
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * A node which can appear at the beginning of a program or function body
to
- * place restrictions on code that follows.
- *
- * <p>
- * "Use subsets" are they were defined in ES5.
- * Since then the grammar was changed to use a separate string literal per
- * use-directive. The use-directives do not necessarily define subsets. But
- * they typically should define at least almost subsets in practice so
- * the code within their scope will still work on browsers that do not
- * recognize the "subset" to be used. For example, ES5/strict is not a
subset
- * of ES5/non-strict. See issue 1111.
- *
- * <p>An <a
href="http://wiki.ecmascript.org/lib/exe/fetch.php?id=es3.1%3Aes3.1_proposal_working_draft&amp;cache=cache&amp;media=es3.1:tc39-es31-draft27oct08.pdf"
- * >ES5 draft</a> defined the use grammar as:<blockquote><pre>
- * UseSubsetDirective opt :
- * " use SubsetList(opt) " ;
- * SubsetList :
- * Subset
- * SubsetList, Subset
- * Subset : one of
- * strict
- * </pre></blockquote>
- * and later
- * <blockquote>
- * The production UseSubsetDirectiveopt : " use SubsetList " ; is evaluated
- * as follows:<ol>
- * <li>Evaluate SubsetList
- * <li>Return Result(1)
- * </ol>
- *
- * <p>
- * The production SubsetList : Subset is evaluated as follows:<ol>
- * <li>If Subset is not the name of a usage subset that is supported by
this
- * ECMAScript implementation, return an empty internal list.
- * <li>Return an internal list containing one element which is the
Subset.
- * </ol>
- *
- * The production SubsetList : SubsetList , Subset is evaluated as follows:
- * <ol>
- * <li>Evaluate SubsetList.
- * <li>If Subset is not the name of a usage subset that is supported by
this
- * ECMAScript implementation, return Result(1)
- * <li>If Subset is already an element of Result(1), return Result(1)
- * <li>Return an internal list whose length is one greater than the
length
- * of Result(1) and whose items are the items of Result(1), in order,
- * followed at the end by Subset, which is the last item of the new
list.
- * </ol>
- * </blockquote>
- *
- * <p>The spec will change to relax the Subset definition and to clear up
the
- * verbiage around what should be considered a {@code UseSubsetDirective},
- * but the idea of having programs carry claims that they fit within
fail-stop
- * named subsets of the language seems to have been agreed to.
- *
- * @author mikes...@gmail.com
- */
-public final class UseSubsetDirective extends AbstractStatement {
- /** @param value unused. This ctor is provided for reflection. */
- @ReflectiveCtor
- public UseSubsetDirective(
- FilePosition pos, Void value, List<? extends UseSubset> children) {
- this(pos, children);
- }
-
- public UseSubsetDirective(
- FilePosition pos, List<? extends UseSubset> children) {
- super(pos, UseSubset.class);
- createMutation().appendChildren(children).execute();
- }
-
- @Override
- protected void childrenChanged() {
- super.childrenChanged();
- if (children().isEmpty()) { throw new IndexOutOfBoundsException(); }
- for (ParseTreeNode us : children()) {
- if (!(us instanceof UseSubset)) {
- throw new ClassCastException(us.getClass().getName());
- }
- }
- }
-
- @Override
- public Object getValue() { return null; }
-
- @Override
- public List<? extends UseSubset> children() {
- return childrenAs(UseSubset.class);
- }
-
- public Set<String> getSubsetNames() {
- Set<String> names = new LinkedHashSet<String>();
- for (UseSubset us : children()) {
- names.add(us.getSubsetName());
- }
- return Collections.unmodifiableSet(names);
- }
-
- public void render(RenderContext rc) {
- StringBuilder sb = new StringBuilder();
- sb.append("use");
- String sep = " ";
- for (UseSubset us : children()) {
- sb.append(sep).append(us.getValue());
- sep = ",";
- }
- StringBuilder escaped = new StringBuilder();
- escaped.append('\'');
- Escaping.escapeJsString(sb, true, true, escaped);
- escaped.append('\'');
- rc.getOut().consume(escaped.toString());
- rc.getOut().consume(";");
- }
-
- @Override
- public boolean isTerminal() {
- return true;
- }
-
- public boolean hasHangingConditional() { return false; }
-}
=======================================
--- /trunk/src/com/google/caja/parser/quasiliteral/UseSubsetQuasiNode.java
Wed Feb 11 20:17:12 2009
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright (C) 2008 Google Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.caja.parser.quasiliteral;
-
-import com.google.caja.lexer.FilePosition;
-import com.google.caja.parser.ParseTreeNode;
-import com.google.caja.parser.js.UseSubset;
-import com.google.caja.parser.js.UseSubsetDirective;
-
-import java.util.ArrayList;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * A quasi mode that matches a use subset node that matches a
- * {@link UseSubsetDirective} that contains all the subset names as the
quasi
- * node.
- *
- * <p>
- * So the quasiliteral {@code 'use strict'} will match {@code 'use
strict'},
- * and {@code 'use strict,cajita'}, but not {@code 'use shiny'}.
- *
- * @author mikes...@gmail.com
- */
-final class UseSubsetQuasiNode extends QuasiNode {
- private final Set<String> subsetNames;
-
- public UseSubsetQuasiNode(Set<String> subsetNames) {
- this.subsetNames = new LinkedHashSet<String>(subsetNames);
- }
-
- @Override
- protected boolean consumeSpecimens(
- List<ParseTreeNode> specimens, Map<String, ParseTreeNode> bindings) {
- if (specimens.isEmpty()) { return false; }
- ParseTreeNode specimen = specimens.get(0);
- if (!(specimen instanceof UseSubsetDirective)) { return false; }
- UseSubsetDirective usd = ((UseSubsetDirective) specimen);
- if (!usd.getSubsetNames().containsAll(subsetNames)) { return false; }
- specimens.remove(0);
- return true;
- }
-
- @Override
- protected boolean createSubstitutes(
- List<ParseTreeNode> substitutes, Map<String, ParseTreeNode>
bindings) {
- List<UseSubset> subsets = new ArrayList<UseSubset>();
- for (String subsetName : subsetNames) {
- subsets.add(new UseSubset(FilePosition.UNKNOWN, subsetName));
- }
- substitutes.add(new UseSubsetDirective(FilePosition.UNKNOWN, subsets));
- return true;
- }
-}
=======================================
--- /trunk/tests/com/google/caja/demos/applet/caja-applet-cajita-golden.js
Thu Sep 10 18:33:03 2009
+++ /dev/null
@@ -1,31 +0,0 @@
-['Howdy\x3cspan id=\"id_1___\"\x3e\x3c/span\x3eThere\x3cscript
type=\"text/javascript\"\x3e{
- ___.loadModule({
- \'instantiate\': function (___, IMPORTS___) {
- var moduleResult___ = ___.NO_RESULT;
- var alert = ___.readImport(IMPORTS___, \'alert\');
- var onerror = ___.readImport(IMPORTS___, \'onerror\');
- {
- var el___;
- var emitter___ = IMPORTS___.htmlEmitter___;
- emitter___.discard(emitter___.attach(\'id_1___\'));
- }
- try {
- {
- moduleResult___ = alert.CALL___(2 + 2);
- }
- } catch (ex___) {
- ___.getNewModuleHandler().handleUncaughtException(ex___, onerror,
- \'example.com\', \'1\');
- }
- {
- el___ = emitter___.finish();
- emitter___.signalLoaded();
- }
- return moduleResult___;
- },
- \'includedModules\': [ ],
- \'cajolerName\': \'com.google.caja\',
- \'cajolerVersion\': \'testBuildVersion\',
- \'cajoledDate\': 0
- });
-}\x3c/script\x3e','']
=======================================
--- /trunk/tests/com/google/caja/parser/quasiliteral/testModule.co.js Tue
Oct 27 15:38:50 2009
+++ /dev/null
@@ -1,34 +0,0 @@
-{ ___.loadModule({
-'instantiate':
- function ( ___, IMPORTS___) {
- var moduleResult___ =
- ___. NO_RESULT;
- moduleResult___ = 1 +
- 1;
- return moduleResult___;
-}
-,
-'includedModules': [ ],
-'cajolerName': 'com.google.caja',
-'cajolerVersion': 'testBuildVersion',
-'cajoledDate': 0,
-'sourceLocationMap': {
- 'type': 'content',
- 'content': [
- '/** Begin line maps. **/{ file: \'file:///CAJOLED-OUTPUT\', count: 7
}',
- '[0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,]', '[0,,,,,,,,,,,,,,,,,,,,,]',
- '[0,,,,,,,,,,,,,,,,,,]', '[0,,,,,,,,,,,,,,,,,,1,,,]', '[2,,3]',
- '[0,,,,,,,,,,,,,,,,,,,,,,,]', '[0]', '/** Begin file information. **/',
- '[(void 0)]', '[(void 0)]', '[(void 0)]', '[\'testModule.js\',(void
0)]',
- '[\'testModule.js\']', '[(void 0)]', '[(void 0)]',
- '/** Begin mapping definitions. **/', '[(void 0),0,0]',
- '[\'testModule.js\',1,1]', '[\'testModule.js\',1,5]',
- '[\'testModule.js\',1,6]' ]
-},
-'originalSource': {
- 'testModule.js': {
- 'type': 'content',
- 'content': [ '1 + 1;' ]
- }
-}
-}); }
=======================================
--- /trunk/build.xml Thu Nov 12 12:53:32 2009
+++ /trunk/build.xml Fri Nov 13 13:37:15 2009
@@ -483,58 +483,74 @@

<!-- Cajoles test resources that contain cajita to javascript. -->
<target name="CajoledTests" depends="pluginc,dirs,CajoledValija">
+ <property name="libplugin" location="${lib}/com/google/caja/plugin"/>
+ <copy file="${tests}/com/google/caja/plugin/domita_test_untrusted.html"
+ tofile="${libplugin}/domita_test_untrusted_valija.html"/>
+ <copy file="${tests}/com/google/caja/plugin/domita_test_untrusted.html"
+ tofile="${libplugin}/domita_test_untrusted_cajita.html"/>
+ <replace file="${libplugin}/domita_test_untrusted_cajita.html">
+ <replacetoken>/*@@cajaLanguageSelectionStatements@@*/</replacetoken>
+ <replacevalue>"use cajita";</replacevalue>
+ </replace>
+ <replace file="${libplugin}/domita_test_untrusted_valija.html">
+ <replacetoken>/*@@cajaLanguageSelectionStatements@@*/</replacetoken>
+ <replacevalue></replacevalue>
+ </replace>
<transform>
- <input
file="${tests}/com/google/caja/plugin/domita_test_untrusted.html"/>
- <output file="${lib}/com/google/caja/plugin/domita_test.co.html"
- language="cajita"/>
- <output file="${lib}/com/google/caja/plugin/domita_test.vo.html"
- language="valija"/>
+ <input file="${libplugin}/domita_test_untrusted_valija.html"/>
+ <output file="${libplugin}/domita_test_untrusted_valija.out.html"
+ language="caja"/>
</transform>
<transform>
- <input file="${tests}/com/google/caja/a.js"/>
- <output file="${lib}/com/google/caja/a.co.js" language="cajita"/>
+ <input file="${libplugin}/domita_test_untrusted_cajita.html"/>
+ <output file="${libplugin}/domita_test_untrusted_cajita.out.html"
+ language="caja"/>
+ </transform>
+ <transform>
+ <input file="${tests}/com/google/caja/a.js"/>
+ <output file="${lib}/com/google/caja/a.out.js" language="caja"/>
</transform>
<transform>
- <input file="${tests}/com/google/caja/foo/b.js"/>
- <output file="${lib}/com/google/caja/foo/b.co.js" language="cajita"/>
+ <input file="${tests}/com/google/caja/foo/b.js"/>
+ <output file="${lib}/com/google/caja/foo/b.out.js" language="caja"/>
</transform>
<transform>
- <input file="${tests}/com/google/caja/c.js"/>
- <output file="${lib}/com/google/caja/c.co.js" language="cajita"/>
+ <input file="${tests}/com/google/caja/c.js"/>
+ <output file="${lib}/com/google/caja/c.out.js" language="caja"/>
</transform>
<transform>
- <input file="${tests}/com/google/caja/recursion.js"/>
- <output file="${lib}/com/google/caja/recursion.co.js"
language="cajita"/>
+ <input file="${tests}/com/google/caja/recursion.js"/>
+ <output file="${lib}/com/google/caja/recursion.out.js"
language="caja"/>
</transform>
<transform>
- <input file="${tests}/com/google/caja/x.js"/>
- <output file="${lib}/com/google/caja/x.vo.js" language="valija"/>
+ <input file="${tests}/com/google/caja/x.js"/>
+ <output file="${lib}/com/google/caja/x.out.js" language="caja"/>
</transform>
<transform>
- <input file="${tests}/com/google/caja/foo/inc.js"/>
- <output file="${lib}/com/google/caja/foo/inc.vo.js"
language="valija"/>
+ <input file="${tests}/com/google/caja/foo/inc.js"/>
+ <output file="${lib}/com/google/caja/foo/inc.out.js" language="caja"/>
</transform>
<transform>
- <input file="${tests}/com/google/caja/add.js"/>
- <output file="${lib}/com/google/caja/add.vo.js" language="valija"/>
+ <input file="${tests}/com/google/caja/add.js"/>
+ <output file="${lib}/com/google/caja/add.out.js" language="caja"/>
</transform>
<transform>
- <input file="${tests}/com/google/caja/commonJsRecursion.js"/>
- <output file="${lib}/com/google/caja/commonJsRecursion.vo.js"
- language="valija"/>
+ <input file="${tests}/com/google/caja/commonJsRecursion.js"/>
+ <output file="${lib}/com/google/caja/commonJsRecursion.out.js"
+ language="caja"/>
</transform>
<transform>
- <input file="${tests}/com/google/caja/foo/f.js"/>
- <output file="${lib}/com/google/caja/foo/f.co.js" language="cajita"/>
+ <input file="${tests}/com/google/caja/foo/f.js"/>
+ <output file="${lib}/com/google/caja/foo/f.out.js" language="caja"/>
</transform>
<transform>
- <input file="${tests}/com/google/caja/foo/staticinc.js"/>
- <output file="${lib}/com/google/caja/foo/staticinc.vo.js"
- language="valija"/>
+ <input file="${tests}/com/google/caja/foo/staticinc.js"/>
+ <output file="${lib}/com/google/caja/foo/staticinc.out.js"
+ language="caja"/>
</transform>
<transform>
- <input file="${tests}/com/google/caja/sum.js"/>
- <output file="${lib}/com/google/caja/sum.vo.js" language="valija"/>
+ <input file="${tests}/com/google/caja/sum.js"/>
+ <output file="${lib}/com/google/caja/sum.out.js" language="caja"/>
</transform>
<copy todir="${lib}">
<fileset dir="${src}" includes="**/*.html"/>
@@ -543,13 +559,13 @@
</target>
<target name="CajoledValija" depends="pluginc">
<transform>
- <output file="${lib}/com/google/caja/plugin/valija.co.js"
- language="cajita"/>
+ <output file="${lib}/com/google/caja/plugin/valija.out.js"
+ language="caja"/>
<input file="${src}/com/google/caja/valija-cajita.js"/>
</transform>
<transform>
- <output file="${lib}/com/google/caja/plugin/commonjs-sandbox.co.js"
- language="cajita"/>
+ <output file="${lib}/com/google/caja/plugin/commonjs-sandbox.out.js"
+ language="caja"/>
<input file="${src}/com/google/caja/commonjs-sandbox.js"/>
</transform>
</target>
@@ -850,14 +866,15 @@
<target name="lolcat-search" depends="dirs,pluginc,MinifiedJs"
description="IM IN UR BUILD DEMOING UR GADGETZ">
<transform>
- <output file="${www}/lolcat-search/searchbox.co.html"
- language="cajita"/>
+ <output file="${www}/lolcat-search/searchbox.out.js"
+ language="caja" onlyJsEmitted="true"/>
<input file="${demos}/lolcat-search/searchbox.html"/>
<depend file="${demos}/lolcat-search/searchbox.css"/>
<depend file="${demos}/lolcat-search/searchbox.js"/>
</transform>
<transform>
- <output file="${www}/lolcat-search/kittens.co.html"
language="cajita"/>
+ <output file="${www}/lolcat-search/kittens.out.js"
+ language="caja" onlyJsEmitted="true"/>
<input file="${demos}/lolcat-search/kittens.html"/>
<depend file="${demos}/lolcat-search/katTranzlator.js"/>
<depend file="${demos}/lolcat-search/kittens.js"/>
@@ -874,6 +891,8 @@
<fileset dir="${lib}/com/google/caja/plugin">
<include name="domita-minified.js"/>
<include name="html-sanitizer-minified.js"/>
+ <include name="valija.out.js"/>
+ <include name="module-promise-minified.js"/>
</fileset>
<fileset dir="${src}/com/google/caja">
<include name="log-to-console.js"/>
@@ -888,41 +907,47 @@
depends="dirs,pluginc,MinifiedJs,CajoledValija,lolcat-search"
description="Explain Caja">
<transform>
- <output file="${www}/slides/redirection.co.html" language="valija"
- ignore="UNSAFE_TAG DISALLOWED_CSS_PROPERTY_IN_SELECTOR"/>
+ <output file="${www}/slides/redirection.out.js" language="caja"
+ ignore="UNSAFE_TAG DISALLOWED_CSS_PROPERTY_IN_SELECTOR"
+ onlyJsEmitted="true"/>
<input file="${demos}/slides/redirection.html"/>
</transform>
<transform>
- <output file="${www}/slides/history.co.html" language="valija"
- ignore="UNSAFE_TAG DISALLOWED_CSS_PROPERTY_IN_SELECTOR"/>
+ <output file="${www}/slides/history.out.js" language="caja"
+ ignore="UNSAFE_TAG DISALLOWED_CSS_PROPERTY_IN_SELECTOR"
+ onlyJsEmitted="true"/>
<input file="${demos}/slides/history.html"/>
</transform>
<transform>
- <output file="${www}/slides/cookie.co.html" language="valija"
- ignore="UNSAFE_TAG DISALLOWED_CSS_PROPERTY_IN_SELECTOR"/>
+ <output file="${www}/slides/cookie.out.js" language="caja"
+ ignore="UNSAFE_TAG DISALLOWED_CSS_PROPERTY_IN_SELECTOR"
+ onlyJsEmitted="true"/>
<input file="${demos}/slides/cookie.html"/>
</transform>
<transform>
- <output file="${www}/slides/script-injection.co.html"
language="valija"
- ignore="UNSAFE_TAG DISALLOWED_CSS_PROPERTY_IN_SELECTOR"/>
+ <output file="${www}/slides/script-injection.out.js" language="caja"
+ ignore="UNSAFE_TAG DISALLOWED_CSS_PROPERTY_IN_SELECTOR"
+ onlyJsEmitted="true"/>
<input file="${demos}/slides/script-injection.html"/>
</transform>
<transform>
- <output file="${www}/slides/tame-alert.co.html" language="valija"
- ignore="UNSAFE_TAG DISALLOWED_CSS_PROPERTY_IN_SELECTOR"/>
+ <output file="${www}/slides/tame-alert.out.js" language="caja"
+ ignore="UNSAFE_TAG DISALLOWED_CSS_PROPERTY_IN_SELECTOR"
+ onlyJsEmitted="true"/>
<input file="${demos}/slides/tame-alert.html"/>
</transform>

<transform>
- <output file="${www}/slides/searchbox.co.html"
- language="cajita"/>
- <input file="${demos}/lolcat-search/searchbox.html"/>
+ <output file="${www}/slides/searchbox.out.js"
+ language="caja" onlyJsEmitted="true"/>
+ <include file="${demos}/lolcat-search/searchbox.html"/>
<depend file="${demos}/lolcat-search/searchbox.css"/>
<depend file="${demos}/lolcat-search/searchbox.js"/>
</transform>
<transform>
- <output file="${www}/slides/kittens.co.html" language="cajita"/>
- <input file="${demos}/lolcat-search/kittens.html"/>
+ <output file="${www}/slides/kittens.out.js"
+ language="caja" onlyJsEmitted="true"/>
+ <include file="${demos}/lolcat-search/kittens.html"/>
<depend file="${demos}/lolcat-search/katTranzlator.js"/>
<depend file="${demos}/lolcat-search/kittens.js"/>
</transform>
@@ -934,7 +959,8 @@
<include name="html-emitter.js"/>
<include name="css-defs.js"/>
<include name="html4-defs.js"/>
- <include name="valija.co.js"/>
+ <include name="valija.out.js"/>
+ <include name="module-promise-minified.js"/>
<include name="bridal.js"/>
<include name="domita.js"/>
<include name="domita-minified.js"/>
@@ -1014,7 +1040,7 @@
<fileset dir="${lib}/com/google/caja/plugin">
<include name="css-defs.js"/>
<include name="html4-defs.js"/>
- <include name="valija.co.js"/>
+ <include name="valija.out.js"/>
</fileset>
<fileset dir="${third_party}/js/prettify">
<include name="lang-css.js"/>
@@ -1059,7 +1085,7 @@
<script type="text/javascript" src="prettify.js"></script>
<script type="text/javascript" src="lang-css.js"></script>
<script type="text/javascript" src="testbed.js"></script>
- <script type="text/javascript" src="valija.co.js"></script>
+ <script type="text/javascript" src="valija.out.js"></script>
]]>
</replacevalue>
</replace>
@@ -1083,7 +1109,7 @@
<input file="${third_party}/js/prettify/prettify.js"/>
<input file="${third_party}/js/prettify/lang-css.js"/>
<input file="${src}/com/google/caja/demos/applet/testbed.js"/>
- <input file="${lib}/com/google/caja/plugin/valija.co.js"/>
+ <input file="${lib}/com/google/caja/plugin/valija.out.js"/>
</transform>
</target>

@@ -1130,8 +1156,8 @@
<input file="${demos}/calendar/main.js"/>
</transform>
<transform>
- <output file="${lib}/com/google/caja/demos/calendar/calendar.vo.js"
- language="valija" debug="false"/>
+ <output file="${lib}/com/google/caja/demos/calendar/calendar.out.js"
+ language="caja" debug="false"/>
<input file="${demos}/calendar/widget.css"/>
<input file="${demos}/calendar/util.js"/>
<input file="${demos}/calendar/bitset.js"/>
@@ -1168,8 +1194,7 @@
</fileset>
<fileset dir="${lib}/com/google/caja/demos/calendar">
<include name="*-minified.js"/>
- <include name="*.vo.js"/>
- <include name="*.co.js"/>
+ <include name="*.out.js"/>
</fileset>
<fileset dir="${demos}/calendar">
<include name="demo.html"/>
@@ -1179,7 +1204,7 @@
<fileset dir="${lib}/com/google/caja/plugin">
<include name="domita-minified.js"/>
<include name="html-sanitizer-minified.js"/>
- <include name="valija.co.js"/>
+ <include name="valija.out.js"/>
</fileset>
<fileset dir="${third_party}/js/firebug">
<include name="firebugx.js"/>
@@ -1190,11 +1215,11 @@
<target name="yuitest" depends="pluginc,dirs,CajoledValija">
<transform>
<input file="yuitest/yahoo-dom.js"/>
- <output file="yuitest/yahoo-dom.vo.js" language="valija"/>
+ <output file="yuitest/yahoo-dom.out.js" language="caja"/>
</transform>
<transform>
<input file="yuitest/dom_test.html"/>
- <output file="yuitest/dom_test.vo.html" language="valija"/>
+ <output file="yuitest/dom_test.out.html" language="caja"/>
</transform>
</target>

=======================================
--- /trunk/src/com/google/caja/ancillary/linter/VariableLiveness.java Mon
Oct 19 18:04:03 2009
+++ /trunk/src/com/google/caja/ancillary/linter/VariableLiveness.java Fri
Nov 13 13:37:15 2009
@@ -47,6 +47,7 @@
import com.google.caja.parser.js.TryStmt;
import com.google.caja.parser.js.WhileLoop;
import com.google.caja.parser.js.WithStmt;
+import com.google.caja.parser.js.DirectivePrologue;
import com.google.caja.util.SyntheticAttributeKey;

import java.util.List;
@@ -207,6 +208,10 @@
return processNoop(onEntry);
} else if (s instanceof LabeledStmtWrapper) {
return processLabeledStmtWrapper((LabeledStmtWrapper) s, onEntry);
+ } else if (s instanceof DirectivePrologue) {
+ // TODO: New node type, not yet supported by linter
+ // return processDirectivePrologue((DirectivePrologue) s, onEntry);
+ return processNoop(onEntry);
} else {
throw new RuntimeException(s.getClass().getName());
}
@@ -670,6 +675,12 @@
}
return last;
}
+
+ private static LiveCalc processDirectivePrologue(
+ DirectivePrologue d, LiveSet onEntry) {
+ // TODO: New node type, not yet supported by linter
+ return null;
+ }

/**
* Incorporates the set of variables live at breaks into the live-set and
=======================================
--- /trunk/src/com/google/caja/cajita-module.js Fri Nov 13 11:43:08 2009
+++ /trunk/src/com/google/caja/cajita-module.js Fri Nov 13 13:37:15 2009
@@ -14,7 +14,7 @@

/**
* @author maoz...@gmail.com
- * @requires ___
+ * @requires ___, bridal
* @provides xhrModuleLoadMaker, scriptModuleLoadMaker, clearModuleCache
*
* Each load maker object, given a current module identifier and an
@@ -26,6 +26,7 @@
*/
var xhrModuleLoadMaker;
var scriptModuleLoadMaker;
+var defaultModuleIdResolver;
var clearModuleCache;

(function() {
@@ -38,7 +39,7 @@
return src;
}

- function defaultMidResolver(mid, src) {
+ defaultModuleIdResolver = function(mid, src) {
if (src[0] !== '.') {
return src;
}
@@ -65,7 +66,7 @@
}

return newMid;
- }
+ };

function syncLoad(mid) {
mid = addJsExtension(mid);
@@ -79,10 +80,40 @@
var load = function(src) {
return syncLoad(midResolver(mid, src));
};
- load.FUNC___ = 'load';
- ___.setStatic(load, 'async', ___.markFuncFreeze(function (src) {
+
+ var async = function(src) {
return asyncLoad(midResolver(mid, src), midResolver);
- }));
+ };
+
+ var asyncAll = function(moduleNames) {
+ var r = Q.defer();
+ var i;
+ var modulePromises = [];
+ var modules = {};
+
+ for (i = 0; i < moduleNames.length; ++i) {
+ modulePromises[i] = async(moduleNames[i]);
+ }
+
+ var waitNext = function(idx) {
+ if (idx === moduleNames.length) {
+ r.resolve(modules);
+ } else {
+ Q.when( modulePromises[idx], function(theModule) {
+ modules[moduleNames[idx]] = theModule;
+ waitNext(idx + 1);
+ }, function(reason) {
+ r.resolve(Q.reject(reason));
+ });
+ }
+ };
+ waitNext(0);
+ return r.promise();
+ };
+
+ load.FUNC___ = 'load';
+ ___.setStatic(load, 'async', ___.markFuncFreeze(async));
+ ___.setStatic(load, 'asyncAll', ___.markFuncFreeze(asyncAll));
return ___.primFreeze(load);
}

@@ -121,7 +152,9 @@
}

var r = Q.defer();
- var xhr = new XMLHttpRequest(); // TODO(mikesamuel): get working on IE
+ cache[mid] = r.promise;
+
+ var xhr = bridal.makeXhr();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
@@ -132,7 +165,6 @@
var load = loadMaker(mid, midResolver, xhrAsyncLoad);
module.moduleId = mid;
var securedModule = ___.prepareModule(module, load);
- cache[mid] = r.promise;
var dependency = resolveDependency(module, load);
Q.when(dependency, function(result) {
r.resolve(securedModule);
@@ -161,14 +193,16 @@
};

xhr.open("GET", mid, true);
- xhr.overrideMimeType("application/javascript");
+ if (typeof xhr.overrideMimeType === 'function') {
+ xhr.overrideMimeType("application/javascript");
+ }
xhr.send(null);
return r.promise;
}

xhrModuleLoadMaker = ___.markFuncFreeze(function(mid, midResolver) {
if (midResolver === undefined) {
- midResolver = defaultMidResolver;
+ midResolver = defaultModuleIdResolver;
}

return loadMaker(mid, midResolver, xhrAsyncLoad);
@@ -185,44 +219,58 @@
}

var r = Q.defer();
+ cache[mid] = r.promise;

function dequeue() {
if (head < queue.length) {
busy = true;
var savedHead = head;

- ___.setNewModuleHandler(___.primFreeze({
- handle: ___.markFuncFreeze(function theHandler(module) {
- if (savedHead === head) {
- var r = queue[head].defer;
- try {
- var curMid = queue[head].mid;
- var load = loadMaker(curMid, midResolver, scriptAsyncLoad);
- module.moduleId = mid;
- var securedModule = ___.prepareModule(module, load);
- cache[curMid] = r.promise;
-
- var dependency = resolveDependency(module, load);
- Q.when(dependency, function(result) {
- r.resolve(securedModule);
- },
- function(reason) {
- r.resolve(Q.reject(
- "Resolving dependency for the
module "
- + curMid + " failed."));
- });
- } catch (e) {
- r.resolve(Q.reject(e));
- }
- delete queue[head];
- head++;
- dequeue();
- } else {
- // this should not happen
- // the module may have been mistakenly treated as a failure
- }
- })
- }));
+ // TODO(ihab.awad): Modifying a frozen structure (the new module
+ // handler) in un-cajoled code is possible but poor practice.
+
+ // TODO(ihab.awad): Consider refactoring the <script> module
loader to
+ // always use a JSONP-style callback function so that it does not
+ // trample on code that uses the standard ___.loadModule().
+
+ // TODO(ihab.awad): Consider deprecating the entire
newModuleHandler
+ // system since it relies on globally visible modifications
to "___";
+ // instead maybe we should just cajole to a well-known callback if
none
+ // is supplied, like:
+ // cajaModuleCallback___(___.prepareModule({ ... module ...
}));
+
+ var newModuleHandler = ___.makeNormalNewModuleHandler();
+ newModuleHandler.handle = ___.markFuncFreeze(
+ function theHandler(module) {
+ if (savedHead === head) {
+ var r = queue[head].defer;
+ try {
+ var curMid = queue[head].mid;
+ var load = loadMaker(curMid, midResolver,
scriptAsyncLoad);
+ module.moduleId = mid;
+ var securedModule = ___.prepareModule(module, load);
+
+ var dependency = resolveDependency(module, load);
+ Q.when(dependency,
+ function(result) {
+ r.resolve(securedModule);
+ },
+ function(reason) {
+ r.resolve(Q.reject(
+ "Resolving dependency for the module "
+ + curMid + " failed."));
+ });
+ } catch (e) {
+ r.resolve(Q.reject(e));
+ }
+ delete queue[head];
+ head++;
+ dequeue();
+ } else {
+ throw new Error('Module queue got out of sync');
+ }
+ });
+ ___.setNewModuleHandler(newModuleHandler);

function timeout() {
if (savedHead === head) {
@@ -252,7 +300,7 @@
};
document.getElementsByTagName('head')[0].appendChild(script);
} else {
- busy = false;
+ busy = false;
}
}

@@ -270,7 +318,7 @@

scriptModuleLoadMaker = ___.markFuncFreeze(function(mid, midResolver) {
if (midResolver === undefined) {
- midResolver = defaultMidResolver;
+ midResolver = defaultModuleIdResolver;
}

return loadMaker(mid, midResolver, scriptAsyncLoad);
=======================================
--- /trunk/src/com/google/caja/cajita.js Wed Nov 4 20:56:10 2009
+++ /trunk/src/com/google/caja/cajita.js Fri Nov 13 13:37:15 2009
@@ -3370,9 +3370,12 @@
// before invoking the Cajita module.
var completeImports = copy(sharedImports);
completeImports.load = load;
- forOwnKeys(imports, markFuncFreeze(function(k, v) {
- completeImports[k] = v;
- }));
+ // Copy all properties, including Cajita-unreadable ones since these
may
+ // be used by privileged code.
+ var k;
+ for (k in imports) {
+ if (hasOwnProp(imports, k)) { completeImports[k] = imports[k]; }
+ }
return module.instantiate(___, primFreeze(completeImports));
}
theModule.FUNC___ = 'theModule';
@@ -3386,7 +3389,10 @@
setStatic(theModule, 'moduleId', module.moduleId);
// The below is a transitive freeze because includedModules is an array
// of strings.
- setStatic(theModule, 'includedModules',
___.freeze(module.includedModules));
+ if (!!module.includedModules) {
+ setStatic(theModule, 'includedModules',
+ ___.freeze(module.includedModules));
+ }

return primFreeze(theModule);
}
=======================================
--- /trunk/src/com/google/caja/commonjs-sandbox.js Thu Sep 10 18:33:03 2009
+++ /trunk/src/com/google/caja/commonjs-sandbox.js Fri Nov 13 13:37:15 2009
@@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

+'use strict';
+'use cajita';
+
/**
* @author maoz...@gmail.com
* @provides commonJsSandboxMaker
@@ -82,3 +85,14 @@
if (typeof loader !== 'undefined') {
loader.provide(commonJsSandboxMaker);
}
+
+// If this module is called with the new-style Cajita module convention,
+// passing 'env', 'valijaModule' and 'load' as Cajita-level parameters, the
+// value returned from instantiating the module should be the fully
constructed
+// ServerJS sandbox object.
+if (typeof env !== 'undefined'
+ && typeof valijaModule !== 'undefined') {
+ commonJsSandboxMaker(env, function(valijaOuters) {
+ return valijaModule({ outers: valijaOuters });
+ });
+}
=======================================
--- /trunk/src/com/google/caja/demos/applet/CajaApplet.java Thu Jul 30
19:46:50 2009
+++ /trunk/src/com/google/caja/demos/applet/CajaApplet.java Fri Nov 13
13:37:15 2009
@@ -172,7 +172,6 @@
}
};
rw.setDebugMode(features.contains(Feature.DEBUG_SYMBOLS));
- rw.setValijaMode(features.contains(Feature.VALIJA_MODE));

StringBuilder cajoledOutput = new StringBuilder();

@@ -248,8 +247,6 @@
DEBUG_SYMBOLS,
/** Present if the output should be embeddable in HTML or XML. */
EMBEDDABLE,
- /** Present to enable valija mode. */
- VALIJA_MODE,
;
}
}
=======================================
--- /trunk/src/com/google/caja/demos/applet/testbed.js Wed Sep 23 14:31:25
2009
+++ /trunk/src/com/google/caja/demos/applet/testbed.js Fri Nov 13 13:37:15
2009
@@ -221,7 +221,7 @@
var features = ['testbedServer=' +
getTestbedServer().replace(/,/g, '%2C')];
// See CajaApplet.Feature
cajita.forOwnKeys(
- { EMBEDDABLE: true, DEBUG_SYMBOLS: true, VALIJA_MODE: true },
+ { EMBEDDABLE: true, DEBUG_SYMBOLS: true },
___.markFuncFreeze(function (featureName) {
if (document.getElementById(featureName + uiSuffix).checked) {
features.push(featureName);
=======================================
--- /trunk/src/com/google/caja/demos/calendar/demo-cajoled.html Fri Aug 28
19:16:06 2009
+++ /trunk/src/com/google/caja/demos/calendar/demo-cajoled.html Fri Nov 13
13:37:15 2009
@@ -84,7 +84,7 @@

<!-- Load the Valija module. That module calls laoder.provide() defined
above, which sets the variable 'valijaMaker'. -->
- <script type="text/javascript" src="valija.co.js"></script>
+ <script type="text/javascript" src="valija.out.js"></script>

<script type="text/javascript">(function () {
var uriCallback = { rewrite: function () { return null; } };
@@ -154,5 +154,5 @@

window.imports = imports;
})();</script>
- <script src="calendar.vo.js"></script>
+ <script src="calendar.out.js"></script>
</html>
=======================================
--- /trunk/src/com/google/caja/demos/lolcat-search/katTranzlator.js Wed Mar
18 18:17:29 2009
+++ /trunk/src/com/google/caja/demos/lolcat-search/katTranzlator.js Fri Nov
13 13:37:15 2009
@@ -19,6 +19,9 @@
* @author mikes...@gmail.com
*/

+'use strict';
+'use cajita';
+
/**
* @param {string} text English
* @return {string} LOLCAT
=======================================
--- /trunk/src/com/google/caja/demos/lolcat-search/kittens.js Wed Mar 18
18:17:29 2009
+++ /trunk/src/com/google/caja/demos/lolcat-search/kittens.js Fri Nov 13
13:37:15 2009
@@ -19,6 +19,8 @@
* @author mikes...@gmail.com
*/

+'use strict';
+'use cajita';

/** @type {SearchEngine} */
searchEngine;
=======================================
--- /trunk/src/com/google/caja/demos/lolcat-search/search.html Tue Jul 7
09:39:02 2009
+++ /trunk/src/com/google/caja/demos/lolcat-search/search.html Fri Nov 13
13:37:15 2009
@@ -37,6 +37,7 @@
<script type="text/javascript" src="log-to-console.js"></script>
<script type="text/javascript" src="domita-minified.js"></script>
<script type="text/javascript"
src="html-sanitizer-minified.js"></script>
+ <script type="text/javascript"
src="module-promise-minified.js"></script>

<script type="text/javascript">(function () {
___.sharedImports.console = {};
@@ -51,39 +52,6 @@
}
})();</script>

- <script type="text/javascript">
- function makeXhr() {
- if (typeof XMLHttpRequest === 'undefined') {
- var activeXClassIds = [
- 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0',
- 'MSXML2.XMLHTTP', 'MICROSOFT.XMLHTTP.1.0', 'MICROSOFT.XMLHTTP.1',
- 'MICROSOFT.XMLHTTP'];
- for (var i = 0, n = activeXClassIds.length; i < n; i++) {
- var candidate = activeXClassIds[i];
- try {
- return new ActiveXObject(candidate);
- } catch (e) {}
- }
- }
- return new XMLHttpRequest;
- }
-
- function inlineHtml(href, container) {
- var xhr = makeXhr();
- xhr.open('GET', href, false);
- xhr.send(null);
- if (xhr.status !== 200 && xhr.status !== 0) {
- throw new Error('Failed to load ' + href + ' : ' + xhr.status);
- }
- var htmlAndScript = xhr.responseText.match(
- /^([\s\S]*?)<script[^>]*>([\s\S]*?)<\/script>$/);
- var div = container.ownerDocument.createElement('DIV');
- div.innerHTML = htmlAndScript[1];
- while (div.firstChild) { container.appendChild(div.firstChild); }
- (new Function(htmlAndScript[2]))();
- }
- </script>
-
<!-- Google Search API as documented at
-
http://code.google.com/apis/ajaxsearch/documentation/reference.html -->
<!-- This allows us to serve from 127.0.0.1 -->
@@ -112,62 +80,67 @@
<!-- And another for the searchbox gadget. -->
<div class=searchbox><ul id="results-searchbox"></ul></div>

- <!--
- - Initialize separate global namespaces for each plugin as specified
at
- - http://code.google.com/p/google-caja/wiki/CajaHostingModules
- -->
<script type="text/javascript">
- var searchBoxImports = ___.copy(___.sharedImports);
- attachDocumentStub(
- '-searchbox', { rewrite: function () { return null; } },
- searchBoxImports, document.getElementById('base-searchbox'));
- searchBoxImports.htmlEmitter___ = new HtmlEmitter(
- document.getElementById('base-searchbox'));
- </script>
- <script type="text/javascript">
- var kittensImports = ___.copy(___.sharedImports);
- kittensImports.exports = {};
- ___.grantRead(searchBoxImports, 'exports');
- attachDocumentStub(
- '-kittens', { rewrite: function (url, mimeType) {
- return /^image\//.test(mimeType) ? url : null;
- } },
- kittensImports, document.getElementById('base-kittens'));
- kittensImports.htmlEmitter___ = new HtmlEmitter(
- document.getElementById('base-kittens'));
- </script>
-
- <!-- Inject some capabilities into the 2 plugins. -->
- <script type="text/javascript">
- (function () {
- google.load('search', '1');
-
- var searchEngine = new SearchEngine();
-
- // Provide both modules an interface to Google search.
- searchBoxImports.searchEngine = kittensImports.searchEngine
- = searchEngine;
- ___.grantRead(searchBoxImports, 'searchEngine');
- ___.grantRead(kittensImports, 'searchEngine');
- })();
- </script>
-
- <script type="text/javascript">
- ___.getNewModuleHandler().setImports(kittensImports);
- inlineHtml('kittens.co.html',
- document.getElementById('base-kittens'));
- </script>
-
- <!-- Allow searchBoxImports to talk to kittens. -->
- <script type="text/javascript">
- searchBoxImports.resultConsumer = kittensImports.exports.showKitten;
- ___.grantRead(searchBoxImports, 'resultConsumer');
- </script>
-
- <script type="text/javascript">
- ___.getNewModuleHandler().setImports(searchBoxImports);
- inlineHtml('searchbox.co.html',
- document.getElementById('base-searchbox'));
+ google.load('search', '1');
+ var searchEngine = new SearchEngine();
+
+ var xhrModuleLoad = xhrModuleLoadMaker(
+ document.location.toString(),
+ function moduleIdResolver(base, input) {
+ return defaultModuleIdResolver(base, input + '.out.js');
+ });
+
+ Q.when(
+ xhrModuleLoad.asyncAll(['valija', 'searchbox', 'kittens']),
+ function(modules) {
+
+ // Initialize separate global namespaces for each plugin
+
+ var searchBoxImports;
+ var kittensImports;
+
+ searchBoxImports = ___.copy(___.sharedImports);
+ attachDocumentStub(
+ '-searchbox', { rewrite: function () { return null; } },
+ searchBoxImports,
document.getElementById('base-searchbox'));
+ searchBoxImports.htmlEmitter___ = new HtmlEmitter(
+ document.getElementById('base-searchbox'));
+ searchBoxImports.outers = searchBoxImports;
+ searchBoxImports.$v = modules['valija'].CALL___({
+ outers: searchBoxImports.outers
+ });
+
+ kittensImports = ___.copy(___.sharedImports);
+ kittensImports.exports = {};
+ ___.grantRead(searchBoxImports, 'exports');
+ attachDocumentStub(
+ '-kittens', { rewrite: function (url, mimeType) {
+ return /^image\//.test(mimeType) ? url :
null;
+ } },
+ kittensImports, document.getElementById('base-kittens'));
+ kittensImports.htmlEmitter___ = new HtmlEmitter(
+ document.getElementById('base-kittens'));
+ kittensImports.outers = kittensImports;
+ kittensImports.$v = modules['valija'].CALL___({
+ outers: kittensImports.outers
+ });
+
+ // Inject some capabilities into the 2 plugins
+
+ // Provide both modules an interface to Google search.
+ searchBoxImports.searchEngine = kittensImports.searchEngine
+ = searchEngine;
+ ___.grantRead(searchBoxImports, 'searchEngine');
+ ___.grantRead(kittensImports, 'searchEngine');
+
+ modules['kittens'].CALL___(kittensImports);
+
+ // Allow searchBoxImports to talk to kittens.
+ searchBoxImports.resultConsumer =
kittensImports.exports.showKitten;
+ ___.grantRead(searchBoxImports, 'resultConsumer');
+
+ modules['searchbox'].CALL___(searchBoxImports);
+ });
</script>

</body>
=======================================
--- /trunk/src/com/google/caja/demos/lolcat-search/searchbox.js Wed Mar 18
18:17:29 2009
+++ /trunk/src/com/google/caja/demos/lolcat-search/searchbox.js Fri Nov 13
13:37:15 2009
@@ -20,6 +20,8 @@
* @author mikes...@gmail.com
*/

+'use strict';
+'use cajita';

/**
* Injected by the container.
@@ -84,6 +86,12 @@
}
});
}
+
+/**
+ * Make 'doSearch' available to the HTML (Valija) global scope so we can
+ * call it as an event handler via a static HTML attribute.
+ */
+$v.so('doSearch', doSearch);

/**
* Event handler that is called when a result link is clicked.
=======================================
--- /trunk/src/com/google/caja/demos/lolcat-search/slides.html Fri Oct 24
16:01:25 2008
+++ /trunk/src/com/google/caja/demos/lolcat-search/slides.html Fri Nov 13
13:37:15 2009
@@ -406,7 +406,7 @@
document.getElementById(<span class=str>'base-searchBox___'</span>));
&lt;/script&gt;
<span class=cmt>&lt;!-- Load the gadget JS --&gt;</span>
-&lt;script type="text/javascript" src="<b>searchbox.co.js</b>"/&gt;
+&lt;script type="text/javascript" src="<b>searchbox.out.js</b>"/&gt;
</pre>
</li>

=======================================
--- /trunk/src/com/google/caja/demos/slides/index.html Fri Oct 23 12:20:15
2009
+++ /trunk/src/com/google/caja/demos/slides/index.html Fri Nov 13 13:37:15
2009
@@ -29,7 +29,8 @@
<script type="text/javascript" src="log-to-console.js"></script>
<script type="text/javascript" src="domita-minified.js"></script>
<script type="text/javascript"
src="html-sanitizer-minified.js"></script>
-
+ <script type="text/javascript"
src="module-promise-minified.js"></script>
+
<script type="text/javascript">(function () {
___.sharedImports.console = {};
for (var k in { log: 0, warn: 0, info: 0, error: 0, trace: 0,
@@ -43,69 +44,97 @@
}
})();</script>

- <script type="text/javascript">
- function makeXhr() {
- if (typeof XMLHttpRequest === 'undefined') {
- var activeXClassIds = [
- 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0',
- 'MSXML2.XMLHTTP', 'MICROSOFT.XMLHTTP.1.0', 'MICROSOFT.XMLHTTP.1',
- 'MICROSOFT.XMLHTTP'];
- for (var i = 0, n = activeXClassIds.length; i < n; i++) {
- var candidate = activeXClassIds[i];
- try {
- return new ActiveXObject(candidate);
- } catch (e) {}
- }
- }
- return new XMLHttpRequest;
- }
-
- function inlineHtml(href, container) {
- var xhr = makeXhr();
- xhr.open('GET', href, false);
- xhr.send(null);
- if (xhr.status !== 200 && xhr.status !== 0) {
- throw new Error('Failed to load ' + href + ' : ' + xhr.status);
- }
- var htmlAndScript = xhr.responseText.match(
- /^([\s\S]*?)<script[^>]*>([\s\S]*?)<\/script>$/);
- var div = container.ownerDocument.createElement('DIV');
- div.innerHTML = htmlAndScript[1];
- while (div.firstChild) { container.appendChild(div.firstChild); }
- (new Function(htmlAndScript[2]))();
- }
- </script>
-<script>
-var valijaMaker = undefined;
-
-(function(){
- var imports = ___.copy(___.sharedImports);
- imports.loader = {
- provide: function(v) { valijaMaker = v; }
- };
- ___.grantRead(imports, 'loader');
- ___.grantFunc(imports.loader, 'provide');
- ___.getNewModuleHandler().setImports(imports);
- ___.getNewModuleHandler().handleUncaughtException = function(e) {
- throw e;
- };
- })();
-</script>
- <script type="text/javascript" src="valija.co.js"></script>
-<script>
-var newIsolatedGadget = (function() {
- return function(id) {
- var newImports = ___.copy(___.sharedImports);
- newImports.outers = newImports;
- attachDocumentStub('-' + id, { rewrite: function () { return null; } },
- newImports, document.getElementById('base-' + id));
- newImports.htmlEmitter___ = new HtmlEmitter(
- document.getElementById('base-' + id));
- ___.getNewModuleHandler().setImports(newImports);
- newImports.$v = valijaMaker.CALL___(newImports.outers);
- }
-})();
-</script>
+ <!-- Google Search API as documented at
+ -
http://code.google.com/apis/ajaxsearch/documentation/reference.html -->
+ <!-- This allows us to serve from 127.0.0.1 -->
+ <!--script type="text/javascript"
src="http://www.google.com/jsapi?key=ABQIAAAARYHJOWhGvC-hnHaFO4oa7BRi_j0U6kJrkFvY4-OX2XYmEAa76BTIOZulNVZlEl6ODqNB1GWqhRyqZQ"></script-->
+ <!-- Ihis allows us to serve from google-caja.googlecode.com -->
+ <script type="text/javascript"
src="http://www.google.com/jsapi?key=ABQIAAAARYHJOWhGvC-hnHaFO4oa7BRvHrijLxG0Kbzp8ris5IURMLbrEBS7CZj1UJz7CIXsA-YHseffaxlnlQ"></script>
+
+ <!-- Container code. -->
+ <script type="text/javascript">google.load('search', '1');</script>
+ <script type="text/javascript" src="searchengine.js"></script>
+ <script type="text/javascript" src="chtml.js"></script>
+
+ <script>
+ google.load('search', '1');
+ var searchEngine = new SearchEngine();
+
+ var xhrModuleLoad = xhrModuleLoadMaker(
+ document.location.toString(),
+ function moduleIdResolver(base, input) {
+ return defaultModuleIdResolver(base, input + '.out.js');
+ });
+
+ var modulesVow =
+ xhrModuleLoad.asyncAll(['valija', 'searchbox', 'kittens']);
+
+ var newIsolatedGadget = function(id, moduleName) {
+ var newImports = ___.copy(___.sharedImports);
+ newImports.outers = newImports;
+ attachDocumentStub('-' + id, { rewrite: function () { return null;
} },
+ newImports, document.getElementById('base-' + id));
+ newImports.htmlEmitter___ = new HtmlEmitter(
+ document.getElementById('base-' + id));
+ ___.getNewModuleHandler().setImports(newImports);
+ Q.when(xhrModuleLoad.asyncAll(['valija', moduleName]),
+ function(modules) {
+ newImports.$v = modules['valija'].CALL___(newImports.outers);
+ modules[moduleName].CALL___(newImports);
+ });
+ };
+
+ Q.when(modulesVow, function(modules) {
+
+ // Initialize separate global namespaces for each plugin
+
+ var searchBoxImports;
+ var kittensImports;
+
+ searchBoxImports = ___.copy(___.sharedImports);
+ attachDocumentStub(
+ '-searchbox', { rewrite: function () { return null; } },
+ searchBoxImports, document.getElementById('base-searchbox'));
+ searchBoxImports.htmlEmitter___ = new HtmlEmitter(
+ document.getElementById('base-searchbox'));
+ searchBoxImports.outers = searchBoxImports;
+ searchBoxImports.$v = modules['valija'].CALL___({
+ outers: searchBoxImports.outers
+ });
+
+ kittensImports = ___.copy(___.sharedImports);
+ kittensImports.exports = {};
+ ___.grantRead(searchBoxImports, 'exports');
+ attachDocumentStub(
+ '-kittens', { rewrite: function (url, mimeType) {
+ return /^image\//.test(mimeType) ? url : null;
+ } },
+ kittensImports, document.getElementById('base-kittens'));
+ kittensImports.htmlEmitter___ = new HtmlEmitter(
+ document.getElementById('base-kittens'));
+ kittensImports.outers = kittensImports;
+ kittensImports.$v = modules['valija'].CALL___({
+ outers: kittensImports.outers
+ });
+
+ // Inject some capabilities into the 2 plugins
+
+ // Provide both modules an interface to Google search.
+ searchBoxImports.searchEngine = kittensImports.searchEngine
+ = searchEngine;
+ ___.grantRead(searchBoxImports, 'searchEngine');
+ ___.grantRead(kittensImports, 'searchEngine');
+
+ modules['kittens'].CALL___(kittensImports);
+
+ // Allow searchBoxImports to talk to kittens.
+ searchBoxImports.resultConsumer =
kittensImports.exports.showKitten;
+ ___.grantRead(searchBoxImports, 'resultConsumer');
+
+ modules['searchbox'].CALL___(searchBoxImports);
+ });
+
+ </script>
</head>
<body>
<div class="background"></div>
@@ -225,17 +254,6 @@
<div class="slide">
<h1>LOLcat Search</h1>

- <!-- Google Search API as documented at
- -
http://code.google.com/apis/ajaxsearch/documentation/reference.html -->
- <!-- This allows us to serve from 127.0.0.1 -->
- <!--script type="text/javascript"
src="http://www.google.com/jsapi?key=ABQIAAAARYHJOWhGvC-hnHaFO4oa7BRi_j0U6kJrkFvY4-OX2XYmEAa76BTIOZulNVZlEl6ODqNB1GWqhRyqZQ"></script-->
- <!-- Ihis allows us to serve from google-caja.googlecode.com -->
- <script type="text/javascript"
src="http://www.google.com/jsapi?key=ABQIAAAARYHJOWhGvC-hnHaFO4oa7BRvHrijLxG0Kbzp8ris5IURMLbrEBS7CZj1UJz7CIXsA-YHseffaxlnlQ"></script>
-
- <!-- Container code. -->
- <script type="text/javascript">google.load('search', '1');</script>
- <script type="text/javascript" src="searchengine.js"></script>
- <script type="text/javascript" src="chtml.js"></script>
<script type="text/javascript">
___.sharedImports.StringInterpolation = StringInterpolation;
___.grantFunc(___.sharedImports, 'StringInterpolation');
@@ -252,64 +270,6 @@
<!-- And another for the searchbox gadget. -->
<div class=searchbox><ul id="results-searchbox"></ul></div>

- <!--
- - Initialize separate global namespaces for each plugin as
specified at
- - http://code.google.com/p/google-caja/wiki/CajaHostingModules
- -->
- <script type="text/javascript">
- var searchBoxImports = ___.copy(___.sharedImports);
- attachDocumentStub(
- '-searchbox', { rewrite: function () { return null; } },
- searchBoxImports, document.getElementById('base-searchbox'));
- searchBoxImports.htmlEmitter___ = new HtmlEmitter(
- document.getElementById('base-searchbox'));
- </script>
- <script type="text/javascript">
- var kittensImports = ___.copy(___.sharedImports);
- kittensImports.exports = {};
- ___.grantRead(searchBoxImports, 'exports');
- attachDocumentStub(
- '-kittens', { rewrite: function (url, mimeType) {
- return /^image\//.test(mimeType) ?
url : null;
- } },
- kittensImports, document.getElementById('base-kittens'));
- kittensImports.htmlEmitter___ = new HtmlEmitter(
- document.getElementById('base-kittens'));
- </script>
-
- <!-- Inject some capabilities into the 2 plugins. -->
- <script type="text/javascript">
- (function () {
- google.load('search', '1');
-
- var searchEngine = new SearchEngine();
-
- // Provide both modules an interface to Google search.
- searchBoxImports.searchEngine = kittensImports.searchEngine
- = searchEngine;
- ___.grantRead(searchBoxImports, 'searchEngine');
- ___.grantRead(kittensImports, 'searchEngine');
- })();
- </script>
-
- <script type="text/javascript">
- ___.getNewModuleHandler().setImports(kittensImports);
- inlineHtml('kittens.co.html',
- document.getElementById('base-kittens'));
- </script>
-
-
- <!-- Allow searchBoxImports to talk to kittens. -->
- <script type="text/javascript">
- searchBoxImports.resultConsumer =
kittensImports.exports.showKitten;
- ___.grantRead(searchBoxImports, 'resultConsumer');
- </script>
-
- <script type="text/javascript">
- ___.getNewModuleHandler().setImports(searchBoxImports);
- inlineHtml('searchbox.co.html',
- document.getElementById('base-searchbox'));
- </script>
<div class="handout">
</div>
</div>
@@ -342,9 +302,7 @@
<script type="text/javascript">
</script>
<script type="text/javascript">
- newIsolatedGadget('attackRedirection');
- inlineHtml('redirection.co.html',
- document.getElementById('base-attackRedirection'));
+ newIsolatedGadget('attackRedirection', 'redirection');
</script>

<div class="vbox">
@@ -383,9 +341,7 @@
</div>
</div>
<script type="text/javascript">
- newIsolatedGadget('attackHistory');
- inlineHtml('history.co.html',
- document.getElementById('base-attackHistory'));
+ newIsolatedGadget('attackHistory', 'history');
</script>

<div class="vbox">
@@ -425,9 +381,7 @@
</div>
<script type="text/javascript">document.cookie = "secret
cookie"</script>
<script type="text/javascript">
- newIsolatedGadget('attackCookie');
- inlineHtml('cookie.co.html',
- document.getElementById('base-attackCookie'));
+ newIsolatedGadget('attackCookie', 'cookie');
</script>

<div class="vbox">
@@ -461,9 +415,7 @@
</div>
</div>
<script type="text/javascript">
- newIsolatedGadget('attackScript');
- inlineHtml('script-injection.co.html',
- document.getElementById('base-attackScript'));
+ newIsolatedGadget('attackScript', 'script-injection');
</script>

<div class="vbox">
=======================================
--- /trunk/src/com/google/caja/opensocial/DefaultGadgetRewriter.java Fri
Nov 13 11:43:08 2009
+++ /trunk/src/com/google/caja/opensocial/DefaultGadgetRewriter.java Fri
Nov 13 13:37:15 2009
@@ -62,7 +62,6 @@
private CssSchema cssSchema;
private HtmlSchema htmlSchema;
private boolean debugMode;
- private boolean valijaMode;

public DefaultGadgetRewriter(BuildInfo buildInfo, MessageQueue mq) {
this.buildInfo = buildInfo;
@@ -83,13 +82,6 @@
* @param debugMode whether to include debugging info in cajoled output.
*/
public void setDebugMode(boolean debugMode) { this.debugMode =
debugMode; }
-
- /**
- * @param valijaMode whether to treat the source as valija.
- */
- public void setValijaMode(boolean valijaMode) {
- this.valijaMode = valijaMode;
- }

public void rewrite(ExternalReference gadgetRef, UriCallback uriCallback,
String view, Appendable output)
@@ -234,7 +226,6 @@
}
});
meta.setDebugMode(debugMode);
- meta.setValijaMode(valijaMode);

PluginCompiler compiler = createPluginCompiler(meta, mq);

=======================================
--- /trunk/src/com/google/caja/opensocial/GadgetRewriterMain.java Fri Jun
19 12:47:27 2009
+++ /trunk/src/com/google/caja/opensocial/GadgetRewriterMain.java Fri Nov
13 13:37:15 2009
@@ -71,7 +71,6 @@
rewriter.setCssSchema(config.getCssSchema(mq));
rewriter.setHtmlSchema(config.getHtmlSchema(mq));
rewriter.setDebugMode(config.debugMode());
- rewriter.setValijaMode(true);

Writer w = new BufferedWriter(new FileWriter(config.getOutputBase()));
try {
=======================================
--- /trunk/src/com/google/caja/parser/js/Parser.java Mon Nov 2 13:56:19
2009
+++ /trunk/src/com/google/caja/parser/js/Parser.java Fri Nov 13 13:37:15
2009
@@ -33,6 +33,7 @@
import com.google.caja.reporting.MessageType;
import com.google.caja.reporting.RenderContext;
import com.google.caja.util.Pair;
+import com.google.caja.util.Lists;

import java.math.BigDecimal;
import java.util.ArrayList;
@@ -305,8 +306,8 @@
private Block parseProgramOrFunctionBody() throws ParseException {
Mark m = tq.mark();
List<Statement> stmts = new ArrayList<Statement>();
- UseSubsetDirective usd = parseOptionalUseSubsetDirective();
- if (usd != null) { stmts.add(usd); }
+ DirectivePrologue prologue = parseOptionalDirectivePrologue();
+ if (prologue != null) { stmts.add(prologue); }
while (!tq.isEmpty() && !tq.lookaheadToken(Punctuation.RCURLY)) {
stmts.add(parseTerminatedStatement());
}
@@ -315,38 +316,69 @@
return b;
}

- private UseSubsetDirective parseOptionalUseSubsetDirective()
+ private DirectivePrologue parseOptionalDirectivePrologue()
throws ParseException {
+ // Quick return if we are sure we will not accumulate anything
if (tq.isEmpty() || tq.peek().type != JsTokenType.STRING) { return
null; }
- Mark m = tq.mark();
- Token<JsTokenType> quotedString = tq.pop();
- if (!tq.checkToken(Punctuation.SEMI)) {
- tq.rewind(m);
- return null;
- }
- String decoded = StringLiteral.getUnquotedValueOf(quotedString.text);
- if (!(decoded.startsWith("use")
- && (decoded.length() == 3
- || JsLexer.isJsSpace(decoded.charAt(3))))) {
- tq.rewind(m);
- return null;
- }
-
- FilePosition quotedStringStart =
FilePosition.startOf(quotedString.pos);
- List<UseSubset> subsets = new ArrayList<UseSubset>();
- for (String subsetName : decoded.substring(3).split(",")) {
- String trimName = subsetName.trim();
- if (!("strict".equals(trimName) || "cajita".equals(trimName))) {
+
+ Mark startOfPrologue = tq.mark();
+ List<Directive> directives = Lists.newArrayList();
+
+ while (tq.peek().type == JsTokenType.STRING) {
+ Mark startOfDirective = tq.mark();
+ Token<JsTokenType> quotedString = tq.pop();
+
+ boolean isDirective = false;
+ switch(tq.peek().type) {
+ case STRING:
+ case REGEXP:
+ case WORD:
+ case INTEGER:
+ case FLOAT:
+ case KEYWORD:
+ case COMMENT:
+ isDirective = true;
+ mq.addMessage(
+ MessageType.SEMICOLON_INSERTED,
+ FilePosition.endOf(quotedString.pos));
+ break;
+ case PUNCTUATION:
+ if (tq.lookaheadToken(Punctuation.SEMI)) {
+ isDirective = true;
+ tq.pop();
+ } else if (tq.lookaheadToken(Punctuation.RCURLY)) {
+ isDirective = true;
+ mq.addMessage(
+ MessageType.SEMICOLON_INSERTED,
+ FilePosition.endOf(quotedString.pos));
+ }
+ break;
+ case LINE_CONTINUATION:
+ break;
+ }
+
+ if (!isDirective) {
+ tq.rewind(startOfDirective);
+ break;
+ }
+
+ String decoded = StringLiteral.getUnquotedValueOf(quotedString.text);
+ if (!Directive.RecognizedValue.isDirectiveStringRecognized(decoded))
{
mq.addMessage(
- MessageType.UNRECOGNIZED_USE_SUBSET,
- quotedString.pos, MessagePart.Factory.valueOf(trimName));
- }
- UseSubset us = new UseSubset(quotedStringStart, trimName);
- subsets.add(us);
- }
- UseSubsetDirective usd = new UseSubsetDirective(posFrom(m), subsets);
- finish(usd, m);
- return usd;
+ MessageType.UNRECOGNIZED_DIRECTIVE_IN_PROLOGUE,
+ quotedString.pos, MessagePart.Factory.valueOf(decoded));
+ }
+
+ directives.add(new Directive(
+ FilePosition.startOf(quotedString.pos), decoded));
+ }
+
+ if (directives.isEmpty()) { return null; }
+
+ DirectivePrologue prologue =
+ new DirectivePrologue(posFrom(startOfPrologue), directives);
+ finish(prologue, startOfPrologue);
+ return prologue;
}

private LabeledStatement parseLoopOrSwitch(FilePosition start, String
label)
=======================================
--- /trunk/src/com/google/caja/parser/quasiliteral/CajitaRewriter.java Mon
Nov 2 13:56:19 2009
+++ /trunk/src/com/google/caja/parser/quasiliteral/CajitaRewriter.java Fri
Nov 13 13:37:15 2009
@@ -57,7 +57,7 @@
import com.google.caja.parser.js.TranslatedCode;
import com.google.caja.parser.js.TryStmt;
import com.google.caja.parser.js.UncajoledModule;
-import com.google.caja.parser.js.UseSubsetDirective;
+import com.google.caja.parser.js.DirectivePrologue;
import com.google.caja.reporting.BuildInfo;
import com.google.caja.reporting.MessagePart;
import com.google.caja.reporting.MessageQueue;
@@ -2223,7 +2223,7 @@
matches="'use';",
substitutes=";")
public ParseTreeNode fire(ParseTreeNode node, Scope scope) {
- if (node instanceof UseSubsetDirective) {
+ if (node instanceof DirectivePrologue) {
return new Noop(node.getFilePosition());
}
return NONE;
=======================================
---
/trunk/src/com/google/caja/parser/quasiliteral/DefaultValijaRewriter.java
Thu Sep 10 18:33:03 2009
+++
/trunk/src/com/google/caja/parser/quasiliteral/DefaultValijaRewriter.java
Fri Nov 13 13:37:15 2009
@@ -221,9 +221,6 @@
ParseTreeNode arg = bindings.get("arg");
if (arg instanceof StringLiteral) {
String src = ((StringLiteral) arg).getUnquotedValue();
- if (!src.endsWith(".vo")) {
- src = src + ".vo";
- }
return substV("arg",
new StringLiteral(FilePosition.UNKNOWN, src));
} else {
@@ -251,10 +248,7 @@
ParseTreeNode arg = bindings.get("arg");
if (arg instanceof StringLiteral) {
String src = ((StringLiteral) arg).getUnquotedValue();
- if (!src.endsWith(".vo")) {
- src = src + ".vo";
- }
- return substV("arg",
+ return substV("arg",
new StringLiteral(FilePosition.UNKNOWN, src));
} else {
mq.addMessage(
=======================================
--- /trunk/src/com/google/caja/parser/quasiliteral/QuasiBuilder.java Fri
Dec 5 14:39:13 2008
+++ /trunk/src/com/google/caja/parser/quasiliteral/QuasiBuilder.java Fri
Nov 13 13:37:15 2009
@@ -35,7 +35,7 @@
import com.google.caja.parser.js.Statement;
import com.google.caja.parser.js.StringLiteral;
import com.google.caja.parser.js.SyntheticNodes;
-import com.google.caja.parser.js.UseSubsetDirective;
+import com.google.caja.parser.js.DirectivePrologue;
import com.google.caja.reporting.DevNullMessageQueue;

import java.io.StringReader;
@@ -249,8 +249,8 @@
}
}

- if (n instanceof UseSubsetDirective) {
- return buildUseSubsetQuasiNode(((UseSubsetDirective)
n).getSubsetNames());
+ if (n instanceof DirectivePrologue) {
+ return buildDirectivePrologueMatchNode(((DirectivePrologue)
n).getDirectives());
}

if (n instanceof StringLiteral) {
@@ -352,8 +352,8 @@
return new ObjectConstructorHole(keyExpr, valueExpr);
}

- private static QuasiNode buildUseSubsetQuasiNode(Set<String>
subsetNames) {
- return new UseSubsetQuasiNode(subsetNames);
+ private static QuasiNode buildDirectivePrologueMatchNode(Set<String>
subsetNames) {
+ return new DirectivePrologueQuasiNode(subsetNames);
}

private static QuasiNode[] buildChildrenOf(ParseTreeNode n) {
=======================================
--- /trunk/src/com/google/caja/plugin/BuildServiceImplementation.java Fri
Nov 13 11:43:08 2009
+++ /trunk/src/com/google/caja/plugin/BuildServiceImplementation.java Fri
Nov 13 13:37:15 2009
@@ -148,16 +148,10 @@
boolean passed = true;
ParseTreeNode outputJs;
Node outputHtml;
- if (!"javascript".equals(language)) {
+ if ("caja".equals(language)) {
PluginMeta meta = new PluginMeta(env);
meta.setDebugMode(Boolean.TRUE.equals(options.get("debug")));
- if ("valija".equals(language)) {
- meta.setValijaMode(true);
- } else if ("cajita".equals(language)) {
- meta.setValijaMode(false);
- } else {
- throw new RuntimeException("Unrecognized language: " + language);
- }
+
meta.setOnlyJsEmitted(Boolean.TRUE.equals(options.get("onlyJsEmitted")));
PluginCompiler compiler =
new PluginCompiler(BuildInfo.getInstance(), meta, mq);
compiler.setMessageContext(mc);
@@ -183,7 +177,7 @@

outputJs = passed ? compiler.getJavascript() : null;
outputHtml = passed ? compiler.getStaticHtml() : null;
- } else {
+ } else if ("javascript".equals(language)) {
passed = true;
JsOptimizer optimizer = new JsOptimizer(mq);
for (File f : inputs) {
@@ -204,6 +198,8 @@
}
outputJs = optimizer.optimize();
outputHtml = null;
+ } else {
+ throw new RuntimeException("Unrecognized language: " + language);
}
passed = passed && !hasErrors(mq);

=======================================
--- /trunk/src/com/google/caja/plugin/ExpressionSanitizerCaja.java Mon Aug
10 14:00:55 2009
+++ /trunk/src/com/google/caja/plugin/ExpressionSanitizerCaja.java Fri Nov
13 13:37:15 2009
@@ -32,26 +32,19 @@
public class ExpressionSanitizerCaja {
private final BuildInfo buildInfo;
private final MessageQueue mq;
- private final PluginMeta meta;

public ExpressionSanitizerCaja(BuildInfo buildInfo,
- MessageQueue mq,
- PluginMeta meta) {
+ MessageQueue mq) {
this.buildInfo = buildInfo;
this.mq = mq;
- this.meta = meta;
}

public ParseTreeNode sanitize(AncestorChain<?> toSanitize) {
MutableParseTreeNode input = (MutableParseTreeNode) toSanitize.node;
ParseTreeNode result;
- if (this.meta.isValijaMode()) {
- result = newValijaRewriter(this.mq).expand(input);
- if (!this.mq.hasMessageAtLevel(MessageLevel.ERROR)) {
- result = newCajitaRewriter(this.mq).expand(result);
- }
- } else {
- result = newCajitaRewriter(this.mq).expand(input);
+ result = newValijaRewriter(this.mq).expand(input);
+ if (!this.mq.hasMessageAtLevel(MessageLevel.ERROR)) {
+ result = newCajitaRewriter(this.mq).expand(result);
}
if (!this.mq.hasMessageAtLevel(MessageLevel.ERROR)) {
result = new IllegalReferenceCheckRewriter(this.mq,
false).expand(result);
=======================================
--- /trunk/src/com/google/caja/plugin/PluginCompilerMain.java Mon Nov 2
13:56:19 2009
+++ /trunk/src/com/google/caja/plugin/PluginCompilerMain.java Fri Nov 13
13:37:15 2009
@@ -111,7 +111,6 @@
try {
PluginMeta meta = new PluginMeta(makeEnvironment(config));
meta.setDebugMode(config.debugMode());
- meta.setValijaMode(true);
meta.setIdClass(config.getIdClass());
PluginCompiler compiler = new PluginCompiler(
BuildInfo.getInstance(), meta, mq);
=======================================
--- /trunk/src/com/google/caja/plugin/PluginMeta.java Tue Oct 27 15:38:50
2009
+++ /trunk/src/com/google/caja/plugin/PluginMeta.java Fri Nov 13 13:37:15
2009
@@ -26,8 +26,6 @@
private boolean debugMode;
/** True if the output should be *only* JS, not HTML+JS. */
private boolean onlyJsEmitted;
- /** True if the source should be treated as Valija */
- private boolean valijaMode;
/**
* The DOM ID suffix if known at Cajole time. Most clients should allow
the
* module ID to be assigned dynamically but for those clients who know
that
@@ -68,13 +66,6 @@
this.onlyJsEmitted = onlyJsEmitted;
}

- /** True if the source should be treated as Valija. */
- public boolean isValijaMode() { return valijaMode; }
-
- public void setValijaMode(boolean valijaMode) {
- this.valijaMode = valijaMode;
- }
-
/**
* Null if the module ID is not known statically.
* See {@code imports.getIdClass___()} defined in "domita.js".
=======================================
--- /trunk/src/com/google/caja/plugin/bridal.js Mon Oct 19 16:34:34 2009
+++ /trunk/src/com/google/caja/plugin/bridal.js Fri Nov 13 13:37:15 2009
@@ -21,7 +21,8 @@
* @author ihab...@gmail.com
* @author jas...@gmail.com
* @provides bridal
- * @requires ___, cajita, document, html, html4, navigator, window
+ * @requires ___, cajita, document, html, html4, navigator, window,
+ * XMLHttpRequest, ActiveXObject
*/

var bridal = (function() {
@@ -571,6 +572,26 @@
+ pseudoElement);
}
}
+
+ /**
+ * Returns a new XMLHttpRequest object, hiding browser differences in the
+ * method of construction.
+ */
+ function makeXhr() {
+ if (typeof XMLHttpRequest === 'undefined') {
+ var activeXClassIds = [
+ 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0',
+ 'MSXML2.XMLHTTP', 'MICROSOFT.XMLHTTP.1.0', 'MICROSOFT.XMLHTTP.1',
+ 'MICROSOFT.XMLHTTP'];
+ for (var i = 0, n = activeXClassIds.length; i < n; i++) {
+ var candidate = activeXClassIds[i];
+ try {
+ return new ActiveXObject(candidate);
+ } catch (e) {}
+ }
+ }
+ return new XMLHttpRequest;
+ }

return {
addEventListener: addEventListener,
@@ -586,6 +607,7 @@
getBoundingClientRect: getBoundingClientRect,
untameEventType: untameEventType,
extendedCreateElementFeature: featureExtendedCreateElement,
- getComputedStyle: getComputedStyle
+ getComputedStyle: getComputedStyle,
+ makeXhr: makeXhr
};
})();
=======================================
--- /trunk/src/com/google/caja/plugin/stages/ValidateJavascriptStage.java
Wed May 20 13:31:01 2009
+++ /trunk/src/com/google/caja/plugin/stages/ValidateJavascriptStage.java
Fri Nov 13 13:37:15 2009
@@ -50,7 +50,7 @@

if (nonSyntheticScopeRoot != null) { // False for empty programs
ParseTreeNode validated = new ExpressionSanitizerCaja(
- buildInfo, jobs.getMessageQueue(), jobs.getPluginMeta())
+ buildInfo, jobs.getMessageQueue())
.sanitize(nonSyntheticScopeRoot);
if (nonSyntheticScopeRoot.parent == null) {
it.set(new Job(AncestorChain.instance(validated)));
=======================================
--- /trunk/src/com/google/caja/reporting/MessageType.java Fri Nov 13
11:43:08 2009
+++ /trunk/src/com/google/caja/reporting/MessageType.java Fri Nov 13
13:37:15 2009
@@ -69,8 +69,9 @@
MISSING_ATTRIBUTE_VALUE(
"%s: missing value for attribute %s", MessageLevel.FATAL_ERROR),
OCTAL_LITERAL("%s: octal literal %s", MessageLevel.LINT),
- UNRECOGNIZED_USE_SUBSET(
- "%s: unrecognized subset name in 'use' clause: %s",
MessageLevel.WARNING),
+ UNRECOGNIZED_DIRECTIVE_IN_PROLOGUE(
+ "%s: unrecognized directive in prologue: %s",
+ MessageLevel.WARNING),
SKIPPING("%s: Skipping malformed content", MessageLevel.WARNING),
DUPLICATE_ATTRIBUTE(
"%s: attribute %s duplicates one at %s", MessageLevel.WARNING),
=======================================
--- /trunk/src/com/google/caja/service/CajolingService.java Mon Nov 2
13:56:19 2009
+++ /trunk/src/com/google/caja/service/CajolingService.java Fri Nov 13
13:37:15 2009
@@ -277,7 +277,6 @@

public static enum Transform {
INNOCENT,
- VALIJA,
- CAJITA;
+ CAJOLE;
}
}
=======================================
--- /trunk/src/com/google/caja/service/HtmlHandler.java Fri Nov 13 11:43:08
2009
+++ /trunk/src/com/google/caja/service/HtmlHandler.java Fri Nov 13 13:37:15
2009
@@ -65,7 +65,7 @@
private final BuildInfo buildInfo;
private final PluginEnvironment pluginEnvironment;
private final static String DEFAULT_HOSTED_SERVICE
- = "http://caja.appsport.com/cajoler";
+ = "http://caja.appspot.com/cajoler";

public HtmlHandler(BuildInfo buildInfo) {
this(buildInfo, DEFAULT_HOSTED_SERVICE, null);
@@ -127,8 +127,6 @@
OutputStream response)
throws UnsupportedContentTypeException {
PluginMeta meta = new PluginMeta(pluginEnvironment);
- // HtmlHandler only cajoles in valija mode
- meta.setValijaMode(true);
if (checker.check(outputContentType, "text/html")
|| checker.check(outputContentType, "*/*")) {
meta.setOnlyJsEmitted(false);
=======================================
--- /trunk/src/com/google/caja/service/JsHandler.java Fri Nov 13 11:43:08
2009
+++ /trunk/src/com/google/caja/service/JsHandler.java Fri Nov 13 13:37:15
2009
@@ -60,8 +60,7 @@
return checker.check("text/javascript", inputContentType)
&& checker.check(outputContentType, "text/javascript")
&& (transform == null
- || transform.equals(CajolingService.Transform.CAJITA)
- || transform.equals(CajolingService.Transform.VALIJA));
+ || transform.equals(CajolingService.Transform.CAJOLE));
}

public Pair<String,String> apply(URI uri,
@@ -84,9 +83,8 @@

try {
OutputStreamWriter writer = new
OutputStreamWriter(response, "UTF-8");
- boolean valijaMode =
CajolingService.Transform.VALIJA.equals(transform);
cajoleJs(uri, new StringReader(new String(content, charset)),
- moduleCallback, valijaMode, writer);
+ moduleCallback, writer);
writer.flush();
} catch (IOException e) {
throw new UnsupportedContentTypeException();
@@ -97,7 +95,6 @@
private void cajoleJs(URI inputUri,
Reader cajaInput,
Expression moduleCallback,
- boolean valijaMode,
Appendable output)
throws IOException, UnsupportedContentTypeException {
InputSource is = new InputSource (inputUri);
@@ -111,10 +108,9 @@
Rewriter vrw = new DefaultValijaRewriter(mq, false /* logging */);
Rewriter crw = new CajitaRewriter(buildInfo, mq, false /* logging
*/);
UncajoledModule ucm = new UncajoledModule(input);
- CajoledModule cm = (CajoledModule) (valijaMode
- ? crw.expand(vrw.expand(ucm))
- : crw.expand(ucm));
- output.append(renderJavascript(cm, moduleCallback));
+ output.append(renderJavascript(
+ (CajoledModule) crw.expand(vrw.expand(ucm)),
+ moduleCallback));
} catch (ParseException e) {
throw new UnsupportedContentTypeException();
} catch (IllegalArgumentException e) {
=======================================
--- /trunk/src/com/google/caja/tools/TransformAntTask.java Thu Nov 12
12:53:32 2009
+++ /trunk/src/com/google/caja/tools/TransformAntTask.java Fri Nov 13
13:37:15 2009
@@ -79,7 +79,7 @@
}

public class TranslateTaskOutput extends Output {
- private boolean debug, rename;
+ private boolean debug, rename, onlyJsEmitted;
private String language;
private String renderer = "pretty";
private Set<String> messagesToIgnore = Sets.newHashSet();
@@ -92,12 +92,16 @@
options.put("renderer", renderer);
options.put("toIgnore", messagesToIgnore);
options.put("rename", rename);
+ options.put("onlyJsEmitted", onlyJsEmitted);
return options;
}

// Invoked reflectively by ANT.
public void setDebug(boolean debug) { this.debug = debug; }
public void setRename(boolean rename) { this.rename = rename; }
+ public void setOnlyJsEmitted(boolean onlyJsEmitted) {
+ this.onlyJsEmitted = onlyJsEmitted;
+ }
public void setLanguage(String language) { this.language = language; }
public void setRenderer(String renderer) { this.renderer = renderer; }
public void setIgnore(String messageTypeNames) {
=======================================
--- /trunk/src/com/google/caja/valija-cajita.js Thu Oct 15 15:42:13 2009
+++ /trunk/src/com/google/caja/valija-cajita.js Fri Nov 13 13:37:15 2009
@@ -52,10 +52,13 @@
* not cajoled.
*
* @author eri...@gmail.com
- * @requires cajita, loader
+ * @requires cajita, loader, outers
* @provides valijaMaker
*/

+'use strict';
+'use cajita';
+
var valijaMaker = (function(outers) {

/**
@@ -513,3 +516,11 @@
if (typeof loader !== 'undefined') {
loader.provide(valijaMaker);
}
+
+// If the Valija module is called with the new-style Cajita module
convention,
+// passing an 'outers' as a Cajita-level parameter, the value returned from
+// instantiating the module should be the fully constructed '$v' object,
not
+// just valijaMaker.
+if (typeof outers !== 'undefined') {
+ valijaMaker(outers);
+}
=======================================
--- /trunk/tests/com/google/caja/a.js Thu Sep 10 18:33:03 2009
+++ /trunk/tests/com/google/caja/a.js Fri Nov 13 13:37:15 2009
@@ -12,9 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

+'use strict';
+'use cajita';
+
/**
* @author maoz...@gmail.com
*
* A test file for module loading in Cajita
*/
-x + y
+x + y;
=======================================
--- /trunk/tests/com/google/caja/c.js Thu Sep 10 18:33:03 2009
+++ /trunk/tests/com/google/caja/c.js Fri Nov 13 13:37:15 2009
@@ -12,9 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

+'use strict';
+'use cajita';
+
/**
* @author maoz...@gmail.com
*
* A test file for module loading in Cajita
*/
-x + 1
+x + 1;
=======================================
--- /trunk/tests/com/google/caja/commonJsRecursion.js Thu Sep 10 18:33:03
2009
+++ /trunk/tests/com/google/caja/commonJsRecursion.js Fri Nov 13 13:37:15
2009
@@ -21,7 +21,7 @@
if (a < 0) { return true; } else { return false; }
};
exports.isNonNegative = function (a) {
- var m = require.async('./commonJsRecursion.vo');
+ var m = require.async('./commonJsRecursion');
var r = env.Q.defer();
env.Q.when(m, function(module) { r.resolve(!module.isNegative(a)); },
function(reason) { r.resolve(env.Q.reject(reason)); });
=======================================
--- /trunk/tests/com/google/caja/demos/applet/CajaAppletTest.java Thu Jul
30 19:46:50 2009
+++ /trunk/tests/com/google/caja/demos/applet/CajaAppletTest.java Fri Nov
13 13:37:15 2009
@@ -49,17 +49,6 @@
CajaApplet applet = makeApplet();
assertEquals(
TestUtil.readResource(getClass(), "caja-applet-valija-golden.js"),
- applet.cajole(
- "Howdy<script>alert(2 + 2);</script>There",
- CajaApplet.Feature.VALIJA_MODE.name())
- .replace("\\n", "\n"));
- }
-
- public final void testCajoleInCajita() throws Exception {
- if (checkHeadless()) return;
- CajaApplet applet = makeApplet();
- assertEquals(
- TestUtil.readResource(getClass(), "caja-applet-cajita-golden.js"),
applet.cajole("Howdy<script>alert(2 + 2);</script>There", "")
.replace("\\n", "\n"));
}
=======================================
--- /trunk/tests/com/google/caja/demos/benchmarks/BenchmarkRunner.java Wed
Oct 21 11:42:18 2009
+++ /trunk/tests/com/google/caja/demos/benchmarks/BenchmarkRunner.java Fri
Nov 13 13:37:15 2009
@@ -132,12 +132,13 @@
boolean wrapGlobals) throws Exception {
PluginMeta meta = new PluginMeta();
MessageQueue mq = new SimpleMessageQueue();
- meta.setValijaMode(valija);
PluginCompiler pc = new PluginCompiler(new TestBuildInfo(), meta, mq);
CharProducer src = wrapGlobals ?
fromString(wrapGlobals(plain(fromResource(filename)))):
fromString(plain(fromResource(filename)));
- pc.addInput(AncestorChain.instance(js(src)));
+ pc.addInput(AncestorChain.instance(valija
+ ? BenchmarkUtils.addUseCajitaDirective(js(src))
+ : js(src)));
if (!pc.run()) {
return -1;
}
@@ -159,7 +160,7 @@
+ "testImports.outers = ___.copy(___.sharedImports);\n"
+ "___.getNewModuleHandler().setImports(testImports);",
getName() + "valija-setup"),
- new Executor.Input(getClass(), "../../plugin/valija.co.js"),
+ new Executor.Input(getClass(), "../../plugin/valija.out.js"),
new Executor.Input(
// Set up the imports environment.
""
=======================================
--- /trunk/tests/com/google/caja/demos/benchmarks/BenchmarkSize.java Wed
Aug 26 18:37:38 2009
+++ /trunk/tests/com/google/caja/demos/benchmarks/BenchmarkSize.java Fri
Nov 13 13:37:15 2009
@@ -60,13 +60,13 @@
public final void testOverhead() throws IOException {
varzOverhead("valija", "minify", "plain",

size(charset(plain(fromResource("../../plugin/domita-minified.js")))) +
- size(charset(plain(fromResource("../../plugin/valija.co.js")))) +
+ size(charset(plain(fromResource("../../plugin/valija.out.js")))) +
size(charset(plain(
fromResource("../../plugin/html-sanitizer-minified.js")))));
varzOverhead("valija", "minify", "gzip",
size(gzip(charset(plain(
fromResource("../../plugin/domita-minified.js"))))) +
-
size(gzip(charset(plain(fromResource("../../plugin/valija.co.js"))))) +
+
size(gzip(charset(plain(fromResource("../../plugin/valija.out.js"))))) +
size(gzip(charset(plain(
fromResource("../../plugin/html-sanitizer-minified.js"))))));

@@ -174,7 +174,7 @@
}
PluginMeta meta = new PluginMeta();
MessageQueue mq = TestUtil.createTestMessageQueue(this.mc);
- meta.setValijaMode(valija);
+ if (!valija) { js = BenchmarkUtils.addUseCajitaDirective(js); }
PluginCompiler pc = new PluginCompiler(new TestBuildInfo(), meta, mq);
pc.addInput(AncestorChain.instance(js));
if (pc.run()) {
=======================================
--- /trunk/tests/com/google/caja/foo/b.js Thu Sep 10 18:33:03 2009
+++ /trunk/tests/com/google/caja/foo/b.js Fri Nov 13 13:37:15 2009
@@ -12,12 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

+'use strict';
+'use cajita';
+
/**
* @author maoz...@gmail.com
*
* A test file for asynchronous module loading in Cajita
*/
-var m = load.async('../c.co');
+var m = load.async('../c');
var f1 = function(module) {
var r1 = module({x: x});
var r2 = module({x: y});
=======================================
--- /trunk/tests/com/google/caja/foo/f.js Thu Sep 10 18:33:03 2009
+++ /trunk/tests/com/google/caja/foo/f.js Fri Nov 13 13:37:15 2009
@@ -12,10 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

+'use strict';
+'use cajita';
+
/**
* @author maoz...@gmail.com
*
* A test file for unbundled synchronous module loading in Cajita
*/
-var m = load('../c.co');
+var m = load('../c');
m({x: x}) + m({x: y});
=======================================
***Additional files exist in this changeset.***
Reply all
Reply to author
Forward
0 new messages