Back to index

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

Go to the source code of this file.

Functions

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)
static void PR_CALLBACK WinProfileCleanup (JSContext *cx, JSObject *obj)
 WinProfileGetString (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 WinProfileWriteString (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 WinProfile (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
PRInt32 InitWinProfilePrototype (JSContext *jscontext, JSObject *global, JSObject **winProfilePrototype)

Variables

JSClass WinProfileClass
static JSConstDoubleSpec winprofile_constants []
static JSFunctionSpec WinProfileMethods []

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;
}
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 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);
}
PRInt32 InitWinProfilePrototype ( JSContext jscontext,
JSObject global,
JSObject **  winProfilePrototype 
)

Definition at line 194 of file nsJSWinProfile.cpp.

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

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

  if(PR_FALSE == JS_DefineConstDoubles(jscontext, *winProfilePrototype, winprofile_constants))
    return NS_ERROR_FAILURE;

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 173 of file nsJSWinProfile.cpp.

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

Definition at line 81 of file nsJSWinProfile.cpp.

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

Here is the call graph for this function:

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

Definition at line 94 of file nsJSWinProfile.cpp.

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

  nsString     nativeRet;
  nsAutoString b0;
  nsAutoString b1;

  *rval = JSVAL_NULL;

  if(argc >= 2)                             
  {
    //  public string getString ( String section,
    //                         String key);

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

    nativeThis->GetString(b0, b1, &nativeRet);

    ConvertStrToJSVal(nativeRet, cx, rval);
  }
  else
  {
    JS_ReportWarning(cx, "WinProfile.getString() parameters error");
  }

  return JS_TRUE;
}

Here is the call graph for this function:

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

Definition at line 132 of file nsJSWinProfile.cpp.

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

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

  *rval = JSVAL_ZERO;

  if(argc >= 3)
  {
    //  public int writeString ( String section,
    //                           String key,
    //                           String value);

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

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

  return JS_TRUE;
}

Here is the call graph for this function:


Variable Documentation

Initial value:
 
{
    {0}
}

Definition at line 178 of file nsJSWinProfile.cpp.

Initial value:
 
{
  {"getString",                  WinProfileGetString,                 2},
  {"writeString",                WinProfileWriteString,               3},
  {0}
}

Definition at line 186 of file nsJSWinProfile.cpp.