| /* |
| 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 "ExceptionCode.h" |
| #include "JSDOMBinding.h" |
| #include "JSDOMConstructor.h" |
| #include "JSDOMConvert.h" |
| #include <runtime/Error.h> |
| #include <runtime/FunctionPrototype.h> |
| #include <wtf/GetPtr.h> |
| |
| using namespace JSC; |
| |
| namespace WebCore { |
| |
| // Attributes |
| |
| JSC::EncodedJSValue jsImageDataWidth(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsImageDataHeight(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsImageDataConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSImageDataConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| |
| class JSImageDataPrototype : public JSC::JSNonFinalObject { |
| public: |
| typedef JSC::JSNonFinalObject Base; |
| static JSImageDataPrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure) |
| { |
| JSImageDataPrototype* ptr = new (NotNull, JSC::allocateCell<JSImageDataPrototype>(vm.heap)) JSImageDataPrototype(vm, globalObject, structure); |
| ptr->finishCreation(vm); |
| return ptr; |
| } |
| |
| 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()); |
| } |
| |
| private: |
| JSImageDataPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| : JSC::JSNonFinalObject(vm, structure) |
| { |
| } |
| |
| void finishCreation(JSC::VM&); |
| }; |
| |
| typedef JSDOMConstructor<JSImageData> JSImageDataConstructor; |
| |
| static inline EncodedJSValue constructJSImageData1(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| auto* castedThis = jsCast<JSImageDataConstructor*>(state->callee()); |
| ASSERT(castedThis); |
| if (UNLIKELY(state->argumentCount() < 2)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| ExceptionCode ec = 0; |
| auto data = toUint8ClampedArray(state->uncheckedArgument(0)); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| if (UNLIKELY(!data)) |
| return throwArgumentTypeError(*state, throwScope, 0, "data", "ImageData", nullptr, "Uint8ClampedArray"); |
| auto sw = convert<uint32_t>(*state, state->uncheckedArgument(1), NormalConversion); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| auto sh = convert<uint32_t>(*state, state->argument(2), NormalConversion); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| auto object = ImageData::create(*data, WTFMove(sw), WTFMove(sh), ec); |
| if (UNLIKELY(ec)) { |
| setDOMException(state, throwScope, ec); |
| return JSValue::encode(JSValue()); |
| } |
| return JSValue::encode(toJSNewlyCreated(state, castedThis->globalObject(), WTFMove(object))); |
| } |
| |
| static inline EncodedJSValue constructJSImageData2(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| auto* castedThis = jsCast<JSImageDataConstructor*>(state->callee()); |
| ASSERT(castedThis); |
| if (UNLIKELY(state->argumentCount() < 2)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| ExceptionCode ec = 0; |
| auto sw = convert<uint32_t>(*state, state->uncheckedArgument(0), NormalConversion); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| auto sh = convert<uint32_t>(*state, state->uncheckedArgument(1), NormalConversion); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| auto object = ImageData::create(WTFMove(sw), WTFMove(sh), ec); |
| if (UNLIKELY(ec)) { |
| setDOMException(state, throwScope, ec); |
| return JSValue::encode(JSValue()); |
| } |
| return JSValue::encode(toJSNewlyCreated(state, castedThis->globalObject(), WTFMove(object))); |
| } |
| |
| template<> EncodedJSValue JSC_HOST_CALL JSImageDataConstructor::construct(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| size_t argsCount = std::min<size_t>(3, state->argumentCount()); |
| if (argsCount == 2) { |
| JSValue distinguishingArg = state->uncheckedArgument(0); |
| if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits(JSUint8ClampedArray::info())) |
| return constructJSImageData1(state); |
| if (distinguishingArg.isNumber()) |
| return constructJSImageData2(state); |
| return constructJSImageData2(state); |
| } |
| if (argsCount == 3) { |
| return constructJSImageData1(state); |
| } |
| return argsCount < 2 ? throwVMError(state, throwScope, createNotEnoughArgumentsError(state)) : throwVMTypeError(state, throwScope); |
| } |
| |
| template<> JSValue JSImageDataConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| { |
| UNUSED_PARAM(vm); |
| return globalObject.functionPrototype(); |
| } |
| |
| template<> void JSImageDataConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
| { |
| putDirect(vm, vm.propertyNames->prototype, JSImageData::prototype(vm, &globalObject), DontDelete | ReadOnly | DontEnum); |
| putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("ImageData"))), ReadOnly | DontEnum); |
| putDirect(vm, vm.propertyNames->length, jsNumber(2), ReadOnly | DontEnum); |
| } |
| |
| template<> const ClassInfo JSImageDataConstructor::s_info = { "ImageData", &Base::s_info, 0, CREATE_METHOD_TABLE(JSImageDataConstructor) }; |
| |
| /* Hash table for prototype */ |
| |
| static const HashTableValue JSImageDataPrototypeTableValues[] = |
| { |
| { "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsImageDataConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSImageDataConstructor) } }, |
| { "width", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsImageDataWidth), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "height", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsImageDataHeight), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| }; |
| |
| const ClassInfo JSImageDataPrototype::s_info = { "ImageDataPrototype", &Base::s_info, 0, CREATE_METHOD_TABLE(JSImageDataPrototype) }; |
| |
| void JSImageDataPrototype::finishCreation(VM& vm) |
| { |
| Base::finishCreation(vm); |
| reifyStaticProperties(vm, JSImageDataPrototypeTableValues, *this); |
| } |
| |
| const ClassInfo JSImageData::s_info = { "ImageData", &Base::s_info, 0, CREATE_METHOD_TABLE(JSImageData) }; |
| |
| JSImageData::JSImageData(Structure* structure, JSDOMGlobalObject& globalObject, Ref<ImageData>&& impl) |
| : JSDOMWrapper<ImageData>(structure, globalObject, WTFMove(impl)) |
| { |
| } |
| |
| JSObject* JSImageData::createPrototype(VM& vm, JSGlobalObject* globalObject) |
| { |
| return JSImageDataPrototype::create(vm, globalObject, JSImageDataPrototype::createStructure(vm, globalObject, globalObject->objectPrototype())); |
| } |
| |
| JSObject* JSImageData::prototype(VM& vm, JSGlobalObject* globalObject) |
| { |
| return getDOMPrototype<JSImageData>(vm, globalObject); |
| } |
| |
| void JSImageData::destroy(JSC::JSCell* cell) |
| { |
| JSImageData* thisObject = static_cast<JSImageData*>(cell); |
| thisObject->JSImageData::~JSImageData(); |
| } |
| |
| EncodedJSValue jsImageDataWidth(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSImageData*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "ImageData", "width"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsNumber(impl.width()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsImageDataHeight(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSImageData*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "ImageData", "height"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsNumber(impl.height()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsImageDataConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| JSImageDataPrototype* domObject = jsDynamicCast<JSImageDataPrototype*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!domObject)) |
| return throwVMTypeError(state, throwScope); |
| return JSValue::encode(JSImageData::getConstructor(state->vm(), domObject->globalObject())); |
| } |
| |
| bool setJSImageDataConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| JSValue value = JSValue::decode(encodedValue); |
| JSImageDataPrototype* domObject = jsDynamicCast<JSImageDataPrototype*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!domObject)) { |
| throwVMTypeError(state, throwScope); |
| return false; |
| } |
| // Shadowing a built-in constructor |
| return domObject->putDirect(state->vm(), state->propertyNames().constructor, value); |
| } |
| |
| JSValue JSImageData::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| { |
| return getDOMConstructor<JSImageDataConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| } |
| |
| bool JSImageDataOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor) |
| { |
| UNUSED_PARAM(handle); |
| UNUSED_PARAM(visitor); |
| return false; |
| } |
| |
| void JSImageDataOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
| { |
| auto* jsImageData = jsCast<JSImageData*>(handle.slot()->asCell()); |
| auto& world = *static_cast<DOMWrapperWorld*>(context); |
| uncacheWrapper(world, &jsImageData->wrapped(), jsImageData); |
| } |
| |
| ImageData* JSImageData::toWrapped(JSC::JSValue value) |
| { |
| if (auto* wrapper = jsDynamicCast<JSImageData*>(value)) |
| return &wrapper->wrapped(); |
| return nullptr; |
| } |
| |
| } |