Title: [254419] trunk/Source/_javascript_Core
Revision
254419
Author
[email protected]
Date
2020-01-12 19:10:13 -0800 (Sun, 12 Jan 2020)

Log Message

[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:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (254418 => 254419)


--- trunk/Source/_javascript_Core/ChangeLog	2020-01-13 01:18:45 UTC (rev 254418)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-01-13 03:10:13 UTC (rev 254419)
@@ -1,5 +1,39 @@
 2020-01-12  Yusuke Suzuki  <[email protected]>
 
+        [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  <[email protected]>
+
         [JSC] Consistently use "var" in builtin JS
         https://bugs.webkit.org/show_bug.cgi?id=206157
 

Modified: trunk/Source/_javascript_Core/builtins/ArrayIteratorPrototype.js (254418 => 254419)


--- trunk/Source/_javascript_Core/builtins/ArrayIteratorPrototype.js	2020-01-13 01:18:45 UTC (rev 254418)
+++ trunk/Source/_javascript_Core/builtins/ArrayIteratorPrototype.js	2020-01-13 03:10:13 UTC (rev 254419)
@@ -45,8 +45,8 @@
     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);
@@ -53,13 +53,14 @@
             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 };
 }

Modified: trunk/Source/_javascript_Core/builtins/MapIteratorPrototype.js (254418 => 254419)


--- trunk/Source/_javascript_Core/builtins/MapIteratorPrototype.js	2020-01-13 01:18:45 UTC (rev 254418)
+++ trunk/Source/_javascript_Core/builtins/MapIteratorPrototype.js	2020-01-13 03:10:13 UTC (rev 254419)
@@ -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;

Modified: trunk/Source/_javascript_Core/builtins/MapPrototype.js (254418 => 254419)


--- trunk/Source/_javascript_Core/builtins/MapPrototype.js	2020-01-13 01:18:45 UTC (rev 254418)
+++ trunk/Source/_javascript_Core/builtins/MapPrototype.js	2020-01-13 03:10:13 UTC (rev 254419)
@@ -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 */)

Modified: trunk/Source/_javascript_Core/builtins/SetIteratorPrototype.js (254418 => 254419)


--- trunk/Source/_javascript_Core/builtins/SetIteratorPrototype.js	2020-01-13 01:18:45 UTC (rev 254418)
+++ trunk/Source/_javascript_Core/builtins/SetIteratorPrototype.js	2020-01-13 03:10:13 UTC (rev 254419)
@@ -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 };

Modified: trunk/Source/_javascript_Core/builtins/SetPrototype.js (254418 => 254419)


--- trunk/Source/_javascript_Core/builtins/SetPrototype.js	2020-01-13 01:18:45 UTC (rev 254418)
+++ trunk/Source/_javascript_Core/builtins/SetPrototype.js	2020-01-13 03:10:13 UTC (rev 254419)
@@ -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 */)

Modified: trunk/Source/_javascript_Core/bytecode/BytecodeIntrinsicRegistry.cpp (254418 => 254419)


--- trunk/Source/_javascript_Core/bytecode/BytecodeIntrinsicRegistry.cpp	2020-01-13 01:18:45 UTC (rev 254418)
+++ trunk/Source/_javascript_Core/bytecode/BytecodeIntrinsicRegistry.cpp	2020-01-13 03:10:13 UTC (rev 254419)
@@ -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)));

Modified: trunk/Source/_javascript_Core/bytecode/BytecodeIntrinsicRegistry.h (254418 => 254419)


--- trunk/Source/_javascript_Core/bytecode/BytecodeIntrinsicRegistry.h	2020-01-13 01:18:45 UTC (rev 254418)
+++ trunk/Source/_javascript_Core/bytecode/BytecodeIntrinsicRegistry.h	2020-01-13 03:10:13 UTC (rev 254419)
@@ -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) \

Modified: trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp (254418 => 254419)


--- trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp	2020-01-13 01:18:45 UTC (rev 254418)
+++ trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp	2020-01-13 03:10:13 UTC (rev 254419)
@@ -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)

Modified: trunk/Source/_javascript_Core/inspector/JSInjectedScriptHost.cpp (254418 => 254419)


--- trunk/Source/_javascript_Core/inspector/JSInjectedScriptHost.cpp	2020-01-13 01:18:45 UTC (rev 254418)
+++ trunk/Source/_javascript_Core/inspector/JSInjectedScriptHost.cpp	2020-01-13 03:10:13 UTC (rev 254419)
@@ -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;
 }
 

Modified: trunk/Source/_javascript_Core/runtime/JSArrayIterator.cpp (254418 => 254419)


--- trunk/Source/_javascript_Core/runtime/JSArrayIterator.cpp	2020-01-13 01:18:45 UTC (rev 254418)
+++ trunk/Source/_javascript_Core/runtime/JSArrayIterator.cpp	2020-01-13 03:10:13 UTC (rev 254419)
@@ -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)

Modified: trunk/Source/_javascript_Core/runtime/JSArrayIterator.h (254418 => 254419)


--- trunk/Source/_javascript_Core/runtime/JSArrayIterator.h	2020-01-13 01:18:45 UTC (rev 254418)
+++ trunk/Source/_javascript_Core/runtime/JSArrayIterator.h	2020-01-13 03:10:13 UTC (rev 254419)
@@ -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),
         } };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to