sundar@391: /* sundar@391: * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. sundar@391: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. sundar@391: * sundar@391: * This code is free software; you can redistribute it and/or modify it sundar@391: * under the terms of the GNU General Public License version 2 only, as sundar@391: * published by the Free Software Foundation. sundar@391: * sundar@391: * This code is distributed in the hope that it will be useful, but WITHOUT sundar@391: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or sundar@391: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License sundar@391: * version 2 for more details (a copy is included in the LICENSE file that sundar@391: * accompanied this code). sundar@391: * sundar@391: * You should have received a copy of the GNU General Public License version sundar@391: * 2 along with this work; if not, write to the Free Software Foundation, sundar@391: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. sundar@391: * sundar@391: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA sundar@391: * or visit www.oracle.com if you need additional information or have any sundar@391: * questions. sundar@391: */ sundar@391: sundar@391: /** sundar@391: * JDK-8019508: Comma handling in object literal parsing is wrong sundar@391: * sundar@391: * @test sundar@391: * @run sundar@391: */ sundar@391: sundar@391: function checkObjLiteral(str) { sundar@391: try { sundar@391: eval(str); sundar@391: fail("SyntaxError expected for: " + str); sundar@391: } catch (e) { sundar@391: if (! (e instanceof SyntaxError)) { sundar@391: fail("expected SyntaxError, got " + e); sundar@391: } sundar@606: printError(e); sundar@391: } sundar@391: } sundar@391: sundar@391: // only comma sundar@391: checkObjLiteral("({,})"); sundar@391: sundar@391: // starting with comma sundar@391: checkObjLiteral("({, a:2 })"); sundar@391: sundar@391: // consecutive commas sundar@391: checkObjLiteral("({a:3,,})"); sundar@391: sundar@391: // missing comma sundar@391: checkObjLiteral("({a:3 b:2}"); sundar@391: sundar@391: // single trailing comma is okay! sundar@391: var obj = { a: 3, };