Skip to content
Permalink
Browse files
Drop [UsePointersEvenForNonNullableObjectArguments] from File API int…
…erfaces

https://bugs.webkit.org/show_bug.cgi?id=156898

Reviewed by Chris Dumez.

Source/WebCore:

Making FileReaderSync API API throwing a TypeError in case of null parameters, in lieu of a NOT_FOUND_ERR.
Making FileReader API taking nullable parameters as a temporary fix.

Test: fast/files/workers/worker-file-reader-sync-bad-parameter.html

* Modules/websockets/WebSocketChannel.cpp:
(WebCore::WebSocketChannel::processOutgoingFrameQueue): Updated to cope with FileReaderLoader::start taking a Blob&.
* fileapi/FileReader.cpp:
(WebCore::FileReader::readAsArrayBuffer): Updated to cope with readInternal taking a Blob&.
(WebCore::FileReader::readAsBinaryString): Ditto.
(WebCore::FileReader::readAsText): Ditto.
(WebCore::FileReader::readAsDataURL): Ditto.
(WebCore::FileReader::readInternal):  Updated to cope with FileReaderLoader::start taking a Blob&.
* fileapi/FileReader.h:
* fileapi/FileReader.idl: Marking the readXX methods as taking a nullable blob parameter to keep compatibility, at least temporarily.
* fileapi/FileReaderLoader.cpp:
(WebCore::FileReaderLoader::start): It now takes a Blob& as input.
* fileapi/FileReaderLoader.h:
* fileapi/FileReaderSync.cpp:
(WebCore::FileReaderSync::readAsArrayBuffer): Taking a Blob& as input.
(WebCore::FileReaderSync::readAsBinaryString): Ditto.
(WebCore::FileReaderSync::readAsText): Ditto.
(WebCore::FileReaderSync::readAsDataURL): Ditto.
(WebCore::FileReaderSync::startLoading) Ditto.
* fileapi/FileReaderSync.h:
(WebCore::FileReaderSync::readAsText): Ditto.
* fileapi/FileReaderSync.idl:

LayoutTests:

Checking FileReaderSync send method in case of null or undefined blob parameter.
worker-read-blob-sync.html and worker-read-file-sync check the case of badly typed parameters.
In all cases, TypeError is thrown.

* fast/files/workers/resources/worker-file-reader-sync-bad-parameter.js: Added.
(test):
* fast/files/workers/worker-file-reader-sync-bad-parameter-expected.txt: Added.
* fast/files/workers/worker-file-reader-sync-bad-parameter.html: Added.
* fast/files/workers/worker-read-blob-sync-expected.txt: Rebasing expectation.
* fast/files/workers/worker-read-file-sync-expected.txt: Ditto.


Canonical link: https://commits.webkit.org/175083@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@199985 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
youennf committed Apr 25, 2016
1 parent 77ad0d4 commit 1d4f507ce441351b04d5277d642b29a1e2e3b57c
Show file tree
Hide file tree
Showing 16 changed files with 162 additions and 89 deletions.
@@ -1,3 +1,21 @@
2016-04-25 Youenn Fablet <youenn.fablet@crf.canon.fr>

Drop [UsePointersEvenForNonNullableObjectArguments] from File API interfaces
https://bugs.webkit.org/show_bug.cgi?id=156898

Reviewed by Chris Dumez.

Checking FileReaderSync send method in case of null or undefined blob parameter.
worker-read-blob-sync.html and worker-read-file-sync check the case of badly typed parameters.
In all cases, TypeError is thrown.

* fast/files/workers/resources/worker-file-reader-sync-bad-parameter.js: Added.
(test):
* fast/files/workers/worker-file-reader-sync-bad-parameter-expected.txt: Added.
* fast/files/workers/worker-file-reader-sync-bad-parameter.html: Added.
* fast/files/workers/worker-read-blob-sync-expected.txt: Rebasing expectation.
* fast/files/workers/worker-read-file-sync-expected.txt: Ditto.

