本文整理汇总了C++中jsval::isString方法的典型用法代码示例。如果您正苦于以下问题:C++ jsval::isString方法的具体用法?C++ jsval::isString怎么用?C++ jsval::isString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jsval
的用法示例。
在下文中一共展示了jsval::isString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set
void set(jsval val, JSContext* cx) {
if (val.isString()) {
this->set(val.toString(), cx);
} else {
buffer = NULL;
}
}
示例2: cx
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;
}
示例3: ar
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;
}