• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ jsval类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中jsval的典型用法代码示例。如果您正苦于以下问题:C++ jsval类的具体用法?C++ jsval怎么用?C++ jsval使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了jsval类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: set

 void set(jsval val, JSContext* cx) {
     if (val.isString()) {
         this->set(val.toString(), cx);
     } else {
         buffer = NULL;
     }
 }
开发者ID:0309,项目名称:cocos2d-x,代码行数:7,代码来源:jsb_pluginx_basic_conversions.cpp


示例2: obj

// static
nsresult
IDBKeyRange::FromJSVal(JSContext* aCx,
                       const jsval& aVal,
                       IDBKeyRange** aKeyRange)
{
  nsRefPtr<IDBKeyRange> keyRange;

  if (aVal.isNullOrUndefined()) {
    // undefined and null returns no IDBKeyRange.
    keyRange.forget(aKeyRange);
    return NS_OK;
  }

  JS::Rooted<JSObject*> obj(aCx, aVal.isObject() ? &aVal.toObject() : nullptr);
  if (aVal.isPrimitive() || JS_IsArrayObject(aCx, obj) ||
      JS_ObjectIsDate(aCx, obj)) {
    // A valid key returns an 'only' IDBKeyRange.
    keyRange = new IDBKeyRange(nullptr, false, false, true);

    nsresult rv = GetKeyFromJSVal(aCx, aVal, keyRange->Lower());
    if (NS_FAILED(rv)) {
      return rv;
    }
  }
  else {
    MOZ_ASSERT(aVal.isObject());
    // An object is not permitted unless it's another IDBKeyRange.
    if (NS_FAILED(UNWRAP_OBJECT(IDBKeyRange, obj, keyRange))) {
      return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
    }
  }

  keyRange.forget(aKeyRange);
  return NS_OK;
}
开发者ID:Gabuzo,项目名称:mozilla-central,代码行数:36,代码来源:IDBKeyRange.cpp


示例3: Handle

  NS_IMETHOD Handle(const nsAString& aName, const jsval& aResult)
  {
    MOZ_ASSERT(NS_IsMainThread());

    // The geolocation is enabled by default:
    bool value = true;
    if (aResult.isBoolean()) {
      value = aResult.toBoolean();
    }

    MozSettingValue(value);
    return NS_OK;
  }
开发者ID:kzth,项目名称:releases-mozilla-aurora,代码行数:13,代码来源:nsGeolocation.cpp


示例4: Handle

  NS_DECL_ISUPPORTS

  NS_IMETHOD Handle(const nsAString& aName, const jsval& aResult, JSContext* aCx)
  {
    MOZ_ASSERT(NS_IsMainThread());
    MOZ_ASSERT(gBluetoothService);

    if (!aResult.isBoolean()) {
      NS_WARNING("Setting for '" BLUETOOTH_ENABLED_SETTING "' is not a boolean!");
      return NS_OK;
    }

    return aResult.toBoolean() ? gBluetoothService->Start() : NS_OK;
  }
开发者ID:dperit,项目名称:mozilla-central,代码行数:14,代码来源:BluetoothService.cpp


示例5: jsval_array_to_string

bool jsval_array_to_string(JSContext *cx, jsval v, std::string* ret)
{
	JS::RootedObject jsobj(cx);
	bool ok = v.isObject() && JS_ValueToObject( cx, JS::RootedValue(cx, v), &jsobj );
	JSB_PRECONDITION2( ok, cx, false, "Error converting value to object");
	JSB_PRECONDITION2( jsobj && JS_IsArrayObject( cx, jsobj), cx, false, "Object must be an array");

	uint32_t len;
	JS_GetArrayLength(cx, jsobj, &len);

	for( uint32_t i=0; i< len;i++ ) {
		JS::RootedValue valarg(cx);
		JS_GetElement(cx, jsobj, i, &valarg);

		std::string temp;
		ok = jsval_to_std_string(cx, valarg, &temp);
		JSB_PRECONDITION2(ok, cx, false, "Error processing arguments");
		if(i != len -1)
			ret->append(temp + ",");
		else
			ret->append(temp);
	}

	return true;
}
开发者ID:TheWindShan,项目名称:HYFish,代码行数:25,代码来源:jsb_pluginx_basic_conversions.cpp


示例6: JS_WriteTypedArray

