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 "JSDOMStringMap.h" |
23 | |
24 | #include "CustomElementReactionQueue.h" |
25 | #include "Element.h" |
26 | #include "JSDOMAbstractOperations.h" |
27 | #include "JSDOMBinding.h" |
28 | #include "JSDOMConstructorNotConstructable.h" |
29 | #include "JSDOMConvertStrings.h" |
30 | #include "JSDOMExceptionHandling.h" |
31 | #include "JSDOMWrapperCache.h" |
32 | #include "JSNodeCustom.h" |
33 | #include "ScriptExecutionContext.h" |
34 | #include <JavaScriptCore/FunctionPrototype.h> |
35 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
36 | #include <JavaScriptCore/JSCInlines.h> |
37 | #include <wtf/GetPtr.h> |
38 | #include <wtf/PointerPreparations.h> |
39 | #include <wtf/URL.h> |
40 | |
41 | |
42 | namespace WebCore { |
43 | using namespace JSC; |
44 | |
45 | // Attributes |
46 | |
47 | JSC::EncodedJSValue jsDOMStringMapConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
48 | bool setJSDOMStringMapConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
49 | |
50 | class JSDOMStringMapPrototype : public JSC::JSNonFinalObject { |
51 | public: |
52 | using Base = JSC::JSNonFinalObject; |
53 | static JSDOMStringMapPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
54 | { |
55 | JSDOMStringMapPrototype* ptr = new (NotNull, JSC::allocateCell<JSDOMStringMapPrototype>(vm.heap)) JSDOMStringMapPrototype(vm, globalObject, structure); |
56 | ptr->finishCreation(vm); |
57 | return ptr; |
58 | } |
59 | |
60 | DECLARE_INFO; |
61 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
62 | { |
63 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
64 | } |
65 | |
66 | private: |
67 | JSDOMStringMapPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
68 | : JSC::JSNonFinalObject(vm, structure) |
69 | { |
70 | } |
71 | |
72 | void finishCreation(JSC::VM&); |
73 | }; |
74 | |
75 | using JSDOMStringMapConstructor = JSDOMConstructorNotConstructable<JSDOMStringMap>; |
76 | |
77 | template<> JSValue JSDOMStringMapConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
78 | { |
79 | UNUSED_PARAM(vm); |
80 | return globalObject.functionPrototype(); |
81 | } |
82 | |
83 | template<> void JSDOMStringMapConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
84 | { |
85 | putDirect(vm, vm.propertyNames->prototype, JSDOMStringMap::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
86 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("DOMStringMap"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
87 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
88 | } |
89 | |
90 | template<> const ClassInfo JSDOMStringMapConstructor::s_info = { "DOMStringMap" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMStringMapConstructor) }; |
91 | |
92 | /* Hash table for prototype */ |
93 | |
94 | static const HashTableValue JSDOMStringMapPrototypeTableValues[] = |
95 | { |
96 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMStringMapConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDOMStringMapConstructor) } }, |
97 | }; |
98 | |
99 | const ClassInfo JSDOMStringMapPrototype::s_info = { "DOMStringMapPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMStringMapPrototype) }; |
100 | |
101 | void JSDOMStringMapPrototype::finishCreation(VM& vm) |
102 | { |
103 | Base::finishCreation(vm); |
104 | reifyStaticProperties(vm, JSDOMStringMap::info(), JSDOMStringMapPrototypeTableValues, *this); |
105 | } |
106 | |
107 | const ClassInfo JSDOMStringMap::s_info = { "DOMStringMap" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMStringMap) }; |
108 | |
109 | JSDOMStringMap::JSDOMStringMap(Structure* structure, JSDOMGlobalObject& globalObject, Ref<DOMStringMap>&& impl) |
110 | : JSDOMWrapper<DOMStringMap>(structure, globalObject, WTFMove(impl)) |
111 | { |
112 | } |
113 | |
114 | void JSDOMStringMap::finishCreation(VM& vm) |
115 | { |
116 | Base::finishCreation(vm); |
117 | ASSERT(inherits(vm, info())); |
118 | |
119 | } |
120 | |
121 | JSObject* JSDOMStringMap::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
122 | { |
123 | return JSDOMStringMapPrototype::create(vm, &globalObject, JSDOMStringMapPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
124 | } |
125 | |
126 | JSObject* JSDOMStringMap::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
127 | { |
128 | return getDOMPrototype<JSDOMStringMap>(vm, globalObject); |
129 | } |
130 | |
131 | JSValue JSDOMStringMap::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
132 | { |
133 | return getDOMConstructor<JSDOMStringMapConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
134 | } |
135 | |
136 | void JSDOMStringMap::destroy(JSC::JSCell* cell) |
137 | { |
138 | JSDOMStringMap* thisObject = static_cast<JSDOMStringMap*>(cell); |
139 | thisObject->JSDOMStringMap::~JSDOMStringMap(); |
140 | } |
141 | |
142 | bool JSDOMStringMap::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot) |
143 | { |
144 | auto* thisObject = jsCast<JSDOMStringMap*>(object); |
145 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
146 | using GetterIDLType = IDLDOMString; |
147 | auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> { |
148 | auto result = thisObject.wrapped().namedItem(propertyNameToAtomicString(propertyName)); |
149 | if (!GetterIDLType::isNullValue(result)) |
150 | return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) }; |
151 | return WTF::nullopt; |
152 | }; |
153 | if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::Yes>(*state, *thisObject, propertyName, getterFunctor)) { |
154 | auto value = toJS<IDLDOMString>(*state, WTFMove(namedProperty.value())); |
155 | slot.setValue(thisObject, static_cast<unsigned>(0), value); |
156 | return true; |
157 | } |
158 | return JSObject::getOwnPropertySlot(object, state, propertyName, slot); |
159 | } |
160 | |
161 | bool JSDOMStringMap::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot) |
162 | { |
163 | auto* thisObject = jsCast<JSDOMStringMap*>(object); |
164 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
165 | auto propertyName = Identifier::from(state, index); |
166 | using GetterIDLType = IDLDOMString; |
167 | auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> { |
168 | auto result = thisObject.wrapped().namedItem(propertyNameToAtomicString(propertyName)); |
169 | if (!GetterIDLType::isNullValue(result)) |
170 | return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) }; |
171 | return WTF::nullopt; |
172 | }; |
173 | if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::Yes>(*state, *thisObject, propertyName, getterFunctor)) { |
174 | auto value = toJS<IDLDOMString>(*state, WTFMove(namedProperty.value())); |
175 | slot.setValue(thisObject, static_cast<unsigned>(0), value); |
176 | return true; |
177 | } |
178 | return JSObject::getOwnPropertySlotByIndex(object, state, index, slot); |
179 | } |
180 | |
181 | void JSDOMStringMap::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode) |
182 | { |
183 | auto* thisObject = jsCast<JSDOMStringMap*>(object); |
184 | ASSERT_GC_OBJECT_INHERITS(object, info()); |
185 | for (auto& propertyName : thisObject->wrapped().supportedPropertyNames()) |
186 | propertyNames.add(Identifier::fromString(state, propertyName)); |
187 | JSObject::getOwnPropertyNames(object, state, propertyNames, mode); |
188 | } |
189 | |
190 | bool JSDOMStringMap::put(JSCell* cell, ExecState* state, PropertyName propertyName, JSValue value, PutPropertySlot& putPropertySlot) |
191 | { |
192 | auto* thisObject = jsCast<JSDOMStringMap*>(cell); |
193 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
194 | |
195 | CustomElementReactionStack customElementReactionStack(*state); |
196 | if (!propertyName.isSymbol()) { |
197 | auto throwScope = DECLARE_THROW_SCOPE(state->vm()); |
198 | auto nativeValue = convert<IDLDOMString>(*state, value); |
199 | RETURN_IF_EXCEPTION(throwScope, true); |
200 | propagateException(*state, throwScope, thisObject->wrapped().setNamedItem(propertyNameToString(propertyName), WTFMove(nativeValue))); |
201 | return true; |
202 | } |
203 | |
204 | return JSObject::put(thisObject, state, propertyName, value, putPropertySlot); |
205 | } |
206 | |
207 | bool JSDOMStringMap::putByIndex(JSCell* cell, ExecState* state, unsigned index, JSValue value, bool) |
208 | { |
209 | auto* thisObject = jsCast<JSDOMStringMap*>(cell); |
210 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
211 | |
212 | CustomElementReactionStack customElementReactionStack(*state); |
213 | auto propertyName = Identifier::from(state, index); |
214 | auto throwScope = DECLARE_THROW_SCOPE(state->vm()); |
215 | auto nativeValue = convert<IDLDOMString>(*state, value); |
216 | RETURN_IF_EXCEPTION(throwScope, true); |
217 | propagateException(*state, throwScope, thisObject->wrapped().setNamedItem(propertyNameToString(propertyName), WTFMove(nativeValue))); |
218 | return true; |
219 | } |
220 | |
221 | bool JSDOMStringMap::defineOwnProperty(JSObject* object, ExecState* state, PropertyName propertyName, const PropertyDescriptor& propertyDescriptor, bool shouldThrow) |
222 | { |
223 | auto* thisObject = jsCast<JSDOMStringMap*>(object); |
224 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
225 | |
226 | CustomElementReactionStack customElementReactionStack(*state); |
227 | if (!propertyName.isSymbol()) { |
228 | if (!propertyDescriptor.isDataDescriptor()) |
229 | return false; |
230 | auto throwScope = DECLARE_THROW_SCOPE(state->vm()); |
231 | auto nativeValue = convert<IDLDOMString>(*state, propertyDescriptor.value()); |
232 | RETURN_IF_EXCEPTION(throwScope, true); |
233 | propagateException(*state, throwScope, thisObject->wrapped().setNamedItem(propertyNameToString(propertyName), WTFMove(nativeValue))); |
234 | return true; |
235 | } |
236 | |
237 | PropertyDescriptor newPropertyDescriptor = propertyDescriptor; |
238 | newPropertyDescriptor.setConfigurable(true); |
239 | return JSObject::defineOwnProperty(object, state, propertyName, newPropertyDescriptor, shouldThrow); |
240 | } |
241 | |
242 | bool JSDOMStringMap::deleteProperty(JSCell* cell, ExecState* state, PropertyName propertyName) |
243 | { |
244 | auto& thisObject = *jsCast<JSDOMStringMap*>(cell); |
245 | auto& impl = thisObject.wrapped(); |
246 | if (isVisibleNamedProperty<OverrideBuiltins::Yes>(*state, thisObject, propertyName)) { |
247 | CustomElementReactionStack customElementReactionStack(*state); |
248 | return impl.deleteNamedProperty(propertyNameToString(propertyName)); |
249 | } |
250 | return JSObject::deleteProperty(cell, state, propertyName); |
251 | } |
252 | |
253 | bool JSDOMStringMap::deletePropertyByIndex(JSCell* cell, ExecState* state, unsigned index) |
254 | { |
255 | auto& thisObject = *jsCast<JSDOMStringMap*>(cell); |
256 | auto& impl = thisObject.wrapped(); |
257 | auto propertyName = Identifier::from(state, index); |
258 | if (isVisibleNamedProperty<OverrideBuiltins::Yes>(*state, thisObject, propertyName)) { |
259 | CustomElementReactionStack customElementReactionStack(*state); |
260 | return impl.deleteNamedProperty(propertyNameToString(propertyName)); |
261 | } |
262 | return JSObject::deletePropertyByIndex(cell, state, index); |
263 | } |
264 | |
265 | EncodedJSValue jsDOMStringMapConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
266 | { |
267 | VM& vm = state->vm(); |
268 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
269 | auto* prototype = jsDynamicCast<JSDOMStringMapPrototype*>(vm, JSValue::decode(thisValue)); |
270 | if (UNLIKELY(!prototype)) |
271 | return throwVMTypeError(state, throwScope); |
272 | return JSValue::encode(JSDOMStringMap::getConstructor(state->vm(), prototype->globalObject())); |
273 | } |
274 | |
275 | bool setJSDOMStringMapConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
276 | { |
277 | VM& vm = state->vm(); |
278 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
279 | auto* prototype = jsDynamicCast<JSDOMStringMapPrototype*>(vm, JSValue::decode(thisValue)); |
280 | if (UNLIKELY(!prototype)) { |
281 | throwVMTypeError(state, throwScope); |
282 | return false; |
283 | } |
284 | // Shadowing a built-in constructor |
285 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
286 | } |
287 | |
288 | void JSDOMStringMap::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
289 | { |
290 | auto* thisObject = jsCast<JSDOMStringMap*>(cell); |
291 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
292 | if (thisObject->scriptExecutionContext()) |
293 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
294 | Base::heapSnapshot(cell, builder); |
295 | } |
296 | |
297 | bool JSDOMStringMapOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
298 | { |
299 | auto* jsDOMStringMap = jsCast<JSDOMStringMap*>(handle.slot()->asCell()); |
300 | Element* element = WTF::getPtr(jsDOMStringMap->wrapped().element()); |
301 | if (!element) |
302 | return false; |
303 | if (UNLIKELY(reason)) |
304 | *reason = "Reachable from DOMStringMapOwner" ; |
305 | void* root = WebCore::root(element); |
306 | return visitor.containsOpaqueRoot(root); |
307 | } |
308 | |
309 | void JSDOMStringMapOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
310 | { |
311 | auto* jsDOMStringMap = static_cast<JSDOMStringMap*>(handle.slot()->asCell()); |
312 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
313 | uncacheWrapper(world, &jsDOMStringMap->wrapped(), jsDOMStringMap); |
314 | } |
315 | |
316 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<DOMStringMap>&& impl) |
317 | { |
318 | return createWrapper<DOMStringMap>(globalObject, WTFMove(impl)); |
319 | } |
320 | |
321 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, DOMStringMap& impl) |
322 | { |
323 | return wrap(state, globalObject, impl); |
324 | } |
325 | |
326 | DOMStringMap* JSDOMStringMap::toWrapped(JSC::VM& vm, JSC::JSValue value) |
327 | { |
328 | if (auto* wrapper = jsDynamicCast<JSDOMStringMap*>(vm, value)) |
329 | return &wrapper->wrapped(); |
330 | return nullptr; |
331 | } |
332 | |
333 | } |
334 | |