Bug 1087925 - calling some NFCTag API should throw if the condition is not met. r=smaug, dimi

This commit is contained in:
Yoshi Huang 2014-11-05 17:43:54 +08:00
parent a76656b90f
commit e515bfb51f

View File

@ -72,6 +72,19 @@ MozNFCTagImpl.prototype = {
throw new this._window.DOMError("InvalidStateError", "NFCTag object is invalid");
}
if (this.isReadOnly) {
throw new this._window.DOMError("InvalidAccessError", "NFCTag object is read-only");
}
let ndefLen = 0;
for (let record of records) {
ndefLen += record.size;
}
if (ndefLen > this.maxNDEFSize) {
throw new this._window.DOMError("NotSupportedError", "Exceed max NDEF size");
}
return this._nfcContentHelper.writeNDEF(records, this.session);
},
@ -79,6 +92,12 @@ MozNFCTagImpl.prototype = {
if (this.isLost) {
throw new this._window.DOMError("InvalidStateError", "NFCTag object is invalid");
}
if (!this.canBeMadeReadOnly) {
throw new this._window.DOMError("InvalidAccessError",
"NFCTag object cannot be made read-only");
}
return this._nfcContentHelper.makeReadOnly(this.session);
},