[JSC/V8] Improve DOMString[] support
authortkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Jun 2012 09:59:20 +0000 (09:59 +0000)
committertkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Jun 2012 09:59:20 +0000 (09:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=89070

Reviewed by Kentaro Hara.

Tests: new test case in TestObj.idl

* bindings/js/JSDOMBinding.cpp:
(WebCore::jsArray): Implement jsArray() for DOMStringList.
* bindings/js/JSDOMBinding.h: Declare jsArray() for DOMStringList.
* bindings/scripts/CodeGeneratorJS.pm:
(NativeToJSValue): Avoid to include JSDOMString.h and DOMString.h.
* bindings/scripts/CodeGeneratorV8.pm:
(GetNativeType): Move a check for DOMString[] because it's a RefPtr type
and we'd like to avoid to generate RefPtr<DOMString[]>
(%non_wrapper_types): DOMString[] is not a wrapper type. This is needed
to avoid to generate unnecessary custom function template.
(NativeToJSValue): Avoid to include V8DOMString.h and DOMString.h.

* bindings/scripts/test/TestObj.idl: Add non-overload function using DOMString[].
* bindings/scripts/test/JS/JSTestObj.cpp: Update expectation.
* bindings/scripts/test/JS/JSTestObj.h: ditto.
* bindings/scripts/test/V8/V8TestObj.cpp: ditto.

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

Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSDOMBinding.cpp
Source/WebCore/bindings/js/JSDOMBinding.h
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/CodeGeneratorV8.pm
Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestObj.h
Source/WebCore/bindings/scripts/test/TestObj.idl
Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp

index 459c1fa..2df1c60 100644 (file)
@@ -1,3 +1,29 @@
+2012-06-14  Kent Tamura  <tkent@chromium.org>
+
+        [JSC/V8] Improve DOMString[] support
+        https://bugs.webkit.org/show_bug.cgi?id=89070
+
+        Reviewed by Kentaro Hara.
+
+        Tests: new test case in TestObj.idl
+
+        * bindings/js/JSDOMBinding.cpp:
+        (WebCore::jsArray): Implement jsArray() for DOMStringList.
+        * bindings/js/JSDOMBinding.h: Declare jsArray() for DOMStringList.
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (NativeToJSValue): Avoid to include JSDOMString.h and DOMString.h.
+        * bindings/scripts/CodeGeneratorV8.pm:
+        (GetNativeType): Move a check for DOMString[] because it's a RefPtr type
+        and we'd like to avoid to generate RefPtr<DOMString[]>
+        (%non_wrapper_types): DOMString[] is not a wrapper type. This is needed
+        to avoid to generate unnecessary custom function template.
+        (NativeToJSValue): Avoid to include V8DOMString.h and DOMString.h.
+
+        * bindings/scripts/test/TestObj.idl: Add non-overload function using DOMString[].
+        * bindings/scripts/test/JS/JSTestObj.cpp: Update expectation.
+        * bindings/scripts/test/JS/JSTestObj.h: ditto.
+        * bindings/scripts/test/V8/V8TestObj.cpp: ditto.
+
 2012-06-14  Matt Falkenhagen  <falken@chromium.org>
 
         LocaleToScriptMappingDefault.cpp should also do what scriptCodeForFontSelection does in LocaleToScriptMappingICU.cpp
index 3a6c64a..d03655e 100644 (file)
@@ -22,6 +22,7 @@
 #include "JSDOMBinding.h"
 
 #include "DOMObjectHashTableMap.h"
+#include "DOMStringList.h"
 #include "ExceptionCode.h"
 #include "ExceptionHeaders.h"
 #include "ExceptionInterfaces.h"
@@ -146,6 +147,16 @@ double valueToDate(ExecState* exec, JSValue value)
     return static_cast<DateInstance*>(value.toObject(exec))->internalNumber();
 }
 
