Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
nsJSWinReg.cpp File Reference
#include "jsapi.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsString.h"
#include "nsInstall.h"
#include "nsWinReg.h"
#include "nsJSWinReg.h"

Go to the source code of this file.

Functions

static void PR_CALLBACK WinRegCleanup (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)
 WinRegSetRootKey (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 WinRegKeyExists (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 WinRegValueExists (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 WinRegIsKeyWritable (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 WinRegCreateKey (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 WinRegDeleteKey (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 WinRegDeleteValue (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 WinRegSetValueString (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 WinRegGetValueString (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 WinRegEnumValueNames (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 WinRegEnumKeys (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 WinRegSetValueNumber (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 WinRegGetValueNumber (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 WinRegSetValue (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 WinRegGetValue (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 WinReg (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
PRInt32 InitWinRegPrototype (JSContext *jscontext, JSObject *global, JSObject **winRegPrototype)

Variables

JSClass WinRegClass
static JSConstDoubleSpec winreg_constants []
static JSFunctionSpec WinRegMethods []

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;
}

Here is the call 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();
  }
}

Here is the call graph for this function:

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);
}

Here is the call graph for this function:

PRInt32 InitWinRegPrototype ( JSContext jscontext,
JSObject global,
JSObject **  winRegPrototype 
)

Definition at line 725 of file nsJSWinReg.cpp.

{
  *winRegPrototype = JS_InitClass( jscontext,         // context
                                  global,            // global object
                                  nsnull,            // parent proto 
                                  &WinRegClass,      // JSClass
                                  nsnull,            // JSNative ctor
                                  0,                 // ctor args
                                  nsnull,            // proto props
                                  nsnull,            // proto funcs
                                  nsnull,            // ctor props (static)
                                  WinRegMethods);    // ctor funcs (static)

  if(nsnull == *winRegPrototype) 
  {
    return NS_ERROR_FAILURE;
  }

  if(PR_FALSE == JS_DefineConstDoubles(jscontext, *winRegPrototype, winreg_constants))
    return NS_ERROR_FAILURE;

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 686 of file nsJSWinReg.cpp.

{
  return JS_FALSE;
}
static void PR_CALLBACK WinRegCleanup ( JSContext cx,
JSObject obj 
) [static]

Definition at line 62 of file nsJSWinReg.cpp.

{
    nsWinReg *nativeThis = (nsWinReg*)JS_GetPrivate(cx, obj);
    delete nativeThis;
}

Here is the call graph for this function:

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

Definition at line 240 of file nsJSWinReg.cpp.

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

  PRInt32 nativeRet;
  nsAutoString b0;
  nsAutoString b1;

  *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);

  if(argc >= 2)                             
  {
    //  public int createKey ( String subKey,
    //                         String className);

    ConvertJSValToStr(b0, cx, argv[0]);
    ConvertJSValToStr(b1, cx, argv[1]);

    if(NS_OK == nativeThis->CreateKey(b0, b1, &nativeRet))
    {
      *rval = INT_TO_JSVAL(nativeRet);
    }
  }
  else
  {
    JS_ReportWarning(cx, "WinReg.CreateKey() parameters error");
  }

  return JS_TRUE;
}

Here is the call graph for this function:

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

Definition at line 278 of file nsJSWinReg.cpp.

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

  PRInt32 nativeRet;
  nsAutoString b0;

  *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);

  if(argc >= 1)                             
  {
    //  public int deleteKey ( String subKey);

    ConvertJSValToStr(b0, cx, argv[0]);

    if(NS_OK == nativeThis->DeleteKey(b0, &nativeRet))
    {
      *rval = INT_TO_JSVAL(nativeRet);
    }
  }
  else
  {
    JS_ReportWarning(cx, "WinReg.DeleteKey() parameters error");
  }

  return JS_TRUE;
}

Here is the call graph for this function:

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

Definition at line 314 of file nsJSWinReg.cpp.

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

  PRInt32 nativeRet;
  nsString b0;
  nsString b1;

  *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);

  if(argc >= 2)                             
  {
    //  public int deleteValue ( String subKey,
    //                           String valueName);

    ConvertJSValToStr(b0, cx, argv[0]);
    ConvertJSValToStr(b1, cx, argv[1]);

    if(NS_OK == nativeThis->DeleteValue(b0, b1, &nativeRet))
    {
      *rval = INT_TO_JSVAL(nativeRet);
    }
  }
  else
  {
    JS_ReportWarning(cx, "WinReg.DeleteValue() parameters error");
  }

  return JS_TRUE;
}

Here is the call graph for this function:

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

Definition at line 476 of file nsJSWinReg.cpp.

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

  nsAutoString   nativeRet;
  nsAutoString   b0;
  int32          b1;

  *rval = JSVAL_NULL;

  if(argc >= 2)                             
  {
    //  public String enumKeys ( String subkey,
    //                           Int    index);

    ConvertJSValToStr(b0, cx, argv[0]);

    if(JS_ValueToInt32(cx, argv[1], &b1))
    {
      if ( NS_OK ==  nativeThis->EnumKeys(b0, b1, nativeRet) )
      {
          ConvertStrToJSVal(nativeRet, cx, rval);
      }
    }
    else
    {
      JS_ReportWarning(cx, "WinReg.enumKeys() - Parameter 2 must be a number");
    }
  }
  else
  {
    JS_ReportWarning(cx, "WinReg.enumKeys() - Too few parameters");
  }

  return JS_TRUE;
}

Here is the call graph for this function:

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

Definition at line 431 of file nsJSWinReg.cpp.

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

  nsAutoString   nativeRet;
  nsAutoString   b0;
  int32          b1;

  *rval = JSVAL_NULL;

  if(argc >= 2)                             
  {
    //  public String enumValueNames ( String subkey,
    //                                 Int index);

    ConvertJSValToStr(b0, cx, argv[0]);

    if(JS_ValueToInt32(cx, argv[1], &b1))
    {
      if ( NS_OK == nativeThis->EnumValueNames(b0, b1, nativeRet) )
      {
          ConvertStrToJSVal(nativeRet, cx, rval);
      }
    }
    else  
    {
      JS_ReportWarning(cx, "WinReg.enumValueNames - Parameter 2 must be a number");
    }
  }
  else
  {
    JS_ReportWarning(cx, "WinReg.enumValueNames() - Too few parameters");
  }

  return JS_TRUE;
}

Here is the call graph for this function:

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

Definition at line 647 of file nsJSWinReg.cpp.

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

  nsWinRegValue *nativeRet;
  nsAutoString  b0;
  nsAutoString  b1;

  *rval = JSVAL_NULL;

  if(argc >= 2)                             
  {
    //  public int getValue ( String subKey,
    //                        String valueName);

    ConvertJSValToStr(b0, cx, argv[0]);
    ConvertJSValToStr(b1, cx, argv[1]);

    if(NS_OK == nativeThis->GetValue(b0, b1, &nativeRet))
    {
      *rval = INT_TO_JSVAL(nativeRet);
    }
  }
  else
  {
    JS_ReportWarning(cx, "WinReg.GetValue() parameters error");
  }

  return JS_TRUE;
}

Here is the call graph for this function:

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

Definition at line 565 of file nsJSWinReg.cpp.

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

  PRInt32      nativeRet;
  nsAutoString b0;
  nsAutoString b1;

  *rval = JSVAL_NULL;

  if(argc >= 2)                             
  {
    //  public int getValueNumber ( String subKey,
    //                              Number valueName);

    ConvertJSValToStr(b0, cx, argv[0]);
    ConvertJSValToStr(b1, cx, argv[1]);

    if(NS_OK == nativeThis->GetValueNumber(b0, b1, &nativeRet))
    {
      *rval = INT_TO_JSVAL(nativeRet);
    }
  }
  else
  {
    JS_ReportWarning(cx, "WinReg.GetValueNumber() parameters error");
  }

  return JS_TRUE;
}

Here is the call graph for this function:

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

Definition at line 393 of file nsJSWinReg.cpp.

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

  nsString     nativeRet;
  nsAutoString b0;
  nsAutoString b1;

  *rval = JSVAL_NULL;

  if(argc >= 2)                             
  {
    //  public string getValueString ( String subKey,
    //                              String valueName);

    ConvertJSValToStr(b0, cx, argv[0]);
    ConvertJSValToStr(b1, cx, argv[1]);

    if(NS_OK == nativeThis->GetValueString(b0, b1, &nativeRet))
    {
      ConvertStrToJSVal(nativeRet, cx, rval);
    }
  }
  else
  {
    JS_ReportWarning(cx, "WinReg.GetValueString() parameters error");
  }

  return JS_TRUE;
}

Here is the call graph for this function:

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

Definition at line 205 of file nsJSWinReg.cpp.

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

  PRInt32 nativeRet;
  nsAutoString b0;

  *rval = JSVAL_FALSE;

  if(argc >= 1)
  {
    //  public boolean isKeyWritable ( String subKey );

    ConvertJSValToStr(b0, cx, argv[0]);

    if(NS_OK == nativeThis->IsKeyWritable(b0, &nativeRet))
    {
      *rval = BOOLEAN_TO_JSVAL(nativeRet);
    }
  }
  else
  {
    JS_ReportWarning(cx, "WinReg.IsKeyWritable() parameters error");
  }

  return JS_TRUE;
}

