зеркало из https://github.com/mozilla/gecko-dev.git
Bug 381693 - Allow null targetObj arg to xpcIJSModuleLoader::import().
r=sayrer, src=brendan.
This commit is contained in:
Родитель
fe1aace69e
Коммит
c30fbd2d20
|
@ -56,18 +56,22 @@ interface xpcIJSModuleLoader : nsISupports
|
|||
*
|
||||
* Synchronously loads and evaluates the js file located at
|
||||
* 'registryLocation' with a new, fully privileged global object.
|
||||
* After loading, looks for a property 'EXPORTED_SYMBOLS' on the
|
||||
* new global object. 'EXPORTED_SYMBOLS' is expected to be an
|
||||
* array of strings identifying properties on the global object.
|
||||
* If present, these properties will be installed as properties on
|
||||
* targetObj, or, if 'targetObj' is not specified, on the caller's
|
||||
* global object.
|
||||
*
|
||||
* If 'targetObj' is specified and equal to null, returns the
|
||||
* module's global object. Otherwise (if 'targetObj' is not
|
||||
* specified, or 'targetObj' is != null) looks for a property
|
||||
* 'EXPORTED_SYMBOLS' on the new global object. 'EXPORTED_SYMBOLS'
|
||||
* is expected to be an array of strings identifying properties on
|
||||
* the global object. These properties will be installed as
|
||||
* properties on 'targetObj', or, if 'targetObj' is not specified,
|
||||
* on the caller's global object. If 'EXPORTED_SYMBOLS' is not
|
||||
* found, an error is thrown.
|
||||
*
|
||||
* @param resourceURI A resource:// URI string to load the module from.
|
||||
* @param targetObj the object to install the exported properties on.
|
||||
* If this parameter is null or is a primitive value, this
|
||||
* method throws an exception.
|
||||
* @returns the new global object the module code was loaded into.
|
||||
* If this parameter is a primitive value, this method throws
|
||||
* an exception.
|
||||
* @returns the module code's global object.
|
||||
*
|
||||
* The implementation maintains a hash of registryLocation->global obj.
|
||||
* Subsequent invocations of importModule with 'registryLocation'
|
||||
|
|
|
@ -176,18 +176,22 @@ interface nsIXPCComponents_Utils : nsISupports
|
|||
*
|
||||
* Synchronously loads and evaluates the js file located at
|
||||
* 'registryLocation' with a new, fully privileged global object.
|
||||
* After loading, looks for a property 'EXPORTED_SYMBOLS' on the
|
||||
* new global object. 'EXPORTED_SYMBOLS' is expected to be an
|
||||
* array of strings identifying properties on the global object.
|
||||
* If present, these properties will be installed as properties on
|
||||
* targetObj, or, if 'targetObj' is not specified, on the caller's
|
||||
* global object.
|
||||
*
|
||||
* If 'targetObj' is specified and equal to null, returns the
|
||||
* module's global object. Otherwise (if 'targetObj' is not
|
||||
* specified, or 'targetObj' is != null) looks for a property
|
||||
* 'EXPORTED_SYMBOLS' on the new global object. 'EXPORTED_SYMBOLS'
|
||||
* is expected to be an array of strings identifying properties on
|
||||
* the global object. These properties will be installed as
|
||||
* properties on 'targetObj', or, if 'targetObj' is not specified,
|
||||
* on the caller's global object. If 'EXPORTED_SYMBOLS' is not
|
||||
* found, an error is thrown.
|
||||
*
|
||||
* @param resourceURI A resource:// URI string to load the module from.
|
||||
* @param targetObj the object to install the exported properties on.
|
||||
* If this parameter is null or is a primitive value, this
|
||||
* method throws an exception.
|
||||
* @returns the new global object the module code was loaded into.
|
||||
* If this parameter is a primitive value, this method throws
|
||||
* an exception.
|
||||
* @returns the module code's global object.
|
||||
*
|
||||
* The implementation maintains a hash of registryLocation->global obj.
|
||||
* Subsequent invocations of importModule with 'registryLocation'
|
||||
|
|
|
@ -1348,11 +1348,11 @@ mozJSComponentLoader::Import(const nsACString & registryLocation)
|
|||
jsval *argv = nsnull;
|
||||
rv = cc->GetArgvPtr(&argv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (JSVAL_IS_PRIMITIVE(argv[1]) ||
|
||||
!JS_ValueToObject(cx, argv[1], &targetObject)) {
|
||||
if (!JSVAL_IS_OBJECT(argv[1])) {
|
||||
return ReportOnCaller(cc, ERROR_SCOPE_OBJ,
|
||||
PromiseFlatCString(registryLocation).get());
|
||||
}
|
||||
targetObject = JSVAL_TO_OBJECT(argv[1]);
|
||||
} else {
|
||||
// Our targetObject is the caller's global object. Find it by
|
||||
// walking the calling object's parent chain.
|
||||
|
|
|
@ -74,5 +74,15 @@ function run_test() {
|
|||
true,
|
||||
"NS_ERROR_ILLEGAL_VALUE");
|
||||
|
||||
// check that we can access modules' global objects even if
|
||||
// EXPORTED_SYMBOLS is missing or ill-formed:
|
||||
do_check_eq(typeof(Components.utils.import("resource://test/bogus_exports_type.jsm",
|
||||
null)),
|
||||
"object");
|
||||
|
||||
do_check_eq(typeof(Components.utils.import("resource://test/bogus_element_type.jsm",
|
||||
null)),
|
||||
"object");
|
||||
|
||||
resProt.setSubstitution("test", null);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,17 @@ function run_test() {
|
|||
do_check_eq(typeof(scope.XPCOMUtils), "object");
|
||||
do_check_eq(typeof(scope.XPCOMUtils.generateModule), "function");
|
||||
|
||||
// try again on the global object
|
||||
// access module's global object directly without importing any
|
||||
// symbols
|
||||
var module = Components.utils.import("resource://gre/modules/XPCOMUtils.jsm",
|
||||
null);
|
||||
do_check_eq(typeof(XPCOMUtils), "undefined");
|
||||
do_check_eq(typeof(module), "object");
|
||||
do_check_eq(typeof(module.XPCOMUtils), "object");
|
||||
do_check_eq(typeof(module.XPCOMUtils.generateModule), "function");
|
||||
do_check_true(scope.XPCOMUtils == module.XPCOMUtils);
|
||||
|
||||
// import symbols to our global object
|
||||
do_check_eq(typeof(Components.utils.import), "function");
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
do_check_eq(typeof(XPCOMUtils), "object");
|
||||
|
|
Загрузка…
Ссылка в новой задаче