Skip to content

Trailing commas not supported inside Array constructor #64

@aptivaman

Description

@aptivaman

In evaljs, trailing commas are allowed in array declarations, but when using Array constructors, it causes a crash:

import dukpy
testArray1 = '''
var array1 = [1, 2, 3, ];
array1.reduce(function(a, b) { return a + b; }, 0);
'''
print(dukpy.evaljs(testArray1))

testArray2 = '''
var array2 = new Array(1, 2, 3, );
array2.reduce(function(a, b) { return a + b; }, 0);
'''
print(dukpy.evaljs(testArray2))
~ $ python3 test.py
6
Traceback (most recent call last):
  File "test.py", line 12, in <module>
    print(dukpy.evaljs(testArray2))
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/dukpy/evaljs.py", line 134, in evaljs
    return JSInterpreter().evaljs(code, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/dukpy/evaljs.py", line 57, in evaljs
    res = _dukpy.eval_string(self, jscode, jsvars)
_dukpy.JSRuntimeError: SyntaxError: empty expression not allowed (line 2)
	src/pyduktape.c:2
	duk_js_compiler.c:4731

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions