Changeset 57207 in webkit


Ignore:
Timestamp:
Apr 7, 2010 7:04:56 AM (14 years ago)
Author:
vitalyr@chromium.org
Message:

2010-04-07 Vitaly Repeshko <vitalyr@chromium.org>

Reviewed by Yury Semikhatsky.

[V8] Throw exception in SerializedScriptValue on input errors
https://bugs.webkit.org/show_bug.cgi?id=37160

When cycles are detected SerializedScriptValue should throw
NOT_SUPPORTED_ERR. See
http://www.whatwg.org/specs/web-apps/2009-10-27/multipage/urls.html#structured-clone

  • bindings/scripts/CodeGeneratorV8.pm: Custom processing for function arguments of type SerializedScriptValue.
  • bindings/v8/SerializedScriptValue.cpp: (WebCore::SerializedScriptValue::SerializedScriptValue):
  • bindings/v8/SerializedScriptValue.h: (WebCore::SerializedScriptValue::create): Added a constructor function with an extra paratemer to check whether an exception was thrown.

SerializedScriptValue::create callers updated to check for
exceptions:

  • bindings/v8/custom/V8DOMWindowCustom.cpp: (WebCore::V8DOMWindow::postMessageCallback):
  • bindings/v8/custom/V8DedicatedWorkerContextCustom.cpp: (WebCore::V8DedicatedWorkerContext::postMessageCallback):
  • bindings/v8/custom/V8HistoryCustom.cpp: (WebCore::V8History::pushStateCallback): (WebCore::V8History::replaceStateCallback):
  • bindings/v8/custom/V8MessagePortCustom.cpp: (WebCore::V8MessagePort::postMessageCallback):
  • bindings/v8/custom/V8PopStateEventCustom.cpp: (WebCore::V8PopStateEvent::initPopStateEventCallback):
  • bindings/v8/custom/V8WorkerCustom.cpp: (WebCore::V8Worker::postMessageCallback):
