Components.utils 编辑

Components.utils is a collection of various useful XPConnect features. Its interface is defined at js/xpconnect/idl/xpccomponents.idl.

The object currently has the following members:

EDITORS! please keep this list in sync with the Components object page

Methods

MethodDescription
cloneInto()Create a structured clone of an object in a different JavaScript context.
createArrayIn()

Removed in Gecko 31

Returns an array created in specified compartment.

createObjectIn()Creates a new object, created in the scope of the specified object's compartment.
dispatch()Dispatches a runnable to the current/main thread. If the parameter is passed, the runnable will be dispatch in the compartment of the parameter, which affects which error reporter gets called.
evalInSandbox()Runs JavaScript code in a sandbox, usually used to run code with restricted privileges.
evalInWindow()

Removed in Gecko 34.

Evaluate JavaScript code in a less-privileged JavaScript context.

exportFunction()Export a JavaScript function from a more-privileged to a less-privileged scope, allowing it to be called in the less-privileged scope.
forceGC()Forces a garbage collection cycle.
forceCC()Forces a cycle collection cycle.
forceShrinkingGC()Forces a shrinking garbage collection cycle.
getComponentsForScope()This seemingly-paradoxical API allows privileged code to explicitly give unprivileged code a reference to its own Components object (whereas it's normally hidden away on a scope chain visible only to XBL methods). See also SpecialPowers.getComponents.
getGlobalForObject()Returns the global object with which a given object is associated (through its prototype chain at birth, for example).
getJSTestingFunctions()
getObjectPrincipal()Gets the nsIPrincipal for the given JavaScript object.
getWeakReference()Gets a weak reference for the object passed in.
import()Loads a JS module into the current script, without sharing a scope.
importGlobalProperties()Specify a list of constructors to import into the scope.
isXrayWrapper()Test whether a given object is an Xray or not.
unload()Unloads a JS module loaded with import().
isDeadWrapper()Determines whether this object is backed by a DeadObjectProxy.
lookupMethod()Looks up a native (i.e. declared in the interface) method or property of an XPCOM object. Serves the same purpose as XPCNativeWrapper.
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.
nondeterministicGetWeakMapKeys()

Return the keys in a weak map. This operation is non-deterministic because it is affected by the scheduling of the garbage collector and the cycle collector. This should only be used to write tests of the interaction of the GC and CC with weak maps.

Obsolete since Gecko 45 the function was moved to ThreadSafeChromeUtils

nukeSandbox()
recomputeWrappers()To be called from JS only. This is for Gecko internal use only, and may disappear at any moment.
reportError()Reports a JavaScript Error object to the Error Console.
setWantXrays()To be called from JS only. This is for Gecko internal use only, and may disappear at any moment.
schedulePreciseGC()Schedules a garbage collection cycle for some time in the future at which no JavaScript code is running. This lets you specify a callback so you can be notified once the garbage collection cycle has been performed.
setGCZeal()Sets the level of garbage collection level for full garbage collection. See JS_SetGCZeal for details; this method calls through to that with the specified value as the zeal value.
unwaiveXrays()Undoes waiveXrays(): reapplies the Xray filtering protection.
waiveXrays()Removes the filtering provided by an Xray.

Properties

PropertyTypeDescription
SandboxnsIXPCComponents_utils_SandboxCreates sandbox objects for use with evalInSandbox().
ionBooleanRead only.
strictBooleanStrict mode is enabled. This reflects the value of the JavaScript environment's option by the same name. Read only.
strict_modeBooleanRead only.
werrorBooleanWarnings should be treated as errors. This reflects the value of the JavaScript environment's option by the same name. Read only.

 

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

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

发布评论

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

词条统计

浏览:104 次

字数:9158

最后编辑:8年前

编辑次数:0 次

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