Implement Array key, value and entries iterators
authoroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Oct 2013 20:34:09 +0000 (20:34 +0000)
committeroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Oct 2013 20:34:09 +0000 (20:34 +0000)
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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@156791 268f45cc-cd09-0410-ab3c-d52691b4dbfc

22 files changed:
LayoutTests/ChangeLog
LayoutTests/js/Object-getOwnPropertyNames-expected.txt
LayoutTests/js/array-iterators-expected.txt [new file with mode: 0644]
LayoutTests/js/array-iterators.html [new file with mode: 0644]
LayoutTests/js/script-tests/Object-getOwnPropertyNames.js
LayoutTests/js/script-tests/array-iterators.js [new file with mode: 0644]
Source/JavaScriptCore/CMakeLists.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/GNUmakefile.list.am
Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/runtime/ArrayIteratorConstructor.cpp [new file with mode: 0644]
Source/JavaScriptCore/runtime/ArrayIteratorConstructor.h [new file with mode: 0644]
Source/JavaScriptCore/runtime/ArrayIteratorPrototype.cpp [new file with mode: 0644]
Source/JavaScriptCore/runtime/ArrayIteratorPrototype.h [new file with mode: 0644]
Source/JavaScriptCore/runtime/ArrayPrototype.cpp
Source/JavaScriptCore/runtime/CommonIdentifiers.h
Source/JavaScriptCore/runtime/Identifier.h
Source/JavaScriptCore/runtime/JSArrayIterator.cpp [new file with mode: 0644]
Source/JavaScriptCore/runtime/JSArrayIterator.h [new file with mode: 0644]
Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Source/JavaScriptCore/runtime/JSGlobalObject.h

index a3ce2c7..dec084a 100644 (file)
@@ -1,3 +1,18 @@
+2013-10-01  Oliver Hunt  <oliver@apple.com>
+
+        Implement Array key, value and entries iterators
+        https://bugs.webkit.org/show_bug.cgi?id=122195
+
+        Reviewed by Filip Pizlo.
+
+        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.
+
 2013-09-25  Oliver Hunt  <oliver@apple.com>
 
         Implement prefixed-destructuring assignment
