[JSC] Use internal object field mechanism to implement JSStringIterator
authorysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Jan 2020 03:12:13 +0000 (03:12 +0000)
committerysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Jan 2020 03:12:13 +0000 (03:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=206144

Reviewed by Ross Kirsling.

JSTests:

* stress/string-iterators.js:
* stress/tailCallForwardArguments.js:
(putFuncToPrivateName.createBuiltin):
(createTailCallForwardingFuncWith):

Source/JavaScriptCore:

This patch uses internal object field mechanism to implement JSStringIterator,
and we also put JSStringIterator into IsoSubspace.

* builtins/BuiltinNames.h:
* builtins/StringIteratorPrototype.js:
(next):
* bytecode/BytecodeIntrinsicRegistry.cpp:
(JSC::BytecodeIntrinsicRegistry::BytecodeIntrinsicRegistry):
* bytecode/BytecodeIntrinsicRegistry.h:
* bytecompiler/BytecodeGenerator.h:
(JSC::BytecodeGenerator::emitIsStringIterator):
* bytecompiler/NodesCodegen.cpp:
(JSC::stringIteratorInternalFieldIndex):
(JSC::BytecodeIntrinsicNode::emit_intrinsic_getStringIteratorInternalField):
(JSC::BytecodeIntrinsicNode::emit_intrinsic_putStringIteratorInternalField):
* inspector/JSInjectedScriptHost.cpp:
(Inspector::JSInjectedScriptHost::getInternalProperties):
* runtime/JSCast.h:
* runtime/JSStringIterator.cpp:
(JSC::JSStringIterator::finishCreation):
(JSC::JSStringIterator::clone):
(JSC::JSStringIterator::visitChildren):
(JSC::JSStringIterator::iteratedValue const): Deleted.
* runtime/JSStringIterator.h:
* runtime/JSType.cpp:
(WTF::printInternal):
* runtime/JSType.h:
* runtime/StringPrototype.cpp:
(JSC::stringProtoFuncIterator):
* runtime/VM.cpp:
* runtime/VM.h:

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

19 files changed:
JSTests/ChangeLog
JSTests/stress/string-iterators.js
JSTests/stress/tailCallForwardArguments.js
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/builtins/BuiltinNames.h
Source/JavaScriptCore/builtins/StringIteratorPrototype.js
Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.cpp
Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.h
Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp
Source/JavaScriptCore/runtime/JSCast.h
Source/JavaScriptCore/runtime/JSStringIterator.cpp
Source/JavaScriptCore/runtime/JSStringIterator.h
Source/JavaScriptCore/runtime/JSType.cpp
Source/JavaScriptCore/runtime/JSType.h
Source/JavaScriptCore/runtime/StringPrototype.cpp
Source/JavaScriptCore/runtime/VM.cpp
Source/JavaScriptCore/runtime/VM.h

index 8c647a2..53aeebf 100644 (file)
@@ -1,3 +1,15 @@
+2020-01-12  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        [JSC] Use internal object field mechanism to implement JSStringIterator
+        https://bugs.webkit.org/show_bug.cgi?id=206144
+
+        Reviewed by Ross Kirsling.
+
+        * stress/string-iterators.js:
+        * stress/tailCallForwardArguments.js:
+        (putFuncToPrivateName.createBuiltin):
+        (createTailCallForwardingFuncWith):
+
 2020-01-10  Yusuke Suzuki  <ysuzuki@apple.com>
 
         [JSC] Flush old tables in End phase
index f66b620..c5c7fee 100644 (file)
@@ -181,8 +181,6 @@ for (var primitive of primitives) {
     if (!didThrow)
         throw "Error: no error thrown";
     var message = 'TypeError: %StringIteratorPrototype%.next requires that |this| be a String Iterator instance';
-    if (primitive == null)
-        message = 'TypeError: %StringIteratorPrototype%.next requires that |this| not be null or undefined'
     if (String(didThrow) !== message)
         throw "Error: bad error thrown: " + didThrow;
 }
index 6972552..e584df1 100644 (file)
@@ -3,7 +3,7 @@
 var createBuiltin = $vm.createBuiltin;
 
 // This is pretty bad but I need a private name.
-var putFuncToPrivateName = createBuiltin(`(function (func) { @arrayIteratorIsDone = func })`)
+var putFuncToPrivateName = createBuiltin(`(function (func) { @generatorThis = func })`)
 putFuncToPrivateName(function (a,b) { return b; })
 
 function createTailCallForwardingFuncWith(body, thisValue) {
@@ -12,7 +12,7 @@ function createTailCallForwardingFuncWith(body, thisValue) {
 
         ${body}
 
-        return @tailCallForwardArguments(@arrayIteratorIsDone, ${thisValue});
+        return @tailCallForwardArguments(@generatorThis, ${thisValue});
     })`);
 }
 
index 05db9bc..0880783 100644 (file)
@@ -1,5 +1,44 @@
 2020-01-12  Yusuke Suzuki  <ysuzuki@apple.com>
 
+        [JSC] Use internal object field mechanism to implement JSStringIterator
+        https://bugs.webkit.org/show_bug.cgi?id=206144
+
+        Reviewed by Ross Kirsling.
+
+        This patch uses internal object field mechanism to implement JSStringIterator,
+        and we also put JSStringIterator into IsoSubspace.
+
+        * builtins/BuiltinNames.h:
+        * builtins/StringIteratorPrototype.js:
+        (next):
+        * bytecode/BytecodeIntrinsicRegistry.cpp:
+        (JSC::BytecodeIntrinsicRegistry::BytecodeIntrinsicRegistry):
+        * bytecode/BytecodeIntrinsicRegistry.h:
+        * bytecompiler/BytecodeGenerator.h:
+        (JSC::BytecodeGenerator::emitIsStringIterator):
+        * bytecompiler/NodesCodegen.cpp:
+        (JSC::stringIteratorInternalFieldIndex):
+        (JSC::BytecodeIntrinsicNode::emit_intrinsic_getStringIteratorInternalField):
+        (JSC::BytecodeIntrinsicNode::emit_intrinsic_putStringIteratorInternalField):
+        * inspector/JSInjectedScriptHost.cpp:
+        (Inspector::JSInjectedScriptHost::getInternalProperties):
+        * runtime/JSCast.h:
+        * runtime/JSStringIterator.cpp:
+        (JSC::JSStringIterator::finishCreation):
+        (JSC::JSStringIterator::clone):
+        (JSC::JSStringIterator::visitChildren):
+        (JSC::JSStringIterator::iteratedValue const): Deleted.
+        * runtime/JSStringIterator.h:
+        * runtime/JSType.cpp:
+        (WTF::printInternal):
+        * runtime/JSType.h:
+        * runtime/StringPrototype.cpp:
+        (JSC::stringProtoFuncIterator):
+        * runtime/VM.cpp:
+        * runtime/VM.h:
+
+2020-01-12  Yusuke Suzuki  <ysuzuki@apple.com>
+
         [JSC] Remove IsDone from JSArrayIterator
         https://bugs.webkit.org/show_bug.cgi?id=206140
 
index b0b7868..154fff8 100644 (file)
@@ -46,11 +46,6 @@ namespace JSC {
     JSC_COMMON_BYTECODE_INTRINSIC_CONSTANTS_EACH_NAME(macro) \
     macro(add) \
     macro(applyFunction) \
-    macro(arrayIteratorNextIndex) \
-    macro(arrayIterationKind) \
-    macro(arrayIteratorNext) \
-    macro(arrayIteratorIsDone) \
-    macro(arrayIteratorKind) \
     macro(arraySpeciesCreate) \
     macro(assert) \
     macro(callFunction) \
@@ -59,7 +54,6 @@ namespace JSC {
     macro(isView) \
     macro(iteratedObject) \
     macro(iteratedString) \
-    macro(stringIteratorNextIndex) \
     macro(promise) \
     macro(promiseOrCapability) \
     macro(Object) \
index d122de8..6dbdb76 100644 (file)
@@ -27,21 +27,18 @@ function next()
 {
     "use strict";
 
-    if (@isUndefinedOrNull(this))
-        @throwTypeError("%StringIteratorPrototype%.next requires that |this| not be null or undefined");
-
-    var position = @getByIdDirectPrivate(this, "stringIteratorNextIndex");
-    if (position === @undefined)
+    if (!@isStringIterator(this))
         @throwTypeError("%StringIteratorPrototype%.next requires that |this| be a String Iterator instance");
 
     var done = true;
     var value = @undefined;
 
-    var string = @getByIdDirectPrivate(this, "iteratedString");
-    if (string !== @undefined) {
+    var position = @getStringIteratorInternalField(this, @stringIteratorFieldIndex);
+    if (position !== -1) {
+        var string = @getStringIteratorInternalField(this, @stringIteratorFieldIteratedString);
         var length = string.length >>> 0;
         if (position >= length)
-            @putByIdDirectPrivate(this, "iteratedString", @undefined);
+            @putStringIteratorInternalField(this, @stringIteratorFieldIndex, -1);
         else {
             done = false;
 
@@ -55,8 +52,7 @@ function next()
                 else
                     value = string[position] + string[position + 1];
             }
-
-            @putByIdDirectPrivate(this, "stringIteratorNextIndex", position + value.length);
+            @putStringIteratorInternalField(this, @stringIteratorFieldIndex, position + value.length);
         }
     }
 
index 73cc87f..32aaf87 100644 (file)
@@ -38,6 +38,7 @@
 #include "JSGlobalObject.h"
 #include "JSModuleLoader.h"
 #include "JSPromise.h"
+#include "JSStringIterator.h"
 #include "Nodes.h"
 #include "StrongInlines.h"
 
@@ -91,6 +92,8 @@ BytecodeIntrinsicRegistry::BytecodeIntrinsicRegistry(VM& vm)
     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_arrayIteratorFieldKind.set(m_vm, jsNumber(static_cast<int32_t>(JSArrayIterator::Field::Kind)));
+    m_stringIteratorFieldIndex.set(m_vm, jsNumber(static_cast<int32_t>(JSStringIterator::Field::Index)));
+    m_stringIteratorFieldIteratedString.set(m_vm, jsNumber(static_cast<int32_t>(JSStringIterator::Field::IteratedString)));
     m_asyncGeneratorFieldSuspendReason.set(m_vm, jsNumber(static_cast<unsigned>(JSAsyncGenerator::Field::SuspendReason)));
     m_asyncGeneratorFieldQueueFirst.set(m_vm, jsNumber(static_cast<unsigned>(JSAsyncGenerator::Field::QueueFirst)));
     m_asyncGeneratorFieldQueueLast.set(m_vm, jsNumber(static_cast<unsigned>(JSAsyncGenerator::Field::QueueLast)));
index 0abd1c8..cf1c382 100644 (file)
@@ -46,6 +46,7 @@ enum class LinkTimeConstant : int32_t;
     macro(getGeneratorInternalField) \
     macro(getAsyncGeneratorInternalField) \
     macro(getArrayIteratorInternalField) \
+    macro(getStringIteratorInternalField) \
     macro(idWithProfile) \
     macro(isObject) \
     macro(isJSArray) \
@@ -57,6 +58,7 @@ enum class LinkTimeConstant : int32_t;
     macro(isRegExpObject) \
     macro(isMap) \
     macro(isSet) \
+    macro(isStringIterator) \
     macro(isArrayIterator) \
     macro(isUndefinedOrNull) \
     macro(tailCallForwardArguments) \
@@ -71,6 +73,7 @@ enum class LinkTimeConstant : int32_t;
     macro(putGeneratorInternalField) \
     macro(putAsyncGeneratorInternalField) \
     macro(putArrayIteratorInternalField) \
+    macro(putStringIteratorInternalField) \
     macro(toNumber) \
     macro(toString) \
     macro(toObject) \
@@ -122,6 +125,8 @@ enum class LinkTimeConstant : int32_t;
     macro(arrayIteratorFieldIsDone) \
     macro(arrayIteratorFieldIteratedObject) \
     macro(arrayIteratorFieldKind) \
+    macro(stringIteratorFieldIndex) \
+    macro(stringIteratorFieldIteratedString) \
     macro(asyncGeneratorFieldSuspendReason) \
     macro(asyncGeneratorFieldQueueFirst) \
     macro(asyncGeneratorFieldQueueLast) \
index 62d5cbb..a5f366b 100644 (file)
@@ -878,6 +878,7 @@ namespace JSC {
         RegisterID* emitIsRegExpObject(RegisterID* dst, RegisterID* src) { return emitIsCellWithType(dst, src, RegExpObjectType); }
         RegisterID* emitIsMap(RegisterID* dst, RegisterID* src) { return emitIsCellWithType(dst, src, JSMapType); }
         RegisterID* emitIsSet(RegisterID* dst, RegisterID* src) { return emitIsCellWithType(dst, src, JSSetType); }
+        RegisterID* emitIsStringIterator(RegisterID* dst, RegisterID* src) { return emitIsCellWithType(dst, src, JSStringIteratorType); }
         RegisterID* emitIsArrayIterator(RegisterID* dst, RegisterID* src) { return emitIsCellWithType(dst, src, JSArrayIteratorType); }
         RegisterID* emitIsObject(RegisterID* dst, RegisterID* src);
         RegisterID* emitIsNumber(RegisterID* dst, RegisterID* src);
index 6c1a4e2..3326fb3 100644 (file)
@@ -40,6 +40,7 @@
 #include "JSGenerator.h"
 #include "JSGlobalObject.h"
 #include "JSImmutableButterfly.h"
+#include "JSStringIterator.h"
 #include "LabelScope.h"
 #include "Lexer.h"
 #include "Parser.h"
@@ -1077,6 +1078,17 @@ static JSArrayIterator::Field arrayIteratorInternalFieldIndex(BytecodeIntrinsicN
     return JSArrayIterator::Field::Index;
 }
 
+static JSStringIterator::Field stringIteratorInternalFieldIndex(BytecodeIntrinsicNode* node)
+{
+    ASSERT(node->entry().type() == BytecodeIntrinsicRegistry::Type::Emitter);
+    if (node->entry().emitter() == &BytecodeIntrinsicNode::emit_intrinsic_stringIteratorFieldIndex)
+        return JSStringIterator::Field::Index;
+    if (node->entry().emitter() == &BytecodeIntrinsicNode::emit_intrinsic_stringIteratorFieldIteratedString)
+        return JSStringIterator::Field::IteratedString;
+    RELEASE_ASSERT_NOT_REACHED();
+    return JSStringIterator::Field::Index;
+}
+
 RegisterID* BytecodeIntrinsicNode::emit_intrinsic_getPromiseInternalField(BytecodeGenerator& generator, RegisterID* dst)
 {
     ArgumentListNode* node = m_args->m_listNode;
@@ -1129,6 +1141,19 @@ RegisterID* BytecodeIntrinsicNode::emit_intrinsic_getArrayIteratorInternalField(
     return generator.emitGetInternalField(generator.finalDestination(dst), base.get(), index);
 }
 
+RegisterID* BytecodeIntrinsicNode::emit_intrinsic_getStringIteratorInternalField(BytecodeGenerator& generator, RegisterID* dst)
+{
+    ArgumentListNode* node = m_args->m_listNode;
+    RefPtr<RegisterID> base = generator.emitNode(node);
+    node = node->m_next;
+    RELEASE_ASSERT(node->m_expr->isBytecodeIntrinsicNode());
+    unsigned index = static_cast<unsigned>(stringIteratorInternalFieldIndex(static_cast<BytecodeIntrinsicNode*>(node->m_expr)));
+    ASSERT(index < JSStringIterator::numberOfInternalFields);
+    ASSERT(!node->m_next);
+
+    return generator.emitGetInternalField(generator.finalDestination(dst), base.get(), index);
+}
+
 RegisterID* BytecodeIntrinsicNode::emit_intrinsic_argument(BytecodeGenerator& generator, RegisterID* dst)
 {
     ArgumentListNode* node = m_args->m_listNode;
@@ -1262,6 +1287,22 @@ RegisterID* BytecodeIntrinsicNode::emit_intrinsic_putArrayIteratorInternalField(
     return generator.move(dst, generator.emitPutInternalField(base.get(), index, value.get()));
 }
 
+RegisterID* BytecodeIntrinsicNode::emit_intrinsic_putStringIteratorInternalField(BytecodeGenerator& generator, RegisterID* dst)
+{
+    ArgumentListNode* node = m_args->m_listNode;
+    RefPtr<RegisterID> base = generator.emitNode(node);
+    node = node->m_next;
+    RELEASE_ASSERT(node->m_expr->isBytecodeIntrinsicNode());
+    unsigned index = static_cast<unsigned>(stringIteratorInternalFieldIndex(static_cast<BytecodeIntrinsicNode*>(node->m_expr)));
+    ASSERT(index < JSStringIterator::numberOfInternalFields);
+    node = node->m_next;
+    RefPtr<RegisterID> value = generator.emitNode(node);
+
+    ASSERT(!node->m_next);
+
+    return generator.move(dst, generator.emitPutInternalField(base.get(), index, value.get()));
+}
+
 RegisterID* BytecodeIntrinsicNode::emit_intrinsic_tailCallForwardArguments(BytecodeGenerator& generator, RegisterID* dst)
 {
     ArgumentListNode* node = m_args->m_listNode;
@@ -1395,6 +1436,7 @@ CREATE_INTRINSIC_FOR_BRAND_CHECK(isPromise, IsPromise)
 CREATE_INTRINSIC_FOR_BRAND_CHECK(isRegExpObject, IsRegExpObject)
 CREATE_INTRINSIC_FOR_BRAND_CHECK(isMap, IsMap)
 CREATE_INTRINSIC_FOR_BRAND_CHECK(isSet, IsSet)
+CREATE_INTRINSIC_FOR_BRAND_CHECK(isStringIterator, IsStringIterator)
 CREATE_INTRINSIC_FOR_BRAND_CHECK(isArrayIterator, IsArrayIterator)
 CREATE_INTRINSIC_FOR_BRAND_CHECK(isUndefinedOrNull, IsUndefinedOrNull)
 
index ef2c410..f14578d 100644 (file)
@@ -431,7 +431,7 @@ JSValue JSInjectedScriptHost::getInternalProperties(JSGlobalObject* globalObject
         JSArray* array = constructEmptyArray(globalObject, nullptr, 1);
         RETURN_IF_EXCEPTION(scope, JSValue());
         scope.release();
-        array->putDirectIndex(globalObject, index++, constructInternalProperty(globalObject, "string", stringIterator->iteratedValue(globalObject)));
+        array->putDirectIndex(globalObject, index++, constructInternalProperty(globalObject, "string", stringIterator->iteratedString()));
         return array;
     }
 
index f8f3a4f..673e01c 100644 (file)
@@ -48,6 +48,8 @@ inline To jsCast(JSValue from)
 // Specific type overloads.
 #define FOR_EACH_JS_DYNAMIC_CAST_JS_TYPE_OVERLOAD(macro) \
     macro(JSImmutableButterfly, JSType::JSImmutableButterflyType, JSType::JSImmutableButterflyType) \
+    macro(JSArrayIterator, JSType::JSArrayIteratorType, JSType::JSArrayIteratorType) \
+    macro(JSStringIterator, JSType::JSStringIteratorType, JSType::JSStringIteratorType) \
     macro(JSObject, FirstObjectType, LastObjectType) \
     macro(JSFinalObject, JSType::FinalObjectType, JSType::FinalObjectType) \
     macro(JSFunction, JSType::JSFunctionType, JSType::JSFunctionType) \
index 351d470..16bf5dd 100644 (file)
 #include "config.h"
 #include "JSStringIterator.h"
 
-#include "BuiltinNames.h"
 #include "JSCInlines.h"
+#include "JSInternalFieldObjectImplInlines.h"
 
 namespace JSC {
 
 const ClassInfo JSStringIterator::s_info = { "String Iterator", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSStringIterator) };
 
-void JSStringIterator::finishCreation(VM& vm, JSGlobalObject*, JSString* iteratedString)
+void JSStringIterator::finishCreation(VM& vm, JSString* iteratedString)
 {
     Base::finishCreation(vm);
     ASSERT(inherits(vm, info()));
-    putDirect(vm, vm.propertyNames->builtinNames().iteratedStringPrivateName(), iteratedString);
-    putDirect(vm, vm.propertyNames->builtinNames().stringIteratorNextIndexPrivateName(), jsNumber(0));
-}
-
-JSValue JSStringIterator::iteratedValue(JSGlobalObject* globalObject) const
-{
-    return getDirect(globalObject->vm(), globalObject->vm().propertyNames->builtinNames().iteratedStringPrivateName());
+    internalField(Field::Index).set(vm, this, jsNumber(0));
+    internalField(Field::IteratedString).set(vm, this, iteratedString);
 }
 
 JSStringIterator* JSStringIterator::clone(JSGlobalObject* globalObject)
 {
     VM& vm = globalObject->vm();
-    JSValue iteratedString = getDirect(vm, vm.propertyNames->builtinNames().iteratedStringPrivateName());
-    JSValue nextIndex = getDirect(vm, vm.propertyNames->builtinNames().stringIteratorNextIndexPrivateName());
-
-    auto clone = JSStringIterator::create(globalObject, globalObject->stringIteratorStructure(), asString(iteratedString));
-    clone->putDirect(vm, vm.propertyNames->builtinNames().stringIteratorNextIndexPrivateName(), nextIndex);
+    JSString* iteratedString = jsCast<JSString*>(this->iteratedString());
+    auto* clone = JSStringIterator::create(vm, globalObject->stringIteratorStructure(), iteratedString);
+    clone->internalField(Field::Index).set(vm, clone, this->index());
     return clone;
 }
 
+void JSStringIterator::visitChildren(JSCell* cell, SlotVisitor& visitor)
+{
+    auto* thisObject = jsCast<JSStringIterator*>(cell);
+    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+    Base::visitChildren(thisObject, visitor);
+}
+
 } // namespace JSC
index bfd9716..b48b7a8 100644 (file)
 
 namespace JSC {
 
-class JSStringIterator final : public JSNonFinalObject {
+class JSStringIterator final : public JSInternalFieldObjectImpl<2> {
 public:
-    typedef JSNonFinalObject Base;
+    using Base = JSInternalFieldObjectImpl<2>;
+
+    enum class Field : uint8_t {
+        Index = 0,
+        IteratedString,
+    };
 
     DECLARE_EXPORT_INFO;
 
+    static size_t allocationSize(Checked<size_t> inlineCapacity)
+    {
+        ASSERT_UNUSED(inlineCapacity, inlineCapacity == 0U);
+        return sizeof(JSStringIterator);
+    }
+
+    template<typename CellType, SubspaceAccess mode>
+    static IsoSubspace* subspaceFor(VM& vm)
+    {
+        return vm.stringIteratorSpace<mode>();
+    }
+
+    static std::array<JSValue, numberOfInternalFields> initialValues()
+    {
+        return { {
+            jsNumber(0),
+            jsNull(),
+        } };
+    }
+
+    const WriteBarrier<Unknown>& internalField(Field field) const { return Base::internalField(static_cast<uint32_t>(field)); }
+    WriteBarrier<Unknown>& internalField(Field field) { return Base::internalField(static_cast<uint32_t>(field)); }
+
     static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
     {
-        return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+        return Structure::create(vm, globalObject, prototype, TypeInfo(JSStringIteratorType, StructureFlags), info());
     }
 
-    static JSStringIterator* create(JSGlobalObject* globalObject, Structure* structure, JSString* iteratedString)
+    static JSStringIterator* create(VM& vm, Structure* structure, JSString* iteratedString)
     {
-        VM& vm = getVM(globalObject);
         JSStringIterator* instance = new (NotNull, allocateCell<JSStringIterator>(vm.heap)) JSStringIterator(vm, structure);
-        instance->finishCreation(vm, structure->globalObject(), iteratedString);
+        instance->finishCreation(vm, iteratedString);
         return instance;
     }
 
-    JSValue iteratedValue(JSGlobalObject*) const;
+    JSValue iteratedString() const { return internalField(Field::IteratedString).get(); }
+    JSValue index() const { return internalField(Field::Index).get(); }
     JSStringIterator* clone(JSGlobalObject*);
 
+    static void visitChildren(JSCell*, SlotVisitor&);
+
 private:
     JSStringIterator(VM& vm, Structure* structure)
         : Base(vm, structure)
     {
     }
 
-    void finishCreation(VM&, JSGlobalObject*, JSString* iteratedString);
+    void finishCreation(VM&, JSString* iteratedString);
 };
 
 } // namespace JSC
index 1038dc5..b02b347 100644 (file)
@@ -100,6 +100,7 @@ void printInternal(PrintStream& out, JSC::JSType type)
     CASE(JSGeneratorType)
     CASE(JSAsyncGeneratorType)
     CASE(JSArrayIteratorType)
+    CASE(JSStringIteratorType)
     CASE(JSPromiseType)
     CASE(JSMapType)
     CASE(JSSetType)
index 2d1d308..1479925 100644 (file)
@@ -111,6 +111,7 @@ enum JSType : uint8_t {
     JSGeneratorType,
     JSAsyncGeneratorType,
     JSArrayIteratorType,
+    JSStringIteratorType,
     JSPromiseType,
     JSMapType,
     JSSetType,
index 470aac1..53b8778 100644 (file)
@@ -1860,7 +1860,7 @@ EncodedJSValue JSC_HOST_CALL stringProtoFuncIterator(JSGlobalObject* globalObjec
         return throwVMTypeError(globalObject, scope);
     JSString* string = thisValue.toString(globalObject);
     RETURN_IF_EXCEPTION(scope, encodedJSValue());
-    return JSValue::encode(JSStringIterator::create(globalObject, globalObject->stringIteratorStructure(), string));
+    return JSValue::encode(JSStringIterator::create(vm, globalObject->stringIteratorStructure(), string));
 }
 
 enum class NormalizationForm { NFC, NFD, NFKC, NFKD };
index ac234dd..4752aa0 100644 (file)
 #include "JSSet.h"
 #include "JSSetIterator.h"
 #include "JSSourceCode.h"
+#include "JSStringIterator.h"
 #include "JSTemplateObjectDescriptor.h"
 #include "JSToWasmICCallee.h"
 #include "JSTypedArrays.h"
@@ -1441,6 +1442,7 @@ void VM::ensureShadowChicken()
 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(apiGlobalObjectSpace, apiGlobalObjectHeapCellType.get(), JSAPIGlobalObject)
 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(apiValueWrapperSpace, cellHeapCellType.get(), JSAPIValueWrapper)
 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(arrayBufferSpace, cellHeapCellType.get(), JSArrayBuffer)
+DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(arrayIteratorSpace, cellHeapCellType.get(), JSArrayIterator)
 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(asyncGeneratorSpace, cellHeapCellType.get(), JSAsyncGenerator)
 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(bigIntObjectSpace, cellHeapCellType.get(), BigIntObject)
 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(booleanObjectSpace, cellHeapCellType.get(), BooleanObject)
@@ -1457,7 +1459,6 @@ DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(float32ArraySpace, cellHeapCellType.get(
 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(float64ArraySpace, cellHeapCellType.get(), JSFloat64Array)
 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(functionRareDataSpace, destructibleCellHeapCellType.get(), FunctionRareData)
 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(generatorSpace, cellHeapCellType.get(), JSGenerator)
-DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(arrayIteratorSpace, cellHeapCellType.get(), JSArrayIterator)
 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(globalObjectSpace, globalObjectHeapCellType.get(), JSGlobalObject)
 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(jsModuleRecordSpace, jsModuleRecordHeapCellType.get(), JSModuleRecord)
 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(int8ArraySpace, cellHeapCellType.get(), JSInt8Array)
@@ -1477,6 +1478,7 @@ DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(setBucketSpace, cellHeapCellType.get(),
 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(setIteratorSpace, cellHeapCellType.get(), JSSetIterator)
 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(setSpace, cellHeapCellType.get(), JSSet)
 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(strictEvalActivationSpace, cellHeapCellType.get(), StrictEvalActivation)
+DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(stringIteratorSpace, cellHeapCellType.get(), JSStringIterator)
 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(sourceCodeSpace, destructibleCellHeapCellType.get(), JSSourceCode)
 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(symbolSpace, destructibleCellHeapCellType.get(), Symbol)
 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(symbolObjectSpace, cellHeapCellType.get(), SymbolObject)
index 824769c..9c2a16c 100644 (file)
@@ -493,6 +493,7 @@ public:
     DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(apiGlobalObjectSpace)
     DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(apiValueWrapperSpace)
     DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(arrayBufferSpace)
+    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(arrayIteratorSpace)
     DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(asyncGeneratorSpace)
     DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(bigIntObjectSpace)
     DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(booleanObjectSpace)
@@ -509,7 +510,6 @@ public:
     DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(float64ArraySpace)
     DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(functionRareDataSpace)
     DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(generatorSpace)
-    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(arrayIteratorSpace)
     DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(globalObjectSpace)
     DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(int8ArraySpace)
     DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(int16ArraySpace)
@@ -529,6 +529,7 @@ public:
     DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(setIteratorSpace)
     DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(setSpace)
     DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(strictEvalActivationSpace)
+    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(stringIteratorSpace)
     DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(sourceCodeSpace)
     DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(symbolSpace)
     DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(symbolObjectSpace)