From 4cabe3612fa3bd1188f17b244c635c950a831bbe Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Tue, 16 Oct 2018 17:22:03 +0200 Subject: [PATCH] jscript: Allow trailing comma in object literals. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/jscript/parser.y | 8 ++++++++ dlls/jscript/tests/lang.js | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/dlls/jscript/parser.y b/dlls/jscript/parser.y index a40b813de1c..0bb885606b6 100644 --- a/dlls/jscript/parser.y +++ b/dlls/jscript/parser.y @@ -778,6 +778,14 @@ ObjectLiteral : '{' '}' { $$ = new_prop_and_value_expression(ctx, NULL); } | '{' PropertyNameAndValueList '}' { $$ = new_prop_and_value_expression(ctx, $2); } + | '{' PropertyNameAndValueList ',' '}' + { + if(ctx->script->version < 2) { + WARN("Trailing comma in object literal is illegal in legacy mode.\n"); + YYABORT; + } + $$ = new_prop_and_value_expression(ctx, $2); + } /* ECMA-262 3rd Edition 11.1.5 */ PropertyNameAndValueList diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js index badb6a8c60a..1cd5668e257 100644 --- a/dlls/jscript/tests/lang.js +++ b/dlls/jscript/tests/lang.js @@ -480,6 +480,20 @@ ok(obj3.prop1 === 1, "obj3.prop1 is not 1"); ok(obj3.prop2 === "boolean", "obj3.prop2 is not \"boolean\""); ok(obj3.constructor === Object, "unexpected obj3.constructor"); +if(invokeVersion >= 2) { + eval("tmp = {prop: 'value',}"); + ok(tmp.prop === "value", "tmp.prop = " + tmp.prop); + eval("tmp = {prop: 'value',second:2,}"); + ok(tmp.prop === "value", "tmp.prop = " + tmp.prop); +}else { + try { + eval("tmp = {prop: 'value',}"); + }catch(e) { + tmp = true; + } + ok(tmp === true, "exception not fired"); +} + { var blockVar = 1; blockVar = 2;