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(-)
This commit is contained in:
"allstars.chh" 2014-02-20 15:08:46 +08:00
Родитель dcf1d4b51f
Коммит 28cc482bb8
3 изменённых файлов: 48 добавлений и 22 удалений

Просмотреть файл

@ -67,8 +67,10 @@ MozNDEFRecord::DropData()
/* 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());
@ -88,15 +90,25 @@ MozNDEFRecord::Constructor(const GlobalObject& aGlobal,
}
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();

Просмотреть файл

@ -36,8 +36,9 @@ public:
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();
@ -50,18 +51,23 @@ public:
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
{
@ -69,9 +75,13 @@ public:
return mType;
}
JSObject* Id(JSContext* cx) const
JSObject* GetId(JSContext* cx) const
{
return GetIdObject();
if (mId) {
return GetIdObject();
} else {
return nullptr;
}
}
JSObject* GetIdObject() const
{
@ -79,9 +89,13 @@ public:
return mId;
}
JSObject* Payload(JSContext* cx) const
JSObject* GetPayload(JSContext* cx) const
{
return GetPayloadObject();
if (mPayload) {
return GetPayloadObject();
} else {
return nullptr;
}
}
JSObject* GetPayloadObject() const
{

Просмотреть файл

@ -5,7 +5,7 @@
/* 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
{
/**
@ -26,18 +26,18 @@ interface MozNDEFRecord
* 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;
};