Back to index

lightning-sunbird  0.9+nobinonly
Enumerations | Functions | Variables
nsJSInstallVersion.cpp File Reference
#include "jsapi.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsString.h"
#include "nsIDOMInstallVersion.h"
#include "nsIScriptNameSpaceManager.h"
#include "nsIComponentManager.h"
#include "nsDOMCID.h"
#include "nsSoftwareUpdateIIDs.h"

Go to the source code of this file.

Enumerations

enum  InstallVersion_slots { INSTALLVERSION_MAJOR = -1, INSTALLVERSION_MINOR = -2, INSTALLVERSION_RELEASE = -3, INSTALLVERSION_BUILD = -4 }

Functions

 GetInstallVersionProperty (JSContext *cx, JSObject *obj, jsval id, jsval *vp)
 SetInstallVersionProperty (JSContext *cx, JSObject *obj, jsval id, jsval *vp)
 EnumerateInstallVersion (JSContext *cx, JSObject *obj)
 ResolveInstallVersion (JSContext *cx, JSObject *obj, jsval id)
 FinalizeInstallVersion (JSContext *cx, JSObject *obj)
void ConvertJSValToStr (nsString &aString, JSContext *aContext, jsval aValue)
void ConvertStrToJSVal (const nsString &aProp, JSContext *aContext, jsval *aReturn)
PRBool ConvertJSValToBool (PRBool *aProp, JSContext *aContext, jsval aValue)
PRBool ConvertJSValToObj (nsISupports **aSupports, REFNSIID aIID, JSClass *aClass, JSContext *aContext, jsval aValue)
void ConvertJSvalToVersionString (nsString &versionString, JSContext *cx, jsval *argument)
 InstallVersionInit (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 InstallVersionToString (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 InstallVersionCompareTo (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 InstallVersion (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
nsresult InitInstallVersionClass (JSContext *jscontext, JSObject *global, void **prototype)
nsresult NS_InitInstallVersionClass (nsIScriptContext *aContext, void **aPrototype)
nsresult NS_NewScriptInstallVersion (nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)

Variables

JSClass InstallVersionClass
static JSPropertySpec InstallVersionProperties []
static JSFunctionSpec InstallVersionMethods []
static JSConstDoubleSpec version_constants []

Enumeration Type Documentation

Enumerator:
INSTALLVERSION_MAJOR 
INSTALLVERSION_MINOR 
INSTALLVERSION_RELEASE 
INSTALLVERSION_BUILD 

Definition at line 110 of file nsJSInstallVersion.cpp.


Function Documentation

PRBool ConvertJSValToBool ( PRBool aProp,
JSContext aContext,
jsval  aValue 
)

Definition at line 276 of file nsJSInstall.cpp.

{
  JSBool temp;
  if(JSVAL_IS_BOOLEAN(aValue) && JS_ValueToBoolean(aContext, aValue, &temp))
  {
    *aProp = (PRBool)temp;
  }
  else
  {
    JS_ReportError(aContext, "Parameter must be a boolean");
    return JS_FALSE;
  }

  return JS_TRUE;
}
PRBool ConvertJSValToObj ( nsISupports **  aSupports,
REFNSIID  aIID,
JSClass aClass,
JSContext aContext,
jsval  aValue 
)

Definition at line 294 of file nsJSInstall.cpp.

{
  if (JSVAL_IS_NULL(aValue)) {
    *aSupports = nsnull;
    return JS_TRUE;
  }
  if (!JSVAL_IS_OBJECT(aValue)) {
    JS_ReportError(aContext, "Parameter must be an object");
    return JS_FALSE;
  }
  JSObject* jsobj = JSVAL_TO_OBJECT(aValue);
  JSClass* jsclass = JS_GetClass(aContext, jsobj);
  if (!jsclass ||
      !(jsclass->flags & JSCLASS_HAS_PRIVATE) ||
      !(jsclass->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS)) {
    JS_ReportError(aContext,
                   "Parameter isn't an object that implements nsISupports");
    return JS_FALSE;
  }
  if (!JS_InstanceOf(aContext,
                     jsobj,
                     aClass,
                     nsnull))
  {
    char buf[128];
    sprintf(buf, "Parameter isn't an instance of type %s", aClass->name);
    JS_ReportError(aContext, buf);
    return JS_FALSE;
  }
  nsISupports *supports = (nsISupports *)JS_GetPrivate(aContext, jsobj);
  if (!supports) {
    NS_ERROR("This should not happen.");
    JS_ReportError(aContext,
                   "JSObject has JSCLASS_PRIVATE_IS_NSISUPPORTS flag but has a null private slot, please file a bug.");
    return JS_FALSE;
  }
  if (NS_FAILED(supports->QueryInterface(aIID, (void **)aSupports))) {
    char buf[128];
    sprintf(buf, "Parameter must be of type %s", aClass->name);
    JS_ReportError(aContext, buf);
    return JS_FALSE;
  }

  return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ConvertJSValToStr ( nsString aString,
JSContext aContext,
jsval  aValue 
)

Definition at line 250 of file nsJSInstall.cpp.

{
  JSString *jsstring;

  if ( !JSVAL_IS_NULL(aValue) &&
       (jsstring = JS_ValueToString(aContext, aValue)) != nsnull)
  {
    aString.Assign(NS_REINTERPRET_CAST(const PRUnichar*, JS_GetStringChars(jsstring)));
  }
  else
  {
    aString.Truncate();
  }
}
void ConvertJSvalToVersionString ( nsString versionString,
JSContext cx,
jsval argument 
)
void ConvertStrToJSVal ( const nsString aProp,
JSContext aContext,
jsval aReturn 
)

Definition at line 267 of file nsJSInstall.cpp.

{
  JSString *jsstring = JS_NewUCStringCopyN(aContext, NS_REINTERPRET_CAST(const jschar*, aProp.get()), aProp.Length());
  // set the return value
  *aReturn = STRING_TO_JSVAL(jsstring);
}

Definition at line 297 of file nsJSInstallVersion.cpp.

{
  return JS_TRUE;
}
FinalizeInstallVersion ( JSContext cx,
JSObject obj 
)

Definition at line 274 of file nsJSInstallVersion.cpp.

{
  nsISupports *nativeThis = (nsISupports*)JS_GetPrivate(cx, obj);

  if (nsnull != nativeThis) {
    // get the js object
    nsIScriptObjectOwner *owner = nsnull;
    if (NS_OK == nativeThis->QueryInterface(NS_GET_IID(nsIScriptObjectOwner), 
                                            (void**)&owner)) {
      owner->SetScriptObject(nsnull);
      NS_RELEASE(owner);
    }
    
    // The addref was part of JSObject construction
    NS_RELEASE(nativeThis);
  }
}

Here is the call graph for this function:

GetInstallVersionProperty ( JSContext cx,
JSObject obj,
jsval  id,
jsval vp 
)

Definition at line 122 of file nsJSInstallVersion.cpp.

{
  nsIDOMInstallVersion *a = (nsIDOMInstallVersion*)JS_GetPrivate(cx, obj);

  // If there's no private data, this must be the prototype, so ignore
  if (nsnull == a) {
    return JS_TRUE;
  }

  if (JSVAL_IS_INT(id)) {
    switch(JSVAL_TO_INT(id)) {
      case INSTALLVERSION_MAJOR:
      {
        PRInt32 prop;
        if (NS_OK == a->GetMajor(&prop)) {
          *vp = INT_TO_JSVAL(prop);
        }
        else {
          return JS_FALSE;
        }
        break;
      }
      case INSTALLVERSION_MINOR:
      {
        PRInt32 prop;
        if (NS_OK == a->GetMinor(&prop)) {
          *vp = INT_TO_JSVAL(prop);
        }
        else {
          return JS_FALSE;
        }
        break;
      }
      case INSTALLVERSION_RELEASE:
      {
        PRInt32 prop;
        if (NS_OK == a->GetRelease(&prop)) {
          *vp = INT_TO_JSVAL(prop);
        }
        else {
          return JS_FALSE;
        }
        break;
      }
      case INSTALLVERSION_BUILD:
      {
        PRInt32 prop;
        if (NS_OK == a->GetBuild(&prop)) {
          *vp = INT_TO_JSVAL(prop);
        }
        else {
          return JS_FALSE;
        }
        break;
      }
    }
  }

  return JS_TRUE;
}

Here is the call graph for this function:

nsresult InitInstallVersionClass ( JSContext jscontext,
JSObject global,
void **  prototype 
)

Definition at line 583 of file nsJSInstallVersion.cpp.

{
  JSObject *proto = nsnull;

  if (prototype != nsnull)
    *prototype = nsnull;

  proto = JS_InitClass(jscontext,     // context
                       global,        // global object
                       nsnull,  // parent proto 
                       &InstallVersionClass,      // JSClass
                       InstallVersion,            // JSNative ctor
                       0,             // ctor args
                       InstallVersionProperties,  // proto props
                       InstallVersionMethods,     // proto funcs
                       nsnull,        // ctor props (static)
                       nsnull);       // ctor funcs (static)
  
  if (nsnull == proto)
      return NS_ERROR_FAILURE;
  
  
  if ( PR_FALSE == JS_DefineConstDoubles(jscontext, proto, version_constants) )
            return NS_ERROR_FAILURE;
  
  if (prototype != nsnull)
      *prototype = proto;
  
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

InstallVersion ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
)

Definition at line 552 of file nsJSInstallVersion.cpp.

{
  nsresult result;
  
  nsIDOMInstallVersion *nativeThis;
  nsIScriptObjectOwner *owner = nsnull;

  static NS_DEFINE_IID(kInstallVersion_CID, NS_SoftwareUpdateInstallVersion_CID);

  result = CallCreateInstance(kInstallVersion_CID, &nativeThis);
  if (NS_FAILED(result)) return JS_FALSE;

            
  result = nativeThis->QueryInterface(NS_GET_IID(nsIScriptObjectOwner),
                                      (void **)&owner);
  if (NS_FAILED(result)) {
    NS_RELEASE(nativeThis);
    return JS_FALSE;
  }

  owner->SetScriptObject((void *)obj);
  JS_SetPrivate(cx, obj, nativeThis);

  NS_RELEASE(owner);
   
  jsval ignore;
  InstallVersionInit(cx, obj, argc, argv, &ignore);

  return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

InstallVersionCompareTo ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
)

Definition at line 396 of file nsJSInstallVersion.cpp.

{
  nsIDOMInstallVersion *nativeThis =
    (nsIDOMInstallVersion*)JS_GetInstancePrivate(cx, obj, &InstallVersionClass,
                                                 argv);
  if (!nativeThis)
    return JS_FALSE;

  PRInt32                 nativeRet;
  nsString                b0str;
  PRInt32                 b0int;
  PRInt32                 b1int;
  PRInt32                 b2int;
  PRInt32                 b3int;

  *rval = JSVAL_NULL;

  // If there's no private data, this must be the prototype, so ignore
  if (nsnull == nativeThis) {
    return JS_TRUE;
  }

  if(argc >= 4)
  {
    //  public int CompareTo(int    major,
    //                       int    minor,
    //                       int    release,
    //                       int    build);

    if(!JSVAL_IS_INT(argv[0]))
    {
        JS_ReportError(cx, "1st parameter must be a number");
        return JS_FALSE;
    }
    else if(!JSVAL_IS_INT(argv[1]))
    {
        JS_ReportError(cx, "2nd parameter must be a number");
        return JS_FALSE;
    }
    else if(!JSVAL_IS_INT(argv[2]))
    {
        JS_ReportError(cx, "3rd parameter must be a number");
        return JS_FALSE;
    }
    else if(!JSVAL_IS_INT(argv[3]))
    {
        JS_ReportError(cx, "4th parameter must be a number");
        return JS_FALSE;
    }

    b0int = JSVAL_TO_INT(argv[0]);
    b1int = JSVAL_TO_INT(argv[1]);
    b2int = JSVAL_TO_INT(argv[2]);
    b3int = JSVAL_TO_INT(argv[3]);

    if(NS_OK != nativeThis->CompareTo(b0int, b1int, b2int, b3int, &nativeRet))
    {
      return JS_FALSE;
    }

    *rval = INT_TO_JSVAL(nativeRet);
  }
  else if(argc >= 1)
  {
     //   public int AddDirectory(String version);  --OR--  VersionInfo version

    if(JSVAL_IS_OBJECT(argv[0]))
    {
        nsCOMPtr<nsIDOMInstallVersion> versionObj;

        if(JS_FALSE == ConvertJSValToObj(getter_AddRefs(versionObj),
                                         NS_GET_IID(nsIDOMInstallVersion),
                                         &InstallVersionClass,
                                         cx,
                                         argv[0]))
        {
          return JS_FALSE;
        }

        if (!versionObj)
        {
          JS_ReportError(cx, "Function compareTo expects a non null object.");
          return JS_FALSE;
        }

        if(NS_OK != nativeThis->CompareTo(versionObj, &nativeRet))
        {
          return JS_FALSE;
        }
    }
    else
    {
        ConvertJSValToStr(b0str, cx, argv[0]);

        if(NS_OK != nativeThis->CompareTo(b0str, &nativeRet))
        {
          return JS_FALSE;
        }
    }

    *rval = INT_TO_JSVAL(nativeRet);
  }
  else
  {
    JS_ReportError(cx, "Function compareTo requires 4 parameters");
    return JS_FALSE;
  }

  return JS_TRUE;
}

Here is the call graph for this function:

InstallVersionInit ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
)

Definition at line 317 of file nsJSInstallVersion.cpp.

{
  nsIDOMInstallVersion *nativeThis =
    (nsIDOMInstallVersion*)JS_GetInstancePrivate(cx, obj, &InstallVersionClass,
                                                 argv);
  if (!nativeThis)
    return JS_FALSE;

  nsAutoString b0;

  *rval = JSVAL_NULL;

  // If there's no private data, this must be the prototype, so ignore
  if (nsnull == nativeThis) {
    return JS_TRUE;
  }

  if (argc == 1) 
  {
    JSString *jsstring;
    if ((jsstring = JS_ValueToString(cx, argv[0])) != nsnull) {
      b0.Assign(NS_REINTERPRET_CAST(const PRUnichar*,
                                    JS_GetStringChars(jsstring)));
    }
  }
  else 
  {
      b0.AssignLiteral("0.0.0.0");
  }
    
  if (NS_OK != nativeThis->Init(b0)) 
        return JS_FALSE;
  
  *rval = JSVAL_VOID;

  return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

InstallVersionToString ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
)

Definition at line 360 of file nsJSInstallVersion.cpp.

{
  nsIDOMInstallVersion *nativeThis =
    (nsIDOMInstallVersion*)JS_GetInstancePrivate(cx, obj, &InstallVersionClass,
                                                 argv);
  if (!nativeThis)
    return JS_FALSE;

  nsAutoString nativeRet;

  *rval = JSVAL_NULL;

  // If there's no private data, this must be the prototype, so ignore
  if (nsnull == nativeThis) {
    return JS_TRUE;
  }

  if (NS_OK != nativeThis->ToString(nativeRet)) {
    return JS_TRUE;
  }

  JSString *jsstring =
    JS_NewUCStringCopyN(cx, NS_REINTERPRET_CAST(const jschar*,
                                                nativeRet.get()),
                        nativeRet.Length());

  // set the return value
  *rval = STRING_TO_JSVAL(jsstring);
  return JS_TRUE;
}

Here is the call graph for this function:

nsresult NS_InitInstallVersionClass ( nsIScriptContext aContext,
void **  aPrototype 
)

Definition at line 617 of file nsJSInstallVersion.cpp.

{
  JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
  JSObject *proto = nsnull;
  JSObject *constructor = nsnull;
  JSObject *global = JS_GetGlobalObject(jscontext);
  jsval vp;

  if ((PR_TRUE != JS_LookupProperty(jscontext, global, "InstallVersion", &vp)) ||
      !JSVAL_IS_OBJECT(vp) ||
      ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
      (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || 
      !JSVAL_IS_OBJECT(vp)) 
  {
    nsresult rv = InitInstallVersionClass(jscontext, global, (void**)&proto);
    if (NS_FAILED(rv)) return rv;
  }
  else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) 
  {
    proto = JSVAL_TO_OBJECT(vp);
  }
  else 
  {
    return NS_ERROR_FAILURE;
  }

  if (aPrototype) 
    *aPrototype = proto;
  
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult NS_NewScriptInstallVersion ( nsIScriptContext aContext,
nsISupports *  aSupports,
nsISupports *  aParent,
void **  aReturn 
)

Definition at line 654 of file nsJSInstallVersion.cpp.

{
  NS_PRECONDITION(nsnull != aContext && nsnull != aSupports &&
                  nsnull != aReturn,
                  "null argument to NS_NewScriptInstallVersion");

  JSObject *proto;
  JSObject *parent;
  nsIScriptObjectOwner *owner;
  JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
  nsresult result = NS_OK;
  nsIDOMInstallVersion *installVersion;

  if (nsnull == aParent) {
    parent = nsnull;
  }
  else if (NS_OK == aParent->QueryInterface(NS_GET_IID(nsIScriptObjectOwner),
                                            (void**)&owner)) {
    if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
      NS_RELEASE(owner);
      return NS_ERROR_FAILURE;
    }
    NS_RELEASE(owner);
  }
  else {
    return NS_ERROR_FAILURE;
  }

  if (NS_OK != NS_InitInstallVersionClass(aContext, (void **)&proto)) {
    return NS_ERROR_FAILURE;
  }

  result = aSupports->QueryInterface(NS_GET_IID(nsIDOMInstallVersion), (void **)&installVersion);
  if (NS_OK != result) {
    return result;
  }

  // create a js object for this class
  *aReturn = JS_NewObject(jscontext, &InstallVersionClass, proto, parent);
  if (nsnull != *aReturn) {
    // connect the native object to the js object
    JS_SetPrivate(jscontext, (JSObject *)*aReturn, installVersion);
  }
  else {
    NS_RELEASE(installVersion);
    return NS_ERROR_FAILURE; 
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ResolveInstallVersion ( JSContext cx,
JSObject obj,
jsval  id 
)

Definition at line 307 of file nsJSInstallVersion.cpp.

{
  return JS_TRUE;
}
SetInstallVersionProperty ( JSContext cx,
JSObject obj,
jsval  id,
jsval vp 
)

Definition at line 188 of file nsJSInstallVersion.cpp.

{
  nsIDOMInstallVersion *a = (nsIDOMInstallVersion*)JS_GetPrivate(cx, obj);

  // If there's no private data, this must be the prototype, so ignore
  if (nsnull == a) {
    return JS_TRUE;
  }

  if (JSVAL_IS_INT(id)) {
    switch(JSVAL_TO_INT(id)) {
      case INSTALLVERSION_MAJOR:
      {
        PRInt32 prop;
        int32 temp;
        if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) {
          prop = (PRInt32)temp;
        }
        else {
          JS_ReportError(cx, "Parameter must be a number");
          return JS_FALSE;
        }
      
        a->SetMajor(prop);
        
        break;
      }
      case INSTALLVERSION_MINOR:
      {
        PRInt32 prop;
        int32 temp;
        if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) {
          prop = (PRInt32)temp;
        }
        else {
          JS_ReportError(cx, "Parameter must be a number");
          return JS_FALSE;
        }
      
        a->SetMinor(prop);
        
        break;
      }
      case INSTALLVERSION_RELEASE:
      {
        PRInt32 prop;
        int32 temp;
        if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) {
          prop = (PRInt32)temp;
        }
        else {
          JS_ReportError(cx, "Parameter must be a number");
          return JS_FALSE;
        }
      
        a->SetRelease(prop);
        
        break;
      }
      case INSTALLVERSION_BUILD:
      {
        PRInt32 prop;
        int32 temp;
        if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) {
          prop = (PRInt32)temp;
        }
        else {
          JS_ReportError(cx, "Parameter must be a number");
          return JS_FALSE;
        }
      
        a->SetBuild(prop);
        
        break;
      }
    }
  }

  return JS_TRUE;
}

Here is the call graph for this function:


Variable Documentation

Initial value:
 
{
  {"init",          InstallVersionInit,       1},
  {"toString",      InstallVersionToString,   0},
  {"compareTo",     InstallVersionCompareTo,  1},
  {0}
}

Definition at line 524 of file nsJSInstallVersion.cpp.

Initial value:

Definition at line 511 of file nsJSInstallVersion.cpp.

Initial value:
 
{
    { nsIDOMInstallVersion::EQUAL,                  "EQUAL"              },
    { nsIDOMInstallVersion::BLD_DIFF,               "BLD_DIFF"           },
    { nsIDOMInstallVersion::BLD_DIFF_MINUS,         "BLD_DIFF_MINUS"     },
    { nsIDOMInstallVersion::REL_DIFF,               "REL_DIFF"           },
    { nsIDOMInstallVersion::REL_DIFF_MINUS,         "REL_DIFF_MINUS"     },
    { nsIDOMInstallVersion::MINOR_DIFF,             "MINOR_DIFF"         },
    { nsIDOMInstallVersion::MINOR_DIFF_MINUS,       "MINOR_DIFF_MINUS"   },
    { nsIDOMInstallVersion::MAJOR_DIFF,             "MAJOR_DIFF"         },
    { nsIDOMInstallVersion::MAJOR_DIFF_MINUS,       "MAJOR_DIFF_MINUS"   },
    {0}
}

Definition at line 532 of file nsJSInstallVersion.cpp.