JS_WriteTypedArray(JSStructuredCloneWriter *w, jsval v)
{
    JS_ASSERT(v.isObject());
    assertSameCompartment(w->context(), v);
    RootedObject obj(w->context(), &v.toObject());

    // If the object is a security wrapper, see if we're allowed to unwrap it.
    // If we aren't, throw.
    if (obj->isWrapper())
        obj = CheckedUnwrap(obj);
    if (!obj) {
        JS_ReportError(w->context(), "Permission denied to access object");
        return false;
    }
    return w->writeTypedArray(obj);
}
开发者ID:BrunoReX,项目名称:palemoon,代码行数:16,代码来源:jsclone.cpp


示例7: Handle

  NS_DECL_ISUPPORTS

  NS_IMETHOD Handle(const nsAString& aName, const jsval& aResult)
  {
    MOZ_ASSERT(NS_IsMainThread());

    if (!aResult.isBoolean()) {
      NS_WARNING("Setting for '" BLUETOOTH_ENABLED_SETTING "' is not a boolean!");
      return NS_OK;
    }

    // It is theoretically possible to shut down before the first settings check
    // has completed (though extremely unlikely).
    if (gBluetoothService) {
      return gBluetoothService->HandleStartupSettingsCheck(aResult.toBoolean());
    }

    return NS_OK;
  }
开发者ID:TelefonicaPushServer,项目名称:mozilla-central,代码行数:19,代码来源:BluetoothService.cpp


示例8: MOZ_ASSERT

NS_IMETHODIMP
SmsRequest::NotifyThreadList(const jsval& aThreadList, JSContext* aCx)
{
  MOZ_ASSERT(aThreadList.isObject());

  if (mParent) {
    JSObject* array = const_cast<JSObject*>(&aThreadList.toObject());

    uint32_t length;
    bool ok = JS_GetArrayLength(aCx, array, &length);
    NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);

    ReplyThreadList reply;
    InfallibleTArray<ThreadListItem>& ipcItems = reply.items();

    if (length) {
      ipcItems.SetCapacity(length);

      for (uint32_t i = 0; i < length; i++) {
        jsval arrayEntry;
        ok = JS_GetElement(aCx, array, i, &arrayEntry);
        NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);

        MOZ_ASSERT(arrayEntry.isObject());

        mozilla::idl::SmsThreadListItem item;
        nsresult rv = item.Init(aCx, &arrayEntry);
        NS_ENSURE_SUCCESS(rv, rv);

        ThreadListItem* ipcItem = ipcItems.AppendElement();
        ipcItem->senderOrReceiver() = item.senderOrReceiver;
        ipcItem->timestamp() = item.timestamp;
        ipcItem->body() = item.body;
        ipcItem->unreadCount() = item.unreadCount;
      }
    }

    return SendMessageReply(reply);
  }

  return NotifySuccess(aThreadList);
}
开发者ID:enopanen,项目名称:mozilla-central,代码行数:42,代码来源:SmsRequest.cpp


示例9: Handle

    NS_DECL_ISUPPORTS

    NS_IMETHOD
    Handle(const nsAString& aName, const jsval& aResult)
    {
        MOZ_ASSERT(NS_IsMainThread());

        JSContext *cx = nsContentUtils::GetCurrentJSContext();
        NS_ENSURE_TRUE(cx, NS_OK);

        if (!aResult.isNumber()) {
            NS_WARNING("'" AUDIO_VOLUME_BT_SCO "' is not a number!");
            return NS_OK;
        }

        BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
        hfp->mCurrentVgs = aResult.toNumber();

        return NS_OK;
    }
开发者ID:,项目名称:,代码行数:20,代码来源:


示例10: jsval_to_LogEventParamMap

JSBool jsval_to_LogEventParamMap(JSContext *cx, jsval v, LogEventParamMap** ret)
{
    JSBool jsret = JS_FALSE;
    if (v.isObject())
    {
        LogEventParamMap* tmp = new LogEventParamMap();
        jsret = jsval_to_TProductInfo(cx, v, tmp);
        if (jsret) {
            *ret = tmp;
        }
    }

    return jsret;
}
开发者ID:0309,项目名称:cocos2d-x,代码行数:14,代码来源:jsb_pluginx_basic_conversions.cpp


示例11: Delete

