mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1094669 - Add a size attribute for MozNDEFRecord. r=smaug, dimi
From 2f518e162998b4ac911b3e10f8a7f8177fe03f59 Mon Sep 17 00:00:00 2001 --- dom/nfc/MozNDEFRecord.cpp | 7 +++++++ dom/nfc/MozNDEFRecord.h | 6 ++++++ dom/webidl/MozNDEFRecord.webidl | 6 ++++++ 3 files changed, 19 insertions(+)
This commit is contained in:
parent
a00417e9d1
commit
df0810a717
@ -131,23 +131,30 @@ MozNDEFRecord::MozNDEFRecord(JSContext* aCx, nsPIDOMWindow* aWindow,
|
|||||||
mWindow = aWindow; // For GetParentObject()
|
mWindow = aWindow; // For GetParentObject()
|
||||||
|
|
||||||
mTnf = aOptions.mTnf;
|
mTnf = aOptions.mTnf;
|
||||||
|
mSize = 3; // 1(flags) + 1(type_length) + 1(payload_length)
|
||||||
|
|
||||||
if (aOptions.mType.WasPassed()) {
|
if (aOptions.mType.WasPassed()) {
|
||||||
const Uint8Array& type = aOptions.mType.Value();
|
const Uint8Array& type = aOptions.mType.Value();
|
||||||
type.ComputeLengthAndData();
|
type.ComputeLengthAndData();
|
||||||
mType = Uint8Array::Create(aCx, this, type.Length(), type.Data());
|
mType = Uint8Array::Create(aCx, this, type.Length(), type.Data());
|
||||||
|
mSize += type.Length();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aOptions.mId.WasPassed()) {
|
if (aOptions.mId.WasPassed()) {
|
||||||
const Uint8Array& id = aOptions.mId.Value();
|
const Uint8Array& id = aOptions.mId.Value();
|
||||||
id.ComputeLengthAndData();
|
id.ComputeLengthAndData();
|
||||||
mId = Uint8Array::Create(aCx, this, id.Length(), id.Data());
|
mId = Uint8Array::Create(aCx, this, id.Length(), id.Data());
|
||||||
|
mSize += 1 /* id_length */ + id.Length();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aOptions.mPayload.WasPassed()) {
|
if (aOptions.mPayload.WasPassed()) {
|
||||||
const Uint8Array& payload = aOptions.mPayload.Value();
|
const Uint8Array& payload = aOptions.mPayload.Value();
|
||||||
payload.ComputeLengthAndData();
|
payload.ComputeLengthAndData();
|
||||||
mPayload = Uint8Array::Create(aCx, this, payload.Length(), payload.Data());
|
mPayload = Uint8Array::Create(aCx, this, payload.Length(), payload.Data());
|
||||||
|
if (payload.Length() > 0xff) {
|
||||||
|
mSize += 3;
|
||||||
|
}
|
||||||
|
mSize += payload.Length();
|
||||||
}
|
}
|
||||||
|
|
||||||
HoldData();
|
HoldData();
|
||||||
|
@ -83,6 +83,11 @@ public:
|
|||||||
retval.set(mPayload);
|
retval.set(mPayload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t Size() const
|
||||||
|
{
|
||||||
|
return mSize;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MozNDEFRecord() MOZ_DELETE;
|
MozNDEFRecord() MOZ_DELETE;
|
||||||
nsRefPtr<nsPIDOMWindow> mWindow;
|
nsRefPtr<nsPIDOMWindow> mWindow;
|
||||||
@ -96,6 +101,7 @@ private:
|
|||||||
JS::Heap<JSObject*> mType;
|
JS::Heap<JSObject*> mType;
|
||||||
JS::Heap<JSObject*> mId;
|
JS::Heap<JSObject*> mId;
|
||||||
JS::Heap<JSObject*> mPayload;
|
JS::Heap<JSObject*> mPayload;
|
||||||
|
uint32_t mSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
|
@ -42,6 +42,12 @@ interface MozNDEFRecord
|
|||||||
*/
|
*/
|
||||||
[Constant]
|
[Constant]
|
||||||
readonly attribute Uint8Array? payload;
|
readonly attribute Uint8Array? payload;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the size of this NDEF Record.
|
||||||
|
*/
|
||||||
|
[Constant]
|
||||||
|
readonly attribute unsigned long size;
|
||||||
};
|
};
|
||||||
|
|
||||||
dictionary MozNDEFRecordOptions {
|
dictionary MozNDEFRecordOptions {
|
||||||
|
Loading…
Reference in New Issue
Block a user