1/*
2 This file is part of the WebKit open source project.
3 This file has been generated by generate-bindings.pl. DO NOT MODIFY!
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include "config.h"
22#include "JSHTMLDocument.h"
23
24#include "JSDOMAbstractOperations.h"
25#include "JSDOMBinding.h"
26#include "JSDOMConstructorNotConstructable.h"
27#include "JSDOMConvertInterface.h"
28#include "JSDOMConvertUnion.h"
29#include "JSDOMExceptionHandling.h"
30#include "JSDOMGlobalObject.h"
31#include "JSDOMWrapperCache.h"
32#include "JSElement.h"
33#include "JSHTMLCollection.h"
34#include "JSWindowProxy.h"
35#include "ScriptExecutionContext.h"
36#include <JavaScriptCore/HeapSnapshotBuilder.h>
37#include <JavaScriptCore/JSCInlines.h>
38#include <wtf/GetPtr.h>
39#include <wtf/PointerPreparations.h>
40#include <wtf/URL.h>
41#include <wtf/Variant.h>
42
43
44namespace WebCore {
45using namespace JSC;
46
47// Attributes
48
49JSC::EncodedJSValue jsHTMLDocumentConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
50bool setJSHTMLDocumentConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
51
52class JSHTMLDocumentPrototype : public JSC::JSNonFinalObject {
53public:
54 using Base = JSC::JSNonFinalObject;
55 static JSHTMLDocumentPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
56 {
57 JSHTMLDocumentPrototype* ptr = new (NotNull, JSC::allocateCell<JSHTMLDocumentPrototype>(vm.heap)) JSHTMLDocumentPrototype(vm, globalObject, structure);
58 ptr->finishCreation(vm);
59 return ptr;
60 }
61
62 DECLARE_INFO;
63 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
64 {
65 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
66 }
67
68private:
69 JSHTMLDocumentPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
70 : JSC::JSNonFinalObject(vm, structure)
71 {
72 }
73
74 void finishCreation(JSC::VM&);
75};
76
77using JSHTMLDocumentConstructor = JSDOMConstructorNotConstructable<JSHTMLDocument>;
78
79template<> JSValue JSHTMLDocumentConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
80{
81 return JSDocument::getConstructor(vm, &globalObject);
82}
83
84template<> void JSHTMLDocumentConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
85{
86 putDirect(vm, vm.propertyNames->prototype, JSHTMLDocument::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
87 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("HTMLDocument"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
88 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
89}
90
91template<> const ClassInfo JSHTMLDocumentConstructor::s_info = { "HTMLDocument", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSHTMLDocumentConstructor) };
92
93/* Hash table for prototype */
94
95static const HashTableValue JSHTMLDocumentPrototypeTableValues[] =
96{
97 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsHTMLDocumentConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSHTMLDocumentConstructor) } },
98};
99
100const ClassInfo JSHTMLDocumentPrototype::s_info = { "HTMLDocumentPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSHTMLDocumentPrototype) };
101
102void JSHTMLDocumentPrototype::finishCreation(VM& vm)
103{
104 Base::finishCreation(vm);
105 reifyStaticProperties(vm, JSHTMLDocument::info(), JSHTMLDocumentPrototypeTableValues, *this);
106}
107
108const ClassInfo JSHTMLDocument::s_info = { "HTMLDocument", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSHTMLDocument) };
109
110JSHTMLDocument::JSHTMLDocument(Structure* structure, JSDOMGlobalObject& globalObject, Ref<HTMLDocument>&& impl)
111 : JSDocument(structure, globalObject, WTFMove(impl))
112{
113}
114
115void JSHTMLDocument::finishCreation(VM& vm)
116{
117 Base::finishCreation(vm);
118 ASSERT(inherits(vm, info()));
119
120}
121
122JSObject* JSHTMLDocument::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
123{
124 return JSHTMLDocumentPrototype::create(vm, &globalObject, JSHTMLDocumentPrototype::createStructure(vm, &globalObject, JSDocument::prototype(vm, globalObject)));
125}
126
127JSObject* JSHTMLDocument::prototype(VM& vm, JSDOMGlobalObject& globalObject)
128{
129 return getDOMPrototype<JSHTMLDocument>(vm, globalObject);
130}
131
132JSValue JSHTMLDocument::getConstructor(VM& vm, const JSGlobalObject* globalObject)
133{
134 return getDOMConstructor<JSHTMLDocumentConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
135}
136
137bool JSHTMLDocument::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot)
138{
139 auto* thisObject = jsCast<JSHTMLDocument*>(object);
140 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
141 using GetterIDLType = IDLUnion<IDLInterface<WindowProxy>, IDLInterface<Element>, IDLInterface<HTMLCollection>>;
142 auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> {
143 auto result = thisObject.wrapped().namedItem(propertyNameToAtomicString(propertyName));
144 if (!GetterIDLType::isNullValue(result))
145 return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) };
146 return WTF::nullopt;
147 };
148 if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::Yes>(*state, *thisObject, propertyName, getterFunctor)) {
149 auto value = toJS<IDLUnion<IDLInterface<WindowProxy>, IDLInterface<Element>, IDLInterface<HTMLCollection>>>(*state, *thisObject->globalObject(), WTFMove(namedProperty.value()));
150 slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
151 return true;
152 }
153 return JSObject::getOwnPropertySlot(object, state, propertyName, slot);
154}
155
156bool JSHTMLDocument::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot)
157{
158 auto* thisObject = jsCast<JSHTMLDocument*>(object);
159 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
160 auto propertyName = Identifier::from(state, index);
161 using GetterIDLType = IDLUnion<IDLInterface<WindowProxy>, IDLInterface<Element>, IDLInterface<HTMLCollection>>;
162 auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> {
163 auto result = thisObject.wrapped().namedItem(propertyNameToAtomicString(propertyName));
164 if (!GetterIDLType::isNullValue(result))
165 return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) };
166 return WTF::nullopt;
167 };
168 if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::Yes>(*state, *thisObject, propertyName, getterFunctor)) {
169 auto value = toJS<IDLUnion<IDLInterface<WindowProxy>, IDLInterface<Element>, IDLInterface<HTMLCollection>>>(*state, *thisObject->globalObject(), WTFMove(namedProperty.value()));
170 slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
171 return true;
172 }
173 return JSObject::getOwnPropertySlotByIndex(object, state, index, slot);
174}
175
176void JSHTMLDocument::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode)
177{
178 auto* thisObject = jsCast<JSHTMLDocument*>(object);
179 ASSERT_GC_OBJECT_INHERITS(object, info());
180 for (auto& propertyName : thisObject->wrapped().supportedPropertyNames())
181 propertyNames.add(Identifier::fromString(state, propertyName));
182 JSObject::getOwnPropertyNames(object, state, propertyNames, mode);
183}
184
185EncodedJSValue jsHTMLDocumentConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
186{
187 VM& vm = state->vm();
188 auto throwScope = DECLARE_THROW_SCOPE(vm);
189 auto* prototype = jsDynamicCast<JSHTMLDocumentPrototype*>(vm, JSValue::decode(thisValue));
190 if (UNLIKELY(!prototype))
191 return throwVMTypeError(state, throwScope);
192 return JSValue::encode(JSHTMLDocument::getConstructor(state->vm(), prototype->globalObject()));
193}
194
195bool setJSHTMLDocumentConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
196{
197 VM& vm = state->vm();
198 auto throwScope = DECLARE_THROW_SCOPE(vm);
199 auto* prototype = jsDynamicCast<JSHTMLDocumentPrototype*>(vm, JSValue::decode(thisValue));
200 if (UNLIKELY(!prototype)) {
201 throwVMTypeError(state, throwScope);
202 return false;
203 }
204 // Shadowing a built-in constructor
205 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
206}
207
208void JSHTMLDocument::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
209{
210 auto* thisObject = jsCast<JSHTMLDocument*>(cell);
211 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
212 if (thisObject->scriptExecutionContext())
213 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
214 Base::heapSnapshot(cell, builder);
215}
216
217
218}
219