NS_IMETHODIMP
SmsManager::Delete(const jsval& aParam, nsIDOMMozSmsRequest** aRequest)
{
  if (aParam.isInt32()) {
    return Delete(aParam.toInt32(), aRequest);
  }

  if (!aParam.isObject()) {
    return NS_ERROR_INVALID_ARG;
  }

  nsresult rv;
  nsIScriptContext* sc = GetContextForEventHandlers(&rv);
  AutoPushJSContext cx(sc->GetNativeContext());
  NS_ENSURE_STATE(sc);
  nsCOMPtr<nsIDOMMozSmsMessage> message =
    do_QueryInterface(nsContentUtils::XPConnect()->GetNativeOfWrapper(cx, &aParam.toObject()));
  NS_ENSURE_TRUE(message, NS_ERROR_INVALID_ARG);

  int32_t id;
  message->GetId(&id);

  return Delete(id, aRequest);
}
开发者ID:,项目名称:,代码行数:24,代码来源:


示例12: set

	void set(JSObject* obj, jsval fval, jsval* args = NULL, unsigned argc = 0) {
		JSContext* cx = getGlobalContext();
		if (obj) {
			this->obj = obj;
			JS_AddObjectRoot(cx, &this->obj);
		}
		if (!fval.isNull()) {
			this->fval = fval;
			JS_AddValueRoot(cx, &this->fval);
		}
		if (args) {
			this->args = args;
			this->argc = argc;
			for (int i=0; i < argc; i++) {
				JS_AddValueRoot(cx, &this->args[i]);
			}
		}
	}
开发者ID:funkaster,项目名称:FakeWebGL,代码行数:18,代码来源:glue.cpp


示例13: GetContextForEventHandlers

NS_IMETHODIMP
SmsManager::Send(const jsval& aNumber, const nsAString& aMessage, jsval* aReturn)
{
  nsresult rv;
  nsIScriptContext* sc = GetContextForEventHandlers(&rv);
  NS_ENSURE_STATE(sc);
  AutoPushJSContext cx(sc->GetNativeContext());
  NS_ASSERTION(cx, "Failed to get a context!");

  if (!aNumber.isString() &&
      !(aNumber.isObject() && JS_IsArrayObject(cx, &aNumber.toObject()))) {
    return NS_ERROR_INVALID_ARG;
  }

  JSObject* global = sc->GetNativeGlobal();
  NS_ASSERTION(global, "Failed to get global object!");

  JSAutoRequest ar(cx);
  JSAutoCompartment ac(cx, global);

  if (aNumber.isString()) {
    return Send(cx, global, aNumber.toString(), aMessage, aReturn);
  }

  // Must be an array then.
  JSObject& numbers = aNumber.toObject();

  uint32_t size;
  JS_ALWAYS_TRUE(JS_GetArrayLength(cx, &numbers, &size));

  jsval* requests = new jsval[size];

  for (uint32_t i=0; i<size; ++i) {
    jsval number;
    if (!JS_GetElement(cx, &numbers, i, &number)) {
      return NS_ERROR_INVALID_ARG;
    }

    nsresult rv = Send(cx, global, number.toString(), aMessage, &requests[i]);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  aReturn->setObjectOrNull(JS_NewArrayObject(cx, size, requests));
  NS_ENSURE_TRUE(aReturn->isObject(), NS_ERROR_FAILURE);

  return NS_OK;
}
开发者ID:,项目名称:,代码行数:47,代码来源:


示例14: jsd_TrapHandler

JSTrapStatus
jsd_TrapHandler(JSContext *cx, JSScript *script_, jsbytecode *pc, jsval *rval,
                jsval closure)
{
    JS::RootedScript script(cx, script_);
    JSDExecHook* jsdhook = (JSDExecHook*) closure.toPrivate();
    JSD_ExecutionHookProc hook;
    void* hookData;
    JSDContext*  jsdc;

    JSD_LOCK();

    if( nullptr == (jsdc = jsd_JSDContextForJSContext(cx)) ||
        ! _isActiveHook(jsdc, script, jsdhook) )
    {
        JSD_UNLOCK();
        return JSTRAP_CONTINUE;
    }

    JSD_ASSERT_VALID_EXEC_HOOK(jsdhook);
    MOZ_ASSERT(!jsdhook->pc || jsdhook->pc == (uintptr_t)pc);
    MOZ_ASSERT(jsdhook->jsdscript->script == script);
    MOZ_ASSERT(jsdhook->jsdscript->jsdc == jsdc);

    hook = jsdhook->hook;
    hookData = jsdhook->callerdata;

    /* do not use jsdhook-> after this point */
    JSD_UNLOCK();

    if( ! jsdc || ! jsdc->inited )
        return JSTRAP_CONTINUE;

    if( JSD_IS_DANGEROUS_THREAD(jsdc) )
        return JSTRAP_CONTINUE;

    return jsd_CallExecutionHook(jsdc, cx, JSD_HOOK_BREAKPOINT,
                                 hook, hookData, rval);
}
开发者ID:Wrichik1999,项目名称:gecko-dev,代码行数:39,代码来源:jsd_scpt.cpp


示例15: GetContextForEventHandlers

NS_IMETHODIMP
SmsManager::Send(const jsval& aNumber, const nsAString& aMessage, jsval* aReturn)
{
  nsresult rv;
  nsIScriptContext* sc = GetContextForEventHandlers(&rv);
  NS_ENSURE_STATE(sc);
  JSContext* cx = sc->GetNativeContext();
  NS_ASSERTION(cx, "Failed to get a context!");

  if (!aNumber.isString() &&
      !(aNumber.isObject() && JS_IsArrayObject(cx, &aNumber.toObject()))) {
    return NS_ERROR_INVALID_ARG;
  }

  JSObject* global = sc->GetNativeGlobal();
  NS_ASSERTION(global, "Failed to get global object!");

  JSAutoRequest ar(cx);
  JSAutoCompartment ac(cx, global);

  if (aNumber.isString()) {
    return Send(cx, global, aNumber.toString(), aMessage, aReturn);
  }

  // Must be an object then.
  if (!aNumber.isObject()) {
    return NS_ERROR_FAILURE;
  }

  JSObject& numbers = aNumber.toObject();
  uint32_t size;
  if (!JS_GetArrayLength(cx, &numbers, &size)) {
    return NS_ERROR_FAILURE;
  }

  JS::AutoValueVector requests(cx);
  if (!requests.resize(size)) {
    return NS_ERROR_FAILURE;
  }

  JSString *str;
  for (uint32_t i = 0; i < size; ++i) {
    jsval number;
    if (!JS_GetElement(cx, &numbers, i, &number)) {
      return NS_ERROR_INVALID_ARG;
    }

    str = JS_ValueToString(cx, number);
    if (!str) {
      return NS_ERROR_FAILURE;
    }

    nsresult rv = Send(cx, global, str, aMessage, &requests[i]);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  JSObject* obj = JS_NewArrayObject(cx, requests.length(), requests.begin());
  if (!obj) {
    return NS_ERROR_FAILURE;
  }

  aReturn->setObject(*obj);
  return NS_OK;
}
开发者ID:Type-of-Tool,项目名称:ExMail,代码行数:64,代码来源:SmsManager.cpp


示例16: switch

bool
JavaScriptShared::toVariant(JSContext *cx, jsval from, JSVariant *to)
{
    switch (JS_TypeOfValue(cx, from)) {
      case JSTYPE_VOID:
        *to = void_t();
        return true;

      case JSTYPE_NULL:
      {
        *to = uint64_t(0);
        return true;
      }

      case JSTYPE_OBJECT:
      case JSTYPE_FUNCTION:
      {
        JSObject *obj = from.toObjectOrNull();
        if (!obj) {
            JS_ASSERT(from == JSVAL_NULL);
            *to = uint64_t(0);
            return true;
        }

        if (xpc_JSObjectIsID(cx, obj)) {
            JSIID iid;
            const nsID *id = xpc_JSObjectToID(cx, obj);
            ConvertID(*id, &iid);
            *to = iid;
            return true;
        }

        ObjectId id;
        if (!makeId(cx, obj, &id))
            return false;
        *to = uint64_t(id);
        return true;
      }

      case JSTYPE_STRING:
      {
        nsDependentJSString dep;
        if (!dep.init(cx, from))
            return false;
        *to = dep;
        return true;
      }

      case JSTYPE_NUMBER:
        if (JSVAL_IS_INT(from))
            *to = double(from.toInt32());
        else
            *to = from.toDouble();
        return true;

      case JSTYPE_BOOLEAN:
        *to = from.toBoolean();
        return true;

      default:
        MOZ_ASSERT(false);
        return false;
    }
}
开发者ID:birtles,项目名称:mozilla-central,代码行数:64,代码来源:JavaScriptShared.cpp


示例17: getGlobalContext

	~DeferredCallback() {
		JSContext* cx = getGlobalContext();
		if (obj) {
			JS_RemoveObjectRoot(cx, &obj);
		}
		if (!fval.isNull()) {
			JS_RemoveValueRoot(cx, &fval);
		}
		if (args) {
			for (int i=0; i < argc; i++) {
				JS_RemoveValueRoot(cx, &args[i]);
			}
			free(args);
		}
	}
开发者ID:funkaster,项目名称:FakeWebGL,代码行数:15,代码来源:glue.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ key_type类代码示例发布时间:2022-05-31
下一篇:
C++ jsonvalue类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap