Bug 710163: (part 2) fix EXT_context_loss semantics r=bjacob
authorDoug Sherk <dsherk@mozilla.com>
Wed, 04 Jan 2012 16:12:05 -0500
changeset 83808 23f3b97f655a4e7db3df368d9c9a205bfde84e79
parent 83807 8e3d4ad9e413e9d84ecf5ca20a76823e3096a54a
child 83809 7dd5039ca2e7db4f3bd171e897000cd859edc0c7
push id21798
push usermak77@bonardo.net
push dateThu, 05 Jan 2012 14:53:22 +0000
treeherdermozilla-central@595fba5b92d4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbjacob
bugs710163
milestone12.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 710163: (part 2) fix EXT_context_loss semantics r=bjacob Housekeeping stuff; update all WebGL API functions to use !IsContextStable() instead of mContextLost.
content/canvas/src/WebGLContext.cpp
content/canvas/src/WebGLContextGL.cpp
--- a/content/canvas/src/WebGLContext.cpp
+++ b/content/canvas/src/WebGLContext.cpp
@@ -798,17 +798,17 @@ private:
 
 } // end namespace mozilla
 
 already_AddRefed<layers::CanvasLayer>
 WebGLContext::GetCanvasLayer(nsDisplayListBuilder* aBuilder,
                              CanvasLayer *aOldLayer,
                              LayerManager *aManager)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return nsnull;
 
     if (!mResetLayer && aOldLayer &&
         aOldLayer->HasUserData(&gWebGLLayerUserData)) {
         NS_ADDREF(aOldLayer);
         return aOldLayer;
     }
 
@@ -862,17 +862,17 @@ WebGLContext::GetCanvasLayer(nsDisplayLi
     mResetLayer = false;
 
     return canvasLayer.forget().get();
 }
 
 NS_IMETHODIMP
 WebGLContext::GetContextAttributes(jsval *aResult)
 {
-    if (mContextLost)
+    if (!IsContextStable())
     {
         *aResult = OBJECT_TO_JSVAL(NULL);
         return NS_OK;
     }
 
     JSContext *cx = nsContentUtils::GetCurrentJSContext();
     if (!cx)
         return NS_ERROR_FAILURE;
@@ -906,17 +906,17 @@ WebGLContext::GetContextAttributes(jsval
 
     return NS_OK;
 }
 
 /* [noscript] DOMString mozGetUnderlyingParamString(in WebGLenum pname); */
 NS_IMETHODIMP
 WebGLContext::MozGetUnderlyingParamString(PRUint32 pname, nsAString& retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     retval.SetIsVoid(true);
 
     MakeContextCurrent();
 
     switch (pname) {
     case LOCAL_GL_VENDOR:
@@ -960,17 +960,17 @@ bool WebGLContext::IsExtensionSupported(
 
     return isSupported;
 }
 
 NS_IMETHODIMP
 WebGLContext::GetExtension(const nsAString& aName, nsIWebGLExtension **retval)
 {
     *retval = nsnull;
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
     
     if (mDisableExtensions) {
         return NS_OK;
     }
 
     // handle simple extensions that don't need custom objects first
     WebGLExtensionID ei = WebGLExtensionID_Max;
@@ -1416,28 +1416,28 @@ NS_INTERFACE_MAP_BEGIN(WebGLExtensionLos
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, WebGLExtension)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(WebGLExtensionLoseContext)
 NS_INTERFACE_MAP_END_INHERITING(WebGLExtension)
 
 /* readonly attribute WebGLsizei drawingBufferWidth; */
 NS_IMETHODIMP
 WebGLContext::GetDrawingBufferWidth(WebGLsizei *aWidth)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     *aWidth = mWidth;
     return NS_OK;
 }
 
 /* readonly attribute WebGLsizei drawingBufferHeight; */
 NS_IMETHODIMP
 WebGLContext::GetDrawingBufferHeight(WebGLsizei *aHeight)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     *aHeight = mHeight;
     return NS_OK;
 }
 
 /* [noscript] attribute WebGLint location; */
 NS_IMETHODIMP
@@ -1499,17 +1499,17 @@ WebGLShaderPrecisionFormat::GetPrecision
     *aPrecision = mPrecision;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::GetSupportedExtensions(nsIVariant **retval)
 {
     *retval = nsnull;
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
     
     if (mDisableExtensions) {
         return NS_OK;
     }
     
     nsCOMPtr<nsIWritableVariant> wrval = do_CreateInstance("@mozilla.org/variant;1");
     NS_ENSURE_TRUE(wrval, NS_ERROR_FAILURE);
--- a/content/canvas/src/WebGLContextGL.cpp
+++ b/content/canvas/src/WebGLContextGL.cpp
@@ -76,83 +76,83 @@ static WebGLenum InternalFormatForFormat
 
 /* Helper macros for when we're just wrapping a gl method, so that
  * we can avoid having to type this 500 times.  Note that these MUST
  * NOT BE USED if we need to check any of the parameters.
  */
 
 #define GL_SAME_METHOD_0(glname, name)                          \
 NS_IMETHODIMP WebGLContext::name() {                            \
-    if (mContextLost) { return NS_OK; }                         \
+    if (!IsContextStable()) { return NS_OK; }                         \
     MakeContextCurrent(); gl->f##glname(); return NS_OK;        \
 }
 
 #define GL_SAME_METHOD_1(glname, name, t1)          \
 NS_IMETHODIMP WebGLContext::name(t1 a1) {           \
-    if (mContextLost) { return NS_OK; }             \
+    if (!IsContextStable()) { return NS_OK; }             \
     MakeContextCurrent(); gl->f##glname(a1); return NS_OK;  \
 }
 
 #define GL_SAME_METHOD_2(glname, name, t1, t2)        \
 NS_IMETHODIMP WebGLContext::name(t1 a1, t2 a2) {      \
-    if (mContextLost) { return NS_OK; }               \
+    if (!IsContextStable()) { return NS_OK; }               \
     MakeContextCurrent(); gl->f##glname(a1,a2); return NS_OK;           \
 }
 
 #define GL_SAME_METHOD_3(glname, name, t1, t2, t3)      \
 NS_IMETHODIMP WebGLContext::name(t1 a1, t2 a2, t3 a3) { \
-    if (mContextLost) { return NS_OK; }                 \
+    if (!IsContextStable()) { return NS_OK; }                 \
     MakeContextCurrent(); gl->f##glname(a1,a2,a3); return NS_OK;        \
 }
 
 #define GL_SAME_METHOD_4(glname, name, t1, t2, t3, t4)         \
 NS_IMETHODIMP WebGLContext::name(t1 a1, t2 a2, t3 a3, t4 a4) { \
-    if (mContextLost) { return NS_OK; }                        \
+    if (!IsContextStable()) { return NS_OK; }                        \
     MakeContextCurrent(); gl->f##glname(a1,a2,a3,a4); return NS_OK;     \
 }
 
 #define GL_SAME_METHOD_5(glname, name, t1, t2, t3, t4, t5)            \
 NS_IMETHODIMP WebGLContext::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) { \
-    if (mContextLost) { return NS_OK; }                               \
+    if (!IsContextStable()) { return NS_OK; }                               \
     MakeContextCurrent(); gl->f##glname(a1,a2,a3,a4,a5); return NS_OK;  \
 }
 
 #define GL_SAME_METHOD_6(glname, name, t1, t2, t3, t4, t5, t6)          \
 NS_IMETHODIMP WebGLContext::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) { \
-    if (mContextLost) { return NS_OK; }                                 \
+    if (!IsContextStable()) { return NS_OK; }                                 \
     MakeContextCurrent(); gl->f##glname(a1,a2,a3,a4,a5,a6); return NS_OK; \
 }
 
 
 //
 //  WebGL API
 //
 
 
 /* void GlActiveTexture (in GLenum texture); */
 NS_IMETHODIMP
 WebGLContext::ActiveTexture(WebGLenum texture)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (texture < LOCAL_GL_TEXTURE0 || texture >= LOCAL_GL_TEXTURE0 + mBound2DTextures.Length())
         return ErrorInvalidEnum("ActiveTexture: texture unit %d out of range (0..%d)",
                                 texture, mBound2DTextures.Length()-1);
 
     MakeContextCurrent();
     mActiveTexture = texture - LOCAL_GL_TEXTURE0;
     gl->fActiveTexture(texture);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::AttachShader(nsIWebGLProgram *pobj, nsIWebGLShader *shobj)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     // if pobj or shobj are null/not specified, it's an error
     if (pobj == nsnull || shobj == nsnull)
         return ErrorInvalidValue("attachShader");
 
     WebGLuint progname, shadername;
     WebGLProgram *program;
@@ -172,17 +172,17 @@ WebGLContext::AttachShader(nsIWebGLProgr
 
     return NS_OK;
 }
 
 
 NS_IMETHODIMP
 WebGLContext::BindAttribLocation(nsIWebGLProgram *pobj, WebGLuint location, const nsAString& name)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     WebGLuint progname;
     if (!GetGLName<WebGLProgram>("bindAttribLocation: program", pobj, &progname))
         return NS_OK;
 
     if (!ValidateGLSLVariableName(name, "bindAttribLocation"))
         return NS_OK;
@@ -332,44 +332,44 @@ WebGLContext::BindTexture(WebGLenum targ
 
     return NS_OK;
 }
 
 GL_SAME_METHOD_4(BlendColor, BlendColor, WebGLfloat, WebGLfloat, WebGLfloat, WebGLfloat)
 
 NS_IMETHODIMP WebGLContext::BlendEquation(WebGLenum mode)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!ValidateBlendEquationEnum(mode, "blendEquation: mode"))
         return NS_OK;
 
     MakeContextCurrent();
     gl->fBlendEquation(mode);
     return NS_OK;
 }
 
 NS_IMETHODIMP WebGLContext::BlendEquationSeparate(WebGLenum modeRGB, WebGLenum modeAlpha)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!ValidateBlendEquationEnum(modeRGB, "blendEquationSeparate: modeRGB") ||
         !ValidateBlendEquationEnum(modeAlpha, "blendEquationSeparate: modeAlpha"))
         return NS_OK;
 
     MakeContextCurrent();
     gl->fBlendEquationSeparate(modeRGB, modeAlpha);
     return NS_OK;
 }
 
 NS_IMETHODIMP WebGLContext::BlendFunc(WebGLenum sfactor, WebGLenum dfactor)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!ValidateBlendFuncSrcEnum(sfactor, "blendFunc: sfactor") ||
         !ValidateBlendFuncDstEnum(dfactor, "blendFunc: dfactor"))
         return NS_OK;
 
     if (!ValidateBlendFuncEnumsCompatibility(sfactor, dfactor, "blendFuncSeparate: srcRGB and dstRGB"))
         return NS_OK;
