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 JAVASCRIPTCORE_BINDINGS_JNI_JSOBJECT_H
27 #define JAVASCRIPTCORE_BINDINGS_JNI_JSOBJECT_H
29 #if ENABLE(JAVA_BINDINGS)
32 #include <CoreFoundation/CoreFoundation.h>
35 #include <JavaVM/jni.h>
36 #include <wtf/RefPtr.h>
38 #define jlong_to_ptr(a) ((void*)(uintptr_t)(a))
39 #define jlong_to_impptr(a) (static_cast<KJS::JSObject*>(((void*)(uintptr_t)(a))))
40 #define ptr_to_jlong(a) ((jlong)(uintptr_t)(a))
52 enum JSObjectCallType
{
65 struct JSObjectCallContext
67 JSObjectCallType type
;
73 CFRunLoopRef originatingLoop
;
80 JavaJSObject(jlong nativeHandle
);
82 static jlong
createNative(jlong nativeHandle
);
83 jobject
call(jstring methodName
, jobjectArray args
) const;
84 jobject
eval(jstring script
) const;
85 jobject
getMember(jstring memberName
) const;
86 void setMember(jstring memberName
, jobject value
) const;
87 void removeMember(jstring memberName
) const;
88 jobject
getSlot(jint index
) const;
89 void setSlot(jint index
, jobject value
) const;
90 jstring
toString() const;
91 void finalize() const;
93 static jvalue
invoke(JSObjectCallContext
*);
95 jobject
convertValueToJObject(JSValue
*) const;
96 JSValue
* convertJObjectToValue(jobject
) const;
97 void getListFromJArray(jobjectArray
, List
&) const;
99 RootObject
* rootObject() const;
102 RefPtr
<RootObject
> _rootObject
;
107 } // namespace Bindings
113 // The Java VM calls these functions to handle calls to methods in Java's JSObject class.
114 jlong
KJS_JSCreateNativeJSObject(JNIEnv
*, jclass
, jstring jurl
, jlong nativeHandle
, jboolean ctx
);
115 void KJS_JSObject_JSFinalize(JNIEnv
*, jclass
, jlong nativeJSObject
);
116 jobject
KJS_JSObject_JSObjectCall(JNIEnv
*, jclass
, jlong nativeJSObject
, jstring jurl
, jstring methodName
, jobjectArray args
, jboolean ctx
);
117 jobject
KJS_JSObject_JSObjectEval(JNIEnv
*, jclass
, jlong nativeJSObject
, jstring jurl
, jstring jscript
, jboolean ctx
);
118 jobject
KJS_JSObject_JSObjectGetMember(JNIEnv
*, jclass
, jlong nativeJSObject
, jstring jurl
, jstring jname
, jboolean ctx
);
119 void KJS_JSObject_JSObjectSetMember(JNIEnv
*, jclass
, jlong nativeJSObject
, jstring jurl
, jstring jname
, jobject value
, jboolean ctx
);
120 void KJS_JSObject_JSObjectRemoveMember(JNIEnv
*, jclass
, jlong nativeJSObject
, jstring jurl
, jstring jname
, jboolean ctx
);
121 jobject
KJS_JSObject_JSObjectGetSlot(JNIEnv
*, jclass
, jlong nativeJSObject
, jstring jurl
, jint jindex
, jboolean ctx
);
122 void KJS_JSObject_JSObjectSetSlot(JNIEnv
*, jclass
, jlong nativeJSObject
, jstring jurl
, jint jindex
, jobject value
, jboolean ctx
);
123 jstring
KJS_JSObject_JSObjectToString(JNIEnv
*, jclass
, jlong nativeJSObject
);
127 #endif // ENABLE(JAVA_BINDINGS)
129 #endif // JAVASCRIPTCORE_BINDINGS_JNI_JSOBJECT_H