Fix for bug 741367 (Creating second XMLHttpRequest via Components.Constructor throws NS_ERROR_FAILURE): don't overwrite content-defined properties. r=bz, a=akeybl.
authorPeter Van der Beken <peterv@propagandism.org>
Fri, 27 Apr 2012 09:57:09 +0200
changeset 94200 62bc457629b60c9352cff17d4582f866f534a2d5
parent 94199 56cc5a3c431612fa98f0550f02a9f34b566e1d9b
child 94201 7d702f45c71a1875dd3e87e583a7d848057211b5
push idunknown
push userunknown
push dateunknown
reviewersbz, akeybl
bugs741367
milestone14.0a2
Fix for bug 741367 (Creating second XMLHttpRequest via Components.Constructor throws NS_ERROR_FAILURE): don't overwrite content-defined properties. r=bz, a=akeybl.
dom/bindings/Utils.cpp
--- a/dom/bindings/Utils.cpp
+++ b/dom/bindings/Utils.cpp
@@ -58,18 +58,24 @@ CreateInterfaceObject(JSContext* cx, JSO
   if (constants && !DefineConstants(cx, constructor, constants)) {
     return NULL;
   }
 
   if (proto && !JS_LinkConstructorAndPrototype(cx, constructor, proto)) {
     return NULL;
   }
 
+  JSBool alreadyDefined;
+  if (!JS_AlreadyHasOwnProperty(cx, receiver, name, &alreadyDefined)) {
+    return NULL;
+  }
+
   // This is Enumerable: False per spec.
-  if (!JS_DefineProperty(cx, receiver, name, OBJECT_TO_JSVAL(constructor), NULL,
+  if (!alreadyDefined &&
+      !JS_DefineProperty(cx, receiver, name, OBJECT_TO_JSVAL(constructor), NULL,
                          NULL, 0)) {
     return NULL;
   }
 
   return constructor;
 }
 
 static JSObject*