2 This file is part of the WebKit open source project.
3 This file has been generated by generate-bindings.pl. DO NOT MODIFY!
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.
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.
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.
22 #include "JSStorage.h"
24 #include "ExceptionCode.h"
25 #include "JSDOMBinding.h"
26 #include "JSStorageCustom.h"
29 #include "wtf/text/AtomicString.h"
30 #include <runtime/Error.h>
31 #include <wtf/GetPtr.h>
37 ASSERT_CLASS_FITS_IN_CELL(JSStorage);
41 #define THUNK_GENERATOR(generator) , generator
43 #define THUNK_GENERATOR(generator)
46 #define INTRINSIC(intrinsic) , intrinsic
48 #define INTRINSIC(intrinsic)
51 static const HashTableValue JSStorageTableValues[] =
53 { "length", DontDelete | DontEnum | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsStorageLength), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
54 { "constructor", DontEnum | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsStorageConstructor), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
55 { 0, 0, 0, 0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) }
58 #undef THUNK_GENERATOR
59 static const HashTable JSStorageTable = { 5, 3, JSStorageTableValues, 0 };
60 /* Hash table for constructor */
62 #define THUNK_GENERATOR(generator) , generator
64 #define THUNK_GENERATOR(generator)
67 #define INTRINSIC(intrinsic) , intrinsic
69 #define INTRINSIC(intrinsic)
72 static const HashTableValue JSStorageConstructorTableValues[] =
74 { 0, 0, 0, 0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) }
77 #undef THUNK_GENERATOR
78 static const HashTable JSStorageConstructorTable = { 1, 0, JSStorageConstructorTableValues, 0 };
79 const ClassInfo JSStorageConstructor::s_info = { "StorageConstructor", &DOMConstructorObject::s_info, &JSStorageConstructorTable, 0, CREATE_METHOD_TABLE(JSStorageConstructor) };
81 JSStorageConstructor::JSStorageConstructor(Structure* structure, JSDOMGlobalObject* globalObject)
82 : DOMConstructorObject(structure, globalObject)
86 void JSStorageConstructor::finishCreation(ExecState* exec, JSDOMGlobalObject* globalObject)
88 Base::finishCreation(exec->globalData());
89 ASSERT(inherits(&s_info));
90 putDirect(exec->globalData(), exec->propertyNames().prototype, JSStoragePrototype::self(exec, globalObject), DontDelete | ReadOnly);
93 bool JSStorageConstructor::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
95 return getStaticValueSlot<JSStorageConstructor, JSDOMWrapper>(exec, &JSStorageConstructorTable, static_cast<JSStorageConstructor*>(cell), propertyName, slot);
98 bool JSStorageConstructor::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
100 return getStaticValueDescriptor<JSStorageConstructor, JSDOMWrapper>(exec, &JSStorageConstructorTable, static_cast<JSStorageConstructor*>(object), propertyName, descriptor);
103 /* Hash table for prototype */
105 #define THUNK_GENERATOR(generator) , generator
107 #define THUNK_GENERATOR(generator)
110 #define INTRINSIC(intrinsic) , intrinsic
112 #define INTRINSIC(intrinsic)
115 static const HashTableValue JSStoragePrototypeTableValues[] =
117 { "key", DontDelete | DontEnum | Function, (intptr_t)static_cast<NativeFunction>(jsStoragePrototypeFunctionKey), (intptr_t)1 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
118 { "getItem", DontDelete | DontEnum | Function, (intptr_t)static_cast<NativeFunction>(jsStoragePrototypeFunctionGetItem), (intptr_t)1 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
119 { "setItem", DontDelete | DontEnum | Function, (intptr_t)static_cast<NativeFunction>(jsStoragePrototypeFunctionSetItem), (intptr_t)2 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
120 { "removeItem", DontDelete | DontEnum | Function, (intptr_t)static_cast<NativeFunction>(jsStoragePrototypeFunctionRemoveItem), (intptr_t)1 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
121 { "clear", DontDelete | DontEnum | Function, (intptr_t)static_cast<NativeFunction>(jsStoragePrototypeFunctionClear), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
122 { 0, 0, 0, 0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) }
125 #undef THUNK_GENERATOR
126 static const HashTable JSStoragePrototypeTable = { 17, 15, JSStoragePrototypeTableValues, 0 };
127 const ClassInfo JSStoragePrototype::s_info = { "StoragePrototype", &JSC::JSNonFinalObject::s_info, &JSStoragePrototypeTable, 0, CREATE_METHOD_TABLE(JSStoragePrototype) };
129 JSObject* JSStoragePrototype::self(ExecState* exec, JSGlobalObject* globalObject)
131 return getDOMPrototype<JSStorage>(exec, globalObject);
134 bool JSStoragePrototype::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
136 JSStoragePrototype* thisObject = jsCast<JSStoragePrototype*>(cell);
137 return getStaticFunctionSlot<JSObject>(exec, &JSStoragePrototypeTable, thisObject, propertyName, slot);
140 bool JSStoragePrototype::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
142 JSStoragePrototype* thisObject = jsCast<JSStoragePrototype*>(object);
143 return getStaticFunctionDescriptor<JSObject>(exec, &JSStoragePrototypeTable, thisObject, propertyName, descriptor);
146 const ClassInfo JSStorage::s_info = { "Storage", &JSDOMWrapper::s_info, &JSStorageTable, 0 , CREATE_METHOD_TABLE(JSStorage) };
148 JSStorage::JSStorage(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<Storage> impl)
149 : JSDOMWrapper(structure, globalObject)
150 , m_impl(impl.leakRef())
154 void JSStorage::finishCreation(JSGlobalData& globalData)
156 Base::finishCreation(globalData);
157 ASSERT(inherits(&s_info));
160 JSObject* JSStorage::createPrototype(ExecState* exec, JSGlobalObject* globalObject)
162 return JSStoragePrototype::create(exec->globalData(), globalObject, JSStoragePrototype::createStructure(globalObject->globalData(), globalObject, globalObject->objectPrototype()));
165 bool JSStorage::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
167 JSStorage* thisObject = jsCast<JSStorage*>(cell);
168 ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
169 const HashEntry* entry = JSStorageTable.entry(exec, propertyName);
171 slot.setCustom(thisObject, entry->propertyGetter());
174 if (canGetItemsForName(exec, static_cast<Storage*>(thisObject->impl()), propertyName)) {
175 slot.setCustom(thisObject, thisObject->nameGetter);
178 return getStaticValueSlot<JSStorage, Base>(exec, &JSStorageTable, thisObject, propertyName, slot);
181 bool JSStorage::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
183 JSStorage* thisObject = jsCast<JSStorage*>(object);
184 ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
185 const HashEntry* entry = JSStorageTable.entry(exec, propertyName);
188 slot.setCustom(thisObject, entry->propertyGetter());
189 descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes());
192 if (canGetItemsForName(exec, static_cast<Storage*>(thisObject->impl()), propertyName)) {
194 slot.setCustom(thisObject, nameGetter);
195 descriptor.setDescriptor(slot.getValue(exec, propertyName), ReadOnly | DontDelete | DontEnum);
198 return getStaticValueDescriptor<JSStorage, Base>(exec, &JSStorageTable, thisObject, propertyName, descriptor);
201 JSValue jsStorageLength(ExecState* exec, JSValue slotBase, const Identifier&)
203 JSStorage* castedThis = static_cast<JSStorage*>(asObject(slotBase));
205 Storage* imp = static_cast<Storage*>(castedThis->impl());
206 JSValue result = jsNumber(imp->length());
211 JSValue jsStorageConstructor(ExecState* exec, JSValue slotBase, const Identifier&)
213 JSStorage* domObject = static_cast<JSStorage*>(asObject(slotBase));
214 return JSStorage::getConstructor(exec, domObject->globalObject());
217 void JSStorage::put(JSCell* cell, ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
219 JSStorage* thisObject = jsCast<JSStorage*>(cell);
220 ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
221 if (thisObject->putDelegate(exec, propertyName, value, slot))
223 Base::put(thisObject, exec, propertyName, value, slot);
226 JSValue JSStorage::getConstructor(ExecState* exec, JSGlobalObject* globalObject)
228 return getDOMConstructor<JSStorageConstructor>(exec, static_cast<JSDOMGlobalObject*>(globalObject));
231 EncodedJSValue JSC_HOST_CALL jsStoragePrototypeFunctionKey(ExecState* exec)
233 JSValue thisValue = exec->hostThisValue();
234 if (!thisValue.inherits(&JSStorage::s_info))
235 return throwVMTypeError(exec);
236 JSStorage* castedThis = static_cast<JSStorage*>(asObject(thisValue));
237 ASSERT_GC_OBJECT_INHERITS(castedThis, &JSStorage::s_info);
238 Storage* imp = static_cast<Storage*>(castedThis->impl());
239 if (exec->argumentCount() < 1)
240 return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
241 unsigned index(MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined).toUInt32(exec));
242 if (exec->hadException())
243 return JSValue::encode(jsUndefined());
245 JSC::JSValue result = jsStringOrNull(exec, imp->key(index));
246 return JSValue::encode(result);
249 EncodedJSValue JSC_HOST_CALL jsStoragePrototypeFunctionGetItem(ExecState* exec)
251 JSValue thisValue = exec->hostThisValue();
252 if (!thisValue.inherits(&JSStorage::s_info))
253 return throwVMTypeError(exec);
254 JSStorage* castedThis = static_cast<JSStorage*>(asObject(thisValue));
255 ASSERT_GC_OBJECT_INHERITS(castedThis, &JSStorage::s_info);
256 Storage* imp = static_cast<Storage*>(castedThis->impl());
257 if (exec->argumentCount() < 1)
258 return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
259 const String& key(ustringToString(MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined).isEmpty() ? UString() : MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined).toString(exec)));
260 if (exec->hadException())
261 return JSValue::encode(jsUndefined());
263 JSC::JSValue result = jsStringOrNull(exec, imp->getItem(key));
264 return JSValue::encode(result);
267 EncodedJSValue JSC_HOST_CALL jsStoragePrototypeFunctionSetItem(ExecState* exec)
269 JSValue thisValue = exec->hostThisValue();
270 if (!thisValue.inherits(&JSStorage::s_info))
271 return throwVMTypeError(exec);
272 JSStorage* castedThis = static_cast<JSStorage*>(asObject(thisValue));
273 ASSERT_GC_OBJECT_INHERITS(castedThis, &JSStorage::s_info);
274 Storage* imp = static_cast<Storage*>(castedThis->impl());
275 if (exec->argumentCount() < 2)
276 return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
277 ExceptionCode ec = 0;
278 const String& key(ustringToString(MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined).isEmpty() ? UString() : MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined).toString(exec)));
279 if (exec->hadException())
280 return JSValue::encode(jsUndefined());
281 const String& data(ustringToString(MAYBE_MISSING_PARAMETER(exec, 1, MissingIsUndefined).isEmpty() ? UString() : MAYBE_MISSING_PARAMETER(exec, 1, MissingIsUndefined).toString(exec)));
282 if (exec->hadException())
283 return JSValue::encode(jsUndefined());
284 imp->setItem(key, data, ec);
285 setDOMException(exec, ec);
286 return JSValue::encode(jsUndefined());
289 EncodedJSValue JSC_HOST_CALL jsStoragePrototypeFunctionRemoveItem(ExecState* exec)
291 JSValue thisValue = exec->hostThisValue();
292 if (!thisValue.inherits(&JSStorage::s_info))
293 return throwVMTypeError(exec);
294 JSStorage* castedThis = static_cast<JSStorage*>(asObject(thisValue));
295 ASSERT_GC_OBJECT_INHERITS(castedThis, &JSStorage::s_info);
296 Storage* imp = static_cast<Storage*>(castedThis->impl());
297 if (exec->argumentCount() < 1)
298 return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
299 const String& key(ustringToString(MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined).isEmpty() ? UString() : MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined).toString(exec)));
300 if (exec->hadException())
301 return JSValue::encode(jsUndefined());
302 imp->removeItem(key);
303 return JSValue::encode(jsUndefined());
306 EncodedJSValue JSC_HOST_CALL jsStoragePrototypeFunctionClear(ExecState* exec)
308 JSValue thisValue = exec->hostThisValue();
309 if (!thisValue.inherits(&JSStorage::s_info))
310 return throwVMTypeError(exec);
311 JSStorage* castedThis = static_cast<JSStorage*>(asObject(thisValue));
312 ASSERT_GC_OBJECT_INHERITS(castedThis, &JSStorage::s_info);
313 Storage* imp = static_cast<Storage*>(castedThis->impl());
315 return JSValue::encode(jsUndefined());
318 static inline bool isObservable(JSStorage* jsStorage)
320 if (jsStorage->hasCustomProperties())
325 bool JSStorageOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
327 JSStorage* jsStorage = static_cast<JSStorage*>(handle.get().asCell());
328 if (!isObservable(jsStorage))
330 Frame* root = jsStorage->impl()->frame();
333 return visitor.containsOpaqueRoot(root);
336 void JSStorageOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
338 JSStorage* jsStorage = static_cast<JSStorage*>(handle.get().asCell());
339 DOMWrapperWorld* world = static_cast<DOMWrapperWorld*>(context);
340 uncacheWrapper(world, jsStorage->impl(), jsStorage);
341 jsStorage->releaseImpl();
344 JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, Storage* impl)
346 return wrap<JSStorage>(exec, globalObject, impl);
349 Storage* toStorage(JSC::JSValue value)
351 return value.inherits(&JSStorage::s_info) ? static_cast<JSStorage*>(asObject(value))->impl() : 0;