Closed Bug 1140428 Opened 9 years ago Closed 9 years ago

Warn when __noSuchMethod__ is used

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla39
Tracking Status
firefox39 --- fixed

People

(Reporter: jandem, Assigned: jandem)

References

Details

(Keywords: dev-doc-complete, site-compat, Whiteboard: [DocArea=JS])

Attachments

(1 file)

Attached patch PatchSplinter Review
With this patch we show a console warning whenever __noSuchMethod__ is used. We warn at most once per compartment, to avoid flooding the console.
Attachment #8573973 - Flags: review?(jorendorff)
Have you considered using GlobalObject::warnOnceAbout?
(In reply to Tom Schuster [:evilpie] from comment #1)
> Have you considered using GlobalObject::warnOnceAbout?

Ah I didn't know about it. It looks more complicated to me: (1) it requires a js.msg entry and (2) I don't understand why it uses a full HeapValue to store a flag. A bool on the compartment seems both simpler and more efficient. If people prefer warnOnceAbout I can use that though.
Attachment #8573973 - Flags: review?(jorendorff) → review+
Blocks: 1142337
https://hg.mozilla.org/mozilla-central/rev/19fafff99435
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla39
No longer blocks: 1142337
Whiteboard: [DocArea=JS]
Depends on: 1143065
I'll add this to the 39 site compat doc hopefully this weekend.
See Also: → 1148638
Is the officially recommended alternative handler's "get" for Proxy?
https://bugzilla.mozilla.org/show_bug.cgi?id=683218#c14
(In reply to YUKI "Piro" Hiroshi from comment #8)
Yes, pretty much.  There are perhaps different ways to skin the dead cat here using proxies, but adding a catchall "get" trap via an interspersed proxy is the easiest way to do it.

Proxies do not do nice things to performance, tho, and will not for some time.  You *really* are better off doing property-existence checks than continuing whatever approach it is you're taking right now.
And I should be *extra* clear to note: DO NOT intersperse an object into the prototype chain of Object.prototype, to catch *all* lookups that aren't found on earlier objects in the prototype chain.  This is an EXTRAORDINARILY BAD idea that will destroy performance for vast swaths of code, and I'm actively working on making it impossible to do this, for this and other reasons.
Also, many use cases for __noSuchMethod__ don't need a proxy. When you just want to forward some method calls to another object, you can often just add a function for each property that forwards the call to the other object (or use a for-in loop to do this automatically for each method on the target object).
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: