Bug 960510 - Part 1: Make type, id and payload optional. r=khuey
author"allstars.chh" <allstars.chh@gmail.com>
Thu, 20 Feb 2014 15:08:46 +0800
changeset 192509 fbc9b3cba3fe147cb2fdd8f15b3696849f3f3360
parent 192508 eb8d3bce5433df76507cd294e308fb3db5abf499
child 192510 82e2e931b427da102dab41122d2d684c165fae9f
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs960510
milestone31.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 960510 - Part 1: Make type, id and payload optional. r=khuey From 4ac0853ddabfadb99bfcd037d3831904d8353fbf Mon Sep 17 00:00:00 2001 --- dom/nfc/MozNDEFRecord.cpp | 26 +++++++++++++++++++------- dom/nfc/MozNDEFRecord.h | 36 +++++++++++++++++++++++++----------- dom/webidl/MozNDEFRecord.webidl | 8 ++++---- 3 files changed, 48 insertions(+), 22 deletions(-)
dom/nfc/MozNDEFRecord.cpp
dom/nfc/MozNDEFRecord.h
dom/webidl/MozNDEFRecord.webidl
--- a/dom/nfc/MozNDEFRecord.cpp
+++ b/dom/nfc/MozNDEFRecord.cpp
@@ -62,18 +62,20 @@ MozNDEFRecord::DropData()
     mPayload = nullptr;
   }
   mozilla::DropJSObjects(this);
 }
 
 /* static */
 already_AddRefed<MozNDEFRecord>
 MozNDEFRecord::Constructor(const GlobalObject& aGlobal,
-                           uint8_t aTnf, const Uint8Array& aType,
-                           const Uint8Array& aId, const Uint8Array& aPayload,
+                           uint8_t aTnf,
+                           const Optional<Uint8Array>& aType,
+                           const Optional<Uint8Array>& aId,
+                           const Optional<Uint8Array>& aPayload,
                            ErrorResult& aRv)
 {
   nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aGlobal.GetAsSupports());
   if (!win) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
@@ -83,25 +85,35 @@ MozNDEFRecord::Constructor(const GlobalO
   if (!ndefrecord) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
   return ndefrecord.forget();
 }
 
 MozNDEFRecord::MozNDEFRecord(JSContext* aCx, nsPIDOMWindow* aWindow,
-                             uint8_t aTnf, const Uint8Array& aType,
-                             const Uint8Array& aId, const Uint8Array& aPayload)
+                             uint8_t aTnf,
+                             const Optional<Uint8Array>& aType,
+                             const Optional<Uint8Array>& aId,
+                             const Optional<Uint8Array>& aPayload)
   : mTnf(aTnf)
 {
   mWindow = aWindow; // For GetParentObject()
 
-  mType = Uint8Array::Create(aCx, this, aType.Length(), aType.Data());
-  mId = Uint8Array::Create(aCx, this, aId.Length(), aId.Data());
-  mPayload = Uint8Array::Create(aCx, this, aPayload.Length(), aPayload.Data());
+  if (aType.WasPassed()) {
+    mType = Uint8Array::Create(aCx, this, aType.Value().Length(), aType.Value().Data());
+  }
+
+  if (aId.WasPassed()) {
+    mId = Uint8Array::Create(aCx, this, aId.Value().Length(), aId.Value().Data());
+  }
+
+  if (aPayload.WasPassed()) {
+    mPayload = Uint8Array::Create(aCx, this, aPayload.Value().Length(), aPayload.Value().Data());
+  }
 
   SetIsDOMBinding();
   HoldData();
 }
 
 MozNDEFRecord::~MozNDEFRecord()
 {
   DropData();
--- a/dom/nfc/MozNDEFRecord.h
+++ b/dom/nfc/MozNDEFRecord.h
@@ -31,62 +31,76 @@ class MozNDEFRecord MOZ_FINAL : public n
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MozNDEFRecord)
 
 public:
 
   MozNDEFRecord(JSContext* aCx, nsPIDOMWindow* aWindow, uint8_t aTnf,
-                const Uint8Array& aType, const Uint8Array& aId,
-                const Uint8Array& aPlayload);
+                const Optional<Uint8Array>& aType,
+                const Optional<Uint8Array>& aId,
+                const Optional<Uint8Array>& aPlayload);
 
   ~MozNDEFRecord();
 
   nsIDOMWindow* GetParentObject() const
   {
     return mWindow;
   }
 
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
   static already_AddRefed<MozNDEFRecord>
-                  Constructor(const GlobalObject& aGlobal, uint8_t aTnf,
-                              const Uint8Array& aType, const Uint8Array& aId,
-                              const Uint8Array& aPayload, ErrorResult& aRv);
+  Constructor(const GlobalObject& aGlobal, uint8_t aTnf,
+              const Optional<Uint8Array>& aType,
+              const Optional<Uint8Array>& aId,
+              const Optional<Uint8Array>& aPayload, ErrorResult& aRv);
 
   uint8_t Tnf() const
   {
     return mTnf;
   }
 
-  JSObject* Type(JSContext* cx) const
+  JSObject* GetType(JSContext* cx) const
   {
-    return GetTypeObject();
+    if (mType) {
+      return GetTypeObject();
+    } else {
+      return nullptr;
+    }
   }
   JSObject* GetTypeObject() const
   {
     JS::ExposeObjectToActiveJS(mType);
     return mType;
   }
 
-  JSObject* Id(JSContext* cx) const
+  JSObject* GetId(JSContext* cx) const
   {
-    return GetIdObject();
+    if (mId) {
+      return GetIdObject();
+    } else {
+      return nullptr;
+    }
   }
   JSObject* GetIdObject() const
   {
     JS::ExposeObjectToActiveJS(mId);
     return mId;
   }
 
-  JSObject* Payload(JSContext* cx) const
+  JSObject* GetPayload(JSContext* cx) const
   {
-    return GetPayloadObject();
+    if (mPayload) {
+      return GetPayloadObject();
+    } else {
+      return nullptr;
+    }
   }
   JSObject* GetPayloadObject() const
   {
     JS::ExposeObjectToActiveJS(mPayload);
     return mPayload;
   }
 
 private:
--- a/dom/webidl/MozNDEFRecord.webidl
+++ b/dom/webidl/MozNDEFRecord.webidl
@@ -1,16 +1,16 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Copyright © 2013 Deutsche Telekom, Inc. */
 
-[Constructor(octet tnf, Uint8Array type, Uint8Array id, Uint8Array payload)]
+[Constructor(octet tnf, optional Uint8Array type, optional Uint8Array id, optional Uint8Array payload)]
 interface MozNDEFRecord
 {
   /**
    * Type Name Field (3-bits) - Specifies the NDEF record type in general.
    *   tnf_empty: 0x00
    *   tnf_well_known: 0x01
    *   tnf_mime_media: 0x02
    *   tnf_absolute_uri: 0x03
@@ -21,23 +21,23 @@ interface MozNDEFRecord
    */
   [Constant]
   readonly attribute octet tnf;
 
   /**
    * type - Describes the content of the payload. This can be a mime type.
    */
   [Constant]
-  readonly attribute Uint8Array type;
+  readonly attribute Uint8Array? type;
 
   /**
    * id - Identifer is application dependent.
    */
   [Constant]
-  readonly attribute Uint8Array id;
+  readonly attribute Uint8Array? id;
 
   /**
    * payload - Binary data blob. The meaning of this field is application
    * dependent.
    */
   [Constant]
-  readonly attribute Uint8Array payload;
+  readonly attribute Uint8Array? payload;
 };