if (wrapper_global != ::JS_GetGlobalObject(cx)) {    return PR_TRUE; }
documentNeedsSecurityCheck(JSContext *cx, nsIXPConnectWrappedNative *wrapper){  // We cache a pointer to a wrapper and a context that we've last vetted  // and cache what the verdict was.  if (cx == cached_doc_cx && wrapper == cached_doc_wrapper) {    return cached_doc_needs_check;  }  cached_doc_cx = cx;  cached_doc_wrapper = wrapper;  cached_doc_needs_check = PR_TRUE;    // Get the JS object from the wrapper  JSObject *wrapper_obj = nsnull;  wrapper->GetJSObject(&wrapper_obj);  JSObject *wrapper_global = GetGlobalJSObject(cx, wrapper_obj);#ifdef DEBUG  {    JSClass *clazz = JS_GET_CLASS(cx, wrapper_obj);    NS_ASSERTION(clazz && clazz->flags & JSCLASS_HAS_PRIVATE &&                 clazz->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS,                 "Bad class for Document object!");  }#endif  if (wrapper_global != ::JS_GetGlobalObject(cx)) {    // cx is not the context in the global object in wrapper, force    // a security check.    return PR_TRUE;  }  // Check if the calling function comes from the same scope that the  // wrapper comes from. If that's the case, or if there's no JS  // running at the moment (i.e. someone is using the JS engine API  // directly to access a property on a JS object) there's no need to  // do a security check.  JSObject *function_obj = nsnull;  JSStackFrame *fp = nsnull;  do {    fp = ::JS_FrameIterator(cx, &fp);    if (!fp) {      if (!function_obj) {        // No JS is running (there's no frame on the JS stack with a        // function object), someone is just accessing properties on a        // JS object using the JS API, no need to do security checks        // then.        // Since the scope chain is immutable, it's OK to keep        // skipping the check        cached_doc_needs_check = PR_FALSE;        return PR_FALSE;      }      break;    }    function_obj = ::JS_GetFrameFunctionObject(cx, fp);  } while (!function_obj);  // Get the global object that the calling function comes from.  JSObject *function_global = GetGlobalJSObject(cx, function_obj);  if (function_global != wrapper_global) {    // The global object we're trying to access a property on is not    // from the scope that the calling function comes from. Do a    // security check.    return PR_TRUE;  }  // We're called from the same context as the context in the global  // object in the scope that wrapper came from, no need to do a  // security check now.  cached_doc_needs_check = PR_FALSE;  return PR_FALSE;}