Add TransferList IDL modifier, with support in V8 code gen.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Mar 2012 08:56:16 +0000 (08:56 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Mar 2012 08:56:16 +0000 (08:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=81127

Patch by Greg Billock <gbillock@google.com> on 2012-03-16
Reviewed by Adam Barth.

* bindings/scripts/CodeGeneratorV8.pm:
(GenerateFunctionCallback):
(GetIndexOf):
(GenerateParametersCheck):
(GenerateConstructorCallback):
(GenerateNamedConstructorCallback):
(GenerateFunctionCallString):
* bindings/scripts/IDLAttributes.txt:
* bindings/scripts/test/CPP/WebDOMTestSerializedScriptValueInterface.cpp:
(WebDOMTestSerializedScriptValueInterface::acceptTransferList):
* bindings/scripts/test/CPP/WebDOMTestSerializedScriptValueInterface.h:
(WebDOMTestSerializedScriptValueInterface):
* bindings/scripts/test/GObject/WebKitDOMTestSerializedScriptValueInterface.cpp:
(webkit_dom_test_serialized_script_value_interface_accept_transfer_list):
* bindings/scripts/test/GObject/WebKitDOMTestSerializedScriptValueInterface.h:
* bindings/scripts/test/JS/JSTestSerializedScriptValueInterface.cpp:
(WebCore::JSTestSerializedScriptValueInterfaceConstructor::finishCreation):
(WebCore::JSTestSerializedScriptValueInterfaceConstructor::constructJSTestSerializedScriptValueInterface):
(WebCore):
(WebCore::JSTestSerializedScriptValueInterfacePrototype::getOwnPropertySlot):
(WebCore::JSTestSerializedScriptValueInterfacePrototype::getOwnPropertyDescriptor):
(WebCore::jsTestSerializedScriptValueInterfacePrototypeFunctionAcceptTransferList):
* bindings/scripts/test/JS/JSTestSerializedScriptValueInterface.h:
(JSTestSerializedScriptValueInterfacePrototype):
(WebCore):
* bindings/scripts/test/ObjC/DOMTestSerializedScriptValueInterface.h:
* bindings/scripts/test/ObjC/DOMTestSerializedScriptValueInterface.mm:
(-[DOMTestSerializedScriptValueInterface acceptTransferList:transferList:]):
* bindings/scripts/test/TestSerializedScriptValueInterface.idl:
* bindings/scripts/test/V8/V8TestSerializedScriptValueInterface.cpp:
(WebCore::TestSerializedScriptValueInterfaceInternal::acceptTransferListCallback):
(TestSerializedScriptValueInterfaceInternal):
(WebCore):
(WebCore::V8TestSerializedScriptValueInterface::constructorCallback):
(WebCore::ConfigureV8TestSerializedScriptValueInterfaceTemplate):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@110972 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/bindings/scripts/CodeGeneratorV8.pm
Source/WebCore/bindings/scripts/IDLAttributes.txt
Source/WebCore/bindings/scripts/test/CPP/WebDOMTestSerializedScriptValueInterface.cpp
Source/WebCore/bindings/scripts/test/CPP/WebDOMTestSerializedScriptValueInterface.h
Source/WebCore/bindings/scripts/test/GObject/WebKitDOMTestSerializedScriptValueInterface.cpp
Source/WebCore/bindings/scripts/test/GObject/WebKitDOMTestSerializedScriptValueInterface.h
Source/WebCore/bindings/scripts/test/JS/JSTestSerializedScriptValueInterface.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestSerializedScriptValueInterface.h
Source/WebCore/bindings/scripts/test/ObjC/DOMTestSerializedScriptValueInterface.h
Source/WebCore/bindings/scripts/test/ObjC/DOMTestSerializedScriptValueInterface.mm
Source/WebCore/bindings/scripts/test/TestSerializedScriptValueInterface.idl
Source/WebCore/bindings/scripts/test/V8/V8TestSerializedScriptValueInterface.cpp

index 87dc08f7ba7f6febd2d66231770fd3f42649a2f1..fa348647389962004ddf469e137b8944eebb0301 100644 (file)
@@ -1,3 +1,46 @@
+2012-03-16  Greg Billock  <gbillock@google.com>
+
+        Add TransferList IDL modifier, with support in V8 code gen.
+        https://bugs.webkit.org/show_bug.cgi?id=81127
+
+        Reviewed by Adam Barth.
+
+        * bindings/scripts/CodeGeneratorV8.pm:
+        (GenerateFunctionCallback):
+        (GetIndexOf):
+        (GenerateParametersCheck):
+        (GenerateConstructorCallback):
+        (GenerateNamedConstructorCallback):
+        (GenerateFunctionCallString):
+        * bindings/scripts/IDLAttributes.txt:
+        * bindings/scripts/test/CPP/WebDOMTestSerializedScriptValueInterface.cpp:
+        (WebDOMTestSerializedScriptValueInterface::acceptTransferList):
+        * bindings/scripts/test/CPP/WebDOMTestSerializedScriptValueInterface.h:
+        (WebDOMTestSerializedScriptValueInterface):
+        * bindings/scripts/test/GObject/WebKitDOMTestSerializedScriptValueInterface.cpp:
+        (webkit_dom_test_serialized_script_value_interface_accept_transfer_list):
+        * bindings/scripts/test/GObject/WebKitDOMTestSerializedScriptValueInterface.h:
+        * bindings/scripts/test/JS/JSTestSerializedScriptValueInterface.cpp:
+        (WebCore::JSTestSerializedScriptValueInterfaceConstructor::finishCreation):
+        (WebCore::JSTestSerializedScriptValueInterfaceConstructor::constructJSTestSerializedScriptValueInterface):
+        (WebCore):
+        (WebCore::JSTestSerializedScriptValueInterfacePrototype::getOwnPropertySlot):
+        (WebCore::JSTestSerializedScriptValueInterfacePrototype::getOwnPropertyDescriptor):
+        (WebCore::jsTestSerializedScriptValueInterfacePrototypeFunctionAcceptTransferList):
+        * bindings/scripts/test/JS/JSTestSerializedScriptValueInterface.h:
+        (JSTestSerializedScriptValueInterfacePrototype):
+        (WebCore):
+        * bindings/scripts/test/ObjC/DOMTestSerializedScriptValueInterface.h:
+        * bindings/scripts/test/ObjC/DOMTestSerializedScriptValueInterface.mm:
+        (-[DOMTestSerializedScriptValueInterface acceptTransferList:transferList:]):
+        * bindings/scripts/test/TestSerializedScriptValueInterface.idl:
+        * bindings/scripts/test/V8/V8TestSerializedScriptValueInterface.cpp:
+        (WebCore::TestSerializedScriptValueInterfaceInternal::acceptTransferListCallback):
+        (TestSerializedScriptValueInterfaceInternal):
+        (WebCore):
+        (WebCore::V8TestSerializedScriptValueInterface::constructorCallback):
+        (WebCore::ConfigureV8TestSerializedScriptValueInterfaceTemplate):
+
 2012-03-16  Dana Jansens  <danakj@chromium.org>
 
         [chromium] Quads that become fully opaque after culling should not use blending
index 577efe3912536940a42219cb981db4026efe5f43..234b1bb1426ccc45ebd484340c03f9e6a7dba077 100644 (file)
@@ -1426,11 +1426,11 @@ END
 END
     }
 
-    my ($parameterCheckString, $paramIndex) = GenerateParametersCheck($function, $implClassName);
+    my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersCheck($function, $implClassName);
     push(@implContentDecls, $parameterCheckString);
 
     # Build the function call string.
-    push(@implContentDecls, GenerateFunctionCallString($function, $paramIndex, "    ", $implClassName));
+    push(@implContentDecls, GenerateFunctionCallString($function, $paramIndex, "    ", $implClassName, %replacements));
 
     if ($raisesExceptions) {
         push(@implContentDecls, "    }\n");
@@ -1511,6 +1511,20 @@ sub GenerateArgumentsCountCheck
     return $argumentsCountCheckString;
 }
 
+sub GetIndexOf
+{
+    my $paramName = shift;
+    my @paramList = @_;
+    my $index = 0;
+    foreach my $param (@paramList) {
+        if ($paramName eq $param) {
+            return $index;
+        }
+        $index++;
+    }
+    return -1;
+}
+
 sub GenerateParametersCheck
 {
     my $function = shift;
@@ -1518,6 +1532,9 @@ sub GenerateParametersCheck
 
     my $parameterCheckString = "";
     my $paramIndex = 0;
+    my @paramTransferListNames = ();
+    my %replacements = ();
+
     foreach my $parameter (@{$function->parameters}) {
         TranslateParameter($parameter);
 
@@ -1528,7 +1545,7 @@ sub GenerateParametersCheck
         my $optional = $parameter->extendedAttributes->{"Optional"};
         if ($optional && $optional ne "DefaultIsUndefined" && $optional ne "DefaultIsNullString" && !$parameter->extendedAttributes->{"Callback"}) {
             $parameterCheckString .= "    if (args.Length() <= $paramIndex) {\n";
-            my $functionCall = GenerateFunctionCallString($function, $paramIndex, "    " x 2, $implClassName);
+            my $functionCall = GenerateFunctionCallString($function, $paramIndex, "    " x 2, $implClassName, %replacements);
             $parameterCheckString .= $functionCall;
             $parameterCheckString .= "    }\n";
         }
@@ -1538,6 +1555,12 @@ sub GenerateParametersCheck
             $parameterDefaultPolicy = "DefaultIsNullString";
         }
 
+        if (GetIndexOf($parameterName, @paramTransferListNames) != -1) {
+            $replacements{$parameterName} = "messagePortArray" . ucfirst($parameterName);
+            $paramIndex++;
+            next;
+        }
+
         AddToImplIncludes("ExceptionCode.h");
         my $nativeType = GetNativeTypeFromSignature($parameter, $paramIndex);
         if ($parameter->extendedAttributes->{"Callback"}) {
@@ -1557,8 +1580,39 @@ sub GenerateParametersCheck
             }
         } elsif ($parameter->type eq "SerializedScriptValue") {
             AddToImplIncludes("SerializedScriptValue.h");
+            my $useTransferList = 0;
+            my $transferListName = "";
+            my $TransferListName = "";
+            if ($parameter->extendedAttributes->{"TransferList"}) {
+                $transferListName = $parameter->extendedAttributes->{"TransferList"};
+                push(@paramTransferListNames, $transferListName);
+
+                my @allParameterNames = ();
+                foreach my $parameter (@{$function->parameters}) {
+                    push(@allParameterNames, $parameter->name);
+                }
+                my $transferListIndex = GetIndexOf($transferListName, @allParameterNames);
+                if ($transferListIndex == -1) {
+                    die "IDL error: TransferList refers to a nonexistent argument";
+                }
+
+                AddToImplIncludes("ArrayBuffer.h");
+                AddToImplIncludes("MessagePort.h");
+                $TransferListName = ucfirst($transferListName);
+                $parameterCheckString .= "    MessagePortArray messagePortArray$TransferListName;\n";
+                $parameterCheckString .= "    ArrayBufferArray arrayBufferArray$TransferListName;\n";
+                $parameterCheckString .= "    if (args.Length() > $transferListIndex) {\n";
+                $parameterCheckString .= "        if (!extractTransferables(args[$transferListIndex], messagePortArray$TransferListName, arrayBufferArray$TransferListName))\n";
+                $parameterCheckString .= "            return throwError(\"Could not extract transferables\", V8Proxy::TypeError);\n";
+                $parameterCheckString .= "    }\n";
+                $useTransferList = 1;
+            }
             $parameterCheckString .= "    bool ${parameterName}DidThrow = false;\n";
-            $parameterCheckString .= "    $nativeType $parameterName = SerializedScriptValue::create(args[$paramIndex], 0, 0, ${parameterName}DidThrow);\n";
+            if (!$useTransferList) {
+                    $parameterCheckString .= "    $nativeType $parameterName = SerializedScriptValue::create(args[$paramIndex], 0, 0, ${parameterName}DidThrow);\n";
+            } else {
+                    $parameterCheckString .= "    $nativeType $parameterName = SerializedScriptValue::create(args[$paramIndex], &messagePortArray$TransferListName, &arrayBufferArray$TransferListName, ${parameterName}DidThrow);\n";
+            }
             $parameterCheckString .= "    if (${parameterName}DidThrow)\n";
             $parameterCheckString .= "        return v8::Undefined();\n";
         } elsif (TypeCanFailConversion($parameter)) {
@@ -1609,7 +1663,7 @@ sub GenerateParametersCheck
 
         $paramIndex++;
     }
-    return ($parameterCheckString, $paramIndex);
+    return ($parameterCheckString, $paramIndex, %replacements);
 }
 
 sub GenerateConstructorCallback
