本文整理汇总了C++中js::Handle::toObject方法的典型用法代码示例。如果您正苦于以下问题:C++ Handle::toObject方法的具体用法?C++ Handle::toObject怎么用?C++ Handle::toObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类js::Handle
的用法示例。
在下文中一共展示了Handle::toObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: arrayBuffer
NS_IMETHODIMP
ArrayBufferInputStream::SetData(JS::Handle<JS::Value> aBuffer,
uint32_t aByteOffset,
uint32_t aLength,
JSContext* aCx)
{
if (!aBuffer.isObject()) {
return NS_ERROR_FAILURE;
}
JS::RootedObject arrayBuffer(aCx, &aBuffer.toObject());
if (!JS_IsArrayBufferObject(arrayBuffer)) {
return NS_ERROR_FAILURE;
}
mArrayBuffer.construct(aCx, aBuffer);
uint32_t buflen = JS_GetArrayBufferByteLength(arrayBuffer);
mOffset = std::min(buflen, aByteOffset);
mBufferLength = std::min(buflen - mOffset, aLength);
mBuffer = JS_GetStableArrayBufferData(aCx, arrayBuffer);
if (!mBuffer) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
示例2: thisObj
bool
FieldSetterImpl(JSContext *cx, JS::CallArgs args)
{
JS::Handle<JS::Value> thisv = args.thisv();
MOZ_ASSERT(ValueHasISupportsPrivate(thisv));
JS::Rooted<JSObject*> thisObj(cx, &thisv.toObject());
// We should be in the compartment of |this|. If we got here via nativeCall,
// |this| is not same-compartment with |callee|, and it's possible via
// asymmetric security semantics that |args.calleev()| is actually a security
// wrapper. In this case, we know we want to do an unsafe unwrap, and
// InstallXBLField knows how to handle cross-compartment pointers.
bool installed = false;
JS::Rooted<JSObject*> callee(cx, js::UncheckedUnwrap(&args.calleev().toObject()));
JS::Rooted<jsid> id(cx);
if (!InstallXBLField(cx, callee, thisObj, &id, &installed)) {
return false;
}
if (installed) {
if (!::JS_SetPropertyById(cx, thisObj, id, args.get(0))) {
return false;
}
}
args.rval().setUndefined();
return true;
}
示例3: obj
// static
nsresult
IDBKeyRange::FromJSVal(JSContext* aCx,
JS::Handle<JS::Value> 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;
}
示例4:
NS_IMETHODIMP
TCPSocketParent::InitJS(JS::Handle<JS::Value> aIntermediary, JSContext* aCx)
{
MOZ_ASSERT(aIntermediary.isObject());
mIntermediaryObj = &aIntermediary.toObject();
return NS_OK;
}
示例5: ReplyError
// PromiseNativeHandler
void
PresentationResponderInfo::ResolvedCallback(JSContext* aCx,
JS::Handle<JS::Value> aValue)
{
MOZ_ASSERT(NS_IsMainThread());
if (NS_WARN_IF(!aValue.isObject())) {
ReplyError(NS_ERROR_NOT_AVAILABLE);
return;
}
JS::Rooted<JSObject*> obj(aCx, &aValue.toObject());
if (NS_WARN_IF(!obj)) {
ReplyError(NS_ERROR_NOT_AVAILABLE);
return;
}
// Start to listen to document state change event |STATE_TRANSFERRING|.
HTMLIFrameElement* frame = nullptr;
nsresult rv = UNWRAP_OBJECT(HTMLIFrameElement, obj, frame);
if (NS_WARN_IF(!frame)) {
ReplyError(NS_ERROR_NOT_AVAILABLE);
return;
}
nsCOMPtr<nsIFrameLoaderOwner> owner = do_QueryInterface((nsIFrameLoaderOwner*) frame);
if (NS_WARN_IF(!owner)) {
ReplyError(NS_ERROR_NOT_AVAILABLE);
return;
}
nsCOMPtr<nsIFrameLoader> frameLoader;
rv = owner->GetFrameLoader(getter_AddRefs(frameLoader));
if (NS_WARN_IF(NS_FAILED(rv))) {
ReplyError(rv);
return;
}
nsRefPtr<TabParent> tabParent = TabParent::GetFrom(frameLoader);
if (tabParent) {
// OOP frame
nsCOMPtr<nsIContentParent> cp = tabParent->Manager();
NS_WARN_IF(!static_cast<ContentParent*>(cp.get())->SendNotifyPresentationReceiverLaunched(tabParent, mSessionId));
} else {
// In-process frame
nsCOMPtr<nsIDocShell> docShell;
rv = frameLoader->GetDocShell(getter_AddRefs(docShell));
if (NS_WARN_IF(NS_FAILED(rv))) {
ReplyError(rv);
return;
}
mLoadingCallback = new PresentationResponderLoadingCallback(mSessionId);
rv = mLoadingCallback->Init(docShell);
if (NS_WARN_IF(NS_FAILED(rv))) {
ReplyError(rv);
return;
}
}
}
示例6: SendReply
NS_IMETHODIMP
MobileConnectionRequestParent::NotifyGetCallForwardingSuccess(JS::Handle<JS::Value> aResults)
{
uint32_t length;
AutoSafeJSContext cx;
JS::Rooted<JSObject*> object(cx, &aResults.toObject());
nsTArray<IPC::MozCallForwardingOptions> results;
if (!JS_IsArrayObject(cx, object) ||
!JS_GetArrayLength(cx, object, &length)) {
return NS_ERROR_TYPE_ERR;
}
for (uint32_t i = 0; i < length; i++) {
JS::Rooted<JS::Value> entry(cx);
IPC::MozCallForwardingOptions info;
if (!JS_GetElement(cx, object, i, &entry) || !info.Init(cx, entry)) {
return NS_ERROR_TYPE_ERR;
}
results.AppendElement(info);
}
return SendReply(MobileConnectionReplySuccessCallForwarding(results));
}
示例7: buffer
NS_IMETHODIMP
nsBinaryInputStream::ReadArrayBuffer(uint32_t aLength,
JS::Handle<JS::Value> aBuffer,
JSContext* aCx, uint32_t* aReadLength)
{
if (!aBuffer.isObject()) {
return NS_ERROR_FAILURE;
}
JS::RootedObject buffer(aCx, &aBuffer.toObject());
if (!JS_IsArrayBufferObject(buffer)) {
return NS_ERROR_FAILURE;
}
uint32_t bufferLength = JS_GetArrayBufferByteLength(buffer);
if (bufferLength < aLength) {
return NS_ERROR_FAILURE;
}
uint32_t bufSize = std::min<uint32_t>(aLength, 4096);
UniquePtr<char[]> buf = MakeUnique<char[]>(bufSize);
uint32_t pos = 0;
*aReadLength = 0;
do {
// Read data into temporary buffer.
uint32_t bytesRead;
uint32_t amount = std::min(aLength - pos, bufSize);
nsresult rv = Read(buf.get(), amount, &bytesRead);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
MOZ_ASSERT(bytesRead <= amount);
if (bytesRead == 0) {
break;
}
// Copy data into actual buffer.
JS::AutoCheckCannotGC nogc;
bool isShared;
if (bufferLength != JS_GetArrayBufferByteLength(buffer)) {
return NS_ERROR_FAILURE;
}
char* data = reinterpret_cast<char*>(JS_GetArrayBufferData(buffer, &isShared, nogc));
MOZ_ASSERT(!isShared); // Implied by JS_GetArrayBufferData()
if (!data) {
return NS_ERROR_FAILURE;
}
*aReadLength += bytesRead;
PodCopy(data + pos, buf.get(), bytesRead);
pos += bytesRead;
} while (pos < aLength);
return NS_OK;
}
示例8: GetDOMClass
bool
ValueHasISupportsPrivate(JS::Handle<JS::Value> v)
{
if (!v.isObject()) {
return false;
}
const DOMJSClass* domClass = GetDOMClass(&v.toObject());
if (domClass) {
return domClass->mDOMObjectIsISupports;
}
const JSClass* clasp = ::JS_GetClass(&v.toObject());
const uint32_t HAS_PRIVATE_NSISUPPORTS =
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS;
return (clasp->flags & HAS_PRIVATE_NSISUPPORTS) == HAS_PRIVATE_NSISUPPORTS;
}
示例9: ac
NS_IMETHODIMP
nsSpeechTask::SendAudio(JS::Handle<JS::Value> aData, JS::Handle<JS::Value> aLandmarks,
JSContext* aCx)
{
MOZ_ASSERT(XRE_IsParentProcess());
if(NS_WARN_IF(!(mStream))) {
return NS_ERROR_NOT_AVAILABLE;
}
if(NS_WARN_IF(mStream->IsDestroyed())) {
return NS_ERROR_NOT_AVAILABLE;
}
if(NS_WARN_IF(!(mChannels))) {
return NS_ERROR_FAILURE;
}
if(NS_WARN_IF(!(aData.isObject()))) {
return NS_ERROR_INVALID_ARG;
}
if (mIndirectAudio) {
NS_WARNING("Can't call SendAudio from an indirect audio speech service.");
return NS_ERROR_FAILURE;
}
JS::Rooted<JSObject*> darray(aCx, &aData.toObject());
JSAutoCompartment ac(aCx, darray);
JS::Rooted<JSObject*> tsrc(aCx, nullptr);
// Allow either Int16Array or plain JS Array
if (JS_IsInt16Array(darray)) {
tsrc = darray;
} else {
bool isArray;
if (!JS_IsArrayObject(aCx, darray, &isArray)) {
return NS_ERROR_UNEXPECTED;
}
if (isArray) {
tsrc = JS_NewInt16ArrayFromArray(aCx, darray);
}
}
if (!tsrc) {
return NS_ERROR_DOM_TYPE_MISMATCH_ERR;
}
uint32_t dataLen = JS_GetTypedArrayLength(tsrc);
RefPtr<mozilla::SharedBuffer> samples;
{
JS::AutoCheckCannotGC nogc;
samples = makeSamples(JS_GetInt16ArrayData(tsrc, nogc), dataLen);
}
SendAudioImpl(samples, dataLen);
return NS_OK;
}
示例10: EventListener
static already_AddRefed<EventListener>
ToEventListener(JSContext* aCx, JS::Handle<JS::Value> aValue)
{
if (NS_WARN_IF(!aValue.isObject())) {
return nullptr;
}
JS::Rooted<JSObject*> obj(aCx, &aValue.toObject());
RefPtr<EventListener> listener =
new EventListener(aCx, obj, GetIncumbentGlobal());
return listener.forget();
}
示例11: NotifyDialMMISuccess
nsresult
TelephonyDialCallback::NotifyDialMMISuccess(JSContext* aCx,
const nsAString& aStatusMessage,
JS::Handle<JS::Value> aInfo)
{
RootedDictionary<MozMMIResult> result(aCx);
result.mServiceCode.Assign(mServiceCode);
result.mStatusMessage.Assign(aStatusMessage);
result.mAdditionalInformation.Construct().SetAsObject() = &aInfo.toObject();
return NotifyDialMMISuccess(aCx, result);
}
示例12:
NS_IMETHODIMP
WebVTTListener::OnRegion(JS::Handle<JS::Value> aRegion, JSContext* aCx)
{
if (!aRegion.isObject()) {
return NS_ERROR_FAILURE;
}
TextTrackRegion* region;
nsresult rv = UNWRAP_OBJECT(VTTRegion, &aRegion.toObject(), region);
NS_ENSURE_SUCCESS(rv, rv);
mElement->mTrack->AddRegion(*region);
return NS_OK;
}
示例13:
NS_IMETHODIMP
WebVTTListener::OnCue(JS::Handle<JS::Value> aCue, JSContext* aCx)
{
if (!aCue.isObject()) {
return NS_ERROR_FAILURE;
}
TextTrackCue* cue = nullptr;
nsresult rv = UNWRAP_OBJECT(VTTCue, &aCue.toObject(), cue);
NS_ENSURE_SUCCESS(rv, rv);
cue->SetTrackElement(mElement);
mElement->mTrack->AddCue(*cue);
return NS_OK;
}
示例14: obj
// static
nsresult
IDBKeyRange::FromJSVal(JSContext* aCx,
JS::Handle<JS::Value> aVal,
IDBKeyRange** aKeyRange)
{
MOZ_ASSERT_IF(!aCx, aVal.isUndefined());
RefPtr<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);
bool isValidKey = aVal.isPrimitive();
if (!isValidKey) {
js::ESClass cls;
if (!js::GetBuiltinClass(aCx, obj, &cls)) {
return NS_ERROR_UNEXPECTED;
}
isValidKey = cls == js::ESClass::Array || cls == js::ESClass::Date;
}
if (isValidKey) {
// 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;
}
示例15: 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;
}