index 4814eb7..9edd066 100644 (file)
@@ -45,7 +45,7 @@ PASS getSortedOwnPropertyNames(Object.prototype) is ['__defineGetter__', '__defi
 PASS getSortedOwnPropertyNames(Function) is ['length', 'name', 'prototype']
 PASS getSortedOwnPropertyNames(Function.prototype) is ['apply', 'bind', 'call', 'constructor', 'length', 'name', 'toString']
 PASS getSortedOwnPropertyNames(Array) is ['isArray', 'length', 'name', 'prototype']
-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']
+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']
 PASS getSortedOwnPropertyNames(String) is ['fromCharCode', 'length', 'name', 'prototype']
 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']
 PASS getSortedOwnPropertyNames(Boolean) is ['length', 'name', 'prototype']
diff --git a/LayoutTests/js/array-iterators-expected.txt b/LayoutTests/js/array-iterators-expected.txt
new file mode 100644 (file)
index 0000000..9819ec0
--- /dev/null
@@ -0,0 +1,65 @@
+This test checks the behavior of the iterator methods on Array objects.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS key is 0
+PASS key is 1
+PASS key is 2
+PASS key is 3
+PASS key is 4
+PASS key is 5
+PASS testArray.length is 6
+PASS keys.next().value is undefined.
+PASS value is 1
+PASS value is 2
+PASS value is 3
+PASS value is 4
+PASS value is 5
+PASS value is 6
+PASS testArray.length is 6
+PASS values.next().value is undefined.
+PASS value is testArray[key]
+PASS key is 0
+PASS value is 1
+PASS value is testArray[key]
+PASS key is 1
+PASS value is 2
+PASS value is testArray[key]
+PASS key is 2
+PASS value is 3
+PASS value is testArray[key]
+PASS key is 3
+PASS value is 4
+PASS value is testArray[key]
+PASS key is 4
+PASS value is 5
+PASS value is testArray[key]
+PASS key is 5
+PASS value is 6
+PASS testArray.length is 6
+PASS entries.next().value is undefined.
+PASS value is testArray[key]
+PASS key is i
+PASS value is testArray[key]
+PASS key is i
+PASS value is testArray[key]
+PASS key is i
+PASS value is testArray[key]
+PASS key is i
+PASS value is testArray[key]
+PASS key is i
+PASS value is testArray[key]
+PASS key is i
+PASS value is testArray[key]
+PASS key is i
+PASS value is testArray[key]
+PASS key is i
+PASS value is testArray[key]
+PASS key is i
+PASS testArray.length is 9
+PASS entries.next().value is undefined.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/js/array-iterators.html b/LayoutTests/js/array-iterators.html
new file mode 100644 (file)
index 0000000..9ee664b
--- /dev/null
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="script-tests/array-iterators.js"></script>
+<script src="../resources/js-test-post.js"></script>
+</body>
+</html>
index 43df417..0f5370b 100644 (file)
@@ -53,7 +53,7 @@ var expectedPropertyNamesSet = {
     "Function": "['length', 'name', 'prototype']",
     "Function.prototype": "['apply', 'bind', 'call', 'constructor', 'length', 'name', 'toString']",
     "Array": "['isArray', 'length', 'name', 'prototype']",
-    "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']",
+    "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']",
     "String": "['fromCharCode', 'length', 'name', 'prototype']",
     "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']",
     "Boolean": "['length', 'name', 'prototype']",
diff --git a/LayoutTests/js/script-tests/array-iterators.js b/LayoutTests/js/script-tests/array-iterators.js
new file mode 100644 (file)
index 0000000..7ccb789
--- /dev/null
@@ -0,0 +1,76 @@
+description(
+"This test checks the behavior of the iterator methods on Array objects."
+);
+
+
+var testArray = [1,2,3,4,5,6]
+var keys = testArray.keys();
+var i = 0;
+while (true) {
+    var {done, value: key} = keys.next();
+    if (done)
+        break;
+    shouldBe("key", String(i))
+    i++;
+}
+
+shouldBe("testArray.length", String(i))
+
+shouldBeUndefined("keys.next().value")
+
+var values = testArray.values();
+var i = 0;
+while (true) {
+    var {done, value} = values.next();
+    if (done)
+        break;
+    i++;
+    shouldBe("value", String(i) )
+}
+
+shouldBe("testArray.length", String(i))
+
+shouldBeUndefined("values.next().value")
+
+var entries = testArray.entries();
+var i = 0;
+do {
+    var {done, value: entry} = entries.next();
+    if (done)
+        break;
+    var [key, value] = entry;
+    shouldBe("value", "testArray[key]")
+    shouldBe("key", String(i))
+    i++
+    shouldBe("value", String(i))
+} while (!done);
+
+shouldBe("testArray.length", String(i))
+
+shouldBeUndefined("entries.next().value")
+
+
+
+var entries = testArray.entries();
+var i = 0;
+do {
+    var {done, value: entry} = entries.next();
+    if (done)
+        break;
+    var [key, value] = entry;
+    shouldBe("value", "testArray[key]")
+    shouldBe("key", "i")
+    i++
+    if (i % 2 == 0)
+        testArray[i] *= 2;
+    if (i < 4)
+        testArray.push(testArray.length)
+    if (i == 4)
+        delete testArray[4]
+    if (i == 5)
+        testArray[4] = 5
+} while (!done);
+shouldBe("testArray.length", String(i))
+
+shouldBeUndefined("entries.next().value")
+
index d8bf555..fb3d850 100644 (file)
@@ -266,6 +266,8 @@ set(JavaScriptCore_SOURCES
     runtime/ArrayBuffer.cpp
     runtime/ArrayBufferView.cpp
     runtime/ArrayConstructor.cpp
+    runtime/ArrayIteratorConstructor.cpp
+    runtime/ArrayIteratorPrototype.cpp
     runtime/ArrayPrototype.cpp
     runtime/BooleanConstructor.cpp
     runtime/BooleanObject.cpp
@@ -309,6 +311,7 @@ set(JavaScriptCore_SOURCES
     runtime/JSArrayBufferConstructor.cpp
     runtime/JSArrayBufferPrototype.cpp
     runtime/JSArrayBufferView.cpp
+    runtime/JSArrayIterator.cpp
     runtime/JSBoundFunction.cpp
     runtime/JSCJSValue.cpp
     runtime/JSCell.cpp
index c5da3ac..9d7edc9 100644 (file)
@@ -1,3 +1,53 @@
+2013-10-01  Oliver Hunt  <oliver@apple.com>
+
+        Implement Array key, value and entries iterators
+        https://bugs.webkit.org/show_bug.cgi?id=122195
+
+        Reviewed by Filip Pizlo.
+
+        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):
+
 2013-10-02  Mark Hahnenberg  <mhahnenberg@apple.com>
 
         get_callee and to_this aren't properly cleared during finalizeUnconditionally
index f8b3b97..dcb7189 100644 (file)
@@ -748,6 +748,10 @@ javascriptcore_sources += \
        Source/JavaScriptCore/runtime/ArrayConstructor.cpp \
        Source/JavaScriptCore/runtime/ArrayConstructor.h \
        Source/JavaScriptCore/runtime/ArrayConventions.h \
+       Source/JavaScriptCore/runtime/ArrayIteratorConstructor.cpp \
+    Source/JavaScriptCore/runtime/ArrayIteratorConstructor.h \
+    Source/JavaScriptCore/runtime/ArrayIteratorPrototype.cpp \
+    Source/JavaScriptCore/runtime/ArrayIteratorPrototype.h \
        Source/JavaScriptCore/runtime/ArrayPrototype.cpp \
        Source/JavaScriptCore/runtime/ArrayPrototype.h \
        Source/JavaScriptCore/runtime/ArrayStorage.h \
@@ -853,6 +857,8 @@ javascriptcore_sources += \
        Source/JavaScriptCore/runtime/JSArrayBufferView.cpp \
        Source/JavaScriptCore/runtime/JSArrayBufferView.h \
        Source/JavaScriptCore/runtime/JSArrayBufferViewInlines.h \
+       Source/JavaScriptCore/runtime/JSArrayIterator.cpp \
+    Source/JavaScriptCore/runtime/JSArrayIterator.h \
        Source/JavaScriptCore/runtime/JSCell.cpp \
        Source/JavaScriptCore/runtime/JSCell.h \
        Source/JavaScriptCore/runtime/JSDataView.cpp \
index dd0727f..891f690 100644 (file)
     <ClCompile Include="..\runtime\ArrayBuffer.cpp" />\r
     <ClCompile Include="..\runtime\ArrayBufferView.cpp" />\r
     <ClCompile Include="..\runtime\ArrayConstructor.cpp" />\r
+    <ClInclude Include="..\runtime\ArrayIteratorConstructor.cpp" />\r
+    <ClInclude Include="..\runtime\ArrayIteratorPrototype.cpp" />\r
     <ClCompile Include="..\runtime\ArrayPrototype.cpp" />\r
     <ClCompile Include="..\runtime\BooleanConstructor.cpp" />\r
     <ClCompile Include="..\runtime\BooleanObject.cpp" />\r
     <ClCompile Include="..\runtime\JSAPIValueWrapper.cpp" />\r
     <ClCompile Include="..\runtime\JSActivation.cpp" />\r
     <ClCompile Include="..\runtime\JSArray.cpp" />\r
+    <ClCompile Include="..\runtime\JSArrayIterator.cpp" />\r
     <ClCompile Include="..\runtime\JSArrayBuffer.cpp" />\r
     <ClCompile Include="..\runtime\JSArrayBufferConstructor.cpp" />\r
     <ClCompile Include="..\runtime\JSArrayBufferPrototype.cpp" />\r
     <ClInclude Include="..\runtime\ArrayBufferView.h" />\r
     <ClInclude Include="..\runtime\ArrayConstructor.h" />\r
     <ClInclude Include="..\runtime\ArrayConventions.h" />\r
+    <ClInclude Include="..\runtime\ArrayIteratorConstructor.h" />\r
+    <ClInclude Include="..\runtime\ArrayIteratorPrototype.h" />\r
     <ClInclude Include="..\runtime\ArrayPrototype.h" />\r
     <ClInclude Include="..\runtime\ArrayStorage.h" />\r
     <ClInclude Include="..\runtime\BatchedTransitionOptimizer.h" />\r
     <ClInclude Include="..\runtime\JSArrayBufferPrototype.h" />\r
     <ClInclude Include="..\runtime\JSArrayBufferView.h" />\r
     <ClInclude Include="..\runtime\JSArrayBufferViewInlines.h" />\r
+    <ClCompile Include="..\runtime\JSArrayIterator.h" />\r
     <ClInclude Include="..\runtime\JSBoundFunction.h" />\r
     <ClInclude Include="..\runtime\JSCJSValue.h" />\r
     <ClInclude Include="..\runtime\JSCJSValueInlines.h" />\r
index bd06950..08cf44e 100644 (file)
                A7B48F490EE8936F00DCBDB6 /* ExecutableAllocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7B48DB60EE74CFC00DCBDB6 /* ExecutableAllocator.cpp */; };
                A7B4ACAF1484C9CE00B38A36 /* JSExportMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = A7B4ACAE1484C9CE00B38A36 /* JSExportMacros.h */; settings = {ATTRIBUTES = (Private, ); }; };
                A7B601821639FD2A00372BA3 /* UnlinkedCodeBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = A79E781F15EECBA80047C855 /* UnlinkedCodeBlock.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               A7BDAEC617F4EA1400F6140C /* ArrayIteratorConstructor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7BDAEC017F4EA1400F6140C /* ArrayIteratorConstructor.cpp */; };
