mirror of
https://github.com/blackjack4494/yt-dlc.git
synced 2024-12-22 07:43:08 +00:00
[swfinterp] Add support for calling methods on objects
This commit is contained in:
parent
01b4b74574
commit
0d989011ff
2 changed files with 41 additions and 11 deletions
21
test/swftests/PrivateCall.as
Normal file
21
test/swftests/PrivateCall.as
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
// input: []
|
||||||
|
// output: 9
|
||||||
|
|
||||||
|
package {
|
||||||
|
public class PrivateCall {
|
||||||
|
public static function main():int{
|
||||||
|
var f:OtherClass = new OtherClass();
|
||||||
|
return f.func();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class OtherClass {
|
||||||
|
private function pf():int {
|
||||||
|
return 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function func():int {
|
||||||
|
return this.pf();
|
||||||
|
}
|
||||||
|
}
|
|
@ -50,6 +50,17 @@ class _AVMClass_Object(object):
|
||||||
return '%s#%x' % (self.avm_class.name, id(self))
|
return '%s#%x' % (self.avm_class.name, id(self))
|
||||||
|
|
||||||
|
|
||||||
|
class _ScopeDict(dict):
|
||||||
|
def __init__(self, avm_class):
|
||||||
|
super(_ScopeDict, self).__init__()
|
||||||
|
self.avm_class = avm_class
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '%s__Scope(%s)' % (
|
||||||
|
self.avm_class.name,
|
||||||
|
super(_ScopeDict, self).__repr__())
|
||||||
|
|
||||||
|
|
||||||
class _AVMClass(object):
|
class _AVMClass(object):
|
||||||
def __init__(self, name_idx, name):
|
def __init__(self, name_idx, name):
|
||||||
self.name_idx = name_idx
|
self.name_idx = name_idx
|
||||||
|
@ -59,17 +70,7 @@ class _AVMClass(object):
|
||||||
self.methods = {}
|
self.methods = {}
|
||||||
self.method_pyfunctions = {}
|
self.method_pyfunctions = {}
|
||||||
|
|
||||||
class ScopeDict(dict):
|
self.variables = _ScopeDict(self)
|
||||||
def __init__(self, avm_class):
|
|
||||||
super(ScopeDict, self).__init__()
|
|
||||||
self.avm_class = avm_class
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return '%s__Scope(%s)' % (
|
|
||||||
self.avm_class.name,
|
|
||||||
super(ScopeDict, self).__repr__())
|
|
||||||
|
|
||||||
self.variables = ScopeDict(self)
|
|
||||||
|
|
||||||
def make_object(self):
|
def make_object(self):
|
||||||
return _AVMClass_Object(self)
|
return _AVMClass_Object(self)
|
||||||
|
@ -411,6 +412,14 @@ class SWFInterpreter(object):
|
||||||
res = func(args)
|
res = func(args)
|
||||||
stack.append(res)
|
stack.append(res)
|
||||||
continue
|
continue
|
||||||
|
elif isinstance(obj, _ScopeDict):
|
||||||
|
if mname in obj.avm_class.method_names:
|
||||||
|
func = self.extract_function(obj.avm_class, mname)
|
||||||
|
res = func(args)
|
||||||
|
else:
|
||||||
|
res = obj[mname]
|
||||||
|
stack.append(res)
|
||||||
|
continue
|
||||||
elif isinstance(obj, compat_str):
|
elif isinstance(obj, compat_str):
|
||||||
if mname == 'split':
|
if mname == 'split':
|
||||||
assert len(args) == 1
|
assert len(args) == 1
|
||||||
|
|
Loading…
Reference in a new issue