aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2014-02-15 02:16:43 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-24 20:41:40 +0100
commitc78d1052c2509646c8cf13b460a8d098de836ad0 (patch)
treeb32bb074293b87996596789ec259f9170887298c /src/qml/jsruntime
parent00be968679152105fece89c3243a457b52d3f268 (diff)
Clean up object literal handling with integral indices
* Object literals with array indices are now created with one run-time call, instead of an initial one for non-integral keys followed by sub-sequent define_builtin_property calls. * Cleaned up propert name retrieval. Instead of using a visitor, it's easier to define a virtual method on the PropertyName type. The visitor doesn't buy us much as it's not possible to recurse within property names, and this way we can use it also from the function scanner to correctly determine the number of arguments needed for object literal initalizations. * Similarly the duplicated/common name member for all property assignments has been moved into PropertyName, for convenient access without AST casts. * Removed now unused builtin_define_property/settergetter functions from IR, run-time and moth. Change-Id: I90d54c81ea5f3f500f4f4a9c14f7caf5135e7f9f Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp59
-rw-r--r--src/qml/jsruntime/qv4runtime_p.h4
-rw-r--r--src/qml/jsruntime/qv4vme_moth.cpp10
3 files changed, 26 insertions, 47 deletions
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index f89a51fd85..7c7ce23bcb 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -1087,23 +1087,6 @@ void __qmljs_builtin_declare_var(ExecutionContext *ctx, bool deletable, const St
ctx->createMutableBinding(name, deletable);
}
-void __qmljs_builtin_define_property(ExecutionContext *ctx, const ValueRef object, const StringRef name, ValueRef val)
-{
- Scope scope(ctx);
- ScopedObject o(scope, object->asObject());
- assert(o);
-
- uint idx = name->asArrayIndex();
- if (idx != UINT_MAX) {
- if (idx > 16 && (!o->arrayData || idx > o->arrayData->length() * 2))
- o->initSparseArray();
- o->arraySet(idx, val);
- } else {
- ScopedValue v(scope, val ? *val : Primitive::undefinedValue());
- o->insertMember(name, v);
- }
-}
-
ReturnedValue __qmljs_builtin_define_array(ExecutionContext *ctx, Value *values, uint length)
{
Scope scope(ctx);
@@ -1117,24 +1100,7 @@ ReturnedValue __qmljs_builtin_define_array(ExecutionContext *ctx, Value *values,
return a.asReturnedValue();
}
-void __qmljs_builtin_define_getter_setter(ExecutionContext *ctx, const ValueRef object, const StringRef name, const ValueRef getter, const ValueRef setter)
-{
- Scope scope(ctx);
- ScopedObject o(scope, object->asObject());
- Q_ASSERT(!!o);
-
- uint idx = name->asArrayIndex();
- Property pd;
- pd.value = getter;
- pd.set = setter;
- if (idx != UINT_MAX) {
- o->arraySet(idx, pd, Attr_Accessor);
- } else {
- o->insertMember(name, pd, Attr_Accessor);
- }
-}
-
-ReturnedValue __qmljs_builtin_define_object_literal(QV4::ExecutionContext *ctx, const QV4::Value *args, int classId)
+ReturnedValue __qmljs_builtin_define_object_literal(QV4::ExecutionContext *ctx, const QV4::Value *args, int classId, int arrayValueCount, int arrayGetterSetterCount)
{
Scope scope(ctx);
QV4::InternalClass *klass = ctx->compilationUnit->runtimeClasses[classId];
@@ -1151,6 +1117,29 @@ ReturnedValue __qmljs_builtin_define_object_literal(QV4::ExecutionContext *ctx,
}
}
+ ScopedValue entry(scope);
+ for (int i = 0; i < arrayValueCount; ++i) {
+ uint idx = args->toUInt32();
+ if (idx > 16 && (!o->arrayData || idx > o->arrayData->length() * 2))
+ o->initSparseArray();
+ ++args;
+ entry = *args++;
+ o->arraySet(idx, entry);
+ }
+
+ ScopedProperty pd(scope);
+ for (int i = 0; i < arrayGetterSetterCount; ++i) {
+ uint idx = args->toUInt32();
+ if (idx > 16 && (!o->arrayData || idx > o->arrayData->length() * 2))
+ o->initSparseArray();
+ ++args;
+ pd->value = *args;
+ ++args;
+ pd->set = *args;
+ ++args;
+ o->arraySet(idx, pd, Attr_Accessor);
+ }
+
return o.asReturnedValue();
}
diff --git a/src/qml/jsruntime/qv4runtime_p.h b/src/qml/jsruntime/qv4runtime_p.h
index 1c34e554c3..dbe7e030e1 100644
--- a/src/qml/jsruntime/qv4runtime_p.h
+++ b/src/qml/jsruntime/qv4runtime_p.h
@@ -141,10 +141,8 @@ QV4::ExecutionContext *__qmljs_builtin_push_catch_scope(QV4::ExecutionContext *c
QV4::ExecutionContext *__qmljs_builtin_pop_scope(QV4::ExecutionContext *ctx);
ReturnedValue __qmljs_builtin_unwind_exception(ExecutionContext *ctx);
void __qmljs_builtin_declare_var(QV4::ExecutionContext *ctx, bool deletable, const QV4::StringRef name);
-void __qmljs_builtin_define_property(QV4::ExecutionContext *ctx, const QV4::ValueRef object, const QV4::StringRef name, QV4::ValueRef val);
QV4::ReturnedValue __qmljs_builtin_define_array(QV4::ExecutionContext *ctx, Value *values, uint length);
-void __qmljs_builtin_define_getter_setter(QV4::ExecutionContext *ctx, const QV4::ValueRef object, const QV4::StringRef name, const QV4::ValueRef getter, const QV4::ValueRef setter);
-QV4::ReturnedValue __qmljs_builtin_define_object_literal(QV4::ExecutionContext *ctx, const QV4::Value *args, int classId);
+QV4::ReturnedValue __qmljs_builtin_define_object_literal(QV4::ExecutionContext *ctx, const QV4::Value *args, int classId, int arrayValueCount, int arrayGetterSetterCount);
QV4::ReturnedValue __qmljs_builtin_setup_arguments_object(ExecutionContext *ctx);
void __qmljs_builtin_convert_this_to_object(ExecutionContext *ctx);
diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp
index 3c44063606..5ae0b3daff 100644
--- a/src/qml/jsruntime/qv4vme_moth.cpp
+++ b/src/qml/jsruntime/qv4vme_moth.cpp
@@ -473,14 +473,6 @@ QV4::ReturnedValue VME::run(QV4::ExecutionContext *context, const uchar *code
__qmljs_builtin_declare_var(context, instr.isDeletable, runtimeStrings[instr.varName]);
MOTH_END_INSTR(CallBuiltinDeclareVar)
- MOTH_BEGIN_INSTR(CallBuiltinDefineGetterSetter)
- __qmljs_builtin_define_getter_setter(context, VALUEPTR(instr.object), runtimeStrings[instr.name], VALUEPTR(instr.getter), VALUEPTR(instr.setter));
- MOTH_END_INSTR(CallBuiltinDefineGetterSetter)
-
- MOTH_BEGIN_INSTR(CallBuiltinDefineProperty)
- __qmljs_builtin_define_property(context, VALUEPTR(instr.object), runtimeStrings[instr.name], VALUEPTR(instr.value));
- MOTH_END_INSTR(CallBuiltinDefineProperty)
-
MOTH_BEGIN_INSTR(CallBuiltinDefineArray)
Q_ASSERT(instr.args + instr.argc <= stackSize);
QV4::Value *args = stack + instr.args;
@@ -489,7 +481,7 @@ QV4::ReturnedValue VME::run(QV4::ExecutionContext *context, const uchar *code
MOTH_BEGIN_INSTR(CallBuiltinDefineObjectLiteral)
QV4::Value *args = stack + instr.args;
- STOREVALUE(instr.result, __qmljs_builtin_define_object_literal(context, args, instr.internalClassId));
+ STOREVALUE(instr.result, __qmljs_builtin_define_object_literal(context, args, instr.internalClassId, instr.arrayValueCount, instr.arrayGetterSetterCount));
MOTH_END_INSTR(CallBuiltinDefineObjectLiteral)
MOTH_BEGIN_INSTR(CallBuiltinSetupArgumentsObject)