+               A7BDAEC717F4EA1400F6140C /* ArrayIteratorConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = A7BDAEC117F4EA1400F6140C /* ArrayIteratorConstructor.h */; };
+               A7BDAEC817F4EA1400F6140C /* ArrayIteratorPrototype.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7BDAEC217F4EA1400F6140C /* ArrayIteratorPrototype.cpp */; };
+               A7BDAEC917F4EA1400F6140C /* ArrayIteratorPrototype.h in Headers */ = {isa = PBXBuildFile; fileRef = A7BDAEC317F4EA1400F6140C /* ArrayIteratorPrototype.h */; };
+               A7BDAECA17F4EA1400F6140C /* JSArrayIterator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7BDAEC417F4EA1400F6140C /* JSArrayIterator.cpp */; };
+               A7BDAECB17F4EA1400F6140C /* JSArrayIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = A7BDAEC517F4EA1400F6140C /* JSArrayIterator.h */; };
                A7BFF3C0179868940002F462 /* DFGFiltrationResult.h in Headers */ = {isa = PBXBuildFile; fileRef = A7BFF3BF179868940002F462 /* DFGFiltrationResult.h */; };
                A7C0C4AC168103020017011D /* JSScriptRefPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = A7C0C4AB167C08CD0017011D /* JSScriptRefPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
                A7C0C4AD1681067E0017011D /* JSScriptRef.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7C0C4AA167C08CD0017011D /* JSScriptRef.cpp */; };
                A7B48DB50EE74CFC00DCBDB6 /* ExecutableAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExecutableAllocator.h; sourceTree = "<group>"; };
                A7B48DB60EE74CFC00DCBDB6 /* ExecutableAllocator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExecutableAllocator.cpp; sourceTree = "<group>"; };
                A7B4ACAE1484C9CE00B38A36 /* JSExportMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSExportMacros.h; sourceTree = "<group>"; };
+               A7BDAEC017F4EA1400F6140C /* ArrayIteratorConstructor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ArrayIteratorConstructor.cpp; sourceTree = "<group>"; };
+               A7BDAEC117F4EA1400F6140C /* ArrayIteratorConstructor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArrayIteratorConstructor.h; sourceTree = "<group>"; };
+               A7BDAEC217F4EA1400F6140C /* ArrayIteratorPrototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ArrayIteratorPrototype.cpp; sourceTree = "<group>"; };
+               A7BDAEC317F4EA1400F6140C /* ArrayIteratorPrototype.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArrayIteratorPrototype.h; sourceTree = "<group>"; };
+               A7BDAEC417F4EA1400F6140C /* JSArrayIterator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSArrayIterator.cpp; sourceTree = "<group>"; };
+               A7BDAEC517F4EA1400F6140C /* JSArrayIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSArrayIterator.h; sourceTree = "<group>"; };
                A7BFF3BF179868940002F462 /* DFGFiltrationResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGFiltrationResult.h; path = dfg/DFGFiltrationResult.h; sourceTree = "<group>"; };
                A7C0C4AA167C08CD0017011D /* JSScriptRef.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSScriptRef.cpp; sourceTree = "<group>"; };
                A7C0C4AB167C08CD0017011D /* JSScriptRefPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSScriptRefPrivate.h; sourceTree = "<group>"; };
                                A7CA3AE217DA41AE006538AF /* JSWeakMap.h */,
                                A7CA3AE917DA5168006538AF /* WeakMapData.cpp */,
                                A7CA3AEA17DA5168006538AF /* WeakMapData.h */,
