Add non generic version of Array.prototype.every
authorRoberto Raggi <roberto.raggi@nokia.com>
Mon, 21 May 2012 15:48:39 +0000 (17:48 +0200)
committerRoberto Raggi <roberto.raggi@nokia.com>
Mon, 21 May 2012 15:48:39 +0000 (17:48 +0200)
qv4ecmaobjects.cpp
tests/fun.4.js

index ad1a8ec..b32569d 100644 (file)
@@ -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");
     }
index 0edd104..09b6a39 100644 (file)
@@ -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 }));