Skip to content

Commit

Permalink
Share code between JSDOMIterator and JSDOMAsyncIterator
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=231437
<rdar://problem/84306323>

Reviewed by Youenn Fablet.

* bindings/js/JSDOMAsyncIterator.h:
(WebCore::jsPair): Deleted.
(WebCore::iteratorCreate): Deleted.
* bindings/js/JSFileSystemDirectoryHandleIterator.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@284549 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
[email protected] committed Oct 20, 2021
1 parent d04ebab commit e2dcdee
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 40 deletions.
13 changes: 13 additions & 0 deletions Source/WebCore/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
2021-10-20 Sihui Liu <[email protected]>

Share code between JSDOMIterator and JSDOMAsyncIterator
https://bugs.webkit.org/show_bug.cgi?id=231437
<rdar://problem/84306323>

Reviewed by Youenn Fablet.

* bindings/js/JSDOMAsyncIterator.h:
(WebCore::jsPair): Deleted.
(WebCore::iteratorCreate): Deleted.
* bindings/js/JSFileSystemDirectoryHandleIterator.h:

2021-10-20 Rob Buis <[email protected]>

Fix percentages on orthogonal replaced children
Expand Down
40 changes: 1 addition & 39 deletions Source/WebCore/bindings/js/JSDOMAsyncIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#pragma once

#include "JSDOMConvert.h"
#include "JSDOMIterator.h"
#include "JSDOMPromise.h"
#include "JSDOMPromiseDeferred.h"
#include <JavaScriptCore/AsyncIteratorPrototype.h>
Expand All @@ -37,19 +38,6 @@

namespace WebCore {

void addValueIterableMethods(JSC::JSGlobalObject&, JSC::JSObject&);

enum class JSDOMAsyncIteratorType { Set, Map };

// struct IteratorTraits {
// static constexpr JSDOMAsyncIteratorType type = [Map|Set];
// using KeyType = [IDLType|void];
// using ValueType = [IDLType];
// };

template<typename T, typename U = void> using EnableIfMap = typename std::enable_if<T::type == JSDOMAsyncIteratorType::Map, U>::type;
template<typename T, typename U = void> using EnableIfSet = typename std::enable_if<T::type == JSDOMAsyncIteratorType::Set, U>::type;

// https://webidl.spec.whatwg.org/#es-asynchronous-iterator-prototype-object
template<typename JSWrapper, typename IteratorTraits, typename JSIterator> class JSDOMAsyncIteratorPrototype final : public JSC::JSNonFinalObject {
public:
Expand Down Expand Up @@ -89,8 +77,6 @@ template<typename JSWrapper, typename IteratorTraits, typename JSIterator> class
void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
};

using IterationKind = JSC::IterationKind;

template<typename JSWrapper, typename IteratorTraits, typename JSIterator> class JSDOMAsyncIteratorBase : public JSDOMObject {
public:
using Base = JSDOMObject;
Expand Down Expand Up @@ -132,30 +118,6 @@ template<typename JSWrapper, typename IteratorTraits, typename JSIterator> class
RefPtr<DOMPromise> m_ongoingPromise;
};

inline JSC::JSValue jsPair(JSC::JSGlobalObject&, JSDOMGlobalObject& globalObject, JSC::JSValue value1, JSC::JSValue value2)
{
JSC::MarkedArgumentBuffer arguments;
arguments.append(value1);
arguments.append(value2);
ASSERT(!arguments.hasOverflowed());
return constructArray(&globalObject, static_cast<JSC::ArrayAllocationProfile*>(nullptr), arguments);
}

template<typename FirstType, typename SecondType, typename T, typename U>
inline JSC::JSValue jsPair(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const T& value1, const U& value2)
{
return jsPair(lexicalGlobalObject, globalObject, toJS<FirstType>(lexicalGlobalObject, globalObject, value1), toJS<SecondType>(lexicalGlobalObject, globalObject, value2));
}

template<typename JSIterator> JSC::JSValue iteratorCreate(typename JSIterator::Wrapper&, IterationKind);

template<typename JSIterator> JSC::JSValue iteratorCreate(typename JSIterator::Wrapper& thisObject, IterationKind kind)
{
ASSERT(thisObject.globalObject());
JSDOMGlobalObject& globalObject = *thisObject.globalObject();
return JSIterator::create(globalObject.vm(), getDOMStructure<JSIterator>(globalObject.vm(), globalObject), thisObject, kind);
}

template<typename IteratorValue, typename IteratorTraits>
inline EnableIfMap<IteratorTraits, JSC::JSValue> convertToJS(JSC::JSGlobalObject& globalObject, JSDOMGlobalObject& domGlobalObject, IteratorValue& value, IteratorTraits, IterationKind kind)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace WebCore {
class FileSystemHandle;

struct JSFileSystemDirectoryHandleIteratorTraits {
static constexpr JSDOMAsyncIteratorType type = JSDOMAsyncIteratorType::Map;
static constexpr JSDOMIteratorType type = JSDOMIteratorType::Map;
using KeyType = IDLByteString;
using ValueType = IDLInterface<FileSystemHandle>;
};
Expand Down

0 comments on commit e2dcdee

Please sign in to comment.