本文整理汇总了C++中js::Handle类的典型用法代码示例。如果您正苦于以下问题:C++ Handle类的具体用法?C++ Handle怎么用?C++ Handle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Handle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getPropertyWrapper
JSBool JavaObject::getPropertyWrapper(JSContext* ctx, JS::Handle<JSObject*> obj,
JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) {
jsval rval;
JSBool result = JavaObject::getProperty(ctx, obj.get(), id.get(), &rval);
vp.set(rval);
return result;
}
示例2: 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;
}
示例3: SetAGpsDataConn
NS_IMETHODIMP
GonkGPSGeolocationProvider::Handle(const nsAString& aName,
JS::Handle<JS::Value> aResult)
{
#ifdef MOZ_B2G_RIL
if (aName.EqualsLiteral("ril.supl.apn")) {
// When we get the APN, we attempt to call data_call_open of AGPS.
if (aResult.isString()) {
JSContext *cx = nsContentUtils::GetCurrentJSContext();
NS_ENSURE_TRUE(cx, NS_OK);
// NB: No need to enter a compartment to read the contents of a string.
nsAutoJSString apn;
if (!apn.init(cx, aResult.toString())) {
return NS_ERROR_FAILURE;
}
if (!apn.IsEmpty()) {
SetAGpsDataConn(apn);
}
}
} else
#endif // MOZ_B2G_RIL
if (aName.EqualsLiteral(SETTING_DEBUG_ENABLED)) {
gGPSDebugging = aResult.isBoolean() ? aResult.toBoolean() : false;
return NS_OK;
}
return NS_OK;
}
示例4: 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;
}
}
}
示例5: 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;
}
示例6: 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;
}
示例7:
NS_IMETHODIMP
TCPSocketParent::InitJS(JS::Handle<JS::Value> aIntermediary, JSContext* aCx)
{
MOZ_ASSERT(aIntermediary.isObject());
mIntermediaryObj = &aIntermediary.toObject();
return NS_OK;
}
示例8: Handle
NS_IMETHOD Handle(const nsAString& aName, JS::Handle<JS::Value> aResult)
{
RefPtr<AudioManager> audioManager = AudioManager::GetInstance();
MOZ_ASSERT(audioManager);
for (uint32_t idx = 0; idx < MOZ_ARRAY_LENGTH(gVolumeData); ++idx) {
NS_ConvertASCIItoUTF16 volumeType(gVolumeData[idx].mChannelName);
if (StringBeginsWith(aName, volumeType)) {
uint32_t device = GetDeviceFromSettingName(aName);
MOZ_ASSERT(device != AUDIO_DEVICE_NONE);
if (aResult.isInt32()) {
int32_t stream = gVolumeData[idx].mStreamType;
uint32_t volIndex = aResult.toInt32();
nsresult rv = audioManager->ValidateVolumeIndex(stream, volIndex);
if (NS_WARN_IF(NS_FAILED(rv))) {
mPromiseHolder.Reject("Error : invalid volume index.", __func__);
return rv;
}
audioManager->SetStreamVolumeForDevice(stream, volIndex, device);
}
if (++mInitCounter == MOZ_ARRAY_LENGTH(kAudioDeviceInfos) * MOZ_ARRAY_LENGTH(gVolumeData)) {
mPromiseHolder.Resolve(true, __func__);
}
return NS_OK;
}
}
mPromiseHolder.Reject("Error : unexpected audio init event.", __func__);
return NS_OK;
}
示例9: 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;
}
示例10: 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;
}
示例11: 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();
}
示例12: SetAGpsDataConn
NS_IMETHODIMP
GonkGPSGeolocationProvider::Handle(const nsAString& aName,
JS::Handle<JS::Value> aResult)
{
#ifdef MOZ_B2G_RIL
if (aName.EqualsLiteral("ril.supl.apn")) {
// When we get the APN, we attempt to call data_call_open of AGPS.
if (aResult.isString()) {
JSContext *cx = nsContentUtils::GetCurrentJSContext();
NS_ENSURE_TRUE(cx, NS_OK);
// NB: No need to enter a compartment to read the contents of a string.
nsAutoJSString apn;
if (!apn.init(cx, aResult.toString())) {
return NS_ERROR_FAILURE;
}
if (!apn.IsEmpty()) {
SetAGpsDataConn(apn);
}
}
} else if (aName.EqualsASCII(kSettingRilDefaultServiceId)) {
uint32_t id = 0;
JSContext *cx = nsContentUtils::GetCurrentJSContext();
NS_ENSURE_TRUE(cx, NS_OK);
if (!JS::ToUint32(cx, aResult, &id)) {
return NS_ERROR_FAILURE;
}
if (!IsValidRilServiceId(id)) {
return NS_ERROR_UNEXPECTED;
}
mRilDataServiceId = id;
UpdateRadioInterface();
MOZ_ASSERT(!mObservingNetworkConnStateChange);
// Now we know which service ID to deal with, observe necessary topic then
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
NS_ENSURE_TRUE(obs, NS_OK);
if (NS_FAILED(obs->AddObserver(this, kNetworkConnStateChangedTopic, false))) {
NS_WARNING("Failed to add network state changed observer!");
} else {
mObservingNetworkConnStateChange = true;
}
}
#endif // MOZ_B2G_RIL
return NS_OK;
}
示例13:
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;
}
示例14:
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;
}
示例15: obj
js_DefineOwnProperty(JSContext *cx, JSObject *objArg, jsid idArg,
JS::Handle<js::PropertyDescriptor> descriptor, bool *bp)
{
RootedObject obj(cx, objArg);
RootedId id(cx, idArg);
js::AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
assertSameCompartment(cx, obj, id, descriptor.value());
if (descriptor.hasGetterObject())
assertSameCompartment(cx, descriptor.getterObject());
if (descriptor.hasSetterObject())
assertSameCompartment(cx, descriptor.setterObject());
return DefineOwnProperty(cx, HandleObject(obj), id, descriptor, bp);
}