Changeset 200032 in webkit


Ignore:
Timestamp:
Apr 25, 2016 10:31:29 AM (8 years ago)
Author:
beidson@apple.com
Message:

Implement latest File object spec (including its constructor).
https://bugs.webkit.org/show_bug.cgi?id=156511

Reviewed by Darin Adler.

Source/WebCore:

Test: fast/files/file-constructor.html

  • CMakeLists.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/JSDictionary.cpp:

(WebCore::JSDictionary::convertValue):

  • bindings/js/JSDictionary.h:
  • bindings/js/JSFileCustom.cpp: Added.

(WebCore::constructJSFile):

  • fileapi/File.cpp:

(WebCore::File::File):
(WebCore::File::lastModified):
(WebCore::File::lastModifiedDate): Deleted.

  • fileapi/File.h:
  • fileapi/File.idl:

LayoutTests:

  • fast/files/file-constructor-expected.txt: Added.
  • fast/files/file-constructor.html: Added.
  • http/tests/local/fileapi/file-last-modified-after-delete-expected.txt:
  • http/tests/local/fileapi/script-tests/file-last-modified-after-delete.js:
  • http/tests/local/fileapi/file-last-modified-expected.txt:
  • http/tests/local/fileapi/script-tests/file-last-modified.js:
  • imported/blink/storage/indexeddb/blob-basics-metadata-expected.txt:
