home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / js / jsj / jsjava.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.0 KB  |  171 lines

  1. /* -*- Mode: C; tab-width: 4; 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. #ifndef _jsjava_h_
  20. #define _jsjava_h_
  21.  
  22. #include "jsapi.h"
  23.  
  24. /*
  25.  * Java <-> JavaScript reflection
  26.  */
  27.  
  28.  
  29.  
  30. /* FIXME change everything to JRI style */
  31. #ifndef _OOBJ_H_
  32. typedef struct HObject HObject;
  33. typedef struct ClassClass ClassClass;
  34. typedef struct ExecEnv ExecEnv;
  35. #endif
  36.  
  37. /* FIXME should be obtained from jri.h */
  38. #ifndef JRI_H
  39. typedef struct JRIEnvInterface  JRIEnvInterface;
  40. typedef const JRIEnvInterface*  JRIEnv;
  41. #endif
  42. #ifndef JNI_H
  43. typedef struct _jobject *jobject;
  44. #endif
  45.  
  46. /***********************************************************************
  47.  *
  48.  *  this callback table is used to export functions to jsjava.c
  49.  */
  50. typedef struct {
  51.     int         (*isEnabled)(void);
  52.     JRIEnv *    (*currentEnv)(JSContext *);
  53.     JSContext *    (*currentContext)(JRIEnv *, char **errp);
  54.     void    (*enterJS)(void);
  55.     void    (*exitJS)(void);
  56.     void *    (*jsClassLoader)(JSContext *, const char *codebase);
  57.     JSPrincipals *
  58.                 (*getJSPrincipalsFromJavaCaller)(JSContext *cx,
  59.                                                  int callerDepth);
  60.     JSObject *    (*getDefaultObject)(JRIEnv *env, jobject hint);
  61. } JSJCallbacks;
  62.  
  63. /***********************************************************************
  64.  *
  65.  *  these functions are provided by jsjava.c
  66.  */
  67.  
  68. /* call to initialize a javascript context and toplevel object for use
  69.  * with JSJ */
  70. PR_EXTERN(JSBool)
  71. JSJ_Init(JSJCallbacks *callbacks);
  72.  
  73. #ifdef JAVA
  74. /* this is called by JSObject.initClass to initialize the default
  75.  * glue if jsjava has been loaded into java.exe as a DLL.  it does
  76.  * nothing if the client or server has already initialized us */
  77. PR_EXTERN(void)
  78. JSJ_InitStandalone();
  79.  
  80. /* shut down java-javascript reflection */
  81. PR_EXTERN(void)
  82. JSJ_Finish(void);
  83.  
  84. /* call to initialize a javascript context and toplevel object for use
  85.  * with JSJ */
  86. PR_EXTERN(JSBool)
  87. JSJ_InitContext(JSContext *cx, JSObject *obj);
  88.  
  89. /* tells whether the js<->java connection can be used */
  90. PR_EXTERN(int)
  91. JSJ_IsEnabled(void);
  92.  
  93. /* Java threads call this to find the JSContext to use for
  94.  * executing JavaScript */
  95. PR_EXTERN(JSContext *)
  96. JSJ_CurrentContext(JRIEnv *env, char **errp);
  97.  
  98. /* Java threads call this before executing JS code (to preserve
  99.  * run-to-completion in the client */
  100. PR_EXTERN(void)
  101. JSJ_EnterJS(void);
  102.  
  103. /* Java threads call this when finished executing JS code */
  104. PR_EXTERN(void)
  105. JSJ_ExitJS(void);
  106.  
  107. /* gets a default netscape.javascript.JSObject from a java object */
  108. PR_EXTERN(JSObject *)
  109. JSJ_GetDefaultObject(JRIEnv *env, jobject hint);
  110.  
  111. /*
  112.  * When crawling the Java stack, this indicates that the next frames
  113.  * are in JavaScript
  114.  */
  115. struct methodblock;
  116. PR_EXTERN(JSBool)
  117. JSJ_IsSafeMethod(struct methodblock *mb);
  118.  
  119. PR_EXTERN(JSBool)
  120. JSJ_IsCalledFromJava(JSContext *cx);
  121.  
  122. /* find the current JSContext, if possible.  if cxp is null,
  123.  * the caller may attempt to infer the JSContext from the
  124.  * classloader */
  125. PR_EXTERN(void)
  126. JSJ_FindCurrentJSContext(JRIEnv *env, JSContext **cxp, void **loaderp);
  127.  
  128. /* extract the javascript object from a netscape.javascript.JSObject */
  129. PR_EXTERN(JSObject *)
  130. JSJ_ExtractInternalJSObject(JRIEnv *env, HObject* jso);
  131.  
  132. /* provided for use by java calling javascript: */
  133.  
  134. PR_EXTERN(JSObject *)
  135. js_ReflectJObjectToJSObject(JSContext *cx, HObject *jo);
  136.  
  137. extern JSObject *
  138. js_ReflectJClassToJSObject(JSContext *cx, ClassClass *clazz);
  139.  
  140. PR_EXTERN(HObject *)
  141. js_ReflectJSObjectToJObject(JSContext *cx, JSObject *mo);
  142.  
  143. /* this JS error reporter saves the error for JSErrorToJException */
  144. PR_EXTERN(void)
  145. js_JavaErrorReporter(JSContext *cx, const char *message, JSErrorReport *error);
  146.  
  147. /* if there was an error in JS, throw the corresponding JSException */
  148. PR_EXTERN(void)
  149. js_JSErrorToJException(JSContext *cx, ExecEnv *ee);
  150.  
  151. PR_EXTERN(void)
  152. js_RemoveReflection(JSContext *cx, JSObject *mo);
  153.  
  154. PR_EXTERN(JSBool)
  155. js_convertJObjectToJSValue(JSContext *cx, jsval *vp, HObject *ho);
  156.  
  157. PR_EXTERN(JSBool)
  158. js_convertJSValueToJObject(HObject **objp, JSContext *cx,
  159.                jsval v, char *sig, ClassClass *fromclass,
  160.                JSBool checkOnly, int *cost);
  161.  
  162. PR_EXTERN(JSPrincipals *)
  163. js_GetJSPrincipalsFromJavaCaller(JSContext *cx, int callerDepth);
  164.  
  165. PR_EXTERN(void)
  166. jsj_ClearSavedErrors(JSContext *cx);
  167.  
  168. #endif /* defined(JAVA) */
  169.  
  170. #endif /* _jsjava_h_ */
  171.