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 "JSStorage.h" |
23 | |
24 | #include "JSDOMAbstractOperations.h" |
25 | #include "JSDOMAttribute.h" |
26 | #include "JSDOMBinding.h" |
27 | #include "JSDOMConstructorNotConstructable.h" |
28 | #include "JSDOMConvertNullable.h" |
29 | #include "JSDOMConvertNumbers.h" |
30 | #include "JSDOMConvertStrings.h" |
31 | #include "JSDOMExceptionHandling.h" |
32 | #include "JSDOMOperation.h" |
33 | #include "JSDOMWrapperCache.h" |
34 | #include "ScriptExecutionContext.h" |
35 | #include <JavaScriptCore/FunctionPrototype.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 | |
42 | |
43 | namespace WebCore { |
44 | using namespace JSC; |
45 | |
46 | // Functions |
47 | |
48 | JSC::EncodedJSValue JSC_HOST_CALL jsStoragePrototypeFunctionKey(JSC::ExecState*); |
49 | JSC::EncodedJSValue JSC_HOST_CALL jsStoragePrototypeFunctionGetItem(JSC::ExecState*); |
50 | JSC::EncodedJSValue JSC_HOST_CALL jsStoragePrototypeFunctionSetItem(JSC::ExecState*); |
51 | JSC::EncodedJSValue JSC_HOST_CALL jsStoragePrototypeFunctionRemoveItem(JSC::ExecState*); |
52 | JSC::EncodedJSValue JSC_HOST_CALL jsStoragePrototypeFunctionClear(JSC::ExecState*); |
53 | |
54 | // Attributes |
55 | |
56 | JSC::EncodedJSValue jsStorageConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
57 | bool setJSStorageConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
58 | JSC::EncodedJSValue jsStorageLength(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
59 | |
60 | class JSStoragePrototype : public JSC::JSNonFinalObject { |
61 | public: |
62 | using Base = JSC::JSNonFinalObject; |
63 | static JSStoragePrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
64 | { |
65 | JSStoragePrototype* ptr = new (NotNull, JSC::allocateCell<JSStoragePrototype>(vm.heap)) JSStoragePrototype(vm, globalObject, structure); |
66 | ptr->finishCreation(vm); |
67 | return ptr; |
68 | } |
69 | |
70 | DECLARE_INFO; |
71 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
72 | { |
73 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
74 | } |
75 | |
76 | private: |
77 | JSStoragePrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
78 | : JSC::JSNonFinalObject(vm, structure) |
79 | { |
80 | } |
81 | |
82 | void finishCreation(JSC::VM&); |
83 | }; |
84 | |
85 | using JSStorageConstructor = JSDOMConstructorNotConstructable<JSStorage>; |
86 | |
87 | template<> JSValue JSStorageConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
88 | { |
89 | UNUSED_PARAM(vm); |
90 | return globalObject.functionPrototype(); |
91 | } |
92 | |
93 | template<> void JSStorageConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
94 | { |
95 | putDirect(vm, vm.propertyNames->prototype, JSStorage::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
96 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("Storage"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
97 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
98 | } |
99 | |
100 | template<> const ClassInfo JSStorageConstructor::s_info = { "Storage" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSStorageConstructor) }; |
101 | |
102 | /* Hash table for prototype */ |
103 | |
104 | static const HashTableValue JSStoragePrototypeTableValues[] = |
105 | { |
106 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsStorageConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSStorageConstructor) } }, |
107 | { "length" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsStorageLength), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
108 | { "key" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsStoragePrototypeFunctionKey), (intptr_t) (1) } }, |
109 | { "getItem" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsStoragePrototypeFunctionGetItem), (intptr_t) (1) } }, |
110 | { "setItem" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsStoragePrototypeFunctionSetItem), (intptr_t) (2) } }, |
111 | { "removeItem" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsStoragePrototypeFunctionRemoveItem), (intptr_t) (1) } }, |
112 | { "clear" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsStoragePrototypeFunctionClear), (intptr_t) (0) } }, |
113 | }; |
114 | |
115 | const ClassInfo JSStoragePrototype::s_info = { "StoragePrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSStoragePrototype) }; |
116 | |
117 | void JSStoragePrototype::finishCreation(VM& vm) |
118 | { |
119 | Base::finishCreation(vm); |
120 | reifyStaticProperties(vm, JSStorage::info(), JSStoragePrototypeTableValues, *this); |
121 | } |
122 | |
123 | const ClassInfo JSStorage::s_info = { "Storage" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSStorage) }; |
124 | |
125 | JSStorage::JSStorage(Structure* structure, JSDOMGlobalObject& globalObject, Ref<Storage>&& impl) |
126 | : JSDOMWrapper<Storage>(structure, globalObject, WTFMove(impl)) |
127 | { |
128 | } |
129 | |
130 | void JSStorage::finishCreation(VM& vm) |
131 | { |
132 | Base::finishCreation(vm); |
133 | ASSERT(inherits(vm, info())); |
134 | |
135 | } |
136 | |
137 | JSObject* JSStorage::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
138 | { |
139 | return JSStoragePrototype::create(vm, &globalObject, JSStoragePrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
140 | } |
141 | |
142 | JSObject* JSStorage::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
143 | { |
144 | return getDOMPrototype<JSStorage>(vm, globalObject); |
145 | } |
146 | |
147 | JSValue JSStorage::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
148 | { |
149 | return getDOMConstructor<JSStorageConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
150 | } |
151 | |
152 | void JSStorage::destroy(JSC::JSCell* cell) |
153 | { |
154 | JSStorage* thisObject = static_cast<JSStorage*>(cell); |
155 | thisObject->JSStorage::~JSStorage(); |
156 | } |
157 | |
158 | bool JSStorage::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot) |
159 | { |
160 | auto* thisObject = jsCast<JSStorage*>(object); |
161 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
162 | using GetterIDLType = IDLDOMString; |
163 | auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> { |
164 | auto result = thisObject.wrapped().getItem(propertyNameToAtomicString(propertyName)); |
165 | if (!GetterIDLType::isNullValue(result)) |
166 | return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) }; |
167 | return WTF::nullopt; |
168 | }; |
169 | if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) { |
170 | auto value = toJS<IDLNullable<IDLDOMString>>(*state, WTFMove(namedProperty.value())); |
171 | slot.setValue(thisObject, static_cast<unsigned>(0), value); |
172 | return true; |
173 | } |
174 | return JSObject::getOwnPropertySlot(object, state, propertyName, slot); |
175 | } |
176 | |
177 | bool JSStorage::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot) |
178 | { |
179 | auto* thisObject = jsCast<JSStorage*>(object); |
180 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
181 | auto propertyName = Identifier::from(state, index); |
182 | using GetterIDLType = IDLDOMString; |
183 | auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> { |
184 | auto result = thisObject.wrapped().getItem(propertyNameToAtomicString(propertyName)); |
185 | if (!GetterIDLType::isNullValue(result)) |
186 | return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) }; |
187 | return WTF::nullopt; |
188 | }; |
189 | if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) { |
190 | auto value = toJS<IDLNullable<IDLDOMString>>(*state, WTFMove(namedProperty.value())); |
191 | slot.setValue(thisObject, static_cast<unsigned>(0), value); |
192 | return true; |
193 | } |
194 | return JSObject::getOwnPropertySlotByIndex(object, state, index, slot); |
195 | } |
196 | |
197 | void JSStorage::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode) |
198 | { |
199 | auto* thisObject = jsCast<JSStorage*>(object); |
200 | ASSERT_GC_OBJECT_INHERITS(object, info()); |
201 | for (auto& propertyName : thisObject->wrapped().supportedPropertyNames()) |
202 | propertyNames.add(Identifier::fromString(state, propertyName)); |
203 | JSObject::getOwnPropertyNames(object, state, propertyNames, mode); |
204 | } |
205 | |
206 | bool JSStorage::put(JSCell* cell, ExecState* state, PropertyName propertyName, JSValue value, PutPropertySlot& putPropertySlot) |
207 | { |
208 | auto* thisObject = jsCast<JSStorage*>(cell); |
209 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
210 | |
211 | if (!propertyName.isSymbol()) { |
212 | PropertySlot slot { thisObject, PropertySlot::InternalMethodType::VMInquiry }; |
213 | JSValue prototype = thisObject->getPrototypeDirect(state->vm()); |
214 | if (!(prototype.isObject() && asObject(prototype)->getPropertySlot(state, propertyName, slot))) { |
215 | auto throwScope = DECLARE_THROW_SCOPE(state->vm()); |
216 | auto nativeValue = convert<IDLDOMString>(*state, value); |
217 | RETURN_IF_EXCEPTION(throwScope, true); |
218 | propagateException(*state, throwScope, thisObject->wrapped().setItem(propertyNameToString(propertyName), WTFMove(nativeValue))); |
219 | return true; |
220 | } |
221 | } |
222 | |
223 | return JSObject::put(thisObject, state, propertyName, value, putPropertySlot); |
224 | } |
225 | |
226 | bool JSStorage::putByIndex(JSCell* cell, ExecState* state, unsigned index, JSValue value, bool shouldThrow) |
227 | { |
228 | auto* thisObject = jsCast<JSStorage*>(cell); |
229 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
230 | |
231 | auto propertyName = Identifier::from(state, index); |
232 | PropertySlot slot { thisObject, PropertySlot::InternalMethodType::VMInquiry }; |
233 | JSValue prototype = thisObject->getPrototypeDirect(state->vm()); |
234 | if (!(prototype.isObject() && asObject(prototype)->getPropertySlot(state, propertyName, slot))) { |
235 | auto throwScope = DECLARE_THROW_SCOPE(state->vm()); |
236 | auto nativeValue = convert<IDLDOMString>(*state, value); |
237 | RETURN_IF_EXCEPTION(throwScope, true); |
238 | propagateException(*state, throwScope, thisObject->wrapped().setItem(propertyNameToString(propertyName), WTFMove(nativeValue))); |
239 | return true; |
240 | } |
241 | |
242 | return JSObject::putByIndex(cell, state, index, value, shouldThrow); |
243 | } |
244 | |
245 | bool JSStorage::defineOwnProperty(JSObject* object, ExecState* state, PropertyName propertyName, const PropertyDescriptor& propertyDescriptor, bool shouldThrow) |
246 | { |
247 | auto* thisObject = jsCast<JSStorage*>(object); |
248 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
249 | |
250 | if (!propertyName.isSymbol()) { |
251 | PropertySlot slot { thisObject, PropertySlot::InternalMethodType::VMInquiry }; |
252 | if (!JSObject::getOwnPropertySlot(thisObject, state, propertyName, slot)) { |
253 | if (!propertyDescriptor.isDataDescriptor()) |
254 | return false; |
255 | auto throwScope = DECLARE_THROW_SCOPE(state->vm()); |
256 | auto nativeValue = convert<IDLDOMString>(*state, propertyDescriptor.value()); |
257 | RETURN_IF_EXCEPTION(throwScope, true); |
258 | propagateException(*state, throwScope, thisObject->wrapped().setItem(propertyNameToString(propertyName), WTFMove(nativeValue))); |
259 | return true; |
260 | } |
261 | } |
262 | |
263 | PropertyDescriptor newPropertyDescriptor = propertyDescriptor; |
264 | newPropertyDescriptor.setConfigurable(true); |
265 | return JSObject::defineOwnProperty(object, state, propertyName, newPropertyDescriptor, shouldThrow); |
266 | } |
267 | |
268 | bool JSStorage::deleteProperty(JSCell* cell, ExecState* state, PropertyName propertyName) |
269 | { |
270 | auto& thisObject = *jsCast<JSStorage*>(cell); |
271 | auto& impl = thisObject.wrapped(); |
272 | if (isVisibleNamedProperty<OverrideBuiltins::No>(*state, thisObject, propertyName)) { |
273 | auto result = impl.removeItem(propertyNameToString(propertyName)); |
274 | if (result.hasException()) { |
275 | auto throwScope = DECLARE_THROW_SCOPE(state->vm()); |
276 | propagateException(*state, throwScope, result.releaseException()); |
277 | return true; |
278 | } |
279 | |
280 | return true; |
281 | } |
282 | return JSObject::deleteProperty(cell, state, propertyName); |
283 | } |
284 | |
285 | bool JSStorage::deletePropertyByIndex(JSCell* cell, ExecState* state, unsigned index) |
286 | { |
287 | auto& thisObject = *jsCast<JSStorage*>(cell); |
288 | auto& impl = thisObject.wrapped(); |
289 | auto propertyName = Identifier::from(state, index); |
290 | if (isVisibleNamedProperty<OverrideBuiltins::No>(*state, thisObject, propertyName)) { |
291 | auto result = impl.removeItem(propertyNameToString(propertyName)); |
292 | if (result.hasException()) { |
293 | auto throwScope = DECLARE_THROW_SCOPE(state->vm()); |
294 | propagateException(*state, throwScope, result.releaseException()); |
295 | return true; |
296 | } |
297 | |
298 | return true; |
299 | } |
300 | return JSObject::deletePropertyByIndex(cell, state, index); |
301 | } |
302 | |
303 | template<> inline JSStorage* IDLAttribute<JSStorage>::cast(ExecState& state, EncodedJSValue thisValue) |
304 | { |
305 | return jsDynamicCast<JSStorage*>(state.vm(), JSValue::decode(thisValue)); |
306 | } |
307 | |
308 | template<> inline JSStorage* IDLOperation<JSStorage>::cast(ExecState& state) |
309 | { |
310 | return jsDynamicCast<JSStorage*>(state.vm(), state.thisValue()); |
311 | } |
312 | |
313 | EncodedJSValue jsStorageConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
314 | { |
315 | VM& vm = state->vm(); |
316 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
317 | auto* prototype = jsDynamicCast<JSStoragePrototype*>(vm, JSValue::decode(thisValue)); |
318 | if (UNLIKELY(!prototype)) |
319 | return throwVMTypeError(state, throwScope); |
320 | return JSValue::encode(JSStorage::getConstructor(state->vm(), prototype->globalObject())); |
321 | } |
322 | |
323 | bool setJSStorageConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
324 | { |
325 | VM& vm = state->vm(); |
326 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
327 | auto* prototype = jsDynamicCast<JSStoragePrototype*>(vm, JSValue::decode(thisValue)); |
328 | if (UNLIKELY(!prototype)) { |
329 | throwVMTypeError(state, throwScope); |
330 | return false; |
331 | } |
332 | // Shadowing a built-in constructor |
333 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
334 | } |
335 | |
336 | static inline JSValue jsStorageLengthGetter(ExecState& state, JSStorage& thisObject, ThrowScope& throwScope) |
337 | { |
338 | UNUSED_PARAM(throwScope); |
339 | UNUSED_PARAM(state); |
340 | auto& impl = thisObject.wrapped(); |
341 | JSValue result = toJS<IDLUnsignedLong>(state, throwScope, impl.length()); |
342 | return result; |
343 | } |
344 | |
345 | EncodedJSValue jsStorageLength(ExecState* state, EncodedJSValue thisValue, PropertyName) |
346 | { |
347 | return IDLAttribute<JSStorage>::get<jsStorageLengthGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "length" ); |
348 | } |
349 | |
350 | static inline JSC::EncodedJSValue jsStoragePrototypeFunctionKeyBody(JSC::ExecState* state, typename IDLOperation<JSStorage>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
351 | { |
352 | UNUSED_PARAM(state); |
353 | UNUSED_PARAM(throwScope); |
354 | auto& impl = castedThis->wrapped(); |
355 | if (UNLIKELY(state->argumentCount() < 1)) |
356 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
357 | auto index = convert<IDLUnsignedLong>(*state, state->uncheckedArgument(0)); |
358 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
359 | return JSValue::encode(toJS<IDLNullable<IDLDOMString>>(*state, impl.key(WTFMove(index)))); |
360 | } |
361 | |
362 | EncodedJSValue JSC_HOST_CALL jsStoragePrototypeFunctionKey(ExecState* state) |
363 | { |
364 | return IDLOperation<JSStorage>::call<jsStoragePrototypeFunctionKeyBody>(*state, "key" ); |
365 | } |
366 | |
367 | static inline JSC::EncodedJSValue jsStoragePrototypeFunctionGetItemBody(JSC::ExecState* state, typename IDLOperation<JSStorage>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
368 | { |
369 | UNUSED_PARAM(state); |
370 | UNUSED_PARAM(throwScope); |
371 | auto& impl = castedThis->wrapped(); |
372 | if (UNLIKELY(state->argumentCount() < 1)) |
373 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
374 | auto key = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
375 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
376 | return JSValue::encode(toJS<IDLNullable<IDLDOMString>>(*state, impl.getItem(WTFMove(key)))); |
377 | } |
378 | |
379 | EncodedJSValue JSC_HOST_CALL jsStoragePrototypeFunctionGetItem(ExecState* state) |
380 | { |
381 | return IDLOperation<JSStorage>::call<jsStoragePrototypeFunctionGetItemBody>(*state, "getItem" ); |
382 | } |
383 | |
384 | static inline JSC::EncodedJSValue jsStoragePrototypeFunctionSetItemBody(JSC::ExecState* state, typename IDLOperation<JSStorage>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
385 | { |
386 | UNUSED_PARAM(state); |
387 | UNUSED_PARAM(throwScope); |
388 | auto& impl = castedThis->wrapped(); |
389 | if (UNLIKELY(state->argumentCount() < 2)) |
390 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
391 | auto key = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
392 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
393 | auto data = convert<IDLDOMString>(*state, state->uncheckedArgument(1)); |
394 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
395 | propagateException(*state, throwScope, impl.setItem(WTFMove(key), WTFMove(data))); |
396 | return JSValue::encode(jsUndefined()); |
397 | } |
398 | |
399 | EncodedJSValue JSC_HOST_CALL jsStoragePrototypeFunctionSetItem(ExecState* state) |
400 | { |
401 | return IDLOperation<JSStorage>::call<jsStoragePrototypeFunctionSetItemBody>(*state, "setItem" ); |
402 | } |
403 | |
404 | static inline JSC::EncodedJSValue jsStoragePrototypeFunctionRemoveItemBody(JSC::ExecState* state, typename IDLOperation<JSStorage>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
405 | { |
406 | UNUSED_PARAM(state); |
407 | UNUSED_PARAM(throwScope); |
408 | auto& impl = castedThis->wrapped(); |
409 | if (UNLIKELY(state->argumentCount() < 1)) |
410 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
411 | auto key = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
412 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
413 | propagateException(*state, throwScope, impl.removeItem(WTFMove(key))); |
414 | return JSValue::encode(jsUndefined()); |
415 | } |
416 | |
417 | EncodedJSValue JSC_HOST_CALL jsStoragePrototypeFunctionRemoveItem(ExecState* state) |
418 | { |
419 | return IDLOperation<JSStorage>::call<jsStoragePrototypeFunctionRemoveItemBody>(*state, "removeItem" ); |
420 | } |
421 | |
422 | static inline JSC::EncodedJSValue jsStoragePrototypeFunctionClearBody(JSC::ExecState* state, typename IDLOperation<JSStorage>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
423 | { |
424 | UNUSED_PARAM(state); |
425 | UNUSED_PARAM(throwScope); |
426 | auto& impl = castedThis->wrapped(); |
427 | propagateException(*state, throwScope, impl.clear()); |
428 | return JSValue::encode(jsUndefined()); |
429 | } |
430 | |
431 | EncodedJSValue JSC_HOST_CALL jsStoragePrototypeFunctionClear(ExecState* state) |
432 | { |
433 | return IDLOperation<JSStorage>::call<jsStoragePrototypeFunctionClearBody>(*state, "clear" ); |
434 | } |
435 | |
436 | void JSStorage::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
437 | { |
438 | auto* thisObject = jsCast<JSStorage*>(cell); |
439 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
440 | if (thisObject->scriptExecutionContext()) |
441 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
442 | Base::heapSnapshot(cell, builder); |
443 | } |
444 | |
445 | bool JSStorageOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
446 | { |
447 | auto* jsStorage = jsCast<JSStorage*>(handle.slot()->asCell()); |
448 | Frame* root = WTF::getPtr(jsStorage->wrapped().frame()); |
449 | if (!root) |
450 | return false; |
451 | if (UNLIKELY(reason)) |
452 | *reason = "Reachable from Frame" ; |
453 | return visitor.containsOpaqueRoot(root); |
454 | } |
455 | |
456 | void JSStorageOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
457 | { |
458 | auto* jsStorage = static_cast<JSStorage*>(handle.slot()->asCell()); |
459 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
460 | uncacheWrapper(world, &jsStorage->wrapped(), jsStorage); |
461 | } |
462 | |
463 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<Storage>&& impl) |
464 | { |
465 | return createWrapper<Storage>(globalObject, WTFMove(impl)); |
466 | } |
467 | |
468 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, Storage& impl) |
469 | { |
470 | return wrap(state, globalObject, impl); |
471 | } |
472 | |
473 | Storage* JSStorage::toWrapped(JSC::VM& vm, JSC::JSValue value) |
474 | { |
475 | if (auto* wrapper = jsDynamicCast<JSStorage*>(vm, value)) |
476 | return &wrapper->wrapped(); |
477 | return nullptr; |
478 | } |
479 | |
480 | } |
481 | |