def CheckPref(descriptor, globalName, varName, retval, wrapperCache = None):
    """
    Check whether bindings should be enabled for this descriptor.  If not, set
    varName to false and return retval.
    """
    if not descriptor.prefable:
        return ""

    if wrapperCache:
       wrapperCache = "      %s->ClearIsDOMBinding();\n" % (wrapperCache)
    else:
        wrapperCache = ""

    failureCode = ("      %s = false;\n" +
                   "      return %s;") % (varName, retval)
    return """
  {
    XPCWrappedNativeScope* scope =
      XPCWrappedNativeScope::FindInJSObjectScope(aCx, %s);
    if (!scope) {
%s
    }

    if (!scope->ExperimentalBindingsEnabled()) {
%s%s
    }
  }
""" % (globalName, failureCode, wrapperCache, failureCode)