Here is the call graph for this function:

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

Definition at line 128 of file nsJSWinReg.cpp.

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

  PRBool nativeRet;
  nsAutoString b0;

  *rval = JSVAL_FALSE;

  if(argc >= 1)
  {
    //  public boolean keyExists ( String subKey );

    ConvertJSValToStr(b0, cx, argv[0]);

    if(NS_OK == nativeThis->KeyExists(b0, &nativeRet))
    {
      *rval = BOOLEAN_TO_JSVAL(nativeRet);
    }
    else
    {
      NS_WARNING("WinReg.KeyExists() internal error");
    }
  }
  else
  {
    JS_ReportWarning(cx, "WinReg.KeyExists() parameters error");
  }

  return JS_TRUE;
}

Here is the call graph for this function:

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

Definition at line 92 of file nsJSWinReg.cpp.

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

  PRInt32  b0;

  *rval = JSVAL_NULL;

  if(argc >= 1)
  {
    //  public void setRootKey(PRInt32 key);
    if(JS_ValueToInt32(cx, argv[0], (int32 *)&b0))
    {
      nativeThis->SetRootKey(b0);
    }
    else
    {
      JS_ReportWarning(cx, "Parameter must be a number");
    }
  }
  else
  {
    JS_ReportWarning(cx, "Function SetRootKey requires 1 parameters");
  }

  return JS_TRUE;
}