+                               A7BDAEC017F4EA1400F6140C /* ArrayIteratorConstructor.cpp */,
+                               A7BDAEC117F4EA1400F6140C /* ArrayIteratorConstructor.h */,
+                               A7BDAEC217F4EA1400F6140C /* ArrayIteratorPrototype.cpp */,
+                               A7BDAEC317F4EA1400F6140C /* ArrayIteratorPrototype.h */,
+                               A7BDAEC417F4EA1400F6140C /* JSArrayIterator.cpp */,
+                               A7BDAEC517F4EA1400F6140C /* JSArrayIterator.h */,
                        );
                        path = runtime;
                        sourceTree = "<group>";
                                0F4680CB14BBB17200BFE272 /* LLIntOfflineAsmConfig.h in Headers */,
                                FED287B215EC9A5700DA8161 /* LLIntOpcode.h in Headers */,
                                0F4680A514BA7F8D00BFE272 /* LLIntSlowPaths.h in Headers */,
+                               A7BDAECB17F4EA1400F6140C /* JSArrayIterator.h in Headers */,
                                0F0B839D14BCF46600885B4F /* LLIntThunks.h in Headers */,
                                A7E5AB381799E4B200D2833D /* LLVMDisassembler.h in Headers */,
                                142E3139134FF0A600AFADB5 /* Local.h in Headers */,
                                0FCCAE4516D0CF7400D0C65B /* ParserError.h in Headers */,
                                A77F1825164192C700640A47 /* ParserModes.h in Headers */,
                                65303D641447B9E100D3F904 /* ParserTokens.h in Headers */,
+                               A7BDAEC717F4EA1400F6140C /* ArrayIteratorConstructor.h in Headers */,
                                0F34B14C16D43E0D001CDA5A /* PolymorphicAccessStructureList.h in Headers */,
                                0F9FC8C414E1B60000D52AE0 /* PolymorphicPutByIdList.h in Headers */,
                                0F98206116BFE38300240D02 /* PreciseJumpTargets.h in Headers */,
                                BC18C52C0E16FCD200B34460 /* RegExpObject.lut.h in Headers */,
                                BCD202C40E1706A7002C7E82 /* RegExpPrototype.h in Headers */,
                                C20B25991706536200C21F4E /* Region.h in Headers */,
+                               A7BDAEC917F4EA1400F6140C /* ArrayIteratorPrototype.h in Headers */,
                                BC18C45D0E16F5CD00B34460 /* Register.h in Headers */,
                                969A072B0ED1CE6900F1F681 /* RegisterID.h in Headers */,
                                0FB7F39D15ED8E4600F167B2 /* Reject.h in Headers */,
                                A72028B61797601E0098028C /* JSCTestRunnerUtils.cpp in Sources */,
                                0F2B66EB17B6B5AB00A7AE3F /* JSDataView.cpp in Sources */,
                                0F2B66ED17B6B5AB00A7AE3F /* JSDataViewPrototype.cpp in Sources */,
+                               A7BDAECA17F4EA1400F6140C /* JSArrayIterator.cpp in Sources */,
                                978801401471AD920041B016 /* JSDateMath.cpp in Sources */,
                                140566D6107EC271005DBC8D /* JSFunction.cpp in Sources */,
                                147F39D2107EC37600427A48 /* JSGlobalObject.cpp in Sources */,
                                E124A8F80E555775003091F1 /* OpaqueJSString.cpp in Sources */,
                                969A079A0ED1D3AE00F1F681 /* Opcode.cpp in Sources */,
                                14280850107EC0D70013E7B2 /* Operations.cpp in Sources */,
