Change signature of defineOwnProperty to take an engine instead of a context
authorLars Knoll <lars.knoll@digia.com>
Wed, 12 Nov 2014 12:32:41 +0000 (13:32 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Sat, 15 Nov 2014 12:16:08 +0000 (13:16 +0100)
Change-Id: Ib0d558d17162a205974c6f2f0daf8af5b0b9547b
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/jsruntime/qv4argumentsobject.cpp
src/qml/jsruntime/qv4argumentsobject_p.h
src/qml/jsruntime/qv4context.cpp
src/qml/jsruntime/qv4jsonobject.cpp
src/qml/jsruntime/qv4object.cpp
src/qml/jsruntime/qv4object_p.h
src/qml/jsruntime/qv4objectproto.cpp

index 0a4abd4..14f9b0e 100644 (file)
@@ -96,11 +96,11 @@ void ArgumentsObject::fullyCreate()
     d()->fullyCreated = true;
 }
 
-bool ArgumentsObject::defineOwnProperty(ExecutionContext *ctx, uint index, const Property &desc, PropertyAttributes attrs)
+bool ArgumentsObject::defineOwnProperty(ExecutionEngine *engine, uint index, const Property &desc, PropertyAttributes attrs)
 {
     fullyCreate();
 
-    Scope scope(ctx);
+    Scope scope(engine);
     Property *pd = arrayData() ? arrayData()->getProperty(index) : 0;
     Property map;
     PropertyAttributes mapAttrs;
@@ -118,10 +118,10 @@ bool ArgumentsObject::defineOwnProperty(ExecutionContext *ctx, uint index, const
         pd->value = mappedArguments()->data[index];
     }
 
-    bool strict = ctx->d()->strictMode;
-    ctx->d()->strictMode = false;
-    bool result = Object::defineOwnProperty2(ctx, index, desc, attrs);
-    ctx->d()->strictMode = strict;
+    bool strict = engine->currentContext()->d()->strictMode;
+    engine->currentContext()->d()->strictMode = false;
+    bool result = Object::defineOwnProperty2(scope.engine, index, desc, attrs);
+    engine->currentContext()->d()->strictMode = strict;
 
     if (isMapped && attrs.isData()) {
         Q_ASSERT(arrayData());
@@ -137,8 +137,8 @@ bool ArgumentsObject::defineOwnProperty(ExecutionContext *ctx, uint index, const
         }
     }
 
-    if (ctx->d()->strictMode && !result)
-        return ctx->engine()->throwTypeError();
+    if (engine->currentContext()->d()->strictMode && !result)
+        return engine->throwTypeError();
     return result;
 }
 
index d1d2e36..d54dfbf 100644 (file)
@@ -112,7 +112,7 @@ struct ArgumentsObject: Object {
                 !static_cast<ArgumentsObject *>(m)->context()->strictMode;
     }
 
-    bool defineOwnProperty(ExecutionContext *ctx, uint index, const Property &desc, PropertyAttributes attrs);
+    bool defineOwnProperty(ExecutionEngine *engine, uint index, const Property &desc, PropertyAttributes attrs);
     static ReturnedValue getIndexed(Managed *m, uint index, bool *hasProperty);
     static void putIndexed(Managed *m, uint index, const ValueRef value);
     static bool deleteIndexedProperty(Managed *m, uint index);
index d3901f4..6d04717 100644 (file)
@@ -124,7 +124,7 @@ void ExecutionContext::createMutableBinding(String *name, bool deletable)
     Property desc(Primitive::undefinedValue());
     PropertyAttributes attrs(Attr_Data);
     attrs.setConfigurable(deletable);
-    activation->__defineOwnProperty__(this, name, desc, attrs);
+    activation->__defineOwnProperty__(scope.engine, name, desc, attrs);
 }
 
 
index 69bd97a..de5ffb5 100644 (file)
@@ -716,7 +716,7 @@ QString Stringify::Str(const QString &key, ValueRef v)
 
     if (replacerFunction) {
         ScopedObject holder(scope, ctx->d()->engine->newObject());
-        holder->put(ctx, QString(), value);
+        holder->put(scope.engine, QString(), value);
         ScopedCallData callData(scope, 2);
         callData->args[0] = Value::fromHeapObject(ctx->d()->engine->newString(key));
         callData->args[1] = value;
index b0737a0..29c2528 100644 (file)
@@ -71,10 +71,10 @@ bool Object::setPrototype(Object *proto)
     return true;
 }
 
