From ed4f4ae4e29bc7a27d0eb7503401a8fbfb669470 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sun, 27 Mar 2022 22:37:55 -0700 Subject: [PATCH] Begin adding WebCore classes to bun --- src/javascript/jsc/bindings/BunBuiltinNames.h | 11 +- src/javascript/jsc/bindings/BunClientData.cpp | 52 +- src/javascript/jsc/bindings/BunClientData.h | 128 ++- .../jsc/bindings/BunGCOutputConstraint.cpp | 79 +- .../jsc/bindings/BunGCOutputConstraint.h | 47 +- src/javascript/jsc/bindings/BunStream.cpp | 56 +- src/javascript/jsc/bindings/BunStream.h | 6 +- src/javascript/jsc/bindings/DOMException.h | 2 +- src/javascript/jsc/bindings/DOMFormData.h | 4 +- src/javascript/jsc/bindings/DOMURL.cpp | 2 +- src/javascript/jsc/bindings/DOMURL.h | 4 +- .../jsc/bindings/DOMWrapperWorld-class.h | 65 ++ .../jsc/bindings/DOMWrapperWorld.cpp | 71 ++ src/javascript/jsc/bindings/DOMWrapperWorld.h | 59 ++ src/javascript/jsc/bindings/Exception.h | 2 +- src/javascript/jsc/bindings/ExceptionCode.h | 2 +- src/javascript/jsc/bindings/ExceptionOr.h | 6 +- .../jsc/bindings/GCDefferalContext.h | 2 + src/javascript/jsc/bindings/IDLTypes.h | 12 +- src/javascript/jsc/bindings/JSCInlines.h | 38 +- src/javascript/jsc/bindings/JSDOMBinding.h | 21 + .../jsc/bindings/JSDOMExceptionHandling.cpp | 40 +- .../jsc/bindings/JSDOMExceptionHandling.h | 31 +- .../jsc/bindings/JSDOMGlobalObject.cpp | 82 ++ .../jsc/bindings/JSDOMGlobalObject.h | 33 + src/javascript/jsc/bindings/JSDOMURL.cpp | 321 ------- src/javascript/jsc/bindings/JSDOMURL.h | 52 -- src/javascript/jsc/bindings/JSDOMWrapper.cpp | 2 +- src/javascript/jsc/bindings/JSDOMWrapper.h | 7 +- .../jsc/bindings/JSDOMWrapperCache.cpp | 49 + .../jsc/bindings/JSDOMWrapperCache.h | 227 +++++ src/javascript/jsc/bindings/Path.cpp | 17 +- src/javascript/jsc/bindings/Process.cpp | 18 +- src/javascript/jsc/bindings/Process.h | 3 +- .../jsc/bindings/ScriptExecutionContext.h | 0 src/javascript/jsc/bindings/StringAdaptors.h | 2 +- .../jsc/bindings/URLDecomposition.cpp | 2 +- .../jsc/bindings/URLDecomposition.h | 4 +- .../jsc/bindings/URLSearchParams.cpp | 2 +- src/javascript/jsc/bindings/URLSearchParams.h | 6 +- .../jsc/bindings/ZigConsoleClient.cpp | 11 +- .../jsc/bindings/ZigConsoleClient.h | 6 +- .../jsc/bindings/ZigGlobalObject.cpp | 302 +++--- src/javascript/jsc/bindings/ZigGlobalObject.h | 112 ++- .../jsc/bindings/ZigSourceProvider.cpp | 17 +- .../jsc/bindings/ZigSourceProvider.h | 12 +- src/javascript/jsc/bindings/bindings.cpp | 238 ++--- src/javascript/jsc/bindings/bindings.zig | 58 +- .../jsc/bindings/bmalloc_heap_ref.h | 53 ++ src/javascript/jsc/bindings/exports.zig | 2 +- src/javascript/jsc/bindings/header-gen.zig | 2 +- src/javascript/jsc/bindings/headers-cpp.h | 152 +-- src/javascript/jsc/bindings/headers.h | 6 +- src/javascript/jsc/bindings/helpers.h | 19 +- src/javascript/jsc/bindings/objects.h | 6 +- src/javascript/jsc/bindings/root.h | 20 +- .../jsc/bindings/webcore/ActiveDOMObject.h | 0 .../jsc/bindings/webcore/BufferSource.h | 114 +++ .../bindings/webcore/DOMClientIsoSubspaces.h | 874 +++++++++++++++++ .../jsc/bindings/webcore/DOMConstructors.h | 864 +++++++++++++++++ .../jsc/bindings/webcore/DOMIsoSubspaces.h | 877 ++++++++++++++++++ .../jsc/bindings/webcore/ExceptionDetails.h | 60 ++ .../webcore/ExtendedDOMClientIsoSubspaces.h | 41 + .../webcore/ExtendedDOMIsoSubspaces.h | 37 + .../jsc/bindings/webcore/JSDOMAttribute.h | 136 +++ .../webcore/JSDOMBindingInternalsBuiltins.cpp | 79 ++ .../webcore/JSDOMBindingInternalsBuiltins.h | 159 ++++ .../jsc/bindings/webcore/JSDOMCastThisValue.h | 54 ++ .../jsc/bindings/webcore/JSDOMConstructor.h | 72 ++ .../bindings/webcore/JSDOMConstructorBase.cpp | 54 ++ .../bindings/webcore/JSDOMConstructorBase.h | 63 ++ .../webcore/JSDOMConstructorNotCallable.h | 85 ++ .../JSDOMConstructorNotConstructable.h | 69 ++ .../jsc/bindings/webcore/JSDOMConvert.h | 47 + .../jsc/bindings/webcore/JSDOMConvertAny.h | 85 ++ .../jsc/bindings/webcore/JSDOMConvertBase.h | 268 ++++++ .../bindings/webcore/JSDOMConvertBoolean.h | 53 ++ .../webcore/JSDOMConvertBufferSource.h | 481 ++++++++++ .../bindings/webcore/JSDOMConvertCallbacks.h | 104 +++ .../jsc/bindings/webcore/JSDOMConvertDate.cpp | 53 ++ .../jsc/bindings/webcore/JSDOMConvertDate.h | 56 ++ .../bindings/webcore/JSDOMConvertDictionary.h | 56 ++ .../webcore/JSDOMConvertEnumeration.h | 70 ++ .../webcore/JSDOMConvertEventListener.h | 51 + .../bindings/webcore/JSDOMConvertInterface.h | 105 +++ .../jsc/bindings/webcore/JSDOMConvertJSON.h | 51 + .../jsc/bindings/webcore/JSDOMConvertNull.h | 50 + .../bindings/webcore/JSDOMConvertNullable.h | 150 +++ .../bindings/webcore/JSDOMConvertNumbers.cpp | 379 ++++++++ .../bindings/webcore/JSDOMConvertNumbers.h | 409 ++++++++ .../jsc/bindings/webcore/JSDOMConvertObject.h | 63 ++ .../bindings/webcore/JSDOMConvertPromise.h | 87 ++ .../jsc/bindings/webcore/JSDOMConvertRecord.h | 191 ++++ .../webcore/JSDOMConvertScheduledAction.h | 54 ++ .../bindings/webcore/JSDOMConvertSequences.h | 435 +++++++++ .../JSDOMConvertSerializedScriptValue.h | 50 + .../bindings/webcore/JSDOMConvertStrings.cpp | 92 ++ .../bindings/webcore/JSDOMConvertStrings.h | 214 +++++ .../jsc/bindings/webcore/JSDOMConvertUnion.h | 416 +++++++++ .../bindings/webcore/JSDOMConvertVariadic.h | 74 ++ .../bindings/webcore/JSDOMConvertWebGL.cpp | 247 +++++ .../jsc/bindings/webcore/JSDOMConvertWebGL.h | 68 ++ .../webcore/JSDOMConvertXPathNSResolver.h | 55 ++ .../jsc/bindings/webcore/JSDOMException.cpp | 381 ++++++++ .../jsc/bindings/webcore/JSDOMException.h | 95 ++ .../webcore/JSDOMGlobalObjectInlines.h | 47 + .../jsc/bindings/webcore/JSDOMIterator.cpp | 55 ++ .../jsc/bindings/webcore/JSDOMIterator.h | 275 ++++++ .../jsc/bindings/webcore/JSDOMOperation.h | 74 ++ .../jsc/bindings/webcore/JSDOMURL.cpp | 846 +++++++++++++++++ .../jsc/bindings/webcore/JSDOMURL.h | 98 ++ .../bindings/webcore/JSURLSearchParams.cpp | 559 +++++++++++ .../bindings/webcore/JSURLSearchParams.dep | 1 + .../jsc/bindings/webcore/JSURLSearchParams.h | 94 ++ .../bindings/webcore/JSValueInWrappedObject.h | 135 +++ .../jsc/bindings/webcore/ScriptWrappable.cpp | 38 + .../jsc/bindings/webcore/ScriptWrappable.h | 63 ++ .../bindings/webcore/ScriptWrappableInlines.h | 56 ++ .../bindings/webcore/WebCoreJSClientData.h | 1 + .../webcore/WebCoreTypedArrayController.cpp | 78 ++ .../webcore/WebCoreTypedArrayController.h | 59 ++ src/javascript/jsc/bindings/webcore/config.h | 1 + .../jsc/bindings/webcore/weak_handle.cpp | 22 + 123 files changed, 12708 insertions(+), 1005 deletions(-) create mode 100644 src/javascript/jsc/bindings/DOMWrapperWorld-class.h create mode 100644 src/javascript/jsc/bindings/DOMWrapperWorld.cpp create mode 100644 src/javascript/jsc/bindings/DOMWrapperWorld.h create mode 100644 src/javascript/jsc/bindings/JSDOMBinding.h create mode 100644 src/javascript/jsc/bindings/JSDOMGlobalObject.cpp create mode 100644 src/javascript/jsc/bindings/JSDOMGlobalObject.h delete mode 100644 src/javascript/jsc/bindings/JSDOMURL.cpp delete mode 100644 src/javascript/jsc/bindings/JSDOMURL.h create mode 100644 src/javascript/jsc/bindings/JSDOMWrapperCache.cpp create mode 100644 src/javascript/jsc/bindings/JSDOMWrapperCache.h create mode 100644 src/javascript/jsc/bindings/ScriptExecutionContext.h create mode 100644 src/javascript/jsc/bindings/bmalloc_heap_ref.h create mode 100644 src/javascript/jsc/bindings/webcore/ActiveDOMObject.h create mode 100644 src/javascript/jsc/bindings/webcore/BufferSource.h create mode 100644 src/javascript/jsc/bindings/webcore/DOMClientIsoSubspaces.h create mode 100644 src/javascript/jsc/bindings/webcore/DOMConstructors.h create mode 100644 src/javascript/jsc/bindings/webcore/DOMIsoSubspaces.h create mode 100644 src/javascript/jsc/bindings/webcore/ExceptionDetails.h create mode 100644 src/javascript/jsc/bindings/webcore/ExtendedDOMClientIsoSubspaces.h create mode 100644 src/javascript/jsc/bindings/webcore/ExtendedDOMIsoSubspaces.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMAttribute.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMBindingInternalsBuiltins.cpp create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMBindingInternalsBuiltins.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMCastThisValue.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConstructor.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConstructorBase.cpp create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConstructorBase.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConstructorNotCallable.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConstructorNotConstructable.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvert.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertAny.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertBase.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertBoolean.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertBufferSource.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertCallbacks.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertDate.cpp create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertDate.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertDictionary.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertEnumeration.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertEventListener.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertInterface.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertJSON.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertNull.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertNullable.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertNumbers.cpp create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertNumbers.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertObject.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertPromise.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertRecord.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertScheduledAction.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertSequences.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertSerializedScriptValue.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertStrings.cpp create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertStrings.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertUnion.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertVariadic.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertWebGL.cpp create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertWebGL.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMConvertXPathNSResolver.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMException.cpp create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMException.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMGlobalObjectInlines.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMIterator.cpp create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMIterator.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMOperation.h create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMURL.cpp create mode 100644 src/javascript/jsc/bindings/webcore/JSDOMURL.h create mode 100644 src/javascript/jsc/bindings/webcore/JSURLSearchParams.cpp create mode 100644 src/javascript/jsc/bindings/webcore/JSURLSearchParams.dep create mode 100644 src/javascript/jsc/bindings/webcore/JSURLSearchParams.h create mode 100644 src/javascript/jsc/bindings/webcore/JSValueInWrappedObject.h create mode 100644 src/javascript/jsc/bindings/webcore/ScriptWrappable.cpp create mode 100644 src/javascript/jsc/bindings/webcore/ScriptWrappable.h create mode 100644 src/javascript/jsc/bindings/webcore/ScriptWrappableInlines.h create mode 100644 src/javascript/jsc/bindings/webcore/WebCoreJSClientData.h create mode 100644 src/javascript/jsc/bindings/webcore/WebCoreTypedArrayController.cpp create mode 100644 src/javascript/jsc/bindings/webcore/WebCoreTypedArrayController.h create mode 100644 src/javascript/jsc/bindings/webcore/config.h create mode 100644 src/javascript/jsc/bindings/webcore/weak_handle.cpp diff --git a/src/javascript/jsc/bindings/BunBuiltinNames.h b/src/javascript/jsc/bindings/BunBuiltinNames.h index 58c039ceff..bb8449c5ef 100644 --- a/src/javascript/jsc/bindings/BunBuiltinNames.h +++ b/src/javascript/jsc/bindings/BunBuiltinNames.h @@ -2,12 +2,15 @@ #pragma once -#include "helpers.h" #include "root.h" -#include -namespace Bun { +#include "helpers.h" + +#include "JavaScriptCore/BuiltinUtils.h" + + +namespace WebCore { using namespace JSC; @@ -116,5 +119,5 @@ private: BUN_COMMON_PRIVATE_IDENTIFIERS_EACH_PROPERTY_NAME(DECLARE_BUILTIN_NAMES) }; -} // namespace Bun +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/BunClientData.cpp b/src/javascript/jsc/bindings/BunClientData.cpp index 0bda7dd69d..9a4fa25f4d 100644 --- a/src/javascript/jsc/bindings/BunClientData.cpp +++ b/src/javascript/jsc/bindings/BunClientData.cpp @@ -1,39 +1,47 @@ - -#include "BunClientData.h" #include "root.h" -#include "JSDOMURL.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include "BunClientData.h" -// #include "BunGCOutputConstraint.h" +#include "ExtendedDOMClientIsoSubspaces.h" +#include "ExtendedDOMIsoSubspaces.h" +#include "JavaScriptCore/FastMallocAlignedMemoryAllocator.h" +#include "JavaScriptCore/HeapInlines.h" +#include "JavaScriptCore/IsoHeapCellType.h" +#include "JavaScriptCore/JSDestructibleObjectHeapCellType.h" +// #include "JavaScriptCore/MarkingConstraint.h" +#include "JavaScriptCore/SubspaceInlines.h" +#include "JavaScriptCore/VM.h" +#include "wtf/MainThread.h" -namespace Bun { +#include "JSDOMConstructorBase.h" + +#include "BunGCOutputConstraint.h" +#include "WebCoreTypedArrayController.h" + +namespace WebCore { using namespace JSC; -using namespace WebCore; -class ExtendedDOMClientIsoSubspaces; -class ExtendedDOMIsoSubspaces; - -#define CLIENT_ISO_SUBSPACE_INIT(subspace) subspace(m_heapData->subspace) JSHeapData::JSHeapData(Heap& heap) - : m_domNamespaceObjectSpace ISO_SUBSPACE_INIT(heap, heap.cellHeapCellType, JSDOMObject) + // : m_domNamespaceObjectSpace ISO_SUBSPACE_INIT(heap, heap.cellHeapCellType, JSDOMObject) + // , + : m_subspaces(makeUnique()) + , m_domConstructorSpace ISO_SUBSPACE_INIT(heap, heap.cellHeapCellType, JSDOMConstructorBase) { } +#define CLIENT_ISO_SUBSPACE_INIT(subspace) subspace(m_heapData->subspace) + JSVMClientData::JSVMClientData(VM& vm) : m_builtinNames(vm) , m_heapData(JSHeapData::ensureHeapData(vm.heap)) + , CLIENT_ISO_SUBSPACE_INIT(m_domConstructorSpace) + , m_clientSubspaces(makeUnique()) { } +#undef CLIENT_ISO_SUBSPACE_INIT + JSHeapData* JSHeapData::ensureHeapData(Heap& heap) { if (!Options::useGlobalGC()) @@ -53,11 +61,11 @@ void JSVMClientData::create(VM* vm) { JSVMClientData* clientData = new JSVMClientData(*vm); vm->clientData = clientData; // ~VM deletes this pointer. + clientData->m_normalWorld = DOMWrapperWorld::create(*vm, DOMWrapperWorld::Type::Normal); // vm->heap.addMarkingConstraint(makeUnique(*vm, *clientData)); - // vm->m_typedArrayController = adoptRef(new WebCoreTypedArrayController( - // type == WorkerThreadType::DedicatedWorker || type == WorkerThreadType::Worklet)); + // vm->m_typedArrayController = adoptRef(new WebCoreTypedArrayController(true)); } -} // namespace Bun \ No newline at end of file +} // namespace WebCore \ No newline at end of file diff --git a/src/javascript/jsc/bindings/BunClientData.h b/src/javascript/jsc/bindings/BunClientData.h index fc48148cde..4e4573a628 100644 --- a/src/javascript/jsc/bindings/BunClientData.h +++ b/src/javascript/jsc/bindings/BunClientData.h @@ -1,15 +1,31 @@ #pragma once -#include "BunBuiltinNames.h" -#include "root.h" -#include -#include -#include -#include -#include +namespace WebCore { -namespace Bun { +class ExtendedDOMClientIsoSubspaces; +class ExtendedDOMIsoSubspaces; + +class DOMWrapperWorld; +} + +#include "root.h" + +#include "ExtendedDOMClientIsoSubspaces.h" +#include "ExtendedDOMIsoSubspaces.h" +#include "DOMIsoSubspaces.h" +// #include "DOMWrapperWorld.h" +#include "BunBuiltinNames.h" +// #include "WebCoreJSBuiltins.h" +// #include "WorkerThreadType.h" +#include "wtf/Function.h" +#include "wtf/HashSet.h" +#include "wtf/RefPtr.h" + +#include "JavaScriptCore/IsoSubspacePerVM.h" + +namespace WebCore { using namespace JSC; +using namespace Zig; enum class UseCustomHeapCellType { Yes, No }; @@ -25,7 +41,7 @@ public: static JSHeapData* ensureHeapData(JSC::Heap&); Lock& lock() { return m_lock; } - // ExtendedDOMIsoSubspaces& subspaces() { return *m_subspaces.get(); } + ExtendedDOMIsoSubspaces& subspaces() { return *m_subspaces.get(); } Vector& outputConstraintSpaces() { return m_outputConstraintSpaces; } @@ -36,13 +52,15 @@ public: func(*space); } - JSC::IsoSubspace m_domNamespaceObjectSpace; + // JSC::IsoSubspace m_domNamespaceObjectSpace; private: Lock m_lock; private: - // std::unique_ptr m_subspaces; + std::unique_ptr m_subspaces; + JSC::IsoSubspace m_domConstructorSpace; + Vector m_outputConstraintSpaces; }; @@ -59,36 +77,96 @@ public: JSHeapData& heapData() { return *m_heapData; } BunBuiltinNames& builtinNames() { return m_builtinNames; } - // ExtendedDOMClientIsoSubspaces& clientSubspaces() { return *m_clientSubspaces.get(); } - // Vector &outputConstraintSpaces() { return m_outputConstraintSpaces; } + WebCore::DOMWrapperWorld& normalWorld() { return *m_normalWorld; } - // template void forEachOutputConstraintSpace(const Func& func) - // { - // for (auto* space : m_outputConstraintSpaces) - // func(*space); - // } + JSC::GCClient::IsoSubspace& domConstructorSpace() { return m_domConstructorSpace; } + + ExtendedDOMClientIsoSubspaces& clientSubspaces() { return *m_clientSubspaces.get(); } + + Vector& outputConstraintSpaces() { return m_outputConstraintSpaces; } + + template void forEachOutputConstraintSpace(const Func& func) + { + for (auto* space : m_outputConstraintSpaces) + func(*space); + } private: BunBuiltinNames m_builtinNames; JSHeapData* m_heapData; - // Vector m_outputConstraintSpaces; + RefPtr m_normalWorld; + JSC::GCClient::IsoSubspace m_domConstructorSpace; + + // JSC::IsoSubspace m_domNamespaceObjectSpace; + + std::unique_ptr m_clientSubspaces; + Vector m_outputConstraintSpaces; }; template ALWAYS_INLINE JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm, GetClient getClient, SetClient setClient, GetServer getServer, SetServer setServer, JSC::HeapCellType& (*getCustomHeapCellType)(JSHeapData&) = nullptr) { - static NeverDestroyed perVM([](JSC::Heap& heap) { - return ISO_SUBSPACE_PARAMETERS(heap.destructibleObjectHeapCellType, T); - }); - return &perVM.get().clientIsoSubspaceforVM(vm); + auto& clientData = *static_cast(vm.clientData); + auto& clientSubspaces = clientData.clientSubspaces(); + if (auto* clientSpace = getClient(clientSubspaces)) + return clientSpace; + + auto& heapData = clientData.heapData(); + Locker locker { heapData.lock() }; + + auto& subspaces = heapData.subspaces(); + JSC::IsoSubspace* space = getServer(subspaces); + if (!space) { + JSC::Heap& heap = vm.heap; + std::unique_ptr uniqueSubspace; + static_assert(useCustomHeapCellType == UseCustomHeapCellType::Yes || std::is_base_of_v || !T::needsDestruction); + if constexpr (useCustomHeapCellType == UseCustomHeapCellType::Yes) + uniqueSubspace = makeUnique ISO_SUBSPACE_INIT(heap, getCustomHeapCellType(heapData), T); + else { + if constexpr (std::is_base_of_v) + uniqueSubspace = makeUnique ISO_SUBSPACE_INIT(heap, heap.destructibleObjectHeapCellType, T); + else + uniqueSubspace = makeUnique ISO_SUBSPACE_INIT(heap, heap.cellHeapCellType, T); + } + space = uniqueSubspace.get(); + setServer(subspaces, uniqueSubspace); + + IGNORE_WARNINGS_BEGIN("unreachable-code") + IGNORE_WARNINGS_BEGIN("tautological-compare") + void (*myVisitOutputConstraint)(JSC::JSCell*, JSC::SlotVisitor&) = T::visitOutputConstraints; + void (*jsCellVisitOutputConstraint)(JSC::JSCell*, JSC::SlotVisitor&) = JSC::JSCell::visitOutputConstraints; + if (myVisitOutputConstraint != jsCellVisitOutputConstraint) + heapData.outputConstraintSpaces().append(space); + IGNORE_WARNINGS_END + IGNORE_WARNINGS_END + } + + auto uniqueClientSubspace = makeUnique(*space); + auto* clientSpace = uniqueClientSubspace.get(); + setClient(clientSubspaces, uniqueClientSubspace); + return clientSpace; } +// template +// ALWAYS_INLINE JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm, GetClient getClient, SetClient setClient, GetServer getServer, SetServer setServer, JSC::HeapCellType& (*getCustomHeapCellType)(JSHeapData&) = nullptr) +// { +// static NeverDestroyed perVM([](JSC::Heap& heap) { +// return ISO_SUBSPACE_PARAMETERS(heap.destructibleObjectHeapCellType, T); +// }); +// return &perVM.get().clientIsoSubspaceforVM(vm); +// } + static JSVMClientData* clientData(JSC::VM& vm) { - return static_cast(vm.clientData); + return static_cast(vm.clientData); } -} // namespace Bun +} // namespace WebCore + +namespace WebCore { +using JSVMClientData = WebCore::JSVMClientData; +using JSHeapData = WebCore::JSHeapData; +} \ No newline at end of file diff --git a/src/javascript/jsc/bindings/BunGCOutputConstraint.cpp b/src/javascript/jsc/bindings/BunGCOutputConstraint.cpp index 53f4bbb909..ef5bba2448 100644 --- a/src/javascript/jsc/bindings/BunGCOutputConstraint.cpp +++ b/src/javascript/jsc/bindings/BunGCOutputConstraint.cpp @@ -1,53 +1,52 @@ -// #include "BunGCOutputConstraint.h" +#include "BunGCOutputConstraint.h" -// #include "BunClientData.h" -// #include -// #include -// #include -// #include -// #include -// #include +#include "BunClientData.h" +#include "JavaScriptCore/BlockDirectoryInlines.h" +#include "JavaScriptCore/HeapInlines.h" +#include "JavaScriptCore/MarkedBlockInlines.h" +#include "JavaScriptCore/MarkingConstraint.h" +#include "JavaScriptCore/SubspaceInlines.h" +#include "JavaScriptCore/VM.h" -// namespace Bun { +namespace WebCore { -// using namespace JSC; +using namespace JSC; -// BunGCOutputConstraint::BunGCOutputConstraint(VM& vm, Bun::JSVMClientData& clientData) -// : MarkingConstraint("Domo", "DOM Output", ConstraintVolatility::SeldomGreyed, -// ConstraintConcurrency::Concurrent, ConstraintParallelism::Parallel) -// , m_vm(vm) -// , m_clientData(clientData) -// , m_lastExecutionVersion(vm.heap.mutatorExecutionVersion()) -// { -// } +BunGCOutputConstraint::BunGCOutputConstraint(VM& vm, WebCore::JSVMClientData& clientData) + : MarkingConstraint("Domo", "DOM Output", ConstraintVolatility::SeldomGreyed, ConstraintConcurrency::Concurrent, ConstraintParallelism::Parallel) + , m_vm(vm) + , m_clientData(clientData) + , m_lastExecutionVersion(vm.heap.mutatorExecutionVersion()) +{ +} -// template void BunGCOutputConstraint::executeImplImpl(Visitor& visitor) -// { -// Heap& heap = m_vm.heap; +template void BunGCOutputConstraint::executeImplImpl(Visitor& visitor) +{ + Heap& heap = m_vm.heap; -// if (heap.mutatorExecutionVersion() == m_lastExecutionVersion) -// return; + if (heap.mutatorExecutionVersion() == m_lastExecutionVersion) + return; -// m_lastExecutionVersion = heap.mutatorExecutionVersion(); + m_lastExecutionVersion = heap.mutatorExecutionVersion(); -// m_clientData.forEachOutputConstraintSpace([&](Subspace& subspace) { -// auto func = [](Visitor& visitor, HeapCell* heapCell, HeapCell::Kind) { -// SetRootMarkReasonScope rootScope(visitor, RootMarkReason::DOMGCOutput); -// JSCell* cell = static_cast(heapCell); -// cell->methodTable(visitor.vm())->visitOutputConstraints(cell, visitor); -// }; + m_clientData.forEachOutputConstraintSpace([&](Subspace& subspace) { + auto func = [](Visitor& visitor, HeapCell* heapCell, HeapCell::Kind) { + SetRootMarkReasonScope rootScope(visitor, RootMarkReason::DOMGCOutput); + JSCell* cell = static_cast(heapCell); + cell->methodTable(visitor.vm())->visitOutputConstraints(cell, visitor); + }; -// RefPtr> task = subspace.template forEachMarkedCellInParallel(func); -// visitor.addParallelConstraintTask(task); -// }); -// } + RefPtr> task = subspace.template forEachMarkedCellInParallel(func); + visitor.addParallelConstraintTask(task); + }); +} -// void BunGCOutputConstraint::executeImpl(AbstractSlotVisitor& visitor) -// { -// executeImplImpl(visitor); -// } -// void BunGCOutputConstraint::executeImpl(SlotVisitor& visitor) { executeImplImpl(visitor); } +void BunGCOutputConstraint::executeImpl(AbstractSlotVisitor& visitor) +{ + executeImplImpl(visitor); +} +void BunGCOutputConstraint::executeImpl(SlotVisitor& visitor) { executeImplImpl(visitor); } -// } // namespace Bun +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/BunGCOutputConstraint.h b/src/javascript/jsc/bindings/BunGCOutputConstraint.h index 003f110b4e..ad23c5e32e 100644 --- a/src/javascript/jsc/bindings/BunGCOutputConstraint.h +++ b/src/javascript/jsc/bindings/BunGCOutputConstraint.h @@ -1,34 +1,35 @@ -// #pragma once +#pragma once -// #include "root.h" -// #include +#include "root.h" -// namespace JSC { -// class VM; -// } +#include "JavaScriptCore/MarkingConstraint.h" -// namespace Bun { +namespace JSC { +class VM; +} -// class JSVMClientData; +namespace WebCore { -// class BunGCOutputConstraint : public JSC::MarkingConstraint { -// WTF_MAKE_FAST_ALLOCATED; +class JSVMClientData; -// public: -// BunGCOutputConstraint(JSC::VM&, Bun::JSVMClientData&); -// ~BunGCOutputConstraint() {}; +class BunGCOutputConstraint : public JSC::MarkingConstraint { + WTF_MAKE_FAST_ALLOCATED; -// protected: -// void executeImpl(JSC::AbstractSlotVisitor&) override; -// void executeImpl(JSC::SlotVisitor&) override; +public: + BunGCOutputConstraint(JSC::VM&, WebCore::JSVMClientData&); + ~BunGCOutputConstraint() {}; -// private: -// template void executeImplImpl(Visitor&); +protected: + void executeImpl(JSC::AbstractSlotVisitor&) override; + void executeImpl(JSC::SlotVisitor&) override; -// JSC::VM& m_vm; -// JSVMClientData& m_clientData; -// uint64_t m_lastExecutionVersion; -// }; +private: + template void executeImplImpl(Visitor&); -// } // namespace Bun + JSC::VM& m_vm; + JSVMClientData& m_clientData; + uint64_t m_lastExecutionVersion; +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/BunStream.cpp b/src/javascript/jsc/bindings/BunStream.cpp index 2214454bfc..13f330ed02 100644 --- a/src/javascript/jsc/bindings/BunStream.cpp +++ b/src/javascript/jsc/bindings/BunStream.cpp @@ -1,8 +1,10 @@ #include "BunStream.h" -#include -#include +#include "JavaScriptCore/JSMicrotask.h" +#include "JavaScriptCore/ObjectConstructor.h" -namespace Bun { +#include "JavaScriptCore/JSCInlines.h" + +namespace WebCore { using JSGlobalObject = JSC::JSGlobalObject; using Exception = JSC::Exception; using JSValue = JSC::JSValue; @@ -127,7 +129,7 @@ static JSC_DEFINE_HOST_FUNCTION(Readable__on, JSC::VM& vm = globalObject->vm(); auto scope = DECLARE_THROW_SCOPE(vm); - auto thisObject = JSC::jsDynamicCast(vm, callFrame->thisValue()); + auto thisObject = JSC::jsDynamicCast(vm, callFrame->thisValue()); if (UNLIKELY(!thisObject)) { scope.release(); JSC::throwVMTypeError(globalObject, scope); @@ -163,7 +165,7 @@ static JSC_DEFINE_HOST_FUNCTION(Readable__on, extern "C" Bun__Readable* JSC__JSValue__getReadableStreamState(JSC__JSValue value, JSC__VM* vm) { - auto* thisObject = JSC::jsDynamicCast(*vm, JSC::JSValue::decode(value)); + auto* thisObject = JSC::jsDynamicCast(*vm, JSC::JSValue::decode(value)); if (UNLIKELY(!thisObject)) { return nullptr; } @@ -171,17 +173,17 @@ extern "C" Bun__Readable* JSC__JSValue__getReadableStreamState(JSC__JSValue valu } extern "C" Bun__Writable* JSC__JSValue__getWritableStreamState(JSC__JSValue value, JSC__VM* vm) { - auto* thisObject = JSC::jsDynamicCast(*vm, JSC::JSValue::decode(value)); + auto* thisObject = JSC::jsDynamicCast(*vm, JSC::JSValue::decode(value)); if (UNLIKELY(!thisObject)) { return nullptr; } return thisObject->state; } -const JSC::ClassInfo Readable::s_info = { "Readable", &Base::s_info, nullptr, nullptr, +const JSC::ClassInfo Readable::s_info = { "Readable"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(Readable) }; -const JSC::ClassInfo Writable::s_info = { "Writable", &Base::s_info, nullptr, nullptr, +const JSC::ClassInfo Writable::s_info = { "Writable"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(Writable) }; static JSC_DEFINE_HOST_FUNCTION(Readable__once, @@ -194,7 +196,7 @@ static JSC_DEFINE_HOST_FUNCTION(Readable__once, JSC::VM& vm = globalObject->vm(); auto scope = DECLARE_THROW_SCOPE(vm); - auto thisObject = JSC::jsDynamicCast(vm, callFrame->thisValue()); + auto thisObject = JSC::jsDynamicCast(vm, callFrame->thisValue()); if (UNLIKELY(!thisObject)) { scope.release(); JSC::throwVMTypeError(globalObject, scope); @@ -238,7 +240,7 @@ static JSC_DEFINE_HOST_FUNCTION(Writable__on, JSC::VM& vm = globalObject->vm(); auto scope = DECLARE_THROW_SCOPE(vm); - auto thisObject = JSC::jsDynamicCast(vm, callFrame->thisValue()); + auto thisObject = JSC::jsDynamicCast(vm, callFrame->thisValue()); if (UNLIKELY(!thisObject)) { scope.release(); JSC::throwVMTypeError(globalObject, scope); @@ -282,7 +284,7 @@ static JSC_DEFINE_HOST_FUNCTION(Writable__once, JSC::VM& vm = globalObject->vm(); auto scope = DECLARE_THROW_SCOPE(vm); - auto thisObject = JSC::jsDynamicCast(vm, callFrame->thisValue()); + auto thisObject = JSC::jsDynamicCast(vm, callFrame->thisValue()); if (UNLIKELY(!thisObject)) { scope.release(); JSC::throwVMTypeError(globalObject, scope); @@ -319,71 +321,71 @@ static JSC_DEFINE_HOST_FUNCTION(Writable__once, static JSC_DEFINE_HOST_FUNCTION(Readable__read, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { - DEFINE_CALLBACK_FUNCTION_BODY(Bun::Readable, Bun__Readable__read); + DEFINE_CALLBACK_FUNCTION_BODY(WebCore::Readable, Bun__Readable__read); } static JSC_DEFINE_HOST_FUNCTION(Readable__pipe, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { - DEFINE_CALLBACK_FUNCTION_BODY(Bun::Readable, Bun__Readable__pipe); + DEFINE_CALLBACK_FUNCTION_BODY(WebCore::Readable, Bun__Readable__pipe); } static JSC_DEFINE_HOST_FUNCTION(Readable__resume, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { - DEFINE_CALLBACK_FUNCTION_BODY(Bun::Readable, Bun__Readable__resume); + DEFINE_CALLBACK_FUNCTION_BODY(WebCore::Readable, Bun__Readable__resume); } static JSC_DEFINE_HOST_FUNCTION(Readable__unpipe, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { - DEFINE_CALLBACK_FUNCTION_BODY(Bun::Readable, Bun__Readable__unpipe); + DEFINE_CALLBACK_FUNCTION_BODY(WebCore::Readable, Bun__Readable__unpipe); } static JSC_DEFINE_HOST_FUNCTION(Readable__pause, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { - DEFINE_CALLBACK_FUNCTION_BODY(Bun::Readable, Bun__Readable__pause); + DEFINE_CALLBACK_FUNCTION_BODY(WebCore::Readable, Bun__Readable__pause); } static JSC_DEFINE_HOST_FUNCTION(Readable__unshift, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { - DEFINE_CALLBACK_FUNCTION_BODY(Bun::Readable, Bun__Readable__unshift); + DEFINE_CALLBACK_FUNCTION_BODY(WebCore::Readable, Bun__Readable__unshift); } // static JSC_DECLARE_HOST_FUNCTION(Readable__isPaused); // static JSC_DECLARE_HOST_FUNCTION(Writable__setDefaultEncoding); -// static DEFINE_CALLBACK_FUNCTION(Writable__setDefaultEncoding, Bun::Writable, +// static DEFINE_CALLBACK_FUNCTION(Writable__setDefaultEncoding, WebCore::Writable, // Bun__Writable__setDefaultEncoding); static JSC_DEFINE_HOST_FUNCTION(Writable__write, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { - DEFINE_CALLBACK_FUNCTION_BODY(Bun::Writable, Bun__Writable__write); + DEFINE_CALLBACK_FUNCTION_BODY(WebCore::Writable, Bun__Writable__write); } static JSC_DEFINE_HOST_FUNCTION(Writable__end, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { - DEFINE_CALLBACK_FUNCTION_BODY(Bun::Writable, Bun__Writable__end); + DEFINE_CALLBACK_FUNCTION_BODY(WebCore::Writable, Bun__Writable__end); } static JSC_DEFINE_HOST_FUNCTION(Writable__close, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { - DEFINE_CALLBACK_FUNCTION_BODY(Bun::Writable, Bun__Writable__close); + DEFINE_CALLBACK_FUNCTION_BODY(WebCore::Writable, Bun__Writable__close); } static JSC_DEFINE_HOST_FUNCTION(Writable__destroy, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { - DEFINE_CALLBACK_FUNCTION_BODY(Bun::Writable, Bun__Writable__destroy); + DEFINE_CALLBACK_FUNCTION_BODY(WebCore::Writable, Bun__Writable__destroy); } static JSC_DEFINE_HOST_FUNCTION(Writable__cork, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { - DEFINE_CALLBACK_FUNCTION_BODY(Bun::Writable, Bun__Writable__cork); + DEFINE_CALLBACK_FUNCTION_BODY(WebCore::Writable, Bun__Writable__cork); } static JSC_DEFINE_HOST_FUNCTION(Writable__uncork, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { - DEFINE_CALLBACK_FUNCTION_BODY(Bun::Writable, Bun__Writable__uncork); + DEFINE_CALLBACK_FUNCTION_BODY(WebCore::Writable, Bun__Writable__uncork); } extern "C" JSC__JSValue Bun__Readable__create(Bun__Readable* state, @@ -422,7 +424,7 @@ Writable::~Writable() void Readable::finishCreation(JSC::VM& vm) { Base::finishCreation(vm); - auto clientData = Bun::clientData(vm); + auto clientData = WebCore::clientData(vm); auto* globalObject = this->globalObject(); putDirect(vm, clientData->builtinNames().onPublicName(), @@ -469,7 +471,7 @@ void Readable::finishCreation(JSC::VM& vm) void Writable::finishCreation(JSC::VM& vm) { Base::finishCreation(vm); - auto clientData = Bun::clientData(vm); + auto clientData = WebCore::clientData(vm); auto* globalObject = this->globalObject(); @@ -524,4 +526,4 @@ void Writable::finishCreation(JSC::VM& vm) 0); } -} // namespace Bun \ No newline at end of file +} // namespace WebCore \ No newline at end of file diff --git a/src/javascript/jsc/bindings/BunStream.h b/src/javascript/jsc/bindings/BunStream.h index 39d0155586..64837c2191 100644 --- a/src/javascript/jsc/bindings/BunStream.h +++ b/src/javascript/jsc/bindings/BunStream.h @@ -4,7 +4,7 @@ #include "BunClientData.h" #include "root.h" -namespace Bun { +namespace WebCore { using namespace JSC; @@ -39,7 +39,7 @@ public: static Readable* create(JSC::VM& vm, Bun__Readable* state, JSC::Structure* structure) { - Readable* accessor = new (NotNull, JSC::allocateCell(vm)) Readable(vm, state, structure); + Readable* accessor = new (NotNull, JSC::allocateCell(vm)) Readable(vm, state, structure); accessor->finishCreation(vm); return accessor; } @@ -86,4 +86,4 @@ public: void finishCreation(JSC::VM& vm); }; -} // namespace Bun \ No newline at end of file +} // namespace WebCore \ No newline at end of file diff --git a/src/javascript/jsc/bindings/DOMException.h b/src/javascript/jsc/bindings/DOMException.h index b764393c17..f5e48262b3 100644 --- a/src/javascript/jsc/bindings/DOMException.h +++ b/src/javascript/jsc/bindings/DOMException.h @@ -30,7 +30,7 @@ #include "root.h" #include "ExceptionCode.h" -#include +#include "wtf/text/WTFString.h" namespace WebCore { diff --git a/src/javascript/jsc/bindings/DOMFormData.h b/src/javascript/jsc/bindings/DOMFormData.h index 9592afdbe0..d2450d2824 100644 --- a/src/javascript/jsc/bindings/DOMFormData.h +++ b/src/javascript/jsc/bindings/DOMFormData.h @@ -33,8 +33,8 @@ // #include "File.h" // #include // #include -// #include -// #include +// #include "wtf/RefCounted.h" +// #include "wtf/text/WTFString.h" // namespace WebCore { diff --git a/src/javascript/jsc/bindings/DOMURL.cpp b/src/javascript/jsc/bindings/DOMURL.cpp index 8b437b5b72..31381b8673 100644 --- a/src/javascript/jsc/bindings/DOMURL.cpp +++ b/src/javascript/jsc/bindings/DOMURL.cpp @@ -32,7 +32,7 @@ // #include "PublicURLManager.h" // #include "ResourceRequest.h" #include "URLSearchParams.h" -// #include +// #include "wtf/MainThread.h" namespace WebCore { diff --git a/src/javascript/jsc/bindings/DOMURL.h b/src/javascript/jsc/bindings/DOMURL.h index aa7c1eddfb..0a62106906 100644 --- a/src/javascript/jsc/bindings/DOMURL.h +++ b/src/javascript/jsc/bindings/DOMURL.h @@ -30,8 +30,8 @@ #include "ExceptionOr.h" #include "URLDecomposition.h" -#include -#include +#include "wtf/URL.h" +#include "wtf/WeakPtr.h" namespace WebCore { diff --git a/src/javascript/jsc/bindings/DOMWrapperWorld-class.h b/src/javascript/jsc/bindings/DOMWrapperWorld-class.h new file mode 100644 index 0000000000..0c33f37efe --- /dev/null +++ b/src/javascript/jsc/bindings/DOMWrapperWorld-class.h @@ -0,0 +1,65 @@ +#pragma once + +#include "root.h" + +#include "JavaScriptCore/JSCInlines.h" + +#include "wtf/Forward.h" + +namespace WebCore { + +class WindowProxy; + +typedef HashMap> DOMObjectWrapperMap; + +class DOMWrapperWorld : public RefCounted { +public: + enum class Type { + Normal, // Main (e.g. Page) + User, // User Scripts (e.g. Extensions) + Internal, // WebKit Internal (e.g. Media Controls) + }; + + static Ref create(JSC::VM& vm, Type type = Type::Internal, const String& name = {}) + { + return adoptRef(*new DOMWrapperWorld(vm, type, name)); + } + WEBCORE_EXPORT ~DOMWrapperWorld(); + + // Free as much memory held onto by this world as possible. + WEBCORE_EXPORT void clearWrappers(); + + void didCreateWindowProxy(WindowProxy* controller) { m_jsWindowProxies.add(controller); } + void didDestroyWindowProxy(WindowProxy* controller) { m_jsWindowProxies.remove(controller); } + + void setShadowRootIsAlwaysOpen() { m_shadowRootIsAlwaysOpen = true; } + bool shadowRootIsAlwaysOpen() const { return m_shadowRootIsAlwaysOpen; } + + void disableLegacyOverrideBuiltInsBehavior() { m_shouldDisableLegacyOverrideBuiltInsBehavior = true; } + bool shouldDisableLegacyOverrideBuiltInsBehavior() const { return m_shouldDisableLegacyOverrideBuiltInsBehavior; } + + DOMObjectWrapperMap& wrappers() { return m_wrappers; } + + Type type() const { return m_type; } + bool isNormal() const { return m_type == Type::Normal; } + + const String& name() const { return m_name; } + + JSC::VM& vm() const { return m_vm; } + +protected: + DOMWrapperWorld(JSC::VM&, Type, const String& name); + +private: + JSC::VM& m_vm; + HashSet m_jsWindowProxies; + DOMObjectWrapperMap m_wrappers; + + String m_name; + Type m_type { Type::Internal }; + + bool m_shadowRootIsAlwaysOpen { false }; + bool m_shouldDisableLegacyOverrideBuiltInsBehavior { false }; +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/DOMWrapperWorld.cpp b/src/javascript/jsc/bindings/DOMWrapperWorld.cpp new file mode 100644 index 0000000000..f0d92ee849 --- /dev/null +++ b/src/javascript/jsc/bindings/DOMWrapperWorld.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2007 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "root.h" + +#include "DOMWrapperWorld.h" + +// #include "JSDOMWindow.h" +#include "WebCoreJSClientData.h" +// #include "WindowProxy.h" +#include "ZigGlobalObject.h" +#include "wtf/MainThread.h" + +namespace WebCore { + +using namespace JSC; + +DOMWrapperWorld::DOMWrapperWorld(JSC::VM& vm, Type type, const String& name) + : m_vm(vm) + , m_name(name) + , m_type(type) +{ + VM::ClientData* clientData = m_vm.clientData; + ASSERT(clientData); + // static_cast(clientData)->rememberWorld(*this); +} + +DOMWrapperWorld::~DOMWrapperWorld() +{ + VM::ClientData* clientData = m_vm.clientData; + ASSERT(clientData); + // static_cast(clientData)->forgetWorld(*this); +} + +void DOMWrapperWorld::clearWrappers() +{ + m_wrappers.clear(); +} + +DOMWrapperWorld& normalWorld(JSC::VM& vm) +{ + VM::ClientData* clientData = vm.clientData; + ASSERT(clientData); + return static_cast(clientData)->normalWorld(); +} + +// DOMWrapperWorld& mainThreadNormalWorld() +// { +// ASSERT(isMainThread()); +// // static DOMWrapperWorld& cachedNormalWorld = normalWorld(commonVM()); +// return cachedNormalWorld; +// } + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/DOMWrapperWorld.h b/src/javascript/jsc/bindings/DOMWrapperWorld.h new file mode 100644 index 0000000000..c03b5ed418 --- /dev/null +++ b/src/javascript/jsc/bindings/DOMWrapperWorld.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2007 Samuel Weinig + * Copyright (C) 2009 Google, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#pragma once + +#include "root.h" +#include "DOMWrapperWorld-class.h" +#include "ZigGlobalObject.h" + +namespace WebCore { + +DOMWrapperWorld& normalWorld(JSC::VM&); +// WEBCORE_EXPORT DOMWrapperWorld& mainThreadNormalWorld(); + +// inline DOMWrapperWorld& debuggerWorld() { return mainThreadNormalWorld(); } +// inline DOMWrapperWorld& pluginWorld() { return mainThreadNormalWorld(); } + +DOMWrapperWorld& currentWorld(JSC::JSGlobalObject&); +DOMWrapperWorld& worldForDOMObject(JSC::JSObject&); + +// Helper function for code paths that must not share objects across isolated DOM worlds. +bool isWorldCompatible(JSC::JSGlobalObject&, JSC::JSValue); + +inline DOMWrapperWorld& currentWorld(JSC::JSGlobalObject& lexicalGlobalObject); +inline DOMWrapperWorld& worldForDOMObject(JSC::JSObject& object); + +inline bool isWorldCompatible(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + return true; + // return !value.isObject() || &worldForDOMObject(*value.getObject()) == ¤tWorld(lexicalGlobalObject); +} + +inline DOMWrapperWorld& currentWorld(JSC::JSGlobalObject& lexicalGlobalObject) +{ + return JSC::jsCast(&lexicalGlobalObject)->world(); +} +inline DOMWrapperWorld& worldForDOMObject(JSC::JSObject& object) +{ + return JSC::jsCast(object.globalObject())->world(); +}; +} diff --git a/src/javascript/jsc/bindings/Exception.h b/src/javascript/jsc/bindings/Exception.h index e14b1e01a1..8607e31151 100644 --- a/src/javascript/jsc/bindings/Exception.h +++ b/src/javascript/jsc/bindings/Exception.h @@ -29,7 +29,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "root.h" #include "ExceptionCode.h" -#include +#include "wtf/text/WTFString.h" namespace WebCore { diff --git a/src/javascript/jsc/bindings/ExceptionCode.h b/src/javascript/jsc/bindings/ExceptionCode.h index d63691db1c..26c1e4adae 100644 --- a/src/javascript/jsc/bindings/ExceptionCode.h +++ b/src/javascript/jsc/bindings/ExceptionCode.h @@ -20,7 +20,7 @@ #include "root.h" -#include +#include "wtf/EnumTraits.h" namespace WebCore { diff --git a/src/javascript/jsc/bindings/ExceptionOr.h b/src/javascript/jsc/bindings/ExceptionOr.h index 6ffd93fe16..f3378466e0 100644 --- a/src/javascript/jsc/bindings/ExceptionOr.h +++ b/src/javascript/jsc/bindings/ExceptionOr.h @@ -29,9 +29,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "root.h" #include "Exception.h" -#include -#include -#include +#include "wtf/CrossThreadCopier.h" +#include "wtf/Expected.h" +#include "wtf/StdLibExtras.h" namespace WebCore { diff --git a/src/javascript/jsc/bindings/GCDefferalContext.h b/src/javascript/jsc/bindings/GCDefferalContext.h index 7bedfb3e0d..994b168376 100644 --- a/src/javascript/jsc/bindings/GCDefferalContext.h +++ b/src/javascript/jsc/bindings/GCDefferalContext.h @@ -2,6 +2,8 @@ #include "helpers.h" +#include "JavaScriptCore/JSCInlines.h" + namespace JSC { ALWAYS_INLINE GCDeferralContext::GCDeferralContext(VM& vm) diff --git a/src/javascript/jsc/bindings/IDLTypes.h b/src/javascript/jsc/bindings/IDLTypes.h index b597fb2801..cadeea27ef 100644 --- a/src/javascript/jsc/bindings/IDLTypes.h +++ b/src/javascript/jsc/bindings/IDLTypes.h @@ -25,14 +25,14 @@ #pragma once +#include "JavaScriptCore/HandleTypes.h" +#include "JavaScriptCore/Strong.h" #include "StringAdaptors.h" -#include -#include +#include "wtf/Brigand.h" +#include "wtf/StdLibExtras.h" +#include "wtf/URL.h" +#include "wtf/WallTime.h" #include -#include -#include -#include -#include #if ENABLE(WEBGL) #include "WebGLAny.h" diff --git a/src/javascript/jsc/bindings/JSCInlines.h b/src/javascript/jsc/bindings/JSCInlines.h index 8e989aa6aa..30e8b41336 100644 --- a/src/javascript/jsc/bindings/JSCInlines.h +++ b/src/javascript/jsc/bindings/JSCInlines.h @@ -36,22 +36,22 @@ // In fact, it can make a lot of sense: outside of JSC, this file becomes a kind of umbrella // header that pulls in most (all?) of the interesting things in JSC. -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "JavaScriptCore/ExceptionHelpers.h" +#include "JavaScriptCore/GCIncomingRefCountedInlines.h" +#include "JavaScriptCore/HeapInlines.h" +#include "JavaScriptCore/IdentifierInlines.h" +#include "JavaScriptCore/JSArrayBufferViewInlines.h" +#include "JavaScriptCore/JSCJSValueInlines.h" +#include "JavaScriptCore/JSCellInlines.h" +#include "JavaScriptCore/JSFunctionInlines.h" +#include "JavaScriptCore/JSGlobalObjectInlines.h" +#include "JavaScriptCore/JSObjectInlines.h" +#include "JavaScriptCore/JSProxy.h" +#include "JavaScriptCore/JSString.h" +#include "JavaScriptCore/Operations.h" +#include "JavaScriptCore/SlotVisitorInlines.h" +#include "JavaScriptCore/StrongInlines.h" +#include "JavaScriptCore/StructureInlines.h" +#include "JavaScriptCore/ThrowScope.h" +#include "JavaScriptCore/WeakGCMapInlines.h" +#include "JavaScriptCore/WeakGCSetInlines.h" diff --git a/src/javascript/jsc/bindings/JSDOMBinding.h b/src/javascript/jsc/bindings/JSDOMBinding.h new file mode 100644 index 0000000000..dc2096f2ba --- /dev/null +++ b/src/javascript/jsc/bindings/JSDOMBinding.h @@ -0,0 +1,21 @@ +#pragma once + +#include "root.h" + +#include "ExceptionOr.h" +#include "JavaScriptCore/AuxiliaryBarrierInlines.h" +#include "JavaScriptCore/HeapInlines.h" +#include "JavaScriptCore/JSArray.h" +#include "JavaScriptCore/JSCJSValueInlines.h" +#include "JavaScriptCore/JSCellInlines.h" +#include "JavaScriptCore/JSObjectInlines.h" +#include "JavaScriptCore/Lookup.h" +#include "JavaScriptCore/ObjectConstructor.h" +#include "JavaScriptCore/SlotVisitorInlines.h" +#include "JavaScriptCore/StructureInlines.h" +#include "JavaScriptCore/WriteBarrier.h" +#include "wtf/Forward.h" +#include "wtf/GetPtr.h" +#include "wtf/Vector.h" +#include +#include "JavaScriptCore/WeakHandleOwner.h" \ No newline at end of file diff --git a/src/javascript/jsc/bindings/JSDOMExceptionHandling.cpp b/src/javascript/jsc/bindings/JSDOMExceptionHandling.cpp index 84f387bef5..70f3c4d87c 100644 --- a/src/javascript/jsc/bindings/JSDOMExceptionHandling.cpp +++ b/src/javascript/jsc/bindings/JSDOMExceptionHandling.cpp @@ -25,11 +25,11 @@ #include "JSDOMException.h" #include "JSDOMExceptionHandling.h" -#include -#include -#include -#include -#include +#include "JavaScriptCore/ErrorHandlingScope.h" +#include "JavaScriptCore/Exception.h" +#include "JavaScriptCore/ExceptionHelpers.h" +#include "JavaScriptCore/ScriptCallStack.h" +#include "JavaScriptCore/ScriptCallStackFactory.h" namespace WebCore { using namespace JSC; @@ -76,7 +76,7 @@ void reportCurrentException(JSGlobalObject* lexicalGlobalObject) auto scope = DECLARE_CATCH_SCOPE(vm); auto* exception = scope.exception(); scope.clearException(); - reportException(lexicalGlobalObject, exception); + // reportException(lexicalGlobalObject, exception); } JSValue createDOMException(JSGlobalObject* lexicalGlobalObject, ExceptionCode ec, const String& message) @@ -116,7 +116,7 @@ JSValue createDOMException(JSGlobalObject* lexicalGlobalObject, ExceptionCode ec // For now, we're going to assume the lexicalGlobalObject. Which is wrong in cases like this: // frames[0].document.createElement(null, null); // throws an exception which should have the subframe's prototypes. // https://bugs.webkit.org/show_bug.cgi?id=222229 - JSDOMGlobalObject* globalObject = deprecatedGlobalObjectForPrototype(lexicalGlobalObject); + JSDOMGlobalObject* globalObject = JSC::jsCast(lexicalGlobalObject); JSValue errorObject = toJS(lexicalGlobalObject, globalObject, DOMException::create(ec, message)); ASSERT(errorObject); @@ -214,10 +214,10 @@ void throwNonFiniteTypeError(JSGlobalObject& lexicalGlobalObject, JSC::ThrowScop throwTypeError(&lexicalGlobalObject, scope, "The provided value is non-finite"_s); } -JSC::EncodedJSValue rejectPromiseWithGetterTypeError(JSC::JSGlobalObject& lexicalGlobalObject, const JSC::ClassInfo* classInfo, JSC::PropertyName attributeName) -{ - return createRejectedPromiseWithTypeError(lexicalGlobalObject, JSC::makeDOMAttributeGetterTypeErrorMessage(classInfo->className, String(attributeName.uid())), RejectedPromiseWithTypeErrorCause::NativeGetter); -} +// JSC::EncodedJSValue rejectPromiseWithGetterTypeError(JSC::JSGlobalObject& lexicalGlobalObject, const JSC::ClassInfo* classInfo, JSC::PropertyName attributeName) +// { +// return createRejectedPromiseWithTypeError(lexicalGlobalObject, JSC::makeDOMAttributeGetterTypeErrorMessage(classInfo->className, String(attributeName.uid())), RejectedPromiseWithTypeErrorCause::NativeGetter); +// } String makeThisTypeErrorMessage(const char* interfaceName, const char* functionName) { @@ -234,16 +234,16 @@ EncodedJSValue throwThisTypeError(JSC::JSGlobalObject& lexicalGlobalObject, JSC: return throwTypeError(lexicalGlobalObject, scope, makeThisTypeErrorMessage(interfaceName, functionName)); } -JSC::EncodedJSValue rejectPromiseWithThisTypeError(DeferredPromise& promise, const char* interfaceName, const char* methodName) -{ - promise.reject(TypeError, makeThisTypeErrorMessage(interfaceName, methodName)); - return JSValue::encode(jsUndefined()); -} +// JSC::EncodedJSValue rejectPromiseWithThisTypeError(DeferredPromise& promise, const char* interfaceName, const char* methodName) +// { +// promise.reject(TypeError, makeThisTypeErrorMessage(interfaceName, methodName)); +// return JSValue::encode(jsUndefined()); +// } -JSC::EncodedJSValue rejectPromiseWithThisTypeError(JSC::JSGlobalObject& lexicalGlobalObject, const char* interfaceName, const char* methodName) -{ - return createRejectedPromiseWithTypeError(lexicalGlobalObject, makeThisTypeErrorMessage(interfaceName, methodName), RejectedPromiseWithTypeErrorCause::InvalidThis); -} +// JSC::EncodedJSValue rejectPromiseWithThisTypeError(JSC::JSGlobalObject& lexicalGlobalObject, const char* interfaceName, const char* methodName) +// { +// return createRejectedPromiseWithTypeError(lexicalGlobalObject, makeThisTypeErrorMessage(interfaceName, methodName), RejectedPromiseWithTypeErrorCause::InvalidThis); +// } void throwDOMSyntaxError(JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope, ASCIILiteral message) { diff --git a/src/javascript/jsc/bindings/JSDOMExceptionHandling.h b/src/javascript/jsc/bindings/JSDOMExceptionHandling.h index 275dc40320..e90f9aecf3 100644 --- a/src/javascript/jsc/bindings/JSDOMExceptionHandling.h +++ b/src/javascript/jsc/bindings/JSDOMExceptionHandling.h @@ -23,9 +23,13 @@ #pragma once +#include "root.h" + +#include "JavaScriptCore/WeakHandleOwner.h" + #include "ExceptionDetails.h" #include "ExceptionOr.h" -#include +#include "JavaScriptCore/ThrowScope.h" namespace JSC { class CatchScope; @@ -35,7 +39,6 @@ namespace WebCore { class CachedScript; class DeferredPromise; -class JSDOMGlobalObject; void throwAttributeTypeError(JSC::JSGlobalObject&, JSC::ThrowScope&, const char* interfaceName, const char* attributeName, const char* expectedType); @@ -59,9 +62,9 @@ String makeUnsupportedIndexedSetterErrorMessage(const char* interfaceName); WEBCORE_EXPORT JSC::EncodedJSValue throwThisTypeError(JSC::JSGlobalObject&, JSC::ThrowScope&, const char* interfaceName, const char* functionName); -WEBCORE_EXPORT JSC::EncodedJSValue rejectPromiseWithGetterTypeError(JSC::JSGlobalObject&, const JSC::ClassInfo*, JSC::PropertyName attributeName); -WEBCORE_EXPORT JSC::EncodedJSValue rejectPromiseWithThisTypeError(DeferredPromise&, const char* interfaceName, const char* operationName); -WEBCORE_EXPORT JSC::EncodedJSValue rejectPromiseWithThisTypeError(JSC::JSGlobalObject&, const char* interfaceName, const char* operationName); +// WEBCORE_EXPORT JSC::EncodedJSValue rejectPromiseWithGetterTypeError(JSC::JSGlobalObject&, const JSC::ClassInfo*, JSC::PropertyName attributeName); +// WEBCORE_EXPORT JSC::EncodedJSValue rejectPromiseWithThisTypeError(DeferredPromise&, const char* interfaceName, const char* operationName); +// WEBCORE_EXPORT JSC::EncodedJSValue rejectPromiseWithThisTypeError(JSC::JSGlobalObject&, const char* interfaceName, const char* operationName); String retrieveErrorMessageWithoutName(JSC::JSGlobalObject&, JSC::VM&, JSC::JSValue exception, JSC::CatchScope&); String retrieveErrorMessage(JSC::JSGlobalObject&, JSC::VM&, JSC::JSValue exception, JSC::CatchScope&); @@ -88,6 +91,12 @@ inline void propagateException(JSC::JSGlobalObject& lexicalGlobalObject, JSC::Th propagateException(lexicalGlobalObject, throwScope, value.releaseException()); } +inline void propagateException(JSC::JSGlobalObject* lexicalGlobalObject, JSC::ThrowScope& throwScope, ExceptionOr&& value) +{ + if (UNLIKELY(value.hasException())) + propagateException(lexicalGlobalObject, throwScope, value.releaseException()); +} + template void invokeFunctorPropagatingExceptionIfNecessary(JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& throwScope, Functor&& functor) { using ReturnType = std::invoke_result_t; @@ -100,4 +109,16 @@ template void invokeFunctorPropagatingExceptionIfNecessary(JSC functor(); } +template void invokeFunctorPropagatingExceptionIfNecessary(JSC::JSGlobalObject* lexicalGlobalObject, JSC::ThrowScope& throwScope, Functor&& functor) +{ + using ReturnType = std::invoke_result_t; + + if constexpr (IsExceptionOr) { + auto result = functor(); + if (UNLIKELY(result.hasException())) + propagateException(lexicalGlobalObject, throwScope, result.releaseException()); + } else + functor(); +} + } // namespace WebCore diff --git a/src/javascript/jsc/bindings/JSDOMGlobalObject.cpp b/src/javascript/jsc/bindings/JSDOMGlobalObject.cpp new file mode 100644 index 0000000000..98b9e9dec5 --- /dev/null +++ b/src/javascript/jsc/bindings/JSDOMGlobalObject.cpp @@ -0,0 +1,82 @@ +#include "JSDOMGlobalObject.h" +#include "JavaScriptCore/JSCast.h" +#include "ZigGlobalObject.h" + +namespace WebCore { + +// static JSDOMGlobalObject& callerGlobalObject(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame* callFrame, bool skipFirstFrame, bool lookUpFromVMEntryScope) +// { +// VM& vm = lexicalGlobalObject.vm(); +// if (callFrame) { +// class GetCallerGlobalObjectFunctor { +// public: +// GetCallerGlobalObjectFunctor(bool skipFirstFrame) +// : m_skipFirstFrame(skipFirstFrame) +// { +// } + +// StackVisitor::Status operator()(StackVisitor& visitor) const +// { +// if (m_skipFirstFrame) { +// if (!m_hasSkippedFirstFrame) { +// m_hasSkippedFirstFrame = true; +// return StackVisitor::Continue; +// } +// } + +// if (auto* codeBlock = visitor->codeBlock()) +// m_globalObject = codeBlock->globalObject(); +// else { +// ASSERT(visitor->callee().rawPtr()); +// // FIXME: Callee is not an object if the caller is Web Assembly. +// // Figure out what to do here. We can probably get the global object +// // from the top-most Wasm Instance. https://bugs.webkit.org/show_bug.cgi?id=165721 +// if (visitor->callee().isCell() && visitor->callee().asCell()->isObject()) +// m_globalObject = jsCast(visitor->callee().asCell())->globalObject(); +// } +// return StackVisitor::Done; +// } + +// JSC::JSGlobalObject* globalObject() const { return m_globalObject; } + +// private: +// bool m_skipFirstFrame { false }; +// mutable bool m_hasSkippedFirstFrame { false }; +// mutable JSC::JSGlobalObject* m_globalObject { nullptr }; +// }; + +// GetCallerGlobalObjectFunctor iter(skipFirstFrame); +// callFrame->iterate(vm, iter); +// if (iter.globalObject()) +// return *jsCast(iter.globalObject()); +// } + +// // In the case of legacyActiveGlobalObjectForAccessor, it is possible that vm.topCallFrame is nullptr when the script is evaluated as JSONP. +// // Since we put JSGlobalObject to VMEntryScope, we can retrieve the right globalObject from that. +// // For callerGlobalObject, we do not check vm.entryScope to keep it the old behavior. +// if (lookUpFromVMEntryScope) { +// if (vm.entryScope) { +// if (auto* result = vm.entryScope->globalObject()) +// return *jsCast(result); +// } +// } + +// // If we cannot find JSGlobalObject in caller frames, we just return the current lexicalGlobalObject. +// return *jsCast(&lexicalGlobalObject); +// } + +// JSDOMGlobalObject& callerGlobalObject(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame* callFrame) +// { +// constexpr bool skipFirstFrame = true; +// constexpr bool lookUpFromVMEntryScope = false; +// return callerGlobalObject(lexicalGlobalObject, callFrame, skipFirstFrame, lookUpFromVMEntryScope); +// } + +// JSDOMGlobalObject& legacyActiveGlobalObjectForAccessor(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame* callFrame) +// { +// constexpr bool skipFirstFrame = false; +// constexpr bool lookUpFromVMEntryScope = true; +// return callerGlobalObject(lexicalGlobalObject, callFrame, skipFirstFrame, lookUpFromVMEntryScope); +// } + +} \ No newline at end of file diff --git a/src/javascript/jsc/bindings/JSDOMGlobalObject.h b/src/javascript/jsc/bindings/JSDOMGlobalObject.h new file mode 100644 index 0000000000..fe2c099540 --- /dev/null +++ b/src/javascript/jsc/bindings/JSDOMGlobalObject.h @@ -0,0 +1,33 @@ +#pragma once + +#include "root.h" + +#include "DOMWrapperWorld.h" + +#include "JavaScriptCore/HeapInlines.h" +#include "JavaScriptCore/JSGlobalObject.h" +#include "JavaScriptCore/JSObjectInlines.h" +#include "JavaScriptCore/WeakGCMap.h" + +namespace WebCore { + +// Zig::GlobalObject* toJSDOMGlobalObject(ScriptExecutionContext&, DOMWrapperWorld&); +WEBCORE_EXPORT Zig::GlobalObject& callerGlobalObject(JSC::JSGlobalObject&, JSC::CallFrame*); +Zig::GlobalObject& legacyActiveGlobalObjectForAccessor(JSC::JSGlobalObject&, JSC::CallFrame*); + +template +JSClass* toJSDOMGlobalObject(JSC::VM& vm, JSC::JSValue value) +{ + // static_assert(std::is_base_of_v); + + if (auto* object = value.getObject()) { + if (object->type() == JSC::PureForwardingProxyType) + return JSC::jsDynamicCast(vm, JSC::jsCast(object)->target()); + if (object->inherits(vm)) + return JSC::jsCast(object); + } + + return nullptr; +} + +} \ No newline at end of file diff --git a/src/javascript/jsc/bindings/JSDOMURL.cpp b/src/javascript/jsc/bindings/JSDOMURL.cpp deleted file mode 100644 index 05a77957ea..0000000000 --- a/src/javascript/jsc/bindings/JSDOMURL.cpp +++ /dev/null @@ -1,321 +0,0 @@ -#include "root.h" - -#include "JSDOMURL.h" -#include -#include - -namespace WebCore { -using namespace JSC; -using namespace Bun; -using JSGlobalObject = JSC::JSGlobalObject; -using JSValue = JSC::JSValue; -using JSString = JSC::JSString; -using JSModuleLoader = JSC::JSModuleLoader; -using JSModuleRecord = JSC::JSModuleRecord; -using Identifier = JSC::Identifier; -using SourceOrigin = JSC::SourceOrigin; -using JSObject = JSC::JSObject; -using JSNonFinalObject = JSC::JSNonFinalObject; -namespace JSCastingHelpers = JSC::JSCastingHelpers; - -JSC_DEFINE_CUSTOM_GETTER(DOMURL__href_get, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) -{ - auto* thisObject = JSC::jsDynamicCast(lexicalGlobalObject->vm(), JSC::JSValue::decode(thisValue)); - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto& impl = thisObject->wrapped(); - RETURN_IF_EXCEPTION(throwScope, {}); - - return JSValue::encode(JSC::jsStringWithCache(vm, impl.href().string())); -} - -JSC_DEFINE_CUSTOM_GETTER(DOMURL__protocol_get, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) -{ - auto* thisObject = JSC::jsDynamicCast(lexicalGlobalObject->vm(), JSC::JSValue::decode(thisValue)); - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto& impl = thisObject->wrapped(); - RETURN_IF_EXCEPTION(throwScope, {}); - - return JSValue::encode(JSC::jsStringWithCache(vm, impl.protocol())); -} -JSC_DEFINE_CUSTOM_GETTER(DOMURL__username_get, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) -{ - auto* thisObject = JSC::jsDynamicCast(lexicalGlobalObject->vm(), JSC::JSValue::decode(thisValue)); - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto& impl = thisObject->wrapped(); - RETURN_IF_EXCEPTION(throwScope, {}); - return JSValue::encode(JSC::jsStringWithCache(vm, impl.username())); -} -JSC_DEFINE_CUSTOM_GETTER(DOMURL__password_get, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) -{ - auto* thisObject = JSC::jsDynamicCast(lexicalGlobalObject->vm(), JSC::JSValue::decode(thisValue)); - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto& impl = thisObject->wrapped(); - RETURN_IF_EXCEPTION(throwScope, {}); - return JSValue::encode(JSC::jsStringWithCache(vm, impl.password())); -} -JSC_DEFINE_CUSTOM_GETTER(DOMURL__host_get, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) -{ - auto* thisObject = JSC::jsDynamicCast(lexicalGlobalObject->vm(), JSC::JSValue::decode(thisValue)); - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto& impl = thisObject->wrapped(); - RETURN_IF_EXCEPTION(throwScope, {}); - return JSValue::encode(JSC::jsStringWithCache(vm, impl.host())); -} -JSC_DEFINE_CUSTOM_GETTER(DOMURL__hostname_get, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) -{ - auto* thisObject = JSC::jsDynamicCast(lexicalGlobalObject->vm(), JSC::JSValue::decode(thisValue)); - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto& impl = thisObject->wrapped(); - RETURN_IF_EXCEPTION(throwScope, {}); - return JSValue::encode(JSC::jsStringWithCache(vm, impl.hostname())); -} -JSC_DEFINE_CUSTOM_GETTER(DOMURL__port_get, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) -{ - auto* thisObject = JSC::jsDynamicCast(lexicalGlobalObject->vm(), JSC::JSValue::decode(thisValue)); - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto& impl = thisObject->wrapped(); - RETURN_IF_EXCEPTION(throwScope, {}); - return JSValue::encode(JSC::jsStringWithCache(vm, impl.port())); -} -JSC_DEFINE_CUSTOM_GETTER(DOMURL__pathname_get, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) -{ - auto* thisObject = JSC::jsDynamicCast(lexicalGlobalObject->vm(), JSC::JSValue::decode(thisValue)); - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto& impl = thisObject->wrapped(); - RETURN_IF_EXCEPTION(throwScope, {}); - return JSValue::encode(JSC::jsStringWithCache(vm, impl.pathname())); -} -JSC_DEFINE_CUSTOM_GETTER(DOMURL__hash_get, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) -{ - auto* thisObject = JSC::jsDynamicCast(lexicalGlobalObject->vm(), JSC::JSValue::decode(thisValue)); - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto& impl = thisObject->wrapped(); - RETURN_IF_EXCEPTION(throwScope, {}); - return JSValue::encode(JSC::jsStringWithCache(vm, impl.hash())); -} - -JSC_DEFINE_CUSTOM_GETTER(DOMURL__search_get, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) -{ - auto* thisObject = JSC::jsDynamicCast(lexicalGlobalObject->vm(), JSC::JSValue::decode(thisValue)); - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto& impl = thisObject->wrapped(); - RETURN_IF_EXCEPTION(throwScope, {}); - return JSValue::encode(JSC::jsStringWithCache(vm, impl.search())); -} - -JSC_DEFINE_CUSTOM_SETTER(DOMURL__protocol_set, - (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, - JSC::EncodedJSValue value, JSC::PropertyName)) -{ - auto* thisObject = JSC::jsDynamicCast(lexicalGlobalObject->vm(), JSC::JSValue::decode(thisValue)); - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto& impl = thisObject->wrapped(); - invokeFunctorPropagatingExceptionIfNecessary(lexicalGlobalObject, throwScope, [&] { - return impl.setProtocol(JSC::JSValue::decode(value).toWTFString(lexicalGlobalObject)); - }); - - return true; -} -JSC_DEFINE_CUSTOM_SETTER(DOMURL__username_set, - (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, - JSC::EncodedJSValue value, JSC::PropertyName)) -{ - auto* thisObject = JSC::jsDynamicCast(lexicalGlobalObject->vm(), JSC::JSValue::decode(thisValue)); - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto& impl = thisObject->wrapped(); - - invokeFunctorPropagatingExceptionIfNecessary(lexicalGlobalObject, throwScope, [&] { - return impl.setUsername(JSC::JSValue::decode(value).toWTFString(lexicalGlobalObject)); - }); - - return true; -} - -JSC_DEFINE_CUSTOM_SETTER(DOMURL__href_set, - (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, - JSC::EncodedJSValue value, JSC::PropertyName)) -{ - auto* thisObject = JSC::jsDynamicCast(lexicalGlobalObject->vm(), JSC::JSValue::decode(thisValue)); - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto& impl = thisObject->wrapped(); - - invokeFunctorPropagatingExceptionIfNecessary(lexicalGlobalObject, throwScope, [&] { - return impl.setHref(JSC::JSValue::decode(value).toWTFString(lexicalGlobalObject)); - }); - - return true; -} - -JSC_DEFINE_CUSTOM_SETTER(DOMURL__password_set, - (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, - JSC::EncodedJSValue value, JSC::PropertyName)) -{ - auto* thisObject = JSC::jsDynamicCast(lexicalGlobalObject->vm(), JSC::JSValue::decode(thisValue)); - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto& impl = thisObject->wrapped(); - invokeFunctorPropagatingExceptionIfNecessary(lexicalGlobalObject, throwScope, [&] { - return impl.setPassword(JSC::JSValue::decode(value).toWTFString(lexicalGlobalObject)); - }); - - return true; -} -JSC_DEFINE_CUSTOM_SETTER(DOMURL__host_set, - (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, - JSC::EncodedJSValue value, JSC::PropertyName)) -{ - auto* thisObject = JSC::jsDynamicCast(lexicalGlobalObject->vm(), JSC::JSValue::decode(thisValue)); - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto& impl = thisObject->wrapped(); - invokeFunctorPropagatingExceptionIfNecessary(lexicalGlobalObject, throwScope, [&] { - return impl.setHost(JSC::JSValue::decode(value).toWTFString(lexicalGlobalObject)); - }); - - return true; -} -JSC_DEFINE_CUSTOM_SETTER(DOMURL__hostname_set, - (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, - JSC::EncodedJSValue value, JSC::PropertyName)) -{ - auto* thisObject = JSC::jsDynamicCast(lexicalGlobalObject->vm(), JSC::JSValue::decode(thisValue)); - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto& impl = thisObject->wrapped(); - invokeFunctorPropagatingExceptionIfNecessary(lexicalGlobalObject, throwScope, [&] { - return impl.setHostname(JSC::JSValue::decode(value).toWTFString(lexicalGlobalObject)); - }); - - return true; -} -JSC_DEFINE_CUSTOM_SETTER(DOMURL__port_set, - (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, - JSC::EncodedJSValue value, JSC::PropertyName)) -{ - auto* thisObject = JSC::jsDynamicCast(lexicalGlobalObject->vm(), JSC::JSValue::decode(thisValue)); - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto& impl = thisObject->wrapped(); - invokeFunctorPropagatingExceptionIfNecessary(lexicalGlobalObject, throwScope, [&] { - return impl.setPort(JSC::JSValue::decode(value).toWTFString(lexicalGlobalObject)); - }); - - return true; -} -JSC_DEFINE_CUSTOM_SETTER(DOMURL__pathname_set, - (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, - JSC::EncodedJSValue value, JSC::PropertyName)) -{ - auto* thisObject = JSC::jsDynamicCast(lexicalGlobalObject->vm(), JSC::JSValue::decode(thisValue)); - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto& impl = thisObject->wrapped(); - invokeFunctorPropagatingExceptionIfNecessary(lexicalGlobalObject, throwScope, [&] { - return impl.setPathname(JSC::JSValue::decode(value).toWTFString(lexicalGlobalObject)); - }); - - return true; -} -JSC_DEFINE_CUSTOM_SETTER(DOMURL__hash_set, - (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, - JSC::EncodedJSValue value, JSC::PropertyName)) -{ - auto* thisObject = JSC::jsDynamicCast(lexicalGlobalObject->vm(), JSC::JSValue::decode(thisValue)); - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto& impl = thisObject->wrapped(); - invokeFunctorPropagatingExceptionIfNecessary(lexicalGlobalObject, throwScope, [&] { - return impl.setHash(JSC::JSValue::decode(value).toWTFString(lexicalGlobalObject)); - }); - - return true; -} - -JSC_DEFINE_CUSTOM_SETTER(DOMURL__search_set, - (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, - JSC::EncodedJSValue value, JSC::PropertyName)) -{ - auto* thisObject = JSC::jsDynamicCast(lexicalGlobalObject->vm(), JSC::JSValue::decode(thisValue)); - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto& impl = thisObject->wrapped(); - invokeFunctorPropagatingExceptionIfNecessary(lexicalGlobalObject, throwScope, [&] { - return impl.setSearch(JSC::JSValue::decode(value).toWTFString(lexicalGlobalObject)); - }); - - return true; -} - -void JSDOMURL::finishCreation(JSC::VM& vm) -{ - Base::finishCreation(vm); - auto clientData = Bun::clientData(vm); - - putDirectCustomAccessor(vm, clientData->builtinNames().protocolPublicName(), - JSC::CustomGetterSetter::create(vm, DOMURL__protocol_get, DOMURL__protocol_set), - static_cast(JSC::PropertyAttribute::CustomValue)); - - putDirectCustomAccessor(vm, clientData->builtinNames().usernamePublicName(), - JSC::CustomGetterSetter::create(vm, DOMURL__username_get, DOMURL__username_set), - static_cast(JSC::PropertyAttribute::CustomValue)); - - putDirectCustomAccessor(vm, clientData->builtinNames().hrefPublicName(), - JSC::CustomGetterSetter::create(vm, DOMURL__href_get, DOMURL__href_set), - static_cast(JSC::PropertyAttribute::CustomValue)); - - putDirectCustomAccessor(vm, clientData->builtinNames().passwordPublicName(), - JSC::CustomGetterSetter::create(vm, DOMURL__password_get, DOMURL__password_set), - static_cast(JSC::PropertyAttribute::CustomValue)); - - putDirectCustomAccessor(vm, clientData->builtinNames().hostPublicName(), - JSC::CustomGetterSetter::create(vm, DOMURL__host_get, DOMURL__host_set), - static_cast(JSC::PropertyAttribute::CustomValue)); - - putDirectCustomAccessor(vm, clientData->builtinNames().hostnamePublicName(), - JSC::CustomGetterSetter::create(vm, DOMURL__hostname_get, DOMURL__hostname_set), - static_cast(JSC::PropertyAttribute::CustomValue)); - - putDirectCustomAccessor(vm, clientData->builtinNames().portPublicName(), - JSC::CustomGetterSetter::create(vm, DOMURL__port_get, DOMURL__port_set), - static_cast(JSC::PropertyAttribute::CustomValue)); - - putDirectCustomAccessor(vm, clientData->builtinNames().pathnamePublicName(), - JSC::CustomGetterSetter::create(vm, DOMURL__pathname_get, DOMURL__pathname_set), - static_cast(JSC::PropertyAttribute::CustomValue)); - - putDirectCustomAccessor(vm, clientData->builtinNames().hashPublicName(), - JSC::CustomGetterSetter::create(vm, DOMURL__hash_get, DOMURL__hash_set), - static_cast(JSC::PropertyAttribute::CustomValue)); - - putDirectCustomAccessor(vm, clientData->builtinNames().searchPublicName(), - JSC::CustomGetterSetter::create(vm, DOMURL__search_get, DOMURL__search_set), - static_cast(JSC::PropertyAttribute::CustomValue)); -} - -JSC::GCClient::IsoSubspace* JSDOMURL::subspaceForImpl(JSC::VM& vm) -{ - return Bun::subspaceForImpl( - vm, - // this is a placeholder - [](auto& spaces) { return spaces.m_clientSubspaceForExposedToWorkerAndWindow.get(); }, - [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForExposedToWorkerAndWindow = WTFMove(space); }, - [](auto& spaces) { return spaces.m_subspaceForExposedToWorkerAndWindow.get(); }, - [](auto& spaces, auto&& space) { spaces.m_subspaceForExposedToWorkerAndWindow = WTFMove(space); }); -} - -const ClassInfo JSDOMURL::s_info = { "JSDOMURL", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMURL) }; - -} diff --git a/src/javascript/jsc/bindings/JSDOMURL.h b/src/javascript/jsc/bindings/JSDOMURL.h deleted file mode 100644 index edbb280c40..0000000000 --- a/src/javascript/jsc/bindings/JSDOMURL.h +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -#include "BunBuiltinNames.h" -#include "BunClientData.h" -#include "DOMURL.h" -#include "JSDOMWrapper.h" -#include "root.h" - -namespace WebCore { - -using namespace WebCore; -using namespace JSC; - -class JSDOMURL : public JSDOMWrapper { - using Base = JSDOMWrapper; - -public: - JSDOMURL(JSC::Structure* structure, JSC::JSGlobalObject& global, DOMURL& domURL) - : Base(structure, global, domURL) - { - } - - DECLARE_INFO; - - static constexpr unsigned StructureFlags = Base::StructureFlags; - - template static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) - { - if constexpr (mode == JSC::SubspaceAccess::Concurrently) - return nullptr; - return subspaceForImpl(vm); - } - static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm); - - static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, - JSC::JSValue prototype) - { - return JSC::Structure::create(vm, globalObject, prototype, - JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); - } - - static JSDOMURL* create(JSC::Structure* structure, JSC::JSGlobalObject* global, Ref domURL) - { - JSDOMURL* accessor = new (NotNull, JSC::allocateCell(global->vm())) JSDOMURL(structure, *global, WTFMove(domURL)); - accessor->finishCreation(global->vm()); - return accessor; - } - - void finishCreation(JSC::VM& vm); -}; - -} // namespace Zig \ No newline at end of file diff --git a/src/javascript/jsc/bindings/JSDOMWrapper.cpp b/src/javascript/jsc/bindings/JSDOMWrapper.cpp index 5fbb4238ef..e04bd59b4f 100644 --- a/src/javascript/jsc/bindings/JSDOMWrapper.cpp +++ b/src/javascript/jsc/bindings/JSDOMWrapper.cpp @@ -33,7 +33,7 @@ // #include "JSDOMWindow.h" // #include "JSRemoteDOMWindow.h" // #include "SerializedScriptValue.h" -// #include +// #include "JavaScriptCore/Error.h" namespace WebCore { diff --git a/src/javascript/jsc/bindings/JSDOMWrapper.h b/src/javascript/jsc/bindings/JSDOMWrapper.h index ad374ec2db..a281745430 100644 --- a/src/javascript/jsc/bindings/JSDOMWrapper.h +++ b/src/javascript/jsc/bindings/JSDOMWrapper.h @@ -22,10 +22,11 @@ #pragma once #include "root.h" -#include "NodeConstants.h" +#include "JSDOMGlobalObject.h" #include "ZigGlobalObject.h" -#include -#include +#include "NodeConstants.h" +#include "JavaScriptCore/JSDestructibleObject.h" +#include "wtf/SignedPtr.h" namespace WebCore { using namespace Zig; diff --git a/src/javascript/jsc/bindings/JSDOMWrapperCache.cpp b/src/javascript/jsc/bindings/JSDOMWrapperCache.cpp new file mode 100644 index 0000000000..305396b4aa --- /dev/null +++ b/src/javascript/jsc/bindings/JSDOMWrapperCache.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2004-2011, 2013, 2016 Apple Inc. All rights reserved. + * Copyright (C) 2007 Samuel Weinig + * Copyright (C) 2013 Michael Pruett + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "root.h" + +#include "JSDOMWrapperCache.h" + +#include "JavaScriptCore/JSCInlines.h" + +namespace WebCore { +using namespace JSC; + +Structure* getCachedDOMStructure(const JSDOMGlobalObject& globalObject, const ClassInfo* classInfo) +{ + return globalObject.structures().get(classInfo).get(); +} + +Structure* cacheDOMStructure(JSDOMGlobalObject& globalObject, Structure* structure, const ClassInfo* classInfo) +{ + auto addToStructures = [](JSDOMStructureMap& structures, JSDOMGlobalObject& globalObject, Structure* structure, const ClassInfo* classInfo) { + ASSERT(!structures.contains(classInfo)); + return structures.set(classInfo, WriteBarrier(globalObject.vm(), &globalObject, structure)).iterator->value.get(); + }; + if (globalObject.vm().heap.mutatorShouldBeFenced()) { + Locker locker { globalObject.gcLock() }; + return addToStructures(globalObject.structures(), globalObject, structure, classInfo); + } + return addToStructures(globalObject.structures(NoLockingNecessary), globalObject, structure, classInfo); +} + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/JSDOMWrapperCache.h b/src/javascript/jsc/bindings/JSDOMWrapperCache.h new file mode 100644 index 0000000000..beeeb2654b --- /dev/null +++ b/src/javascript/jsc/bindings/JSDOMWrapperCache.h @@ -0,0 +1,227 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2003-2006, 2008-2009, 2013, 2016 Apple Inc. All rights reserved. + * Copyright (C) 2007 Samuel Weinig + * Copyright (C) 2009 Google, Inc. All rights reserved. + * Copyright (C) 2012 Ericsson AB. All rights reserved. + * Copyright (C) 2013 Michael Pruett + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#pragma once + +#include "DOMWrapperWorld.h" +#include "JSDOMGlobalObject.h" +#include "JSDOMWrapper.h" +#include "ScriptWrappable.h" +#include "ScriptWrappableInlines.h" +#include "WebCoreTypedArrayController.h" +#include "JavaScriptCore/JSArrayBuffer.h" +#include "JavaScriptCore/TypedArrayInlines.h" +#include "JavaScriptCore/Weak.h" +#include "JavaScriptCore/WeakInlines.h" + +namespace WebCore { + +WEBCORE_EXPORT JSC::Structure* getCachedDOMStructure(const JSDOMGlobalObject&, const JSC::ClassInfo*); +WEBCORE_EXPORT JSC::Structure* cacheDOMStructure(JSDOMGlobalObject&, JSC::Structure*, const JSC::ClassInfo*); + +template JSC::Structure* getDOMStructure(JSC::VM&, JSDOMGlobalObject&); +template JSC::Structure* deprecatedGetDOMStructure(JSC::JSGlobalObject*); +template JSC::JSObject* getDOMPrototype(JSC::VM&, JSC::JSGlobalObject*); + +JSC::WeakHandleOwner* wrapperOwner(DOMWrapperWorld&, JSC::ArrayBuffer*); +void* wrapperKey(JSC::ArrayBuffer*); + +JSDOMObject* getInlineCachedWrapper(DOMWrapperWorld&, void*); +JSDOMObject* getInlineCachedWrapper(DOMWrapperWorld&, ScriptWrappable*); +JSC::JSArrayBuffer* getInlineCachedWrapper(DOMWrapperWorld&, JSC::ArrayBuffer*); + +bool setInlineCachedWrapper(DOMWrapperWorld&, void*, JSDOMObject*, JSC::WeakHandleOwner*); +bool setInlineCachedWrapper(DOMWrapperWorld&, ScriptWrappable*, JSDOMObject* wrapper, JSC::WeakHandleOwner* wrapperOwner); +bool setInlineCachedWrapper(DOMWrapperWorld&, JSC::ArrayBuffer*, JSC::JSArrayBuffer* wrapper, JSC::WeakHandleOwner* wrapperOwner); + +bool clearInlineCachedWrapper(DOMWrapperWorld&, void*, JSDOMObject*); +bool clearInlineCachedWrapper(DOMWrapperWorld&, ScriptWrappable*, JSDOMObject* wrapper); +bool clearInlineCachedWrapper(DOMWrapperWorld&, JSC::ArrayBuffer*, JSC::JSArrayBuffer* wrapper); + +template JSC::JSObject* getOrCreateWrapper(DOMWrapperWorld&, DOMClass&); + +template JSC::JSObject* getCachedWrapper(DOMWrapperWorld&, DOMClass&); +template inline JSC::JSObject* getCachedWrapper(DOMWrapperWorld& world, Ref& object) { return getCachedWrapper(world, object.get()); } +template void cacheWrapper(DOMWrapperWorld&, DOMClass*, WrapperClass*); +template void uncacheWrapper(DOMWrapperWorld&, DOMClass*, WrapperClass*); +template auto createWrapper(JSDOMGlobalObject*, Ref&&) -> typename std::enable_if::value, typename JSDOMWrapperConverterTraits::WrapperClass*>::type; +template auto createWrapper(JSDOMGlobalObject*, Ref&&) -> typename std::enable_if::value, typename JSDOMWrapperConverterTraits::WrapperClass*>::type; + +template JSC::JSValue wrap(JSC::JSGlobalObject*, DOMWrapperWorld&, DOMClass&); +template JSC::JSValue wrap(JSC::JSGlobalObject*, JSDOMGlobalObject*, DOMClass&); + +// Inline functions and template definitions. + +inline JSDOMGlobalObject* deprecatedGlobalObjectForPrototype(JSC::JSGlobalObject* lexicalGlobalObject) +{ + // FIXME: Callers to this function should be using the global object + // from which the object is being created, instead of assuming the lexical one. + // e.g. subframe.document.body should use the subframe's global object, not the lexical one. + return JSC::jsCast(lexicalGlobalObject); +} + +template inline JSC::Structure* getDOMStructure(JSC::VM& vm, JSDOMGlobalObject& globalObject) +{ + if (JSC::Structure* structure = getCachedDOMStructure(globalObject, WrapperClass::info())) + return structure; + return cacheDOMStructure(globalObject, WrapperClass::createStructure(vm, &globalObject, WrapperClass::createPrototype(vm, globalObject)), WrapperClass::info()); +} + +template inline JSC::Structure* deprecatedGetDOMStructure(JSC::JSGlobalObject* lexicalGlobalObject) +{ + // FIXME: This function is wrong. It uses the wrong global object for creating the prototype structure. + return getDOMStructure(JSC::getVM(lexicalGlobalObject), *deprecatedGlobalObjectForPrototype(lexicalGlobalObject)); +} + +template inline JSC::JSObject* getDOMPrototype(JSC::VM& vm, JSDOMGlobalObject& globalObject) +{ + return JSC::jsCast(asObject(getDOMStructure(vm, globalObject)->storedPrototype())); +} + +inline JSC::WeakHandleOwner* wrapperOwner(DOMWrapperWorld& world, JSC::ArrayBuffer*) +{ + return static_cast(world.vm().m_typedArrayController.get())->wrapperOwner(); +} + +inline void* wrapperKey(JSC::ArrayBuffer* domObject) +{ + return domObject; +} + +inline JSDOMObject* getInlineCachedWrapper(DOMWrapperWorld&, void*) { return nullptr; } +inline bool setInlineCachedWrapper(DOMWrapperWorld&, void*, JSDOMObject*, JSC::WeakHandleOwner*) { return false; } +inline bool clearInlineCachedWrapper(DOMWrapperWorld&, void*, JSDOMObject*) { return false; } + +inline JSDOMObject* getInlineCachedWrapper(DOMWrapperWorld& world, ScriptWrappable* domObject) +{ + if (!world.isNormal()) + return nullptr; + return domObject->wrapper(); +} + +inline JSC::JSArrayBuffer* getInlineCachedWrapper(DOMWrapperWorld& world, JSC::ArrayBuffer* buffer) +{ + if (!world.isNormal()) + return nullptr; + return buffer->m_wrapper.get(); +} + +inline bool setInlineCachedWrapper(DOMWrapperWorld& world, ScriptWrappable* domObject, JSDOMObject* wrapper, JSC::WeakHandleOwner* wrapperOwner) +{ + if (!world.isNormal()) + return false; + domObject->setWrapper(wrapper, wrapperOwner, &world); + return true; +} + +inline bool setInlineCachedWrapper(DOMWrapperWorld& world, JSC::ArrayBuffer* domObject, JSC::JSArrayBuffer* wrapper, JSC::WeakHandleOwner* wrapperOwner) +{ + if (!world.isNormal()) + return false; + domObject->m_wrapper = JSC::Weak(wrapper, wrapperOwner, &world); + return true; +} + +inline bool clearInlineCachedWrapper(DOMWrapperWorld& world, ScriptWrappable* domObject, JSDOMObject* wrapper) +{ + if (!world.isNormal()) + return false; + domObject->clearWrapper(wrapper); + return true; +} + +inline bool clearInlineCachedWrapper(DOMWrapperWorld& world, JSC::ArrayBuffer* domObject, JSC::JSArrayBuffer* wrapper) +{ + if (!world.isNormal()) + return false; + weakClear(domObject->m_wrapper, wrapper); + return true; +} + +template inline JSC::JSObject* getCachedWrapper(DOMWrapperWorld& world, DOMClass& domObject) +{ + if (auto* wrapper = getInlineCachedWrapper(world, &domObject)) + return wrapper; + return world.wrappers().get(wrapperKey(&domObject)); +} + +template inline void cacheWrapper(DOMWrapperWorld& world, DOMClass* domObject, WrapperClass* wrapper) +{ + JSC::WeakHandleOwner* owner = wrapperOwner(world, domObject); + if (setInlineCachedWrapper(world, domObject, wrapper, owner)) + return; + weakAdd(world.wrappers(), wrapperKey(domObject), JSC::Weak(wrapper, owner, &world)); +} + +template inline void uncacheWrapper(DOMWrapperWorld& world, DOMClass* domObject, WrapperClass* wrapper) +{ + if (clearInlineCachedWrapper(world, domObject, wrapper)) + return; + weakRemove(world.wrappers(), wrapperKey(domObject), wrapper); +} + +template inline auto createWrapper(JSDOMGlobalObject* globalObject, Ref&& domObject) -> typename std::enable_if::value, typename JSDOMWrapperConverterTraits::WrapperClass*>::type +{ + using WrapperClass = typename JSDOMWrapperConverterTraits::WrapperClass; + + ASSERT(!getCachedWrapper(globalObject->world(), domObject)); + auto* domObjectPtr = domObject.ptr(); + auto* wrapper = WrapperClass::create(getDOMStructure(globalObject->vm(), *globalObject), globalObject, WTFMove(domObject)); + cacheWrapper(globalObject->world(), domObjectPtr, wrapper); + return wrapper; +} + +template inline auto createWrapper(JSDOMGlobalObject* globalObject, Ref&& domObject) -> typename std::enable_if::value, typename JSDOMWrapperConverterTraits::WrapperClass*>::type +{ + return createWrapper(globalObject, static_reference_cast(WTFMove(domObject))); +} + +template inline JSC::JSValue wrap(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, DOMClass& domObject) +{ + if (auto* wrapper = getCachedWrapper(globalObject->world(), domObject)) + return wrapper; + return toJSNewlyCreated(lexicalGlobalObject, globalObject, Ref(domObject)); +} + +template inline void setSubclassStructureIfNeeded(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, JSC::JSObject* jsObject) +{ + JSC::JSObject* newTarget = callFrame->newTarget().getObject(); + JSC::JSObject* constructor = callFrame->jsCallee(); + if (!newTarget || newTarget == constructor) + return; + + using WrapperClass = typename JSDOMWrapperConverterTraits::WrapperClass; + + JSC::VM& vm = lexicalGlobalObject->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + auto* functionGlobalObject = JSC::getFunctionRealm(lexicalGlobalObject, newTarget); + RETURN_IF_EXCEPTION(scope, void()); + auto* newTargetGlobalObject = JSC::jsCast(functionGlobalObject); + auto* baseStructure = getDOMStructure(vm, *newTargetGlobalObject); + auto* subclassStructure = JSC::InternalFunction::createSubclassStructure(lexicalGlobalObject, newTarget, baseStructure); + RETURN_IF_EXCEPTION(scope, void()); + jsObject->setStructure(vm, subclassStructure); +} + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/Path.cpp b/src/javascript/jsc/bindings/Path.cpp index 460cbebd3d..7e5c51e924 100644 --- a/src/javascript/jsc/bindings/Path.cpp +++ b/src/javascript/jsc/bindings/Path.cpp @@ -1,8 +1,13 @@ -#include "BunClientData.h" + #include "root.h" -#include -#include -#include + +#include "BunClientData.h" + +#include "JavaScriptCore/JSCInlines.h" + +#include "JavaScriptCore/JSFunction.h" +#include "JavaScriptCore/JSMicrotask.h" +#include "JavaScriptCore/ObjectConstructor.h" #pragma mark - Node.js Path @@ -36,7 +41,7 @@ namespace JSCastingHelpers = JSC::JSCastingHelpers; arguments.uncheckedAppend(JSC::JSValue::encode(callFrame->uncheckedArgument(i))); \ } \ } \ - auto clientData = Bun::clientData(vm); \ + auto clientData = WebCore::clientData(vm); \ auto isWindows = thisObject->get(globalObject, clientData->builtinNames().isWindowsPrivateName()); \ JSC::JSValue result = JSC::JSValue::decode( \ ZigFunction(globalObject, isWindows.asBoolean(), reinterpret_cast(arguments.data()), argCount) \ @@ -127,7 +132,7 @@ static JSC::JSObject* createPath(JSGlobalObject* globalThis, bool isWindows) JSC::VM& vm = globalThis->vm(); JSC::Structure* plainObjectStructure = JSC::JSFinalObject::createStructure(vm, globalThis, globalThis->objectPrototype(), 0); JSC::JSObject* path = JSC::JSFinalObject::create(vm, plainObjectStructure); - auto clientData = Bun::clientData(vm); + auto clientData = WebCore::clientData(vm); path->putDirect(vm, clientData->builtinNames().isWindowsPrivateName(), JSC::jsBoolean(isWindows), 0); diff --git a/src/javascript/jsc/bindings/Process.cpp b/src/javascript/jsc/bindings/Process.cpp index e910c4e261..fa0f37efc0 100644 --- a/src/javascript/jsc/bindings/Process.cpp +++ b/src/javascript/jsc/bindings/Process.cpp @@ -1,6 +1,8 @@ #include "Process.h" -#include -#include +#include "JavaScriptCore/JSMicrotask.h" +#include "JavaScriptCore/ObjectConstructor.h" + +#include "JavaScriptCore/JSCInlines.h" #pragma mark - Node.js Process @@ -145,7 +147,7 @@ static JSC_DEFINE_HOST_FUNCTION(Process_functionChdir, void Process::finishCreation(JSC::VM& vm) { Base::finishCreation(vm); - auto clientData = Bun::clientData(vm); + auto clientData = WebCore::clientData(vm); putDirectCustomAccessor(vm, clientData->builtinNames().pidPublicName(), JSC::CustomGetterSetter::create(vm, Process_getPID, nullptr), @@ -223,7 +225,7 @@ void Process::finishCreation(JSC::VM& vm) #endif } -const JSC::ClassInfo Process::s_info = { "Process", &Base::s_info, nullptr, nullptr, +const JSC::ClassInfo Process::s_info = { "Process"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(Process) }; JSC_DEFINE_CUSTOM_GETTER(Process_getTitle, (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) @@ -259,7 +261,7 @@ JSC_DEFINE_CUSTOM_GETTER(Process_getArgv, (JSC::JSGlobalObject * globalObject, J if (!thisObject) { return JSValue::encode(JSC::jsUndefined()); } - auto clientData = Bun::clientData(vm); + auto clientData = WebCore::clientData(vm); if (JSC::JSValue argv = thisObject->getIfPropertyExists( globalObject, clientData->builtinNames().argvPrivateName())) { @@ -284,7 +286,7 @@ JSC_DEFINE_CUSTOM_SETTER(Process_setArgv, return false; } - auto clientData = Bun::clientData(vm); + auto clientData = WebCore::clientData(vm); return thisObject->putDirect(vm, clientData->builtinNames().argvPrivateName(), JSC::JSValue::decode(value)); @@ -305,7 +307,7 @@ JSC_DEFINE_CUSTOM_GETTER(Process_getVersionsLazy, JSC::PropertyName)) { JSC::VM& vm = globalObject->vm(); - auto clientData = Bun::clientData(vm); + auto clientData = WebCore::clientData(vm); Zig::Process* thisObject = JSC::jsDynamicCast(vm, JSValue::decode(thisValue)); if (!thisObject) { @@ -351,7 +353,7 @@ JSC_DEFINE_CUSTOM_SETTER(Process_setVersionsLazy, { JSC::VM& vm = globalObject->vm(); - auto clientData = Bun::clientData(vm); + auto clientData = WebCore::clientData(vm); Zig::Process* thisObject = JSC::jsDynamicCast(vm, JSValue::decode(thisValue)); if (!thisObject) { diff --git a/src/javascript/jsc/bindings/Process.h b/src/javascript/jsc/bindings/Process.h index 5a4e7ec009..a710edbad6 100644 --- a/src/javascript/jsc/bindings/Process.h +++ b/src/javascript/jsc/bindings/Process.h @@ -1,8 +1,9 @@ #pragma once +#include "root.h" + #include "BunBuiltinNames.h" #include "BunClientData.h" -#include "root.h" namespace Zig { diff --git a/src/javascript/jsc/bindings/ScriptExecutionContext.h b/src/javascript/jsc/bindings/ScriptExecutionContext.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/javascript/jsc/bindings/StringAdaptors.h b/src/javascript/jsc/bindings/StringAdaptors.h index cceaa3a3b3..28a732a423 100644 --- a/src/javascript/jsc/bindings/StringAdaptors.h +++ b/src/javascript/jsc/bindings/StringAdaptors.h @@ -25,7 +25,7 @@ #pragma once -#include +#include "wtf/text/WTFString.h" namespace WebCore { diff --git a/src/javascript/jsc/bindings/URLDecomposition.cpp b/src/javascript/jsc/bindings/URLDecomposition.cpp index 2be72c0c68..db2bb7f81e 100644 --- a/src/javascript/jsc/bindings/URLDecomposition.cpp +++ b/src/javascript/jsc/bindings/URLDecomposition.cpp @@ -25,7 +25,7 @@ #include "URLDecomposition.h" -#include +#include "wtf/text/StringToIntegerConversion.h" namespace WebCore { diff --git a/src/javascript/jsc/bindings/URLDecomposition.h b/src/javascript/jsc/bindings/URLDecomposition.h index bf9473dcb2..15ae093847 100644 --- a/src/javascript/jsc/bindings/URLDecomposition.h +++ b/src/javascript/jsc/bindings/URLDecomposition.h @@ -27,9 +27,9 @@ #include "root.h" -#include +#include "wtf/URL.h" -#include +#include "wtf/Forward.h" namespace WebCore { diff --git a/src/javascript/jsc/bindings/URLSearchParams.cpp b/src/javascript/jsc/bindings/URLSearchParams.cpp index 11d86bcebc..0ce9554c7b 100644 --- a/src/javascript/jsc/bindings/URLSearchParams.cpp +++ b/src/javascript/jsc/bindings/URLSearchParams.cpp @@ -25,7 +25,7 @@ #include "URLSearchParams.h" #include "DOMURL.h" -#include +#include "wtf/URLParser.h" namespace WebCore { diff --git a/src/javascript/jsc/bindings/URLSearchParams.h b/src/javascript/jsc/bindings/URLSearchParams.h index a3c6c3171e..3749ed9f9a 100644 --- a/src/javascript/jsc/bindings/URLSearchParams.h +++ b/src/javascript/jsc/bindings/URLSearchParams.h @@ -26,10 +26,10 @@ #include "root.h" #include "ExceptionOr.h" +#include "wtf/Vector.h" +#include "wtf/WeakPtr.h" +#include "wtf/text/WTFString.h" #include -#include -#include -#include namespace WebCore { diff --git a/src/javascript/jsc/bindings/ZigConsoleClient.cpp b/src/javascript/jsc/bindings/ZigConsoleClient.cpp index 318c43e1cf..9c025f0785 100644 --- a/src/javascript/jsc/bindings/ZigConsoleClient.cpp +++ b/src/javascript/jsc/bindings/ZigConsoleClient.cpp @@ -1,13 +1,14 @@ #include "helpers.h" +#include "JavaScriptCore/ConsoleClient.h" +#include "JavaScriptCore/ConsoleMessage.h" +#include "JavaScriptCore/JSString.h" +#include "JavaScriptCore/ScriptArguments.h" #include "ZigConsoleClient.h" -#include -#include -#include -#include -#include +#include "wtf/text/WTFString.h" #include "GCDefferalContext.h" +#include "JavaScriptCore/JSCInlines.h" using ScriptArguments = Inspector::ScriptArguments; using MessageType = JSC::MessageType; diff --git a/src/javascript/jsc/bindings/ZigConsoleClient.h b/src/javascript/jsc/bindings/ZigConsoleClient.h index f8c0731de0..684e928fd4 100644 --- a/src/javascript/jsc/bindings/ZigConsoleClient.h +++ b/src/javascript/jsc/bindings/ZigConsoleClient.h @@ -1,8 +1,8 @@ #pragma once -#include -#include -#include +#include "JavaScriptCore/ConsoleClient.h" +#include "wtf/Vector.h" +#include "wtf/text/WTFString.h" namespace Inspector { class InspectorConsoleAgent; diff --git a/src/javascript/jsc/bindings/ZigGlobalObject.cpp b/src/javascript/jsc/bindings/ZigGlobalObject.cpp index fd43fcaebb..c62457c322 100644 --- a/src/javascript/jsc/bindings/ZigGlobalObject.cpp +++ b/src/javascript/jsc/bindings/ZigGlobalObject.cpp @@ -1,81 +1,86 @@ + #include "ZigGlobalObject.h" + #include "helpers.h" +#include "JavaScriptCore/AggregateError.h" +#include "JavaScriptCore/BytecodeIndex.h" +#include "JavaScriptCore/CallFrameInlines.h" +#include "JavaScriptCore/ClassInfo.h" +#include "JavaScriptCore/CodeBlock.h" +#include "JavaScriptCore/CodeCache.h" +#include "JavaScriptCore/Completion.h" +#include "JavaScriptCore/Error.h" +#include "JavaScriptCore/ErrorInstance.h" +#include "JavaScriptCore/Exception.h" +#include "JavaScriptCore/ExceptionScope.h" +#include "JavaScriptCore/FunctionConstructor.h" +#include "JavaScriptCore/HashMapImpl.h" +#include "JavaScriptCore/HashMapImplInlines.h" +#include "JavaScriptCore/Heap.h" +#include "JavaScriptCore/Identifier.h" +#include "JavaScriptCore/InitializeThreading.h" +#include "JavaScriptCore/IteratorOperations.h" +#include "JavaScriptCore/JSArray.h" +#include "JavaScriptCore/JSCInlines.h" +#include "JavaScriptCore/JSCallbackConstructor.h" +#include "JavaScriptCore/JSCallbackObject.h" +#include "JavaScriptCore/JSCast.h" +#include "JavaScriptCore/JSClassRef.h" +#include "JavaScriptCore/JSMicrotask.h" #include "ZigConsoleClient.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -// #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +// #include "JavaScriptCore/JSContextInternal.h" +#include "JavaScriptCore/CatchScope.h" +#include "JavaScriptCore/DeferredWorkTimer.h" +#include "JavaScriptCore/JSInternalPromise.h" +#include "JavaScriptCore/JSLock.h" +#include "JavaScriptCore/JSMap.h" +#include "JavaScriptCore/JSModuleLoader.h" +#include "JavaScriptCore/JSModuleRecord.h" +#include "JavaScriptCore/JSNativeStdFunction.h" +#include "JavaScriptCore/JSObject.h" +#include "JavaScriptCore/JSPromise.h" +#include "JavaScriptCore/JSSet.h" +#include "JavaScriptCore/JSSourceCode.h" +#include "JavaScriptCore/JSString.h" +#include "JavaScriptCore/JSValueInternal.h" +#include "JavaScriptCore/JSVirtualMachineInternal.h" +#include "JavaScriptCore/ObjectConstructor.h" +#include "JavaScriptCore/OptionsList.h" +#include "JavaScriptCore/ParserError.h" +#include "JavaScriptCore/ScriptExecutable.h" +#include "JavaScriptCore/SourceOrigin.h" +#include "JavaScriptCore/StackFrame.h" +#include "JavaScriptCore/StackVisitor.h" +#include "JavaScriptCore/VM.h" +#include "JavaScriptCore/VMEntryScope.h" +#include "JavaScriptCore/WasmFaultSignalHandler.h" +#include "wtf/Gigacage.h" +#include "wtf/StdLibExtras.h" +#include "wtf/URL.h" +#include "wtf/text/ExternalStringImpl.h" +#include "wtf/text/StringCommon.h" +#include "wtf/text/StringImpl.h" +#include "wtf/text/StringView.h" +#include "wtf/text/WTFString.h" #include -#include -#include -#include -#include -#include -#include -#include -#include +#include "wtf/text/Base64.h" #include #include #include -#include -// #include -#include -#include +// #include "JavaScriptCore/CachedType.h" +#include "JavaScriptCore/JSCallbackObject.h" +#include "JavaScriptCore/JSClassRef.h" #include "BunClientData.h" #include "ZigSourceProvider.h" #include "JSDOMURL.h" +#include "JSURLSearchParams.h" + +#include "Process.h" using JSGlobalObject = JSC::JSGlobalObject; using Exception = JSC::Exception; @@ -125,18 +130,19 @@ extern "C" JSC__JSGlobalObject* Zig__GlobalObject__create(JSClassRef* globalObje auto heapSize = JSC::HeapType::Large; JSC::VM& vm = JSC::VM::create(heapSize).leakRef(); - Bun::JSVMClientData::create(&vm); + + WebCore::JSVMClientData::create(&vm); vm.heap.acquireAccess(); JSC::Wasm::enableFastMemory(); JSC::JSLockHolder locker(vm); - Zig::GlobalObject* globalObject = Zig::GlobalObject::create(vm, Zig::GlobalObject::createStructure(vm, JSC::jsNull())); + Zig::GlobalObject* globalObject = Zig::GlobalObject::create(vm, Zig::GlobalObject::createStructure(vm, JSC::JSGlobalObject::create(vm, JSC::JSGlobalObject::createStructure(vm, JSC::jsNull())), JSC::jsNull())); globalObject->setConsole(globalObject); if (count > 0) { - globalObject->installAPIGlobals(globalObjectClass, count); + globalObject->installAPIGlobals(globalObjectClass, count, vm); } JSC::gcProtect(globalObject); @@ -206,7 +212,9 @@ extern "C" bool Zig__GlobalObject__resetModuleRegistryMap(JSC__JSGlobalObject* g namespace Zig { -const JSC::ClassInfo GlobalObject::s_info = { "GlobalObject", &Base::s_info, nullptr, nullptr, +using namespace WebCore; + +const JSC::ClassInfo GlobalObject::s_info = { "GlobalObject"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(GlobalObject) }; extern "C" JSClassRef* Zig__getAPIGlobals(size_t* count); @@ -215,14 +223,14 @@ extern "C" const JSC__JSValue* Zig__getAPIConstructors(size_t* count, JSC__JSGlo static JSGlobalObject* deriveShadowRealmGlobalObject(JSGlobalObject* globalObject) { auto& vm = globalObject->vm(); - Zig::GlobalObject* shadow = Zig::GlobalObject::create(vm, Zig::GlobalObject::createStructure(vm, JSC::jsNull())); + Zig::GlobalObject* shadow = Zig::GlobalObject::create(vm, Zig::GlobalObject::createStructure(vm, JSC::JSGlobalObject::create(vm, JSC::JSGlobalObject::createStructure(vm, JSC::jsNull())), JSC::jsNull())); shadow->setConsole(shadow); size_t count = 0; JSClassRef* globalObjectClass = Zig__getAPIGlobals(&count); shadow->setConsole(shadow); if (count > 0) { - shadow->installAPIGlobals(globalObjectClass, count); + shadow->installAPIGlobals(globalObjectClass, count, vm); } return shadow; @@ -269,7 +277,7 @@ const JSC::GlobalObjectMethodTable GlobalObject::s_globalObjectMethodTable = { }; void GlobalObject::reportUncaughtExceptionAtEventLoop(JSGlobalObject* globalObject, - Exception* exception) + JSC::Exception* exception) { Zig__GlobalObject__reportUncaughtException(globalObject, exception); } @@ -291,6 +299,28 @@ void GlobalObject::setConsole(void* console) #pragma mark - Globals +JSC_DECLARE_CUSTOM_GETTER(JSDOMURL_getter); + +JSC_DEFINE_CUSTOM_GETTER(JSDOMURL_getter, + (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, + JSC::PropertyName)) +{ + Zig::GlobalObject* thisObject = JSC::jsCast(lexicalGlobalObject); + return JSC::JSValue::encode( + WebCore::JSDOMURL::getConstructor(JSC::getVM(lexicalGlobalObject), thisObject)); +} + +JSC_DECLARE_CUSTOM_GETTER(JSURLSearchParams_getter); + +JSC_DEFINE_CUSTOM_GETTER(JSURLSearchParams_getter, + (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, + JSC::PropertyName)) +{ + Zig::GlobalObject* thisObject = JSC::jsCast(lexicalGlobalObject); + return JSC::JSValue::encode( + WebCore::JSURLSearchParams::getConstructor(JSC::getVM(lexicalGlobalObject), thisObject)); +} + static JSC_DECLARE_CUSTOM_SETTER(property_lazyProcessSetter); static JSC_DECLARE_CUSTOM_GETTER(property_lazyProcessGetter); @@ -309,7 +339,7 @@ JSC_DEFINE_CUSTOM_GETTER(property_lazyProcessGetter, Zig::GlobalObject* globalObject = reinterpret_cast(_globalObject); JSC::VM& vm = globalObject->vm(); - auto clientData = Bun::clientData(vm); + auto clientData = WebCore::clientData(vm); JSC::JSValue processPrivate = globalObject->getIfPropertyExists(globalObject, clientData->builtinNames().processPrivateName()); if (LIKELY(processPrivate)) { return JSC::JSValue::encode(processPrivate); @@ -561,7 +591,7 @@ static JSC_DEFINE_HOST_FUNCTION(functionImportMeta__resolve, return JSC::JSValue::encode(JSC::JSValue {}); } - auto clientData = Bun::clientData(vm); + auto clientData = WebCore::clientData(vm); from = JSC::JSValue::encode(thisObject->get(globalObject, clientData->builtinNames().urlPublicName())); } @@ -592,19 +622,19 @@ static JSC_DEFINE_HOST_FUNCTION(functionReportError, // This is not a publicly exposed API currently. // This is used by the bundler to make Response, Request, FetchEvent, // and any other objects available globally. -void GlobalObject::installAPIGlobals(JSClassRef* globals, int count) +void GlobalObject::installAPIGlobals(JSClassRef* globals, int count, JSC::VM& vm) { - auto clientData = Bun::clientData(vm()); + auto clientData = WebCore::clientData(vm); size_t constructor_count = 0; JSC__JSValue const* constructors = Zig__getAPIConstructors(&constructor_count, this); WTF::Vector extraStaticGlobals; extraStaticGlobals.reserveCapacity((size_t)count + constructor_count + 3 + 10); int i = 0; for (; i < constructor_count; i++) { - auto* object = JSC::jsDynamicCast(vm(), JSC::JSValue::decode(constructors[i]).asCell()->getObject()); + auto* object = JSC::jsDynamicCast(vm, JSC::JSValue::decode(constructors[i]).asCell()->getObject()); extraStaticGlobals.uncheckedAppend( - GlobalPropertyInfo { JSC::Identifier::fromString(vm(), object->get(this, vm().propertyNames->name).toWTFString(this)), + GlobalPropertyInfo { JSC::Identifier::fromString(vm, object->get(this, vm.propertyNames->name).toWTFString(this)), JSC::JSValue(object), JSC::PropertyAttribute::DontDelete | 0 }); } int j = 0; @@ -614,10 +644,10 @@ void GlobalObject::installAPIGlobals(JSClassRef* globals, int count) JSC::JSCallbackObject* object = JSC::JSCallbackObject::create(this, this->callbackObjectStructure(), jsClass, nullptr); if (JSObject* prototype = object->classRef()->prototype(this)) - object->setPrototypeDirect(vm(), prototype); + object->setPrototypeDirect(vm, prototype); extraStaticGlobals.uncheckedAppend( - GlobalPropertyInfo { JSC::Identifier::fromString(vm(), jsClass->className()), + GlobalPropertyInfo { JSC::Identifier::fromString(vm, jsClass->className()), JSC::JSValue(object), JSC::PropertyAttribute::DontDelete | 0 }); } @@ -633,85 +663,143 @@ void GlobalObject::installAPIGlobals(JSClassRef* globals, int count) // JSC::JSCallbackObject *object = // JSC::JSCallbackObject::create(this, this->callbackObjectStructure(), // jsClass, nullptr); - // if (JSObject *prototype = jsClass->prototype(this)) object->setPrototypeDirect(vm(), + // if (JSObject *prototype = jsClass->prototype(this)) object->setPrototypeDirect(vm, // prototype); - // process->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "env"), + // process->putDirect(this->vm, JSC::Identifier::fromString(this->vm, "env"), // JSC::JSValue(object), JSC::PropertyAttribute::DontDelete | 0); // } - JSC::Identifier queueMicrotaskIdentifier = JSC::Identifier::fromString(vm(), "queueMicrotask"_s); + JSC::Identifier queueMicrotaskIdentifier = JSC::Identifier::fromString(vm, "queueMicrotask"_s); extraStaticGlobals.uncheckedAppend( GlobalPropertyInfo { queueMicrotaskIdentifier, - JSC::JSFunction::create(vm(), JSC::jsCast(this), 0, + JSC::JSFunction::create(vm, JSC::jsCast(globalObject()), 0, "queueMicrotask", functionQueueMicrotask), JSC::PropertyAttribute::DontDelete | 0 }); - JSC::Identifier setTimeoutIdentifier = JSC::Identifier::fromString(vm(), "setTimeout"_s); + JSC::Identifier setTimeoutIdentifier = JSC::Identifier::fromString(vm, "setTimeout"_s); extraStaticGlobals.uncheckedAppend( GlobalPropertyInfo { setTimeoutIdentifier, - JSC::JSFunction::create(vm(), JSC::jsCast(this), 0, + JSC::JSFunction::create(vm, JSC::jsCast(globalObject()), 0, "setTimeout", functionSetTimeout), JSC::PropertyAttribute::DontDelete | 0 }); - JSC::Identifier clearTimeoutIdentifier = JSC::Identifier::fromString(vm(), "clearTimeout"_s); + JSC::Identifier clearTimeoutIdentifier = JSC::Identifier::fromString(vm, "clearTimeout"_s); extraStaticGlobals.uncheckedAppend( GlobalPropertyInfo { clearTimeoutIdentifier, - JSC::JSFunction::create(vm(), JSC::jsCast(this), 0, + JSC::JSFunction::create(vm, JSC::jsCast(globalObject()), 0, "clearTimeout", functionClearTimeout), JSC::PropertyAttribute::DontDelete | 0 }); - JSC::Identifier setIntervalIdentifier = JSC::Identifier::fromString(vm(), "setInterval"_s); + JSC::Identifier setIntervalIdentifier = JSC::Identifier::fromString(vm, "setInterval"_s); extraStaticGlobals.uncheckedAppend( GlobalPropertyInfo { setIntervalIdentifier, - JSC::JSFunction::create(vm(), JSC::jsCast(this), 0, + JSC::JSFunction::create(vm, JSC::jsCast(globalObject()), 0, "setInterval", functionSetInterval), JSC::PropertyAttribute::DontDelete | 0 }); - JSC::Identifier clearIntervalIdentifier = JSC::Identifier::fromString(vm(), "clearInterval"_s); + JSC::Identifier clearIntervalIdentifier = JSC::Identifier::fromString(vm, "clearInterval"_s); extraStaticGlobals.uncheckedAppend( GlobalPropertyInfo { clearIntervalIdentifier, - JSC::JSFunction::create(vm(), JSC::jsCast(this), 0, + JSC::JSFunction::create(vm, JSC::jsCast(globalObject()), 0, "clearInterval", functionClearInterval), JSC::PropertyAttribute::DontDelete | 0 }); - JSC::Identifier atobIdentifier = JSC::Identifier::fromString(vm(), "atob"_s); + JSC::Identifier atobIdentifier = JSC::Identifier::fromString(vm, "atob"_s); extraStaticGlobals.uncheckedAppend( GlobalPropertyInfo { atobIdentifier, - JSC::JSFunction::create(vm(), JSC::jsCast(this), 0, + JSC::JSFunction::create(vm, JSC::jsCast(globalObject()), 0, "atob", functionATOB), JSC::PropertyAttribute::DontDelete | 0 }); - JSC::Identifier btoaIdentifier = JSC::Identifier::fromString(vm(), "btoa"_s); + JSC::Identifier btoaIdentifier = JSC::Identifier::fromString(vm, "btoa"_s); extraStaticGlobals.uncheckedAppend( GlobalPropertyInfo { btoaIdentifier, - JSC::JSFunction::create(vm(), JSC::jsCast(this), 0, + JSC::JSFunction::create(vm, JSC::jsCast(globalObject()), 0, "btoa", functionBTOA), JSC::PropertyAttribute::DontDelete | 0 }); - JSC::Identifier reportErrorIdentifier = JSC::Identifier::fromString(vm(), "reportError"_s); + JSC::Identifier reportErrorIdentifier = JSC::Identifier::fromString(vm, "reportError"_s); extraStaticGlobals.uncheckedAppend( GlobalPropertyInfo { reportErrorIdentifier, - JSC::JSFunction::create(vm(), JSC::jsCast(this), 0, + JSC::JSFunction::create(vm, JSC::jsCast(globalObject()), 0, + "reportError", functionReportError), + JSC::PropertyAttribute::DontDelete | 0 }); + + JSC::Identifier URLConstructor = JSC::Identifier::fromString(vm, "URL"_s); + extraStaticGlobals.uncheckedAppend( + GlobalPropertyInfo { reportErrorIdentifier, + JSC::JSFunction::create(vm, JSC::jsCast(globalObject()), 0, "reportError", functionReportError), JSC::PropertyAttribute::DontDelete | 0 }); this->addStaticGlobals(extraStaticGlobals.data(), extraStaticGlobals.size()); - putDirectCustomAccessor( - vm(), clientData->builtinNames().processPublicName(), - JSC::CustomGetterSetter::create(vm(), property_lazyProcessGetter, property_lazyProcessSetter), - PropertyAttribute::DontDelete | JSC::PropertyAttribute::CustomAccessor | 0); - auto domURL = WebCore::DOMURL::create("https://example.com/"_s, WTF::String()); - auto url = WebCore::JSDOMURL::create( - WebCore::JSDOMURL::createStructure(vm(), this, objectPrototype()), - this, - domURL.returnValue().get()); + putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "URL"), JSC::CustomGetterSetter::create(vm, JSDOMURL_getter, nullptr), + JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); - this->putDirect(vm(), clientData->builtinNames().urlPublicName(), JSC::JSValue(url), JSC::PropertyAttribute::DontDelete | 0); + putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "URLSearchParams"), JSC::CustomGetterSetter::create(vm, JSURLSearchParams_getter, nullptr), + JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); extraStaticGlobals.releaseBuffer(); } +template +void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor) +{ + GlobalObject* thisObject = jsCast(cell); + ASSERT_GC_OBJECT_INHERITS(thisObject, info()); + Base::visitChildren(thisObject, visitor); + + { + // The GC thread has to grab the GC lock even though it is not mutating the containers. + Locker locker { thisObject->m_gcLock }; + + for (auto& structure : thisObject->m_structures.values()) + visitor.append(structure); + + // for (auto& guarded : thisObject->m_guardedObjects) + // guarded->visitAggregate(visitor); + } + + for (auto& constructor : thisObject->constructors().array()) + visitor.append(constructor); + + // thisObject->m_builtinInternalFunctions.visit(visitor); +} + +DEFINE_VISIT_CHILDREN(GlobalObject); + +// void GlobalObject::destroy(JSCell* cell) +// { +// static_cast(cell)->Zig::GlobalObject::~Zig::GlobalObject(); +// } + +// template +// void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor) +// { +// Zig::GlobalObject* thisObject = jsCast(cell); +// ASSERT_GC_OBJECT_INHERITS(thisObject, info()); +// Base::visitChildren(thisObject, visitor); + +// { +// // The GC thread has to grab the GC lock even though it is not mutating the containers. +// Locker locker { thisObject->m_gcLock }; + +// for (auto& structure : thisObject->m_structures.values()) +// visitor.append(structure); + +// for (auto& guarded : thisObject->m_guardedObjects) +// guarded->visitAggregate(visitor); +// } + +// for (auto& constructor : thisObject->constructors().array()) +// visitor.append(constructor); + +// thisObject->m_builtinInternalFunctions.visit(visitor); +// } + +// DEFINE_VISIT_CHILDREN(Zig::GlobalObject); + JSC::Identifier GlobalObject::moduleLoaderResolve(JSGlobalObject* globalObject, JSModuleLoader* loader, JSValue key, JSValue referrer, JSValue origin) @@ -835,7 +923,7 @@ JSC::JSObject* GlobalObject::moduleLoaderCreateImportMetaProperties(JSGlobalObje JSC::JSObject* metaProperties = JSC::constructEmptyObject(vm, globalObject->nullPrototypeObjectStructure()); RETURN_IF_EXCEPTION(scope, nullptr); - auto clientData = Bun::clientData(vm); + auto clientData = WebCore::clientData(vm); JSString* keyString = key.toStringOrNull(globalObject); if (UNLIKELY(!keyString)) { return metaProperties; diff --git a/src/javascript/jsc/bindings/ZigGlobalObject.h b/src/javascript/jsc/bindings/ZigGlobalObject.h index e5f65578f4..8ac226220d 100644 --- a/src/javascript/jsc/bindings/ZigGlobalObject.h +++ b/src/javascript/jsc/bindings/ZigGlobalObject.h @@ -1,51 +1,98 @@ -#include "root.h" #pragma once -#include "headers-handwritten.h" - namespace JSC { class Structure; class Identifier; } // namespace JSC -#include "Process.h" +#include "root.h" + +#include "headers-handwritten.h" +#include "BunClientData.h" + +#include "JavaScriptCore/CatchScope.h" +#include "JavaScriptCore/JSGlobalObject.h" +#include "JavaScriptCore/JSTypeInfo.h" +#include "JavaScriptCore/Structure.h" + #include "ZigConsoleClient.h" -#include -#include -#include -#include + +#include "DOMConstructors.h" +#include "DOMWrapperWorld-class.h" +#include "DOMIsoSubspaces.h" namespace Zig { +using JSDOMStructureMap = HashMap>; + class GlobalObject : public JSC::JSGlobalObject { using Base = JSC::JSGlobalObject; public: - DECLARE_EXPORT_INFO; + static const JSC::ClassInfo s_info; static const JSC::GlobalObjectMethodTable s_globalObjectMethodTable; - Zig::Process* m_process; - static constexpr bool needsDestruction = true; - template - static GCClient::IsoSubspace* subspaceFor(VM& vm) + static constexpr bool needsDestruction = false; + + template static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) { - return vm.globalObjectSpace(); + if constexpr (mode == JSC::SubspaceAccess::Concurrently) + return nullptr; + return WebCore::subspaceForImpl( + vm, + [](auto& spaces) { return spaces.m_clientSubspaceForGlobalObject.get(); }, + [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForGlobalObject = WTFMove(space); }, + [](auto& spaces) { return spaces.m_subspaceForGlobalObject.get(); }, + [](auto& spaces, auto&& space) { spaces.m_subspaceForGlobalObject = WTFMove(space); }); } + ~GlobalObject(); + + static constexpr const JSC::ClassInfo* info() { return &s_info; } + + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* global, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, global, prototype, JSC::TypeInfo(JSC::GlobalObjectType, StructureFlags), info()); + } + + // Make binding code generation easier. + GlobalObject* globalObject() { return this; } + static GlobalObject* create(JSC::VM& vm, JSC::Structure* structure) { - auto* object = new (NotNull, JSC::allocateCell(vm)) GlobalObject(vm, structure); - object->finishCreation(vm); - return object; + GlobalObject* ptr = new (NotNull, JSC::allocateCell(vm)) GlobalObject(vm, structure); + ptr->finishCreation(vm); + return ptr; } - static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSValue prototype) + const JSDOMStructureMap& structures() const WTF_IGNORES_THREAD_SAFETY_ANALYSIS { - auto* result = JSC::Structure::create( - vm, nullptr, prototype, JSC::TypeInfo(JSC::GlobalObjectType, Base::StructureFlags), info()); - result->setTransitionWatchpointIsLikelyToBeFired(true); - return result; + ASSERT(!Thread::mayBeGCThread()); + return m_structures; } + const WebCore::DOMConstructors& constructors() const + { + ASSERT(!Thread::mayBeGCThread()); + return *m_constructors; + } + + WebCore::DOMWrapperWorld& world() { return m_world.get(); } + + DECLARE_VISIT_CHILDREN; + + bool worldIsNormal() const { return m_worldIsNormal; } + static ptrdiff_t offsetOfWorldIsNormal() { return OBJECT_OFFSETOF(GlobalObject, m_worldIsNormal); } + + JSDOMStructureMap& structures() WTF_REQUIRES_LOCK(m_gcLock) { return m_structures; } + JSDOMStructureMap& structures(NoLockingNecessaryTag) WTF_IGNORES_THREAD_SAFETY_ANALYSIS + { + ASSERT(!vm().heap.mutatorShouldBeFenced()); + return m_structures; + } + + WebCore::DOMConstructors& constructors() { return *m_constructors; } + + Lock& gcLock() WTF_RETURNS_LOCK(m_gcLock) { return m_gcLock; } static void reportUncaughtExceptionAtEventLoop(JSGlobalObject*, JSC::Exception*); static JSGlobalObject* deriveShadowRealmGlobalObject(JSGlobalObject* globalObject); @@ -67,13 +114,24 @@ public: static void promiseRejectionTracker(JSGlobalObject*, JSC::JSPromise*, JSC::JSPromiseRejectionOperation); void setConsole(void* console); - void installAPIGlobals(JSClassRef* globals, int count); + void installAPIGlobals(JSClassRef* globals, int count, JSC::VM& vm); private: GlobalObject(JSC::VM& vm, JSC::Structure* structure) : JSC::JSGlobalObject(vm, structure, &s_globalObjectMethodTable) + , m_constructors(makeUnique()) + , m_world(WebCore::DOMWrapperWorld::create(vm, WebCore::DOMWrapperWorld::Type::Normal)) + , m_worldIsNormal(true) { } + +private: + std::unique_ptr m_constructors; + uint8_t m_worldIsNormal; + JSDOMStructureMap m_structures WTF_GUARDED_BY_LOCK(m_gcLock); + Lock m_gcLock; + + Ref m_world; }; class JSMicrotaskCallback : public RefCounted { @@ -105,3 +163,11 @@ private: }; } // namespace Zig + +namespace WebCore { +using JSDOMGlobalObject = Zig::GlobalObject; +} + +namespace WebCore { +using JSDOMGlobalObject = Zig::GlobalObject; +} diff --git a/src/javascript/jsc/bindings/ZigSourceProvider.cpp b/src/javascript/jsc/bindings/ZigSourceProvider.cpp index 2112a15df0..4e426b4491 100644 --- a/src/javascript/jsc/bindings/ZigSourceProvider.cpp +++ b/src/javascript/jsc/bindings/ZigSourceProvider.cpp @@ -1,13 +1,16 @@ -#include "ZigSourceProvider.h" -#include "helpers.h" #include "root.h" -#include -#include -#include +#include "helpers.h" + +#include "ZigSourceProvider.h" + +#include "JavaScriptCore/BytecodeCacheError.h" +#include "JavaScriptCore/CodeCache.h" + +#include "JavaScriptCore/Completion.h" +#include "wtf/Scope.h" +#include "wtf/text/StringHash.h" #include -#include -#include extern "C" void RefString__free(void*, void*, unsigned); diff --git a/src/javascript/jsc/bindings/ZigSourceProvider.h b/src/javascript/jsc/bindings/ZigSourceProvider.h index cf668e3e0c..cd45a02171 100644 --- a/src/javascript/jsc/bindings/ZigSourceProvider.h +++ b/src/javascript/jsc/bindings/ZigSourceProvider.h @@ -10,13 +10,13 @@ class SourceCodeKey; class SourceProvider; } // namespace JSC +#include "JavaScriptCore/CachedBytecode.h" +#include "JavaScriptCore/JSGlobalObject.h" +#include "JavaScriptCore/JSTypeInfo.h" #include "ZigConsoleClient.h" -#include -#include -#include -// #include -#include -#include +// #include "JavaScriptCore/SourceCodeKey.h" +#include "JavaScriptCore/SourceProvider.h" +#include "JavaScriptCore/Structure.h" namespace Zig { diff --git a/src/javascript/jsc/bindings/bindings.cpp b/src/javascript/jsc/bindings/bindings.cpp index 3a155f5dd1..24a8c9625b 100644 --- a/src/javascript/jsc/bindings/bindings.cpp +++ b/src/javascript/jsc/bindings/bindings.cpp @@ -1,49 +1,53 @@ +#include "root.h" + #include "BunClientData.h" #include "GCDefferalContext.h" + +#include "JavaScriptCore/AggregateError.h" +#include "JavaScriptCore/BytecodeIndex.h" +#include "JavaScriptCore/CodeBlock.h" +#include "JavaScriptCore/Completion.h" +#include "JavaScriptCore/DeferredWorkTimer.h" +#include "JavaScriptCore/ErrorInstance.h" +#include "JavaScriptCore/ExceptionHelpers.h" +#include "JavaScriptCore/ExceptionScope.h" +#include "JavaScriptCore/FunctionConstructor.h" +#include "JavaScriptCore/HeapSnapshotBuilder.h" +#include "JavaScriptCore/Identifier.h" +#include "JavaScriptCore/IteratorOperations.h" +#include "JavaScriptCore/JSArray.h" +#include "JavaScriptCore/JSArrayBuffer.h" +#include "JavaScriptCore/JSArrayInlines.h" +#include "JavaScriptCore/JSCInlines.h" +#include "JavaScriptCore/JSCallbackObject.h" +#include "JavaScriptCore/JSClassRef.h" +#include "JavaScriptCore/JSInternalPromise.h" +#include "JavaScriptCore/JSMap.h" +#include "JavaScriptCore/JSModuleLoader.h" +#include "JavaScriptCore/JSModuleRecord.h" +#include "JavaScriptCore/JSNativeStdFunction.h" +#include "JavaScriptCore/JSONObject.h" +#include "JavaScriptCore/JSObject.h" +#include "JavaScriptCore/JSSet.h" +#include "JavaScriptCore/JSString.h" +#include "JavaScriptCore/Microtask.h" +#include "JavaScriptCore/ObjectConstructor.h" +#include "JavaScriptCore/ParserError.h" +#include "JavaScriptCore/ScriptExecutable.h" +#include "JavaScriptCore/StackFrame.h" +#include "JavaScriptCore/StackVisitor.h" +#include "JavaScriptCore/VM.h" +#include "JavaScriptCore/WasmFaultSignalHandler.h" +#include "JavaScriptCore/Watchdog.h" #include "ZigGlobalObject.h" #include "helpers.h" -#include "root.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include + +#include "wtf/text/ExternalStringImpl.h" +#include "wtf/text/StringCommon.h" +#include "wtf/text/StringImpl.h" +#include "wtf/text/StringView.h" +#include "wtf/text/WTFString.h" + extern "C" { JSC__JSValue SystemError__toErrorInstance(const SystemError* arg0, @@ -66,7 +70,7 @@ JSC__JSValue SystemError__toErrorInstance(const SystemError* arg0, JSC::Structure* errorStructure = globalObject->errorStructure(); JSC::JSObject* result = JSC::ErrorInstance::create(globalObject, errorStructure, message, options); - auto clientData = Bun::clientData(vm); + auto clientData = WebCore::clientData(vm); if (err.code.len > 0) { JSC::JSValue code = Zig::toJSString(err.code, globalObject); @@ -642,7 +646,7 @@ JSC__JSValue JSC__JSValue__createRangeError(const ZigString* message, const ZigS 0); if (code.len > 0) { - auto clientData = Bun::clientData(vm); + auto clientData = WebCore::clientData(vm); JSC::JSValue codeValue = Zig::toJSStringValue(code, globalObject); rangeError->putDirect(vm, clientData->builtinNames().codePublicName(), codeValue, JSC::PropertyAttribute::ReadOnly | 0); @@ -665,7 +669,7 @@ JSC__JSValue JSC__JSValue__createTypeError(const ZigString* message, const ZigSt 0); if (code.len > 0) { - auto clientData = Bun::clientData(vm); + auto clientData = WebCore::clientData(vm); JSC::JSValue codeValue = Zig::toJSStringValue(code, globalObject); typeError->putDirect(vm, clientData->builtinNames().codePublicName(), codeValue, 0); } @@ -1184,77 +1188,77 @@ void JSC__SourceCode__fromString(JSC__SourceCode* arg0, const WTF__String* arg1, #pragma mark - JSC::JSFunction -JSC__JSValue JSC__JSFunction__callWithArguments(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, - JSC__JSValue* arg2, size_t arg3, - JSC__Exception** arg4, const unsigned char* arg5) -{ - auto args = makeArgs(arg2, arg3); - return JSC::JSValue::encode(JSC::call(arg1, JSC::JSValue::decode(JSValue0), - JSC::JSValue::decode(JSValue0), args, (const char*)arg5)); -} -JSC__JSValue JSC__JSFunction__callWithArgumentsAndThis(JSC__JSValue JSValue0, JSC__JSValue JSValue1, - JSC__JSGlobalObject* arg2, - JSC__JSValue* arg3, size_t arg4, - JSC__Exception** arg5, - const unsigned char* arg6) -{ - auto args = makeArgs(arg3, arg4); - return JSC::JSValue::encode(JSC::call(arg2, JSC::JSValue::decode(JSValue0), - JSC::JSValue::decode(JSValue1), args, (const char*)arg6)); -} -JSC__JSValue JSC__JSFunction__callWithoutAnyArgumentsOrThis(JSC__JSValue JSValue0, - JSC__JSGlobalObject* arg1, - JSC__Exception** arg2, - const unsigned char* arg3) -{ - return JSC::JSValue::encode(JSC::call(arg1, JSC::JSValue::decode(JSValue0), - JSC::JSValue::decode(JSValue0), JSC::ArgList(), - (const char*)arg3)); -} -JSC__JSValue JSC__JSFunction__callWithThis(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, - JSC__JSValue JSValue2, JSC__Exception** arg3, - const unsigned char* arg4) -{ - return JSC::JSValue::encode(JSC::call(arg1, JSC::JSValue::decode(JSValue0), - JSC::JSValue::decode(JSValue2), JSC::ArgList(), - (const char*)arg4)); -} -JSC__JSValue JSC__JSFunction__constructWithArguments(JSC__JSValue JSValue0, - JSC__JSGlobalObject* arg1, JSC__JSValue* arg2, - size_t arg3, JSC__Exception** arg4, - const unsigned char* arg5) -{ - auto args = makeArgs(arg2, arg3); - return JSC::JSValue::encode( - JSC::construct(arg1, JSC::JSValue::decode(JSValue0), args, (const char*)arg5)); -} +// JSC__JSValue JSC__JSFunction__callWithArguments(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, +// JSC__JSValue* arg2, size_t arg3, +// JSC__Exception** arg4, const unsigned char* arg5) +// { +// auto args = makeArgs(arg2, arg3); +// return JSC::JSValue::encode(JSC::call(arg1, JSC::JSValue::decode(JSValue0), +// JSC::JSValue::decode(JSValue0), args, (const char*)arg5)); +// } +// JSC__JSValue JSC__JSFunction__callWithArgumentsAndThis(JSC__JSValue JSValue0, JSC__JSValue JSValue1, +// JSC__JSGlobalObject* arg2, +// JSC__JSValue* arg3, size_t arg4, +// JSC__Exception** arg5, +// const unsigned char* arg6) +// { +// auto args = makeArgs(arg3, arg4); +// return JSC::JSValue::encode(JSC::call(arg2, JSC::JSValue::decode(JSValue0), +// JSC::JSValue::decode(JSValue1), args, (const char*)arg6)); +// } +// JSC__JSValue JSC__JSFunction__callWithoutAnyArgumentsOrThis(JSC__JSValue JSValue0, +// JSC__JSGlobalObject* arg1, +// JSC__Exception** arg2, +// const unsigned char* arg3) +// { +// return JSC::JSValue::encode(JSC::call(arg1, JSC::JSValue::decode(JSValue0), +// JSC::JSValue::decode(JSValue0), JSC::ArgList(), +// (const char*)arg3)); +// } +// JSC__JSValue JSC__JSFunction__callWithThis(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, +// JSC__JSValue JSValue2, JSC__Exception** arg3, +// const unsigned char* arg4) +// { +// return JSC::JSValue::encode(JSC::call(arg1, JSC::JSValue::decode(JSValue0), +// JSC::JSValue::decode(JSValue2), JSC::ArgList(), +// (const char*)arg4)); +// } +// JSC__JSValue JSC__JSFunction__constructWithArguments(JSC__JSValue JSValue0, +// JSC__JSGlobalObject* arg1, JSC__JSValue* arg2, +// size_t arg3, JSC__Exception** arg4, +// const unsigned char* arg5) +// { +// auto args = makeArgs(arg2, arg3); +// return JSC::JSValue::encode( +// JSC::construct(arg1, JSC::JSValue::decode(JSValue0), args, (const char*)arg5)); +// } -JSC__JSValue JSC__JSFunction__constructWithArgumentsAndNewTarget( - JSC__JSValue JSValue0, JSC__JSValue JSValue1, JSC__JSGlobalObject* arg2, JSC__JSValue* arg3, - size_t arg4, JSC__Exception** arg5, const unsigned char* arg6) -{ - auto args = makeArgs(arg3, arg4); - return JSC::JSValue::encode(JSC::construct(arg2, JSC::JSValue::decode(JSValue0), - JSC::JSValue::decode(JSValue0), args, - (const char*)arg6)); -} -JSC__JSValue JSC__JSFunction__constructWithNewTarget(JSC__JSValue JSValue0, - JSC__JSGlobalObject* arg1, - JSC__JSValue JSValue2, JSC__Exception** arg3, - const unsigned char* arg4) -{ - return JSC::JSValue::encode(JSC::construct(arg1, JSC::JSValue::decode(JSValue0), - JSC::JSValue::decode(JSValue2), JSC::ArgList(), - (const char*)arg4)); -} -JSC__JSValue JSC__JSFunction__constructWithoutAnyArgumentsOrNewTarget(JSC__JSValue JSValue0, - JSC__JSGlobalObject* arg1, - JSC__Exception** arg2, - const unsigned char* arg3) -{ - return JSC::JSValue::encode( - JSC::construct(arg1, JSC::JSValue::decode(JSValue0), JSC::ArgList(), (const char*)arg3)); -} +// JSC__JSValue JSC__JSFunction__constructWithArgumentsAndNewTarget( +// JSC__JSValue JSValue0, JSC__JSValue JSValue1, JSC__JSGlobalObject* arg2, JSC__JSValue* arg3, +// size_t arg4, JSC__Exception** arg5, const unsigned char* arg6) +// { +// auto args = makeArgs(arg3, arg4); +// return JSC::JSValue::encode(JSC::construct(arg2, JSC::JSValue::decode(JSValue0), +// JSC::JSValue::decode(JSValue0), args, +// (const char*)arg6)); +// } +// JSC__JSValue JSC__JSFunction__constructWithNewTarget(JSC__JSValue JSValue0, +// JSC__JSGlobalObject* arg1, +// JSC__JSValue JSValue2, JSC__Exception** arg3, +// const unsigned char* arg4) +// { +// return JSC::JSValue::encode(JSC::construct(arg1, JSC::JSValue::decode(JSValue0), +// JSC::JSValue::decode(JSValue2), JSC::ArgList(), +// (const char*)arg4)); +// } +// JSC__JSValue JSC__JSFunction__constructWithoutAnyArgumentsOrNewTarget(JSC__JSValue JSValue0, +// JSC__JSGlobalObject* arg1, +// JSC__Exception** arg2, +// const unsigned char* arg3) +// { +// return JSC::JSValue::encode( +// JSC::construct(arg1, JSC::JSValue::decode(JSValue0), JSC::ArgList(), (const char*)arg3)); +// } JSC__JSFunction* JSC__JSFunction__createFromNative(JSC__JSGlobalObject* arg0, uint16_t arg1, const WTF__String* arg2, void* ctx, @@ -2035,7 +2039,7 @@ static void fromErrorInstance(ZigException* except, JSC::JSGlobalObject* global, except->name = Zig::toZigString(err->sanitizedNameString(global)); except->runtime_type = err->runtimeTypeForCause(); - auto clientData = Bun::clientData(global->vm()); + auto clientData = WebCore::clientData(global->vm()); if (except->code != SYNTAX_ERROR_CODE) { if (JSC::JSValue syscall = obj->getIfPropertyExists(global, clientData->builtinNames().syscallPublicName())) { @@ -2643,7 +2647,7 @@ bWTF__String WTF__URL__stringWithoutFragmentIdentifier(WTF__URL* arg0) }; bWTF__StringView WTF__URL__stringWithoutQueryOrFragmentIdentifier(WTF__URL* arg0) { - auto result = arg0->stringWithoutQueryOrFragmentIdentifier(); + auto result = arg0->viewWithoutQueryOrFragmentIdentifier(); return cast(&result); }; bWTF__URL WTF__URL__truncatedForUseAsBase(WTF__URL* arg0) diff --git a/src/javascript/jsc/bindings/bindings.zig b/src/javascript/jsc/bindings/bindings.zig index 6b45fdb1bc..ffb7baae0b 100644 --- a/src/javascript/jsc/bindings/bindings.zig +++ b/src/javascript/jsc/bindings/bindings.zig @@ -19,7 +19,7 @@ pub const JSObject = extern struct { pub const shim = Shimmer("JSC", "JSObject", @This()); bytes: shim.Bytes, const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "JavaScriptCore/JSObject.h"; pub const name = "JSC::JSObject"; pub const namespace = "JSC"; @@ -384,7 +384,7 @@ pub const JSCell = extern struct { pub const shim = Shimmer("JSC", "JSCell", @This()); bytes: shim.Bytes, const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "JavaScriptCore/JSCell.h"; pub const name = "JSC::JSCell"; pub const namespace = "JSC"; @@ -411,7 +411,7 @@ pub const JSString = extern struct { pub const shim = Shimmer("JSC", "JSString", @This()); bytes: shim.Bytes, const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "JavaScriptCore/JSString.h"; pub const name = "JSC::JSString"; pub const namespace = "JSC"; @@ -463,7 +463,7 @@ pub const ScriptArguments = extern struct { pub const shim = Shimmer("Inspector", "ScriptArguments", @This()); bytes: shim.Bytes, const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "JavaScriptCore/ScriptArguments.h"; pub const name = "Inspector::ScriptArguments"; pub const namespace = "Inspector"; @@ -569,7 +569,7 @@ pub const JSModuleLoader = extern struct { pub const shim = Shimmer("JSC", "JSModuleLoader", @This()); bytes: shim.Bytes, const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "JavaScriptCore/JSModuleLoader.h"; pub const name = "JSC::JSModuleLoader"; pub const namespace = "JSC"; @@ -663,7 +663,7 @@ pub const JSModuleRecord = extern struct { pub const shim = Shimmer("JSC", "JSModuleRecord", @This()); bytes: shim.Bytes, const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "JavaScriptCore/JSModuleRecord.h"; pub const name = "JSC::JSModuleRecord"; pub const namespace = "JSC"; @@ -682,7 +682,7 @@ pub const JSPromise = extern struct { pub const shim = Shimmer("JSC", "JSPromise", @This()); bytes: shim.Bytes, const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "JavaScriptCore/JSPromise.h"; pub const name = "JSC::JSPromise"; pub const namespace = "JSC"; @@ -769,7 +769,7 @@ pub const JSInternalPromise = extern struct { pub const shim = Shimmer("JSC", "JSInternalPromise", @This()); bytes: shim.Bytes, const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "JavaScriptCore/JSInternalPromise.h"; pub const name = "JSC::JSInternalPromise"; pub const namespace = "JSC"; @@ -988,7 +988,7 @@ pub const SourceOrigin = extern struct { pub const shim = Shimmer("JSC", "SourceOrigin", @This()); bytes: shim.Bytes, const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "JavaScriptCore/SourceOrigin.h"; pub const name = "JSC::SourceOrigin"; pub const namespace = "JSC"; @@ -1005,7 +1005,7 @@ pub const SourceCode = extern struct { pub const shim = Shimmer("JSC", "SourceCode", @This()); bytes: shim.Bytes, const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "JavaScriptCore/SourceProvider.h"; pub const name = "JSC::SourceCode"; pub const namespace = "JSC"; @@ -1022,7 +1022,7 @@ pub const JSFunction = extern struct { pub const shim = Shimmer("JSC", "JSFunction", @This()); bytes: shim.Bytes, const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "JavaScriptCore/JSFunction.h"; pub const name = "JSC::JSFunction"; pub const namespace = "JSC"; @@ -1224,7 +1224,7 @@ pub const JSGlobalObject = extern struct { pub const shim = Shimmer("JSC", "JSGlobalObject", @This()); bytes: shim.Bytes, - pub const include = ""; + pub const include = "JavaScriptCore/JSGlobalObject.h"; pub const name = "JSC::JSGlobalObject"; pub const namespace = "JSC"; @@ -1395,7 +1395,7 @@ fn _JSCellStub(comptime str: []const u8) type { fn _Bun(comptime str: []const u8) type { if (is_bindgen) { return opaque { - pub const name = "Bun::" ++ str ++ ""; + pub const name = "WebCore::" ++ str ++ ""; }; } else { return opaque {}; @@ -1416,7 +1416,7 @@ pub const URL = extern struct { pub const shim = Shimmer("WTF", "URL", @This()); bytes: shim.Bytes, const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "wtf/URL.h"; pub const name = "WTF::URL"; pub const namespace = "WTF"; @@ -1547,7 +1547,7 @@ pub const String = extern struct { pub const shim = Shimmer("WTF", "String", @This()); bytes: shim.Bytes, const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "wtf/text/WTFString.h"; pub const name = "WTF::String"; pub const namespace = "WTF"; @@ -1638,7 +1638,7 @@ pub const JSValue = enum(u64) { pub const Type = u64; const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "JavaScriptCore/JSValue.h"; pub const name = "JSC::JSValue"; pub const namespace = "JSC"; pub const zero = @intToEnum(JSValue, @as(u64, 0)); @@ -2430,7 +2430,7 @@ pub const PropertyName = extern struct { const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "JavaScriptCore/PropertyName.h"; pub const name = "JSC::PropertyName"; pub const namespace = "JSC"; @@ -2463,7 +2463,7 @@ pub const Exception = extern struct { pub const Type = JSObject; const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "JavaScriptCore/Exception.h"; pub const name = "JSC::Exception"; pub const namespace = "JSC"; @@ -2502,7 +2502,7 @@ pub const JSLock = extern struct { const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "JavaScriptCore/JSLock.h"; pub const name = "JSC::JSLock"; pub const namespace = "JSC"; @@ -2522,7 +2522,7 @@ pub const VM = extern struct { const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "JavaScriptCore/VM.h"; pub const name = "JSC::VM"; pub const namespace = "JSC"; @@ -2639,7 +2639,7 @@ pub const ThrowScope = extern struct { const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "JavaScriptCore/ThrowScope.h"; pub const name = "JSC::ThrowScope"; pub const namespace = "JSC"; @@ -2678,7 +2678,7 @@ pub const CatchScope = extern struct { const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "JavaScriptCore/CatchScope.h"; pub const name = "JSC::CatchScope"; pub const namespace = "JSC"; @@ -2711,7 +2711,7 @@ pub const CallFrame = extern struct { bytes: shim.Bytes, const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "JavaScriptCore/CallFrame.h"; pub const name = "JSC::CallFrame"; pub const namespace = "JSC"; @@ -2767,7 +2767,7 @@ pub const CallFrame = extern struct { // // -// pub const include = ""; +// pub const include = "JavaScriptCore/CommonIdentifiers.h"; // pub const name = "JSC::CommonIdentifiers"; // pub const namespace = "JSC"; @@ -2795,7 +2795,7 @@ pub const EncodedJSValue = enum(i64) { pub const Type = u64; const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "JavaScriptCore/EncodedJSValue.h"; pub const name = "JSC::EncodedJSValue"; pub const namespace = "JSC"; }; @@ -2805,7 +2805,7 @@ pub const Identifier = extern struct { bytes: shim.Bytes, const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "JavaScriptCore/Identifier.h"; pub const name = "JSC::Identifier"; pub const namespace = "JSC"; @@ -2892,7 +2892,7 @@ pub const StringImpl = extern struct { bytes: shim.Bytes, const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "wtf/text/StringImpl.h"; pub const name = "WTF::StringImpl"; pub const namespace = "WTF"; @@ -2940,7 +2940,7 @@ pub const ExternalStringImpl = extern struct { bytes: shim.Bytes, const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "wtf/text/ExternalStringImpl.h"; pub const name = "WTF::ExternalStringImpl"; pub const namespace = "WTF"; @@ -3015,7 +3015,7 @@ pub const StringView = extern struct { bytesA: u64, const cppFn = shim.cppFn; - pub const include = ""; + pub const include = "wtf/text/StringView.h"; pub const name = "WTF::StringView"; pub const namespace = "WTF"; diff --git a/src/javascript/jsc/bindings/bmalloc_heap_ref.h b/src/javascript/jsc/bindings/bmalloc_heap_ref.h new file mode 100644 index 0000000000..d83e484833 --- /dev/null +++ b/src/javascript/jsc/bindings/bmalloc_heap_ref.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2021 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef BMALLOC_HEAP_REF_H +#define BMALLOC_HEAP_REF_H + +#include +#include + +PAS_BEGIN_EXTERN_C; + +#define BMALLOC_HEAP_REF_INITIALIZER(passed_type) \ + ((pas_heap_ref) { \ + .type = (const pas_heap_type*)(passed_type), \ + .heap = NULL, \ + .allocator_index = 0 }) + +#define BMALLOC_PRIMITIVE_HEAP_REF_INITIALIZER_IMPL(passed_type) \ + ((pas_primitive_heap_ref) { \ + .base = BMALLOC_HEAP_REF_INITIALIZER(passed_type), \ + .cached_index = UINT_MAX }) + +#define BMALLOC_FLEX_HEAP_REF_INITIALIZER(passed_type) \ + BMALLOC_PRIMITIVE_HEAP_REF_INITIALIZER_IMPL(passed_type) + +#define BMALLOC_AUXILIARY_HEAP_REF_INITIALIZER(passed_type) \ + BMALLOC_PRIMITIVE_HEAP_REF_INITIALIZER_IMPL(passed_type) + +PAS_END_EXTERN_C; + +#endif /* BMALLOC_HEAP_REF_H */ diff --git a/src/javascript/jsc/bindings/exports.zig b/src/javascript/jsc/bindings/exports.zig index 4715b95f0b..8c6cb17c99 100644 --- a/src/javascript/jsc/bindings/exports.zig +++ b/src/javascript/jsc/bindings/exports.zig @@ -275,7 +275,7 @@ pub const JSErrorCode = enum(u8) { URIError = 6, AggregateError = 7, - // StackOverflow & OutOfMemoryError is not an ErrorType in within JSC, so the number here is just totally made up + // StackOverflow & OutOfMemoryError is not an ErrorType in "JavaScriptCore/ErrorType.h" within JSC, so the number here is just totally made up OutOfMemoryError = 8, BundlerError = 252, StackOverflow = 253, diff --git a/src/javascript/jsc/bindings/header-gen.zig b/src/javascript/jsc/bindings/header-gen.zig index cf8987ab54..612f862158 100644 --- a/src/javascript/jsc/bindings/header-gen.zig +++ b/src/javascript/jsc/bindings/header-gen.zig @@ -621,7 +621,7 @@ pub fn HeaderGen(comptime first_import: type, comptime second_import: type, comp \\ \\#ifdef __cplusplus \\#include "root.h" - \\#include + \\#include "JavaScriptCore/JSClassRef.h" \\#endif \\#include "headers-handwritten.h" \\ diff --git a/src/javascript/jsc/bindings/headers-cpp.h b/src/javascript/jsc/bindings/headers-cpp.h index 4375e000e8..aa51de7e7a 100644 --- a/src/javascript/jsc/bindings/headers-cpp.h +++ b/src/javascript/jsc/bindings/headers-cpp.h @@ -1,4 +1,4 @@ -//-- AUTOGENERATED FILE -- 1648167213 +//-- AUTOGENERATED FILE -- 1648440945 // clang-format off #pragma once @@ -8,201 +8,201 @@ #include "root.h" -#ifndef INCLUDED__JavaScriptCore_JSObject_h_ -#define INCLUDED__JavaScriptCore_JSObject_h_ -#include +#ifndef INCLUDED_JavaScriptCore_JSObject_h +#define INCLUDED_JavaScriptCore_JSObject_h +#include JavaScriptCore/JSObject.h #endif extern "C" const size_t JSC__JSObject_object_size_ = sizeof(JSC::JSObject); extern "C" const size_t JSC__JSObject_object_align_ = alignof(JSC::JSObject); -#ifndef INCLUDED__JavaScriptCore_JSCell_h_ -#define INCLUDED__JavaScriptCore_JSCell_h_ -#include +#ifndef INCLUDED_JavaScriptCore_JSCell_h +#define INCLUDED_JavaScriptCore_JSCell_h +#include JavaScriptCore/JSCell.h #endif extern "C" const size_t JSC__JSCell_object_size_ = sizeof(JSC::JSCell); extern "C" const size_t JSC__JSCell_object_align_ = alignof(JSC::JSCell); -#ifndef INCLUDED__JavaScriptCore_JSString_h_ -#define INCLUDED__JavaScriptCore_JSString_h_ -#include +#ifndef INCLUDED_JavaScriptCore_JSString_h +#define INCLUDED_JavaScriptCore_JSString_h +#include JavaScriptCore/JSString.h #endif extern "C" const size_t JSC__JSString_object_size_ = sizeof(JSC::JSString); extern "C" const size_t JSC__JSString_object_align_ = alignof(JSC::JSString); -#ifndef INCLUDED__JavaScriptCore_ScriptArguments_h_ -#define INCLUDED__JavaScriptCore_ScriptArguments_h_ -#include +#ifndef INCLUDED_JavaScriptCore_ScriptArguments_h +#define INCLUDED_JavaScriptCore_ScriptArguments_h +#include JavaScriptCore/ScriptArguments.h #endif extern "C" const size_t Inspector__ScriptArguments_object_size_ = sizeof(Inspector::ScriptArguments); extern "C" const size_t Inspector__ScriptArguments_object_align_ = alignof(Inspector::ScriptArguments); -#ifndef INCLUDED__JavaScriptCore_JSModuleLoader_h_ -#define INCLUDED__JavaScriptCore_JSModuleLoader_h_ -#include +#ifndef INCLUDED_JavaScriptCore_JSModuleLoader_h +#define INCLUDED_JavaScriptCore_JSModuleLoader_h +#include JavaScriptCore/JSModuleLoader.h #endif extern "C" const size_t JSC__JSModuleLoader_object_size_ = sizeof(JSC::JSModuleLoader); extern "C" const size_t JSC__JSModuleLoader_object_align_ = alignof(JSC::JSModuleLoader); -#ifndef INCLUDED__JavaScriptCore_JSModuleRecord_h_ -#define INCLUDED__JavaScriptCore_JSModuleRecord_h_ -#include +#ifndef INCLUDED_JavaScriptCore_JSModuleRecord_h +#define INCLUDED_JavaScriptCore_JSModuleRecord_h +#include JavaScriptCore/JSModuleRecord.h #endif extern "C" const size_t JSC__JSModuleRecord_object_size_ = sizeof(JSC::JSModuleRecord); extern "C" const size_t JSC__JSModuleRecord_object_align_ = alignof(JSC::JSModuleRecord); -#ifndef INCLUDED__JavaScriptCore_JSPromise_h_ -#define INCLUDED__JavaScriptCore_JSPromise_h_ -#include +#ifndef INCLUDED_JavaScriptCore_JSPromise_h +#define INCLUDED_JavaScriptCore_JSPromise_h +#include JavaScriptCore/JSPromise.h #endif extern "C" const size_t JSC__JSPromise_object_size_ = sizeof(JSC::JSPromise); extern "C" const size_t JSC__JSPromise_object_align_ = alignof(JSC::JSPromise); -#ifndef INCLUDED__JavaScriptCore_JSInternalPromise_h_ -#define INCLUDED__JavaScriptCore_JSInternalPromise_h_ -#include +#ifndef INCLUDED_JavaScriptCore_JSInternalPromise_h +#define INCLUDED_JavaScriptCore_JSInternalPromise_h +#include JavaScriptCore/JSInternalPromise.h #endif extern "C" const size_t JSC__JSInternalPromise_object_size_ = sizeof(JSC::JSInternalPromise); extern "C" const size_t JSC__JSInternalPromise_object_align_ = alignof(JSC::JSInternalPromise); -#ifndef INCLUDED__JavaScriptCore_SourceOrigin_h_ -#define INCLUDED__JavaScriptCore_SourceOrigin_h_ -#include +#ifndef INCLUDED_JavaScriptCore_SourceOrigin_h +#define INCLUDED_JavaScriptCore_SourceOrigin_h +#include JavaScriptCore/SourceOrigin.h #endif extern "C" const size_t JSC__SourceOrigin_object_size_ = sizeof(JSC::SourceOrigin); extern "C" const size_t JSC__SourceOrigin_object_align_ = alignof(JSC::SourceOrigin); -#ifndef INCLUDED__JavaScriptCore_SourceProvider_h_ -#define INCLUDED__JavaScriptCore_SourceProvider_h_ -#include +#ifndef INCLUDED_JavaScriptCore_SourceProvider_h +#define INCLUDED_JavaScriptCore_SourceProvider_h +#include JavaScriptCore/SourceProvider.h #endif extern "C" const size_t JSC__SourceCode_object_size_ = sizeof(JSC::SourceCode); extern "C" const size_t JSC__SourceCode_object_align_ = alignof(JSC::SourceCode); -#ifndef INCLUDED__JavaScriptCore_JSFunction_h_ -#define INCLUDED__JavaScriptCore_JSFunction_h_ -#include +#ifndef INCLUDED_JavaScriptCore_JSFunction_h +#define INCLUDED_JavaScriptCore_JSFunction_h +#include JavaScriptCore/JSFunction.h #endif extern "C" const size_t JSC__JSFunction_object_size_ = sizeof(JSC::JSFunction); extern "C" const size_t JSC__JSFunction_object_align_ = alignof(JSC::JSFunction); -#ifndef INCLUDED__JavaScriptCore_JSGlobalObject_h_ -#define INCLUDED__JavaScriptCore_JSGlobalObject_h_ -#include +#ifndef INCLUDED_JavaScriptCore_JSGlobalObject_h +#define INCLUDED_JavaScriptCore_JSGlobalObject_h +#include JavaScriptCore/JSGlobalObject.h #endif extern "C" const size_t JSC__JSGlobalObject_object_size_ = sizeof(JSC::JSGlobalObject); extern "C" const size_t JSC__JSGlobalObject_object_align_ = alignof(JSC::JSGlobalObject); -#ifndef INCLUDED__wtf_URL_h_ -#define INCLUDED__wtf_URL_h_ -#include +#ifndef INCLUDED_wtf_URL_h +#define INCLUDED_wtf_URL_h +#include wtf/URL.h #endif extern "C" const size_t WTF__URL_object_size_ = sizeof(WTF::URL); extern "C" const size_t WTF__URL_object_align_ = alignof(WTF::URL); -#ifndef INCLUDED__wtf_text_WTFString_h_ -#define INCLUDED__wtf_text_WTFString_h_ -#include +#ifndef INCLUDED_wtf_text_WTFString_h +#define INCLUDED_wtf_text_WTFString_h +#include wtf/text/WTFString.h #endif extern "C" const size_t WTF__String_object_size_ = sizeof(WTF::String); extern "C" const size_t WTF__String_object_align_ = alignof(WTF::String); -#ifndef INCLUDED__JavaScriptCore_JSValue_h_ -#define INCLUDED__JavaScriptCore_JSValue_h_ -#include +#ifndef INCLUDED_JavaScriptCore_JSValue_h +#define INCLUDED_JavaScriptCore_JSValue_h +#include JavaScriptCore/JSValue.h #endif extern "C" const size_t JSC__JSValue_object_size_ = sizeof(JSC::JSValue); extern "C" const size_t JSC__JSValue_object_align_ = alignof(JSC::JSValue); -#ifndef INCLUDED__JavaScriptCore_PropertyName_h_ -#define INCLUDED__JavaScriptCore_PropertyName_h_ -#include +#ifndef INCLUDED_JavaScriptCore_PropertyName_h +#define INCLUDED_JavaScriptCore_PropertyName_h +#include JavaScriptCore/PropertyName.h #endif extern "C" const size_t JSC__PropertyName_object_size_ = sizeof(JSC::PropertyName); extern "C" const size_t JSC__PropertyName_object_align_ = alignof(JSC::PropertyName); -#ifndef INCLUDED__JavaScriptCore_Exception_h_ -#define INCLUDED__JavaScriptCore_Exception_h_ -#include +#ifndef INCLUDED_JavaScriptCore_Exception_h +#define INCLUDED_JavaScriptCore_Exception_h +#include JavaScriptCore/Exception.h #endif extern "C" const size_t JSC__Exception_object_size_ = sizeof(JSC::Exception); extern "C" const size_t JSC__Exception_object_align_ = alignof(JSC::Exception); -#ifndef INCLUDED__JavaScriptCore_VM_h_ -#define INCLUDED__JavaScriptCore_VM_h_ -#include +#ifndef INCLUDED_JavaScriptCore_VM_h +#define INCLUDED_JavaScriptCore_VM_h +#include JavaScriptCore/VM.h #endif extern "C" const size_t JSC__VM_object_size_ = sizeof(JSC::VM); extern "C" const size_t JSC__VM_object_align_ = alignof(JSC::VM); -#ifndef INCLUDED__JavaScriptCore_ThrowScope_h_ -#define INCLUDED__JavaScriptCore_ThrowScope_h_ -#include +#ifndef INCLUDED_JavaScriptCore_ThrowScope_h +#define INCLUDED_JavaScriptCore_ThrowScope_h +#include JavaScriptCore/ThrowScope.h #endif extern "C" const size_t JSC__ThrowScope_object_size_ = sizeof(JSC::ThrowScope); extern "C" const size_t JSC__ThrowScope_object_align_ = alignof(JSC::ThrowScope); -#ifndef INCLUDED__JavaScriptCore_CatchScope_h_ -#define INCLUDED__JavaScriptCore_CatchScope_h_ -#include +#ifndef INCLUDED_JavaScriptCore_CatchScope_h +#define INCLUDED_JavaScriptCore_CatchScope_h +#include JavaScriptCore/CatchScope.h #endif extern "C" const size_t JSC__CatchScope_object_size_ = sizeof(JSC::CatchScope); extern "C" const size_t JSC__CatchScope_object_align_ = alignof(JSC::CatchScope); -#ifndef INCLUDED__JavaScriptCore_CallFrame_h_ -#define INCLUDED__JavaScriptCore_CallFrame_h_ -#include +#ifndef INCLUDED_JavaScriptCore_CallFrame_h +#define INCLUDED_JavaScriptCore_CallFrame_h +#include JavaScriptCore/CallFrame.h #endif extern "C" const size_t JSC__CallFrame_object_size_ = sizeof(JSC::CallFrame); extern "C" const size_t JSC__CallFrame_object_align_ = alignof(JSC::CallFrame); -#ifndef INCLUDED__JavaScriptCore_Identifier_h_ -#define INCLUDED__JavaScriptCore_Identifier_h_ -#include +#ifndef INCLUDED_JavaScriptCore_Identifier_h +#define INCLUDED_JavaScriptCore_Identifier_h +#include JavaScriptCore/Identifier.h #endif extern "C" const size_t JSC__Identifier_object_size_ = sizeof(JSC::Identifier); extern "C" const size_t JSC__Identifier_object_align_ = alignof(JSC::Identifier); -#ifndef INCLUDED__wtf_text_StringImpl_h_ -#define INCLUDED__wtf_text_StringImpl_h_ -#include +#ifndef INCLUDED_wtf_text_StringImpl_h +#define INCLUDED_wtf_text_StringImpl_h +#include wtf/text/StringImpl.h #endif extern "C" const size_t WTF__StringImpl_object_size_ = sizeof(WTF::StringImpl); extern "C" const size_t WTF__StringImpl_object_align_ = alignof(WTF::StringImpl); -#ifndef INCLUDED__wtf_text_ExternalStringImpl_h_ -#define INCLUDED__wtf_text_ExternalStringImpl_h_ -#include +#ifndef INCLUDED_wtf_text_ExternalStringImpl_h +#define INCLUDED_wtf_text_ExternalStringImpl_h +#include wtf/text/ExternalStringImpl.h #endif extern "C" const size_t WTF__ExternalStringImpl_object_size_ = sizeof(WTF::ExternalStringImpl); extern "C" const size_t WTF__ExternalStringImpl_object_align_ = alignof(WTF::ExternalStringImpl); -#ifndef INCLUDED__wtf_text_StringView_h_ -#define INCLUDED__wtf_text_StringView_h_ -#include +#ifndef INCLUDED_wtf_text_StringView_h +#define INCLUDED_wtf_text_StringView_h +#include wtf/text/StringView.h #endif extern "C" const size_t WTF__StringView_object_size_ = sizeof(WTF::StringView); diff --git a/src/javascript/jsc/bindings/headers.h b/src/javascript/jsc/bindings/headers.h index dddfb5cb48..95f5ec3a9b 100644 --- a/src/javascript/jsc/bindings/headers.h +++ b/src/javascript/jsc/bindings/headers.h @@ -1,10 +1,10 @@ // clang-format: off -//-- AUTOGENERATED FILE -- 1648167213 +//-- AUTOGENERATED FILE -- 1648440945 #pragma once -#include #include #include +#include #ifdef __cplusplus #define AUTO_EXTERN_C extern "C" @@ -23,7 +23,7 @@ typedef void* JSClassRef; #ifdef __cplusplus #include "root.h" -#include +#include "JavaScriptCore/JSClassRef.h" #endif #include "headers-handwritten.h" typedef struct bJSC__SourceCode { diff --git a/src/javascript/jsc/bindings/helpers.h b/src/javascript/jsc/bindings/helpers.h index fc9174a38c..392bf60706 100644 --- a/src/javascript/jsc/bindings/helpers.h +++ b/src/javascript/jsc/bindings/helpers.h @@ -1,16 +1,17 @@ #pragma once -#include "headers.h" #include "root.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include "headers.h" + +#include "JavaScriptCore/Error.h" +#include "JavaScriptCore/Exception.h" +#include "JavaScriptCore/Identifier.h" +#include "JavaScriptCore/JSGlobalObject.h" +#include "JavaScriptCore/JSString.h" +#include "JavaScriptCore/JSValueInternal.h" +#include "JavaScriptCore/ThrowScope.h" +#include "JavaScriptCore/VM.h" template class Wrap { public: diff --git a/src/javascript/jsc/bindings/objects.h b/src/javascript/jsc/bindings/objects.h index 9d4d6d38de..dc30306220 100644 --- a/src/javascript/jsc/bindings/objects.h +++ b/src/javascript/jsc/bindings/objects.h @@ -3,9 +3,9 @@ // #include "root.h" // #include "headers.h" -// #include -// #include -// #include +// #include "JavaScriptCore/JSObject.h" +// #include "JavaScriptCore/JSCInlines.h" +// #include "JavaScriptCore/InternalFunction.h" // namespace Zig { diff --git a/src/javascript/jsc/bindings/root.h b/src/javascript/jsc/bindings/root.h index 0d120977e7..aeb22dbab9 100644 --- a/src/javascript/jsc/bindings/root.h +++ b/src/javascript/jsc/bindings/root.h @@ -2,7 +2,7 @@ /* * Copyright (C) 2006-2021 Apple Inc. All rights reserved. - * Copyright (C) 2006 Samuel Weinig + * Copyright (C) 2006 Samuel Weinig "sam.weinig@gmail.com" * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -34,16 +34,14 @@ #define JSC_MAC_VERSION_TBA 0 #define JSC_IOS_VERSION_TBA 0 -#include +#include "wtf/ExportMacros.h" #if !defined(JS_EXPORT_PRIVATE) #if defined(BUILDING_JavaScriptCore) || defined(STATICALLY_LINKED_WITH_JavaScriptCore) #define JS_EXPORT_PRIVATE WTF_EXPORT_DECLARATION -#define WEBCORE_EXPORT WTF_EXPORT_DECLARATION #else #define JS_EXPORT_PRIVATE WTF_IMPORT_DECLARATION -#define WEBCORE_EXPORT WTF_IMPORT_DECLARATION #endif #endif @@ -51,10 +49,10 @@ #ifdef __cplusplus #undef new #undef delete -#include +#include "wtf/FastMalloc.h" #endif -#include +#include "wtf/DisallowCType.h" /* Disabling warning C4206: nonstandard extension used: translation unit is empty. By design, we rely on #define flags to make some translation units empty. @@ -64,9 +62,11 @@ #pragma warning(disable : 4206) #endif -#ifdef USE_FOUNDATION -#include +#ifndef WEBCORE_EXPORT +#define WEBCORE_EXPORT JS_EXPORT_PRIVATE #endif -#include -#include \ No newline at end of file +#include "wtf/PlatformCallingConventions.h" +#include "JavaScriptCore/Strong.h" +#include "JavaScriptCore/Weak.h" +#include "JavaScriptCore/WeakInlines.h" \ No newline at end of file diff --git a/src/javascript/jsc/bindings/webcore/ActiveDOMObject.h b/src/javascript/jsc/bindings/webcore/ActiveDOMObject.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/javascript/jsc/bindings/webcore/BufferSource.h b/src/javascript/jsc/bindings/webcore/BufferSource.h new file mode 100644 index 0000000000..ee78e38d11 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/BufferSource.h @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2016 Igalia S.L. + * Copyright (C) 2021 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "JavaScriptCore/ArrayBuffer.h" +#include "JavaScriptCore/ArrayBufferView.h" +#include "wtf/RefPtr.h" +#include + +namespace WebCore { + +class BufferSource { +public: + using VariantType = std::variant, RefPtr>; + + BufferSource() {} + BufferSource(VariantType&& variant) + : m_variant(WTFMove(variant)) + { + } + + const VariantType& variant() const { return m_variant; } + + const uint8_t* data() const + { + return std::visit([](auto& buffer) -> const uint8_t* { + return buffer ? static_cast(buffer->data()) : nullptr; + }, + m_variant); + } + + void* mutableData() const + { + return std::visit([](auto& buffer) -> void* { + return buffer->data(); + }, + m_variant); + } + + size_t length() const + { + return std::visit([](auto& buffer) -> size_t { + return buffer ? buffer->byteLength() : 0; + }, + m_variant); + } + + template void encode(Encoder&) const; + template static std::optional decode(Decoder&); + +private: + VariantType m_variant; +}; + +template +void BufferSource::encode(Encoder& encoder) const +{ + encoder << static_cast(length()); + if (!length()) + return; + + encoder.encodeFixedLengthData(data(), length() * sizeof(uint8_t), alignof(uint8_t)); +} + +template +std::optional BufferSource::decode(Decoder& decoder) +{ + std::optional size; + decoder >> size; + if (!size) + return std::nullopt; + if (!*size) + return BufferSource(); + + auto dataSize = CheckedSize { *size }; + if (UNLIKELY(dataSize.hasOverflowed())) + return std::nullopt; + + const uint8_t* data = decoder.decodeFixedLengthReference(dataSize, alignof(uint8_t)); + if (!data) + return std::nullopt; + return BufferSource(JSC::ArrayBuffer::tryCreate(static_cast(data), dataSize.value())); +} + +inline BufferSource toBufferSource(const uint8_t* data, size_t length) +{ + return BufferSource(JSC::ArrayBuffer::tryCreate(data, length)); +} + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/DOMClientIsoSubspaces.h b/src/javascript/jsc/bindings/webcore/DOMClientIsoSubspaces.h new file mode 100644 index 0000000000..1a75fa5184 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/DOMClientIsoSubspaces.h @@ -0,0 +1,874 @@ +#pragma once + +#include "root.h" + +#include "wtf/FastMalloc.h" +#include "wtf/Noncopyable.h" + +namespace WebCore { +using namespace JSC; + +class DOMClientIsoSubspaces { + WTF_MAKE_NONCOPYABLE(DOMClientIsoSubspaces); + WTF_MAKE_FAST_ALLOCATED(DOMClientIsoSubspaces); + +public: + DOMClientIsoSubspaces() = default; + + std::unique_ptr m_clientSubspaceForGlobalObject; + + std::unique_ptr m_clientSubspaceForDOMException; + std::unique_ptr m_clientSubspaceForDOMFormData; + std::unique_ptr m_clientSubspaceForDOMFormDataIterator; + std::unique_ptr m_clientSubspaceForDOMURL; + std::unique_ptr m_clientSubspaceForURLSearchParams; + + std::unique_ptr m_clientSubspaceForURLSearchParamsIterator; + + std::unique_ptr m_clientSubspaceForExposedToWorkerAndWindow; + + // std::unique_ptr m_clientSubspaceForTouch; + // std::unique_ptr m_clientSubspaceForTouchEvent; + // std::unique_ptr m_clientSubspaceForTouchList; + // std::unique_ptr m_clientSubspaceForInternalSettingsGenerated; + // std::unique_ptr m_clientSubspaceForGPU; + // std::unique_ptr m_clientSubspaceForGPUAdapter; + // std::unique_ptr m_clientSubspaceForGPUBindGroup; + // std::unique_ptr m_clientSubspaceForGPUBindGroupLayout; + // std::unique_ptr m_clientSubspaceForGPUBuffer; + // std::unique_ptr m_clientSubspaceForGPUBufferUsage; + // std::unique_ptr m_clientSubspaceForGPUCanvasContext; + // std::unique_ptr m_clientSubspaceForGPUColorWrite; + // std::unique_ptr m_clientSubspaceForGPUCommandBuffer; + // std::unique_ptr m_clientSubspaceForGPUCommandEncoder; + // std::unique_ptr m_clientSubspaceForGPUCompilationInfo; + // std::unique_ptr m_clientSubspaceForGPUCompilationMessage; + // std::unique_ptr m_clientSubspaceForGPUComputePassEncoder; + // std::unique_ptr m_clientSubspaceForGPUComputePipeline; + // std::unique_ptr m_clientSubspaceForGPUDevice; + // std::unique_ptr m_clientSubspaceForGPUDeviceLostInfo; + // std::unique_ptr m_clientSubspaceForGPUExternalTexture; + // std::unique_ptr m_clientSubspaceForGPUMapMode; + // std::unique_ptr m_clientSubspaceForGPUOutOfMemoryError; + // std::unique_ptr m_clientSubspaceForGPUPipelineLayout; + // std::unique_ptr m_clientSubspaceForGPUQuerySet; + // std::unique_ptr m_clientSubspaceForGPUQueue; + // std::unique_ptr m_clientSubspaceForGPURenderBundle; + // std::unique_ptr m_clientSubspaceForGPURenderBundleEncoder; + // std::unique_ptr m_clientSubspaceForGPURenderPassEncoder; + // std::unique_ptr m_clientSubspaceForGPURenderPipeline; + // std::unique_ptr m_clientSubspaceForGPUSampler; + // std::unique_ptr m_clientSubspaceForGPUShaderModule; + // std::unique_ptr m_clientSubspaceForGPUShaderStage; + // std::unique_ptr m_clientSubspaceForGPUSupportedFeatures; + // std::unique_ptr m_clientSubspaceForGPUSupportedLimits; + // std::unique_ptr m_clientSubspaceForGPUTexture; + // std::unique_ptr m_clientSubspaceForGPUTextureUsage; + // std::unique_ptr m_clientSubspaceForGPUTextureView; + // std::unique_ptr m_clientSubspaceForGPUUncapturedErrorEvent; + // std::unique_ptr m_clientSubspaceForGPUValidationError; + // std::unique_ptr m_clientSubspaceForWebKitPlaybackTargetAvailabilityEvent; + // std::unique_ptr m_clientSubspaceForApplePayCancelEvent; + // std::unique_ptr m_clientSubspaceForApplePayCouponCodeChangedEvent; + // std::unique_ptr m_clientSubspaceForApplePayError; + // std::unique_ptr m_clientSubspaceForApplePayPaymentAuthorizedEvent; + // std::unique_ptr m_clientSubspaceForApplePayPaymentMethodSelectedEvent; + // std::unique_ptr m_clientSubspaceForApplePaySession; + // std::unique_ptr m_clientSubspaceForApplePaySetup; + // std::unique_ptr m_clientSubspaceForApplePaySetupFeature; + // std::unique_ptr m_clientSubspaceForApplePayShippingContactSelectedEvent; + // std::unique_ptr m_clientSubspaceForApplePayShippingMethodSelectedEvent; + // std::unique_ptr m_clientSubspaceForApplePayValidateMerchantEvent; + // std::unique_ptr m_clientSubspaceForClipboard; + // std::unique_ptr m_clientSubspaceForClipboardItem; + // std::unique_ptr m_clientSubspaceForDOMCache; + // std::unique_ptr m_clientSubspaceForDOMCacheStorage; + // std::unique_ptr m_clientSubspaceForContactsManager; + // std::unique_ptr m_clientSubspaceForBasicCredential; + // std::unique_ptr m_clientSubspaceForCredentialsContainer; + // std::unique_ptr m_clientSubspaceForMediaKeyMessageEvent; + // std::unique_ptr m_clientSubspaceForMediaKeySession; + // std::unique_ptr m_clientSubspaceForMediaKeyStatusMap; + // std::unique_ptr m_clientSubspaceForMediaKeyStatusMapIterator; + // std::unique_ptr m_clientSubspaceForMediaKeySystemAccess; + // std::unique_ptr m_clientSubspaceForMediaKeys; + // std::unique_ptr m_clientSubspaceForWebKitMediaKeyMessageEvent; + // std::unique_ptr m_clientSubspaceForWebKitMediaKeyNeededEvent; + // std::unique_ptr m_clientSubspaceForWebKitMediaKeySession; + // std::unique_ptr m_clientSubspaceForWebKitMediaKeys; + // std::unique_ptr m_clientSubspaceForDOMFileSystem; + // std::unique_ptr m_clientSubspaceForFileSystemDirectoryEntry; + // std::unique_ptr m_clientSubspaceForFileSystemDirectoryReader; + // std::unique_ptr m_clientSubspaceForFileSystemEntry; + // std::unique_ptr m_clientSubspaceForFileSystemFileEntry; + // std::unique_ptr m_clientSubspaceForFetchHeaders; + // std::unique_ptr m_clientSubspaceForFetchHeadersIterator; + // std::unique_ptr m_clientSubspaceForFetchRequest; + // std::unique_ptr m_clientSubspaceForFetchResponse; + // std::unique_ptr m_clientSubspaceForFileSystemDirectoryHandle; + // std::unique_ptr m_clientSubspaceForFileSystemFileHandle; + // std::unique_ptr m_clientSubspaceForFileSystemHandle; + // std::unique_ptr m_clientSubspaceForFileSystemSyncAccessHandle; + // std::unique_ptr m_clientSubspaceForGamepad; + // std::unique_ptr m_clientSubspaceForGamepadButton; + // std::unique_ptr m_clientSubspaceForGamepadEvent; + // std::unique_ptr m_clientSubspaceForGeolocation; + // std::unique_ptr m_clientSubspaceForGeolocationCoordinates; + // std::unique_ptr m_clientSubspaceForGeolocationPosition; + // std::unique_ptr m_clientSubspaceForGeolocationPositionError; + // std::unique_ptr m_clientSubspaceForHighlight; + // std::unique_ptr m_clientSubspaceForHighlightRegister; + // std::unique_ptr m_clientSubspaceForIDBCursor; + // std::unique_ptr m_clientSubspaceForIDBCursorWithValue; + // std::unique_ptr m_clientSubspaceForIDBDatabase; + // std::unique_ptr m_clientSubspaceForIDBFactory; + // std::unique_ptr m_clientSubspaceForIDBIndex; + // std::unique_ptr m_clientSubspaceForIDBKeyRange; + // std::unique_ptr m_clientSubspaceForIDBObjectStore; + // std::unique_ptr m_clientSubspaceForIDBOpenDBRequest; + // std::unique_ptr m_clientSubspaceForIDBRequest; + // std::unique_ptr m_clientSubspaceForIDBTransaction; + // std::unique_ptr m_clientSubspaceForIDBVersionChangeEvent; + // std::unique_ptr m_clientSubspaceForMediaCapabilities; + // std::unique_ptr m_clientSubspaceForMediaControlsHost; + // std::unique_ptr m_clientSubspaceForBlobEvent; + // std::unique_ptr m_clientSubspaceForMediaRecorder; + // std::unique_ptr m_clientSubspaceForMediaRecorderErrorEvent; + // std::unique_ptr m_clientSubspaceForMediaMetadata; + // std::unique_ptr m_clientSubspaceForMediaSession; + // std::unique_ptr m_clientSubspaceForMediaSessionCoordinator; + // std::unique_ptr m_clientSubspaceForMediaSource; + // std::unique_ptr m_clientSubspaceForSourceBuffer; + // std::unique_ptr m_clientSubspaceForSourceBufferList; + // std::unique_ptr m_clientSubspaceForVideoPlaybackQuality; + // std::unique_ptr m_clientSubspaceForCanvasCaptureMediaStreamTrack; + // std::unique_ptr m_clientSubspaceForMediaDeviceInfo; + // std::unique_ptr m_clientSubspaceForMediaDevices; + // std::unique_ptr m_clientSubspaceForMediaStream; + // std::unique_ptr m_clientSubspaceForMediaStreamTrack; + // std::unique_ptr m_clientSubspaceForMediaStreamTrackEvent; + // std::unique_ptr m_clientSubspaceForOverconstrainedError; + // std::unique_ptr m_clientSubspaceForOverconstrainedErrorEvent; + // std::unique_ptr m_clientSubspaceForRTCCertificate; + // std::unique_ptr m_clientSubspaceForRTCDTMFSender; + // std::unique_ptr m_clientSubspaceForRTCDTMFToneChangeEvent; + // std::unique_ptr m_clientSubspaceForRTCDataChannel; + // std::unique_ptr m_clientSubspaceForRTCDataChannelEvent; + // std::unique_ptr m_clientSubspaceForRTCDtlsTransport; + // std::unique_ptr m_clientSubspaceForRTCEncodedAudioFrame; + // std::unique_ptr m_clientSubspaceForRTCEncodedVideoFrame; + // std::unique_ptr m_clientSubspaceForRTCError; + // std::unique_ptr m_clientSubspaceForRTCErrorEvent; + // std::unique_ptr m_clientSubspaceForRTCIceCandidate; + // std::unique_ptr m_clientSubspaceForRTCIceTransport; + // std::unique_ptr m_clientSubspaceForRTCPeerConnection; + // std::unique_ptr m_clientSubspaceForRTCPeerConnectionIceErrorEvent; + // std::unique_ptr m_clientSubspaceForRTCPeerConnectionIceEvent; + // std::unique_ptr m_clientSubspaceForRTCRtpReceiver; + // std::unique_ptr m_clientSubspaceForRTCRtpSFrameTransform; + // std::unique_ptr m_clientSubspaceForRTCRtpSFrameTransformErrorEvent; + // std::unique_ptr m_clientSubspaceForRTCRtpScriptTransform; + // std::unique_ptr m_clientSubspaceForRTCRtpScriptTransformer; + // std::unique_ptr m_clientSubspaceForRTCRtpSender; + // std::unique_ptr m_clientSubspaceForRTCRtpTransceiver; + // std::unique_ptr m_clientSubspaceForRTCSctpTransport; + // std::unique_ptr m_clientSubspaceForRTCSessionDescription; + // std::unique_ptr m_clientSubspaceForRTCStatsReport; + // std::unique_ptr m_clientSubspaceForRTCTrackEvent; + // std::unique_ptr m_clientSubspaceForRTCTransformEvent; + // std::unique_ptr m_clientSubspaceForHTMLModelElement; + // std::unique_ptr m_clientSubspaceForNotification; + // std::unique_ptr m_clientSubspaceForNotificationEvent; + // std::unique_ptr m_clientSubspaceForMerchantValidationEvent; + // std::unique_ptr m_clientSubspaceForPaymentAddress; + // std::unique_ptr m_clientSubspaceForPaymentMethodChangeEvent; + // std::unique_ptr m_clientSubspaceForPaymentRequest; + // std::unique_ptr m_clientSubspaceForPaymentRequestUpdateEvent; + // std::unique_ptr m_clientSubspaceForPaymentResponse; + // std::unique_ptr m_clientSubspaceForPermissionStatus; + // std::unique_ptr m_clientSubspaceForPermissions; + // std::unique_ptr m_clientSubspaceForPictureInPictureEvent; + // std::unique_ptr m_clientSubspaceForPictureInPictureWindow; + // std::unique_ptr m_clientSubspaceForPushEvent; + // std::unique_ptr m_clientSubspaceForPushManager; + // std::unique_ptr m_clientSubspaceForPushMessageData; + // std::unique_ptr m_clientSubspaceForPushSubscription; + // std::unique_ptr m_clientSubspaceForPushSubscriptionChangeEvent; + // std::unique_ptr m_clientSubspaceForPushSubscriptionOptions; + // std::unique_ptr m_clientSubspaceForRemotePlayback; + // std::unique_ptr m_clientSubspaceForSpeechRecognition; + // std::unique_ptr m_clientSubspaceForSpeechRecognitionAlternative; + // std::unique_ptr m_clientSubspaceForSpeechRecognitionErrorEvent; + // std::unique_ptr m_clientSubspaceForSpeechRecognitionEvent; + // std::unique_ptr m_clientSubspaceForSpeechRecognitionResult; + // std::unique_ptr m_clientSubspaceForSpeechRecognitionResultList; + // std::unique_ptr m_clientSubspaceForSpeechSynthesis; + // std::unique_ptr m_clientSubspaceForSpeechSynthesisErrorEvent; + // std::unique_ptr m_clientSubspaceForSpeechSynthesisEvent; + // std::unique_ptr m_clientSubspaceForSpeechSynthesisUtterance; + // std::unique_ptr m_clientSubspaceForSpeechSynthesisVoice; + // std::unique_ptr m_clientSubspaceForStorageManager; + // std::unique_ptr m_clientSubspaceForByteLengthQueuingStrategy; + // std::unique_ptr m_clientSubspaceForCountQueuingStrategy; + // std::unique_ptr m_clientSubspaceForReadableByteStreamController; + // std::unique_ptr m_clientSubspaceForReadableStream; + // std::unique_ptr m_clientSubspaceForReadableStreamBYOBReader; + // std::unique_ptr m_clientSubspaceForReadableStreamBYOBRequest; + // std::unique_ptr m_clientSubspaceForReadableStreamDefaultController; + // std::unique_ptr m_clientSubspaceForReadableStreamDefaultReader; + // std::unique_ptr m_clientSubspaceForReadableStreamSink; + // std::unique_ptr m_clientSubspaceForReadableStreamSource; + // std::unique_ptr m_clientSubspaceForTransformStream; + // std::unique_ptr m_clientSubspaceForTransformStreamDefaultController; + // std::unique_ptr m_clientSubspaceForWritableStream; + // std::unique_ptr m_clientSubspaceForWritableStreamDefaultController; + // std::unique_ptr m_clientSubspaceForWritableStreamDefaultWriter; + // std::unique_ptr m_clientSubspaceForWritableStreamSink; + // std::unique_ptr m_clientSubspaceForWebLock; + // std::unique_ptr m_clientSubspaceForWebLockManager; + // std::unique_ptr m_clientSubspaceForAnalyserNode; + // std::unique_ptr m_clientSubspaceForAudioBuffer; + // std::unique_ptr m_clientSubspaceForAudioBufferSourceNode; + // std::unique_ptr m_clientSubspaceForAudioContext; + // std::unique_ptr m_clientSubspaceForAudioDestinationNode; + // std::unique_ptr m_clientSubspaceForAudioListener; + // std::unique_ptr m_clientSubspaceForAudioNode; + // std::unique_ptr m_clientSubspaceForAudioParam; + // std::unique_ptr m_clientSubspaceForAudioParamMap; + // std::unique_ptr m_clientSubspaceForAudioProcessingEvent; + // std::unique_ptr m_clientSubspaceForAudioScheduledSourceNode; + // std::unique_ptr m_clientSubspaceForAudioWorklet; + // std::unique_ptr m_clientSubspaceForAudioWorkletGlobalScope; + // std::unique_ptr m_clientSubspaceForAudioWorkletNode; + // std::unique_ptr m_clientSubspaceForAudioWorkletProcessor; + // std::unique_ptr m_clientSubspaceForBaseAudioContext; + // std::unique_ptr m_clientSubspaceForBiquadFilterNode; + // std::unique_ptr m_clientSubspaceForChannelMergerNode; + // std::unique_ptr m_clientSubspaceForChannelSplitterNode; + // std::unique_ptr m_clientSubspaceForConstantSourceNode; + // std::unique_ptr m_clientSubspaceForConvolverNode; + // std::unique_ptr m_clientSubspaceForDelayNode; + // std::unique_ptr m_clientSubspaceForDynamicsCompressorNode; + // std::unique_ptr m_clientSubspaceForGainNode; + // std::unique_ptr m_clientSubspaceForIIRFilterNode; + // std::unique_ptr m_clientSubspaceForMediaElementAudioSourceNode; + // std::unique_ptr m_clientSubspaceForMediaStreamAudioDestinationNode; + // std::unique_ptr m_clientSubspaceForMediaStreamAudioSourceNode; + // std::unique_ptr m_clientSubspaceForOfflineAudioCompletionEvent; + // std::unique_ptr m_clientSubspaceForOfflineAudioContext; + // std::unique_ptr m_clientSubspaceForOscillatorNode; + // std::unique_ptr m_clientSubspaceForPannerNode; + // std::unique_ptr m_clientSubspaceForPeriodicWave; + // std::unique_ptr m_clientSubspaceForScriptProcessorNode; + // std::unique_ptr m_clientSubspaceForStereoPannerNode; + // std::unique_ptr m_clientSubspaceForWaveShaperNode; + // std::unique_ptr m_clientSubspaceForAuthenticatorAssertionResponse; + // std::unique_ptr m_clientSubspaceForAuthenticatorAttestationResponse; + // std::unique_ptr m_clientSubspaceForAuthenticatorResponse; + // std::unique_ptr m_clientSubspaceForPublicKeyCredential; + // std::unique_ptr m_clientSubspaceForVideoColorSpace; + // std::unique_ptr m_clientSubspaceForDatabase; + // std::unique_ptr m_clientSubspaceForSQLError; + // std::unique_ptr m_clientSubspaceForSQLResultSet; + // std::unique_ptr m_clientSubspaceForSQLResultSetRowList; + // std::unique_ptr m_clientSubspaceForSQLTransaction; + // std::unique_ptr m_clientSubspaceForCloseEvent; + // std::unique_ptr m_clientSubspaceForWebSocket; + // std::unique_ptr m_clientSubspaceForWebXRBoundedReferenceSpace; + // std::unique_ptr m_clientSubspaceForWebXRFrame; + // std::unique_ptr m_clientSubspaceForWebXRHand; + // std::unique_ptr m_clientSubspaceForWebXRHandIterator; + // std::unique_ptr m_clientSubspaceForWebXRInputSource; + // std::unique_ptr m_clientSubspaceForWebXRInputSourceArray; + // std::unique_ptr m_clientSubspaceForWebXRInputSourceArrayIterator; + // std::unique_ptr m_clientSubspaceForWebXRJointPose; + // std::unique_ptr m_clientSubspaceForWebXRJointSpace; + // std::unique_ptr m_clientSubspaceForWebXRLayer; + // std::unique_ptr m_clientSubspaceForWebXRPose; + // std::unique_ptr m_clientSubspaceForWebXRReferenceSpace; + // std::unique_ptr m_clientSubspaceForWebXRRenderState; + // std::unique_ptr m_clientSubspaceForWebXRRigidTransform; + // std::unique_ptr m_clientSubspaceForWebXRSession; + // std::unique_ptr m_clientSubspaceForWebXRSpace; + // std::unique_ptr m_clientSubspaceForWebXRSystem; + // std::unique_ptr m_clientSubspaceForWebXRView; + // std::unique_ptr m_clientSubspaceForWebXRViewerPose; + // std::unique_ptr m_clientSubspaceForWebXRViewport; + // std::unique_ptr m_clientSubspaceForWebXRWebGLLayer; + // std::unique_ptr m_clientSubspaceForXRInputSourceEvent; + // std::unique_ptr m_clientSubspaceForXRInputSourcesChangeEvent; + // std::unique_ptr m_clientSubspaceForXRReferenceSpaceEvent; + // std::unique_ptr m_clientSubspaceForXRSessionEvent; + // std::unique_ptr m_clientSubspaceForAnimationEffect; + // std::unique_ptr m_clientSubspaceForAnimationPlaybackEvent; + // std::unique_ptr m_clientSubspaceForAnimationTimeline; + // std::unique_ptr m_clientSubspaceForCSSAnimation; + // std::unique_ptr m_clientSubspaceForCSSTransition; + // std::unique_ptr m_clientSubspaceForCustomEffect; + // std::unique_ptr m_clientSubspaceForDocumentTimeline; + // std::unique_ptr m_clientSubspaceForKeyframeEffect; + // std::unique_ptr m_clientSubspaceForWebAnimation; + // std::unique_ptr m_clientSubspaceForCryptoKey; + // std::unique_ptr m_clientSubspaceForSubtleCrypto; + // std::unique_ptr m_clientSubspaceForCSSConditionRule; + // std::unique_ptr m_clientSubspaceForCSSCounterStyleRule; + // std::unique_ptr m_clientSubspaceForCSSFontFaceRule; + // std::unique_ptr m_clientSubspaceForCSSFontPaletteValuesRule; + // std::unique_ptr m_clientSubspaceForCSSGroupingRule; + // std::unique_ptr m_clientSubspaceForCSSImportRule; + // std::unique_ptr m_clientSubspaceForCSSKeyframeRule; + // std::unique_ptr m_clientSubspaceForCSSKeyframesRule; + // std::unique_ptr m_clientSubspaceForCSSLayerBlockRule; + // std::unique_ptr m_clientSubspaceForCSSLayerStatementRule; + // std::unique_ptr m_clientSubspaceForCSSMediaRule; + // std::unique_ptr m_clientSubspaceForCSSNamespaceRule; + // std::unique_ptr m_clientSubspaceForCSSPageRule; + // std::unique_ptr m_clientSubspaceForCSSPaintSize; + // std::unique_ptr m_clientSubspaceForCSSRule; + // std::unique_ptr m_clientSubspaceForCSSRuleList; + // std::unique_ptr m_clientSubspaceForCSSStyleDeclaration; + // std::unique_ptr m_clientSubspaceForCSSStyleRule; + // std::unique_ptr m_clientSubspaceForCSSStyleSheet; + // std::unique_ptr m_clientSubspaceForCSSSupportsRule; + // std::unique_ptr m_clientSubspaceForCSSUnknownRule; + // std::unique_ptr m_clientSubspaceForDOMCSSNamespace; + // std::unique_ptr m_clientSubspaceForDOMMatrix; + // std::unique_ptr m_clientSubspaceForDOMMatrixReadOnly; + // std::unique_ptr m_clientSubspaceForDeprecatedCSSOMCounter; + // std::unique_ptr m_clientSubspaceForDeprecatedCSSOMPrimitiveValue; + // std::unique_ptr m_clientSubspaceForDeprecatedCSSOMRGBColor; + // std::unique_ptr m_clientSubspaceForDeprecatedCSSOMRect; + // std::unique_ptr m_clientSubspaceForDeprecatedCSSOMValue; + // std::unique_ptr m_clientSubspaceForDeprecatedCSSOMValueList; + // std::unique_ptr m_clientSubspaceForFontFace; + // std::unique_ptr m_clientSubspaceForFontFaceSet; + // std::unique_ptr m_clientSubspaceForFontFaceSetIterator; + // std::unique_ptr m_clientSubspaceForMediaList; + // std::unique_ptr m_clientSubspaceForMediaQueryList; + // std::unique_ptr m_clientSubspaceForMediaQueryListEvent; + // std::unique_ptr m_clientSubspaceForStyleMedia; + // std::unique_ptr m_clientSubspaceForStyleSheet; + // std::unique_ptr m_clientSubspaceForStyleSheetList; + // std::unique_ptr m_clientSubspaceForCSSKeywordValue; + // std::unique_ptr m_clientSubspaceForCSSNumericValue; + // std::unique_ptr m_clientSubspaceForCSSOMVariableReferenceValue; + // std::unique_ptr m_clientSubspaceForCSSStyleImageValue; + // std::unique_ptr m_clientSubspaceForCSSStyleValue; + // std::unique_ptr m_clientSubspaceForCSSUnitValue; + // std::unique_ptr m_clientSubspaceForCSSUnparsedValue; + // std::unique_ptr m_clientSubspaceForCSSUnparsedValueIterator; + // std::unique_ptr m_clientSubspaceForStylePropertyMap; + // std::unique_ptr m_clientSubspaceForStylePropertyMapReadOnly; + // std::unique_ptr m_clientSubspaceForCSSMathInvert; + // std::unique_ptr m_clientSubspaceForCSSMathMax; + // std::unique_ptr m_clientSubspaceForCSSMathMin; + // std::unique_ptr m_clientSubspaceForCSSMathNegate; + // std::unique_ptr m_clientSubspaceForCSSMathProduct; + // std::unique_ptr m_clientSubspaceForCSSMathSum; + // std::unique_ptr m_clientSubspaceForCSSMathValue; + // std::unique_ptr m_clientSubspaceForCSSNumericArray; + // std::unique_ptr m_clientSubspaceForCSSNumericArrayIterator; + // std::unique_ptr m_clientSubspaceForCSSMatrixComponent; + // std::unique_ptr m_clientSubspaceForCSSPerspective; + // std::unique_ptr m_clientSubspaceForCSSRotate; + // std::unique_ptr m_clientSubspaceForCSSScale; + // std::unique_ptr m_clientSubspaceForCSSSkew; + // std::unique_ptr m_clientSubspaceForCSSSkewX; + // std::unique_ptr m_clientSubspaceForCSSSkewY; + // std::unique_ptr m_clientSubspaceForCSSTransformComponent; + // std::unique_ptr m_clientSubspaceForCSSTransformValue; + // std::unique_ptr m_clientSubspaceForCSSTransformValueIterator; + // std::unique_ptr m_clientSubspaceForCSSTranslate; + // std::unique_ptr m_clientSubspaceForAbortController; + // std::unique_ptr m_clientSubspaceForAbortSignal; + // std::unique_ptr m_clientSubspaceForAbstractRange; + // std::unique_ptr m_clientSubspaceForAnimationEvent; + // std::unique_ptr m_clientSubspaceForAttr; + // std::unique_ptr m_clientSubspaceForBeforeUnloadEvent; + // std::unique_ptr m_clientSubspaceForBroadcastChannel; + // std::unique_ptr m_clientSubspaceForCDATASection; + // std::unique_ptr m_clientSubspaceForCharacterData; + // std::unique_ptr m_clientSubspaceForClipboardEvent; + // std::unique_ptr m_clientSubspaceForComment; + // std::unique_ptr m_clientSubspaceForCompositionEvent; + // std::unique_ptr m_clientSubspaceForCustomElementRegistry; + // std::unique_ptr m_clientSubspaceForCustomEvent; + // std::unique_ptr m_clientSubspaceForDOMException; + // std::unique_ptr m_clientSubspaceForDOMImplementation; + // std::unique_ptr m_clientSubspaceForDOMPoint; + // std::unique_ptr m_clientSubspaceForDOMPointReadOnly; + // std::unique_ptr m_clientSubspaceForDOMQuad; + // std::unique_ptr m_clientSubspaceForDOMRect; + // std::unique_ptr m_clientSubspaceForDOMRectList; + // std::unique_ptr m_clientSubspaceForDOMRectReadOnly; + // std::unique_ptr m_clientSubspaceForDOMStringList; + // std::unique_ptr m_clientSubspaceForDOMStringMap; + // std::unique_ptr m_clientSubspaceForDataTransfer; + // std::unique_ptr m_clientSubspaceForDataTransferItem; + // std::unique_ptr m_clientSubspaceForDataTransferItemList; + // std::unique_ptr m_clientSubspaceForDeviceMotionEvent; + // std::unique_ptr m_clientSubspaceForDeviceOrientationEvent; + // std::unique_ptr m_clientSubspaceForDocument; + // std::unique_ptr m_clientSubspaceForDocumentFragment; + // std::unique_ptr m_clientSubspaceForDocumentType; + // std::unique_ptr m_clientSubspaceForDragEvent; + // std::unique_ptr m_clientSubspaceForElement; + // std::unique_ptr m_clientSubspaceForErrorEvent; + // std::unique_ptr m_clientSubspaceForEvent; + // std::unique_ptr m_clientSubspaceForEventListener; + // std::unique_ptr m_clientSubspaceForEventTarget; + // std::unique_ptr m_clientSubspaceForFocusEvent; + // std::unique_ptr m_clientSubspaceForFormDataEvent; + // std::unique_ptr m_clientSubspaceForHashChangeEvent; + // std::unique_ptr m_clientSubspaceForIdleDeadline; + // std::unique_ptr m_clientSubspaceForInputEvent; + // std::unique_ptr m_clientSubspaceForKeyboardEvent; + // std::unique_ptr m_clientSubspaceForMessageChannel; + // std::unique_ptr m_clientSubspaceForMessageEvent; + // std::unique_ptr m_clientSubspaceForMessagePort; + // std::unique_ptr m_clientSubspaceForMouseEvent; + // std::unique_ptr m_clientSubspaceForMutationEvent; + // std::unique_ptr m_clientSubspaceForMutationObserver; + // std::unique_ptr m_clientSubspaceForMutationRecord; + // std::unique_ptr m_clientSubspaceForNamedNodeMap; + // std::unique_ptr m_clientSubspaceForNode; + // std::unique_ptr m_clientSubspaceForNodeIterator; + // std::unique_ptr m_clientSubspaceForNodeList; + // std::unique_ptr m_clientSubspaceForNodeListIterator; + // std::unique_ptr m_clientSubspaceForOverflowEvent; + // std::unique_ptr m_clientSubspaceForPageTransitionEvent; + // std::unique_ptr m_clientSubspaceForPointerEvent; + // std::unique_ptr m_clientSubspaceForPopStateEvent; + // std::unique_ptr m_clientSubspaceForProcessingInstruction; + // std::unique_ptr m_clientSubspaceForProgressEvent; + // std::unique_ptr m_clientSubspaceForPromiseRejectionEvent; + // std::unique_ptr m_clientSubspaceForRange; + // std::unique_ptr m_clientSubspaceForSecurityPolicyViolationEvent; + // std::unique_ptr m_clientSubspaceForShadowRoot; + // std::unique_ptr m_clientSubspaceForStaticRange; + // std::unique_ptr m_clientSubspaceForText; + // std::unique_ptr m_clientSubspaceForTextDecoder; + // std::unique_ptr m_clientSubspaceForTextDecoderStream; + // std::unique_ptr m_clientSubspaceForTextDecoderStreamDecoder; + // std::unique_ptr m_clientSubspaceForTextEncoder; + // std::unique_ptr m_clientSubspaceForTextEncoderStream; + // std::unique_ptr m_clientSubspaceForTextEncoderStreamEncoder; + // std::unique_ptr m_clientSubspaceForTextEvent; + // std::unique_ptr m_clientSubspaceForTransitionEvent; + // std::unique_ptr m_clientSubspaceForTreeWalker; + // std::unique_ptr m_clientSubspaceForUIEvent; + // std::unique_ptr m_clientSubspaceForWheelEvent; + // std::unique_ptr m_clientSubspaceForXMLDocument; + // std::unique_ptr m_clientSubspaceForBlob; + // std::unique_ptr m_clientSubspaceForFile; + // std::unique_ptr m_clientSubspaceForFileList; + // std::unique_ptr m_clientSubspaceForFileReader; + // std::unique_ptr m_clientSubspaceForFileReaderSync; + // std::unique_ptr m_clientSubspaceForDOMFormData; + // std::unique_ptr m_clientSubspaceForDOMFormDataIterator; + // std::unique_ptr m_clientSubspaceForDOMTokenList; + // std::unique_ptr m_clientSubspaceForDOMTokenListIterator; + // std::unique_ptr m_clientSubspaceForDOMURL; + // std::unique_ptr m_clientSubspaceForHTMLAllCollection; + // std::unique_ptr m_clientSubspaceForHTMLAnchorElement; + // std::unique_ptr m_clientSubspaceForHTMLAreaElement; + // std::unique_ptr m_clientSubspaceForHTMLAttachmentElement; + // std::unique_ptr m_clientSubspaceForHTMLAudioElement; + // std::unique_ptr m_clientSubspaceForHTMLBRElement; + // std::unique_ptr m_clientSubspaceForHTMLBaseElement; + // std::unique_ptr m_clientSubspaceForHTMLBodyElement; + // std::unique_ptr m_clientSubspaceForHTMLButtonElement; + // std::unique_ptr m_clientSubspaceForHTMLCanvasElement; + // std::unique_ptr m_clientSubspaceForHTMLCollection; + // std::unique_ptr m_clientSubspaceForHTMLDListElement; + // std::unique_ptr m_clientSubspaceForHTMLDataElement; + // std::unique_ptr m_clientSubspaceForHTMLDataListElement; + // std::unique_ptr m_clientSubspaceForHTMLDetailsElement; + // std::unique_ptr m_clientSubspaceForHTMLDialogElement; + // std::unique_ptr m_clientSubspaceForHTMLDirectoryElement; + // std::unique_ptr m_clientSubspaceForHTMLDivElement; + // std::unique_ptr m_clientSubspaceForHTMLDocument; + // std::unique_ptr m_clientSubspaceForHTMLElement; + // std::unique_ptr m_clientSubspaceForHTMLEmbedElement; + // std::unique_ptr m_clientSubspaceForHTMLFieldSetElement; + // std::unique_ptr m_clientSubspaceForHTMLFontElement; + // std::unique_ptr m_clientSubspaceForHTMLFormControlsCollection; + // std::unique_ptr m_clientSubspaceForHTMLFormElement; + // std::unique_ptr m_clientSubspaceForHTMLFrameElement; + // std::unique_ptr m_clientSubspaceForHTMLFrameSetElement; + // std::unique_ptr m_clientSubspaceForHTMLHRElement; + // std::unique_ptr m_clientSubspaceForHTMLHeadElement; + // std::unique_ptr m_clientSubspaceForHTMLHeadingElement; + // std::unique_ptr m_clientSubspaceForHTMLHtmlElement; + // std::unique_ptr m_clientSubspaceForHTMLIFrameElement; + // std::unique_ptr m_clientSubspaceForHTMLImageElement; + // std::unique_ptr m_clientSubspaceForHTMLInputElement; + // std::unique_ptr m_clientSubspaceForHTMLLIElement; + // std::unique_ptr m_clientSubspaceForHTMLLabelElement; + // std::unique_ptr m_clientSubspaceForHTMLLegendElement; + // std::unique_ptr m_clientSubspaceForHTMLLinkElement; + // std::unique_ptr m_clientSubspaceForHTMLMapElement; + // std::unique_ptr m_clientSubspaceForHTMLMarqueeElement; + // std::unique_ptr m_clientSubspaceForHTMLMediaElement; + // std::unique_ptr m_clientSubspaceForHTMLMenuElement; + // std::unique_ptr m_clientSubspaceForHTMLMenuItemElement; + // std::unique_ptr m_clientSubspaceForHTMLMetaElement; + // std::unique_ptr m_clientSubspaceForHTMLMeterElement; + // std::unique_ptr m_clientSubspaceForHTMLModElement; + // std::unique_ptr m_clientSubspaceForHTMLOListElement; + // std::unique_ptr m_clientSubspaceForHTMLObjectElement; + // std::unique_ptr m_clientSubspaceForHTMLOptGroupElement; + // std::unique_ptr m_clientSubspaceForHTMLOptionElement; + // std::unique_ptr m_clientSubspaceForHTMLOptionsCollection; + // std::unique_ptr m_clientSubspaceForHTMLOutputElement; + // std::unique_ptr m_clientSubspaceForHTMLParagraphElement; + // std::unique_ptr m_clientSubspaceForHTMLParamElement; + // std::unique_ptr m_clientSubspaceForHTMLPictureElement; + // std::unique_ptr m_clientSubspaceForHTMLPreElement; + // std::unique_ptr m_clientSubspaceForHTMLProgressElement; + // std::unique_ptr m_clientSubspaceForHTMLQuoteElement; + // std::unique_ptr m_clientSubspaceForHTMLScriptElement; + // std::unique_ptr m_clientSubspaceForHTMLSelectElement; + // std::unique_ptr m_clientSubspaceForHTMLSlotElement; + // std::unique_ptr m_clientSubspaceForHTMLSourceElement; + // std::unique_ptr m_clientSubspaceForHTMLSpanElement; + // std::unique_ptr m_clientSubspaceForHTMLStyleElement; + // std::unique_ptr m_clientSubspaceForHTMLTableCaptionElement; + // std::unique_ptr m_clientSubspaceForHTMLTableCellElement; + // std::unique_ptr m_clientSubspaceForHTMLTableColElement; + // std::unique_ptr m_clientSubspaceForHTMLTableElement; + // std::unique_ptr m_clientSubspaceForHTMLTableRowElement; + // std::unique_ptr m_clientSubspaceForHTMLTableSectionElement; + // std::unique_ptr m_clientSubspaceForHTMLTemplateElement; + // std::unique_ptr m_clientSubspaceForHTMLTextAreaElement; + // std::unique_ptr m_clientSubspaceForHTMLTimeElement; + // std::unique_ptr m_clientSubspaceForHTMLTitleElement; + // std::unique_ptr m_clientSubspaceForHTMLTrackElement; + // std::unique_ptr m_clientSubspaceForHTMLUListElement; + // std::unique_ptr m_clientSubspaceForHTMLUnknownElement; + // std::unique_ptr m_clientSubspaceForHTMLVideoElement; + // std::unique_ptr m_clientSubspaceForImageBitmap; + // std::unique_ptr m_clientSubspaceForImageData; + // std::unique_ptr m_clientSubspaceForMediaController; + // std::unique_ptr m_clientSubspaceForMediaEncryptedEvent; + // std::unique_ptr m_clientSubspaceForMediaError; + // std::unique_ptr m_clientSubspaceForOffscreenCanvas; + // std::unique_ptr m_clientSubspaceForRadioNodeList; + // std::unique_ptr m_clientSubspaceForSubmitEvent; + // std::unique_ptr m_clientSubspaceForTextMetrics; + // std::unique_ptr m_clientSubspaceForTimeRanges; + // std::unique_ptr m_clientSubspaceForURLSearchParams; + // std::unique_ptr m_clientSubspaceForURLSearchParamsIterator; + // std::unique_ptr m_clientSubspaceForValidityState; + // std::unique_ptr m_clientSubspaceForWebKitMediaKeyError; + // std::unique_ptr m_clientSubspaceForANGLEInstancedArrays; + // std::unique_ptr m_clientSubspaceForCanvasGradient; + // std::unique_ptr m_clientSubspaceForCanvasPattern; + // std::unique_ptr m_clientSubspaceForCanvasRenderingContext2D; + // std::unique_ptr m_clientSubspaceForEXTBlendMinMax; + // std::unique_ptr m_clientSubspaceForEXTColorBufferFloat; + // std::unique_ptr m_clientSubspaceForEXTColorBufferHalfFloat; + // std::unique_ptr m_clientSubspaceForEXTFloatBlend; + // std::unique_ptr m_clientSubspaceForEXTFragDepth; + // std::unique_ptr m_clientSubspaceForEXTShaderTextureLOD; + // std::unique_ptr m_clientSubspaceForEXTTextureCompressionRGTC; + // std::unique_ptr m_clientSubspaceForEXTTextureFilterAnisotropic; + // std::unique_ptr m_clientSubspaceForEXTsRGB; + // std::unique_ptr m_clientSubspaceForImageBitmapRenderingContext; + // std::unique_ptr m_clientSubspaceForKHRParallelShaderCompile; + // std::unique_ptr m_clientSubspaceForOESElementIndexUint; + // std::unique_ptr m_clientSubspaceForOESFBORenderMipmap; + // std::unique_ptr m_clientSubspaceForOESStandardDerivatives; + // std::unique_ptr m_clientSubspaceForOESTextureFloat; + // std::unique_ptr m_clientSubspaceForOESTextureFloatLinear; + // std::unique_ptr m_clientSubspaceForOESTextureHalfFloat; + // std::unique_ptr m_clientSubspaceForOESTextureHalfFloatLinear; + // std::unique_ptr m_clientSubspaceForOESVertexArrayObject; + // std::unique_ptr m_clientSubspaceForOffscreenCanvasRenderingContext2D; + // std::unique_ptr m_clientSubspaceForPaintRenderingContext2D; + // std::unique_ptr m_clientSubspaceForPath2D; + // std::unique_ptr m_clientSubspaceForWebGL2RenderingContext; + // std::unique_ptr m_clientSubspaceForWebGLActiveInfo; + // std::unique_ptr m_clientSubspaceForWebGLBuffer; + // std::unique_ptr m_clientSubspaceForWebGLColorBufferFloat; + // std::unique_ptr m_clientSubspaceForWebGLCompressedTextureASTC; + // std::unique_ptr m_clientSubspaceForWebGLCompressedTextureATC; + // std::unique_ptr m_clientSubspaceForWebGLCompressedTextureETC; + // std::unique_ptr m_clientSubspaceForWebGLCompressedTextureETC1; + // std::unique_ptr m_clientSubspaceForWebGLCompressedTexturePVRTC; + // std::unique_ptr m_clientSubspaceForWebGLCompressedTextureS3TC; + // std::unique_ptr m_clientSubspaceForWebGLCompressedTextureS3TCsRGB; + // std::unique_ptr m_clientSubspaceForWebGLContextEvent; + // std::unique_ptr m_clientSubspaceForWebGLDebugRendererInfo; + // std::unique_ptr m_clientSubspaceForWebGLDebugShaders; + // std::unique_ptr m_clientSubspaceForWebGLDepthTexture; + // std::unique_ptr m_clientSubspaceForWebGLDrawBuffers; + // std::unique_ptr m_clientSubspaceForWebGLFramebuffer; + // std::unique_ptr m_clientSubspaceForWebGLLoseContext; + // std::unique_ptr m_clientSubspaceForWebGLMultiDraw; + // std::unique_ptr m_clientSubspaceForWebGLProgram; + // std::unique_ptr m_clientSubspaceForWebGLQuery; + // std::unique_ptr m_clientSubspaceForWebGLRenderbuffer; + // std::unique_ptr m_clientSubspaceForWebGLRenderingContext; + // std::unique_ptr m_clientSubspaceForWebGLSampler; + // std::unique_ptr m_clientSubspaceForWebGLShader; + // std::unique_ptr m_clientSubspaceForWebGLShaderPrecisionFormat; + // std::unique_ptr m_clientSubspaceForWebGLSync; + // std::unique_ptr m_clientSubspaceForWebGLTexture; + // std::unique_ptr m_clientSubspaceForWebGLTransformFeedback; + // std::unique_ptr m_clientSubspaceForWebGLUniformLocation; + // std::unique_ptr m_clientSubspaceForWebGLVertexArrayObject; + // std::unique_ptr m_clientSubspaceForWebGLVertexArrayObjectOES; + // std::unique_ptr m_clientSubspaceForAudioTrack; + // std::unique_ptr m_clientSubspaceForAudioTrackConfiguration; + // std::unique_ptr m_clientSubspaceForAudioTrackList; + // std::unique_ptr m_clientSubspaceForDataCue; + // std::unique_ptr m_clientSubspaceForTextTrack; + // std::unique_ptr m_clientSubspaceForTextTrackCue; + // std::unique_ptr m_clientSubspaceForTextTrackCueGeneric; + // std::unique_ptr m_clientSubspaceForTextTrackCueList; + // std::unique_ptr m_clientSubspaceForTextTrackList; + // std::unique_ptr m_clientSubspaceForTrackEvent; + // std::unique_ptr m_clientSubspaceForVTTCue; + // std::unique_ptr m_clientSubspaceForVTTRegion; + // std::unique_ptr m_clientSubspaceForVTTRegionList; + // std::unique_ptr m_clientSubspaceForVideoTrack; + // std::unique_ptr m_clientSubspaceForVideoTrackConfiguration; + // std::unique_ptr m_clientSubspaceForVideoTrackList; + // std::unique_ptr m_clientSubspaceForCommandLineAPIHost; + // std::unique_ptr m_clientSubspaceForInspectorAuditAccessibilityObject; + // std::unique_ptr m_clientSubspaceForInspectorAuditDOMObject; + // std::unique_ptr m_clientSubspaceForInspectorAuditResourcesObject; + // std::unique_ptr m_clientSubspaceForInspectorFrontendHost; + // std::unique_ptr m_clientSubspaceForDOMApplicationCache; + // std::unique_ptr m_clientSubspaceForMathMLElement; + // std::unique_ptr m_clientSubspaceForMathMLMathElement; + // std::unique_ptr m_clientSubspaceForBarProp; + // std::unique_ptr m_clientSubspaceForCrypto; + // std::unique_ptr m_clientSubspaceForDOMSelection; + // std::unique_ptr m_clientSubspaceForDOMWindow; + // std::unique_ptr m_clientSubspaceForEventSource; + // std::unique_ptr m_clientSubspaceForHistory; + // std::unique_ptr m_clientSubspaceForIntersectionObserver; + // std::unique_ptr m_clientSubspaceForIntersectionObserverEntry; + // std::unique_ptr m_clientSubspaceForLocation; + // std::unique_ptr m_clientSubspaceForNavigator; + // std::unique_ptr m_clientSubspaceForPerformance; + // std::unique_ptr m_clientSubspaceForPerformanceEntry; + // std::unique_ptr m_clientSubspaceForPerformanceMark; + // std::unique_ptr m_clientSubspaceForPerformanceMeasure; + // std::unique_ptr m_clientSubspaceForPerformanceNavigation; + // std::unique_ptr m_clientSubspaceForPerformanceNavigationTiming; + // std::unique_ptr m_clientSubspaceForPerformanceObserver; + // std::unique_ptr m_clientSubspaceForPerformanceObserverEntryList; + // std::unique_ptr m_clientSubspaceForPerformancePaintTiming; + // std::unique_ptr m_clientSubspaceForPerformanceResourceTiming; + // std::unique_ptr m_clientSubspaceForPerformanceServerTiming; + // std::unique_ptr m_clientSubspaceForPerformanceTiming; + // std::unique_ptr m_clientSubspaceForRemoteDOMWindow; + // std::unique_ptr m_clientSubspaceForResizeObserver; + // std::unique_ptr m_clientSubspaceForResizeObserverEntry; + // std::unique_ptr m_clientSubspaceForResizeObserverSize; + // std::unique_ptr m_clientSubspaceForScreen; + // std::unique_ptr m_clientSubspaceForShadowRealmGlobalScope; + // std::unique_ptr m_clientSubspaceForUndoItem; + // std::unique_ptr m_clientSubspaceForUndoManager; + // std::unique_ptr m_clientSubspaceForUserMessageHandler; + // std::unique_ptr m_clientSubspaceForUserMessageHandlersNamespace; + // std::unique_ptr m_clientSubspaceForVisualViewport; + // std::unique_ptr m_clientSubspaceForWebKitNamespace; + // std::unique_ptr m_clientSubspaceForWebKitPoint; + // std::unique_ptr m_clientSubspaceForWorkerNavigator; + // std::unique_ptr m_clientSubspaceForDOMMimeType; + // std::unique_ptr m_clientSubspaceForDOMMimeTypeArray; + // std::unique_ptr m_clientSubspaceForDOMPlugin; + // std::unique_ptr m_clientSubspaceForDOMPluginArray; + // std::unique_ptr m_clientSubspaceForStorage; + // std::unique_ptr m_clientSubspaceForStorageEvent; + // std::unique_ptr m_clientSubspaceForSVGAElement; + // std::unique_ptr m_clientSubspaceForSVGAltGlyphDefElement; + // std::unique_ptr m_clientSubspaceForSVGAltGlyphElement; + // std::unique_ptr m_clientSubspaceForSVGAltGlyphItemElement; + // std::unique_ptr m_clientSubspaceForSVGAngle; + // std::unique_ptr m_clientSubspaceForSVGAnimateColorElement; + // std::unique_ptr m_clientSubspaceForSVGAnimateElement; + // std::unique_ptr m_clientSubspaceForSVGAnimateMotionElement; + // std::unique_ptr m_clientSubspaceForSVGAnimateTransformElement; + // std::unique_ptr m_clientSubspaceForSVGAnimatedAngle; + // std::unique_ptr m_clientSubspaceForSVGAnimatedBoolean; + // std::unique_ptr m_clientSubspaceForSVGAnimatedEnumeration; + // std::unique_ptr m_clientSubspaceForSVGAnimatedInteger; + // std::unique_ptr m_clientSubspaceForSVGAnimatedLength; + // std::unique_ptr m_clientSubspaceForSVGAnimatedLengthList; + // std::unique_ptr m_clientSubspaceForSVGAnimatedNumber; + // std::unique_ptr m_clientSubspaceForSVGAnimatedNumberList; + // std::unique_ptr m_clientSubspaceForSVGAnimatedPreserveAspectRatio; + // std::unique_ptr m_clientSubspaceForSVGAnimatedRect; + // std::unique_ptr m_clientSubspaceForSVGAnimatedString; + // std::unique_ptr m_clientSubspaceForSVGAnimatedTransformList; + // std::unique_ptr m_clientSubspaceForSVGAnimationElement; + // std::unique_ptr m_clientSubspaceForSVGCircleElement; + // std::unique_ptr m_clientSubspaceForSVGClipPathElement; + // std::unique_ptr m_clientSubspaceForSVGComponentTransferFunctionElement; + // std::unique_ptr m_clientSubspaceForSVGCursorElement; + // std::unique_ptr m_clientSubspaceForSVGDefsElement; + // std::unique_ptr m_clientSubspaceForSVGDescElement; + // std::unique_ptr m_clientSubspaceForSVGElement; + // std::unique_ptr m_clientSubspaceForSVGEllipseElement; + // std::unique_ptr m_clientSubspaceForSVGFEBlendElement; + // std::unique_ptr m_clientSubspaceForSVGFEColorMatrixElement; + // std::unique_ptr m_clientSubspaceForSVGFEComponentTransferElement; + // std::unique_ptr m_clientSubspaceForSVGFECompositeElement; + // std::unique_ptr m_clientSubspaceForSVGFEConvolveMatrixElement; + // std::unique_ptr m_clientSubspaceForSVGFEDiffuseLightingElement; + // std::unique_ptr m_clientSubspaceForSVGFEDisplacementMapElement; + // std::unique_ptr m_clientSubspaceForSVGFEDistantLightElement; + // std::unique_ptr m_clientSubspaceForSVGFEDropShadowElement; + // std::unique_ptr m_clientSubspaceForSVGFEFloodElement; + // std::unique_ptr m_clientSubspaceForSVGFEFuncAElement; + // std::unique_ptr m_clientSubspaceForSVGFEFuncBElement; + // std::unique_ptr m_clientSubspaceForSVGFEFuncGElement; + // std::unique_ptr m_clientSubspaceForSVGFEFuncRElement; + // std::unique_ptr m_clientSubspaceForSVGFEGaussianBlurElement; + // std::unique_ptr m_clientSubspaceForSVGFEImageElement; + // std::unique_ptr m_clientSubspaceForSVGFEMergeElement; + // std::unique_ptr m_clientSubspaceForSVGFEMergeNodeElement; + // std::unique_ptr m_clientSubspaceForSVGFEMorphologyElement; + // std::unique_ptr m_clientSubspaceForSVGFEOffsetElement; + // std::unique_ptr m_clientSubspaceForSVGFEPointLightElement; + // std::unique_ptr m_clientSubspaceForSVGFESpecularLightingElement; + // std::unique_ptr m_clientSubspaceForSVGFESpotLightElement; + // std::unique_ptr m_clientSubspaceForSVGFETileElement; + // std::unique_ptr m_clientSubspaceForSVGFETurbulenceElement; + // std::unique_ptr m_clientSubspaceForSVGFilterElement; + // std::unique_ptr m_clientSubspaceForSVGFontElement; + // std::unique_ptr m_clientSubspaceForSVGFontFaceElement; + // std::unique_ptr m_clientSubspaceForSVGFontFaceFormatElement; + // std::unique_ptr m_clientSubspaceForSVGFontFaceNameElement; + // std::unique_ptr m_clientSubspaceForSVGFontFaceSrcElement; + // std::unique_ptr m_clientSubspaceForSVGFontFaceUriElement; + // std::unique_ptr m_clientSubspaceForSVGForeignObjectElement; + // std::unique_ptr m_clientSubspaceForSVGGElement; + // std::unique_ptr m_clientSubspaceForSVGGeometryElement; + // std::unique_ptr m_clientSubspaceForSVGGlyphElement; + // std::unique_ptr m_clientSubspaceForSVGGlyphRefElement; + // std::unique_ptr m_clientSubspaceForSVGGradientElement; + // std::unique_ptr m_clientSubspaceForSVGGraphicsElement; + // std::unique_ptr m_clientSubspaceForSVGHKernElement; + // std::unique_ptr m_clientSubspaceForSVGImageElement; + // std::unique_ptr m_clientSubspaceForSVGLength; + // std::unique_ptr m_clientSubspaceForSVGLengthList; + // std::unique_ptr m_clientSubspaceForSVGLineElement; + // std::unique_ptr m_clientSubspaceForSVGLinearGradientElement; + // std::unique_ptr m_clientSubspaceForSVGMPathElement; + // std::unique_ptr m_clientSubspaceForSVGMarkerElement; + // std::unique_ptr m_clientSubspaceForSVGMaskElement; + // std::unique_ptr m_clientSubspaceForSVGMatrix; + // std::unique_ptr m_clientSubspaceForSVGMetadataElement; + // std::unique_ptr m_clientSubspaceForSVGMissingGlyphElement; + // std::unique_ptr m_clientSubspaceForSVGNumber; + // std::unique_ptr m_clientSubspaceForSVGNumberList; + // std::unique_ptr m_clientSubspaceForSVGPathElement; + // std::unique_ptr m_clientSubspaceForSVGPathSeg; + // std::unique_ptr m_clientSubspaceForSVGPathSegArcAbs; + // std::unique_ptr m_clientSubspaceForSVGPathSegArcRel; + // std::unique_ptr m_clientSubspaceForSVGPathSegClosePath; + // std::unique_ptr m_clientSubspaceForSVGPathSegCurvetoCubicAbs; + // std::unique_ptr m_clientSubspaceForSVGPathSegCurvetoCubicRel; + // std::unique_ptr m_clientSubspaceForSVGPathSegCurvetoCubicSmoothAbs; + // std::unique_ptr m_clientSubspaceForSVGPathSegCurvetoCubicSmoothRel; + // std::unique_ptr m_clientSubspaceForSVGPathSegCurvetoQuadraticAbs; + // std::unique_ptr m_clientSubspaceForSVGPathSegCurvetoQuadraticRel; + // std::unique_ptr m_clientSubspaceForSVGPathSegCurvetoQuadraticSmoothAbs; + // std::unique_ptr m_clientSubspaceForSVGPathSegCurvetoQuadraticSmoothRel; + // std::unique_ptr m_clientSubspaceForSVGPathSegLinetoAbs; + // std::unique_ptr m_clientSubspaceForSVGPathSegLinetoHorizontalAbs; + // std::unique_ptr m_clientSubspaceForSVGPathSegLinetoHorizontalRel; + // std::unique_ptr m_clientSubspaceForSVGPathSegLinetoRel; + // std::unique_ptr m_clientSubspaceForSVGPathSegLinetoVerticalAbs; + // std::unique_ptr m_clientSubspaceForSVGPathSegLinetoVerticalRel; + // std::unique_ptr m_clientSubspaceForSVGPathSegList; + // std::unique_ptr m_clientSubspaceForSVGPathSegMovetoAbs; + // std::unique_ptr m_clientSubspaceForSVGPathSegMovetoRel; + // std::unique_ptr m_clientSubspaceForSVGPatternElement; + // std::unique_ptr m_clientSubspaceForSVGPoint; + // std::unique_ptr m_clientSubspaceForSVGPointList; + // std::unique_ptr m_clientSubspaceForSVGPolygonElement; + // std::unique_ptr m_clientSubspaceForSVGPolylineElement; + // std::unique_ptr m_clientSubspaceForSVGPreserveAspectRatio; + // std::unique_ptr m_clientSubspaceForSVGRadialGradientElement; + // std::unique_ptr m_clientSubspaceForSVGRect; + // std::unique_ptr m_clientSubspaceForSVGRectElement; + // std::unique_ptr m_clientSubspaceForSVGRenderingIntent; + // std::unique_ptr m_clientSubspaceForSVGSVGElement; + // std::unique_ptr m_clientSubspaceForSVGScriptElement; + // std::unique_ptr m_clientSubspaceForSVGSetElement; + // std::unique_ptr m_clientSubspaceForSVGStopElement; + // std::unique_ptr m_clientSubspaceForSVGStringList; + // std::unique_ptr m_clientSubspaceForSVGStyleElement; + // std::unique_ptr m_clientSubspaceForSVGSwitchElement; + // std::unique_ptr m_clientSubspaceForSVGSymbolElement; + // std::unique_ptr m_clientSubspaceForSVGTRefElement; + // std::unique_ptr m_clientSubspaceForSVGTSpanElement; + // std::unique_ptr m_clientSubspaceForSVGTextContentElement; + // std::unique_ptr m_clientSubspaceForSVGTextElement; + // std::unique_ptr m_clientSubspaceForSVGTextPathElement; + // std::unique_ptr m_clientSubspaceForSVGTextPositioningElement; + // std::unique_ptr m_clientSubspaceForSVGTitleElement; + // std::unique_ptr m_clientSubspaceForSVGTransform; + // std::unique_ptr m_clientSubspaceForSVGTransformList; + // std::unique_ptr m_clientSubspaceForSVGUnitTypes; + // std::unique_ptr m_clientSubspaceForSVGUseElement; + // std::unique_ptr m_clientSubspaceForSVGVKernElement; + // std::unique_ptr m_clientSubspaceForSVGViewElement; + // std::unique_ptr m_clientSubspaceForSVGViewSpec; + // std::unique_ptr m_clientSubspaceForSVGZoomEvent; + // std::unique_ptr m_clientSubspaceForGCObservation; + // std::unique_ptr m_clientSubspaceForInternalSettings; + // std::unique_ptr m_clientSubspaceForInternals; + // std::unique_ptr m_clientSubspaceForInternalsMapLike; + // std::unique_ptr m_clientSubspaceForInternalsSetLike; + // std::unique_ptr m_clientSubspaceForMallocStatistics; + // std::unique_ptr m_clientSubspaceForMemoryInfo; + // std::unique_ptr m_clientSubspaceForMockCDMFactory; + // std::unique_ptr m_clientSubspaceForMockContentFilterSettings; + // std::unique_ptr m_clientSubspaceForMockPageOverlay; + // std::unique_ptr m_clientSubspaceForMockPaymentCoordinator; + // std::unique_ptr m_clientSubspaceForServiceWorkerInternals; + // std::unique_ptr m_clientSubspaceForTypeConversions; + // std::unique_ptr m_clientSubspaceForWebFakeXRDevice; + // std::unique_ptr m_clientSubspaceForWebFakeXRInputController; + // std::unique_ptr m_clientSubspaceForWebXRTest; + // std::unique_ptr m_clientSubspaceForDedicatedWorkerGlobalScope; + // std::unique_ptr m_clientSubspaceForWorker; + // std::unique_ptr m_clientSubspaceForWorkerGlobalScope; + // std::unique_ptr m_clientSubspaceForWorkerLocation; + // std::unique_ptr m_clientSubspaceForExtendableEvent; + // std::unique_ptr m_clientSubspaceForExtendableMessageEvent; + // std::unique_ptr m_clientSubspaceForFetchEvent; + // std::unique_ptr m_clientSubspaceForNavigationPreloadManager; + // std::unique_ptr m_clientSubspaceForServiceWorker; + // std::unique_ptr m_clientSubspaceForServiceWorkerClient; + // std::unique_ptr m_clientSubspaceForServiceWorkerClients; + // std::unique_ptr m_clientSubspaceForServiceWorkerContainer; + // std::unique_ptr m_clientSubspaceForServiceWorkerGlobalScope; + // std::unique_ptr m_clientSubspaceForServiceWorkerRegistration; + // std::unique_ptr m_clientSubspaceForServiceWorkerWindowClient; + // std::unique_ptr m_clientSubspaceForSharedWorker; + // std::unique_ptr m_clientSubspaceForSharedWorkerGlobalScope; + // std::unique_ptr m_clientSubspaceForPaintWorkletGlobalScope; + // std::unique_ptr m_clientSubspaceForWorklet; + // std::unique_ptr m_clientSubspaceForWorkletGlobalScope; + // std::unique_ptr m_clientSubspaceForDOMParser; + // std::unique_ptr m_clientSubspaceForXMLHttpRequest; + // std::unique_ptr m_clientSubspaceForXMLHttpRequestEventTarget; + // std::unique_ptr m_clientSubspaceForXMLHttpRequestProgressEvent; + // std::unique_ptr m_clientSubspaceForXMLHttpRequestUpload; + // std::unique_ptr m_clientSubspaceForXMLSerializer; + // std::unique_ptr m_clientSubspaceForXPathEvaluator; + // std::unique_ptr m_clientSubspaceForXPathExpression; + // std::unique_ptr m_clientSubspaceForXPathNSResolver; + // std::unique_ptr m_clientSubspaceForXPathResult; + // std::unique_ptr m_clientSubspaceForXSLTProcessor; +}; +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/DOMConstructors.h b/src/javascript/jsc/bindings/webcore/DOMConstructors.h new file mode 100644 index 0000000000..3d6833e7a9 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/DOMConstructors.h @@ -0,0 +1,864 @@ +#include "JavaScriptCore/JSCInlines.h" +#include "wtf/FastMalloc.h" +#include "wtf/Noncopyable.h" + +#pragma once + +namespace WebCore { + +enum class DOMConstructorID : uint16_t { + Touch, + TouchEvent, + TouchList, + InternalSettingsGenerated, + GPU, + GPUAdapter, + GPUBindGroup, + GPUBindGroupLayout, + GPUBuffer, + GPUBufferUsage, + GPUCanvasContext, + GPUColorWrite, + GPUCommandBuffer, + GPUCommandEncoder, + GPUCompilationInfo, + GPUCompilationMessage, + GPUComputePassEncoder, + GPUComputePipeline, + GPUDevice, + GPUDeviceLostInfo, + GPUExternalTexture, + GPUMapMode, + GPUOutOfMemoryError, + GPUPipelineLayout, + GPUQuerySet, + GPUQueue, + GPURenderBundle, + GPURenderBundleEncoder, + GPURenderPassEncoder, + GPURenderPipeline, + GPUSampler, + GPUShaderModule, + GPUShaderStage, + GPUSupportedFeatures, + GPUSupportedLimits, + GPUTexture, + GPUTextureUsage, + GPUTextureView, + GPUUncapturedErrorEvent, + GPUValidationError, + WebKitPlaybackTargetAvailabilityEvent, + ApplePayCancelEvent, + ApplePayCouponCodeChangedEvent, + ApplePayError, + ApplePayPaymentAuthorizedEvent, + ApplePayPaymentMethodSelectedEvent, + ApplePaySession, + ApplePaySetup, + ApplePaySetupFeature, + ApplePayShippingContactSelectedEvent, + ApplePayShippingMethodSelectedEvent, + ApplePayValidateMerchantEvent, + Clipboard, + ClipboardItem, + DOMCache, + DOMCacheStorage, + ContactsManager, + BasicCredential, + CredentialsContainer, + MediaKeyMessageEvent, + MediaKeySession, + MediaKeyStatusMap, + MediaKeySystemAccess, + MediaKeys, + WebKitMediaKeyMessageEvent, + WebKitMediaKeyNeededEvent, + WebKitMediaKeySession, + WebKitMediaKeys, + DOMFileSystem, + FileSystemDirectoryEntry, + FileSystemDirectoryReader, + FileSystemEntry, + FileSystemFileEntry, + FetchHeaders, + FetchRequest, + FetchResponse, + FileSystemDirectoryHandle, + FileSystemFileHandle, + FileSystemHandle, + FileSystemSyncAccessHandle, + Gamepad, + GamepadButton, + GamepadEvent, + Geolocation, + GeolocationCoordinates, + GeolocationPosition, + GeolocationPositionError, + Highlight, + HighlightRegister, + IDBCursor, + IDBCursorWithValue, + IDBDatabase, + IDBFactory, + IDBIndex, + IDBKeyRange, + IDBObjectStore, + IDBOpenDBRequest, + IDBRequest, + IDBTransaction, + IDBVersionChangeEvent, + MediaCapabilities, + MediaControlsHost, + BlobEvent, + MediaRecorder, + MediaRecorderErrorEvent, + MediaMetadata, + MediaSession, + MediaSessionCoordinator, + MediaSource, + SourceBuffer, + SourceBufferList, + VideoPlaybackQuality, + CanvasCaptureMediaStreamTrack, + MediaDeviceInfo, + MediaDevices, + MediaStream, + MediaStreamTrack, + MediaStreamTrackEvent, + OverconstrainedError, + OverconstrainedErrorEvent, + RTCCertificate, + RTCDTMFSender, + RTCDTMFToneChangeEvent, + RTCDataChannel, + RTCDataChannelEvent, + RTCDtlsTransport, + RTCEncodedAudioFrame, + RTCEncodedVideoFrame, + RTCError, + RTCErrorEvent, + RTCIceCandidate, + RTCIceTransport, + RTCPeerConnection, + RTCPeerConnectionIceErrorEvent, + RTCPeerConnectionIceEvent, + RTCRtpReceiver, + RTCRtpSFrameTransform, + RTCRtpSFrameTransformErrorEvent, + RTCRtpScriptTransform, + RTCRtpScriptTransformer, + RTCRtpSender, + RTCRtpTransceiver, + RTCSctpTransport, + RTCSessionDescription, + RTCStatsReport, + RTCTrackEvent, + RTCTransformEvent, + HTMLModelElement, + Notification, + NotificationEvent, + MerchantValidationEvent, + PaymentAddress, + PaymentMethodChangeEvent, + PaymentRequest, + PaymentRequestUpdateEvent, + PaymentResponse, + PermissionStatus, + Permissions, + PictureInPictureEvent, + PictureInPictureWindow, + PushEvent, + PushManager, + PushMessageData, + PushSubscription, + PushSubscriptionChangeEvent, + PushSubscriptionOptions, + RemotePlayback, + SpeechRecognition, + SpeechRecognitionAlternative, + SpeechRecognitionErrorEvent, + SpeechRecognitionEvent, + SpeechRecognitionResult, + SpeechRecognitionResultList, + SpeechSynthesis, + SpeechSynthesisErrorEvent, + SpeechSynthesisEvent, + SpeechSynthesisUtterance, + SpeechSynthesisVoice, + StorageManager, + ByteLengthQueuingStrategy, + CountQueuingStrategy, + ReadableByteStreamController, + ReadableStream, + ReadableStreamBYOBReader, + ReadableStreamBYOBRequest, + ReadableStreamDefaultController, + ReadableStreamDefaultReader, + ReadableStreamSink, + ReadableStreamSource, + TransformStream, + TransformStreamDefaultController, + WritableStream, + WritableStreamDefaultController, + WritableStreamDefaultWriter, + WritableStreamSink, + WebLock, + WebLockManager, + AnalyserNode, + AudioBuffer, + AudioBufferSourceNode, + AudioContext, + AudioDestinationNode, + AudioListener, + AudioNode, + AudioParam, + AudioParamMap, + AudioProcessingEvent, + AudioScheduledSourceNode, + AudioWorklet, + AudioWorkletGlobalScope, + AudioWorkletNode, + AudioWorkletProcessor, + BaseAudioContext, + BiquadFilterNode, + ChannelMergerNode, + ChannelSplitterNode, + ConstantSourceNode, + ConvolverNode, + DelayNode, + DynamicsCompressorNode, + GainNode, + IIRFilterNode, + MediaElementAudioSourceNode, + MediaStreamAudioDestinationNode, + MediaStreamAudioSourceNode, + OfflineAudioCompletionEvent, + OfflineAudioContext, + OscillatorNode, + PannerNode, + PeriodicWave, + ScriptProcessorNode, + StereoPannerNode, + WaveShaperNode, + AuthenticatorAssertionResponse, + AuthenticatorAttestationResponse, + AuthenticatorResponse, + PublicKeyCredential, + VideoColorSpace, + Database, + SQLError, + SQLResultSet, + SQLResultSetRowList, + SQLTransaction, + CloseEvent, + WebSocket, + WebXRBoundedReferenceSpace, + WebXRFrame, + WebXRHand, + WebXRInputSource, + WebXRInputSourceArray, + WebXRJointPose, + WebXRJointSpace, + WebXRLayer, + WebXRPose, + WebXRReferenceSpace, + WebXRRenderState, + WebXRRigidTransform, + WebXRSession, + WebXRSpace, + WebXRSystem, + WebXRView, + WebXRViewerPose, + WebXRViewport, + WebXRWebGLLayer, + XRInputSourceEvent, + XRInputSourcesChangeEvent, + XRReferenceSpaceEvent, + XRSessionEvent, + AnimationEffect, + AnimationPlaybackEvent, + AnimationTimeline, + CSSAnimation, + CSSTransition, + CustomEffect, + DocumentTimeline, + KeyframeEffect, + WebAnimation, + CryptoKey, + SubtleCrypto, + CSSConditionRule, + CSSCounterStyleRule, + CSSFontFaceRule, + CSSFontPaletteValuesRule, + CSSGroupingRule, + CSSImportRule, + CSSKeyframeRule, + CSSKeyframesRule, + CSSLayerBlockRule, + CSSLayerStatementRule, + CSSMediaRule, + CSSNamespaceRule, + CSSPageRule, + CSSPaintSize, + CSSRule, + CSSRuleList, + CSSStyleDeclaration, + CSSStyleRule, + CSSStyleSheet, + CSSSupportsRule, + CSSUnknownRule, + DOMCSSNamespace, + DOMMatrix, + DOMMatrixReadOnly, + DeprecatedCSSOMCounter, + DeprecatedCSSOMPrimitiveValue, + DeprecatedCSSOMRGBColor, + DeprecatedCSSOMRect, + DeprecatedCSSOMValue, + DeprecatedCSSOMValueList, + FontFace, + FontFaceSet, + MediaList, + MediaQueryList, + MediaQueryListEvent, + StyleMedia, + StyleSheet, + StyleSheetList, + CSSKeywordValue, + CSSNumericValue, + CSSOMVariableReferenceValue, + CSSStyleImageValue, + CSSStyleValue, + CSSUnitValue, + CSSUnparsedValue, + StylePropertyMap, + StylePropertyMapReadOnly, + CSSMathInvert, + CSSMathMax, + CSSMathMin, + CSSMathNegate, + CSSMathProduct, + CSSMathSum, + CSSMathValue, + CSSNumericArray, + CSSMatrixComponent, + CSSPerspective, + CSSRotate, + CSSScale, + CSSSkew, + CSSSkewX, + CSSSkewY, + CSSTransformComponent, + CSSTransformValue, + CSSTranslate, + AbortController, + AbortSignal, + AbstractRange, + AnimationEvent, + Attr, + BeforeUnloadEvent, + BroadcastChannel, + CDATASection, + CharacterData, + ClipboardEvent, + Comment, + CompositionEvent, + CustomElementRegistry, + CustomEvent, + DOMException, + DOMImplementation, + DOMPoint, + DOMPointReadOnly, + DOMQuad, + DOMRect, + DOMRectList, + DOMRectReadOnly, + DOMStringList, + DOMStringMap, + DataTransfer, + DataTransferItem, + DataTransferItemList, + DeviceMotionEvent, + DeviceOrientationEvent, + Document, + DocumentFragment, + DocumentType, + DragEvent, + Element, + ErrorEvent, + Event, + EventListener, + EventTarget, + FocusEvent, + FormDataEvent, + HashChangeEvent, + IdleDeadline, + InputEvent, + KeyboardEvent, + MessageChannel, + MessageEvent, + MessagePort, + MouseEvent, + MutationEvent, + MutationObserver, + MutationRecord, + NamedNodeMap, + Node, + NodeFilter, + NodeIterator, + NodeList, + OverflowEvent, + PageTransitionEvent, + PointerEvent, + PopStateEvent, + ProcessingInstruction, + ProgressEvent, + PromiseRejectionEvent, + Range, + SecurityPolicyViolationEvent, + ShadowRoot, + StaticRange, + Text, + TextDecoder, + TextDecoderStream, + TextDecoderStreamDecoder, + TextEncoder, + TextEncoderStream, + TextEncoderStreamEncoder, + TextEvent, + TransitionEvent, + TreeWalker, + UIEvent, + WheelEvent, + XMLDocument, + Blob, + File, + FileList, + FileReader, + FileReaderSync, + DOMFormData, + DOMTokenList, + DOMURL, + HTMLAllCollection, + HTMLAnchorElement, + HTMLAreaElement, + HTMLAttachmentElement, + HTMLAudioElement, + HTMLAudioElementLegacyFactory, + HTMLBRElement, + HTMLBaseElement, + HTMLBodyElement, + HTMLButtonElement, + HTMLCanvasElement, + HTMLCollection, + HTMLDListElement, + HTMLDataElement, + HTMLDataListElement, + HTMLDetailsElement, + HTMLDialogElement, + HTMLDirectoryElement, + HTMLDivElement, + HTMLDocument, + HTMLElement, + HTMLEmbedElement, + HTMLFieldSetElement, + HTMLFontElement, + HTMLFormControlsCollection, + HTMLFormElement, + HTMLFrameElement, + HTMLFrameSetElement, + HTMLHRElement, + HTMLHeadElement, + HTMLHeadingElement, + HTMLHtmlElement, + HTMLIFrameElement, + HTMLImageElement, + HTMLImageElementLegacyFactory, + HTMLInputElement, + HTMLLIElement, + HTMLLabelElement, + HTMLLegendElement, + HTMLLinkElement, + HTMLMapElement, + HTMLMarqueeElement, + HTMLMediaElement, + HTMLMenuElement, + HTMLMenuItemElement, + HTMLMetaElement, + HTMLMeterElement, + HTMLModElement, + HTMLOListElement, + HTMLObjectElement, + HTMLOptGroupElement, + HTMLOptionElement, + HTMLOptionElementLegacyFactory, + HTMLOptionsCollection, + HTMLOutputElement, + HTMLParagraphElement, + HTMLParamElement, + HTMLPictureElement, + HTMLPreElement, + HTMLProgressElement, + HTMLQuoteElement, + HTMLScriptElement, + HTMLSelectElement, + HTMLSlotElement, + HTMLSourceElement, + HTMLSpanElement, + HTMLStyleElement, + HTMLTableCaptionElement, + HTMLTableCellElement, + HTMLTableColElement, + HTMLTableElement, + HTMLTableRowElement, + HTMLTableSectionElement, + HTMLTemplateElement, + HTMLTextAreaElement, + HTMLTimeElement, + HTMLTitleElement, + HTMLTrackElement, + HTMLUListElement, + HTMLUnknownElement, + HTMLVideoElement, + ImageBitmap, + ImageData, + MediaController, + MediaEncryptedEvent, + MediaError, + OffscreenCanvas, + RadioNodeList, + SubmitEvent, + TextMetrics, + TimeRanges, + URLSearchParams, + ValidityState, + WebKitMediaKeyError, + ANGLEInstancedArrays, + CanvasGradient, + CanvasPattern, + CanvasRenderingContext2D, + EXTBlendMinMax, + EXTColorBufferFloat, + EXTColorBufferHalfFloat, + EXTFloatBlend, + EXTFragDepth, + EXTShaderTextureLOD, + EXTTextureCompressionRGTC, + EXTTextureFilterAnisotropic, + EXTsRGB, + ImageBitmapRenderingContext, + KHRParallelShaderCompile, + OESElementIndexUint, + OESFBORenderMipmap, + OESStandardDerivatives, + OESTextureFloat, + OESTextureFloatLinear, + OESTextureHalfFloat, + OESTextureHalfFloatLinear, + OESVertexArrayObject, + OffscreenCanvasRenderingContext2D, + PaintRenderingContext2D, + Path2D, + WebGL2RenderingContext, + WebGLActiveInfo, + WebGLBuffer, + WebGLColorBufferFloat, + WebGLCompressedTextureASTC, + WebGLCompressedTextureATC, + WebGLCompressedTextureETC, + WebGLCompressedTextureETC1, + WebGLCompressedTexturePVRTC, + WebGLCompressedTextureS3TC, + WebGLCompressedTextureS3TCsRGB, + WebGLContextEvent, + WebGLDebugRendererInfo, + WebGLDebugShaders, + WebGLDepthTexture, + WebGLDrawBuffers, + WebGLFramebuffer, + WebGLLoseContext, + WebGLMultiDraw, + WebGLProgram, + WebGLQuery, + WebGLRenderbuffer, + WebGLRenderingContext, + WebGLSampler, + WebGLShader, + WebGLShaderPrecisionFormat, + WebGLSync, + WebGLTexture, + WebGLTransformFeedback, + WebGLUniformLocation, + WebGLVertexArrayObject, + WebGLVertexArrayObjectOES, + AudioTrack, + AudioTrackConfiguration, + AudioTrackList, + DataCue, + TextTrack, + TextTrackCue, + TextTrackCueGeneric, + TextTrackCueList, + TextTrackList, + TrackEvent, + VTTCue, + VTTRegion, + VTTRegionList, + VideoTrack, + VideoTrackConfiguration, + VideoTrackList, + CommandLineAPIHost, + InspectorAuditAccessibilityObject, + InspectorAuditDOMObject, + InspectorAuditResourcesObject, + InspectorFrontendHost, + DOMApplicationCache, + MathMLElement, + MathMLMathElement, + BarProp, + Crypto, + DOMSelection, + DOMWindow, + EventSource, + History, + IntersectionObserver, + IntersectionObserverEntry, + Location, + Navigator, + Performance, + PerformanceEntry, + PerformanceMark, + PerformanceMeasure, + PerformanceNavigation, + PerformanceNavigationTiming, + PerformanceObserver, + PerformanceObserverEntryList, + PerformancePaintTiming, + PerformanceResourceTiming, + PerformanceServerTiming, + PerformanceTiming, + RemoteDOMWindow, + ResizeObserver, + ResizeObserverEntry, + ResizeObserverSize, + Screen, + ShadowRealmGlobalScope, + UndoItem, + UndoManager, + UserMessageHandler, + UserMessageHandlersNamespace, + VisualViewport, + WebKitNamespace, + WebKitPoint, + WorkerNavigator, + DOMMimeType, + DOMMimeTypeArray, + DOMPlugin, + DOMPluginArray, + Storage, + StorageEvent, + SVGAElement, + SVGAltGlyphDefElement, + SVGAltGlyphElement, + SVGAltGlyphItemElement, + SVGAngle, + SVGAnimateColorElement, + SVGAnimateElement, + SVGAnimateMotionElement, + SVGAnimateTransformElement, + SVGAnimatedAngle, + SVGAnimatedBoolean, + SVGAnimatedEnumeration, + SVGAnimatedInteger, + SVGAnimatedLength, + SVGAnimatedLengthList, + SVGAnimatedNumber, + SVGAnimatedNumberList, + SVGAnimatedPreserveAspectRatio, + SVGAnimatedRect, + SVGAnimatedString, + SVGAnimatedTransformList, + SVGAnimationElement, + SVGCircleElement, + SVGClipPathElement, + SVGComponentTransferFunctionElement, + SVGCursorElement, + SVGDefsElement, + SVGDescElement, + SVGElement, + SVGEllipseElement, + SVGFEBlendElement, + SVGFEColorMatrixElement, + SVGFEComponentTransferElement, + SVGFECompositeElement, + SVGFEConvolveMatrixElement, + SVGFEDiffuseLightingElement, + SVGFEDisplacementMapElement, + SVGFEDistantLightElement, + SVGFEDropShadowElement, + SVGFEFloodElement, + SVGFEFuncAElement, + SVGFEFuncBElement, + SVGFEFuncGElement, + SVGFEFuncRElement, + SVGFEGaussianBlurElement, + SVGFEImageElement, + SVGFEMergeElement, + SVGFEMergeNodeElement, + SVGFEMorphologyElement, + SVGFEOffsetElement, + SVGFEPointLightElement, + SVGFESpecularLightingElement, + SVGFESpotLightElement, + SVGFETileElement, + SVGFETurbulenceElement, + SVGFilterElement, + SVGFontElement, + SVGFontFaceElement, + SVGFontFaceFormatElement, + SVGFontFaceNameElement, + SVGFontFaceSrcElement, + SVGFontFaceUriElement, + SVGForeignObjectElement, + SVGGElement, + SVGGeometryElement, + SVGGlyphElement, + SVGGlyphRefElement, + SVGGradientElement, + SVGGraphicsElement, + SVGHKernElement, + SVGImageElement, + SVGLength, + SVGLengthList, + SVGLineElement, + SVGLinearGradientElement, + SVGMPathElement, + SVGMarkerElement, + SVGMaskElement, + SVGMatrix, + SVGMetadataElement, + SVGMissingGlyphElement, + SVGNumber, + SVGNumberList, + SVGPathElement, + SVGPathSeg, + SVGPathSegArcAbs, + SVGPathSegArcRel, + SVGPathSegClosePath, + SVGPathSegCurvetoCubicAbs, + SVGPathSegCurvetoCubicRel, + SVGPathSegCurvetoCubicSmoothAbs, + SVGPathSegCurvetoCubicSmoothRel, + SVGPathSegCurvetoQuadraticAbs, + SVGPathSegCurvetoQuadraticRel, + SVGPathSegCurvetoQuadraticSmoothAbs, + SVGPathSegCurvetoQuadraticSmoothRel, + SVGPathSegLinetoAbs, + SVGPathSegLinetoHorizontalAbs, + SVGPathSegLinetoHorizontalRel, + SVGPathSegLinetoRel, + SVGPathSegLinetoVerticalAbs, + SVGPathSegLinetoVerticalRel, + SVGPathSegList, + SVGPathSegMovetoAbs, + SVGPathSegMovetoRel, + SVGPatternElement, + SVGPoint, + SVGPointList, + SVGPolygonElement, + SVGPolylineElement, + SVGPreserveAspectRatio, + SVGRadialGradientElement, + SVGRect, + SVGRectElement, + SVGRenderingIntent, + SVGSVGElement, + SVGScriptElement, + SVGSetElement, + SVGStopElement, + SVGStringList, + SVGStyleElement, + SVGSwitchElement, + SVGSymbolElement, + SVGTRefElement, + SVGTSpanElement, + SVGTextContentElement, + SVGTextElement, + SVGTextPathElement, + SVGTextPositioningElement, + SVGTitleElement, + SVGTransform, + SVGTransformList, + SVGUnitTypes, + SVGUseElement, + SVGVKernElement, + SVGViewElement, + SVGViewSpec, + SVGZoomEvent, + GCObservation, + InternalSettings, + Internals, + InternalsMapLike, + InternalsSetLike, + MallocStatistics, + MemoryInfo, + MockCDMFactory, + MockContentFilterSettings, + MockPageOverlay, + MockPaymentCoordinator, + ServiceWorkerInternals, + TypeConversions, + WebFakeXRDevice, + WebFakeXRInputController, + WebXRTest, + DedicatedWorkerGlobalScope, + Worker, + WorkerGlobalScope, + WorkerLocation, + ExtendableEvent, + ExtendableMessageEvent, + FetchEvent, + NavigationPreloadManager, + ServiceWorker, + ServiceWorkerClient, + ServiceWorkerClients, + ServiceWorkerContainer, + ServiceWorkerGlobalScope, + ServiceWorkerRegistration, + ServiceWorkerWindowClient, + SharedWorker, + SharedWorkerGlobalScope, + PaintWorkletGlobalScope, + Worklet, + WorkletGlobalScope, + CustomXPathNSResolver, + DOMParser, + XMLHttpRequest, + XMLHttpRequestEventTarget, + XMLHttpRequestProgressEvent, + XMLHttpRequestUpload, + XMLSerializer, + XPathEvaluator, + XPathExpression, + XPathNSResolver, + XPathResult, + XSLTProcessor, +}; + +static constexpr unsigned numberOfDOMConstructors = 836; + +class DOMConstructors { + WTF_MAKE_NONCOPYABLE(DOMConstructors); + WTF_MAKE_FAST_ALLOCATED(DOMConstructors); + +public: + using ConstructorArray = std::array, numberOfDOMConstructors>; + DOMConstructors() = default; + ConstructorArray& array() { return m_array; } + const ConstructorArray& array() const { return m_array; } + +private: + ConstructorArray m_array {}; +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/DOMIsoSubspaces.h b/src/javascript/jsc/bindings/webcore/DOMIsoSubspaces.h new file mode 100644 index 0000000000..dd1a665a49 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/DOMIsoSubspaces.h @@ -0,0 +1,877 @@ + +#pragma once + +#include "root.h" + +#include "wtf/FastMalloc.h" +#include "wtf/Noncopyable.h" + +namespace WebCore { +using namespace JSC; + +class DOMIsoSubspaces { + WTF_MAKE_NONCOPYABLE(DOMIsoSubspaces); + WTF_MAKE_FAST_ALLOCATED(DOMIsoSubspaces); + +public: + DOMIsoSubspaces() = default; + // std::unique_ptr m_subspaceForTouch; + // std::unique_ptr m_subspaceForTouchEvent; + // std::unique_ptr m_subspaceForTouchList; + // std::unique_ptr m_subspaceForInternalSettingsGenerated; + // std::unique_ptr m_subspaceForGPU; + // std::unique_ptr m_subspaceForGPUAdapter; + // std::unique_ptr m_subspaceForGPUBindGroup; + // std::unique_ptr m_subspaceForGPUBindGroupLayout; + // std::unique_ptr m_subspaceForGPUBuffer; + // std::unique_ptr m_subspaceForGPUBufferUsage; + // std::unique_ptr m_subspaceForGPUCanvasContext; + // std::unique_ptr m_subspaceForGPUColorWrite; + // std::unique_ptr m_subspaceForGPUCommandBuffer; + // std::unique_ptr m_subspaceForGPUCommandEncoder; + // std::unique_ptr m_subspaceForGPUCompilationInfo; + // std::unique_ptr m_subspaceForGPUCompilationMessage; + // std::unique_ptr m_subspaceForGPUComputePassEncoder; + // std::unique_ptr m_subspaceForGPUComputePipeline; + // std::unique_ptr m_subspaceForGPUDevice; + // std::unique_ptr m_subspaceForGPUDeviceLostInfo; + // std::unique_ptr m_subspaceForGPUExternalTexture; + // std::unique_ptr m_subspaceForGPUMapMode; + // std::unique_ptr m_subspaceForGPUOutOfMemoryError; + // std::unique_ptr m_subspaceForGPUPipelineLayout; + // std::unique_ptr m_subspaceForGPUQuerySet; + // std::unique_ptr m_subspaceForGPUQueue; + // std::unique_ptr m_subspaceForGPURenderBundle; + // std::unique_ptr m_subspaceForGPURenderBundleEncoder; + // std::unique_ptr m_subspaceForGPURenderPassEncoder; + // std::unique_ptr m_subspaceForGPURenderPipeline; + // std::unique_ptr m_subspaceForGPUSampler; + // std::unique_ptr m_subspaceForGPUShaderModule; + // std::unique_ptr m_subspaceForGPUShaderStage; + // std::unique_ptr m_subspaceForGPUSupportedFeatures; + // std::unique_ptr m_subspaceForGPUSupportedLimits; + // std::unique_ptr m_subspaceForGPUTexture; + // std::unique_ptr m_subspaceForGPUTextureUsage; + // std::unique_ptr m_subspaceForGPUTextureView; + // std::unique_ptr m_subspaceForGPUUncapturedErrorEvent; + // std::unique_ptr m_subspaceForGPUValidationError; + // std::unique_ptr m_subspaceForWebKitPlaybackTargetAvailabilityEvent; + // std::unique_ptr m_subspaceForApplePayCancelEvent; + // std::unique_ptr m_subspaceForApplePayCouponCodeChangedEvent; + // std::unique_ptr m_subspaceForApplePayError; + // std::unique_ptr m_subspaceForApplePayPaymentAuthorizedEvent; + // std::unique_ptr m_subspaceForApplePayPaymentMethodSelectedEvent; + // std::unique_ptr m_subspaceForApplePaySession; + // std::unique_ptr m_subspaceForApplePaySetup; + // std::unique_ptr m_subspaceForApplePaySetupFeature; + // std::unique_ptr m_subspaceForApplePayShippingContactSelectedEvent; + // std::unique_ptr m_subspaceForApplePayShippingMethodSelectedEvent; + // std::unique_ptr m_subspaceForApplePayValidateMerchantEvent; + // std::unique_ptr m_subspaceForClipboard; + // std::unique_ptr m_subspaceForClipboardItem; + // std::unique_ptr m_subspaceForDOMCache; + // std::unique_ptr m_subspaceForDOMCacheStorage; + // std::unique_ptr m_subspaceForContactsManager; + // std::unique_ptr m_subspaceForBasicCredential; + // std::unique_ptr m_subspaceForCredentialsContainer; + // std::unique_ptr m_subspaceForMediaKeyMessageEvent; + // std::unique_ptr m_subspaceForMediaKeySession; + // std::unique_ptr m_subspaceForMediaKeyStatusMap; + // std::unique_ptr m_subspaceForMediaKeyStatusMapIterator; + // std::unique_ptr m_subspaceForMediaKeySystemAccess; + // std::unique_ptr m_subspaceForMediaKeys; + // std::unique_ptr m_subspaceForWebKitMediaKeyMessageEvent; + // std::unique_ptr m_subspaceForWebKitMediaKeyNeededEvent; + // std::unique_ptr m_subspaceForWebKitMediaKeySession; + // std::unique_ptr m_subspaceForWebKitMediaKeys; + // std::unique_ptr m_subspaceForDOMFileSystem; + // std::unique_ptr m_subspaceForFileSystemDirectoryEntry; + // std::unique_ptr m_subspaceForFileSystemDirectoryReader; + // std::unique_ptr m_subspaceForFileSystemEntry; + // std::unique_ptr m_subspaceForFileSystemFileEntry; + // std::unique_ptr m_subspaceForFetchHeaders; + // std::unique_ptr m_subspaceForFetchHeadersIterator; + // std::unique_ptr m_subspaceForFetchRequest; + // std::unique_ptr m_subspaceForFetchResponse; + // std::unique_ptr m_subspaceForFileSystemDirectoryHandle; + // std::unique_ptr m_subspaceForFileSystemFileHandle; + // std::unique_ptr m_subspaceForFileSystemHandle; + // std::unique_ptr m_subspaceForFileSystemSyncAccessHandle; + // std::unique_ptr m_subspaceForGamepad; + // std::unique_ptr m_subspaceForGamepadButton; + // std::unique_ptr m_subspaceForGamepadEvent; + // std::unique_ptr m_subspaceForGeolocation; + // std::unique_ptr m_subspaceForGeolocationCoordinates; + // std::unique_ptr m_subspaceForGeolocationPosition; + // std::unique_ptr m_subspaceForGeolocationPositionError; + // std::unique_ptr m_subspaceForHighlight; + // std::unique_ptr m_subspaceForHighlightRegister; + // std::unique_ptr m_subspaceForIDBCursor; + // std::unique_ptr m_subspaceForIDBCursorWithValue; + // std::unique_ptr m_subspaceForIDBDatabase; + // std::unique_ptr m_subspaceForIDBFactory; + // std::unique_ptr m_subspaceForIDBIndex; + // std::unique_ptr m_subspaceForIDBKeyRange; + // std::unique_ptr m_subspaceForIDBObjectStore; + // std::unique_ptr m_subspaceForIDBOpenDBRequest; + // std::unique_ptr m_subspaceForIDBRequest; + // std::unique_ptr m_subspaceForIDBTransaction; + // std::unique_ptr m_subspaceForIDBVersionChangeEvent; + // std::unique_ptr m_subspaceForMediaCapabilities; + // std::unique_ptr m_subspaceForMediaControlsHost; + // std::unique_ptr m_subspaceForBlobEvent; + // std::unique_ptr m_subspaceForMediaRecorder; + // std::unique_ptr m_subspaceForMediaRecorderErrorEvent; + // std::unique_ptr m_subspaceForMediaMetadata; + // std::unique_ptr m_subspaceForMediaSession; + // std::unique_ptr m_subspaceForMediaSessionCoordinator; + // std::unique_ptr m_subspaceForMediaSource; + // std::unique_ptr m_subspaceForSourceBuffer; + // std::unique_ptr m_subspaceForSourceBufferList; + // std::unique_ptr m_subspaceForVideoPlaybackQuality; + // std::unique_ptr m_subspaceForCanvasCaptureMediaStreamTrack; + // std::unique_ptr m_subspaceForMediaDeviceInfo; + // std::unique_ptr m_subspaceForMediaDevices; + // std::unique_ptr m_subspaceForMediaStream; + // std::unique_ptr m_subspaceForMediaStreamTrack; + // std::unique_ptr m_subspaceForMediaStreamTrackEvent; + // std::unique_ptr m_subspaceForOverconstrainedError; + // std::unique_ptr m_subspaceForOverconstrainedErrorEvent; + // std::unique_ptr m_subspaceForRTCCertificate; + // std::unique_ptr m_subspaceForRTCDTMFSender; + // std::unique_ptr m_subspaceForRTCDTMFToneChangeEvent; + // std::unique_ptr m_subspaceForRTCDataChannel; + // std::unique_ptr m_subspaceForRTCDataChannelEvent; + // std::unique_ptr m_subspaceForRTCDtlsTransport; + // std::unique_ptr m_subspaceForRTCEncodedAudioFrame; + // std::unique_ptr m_subspaceForRTCEncodedVideoFrame; + // std::unique_ptr m_subspaceForRTCError; + // std::unique_ptr m_subspaceForRTCErrorEvent; + // std::unique_ptr m_subspaceForRTCIceCandidate; + // std::unique_ptr m_subspaceForRTCIceTransport; + // std::unique_ptr m_subspaceForRTCPeerConnection; + // std::unique_ptr m_subspaceForRTCPeerConnectionIceErrorEvent; + // std::unique_ptr m_subspaceForRTCPeerConnectionIceEvent; + // std::unique_ptr m_subspaceForRTCRtpReceiver; + // std::unique_ptr m_subspaceForRTCRtpSFrameTransform; + // std::unique_ptr m_subspaceForRTCRtpSFrameTransformErrorEvent; + // std::unique_ptr m_subspaceForRTCRtpScriptTransform; + // std::unique_ptr m_subspaceForRTCRtpScriptTransformer; + // std::unique_ptr m_subspaceForRTCRtpSender; + // std::unique_ptr m_subspaceForRTCRtpTransceiver; + // std::unique_ptr m_subspaceForRTCSctpTransport; + // std::unique_ptr m_subspaceForRTCSessionDescription; + // std::unique_ptr m_subspaceForRTCStatsReport; + // std::unique_ptr m_subspaceForRTCTrackEvent; + // std::unique_ptr m_subspaceForRTCTransformEvent; + // std::unique_ptr m_subspaceForHTMLModelElement; + // std::unique_ptr m_subspaceForNotification; + // std::unique_ptr m_subspaceForNotificationEvent; + // std::unique_ptr m_subspaceForMerchantValidationEvent; + // std::unique_ptr m_subspaceForPaymentAddress; + // std::unique_ptr m_subspaceForPaymentMethodChangeEvent; + // std::unique_ptr m_subspaceForPaymentRequest; + // std::unique_ptr m_subspaceForPaymentRequestUpdateEvent; + // std::unique_ptr m_subspaceForPaymentResponse; + // std::unique_ptr m_subspaceForPermissionStatus; + // std::unique_ptr m_subspaceForPermissions; + // std::unique_ptr m_subspaceForPictureInPictureEvent; + // std::unique_ptr m_subspaceForPictureInPictureWindow; + // std::unique_ptr m_subspaceForPushEvent; + // std::unique_ptr m_subspaceForPushManager; + // std::unique_ptr m_subspaceForPushMessageData; + // std::unique_ptr m_subspaceForPushSubscription; + // std::unique_ptr m_subspaceForPushSubscriptionChangeEvent; + // std::unique_ptr m_subspaceForPushSubscriptionOptions; + // std::unique_ptr m_subspaceForRemotePlayback; + // std::unique_ptr m_subspaceForSpeechRecognition; + // std::unique_ptr m_subspaceForSpeechRecognitionAlternative; + // std::unique_ptr m_subspaceForSpeechRecognitionErrorEvent; + // std::unique_ptr m_subspaceForSpeechRecognitionEvent; + // std::unique_ptr m_subspaceForSpeechRecognitionResult; + // std::unique_ptr m_subspaceForSpeechRecognitionResultList; + // std::unique_ptr m_subspaceForSpeechSynthesis; + // std::unique_ptr m_subspaceForSpeechSynthesisErrorEvent; + // std::unique_ptr m_subspaceForSpeechSynthesisEvent; + // std::unique_ptr m_subspaceForSpeechSynthesisUtterance; + // std::unique_ptr m_subspaceForSpeechSynthesisVoice; + // std::unique_ptr m_subspaceForStorageManager; + // std::unique_ptr m_subspaceForByteLengthQueuingStrategy; + // std::unique_ptr m_subspaceForCountQueuingStrategy; + // std::unique_ptr m_subspaceForReadableByteStreamController; + // std::unique_ptr m_subspaceForReadableStream; + // std::unique_ptr m_subspaceForReadableStreamBYOBReader; + // std::unique_ptr m_subspaceForReadableStreamBYOBRequest; + // std::unique_ptr m_subspaceForReadableStreamDefaultController; + // std::unique_ptr m_subspaceForReadableStreamDefaultReader; + // std::unique_ptr m_subspaceForReadableStreamSink; + // std::unique_ptr m_subspaceForReadableStreamSource; + // std::unique_ptr m_subspaceForTransformStream; + // std::unique_ptr m_subspaceForTransformStreamDefaultController; + // std::unique_ptr m_subspaceForWritableStream; + // std::unique_ptr m_subspaceForWritableStreamDefaultController; + // std::unique_ptr m_subspaceForWritableStreamDefaultWriter; + // std::unique_ptr m_subspaceForWritableStreamSink; + // std::unique_ptr m_subspaceForWebLock; + // std::unique_ptr m_subspaceForWebLockManager; + // std::unique_ptr m_subspaceForAnalyserNode; + // std::unique_ptr m_subspaceForAudioBuffer; + // std::unique_ptr m_subspaceForAudioBufferSourceNode; + // std::unique_ptr m_subspaceForAudioContext; + // std::unique_ptr m_subspaceForAudioDestinationNode; + // std::unique_ptr m_subspaceForAudioListener; + // std::unique_ptr m_subspaceForAudioNode; + // std::unique_ptr m_subspaceForAudioParam; + // std::unique_ptr m_subspaceForAudioParamMap; + // std::unique_ptr m_subspaceForAudioProcessingEvent; + // std::unique_ptr m_subspaceForAudioScheduledSourceNode; + // std::unique_ptr m_subspaceForAudioWorklet; + // std::unique_ptr m_subspaceForAudioWorkletGlobalScope; + // std::unique_ptr m_subspaceForAudioWorkletNode; + // std::unique_ptr m_subspaceForAudioWorkletProcessor; + // std::unique_ptr m_subspaceForBaseAudioContext; + // std::unique_ptr m_subspaceForBiquadFilterNode; + // std::unique_ptr m_subspaceForChannelMergerNode; + // std::unique_ptr m_subspaceForChannelSplitterNode; + // std::unique_ptr m_subspaceForConstantSourceNode; + // std::unique_ptr m_subspaceForConvolverNode; + // std::unique_ptr m_subspaceForDelayNode; + // std::unique_ptr m_subspaceForDynamicsCompressorNode; + // std::unique_ptr m_subspaceForGainNode; + // std::unique_ptr m_subspaceForIIRFilterNode; + // std::unique_ptr m_subspaceForMediaElementAudioSourceNode; + // std::unique_ptr m_subspaceForMediaStreamAudioDestinationNode; + // std::unique_ptr m_subspaceForMediaStreamAudioSourceNode; + // std::unique_ptr m_subspaceForOfflineAudioCompletionEvent; + // std::unique_ptr m_subspaceForOfflineAudioContext; + // std::unique_ptr m_subspaceForOscillatorNode; + // std::unique_ptr m_subspaceForPannerNode; + // std::unique_ptr m_subspaceForPeriodicWave; + // std::unique_ptr m_subspaceForScriptProcessorNode; + // std::unique_ptr m_subspaceForStereoPannerNode; + // std::unique_ptr m_subspaceForWaveShaperNode; + // std::unique_ptr m_subspaceForAuthenticatorAssertionResponse; + // std::unique_ptr m_subspaceForAuthenticatorAttestationResponse; + // std::unique_ptr m_subspaceForAuthenticatorResponse; + // std::unique_ptr m_subspaceForPublicKeyCredential; + // std::unique_ptr m_subspaceForVideoColorSpace; + // std::unique_ptr m_subspaceForDatabase; + // std::unique_ptr m_subspaceForSQLError; + // std::unique_ptr m_subspaceForSQLResultSet; + // std::unique_ptr m_subspaceForSQLResultSetRowList; + // std::unique_ptr m_subspaceForSQLTransaction; + // std::unique_ptr m_subspaceForCloseEvent; + // std::unique_ptr m_subspaceForWebSocket; + // std::unique_ptr m_subspaceForWebXRBoundedReferenceSpace; + // std::unique_ptr m_subspaceForWebXRFrame; + // std::unique_ptr m_subspaceForWebXRHand; + // std::unique_ptr m_subspaceForWebXRHandIterator; + // std::unique_ptr m_subspaceForWebXRInputSource; + // std::unique_ptr m_subspaceForWebXRInputSourceArray; + // std::unique_ptr m_subspaceForWebXRInputSourceArrayIterator; + // std::unique_ptr m_subspaceForWebXRJointPose; + // std::unique_ptr m_subspaceForWebXRJointSpace; + // std::unique_ptr m_subspaceForWebXRLayer; + // std::unique_ptr m_subspaceForWebXRPose; + // std::unique_ptr m_subspaceForWebXRReferenceSpace; + // std::unique_ptr m_subspaceForWebXRRenderState; + // std::unique_ptr m_subspaceForWebXRRigidTransform; + // std::unique_ptr m_subspaceForWebXRSession; + // std::unique_ptr m_subspaceForWebXRSpace; + // std::unique_ptr m_subspaceForWebXRSystem; + // std::unique_ptr m_subspaceForWebXRView; + // std::unique_ptr m_subspaceForWebXRViewerPose; + // std::unique_ptr m_subspaceForWebXRViewport; + // std::unique_ptr m_subspaceForWebXRWebGLLayer; + // std::unique_ptr m_subspaceForXRInputSourceEvent; + // std::unique_ptr m_subspaceForXRInputSourcesChangeEvent; + // std::unique_ptr m_subspaceForXRReferenceSpaceEvent; + // std::unique_ptr m_subspaceForXRSessionEvent; + // std::unique_ptr m_subspaceForAnimationEffect; + // std::unique_ptr m_subspaceForAnimationPlaybackEvent; + // std::unique_ptr m_subspaceForAnimationTimeline; + // std::unique_ptr m_subspaceForCSSAnimation; + // std::unique_ptr m_subspaceForCSSTransition; + // std::unique_ptr m_subspaceForCustomEffect; + // std::unique_ptr m_subspaceForDocumentTimeline; + // std::unique_ptr m_subspaceForKeyframeEffect; + // std::unique_ptr m_subspaceForWebAnimation; + // std::unique_ptr m_subspaceForCryptoKey; + // std::unique_ptr m_subspaceForSubtleCrypto; + // std::unique_ptr m_subspaceForCSSConditionRule; + // std::unique_ptr m_subspaceForCSSCounterStyleRule; + // std::unique_ptr m_subspaceForCSSFontFaceRule; + // std::unique_ptr m_subspaceForCSSFontPaletteValuesRule; + // std::unique_ptr m_subspaceForCSSGroupingRule; + // std::unique_ptr m_subspaceForCSSImportRule; + // std::unique_ptr m_subspaceForCSSKeyframeRule; + // std::unique_ptr m_subspaceForCSSKeyframesRule; + // std::unique_ptr m_subspaceForCSSLayerBlockRule; + // std::unique_ptr m_subspaceForCSSLayerStatementRule; + // std::unique_ptr m_subspaceForCSSMediaRule; + // std::unique_ptr m_subspaceForCSSNamespaceRule; + // std::unique_ptr m_subspaceForCSSPageRule; + // std::unique_ptr m_subspaceForCSSPaintSize; + // std::unique_ptr m_subspaceForCSSRule; + // std::unique_ptr m_subspaceForCSSRuleList; + // std::unique_ptr m_subspaceForCSSStyleDeclaration; + // std::unique_ptr m_subspaceForCSSStyleRule; + // std::unique_ptr m_subspaceForCSSStyleSheet; + // std::unique_ptr m_subspaceForCSSSupportsRule; + // std::unique_ptr m_subspaceForCSSUnknownRule; + // std::unique_ptr m_subspaceForDOMCSSNamespace; + // std::unique_ptr m_subspaceForDOMMatrix; + // std::unique_ptr m_subspaceForDOMMatrixReadOnly; + // std::unique_ptr m_subspaceForDeprecatedCSSOMCounter; + // std::unique_ptr m_subspaceForDeprecatedCSSOMPrimitiveValue; + // std::unique_ptr m_subspaceForDeprecatedCSSOMRGBColor; + // std::unique_ptr m_subspaceForDeprecatedCSSOMRect; + // std::unique_ptr m_subspaceForDeprecatedCSSOMValue; + // std::unique_ptr m_subspaceForDeprecatedCSSOMValueList; + // std::unique_ptr m_subspaceForFontFace; + // std::unique_ptr m_subspaceForFontFaceSet; + // std::unique_ptr m_subspaceForFontFaceSetIterator; + // std::unique_ptr m_subspaceForMediaList; + // std::unique_ptr m_subspaceForMediaQueryList; + // std::unique_ptr m_subspaceForMediaQueryListEvent; + // std::unique_ptr m_subspaceForStyleMedia; + // std::unique_ptr m_subspaceForStyleSheet; + // std::unique_ptr m_subspaceForStyleSheetList; + // std::unique_ptr m_subspaceForCSSKeywordValue; + // std::unique_ptr m_subspaceForCSSNumericValue; + // std::unique_ptr m_subspaceForCSSOMVariableReferenceValue; + // std::unique_ptr m_subspaceForCSSStyleImageValue; + // std::unique_ptr m_subspaceForCSSStyleValue; + // std::unique_ptr m_subspaceForCSSUnitValue; + // std::unique_ptr m_subspaceForCSSUnparsedValue; + // std::unique_ptr m_subspaceForCSSUnparsedValueIterator; + // std::unique_ptr m_subspaceForStylePropertyMap; + // std::unique_ptr m_subspaceForStylePropertyMapReadOnly; + // std::unique_ptr m_subspaceForCSSMathInvert; + // std::unique_ptr m_subspaceForCSSMathMax; + // std::unique_ptr m_subspaceForCSSMathMin; + // std::unique_ptr m_subspaceForCSSMathNegate; + // std::unique_ptr m_subspaceForCSSMathProduct; + // std::unique_ptr m_subspaceForCSSMathSum; + // std::unique_ptr m_subspaceForCSSMathValue; + // std::unique_ptr m_subspaceForCSSNumericArray; + // std::unique_ptr m_subspaceForCSSNumericArrayIterator; + // std::unique_ptr m_subspaceForCSSMatrixComponent; + // std::unique_ptr m_subspaceForCSSPerspective; + // std::unique_ptr m_subspaceForCSSRotate; + // std::unique_ptr m_subspaceForCSSScale; + // std::unique_ptr m_subspaceForCSSSkew; + // std::unique_ptr m_subspaceForCSSSkewX; + // std::unique_ptr m_subspaceForCSSSkewY; + // std::unique_ptr m_subspaceForCSSTransformComponent; + // std::unique_ptr m_subspaceForCSSTransformValue; + // std::unique_ptr m_subspaceForCSSTransformValueIterator; + // std::unique_ptr m_subspaceForCSSTranslate; + // std::unique_ptr m_subspaceForAbortController; + // std::unique_ptr m_subspaceForAbortSignal; + // std::unique_ptr m_subspaceForAbstractRange; + // std::unique_ptr m_subspaceForAnimationEvent; + // std::unique_ptr m_subspaceForAttr; + // std::unique_ptr m_subspaceForBeforeUnloadEvent; + // std::unique_ptr m_subspaceForBroadcastChannel; + // std::unique_ptr m_subspaceForCDATASection; + // std::unique_ptr m_subspaceForCharacterData; + // std::unique_ptr m_subspaceForClipboardEvent; + // std::unique_ptr m_subspaceForComment; + // std::unique_ptr m_subspaceForCompositionEvent; + // std::unique_ptr m_subspaceForCustomElementRegistry; + // std::unique_ptr m_subspaceForCustomEvent; + // std::unique_ptr m_subspaceForDOMException; + // std::unique_ptr m_subspaceForDOMImplementation; + // std::unique_ptr m_subspaceForDOMPoint; + // std::unique_ptr m_subspaceForDOMPointReadOnly; + // std::unique_ptr m_subspaceForDOMQuad; + // std::unique_ptr m_subspaceForDOMRect; + // std::unique_ptr m_subspaceForDOMRectList; + // std::unique_ptr m_subspaceForDOMRectReadOnly; + // std::unique_ptr m_subspaceForDOMStringList; + // std::unique_ptr m_subspaceForDOMStringMap; + // std::unique_ptr m_subspaceForDataTransfer; + // std::unique_ptr m_subspaceForDataTransferItem; + // std::unique_ptr m_subspaceForDataTransferItemList; + // std::unique_ptr m_subspaceForDeviceMotionEvent; + // std::unique_ptr m_subspaceForDeviceOrientationEvent; + // std::unique_ptr m_subspaceForDocument; + // std::unique_ptr m_subspaceForDocumentFragment; + // std::unique_ptr m_subspaceForDocumentType; + // std::unique_ptr m_subspaceForDragEvent; + // std::unique_ptr m_subspaceForElement; + // std::unique_ptr m_subspaceForErrorEvent; + // std::unique_ptr m_subspaceForEvent; + // std::unique_ptr m_subspaceForEventListener; + // std::unique_ptr m_subspaceForEventTarget; + // std::unique_ptr m_subspaceForFocusEvent; + // std::unique_ptr m_subspaceForFormDataEvent; + // std::unique_ptr m_subspaceForHashChangeEvent; + // std::unique_ptr m_subspaceForIdleDeadline; + // std::unique_ptr m_subspaceForInputEvent; + // std::unique_ptr m_subspaceForKeyboardEvent; + // std::unique_ptr m_subspaceForMessageChannel; + // std::unique_ptr m_subspaceForMessageEvent; + // std::unique_ptr m_subspaceForMessagePort; + // std::unique_ptr m_subspaceForMouseEvent; + // std::unique_ptr m_subspaceForMutationEvent; + // std::unique_ptr m_subspaceForMutationObserver; + // std::unique_ptr m_subspaceForMutationRecord; + // std::unique_ptr m_subspaceForNamedNodeMap; + // std::unique_ptr m_subspaceForNode; + // std::unique_ptr m_subspaceForNodeIterator; + // std::unique_ptr m_subspaceForNodeList; + // std::unique_ptr m_subspaceForNodeListIterator; + // std::unique_ptr m_subspaceForOverflowEvent; + // std::unique_ptr m_subspaceForPageTransitionEvent; + // std::unique_ptr m_subspaceForPointerEvent; + // std::unique_ptr m_subspaceForPopStateEvent; + // std::unique_ptr m_subspaceForProcessingInstruction; + // std::unique_ptr m_subspaceForProgressEvent; + // std::unique_ptr m_subspaceForPromiseRejectionEvent; + // std::unique_ptr m_subspaceForRange; + // std::unique_ptr m_subspaceForSecurityPolicyViolationEvent; + // std::unique_ptr m_subspaceForShadowRoot; + // std::unique_ptr m_subspaceForStaticRange; + // std::unique_ptr m_subspaceForText; + // std::unique_ptr m_subspaceForTextDecoder; + // std::unique_ptr m_subspaceForTextDecoderStream; + // std::unique_ptr m_subspaceForTextDecoderStreamDecoder; + // std::unique_ptr m_subspaceForTextEncoder; + // std::unique_ptr m_subspaceForTextEncoderStream; + // std::unique_ptr m_subspaceForTextEncoderStreamEncoder; + // std::unique_ptr m_subspaceForTextEvent; + // std::unique_ptr m_subspaceForTransitionEvent; + // std::unique_ptr m_subspaceForTreeWalker; + // std::unique_ptr m_subspaceForUIEvent; + // std::unique_ptr m_subspaceForWheelEvent; + // std::unique_ptr m_subspaceForXMLDocument; + // std::unique_ptr m_subspaceForBlob; + // std::unique_ptr m_subspaceForFile; + // std::unique_ptr m_subspaceForFileList; + // std::unique_ptr m_subspaceForFileReader; + // std::unique_ptr m_subspaceForFileReaderSync; + // std::unique_ptr m_subspaceForDOMFormData; + // std::unique_ptr m_subspaceForDOMFormDataIterator; + // std::unique_ptr m_subspaceForDOMTokenList; + // std::unique_ptr m_subspaceForDOMTokenListIterator; + // std::unique_ptr m_subspaceForDOMURL; + // std::unique_ptr m_subspaceForHTMLAllCollection; + // std::unique_ptr m_subspaceForHTMLAnchorElement; + // std::unique_ptr m_subspaceForHTMLAreaElement; + // std::unique_ptr m_subspaceForHTMLAttachmentElement; + // std::unique_ptr m_subspaceForHTMLAudioElement; + // std::unique_ptr m_subspaceForHTMLBRElement; + // std::unique_ptr m_subspaceForHTMLBaseElement; + // std::unique_ptr m_subspaceForHTMLBodyElement; + // std::unique_ptr m_subspaceForHTMLButtonElement; + // std::unique_ptr m_subspaceForHTMLCanvasElement; + // std::unique_ptr m_subspaceForHTMLCollection; + // std::unique_ptr m_subspaceForHTMLDListElement; + // std::unique_ptr m_subspaceForHTMLDataElement; + // std::unique_ptr m_subspaceForHTMLDataListElement; + // std::unique_ptr m_subspaceForHTMLDetailsElement; + // std::unique_ptr m_subspaceForHTMLDialogElement; + // std::unique_ptr m_subspaceForHTMLDirectoryElement; + // std::unique_ptr m_subspaceForHTMLDivElement; + // std::unique_ptr m_subspaceForHTMLDocument; + // std::unique_ptr m_subspaceForHTMLElement; + // std::unique_ptr m_subspaceForHTMLEmbedElement; + // std::unique_ptr m_subspaceForHTMLFieldSetElement; + // std::unique_ptr m_subspaceForHTMLFontElement; + // std::unique_ptr m_subspaceForHTMLFormControlsCollection; + // std::unique_ptr m_subspaceForHTMLFormElement; + // std::unique_ptr m_subspaceForHTMLFrameElement; + // std::unique_ptr m_subspaceForHTMLFrameSetElement; + // std::unique_ptr m_subspaceForHTMLHRElement; + // std::unique_ptr m_subspaceForHTMLHeadElement; + // std::unique_ptr m_subspaceForHTMLHeadingElement; + // std::unique_ptr m_subspaceForHTMLHtmlElement; + // std::unique_ptr m_subspaceForHTMLIFrameElement; + // std::unique_ptr m_subspaceForHTMLImageElement; + // std::unique_ptr m_subspaceForHTMLInputElement; + // std::unique_ptr m_subspaceForHTMLLIElement; + // std::unique_ptr m_subspaceForHTMLLabelElement; + // std::unique_ptr m_subspaceForHTMLLegendElement; + // std::unique_ptr m_subspaceForHTMLLinkElement; + // std::unique_ptr m_subspaceForHTMLMapElement; + // std::unique_ptr m_subspaceForHTMLMarqueeElement; + // std::unique_ptr m_subspaceForHTMLMediaElement; + // std::unique_ptr m_subspaceForHTMLMenuElement; + // std::unique_ptr m_subspaceForHTMLMenuItemElement; + // std::unique_ptr m_subspaceForHTMLMetaElement; + // std::unique_ptr m_subspaceForHTMLMeterElement; + // std::unique_ptr m_subspaceForHTMLModElement; + // std::unique_ptr m_subspaceForHTMLOListElement; + // std::unique_ptr m_subspaceForHTMLObjectElement; + // std::unique_ptr m_subspaceForHTMLOptGroupElement; + // std::unique_ptr m_subspaceForHTMLOptionElement; + // std::unique_ptr m_subspaceForHTMLOptionsCollection; + // std::unique_ptr m_subspaceForHTMLOutputElement; + // std::unique_ptr m_subspaceForHTMLParagraphElement; + // std::unique_ptr m_subspaceForHTMLParamElement; + // std::unique_ptr m_subspaceForHTMLPictureElement; + // std::unique_ptr m_subspaceForHTMLPreElement; + // std::unique_ptr m_subspaceForHTMLProgressElement; + // std::unique_ptr m_subspaceForHTMLQuoteElement; + // std::unique_ptr m_subspaceForHTMLScriptElement; + // std::unique_ptr m_subspaceForHTMLSelectElement; + // std::unique_ptr m_subspaceForHTMLSlotElement; + // std::unique_ptr m_subspaceForHTMLSourceElement; + // std::unique_ptr m_subspaceForHTMLSpanElement; + // std::unique_ptr m_subspaceForHTMLStyleElement; + // std::unique_ptr m_subspaceForHTMLTableCaptionElement; + // std::unique_ptr m_subspaceForHTMLTableCellElement; + // std::unique_ptr m_subspaceForHTMLTableColElement; + // std::unique_ptr m_subspaceForHTMLTableElement; + // std::unique_ptr m_subspaceForHTMLTableRowElement; + // std::unique_ptr m_subspaceForHTMLTableSectionElement; + // std::unique_ptr m_subspaceForHTMLTemplateElement; + // std::unique_ptr m_subspaceForHTMLTextAreaElement; + // std::unique_ptr m_subspaceForHTMLTimeElement; + // std::unique_ptr m_subspaceForHTMLTitleElement; + // std::unique_ptr m_subspaceForHTMLTrackElement; + // std::unique_ptr m_subspaceForHTMLUListElement; + // std::unique_ptr m_subspaceForHTMLUnknownElement; + // std::unique_ptr m_subspaceForHTMLVideoElement; + // std::unique_ptr m_subspaceForImageBitmap; + // std::unique_ptr m_subspaceForImageData; + // std::unique_ptr m_subspaceForMediaController; + // std::unique_ptr m_subspaceForMediaEncryptedEvent; + // std::unique_ptr m_subspaceForMediaError; + // std::unique_ptr m_subspaceForOffscreenCanvas; + // std::unique_ptr m_subspaceForRadioNodeList; + // std::unique_ptr m_subspaceForSubmitEvent; + // std::unique_ptr m_subspaceForTextMetrics; + // std::unique_ptr m_subspaceForTimeRanges; + // std::unique_ptr m_subspaceForURLSearchParams; + // std::unique_ptr m_subspaceForURLSearchParamsIterator; + // std::unique_ptr m_subspaceForValidityState; + // std::unique_ptr m_subspaceForWebKitMediaKeyError; + // std::unique_ptr m_subspaceForANGLEInstancedArrays; + // std::unique_ptr m_subspaceForCanvasGradient; + // std::unique_ptr m_subspaceForCanvasPattern; + // std::unique_ptr m_subspaceForCanvasRenderingContext2D; + // std::unique_ptr m_subspaceForEXTBlendMinMax; + // std::unique_ptr m_subspaceForEXTColorBufferFloat; + // std::unique_ptr m_subspaceForEXTColorBufferHalfFloat; + // std::unique_ptr m_subspaceForEXTFloatBlend; + // std::unique_ptr m_subspaceForEXTFragDepth; + // std::unique_ptr m_subspaceForEXTShaderTextureLOD; + // std::unique_ptr m_subspaceForEXTTextureCompressionRGTC; + // std::unique_ptr m_subspaceForEXTTextureFilterAnisotropic; + // std::unique_ptr m_subspaceForEXTsRGB; + // std::unique_ptr m_subspaceForImageBitmapRenderingContext; + // std::unique_ptr m_subspaceForKHRParallelShaderCompile; + // std::unique_ptr m_subspaceForOESElementIndexUint; + // std::unique_ptr m_subspaceForOESFBORenderMipmap; + // std::unique_ptr m_subspaceForOESStandardDerivatives; + // std::unique_ptr m_subspaceForOESTextureFloat; + // std::unique_ptr m_subspaceForOESTextureFloatLinear; + // std::unique_ptr m_subspaceForOESTextureHalfFloat; + // std::unique_ptr m_subspaceForOESTextureHalfFloatLinear; + // std::unique_ptr m_subspaceForOESVertexArrayObject; + // std::unique_ptr m_subspaceForOffscreenCanvasRenderingContext2D; + // std::unique_ptr m_subspaceForPaintRenderingContext2D; + // std::unique_ptr m_subspaceForPath2D; + // std::unique_ptr m_subspaceForWebGL2RenderingContext; + // std::unique_ptr m_subspaceForWebGLActiveInfo; + // std::unique_ptr m_subspaceForWebGLBuffer; + // std::unique_ptr m_subspaceForWebGLColorBufferFloat; + // std::unique_ptr m_subspaceForWebGLCompressedTextureASTC; + // std::unique_ptr m_subspaceForWebGLCompressedTextureATC; + // std::unique_ptr m_subspaceForWebGLCompressedTextureETC; + // std::unique_ptr m_subspaceForWebGLCompressedTextureETC1; + // std::unique_ptr m_subspaceForWebGLCompressedTexturePVRTC; + // std::unique_ptr m_subspaceForWebGLCompressedTextureS3TC; + // std::unique_ptr m_subspaceForWebGLCompressedTextureS3TCsRGB; + // std::unique_ptr m_subspaceForWebGLContextEvent; + // std::unique_ptr m_subspaceForWebGLDebugRendererInfo; + // std::unique_ptr m_subspaceForWebGLDebugShaders; + // std::unique_ptr m_subspaceForWebGLDepthTexture; + // std::unique_ptr m_subspaceForWebGLDrawBuffers; + // std::unique_ptr m_subspaceForWebGLFramebuffer; + // std::unique_ptr m_subspaceForWebGLLoseContext; + // std::unique_ptr m_subspaceForWebGLMultiDraw; + // std::unique_ptr m_subspaceForWebGLProgram; + // std::unique_ptr m_subspaceForWebGLQuery; + // std::unique_ptr m_subspaceForWebGLRenderbuffer; + // std::unique_ptr m_subspaceForWebGLRenderingContext; + // std::unique_ptr m_subspaceForWebGLSampler; + // std::unique_ptr m_subspaceForWebGLShader; + // std::unique_ptr m_subspaceForWebGLShaderPrecisionFormat; + // std::unique_ptr m_subspaceForWebGLSync; + // std::unique_ptr m_subspaceForWebGLTexture; + // std::unique_ptr m_subspaceForWebGLTransformFeedback; + // std::unique_ptr m_subspaceForWebGLUniformLocation; + // std::unique_ptr m_subspaceForWebGLVertexArrayObject; + // std::unique_ptr m_subspaceForWebGLVertexArrayObjectOES; + // std::unique_ptr m_subspaceForAudioTrack; + // std::unique_ptr m_subspaceForAudioTrackConfiguration; + // std::unique_ptr m_subspaceForAudioTrackList; + // std::unique_ptr m_subspaceForDataCue; + // std::unique_ptr m_subspaceForTextTrack; + // std::unique_ptr m_subspaceForTextTrackCue; + // std::unique_ptr m_subspaceForTextTrackCueGeneric; + // std::unique_ptr m_subspaceForTextTrackCueList; + // std::unique_ptr m_subspaceForTextTrackList; + // std::unique_ptr m_subspaceForTrackEvent; + // std::unique_ptr m_subspaceForVTTCue; + // std::unique_ptr m_subspaceForVTTRegion; + // std::unique_ptr m_subspaceForVTTRegionList; + // std::unique_ptr m_subspaceForVideoTrack; + // std::unique_ptr m_subspaceForVideoTrackConfiguration; + // std::unique_ptr m_subspaceForVideoTrackList; + // std::unique_ptr m_subspaceForCommandLineAPIHost; + // std::unique_ptr m_subspaceForInspectorAuditAccessibilityObject; + // std::unique_ptr m_subspaceForInspectorAuditDOMObject; + // std::unique_ptr m_subspaceForInspectorAuditResourcesObject; + // std::unique_ptr m_subspaceForInspectorFrontendHost; + // std::unique_ptr m_subspaceForDOMApplicationCache; + // std::unique_ptr m_subspaceForMathMLElement; + // std::unique_ptr m_subspaceForMathMLMathElement; + // std::unique_ptr m_subspaceForBarProp; + // std::unique_ptr m_subspaceForCrypto; + // std::unique_ptr m_subspaceForDOMSelection; + // std::unique_ptr m_subspaceForDOMWindow; + // std::unique_ptr m_subspaceForEventSource; + // std::unique_ptr m_subspaceForHistory; + // std::unique_ptr m_subspaceForIntersectionObserver; + // std::unique_ptr m_subspaceForIntersectionObserverEntry; + // std::unique_ptr m_subspaceForLocation; + // std::unique_ptr m_subspaceForNavigator; + // std::unique_ptr m_subspaceForPerformance; + // std::unique_ptr m_subspaceForPerformanceEntry; + // std::unique_ptr m_subspaceForPerformanceMark; + // std::unique_ptr m_subspaceForPerformanceMeasure; + // std::unique_ptr m_subspaceForPerformanceNavigation; + // std::unique_ptr m_subspaceForPerformanceNavigationTiming; + // std::unique_ptr m_subspaceForPerformanceObserver; + // std::unique_ptr m_subspaceForPerformanceObserverEntryList; + // std::unique_ptr m_subspaceForPerformancePaintTiming; + // std::unique_ptr m_subspaceForPerformanceResourceTiming; + // std::unique_ptr m_subspaceForPerformanceServerTiming; + // std::unique_ptr m_subspaceForPerformanceTiming; + // std::unique_ptr m_subspaceForRemoteDOMWindow; + // std::unique_ptr m_subspaceForResizeObserver; + // std::unique_ptr m_subspaceForResizeObserverEntry; + // std::unique_ptr m_subspaceForResizeObserverSize; + // std::unique_ptr m_subspaceForScreen; + // std::unique_ptr m_subspaceForShadowRealmGlobalScope; + // std::unique_ptr m_subspaceForUndoItem; + // std::unique_ptr m_subspaceForUndoManager; + // std::unique_ptr m_subspaceForUserMessageHandler; + // std::unique_ptr m_subspaceForUserMessageHandlersNamespace; + // std::unique_ptr m_subspaceForVisualViewport; + // std::unique_ptr m_subspaceForWebKitNamespace; + // std::unique_ptr m_subspaceForWebKitPoint; + // std::unique_ptr m_subspaceForWorkerNavigator; + // std::unique_ptr m_subspaceForDOMMimeType; + // std::unique_ptr m_subspaceForDOMMimeTypeArray; + // std::unique_ptr m_subspaceForDOMPlugin; + // std::unique_ptr m_subspaceForDOMPluginArray; + // std::unique_ptr m_subspaceForStorage; + // std::unique_ptr m_subspaceForStorageEvent; + // std::unique_ptr m_subspaceForSVGAElement; + // std::unique_ptr m_subspaceForSVGAltGlyphDefElement; + // std::unique_ptr m_subspaceForSVGAltGlyphElement; + // std::unique_ptr m_subspaceForSVGAltGlyphItemElement; + // std::unique_ptr m_subspaceForSVGAngle; + // std::unique_ptr m_subspaceForSVGAnimateColorElement; + // std::unique_ptr m_subspaceForSVGAnimateElement; + // std::unique_ptr m_subspaceForSVGAnimateMotionElement; + // std::unique_ptr m_subspaceForSVGAnimateTransformElement; + // std::unique_ptr m_subspaceForSVGAnimatedAngle; + // std::unique_ptr m_subspaceForSVGAnimatedBoolean; + // std::unique_ptr m_subspaceForSVGAnimatedEnumeration; + // std::unique_ptr m_subspaceForSVGAnimatedInteger; + // std::unique_ptr m_subspaceForSVGAnimatedLength; + // std::unique_ptr m_subspaceForSVGAnimatedLengthList; + // std::unique_ptr m_subspaceForSVGAnimatedNumber; + // std::unique_ptr m_subspaceForSVGAnimatedNumberList; + // std::unique_ptr m_subspaceForSVGAnimatedPreserveAspectRatio; + // std::unique_ptr m_subspaceForSVGAnimatedRect; + // std::unique_ptr m_subspaceForSVGAnimatedString; + // std::unique_ptr m_subspaceForSVGAnimatedTransformList; + // std::unique_ptr m_subspaceForSVGAnimationElement; + // std::unique_ptr m_subspaceForSVGCircleElement; + // std::unique_ptr m_subspaceForSVGClipPathElement; + // std::unique_ptr m_subspaceForSVGComponentTransferFunctionElement; + // std::unique_ptr m_subspaceForSVGCursorElement; + // std::unique_ptr m_subspaceForSVGDefsElement; + // std::unique_ptr m_subspaceForSVGDescElement; + // std::unique_ptr m_subspaceForSVGElement; + // std::unique_ptr m_subspaceForSVGEllipseElement; + // std::unique_ptr m_subspaceForSVGFEBlendElement; + // std::unique_ptr m_subspaceForSVGFEColorMatrixElement; + // std::unique_ptr m_subspaceForSVGFEComponentTransferElement; + // std::unique_ptr m_subspaceForSVGFECompositeElement; + // std::unique_ptr m_subspaceForSVGFEConvolveMatrixElement; + // std::unique_ptr m_subspaceForSVGFEDiffuseLightingElement; + // std::unique_ptr m_subspaceForSVGFEDisplacementMapElement; + // std::unique_ptr m_subspaceForSVGFEDistantLightElement; + // std::unique_ptr m_subspaceForSVGFEDropShadowElement; + // std::unique_ptr m_subspaceForSVGFEFloodElement; + // std::unique_ptr m_subspaceForSVGFEFuncAElement; + // std::unique_ptr m_subspaceForSVGFEFuncBElement; + // std::unique_ptr m_subspaceForSVGFEFuncGElement; + // std::unique_ptr m_subspaceForSVGFEFuncRElement; + // std::unique_ptr m_subspaceForSVGFEGaussianBlurElement; + // std::unique_ptr m_subspaceForSVGFEImageElement; + // std::unique_ptr m_subspaceForSVGFEMergeElement; + // std::unique_ptr m_subspaceForSVGFEMergeNodeElement; + // std::unique_ptr m_subspaceForSVGFEMorphologyElement; + // std::unique_ptr m_subspaceForSVGFEOffsetElement; + // std::unique_ptr m_subspaceForSVGFEPointLightElement; + // std::unique_ptr m_subspaceForSVGFESpecularLightingElement; + // std::unique_ptr m_subspaceForSVGFESpotLightElement; + // std::unique_ptr m_subspaceForSVGFETileElement; + // std::unique_ptr m_subspaceForSVGFETurbulenceElement; + // std::unique_ptr m_subspaceForSVGFilterElement; + // std::unique_ptr m_subspaceForSVGFontElement; + // std::unique_ptr m_subspaceForSVGFontFaceElement; + // std::unique_ptr m_subspaceForSVGFontFaceFormatElement; + // std::unique_ptr m_subspaceForSVGFontFaceNameElement; + // std::unique_ptr m_subspaceForSVGFontFaceSrcElement; + // std::unique_ptr m_subspaceForSVGFontFaceUriElement; + // std::unique_ptr m_subspaceForSVGForeignObjectElement; + // std::unique_ptr m_subspaceForSVGGElement; + // std::unique_ptr m_subspaceForSVGGeometryElement; + // std::unique_ptr m_subspaceForSVGGlyphElement; + // std::unique_ptr m_subspaceForSVGGlyphRefElement; + // std::unique_ptr m_subspaceForSVGGradientElement; + // std::unique_ptr m_subspaceForSVGGraphicsElement; + // std::unique_ptr m_subspaceForSVGHKernElement; + // std::unique_ptr m_subspaceForSVGImageElement; + // std::unique_ptr m_subspaceForSVGLength; + // std::unique_ptr m_subspaceForSVGLengthList; + // std::unique_ptr m_subspaceForSVGLineElement; + // std::unique_ptr m_subspaceForSVGLinearGradientElement; + // std::unique_ptr m_subspaceForSVGMPathElement; + // std::unique_ptr m_subspaceForSVGMarkerElement; + // std::unique_ptr m_subspaceForSVGMaskElement; + // std::unique_ptr m_subspaceForSVGMatrix; + // std::unique_ptr m_subspaceForSVGMetadataElement; + // std::unique_ptr m_subspaceForSVGMissingGlyphElement; + // std::unique_ptr m_subspaceForSVGNumber; + // std::unique_ptr m_subspaceForSVGNumberList; + // std::unique_ptr m_subspaceForSVGPathElement; + // std::unique_ptr m_subspaceForSVGPathSeg; + // std::unique_ptr m_subspaceForSVGPathSegArcAbs; + // std::unique_ptr m_subspaceForSVGPathSegArcRel; + // std::unique_ptr m_subspaceForSVGPathSegClosePath; + // std::unique_ptr m_subspaceForSVGPathSegCurvetoCubicAbs; + // std::unique_ptr m_subspaceForSVGPathSegCurvetoCubicRel; + // std::unique_ptr m_subspaceForSVGPathSegCurvetoCubicSmoothAbs; + // std::unique_ptr m_subspaceForSVGPathSegCurvetoCubicSmoothRel; + // std::unique_ptr m_subspaceForSVGPathSegCurvetoQuadraticAbs; + // std::unique_ptr m_subspaceForSVGPathSegCurvetoQuadraticRel; + // std::unique_ptr m_subspaceForSVGPathSegCurvetoQuadraticSmoothAbs; + // std::unique_ptr m_subspaceForSVGPathSegCurvetoQuadraticSmoothRel; + // std::unique_ptr m_subspaceForSVGPathSegLinetoAbs; + // std::unique_ptr m_subspaceForSVGPathSegLinetoHorizontalAbs; + // std::unique_ptr m_subspaceForSVGPathSegLinetoHorizontalRel; + // std::unique_ptr m_subspaceForSVGPathSegLinetoRel; + // std::unique_ptr m_subspaceForSVGPathSegLinetoVerticalAbs; + // std::unique_ptr m_subspaceForSVGPathSegLinetoVerticalRel; + // std::unique_ptr m_subspaceForSVGPathSegList; + // std::unique_ptr m_subspaceForSVGPathSegMovetoAbs; + // std::unique_ptr m_subspaceForSVGPathSegMovetoRel; + // std::unique_ptr m_subspaceForSVGPatternElement; + // std::unique_ptr m_subspaceForSVGPoint; + // std::unique_ptr m_subspaceForSVGPointList; + // std::unique_ptr m_subspaceForSVGPolygonElement; + // std::unique_ptr m_subspaceForSVGPolylineElement; + // std::unique_ptr m_subspaceForSVGPreserveAspectRatio; + // std::unique_ptr m_subspaceForSVGRadialGradientElement; + // std::unique_ptr m_subspaceForSVGRect; + // std::unique_ptr m_subspaceForSVGRectElement; + // std::unique_ptr m_subspaceForSVGRenderingIntent; + // std::unique_ptr m_subspaceForSVGSVGElement; + // std::unique_ptr m_subspaceForSVGScriptElement; + // std::unique_ptr m_subspaceForSVGSetElement; + // std::unique_ptr m_subspaceForSVGStopElement; + // std::unique_ptr m_subspaceForSVGStringList; + // std::unique_ptr m_subspaceForSVGStyleElement; + // std::unique_ptr m_subspaceForSVGSwitchElement; + // std::unique_ptr m_subspaceForSVGSymbolElement; + // std::unique_ptr m_subspaceForSVGTRefElement; + // std::unique_ptr m_subspaceForSVGTSpanElement; + // std::unique_ptr m_subspaceForSVGTextContentElement; + // std::unique_ptr m_subspaceForSVGTextElement; + // std::unique_ptr m_subspaceForSVGTextPathElement; + // std::unique_ptr m_subspaceForSVGTextPositioningElement; + // std::unique_ptr m_subspaceForSVGTitleElement; + // std::unique_ptr m_subspaceForSVGTransform; + // std::unique_ptr m_subspaceForSVGTransformList; + // std::unique_ptr m_subspaceForSVGUnitTypes; + // std::unique_ptr m_subspaceForSVGUseElement; + // std::unique_ptr m_subspaceForSVGVKernElement; + // std::unique_ptr m_subspaceForSVGViewElement; + // std::unique_ptr m_subspaceForSVGViewSpec; + // std::unique_ptr m_subspaceForSVGZoomEvent; + // std::unique_ptr m_subspaceForGCObservation; + // std::unique_ptr m_subspaceForInternalSettings; + // std::unique_ptr m_subspaceForInternals; + // std::unique_ptr m_subspaceForInternalsMapLike; + // std::unique_ptr m_subspaceForInternalsSetLike; + // std::unique_ptr m_subspaceForMallocStatistics; + // std::unique_ptr m_subspaceForMemoryInfo; + // std::unique_ptr m_subspaceForMockCDMFactory; + // std::unique_ptr m_subspaceForMockContentFilterSettings; + // std::unique_ptr m_subspaceForMockPageOverlay; + // std::unique_ptr m_subspaceForMockPaymentCoordinator; + // std::unique_ptr m_subspaceForServiceWorkerInternals; + // std::unique_ptr m_subspaceForTypeConversions; + // std::unique_ptr m_subspaceForWebFakeXRDevice; + // std::unique_ptr m_subspaceForWebFakeXRInputController; + // std::unique_ptr m_subspaceForWebXRTest; + // std::unique_ptr m_subspaceForDedicatedWorkerGlobalScope; + // std::unique_ptr m_subspaceForWorker; + std::unique_ptr m_subspaceForWorkerGlobalScope; + // std::unique_ptr m_subspaceForWorkerLocation; + // std::unique_ptr m_subspaceForExtendableEvent; + // std::unique_ptr m_subspaceForExtendableMessageEvent; + // std::unique_ptr m_subspaceForFetchEvent; + // std::unique_ptr m_subspaceForNavigationPreloadManager; + // std::unique_ptr m_subspaceForServiceWorker; + // std::unique_ptr m_subspaceForServiceWorkerClient; + // std::unique_ptr m_subspaceForServiceWorkerClients; + // std::unique_ptr m_subspaceForServiceWorkerContainer; + // std::unique_ptr m_subspaceForServiceWorkerGlobalScope; + // std::unique_ptr m_subspaceForServiceWorkerRegistration; + // std::unique_ptr m_subspaceForServiceWorkerWindowClient; + // std::unique_ptr m_subspaceForSharedWorker; + // std::unique_ptr m_subspaceForSharedWorkerGlobalScope; + // std::unique_ptr m_subspaceForPaintWorkletGlobalScope; + // std::unique_ptr m_subspaceForWorklet; + // std::unique_ptr m_subspaceForWorkletGlobalScope; + // std::unique_ptr m_subspaceForDOMParser; + // std::unique_ptr m_subspaceForXMLHttpRequest; + // std::unique_ptr m_subspaceForXMLHttpRequestEventTarget; + // std::unique_ptr m_subspaceForXMLHttpRequestProgressEvent; + // std::unique_ptr m_subspaceForXMLHttpRequestUpload; + // std::unique_ptr m_subspaceForXMLSerializer; + // std::unique_ptr m_subspaceForXPathEvaluator; + // std::unique_ptr m_subspaceForXPathExpression; + // std::unique_ptr m_subspaceForXPathNSResolver; + // std::unique_ptr m_subspaceForXPathResult; + // std::unique_ptr m_subspaceForXSLTProcessor; + + std::unique_ptr m_subspaceForGlobalObject; + + std::unique_ptr m_subspaceForExposedToWorkerAndWindow; + std::unique_ptr m_subspaceForURLSearchParams; + std::unique_ptr m_subspaceForURLSearchParamsIterator; + + std::unique_ptr m_subspaceForDOMException; + std::unique_ptr m_subspaceForDOMFormData; + std::unique_ptr m_subspaceForDOMFormDataIterator; + std::unique_ptr m_subspaceForDOMURL; +}; +} // namespace WebCore + +namespace WebCore { +using DOMIsoSubspaces = WebCore::DOMIsoSubspaces; +} \ No newline at end of file diff --git a/src/javascript/jsc/bindings/webcore/ExceptionDetails.h b/src/javascript/jsc/bindings/webcore/ExceptionDetails.h new file mode 100644 index 0000000000..d25c2e462c --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/ExceptionDetails.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2019 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "wtf/text/WTFString.h" + +namespace WebCore { + +struct ExceptionDetails { + enum class Type : uint8_t { + Script, + InvalidTargetFrame, + AppBoundDomain, + }; + + String message; + int lineNumber { 0 }; + int columnNumber { 0 }; + Type type { Type::Script }; + + // This bizarre explicit initialization of String is because older compilers (like on High Sierra) + // don't properly handle partial initialization lists unless every struct member has an explicit default value. + // Once we stop building on those platforms we can remove this. + String sourceURL {}; +}; + +} // namespace WebCore + +namespace WTF { +template<> struct EnumTraits { + using values = EnumValues< + WebCore::ExceptionDetails::Type, + WebCore::ExceptionDetails::Type::Script, + WebCore::ExceptionDetails::Type::InvalidTargetFrame, + WebCore::ExceptionDetails::Type::AppBoundDomain>; +}; +} diff --git a/src/javascript/jsc/bindings/webcore/ExtendedDOMClientIsoSubspaces.h b/src/javascript/jsc/bindings/webcore/ExtendedDOMClientIsoSubspaces.h new file mode 100644 index 0000000000..174eaa1948 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/ExtendedDOMClientIsoSubspaces.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2022 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "DOMClientIsoSubspaces.h" + +namespace WebCore { + +class ExtendedDOMClientIsoSubspaces : public DOMClientIsoSubspaces { +public: + ExtendedDOMClientIsoSubspaces() = default; +}; + +} // namespace WebCore + +namespace WebCore { +using ExtendedDOMClientIsoSubspaces = WebCore::ExtendedDOMClientIsoSubspaces; +} \ No newline at end of file diff --git a/src/javascript/jsc/bindings/webcore/ExtendedDOMIsoSubspaces.h b/src/javascript/jsc/bindings/webcore/ExtendedDOMIsoSubspaces.h new file mode 100644 index 0000000000..d5ccb42887 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/ExtendedDOMIsoSubspaces.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2022 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "DOMIsoSubspaces.h" + +namespace WebCore { + +class ExtendedDOMIsoSubspaces : public DOMIsoSubspaces { +public: + ExtendedDOMIsoSubspaces() = default; +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMAttribute.h b/src/javascript/jsc/bindings/webcore/JSDOMAttribute.h new file mode 100644 index 0000000000..17b0f588c7 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMAttribute.h @@ -0,0 +1,136 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2003-2020 Apple Inc. All rights reserved. + * Copyright (C) 2007 Samuel Weinig + * Copyright (C) 2009 Google, Inc. All rights reserved. + * Copyright (C) 2012 Ericsson AB. All rights reserved. + * Copyright (C) 2013 Michael Pruett + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#pragma once + +#include "JSDOMCastThisValue.h" +#include "JSDOMExceptionHandling.h" + +namespace WebCore { + +template +class IDLAttribute { +public: + using Setter = bool(JSC::JSGlobalObject&, JSClass&, JSC::JSValue); + using SetterPassingPropertyName = bool(JSC::JSGlobalObject&, JSClass&, JSC::JSValue, JSC::PropertyName); + using StaticSetter = bool(JSC::JSGlobalObject&, JSC::JSValue); + using Getter = JSC::JSValue(JSC::JSGlobalObject&, JSClass&); + using GetterPassingPropertyName = JSC::JSValue(JSC::JSGlobalObject&, JSClass&, JSC::PropertyName); + using StaticGetter = JSC::JSValue(JSC::JSGlobalObject&); + + template + static bool set(JSC::JSGlobalObject& lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, JSC::PropertyName attributeName) + { + auto throwScope = DECLARE_THROW_SCOPE(JSC::getVM(&lexicalGlobalObject)); + + auto* thisObject = castThisValue(lexicalGlobalObject, JSC::JSValue::decode(thisValue)); + if (UNLIKELY(!thisObject)) { + if constexpr (shouldThrow == CastedThisErrorBehavior::Throw) + return JSC::throwVMDOMAttributeSetterTypeError(&lexicalGlobalObject, throwScope, JSClass::info(), attributeName); + else + return false; + } + + RELEASE_AND_RETURN(throwScope, (setter(lexicalGlobalObject, *thisObject, JSC::JSValue::decode(encodedValue)))); + } + + // FIXME: FIXME: This can be merged with `set` if we replace the explicit setter function template parameter with a generic lambda. + template + static bool setPassingPropertyName(JSC::JSGlobalObject& lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, JSC::PropertyName attributeName) + { + auto throwScope = DECLARE_THROW_SCOPE(JSC::getVM(&lexicalGlobalObject)); + + auto* thisObject = castThisValue(lexicalGlobalObject, JSC::JSValue::decode(thisValue)); + if (UNLIKELY(!thisObject)) { + if constexpr (shouldThrow == CastedThisErrorBehavior::Throw) + return JSC::throwVMDOMAttributeSetterTypeError(&lexicalGlobalObject, throwScope, JSClass::info(), attributeName); + else + return false; + } + + RELEASE_AND_RETURN(throwScope, (setter(lexicalGlobalObject, *thisObject, JSC::JSValue::decode(encodedValue), attributeName))); + } + + template + static bool setStatic(JSC::JSGlobalObject& lexicalGlobalObject, JSC::EncodedJSValue, JSC::EncodedJSValue encodedValue, JSC::PropertyName) + { + return setter(lexicalGlobalObject, JSC::JSValue::decode(encodedValue)); + } + + template + static JSC::EncodedJSValue get(JSC::JSGlobalObject& lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName attributeName) + { + auto throwScope = DECLARE_THROW_SCOPE(JSC::getVM(&lexicalGlobalObject)); + + if constexpr (shouldThrow == CastedThisErrorBehavior::Assert) { + ASSERT(castThisValue(lexicalGlobalObject, JSC::JSValue::decode(thisValue))); + auto* thisObject = JSC::jsCast(JSC::JSValue::decode(thisValue)); + RELEASE_AND_RETURN(throwScope, (JSC::JSValue::encode(getter(lexicalGlobalObject, *thisObject)))); + } else { + auto* thisObject = castThisValue(lexicalGlobalObject, JSC::JSValue::decode(thisValue)); + if (UNLIKELY(!thisObject)) { + if constexpr (shouldThrow == CastedThisErrorBehavior::Throw) + return JSC::throwVMDOMAttributeGetterTypeError(&lexicalGlobalObject, throwScope, JSClass::info(), attributeName); + else if constexpr (shouldThrow == CastedThisErrorBehavior::RejectPromise) + RELEASE_AND_RETURN(throwScope, rejectPromiseWithGetterTypeError(lexicalGlobalObject, JSClass::info(), attributeName)); + else + return JSC::JSValue::encode(JSC::jsUndefined()); + } + + RELEASE_AND_RETURN(throwScope, (JSC::JSValue::encode(getter(lexicalGlobalObject, *thisObject)))); + } + } + + // FIXME: This can be merged with `get` if we replace the explicit setter function template parameter with a generic lambda. + template + static JSC::EncodedJSValue getPassingPropertyName(JSC::JSGlobalObject& lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName attributeName) + { + auto throwScope = DECLARE_THROW_SCOPE(JSC::getVM(&lexicalGlobalObject)); + + if constexpr (shouldThrow == CastedThisErrorBehavior::Assert) { + ASSERT(castThisValue(lexicalGlobalObject, JSC::JSValue::decode(thisValue))); + auto* thisObject = JSC::jsCast(JSC::JSValue::decode(thisValue)); + RELEASE_AND_RETURN(throwScope, (JSC::JSValue::encode(getter(lexicalGlobalObject, *thisObject, attributeName)))); + } else { + auto* thisObject = castThisValue(lexicalGlobalObject, JSC::JSValue::decode(thisValue)); + if (UNLIKELY(!thisObject)) { + if constexpr (shouldThrow == CastedThisErrorBehavior::Throw) + return JSC::throwVMDOMAttributeGetterTypeError(&lexicalGlobalObject, throwScope, JSClass::info(), attributeName); + else if constexpr (shouldThrow == CastedThisErrorBehavior::RejectPromise) + RELEASE_AND_RETURN(throwScope, rejectPromiseWithGetterTypeError(lexicalGlobalObject, JSClass::info(), attributeName)); + else + return JSC::JSValue::encode(JSC::jsUndefined()); + } + + RELEASE_AND_RETURN(throwScope, (JSC::JSValue::encode(getter(lexicalGlobalObject, *thisObject, attributeName)))); + } + } + + template + static JSC::EncodedJSValue getStatic(JSC::JSGlobalObject& lexicalGlobalObject, JSC::EncodedJSValue, JSC::PropertyName) + { + return JSC::JSValue::encode(getter(lexicalGlobalObject)); + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMBindingInternalsBuiltins.cpp b/src/javascript/jsc/bindings/webcore/JSDOMBindingInternalsBuiltins.cpp new file mode 100644 index 0000000000..2ae04a290d --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMBindingInternalsBuiltins.cpp @@ -0,0 +1,79 @@ +// /* +// * Copyright (c) 2016 Apple Inc. All rights reserved. +// * Copyright (c) 2017 Apple Inc. +// * +// * Redistribution and use in source and binary forms, with or without +// * modification, are permitted provided that the following conditions +// * are met: +// * 1. Redistributions of source code must retain the above copyright +// * notice, this list of conditions and the following disclaimer. +// * 2. Redistributions in binary form must reproduce the above copyright +// * notice, this list of conditions and the following disclaimer in the +// * documentation and/or other materials provided with the distribution. +// * +// * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' +// * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +// * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS +// * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +// * THE POSSIBILITY OF SUCH DAMAGE. +// * +// */ + +// // DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for +// // builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py + +// #include "config.h" +// #include "JSDOMBindingInternalsBuiltins.h" + +// #include "WebCoreJSClientData.h" +// #include "JavaScriptCore/HeapInlines.h" +// #include "JavaScriptCore/IdentifierInlines.h" +// #include "JavaScriptCore/Intrinsic.h" +// #include "JavaScriptCore/JSCJSValueInlines.h" +// #include "JavaScriptCore/JSCellInlines.h" +// #include "JavaScriptCore/StructureInlines.h" +// #include "JavaScriptCore/VM.h" + +// namespace WebCore { + +// const JSC::ConstructAbility s_jsDOMBindingInternalsForEachWrapperCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; +// const JSC::ConstructorKind s_jsDOMBindingInternalsForEachWrapperCodeConstructorKind = JSC::ConstructorKind::None; +// const int s_jsDOMBindingInternalsForEachWrapperCodeLength = 170; +// static const JSC::Intrinsic s_jsDOMBindingInternalsForEachWrapperCodeIntrinsic = JSC::NoIntrinsic; +// const char* const s_jsDOMBindingInternalsForEachWrapperCode = +// "(function (mapLikeOrSetLike, callback)\n" \ +// "{\n" \ +// " \"use strict\";\n" \ +// " mapLikeOrSetLike.forEach((value, key, backingMapOrSet) => {\n" \ +// " callback(value, key, this);\n" \ +// " });\n" \ +// "})\n" \ +// ; + +// const JSC::ConstructAbility s_jsDOMBindingInternalsGetUserMediaShimCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; +// const JSC::ConstructorKind s_jsDOMBindingInternalsGetUserMediaShimCodeConstructorKind = JSC::ConstructorKind::None; +// const int s_jsDOMBindingInternalsGetUserMediaShimCodeLength = 147; +// static const JSC::Intrinsic s_jsDOMBindingInternalsGetUserMediaShimCodeIntrinsic = JSC::NoIntrinsic; +// const char* const s_jsDOMBindingInternalsGetUserMediaShimCode = +// "(function (constraints, successCallback, errorCallback)\n" \ +// "{\n" \ +// " this.mediaDevices.getUserMedia(constraints).then(successCallback, errorCallback);\n" \ +// "})\n" \ +// ; + +// #define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \ +// JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \ +// {\ +// JSVMClientData* clientData = static_cast(vm.clientData); \ +// return clientData->builtinFunctions().jsDOMBindingInternalsBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().jsDOMBindingInternalsBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \ +// } +// WEBCORE_FOREACH_JSDOMBINDINGINTERNALS_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR) +// #undef DEFINE_BUILTIN_GENERATOR + +// } // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMBindingInternalsBuiltins.h b/src/javascript/jsc/bindings/webcore/JSDOMBindingInternalsBuiltins.h new file mode 100644 index 0000000000..40b698c3a2 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMBindingInternalsBuiltins.h @@ -0,0 +1,159 @@ +// /* +// * Copyright (c) 2016 Apple Inc. All rights reserved. +// * Copyright (c) 2017 Apple Inc. +// * +// * Redistribution and use in source and binary forms, with or without +// * modification, are permitted provided that the following conditions +// * are met: +// * 1. Redistributions of source code must retain the above copyright +// * notice, this list of conditions and the following disclaimer. +// * 2. Redistributions in binary form must reproduce the above copyright +// * notice, this list of conditions and the following disclaimer in the +// * documentation and/or other materials provided with the distribution. +// * +// * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' +// * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +// * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS +// * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +// * THE POSSIBILITY OF SUCH DAMAGE. +// * +// */ + +// // DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for +// // builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py + +// #pragma once + +// #include "JavaScriptCore/BuiltinUtils.h" +// #include "JavaScriptCore/Identifier.h" +// #include "JavaScriptCore/JSFunction.h" +// #include "JavaScriptCore/UnlinkedFunctionExecutable.h" + +// namespace JSC { +// class FunctionExecutable; +// } + +// namespace WebCore { + +// /* JSDOMBindingInternals */ +// extern const char* const s_jsDOMBindingInternalsForEachWrapperCode; +// extern const int s_jsDOMBindingInternalsForEachWrapperCodeLength; +// extern const JSC::ConstructAbility s_jsDOMBindingInternalsForEachWrapperCodeConstructAbility; +// extern const JSC::ConstructorKind s_jsDOMBindingInternalsForEachWrapperCodeConstructorKind; +// extern const char* const s_jsDOMBindingInternalsGetUserMediaShimCode; +// extern const int s_jsDOMBindingInternalsGetUserMediaShimCodeLength; +// extern const JSC::ConstructAbility s_jsDOMBindingInternalsGetUserMediaShimCodeConstructAbility; +// extern const JSC::ConstructorKind s_jsDOMBindingInternalsGetUserMediaShimCodeConstructorKind; + +// #define WEBCORE_BUILTIN_JSDOMBINDINGINTERNALS_FOREACHWRAPPER 0 +// #define WEBCORE_BUILTIN_JSDOMBINDINGINTERNALS_GETUSERMEDIASHIM 0 + +// #define WEBCORE_FOREACH_JSDOMBINDINGINTERNALS_BUILTIN_CODE(macro) \ +// macro(jsDOMBindingInternalsForEachWrapperCode, forEachWrapper, static_cast(nullptr), s_jsDOMBindingInternalsForEachWrapperCodeLength) \ +// macro(jsDOMBindingInternalsGetUserMediaShimCode, getUserMediaShim, static_cast(nullptr), s_jsDOMBindingInternalsGetUserMediaShimCodeLength) + +// #define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \ +// JSC::FunctionExecutable* codeName##Generator(JSC::VM&); + +// WEBCORE_FOREACH_JSDOMBINDINGINTERNALS_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR) +// #undef DECLARE_BUILTIN_GENERATOR + +// class JSDOMBindingInternalsBuiltinsWrapper : private JSC::WeakHandleOwner { +// public: +// explicit JSDOMBindingInternalsBuiltinsWrapper(JSC::VM& vm) +// : m_vm(vm) +// WEBCORE_FOREACH_JSDOMBINDINGINTERNALS_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES) +// #define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createFromLiteral(s_##name, length), {})) +// WEBCORE_FOREACH_JSDOMBINDINGINTERNALS_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS) +// #undef INITIALIZE_BUILTIN_SOURCE_MEMBERS +// { +// } + +// #define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \ +// JSC::UnlinkedFunctionExecutable* name##Executable(); \ +// const JSC::SourceCode& name##Source() const { return m_##name##Source; } +// WEBCORE_FOREACH_JSDOMBINDINGINTERNALS_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES) +// #undef EXPOSE_BUILTIN_EXECUTABLES + +// WEBCORE_FOREACH_JSDOMBINDINGINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR) + +// void exportNames(); + +// private: +// JSC::VM& m_vm; + +// WEBCORE_FOREACH_JSDOMBINDINGINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES) + +// #define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \ +// JSC::SourceCode m_##name##Source; \ +// JSC::Weak m_##name##Executable; +// WEBCORE_FOREACH_JSDOMBINDINGINTERNALS_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS) +// #undef DECLARE_BUILTIN_SOURCE_MEMBERS +// }; + +// #define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \ +// inline JSC::UnlinkedFunctionExecutable* JSDOMBindingInternalsBuiltinsWrapper::name##Executable() \ +// { \ +// if (!m_##name##Executable) { \ +// JSC::Identifier executableName = functionName##PublicName(); \ +// if (overriddenName) \ +// executableName = JSC::Identifier::fromString(m_vm, overriddenName); \ +// m_##name##Executable = JSC::Weak(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable); \ +// } \ +// return m_##name##Executable.get(); \ +// } +// WEBCORE_FOREACH_JSDOMBINDINGINTERNALS_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES) +// #undef DEFINE_BUILTIN_EXECUTABLES + +// inline void JSDOMBindingInternalsBuiltinsWrapper::exportNames() +// { +// #define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName()); +// WEBCORE_FOREACH_JSDOMBINDINGINTERNALS_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME) +// #undef EXPORT_FUNCTION_NAME +// } + +// class JSDOMBindingInternalsBuiltinFunctions { +// public: +// explicit JSDOMBindingInternalsBuiltinFunctions(JSC::VM& vm) +// : m_vm(vm) +// { +// } + +// void init(JSC::JSGlobalObject&); +// template void visit(Visitor&); + +// public: +// JSC::VM& m_vm; + +// #define DECLARE_BUILTIN_SOURCE_MEMBERS(functionName) \ +// JSC::WriteBarrier m_##functionName##Function; +// WEBCORE_FOREACH_JSDOMBINDINGINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_SOURCE_MEMBERS) +// #undef DECLARE_BUILTIN_SOURCE_MEMBERS +// }; + +// inline void JSDOMBindingInternalsBuiltinFunctions::init(JSC::JSGlobalObject& globalObject) +// { +// #define EXPORT_FUNCTION(codeName, functionName, overriddenName, length) \ +// m_##functionName##Function.set(m_vm, &globalObject, JSC::JSFunction::create(m_vm, codeName##Generator(m_vm), &globalObject)); +// WEBCORE_FOREACH_JSDOMBINDINGINTERNALS_BUILTIN_CODE(EXPORT_FUNCTION) +// #undef EXPORT_FUNCTION +// } + +// template +// inline void JSDOMBindingInternalsBuiltinFunctions::visit(Visitor& visitor) +// { +// #define VISIT_FUNCTION(name) visitor.append(m_##name##Function); +// WEBCORE_FOREACH_JSDOMBINDINGINTERNALS_BUILTIN_FUNCTION_NAME(VISIT_FUNCTION) +// #undef VISIT_FUNCTION +// } + +// template void JSDOMBindingInternalsBuiltinFunctions::visit(JSC::AbstractSlotVisitor&); +// template void JSDOMBindingInternalsBuiltinFunctions::visit(JSC::SlotVisitor&); + +// } // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMCastThisValue.h b/src/javascript/jsc/bindings/webcore/JSDOMCastThisValue.h new file mode 100644 index 0000000000..ada862b728 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMCastThisValue.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2003-2006, 2008-2009, 2013, 2016 Apple Inc. All rights reserved. + * Copyright (C) 2007 Samuel Weinig + * Copyright (C) 2009 Google, Inc. All rights reserved. + * Copyright (C) 2012 Ericsson AB. All rights reserved. + * Copyright (C) 2013 Michael Pruett + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "JSDOMGlobalObject.h" + +namespace WebCore { + +enum class CastedThisErrorBehavior : uint8_t { + Throw, + ReturnEarly, + RejectPromise, + Assert, +}; + +template +JSClass* castThisValue(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue thisValue) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + if constexpr (std::is_base_of_v) + return toJSDOMGlobalObject(vm, thisValue.isUndefinedOrNull() ? JSC::JSValue(&lexicalGlobalObject) : thisValue); + else + return JSC::jsDynamicCast(vm, thisValue); +} + +} diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConstructor.h b/src/javascript/jsc/bindings/webcore/JSDOMConstructor.h new file mode 100644 index 0000000000..af969de89c --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConstructor.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2015, 2016 Canon Inc. All rights reserved. + * Copyright (C) 2016-2021 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#pragma once + +#include "JSDOMConstructorBase.h" + +namespace WebCore { + +template class JSDOMConstructor final : public JSDOMConstructorBase { +public: + using Base = JSDOMConstructorBase; + + static JSDOMConstructor* create(JSC::VM&, JSC::Structure*, JSDOMGlobalObject&); + static JSC::Structure* createStructure(JSC::VM&, JSC::JSGlobalObject&, JSC::JSValue prototype); + + DECLARE_INFO; + + // Must be defined for each specialization class. + static JSC::JSValue prototypeForStructure(JSC::VM&, const JSDOMGlobalObject&); + + // Must be defined for each specialization class. + static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*); + +private: + JSDOMConstructor(JSC::VM& vm, JSC::Structure* structure) + : Base(vm, structure, construct) + { + } + + void finishCreation(JSC::VM&, JSDOMGlobalObject&); + + // Usually defined for each specialization class. + void initializeProperties(JSC::VM&, JSDOMGlobalObject&) { } +}; + +template inline JSDOMConstructor* JSDOMConstructor::create(JSC::VM& vm, JSC::Structure* structure, JSDOMGlobalObject& globalObject) +{ + JSDOMConstructor* constructor = new (NotNull, JSC::allocateCell(vm)) JSDOMConstructor(vm, structure); + constructor->finishCreation(vm, globalObject); + return constructor; +} + +template inline JSC::Structure* JSDOMConstructor::createStructure(JSC::VM& vm, JSC::JSGlobalObject& globalObject, JSC::JSValue prototype) +{ + return JSC::Structure::create(vm, &globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info()); +} + +template inline void JSDOMConstructor::finishCreation(JSC::VM& vm, JSDOMGlobalObject& globalObject) +{ + Base::finishCreation(vm); + ASSERT(inherits(vm, info())); + initializeProperties(vm, globalObject); +} + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConstructorBase.cpp b/src/javascript/jsc/bindings/webcore/JSDOMConstructorBase.cpp new file mode 100644 index 0000000000..90170e9106 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConstructorBase.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2004-2022 Apple Inc. All rights reserved. + * Copyright (C) 2007 Samuel Weinig + * Copyright (C) 2013 Michael Pruett + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSDOMConstructor.h" + +#include "JavaScriptCore/JSCInlines.h" +#include "WebCoreJSClientData.h" + +namespace WebCore { +using namespace JSC; + +STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSDOMConstructorBase); + +JSC_DEFINE_HOST_FUNCTION(callThrowTypeErrorForJSDOMConstructor, (JSGlobalObject * globalObject, CallFrame*)) +{ + VM& vm = globalObject->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + throwTypeError(globalObject, scope, "Constructor requires 'new' operator"_s); + return JSValue::encode(jsNull()); +} + +JSC_DEFINE_HOST_FUNCTION(callThrowTypeErrorForJSDOMConstructorNotConstructable, (JSC::JSGlobalObject * globalObject, JSC::CallFrame*)) +{ + JSC::VM& vm = globalObject->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + JSC::throwTypeError(globalObject, scope, "Illegal constructor"_s); + return JSC::JSValue::encode(JSC::jsNull()); +} + +JSC::GCClient::IsoSubspace* JSDOMConstructorBase::subspaceForImpl(JSC::VM& vm) +{ + return &static_cast(vm.clientData)->domConstructorSpace(); +} + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConstructorBase.h b/src/javascript/jsc/bindings/webcore/JSDOMConstructorBase.h new file mode 100644 index 0000000000..a5b644d196 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConstructorBase.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2015, 2016 Canon Inc. All rights reserved. + * Copyright (C) 2016-2022 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#pragma once + +#include "JSDOMGlobalObject.h" +#include "JavaScriptCore/InternalFunction.h" + +#include "ZigGlobalObject.h" + +namespace WebCore { + +JSC_DECLARE_HOST_FUNCTION(callThrowTypeErrorForJSDOMConstructor); +JSC_DECLARE_HOST_FUNCTION(callThrowTypeErrorForJSDOMConstructorNotConstructable); + +// Base class for all callable constructor objects in the JSC bindings. +class JSDOMConstructorBase : public JSC::InternalFunction { +public: + using Base = InternalFunction; + + static constexpr unsigned StructureFlags = Base::StructureFlags; + static constexpr bool needsDestruction = false; + + template + static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + static_assert(sizeof(CellType) == sizeof(JSDOMConstructorBase)); + STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(CellType, JSDOMConstructorBase); + static_assert(CellType::destroy == JSC::JSCell::destroy, "JSDOMConstructor is not destructible actually"); + return subspaceForImpl(vm); + } + + static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM&); + + JSDOMGlobalObject* globalObject() const { return JSC::jsCast(Base::globalObject()); } + // ScriptExecutionContext* scriptExecutionContext() const { return globalObject()->scriptExecutionContext(); } + +protected: + JSDOMConstructorBase(JSC::VM& vm, JSC::Structure* structure, JSC::NativeFunction functionForConstruct) + : Base(vm, structure, + functionForConstruct ? callThrowTypeErrorForJSDOMConstructor : callThrowTypeErrorForJSDOMConstructorNotConstructable, + functionForConstruct ? functionForConstruct : callThrowTypeErrorForJSDOMConstructorNotConstructable) + { + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConstructorNotCallable.h b/src/javascript/jsc/bindings/webcore/JSDOMConstructorNotCallable.h new file mode 100644 index 0000000000..da94a3f486 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConstructorNotCallable.h @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2021 Alexey Shvayka + * Copyright (C) 2021-2022 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "JSDOMWrapper.h" +#include "WebCoreJSClientData.h" + +namespace WebCore { + +template class JSDOMConstructorNotCallable : public JSDOMObject { +public: + using Base = JSDOMObject; + + static constexpr unsigned StructureFlags = Base::StructureFlags; + static constexpr bool needsDestruction = false; + static JSDOMConstructorNotCallable* create(JSC::VM&, JSC::Structure*, JSDOMGlobalObject&); + static JSC::Structure* createStructure(JSC::VM&, JSC::JSGlobalObject&, JSC::JSValue prototype); + + DECLARE_INFO; + + static JSC::JSValue prototypeForStructure(JSC::VM&, const JSDOMGlobalObject&); + + template + static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + static_assert(sizeof(CellType) == sizeof(JSDOMConstructorNotCallable)); + STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(CellType, JSDOMConstructorNotCallable); + static_assert(CellType::destroy == JSC::JSCell::destroy, "JSDOMConstructorNotCallable is not destructible actually"); + return &static_cast(vm.clientData)->domNamespaceObjectSpace(); + } + +private: + JSDOMConstructorNotCallable(JSC::Structure* structure, JSDOMGlobalObject& globalObject) + : Base(structure, globalObject) + { + } + + void finishCreation(JSC::VM&, JSDOMGlobalObject&); + void initializeProperties(JSC::VM&, JSDOMGlobalObject&) {} +}; + +template inline JSDOMConstructorNotCallable* JSDOMConstructorNotCallable::create(JSC::VM& vm, JSC::Structure* structure, JSDOMGlobalObject& globalObject) +{ + JSDOMConstructorNotCallable* constructor = new (NotNull, JSC::allocateCell(vm)) JSDOMConstructorNotCallable(structure, globalObject); + constructor->finishCreation(vm, globalObject); + return constructor; +} + +template inline JSC::Structure* JSDOMConstructorNotCallable::createStructure(JSC::VM& vm, JSC::JSGlobalObject& globalObject, JSC::JSValue prototype) +{ + return JSC::Structure::create(vm, &globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); +} + +template inline void JSDOMConstructorNotCallable::finishCreation(JSC::VM& vm, JSDOMGlobalObject& globalObject) +{ + Base::finishCreation(vm); + ASSERT(inherits(vm, info())); + initializeProperties(vm, globalObject); +} + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConstructorNotConstructable.h b/src/javascript/jsc/bindings/webcore/JSDOMConstructorNotConstructable.h new file mode 100644 index 0000000000..55d4e7792b --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConstructorNotConstructable.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2015, 2016 Canon Inc. All rights reserved. + * Copyright (C) 2016-2021 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#pragma once + +#include "JSDOMConstructorBase.h" + +namespace WebCore { + +template class JSDOMConstructorNotConstructable final : public JSDOMConstructorBase { +public: + using Base = JSDOMConstructorBase; + + static JSDOMConstructorNotConstructable* create(JSC::VM&, JSC::Structure*, JSDOMGlobalObject&); + static JSC::Structure* createStructure(JSC::VM&, JSC::JSGlobalObject&, JSC::JSValue prototype); + + DECLARE_INFO; + + // Must be defined for each specialization class. + static JSC::JSValue prototypeForStructure(JSC::VM&, const JSDOMGlobalObject&); + +private: + JSDOMConstructorNotConstructable(JSC::VM& vm, JSC::Structure* structure) + : Base(vm, structure, nullptr) + { + } + + void finishCreation(JSC::VM&, JSDOMGlobalObject&); + + // Usually defined for each specialization class. + void initializeProperties(JSC::VM&, JSDOMGlobalObject&) {} +}; + +template inline JSDOMConstructorNotConstructable* JSDOMConstructorNotConstructable::create(JSC::VM& vm, JSC::Structure* structure, JSDOMGlobalObject& globalObject) +{ + JSDOMConstructorNotConstructable* constructor = new (NotNull, JSC::allocateCell(vm)) JSDOMConstructorNotConstructable(vm, structure); + constructor->finishCreation(vm, globalObject); + return constructor; +} + +template inline JSC::Structure* JSDOMConstructorNotConstructable::createStructure(JSC::VM& vm, JSC::JSGlobalObject& globalObject, JSC::JSValue prototype) +{ + return JSC::Structure::create(vm, &globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info()); +} + +template inline void JSDOMConstructorNotConstructable::finishCreation(JSC::VM& vm, JSDOMGlobalObject& globalObject) +{ + Base::finishCreation(vm); + ASSERT(inherits(vm, info())); + initializeProperties(vm, globalObject); +} + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvert.h b/src/javascript/jsc/bindings/webcore/JSDOMConvert.h new file mode 100644 index 0000000000..91cd5602c0 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvert.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "JSDOMConvertAny.h" +#include "JSDOMConvertBoolean.h" +#include "JSDOMConvertBufferSource.h" +#include "JSDOMConvertCallbacks.h" +#include "JSDOMConvertDate.h" +#include "JSDOMConvertDictionary.h" +#include "JSDOMConvertEnumeration.h" +#include "JSDOMConvertEventListener.h" +#include "JSDOMConvertInterface.h" +#include "JSDOMConvertJSON.h" +#include "JSDOMConvertNull.h" +#include "JSDOMConvertNullable.h" +#include "JSDOMConvertNumbers.h" +#include "JSDOMConvertObject.h" +#include "JSDOMConvertRecord.h" +#include "JSDOMConvertSequences.h" +#include "JSDOMConvertSerializedScriptValue.h" +#include "JSDOMConvertStrings.h" +#include "JSDOMConvertUnion.h" +#include "JSDOMConvertWebGL.h" diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertAny.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertAny.h new file mode 100644 index 0000000000..b744bbb89b --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertAny.h @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include "JSDOMConvertBase.h" +#include "JSValueInWrappedObject.h" + +namespace WebCore { + +template<> struct Converter : DefaultConverter { + using ReturnType = JSC::JSValue; + + static constexpr bool conversionHasSideEffects = false; + + static JSC::JSValue convert(JSC::JSGlobalObject&, JSC::JSValue value) + { + return value; + } + + static JSC::JSValue convert(const JSC::Strong& value) + { + return value.get(); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = false; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(const JSC::JSValue& value) + { + return value; + } + + static JSC::JSValue convert(const JSC::Strong& value) + { + return value.get(); + } + + static JSC::JSValue convert(const JSValueInWrappedObject& value) + { + return value.getValue(); + } +}; + +template<> struct VariadicConverter { + using Item = typename IDLAny::ImplementationType; + + static std::optional convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + + auto result = Converter::convert(lexicalGlobalObject, value); + RETURN_IF_EXCEPTION(scope, std::nullopt); + + return Item { vm, result }; + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertBase.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertBase.h new file mode 100644 index 0000000000..928e79b991 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertBase.h @@ -0,0 +1,268 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once +#include "root.h" +#include "ZigGlobalObject.h" + +#include "JSDOMExceptionHandling.h" +#include "JavaScriptCore/Error.h" + +namespace WebCore { + +// Conversion from JSValue -> Implementation +template struct Converter; + +namespace Detail { + +template inline T* getPtrOrRef(const T* p) { return const_cast(p); } +template inline T& getPtrOrRef(const T& p) { return const_cast(p); } +template inline T* getPtrOrRef(const RefPtr& p) { return p.get(); } +template inline T& getPtrOrRef(const Ref& p) { return p.get(); } + +} + +struct DefaultExceptionThrower { + void operator()(JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) + { + throwTypeError(&lexicalGlobalObject, scope); + } +}; + +template typename Converter::ReturnType convert(JSC::JSGlobalObject&, JSC::JSValue); +template typename Converter::ReturnType convert(JSC::JSGlobalObject&, JSC::JSValue, JSC::JSObject&); +template typename Converter::ReturnType convert(JSC::JSGlobalObject&, JSC::JSValue, JSDOMGlobalObject&); +template typename Converter::ReturnType convert(JSC::JSGlobalObject&, JSC::JSValue, ExceptionThrower&&); +template typename Converter::ReturnType convert(JSC::JSGlobalObject&, JSC::JSValue, JSC::JSObject&, ExceptionThrower&&); +template typename Converter::ReturnType convert(JSC::JSGlobalObject&, JSC::JSValue, JSDOMGlobalObject&, ExceptionThrower&&); + +template inline typename Converter::ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + return Converter::convert(lexicalGlobalObject, value); +} + +template inline typename Converter::ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, JSC::JSObject& thisObject) +{ + return Converter::convert(lexicalGlobalObject, value, thisObject); +} + +template inline typename Converter::ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, JSDOMGlobalObject& globalObject) +{ + return Converter::convert(lexicalGlobalObject, value, globalObject); +} + +template inline typename Converter::ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower) +{ + return Converter::convert(lexicalGlobalObject, value, std::forward(exceptionThrower)); +} + +template inline typename Converter::ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, JSC::JSObject& thisObject, ExceptionThrower&& exceptionThrower) +{ + return Converter::convert(lexicalGlobalObject, value, thisObject, std::forward(exceptionThrower)); +} + +template inline typename Converter::ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, JSDOMGlobalObject& globalObject, ExceptionThrower&& exceptionThrower) +{ + return Converter::convert(lexicalGlobalObject, value, globalObject, std::forward(exceptionThrower)); +} + +// Conversion from Implementation -> JSValue +template struct JSConverter; + +template inline JSC::JSValue toJS(U&&); +template inline JSC::JSValue toJS(JSC::JSGlobalObject&, U&&); +template inline JSC::JSValue toJS(JSC::JSGlobalObject&, JSDOMGlobalObject&, U&&); +template inline JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject&, JSDOMGlobalObject&, U&&); + +template inline JSC::JSValue toJS(JSC::JSGlobalObject&, JSC::ThrowScope&, U&& valueOrFunctor); +template inline JSC::JSValue toJS(JSC::JSGlobalObject&, JSDOMGlobalObject&, JSC::ThrowScope&, U&& valueOrFunctor); +template inline JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject&, JSDOMGlobalObject&, JSC::ThrowScope&, U&& valueOrFunctor); + +template::needsState, bool needsGlobalObject = JSConverter::needsGlobalObject> +struct JSConverterOverloader; + +template +struct JSConverterOverloader { + template static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, U&& value) + { + return JSConverter::convert(lexicalGlobalObject, globalObject, std::forward(value)); + } +}; + +template +struct JSConverterOverloader { + template static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, U&& value) + { + return JSConverter::convert(lexicalGlobalObject, std::forward(value)); + } + + template static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject&, U&& value) + { + return JSConverter::convert(lexicalGlobalObject, std::forward(value)); + } +}; + +template +struct JSConverterOverloader { + template static JSC::JSValue convert(JSC::JSGlobalObject&, U&& value) + { + return JSConverter::convert(std::forward(value)); + } + + template static JSC::JSValue convert(JSC::JSGlobalObject&, JSDOMGlobalObject&, U&& value) + { + return JSConverter::convert(std::forward(value)); + } +}; + +template inline JSC::JSValue toJS(U&& value) +{ + return JSConverter::convert(std::forward(value)); +} + +template inline JSC::JSValue toJS(JSC::JSGlobalObject& lexicalGlobalObject, U&& value) +{ + return JSConverterOverloader::convert(lexicalGlobalObject, std::forward(value)); +} + +template inline JSC::JSValue toJS(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, U&& value) +{ + return JSConverterOverloader::convert(lexicalGlobalObject, globalObject, std::forward(value)); +} + +template inline JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, U&& value) +{ + return JSConverter::convertNewlyCreated(lexicalGlobalObject, globalObject, std::forward(value)); +} + +template inline JSC::JSValue toJS(JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& throwScope, U&& valueOrFunctor) +{ + if constexpr (std::is_invocable_v) { + using FunctorReturnType = std::invoke_result_t; + + if constexpr (std::is_same_v) { + valueOrFunctor(); + return JSC::jsUndefined(); + } else if constexpr (std::is_same_v, FunctorReturnType>) { + auto result = valueOrFunctor(); + if (UNLIKELY(result.hasException())) { + propagateException(lexicalGlobalObject, throwScope, result.releaseException()); + return {}; + } + return JSC::jsUndefined(); + } else + return toJS(lexicalGlobalObject, throwScope, valueOrFunctor()); + } else { + if constexpr (IsExceptionOr) { + if (UNLIKELY(valueOrFunctor.hasException())) { + propagateException(lexicalGlobalObject, throwScope, valueOrFunctor.releaseException()); + return {}; + } + + return toJS(lexicalGlobalObject, valueOrFunctor.releaseReturnValue()); + } else + return toJS(lexicalGlobalObject, std::forward(valueOrFunctor)); + } +} + +template inline JSC::JSValue toJS(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, JSC::ThrowScope& throwScope, U&& valueOrFunctor) +{ + if constexpr (std::is_invocable_v) { + using FunctorReturnType = std::invoke_result_t; + + if constexpr (std::is_same_v) { + valueOrFunctor(); + return JSC::jsUndefined(); + } else if constexpr (std::is_same_v, FunctorReturnType>) { + auto result = valueOrFunctor(); + if (UNLIKELY(result.hasException())) { + propagateException(lexicalGlobalObject, throwScope, result.releaseException()); + return {}; + } + return JSC::jsUndefined(); + } else + return toJS(lexicalGlobalObject, globalObject, throwScope, valueOrFunctor()); + } else { + if constexpr (IsExceptionOr) { + if (UNLIKELY(valueOrFunctor.hasException())) { + propagateException(lexicalGlobalObject, throwScope, valueOrFunctor.releaseException()); + return {}; + } + + return toJS(lexicalGlobalObject, globalObject, valueOrFunctor.releaseReturnValue()); + } else + return toJS(lexicalGlobalObject, globalObject, std::forward(valueOrFunctor)); + } +} + +template inline JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, JSC::ThrowScope& throwScope, U&& valueOrFunctor) +{ + if constexpr (std::is_invocable_v) { + using FunctorReturnType = std::invoke_result_t; + + if constexpr (std::is_same_v) { + valueOrFunctor(); + return JSC::jsUndefined(); + } else if constexpr (std::is_same_v, FunctorReturnType>) { + auto result = valueOrFunctor(); + if (UNLIKELY(result.hasException())) { + propagateException(lexicalGlobalObject, throwScope, result.releaseException()); + return {}; + } + return JSC::jsUndefined(); + } else + return toJSNewlyCreated(lexicalGlobalObject, globalObject, throwScope, valueOrFunctor()); + + } else { + if constexpr (IsExceptionOr) { + if (UNLIKELY(valueOrFunctor.hasException())) { + propagateException(lexicalGlobalObject, throwScope, valueOrFunctor.releaseException()); + return {}; + } + + return toJSNewlyCreated(lexicalGlobalObject, globalObject, valueOrFunctor.releaseReturnValue()); + } else + return toJSNewlyCreated(lexicalGlobalObject, globalObject, std::forward(valueOrFunctor)); + } +} + +template struct DefaultConverter { + using ReturnType = typename T::ImplementationType; + + // We assume the worst, subtypes can override to be less pessimistic. + // An example of something that can have side effects + // is having a converter that does JSC::JSValue::toNumber. + // toNumber() in JavaScript can call arbitrary JS functions. + // + // An example of something that does not have side effects + // is something having a converter that does JSC::JSValue::toBoolean. + // toBoolean() in JS can't call arbitrary functions. + static constexpr bool conversionHasSideEffects = true; +}; + +// Conversion from JSValue -> Implementation for variadic arguments +template struct VariadicConverter; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertBoolean.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertBoolean.h new file mode 100644 index 0000000000..ed8ea5211e --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertBoolean.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include "JSDOMConvertBase.h" + +namespace WebCore { + +template<> struct Converter : DefaultConverter { + + static constexpr bool conversionHasSideEffects = false; + + static bool convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return value.toBoolean(&lexicalGlobalObject); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = false; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(bool value) + { + return JSC::jsBoolean(value); + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertBufferSource.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertBufferSource.h new file mode 100644 index 0000000000..7cc629ab81 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertBufferSource.h @@ -0,0 +1,481 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "BufferSource.h" +#include "IDLTypes.h" +#include "JSDOMConvertBase.h" +#include "JSDOMWrapperCache.h" +#include "JavaScriptCore/JSTypedArrays.h" + +namespace WebCore { + +struct IDLInt8Array : IDLTypedArray { +}; +struct IDLInt16Array : IDLTypedArray { +}; +struct IDLInt32Array : IDLTypedArray { +}; +struct IDLUint8Array : IDLTypedArray { +}; +struct IDLUint16Array : IDLTypedArray { +}; +struct IDLUint32Array : IDLTypedArray { +}; +struct IDLUint8ClampedArray : IDLTypedArray { +}; +struct IDLFloat32Array : IDLTypedArray { +}; +struct IDLFloat64Array : IDLTypedArray { +}; +struct IDLBigInt64Array : IDLTypedArray { +}; +struct IDLBigUint64Array : IDLTypedArray { +}; + +inline RefPtr toPossiblySharedInt8Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView(vm, value); } +inline RefPtr toPossiblySharedInt16Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView(vm, value); } +inline RefPtr toPossiblySharedInt32Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView(vm, value); } +inline RefPtr toPossiblySharedUint8Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView(vm, value); } +inline RefPtr toPossiblySharedUint8ClampedArray(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView(vm, value); } +inline RefPtr toPossiblySharedUint16Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView(vm, value); } +inline RefPtr toPossiblySharedUint32Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView(vm, value); } +inline RefPtr toPossiblySharedFloat32Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView(vm, value); } +inline RefPtr toPossiblySharedFloat64Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView(vm, value); } +inline RefPtr toPossiblySharedBigInt64Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView(vm, value); } +inline RefPtr toPossiblySharedBigUint64Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView(vm, value); } + +inline RefPtr toUnsharedInt8Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView(vm, value); } +inline RefPtr toUnsharedInt16Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView(vm, value); } +inline RefPtr toUnsharedInt32Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView(vm, value); } +inline RefPtr toUnsharedUint8Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView(vm, value); } +inline RefPtr toUnsharedUint8ClampedArray(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView(vm, value); } +inline RefPtr toUnsharedUint16Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView(vm, value); } +inline RefPtr toUnsharedUint32Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView(vm, value); } +inline RefPtr toUnsharedFloat32Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView(vm, value); } +inline RefPtr toUnsharedFloat64Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView(vm, value); } +inline RefPtr toUnsharedBigInt64Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView(vm, value); } +inline RefPtr toUnsharedBigUint64Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView(vm, value); } + +inline JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, JSC::ArrayBuffer& buffer) +{ + if (auto result = getCachedWrapper(globalObject->world(), buffer)) + return result; + + // The JSArrayBuffer::create function will register the wrapper in finishCreation. + return JSC::JSArrayBuffer::create(JSC::getVM(lexicalGlobalObject), globalObject->arrayBufferStructure(buffer.sharingMode()), &buffer); +} + +inline JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSC::JSGlobalObject* globalObject, JSC::ArrayBufferView& view) +{ + return view.wrap(lexicalGlobalObject, globalObject); +} + +inline JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, JSC::ArrayBuffer* buffer) +{ + if (!buffer) + return JSC::jsNull(); + return toJS(lexicalGlobalObject, globalObject, *buffer); +} + +inline JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSC::JSGlobalObject* globalObject, JSC::ArrayBufferView* view) +{ + if (!view) + return JSC::jsNull(); + return toJS(lexicalGlobalObject, globalObject, *view); +} + +inline RefPtr toPossiblySharedArrayBufferView(JSC::VM& vm, JSC::JSValue value) +{ + auto* wrapper = JSC::jsDynamicCast(vm, value); + if (!wrapper) + return nullptr; + return wrapper->possiblySharedImpl(); +} + +inline RefPtr toUnsharedArrayBufferView(JSC::VM& vm, JSC::JSValue value) +{ + auto result = toPossiblySharedArrayBufferView(vm, value); + if (!result || result->isShared()) + return nullptr; + return result; +} + +namespace Detail { + +enum class BufferSourceConverterAllowSharedMode { Allow, + Disallow }; +template +struct BufferSourceConverter { + using WrapperType = typename Converter::WrapperType; + using ReturnType = typename Converter::ReturnType; + + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + ReturnType object {}; + if constexpr (mode == BufferSourceConverterAllowSharedMode::Allow) + object = WrapperType::toWrappedAllowShared(vm, value); + else + object = WrapperType::toWrapped(vm, value); + if (UNLIKELY(!object)) + exceptionThrower(lexicalGlobalObject, scope); + return object; + } +}; + +} + +template<> struct Converter : DefaultConverter { + using WrapperType = JSC::JSArrayBuffer; + using ReturnType = JSC::ArrayBuffer*; + + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + return Detail::BufferSourceConverter::convert(lexicalGlobalObject, value, std::forward(exceptionThrower)); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const U& value) + { + return toJS(&lexicalGlobalObject, &globalObject, Detail::getPtrOrRef(value)); + } +}; + +template<> struct Converter : DefaultConverter { + using WrapperType = JSC::JSDataView; + using ReturnType = RefPtr; + + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + return Detail::BufferSourceConverter::convert(lexicalGlobalObject, value, std::forward(exceptionThrower)); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const U& value) + { + return toJS(&lexicalGlobalObject, &globalObject, Detail::getPtrOrRef(value)); + } +}; + +template<> struct Converter : DefaultConverter { + using WrapperType = JSC::JSInt8Array; + using ReturnType = RefPtr; + + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + return Detail::BufferSourceConverter::convert(lexicalGlobalObject, value, std::forward(exceptionThrower)); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const U& value) + { + return toJS(&lexicalGlobalObject, &globalObject, Detail::getPtrOrRef(value)); + } +}; + +template<> struct Converter : DefaultConverter { + using WrapperType = JSC::JSInt16Array; + using ReturnType = RefPtr; + + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + return Detail::BufferSourceConverter::convert(lexicalGlobalObject, value, std::forward(exceptionThrower)); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const U& value) + { + return toJS(&lexicalGlobalObject, &globalObject, Detail::getPtrOrRef(value)); + } +}; + +template<> struct Converter : DefaultConverter { + using WrapperType = JSC::JSInt32Array; + using ReturnType = RefPtr; + + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + return Detail::BufferSourceConverter::convert(lexicalGlobalObject, value, std::forward(exceptionThrower)); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const U& value) + { + return toJS(&lexicalGlobalObject, &globalObject, Detail::getPtrOrRef(value)); + } +}; + +template<> struct Converter : DefaultConverter { + using WrapperType = JSC::JSUint8Array; + using ReturnType = RefPtr; + + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + return Detail::BufferSourceConverter::convert(lexicalGlobalObject, value, std::forward(exceptionThrower)); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const U& value) + { + return toJS(&lexicalGlobalObject, &globalObject, Detail::getPtrOrRef(value)); + } + + template + static JSC::JSValue convertNewlyCreated(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, U&& value) + { + return convert(lexicalGlobalObject, globalObject, std::forward(value)); + } +}; + +template<> struct Converter : DefaultConverter { + using WrapperType = JSC::JSUint16Array; + using ReturnType = RefPtr; + + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + return Detail::BufferSourceConverter::convert(lexicalGlobalObject, value, std::forward(exceptionThrower)); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const U& value) + { + return toJS(&lexicalGlobalObject, &globalObject, Detail::getPtrOrRef(value)); + } +}; + +template<> struct Converter : DefaultConverter { + using WrapperType = JSC::JSUint32Array; + using ReturnType = RefPtr; + + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + return Detail::BufferSourceConverter::convert(lexicalGlobalObject, value, std::forward(exceptionThrower)); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const U& value) + { + return toJS(&lexicalGlobalObject, &globalObject, Detail::getPtrOrRef(value)); + } +}; + +template<> struct Converter : DefaultConverter { + using WrapperType = JSC::JSUint8ClampedArray; + using ReturnType = RefPtr; + + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + return Detail::BufferSourceConverter::convert(lexicalGlobalObject, value, std::forward(exceptionThrower)); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const U& value) + { + return toJS(&lexicalGlobalObject, &globalObject, Detail::getPtrOrRef(value)); + } +}; + +template<> struct Converter : DefaultConverter { + using WrapperType = JSC::JSFloat32Array; + using ReturnType = RefPtr; + + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + return Detail::BufferSourceConverter::convert(lexicalGlobalObject, value, std::forward(exceptionThrower)); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const U& value) + { + return toJS(&lexicalGlobalObject, &globalObject, Detail::getPtrOrRef(value)); + } +}; + +template<> struct Converter : DefaultConverter { + using WrapperType = JSC::JSFloat64Array; + using ReturnType = RefPtr; + + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + return Detail::BufferSourceConverter::convert(lexicalGlobalObject, value, std::forward(exceptionThrower)); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const U& value) + { + return toJS(&lexicalGlobalObject, &globalObject, Detail::getPtrOrRef(value)); + } +}; + +template<> struct Converter : DefaultConverter { + using WrapperType = JSC::JSBigInt64Array; + using ReturnType = RefPtr; + + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + return Detail::BufferSourceConverter::convert(lexicalGlobalObject, value, std::forward(exceptionThrower)); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const U& value) + { + return toJS(&lexicalGlobalObject, &globalObject, Detail::getPtrOrRef(value)); + } +}; + +template<> struct Converter : DefaultConverter { + using WrapperType = JSC::JSBigUint64Array; + using ReturnType = RefPtr; + + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + return Detail::BufferSourceConverter::convert(lexicalGlobalObject, value, std::forward(exceptionThrower)); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const U& value) + { + return toJS(&lexicalGlobalObject, &globalObject, Detail::getPtrOrRef(value)); + } +}; + +template<> struct Converter : DefaultConverter { + using WrapperType = JSC::JSArrayBufferView; + using ReturnType = RefPtr; + + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + return Detail::BufferSourceConverter::convert(lexicalGlobalObject, value, std::forward(exceptionThrower)); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const U& value) + { + return toJS(&lexicalGlobalObject, &globalObject, Detail::getPtrOrRef(value)); + } +}; + +template +struct Converter> : DefaultConverter { + using ConverterType = Converter; + using WrapperType = typename ConverterType::WrapperType; + using ReturnType = typename ConverterType::ReturnType; + + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + return Detail::BufferSourceConverter::convert(lexicalGlobalObject, value, std::forward(exceptionThrower)); + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertCallbacks.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertCallbacks.h new file mode 100644 index 0000000000..c8ce13c14d --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertCallbacks.h @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include "JSDOMConvertBase.h" +#include "JSDOMGlobalObject.h" + +namespace WebCore { + +template struct Converter> : DefaultConverter> { + + static constexpr bool conversionHasSideEffects = false; + + template + static RefPtr convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + JSC::VM& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + + if (!value.isCallable(vm)) { + exceptionThrower(lexicalGlobalObject, scope); + return nullptr; + } + + return T::create(vm, JSC::asObject(value)); + } +}; + +template struct JSConverter> { + static constexpr bool needsState = false; + static constexpr bool needsGlobalObject = false; + + template + static JSC::JSValue convert(const U& value) + { + return toJS(Detail::getPtrOrRef(value)); + } + + template + static JSC::JSValue convertNewlyCreated(U&& value) + { + return toJSNewlyCreated(std::forward(value)); + } +}; + + +template struct Converter> : DefaultConverter> { + template + static RefPtr convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + JSC::VM& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + + if (!value.isObject()) { + exceptionThrower(lexicalGlobalObject, scope); + return nullptr; + } + + return T::create(vm, JSC::asObject(value)); + } +}; + +template struct JSConverter> { + static constexpr bool needsState = false; + static constexpr bool needsGlobalObject = false; + + template + static JSC::JSValue convert(const U& value) + { + return toJS(Detail::getPtrOrRef(value)); + } + + template + static JSC::JSValue convertNewlyCreated(U&& value) + { + return toJSNewlyCreated(std::forward(value)); + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertDate.cpp b/src/javascript/jsc/bindings/webcore/JSDOMConvertDate.cpp new file mode 100644 index 0000000000..739be11efd --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertDate.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2004-2011, 2013, 2016 Apple Inc. All rights reserved. + * Copyright (C) 2007 Samuel Weinig + * Copyright (C) 2013 Michael Pruett + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSDOMConvertDate.h" + +#include "JavaScriptCore/DateInstance.h" +#include "JavaScriptCore/HeapInlines.h" +#include "JavaScriptCore/JSCJSValueInlines.h" +#include "JavaScriptCore/JSGlobalObject.h" + +namespace WebCore { +using namespace JSC; + +JSValue jsDate(JSGlobalObject& lexicalGlobalObject, WallTime value) +{ + return DateInstance::create(lexicalGlobalObject.vm(), lexicalGlobalObject.dateStructure(), value.secondsSinceEpoch().milliseconds()); +} + +WallTime valueToDate(JSC::JSGlobalObject& lexicalGlobalObject, JSValue value) +{ + double milliseconds = std::numeric_limits::quiet_NaN(); + + auto& vm = lexicalGlobalObject.vm(); + if (value.inherits(vm)) + milliseconds = jsCast(value)->internalNumber(); + else if (value.isNumber()) + milliseconds = value.asNumber(); + else if (value.isString()) + milliseconds = vm.dateCache.parseDate(&lexicalGlobalObject, vm, value.getString(&lexicalGlobalObject)); + + return WallTime::fromRawSeconds(Seconds::fromMilliseconds(milliseconds).value()); +} + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertDate.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertDate.h new file mode 100644 index 0000000000..de0a9f770a --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertDate.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include "JSDOMConvertBase.h" +#include "JavaScriptCore/JSGlobalObject.h" +#include "wtf/WallTime.h" + +namespace WebCore { + +JSC::JSValue jsDate(JSC::JSGlobalObject&, WallTime value); +WallTime valueToDate(JSC::JSGlobalObject&, JSC::JSValue); // NaN if the value can't be converted to a date. + +template<> struct Converter : DefaultConverter { + static WallTime convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return valueToDate(lexicalGlobalObject, value); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = false; + + // FIXME: This should be taking a JSDOMGlobalObject and passing it to jsDate. + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, WallTime value) + { + return jsDate(lexicalGlobalObject, value); + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertDictionary.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertDictionary.h new file mode 100644 index 0000000000..94173b16fd --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertDictionary.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include "JSDOMConvertBase.h" + +namespace WebCore { + +// Specialized by generated code for IDL dictionary conversion. +template T convertDictionary(JSC::JSGlobalObject&, JSC::JSValue); + + +template struct Converter> : DefaultConverter> { + using ReturnType = T; + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return convertDictionary(lexicalGlobalObject, value); + } +}; + +template struct JSConverter> { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const T& dictionary) + { + return convertDictionaryToJS(lexicalGlobalObject, globalObject, dictionary); + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertEnumeration.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertEnumeration.h new file mode 100644 index 0000000000..d458e4aa8c --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertEnumeration.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include "JSDOMConvertBase.h" +#include "JSDOMGlobalObject.h" + +namespace WebCore { + +// Specialized by generated code for IDL enumeration conversion. +template std::optional parseEnumeration(JSC::JSGlobalObject&, JSC::JSValue); +template const char* expectedEnumerationValues(); + +// Specialized by generated code for IDL enumeration conversion. +template JSC::JSString* convertEnumerationToJS(JSC::JSGlobalObject&, T); + + +template struct Converter> : DefaultConverter> { + template + static T convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + + auto result = parseEnumeration(lexicalGlobalObject, value); + RETURN_IF_EXCEPTION(throwScope, { }); + + if (UNLIKELY(!result)) { + exceptionThrower(lexicalGlobalObject, throwScope); + return { }; + } + return result.value(); + } +}; + +template struct JSConverter> { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, T value) + { + return convertEnumerationToJS(lexicalGlobalObject, value); + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertEventListener.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertEventListener.h new file mode 100644 index 0000000000..09d0cbb6e1 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertEventListener.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include "JSDOMConvertBase.h" + +namespace WebCore { + +template struct Converter> : DefaultConverter> { + using ReturnType = RefPtr; + + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, JSC::JSObject& thisObject, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + auto scope = DECLARE_THROW_SCOPE(JSC::getVM(&lexicalGlobalObject)); + + if (UNLIKELY(!value.isObject())) { + exceptionThrower(lexicalGlobalObject, scope); + return nullptr; + } + + bool isAttribute = false; + return T::create(*asObject(value), thisObject, isAttribute, currentWorld(lexicalGlobalObject)); + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertInterface.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertInterface.h new file mode 100644 index 0000000000..3492764678 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertInterface.h @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "root.h" + +#include "IDLTypes.h" +#include "JSDOMConvertBase.h" +#include "JavaScriptCore/Error.h" + +namespace WebCore { + +template struct JSDOMWrapperConverterTraits; + +template +struct JSToWrappedOverloader { + using ReturnType = typename JSDOMWrapperConverterTraits::ToWrappedReturnType; + using WrapperType = typename JSDOMWrapperConverterTraits::WrapperClass; + + static ReturnType toWrapped(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return WrapperType::toWrapped(JSC::getVM(&lexicalGlobalObject), value); + } +}; + +template +struct JSToWrappedOverloader::needsState>::type> { + using ReturnType = typename JSDOMWrapperConverterTraits::ToWrappedReturnType; + using WrapperType = typename JSDOMWrapperConverterTraits::WrapperClass; + + static ReturnType toWrapped(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return WrapperType::toWrapped(lexicalGlobalObject, value); + } +}; + +template struct Converter> : DefaultConverter> { + using ReturnType = typename JSDOMWrapperConverterTraits::ToWrappedReturnType; + using WrapperType = typename JSDOMWrapperConverterTraits::WrapperClass; + + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + ReturnType object = JSToWrappedOverloader::toWrapped(lexicalGlobalObject, value); + if (UNLIKELY(!object)) + exceptionThrower(lexicalGlobalObject, scope); + return object; + } +}; + +template struct JSConverter> { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const U& value) + { + return toJS(&lexicalGlobalObject, &globalObject, Detail::getPtrOrRef(value)); + } + + template + static JSC::JSValue convertNewlyCreated(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, U&& value) + { + return toJSNewlyCreated(&lexicalGlobalObject, &globalObject, std::forward(value)); + } +}; + +template struct VariadicConverter> { + using Item = std::reference_wrapper; + + static std::optional convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + auto* result = Converter>::convert(lexicalGlobalObject, value); + if (!result) + return std::nullopt; + return std::optional { *result }; + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertJSON.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertJSON.h new file mode 100644 index 0000000000..9a289ef6c4 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertJSON.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include "JSDOMConvertBase.h" +#include "JavaScriptCore/JSONObject.h" + +namespace WebCore { + +template<> struct Converter : DefaultConverter { + static String convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return JSC::JSONStringify(&lexicalGlobalObject, value, 0); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const String& value) + { + return JSC::JSONParse(&lexicalGlobalObject, value); + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertNull.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertNull.h new file mode 100644 index 0000000000..b132825d2d --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertNull.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include "JSDOMConvertBase.h" + +namespace WebCore { + +template<> struct Converter : DefaultConverter { + static std::nullptr_t convert(JSC::JSGlobalObject&, JSC::JSValue) + { + return nullptr; + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = false; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(std::nullptr_t) + { + return JSC::jsNull(); + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertNullable.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertNullable.h new file mode 100644 index 0000000000..a3e4b5cc41 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertNullable.h @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include "JSDOMConvertAny.h" +#include "JSDOMConvertInterface.h" +#include "JSDOMConvertNumbers.h" +#include "JSDOMConvertStrings.h" + +namespace WebCore { + +namespace Detail { + +template +struct NullableConversionType; + +template +struct NullableConversionType { + using Type = typename IDLNullable::ImplementationType; +}; + +template +struct NullableConversionType> { + using Type = typename Converter>::ReturnType; +}; + +template<> +struct NullableConversionType { + using Type = typename Converter::ReturnType; +}; + +} + +template struct Converter> : DefaultConverter> { + using ReturnType = typename Detail::NullableConversionType::Type; + + // 1. If Type(V) is not Object, and the conversion to an IDL value is being performed + // due to V being assigned to an attribute whose type is a nullable callback function + // that is annotated with [LegacyTreatNonObjectAsNull], then return the IDL nullable + // type T? value null. + // + // NOTE: Handled elsewhere. + // + // 2. Otherwise, if V is null or undefined, then return the IDL nullable type T? value null. + // 3. Otherwise, return the result of converting V using the rules for the inner IDL type T. + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + if (value.isUndefinedOrNull()) + return T::nullValue(); + return Converter::convert(lexicalGlobalObject, value); + } + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, JSC::JSObject& thisObject) + { + if (value.isUndefinedOrNull()) + return T::nullValue(); + return Converter::convert(lexicalGlobalObject, value, thisObject); + } + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, JSDOMGlobalObject& globalObject) + { + if (value.isUndefinedOrNull()) + return T::nullValue(); + return Converter::convert(lexicalGlobalObject, value, globalObject); + } + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower) + { + if (value.isUndefinedOrNull()) + return T::nullValue(); + return Converter::convert(lexicalGlobalObject, value, std::forward(exceptionThrower)); + } + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, JSC::JSObject& thisObject, ExceptionThrower&& exceptionThrower) + { + if (value.isUndefinedOrNull()) + return T::nullValue(); + return Converter::convert(lexicalGlobalObject, value, thisObject, std::forward(exceptionThrower)); + } + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, JSDOMGlobalObject& globalObject, ExceptionThrower&& exceptionThrower) + { + if (value.isUndefinedOrNull()) + return T::nullValue(); + return Converter::convert(lexicalGlobalObject, value, globalObject, std::forward(exceptionThrower)); + } +}; + +template struct JSConverter> { + using ImplementationType = typename IDLNullable::ImplementationType; + + static constexpr bool needsState = JSConverter::needsState; + static constexpr bool needsGlobalObject = JSConverter::needsGlobalObject; + + template + static JSC::JSValue convert(U&& value) + { + if (T::isNullValue(value)) + return JSC::jsNull(); + return JSConverter::convert(T::extractValueFromNullable(value)); + } + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, U&& value) + { + if (T::isNullValue(value)) + return JSC::jsNull(); + return JSConverter::convert(lexicalGlobalObject, T::extractValueFromNullable(value)); + } + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, U&& value) + { + if (T::isNullValue(value)) + return JSC::jsNull(); + return JSConverter::convert(lexicalGlobalObject, globalObject, T::extractValueFromNullable(value)); + } + + template + static JSC::JSValue convertNewlyCreated(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, U&& value) + { + if (T::isNullValue(value)) + return JSC::jsNull(); + return JSConverter::convert(lexicalGlobalObject, globalObject, T::extractValueFromNullable(value)); + } +}; + + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertNumbers.cpp b/src/javascript/jsc/bindings/webcore/JSDOMConvertNumbers.cpp new file mode 100644 index 0000000000..438d327237 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertNumbers.cpp @@ -0,0 +1,379 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2004-2011, 2013, 2016 Apple Inc. All rights reserved. + * Copyright (C) 2007 Samuel Weinig + * Copyright (C) 2013 Michael Pruett + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSDOMConvertNumbers.h" + +#include "JSDOMExceptionHandling.h" +#include "JavaScriptCore/HeapInlines.h" +#include "JavaScriptCore/JSCJSValueInlines.h" +#include "wtf/MathExtras.h" +#include "wtf/text/StringConcatenateNumbers.h" +#include "wtf/text/WTFString.h" + +namespace WebCore { +using namespace JSC; + +enum class IntegerConversionConfiguration { Normal, + EnforceRange, + Clamp }; + +static const int32_t kMaxInt32 = 0x7fffffff; +static const int32_t kMinInt32 = -kMaxInt32 - 1; +static const uint32_t kMaxUInt32 = 0xffffffffU; +static const int64_t kJSMaxInteger = 0x20000000000000LL - 1; // 2^53 - 1, largest integer exactly representable in ECMAScript. + +static String rangeErrorString(double value, double min, double max) +{ + return makeString("Value ", value, " is outside the range [", min, ", ", max, ']'); +} + +static double enforceRange(JSGlobalObject& lexicalGlobalObject, double x, double minimum, double maximum) +{ + VM& vm = lexicalGlobalObject.vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + if (std::isnan(x) || std::isinf(x)) { + throwTypeError(&lexicalGlobalObject, scope, rangeErrorString(x, minimum, maximum)); + return 0; + } + x = trunc(x); + if (x < minimum || x > maximum) { + throwTypeError(&lexicalGlobalObject, scope, rangeErrorString(x, minimum, maximum)); + return 0; + } + return x; +} + +namespace { + +template +struct IntTypeLimits { +}; + +template<> +struct IntTypeLimits { + static const int8_t minValue = -128; + static const int8_t maxValue = 127; + static const unsigned numberOfValues = 256; // 2^8 +}; + +template<> +struct IntTypeLimits { + static const uint8_t maxValue = 255; + static const unsigned numberOfValues = 256; // 2^8 +}; + +template<> +struct IntTypeLimits { + static const short minValue = -32768; + static const short maxValue = 32767; + static const unsigned numberOfValues = 65536; // 2^16 +}; + +template<> +struct IntTypeLimits { + static const unsigned short maxValue = 65535; + static const unsigned numberOfValues = 65536; // 2^16 +}; + +} + +template +static inline T toSmallerInt(JSGlobalObject& lexicalGlobalObject, JSValue value) +{ + VM& vm = lexicalGlobalObject.vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + static_assert(std::is_signed::value && std::is_integral::value, "Should only be used for signed integral types"); + + typedef IntTypeLimits LimitsTrait; + // Fast path if the value is already a 32-bit signed integer in the right range. + if (value.isInt32()) { + int32_t d = value.asInt32(); + if (d >= LimitsTrait::minValue && d <= LimitsTrait::maxValue) + return static_cast(d); + switch (configuration) { + case IntegerConversionConfiguration::Normal: + break; + case IntegerConversionConfiguration::EnforceRange: + throwTypeError(&lexicalGlobalObject, scope); + return 0; + case IntegerConversionConfiguration::Clamp: + return d < LimitsTrait::minValue ? LimitsTrait::minValue : LimitsTrait::maxValue; + } + d %= LimitsTrait::numberOfValues; + return static_cast(d > LimitsTrait::maxValue ? d - LimitsTrait::numberOfValues : d); + } + + double x = value.toNumber(&lexicalGlobalObject); + RETURN_IF_EXCEPTION(scope, 0); + + switch (configuration) { + case IntegerConversionConfiguration::Normal: + break; + case IntegerConversionConfiguration::EnforceRange: + return enforceRange(lexicalGlobalObject, x, LimitsTrait::minValue, LimitsTrait::maxValue); + case IntegerConversionConfiguration::Clamp: + return std::isnan(x) ? 0 : clampTo(x); + } + + if (std::isnan(x) || std::isinf(x) || !x) + return 0; + + x = x < 0 ? -floor(fabs(x)) : floor(fabs(x)); + x = fmod(x, LimitsTrait::numberOfValues); + + return static_cast(x > LimitsTrait::maxValue ? x - LimitsTrait::numberOfValues : x); +} + +template +static inline T toSmallerUInt(JSGlobalObject& lexicalGlobalObject, JSValue value) +{ + VM& vm = lexicalGlobalObject.vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + static_assert(std::is_unsigned::value && std::is_integral::value, "Should only be used for unsigned integral types"); + + typedef IntTypeLimits LimitsTrait; + // Fast path if the value is already a 32-bit unsigned integer in the right range. + if (value.isUInt32()) { + uint32_t d = value.asUInt32(); + if (d <= LimitsTrait::maxValue) + return static_cast(d); + switch (configuration) { + case IntegerConversionConfiguration::Normal: + return static_cast(d); + case IntegerConversionConfiguration::EnforceRange: + throwTypeError(&lexicalGlobalObject, scope); + return 0; + case IntegerConversionConfiguration::Clamp: + return LimitsTrait::maxValue; + } + } + + double x = value.toNumber(&lexicalGlobalObject); + RETURN_IF_EXCEPTION(scope, 0); + + switch (configuration) { + case IntegerConversionConfiguration::Normal: + break; + case IntegerConversionConfiguration::EnforceRange: + return enforceRange(lexicalGlobalObject, x, 0, LimitsTrait::maxValue); + case IntegerConversionConfiguration::Clamp: + return std::isnan(x) ? 0 : clampTo(x); + } + + if (std::isnan(x) || std::isinf(x) || !x) + return 0; + + x = x < 0 ? -floor(fabs(x)) : floor(fabs(x)); + x = fmod(x, LimitsTrait::numberOfValues); + if (x < 0) + x += LimitsTrait::numberOfValues; + return static_cast(x); +} + +template<> int8_t convertToIntegerEnforceRange(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + return toSmallerInt(lexicalGlobalObject, value); +} + +template<> uint8_t convertToIntegerEnforceRange(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + return toSmallerUInt(lexicalGlobalObject, value); +} + +template<> int8_t convertToIntegerClamp(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + return toSmallerInt(lexicalGlobalObject, value); +} + +template<> uint8_t convertToIntegerClamp(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + return toSmallerUInt(lexicalGlobalObject, value); +} + +template<> int8_t convertToInteger(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + return toSmallerInt(lexicalGlobalObject, value); +} + +template<> uint8_t convertToInteger(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + return toSmallerUInt(lexicalGlobalObject, value); +} + +template<> int16_t convertToIntegerEnforceRange(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + return toSmallerInt(lexicalGlobalObject, value); +} + +template<> uint16_t convertToIntegerEnforceRange(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + return toSmallerUInt(lexicalGlobalObject, value); +} + +template<> int16_t convertToIntegerClamp(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + return toSmallerInt(lexicalGlobalObject, value); +} + +template<> uint16_t convertToIntegerClamp(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + return toSmallerUInt(lexicalGlobalObject, value); +} + +template<> int16_t convertToInteger(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + return toSmallerInt(lexicalGlobalObject, value); +} + +template<> uint16_t convertToInteger(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + return toSmallerUInt(lexicalGlobalObject, value); +} + +template<> int32_t convertToIntegerEnforceRange(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + if (value.isInt32()) + return value.asInt32(); + + VM& vm = lexicalGlobalObject.vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + double x = value.toNumber(&lexicalGlobalObject); + RETURN_IF_EXCEPTION(scope, 0); + return enforceRange(lexicalGlobalObject, x, kMinInt32, kMaxInt32); +} + +template<> uint32_t convertToIntegerEnforceRange(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + if (value.isUInt32()) + return value.asUInt32(); + + VM& vm = lexicalGlobalObject.vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + double x = value.toNumber(&lexicalGlobalObject); + RETURN_IF_EXCEPTION(scope, 0); + return enforceRange(lexicalGlobalObject, x, 0, kMaxUInt32); +} + +template<> int32_t convertToIntegerClamp(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + if (value.isInt32()) + return value.asInt32(); + + double x = value.toNumber(&lexicalGlobalObject); + return std::isnan(x) ? 0 : clampTo(x); +} + +template<> uint32_t convertToIntegerClamp(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + if (value.isUInt32()) + return value.asUInt32(); + + double x = value.toNumber(&lexicalGlobalObject); + return std::isnan(x) ? 0 : clampTo(x); +} + +template<> int32_t convertToInteger(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + return value.toInt32(&lexicalGlobalObject); +} + +template<> uint32_t convertToInteger(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + return value.toUInt32(&lexicalGlobalObject); +} + +template<> int64_t convertToIntegerEnforceRange(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + if (value.isInt32()) + return value.asInt32(); + + VM& vm = lexicalGlobalObject.vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + double x = value.toNumber(&lexicalGlobalObject); + RETURN_IF_EXCEPTION(scope, 0); + return enforceRange(lexicalGlobalObject, x, -kJSMaxInteger, kJSMaxInteger); +} + +template<> uint64_t convertToIntegerEnforceRange(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + if (value.isUInt32()) + return value.asUInt32(); + + VM& vm = lexicalGlobalObject.vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + double x = value.toNumber(&lexicalGlobalObject); + RETURN_IF_EXCEPTION(scope, 0); + return enforceRange(lexicalGlobalObject, x, 0, kJSMaxInteger); +} + +template<> int64_t convertToIntegerClamp(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + if (value.isInt32()) + return value.asInt32(); + + double x = value.toNumber(&lexicalGlobalObject); + return std::isnan(x) ? 0 : static_cast(std::min(std::max(x, -kJSMaxInteger), kJSMaxInteger)); +} + +template<> uint64_t convertToIntegerClamp(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + if (value.isUInt32()) + return value.asUInt32(); + + double x = value.toNumber(&lexicalGlobalObject); + return std::isnan(x) ? 0 : static_cast(std::min(std::max(x, 0), kJSMaxInteger)); +} + +template<> int64_t convertToInteger(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + if (value.isInt32()) + return value.asInt32(); + + double x = value.toNumber(&lexicalGlobalObject); + + // Map NaNs and +/-Infinity to 0; convert finite values modulo 2^64. + unsigned long long n; + doubleToInteger(x, n); + return n; +} + +template<> uint64_t convertToInteger(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ + if (value.isUInt32()) + return value.asUInt32(); + + double x = value.toNumber(&lexicalGlobalObject); + + // Map NaNs and +/-Infinity to 0; convert finite values modulo 2^64. + unsigned long long n; + doubleToInteger(x, n); + return n; +} + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertNumbers.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertNumbers.h new file mode 100644 index 0000000000..399a85ebbe --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertNumbers.h @@ -0,0 +1,409 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include "JSDOMConvertBase.h" +#include "JSDOMExceptionHandling.h" +#include "JavaScriptCore/JSCJSValueInlines.h" +#include "JavaScriptCore/PureNaN.h" + +namespace WebCore { + +// The following functions convert values to integers as per the WebIDL specification. +// The conversion fails if the value cannot be converted to a number or, if EnforceRange is specified, +// the value is outside the range of the destination integer type. + +template T convertToInteger(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT int8_t convertToInteger(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT uint8_t convertToInteger(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT int16_t convertToInteger(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT uint16_t convertToInteger(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT int32_t convertToInteger(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT uint32_t convertToInteger(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT int64_t convertToInteger(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT uint64_t convertToInteger(JSC::JSGlobalObject&, JSC::JSValue); + +template T convertToIntegerEnforceRange(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT int8_t convertToIntegerEnforceRange(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT uint8_t convertToIntegerEnforceRange(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT int16_t convertToIntegerEnforceRange(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT uint16_t convertToIntegerEnforceRange(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT int32_t convertToIntegerEnforceRange(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT uint32_t convertToIntegerEnforceRange(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT int64_t convertToIntegerEnforceRange(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT uint64_t convertToIntegerEnforceRange(JSC::JSGlobalObject&, JSC::JSValue); + +template T convertToIntegerClamp(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT int8_t convertToIntegerClamp(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT uint8_t convertToIntegerClamp(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT int16_t convertToIntegerClamp(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT uint16_t convertToIntegerClamp(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT int32_t convertToIntegerClamp(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT uint32_t convertToIntegerClamp(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT int64_t convertToIntegerClamp(JSC::JSGlobalObject&, JSC::JSValue); +template<> WEBCORE_EXPORT uint64_t convertToIntegerClamp(JSC::JSGlobalObject&, JSC::JSValue); + +// MARK: - +// MARK: Integer types + +template<> struct Converter : DefaultConverter { + static int8_t convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return convertToInteger(lexicalGlobalObject, value); + } +}; + +template<> struct JSConverter { + using Type = typename IDLByte::ImplementationType; + + static constexpr bool needsState = false; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(Type value) + { + return JSC::jsNumber(value); + } +}; + +template<> struct Converter : DefaultConverter { + static uint8_t convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return convertToInteger(lexicalGlobalObject, value); + } +}; + +template<> struct JSConverter { + using Type = typename IDLOctet::ImplementationType; + + static constexpr bool needsState = false; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(Type value) + { + return JSC::jsNumber(value); + } +}; + +template<> struct Converter : DefaultConverter { + static int16_t convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return convertToInteger(lexicalGlobalObject, value); + } +}; + +template<> struct JSConverter { + using Type = typename IDLShort::ImplementationType; + + static constexpr bool needsState = false; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(Type value) + { + return JSC::jsNumber(value); + } +}; + +template<> struct Converter : DefaultConverter { + static uint16_t convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return convertToInteger(lexicalGlobalObject, value); + } +}; + +template<> struct JSConverter { + using Type = typename IDLUnsignedShort::ImplementationType; + + static constexpr bool needsState = false; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(Type value) + { + return JSC::jsNumber(value); + } +}; + +template<> struct Converter : DefaultConverter { + static inline int32_t convert(JSC::JSGlobalObject&, JSC::ThrowScope&, double number) + { + return JSC::toInt32(number); + } + + static int32_t convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return convertToInteger(lexicalGlobalObject, value); + } +}; + +template<> struct JSConverter { + using Type = typename IDLLong::ImplementationType; + + static constexpr bool needsState = false; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(Type value) + { + return JSC::jsNumber(value); + } +}; + +template<> struct Converter : DefaultConverter { + static uint32_t convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return convertToInteger(lexicalGlobalObject, value); + } +}; + +template<> struct JSConverter { + using Type = typename IDLUnsignedLong::ImplementationType; + + static constexpr bool needsState = false; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(Type value) + { + return JSC::jsNumber(value); + } +}; + +template<> struct Converter : DefaultConverter { + static int64_t convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return convertToInteger(lexicalGlobalObject, value); + } +}; + +template<> struct JSConverter { + using Type = typename IDLLongLong::ImplementationType; + + static constexpr bool needsState = false; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(Type value) + { + return JSC::jsNumber(value); + } +}; + +template<> struct Converter : DefaultConverter { + static uint64_t convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return convertToInteger(lexicalGlobalObject, value); + } +}; + +template<> struct JSConverter { + using Type = typename IDLUnsignedLongLong::ImplementationType; + + static constexpr bool needsState = false; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(Type value) + { + return JSC::jsNumber(value); + } +}; + +// MARK: - +// MARK: Annotated Integer types + +template struct Converter> : DefaultConverter> { + using ReturnType = typename IDLClampAdaptor::ImplementationType; + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return convertToIntegerClamp(lexicalGlobalObject, value); + } +}; + +template struct JSConverter> { + using Type = typename IDLClampAdaptor::ImplementationType; + + static constexpr bool needsState = false; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(Type value) + { + return JSConverter::convert(value); + } +}; + +template struct Converter> : DefaultConverter> { + using ReturnType = typename IDLEnforceRangeAdaptor::ImplementationType; + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return convertToIntegerEnforceRange(lexicalGlobalObject, value); + } +}; + +template struct JSConverter> { + using Type = typename IDLEnforceRangeAdaptor::ImplementationType; + + static constexpr bool needsState = false; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(Type value) + { + return JSConverter::convert(value); + } +}; + +// MARK: - +// MARK: Floating point types + +template<> struct Converter : DefaultConverter { + + static inline float convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope, double number) + { + if (UNLIKELY(!std::isfinite(number))) + throwNonFiniteTypeError(lexicalGlobalObject, scope); + return static_cast(number); + } + + static float convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + JSC::VM& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + double number = value.toNumber(&lexicalGlobalObject); + RETURN_IF_EXCEPTION(scope, 0.0); + if (UNLIKELY(number < std::numeric_limits::lowest() || number > std::numeric_limits::max())) + throwTypeError(&lexicalGlobalObject, scope, "The provided value is outside the range of a float"); + if (UNLIKELY(!std::isfinite(number))) + throwNonFiniteTypeError(lexicalGlobalObject, scope); + return static_cast(number); + } +}; + +template<> struct JSConverter { + using Type = typename IDLFloat::ImplementationType; + + static constexpr bool needsState = false; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(Type value) + { + return JSC::jsNumber(value); + } +}; + +template<> struct Converter : DefaultConverter { + static inline float convert(JSC::JSGlobalObject&, JSC::ThrowScope&, double number) + { + return static_cast(number); + } + + static float convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + JSC::VM& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + double number = value.toNumber(&lexicalGlobalObject); + RETURN_IF_EXCEPTION(scope, 0.0); + + if (UNLIKELY(number < std::numeric_limits::lowest())) + return -std::numeric_limits::infinity(); + if (UNLIKELY(number > std::numeric_limits::max())) + return std::numeric_limits::infinity(); + return static_cast(number); + } +}; + +template<> struct JSConverter { + using Type = typename IDLUnrestrictedFloat::ImplementationType; + + static constexpr bool needsState = false; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(Type value) + { + return JSC::jsNumber(value); + } +}; + +template<> struct Converter : DefaultConverter { + static inline double convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope, double number) + { + if (UNLIKELY(!std::isfinite(number))) + throwNonFiniteTypeError(lexicalGlobalObject, scope); + return number; + } + + static double convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + JSC::VM& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + double number = value.toNumber(&lexicalGlobalObject); + RETURN_IF_EXCEPTION(scope, 0.0); + if (UNLIKELY(!std::isfinite(number))) + throwNonFiniteTypeError(lexicalGlobalObject, scope); + return number; + } +}; + +template<> struct JSConverter { + using Type = typename IDLDouble::ImplementationType; + + static constexpr bool needsState = false; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(Type value) + { + ASSERT(!std::isnan(value)); + return JSC::jsNumber(value); + } +}; + +template<> struct Converter : DefaultConverter { + static inline double convert(JSC::JSGlobalObject&, JSC::ThrowScope&, double number) + { + return number; + } + + static double convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return value.toNumber(&lexicalGlobalObject); + } +}; + +template<> struct JSConverter { + using Type = typename IDLUnrestrictedDouble::ImplementationType; + + static constexpr bool needsState = false; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(Type value) + { + return JSC::jsNumber(JSC::purifyNaN(value)); + } + + // Add overload for MediaTime. + static JSC::JSValue convert(const MediaTime& value) + { + return JSC::jsNumber(JSC::purifyNaN(value.toDouble())); + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertObject.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertObject.h new file mode 100644 index 0000000000..24dacac9e4 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertObject.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include "JSDOMConvertBase.h" +#include "JavaScriptCore/StrongInlines.h" + +namespace WebCore { + +template<> struct Converter : DefaultConverter { + + static constexpr bool conversionHasSideEffects = false; + + template + static JSC::Strong convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + JSC::VM& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + + if (!value.isObject()) { + exceptionThrower(lexicalGlobalObject, scope); + return {}; + } + + return { vm, JSC::asObject(value) }; + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = false; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(const JSC::Strong& value) + { + return value.get(); + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertPromise.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertPromise.h new file mode 100644 index 0000000000..a0051c3836 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertPromise.h @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2017 Yusuke Suzuki . + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include "JSDOMConvertBase.h" +#include "JSDOMPromise.h" +#include "WorkerGlobalScope.h" + +namespace WebCore { + +template struct Converter> : DefaultConverter> { + using ReturnType = RefPtr; + + // https://webidl.spec.whatwg.org/#es-promise + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + JSC::VM& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + auto* globalObject = JSC::jsDynamicCast(vm, &lexicalGlobalObject); + if (!globalObject) + return nullptr; + + // 1. Let resolve be the original value of %Promise%.resolve. + // 2. Let promise be the result of calling resolve with %Promise% as the this value and V as the single argument value. + auto* promise = JSC::JSPromise::resolvedPromise(globalObject, value); + if (scope.exception()) { + auto* scriptExecutionContext = globalObject->scriptExecutionContext(); + if (is(scriptExecutionContext)) { + auto* scriptController = downcast(*scriptExecutionContext).script(); + bool terminatorCausedException = vm.isTerminationException(scope.exception()); + if (terminatorCausedException || (scriptController && scriptController->isTerminatingExecution())) { + scriptController->forbidExecution(); + return nullptr; + } + } + exceptionThrower(lexicalGlobalObject, scope); + return nullptr; + } + ASSERT(promise); + + // 3. Return the IDL promise type value that is a reference to the same object as promise. + return DOMPromise::create(*globalObject, *promise); + } +}; + +template struct JSConverter> { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + static JSC::JSValue convert(JSC::JSGlobalObject&, JSDOMGlobalObject&, DOMPromise& promise) + { + return promise.promise(); + } + + template class U> + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, U& promiseProxy) + { + return promiseProxy.promise(lexicalGlobalObject, globalObject); + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertRecord.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertRecord.h new file mode 100644 index 0000000000..736fe7303f --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertRecord.h @@ -0,0 +1,191 @@ +/* + * Copyright (C) 2016-2019 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include "JSDOMConvertStrings.h" +#include "JSDOMGlobalObject.h" +#include "JavaScriptCore/ObjectConstructor.h" + +namespace WebCore { + +namespace Detail { + +template +struct IdentifierConverter; + +template<> struct IdentifierConverter { + static String convert(JSC::JSGlobalObject& lexicalGlobalObject, const JSC::Identifier& identifier) + { + return identifierToString(lexicalGlobalObject, identifier); + } +}; + +template<> struct IdentifierConverter { + static String convert(JSC::JSGlobalObject& lexicalGlobalObject, const JSC::Identifier& identifier) + { + return identifierToByteString(lexicalGlobalObject, identifier); + } +}; + +template<> struct IdentifierConverter { + static String convert(JSC::JSGlobalObject& lexicalGlobalObject, const JSC::Identifier& identifier) + { + return identifierToUSVString(lexicalGlobalObject, identifier); + } +}; + +} + +template struct Converter> : DefaultConverter> { + using ReturnType = typename IDLRecord::ImplementationType; + using KeyType = typename K::ImplementationType; + using ValueType = typename V::ImplementationType; + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, JSDOMGlobalObject& globalObject) + { + return convertRecord(lexicalGlobalObject, value, globalObject); + } + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return convertRecord(lexicalGlobalObject, value); + } + +private: + template + static ReturnType convertRecord(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, Args... args) + { + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + + // 1. Let result be a new empty instance of record. + // 2. If Type(O) is Undefined or Null, return result. + if (value.isUndefinedOrNull()) + return {}; + + // 3. If Type(O) is not Object, throw a TypeError. + if (!value.isObject()) { + throwTypeError(&lexicalGlobalObject, scope); + return {}; + } + + JSC::JSObject* object = JSC::asObject(value); + + ReturnType result; + HashMap resultMap; + + // 4. Let keys be ? O.[[OwnPropertyKeys]](). + JSC::PropertyNameArray keys(vm, JSC::PropertyNameMode::StringsAndSymbols, JSC::PrivateSymbolMode::Exclude); + object->methodTable(vm)->getOwnPropertyNames(object, &lexicalGlobalObject, keys, JSC::DontEnumPropertiesMode::Include); + RETURN_IF_EXCEPTION(scope, {}); + + // 5. Repeat, for each element key of keys in List order: + for (auto& key : keys) { + // 1. Let desc be ? O.[[GetOwnProperty]](key). + JSC::PropertySlot slot(object, JSC::PropertySlot::InternalMethodType::GetOwnProperty); + bool hasProperty = object->methodTable(vm)->getOwnPropertySlot(object, &lexicalGlobalObject, key, slot); + RETURN_IF_EXCEPTION(scope, {}); + + // 2. If desc is not undefined and desc.[[Enumerable]] is true: + + // It's necessary to filter enumerable here rather than using DontEnumPropertiesMode::Exclude, + // to prevent an observable extra [[GetOwnProperty]] operation in the case of ProxyObject records. + if (hasProperty && !(slot.attributes() & JSC::PropertyAttribute::DontEnum)) { + // 1. Let typedKey be key converted to an IDL value of type K. + auto typedKey = Detail::IdentifierConverter::convert(lexicalGlobalObject, key); + RETURN_IF_EXCEPTION(scope, {}); + + // 2. Let value be ? Get(O, key). + JSC::JSValue subValue; + if (LIKELY(!slot.isTaintedByOpaqueObject())) + subValue = slot.getValue(&lexicalGlobalObject, key); + else + subValue = object->get(&lexicalGlobalObject, key); + RETURN_IF_EXCEPTION(scope, {}); + + // 3. Let typedValue be value converted to an IDL value of type V. + auto typedValue = Converter::convert(lexicalGlobalObject, subValue, args...); + RETURN_IF_EXCEPTION(scope, {}); + + // 4. Set result[typedKey] to typedValue. + // Note: It's possible that typedKey is already in result if K is USVString and key contains unpaired surrogates. + if constexpr (std::is_same_v) { + if (!typedKey.is8Bit()) { + auto addResult = resultMap.add(typedKey, result.size()); + if (!addResult.isNewEntry) { + ASSERT(result[addResult.iterator->value].key == typedKey); + result[addResult.iterator->value].value = WTFMove(typedValue); + continue; + } + } + } else + UNUSED_VARIABLE(resultMap); + + // 5. Otherwise, append to result a mapping (typedKey, typedValue). + result.append({ WTFMove(typedKey), WTFMove(typedValue) }); + } + } + + // 6. Return result. + return result; + } +}; + +template struct JSConverter> { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const MapType& map) + { + auto& vm = JSC::getVM(&lexicalGlobalObject); + + // 1. Let result be ! ObjectCreate(%ObjectPrototype%). + auto result = constructEmptyObject(&lexicalGlobalObject, globalObject.objectPrototype()); + + // 2. Repeat, for each mapping (key, value) in D: + for (const auto& keyValuePair : map) { + // 1. Let esKey be key converted to an ECMAScript value. + // Note, this step is not required, as we need the key to be + // an Identifier, not a JSValue. + + // 2. Let esValue be value converted to an ECMAScript value. + auto esValue = toJS(lexicalGlobalObject, globalObject, keyValuePair.value); + + // 3. Let created be ! CreateDataProperty(result, esKey, esValue). + bool created = result->putDirect(vm, JSC::Identifier::fromString(vm, keyValuePair.key), esValue); + + // 4. Assert: created is true. + ASSERT_UNUSED(created, created); + } + + // 3. Return result. + return result; + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertScheduledAction.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertScheduledAction.h new file mode 100644 index 0000000000..85a7fd6ab0 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertScheduledAction.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2017 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include "JSDOMConvertBase.h" +#include "JSDOMConvertStrings.h" +#include "ScheduledAction.h" + +namespace WebCore { + +template<> struct Converter : DefaultConverter { + static std::unique_ptr convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, JSDOMGlobalObject& globalObject) + { + JSC::VM& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + + if (!value.isCallable(vm)) { + auto code = Converter::convert(lexicalGlobalObject, value); + RETURN_IF_EXCEPTION(scope, nullptr); + return ScheduledAction::create(globalObject.world(), WTFMove(code)); + } + + // The value must be an object at this point because no non-object values are callable. + ASSERT(value.isObject()); + return ScheduledAction::create(globalObject.world(), JSC::Strong { vm, JSC::asObject(value) }); + } +}; + +} + diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertSequences.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertSequences.h new file mode 100644 index 0000000000..a08336f642 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertSequences.h @@ -0,0 +1,435 @@ +/* + * Copyright (C) 2016-2017 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include "JSDOMConvertBase.h" +#include "JSDOMConvertNumbers.h" +#include "JSDOMGlobalObject.h" +#include "JavaScriptCore/IteratorOperations.h" +#include "JavaScriptCore/JSArray.h" +#include "JavaScriptCore/JSGlobalObjectInlines.h" +#include "JavaScriptCore/ObjectConstructor.h" + +namespace WebCore { + +namespace Detail { + +template +struct GenericSequenceConverter { + using ReturnType = Vector; + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject* object) + { + return convert(lexicalGlobalObject, object, ReturnType()); + } + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject* object, ReturnType&& result) + { + forEachInIterable(&lexicalGlobalObject, object, [&result](JSC::VM& vm, JSC::JSGlobalObject* lexicalGlobalObject, JSC::JSValue nextValue) { + auto scope = DECLARE_THROW_SCOPE(vm); + + auto convertedValue = Converter::convert(*lexicalGlobalObject, nextValue); + if (UNLIKELY(scope.exception())) + return; + result.append(WTFMove(convertedValue)); + }); + return WTFMove(result); + } + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject* object, JSC::JSValue method) + { + return convert(lexicalGlobalObject, object, method, ReturnType()); + } + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject* object, JSC::JSValue method, ReturnType&& result) + { + forEachInIterable(lexicalGlobalObject, object, method, [&result](JSC::VM& vm, JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue nextValue) { + auto scope = DECLARE_THROW_SCOPE(vm); + + auto convertedValue = Converter::convert(lexicalGlobalObject, nextValue); + if (UNLIKELY(scope.exception())) + return; + result.append(WTFMove(convertedValue)); + }); + return WTFMove(result); + } +}; + +// Specialization for numeric types +// FIXME: This is only implemented for the IDLFloatingPointTypes and IDLLong. To add +// support for more numeric types, add an overload of Converter::convert that +// takes a JSGlobalObject, ThrowScope and double as its arguments. +template +struct NumericSequenceConverter { + using GenericConverter = GenericSequenceConverter; + using ReturnType = typename GenericConverter::ReturnType; + + static ReturnType convertArray(JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope, JSC::JSArray* array, unsigned length, JSC::IndexingType indexingType, ReturnType&& result) + { + if (indexingType == JSC::Int32Shape) { + for (unsigned i = 0; i < length; i++) { + auto indexValue = array->butterfly()->contiguousInt32().at(array, i).get(); + ASSERT(!indexValue || indexValue.isInt32()); + if (!indexValue) + result.uncheckedAppend(0); + else + result.uncheckedAppend(indexValue.asInt32()); + } + return WTFMove(result); + } + + ASSERT(indexingType == JSC::DoubleShape); + for (unsigned i = 0; i < length; i++) { + double doubleValue = array->butterfly()->contiguousDouble().at(array, i); + if (std::isnan(doubleValue)) + result.uncheckedAppend(0); + else { + auto convertedValue = Converter::convert(lexicalGlobalObject, scope, doubleValue); + RETURN_IF_EXCEPTION(scope, {}); + + result.uncheckedAppend(convertedValue); + } + } + return WTFMove(result); + } + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + + if (!value.isObject()) { + throwSequenceTypeError(lexicalGlobalObject, scope); + return {}; + } + + JSC::JSObject* object = JSC::asObject(value); + if (!JSC::isJSArray(object)) + RELEASE_AND_RETURN(scope, GenericConverter::convert(lexicalGlobalObject, object)); + + JSC::JSArray* array = JSC::asArray(object); + if (!array->isIteratorProtocolFastAndNonObservable()) + RELEASE_AND_RETURN(scope, GenericConverter::convert(lexicalGlobalObject, object)); + + unsigned length = array->length(); + ReturnType result; + // If we're not an int32/double array, it's possible that converting a + // JSValue to a number could cause the iterator protocol to change, hence, + // we may need more capacity, or less. In such cases, we use the length + // as a proxy for the capacity we will most likely need (it's unlikely that + // a program is written with a valueOf that will augment the iterator protocol). + // If we are an int32/double array, then length is precisely the capacity we need. + if (!result.tryReserveCapacity(length)) { + // FIXME: Is the right exception to throw? + throwTypeError(&lexicalGlobalObject, scope); + return {}; + } + + JSC::IndexingType indexingType = array->indexingType() & JSC::IndexingShapeMask; + if (indexingType != JSC::Int32Shape && indexingType != JSC::DoubleShape) + RELEASE_AND_RETURN(scope, GenericConverter::convert(lexicalGlobalObject, object, WTFMove(result))); + + return convertArray(lexicalGlobalObject, scope, array, length, indexingType, WTFMove(result)); + } + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject* object, JSC::JSValue method) + { + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + + if (!JSC::isJSArray(object)) + RELEASE_AND_RETURN(scope, GenericConverter::convert(lexicalGlobalObject, object, method)); + + JSC::JSArray* array = JSC::asArray(object); + if (!array->isIteratorProtocolFastAndNonObservable()) + RELEASE_AND_RETURN(scope, GenericConverter::convert(lexicalGlobalObject, object, method)); + + unsigned length = array->length(); + ReturnType result; + // If we're not an int32/double array, it's possible that converting a + // JSValue to a number could cause the iterator protocol to change, hence, + // we may need more capacity, or less. In such cases, we use the length + // as a proxy for the capacity we will most likely need (it's unlikely that + // a program is written with a valueOf that will augment the iterator protocol). + // If we are an int32/double array, then length is precisely the capacity we need. + if (!result.tryReserveCapacity(length)) { + // FIXME: Is the right exception to throw? + throwTypeError(&lexicalGlobalObject, scope); + return {}; + } + + JSC::IndexingType indexingType = array->indexingType() & JSC::IndexingShapeMask; + if (indexingType != JSC::Int32Shape && indexingType != JSC::DoubleShape) + RELEASE_AND_RETURN(scope, GenericConverter::convert(lexicalGlobalObject, object, method, WTFMove(result))); + + return convertArray(lexicalGlobalObject, scope, array, length, indexingType, WTFMove(result)); + } +}; + +template +struct SequenceConverter { + using GenericConverter = GenericSequenceConverter; + using ReturnType = typename GenericConverter::ReturnType; + + static ReturnType convertArray(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSArray* array) + { + auto& vm = lexicalGlobalObject.vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + unsigned length = array->length(); + + ReturnType result; + if (!result.tryReserveCapacity(length)) { + // FIXME: Is the right exception to throw? + throwTypeError(&lexicalGlobalObject, scope); + return {}; + } + + JSC::IndexingType indexingType = array->indexingType() & JSC::IndexingShapeMask; + + if (indexingType == JSC::ContiguousShape) { + for (unsigned i = 0; i < length; i++) { + auto indexValue = array->butterfly()->contiguous().at(array, i).get(); + if (!indexValue) + indexValue = JSC::jsUndefined(); + + auto convertedValue = Converter::convert(lexicalGlobalObject, indexValue); + RETURN_IF_EXCEPTION(scope, {}); + + result.uncheckedAppend(convertedValue); + } + return result; + } + + for (unsigned i = 0; i < length; i++) { + auto indexValue = array->getDirectIndex(&lexicalGlobalObject, i); + RETURN_IF_EXCEPTION(scope, {}); + + if (!indexValue) + indexValue = JSC::jsUndefined(); + + auto convertedValue = Converter::convert(lexicalGlobalObject, indexValue); + RETURN_IF_EXCEPTION(scope, {}); + + result.uncheckedAppend(convertedValue); + } + return result; + } + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + + if (!value.isObject()) { + throwSequenceTypeError(lexicalGlobalObject, scope); + return {}; + } + + JSC::JSObject* object = JSC::asObject(value); + if (Converter::conversionHasSideEffects) + RELEASE_AND_RETURN(scope, (GenericConverter::convert(lexicalGlobalObject, object))); + + if (!JSC::isJSArray(object)) + RELEASE_AND_RETURN(scope, (GenericConverter::convert(lexicalGlobalObject, object))); + + JSC::JSArray* array = JSC::asArray(object); + if (!array->isIteratorProtocolFastAndNonObservable()) + RELEASE_AND_RETURN(scope, (GenericConverter::convert(lexicalGlobalObject, object))); + + RELEASE_AND_RETURN(scope, (convertArray(lexicalGlobalObject, array))); + } + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject* object, JSC::JSValue method) + { + if (Converter::conversionHasSideEffects) + return GenericConverter::convert(lexicalGlobalObject, object, method); + + if (!JSC::isJSArray(object)) + return GenericConverter::convert(lexicalGlobalObject, object, method); + + JSC::JSArray* array = JSC::asArray(object); + if (!array->isIteratorProtocolFastAndNonObservable()) + return GenericConverter::convert(lexicalGlobalObject, object, method); + + return convertArray(lexicalGlobalObject, array); + } +}; + +template<> +struct SequenceConverter { + using ReturnType = typename GenericSequenceConverter::ReturnType; + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return NumericSequenceConverter::convert(lexicalGlobalObject, value); + } + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject* object, JSC::JSValue method) + { + return NumericSequenceConverter::convert(lexicalGlobalObject, object, method); + } +}; + +template<> +struct SequenceConverter { + using ReturnType = typename GenericSequenceConverter::ReturnType; + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return NumericSequenceConverter::convert(lexicalGlobalObject, value); + } + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject* object, JSC::JSValue method) + { + return NumericSequenceConverter::convert(lexicalGlobalObject, object, method); + } +}; + +template<> +struct SequenceConverter { + using ReturnType = typename GenericSequenceConverter::ReturnType; + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return NumericSequenceConverter::convert(lexicalGlobalObject, value); + } + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject* object, JSC::JSValue method) + { + return NumericSequenceConverter::convert(lexicalGlobalObject, object, method); + } +}; + +template<> +struct SequenceConverter { + using ReturnType = typename GenericSequenceConverter::ReturnType; + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return NumericSequenceConverter::convert(lexicalGlobalObject, value); + } + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject* object, JSC::JSValue method) + { + return NumericSequenceConverter::convert(lexicalGlobalObject, object, method); + } +}; + +template<> +struct SequenceConverter { + using ReturnType = typename GenericSequenceConverter::ReturnType; + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return NumericSequenceConverter::convert(lexicalGlobalObject, value); + } + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject* object, JSC::JSValue method) + { + return NumericSequenceConverter::convert(lexicalGlobalObject, object, method); + } +}; + +} + +template struct Converter> : DefaultConverter> { + using ReturnType = typename Detail::SequenceConverter::ReturnType; + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return Detail::SequenceConverter::convert(lexicalGlobalObject, value); + } + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject* object, JSC::JSValue method) + { + return Detail::SequenceConverter::convert(lexicalGlobalObject, object, method); + } +}; + +template struct JSConverter> { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const Vector& vector) + { + JSC::VM& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + JSC::MarkedArgumentBuffer list; + for (auto& element : vector) { + auto jsValue = toJS(lexicalGlobalObject, globalObject, element); + RETURN_IF_EXCEPTION(scope, {}); + list.append(jsValue); + } + if (UNLIKELY(list.hasOverflowed())) { + throwOutOfMemoryError(&lexicalGlobalObject, scope); + return {}; + } + RELEASE_AND_RETURN(scope, JSC::constructArray(&globalObject, static_cast(nullptr), list)); + } +}; + +template struct Converter> : DefaultConverter> { + using ReturnType = typename Detail::SequenceConverter::ReturnType; + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return Detail::SequenceConverter::convert(lexicalGlobalObject, value); + } + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject* object, JSC::JSValue method) + { + return Detail::SequenceConverter::convert(lexicalGlobalObject, object, method); + } +}; + +template struct JSConverter> { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const Vector& vector) + { + JSC::VM& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + JSC::MarkedArgumentBuffer list; + for (auto& element : vector) { + auto jsValue = toJS(lexicalGlobalObject, globalObject, element); + RETURN_IF_EXCEPTION(scope, {}); + list.append(jsValue); + } + if (UNLIKELY(list.hasOverflowed())) { + throwOutOfMemoryError(&lexicalGlobalObject, scope); + return {}; + } + auto* array = JSC::constructArray(&globalObject, static_cast(nullptr), list); + RETURN_IF_EXCEPTION(scope, {}); + RELEASE_AND_RETURN(scope, JSC::objectConstructorFreeze(&lexicalGlobalObject, array)); + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertSerializedScriptValue.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertSerializedScriptValue.h new file mode 100644 index 0000000000..ba714ff67c --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertSerializedScriptValue.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include "JSDOMConvertStrings.h" + +namespace WebCore { + +template struct Converter> : DefaultConverter> { + static RefPtr convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return T::create(lexicalGlobalObject, value); + } +}; + +template struct JSConverter> { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, RefPtr value) + { + return value ? value->deserialize(lexicalGlobalObject, &globalObject) : JSC::jsNull(); + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertStrings.cpp b/src/javascript/jsc/bindings/webcore/JSDOMConvertStrings.cpp new file mode 100644 index 0000000000..6c0a208d86 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertStrings.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2004-2011, 2013, 2016 Apple Inc. All rights reserved. + * Copyright (C) 2007 Samuel Weinig + * Copyright (C) 2013 Michael Pruett + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSDOMConvertStrings.h" + +#include "JSDOMExceptionHandling.h" +#include "JavaScriptCore/HeapInlines.h" +#include "JavaScriptCore/JSCJSValueInlines.h" +#include "wtf/text/StringBuilder.h" +#include "wtf/unicode/CharacterNames.h" + +namespace WebCore { +using namespace JSC; + +String identifierToString(JSGlobalObject& lexicalGlobalObject, const Identifier& identifier) +{ + if (UNLIKELY(identifier.isSymbol())) { + auto scope = DECLARE_THROW_SCOPE(lexicalGlobalObject.vm()); + throwTypeError(&lexicalGlobalObject, scope, SymbolCoercionError); + return {}; + } + + return identifier.string(); +} + +static inline String stringToByteString(JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope, String&& string) +{ + if (!string.isAllLatin1()) { + throwTypeError(&lexicalGlobalObject, scope); + return {}; + } + + return WTFMove(string); +} + +String identifierToByteString(JSGlobalObject& lexicalGlobalObject, const Identifier& identifier) +{ + VM& vm = lexicalGlobalObject.vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + auto string = identifierToString(lexicalGlobalObject, identifier); + RETURN_IF_EXCEPTION(scope, {}); + return stringToByteString(lexicalGlobalObject, scope, WTFMove(string)); +} + +String valueToByteString(JSGlobalObject& lexicalGlobalObject, JSValue value) +{ + VM& vm = lexicalGlobalObject.vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + auto string = value.toWTFString(&lexicalGlobalObject); + RETURN_IF_EXCEPTION(scope, {}); + + return stringToByteString(lexicalGlobalObject, scope, WTFMove(string)); +} + +String identifierToUSVString(JSGlobalObject& lexicalGlobalObject, const Identifier& identifier) +{ + return replaceUnpairedSurrogatesWithReplacementCharacter(identifierToString(lexicalGlobalObject, identifier)); +} + +String valueToUSVString(JSGlobalObject& lexicalGlobalObject, JSValue value) +{ + VM& vm = lexicalGlobalObject.vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + auto string = value.toWTFString(&lexicalGlobalObject); + RETURN_IF_EXCEPTION(scope, {}); + + return replaceUnpairedSurrogatesWithReplacementCharacter(WTFMove(string)); +} + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertStrings.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertStrings.h new file mode 100644 index 0000000000..29fa7259ad --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertStrings.h @@ -0,0 +1,214 @@ +/* + * Copyright (C) 2016-2019 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include "JSDOMConvertBase.h" +#include "StringAdaptors.h" + +namespace WebCore { + +WEBCORE_EXPORT String identifierToString(JSC::JSGlobalObject&, const JSC::Identifier&); +WEBCORE_EXPORT String identifierToByteString(JSC::JSGlobalObject&, const JSC::Identifier&); +WEBCORE_EXPORT String valueToByteString(JSC::JSGlobalObject&, JSC::JSValue); +WEBCORE_EXPORT String identifierToUSVString(JSC::JSGlobalObject&, const JSC::Identifier&); +WEBCORE_EXPORT String valueToUSVString(JSC::JSGlobalObject&, JSC::JSValue); + +inline String propertyNameToString(JSC::PropertyName propertyName) +{ + ASSERT(!propertyName.isSymbol()); + return propertyName.uid() ? propertyName.uid() : propertyName.publicName(); +} + +inline AtomString propertyNameToAtomString(JSC::PropertyName propertyName) +{ + return AtomString(propertyName.uid() ? propertyName.uid() : propertyName.publicName()); +} + +// MARK: - +// MARK: String types + +template<> struct Converter : DefaultConverter { + static String convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return value.toWTFString(&lexicalGlobalObject); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const String& value) + { + return JSC::jsStringWithCache(JSC::getVM(&lexicalGlobalObject), value); + } + + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const UncachedString& value) + { + return JSC::jsString(JSC::getVM(&lexicalGlobalObject), value.string); + } + + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const OwnedString& value) + { + return JSC::jsOwnedString(JSC::getVM(&lexicalGlobalObject), value.string); + } + + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const URL& value) + { + return JSC::jsOwnedString(JSC::getVM(&lexicalGlobalObject), value.string()); + } +}; + +template<> struct Converter : DefaultConverter { + static String convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return valueToByteString(lexicalGlobalObject, value); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const String& value) + { + return JSC::jsStringWithCache(JSC::getVM(&lexicalGlobalObject), value); + } + + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const UncachedString& value) + { + return JSC::jsString(JSC::getVM(&lexicalGlobalObject), value.string); + } + + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const OwnedString& value) + { + return JSC::jsOwnedString(JSC::getVM(&lexicalGlobalObject), value.string); + } +}; + +template<> struct Converter : DefaultConverter { + static String convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return valueToUSVString(lexicalGlobalObject, value); + } + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const URL& value) + { + return JSC::jsOwnedString(JSC::getVM(&lexicalGlobalObject), value.string()); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const String& value) + { + return JSC::jsStringWithCache(JSC::getVM(&lexicalGlobalObject), value); + } + + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const UncachedString& value) + { + return JSC::jsString(JSC::getVM(&lexicalGlobalObject), value.string); + } + + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const OwnedString& value) + { + return JSC::jsOwnedString(JSC::getVM(&lexicalGlobalObject), value.string); + } + + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const URL& value) + { + return JSC::jsOwnedString(JSC::getVM(&lexicalGlobalObject), value.string()); + } +}; + +// MARK: - +// MARK: String type adaptors + +template struct Converter> : DefaultConverter> { + static String convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + if (value.isNull()) + return emptyString(); + return Converter::convert(lexicalGlobalObject, value); + } +}; + +template struct JSConverter> { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const String& value) + { + return JSConverter::convert(lexicalGlobalObject, value); + } +}; + +template struct Converter> : DefaultConverter> { + static AtomString convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + static_assert(std::is_same::value, "This adaptor is only supported for IDLDOMString at the moment."); + + return value.toString(&lexicalGlobalObject)->toAtomString(&lexicalGlobalObject); + } +}; + +template struct JSConverter> { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const AtomString& value) + { + static_assert(std::is_same::value, "This adaptor is only supported for IDLDOMString at the moment."); + + return JSConverter::convert(lexicalGlobalObject, value); + } +}; + +template struct Converter> : DefaultConverter> { + static AtomString convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + static_assert(std::is_same::value, "This adaptor is only supported for IDLDOMString at the moment."); + + return AtomString(value.toString(&lexicalGlobalObject)->toExistingAtomString(&lexicalGlobalObject)); + } +}; + +template struct JSConverter> { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = false; + + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const AtomString& value) + { + static_assert(std::is_same::value, "This adaptor is only supported for IDLDOMString at the moment."); + + return JSConverter::convert(lexicalGlobalObject, value); + } +}; + + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertUnion.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertUnion.h new file mode 100644 index 0000000000..db192f7f99 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertUnion.h @@ -0,0 +1,416 @@ +/* + * Copyright (C) 2016-2020 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include "JSDOMBinding.h" +#include "JSDOMConvertBase.h" +#include "JSDOMConvertBufferSource.h" +#include "JSDOMConvertInterface.h" +#include "JSDOMConvertNull.h" +#include "JavaScriptCore/IteratorOperations.h" +#include + +namespace WebCore { + +template +struct ConditionalReturner; + +template +struct ConditionalReturner { + template + static std::optional get(T&& value) + { + return ReturnType(std::forward(value)); + } +}; + +template +struct ConditionalReturner { + template + static std::optional get(T&&) + { + return std::nullopt; + } +}; + +template +struct ConditionalConverter; + +template +struct ConditionalConverter { + static std::optional convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + return ReturnType(Converter::convert(lexicalGlobalObject, value)); + } +}; + +template +struct ConditionalConverter { + static std::optional convert(JSC::JSGlobalObject&, JSC::JSValue) + { + return std::nullopt; + } +}; + +template +struct ConditionalSequenceConverter; + +template +struct ConditionalSequenceConverter { + static std::optional convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject* object, JSC::JSValue method) + { + return ReturnType(Converter::convert(lexicalGlobalObject, object, method)); + } +}; + +template +struct ConditionalSequenceConverter { + static std::optional convert(JSC::JSGlobalObject&, JSC::JSObject*, JSC::JSValue) + { + return std::nullopt; + } +}; + +namespace Detail { + +template +struct ConditionalFront; + +template +struct ConditionalFront { + using type = brigand::front; +}; + +template +struct ConditionalFront { + using type = void; +}; + +} + +template +using ConditionalFront = typename Detail::ConditionalFront::type; + +template struct Converter> : DefaultConverter> { + using Type = IDLUnion; + using TypeList = typename Type::TypeList; + using ReturnType = typename Type::ImplementationType; + + using NumericTypeList = brigand::filter>; + static constexpr size_t numberOfNumericTypes = brigand::size::value; + static_assert(numberOfNumericTypes == 0 || numberOfNumericTypes == 1, "There can be 0 or 1 numeric types in an IDLUnion."); + using NumericType = ConditionalFront; + + using StringTypeList = brigand::filter>; + static constexpr size_t numberOfStringTypes = brigand::size::value; + static_assert(numberOfStringTypes == 0 || numberOfStringTypes == 1, "There can be 0 or 1 string types in an IDLUnion."); + using StringType = ConditionalFront; + + using SequenceTypeList = brigand::filter>; + static constexpr size_t numberOfSequenceTypes = brigand::size::value; + static_assert(numberOfSequenceTypes == 0 || numberOfSequenceTypes == 1, "There can be 0 or 1 sequence types in an IDLUnion."); + using SequenceType = ConditionalFront; + + using FrozenArrayTypeList = brigand::filter>; + static constexpr size_t numberOfFrozenArrayTypes = brigand::size::value; + static_assert(numberOfFrozenArrayTypes == 0 || numberOfFrozenArrayTypes == 1, "There can be 0 or 1 FrozenArray types in an IDLUnion."); + using FrozenArrayType = ConditionalFront; + + using DictionaryTypeList = brigand::filter>; + static constexpr size_t numberOfDictionaryTypes = brigand::size::value; + static_assert(numberOfDictionaryTypes == 0 || numberOfDictionaryTypes == 1, "There can be 0 or 1 dictionary types in an IDLUnion."); + static constexpr bool hasDictionaryType = numberOfDictionaryTypes != 0; + using DictionaryType = ConditionalFront; + + using RecordTypeList = brigand::filter>; + static constexpr size_t numberOfRecordTypes = brigand::size::value; + static_assert(numberOfRecordTypes == 0 || numberOfRecordTypes == 1, "There can be 0 or 1 record types in an IDLUnion."); + static constexpr bool hasRecordType = numberOfRecordTypes != 0; + using RecordType = ConditionalFront; + + using ObjectTypeList = brigand::filter>; + static constexpr size_t numberOfObjectTypes = brigand::size::value; + static_assert(numberOfObjectTypes == 0 || numberOfObjectTypes == 1, "There can be 0 or 1 object types in an IDLUnion."); + static constexpr bool hasObjectType = numberOfObjectTypes != 0; + using ObjectType = ConditionalFront; + + static constexpr bool hasAnyObjectType = (numberOfSequenceTypes + numberOfFrozenArrayTypes + numberOfDictionaryTypes + numberOfRecordTypes + numberOfObjectTypes) > 0; + + using InterfaceTypeList = brigand::filter>; + using TypedArrayTypeList = brigand::filter>; + + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + JSC::VM& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + + // 1. If the union type includes a nullable type and V is null or undefined, then return the IDL value null. + constexpr bool hasNullType = brigand::any>::value; + if (hasNullType) { + if (value.isUndefinedOrNull()) + RELEASE_AND_RETURN(scope, (ConditionalConverter::convert(lexicalGlobalObject, value).value())); + } + + // 2. Let types be the flattened member types of the union type. + // NOTE: Union is expected to be pre-flattented. + + // 3. If V is null or undefined then: + if (hasDictionaryType) { + if (value.isUndefinedOrNull()) { + // 1. If types includes a dictionary type, then return the result of converting V to that dictionary type. + RELEASE_AND_RETURN(scope, (ConditionalConverter::convert(lexicalGlobalObject, value).value())); + } + } + + // 4. If V is a platform object, then: + // 1. If types includes an interface type that V implements, then return the IDL value that is a reference to the object V. + // 2. If types includes object, then return the IDL value that is a reference to the object V. + // (FIXME: Add support for object and step 4.2) + if (brigand::any>::value) { + std::optional returnValue; + brigand::for_each([&](auto&& type) { + if (returnValue) + return; + + using Type = typename WTF::RemoveCVAndReference::type::type; + using ImplementationType = typename Type::ImplementationType; + using RawType = typename Type::RawType; + + auto castedValue = JSToWrappedOverloader::toWrapped(lexicalGlobalObject, value); + if (!castedValue) + return; + + returnValue = ReturnType(ImplementationType(castedValue)); + }); + + if (returnValue) + return WTFMove(returnValue.value()); + } + + // FIXME: Add support for steps 5 & 6. + // + // 5. If V is a DOMException platform object, then: + // 1. If types includes DOMException or Error, then return the result of converting V to that type. + // 2 If types includes object, then return the IDL value that is a reference to the object V. + // + // 6. If Type(V) is Object and V has an [[ErrorData]] internal slot), then: + // 1. If types includes Error, then return the result of converting V to Error. + // 2. If types includes object, then return the IDL value that is a reference to the object V. + + // 7. If Type(V) is Object and V has an [[ArrayBufferData]] internal slot, then: + // 1. If types includes ArrayBuffer, then return the result of converting V to ArrayBuffer. + // 2. If types includes object, then return the IDL value that is a reference to the object V. + constexpr bool hasArrayBufferType = brigand::any>::value; + if (hasArrayBufferType || hasObjectType) { + auto arrayBuffer = (brigand::any>::value) ? JSC::JSArrayBuffer::toWrappedAllowShared(vm, value) : JSC::JSArrayBuffer::toWrapped(vm, value); + if (arrayBuffer) { + if (hasArrayBufferType) + return ConditionalReturner::get(WTFMove(arrayBuffer)).value(); + RELEASE_AND_RETURN(scope, (ConditionalConverter::convert(lexicalGlobalObject, value).value())); + } + } + + constexpr bool hasArrayBufferViewType = brigand::any>::value; + if (hasArrayBufferViewType || hasObjectType) { + auto arrayBufferView = (brigand::any>::value) ? JSC::JSArrayBufferView::toWrappedAllowShared(vm, value) : JSC::JSArrayBufferView::toWrapped(vm, value); + if (arrayBufferView) { + if (hasArrayBufferViewType) + return ConditionalReturner::get(WTFMove(arrayBufferView)).value(); + RELEASE_AND_RETURN(scope, (ConditionalConverter::convert(lexicalGlobalObject, value).value())); + } + } + + // 8. If Type(V) is Object and V has a [[DataView]] internal slot, then: + // 1. If types includes DataView, then return the result of converting V to DataView. + // 2. If types includes object, then return the IDL value that is a reference to the object V. + constexpr bool hasDataViewType = brigand::any>::value; + if (hasDataViewType || hasObjectType) { + auto dataView = JSC::JSDataView::toWrapped(vm, value); + if (dataView) { + if (hasDataViewType) + return ConditionalReturner::get(WTFMove(dataView)).value(); + RELEASE_AND_RETURN(scope, (ConditionalConverter::convert(lexicalGlobalObject, value).value())); + } + } + + // 9. If Type(V) is Object and V has a [[TypedArrayName]] internal slot, then: + // 1. If types includes a typed array type whose name is the value of V’s [[TypedArrayName]] internal slot, then return the result of converting V to that type. + // 2. If types includes object, then return the IDL value that is a reference to the object V. + // (FIXME: Add support for object and step 9.2) + constexpr bool hasTypedArrayType = brigand::any>::value; + if (hasTypedArrayType) { + std::optional returnValue; + brigand::for_each([&](auto&& type) { + if (returnValue) + return; + + using Type = typename WTF::RemoveCVAndReference::type::type; + using ImplementationType = typename Type::ImplementationType; + using WrapperType = typename Converter::WrapperType; + + auto castedValue = (brigand::any>::value) ? WrapperType::toWrappedAllowShared(vm, value) : WrapperType::toWrapped(vm, value); + if (!castedValue) + return; + + returnValue = ReturnType(ImplementationType(castedValue)); + }); + + if (returnValue) + return WTFMove(returnValue.value()); + } + + // FIXME: Add support for step 10. + // + // 10. If IsCallable(V) is true, then: + // 1. If types includes a callback function type, then return the result of converting V to that callback function type. + // 2. If types includes object, then return the IDL value that is a reference to the object V. + + // 11. If V is any kind of object, then: + if (hasAnyObjectType) { + if (value.isCell()) { + JSC::JSCell* cell = value.asCell(); + if (cell->isObject()) { + auto object = asObject(value); + + // 1. If types includes a sequence type, then: + // 1. Let method be the result of GetMethod(V, @@iterator). + // 2. ReturnIfAbrupt(method). + // 3. If method is not undefined, return the result of creating a + // sequence of that type from V and method. + constexpr bool hasSequenceType = numberOfSequenceTypes != 0; + if (hasSequenceType) { + auto method = JSC::iteratorMethod(&lexicalGlobalObject, object); + RETURN_IF_EXCEPTION(scope, ReturnType()); + if (!method.isUndefined()) + RELEASE_AND_RETURN(scope, (ConditionalSequenceConverter::convert(lexicalGlobalObject, object, method).value())); + } + + // 2. If types includes a frozen array type, then: + // 1. Let method be the result of GetMethod(V, @@iterator). + // 2. ReturnIfAbrupt(method). + // 3. If method is not undefined, return the result of creating a + // frozen array of that type from V and method. + constexpr bool hasFrozenArrayType = numberOfFrozenArrayTypes != 0; + if (hasFrozenArrayType) { + auto method = JSC::iteratorMethod(&lexicalGlobalObject, object); + RETURN_IF_EXCEPTION(scope, ReturnType()); + if (!method.isUndefined()) + RELEASE_AND_RETURN(scope, (ConditionalSequenceConverter::convert(lexicalGlobalObject, object, method).value())); + } + + // 3. If types includes a dictionary type, then return the result of + // converting V to that dictionary type. + if (hasDictionaryType) + RELEASE_AND_RETURN(scope, (ConditionalConverter::convert(lexicalGlobalObject, value).value())); + + // 4. If types includes a record type, then return the result of converting V to that record type. + if (hasRecordType) + RELEASE_AND_RETURN(scope, (ConditionalConverter::convert(lexicalGlobalObject, value).value())); + + // 5. If types includes a callback interface type, then return the result of converting V to that interface type. + // (FIXME: Add support for callback interface type and step 12.5) + + // 6. If types includes object, then return the IDL value that is a reference to the object V. + if (hasObjectType) + RELEASE_AND_RETURN(scope, (ConditionalConverter::convert(lexicalGlobalObject, value).value())); + } + } + } + + // 12. If V is a Boolean value, then: + // 1. If types includes a boolean, then return the result of converting V to boolean. + constexpr bool hasBooleanType = brigand::any>::value; + if (hasBooleanType) { + if (value.isBoolean()) + RELEASE_AND_RETURN(scope, (ConditionalConverter::convert(lexicalGlobalObject, value).value())); + } + + // 13. If V is a Number value, then: + // 1. If types includes a numeric type, then return the result of converting V to that numeric type. + constexpr bool hasNumericType = brigand::size::value != 0; + if (hasNumericType) { + if (value.isNumber()) + RELEASE_AND_RETURN(scope, (ConditionalConverter::convert(lexicalGlobalObject, value).value())); + } + + // 14. If types includes a string type, then return the result of converting V to that type. + constexpr bool hasStringType = brigand::size::value != 0; + if (hasStringType) + RELEASE_AND_RETURN(scope, (ConditionalConverter::convert(lexicalGlobalObject, value).value())); + + // 15. If types includes a numeric type, then return the result of converting V to that numeric type. + if (hasNumericType) + RELEASE_AND_RETURN(scope, (ConditionalConverter::convert(lexicalGlobalObject, value).value())); + + // 16. If types includes a boolean, then return the result of converting V to boolean. + if (hasBooleanType) + RELEASE_AND_RETURN(scope, (ConditionalConverter::convert(lexicalGlobalObject, value).value())); + + // 17. Throw a TypeError. + throwTypeError(&lexicalGlobalObject, scope); + return ReturnType(); + } +}; + +template struct JSConverter> { + using Type = IDLUnion; + using TypeList = typename Type::TypeList; + using ImplementationType = typename Type::ImplementationType; + + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + using Sequence = brigand::make_sequence, std::variant_size::value>; + + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const ImplementationType& variant) + { + auto index = variant.index(); + + std::optional returnValue; + brigand::for_each([&](auto&& type) { + using I = typename WTF::RemoveCVAndReference::type::type; + if (I::value == index) { + ASSERT(!returnValue); + returnValue = toJS>(lexicalGlobalObject, globalObject, std::get(variant)); + } + }); + + ASSERT(returnValue); + return returnValue.value(); + } +}; + +// BufferSource specialization. In WebKit, BufferSource is defined as IDLUnion as a hack, and it is not compatible to +// annotation described in WebIDL. +template<> struct Converter>> : DefaultConverter> { + static auto convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) -> decltype(auto) + { + return Converter, IDLAllowSharedAdaptor>>::convert(lexicalGlobalObject, value); + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertVariadic.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertVariadic.h new file mode 100644 index 0000000000..dd16b1d66e --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertVariadic.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2016-2021 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include "JSDOMConvertBase.h" +#include "wtf/FixedVector.h" + +namespace WebCore { + +template +struct VariadicConverter { + using Item = typename IDLType::ImplementationType; + + static std::optional convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) + { + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + + auto result = Converter::convert(lexicalGlobalObject, value); + RETURN_IF_EXCEPTION(scope, std::nullopt); + + return result; + } +}; + +template FixedVector::Item> convertVariadicArguments(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, size_t startIndex) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + + size_t length = callFrame.argumentCount(); + if (startIndex >= length) + return {}; + + FixedVector::Item> result(length - startIndex); + + size_t resultIndex = 0; + for (size_t i = startIndex; i < length; ++i) { + auto value = VariadicConverter::convert(lexicalGlobalObject, callFrame.uncheckedArgument(i)); + EXCEPTION_ASSERT_UNUSED(scope, !!scope.exception() == !value); + if (!value) + return {}; + result[resultIndex] = WTFMove(*value); + resultIndex++; + } + + return result; +} + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertWebGL.cpp b/src/javascript/jsc/bindings/webcore/JSDOMConvertWebGL.cpp new file mode 100644 index 0000000000..e2f6db7430 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertWebGL.cpp @@ -0,0 +1,247 @@ +/* + * Copyright (C) 2017 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSDOMConvertWebGL.h" + +#if ENABLE(WEBGL) + +#include "JSANGLEInstancedArrays.h" +#include "JSDOMConvertBufferSource.h" +#include "JSEXTBlendMinMax.h" +#include "JSEXTColorBufferFloat.h" +#include "JSEXTColorBufferHalfFloat.h" +#include "JSEXTFloatBlend.h" +#include "JSEXTFragDepth.h" +#include "JSEXTShaderTextureLOD.h" +#include "JSEXTTextureCompressionRGTC.h" +#include "JSEXTTextureFilterAnisotropic.h" +#include "JSEXTsRGB.h" +#include "JSKHRParallelShaderCompile.h" +#include "JSOESElementIndexUint.h" +#include "JSOESFBORenderMipmap.h" +#include "JSOESStandardDerivatives.h" +#include "JSOESTextureFloat.h" +#include "JSOESTextureFloatLinear.h" +#include "JSOESTextureHalfFloat.h" +#include "JSOESTextureHalfFloatLinear.h" +#include "JSOESVertexArrayObject.h" +#include "JSWebGLBuffer.h" +#include "JSWebGLColorBufferFloat.h" +#include "JSWebGLCompressedTextureASTC.h" +#include "JSWebGLCompressedTextureATC.h" +#include "JSWebGLCompressedTextureETC.h" +#include "JSWebGLCompressedTextureETC1.h" +#include "JSWebGLCompressedTexturePVRTC.h" +#include "JSWebGLCompressedTextureS3TC.h" +#include "JSWebGLCompressedTextureS3TCsRGB.h" +#include "JSWebGLDebugRendererInfo.h" +#include "JSWebGLDebugShaders.h" +#include "JSWebGLDepthTexture.h" +#include "JSWebGLDrawBuffers.h" +#include "JSWebGLFramebuffer.h" +#include "JSWebGLLoseContext.h" +#include "JSWebGLMultiDraw.h" +#include "JSWebGLProgram.h" +#include "JSWebGLRenderbuffer.h" +#include "JSWebGLSampler.h" +#include "JSWebGLTexture.h" +#include "JSWebGLTransformFeedback.h" +#include "JSWebGLVertexArrayObject.h" +#include "JSWebGLVertexArrayObjectOES.h" +#include "JavaScriptCore/JSCInlines.h" + +namespace WebCore { +using namespace JSC; + +// FIXME: This should use the IDLUnion JSConverter. +JSValue convertToJSValue(JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const WebGLAny& any) +{ + return WTF::switchOn( + any, + [](std::nullptr_t) -> JSValue { + return jsNull(); + }, + [](bool value) -> JSValue { + return jsBoolean(value); + }, + [](int value) -> JSValue { + return jsNumber(value); + }, + [](unsigned value) -> JSValue { + return jsNumber(value); + }, + [](long long value) -> JSValue { + return jsNumber(value); + }, + [](float value) -> JSValue { + return jsNumber(value); + }, + [&](const String& value) -> JSValue { + return jsStringWithCache(lexicalGlobalObject.vm(), value); + }, + [&](const Vector& values) -> JSValue { + MarkedArgumentBuffer list; + for (auto& value : values) + list.append(jsBoolean(value)); + RELEASE_ASSERT(!list.hasOverflowed()); + return constructArray(&globalObject, static_cast(nullptr), list); + }, + [&](const Vector& values) -> JSValue { + MarkedArgumentBuffer list; + for (auto& value : values) + list.append(jsNumber(value)); + RELEASE_ASSERT(!list.hasOverflowed()); + return constructArray(&globalObject, static_cast(nullptr), list); + }, + [&](const Vector& values) -> JSValue { + MarkedArgumentBuffer list; + for (auto& value : values) + list.append(jsNumber(value)); + RELEASE_ASSERT(!list.hasOverflowed()); + return constructArray(&globalObject, static_cast(nullptr), list); + }, + [&](const RefPtr& array) { + return toJS(&lexicalGlobalObject, &globalObject, array.get()); + }, + [&](const RefPtr& array) { + return toJS(&lexicalGlobalObject, &globalObject, array.get()); + }, + [&](const RefPtr& array) { + return toJS(&lexicalGlobalObject, &globalObject, array.get()); + }, + [&](const RefPtr& array) { + return toJS(&lexicalGlobalObject, &globalObject, array.get()); + }, + [&](const RefPtr& buffer) { + return toJS(&lexicalGlobalObject, &globalObject, buffer.get()); + }, + [&](const RefPtr& buffer) { + return toJS(&lexicalGlobalObject, &globalObject, buffer.get()); + }, + [&](const RefPtr& program) { + return toJS(&lexicalGlobalObject, &globalObject, program.get()); + }, + [&](const RefPtr& buffer) { + return toJS(&lexicalGlobalObject, &globalObject, buffer.get()); + }, + [&](const RefPtr& texture) { + return toJS(&lexicalGlobalObject, &globalObject, texture.get()); + }, + [&](const RefPtr& array) { + return toJS(&lexicalGlobalObject, &globalObject, array.get()); + } +#if ENABLE(WEBGL2) + , + [&](const RefPtr& sampler) { + return toJS(&lexicalGlobalObject, &globalObject, sampler.get()); + }, + [&](const RefPtr& transformFeedback) { + return toJS(&lexicalGlobalObject, &globalObject, transformFeedback.get()); + }, + [&](const RefPtr& array) { + return toJS(&lexicalGlobalObject, &globalObject, array.get()); + } +#endif + ); +} + +JSValue convertToJSValue(JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, WebGLExtension& extension) +{ + switch (extension.getName()) { + case WebGLExtension::WebGLLoseContextName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::EXTShaderTextureLODName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::EXTTextureCompressionRGTCName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::EXTTextureFilterAnisotropicName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::EXTsRGBName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::EXTFragDepthName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::EXTBlendMinMaxName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::KHRParallelShaderCompileName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::OESStandardDerivativesName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::OESTextureFloatName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::OESTextureFloatLinearName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::OESTextureHalfFloatName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::OESTextureHalfFloatLinearName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::OESVertexArrayObjectName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::OESElementIndexUintName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::OESFBORenderMipmapName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::WebGLDebugRendererInfoName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::WebGLDebugShadersName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::WebGLCompressedTextureATCName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::WebGLCompressedTextureETCName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::WebGLCompressedTextureETC1Name: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::WebGLCompressedTexturePVRTCName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::WebGLCompressedTextureS3TCName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::WebGLCompressedTextureS3TCsRGBName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::WebGLCompressedTextureASTCName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::WebGLDepthTextureName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::WebGLDrawBuffersName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::ANGLEInstancedArraysName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::EXTColorBufferHalfFloatName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::EXTFloatBlendName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::WebGLColorBufferFloatName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::EXTColorBufferFloatName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + case WebGLExtension::WebGLMultiDrawName: + return toJS(&lexicalGlobalObject, &globalObject, static_cast(extension)); + } + ASSERT_NOT_REACHED(); + return jsNull(); +} + +} + +#endif diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertWebGL.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertWebGL.h new file mode 100644 index 0000000000..ae8f7e688d --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertWebGL.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#if ENABLE(WEBGL) + +#include "IDLTypes.h" +#include "JSDOMConvertBase.h" + +namespace WebCore { + +JSC::JSValue convertToJSValue(JSC::JSGlobalObject&, JSDOMGlobalObject&, const WebGLAny&); +JSC::JSValue convertToJSValue(JSC::JSGlobalObject&, JSDOMGlobalObject&, WebGLExtension&); + +inline JSC::JSValue convertToJSValue(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, WebGLExtension* extension) +{ + if (!extension) + return JSC::jsNull(); + return convertToJSValue(lexicalGlobalObject, globalObject, *extension); +} + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const WebGLAny& value) + { + return convertToJSValue(lexicalGlobalObject, globalObject, value); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const T& value) + { + return convertToJSValue(lexicalGlobalObject, globalObject, Detail::getPtrOrRef(value)); + } +}; + +} // namespace WebCore + +#endif diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertXPathNSResolver.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertXPathNSResolver.h new file mode 100644 index 0000000000..eed7d19808 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertXPathNSResolver.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include "JSDOMConvertBase.h" + +#include "JSCustomXPathNSResolver.h" +#include "JSXPathNSResolver.h" + +namespace WebCore { + +template<> struct Converter> : DefaultConverter> { + template + static RefPtr convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + JSC::VM& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + if (!value.isObject()) { + exceptionThrower(lexicalGlobalObject, scope); + return nullptr; + } + + auto object = asObject(value); + if (object->inherits(vm)) + return &JSC::jsCast(object)->wrapped(); + + return JSCustomXPathNSResolver::create(vm, object); + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMException.cpp b/src/javascript/jsc/bindings/webcore/JSDOMException.cpp new file mode 100644 index 0000000000..4a075205f2 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMException.cpp @@ -0,0 +1,381 @@ +/* + This file is part of the WebKit open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "root.h" + +#include "JSDOMException.h" + +#include "ActiveDOMObject.h" +#include "ExtendedDOMClientIsoSubspaces.h" +#include "ExtendedDOMIsoSubspaces.h" +#include "JSDOMAttribute.h" +#include "JSDOMBinding.h" +#include "JSDOMConstructor.h" +#include "JSDOMConvertInterface.h" +#include "JSDOMConvertNumbers.h" +#include "JSDOMConvertStrings.h" +#include "JSDOMExceptionHandling.h" +#include "JSDOMGlobalObjectInlines.h" +#include "JSDOMWrapperCache.h" +#include "ScriptExecutionContext.h" +#include "WebCoreJSClientData.h" +#include "JavaScriptCore/FunctionPrototype.h" +#include "JavaScriptCore/HeapAnalyzer.h" +#include "JavaScriptCore/JSCInlines.h" +#include "JavaScriptCore/JSDestructibleObjectHeapCellType.h" +#include "JavaScriptCore/SlotVisitorMacros.h" +#include "JavaScriptCore/SubspaceInlines.h" +#include "wtf/GetPtr.h" +#include "wtf/PointerPreparations.h" +#include "wtf/URL.h" + +namespace WebCore { +using namespace JSC; + +// Attributes + +static JSC_DECLARE_CUSTOM_GETTER(jsDOMExceptionConstructor); +static JSC_DECLARE_CUSTOM_GETTER(jsDOMException_code); +static JSC_DECLARE_CUSTOM_GETTER(jsDOMException_name); +static JSC_DECLARE_CUSTOM_GETTER(jsDOMException_message); + +class JSDOMExceptionPrototype final : public JSC::JSNonFinalObject { +public: + using Base = JSC::JSNonFinalObject; + static JSDOMExceptionPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) + { + JSDOMExceptionPrototype* ptr = new (NotNull, JSC::allocateCell(vm)) JSDOMExceptionPrototype(vm, globalObject, structure); + ptr->finishCreation(vm); + return ptr; + } + + DECLARE_INFO; + template + static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSDOMExceptionPrototype, Base); + return &vm.plainObjectSpace(); + } + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); + } + +private: + JSDOMExceptionPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) + : JSC::JSNonFinalObject(vm, structure) + { + } + + void finishCreation(JSC::VM&); +}; +STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSDOMExceptionPrototype, JSDOMExceptionPrototype::Base); + +using JSDOMExceptionDOMConstructor = JSDOMConstructor; + +/* Hash table for constructor */ + +static const HashTableValue JSDOMExceptionConstructorTableValues[] = { + { "INDEX_SIZE_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(1) } }, + { "DOMSTRING_SIZE_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(2) } }, + { "HIERARCHY_REQUEST_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(3) } }, + { "WRONG_DOCUMENT_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(4) } }, + { "INVALID_CHARACTER_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(5) } }, + { "NO_DATA_ALLOWED_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(6) } }, + { "NO_MODIFICATION_ALLOWED_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(7) } }, + { "NOT_FOUND_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(8) } }, + { "NOT_SUPPORTED_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(9) } }, + { "INUSE_ATTRIBUTE_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(10) } }, + { "INVALID_STATE_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(11) } }, + { "SYNTAX_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(12) } }, + { "INVALID_MODIFICATION_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(13) } }, + { "NAMESPACE_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(14) } }, + { "INVALID_ACCESS_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(15) } }, + { "VALIDATION_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(16) } }, + { "TYPE_MISMATCH_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(17) } }, + { "SECURITY_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(18) } }, + { "NETWORK_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(19) } }, + { "ABORT_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(20) } }, + { "URL_MISMATCH_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(21) } }, + { "QUOTA_EXCEEDED_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(22) } }, + { "TIMEOUT_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(23) } }, + { "INVALID_NODE_TYPE_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(24) } }, + { "DATA_CLONE_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(25) } }, +}; + +template<> EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSDOMExceptionDOMConstructor::construct(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame) +{ + VM& vm = lexicalGlobalObject->vm(); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto* castedThis = jsCast(callFrame->jsCallee()); + ASSERT(castedThis); + EnsureStillAliveScope argument0 = callFrame->argument(0); + auto message = argument0.value().isUndefined() ? emptyString() : convert(*lexicalGlobalObject, argument0.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + EnsureStillAliveScope argument1 = callFrame->argument(1); + auto name = argument1.value().isUndefined() ? "Error"_s : convert(*lexicalGlobalObject, argument1.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + auto object = DOMException::create(WTFMove(message), WTFMove(name)); + if constexpr (IsExceptionOr) + RETURN_IF_EXCEPTION(throwScope, {}); + static_assert(TypeOrExceptionOrUnderlyingType::isRef); + auto jsValue = toJSNewlyCreated>(*lexicalGlobalObject, *castedThis->globalObject(), throwScope, WTFMove(object)); + if constexpr (IsExceptionOr) + RETURN_IF_EXCEPTION(throwScope, {}); + setSubclassStructureIfNeeded(lexicalGlobalObject, callFrame, asObject(jsValue)); + RETURN_IF_EXCEPTION(throwScope, {}); + return JSValue::encode(jsValue); +} +JSC_ANNOTATE_HOST_FUNCTION(JSDOMExceptionDOMConstructorConstruct, JSDOMExceptionDOMConstructor::construct); + +template<> const ClassInfo JSDOMExceptionDOMConstructor::s_info = { "DOMException"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMExceptionDOMConstructor) }; + +template<> JSValue JSDOMExceptionDOMConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) +{ + UNUSED_PARAM(vm); + return globalObject.functionPrototype(); +} + +template<> void JSDOMExceptionDOMConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) +{ + putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); + JSString* nameString = jsNontrivialString(vm, "DOMException"_s); + m_originalName.set(vm, this, nameString); + putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); + putDirect(vm, vm.propertyNames->prototype, JSDOMException::prototype(vm, globalObject), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete); + reifyStaticProperties(vm, JSDOMException::info(), JSDOMExceptionConstructorTableValues, *this); +} + +/* Hash table for prototype */ + +static const HashTableValue JSDOMExceptionPrototypeTableValues[] = { + { "constructor", static_cast(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t) static_cast(jsDOMExceptionConstructor), (intptr_t) static_cast(0) } }, + { "code", static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast(jsDOMException_code), (intptr_t) static_cast(0) } }, + { "name", static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast(jsDOMException_name), (intptr_t) static_cast(0) } }, + { "message", static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast(jsDOMException_message), (intptr_t) static_cast(0) } }, + { "INDEX_SIZE_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(1) } }, + { "DOMSTRING_SIZE_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(2) } }, + { "HIERARCHY_REQUEST_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(3) } }, + { "WRONG_DOCUMENT_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(4) } }, + { "INVALID_CHARACTER_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(5) } }, + { "NO_DATA_ALLOWED_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(6) } }, + { "NO_MODIFICATION_ALLOWED_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(7) } }, + { "NOT_FOUND_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(8) } }, + { "NOT_SUPPORTED_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(9) } }, + { "INUSE_ATTRIBUTE_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(10) } }, + { "INVALID_STATE_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(11) } }, + { "SYNTAX_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(12) } }, + { "INVALID_MODIFICATION_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(13) } }, + { "NAMESPACE_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(14) } }, + { "INVALID_ACCESS_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(15) } }, + { "VALIDATION_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(16) } }, + { "TYPE_MISMATCH_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(17) } }, + { "SECURITY_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(18) } }, + { "NETWORK_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(19) } }, + { "ABORT_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(20) } }, + { "URL_MISMATCH_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(21) } }, + { "QUOTA_EXCEEDED_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(22) } }, + { "TIMEOUT_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(23) } }, + { "INVALID_NODE_TYPE_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(24) } }, + { "DATA_CLONE_ERR", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(25) } }, +}; + +const ClassInfo JSDOMExceptionPrototype::s_info = { "DOMException"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMExceptionPrototype) }; + +void JSDOMExceptionPrototype::finishCreation(VM& vm) +{ + Base::finishCreation(vm); + reifyStaticProperties(vm, JSDOMException::info(), JSDOMExceptionPrototypeTableValues, *this); + JSC_TO_STRING_TAG_WITHOUT_TRANSITION(); +} + +const ClassInfo JSDOMException::s_info = { "DOMException"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMException) }; + +JSDOMException::JSDOMException(Structure* structure, JSDOMGlobalObject& globalObject, Ref&& impl) + : JSDOMWrapper(structure, globalObject, WTFMove(impl)) +{ +} + +void JSDOMException::finishCreation(VM& vm) +{ + Base::finishCreation(vm); + ASSERT(inherits(vm, info())); + + // static_assert(!std::is_base_of::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject."); +} + +JSObject* JSDOMException::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) +{ + return JSDOMExceptionPrototype::create(vm, &globalObject, JSDOMExceptionPrototype::createStructure(vm, &globalObject, globalObject.errorPrototype())); +} + +JSObject* JSDOMException::prototype(VM& vm, JSDOMGlobalObject& globalObject) +{ + return getDOMPrototype(vm, globalObject); +} + +JSValue JSDOMException::getConstructor(VM& vm, const JSGlobalObject* globalObject) +{ + return getDOMConstructor(vm, *jsCast(globalObject)); +} + +void JSDOMException::destroy(JSC::JSCell* cell) +{ + JSDOMException* thisObject = static_cast(cell); + thisObject->JSDOMException::~JSDOMException(); +} + +JSC_DEFINE_CUSTOM_GETTER(jsDOMExceptionConstructor, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto* prototype = jsDynamicCast(vm, JSValue::decode(thisValue)); + if (UNLIKELY(!prototype)) + return throwVMTypeError(lexicalGlobalObject, throwScope); + return JSValue::encode(JSDOMException::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); +} + +static inline JSValue jsDOMException_codeGetter(JSGlobalObject& lexicalGlobalObject, JSDOMException& thisObject) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.legacyCode()))); +} + +JSC_DEFINE_CUSTOM_GETTER(jsDOMException_code, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); +} + +static inline JSValue jsDOMException_nameGetter(JSGlobalObject& lexicalGlobalObject, JSDOMException& thisObject) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.name()))); +} + +JSC_DEFINE_CUSTOM_GETTER(jsDOMException_name, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); +} + +static inline JSValue jsDOMException_messageGetter(JSGlobalObject& lexicalGlobalObject, JSDOMException& thisObject) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.message()))); +} + +JSC_DEFINE_CUSTOM_GETTER(jsDOMException_message, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); +} + +JSC::GCClient::IsoSubspace* JSDOMException::subspaceForImpl(JSC::VM& vm) +{ + return WebCore::subspaceForImpl( + vm, + [](auto& spaces) { return spaces.m_clientSubspaceForDOMException.get(); }, + [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForDOMException = WTFMove(space); }, + [](auto& spaces) { return spaces.m_subspaceForDOMException.get(); }, + [](auto& spaces, auto&& space) { spaces.m_subspaceForDOMException = WTFMove(space); }); +} + +void JSDOMException::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer) +{ + auto* thisObject = jsCast(cell); + analyzer.setWrappedObjectForCell(cell, &thisObject->wrapped()); + // if (thisObject->scriptExecutionContext()) + // analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); + Base::analyzeHeap(cell, analyzer); +} + +bool JSDOMExceptionOwner::isReachableFromOpaqueRoots(JSC::Handle handle, void*, AbstractSlotVisitor& visitor, const char** reason) +{ + UNUSED_PARAM(handle); + UNUSED_PARAM(visitor); + UNUSED_PARAM(reason); + return false; +} + +void JSDOMExceptionOwner::finalize(JSC::Handle handle, void* context) +{ + auto* jsDOMException = static_cast(handle.slot()->asCell()); + auto& world = *static_cast(context); + uncacheWrapper(world, &jsDOMException->wrapped(), jsDOMException); +} + +// #if ENABLE(BINDING_INTEGRITY) +// #if PLATFORM(WIN) +// #pragma warning(disable : 4483) +// extern "C" { +// extern void (*const __identifier("??_7DOMException@WebCore@@6B@")[])(); +// } +// #else +// extern "C" { +// extern void* _ZTVN7WebCore12DOMExceptionE[]; +// } +// #endif +// #endif + +JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject*, JSDOMGlobalObject* globalObject, Ref&& impl) +{ + + // if constexpr (std::is_polymorphic_v) { + // #if ENABLE(BINDING_INTEGRITY) + // const void* actualVTablePointer = getVTablePointer(impl.ptr()); + // #if PLATFORM(WIN) + // void* expectedVTablePointer = __identifier("??_7DOMException@WebCore@@6B@"); + // #else + // void* expectedVTablePointer = &_ZTVN7WebCore12DOMExceptionE[2]; + // #endif + + // // If you hit this assertion you either have a use after free bug, or + // // DOMException has subclasses. If DOMException has subclasses that get passed + // // to toJS() we currently require DOMException you to opt out of binding hardening + // // by adding the SkipVTableValidation attribute to the interface IDL definition + // RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer); + // #endif + // } + return createWrapper(globalObject, WTFMove(impl)); +} + +JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, DOMException& impl) +{ + return wrap(lexicalGlobalObject, globalObject, impl); +} + +DOMException* JSDOMException::toWrapped(JSC::VM& vm, JSC::JSValue value) +{ + if (auto* wrapper = jsDynamicCast(vm, value)) + return &wrapper->wrapped(); + return nullptr; +} + +inline JSC::WeakHandleOwner* wrapperOwner(DOMWrapperWorld&, DOMException*) +{ + static NeverDestroyed owner; + return &owner.get(); +} + +} diff --git a/src/javascript/jsc/bindings/webcore/JSDOMException.h b/src/javascript/jsc/bindings/webcore/JSDOMException.h new file mode 100644 index 0000000000..0d09fdd23b --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMException.h @@ -0,0 +1,95 @@ +/* + This file is part of the WebKit open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#pragma once + +#include "root.h" + +#include "DOMException.h" +#include "JSDOMWrapper.h" +#include "JavaScriptCore/ErrorPrototype.h" +#include "wtf/NeverDestroyed.h" + +#include "JavaScriptCore/WeakHandleOwner.h" + +namespace WebCore { + +class JSDOMException : public JSDOMWrapper { +public: + using Base = JSDOMWrapper; + static JSDOMException* create(JSC::Structure* structure, JSDOMGlobalObject* globalObject, Ref&& impl) + { + JSDOMException* ptr = new (NotNull, JSC::allocateCell(globalObject->vm())) JSDOMException(structure, *globalObject, WTFMove(impl)); + ptr->finishCreation(globalObject->vm()); + return ptr; + } + + static JSC::JSObject* createPrototype(JSC::VM&, JSDOMGlobalObject&); + static JSC::JSObject* prototype(JSC::VM&, JSDOMGlobalObject&); + static DOMException* toWrapped(JSC::VM&, JSC::JSValue); + static void destroy(JSC::JSCell*); + + DECLARE_INFO; + + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info(), JSC::NonArray); + } + + static JSC::JSValue getConstructor(JSC::VM&, const JSC::JSGlobalObject*); + template static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + if constexpr (mode == JSC::SubspaceAccess::Concurrently) + return nullptr; + return subspaceForImpl(vm); + } + static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm); + static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&); + +protected: + JSDOMException(JSC::Structure*, JSDOMGlobalObject&, Ref&&); + + void finishCreation(JSC::VM&); +}; + +class JSDOMExceptionOwner final : public JSC::WeakHandleOwner { +public: + bool isReachableFromOpaqueRoots(JSC::Handle, void* context, JSC::AbstractSlotVisitor&, const char**) final; + void finalize(JSC::Handle, void* context) final; +}; + +inline JSC::WeakHandleOwner* wrapperOwner(DOMWrapperWorld&, DOMException*); + +inline void* wrapperKey(DOMException* wrappableObject) +{ + return wrappableObject; +} + +JSC::JSValue toJS(JSC::JSGlobalObject*, JSDOMGlobalObject*, DOMException&); +inline JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, DOMException* impl) { return impl ? toJS(lexicalGlobalObject, globalObject, *impl) : JSC::jsNull(); } +JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject*, JSDOMGlobalObject*, Ref&&); +inline JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, RefPtr&& impl) { return impl ? toJSNewlyCreated(lexicalGlobalObject, globalObject, impl.releaseNonNull()) : JSC::jsNull(); } + +template<> struct JSDOMWrapperConverterTraits { + using WrapperClass = JSDOMException; + using ToWrappedReturnType = DOMException*; +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMGlobalObjectInlines.h b/src/javascript/jsc/bindings/webcore/JSDOMGlobalObjectInlines.h new file mode 100644 index 0000000000..313b14aa20 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMGlobalObjectInlines.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2021 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#pragma once + +#include "DOMConstructors.h" +#include "JSDOMGlobalObject.h" + +namespace WebCore { + +template +inline JSC::JSObject* getDOMConstructor(JSC::VM& vm, const Zig::GlobalObject& globalObject) +{ + // No locking is necessary unless we need to add a new constructor to Zig::GlobalObject::constructors(). + if (JSC::JSObject* constructor = globalObject.constructors().array()[static_cast(constructorID)].get()) + return constructor; + JSC::JSObject* constructor = ConstructorClass::create(vm, ConstructorClass::createStructure(vm, const_cast(globalObject), ConstructorClass::prototypeForStructure(vm, globalObject)), const_cast(globalObject)); + ASSERT(!globalObject.constructors().array()[static_cast(constructorID)].get()); + Zig::GlobalObject& mutableGlobalObject = const_cast(globalObject); + mutableGlobalObject.constructors().array()[static_cast(constructorID)].set(vm, &globalObject, constructor); + return constructor; +} + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMIterator.cpp b/src/javascript/jsc/bindings/webcore/JSDOMIterator.cpp new file mode 100644 index 0000000000..205e1c80a8 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMIterator.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2016 Apple, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSDOMIterator.h" + +#include "JavaScriptCore/ArrayPrototype.h" +#include "JavaScriptCore/BuiltinNames.h" + +namespace WebCore { + +void addValueIterableMethods(JSC::JSGlobalObject& globalObject, JSC::JSObject& prototype) +{ + JSC::ArrayPrototype* arrayPrototype = globalObject.arrayPrototype(); + ASSERT(arrayPrototype); + + JSC::JSGlobalObject* lexicalGlobalObject = &globalObject; + ASSERT(lexicalGlobalObject); + JSC::VM& vm = lexicalGlobalObject->vm(); + + auto copyProperty = [&](const JSC::Identifier& arrayIdentifier, const JSC::Identifier& otherIdentifier, unsigned attributes = 0) { + JSC::JSValue value = arrayPrototype->getDirect(vm, arrayIdentifier); + ASSERT(value); + prototype.putDirect(vm, otherIdentifier, value, attributes); + }; + + copyProperty(vm.propertyNames->builtinNames().entriesPrivateName(), vm.propertyNames->builtinNames().entriesPublicName()); + copyProperty(vm.propertyNames->builtinNames().forEachPrivateName(), vm.propertyNames->builtinNames().forEachPublicName()); + copyProperty(vm.propertyNames->builtinNames().keysPrivateName(), vm.propertyNames->builtinNames().keysPublicName()); + copyProperty(vm.propertyNames->builtinNames().valuesPrivateName(), vm.propertyNames->builtinNames().valuesPublicName()); +} + +} diff --git a/src/javascript/jsc/bindings/webcore/JSDOMIterator.h b/src/javascript/jsc/bindings/webcore/JSDOMIterator.h new file mode 100644 index 0000000000..04b4c001b3 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMIterator.h @@ -0,0 +1,275 @@ +/* + * Copyright (C) 2016 Canon, Inc. All rights reserved. + * Copyright (C) 2016-2022 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY CANON INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CANON INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "JSDOMConvert.h" +#include "JavaScriptCore/IteratorPrototype.h" +#include "JavaScriptCore/PropertySlot.h" +#include + +namespace WebCore { + +void addValueIterableMethods(JSC::JSGlobalObject&, JSC::JSObject&); + +enum class JSDOMIteratorType { Set, + Map }; + +// struct IteratorTraits { +// static constexpr JSDOMIteratorType type = [Map|Set]; +// using KeyType = [IDLType|void]; +// using ValueType = [IDLType]; +// }; + +template using EnableIfMap = typename std::enable_if::type; +template using EnableIfSet = typename std::enable_if::type; + +template class JSDOMIteratorPrototype final : public JSC::JSNonFinalObject { +public: + using Base = JSC::JSNonFinalObject; + using DOMWrapped = typename JSWrapper::DOMWrapped; + + template + static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSDOMIteratorPrototype, Base); + return &vm.plainObjectSpace(); + } + + static JSDOMIteratorPrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure) + { + STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSDOMIteratorPrototype, JSDOMIteratorPrototype::Base); + JSDOMIteratorPrototype* prototype = new (NotNull, JSC::allocateCell(vm)) JSDOMIteratorPrototype(vm, structure); + prototype->finishCreation(vm, globalObject); + return prototype; + } + + DECLARE_INFO; + + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); + } + + static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES next(JSC::JSGlobalObject*, JSC::CallFrame*); + +private: + JSDOMIteratorPrototype(JSC::VM& vm, JSC::Structure* structure) + : Base(vm, structure) + { + } + + void finishCreation(JSC::VM&, JSC::JSGlobalObject*); +}; + +using IterationKind = JSC::IterationKind; + +template class JSDOMIteratorBase : public JSDOMObject { +public: + using Base = JSDOMObject; + + using Wrapper = JSWrapper; + using Traits = IteratorTraits; + + using DOMWrapped = typename Wrapper::DOMWrapped; + using Prototype = JSDOMIteratorPrototype; + + DECLARE_INFO; + + static Prototype* createPrototype(JSC::VM& vm, JSC::JSGlobalObject& globalObject) + { + return Prototype::create(vm, &globalObject, Prototype::createStructure(vm, &globalObject, globalObject.iteratorPrototype())); + } + + JSC::JSValue next(JSC::JSGlobalObject&); + + static void createStructure(JSC::VM&, JSC::JSGlobalObject*, JSC::JSValue); // Make use of createStructure for this compile-error. + +protected: + JSDOMIteratorBase(JSC::Structure* structure, JSWrapper& iteratedObject, IterationKind kind) + : Base(structure, *iteratedObject.globalObject()) + , m_iterator(iteratedObject.wrapped().createIterator()) + , m_kind(kind) + { + } + + template EnableIfMap asJS(JSC::JSGlobalObject&, IteratorValue&); + template EnableIfSet asJS(JSC::JSGlobalObject&, IteratorValue&); + + static void destroy(JSC::JSCell*); + + std::optional m_iterator; + IterationKind m_kind; +}; + +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(nullptr), arguments); +} + +template +inline JSC::JSValue jsPair(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const T& value1, const U& value2) +{ + return jsPair(lexicalGlobalObject, globalObject, toJS(lexicalGlobalObject, globalObject, value1), toJS(lexicalGlobalObject, globalObject, value2)); +} + +template JSC::JSValue iteratorCreate(typename JSIterator::Wrapper&, IterationKind); +template JSC::JSValue iteratorForEach(JSC::JSGlobalObject&, JSC::CallFrame&, typename JSIterator::Wrapper&); + +template JSC::JSValue iteratorCreate(typename JSIterator::Wrapper& thisObject, IterationKind kind) +{ + ASSERT(thisObject.globalObject()); + JSDOMGlobalObject& globalObject = *thisObject.globalObject(); + return JSIterator::create(globalObject.vm(), getDOMStructure(globalObject.vm(), globalObject), thisObject, kind); +} + +template +template inline EnableIfMap JSDOMIteratorBase::asJS(JSC::JSGlobalObject& lexicalGlobalObject, IteratorValue& value) +{ + ASSERT(value); + + switch (m_kind) { + case IterationKind::Keys: + return toJS(lexicalGlobalObject, *globalObject(), value->key); + case IterationKind::Values: + return toJS(lexicalGlobalObject, *globalObject(), value->value); + case IterationKind::Entries: + return jsPair(lexicalGlobalObject, *globalObject(), value->key, value->value); + }; + + ASSERT_NOT_REACHED(); + return {}; +} + +template +template inline EnableIfSet JSDOMIteratorBase::asJS(JSC::JSGlobalObject& lexicalGlobalObject, IteratorValue& value) +{ + ASSERT(value); + + auto globalObject = this->globalObject(); + auto result = toJS(lexicalGlobalObject, *globalObject, value); + + switch (m_kind) { + case IterationKind::Keys: + case IterationKind::Values: + return result; + case IterationKind::Entries: + return jsPair(lexicalGlobalObject, *globalObject, result, result); + }; + + ASSERT_NOT_REACHED(); + return {}; +} + +template EnableIfMap appendForEachArguments(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, JSC::MarkedArgumentBuffer& arguments, IteratorValue& value) +{ + ASSERT(value); + arguments.append(toJS(lexicalGlobalObject, globalObject, value->value)); + arguments.append(toJS(lexicalGlobalObject, globalObject, value->key)); +} + +template EnableIfSet appendForEachArguments(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, JSC::MarkedArgumentBuffer& arguments, IteratorValue& value) +{ + ASSERT(value); + auto argument = toJS(lexicalGlobalObject, globalObject, value); + arguments.append(argument); + arguments.append(argument); +} + +template JSC::JSValue iteratorForEach(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, typename JSIterator::Wrapper& thisObject) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto scope = DECLARE_THROW_SCOPE(vm); + JSC::JSValue callback = callFrame.argument(0); + JSC::JSValue thisValue = callFrame.argument(1); + + auto callData = JSC::getCallData(JSC::getVM(&lexicalGlobalObject), callback); + if (callData.type == JSC::CallData::Type::None) + return throwTypeError(&lexicalGlobalObject, scope, "Cannot call callback"_s); + + auto iterator = thisObject.wrapped().createIterator(); + while (auto value = iterator.next()) { + JSC::MarkedArgumentBuffer arguments; + appendForEachArguments(lexicalGlobalObject, *thisObject.globalObject(), arguments, value); + arguments.append(&thisObject); + if (UNLIKELY(arguments.hasOverflowed())) { + throwOutOfMemoryError(&lexicalGlobalObject, scope); + return {}; + } + JSC::call(&lexicalGlobalObject, callback, callData, thisValue, arguments); + if (UNLIKELY(scope.exception())) + break; + } + return JSC::jsUndefined(); +} + +template +void JSDOMIteratorBase::destroy(JSCell* cell) +{ + JSDOMIteratorBase* thisObject = static_cast*>(cell); + thisObject->JSDOMIteratorBase::~JSDOMIteratorBase(); +} + +template +JSC::JSValue JSDOMIteratorBase::next(JSC::JSGlobalObject& lexicalGlobalObject) +{ + if (m_iterator) { + auto iteratorValue = m_iterator->next(); + if (iteratorValue) + return createIteratorResultObject(&lexicalGlobalObject, asJS(lexicalGlobalObject, iteratorValue), false); + m_iterator = std::nullopt; + } + return createIteratorResultObject(&lexicalGlobalObject, JSC::jsUndefined(), true); +} + +template +JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSDOMIteratorPrototype::next(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callFrame) +{ + JSC::VM& vm = globalObject->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + auto iterator = JSC::jsDynamicCast*>(vm, callFrame->thisValue()); + if (!iterator) + return JSC::JSValue::encode(throwTypeError(globalObject, scope, "Cannot call next() on a non-Iterator object"_s)); + + return JSC::JSValue::encode(iterator->next(*globalObject)); +} + +template +void JSDOMIteratorPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) +{ + Base::finishCreation(vm); + ASSERT(inherits(vm, info())); + + JSC_NATIVE_INTRINSIC_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->next, next, 0, 0, JSC::NoIntrinsic); + JSC_TO_STRING_TAG_WITHOUT_TRANSITION(); +} + +} diff --git a/src/javascript/jsc/bindings/webcore/JSDOMOperation.h b/src/javascript/jsc/bindings/webcore/JSDOMOperation.h new file mode 100644 index 0000000000..c3f6d0451c --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMOperation.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2003-2020 Apple Inc. All rights reserved. + * Copyright (C) 2007 Samuel Weinig + * Copyright (C) 2009 Google, Inc. All rights reserved. + * Copyright (C) 2012 Ericsson AB. All rights reserved. + * Copyright (C) 2013 Michael Pruett + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#pragma once + +#include "JSDOMCastThisValue.h" +#include "JSDOMExceptionHandling.h" + +namespace WebCore { + +template +class IDLOperation { +public: + using ClassParameter = JSClass*; + using Operation = JSC::EncodedJSValue(JSC::JSGlobalObject*, JSC::CallFrame*, ClassParameter); + using StaticOperation = JSC::EncodedJSValue(JSC::JSGlobalObject*, JSC::CallFrame*); + + // FIXME: Remove this after FunctionCallResolveNode is fixed not to pass resolved scope as |this| value. + // https://bugs.webkit.org/show_bug.cgi?id=225397 + static JSClass* cast(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame) + { + if constexpr (std::is_base_of_v) + return castThisValue(lexicalGlobalObject, callFrame.thisValue().toThis(&lexicalGlobalObject, JSC::ECMAMode::strict())); + else + return castThisValue(lexicalGlobalObject, callFrame.thisValue()); + } + + template + static JSC::EncodedJSValue call(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, const char* operationName) + { + auto throwScope = DECLARE_THROW_SCOPE(JSC::getVM(&lexicalGlobalObject)); + + auto* thisObject = cast(lexicalGlobalObject, callFrame); + if constexpr (shouldThrow != CastedThisErrorBehavior::Assert) { + if (UNLIKELY(!thisObject)) + return throwThisTypeError(lexicalGlobalObject, throwScope, JSClass::info()->className, operationName); + } else + ASSERT(thisObject); + + ASSERT_GC_OBJECT_INHERITS(thisObject, JSClass::info()); + + // FIXME: We should refactor the binding generated code to use references for lexicalGlobalObject and thisObject. + RELEASE_AND_RETURN(throwScope, (operation(&lexicalGlobalObject, &callFrame, thisObject))); + } + + template + static JSC::EncodedJSValue callStatic(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, const char*) + { + // FIXME: We should refactor the binding generated code to use references for lexicalGlobalObject. + return operation(&lexicalGlobalObject, &callFrame); + } +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSDOMURL.cpp b/src/javascript/jsc/bindings/webcore/JSDOMURL.cpp new file mode 100644 index 0000000000..b7efa19ae4 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMURL.cpp @@ -0,0 +1,846 @@ +/* + This file is part of the WebKit open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "root.h" +#include "JSDOMURL.h" + +#include "ActiveDOMObject.h" +#include "ExtendedDOMClientIsoSubspaces.h" +#include "ExtendedDOMIsoSubspaces.h" +#include "IDLTypes.h" +// #include "JSBlob.h" +#include "JSDOMAttribute.h" +#include "JSDOMBinding.h" +#include "JSDOMConstructor.h" +#include "JSDOMConvertBase.h" +#include "JSDOMConvertInterface.h" +#include "JSDOMConvertStrings.h" +#include "JSDOMExceptionHandling.h" +#include "JSDOMGlobalObject.h" +#include "JSDOMGlobalObjectInlines.h" +#include "JSDOMOperation.h" +#include "JSDOMURL.h" +#include "JSDOMWrapperCache.h" +#include "JSURLSearchParams.h" +#include "ScriptExecutionContext.h" +#include "WebCoreJSClientData.h" +#include "JavaScriptCore/FunctionPrototype.h" +#include "JavaScriptCore/HeapAnalyzer.h" +#include "JavaScriptCore/JSCInlines.h" +#include "JavaScriptCore/JSDestructibleObjectHeapCellType.h" +#include "JavaScriptCore/SlotVisitorMacros.h" +#include "JavaScriptCore/SubspaceInlines.h" +#include "wtf/GetPtr.h" +#include "wtf/PointerPreparations.h" +#include "wtf/URL.h" + +#if ENABLE(MEDIA_SOURCE) +#include "DOMURLMediaSource.h" +#include "JSMediaSource.h" +#endif + +namespace WebCore { +using namespace JSC; + +// Functions + +static JSC_DECLARE_HOST_FUNCTION(jsDOMURLPrototypeFunction_toJSON); +static JSC_DECLARE_HOST_FUNCTION(jsDOMURLConstructorFunction_createObjectURL); +static JSC_DECLARE_HOST_FUNCTION(jsDOMURLConstructorFunction_revokeObjectURL); +static JSC_DECLARE_HOST_FUNCTION(jsDOMURLPrototypeFunction_toString); + +// Attributes + +static JSC_DECLARE_CUSTOM_GETTER(jsDOMURLConstructor); +static JSC_DECLARE_CUSTOM_GETTER(jsDOMURL_href); +static JSC_DECLARE_CUSTOM_SETTER(setJSDOMURL_href); +static JSC_DECLARE_CUSTOM_GETTER(jsDOMURL_origin); +static JSC_DECLARE_CUSTOM_GETTER(jsDOMURL_protocol); +static JSC_DECLARE_CUSTOM_SETTER(setJSDOMURL_protocol); +static JSC_DECLARE_CUSTOM_GETTER(jsDOMURL_username); +static JSC_DECLARE_CUSTOM_SETTER(setJSDOMURL_username); +static JSC_DECLARE_CUSTOM_GETTER(jsDOMURL_password); +static JSC_DECLARE_CUSTOM_SETTER(setJSDOMURL_password); +static JSC_DECLARE_CUSTOM_GETTER(jsDOMURL_host); +static JSC_DECLARE_CUSTOM_SETTER(setJSDOMURL_host); +static JSC_DECLARE_CUSTOM_GETTER(jsDOMURL_hostname); +static JSC_DECLARE_CUSTOM_SETTER(setJSDOMURL_hostname); +static JSC_DECLARE_CUSTOM_GETTER(jsDOMURL_port); +static JSC_DECLARE_CUSTOM_SETTER(setJSDOMURL_port); +static JSC_DECLARE_CUSTOM_GETTER(jsDOMURL_pathname); +static JSC_DECLARE_CUSTOM_SETTER(setJSDOMURL_pathname); +static JSC_DECLARE_CUSTOM_GETTER(jsDOMURL_hash); +static JSC_DECLARE_CUSTOM_SETTER(setJSDOMURL_hash); +static JSC_DECLARE_CUSTOM_GETTER(jsDOMURL_search); +static JSC_DECLARE_CUSTOM_SETTER(setJSDOMURL_search); +static JSC_DECLARE_CUSTOM_GETTER(jsDOMURL_searchParams); + +class JSDOMURLPrototype final : public JSC::JSNonFinalObject { +public: + using Base = JSC::JSNonFinalObject; + static JSDOMURLPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) + { + JSDOMURLPrototype* ptr = new (NotNull, JSC::allocateCell(vm)) JSDOMURLPrototype(vm, globalObject, structure); + ptr->finishCreation(vm); + return ptr; + } + + DECLARE_INFO; + template + static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSDOMURLPrototype, Base); + return &vm.plainObjectSpace(); + } + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); + } + +private: + JSDOMURLPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) + : JSC::JSNonFinalObject(vm, structure) + { + } + + void finishCreation(JSC::VM&); +}; +STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSDOMURLPrototype, JSDOMURLPrototype::Base); + +using JSDOMURLDOMConstructor = JSDOMConstructor; + +/* Hash table for constructor */ + +static const HashTableValue JSDOMURLConstructorTableValues[] = { + { "createObjectURL", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsDOMURLConstructorFunction_createObjectURL), (intptr_t)(1) } }, + { "revokeObjectURL", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsDOMURLConstructorFunction_revokeObjectURL), (intptr_t)(1) } }, +}; + +static inline EncodedJSValue constructJSDOMURL1(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame) +{ + VM& vm = lexicalGlobalObject->vm(); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto* castedThis = jsCast(callFrame->jsCallee()); + ASSERT(castedThis); + EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); + auto url = convert(*lexicalGlobalObject, argument0.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + EnsureStillAliveScope argument1 = callFrame->argument(1); + auto base = argument1.value().isUndefined() ? String() : convert(*lexicalGlobalObject, argument1.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + auto object = DOMURL::create(WTFMove(url), WTFMove(base)); + if constexpr (IsExceptionOr) + RETURN_IF_EXCEPTION(throwScope, {}); + static_assert(TypeOrExceptionOrUnderlyingType::isRef); + auto jsValue = toJSNewlyCreated>(*lexicalGlobalObject, *castedThis->globalObject(), throwScope, WTFMove(object)); + if constexpr (IsExceptionOr) + RETURN_IF_EXCEPTION(throwScope, {}); + setSubclassStructureIfNeeded(lexicalGlobalObject, callFrame, asObject(jsValue)); + RETURN_IF_EXCEPTION(throwScope, {}); + return JSValue::encode(jsValue); +} + +static inline EncodedJSValue constructJSDOMURL2(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame) +{ + VM& vm = lexicalGlobalObject->vm(); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto* castedThis = jsCast(callFrame->jsCallee()); + ASSERT(castedThis); + EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); + auto url = convert(*lexicalGlobalObject, argument0.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + EnsureStillAliveScope argument1 = callFrame->uncheckedArgument(1); + auto base = convert>(*lexicalGlobalObject, argument1.value(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentTypeError(lexicalGlobalObject, scope, 1, "base", "URL", nullptr, "DOMURL"); }); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + auto object = DOMURL::create(WTFMove(url), *base); + if constexpr (IsExceptionOr) + RETURN_IF_EXCEPTION(throwScope, {}); + static_assert(TypeOrExceptionOrUnderlyingType::isRef); + auto jsValue = toJSNewlyCreated>(*lexicalGlobalObject, *castedThis->globalObject(), throwScope, WTFMove(object)); + if constexpr (IsExceptionOr) + RETURN_IF_EXCEPTION(throwScope, {}); + setSubclassStructureIfNeeded(lexicalGlobalObject, callFrame, asObject(jsValue)); + RETURN_IF_EXCEPTION(throwScope, {}); + return JSValue::encode(jsValue); +} + +template<> EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSDOMURLDOMConstructor::construct(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame) +{ + VM& vm = lexicalGlobalObject->vm(); + auto throwScope = DECLARE_THROW_SCOPE(vm); + UNUSED_PARAM(throwScope); + size_t argsCount = std::min(2, callFrame->argumentCount()); + if (argsCount == 1) { + RELEASE_AND_RETURN(throwScope, (constructJSDOMURL1(lexicalGlobalObject, callFrame))); + } + if (argsCount == 2) { + JSValue distinguishingArg = callFrame->uncheckedArgument(1); + if (distinguishingArg.isUndefined()) + RELEASE_AND_RETURN(throwScope, (constructJSDOMURL1(lexicalGlobalObject, callFrame))); + if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits(vm)) + RELEASE_AND_RETURN(throwScope, (constructJSDOMURL2(lexicalGlobalObject, callFrame))); + RELEASE_AND_RETURN(throwScope, (constructJSDOMURL1(lexicalGlobalObject, callFrame))); + } + return argsCount < 1 ? throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)) : throwVMTypeError(lexicalGlobalObject, throwScope); +} +JSC_ANNOTATE_HOST_FUNCTION(JSDOMURLConstructorConstruct, JSDOMURLDOMConstructor::construct); + +template<> const ClassInfo JSDOMURLDOMConstructor::s_info = { "URL"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMURLDOMConstructor) }; + +template<> JSValue JSDOMURLDOMConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) +{ + UNUSED_PARAM(vm); + return globalObject.functionPrototype(); +} + +template<> void JSDOMURLDOMConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) +{ + putDirect(vm, vm.propertyNames->length, jsNumber(1), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); + JSString* nameString = jsNontrivialString(vm, "URL"_s); + m_originalName.set(vm, this, nameString); + putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); + putDirect(vm, vm.propertyNames->prototype, JSDOMURL::prototype(vm, globalObject), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete); + reifyStaticProperties(vm, JSDOMURL::info(), JSDOMURLConstructorTableValues, *this); +} + +/* Hash table for prototype */ + +static const HashTableValue JSDOMURLPrototypeTableValues[] = { + { "constructor", static_cast(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t) static_cast(jsDOMURLConstructor), (intptr_t) static_cast(0) } }, + { "href", static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast(jsDOMURL_href), (intptr_t) static_cast(setJSDOMURL_href) } }, + { "origin", static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast(jsDOMURL_origin), (intptr_t) static_cast(0) } }, + { "protocol", static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast(jsDOMURL_protocol), (intptr_t) static_cast(setJSDOMURL_protocol) } }, + { "username", static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast(jsDOMURL_username), (intptr_t) static_cast(setJSDOMURL_username) } }, + { "password", static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast(jsDOMURL_password), (intptr_t) static_cast(setJSDOMURL_password) } }, + { "host", static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast(jsDOMURL_host), (intptr_t) static_cast(setJSDOMURL_host) } }, + { "hostname", static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast(jsDOMURL_hostname), (intptr_t) static_cast(setJSDOMURL_hostname) } }, + { "port", static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast(jsDOMURL_port), (intptr_t) static_cast(setJSDOMURL_port) } }, + { "pathname", static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast(jsDOMURL_pathname), (intptr_t) static_cast(setJSDOMURL_pathname) } }, + { "hash", static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast(jsDOMURL_hash), (intptr_t) static_cast(setJSDOMURL_hash) } }, + { "search", static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast(jsDOMURL_search), (intptr_t) static_cast(setJSDOMURL_search) } }, + { "searchParams", static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast(jsDOMURL_searchParams), (intptr_t) static_cast(0) } }, + { "toJSON", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsDOMURLPrototypeFunction_toJSON), (intptr_t)(0) } }, + { "toString", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsDOMURLPrototypeFunction_toString), (intptr_t)(0) } }, +}; + +const ClassInfo JSDOMURLPrototype::s_info = { "URL"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMURLPrototype) }; + +void JSDOMURLPrototype::finishCreation(VM& vm) +{ + Base::finishCreation(vm); + reifyStaticProperties(vm, JSDOMURL::info(), JSDOMURLPrototypeTableValues, *this); + JSC_TO_STRING_TAG_WITHOUT_TRANSITION(); +} + +const ClassInfo JSDOMURL::s_info = { "URL"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMURL) }; + +JSDOMURL::JSDOMURL(Structure* structure, JSDOMGlobalObject& globalObject, Ref&& impl) + : JSDOMWrapper(structure, globalObject, WTFMove(impl)) +{ +} + +void JSDOMURL::finishCreation(VM& vm) +{ + Base::finishCreation(vm); + ASSERT(inherits(vm, info())); + + // static_assert(!std::is_base_of::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject."); +} + +JSObject* JSDOMURL::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) +{ + return JSDOMURLPrototype::create(vm, &globalObject, JSDOMURLPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); +} + +JSObject* JSDOMURL::prototype(VM& vm, JSDOMGlobalObject& globalObject) +{ + return getDOMPrototype(vm, globalObject); +} + +JSValue JSDOMURL::getConstructor(VM& vm, const JSGlobalObject* globalObject) +{ + return getDOMConstructor(vm, *jsCast(globalObject)); +} + +void JSDOMURL::destroy(JSC::JSCell* cell) +{ + JSDOMURL* thisObject = static_cast(cell); + thisObject->JSDOMURL::~JSDOMURL(); +} + +JSC_DEFINE_CUSTOM_GETTER(jsDOMURLConstructor, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto* prototype = jsDynamicCast(vm, JSValue::decode(thisValue)); + if (UNLIKELY(!prototype)) + return throwVMTypeError(lexicalGlobalObject, throwScope); + return JSValue::encode(JSDOMURL::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); +} + +static inline JSValue jsDOMURL_hrefGetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.href()))); +} + +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_href, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); +} + +static inline bool setJSDOMURL_hrefSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + auto nativeValue = convert(lexicalGlobalObject, value); + RETURN_IF_EXCEPTION(throwScope, false); + invokeFunctorPropagatingExceptionIfNecessary(lexicalGlobalObject, throwScope, [&] { + return impl.setHref(WTFMove(nativeValue)); + }); + return true; +} + +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_href, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) +{ + return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); +} + +static inline JSValue jsDOMURL_originGetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.origin()))); +} + +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_origin, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); +} + +static inline JSValue jsDOMURL_protocolGetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.protocol()))); +} + +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_protocol, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); +} + +static inline bool setJSDOMURL_protocolSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + auto nativeValue = convert(lexicalGlobalObject, value); + RETURN_IF_EXCEPTION(throwScope, false); + invokeFunctorPropagatingExceptionIfNecessary(lexicalGlobalObject, throwScope, [&] { + return impl.setProtocol(WTFMove(nativeValue)); + }); + return true; +} + +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_protocol, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) +{ + return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); +} + +static inline JSValue jsDOMURL_usernameGetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.username()))); +} + +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_username, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); +} + +static inline bool setJSDOMURL_usernameSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + auto nativeValue = convert(lexicalGlobalObject, value); + RETURN_IF_EXCEPTION(throwScope, false); + invokeFunctorPropagatingExceptionIfNecessary(lexicalGlobalObject, throwScope, [&] { + return impl.setUsername(WTFMove(nativeValue)); + }); + return true; +} + +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_username, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) +{ + return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); +} + +static inline JSValue jsDOMURL_passwordGetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.password()))); +} + +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_password, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); +} + +static inline bool setJSDOMURL_passwordSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + auto nativeValue = convert(lexicalGlobalObject, value); + RETURN_IF_EXCEPTION(throwScope, false); + invokeFunctorPropagatingExceptionIfNecessary(lexicalGlobalObject, throwScope, [&] { + return impl.setPassword(WTFMove(nativeValue)); + }); + return true; +} + +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_password, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) +{ + return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); +} + +static inline JSValue jsDOMURL_hostGetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.host()))); +} + +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_host, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); +} + +static inline bool setJSDOMURL_hostSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + auto nativeValue = convert(lexicalGlobalObject, value); + RETURN_IF_EXCEPTION(throwScope, false); + invokeFunctorPropagatingExceptionIfNecessary(lexicalGlobalObject, throwScope, [&] { + return impl.setHost(WTFMove(nativeValue)); + }); + return true; +} + +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_host, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) +{ + return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); +} + +static inline JSValue jsDOMURL_hostnameGetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.hostname()))); +} + +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_hostname, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); +} + +static inline bool setJSDOMURL_hostnameSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + auto nativeValue = convert(lexicalGlobalObject, value); + RETURN_IF_EXCEPTION(throwScope, false); + invokeFunctorPropagatingExceptionIfNecessary(lexicalGlobalObject, throwScope, [&] { + return impl.setHostname(WTFMove(nativeValue)); + }); + return true; +} + +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_hostname, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) +{ + return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); +} + +static inline JSValue jsDOMURL_portGetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.port()))); +} + +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_port, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); +} + +static inline bool setJSDOMURL_portSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + auto nativeValue = convert(lexicalGlobalObject, value); + RETURN_IF_EXCEPTION(throwScope, false); + invokeFunctorPropagatingExceptionIfNecessary(lexicalGlobalObject, throwScope, [&] { + return impl.setPort(WTFMove(nativeValue)); + }); + return true; +} + +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_port, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) +{ + return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); +} + +static inline JSValue jsDOMURL_pathnameGetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.pathname()))); +} + +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_pathname, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); +} + +static inline bool setJSDOMURL_pathnameSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + auto nativeValue = convert(lexicalGlobalObject, value); + RETURN_IF_EXCEPTION(throwScope, false); + invokeFunctorPropagatingExceptionIfNecessary(lexicalGlobalObject, throwScope, [&] { + return impl.setPathname(WTFMove(nativeValue)); + }); + return true; +} + +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_pathname, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) +{ + return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); +} + +static inline JSValue jsDOMURL_hashGetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.hash()))); +} + +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_hash, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); +} + +static inline bool setJSDOMURL_hashSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + auto nativeValue = convert(lexicalGlobalObject, value); + RETURN_IF_EXCEPTION(throwScope, false); + invokeFunctorPropagatingExceptionIfNecessary(lexicalGlobalObject, throwScope, [&] { + return impl.setHash(WTFMove(nativeValue)); + }); + return true; +} + +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_hash, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) +{ + return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); +} + +static inline JSValue jsDOMURL_searchGetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.search()))); +} + +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_search, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); +} + +static inline bool setJSDOMURL_searchSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto& impl = thisObject.wrapped(); + auto nativeValue = convert(lexicalGlobalObject, value); + RETURN_IF_EXCEPTION(throwScope, false); + invokeFunctorPropagatingExceptionIfNecessary(lexicalGlobalObject, throwScope, [&] { + return impl.setSearch(WTFMove(nativeValue)); + }); + return true; +} + +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_search, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) +{ + return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); +} + +static inline JSValue jsDOMURL_searchParamsGetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject) +{ + auto& vm = JSC::getVM(&lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + if (JSValue cachedValue = thisObject.m_searchParams.get()) + return cachedValue; + auto& impl = thisObject.wrapped(); + JSValue result = toJS>(lexicalGlobalObject, *thisObject.globalObject(), throwScope, impl.searchParams()); + RETURN_IF_EXCEPTION(throwScope, {}); + thisObject.m_searchParams.set(JSC::getVM(&lexicalGlobalObject), &thisObject, result); + return result; +} + +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_searchParams, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); +} + +static inline JSC::EncodedJSValue jsDOMURLPrototypeFunction_toJSONBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis) +{ + auto& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + UNUSED_PARAM(throwScope); + UNUSED_PARAM(callFrame); + auto& impl = castedThis->wrapped(); + RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS(*lexicalGlobalObject, throwScope, impl.toJSON()))); +} + +JSC_DEFINE_HOST_FUNCTION(jsDOMURLPrototypeFunction_toJSON, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "toJSON"); +} + +static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_createObjectURL1Body(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame) +{ + // auto& vm = JSC::getVM(lexicalGlobalObject); + // auto throwScope = DECLARE_THROW_SCOPE(vm); + // UNUSED_PARAM(throwScope); + // UNUSED_PARAM(callFrame); + // auto* context = jsCast(lexicalGlobalObject)->scriptExecutionContext(); + // if (UNLIKELY(!context)) + return JSValue::encode(jsUndefined()); + // EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); + // auto blob = convert>(*lexicalGlobalObject, argument0.value(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentTypeError(lexicalGlobalObject, scope, 0, "blob", "URL", "createObjectURL", "Blob"); }); + // RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + // RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS(*lexicalGlobalObject, throwScope, DOMURL::createObjectURL(*context, *blob)))); +} + +static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_revokeObjectURLBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame) +{ + // auto& vm = JSC::getVM(lexicalGlobalObject); + // auto throwScope = DECLARE_THROW_SCOPE(vm); + // UNUSED_PARAM(throwScope); + // UNUSED_PARAM(callFrame); + // if (UNLIKELY(callFrame->argumentCount() < 1)) + // return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); + // auto* context = jsCast(lexicalGlobalObject)->scriptExecutionContext(); + // if (UNLIKELY(!context)) + return JSValue::encode(jsUndefined()); + // EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); + // auto url = convert(*lexicalGlobalObject, argument0.value()); + // RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + // RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { return DOMURL::revokeObjectURL(*context, WTFMove(url)); }))); +} + +JSC_DEFINE_HOST_FUNCTION(jsDOMURLConstructorFunction_revokeObjectURL, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::callStatic(*lexicalGlobalObject, *callFrame, "revokeObjectURL"); +} + +#if ENABLE(MEDIA_SOURCE) +static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_createObjectURL2Body(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame) +{ + // auto& vm = JSC::getVM(lexicalGlobalObject); + // auto throwScope = DECLARE_THROW_SCOPE(vm); + // UNUSED_PARAM(throwScope); + // UNUSED_PARAM(callFrame); + // auto* context = jsCast(lexicalGlobalObject)->scriptExecutionContext(); + // if (UNLIKELY(!context)) + return JSValue::encode(jsUndefined()); + // EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); + // auto source = convert>(*lexicalGlobalObject, argument0.value(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentTypeError(lexicalGlobalObject, scope, 0, "source", "URL", "createObjectURL", "MediaSource"); }); + // RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + // RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS(*lexicalGlobalObject, throwScope, WebCore::DOMURLMediaSource::createObjectURL(*context, *source)))); +} + +#endif + +static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_createObjectURLOverloadDispatcher(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame) +{ + return JSValue::encode(jsUndefined()); + + // auto& vm = JSC::getVM(lexicalGlobalObject); + // auto throwScope = DECLARE_THROW_SCOPE(vm); + // UNUSED_PARAM(throwScope); + UNUSED_PARAM(callFrame); + // size_t argsCount = std::min(1, callFrame->argumentCount()); + // if (argsCount == 1) { + // JSValue distinguishingArg = callFrame->uncheckedArgument(0); + // if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits(vm)) + // RELEASE_AND_RETURN(throwScope, (jsDOMURLConstructorFunction_createObjectURL1Body(lexicalGlobalObject, callFrame))); + // #if ENABLE(MEDIA_SOURCE) + // if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits(vm)) + // RELEASE_AND_RETURN(throwScope, (jsDOMURLConstructorFunction_createObjectURL2Body(lexicalGlobalObject, callFrame))); + // #endif + // } + // return argsCount < 1 ? throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)) : throwVMTypeError(lexicalGlobalObject, throwScope); +} + +JSC_DEFINE_HOST_FUNCTION(jsDOMURLConstructorFunction_createObjectURL, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::callStatic(*lexicalGlobalObject, *callFrame, "createObjectURL"); +} + +static inline JSC::EncodedJSValue jsDOMURLPrototypeFunction_toStringBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis) +{ + auto& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + UNUSED_PARAM(throwScope); + UNUSED_PARAM(callFrame); + auto& impl = castedThis->wrapped(); + RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS(*lexicalGlobalObject, throwScope, impl.href()))); +} + +JSC_DEFINE_HOST_FUNCTION(jsDOMURLPrototypeFunction_toString, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "toString"); +} + +JSC::GCClient::IsoSubspace* JSDOMURL::subspaceForImpl(JSC::VM& vm) +{ + return WebCore::subspaceForImpl( + vm, + [](auto& spaces) { return spaces.m_clientSubspaceForDOMURL.get(); }, + [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForDOMURL = WTFMove(space); }, + [](auto& spaces) { return spaces.m_subspaceForDOMURL.get(); }, + [](auto& spaces, auto&& space) { spaces.m_subspaceForDOMURL = WTFMove(space); }); +} + +template +void JSDOMURL::visitChildrenImpl(JSCell* cell, Visitor& visitor) +{ + auto* thisObject = jsCast(cell); + ASSERT_GC_OBJECT_INHERITS(thisObject, info()); + Base::visitChildren(thisObject, visitor); + visitor.append(thisObject->m_searchParams); +} + +DEFINE_VISIT_CHILDREN(JSDOMURL); + +void JSDOMURL::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer) +{ + auto* thisObject = jsCast(cell); + analyzer.setWrappedObjectForCell(cell, &thisObject->wrapped()); + // if (thisObject->scriptExecutionContext()) + // analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); + Base::analyzeHeap(cell, analyzer); +} + +JSDOMURLOwner::~JSDOMURLOwner() +{ +} + +bool JSDOMURLOwner::isReachableFromOpaqueRoots(JSC::Handle handle, void*, AbstractSlotVisitor& visitor, const char** reason) +{ + UNUSED_PARAM(handle); + UNUSED_PARAM(visitor); + UNUSED_PARAM(reason); + return false; +} + +void JSDOMURLOwner::finalize(JSC::Handle handle, void* context) +{ + auto* jsDOMURL = static_cast(handle.slot()->asCell()); + auto& world = *static_cast(context); + uncacheWrapper(world, &jsDOMURL->wrapped(), jsDOMURL); +} + +#if ENABLE(BINDING_INTEGRITY) +#if PLATFORM(WIN) +#pragma warning(disable : 4483) +extern "C" { +extern void (*const __identifier("??_7DOMURL@WebCore@@6B@")[])(); +} +#else +extern "C" { +extern void* _ZTVN7WebCore6DOMURLE[]; +} +#endif +#endif + +JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject*, JSDOMGlobalObject* globalObject, Ref&& impl) +{ + + if constexpr (std::is_polymorphic_v) { +#if ENABLE(BINDING_INTEGRITY) + const void* actualVTablePointer = getVTablePointer(impl.ptr()); +#if PLATFORM(WIN) + void* expectedVTablePointer = __identifier("??_7DOMURL@WebCore@@6B@"); +#else + void* expectedVTablePointer = &_ZTVN7WebCore6DOMURLE[2]; +#endif + + // If you hit this assertion you either have a use after free bug, or + // DOMURL has subclasses. If DOMURL has subclasses that get passed + // to toJS() we currently require DOMURL you to opt out of binding hardening + // by adding the SkipVTableValidation attribute to the interface IDL definition + RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer); +#endif + } + return createWrapper(globalObject, WTFMove(impl)); +} + +JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, DOMURL& impl) +{ + return wrap(lexicalGlobalObject, globalObject, impl); +} + +DOMURL* JSDOMURL::toWrapped(JSC::VM& vm, JSC::JSValue value) +{ + if (auto* wrapper = jsDynamicCast(vm, value)) + return &wrapper->wrapped(); + return nullptr; +} + +} diff --git a/src/javascript/jsc/bindings/webcore/JSDOMURL.h b/src/javascript/jsc/bindings/webcore/JSDOMURL.h new file mode 100644 index 0000000000..e89add235b --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSDOMURL.h @@ -0,0 +1,98 @@ +/* + This file is part of the WebKit open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#pragma once + +#include "DOMURL.h" +#include "JSDOMWrapper.h" +#include "wtf/NeverDestroyed.h" + +namespace WebCore { + +class WEBCORE_EXPORT JSDOMURL : public JSDOMWrapper { +public: + using Base = JSDOMWrapper; + static JSDOMURL* create(JSC::Structure* structure, JSDOMGlobalObject* globalObject, Ref&& impl) + { + JSDOMURL* ptr = new (NotNull, JSC::allocateCell(globalObject->vm())) JSDOMURL(structure, *globalObject, WTFMove(impl)); + ptr->finishCreation(globalObject->vm()); + return ptr; + } + + static JSC::JSObject* createPrototype(JSC::VM&, JSDOMGlobalObject&); + static JSC::JSObject* prototype(JSC::VM&, JSDOMGlobalObject&); + static DOMURL* toWrapped(JSC::VM&, JSC::JSValue); + static void destroy(JSC::JSCell*); + + DECLARE_INFO; + + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info(), JSC::NonArray); + } + + static JSC::JSValue getConstructor(JSC::VM&, const JSC::JSGlobalObject*); + mutable JSC::WriteBarrier m_searchParams; + template static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + if constexpr (mode == JSC::SubspaceAccess::Concurrently) + return nullptr; + return subspaceForImpl(vm); + } + static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm); + DECLARE_VISIT_CHILDREN; + + static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&); + +protected: + JSDOMURL(JSC::Structure*, JSDOMGlobalObject&, Ref&&); + + void finishCreation(JSC::VM&); +}; + +class JSDOMURLOwner final : public JSC::WeakHandleOwner { +public: + ~JSDOMURLOwner() final; + bool isReachableFromOpaqueRoots(JSC::Handle, void* context, JSC::AbstractSlotVisitor&, const char**) final; + void finalize(JSC::Handle, void* context) final; +}; + +inline JSC::WeakHandleOwner* wrapperOwner(DOMWrapperWorld&, DOMURL*) +{ + static NeverDestroyed owner; + return &owner.get(); +} + +inline void* wrapperKey(DOMURL* wrappableObject) +{ + return wrappableObject; +} + +WEBCORE_EXPORT JSC::JSValue toJS(JSC::JSGlobalObject*, JSDOMGlobalObject*, DOMURL&); +inline JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, DOMURL* impl) { return impl ? toJS(lexicalGlobalObject, globalObject, *impl) : JSC::jsNull(); } +JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject*, JSDOMGlobalObject*, Ref&&); +inline JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, RefPtr&& impl) { return impl ? toJSNewlyCreated(lexicalGlobalObject, globalObject, impl.releaseNonNull()) : JSC::jsNull(); } + +template<> struct JSDOMWrapperConverterTraits { + using WrapperClass = JSDOMURL; + using ToWrappedReturnType = DOMURL*; +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSURLSearchParams.cpp b/src/javascript/jsc/bindings/webcore/JSURLSearchParams.cpp new file mode 100644 index 0000000000..92311cf495 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSURLSearchParams.cpp @@ -0,0 +1,559 @@ +/* + This file is part of the WebKit open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" +#include "JSURLSearchParams.h" + +#include "ActiveDOMObject.h" +#include "ExtendedDOMClientIsoSubspaces.h" +#include "ExtendedDOMIsoSubspaces.h" +#include "IDLTypes.h" +#include "JSDOMBinding.h" +#include "JSDOMConstructor.h" +#include "JSDOMConvertBase.h" +#include "JSDOMConvertBoolean.h" +#include "JSDOMConvertInterface.h" +#include "JSDOMConvertNullable.h" +#include "JSDOMConvertRecord.h" +#include "JSDOMConvertSequences.h" +#include "JSDOMConvertStrings.h" +#include "JSDOMConvertUnion.h" +#include "JSDOMExceptionHandling.h" +#include "JSDOMGlobalObject.h" +#include "JSDOMGlobalObjectInlines.h" +#include "JSDOMIterator.h" +#include "JSDOMOperation.h" +#include "JSDOMWrapperCache.h" +#include "JavaScriptCore/BuiltinNames.h" +#include "JavaScriptCore/FunctionPrototype.h" +#include "JavaScriptCore/HeapAnalyzer.h" +#include "JavaScriptCore/JSArray.h" +#include "JavaScriptCore/JSCInlines.h" +#include "JavaScriptCore/JSDestructibleObjectHeapCellType.h" +#include "JavaScriptCore/SlotVisitorMacros.h" +#include "JavaScriptCore/SubspaceInlines.h" +#include "ScriptExecutionContext.h" +#include "WebCoreJSClientData.h" +#include "wtf/GetPtr.h" +#include "wtf/PointerPreparations.h" +#include "wtf/URL.h" +#include "wtf/Vector.h" +#include + +namespace WebCore { +using namespace JSC; + +// Functions + +static JSC_DECLARE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_append); +static JSC_DECLARE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_delete); +static JSC_DECLARE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_get); +static JSC_DECLARE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_getAll); +static JSC_DECLARE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_has); +static JSC_DECLARE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_set); +static JSC_DECLARE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_sort); +static JSC_DECLARE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_entries); +static JSC_DECLARE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_keys); +static JSC_DECLARE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_values); +static JSC_DECLARE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_forEach); +static JSC_DECLARE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_toString); + +// Attributes + +static JSC_DECLARE_CUSTOM_GETTER(jsURLSearchParamsConstructor); + +class JSURLSearchParamsPrototype final : public JSC::JSNonFinalObject { +public: + using Base = JSC::JSNonFinalObject; + static JSURLSearchParamsPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) + { + JSURLSearchParamsPrototype* ptr = new (NotNull, JSC::allocateCell(vm)) JSURLSearchParamsPrototype(vm, globalObject, structure); + ptr->finishCreation(vm); + return ptr; + } + + DECLARE_INFO; + template + static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSURLSearchParamsPrototype, Base); + return &vm.plainObjectSpace(); + } + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); + } + +private: + JSURLSearchParamsPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) + : JSC::JSNonFinalObject(vm, structure) + { + } + + void finishCreation(JSC::VM&); +}; +STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSURLSearchParamsPrototype, JSURLSearchParamsPrototype::Base); + +using JSURLSearchParamsDOMConstructor = JSDOMConstructor; + +template<> EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSURLSearchParamsDOMConstructor::construct(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame) +{ + VM& vm = lexicalGlobalObject->vm(); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto* castedThis = jsCast(callFrame->jsCallee()); + ASSERT(castedThis); + EnsureStillAliveScope argument0 = callFrame->argument(0); + auto init = argument0.value().isUndefined() ? emptyString() : convert>, IDLRecord, IDLUSVString>>(*lexicalGlobalObject, argument0.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + auto object = URLSearchParams::create(WTFMove(init)); + if constexpr (IsExceptionOr) + RETURN_IF_EXCEPTION(throwScope, {}); + static_assert(TypeOrExceptionOrUnderlyingType::isRef); + auto jsValue = toJSNewlyCreated>(*lexicalGlobalObject, *castedThis->globalObject(), throwScope, WTFMove(object)); + if constexpr (IsExceptionOr) + RETURN_IF_EXCEPTION(throwScope, {}); + setSubclassStructureIfNeeded(lexicalGlobalObject, callFrame, asObject(jsValue)); + RETURN_IF_EXCEPTION(throwScope, {}); + return JSValue::encode(jsValue); +} +JSC_ANNOTATE_HOST_FUNCTION(JSURLSearchParamsDOMConstructorConstruct, JSURLSearchParamsDOMConstructor::construct); + +template<> const ClassInfo JSURLSearchParamsDOMConstructor::s_info = { "URLSearchParams"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSURLSearchParamsDOMConstructor) }; + +template<> JSValue JSURLSearchParamsDOMConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) +{ + UNUSED_PARAM(vm); + return globalObject.functionPrototype(); +} + +template<> void JSURLSearchParamsDOMConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) +{ + putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); + JSString* nameString = jsNontrivialString(vm, "URLSearchParams"_s); + m_originalName.set(vm, this, nameString); + putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); + putDirect(vm, vm.propertyNames->prototype, JSURLSearchParams::prototype(vm, globalObject), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete); +} + +/* Hash table for prototype */ + +static const HashTableValue JSURLSearchParamsPrototypeTableValues[] = { + { "constructor", static_cast(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t) static_cast(jsURLSearchParamsConstructor), (intptr_t) static_cast(0) } }, + { "append", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsURLSearchParamsPrototypeFunction_append), (intptr_t)(2) } }, + { "delete", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsURLSearchParamsPrototypeFunction_delete), (intptr_t)(1) } }, + { "get", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsURLSearchParamsPrototypeFunction_get), (intptr_t)(1) } }, + { "getAll", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsURLSearchParamsPrototypeFunction_getAll), (intptr_t)(1) } }, + { "has", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsURLSearchParamsPrototypeFunction_has), (intptr_t)(1) } }, + { "set", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsURLSearchParamsPrototypeFunction_set), (intptr_t)(2) } }, + { "sort", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsURLSearchParamsPrototypeFunction_sort), (intptr_t)(0) } }, + { "entries", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsURLSearchParamsPrototypeFunction_entries), (intptr_t)(0) } }, + { "keys", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsURLSearchParamsPrototypeFunction_keys), (intptr_t)(0) } }, + { "values", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsURLSearchParamsPrototypeFunction_values), (intptr_t)(0) } }, + { "forEach", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsURLSearchParamsPrototypeFunction_forEach), (intptr_t)(1) } }, + { "toString", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsURLSearchParamsPrototypeFunction_toString), (intptr_t)(0) } }, +}; + +const ClassInfo JSURLSearchParamsPrototype::s_info = { "URLSearchParams"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSURLSearchParamsPrototype) }; + +void JSURLSearchParamsPrototype::finishCreation(VM& vm) +{ + Base::finishCreation(vm); + reifyStaticProperties(vm, JSURLSearchParams::info(), JSURLSearchParamsPrototypeTableValues, *this); + putDirect(vm, vm.propertyNames->iteratorSymbol, getDirect(vm, vm.propertyNames->builtinNames().entriesPublicName()), static_cast(JSC::PropertyAttribute::DontEnum)); + JSC_TO_STRING_TAG_WITHOUT_TRANSITION(); +} + +const ClassInfo JSURLSearchParams::s_info = { "URLSearchParams"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSURLSearchParams) }; + +JSURLSearchParams::JSURLSearchParams(Structure* structure, JSDOMGlobalObject& globalObject, Ref&& impl) + : JSDOMWrapper(structure, globalObject, WTFMove(impl)) +{ +} + +void JSURLSearchParams::finishCreation(VM& vm) +{ + Base::finishCreation(vm); + ASSERT(inherits(vm, info())); + + // static_assert(!std::is_base_of::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject."); +} + +JSObject* JSURLSearchParams::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) +{ + return JSURLSearchParamsPrototype::create(vm, &globalObject, JSURLSearchParamsPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); +} + +JSObject* JSURLSearchParams::prototype(VM& vm, JSDOMGlobalObject& globalObject) +{ + return getDOMPrototype(vm, globalObject); +} + +JSValue JSURLSearchParams::getConstructor(VM& vm, const JSGlobalObject* globalObject) +{ + return getDOMConstructor(vm, *jsCast(globalObject)); +} + +void JSURLSearchParams::destroy(JSC::JSCell* cell) +{ + JSURLSearchParams* thisObject = static_cast(cell); + thisObject->JSURLSearchParams::~JSURLSearchParams(); +} + +JSC_DEFINE_CUSTOM_GETTER(jsURLSearchParamsConstructor, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto* prototype = jsDynamicCast(vm, JSValue::decode(thisValue)); + if (UNLIKELY(!prototype)) + return throwVMTypeError(lexicalGlobalObject, throwScope); + return JSValue::encode(JSURLSearchParams::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); +} + +static inline JSC::EncodedJSValue jsURLSearchParamsPrototypeFunction_appendBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis) +{ + auto& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + UNUSED_PARAM(throwScope); + UNUSED_PARAM(callFrame); + auto& impl = castedThis->wrapped(); + if (UNLIKELY(callFrame->argumentCount() < 2)) + return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); + EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); + auto name = convert(*lexicalGlobalObject, argument0.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + EnsureStillAliveScope argument1 = callFrame->uncheckedArgument(1); + auto value = convert(*lexicalGlobalObject, argument1.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { return impl.append(WTFMove(name), WTFMove(value)); }))); +} + +JSC_DEFINE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_append, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "append"); +} + +static inline JSC::EncodedJSValue jsURLSearchParamsPrototypeFunction_deleteBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis) +{ + auto& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + UNUSED_PARAM(throwScope); + UNUSED_PARAM(callFrame); + auto& impl = castedThis->wrapped(); + if (UNLIKELY(callFrame->argumentCount() < 1)) + return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); + EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); + auto name = convert(*lexicalGlobalObject, argument0.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { return impl.remove(WTFMove(name)); }))); +} + +JSC_DEFINE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_delete, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "delete"); +} + +static inline JSC::EncodedJSValue jsURLSearchParamsPrototypeFunction_getBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis) +{ + auto& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + UNUSED_PARAM(throwScope); + UNUSED_PARAM(callFrame); + auto& impl = castedThis->wrapped(); + if (UNLIKELY(callFrame->argumentCount() < 1)) + return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); + EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); + auto name = convert(*lexicalGlobalObject, argument0.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS>(*lexicalGlobalObject, throwScope, impl.get(WTFMove(name))))); +} + +JSC_DEFINE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_get, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "get"); +} + +static inline JSC::EncodedJSValue jsURLSearchParamsPrototypeFunction_getAllBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis) +{ + auto& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + UNUSED_PARAM(throwScope); + UNUSED_PARAM(callFrame); + auto& impl = castedThis->wrapped(); + if (UNLIKELY(callFrame->argumentCount() < 1)) + return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); + EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); + auto name = convert(*lexicalGlobalObject, argument0.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS>(*lexicalGlobalObject, *castedThis->globalObject(), throwScope, impl.getAll(WTFMove(name))))); +} + +JSC_DEFINE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_getAll, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "getAll"); +} + +static inline JSC::EncodedJSValue jsURLSearchParamsPrototypeFunction_hasBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis) +{ + auto& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + UNUSED_PARAM(throwScope); + UNUSED_PARAM(callFrame); + auto& impl = castedThis->wrapped(); + if (UNLIKELY(callFrame->argumentCount() < 1)) + return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); + EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); + auto name = convert(*lexicalGlobalObject, argument0.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS(*lexicalGlobalObject, throwScope, impl.has(WTFMove(name))))); +} + +JSC_DEFINE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_has, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "has"); +} + +static inline JSC::EncodedJSValue jsURLSearchParamsPrototypeFunction_setBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis) +{ + auto& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + UNUSED_PARAM(throwScope); + UNUSED_PARAM(callFrame); + auto& impl = castedThis->wrapped(); + if (UNLIKELY(callFrame->argumentCount() < 2)) + return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); + EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); + auto name = convert(*lexicalGlobalObject, argument0.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + EnsureStillAliveScope argument1 = callFrame->uncheckedArgument(1); + auto value = convert(*lexicalGlobalObject, argument1.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { return impl.set(WTFMove(name), WTFMove(value)); }))); +} + +JSC_DEFINE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_set, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "set"); +} + +static inline JSC::EncodedJSValue jsURLSearchParamsPrototypeFunction_sortBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis) +{ + auto& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + UNUSED_PARAM(throwScope); + UNUSED_PARAM(callFrame); + auto& impl = castedThis->wrapped(); + RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { return impl.sort(); }))); +} + +JSC_DEFINE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_sort, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "sort"); +} + +static inline JSC::EncodedJSValue jsURLSearchParamsPrototypeFunction_toStringBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis) +{ + auto& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + UNUSED_PARAM(throwScope); + UNUSED_PARAM(callFrame); + auto& impl = castedThis->wrapped(); + RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS(*lexicalGlobalObject, throwScope, impl.toString()))); +} + +JSC_DEFINE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_toString, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "toString"); +} + +struct URLSearchParamsIteratorTraits { + static constexpr JSDOMIteratorType type = JSDOMIteratorType::Map; + using KeyType = IDLUSVString; + using ValueType = IDLUSVString; +}; + +using URLSearchParamsIteratorBase = JSDOMIteratorBase; +class URLSearchParamsIterator final : public URLSearchParamsIteratorBase { +public: + using Base = URLSearchParamsIteratorBase; + DECLARE_INFO; + + template static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + if constexpr (mode == JSC::SubspaceAccess::Concurrently) + return nullptr; + return WebCore::subspaceForImpl( + vm, + [](auto& spaces) { return spaces.m_clientSubspaceForURLSearchParamsIterator.get(); }, + [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForURLSearchParamsIterator = WTFMove(space); }, + [](auto& spaces) { return spaces.m_subspaceForURLSearchParamsIterator.get(); }, + [](auto& spaces, auto&& space) { spaces.m_subspaceForURLSearchParamsIterator = WTFMove(space); }); + } + + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); + } + + static URLSearchParamsIterator* create(JSC::VM& vm, JSC::Structure* structure, JSURLSearchParams& iteratedObject, IterationKind kind) + { + auto* instance = new (NotNull, JSC::allocateCell(vm)) URLSearchParamsIterator(structure, iteratedObject, kind); + instance->finishCreation(vm); + return instance; + } + +private: + URLSearchParamsIterator(JSC::Structure* structure, JSURLSearchParams& iteratedObject, IterationKind kind) + : Base(structure, iteratedObject, kind) + { + } +}; + +using URLSearchParamsIteratorPrototype = JSDOMIteratorPrototype; +JSC_ANNOTATE_HOST_FUNCTION(URLSearchParamsIteratorPrototypeNext, URLSearchParamsIteratorPrototype::next); + +template<> +const JSC::ClassInfo URLSearchParamsIteratorBase::s_info = { "URLSearchParams Iterator"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(URLSearchParamsIteratorBase) }; +const JSC::ClassInfo URLSearchParamsIterator::s_info = { "URLSearchParams Iterator"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(URLSearchParamsIterator) }; + +template<> +const JSC::ClassInfo URLSearchParamsIteratorPrototype::s_info = { "URLSearchParams Iterator"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(URLSearchParamsIteratorPrototype) }; + +static inline EncodedJSValue jsURLSearchParamsPrototypeFunction_entriesCaller(JSGlobalObject*, CallFrame*, JSURLSearchParams* thisObject) +{ + return JSValue::encode(iteratorCreate(*thisObject, IterationKind::Entries)); +} + +JSC_DEFINE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_entries, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "entries"); +} + +static inline EncodedJSValue jsURLSearchParamsPrototypeFunction_keysCaller(JSGlobalObject*, CallFrame*, JSURLSearchParams* thisObject) +{ + return JSValue::encode(iteratorCreate(*thisObject, IterationKind::Keys)); +} + +JSC_DEFINE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_keys, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "keys"); +} + +static inline EncodedJSValue jsURLSearchParamsPrototypeFunction_valuesCaller(JSGlobalObject*, CallFrame*, JSURLSearchParams* thisObject) +{ + return JSValue::encode(iteratorCreate(*thisObject, IterationKind::Values)); +} + +JSC_DEFINE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_values, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "values"); +} + +static inline EncodedJSValue jsURLSearchParamsPrototypeFunction_forEachCaller(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame, JSURLSearchParams* thisObject) +{ + return JSValue::encode(iteratorForEach(*lexicalGlobalObject, *callFrame, *thisObject)); +} + +JSC_DEFINE_HOST_FUNCTION(jsURLSearchParamsPrototypeFunction_forEach, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "forEach"); +} + +JSC::GCClient::IsoSubspace* JSURLSearchParams::subspaceForImpl(JSC::VM& vm) +{ + return WebCore::subspaceForImpl( + vm, + [](auto& spaces) { return spaces.m_clientSubspaceForURLSearchParams.get(); }, + [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForURLSearchParams = WTFMove(space); }, + [](auto& spaces) { return spaces.m_subspaceForURLSearchParams.get(); }, + [](auto& spaces, auto&& space) { spaces.m_subspaceForURLSearchParams = WTFMove(space); }); +} + +void JSURLSearchParams::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer) +{ + auto* thisObject = jsCast(cell); + analyzer.setWrappedObjectForCell(cell, &thisObject->wrapped()); + // if (thisObject->scriptExecutionContext()) + // analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); + Base::analyzeHeap(cell, analyzer); +} + +bool JSURLSearchParamsOwner::isReachableFromOpaqueRoots(JSC::Handle handle, void*, AbstractSlotVisitor& visitor, const char** reason) +{ + UNUSED_PARAM(handle); + UNUSED_PARAM(visitor); + UNUSED_PARAM(reason); + return false; +} + +void JSURLSearchParamsOwner::finalize(JSC::Handle handle, void* context) +{ + auto* jsURLSearchParams = static_cast(handle.slot()->asCell()); + auto& world = *static_cast(context); + uncacheWrapper(world, &jsURLSearchParams->wrapped(), jsURLSearchParams); +} + +// #if ENABLE(BINDING_INTEGRITY) +// #if PLATFORM(WIN) +// #pragma warning(disable : 4483) +// extern "C" { +// extern void (*const __identifier("??_7URLSearchParams@WebCore@@6B@")[])(); +// } +// #else +// extern "C" { +// extern void* _ZTVN7WebCore15URLSearchParamsE[]; +// } +// #endif +// #endif + +JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject*, JSDOMGlobalObject* globalObject, Ref&& impl) +{ + + // if constexpr (std::is_polymorphic_v) { + // #if ENABLE(BINDING_INTEGRITY) + // const void* actualVTablePointer = getVTablePointer(impl.ptr()); + // #if PLATFORM(WIN) + // void* expectedVTablePointer = __identifier("??_7URLSearchParams@WebCore@@6B@"); + // #else + // void* expectedVTablePointer = &_ZTVN7WebCore15URLSearchParamsE[2]; + // #endif + + // // If you hit this assertion you either have a use after free bug, or + // // URLSearchParams has subclasses. If URLSearchParams has subclasses that get passed + // // to toJS() we currently require URLSearchParams you to opt out of binding hardening + // // by adding the SkipVTableValidation attribute to the interface IDL definition + // RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer); + // #endif + // } + return createWrapper(globalObject, WTFMove(impl)); +} + +JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, URLSearchParams& impl) +{ + return wrap(lexicalGlobalObject, globalObject, impl); +} + +URLSearchParams* JSURLSearchParams::toWrapped(JSC::VM& vm, JSC::JSValue value) +{ + if (auto* wrapper = jsDynamicCast(vm, value)) + return &wrapper->wrapped(); + return nullptr; +} + +} diff --git a/src/javascript/jsc/bindings/webcore/JSURLSearchParams.dep b/src/javascript/jsc/bindings/webcore/JSURLSearchParams.dep new file mode 100644 index 0000000000..73a94dc7bb --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSURLSearchParams.dep @@ -0,0 +1 @@ +JSURLSearchParams.h : diff --git a/src/javascript/jsc/bindings/webcore/JSURLSearchParams.h b/src/javascript/jsc/bindings/webcore/JSURLSearchParams.h new file mode 100644 index 0000000000..b7e90a3fbf --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSURLSearchParams.h @@ -0,0 +1,94 @@ +/* + This file is part of the WebKit open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#pragma once + +#include "JSDOMWrapper.h" +#include "URLSearchParams.h" +#include "wtf/NeverDestroyed.h" + +namespace WebCore { + +class JSURLSearchParams : public JSDOMWrapper { +public: + using Base = JSDOMWrapper; + static JSURLSearchParams* create(JSC::Structure* structure, JSDOMGlobalObject* globalObject, Ref&& impl) + { + JSURLSearchParams* ptr = new (NotNull, JSC::allocateCell(globalObject->vm())) JSURLSearchParams(structure, *globalObject, WTFMove(impl)); + ptr->finishCreation(globalObject->vm()); + return ptr; + } + + static JSC::JSObject* createPrototype(JSC::VM&, JSDOMGlobalObject&); + static JSC::JSObject* prototype(JSC::VM&, JSDOMGlobalObject&); + static URLSearchParams* toWrapped(JSC::VM&, JSC::JSValue); + static void destroy(JSC::JSCell*); + + DECLARE_INFO; + + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info(), JSC::NonArray); + } + + static JSC::JSValue getConstructor(JSC::VM&, const JSC::JSGlobalObject*); + template static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + if constexpr (mode == JSC::SubspaceAccess::Concurrently) + return nullptr; + return subspaceForImpl(vm); + } + static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm); + static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&); + +protected: + JSURLSearchParams(JSC::Structure*, JSDOMGlobalObject&, Ref&&); + + void finishCreation(JSC::VM&); +}; + +class JSURLSearchParamsOwner final : public JSC::WeakHandleOwner { +public: + bool isReachableFromOpaqueRoots(JSC::Handle, void* context, JSC::AbstractSlotVisitor&, const char**) final; + void finalize(JSC::Handle, void* context) final; +}; + +inline JSC::WeakHandleOwner* wrapperOwner(DOMWrapperWorld&, URLSearchParams*) +{ + static NeverDestroyed owner; + return &owner.get(); +} + +inline void* wrapperKey(URLSearchParams* wrappableObject) +{ + return wrappableObject; +} + +JSC::JSValue toJS(JSC::JSGlobalObject*, JSDOMGlobalObject*, URLSearchParams&); +inline JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, URLSearchParams* impl) { return impl ? toJS(lexicalGlobalObject, globalObject, *impl) : JSC::jsNull(); } +JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject*, JSDOMGlobalObject*, Ref&&); +inline JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, RefPtr&& impl) { return impl ? toJSNewlyCreated(lexicalGlobalObject, globalObject, impl.releaseNonNull()) : JSC::jsNull(); } + +template<> struct JSDOMWrapperConverterTraits { + using WrapperClass = JSURLSearchParams; + using ToWrappedReturnType = URLSearchParams*; +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/JSValueInWrappedObject.h b/src/javascript/jsc/bindings/webcore/JSValueInWrappedObject.h new file mode 100644 index 0000000000..d05fdb8fdc --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/JSValueInWrappedObject.h @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2018-2021 Apple Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "DOMWrapperWorld.h" +#include "JSDOMWrapper.h" +#include "JavaScriptCore/JSCJSValue.h" +#include "JavaScriptCore/SlotVisitor.h" +#include "JavaScriptCore/Weak.h" +#include + +namespace WebCore { + +// This class includes a lot of GC related subtle things, and changing this class easily causes GC crashes. +// Any changes on this class must be reviewed by JavaScriptCore reviewers too. +class JSValueInWrappedObject { + // It must be neither copyable nor movable. Changing this will break concurrent GC. + WTF_MAKE_NONCOPYABLE(JSValueInWrappedObject); + WTF_MAKE_NONMOVABLE(JSValueInWrappedObject); + +public: + JSValueInWrappedObject(JSC::JSValue = {}); + + explicit operator bool() const; + template void visit(Visitor&) const; + void clear(); + + void set(JSC::VM&, const JSC::JSCell* owner, JSC::JSValue); + void setWeakly(JSC::JSValue); + JSC::JSValue getValue(JSC::JSValue nullValue = JSC::jsUndefined()) const; + + // FIXME: Remove this once IDBRequest semantic bug is fixed. + // https://bugs.webkit.org/show_bug.cgi?id=236278 + void setWithoutBarrier(JSValueInWrappedObject&); + +private: + // Keep in mind that all of these fields are accessed concurrently without lock from concurrent GC thread. + JSC::JSValue m_nonCell {}; + JSC::Weak m_cell {}; +}; + +JSC::JSValue cachedPropertyValue(JSC::JSGlobalObject&, const JSDOMObject& owner, JSValueInWrappedObject& cacheSlot, const Function&); + +inline JSValueInWrappedObject::JSValueInWrappedObject(JSC::JSValue value) +{ + setWeakly(value); +} + +inline JSC::JSValue JSValueInWrappedObject::getValue(JSC::JSValue nullValue) const +{ + if (m_nonCell) + return m_nonCell; + return m_cell ? m_cell.get() : nullValue; +} + +inline JSValueInWrappedObject::operator bool() const +{ + return m_nonCell || m_cell; +} + +template +inline void JSValueInWrappedObject::visit(Visitor& visitor) const +{ + visitor.append(m_cell); +} + +template void JSValueInWrappedObject::visit(JSC::AbstractSlotVisitor&) const; +template void JSValueInWrappedObject::visit(JSC::SlotVisitor&) const; + +inline void JSValueInWrappedObject::setWeakly(JSC::JSValue value) +{ + if (!value.isCell()) { + m_nonCell = value; + m_cell.clear(); + return; + } + m_nonCell = {}; + JSC::Weak weak { value.asCell() }; + WTF::storeStoreFence(); + m_cell = WTFMove(weak); +} + +inline void JSValueInWrappedObject::set(JSC::VM& vm, const JSC::JSCell* owner, JSC::JSValue value) +{ + setWeakly(value); + vm.writeBarrier(owner, value); +} + +inline void JSValueInWrappedObject::clear() +{ + m_nonCell = {}; + m_cell.clear(); +} + +inline void JSValueInWrappedObject::setWithoutBarrier(JSValueInWrappedObject& other) +{ + JSC::Weak weak { other.m_cell.get() }; + WTF::storeStoreFence(); // Ensure Weak is fully initialized for concurrent access. + m_nonCell = other.m_nonCell; + m_cell = WTFMove(weak); +} + +inline JSC::JSValue cachedPropertyValue(JSC::JSGlobalObject& lexicalGlobalObject, const JSDOMObject& owner, JSValueInWrappedObject& cachedValue, const Function& function) +{ + if (cachedValue && isWorldCompatible(lexicalGlobalObject, cachedValue.getValue())) + return cachedValue.getValue(); + auto value = function(); + cachedValue.set(lexicalGlobalObject.vm(), &owner, cloneAcrossWorlds(lexicalGlobalObject, owner, value)); + ASSERT(isWorldCompatible(lexicalGlobalObject, cachedValue.getValue())); + return cachedValue.getValue(); +} + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/ScriptWrappable.cpp b/src/javascript/jsc/bindings/webcore/ScriptWrappable.cpp new file mode 100644 index 0000000000..c55b2ac920 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/ScriptWrappable.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2019 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptWrappable.h" + +// #include "wtf/IsoMallocInlines.h" + +namespace WebCore { + +// WTF_MAKE_FAST_ALLOCATED + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/ScriptWrappable.h b/src/javascript/jsc/bindings/webcore/ScriptWrappable.h new file mode 100644 index 0000000000..5d5f609d63 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/ScriptWrappable.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2013 Apple Inc. All rights reserved. + * Copyright (c) 2010, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "JavaScriptCore/Weak.h" +// #include "wtf/IsoMalloc.h" + +namespace JSC { +class WeakHandleOwner; +} + +namespace WebCore { + +class JSDOMObject; + +class ScriptWrappable { + WTF_MAKE_FAST_ALLOCATED; + +public: + JSDOMObject* wrapper() const; + void setWrapper(JSDOMObject*, JSC::WeakHandleOwner*, void*); + void clearWrapper(JSDOMObject*); + + template + static ptrdiff_t offsetOfWrapper() { return CAST_OFFSET(Derived*, ScriptWrappable*) + OBJECT_OFFSETOF(ScriptWrappable, m_wrapper); } + +protected: + ~ScriptWrappable() = default; + +private: + JSC::Weak m_wrapper; +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/ScriptWrappableInlines.h b/src/javascript/jsc/bindings/webcore/ScriptWrappableInlines.h new file mode 100644 index 0000000000..80b8087bf5 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/ScriptWrappableInlines.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2013 Apple Inc. All rights reserved. + * Copyright (c) 2010, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "JSDOMWrapper.h" +#include "JavaScriptCore/Weak.h" +#include "JavaScriptCore/WeakInlines.h" + +namespace WebCore { + +inline JSDOMObject* ScriptWrappable::wrapper() const +{ + return m_wrapper.get(); +} + +inline void ScriptWrappable::setWrapper(JSDOMObject* wrapper, JSC::WeakHandleOwner* wrapperOwner, void* context) +{ + ASSERT(!m_wrapper); + m_wrapper = JSC::Weak(wrapper, wrapperOwner, context); +} + +inline void ScriptWrappable::clearWrapper(JSDOMObject* wrapper) +{ + weakClear(m_wrapper, wrapper); +} + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/WebCoreJSClientData.h b/src/javascript/jsc/bindings/webcore/WebCoreJSClientData.h new file mode 100644 index 0000000000..68ada7e35a --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/WebCoreJSClientData.h @@ -0,0 +1 @@ +#include "BunClientData.h" \ No newline at end of file diff --git a/src/javascript/jsc/bindings/webcore/WebCoreTypedArrayController.cpp b/src/javascript/jsc/bindings/webcore/WebCoreTypedArrayController.cpp new file mode 100644 index 0000000000..9b68adc9a2 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/WebCoreTypedArrayController.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2013-2021 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "root.h" + +#include "JavaScriptCore/JSCInlines.h" + +#include "WebCoreTypedArrayController.h" + +#include "JSDOMConvertBufferSource.h" + +#include "JSDOMGlobalObject.h" + +#include "JavaScriptCore/ArrayBuffer.h" + +#include "JavaScriptCore/JSArrayBuffer.h" + +namespace WebCore { + +WebCoreTypedArrayController::WebCoreTypedArrayController(bool allowAtomicsWait) + : m_allowAtomicsWait(allowAtomicsWait) +{ +} + +WebCoreTypedArrayController::~WebCoreTypedArrayController() = default; + +JSC::JSArrayBuffer* WebCoreTypedArrayController::toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSC::JSGlobalObject* globalObject, JSC::ArrayBuffer* buffer) +{ + return JSC::jsCast(WebCore::toJS(lexicalGlobalObject, JSC::jsCast(globalObject), buffer)); +} + +void WebCoreTypedArrayController::registerWrapper(JSC::JSGlobalObject* globalObject, JSC::ArrayBuffer* native, JSC::JSArrayBuffer* wrapper) +{ + cacheWrapper(JSC::jsCast(globalObject)->world(), native, wrapper); +} + +bool WebCoreTypedArrayController::isAtomicsWaitAllowedOnCurrentThread() +{ + return m_allowAtomicsWait; +} + +bool WebCoreTypedArrayController::JSArrayBufferOwner::isReachableFromOpaqueRoots(JSC::Handle handle, void*, JSC::AbstractSlotVisitor& visitor, const char** reason) +{ + if (UNLIKELY(reason)) + *reason = "ArrayBuffer is opaque root"; + auto& wrapper = *JSC::jsCast(handle.slot()->asCell()); + return visitor.containsOpaqueRoot(wrapper.impl()); +} + +void WebCoreTypedArrayController::JSArrayBufferOwner::finalize(JSC::Handle handle, void* context) +{ + auto& wrapper = *static_cast(handle.slot()->asCell()); + uncacheWrapper(*static_cast(context), wrapper.impl(), &wrapper); +} + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/WebCoreTypedArrayController.h b/src/javascript/jsc/bindings/webcore/WebCoreTypedArrayController.h new file mode 100644 index 0000000000..437fb7d162 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/WebCoreTypedArrayController.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2013-2021 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "JavaScriptCore/JSGlobalObject.h" +#include "JavaScriptCore/TypedArrayController.h" + +namespace JSC { +class WeakHandleOwner; +} + +namespace WebCore { + +class WebCoreTypedArrayController : public JSC::TypedArrayController { +public: + WebCoreTypedArrayController(bool allowAtomicsWait); + virtual ~WebCoreTypedArrayController(); + + JSC::JSArrayBuffer* toJS(JSC::JSGlobalObject*, JSC::JSGlobalObject*, JSC::ArrayBuffer*) override; + void registerWrapper(JSC::JSGlobalObject*, ArrayBuffer*, JSC::JSArrayBuffer*) override; + bool isAtomicsWaitAllowedOnCurrentThread() override; + + JSC::WeakHandleOwner* wrapperOwner() { return &m_owner; } + +private: + class JSArrayBufferOwner : public JSC::WeakHandleOwner { + public: + bool isReachableFromOpaqueRoots(JSC::Handle, void* context, JSC::AbstractSlotVisitor&, const char**) override; + void finalize(JSC::Handle, void* context) override; + }; + + JSArrayBufferOwner m_owner; + bool m_allowAtomicsWait; +}; + +} // namespace WebCore \ No newline at end of file diff --git a/src/javascript/jsc/bindings/webcore/config.h b/src/javascript/jsc/bindings/webcore/config.h new file mode 100644 index 0000000000..a9f9f5d294 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/config.h @@ -0,0 +1 @@ +#include "root.h" \ No newline at end of file diff --git a/src/javascript/jsc/bindings/webcore/weak_handle.cpp b/src/javascript/jsc/bindings/webcore/weak_handle.cpp new file mode 100644 index 0000000000..f10ae654d6 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/weak_handle.cpp @@ -0,0 +1,22 @@ +#include "config.h" +#include "JavaScriptCore/WeakHandleOwner.h" + +namespace JSC { + +class SlotVisitor; +template class Handle; + +WeakHandleOwner::~WeakHandleOwner() +{ +} + +bool WeakHandleOwner::isReachableFromOpaqueRoots(Handle, void*, AbstractSlotVisitor&, const char**) +{ + return false; +} + +void WeakHandleOwner::finalize(Handle, void*) +{ +} + +} // namespace JSC