Skip to content

Commit 9cd56d3

Browse files
committed
Implement Array key, value and entries iterators
https://bugs.webkit.org/show_bug.cgi?id=122195 Reviewed by Filip Pizlo. Source/JavaScriptCore: Add implementation of ES6 Array iterators for keys(), values() and entries() Fairly self explanatory as we just need a simple implementation so that we can implement and test other features. * JavaScriptCore.xcodeproj/project.pbxproj: * runtime/ArrayIteratorConstructor.cpp: Added. (JSC::ArrayIteratorConstructor::finishCreation): * runtime/ArrayIteratorConstructor.h: Added. (JSC::ArrayIteratorConstructor::create): (JSC::ArrayIteratorConstructor::createStructure): (JSC::ArrayIteratorConstructor::ArrayIteratorConstructor): * runtime/ArrayIteratorPrototype.cpp: Added. (JSC::ArrayIteratorPrototype::finishCreation): (JSC::createIteratorResult): (JSC::arrayIteratorPrototypeNext): * runtime/ArrayIteratorPrototype.h: Added. (JSC::ArrayIteratorPrototype::create): (JSC::ArrayIteratorPrototype::createStructure): (JSC::ArrayIteratorPrototype::ArrayIteratorPrototype): * runtime/ArrayPrototype.cpp: (JSC::arrayProtoFuncValues): (JSC::arrayProtoFuncEntries): (JSC::arrayProtoFuncKeys): * runtime/CommonIdentifiers.h: * runtime/Identifier.h: (JSC::Identifier::createEmptyUnique): * runtime/JSArrayIterator.cpp: Added. (JSC::JSArrayIterator::finishCreation): * runtime/JSArrayIterator.h: Added. (JSC::JSArrayIterator::createStructure): (JSC::JSArrayIterator::create): (JSC::JSArrayIterator::iterationKind): (JSC::JSArrayIterator::iteratedObject): (JSC::JSArrayIterator::nextIndex): (JSC::JSArrayIterator::setNextIndex): (JSC::JSArrayIterator::finish): (JSC::JSArrayIterator::JSArrayIterator): * runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::reset): * runtime/JSGlobalObject.h: (JSC::JSGlobalObject::iteratorResultStructure): LayoutTests: Add tests * js/Object-getOwnPropertyNames-expected.txt: * js/array-iterators-expected.txt: Added. * js/array-iterators.html: Added. * js/script-tests/Object-getOwnPropertyNames.js: * js/script-tests/array-iterators.js: Added. Canonical link: https://commits.webkit.org/140275@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@156791 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent a4c52ec commit 9cd56d3

22 files changed

Lines changed: 734 additions & 3 deletions

‎LayoutTests/ChangeLog‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
2013-10-01 Oliver Hunt <oliver@apple.com>
2+
3+
Implement Array key, value and entries iterators
4+
https://bugs.webkit.org/show_bug.cgi?id=122195
5+
6+
Reviewed by Filip Pizlo.
7+
8+
Add tests
9+
10+
* js/Object-getOwnPropertyNames-expected.txt:
11+
* js/array-iterators-expected.txt: Added.
12+
* js/array-iterators.html: Added.
13+
* js/script-tests/Object-getOwnPropertyNames.js:
14+
* js/script-tests/array-iterators.js: Added.
15+
116
2013-09-25 Oliver Hunt <oliver@apple.com>
217

318
Implement prefixed-destructuring assignment

‎LayoutTests/js/Object-getOwnPropertyNames-expected.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ PASS getSortedOwnPropertyNames(Object.prototype) is ['__defineGetter__', '__defi
4545
PASS getSortedOwnPropertyNames(Function) is ['length', 'name', 'prototype']
4646
PASS getSortedOwnPropertyNames(Function.prototype) is ['apply', 'bind', 'call', 'constructor', 'length', 'name', 'toString']
4747
PASS getSortedOwnPropertyNames(Array) is ['isArray', 'length', 'name', 'prototype']
48-
PASS getSortedOwnPropertyNames(Array.prototype) is ['concat', 'constructor', 'every', 'filter', 'forEach', 'indexOf', 'join', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift']
48+
PASS getSortedOwnPropertyNames(Array.prototype) is ['concat', 'constructor', 'entries', 'every', 'filter', 'forEach', 'indexOf', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift', 'values']
4949
PASS getSortedOwnPropertyNames(String) is ['fromCharCode', 'length', 'name', 'prototype']
5050
PASS getSortedOwnPropertyNames(String.prototype) is ['anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt', 'concat', 'constructor', 'fixed', 'fontcolor', 'fontsize', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'replace', 'search', 'slice', 'small', 'split', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimLeft', 'trimRight', 'valueOf']
5151
PASS getSortedOwnPropertyNames(Boolean) is ['length', 'name', 'prototype']
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
This test checks the behavior of the iterator methods on Array objects.
2+
3+
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4+
5+
6+
PASS key is 0
7+
PASS key is 1
8+
PASS key is 2
9+
PASS key is 3
10+
PASS key is 4
11+
PASS key is 5
12+
PASS testArray.length is 6
13+
PASS keys.next().value is undefined.
14+
PASS value is 1
15+
PASS value is 2
16+
PASS value is 3
17+
PASS value is 4
18+
PASS value is 5
19+
PASS value is 6
20+
PASS testArray.length is 6
21+
PASS values.next().value is undefined.
22+
PASS value is testArray[key]
23+
PASS key is 0
24+
PASS value is 1
25+
PASS value is testArray[key]
26+
PASS key is 1
27+
PASS value is 2
28+
PASS value is testArray[key]
29+
PASS key is 2
30+
PASS value is 3
31+
PASS value is testArray[key]
32+
PASS key is 3
33+
PASS value is 4
34+
PASS value is testArray[key]
35+
PASS key is 4
36+
PASS value is 5
37+
PASS value is testArray[key]
38+
PASS key is 5
39+
PASS value is 6
40+
PASS testArray.length is 6
41+
PASS entries.next().value is undefined.
42+
PASS value is testArray[key]
43+
PASS key is i
44+
PASS value is testArray[key]
45+
PASS key is i
46+
PASS value is testArray[key]
47+
PASS key is i
48+
PASS value is testArray[key]
49+
PASS key is i
50+
PASS value is testArray[key]
51+
PASS key is i
52+
PASS value is testArray[key]
53+
PASS key is i
54+
PASS value is testArray[key]
55+
PASS key is i
56+
PASS value is testArray[key]
57+
PASS key is i
58+
PASS value is testArray[key]
59+
PASS key is i
60+
PASS testArray.length is 9
61+
PASS entries.next().value is undefined.
62+
PASS successfullyParsed is true
63+
64+
TEST COMPLETE
65+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2+
<html>
3+
<head>
4+
<script src="../resources/js-test-pre.js"></script>
5+
</head>
6+
<body>
7+
<script src="script-tests/array-iterators.js"></script>
8+
<script src="../resources/js-test-post.js"></script>
9+
</body>
10+
</html>

‎LayoutTests/js/script-tests/Object-getOwnPropertyNames.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var expectedPropertyNamesSet = {
5353
"Function": "['length', 'name', 'prototype']",
5454
"Function.prototype": "['apply', 'bind', 'call', 'constructor', 'length', 'name', 'toString']",
5555
"Array": "['isArray', 'length', 'name', 'prototype']",
56-
"Array.prototype": "['concat', 'constructor', 'every', 'filter', 'forEach', 'indexOf', 'join', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift']",
56+
"Array.prototype": "['concat', 'constructor', 'entries', 'every', 'filter', 'forEach', 'indexOf', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift', 'values']",
5757
"String": "['fromCharCode', 'length', 'name', 'prototype']",
5858
"String.prototype": "['anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt', 'concat', 'constructor', 'fixed', 'fontcolor', 'fontsize', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'replace', 'search', 'slice', 'small', 'split', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimLeft', 'trimRight', 'valueOf']",
5959
"Boolean": "['length', 'name', 'prototype']",
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
description(
2+
"This test checks the behavior of the iterator methods on Array objects."
3+
);
4+
5+
6+
var testArray = [1,2,3,4,5,6]
7+
var keys = testArray.keys();
8+
var i = 0;
9+
while (true) {
10+
var {done, value: key} = keys.next();
11+
if (done)
12+
break;
13+
shouldBe("key", String(i))
14+
i++;
15+
}
16+
17+
shouldBe("testArray.length", String(i))
18+
19+
shouldBeUndefined("keys.next().value")
20+
21+
var values = testArray.values();
22+
var i = 0;
23+
while (true) {
24+
var {done, value} = values.next();
25+
if (done)
26+
break;
27+
i++;
28+
shouldBe("value", String(i) )
29+
}
30+
31+
shouldBe("testArray.length", String(i))
32+
33+
shouldBeUndefined("values.next().value")
34+
35+
var entries = testArray.entries();
36+
var i = 0;
37+
do {
38+
var {done, value: entry} = entries.next();
39+
if (done)
40+
break;
41+
var [key, value] = entry;
42+
shouldBe("value", "testArray[key]")
43+
shouldBe("key", String(i))
44+
i++
45+
shouldBe("value", String(i))
46+
} while (!done);
47+
48+
shouldBe("testArray.length", String(i))
49+
50+
shouldBeUndefined("entries.next().value")
51+
52+
53+
54+
var entries = testArray.entries();
55+
var i = 0;
56+
do {
57+
var {done, value: entry} = entries.next();
58+
if (done)
59+
break;
60+
var [key, value] = entry;
61+
shouldBe("value", "testArray[key]")
62+
shouldBe("key", "i")
63+
i++
64+
if (i % 2 == 0)
65+
testArray[i] *= 2;
66+
if (i < 4)
67+
testArray.push(testArray.length)
68+
if (i == 4)
69+
delete testArray[4]
70+
if (i == 5)
71+
testArray[4] = 5
72+
} while (!done);
73+
shouldBe("testArray.length", String(i))
74+
75+
shouldBeUndefined("entries.next().value")
76+

‎Source/JavaScriptCore/CMakeLists.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ set(JavaScriptCore_SOURCES
266266
runtime/ArrayBuffer.cpp
267267
runtime/ArrayBufferView.cpp
268268
runtime/ArrayConstructor.cpp
269+
runtime/ArrayIteratorConstructor.cpp
270+
runtime/ArrayIteratorPrototype.cpp
269271
runtime/ArrayPrototype.cpp
270272
runtime/BooleanConstructor.cpp
271273
runtime/BooleanObject.cpp
@@ -309,6 +311,7 @@ set(JavaScriptCore_SOURCES
309311
runtime/JSArrayBufferConstructor.cpp
310312
runtime/JSArrayBufferPrototype.cpp
311313
runtime/JSArrayBufferView.cpp
314+
runtime/JSArrayIterator.cpp
312315
runtime/JSBoundFunction.cpp
313316
runtime/JSCJSValue.cpp
314317
runtime/JSCell.cpp

‎Source/JavaScriptCore/ChangeLog‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,53 @@
1+
2013-10-01 Oliver Hunt <oliver@apple.com>
2+
3+
Implement Array key, value and entries iterators
4+
https://bugs.webkit.org/show_bug.cgi?id=122195
5+
6+
Reviewed by Filip Pizlo.
7+
8+
Add implementation of ES6 Array iterators for keys(), values() and entries()
9+
10+
Fairly self explanatory as we just need a simple implementation so that we can
11+
implement and test other features.
12+
13+
* JavaScriptCore.xcodeproj/project.pbxproj:
14+
* runtime/ArrayIteratorConstructor.cpp: Added.
15+
(JSC::ArrayIteratorConstructor::finishCreation):
16+
* runtime/ArrayIteratorConstructor.h: Added.
17+
(JSC::ArrayIteratorConstructor::create):
18+
(JSC::ArrayIteratorConstructor::createStructure):
19+
(JSC::ArrayIteratorConstructor::ArrayIteratorConstructor):
20+
* runtime/ArrayIteratorPrototype.cpp: Added.
21+
(JSC::ArrayIteratorPrototype::finishCreation):
22+
(JSC::createIteratorResult):
23+
(JSC::arrayIteratorPrototypeNext):
24+
* runtime/ArrayIteratorPrototype.h: Added.
25+
(JSC::ArrayIteratorPrototype::create):
26+
(JSC::ArrayIteratorPrototype::createStructure):
27+
(JSC::ArrayIteratorPrototype::ArrayIteratorPrototype):
28+
* runtime/ArrayPrototype.cpp:
29+
(JSC::arrayProtoFuncValues):
30+
(JSC::arrayProtoFuncEntries):
31+
(JSC::arrayProtoFuncKeys):
32+
* runtime/CommonIdentifiers.h:
33+
* runtime/Identifier.h:
34+
(JSC::Identifier::createEmptyUnique):
35+
* runtime/JSArrayIterator.cpp: Added.
36+
(JSC::JSArrayIterator::finishCreation):
37+
* runtime/JSArrayIterator.h: Added.
38+
(JSC::JSArrayIterator::createStructure):
39+
(JSC::JSArrayIterator::create):
40+
(JSC::JSArrayIterator::iterationKind):
41+
(JSC::JSArrayIterator::iteratedObject):
42+
(JSC::JSArrayIterator::nextIndex):
43+
(JSC::JSArrayIterator::setNextIndex):
44+
(JSC::JSArrayIterator::finish):
45+
(JSC::JSArrayIterator::JSArrayIterator):
46+
* runtime/JSGlobalObject.cpp:
47+
(JSC::JSGlobalObject::reset):
48+
* runtime/JSGlobalObject.h:
49+
(JSC::JSGlobalObject::iteratorResultStructure):
50+
151
2013-10-02 Mark Hahnenberg <mhahnenberg@apple.com>
252

353
get_callee and to_this aren't properly cleared during finalizeUnconditionally

‎Source/JavaScriptCore/GNUmakefile.list.am‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,10 @@ javascriptcore_sources += \
748748
Source/JavaScriptCore/runtime/ArrayConstructor.cpp \
749749
Source/JavaScriptCore/runtime/ArrayConstructor.h \
750750
Source/JavaScriptCore/runtime/ArrayConventions.h \
751+
Source/JavaScriptCore/runtime/ArrayIteratorConstructor.cpp \
752+
Source/JavaScriptCore/runtime/ArrayIteratorConstructor.h \
753+
Source/JavaScriptCore/runtime/ArrayIteratorPrototype.cpp \
754+
Source/JavaScriptCore/runtime/ArrayIteratorPrototype.h \
751755
Source/JavaScriptCore/runtime/ArrayPrototype.cpp \
752756
Source/JavaScriptCore/runtime/ArrayPrototype.h \
753757
Source/JavaScriptCore/runtime/ArrayStorage.h \
@@ -853,6 +857,8 @@ javascriptcore_sources += \
853857
Source/JavaScriptCore/runtime/JSArrayBufferView.cpp \
854858
Source/JavaScriptCore/runtime/JSArrayBufferView.h \
855859
Source/JavaScriptCore/runtime/JSArrayBufferViewInlines.h \
860+
Source/JavaScriptCore/runtime/JSArrayIterator.cpp \
861+
Source/JavaScriptCore/runtime/JSArrayIterator.h \
856862
Source/JavaScriptCore/runtime/JSCell.cpp \
857863
Source/JavaScriptCore/runtime/JSCell.h \
858864
Source/JavaScriptCore/runtime/JSDataView.cpp \

‎Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@
425425
<ClCompile Include="..\runtime\ArrayBuffer.cpp" />
426426
<ClCompile Include="..\runtime\ArrayBufferView.cpp" />
427427
<ClCompile Include="..\runtime\ArrayConstructor.cpp" />
428+
<ClInclude Include="..\runtime\ArrayIteratorConstructor.cpp" />
429+
<ClInclude Include="..\runtime\ArrayIteratorPrototype.cpp" />
428430
<ClCompile Include="..\runtime\ArrayPrototype.cpp" />
429431
<ClCompile Include="..\runtime\BooleanConstructor.cpp" />
430432
<ClCompile Include="..\runtime\BooleanObject.cpp" />
@@ -460,6 +462,7 @@
460462
<ClCompile Include="..\runtime\JSAPIValueWrapper.cpp" />
461463
<ClCompile Include="..\runtime\JSActivation.cpp" />
462464
<ClCompile Include="..\runtime\JSArray.cpp" />
465+
<ClCompile Include="..\runtime\JSArrayIterator.cpp" />
463466
<ClCompile Include="..\runtime\JSArrayBuffer.cpp" />
464467
<ClCompile Include="..\runtime\JSArrayBufferConstructor.cpp" />
465468
<ClCompile Include="..\runtime\JSArrayBufferPrototype.cpp" />
@@ -840,6 +843,8 @@
840843
<ClInclude Include="..\runtime\ArrayBufferView.h" />
841844
<ClInclude Include="..\runtime\ArrayConstructor.h" />
842845
<ClInclude Include="..\runtime\ArrayConventions.h" />
846+
<ClInclude Include="..\runtime\ArrayIteratorConstructor.h" />
847+
<ClInclude Include="..\runtime\ArrayIteratorPrototype.h" />
843848
<ClInclude Include="..\runtime\ArrayPrototype.h" />
844849
<ClInclude Include="..\runtime\ArrayStorage.h" />
845850
<ClInclude Include="..\runtime\BatchedTransitionOptimizer.h" />
@@ -898,6 +903,7 @@
898903
<ClInclude Include="..\runtime\JSArrayBufferPrototype.h" />
899904
<ClInclude Include="..\runtime\JSArrayBufferView.h" />
900905
<ClInclude Include="..\runtime\JSArrayBufferViewInlines.h" />
906+
<ClCompile Include="..\runtime\JSArrayIterator.h" />
901907
<ClInclude Include="..\runtime\JSBoundFunction.h" />
902908
<ClInclude Include="..\runtime\JSCJSValue.h" />
903909
<ClInclude Include="..\runtime\JSCJSValueInlines.h" />

0 commit comments

Comments
 (0)