mirror of
https://codeberg.org/polarisfm/youtube-dl
synced 2024-11-26 10:24:33 +01:00
[swfinterp] Formalize built-in classes
This commit is contained in:
parent
4686ae4b64
commit
6b592d93a2
@ -149,6 +149,11 @@ def _read_byte(reader):
|
|||||||
|
|
||||||
|
|
||||||
StringClass = _AVMClass('(no name idx)', 'String')
|
StringClass = _AVMClass('(no name idx)', 'String')
|
||||||
|
ByteArrayClass = _AVMClass('(no name idx)', 'ByteArray')
|
||||||
|
_builtin_classes = {
|
||||||
|
StringClass.name: StringClass,
|
||||||
|
ByteArrayClass.name: ByteArrayClass,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class _Undefined(object):
|
class _Undefined(object):
|
||||||
@ -468,11 +473,31 @@ class SWFInterpreter(object):
|
|||||||
[stack.pop() for _ in range(arg_count)]))
|
[stack.pop() for _ in range(arg_count)]))
|
||||||
obj = stack.pop()
|
obj = stack.pop()
|
||||||
|
|
||||||
if isinstance(obj, _AVMClass_Object):
|
if obj == StringClass:
|
||||||
|
if mname == 'String':
|
||||||
|
assert len(args) == 1
|
||||||
|
assert isinstance(args[0], (
|
||||||
|
int, compat_str, _Undefined))
|
||||||
|
if args[0] == undefined:
|
||||||
|
res = 'undefined'
|
||||||
|
else:
|
||||||
|
res = compat_str(args[0])
|
||||||
|
stack.append(res)
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
raise NotImplementedError(
|
||||||
|
'Function String.%s is not yet implemented'
|
||||||
|
% mname)
|
||||||
|
elif isinstance(obj, _AVMClass_Object):
|
||||||
func = self.extract_function(obj.avm_class, mname)
|
func = self.extract_function(obj.avm_class, mname)
|
||||||
res = func(args)
|
res = func(args)
|
||||||
stack.append(res)
|
stack.append(res)
|
||||||
continue
|
continue
|
||||||
|
elif isinstance(obj, _AVMClass):
|
||||||
|
func = self.extract_function(obj, mname)
|
||||||
|
res = func(args)
|
||||||
|
stack.append(res)
|
||||||
|
continue
|
||||||
elif isinstance(obj, _ScopeDict):
|
elif isinstance(obj, _ScopeDict):
|
||||||
if mname in obj.avm_class.method_names:
|
if mname in obj.avm_class.method_names:
|
||||||
func = self.extract_function(obj.avm_class, mname)
|
func = self.extract_function(obj.avm_class, mname)
|
||||||
@ -504,21 +529,6 @@ class SWFInterpreter(object):
|
|||||||
res = args[0].join(obj)
|
res = args[0].join(obj)
|
||||||
stack.append(res)
|
stack.append(res)
|
||||||
continue
|
continue
|
||||||
elif obj == StringClass:
|
|
||||||
if mname == 'String':
|
|
||||||
assert len(args) == 1
|
|
||||||
assert isinstance(args[0], (
|
|
||||||
int, compat_str, _Undefined))
|
|
||||||
if args[0] == undefined:
|
|
||||||
res = 'undefined'
|
|
||||||
else:
|
|
||||||
res = compat_str(args[0])
|
|
||||||
stack.append(res)
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
raise NotImplementedError(
|
|
||||||
'Function String.%s is not yet implemented'
|
|
||||||
% mname)
|
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
'Unsupported property %r on %r'
|
'Unsupported property %r on %r'
|
||||||
% (mname, obj))
|
% (mname, obj))
|
||||||
@ -582,8 +592,8 @@ class SWFInterpreter(object):
|
|||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
res = scopes[0]
|
res = scopes[0]
|
||||||
if mname not in res and mname == 'String':
|
if mname not in res and mname in _builtin_classes:
|
||||||
stack.append(StringClass)
|
stack.append(_builtin_classes[mname])
|
||||||
else:
|
else:
|
||||||
stack.append(res[mname])
|
stack.append(res[mname])
|
||||||
elif opcode == 94: # findproperty
|
elif opcode == 94: # findproperty
|
||||||
|
Loading…
Reference in New Issue
Block a user