test/script/basic/JDK-8019508.js

Mon, 01 Jul 2013 23:36:40 +0530

author
sundar
date
Mon, 01 Jul 2013 23:36:40 +0530
changeset 391
9165138b427c
child 606
7cc5ff16380f
permissions
-rw-r--r--

8019508: Comma handling in object literal parsing is wrong
Reviewed-by: hannesw

sundar@391 1 /*
sundar@391 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
sundar@391 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
sundar@391 4 *
sundar@391 5 * This code is free software; you can redistribute it and/or modify it
sundar@391 6 * under the terms of the GNU General Public License version 2 only, as
sundar@391 7 * published by the Free Software Foundation.
sundar@391 8 *
sundar@391 9 * This code is distributed in the hope that it will be useful, but WITHOUT
sundar@391 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
sundar@391 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
sundar@391 12 * version 2 for more details (a copy is included in the LICENSE file that
sundar@391 13 * accompanied this code).
sundar@391 14 *
sundar@391 15 * You should have received a copy of the GNU General Public License version
sundar@391 16 * 2 along with this work; if not, write to the Free Software Foundation,
sundar@391 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
sundar@391 18 *
sundar@391 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
sundar@391 20 * or visit www.oracle.com if you need additional information or have any
sundar@391 21 * questions.
sundar@391 22 */
sundar@391 23
sundar@391 24 /**
sundar@391 25 * JDK-8019508: Comma handling in object literal parsing is wrong
sundar@391 26 *
sundar@391 27 * @test
sundar@391 28 * @run
sundar@391 29 */
sundar@391 30
sundar@391 31 function checkObjLiteral(str) {
sundar@391 32 try {
sundar@391 33 eval(str);
sundar@391 34 fail("SyntaxError expected for: " + str);
sundar@391 35 } catch (e) {
sundar@391 36 if (! (e instanceof SyntaxError)) {
sundar@391 37 fail("expected SyntaxError, got " + e);
sundar@391 38 }
sundar@391 39 print(e.message.replace(/\\/g, '/'));
sundar@391 40 }
sundar@391 41 }
sundar@391 42
sundar@391 43 // only comma
sundar@391 44 checkObjLiteral("({,})");
sundar@391 45
sundar@391 46 // starting with comma
sundar@391 47 checkObjLiteral("({, a:2 })");
sundar@391 48
sundar@391 49 // consecutive commas
sundar@391 50 checkObjLiteral("({a:3,,})");
sundar@391 51
sundar@391 52 // missing comma
sundar@391 53 checkObjLiteral("({a:3 b:2}");
sundar@391 54
sundar@391 55 // single trailing comma is okay!
sundar@391 56 var obj = { a: 3, };

mercurial