Bug 796983 part 1. Switch nullable primitives to using a const Nullable. r=jst
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 17 Oct 2012 17:01:55 -0400
changeset 110722 d8798b6331be496aadbc691fee4cd4f4280f54cf
parent 110721 d3a655f609caee9fa831060d310d1ac354450e88
child 110723 50d6355b80c44f79bd42b12af7e00b8614d0cb59
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersjst
bugs796983
milestone19.0a1
Bug 796983 part 1. Switch nullable primitives to using a const Nullable. r=jst
content/events/src/nsDOMEventTargetHelper.h
dom/bindings/Codegen.py
dom/bindings/test/TestBindingHeader.h
--- a/content/events/src/nsDOMEventTargetHelper.h
+++ b/content/events/src/nsDOMEventTargetHelper.h
@@ -28,17 +28,17 @@ public:
   nsDOMEventTargetHelper() : mOwner(nullptr), mHasOrHasHadOwner(false) {}
   virtual ~nsDOMEventTargetHelper();
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(nsDOMEventTargetHelper)
 
   NS_DECL_NSIDOMEVENTTARGET
   void AddEventListener(const nsAString& aType,
                         nsIDOMEventListener* aCallback, // XXX nullable
-                        bool aCapture, Nullable<bool>& aWantsUntrusted,
+                        bool aCapture, const Nullable<bool>& aWantsUntrusted,
                         mozilla::ErrorResult& aRv)
   {
     aRv = AddEventListener(aType, aCallback, aCapture,
                            !aWantsUntrusted.IsNull() && aWantsUntrusted.Value(),
                            aWantsUntrusted.IsNull() ? 1 : 2);
   }
   void RemoveEventListener(const nsAString& aType,
                            nsIDOMEventListener* aCallback,
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -2534,27 +2534,30 @@ for (uint32_t i = 0; i < length; ++i) {
 
     conversionBehavior = "eDefault"
     if isEnforceRange:
         conversionBehavior = "eEnforceRange"
     elif isClamp:
         conversionBehavior = "eClamp"
 
     if type.nullable():
-        dataLoc = "${declName}.SetValue()"
+        declType = CGGeneric("Nullable<" + typeName + ">")
+        mutableType = declType.define() + "&"
+        if not isOptional and not isMember:
+            declType = CGWrapper(declType, pre="const ")
+        dataLoc = ("const_cast< %s >(${declName}).SetValue()" % mutableType)
         nullCondition = "${val}.isNullOrUndefined()"
         if defaultValue is not None and isinstance(defaultValue, IDLNullValue):
             nullCondition = "!(${haveValue}) || " + nullCondition
         template = (
             "if (%s) {\n"
-            "  ${declName}.SetNull();\n"
+            "  const_cast< %s >(${declName}).SetNull();\n"
             "} else if (!ValueToPrimitive<%s, %s>(cx, ${val}, &%s)) {\n"
             "  return false;\n"
-            "}" % (nullCondition, typeName, conversionBehavior, dataLoc))
-        declType = CGGeneric("Nullable<" + typeName + ">")
+            "}" % (nullCondition, mutableType, typeName, conversionBehavior, dataLoc))
     else:
         assert(defaultValue is None or
                not isinstance(defaultValue, IDLNullValue))
         dataLoc = "${declName}"
         template = (
             "if (!ValueToPrimitive<%s, %s>(cx, ${val}, &%s)) {\n"
             "  return false;\n"
             "}" % (typeName, conversionBehavior, dataLoc))
--- a/dom/bindings/test/TestBindingHeader.h
+++ b/dom/bindings/test/TestBindingHeader.h
@@ -107,17 +107,18 @@ public:
   // Constructors
   static
   already_AddRefed<TestInterface> Constructor(nsISupports*, ErrorResult&);
   static
   already_AddRefed<TestInterface> Constructor(nsISupports*, const nsAString&,
                                               ErrorResult&);
   static
   already_AddRefed<TestInterface> Constructor(nsISupports*, uint32_t,
-                                              Nullable<bool>&, ErrorResult&);
+                                              const Nullable<bool>&,
+                                              ErrorResult&);
   static
   already_AddRefed<TestInterface> Constructor(nsISupports*, TestInterface*,
                                               ErrorResult&);
   static
   already_AddRefed<TestInterface> Constructor(nsISupports*,
                                               TestNonCastableInterface&,
                                               ErrorResult&);
   /*  static
@@ -130,17 +131,17 @@ public:
   // Integer types
   int8_t ReadonlyByte();
   int8_t WritableByte();
   void SetWritableByte(int8_t);
   void PassByte(int8_t);
   int8_t ReceiveByte();
   void PassOptionalByte(const Optional<int8_t>&);
   void PassOptionalByteWithDefault(int8_t);
-  void PassNullableByte(Nullable<int8_t>&);
+  void PassNullableByte(const Nullable<int8_t>&);
   void PassOptionalNullableByte(const Optional< Nullable<int8_t> >&);
 
   int16_t ReadonlyShort();
   int16_t WritableShort();
   void SetWritableShort(int16_t);
   void PassShort(int16_t);
   int16_t ReceiveShort();
   void PassOptionalShort(const Optional<int16_t>&);
@@ -321,17 +322,17 @@ public:
   // String types
   void PassString(const nsAString&);
   void PassNullableString(const nsAString&);
   void PassOptionalString(const Optional<nsAString>&);
   void PassOptionalStringWithDefaultValue(const nsAString&);
   void PassOptionalNullableString(const Optional<nsAString>&);
   void PassOptionalNullableStringWithDefaultValue(const nsAString&);
 
-  // Enumarated types
+  // Enumerated types
   void PassEnum(TestEnum);
   void PassOptionalEnum(const Optional<TestEnum>&);
   void PassEnumWithDefault(TestEnum);
   TestEnum ReceiveEnum();
   TestEnum EnumAttribute();
   TestEnum ReadonlyEnumAttribute();
   void SetEnumAttribute(TestEnum);
 
@@ -435,16 +436,17 @@ private:
   // We add signatures here that _could_ start matching if the codegen
   // got data types wrong.  That way if it ever does we'll have a call
   // to these private deleted methods and compilation will fail.
   void SetReadonlyByte(int8_t) MOZ_DELETE;
   template<typename T>
   void SetWritableByte(T) MOZ_DELETE;
   template<typename T>
   void PassByte(T) MOZ_DELETE;
+  void PassNullableByte(Nullable<int8_t>&) MOZ_DELETE;
   template<typename T>
   void PassOptionalByte(const Optional<T>&) MOZ_DELETE;
   template<typename T>
   void PassOptionalByteWithDefault(T) MOZ_DELETE;
 
   void SetReadonlyShort(int16_t) MOZ_DELETE;
   template<typename T>
   void SetWritableShort(T) MOZ_DELETE;