Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some functions limited by Function.prototype.apply #314

Open
pauldraper opened this issue Jul 6, 2014 · 3 comments
Open

Some functions limited by Function.prototype.apply #314

pauldraper opened this issue Jul 6, 2014 · 3 comments

Comments

@pauldraper
Copy link
Contributor

There are limitations to the number of arguments that can be passed with Function.prototype.apply.

Some functions that use Function.prototype.apply only use it with the variable arguments in the first place. Those are limited by this anyway. There's nothing to do there, at least not without changing the API.

  • goog.array.concat
  • goog.array.splice
  • goog.array.join
  • goog.array.slice
  • goog.math.average
  • goog.math.standardDeviation

But some functions accept an array as a single argument and then pass that to Function.prototype.apply. It is reasonable, though somewhat uncommon, for there to be more than 65,537 elements in an array.

  • goog.array.extend
  • goog.array.flatten
  • goog.array.insertArrayAt
  • goog.array.rotate
  • goog.math.Path.prototype.appendPath
  • goog.object.create
  • goog.string.format
  • goog.testing.PerformanceTimer.createResults
  • goog.testing.PerformanceTimer.prototype.finishTask_

The numbers seemed to vary (OS dependent?), but this is what I've measured:

Browser apply() literal
Chrome 14 131155 32767
Chrome 35 126213 65535
Firefox 30 500001 65535
IE 9 254335 65533
IE 10 253667 65533
IE 11 252447 65533
Opera 22 126063 65535
Safari 4 524215 524205
Safari 7 65537 522159

JSFiddle


Other references to this problem:

  • This issue with goog.crypt.byteArrayToString was mentioned in the discussion list and then fixed by da353e0.
  • Webkit bug, reported 2012-03-11
diracdeltas pushed a commit to diracdeltas/closure-library that referenced this issue Oct 3, 2014
Function.prototype.apply was limiting the size of the subarray that could be
flattened. Related issue:
google#314

Signed off by: Yan Zhu, yzhu@yahoo-inc.com
@Ubehebe
Copy link
Contributor

Ubehebe commented Nov 3, 2014

It does seem like we could replace .apply(...) with direct function calls in many of the methods you point out. Feel free to send pull requests. Beyond that, was there a more general API change you had in mind?

@pauldraper
Copy link
Contributor Author

No, that's pretty much it.

@diracdeltas
Copy link
Contributor

goog.array.extend and goog.array.flatten have been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants