| 1055 | } |
| 1056 | |
| 1057 | static bool array_every(JSContext *cx, unsigned argc, JS::Value *vp) { |
| 1058 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
| 1059 | |
| 1060 | if (!args.requireAtLeast(cx, "every", 1)) { |
| 1061 | return false; |
| 1062 | } |
| 1063 | |
| 1064 | JS::RootedObject proxy(cx, JS::ToObject(cx, args.thisv())); |
| 1065 | if (!proxy) { |
| 1066 | return false; |
| 1067 | } |
| 1068 | PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot); |
| 1069 | |
| 1070 | JS::Value callbackfn = args[0].get(); |
| 1071 | |
| 1072 | if (!callbackfn.isObject() || !JS::IsCallable(&callbackfn.toObject())) { |
| 1073 | JS_ReportErrorNumberASCII(cx, js::GetErrorMessage, nullptr, JSMSG_NOT_FUNCTION, "every: callback"); |
| 1074 | return false; |
| 1075 | } |
| 1076 | |
| 1077 | JS::RootedValue selfValue(cx, jsTypeFactory(cx, self)); |
| 1078 | JS::RootedValue callBack(cx, callbackfn); |
| 1079 | |
| 1080 | JS::Rooted<JS::ValueArray<3>> jArgs(cx); |
| 1081 | JS::RootedValue rval(cx); |
| 1082 | |
| 1083 | JS::RootedObject rootedThisArg(cx); |
| 1084 | if (args.length() > 1) { |
| 1085 | JS::Value thisArg = args[1].get(); |
| 1086 | if (!thisArg.isObjectOrNull()) { |
| 1087 | JS_ReportErrorNumberASCII(cx, js::GetErrorMessage, nullptr, JSMSG_NOT_OBJORNULL, "'this' argument"); |
| 1088 | return false; |
| 1089 | } |
| 1090 | |
| 1091 | // TODO support null, currently gets TypeError |
| 1092 | rootedThisArg.set(thisArg.toObjectOrNull()); |
| 1093 | // check if callback is a PyMethod, need to make a new method bound to thisArg |
| 1094 | if (!makeNewPyMethod(cx, &callBack, rootedThisArg)) { |
| 1095 | return false; |
| 1096 | } |
| 1097 | } |
| 1098 | else { |
| 1099 | rootedThisArg.set(nullptr); |
| 1100 | } |
| 1101 | |
| 1102 | Py_ssize_t len = PyList_GET_SIZE(self); |
| 1103 | for (Py_ssize_t index = 0, toIndex = 0; index < len; index++) { |
| 1104 | jArgs[0].set(jsTypeFactory(cx, PyList_GetItem(self, index))); |
| 1105 | jArgs[1].setInt32(index); |
| 1106 | jArgs[2].set(selfValue); |
| 1107 | |
| 1108 | if (!JS_CallFunctionValue(cx, rootedThisArg, callBack, jArgs, &rval)) { |
| 1109 | return false; |
| 1110 | } |
| 1111 | |
| 1112 | if (!rval.toBoolean()) { |
| 1113 | args.rval().setBoolean(false); |
| 1114 | return true; |
nothing calls this directly
no test coverage detected