📄 jsj_utils.c
字号:
return; err_jsstr = JS_NewString(cx, err, strlen(err)); if (!err_jsstr) return; JS_SetPendingException(cx, STRING_TO_JSVAL(err_jsstr)); return; } (*jEnv)->ExceptionClear(jEnv); /* Check for JSException */ if (njJSException && (*jEnv)->IsInstanceOf(jEnv, java_exception, njJSException)) { wrapped_exception_type = (*jEnv)->GetIntField(jEnv, java_exception, njJSException_wrappedExceptionType); /* (int) to suppress warning */ if ((int)wrapped_exception_type != JSTYPE_EMPTY) { java_obj = (*jEnv)->GetObjectField(jEnv, java_exception, njJSException_wrappedException); if ((java_obj == NULL) && (wrapped_exception_type == JSTYPE_OBJECT)) { js_exception = JSVAL_NULL; } else { java_class = (*jEnv)->GetObjectClass(jEnv, java_obj); class_descriptor = jsj_GetJavaClassDescriptor(cx, jEnv, java_class); /* OK to delete ref, since above call adds global ref */ (*jEnv)->DeleteLocalRef(jEnv, java_class); /* Convert native JS values back to native types. */ switch(wrapped_exception_type) { case JSTYPE_NUMBER: if (!jsj_ConvertJavaObjectToJSNumber(cx, jEnv, class_descriptor, java_obj, &js_exception)) goto error; break; case JSTYPE_BOOLEAN: if (!jsj_ConvertJavaObjectToJSBoolean(cx, jEnv, class_descriptor, java_obj, &js_exception)) goto error; break; case JSTYPE_STRING: if (!jsj_ConvertJavaObjectToJSString(cx, jEnv, class_descriptor, java_obj, &js_exception)) goto error; break; case JSTYPE_VOID: js_exception = JSVAL_VOID; break; case JSTYPE_OBJECT: case JSTYPE_FUNCTION: default: if ((*jEnv)->IsInstanceOf(jEnv, java_obj, njJSObject)) { js_exception = OBJECT_TO_JSVAL(jsj_UnwrapJSObjectWrapper(jEnv, java_obj)); if (!js_exception) goto error; } else { if (!jsj_ConvertJavaObjectToJSValue(cx, jEnv, java_obj, &js_exception)) goto error; } } } } /* Check for internal exception */ } else { if (!JSJ_ConvertJavaObjectToJSValue(cx, java_exception, &js_exception)) { goto error; } } /* Set pending JS exception and clear the java exception. */ JS_SetPendingException(cx, js_exception); goto done;error: JS_ASSERT(0); jsj_LogError("Out of memory while attempting to throw JSException\n"); done: if (class_descriptor) jsj_ReleaseJavaClassDescriptor(cx, jEnv, class_descriptor); if (java_obj) (*jEnv)->DeleteLocalRef(jEnv, java_obj); if (java_exception) (*jEnv)->DeleteLocalRef(jEnv, java_exception);}voidjsj_ReportJavaError(JSContext *cx, JNIEnv *env, const char *format, ...){ va_list ap; va_start(ap, format); vreport_java_error(cx, env, format, ap); va_end(ap);}/* * Same as jsj_ReportJavaError, except "internal error: " is prepended * to message. */voidjsj_UnexpectedJavaError(JSContext *cx, JNIEnv *env, const char *format, ...){ va_list ap; const char *format2; va_start(ap, format); format2 = JS_smprintf("internal error: %s", format); if (format2) { vreport_java_error(cx, env, format2, ap); free((void*)format2); } va_end(ap);}/* * Most LiveConnect errors are signaled by calling JS_ReportError(), * but in some circumstances, the target JSContext for such errors * is not determinable, e.g. during initialization. In such cases * any error messages are routed to this function. */voidjsj_LogError(const char *error_msg){ if (JSJ_callbacks && JSJ_callbacks->error_print) JSJ_callbacks->error_print(error_msg); else fputs(error_msg, stderr);}/* Error number handling. jsj_ErrorFormatString is an array of format strings mapped by error number. It is initialized by the contents of jsj.msg jsj_GetErrorMessage is invoked by the engine whenever it wants to convert an error number into an error format string.*//* this define needs to go somewhere sensible*/#define JSJ_HAS_DFLT_MSG_STRINGS 1JSErrorFormatString jsj_ErrorFormatString[JSJ_Err_Limit] = {#if JSJ_HAS_DFLT_MSG_STRINGS#define MSG_DEF(name, number, count, format) \ { format, count } ,#else#define MSG_DEF(name, number, count, format) \ { NULL, count } ,#endif#include "jsj.msg"#undef MSG_DEF};const JSErrorFormatString *jsj_GetErrorMessage(void *userRef, const char *locale, const uintN errorNumber){ if ((errorNumber > 0) && (errorNumber < JSJ_Err_Limit)) return &jsj_ErrorFormatString[errorNumber]; else return NULL;}jsizejsj_GetJavaArrayLength(JSContext *cx, JNIEnv *jEnv, jarray java_array){ jsize array_length = (*jEnv)->GetArrayLength(jEnv, java_array); jthrowable java_exception = (*jEnv)->ExceptionOccurred(jEnv); if (java_exception) { jsj_UnexpectedJavaError(cx, jEnv, "Couldn't obtain array length"); (*jEnv)->DeleteLocalRef(jEnv, java_exception); return -1; } return array_length;}static JSJavaThreadState *the_java_jsj_env = NULL;JSJavaThreadState *jsj_EnterJava(JSContext *cx, JNIEnv **envp){ JSJavaThreadState *jsj_env; char *err_msg; *envp = NULL; err_msg = NULL; jsj_env = the_java_jsj_env; if (jsj_env == NULL && JSJ_callbacks && JSJ_callbacks->map_js_context_to_jsj_thread) jsj_env = JSJ_callbacks->map_js_context_to_jsj_thread(cx, &err_msg); if (!jsj_env) { if (err_msg) { JS_ReportError(cx, err_msg); free(err_msg); } return NULL; } /* simultaneous calls from different JSContext are not allowed */ if ((jsj_env->recursion_depth > 0) && (jsj_env->cx != cx)) return NULL; jsj_env->recursion_depth++; /* bug #60018: prevent dangling pointer to JSContext */ if (!jsj_env->cx) jsj_env->cx = cx; if (envp) *envp = jsj_env->jEnv; return jsj_env;}extern voidjsj_ExitJava(JSJavaThreadState *jsj_env){ jsj_JSIsCallingApplet = JS_FALSE; if (jsj_env) { JS_ASSERT(jsj_env->recursion_depth > 0); if (--jsj_env->recursion_depth == 0) jsj_env->cx = NULL; }}/** * Since only one Java thread is allowed to enter JavaScript, this function is * used to enforce the use of that thread's state. The static global the_java_jsj_env * overrides using JSJ_callbacks->map_js_context_to_jsj_thread, which maps * native threads to JSJavaThreadStates. This isn't appropriate when Java calls * JavaScript, as there can be a many to one mapping from Java threads to native * threads. */JSJavaThreadState *jsj_SetJavaJSJEnv(JSJavaThreadState* java_jsj_env){ JSJavaThreadState *old_jsj_env = the_java_jsj_env; the_java_jsj_env = java_jsj_env; return old_jsj_env;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -