mleibman / SlickGrid

A lightning fast JavaScript grid/spreadsheet
http://wiki.github.com/mleibman/SlickGrid
MIT License
6.82k stars 1.98k forks source link

CompileAccumulatorLoop: TypeError: Cannot assign to read only property 'name' of function #1032

Open wajda opened 9 years ago

wajda commented 9 years ago

When using minification (UglifyJS2) the browser complains about assigning to read only property 'name' of anonymous function. It's file slick.dataview.js, function compileAccumulatorLoop, the following line: fn.displayName = fn.name = "compiledAccumulatorLoop";

in:

function compileAccumulatorLoop(aggregator) {
      var accumulatorInfo = getFunctionInfo(aggregator.accumulate);
      var fn = new Function(
          "_items",
          "for (var " + accumulatorInfo.params[0] + ", _i=0, _il=_items.length; _i<_il; _i++) {" +
              accumulatorInfo.params[0] + " = _items[_i]; " +
              accumulatorInfo.body +
          "}"
      );
      fn.displayName = fn.name = "compiledAccumulatorLoop";
      return fn;
    }
wajda commented 9 years ago
TypeError: Cannot assign to read only property 'name' of function anonymous(_items
/**/) {
for (var item, _i=0, _il=_items.length; _i<_il; _i++) {item = _items[_i]; var val=item[this.field_];this.count_++,null!=val&&""!==val&&0/0!==val&&(this.nonNullCount_++,this.sum_+=parseFloat(val))}
6pac commented 9 years ago

This has been integrated into my 'alternative master'. Any testing is appreciated. See https://github.com/mleibman/SlickGrid/issues/1055

kika commented 9 years ago

@6pac It looks like your change is not related to this particular problem. WebKit based browsers complain about assignment to .name in use strict mode and it appears it has nothing to do with the changes to the regular expression. I'm using your fork (thanks for maintaining it, really appreciate support for SlickGrid, I rely on it heavily in my project) and have this problem in production (after minification). I believe minification reorders use strict directives and cause this, but this just speculation.

6pac commented 9 years ago

Yeah, I'd regard the naming as sugar. Seems the support is patchy

http://stackoverflow.com/questions/11486459/why-doesnt-javascript-allow-assigning-the-property-name-on-a-function