Obsolescence of __noSuchMethod__

Bug reports and enhancement requests
Post Reply
barbaz
Senior Member
Posts: 9282
Joined: Sat Aug 03, 2013 5:45 pm

Obsolescence of __noSuchMethod__

Post by barbaz » Sun Mar 29, 2015 9:52 pm

https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/noSuchMethod wrote:Obsolete since Gecko 39 (Firefox 39 / Thunderbird 39 / SeaMonkey 2.36)
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.


This is going to break a LOT of our surrogates.

https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/noSuchMethod wrote:While __noSuchMethod__ is non-standard, the ECMAScript Harmony (ES6) specification will have Proxy, with which you can achieve the below (and more).



EDIT SeaMonkey 2.37a1 gives this warning in the Error Console when a __noSuchMethod__ is hit:

Code: Select all

Warning: Error: __noSuchMethod__ is deprecated


Also, as of the time of this edit I have not seen or come up with any Proxy-based emulation of __noSuchMethod__ that is limited to function calls - in fact I don't even know if Proxy can tell whether a property is accessed as part of a function call... does that matter?
Last edited by barbaz on Tue Mar 31, 2015 8:46 pm, edited 1 time in total.
Reason: +
*Always* check the changelogs BEFORE updating that important software!
-

barbaz
Senior Member
Posts: 9282
Joined: Sat Aug 03, 2013 5:45 pm

Re: Obsolescence of __noSuchMethod__

Post by barbaz » Fri Apr 24, 2015 1:15 am

So I've played with Proxy (fun stuff! :mrgreen: ) and thought about this... and I think that Proxy trapping all property acesses is actually going to make the surrogates more stable than the current __noSuchMethod__.. I recently contributed a surrogate where the page explicitly checked for a property before using it, and unlike __noSuchMethod__, where I had to explicitly specify the property, the use of Proxy would have meant that it makes no difference.

So I think we only need to intercept the get() operation with a shim something like this:

Code: Select all

let canUseProxy = typeof Proxy != 'undefined';

if (canUseProxy) {
  someObject = new Proxy(_internal_someObject, {
    get: function(target, prop, rcv) {
      // Emulate __noSuchMethod__: Give a specified function that does nothing if the property isn't in our object
      // NOTE: This assumes all nonexistant properties attempted to be accessed were meant to be functions.  Be careful here...
      return prop in target ? target[prop] : target['__noSuchMethod__'];
    },
  });
}

right?
(Obviously we wouldn't want to override __noSuchMethod__ at this point, rather using some other name if we make the switch now. But when __noSuchMethod__ becomes obsolete...)
*Always* check the changelogs BEFORE updating that important software!
-

barbaz
Senior Member
Posts: 9282
Joined: Sat Aug 03, 2013 5:45 pm

Re: Obsolescence of __noSuchMethod__

Post by barbaz » Wed Jul 22, 2015 6:13 pm

The Mozilla bug on removing __noSuchMethod__, https://bugzilla.mozilla.org/show_bug.cgi?id=683218
(Note comment 26)
*Always* check the changelogs BEFORE updating that important software!
-

User avatar
therube
Ambassador
Posts: 7469
Joined: Thu Mar 19, 2009 4:17 pm
Location: Maryland USA

Re: Obsolescence of __noSuchMethod__

Post by therube » Wed Jul 22, 2015 7:30 pm

(Since when did "popularity" mean anything in Mozilla decisions ;-).)
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.19) Gecko/20110420 SeaMonkey/2.0.14 Pinball NoScript FlashGot AdblockPlus
Mozilla/5.0 (Windows NT 5.1; rv:36.0) Gecko/20100101 SeaMonkey/2.33.1

barbaz
Senior Member
Posts: 9282
Joined: Sat Aug 03, 2013 5:45 pm

Re: Obsolescence of __noSuchMethod__

Post by barbaz » Tue Jul 28, 2015 7:42 pm

https://noscript.net/changelog#2.6.9.32rc3 wrote:x [Surrogate] shimmed or replaced code causing deprecations

Does this change mean this thread can be marked resolved?
*Always* check the changelogs BEFORE updating that important software!
-

fluffypuff
Posts: 5
Joined: Tue May 12, 2015 6:01 am

Re: Obsolescence of __noSuchMethod__

Post by fluffypuff » Fri Feb 19, 2016 5:59 am

noscript-2.9.0.4rc1 (noscriptService.js) still relies on __noSuchMethod__ but, as of ff44, mozilla has removed it
https://developer.mozilla.org/en-US/Firefox/Releases/44

After reading the MDN docs regarding js proxy
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/revocable
if the revoke() function gets called, the proxy becomes unusable: Any trap to a handler will throw a TypeError. Once a proxy is revoked, it will remain revoked and can be garbage collected.
...I'm left wondering whether proxying will provide ineffectual functionality.
For surrogates, the proxy declaration(s) reside within contentscript, right?
What's to prevent, e.g. anti-adblock script authors, enumerating and revoking any proxies we've created?

Then, after reading this
https://ponyfoo.com/articles/es6-proxies-in-depth
I'm now wondering whether we could (should?) both create AND proactively revoke() to achieve the same end result as provided by __noSuchMethod__
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0 Iceweasel/38.5.0

User avatar
Thrawn
Senior Member
Posts: 3106
Joined: Mon Jan 16, 2012 3:46 am
Location: Australia
Contact:

Re: Obsolescence of __noSuchMethod__

Post by Thrawn » Sat Feb 20, 2016 11:05 am

I think perhaps you don't understand the workings of the Proxy object. How much JavaScript experience do you have?
======
Thrawn
------------
Religion is not the opium of the masses. Daily life is the opium of the masses.

True religion, which dares to acknowledge death and challenge the way we live, is an attempt to wake up.
Mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0

Post Reply