aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/jsruntime/qv4typedarray.cpp57
-rw-r--r--src/qml/jsruntime/qv4typedarray_p.h1
-rw-r--r--tests/auto/qml/ecmascripttests/TestExpectations32
3 files changed, 57 insertions, 33 deletions
diff --git a/src/qml/jsruntime/qv4typedarray.cpp b/src/qml/jsruntime/qv4typedarray.cpp
index 124aa724c6..68ac5645ae 100644
--- a/src/qml/jsruntime/qv4typedarray.cpp
+++ b/src/qml/jsruntime/qv4typedarray.cpp
@@ -625,6 +625,60 @@ ReturnedValue IntrinsicTypedArrayPrototype::method_fill(const FunctionObject *b,
return v.asReturnedValue();
}
+ReturnedValue IntrinsicTypedArrayPrototype::method_filter(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
+{
+ Scope scope(b);
+ Scoped<TypedArray> instance(scope, thisObject);
+ if (!instance || instance->d()->buffer->isDetachedBuffer())
+ return scope.engine->throwTypeError();
+
+ uint len = instance->length();
+
+ if (!argc || !argv->isFunctionObject())
+ THROW_TYPE_ERROR();
+ const FunctionObject *callback = static_cast<const FunctionObject *>(argv);
+
+ ScopedValue selected(scope);
+ ScopedValue that(scope, argc > 1 ? argv[1] : Primitive::undefinedValue());
+ Value *arguments = scope.alloc(3);
+ Value *list = arguments;
+
+ uint to = 0;
+ for (uint k = 0; k < len; ++k) {
+ if (instance->d()->buffer->isDetachedBuffer())
+ return scope.engine->throwTypeError();
+ bool exists;
+ arguments[0] = instance->get(k, &exists);
+ if (!exists)
+ continue;
+
+ arguments[1] = Primitive::fromDouble(k);
+ arguments[2] = instance;
+ selected = callback->call(that, arguments, 3);
+ if (selected->toBoolean()) {
+ ++arguments;
+ scope.alloc(1);
+ ++to;
+ }
+ }
+
+ const FunctionObject *constructor = instance->speciesConstructor(scope, scope.engine->typedArrayCtors + instance->d()->arrayType);
+ if (!constructor)
+ return scope.engine->throwTypeError();
+
+ arguments = scope.alloc(1);
+ arguments[0] = Encode(to);
+ Scoped<TypedArray> a(scope, constructor->callAsConstructor(arguments, 1));
+ if (!a || a->d()->buffer->isDetachedBuffer())
+ return scope.engine->throwTypeError();
+ if (a->length() < to)
+ return scope.engine->throwTypeError();
+
+ for (uint i = 0; i < to; ++i)
+ a->put(i, list[i]);
+
+ return a->asReturnedValue();
+}
ReturnedValue IntrinsicTypedArrayPrototype::method_find(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
{
@@ -1310,7 +1364,7 @@ ReturnedValue IntrinsicTypedArrayCtor::method_of(const FunctionObject *f, const
return scope.engine->throwTypeError();
TypedArray *a = newObj->as<TypedArray>();
Q_ASSERT(a);
- if (a->getLength() < len)
+ if (a->length() < static_cast<uint>(len))
return scope.engine->throwTypeError();
for (int k = 0; k < len; ++k) {
@@ -1339,6 +1393,7 @@ void IntrinsicTypedArrayPrototype::init(ExecutionEngine *engine, IntrinsicTypedA
defineDefaultProperty(QStringLiteral("entries"), method_entries, 0);
defineDefaultProperty(QStringLiteral("every"), method_every, 1);
defineDefaultProperty(QStringLiteral("fill"), method_fill, 1);
+ defineDefaultProperty(QStringLiteral("filter"), method_filter, 1);
defineDefaultProperty(QStringLiteral("find"), method_find, 1);
defineDefaultProperty(QStringLiteral("findIndex"), method_findIndex, 1);
defineDefaultProperty(QStringLiteral("forEach"), method_forEach, 1);
diff --git a/src/qml/jsruntime/qv4typedarray_p.h b/src/qml/jsruntime/qv4typedarray_p.h
index ab640b85de..ddd2193e9f 100644
--- a/src/qml/jsruntime/qv4typedarray_p.h
+++ b/src/qml/jsruntime/qv4typedarray_p.h
@@ -178,6 +178,7 @@ struct IntrinsicTypedArrayPrototype : Object
static ReturnedValue method_entries(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
static ReturnedValue method_every(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
static ReturnedValue method_fill(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
+ static ReturnedValue method_filter(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
static ReturnedValue method_find(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
static ReturnedValue method_findIndex(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
static ReturnedValue method_forEach(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
diff --git a/tests/auto/qml/ecmascripttests/TestExpectations b/tests/auto/qml/ecmascripttests/TestExpectations
index 5cbc1ce3ac..6b54a55b3d 100644
--- a/tests/auto/qml/ecmascripttests/TestExpectations
+++ b/tests/auto/qml/ecmascripttests/TestExpectations
@@ -683,38 +683,6 @@ built-ins/TypedArray/from/name.js fails
built-ins/TypedArray/from/prop-desc.js fails
built-ins/TypedArray/prototype/constructor.js fails
built-ins/TypedArray/prototype/fill/fill-values-conversion-operations-consistent-nan.js fails
-built-ins/TypedArray/prototype/filter/arraylength-internal.js fails
-built-ins/TypedArray/prototype/filter/callbackfn-arguments-with-thisarg.js fails
-built-ins/TypedArray/prototype/filter/callbackfn-arguments-without-thisarg.js fails
-built-ins/TypedArray/prototype/filter/callbackfn-called-before-ctor.js fails
-built-ins/TypedArray/prototype/filter/callbackfn-called-before-species.js fails
-built-ins/TypedArray/prototype/filter/callbackfn-detachbuffer.js fails
-built-ins/TypedArray/prototype/filter/callbackfn-no-iteration-over-non-integer.js fails
-built-ins/TypedArray/prototype/filter/callbackfn-not-called-on-empty.js fails
-built-ins/TypedArray/prototype/filter/callbackfn-return-does-not-change-instance.js fails
-built-ins/TypedArray/prototype/filter/callbackfn-returns-abrupt.js fails
-built-ins/TypedArray/prototype/filter/callbackfn-set-value-during-iteration.js fails
-built-ins/TypedArray/prototype/filter/callbackfn-this.js fails
-built-ins/TypedArray/prototype/filter/invoked-as-func.js fails
-built-ins/TypedArray/prototype/filter/invoked-as-method.js fails
-built-ins/TypedArray/prototype/filter/length.js fails
-built-ins/TypedArray/prototype/filter/name.js fails
-built-ins/TypedArray/prototype/filter/prop-desc.js fails
-built-ins/TypedArray/prototype/filter/result-does-not-share-buffer.js fails
-built-ins/TypedArray/prototype/filter/result-empty-callbackfn-returns-false.js fails
-built-ins/TypedArray/prototype/filter/result-full-callbackfn-returns-true.js fails
-built-ins/TypedArray/prototype/filter/speciesctor-get-ctor-abrupt.js fails
-built-ins/TypedArray/prototype/filter/speciesctor-get-ctor-inherited.js fails
-built-ins/TypedArray/prototype/filter/speciesctor-get-ctor.js fails
-built-ins/TypedArray/prototype/filter/speciesctor-get-species-abrupt.js fails
-built-ins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-invocation.js fails
-built-ins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-length.js fails
-built-ins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-returns-another-instance.js fails
-built-ins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor.js fails
-built-ins/TypedArray/prototype/filter/speciesctor-get-species-use-default-ctor.js fails
-built-ins/TypedArray/prototype/filter/speciesctor-get-species.js fails
-built-ins/TypedArray/prototype/filter/values-are-not-cached.js fails
-built-ins/TypedArray/prototype/filter/values-are-set.js fails
built-ins/TypedArray/prototype/map/arraylength-internal.js fails
built-ins/TypedArray/prototype/map/callbackfn-arguments-with-thisarg.js fails
built-ins/TypedArray/prototype/map/callbackfn-arguments-without-thisarg.js fails