static void InvokeAttributeHandlerHelper(const Function::Ptr& callback, const Object::Ptr& object, const Value& cookie) { std::vector<Value> arguments; arguments.push_back(object); callback->Invoke(arguments); }
static bool ArraySortCmp(const Function::Ptr& cmp, const Value& a, const Value& b) { std::vector<Value> args; args.push_back(a); args.push_back(b); return cmp->Invoke(args); }
static inline Value FunctionCall(ScriptFrame& frame, const Value& self, const Function::Ptr& func, const std::vector<Value>& arguments) { ScriptFrame vframe; if (!self.IsEmpty()) vframe.Self = self; return func->Invoke(arguments); }
static Array::Ptr ArrayMap(const Function::Ptr& function) { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); if (vframe->Sandboxed && !function->IsSideEffectFree()) BOOST_THROW_EXCEPTION(ScriptError("Map function must be side-effect free.")); Array::Ptr result = new Array(); ObjectLock olock(self); for (const Value& item : self) { std::vector<Value> args; args.push_back(item); result->Add(function->Invoke(args)); } return result; }
static Value ArrayReduce(const Function::Ptr& function) { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); if (vframe->Sandboxed && !function->IsSideEffectFree()) BOOST_THROW_EXCEPTION(ScriptError("Reduce function must be side-effect free.")); if (self->GetLength() == 0) return Empty; Value result = self->Get(0); ObjectLock olock(self); for (size_t i = 1; i < self->GetLength(); i++) { std::vector<Value> args; args.push_back(result); args.push_back(self->Get(i)); result = function->Invoke(args); } return result; }
static void InvokeAttributeHandlerHelper(const Function::Ptr& callback, const Object::Ptr& object, const Value& cookie) { callback->Invoke({ object }); }