@@ -1652,7 +1706,7 @@ END
         push(@implContent, "    ExceptionCode ec = 0;\n");
     }
 
-    my ($parameterCheckString, $paramIndex) = GenerateParametersCheck($function, $implClassName);
+    my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersCheck($function, $implClassName);
     push(@implContent, $parameterCheckString);
 
     if ($dataNode->extendedAttributes->{"CallWith"} && $dataNode->extendedAttributes->{"CallWith"} eq "ScriptExecutionContext") {
@@ -1673,7 +1727,11 @@ END
     my $index = 0;
     foreach my $parameter (@{$function->parameters}) {
         last if $index eq $paramIndex;
-        push(@argumentList, $parameter->name);
+        if ($replacements{$parameter->name}) {
+            push(@argumentList, $replacements{$parameter->name});
+        } else {
+            push(@argumentList, $parameter->name);
+        }
         $index++;
     }
 
@@ -1837,7 +1895,7 @@ END
         push(@implContent, "    ExceptionCode ec = 0;\n");
     }
 
-    my ($parameterCheckString, $paramIndex) = GenerateParametersCheck($function, $implClassName);
+    my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersCheck($function, $implClassName);
     push(@implContent, $parameterCheckString);
 
     push(@beforeArgumentList, "document");
@@ -1850,7 +1908,11 @@ END
     my $index = 0;
     foreach my $parameter (@{$function->parameters}) {
         last if $index eq $paramIndex;
-        push(@argumentList, $parameter->name);
+        if ($replacements{$parameter->name}) {
+            push(@argumentList, $replacements{$parameter->name});
+        } else {
+            push(@argumentList, $parameter->name);
+        }
         $index++;
     }
 
