Components object 编辑

Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

Warning: This object is only intended for code running with chrome privileges. Exposing the object to regular web code was a mistake. If you use this object on your web page, your site might break at any time! In current versions of Firefox only a few interfaces required for compatibility are still accessible. Don't use Components!

The Components object is the object through which XPConnect functionality is reflected into JavaScript. The Components object is actually a native instance of the nsIXPCComponents interface which is reflected into JavaScript as a top level object using XPConnect.

Some properties of Components require advanced privileges and may not work in web pages.

The Components object has the following members:

classes
array of classes by ContractID
classesByID
array of classes by CID
Constructor
constructor for constructor of components
Exception
constructor for XPConnect exceptions
ID
constructor for XPCOM nsIDs
interfaces
array of interfaces by interface name
interfacesByID
array of interfaces by IID
isSuccessCode
function to determine if a given result code is a success code
lastResult
result code of most recent XPConnect call
manager
the global XPCOM component manager
results
array of known result codes by name
returnCode
pending result for current call
stack
current JavaScript call stack
utils
provides access to several useful features
utils.atline
Provides access to the value of the atline property in the JavaScript environment.
utils.createObjectIn
Creates a new object in the scope of the specified object's compartment. May only be called from JavaScript code.
utils.evalInSandbox
Runs JavaScript code in a sandbox, usually used to run code with restricted privileges.
utils.forceGC
Forces a garbage collection cycle.
utils.getGlobalForObject 
Returns the global object with which a given object is associated (through its prototype chain at birth, for example).
utils.getWeakReference 
Gets a weak reference for the object passed in.
utils.import 
Loads a JavaScript module into the current script, without sharing a scope.
utils.lookupMethod
Looks up a native (i.e. declared in the interface) method or property of an XPCOM object. Serves the same purpose as XPCNativeWrapper.
utils.makeObjectPropsNormal
Ensures that all functions come from the specified object's scope, and aren't cross-compartment wrappers. May only be called from JavaScript code.
utils.methodjit Obsolete since Gecko 24.0
Provides access to the value of the methodjit property in the JavaScript environment.
utils.methodjit_always Obsolete since Gecko 24.0
Provides access to the value of the methodjit_always property in the JavaScript environment.
utils.relimit
Provides access to the value of the relimit property in the JavaScript environment.
utils.reportError
Reports a JavaScript Error object to the Error Console.
utils.schedulePreciseGC
Requests that garbage collection occur sometime in the future when no JavaScript code is running; accepts a callback function to receive notification once collection is complete.
utils.setGCZeal()
Sets the GC zeal level for the context.
utils.strict
Provides access to the value of the strict property in the JavaScript environment.
utils.werror
Provides access to the value of the werror property in the JavaScript environment.
utils.Sandbox
Creates sandbox objects for use with evalInSandbox.
utils.xml
Provides access to the value of the xml property in the JavaScript environment.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:48 次

字数:8164

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文