Commit 9719b8c9 authored by oliver@apple.com's avatar oliver@apple.com

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.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@156791 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent ea2abd61
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
......@@ -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']
......
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
<!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>
......@@ -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']",
......
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")
......@@ -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
......
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
......@@ -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 \
......
......@@ -425,6 +425,8 @@
<ClCompile Include="..\runtime\ArrayBuffer.cpp" />
<ClCompile Include="..\runtime\ArrayBufferView.cpp" />
<ClCompile Include="..\runtime\ArrayConstructor.cpp" />
<ClInclude Include="..\runtime\ArrayIteratorConstructor.cpp" />
<ClInclude Include="..\runtime\ArrayIteratorPrototype.cpp" />
<ClCompile Include="..\runtime\ArrayPrototype.cpp" />
<ClCompile Include="..\runtime\BooleanConstructor.cpp" />
<ClCompile Include="..\runtime\BooleanObject.cpp" />
......@@ -460,6 +462,7 @@
<ClCompile Include="..\runtime\JSAPIValueWrapper.cpp" />
<ClCompile Include="..\runtime\JSActivation.cpp" />
<ClCompile Include="..\runtime\JSArray.cpp" />
<ClCompile Include="..\runtime\JSArrayIterator.cpp" />
<ClCompile Include="..\runtime\JSArrayBuffer.cpp" />
<ClCompile Include="..\runtime\JSArrayBufferConstructor.cpp" />
<ClCompile Include="..\runtime\JSArrayBufferPrototype.cpp" />
......@@ -840,6 +843,8 @@
<ClInclude Include="..\runtime\ArrayBufferView.h" />
<ClInclude Include="..\runtime\ArrayConstructor.h" />
<ClInclude Include="..\runtime\ArrayConventions.h" />
<ClInclude Include="..\runtime\ArrayIteratorConstructor.h" />
<ClInclude Include="..\runtime\ArrayIteratorPrototype.h" />
<ClInclude Include="..\runtime\ArrayPrototype.h" />
<ClInclude Include="..\runtime\ArrayStorage.h" />
<ClInclude Include="..\runtime\BatchedTransitionOptimizer.h" />
......@@ -898,6 +903,7 @@
<ClInclude Include="..\runtime\JSArrayBufferPrototype.h" />
<ClInclude Include="..\runtime\JSArrayBufferView.h" />
<ClInclude Include="..\runtime\JSArrayBufferViewInlines.h" />
<ClCompile Include="..\runtime\JSArrayIterator.h" />
<ClInclude Include="..\runtime\JSBoundFunction.h" />
<ClInclude Include="..\runtime\JSCJSValue.h" />
<ClInclude Include="..\runtime\JSCJSValueInlines.h" />
......
......@@ -938,6 +938,12 @@
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 */; };
......@@ -2159,6 +2165,12 @@
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>"; };
......@@ -3431,6 +3443,12 @@
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>";
......@@ -4313,6 +4331,7 @@
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 */,
......@@ -4372,6 +4391,7 @@
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 */,
......@@ -4419,6 +4439,7 @@
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 */,
......@@ -5097,6 +5118,7 @@
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 */,
......@@ -5189,6 +5211,7 @@
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 */,
......@@ -5233,6 +5256,7 @@
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 */,
......
/*
* 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);
}
}
/*
* 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)
/*
* 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);
}
}
/*
* 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