WebCore/generated/JSStorage.cpp
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     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 
       
    23 #if ENABLE(DOM_STORAGE)
       
    24 
       
    25 #include "JSStorage.h"
       
    26 
       
    27 #include "AtomicString.h"
       
    28 #include "JSStorageCustom.h"
       
    29 #include "KURL.h"
       
    30 #include "Storage.h"
       
    31 #include <runtime/Error.h>
       
    32 #include <runtime/JSNumberCell.h>
       
    33 #include <wtf/GetPtr.h>
       
    34 
       
    35 using namespace JSC;
       
    36 
       
    37 namespace WebCore {
       
    38 
       
    39 ASSERT_CLASS_FITS_IN_CELL(JSStorage);
       
    40 
       
    41 /* Hash table */
       
    42 #if ENABLE(JIT)
       
    43 #define THUNK_GENERATOR(generator) , generator
       
    44 #else
       
    45 #define THUNK_GENERATOR(generator)
       
    46 #endif
       
    47 
       
    48 static const HashTableValue JSStorageTableValues[3] =
       
    49 {
       
    50     { "length", DontDelete | DontEnum | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsStorageLength), (intptr_t)0 THUNK_GENERATOR(0) },
       
    51     { "constructor", DontEnum | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsStorageConstructor), (intptr_t)0 THUNK_GENERATOR(0) },
       
    52     { 0, 0, 0, 0 THUNK_GENERATOR(0) }
       
    53 };
       
    54 
       
    55 #undef THUNK_GENERATOR
       
    56 static JSC_CONST_HASHTABLE HashTable JSStorageTable = { 5, 3, JSStorageTableValues, 0 };
       
    57 /* Hash table for constructor */
       
    58 #if ENABLE(JIT)
       
    59 #define THUNK_GENERATOR(generator) , generator
       
    60 #else
       
    61 #define THUNK_GENERATOR(generator)
       
    62 #endif
       
    63 
       
    64 static const HashTableValue JSStorageConstructorTableValues[1] =
       
    65 {
       
    66     { 0, 0, 0, 0 THUNK_GENERATOR(0) }
       
    67 };
       
    68 
       
    69 #undef THUNK_GENERATOR
       
    70 static JSC_CONST_HASHTABLE HashTable JSStorageConstructorTable = { 1, 0, JSStorageConstructorTableValues, 0 };
       
    71 class JSStorageConstructor : public DOMConstructorObject {
       
    72 public:
       
    73     JSStorageConstructor(JSC::ExecState*, JSDOMGlobalObject*);
       
    74 
       
    75     virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier&, JSC::PropertySlot&);
       
    76     virtual bool getOwnPropertyDescriptor(JSC::ExecState*, const JSC::Identifier&, JSC::PropertyDescriptor&);
       
    77     virtual const JSC::ClassInfo* classInfo() const { return &s_info; }
       
    78     static const JSC::ClassInfo s_info;
       
    79     static PassRefPtr<JSC::Structure> createStructure(JSC::JSValue prototype)
       
    80     {
       
    81         return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), AnonymousSlotCount);
       
    82     }
       
    83 protected:
       
    84     static const unsigned StructureFlags = JSC::OverridesGetOwnPropertySlot | JSC::ImplementsHasInstance | DOMConstructorObject::StructureFlags;
       
    85 };
       
    86 
       
    87 const ClassInfo JSStorageConstructor::s_info = { "StorageConstructor", 0, &JSStorageConstructorTable, 0 };
       
    88 
       
    89 JSStorageConstructor::JSStorageConstructor(ExecState* exec, JSDOMGlobalObject* globalObject)
       
    90     : DOMConstructorObject(JSStorageConstructor::createStructure(globalObject->objectPrototype()), globalObject)
       
    91 {
       
    92     putDirect(exec->propertyNames().prototype, JSStoragePrototype::self(exec, globalObject), DontDelete | ReadOnly);
       
    93 }
       
    94 
       
    95 bool JSStorageConstructor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
       
    96 {
       
    97     return getStaticValueSlot<JSStorageConstructor, DOMObject>(exec, &JSStorageConstructorTable, this, propertyName, slot);
       
    98 }
       
    99 
       
   100 bool JSStorageConstructor::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
       
   101 {
       
   102     return getStaticValueDescriptor<JSStorageConstructor, DOMObject>(exec, &JSStorageConstructorTable, this, propertyName, descriptor);
       
   103 }
       
   104 
       
   105 /* Hash table for prototype */
       
   106 #if ENABLE(JIT)
       
   107 #define THUNK_GENERATOR(generator) , generator
       
   108 #else
       
   109 #define THUNK_GENERATOR(generator)
       
   110 #endif
       
   111 
       
   112 static const HashTableValue JSStoragePrototypeTableValues[6] =
       
   113 {
       
   114     { "key", DontDelete | DontEnum | Function, (intptr_t)static_cast<NativeFunction>(jsStoragePrototypeFunctionKey), (intptr_t)1 THUNK_GENERATOR(0) },
       
   115     { "getItem", DontDelete | DontEnum | Function, (intptr_t)static_cast<NativeFunction>(jsStoragePrototypeFunctionGetItem), (intptr_t)1 THUNK_GENERATOR(0) },
       
   116     { "setItem", DontDelete | DontEnum | Function, (intptr_t)static_cast<NativeFunction>(jsStoragePrototypeFunctionSetItem), (intptr_t)2 THUNK_GENERATOR(0) },
       
   117     { "removeItem", DontDelete | DontEnum | Function, (intptr_t)static_cast<NativeFunction>(jsStoragePrototypeFunctionRemoveItem), (intptr_t)1 THUNK_GENERATOR(0) },
       
   118     { "clear", DontDelete | DontEnum | Function, (intptr_t)static_cast<NativeFunction>(jsStoragePrototypeFunctionClear), (intptr_t)0 THUNK_GENERATOR(0) },
       
   119     { 0, 0, 0, 0 THUNK_GENERATOR(0) }
       
   120 };
       
   121 
       
   122 #undef THUNK_GENERATOR
       
   123 static JSC_CONST_HASHTABLE HashTable JSStoragePrototypeTable = { 17, 15, JSStoragePrototypeTableValues, 0 };
       
   124 const ClassInfo JSStoragePrototype::s_info = { "StoragePrototype", 0, &JSStoragePrototypeTable, 0 };
       
   125 
       
   126 JSObject* JSStoragePrototype::self(ExecState* exec, JSGlobalObject* globalObject)
       
   127 {
       
   128     return getDOMPrototype<JSStorage>(exec, globalObject);
       
   129 }
       
   130 
       
   131 bool JSStoragePrototype::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
       
   132 {
       
   133     return getStaticFunctionSlot<JSObject>(exec, &JSStoragePrototypeTable, this, propertyName, slot);
       
   134 }
       
   135 
       
   136 bool JSStoragePrototype::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
       
   137 {
       
   138     return getStaticFunctionDescriptor<JSObject>(exec, &JSStoragePrototypeTable, this, propertyName, descriptor);
       
   139 }
       
   140 
       
   141 const ClassInfo JSStorage::s_info = { "Storage", 0, &JSStorageTable, 0 };
       
   142 
       
   143 JSStorage::JSStorage(NonNullPassRefPtr<Structure> structure, JSDOMGlobalObject* globalObject, PassRefPtr<Storage> impl)
       
   144     : DOMObjectWithGlobalPointer(structure, globalObject)
       
   145     , m_impl(impl)
       
   146 {
       
   147 }
       
   148 
       
   149 JSStorage::~JSStorage()
       
   150 {
       
   151     forgetDOMObject(this, impl());
       
   152 }
       
   153 
       
   154 JSObject* JSStorage::createPrototype(ExecState* exec, JSGlobalObject* globalObject)
       
   155 {
       
   156     return new (exec) JSStoragePrototype(globalObject, JSStoragePrototype::createStructure(globalObject->objectPrototype()));
       
   157 }
       
   158 
       
   159 bool JSStorage::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
       
   160 {
       
   161     const HashEntry* entry = JSStorageTable.entry(exec, propertyName);
       
   162     if (entry) {
       
   163         slot.setCustom(this, entry->propertyGetter());
       
   164         return true;
       
   165     }
       
   166     if (canGetItemsForName(exec, static_cast<Storage*>(impl()), propertyName)) {
       
   167         slot.setCustom(this, nameGetter);
       
   168         return true;
       
   169     }
       
   170     return getStaticValueSlot<JSStorage, Base>(exec, &JSStorageTable, this, propertyName, slot);
       
   171 }
       
   172 
       
   173 bool JSStorage::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
       
   174 {
       
   175     const HashEntry* entry = JSStorageTable.entry(exec, propertyName);
       
   176     if (entry) {
       
   177         PropertySlot slot;
       
   178         slot.setCustom(this, entry->propertyGetter());
       
   179         descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes());
       
   180         return true;
       
   181     }
       
   182     if (canGetItemsForName(exec, static_cast<Storage*>(impl()), propertyName)) {
       
   183         PropertySlot slot;
       
   184         slot.setCustom(this, nameGetter);
       
   185         descriptor.setDescriptor(slot.getValue(exec, propertyName), ReadOnly | DontDelete | DontEnum);
       
   186         return true;
       
   187     }
       
   188     return getStaticValueDescriptor<JSStorage, Base>(exec, &JSStorageTable, this, propertyName, descriptor);
       
   189 }
       
   190 
       
   191 JSValue jsStorageLength(ExecState* exec, JSValue slotBase, const Identifier&)
       
   192 {
       
   193     JSStorage* castedThis = static_cast<JSStorage*>(asObject(slotBase));
       
   194     UNUSED_PARAM(exec);
       
   195     Storage* imp = static_cast<Storage*>(castedThis->impl());
       
   196     JSValue result = jsNumber(exec, imp->length());
       
   197     return result;
       
   198 }
       
   199 
       
   200 JSValue jsStorageConstructor(ExecState* exec, JSValue slotBase, const Identifier&)
       
   201 {
       
   202     JSStorage* domObject = static_cast<JSStorage*>(asObject(slotBase));
       
   203     return JSStorage::getConstructor(exec, domObject->globalObject());
       
   204 }
       
   205 void JSStorage::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
       
   206 {
       
   207     if (putDelegate(exec, propertyName, value, slot))
       
   208         return;
       
   209     Base::put(exec, propertyName, value, slot);
       
   210 }
       
   211 
       
   212 JSValue JSStorage::getConstructor(ExecState* exec, JSGlobalObject* globalObject)
       
   213 {
       
   214     return getDOMConstructor<JSStorageConstructor>(exec, static_cast<JSDOMGlobalObject*>(globalObject));
       
   215 }
       
   216 
       
   217 EncodedJSValue JSC_HOST_CALL jsStoragePrototypeFunctionKey(ExecState* exec)
       
   218 {
       
   219     JSValue thisValue = exec->hostThisValue();
       
   220     if (!thisValue.inherits(&JSStorage::s_info))
       
   221         return throwVMTypeError(exec);
       
   222     JSStorage* castedThis = static_cast<JSStorage*>(asObject(thisValue));
       
   223     Storage* imp = static_cast<Storage*>(castedThis->impl());
       
   224     unsigned index = exec->argument(0).toInt32(exec);
       
   225 
       
   226 
       
   227     JSC::JSValue result = jsStringOrNull(exec, imp->key(index));
       
   228     return JSValue::encode(result);
       
   229 }
       
   230 
       
   231 EncodedJSValue JSC_HOST_CALL jsStoragePrototypeFunctionGetItem(ExecState* exec)
       
   232 {
       
   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     Storage* imp = static_cast<Storage*>(castedThis->impl());
       
   238     const String& key = ustringToString(exec->argument(0).toString(exec));
       
   239 
       
   240 
       
   241     JSC::JSValue result = jsStringOrNull(exec, imp->getItem(key));
       
   242     return JSValue::encode(result);
       
   243 }
       
   244 
       
   245 EncodedJSValue JSC_HOST_CALL jsStoragePrototypeFunctionSetItem(ExecState* exec)
       
   246 {
       
   247     JSValue thisValue = exec->hostThisValue();
       
   248     if (!thisValue.inherits(&JSStorage::s_info))
       
   249         return throwVMTypeError(exec);
       
   250     JSStorage* castedThis = static_cast<JSStorage*>(asObject(thisValue));
       
   251     Storage* imp = static_cast<Storage*>(castedThis->impl());
       
   252     ExceptionCode ec = 0;
       
   253     const String& key = ustringToString(exec->argument(0).toString(exec));
       
   254     const String& data = ustringToString(exec->argument(1).toString(exec));
       
   255 
       
   256     imp->setItem(key, data, ec);
       
   257     setDOMException(exec, ec);
       
   258     return JSValue::encode(jsUndefined());
       
   259 }
       
   260 
       
   261 EncodedJSValue JSC_HOST_CALL jsStoragePrototypeFunctionRemoveItem(ExecState* exec)
       
   262 {
       
   263     JSValue thisValue = exec->hostThisValue();
       
   264     if (!thisValue.inherits(&JSStorage::s_info))
       
   265         return throwVMTypeError(exec);
       
   266     JSStorage* castedThis = static_cast<JSStorage*>(asObject(thisValue));
       
   267     Storage* imp = static_cast<Storage*>(castedThis->impl());
       
   268     const String& key = ustringToString(exec->argument(0).toString(exec));
       
   269 
       
   270     imp->removeItem(key);
       
   271     return JSValue::encode(jsUndefined());
       
   272 }
       
   273 
       
   274 EncodedJSValue JSC_HOST_CALL jsStoragePrototypeFunctionClear(ExecState* exec)
       
   275 {
       
   276     JSValue thisValue = exec->hostThisValue();
       
   277     if (!thisValue.inherits(&JSStorage::s_info))
       
   278         return throwVMTypeError(exec);
       
   279     JSStorage* castedThis = static_cast<JSStorage*>(asObject(thisValue));
       
   280     Storage* imp = static_cast<Storage*>(castedThis->impl());
       
   281 
       
   282     imp->clear();
       
   283     return JSValue::encode(jsUndefined());
       
   284 }
       
   285 
       
   286 JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, Storage* object)
       
   287 {
       
   288     return getDOMObjectWrapper<JSStorage>(exec, globalObject, object);
       
   289 }
       
   290 Storage* toStorage(JSC::JSValue value)
       
   291 {
       
   292     return value.inherits(&JSStorage::s_info) ? static_cast<JSStorage*>(asObject(value))->impl() : 0;
       
   293 }
       
   294 
       
   295 }
       
   296 
       
   297 #endif // ENABLE(DOM_STORAGE)