nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/JSONParser.java
author hannesw
Thu, 05 Feb 2015 16:26:36 +0100
changeset 28788 51c662748340
parent 28786 679fd2d26470
child 29405 e4f80bdb9141
permissions -rw-r--r--
8072626: Test for JDK-8068872 fails in tip Reviewed-by: lagergren, jlaskey
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     1
/*
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
     2
 * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     4
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    10
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    15
 * accompanied this code).
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    16
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    20
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    23
 * questions.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    24
 */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    25
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    26
package jdk.nashorn.internal.parser;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    27
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    28
import java.util.ArrayList;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    29
import java.util.List;
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    30
import jdk.nashorn.internal.codegen.ObjectClassGenerator;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    31
import jdk.nashorn.internal.objects.Global;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    32
import jdk.nashorn.internal.runtime.ECMAErrors;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    33
import jdk.nashorn.internal.runtime.ErrorManager;
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    34
import jdk.nashorn.internal.runtime.JSErrorType;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    35
import jdk.nashorn.internal.runtime.JSType;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    36
import jdk.nashorn.internal.runtime.ParserException;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    37
import jdk.nashorn.internal.runtime.Property;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    38
import jdk.nashorn.internal.runtime.PropertyMap;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    39
import jdk.nashorn.internal.runtime.ScriptObject;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    40
import jdk.nashorn.internal.runtime.Source;
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    41
import jdk.nashorn.internal.runtime.SpillProperty;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    42
import jdk.nashorn.internal.runtime.arrays.ArrayData;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    43
import jdk.nashorn.internal.runtime.arrays.ArrayIndex;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    44
import jdk.nashorn.internal.scripts.JO;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    45
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    46
import static jdk.nashorn.internal.parser.TokenType.STRING;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    47
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    48
/**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    49
 * Parses JSON text and returns the corresponding IR node. This is derived from the objectLiteral production of the main parser.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    50
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    51
 * See: 15.12.1.2 The JSON Syntactic Grammar
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    52
 */
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    53
public class JSONParser {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    54
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    55
    final private String source;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    56
    final private Global global;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    57
    final int length;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    58
    int pos = 0;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    59
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    60
    private static PropertyMap EMPTY_MAP = PropertyMap.newMap();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    61
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    62
    private static final int EOF = -1;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    63
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    64
    private static final String TRUE  = "true";
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    65
    private static final String FALSE = "false";
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    66
    private static final String NULL  = "null";
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    67
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    68
    private static final int STATE_EMPTY          = 0;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    69
    private static final int STATE_ELEMENT_PARSED = 1;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    70
    private static final int STATE_COMMA_PARSED   = 2;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    71
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    72
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    73
     * Constructor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    74
     * @param source  the source
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    75
     * @param global the global object
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    76
     */
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    77
    public JSONParser(final String source, final Global global ) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    78
        this.source = source;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    79
        this.global = global;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
    80
        this.length = source.length();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    81
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    82
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    83
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    84
     * Implementation of the Quote(value) operation as defined in the ECMA script spec
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    85
     * It wraps a String value in double quotes and escapes characters within in
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    86
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    87
     * @param value string to quote
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    88
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    89
     * @return quoted and escaped string
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    90
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    91
    public static String quote(final String value) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    92
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    93
        final StringBuilder product = new StringBuilder();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    94
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    95
        product.append("\"");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    96
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    97
        for (final char ch : value.toCharArray()) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    98
            // TODO: should use a table?
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    99
            switch (ch) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   100
            case '\\':
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   101
                product.append("\\\\");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   102
                break;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   103
            case '"':
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   104
                product.append("\\\"");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   105
                break;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   106
            case '\b':
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   107
                product.append("\\b");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   108
                break;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   109
            case '\f':
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   110
                product.append("\\f");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   111
                break;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   112
            case '\n':
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   113
                product.append("\\n");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   114
                break;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   115
            case '\r':
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   116
                product.append("\\r");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   117
                break;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   118
            case '\t':
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   119
                product.append("\\t");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   120
                break;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   121
            default:
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   122
                if (ch < ' ') {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   123
                    product.append(Lexer.unicodeEscape(ch));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   124
                    break;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   125
                }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   126
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   127
                product.append(ch);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   128
                break;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   129
            }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   130
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   131
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   132
        product.append("\"");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   133
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   134
        return product.toString();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   135
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   136
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   137
    /**
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   138
     * Public parse method. Parse a string into a JSON object.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   139
     *
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   140
     * @return the parsed JSON Object
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   141
     */
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   142
    public Object parse() {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   143
        final Object value = parseLiteral();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   144
        skipWhiteSpace();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   145
        if (pos < length) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   146
            throw expectedError(pos, "eof", toString(peek()));
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   147
        }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   148
        return value;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   149
    }