2016-04-25 Manuel Rego Casasnovas <rego@igalia.com>

[css-grid] Fix grid-template-columns|rows computed style with content alignment
@@ -0,0 +1,19 @@
if (self.importScripts)
self.importScripts('../../../../resources/testharness.js');

test(function() {
assert_throws(new TypeError(), function() { new FileReaderSync().readAsBinaryString(null); });
assert_throws(new TypeError(), function() { new FileReaderSync().readAsArrayBuffer(null); });
assert_throws(new TypeError(), function() { new FileReaderSync().readAsText(null); });
assert_throws(new TypeError(), function() { new FileReaderSync().readAsDataURL(null); });
}, "Trying to read a null parameter");


test(function() {
assert_throws(new TypeError(), function() { new FileReaderSync().readAsBinaryString(undefined); });
assert_throws(new TypeError(), function() { new FileReaderSync().readAsArrayBuffer(undefined); });
assert_throws(new TypeError(), function() { new FileReaderSync().readAsText(undefined); });
assert_throws(new TypeError(), function() { new FileReaderSync().readAsDataURL(undefined); });
}, "Trying to read an undefined parameter");

done();
@@ -0,0 +1,4 @@

PASS Trying to read a null parameter
PASS Trying to read an undefined parameter

@@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Checking FileReaderSync API in case of null and undefined blob parameter</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#fetching">
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("resources/worker-file-reader-sync-bad-parameter.js"));
</script>
</body>
</html>

@@ -2,77 +2,77 @@
Received files in worker
Test reading a blob containing non-existent file
Received exception 1: NOT_FOUND_ERR
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a blob containing existent and non-existent file
Received exception 1: NOT_FOUND_ERR
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a blob containing empty file
result size: 0
result:
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a blob containing empty text
result size: 0
result:
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a blob containing empty files and empty texts
result size: 0
result:
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a blob containing single file
result size: 5
result: Hello
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a blob containing single text
result size: 5
result: First
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a blob containing single text as data URL
result size: 21
result: data:;base64,Rmlyc3Q=
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a blob containing single text as data URL (optional content type provided)
result size: 29
result: data:type/foo;base64,Rmlyc3Q=
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a blob containing single ArrayBuffer
result size: 9
result: 0x0 0x1 0x2 0x80 0x81 0x82 0xfd 0xfe 0xff
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a blob containing sliced file
result size: 5
result: onder
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a blob containing sliced text
result size: 4
result: irst
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a blob containing sliced ArrayBuffer
result size: 8
result: 0x1 0x2 0x80 0x81 0x82 0xfd 0xfe 0xff
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a blob containing multiple files
result size: 19
result: HelloWonderfulWorld
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a blob containing multiple texts
result size: 16
result: FirstSecondThird
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a blob containing multiple ArrayBuffer
result size: 9
result: 0x0 0x1 0x2 0x80 0x81 0x82 0xfd 0xfe 0xff
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a hybrid blob
result size: 38
result: FirstHelloSecondWonderfulWorldThird012
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a sliced hybrid blob
result size: 12
result: lloSecondWon
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a triple-sliced hybrid blob
result size: 30
result: ondWonderfulWorldThird012Foolo
Received exception 8: NotFoundError
Received exception undefined: TypeError
DONE

