Skip to content

Commit e250064

Browse files
committed
Perlito5 - js - native method lookup without using eval()
1 parent 6804ce8 commit e250064

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src5/lib/Perlito5/JavaScript2/Runtime.pm

+15-8
Original file line numberDiff line numberDiff line change
@@ -327,16 +327,23 @@ function p5call(invocant, method, list, p5want, no_params) {
327327
328328
list.shift();
329329
330-
if ( fun === fun.apply ) {
331-
// fun is "apply"
332-
// print Math->max->apply(undef,[9,2,3,7])
333-
var invox = list.shift();
334-
var argsx = list.shift();
335-
var args = p5array_deref( argsx , "" );
336-
return invocant.apply(invox, args);
330+
var args = [];
331+
for(var i = 0; i < list.length; i++) {
332+
if (typeof list[i] === "undefined" || list[i] == null) {
333+
args.push(null);
334+
}
335+
else if (list[i].hasOwnProperty("_array_")) {
336+
args.push(list[i]._array_); // array deref
337+
}
338+
else if (list[i].hasOwnProperty("_hash_")) {
339+
args.push(list[i]._hash_); // hash deref
340+
}
341+
else {
342+
args.push(list[i]);
343+
}
337344
}
338345
339-
return fun.apply(invocant, list);
346+
return fun.apply(invocant, args);
340347
}
341348
if (list.length == 0) {
342349
// property

0 commit comments

Comments
 (0)