Here is the call graph for this function:

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

Definition at line 603 of file nsJSWinReg.cpp.

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

  nsAutoString b0;
  nsAutoString b1;

  *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);

  if(argc >= 3)
  {
    //  public int setValue ( String        subKey,
    //                        String        valueName,
    //                        nsWinRegItem  *value);

    ConvertJSValToStr(b0, cx, argv[0]);
    ConvertJSValToStr(b1, cx, argv[1]);

    // fix: this parameter is an object, not a string.
    // A way needs to be figured out to convert the JSVAL to this object type
//    ConvertJSValToStr(b2, cx, argv[2]);

//    if(NS_OK != nativeThis->SetValue(b0, b1, b2, &nativeRet))
//    {
//      return JS_FALSE;
//    }

//    *rval = INT_TO_JSVAL(nativeRet);
  }
  else
  {
    JS_ReportWarning(cx, "WinReg.SetValue() parameters error");
  }

  return JS_TRUE;
}

Here is the call graph for this function:

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

Definition at line 521 of file nsJSWinReg.cpp.

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

  PRInt32 nativeRet;
  nsAutoString b0;
  nsAutoString b1;
  int32        ib2;

  *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);

  if(argc >= 3)
  {
    //  public int setValueNumber ( String subKey,
    //                              String valueName,
    //                              Number value);

    ConvertJSValToStr(b0, cx, argv[0]);
    ConvertJSValToStr(b1, cx, argv[1]);

    if(!JS_ValueToInt32(cx, argv[2], &ib2))
    {
      JS_ReportWarning(cx, "Parameter 3 must be a number");
    }
    else if(NS_OK == nativeThis->SetValueNumber(b0, b1, ib2, &nativeRet))
    {
      *rval = INT_TO_JSVAL(nativeRet);
    }
  }
  else
  {
    JS_ReportWarning(cx, "WinReg.SetValueNumber() parameters error");
  }

  return JS_TRUE;
}

