1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3
* The contents of this file are subject to the Netscape Public License
4
* Version 1.0 (the "NPL"); you may not use this file except in
5
* compliance with the NPL. You may obtain a copy of the NPL at
6
* http://www.mozilla.org/NPL/
8
* Software distributed under the NPL is distributed on an "AS IS" basis,
9
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
10
* for the specific language governing rights and limitations under the
13
* The Initial Developer of this code under the NPL is Netscape
14
* Communications Corporation. Portions created by Netscape are
15
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
21
#include "nsIScriptContext.h"
24
#include "nsInstall.h"
25
#include "nsJSFileSpecObj.h"
27
extern void ConvertJSValToStr(nsString& aString,
31
extern void ConvertStrToJSVal(const nsString& aProp,
35
extern PRBool ConvertJSValToBool(PRBool* aProp,
39
extern PRBool ConvertJSValToObj(nsISupports** aSupports,
41
const nsString& aTypeName,
47
/***********************************************************************************/
48
// Native methods for FileSpecObj functions
51
* Native method fso_ToString
53
PR_STATIC_CALLBACK(JSBool)
54
fso_ToString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
57
nsInstallFolder *nativeThis = (nsInstallFolder*)JS_GetPrivate(cx, obj);
58
nsAutoString stringReturned;
62
// If there's no private data, this must be the prototype, so ignore
63
if(nsnull == nativeThis)
68
if(NS_FAILED( nativeThis->ToString(&stringReturned)))
73
JS_NewUCStringCopyN(cx, NS_REINTERPRET_CAST(const jschar*,
74
stringReturned.get()),
75
stringReturned.Length());
77
// set the return value
78
*rval = STRING_TO_JSVAL(jsstring);
85
* Native method fso_AppendString
87
PR_STATIC_CALLBACK(JSBool)
88
fso_AppendPath(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
95
* FileSpecObj destructor
97
static void PR_CALLBACK FileSpecObjectCleanup(JSContext *cx, JSObject *obj)
99
nsInstallFolder *nativeThis = (nsInstallFolder*)JS_GetPrivate(cx, obj);
100
if (nativeThis != nsnull)
104
/***********************************************************************/
108
JSClass FileSpecObjectClass = {
118
FileSpecObjectCleanup
123
// FileObj class methods
125
static JSFunctionSpec fileSpecObjMethods[] =
127
{"appendPath", fso_AppendPath, 1},
128
{"toString", fso_ToString, 0},
133
PRInt32 InitFileSpecObjectPrototype(JSContext *jscontext,
135
JSObject **fileSpecObjectPrototype)
137
*fileSpecObjectPrototype = JS_InitClass( jscontext, // context
138
global, // global object
139
nsnull, // parent proto
140
&FileSpecObjectClass, // JSClass
141
nsnull, // JSNative ctor
143
nsnull, // proto props
144
fileSpecObjMethods,// proto funcs
145
nsnull, // ctor props (static)
146
nsnull); // ctor funcs (static)
148
if (nsnull == *fileSpecObjectPrototype)
150
return NS_ERROR_FAILURE;