From 85e0ab7b5b4926e526c067a7bc3b9db48345ff28 Mon Sep 17 00:00:00 2001 From: "timeless@mozdev.org" Date: Wed, 19 May 2010 13:47:07 -0700 Subject: [PATCH] Bug 565620 the NativeJSContext constructor needs to initialize more variables or the class needs to be much more careful; r=vlad --- content/canvas/src/NativeJSContext.cpp | 2 ++ content/canvas/src/NativeJSContext.h | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/content/canvas/src/NativeJSContext.cpp b/content/canvas/src/NativeJSContext.cpp index 306a4f72e7f..4f9239d8504 100644 --- a/content/canvas/src/NativeJSContext.cpp +++ b/content/canvas/src/NativeJSContext.cpp @@ -8,6 +8,7 @@ JSRuntime* NativeJSContext::sJSScriptRuntime = 0; PRBool NativeJSContext::AddGCRoot(void *aPtr, const char *aName) { + NS_ASSERTION(NS_SUCCEEDED(error), "class failed to initialize and caller used class without checking!"); if (!sJSScriptRuntime) { nsresult rv = CallGetService("@mozilla.org/js/xpc/RuntimeService;1", &sJSRuntimeService); @@ -29,6 +30,7 @@ NativeJSContext::AddGCRoot(void *aPtr, const char *aName) void NativeJSContext::ReleaseGCRoot(void *aPtr) { + NS_ASSERTION(NS_SUCCEEDED(error), "class failed to initialize and caller used class without checking!"); if (!sJSScriptRuntime) { NS_NOTREACHED("Trying to remove a JS GC root when none were added"); return; diff --git a/content/canvas/src/NativeJSContext.h b/content/canvas/src/NativeJSContext.h index feb296272c4..e9f8f457acb 100644 --- a/content/canvas/src/NativeJSContext.h +++ b/content/canvas/src/NativeJSContext.h @@ -39,10 +39,12 @@ public: } ~NativeJSContext() { - JS_EndRequest(ctx); + if (NS_SUCCEEDED(error)) + JS_EndRequest(ctx); } PRBool CheckArray (JSObject *obj, jsuint *sz) { + NS_ASSERTION(NS_SUCCEEDED(error), "class failed to initialize and caller used class without checking!"); if (obj && ::JS_IsArrayObject(ctx, obj) && ::JS_GetArrayLength(ctx, obj, sz)) @@ -51,6 +53,7 @@ public: } PRBool CheckArray (jsval val, jsuint *sz) { + NS_ASSERTION(NS_SUCCEEDED(error), "class failed to initialize and caller used class without checking!"); if (!JSVAL_IS_NULL(val) && JSVAL_IS_OBJECT(val) && ::JS_IsArrayObject(ctx, JSVAL_TO_OBJECT(val)) && @@ -63,6 +66,7 @@ public: void ReleaseGCRoot (void *aPtr); void SetRetVal (PRInt32 val) { + NS_ASSERTION(NS_SUCCEEDED(error), "class failed to initialize and caller used class without checking!"); if (INT_FITS_IN_JSVAL(val)) SetRetValAsJSVal(INT_TO_JSVAL(val)); else @@ -70,6 +74,7 @@ public: } void SetRetVal (PRUint32 val) { + NS_ASSERTION(NS_SUCCEEDED(error), "class failed to initialize and caller used class without checking!"); if (INT_FITS_IN_JSVAL(val)) SetRetValAsJSVal(INT_TO_JSVAL((int) val)); else @@ -77,12 +82,14 @@ public: } void SetRetVal (double val) { + NS_ASSERTION(NS_SUCCEEDED(error), "class failed to initialize and caller used class without checking!"); jsval *vp; ncc->GetRetValPtr(&vp); JS_NewDoubleValue(ctx, val, vp); } void SetBoolRetVal (PRBool val) { + NS_ASSERTION(NS_SUCCEEDED(error), "class failed to initialize and caller used class without checking!"); if (val) SetRetValAsJSVal(JSVAL_TRUE); else @@ -90,6 +97,7 @@ public: } void SetRetVal (PRInt32 *vp, PRUint32 len) { + NS_ASSERTION(NS_SUCCEEDED(error), "class failed to initialize and caller used class without checking!"); nsAutoArrayPtr jsvector(new jsval[len]); if (!JS_EnterLocalRootScope(ctx)) @@ -110,6 +118,7 @@ public: } void SetRetVal (PRUint32 *vp, PRUint32 len) { + NS_ASSERTION(NS_SUCCEEDED(error), "class failed to initialize and caller used class without checking!"); nsAutoArrayPtr jsvector(new jsval[len]); if (!JS_EnterLocalRootScope(ctx)) @@ -126,6 +135,7 @@ public: } void SetRetVal (double *dp, PRUint32 len) { + NS_ASSERTION(NS_SUCCEEDED(error), "class failed to initialize and caller used class without checking!"); nsAutoArrayPtr jsvector(new jsval[len]); if (!JS_EnterLocalRootScope(ctx)) @@ -141,6 +151,7 @@ public: } void SetRetVal (float *fp, PRUint32 len) { + NS_ASSERTION(NS_SUCCEEDED(error), "class failed to initialize and caller used class without checking!"); nsAutoArrayPtr jsvector(new jsval[len]); if (!JS_EnterLocalRootScope(ctx)) @@ -155,6 +166,7 @@ public: } void SetRetValAsJSVal (jsval val) { + NS_ASSERTION(NS_SUCCEEDED(error), "class failed to initialize and caller used class without checking!"); jsval *vp; ncc->GetRetValPtr(&vp); *vp = val; @@ -162,6 +174,7 @@ public: } void SetRetVal (JSObject *obj) { + NS_ASSERTION(NS_SUCCEEDED(error), "class failed to initialize and caller used class without checking!"); SetRetValAsJSVal(OBJECT_TO_JSVAL(obj)); }