| 162 | } |
| 163 | |
| 164 | static Array::Ptr ArrayFilter(const Function::Ptr& function) |
| 165 | { |
| 166 | ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); |
| 167 | Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); |
| 168 | REQUIRE_NOT_NULL(self); |
| 169 | REQUIRE_NOT_NULL(function); |
| 170 | |
| 171 | if (vframe->Sandboxed && !function->IsSideEffectFree()) |
| 172 | BOOST_THROW_EXCEPTION(ScriptError("Filter function must be side-effect free.")); |
| 173 | |
| 174 | ArrayData result; |
| 175 | |
| 176 | ObjectLock olock(self); |
| 177 | for (const Value& item : self) { |
| 178 | if (function->Invoke({ item })) |
| 179 | result.push_back(item); |
| 180 | } |
| 181 | |
| 182 | return new Array(std::move(result)); |
| 183 | } |
| 184 | |
| 185 | static bool ArrayAny(const Function::Ptr& function) |
| 186 | { |
nothing calls this directly
no test coverage detected