From 730302a642abc0224184d8f04672238152800299 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 21 May 2012 17:48:39 +0200 Subject: [PATCH] Add non generic version of Array.prototype.every --- qv4ecmaobjects.cpp | 18 +++++++++++++++++- tests/fun.4.js | 4 +++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/qv4ecmaobjects.cpp b/qv4ecmaobjects.cpp index ad1a8ec..b32569d 100644 --- a/qv4ecmaobjects.cpp +++ b/qv4ecmaobjects.cpp @@ -1405,7 +1405,23 @@ void ArrayPrototype::method_every(Context *ctx) { Value self = ctx->thisObject; if (ArrayObject *instance = self.asArrayObject()) { - Q_UNIMPLEMENTED(); + Value callback = ctx->argument(0); + if (callback.isFunctionObject()) { + Value thisArg = ctx->argument(1); + bool ok = true; + for (uint k = 0; ok && k < instance->value.size(); ++k) { + Value args[3]; + args[0] = instance->value.at(k); + args[1] = Value::fromNumber(k); + args[2] = ctx->thisObject; + Value r; + __qmljs_call_value(ctx, &r, &thisArg, &callback, args, 3); + ok = __qmljs_to_boolean(ctx, &r); + } + ctx->result = Value::fromBoolean(ok); + } else { + assert(!"type error"); + } } else { assert(!"generic implementation"); } diff --git a/tests/fun.4.js b/tests/fun.4.js index 0edd104..09b6a39 100644 --- a/tests/fun.4.js +++ b/tests/fun.4.js @@ -5,7 +5,9 @@ function foo(a,b,c) { foo.call(null, 1,2,3); -[10,20,30].forEach(function (v,k,o) { print(v,k,o); }) +[10,20,30].forEach(function (v,k,o) { print(v,k,o); }); + +print([10, 20, 30].every(function (v,k,o) { return v > 9 })); -- 2.7.4