本文整理汇总了C++中function::Ptr::IsSideEffectFree方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::IsSideEffectFree方法的具体用法?C++ Ptr::IsSideEffectFree怎么用?C++ Ptr::IsSideEffectFree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类function::Ptr
的用法示例。
在下文中一共展示了Ptr::IsSideEffectFree方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DoEvaluate
ExpressionResult FunctionCallExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
{
Value self, vfunc;
String index;
if (m_FName->GetReference(frame, false, &self, &index))
vfunc = VMOps::GetField(self, index, frame.Sandboxed, m_DebugInfo);
else {
ExpressionResult vfuncres = m_FName->Evaluate(frame);
CHECK_RESULT(vfuncres);
vfunc = vfuncres.GetValue();
}
if (vfunc.IsObjectType<Type>()) {
std::vector<Value> arguments;
for (Expression *arg : m_Args) {
ExpressionResult argres = arg->Evaluate(frame);
CHECK_RESULT(argres);
arguments.push_back(argres.GetValue());
}
return VMOps::ConstructorCall(vfunc, arguments, m_DebugInfo);
}
if (!vfunc.IsObjectType<Function>())
BOOST_THROW_EXCEPTION(ScriptError("Argument is not a callable object.", m_DebugInfo));
Function::Ptr func = vfunc;
if (!func->IsSideEffectFree() && frame.Sandboxed)
BOOST_THROW_EXCEPTION(ScriptError("Function is not marked as safe for sandbox mode.", m_DebugInfo));
std::vector<Value> arguments;
for (Expression *arg : m_Args) {
ExpressionResult argres = arg->Evaluate(frame);
CHECK_RESULT(argres);
arguments.push_back(argres.GetValue());
}
return VMOps::FunctionCall(frame, self, func, arguments);
}
示例2: olock
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;
}
示例3: ArrayReduce
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;
}