本文整理汇总了C++中js::HandleValue::isNullOrUndefined方法的典型用法代码示例。如果您正苦于以下问题:C++ HandleValue::isNullOrUndefined方法的具体用法?C++ HandleValue::isNullOrUndefined怎么用?C++ HandleValue::isNullOrUndefined使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类js::HandleValue
的用法示例。
在下文中一共展示了HandleValue::isNullOrUndefined方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TranslateChoices
nsresult TranslateChoices(
JS::HandleValue aChoices,
const nsTArray<PermissionRequest>& aPermissionRequests,
nsTArray<PermissionChoice>& aTranslatedChoices) {
if (aChoices.isNullOrUndefined()) {
// No choice is specified.
} else if (aChoices.isObject()) {
// Iterate through all permission types.
for (uint32_t i = 0; i < aPermissionRequests.Length(); ++i) {
nsCString type = aPermissionRequests[i].type();
JS::Rooted<JSObject*> obj(RootingCx(), &aChoices.toObject());
// People really shouldn't be passing WindowProxy or Location
// objects for the choices here.
obj = js::CheckedUnwrapStatic(obj);
if (!obj) {
return NS_ERROR_FAILURE;
}
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
JSAutoRealm ar(cx, obj);
JS::Rooted<JS::Value> val(cx);
if (!JS_GetProperty(cx, obj, type.BeginReading(), &val) ||
!val.isString()) {
// no setting for the permission type, clear exception and skip it
jsapi.ClearException();
} else {
nsAutoJSString choice;
if (!choice.init(cx, val)) {
jsapi.ClearException();
return NS_ERROR_FAILURE;
}
aTranslatedChoices.AppendElement(PermissionChoice(type, choice));
}
}
} else {
MOZ_ASSERT(false, "SelectedChoices should be undefined or an JS object");
return NS_ERROR_FAILURE;
}
return NS_OK;
}
示例2: funcArgs
void
JavaScriptFilterService::doIdle(void)
{
ODL_OBJENTER(); //####
if (isActive())
{
ODL_LOG("(isActive())"); //####
if (_goAhead.check())
{
ODL_LOG("(_goAhead.check())"); //####
if (_scriptThreadFunc.isNullOrUndefined())
{
ODL_LOG("(_scriptThreadFunc.isNullOrUndefined())"); //####
// We have a request from an input handler.
if (_inHandlers.size() > _mostRecentSlot)
{
ODL_LOG("(getInletCount() > _mostRecentSlot)"); //####
JS::HandleValue handlerFunc = _inletHandlers[_mostRecentSlot];
JavaScriptFilterInputHandler * aHandler = _inHandlers.at(_mostRecentSlot);
if (aHandler && (! handlerFunc.isNullOrUndefined()))
{
ODL_LOG("(aHandler && (! handlerFunc.isNullOrUndefined()))"); //####
JS::RootedValue argValue(_context);
JS::Value slotNumberValue;
JS::AutoValueVector funcArgs(_context);
JS::RootedValue funcResult(_context);
slotNumberValue.setInt32(static_cast<int32_t>(_mostRecentSlot));
createValueFromBottle(_context, aHandler->getReceivedData(), &argValue);
funcArgs.append(slotNumberValue);
funcArgs.append(argValue);
JS_BeginRequest(_context);
if (JS_CallFunctionValue(_context, _global, handlerFunc, funcArgs,
&funcResult))
{
// We don't care about the function result, as it's supposed to just
// write to the outlet stream(s).
}
else
{
ODL_LOG("! (JS_CallFunctionValue(_context, _global, " //####
"handlerFunc, funcArgs, &funcResult))"); //####
JS::RootedValue exc(_context);
if (JS_GetPendingException(_context, &exc))
{
JS_ClearPendingException(_context);
std::stringstream buff;
YarpString message("Exception occurred while executing "
"handler function for inlet ");
buff << _mostRecentSlot;
message += buff.str();
message += ".";
MpM_FAIL_(message.c_str());
}
}
JS_EndRequest(_context);
}
}
_staller.post();
}
else
{
ODL_LOG("! (_scriptThreadFunc.isNullOrUndefined())"); //####
try
{
JS::AutoValueVector funcArgs(_context);
JS::RootedValue funcResult(_context);
JS_BeginRequest(_context);
if (JS_CallFunctionValue(_context, _global, _scriptThreadFunc, funcArgs,
&funcResult))
{
ODL_LOG("(JS_CallFunctionValue(_context, _global, " //####
"_scriptThreadFunc, funcArgs, &funcResult))"); //####
// We don't care about the function result, as it's supposed to just perform
// an iteration of the thread.
}
else
{
ODL_LOG("! (JS_CallFunctionValue(_context, _global, " //####
"_scriptThreadFunc, funcArgs, &funcResult))"); //####
JS::RootedValue exc(_context);
if (JS_GetPendingException(_context, &exc))
{
ODL_LOG("(JS_GetPendingException(_context, &exc))"); //####
JS_ClearPendingException(_context);
MpM_FAIL_("Exception occurred while executing the scriptThread "
"function.");
}
}
JS_EndRequest(_context);
}
catch (...)
{
ODL_LOG("Exception caught"); //####
throw;
//.........这里部分代码省略.........