本文整理汇总了C++中js::Handle::isNull方法的典型用法代码示例。如果您正苦于以下问题:C++ Handle::isNull方法的具体用法?C++ Handle::isNull怎么用?C++ Handle::isNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类js::Handle
的用法示例。
在下文中一共展示了Handle::isNull方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
NS_IMETHODIMP
SmsFilter::SetRead(JSContext* aCx, JS::Handle<JS::Value> aRead)
{
if (aRead.isNull()) {
mData.read() = eReadState_Unknown;
return NS_OK;
}
if (!aRead.isBoolean()) {
return NS_ERROR_INVALID_ARG;
}
mData.read() = aRead.toBoolean() ? eReadState_Read : eReadState_Unread;
return NS_OK;
}
示例2: obj
NS_IMETHODIMP
SmsFilter::SetNumbers(JSContext* aCx, JS::Handle<JS::Value> aNumbers)
{
if (aNumbers.isNull()) {
mData.numbers().Clear();
return NS_OK;
}
if (!aNumbers.isObject()) {
return NS_ERROR_INVALID_ARG;
}
JS::Rooted<JSObject*> obj(aCx, &aNumbers.toObject());
if (!JS_IsArrayObject(aCx, obj)) {
return NS_ERROR_INVALID_ARG;
}
uint32_t size;
JS_ALWAYS_TRUE(JS_GetArrayLength(aCx, obj, &size));
nsTArray<nsString> numbers;
for (uint32_t i=0; i<size; ++i) {
JS::Rooted<JS::Value> jsNumber(aCx);
if (!JS_GetElement(aCx, obj, i, &jsNumber)) {
return NS_ERROR_INVALID_ARG;
}
if (!jsNumber.isString()) {
return NS_ERROR_INVALID_ARG;
}
nsDependentJSString number;
number.init(aCx, jsNumber.toString());
numbers.AppendElement(number);
}
mData.numbers().Clear();
mData.numbers().AppendElements(numbers);
return NS_OK;
}
示例3: FireInteralError
NS_IMETHODIMP
TCPSocketParent::SendEvent(const nsAString& aType, JS::Handle<JS::Value> aDataVal,
const nsAString& aReadyState, JSContext* aCx)
{
if (!mIPCOpen) {
NS_WARNING("Dropping callback due to no IPC connection");
return NS_OK;
}
CallbackData data;
if (aDataVal.isString()) {
JSString* jsstr = aDataVal.toString();
nsAutoJSString str;
if (!str.init(aCx, jsstr)) {
FireInteralError(this, __LINE__);
return NS_ERROR_OUT_OF_MEMORY;
}
data = SendableData(str);
} else if (aDataVal.isUndefined() || aDataVal.isNull()) {
data = mozilla::void_t();
} else if (aDataVal.isObject()) {
JS::Rooted<JSObject *> obj(aCx, &aDataVal.toObject());
if (JS_IsArrayBufferObject(obj)) {
FallibleTArray<uint8_t> fallibleArr;
uint32_t errLine = 0;
do {
JS::AutoCheckCannotGC nogc;
uint32_t nbytes = JS_GetArrayBufferByteLength(obj);
uint8_t* buffer = JS_GetArrayBufferData(obj, nogc);
if (!buffer) {
errLine = __LINE__;
break;
}
if (!fallibleArr.InsertElementsAt(0, buffer, nbytes, fallible)) {
errLine = __LINE__;
break;
}
} while (false);
if (errLine) {
FireInteralError(this, errLine);
return NS_ERROR_OUT_OF_MEMORY;
}
InfallibleTArray<uint8_t> arr;
arr.SwapElements(fallibleArr);
data = SendableData(arr);
} else {
nsAutoJSString name;
JS::Rooted<JS::Value> val(aCx);
if (!JS_GetProperty(aCx, obj, "name", &val)) {
NS_ERROR("No name property on supposed error object");
} else if (val.isString()) {
if (!name.init(aCx, val.toString())) {
NS_WARNING("couldn't initialize string");
}
}
data = TCPError(name);
}
} else {
NS_ERROR("Unexpected JS value encountered");
FireInteralError(this, __LINE__);
return NS_ERROR_FAILURE;
}
mozilla::unused <<
PTCPSocketParent::SendCallback(nsString(aType), data,
nsString(aReadyState));
return NS_OK;
}