Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(514)

Unified Diff: src/json.js

Issue 5443001: Move quoting of a JSON string to a specialized runtime function. (Closed)
Patch Set: Remove TODO, add counters to track behavior. Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/runtime.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/json.js
diff --git a/src/json.js b/src/json.js
index 5993100f5395a336b36089231e3e16344bd46bd2..feeedda76ef6f76d4ea30e3f5ed68f6a98430620 100644
--- a/src/json.js
+++ b/src/json.js
@@ -66,34 +66,10 @@ function JSONParse(text, reviver) {
}
}
-var characterQuoteCache = {
- '\b': '\\b', // ASCII 8, Backspace
- '\t': '\\t', // ASCII 9, Tab
- '\n': '\\n', // ASCII 10, Newline
- '\f': '\\f', // ASCII 12, Formfeed
- '\r': '\\r', // ASCII 13, Carriage Return
- '\"': '\\"',
- '\\': '\\\\'
-};
-
-function QuoteSingleJSONCharacter(c) {
- if (c in characterQuoteCache) {
- return characterQuoteCache[c];
- }
- var charCode = c.charCodeAt(0);
- var result;
- if (charCode < 16) result = '\\u000';
- else if (charCode < 256) result = '\\u00';
- else if (charCode < 4096) result = '\\u0';
- else result = '\\u';
- result += charCode.toString(16);
- characterQuoteCache[c] = result;
- return result;
-}
-
function QuoteJSONString(str) {
- var quotable = /[\\\"\x00-\x1f]/g;
- return '"' + str.replace(quotable, QuoteSingleJSONCharacter) + '"';
+ var quoted_str = %QuoteJSONString(str);
+ if (IS_STRING(quoted_str)) return quoted_str;
+ return '"' + str + '"';
}
function StackContains(stack, val) {
« no previous file with comments | « no previous file | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698