+                               A7BDAEC817F4EA1400F6140C /* ArrayIteratorPrototype.cpp in Sources */,
                                0FE228EE1436AB2C00196C48 /* Options.cpp in Sources */,
                                148F21BC107EC54D0042EC2C /* Parser.cpp in Sources */,
                                93052C340FB792190048FDC3 /* ParserArena.cpp in Sources */,
                                A7299DA117D12848005F5FF9 /* SetPrototype.cpp in Sources */,
                                0F2B670417B6B5AB00A7AE3F /* SimpleTypedArrayController.cpp in Sources */,
                                C225494315F7DBAA0065E898 /* SlotVisitor.cpp in Sources */,
+                               A7BDAEC617F4EA1400F6140C /* ArrayIteratorConstructor.cpp in Sources */,
                                9330402C0E6A764000786E6A /* SmallStrings.cpp in Sources */,
                                0F8F2B9E17306C8D007DBDA5 /* SourceCode.cpp in Sources */,
                                0F493AFA16D0CAD30084508B /* SourceProvider.cpp in Sources */,
diff --git a/Source/JavaScriptCore/runtime/ArrayIteratorConstructor.cpp b/Source/JavaScriptCore/runtime/ArrayIteratorConstructor.cpp
new file mode 100644 (file)
index 0000000..0916eee
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2013 Apple, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "ArrayIteratorConstructor.h"
+
+#include "JSCJSValueInlines.h"
+#include "JSCellInlines.h"
+#include "JSGlobalObject.h"
+
+namespace JSC {
+
+const ClassInfo ArrayIteratorConstructor::s_info = { "Function", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(ArrayIteratorConstructor) };
+
+void ArrayIteratorConstructor::finishCreation(VM& vm)
+{
+    Base::finishCreation(vm);
+}
+
+}
diff --git a/Source/JavaScriptCore/runtime/ArrayIteratorConstructor.h b/Source/JavaScriptCore/runtime/ArrayIteratorConstructor.h
new file mode 100644 (file)
index 0000000..489d5d9
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2013 Apple, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef ArrayIteratorConstructor_h
+#define ArrayIteratorConstructor_h
+
+#include "InternalFunction.h"
+
+namespace JSC {
+
+class ArrayIteratorPrototype;
+
+class ArrayIteratorConstructor : public JSNonFinalObject {
+public:
+    typedef JSNonFinalObject Base;
+
+    static ArrayIteratorConstructor* create(VM& vm, Structure* structure, ArrayIteratorPrototype*)
+    {
+        ArrayIteratorConstructor* constructor = new (NotNull, allocateCell<ArrayIteratorConstructor>(vm.heap)) ArrayIteratorConstructor(vm, structure);
+        constructor->finishCreation(vm);
+        return constructor;
+    }
+
+    DECLARE_INFO;
+
+    static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+    {
+        return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+    }
+
+private:
+    ArrayIteratorConstructor(VM& vm, Structure* structure)
+        : Base(vm, structure)
+    {
+    }
+    void finishCreation(VM&);
+};
+
+}
+
+#endif // !defined(ArrayIteratorConstructor_h)
diff --git a/Source/JavaScriptCore/runtime/ArrayIteratorPrototype.cpp b/Source/JavaScriptCore/runtime/ArrayIteratorPrototype.cpp
new file mode 100644 (file)
index 0000000..2c8fa15
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2013 Apple, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "ArrayIteratorPrototype.h"
+
+#include "JSArrayIterator.h"
+#include "JSCJSValueInlines.h"
+#include "JSCellInlines.h"
+#include "JSGlobalObject.h"
+#include "ObjectConstructor.h"
+
+namespace JSC {
+
+const ClassInfo ArrayIteratorPrototype::s_info = { "Array Iterator", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(ArrayIteratorPrototype) };
+
+static EncodedJSValue JSC_HOST_CALL arrayIteratorPrototypeNext(ExecState*);
+
+void ArrayIteratorPrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
+{
+    Base::finishCreation(vm);
+    ASSERT(inherits(info()));
+    vm.prototypeMap.addPrototype(this);
+
+    JSC_NATIVE_FUNCTION(vm.propertyNames->next, arrayIteratorPrototypeNext, DontEnum, 0);
+}
+
+static EncodedJSValue createIteratorResult(CallFrame* callFrame, ArrayIterationKind kind, size_t index, JSValue result, bool done)
+{
+    JSGlobalObject* globalObject = callFrame->callee()->globalObject();
+    JSObject* resultObject = constructEmptyObject(callFrame);
+    resultObject->putDirect(callFrame->vm(), callFrame->propertyNames().done, jsBoolean(done));
+    switch (kind & ~ArrayIterateSparseTag) {
+    case ArrayIterateKey:
+        resultObject->putDirect(callFrame->vm(), callFrame->propertyNames().value, done ? jsUndefined() : jsNumber(index));
+        break;
+    case ArrayIterateValue:
+        resultObject->putDirect(callFrame->vm(), callFrame->propertyNames().value, done ? jsUndefined() : result);
+        break;
+    case ArrayIterateKeyValue: {
+        if (!done) {
+            MarkedArgumentBuffer args;
+            args.append(jsNumber(index));
+            args.append(result);
+            JSArray* resultArray = constructArray(callFrame, 0, globalObject, args);
+            resultObject->putDirect(callFrame->vm(), callFrame->propertyNames().value, resultArray);
+        } else
+            resultObject->putDirect(callFrame->vm(), callFrame->propertyNames().value, jsUndefined());
+
+        break;
+    }
+    default:
+        RELEASE_ASSERT_NOT_REACHED();
+    }
+    return JSValue::encode(resultObject);
+}
+    
+EncodedJSValue JSC_HOST_CALL arrayIteratorPrototypeNext(CallFrame* callFrame)
+{
+    JSArrayIterator* iterator = jsDynamicCast<JSArrayIterator*>(callFrame->thisValue());
+    if (!iterator)
+        throwTypeError(callFrame, ASCIILiteral("Cannot call ArrayIterator.next() on a non-ArrayIterator object"));
+    JSObject* iteratedObject = iterator->iteratedObject();
+    size_t index = iterator->nextIndex();
+    ArrayIterationKind kind = iterator->iterationKind();
+    JSValue jsLength = JSValue(iteratedObject).get(callFrame, callFrame->propertyNames().length);
+    if (callFrame->hadException())
+        return JSValue::encode(jsNull());
+
+    size_t length = jsLength.toUInt32(callFrame);
+    if (callFrame->hadException())
+        return JSValue::encode(jsNull());
+
+    if (index >= length) {
+        iterator->finish();
+        return createIteratorResult(callFrame, kind, index, jsUndefined(), true);
+    }
+    if (JSValue result = iteratedObject->tryGetIndexQuickly(index)) {
+        iterator->setNextIndex(index + 1);
+        return createIteratorResult(callFrame, kind, index, result, false);
+    }
+    
+    JSValue result = jsUndefined();
+    PropertySlot slot(iteratedObject);
+    if (kind > ArrayIterateSparseTag) {
+        // We assume that the indexed property will be an own property so cache the getOwnProperty
+        // method locally
+        auto getOwnPropertySlotByIndex = iteratedObject->methodTable()->getOwnPropertySlotByIndex;
+        while (index < length) {
+            if (getOwnPropertySlotByIndex(iteratedObject, callFrame, index, slot)) {
+                result = slot.getValue(callFrame, index);
+                break;
+            }
+            if (iteratedObject->getPropertySlot(callFrame, index, slot)) {
+                result = slot.getValue(callFrame, index);
+                break;
+            }
+            index++;
+        }
+    } else if (iteratedObject->getPropertySlot(callFrame, index, slot))
+        result = slot.getValue(callFrame, index);
+
+    if (index == length)
+        iterator->finish();
+    else
+        iterator->setNextIndex(index + 1);
+    return createIteratorResult(callFrame, kind, index, jsUndefined(), index == length);
+}
+
+}
diff --git a/Source/JavaScriptCore/runtime/ArrayIteratorPrototype.h b/Source/JavaScriptCore/runtime/ArrayIteratorPrototype.h
new file mode 100644 (file)
index 0000000..10ee9a6
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2013 Apple, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef ArrayIteratorPrototype_h
+#define ArrayIteratorPrototype_h
+
+#include "JSObject.h"
+
+namespace JSC {
+
+class ArrayIteratorPrototype : public JSNonFinalObject {
+public:
+    typedef JSNonFinalObject Base;
+
+    static ArrayIteratorPrototype* create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
+    {
+        ArrayIteratorPrototype* prototype = new (NotNull, allocateCell<ArrayIteratorPrototype>(vm.heap)) ArrayIteratorPrototype(vm, structure);
+        prototype->finishCreation(vm, globalObject);
+        return prototype;
+    }
+
+    DECLARE_INFO;
+
+    static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+    {
+        return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+    }
+
+private:
+    ArrayIteratorPrototype(VM& vm, Structure* structure)
+        : Base(vm, structure)
+    {
+    }
+    void finishCreation(VM&, JSGlobalObject*);
+};
+
+}
+
+#endif // !defined(ArrayIteratorPrototype_h)
index 5f8c76d..b2f6a98 100644 (file)
@@ -31,6 +31,7 @@
 #include "Error.h"
 #include "Interpreter.h"
 #include "JIT.h"
