Window.Promise - Function.prototype.toString called on incompatible object

For the more technical/geeky chat subjects!

Moderator: satrow

User avatar
adesh
Astronaut
Astronaut
Posts: 564
Joined: Tue, 06 Jun 2017, 07:38

Window.Promise - Function.prototype.toString called on incompatible object

Unread postby adesh » Thu, 10 May 2018, 18:11

While trying a website in Pale Moon, I was getting a "systax error" from a third-party script. Looking in the browser console, issue turned out to be related to stringify-ing an object. Further research led me to https://github.com/lodash/lodash/issues ... -203975179, which clearly states the issue.
The line having the issue is in Google Maps JS:

Code: Select all

String(_.ob.Promise)

where "_.ob" is the current window object.

I do not face the same issue with Basilisk, so it probably got fixed in some later FF version. I want to fix this issue in Pale Moon but searching on bugzilla with "Promise String/toString" did not return any candidate bugs.

Can you help me in creating a test case for this issue? I do not have any experience with web-workers.
How can I figure out which commit in Mozilla codebase fixes this issue, so I can try to port the fix.

vingtzwanzig
Moonbather
Moonbather
Posts: 60
Joined: Thu, 20 Apr 2017, 21:25
Contact:

Re: Window.Promise - Function.prototype.toString called on incompatible object

Unread postby vingtzwanzig » Sat, 12 May 2018, 21:52

If I follow the discussion on the linked bug report correctly then it is the patch linked on there that resolved it:
https://github.com/lodash/lodash/commit ... e045ef18ad

Code: Select all

 lodash.js
@@ -10838,7 +10838,9 @@
         return false;
       }
       if (isFunction(value)) {
-        return reIsNative.test(funcToString.call(value));
+        try {
+          return reIsNative.test(funcToString.call(value));
+        } catch (e) {}
       }
       return isObjectLike(value) &&
         (isHostObject(value) ? reIsNative : reIsHostCtor).test(value);

Because it looks like _ is passed to .toString which errors out, and the try ... catch presumably fixes that.
(But that is only from my limited knowledge of Python programming and this is js ;) )
Your String(_.ob.Promise) is different, so that patch above won't work. Ah - now I see your problem!
So what file is that line from, and how would you fix it in a similar way? Does the file have many historical changes, some things are seldom changed much, you might be lucky.

User avatar
adesh
Astronaut
Astronaut
Posts: 564
Joined: Tue, 06 Jun 2017, 07:38

Re: Window.Promise - Function.prototype.toString called on incompatible object

Unread postby adesh » Sun, 13 May 2018, 08:37

Thanks vingtzwanzig, but I cannot modify the script as it is a Google Maps script loaded on another website. What I am trying to do is fix Pale Moon to correctly handle the script.
This is what I get in console:

Code: Select all

Error: toString called on incompatible object js:112:1390

This is the script (error at 112:1390 as indicated above):

Code: Select all

https://maps.googleapis.com/maps/api/js?channel=web-lite&libraries=geometry&v=3.27

vingtzwanzig
Moonbather
Moonbather
Posts: 60
Joined: Thu, 20 Apr 2017, 21:25
Contact:

Re: Window.Promise - Function.prototype.toString called on incompatible object

Unread postby vingtzwanzig » Sun, 13 May 2018, 14:04

112:1390 - Not following 80 column kernel code standards then :)
_.vb.m=function(){if(-1!=String(_.ob.Promise).indexOf("[native code]")){var a=_.ob.Promise.resolve(void 0);

That is the whole of the problem line, it seems to call String on _.ob.Promise and check if it returns -1.
https://developer.mozilla.org/en-US/doc ... cts/String
https://developer.mozilla.org/en-US/doc ... urn_values

"It's possible to use String as a more reliable toString() alternative, as it works when used on null, undefined, and on symbols. "
So String ought to work, if it is failing then it is not behaving as described. It doesn't define a return value on that page though, perhaps the -1 on error might not be a correct assumption? String is a global function, _ (underscore) is a convention to denote a local object.
String() must be defined in some javascript library, perhaps it is a library version issue.


Return to “Technical chat”

Who is online

Users browsing this forum: No registered users and 2 guests