]>
git.saurik.com Git - apple/javascriptcore.git/blob - bindings/jni/jni_runtime.h
eb6d2736f10612b2a2f236836d486285d550844c
2 * Copyright (C) 2003 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef _JNI_RUNTIME_H_
27 #define _JNI_RUNTIME_H_
29 #if ENABLE(JAVA_BINDINGS)
31 #include <jni_utility.h>
32 #include <jni_instance.h>
41 typedef const char* RuntimeType
;
49 _rep
= UString().rep();
52 void _commonInit (JNIEnv
*e
, jstring s
)
54 int _size
= e
->GetStringLength (s
);
55 const jchar
*uc
= getUCharactersFromJStringInEnv (e
, s
);
58 _rep
= UString((UChar
*)uc
,_size
).rep();
60 releaseUCharactersForJStringInEnv (e
, s
, uc
);
63 JavaString (JNIEnv
*e
, jstring s
) {
67 JavaString (jstring s
) {
68 _commonInit (getJNIEnv(), s
);
77 const char *UTF8String() const {
78 if (_utf8String
.c_str() == 0) {
80 _utf8String
= UString(_rep
).UTF8String();
82 return _utf8String
.c_str();
84 const jchar
*uchars() const { return (const jchar
*)_rep
->data(); }
85 int length() const { return _rep
->size(); }
86 UString
ustring() const { return UString(_rep
); }
89 RefPtr
<UString::Rep
> _rep
;
90 mutable CString _utf8String
;
96 JavaParameter () : _JNIType(invalid_type
) {};
97 JavaParameter (JNIEnv
*env
, jstring type
);
98 virtual ~JavaParameter() { }
100 RuntimeType
type() const { return _type
.UTF8String(); }
101 JNIType
getJNIType() const { return _JNIType
; }
109 class JavaField
: public Field
112 JavaField (JNIEnv
*env
, jobject aField
);
114 virtual JSValue
*valueFromInstance(ExecState
*exec
, const Instance
*instance
) const;
115 virtual void setValueToInstance(ExecState
*exec
, const Instance
*instance
, JSValue
*aValue
) const;
117 virtual const char *name() const { return _name
.UTF8String(); }
118 virtual RuntimeType
type() const { return _type
.UTF8String(); }
120 JNIType
getJNIType() const { return _JNIType
; }
123 void dispatchSetValueToInstance(ExecState
*exec
, const JavaInstance
*instance
, jvalue javaValue
, const char *name
, const char *sig
) const;
124 jvalue
dispatchValueFromInstance(ExecState
*exec
, const JavaInstance
*instance
, const char *name
, const char *sig
, JNIType returnType
) const;
129 RefPtr
<JObjectWrapper
> _field
;
133 class JavaMethod
: public Method
136 JavaMethod(JNIEnv
* env
, jobject aMethod
);
139 virtual const char *name() const { return _name
.UTF8String(); };
140 RuntimeType
returnType() const { return _returnType
.UTF8String(); };
141 JavaParameter
* parameterAt(int i
) const { return &_parameters
[i
]; };
142 int numParameters() const { return _numParameters
; };
144 const char *signature() const;
145 JNIType
JNIReturnType() const;
147 jmethodID
methodID (jobject obj
) const;
149 bool isStatic() const { return _isStatic
; }
152 JavaParameter
* _parameters
;
155 mutable char* _signature
;
156 JavaString _returnType
;
157 JNIType _JNIReturnType
;
158 mutable jmethodID _methodID
;
162 class JavaArray
: public Array
165 JavaArray(jobject array
, const char* type
, PassRefPtr
<RootObject
>);
166 virtual ~JavaArray();
168 RootObject
* rootObject() const;
170 virtual void setValueAt(ExecState
*exec
, unsigned int index
, JSValue
*aValue
) const;
171 virtual JSValue
*valueAt(ExecState
*exec
, unsigned int index
) const;
172 virtual unsigned int getLength() const;
174 jobject
javaArray() const { return _array
->_instance
; }
176 static JSValue
* convertJObjectToArray (ExecState
* exec
, jobject anObject
, const char* type
, PassRefPtr
<RootObject
>);
179 RefPtr
<JObjectWrapper
> _array
;
180 unsigned int _length
;
184 } // namespace Bindings
188 #endif // ENABLE(JAVA_BINDINGS)
190 #endif // _JNI_RUNTIME_H_