Commit 3e34db61 authored by Wanming Lin's avatar Wanming Lin Committed by Commit Bot

[webnfc] Correct error type

Per spec:
  If languageLength cannot be stored in 6 bit (languageLength > 63),
  throw a SyntaxError.

But current implementation throws a TypeError, this CL fixs the error type.

Bug: 520391
Change-Id: I6ff64d87b387a07fff926ada80e5ee5d73b716b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1981199
Commit-Queue: Rijubrata Bhaumik <rijubrata.bhaumik@intel.com>
Reviewed-by: default avatarLeon Han <leon.han@intel.com>
Reviewed-by: default avatarRijubrata Bhaumik <rijubrata.bhaumik@intel.com>
Cr-Commit-Position: refs/heads/master@{#727414}
parent 99a3c8c0
...@@ -145,7 +145,8 @@ static NDEFRecord* CreateTextRecord(const ExecutionContext* execution_context, ...@@ -145,7 +145,8 @@ static NDEFRecord* CreateTextRecord(const ExecutionContext* execution_context,
// Bits 0 to 5 define the length of the language tag // Bits 0 to 5 define the length of the language tag
// https://w3c.github.io/web-nfc/#text-record // https://w3c.github.io/web-nfc/#text-record
if (language.length() > 63) { if (language.length() > 63) {
exception_state.ThrowTypeError("Lang length cannot be stored in 6 bit."); exception_state.ThrowDOMException(DOMExceptionCode::kSyntaxError,
"Lang length cannot be stored in 6 bit.");
return nullptr; return nullptr;
} }
......
...@@ -35,9 +35,6 @@ const invalid_type_messages = ...@@ -35,9 +35,6 @@ const invalid_type_messages =
// "utf-16", "utf-16le" or "utf-16be". // "utf-16", "utf-16le" or "utf-16be".
createMessage([createTextRecord(test_text_data, "chinese")]), createMessage([createTextRecord(test_text_data, "chinese")]),
// NDEFRecord.lang length for 'text' record must be lower than 64.
createMessage([createTextRecord(test_text_data, undefined /* encoding */, [...Array(64)].map(_ => 'a'))]),
// https://w3c.github.io/web-nfc/#dfn-map-a-url-to-ndef // https://w3c.github.io/web-nfc/#dfn-map-a-url-to-ndef
// NDEFRecord must have data. // NDEFRecord must have data.
createMessage([createUrlRecord()]), createMessage([createUrlRecord()]),
...@@ -91,6 +88,10 @@ const invalid_syntax_messages = ...@@ -91,6 +88,10 @@ const invalid_syntax_messages =
// Data for 'url' or 'absolute-url' record, must be a valid URL. // Data for 'url' or 'absolute-url' record, must be a valid URL.
createMessage([createUrlRecord('Invalid URL:// Data')]), createMessage([createUrlRecord('Invalid URL:// Data')]),
createMessage([createUrlRecord('Invalid URL:// Data', true)]), createMessage([createUrlRecord('Invalid URL:// Data', true)]),
// NDEFRecord.lang length for 'text' record must be lower than 64.
createMessage([createTextRecord(test_text_data, undefined /* encoding */,
[...Array(64)].map(_ => 'a'))]),
]; ];
const invalid_signals = [ const invalid_signals = [
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment