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