@@ -378,17 +378,17 @@ NS_IMETHODIMP WebGLContext::BlendFunc(We
     gl->fBlendFunc(sfactor, dfactor);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::BlendFuncSeparate(WebGLenum srcRGB, WebGLenum dstRGB,
                                 WebGLenum srcAlpha, WebGLenum dstAlpha)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!ValidateBlendFuncSrcEnum(srcRGB, "blendFuncSeparate: srcRGB") ||
         !ValidateBlendFuncSrcEnum(srcAlpha, "blendFuncSeparate: srcAlpha") ||
         !ValidateBlendFuncDstEnum(dstRGB, "blendFuncSeparate: dstRGB") ||
         !ValidateBlendFuncDstEnum(dstAlpha, "blendFuncSeparate: dstAlpha"))
         return NS_OK;
 
@@ -426,39 +426,39 @@ GLenum WebGLContext::CheckedBufferData(G
         gl->fBufferData(target, size, data, usage);
         return LOCAL_GL_NO_ERROR;
     }
 }
 
 NS_IMETHODIMP
 WebGLContext::BufferData(PRInt32 dummy)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     // this should never be called
     LogMessageIfVerbose("BufferData");
     return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 WebGLContext::BufferData_null()
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     // see http://www.khronos.org/bugzilla/show_bug.cgi?id=386
     return ErrorInvalidValue("bufferData: null object passed");
 }
 
 
 NS_IMETHODIMP
 WebGLContext::BufferData_size(WebGLenum target, WebGLsizei size, WebGLenum usage)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     WebGLBuffer *boundBuffer = NULL;
 
     if (target == LOCAL_GL_ARRAY_BUFFER) {
         boundBuffer = mBoundArrayBuffer;
     } else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
         boundBuffer = mBoundElementArrayBuffer;
