From ec55e174844734967577a99209e23c4d0769e884 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 1 Nov 2017 14:42:43 +0100 Subject: Convert TypedArray and friends to new calling convention Change-Id: Ia532b98738edb1bcc3fa5b81456763f2ec49952a Reviewed-by: Erik Verbruggen --- src/qml/jsruntime/qv4arraybuffer.cpp | 31 ++++++++------- src/qml/jsruntime/qv4arraybuffer_p.h | 8 ++-- src/qml/jsruntime/qv4dataview.cpp | 74 ++++++++++++++++++------------------ src/qml/jsruntime/qv4dataview_p.h | 18 ++++----- src/qml/jsruntime/qv4typedarray.cpp | 44 ++++++++++----------- src/qml/jsruntime/qv4typedarray_p.h | 12 +++--- 6 files changed, 93 insertions(+), 94 deletions(-) diff --git a/src/qml/jsruntime/qv4arraybuffer.cpp b/src/qml/jsruntime/qv4arraybuffer.cpp index 3f06ce8bd5..f7b9e8acef 100644 --- a/src/qml/jsruntime/qv4arraybuffer.cpp +++ b/src/qml/jsruntime/qv4arraybuffer.cpp @@ -78,13 +78,13 @@ ReturnedValue ArrayBufferCtor::call(const FunctionObject *f, const Value *, cons return callAsConstructor(f, argv, argc); } -ReturnedValue ArrayBufferCtor::method_isView(const BuiltinFunction *, CallData *callData) +ReturnedValue ArrayBufferCtor::method_isView(const FunctionObject *, const Value *, const Value *argv, int argc) { - if (callData->argc() < 1) + if (argc < 1) return Encode(false); - if (callData->args[0].as() || - callData->args[0].as()) + if (argv[0].as() || + argv[0].as()) return Encode(true); return Encode(false); @@ -157,25 +157,25 @@ void ArrayBufferPrototype::init(ExecutionEngine *engine, Object *ctor) defineDefaultProperty(QStringLiteral("toString"), method_toString, 0); } -ReturnedValue ArrayBufferPrototype::method_get_byteLength(const BuiltinFunction *b, CallData *callData) +ReturnedValue ArrayBufferPrototype::method_get_byteLength(const FunctionObject *b, const Value *thisObject, const Value *, int) { - ArrayBuffer *a = callData->thisObject.as(); + const ArrayBuffer *a = thisObject->as(); if (!a) return b->engine()->throwTypeError(); return Encode(a->d()->data->size); } -ReturnedValue ArrayBufferPrototype::method_slice(const BuiltinFunction *b, CallData *callData) +ReturnedValue ArrayBufferPrototype::method_slice(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { ExecutionEngine *v4 = b->engine(); - ArrayBuffer *a = callData->thisObject.as(); + const ArrayBuffer *a = thisObject->as(); if (!a) return v4->throwTypeError(); - double start = callData->argc() > 0 ? callData->args[0].toInteger() : 0; - double end = (callData->argc() < 2 || callData->args[1].isUndefined()) ? - a->d()->data->size : callData->args[1].toInteger(); + double start = argc > 0 ? argv[0].toInteger() : 0; + double end = (argc < 2 || argv[1].isUndefined()) ? + a->d()->data->size : argv[1].toInteger(); if (v4->hasException) return QV4::Encode::undefined(); @@ -187,10 +187,9 @@ ReturnedValue ArrayBufferPrototype::method_slice(const BuiltinFunction *b, CallD if (!constructor) return v4->throwTypeError(); - JSCallData jsCallData(scope, 1); double newLen = qMax(final - first, 0.); - jsCallData->args[0] = QV4::Encode(newLen); - QV4::Scoped newBuffer(scope, constructor->callAsConstructor(jsCallData)); + ScopedValue argument(scope, QV4::Encode(newLen)); + QV4::Scoped newBuffer(scope, constructor->callAsConstructor(argument, 1)); if (!newBuffer || newBuffer->d()->data->size < (int)newLen) return v4->throwTypeError(); @@ -198,10 +197,10 @@ ReturnedValue ArrayBufferPrototype::method_slice(const BuiltinFunction *b, CallD return Encode::undefined(); } -ReturnedValue ArrayBufferPrototype::method_toString(const BuiltinFunction *b, CallData *callData) +ReturnedValue ArrayBufferPrototype::method_toString(const FunctionObject *b, const Value *thisObject, const Value *, int) { ExecutionEngine *v4 = b->engine(); - ArrayBuffer *a = callData->thisObject.as(); + const ArrayBuffer *a = thisObject->as(); if (!a) RETURN_UNDEFINED(); return Encode(v4->newString(QString::fromUtf8(a->asByteArray()))); diff --git a/src/qml/jsruntime/qv4arraybuffer_p.h b/src/qml/jsruntime/qv4arraybuffer_p.h index e144faa47f..e236a23d1f 100644 --- a/src/qml/jsruntime/qv4arraybuffer_p.h +++ b/src/qml/jsruntime/qv4arraybuffer_p.h @@ -81,7 +81,7 @@ struct ArrayBufferCtor: FunctionObject static ReturnedValue callAsConstructor(const FunctionObject *f, const Value *argv, int argc); static ReturnedValue call(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc); - static ReturnedValue method_isView(const BuiltinFunction *, CallData *callData); + static ReturnedValue method_isView(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); }; @@ -104,9 +104,9 @@ struct ArrayBufferPrototype: Object { void init(ExecutionEngine *engine, Object *ctor); - static ReturnedValue method_get_byteLength(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_slice(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_toString(const BuiltinFunction *, CallData *callData); + static ReturnedValue method_get_byteLength(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_slice(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); }; diff --git a/src/qml/jsruntime/qv4dataview.cpp b/src/qml/jsruntime/qv4dataview.cpp index 815f6ed991..397ef1cfec 100644 --- a/src/qml/jsruntime/qv4dataview.cpp +++ b/src/qml/jsruntime/qv4dataview.cpp @@ -119,27 +119,27 @@ void DataViewPrototype::init(ExecutionEngine *engine, Object *ctor) defineDefaultProperty(QStringLiteral("setUInt32"), method_set, 0); } -ReturnedValue DataViewPrototype::method_get_buffer(const BuiltinFunction *b, CallData *callData) +ReturnedValue DataViewPrototype::method_get_buffer(const FunctionObject *b, const Value *thisObject, const Value *, int) { - DataView *v = callData->thisObject.as(); + const DataView *v = thisObject->as(); if (!v) return b->engine()->throwTypeError(); return v->d()->buffer->asReturnedValue(); } -ReturnedValue DataViewPrototype::method_get_byteLength(const BuiltinFunction *b, CallData *callData) +ReturnedValue DataViewPrototype::method_get_byteLength(const FunctionObject *b, const Value *thisObject, const Value *, int) { - DataView *v = callData->thisObject.as(); + const DataView *v = thisObject->as(); if (!v) return b->engine()->throwTypeError(); return Encode(v->d()->byteLength); } -ReturnedValue DataViewPrototype::method_get_byteOffset(const BuiltinFunction *b, CallData *callData) +ReturnedValue DataViewPrototype::method_get_byteOffset(const FunctionObject *b, const Value *thisObject, const Value *, int) { - DataView *v = callData->thisObject.as(); + const DataView *v = thisObject->as(); if (!v) return b->engine()->throwTypeError(); @@ -147,12 +147,12 @@ ReturnedValue DataViewPrototype::method_get_byteOffset(const BuiltinFunction *b, } template -ReturnedValue DataViewPrototype::method_getChar(const BuiltinFunction *b, CallData *callData) +ReturnedValue DataViewPrototype::method_getChar(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { - DataView *v = callData->thisObject.as(); - if (!v || callData->argc() < 1) + const DataView *v = thisObject->as(); + if (!v || argc < 1) return b->engine()->throwTypeError(); - double l = callData->args[0].toNumber(); + double l = argv[0].toNumber(); uint idx = (uint)l; if (l != idx || idx + sizeof(T) > v->d()->byteLength) return b->engine()->throwTypeError(); @@ -164,18 +164,18 @@ ReturnedValue DataViewPrototype::method_getChar(const BuiltinFunction *b, CallDa } template -ReturnedValue DataViewPrototype::method_get(const BuiltinFunction *b, CallData *callData) +ReturnedValue DataViewPrototype::method_get(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { - DataView *v = callData->thisObject.as(); - if (!v || callData->argc() < 1) + const DataView *v = thisObject->as(); + if (!v || argc < 1) return b->engine()->throwTypeError(); - double l = callData->args[0].toNumber(); + double l = argv[0].toNumber(); uint idx = (uint)l; if (l != idx || idx + sizeof(T) > v->d()->byteLength) return b->engine()->throwTypeError(); idx += v->d()->byteOffset; - bool littleEndian = callData->argc() < 2 ? false : callData->args[1].toBoolean(); + bool littleEndian = argc < 2 ? false : argv[1].toBoolean(); T t = littleEndian ? qFromLittleEndian((uchar *)v->d()->buffer->data->data() + idx) @@ -185,18 +185,18 @@ ReturnedValue DataViewPrototype::method_get(const BuiltinFunction *b, CallData * } template -ReturnedValue DataViewPrototype::method_getFloat(const BuiltinFunction *b, CallData *callData) +ReturnedValue DataViewPrototype::method_getFloat(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { - DataView *v = callData->thisObject.as(); - if (!v || callData->argc() < 1) + const DataView *v = thisObject->as(); + if (!v || argc < 1) return b->engine()->throwTypeError(); - double l = callData->args[0].toNumber(); + double l = argv[0].toNumber(); uint idx = (uint)l; if (l != idx || idx + sizeof(T) > v->d()->byteLength) return b->engine()->throwTypeError(); idx += v->d()->byteOffset; - bool littleEndian = callData->argc() < 2 ? false : callData->args[1].toBoolean(); + bool littleEndian = argc < 2 ? false : argv[1].toBoolean(); if (sizeof(T) == 4) { // float @@ -222,38 +222,38 @@ ReturnedValue DataViewPrototype::method_getFloat(const BuiltinFunction *b, CallD } template -ReturnedValue DataViewPrototype::method_setChar(const BuiltinFunction *b, CallData *callData) +ReturnedValue DataViewPrototype::method_setChar(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { - DataView *v = callData->thisObject.as(); - if (!v || callData->argc() < 1) + const DataView *v = thisObject->as(); + if (!v || argc < 1) return b->engine()->throwTypeError(); - double l = callData->args[0].toNumber(); + double l = argv[0].toNumber(); uint idx = (uint)l; if (l != idx || idx + sizeof(T) > v->d()->byteLength) return b->engine()->throwTypeError(); idx += v->d()->byteOffset; - int val = callData->argc() >= 2 ? callData->args[1].toInt32() : 0; + int val = argc >= 2 ? argv[1].toInt32() : 0; v->d()->buffer->data->data()[idx] = (char)val; RETURN_UNDEFINED(); } template -ReturnedValue DataViewPrototype::method_set(const BuiltinFunction *b, CallData *callData) +ReturnedValue DataViewPrototype::method_set(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { - DataView *v = callData->thisObject.as(); - if (!v || callData->argc() < 1) + const DataView *v = thisObject->as(); + if (!v || argc < 1) return b->engine()->throwTypeError(); - double l = callData->args[0].toNumber(); + double l = argv[0].toNumber(); uint idx = (uint)l; if (l != idx || idx + sizeof(T) > v->d()->byteLength) return b->engine()->throwTypeError(); idx += v->d()->byteOffset; - int val = callData->argc() >= 2 ? callData->args[1].toInt32() : 0; + int val = argc >= 2 ? argv[1].toInt32() : 0; - bool littleEndian = callData->argc() < 3 ? false : callData->args[2].toBoolean(); + bool littleEndian = argc < 3 ? false : argv[2].toBoolean(); if (littleEndian) qToLittleEndian(val, (uchar *)v->d()->buffer->data->data() + idx); @@ -264,19 +264,19 @@ ReturnedValue DataViewPrototype::method_set(const BuiltinFunction *b, CallData * } template -ReturnedValue DataViewPrototype::method_setFloat(const BuiltinFunction *b, CallData *callData) +ReturnedValue DataViewPrototype::method_setFloat(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { - DataView *v = callData->thisObject.as(); - if (!v || callData->argc() < 1) + const DataView *v = thisObject->as(); + if (!v || argc < 1) return b->engine()->throwTypeError(); - double l = callData->args[0].toNumber(); + double l = argv[0].toNumber(); uint idx = (uint)l; if (l != idx || idx + sizeof(T) > v->d()->byteLength) return b->engine()->throwTypeError(); idx += v->d()->byteOffset; - double val = callData->argc() >= 2 ? callData->args[1].toNumber() : qt_qnan(); - bool littleEndian = callData->argc() < 3 ? false : callData->args[2].toBoolean(); + double val = argc >= 2 ? argv[1].toNumber() : qt_qnan(); + bool littleEndian = argc < 3 ? false : argv[2].toBoolean(); if (sizeof(T) == 4) { // float diff --git a/src/qml/jsruntime/qv4dataview_p.h b/src/qml/jsruntime/qv4dataview_p.h index 30fc7e993b..c921a0ca45 100644 --- a/src/qml/jsruntime/qv4dataview_p.h +++ b/src/qml/jsruntime/qv4dataview_p.h @@ -93,21 +93,21 @@ struct DataViewPrototype: Object { void init(ExecutionEngine *engine, Object *ctor); - static ReturnedValue method_get_buffer(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_get_byteLength(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_get_byteOffset(const BuiltinFunction *, CallData *callData); + static ReturnedValue method_get_buffer(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_byteLength(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_byteOffset(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); template - static ReturnedValue method_getChar(const BuiltinFunction *, CallData *callData); + static ReturnedValue method_getChar(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); template - static ReturnedValue method_get(const BuiltinFunction *, CallData *callData); + static ReturnedValue method_get(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); template - static ReturnedValue method_getFloat(const BuiltinFunction *, CallData *callData); + static ReturnedValue method_getFloat(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); template - static ReturnedValue method_setChar(const BuiltinFunction *, CallData *callData); + static ReturnedValue method_setChar(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); template - static ReturnedValue method_set(const BuiltinFunction *, CallData *callData); + static ReturnedValue method_set(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); template - static ReturnedValue method_setFloat(const BuiltinFunction *, CallData *callData); + static ReturnedValue method_setFloat(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); }; diff --git a/src/qml/jsruntime/qv4typedarray.cpp b/src/qml/jsruntime/qv4typedarray.cpp index c1fbec70ea..4ba31f9b6e 100644 --- a/src/qml/jsruntime/qv4typedarray.cpp +++ b/src/qml/jsruntime/qv4typedarray.cpp @@ -409,57 +409,57 @@ void TypedArrayPrototype::init(ExecutionEngine *engine, TypedArrayCtor *ctor) defineDefaultProperty(QStringLiteral("subarray"), method_subarray, 0); } -ReturnedValue TypedArrayPrototype::method_get_buffer(const BuiltinFunction *b, CallData *callData) +ReturnedValue TypedArrayPrototype::method_get_buffer(const FunctionObject *b, const Value *thisObject, const Value *, int) { ExecutionEngine *v4 = b->engine(); - TypedArray *v = callData->thisObject.as(); + const TypedArray *v = thisObject->as(); if (!v) return v4->throwTypeError(); return v->d()->buffer->asReturnedValue(); } -ReturnedValue TypedArrayPrototype::method_get_byteLength(const BuiltinFunction *b, CallData *callData) +ReturnedValue TypedArrayPrototype::method_get_byteLength(const FunctionObject *b, const Value *thisObject, const Value *, int) { ExecutionEngine *v4 = b->engine(); - TypedArray *v = callData->thisObject.as(); + const TypedArray *v = thisObject->as(); if (!v) return v4->throwTypeError(); return Encode(v->d()->byteLength); } -ReturnedValue TypedArrayPrototype::method_get_byteOffset(const BuiltinFunction *b, CallData *callData) +ReturnedValue TypedArrayPrototype::method_get_byteOffset(const FunctionObject *b, const Value *thisObject, const Value *, int) { ExecutionEngine *v4 = b->engine(); - TypedArray *v = callData->thisObject.as(); + const TypedArray *v = thisObject->as(); if (!v) return v4->throwTypeError(); return Encode(v->d()->byteOffset); } -ReturnedValue TypedArrayPrototype::method_get_length(const BuiltinFunction *b, CallData *callData) +ReturnedValue TypedArrayPrototype::method_get_length(const FunctionObject *b, const Value *thisObject, const Value *, int) { ExecutionEngine *v4 = b->engine(); - TypedArray *v = callData->thisObject.as(); + const TypedArray *v = thisObject->as(); if (!v) return v4->throwTypeError(); return Encode(v->d()->byteLength/v->d()->type->bytesPerElement); } -ReturnedValue TypedArrayPrototype::method_set(const BuiltinFunction *b, CallData *callData) +ReturnedValue TypedArrayPrototype::method_set(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { Scope scope(b); - Scoped a(scope, callData->thisObject); + Scoped a(scope, *thisObject); if (!a) return scope.engine->throwTypeError(); Scoped buffer(scope, a->d()->buffer); if (!buffer) scope.engine->throwTypeError(); - double doffset = callData->argc() >= 2 ? callData->args[1].toInteger() : 0; + double doffset = argc >= 2 ? argv[1].toInteger() : 0; if (scope.engine->hasException) RETURN_UNDEFINED(); @@ -468,10 +468,10 @@ ReturnedValue TypedArrayPrototype::method_set(const BuiltinFunction *b, CallData uint offset = (uint)doffset; uint elementSize = a->d()->type->bytesPerElement; - Scoped srcTypedArray(scope, callData->args[0]); + Scoped srcTypedArray(scope, argv[0]); if (!srcTypedArray) { // src is a regular object - ScopedObject o(scope, callData->args[0].toObject(scope.engine)); + ScopedObject o(scope, argv[0].toObject(scope.engine)); if (scope.engine->hasException || !o) return scope.engine->throwTypeError(); @@ -538,10 +538,10 @@ ReturnedValue TypedArrayPrototype::method_set(const BuiltinFunction *b, CallData RETURN_UNDEFINED(); } -ReturnedValue TypedArrayPrototype::method_subarray(const BuiltinFunction *builtin, CallData *callData) +ReturnedValue TypedArrayPrototype::method_subarray(const FunctionObject *builtin, const Value *thisObject, const Value *argv, int argc) { Scope scope(builtin); - Scoped a(scope, callData->thisObject); + Scoped a(scope, *thisObject); if (!a) return scope.engine->throwTypeError(); @@ -551,12 +551,12 @@ ReturnedValue TypedArrayPrototype::method_subarray(const BuiltinFunction *builti return scope.engine->throwTypeError(); int len = a->length(); - double b = callData->argc() > 0 ? callData->args[0].toInteger() : 0; + double b = argc > 0 ? argv[0].toInteger() : 0; if (b < 0) b = len + b; uint begin = (uint)qBound(0., b, (double)len); - double e = callData->argc() < 2 || callData->args[1].isUndefined() ? len : callData->args[1].toInteger(); + double e = argc < 2 || argv[1].isUndefined() ? len : argv[1].toInteger(); if (e < 0) e = len + e; uint end = (uint)qBound(0., e, (double)len); @@ -572,9 +572,9 @@ ReturnedValue TypedArrayPrototype::method_subarray(const BuiltinFunction *builti if (!constructor) return scope.engine->throwTypeError(); - JSCallData jsCallData(scope, 3); - jsCallData->args[0] = buffer; - jsCallData->args[1] = Encode(a->d()->byteOffset + begin*a->d()->type->bytesPerElement); - jsCallData->args[2] = Encode(newLen); - return constructor->callAsConstructor(jsCallData); + Value *arguments = scope.alloc(3); + arguments[0] = buffer; + arguments[1] = Encode(a->d()->byteOffset + begin*a->d()->type->bytesPerElement); + arguments[2] = Encode(newLen); + return constructor->callAsConstructor(arguments, 3); } diff --git a/src/qml/jsruntime/qv4typedarray_p.h b/src/qml/jsruntime/qv4typedarray_p.h index 6fe53e68d5..835858b474 100644 --- a/src/qml/jsruntime/qv4typedarray_p.h +++ b/src/qml/jsruntime/qv4typedarray_p.h @@ -153,13 +153,13 @@ struct TypedArrayPrototype : Object void init(ExecutionEngine *engine, TypedArrayCtor *ctor); - static ReturnedValue method_get_buffer(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_get_byteLength(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_get_byteOffset(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_get_length(const BuiltinFunction *, CallData *callData); + static ReturnedValue method_get_buffer(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_byteLength(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_byteOffset(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_length(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); - static ReturnedValue method_set(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_subarray(const BuiltinFunction *, CallData *callData); + static ReturnedValue method_set(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_subarray(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); }; inline void -- cgit v1.2.3