@@ -3150,6 +3212,7 @@ sub GenerateFunctionCallString()
     my $numberOfParameters = shift;
     my $indent = shift;
     my $implClassName = shift;
+    my %replacements = @_;
 
     my $name = $function->signature->name;
     my $returnType = GetTypeFromSignature($function->signature);
@@ -3194,7 +3257,9 @@ sub GenerateFunctionCallString()
         my $paramName = $parameter->name;
         my $paramType = $parameter->type;
 
-        if ($parameter->type eq "IDBKey" || $parameter->type eq "NodeFilter" || $parameter->type eq "XPathNSResolver") {
+        if ($replacements{$paramName}) {
+            push @arguments, $replacements{$paramName};
+        } elsif ($parameter->type eq "IDBKey" || $parameter->type eq "NodeFilter" || $parameter->type eq "XPathNSResolver") {
             push @arguments, "$paramName.get()";
         } elsif ($codeGenerator->IsSVGTypeNeedingTearOff($parameter->type) and not $implClassName =~ /List$/) {
             push @arguments, "$paramName->propertyReference()";
index d105e08727de91177ef51920d71744ff790d9c98..b8764b29bd3b988cd51ebbd4bac9ea9fde11e71a 100644 (file)
@@ -97,6 +97,7 @@ ReplaceableConstructor
 ReturnNewObject
 StrictTypeChecking
 Supplemental=*
+TransferList=*
 TreatNullAs=NullString
 TreatReturnedNullStringAs=False|Null|Undefined
 TreatUndefinedAs=NullString
index 541546450a58d32736dacc755b83b628de08588e..d94df3994460189279a4622367e322434f638d97 100644 (file)
 
 #include "WebDOMTestSerializedScriptValueInterface.h"
 
+#include "Array.h"
 #include "SerializedScriptValue.h"
 #include "TestSerializedScriptValueInterface.h"
+#include "WebDOMArray.h"
 #include "WebExceptionHandler.h"
 #include <wtf/GetPtr.h>
 #include <wtf/RefPtr.h>
@@ -123,6 +125,22 @@ WebDOMString WebDOMTestSerializedScriptValueInterface::cachedReadonlyValue() con
     return impl()->cachedReadonlyValue()->toString();
 }
 
+void WebDOMTestSerializedScriptValueInterface::acceptTransferList(const WebDOMString& data, const WebDOMArray& transferList)
+{
+    if (!impl())
+        return;
+
+    impl()->acceptTransferList(WebCore::SerializedScriptValue::create(WTF::String(data)), toWebCore(transferList));
+}
+
+void WebDOMTestSerializedScriptValueInterface::multiTransferList(const WebDOMString& first, const WebDOMArray& tx, const WebDOMString& second, const WebDOMArray& txx)
+{
+    if (!impl())
+        return;
+
+    impl()->multiTransferList(WebCore::SerializedScriptValue::create(WTF::String(first)), toWebCore(tx), WebCore::SerializedScriptValue::create(WTF::String(second)), toWebCore(txx));
+}
+
 WebCore::TestSerializedScriptValueInterface* toWebCore(const WebDOMTestSerializedScriptValueInterface& wrapper)
 {
     return wrapper.impl();
index d03b75e6a767f22cfcfbf9a5d55822de71b24399..6594b8a621440a7dad5eaa5727046dc9f44f3687 100644 (file)
@@ -32,6 +32,7 @@ namespace WebCore {
 class TestSerializedScriptValueInterface;
 };
 
+class WebDOMArray;
 class WebDOMString;
 
 class WebDOMTestSerializedScriptValueInterface : public WebDOMObject {
@@ -49,6 +50,9 @@ public:
     void setCachedValue(const WebDOMString&);
     WebDOMString cachedReadonlyValue() const;
 
+    void acceptTransferList(const WebDOMString& data, const WebDOMArray& transferList);
+    void multiTransferList(const WebDOMString& first, const WebDOMArray& tx, const WebDOMString& second, const WebDOMArray& txx);
+
     WebCore::TestSerializedScriptValueInterface* impl() const;
 
 protected:
index 961c4b3a5c2f92d47364456160c8fb5806da374f..845a3737c1a12caa47a0f2a0a16d94f56b8e2030 100644 (file)
@@ -32,6 +32,8 @@
 #include "TestSerializedScriptValueInterface.h"
 #include "WebKitDOMBinding.h"
 #include "gobject/ConvertToUTF8String.h"
+#include "webkit/WebKitDOMArray.h"
+#include "webkit/WebKitDOMArrayPrivate.h"
 #include "webkit/WebKitDOMSerializedScriptValue.h"
 #include "webkit/WebKitDOMSerializedScriptValuePrivate.h"
 #include "webkit/WebKitDOMTestSerializedScriptValueInterface.h"
@@ -54,6 +56,60 @@ WebKitDOMTestSerializedScriptValueInterface* kit(WebCore::TestSerializedScriptVa
     
 } // namespace WebKit //
 
+void
+webkit_dom_test_serialized_script_value_interface_accept_transfer_list(WebKitDOMTestSerializedScriptValueInterface* self, WebKitDOMSerializedScriptValue* data, WebKitDOMArray* transfer_list)
+{
+    g_return_if_fail(self);
+    WebCore::JSMainThreadNullState state;
+    WebCore::TestSerializedScriptValueInterface * item = WebKit::core(self);
+    g_return_if_fail(data);
+    g_return_if_fail(transfer_list);
+    WebCore::SerializedScriptValue * converted_data = NULL;
+    if (data != NULL) {
+        converted_data = WebKit::core(data);
+        g_return_if_fail(converted_data);
+    }
+    WebCore::Array * converted_transfer_list = NULL;
+    if (transfer_list != NULL) {
+        converted_transfer_list = WebKit::core(transfer_list);
+        g_return_if_fail(converted_transfer_list);
+    }
+    item->acceptTransferList(converted_data, converted_transfer_list);
+}
+
+void
+webkit_dom_test_serialized_script_value_interface_multi_transfer_list(WebKitDOMTestSerializedScriptValueInterface* self, WebKitDOMSerializedScriptValue* first, WebKitDOMArray* tx, WebKitDOMSerializedScriptValue* second, WebKitDOMArray* txx)
+{
+    g_return_if_fail(self);
+    WebCore::JSMainThreadNullState state;
+    WebCore::TestSerializedScriptValueInterface * item = WebKit::core(self);
+    g_return_if_fail(first);
+    g_return_if_fail(tx);
+    g_return_if_fail(second);
+    g_return_if_fail(txx);
+    WebCore::SerializedScriptValue * converted_first = NULL;
+    if (first != NULL) {
+        converted_first = WebKit::core(first);
+        g_return_if_fail(converted_first);
+    }
+    WebCore::Array * converted_tx = NULL;
+    if (tx != NULL) {
+        converted_tx = WebKit::core(tx);
+        g_return_if_fail(converted_tx);
+    }
+    WebCore::SerializedScriptValue * converted_second = NULL;
+    if (second != NULL) {
+        converted_second = WebKit::core(second);
+        g_return_if_fail(converted_second);
+    }
+    WebCore::Array * converted_txx = NULL;
+    if (txx != NULL) {
+        converted_txx = WebKit::core(txx);
+        g_return_if_fail(converted_txx);
+    }
+    item->multiTransferList(converted_first, converted_tx, converted_second, converted_txx);
+}
+
 WebKitDOMSerializedScriptValue*
 webkit_dom_test_serialized_script_value_interface_get_value(WebKitDOMTestSerializedScriptValueInterface* self)
 {
index 516141859ce3e53cb54e4bebf3e4923cc9e4f3dc..5d15cd3309a949a8d7af7f361316d0c669173217 100644 (file)
@@ -46,6 +46,32 @@ struct _WebKitDOMTestSerializedScriptValueInterfaceClass {
 WEBKIT_API GType
 webkit_dom_test_serialized_script_value_interface_get_type (void);
 
+/**
+ * webkit_dom_test_serialized_script_value_interface_accept_transfer_list:
+ * @self: A #WebKitDOMTestSerializedScriptValueInterface
+ * @data: A #WebKitDOMSerializedScriptValue
+ * @transfer_list: A #WebKitDOMArray
+ *
+ * Returns:
+ *
+**/
+WEBKIT_API void
+webkit_dom_test_serialized_script_value_interface_accept_transfer_list(WebKitDOMTestSerializedScriptValueInterface* self, WebKitDOMSerializedScriptValue* data, WebKitDOMArray* transfer_list);
+
+/**
+ * webkit_dom_test_serialized_script_value_interface_multi_transfer_list:
+ * @self: A #WebKitDOMTestSerializedScriptValueInterface
+ * @first: A #WebKitDOMSerializedScriptValue
+ * @tx: A #WebKitDOMArray
+ * @second: A #WebKitDOMSerializedScriptValue
+ * @txx: A #WebKitDOMArray
+ *
+ * Returns:
+ *
+**/
+WEBKIT_API void
+webkit_dom_test_serialized_script_value_interface_multi_transfer_list(WebKitDOMTestSerializedScriptValueInterface* self, WebKitDOMSerializedScriptValue* first, WebKitDOMArray* tx, WebKitDOMSerializedScriptValue* second, WebKitDOMArray* txx);
+
 /**
  * webkit_dom_test_serialized_script_value_interface_get_value:
  * @self: A #WebKitDOMTestSerializedScriptValueInterface
index c0ea6eaad9e8d057a4ed575ec3bc72e14a9e0b54..ef6a7b3379fc7785a52560b9242d4d83e78a6c9d 100644 (file)
 #include "JSTestSerializedScriptValueInterface.h"
 
 #include "ExceptionCode.h"
+#include "JSArray.h"
 #include "JSDOMBinding.h"
 #include "SerializedScriptValue.h"
 #include "TestSerializedScriptValueInterface.h"
 #include <runtime/Error.h>
 #include <wtf/GetPtr.h>
 
+#if ENABLE(Condition1) || ENABLE(Condition2)
+#include ".h"
+#include "JS.h"
+#endif
+
 using namespace JSC;
 
 namespace WebCore {
@@ -69,7 +75,7 @@ void JSTestSerializedScriptValueInterfaceConstructor::finishCreation(ExecState*
     Base::finishCreation(exec->globalData());
     ASSERT(inherits(&s_info));
     putDirect(exec->globalData(), exec->propertyNames().prototype, JSTestSerializedScriptValueInterfacePrototype::self(exec, globalObject), DontDelete | ReadOnly);
-    putDirect(exec->globalData(), exec->propertyNames().length, jsNumber(2), ReadOnly | DontDelete | DontEnum);
+    putDirect(exec->globalData(), exec->propertyNames().length, jsNumber(3), ReadOnly | DontDelete | DontEnum);
 }
 
 bool JSTestSerializedScriptValueInterfaceConstructor::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
@@ -90,10 +96,21 @@ EncodedJSValue JSC_HOST_CALL JSTestSerializedScriptValueInterfaceConstructor::co
     const String& hello(ustringToString(MAYBE_MISSING_PARAMETER(exec, 0, DefaultIsUndefined).isEmpty() ? UString() : MAYBE_MISSING_PARAMETER(exec, 0, DefaultIsUndefined).toString(exec)->value(exec)));
     if (exec->hadException())
         return JSValue::encode(jsUndefined());
-    RefPtr<SerializedScriptValue> value(SerializedScriptValue::create(exec, MAYBE_MISSING_PARAMETER(exec, 1, DefaultIsUndefined)));
+    RefPtr<SerializedScriptValue> data(SerializedScriptValue::create(exec, MAYBE_MISSING_PARAMETER(exec, 1, DefaultIsUndefined)));
+    if (exec->hadException())
+        return JSValue::encode(jsUndefined());
+
+    size_t argsCount = exec->argumentCount();
+    if (argsCount <= 2) {
+
+        JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl->constructorCallback(hello, data)));
+        return JSValue::encode(result);
+    }
+
+    Array* transferList(toArray(MAYBE_MISSING_PARAMETER(exec, 2, DefaultIsUndefined)));
     if (exec->hadException())
         return JSValue::encode(jsUndefined());
-    RefPtr<TestSerializedScriptValueInterface> object = TestSerializedScriptValueInterface::create(hello, value);
+    RefPtr<TestSerializedScriptValueInterface> object = TestSerializedScriptValueInterface::create(hello, data, transferList);
     return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), object.get())));
 }
 
@@ -107,10 +124,12 @@ ConstructType JSTestSerializedScriptValueInterfaceConstructor::getConstructData(
 
 static const HashTableValue JSTestSerializedScriptValueInterfacePrototypeTableValues[] =
 {
+    { "acceptTransferList", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsTestSerializedScriptValueInterfacePrototypeFunctionAcceptTransferList), (intptr_t)2, NoIntrinsic },
+    { "multiTransferList", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsTestSerializedScriptValueInterfacePrototypeFunctionMultiTransferList), (intptr_t)4, NoIntrinsic },
     { 0, 0, 0, 0, NoIntrinsic }
 };
 
-static const HashTable JSTestSerializedScriptValueInterfacePrototypeTable = { 1, 0, JSTestSerializedScriptValueInterfacePrototypeTableValues, 0 };
+static const HashTable JSTestSerializedScriptValueInterfacePrototypeTable = { 5, 3, JSTestSerializedScriptValueInterfacePrototypeTableValues, 0 };
 const ClassInfo JSTestSerializedScriptValueInterfacePrototype::s_info = { "TestSerializedScriptValueInterfacePrototype", &Base::s_info, &JSTestSerializedScriptValueInterfacePrototypeTable, 0, CREATE_METHOD_TABLE(JSTestSerializedScriptValueInterfacePrototype) };
 
 JSObject* JSTestSerializedScriptValueInterfacePrototype::self(ExecState* exec, JSGlobalObject* globalObject)
@@ -118,6 +137,18 @@ JSObject* JSTestSerializedScriptValueInterfacePrototype::self(ExecState* exec, J
     return getDOMPrototype<JSTestSerializedScriptValueInterface>(exec, globalObject);
 }
 
+bool JSTestSerializedScriptValueInterfacePrototype::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+    JSTestSerializedScriptValueInterfacePrototype* thisObject = jsCast<JSTestSerializedScriptValueInterfacePrototype*>(cell);
+    return getStaticFunctionSlot<JSObject>(exec, &JSTestSerializedScriptValueInterfacePrototypeTable, thisObject, propertyName, slot);
+}
+
+bool JSTestSerializedScriptValueInterfacePrototype::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
+{
+    JSTestSerializedScriptValueInterfacePrototype* thisObject = jsCast<JSTestSerializedScriptValueInterfacePrototype*>(object);
+    return getStaticFunctionDescriptor<JSObject>(exec, &JSTestSerializedScriptValueInterfacePrototypeTable, thisObject, propertyName, descriptor);
+}
+
 const ClassInfo JSTestSerializedScriptValueInterface::s_info = { "TestSerializedScriptValueInterface", &Base::s_info, &JSTestSerializedScriptValueInterfaceTable, 0 , CREATE_METHOD_TABLE(JSTestSerializedScriptValueInterface) };
 
 JSTestSerializedScriptValueInterface::JSTestSerializedScriptValueInterface(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<TestSerializedScriptValueInterface> impl)
@@ -242,6 +273,79 @@ JSValue JSTestSerializedScriptValueInterface::getConstructor(ExecState* exec, JS
     return getDOMConstructor<JSTestSerializedScriptValueInterfaceConstructor>(exec, static_cast<JSDOMGlobalObject*>(globalObject));
 }
 
+EncodedJSValue JSC_HOST_CALL jsTestSerializedScriptValueInterfacePrototypeFunctionAcceptTransferList(ExecState* exec)
+{
+    JSValue thisValue = exec->hostThisValue();
+    if (!thisValue.inherits(&JSTestSerializedScriptValueInterface::s_info))
+        return throwVMTypeError(exec);
+    JSTestSerializedScriptValueInterface* castedThis = static_cast<JSTestSerializedScriptValueInterface*>(asObject(thisValue));
+    ASSERT_GC_OBJECT_INHERITS(castedThis, &JSTestSerializedScriptValueInterface::s_info);
+    TestSerializedScriptValueInterface* impl = static_cast<TestSerializedScriptValueInterface*>(castedThis->impl());
+    if (exec->argumentCount() < 1)
+        return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
+    RefPtr<SerializedScriptValue> data(SerializedScriptValue::create(exec, MAYBE_MISSING_PARAMETER(exec, 0, DefaultIsUndefined)));
+    if (exec->hadException())
+        return JSValue::encode(jsUndefined());
+
+    size_t argsCount = exec->argumentCount();
+    if (argsCount <= 1) {
+        impl->acceptTransferList(data);
+        return JSValue::encode(jsUndefined());
+    }
+
+    Array* transferList(toArray(MAYBE_MISSING_PARAMETER(exec, 1, DefaultIsUndefined)));
+    if (exec->hadException())
+        return JSValue::encode(jsUndefined());
+    impl->acceptTransferList(data, transferList);
+    return JSValue::encode(jsUndefined());
+}
+
+EncodedJSValue JSC_HOST_CALL jsTestSerializedScriptValueInterfacePrototypeFunctionMultiTransferList(ExecState* exec)
+{
+    JSValue thisValue = exec->hostThisValue();
+    if (!thisValue.inherits(&JSTestSerializedScriptValueInterface::s_info))
+        return throwVMTypeError(exec);
+    JSTestSerializedScriptValueInterface* castedThis = static_cast<JSTestSerializedScriptValueInterface*>(asObject(thisValue));
+    ASSERT_GC_OBJECT_INHERITS(castedThis, &JSTestSerializedScriptValueInterface::s_info);
+    TestSerializedScriptValueInterface* impl = static_cast<TestSerializedScriptValueInterface*>(castedThis->impl());
+
+    size_t argsCount = exec->argumentCount();
+    if (argsCount <= 0) {
+        impl->multiTransferList();
+        return JSValue::encode(jsUndefined());
+    }
+
+    RefPtr<SerializedScriptValue> first(SerializedScriptValue::create(exec, MAYBE_MISSING_PARAMETER(exec, 0, DefaultIsUndefined)));
+    if (exec->hadException())
+        return JSValue::encode(jsUndefined());
+    if (argsCount <= 1) {
+        impl->multiTransferList(first);
+        return JSValue::encode(jsUndefined());
+    }
+
+    Array* tx(toArray(MAYBE_MISSING_PARAMETER(exec, 1, DefaultIsUndefined)));
+    if (exec->hadException())
+        return JSValue::encode(jsUndefined());
+    if (argsCount <= 2) {
+        impl->multiTransferList(first, tx);
+        return JSValue::encode(jsUndefined());
+    }
+
+    RefPtr<SerializedScriptValue> second(SerializedScriptValue::create(exec, MAYBE_MISSING_PARAMETER(exec, 2, DefaultIsUndefined)));
+    if (exec->hadException())
+        return JSValue::encode(jsUndefined());
+    if (argsCount <= 3) {
+        impl->multiTransferList(first, tx, second);
+        return JSValue::encode(jsUndefined());
+    }
+
+    Array* txx(toArray(MAYBE_MISSING_PARAMETER(exec, 3, DefaultIsUndefined)));
+    if (exec->hadException())
+        return JSValue::encode(jsUndefined());
+    impl->multiTransferList(first, tx, second, txx);
+    return JSValue::encode(jsUndefined());
+}
+
 void JSTestSerializedScriptValueInterface::visitChildren(JSCell* cell, SlotVisitor& visitor)
 {
     JSTestSerializedScriptValueInterface* thisObject = jsCast<JSTestSerializedScriptValueInterface*>(cell);
index c944e42a3a51fdbdca87b5edfb6ad9ef1a9f1aef..ad44b57a7978b542e4f6cbb4d2a79f7084c8e18b 100644 (file)
@@ -103,6 +103,8 @@ public:
     }
 
     static const JSC::ClassInfo s_info;
+    static bool getOwnPropertySlot(JSC::JSCell*, JSC::ExecState*, const JSC::Identifier&, JSC::PropertySlot&);
+    static bool getOwnPropertyDescriptor(JSC::JSObject*, JSC::ExecState*, const JSC::Identifier&, JSC::PropertyDescriptor&);
     static JSC::Structure* createStructure(JSC::JSGlobalData& globalData, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
     {
         return JSC::Structure::create(globalData, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), &s_info);
@@ -111,7 +113,7 @@ public:
 private:
     JSTestSerializedScriptValueInterfacePrototype(JSC::JSGlobalData& globalData, JSC::JSGlobalObject*, JSC::Structure* structure) : JSC::JSNonFinalObject(globalData, structure) { }
 protected:
-    static const unsigned StructureFlags = JSC::OverridesVisitChildren | Base::StructureFlags;
+    static const unsigned StructureFlags = JSC::OverridesGetOwnPropertySlot | JSC::OverridesVisitChildren | Base::StructureFlags;
 };
 
 class JSTestSerializedScriptValueInterfaceConstructor : public DOMConstructorObject {
@@ -141,6 +143,10 @@ protected:
     static JSC::ConstructType getConstructData(JSC::JSCell*, JSC::ConstructData&);
 };
 
+// Functions
+
+JSC::EncodedJSValue JSC_HOST_CALL jsTestSerializedScriptValueInterfacePrototypeFunctionAcceptTransferList(JSC::ExecState*);
+JSC::EncodedJSValue JSC_HOST_CALL jsTestSerializedScriptValueInterfacePrototypeFunctionMultiTransferList(JSC::ExecState*);
 // Attributes
 
 JSC::JSValue jsTestSerializedScriptValueInterfaceValue(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);
index b5f3a17c95b251121b5951db7bca5bed4499b7ce..ce521d14545a4d1bea924bd285c9f78678752f86 100644 (file)
@@ -28,6 +28,7 @@
 
 #if WEBKIT_VERSION_MAX_ALLOWED >= WEBKIT_VERSION_LATEST
 
+@class DOMArray;
 @class NSString;
 
 @interface DOMTestSerializedScriptValueInterface : DOMObject
@@ -37,6 +38,8 @@
 - (NSString *)cachedValue;
 - (void)setCachedValue:(NSString *)newCachedValue;
 - (NSString *)cachedReadonlyValue;
+- (void)acceptTransferList:(NSString *)data transferList:(DOMArray *)transferList;
+- (void)multiTransferList:(NSString *)first tx:(DOMArray *)tx second:(NSString *)second txx:(DOMArray *)txx;
 @end
 
 #endif
index 388f1c56d7cb282e79de30c971f8cc0557aff110..168f096b9467f0055040f7ae840a495d571b1806 100644 (file)
@@ -32,6 +32,8 @@
 
 #import "DOMTestSerializedScriptValueInterface.h"
 
+#import "Array.h"
+#import "DOMArrayInternal.h"
 #import "DOMBlobInternal.h"
 #import "DOMCSSRuleInternal.h"
 #import "DOMCSSValueInternal.h"
     return IMPL->cachedReadonlyValue()->toString();
 }
 
+- (void)acceptTransferList:(NSString *)data transferList:(DOMArray *)transferList
+{
+    WebCore::JSMainThreadNullState state;
+    IMPL->acceptTransferList(WebCore::SerializedScriptValue::create(WTF::String(data)), core(transferList));
+}
+
+- (void)multiTransferList:(NSString *)first tx:(DOMArray *)tx second:(NSString *)second txx:(DOMArray *)txx
+{
+    WebCore::JSMainThreadNullState state;
+    IMPL->multiTransferList(WebCore::SerializedScriptValue::create(WTF::String(first)), core(tx), WebCore::SerializedScriptValue::create(WTF::String(second)), core(txx));
+}
+
 @end
 
 WebCore::TestSerializedScriptValueInterface* core(DOMTestSerializedScriptValueInterface *wrapper)
index dddee9fae64dec3f09692720b730632aa1694c96..7e954d50f8f6b1dcb0e3e3b1e51151bf1eb11f3d 100644 (file)
@@ -29,10 +29,13 @@ module test {
     interface [
         Conditional=Condition1|Condition2,
         Constructor(in DOMString hello, in SerializedScriptValue value),
+        Constructor(in DOMString hello, in [TransferList=transferList] SerializedScriptValue data, in [Optional] Array transferList),
     ] TestSerializedScriptValueInterface {
         attribute SerializedScriptValue value;
         readonly attribute SerializedScriptValue readonlyValue;
         attribute [CachedAttribute] SerializedScriptValue cachedValue;
         readonly attribute [CachedAttribute] SerializedScriptValue cachedReadonlyValue;
+        void acceptTransferList(in [TransferList=transferList] SerializedScriptValue data, in [Optional] Array transferList);
+        void multiTransferList(in [Optional, TransferList=tx] SerializedScriptValue first, in [Optional] Array tx, in [Optional, TransferList=txx] SerializedScriptValue second, in [Optional] Array txx);
     };
 }
index f329ab0f33545f224b48b62d64085cd9524605ec..e2a68c3b92930071973f535298be4ee2c21dfbed 100644 (file)
 
 #if ENABLE(Condition1) || ENABLE(Condition2)
 
+#include "ArrayBuffer.h"
 #include "ExceptionCode.h"
+#include "MessagePort.h"
 #include "RuntimeEnabledFeatures.h"
 #include "SerializedScriptValue.h"
+#include "V8.h"
 #include "V8Binding.h"
 #include "V8BindingMacros.h"
 #include "V8BindingState.h"
 #include "V8DOMWrapper.h"
 #include "V8IsolatedContext.h"
 #include "V8Proxy.h"
+#include <wtf/GetPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
 #include <wtf/UnusedParam.h>
 
 namespace WebCore {
@@ -103,6 +109,74 @@ static v8::Handle<v8::Value> cachedReadonlyValueAttrGetter(v8::Local<v8::String>
     return value;
 }
 
+static v8::Handle<v8::Value> acceptTransferListCallback(const v8::Arguments& args)
+{
+    INC_STATS("DOM.TestSerializedScriptValueInterface.acceptTransferList");
+    if (args.Length() < 1)
+        return throwError("Not enough arguments", V8Proxy::TypeError);
+    TestSerializedScriptValueInterface* imp = V8TestSerializedScriptValueInterface::toNative(args.Holder());
+    MessagePortArray messagePortArrayTransferList;
+    ArrayBufferArray arrayBufferArrayTransferList;
+    if (args.Length() > 1) {
+        if (!extractTransferables(args[1], messagePortArrayTransferList, arrayBufferArrayTransferList))
+            return throwError("Could not extract transferables", V8Proxy::TypeError);
+    }
+    bool dataDidThrow = false;
+    RefPtr<SerializedScriptValue> data = SerializedScriptValue::create(args[0], &messagePortArrayTransferList, &arrayBufferArrayTransferList, dataDidThrow);
+    if (dataDidThrow)
+        return v8::Undefined();
+    if (args.Length() <= 1) {
+        imp->acceptTransferList(data);
+        return v8::Handle<v8::Value>();
+    }
+    imp->acceptTransferList(data, messagePortArrayTransferList);
+    return v8::Handle<v8::Value>();
+}
+
+static v8::Handle<v8::Value> multiTransferListCallback(const v8::Arguments& args)
+{
+    INC_STATS("DOM.TestSerializedScriptValueInterface.multiTransferList");
+    TestSerializedScriptValueInterface* imp = V8TestSerializedScriptValueInterface::toNative(args.Holder());
+    if (args.Length() <= 0) {
+        imp->multiTransferList();
+        return v8::Handle<v8::Value>();
+    }
+    MessagePortArray messagePortArrayTx;
+    ArrayBufferArray arrayBufferArrayTx;
+    if (args.Length() > 1) {
+        if (!extractTransferables(args[1], messagePortArrayTx, arrayBufferArrayTx))
+            return throwError("Could not extract transferables", V8Proxy::TypeError);
+    }
+    bool firstDidThrow = false;
+    RefPtr<SerializedScriptValue> first = SerializedScriptValue::create(args[0], &messagePortArrayTx, &arrayBufferArrayTx, firstDidThrow);
+    if (firstDidThrow)
+        return v8::Undefined();
+    if (args.Length() <= 1) {
+        imp->multiTransferList(first);
+        return v8::Handle<v8::Value>();
+    }
+    if (args.Length() <= 2) {
+        imp->multiTransferList(first, messagePortArrayTx);
+        return v8::Handle<v8::Value>();
+    }
+    MessagePortArray messagePortArrayTxx;
+    ArrayBufferArray arrayBufferArrayTxx;
+    if (args.Length() > 3) {
+        if (!extractTransferables(args[3], messagePortArrayTxx, arrayBufferArrayTxx))
+            return throwError("Could not extract transferables", V8Proxy::TypeError);
+    }
+    bool secondDidThrow = false;
+    RefPtr<SerializedScriptValue> second = SerializedScriptValue::create(args[2], &messagePortArrayTxx, &arrayBufferArrayTxx, secondDidThrow);
+    if (secondDidThrow)
+        return v8::Undefined();
+    if (args.Length() <= 3) {
+        imp->multiTransferList(first, messagePortArrayTx, second);
+        return v8::Handle<v8::Value>();
+    }
+    imp->multiTransferList(first, messagePortArrayTx, second, messagePortArrayTxx);
+    return v8::Handle<v8::Value>();
+}
+
 } // namespace TestSerializedScriptValueInterfaceInternal
 
 static const BatchedAttribute TestSerializedScriptValueInterfaceAttrs[] = {
@@ -116,6 +190,11 @@ static const BatchedAttribute TestSerializedScriptValueInterfaceAttrs[] = {
     {"cachedReadonlyValue", TestSerializedScriptValueInterfaceInternal::cachedReadonlyValueAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
 };
 
+static const BatchedCallback TestSerializedScriptValueInterfaceCallbacks[] = {
+    {"acceptTransferList", TestSerializedScriptValueInterfaceInternal::acceptTransferListCallback},
+    {"multiTransferList", TestSerializedScriptValueInterfaceInternal::multiTransferListCallback},
+};
+
 v8::Handle<v8::Value> V8TestSerializedScriptValueInterface::constructorCallback(const v8::Arguments& args)
 {
     INC_STATS("DOM.TestSerializedScriptValueInterface.Constructor");
@@ -128,12 +207,21 @@ v8::Handle<v8::Value> V8TestSerializedScriptValueInterface::constructorCallback(
     if (args.Length() < 2)
         return throwError("Not enough arguments", V8Proxy::TypeError);
     STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, hello, MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined));
-    bool valueDidThrow = false;
-    RefPtr<SerializedScriptValue> value = SerializedScriptValue::create(args[1], 0, 0, valueDidThrow);
-    if (valueDidThrow)
+    MessagePortArray messagePortArrayTransferList;
+    ArrayBufferArray arrayBufferArrayTransferList;
+    if (args.Length() > 2) {
+        if (!extractTransferables(args[2], messagePortArrayTransferList, arrayBufferArrayTransferList))
+            return throwError("Could not extract transferables", V8Proxy::TypeError);
+    }
+    bool dataDidThrow = false;
+    RefPtr<SerializedScriptValue> data = SerializedScriptValue::create(args[1], &messagePortArrayTransferList, &arrayBufferArrayTransferList, dataDidThrow);
+    if (dataDidThrow)
         return v8::Undefined();
+    if (args.Length() <= 2) {
+        return toV8(imp->Constructor(hello, data));
+    }
 
-    RefPtr<TestSerializedScriptValueInterface> impl = TestSerializedScriptValueInterface::create(hello, value);
+    RefPtr<TestSerializedScriptValueInterface> impl = TestSerializedScriptValueInterface::create(hello, data, messagePortArrayTransferList);
     v8::Handle<v8::Object> wrapper = args.Holder();
 
     V8DOMWrapper::setDOMWrapper(wrapper, &info, impl.get());
@@ -149,9 +237,13 @@ static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestSerializedScriptValue
     v8::Local<v8::Signature> defaultSignature;
     defaultSignature = configureTemplate(desc, "TestSerializedScriptValueInterface", v8::Persistent<v8::FunctionTemplate>(), V8TestSerializedScriptValueInterface::internalFieldCount,
         TestSerializedScriptValueInterfaceAttrs, WTF_ARRAY_LENGTH(TestSerializedScriptValueInterfaceAttrs),
-        0, 0);
+        TestSerializedScriptValueInterfaceCallbacks, WTF_ARRAY_LENGTH(TestSerializedScriptValueInterfaceCallbacks));
     UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
     desc->SetCallHandler(V8TestSerializedScriptValueInterface::constructorCallback);
+    v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
+    v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate();
+    UNUSED_PARAM(instance); // In some cases, it will not be used.
+    UNUSED_PARAM(proto); // In some cases, it will not be used.
     
 
     // Custom toString template