Mark a bunch more copy-construction, assignment, default-construction, etc. operators and methods as deleted in the JS engine. No bug, r=bhackett over IRC
authorJeff Walden <jwalden@mit.edu>
Wed, 28 Dec 2011 08:09:07 -0600
changeset 84675 9bb39109e7246f6c7dc16295c242c57d0d7e9be5
parent 84674 f4193185e67d56c5f898ed5cdf7a2e191eab040d
child 84676 9ff526c636cd7d0c32c21906ed9818e15a2e511b
push idunknown
push userunknown
push dateunknown
reviewersbhackett
milestone12.0a1
Mark a bunch more copy-construction, assignment, default-construction, etc. operators and methods as deleted in the JS engine. No bug, r=bhackett over IRC
js/src/frontend/ParseMaps.h
js/src/jscntxt.h
js/src/jsgc.cpp
js/src/jsonparser.h
js/src/jsstr.cpp
js/src/jsstrinlines.h
js/src/jsutil.h
js/src/shell/jsworkers.cpp
js/src/vm/BooleanObject.h
js/src/vm/GlobalObject.h
js/src/vm/NumberObject.h
js/src/vm/RegExpObject.h
js/src/vm/StringObject.h
--- a/js/src/frontend/ParseMaps.h
+++ b/js/src/frontend/ParseMaps.h
@@ -36,16 +36,18 @@
  * 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 ParseMaps_h__
 #define ParseMaps_h__
 
