| /* |
| 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 "JSShadowRoot.h" |
| |
| #include "ExceptionCode.h" |
| #include "JSDOMBinding.h" |
| #include "JSDOMConstructor.h" |
| #include "JSDOMConvert.h" |
| #include "JSElement.h" |
| #include "URL.h" |
| #include <runtime/JSString.h> |
| #include <wtf/GetPtr.h> |
| |
| using namespace JSC; |
| |
| namespace WebCore { |
| |
| template<typename T> Optional<T> parse(ExecState&, JSValue); |
| template<typename T> const char* expectedEnumerationValues(); |
| |
| JSString* jsStringWithCache(ExecState*, ShadowRoot::Mode); |
| |
| JSString* jsStringWithCache(ExecState* state, ShadowRoot::Mode enumerationValue) |
| { |
| static NeverDestroyed<const String> values[] = { |
| ASCIILiteral("user-agent"), |
| ASCIILiteral("closed"), |
| ASCIILiteral("open"), |
| }; |
| static_assert(static_cast<size_t>(ShadowRoot::Mode::UserAgent) == 0, "ShadowRoot::Mode::UserAgent is not 0 as expected"); |
| static_assert(static_cast<size_t>(ShadowRoot::Mode::Closed) == 1, "ShadowRoot::Mode::Closed is not 1 as expected"); |
| static_assert(static_cast<size_t>(ShadowRoot::Mode::Open) == 2, "ShadowRoot::Mode::Open is not 2 as expected"); |
| ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
| return jsStringWithCache(state, values[static_cast<size_t>(enumerationValue)]); |
| } |
| |
| template<> struct JSValueTraits<ShadowRoot::Mode> { |
| static JSString* arrayJSValue(ExecState* state, JSDOMGlobalObject*, ShadowRoot::Mode value) { return jsStringWithCache(state, value); } |
| }; |
| |
| template<> Optional<ShadowRoot::Mode> parse<ShadowRoot::Mode>(ExecState& state, JSValue value) |
| { |
| auto stringValue = value.toWTFString(&state); |
| if (stringValue == "user-agent") |
| return ShadowRoot::Mode::UserAgent; |
| if (stringValue == "closed") |
| return ShadowRoot::Mode::Closed; |
| if (stringValue == "open") |
| return ShadowRoot::Mode::Open; |
| return Nullopt; |
| } |
| |
| template<> ShadowRoot::Mode convert<ShadowRoot::Mode>(ExecState& state, JSValue value) |
| { |
| VM& vm = state.vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| auto result = parse<ShadowRoot::Mode>(state, value); |
| if (UNLIKELY(!result)) { |
| throwTypeError(&state, throwScope); |
| return { }; |
| } |
| return result.value(); |
| } |
| |
| template<> inline const char* expectedEnumerationValues<ShadowRoot::Mode>() |
| { |
| return "\"user-agent\", \"closed\", \"open\""; |
| } |
| |
| // Attributes |
| |
| JSC::EncodedJSValue jsShadowRootMode(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsShadowRootActiveElement(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsShadowRootHost(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsShadowRootInnerHTML(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSShadowRootInnerHTML(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| JSC::EncodedJSValue jsShadowRootConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSShadowRootConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| |
| class JSShadowRootPrototype : public JSC::JSNonFinalObject { |
| public: |
| typedef JSC::JSNonFinalObject Base; |
| static JSShadowRootPrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure) |
| { |
| JSShadowRootPrototype* ptr = new (NotNull, JSC::allocateCell<JSShadowRootPrototype>(vm.heap)) JSShadowRootPrototype(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: |
| JSShadowRootPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| : JSC::JSNonFinalObject(vm, structure) |
| { |
| } |
| |
| void finishCreation(JSC::VM&); |
| }; |
| |
| typedef JSDOMConstructorNotConstructable<JSShadowRoot> JSShadowRootConstructor; |
| |
| template<> JSValue JSShadowRootConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| { |
| return JSDocumentFragment::getConstructor(vm, &globalObject); |
| } |
| |
| template<> void JSShadowRootConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
| { |
| putDirect(vm, vm.propertyNames->prototype, JSShadowRoot::prototype(vm, &globalObject), DontDelete | ReadOnly | DontEnum); |
| putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("ShadowRoot"))), ReadOnly | DontEnum); |
| putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontEnum); |
| } |
| |
| template<> const ClassInfo JSShadowRootConstructor::s_info = { "ShadowRoot", &Base::s_info, 0, CREATE_METHOD_TABLE(JSShadowRootConstructor) }; |
| |
| /* Hash table for prototype */ |
| |
| static const HashTableValue JSShadowRootPrototypeTableValues[] = |
| { |
| { "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsShadowRootConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSShadowRootConstructor) } }, |
| { "mode", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsShadowRootMode), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "activeElement", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsShadowRootActiveElement), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "host", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsShadowRootHost), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "innerHTML", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsShadowRootInnerHTML), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSShadowRootInnerHTML) } }, |
| }; |
| |
| const ClassInfo JSShadowRootPrototype::s_info = { "ShadowRootPrototype", &Base::s_info, 0, CREATE_METHOD_TABLE(JSShadowRootPrototype) }; |
| |
| void JSShadowRootPrototype::finishCreation(VM& vm) |
| { |
| Base::finishCreation(vm); |
| reifyStaticProperties(vm, JSShadowRootPrototypeTableValues, *this); |
| } |
| |
| const ClassInfo JSShadowRoot::s_info = { "ShadowRoot", &Base::s_info, 0, CREATE_METHOD_TABLE(JSShadowRoot) }; |
| |
| JSShadowRoot::JSShadowRoot(Structure* structure, JSDOMGlobalObject& globalObject, Ref<ShadowRoot>&& impl) |
| : JSDocumentFragment(structure, globalObject, WTFMove(impl)) |
| { |
| } |
| |
| JSObject* JSShadowRoot::createPrototype(VM& vm, JSGlobalObject* globalObject) |
| { |
| return JSShadowRootPrototype::create(vm, globalObject, JSShadowRootPrototype::createStructure(vm, globalObject, JSDocumentFragment::prototype(vm, globalObject))); |
| } |
| |
| JSObject* JSShadowRoot::prototype(VM& vm, JSGlobalObject* globalObject) |
| { |
| return getDOMPrototype<JSShadowRoot>(vm, globalObject); |
| } |
| |
| EncodedJSValue jsShadowRootMode(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<JSShadowRoot*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "ShadowRoot", "mode"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringWithCache(state, impl.mode()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsShadowRootActiveElement(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<JSShadowRoot*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "ShadowRoot", "activeElement"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = toJS(state, castedThis->globalObject(), impl.activeElement()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsShadowRootHost(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<JSShadowRoot*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "ShadowRoot", "host"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = toJS(state, castedThis->globalObject(), impl.host()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsShadowRootInnerHTML(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<JSShadowRoot*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "ShadowRoot", "innerHTML"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringWithCache(state, impl.innerHTML()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsShadowRootConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| JSShadowRootPrototype* domObject = jsDynamicCast<JSShadowRootPrototype*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!domObject)) |
| return throwVMTypeError(state, throwScope); |
| return JSValue::encode(JSShadowRoot::getConstructor(state->vm(), domObject->globalObject())); |
| } |
| |
| bool setJSShadowRootConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| JSValue value = JSValue::decode(encodedValue); |
| JSShadowRootPrototype* domObject = jsDynamicCast<JSShadowRootPrototype*>(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); |
| } |
| |
| bool setJSShadowRootInnerHTML(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue value = JSValue::decode(encodedValue); |
| UNUSED_PARAM(thisValue); |
| JSShadowRoot* castedThis = jsDynamicCast<JSShadowRoot*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!castedThis)) { |
| return throwSetterTypeError(*state, throwScope, "ShadowRoot", "innerHTML"); |
| } |
| auto& impl = castedThis->wrapped(); |
| ExceptionCode ec = 0; |
| auto nativeValue = valueToStringTreatingNullAsEmptyString(state, value); |
| RETURN_IF_EXCEPTION(throwScope, false); |
| impl.setInnerHTML(WTFMove(nativeValue), ec); |
| setDOMException(state, throwScope, ec); |
| return true; |
| } |
| |
| |
| JSValue JSShadowRoot::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| { |
| return getDOMConstructor<JSShadowRootConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| } |
| |
| void JSShadowRoot::visitChildren(JSCell* cell, SlotVisitor& visitor) |
| { |
| auto* thisObject = jsCast<JSShadowRoot*>(cell); |
| ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
| Base::visitChildren(thisObject, visitor); |
| thisObject->wrapped().visitJSEventListeners(visitor); |
| } |
| |
| #if ENABLE(BINDING_INTEGRITY) |
| #if PLATFORM(WIN) |
| #pragma warning(disable: 4483) |
| extern "C" { extern void (*const __identifier("??_7ShadowRoot@WebCore@@6B@")[])(); } |
| #else |
| extern "C" { extern void* _ZTVN7WebCore10ShadowRootE[]; } |
| #endif |
| #endif |
| |
| JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<ShadowRoot>&& impl) |
| { |
| |
| #if ENABLE(BINDING_INTEGRITY) |
| void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr())); |
| #if PLATFORM(WIN) |
| void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7ShadowRoot@WebCore@@6B@")); |
| #else |
| void* expectedVTablePointer = &_ZTVN7WebCore10ShadowRootE[2]; |
| #if COMPILER(CLANG) |
| // If this fails ShadowRoot does not have a vtable, so you need to add the |
| // ImplementationLacksVTable attribute to the interface definition |
| static_assert(__is_polymorphic(ShadowRoot), "ShadowRoot is not polymorphic"); |
| #endif |
| #endif |
| // If you hit this assertion you either have a use after free bug, or |
| // ShadowRoot has subclasses. If ShadowRoot has subclasses that get passed |
| // to toJS() we currently require ShadowRoot you to opt out of binding hardening |
| // by adding the SkipVTableValidation attribute to the interface IDL definition |
| RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer); |
| #endif |
| return createWrapper<ShadowRoot>(globalObject, WTFMove(impl)); |
| } |
| |
| JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, ShadowRoot& impl) |
| { |
| return wrap(state, globalObject, impl); |
| } |
| |
| |
| } |