本文整理汇总了C++中VJSParms_callStaticFunction::SetException方法的典型用法代码示例。如果您正苦于以下问题:C++ VJSParms_callStaticFunction::SetException方法的具体用法?C++ VJSParms_callStaticFunction::SetException怎么用?C++ VJSParms_callStaticFunction::SetException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VJSParms_callStaticFunction
的用法示例。
在下文中一共展示了VJSParms_callStaticFunction::SetException方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _evaluate
void VJSRequireClass::_evaluate (VJSParms_callStaticFunction &ioParms, void *)
{
XBOX::VJSContext context(ioParms.GetContext());
XBOX::VString fullPath;
XBOX::VJSObject exportsObject(context), moduleObject(context);
if (!ioParms.GetStringParam(1, fullPath)) {
XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "1");
return;
}
if (!ioParms.GetParamObject(2, exportsObject)) {
XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_OBJECT, "2");
return;
}
if (!ioParms.GetParamObject(3, moduleObject)) {
XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_OBJECT, "3");
return;
}
XBOX::VError error;
XBOX::VURL url;
XBOX::VString script;
if ((error = VJSModuleState::LoadScript(fullPath, &url, &script)) != XBOX::VE_OK) {
if (error == XBOX::VE_JVSC_SCRIPT_NOT_FOUND) {
// Should not happen as require() does already check for existence.
XBOX::vThrowError(XBOX::VE_JVSC_SCRIPT_NOT_FOUND, fullPath);
} else
XBOX::vThrowError(error);
} else {
XBOX::VFilePath path(fullPath, FPS_POSIX);
XBOX::VFile *file;
if ((file = new XBOX::VFile(path)) == NULL) {
XBOX::vThrowError(XBOX::VE_MEMORY_FULL);
} else {
context.GetGlobalObjectPrivateInstance()->RegisterIncludedFile(file);
XBOX::VString functionScript;
XBOX::VJSValue functionResult(context);
XBOX::JS4D::ExceptionRef exception;
// Make a function of the module script, then call it.
functionScript.AppendString("(function (exports, module) {");
functionScript.AppendString(script);
functionScript.AppendString("})");
if (!context.EvaluateScript(functionScript, &url, &functionResult, &exception)) {
ioParms.SetException(exception); // Syntax error.
} else {
xbox_assert(functionResult.IsFunction());
XBOX::VJSObject functionObject(context);
std::vector<XBOX::VJSValue> arguments;
XBOX::VJSValue result(context);
functionObject.SetObjectRef((XBOX::JS4D::ObjectRef) functionResult.GetValueRef());
arguments.push_back(exportsObject);
arguments.push_back(moduleObject);
if (!context.GetGlobalObject().CallFunction(functionObject, &arguments, &result, &exception, &path))
ioParms.SetException(exception);
else
ioParms.ReturnValue(result);
}
XBOX::ReleaseRefCountable<XBOX::VFile>(&file);
}
}
}