@@ -489,17 +489,17 @@ WebGLContext::BufferData_size(WebGLenum 
         return ErrorOutOfMemory("bufferData: out of memory");
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::BufferData_buf(WebGLenum target, JSObject *wb, WebGLenum usage)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     WebGLBuffer *boundBuffer = NULL;
 
     if (target == LOCAL_GL_ARRAY_BUFFER) {
         boundBuffer = mBoundArrayBuffer;
     } else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
         boundBuffer = mBoundElementArrayBuffer;
@@ -530,17 +530,17 @@ WebGLContext::BufferData_buf(WebGLenum t
         return ErrorOutOfMemory("bufferData: out of memory");
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::BufferData_array(WebGLenum target, JSObject *wa, WebGLenum usage)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     WebGLBuffer *boundBuffer = NULL;
 
     if (target == LOCAL_GL_ARRAY_BUFFER) {
         boundBuffer = mBoundArrayBuffer;
     } else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
         boundBuffer = mBoundElementArrayBuffer;
@@ -571,35 +571,35 @@ WebGLContext::BufferData_array(WebGLenum
         return ErrorOutOfMemory("bufferData: out of memory");
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::BufferSubData(PRInt32)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 WebGLContext::BufferSubData_null()
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     return NS_OK; // see http://www.khronos.org/bugzilla/show_bug.cgi?id=386
 }
 
 NS_IMETHODIMP
 WebGLContext::BufferSubData_buf(GLenum target, WebGLsizei byteOffset, JSObject *wb)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     WebGLBuffer *boundBuffer = NULL;
 
     if (target == LOCAL_GL_ARRAY_BUFFER) {
         boundBuffer = mBoundArrayBuffer;
     } else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
         boundBuffer = mBoundElementArrayBuffer;
@@ -629,17 +629,17 @@ WebGLContext::BufferSubData_buf(GLenum t
     gl->fBufferSubData(target, byteOffset, JS_GetArrayBufferByteLength(wb), JS_GetArrayBufferData(wb));
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::BufferSubData_array(WebGLenum target, WebGLsizei byteOffset, JSObject *wa)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     WebGLBuffer *boundBuffer = NULL;
 
     if (target == LOCAL_GL_ARRAY_BUFFER) {
         boundBuffer = mBoundArrayBuffer;
     } else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
         boundBuffer = mBoundElementArrayBuffer;
@@ -669,17 +669,17 @@ WebGLContext::BufferSubData_array(WebGLe
     gl->fBufferSubData(target, byteOffset, JS_GetTypedArrayByteLength(wa), JS_GetTypedArrayData(wa));
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::CheckFramebufferStatus(WebGLenum target, WebGLenum *retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
     {
         *retval = LOCAL_GL_FRAMEBUFFER_UNSUPPORTED;
         return NS_OK;
     }
 
     *retval = 0;
 
     MakeContextCurrent();
@@ -692,17 +692,17 @@ WebGLContext::CheckFramebufferStatus(Web
         *retval = gl->fCheckFramebufferStatus(target);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::Clear(PRUint32 mask)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     MakeContextCurrent();
 
     PRUint32 m = mask & (LOCAL_GL_COLOR_BUFFER_BIT | LOCAL_GL_DEPTH_BUFFER_BIT | LOCAL_GL_STENCIL_BUFFER_BIT);
     if (mask != m)
         return ErrorInvalidValue("clear: invalid mask bits");
 
@@ -734,56 +734,56 @@ WebGLContext::Clear(PRUint32 mask)
     }
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::ClearColor(WebGLfloat r, WebGLfloat g, WebGLfloat b, WebGLfloat a)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     MakeContextCurrent();
     mColorClearValue[0] = r;
     mColorClearValue[1] = g;
     mColorClearValue[2] = b;
     mColorClearValue[3] = a;
     gl->fClearColor(r, g, b, a);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::ClearDepth(WebGLfloat v)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     MakeContextCurrent();
     mDepthClearValue = v;
     gl->fClearDepth(v);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::ClearStencil(WebGLint v)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     MakeContextCurrent();
     mStencilClearValue = v;
     gl->fClearStencil(v);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::ColorMask(WebGLboolean r, WebGLboolean g, WebGLboolean b, WebGLboolean a)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     MakeContextCurrent();
     mColorWriteMask[0] = r;
     mColorWriteMask[1] = g;
     mColorWriteMask[2] = b;
     mColorWriteMask[3] = a;
     gl->fColorMask(r, g, b, a);
@@ -885,17 +885,17 @@ WebGLContext::CopyTexImage2D(WebGLenum t
                              WebGLint level,
                              WebGLenum internalformat,
                              WebGLint x,
                              WebGLint y,
                              WebGLsizei width,
                              WebGLsizei height,
                              WebGLint border)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     switch (target) {
         case LOCAL_GL_TEXTURE_2D:
         case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X:
         case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
         case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
         case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
@@ -990,17 +990,17 @@ WebGLContext::CopyTexSubImage2D(WebGLenu
                                 WebGLint level,
                                 WebGLint xoffset,
                                 WebGLint yoffset,
                                 WebGLint x,
                                 WebGLint y,
                                 WebGLsizei width,
                                 WebGLsizei height)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     switch (target) {
         case LOCAL_GL_TEXTURE_2D:
         case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X:
         case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
         case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
         case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
@@ -1057,31 +1057,31 @@ WebGLContext::CopyTexSubImage2D(WebGLenu
 
     return CopyTexSubImage2D_base(target, level, format, xoffset, yoffset, x, y, width, height, true);
 }
 
 
 NS_IMETHODIMP
 WebGLContext::CreateProgram(nsIWebGLProgram **retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     *retval = nsnull;
 
     WebGLProgram *prog = new WebGLProgram(this);
     NS_ADDREF(*retval = prog);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::CreateShader(WebGLenum type, nsIWebGLShader **retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     *retval = nsnull;
 
     if (type != LOCAL_GL_VERTEX_SHADER &&
         type != LOCAL_GL_FRAGMENT_SHADER)
     {
         return ErrorInvalidEnumInfo("createShader: type", type);
@@ -1091,31 +1091,31 @@ WebGLContext::CreateShader(WebGLenum typ
     NS_ADDREF(*retval = shader);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::CullFace(WebGLenum face)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!ValidateFaceEnum(face, "cullFace"))
         return NS_OK;
 
     MakeContextCurrent();
     gl->fCullFace(face);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::DeleteBuffer(nsIWebGLBuffer *bobj)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     WebGLuint bufname;
     WebGLBuffer *buf;
     bool isNull, isDeleted;
     if (!GetConcreteObjectAndGLName("deleteBuffer", bobj, &buf, &bufname, &isNull, &isDeleted))
         return NS_OK;
 
@@ -1135,17 +1135,17 @@ WebGLContext::DeleteBuffer(nsIWebGLBuffe
     buf->RequestDelete();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::DeleteFramebuffer(nsIWebGLFramebuffer *fbobj)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     WebGLFramebuffer *fbuf;
     WebGLuint fbufname;
     bool isNull, isDeleted;
     if (!GetConcreteObjectAndGLName("deleteFramebuffer", fbobj, &fbuf, &fbufname, &isNull, &isDeleted))
         return NS_OK;
 
@@ -1158,17 +1158,17 @@ WebGLContext::DeleteFramebuffer(nsIWebGL
         BindFramebuffer(LOCAL_GL_FRAMEBUFFER, nsnull);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::DeleteRenderbuffer(nsIWebGLRenderbuffer *rbobj)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     WebGLRenderbuffer *rbuf;
     WebGLuint rbufname;
     bool isNull, isDeleted;
     if (!GetConcreteObjectAndGLName("deleteRenderbuffer", rbobj, &rbuf, &rbufname, &isNull, &isDeleted))
         return NS_OK;
 
@@ -1184,17 +1184,17 @@ WebGLContext::DeleteRenderbuffer(nsIWebG
     rbuf->RequestDelete();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::DeleteTexture(nsIWebGLTexture *tobj)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     WebGLTexture *tex;
     WebGLuint texname;
     bool isNull, isDeleted;
     if (!GetConcreteObjectAndGLName("deleteTexture", tobj, &tex, &texname, &isNull, &isDeleted))
         return NS_OK;
 
@@ -1217,17 +1217,17 @@ WebGLContext::DeleteTexture(nsIWebGLText
     tex->RequestDelete();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::DeleteProgram(nsIWebGLProgram *pobj)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     WebGLuint progname;
     WebGLProgram *prog;
     bool isNull, isDeleted;
     if (!GetConcreteObjectAndGLName("deleteProgram", pobj, &prog, &progname, &isNull, &isDeleted))
         return NS_OK;
 
@@ -1237,17 +1237,17 @@ WebGLContext::DeleteProgram(nsIWebGLProg
     prog->RequestDelete();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::DeleteShader(nsIWebGLShader *sobj)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     WebGLuint shadername;
     WebGLShader *shader;
     bool isNull, isDeleted;
     if (!GetConcreteObjectAndGLName("deleteShader", sobj, &shader, &shadername, &isNull, &isDeleted))
         return NS_OK;
 
@@ -1257,17 +1257,17 @@ WebGLContext::DeleteShader(nsIWebGLShade
     shader->RequestDelete();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::DetachShader(nsIWebGLProgram *pobj, nsIWebGLShader *shobj)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     WebGLuint progname, shadername;
     WebGLProgram *program;
     WebGLShader *shader;
     bool shaderDeleted;
     if (!GetConcreteObjectAndGLName("detachShader: program", pobj, &program, &progname) ||
         !GetConcreteObjectAndGLName("detachShader: shader", shobj, &shader, &shadername, nsnull, &shaderDeleted))
@@ -1279,57 +1279,57 @@ WebGLContext::DetachShader(nsIWebGLProgr
         return ErrorInvalidOperation("DetachShader: shader is not attached");
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::DepthFunc(WebGLenum func)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!ValidateComparisonEnum(func, "depthFunc"))
         return NS_OK;
 
     MakeContextCurrent();
     gl->fDepthFunc(func);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::DepthMask(WebGLboolean b)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     MakeContextCurrent();
     mDepthWriteMask = b;
     gl->fDepthMask(b);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::DepthRange(WebGLfloat zNear, WebGLfloat zFar)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (zNear > zFar)
         return ErrorInvalidOperation("depthRange: the near value is greater than the far value!");
 
     MakeContextCurrent();
     gl->fDepthRange(zNear, zFar);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::DisableVertexAttribArray(WebGLuint index)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!ValidateAttribIndex(index, "disableVertexAttribArray"))
         return NS_OK;
 
     MakeContextCurrent();
 
     if (index || gl->IsGLES2())
@@ -1545,17 +1545,17 @@ WebGLContext::UnbindFakeBlackTextures()
     }
 
     gl->fActiveTexture(LOCAL_GL_TEXTURE0 + mActiveTexture);
 }
 
 NS_IMETHODIMP
 WebGLContext::DrawArrays(GLenum mode, WebGLint first, WebGLsizei count)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!ValidateDrawModeEnum(mode, "drawArrays: mode"))
         return NS_OK;
 
     if (first < 0 || count < 0)
         return ErrorInvalidValue("DrawArrays: negative first or count");
 
@@ -1606,17 +1606,17 @@ WebGLContext::DrawArrays(GLenum mode, We
     Invalidate();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::DrawElements(WebGLenum mode, WebGLsizei count, WebGLenum type, WebGLint byteOffset)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!ValidateDrawModeEnum(mode, "drawElements: mode"))
         return NS_OK;
 
     if (count < 0 || byteOffset < 0)
         return ErrorInvalidValue("DrawElements: negative count or offset");
 
@@ -1716,17 +1716,17 @@ WebGLContext::DrawElements(WebGLenum mod
     mBackbufferClearingStatus = BackbufferClearingStatus::HasBeenDrawnTo;
     Invalidate();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP WebGLContext::Enable(WebGLenum cap)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!ValidateCapabilityEnum(cap, "enable"))
         return NS_OK;
 
     switch(cap) {
         case LOCAL_GL_SCISSOR_TEST:
             mScissorTestEnabled = 1;
@@ -1738,17 +1738,17 @@ NS_IMETHODIMP WebGLContext::Enable(WebGL
 
     MakeContextCurrent();
     gl->fEnable(cap);
     return NS_OK;
 }
 
 NS_IMETHODIMP WebGLContext::Disable(WebGLenum cap)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!ValidateCapabilityEnum(cap, "disable"))
         return NS_OK;
 
     switch(cap) {
         case LOCAL_GL_SCISSOR_TEST:
             mScissorTestEnabled = 0;
@@ -1761,66 +1761,66 @@ NS_IMETHODIMP WebGLContext::Disable(WebG
     MakeContextCurrent();
     gl->fDisable(cap);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::EnableVertexAttribArray(WebGLuint index)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!ValidateAttribIndex(index, "enableVertexAttribArray"))
         return NS_OK;
 
     MakeContextCurrent();
 
     gl->fEnableVertexAttribArray(index);
     mAttribBuffers[index].enabled = true;
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::FramebufferRenderbuffer(WebGLenum target, WebGLenum attachment, WebGLenum rbtarget, nsIWebGLRenderbuffer *rbobj)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!mBoundFramebuffer)
         return ErrorInvalidOperation("framebufferRenderbuffer: cannot modify framebuffer 0");
 
     return mBoundFramebuffer->FramebufferRenderbuffer(target, attachment, rbtarget, rbobj);
 }
 
 NS_IMETHODIMP
 WebGLContext::FramebufferTexture2D(WebGLenum target,
                                    WebGLenum attachment,
                                    WebGLenum textarget,
                                    nsIWebGLTexture *tobj,
                                    WebGLint level)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (mBoundFramebuffer)
         return mBoundFramebuffer->FramebufferTexture2D(target, attachment, textarget, tobj, level);
     else
         return ErrorInvalidOperation("framebufferTexture2D: cannot modify framebuffer 0");
 }
 
 GL_SAME_METHOD_0(Flush, Flush)
 
 GL_SAME_METHOD_0(Finish, Finish)
 
 NS_IMETHODIMP
 WebGLContext::FrontFace(WebGLenum mode)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     switch (mode) {
         case LOCAL_GL_CW:
         case LOCAL_GL_CCW:
             break;
         default:
             return ErrorInvalidEnumInfo("frontFace: mode", mode);
@@ -1830,17 +1830,17 @@ WebGLContext::FrontFace(WebGLenum mode)
     gl->fFrontFace(mode);
     return NS_OK;
 }
 
 // returns an object: { size: ..., type: ..., name: ... }
 NS_IMETHODIMP
 WebGLContext::GetActiveAttrib(nsIWebGLProgram *pobj, PRUint32 index, nsIWebGLActiveInfo **retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     *retval = nsnull;
 
     WebGLuint progname;
     if (!GetGLName<WebGLProgram>("getActiveAttrib: program", pobj, &progname))
         return NS_OK;
 
@@ -1865,17 +1865,17 @@ WebGLContext::GetActiveAttrib(nsIWebGLPr
     NS_ADDREF(*retval = retActiveInfo);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::GenerateMipmap(WebGLenum target)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!ValidateTextureTargetEnum(target, "generateMipmap"))
         return NS_OK;
 
     WebGLTexture *tex = activeBoundTextureForTarget(target);
 
     if (!tex)
@@ -1894,17 +1894,17 @@ WebGLContext::GenerateMipmap(WebGLenum t
     MakeContextCurrent();
     gl->fGenerateMipmap(target);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::GetActiveUniform(nsIWebGLProgram *pobj, PRUint32 index, nsIWebGLActiveInfo **retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     *retval = nsnull;
 
     WebGLuint progname;
     if (!GetGLName<WebGLProgram>("getActiveUniform: program", pobj, &progname))
         return NS_OK;
 
@@ -1950,17 +1950,17 @@ WebGLContext::GetActiveUniform(nsIWebGLP
     NS_ADDREF(*retval = retActiveInfo);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::GetAttachedShaders(nsIWebGLProgram *pobj, nsIVariant **retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     *retval = nsnull;
 
     WebGLProgram *prog;
     bool isNull;
     if (!GetConcreteObject("getAttachedShaders", pobj, &prog, &isNull)) 
         return NS_OK;
@@ -1993,17 +1993,17 @@ WebGLContext::GetAttachedShaders(nsIWebG
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::GetAttribLocation(nsIWebGLProgram *pobj,
                                 const nsAString& name,
                                 PRInt32 *retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
     {
         *retval = -1;
         return NS_OK;
     }
 
     *retval = 0;
 
     WebGLuint progname;
@@ -2016,17 +2016,17 @@ WebGLContext::GetAttribLocation(nsIWebGL
     MakeContextCurrent();
     *retval = gl->fGetAttribLocation(progname, NS_LossyConvertUTF16toASCII(name).get());
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::GetParameter(PRUint32 pname, nsIVariant **retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     *retval = nsnull;
 
     nsCOMPtr<nsIWritableVariant> wrval = do_CreateInstance("@mozilla.org/variant;1");
     NS_ENSURE_TRUE(wrval, NS_ERROR_FAILURE);
 
     MakeContextCurrent();
@@ -2329,17 +2329,17 @@ WebGLContext::GetParameter(PRUint32 pnam
     *retval = wrval.forget().get();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::GetBufferParameter(WebGLenum target, WebGLenum pname, nsIVariant **retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     *retval = nsnull;
 
     nsCOMPtr<nsIWritableVariant> wrval = do_CreateInstance("@mozilla.org/variant;1");
     NS_ENSURE_TRUE(wrval, NS_ERROR_FAILURE);
 
     if (target != LOCAL_GL_ARRAY_BUFFER && target != LOCAL_GL_ELEMENT_ARRAY_BUFFER)
@@ -2366,17 +2366,17 @@ WebGLContext::GetBufferParameter(WebGLen
     *retval = wrval.forget().get();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::GetFramebufferAttachmentParameter(WebGLenum target, WebGLenum attachment, WebGLenum pname, nsIVariant **retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     *retval = nsnull;
 
     nsCOMPtr<nsIWritableVariant> wrval = do_CreateInstance("@mozilla.org/variant;1");
     NS_ENSURE_TRUE(wrval, NS_ERROR_FAILURE);
 
     if (target != LOCAL_GL_FRAMEBUFFER)
@@ -2447,17 +2447,17 @@ WebGLContext::GetFramebufferAttachmentPa
     *retval = wrval.forget().get();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::GetRenderbufferParameter(WebGLenum target, WebGLenum pname, nsIVariant **retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     *retval = nsnull;
 
     nsCOMPtr<nsIWritableVariant> wrval = do_CreateInstance("@mozilla.org/variant;1");
     NS_ENSURE_TRUE(wrval, NS_ERROR_FAILURE);
 
     if (target != LOCAL_GL_RENDERBUFFER)
@@ -2498,31 +2498,31 @@ WebGLContext::GetRenderbufferParameter(W
     *retval = wrval.forget().get();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::CreateBuffer(nsIWebGLBuffer **retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     *retval = nsnull;
 
     WebGLBuffer *globj = new WebGLBuffer(this);
     NS_ADDREF(*retval = globj);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::CreateTexture(nsIWebGLTexture **retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     *retval = nsnull;
 
     MakeContextCurrent();
 
     WebGLTexture *globj = new WebGLTexture(this);
     NS_ADDREF(*retval = globj);
@@ -2545,17 +2545,17 @@ WebGLContext::GetError(WebGLenum *_retva
     mWebGLError = LOCAL_GL_NO_ERROR;
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::GetProgramParameter(nsIWebGLProgram *pobj, PRUint32 pname, nsIVariant **retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     *retval = nsnull;
 
     WebGLuint progname;
     bool isDeleted;
     WebGLProgram *prog;
     if (!GetConcreteObjectAndGLName("getProgramParameter: program", pobj, &prog, &progname, nsnull, &isDeleted))
@@ -2610,17 +2610,17 @@ WebGLContext::GetProgramParameter(nsIWeb
     *retval = wrval.forget().get();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::GetProgramInfoLog(nsIWebGLProgram *pobj, nsAString& retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
     {
         retval.SetIsVoid(true);
         return NS_OK;
     }
 
     WebGLuint progname;
     if (!GetGLName<WebGLProgram>("getProgramInfoLog: program", pobj, &progname))
         return NS_OK;
@@ -2738,35 +2738,35 @@ nsresult WebGLContext::TexParameter_base
         gl->fTexParameterf(target, pname, floatParam);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::TexParameterf(WebGLenum target, WebGLenum pname, WebGLfloat param)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     return TexParameter_base(target, pname, nsnull, &param);
 }
 
 NS_IMETHODIMP
 WebGLContext::TexParameteri(WebGLenum target, WebGLenum pname, WebGLint param)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     return TexParameter_base(target, pname, &param, nsnull);
 }
 
 NS_IMETHODIMP
 WebGLContext::GetTexParameter(WebGLenum target, WebGLenum pname, nsIVariant **retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     *retval = nsnull;
 
     MakeContextCurrent();
 
     if (!ValidateTextureTargetEnum(target, "getTexParameter: target"))
         return NS_OK;
@@ -2797,17 +2797,17 @@ WebGLContext::GetTexParameter(WebGLenum 
 
     return NS_OK;
 }
 
 /* any getUniform(in WebGLProgram program, in WebGLUniformLocation location) raises(DOMException); */
 NS_IMETHODIMP
 WebGLContext::GetUniform(nsIWebGLProgram *pobj, nsIWebGLUniformLocation *ploc, nsIVariant **retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     *retval = nsnull;
 
     WebGLuint progname;
     WebGLProgram *prog;
     if (!GetConcreteObjectAndGLName("getUniform: program", pobj, &prog, &progname))
         return NS_OK;
@@ -2919,17 +2919,17 @@ WebGLContext::GetUniform(nsIWebGLProgram
     *retval = wrval.forget().get();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::GetUniformLocation(nsIWebGLProgram *pobj, const nsAString& name, nsIWebGLUniformLocation **retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     *retval = nsnull;
 
     WebGLuint progname;
     WebGLProgram *prog;
     if (!GetConcreteObjectAndGLName("getUniformLocation: program", pobj, &prog, &progname))
         return NS_OK;
@@ -2946,17 +2946,17 @@ WebGLContext::GetUniformLocation(nsIWebG
         NS_ADDREF(loc = new WebGLUniformLocation(this, prog, intlocation));
     *retval = loc;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::GetVertexAttrib(WebGLuint index, WebGLenum pname, nsIVariant **retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     *retval = nsnull;
 
     if (!ValidateAttribIndex(index, "getVertexAttrib"))
         return NS_OK;
 
     nsCOMPtr<nsIWritableVariant> wrval = do_CreateInstance("@mozilla.org/variant;1");
@@ -3020,33 +3020,33 @@ WebGLContext::GetVertexAttrib(WebGLuint 
     return NS_OK;
 }
 
 /* GLuint getVertexAttribOffset (in GLuint index, in GLenum pname); */
 NS_IMETHODIMP
 WebGLContext::GetVertexAttribOffset(WebGLuint index, WebGLenum pname, WebGLuint *retval)
 {
     *retval = 0;
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!ValidateAttribIndex(index, "getVertexAttribOffset"))
         return NS_OK;
 
     if (pname != LOCAL_GL_VERTEX_ATTRIB_ARRAY_POINTER)
         return ErrorInvalidEnum("getVertexAttribOffset: bad parameter");
 
     *retval = mAttribBuffers[index].byteOffset;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::Hint(WebGLenum target, WebGLenum mode)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     bool isValid = false;
 
     switch (target) {
         case LOCAL_GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
             if (mEnabledExtensions[WebGL_OES_standard_derivatives]) 
                 isValid = true;
@@ -3059,17 +3059,17 @@ WebGLContext::Hint(WebGLenum target, Web
     }
 
     return ErrorInvalidEnum("hint: invalid hint");
 }
 
 NS_IMETHODIMP
 WebGLContext::IsBuffer(nsIWebGLBuffer *bobj, WebGLboolean *retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
     {
         *retval = false;
         return NS_OK;
     }
 
     bool isDeleted;
     WebGLuint buffername;
     WebGLBuffer *buffer;
@@ -3077,17 +3077,17 @@ WebGLContext::IsBuffer(nsIWebGLBuffer *b
               !isDeleted &&
               buffer->HasEverBeenBound();
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::IsFramebuffer(nsIWebGLFramebuffer *fbobj, WebGLboolean *retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
     {
         *retval = false;
         return NS_OK;
     }
 
     bool isDeleted;
     WebGLuint fbname;
     WebGLFramebuffer *fb;
@@ -3095,33 +3095,33 @@ WebGLContext::IsFramebuffer(nsIWebGLFram
               !isDeleted &&
               fb->HasEverBeenBound();
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::IsProgram(nsIWebGLProgram *pobj, WebGLboolean *retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
     {
         *retval = false;
         return NS_OK;
     }
 
     bool isDeleted;
     WebGLProgram *prog = nsnull;
     *retval = GetConcreteObject("isProgram", pobj, &prog, nsnull, &isDeleted, false) &&
               !isDeleted;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::IsRenderbuffer(nsIWebGLRenderbuffer *rbobj, WebGLboolean *retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
     {
         *retval = false;
         return NS_OK;
     }
 
     bool isDeleted;
     WebGLuint rbname;
     WebGLRenderbuffer *rb;
@@ -3129,33 +3129,33 @@ WebGLContext::IsRenderbuffer(nsIWebGLRen
               !isDeleted &&
               rb->HasEverBeenBound();
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::IsShader(nsIWebGLShader *sobj, WebGLboolean *retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
     {
         *retval = false;
         return NS_OK;
     }
 
     bool isDeleted;
     WebGLShader *shader = nsnull;
     *retval = GetConcreteObject("isShader", sobj, &shader, nsnull, &isDeleted, false) &&
               !isDeleted;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::IsTexture(nsIWebGLTexture *tobj, WebGLboolean *retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
     {
         *retval = false;
         return NS_OK;
     }
 
     bool isDeleted;
     WebGLuint texname;
     WebGLTexture *tex;
@@ -3163,17 +3163,17 @@ WebGLContext::IsTexture(nsIWebGLTexture 
               !isDeleted &&
               tex->HasEverBeenBound();
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::IsEnabled(WebGLenum cap, WebGLboolean *retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
     {
         *retval = false;
         return NS_OK;
     }
 
     *retval = 0;
 
     if (!ValidateCapabilityEnum(cap, "isEnabled"))
@@ -3184,17 +3184,17 @@ WebGLContext::IsEnabled(WebGLenum cap, W
     return NS_OK;
 }
 
 GL_SAME_METHOD_1(LineWidth, LineWidth, WebGLfloat)
 
 NS_IMETHODIMP
 WebGLContext::LinkProgram(nsIWebGLProgram *pobj)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     GLuint progname;
     WebGLProgram *program;
     if (!GetConcreteObjectAndGLName("linkProgram", pobj, &program, &progname))
         return NS_OK;
 
     if (!program->NextGeneration())
@@ -3219,17 +3219,17 @@ WebGLContext::LinkProgram(nsIWebGLProgra
     }
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::PixelStorei(WebGLenum pname, WebGLint param)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     switch (pname) {
         case UNPACK_FLIP_Y_WEBGL:
             mPixelStoreFlipY = (param != 0);
             break;
         case UNPACK_PREMULTIPLY_ALPHA_WEBGL:
             mPixelStorePremultiplyAlpha = (param != 0);
@@ -3262,17 +3262,17 @@ WebGLContext::PixelStorei(WebGLenum pnam
 }
 
 
 GL_SAME_METHOD_2(PolygonOffset, PolygonOffset, WebGLfloat, WebGLfloat)
 
 NS_IMETHODIMP
 WebGLContext::ReadPixels(PRInt32)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     return NS_ERROR_FAILURE;
 }
 
 nsresult
 WebGLContext::ReadPixels_base(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height,
                               WebGLenum format, WebGLenum type, JSObject* pixels)
@@ -3491,26 +3491,26 @@ WebGLContext::ReadPixels_base(WebGLint x
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::ReadPixels_array(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height,
                                WebGLenum format, WebGLenum type, JSObject *pixels)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     return ReadPixels_base(x, y, width, height, format, type, pixels);
 }
 
 NS_IMETHODIMP
 WebGLContext::RenderbufferStorage(WebGLenum target, WebGLenum internalformat, WebGLsizei width, WebGLsizei height)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!mBoundRenderbuffer || !mBoundRenderbuffer->GLName())
         return ErrorInvalidOperation("renderbufferStorage called on renderbuffer 0");
 
     if (target != LOCAL_GL_RENDERBUFFER)
         return ErrorInvalidEnumInfo("renderbufferStorage: target", target);
 
@@ -3581,31 +3581,31 @@ WebGLContext::RenderbufferStorage(WebGLe
     return NS_OK;
 }
 
 GL_SAME_METHOD_2(SampleCoverage, SampleCoverage, WebGLfloat, WebGLboolean)
 
 NS_IMETHODIMP
 WebGLContext::Scissor(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (width < 0 || height < 0)
         return ErrorInvalidValue("Scissor: negative size");
 
     MakeContextCurrent();
     gl->fScissor(x, y, width, height);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::StencilFunc(WebGLenum func, WebGLint ref, WebGLuint mask)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!ValidateComparisonEnum(func, "stencilFunc: func"))
         return NS_OK;
 
     mStencilRefFront = ref;
     mStencilRefBack = ref;
     mStencilValueMaskFront = mask;
@@ -3614,17 +3614,17 @@ WebGLContext::StencilFunc(WebGLenum func
     MakeContextCurrent();
     gl->fStencilFunc(func, ref, mask);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::StencilFuncSeparate(WebGLenum face, WebGLenum func, WebGLint ref, WebGLuint mask)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!ValidateFaceEnum(face, "stencilFuncSeparate: face") ||
         !ValidateComparisonEnum(func, "stencilFuncSeparate: func"))
         return NS_OK;
 
     switch (face) {
         case LOCAL_GL_FRONT_AND_BACK:
@@ -3646,31 +3646,31 @@ WebGLContext::StencilFuncSeparate(WebGLe
     MakeContextCurrent();
     gl->fStencilFuncSeparate(face, func, ref, mask);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::StencilMask(WebGLuint mask)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     mStencilWriteMaskFront = mask;
     mStencilWriteMaskBack = mask;
 
     MakeContextCurrent();
     gl->fStencilMask(mask);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::StencilMaskSeparate(WebGLenum face, WebGLuint mask)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!ValidateFaceEnum(face, "stencilMaskSeparate: face"))
         return NS_OK;
 
     switch (face) {
         case LOCAL_GL_FRONT_AND_BACK:
             mStencilWriteMaskFront = mask;
@@ -3687,33 +3687,33 @@ WebGLContext::StencilMaskSeparate(WebGLe
     MakeContextCurrent();
     gl->fStencilMaskSeparate(face, mask);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::StencilOp(WebGLenum sfail, WebGLenum dpfail, WebGLenum dppass)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!ValidateStencilOpEnum(sfail, "stencilOp: sfail") ||
         !ValidateStencilOpEnum(dpfail, "stencilOp: dpfail") ||
         !ValidateStencilOpEnum(dppass, "stencilOp: dppass"))
         return NS_OK;
 
     MakeContextCurrent();
     gl->fStencilOp(sfail, dpfail, dppass);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::StencilOpSeparate(WebGLenum face, WebGLenum sfail, WebGLenum dpfail, WebGLenum dppass)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!ValidateFaceEnum(face, "stencilOpSeparate: face") ||
         !ValidateStencilOpEnum(sfail, "stencilOpSeparate: sfail") ||
         !ValidateStencilOpEnum(dpfail, "stencilOpSeparate: dpfail") ||
         !ValidateStencilOpEnum(dppass, "stencilOpSeparate: dppass"))
         return NS_OK;
 
@@ -4021,17 +4021,17 @@ WebGLContext::DOMElementToImageSurface(n
 #define SIMPLE_ARRAY_METHOD_UNIFORM(name, cnt, arrayType, ptrType)      \
 NS_IMETHODIMP                                                           \
 WebGLContext::name(PRInt32) {                                     \
      return NS_ERROR_NOT_IMPLEMENTED;                                   \
 }                                                                       \
 NS_IMETHODIMP                                                           \
 WebGLContext::name##_array(nsIWebGLUniformLocation *ploc, JSObject *wa) \
 {                                                                       \
-    if (mContextLost)                                                   \
+    if (!IsContextStable())                                                   \
         return NS_OK;                                                   \
     OBTAIN_UNIFORM_LOCATION(#name ": location")                         \
     if (!wa || JS_GetTypedArrayType(wa) != js::TypedArray::arrayType)   \
         return ErrorInvalidOperation(#name ": array must be " #arrayType);      \
     if (JS_GetTypedArrayLength(wa) == 0 || JS_GetTypedArrayLength(wa) % cnt != 0)\
         return ErrorInvalidValue(#name ": array must be > 0 elements and have a length multiple of %d", cnt); \
     MakeContextCurrent();                                               \
     gl->f##name(location, JS_GetTypedArrayLength(wa) / cnt, (ptrType *)JS_GetTypedArrayData(wa));            \
@@ -4041,57 +4041,57 @@ WebGLContext::name##_array(nsIWebGLUnifo
 #define SIMPLE_MATRIX_METHOD_UNIFORM(name, dim, arrayType, ptrType)     \
 NS_IMETHODIMP                                                           \
 WebGLContext::name(PRInt32) {                                     \
      return NS_ERROR_NOT_IMPLEMENTED;                                   \
 }                                                                       \
 NS_IMETHODIMP                                                           \
 WebGLContext::name##_array(nsIWebGLUniformLocation *ploc, WebGLboolean transpose, JSObject *wa)  \
 {                                                                       \
-    if (mContextLost)                                                   \
+    if (!IsContextStable())                                                   \
         return NS_OK;                                                   \
     OBTAIN_UNIFORM_LOCATION(#name ": location")                         \
     if (!wa || JS_GetTypedArrayType(wa) != js::TypedArray::arrayType)                   \
         return ErrorInvalidValue(#name ": array must be " #arrayType);      \
     if (JS_GetTypedArrayLength(wa) == 0 || JS_GetTypedArrayLength(wa) % (dim*dim) != 0)                 \
         return ErrorInvalidValue(#name ": array length must be >0 and multiple of %d", dim*dim); \
     if (transpose)                                                      \
         return ErrorInvalidValue(#name ": transpose must be FALSE as per the OpenGL ES 2.0 spec"); \
     MakeContextCurrent();                                               \
     gl->f##name(location, JS_GetTypedArrayLength(wa) / (dim*dim), transpose, (ptrType *)JS_GetTypedArrayData(wa)); \
     return NS_OK;                                                       \
 }
 
 #define SIMPLE_METHOD_UNIFORM_1(glname, name, t1)        \
 NS_IMETHODIMP WebGLContext::name(nsIWebGLUniformLocation *ploc, t1 a1) {      \
-    if (mContextLost)                                    \
+    if (!IsContextStable())                                    \
         return NS_OK;                                    \
     OBTAIN_UNIFORM_LOCATION(#name ": location") \
     MakeContextCurrent(); gl->f##glname(location, a1); return NS_OK; \
 }
 
 #define SIMPLE_METHOD_UNIFORM_2(glname, name, t1, t2)        \
 NS_IMETHODIMP WebGLContext::name(nsIWebGLUniformLocation *ploc, t1 a1, t2 a2) {      \
-    if (mContextLost)                                        \
+    if (!IsContextStable())                                        \
         return NS_OK;                                        \
     OBTAIN_UNIFORM_LOCATION(#name ": location") \
     MakeContextCurrent(); gl->f##glname(location, a1, a2); return NS_OK; \
 }
 
 #define SIMPLE_METHOD_UNIFORM_3(glname, name, t1, t2, t3)        \
 NS_IMETHODIMP WebGLContext::name(nsIWebGLUniformLocation *ploc, t1 a1, t2 a2, t3 a3) {      \
-    if (mContextLost)                                            \
+    if (!IsContextStable())                                            \
         return NS_OK;                                            \
     OBTAIN_UNIFORM_LOCATION(#name ": location") \
     MakeContextCurrent(); gl->f##glname(location, a1, a2, a3); return NS_OK; \
 }
 
 #define SIMPLE_METHOD_UNIFORM_4(glname, name, t1, t2, t3, t4)        \
 NS_IMETHODIMP WebGLContext::name(nsIWebGLUniformLocation *ploc, t1 a1, t2 a2, t3 a3, t4 a4) {      \
-    if (mContextLost)                                                \
+    if (!IsContextStable())                                                \
         return NS_OK;                                                \
     OBTAIN_UNIFORM_LOCATION(#name ": location") \
     MakeContextCurrent(); gl->f##glname(location, a1, a2, a3, a4); return NS_OK; \
 }
 
 SIMPLE_METHOD_UNIFORM_1(Uniform1i, Uniform1i, WebGLint)
 SIMPLE_METHOD_UNIFORM_2(Uniform2i, Uniform2i, WebGLint, WebGLint)
 SIMPLE_METHOD_UNIFORM_3(Uniform3i, Uniform3i, WebGLint, WebGLint, WebGLint)
@@ -4114,17 +4114,17 @@ SIMPLE_ARRAY_METHOD_UNIFORM(Uniform4fv, 
 
 SIMPLE_MATRIX_METHOD_UNIFORM(UniformMatrix2fv, 2, TYPE_FLOAT32, WebGLfloat)
 SIMPLE_MATRIX_METHOD_UNIFORM(UniformMatrix3fv, 3, TYPE_FLOAT32, WebGLfloat)
 SIMPLE_MATRIX_METHOD_UNIFORM(UniformMatrix4fv, 4, TYPE_FLOAT32, WebGLfloat)
 
 NS_IMETHODIMP
 WebGLContext::VertexAttrib1f(PRUint32 index, WebGLfloat x0)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     MakeContextCurrent();
 
     if (index) {
         gl->fVertexAttrib1f(index, x0);
     } else {
         mVertexAttrib0Vector[0] = x0;
@@ -4136,17 +4136,17 @@ WebGLContext::VertexAttrib1f(PRUint32 in
     }
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::VertexAttrib2f(PRUint32 index, WebGLfloat x0, WebGLfloat x1)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     MakeContextCurrent();
 
     if (index) {
         gl->fVertexAttrib2f(index, x0, x1);
     } else {
         mVertexAttrib0Vector[0] = x0;
@@ -4158,17 +4158,17 @@ WebGLContext::VertexAttrib2f(PRUint32 in
     }
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::VertexAttrib3f(PRUint32 index, WebGLfloat x0, WebGLfloat x1, WebGLfloat x2)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     MakeContextCurrent();
 
     if (index) {
         gl->fVertexAttrib3f(index, x0, x1, x2);
     } else {
         mVertexAttrib0Vector[0] = x0;
@@ -4181,17 +4181,17 @@ WebGLContext::VertexAttrib3f(PRUint32 in
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::VertexAttrib4f(PRUint32 index, WebGLfloat x0, WebGLfloat x1,
                                              WebGLfloat x2, WebGLfloat x3)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     MakeContextCurrent();
 
     if (index) {
         gl->fVertexAttrib4f(index, x0, x1, x2, x3);
     } else {
         mVertexAttrib0Vector[0] = x0;
@@ -4208,17 +4208,17 @@ WebGLContext::VertexAttrib4f(PRUint32 in
 #define SIMPLE_ARRAY_METHOD_NO_COUNT(name, cnt, arrayType, ptrType)  \
 NS_IMETHODIMP                                                           \
 WebGLContext::name(PRInt32) {                                     \
      return NS_ERROR_NOT_IMPLEMENTED;                                   \
 }                                                                       \
 NS_IMETHODIMP                                                           \
 WebGLContext::name##_array(WebGLuint idx, JSObject *wa)           \
 {                                                                       \
-    if (mContextLost)                                                   \
+    if (!IsContextStable())                                                   \
         return NS_OK;                                                   \
     if (!wa || JS_GetTypedArrayType(wa) != js::TypedArray::arrayType)                   \
         return ErrorInvalidOperation(#name ": array must be " #arrayType); \
     if (JS_GetTypedArrayLength(wa) < cnt)                                               \
         return ErrorInvalidOperation(#name ": array must be >= %d elements", cnt); \
     MakeContextCurrent();                                               \
     ptrType *ptr = (ptrType *)JS_GetTypedArrayData(wa);                                  \
     if (idx) {                                                        \
@@ -4237,17 +4237,17 @@ WebGLContext::name##_array(WebGLuint idx
 SIMPLE_ARRAY_METHOD_NO_COUNT(VertexAttrib1fv, 1, TYPE_FLOAT32, WebGLfloat)
 SIMPLE_ARRAY_METHOD_NO_COUNT(VertexAttrib2fv, 2, TYPE_FLOAT32, WebGLfloat)
 SIMPLE_ARRAY_METHOD_NO_COUNT(VertexAttrib3fv, 3, TYPE_FLOAT32, WebGLfloat)
 SIMPLE_ARRAY_METHOD_NO_COUNT(VertexAttrib4fv, 4, TYPE_FLOAT32, WebGLfloat)
 
 NS_IMETHODIMP
 WebGLContext::UseProgram(nsIWebGLProgram *pobj)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     WebGLProgram *prog;
     WebGLuint progname;
     bool isNull;
     if (!GetConcreteObjectAndGLName("useProgram", pobj, &prog, &progname, &isNull))
         return NS_OK;
 
@@ -4261,17 +4261,17 @@ WebGLContext::UseProgram(nsIWebGLProgram
     mCurrentProgram = prog;
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::ValidateProgram(nsIWebGLProgram *pobj)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     WebGLuint progname;
     if (!GetGLName<WebGLProgram>("validateProgram", pobj, &progname))
         return NS_OK;
 
     MakeContextCurrent();
 
@@ -4284,59 +4284,59 @@ WebGLContext::ValidateProgram(nsIWebGLPr
     gl->fValidateProgram(progname);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::CreateFramebuffer(nsIWebGLFramebuffer **retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     *retval = 0;
 
     WebGLFramebuffer *globj = new WebGLFramebuffer(this);
     NS_ADDREF(*retval = globj);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::CreateRenderbuffer(nsIWebGLRenderbuffer **retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     *retval = 0;
 
     WebGLRenderbuffer *globj = new WebGLRenderbuffer(this);
     NS_ADDREF(*retval = globj);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::Viewport(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (width < 0 || height < 0)
         return ErrorInvalidValue("Viewport: negative size");
 
     MakeContextCurrent();
     gl->fViewport(x, y, width, height);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::CompileShader(nsIWebGLShader *sobj)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     WebGLShader *shader;
     WebGLuint shadername;
     if (!GetConcreteObjectAndGLName("compileShader", sobj, &shader, &shadername))
         return NS_OK;
 
     MakeContextCurrent();
@@ -4446,17 +4446,17 @@ WebGLContext::CompileShader(nsIWebGLShad
 
     return NS_OK;
 }
 
 
 NS_IMETHODIMP
 WebGLContext::GetShaderParameter(nsIWebGLShader *sobj, WebGLenum pname, nsIVariant **retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     *retval = nsnull;
 
     WebGLShader *shader;
     WebGLuint shadername;
     if (!GetConcreteObjectAndGLName("getShaderParameter: shader", sobj, &shader, &shadername))
         return NS_OK;
@@ -4497,17 +4497,17 @@ WebGLContext::GetShaderParameter(nsIWebG
     *retval = wrval.forget().get();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::GetShaderInfoLog(nsIWebGLShader *sobj, nsAString& retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
     {
         retval.SetIsVoid(true);
         return NS_OK;
     }
 
     WebGLShader *shader;
     WebGLuint shadername;
     if (!GetConcreteObjectAndGLName("getShaderInfoLog: shader", sobj, &shader, &shadername))
@@ -4542,17 +4542,17 @@ WebGLContext::GetShaderInfoLog(nsIWebGLS
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::GetShaderPrecisionFormat(WebGLenum shadertype, WebGLenum precisiontype, nsIWebGLShaderPrecisionFormat **retval)
 {
     *retval = nsnull;
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     switch (shadertype) {
         case LOCAL_GL_FRAGMENT_SHADER:
         case LOCAL_GL_VERTEX_SHADER:
             break;
         default:
             return ErrorInvalidEnumInfo("getShaderPrecisionFormat: shadertype", shadertype);
@@ -4580,17 +4580,17 @@ WebGLContext::GetShaderPrecisionFormat(W
     NS_ADDREF(*retval = retShaderPrecisionFormat);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::GetShaderSource(nsIWebGLShader *sobj, nsAString& retval)
 {
-    if (mContextLost)
+    if (!IsContextStable())
     {
         retval.SetIsVoid(true);
         return NS_OK;
     }
 
     WebGLShader *shader;
     WebGLuint shadername;
     if (!GetConcreteObjectAndGLName("getShaderSource: shader", sobj, &shader, &shadername))
@@ -4599,17 +4599,17 @@ WebGLContext::GetShaderSource(nsIWebGLSh
     retval.Assign(shader->Source());
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::ShaderSource(nsIWebGLShader *sobj, const nsAString& source)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     WebGLShader *shader;
     WebGLuint shadername;
     if (!GetConcreteObjectAndGLName("shaderSource: shader", sobj, &shader, &shadername))
         return NS_OK;
 
     // We're storing an actual instance of StripComments because, if we don't, the 
@@ -4627,17 +4627,17 @@ WebGLContext::ShaderSource(nsIWebGLShade
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::VertexAttribPointer(WebGLuint index, WebGLint size, WebGLenum type,
                                   WebGLboolean normalized, WebGLsizei stride,
                                   WebGLsizeiptr byteOffset)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (mBoundArrayBuffer == nsnull)
         return ErrorInvalidOperation("VertexAttribPointer: must have valid GL_ARRAY_BUFFER binding");
 
     WebGLsizei requiredAlignment = 1;
     switch (type) {
       case LOCAL_GL_BYTE:
@@ -4703,17 +4703,17 @@ WebGLContext::VertexAttribPointer(WebGLu
                              (void*) (byteOffset));
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::TexImage2D(PRInt32)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     return NS_ERROR_FAILURE;
 }
 
 GLenum WebGLContext::CheckedTexImage2D(GLenum target,
                                        GLint level,
                                        GLenum internalFormat,
@@ -4899,47 +4899,47 @@ WebGLContext::TexImage2D_base(WebGLenum 
 }
 
 NS_IMETHODIMP
 WebGLContext::TexImage2D_array(WebGLenum target, WebGLint level, WebGLenum internalformat,
                                WebGLsizei width, WebGLsizei height, WebGLint border,
                                WebGLenum format, WebGLenum type,
                                JSObject *pixels)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     return TexImage2D_base(target, level, internalformat, width, height, 0, border, format, type,
                            pixels ? JS_GetTypedArrayData(pixels) : 0,
                            pixels ? JS_GetTypedArrayByteLength(pixels) : 0,
                            pixels ? (int)JS_GetTypedArrayType(pixels) : -1,
                            WebGLTexelFormat::Auto, false);
 }
 
 NS_IMETHODIMP
 WebGLContext::TexImage2D_imageData(WebGLenum target, WebGLint level, WebGLenum internalformat,
                                WebGLsizei width, WebGLsizei height, WebGLint border,
                                WebGLenum format, WebGLenum type,
                                JSObject *pixels)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     return TexImage2D_base(target, level, internalformat, width, height, 4*width, border, format, type,
                            pixels ? JS_GetTypedArrayData(pixels) : 0,
                            pixels ? JS_GetTypedArrayByteLength(pixels) : 0,
                            -1,
                            WebGLTexelFormat::RGBA8, false);
 }
 
 NS_IMETHODIMP
 WebGLContext::TexImage2D_dom(WebGLenum target, WebGLint level, WebGLenum internalformat,
                              WebGLenum format, GLenum type, nsIDOMElement *elt)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     nsRefPtr<gfxImageSurface> isurf;
 
     int srcFormat;
     nsresult rv = DOMElementToImageSurface(elt, getter_AddRefs(isurf), &srcFormat);
     if (NS_FAILED(rv))
         return rv;
@@ -4952,17 +4952,17 @@ WebGLContext::TexImage2D_dom(WebGLenum t
                            isurf->Data(), byteLength,
                            -1,
                            srcFormat, mPixelStorePremultiplyAlpha);
 }
 
 NS_IMETHODIMP
 WebGLContext::TexSubImage2D(PRInt32)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     return NS_ERROR_FAILURE;
 }
 
 nsresult
 WebGLContext::TexSubImage2D_base(WebGLenum target, WebGLint level,
                                  WebGLint xoffset, WebGLint yoffset,
@@ -5080,17 +5080,17 @@ WebGLContext::TexSubImage2D_base(WebGLen
 
 NS_IMETHODIMP
 WebGLContext::TexSubImage2D_array(WebGLenum target, WebGLint level,
                                   WebGLint xoffset, WebGLint yoffset,
                                   WebGLsizei width, WebGLsizei height,
                                   WebGLenum format, WebGLenum type,
                                   JSObject *pixels)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!pixels)
         return ErrorInvalidValue("TexSubImage2D: pixels must not be null!");
 
     return TexSubImage2D_base(target, level, xoffset, yoffset,
                               width, height, 0, format, type,
                               JS_GetTypedArrayData(pixels), JS_GetTypedArrayByteLength(pixels),
@@ -5100,17 +5100,17 @@ WebGLContext::TexSubImage2D_array(WebGLe
 
 NS_IMETHODIMP
 WebGLContext::TexSubImage2D_imageData(WebGLenum target, WebGLint level,
                                       WebGLint xoffset, WebGLint yoffset,
                                       WebGLsizei width, WebGLsizei height,
                                       WebGLenum format, WebGLenum type,
                                       JSObject *pixels)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     if (!pixels)
         return ErrorInvalidValue("TexSubImage2D: pixels must not be null!");
 
     return TexSubImage2D_base(target, level, xoffset, yoffset,
                               width, height, 4*width, format, type,
                               JS_GetTypedArrayData(pixels), JS_GetTypedArrayByteLength(pixels),
@@ -5119,17 +5119,17 @@ WebGLContext::TexSubImage2D_imageData(We
 }
 
 NS_IMETHODIMP
 WebGLContext::TexSubImage2D_dom(WebGLenum target, WebGLint level,
                                 WebGLint xoffset, WebGLint yoffset,
                                 WebGLenum format, WebGLenum type,
                                 nsIDOMElement *elt)
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return NS_OK;
 
     nsRefPtr<gfxImageSurface> isurf;
 
     int srcFormat;
     nsresult rv = DOMElementToImageSurface(elt, getter_AddRefs(isurf), &srcFormat);
     if (NS_FAILED(rv))
         return rv;
@@ -5143,17 +5143,17 @@ WebGLContext::TexSubImage2D_dom(WebGLenu
                               isurf->Data(), byteLength,
                               -1,
                               srcFormat, mPixelStorePremultiplyAlpha);
 }
 
 bool
 WebGLContext::LoseContext()
 {
-    if (mContextLost)
+    if (!IsContextStable())
         return false;
 
     mContextLostDueToTest = true;
     ForceLoseContext();
 
     return true;
 }