зеркало из https://github.com/mozilla/gecko-dev.git
Bug 287441: add __LOCATION__ property so JS components can tell where they're
loaded from. r=dbradley.
This commit is contained in:
Родитель
f8a0934ba2
Коммит
06528c8adc
|
@ -1025,6 +1025,29 @@ mozJSComponentLoader::GlobalForLocation(const char *aLocation,
|
|||
goto out;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> locationHolder;
|
||||
rv = xpc->WrapNative(cx, global, localFile,
|
||||
NS_GET_IID(nsILocalFile),
|
||||
getter_AddRefs(locationHolder));
|
||||
if (NS_FAILED(rv)) {
|
||||
global = nsnull;
|
||||
goto out;
|
||||
}
|
||||
|
||||
JSObject *locationObj;
|
||||
rv = locationHolder->GetJSObject(&locationObj);
|
||||
if (NS_FAILED(rv)) {
|
||||
global = nsnull;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!JS_DefineProperty(cx, global, "__LOCATION__",
|
||||
OBJECT_TO_JSVAL(locationObj), NULL,
|
||||
NULL, 0)) {
|
||||
global = nsnull;
|
||||
goto out;
|
||||
}
|
||||
|
||||
script =
|
||||
JS_CompileFileHandleForPrincipals(cx, global, nativePath.get(),
|
||||
fileHandle, jsPrincipals);
|
||||
|
|
Загрузка…
Ссылка в новой задаче