本文整理汇总了C++中JS_IsExceptionPending函数的典型用法代码示例。如果您正苦于以下问题:C++ JS_IsExceptionPending函数的具体用法?C++ JS_IsExceptionPending怎么用?C++ JS_IsExceptionPending使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JS_IsExceptionPending函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: xpc_qsXPCOMObjectToJsval
JSBool
xpc_qsXPCOMObjectToJsval(XPCLazyCallContext &lccx, nsISupports *p,
nsWrapperCache *cache, const nsIID *iid,
XPCNativeInterface **iface, jsval *rval)
{
// From the T_INTERFACE case in XPCConvert::NativeData2JS.
// This is one of the slowest things quick stubs do.
JSContext *cx = lccx.GetJSContext();
if(!iface)
return xpc_qsThrow(cx, NS_ERROR_XPC_BAD_CONVERT_NATIVE);
// XXX The OBJ_IS_NOT_GLOBAL here is not really right. In
// fact, this code is depending on the fact that the
// global object will not have been collected, and
// therefore this NativeInterface2JSObject will not end up
// creating a new XPCNativeScriptableShared.
nsresult rv;
if(!XPCConvert::NativeInterface2JSObject(lccx, rval, nsnull, p,
iid, iface, cache,
lccx.GetCurrentJSObject(), PR_TRUE,
OBJ_IS_NOT_GLOBAL, &rv))
{
// I can't tell if NativeInterface2JSObject throws JS exceptions
// or not. This is a sloppy stab at the right semantics; the
// method really ought to be fixed to behave consistently.
if(!JS_IsExceptionPending(cx))
xpc_qsThrow(cx, NS_FAILED(rv) ? rv : NS_ERROR_UNEXPECTED);
return JS_FALSE;
}
#ifdef DEBUG
JSObject* jsobj = JSVAL_TO_OBJECT(*rval);
if(jsobj && !STOBJ_GET_PARENT(jsobj))
NS_ASSERTION(STOBJ_GET_CLASS(jsobj)->flags & JSCLASS_IS_GLOBAL,
"Why did we recreate this wrapper?");
#endif
return JS_TRUE;
}
示例2: NativeInterface2JSObjectAndThrowIfFailed
static bool
NativeInterface2JSObjectAndThrowIfFailed(XPCLazyCallContext& aLccx,
JSContext* aCx,
JS::Value* aRetval,
xpcObjectHelper& aHelper,
const nsIID* aIID,
bool aAllowNativeWrapper)
{
nsresult rv;
if (!XPCConvert::NativeInterface2JSObject(aLccx, aRetval, NULL, aHelper, aIID,
NULL, aAllowNativeWrapper, &rv)) {
// I can't tell if NativeInterface2JSObject throws JS exceptions
// or not. This is a sloppy stab at the right semantics; the
// method really ought to be fixed to behave consistently.
if (!JS_IsExceptionPending(aCx)) {
Throw<true>(aCx, NS_FAILED(rv) ? rv : NS_ERROR_UNEXPECTED);
}
return false;
}
return true;
}
示例3: ThrowExceptionObject
// static
void
XPCThrower::BuildAndThrowException(JSContext* cx, nsresult rv, const char* sz)
{
JSBool success = JS_FALSE;
/* no need to set an expection if the security manager already has */
if(rv == NS_ERROR_XPC_SECURITY_MANAGER_VETO && JS_IsExceptionPending(cx))
return;
nsCOMPtr<nsIException> finalException;
nsCOMPtr<nsIException> defaultException;
nsXPCException::NewException(sz, rv, nsnull, nsnull, getter_AddRefs(defaultException));
XPCPerThreadData* tls = XPCPerThreadData::GetData(cx);
if(tls)
{
nsIExceptionManager * exceptionManager = tls->GetExceptionManager();
if(exceptionManager)
{
// Ask the provider for the exception, if there is no provider
// we expect it to set e to null
exceptionManager->GetExceptionFromProvider(
rv,
defaultException,
getter_AddRefs(finalException));
// We should get at least the defaultException back,
// but just in case
if(finalException == nsnull)
{
finalException = defaultException;
}
}
}
// XXX Should we put the following test and call to JS_ReportOutOfMemory
// inside this test?
if(finalException)
success = ThrowExceptionObject(cx, finalException);
// If we weren't able to build or throw an exception we're
// most likely out of memory
if(!success)
JS_ReportOutOfMemory(cx);
}
示例4: Throw
bool
Throw(JSContext* aCx, nsresult aRv, const char* aMessage)
{
if (JS_IsExceptionPending(aCx)) {
// Don't clobber the existing exception.
return false;
}
CycleCollectedJSRuntime* runtime = CycleCollectedJSRuntime::Get();
nsCOMPtr<nsIException> existingException = runtime->GetPendingException();
if (existingException) {
nsresult nr;
if (NS_SUCCEEDED(existingException->GetResult(&nr)) &&
aRv == nr) {
// Reuse the existing exception.
// Clear pending exception
runtime->SetPendingException(nullptr);
if (!ThrowExceptionObject(aCx, existingException)) {
// If we weren't able to throw an exception we're
// most likely out of memory
JS_ReportOutOfMemory(aCx);
}
return false;
}
}
nsRefPtr<Exception> finalException = CreateException(aCx, aRv, aMessage);
MOZ_ASSERT(finalException);
if (!ThrowExceptionObject(aCx, finalException)) {
// If we weren't able to throw an exception we're
// most likely out of memory
JS_ReportOutOfMemory(aCx);
}
return false;
}
示例5: js_cocos2dx_audioengine_AudioEngine_setFinishCallback
bool js_cocos2dx_audioengine_AudioEngine_setFinishCallback(JSContext *cx, uint32_t argc, jsval *vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
bool ok = true;
if (argc == 2) {
int arg0;
std::function<void (int, const std::basic_string<char> &)> arg1;
ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0);
do {
if(JS_TypeOfValue(cx, args.get(1)) == JSTYPE_FUNCTION)
{
std::shared_ptr<JSFunctionWrapper> func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(1)));
auto lambda = [=](int larg0, const std::basic_string<char> & larg1) -> void {
JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET
jsval largv[2];
largv[0] = int32_to_jsval(cx, larg0);
largv[1] = std_string_to_jsval(cx, larg1);
JS::RootedValue rval(cx);
bool succeed = func->invoke(2, &largv[0], &rval);
if (!succeed && JS_IsExceptionPending(cx)) {
JS_ReportPendingException(cx);
}
};
arg1 = lambda;
}
else
{
arg1 = nullptr;
}
} while(0)
;
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_audioengine_AudioEngine_setFinishCallback : Error processing arguments");
cocos2d::experimental::AudioEngine::setFinishCallback(arg0, arg1);
args.rval().setUndefined();
return true;
}
JS_ReportError(cx, "js_cocos2dx_audioengine_AudioEngine_setFinishCallback : wrong number of arguments");
return false;
}
示例6: js_cocos2dx_nativehelper_NativeHelper_setCallBack
bool js_cocos2dx_nativehelper_NativeHelper_setCallBack(JSContext *cx, uint32_t argc, jsval *vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
bool ok = true;
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
js_proxy_t *proxy = jsb_get_js_proxy(obj);
cocos2d::NativeHelper* cobj = (cocos2d::NativeHelper *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_nativehelper_NativeHelper_setCallBack : Invalid Native Object");
if (argc == 1) {
std::function<void ()> arg0;
do {
if(JS_TypeOfValue(cx, args.get(0)) == JSTYPE_FUNCTION)
{
std::shared_ptr<JSFunctionWrapper> func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(0)));
auto lambda = [=]() -> void {
JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET
JS::RootedValue rval(cx);
bool ok = func->invoke(0, nullptr, &rval);
if (!ok && JS_IsExceptionPending(cx)) {
JS_ReportPendingException(cx);
}
};
arg0 = lambda;
}
else
{
arg0 = nullptr;
}
} while(0)
;
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_nativehelper_NativeHelper_setCallBack : Error processing arguments");
cobj->setCallBack(arg0);
args.rval().setUndefined();
return true;
}
JS_ReportError(cx, "js_cocos2dx_nativehelper_NativeHelper_setCallBack : wrong number of arguments: %d, was expecting %d", argc, 1);
return false;
}
示例7: Throw
bool
Throw(JSContext* aCx, nsresult aRv, const nsACString& aMessage)
{
if (aRv == NS_ERROR_UNCATCHABLE_EXCEPTION) {
// Nuke any existing exception on aCx, to make sure we're uncatchable.
JS_ClearPendingException(aCx);
return false;
}
if (JS_IsExceptionPending(aCx)) {
// Don't clobber the existing exception.
return false;
}
CycleCollectedJSContext* context = CycleCollectedJSContext::Get();
nsCOMPtr<nsIException> existingException = context->GetPendingException();
// Make sure to clear the pending exception now. Either we're going to reuse
// it (and we already grabbed it), or we plan to throw something else and this
// pending exception is no longer relevant.
context->SetPendingException(nullptr);
// Ignore the pending exception if we have a non-default message passed in.
if (aMessage.IsEmpty() && existingException) {
nsresult nr;
if (NS_SUCCEEDED(existingException->GetResult(&nr)) &&
aRv == nr) {
// Reuse the existing exception.
ThrowExceptionObject(aCx, existingException);
return false;
}
}
RefPtr<Exception> finalException = CreateException(aRv, aMessage);
MOZ_ASSERT(finalException);
ThrowExceptionObject(aCx, finalException);
return false;
}
示例8: evaluate_compiled_script
/*
* call-seq:
* evaluate_compiled_script(script)
*
* Evaluate +script+
*/
static VALUE evaluate_compiled_script(VALUE self, VALUE compiled_script)
{
JohnsonRuntime* runtime;
Data_Get_Struct(self, JohnsonRuntime, runtime);
JSContext * context = johnson_get_current_context(runtime);
JohnsonContext * johnson_context = OUR_CONTEXT(context);
// clean things up first
johnson_context->ex = 0;
memset(johnson_context->msg, 0, MAX_EXCEPTION_MESSAGE_SIZE);
jsval compiled_js;
if(!convert_to_js(runtime, compiled_script, &compiled_js))
rb_raise(rb_eRuntimeError, "Script compilation failed");
JSScript * js_script = (JSScript *)JS_GetPrivate(context, JSVAL_TO_OBJECT(compiled_js));
jsval js;
JSBool ok = JS_ExecuteScript(context, runtime->global, js_script, &js);
if (!ok)
{
if (JS_IsExceptionPending(context))
{
// If there's an exception pending here, it's a syntax error.
JS_GetPendingException(context, &johnson_context->ex);
JS_ClearPendingException(context);
}
if (johnson_context->ex) {
RAISE_JS_ERROR(self, johnson_context->ex);
return Qnil;
}
}
return convert_to_ruby(runtime, js);
}
示例9: js_cocos2dx_CCRichText_addEventListener
static bool js_cocos2dx_CCRichText_addEventListener(JSContext *cx, uint32_t argc, jsval *vp)
{
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy = jsb_get_js_proxy(obj);
CCRichText* cobj = (CCRichText *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");
if(argc == 1){
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
std::shared_ptr<JSFunctionWrapper> func(new JSFunctionWrapper(cx, obj, args.get(0)));
cobj->addEventListener([=](kRichTextState richTextState, int eventId, int x, int y)->bool{
JS::RootedValue rval(cx);
jsval dataVal[4];
dataVal[0] = int32_to_jsval(cx, (int32_t)richTextState);
dataVal[1] = int32_to_jsval(cx,eventId);
dataVal[2] = int32_to_jsval(cx,x);
dataVal[3] = int32_to_jsval(cx,y);
bool ok = func->invoke(4, dataVal, &rval);
if (!ok && JS_IsExceptionPending(cx)) {
JS_ReportPendingException(cx);
}
if(rval.isBoolean())
{
return rval.toBoolean();
}
return false;
});
return true;
}
JS_ReportError(cx, "Invalid number of arguments");
return false;
}
示例10: NORETURN
NORETURN(void) raise_js_error_in_ruby(JohnsonRuntime* runtime)
{
JSContext * context = johnson_get_current_context(runtime);
JohnsonContext * johnson_context = OUR_CONTEXT(context);
if (JS_IsExceptionPending(context))
{
assert(JS_GetPendingException(context, &(johnson_context->ex)));
JS_AddNamedRoot(context, &(johnson_context->ex), "raise_js_error_in_ruby");
JS_ClearPendingException(context);
JS_RemoveRoot(context, &(johnson_context->ex));
}
VALUE ruby_runtime = (VALUE)JS_GetRuntimePrivate(runtime->js);
if (johnson_context->ex)
RAISE_JS_ERROR(ruby_runtime, johnson_context->ex);
// FIXME: I don't think this is needed, it should
// be done on the Ruby side.
if (!johnson_context->msg)
rb_raise(rb_eRuntimeError, "Unknown JavaScriptError");
// FIXME: I don't think this can ever happen....
rb_raise(rb_eRuntimeError, johnson_context->msg);
}
示例11: js_cocos2dx_GraphLayer_addEventListener
static bool js_cocos2dx_GraphLayer_addEventListener(JSContext *cx, uint32_t argc, jsval *vp)
{
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy = jsb_get_js_proxy(obj);
GraphLayer* cobj = (GraphLayer *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");
if(argc == 1){
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
std::shared_ptr<JSFunctionWrapper> func(new JSFunctionWrapper(cx, obj, args.get(0)));
cobj->addEventListener([=](int x)->void{
jsval arg= int32_to_jsval(cx, (int32_t)x);
JS::RootedValue rval(cx);
bool ok = func->invoke(1, &arg, &rval);
if (!ok && JS_IsExceptionPending(cx)) {
JS_ReportPendingException(cx);
}
});
return true;
}
JS_ReportError(cx, "Invalid number of arguments");
return false;
}
示例12: native_compile
/*
* call-seq:
* native_compile(script, filename, linenum)
*
* Compile +script+ with +filename+ using +linenum+
*/
static VALUE native_compile(VALUE self, VALUE script, VALUE filename, VALUE linenum)
{
JohnsonRuntime* runtime;
Data_Get_Struct(self, JohnsonRuntime, runtime);
JSContext * context = johnson_get_current_context(runtime);
JohnsonContext * johnson_context = OUR_CONTEXT(context);
JSScript * compiled_js = JS_CompileScript(
context,
runtime->global,
StringValuePtr(script),
(size_t)StringValueLen(script),
StringValueCStr(filename),
(unsigned)NUM2INT(linenum)
);
if(compiled_js == NULL) {
if (JS_IsExceptionPending(context))
{
// If there's an exception pending here, it's a syntax error.
JS_GetPendingException(context, &johnson_context->ex);
JS_ClearPendingException(context);
}
if (johnson_context->ex) {
RAISE_JS_ERROR(self, johnson_context->ex);
return Qnil;
}
}
JSObject * script_object = JS_NewScriptObject(context, compiled_js);
PREPARE_RUBY_JROOTS(context, 1);
JROOT(script_object);
JRETURN_RUBY(make_ruby_land_proxy(runtime, OBJECT_TO_JSVAL(script_object), "JSScriptProxy"));
}
示例13: NS_ASSERTION
/* nsISupports getService (); */
NS_IMETHODIMP
nsJSCID::GetService(nsISupports **_retval)
{
if(!mDetails.IsValid())
return NS_ERROR_XPC_BAD_CID;
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
if(!xpc)
return NS_ERROR_UNEXPECTED;
nsAXPCNativeCallContext *ccxp = nsnull;
xpc->GetCurrentNativeCallContext(&ccxp);
if(!ccxp)
return NS_ERROR_UNEXPECTED;
PRUint32 argc;
jsval * argv;
jsval * vp;
JSContext* cx;
JSObject* obj;
ccxp->GetJSContext(&cx);
ccxp->GetArgc(&argc);
ccxp->GetArgvPtr(&argv);
ccxp->GetRetValPtr(&vp);
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
ccxp->GetCalleeWrapper(getter_AddRefs(wrapper));
wrapper->GetJSObject(&obj);
// Do the security check if necessary
XPCContext* xpcc = XPCContext::GetXPCContext(cx);
nsIXPCSecurityManager* sm;
sm = xpcc->GetAppropriateSecurityManager(
nsIXPCSecurityManager::HOOK_GET_SERVICE);
if(sm && NS_FAILED(sm->CanCreateInstance(cx, mDetails.ID())))
{
NS_ASSERTION(JS_IsExceptionPending(cx),
"security manager vetoed GetService without setting exception");
return NS_OK;
}
// If an IID was passed in then use it
const nsID* iid = GetIIDArg(argc, argv, cx);
if (!iid)
return NS_ERROR_XPC_BAD_IID;
nsCOMPtr<nsIServiceManager> svcMgr;
nsresult rv = NS_GetServiceManager(getter_AddRefs(svcMgr));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsISupports> srvc;
rv = svcMgr->GetService(mDetails.ID(), *iid, getter_AddRefs(srvc));
NS_ASSERTION(NS_FAILED(rv) || srvc, "service manager returned success, but service is null!");
if(NS_FAILED(rv) || !srvc)
return NS_ERROR_XPC_GS_RETURNED_FAILURE;
JSObject* instJSObj;
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
rv = xpc->WrapNative(cx, obj, srvc, *iid, getter_AddRefs(holder));
if(NS_FAILED(rv) || !holder || NS_FAILED(holder->GetJSObject(&instJSObj)))
return NS_ERROR_XPC_CANT_CREATE_WN;
*vp = OBJECT_TO_JSVAL(instJSObj);
ccxp->SetReturnValueWasSet(JS_TRUE);
return NS_OK;
}
示例14: do_import
//.........这里部分代码省略.........
NULL, NULL,
GJS_MODULE_PROP_FLAGS & ~JSPROP_PERMANENT)) {
result = JS_TRUE;
goto out;
}
}
}
/* Second try importing a directory (a sub-importer) */
if (full_path)
g_free(full_path);
full_path = g_build_filename(dirname, name,
NULL);
if (g_file_test(full_path, G_FILE_TEST_IS_DIR)) {
gjs_debug(GJS_DEBUG_IMPORTER,
"Adding directory '%s' to child importer '%s'",
full_path, name);
if (directories == NULL) {
directories = g_ptr_array_new();
}
g_ptr_array_add(directories, full_path);
/* don't free it twice - pass ownership to ptr array */
full_path = NULL;
}
/* If we just added to directories, we know we don't need to
* check for a file. If we added to directories on an earlier
* iteration, we want to ignore any files later in the
* path. So, always skip the rest of the loop block if we have
* directories.
*/
if (directories != NULL) {
continue;
}
/* Third, if it's not a directory, try importing a file */
g_free(full_path);
full_path = g_build_filename(dirname, filename,
NULL);
if (g_file_test(full_path, G_FILE_TEST_EXISTS)) {
if (import_file(context, obj, name, full_path)) {
gjs_debug(GJS_DEBUG_IMPORTER,
"successfully imported module '%s'", name);
result = JS_TRUE;
}
/* Don't keep searching path if we fail to load the file for
* reasons other than it doesn't exist... i.e. broken files
* block searching for nonbroken ones
*/
goto out;
}
gjs_debug(GJS_DEBUG_IMPORTER,
"JS import '%s' not found in %s",
name, dirname);
}
if (directories != NULL) {
/* NULL-terminate the char** */
g_ptr_array_add(directories, NULL);
if (import_directory(context, obj, name,
(const char**) directories->pdata)) {
gjs_debug(GJS_DEBUG_IMPORTER,
"successfully imported directory '%s'", name);
result = JS_TRUE;
}
}
out:
if (directories != NULL) {
char **str_array;
/* NULL-terminate the char**
* (maybe for a second time, but doesn't matter)
*/
g_ptr_array_add(directories, NULL);
str_array = (char**) directories->pdata;
g_ptr_array_free(directories, FALSE);
g_strfreev(str_array);
}
g_free(full_path);
g_free(filename);
g_free(dirname);
if (!result &&
!JS_IsExceptionPending(context)) {
/* If no exception occurred, the problem is just that we got to the
* end of the path. Be sure an exception is set.
*/
gjs_throw(context, "No JS module '%s' found in search path", name);
}
return result;
}
示例15: import_file
static JSBool
import_file(JSContext *context,
JSObject *obj,
const char *name,
const char *full_path)
{
char *script;
gsize script_len;
JSObject *module_obj;
GError *error;
jsval script_retval;
JSBool retval = JS_FALSE;
gjs_debug(GJS_DEBUG_IMPORTER,
"Importing '%s'", full_path);
module_obj = JS_NewObject(context, NULL, NULL, NULL);
if (module_obj == NULL) {
return JS_FALSE;
}
if (!define_import(context, obj, module_obj, name))
return JS_FALSE;
if (!define_meta_properties(context, module_obj, full_path, name, obj))
goto out;
script_len = 0;
error = NULL;
if (!(g_file_get_contents(full_path, &script, &script_len, &error))) {
if (!g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_ISDIR) &&
!g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_NOTDIR) &&
!g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
gjs_throw_g_error(context, error);
else
g_error_free(error);
goto out;
}
g_assert(script != NULL);
if (!JS_EvaluateScript(context,
module_obj,
script,
script_len,
full_path,
1, /* line number */
&script_retval)) {
g_free(script);
/* If JSOPTION_DONT_REPORT_UNCAUGHT is set then the exception
* would be left set after the evaluate and not go to the error
* reporter function.
*/
if (JS_IsExceptionPending(context)) {
gjs_debug(GJS_DEBUG_IMPORTER,
"Module '%s' left an exception set",
name);
gjs_log_and_keep_exception(context);
} else {
gjs_throw(context,
"JS_EvaluateScript() returned FALSE but did not set exception");
}
goto out;
}
g_free(script);
if (!finish_import(context, name))
goto out;
if (!seal_import(context, obj, name))
goto out;
retval = JS_TRUE;
out:
if (!retval)
cancel_import(context, obj, name);
return retval;
}