Changeset 126464 in webkit


Ignore:
Timestamp:
Aug 23, 2012 12:08:54 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Serialization of JavaScript values does not appear to respect new HTML5 Structured Clone semantics
https://bugs.webkit.org/show_bug.cgi?id=65292

Patch by Christophe Dumez <Christophe Dumez> on 2012-08-23
Reviewed by Oliver Hunt.

Source/JavaScriptCore:

Add function to construct a StringObject from a JSValue.
Similar functions already exist for NumberObject and
BooleanObject for example.

Export several symbols so address linking errors in
WebCore.

  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
  • runtime/BooleanObject.h:

(BooleanObject):

  • runtime/NumberObject.h:

(NumberObject):
(JSC):

  • runtime/StringObject.cpp:

(JSC::constructString):
(JSC):

  • runtime/StringObject.h:

(JSC):

Source/WebCore:

JSC now correctly serialize Boolean, Number and String objects as per
the structured clone algorithm specification. This patch reduces the
delta with the V8 implementation of SerializedScriptValue.

No new tests, already tested by fast/dom/Window/window-postmessage-clone.html

  • bindings/js/SerializedScriptValue.cpp:

(WebCore):
(WebCore::CloneSerializer::dumpStringObject):
(CloneSerializer):
(WebCore::CloneSerializer::dumpIfTerminal):
(WebCore::CloneDeserializer::readTerminal):

LayoutTests:

