[jsinterp] Improve slice implementation (#10664)

Authored by: seproDev
This commit is contained in:
sepro
2024-08-05 22:28:24 +02:00
committed by GitHub
parent e7d73bc453
commit bb8bf1db99
2 changed files with 31 additions and 3 deletions

View File

@@ -709,9 +709,9 @@ class JSInterpreter:
obj.reverse()
return obj
elif member == 'slice':
assertion(isinstance(obj, list), 'must be applied on a list')
assertion(len(argvals) == 1, 'takes exactly one argument')
return obj[argvals[0]:]
assertion(isinstance(obj, (list, str)), 'must be applied on a list or string')
assertion(len(argvals) <= 2, 'takes between 0 and 2 arguments')
return obj[slice(*argvals, None)]
elif member == 'splice':
assertion(isinstance(obj, list), 'must be applied on a list')
assertion(argvals, 'takes one or more arguments')