+#include "JSArrayIterator.h"
 #include "JSStringBuilder.h"
 #include "JSStringJoiner.h"
 #include "Lookup.h"
@@ -64,6 +65,9 @@ static EncodedJSValue JSC_HOST_CALL arrayProtoFuncMap(ExecState*);
 static EncodedJSValue JSC_HOST_CALL arrayProtoFuncReduce(ExecState*);
 static EncodedJSValue JSC_HOST_CALL arrayProtoFuncReduceRight(ExecState*);
 static EncodedJSValue JSC_HOST_CALL arrayProtoFuncLastIndexOf(ExecState*);
+static EncodedJSValue JSC_HOST_CALL arrayProtoFuncValues(ExecState*);
+static EncodedJSValue JSC_HOST_CALL arrayProtoFuncKeys(ExecState*);
+static EncodedJSValue JSC_HOST_CALL arrayProtoFuncEntries(ExecState*);
 
 }
 
@@ -112,6 +116,9 @@ const ClassInfo ArrayPrototype::s_info = {"Array", &JSArray::s_info, 0, ExecStat
   reduce         arrayProtoFuncReduce         DontEnum|Function 1
   reduceRight    arrayProtoFuncReduceRight    DontEnum|Function 1
   map            arrayProtoFuncMap            DontEnum|Function 1
+  values         arrayProtoFuncValues         DontEnum|Function 0
+  entries        arrayProtoFuncEntries        DontEnum|Function 0
+  keys           arrayProtoFuncKeys           DontEnum|Function 0
 @end
 */
 
@@ -1331,4 +1338,22 @@ EncodedJSValue JSC_HOST_CALL arrayProtoFuncLastIndexOf(ExecState* exec)
     return JSValue::encode(jsNumber(-1));
 }
 
