bug 315304 throw exception (return JS_FALSE) if we can't create the native object. r=dougt, sr=brendan, a=schrep

This commit is contained in:
dveditz%cruzio.com 2005-11-07 19:58:28 +00:00
Родитель cd4722bc8f
Коммит 923e5d89aa
1 изменённых файлов: 37 добавлений и 34 удалений

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

@ -196,20 +196,37 @@ InstallTriggerCheckLoadURIFromScript(JSContext *cx, const nsAString& uriStr)
return rv;
}
//
// Helper function to get native object
//
// This is our own version of JS_GetInstancePrivate() that in addition
// performs the delayed creation of the native InstallTrigger if necessary
//
static nsIDOMInstallTriggerGlobal* getTriggerNative(JSContext *cx, JSObject *obj)
{
if (!JS_InstanceOf(cx, obj, &InstallTriggerGlobalClass, nsnull))
return nsnull;
nsIDOMInstallTriggerGlobal *native = (nsIDOMInstallTriggerGlobal*)JS_GetPrivate(cx, obj);
if (!native) {
// xpinstall script contexts delay creation of the native.
CreateNativeObject(cx, obj, &native);
}
return native;
}
//
// Native method UpdateEnabled
//
PR_STATIC_CALLBACK(JSBool)
InstallTriggerGlobalUpdateEnabled(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallTriggerGlobal *nativeThis = (nsIDOMInstallTriggerGlobal*)
JS_GetInstancePrivate(cx, obj, &InstallTriggerGlobalClass, 0);
nsIDOMInstallTriggerGlobal *nativeThis = getTriggerNative(cx, obj);
if (!nativeThis)
return JS_FALSE;
*rval = JSVAL_FALSE;
if (nsnull == nativeThis && (JS_FALSE == CreateNativeObject(cx, obj, &nativeThis)) )
return JS_TRUE;
nsIScriptGlobalObject *globalObject = nsnull;
nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);
if (scriptContext)
@ -230,15 +247,12 @@ InstallTriggerGlobalUpdateEnabled(JSContext *cx, JSObject *obj, uintN argc, jsva
PR_STATIC_CALLBACK(JSBool)
InstallTriggerGlobalInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallTriggerGlobal *nativeThis = (nsIDOMInstallTriggerGlobal*)
JS_GetInstancePrivate(cx, obj, &InstallTriggerGlobalClass, 0);
nsIDOMInstallTriggerGlobal *nativeThis = getTriggerNative(cx, obj);
if (!nativeThis)
return JS_FALSE;
*rval = JSVAL_FALSE;
if (nsnull == nativeThis && (JS_FALSE == CreateNativeObject(cx, obj, &nativeThis)) )
return JS_TRUE;
// make sure XPInstall is enabled, return false if not
nsIScriptGlobalObject *globalObject = nsnull;
nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);
@ -414,8 +428,9 @@ InstallTriggerGlobalInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *arg
PR_STATIC_CALLBACK(JSBool)
InstallTriggerGlobalInstallChrome(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallTriggerGlobal *nativeThis = (nsIDOMInstallTriggerGlobal*)
JS_GetInstancePrivate(cx, obj, &InstallTriggerGlobalClass, 0);
nsIDOMInstallTriggerGlobal *nativeThis = getTriggerNative(cx, obj);
if (!nativeThis)
return JS_FALSE;
uint32 chromeType = NOT_CHROME;
nsAutoString sourceURL;
@ -423,10 +438,6 @@ InstallTriggerGlobalInstallChrome(JSContext *cx, JSObject *obj, uintN argc, jsva
*rval = JSVAL_FALSE;
if (nsnull == nativeThis && (JS_FALSE == CreateNativeObject(cx, obj, &nativeThis)) ) {
return JS_TRUE;
}
// get chromeType first, the update enabled check for skins skips whitelisting
if (argc >=1)
JS_ValueToECMAUint32(cx, argv[0], &chromeType);
@ -506,17 +517,15 @@ InstallTriggerGlobalInstallChrome(JSContext *cx, JSObject *obj, uintN argc, jsva
PR_STATIC_CALLBACK(JSBool)
InstallTriggerGlobalStartSoftwareUpdate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallTriggerGlobal *nativeThis = (nsIDOMInstallTriggerGlobal*)
JS_GetInstancePrivate(cx, obj, &InstallTriggerGlobalClass, 0);
nsIDOMInstallTriggerGlobal *nativeThis = getTriggerNative(cx, obj);
if (!nativeThis)
return JS_FALSE;
PRBool nativeRet;
PRInt32 flags = 0;
*rval = JSVAL_FALSE;
if (nsnull == nativeThis && (JS_FALSE == CreateNativeObject(cx, obj, &nativeThis)) )
return JS_TRUE;
// make sure XPInstall is enabled, return if not
nsIScriptGlobalObject *globalObject = nsnull;
nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);
@ -595,8 +604,9 @@ InstallTriggerGlobalStartSoftwareUpdate(JSContext *cx, JSObject *obj, uintN argc
PR_STATIC_CALLBACK(JSBool)
InstallTriggerGlobalCompareVersion(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallTriggerGlobal *nativeThis = (nsIDOMInstallTriggerGlobal*)
JS_GetInstancePrivate(cx, obj, &InstallTriggerGlobalClass, 0);
nsIDOMInstallTriggerGlobal *nativeThis = getTriggerNative(cx, obj);
if (!nativeThis)
return JS_FALSE;
nsAutoString regname;
nsAutoString version;
@ -606,10 +616,6 @@ InstallTriggerGlobalCompareVersion(JSContext *cx, JSObject *obj, uintN argc, jsv
PRInt32 nativeRet = nsIDOMInstallTriggerGlobal::NOT_FOUND;
*rval = INT_TO_JSVAL(nativeRet);
if (nsnull == nativeThis && (JS_FALSE == CreateNativeObject(cx, obj, &nativeThis)) )
return JS_TRUE;
// make sure XPInstall is enabled, return if not
nsIScriptGlobalObject *globalObject = nsnull;
nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);
@ -696,8 +702,9 @@ InstallTriggerGlobalCompareVersion(JSContext *cx, JSObject *obj, uintN argc, jsv
PR_STATIC_CALLBACK(JSBool)
InstallTriggerGlobalGetVersion(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallTriggerGlobal *nativeThis = (nsIDOMInstallTriggerGlobal*)
JS_GetInstancePrivate(cx, obj, &InstallTriggerGlobalClass, 0);
nsIDOMInstallTriggerGlobal *nativeThis = getTriggerNative(cx, obj);
if (!nativeThis)
return JS_FALSE;
nsAutoString regname;
nsAutoString version;
@ -705,10 +712,6 @@ InstallTriggerGlobalGetVersion(JSContext *cx, JSObject *obj, uintN argc, jsval *
// In case of error return a null value
*rval = JSVAL_NULL;
if (nsnull == nativeThis && (JS_FALSE == CreateNativeObject(cx, obj, &nativeThis)) )
return JS_TRUE;
// make sure XPInstall is enabled, return if not
nsIScriptGlobalObject *globalObject = nsnull;
nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);