Changeset 206681 in webkit


Ignore:
Timestamp:
Sep 30, 2016, 3:21:59 PM (9 years ago)
Author:
Chris Dumez
Message:

[iOS] Allow sequence<Touch> input in TouchEvent constructor
https://bugs.webkit.org/show_bug.cgi?id=162806
<rdar://problem/28566429>

Reviewed by Ryosuke Niwa.

Allow sequence<Touch> input in TouchEvent constructor in addition to
TouchList objects. It is convenient for developers to pass arrays of
Touch objects.

No new tests, already covered by:
imported/w3c/web-platform-tests/touch-events/touch-touchevent-constructor.html

  • bindings/js/JSDOMBinding.h:

(WebCore::toRefNativeArray):
(WebCore::toRefPtrNativeArray):

  • bindings/js/JSDictionary.cpp:

(WebCore::JSDictionary::convertValue):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r206679 r206681  
     12016-09-30  Chris Dumez  <cdumez@apple.com>
     2
     3        [iOS] Allow sequence<Touch> input in TouchEvent constructor
     4        https://bugs.webkit.org/show_bug.cgi?id=162806
     5        <rdar://problem/28566429>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Allow sequence<Touch> input in TouchEvent constructor in addition to
     10        TouchList objects. It is convenient for developers to pass arrays of
     11        Touch objects.
     12
     13        No new tests, already covered by:
     14        imported/w3c/web-platform-tests/touch-events/touch-touchevent-constructor.html
     15
     16        * bindings/js/JSDOMBinding.h:
     17        (WebCore::toRefNativeArray):
     18        (WebCore::toRefPtrNativeArray):
     19        * bindings/js/JSDictionary.cpp:
     20        (WebCore::JSDictionary::convertValue):
     21
    1222016-09-30  Myles C. Maxfield  <mmaxfield@apple.com>
    223
  • trunk/Source/WebCore/bindings/js/JSDOMBinding.h

    r206386 r206681  
    310310RefPtr<JSC::Float64Array> toFloat64Array(JSC::JSValue);
    311311
    312 template<typename T, typename JSType> Vector<RefPtr<T>> toRefPtrNativeArray(JSC::ExecState*, JSC::JSValue);
     312template<typename T, typename JSType> Vector<Ref<T>> toRefNativeArray(JSC::ExecState&, JSC::JSValue);
     313template<typename T, typename JSType> Vector<RefPtr<T>> toRefPtrNativeArray(JSC::ExecState&, JSC::JSValue);
    313314template<typename T> Vector<T> toNativeArray(JSC::ExecState&, JSC::JSValue);
    314315bool hasIteratorMethod(JSC::ExecState&, JSC::JSValue);
     
    813814};
    814815
     816template<typename T, typename JST> inline Vector<Ref<T>> toRefNativeArray(JSC::ExecState& state, JSC::JSValue value)
     817{
     818    JSC::VM& vm = state.vm();
     819    auto scope = DECLARE_THROW_SCOPE(vm);
     820
     821    if (!value.isObject()) {
     822        throwSequenceTypeError(state, scope);
     823        return { };
     824    }
     825
     826    Vector<Ref<T>> result;
     827    forEachInIterable(&state, value, [&result](JSC::VM& vm, JSC::ExecState* state, JSC::JSValue jsValue) {
     828        auto scope = DECLARE_THROW_SCOPE(vm);
     829
     830        if (jsValue.inherits(JST::info())) {
     831            auto* object = JST::toWrapped(jsValue);
     832            ASSERT(object);
     833            result.append(*object);
     834        } else
     835            throwArrayElementTypeError(*state, scope);
     836    });
     837    return result;
     838}
     839
    815840template<typename T, typename JST> Vector<RefPtr<T>> toRefPtrNativeArray(JSC::ExecState& exec, JSC::JSValue value)
    816841{
     
    820845    if (!value.isObject()) {
    821846        throwSequenceTypeError(exec, scope);
    822         return Vector<RefPtr<T>>();
     847        return { };
    823848    }
    824849
  • trunk/Source/WebCore/bindings/js/JSDictionary.cpp

    r206575 r206681  
    7070
    7171#if ENABLE(IOS_TOUCH_EVENTS) || ENABLE(TOUCH_EVENTS)
     72#include "JSTouch.h"
    7273#include "JSTouchList.h"
    7374#endif
     
    352353#endif
    353354
    354 #if ENABLE(IOS_TOUCH_EVENTS) || ENABLE(TOUCH_EVENTS)
     355#if ENABLE(TOUCH_EVENTS) && !ENABLE(IOS_TOUCH_EVENTS)
    355356void JSDictionary::convertValue(JSC::ExecState*, JSC::JSValue value, RefPtr<TouchList>& result)
    356357{
    357358    result = JSTouchList::toWrapped(value);
     359}
     360#endif
     361
     362#if ENABLE(IOS_TOUCH_EVENTS)
     363void JSDictionary::convertValue(JSC::ExecState* exec, JSC::JSValue value, RefPtr<TouchList>& result)
     364{
     365    VM& vm = exec->vm();
     366    auto scope = DECLARE_THROW_SCOPE(vm);
     367
     368    JSObject* object = value.getObject();
     369    if (!object) {
     370        result = nullptr;
     371        return;
     372    }
     373
     374    // Allow both TouchList and sequence<Touch> as input.
     375    const ClassInfo* classInfo = object->classInfo();
     376    if (classInfo == JSTouchList::info()) {
     377        result = JSTouchList::toWrapped(value);
     378        return;
     379    }
     380
     381    auto touches = toRefNativeArray<Touch, JSTouch>(*exec, value);
     382    RETURN_IF_EXCEPTION(scope, void());
     383    result = TouchList::create(WTFMove(touches));
    358384}
    359385#endif
Note: See TracChangeset for help on using the changeset viewer.