|
|
@ -228,21 +228,25 @@ class JSInterpreter(object):
|
|
|
|
switch_val, remaining = self._seperate_at_paren(expr[m.end() - 1:], ')')
|
|
|
|
switch_val, remaining = self._seperate_at_paren(expr[m.end() - 1:], ')')
|
|
|
|
switch_val = self.interpret_expression(switch_val, local_vars, allow_recursion)
|
|
|
|
switch_val = self.interpret_expression(switch_val, local_vars, allow_recursion)
|
|
|
|
body, expr = self._seperate_at_paren(remaining, '}')
|
|
|
|
body, expr = self._seperate_at_paren(remaining, '}')
|
|
|
|
body, default = body.split('default:') if 'default:' in body else (body, None)
|
|
|
|
items = body.replace('default:', 'case default:').split('case ')[1:]
|
|
|
|
items = body.split('case ')[1:]
|
|
|
|
for default in (False, True):
|
|
|
|
if default:
|
|
|
|
matched = False
|
|
|
|
items.append(f'default:{default}')
|
|
|
|
for item in items:
|
|
|
|
matched = False
|
|
|
|
case, stmt = [i.strip() for i in self._seperate(item, ':', 1)]
|
|
|
|
for item in items:
|
|
|
|
if default:
|
|
|
|
case, stmt = [i.strip() for i in self._seperate(item, ':', 1)]
|
|
|
|
matched = matched or case == 'default'
|
|
|
|
matched = matched or case == 'default' or switch_val == self.interpret_expression(case, local_vars, allow_recursion)
|
|
|
|
elif not matched:
|
|
|
|
if matched:
|
|
|
|
matched = case != 'default' and switch_val == self.interpret_expression(case, local_vars, allow_recursion)
|
|
|
|
|
|
|
|
if not matched:
|
|
|
|
|
|
|
|
continue
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
ret, should_abort = self.interpret_statement(stmt, local_vars, allow_recursion - 1)
|
|
|
|
ret, should_abort = self.interpret_statement(stmt, local_vars, allow_recursion - 1)
|
|
|
|
if should_abort:
|
|
|
|
if should_abort:
|
|
|
|
return ret
|
|
|
|
return ret
|
|
|
|
except JS_Break:
|
|
|
|
except JS_Break:
|
|
|
|
break
|
|
|
|
break
|
|
|
|
|
|
|
|
if matched:
|
|
|
|
|
|
|
|
break
|
|
|
|
return self.interpret_statement(expr, local_vars, allow_recursion - 1)[0]
|
|
|
|
return self.interpret_statement(expr, local_vars, allow_recursion - 1)[0]
|
|
|
|
|
|
|
|
|
|
|
|
# Comma seperated statements
|
|
|
|
# Comma seperated statements
|
|
|
|