本文整理汇总了C++中js::Value::setString方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::setString方法的具体用法?C++ Value::setString怎么用?C++ Value::setString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类js::Value
的用法示例。
在下文中一共展示了Value::setString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
NS_IMETHODIMP
MmsMessage::GetAttachments(JSContext* aCx, JS::Value* aAttachments)
{
// TODO Bug 850529 We should return an empty array (or null)
// when it has no attachments? Need to further check this.
uint32_t length = mAttachments.Length();
if (length == 0) {
*aAttachments = JSVAL_NULL;
return NS_OK;
}
JSObject* attachments = JS_NewArrayObject(aCx, length, nullptr);
NS_ENSURE_TRUE(attachments, NS_ERROR_OUT_OF_MEMORY);
for (uint32_t i = 0; i < length; ++i) {
const MmsAttachment &attachment = mAttachments[i];
JSObject* attachmentObj = JS_NewObject(aCx, nullptr, nullptr, nullptr);
NS_ENSURE_TRUE(attachmentObj, NS_ERROR_OUT_OF_MEMORY);
JS::Value tmpJsVal;
JSString* tmpJsStr;
// Get |attachment.mId|.
tmpJsStr = JS_NewUCStringCopyN(aCx,
attachment.id.get(),
attachment.id.Length());
NS_ENSURE_TRUE(tmpJsStr, NS_ERROR_OUT_OF_MEMORY);
tmpJsVal.setString(tmpJsStr);
if (!JS_DefineProperty(aCx, attachmentObj, "id", tmpJsVal,
NULL, NULL, JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE;
}
// Get |attachment.mLocation|.
tmpJsStr = JS_NewUCStringCopyN(aCx,
attachment.location.get(),
attachment.location.Length());
NS_ENSURE_TRUE(tmpJsStr, NS_ERROR_OUT_OF_MEMORY);
tmpJsVal.setString(tmpJsStr);
if (!JS_DefineProperty(aCx, attachmentObj, "location", tmpJsVal,
NULL, NULL, JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE;
}
// Get |attachment.mContent|.
nsresult rv = nsContentUtils::WrapNative(aCx,
JS_GetGlobalForScopeChain(aCx),
attachment.content,
&NS_GET_IID(nsIDOMBlob),
&tmpJsVal);
NS_ENSURE_SUCCESS(rv, rv);
if (!JS_DefineProperty(aCx, attachmentObj, "content", tmpJsVal,
NULL, NULL, JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE;
}
tmpJsVal = OBJECT_TO_JSVAL(attachmentObj);
if (!JS_SetElement(aCx, attachments, i, &tmpJsVal)) {
return NS_ERROR_FAILURE;
}
}
aAttachments->setObject(*attachments);
return NS_OK;
}