(iOS 8 GM iPhone5C) TypeError: Attempted to assign to readonly property
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...
Spent the afternoon looking for a way to reproduce the error in a controlled environment but still no solutions sadly.
I've expanded a bit the workaround of @HAKASHUN so if anyone needs a fast - notSoGood - fix this is what I did.
AngularJS ver. 1.3.6:
RootScope https://github.com/angular/angular.js/blob/master/src/ng/rootScope.js#L208 From:
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;
};
To:
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;
};
https://github.com/angular/angular.js/blob/master/src/ng/rootScope.js#L221 From:
child.$parent = parent;
child.$$prevSibling = parent.$$childTail;
To:
child['$parent'] = parent;
child['$$prevSibling'] = parent.$$childTail;
Compile https://github.com/angular/angular.js/blob/master/src/ng/compile.js#L1375 From:
transcludedScope.$$transcluded = true;
To
transcludedScope['$$transcluded'] = true;
Until now I am not able to help you with more informations, will keep looking into the issue.
I figured this one out. iOS dies on this line:
this.$$watchers = this.$$nextSibling =
this.$$childHead = this.$$childTail = null;
When I broke this out into separate statements, I found the error was caused when this.$$watchers was assigned first. The following worked correctly:
this.$$childTail = null;
this.$$childHead = null;
this.$$nextSibling = null;
this.$$watchers = null;
I suspect iOS executes the order of the assignment incorrectly, causing the error. I don't know where else this syntax difference would cause errors, but I suspect it has far reaching implications.
@Wasmoo wow, this sounds strange. Are you able to isolate this thing in a minimal example, ideally in plunker? If so this would be definitively an issue on the browser side.
@pkozlowski-opensource Unfortunately no. I just ran into the error on the project I'm working on and I have no idea of its source (jQuery throws something at Angular). As it is in my project, you have to click on just the right things in just the right order to get the error to occur, but this and only this change fixes my problem.
Hopefully someone else who is getting the error can confirm the fix.
We are experiencing this problem in 'heavy' page filled with several scopes and template, simplifying this out in a plunker seems really difficoult :/
I'll try @Wasmoo's fix out, will post back the result on our codebase in a couple minutes.
Nope @Wasmoo's is not solving the issue in our codebase.
:-( Sadness! I also confirmed that iOS does assignment in this syntax in the correct order:
j.a = j.b = j.c = 0;
is equivalent to
j.c = 0;
j.b = 0;
j.a = 0;
So that throws that theory out, though I can't explain why my fix works for me.
For what it's worth, my project is still broken - my fix only moved the bug so it fails in the same way at some other point.
@Wasmoo by applying my workaround you should be able to remove the problem (still you're gonna have to maintain for the next angular versions)
@m3kka Works like magic!
@m3kka would it mean that Safari on iOS doesn't like dotted access to properties staring with $? Hmm, there must be something additional going on...
Here's a monkey patch I created to not have to modify the angular.js source code directly. I've been using it for the past few weeks with no more issues. It was based on angular 1.3.3.
https://gist.github.com/jhunken/767cdf62ecc9f31c56da
I also haven't been able to reproduce this issue with a minimal example unfortunately.
If someone is looking for a solution without having to use a patched version of Angular, you could try the following.
I had a couple nested state controllers for ui-router and noticed the error was being triggered by a couple lines that were accessing variables on a parent scope. In an attempt to gain access to these variables without going through the scope I set up my controller using the Controller as syntax. This made it so I could access the variables directly without having to traverse up the scopes.
Not sure if this will work for everyone but my application no longer throws the error.
@pkozlowski-opensource I think that IOS is somehow messing up with the readonly property on js objects. Apparently accessing the elements with the 'key notation' (can't remember the actual name) ignores this mess up.
Also apparently Angular is not the only one affected by this issue -http://craigsworks.com/projects/forums/showthread.php?tid=3649
@jhunken You made me bash my head. Should have used decorators from the beginning. Thank you :)
I have the same problem. Suggested workaround seems to solved it. I use @jhunken's decorator.
Noob question: what does this issue being in purgatory milestone mean? It doesn't sound good.
I still have yet to reproduce this, and I have wasted a lot of time trying. I am however happy to say that @jhunken 's monkey patch seems to have solved my problems for now. I look forward to figuring out why this works since I squandered so much time stepping through this process over/over without getting any results.
Adding some details that probably are not useful on their own, but... On iOS 8.1.2 iPad 2 and mini I have seen the "TypeError: Attempted to assign to readonly property". It's a large app, so hard to get into plunkr.
We had the issue appearing consistently using Angular 1.3.7 (we had removed 'use strict' from the min file for v1.3 to fix this same problem, but didn't remove it after the upgrade). Last time the error was popping up in a different place in the app and was less consistent. This time we had repro steps to do it on demand. Removing 'use strict' from angular.min.js fixed the issue. The final step before the error involved changing the route (we use the standard router: ngRoute). In our case this resulted in a data grid with no data and the messages weren't translated (using the translate directive from pascalprecht.translate). Switching the route again using the same dropdown or refreshing would get the page working again.
I do believe this is a mobile safari bug because we do not see it in any other browser.
This seems to be an iOS 8 bug - http://stackoverflow.com/a/27401601
On bugsnag error logs for my application I also see that only on Mobile safari with iOS 8.0 and 8.1
Below is a stack trace for angular 1.2.28. The same issue is there also for 1.2.24.
TypeError Attempted to assign to readonly property.
angular.js:12188:37 $$childScopeClass
angular.js:12198:8 prototype
angular.js:6161:29
angular.js:6773:35 controllersBoundTransclude
angular.js:21409:16 link
angular.js:6752:19 nodeLinkFn
angular.js:6146:23 compositeLinkFn
angular.js:6746:35 nodeLinkFn
angular.js:6954:36
angular.js:8171:13
angular.js:11682:81 wrappedCallback
angular.js:11768:34
angular.js:12811:28 prototype
angular.js:12623:36 prototype
angular.js:12915:12 prototype
angular.js:19264:29
angular.js:2853:14
angular.js:325:22 forEach
angular.js:2852:12 eventHandler
Is there any other fix for this besides removing 'use strict'? I would like to CDN angular and this would disable it...
edit: using gist works. sorry about that
Monkey patching worked for me too, Obviously not a good solution, and this is a bug that is breaking angular out in production. Looks like ios8 webkit really dislikes assignment of .$$variables
For some info, I had to patch compile.js as my directives compile phase was being borked.
transcludedScope['$$transcluded'] = true;