paulmillr / es6-shim

ECMAScript 6 compatibility shims for legacy JS engines
http://paulmillr.com
MIT License
3.11k stars 388 forks source link

es6-shim.min.js (v0.34.1) in SharePoint - Uncaught Sys.ParameterCountException: Sys.ParameterCountException: Parameter count mismatch. #399

Closed williamyinssw closed 8 years ago

williamyinssw commented 8 years ago

When 'es6-shim.min.js' is referred in any SharePoint 2013 page,

<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.34.0/es6-shim.min.js"></script>

it shows the following error:

Uncaught Sys.ParameterCountException: Sys.ParameterCountException: Parameter count mismatch.  ScriptResource.axd?d=....

This may be a conflict issue with .NET Ajax controls..

ljharb commented 8 years ago

Can you provide a reproducible test case, ideally on a jsfiddle?

Does that error come with any sort of stack trace? What happens if you include the non-minified version?

arntj commented 8 years ago

All it takes to reproduce this issue, is to include the MicrosoftAjax 3.5 js (debug version) before ES6 shims. I've reproduced it in Chrome in the following jsfiddle (remember to have the browser debug console open before running it):

https://jsfiddle.net/p8ysoxts/

(Note: This fiddle is apparently empty, but the mentioned js files have been included as "external resources" in this fiddle. That is all it takes to reproduce the issue.)

arntj commented 8 years ago

I've also reproduced it with Microsoft Ajax 4.5.2:

https://jsfiddle.net/18pdk5u3/

arntj commented 8 years ago

The problem is that Microsoft Ajax enforces validation of parameters on String.prototype.startsWith, so that it throws an exception when it is called with more than one parameter. ES6-shim runs this function with two parameters as a part of a feature check (line 830 in es6-shim.js). This could be fixed by wrapping this line in a try-catch.

ljharb commented 8 years ago

@arntj In general, shims and polyfills need to always be run first, before application code (and language shims should run before engine-level shims). If you include es5-shim and es6-shim before your Ajax lib, does everything work?

arntj commented 8 years ago

Yes, it does work, but it's a little inconvenient given the current architecure of our website.

ljharb commented 8 years ago

I'll fix this one - my general policy is not to fix errors like this, unless it's easy - and in this case it's easy.

Thanks for confirming!

ljharb commented 8 years ago

This fix will be included in the next release. However, I'd recommend updating this Ajax library that's doing the wrong thing with startsWith, as well as loading the es5-shim and es6-shim first, before anything else.