+#include "mozilla/Attributes.h"
+
 #include "ds/InlineMap.h"
 #include "js/HashTable.h"
 #include "js/Vector.h"
 
 namespace js {
 
 struct Definition;
 
@@ -262,18 +264,18 @@ template <> struct IsPodType<DefnOrHeade
 class AtomDecls
 {
     /* AtomDeclsIter needs to get at the DOHMap directly. */
     friend class AtomDeclsIter;
 
     JSContext   *cx;
     AtomDOHMap  *map;
 
-    AtomDecls(const AtomDecls &other);
-    void operator=(const AtomDecls &other);
+    AtomDecls(const AtomDecls &other) MOZ_DELETE;
+    void operator=(const AtomDecls &other) MOZ_DELETE;
 
     AtomDeclNode *allocNode(Definition *defn);
 
     /*
      * Fallibly return the value in |doh| as a node.
      * Update the defn currently occupying |doh| to a node if necessary.
      */
     AtomDeclNode *lastAsNode(DefnOrHeader *doh);
--- a/js/src/jscntxt.h
+++ b/js/src/jscntxt.h
@@ -33,21 +33,23 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * 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 ***** */
 
+/* JS execution context. */
+
 #ifndef jscntxt_h___
 #define jscntxt_h___
-/*
- * JS execution context.
- */
+
+#include "mozilla/Attributes.h"
+
 #include <string.h>
 
 #include "jsfriendapi.h"
 #include "jsprvtd.h"
 #include "jsatom.h"
 #include "jsclist.h"
 #include "jsdhash.h"
 #include "jsgc.h"
@@ -1401,20 +1403,19 @@ class AutoGCRooter {
         ID =          -11, /* js::AutoIdRooter */
         VALVECTOR =   -12, /* js::AutoValueVector */
         DESCRIPTOR =  -13, /* js::AutoPropertyDescriptorRooter */
         STRING =      -14, /* js::AutoStringRooter */
         IDVECTOR =    -15, /* js::AutoIdVector */
         OBJVECTOR =   -16  /* js::AutoObjectVector */
     };
 
-    private:
-    /* No copy or assignment semantics. */
-    AutoGCRooter(AutoGCRooter &ida);
-    void operator=(AutoGCRooter &ida);
+  private:
+    AutoGCRooter(AutoGCRooter &ida) MOZ_DELETE;
+    void operator=(AutoGCRooter &ida) MOZ_DELETE;
 };
 
 /* FIXME(bug 332648): Move this into a public header. */
 class AutoValueRooter : private AutoGCRooter
 {
   public:
     explicit AutoValueRooter(JSContext *cx
                              JS_GUARD_OBJECT_NOTIFIER_PARAM)
@@ -1613,19 +1614,18 @@ class AutoIdArray : private AutoGCRooter
 
   protected:
     inline void trace(JSTracer *trc);
 
   private:
     JSIdArray * idArray;
     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
 
-    /* No copy or assignment semantics. */
-    AutoIdArray(AutoIdArray &ida);
-    void operator=(AutoIdArray &ida);
+    AutoIdArray(AutoIdArray &ida) MOZ_DELETE;
+    void operator=(AutoIdArray &ida) MOZ_DELETE;
 };
 
 /* The auto-root for enumeration object and its state. */
 class AutoEnumStateRooter : private AutoGCRooter
 {
   public:
     AutoEnumStateRooter(JSContext *cx, JSObject *obj
                         JS_GUARD_OBJECT_NOTIFIER_PARAM)
@@ -1792,17 +1792,18 @@ class AutoKeepAtoms {
     ~AutoKeepAtoms() { JS_UNKEEP_ATOMS(rt); }
 };
 
 class AutoReleasePtr {
     JSContext   *cx;
     void        *ptr;
     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
 
-    AutoReleasePtr operator=(const AutoReleasePtr &other);
+    AutoReleasePtr(const AutoReleasePtr &other) MOZ_DELETE;
+    AutoReleasePtr operator=(const AutoReleasePtr &other) MOZ_DELETE;
 
   public:
     explicit AutoReleasePtr(JSContext *cx, void *ptr
                             JS_GUARD_OBJECT_NOTIFIER_PARAM)
       : cx(cx), ptr(ptr)
     {
         JS_GUARD_OBJECT_NOTIFIER_INIT;
     }
@@ -1812,17 +1813,18 @@ class AutoReleasePtr {
 /*
  * FIXME: bug 602774: cleaner API for AutoReleaseNullablePtr
  */
 class AutoReleaseNullablePtr {
     JSContext   *cx;
     void        *ptr;
     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
 
-    AutoReleaseNullablePtr operator=(const AutoReleaseNullablePtr &other);
+    AutoReleaseNullablePtr(const AutoReleaseNullablePtr &other) MOZ_DELETE;
+    AutoReleaseNullablePtr operator=(const AutoReleaseNullablePtr &other) MOZ_DELETE;
 
   public:
     explicit AutoReleaseNullablePtr(JSContext *cx, void *ptr
                                     JS_GUARD_OBJECT_NOTIFIER_PARAM)
       : cx(cx), ptr(ptr)
     {
         JS_GUARD_OBJECT_NOTIFIER_INIT;
     }
--- a/js/src/jsgc.cpp
+++ b/js/src/jsgc.cpp
@@ -33,31 +33,32 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * 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 ***** */
 
+/* JS Mark-and-Sweep Garbage Collector. */
+
+#include "mozilla/Attributes.h"
+#include "mozilla/Util.h"
+
 /*
- * JS Mark-and-Sweep Garbage Collector.
- *
  * This GC allocates fixed-sized things with sizes up to GC_NBYTES_MAX (see
  * jsgc.h). It allocates from a special GC arena pool with each arena allocated
  * using malloc. It uses an ideally parallel array of flag bytes to hold the
  * mark bit, finalizer type index, etc.
  *
  * XXX swizzle page to freelist for better locality of reference
  */
 #include <math.h>
 #include <string.h>     /* for memset used when DEBUG */
 
-#include "mozilla/Util.h"
-
 #include "jstypes.h"
 #include "jsstdint.h"
 #include "jsutil.h"
 #include "jshash.h"
 #include "jsclist.h"
 #include "jsprf.h"
 #include "jsapi.h"
 #include "jsatom.h"
@@ -2777,19 +2778,18 @@ LetOtherGCFinish(JSContext *cx)
 class AutoGCSession {
   public:
     explicit AutoGCSession(JSContext *cx);
     ~AutoGCSession();
 
   private:
     JSContext   *context;
 
-    /* Disable copy constructor or assignments */
-    AutoGCSession(const AutoGCSession&);
-    void operator=(const AutoGCSession&);
+    AutoGCSession(const AutoGCSession&) MOZ_DELETE;
+    void operator=(const AutoGCSession&) MOZ_DELETE;
 };
 
 /*
  * Start a new GC session. Together with LetOtherGCFinish this function
  * contains the rendezvous algorithm by which we stop the world for GC.
  *
  * This thread becomes the GC thread. Wait for all other threads to quiesce.
  * Then set rt->gcRunning and return.
--- a/js/src/jsonparser.h
+++ b/js/src/jsonparser.h
@@ -36,26 +36,30 @@
  * 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 jsonparser_h___
 #define jsonparser_h___
 
+#include "mozilla/Attributes.h"
 #include "mozilla/RangedPtr.h"
 
 #include "jscntxt.h"
 #include "jsstr.h"
 
 /*
  * NB: This class must only be used on the stack as it contains a js::Value.
  */
 class JSONParser
 {
+    JSONParser(const JSONParser &other) MOZ_DELETE;
+    void operator=(const JSONParser &other) MOZ_DELETE;
+
   public:
     enum ErrorHandling { RaiseError, NoError };
     enum ParsingMode { StrictJSON, LegacyJSON };
 
   private:
     /* Data members */
 
     JSContext * const cx;
--- a/js/src/jsstr.cpp
+++ b/js/src/jsstr.cpp
@@ -43,16 +43,19 @@
  *
  * In order to avoid unnecessary js_LockGCThing/js_UnlockGCThing calls, these
  * native methods store strings (possibly newborn) converted from their 'this'
  * parameter and arguments on the stack: 'this' conversions at argv[-1], arg
  * conversions at their index (argv[0], argv[1]).  This is a legitimate method
  * of rooting things that might lose their newborn root due to subsequent GC
  * allocations in the same native method.
  */
+
+#include "mozilla/Attributes.h"
+
 #include <stdlib.h>
 #include <string.h>
 #include "jstypes.h"
 #include "jsstdint.h"
 #include "jsutil.h"
 #include "jshash.h"
 #include "jsprf.h"
 #include "jsapi.h"
@@ -1353,18 +1356,18 @@ class RegExpPair
 /*
  * RegExpGuard factors logic out of String regexp operations.
  *
  * |optarg| indicates in which argument position RegExp flags will be found, if
  * present. This is a Mozilla extension and not part of any ECMA spec.
  */
 class RegExpGuard
 {
-    RegExpGuard(const RegExpGuard &);
-    void operator=(const RegExpGuard &);
+    RegExpGuard(const RegExpGuard &) MOZ_DELETE;
+    void operator=(const RegExpGuard &) MOZ_DELETE;
 
     JSContext   *cx;
     RegExpPair  rep;
     FlatMatch   fm;
 
     /*
      * Upper bound on the number of characters we are willing to potentially
      * waste on searching for RegExp meta-characters.
--- a/js/src/jsstrinlines.h
+++ b/js/src/jsstrinlines.h
@@ -35,16 +35,18 @@
  * 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 jsstrinlines_h___
 #define jsstrinlines_h___
 
+#include "mozilla/Attributes.h"
+
 #include "jsatom.h"
 #include "jsstr.h"
 
 #include "jscntxtinlines.h"
 #include "jsgcinlines.h"
 #include "vm/String-inl.h"
 
 namespace js {
@@ -71,16 +73,19 @@ class StringBuffer
 
     CharBuffer cb;
 
     static inline bool checkLength(JSContext *cx, size_t length);
     inline bool checkLength(size_t length);
     JSContext *context() const { return cb.allocPolicy().context(); }
     jschar *extractWellSized();
 
+    StringBuffer(const StringBuffer &other) MOZ_DELETE;
+    void operator=(const StringBuffer &other) MOZ_DELETE;
+
   public:
     explicit inline StringBuffer(JSContext *cx);
     bool reserve(size_t len);
     bool resize(size_t len);
     bool append(const jschar c);
     bool append(const jschar *chars, size_t len);
     bool append(const jschar *begin, const jschar *end);
     bool append(JSString *str);
@@ -238,16 +243,19 @@ ValueToStringBuffer(JSContext *cx, const
 
     return ValueToStringBufferSlow(cx, v, sb);
 }
 
 class RopeBuilder {
     JSContext *cx;
     JSString *res;
 
+    RopeBuilder(const RopeBuilder &other) MOZ_DELETE;
+    void operator=(const RopeBuilder &other) MOZ_DELETE;
+
   public:
     RopeBuilder(JSContext *cx)
       : cx(cx), res(cx->runtime->emptyString)
     {}
 
     inline bool append(JSString *str) {
         res = js_ConcatStrings(cx, res, str);
         return !!res;
--- a/js/src/jsutil.h
+++ b/js/src/jsutil.h
@@ -39,16 +39,18 @@
 
 /*
  * PR assertion checker.
  */
 
 #ifndef jsutil_h___
 #define jsutil_h___
 
+#include "mozilla/Attributes.h"
+
 #include "js/Utility.h"
 
 /* Forward declarations. */
 struct JSContext;
 
 #ifdef __cplusplus
 namespace js {
 
@@ -218,18 +220,18 @@ class NeedsIncRef
 template <class RefCountable>
 class AutoRefCount
 {
     typedef RefCountable *****ConvertibleToBool;
 
     JSContext *const cx;
     RefCountable *obj;
 
-    AutoRefCount(const AutoRefCount &);
-    void operator=(const AutoRefCount &);
+    AutoRefCount(const AutoRefCount &other) MOZ_DELETE;
+    void operator=(const AutoRefCount &other) MOZ_DELETE;
 
   public:
     explicit AutoRefCount(JSContext *cx)
       : cx(cx), obj(NULL)
     {}
 
     AutoRefCount(JSContext *cx, NeedsIncRef<RefCountable> aobj)
       : cx(cx), obj(aobj.get())
--- a/js/src/shell/jsworkers.cpp
+++ b/js/src/shell/jsworkers.cpp
@@ -94,26 +94,24 @@ extern size_t gMaxStackSize;
  * the parent-child relationship is a partial order.)
  */
 
 namespace js {
 namespace workers {
 
 template <class T, class AllocPolicy>
 class Queue {
-  private:
     typedef Vector<T, 4, AllocPolicy> Vec;
     Vec v1;
     Vec v2;
     Vec *front;
     Vec *back;
 
-    // Queue is not copyable.
-    Queue(const Queue &);
-    Queue & operator=(const Queue &);
+    Queue(const Queue &) MOZ_DELETE;
+    Queue & operator=(const Queue &) MOZ_DELETE;
 
   public:
     Queue() : front(&v1), back(&v2) {}
     bool push(T t) { return back->append(t); }
     bool empty() { return front->empty() && back->empty(); }
 
     T pop() {
         if (front->empty()) {
--- a/js/src/vm/BooleanObject.h
+++ b/js/src/vm/BooleanObject.h
@@ -36,16 +36,18 @@
  * 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 uintN PRIMITIVE_VALUE_SLOT = 0;
@@ -75,15 +77,15 @@ class BooleanObject : public ::JSObject
         setSlot(PRIMITIVE_VALUE_SLOT, BooleanValue(b));
     }
 
     /* For access to init, as Boolean.prototype is special. */
     friend JSObject *
     ::js_InitBooleanClass(JSContext *cx, JSObject *global);
 
   private:
-    BooleanObject();
-    BooleanObject &operator=(const BooleanObject &bo);
+    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
@@ -36,16 +36,18 @@
  * 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 GlobalObject_h___
 #define GlobalObject_h___
 
+#include "mozilla/Attributes.h"
+
 #include "jsarray.h"
 #include "jsbool.h"
 #include "jsfun.h"
 #include "jsiter.h"
 #include "jsnum.h"
 #include "jstypedarray.h"
 
 #include "js/Vector.h"
@@ -85,16 +87,19 @@ 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;
+
     /*
      * Count of slots to store built-in constructors, prototypes, and initial
      * visible properties for the constructors.
      */
     static const uintN STANDARD_CLASS_SLOTS  = JSProto_LIMIT * 3;
 
     /* One-off properties stored after slots for built-ins. */
     static const uintN THROWTYPEERROR          = STANDARD_CLASS_SLOTS;
--- a/js/src/vm/NumberObject.h
+++ b/js/src/vm/NumberObject.h
@@ -36,16 +36,18 @@
  * 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 uintN PRIMITIVE_VALUE_SLOT = 0;
@@ -75,15 +77,15 @@ class NumberObject : public ::JSObject
         setSlot(PRIMITIVE_VALUE_SLOT, NumberValue(d));
     }
 
     /* For access to init, as Number.prototype is special. */
     friend JSObject *
     ::js_InitNumberClass(JSContext *cx, JSObject *global);
 
   private:
-    NumberObject();
-    NumberObject &operator=(const NumberObject &so);
+    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
@@ -36,16 +36,18 @@
  * 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 RegExpObject_h__
 #define RegExpObject_h__
 
+#include "mozilla/Attributes.h"
+
 #include <stddef.h>
 #include "jsobj.h"
 
 #include "js/TemplateLib.h"
 
 #include "yarr/Yarr.h"
 #if ENABLE_YARR_JIT
 #include "yarr/YarrJIT.h"
@@ -195,18 +197,18 @@ class RegExpObject : public ::JSObject
 
     /*
      * Compute the initial shape to associate with fresh RegExp objects,
      * encoding their initial properties. Return the shape after
      * changing this regular expression object's last property to it.
      */
     Shape *assignInitialShape(JSContext *cx);
 
-    RegExpObject();
-    RegExpObject &operator=(const RegExpObject &reo);
+    RegExpObject() MOZ_DELETE;
+    RegExpObject &operator=(const RegExpObject &reo) MOZ_DELETE;
 }; /* class RegExpObject */
 
 /* Either builds a new RegExpObject or re-initializes an existing one. */
 class RegExpObjectBuilder
 {
     typedef detail::RegExpPrivate RegExpPrivate;
 
     JSContext       *cx;
--- a/js/src/vm/StringObject.h
+++ b/js/src/vm/StringObject.h
@@ -36,16 +36,18 @@
  * 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 uintN PRIMITIVE_THIS_SLOT = 0;
@@ -90,15 +92,15 @@ class StringObject : public ::JSObject
     /*
      * 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();
-    StringObject &operator=(const StringObject &so);
+    StringObject() MOZ_DELETE;
+    StringObject &operator=(const StringObject &so) MOZ_DELETE;
 };
 
 } // namespace js
 
 #endif /* StringObject_h__ */