Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(834)

Unified Diff: third_party/WebKit/Source/modules/nfc/NFC.cpp

Issue 2836063004: [webnfc] Nfc.push method must reject promise with TypeError (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/nfc/push.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/nfc/NFC.cpp
diff --git a/third_party/WebKit/Source/modules/nfc/NFC.cpp b/third_party/WebKit/Source/modules/nfc/NFC.cpp
index 4a3d6ece9cdd2b6a0ae11be11120a9e197a1d927..2188f2894d6ba9fcee5d0c6f2f9d91f2f46c5cb3 100644
--- a/third_party/WebKit/Source/modules/nfc/NFC.cpp
+++ b/third_party/WebKit/Source/modules/nfc/NFC.cpp
@@ -431,33 +431,34 @@ bool IsValidNFCRecord(const NFCRecord& record) {
return false;
}
-DOMException* IsValidNFCRecordArray(const HeapVector<NFCRecord>& records) {
- // https://w3c.github.io/web-nfc/#the-push-method
- // If NFCMessage.data is empty, reject promise with SyntaxError
+bool IsValidNFCRecordArray(const HeapVector<NFCRecord>& records) {
if (records.IsEmpty())
- return DOMException::Create(kSyntaxError);
+ return false;
for (const auto& record : records) {
if (!IsValidNFCRecord(record))
- return DOMException::Create(kSyntaxError);
+ return false;
}
- return nullptr;
+ return true;
}
-DOMException* IsValidNFCPushMessage(const NFCPushMessage& message) {
+bool IsValidNFCPushMessage(const NFCPushMessage& message) {
+ // If NFCPushMessage of invalid type, reject promise with TypeError
if (!message.isNFCMessage() && !message.isString() &&
!message.isArrayBuffer())
- return DOMException::Create(kTypeMismatchError);
+ return false;
if (message.isNFCMessage()) {
+ // https://w3c.github.io/web-nfc/#the-push-method
+ // If NFCMessage.data is empty, reject promise with TypeError
if (!message.getAsNFCMessage().hasData())
- return DOMException::Create(kTypeMismatchError);
+ return false;
return IsValidNFCRecordArray(message.getAsNFCMessage().data());
}
- return nullptr;
+ return true;
}
bool SetURL(const String& origin,
@@ -614,9 +615,12 @@ ScriptPromise NFC::push(ScriptState* script_state,
if (!promise.IsEmpty())
return promise;
- DOMException* exception = IsValidNFCPushMessage(push_message);
- if (exception)
- return ScriptPromise::RejectWithDOMException(script_state, exception);
+ if (!IsValidNFCPushMessage(push_message)) {
+ return ScriptPromise::Reject(
+ script_state, V8ThrowException::CreateTypeError(
+ script_state->GetIsolate(),
+ "Invalid NFCPushMessage type was provided."));
+ }
device::nfc::mojom::blink::NFCMessagePtr message =
device::nfc::mojom::blink::NFCMessage::From(push_message);
« no previous file with comments | « third_party/WebKit/LayoutTests/nfc/push.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698