Пример #1
0
void
WebGLContext::GetParameterIndexed(JSContext* cx, GLenum pname, GLuint index,
                                  JS::MutableHandle<JS::Value> retval)
{
    if (IsContextLost()) {
        retval.setNull();
        return;
    }

    MakeContextCurrent();

    switch (pname) {
        case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
        {
            if (index >= mGLMaxTransformFeedbackSeparateAttribs) {
                ErrorInvalidValue("getParameterIndexed: index should be less than MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS", index);
                retval.setNull();
                return;
            }
            retval.setNull(); // See bug 903594
            return;
        }

        default:
            break;
    }

    ErrorInvalidEnumInfo("getParameterIndexed: parameter", pname);
    retval.setNull();
}
Пример #2
0
bool
EventListenerInfo::GetJSVal(JSContext* aCx,
                            Maybe<JSAutoCompartment>& aAc,
                            JS::MutableHandle<JS::Value> aJSVal)
{
  aJSVal.setNull();
  nsCOMPtr<nsIXPConnectWrappedJS> wrappedJS = do_QueryInterface(mListener);
  if (wrappedJS) {
    JS::Rooted<JSObject*> object(aCx, wrappedJS->GetJSObject());
    if (!object) {
      return false;
    }
    aAc.emplace(aCx, object);
    aJSVal.setObject(*object);
    return true;
  }

  nsCOMPtr<JSEventHandler> jsHandler = do_QueryInterface(mListener);
  if (jsHandler && jsHandler->GetTypedEventHandler().HasEventHandler()) {
    JS::Handle<JSObject*> handler =
      jsHandler->GetTypedEventHandler().Ptr()->CallableOrNull();
    if (handler) {
      aAc.emplace(aCx, handler);
      aJSVal.setObject(*handler);
      return true;
    }
  }
  return false;
}
Пример #3
0
void
DataTransfer::MozGetDataAt(JSContext* aCx, const nsAString& aFormat,
                           uint32_t aIndex,
                           JS::MutableHandle<JS::Value> aRetval,
                           nsIPrincipal& aSubjectPrincipal,
                           mozilla::ErrorResult& aRv)
{
  nsCOMPtr<nsIVariant> data;
  aRv = GetDataAtInternal(aFormat, aIndex, &aSubjectPrincipal,
                          getter_AddRefs(data));
  if (aRv.Failed()) {
    return;
  }

  if (!data) {
    aRetval.setNull();
    return;
  }

  JS::Rooted<JS::Value> result(aCx);
  if (!VariantToJsval(aCx, data, aRetval)) {
    aRv = NS_ERROR_FAILURE;
    return;
  }
}
Пример #4
0
NS_IMETHODIMP nsScriptableRegion::GetRects(JSContext* aCx, JS::MutableHandle<JS::Value> aRects)
{
  uint32_t numRects = mRegion.GetNumRects();

  if (!numRects) {
    aRects.setNull();
    return NS_OK;
  }

  JS::Rooted<JSObject*> destArray(aCx, JS_NewArrayObject(aCx, numRects * 4));
  if (!destArray) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  aRects.setObject(*destArray);

  uint32_t n = 0;
  nsIntRegionRectIterator iter(mRegion);
  const nsIntRect *rect;

  while ((rect = iter.Next())) {
    if (!JS_DefineElement(aCx, destArray, n, rect->x, JSPROP_ENUMERATE) ||
        !JS_DefineElement(aCx, destArray, n + 1, rect->y, JSPROP_ENUMERATE) ||
        !JS_DefineElement(aCx, destArray, n + 2, rect->width, JSPROP_ENUMERATE) ||
        !JS_DefineElement(aCx, destArray, n + 3, rect->height, JSPROP_ENUMERATE)) {
      return NS_ERROR_FAILURE;
    }
    n += 4;
  }

  return NS_OK;
}
Пример #5
0
void
CustomEvent::GetDetail(JSContext* aCx,
                       JS::MutableHandle<JS::Value> aRetval)
{
    if (!mDetail) {
        aRetval.setNull();
        return;
    }

    VariantToJsval(aCx, mDetail, aRetval);
}
Пример #6
0
NS_IMETHODIMP
SmsFilter::GetThreadId(JSContext* aCx, JS::MutableHandle<JS::Value> aThreadId)
{
  if (!mData.threadId()) {
    aThreadId.setNull();
    return NS_OK;
  }

  aThreadId.setNumber(static_cast<double>(mData.threadId()));
  return NS_OK;
}
Пример #7
0
NS_IMETHODIMP
SmsFilter::GetRead(JSContext* aCx, JS::MutableHandle<JS::Value> aRead)
{
  if (mData.read() == eReadState_Unknown) {
    aRead.setNull();
    return NS_OK;
  }

  aRead.setBoolean(mData.read());
  return NS_OK;
}
Пример #8
0
void BrowsingContext::GetOpener(JSContext* aCx,
                                JS::MutableHandle<JS::Value> aOpener,
                                ErrorResult& aError) const {
  RefPtr<BrowsingContext> opener = GetOpener();
  if (!opener) {
    aOpener.setNull();
    return;
  }

  if (!ToJSValue(aCx, WindowProxyHolder(opener), aOpener)) {
    aError.NoteJSContextException(aCx);
  }
}
Пример #9
0
bool
EventListenerInfo::GetJSVal(JSContext* aCx,
                            Maybe<JSAutoRealm>& aAr,
                            JS::MutableHandle<JS::Value> aJSVal)
{
  if (mScriptedListener) {
    aJSVal.setObject(*mScriptedListener);
    aAr.emplace(aCx, mScriptedListener);
    return true;
  }

  aJSVal.setNull();
  return false;
}
Пример #10
0
NS_IMETHODIMP
MmsMessage::GetDeliveryInfo(JSContext* aCx, JS::MutableHandle<JS::Value> aDeliveryInfo)
{
  // TODO Bug 850525 It'd be better to depend on the delivery of MmsMessage
  // to return a more correct value. Ex, if .delivery = 'received', we should
  // also make .deliveryInfo = null, since the .deliveryInfo is useless.
  uint32_t length = mDeliveryInfo.Length();
  if (length == 0) {
    aDeliveryInfo.setNull();
    return NS_OK;
  }

  if (!ToJSValue(aCx, mDeliveryInfo, aDeliveryInfo)) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  return NS_OK;
}
Пример #11
0
nsresult
KeyPath::ToJSVal(JSContext* aCx, JS::MutableHandle<JS::Value> aValue) const
{
    if (IsArray()) {
        uint32_t len = mStrings.Length();
        JS::Rooted<JSObject*> array(aCx, JS_NewArrayObject(aCx, len));
        if (!array) {
            IDB_WARNING("Failed to make array!");
            return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
        }

        for (uint32_t i = 0; i < len; ++i) {
            JS::Rooted<JS::Value> val(aCx);
            nsString tmp(mStrings[i]);
            if (!xpc::StringToJsval(aCx, tmp, &val)) {
                IDB_REPORT_INTERNAL_ERR();
                return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
            }

            if (!JS_SetElement(aCx, array, i, val)) {
                IDB_REPORT_INTERNAL_ERR();
                return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
            }
        }

        aValue.setObject(*array);
        return NS_OK;
    }

    if (IsString()) {
        nsString tmp(mStrings[0]);
        if (!xpc::StringToJsval(aCx, tmp, aValue)) {
            IDB_REPORT_INTERNAL_ERR();
            return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
        }
        return NS_OK;
    }

    aValue.setNull();
    return NS_OK;
}
Пример #12
0
void
nsHistory::GetState(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
                    ErrorResult& aRv) const
{
  nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mInnerWindow));
  if (!win) {
    aRv.Throw(NS_ERROR_NOT_AVAILABLE);
    return;
  }

  if (!win->HasActiveDocument()) {
    aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
    return;
  }

  nsCOMPtr<nsIDocument> doc =
    do_QueryInterface(win->GetExtantDoc());
  if (!doc) {
    aRv.Throw(NS_ERROR_NOT_AVAILABLE);
    return;
  }

  nsCOMPtr<nsIVariant> variant;
  doc->GetStateObject(getter_AddRefs(variant));

  if (variant) {
    aRv = variant->GetAsJSVal(aResult);

    if (aRv.Failed()) {
      return;
    }

    if (!JS_WrapValue(aCx, aResult)) {
      aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
    }

    return;
  }

  aResult.setNull();
}
Пример #13
0
NS_IMETHODIMP
PlaceInfo::GetVisits(JSContext* aContext,
                     JS::MutableHandle<JS::Value> _visits)
{
  // If the visits data was not provided, return null rather
  // than an empty array to distinguish this case from the case
  // of a place without any visit.
  if (!mVisitsAvailable) {
    _visits.setNull();
    return NS_OK;
  }

  // TODO bug 625913 when we use this in situations that have more than one
  // visit here, we will likely want to make this cache the value.
  JS::Rooted<JSObject*> visits(aContext,
                               JS_NewArrayObject(aContext, 0));
  NS_ENSURE_TRUE(visits, NS_ERROR_OUT_OF_MEMORY);

  JS::Rooted<JSObject*> global(aContext, JS::CurrentGlobalOrNull(aContext));
  NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED);

  nsCOMPtr<nsIXPConnect> xpc = mozilla::services::GetXPConnect();

  for (VisitsArray::size_type idx = 0; idx < mVisits.Length(); idx++) {
    nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
    nsresult rv = xpc->WrapNative(aContext, global, mVisits[idx],
                                  NS_GET_IID(mozIVisitInfo),
                                  getter_AddRefs(wrapper));
    NS_ENSURE_SUCCESS(rv, rv);

    JS::Rooted<JSObject*> jsobj(aContext, wrapper->GetJSObject());
    NS_ENSURE_STATE(jsobj);

    bool rc = JS_SetElement(aContext, visits, idx, jsobj);
    NS_ENSURE_TRUE(rc, NS_ERROR_UNEXPECTED);
  }

  _visits.setObject(*visits);
  return NS_OK;
}