本文整理汇总了C++中JSStackFrame::hasScript方法的典型用法代码示例。如果您正苦于以下问题:C++ JSStackFrame::hasScript方法的具体用法?C++ JSStackFrame::hasScript怎么用?C++ JSStackFrame::hasScript使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSStackFrame
的用法示例。
在下文中一共展示了JSStackFrame::hasScript方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ThrowException
// If you change this code, change also nsContentUtils::CanAccessNativeAnon()!
JSBool
AllowedToAct(JSContext *cx, jsid id)
{
// TODO bug 508928: Refactor this with the XOW security checking code.
nsIScriptSecurityManager *ssm = GetSecurityManager();
if (!ssm) {
return JS_TRUE;
}
JSStackFrame *fp;
nsIPrincipal *principal = ssm->GetCxSubjectPrincipalAndFrame(cx, &fp);
if (!principal) {
return ThrowException(NS_ERROR_UNEXPECTED, cx);
}
if (!fp) {
if (!JS_FrameIterator(cx, &fp)) {
// No code at all is running. So we must be arriving here as the result
// of C++ code asking us to do something. Allow access.
return JS_TRUE;
}
// Some code is running, we can't make the assumption, as above, but we
// can't use a native frame, so clear fp.
fp = nsnull;
} else if (!fp->hasScript()) {
fp = nsnull;
}
PRBool privileged;
if (NS_SUCCEEDED(ssm->IsSystemPrincipal(principal, &privileged)) &&
privileged) {
// Chrome things are allowed to touch us.
return JS_TRUE;
}
// XXX HACK EWW! Allow chrome://global/ access to these things, even
// if they've been cloned into less privileged contexts.
const char *filename;
if (fp &&
(filename = fp->getScript()->filename) &&
!strncmp(filename, prefix, NS_ARRAY_LENGTH(prefix) - 1)) {
return JS_TRUE;
}
// Before we throw, check for UniversalXPConnect.
nsresult rv = ssm->IsCapabilityEnabled("UniversalXPConnect", &privileged);
if (NS_SUCCEEDED(rv) && privileged) {
return JS_TRUE;
}
if (JSID_IS_VOID(id)) {
ThrowException(NS_ERROR_XPC_SECURITY_MANAGER_VETO, cx);
} else {
// TODO Localize me?
jsval idval;
JSString *str;
if (JS_IdToValue(cx, id, &idval) && (str = JS_ValueToString(cx, idval))) {
JS_ReportError(cx, "Permission denied to access property '%hs' from a non-chrome context",
JS_GetStringChars(str));
}
}
return JS_FALSE;
}