示例#1
0
bool
SmsRequest::SetSuccessInternal(nsISupports* aObject)
{
    NS_PRECONDITION(!mDone, "mDone shouldn't have been set to true already!");
    NS_PRECONDITION(mError == eNoError, "mError shouldn't have been set!");
    NS_PRECONDITION(mResult == JSVAL_VOID, "mResult shouldn't have been set!");

    JSContext* cx = mScriptContext->GetNativeContext();
    NS_ASSERTION(cx, "Failed to get a context!");

    JSObject* global = mScriptContext->GetNativeGlobal();
    NS_ASSERTION(global, "Failed to get global object!");

    JSAutoRequest ar(cx);
    JSAutoEnterCompartment ac;
    if (!ac.enter(cx, global)) {
        SetError(eInternalError);
        return false;
    }

    RootResult();

    if (NS_FAILED(nsContentUtils::WrapNative(cx, global, aObject, &mResult))) {
        UnrootResult();
        mResult = JSVAL_VOID;
        SetError(eInternalError);
        return false;
    }

    mDone = true;
    return true;
}
示例#2
0
bool
SmsRequest::SetSuccessInternal(nsISupports* aObject)
{
  NS_PRECONDITION(!mDone, "mDone shouldn't have been set to true already!");
  NS_PRECONDITION(!mError, "mError shouldn't have been set!");
  NS_PRECONDITION(mResult == JSVAL_VOID, "mResult shouldn't have been set!");

  nsresult rv;
  nsIScriptContext* sc = GetContextForEventHandlers(&rv);
  if (!sc) {
    SetError(nsISmsRequest::INTERNAL_ERROR);
    return false;
  }

  JSContext* cx = sc->GetNativeContext();    
  NS_ASSERTION(cx, "Failed to get a context!");

  JSObject* global = sc->GetNativeGlobal();
  NS_ASSERTION(global, "Failed to get global object!");

  JSAutoRequest ar(cx);
  JSAutoCompartment ac(cx, global);

  RootResult();

  if (NS_FAILED(nsContentUtils::WrapNative(cx, global, aObject, &mResult))) {
    UnrootResult();
    SetError(nsISmsRequest::INTERNAL_ERROR);
    return false;
  }

  mDone = true;
  return true;
}