Changeset 51480 in webkit


Ignore:
Timestamp:
Nov 29, 2009 8:15:40 PM (14 years ago)
Author:
oliver@apple.com
Message:

postMessage should serialize File objects
https://bugs.webkit.org/show_bug.cgi?id=31955

Reviewed by Sam Weinig.

Update SerializedScriptValue to include support for
File objects in the serialized object graph.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r51478 r51480  
     12009-11-28  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        postMessage should serialize File objects
     6        https://bugs.webkit.org/show_bug.cgi?id=31955
     7
     8        Add test for postMessage serialization of File objects.
     9
     10        * fast/dom/Window/window-postmessage-clone-expected.txt:
     11        * fast/dom/Window/window-postmessage-clone.html:
     12
    1132009-11-29  Simon Fraser  <simon.fraser@apple.com>
    214
  • trunk/LayoutTests/fast/dom/Window/window-postmessage-clone-expected.txt

    r49229 r51480  
    1717PASS: eventData is 2009-02-13T23:31:30.000Z of type object
    1818PASS: eventData is [object Array](default toString threw RangeError: Maximum call stack size exceeded.) of type object
     19PASS: eventData is [object File] of type object
    1920PASS: eventData is done of type string
    2021
  • trunk/LayoutTests/fast/dom/Window/window-postmessage-clone.html

    r49229 r51480  
    44<div id="description"></div>
    55<div id="console"></div>
     6<input type="file" id="fileInput"></input>
    67<script>
    78if (window.layoutTestController) {
     
    124125tryPostMessage('window', true);
    125126
     127var fileInput = document.getElementById("fileInput");
     128var fileRect = fileInput.getClientRects()[0];
     129var targetX = fileRect.left + fileRect.width / 2;
     130var targetY = fileRect.top + fileRect.height / 2;
     131eventSender.beginDragWithFiles(['get-file-upload.html']);
     132eventSender.mouseMoveTo(targetX, targetY);
     133eventSender.mouseUp();
     134
     135tryPostMessage('fileInput.files[0]', false, fileInput.files[0]);
     136
    126137tryPostMessage('"done"');
    127138</script>
  • trunk/WebCore/ChangeLog

    r51476 r51480  
     12009-11-28  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        postMessage should serialize File objects
     6        https://bugs.webkit.org/show_bug.cgi?id=31955
     7
     8        Update SerializedScriptValue to include support for
     9        File objects in the serialized object graph.
     10
     11        * bindings/js/SerializedScriptValue.cpp:
     12        (WebCore::SerializedScriptValueData::SerializedScriptValueData):
     13        (WebCore::SerializingTreeWalker::convertIfTerminal):
     14        (WebCore::DeserializingTreeWalker::convertIfTerminal):
     15        * bindings/js/SerializedScriptValue.h:
     16        (WebCore::SerializedScriptValueData::):
     17        (WebCore::SerializedScriptValueData::asString):
     18
    1192009-11-29  Simon Fraser  <simon.fraser@apple.com>
    220
  • trunk/WebCore/bindings/js/SerializedScriptValue.cpp

    r51256 r51480  
    2828#include "SerializedScriptValue.h"
    2929
     30#include "File.h"
     31#include "JSDOMGlobalObject.h"
     32#include "JSFile.h"
     33#include "JSFileList.h"
    3034#include <JavaScriptCore/APICast.h>
    3135#include <runtime/DateInstance.h>
     
    147151    : m_type(ArrayType)
    148152    , m_sharedData(data)
     153{
     154}
     155
     156SerializedScriptValueData::SerializedScriptValueData(const File* file)
     157    : m_type(FileType)
     158    , m_string(file->path().crossThreadString())
    149159{
    150160}
     
    483493            return SerializedScriptValueData();
    484494
    485         CallData unusedData;
    486         if (value.isObject() && value.getCallData(unusedData) == CallTypeNone)
    487             return SerializedScriptValueData();
    488 
     495        if (value.isObject()) {
     496            JSObject* obj = asObject(value);
     497            if (obj->inherits(&JSFile::s_info))
     498                return SerializedScriptValueData(toFile(obj));
     499               
     500            CallData unusedData;
     501            if (value.getCallData(unusedData) == CallTypeNone)
     502                return SerializedScriptValueData();
     503        }
    489504        // Any other types are expected to serialize as null.
    490505        return SerializedScriptValueData(jsNull());
     
    642657            case SerializedScriptValueData::DateType:
    643658                return new (m_exec) DateInstance(m_exec, value.asDouble());
     659            case SerializedScriptValueData::FileType:
     660                return toJS(m_exec, static_cast<JSDOMGlobalObject*>(m_exec->lexicalGlobalObject()), File::create(value.asString().crossThreadString()));
    644661            default:
    645662                ASSERT_NOT_REACHED();
  • trunk/WebCore/bindings/js/SerializedScriptValue.h

    r51256 r51480  
    3434
    3535namespace WebCore {
     36    class File;
    3637    class SerializedObject;
    3738    class SerializedArray;
     
    5556            ObjectType,
    5657            ArrayType,
    57             StringType
     58            StringType,
     59            FileType
    5860        };
    5961
     
    7880        {
    7981        }
     82       
     83        explicit SerializedScriptValueData(const File*);
    8084
    8185        explicit SerializedScriptValueData(JSC::JSValue value)
     
    109113        String asString() const
    110114        {
    111             ASSERT(m_type == StringType);
     115            ASSERT(m_type == StringType || m_type == FileType);
    112116            return m_string;
    113117        }
Note: See TracChangeset for help on using the changeset viewer.