+EncodedJSValue JSC_HOST_CALL arrayProtoFuncValues(ExecState* exec)
+{
+    JSObject* thisObj = exec->hostThisValue().toThis(exec, StrictMode).toObject(exec);
+    return JSValue::encode(JSArrayIterator::create(exec, exec->callee()->globalObject()->arrayIteratorStructure(), ArrayIterateValue, thisObj));
+}
+
+EncodedJSValue JSC_HOST_CALL arrayProtoFuncEntries(ExecState* exec)
+{
+    JSObject* thisObj = exec->hostThisValue().toThis(exec, StrictMode).toObject(exec);
+    return JSValue::encode(JSArrayIterator::create(exec, exec->callee()->globalObject()->arrayIteratorStructure(), ArrayIterateKeyValue, thisObj));
+}
+    
+EncodedJSValue JSC_HOST_CALL arrayProtoFuncKeys(ExecState* exec)
+{
+    JSObject* thisObj = exec->hostThisValue().toThis(exec, StrictMode).toObject(exec);
+    return JSValue::encode(JSArrayIterator::create(exec, exec->callee()->globalObject()->arrayIteratorStructure(), ArrayIterateKey, thisObj));
+}
+
 } // namespace JSC
index 5422c7a..d87d0b4 100644 (file)
@@ -29,6 +29,7 @@
 #define JSC_COMMON_IDENTIFIERS_EACH_PROPERTY_NAME(macro) \
     macro(Array) \
     macro(ArrayBuffer) \
+    macro(ArrayIterator) \
     macro(BYTES_PER_ELEMENT) \
     macro(Boolean) \
     macro(Date) \
@@ -80,6 +81,7 @@
     macro(descriptions) \
     macro(displayName) \
     macro(document) \
+    macro(done) \
     macro(enumerable) \
     macro(eval) \
     macro(exec) \
     macro(message) \
     macro(multiline) \
     macro(name) \
+    macro(next) \
     macro(now) \
     macro(numInlinedCalls) \
     macro(numInlinedGetByIds) \
