Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Perlito5 - js2 - fix context in method calls

  • Loading branch information...
commit 589722e4057916d88cb49375557c9ed90dd3051d 1 parent 643adab
@fglock authored
View
12 html/perlito5.js
@@ -130,7 +130,7 @@ function p5method_lookup(method, class_name, seen) {
}
}
-function p5call(invocant, method, list) {
+function p5call(invocant, method, list, p5want) {
list.unshift(invocant);
if (typeof invocant === "string") {
@@ -140,11 +140,11 @@ function p5call(invocant, method, list) {
if ( invocant.hasOwnProperty("_class_") ) {
if ( invocant._class_.hasOwnProperty(method) ) {
- return invocant._class_[method](list)
+ return invocant._class_[method](list, p5want)
}
var m = p5method_lookup(method, invocant._class_._ref_, {});
if (m) {
- return m(list)
+ return m(list, p5want)
}
// method can have an optional namespace
@@ -154,7 +154,7 @@ function p5call(invocant, method, list) {
pkg_name = pkg_name.join("::");
m = p5method_lookup(name, pkg_name, {});
if (m) {
- return m(list)
+ return m(list, p5want)
}
p5pkg.CORE.die(["method not found: ", name, " in class ", pkg_name]);
}
@@ -162,7 +162,7 @@ function p5call(invocant, method, list) {
pkg_name = p5get_class_for_method('AUTOLOAD', invocant._class_._ref_, {}) || p5get_class_for_method('AUTOLOAD', "UNIVERSAL", {});
if (pkg_name) {
p5pkg[pkg_name]["v_AUTOLOAD"] = invocant._class_._ref_ + "::" + method;
- return p5pkg[pkg_name]["AUTOLOAD"](list);
+ return p5pkg[pkg_name]["AUTOLOAD"](list, p5want);
}
p5pkg.CORE.die(["method not found: ", method, " in class ", invocant._class_._ref_]);
@@ -173,7 +173,7 @@ function p5call(invocant, method, list) {
}
-function p5call_sub(namespace, name, list) {
+function p5call_sub(namespace, name, list, p5want) {
if(p5pkg[namespace].hasOwnProperty(name)) {
// TODO
}
View
4 perlito5.pl
2 additions, 2 deletions not shown
View
12 src5/lib/Perlito5/Javascript2/Runtime.pm
@@ -136,7 +136,7 @@ function p5method_lookup(method, class_name, seen) {
}
}
-function p5call(invocant, method, list) {
+function p5call(invocant, method, list, p5want) {
list.unshift(invocant);
if (typeof invocant === "string") {
@@ -146,11 +146,11 @@ function p5call(invocant, method, list) {
if ( invocant.hasOwnProperty("_class_") ) {
if ( invocant._class_.hasOwnProperty(method) ) {
- return invocant._class_[method](list)
+ return invocant._class_[method](list, p5want)
}
var m = p5method_lookup(method, invocant._class_._ref_, {});
if (m) {
- return m(list)
+ return m(list, p5want)
}
// method can have an optional namespace
@@ -160,7 +160,7 @@ function p5call(invocant, method, list) {
pkg_name = pkg_name.join("::");
m = p5method_lookup(name, pkg_name, {});
if (m) {
- return m(list)
+ return m(list, p5want)
}
p5pkg.CORE.die(["method not found: ", name, " in class ", pkg_name]);
}
@@ -168,7 +168,7 @@ function p5call(invocant, method, list) {
pkg_name = p5get_class_for_method('AUTOLOAD', invocant._class_._ref_, {}) || p5get_class_for_method('AUTOLOAD', "UNIVERSAL", {});
if (pkg_name) {
p5pkg[pkg_name]["v_AUTOLOAD"] = invocant._class_._ref_ + "::" + method;
- return p5pkg[pkg_name]["AUTOLOAD"](list);
+ return p5pkg[pkg_name]["AUTOLOAD"](list, p5want);
}
p5pkg.CORE.die(["method not found: ", method, " in class ", invocant._class_._ref_]);
@@ -179,7 +179,7 @@ function p5call(invocant, method, list) {
}
-function p5call_sub(namespace, name, list) {
+function p5call_sub(namespace, name, list, p5want) {
if(p5pkg[namespace].hasOwnProperty(name)) {
// TODO
}
View
22 src5/lib/Perlito5/Javascript3/Runtime.pm
@@ -144,7 +144,7 @@ function p5method_lookup(method, class_name, seen) {
}
}
-function p5call(invocant, method, list) {
+function p5call(invocant, method, list, p5want) {
list.unshift(invocant);
if (invocant instanceof p5Scalar) {
@@ -155,11 +155,11 @@ function p5call(invocant, method, list) {
if ( invocant.hasOwnProperty("_class_") ) {
if ( invocant._class_.hasOwnProperty(method) ) {
- return invocant._class_[method](list)
+ return invocant._class_[method](list, p5want)
}
var m = p5method_lookup(method, invocant._class_._ref_, {});
if (m) {
- return m(list)
+ return m(list, p5want)
}
// method can have an optional namespace
@@ -169,7 +169,7 @@ function p5call(invocant, method, list) {
pkg_name = pkg_name.join("::");
m = p5method_lookup(name, pkg_name, {});
if (m) {
- return m(list)
+ return m(list, p5want)
}
p5pkg.CORE.die(["method not found: ", name, " in class ", pkg_name]);
}
@@ -177,7 +177,7 @@ function p5call(invocant, method, list) {
pkg_name = p5get_class_for_method('AUTOLOAD', invocant._class_._ref_, {}) || p5get_class_for_method('AUTOLOAD', "UNIVERSAL", {});
if (pkg_name) {
p5pkg[pkg_name]["v_AUTOLOAD"] = invocant._class_._ref_ + "::" + method;
- return p5pkg[pkg_name]["AUTOLOAD"](list);
+ return p5pkg[pkg_name]["AUTOLOAD"](list, p5want);
}
p5pkg.CORE.die(["method not found: ", method, " in class ", invocant._class_._ref_]);
@@ -188,13 +188,23 @@ function p5call(invocant, method, list) {
if (typeof invocant === "string") {
var aclass = p5make_package(invocant);
- return p5call(aclass, method, list);
+ return p5call(aclass, method, list, p5want);
}
p5pkg.CORE.die(["Can't call method ", method, " on unblessed reference"]);
}
+function p5call_sub(namespace, name, list, p5want) {
+ if(p5pkg[namespace].hasOwnProperty(name)) {
+ // TODO
+ }
+ if(p5pkg[namespace].hasOwnProperty("AUTOLOAD")) {
+ // TODO
+ }
+ p5pkg.CORE.die(["Undefined subroutine &" + namespace + "::" + name]);
+}
+
p5make_package("main");
p5pkg["main"]["v_@"] = new p5Scalar(""); // $@
p5pkg["main"]["v_|"] = new p5Scalar(0); // $|
View
25 t5/01-perlito/31-autoload.t
@@ -1,9 +1,10 @@
use feature 'say';
use strict;
-say "1..3";
+say "1..4";
{
+
package A;
our $AUTOLOAD;
@@ -15,12 +16,28 @@ say "1..3";
say "# $AUTOLOAD";
print "not " if $AUTOLOAD ne "A::a";
say "ok 2";
- return 456;
+ return wantarray ? ( 4, 5 ) : 456;
}
my $v = a(123);
- print "not " if $v != 456;
- say "ok 3";
+ print "not " if $v != 456;
+ say "ok 3";
+
}
+{
+
+ package C;
+
+ our $AUTOLOAD;
+
+ sub AUTOLOAD {
+ return wantarray ? ( 6, 7 ) : 456;
+ }
+
+ my @x = a(123);
+ print "not " if $x[0] != 6 || $x[1] != 7;
+ say "ok 4";
+
+}
View
25 t5/01-perlito/32-autoload-method.t
@@ -1,9 +1,10 @@
use feature 'say';
use strict;
-say "1..4";
+say "1..5";
{
+
package A;
our $AUTOLOAD;
@@ -17,12 +18,28 @@ say "1..4";
say "# $AUTOLOAD";
print "not " if $AUTOLOAD ne "A::a";
say "ok 3";
- return 456;
+ return wantarray ? ( 4, 5 ) : 456;
}
my $v = A->a(123);
- print "not " if $v != 456;
- say "ok 4";
+ print "not " if $v != 456;
+ say "ok 4";
+
}
+{
+
+ package C;
+
+ our $AUTOLOAD;
+
+ sub AUTOLOAD {
+ return wantarray ? ( 6, 7 ) : 456;
+ }
+
+ my @x = C->a(123);
+ print "not " if $x[0] != 6 || $x[1] != 7;
+ say "ok 5";
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.