当前位置: 首页>>代码示例>>C++>>正文


C++ HandleValue::isNullOrUndefined方法代码示例

本文整理汇总了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;
}
开发者ID:jasonLaster,项目名称:gecko-dev,代码行数:47,代码来源:nsContentPermissionHelper.cpp

示例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;
//.........这里部分代码省略.........
开发者ID:MovementAndMeaning,项目名称:Core_MPlusM,代码行数:101,代码来源:m+mJavaScriptFilterService.cpp


注:本文中的js::HandleValue::isNullOrUndefined方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。