~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/xpinstall/src/nsJSFileSpecObj.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 
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/
 
7
 *
 
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
 
11
 * NPL.
 
12
 *
 
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
 
16
 * Reserved.
 
17
 */
 
18
 
 
19
#include "jsapi.h"
 
20
#include "nscore.h"
 
21
#include "nsIScriptContext.h"
 
22
 
 
23
#include "nsString.h"
 
24
#include "nsInstall.h"
 
25
#include "nsJSFileSpecObj.h"
 
26
 
 
27
extern void ConvertJSValToStr(nsString&  aString,
 
28
                             JSContext* aContext,
 
29
                             jsval      aValue);
 
30
 
 
31
extern void ConvertStrToJSVal(const nsString& aProp,
 
32
                             JSContext* aContext,
 
33
                             jsval* aReturn);
 
34
 
 
35
extern PRBool ConvertJSValToBool(PRBool* aProp,
 
36
                                JSContext* aContext,
 
37
                                jsval aValue);
 
38
 
 
39
extern PRBool ConvertJSValToObj(nsISupports** aSupports,
 
40
                               REFNSIID aIID,
 
41
                               const nsString& aTypeName,
 
42
                               JSContext* aContext,
 
43
                               jsval aValue);
 
44
 
 
45
 
 
46
 
 
47
/***********************************************************************************/
 
48
// Native methods for FileSpecObj functions
 
49
 
 
50
/*
 
51
 * Native method fso_ToString
 
52
 */
 
53
PR_STATIC_CALLBACK(JSBool)
 
54
fso_ToString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 
55
{
 
56
 
 
57
  nsInstallFolder *nativeThis = (nsInstallFolder*)JS_GetPrivate(cx, obj);
 
58
  nsAutoString stringReturned;
 
59
 
 
60
  *rval = JSVAL_NULL;
 
61
 
 
62
  // If there's no private data, this must be the prototype, so ignore
 
63
  if(nsnull == nativeThis)
 
64
  {
 
65
    return JS_TRUE;
 
66
  }
 
67
 
 
68
  if(NS_FAILED( nativeThis->ToString(&stringReturned)))
 
69
    return JS_TRUE;
 
70
 
 
71
 
 
72
  JSString *jsstring =
 
73
    JS_NewUCStringCopyN(cx, NS_REINTERPRET_CAST(const jschar*,
 
74
                                                stringReturned.get()),
 
75
                        stringReturned.Length());
 
76
 
 
77
  // set the return value
 
78
  *rval = STRING_TO_JSVAL(jsstring);
 
79
 
 
80
  return JS_TRUE;
 
81
}
 
82
 
 
83
 
 
84
/*
 
85
 * Native method fso_AppendString
 
86
 */
 
87
PR_STATIC_CALLBACK(JSBool)
 
88
fso_AppendPath(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 
89
{
 
90
  return JS_TRUE;
 
91
}
 
92
 
 
93
 
 
94
/*
 
95
 * FileSpecObj destructor
 
96
 */
 
97
static void PR_CALLBACK FileSpecObjectCleanup(JSContext *cx, JSObject *obj)
 
98
{
 
99
    nsInstallFolder *nativeThis = (nsInstallFolder*)JS_GetPrivate(cx, obj);
 
100
    if (nativeThis != nsnull)
 
101
       delete nativeThis;
 
102
}
 
103
 
 
104
/***********************************************************************/
 
105
//
 
106
// class for FileObj
 
107
//
 
108
JSClass FileSpecObjectClass = {
 
109
  "FileSpecObject",
 
110
  JSCLASS_HAS_PRIVATE,
 
111
  JS_PropertyStub,
 
112
  JS_PropertyStub,
 
113
  JS_PropertyStub,
 
114
  JS_PropertyStub,
 
115
  JS_EnumerateStub,
 
116
  JS_ResolveStub,
 
117
  JS_ConvertStub,
 
118
  FileSpecObjectCleanup
 
119
};
 
120
 
 
121
 
 
122
//
 
123
// FileObj class methods
 
124
//
 
125
static JSFunctionSpec fileSpecObjMethods[] = 
 
126
{
 
127
  {"appendPath",       fso_AppendPath,     1},
 
128
  {"toString",         fso_ToString,       0},
 
129
  {0}
 
130
};
 
131
 
 
132
 
 
133
PRInt32  InitFileSpecObjectPrototype(JSContext *jscontext, 
 
134
                                      JSObject *global, 
 
135
                                      JSObject **fileSpecObjectPrototype)
 
136
{
 
137
  *fileSpecObjectPrototype  = JS_InitClass( jscontext,         // context
 
138
                                            global,            // global object
 
139
                                            nsnull,            // parent proto 
 
140
                                            &FileSpecObjectClass, // JSClass
 
141
                                            nsnull,            // JSNative ctor
 
142
                                            0,                 // ctor args
 
143
                                            nsnull,            // proto props
 
144
                                            fileSpecObjMethods,// proto funcs
 
145
                                            nsnull,            // ctor props (static)
 
146
                                            nsnull);           // ctor funcs (static)
 
147
 
 
148
  if (nsnull == *fileSpecObjectPrototype) 
 
149
  {
 
150
      return NS_ERROR_FAILURE;
 
151
  }
 
152
 
 
153
 
 
154
  return NS_OK;
 
155
}
 
156
 
 
157