18317
2f5434c9c9fd 8015346: JSON parsing issues with escaped strings, octal, decimal numbers
sundar
parents: 17981
diff changeset
   150
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   151
    private Object parseLiteral() {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   152
        skipWhiteSpace();
18317
2f5434c9c9fd 8015346: JSON parsing issues with escaped strings, octal, decimal numbers
sundar
parents: 17981
diff changeset
   153
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   154
        final int c = peek();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   155
        if (c == EOF) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   156
            throw expectedError(pos, "json literal", "eof");
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   157
        }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   158
        switch (c) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   159
        case '{':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   160
            return parseObject();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   161
        case '[':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   162
            return parseArray();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   163
        case '"':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   164
            return parseString();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   165
        case 'f':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   166
            return parseKeyword(FALSE, Boolean.FALSE);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   167
        case 't':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   168
            return parseKeyword(TRUE, Boolean.TRUE);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   169
        case 'n':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   170
            return parseKeyword(NULL, null);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   171
        default:
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   172
            if (isDigit(c) || c == '-') {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   173
                return parseNumber();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   174
            } else if (c == '.') {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   175
                throw numberError(pos);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   176
            } else {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   177
                throw expectedError(pos, "json literal", toString(c));
18317
2f5434c9c9fd 8015346: JSON parsing issues with escaped strings, octal, decimal numbers
sundar
parents: 17981
diff changeset
   178
            }
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   179
        }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   180
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   181
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   182
    private Object parseObject() {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   183
        PropertyMap propertyMap = EMPTY_MAP;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   184
        ArrayData arrayData = ArrayData.EMPTY_ARRAY;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   185
        final ArrayList<Object> values = new ArrayList<>();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   186
        int state = STATE_EMPTY;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   187
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   188
        assert peek() == '{';
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   189
        pos++;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   190
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   191
        while (pos < length) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   192
            skipWhiteSpace();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   193
            final int c = peek();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   194
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   195
            switch (c) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   196
            case '"':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   197
                if (state == STATE_ELEMENT_PARSED) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   198
                    throw expectedError(pos - 1, ", or }", toString(c));
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   199
                }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   200
                final String id = parseString();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   201
                expectColon();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   202
                final Object value = parseLiteral();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   203
                final int index = ArrayIndex.getArrayIndex(id);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   204
                if (ArrayIndex.isValidArrayIndex(index)) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   205
                    arrayData = addArrayElement(arrayData, index, value);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   206
                } else {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   207
                    propertyMap = addObjectProperty(propertyMap, values, id, value);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   208
                }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   209
                state = STATE_ELEMENT_PARSED;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   210
                break;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   211
            case ',':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   212
                if (state != STATE_ELEMENT_PARSED) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   213
                    throw error(AbstractParser.message("trailing.comma.in.json"), pos);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   214
                }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   215
                state = STATE_COMMA_PARSED;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   216
                pos++;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   217
                break;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   218
            case '}':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   219
                if (state == STATE_COMMA_PARSED) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   220
                    throw error(AbstractParser.message("trailing.comma.in.json"), pos);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   221
                }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   222
                pos++;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   223
                return createObject(propertyMap, values, arrayData);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   224
            default:
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   225
                throw expectedError(pos, ", or }", toString(c));
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   226
            }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   227
        }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   228
        throw expectedError(pos, ", or }", "eof");
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   229
    }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   230
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   231
    private static ArrayData addArrayElement(final ArrayData arrayData, final int index, final Object value) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   232
        final long oldLength = arrayData.length();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   233
        final long longIndex = ArrayIndex.toLongIndex(index);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   234
        ArrayData newArrayData = arrayData;
