本文整理汇总了C++中rq函数的典型用法代码示例。如果您正苦于以下问题:C++ rq函数的具体用法?C++ rq怎么用?C++ rq使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rq函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetScriptInterface
void CSimulation2::LoadPlayerSettings(bool newPlayers)
{
JSContext* cx = GetScriptInterface().GetContext();
JSAutoRequest rq(cx);
JS::RootedValue global(cx, GetScriptInterface().GetGlobalObject());
GetScriptInterface().CallFunctionVoid(global, "LoadPlayerSettings", m->m_MapSettings, newPlayers);
}
示例2: rq
void CComponentTypeScript::Deserialize(const CParamNode& paramNode, IDeserializer& deserialize, entity_id_t ent)
{
JSContext* cx = m_ScriptInterface.GetContext();
JSAutoRequest rq(cx);
m_ScriptInterface.SetProperty(m_Instance, "entity", (int)ent, true, false);
m_ScriptInterface.SetProperty(m_Instance, "template", paramNode, true, false);
// Support a custom "Deserialize" function, to which we pass the deserialized data
// instead of automatically adding the deserialized properties onto the object
if (m_HasCustomDeserialize)
{
JS::RootedValue val(cx);
// If Serialize = null, we'll still call Deserialize but with undefined argument
if (!m_HasNullSerialize)
deserialize.ScriptVal("object", &val);
if (!m_ScriptInterface.CallFunctionVoid(m_Instance, "Deserialize", val))
LOGERROR("Script Deserialize call failed");
}
else
{
if (!m_HasNullSerialize)
{
// Use ScriptObjectAppend so we don't lose the carefully-constructed
// prototype/parent of this object
deserialize.ScriptObjectAppend("object", m_Instance);
}
}
}
示例3: rq
void CBinarySerializerScriptImpl::ScriptString(const char* name, JS::HandleString string)
{
JSContext* cx = m_ScriptInterface.GetContext();
JSAutoRequest rq(cx);
#if BYTE_ORDER != LITTLE_ENDIAN
#error TODO: probably need to convert JS strings to little-endian
#endif
size_t length;
JS::AutoCheckCannotGC nogc;
// Serialize strings directly as UTF-16 or Latin1, to avoid expensive encoding conversions
bool isLatin1 = JS_StringHasLatin1Chars(string);
m_Serializer.Bool("isLatin1", isLatin1);
if (isLatin1)
{
const JS::Latin1Char* chars = JS_GetLatin1StringCharsAndLength(cx, nogc, string, &length);
if (!chars)
throw PSERROR_Serialize_ScriptError("JS_GetLatin1StringCharsAndLength failed");
m_Serializer.NumberU32_Unbounded("string length", (u32)length);
m_Serializer.RawBytes(name, (const u8*)chars, length);
}
else
{
const char16_t* chars = JS_GetTwoByteStringCharsAndLength(cx, nogc, string, &length);
if (!chars)
throw PSERROR_Serialize_ScriptError("JS_GetTwoByteStringCharsAndLength failed");
m_Serializer.NumberU32_Unbounded("string length", (u32)length);
m_Serializer.RawBytes(name, (const u8*)chars, length*2);
}
}
示例4: rq
void CStdDeserializer::ScriptString(const char* name, JS::MutableHandleString out)
{
#if BYTE_ORDER != LITTLE_ENDIAN
#error TODO: probably need to convert JS strings from little-endian
#endif
JSContext* cx = m_ScriptInterface.GetContext();
JSAutoRequest rq(cx);
bool isLatin1;
Bool("isLatin1", isLatin1);
if (isLatin1)
{
std::vector<JS::Latin1Char> str;
ReadStringLatin1(name, str);
out.set(JS_NewStringCopyN(cx, (const char*)str.data(), str.size()));
if (!out)
throw PSERROR_Deserialize_ScriptError("JS_NewStringCopyN failed");
}
else
{
utf16string str;
ReadStringUTF16(name, str);
out.set(JS_NewUCStringCopyN(cx, (const char16_t*)str.data(), str.length()));
if (!out)
throw PSERROR_Deserialize_ScriptError("JS_NewUCStringCopyN failed");
}
}
示例5: LOGD
void CBackupDeleter::run()
{
if (! _ctx._options->_removeNonExistingFiles )
return;
LOGD("{} START", __PRETTY_FUNCTION__);
const CAsset * pRoot( _parser.getRoot() );
assert( pRoot );
CRequest rq(_ctx._options->_curlVerbose);
for (const auto & p : _remote.paths())
{
const CAsset * pLocal = pRoot->find(p);
if (pLocal == nullptr)
{
rq.addHeader("X-Auth-Token", _ctx._cr.token());
const std::string url= fmt::format("{}/{}/{}", _ctx._cr.endpoint(), _ctx._options->_dstContainer, (_ctx._options->_dstFolder / rq.escapePath(p)).string() );
LOGI("deleting backup '{}'", url); //p.string());
rq.del(url);
if ( rq.getHttpResponseCode() != 204 )
{
LOGE("Failed to delete '{}' [http response : {}]", url, rq.getHttpResponseCode());
_ctx.abort();
}
}
if (_ctx.aborted())
break;
}
LOGD("{} DONE", __PRETTY_FUNCTION__);
}
示例6: PushLocalCommand
virtual void PushLocalCommand(player_id_t player, JS::HandleValue cmd)
{
JSContext* cx = GetSimContext().GetScriptInterface().GetContext();
JSAutoRequest rq(cx);
m_LocalQueue.emplace_back(SimulationCommand(player, cx, cmd));
}
示例7: ENSURE
bool CNetClient::OnGameStart(void* context, CFsmEvent* event)
{
ENSURE(event->GetType() == (uint)NMT_GAME_START);
CNetClient* client = (CNetClient*)context;
JSContext* cx = client->GetScriptInterface().GetContext();
JSAutoRequest rq(cx);
// Find the player assigned to our GUID
int player = -1;
if (client->m_PlayerAssignments.find(client->m_GUID) != client->m_PlayerAssignments.end())
player = client->m_PlayerAssignments[client->m_GUID].m_PlayerID;
client->m_ClientTurnManager = new CNetClientTurnManager(
*client->m_Game->GetSimulation2(), *client, client->m_HostID, client->m_Game->GetReplayLogger());
client->m_Game->SetPlayerID(player);
client->m_Game->StartGame(&client->m_GameAttributes, "");
JS::RootedValue msg(cx);
client->GetScriptInterface().Eval("({'type':'start'})", &msg);
client->PushGuiMessage(msg);
return true;
}
示例8: rq
template<> bool ScriptInterface::FromJSVal<bool>(JSContext* cx, JS::HandleValue v, bool& out)
{
JSAutoRequest rq(cx);
WARN_IF_NOT(v.isBoolean(), v);
out = JS::ToBoolean(v);
return true;
}
示例9: assert_kdb
bool
Sched_context::deblock(unsigned cpu, Sched_context *crs, bool lazy_q = false)
{
assert_kdb(cpu_lock.test());
Sched_context *cs = rq(cpu).current_sched();
bool res = true;
if (this == cs)
{
if (crs->dominates(this))
res = false;
}
else
{
deblock_refill(cpu);
if ((EXPECT_TRUE(cs != 0) && cs->dominates(this)) || crs->dominates(this))
res = false;
}
if (res && lazy_q)
return true;
ready_enqueue(cpu);
return res;
}
示例10: rq
bool ScriptInterface::ParseJSON(const std::string& string_utf8, JS::MutableHandleValue out)
{
JSAutoRequest rq(m->m_cx);
std::wstring attrsW = wstring_from_utf8(string_utf8);
utf16string string(attrsW.begin(), attrsW.end());
if (JS_ParseJSON(m->m_cx, reinterpret_cast<const jschar*>(string.c_str()), (u32)string.size(), out))
return true;
LOGERROR("JS_ParseJSON failed!");
if (!JS_IsExceptionPending(m->m_cx))
return false;
JS::RootedValue exc(m->m_cx);
if (!JS_GetPendingException(m->m_cx, &exc))
return false;
JS_ClearPendingException(m->m_cx);
// We expect an object of type SyntaxError
if (!exc.isObject())
return false;
JS::RootedValue rval(m->m_cx);
JS::RootedObject excObj(m->m_cx, &exc.toObject());
if (!JS_CallFunctionName(m->m_cx, excObj, "toString", JS::HandleValueArray::empty(), &rval))
return false;
std::wstring error;
ScriptInterface::FromJSVal(m->m_cx, rval, error);
LOGERROR("%s", utf8_from_wstring(error));
return false;
}
示例11: m_runtime
ScriptInterface_impl::ScriptInterface_impl(const char* nativeScopeName, const shared_ptr<ScriptRuntime>& runtime) :
m_runtime(runtime), m_glob(runtime->m_rt), m_nativeScope(runtime->m_rt)
{
bool ok;
m_cx = JS_NewContext(m_runtime->m_rt, STACK_CHUNK_SIZE);
ENSURE(m_cx);
JS_SetParallelIonCompilationEnabled(m_runtime->m_rt, true);
// For GC debugging:
// JS_SetGCZeal(m_cx, 2);
JS_SetContextPrivate(m_cx, NULL);
JS_SetErrorReporter(m_cx, ErrorReporter);
JS_SetGlobalJitCompilerOption(m_runtime->m_rt, JSJITCOMPILER_ION_ENABLE, 1);
JS_SetGlobalJitCompilerOption(m_runtime->m_rt, JSJITCOMPILER_BASELINE_ENABLE, 1);
JS::ContextOptionsRef(m_cx).setExtraWarnings(1)
.setWerror(0)
.setVarObjFix(1)
.setStrictMode(1);
JS::CompartmentOptions opt;
opt.setVersion(JSVERSION_LATEST);
JSAutoRequest rq(m_cx);
JS::RootedObject globalRootedVal(m_cx, JS_NewGlobalObject(m_cx, &global_class, NULL, JS::OnNewGlobalHookOption::FireOnNewGlobalHook, opt));
m_comp = JS_EnterCompartment(m_cx, globalRootedVal);
ok = JS_InitStandardClasses(m_cx, globalRootedVal);
ENSURE(ok);
m_glob = globalRootedVal.get();
// Use the testing functions to globally enable gcPreserveCode. This brings quite a
// big performance improvement. In future SpiderMonkey versions, we should probably
// use the functions implemented here: https://bugzilla.mozilla.org/show_bug.cgi?id=1068697
JS::RootedObject testingFunctionsObj(m_cx, js::GetTestingFunctions(m_cx));
ENSURE(testingFunctionsObj);
JS::RootedValue ret(m_cx);
JS_CallFunctionName(m_cx, testingFunctionsObj, "gcPreserveCode", JS::HandleValueArray::empty(), &ret);
JS_DefineProperty(m_cx, m_glob, "global", globalRootedVal, JSPROP_ENUMERATE | JSPROP_READONLY
| JSPROP_PERMANENT);
m_nativeScope = JS_DefineObject(m_cx, m_glob, nativeScopeName, NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY
| JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "print", ::print, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "log", ::logmsg, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "warn", ::warn, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "error", ::error, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "deepcopy", ::deepcopy, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
Register("ProfileStart", ::ProfileStart, 1);
Register("ProfileStop", ::ProfileStop, 0);
runtime->RegisterContext(m_cx);
}
示例12: rq
bool ScriptInterface::LoadGlobalScriptFile(const VfsPath& path)
{
JSAutoRequest rq(m->m_cx);
JS::RootedObject global(m->m_cx, m->m_glob);
if (!VfsFileExists(path))
{
LOGERROR("File '%s' does not exist", path.string8());
return false;
}
CVFSFile file;
PSRETURN ret = file.Load(g_VFS, path);
if (ret != PSRETURN_OK)
{
LOGERROR("Failed to load file '%s': %s", path.string8(), GetErrorString(ret));
return false;
}
std::wstring code = wstring_from_utf8(file.DecodeUTF8()); // assume it's UTF-8
utf16string codeUtf16(code.begin(), code.end());
uint lineNo = 1;
// CompileOptions does not copy the contents of the filename string pointer.
// Passing a temporary string there will cause undefined behaviour, so we create a separate string to avoid the temporary.
std::string filenameStr = path.string8();
JS::RootedValue rval(m->m_cx);
JS::CompileOptions opts(m->m_cx);
opts.setFileAndLine(filenameStr.c_str(), lineNo);
return JS::Evaluate(m->m_cx, global, opts,
reinterpret_cast<const char16_t*>(codeUtf16.c_str()), (uint)(codeUtf16.length()), &rval);
}
示例13: PSERROR_GUI_OperationNeedsGUIObject
void IGUIObject::RegisterScriptHandler(const CStr& Action, const CStr& Code, CGUI* pGUI)
{
if(!GetGUI())
throw PSERROR_GUI_OperationNeedsGUIObject();
JSContext* cx = pGUI->GetScriptInterface()->GetContext();
JSAutoRequest rq(cx);
JS::RootedValue globalVal(cx, pGUI->GetGlobalObject());
JS::RootedObject globalObj(cx, &globalVal.toObject());
const int paramCount = 1;
const char* paramNames[paramCount] = { "mouse" };
// Location to report errors from
CStr CodeName = GetName()+" "+Action;
// Generate a unique name
static int x = 0;
char buf[64];
sprintf_s(buf, ARRAY_SIZE(buf), "__eventhandler%d (%s)", x++, Action.c_str());
JS::CompileOptions options(cx);
options.setFileAndLine(CodeName.c_str(), 0);
options.setCompileAndGo(true);
JS::RootedFunction func(cx, JS_CompileFunction(cx, globalObj,
buf, paramCount, paramNames, Code.c_str(), Code.length(), options));
if (!func)
return; // JS will report an error message
JS::RootedObject funcObj(cx, JS_GetFunctionObject(func));
SetScriptHandler(Action, funcObj);
}
示例14: rq
void IGUIObject::ScriptEvent(const CStr& Action)
{
auto it = m_ScriptHandlers.find(Action);
if (it == m_ScriptHandlers.end())
return;
JSContext* cx = m_pGUI->GetScriptInterface()->GetContext();
JSAutoRequest rq(cx);
// Set up the 'mouse' parameter
JS::RootedValue mouse(cx);
m_pGUI->GetScriptInterface()->Eval("({})", &mouse);
m_pGUI->GetScriptInterface()->SetProperty(mouse, "x", m_pGUI->m_MousePos.x, false);
m_pGUI->GetScriptInterface()->SetProperty(mouse, "y", m_pGUI->m_MousePos.y, false);
m_pGUI->GetScriptInterface()->SetProperty(mouse, "buttons", m_pGUI->m_MouseButtons, false);
JS::AutoValueVector paramData(cx);
paramData.append(mouse);
JS::RootedObject obj(cx, GetJSObject());
JS::RootedValue handlerVal(cx, JS::ObjectValue(*it->second));
JS::RootedValue result(cx);
bool ok = JS_CallFunctionValue(cx, obj, handlerVal, paramData, &result);
if (!ok)
{
// We have no way to propagate the script exception, so just ignore it
// and hope the caller checks JS_IsExceptionPending
}
}
示例15: rq
// Return file contents as an array of lines. Assume file is UTF-8 encoded text.
//
// lines = readFileLines(filename);
// filename: VFS filename (may include path)
JS::Value JSI_VFS::ReadFileLines(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename)
{
JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
JSAutoRequest rq(cx);
//
// read file
//
CVFSFile file;
if (file.Load(g_VFS, filename) != PSRETURN_OK)
return JSVAL_NULL;
CStr contents = file.DecodeUTF8(); // assume it's UTF-8
// Fix CRLF line endings. (This function will only ever be used on text files.)
contents.Replace("\r\n", "\n");
//
// split into array of strings (one per line)
//
std::stringstream ss(contents);
JS::RootedObject line_array(cx, JS_NewArrayObject(cx, JS::HandleValueArray::empty()));
std::string line;
int cur_line = 0;
while (std::getline(ss, line))
{
// Decode each line as UTF-8
JS::RootedValue val(cx);
ScriptInterface::ToJSVal(cx, &val, CStr(line).FromUTF8());
JS_SetElement(cx, line_array, cur_line++, val);
}
return JS::ObjectValue(*line_array);
}