(value)
| 2681 | |
| 2682 | // Internal: Parses a JSON `value` token. |
| 2683 | var get = function (value) { |
| 2684 | var results, hasMembers; |
| 2685 | if (value == "$") { |
| 2686 | // Unexpected end of input. |
| 2687 | abort(); |
| 2688 | } |
| 2689 | if (typeof value == "string") { |
| 2690 | if ((charIndexBuggy ? value.charAt(0) : value[0]) == "@") { |
| 2691 | // Remove the sentinel `@` character. |
| 2692 | return value.slice(1); |
| 2693 | } |
| 2694 | // Parse object and array literals. |
| 2695 | if (value == "[") { |
| 2696 | // Parses a JSON array, returning a new JavaScript array. |
| 2697 | results = []; |
| 2698 | for (;; hasMembers || (hasMembers = true)) { |
| 2699 | value = lex(); |
| 2700 | // A closing square bracket marks the end of the array literal. |
| 2701 | if (value == "]") { |
| 2702 | break; |
| 2703 | } |
| 2704 | // If the array literal contains elements, the current token |
| 2705 | // should be a comma separating the previous element from the |
| 2706 | // next. |
| 2707 | if (hasMembers) { |
| 2708 | if (value == ",") { |
| 2709 | value = lex(); |
| 2710 | if (value == "]") { |
| 2711 | // Unexpected trailing `,` in array literal. |
| 2712 | abort(); |
| 2713 | } |
| 2714 | } else { |
| 2715 | // A `,` must separate each array element. |
| 2716 | abort(); |
| 2717 | } |
| 2718 | } |
| 2719 | // Elisions and leading commas are not permitted. |
| 2720 | if (value == ",") { |
| 2721 | abort(); |
| 2722 | } |
| 2723 | results.push(get(value)); |
| 2724 | } |
| 2725 | return results; |
| 2726 | } else if (value == "{") { |
| 2727 | // Parses a JSON object, returning a new JavaScript object. |
| 2728 | results = {}; |
| 2729 | for (;; hasMembers || (hasMembers = true)) { |
| 2730 | value = lex(); |
| 2731 | // A closing curly brace marks the end of the object literal. |
| 2732 | if (value == "}") { |
| 2733 | break; |
| 2734 | } |
| 2735 | // If the object literal contains members, the current token |
| 2736 | // should be a comma separator. |
| 2737 | if (hasMembers) { |
| 2738 | if (value == ",") { |
| 2739 | value = lex(); |
| 2740 | if (value == "}") { |
no test coverage detected