Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
NS_IMETHODIMP
SmsFilter::SetThreadId(JSContext* aCx, JS::Handle<JS::Value> aThreadId)
{
  if (aThreadId.isNull()) {
    mData.threadId() = 0;
    return NS_OK;
  }

  if (!aThreadId.isNumber()) {
    return NS_ERROR_INVALID_ARG;
  }

  double number = aThreadId.toNumber();
  uint64_t integer = static_cast<uint64_t>(number);
  if (integer == 0 || integer != number) {
    return NS_ERROR_INVALID_ARG;
  }
  mData.threadId() = integer;

  return NS_OK;
}
Exemplo n.º 4
0
NS_IMETHODIMP
TCPSocketParent::SendEvent(const nsAString& aType, JS::Handle<JS::Value> aDataVal,
                           const nsAString& aReadyState, JSContext* aCx)
{
  if (!mIPCOpen) {
    NS_WARNING("Dropping callback due to no IPC connection");
    return NS_OK;
  }

  CallbackData data;
  if (aDataVal.isString()) {
    JSString* jsstr = aDataVal.toString();
    nsAutoJSString str;
    if (!str.init(aCx, jsstr)) {
      FireInteralError(this, __LINE__);
      return NS_ERROR_OUT_OF_MEMORY;
    }
    data = SendableData(str);

  } else if (aDataVal.isUndefined() || aDataVal.isNull()) {
    data = mozilla::void_t();

  } else if (aDataVal.isObject()) {
    JS::Rooted<JSObject *> obj(aCx, &aDataVal.toObject());
    if (JS_IsArrayBufferObject(obj)) {
      FallibleTArray<uint8_t> fallibleArr;
      uint32_t errLine = 0;
      do {
          JS::AutoCheckCannotGC nogc;
          uint32_t nbytes = JS_GetArrayBufferByteLength(obj);
          uint8_t* buffer = JS_GetArrayBufferData(obj, nogc);
          if (!buffer) {
              errLine = __LINE__;
              break;
          }
          if (!fallibleArr.InsertElementsAt(0, buffer, nbytes, fallible)) {
              errLine = __LINE__;
              break;
          }
      } while (false);

      if (errLine) {
          FireInteralError(this, errLine);
          return NS_ERROR_OUT_OF_MEMORY;
      }

      InfallibleTArray<uint8_t> arr;
      arr.SwapElements(fallibleArr);
      data = SendableData(arr);

    } else {
      nsAutoJSString name;

      JS::Rooted<JS::Value> val(aCx);
      if (!JS_GetProperty(aCx, obj, "name", &val)) {
        NS_ERROR("No name property on supposed error object");
      } else if (val.isString()) {
        if (!name.init(aCx, val.toString())) {
          NS_WARNING("couldn't initialize string");
        }
      }

      data = TCPError(name);
    }
  } else {
    NS_ERROR("Unexpected JS value encountered");
    FireInteralError(this, __LINE__);
    return NS_ERROR_FAILURE;
  }
  mozilla::unused <<
      PTCPSocketParent::SendCallback(nsString(aType), data,
                                     nsString(aReadyState));
  return NS_OK;
}