Closed Bug 371033 Opened 17 years ago Closed 12 years ago

Universal support for noSuchMethod

Categories

(Core :: JavaScript Engine, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: igor, Unassigned)

References

Details

Attachments

(1 file)

Currently __noSuchMethod__ can capture only methods called through obj.notExistingProperty(). It does not work with obj[expression]() or with notExistingName() calls as the following jsshell session demonstrates:

js> o = {}
o = {}
[object Object]
js> o.__noSuchMethod__ = function(id) { print("Unknown call: "+id); } 
o.__noSuchMethod__ = function(id) { print("Unknown call: "+id); } 
function (id) {
    print("Unknown call: " + id);
}
js> o.x()
o.x()
Unknown call: x
js> var name = 'x';
var name = 'x';
js> o[name]()
o[name]()
typein:12: TypeError: o[name] is not a function
js> with (o) { x(); }
with (o) { x(); }
typein:13: ReferenceError: x is not defined

It would nice to extend __noSuchMethod__ support to cover all cases.
The new callelem/callname bytecodes that bug 363530 adds should allow to gain all the necessary information to implement this bug.
Depends on: 363530
We should implement the ES4 catchalls proposal too, not just extend the old nSM hack I did for the Tibet guys.

http://developer.mozilla.org/es4/proposals/catchalls.html (out of date, update coming this week, I'll attach a saved version of the latest wiki page to this bug in the mean time).

/be
Depends on: js-catchall, 312196, 355258
I am not working on the bug right now.
Assignee: igor → general
This might, or might not be helpful information:
In SpiderMonkey:

js> var x = { __noSuchMethod__: function(id) { print(id); } }
js> x.y()                                                     
y
js> x["y"]()
y
js> var z = "y"
js> x[z]()
typein:7: TypeError: x[z] is not a function

In Rhino:

js> var x = { __noSuchMethod__: function(id) { print(id); } }
js> x.y()
y
js> x["y"]()
y
js> var z = "y"
js> x[z]()
y

So AFAIK Rhino "does it right" while SpiderMonkey does not.
Wilson: you are using an out of date SpiderMonkey. Fresh hg.mozilla.org trunk:

js> var x = { __noSuchMethod__: function(id) { print(id); } }
js> x.y()                                                     
y
js> x["y"]()
y
js> var z = "y"
js> x[z]()
y

This bug is somewhat more fixed. Other forms remain unsupporetd, however.

/be
Oopsies. I just checked and it /is/ fixed on mozilla-central.
If anything, we are going to eventually remove __noSuchMethod__ (bug 683218).
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: