-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmethod.js
More file actions
executable file
·49 lines (44 loc) · 1.54 KB
/
method.js
File metadata and controls
executable file
·49 lines (44 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* @constructor
*
* co_varnames and co_name come from generated code, must access as dict.
*/
Sk.builtin.method = function(func, self)
{
this.im_func = func;
this.im_self = self;
//print("constructing method", this.im_func.tp$name, this.im_self.tp$name);
};
goog.exportSymbol("Sk.builtin.method", Sk.builtin.method);
Sk.builtin.method.prototype.tp$call = function(args, kw)
{
goog.asserts.assert(this.im_self, "should just be a function, not a method since there's no self?");
goog.asserts.assert(this.im_func instanceof Sk.builtin.func);
//print("calling method");
// todo; modification OK?
args.unshift(this.im_self);
if (kw)
{
// bind the kw args
var kwlen = kw.length;
for (var i = 0; i < kwlen; i += 2)
{
// todo; make this a dict mapping name to offset
var varnames = this.im_func.func_code['co_varnames'];
var numvarnames = varnames && varnames.length;
for (var j = 0; j < numvarnames; ++j)
{
if (kw[i] === varnames[j])
break;
}
args[j] = kw[i+1];
}
}
// note: functions expect globals to be their 'this'. see compile.js and function.js also
return this.im_func.func_code.apply(this.im_func.func_globals, args);
};
Sk.builtin.method.prototype['$r'] = function()
{
return new Sk.builtin.str("<bound method " + this.im_self.ob$type.tp$name + "." + this.im_func.func_code['co_name'].v
+ " of " + this.im_self['$r']().v + ">");
};