From 7d46d7251032ea31f7e7dcef4855a0e5d669fed5 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 26 Apr 2018 11:48:46 +0200 Subject: Implement support for arguments[Symbol.iterator] Change-Id: Ieb60e2d8f41c38146b588bc8cd225a2a567e0956 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4argumentsobject.cpp | 6 ++++++ src/qml/jsruntime/qv4argumentsobject_p.h | 6 ++++-- src/qml/jsruntime/qv4arrayobject.cpp | 7 +++++-- src/qml/jsruntime/qv4engine.cpp | 2 ++ src/qml/jsruntime/qv4engine_p.h | 2 ++ 5 files changed, 19 insertions(+), 4 deletions(-) (limited to 'src/qml/jsruntime') diff --git a/src/qml/jsruntime/qv4argumentsobject.cpp b/src/qml/jsruntime/qv4argumentsobject.cpp index 31f019f490..58951d043c 100644 --- a/src/qml/jsruntime/qv4argumentsobject.cpp +++ b/src/qml/jsruntime/qv4argumentsobject.cpp @@ -37,11 +37,13 @@ ** ****************************************************************************/ #include +#include #include #include #include #include #include +#include using namespace QV4; @@ -65,6 +67,8 @@ void Heap::ArgumentsObject::init(QV4::CppStackFrame *frame) setProperty(v4, CalleePropertyIndex, context->d()->function); Q_ASSERT(LengthPropertyIndex == internalClass->find(v4->id_length()->identifier())); setProperty(v4, LengthPropertyIndex, Primitive::fromInt32(context->argc())); + Q_ASSERT(SymbolIteratorPropertyIndex == internalClass->find(v4->symbol_iterator()->identifier())); + setProperty(v4, SymbolIteratorPropertyIndex, *v4->arrayProtoValues()); } void Heap::StrictArgumentsObject::init(QV4::CppStackFrame *frame) @@ -75,6 +79,8 @@ void Heap::StrictArgumentsObject::init(QV4::CppStackFrame *frame) Object::init(); Q_ASSERT(CalleePropertyIndex == internalClass->find(v4->id_callee()->identifier())); + Q_ASSERT(SymbolIteratorPropertyIndex == internalClass->find(v4->symbol_iterator()->identifier())); + setProperty(v4, SymbolIteratorPropertyIndex, *v4->arrayProtoValues()); setProperty(v4, CalleePropertyIndex + QV4::Object::GetterOffset, *v4->thrower()); setProperty(v4, CalleePropertyIndex + QV4::Object::SetterOffset, *v4->thrower()); diff --git a/src/qml/jsruntime/qv4argumentsobject_p.h b/src/qml/jsruntime/qv4argumentsobject_p.h index 01e2c10090..f246f66019 100644 --- a/src/qml/jsruntime/qv4argumentsobject_p.h +++ b/src/qml/jsruntime/qv4argumentsobject_p.h @@ -85,7 +85,8 @@ DECLARE_HEAP_OBJECT(ArgumentsObject, Object) { DECLARE_MARKOBJECTS(ArgumentsObject); enum { LengthPropertyIndex = 0, - CalleePropertyIndex = 1 + SymbolIteratorPropertyIndex = 1, + CalleePropertyIndex = 2 }; void init(CppStackFrame *frame); }; @@ -95,7 +96,8 @@ DECLARE_HEAP_OBJECT(ArgumentsObject, Object) { DECLARE_HEAP_OBJECT(StrictArgumentsObject, Object) { enum { LengthPropertyIndex = 0, - CalleePropertyIndex = 1 + SymbolIteratorPropertyIndex = 1, + CalleePropertyIndex = 2 }; void init(CppStackFrame *frame); }; diff --git a/src/qml/jsruntime/qv4arrayobject.cpp b/src/qml/jsruntime/qv4arrayobject.cpp index 4dfe177c12..71ffc29fca 100644 --- a/src/qml/jsruntime/qv4arrayobject.cpp +++ b/src/qml/jsruntime/qv4arrayobject.cpp @@ -120,8 +120,11 @@ void ArrayPrototype::init(ExecutionEngine *engine, Object *ctor) defineDefaultProperty(QStringLiteral("filter"), method_filter, 1); defineDefaultProperty(QStringLiteral("reduce"), method_reduce, 1); defineDefaultProperty(QStringLiteral("reduceRight"), method_reduceRight, 1); - defineDefaultProperty(QStringLiteral("values"), method_values, 0); - defineDefaultProperty(engine->symbol_iterator(), method_values, 0); + ScopedString valuesString(scope, engine->newIdentifier(QStringLiteral("values"))); + ScopedObject values(scope, FunctionObject::createBuiltinFunction(engine, valuesString, method_values, 0)); + engine->jsObjects[ExecutionEngine::ArrayProtoValues] = values; + defineDefaultProperty(QStringLiteral("values"), values); + defineDefaultProperty(engine->symbol_iterator(), values); } ReturnedValue ArrayPrototype::method_isArray(const FunctionObject *, const Value *, const Value *argv, int argc) diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 70072dabca..c8fb568ad1 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -290,9 +290,11 @@ ExecutionEngine::ExecutionEngine(QJSEngine *jsEngine) Scoped argsClass(scope); argsClass = newInternalClass(ArgumentsObject::staticVTable(), objectPrototype()); argsClass = argsClass->addMember(id_length()->identifier(), Attr_NotEnumerable); + argsClass = argsClass->addMember(symbol_iterator()->identifier(), Attr_Data|Attr_NotEnumerable); classes[Class_ArgumentsObject] = argsClass->addMember(id_callee()->identifier(), Attr_Data|Attr_NotEnumerable); argsClass = newInternalClass(StrictArgumentsObject::staticVTable(), objectPrototype()); argsClass = argsClass->addMember(id_length()->identifier(), Attr_NotEnumerable); + argsClass = argsClass->addMember(symbol_iterator()->identifier(), Attr_Data|Attr_NotEnumerable); classes[Class_StrictArgumentsObject] = argsClass->addMember(id_callee()->identifier(), Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable); *static_cast(globalObject) = newObject(); diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index 517d9f88a8..f6ffd775ea 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -163,6 +163,7 @@ public: ObjectProto, SymbolProto, ArrayProto, + ArrayProtoValues, PropertyListProto, StringProto, NumberProto, @@ -239,6 +240,7 @@ public: Object *objectPrototype() const { return reinterpret_cast(jsObjects + ObjectProto); } Object *symbolPrototype() const { return reinterpret_cast(jsObjects + SymbolProto); } Object *arrayPrototype() const { return reinterpret_cast(jsObjects + ArrayProto); } + Object *arrayProtoValues() const { return reinterpret_cast(jsObjects + ArrayProtoValues); } Object *propertyListPrototype() const { return reinterpret_cast(jsObjects + PropertyListProto); } Object *stringPrototype() const { return reinterpret_cast(jsObjects + StringProto); } Object *numberPrototype() const { return reinterpret_cast(jsObjects + NumberProto); } -- cgit v1.2.3