Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit b65205b

Browse files
committed
[Merge chakra-core/ChakraCore@8a61170da3] [1.6>1.7] [MERGE #3452 @akroshg] Splice helper function should check for side-effect in the prototype.
Merge pull request #3452 from akroshg:os12444598 Splice has fast path which did not check the prototype (say you have proxy) properly which resulted to incorrect result. Fixed that by using the side-effect macro to take the slower and observable code path.
1 parent 8a90ffb commit b65205b

File tree

4 files changed

+31
-16
lines changed

4 files changed

+31
-16
lines changed

deps/chakrashim/core/lib/Runtime/Library/JavascriptArray.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6901,7 +6901,8 @@ namespace Js
69016901
Var* insertArgs = args.Info.Count > 3 ? &args.Values[3] : nullptr;
69026902
uint32 insertLen = args.Info.Count > 3 ? args.Info.Count - 3 : 0;
69036903

6904-
if (pArr != nullptr)
6904+
// Force check the prototype as we may insert values more than current elements
6905+
if (pArr != nullptr && !HasAnyES5ArrayInPrototypeChain(pArr, true /*forceCheckProtoChain*/))
69056906
{
69066907
// Since we get the length from an array and that cannot be more than uint32.
69076908
_Analysis_assume_(length <= UINT_MAX);

deps/chakrashim/core/test/Array/Array_TypeConfusion_bugs.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,5 +799,19 @@ var tests = [
799799
assert.areEqual(16, ret[0]);
800800
}
801801
},
802+
{
803+
name: "splice : the method splice should get property from prototype which is a proxy",
804+
body: function ()
805+
{
806+
var v1 = [];
807+
v1.length = 20;
808+
var hasCalled = 0;
809+
v1.__proto__ = new Proxy([222], {has : function() { hasCalled++;} });
810+
v1.push(1);
811+
assert.areEqual(222, v1[0]);
812+
var ret = v1.splice(0, 10);
813+
assert.areEqual(20, hasCalled);
814+
}
815+
},
802816
];
803817
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });

deps/chakrashim/core/test/Array/protoLookupWithGetters.baseline

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
Test case 1
2-
d1,d2,d3,d4,p5,p6,p7,p8,p9
2+
p0,p1,p2,p3,p4,p5,p6,p7,p8
33
9
44
p0,p1,p2,p3,p4
55
5
66

77
Test case 2
8-
d1,d2,d3,d4,d5,d6,d7,p5,p6,p7,p8,p9
8+
p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p8,p9
99
12
1010
p0,p1,p2,p3,p4
1111
5
1212

1313
Test case 3
14-
d1,d2,d3,d4,d5,d6,d7,p5,,p7,,p9
14+
d1,p1,d3,p3,d5,p5,d7,p7,,p9,,p9
1515
12
1616
,p1,,p3,
1717
5
1818

1919
Test case 4
20-
P0,P1,P2,d1,d2,d3,P8,P9
20+
P0,P1,P2,P3,P4,P5,P6,P7
2121
8
2222
P3,P4,P5,P6,P7
2323
5
2424

2525
Test case 5
26-
P0,P1,P2,d1,d2,d3,P8,P9
26+
P0,P1,P2,P3,P4,P5,P6,P7
2727
8
2828
P3,P4,P5,P6,P7
2929
5
3030

3131
Test case 6
32-
P0,P1,P2,d1,d2,d3,P4,P5,P6,P7,P8,P9
32+
P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P8,P9
3333
12
3434
P3
3535
1
@@ -60,13 +60,13 @@ Test case 10
6060
20
6161
a4,O6
6262
2
63-
10,a1,a1,O3,a4,a,b,a,b,a13,a13,O15,a16,a16,O18,a19
63+
10,a1,a1,O3,a4,a,b,a7,b,a13,a10,O15,a16,a13,O18,a19
6464
16
6565
a7,a7,O9,a10,a10,O12
6666
6
67-
10,a1,a1,O3,a4,a,b,a,b,a13,a,b,c,e,f,a16,a16,O18,a19
67+
10,a1,a1,O3,a4,a,b,a7,b,a13,a10,b,c,a13,f,a16,a16,O18,O18
6868
19
69-
a13,O15
69+
a10,O15
7070
2
7171

7272
Test case 11

deps/chakrashim/core/test/Array/protoLookupWithGetters.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ write("Test case 1");
1212

1313
for(var i =0;i<10;i++)
1414
{
15-
Object.defineProperty(Array.prototype, i, { get: function (i) { return function () { return "p"+i; } }(i), configurable: true, enumerable: true });
15+
Object.defineProperty(Array.prototype, i, { get: function (i) { return function () { return "p"+i; } }(i), set : function(a) {}, configurable: true, enumerable: true });
1616
}
1717

1818
var arr=new Array(10);
@@ -33,7 +33,7 @@ write("Test case 2");
3333

3434
for(var i =0;i<10;i++)
3535
{
36-
Object.defineProperty(Array.prototype, i, { get: function (i) { return function () { return "p"+i; } }(i), configurable: true, enumerable: true });
36+
Object.defineProperty(Array.prototype, i, { get: function (i) { return function () { return "p"+i; } }(i), set : function(a) {}, configurable: true, enumerable: true });
3737
}
3838

3939
var arr=new Array(10);
@@ -54,7 +54,7 @@ write("Test case 3");
5454
for(var i =0;i<10;i++)
5555
{
5656
i++;
57-
Object.defineProperty(Array.prototype, i, { get: function (i) { return function () { return "p"+i; } }(i), configurable: true, enumerable: true });
57+
Object.defineProperty(Array.prototype, i, { get: function (i) { return function () { return "p"+i; } }(i), set : function(a) {}, configurable: true, enumerable: true });
5858
}
5959

6060
var arr=new Array(10);
@@ -73,7 +73,7 @@ write("");
7373
write("Test case 4");
7474
for(var k=0;k<10;k++)
7575
{
76-
Object.defineProperty(Array.prototype, k, { get: function (k) { return function () { return "P"+k; } }(k), configurable: true, enumerable: true });
76+
Object.defineProperty(Array.prototype, k, { get: function (k) { return function () { return "P"+k; } }(k), set : function(a) {}, configurable: true, enumerable: true });
7777
}
7878
var arr=new Array(10);
7979
var newarr=arr.splice(3,5,"d1","d2","d3")
@@ -90,7 +90,7 @@ write("");
9090
write("Test case 5");
9191
for(var k=0;k<10;k++)
9292
{
93-
Object.defineProperty(Array.prototype, k, { get: function (k) { return function () { return "P"+k; } }(k), configurable: true, enumerable: true });
93+
Object.defineProperty(Array.prototype, k, { get: function (k) { return function () { return "P"+k; } }(k), set : function(a) {}, configurable: true, enumerable: true });
9494
}
9595
var arr=new Array(10);
9696
var newarr=arr.splice(3,5,"d1","d2","d3")
@@ -108,7 +108,7 @@ write("");
108108
write("Test case 6");
109109
for(var k=0;k<10;k++)
110110
{
111-
Object.defineProperty(Array.prototype, k, { get: function (k) { return function () { return "P"+k; } }(k), configurable: true, enumerable: true });
111+
Object.defineProperty(Array.prototype, k, { get: function (k) { return function () { return "P"+k; } }(k), set : function(a) {}, configurable: true, enumerable: true });
112112
}
113113
var arr=new Array(10);
114114
var newarr=arr.splice(3,1,"d1","d2","d3")

0 commit comments

Comments
 (0)