Update expected results for fast/dom/Window/window-postmessage-clone.html
now that String, Boolean and Number object are correctly serialized with
JSC.

  • fast/dom/Window/window-postmessage-clone-expected.txt:
  • platform/gtk/fast/dom/Window/window-postmessage-clone-expected.txt:
Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r126460 r126464  
     12012-08-23  Christophe Dumez  <christophe.dumez@intel.com>
     2
     3        Serialization of JavaScript values does not appear to respect new HTML5 Structured Clone semantics
     4        https://bugs.webkit.org/show_bug.cgi?id=65292
     5
     6        Reviewed by Oliver Hunt.
     7
     8        Update expected results for fast/dom/Window/window-postmessage-clone.html
     9        now that String, Boolean and Number object are correctly serialized with
     10        JSC.
     11
     12        * fast/dom/Window/window-postmessage-clone-expected.txt:
     13        * platform/gtk/fast/dom/Window/window-postmessage-clone-expected.txt:
     14
    1152012-08-23  Kenneth Russell  <kbr@google.com>
    216
  • trunk/LayoutTests/fast/dom/Window/window-postmessage-clone-expected.txt

    r115088 r126464  
    11Tests that we clone object hierarchies
    22
    3 FAIL: 'postMessage((function(){}))' should throw but didn't
    4 FAIL: 'postMessage(var x = 0; try { eval("badref"); } catch(e) { x = e; } x)' should throw but didn't
    5 PASS: 'postMessage(window)' threw TypeError: Type error
     3PASS: 'postMessage((function(){}))' threw Error: DATA_CLONE_ERR: DOM Exception 25
     4PASS: 'postMessage(var x = 0; try { eval("badref"); } catch(e) { x = e; } x)' threw Error: DATA_CLONE_ERR: DOM Exception 25
     5PASS: 'postMessage(window)' threw Error: DATA_CLONE_ERR: DOM Exception 25
    66PASS: 'postMessage(({get a() { throw "x" }}))' threw x
    77PASS: 'postMessage((function() {return {get a() { throw "accessor-exn"; }};})())' threw accessor-exn
     
    2828PASS: eventData is 1,2,3 of type object
    2929PASS: eventData is ,,1 of type object
    30 FAIL: eventData is null should be function () {} of type function
    31 FAIL: eventData is [object Object] should be ReferenceError: Can't find variable: badref of type object
    3230PASS: eventData is 2009-02-13T23:31:30.000Z of type object
    3331PASS: eventData is [object Object] of type object
    34 FAIL: eventData is [object Object] should be true of type object
    35 FAIL: eventData is [object Object] should be false of type object
    36 FAIL: eventData is [object Object] should be gnirts of type object
    37 FAIL: eventData is [object Object] should be 42 of type object
     32PASS: eventData is true of type object
     33PASS: eventData is false of type object
     34PASS: eventData is gnirts of type object
     35PASS: eventData is 42 of type object
    3836PASS: eventData is === to eventData.self
    3937PASS: eventData is === to eventData[0]
     
    9189PASS: window.acalled === true
    9290FAIL: window.bcalled === undefined
    93 FAIL: Boolean values correct (0)
    94 FAIL: Boolean values correct (3)
     91PASS: Boolean values correct (0)
     92PASS: Boolean values correct (3)
    9593PASS: Boolean values correct (1,2)
    9694PASS: Boolean values correct (4,5)
     
    9997PASS: References to Booleans correct (0,2)
    10098PASS: References to Booleans correct (3,5)
    101 FAIL: Number values correct (0)
     99PASS: Number values correct (0)
    102100PASS: Number values correct (0,2)
    103101PASS: References to numbers correct (0,1)
    104102PASS: References to numbers correct (0,2)
    105 FAIL: String values correct (0)
     103PASS: String values correct (0)
    106104PASS: String values correct (0,2)
    107105PASS: References to strings correct (0,1)
    108106PASS: References to strings correct (0,2)
    109 FAIL: String object properties not serialized
    110 FAIL: Number object properties not serialized
    111 FAIL: Boolean object properties not serialized
     107PASS: String object properties not serialized
     108PASS: Number object properties not serialized
     109PASS: Boolean object properties not serialized
    112110PASS: Date values correct (0)
    113111PASS: Date values correct (1)
  • trunk/LayoutTests/platform/gtk/fast/dom/Window/window-postmessage-clone-expected.txt

    r114992 r126464  
    1 CONSOLE MESSAGE: line 86: TypeError: No default value
    2 CONSOLE MESSAGE: line 86: TypeError: No default value
    31Tests that we clone object hierarchies
    42
    5 FAIL: 'postMessage((function(){}))' should throw but didn't
    6 FAIL: 'postMessage(var x = 0; try { eval("badref"); } catch(e) { x = e; } x)' should throw but didn't
    7 PASS: 'postMessage(window)' threw TypeError: Type error
     3PASS: 'postMessage((function(){}))' threw Error: DATA_CLONE_ERR: DOM Exception 25
     4PASS: 'postMessage(var x = 0; try { eval("badref"); } catch(e) { x = e; } x)' threw Error: DATA_CLONE_ERR: DOM Exception 25
     5PASS: 'postMessage(window)' threw Error: DATA_CLONE_ERR: DOM Exception 25
    86PASS: 'postMessage(({get a() { throw "x" }}))' threw x
    97PASS: eventData is null of type object
     
    2624PASS: eventData is 1,2,3 of type object
    2725PASS: eventData is ,,1 of type object
    28 FAIL: eventData is null should be function () {} of type function
    29 FAIL: eventData is [object Object] should be ReferenceError: Can't find variable: badref of type object
    3026PASS: eventData is 2009-02-13T23:31:30.000Z of type object
    3127PASS: eventData is [object Object] of type object
    32 FAIL: eventData is [object Object] should be true of type object
    33 FAIL: eventData is [object Object] should be false of type object
    34 FAIL: eventData is [object Object] should be gnirts of type object
    35 FAIL: eventData is [object Object] should be 42 of type object
     28PASS: eventData is true of type object
     29PASS: eventData is false of type object
     30PASS: eventData is gnirts of type object
     31PASS: eventData is 42 of type object
    3632PASS: eventData is === to eventData.self
    3733PASS: eventData is === to eventData[0]
     
    9389PASS: window.acalled === true
    9490FAIL: window.bcalled === undefined
    95 FAIL: Boolean values correct (0)
    96 FAIL: Boolean values correct (3)
     91PASS: Boolean values correct (0)
     92PASS: Boolean values correct (3)
    9793PASS: Boolean values correct (1,2)
    9894PASS: Boolean values correct (4,5)
     
    10197PASS: References to Booleans correct (0,2)
    10298PASS: References to Booleans correct (3,5)
    103 FAIL: Number values correct (0)
     99PASS: Number values correct (0)
    104100PASS: Number values correct (0,2)
    105101PASS: References to numbers correct (0,1)
    106102PASS: References to numbers correct (0,2)
    107 FAIL: String values correct (0)
     103PASS: String values correct (0)
    108104PASS: String values correct (0,2)
    109105PASS: References to strings correct (0,1)
    110106PASS: References to strings correct (0,2)
    111 FAIL: String object properties not serialized
    112 FAIL: Number object properties not serialized
    113 FAIL: Boolean object properties not serialized
     107PASS: String object properties not serialized
     108PASS: Number object properties not serialized
     109PASS: Boolean object properties not serialized
    114110PASS: Date values correct (0)
    115111PASS: Date values correct (1)
  • trunk/Source/JavaScriptCore/ChangeLog

    r126387 r126464  
     12012-08-23  Christophe Dumez  <christophe.dumez@intel.com>
     2
     3        Serialization of JavaScript values does not appear to respect new HTML5 Structured Clone semantics
     4        https://bugs.webkit.org/show_bug.cgi?id=65292
     5
     6        Reviewed by Oliver Hunt.
     7
     8        Add function to construct a StringObject from a JSValue.
     9        Similar functions already exist for NumberObject and
     10        BooleanObject for example.
     11
     12        Export several symbols so address linking errors in
     13        WebCore.
     14
     15        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
     16        * runtime/BooleanObject.h:
     17        (BooleanObject):
     18        * runtime/NumberObject.h:
     19        (NumberObject):
     20        (JSC):
     21        * runtime/StringObject.cpp:
     22        (JSC::constructString):
     23        (JSC):
     24        * runtime/StringObject.h:
     25        (JSC):
     26
    1272012-08-22  Filip Pizlo  <fpizlo@apple.com>
    228
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def

    r125711 r126464  
    22
    33    ??0ArrayBufferView@WTF@@IAE@V?$PassRefPtr@VArrayBuffer@WTF@@@1@I@Z
     4    ??0BooleanObject@JSC@@IAE@AAVJSGlobalData@1@PAVStructure@1@@Z
    45    ??0CString@WTF@@QAE@PBD@Z
    56    ??0CString@WTF@@QAE@PBDI@Z
     
    108109    ?constructEmptyObject@JSC@@YAPAVJSObject@1@PAVExecState@1@@Z
    109110    ?constructFunctionSkippingEvalEnabledCheck@JSC@@YAPAVJSObject@1@PAVExecState@1@PAVJSGlobalObject@1@ABVArgList@1@ABVIdentifier@1@ABVUString@1@ABVTextPosition@WTF@@@Z
     111    ?constructNumber@JSC@@YAPAVNumberObject@1@PAVExecState@1@PAVJSGlobalObject@1@VJSValue@1@@Z
     112    ?constructString@JSC@@YAPAVStringObject@1@PAVExecState@1@PAVJSGlobalObject@1@VJSValue@1@@Z
    110113    ?convertLatin1ToUTF8@Unicode@WTF@@YA?AW4ConversionResult@12@PAPBEPBEPAPADPAD@Z
    111114    ?convertUTF16ToUTF8@Unicode@WTF@@YA?AW4ConversionResult@12@PAPB_WPB_WPAPADPAD_N@Z
     
    187190    ?finalize@WeakHandleOwner@JSC@@UAEXV?$Handle@W4Unknown@JSC@@@2@PAX@Z
    188191    ?findAllocator@WeakSet@JSC@@AAEPAUFreeCell@WeakBlock@2@XZ
     192    ?finishCreation@BooleanObject@JSC@@IAEXAAVJSGlobalData@2@@Z
    189193    ?finishCreation@DateInstance@JSC@@IAEXAAVJSGlobalData@2@N@Z
    190194    ?finishCreation@InternalFunction@JSC@@IAEXAAVJSGlobalData@2@ABVUString@2@@Z
  • trunk/Source/JavaScriptCore/runtime/BooleanObject.h

    r103243 r126464  
    2828    class BooleanObject : public JSWrapperObject {
    2929    protected:
    30         BooleanObject(JSGlobalData&, Structure*);
    31         void finishCreation(JSGlobalData&);
     30        JS_EXPORT_PRIVATE BooleanObject(JSGlobalData&, Structure*);
     31        JS_EXPORT_PRIVATE void finishCreation(JSGlobalData&);
    3232
    3333    public:
     
    4141        }
    4242       
    43         static const ClassInfo s_info;
     43        static JS_EXPORTDATA const ClassInfo s_info;
    4444       
    4545        static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue prototype)
  • trunk/Source/JavaScriptCore/runtime/NumberObject.h

    r103243 r126464  
    4141        }
    4242
    43         static const ClassInfo s_info;
     43        static JS_EXPORTDATA const ClassInfo s_info;
    4444
    4545        static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue prototype)
     
    4949    };
    5050
    51     NumberObject* constructNumber(ExecState*, JSGlobalObject*, JSValue);
     51    JS_EXPORT_PRIVATE NumberObject* constructNumber(ExecState*, JSGlobalObject*, JSValue);
    5252
    5353} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/StringObject.cpp

    r116828 r126464  
    2323
    2424#include "Error.h"
     25#include "JSGlobalObject.h"
    2526#include "PropertyNameArray.h"
    2627
     
    144145}
    145146
     147StringObject* constructString(ExecState* exec, JSGlobalObject* globalObject, JSValue string)
     148{
     149    StringObject* object = StringObject::create(exec, globalObject->stringObjectStructure());
     150    object->setInternalValue(exec->globalData(), string);
     151    return object;
     152}
     153
    146154} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/StringObject.h

    r116828 r126464  
    7979    }
    8080
     81    JS_EXPORT_PRIVATE StringObject* constructString(ExecState*, JSGlobalObject*, JSValue);
     82
    8183} // namespace JSC
    8284
  • trunk/Source/WebCore/ChangeLog

    r126461 r126464  
     12012-08-23  Christophe Dumez  <christophe.dumez@intel.com>
     2
     3        Serialization of JavaScript values does not appear to respect new HTML5 Structured Clone semantics
     4        https://bugs.webkit.org/show_bug.cgi?id=65292
     5
     6        Reviewed by Oliver Hunt.
     7
     8        JSC now correctly serialize Boolean, Number and String objects as per
     9        the structured clone algorithm specification. This patch reduces the
     10        delta with the V8 implementation of SerializedScriptValue.
     11
     12        No new tests, already tested by fast/dom/Window/window-postmessage-clone.html
     13
     14        * bindings/js/SerializedScriptValue.cpp:
     15        (WebCore):
     16        (WebCore::CloneSerializer::dumpStringObject):
     17        (CloneSerializer):
     18        (WebCore::CloneSerializer::dumpIfTerminal):
     19        (WebCore::CloneDeserializer::readTerminal):
     20
    1212012-08-23  Joshua Bell  <jsbell@chromium.org>
    222
  • trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp

    r126067 r126464  
    5757#include <JavaScriptCore/APICast.h>
    5858#include <JavaScriptCore/APIShims.h>
     59#include <runtime/BooleanObject.h>
    5960#include <runtime/DateInstance.h>
    6061#include <runtime/Error.h>
     
    109110    ArrayBufferViewTag = 22,
    110111    ArrayBufferTransferTag = 23,
     112    TrueObjectTag = 24,
     113    FalseObjectTag = 25,
     114    StringObjectTag = 26,
     115    EmptyStringObjectTag = 27,
     116    NumberObjectTag = 28,
    111117    ErrorTag = 255
    112118};
     
    153159 * Initial version was 1.
    154160 * Version 2. added the ObjectReferenceTag and support for serialization of cyclic graphs.
     161 * Version 3. added the FalseObjectTag, TrueObjectTag, NumberObjectTag, StringObjectTag
     162 * and EmptyStringObjectTag for serialization of Boolean, Number and String objects.
    155163 */
    156 static const unsigned int CurrentVersion = 2;
     164static const unsigned int CurrentVersion = 3;
    157165static const unsigned int TerminatorTag = 0xFFFFFFFF;
    158166static const unsigned int StringPoolTag = 0xFFFFFFFE;
     
    183191 *    | FalseTag
    184192 *    | TrueTag
     193 *    | FalseObjectTag
     194 *    | TrueObjectTag
    185195 *    | DoubleTag <value:double>
     196 *    | NumberObjectTag <value:double>
    186197 *    | DateTag <value:double>
    187198 *    | String
    188199 *    | EmptyStringTag
     200 *    | EmptyStringObjectTag
    189201 *    | File
    190202 *    | FileList
     
    200212 *      EmptyStringTag
    201213 *      StringTag StringData
     214 *
     215 * StringObject:
     216 *      EmptyStringObjectTag
     217 *      StringObjectTag StringData
    202218 *
    203219 * StringData :-
     
    518534    }
    519535
     536    void dumpStringObject(UString str)
     537    {
     538        if (str.isEmpty())
     539            write(EmptyStringObjectTag);
     540        else {
     541            write(StringObjectTag);
     542            write(str);
     543        }
     544    }
     545
    520546    bool dumpArrayBufferView(JSObject* obj, SerializationReturnCode& code)
    521547    {
     
    586612        if (value.isObject()) {
    587613            JSObject* obj = asObject(value);
     614            if (obj->inherits(&BooleanObject::s_info)) {
     615                if (!startObjectInternal(obj)) // handle duplicates
     616                    return true;
     617                write(asBooleanObject(value)->internalValue().toBoolean() ? TrueObjectTag : FalseObjectTag);
     618                return true;
     619            }
     620            if (obj->inherits(&StringObject::s_info)) {
     621                if (!startObjectInternal(obj)) // handle duplicates
     622                    return true;
     623                UString str = asString(asStringObject(value)->internalValue())->value(m_exec);
     624                dumpStringObject(str);
     625                return true;
     626            }
     627            if (obj->inherits(&NumberObject::s_info)) {
     628                if (!startObjectInternal(obj)) // handle duplicates
     629                    return true;
     630                write(NumberObjectTag);
     631                NumberObject* obj = static_cast<NumberObject*>(asObject(value));
     632                write(obj->internalValue().asNumber());
     633                return true;
     634            }
    588635            if (obj->inherits(&JSFile::s_info)) {
    589636                write(FileTag);
     
    13991446        case TrueTag:
    14001447            return jsBoolean(true);
     1448        case FalseObjectTag: {
     1449            BooleanObject* obj = BooleanObject::create(m_exec->globalData(), m_globalObject->booleanObjectStructure());
     1450            obj->setInternalValue(m_exec->globalData(), jsBoolean(false));
     1451            m_gcBuffer.append(obj);
     1452            return obj;
     1453        }
     1454        case TrueObjectTag: {
     1455            BooleanObject* obj = BooleanObject::create(m_exec->globalData(), m_globalObject->booleanObjectStructure());
     1456            obj->setInternalValue(m_exec->globalData(), jsBoolean(true));
     1457             m_gcBuffer.append(obj);
     1458            return obj;
     1459        }
    14011460        case DoubleTag: {
    14021461            double d;
     
    14041463                return JSValue();
    14051464            return jsNumber(d);
     1465        }
     1466        case NumberObjectTag: {
     1467            double d;
     1468            if (!read(d))
     1469                return JSValue();
     1470            NumberObject* obj = constructNumber(m_exec, m_globalObject, jsNumber(d));
     1471            m_gcBuffer.append(obj);
     1472            return obj;
    14061473        }
    14071474        case DateTag: {
     
    14801547        case EmptyStringTag:
    14811548            return jsEmptyString(&m_exec->globalData());
     1549        case StringObjectTag: {
     1550            CachedStringRef cachedString;
     1551            if (!readStringData(cachedString))
     1552                return JSValue();
     1553            StringObject* obj = constructString(m_exec, m_globalObject, cachedString->jsString(m_exec));
     1554            m_gcBuffer.append(obj);
     1555            return obj;
     1556        }
     1557        case EmptyStringObjectTag: {
     1558            StringObject* obj = constructString(m_exec, m_globalObject, jsEmptyString(&m_exec->globalData()));
     1559            m_gcBuffer.append(obj);
     1560            return obj;
     1561        }
    14821562        case RegExpTag: {
    14831563            CachedStringRef pattern;
Note: See TracChangeset for help on using the changeset viewer.