@@ -2,80 +2,80 @@
Received files in worker
Test reading a non-existent file as array buffer
Received exception 1: NOT_FOUND_ERR
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a non-existent file as binary string
Received exception 1: NOT_FOUND_ERR
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a non-existent file as text
Received exception 1: NOT_FOUND_ERR
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a non-existent file as data URL
Received exception 1: NOT_FOUND_ERR
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading an empty file as array buffer
result size: 0
result:
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading an empty file as binary string
result size: 0
result:
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading an empty file as text
result size: 0
result:
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading an empty file as data URL
result size: 5
result: data:
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a UTF-8 file as array buffer
result size: 5
result: Hello
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a UTF-8 file as binary string
result size: 5
result: Hello
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a binary file as array buffer
result size: 9
result: 0x0 0x1 0x2 0x80 0x81 0x82 0xfd 0xfe 0xff
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a binary file as binary string
result size: 9
result: 0x0 0x1 0x2 0x80 0x81 0x82 0xfd 0xfe 0xff
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a UTF-8 file as text
result size: 5
result: Hello
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a UTF-16BE BOM file as text
result size: 5
result: Hello
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a UTF-16LE BOM file as text
result size: 5
result: Hello
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a UTF-8 BOM file as text
result size: 5
result: Hello
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a UTF-16BE file as text with UTF-16BE encoding
result size: 5
result: Hello
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a UTF-16BE BOM file as text with UTF8 encoding
result size: 5
result: Hello
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a UTF-16BE BOM file as text with invalid encoding
result size: 5
result: Hello
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test reading a UTF-8 file as data URL
result size: 31
result: data:text/plain;base64,SGVsbG8=
Received exception 8: NotFoundError
Received exception undefined: TypeError
Test calling multiple read methods in a row
result size: 5
result: Hello
@@ -1,3 +1,38 @@
2016-04-25 Youenn Fablet <youenn.fablet@crf.canon.fr>

Drop [UsePointersEvenForNonNullableObjectArguments] from File API interfaces
https://bugs.webkit.org/show_bug.cgi?id=156898

Reviewed by Chris Dumez.

Making FileReaderSync API API throwing a TypeError in case of null parameters, in lieu of a NOT_FOUND_ERR.
Making FileReader API taking nullable parameters as a temporary fix.

Test: fast/files/workers/worker-file-reader-sync-bad-parameter.html

* Modules/websockets/WebSocketChannel.cpp:
(WebCore::WebSocketChannel::processOutgoingFrameQueue): Updated to cope with FileReaderLoader::start taking a Blob&.
* fileapi/FileReader.cpp:
(WebCore::FileReader::readAsArrayBuffer): Updated to cope with readInternal taking a Blob&.
(WebCore::FileReader::readAsBinaryString): Ditto.
(WebCore::FileReader::readAsText): Ditto.
(WebCore::FileReader::readAsDataURL): Ditto.
(WebCore::FileReader::readInternal): Updated to cope with FileReaderLoader::start taking a Blob&.
* fileapi/FileReader.h:
* fileapi/FileReader.idl: Marking the readXX methods as taking a nullable blob parameter to keep compatibility, at least temporarily.
* fileapi/FileReaderLoader.cpp:
(WebCore::FileReaderLoader::start): It now takes a Blob& as input.
* fileapi/FileReaderLoader.h:
* fileapi/FileReaderSync.cpp:
(WebCore::FileReaderSync::readAsArrayBuffer): Taking a Blob& as input.
(WebCore::FileReaderSync::readAsBinaryString): Ditto.
(WebCore::FileReaderSync::readAsText): Ditto.
(WebCore::FileReaderSync::readAsDataURL): Ditto.
(WebCore::FileReaderSync::startLoading) Ditto.
* fileapi/FileReaderSync.h:
(WebCore::FileReaderSync::readAsText): Ditto.
* fileapi/FileReaderSync.idl:

2016-04-25 Manuel Rego Casasnovas <rego@igalia.com>

[css-grid] Fix grid-template-columns|rows computed style with content alignment
@@ -750,9 +750,10 @@ void WebSocketChannel::processOutgoingFrameQueue()
case BlobLoaderNotStarted:
ref(); // Will be derefed after didFinishLoading() or didFail().
ASSERT(!m_blobLoader);
ASSERT(frame->blobData);
m_blobLoader = std::make_unique<FileReaderLoader>(FileReaderLoader::ReadAsArrayBuffer, this);
m_blobLoaderStatus = BlobLoaderStarted;
m_blobLoader->start(m_document, frame->blobData.get());
m_blobLoader->start(m_document, *frame->blobData);
m_outgoingFrameQueue.prepend(frame.release());
return;

