本文整理汇总了C++中JSAutoByteString::length方法的典型用法代码示例。如果您正苦于以下问题:C++ JSAutoByteString::length方法的具体用法?C++ JSAutoByteString::length怎么用?C++ JSAutoByteString::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSAutoByteString
的用法示例。
在下文中一共展示了JSAutoByteString::length方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: JS_btoa
// {{{ Conversions
bool JSGlobal::JS_btoa(JSContext *cx, JS::CallArgs &args)
{
if (args[0].isString()) {
JSAutoByteString cdata;
JS::RootedString str(cx, args[0].toString());
cdata.encodeUtf8(cx, str);
char *ret = Utils::B64Encode(
reinterpret_cast<unsigned char *>(cdata.ptr()), cdata.length());
args.rval().setString(JS_NewStringCopyZ(cx, ret));
free(ret);
} else {
args.rval().setNull();
JS_ReportWarning(cx, "btoa() non-string given");
}
return true;
}
示例2: str
nsresult
RilConsumer::Send(JSContext* aCx, const CallArgs& aArgs)
{
if (NS_WARN_IF(!mSocket) ||
NS_WARN_IF(mSocket->GetConnectionStatus() == SOCKET_DISCONNECTED)) {
// Probably shutting down.
return NS_OK;
}
UniquePtr<UnixSocketRawData> raw;
Value v = aArgs[1];
if (v.isString()) {
JSAutoByteString abs;
Rooted<JSString*> str(aCx, v.toString());
if (!abs.encodeUtf8(aCx, str)) {
return NS_ERROR_FAILURE;
}
raw = MakeUnique<UnixSocketRawData>(abs.ptr(), abs.length());
} else if (!v.isPrimitive()) {
JSObject* obj = v.toObjectOrNull();
if (!JS_IsTypedArrayObject(obj)) {
JS_ReportError(aCx, "Object passed in wasn't a typed array");
return NS_ERROR_FAILURE;
}
uint32_t type = JS_GetArrayBufferViewType(obj);
if (type != js::Scalar::Int8 &&
type != js::Scalar::Uint8 &&
type != js::Scalar::Uint8Clamped) {
JS_ReportError(aCx, "Typed array data is not octets");
return NS_ERROR_FAILURE;
}
size_t size = JS_GetTypedArrayByteLength(obj);
bool isShared;
void* data;
{
AutoCheckCannotGC nogc;
data = JS_GetArrayBufferViewData(obj, &isShared, nogc);
}
if (isShared) {
JS_ReportError(
aCx, "Incorrect argument. Shared memory not supported");
return NS_ERROR_FAILURE;
}
raw = MakeUnique<UnixSocketRawData>(data, size);
} else {
JS_ReportError(
aCx, "Incorrect argument. Expecting a string or a typed array");
return NS_ERROR_FAILURE;
}
if (!raw) {
JS_ReportError(aCx, "Unable to post to RIL");
return NS_ERROR_FAILURE;
}
mSocket->SendSocketData(raw.release());
return NS_OK;
}