Changeset 206956 in webkit


Ignore:
Timestamp:
Oct 8, 2016 12:07:14 PM (8 years ago)
Author:
weinig@apple.com
Message:

Autogenerate passing union types as part of a functions variadic arguments
https://bugs.webkit.org/show_bug.cgi?id=162919

Reviewed by Darin Adler.

  • CMakeLists.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/JSBindingsAllInOne.cpp:

Remove deleted files.

  • bindings/generic/IDLTypes.h:

Switch to use std::reference_wrapper as it's implementation type. We may need more
granularity here in the future, but this will work for now.

  • bindings/js/JSCharacterDataCustom.cpp: Removed.
  • bindings/js/JSDocumentTypeCustom.cpp: Removed.
  • bindings/js/JSNodeOrString.cpp: Removed.
  • bindings/js/JSNodeOrString.h: Removed.
  • bindings/js/JSDOMBinding.h:

(WebCore::VariadicHelperBase::convert): Deleted.
(WebCore::toArguments): Deleted.
Moved to JSDOMConvert.h and renamed to convertVariadicArguments and make
it work in terms of IDLTypes.

  • bindings/js/JSDOMConvert.h:

(WebCore::Converter<IDLInterface<T>>::convert):
(WebCore::VariadicConverterBase::convert):
(WebCore::VariadicConverterBase<IDLInterface<T>>::convert):
(WebCore::convertVariadicArguments):

  • bindings/js/JSDocumentCustom.cpp:

(WebCore::JSDocument::prepend): Deleted.
(WebCore::JSDocument::append): Deleted.

  • bindings/js/JSDocumentFragmentCustom.cpp:

(WebCore::JSDocumentFragment::prepend): Deleted.
(WebCore::JSDocumentFragment::append): Deleted.

  • bindings/js/JSElementCustom.cpp:

(WebCore::JSElement::before): Deleted.
(WebCore::JSElement::after): Deleted.
(WebCore::JSElement::replaceWith): Deleted.
(WebCore::JSElement::prepend): Deleted.
(WebCore::JSElement::append): Deleted.
Remove now generated functions.

  • bindings/scripts/CodeGenerator.pm:

(assert):
Add assert to help debugging.

(ParseInterface):
Don't treat union types as interfaces.

(GetFlattenedMemberTypes):
(GetNumberOfNullableMemberTypes):
(GetIDLUnionMemberTypes):
Implement WebIDL algorithms for getting the flattened member list of union, and use it
to construct the c++ IDLType.

(GetBaseIDLType):
(GetIDLType):
Add helper to convert an parsed idlType to a c++ IDLType.

(IsWrapperType):
Don't treat union types as wrappers.

  • bindings/scripts/CodeGeneratorJS.pm:

(AddToImplIncludesForIDLType):
Add helper for adding #includes based on a parsed idlType. It recursively handles union types.

(GenerateParametersCheck):
Use the new convertVariadicArguments function to handle all variadic arguments, including
union types.

  • bindings/scripts/IDLParser.pm:

(parseDictionaryMember):
(parseAttributeRest):
(parseOptionalOrRequiredArgument):
(parseExceptionField):
Add an idlType to domSignature and populate it.

  • bindings/scripts/test/JS/JSTestObj.cpp:

(WebCore::jsTestObjPrototypeFunctionOverloadedMethod13):
(WebCore::jsTestObjPrototypeFunctionVariadicStringMethod):
(WebCore::jsTestObjPrototypeFunctionVariadicDoubleMethod):
(WebCore::jsTestObjPrototypeFunctionVariadicNodeMethod):
(WebCore::jsTestObjPrototypeFunctionVariadicUnionMethod):

  • bindings/scripts/test/JS/JSTestOverloadedConstructors.cpp:

(WebCore::constructJSTestOverloadedConstructors5):

  • bindings/scripts/test/TestObj.idl:

Add and update tests.

  • dom/ChildNode.idl:
  • dom/ParentNode.idl:

Remove Custom extended attribute.

  • dom/ContainerNode.cpp:
  • dom/ContainerNode.h:
  • dom/Node.cpp:
  • dom/Node.h:

Switch to using std::reference_wrapper instead of Ref<> for passed in parameters.

