Permalink
Browse files

Finished deprecating html.escapeHTML, and finished the command line o…

…ption for optimization level.
  • Loading branch information...
1 parent 078f9d3 commit 59455f0a25fccb7796f181eb9a24346ea263c191 @kriskowal kriskowal committed Mar 1, 2010
Showing with 46 additions and 28 deletions.
  1. +8 −7 engines/rhino/bootstrap.js
  2. +26 −20 lib/html.js
  3. +8 −1 lib/narwhal.js
  4. +4 −0 narwhal.js
View
@@ -13,13 +13,13 @@
/* this gets used for several fixtures */
var context = Packages.org.mozilla.javascript.Context.getCurrentContext();
- // TODO: enable this via a command line switch
-// context.setOptimizationLevel(-1);
-
-
+ var setOptimizationLevel = function (n) {
+ context.setOptimizationLevel(Number(n));
+ };
+
context.setLanguageVersion(180);
context.getWrapFactory().setJavaPrimitiveWrap(false);
-
+
var prefix = "";
if (typeof NARWHAL_HOME != "undefined") {
prefix = NARWHAL_HOME;
@@ -108,7 +108,8 @@
prefix: prefix,
evaluate: evaluate,
debug: debug,
- verbose: verbose
+ verbose: verbose,
+ setOptimizationLevel: setOptimizationLevel
},
file: {
read: read,
@@ -123,7 +124,7 @@
print(e);
Packages.java.lang.System.exit(1);
}
-
+
})(this, function () {
return eval(arguments[0]);
});
View
@@ -2,31 +2,37 @@
// -- gmosx George Moschovitis
/**
- * Escape HTML characters.
- * TODO: Deprecate escapeHTML() in favor of escape()
+ * Escape significant HTML characters as HTML entities.
*/
-exports.escape = exports.escapeHTML = function(str) {
- if (str) {
- return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
- } else {
- return "";
- }
-}
-
+exports.escape = exports.escapeHTML = function(string) {
+ return String(string)
+ .replace(/&/g, "&amp;")
+ .replace(/</g, "&lt;")
+ .replace(/>/g, "&gt;");
+};
+
/**
- * Unescape HTML characters.
+ * Translate basic HTML entities for ampersand, less-than,
+ * and greater-than to their respective plain characters.
*/
-exports.unescape = function(str) {
- if (str) {
- return str.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">");
- } else {
- return "";
- }
-}
-
+exports.unescape = function(string) {
+ return String(string)
+ .replace(/&amp;/g, "&")
+ .replace(/&lt;/g, "<")
+ .replace(/&gt;/g, ">");
+};
+
/**
* Strip HTML tags.
*/
exports.stripTags = function (str) {
- return str.replace(/<([^>]+)>/g, "");
+ return str.replace(/<([^>]+)>/g, "");
}
+
+// deprecated
+
+exports.escapeHTML = function (str) {
+ require("narwhal").deprecation("html.escapeHTML is deprecated.");
+ return exports.escape(str);
+};
+
View
@@ -92,7 +92,14 @@ parser.option('--no-term')
require("term").stream.disable();
});
-parser.option('-O', 'optimize').inc().hidden();
+if (system.setOptimizationLevel) {
+ parser.option('-O', 'optimize')
+ .help("increase the optimization level (stacks \0bold(\0green(-OO\0)\0))")
+ .inc();
+ parser.option('-o', 'optimize')
+ .help("decrease the optimization level (stacks \0bold(\0green(-oo\0)\0))")
+ .dec();
+}
parser.option('--narwhal')
.def('left')
View
@@ -155,6 +155,10 @@ if (options.verbose !== undefined) {
require.verbose = system.verbose;
}
+// if the engine provides an optimization level, like Rhino, call it through.
+if (system.setOptimizationLevel)
+ system.setOptimizationLevel(options.optimize);
+
if (deprecated) {
if (options.verbose) {
system.print(

0 comments on commit 59455f0

Please sign in to comment.