Location:
trunk/WebCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r57206 r57207  
     12010-04-07  Vitaly Repeshko  <vitalyr@chromium.org>
     2
     3        Reviewed by Yury Semikhatsky.
     4
     5        [V8] Throw exception in SerializedScriptValue on input errors
     6        https://bugs.webkit.org/show_bug.cgi?id=37160
     7
     8        When cycles are detected SerializedScriptValue should throw
     9        NOT_SUPPORTED_ERR. See
     10        http://www.whatwg.org/specs/web-apps/2009-10-27/multipage/urls.html#structured-clone
     11
     12        * bindings/scripts/CodeGeneratorV8.pm: Custom processing for
     13        function arguments of type SerializedScriptValue.
     14
     15        * bindings/v8/SerializedScriptValue.cpp:
     16        (WebCore::SerializedScriptValue::SerializedScriptValue):
     17        * bindings/v8/SerializedScriptValue.h:
     18        (WebCore::SerializedScriptValue::create): Added a constructor
     19        function with an extra paratemer to check whether an exception was
     20        thrown.
     21
     22        SerializedScriptValue::create callers updated to check for
     23        exceptions:
     24        * bindings/v8/custom/V8DOMWindowCustom.cpp:
     25        (WebCore::V8DOMWindow::postMessageCallback):
     26        * bindings/v8/custom/V8DedicatedWorkerContextCustom.cpp:
     27        (WebCore::V8DedicatedWorkerContext::postMessageCallback):
     28        * bindings/v8/custom/V8HistoryCustom.cpp:
     29        (WebCore::V8History::pushStateCallback):
     30        (WebCore::V8History::replaceStateCallback):
     31        * bindings/v8/custom/V8MessagePortCustom.cpp:
     32        (WebCore::V8MessagePort::postMessageCallback):
     33        * bindings/v8/custom/V8PopStateEventCustom.cpp:
     34        (WebCore::V8PopStateEvent::initPopStateEventCallback):
     35        * bindings/v8/custom/V8WorkerCustom.cpp:
     36        (WebCore::V8Worker::postMessageCallback):
     37
    1382010-04-07  Alexander Pavlov  <apavlov@chromium.org>
    239
  • trunk/WebCore/bindings/scripts/CodeGeneratorV8.pm

    r57134 r57207  
    11021102        }
    11031103
    1104         if (BasicTypeCanFailConversion($parameter)) {
     1104        if ($parameter->type eq "SerializedScriptValue") {
     1105            $implIncludes{"SerializedScriptValue.h"} = 1;
     1106            push(@implContentDecls, "    bool ${parameterName}DidThrow = false;\n");
     1107        } elsif (BasicTypeCanFailConversion($parameter)) {
    11051108            push(@implContentDecls, "    bool ${parameterName}Ok;\n");
    11061109        }
    11071110
    11081111        push(@implContentDecls, "    " . GetNativeTypeFromSignature($parameter, $paramIndex) . " $parameterName = ");
    1109         push(@implContentDecls, JSValueToNative($parameter, "args[$paramIndex]",
    1110            BasicTypeCanFailConversion($parameter) ?  "${parameterName}Ok" : undef) . ";\n");
     1112
     1113        if ($parameter->type eq "SerializedScriptValue") {
     1114            push(@implContentDecls, "SerializedScriptValue::create(args[$paramIndex], ${parameterName}DidThrow);\n");
     1115            push(@implContentDecls, "    if (${parameterName}DidThrow)\n    return v8::Undefined();\n");
     1116        } else {
     1117            push(@implContentDecls, JSValueToNative($parameter, "args[$paramIndex]",
     1118                                                    BasicTypeCanFailConversion($parameter) ?  "${parameterName}Ok" : undef) . ";\n");
     1119        }
    11111120
    11121121        if (TypeCanFailConversion($parameter)) {
     
    24852494    }
    24862495
    2487     if ($type eq "SerializedScriptValue") {
    2488         $implIncludes{"SerializedScriptValue.h"} = 1;
    2489         return "SerializedScriptValue::create($value)";
    2490     }
     2496    die "Unexpected SerializedScriptValue" if $type eq "SerializedScriptValue";
    24912497
    24922498    if ($type eq "DOMObject") {
  • trunk/WebCore/bindings/v8/SerializedScriptValue.cpp

    r57145 r57207  
    3737#include "SharedBuffer.h"
    3838#include "V8ImageData.h"
     39#include "V8Proxy.h"
    3940
    4041#include <v8.h>
     
    870871} // namespace
    871872
    872 SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value)
     873SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, bool& didThrow)
    873874{
     875    didThrow = false;
    874876    Writer writer;
    875877    Serializer serializer(writer);
    876878    if (!serializer.serialize(value)) {
    877         // FIXME: throw exception
     879        throwError(NOT_SUPPORTED_ERR);
     880        didThrow = true;
    878881        return;
    879882    }
  • trunk/WebCore/bindings/v8/SerializedScriptValue.h

    r56903 r57207  
    5757    static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value> value)
    5858    {
    59         return adoptRef(new SerializedScriptValue(value));
     59        bool didThrow;
     60        return adoptRef(new SerializedScriptValue(value, didThrow));
     61    }
     62
     63    // Creates a serialized representation of the given V8 value.
     64    //
     65    // If a serialization error occurs (e.g., cyclic input value) this
     66    // function returns an empty representation, schedules a V8 exception to
     67    // be thrown using v8::ThrowException(), and sets |didThrow|. In this case
     68    // the caller must not invoke any V8 operations until control returns to
     69    // V8. When serialization is successful, |didThrow| is false.
     70    static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value> value, bool& didThrow)
     71    {
     72        return adoptRef(new SerializedScriptValue(value, didThrow));
    6073    }
    6174
     
    100113    SerializedScriptValue() { }
    101114
    102     explicit SerializedScriptValue(v8::Handle<v8::Value>);
     115    SerializedScriptValue(v8::Handle<v8::Value>, bool& didThrow);
    103116
    104117    SerializedScriptValue(String data, StringDataMode mode);
  • trunk/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp

    r56166 r57207  
    321321    ASSERT(source->frame());
    322322
    323     v8::TryCatch tryCatch;
    324     RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0]);
     323    bool didThrow = false;
     324    RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0], didThrow);
     325    if (didThrow)
     326        return v8::Undefined();
     327
    325328    MessagePortArray portArray;
    326329    String targetOrigin;
     
    330333    // or
    331334    //   postMessage(message, targetOrigin);
     335    v8::TryCatch tryCatch;
    332336    if (args.Length() > 2) {
    333337        if (!getMessagePortArray(args[1], portArray))
  • trunk/WebCore/bindings/v8/custom/V8DedicatedWorkerContextCustom.cpp

    r53586 r57207  
    4747    INC_STATS(L"DOM.DedicatedWorkerContext.postMessage");
    4848    DedicatedWorkerContext* workerContext = V8DedicatedWorkerContext::toNative(args.Holder());
    49     RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0]);
     49    bool didThrow = false;
     50    RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0], didThrow);
     51    if (didThrow)
     52        return v8::Undefined();
    5053    MessagePortArray portArray;
    5154    if (args.Length() > 1) {
  • trunk/WebCore/bindings/v8/custom/V8HistoryCustom.cpp

    r57004 r57207  
    4444v8::Handle<v8::Value> V8History::pushStateCallback(const v8::Arguments& args)
    4545{
    46     RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(args[0]);
     46    bool didThrow = false;
     47    RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(args[0], didThrow);
     48    if (didThrow)
     49        return v8::Undefined();
    4750
    4851    v8::TryCatch tryCatch;
     
    6568v8::Handle<v8::Value> V8History::replaceStateCallback(const v8::Arguments& args)
    6669{
    67     RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(args[0]);
     70    bool didThrow = false;
     71    RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(args[0], didThrow);
     72    if (didThrow)
     73        return v8::Undefined();
    6874
    6975    v8::TryCatch tryCatch;
  • trunk/WebCore/bindings/v8/custom/V8MessagePortCustom.cpp

    r55096 r57207  
    4747    INC_STATS("DOM.MessagePort.postMessage");
    4848    MessagePort* messagePort = V8MessagePort::toNative(args.Holder());
    49     RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0]);
     49    bool didThrow = false;
     50    RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0], didThrow);
     51    if (didThrow)
     52        return v8::Undefined();
    5053    MessagePortArray portArray;
    5154    if (args.Length() > 1) {
  • trunk/WebCore/bindings/v8/custom/V8PopStateEventCustom.cpp

    r53586 r57207  
    3636#include "V8Proxy.h"
    3737
     38#include <v8.h>
     39
    3840namespace WebCore {
    3941
     
    4547    bool canBubbleArg = args[1]->BooleanValue();
    4648    bool cancelableArg = args[2]->BooleanValue();
    47     RefPtr<SerializedScriptValue> stateArg = SerializedScriptValue::create(args[3]);
     49
     50    bool didThrow = false;
     51    RefPtr<SerializedScriptValue> stateArg = SerializedScriptValue::create(args[3], didThrow);
     52    if (didThrow)
     53        return v8::Undefined();
    4854
    4955    PopStateEvent* event = V8PopStateEvent::toNative(args.Holder());
  • trunk/WebCore/bindings/v8/custom/V8WorkerCustom.cpp

    r55798 r57207  
    9292    INC_STATS("DOM.Worker.postMessage");
    9393    Worker* worker = V8Worker::toNative(args.Holder());
    94     RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0]);
     94    bool didThrow = false;
     95    RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0], didThrow);
     96    if (didThrow)
     97        return v8::Undefined();
    9598    MessagePortArray portArray;
    9699    if (args.Length() > 1) {
Note: See TracChangeset for help on using the changeset viewer.