Skip to content

Commit

Permalink
Merge pull request #50 from y8n/master
Browse files Browse the repository at this point in the history
fix function proxy toString error
  • Loading branch information
jerrybendy authored Mar 24, 2021
2 parents fc69a9e + 9e8ed04 commit 7fd008a
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,24 @@
// There is a bug in Safari 10.1 and `Proxy`ing it is not enough.
var forSureUsePolyfill = !decodesPlusesCorrectly;
var useProxy = (!forSureUsePolyfill && nativeURLSearchParams && !isSupportObjectConstructor && self.Proxy);
var propValue;
if (useProxy) {
// Safari 10.0 doesn't support Proxy, so it won't extend URLSearchParams on safari 10.0
propValue = new Proxy(nativeURLSearchParams, {
construct: function (target, args) {
return new target((new URLSearchParamsPolyfill(args[0]).toString()));
}
})
// Chrome <=60 .toString() on a function proxy got error "Function.prototype.toString is not generic"
propValue.toString = Function.prototype.toString.bind(URLSearchParamsPolyfill);
} else {
propValue = URLSearchParamsPolyfill;
}
/*
* Apply polifill to global object and append other prototype into it
*/
Object.defineProperty(self, 'URLSearchParams', {
value: (useProxy ?
// Safari 10.0 doesn't support Proxy, so it won't extend URLSearchParams on safari 10.0
new Proxy(nativeURLSearchParams, {
construct: function(target, args) {
return new target((new URLSearchParamsPolyfill(args[0]).toString()));
}
}) :
URLSearchParamsPolyfill)
value: propValue
});

var USPProto = self.URLSearchParams.prototype;
Expand Down

0 comments on commit 7fd008a

Please sign in to comment.