| 139 | } |
| 140 | |
| 141 | static Value ArrayReduce(const Function::Ptr& function) |
| 142 | { |
| 143 | ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); |
| 144 | Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); |
| 145 | REQUIRE_NOT_NULL(self); |
| 146 | REQUIRE_NOT_NULL(function); |
| 147 | |
| 148 | if (vframe->Sandboxed && !function->IsSideEffectFree()) |
| 149 | BOOST_THROW_EXCEPTION(ScriptError("Reduce function must be side-effect free.")); |
| 150 | |
| 151 | if (self->GetLength() == 0) |
| 152 | return Empty; |
| 153 | |
| 154 | Value result = self->Get(0); |
| 155 | |
| 156 | ObjectLock olock(self); |
| 157 | for (size_t i = 1; i < self->GetLength(); i++) { |
| 158 | result = function->Invoke({ result, self->Get(i) }); |
| 159 | } |
| 160 | |
| 161 | return result; |
| 162 | } |
| 163 | |
| 164 | static Array::Ptr ArrayFilter(const Function::Ptr& function) |
| 165 | { |
nothing calls this directly
no test coverage detected