]> git.saurik.com Git - apple/javascriptcore.git/blame - bindings/jni/jni_utility.h
JavaScriptCore-466.1.tar.gz
[apple/javascriptcore.git] / bindings / jni / jni_utility.h
CommitLineData
b37bf2e1
A
1/*
2 * Copyright (C) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
24 */
25
26#ifndef _JNI_UTILITY_H_
27#define _JNI_UTILITY_H_
28
29#if ENABLE(JAVA_BINDINGS)
30
31#include <list.h>
32
33#include <JavaVM/jni.h>
34
35// The order of these items can not be modified as they are tightly
36// bound with the JVM on Mac OSX. If new types need to be added, they
37// should be added to the end. It is used in jni_obc.mm when calling
38// through to the JVM. Newly added items need to be made compatible
39// in that file.
40typedef enum {
41 invalid_type = 0,
42 void_type,
43 object_type,
44 boolean_type,
45 byte_type,
46 char_type,
47 short_type,
48 int_type,
49 long_type,
50 float_type,
51 double_type,
52 array_type
53} JNIType;
54
55namespace KJS {
56
57namespace Bindings {
58
59class JavaParameter;
60
61const char *getCharactersFromJString(jstring aJString);
62void releaseCharactersForJString(jstring aJString, const char *s);
63
64const char *getCharactersFromJStringInEnv(JNIEnv *env, jstring aJString);
65void releaseCharactersForJStringInEnv(JNIEnv *env, jstring aJString, const char *s);
66const jchar *getUCharactersFromJStringInEnv(JNIEnv *env, jstring aJString);
67void releaseUCharactersForJStringInEnv(JNIEnv *env, jstring aJString, const jchar *s);
68
69JNIType JNITypeFromClassName(const char *name);
70JNIType JNITypeFromPrimitiveType(char type);
71const char *signatureFromPrimitiveType(JNIType type);
72
73jvalue convertValueToJValue(ExecState *exec, JSValue *value, JNIType _JNIType, const char *javaClassName);
74
75jvalue getJNIField(jobject obj, JNIType type, const char *name, const char *signature);
76
77jmethodID getMethodID(jobject obj, const char *name, const char *sig);
78
79jobject callJNIObjectMethod(jobject obj, const char *name, const char *sig, ... );
80void callJNIVoidMethod(jobject obj, const char *name, const char *sig, ... );
81jboolean callJNIBooleanMethod(jobject obj, const char *name, const char *sig, ... );
82jboolean callJNIStaticBooleanMethod(jclass cls, const char *name, const char *sig, ... );
83jbyte callJNIByteMethod(jobject obj, const char *name, const char *sig, ... );
84jchar callJNICharMethod(jobject obj, const char *name, const char *sig, ... );
85jshort callJNIShortMethod(jobject obj, const char *name, const char *sig, ... );
86jint callJNIIntMethod(jobject obj, const char *name, const char *sig, ... );
87jlong callJNILongMethod(jobject obj, const char *name, const char *sig, ... );
88jfloat callJNIFloatMethod(jobject obj, const char *name, const char *sig, ... );
89jdouble callJNIDoubleMethod(jobject obj, const char *name, const char *sig, ... );
90
91jobject callJNIObjectMethodA(jobject obj, const char *name, const char *sig, jvalue *args);
92void callJNIVoidMethodA(jobject obj, const char *name, const char *sig, jvalue *args);
93jboolean callJNIBooleanMethodA(jobject obj, const char *name, const char *sig, jvalue *args);
94jbyte callJNIByteMethodA(jobject obj, const char *name, const char *sig, jvalue *args);
95jchar callJNICharMethodA(jobject obj, const char *name, const char *sig, jvalue *args);
96jshort callJNIShortMethodA(jobject obj, const char *name, const char *sig, jvalue *args);
97jint callJNIIntMethodA(jobject obj, const char *name, const char *sig, jvalue *args);
98jlong callJNILongMethodA(jobject obj, const char *name, const char *sig, jvalue *args);
99jfloat callJNIFloatMethodA(jobject obj, const char *name, const char *sig, jvalue *args);
100jdouble callJNIDoubleMethodA(jobject obj, const char *name, const char *sig, jvalue *args);
101
102jobject callJNIObjectMethodIDA(jobject obj, jmethodID methodID, jvalue *args);
103void callJNIVoidMethodIDA(jobject obj, jmethodID methodID, jvalue *args);
104jboolean callJNIBooleanMethodIDA(jobject obj, jmethodID methodID, jvalue *args);
105jbyte callJNIByteMethodIDA(jobject obj, jmethodID methodID, jvalue *args);
106jchar callJNICharMethodIDA(jobject obj, jmethodID methodID, jvalue *args);
107jshort callJNIShortMethodIDA(jobject obj, jmethodID methodID, jvalue *args);
108jint callJNIIntMethodIDA(jobject obj, jmethodID methodID, jvalue *args);
109jlong callJNILongMethodIDA(jobject obj, jmethodID methodID, jvalue *args);
110jfloat callJNIFloatMethodIDA(jobject obj, jmethodID methodID, jvalue *args);
111jdouble callJNIDoubleMethodIDA(jobject obj, jmethodID methodID, jvalue *args);
112
113JavaVM *getJavaVM();
114void setJavaVM(JavaVM *javaVM);
115JNIEnv *getJNIEnv();
116
117bool dispatchJNICall(const void *targetAppletView, jobject obj, bool isStatic, JNIType returnType, jmethodID methodID, jvalue *args, jvalue &result, const char *callingURL, JSValue *&exceptionDescription);
118
119} // namespace Bindings
120
121} // namespace KJS
122
123#endif // ENABLE(JAVA_BINDINGS)
124
125#endif // _JNI_UTILITY_H_