Changeset 119791 in webkit


Ignore:
Timestamp:
Jun 7, 2012 8:15:27 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

FileAPI: Blob should support ArrayBufferView instead of ArrayBuffer for Constructor Parameters
https://bugs.webkit.org/show_bug.cgi?id=88294

Patch by Li Yin <li.yin@intel.com> on 2012-06-07
Reviewed by Jian Li.

Source/WebCore:

From Spec: http://dev.w3.org/2006/webapi/FileAPI/#dfn-Blob
Currently we add the support for ArrayBufferView, while still keeping ArrayBuffer for
backward compatibility. We will remove it in the near future.

Test: fast/files/blob-constructor.html

  • bindings/js/JSBlobCustom.cpp:

(WebCore::JSBlobConstructor::constructJSBlob):

  • bindings/v8/custom/V8BlobCustom.cpp:

(WebCore::V8Blob::constructorCallback):

  • fileapi/WebKitBlobBuilder.cpp:

(WebCore::WebKitBlobBuilder::append):
(WebCore):

  • fileapi/WebKitBlobBuilder.h:

(WebCore):
(WebKitBlobBuilder):

  • fileapi/WebKitBlobBuilder.idl: Add support for ArrayBufferView in append method

LayoutTests:

Support ArrayBufferView in Blob constructing function.

  • fast/files/blob-constructor-expected.txt:
  • fast/files/file-reader-fffd-expected.txt:
  • fast/files/file-reader-fffd.html:
  • fast/files/script-tests/blob-constructor.js:
  • http/tests/websocket/tests/hybi/bufferedAmount-after-close-in-busy.html:
  • http/tests/websocket/tests/hybi/bufferedAmount-after-close.html:
  • http/tests/websocket/tests/hybi/send-blob.html:
  • http/tests/websocket/tests/hybi/workers/resources/send-blob.js:

