var HiseJavascriptEngine::RootObject::FunctionCall::invokeFunction(const Scope& s, const var& function, const var& thisObject) const { s.checkTimeOut(location); var argVars[16]; const int thisNumArgs = jmin<int>(16, arguments.size()); for (int i = 0; i < thisNumArgs; i++) { argVars[i] = arguments.getUnchecked(i)->getResult(s); } const var::NativeFunctionArgs args(thisObject, argVars, thisNumArgs); if (var::NativeFunction nativeFunction = function.getNativeFunction()) return nativeFunction(args); if (FunctionObject* fo = dynamic_cast<FunctionObject*> (function.getObject())) return fo->invoke(s, args); if (DotOperator* dot = dynamic_cast<DotOperator*> (object.get())) if (DynamicObject* o = thisObject.getDynamicObject()) if (o->hasMethod(dot->child)) // allow an overridden DynamicObject::invokeMethod to accept a method call. return o->invokeMethod(dot->child, args); location.throwError("This expression is not a function!"); return var(); }
const var var::invoke (const var& targetObject, const var* arguments, int numArguments) const { if (isMethod()) { DynamicObject* const target = targetObject.getObject(); if (target != 0) return (target->*(value.methodValue)) (arguments, numArguments); } return var::null; }
bool HiseJavascriptEngine::RootObject::isFunction(const var& v) noexcept { return dynamic_cast<FunctionObject*> (v.getObject()) != nullptr; }