/* 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 "JSImageData.h" #include "ActiveDOMObject.h" #include "ExtendedDOMClientIsoSubspaces.h" #include "ExtendedDOMIsoSubspaces.h" #include "JSDOMAttribute.h" #include "JSDOMBinding.h" #include "JSDOMConstructor.h" #include "JSDOMConvertBufferSource.h" #include "JSDOMConvertDictionary.h" #include "JSDOMConvertEnumeration.h" #include "JSDOMConvertInterface.h" #include "JSDOMConvertNumbers.h" #include "JSDOMExceptionHandling.h" #include "JSDOMGlobalObject.h" #include "JSDOMGlobalObjectInlines.h" #include "JSDOMWrapperCache.h" // #include "JSImageDataSettings.h" // #include "JSPredefinedColorSpace.h" #include "ScriptExecutionContext.h" #include "WebCoreJSClientData.h" #include "JavaScriptCore/FunctionPrototype.h" #include "JavaScriptCore/HeapAnalyzer.h" #include "JavaScriptCore/JSDestructibleObjectHeapCellType.h" #include "JavaScriptCore/SlotVisitorMacros.h" #include "JavaScriptCore/SubspaceInlines.h" #include #include #include #include "JavaScriptCore/JSArrayBufferViewInlines.h" #include "JavaScriptCore/JSGenericTypedArrayViewInlines.h" #include "JavaScriptCore/ArrayBufferView.h" #include "JavaScriptCore/JSCInlines.h" #include "JSImageData.h" namespace WebCore { using namespace JSC; // Attributes static JSC_DECLARE_CUSTOM_GETTER(jsImageDataConstructor); static JSC_DECLARE_CUSTOM_GETTER(jsImageData_width); static JSC_DECLARE_CUSTOM_GETTER(jsImageData_height); static JSC_DECLARE_CUSTOM_GETTER(jsImageData_data); // static JSC_DECLARE_CUSTOM_GETTER(jsImageData_colorSpace); class JSImageDataPrototype final : public JSC::JSNonFinalObject { public: using Base = JSC::JSNonFinalObject; static JSImageDataPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) { JSImageDataPrototype* ptr = new (NotNull, JSC::allocateCell(vm)) JSImageDataPrototype(vm, globalObject, structure); ptr->finishCreation(vm); return ptr; } DECLARE_INFO; template static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) { STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSImageDataPrototype, 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: JSImageDataPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) : JSC::JSNonFinalObject(vm, structure) { } void finishCreation(JSC::VM&); }; STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSImageDataPrototype, JSImageDataPrototype::Base); using JSImageDataDOMConstructor = JSDOMConstructor; static inline EncodedJSValue constructJSImageData1(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 sw = convert(*lexicalGlobalObject, argument0.value()); RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); EnsureStillAliveScope argument1 = callFrame->uncheckedArgument(1); auto sh = convert(*lexicalGlobalObject, argument1.value()); RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); // auto settings = convert>(*lexicalGlobalObject, argument2.value()); // RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); auto object = ImageData::create(WTFMove(sw), WTFMove(sh)); 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 constructJSImageData2(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 data = convert(*lexicalGlobalObject, argument0.value(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentTypeError(lexicalGlobalObject, scope, 0, "data", "ImageData", nullptr, "Uint8ClampedArray"); }); RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); EnsureStillAliveScope argument1 = callFrame->uncheckedArgument(1); auto sw = convert(*lexicalGlobalObject, argument1.value()); RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); EnsureStillAliveScope argument2 = callFrame->argument(2); auto sh = argument2.value().isUndefined() ? std::optional::ReturnType>() : std::optional::ReturnType>(convert(*lexicalGlobalObject, argument2.value())); RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); auto object = ImageData::create(data.releaseNonNull(), WTFMove(sw), WTFMove(sh)); 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 JSImageDataDOMConstructor::construct(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame) { VM& vm = lexicalGlobalObject->vm(); auto throwScope = DECLARE_THROW_SCOPE(vm); UNUSED_PARAM(throwScope); size_t argsCount = std::min(4, callFrame->argumentCount()); if (argsCount == 2) { JSValue distinguishingArg = callFrame->uncheckedArgument(0); if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits(vm)) RELEASE_AND_RETURN(throwScope, (constructJSImageData2(lexicalGlobalObject, callFrame))); if (distinguishingArg.isNumber()) RELEASE_AND_RETURN(throwScope, (constructJSImageData1(lexicalGlobalObject, callFrame))); RELEASE_AND_RETURN(throwScope, (constructJSImageData1(lexicalGlobalObject, callFrame))); } if (argsCount == 3) { JSValue distinguishingArg = callFrame->uncheckedArgument(0); if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits(vm)) RELEASE_AND_RETURN(throwScope, (constructJSImageData2(lexicalGlobalObject, callFrame))); if (distinguishingArg.isNumber()) RELEASE_AND_RETURN(throwScope, (constructJSImageData1(lexicalGlobalObject, callFrame))); RELEASE_AND_RETURN(throwScope, (constructJSImageData1(lexicalGlobalObject, callFrame))); } if (argsCount == 4) { RELEASE_AND_RETURN(throwScope, (constructJSImageData2(lexicalGlobalObject, callFrame))); } return argsCount < 2 ? throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)) : throwVMTypeError(lexicalGlobalObject, throwScope); } JSC_ANNOTATE_HOST_FUNCTION(JSImageDataConstructorConstruct, JSImageDataDOMConstructor::construct); template<> const ClassInfo JSImageDataDOMConstructor::s_info = { "ImageData"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSImageDataDOMConstructor) }; template<> JSValue JSImageDataDOMConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) { UNUSED_PARAM(vm); return globalObject.functionPrototype(); } template<> void JSImageDataDOMConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) { putDirect(vm, vm.propertyNames->length, jsNumber(2), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); JSString* nameString = jsNontrivialString(vm, "ImageData"_s); m_originalName.set(vm, this, nameString); putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); putDirect(vm, vm.propertyNames->prototype, JSImageData::prototype(vm, globalObject), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete); } /* Hash table for prototype */ static const HashTableValue JSImageDataPrototypeTableValues[] = { { "constructor", static_cast(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t) static_cast(jsImageDataConstructor), (intptr_t) static_cast(0) } }, { "width", static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast(jsImageData_width), (intptr_t) static_cast(0) } }, { "height", static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast(jsImageData_height), (intptr_t) static_cast(0) } }, { "data", static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast(jsImageData_data), (intptr_t) static_cast(0) } }, // { "colorSpace", static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast(jsImageData_colorSpace), (intptr_t) static_cast(0) } }, }; const ClassInfo JSImageDataPrototype::s_info = { "ImageData"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSImageDataPrototype) }; void JSImageDataPrototype::finishCreation(VM& vm) { Base::finishCreation(vm); reifyStaticProperties(vm, JSImageData::info(), JSImageDataPrototypeTableValues, *this); JSC_TO_STRING_TAG_WITHOUT_TRANSITION(); } const ClassInfo JSImageData::s_info = { "ImageData"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSImageData) }; JSImageData::JSImageData(Structure* structure, JSDOMGlobalObject& globalObject, Ref&& impl) : JSDOMWrapper(structure, globalObject, WTFMove(impl)) { } void JSImageData::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* JSImageData::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) { return JSImageDataPrototype::create(vm, &globalObject, JSImageDataPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); } JSObject* JSImageData::prototype(VM& vm, JSDOMGlobalObject& globalObject) { return getDOMPrototype(vm, globalObject); } JSValue JSImageData::getConstructor(VM& vm, const JSGlobalObject* globalObject) { return getDOMConstructor(vm, *jsCast(globalObject)); } void JSImageData::destroy(JSC::JSCell* cell) { JSImageData* thisObject = static_cast(cell); thisObject->JSImageData::~JSImageData(); } JSC_DEFINE_CUSTOM_GETTER(jsImageDataConstructor, (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(JSImageData::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } static inline JSValue jsImageData_widthGetter(JSGlobalObject& lexicalGlobalObject, JSImageData& thisObject) { auto& vm = JSC::getVM(&lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.width()))); } JSC_DEFINE_CUSTOM_GETTER(jsImageData_width, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } static inline JSValue jsImageData_heightGetter(JSGlobalObject& lexicalGlobalObject, JSImageData& thisObject) { auto& vm = JSC::getVM(&lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.height()))); } JSC_DEFINE_CUSTOM_GETTER(jsImageData_height, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } static inline JSValue jsImageData_dataGetter(JSGlobalObject& lexicalGlobalObject, JSImageData& thisObject) { auto& vm = JSC::getVM(&lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, *thisObject.globalObject(), throwScope, impl.data()))); } JSC_DEFINE_CUSTOM_GETTER(jsImageData_data, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } // static inline JSValue jsImageData_colorSpaceGetter(JSGlobalObject& lexicalGlobalObject, JSImageData& thisObject) // { // return JSC::JSValue(JSC::jsString(lexicalGlobalObject.vm(), "srgb"_s)); // } // JSC_DEFINE_CUSTOM_GETTER(jsImageData_colorSpace, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) // { // return JSC::JSValue::encode( // jsImageData_colorSpaceGetter(*lexicalGlobalObject, *jsCast(JSValue::decode(thisValue)))); // } JSC::GCClient::IsoSubspace* JSImageData::subspaceForImpl(JSC::VM& vm) { return WebCore::subspaceForImpl( vm, [](auto& spaces) { return spaces.m_clientSubspaceForImageData.get(); }, [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForImageData = WTFMove(space); }, [](auto& spaces) { return spaces.m_subspaceForImageData.get(); }, [](auto& spaces, auto&& space) { spaces.m_subspaceForImageData = WTFMove(space); }); } void JSImageData::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 JSImageDataOwner::isReachableFromOpaqueRoots(JSC::Handle handle, void*, AbstractSlotVisitor& visitor, const char** reason) { UNUSED_PARAM(handle); UNUSED_PARAM(visitor); UNUSED_PARAM(reason); return false; } void JSImageDataOwner::finalize(JSC::Handle handle, void* context) { auto* jsImageData = static_cast(handle.slot()->asCell()); auto& world = *static_cast(context); uncacheWrapper(world, &jsImageData->wrapped(), jsImageData); } ImageData* JSImageData::toWrapped(JSC::VM& vm, JSC::JSValue value) { if (auto* wrapper = jsDynamicCast(vm, value)) return &wrapper->wrapped(); return nullptr; } }