+JSC::JSValue jsArray(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, PassRefPtr<DOMStringList> stringList)
+{
+    if (!stringList)
+        return jsNull();
+    JSC::MarkedArgumentBuffer list;
+    for (unsigned i = 0; i < stringList->length(); ++i)
+        list.append(jsString(exec, stringList->item(i)));
+    return JSC::constructArray(exec, globalObject, list);
+}
+
 void reportException(ExecState* exec, JSValue exception)
 {
     if (isTerminatedExecutionException(exception))
index 1be6310..d278a80 100644 (file)
@@ -44,6 +44,8 @@
 
 namespace WebCore {
 
+class DOMStringList;
+
 enum ParameterDefaultPolicy {
     DefaultIsUndefined,
     DefaultIsNullString
@@ -291,6 +293,8 @@ enum ParameterDefaultPolicy {
         return JSC::constructArray(exec, globalObject, list);
     }
 
+    JSC::JSValue jsArray(JSC::ExecState*, JSDOMGlobalObject*, PassRefPtr<DOMStringList>);
+
     template<>
     inline JSC::JSValue jsArray(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, const Vector<String>& iterator)
     {
index 0a86761..ec48f45 100644 (file)
@@ -3072,7 +3072,10 @@ sub NativeToJSValue
 
     my $arrayType = $codeGenerator->GetArrayType($type);
     if ($arrayType) {
-        if (!$codeGenerator->SkipIncludeHeader($arrayType)) {
+        if ($type eq "DOMString[]") {
+            AddToImplIncludes("JSDOMStringList.h", $conditional);
+            AddToImplIncludes("DOMStringList.h", $conditional);
+        } elsif (!$codeGenerator->SkipIncludeHeader($arrayType)) {
             AddToImplIncludes("JS$arrayType.h", $conditional);
             AddToImplIncludes("$arrayType.h", $conditional);
         }
index 8b92d0b..d57a585 100644 (file)
@@ -3506,6 +3506,7 @@ sub GetNativeType
     # necessary as resolvers could be constructed on fly.
     return "RefPtr<XPathNSResolver>" if $type eq "XPathNSResolver";
 
+    return "RefPtr<DOMStringList>" if $type eq "DOMString[]";
     return "RefPtr<${type}>" if IsRefPtrType($type) and not $isParameter;
 
     return "RefPtr<MediaQueryListListener>" if $type eq "MediaQueryListListener";
@@ -3514,7 +3515,6 @@ sub GetNativeType
     return "Vector<float>" if $type eq "float[]";
     return "Vector<double>" if $type eq "double[]";
     return "RefPtr<DOMStringList>" if $type eq "DOMStringList";
-    return "RefPtr<DOMStringList>" if $type eq "DOMString[]";
 
     # Default, assume native type is a pointer with same type name as idl type
     return "${type}*";
@@ -3746,6 +3746,7 @@ my %non_wrapper_types = (
     'CompareHow' => 1,
     'DOMObject' => 1,
     'DOMString' => 1,
+    'DOMString[]' => 1,
     'DOMTimeStamp' => 1,
     'Date' => 1,
     'Dictionary' => 1,
@@ -3864,7 +3865,10 @@ sub NativeToJSValue
 
     my $arrayType = $codeGenerator->GetArrayType($type);
     if ($arrayType) {
-        if (!$codeGenerator->SkipIncludeHeader($arrayType)) {
+        if ($type eq "DOMString[]") {
+            AddToImplIncludes("V8DOMStringList.h");
+            AddToImplIncludes("DOMStrignList.h");
+        } elsif (!$codeGenerator->SkipIncludeHeader($arrayType)) {
             AddToImplIncludes("V8$arrayType.h");
             AddToImplIncludes("$arrayType.h");
         }
index c89ef7a..f4a5cd8 100644 (file)
@@ -21,6 +21,7 @@
 #include "config.h"
 #include "JSTestObj.h"
 
+#include "DOMStringList.h"
 #include "Dictionary.h"
 #include "Document.h"
 #include "ExceptionCode.h"
@@ -302,6 +303,7 @@ static const HashTableValue JSTestObjPrototypeTableValues[] =
 #endif
     { "overloadedMethod", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionOverloadedMethod), (intptr_t)2, NoIntrinsic },
     { "methodWithUnsignedLongArray", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithUnsignedLongArray), (intptr_t)1, NoIntrinsic },
+    { "stringArrayFunction", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionStringArrayFunction), (intptr_t)1, NoIntrinsic },
     { "getSVGDocument", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionGetSVGDocument), (intptr_t)0, NoIntrinsic },
     { "convert1", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionConvert1), (intptr_t)1, NoIntrinsic },
     { "convert2", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionConvert2), (intptr_t)1, NoIntrinsic },
@@ -2250,6 +2252,26 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithUnsignedLongArr
     return JSValue::encode(jsUndefined());
 }
 
+EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionStringArrayFunction(ExecState* exec)
+{
+    JSValue thisValue = exec->hostThisValue();
+    if (!thisValue.inherits(&JSTestObj::s_info))
+        return throwVMTypeError(exec);
+    JSTestObj* castedThis = jsCast<JSTestObj*>(asObject(thisValue));
+    ASSERT_GC_OBJECT_INHERITS(castedThis, &JSTestObj::s_info);
+    TestObj* impl = static_cast<TestObj*>(castedThis->impl());
+    if (exec->argumentCount() < 1)
+        return throwVMError(exec, createNotEnoughArgumentsError(exec));
+    ExceptionCode ec = 0;
+    RefPtr<DOMStringList> values(toDOMStringList(exec, MAYBE_MISSING_PARAMETER(exec, 0, DefaultIsUndefined)));
+    if (exec->hadException())
+        return JSValue::encode(jsUndefined());
+
+    JSC::JSValue result = jsArray(exec, castedThis->globalObject(), impl->stringArrayFunction(values, ec));
+    setDOMException(exec, ec);
+    return JSValue::encode(result);
+}
+
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionGetSVGDocument(ExecState* exec)
 {
     JSValue thisValue = exec->hostThisValue();
index cfa7955..c74b23f 100644 (file)
@@ -204,6 +204,7 @@ JSC::EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionClassMethod2(JSC::
 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionOverloadedMethod1(JSC::ExecState*);
 #endif
 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithUnsignedLongArray(JSC::ExecState*);
+JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionStringArrayFunction(JSC::ExecState*);
 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionGetSVGDocument(JSC::ExecState*);
 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionConvert1(JSC::ExecState*);
 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionConvert2(JSC::ExecState*);
index 2bb0909..ef342f8 100644 (file)
@@ -201,6 +201,9 @@ module test {
 #if defined(TESTING_JS)
         void methodWithUnsignedLongArray(in unsigned long[] unsignedLongArray);
 #endif
+#if defined(TESTING_V8) || defined(TESTING_JS)
+        DOMString[] stringArrayFunction(in DOMString[] values) raises(DOMException);
+#endif
 
         readonly attribute [CheckSecurityForNode] Document contentDocument;
         [CheckSecurityForNode] SVGDocument getSVGDocument()
index fed7a52..90282ab 100644 (file)
@@ -22,6 +22,7 @@
 #include "V8TestObj.h"
 
 #include "ContextFeatures.h"
+#include "DOMStrignList.h"
 #include "Dictionary.h"
 #include "ExceptionCode.h"
 #include "HTMLNames.h"
@@ -38,6 +39,7 @@
 #include "V8Binding.h"
 #include "V8BindingMacros.h"
 #include "V8BindingState.h"
+#include "V8DOMStringList.h"
 #include "V8DOMWrapper.h"
 #include "V8Document.h"
 #include "V8IsolatedContext.h"
@@ -1673,6 +1675,24 @@ static v8::Handle<v8::Value> enabledAtRuntimeMethod2Callback(const v8::Arguments
     return v8::Handle<v8::Value>();
 }
 
+static v8::Handle<v8::Value> stringArrayFunctionCallback(const v8::Arguments& args)
+{
+    INC_STATS("DOM.TestObj.stringArrayFunction");
+    if (args.Length() < 1)
+        return V8Proxy::throwNotEnoughArgumentsError(args.GetIsolate());
+    TestObj* imp = V8TestObj::toNative(args.Holder());
+    ExceptionCode ec = 0;
+    {
+    EXCEPTION_BLOCK(RefPtr<DOMStringList>, values, v8ValueToWebCoreDOMStringList(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined)));
+    RefPtr<DOMStringList> result = imp->stringArrayFunction(values, ec);
+    if (UNLIKELY(ec))
+        goto fail;
+    return v8Array(result.release(), args.GetIsolate());
+    }
+    fail:
+    return V8Proxy::setDOMException(ec, args.GetIsolate());
+}
+
 static v8::Handle<v8::Value> getSVGDocumentCallback(const v8::Arguments& args)
 {
     INC_STATS("DOM.TestObj.getSVGDocument");
@@ -1949,6 +1969,7 @@ static const BatchedCallback TestObjCallbacks[] = {
     {"conditionalMethod3", TestObjV8Internal::conditionalMethod3Callback},
 #endif
     {"overloadedMethod", TestObjV8Internal::overloadedMethodCallback},
+    {"stringArrayFunction", TestObjV8Internal::stringArrayFunctionCallback},
     {"getSVGDocument", TestObjV8Internal::getSVGDocumentCallback},
     {"mutablePointFunction", TestObjV8Internal::mutablePointFunctionCallback},
     {"immutablePointFunction", TestObjV8Internal::immutablePointFunctionCallback},