From 4d7258a8dc8b32c6a9055e4bf3ba7e49d5ed42ab Mon Sep 17 00:00:00 2001 From: Pawel Kaczmarek Date: Tue, 3 Mar 2015 11:22:44 +0100 Subject: [PATCH] [Filesystem] FileStream.close [Verification] Following TCT should pass: FileStream_close Change-Id: I612de747f0c248043542d61b210109cd5a8c26a8 Signed-off-by: Pawel Kaczmarek --- src/filesystem/js/file_stream.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/filesystem/js/file_stream.js b/src/filesystem/js/file_stream.js index 445663ae..b40eee81 100644 --- a/src/filesystem/js/file_stream.js +++ b/src/filesystem/js/file_stream.js @@ -41,12 +41,23 @@ function FileStream(data, mode, encoding) { value: data, writable: false, enumerable: false + }, + _closed: { + value: false, + writable: true, + enumerable: false } }); } +function _checkClosed(stream) { + if (stream._closed) { + throw new tizen.WebAPIException(tizen.WebAPIException.IO_ERR, 'Stream is closed.'); + } +} + FileStream.prototype.close = function() { -// TODO: close + this._closed = true; }; function _checkReadAccess(mode) { @@ -69,6 +80,8 @@ FileStream.prototype.read = function() { } ]); + _checkClosed(this); + if (args.charCount <= 0) { throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR, 'Argument "charCount" must be greater than 0'); @@ -102,6 +115,8 @@ FileStream.prototype.readBytes = function() { } ]); + _checkClosed(this); + if (args.byteCount <= 0) { throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR, 'Argument "byteCount" must be greater than 0'); @@ -140,6 +155,8 @@ FileStream.prototype.readBase64 = function() { } ]); + _checkClosed(this); + if (args.byteCount <= 0) { throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR, 'Argument "byteCount" must be greater than 0'); @@ -172,6 +189,7 @@ FileStream.prototype.write = function() { } ]); + _checkClosed(this); _checkWriteAccess(this._mode); var data = { @@ -197,6 +215,7 @@ FileStream.prototype.writeBytes = function() { } ]); + _checkClosed(this); _checkWriteAccess(this._mode); var data = { @@ -220,6 +239,7 @@ FileStream.prototype.writeBase64 = function() { } ]); + _checkClosed(this); _checkWriteAccess(this._mode); var data = { -- 2.34.1