(target, name, args, keywords, context)
| 21987 | } |
| 21988 | |
| 21989 | call(target, name, args, keywords, context) { |
| 21990 | const builtins = this.builtins; |
| 21991 | const callTarget = this.target(target, context); |
| 21992 | const callArguments = args.map((arg) => this.expression(arg, context)); |
| 21993 | if (!callTarget || (name !== null && !callTarget[name])) { |
| 21994 | if (name === '__new__' && callArguments.length === 1 && callArguments[0] === callTarget) { |
| 21995 | name = null; |
| 21996 | callArguments.shift(); |
| 21997 | } else { |
| 21998 | const targetName = `${this.identifier(target)}.${name}`; |
| 21999 | throw new python.Error(`Unknown function '${targetName}'.`); |
| 22000 | } |
| 22001 | } |
| 22002 | const func = name ? callTarget[name] : callTarget; |
| 22003 | if (func.__class__ === builtins.type) { |
| 22004 | if (func.prototype && func.prototype.__class__ === func) { |
| 22005 | return Reflect.construct(func, callArguments); |
| 22006 | } |
| 22007 | const obj = Object.create(func); |
| 22008 | obj.__class__ = func; |
| 22009 | if (obj.__init__ && typeof obj.__init__ === 'function') { |
| 22010 | obj.__init__(...args); |
| 22011 | } |
| 22012 | return obj; |
| 22013 | } |
| 22014 | if (func.__class__ === builtins.function) { |
| 22015 | if (func.__call__) { |
| 22016 | return func.__call__(callArguments); |
| 22017 | } |
| 22018 | } |
| 22019 | if (func.__class__ === builtins.method) { |
| 22020 | if (func.__call__) { |
| 22021 | return func.__call__([callTarget].concat(callArguments)); |
| 22022 | } |
| 22023 | } |
| 22024 | if (typeof func === 'function') { |
| 22025 | return func.apply(callTarget, callArguments); |
| 22026 | } |
| 22027 | throw new python.Error('Unsupported call expression.'); |
| 22028 | } |
| 22029 | |
| 22030 | apply(method, args, context) { |
| 22031 | const locals = Array.prototype.slice.call(args); |
no test coverage detected