Location:
trunk/Source/WebCore
Files:
4 deleted
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r206917 r206956  
    10691069    bindings/js/JSCallbackData.cpp
    10701070    bindings/js/JSCanvasRenderingContext2DCustom.cpp
    1071     bindings/js/JSCharacterDataCustom.cpp
    10721071    bindings/js/JSClientRectCustom.cpp
    10731072    bindings/js/JSCommandLineAPIHostCustom.cpp
     
    11061105    bindings/js/JSDocumentCustom.cpp
    11071106    bindings/js/JSDocumentFragmentCustom.cpp
    1108     bindings/js/JSDocumentTypeCustom.cpp
    11091107    bindings/js/JSElementCustom.cpp
    11101108    bindings/js/JSErrorEventCustom.cpp
     
    11591157    bindings/js/JSNodeFilterCustom.cpp
    11601158    bindings/js/JSNodeIteratorCustom.cpp
    1161     bindings/js/JSNodeOrString.cpp
    11621159    bindings/js/JSNodeListCustom.cpp
    11631160    bindings/js/JSPerformanceEntryCustom.cpp
  • trunk/Source/WebCore/ChangeLog

    r206954 r206956  
     12016-10-06  Sam Weinig  <sam@webkit.org>
     2
     3        Autogenerate passing union types as part of a functions variadic arguments
     4        https://bugs.webkit.org/show_bug.cgi?id=162919
     5
     6        Reviewed by Darin Adler.
     7
     8        * CMakeLists.txt:
     9        * WebCore.xcodeproj/project.pbxproj:
     10        * bindings/js/JSBindingsAllInOne.cpp:
     11        Remove deleted files.
     12
     13        * bindings/generic/IDLTypes.h:
     14        Switch to use std::reference_wrapper as it's implementation type. We may need more
     15        granularity here in the future, but this will work for now.
     16
     17        * bindings/js/JSCharacterDataCustom.cpp: Removed.
     18        * bindings/js/JSDocumentTypeCustom.cpp: Removed.
     19        * bindings/js/JSNodeOrString.cpp: Removed.
     20        * bindings/js/JSNodeOrString.h: Removed.
     21
     22        * bindings/js/JSDOMBinding.h:
     23        (WebCore::VariadicHelperBase::convert): Deleted.
     24        (WebCore::toArguments): Deleted.
     25        Moved to JSDOMConvert.h and renamed to convertVariadicArguments and make
     26        it work in terms of IDLTypes.
     27
     28        * bindings/js/JSDOMConvert.h:
     29        (WebCore::Converter<IDLInterface<T>>::convert):
     30        (WebCore::VariadicConverterBase::convert):
     31        (WebCore::VariadicConverterBase<IDLInterface<T>>::convert):
     32        (WebCore::convertVariadicArguments):
     33
     34        * bindings/js/JSDocumentCustom.cpp:
     35        (WebCore::JSDocument::prepend): Deleted.
     36        (WebCore::JSDocument::append): Deleted.
     37        * bindings/js/JSDocumentFragmentCustom.cpp:
     38        (WebCore::JSDocumentFragment::prepend): Deleted.
     39        (WebCore::JSDocumentFragment::append): Deleted.
     40        * bindings/js/JSElementCustom.cpp:
     41        (WebCore::JSElement::before): Deleted.
     42        (WebCore::JSElement::after): Deleted.
     43        (WebCore::JSElement::replaceWith): Deleted.
     44        (WebCore::JSElement::prepend): Deleted.
     45        (WebCore::JSElement::append): Deleted.
     46        Remove now generated functions.
     47
     48        * bindings/scripts/CodeGenerator.pm:
     49        (assert):
     50        Add assert to help debugging.
     51
     52        (ParseInterface):
     53        Don't treat union types as interfaces.
     54
     55        (GetFlattenedMemberTypes):
     56        (GetNumberOfNullableMemberTypes):
     57        (GetIDLUnionMemberTypes):
     58        Implement WebIDL algorithms for getting the flattened member list of union, and use it
     59        to construct the c++ IDLType.
     60
     61        (GetBaseIDLType):
     62        (GetIDLType):
     63        Add helper to convert an parsed idlType to a c++ IDLType.
     64
     65        (IsWrapperType):
     66        Don't treat union types as wrappers.
     67       
     68        * bindings/scripts/CodeGeneratorJS.pm:
     69        (AddToImplIncludesForIDLType):
     70        Add helper for adding #includes based on a parsed idlType. It recursively handles union types.
     71
     72        (GenerateParametersCheck):
     73        Use the new convertVariadicArguments function to handle all variadic arguments, including
     74        union types.
     75
     76        * bindings/scripts/IDLParser.pm:
     77        (parseDictionaryMember):
     78        (parseAttributeRest):
     79        (parseOptionalOrRequiredArgument):
     80        (parseExceptionField):
     81        Add an idlType to domSignature and populate it.
     82
     83        * bindings/scripts/test/JS/JSTestObj.cpp:
     84        (WebCore::jsTestObjPrototypeFunctionOverloadedMethod13):
     85        (WebCore::jsTestObjPrototypeFunctionVariadicStringMethod):
     86        (WebCore::jsTestObjPrototypeFunctionVariadicDoubleMethod):
     87        (WebCore::jsTestObjPrototypeFunctionVariadicNodeMethod):
     88        (WebCore::jsTestObjPrototypeFunctionVariadicUnionMethod):
     89        * bindings/scripts/test/JS/JSTestOverloadedConstructors.cpp:
     90        (WebCore::constructJSTestOverloadedConstructors5):
     91        * bindings/scripts/test/TestObj.idl:
     92        Add and update tests.
     93
     94        * dom/ChildNode.idl:
     95        * dom/ParentNode.idl:
     96        Remove Custom extended attribute.
     97
     98        * dom/ContainerNode.cpp:
     99        * dom/ContainerNode.h:
     100        * dom/Node.cpp:
     101        * dom/Node.h:
     102        Switch to using std::reference_wrapper instead of Ref<> for passed in parameters.
     103
    11042016-10-08  Youenn Fablet  <youenn@apple.com>
    2105
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r206917 r206956  
    27382738                7C2BDD3D17C7F98C0038FF15 /* JSDOMGlobalObjectTask.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C2BDD3B17C7F98B0038FF15 /* JSDOMGlobalObjectTask.cpp */; };
    27392739                7C2BDD3E17C7F98C0038FF15 /* JSDOMGlobalObjectTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C2BDD3C17C7F98B0038FF15 /* JSDOMGlobalObjectTask.h */; };
    2740                 7C33F35A1B4A044800502CAF /* JSCharacterDataCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C33F3581B4A044800502CAF /* JSCharacterDataCustom.cpp */; };
    2741                 7C33F35E1B4A04CE00502CAF /* JSDocumentTypeCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C33F35C1B4A04CE00502CAF /* JSDocumentTypeCustom.cpp */; };
    27422740                7C33F3621B4A050400502CAF /* JSDocumentFragmentCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C33F3601B4A050400502CAF /* JSDocumentFragmentCustom.cpp */; };
    27432741                7C3A91E61C963B8800D1A7E3 /* ClipboardAccessPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C3A91E51C963B8800D1A7E3 /* ClipboardAccessPolicy.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    27732771                7C7941E51C56C29300A4C58E /* DataDetectorsCoreSoftLink.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C7941E31C56C29300A4C58E /* DataDetectorsCoreSoftLink.h */; };
    27742772                7C83DE861D04CC5D00FEBCF3 /* SpringSolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C83DE851D04CBD400FEBCF3 /* SpringSolver.h */; };
    2775                 7C91A38F1B498ABE003F9EFA /* JSNodeOrString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C91A38D1B498ABE003F9EFA /* JSNodeOrString.cpp */; };
    2776                 7C91A3901B498ABE003F9EFA /* JSNodeOrString.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C91A38E1B498ABE003F9EFA /* JSNodeOrString.h */; };
    27772773                7C93F3491AA6BA5E00A98BAB /* CompiledContentExtension.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C93F3471AA6BA5E00A98BAB /* CompiledContentExtension.cpp */; };
    27782774                7C93F34A1AA6BA5E00A98BAB /* CompiledContentExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C93F3481AA6BA5E00A98BAB /* CompiledContentExtension.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    98509846                7C2BDD3B17C7F98B0038FF15 /* JSDOMGlobalObjectTask.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMGlobalObjectTask.cpp; sourceTree = "<group>"; };
    98519847                7C2BDD3C17C7F98B0038FF15 /* JSDOMGlobalObjectTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMGlobalObjectTask.h; sourceTree = "<group>"; };
    9852                 7C33F3581B4A044800502CAF /* JSCharacterDataCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCharacterDataCustom.cpp; sourceTree = "<group>"; };
    9853                 7C33F35C1B4A04CE00502CAF /* JSDocumentTypeCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDocumentTypeCustom.cpp; sourceTree = "<group>"; };
    98549848                7C33F3601B4A050400502CAF /* JSDocumentFragmentCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDocumentFragmentCustom.cpp; sourceTree = "<group>"; };
    98559849                7C3A91E51C963B8800D1A7E3 /* ClipboardAccessPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClipboardAccessPolicy.h; sourceTree = "<group>"; };
     
    98979891                7C7941E31C56C29300A4C58E /* DataDetectorsCoreSoftLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataDetectorsCoreSoftLink.h; sourceTree = "<group>"; };
    98989892                7C83DE851D04CBD400FEBCF3 /* SpringSolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpringSolver.h; sourceTree = "<group>"; };
    9899                 7C91A38D1B498ABE003F9EFA /* JSNodeOrString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSNodeOrString.cpp; sourceTree = "<group>"; };
    9900                 7C91A38E1B498ABE003F9EFA /* JSNodeOrString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSNodeOrString.h; sourceTree = "<group>"; };
    99019893                7C93F3471AA6BA5E00A98BAB /* CompiledContentExtension.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CompiledContentExtension.cpp; sourceTree = "<group>"; };
    99029894                7C93F3481AA6BA5E00A98BAB /* CompiledContentExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompiledContentExtension.h; sourceTree = "<group>"; };
     
    2110221094                                C6F420A016B7164E0052A9F2 /* JSMutationCallback.cpp */,
    2110321095                                C6F420A116B7164E0052A9F2 /* JSMutationCallback.h */,
    21104                                 7C91A38D1B498ABE003F9EFA /* JSNodeOrString.cpp */,
    21105                                 7C91A38E1B498ABE003F9EFA /* JSNodeOrString.h */,
    2110621096                                CB38FD551CD21D5B00592A3F /* JSPerformanceEntryCustom.cpp */,
    2110721097                                93B70D4F09EB0C7C009D8468 /* JSPluginElementFunctions.cpp */,
     
    2115521145                                8931DE5A14C44C44000DC9D2 /* JSBlobCustom.cpp */,
    2115621146                                49EED14B1051971900099FAB /* JSCanvasRenderingContext2DCustom.cpp */,
    21157                                 7C33F3581B4A044800502CAF /* JSCharacterDataCustom.cpp */,
    2115821147                                46A58AC41D46B3FA00432036 /* JSClientRectCustom.cpp */,
    2115921148                                A584FE371864DAC100843B10 /* JSCommandLineAPIHostCustom.cpp */,
     
    2117721166                                ADDA94BF19686F8000453029 /* JSDocumentCustom.h */,
    2117821167                                7C33F3601B4A050400502CAF /* JSDocumentFragmentCustom.cpp */,
    21179                                 7C33F35C1B4A04CE00502CAF /* JSDocumentTypeCustom.cpp */,
    2118021168                                A9C6E6460D7465CA006442E9 /* JSDOMMimeTypeArrayCustom.cpp */,
    2118121169                                A9C6E64A0D7465E7006442E9 /* JSDOMPluginArrayCustom.cpp */,
     
    2526425252                                BCD9C2C30C17B69E005C90A2 /* JSNodeList.h in Headers */,
    2526525253                                AD20B18D18E9D237005A8083 /* JSNodeListCustom.h in Headers */,
    25266                                 7C91A3901B498ABE003F9EFA /* JSNodeOrString.h in Headers */,
    2526725254                                33503CA410179AD7003B47E1 /* JSNotification.h in Headers */,
    2526825255                                33503CA610179AD7003B47E1 /* JSNotificationCenter.h in Headers */,
     
    2864928636                                FDA15EA312B03EE1003A583A /* JSChannelSplitterNode.cpp in Sources */,
    2865028637                                65DF31F309D1CC60000BE325 /* JSCharacterData.cpp in Sources */,
    28651                                 7C33F35A1B4A044800502CAF /* JSCharacterDataCustom.cpp in Sources */,
    2865228638                                BCC065870F3CE2A700CD2D87 /* JSClientRect.cpp in Sources */,
    2865328639                                46A58AC51D46B3FA00432036 /* JSClientRectCustom.cpp in Sources */,
     
    2872128707                                1221E05F1C02B444006A1A00 /* JSDocumentTimeline.cpp in Sources */,
    2872228708                                65DF31F509D1CC60000BE325 /* JSDocumentType.cpp in Sources */,
    28723                                 7C33F35E1B4A04CE00502CAF /* JSDocumentTypeCustom.cpp in Sources */,
    2872428709                                1AC2260C0DB69F190089B669 /* JSDOMApplicationCache.cpp in Sources */,
    2872528710                                93B70D6309EB0C7C009D8468 /* JSDOMBinding.cpp in Sources */,
     
    2898428969                                BCD9C2C20C17B69E005C90A2 /* JSNodeList.cpp in Sources */,
    2898528970                                BCD9C2650C17AA67005C90A2 /* JSNodeListCustom.cpp in Sources */,
    28986                                 7C91A38F1B498ABE003F9EFA /* JSNodeOrString.cpp in Sources */,
    2898728971                                33503CA310179AD7003B47E1 /* JSNotification.cpp in Sources */,
    2898828972                                33503CA510179AD7003B47E1 /* JSNotificationCenter.cpp in Sources */,
  • trunk/Source/WebCore/bindings/generic/IDLTypes.h

    r206812 r206956  
    8585struct IDLObject : IDLUnsupportedType { };
    8686
    87 template<typename T> struct IDLInterface : IDLType<Ref<T>> {
     87template<typename T> struct IDLInterface : IDLType<std::reference_wrapper<T>> {
    8888    using RawType = T;
    89     using NullableType = RefPtr<T>;
     89    using NullableType = T*;
    9090};
    9191
  • trunk/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp

    r205278 r206956  
    4242#include "JSCallbackData.cpp"
    4343#include "JSCanvasRenderingContext2DCustom.cpp"
    44 #include "JSCharacterDataCustom.cpp"
    4544#include "JSClientRectCustom.cpp"
    4645#include "JSCommandLineAPIHostCustom.cpp"
     
    7069#include "JSDocumentCustom.cpp"
    7170#include "JSDocumentFragmentCustom.cpp"
    72 #include "JSDocumentTypeCustom.cpp"
    7371#include "JSElementCustom.cpp"
    7472#include "JSErrorEventCustom.cpp"
     
    115113#include "JSNodeIteratorCustom.cpp"
    116114#include "JSNodeListCustom.cpp"
    117 #include "JSNodeOrString.cpp"
    118115#include "JSPluginElementFunctions.cpp"
    119116#include "JSPopStateEventCustom.cpp"
  • trunk/Source/WebCore/bindings/js/JSDOMBinding.h

    r206954 r206956  
    343343template<typename T> struct NativeValueTraits;
    344344
    345 template<typename JSClass, typename DOMClass, typename Enable = void>
    346 struct VariadicHelperBase {
    347     using Item = DOMClass;
    348 
    349     static Optional<Item> convert(JSC::ExecState& state, JSC::JSValue jsValue)
    350     {
    351         typedef NativeValueTraits<DOMClass> TraitsType;
    352         DOMClass indexValue;
    353         if (!TraitsType::nativeValue(state, jsValue, indexValue))
    354             return Nullopt;
    355         return indexValue;
    356     }
    357 };
    358 
    359 template<typename JSClass, typename DOMClass>
    360 struct VariadicHelperBase<JSClass, DOMClass, typename std::enable_if<!JSDOMObjectInspector<JSClass>::isBuiltin>::type> {
    361     using Class = typename std::remove_reference<decltype(std::declval<JSClass>().wrapped())>::type;
    362     using Item = std::reference_wrapper<Class>;
    363 
    364     static Optional<Item> convert(JSC::ExecState&, JSC::JSValue jsValue)
    365     {
    366         auto* value = JSClass::toWrapped(jsValue);
    367         if (!value)
    368             return Nullopt;
    369         return Optional<Item>(*value);
    370     }
    371 };
    372 
    373 template<typename JSClass, typename DOMClass>
    374 struct VariadicHelper : public VariadicHelperBase<JSClass, DOMClass> {
    375     using Item = typename VariadicHelperBase<JSClass, DOMClass>::Item;
    376     using Container = Vector<Item>;
    377 
    378     struct Result {
    379         size_t argumentIndex;
    380         Optional<Container> arguments;
    381     };
    382 };
    383 
    384 template<typename VariadicHelper> typename VariadicHelper::Result toArguments(JSC::ExecState&, size_t startIndex = 0);
    385345
    386346enum class CastedThisErrorBehavior { Throw, ReturnEarly };
     
    917877}
    918878
    919 template<typename VariadicHelper> typename VariadicHelper::Result toArguments(JSC::ExecState& state, size_t startIndex)
    920 {
    921     size_t length = state.argumentCount();
    922     if (startIndex > length)
    923         return { 0, Nullopt };
    924 
    925     typename VariadicHelper::Container result;
    926     result.reserveInitialCapacity(length - startIndex);
    927 
    928     for (size_t i = startIndex; i < length; ++i) {
    929         auto value = VariadicHelper::convert(state, state.uncheckedArgument(i));
    930         if (!value)
    931             return { i, Nullopt };
    932         result.uncheckedAppend(WTFMove(value.value()));
    933     }
    934     return { length, WTFMove(result) };
    935 }
    936 
    937879template<JSC::NativeFunction nativeFunction, int length> JSC::EncodedJSValue nonCachingStaticFunctionGetter(JSC::ExecState* exec, JSC::EncodedJSValue, JSC::PropertyName propertyName)
    938880{
  • trunk/Source/WebCore/bindings/js/JSDOMConvert.h

    r206812 r206956  
    4444template<typename T> Optional<T> convertDictionary(JSC::ExecState&, JSC::JSValue);
    4545
     46// Used for IDL enumerations.
     47template<typename T> Optional<T> parse(JSC::ExecState&, JSC::JSValue);
     48template<typename T> const char* expectedEnumerationValues();
     49
    4650enum class IsNullable { No, Yes };
    4751template<typename T, typename JST> T* convertWrapperType(JSC::ExecState&, JSC::JSValue, IsNullable);
     
    109113    {
    110114        return valueToUSVString(&state, value);
     115    }
     116};
     117
     118template<typename T> struct Converter<IDLInterface<T>> : DefaultConverter<T*> {
     119    static T* convert(JSC::ExecState& state, JSC::JSValue value)
     120    {
     121        return convertWrapperType<T, typename JSDOMWrapperConverterTraits<T>::WrapperClass>(state, value, IsNullable::No);
    111122    }
    112123};
     
    409420};
    410421
    411 // Used for IDL enumerations.
    412 template<typename T> Optional<T> parse(JSC::ExecState&, JSC::JSValue);
    413 template<typename T> const char* expectedEnumerationValues();
     422template<typename IDLType>
     423struct VariadicConverterBase;
     424
     425template<typename IDLType>
     426struct VariadicConverterBase {
     427    using Item = typename IDLType::ImplementationType;
     428
     429    static Optional<Item> convert(JSC::ExecState& state, JSC::JSValue value)
     430    {
     431        auto& vm = state.vm();
     432        auto scope = DECLARE_THROW_SCOPE(vm);
     433
     434        auto result = Converter<IDLType>::convert(state, value);
     435        RETURN_IF_EXCEPTION(scope, Nullopt);
     436
     437        return result;
     438    }
     439};
     440
     441template<typename T>
     442struct VariadicConverterBase<IDLInterface<T>> {
     443    using Item = typename IDLInterface<T>::ImplementationType;
     444
     445    static Optional<Item> convert(JSC::ExecState& state, JSC::JSValue value)
     446    {
     447        auto* result = Converter<IDLInterface<T>>::convert(state, value);
     448        if (!result)
     449            return Nullopt;
     450        return Optional<Item>(*result);
     451    }
     452};
     453
     454template<typename IDLType>
     455struct VariadicConverter : VariadicConverterBase<IDLType> {
     456    using Item = typename VariadicConverterBase<IDLType>::Item;
     457    using Container = Vector<Item>;
     458
     459    struct Result {
     460        size_t argumentIndex;
     461        Optional<Container> arguments;
     462    };
     463};
     464
     465template<typename IDLType> typename VariadicConverter<IDLType>::Result convertVariadicArguments(JSC::ExecState& state, size_t startIndex)
     466{
     467    size_t length = state.argumentCount();
     468    if (startIndex > length)
     469        return { 0, Nullopt };
     470
     471    typename VariadicConverter<IDLType>::Container result;
     472    result.reserveInitialCapacity(length - startIndex);
     473
     474    for (size_t i = startIndex; i < length; ++i) {
     475        auto value = VariadicConverter<IDLType>::convert(state, state.uncheckedArgument(i));
     476        if (!value)
     477            return { i, Nullopt };
     478        result.uncheckedAppend(WTFMove(*value));
     479    }
     480
     481    return { length, WTFMove(result) };
     482}
    414483
    415484} // namespace WebCore
  • trunk/Source/WebCore/bindings/js/JSDocumentCustom.cpp

    r206462 r206956  
    3030#include "JSHTMLDocument.h"
    3131#include "JSLocation.h"
    32 #include "JSNodeOrString.h"
    3332#include "JSXMLDocument.h"
    3433#include "Location.h"
     
    109108}
    110109
    111 JSValue JSDocument::prepend(ExecState& state)
    112 {
    113     ExceptionCode ec = 0;
    114     wrapped().prepend(toNodeOrStringVector(state), ec);
    115     setDOMException(&state, ec);
    116 
    117     return jsUndefined();
    118 }
    119 
    120 JSValue JSDocument::append(ExecState& state)
    121 {
    122     ExceptionCode ec = 0;
    123     wrapped().append(toNodeOrStringVector(state), ec);
    124     setDOMException(&state, ec);
    125 
    126     return jsUndefined();
    127 }
    128 
    129110#if ENABLE(TOUCH_EVENTS)
    130111JSValue JSDocument::createTouchList(ExecState& state)
  • trunk/Source/WebCore/bindings/js/JSDocumentFragmentCustom.cpp

    r205422 r206956  
    2828
    2929#include "ExceptionCode.h"
    30 #include "JSNodeOrString.h"
    3130#include "JSShadowRoot.h"
    3231
     
    3433
    3534namespace WebCore {
    36 
    37 JSValue JSDocumentFragment::prepend(ExecState& state)
    38 {
    39     ExceptionCode ec = 0;
    40     wrapped().prepend(toNodeOrStringVector(state), ec);
    41     setDOMException(&state, ec);
    42 
    43     return jsUndefined();
    44 }
    45 
    46 JSValue JSDocumentFragment::append(ExecState& state)
    47 {
    48     ExceptionCode ec = 0;
    49     wrapped().append(toNodeOrStringVector(state), ec);
    50     setDOMException(&state, ec);
    51 
    52     return jsUndefined();
    53 }
    5435
    5536JSValue toJSNewlyCreated(ExecState*, JSDOMGlobalObject* globalObject, Ref<DocumentFragment>&& impl)
  • trunk/Source/WebCore/bindings/js/JSElementCustom.cpp

    r205422 r206956  
    3939#include "JSHTMLElementWrapperFactory.h"
    4040#include "JSNodeList.h"
    41 #include "JSNodeOrString.h"
    4241#include "JSSVGElementWrapperFactory.h"
    4342#include "NodeList.h"
     
    7675}
    7776
    78 JSValue JSElement::before(ExecState& state)
    79 {
    80     ExceptionCode ec = 0;
    81     wrapped().before(toNodeOrStringVector(state), ec);
    82     setDOMException(&state, ec);
    83 
    84     return jsUndefined();
    85 }
    86 
    87 JSValue JSElement::after(ExecState& state)
    88 {
    89     ExceptionCode ec = 0;
    90     wrapped().after(toNodeOrStringVector(state), ec);
    91     setDOMException(&state, ec);
    92 
    93     return jsUndefined();
    94 }
    95 
    96 JSValue JSElement::replaceWith(ExecState& state)
    97 {
    98     ExceptionCode ec = 0;
    99     wrapped().replaceWith(toNodeOrStringVector(state), ec);
    100     setDOMException(&state, ec);
    101 
    102     return jsUndefined();
    103 }
    104 
    105 JSValue JSElement::prepend(ExecState& state)
    106 {
    107     ExceptionCode ec = 0;
    108     wrapped().prepend(toNodeOrStringVector(state), ec);
    109     setDOMException(&state, ec);
    110 
    111     return jsUndefined();
    112 }
    113 
    114 JSValue JSElement::append(ExecState& state)
    115 {
    116     ExceptionCode ec = 0;
    117     wrapped().append(toNodeOrStringVector(state), ec);
    118     setDOMException(&state, ec);
    119 
    120     return jsUndefined();
    121 }
    122 
    12377} // namespace WebCore
  • trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm

    r206877 r206956  
    3030
    3131use File::Find;
     32use Carp qw<longmess>;
     33use Data::Dumper;
    3234
    3335my $useDocument = "";
     
    141143my $cachedExternalDictionaries = {};
    142144
     145sub assert
     146{
     147    my $message = shift;
     148   
     149    my $mess = longmess();
     150    print Dumper($mess);
     151
     152    die $message;
     153}
     154
    143155# Default constructor
    144156sub new
     
    322334
    323335    return undef if $interfaceName eq 'Object';
     336    return undef if $interfaceName eq 'UNION';
    324337
    325338    if (exists $cachedInterfaces->{$interfaceName}) {
     
    329342    # Step #1: Find the IDL file associated with 'interface'
    330343    my $filename = $object->IDLFileForInterface($interfaceName)
    331         or die("Could NOT find IDL file for interface \"$interfaceName\", reachable from \"" . $outerInterface->name . "\"!\n");
     344        or assert("Could NOT find IDL file for interface \"$interfaceName\", reachable from \"" . $outerInterface->name . "\"!\n");
    332345
    333346    print "  |  |>  Parsing parent IDL \"$filename\" for interface \"$interfaceName\"\n" if $verbose;
     
    663676    return $object->GetFrozenArrayInnerType($type) if $object->IsFrozenArrayType($type);
    664677    return "";
     678}
     679
     680# http://heycam.github.io/webidl/#dfn-flattened-union-member-types
     681sub GetFlattenedMemberTypes
     682{
     683    my ($object, $idlUnionType) = @_;
     684
     685    my @flattenedMemberTypes = ();
     686
     687    foreach my $memberType (@{$idlUnionType->subtypes}) {
     688        if ($memberType->isUnion) {
     689            push(@flattenedMemberTypes, $object->GetFlattenedMemberTypes($memberType));
     690        } else {
     691            push(@flattenedMemberTypes, $memberType);
     692        }
     693    }
     694
     695    return @flattenedMemberTypes;
     696}
     697
     698# http://heycam.github.io/webidl/#dfn-number-of-nullable-member-types
     699sub GetNumberOfNullableMemberTypes
     700{
     701    my ($object, $idlUnionType) = @_;
     702
     703    my $count = 0;
     704
     705    foreach my $memberType (@{$idlUnionType->subtypes}) {
     706        $count++ if $memberType->isNullable;
     707        $count += $object->GetNumberOfNullableMemberTypes($memberType) if $memberType->isUnion;
     708    }
     709
     710    return $count;
     711}
     712
     713sub GetIDLUnionMemberTypes
     714{
     715    my ($object, $interface, $idlUnionType) = @_;
     716
     717    my $numberOfNullableMembers = $object->GetNumberOfNullableMemberTypes($idlUnionType);
     718    assert("Union types must only have 0 or 1 nullable types.") if $numberOfNullableMembers > 1;
     719
     720    my @idlUnionMemberTypes = ();
     721
     722    push(@idlUnionMemberTypes, "IDLNull") if $numberOfNullableMembers == 1;
     723
     724    foreach my $memberType ($object->GetFlattenedMemberTypes($idlUnionType)) {
     725        push(@idlUnionMemberTypes, $object->GetBaseIDLType($interface, $memberType));
     726    }
     727
     728    return @idlUnionMemberTypes;
     729}
     730
     731sub GetBaseIDLType
     732{
     733    my ($object, $interface, $idlType) = @_;
     734
     735    my %IDLTypes = (
     736        "any" => "IDLAny",
     737        "boolean" => "IDLBoolean",
     738        "byte" => "IDLByte",
     739        "octet" => "IDLOctet",
     740        "short" => "IDLShort",
     741        "unsigned short" => "IDLUnsignedShort",
     742        "long" => "IDLLong",
     743        "unsigned long" => "IDLUnsignedLong",
     744        "long long" => "IDLLongLong",
     745        "unsigned long long" => "IDLUnsignedLongLong",
     746        "float" => "IDLFloat",
     747        "unrestricted float" => "IDLUnrestrictedFloat",
     748        "double" => "IDLDouble",
     749        "unrestricted double" => "IDLUnrestrictedDouble",
     750        "DOMString" => "IDLDOMString",
     751        "ByteString" => "IDLByteString",
     752        "USVString" => "IDLUSVString",
     753    );
     754
     755    return $IDLTypes{$idlType->name} if exists $IDLTypes{$idlType->name};
     756    return "IDLEnumeration<" . $object->GetEnumerationClassName($interface, $idlType->name) . ">" if $object->IsEnumType($idlType->name);
     757    return "IDLDictionary<" . $object->GetDictionaryClassName($interface, $idlType->name) . ">" if $object->IsDictionaryType($idlType->name);
     758    return "IDLSequence<" . $object->GetIDLType($interface, @{$idlType->subtypes}[0]) . ">" if $object->IsSequenceType($idlType->name);
     759    return "IDLFrozenArray<" . $object->GetIDLType($interface, @{$idlType->subtypes}[0]) . ">" if $object->IsFrozenArrayType($idlType->name);
     760    return "IDLUnion<" . join(", ", $object->GetIDLUnionMemberTypes($interface, $idlType)) . ">" if $idlType->isUnion;
     761    return "IDLInterface<" . $idlType->name . ">";
     762}
     763
     764sub GetIDLType
     765{
     766    my ($object, $interface, $idlType) = @_;
     767
     768    my $baseIDLType = $object->GetBaseIDLType($interface, $idlType);
     769    return "IDLNullable<" . $baseIDLType . ">" if $idlType->isNullable;
     770    return $baseIDLType;
    665771}
    666772
     
    854960    return 0 if !$object->IsRefPtrType($type);
    855961    return 0 if $object->IsTypedArrayType($type);
     962    return 0 if $type eq "UNION";
    856963    return 0 if $webCoreTypeHash{$type};
    857964
     
    867974    my $interfaceName = shift;
    868975
    869     my $idlFile = $object->IDLFileForInterface($interfaceName) or die("Could NOT find IDL file for interface \"$interfaceName\"!\n");
     976    my $idlFile = $object->IDLFileForInterface($interfaceName) or assert("Could NOT find IDL file for interface \"$interfaceName\"!\n");
    870977
    871978    open FILE, "<", $idlFile or die;
     
    8991006  return 0 unless $object->IsWrapperType($type);
    9001007
    901   my $idlFile = $object->IDLFileForInterface($type) or die("Could NOT find IDL file for interface \"$type\"!\n");
     1008  my $idlFile = $object->IDLFileForInterface($type) or assert("Could NOT find IDL file for interface \"$type\"!\n");
    9021009
    9031010  open FILE, "<", $idlFile or die;
     
    9351042  return 0 unless $object->IsCallbackInterface($type);
    9361043
    937   my $idlFile = $object->IDLFileForInterface($type) or die("Could NOT find IDL file for interface \"$type\"!\n");
     1044  my $idlFile = $object->IDLFileForInterface($type) or assert("Could NOT find IDL file for interface \"$type\"!\n");
    9381045
    9391046  open FILE, "<", $idlFile or die;
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r206953 r206956  
    246246        # default, include the same named file
    247247        $includesRef->{"${type}.h"} = 1;
     248    }
     249}
     250
     251sub AddToImplIncludesForIDLType
     252{
     253    my ($idlType, $conditional) = @_;
     254
     255    return if $codeGenerator->SkipIncludeHeader($idlType->name);
     256
     257    if ($idlType->isUnion) {
     258        AddToImplIncludes("<wtf/Variant.h>", $conditional);
     259
     260        foreach my $memberType (@{$idlType->subtypes}) {
     261            AddToImplIncludesForIDLType($memberType, $conditional);
     262        }
     263
     264        return;
     265    }
     266
     267    if ($codeGenerator->IsWrapperType($idlType->name)) {
     268        AddToImplIncludes("JS" . $idlType->name . ".h");
     269        return;
    248270    }
    249271}
     
    40114033    foreach my $parameter (@{$function->parameters}) {
    40124034        my $type = $parameter->type;
     4035        my $idlType = $parameter->idlType;
    40134036
    40144037        die "Optional parameters of non-nullable wrapper types are not supported" if $parameter->isOptional && !$parameter->isNullable && $codeGenerator->IsWrapperType($type);
     
    40724095            $value = "WTFMove($name)";
    40734096        } elsif ($parameter->isVariadic) {
    4074             AddToImplIncludes("JS${type}.h", $function->signature->extendedAttributes->{Conditional}) unless $codeGenerator->SkipIncludeHeader($type) or !$codeGenerator->IsWrapperType($type);
    4075             my ($wrapperType, $wrappedType) = GetVariadicType($interface, $type);
    4076             push(@$outputArray, "    auto $name = toArguments<VariadicHelper<$wrapperType, $wrappedType>>(*state, $argumentIndex);\n");
    4077 
    4078             if (IsNativeType($type)) {
    4079                 push(@$outputArray, "    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());\n");
    4080             }
    4081             else {
    4082                 push(@$outputArray, "    if (!$name.arguments)\n");
    4083                 push(@$outputArray, "        return throwArgumentTypeError(*state, throwScope, $name.argumentIndex, \"$name\", \"$visibleInterfaceName\", $quotedFunctionName, \"$type\");\n");
    4084             }
     4097            $implIncludes{"JSDOMConvert.h"} = 1;
     4098            AddToImplIncludesForIDLType($idlType, $function->signature->extendedAttributes->{Conditional});
     4099       
     4100            my $metaType = $codeGenerator->GetIDLType($interface, $idlType);
     4101            push(@$outputArray, "    auto $name = convertVariadicArguments<$metaType>(*state, $argumentIndex);\n");
     4102            push(@$outputArray, "    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());\n");
     4103
    40854104            $value = "WTFMove($name.arguments.value())";
    40864105
  • trunk/Source/WebCore/bindings/scripts/IDLParser.pm

    r206776 r206956  
    4545});
    4646
     47struct( domType => {
     48    name =>         '$', # Type identifier
     49    isNullable =>   '$', # Is the type Nullable (T?)
     50    isUnion =>      '$', # Is the type a union (T or U)
     51    subtypes =>     '@', # Array of subtypes, only valid if isUnion or sequence
     52});
     53
    4754# Used to represent 'interface' blocks
    4855struct( domInterface => {
     
    8087});
    8188
    82 struct( domType => {
    83     name =>         '$', # Type identifier
    84     isNullable =>   '$', # Is the type Nullable (T?)
    85     isUnion =>      '$', # Is the type a union (T or U)
    86     subtypes =>     '@', # Array of subtypes, only valid if isUnion or sequence
    87 });
    88 
    8989# Used to represent a map of 'variable name' <-> 'variable type'
    9090struct( domSignature => {
    9191    direction => '$',   # Variable direction (in or out)
    9292    name => '$',        # Variable name
    93     type => '$'      ,  # Variable type
     93    type => '$',        # Variable type name (DEPRECATED - please use idlType)
     94    idlType => '$',     # Variable type
    9495    specials => '@',    # Specials
    9596    extendedAttributes => '$', # Extended attributes
     
    708709
    709710        my $type = $self->parseType();
     711        $member->idlType($type);
    710712        $member->type($type->name);
    711713        $member->isNullable($type->isNullable);
     
    12551257       
    12561258        my $type = $self->parseType();
     1259        $newDataNode->signature->idlType($type);
    12571260        $newDataNode->signature->type($type->name);
    12581261        $newDataNode->signature->isNullable($type->isNullable);
     
    15471550
    15481551        my $type = $self->parseType();
     1552        $paramDataNode->idlType($type);
    15491553        $paramDataNode->type(identifierRemoveNullablePrefix($type->name));
    15501554        $paramDataNode->isNullable($type->isNullable);
     
    15561560    if ($next->type() == IdentifierToken || $next->value() =~ /$nextExceptionField_1/) {
    15571561        my $type = $self->parseType();
     1562        $paramDataNode->idlType($type);
    15581563        $paramDataNode->type($type->name);
    15591564        $paramDataNode->isNullable($type->isNullable);
     
    16181623
    16191624        my $type = $self->parseType();
     1625        $newDataNode->signature->idlType($type);
    16201626        $newDataNode->signature->type($type->name);
    16211627        $newDataNode->signature->isNullable($type->isNullable);
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp

    r206953 r206956  
    7272#include <runtime/PropertyNameArray.h>
    7373#include <wtf/GetPtr.h>
     74#include <wtf/Variant.h>
    7475
    7576#if ENABLE(Condition1)
     
    985986JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionVariadicDoubleMethod(JSC::ExecState*);
    986987JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionVariadicNodeMethod(JSC::ExecState*);
     988JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionVariadicUnionMethod(JSC::ExecState*);
    987989JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionAny(JSC::ExecState*);
    988990JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunction(JSC::ExecState*);
     
    15921594    { "variadicDoubleMethod", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionVariadicDoubleMethod), (intptr_t) (1) } },
    15931595    { "variadicNodeMethod", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionVariadicNodeMethod), (intptr_t) (1) } },
     1596    { "variadicUnionMethod", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionVariadicUnionMethod), (intptr_t) (1) } },
    15941597    { "any", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionAny), (intptr_t) (2) } },
    15951598    { "testPromiseFunction", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionTestPromiseFunction), (intptr_t) (0) } },
     
    65646567    ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestObj::info());
    65656568    auto& impl = castedThis->wrapped();
    6566     auto blobArgs = toArguments<VariadicHelper<JSBlob, Blob>>(*state, 0);
    6567     if (!blobArgs.arguments)
    6568         return throwArgumentTypeError(*state, throwScope, blobArgs.argumentIndex, "blobArgs", "TestObject", "overloadedMethod", "Blob");
     6569    auto blobArgs = convertVariadicArguments<IDLInterface<Blob>>(*state, 0);
     6570    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    65696571    impl.overloadedMethod(WTFMove(blobArgs.arguments.value()));
    65706572    return JSValue::encode(jsUndefined());
     
    70827084    auto head = state->uncheckedArgument(0).toWTFString(state);
    70837085    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    7084     auto tail = toArguments<VariadicHelper<JSC::JSValue, String>>(*state, 1);
     7086    auto tail = convertVariadicArguments<IDLDOMString>(*state, 1);
    70857087    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    70867088    impl.variadicStringMethod(WTFMove(head), WTFMove(tail.arguments.value()));
     
    71037105    auto head = convert<double>(*state, state->uncheckedArgument(0), ShouldAllowNonFinite::Yes);
    71047106    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    7105     auto tail = toArguments<VariadicHelper<JSC::JSValue, double>>(*state, 1);
     7107    auto tail = convertVariadicArguments<IDLUnrestrictedDouble>(*state, 1);
    71067108    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    71077109    impl.variadicDoubleMethod(WTFMove(head), WTFMove(tail.arguments.value()));
     
    71257127    if (UNLIKELY(!head))
    71267128        return throwArgumentTypeError(*state, throwScope, 0, "head", "TestObject", "variadicNodeMethod", "Node");
    7127     auto tail = toArguments<VariadicHelper<JSNode, Node>>(*state, 1);
    7128     if (!tail.arguments)
    7129         return throwArgumentTypeError(*state, throwScope, tail.argumentIndex, "tail", "TestObject", "variadicNodeMethod", "Node");
     7129    auto tail = convertVariadicArguments<IDLInterface<Node>>(*state, 1);
     7130    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    71307131    impl.variadicNodeMethod(*head, WTFMove(tail.arguments.value()));
     7132    return JSValue::encode(jsUndefined());
     7133}
     7134
     7135EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionVariadicUnionMethod(ExecState* state)
     7136{
     7137    VM& vm = state->vm();
     7138    auto throwScope = DECLARE_THROW_SCOPE(vm);
     7139    UNUSED_PARAM(throwScope);
     7140    JSValue thisValue = state->thisValue();
     7141    auto castedThis = jsDynamicCast<JSTestObj*>(thisValue);
     7142    if (UNLIKELY(!castedThis))
     7143        return throwThisTypeError(*state, throwScope, "TestObject", "variadicUnionMethod");
     7144    ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestObj::info());
     7145    auto& impl = castedThis->wrapped();
     7146    if (UNLIKELY(state->argumentCount() < 1))
     7147        return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
     7148    auto head = state->uncheckedArgument(0).toWTFString(state);
     7149    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
     7150    auto tail = convertVariadicArguments<IDLUnion<IDLInterface<Node>, IDLDOMString>>(*state, 1);
     7151    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
     7152    impl.variadicUnionMethod(WTFMove(head), WTFMove(tail.arguments.value()));
    71317153    return JSValue::encode(jsUndefined());
    71327154}
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestOverloadedConstructors.cpp

    r206723 r206956  
    2626#include "JSDOMBinding.h"
    2727#include "JSDOMConstructor.h"
     28#include "JSDOMConvert.h"
    2829#include <runtime/Error.h>
    2930#include <runtime/FunctionPrototype.h>
     
    138139    auto* castedThis = jsCast<JSTestOverloadedConstructorsConstructor*>(state->callee());
    139140    ASSERT(castedThis);
    140     auto longArgs = toArguments<VariadicHelper<JSC::JSValue, int32_t>>(*state, 0);
     141    auto longArgs = convertVariadicArguments<IDLLong>(*state, 0);
    141142    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    142143    auto object = TestOverloadedConstructors::create(WTFMove(longArgs));
  • trunk/Source/WebCore/bindings/scripts/test/TestObj.idl

    r206877 r206956  
    360360    void variadicDoubleMethod(unrestricted double head, unrestricted double... tail);
    361361    void variadicNodeMethod(Node head, Node... tail);
     362    void variadicUnionMethod(DOMString head, (Node or DOMString)... tail);
    362363
    363364    // Nullable attributes.
  • trunk/Source/WebCore/dom/ChildNode.idl

    r206723 r206956  
    2323    NoInterfaceObject,
    2424] interface ChildNode {
    25     [Unscopable, MayThrowLegacyException, Custom] void before((Node or DOMString)... nodes);
    26     [Unscopable, MayThrowLegacyException, Custom] void after((Node or DOMString)... nodes);
    27     [Unscopable, MayThrowLegacyException, Custom] void replaceWith((Node or DOMString)... nodes);
     25    [Unscopable, MayThrowLegacyException] void before((Node or DOMString)... nodes);
     26    [Unscopable, MayThrowLegacyException] void after((Node or DOMString)... nodes);
     27    [Unscopable, MayThrowLegacyException] void replaceWith((Node or DOMString)... nodes);
    2828    [Unscopable, MayThrowLegacyException] void remove();
    2929};
  • trunk/Source/WebCore/dom/ContainerNode.cpp

    r204493 r206956  
    878878}
    879879
    880 void ContainerNode::append(Vector<std::experimental::variant<Ref<Node>, String>>&& nodeOrStringVector, ExceptionCode& ec)
     880void ContainerNode::append(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&& nodeOrStringVector, ExceptionCode& ec)
    881881{
    882882    RefPtr<Node> node = convertNodesOrStringsIntoNode(WTFMove(nodeOrStringVector), ec);
     
    887887}
    888888
    889 void ContainerNode::prepend(Vector<std::experimental::variant<Ref<Node>, String>>&& nodeOrStringVector, ExceptionCode& ec)
     889void ContainerNode::prepend(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&& nodeOrStringVector, ExceptionCode& ec)
    890890{
    891891    RefPtr<Node> node = convertNodesOrStringsIntoNode(WTFMove(nodeOrStringVector), ec);
  • trunk/Source/WebCore/dom/ContainerNode.h

    r204717 r206956  
    100100    WEBCORE_EXPORT Element* lastElementChild() const;
    101101    WEBCORE_EXPORT unsigned childElementCount() const;
    102     void append(Vector<std::experimental::variant<Ref<Node>, String>>&&, ExceptionCode&);
    103     void prepend(Vector<std::experimental::variant<Ref<Node>, String>>&&, ExceptionCode&);
     102    void append(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&&, ExceptionCode&);
     103    void prepend(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&&, ExceptionCode&);
    104104
    105105    bool ensurePreInsertionValidity(Node& newChild, Node* refChild, ExceptionCode&);
  • trunk/Source/WebCore/dom/Node.cpp

    r206944 r206956  
    436436}
    437437
    438 static HashSet<RefPtr<Node>> nodeSetPreTransformedFromNodeOrStringVector(const Vector<std::experimental::variant<Ref<Node>, String>>& vector)
     438static HashSet<RefPtr<Node>> nodeSetPreTransformedFromNodeOrStringVector(const Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>& vector)
    439439{
    440440    HashSet<RefPtr<Node>> nodeSet;
    441441
    442442    auto visitor = WTF::makeVisitor(
    443         [&](const Ref<Node>& node) { nodeSet.add(const_cast<Node*>(node.ptr())); },
     443        [&](const std::reference_wrapper<Node>& node) { nodeSet.add(const_cast<Node*>(&node.get())); },
    444444        [](const String&) { }
    445445    );
     
    469469}
    470470
    471 RefPtr<Node> Node::convertNodesOrStringsIntoNode(Vector<std::experimental::variant<Ref<Node>, String>>&& nodeOrStringVector, ExceptionCode& ec)
     471RefPtr<Node> Node::convertNodesOrStringsIntoNode(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&& nodeOrStringVector, ExceptionCode& ec)
    472472{
    473473    if (nodeOrStringVector.isEmpty())
     
    478478
    479479    auto visitor = WTF::makeVisitor(
    480         [&](Ref<Node>& node) { nodes.uncheckedAppend(node.copyRef()); },
     480        [&](std::reference_wrapper<Node>& node) { nodes.uncheckedAppend(node); },
    481481        [&](String& string) { nodes.uncheckedAppend(Text::create(document(), string)); }
    482482    );
     
    496496}
    497497
    498 void Node::before(Vector<std::experimental::variant<Ref<Node>, String>>&& nodeOrStringVector, ExceptionCode& ec)
     498void Node::before(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&& nodeOrStringVector, ExceptionCode& ec)
    499499{
    500500    RefPtr<ContainerNode> parent = parentNode();
     
    517517}
    518518
    519 void Node::after(Vector<std::experimental::variant<Ref<Node>, String>>&& nodeOrStringVector, ExceptionCode& ec)
     519void Node::after(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&& nodeOrStringVector, ExceptionCode& ec)
    520520{
    521521    RefPtr<ContainerNode> parent = parentNode();
     
    533533}
    534534
    535 void Node::replaceWith(Vector<std::experimental::variant<Ref<Node>, String>>&& nodeOrStringVector, ExceptionCode& ec)
     535void Node::replaceWith(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&& nodeOrStringVector, ExceptionCode& ec)
    536536{
    537537    RefPtr<ContainerNode> parent = parentNode();
  • trunk/Source/WebCore/dom/Node.h

    r206843 r206956  
    203203
    204204    // From the ChildNode - https://dom.spec.whatwg.org/#childnode
    205     void before(Vector<std::experimental::variant<Ref<Node>, String>>&&, ExceptionCode&);
    206     void after(Vector<std::experimental::variant<Ref<Node>, String>>&&, ExceptionCode&);
    207     void replaceWith(Vector<std::experimental::variant<Ref<Node>, String>>&&, ExceptionCode&);
     205    void before(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&&, ExceptionCode&);
     206    void after(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&&, ExceptionCode&);
     207    void replaceWith(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&&, ExceptionCode&);
    208208    WEBCORE_EXPORT void remove(ExceptionCode&);
    209209
     
    660660    void updateAncestorsForStyleRecalc();
    661661
    662     RefPtr<Node> convertNodesOrStringsIntoNode(Vector<std::experimental::variant<Ref<Node>, String>>&&, ExceptionCode&);
     662    RefPtr<Node> convertNodesOrStringsIntoNode(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&&, ExceptionCode&);
    663663
    664664private:
  • trunk/Source/WebCore/dom/ParentNode.idl

    r206723 r206956  
    3434    readonly attribute unsigned long childElementCount;
    3535
    36     [Unscopable, MayThrowLegacyException, Custom] void prepend((Node or DOMString)... nodes);
    37     [Unscopable, MayThrowLegacyException, Custom] void append((Node or DOMString)... nodes);
     36    [Unscopable, MayThrowLegacyException] void prepend((Node or DOMString)... nodes);
     37    [Unscopable, MayThrowLegacyException] void append((Node or DOMString)... nodes);
    3838
    3939    // [Unscopable] Element? query(DOMString relativeSelectors);
Note: See TracChangeset for help on using the changeset viewer.