Skip to content

Commit 4b51a26

Browse files
committed
Perlito5 - js - 0+ overload
1 parent 5946b0f commit 4b51a26

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

perlito5.pl

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src5/lib/Perlito5/Javascript2/Runtime.pm

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,12 @@ p5str = function(o) {
662662
// test for overload
663663
var meth = p5method_lookup('(""', o._class_._ref_, {});
664664
if (meth) {
665-
return p5str(meth([o], 1));
665+
return p5str(meth([o], 0));
666+
}
667+
// TODO - test the "fallback" flag
668+
meth = p5method_lookup('(0+', o._class_._ref_, {});
669+
if (meth) {
670+
return p5str(meth([o], 0));
666671
}
667672
// no overload, strigify the reference instead
668673
class_name = o._class_._ref_ + '=';
@@ -706,7 +711,12 @@ p5num = function(o) {
706711
// test for overload
707712
var meth = p5method_lookup('(0+', o._class_._ref_, {});
708713
if (meth) {
709-
return p5num(meth([o], 1));
714+
return p5num(meth([o], 0));
715+
}
716+
// TODO - test the "fallback" flag
717+
meth = p5method_lookup('(""', o._class_._ref_, {});
718+
if (meth) {
719+
return p5num(meth([o], 0));
710720
}
711721
}
712722
}

t5/01-perlito/510-string-overload.t

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use strict;
22
use warnings;
33
use feature ("say");
44

5-
say "1..2";
5+
say "1..6";
66

77
{ package S;
88
no strict 'refs';
@@ -22,3 +22,31 @@ $res = $v->$s;
2222
print "not " if $res ne "123";
2323
print "ok 2 - method call # $res\n";
2424

25+
# TODO - test if fallback is enabled
26+
# $res = 0 + $v;
27+
# print "not " if $res ne "123";
28+
print "ok 3 - overload fallback # $res # TODO\n";
29+
30+
31+
{ package N;
32+
no strict 'refs';
33+
*{'N::(0+'} = sub { 123 };
34+
*{'N::()'} = sub {}; # Make it findable via fetchmethod
35+
*{'N::()'} = \"fallback";
36+
}
37+
38+
$v = bless {}, "N";
39+
$res = 0 + $v;
40+
print "not " if $res != 123;
41+
print "ok 4 - overload # $res\n";
42+
43+
$s = '(0+';
44+
$res = $v->$s;
45+
print "not " if $res != 123;
46+
print "ok 5 - method call # $res\n";
47+
48+
$res = "$v";
49+
print "not " if $res ne "123";
50+
print "ok 6 - overload fallback # $res\n";
51+
52+

0 commit comments

Comments
 (0)