| 119 | } |
| 120 | |
| 121 | static Array::Ptr ArrayMap(const Function::Ptr& function) |
| 122 | { |
| 123 | ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); |
| 124 | Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); |
| 125 | REQUIRE_NOT_NULL(self); |
| 126 | REQUIRE_NOT_NULL(function); |
| 127 | |
| 128 | if (vframe->Sandboxed && !function->IsSideEffectFree()) |
| 129 | BOOST_THROW_EXCEPTION(ScriptError("Map function must be side-effect free.")); |
| 130 | |
| 131 | ArrayData result; |
| 132 | |
| 133 | ObjectLock olock(self); |
| 134 | for (const Value& item : self) { |
| 135 | result.push_back(function->Invoke({ item })); |
| 136 | } |
| 137 | |
| 138 | return new Array(std::move(result)); |
| 139 | } |
| 140 | |
| 141 | static Value ArrayReduce(const Function::Ptr& function) |
| 142 | { |
nothing calls this directly
no test coverage detected