28788
51c662748340 8072626: Test for JDK-8068872 fails in tip
hannesw
parents: 28786
diff changeset
   235
        if (longIndex >= oldLength) {
51c662748340 8072626: Test for JDK-8068872 fails in tip
hannesw
parents: 28786
diff changeset
   236
            newArrayData = newArrayData.ensure(longIndex);
51c662748340 8072626: Test for JDK-8068872 fails in tip
hannesw
parents: 28786
diff changeset
   237
            if (longIndex > oldLength) {
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   238
                newArrayData = newArrayData.delete(oldLength, longIndex - 1);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   239
            }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   240
        }
28788
51c662748340 8072626: Test for JDK-8068872 fails in tip
hannesw
parents: 28786
diff changeset
   241
        return newArrayData.set(index, value, false);
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   242
    }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   243
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   244
    private static PropertyMap addObjectProperty(final PropertyMap propertyMap, final List<Object> values,
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   245
                                                 final String id, final Object value) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   246
        final Property oldProperty = propertyMap.findProperty(id);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   247
        final Property newProperty;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   248
        final PropertyMap newMap;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   249
        final Class<?> type = ObjectClassGenerator.OBJECT_FIELDS_ONLY ? Object.class : getType(value);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   250
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   251
        if (oldProperty != null) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   252
            values.set(oldProperty.getSlot(), value);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   253
            newProperty = new SpillProperty(id, 0, oldProperty.getSlot());
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   254
            newProperty.setType(type);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   255
            newMap = propertyMap.replaceProperty(oldProperty, newProperty);;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   256
        } else {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   257
            values.add(value);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   258
            newProperty = new SpillProperty(id, 0, propertyMap.size());
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   259
            newProperty.setType(type);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   260
            newMap = propertyMap.addProperty(newProperty);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   261
        }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   262
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   263
        return newMap;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   264
    }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   265
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   266
    private Object createObject(final PropertyMap propertyMap, final List<Object> values, final ArrayData arrayData) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   267
        final long[] primitiveSpill = new long[values.size()];
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   268
        final Object[] objectSpill = new Object[values.size()];
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   269
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   270
        for (final Property property : propertyMap.getProperties()) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   271
            if (property.getType() == Object.class) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   272
                objectSpill[property.getSlot()] = values.get(property.getSlot());
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   273
            } else {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   274
                primitiveSpill[property.getSlot()] = ObjectClassGenerator.pack((Number) values.get(property.getSlot()));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   275
            }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   276
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   277
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   278
        final ScriptObject object = new JO(propertyMap, primitiveSpill, objectSpill);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   279
        object.setInitialProto(global.getObjectPrototype());
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   280
        object.setArray(arrayData);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   281
        return object;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   282
    }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   283
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   284
    private static Class<?> getType(final Object value) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   285
        if (value instanceof Integer) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   286
            return int.class;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   287
        } else if (value instanceof Long) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   288
            return long.class;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   289
        } else if (value instanceof Double) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   290
            return double.class;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   291
        } else {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   292
            return Object.class;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   293
        }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   294
    }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   295
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   296
    private void expectColon() {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   297
        skipWhiteSpace();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   298
        final int n = next();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   299
        if (n != ':') {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   300
            throw expectedError(pos - 1, ":", toString(n));
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   301
        }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   302
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   303
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   304
    private Object parseArray() {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   305
        ArrayData arrayData = ArrayData.EMPTY_ARRAY;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   306
        int state = STATE_EMPTY;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   307
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   308
        assert peek() == '[';
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   309
        pos++;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   310
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   311
        while (pos < length) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   312
            skipWhiteSpace();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   313
            final int c = peek();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   314
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   315
            switch (c) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   316
            case ',':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   317
                if (state != STATE_ELEMENT_PARSED) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   318
                    throw error(AbstractParser.message("trailing.comma.in.json"), pos);
20218
5818e1531c40 8025147: Trailing comma is not allowed in JSONArray and JSONObject
sundar
parents: 18867
diff changeset
   319
                }
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   320
                state = STATE_COMMA_PARSED;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   321
                pos++;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   322
                break;
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   323
            case ']':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   324
                if (state == STATE_COMMA_PARSED) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   325
                    throw error(AbstractParser.message("trailing.comma.in.json"), pos);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   326
                }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   327
                pos++;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   328
                return global.wrapAsObject(arrayData);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   329
            default:
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   330
                if (state == STATE_ELEMENT_PARSED) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   331
                    throw expectedError(pos, ", or ]", toString(c));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   332
                }
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   333
                final long index = arrayData.length();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   334
                arrayData = arrayData.ensure(index).set((int) index, parseLiteral(), true);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   335
                state = STATE_ELEMENT_PARSED;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   336
                break;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   337
            }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   338
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   339
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   340
        throw expectedError(pos, ", or ]", "eof");
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   341
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   342
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   343
    private String parseString() {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   344
        // String buffer is only instantiated if string contains escape sequences.
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   345
        int start = ++pos;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   346
        StringBuilder sb = null;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   347
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   348
        while (pos < length) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   349
            final int c = next();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   350
            if (c <= 0x1f) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   351
                // Characters < 0x1f are not allowed in JSON strings.
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   352
                throw syntaxError(pos, "String contains control character");
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   353
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   354
            } else if (c == '\\') {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   355
                if (sb == null) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   356
                    sb = new StringBuilder(pos - start + 16);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   357
                }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   358
                sb.append(source, start, pos - 1);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   359
                sb.append(parseEscapeSequence());
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   360
                start = pos;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   361
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   362
            } else if (c == '"') {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   363
                if (sb != null) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   364
                    sb.append(source, start, pos - 1);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   365
                    return sb.toString();
20218
5818e1531c40 8025147: Trailing comma is not allowed in JSONArray and JSONObject
sundar
parents: 18867
diff changeset
   366
                }
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   367
                return source.substring(start, pos - 1);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   368
            }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   369
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   370
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   371
        throw error(Lexer.message("missing.close.quote"), pos, length);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   372
    }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   373
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   374
    private char parseEscapeSequence() {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   375
        final int c = next();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   376
        switch (c) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   377
        case '"':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   378
            return '"';
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   379
        case '\\':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   380
            return '\\';
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   381
        case '/':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   382
            return '/';
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   383
        case 'b':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   384
            return '\b';
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   385
        case 'f':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   386
            return '\f';
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   387
        case 'n':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   388
            return '\n';
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   389
        case 'r':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   390
            return '\r';
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   391
        case 't':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   392
            return '\t';
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   393
        case 'u':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   394
            return parseUnicodeEscape();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   395
        default:
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   396
            throw error(Lexer.message("invalid.escape.char"), pos - 1, length);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   397
        }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   398
    }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   399
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   400
    private char parseUnicodeEscape() {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   401
        return (char) (parseHexDigit() << 12 | parseHexDigit() << 8 | parseHexDigit() << 4 | parseHexDigit());
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   402
    }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   403
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   404
    private int parseHexDigit() {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   405
        final int c = next();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   406
        if (c >= '0' && c <= '9') {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   407
            return c - '0';
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   408
        } else if (c >= 'A' && c <= 'F') {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   409
            return c + 10 - 'A';
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   410
        } else if (c >= 'a' && c <= 'f') {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   411
            return c + 10 - 'a';
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   412
        }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   413
        throw error(Lexer.message("invalid.hex"), pos - 1, length);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   414
    }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   415
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   416
    private boolean isDigit(final int c) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   417
        return c >= '0' && c <= '9';
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   418
    }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   419
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   420
    private void skipDigits() {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   421
        while (pos < length) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   422
            final int c = peek();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   423
            if (!isDigit(c)) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   424
                break;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   425
            }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   426
            pos++;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   427
        }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   428
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   429
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   430
    private Number parseNumber() {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   431
        final int start = pos;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   432
        int c = next();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   433
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   434
        if (c == '-') {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   435
            c = next();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   436
        }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   437
        if (!isDigit(c)) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   438
            throw numberError(start);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   439
        }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   440
        // no more digits allowed after 0
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   441
        if (c != '0') {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   442
            skipDigits();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   443
        }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   444
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   445
        // fraction
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   446
        if (peek() == '.') {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   447
            pos++;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   448
            if (!isDigit(next())) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   449
                throw numberError(pos - 1);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   450
            }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   451
            skipDigits();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   452
        }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   453
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   454
        // exponent
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   455
        c = peek();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   456
        if (c == 'e' || c == 'E') {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   457
            pos++;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   458
            c = next();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   459
            if (c == '-' || c == '+') {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   460
                c = next();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   461
            }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   462
            if (!isDigit(c)) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   463
                throw numberError(pos - 1);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   464
            }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   465
            skipDigits();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   466
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   467
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   468
        final double d = Double.parseDouble(source.substring(start, pos));
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   469
        if (JSType.isRepresentableAsInt(d)) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   470
            return (int) d;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   471
        } else if (JSType.isRepresentableAsLong(d)) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   472
            return (long) d;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   473
        }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   474
        return d;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   475
    }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   476
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   477
    private Object parseKeyword(final String keyword, final Object value) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   478
        if (!source.regionMatches(pos, keyword, 0, keyword.length())) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   479
            throw expectedError(pos, "json literal", "ident");
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   480
        }
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   481
        pos += keyword.length();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   482
        return value;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   483
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   484
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   485
    private int peek() {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   486
        if (pos >= length) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   487
            return -1;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   488
        }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   489
        return source.charAt(pos);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   490
    }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   491
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   492
    private int next() {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   493
        final int next = peek();
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   494
        pos++;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   495
        return next;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   496
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   497
28786
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   498
    private void skipWhiteSpace() {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   499
        while (pos < length) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   500
            switch (peek()) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   501
            case '\t':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   502
            case '\r':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   503
            case '\n':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   504
            case ' ':
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   505
                pos++;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   506
                break;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   507
            default:
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   508
                return;
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   509
            }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   510
        }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   511
    }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   512
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   513
    private static String toString(final int c) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   514
        return c == EOF ? "eof" : String.valueOf((char) c);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   515
    }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   516
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   517
    ParserException error(final String message, final int start, final int length) throws ParserException {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   518
        final long token     = Token.toDesc(STRING, start, length);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   519
        final int  pos       = Token.descPosition(token);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   520
        final Source src     = Source.sourceFor("<json>", source);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   521
        final int  lineNum   = src.getLine(pos);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   522
        final int  columnNum = src.getColumn(pos);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   523
        final String formatted = ErrorManager.format(message, src, lineNum, columnNum, token);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   524
        return new ParserException(JSErrorType.SYNTAX_ERROR, formatted, src, lineNum, columnNum, token);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   525
    }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   526
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   527
    private ParserException error(final String message, final int start) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   528
        return error(message, start, length);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   529
    }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   530
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   531
    private ParserException numberError(final int start) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   532
        return error(Lexer.message("json.invalid.number"), start);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   533
    }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   534
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   535
    private ParserException expectedError(final int start, final String expected, final String found) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   536
        return error(AbstractParser.message("expected", expected, found), start);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   537
    }
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   538
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   539
    private ParserException syntaxError(final int start, final String reason) {
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   540
        final String message = ECMAErrors.getMessage("syntax.error.invalid.json", reason);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   541
        return error(message, start);
679fd2d26470 8062141: Various performance issues parsing JSON
hannesw
parents: 27209
diff changeset
   542
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   543
}