Bug 287441: add __LOCATION__ property so JS components can tell where they're

loaded from.  r=dbradley.
This commit is contained in:
shaver%mozilla.org 2005-03-24 18:24:09 +00:00
Родитель f8a0934ba2
Коммит 06528c8adc
1 изменённых файлов: 23 добавлений и 0 удалений

Просмотреть файл

@ -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);