Array state will be cached in iOS 12 Safari. Is it a bug or feature?
Clash Royale CLAN TAG#URR8PPP
up vote
248
down vote
favorite
Today I found some problem of Array's value state in the newly released iOSÂ 12 Safari, for example, code like this:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>iOS 12 Safari bugs</title>
<script type="text/javascript">
window.addEventListener("load", function ()
let arr = [1, 2, 3, 4, 5];
alert(arr.join());
document.querySelector("button").addEventListener("click", function ()
arr.reverse();
);
);
</script>
</head>
<body>
<button>Array.reverse()</button>
<p style="color:red;">test: click button and refresh page, code:</p>
</body>
</html>
After refreshing the page, the array's value is still reversed. Is this a bug or a feature of new Safari?
Here is a demo page. Try to use it with iOS 12 Safari:
https://cdn.miss.cat/demo/ios12-safari-bug.html
javascript ios safari ios12
New contributor
add a comment |Â
up vote
248
down vote
favorite
Today I found some problem of Array's value state in the newly released iOSÂ 12 Safari, for example, code like this:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>iOS 12 Safari bugs</title>
<script type="text/javascript">
window.addEventListener("load", function ()
let arr = [1, 2, 3, 4, 5];
alert(arr.join());
document.querySelector("button").addEventListener("click", function ()
arr.reverse();
);
);
</script>
</head>
<body>
<button>Array.reverse()</button>
<p style="color:red;">test: click button and refresh page, code:</p>
</body>
</html>
After refreshing the page, the array's value is still reversed. Is this a bug or a feature of new Safari?
Here is a demo page. Try to use it with iOS 12 Safari:
https://cdn.miss.cat/demo/ios12-safari-bug.html
javascript ios safari ios12
New contributor
23
Bug confirmed also in macOS 10.14 Mojave - i.imgur.com/ZJtJJC1.png
â a_rahmanshah
19 hours ago
26
macOS 10.13.6 (High Sierra) with Safari Version 12.0 (13606.2.11) has the same issue. Array is still reversed after refreshing the page.
â Kevin Gimbel
17 hours ago
3
when someone ask if it's a feature or a bug.... is always the second:)
â Taioli Francesco
14 hours ago
1
@TaioliFrancesco unless its something by Bethesda :P
â Christopher Nuccio
11 hours ago
add a comment |Â
up vote
248
down vote
favorite
up vote
248
down vote
favorite
Today I found some problem of Array's value state in the newly released iOSÂ 12 Safari, for example, code like this:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>iOS 12 Safari bugs</title>
<script type="text/javascript">
window.addEventListener("load", function ()
let arr = [1, 2, 3, 4, 5];
alert(arr.join());
document.querySelector("button").addEventListener("click", function ()
arr.reverse();
);
);
</script>
</head>
<body>
<button>Array.reverse()</button>
<p style="color:red;">test: click button and refresh page, code:</p>
</body>
</html>
After refreshing the page, the array's value is still reversed. Is this a bug or a feature of new Safari?
Here is a demo page. Try to use it with iOS 12 Safari:
https://cdn.miss.cat/demo/ios12-safari-bug.html
javascript ios safari ios12
New contributor
Today I found some problem of Array's value state in the newly released iOSÂ 12 Safari, for example, code like this:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>iOS 12 Safari bugs</title>
<script type="text/javascript">
window.addEventListener("load", function ()
let arr = [1, 2, 3, 4, 5];
alert(arr.join());
document.querySelector("button").addEventListener("click", function ()
arr.reverse();
);
);
</script>
</head>
<body>
<button>Array.reverse()</button>
<p style="color:red;">test: click button and refresh page, code:</p>
</body>
</html>
After refreshing the page, the array's value is still reversed. Is this a bug or a feature of new Safari?
Here is a demo page. Try to use it with iOS 12 Safari:
https://cdn.miss.cat/demo/ios12-safari-bug.html
javascript ios safari ios12
javascript ios safari ios12
New contributor
New contributor
edited 15 mins ago
Peter Mortensen
13k1983111
13k1983111
New contributor
asked yesterday
abelyao
306237
306237
New contributor
New contributor
23
Bug confirmed also in macOS 10.14 Mojave - i.imgur.com/ZJtJJC1.png
â a_rahmanshah
19 hours ago
26
macOS 10.13.6 (High Sierra) with Safari Version 12.0 (13606.2.11) has the same issue. Array is still reversed after refreshing the page.
â Kevin Gimbel
17 hours ago
3
when someone ask if it's a feature or a bug.... is always the second:)
â Taioli Francesco
14 hours ago
1
@TaioliFrancesco unless its something by Bethesda :P
â Christopher Nuccio
11 hours ago
add a comment |Â
23
Bug confirmed also in macOS 10.14 Mojave - i.imgur.com/ZJtJJC1.png
â a_rahmanshah
19 hours ago
26
macOS 10.13.6 (High Sierra) with Safari Version 12.0 (13606.2.11) has the same issue. Array is still reversed after refreshing the page.
â Kevin Gimbel
17 hours ago
3
when someone ask if it's a feature or a bug.... is always the second:)
â Taioli Francesco
14 hours ago
1
@TaioliFrancesco unless its something by Bethesda :P
â Christopher Nuccio
11 hours ago
23
23
Bug confirmed also in macOS 10.14 Mojave - i.imgur.com/ZJtJJC1.png
â a_rahmanshah
19 hours ago
Bug confirmed also in macOS 10.14 Mojave - i.imgur.com/ZJtJJC1.png
â a_rahmanshah
19 hours ago
26
26
macOS 10.13.6 (High Sierra) with Safari Version 12.0 (13606.2.11) has the same issue. Array is still reversed after refreshing the page.
â Kevin Gimbel
17 hours ago
macOS 10.13.6 (High Sierra) with Safari Version 12.0 (13606.2.11) has the same issue. Array is still reversed after refreshing the page.
â Kevin Gimbel
17 hours ago
3
3
when someone ask if it's a feature or a bug.... is always the second:)
â Taioli Francesco
14 hours ago
when someone ask if it's a feature or a bug.... is always the second:)
â Taioli Francesco
14 hours ago
1
1
@TaioliFrancesco unless its something by Bethesda :P
â Christopher Nuccio
11 hours ago
@TaioliFrancesco unless its something by Bethesda :P
â Christopher Nuccio
11 hours ago
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
169
down vote
It's definitely a BUG! And it's a very serious bug.
Per my testing, the bug is due to the optimization of array initializers in which all values are primitive literals. For example, () => [1, null, 'x']
will result in such an array; all returned array references from this lambda will link to the same memory address, and some method like toString()
will be cached. Normally, any mutable operation on such arrays will copy the data to a separate memory space and link to it; this is called copy-on-write, or CoW for short.
The reverse()
method mutates the array, so it should trigger a copy-on-write. Apparently, it no longer does so, which causes the bug youâÂÂre seeing.
On the other hand, all methods which do not modify the array should not trigger CoW, and IâÂÂve found that even a.fill(value, 0, 0)
or a.copyWithin(index, 0, 0)
won't trigger CoW because such callings don't really mutate the array. But I noticed that a.slice()
WILL trigger CoW. So, if I had to guess, IâÂÂd say the underlying cause of this bug may be that someone accidentally swapped the indices of My guess is not correct, the original author (Keith Miller @ Apple) just simply miss the slice
and reverse
.reverse()
case though he already wrote many test cases. slice()
is a separate story, may be related to fastSlice optimization though I still don't understand the reason. Anyway, unnecessary CoW won't cause bug.
7
Note: Safari 12.0 on Mac OS X also have the same issue.
â hax
16 hours ago
5
Yeah itâÂÂs been fixed in the sources already, and shipped in Safari Technology Preview already. Try cdn.miss.cat/demo/ios12-safari-bug.html in Safari Technology Preview 65. YouâÂÂll find that it doesnâÂÂt have the bug.
â sideshowbarker
16 hours ago
3
I donâÂÂt believe the underlying cause of the bug is the result of an index mixup; instead, it seems to be caused by neglecting to check whether an object is immutable before modifying it. The slice issue may have a similar explanation, but itâÂÂs not the same but and wonâÂÂt be fixed by the patch for reverse, as far as I can tell. You should consider opening a WebKit bug report for the slice issue.
â Zenexer
13 hours ago
1
@Zenexer You are right. I wrote this answer before I found the bugs.webkit.org/show_bug.cgi?id=188794 and see the source code. I will edit my answer.
â hax
13 hours ago
add a comment |Â
up vote
33
down vote
I wrote a lib to fix the bug.
https://www.npmjs.com/package/array-reverse-polyfill
This is the code:
(function()
function buggy()
var a = [1, 2];
return String(a) === String(a.reverse());
if(!buggy()) return;
var r = Array.prototype.reverse;
Array.prototype.reverse = function reverse()
if (Array.isArray(this)) this.length = this.length;
return r.call(this);
)();
2
Update at any time. Welcome to contribute.
â Edire Fan
16 hours ago
2
@EdireFan why does this work?
â zephi
7 hours ago
1
@zephi, I guess that writing on length (this.length = this.length
) will trigger Copy On Write, so will change the memory address of the array, and so will fix the behavior ofreverse
.
â Cà Âur
2 hours ago
add a comment |Â
up vote
0
down vote
It seems not to be cached if the number of elements changes.
I was able to avoid this like this.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>iOS 12 Safari bugs</title>
<script type="text/javascript">
window.addEventListener("load", function ()
let arr = [1, 2, 3, 4, 5];
arr.push('');
arr.pop();
alert(arr.join());
document.querySelector("button").addEventListener("click", function ()
arr.reverse();
);
);
</script>
</head>
<body>
<button>Array.reverse()</button>
<p style="color:red;">test: click button and refresh page, code:</p>
</body>
</html>
New contributor
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
169
down vote
It's definitely a BUG! And it's a very serious bug.
Per my testing, the bug is due to the optimization of array initializers in which all values are primitive literals. For example, () => [1, null, 'x']
will result in such an array; all returned array references from this lambda will link to the same memory address, and some method like toString()
will be cached. Normally, any mutable operation on such arrays will copy the data to a separate memory space and link to it; this is called copy-on-write, or CoW for short.
The reverse()
method mutates the array, so it should trigger a copy-on-write. Apparently, it no longer does so, which causes the bug youâÂÂre seeing.
On the other hand, all methods which do not modify the array should not trigger CoW, and IâÂÂve found that even a.fill(value, 0, 0)
or a.copyWithin(index, 0, 0)
won't trigger CoW because such callings don't really mutate the array. But I noticed that a.slice()
WILL trigger CoW. So, if I had to guess, IâÂÂd say the underlying cause of this bug may be that someone accidentally swapped the indices of My guess is not correct, the original author (Keith Miller @ Apple) just simply miss the slice
and reverse
.reverse()
case though he already wrote many test cases. slice()
is a separate story, may be related to fastSlice optimization though I still don't understand the reason. Anyway, unnecessary CoW won't cause bug.
7
Note: Safari 12.0 on Mac OS X also have the same issue.
â hax
16 hours ago
5
Yeah itâÂÂs been fixed in the sources already, and shipped in Safari Technology Preview already. Try cdn.miss.cat/demo/ios12-safari-bug.html in Safari Technology Preview 65. YouâÂÂll find that it doesnâÂÂt have the bug.
â sideshowbarker
16 hours ago
3
I donâÂÂt believe the underlying cause of the bug is the result of an index mixup; instead, it seems to be caused by neglecting to check whether an object is immutable before modifying it. The slice issue may have a similar explanation, but itâÂÂs not the same but and wonâÂÂt be fixed by the patch for reverse, as far as I can tell. You should consider opening a WebKit bug report for the slice issue.
â Zenexer
13 hours ago
1
@Zenexer You are right. I wrote this answer before I found the bugs.webkit.org/show_bug.cgi?id=188794 and see the source code. I will edit my answer.
â hax
13 hours ago
add a comment |Â
up vote
169
down vote
It's definitely a BUG! And it's a very serious bug.
Per my testing, the bug is due to the optimization of array initializers in which all values are primitive literals. For example, () => [1, null, 'x']
will result in such an array; all returned array references from this lambda will link to the same memory address, and some method like toString()
will be cached. Normally, any mutable operation on such arrays will copy the data to a separate memory space and link to it; this is called copy-on-write, or CoW for short.
The reverse()
method mutates the array, so it should trigger a copy-on-write. Apparently, it no longer does so, which causes the bug youâÂÂre seeing.
On the other hand, all methods which do not modify the array should not trigger CoW, and IâÂÂve found that even a.fill(value, 0, 0)
or a.copyWithin(index, 0, 0)
won't trigger CoW because such callings don't really mutate the array. But I noticed that a.slice()
WILL trigger CoW. So, if I had to guess, IâÂÂd say the underlying cause of this bug may be that someone accidentally swapped the indices of My guess is not correct, the original author (Keith Miller @ Apple) just simply miss the slice
and reverse
.reverse()
case though he already wrote many test cases. slice()
is a separate story, may be related to fastSlice optimization though I still don't understand the reason. Anyway, unnecessary CoW won't cause bug.
7
Note: Safari 12.0 on Mac OS X also have the same issue.
â hax
16 hours ago
5
Yeah itâÂÂs been fixed in the sources already, and shipped in Safari Technology Preview already. Try cdn.miss.cat/demo/ios12-safari-bug.html in Safari Technology Preview 65. YouâÂÂll find that it doesnâÂÂt have the bug.
â sideshowbarker
16 hours ago
3
I donâÂÂt believe the underlying cause of the bug is the result of an index mixup; instead, it seems to be caused by neglecting to check whether an object is immutable before modifying it. The slice issue may have a similar explanation, but itâÂÂs not the same but and wonâÂÂt be fixed by the patch for reverse, as far as I can tell. You should consider opening a WebKit bug report for the slice issue.
â Zenexer
13 hours ago
1
@Zenexer You are right. I wrote this answer before I found the bugs.webkit.org/show_bug.cgi?id=188794 and see the source code. I will edit my answer.
â hax
13 hours ago
add a comment |Â
up vote
169
down vote
up vote
169
down vote
It's definitely a BUG! And it's a very serious bug.
Per my testing, the bug is due to the optimization of array initializers in which all values are primitive literals. For example, () => [1, null, 'x']
will result in such an array; all returned array references from this lambda will link to the same memory address, and some method like toString()
will be cached. Normally, any mutable operation on such arrays will copy the data to a separate memory space and link to it; this is called copy-on-write, or CoW for short.
The reverse()
method mutates the array, so it should trigger a copy-on-write. Apparently, it no longer does so, which causes the bug youâÂÂre seeing.
On the other hand, all methods which do not modify the array should not trigger CoW, and IâÂÂve found that even a.fill(value, 0, 0)
or a.copyWithin(index, 0, 0)
won't trigger CoW because such callings don't really mutate the array. But I noticed that a.slice()
WILL trigger CoW. So, if I had to guess, IâÂÂd say the underlying cause of this bug may be that someone accidentally swapped the indices of My guess is not correct, the original author (Keith Miller @ Apple) just simply miss the slice
and reverse
.reverse()
case though he already wrote many test cases. slice()
is a separate story, may be related to fastSlice optimization though I still don't understand the reason. Anyway, unnecessary CoW won't cause bug.
It's definitely a BUG! And it's a very serious bug.
Per my testing, the bug is due to the optimization of array initializers in which all values are primitive literals. For example, () => [1, null, 'x']
will result in such an array; all returned array references from this lambda will link to the same memory address, and some method like toString()
will be cached. Normally, any mutable operation on such arrays will copy the data to a separate memory space and link to it; this is called copy-on-write, or CoW for short.
The reverse()
method mutates the array, so it should trigger a copy-on-write. Apparently, it no longer does so, which causes the bug youâÂÂre seeing.
On the other hand, all methods which do not modify the array should not trigger CoW, and IâÂÂve found that even a.fill(value, 0, 0)
or a.copyWithin(index, 0, 0)
won't trigger CoW because such callings don't really mutate the array. But I noticed that a.slice()
WILL trigger CoW. So, if I had to guess, IâÂÂd say the underlying cause of this bug may be that someone accidentally swapped the indices of My guess is not correct, the original author (Keith Miller @ Apple) just simply miss the slice
and reverse
.reverse()
case though he already wrote many test cases. slice()
is a separate story, may be related to fastSlice optimization though I still don't understand the reason. Anyway, unnecessary CoW won't cause bug.
edited 13 hours ago
answered yesterday
hax
4841310
4841310
7
Note: Safari 12.0 on Mac OS X also have the same issue.
â hax
16 hours ago
5
Yeah itâÂÂs been fixed in the sources already, and shipped in Safari Technology Preview already. Try cdn.miss.cat/demo/ios12-safari-bug.html in Safari Technology Preview 65. YouâÂÂll find that it doesnâÂÂt have the bug.
â sideshowbarker
16 hours ago
3
I donâÂÂt believe the underlying cause of the bug is the result of an index mixup; instead, it seems to be caused by neglecting to check whether an object is immutable before modifying it. The slice issue may have a similar explanation, but itâÂÂs not the same but and wonâÂÂt be fixed by the patch for reverse, as far as I can tell. You should consider opening a WebKit bug report for the slice issue.
â Zenexer
13 hours ago
1
@Zenexer You are right. I wrote this answer before I found the bugs.webkit.org/show_bug.cgi?id=188794 and see the source code. I will edit my answer.
â hax
13 hours ago
add a comment |Â
7
Note: Safari 12.0 on Mac OS X also have the same issue.
â hax
16 hours ago
5
Yeah itâÂÂs been fixed in the sources already, and shipped in Safari Technology Preview already. Try cdn.miss.cat/demo/ios12-safari-bug.html in Safari Technology Preview 65. YouâÂÂll find that it doesnâÂÂt have the bug.
â sideshowbarker
16 hours ago
3
I donâÂÂt believe the underlying cause of the bug is the result of an index mixup; instead, it seems to be caused by neglecting to check whether an object is immutable before modifying it. The slice issue may have a similar explanation, but itâÂÂs not the same but and wonâÂÂt be fixed by the patch for reverse, as far as I can tell. You should consider opening a WebKit bug report for the slice issue.
â Zenexer
13 hours ago
1
@Zenexer You are right. I wrote this answer before I found the bugs.webkit.org/show_bug.cgi?id=188794 and see the source code. I will edit my answer.
â hax
13 hours ago
7
7
Note: Safari 12.0 on Mac OS X also have the same issue.
â hax
16 hours ago
Note: Safari 12.0 on Mac OS X also have the same issue.
â hax
16 hours ago
5
5
Yeah itâÂÂs been fixed in the sources already, and shipped in Safari Technology Preview already. Try cdn.miss.cat/demo/ios12-safari-bug.html in Safari Technology Preview 65. YouâÂÂll find that it doesnâÂÂt have the bug.
â sideshowbarker
16 hours ago
Yeah itâÂÂs been fixed in the sources already, and shipped in Safari Technology Preview already. Try cdn.miss.cat/demo/ios12-safari-bug.html in Safari Technology Preview 65. YouâÂÂll find that it doesnâÂÂt have the bug.
â sideshowbarker
16 hours ago
3
3
I donâÂÂt believe the underlying cause of the bug is the result of an index mixup; instead, it seems to be caused by neglecting to check whether an object is immutable before modifying it. The slice issue may have a similar explanation, but itâÂÂs not the same but and wonâÂÂt be fixed by the patch for reverse, as far as I can tell. You should consider opening a WebKit bug report for the slice issue.
â Zenexer
13 hours ago
I donâÂÂt believe the underlying cause of the bug is the result of an index mixup; instead, it seems to be caused by neglecting to check whether an object is immutable before modifying it. The slice issue may have a similar explanation, but itâÂÂs not the same but and wonâÂÂt be fixed by the patch for reverse, as far as I can tell. You should consider opening a WebKit bug report for the slice issue.
â Zenexer
13 hours ago
1
1
@Zenexer You are right. I wrote this answer before I found the bugs.webkit.org/show_bug.cgi?id=188794 and see the source code. I will edit my answer.
â hax
13 hours ago
@Zenexer You are right. I wrote this answer before I found the bugs.webkit.org/show_bug.cgi?id=188794 and see the source code. I will edit my answer.
â hax
13 hours ago
add a comment |Â
up vote
33
down vote
I wrote a lib to fix the bug.
https://www.npmjs.com/package/array-reverse-polyfill
This is the code:
(function()
function buggy()
var a = [1, 2];
return String(a) === String(a.reverse());
if(!buggy()) return;
var r = Array.prototype.reverse;
Array.prototype.reverse = function reverse()
if (Array.isArray(this)) this.length = this.length;
return r.call(this);
)();
2
Update at any time. Welcome to contribute.
â Edire Fan
16 hours ago
2
@EdireFan why does this work?
â zephi
7 hours ago
1
@zephi, I guess that writing on length (this.length = this.length
) will trigger Copy On Write, so will change the memory address of the array, and so will fix the behavior ofreverse
.
â Cà Âur
2 hours ago
add a comment |Â
up vote
33
down vote
I wrote a lib to fix the bug.
https://www.npmjs.com/package/array-reverse-polyfill
This is the code:
(function()
function buggy()
var a = [1, 2];
return String(a) === String(a.reverse());
if(!buggy()) return;
var r = Array.prototype.reverse;
Array.prototype.reverse = function reverse()
if (Array.isArray(this)) this.length = this.length;
return r.call(this);
)();
2
Update at any time. Welcome to contribute.
â Edire Fan
16 hours ago
2
@EdireFan why does this work?
â zephi
7 hours ago
1
@zephi, I guess that writing on length (this.length = this.length
) will trigger Copy On Write, so will change the memory address of the array, and so will fix the behavior ofreverse
.
â Cà Âur
2 hours ago
add a comment |Â
up vote
33
down vote
up vote
33
down vote
I wrote a lib to fix the bug.
https://www.npmjs.com/package/array-reverse-polyfill
This is the code:
(function()
function buggy()
var a = [1, 2];
return String(a) === String(a.reverse());
if(!buggy()) return;
var r = Array.prototype.reverse;
Array.prototype.reverse = function reverse()
if (Array.isArray(this)) this.length = this.length;
return r.call(this);
)();
I wrote a lib to fix the bug.
https://www.npmjs.com/package/array-reverse-polyfill
This is the code:
(function()
function buggy()
var a = [1, 2];
return String(a) === String(a.reverse());
if(!buggy()) return;
var r = Array.prototype.reverse;
Array.prototype.reverse = function reverse()
if (Array.isArray(this)) this.length = this.length;
return r.call(this);
)();
(function()
function buggy()
var a = [1, 2];
return String(a) === String(a.reverse());
if(!buggy()) return;
var r = Array.prototype.reverse;
Array.prototype.reverse = function reverse()
if (Array.isArray(this)) this.length = this.length;
return r.call(this);
)();
(function()
function buggy()
var a = [1, 2];
return String(a) === String(a.reverse());
if(!buggy()) return;
var r = Array.prototype.reverse;
Array.prototype.reverse = function reverse()
if (Array.isArray(this)) this.length = this.length;
return r.call(this);
)();
edited 9 hours ago
Communityâ¦
11
11
answered yesterday
Edire Fan
26127
26127
2
Update at any time. Welcome to contribute.
â Edire Fan
16 hours ago
2
@EdireFan why does this work?
â zephi
7 hours ago
1
@zephi, I guess that writing on length (this.length = this.length
) will trigger Copy On Write, so will change the memory address of the array, and so will fix the behavior ofreverse
.
â Cà Âur
2 hours ago
add a comment |Â
2
Update at any time. Welcome to contribute.
â Edire Fan
16 hours ago
2
@EdireFan why does this work?
â zephi
7 hours ago
1
@zephi, I guess that writing on length (this.length = this.length
) will trigger Copy On Write, so will change the memory address of the array, and so will fix the behavior ofreverse
.
â Cà Âur
2 hours ago
2
2
Update at any time. Welcome to contribute.
â Edire Fan
16 hours ago
Update at any time. Welcome to contribute.
â Edire Fan
16 hours ago
2
2
@EdireFan why does this work?
â zephi
7 hours ago
@EdireFan why does this work?
â zephi
7 hours ago
1
1
@zephi, I guess that writing on length (
this.length = this.length
) will trigger Copy On Write, so will change the memory address of the array, and so will fix the behavior of reverse
.â Cà Âur
2 hours ago
@zephi, I guess that writing on length (
this.length = this.length
) will trigger Copy On Write, so will change the memory address of the array, and so will fix the behavior of reverse
.â Cà Âur
2 hours ago
add a comment |Â
up vote
0
down vote
It seems not to be cached if the number of elements changes.
I was able to avoid this like this.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>iOS 12 Safari bugs</title>
<script type="text/javascript">
window.addEventListener("load", function ()
let arr = [1, 2, 3, 4, 5];
arr.push('');
arr.pop();
alert(arr.join());
document.querySelector("button").addEventListener("click", function ()
arr.reverse();
);
);
</script>
</head>
<body>
<button>Array.reverse()</button>
<p style="color:red;">test: click button and refresh page, code:</p>
</body>
</html>
New contributor
add a comment |Â
up vote
0
down vote
It seems not to be cached if the number of elements changes.
I was able to avoid this like this.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>iOS 12 Safari bugs</title>
<script type="text/javascript">
window.addEventListener("load", function ()
let arr = [1, 2, 3, 4, 5];
arr.push('');
arr.pop();
alert(arr.join());
document.querySelector("button").addEventListener("click", function ()
arr.reverse();
);
);
</script>
</head>
<body>
<button>Array.reverse()</button>
<p style="color:red;">test: click button and refresh page, code:</p>
</body>
</html>
New contributor
add a comment |Â
up vote
0
down vote
up vote
0
down vote
It seems not to be cached if the number of elements changes.
I was able to avoid this like this.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>iOS 12 Safari bugs</title>
<script type="text/javascript">
window.addEventListener("load", function ()
let arr = [1, 2, 3, 4, 5];
arr.push('');
arr.pop();
alert(arr.join());
document.querySelector("button").addEventListener("click", function ()
arr.reverse();
);
);
</script>
</head>
<body>
<button>Array.reverse()</button>
<p style="color:red;">test: click button and refresh page, code:</p>
</body>
</html>
New contributor
It seems not to be cached if the number of elements changes.
I was able to avoid this like this.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>iOS 12 Safari bugs</title>
<script type="text/javascript">
window.addEventListener("load", function ()
let arr = [1, 2, 3, 4, 5];
arr.push('');
arr.pop();
alert(arr.join());
document.querySelector("button").addEventListener("click", function ()
arr.reverse();
);
);
</script>
</head>
<body>
<button>Array.reverse()</button>
<p style="color:red;">test: click button and refresh page, code:</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>iOS 12 Safari bugs</title>
<script type="text/javascript">
window.addEventListener("load", function ()
let arr = [1, 2, 3, 4, 5];
arr.push('');
arr.pop();
alert(arr.join());
document.querySelector("button").addEventListener("click", function ()
arr.reverse();
);
);
</script>
</head>
<body>
<button>Array.reverse()</button>
<p style="color:red;">test: click button and refresh page, code:</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>iOS 12 Safari bugs</title>
<script type="text/javascript">
window.addEventListener("load", function ()
let arr = [1, 2, 3, 4, 5];
arr.push('');
arr.pop();
alert(arr.join());
document.querySelector("button").addEventListener("click", function ()
arr.reverse();
);
);
</script>
</head>
<body>
<button>Array.reverse()</button>
<p style="color:red;">test: click button and refresh page, code:</p>
</body>
</html>
New contributor
New contributor
answered 6 mins ago
Atsushi Sasaki
1
1
New contributor
New contributor
add a comment |Â
add a comment |Â
abelyao is a new contributor. Be nice, and check out our Code of Conduct.
abelyao is a new contributor. Be nice, and check out our Code of Conduct.
abelyao is a new contributor. Be nice, and check out our Code of Conduct.
abelyao is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52390368%2farray-state-will-be-cached-in-ios-12-safari-is-it-a-bug-or-feature%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
23
Bug confirmed also in macOS 10.14 Mojave - i.imgur.com/ZJtJJC1.png
â a_rahmanshah
19 hours ago
26
macOS 10.13.6 (High Sierra) with Safari Version 12.0 (13606.2.11) has the same issue. Array is still reversed after refreshing the page.
â Kevin Gimbel
17 hours ago
3
when someone ask if it's a feature or a bug.... is always the second:)
â Taioli Francesco
14 hours ago
1
@TaioliFrancesco unless its something by Bethesda :P
â Christopher Nuccio
11 hours ago