Location:
trunk
Files:
3 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r200030 r200032  
     12016-04-25  Brady Eidson  <beidson@apple.com>
     2
     3        Implement latest File object spec (including its constructor).
     4        https://bugs.webkit.org/show_bug.cgi?id=156511
     5
     6        Reviewed by Darin Adler.
     7
     8        * fast/files/file-constructor-expected.txt: Added.
     9        * fast/files/file-constructor.html: Added.
     10       
     11        * http/tests/local/fileapi/file-last-modified-after-delete-expected.txt:
     12        * http/tests/local/fileapi/script-tests/file-last-modified-after-delete.js:
     13
     14        * http/tests/local/fileapi/file-last-modified-expected.txt:
     15        * http/tests/local/fileapi/script-tests/file-last-modified.js:
     16
     17        * imported/blink/storage/indexeddb/blob-basics-metadata-expected.txt:
     18
    1192016-04-25  Daniel Bates  <dabates@apple.com>
    220
  • trunk/LayoutTests/http/tests/local/fileapi/file-last-modified-after-delete-expected.txt

    r145035 r200032  
    55
    66PASS event.dataTransfer contains a File object on drop.
    7 PASS lastModifiedDate is not null
    8 PASS lastModifiedDate is >= testStartTime
    9 PASS (new Date()).getTime() is >= lastModifiedDate
     7PASS lastModified is not null
     8PASS lastModified is >= testStartTime.getTime()
     9PASS (new Date()).getTime() is >= lastModified
    1010PASS successfullyParsed is true
    1111
  • trunk/LayoutTests/http/tests/local/fileapi/file-last-modified-expected.txt

    r74380 r200032  
    55
    66PASS event.dataTransfer contains a File object on drop.
    7 PASS file.lastModifiedDate verified
     7PASS file.lastModified verified
    88PASS successfullyParsed is true
    99
  • trunk/LayoutTests/http/tests/local/fileapi/script-tests/file-last-modified-after-delete.js

    r145035 r200032  
    1111    removeTempFile(tempFileName);
    1212
    13     // This synchronosly queries the file's lastModifiedDate (which should fail) until/unless we start capturing the file metadata at File construction time.
    14     lastModifiedDate = file.lastModifiedDate;
     13    // This synchronosly queries the file's lastModified (which should fail) until/unless we start capturing the file metadata at File construction time.
     14    lastModified = file.lastModified;
    1515
    1616    // The returned value should be equal to the current date/time since the file's modified date/time is not available.
    17     shouldNotBe('lastModifiedDate', 'null');
    18     shouldBeGreaterThanOrEqual('lastModifiedDate', 'testStartTime');
    19     shouldBeGreaterThanOrEqual('(new Date()).getTime()', 'lastModifiedDate');
     17    shouldNotBe('lastModified', 'null');
     18    shouldBeGreaterThanOrEqual('lastModified', 'testStartTime.getTime()');
     19    shouldBeGreaterThanOrEqual('(new Date()).getTime()', 'lastModified');
    2020}
    2121
  • trunk/LayoutTests/http/tests/local/fileapi/script-tests/file-last-modified.js

    r74380 r200032  
    77    xhr.send();
    88    var expectedDate = new Date(parseInt(xhr.responseText) * 1000);
    9     var actualDate = file.lastModifiedDate;
    10     if (expectedDate.toString() == actualDate.toString())
    11         testPassed("file.lastModifiedDate verified");
     9    var actualDate = file.lastModified;
     10    if (expectedDate.getTime() == actualDate)
     11        testPassed("file.lastModified verified");
    1212    else
    13         testFailed("file.lastModifiedDate incorrect");
     13        testFailed("file.lastModified incorrect");
    1414}
    1515
  • trunk/LayoutTests/imported/blink/storage/indexeddb/blob-basics-metadata-expected.txt

    r199730 r200032  
    4040testNewFile():
    4141newFile = new File([test_content], 'filename', {type:'text/plain'})
    42 FAIL newFile = new File([test_content], 'filename', {type:'text/plain'}) threw exception TypeError: function is not a constructor (evaluating 'new File([test_content], 'filename', {type:'text/plain'})')
    4342
    4443validateResult(newFile):
    45 FAIL newFile.name == newFile.name should be true. Threw exception ReferenceError: Can't find variable: newFile
     44PASS newFile.name == newFile.name is true
    4645transaction = db.transaction('storeName', 'readwrite')
    4746store = transaction.objectStore('storeName')
    4847store.put(newFile, 'newFilekey')
    49 FAIL store.put(newFile, 'newFilekey') threw exception ReferenceError: Can't find variable: newFile
    5048transaction = db.transaction('storeName', 'readwrite')
    5149store = transaction.objectStore('storeName')
    5250request = store.get('newFilekey')
    53 FAIL event.target.result.name == newFile.name should be true. Threw exception TypeError: undefined is not an object (evaluating 'event.target.result.name')
     51PASS event.target.result.name == newFile.name is true
    5452
    5553testFileList():
     
    7876PASS cursor.value == 'value' is true
    7977cursor.continue();
    80 FAIL cursor.value.name == newFile.name should be true. Threw exception TypeError: null is not an object (evaluating 'cursor.value')
     78PASS cursor.value.name == newFile.name is true
    8179cursor.continue();
    82 FAIL Unexpected error: TypeError: null is not an object (evaluating 'cursor.continue')
    83 FAIL successfullyParsed should be true. Was false.
     80PASS cursor is null
     81PASS successfullyParsed is true
    8482
    8583TEST COMPLETE
  • trunk/Source/WebCore/CMakeLists.txt

    r199976 r200032  
    11441144    bindings/js/JSExceptionBase.cpp
    11451145    bindings/js/JSFetchResponseCustom.cpp
     1146    bindings/js/JSFileCustom.cpp
    11461147    bindings/js/JSFileReaderCustom.cpp
    11471148    bindings/js/JSGeolocationCustom.cpp
  • trunk/Source/WebCore/ChangeLog

    r200031 r200032  
     12016-04-25  Brady Eidson  <beidson@apple.com>
     2
     3        Implement latest File object spec (including its constructor).
     4        https://bugs.webkit.org/show_bug.cgi?id=156511
     5
     6        Reviewed by Darin Adler.
     7
     8        Test: fast/files/file-constructor.html
     9
     10        * CMakeLists.txt:
     11        * WebCore.xcodeproj/project.pbxproj:
     12
     13        * bindings/js/JSDictionary.cpp:
     14        (WebCore::JSDictionary::convertValue):
     15        * bindings/js/JSDictionary.h:
     16
     17        * bindings/js/JSFileCustom.cpp: Added.
     18        (WebCore::constructJSFile):
     19
     20        * fileapi/File.cpp:
     21        (WebCore::File::File):
     22        (WebCore::File::lastModified):
     23        (WebCore::File::lastModifiedDate): Deleted.
     24        * fileapi/File.h:
     25        * fileapi/File.idl:
     26
    1272016-04-25  Antti Koivisto  <antti@apple.com>
    228
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r199976 r200032  
    20592059                516D7D711BB5F0BD00AF7C77 /* IDBConnectionToClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 516D7D6D1BB5F06500AF7C77 /* IDBConnectionToClient.cpp */; };
    20602060                516D7D721BB5F0BD00AF7C77 /* IDBConnectionToClientDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 516D7D6E1BB5F06500AF7C77 /* IDBConnectionToClientDelegate.h */; settings = {ATTRIBUTES = (Private, ); }; };
     2061                516E54FA1CCB2EA80040D954 /* JSFileCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 516E54F91CCB27FF0040D954 /* JSFileCustom.cpp */; };
    20612062                516F7F6D1C31E39A00F111DC /* ServerOpenDBRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 516F7F6C1C31C79D00F111DC /* ServerOpenDBRequest.h */; settings = {ATTRIBUTES = (Private, ); }; };
    20622063                516F7F6E1C31E39C00F111DC /* ServerOpenDBRequest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 516F7F6B1C31C79D00F111DC /* ServerOpenDBRequest.cpp */; };
     
    96459646                516D7D6D1BB5F06500AF7C77 /* IDBConnectionToClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IDBConnectionToClient.cpp; sourceTree = "<group>"; };
    96469647                516D7D6E1BB5F06500AF7C77 /* IDBConnectionToClientDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBConnectionToClientDelegate.h; sourceTree = "<group>"; };
     9648                516E54F91CCB27FF0040D954 /* JSFileCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSFileCustom.cpp; sourceTree = "<group>"; };
    96479649                516F7F6B1C31C79D00F111DC /* ServerOpenDBRequest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServerOpenDBRequest.cpp; sourceTree = "<group>"; };
    96489650                516F7F6C1C31C79D00F111DC /* ServerOpenDBRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServerOpenDBRequest.h; sourceTree = "<group>"; };
     
    2244822450                                ADEC78F718EE5308001315C2 /* JSElementCustom.h */,
    2244922451                                BCEFAF4D0C317E6900FA81F6 /* JSEventCustom.cpp */,
     22452                                516E54F91CCB27FF0040D954 /* JSFileCustom.cpp */,
    2245022453                                2E7582ED12764F260062628B /* JSFileReaderCustom.cpp */,
    2245122454                                C28083411C6DC96A001451B6 /* JSFontFaceCustom.cpp */,
     
    3024430247                                E1C36CBD0EB08062007410BC /* JSDOMGlobalObject.cpp in Sources */,
    3024530248                                7C2BDD3D17C7F98C0038FF15 /* JSDOMGlobalObjectTask.cpp in Sources */,
     30249                                516E54FA1CCB2EA80040D954 /* JSFileCustom.cpp in Sources */,
    3024630250                                65DF31F709D1CC60000BE325 /* JSDOMImplementation.cpp in Sources */,
    3024730251                                A9D248060D757E7D00FDF959 /* JSDOMMimeType.cpp in Sources */,
  • trunk/Source/WebCore/bindings/js/JSDictionary.cpp

    r198492 r200032  
    9999}
    100100
     101void JSDictionary::convertValue(ExecState* exec, JSValue value, long int& result)
     102{
     103    result = value.toInt32(exec);
     104}
     105
    101106void JSDictionary::convertValue(ExecState* exec, JSValue value, unsigned& result)
    102107{
     
    118123    double d = value.toNumber(exec);
    119124    doubleToInteger(d, result);
     125}
     126
     127void JSDictionary::convertValue(ExecState* exec, JSValue value, long long& result)
     128{
     129    double d = value.toNumber(exec);
     130    result = llrint(d);
    120131}
    121132
  • trunk/Source/WebCore/bindings/js/JSDictionary.h

    r199750 r200032  
    118118    static void convertValue(JSC::ExecState*, JSC::JSValue, bool& result);
    119119    static void convertValue(JSC::ExecState*, JSC::JSValue, int& result);
     120    static void convertValue(JSC::ExecState*, JSC::JSValue, long int& result);
    120121    static void convertValue(JSC::ExecState*, JSC::JSValue, unsigned& result);
    121122    static void convertValue(JSC::ExecState*, JSC::JSValue, unsigned short& result);
    122123    static void convertValue(JSC::ExecState*, JSC::JSValue, unsigned long& result);
    123124    static void convertValue(JSC::ExecState*, JSC::JSValue, unsigned long long& result);
     125    static void convertValue(JSC::ExecState*, JSC::JSValue, long long& result);
    124126    static void convertValue(JSC::ExecState*, JSC::JSValue, double& result);
    125127    static void convertValue(JSC::ExecState*, JSC::JSValue, Dictionary& result);
  • trunk/Source/WebCore/fileapi/File.cpp

    r199524 r200032  
    6565}
    6666
    67 double File::lastModifiedDate() const
     67File::File(Vector<BlobPart>&& blobParts, const String& filename, const String& contentType, int64_t lastModified)
     68    : Blob(WTFMove(blobParts), contentType)
     69    , m_name(filename)
     70    , m_overrideLastModifiedDate(lastModified)
    6871{
     72}
     73
     74double File::lastModified() const
     75{
     76    if (m_overrideLastModifiedDate)
     77        return m_overrideLastModifiedDate.value();
     78
     79    // FIXME: This does sync-i/o on the main thread and also recalculates every time the method is called.
     80    // The i/o should be performed on a background thread,
     81    // and the result should be cached along with an asynchronous monitor for changes to the file.
    6982    time_t modificationTime;
    7083    if (getFileModificationTime(m_path, modificationTime) && isValidFileTime(modificationTime))
  • trunk/Source/WebCore/fileapi/File.h

    r197563 r200032  
    2828
    2929#include "Blob.h"
     30#include <wtf/Optional.h>
    3031#include <wtf/Ref.h>
    3132#include <wtf/TypeCasts.h>
     
    4142    {
    4243        return adoptRef(*new File(path));
     44    }
     45
     46    // Create a File using the 'new File' constructor.
     47    static Ref<File> create(Vector<BlobPart> blobParts, const String& filename, const String& contentType, int64_t lastModified)
     48    {
     49        return adoptRef(*new File(WTFMove(blobParts), filename, contentType, lastModified));
    4350    }
    4451
     
    6067    const String& path() const { return m_path; }
    6168    const String& name() const { return m_name; }
    62 
    63     // This returns the current date and time if the file's last modification date is not known (per spec: http://www.w3.org/TR/FileAPI/#dfn-lastModifiedDate).
    64     double lastModifiedDate() const;
     69    double lastModified() const;
    6570
    6671    static String contentTypeForFile(const String& path);
     
    7378    WEBCORE_EXPORT explicit File(const String& path);
    7479    File(const String& path, const String& nameOverride);
     80    File(Vector<BlobPart>&& blobParts, const String& filename, const String& contentType, int64_t lastModified);
    7581
    7682    File(DeserializationContructor, const String& path, const URL& srcURL, const String& type, const String& name);
     
    8389    String m_path;
    8490    String m_name;
     91
     92    Optional<String> m_overrideFilename;
     93    Optional<int64_t> m_overrideLastModifiedDate;
    8594};
    8695
  • trunk/Source/WebCore/fileapi/File.idl

    r199264 r200032  
    2525
    2626[
     27    Exposed=(Window),
    2728    JSGenerateToNativeObject,
    2829    JSGenerateToJSObject,
    2930    ExportMacro=WEBCORE_EXPORT,
     31    CustomConstructor(sequence<any> fileBits, DOMString fileName, optional FilePropertyBag options),
    3032] interface File : Blob {
    3133    readonly attribute DOMString name;
    32 #if !defined(LANGUAGE_GOBJECT) || !LANGUAGE_GOBJECT
    33     readonly attribute Date lastModifiedDate;
    34 #endif
     34    readonly attribute long long lastModified;
    3535};
    3636
Note: See TracChangeset for help on using the changeset viewer.