@@ -208,6 +211,7 @@ namespace JSC {
         const Identifier underscoreProto;
         const Identifier thisIdentifier;
         const Identifier useStrictIdentifier;
+        const PrivateName iteratorPrivateName;
 
         
 #define JSC_IDENTIFIER_DECLARE_KEYWORD_NAME_GLOBAL(name) const Identifier name##Keyword;
index d4db10b..bd1eecc 100644 (file)
@@ -60,6 +60,11 @@ namespace JSC {
         
         CString ascii() const { return m_string.ascii(); }
         CString utf8() const { return m_string.utf8(); }
+        
+        static Identifier createEmptyUnique(VM* vm)
+        {
+            return Identifier(vm, String(StringImpl::createEmptyUnique()));
+        }
 
         static Identifier createLCharFromUChar(VM* vm, const UChar* s, int length) { return Identifier(vm, add8(vm, s, length)); }
 
diff --git a/Source/JavaScriptCore/runtime/JSArrayIterator.cpp b/Source/JavaScriptCore/runtime/JSArrayIterator.cpp
new file mode 100644 (file)
index 0000000..5a59f1e
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2013 Apple, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "JSArrayIterator.h"
+
+#include "JSCJSValueInlines.h"
+#include "JSCellInlines.h"
+
+namespace JSC {
+
+const ClassInfo JSArrayIterator::s_info = { "ArrayIterator", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSArrayIterator) };
+
+void JSArrayIterator::finishCreation(VM& vm, JSGlobalObject*, ArrayIterationKind kind, JSObject* iteratedObject)
+{
+    Base::finishCreation(vm);
+    m_iterationKind = kind;
+    m_iteratedObject.set(vm, this, iteratedObject);
+}
+
+}
diff --git a/Source/JavaScriptCore/runtime/JSArrayIterator.h b/Source/JavaScriptCore/runtime/JSArrayIterator.h
new file mode 100644 (file)
index 0000000..1ef0557
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2013 Apple, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef JSArrayIterator_h
+#define JSArrayIterator_h
+
+#include "JSObject.h"
+
+namespace JSC {
+
+enum ArrayIterationKind {
+    ArrayIterateKey,
+    ArrayIterateValue,
+    ArrayIterateKeyValue,
+    ArrayIterateSparseTag = 4,
+    ArrayIterateSparseKey,
+    ArrayIterateSparseValue,
+    ArrayIterateSparseKeyValue
+};
+
+class JSArrayIterator : public JSNonFinalObject {
+public:
+    typedef JSNonFinalObject Base;
+
+    DECLARE_EXPORT_INFO;
+
+    static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+    {
+        return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+    }
+
+    static JSArrayIterator* create(ExecState* exec, Structure* structure, ArrayIterationKind kind, JSObject* iteratedObject)
+    {
+        VM& vm = exec->vm();
+        JSArrayIterator* instance = new (NotNull, allocateCell<JSArrayIterator>(vm.heap)) JSArrayIterator(vm, structure);
+        instance->finishCreation(vm, structure->globalObject(), kind, iteratedObject);
+        return instance;
+    }
+
+    ArrayIterationKind iterationKind() const { return m_iterationKind; }
+    JSObject* iteratedObject() const { return m_iteratedObject.get(); }
+    size_t nextIndex() const { return m_nextIndex; }
+    void setNextIndex(size_t nextIndex) { m_nextIndex = nextIndex; }
+    void finish() { m_nextIndex = std::numeric_limits<size_t>::max(); }
+    
+    using JSNonFinalObject::arrayStorageOrNull;
+
+private:
+
+    static const unsigned StructureFlags = Base::StructureFlags;
+
+    JSArrayIterator(VM& vm, Structure* structure)
+        : Base(vm, structure)
+        , m_nextIndex(0)
+    {
+    }
+
+    void finishCreation(VM&, JSGlobalObject*, ArrayIterationKind, JSObject* iteratedObject);
+    
+    ArrayIterationKind m_iterationKind;
+    WriteBarrier<JSObject> m_iteratedObject;
+    size_t m_nextIndex;
+};
+
+}
+
+#endif // !defined(JSArrayIterator_h)
index ce840b2..92f5aba 100644 (file)
@@ -32,6 +32,8 @@
 
 #include "Arguments.h"
 #include "ArrayConstructor.h"
+#include "ArrayIteratorConstructor.h"
+#include "ArrayIteratorPrototype.h"
 #include "ArrayPrototype.h"
 #include "BooleanConstructor.h"
 #include "BooleanPrototype.h"
@@ -53,6 +55,7 @@
 #include "JSArrayBuffer.h"
 #include "JSArrayBufferConstructor.h"
 #include "JSArrayBufferPrototype.h"
+#include "JSArrayIterator.h"
 #include "JSBoundFunction.h"
 #include "JSCallbackConstructor.h"
 #include "JSCallbackFunction.h"
@@ -382,7 +385,12 @@ void JSGlobalObject::reset(JSValue prototype)
     FOR_EACH_SIMPLE_BUILTIN_TYPE(PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE)
 
 #undef PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE
-
+    PrototypeMap& prototypeMap = vm.prototypeMap;
+    Structure* iteratorResultStructure = prototypeMap.emptyObjectStructureForPrototype(m_objectPrototype.get(), JSFinalObject::defaultInlineCapacity());
+    PropertyOffset offset;
+    iteratorResultStructure = Structure::addPropertyTransition(vm, iteratorResultStructure, vm.propertyNames->done, 0, 0, offset);
+    iteratorResultStructure = Structure::addPropertyTransition(vm, iteratorResultStructure, vm.propertyNames->value, 0, 0, offset);
+    m_iteratorResultStructure.set(vm, this, iteratorResultStructure);
 
     m_evalFunction.set(vm, this, JSFunction::create(vm, this, 1, vm.propertyNames->eval.string(), globalFuncEval));
     putDirectWithoutTransition(vm, vm.propertyNames->eval, m_evalFunction.get(), DontEnum);
index 274c9be..a65b9f5 100644 (file)
@@ -81,6 +81,7 @@ struct HashTable;
     macro(Error, error, error, ErrorInstance, Error) \
     macro(JSArrayBuffer, arrayBuffer, arrayBuffer, JSArrayBuffer, ArrayBuffer) \
     macro(WeakMap, weakMap, weakMap, JSWeakMap, WeakMap) \
+    macro(ArrayIterator, arrayIterator, arrayIterator, JSArrayIterator, ArrayIterator) \
 
 #define DECLARE_SIMPLE_BUILTIN_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
     class JS ## capitalName; \
@@ -194,6 +195,8 @@ protected:
     WriteBarrier<Structure> m_regExpMatchesArrayStructure;
     WriteBarrier<Structure> m_regExpStructure;
     WriteBarrier<Structure> m_internalFunctionStructure;
+    
+    WriteBarrier<Structure> m_iteratorResultStructure;
 
 #if ENABLE(PROMISES)
     WriteBarrier<Structure> m_promiseStructure;
@@ -402,6 +405,7 @@ public:
     Structure* regExpStructure() const { return m_regExpStructure.get(); }
     Structure* setStructure() const { return m_setStructure.get(); }
     Structure* stringObjectStructure() const { return m_stringObjectStructure.get(); }
+    Structure* iteratorResultStructure() const { return m_iteratorResultStructure.get(); }
 
 #if ENABLE(PROMISES)
     Structure* promiseStructure() const { return m_promiseStructure.get(); }