angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

(iOS 8 GM iPhone5C) TypeError: Attempted to assign to readonly property

Open HAKASHUN opened this issue 12 years ago • 163 comments

I am using on iOS 8 GM(iPhone5C). With this device, I am getting this error in this line(https://github.com/angular/angular.js/blob/master/src/ng/rootScope.js#L216) But on iOS 8 GM(iPhone5S) and iOS 7.x (iPhone5C, iPhone5S), this error does not occur.

To resolve this error, I rewrote the code as follows:

$new: function(isolate) {
        var child;

        if (isolate) {
          child = new Scope();
          child.$root = this.$root;
          // ensure that there is just one async queue per $rootScope and its children
          child.$$asyncQueue = this.$$asyncQueue;
          child.$$postDigestQueue = this.$$postDigestQueue;
        } else {
          // Only create a child scope class if somebody asks for one,
          // but cache it to allow the VM to optimize lookups.
          if (!this.$$ChildScope) {
            this.$$ChildScope = function ChildScope() {
              this['$$watchers'] = this['$$nextSibling'] =
                  this['$$childHead'] = this['$$childTail'] = null;
              this['$$listeners'] = {};
              this['$$listenerCount'] = {};
              this['$id'] = nextUid();
              this['$$ChildScope'] = null;
            };
            this.$$ChildScope.prototype = this;
          }
          child = new this.$$ChildScope();
        }
        child['this'] = child;
        child['$parent'] = this;
        child['$$prevSibling'] = this.$$childTail;
        if (this.$$childHead) {
          this.$$childTail.$$nextSibling = child;
          this.$$childTail = child;
        } else {
          this.$$childHead = this.$$childTail = child;
        }
        return child;
      },

The situation has improved, but I do not understand the reason...

HAKASHUN avatar Sep 17 '14 13:09 HAKASHUN

My company has released a utility which rewrites our code with all dot property assignments changed to bracket notation assignments.

That is, it rewrites the following code

object.$$a = 5;

to this

var __webkitAssign__$$a = '$$a';
object[__webkitAssign__$$a] = 5;

as a workaround to prevent a TypeError. The utility is available on npm. It has alleviated the "readonly" issue for us on iOS.

For a while, my company simply removed 'use strict';, but recently we encountered a strange bug where repeatedly opening dialogs from angular's material design library resulted in the page freezing. An error was thrown: Error: null is not an object (evaluating 'parent.$$childTail.$$nextSibling = child'), and I suppose that somehow resulted in $digest looping infinitely (thus the freeze).

We tried adding 'use strict'; back, but then we started seeing the "readonly" error at exactly the same time as the aforementioned error. This leads me to believe the null reference is related to this JIT bug, and that the bug is not (or hopefully, was not) limited to just strict mode.

The utility isn't perfect, but it at least seems to fix the issue on the angular.js distributed via bower.

jacksonrayhamilton avatar Jul 09 '15 23:07 jacksonrayhamilton

I have verified that @jacksonrayhamilton 's solution works wonderfully on v1.2.26

LoganLehman avatar Jul 22 '15 22:07 LoganLehman

For me @jacksonrayhamilton 's solution also works flawlessly on v1.4.1

EikeLueders avatar Jul 28 '15 06:07 EikeLueders

I mentioned before that patching AngularJS worked for me, in a new project it was not enough. I used the utility that @jacksonrayhamilton posted and now it works, thanks! (v1.3.16 and 1.4.3)

Nivani avatar Jul 28 '15 10:07 Nivani

This was finally fixed in webkit https://bugs.webkit.org/show_bug.cgi?id=138038#c21 but it will take some time for the updates to be on everybody's phone

lgalfaso avatar Jul 28 '15 19:07 lgalfaso

I am using this patch and it created another issue on angularjs 1.4.3 (previously I used 1.2.28): If you have directive with isolated scope that contains ngRepeat (or another ng directive that creates new scope) it won't evaluate any expressions inside the ngRepeat HTML. It will just print "text with {{ variableName }}" instead of the value. Here is the issue: http://stackoverflow.com/questions/31919921/angularjs-1-4-3-ngrepeat-prints-variablename-instead-of-value-when-used-in

iliyanwhich avatar Aug 10 '15 15:08 iliyanwhich

We are using:

{
    ...
    "angular": "1.3.1",
    "angular-translate": "2.4.2",
    "ui-route": "0.2.15",
    ...
}

And as @brauliodiez described we just got rid of the "undefined" by changing the way we are using translate,

from not working using:

<h1 translate>resetPassword.ChangePassword</h1>

to working with:

<h1>{{::'resetPassword.ChangePassword' | translate}}</h1>

We haven't used any monkey patch or hasn't removed 'use strict';

onesoftdk avatar Aug 11 '15 11:08 onesoftdk

+1 on efficacy of @jacksonrayhamilton solution using Angular 1.3.16. Can also confirm that this problem basically breaks apps that use Angular Material.

cgewecke avatar Aug 11 '15 20:08 cgewecke

@johgusta solution worked really well on our website, plus it looks much safer as it is not rewriting Angular internals.

albertogasparin avatar Aug 17 '15 09:08 albertogasparin

I ran into this issue yesterday, got "readonly property" error. but it's very strange that this bug is not always appear. I use the same simulater & sourcecode in same mac air notebook, sometimes got error, sometimes no error at all.

huan avatar Aug 17 '15 11:08 huan

Currently getting this error on iOS 8.4.1, angular 1.4.3. Only getting this on iPad mini.

wesjones avatar Aug 19 '15 18:08 wesjones

@jacksonrayhamilton I went to try the utility but I'm a little clear on "create a transformed angular.webkitassign.js in the same directory". I'm not sure what I do there.

alscheuring avatar Aug 30 '15 01:08 alscheuring

@alscheuring, in the future please file issues for webkit-assign on our Issues page.

webkit-assign provides a command-line interface. Open a terminal and do npm install -g webkit-assign to install the program. cd to the directory of a file you'd like to transform. Then type webkit-assign FILENAME.js (where "FILENAME.js" should be replaced with an actual filename), and the program will produce a fixed copy of the file in the same directory.

jacksonrayhamilton avatar Aug 30 '15 18:08 jacksonrayhamilton

Many thanks to @jacksonrayhamilton's solution. Worked perfectly. I have used @jhunken's patch but it seemed to only reduce the frequency in which the error occurs (still seems to happen randomly).

ronaldcurtis avatar Sep 15 '15 04:09 ronaldcurtis

@jacksonrayhamilton's solution is great. We're transforming angular.js with a custom webpack loader:

// webpackConfig.js (an excerpt)

{
  module: {
    loaders: [
      {
        test: /angular\.js$/,
        loader: path.join(__dirname, 'webpack/webkitAssignLoader')
      }
    ]
  }
}
// webkitAssignLoader.js

var webkitAssign = require('webkit-assign');

module.exports = function (source) {
  this.cacheable();
  return webkitAssign(source);
};

Cinamonas avatar Sep 15 '15 08:09 Cinamonas

I published @Cinamonas' loader: https://www.npmjs.com/package/webkit-assign-loader

wombleton avatar Sep 21 '15 02:09 wombleton

@johgusta @albertogasparin Which version of Angular are you guys using to claim that this solution (https://gist.github.com/johgusta/46fb1ecd459dbc3bfdfc) is working? This fix doesn't work for us with Angular-1.4.6.

skusunam avatar Sep 24 '15 19:09 skusunam

@johgusta's solution solved my problem in angular 1.4.2

brunofranco avatar Sep 30 '15 09:09 brunofranco

@johgusta's solution appears to have solved our issues in angular 1.4.5

atMari avatar Oct 12 '15 19:10 atMari

+1, tried with 1.4.0, 1.4.6 same story. How I can intelligently patch Angular if I don't use webpack?

shershen08 avatar Nov 05 '15 11:11 shershen08