diff options
-rw-r--r-- | src/qml/jsruntime/qv4typedarray.cpp | 38 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4typedarray_p.h | 2 | ||||
-rw-r--r-- | tests/auto/qml/ecmascripttests/TestExpectations | 11 |
3 files changed, 40 insertions, 11 deletions
diff --git a/src/qml/jsruntime/qv4typedarray.cpp b/src/qml/jsruntime/qv4typedarray.cpp index e064efd486..21b90ad851 100644 --- a/src/qml/jsruntime/qv4typedarray.cpp +++ b/src/qml/jsruntime/qv4typedarray.cpp @@ -660,6 +660,42 @@ ReturnedValue IntrinsicTypedArrayCtor::virtualCall(const FunctionObject *f, cons return f->engine()->throwTypeError(); } +static bool validateTypedArray(const Object *o) +{ + const TypedArray *a = o->as<TypedArray>(); + if (!a) + return false; + if (a->d()->buffer->isDetachedBuffer()) + return false; + return true; +} + +ReturnedValue IntrinsicTypedArrayCtor::method_of(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc) +{ + Scope scope(f); + int len = argc; + const Value *items = argv; + const FunctionObject *C = thisObject->as<FunctionObject>(); + if (!C) + return scope.engine->throwTypeError(); + + Value lenValue = Primitive::fromInt32(len); + ScopedObject newObj(scope, C->callAsConstructor(&lenValue, 1)); + if (scope.hasException()) + return Encode::undefined(); + if (!::validateTypedArray(newObj)) + return scope.engine->throwTypeError(); + TypedArray *a = newObj->as<TypedArray>(); + Q_ASSERT(a); + if (a->getLength() < len) + return scope.engine->throwTypeError(); + + for (int k = 0; k < len; ++k) { + newObj->put(PropertyKey::fromArrayIndex(k), items[k]); + } + return newObj->asReturnedValue(); +} + void IntrinsicTypedArrayPrototype::init(ExecutionEngine *engine, IntrinsicTypedArrayCtor *ctor) { Scope scope(engine); @@ -667,6 +703,8 @@ void IntrinsicTypedArrayPrototype::init(ExecutionEngine *engine, IntrinsicTypedA ctor->defineReadonlyConfigurableProperty(engine->id_length(), Primitive::fromInt32(0)); ScopedString s(scope, engine->newString(QStringLiteral("TypedArray"))); ctor->defineReadonlyConfigurableProperty(engine->id_name(), s); + s = scope.engine->newString(QStringLiteral("of")); + ctor->defineDefaultProperty(s, IntrinsicTypedArrayCtor::method_of); ctor->addSymbolSpecies(); defineAccessorProperty(QStringLiteral("buffer"), method_get_buffer, nullptr); diff --git a/src/qml/jsruntime/qv4typedarray_p.h b/src/qml/jsruntime/qv4typedarray_p.h index 967d3235b2..06292b7f8d 100644 --- a/src/qml/jsruntime/qv4typedarray_p.h +++ b/src/qml/jsruntime/qv4typedarray_p.h @@ -150,6 +150,8 @@ struct IntrinsicTypedArrayCtor: FunctionObject static ReturnedValue virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *); static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc); + + static ReturnedValue method_of(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); }; struct TypedArrayCtor: FunctionObject diff --git a/tests/auto/qml/ecmascripttests/TestExpectations b/tests/auto/qml/ecmascripttests/TestExpectations index 0fc97ca033..3d0d2647f9 100644 --- a/tests/auto/qml/ecmascripttests/TestExpectations +++ b/tests/auto/qml/ecmascripttests/TestExpectations @@ -683,9 +683,6 @@ built-ins/TypedArray/from/iter-next-value-error.js fails built-ins/TypedArray/from/length.js fails built-ins/TypedArray/from/name.js fails built-ins/TypedArray/from/prop-desc.js fails -built-ins/TypedArray/of/length.js fails -built-ins/TypedArray/of/name.js fails -built-ins/TypedArray/of/prop-desc.js fails built-ins/TypedArray/prototype/byteLength/detached-buffer.js fails built-ins/TypedArray/prototype/byteOffset/detached-buffer.js fails built-ins/TypedArray/prototype/constructor.js fails @@ -1146,14 +1143,6 @@ built-ins/TypedArrays/internals/Set/key-is-not-integer.js fails built-ins/TypedArrays/internals/Set/key-is-out-of-bounds.js fails built-ins/TypedArrays/internals/Set/tonumber-value-detached-buffer.js fails built-ins/TypedArrays/internals/Set/tonumber-value-throws.js strictFails -built-ins/TypedArrays/of/argument-number-value-throws.js fails -built-ins/TypedArrays/of/custom-ctor-returns-other-instance.js fails -built-ins/TypedArrays/of/custom-ctor.js fails -built-ins/TypedArrays/of/nan-conversion.js fails -built-ins/TypedArrays/of/new-instance-empty.js fails -built-ins/TypedArrays/of/new-instance-from-zero.js fails -built-ins/TypedArrays/of/new-instance-using-custom-ctor.js fails -built-ins/TypedArrays/of/new-instance.js fails built-ins/WeakMap/constructor.js fails built-ins/WeakMap/empty-iterable.js fails built-ins/WeakMap/get-set-method-failure.js fails |