hugg95 / closure-library

Automatically exported from code.google.com/p/closure-library
0 stars 0 forks source link

goog.array.reduce is site dependent even if goog.TRUSTED_SITE=false #537

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

What steps will reproduce the problem?
1. Implement Array.prototype.reduce = function() {} with a different semantics 
than the one closure library expects
2. call goog.array.reduce([1,2,3,4], function(a, b){return a + b}, 0)
3.

What is the expected output? What do you see instead?
expect to get 10
the output depends on the Array.prototype.reduce implementation

What version of the product are you using? On what operating system?
25th Jan 2013

Please provide any additional information below.

in my variation of the library i have modified goog.array.reduce (can be 
optimized):
goog.array.reduce = function(arr, f, val, opt_obj) {
  if(goog.NATIVE_ARRAY_PROTOTYPES && goog.array.ARRAY_PROTOTYPE_.reduce) {
    if(opt_obj) {
        f = goog.bind(f, opt_obj);
    }
    return goog.array.ARRAY_PROTOTYPE_.reduce.call(arr, f, val);
  }
  var rval = val;
  goog.array.forEach(arr, function(val, index) {
    rval = f.call(opt_obj, rval, val, index, arr);
  });
  return rval;
};

Note: we cannot accept patches without the contributor license agreement
being signed. See http://code.google.com/p/closure-
library/wiki/Contributors for more info.

Original issue reported on code.google.com by tsh...@gmail.com on 11 Feb 2013 at 1:41

GoogleCodeExporter commented 9 years ago
Do one of the widespread JavaScript libraries override Array.prototype.reduce 
causing real issues?
If not, I'm leaning to mark it as working as intended.

Original comment by pall...@google.com on 12 Mar 2013 at 1:36

GoogleCodeExporter commented 9 years ago
Well, I couldn't find such library today
But please consider the case where the site is untrusted
I use closure library to develop a library that webmasters can add to their 
site (think google analytics script for example)
Such sites might use old libraries or implement their own Array.prototype.reduce

Original comment by tsh...@gmail.com on 22 Jul 2013 at 8:41

GoogleCodeExporter commented 9 years ago

Original comment by pall...@google.com on 29 Jul 2013 at 8:33

GoogleCodeExporter commented 9 years ago

Original comment by pall...@google.com on 8 Aug 2013 at 4:56