Here is the call graph for this function:

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

Definition at line 352 of file nsJSWinReg.cpp.

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

  PRInt32 nativeRet;
  nsAutoString b0;
  nsAutoString b1;
  nsAutoString b2;

  *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);

  if(argc >= 3)
  {
    //  public int setValueString ( String subKey,
    //                              String valueName,
    //                              String value);

    ConvertJSValToStr(b0, cx, argv[0]);
    ConvertJSValToStr(b1, cx, argv[1]);
    ConvertJSValToStr(b2, cx, argv[2]);

    if(NS_OK == nativeThis->SetValueString(b0, b1, b2, &nativeRet))
    {
      *rval = INT_TO_JSVAL(nativeRet);
    }
  }
  else
  {
    JS_ReportWarning(cx, "WinReg.SetValueString() parameters error");
  }

  return JS_TRUE;
}

Here is the call graph for this function:

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

Definition at line 167 of file nsJSWinReg.cpp.

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

  PRBool nativeRet;
  nsAutoString b0;
  nsAutoString b1;

  *rval = JSVAL_FALSE;

  if(argc >= 2)
  {
    //  public boolean valueExists ( String subKey,
    //                           String value );

    ConvertJSValToStr(b0, cx, argv[0]);
    ConvertJSValToStr(b1, cx, argv[1]);

    if(NS_OK == nativeThis->ValueExists(b0, b1, &nativeRet))
    {
      *rval = BOOLEAN_TO_JSVAL(nativeRet);
    }
  }
  else
  {
    JS_ReportWarning(cx, "WinReg.ValueExists() parameters error");
  }

  return JS_TRUE;
}

Here is the call graph for this function:


Variable Documentation

Initial value:
 
{
    { nsWinReg::NS_HKEY_CLASSES_ROOT,        "HKEY_CLASSES_ROOT"            },
    { nsWinReg::NS_HKEY_CURRENT_USER,        "HKEY_CURRENT_USER"            },
    { nsWinReg::NS_HKEY_LOCAL_MACHINE,       "HKEY_LOCAL_MACHINE"           },
    { nsWinReg::NS_HKEY_USERS,               "HKEY_USERS"                   },
    {0}
}

Definition at line 692 of file nsJSWinReg.cpp.

Initial value:
 
{
  {"setRootKey",                WinRegSetRootKey,               1},
  {"keyExists",                 WinRegKeyExists,                1},
  {"valueExists",               WinRegValueExists,              2},
  {"isKeyWritable",             WinRegIsKeyWritable,            1},
  {"createKey",                 WinRegCreateKey,                2},
  {"deleteKey",                 WinRegDeleteKey,                1},
  {"deleteValue",               WinRegDeleteValue,              2},
  {"setValueString",            WinRegSetValueString,           3},
  {"getValueString",            WinRegGetValueString,           2},
  {"setValueNumber",            WinRegSetValueNumber,           3},
  {"getValueNumber",            WinRegGetValueNumber,           2},
  {"setValue",                  WinRegSetValue,                 3},
  {"getValue",                  WinRegGetValue,                 2},
  {"enumKeys",                  WinRegEnumKeys,                 2},
  {"enumValueNames",            WinRegEnumValueNames,           2},
  {0}
}

Definition at line 704 of file nsJSWinReg.cpp.