aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4proxy.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-03-12 15:46:29 +0100
committerUlf Hermann <ulf.hermann@qt.io>2021-03-17 13:10:22 +0100
commit9caea013ceb221b5617c4940e7bb9ee9fecdd631 (patch)
treef4480e860a965f6515e516475baeced69b5d91fd /src/qml/jsruntime/qv4proxy.cpp
parentb0e9c83f99aa7090c82b7c55894f5e264b74608a (diff)
Clean up JSCallData setup
We either have pre-populated arguments and thisObject, then we can just use them and keep them const. Or, we want to allocate and populate the arguments and the thisObject. Then, do allocate them in a separate object, and transform that into JSCallData afterwards if necessary. Furthermore, avoid alloc(0) as that just returns the current stack top. Writing to it will clobber other data. Rather, just use nullptr and crash if it's written to. Also, remove the useless operator-> from JSCallData. That one just confuses the reader. Change-Id: I8310911fcfe005b05a07b78fcb3791d991a0c2ce Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4proxy.cpp')
-rw-r--r--src/qml/jsruntime/qv4proxy.cpp79
1 files changed, 45 insertions, 34 deletions
diff --git a/src/qml/jsruntime/qv4proxy.cpp b/src/qml/jsruntime/qv4proxy.cpp
index bc46f0ce58..b223e73f0f 100644
--- a/src/qml/jsruntime/qv4proxy.cpp
+++ b/src/qml/jsruntime/qv4proxy.cpp
@@ -90,10 +90,11 @@ ReturnedValue ProxyObject::virtualGet(const Managed *m, PropertyKey id, const Va
if (hasProperty)
*hasProperty = true;
- JSCallData cdata(handler, scope.alloc(3), 3);
- cdata.args[0] = target;
- cdata.args[1] = id.toStringOrSymbol(scope.engine);
- cdata.args[2] = *receiver;
+ Value *args = scope.alloc(3);
+ args[0] = target;
+ args[1] = id.toStringOrSymbol(scope.engine);
+ args[2] = *receiver;
+ JSCallData cdata(handler, args, 3);
ScopedValue trapResult(scope, static_cast<const FunctionObject *>(trap.ptr)->call(cdata));
if (scope.engine->hasException)
@@ -131,11 +132,12 @@ bool ProxyObject::virtualPut(Managed *m, PropertyKey id, const Value &value, Val
if (!trap->isFunctionObject())
return scope.engine->throwTypeError();
- JSCallData cdata(handler, scope.alloc(4), 4);
- cdata.args[0] = target;
- cdata.args[1] = id.toStringOrSymbol(scope.engine);
- cdata.args[2] = value;
- cdata.args[3] = *receiver;
+ Value *args = scope.alloc(4);
+ args[0] = target;
+ args[1] = id.toStringOrSymbol(scope.engine);
+ args[2] = value;
+ args[3] = *receiver;
+ JSCallData cdata(handler, args, 4);
ScopedValue trapResult(scope, static_cast<const FunctionObject *>(trap.ptr)->call(cdata));
if (scope.engine->hasException || !trapResult->toBoolean())
@@ -172,10 +174,11 @@ bool ProxyObject::virtualDeleteProperty(Managed *m, PropertyKey id)
if (!trap->isFunctionObject())
return scope.engine->throwTypeError();
- JSCallData cdata(handler, scope.alloc(3), 3);
- cdata.args[0] = target;
- cdata.args[1] = id.toStringOrSymbol(scope.engine);
- cdata.args[2] = o->d(); // ### fix receiver handling
+ Value *args = scope.alloc(3);
+ args[0] = target;
+ args[1] = id.toStringOrSymbol(scope.engine);
+ args[2] = o->d(); // ### fix receiver handling
+ JSCallData cdata(handler, args, 3);
ScopedValue trapResult(scope, static_cast<const FunctionObject *>(trap.ptr)->call(cdata));
if (scope.engine->hasException || !trapResult->toBoolean())
@@ -208,9 +211,10 @@ bool ProxyObject::virtualHasProperty(const Managed *m, PropertyKey id)
if (!trap->isFunctionObject())
return scope.engine->throwTypeError();
- JSCallData cdata(handler, scope.alloc(2), 2);
- cdata.args[0] = target;
- cdata.args[1] = id.isArrayIndex() ? Value::fromUInt32(id.asArrayIndex()).toString(scope.engine) : id.asStringOrSymbol();
+ Value *args = scope.alloc(2);
+ args[0] = target;
+ args[1] = id.isArrayIndex() ? Value::fromUInt32(id.asArrayIndex()).toString(scope.engine) : id.asStringOrSymbol();
+ JSCallData cdata(handler, args, 2);
ScopedValue trapResult(scope, static_cast<const FunctionObject *>(trap.ptr)->call(cdata));
if (scope.engine->hasException)
@@ -250,9 +254,10 @@ PropertyAttributes ProxyObject::virtualGetOwnProperty(const Managed *m, Property
return Attr_Invalid;
}
- JSCallData cdata(handler, scope.alloc(2), 2);
- cdata.args[0] = target;
- cdata.args[1] = id.isArrayIndex() ? Value::fromUInt32(id.asArrayIndex()).toString(scope.engine) : id.asStringOrSymbol();
+ Value *args = scope.alloc(2);
+ args[0] = target;
+ args[1] = id.isArrayIndex() ? Value::fromUInt32(id.asArrayIndex()).toString(scope.engine) : id.asStringOrSymbol();
+ JSCallData cdata(handler, args, 2);
ScopedValue trapResult(scope, static_cast<const FunctionObject *>(trap.ptr)->call(cdata));
if (scope.engine->hasException)
@@ -325,10 +330,11 @@ bool ProxyObject::virtualDefineOwnProperty(Managed *m, PropertyKey id, const Pro
return false;
}
- JSCallData cdata(handler, scope.alloc(3), 3);
- cdata.args[0] = target;
- cdata.args[1] = id.isArrayIndex() ? Value::fromUInt32(id.asArrayIndex()).toString(scope.engine) : id.asStringOrSymbol();
- cdata.args[2] = ObjectPrototype::fromPropertyDescriptor(scope.engine, p, attrs);
+ Value *args = scope.alloc(3);
+ args[0] = target;
+ args[1] = id.isArrayIndex() ? Value::fromUInt32(id.asArrayIndex()).toString(scope.engine) : id.asStringOrSymbol();
+ args[2] = ObjectPrototype::fromPropertyDescriptor(scope.engine, p, attrs);
+ JSCallData cdata(handler, args, 3);
ScopedValue trapResult(scope, static_cast<const FunctionObject *>(trap.ptr)->call(cdata));
bool result = !scope.engine->hasException && trapResult->toBoolean();
@@ -377,8 +383,9 @@ bool ProxyObject::virtualIsExtensible(const Managed *m)
if (!trap->isFunctionObject())
return scope.engine->throwTypeError();
- JSCallData cdata(handler, scope.alloc(1), 1);
- cdata.args[0] = target;
+ Value *args = scope.alloc(1);
+ args[0] = target;
+ JSCallData cdata(handler, args, 1);
ScopedValue trapResult(scope, static_cast<const FunctionObject *>(trap.ptr)->call(cdata));
if (scope.engine->hasException)
@@ -410,8 +417,9 @@ bool ProxyObject::virtualPreventExtensions(Managed *m)
if (!trap->isFunctionObject())
return scope.engine->throwTypeError();
- JSCallData cdata(handler, scope.alloc(1), 1);
- cdata.args[0] = target;
+ Value *args = scope.alloc(1);
+ args[0] = target;
+ JSCallData cdata(handler, args, 1);
ScopedValue trapResult(scope, static_cast<const FunctionObject *>(trap.ptr)->call(cdata));
if (scope.engine->hasException)
@@ -447,8 +455,9 @@ Heap::Object *ProxyObject::virtualGetPrototypeOf(const Managed *m)
return nullptr;
}
- JSCallData cdata(handler, scope.alloc(1), 1);
- cdata.args[0] = target;
+ Value *args = scope.alloc(1);
+ args[0] = target;
+ JSCallData cdata(handler, args, 1);
ScopedValue trapResult(scope, static_cast<const FunctionObject *>(trap.ptr)->call(cdata));
if (scope.engine->hasException)
@@ -491,9 +500,10 @@ bool ProxyObject::virtualSetPrototypeOf(Managed *m, const Object *p)
return false;
}
- JSCallData cdata(handler, scope.alloc(2), 2);
- cdata.args[0] = target;
- cdata.args[1] = p ? p->asReturnedValue() : Encode::null();
+ Value *args = scope.alloc(2);
+ args[0] = target;
+ args[1] = p ? p->asReturnedValue() : Encode::null();
+ JSCallData cdata(handler, args, 2);
ScopedValue trapResult(scope, static_cast<const FunctionObject *>(trap.ptr)->call(cdata));
bool result = !scope.engine->hasException && trapResult->toBoolean();
@@ -584,8 +594,9 @@ OwnPropertyKeyIterator *ProxyObject::virtualOwnPropertyKeys(const Object *m, Val
return nullptr;
}
- JSCallData cdata(handler, scope.alloc(1), 1);
- cdata.args[0] = target;
+ Value *args = scope.alloc(1);
+ args[0] = target;
+ JSCallData cdata(handler, args, 1);
ScopedObject trapResult(scope, static_cast<const FunctionObject *>(trap.ptr)->call(cdata));
if (scope.engine->hasException)
return nullptr;