Skip to content

Commit 92f88af

Browse files
Leon Hanchromium-wpt-export-bot
authored andcommitted
[webnfc] Make the retval of NDEFRecord#{toText,toArrayBuffer,toJSON}() nullable
Previously, for invalid cases, toText() returns an empty string, toJSON() returns undefined, which does not match the spec. The spec was changed at: w3c/web-nfc#298 BUG=520391 Change-Id: Ia63e675c5b0032cee13802d1e5d706c35089a056 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1761586 Reviewed-by: Rijubrata Bhaumik <[email protected]> Reviewed-by: Reilly Grant <[email protected]> Commit-Queue: Leon Han <[email protected]> Cr-Commit-Position: refs/heads/master@{#688840}
1 parent 8405bbd commit 92f88af

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

web-nfc/NDEFMessage_constructor.https.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
'toText() contains the same text content');
2929
assert_equals(message.records[0].toArrayBuffer(), null,
3030
'toArrayBuffer() returns null');
31-
assert_equals(message.records[0].toJSON(), undefined,
32-
'toJSON() returns undefined');
31+
assert_equals(message.records[0].toJSON(), null,
32+
'toJSON() returns null');
3333
}, 'NDEFMessage constructor with a text record');
3434

3535
</script>

web-nfc/NDEFRecord_constructor.https.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
const record = new NDEFRecord(null);
1616
assert_equals(record.recordType.length, 0, 'empty recordType');
1717
assert_equals(record.mediaType.length, 0, 'empty mediaType');
18-
assert_equals(record.toText().length, 0, 'toText() gets an empty string');
18+
assert_equals(record.toText(), null, 'toText() returns null');
1919
assert_equals(record.toArrayBuffer(), null, 'toArrayBuffer() returns null');
20-
assert_equals(record.toJSON(), undefined, 'toJSON() returns undefined');
20+
assert_equals(record.toJSON(), null, 'toJSON() returns null');
2121
}, 'NDEFRecord constructor with null init dict');
2222

2323
test(() => {

web-nfc/resources/nfc-helpers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ function assertWebNDEFMessagesEqual(message, expectedMessage) {
165165
expectedJson = expectedRecord.toJSON();
166166
} catch (e) {
167167
}
168-
if (json === undefined)
169-
assert_equals(expectedJson, undefined);
168+
if (json === undefined || json === null)
169+
assert_equals(json, expectedJson);
170170
else
171171
assert_object_equals(json, expectedJson);
172172
}

0 commit comments

Comments
 (0)