Bug 752737 - Delete the default and copy constructors and assignment operator from JSString and JSObject to avoid errors. r=luke
authorJeff Walden <jwalden@mit.edu>
Mon, 07 May 2012 16:45:19 -0700
changeset 93435 e5f63aa66be67ae934caadb299f1f4ec82483aec
parent 93434 bfe31dbdee16fed4191826d5b419a46b04e59415
child 93436 77a87e7c6f500f6527073b02788dd67204fb8979
push id22634
push useremorley@mozilla.com
push dateTue, 08 May 2012 09:48:43 +0000
treeherdermozilla-central@e4f9e2eab6b1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs752737
milestone15.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 752737 - Delete the default and copy constructors and assignment operator from JSString and JSObject to avoid errors. r=luke
js/src/jsapi-tests/testConservativeGC.cpp
js/src/jsobj.h
js/src/vm/BooleanObject.h
js/src/vm/GlobalObject.h
js/src/vm/NumberObject.h
js/src/vm/RegExpObject.h
js/src/vm/String.h
js/src/vm/StringObject.h
--- a/js/src/jsapi-tests/testConservativeGC.cpp
+++ b/js/src/jsapi-tests/testConservativeGC.cpp
@@ -8,46 +8,48 @@ BEGIN_TEST(testConservativeGC)
     EVAL("({foo: 'bar'});", &v2);
     CHECK(JSVAL_IS_OBJECT(v2));
     char objCopy[sizeof(JSObject)];
     js_memcpy(&objCopy, JSVAL_TO_OBJECT(v2), sizeof(JSObject));
 
     jsval v3;
     EVAL("String(Math.PI);", &v3);
     CHECK(JSVAL_IS_STRING(v3));
-    JSString strCopy = *JSVAL_TO_STRING(v3);
+    char strCopy[sizeof(JSString)];
+    js_memcpy(&strCopy, JSVAL_TO_STRING(v3), sizeof(JSString));
 
     jsval tmp;
     EVAL("({foo2: 'bar2'});", &tmp);
     CHECK(JSVAL_IS_OBJECT(tmp));
     JSObject *obj2 = JSVAL_TO_OBJECT(tmp);
     char obj2Copy[sizeof(JSObject)];
     js_memcpy(&obj2Copy, obj2, sizeof(JSObject));
 
     EVAL("String(Math.sqrt(3));", &tmp);
     CHECK(JSVAL_IS_STRING(tmp));
     JSString *str2 = JSVAL_TO_STRING(tmp);
-    JSString str2Copy = *str2;
+    char str2Copy[sizeof(JSString)];
+    js_memcpy(&str2Copy, str2, sizeof(JSString));
 
     tmp = JSVAL_NULL;
 
     JS_GC(rt);
 
     EVAL("var a = [];\n"
          "for (var i = 0; i != 10000; ++i) {\n"
          "a.push(i + 0.1, [1, 2], String(Math.sqrt(i)), {a: i});\n"
          "}", &tmp);
 
     JS_GC(rt);
 
     checkObjectFields((JSObject *)objCopy, JSVAL_TO_OBJECT(v2));
-    CHECK(!memcmp(&strCopy, JSVAL_TO_STRING(v3), sizeof(strCopy)));
+    CHECK(!memcmp(strCopy, JSVAL_TO_STRING(v3), sizeof(strCopy)));
 
     checkObjectFields((JSObject *)obj2Copy, obj2);
-    CHECK(!memcmp(&str2Copy, str2, sizeof(str2Copy)));
+    CHECK(!memcmp(str2Copy, str2, sizeof(str2Copy)));
 
     return true;
 }
 
 bool checkObjectFields(JSObject *savedCopy, JSObject *obj)
 {
     /* Ignore fields which are unstable across GCs. */
     CHECK(savedCopy->lastProperty() == obj->lastProperty());
--- a/js/src/jsobj.h
+++ b/js/src/jsobj.h
@@ -993,16 +993,20 @@ struct JSObject : public js::ObjectImpl
     static void staticAsserts() {
         MOZ_STATIC_ASSERT(sizeof(JSObject) == sizeof(js::shadow::Object),
                           "shadow interface must match actual interface");
         MOZ_STATIC_ASSERT(sizeof(JSObject) == sizeof(js::ObjectImpl),
                           "JSObject itself must not have any fields");
         MOZ_STATIC_ASSERT(sizeof(JSObject) % sizeof(js::Value) == 0,
                           "fixed slots after an object must be aligned");
     }
+
+    JSObject() MOZ_DELETE;
+    JSObject(const JSObject &other) MOZ_DELETE;
+    void operator=(const JSObject &other) MOZ_DELETE;
 };
 
 /*
  * The only sensible way to compare JSObject with == is by identity. We use
  * const& instead of * as a syntactic way to assert non-null. This leads to an
  * abundance of address-of operators to identity. Hence this overload.
  */
 static JS_ALWAYS_INLINE bool
--- a/js/src/vm/BooleanObject.h
+++ b/js/src/vm/BooleanObject.h
@@ -36,18 +36,16 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef BooleanObject_h___
 #define BooleanObject_h___
 
-#include "mozilla/Attributes.h"
-
 #include "jsbool.h"
 
 namespace js {
 
 class BooleanObject : public JSObject
 {
     /* Stores this Boolean object's [[PrimitiveValue]]. */
     static const unsigned PRIMITIVE_VALUE_SLOT = 0;
@@ -74,17 +72,13 @@ class BooleanObject : public JSObject
   private:
     inline void setPrimitiveValue(bool b) {
         setFixedSlot(PRIMITIVE_VALUE_SLOT, BooleanValue(b));
     }
 
     /* For access to init, as Boolean.prototype is special. */
     friend JSObject *
     ::js_InitBooleanClass(JSContext *cx, JSObject *global);
-
-  private:
-    BooleanObject() MOZ_DELETE;
-    BooleanObject &operator=(const BooleanObject &bo) MOZ_DELETE;
 };
 
 } // namespace js
 
 #endif /* BooleanObject_h__ */
--- a/js/src/vm/GlobalObject.h
+++ b/js/src/vm/GlobalObject.h
@@ -89,20 +89,18 @@ class Debugger;
  *
  * The first two ranges are necessary to implement js::FindClassObject,
  * js::FindClassPrototype, and spec language speaking in terms of "the original
  * Array prototype object", or "as if by the expression new Array()" referring
  * to the original Array constructor.  The third range stores the (writable and
  * even deletable) Object, Array, &c. properties (although a slot won't be used
  * again if its property is deleted and readded).
  */
-class GlobalObject : public JSObject {
-    GlobalObject(const GlobalObject &other) MOZ_DELETE;
-    void operator=(const GlobalObject &other) MOZ_DELETE;
-
+class GlobalObject : public JSObject
+{
     /*
      * Count of slots to store built-in constructors, prototypes, and initial
      * visible properties for the constructors.
      */
     static const unsigned STANDARD_CLASS_SLOTS  = JSProto_LIMIT * 3;
 
     /* One-off properties stored after slots for built-ins. */
     static const unsigned THROWTYPEERROR          = STANDARD_CLASS_SLOTS;
--- a/js/src/vm/NumberObject.h
+++ b/js/src/vm/NumberObject.h
@@ -36,18 +36,16 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef NumberObject_h___
 #define NumberObject_h___
 
-#include "mozilla/Attributes.h"
-
 #include "jsnum.h"
 
 namespace js {
 
 class NumberObject : public JSObject
 {
     /* Stores this Number object's [[PrimitiveValue]]. */
     static const unsigned PRIMITIVE_VALUE_SLOT = 0;
@@ -74,17 +72,13 @@ class NumberObject : public JSObject
   private:
     inline void setPrimitiveValue(double d) {
         setFixedSlot(PRIMITIVE_VALUE_SLOT, NumberValue(d));
     }
 
     /* For access to init, as Number.prototype is special. */
     friend JSObject *
     ::js_InitNumberClass(JSContext *cx, JSObject *global);
-
-  private:
-    NumberObject() MOZ_DELETE;
-    NumberObject &operator=(const NumberObject &so) MOZ_DELETE;
 };
 
 } // namespace js
 
 #endif /* NumberObject_h__ */
--- a/js/src/vm/RegExpObject.h
+++ b/js/src/vm/RegExpObject.h
@@ -419,19 +419,16 @@ class RegExpObject : public JSObject
 
     /*
      * Precondition: the syntax for |source| has already been validated.
      * Side effect: sets the private field.
      */
     bool createShared(JSContext *cx, RegExpGuard *g);
     RegExpShared *maybeShared() const;
 
-    RegExpObject() MOZ_DELETE;
-    RegExpObject &operator=(const RegExpObject &reo) MOZ_DELETE;
-
     /* Call setShared in preference to setPrivate. */
     void setPrivate(void *priv) MOZ_DELETE;
 };
 
 /*
  * Parse regexp flags. Report an error and return false if an invalid
  * sequence of flags is encountered (repeat/invalid flag).
  *
--- a/js/src/vm/String.h
+++ b/js/src/vm/String.h
@@ -417,16 +417,21 @@ class JSString : public js::gc::Cell
     static inline void readBarrier(JSString *str);
 
     static inline js::ThingRootKind rootKind() { return js::THING_ROOT_STRING; }
 
 #ifdef DEBUG
     void dump();
     bool equals(const char *s);
 #endif
+
+  private:
+    JSString() MOZ_DELETE;
+    JSString(const JSString &other) MOZ_DELETE;
+    void operator=(const JSString &other) MOZ_DELETE;
 };
 
 class JSRope : public JSString
 {
     enum UsingBarrier { WithIncrementalBarrier, NoBarrier };
     template<UsingBarrier b>
     JSFlatString *flattenInternal(JSContext *cx);
 
--- a/js/src/vm/StringObject.h
+++ b/js/src/vm/StringObject.h
@@ -36,18 +36,16 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef StringObject_h___
 #define StringObject_h___
 
-#include "mozilla/Attributes.h"
-
 #include "jsobj.h"
 #include "jsstr.h"
 
 namespace js {
 
 class StringObject : public JSObject
 {
     static const unsigned PRIMITIVE_VALUE_SLOT = 0;
@@ -94,17 +92,13 @@ class StringObject : public JSObject
     ::js_InitStringClass(JSContext *cx, JSObject *global);
 
     /*
      * Compute the initial shape to associate with fresh String objects, which
      * encodes the initial length property. Return the shape after changing
      * this String object's last property to it.
      */
     Shape *assignInitialShape(JSContext *cx);
-
-  private:
-    StringObject() MOZ_DELETE;
-    StringObject &operator=(const StringObject &so) MOZ_DELETE;
 };
 
 } // namespace js
 
 #endif /* StringObject_h__ */