@@ -88,7 +88,7 @@ void FileReader::readAsArrayBuffer(Blob* blob, ExceptionCode& ec)

LOG(FileAPI, "FileReader: reading as array buffer: %s %s\n", blob->url().string().utf8().data(), is<File>(*blob) ? downcast<File>(*blob).path().utf8().data() : "");

readInternal(blob, FileReaderLoader::ReadAsArrayBuffer, ec);
readInternal(*blob, FileReaderLoader::ReadAsArrayBuffer, ec);
}

void FileReader::readAsBinaryString(Blob* blob, ExceptionCode& ec)
@@ -98,7 +98,7 @@ void FileReader::readAsBinaryString(Blob* blob, ExceptionCode& ec)

LOG(FileAPI, "FileReader: reading as binary: %s %s\n", blob->url().string().utf8().data(), is<File>(*blob) ? downcast<File>(*blob).path().utf8().data() : "");

readInternal(blob, FileReaderLoader::ReadAsBinaryString, ec);
readInternal(*blob, FileReaderLoader::ReadAsBinaryString, ec);
}

void FileReader::readAsText(Blob* blob, const String& encoding, ExceptionCode& ec)
@@ -109,7 +109,7 @@ void FileReader::readAsText(Blob* blob, const String& encoding, ExceptionCode& e
LOG(FileAPI, "FileReader: reading as text: %s %s\n", blob->url().string().utf8().data(), is<File>(*blob) ? downcast<File>(*blob).path().utf8().data() : "");

m_encoding = encoding;
readInternal(blob, FileReaderLoader::ReadAsText, ec);
readInternal(*blob, FileReaderLoader::ReadAsText, ec);
}

void FileReader::readAsText(Blob* blob, ExceptionCode& ec)
@@ -124,10 +124,10 @@ void FileReader::readAsDataURL(Blob* blob, ExceptionCode& ec)

LOG(FileAPI, "FileReader: reading as data URL: %s %s\n", blob->url().string().utf8().data(), is<File>(*blob) ? downcast<File>(*blob).path().utf8().data() : "");

readInternal(blob, FileReaderLoader::ReadAsDataURL, ec);
readInternal(*blob, FileReaderLoader::ReadAsDataURL, ec);
}

void FileReader::readInternal(Blob* blob, FileReaderLoader::ReadType type, ExceptionCode& ec)
void FileReader::readInternal(Blob& blob, FileReaderLoader::ReadType type, ExceptionCode& ec)
{
// If multiple concurrent read methods are called on the same FileReader, INVALID_STATE_ERR should be thrown when the state is LOADING.
if (m_state == LOADING) {
@@ -137,15 +137,15 @@ void FileReader::readInternal(Blob* blob, FileReaderLoader::ReadType type, Excep

setPendingActivity(this);

m_blob = blob;
m_blob = &blob;
m_readType = type;
m_state = LOADING;
m_error = nullptr;

m_loader = std::make_unique<FileReaderLoader>(m_readType, this);
m_loader->setEncoding(m_encoding);
m_loader->setDataType(m_blob->type());
m_loader->start(scriptExecutionContext(), m_blob.get());
m_loader->start(scriptExecutionContext(), blob);
}

void FileReader::abort()
@@ -105,7 +105,7 @@ class FileReader final : public RefCounted<FileReader>, public ActiveDOMObject,
void derefEventTarget() override { deref(); }

void terminate();
void readInternal(Blob*, FileReaderLoader::ReadType, ExceptionCode&);
void readInternal(Blob&, FileReaderLoader::ReadType, ExceptionCode&);
void fireErrorEvent(int httpStatusCode);
void fireEvent(const AtomicString& type);

0 comments on commit 1d4f507

Please sign in to comment.