mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2025-07-05 20:41:47 -07:00
[jsinterp] Support multiple indexing (eg a[1][2])
* extend single indexing with improved RE (should probably use/have used _separate_at_paren()) * fix some cases that should have given undefined, not throwing * standardise RE group names * support length of objects, like {1: 2, 3: 4, length: 42}
This commit is contained in:
parent
c1a03b1ac3
commit
81e64cacf2
2 changed files with 32 additions and 15 deletions
|
@ -366,6 +366,16 @@ class TestJSInterpreter(unittest.TestCase):
|
|||
self._test('function f() { let a; return a?.qq; }', JS_Undefined)
|
||||
self._test('function f() { let a = {m1: 42, m2: 0 }; return a?.qq; }', JS_Undefined)
|
||||
|
||||
def test_indexing(self):
|
||||
self._test('function f() { return [1, 2, 3, 4][3]}', 4)
|
||||
self._test('function f() { return [1, [2, [3, [4]]]][1][1][1][0]}', 4)
|
||||
self._test('function f() { var o = {1: 2, 3: 4}; return o[3]}', 4)
|
||||
self._test('function f() { var o = {1: 2, 3: 4}; return o["3"]}', 4)
|
||||
self._test('function f() { return [1, [2, {3: [4]}]][1][1]["3"][0]}', 4)
|
||||
self._test('function f() { return [1, 2, 3, 4].length}', 4)
|
||||
self._test('function f() { var o = {1: 2, 3: 4}; return o.length}', JS_Undefined)
|
||||
self._test('function f() { var o = {1: 2, 3: 4}; o["length"] = 42; return o.length}', 42)
|
||||
|
||||
def test_regex(self):
|
||||
self._test('function f() { let a=/,,[/,913,/](,)}/; }', None)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue