Skip to content

Commit

Permalink
Finished deprecating html.escapeHTML, and finished the command line o…
Browse files Browse the repository at this point in the history
…ption for optimization level.
  • Loading branch information
kriskowal committed Mar 1, 2010
1 parent 078f9d3 commit 59455f0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 28 deletions.
15 changes: 8 additions & 7 deletions engines/rhino/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -108,7 +108,8 @@
prefix: prefix,
evaluate: evaluate,
debug: debug,
verbose: verbose
verbose: verbose,
setOptimizationLevel: setOptimizationLevel
},
file: {
read: read,
Expand All @@ -123,7 +124,7 @@
print(e);
Packages.java.lang.System.exit(1);
}

})(this, function () {
return eval(arguments[0]);
});
46 changes: 26 additions & 20 deletions lib/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

9 changes: 8 additions & 1 deletion lib/narwhal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 4 additions & 0 deletions narwhal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 59455f0

Please sign in to comment.