Last active
November 2, 2015 05:24
-
-
Save oxyc/6d02b15b745638805afd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/json3.js b/lib/json3.js | |
index 4535232..291b6b7 100644 | |
--- a/lib/json3.js | |
+++ b/lib/json3.js | |
@@ -647,15 +647,13 @@ | |
charCode = source.charCodeAt(++Index); | |
switch (charCode) { | |
case 92: case 34: case 47: case 98: case 116: case 110: case 102: case 114: | |
- // Revive escaped control characters. | |
- value += Unescapes[charCode]; | |
Index++; | |
break; | |
case 117: | |
// `\u` marks the beginning of a Unicode escape sequence. | |
// Advance to the first character and validate the | |
// four-digit code point. | |
- begin = ++Index; | |
+ Index++; | |
for (position = Index + 4; Index < position; Index++) { | |
charCode = source.charCodeAt(Index); | |
// A valid sequence comprises four hexdigits (case- | |
@@ -665,8 +663,6 @@ | |
abort(); | |
} | |
} | |
- // Revive the escaped character. | |
- value += fromCharCode("0x" + source.slice(begin, Index)); | |
break; | |
default: | |
// Invalid escape sequence. | |
@@ -679,13 +675,10 @@ | |
break; | |
} | |
charCode = source.charCodeAt(Index); | |
- begin = Index; | |
// Optimize for the common case where a string is valid. | |
while (charCode >= 32 && charCode != 92 && charCode != 34) { | |
charCode = source.charCodeAt(++Index); | |
} | |
- // Append the string as-is. | |
- value += source.slice(begin, Index); | |
} | |
} | |
if (source.charCodeAt(Index) == 34) { | |
@@ -697,7 +690,6 @@ | |
abort(); | |
default: | |
// Parse numbers and literals. | |
- begin = Index; | |
// Advance past the negative sign, if one is specified. | |
if (charCode == 45) { | |
isSigned = true; | |
@@ -743,8 +735,7 @@ | |
} | |
Index = position; | |
} | |
- // Coerce the parsed value to a JavaScript number. | |
- return +source.slice(begin, Index); | |
+ return; | |
} | |
// A negative sign may only precede numbers. | |
if (isSigned) { | |
@@ -754,13 +745,15 @@ | |
var temp = source.slice(Index, Index + 4); | |
if (temp == "true") { | |
Index += 4; | |
- return true; | |
+ return; | |
+ | |
} else if (temp == "fals" && source.charCodeAt(Index + 4 ) == 101) { | |
Index += 5; | |
- return false; | |
+ return; | |
+ | |
} else if (temp == "null") { | |
Index += 4; | |
- return null; | |
+ return; | |
} | |
// Unrecognized token. | |
abort(); | |
@@ -781,12 +774,11 @@ | |
if (typeof value == "string") { | |
if ((charIndexBuggy ? value.charAt(0) : value[0]) == "@") { | |
// Remove the sentinel `@` character. | |
- return value.slice(1); | |
+ return; | |
} | |
// Parse object and array literals. | |
if (value == "[") { | |
// Parses a JSON array, returning a new JavaScript array. | |
- results = []; | |
for (;;) { | |
value = lex(); | |
// A closing square bracket marks the end of the array literal. | |
@@ -814,12 +806,11 @@ | |
if (value == ",") { | |
abort(); | |
} | |
- results.push(get(value)); | |
+ get(value); | |
} | |
- return results; | |
+ return; | |
} else if (value == "{") { | |
// Parses a JSON object, returning a new JavaScript object. | |
- results = {}; | |
for (;;) { | |
value = lex(); | |
// A closing curly brace marks the end of the object literal. | |
@@ -848,14 +839,14 @@ | |
if (value == "," || typeof value != "string" || (charIndexBuggy ? value.charAt(0) : value[0]) != "@" || lex() != ":") { | |
abort(); | |
} | |
- results[value.slice(1)] = get(lex()); | |
+ get(lex()); | |
} | |
- return results; | |
+ return; | |
} | |
// Unexpected token encountered. | |
abort(); | |
} | |
- return value; | |
+ return; | |
}; | |
// Internal: Updates a traversed object member. | |
@@ -892,12 +883,13 @@ | |
exports.parse = function (source, callback) { | |
var result, value; | |
Index = 0; | |
- Source = new String(source); | |
- result = get(lex()); | |
+ Source = "" + source; | |
+ get(lex()); | |
// If a JSON string contains multiple tokens, it is invalid. | |
if (lex() != "$") { | |
abort(); | |
} | |
+ result = eval('(' + source + ')'); | |
// Reset the parser state. | |
Index = Source = null; | |
return callback && getClass.call(callback) == functionClass ? walk((value = {}, value[""] = result, value), "", callback) : result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment