Back to index

lightning-sunbird  0.9+nobinonly
nsJSWinReg.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "jsapi.h"
00039 #include "nscore.h"
00040 #include "nsIScriptContext.h"
00041 
00042 #include "nsString.h"
00043 #include "nsInstall.h"
00044 #include "nsWinReg.h"
00045 #include "nsJSWinReg.h"
00046 
00047 static void PR_CALLBACK WinRegCleanup(JSContext *cx, JSObject *obj);
00048 
00049 extern void ConvertJSValToStr(nsString&  aString,
00050                              JSContext* aContext,
00051                              jsval      aValue);
00052 
00053 extern void ConvertStrToJSVal(const nsString& aProp,
00054                              JSContext* aContext,
00055                              jsval* aReturn);
00056 
00057 extern PRBool ConvertJSValToBool(PRBool* aProp,
00058                                 JSContext* aContext,
00059                                 jsval aValue);
00060 
00061 
00062 static void PR_CALLBACK WinRegCleanup(JSContext *cx, JSObject *obj)
00063 {
00064     nsWinReg *nativeThis = (nsWinReg*)JS_GetPrivate(cx, obj);
00065     delete nativeThis;
00066 }
00067 
00068 /***********************************************************************/
00069 //
00070 // class for WinReg
00071 //
00072 JSClass WinRegClass = {
00073   "WinReg",
00074   JSCLASS_HAS_PRIVATE,
00075   JS_PropertyStub,
00076   JS_PropertyStub,
00077   JS_PropertyStub,
00078   JS_PropertyStub,
00079   JS_EnumerateStub,
00080   JS_ResolveStub,
00081   JS_ConvertStub,
00082   WinRegCleanup
00083 };
00084 
00085 /***********************************************************************************/
00086 // Native mothods for WinReg functions
00087 
00088 //
00089 // Native method SetRootKey
00090 //
00091 PR_STATIC_CALLBACK(JSBool)
00092 WinRegSetRootKey(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00093 {
00094   nsWinReg *nativeThis =
00095     (nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
00096   if (!nativeThis)
00097     return JS_FALSE;
00098 
00099   PRInt32  b0;
00100 
00101   *rval = JSVAL_NULL;
00102 
00103   if(argc >= 1)
00104   {
00105     //  public void setRootKey(PRInt32 key);
00106     if(JS_ValueToInt32(cx, argv[0], (int32 *)&b0))
00107     {
00108       nativeThis->SetRootKey(b0);
00109     }
00110     else
00111     {
00112       JS_ReportWarning(cx, "Parameter must be a number");
00113     }
00114   }
00115   else
00116   {
00117     JS_ReportWarning(cx, "Function SetRootKey requires 1 parameters");
00118   }
00119 
00120   return JS_TRUE;
00121 }
00122 
00123 
00124 //
00125 // Native method KeyExists
00126 //
00127 PR_STATIC_CALLBACK(JSBool)
00128 WinRegKeyExists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00129 {
00130   nsWinReg *nativeThis =
00131     (nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
00132   if (!nativeThis)
00133     return JS_FALSE;
00134 
00135   PRBool nativeRet;
00136   nsAutoString b0;
00137 
00138   *rval = JSVAL_FALSE;
00139 
00140   if(argc >= 1)
00141   {
00142     //  public boolean keyExists ( String subKey );
00143 
00144     ConvertJSValToStr(b0, cx, argv[0]);
00145 
00146     if(NS_OK == nativeThis->KeyExists(b0, &nativeRet))
00147     {
00148       *rval = BOOLEAN_TO_JSVAL(nativeRet);
00149     }
00150     else
00151     {
00152       NS_WARNING("WinReg.KeyExists() internal error");
00153     }
00154   }
00155   else
00156   {
00157     JS_ReportWarning(cx, "WinReg.KeyExists() parameters error");
00158   }
00159 
00160   return JS_TRUE;
00161 }
00162 
00163 //
00164 // Native method ValueExists
00165 //
00166 PR_STATIC_CALLBACK(JSBool)
00167 WinRegValueExists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00168 {
00169   nsWinReg *nativeThis =
00170     (nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
00171   if (!nativeThis)
00172     return JS_FALSE;
00173 
00174   PRBool nativeRet;
00175   nsAutoString b0;
00176   nsAutoString b1;
00177 
00178   *rval = JSVAL_FALSE;
00179 
00180   if(argc >= 2)
00181   {
00182     //  public boolean valueExists ( String subKey,
00183     //                           String value );
00184 
00185     ConvertJSValToStr(b0, cx, argv[0]);
00186     ConvertJSValToStr(b1, cx, argv[1]);
00187 
00188     if(NS_OK == nativeThis->ValueExists(b0, b1, &nativeRet))
00189     {
00190       *rval = BOOLEAN_TO_JSVAL(nativeRet);
00191     }
00192   }
00193   else
00194   {
00195     JS_ReportWarning(cx, "WinReg.ValueExists() parameters error");
00196   }
00197 
00198   return JS_TRUE;
00199 }
00200 
00201 //
00202 // Native method IsKeyWritable
00203 //
00204 PR_STATIC_CALLBACK(JSBool)
00205 WinRegIsKeyWritable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00206 {
00207   nsWinReg *nativeThis =
00208     (nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
00209   if (!nativeThis)
00210     return JS_FALSE;
00211 
00212   PRInt32 nativeRet;
00213   nsAutoString b0;
00214 
00215   *rval = JSVAL_FALSE;
00216 
00217   if(argc >= 1)
00218   {
00219     //  public boolean isKeyWritable ( String subKey );
00220 
00221     ConvertJSValToStr(b0, cx, argv[0]);
00222 
00223     if(NS_OK == nativeThis->IsKeyWritable(b0, &nativeRet))
00224     {
00225       *rval = BOOLEAN_TO_JSVAL(nativeRet);
00226     }
00227   }
00228   else
00229   {
00230     JS_ReportWarning(cx, "WinReg.IsKeyWritable() parameters error");
00231   }
00232 
00233   return JS_TRUE;
00234 }
00235 
00236 //
00237 // Native method CreateKey
00238 //
00239 PR_STATIC_CALLBACK(JSBool)
00240 WinRegCreateKey(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00241 {
00242   nsWinReg *nativeThis =
00243     (nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
00244   if (!nativeThis)
00245     return JS_FALSE;
00246 
00247   PRInt32 nativeRet;
00248   nsAutoString b0;
00249   nsAutoString b1;
00250 
00251   *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
00252 
00253   if(argc >= 2)                             
00254   {
00255     //  public int createKey ( String subKey,
00256     //                         String className);
00257 
00258     ConvertJSValToStr(b0, cx, argv[0]);
00259     ConvertJSValToStr(b1, cx, argv[1]);
00260 
00261     if(NS_OK == nativeThis->CreateKey(b0, b1, &nativeRet))
00262     {
00263       *rval = INT_TO_JSVAL(nativeRet);
00264     }
00265   }
00266   else
00267   {
00268     JS_ReportWarning(cx, "WinReg.CreateKey() parameters error");
00269   }
00270 
00271   return JS_TRUE;
00272 }
00273 
00274 //
00275 // Native method DeleteKey
00276 //
00277 PR_STATIC_CALLBACK(JSBool)
00278 WinRegDeleteKey(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00279 {
00280   nsWinReg *nativeThis =
00281     (nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
00282   if (!nativeThis)
00283     return JS_FALSE;
00284 
00285   PRInt32 nativeRet;
00286   nsAutoString b0;
00287 
00288   *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
00289 
00290   if(argc >= 1)                             
00291   {
00292     //  public int deleteKey ( String subKey);
00293 
00294     ConvertJSValToStr(b0, cx, argv[0]);
00295 
00296     if(NS_OK == nativeThis->DeleteKey(b0, &nativeRet))
00297     {
00298       *rval = INT_TO_JSVAL(nativeRet);
00299     }
00300   }
00301   else
00302   {
00303     JS_ReportWarning(cx, "WinReg.DeleteKey() parameters error");
00304   }
00305 
00306   return JS_TRUE;
00307 }
00308 
00309 
00310 //
00311 // Native method DeleteValue
00312 //
00313 PR_STATIC_CALLBACK(JSBool)
00314 WinRegDeleteValue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00315 {
00316   nsWinReg *nativeThis =
00317     (nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
00318   if (!nativeThis)
00319     return JS_FALSE;
00320 
00321   PRInt32 nativeRet;
00322   nsString b0;
00323   nsString b1;
00324 
00325   *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
00326 
00327   if(argc >= 2)                             
00328   {
00329     //  public int deleteValue ( String subKey,
00330     //                           String valueName);
00331 
00332     ConvertJSValToStr(b0, cx, argv[0]);
00333     ConvertJSValToStr(b1, cx, argv[1]);
00334 
00335     if(NS_OK == nativeThis->DeleteValue(b0, b1, &nativeRet))
00336     {
00337       *rval = INT_TO_JSVAL(nativeRet);
00338     }
00339   }
00340   else
00341   {
00342     JS_ReportWarning(cx, "WinReg.DeleteValue() parameters error");
00343   }
00344 
00345   return JS_TRUE;
00346 }
00347 
00348 //
00349 // Native method SetValueString
00350 //
00351 PR_STATIC_CALLBACK(JSBool)
00352 WinRegSetValueString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00353 {
00354   nsWinReg *nativeThis =
00355     (nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
00356   if (!nativeThis)
00357     return JS_FALSE;
00358 
00359   PRInt32 nativeRet;
00360   nsAutoString b0;
00361   nsAutoString b1;
00362   nsAutoString b2;
00363 
00364   *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
00365 
00366   if(argc >= 3)
00367   {
00368     //  public int setValueString ( String subKey,
00369     //                              String valueName,
00370     //                              String value);
00371 
00372     ConvertJSValToStr(b0, cx, argv[0]);
00373     ConvertJSValToStr(b1, cx, argv[1]);
00374     ConvertJSValToStr(b2, cx, argv[2]);
00375 
00376     if(NS_OK == nativeThis->SetValueString(b0, b1, b2, &nativeRet))
00377     {
00378       *rval = INT_TO_JSVAL(nativeRet);
00379     }
00380   }
00381   else
00382   {
00383     JS_ReportWarning(cx, "WinReg.SetValueString() parameters error");
00384   }
00385 
00386   return JS_TRUE;
00387 }
00388 
00389 //
00390 // Native method GetValueString
00391 //
00392 PR_STATIC_CALLBACK(JSBool)
00393 WinRegGetValueString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00394 {
00395   nsWinReg *nativeThis =
00396     (nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
00397   if (!nativeThis)
00398     return JS_FALSE;
00399 
00400   nsString     nativeRet;
00401   nsAutoString b0;
00402   nsAutoString b1;
00403 
00404   *rval = JSVAL_NULL;
00405 
00406   if(argc >= 2)                             
00407   {
00408     //  public string getValueString ( String subKey,
00409     //                              String valueName);
00410 
00411     ConvertJSValToStr(b0, cx, argv[0]);
00412     ConvertJSValToStr(b1, cx, argv[1]);
00413 
00414     if(NS_OK == nativeThis->GetValueString(b0, b1, &nativeRet))
00415     {
00416       ConvertStrToJSVal(nativeRet, cx, rval);
00417     }
00418   }
00419   else
00420   {
00421     JS_ReportWarning(cx, "WinReg.GetValueString() parameters error");
00422   }
00423 
00424   return JS_TRUE;
00425 }
00426 
00427 //
00428 // Native method enumValueNames
00429 //
00430 PR_STATIC_CALLBACK(JSBool)
00431 WinRegEnumValueNames(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00432 {
00433   nsWinReg *nativeThis =
00434     (nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
00435   if (!nativeThis)
00436     return JS_FALSE;
00437 
00438   nsAutoString   nativeRet;
00439   nsAutoString   b0;
00440   int32          b1;
00441 
00442   *rval = JSVAL_NULL;
00443 
00444   if(argc >= 2)                             
00445   {
00446     //  public String enumValueNames ( String subkey,
00447     //                                 Int index);
00448 
00449     ConvertJSValToStr(b0, cx, argv[0]);
00450 
00451     if(JS_ValueToInt32(cx, argv[1], &b1))
00452     {
00453       if ( NS_OK == nativeThis->EnumValueNames(b0, b1, nativeRet) )
00454       {
00455           ConvertStrToJSVal(nativeRet, cx, rval);
00456       }
00457     }
00458     else  
00459     {
00460       JS_ReportWarning(cx, "WinReg.enumValueNames - Parameter 2 must be a number");
00461     }
00462   }
00463   else
00464   {
00465     JS_ReportWarning(cx, "WinReg.enumValueNames() - Too few parameters");
00466   }
00467 
00468   return JS_TRUE;
00469 }
00470 
00471 
00472 //
00473 // Native method enumKeys
00474 //
00475 PR_STATIC_CALLBACK(JSBool)
00476 WinRegEnumKeys(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00477 {
00478   nsWinReg *nativeThis =
00479     (nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
00480   if (!nativeThis)
00481     return JS_FALSE;
00482 
00483   nsAutoString   nativeRet;
00484   nsAutoString   b0;
00485   int32          b1;
00486 
00487   *rval = JSVAL_NULL;
00488 
00489   if(argc >= 2)                             
00490   {
00491     //  public String enumKeys ( String subkey,
00492     //                           Int    index);
00493 
00494     ConvertJSValToStr(b0, cx, argv[0]);
00495 
00496     if(JS_ValueToInt32(cx, argv[1], &b1))
00497     {
00498       if ( NS_OK ==  nativeThis->EnumKeys(b0, b1, nativeRet) )
00499       {
00500           ConvertStrToJSVal(nativeRet, cx, rval);
00501       }
00502     }
00503     else
00504     {
00505       JS_ReportWarning(cx, "WinReg.enumKeys() - Parameter 2 must be a number");
00506     }
00507   }
00508   else
00509   {
00510     JS_ReportWarning(cx, "WinReg.enumKeys() - Too few parameters");
00511   }
00512 
00513   return JS_TRUE;
00514 }
00515 
00516 
00517 //
00518 // Native method SetValueNumber
00519 //
00520 PR_STATIC_CALLBACK(JSBool)
00521 WinRegSetValueNumber(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00522 {
00523   nsWinReg *nativeThis =
00524     (nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
00525   if (!nativeThis)
00526     return JS_FALSE;
00527 
00528   PRInt32 nativeRet;
00529   nsAutoString b0;
00530   nsAutoString b1;
00531   int32        ib2;
00532 
00533   *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
00534 
00535   if(argc >= 3)
00536   {
00537     //  public int setValueNumber ( String subKey,
00538     //                              String valueName,
00539     //                              Number value);
00540 
00541     ConvertJSValToStr(b0, cx, argv[0]);
00542     ConvertJSValToStr(b1, cx, argv[1]);
00543 
00544     if(!JS_ValueToInt32(cx, argv[2], &ib2))
00545     {
00546       JS_ReportWarning(cx, "Parameter 3 must be a number");
00547     }
00548     else if(NS_OK == nativeThis->SetValueNumber(b0, b1, ib2, &nativeRet))
00549     {
00550       *rval = INT_TO_JSVAL(nativeRet);
00551     }
00552   }
00553   else
00554   {
00555     JS_ReportWarning(cx, "WinReg.SetValueNumber() parameters error");
00556   }
00557 
00558   return JS_TRUE;
00559 }
00560 
00561 //
00562 // Native method GetValueNumber
00563 //
00564 PR_STATIC_CALLBACK(JSBool)
00565 WinRegGetValueNumber(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00566 {
00567   nsWinReg *nativeThis =
00568     (nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
00569   if (!nativeThis)
00570     return JS_FALSE;
00571 
00572   PRInt32      nativeRet;
00573   nsAutoString b0;
00574   nsAutoString b1;
00575 
00576   *rval = JSVAL_NULL;
00577 
00578   if(argc >= 2)                             
00579   {
00580     //  public int getValueNumber ( String subKey,
00581     //                              Number valueName);
00582 
00583     ConvertJSValToStr(b0, cx, argv[0]);
00584     ConvertJSValToStr(b1, cx, argv[1]);
00585 
00586     if(NS_OK == nativeThis->GetValueNumber(b0, b1, &nativeRet))
00587     {
00588       *rval = INT_TO_JSVAL(nativeRet);
00589     }
00590   }
00591   else
00592   {
00593     JS_ReportWarning(cx, "WinReg.GetValueNumber() parameters error");
00594   }
00595 
00596   return JS_TRUE;
00597 }
00598 
00599 //
00600 // Native method SetValue
00601 //
00602 PR_STATIC_CALLBACK(JSBool)
00603 WinRegSetValue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00604 {
00605   nsWinReg *nativeThis =
00606     (nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
00607   if (!nativeThis)
00608     return JS_FALSE;
00609 
00610   nsAutoString b0;
00611   nsAutoString b1;
00612 
00613   *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
00614 
00615   if(argc >= 3)
00616   {
00617     //  public int setValue ( String        subKey,
00618     //                        String        valueName,
00619     //                        nsWinRegItem  *value);
00620 
00621     ConvertJSValToStr(b0, cx, argv[0]);
00622     ConvertJSValToStr(b1, cx, argv[1]);
00623 
00624     // fix: this parameter is an object, not a string.
00625     // A way needs to be figured out to convert the JSVAL to this object type
00626 //    ConvertJSValToStr(b2, cx, argv[2]);
00627 
00628 //    if(NS_OK != nativeThis->SetValue(b0, b1, b2, &nativeRet))
00629 //    {
00630 //      return JS_FALSE;
00631 //    }
00632 
00633 //    *rval = INT_TO_JSVAL(nativeRet);
00634   }
00635   else
00636   {
00637     JS_ReportWarning(cx, "WinReg.SetValue() parameters error");
00638   }
00639 
00640   return JS_TRUE;
00641 }
00642 
00643 //
00644 // Native method GetValue
00645 //
00646 PR_STATIC_CALLBACK(JSBool)
00647 WinRegGetValue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00648 {
00649   nsWinReg *nativeThis =
00650     (nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
00651   if (!nativeThis)
00652     return JS_FALSE;
00653 
00654   nsWinRegValue *nativeRet;
00655   nsAutoString  b0;
00656   nsAutoString  b1;
00657 
00658   *rval = JSVAL_NULL;
00659 
00660   if(argc >= 2)                             
00661   {
00662     //  public int getValue ( String subKey,
00663     //                        String valueName);
00664 
00665     ConvertJSValToStr(b0, cx, argv[0]);
00666     ConvertJSValToStr(b1, cx, argv[1]);
00667 
00668     if(NS_OK == nativeThis->GetValue(b0, b1, &nativeRet))
00669     {
00670       *rval = INT_TO_JSVAL(nativeRet);
00671     }
00672   }
00673   else
00674   {
00675     JS_ReportWarning(cx, "WinReg.GetValue() parameters error");
00676   }
00677 
00678   return JS_TRUE;
00679 }
00680 
00681 
00682 //
00683 // WinReg constructor
00684 //
00685 PR_STATIC_CALLBACK(JSBool)
00686 WinReg(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00687 {
00688   return JS_FALSE;
00689 }
00690 
00691 
00692 static JSConstDoubleSpec winreg_constants[] = 
00693 {
00694     { nsWinReg::NS_HKEY_CLASSES_ROOT,        "HKEY_CLASSES_ROOT"            },
00695     { nsWinReg::NS_HKEY_CURRENT_USER,        "HKEY_CURRENT_USER"            },
00696     { nsWinReg::NS_HKEY_LOCAL_MACHINE,       "HKEY_LOCAL_MACHINE"           },
00697     { nsWinReg::NS_HKEY_USERS,               "HKEY_USERS"                   },
00698     {0}
00699 };
00700 
00701 //
00702 // WinReg class methods
00703 //
00704 static JSFunctionSpec WinRegMethods[] = 
00705 {
00706   {"setRootKey",                WinRegSetRootKey,               1},
00707   {"keyExists",                 WinRegKeyExists,                1},
00708   {"valueExists",               WinRegValueExists,              2},
00709   {"isKeyWritable",             WinRegIsKeyWritable,            1},
00710   {"createKey",                 WinRegCreateKey,                2},
00711   {"deleteKey",                 WinRegDeleteKey,                1},
00712   {"deleteValue",               WinRegDeleteValue,              2},
00713   {"setValueString",            WinRegSetValueString,           3},
00714   {"getValueString",            WinRegGetValueString,           2},
00715   {"setValueNumber",            WinRegSetValueNumber,           3},
00716   {"getValueNumber",            WinRegGetValueNumber,           2},
00717   {"setValue",                  WinRegSetValue,                 3},
00718   {"getValue",                  WinRegGetValue,                 2},
00719   {"enumKeys",                  WinRegEnumKeys,                 2},
00720   {"enumValueNames",            WinRegEnumValueNames,           2},
00721   {0}
00722 };
00723 
00724 PRInt32
00725 InitWinRegPrototype(JSContext *jscontext, JSObject *global, JSObject **winRegPrototype)
00726 {
00727   *winRegPrototype = JS_InitClass( jscontext,         // context
00728                                   global,            // global object
00729                                   nsnull,            // parent proto 
00730                                   &WinRegClass,      // JSClass
00731                                   nsnull,            // JSNative ctor
00732                                   0,                 // ctor args
00733                                   nsnull,            // proto props
00734                                   nsnull,            // proto funcs
00735                                   nsnull,            // ctor props (static)
00736                                   WinRegMethods);    // ctor funcs (static)
00737 
00738   if(nsnull == *winRegPrototype) 
00739   {
00740     return NS_ERROR_FAILURE;
00741   }
00742 
00743   if(PR_FALSE == JS_DefineConstDoubles(jscontext, *winRegPrototype, winreg_constants))
00744     return NS_ERROR_FAILURE;
00745 
00746   return NS_OK;
00747 }
00748