[JSC] Remove IsDone from JSArrayIterator
https://bugs.webkit.org/show_bug.cgi?id=206140
Reviewed by Keith Miller.
We can store `-1` in Index field to represent whether the iterator is closed.
While this patch does not change the allocation size of JSArrayIterator, this style can
shrink the size of JSStringIterator when we implement it in the same style.
We also rename iterationKindKeyValue to iterationKindEntries.
* builtins/ArrayIteratorPrototype.js:
(globalPrivate.arrayIteratorNextHelper):
* builtins/MapIteratorPrototype.js:
(globalPrivate.mapIteratorNext):
* builtins/MapPrototype.js:
(entries):
* builtins/SetIteratorPrototype.js:
(globalPrivate.setIteratorNext):
* builtins/SetPrototype.js:
(entries):
* bytecode/BytecodeIntrinsicRegistry.cpp:
(JSC::BytecodeIntrinsicRegistry::BytecodeIntrinsicRegistry):
* bytecode/BytecodeIntrinsicRegistry.h:
* bytecompiler/NodesCodegen.cpp:
(JSC::arrayIteratorInternalFieldIndex):
* inspector/JSInjectedScriptHost.cpp:
(Inspector::cloneArrayIteratorObject):
* runtime/JSArrayIterator.cpp:
(JSC::JSArrayIterator::finishCreation):
* runtime/JSArrayIterator.h:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@254419 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog
index 8f1eaa4..05db9bc 100644
--- a/Source/JavaScriptCore/ChangeLog
+++ b/Source/JavaScriptCore/ChangeLog
@@ -1,5 +1,39 @@
2020-01-12 Yusuke Suzuki <ysuzuki@apple.com>
+ [JSC] Remove IsDone from JSArrayIterator
+ https://bugs.webkit.org/show_bug.cgi?id=206140
+
+ Reviewed by Keith Miller.
+
+ We can store `-1` in Index field to represent whether the iterator is closed.
+ While this patch does not change the allocation size of JSArrayIterator, this style can
+ shrink the size of JSStringIterator when we implement it in the same style.
+
+ We also rename iterationKindKeyValue to iterationKindEntries.
+
+ * builtins/ArrayIteratorPrototype.js:
+ (globalPrivate.arrayIteratorNextHelper):
+ * builtins/MapIteratorPrototype.js:
+ (globalPrivate.mapIteratorNext):
+ * builtins/MapPrototype.js:
+ (entries):
+ * builtins/SetIteratorPrototype.js:
+ (globalPrivate.setIteratorNext):
+ * builtins/SetPrototype.js:
+ (entries):
+ * bytecode/BytecodeIntrinsicRegistry.cpp:
+ (JSC::BytecodeIntrinsicRegistry::BytecodeIntrinsicRegistry):
+ * bytecode/BytecodeIntrinsicRegistry.h:
+ * bytecompiler/NodesCodegen.cpp:
+ (JSC::arrayIteratorInternalFieldIndex):
+ * inspector/JSInjectedScriptHost.cpp:
+ (Inspector::cloneArrayIteratorObject):
+ * runtime/JSArrayIterator.cpp:
+ (JSC::JSArrayIterator::finishCreation):
+ * runtime/JSArrayIterator.h:
+
+2020-01-12 Yusuke Suzuki <ysuzuki@apple.com>
+
[JSC] Consistently use "var" in builtin JS
https://bugs.webkit.org/show_bug.cgi?id=206157
diff --git a/Source/JavaScriptCore/builtins/ArrayIteratorPrototype.js b/Source/JavaScriptCore/builtins/ArrayIteratorPrototype.js
index b416fbd..99a8c19 100644
--- a/Source/JavaScriptCore/builtins/ArrayIteratorPrototype.js
+++ b/Source/JavaScriptCore/builtins/ArrayIteratorPrototype.js
@@ -45,21 +45,22 @@
var done = true;
var value;
- if (!@getArrayIteratorInternalField(this, @arrayIteratorFieldIsDone)) {
- var index = @getArrayIteratorInternalField(this, @arrayIteratorFieldIndex);
+ var index = @getArrayIteratorInternalField(this, @arrayIteratorFieldIndex);
+ if (index !== -1) {
var length = array.length >>> 0;
if (index < length) {
@putArrayIteratorInternalField(this, @arrayIteratorFieldIndex, index + 1);
done = false;
if (kind === @iterationKindKey)
value = index;
- else {
+ else {
value = array[index];
- value = kind === @iterationKindValue ? value : [index, value];
+ if (kind === @iterationKindEntries)
+ value = [index, value];
}
- }
+ } else
+ @putArrayIteratorInternalField(this, @arrayIteratorFieldIndex, -1);
}
- @putArrayIteratorInternalField(this, @arrayIteratorFieldIsDone, done);
return { value, done };
}
diff --git a/Source/JavaScriptCore/builtins/MapIteratorPrototype.js b/Source/JavaScriptCore/builtins/MapIteratorPrototype.js
index 41cd408..fffcee8 100644
--- a/Source/JavaScriptCore/builtins/MapIteratorPrototype.js
+++ b/Source/JavaScriptCore/builtins/MapIteratorPrototype.js
@@ -36,7 +36,7 @@
if (!done) {
var key = @mapBucketKey(bucket);
value = @mapBucketValue(bucket);
- if (kind === @iterationKindKeyValue)
+ if (kind === @iterationKindEntries)
value = [ key, value ]
else if (kind === @iterationKindKey)
value = key;
diff --git a/Source/JavaScriptCore/builtins/MapPrototype.js b/Source/JavaScriptCore/builtins/MapPrototype.js
index 8464459..8a5bd3c 100644
--- a/Source/JavaScriptCore/builtins/MapPrototype.js
+++ b/Source/JavaScriptCore/builtins/MapPrototype.js
@@ -62,7 +62,7 @@
if (!@isMap(this))
@throwTypeError("Map.prototype.entries requires that |this| be Map");
- return new @MapIterator(this, @iterationKindKeyValue);
+ return new @MapIterator(this, @iterationKindEntries);
}
function forEach(callback /*, thisArg */)
diff --git a/Source/JavaScriptCore/builtins/SetIteratorPrototype.js b/Source/JavaScriptCore/builtins/SetIteratorPrototype.js
index 183ed67..e9ce8f0 100644
--- a/Source/JavaScriptCore/builtins/SetIteratorPrototype.js
+++ b/Source/JavaScriptCore/builtins/SetIteratorPrototype.js
@@ -35,7 +35,7 @@
var done = bucket === @sentinelSetBucket;
if (!done) {
value = @setBucketKey(bucket);
- if (kind === @iterationKindKeyValue)
+ if (kind === @iterationKindEntries)
value = [ value, value ]
}
return { value, done };
diff --git a/Source/JavaScriptCore/builtins/SetPrototype.js b/Source/JavaScriptCore/builtins/SetPrototype.js
index ade519d..6df8e8f 100644
--- a/Source/JavaScriptCore/builtins/SetPrototype.js
+++ b/Source/JavaScriptCore/builtins/SetPrototype.js
@@ -52,7 +52,7 @@
if (!@isSet(this))
@throwTypeError("Set.prototype.entries requires that |this| be Set");
- return new @SetIterator(this, @iterationKindKeyValue);
+ return new @SetIterator(this, @iterationKindEntries);
}
function forEach(callback /*, thisArg */)
diff --git a/Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.cpp b/Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.cpp
index 00f1379..73cc87f 100644
--- a/Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.cpp
+++ b/Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.cpp
@@ -58,7 +58,7 @@
m_Infinity.set(m_vm, jsDoubleNumber(std::numeric_limits<double>::infinity()));
m_iterationKindKey.set(m_vm, jsNumber(static_cast<unsigned>(IterationKind::Keys)));
m_iterationKindValue.set(m_vm, jsNumber(static_cast<unsigned>(IterationKind::Values)));
- m_iterationKindKeyValue.set(m_vm, jsNumber(static_cast<unsigned>(IterationKind::Entries)));
+ m_iterationKindEntries.set(m_vm, jsNumber(static_cast<unsigned>(IterationKind::Entries)));
m_MAX_ARRAY_INDEX.set(m_vm, jsNumber(MAX_ARRAY_INDEX));
m_MAX_STRING_LENGTH.set(m_vm, jsNumber(JSString::MaxLength));
m_MAX_SAFE_INTEGER.set(m_vm, jsDoubleNumber(maxSafeInteger()));
@@ -90,7 +90,6 @@
m_GeneratorStateExecuting.set(m_vm, jsNumber(static_cast<int32_t>(JSGenerator::GeneratorState::Executing)));
m_arrayIteratorFieldIteratedObject.set(m_vm, jsNumber(static_cast<int32_t>(JSArrayIterator::Field::IteratedObject)));
m_arrayIteratorFieldIndex.set(m_vm, jsNumber(static_cast<int32_t>(JSArrayIterator::Field::Index)));
- m_arrayIteratorFieldIsDone.set(m_vm, jsNumber(static_cast<int32_t>(JSArrayIterator::Field::IsDone)));
m_arrayIteratorFieldKind.set(m_vm, jsNumber(static_cast<int32_t>(JSArrayIterator::Field::Kind)));
m_asyncGeneratorFieldSuspendReason.set(m_vm, jsNumber(static_cast<unsigned>(JSAsyncGenerator::Field::SuspendReason)));
m_asyncGeneratorFieldQueueFirst.set(m_vm, jsNumber(static_cast<unsigned>(JSAsyncGenerator::Field::QueueFirst)));
diff --git a/Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.h b/Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.h
index b5c5f51..0abd1c8 100644
--- a/Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.h
+++ b/Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.h
@@ -89,7 +89,7 @@
macro(Infinity) \
macro(iterationKindKey) \
macro(iterationKindValue) \
- macro(iterationKindKeyValue) \
+ macro(iterationKindEntries) \
macro(MAX_ARRAY_INDEX) \
macro(MAX_STRING_LENGTH) \
macro(MAX_SAFE_INTEGER) \
diff --git a/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp b/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
index 8c82f57..6c1a4e2 100644
--- a/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
+++ b/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
@@ -1069,8 +1069,6 @@
ASSERT(node->entry().type() == BytecodeIntrinsicRegistry::Type::Emitter);
if (node->entry().emitter() == &BytecodeIntrinsicNode::emit_intrinsic_arrayIteratorFieldIndex)
return JSArrayIterator::Field::Index;
- if (node->entry().emitter() == &BytecodeIntrinsicNode::emit_intrinsic_arrayIteratorFieldIsDone)
- return JSArrayIterator::Field::IsDone;
if (node->entry().emitter() == &BytecodeIntrinsicNode::emit_intrinsic_arrayIteratorFieldIteratedObject)
return JSArrayIterator::Field::IteratedObject;
if (node->entry().emitter() == &BytecodeIntrinsicNode::emit_intrinsic_arrayIteratorFieldKind)
diff --git a/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp b/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp
index 3f19474..ef2c410 100644
--- a/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp
+++ b/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp
@@ -546,7 +546,6 @@
{
JSArrayIterator* clone = JSArrayIterator::create(vm, globalObject->arrayIteratorStructure(), iteratorObject->iteratedObject(), iteratorObject->internalField(JSArrayIterator::Field::Kind).get());
clone->internalField(JSArrayIterator::Field::Index).set(vm, clone, iteratorObject->internalField(JSArrayIterator::Field::Index).get());
- clone->internalField(JSArrayIterator::Field::IsDone).set(vm, clone, iteratorObject->internalField(JSArrayIterator::Field::IsDone).get());
return clone;
}
diff --git a/Source/JavaScriptCore/runtime/JSArrayIterator.cpp b/Source/JavaScriptCore/runtime/JSArrayIterator.cpp
index 254e749..62163e5 100644
--- a/Source/JavaScriptCore/runtime/JSArrayIterator.cpp
+++ b/Source/JavaScriptCore/runtime/JSArrayIterator.cpp
@@ -62,10 +62,10 @@
void JSArrayIterator::finishCreation(VM& vm)
{
+ Base::finishCreation(vm);
auto values = initialValues();
for (unsigned index = 0; index < values.size(); ++index)
Base::internalField(index).set(vm, this, values[index]);
- Base::finishCreation(vm);
}
void JSArrayIterator::visitChildren(JSCell* cell, SlotVisitor& visitor)
diff --git a/Source/JavaScriptCore/runtime/JSArrayIterator.h b/Source/JavaScriptCore/runtime/JSArrayIterator.h
index b5ea8d8..a3a76b8 100644
--- a/Source/JavaScriptCore/runtime/JSArrayIterator.h
+++ b/Source/JavaScriptCore/runtime/JSArrayIterator.h
@@ -35,12 +35,10 @@
enum class Field : uint8_t {
Index = 0,
- IsDone,
IteratedObject,
Kind,
};
- // JSArrayIterator has one inline storage slot, which is pointing internalField(0).
static size_t allocationSize(Checked<size_t> inlineCapacity)
{
ASSERT_UNUSED(inlineCapacity, inlineCapacity == 0U);
@@ -57,7 +55,6 @@
{
return { {
jsNumber(0),
- jsBoolean(false),
jsNull(),
jsNumber(0),
} };