-void Object::put(ExecutionContext *ctx, const QString &name, const ValueRef value)
+void Object::put(ExecutionEngine *engine, const QString &name, const ValueRef value)
 {
-    Scope scope(ctx);
-    ScopedString n(scope, ctx->d()->engine->newString(name));
+    Scope scope(engine);
+    ScopedString n(scope, engine->newString(name));
     put(n.getPointer(), value);
 }
 
@@ -827,21 +827,21 @@ bool Object::internalDeleteIndexedProperty(uint index)
 }
 
 // Section 8.12.9
-bool Object::__defineOwnProperty__(ExecutionContext *ctx, String *name, const Property &p, PropertyAttributes attrs)
+bool Object::__defineOwnProperty__(ExecutionEngine *engine, String *name, const Property &p, PropertyAttributes attrs)
 {
     uint idx = name->asArrayIndex();
     if (idx != UINT_MAX)
-        return __defineOwnProperty__(ctx, idx, p, attrs);
+        return __defineOwnProperty__(engine, idx, p, attrs);
 
     name->makeIdentifier();
 
-    Scope scope(ctx);
+    Scope scope(engine);
     Property *current;
     PropertyAttributes *cattrs;
     uint memberIndex;
 
-    if (isArrayObject() && name->equals(ctx->d()->engine->id_length)) {
-        assert(Heap::ArrayObject::LengthPropertyIndex == internalClass()->find(ctx->d()->engine->id_length));
+    if (isArrayObject() && name->equals(engine->id_length)) {
+        Q_ASSERT(Heap::ArrayObject::LengthPropertyIndex == internalClass()->find(engine->id_length));
         Property *lp = propertyAt(Heap::ArrayObject::LengthPropertyIndex);
         cattrs = internalClass()->propertyData.constData() + Heap::ArrayObject::LengthPropertyIndex;
         if (attrs.isEmpty() || p.isSubset(attrs, *lp, *cattrs))
@@ -854,7 +854,7 @@ bool Object::__defineOwnProperty__(ExecutionContext *ctx, String *name, const Pr
             uint l = p.value.asArrayLength(&ok);
             if (!ok) {
                 ScopedValue v(scope, p.value);
-                ctx->engine()->throwRangeError(v);
+                engine->throwRangeError(v);
                 return false;
             }
             succeeded = setArrayLength(l);
@@ -885,30 +885,30 @@ bool Object::__defineOwnProperty__(ExecutionContext *ctx, String *name, const Pr
         return true;
     }
 
-    return __defineOwnProperty__(ctx, memberIndex, name, p, attrs);
+    return __defineOwnProperty__(engine, memberIndex, name, p, attrs);
 reject:
-  if (ctx->d()->strictMode)
-      ctx->engine()->throwTypeError();
+  if (engine->currentContext()->d()->strictMode)
+      engine->throwTypeError();
   return false;
 }
 
-bool Object::__defineOwnProperty__(ExecutionContext *ctx, uint index, const Property &p, PropertyAttributes attrs)
+bool Object::__defineOwnProperty__(ExecutionEngine *engine, uint index, const Property &p, PropertyAttributes attrs)
 {
     // 15.4.5.1, 4b
     if (isArrayObject() && index >= getLength() && !internalClass()->propertyData[Heap::ArrayObject::LengthPropertyIndex].isWritable())
         goto reject;
 
     if (ArgumentsObject::isNonStrictArgumentsObject(this))
-        return static_cast<ArgumentsObject *>(this)->defineOwnProperty(ctx, index, p, attrs);
+        return static_cast<ArgumentsObject *>(this)->defineOwnProperty(engine, index, p, attrs);
 
-    return defineOwnProperty2(ctx, index, p, attrs);
+    return defineOwnProperty2(engine, index, p, attrs);
 reject:
-  if (ctx->d()->strictMode)
-      ctx->engine()->throwTypeError();
+  if (engine->currentContext()->d()->strictMode)
+      engine->throwTypeError();
   return false;
 }
 
-bool Object::defineOwnProperty2(ExecutionContext *ctx, uint index, const Property &p, PropertyAttributes attrs)
+bool Object::defineOwnProperty2(ExecutionEngine *engine, uint index, const Property &p, PropertyAttributes attrs)
 {
     Property *current = 0;
 
@@ -928,7 +928,7 @@ bool Object::defineOwnProperty2(ExecutionContext *ctx, uint index, const Propert
         pp.copy(p, attrs);
         pp.fullyPopulated(&attrs);
         if (attrs == Attr_Data) {
-            Scope scope(ctx);
+            Scope scope(engine);
             ScopedValue v(scope, pp.value);
             arraySet(index, v);
         } else {
@@ -937,14 +937,14 @@ bool Object::defineOwnProperty2(ExecutionContext *ctx, uint index, const Propert
         return true;
     }
 
-    return __defineOwnProperty__(ctx, index, 0, p, attrs);
+    return __defineOwnProperty__(engine, index, 0, p, attrs);
 reject:
-  if (ctx->d()->strictMode)
-      ctx->engine()->throwTypeError();
+  if (engine->currentContext()->d()->strictMode)
+      engine->throwTypeError();
   return false;
 }
 
-bool Object::__defineOwnProperty__(ExecutionContext *ctx, uint index, String *member, const Property &p, PropertyAttributes attrs)
+bool Object::__defineOwnProperty__(ExecutionEngine *engine, uint index, String *member, const Property &p, PropertyAttributes attrs)
 {
     // clause 5
     if (attrs.isEmpty())
@@ -1032,17 +1032,17 @@ bool Object::__defineOwnProperty__(ExecutionContext *ctx, uint index, String *me
         setHasAccessorProperty();
     return true;
   reject:
-    if (ctx->d()->strictMode)
-        ctx->engine()->throwTypeError();
+    if (engine->currentContext()->d()->strictMode)
+        engine->throwTypeError();
     return false;
 }
 
 
-bool Object::__defineOwnProperty__(ExecutionContext *ctx, const QString &name, const Property &p, PropertyAttributes attrs)
+bool Object::__defineOwnProperty__(ExecutionEngine *engine, const QString &name, const Property &p, PropertyAttributes attrs)
 {
-    Scope scope(ctx);
-    ScopedString s(scope, ctx->d()->engine->newString(name));
-    return __defineOwnProperty__(ctx, s.getPointer(), p, attrs);
+    Scope scope(engine);
+    ScopedString s(scope, engine->newString(name));
+    return __defineOwnProperty__(engine, s.getPointer(), p, attrs);
 }
 
 
index 3b1c4b7..e3c3e37 100644 (file)
@@ -121,16 +121,16 @@ struct Q_QML_EXPORT Object: Managed {
     bool hasOwnProperty(String *name) const;
     bool hasOwnProperty(uint index) const;
 
-    bool __defineOwnProperty__(ExecutionContext *ctx, uint index, String *member, const Property &p, PropertyAttributes attrs);
-    bool __defineOwnProperty__(ExecutionContext *ctx, String *name, const Property &p, PropertyAttributes attrs);
-    bool __defineOwnProperty__(ExecutionContext *ctx, uint index, const Property &p, PropertyAttributes attrs);
-    bool __defineOwnProperty__(ExecutionContext *ctx, const QString &name, const Property &p, PropertyAttributes attrs);
-    bool defineOwnProperty2(ExecutionContext *ctx, uint index, const Property &p, PropertyAttributes attrs);
+    bool __defineOwnProperty__(ExecutionEngine *engine, uint index, String *member, const Property &p, PropertyAttributes attrs);
+    bool __defineOwnProperty__(ExecutionEngine *engine, String *name, const Property &p, PropertyAttributes attrs);
+    bool __defineOwnProperty__(ExecutionEngine *engine, uint index, const Property &p, PropertyAttributes attrs);
+    bool __defineOwnProperty__(ExecutionEngine *engine, const QString &name, const Property &p, PropertyAttributes attrs);
+    bool defineOwnProperty2(ExecutionEngine *engine, uint index, const Property &p, PropertyAttributes attrs);
 
     //
     // helpers
     //
-    void put(ExecutionContext *ctx, const QString &name, const ValueRef value);
+    void put(ExecutionEngine *engine, const QString &name, const ValueRef value);
 
     static ReturnedValue getValue(const ValueRef thisObject, const Property *p, PropertyAttributes attrs);
     ReturnedValue getValue(const Property *p, PropertyAttributes attrs) const {
index ba3ef9b..a23be99 100644 (file)
@@ -190,7 +190,7 @@ ReturnedValue ObjectPrototype::method_defineProperty(CallContext *ctx)
     if (scope.engine->hasException)
         return Encode::undefined();
 
-    if (!O->__defineOwnProperty__(ctx, name.getPointer(), pd, attrs))
+    if (!O->__defineOwnProperty__(scope.engine, name.getPointer(), pd, attrs))
         return ctx->engine()->throwTypeError();
 
     return O.asReturnedValue();
@@ -227,9 +227,9 @@ ReturnedValue ObjectPrototype::method_defineProperties(CallContext *ctx)
             return Encode::undefined();
         bool ok;
         if (name)
-            ok = O->__defineOwnProperty__(ctx, name.getPointer(), n, nattrs);
+            ok = O->__defineOwnProperty__(scope.engine, name.getPointer(), n, nattrs);
         else
-            ok = O->__defineOwnProperty__(ctx, index, n, nattrs);
+            ok = O->__defineOwnProperty__(scope.engine, index, n, nattrs);
         if (!ok)
             return ctx->engine()->throwTypeError();
     }
@@ -495,7 +495,7 @@ ReturnedValue ObjectPrototype::method_defineGetter(CallContext *ctx)
     Property pd;
     pd.value = f;
     pd.set = Primitive::emptyValue();
-    o->__defineOwnProperty__(ctx, prop.getPointer(), pd, Attr_Accessor);
+    o->__defineOwnProperty__(scope.engine, prop.getPointer(), pd, Attr_Accessor);
     return Encode::undefined();
 }
 
@@ -523,7 +523,7 @@ ReturnedValue ObjectPrototype::method_defineSetter(CallContext *ctx)
     Property pd;
     pd.value = Primitive::emptyValue();
     pd.set = f;
-    o->__defineOwnProperty__(ctx, prop.getPointer(), pd, Attr_Accessor);
+    o->__defineOwnProperty__(scope.engine, prop.getPointer(), pd, Attr_Accessor);
     return Encode::undefined();
 }
 
@@ -647,24 +647,24 @@ ReturnedValue ObjectPrototype::fromPropertyDescriptor(ExecutionContext *ctx, con
     if (attrs.isData()) {
         pd.value = desc->value;
         s = engine->newString(QStringLiteral("value"));
-        o->__defineOwnProperty__(ctx, s.getPointer(), pd, Attr_Data);
+        o->__defineOwnProperty__(scope.engine, s.getPointer(), pd, Attr_Data);
         pd.value = Primitive::fromBoolean(attrs.isWritable());
         s = engine->newString(QStringLiteral("writable"));
-        o->__defineOwnProperty__(ctx, s.getPointer(), pd, Attr_Data);
+        o->__defineOwnProperty__(scope.engine, s.getPointer(), pd, Attr_Data);
     } else {
         pd.value = desc->getter() ? desc->getter()->asReturnedValue() : Encode::undefined();
         s = engine->newString(QStringLiteral("get"));
-        o->__defineOwnProperty__(ctx, s.getPointer(), pd, Attr_Data);
+        o->__defineOwnProperty__(scope.engine, s.getPointer(), pd, Attr_Data);
         pd.value = desc->setter() ? desc->setter()->asReturnedValue() : Encode::undefined();
         s = engine->newString(QStringLiteral("set"));
-        o->__defineOwnProperty__(ctx, s.getPointer(), pd, Attr_Data);
+        o->__defineOwnProperty__(scope.engine, s.getPointer(), pd, Attr_Data);
     }
     pd.value = Primitive::fromBoolean(attrs.isEnumerable());
     s = engine->newString(QStringLiteral("enumerable"));
-    o->__defineOwnProperty__(ctx, s.getPointer(), pd, Attr_Data);
+    o->__defineOwnProperty__(scope.engine, s.getPointer(), pd, Attr_Data);
     pd.value = Primitive::fromBoolean(attrs.isConfigurable());
     s = engine->newString(QStringLiteral("configurable"));
-    o->__defineOwnProperty__(ctx, s.getPointer(), pd, Attr_Data);
+    o->__defineOwnProperty__(scope.engine, s.getPointer(), pd, Attr_Data);
 
     return o.asReturnedValue();
 }