(createBlobContainingAllDistinctBytes):

Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r119790 r119791  
     12012-06-07  Li Yin  <li.yin@intel.com>
     2
     3        FileAPI: Blob should support ArrayBufferView instead of ArrayBuffer for Constructor Parameters
     4        https://bugs.webkit.org/show_bug.cgi?id=88294
     5
     6        Reviewed by Jian Li.
     7
     8        Support ArrayBufferView in Blob constructing function.
     9
     10        * fast/files/blob-constructor-expected.txt:
     11        * fast/files/file-reader-fffd-expected.txt:
     12        * fast/files/file-reader-fffd.html:
     13        * fast/files/script-tests/blob-constructor.js:
     14        * http/tests/websocket/tests/hybi/bufferedAmount-after-close-in-busy.html:
     15        * http/tests/websocket/tests/hybi/bufferedAmount-after-close.html:
     16        * http/tests/websocket/tests/hybi/send-blob.html:
     17        * http/tests/websocket/tests/hybi/workers/resources/send-blob.js:
     18        (createBlobContainingAllDistinctBytes):
     19
    1202012-06-07  MORITA Hajime  <morrita@google.com>
    221
  • trunk/LayoutTests/fast/files/blob-constructor-expected.txt

    r119702 r119791  
    1414PASS new Blob(0) threw exception TypeError: First argument of the constructor is not of type Array.
    1515PASS (new Blob([])) instanceof window.Blob is true
    16 PASS (new Blob([new ArrayBuffer(8)])) instanceof window.Blob is true
    1716PASS (new Blob(['stringPrimitive'])) instanceof window.Blob is true
    1817PASS (new Blob([String('stringObject')])) instanceof window.Blob is true
     
    4544PASS (new Blob([], {type:'text/html'})).size is 0
    4645PASS window.Blob.length is 2
     46PASS new Blob([new DataView(new ArrayBuffer(100))]).size is 100
     47PASS new Blob([new Uint8Array(100)]).size is 100
     48PASS new Blob([new Uint8ClampedArray(100)]).size is 100
     49PASS new Blob([new Uint16Array(100)]).size is 200
     50PASS new Blob([new Uint32Array(100)]).size is 400
     51PASS new Blob([new Int8Array(100)]).size is 100
     52PASS new Blob([new Int16Array(100)]).size is 200
     53PASS new Blob([new Int32Array(100)]).size is 400
     54PASS new Blob([new Float32Array(100)]).size is 400
     55PASS new Blob([new Float64Array(100)]).size is 800
     56PASS new Blob([new Float64Array(100), new Int32Array(100), new Uint8Array(100), new DataView(new ArrayBuffer(100))]).size is 1400
     57PASS new Blob([new Blob([new Int32Array(100)]), new Uint8Array(100), new Float32Array(100), new DataView(new ArrayBuffer(100))]).size is 1000
    4758PASS successfullyParsed is true
    4859
  • trunk/LayoutTests/fast/files/file-reader-fffd-expected.txt

    r115582 r119791  
    44
    55array = new Uint8Array([65, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 66]);
    6 blob = new Blob([array.buffer]);
     6blob = new Blob([array]);
    77reader = new FileReader();
    88reader.readAsText(blob);
  • trunk/LayoutTests/fast/files/file-reader-fffd.html

    r115582 r119791  
    1212
    1313array = evalAndLog("array = new Uint8Array([65, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 66]);");
    14 blob = evalAndLog("blob = new Blob([array.buffer]);");
     14blob = evalAndLog("blob = new Blob([array]);");
    1515reader = evalAndLog("reader = new FileReader();");
    1616reader.onload = function(event) {
  • trunk/LayoutTests/fast/files/script-tests/blob-constructor.js

    r119702 r119791  
    1616// Test valid blob parts.
    1717shouldBeTrue("(new Blob([])) instanceof window.Blob");
    18 shouldBeTrue("(new Blob([new ArrayBuffer(8)])) instanceof window.Blob");
    1918shouldBeTrue("(new Blob(['stringPrimitive'])) instanceof window.Blob");
    2019shouldBeTrue("(new Blob([String('stringObject')])) instanceof window.Blob");
     
    6564// Odds and ends
    6665shouldBe("window.Blob.length", "2");
     66
     67// Test ArrayBufferView Parameters
     68shouldBe("new Blob([new DataView(new ArrayBuffer(100))]).size", "100");
     69shouldBe("new Blob([new Uint8Array(100)]).size", "100");
     70shouldBe("new Blob([new Uint8ClampedArray(100)]).size", "100");
     71shouldBe("new Blob([new Uint16Array(100)]).size", "200");
     72shouldBe("new Blob([new Uint32Array(100)]).size", "400");
     73shouldBe("new Blob([new Int8Array(100)]).size", "100");
     74shouldBe("new Blob([new Int16Array(100)]).size", "200");
     75shouldBe("new Blob([new Int32Array(100)]).size", "400");
     76shouldBe("new Blob([new Float32Array(100)]).size", "400");
     77shouldBe("new Blob([new Float64Array(100)]).size", "800");
     78shouldBe("new Blob([new Float64Array(100), new Int32Array(100), new Uint8Array(100), new DataView(new ArrayBuffer(100))]).size", "1400");
     79shouldBe("new Blob([new Blob([new Int32Array(100)]), new Uint8Array(100), new Float32Array(100), new DataView(new ArrayBuffer(100))]).size", "1000");
  • trunk/LayoutTests/http/tests/websocket/tests/hybi/bufferedAmount-after-close-in-busy.html

    r115582 r119791  
    2424function createBlobWithLength(length)
    2525{
    26     return new Blob([new ArrayBuffer(length)]);
     26    return new Blob([new Uint8Array(length)]);
    2727}
    2828
  • trunk/LayoutTests/http/tests/websocket/tests/hybi/bufferedAmount-after-close.html

    r115582 r119791  
    2424function createBlobWithLength(length)
    2525{
    26     return new Blob([new ArrayBuffer(length)]);
     26    return new Blob([new Uint8Array(length)]);
    2727}
    2828
  • trunk/LayoutTests/http/tests/websocket/tests/hybi/send-blob.html

    r115582 r119791  
    3434    for (var i = 0; i < 256; ++i)
    3535        array[i] = i;
    36     return new Blob([array.buffer]);
     36    return new Blob([array]);
    3737}
    3838
  • trunk/LayoutTests/http/tests/websocket/tests/hybi/workers/resources/send-blob.js

    r115582 r119791  
    1414    for (var i = 0; i < 256; ++i)
    1515        array[i] = i;
    16     return new Blob([array.buffer]);
     16    return new Blob([array]);
    1717}
    1818
  • trunk/Source/WebCore/ChangeLog

    r119790 r119791  
     12012-06-07  Li Yin  <li.yin@intel.com>
     2
     3        FileAPI: Blob should support ArrayBufferView instead of ArrayBuffer for Constructor Parameters
     4        https://bugs.webkit.org/show_bug.cgi?id=88294
     5
     6        Reviewed by Jian Li.
     7
     8        From Spec: http://dev.w3.org/2006/webapi/FileAPI/#dfn-Blob
     9        Currently we add the support for ArrayBufferView, while still keeping ArrayBuffer for
     10        backward compatibility. We will remove it in the near future.
     11
     12        Test: fast/files/blob-constructor.html
     13
     14        * bindings/js/JSBlobCustom.cpp:
     15        (WebCore::JSBlobConstructor::constructJSBlob):
     16        * bindings/v8/custom/V8BlobCustom.cpp:
     17        (WebCore::V8Blob::constructorCallback):
     18        * fileapi/WebKitBlobBuilder.cpp:
     19        (WebCore::WebKitBlobBuilder::append):
     20        (WebCore):
     21        * fileapi/WebKitBlobBuilder.h:
     22        (WebCore):
     23        (WebKitBlobBuilder):
     24        * fileapi/WebKitBlobBuilder.idl: Add support for ArrayBufferView in append method
     25
    1262012-06-07  MORITA Hajime  <morrita@google.com>
    227
  • trunk/Source/WebCore/bindings/js/JSBlobCustom.cpp

    r119702 r119791  
    3636#include "ExceptionCodePlaceholder.h"
    3737#include "JSArrayBuffer.h"
     38#include "JSArrayBufferView.h"
    3839#include "JSDOMBinding.h"
    3940#include "JSDictionary.h"
     
    120121#if ENABLE(BLOB)
    121122        if (item.inherits(&JSArrayBuffer::s_info))
    122             blobBuilder->append(toArrayBuffer(item));
     123            blobBuilder->append(context, toArrayBuffer(item));
     124        else if (item.inherits(&JSArrayBufferView::s_info))
     125            blobBuilder->append(toArrayBufferView(item));
    123126        else
    124127#endif
  • trunk/Source/WebCore/bindings/v8/custom/V8BlobCustom.cpp

    r119702 r119791  
    3434#include "Dictionary.h"
    3535#include "V8ArrayBuffer.h"
     36#include "V8ArrayBufferView.h"
    3637#include "V8Binding.h"
    3738#include "V8BindingMacros.h"
     
    121122            ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(v8::Handle<v8::Object>::Cast(item));
    122123            ASSERT(arrayBuffer);
    123             blobBuilder->append(arrayBuffer);
     124            blobBuilder->append(context, arrayBuffer);
     125        } else if (V8ArrayBufferView::HasInstance(item)) {
     126            ArrayBufferView* arrayBufferView = V8ArrayBufferView::toNative(v8::Handle<v8::Object>::Cast(item));
     127            ASSERT(arrayBufferView);
     128            blobBuilder->append(arrayBufferView);
    124129        } else
    125130#endif
  • trunk/Source/WebCore/fileapi/WebKitBlobBuilder.cpp

    r118394 r119791  
    3737#include "File.h"
    3838#include "LineEnding.h"
     39#include "ScriptExecutionContext.h"
    3940#include "TextEncoding.h"
    4041#include <wtf/ArrayBuffer.h>
     42#include <wtf/ArrayBufferView.h>
    4143#include <wtf/PassRefPtr.h>
    4244#include <wtf/Vector.h>
     
    8789
    8890#if ENABLE(BLOB)
    89 void WebKitBlobBuilder::append(ArrayBuffer* arrayBuffer)
     91void WebKitBlobBuilder::append(ScriptExecutionContext* context, ArrayBuffer* arrayBuffer)
    9092{
     93    String consoleMessage("ArrayBuffer values are deprecated in Blob Constructor. Use ArrayBufferView instead.");
     94    context->addConsoleMessage(JSMessageSource, LogMessageType, WarningMessageLevel, consoleMessage);
    9195    if (!arrayBuffer)
    9296        return;
     
    9498    size_t oldSize = buffer.size();
    9599    buffer.append(static_cast<const char*>(arrayBuffer->data()), arrayBuffer->byteLength());
     100    m_size += buffer.size() - oldSize;
     101}
     102
     103void WebKitBlobBuilder::append(ArrayBufferView* arrayBufferView)
     104{
     105    if (!arrayBufferView)
     106        return;
     107    Vector<char>& buffer = getBuffer();
     108    size_t oldSize = buffer.size();
     109    buffer.append(static_cast<const char*>(arrayBufferView->baseAddress()), arrayBufferView->byteLength());
    96110    m_size += buffer.size() - oldSize;
    97111}
  • trunk/Source/WebCore/fileapi/WebKitBlobBuilder.h

    r100227 r119791  
    3939
    4040class Blob;
     41class ScriptExecutionContext;
    4142class TextEncoding;
    4243
     
    5152    void append(const String& text, const String& ending, ExceptionCode&);
    5253#if ENABLE(BLOB)
    53     void append(ArrayBuffer*);
     54    void append(ScriptExecutionContext*, ArrayBuffer*);
     55    void append(ArrayBufferView*);
    5456#endif
    5557
  • trunk/Source/WebCore/fileapi/WebKitBlobBuilder.idl

    r115666 r119791  
    4141        void append(in Blob blob);
    4242#if defined(ENABLE_BLOB) && ENABLE_BLOB
    43         void append(in ArrayBuffer arrayBuffer);
     43        [CallWith=ScriptExecutionContext] void append(in ArrayBuffer arrayBuffer);
     44        void append(in ArrayBufferView arrayBufferView);
    4445#endif
    4546        void append(in DOMString value, in [Optional, TreatNullAs=NullString, TreatUndefinedAs=NullString] DOMString endings) raises (DOMException);
Note: See TracChangeset for help on using the changeset viewer.