|
| 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 "JSArrayBuffer.h" |
| 23 | + |
| 24 | +#include "ExceptionCode.h" |
| 25 | +#include "JSArrayBuffer.h" |
| 26 | +#include "JSDOMBinding.h" |
| 27 | +#include <runtime/Error.h> |
| 28 | +#include <wtf/ArrayBuffer.h> |
| 29 | +#include <wtf/GetPtr.h> |
| 30 | + |
| 31 | +using namespace JSC; |
| 32 | + |
| 33 | +namespace WebCore { |
| 34 | + |
| 35 | +ASSERT_CLASS_FITS_IN_CELL(JSArrayBuffer); |
| 36 | +/* Hash table */ |
| 37 | + |
| 38 | +static const HashTableValue JSArrayBufferTableValues[] = |
| 39 | +{ |
| 40 | + { "byteLength", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsArrayBufferByteLength), (intptr_t)0, NoIntrinsic }, |
| 41 | + { "constructor", DontEnum | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsArrayBufferConstructor), (intptr_t)0, NoIntrinsic }, |
| 42 | + { 0, 0, 0, 0, NoIntrinsic } |
| 43 | +}; |
| 44 | + |
| 45 | +static const HashTable JSArrayBufferTable = { 5, 3, JSArrayBufferTableValues, 0 }; |
| 46 | +/* Hash table for constructor */ |
| 47 | + |
| 48 | +static const HashTableValue JSArrayBufferConstructorTableValues[] = |
| 49 | +{ |
| 50 | + { 0, 0, 0, 0, NoIntrinsic } |
| 51 | +}; |
| 52 | + |
| 53 | +static const HashTable JSArrayBufferConstructorTable = { 1, 0, JSArrayBufferConstructorTableValues, 0 }; |
| 54 | +const ClassInfo JSArrayBufferConstructor::s_info = { "ArrayBufferConstructor", &Base::s_info, &JSArrayBufferConstructorTable, 0, CREATE_METHOD_TABLE(JSArrayBufferConstructor) }; |
| 55 | + |
| 56 | +JSArrayBufferConstructor::JSArrayBufferConstructor(Structure* structure, JSDOMGlobalObject* globalObject) |
| 57 | + : DOMConstructorObject(structure, globalObject) |
| 58 | +{ |
| 59 | +} |
| 60 | + |
| 61 | +void JSArrayBufferConstructor::finishCreation(ExecState* exec, JSDOMGlobalObject* globalObject) |
| 62 | +{ |
| 63 | + Base::finishCreation(exec->globalData()); |
| 64 | + ASSERT(inherits(&s_info)); |
| 65 | + putDirect(exec->globalData(), exec->propertyNames().prototype, JSArrayBufferPrototype::self(exec, globalObject), DontDelete | ReadOnly); |
| 66 | + putDirect(exec->globalData(), exec->propertyNames().length, jsNumber(1), ReadOnly | DontDelete | DontEnum); |
| 67 | +} |
| 68 | + |
| 69 | +bool JSArrayBufferConstructor::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot) |
| 70 | +{ |
| 71 | + return getStaticValueSlot<JSArrayBufferConstructor, JSDOMWrapper>(exec, &JSArrayBufferConstructorTable, jsCast<JSArrayBufferConstructor*>(cell), propertyName, slot); |
| 72 | +} |
| 73 | + |
| 74 | +bool JSArrayBufferConstructor::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) |
| 75 | +{ |
| 76 | + return getStaticValueDescriptor<JSArrayBufferConstructor, JSDOMWrapper>(exec, &JSArrayBufferConstructorTable, jsCast<JSArrayBufferConstructor*>(object), propertyName, descriptor); |
| 77 | +} |
| 78 | + |
| 79 | +ConstructType JSArrayBufferConstructor::getConstructData(JSCell*, ConstructData& constructData) |
| 80 | +{ |
| 81 | + constructData.native.function = constructJSArrayBuffer; |
| 82 | + return ConstructTypeHost; |
| 83 | +} |
| 84 | + |
| 85 | +/* Hash table for prototype */ |
| 86 | + |
| 87 | +static const HashTableValue JSArrayBufferPrototypeTableValues[] = |
| 88 | +{ |
| 89 | + { "slice", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsArrayBufferPrototypeFunctionSlice), (intptr_t)2, NoIntrinsic }, |
| 90 | + { 0, 0, 0, 0, NoIntrinsic } |
| 91 | +}; |
| 92 | + |
| 93 | +static const HashTable JSArrayBufferPrototypeTable = { 2, 1, JSArrayBufferPrototypeTableValues, 0 }; |
| 94 | +static const HashTable* getJSArrayBufferPrototypeTable(ExecState* exec) |
| 95 | +{ |
| 96 | + return getHashTableForGlobalData(exec->globalData(), &JSArrayBufferPrototypeTable); |
| 97 | +} |
| 98 | + |
| 99 | +const ClassInfo JSArrayBufferPrototype::s_info = { "ArrayBufferPrototype", &Base::s_info, 0, getJSArrayBufferPrototypeTable, CREATE_METHOD_TABLE(JSArrayBufferPrototype) }; |
| 100 | + |
| 101 | +JSObject* JSArrayBufferPrototype::self(ExecState* exec, JSGlobalObject* globalObject) |
| 102 | +{ |
| 103 | + return getDOMPrototype<JSArrayBuffer>(exec, globalObject); |
| 104 | +} |
| 105 | + |
| 106 | +bool JSArrayBufferPrototype::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot) |
| 107 | +{ |
| 108 | + JSArrayBufferPrototype* thisObject = jsCast<JSArrayBufferPrototype*>(cell); |
| 109 | + return getStaticFunctionSlot<JSObject>(exec, getJSArrayBufferPrototypeTable(exec), thisObject, propertyName, slot); |
| 110 | +} |
| 111 | + |
| 112 | +bool JSArrayBufferPrototype::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) |
| 113 | +{ |
| 114 | + JSArrayBufferPrototype* thisObject = jsCast<JSArrayBufferPrototype*>(object); |
| 115 | + return getStaticFunctionDescriptor<JSObject>(exec, getJSArrayBufferPrototypeTable(exec), thisObject, propertyName, descriptor); |
| 116 | +} |
| 117 | + |
| 118 | +static const HashTable* getJSArrayBufferTable(ExecState* exec) |
| 119 | +{ |
| 120 | + return getHashTableForGlobalData(exec->globalData(), &JSArrayBufferTable); |
| 121 | +} |
| 122 | + |
| 123 | +const ClassInfo JSArrayBuffer::s_info = { "ArrayBuffer", &Base::s_info, 0, getJSArrayBufferTable , CREATE_METHOD_TABLE(JSArrayBuffer) }; |
| 124 | + |
| 125 | +JSArrayBuffer::JSArrayBuffer(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<ArrayBuffer> impl) |
| 126 | + : JSDOMWrapper(structure, globalObject) |
| 127 | + , m_impl(impl.leakRef()) |
| 128 | +{ |
| 129 | +} |
| 130 | + |
| 131 | +void JSArrayBuffer::finishCreation(JSGlobalData& globalData) |
| 132 | +{ |
| 133 | + Base::finishCreation(globalData); |
| 134 | + ASSERT(inherits(&s_info)); |
| 135 | +} |
| 136 | + |
| 137 | +JSObject* JSArrayBuffer::createPrototype(ExecState* exec, JSGlobalObject* globalObject) |
| 138 | +{ |
| 139 | + return JSArrayBufferPrototype::create(exec->globalData(), globalObject, JSArrayBufferPrototype::createStructure(globalObject->globalData(), globalObject, globalObject->objectPrototype())); |
| 140 | +} |
| 141 | + |
| 142 | +void JSArrayBuffer::destroy(JSC::JSCell* cell) |
| 143 | +{ |
| 144 | + JSArrayBuffer* thisObject = jsCast<JSArrayBuffer*>(cell); |
| 145 | + thisObject->JSArrayBuffer::~JSArrayBuffer(); |
| 146 | +} |
| 147 | + |
| 148 | +JSArrayBuffer::~JSArrayBuffer() |
| 149 | +{ |
| 150 | + releaseImplIfNotNull(); |
| 151 | +} |
| 152 | + |
| 153 | +bool JSArrayBuffer::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot) |
| 154 | +{ |
| 155 | + JSArrayBuffer* thisObject = jsCast<JSArrayBuffer*>(cell); |
| 156 | + ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info); |
| 157 | + return getStaticValueSlot<JSArrayBuffer, Base>(exec, getJSArrayBufferTable(exec), thisObject, propertyName, slot); |
| 158 | +} |
| 159 | + |
| 160 | +bool JSArrayBuffer::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) |
| 161 | +{ |
| 162 | + JSArrayBuffer* thisObject = jsCast<JSArrayBuffer*>(object); |
| 163 | + ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info); |
| 164 | + return getStaticValueDescriptor<JSArrayBuffer, Base>(exec, getJSArrayBufferTable(exec), thisObject, propertyName, descriptor); |
| 165 | +} |
| 166 | + |
| 167 | +JSValue jsArrayBufferByteLength(ExecState* exec, JSValue slotBase, const Identifier&) |
| 168 | +{ |
| 169 | + JSArrayBuffer* castedThis = jsCast<JSArrayBuffer*>(asObject(slotBase)); |
| 170 | + UNUSED_PARAM(exec); |
| 171 | + ArrayBuffer* impl = static_cast<ArrayBuffer*>(castedThis->impl()); |
| 172 | + JSValue result = jsNumber(impl->byteLength()); |
| 173 | + return result; |
| 174 | +} |
| 175 | + |
| 176 | + |
| 177 | +JSValue jsArrayBufferConstructor(ExecState* exec, JSValue slotBase, const Identifier&) |
| 178 | +{ |
| 179 | + JSArrayBuffer* domObject = jsCast<JSArrayBuffer*>(asObject(slotBase)); |
| 180 | + return JSArrayBuffer::getConstructor(exec, domObject->globalObject()); |
| 181 | +} |
| 182 | + |
| 183 | +JSValue JSArrayBuffer::getConstructor(ExecState* exec, JSGlobalObject* globalObject) |
| 184 | +{ |
| 185 | + return getDOMConstructor<JSArrayBufferConstructor>(exec, jsCast<JSDOMGlobalObject*>(globalObject)); |
| 186 | +} |
| 187 | + |
| 188 | +EncodedJSValue JSC_HOST_CALL jsArrayBufferPrototypeFunctionSlice(ExecState* exec) |
| 189 | +{ |
| 190 | + JSValue thisValue = exec->hostThisValue(); |
| 191 | + if (!thisValue.inherits(&JSArrayBuffer::s_info)) |
| 192 | + return throwVMTypeError(exec); |
| 193 | + JSArrayBuffer* castedThis = jsCast<JSArrayBuffer*>(asObject(thisValue)); |
| 194 | + ASSERT_GC_OBJECT_INHERITS(castedThis, &JSArrayBuffer::s_info); |
| 195 | + ArrayBuffer* impl = static_cast<ArrayBuffer*>(castedThis->impl()); |
| 196 | + if (exec->argumentCount() < 1) |
| 197 | + return throwVMError(exec, createNotEnoughArgumentsError(exec)); |
| 198 | + int begin(MAYBE_MISSING_PARAMETER(exec, 0, DefaultIsUndefined).toInt32(exec)); |
| 199 | + if (exec->hadException()) |
| 200 | + return JSValue::encode(jsUndefined()); |
| 201 | + |
| 202 | + size_t argsCount = exec->argumentCount(); |
| 203 | + if (argsCount <= 1) { |
| 204 | + |
| 205 | + JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl->slice(begin))); |
| 206 | + return JSValue::encode(result); |
| 207 | + } |
| 208 | + |
| 209 | + int end(MAYBE_MISSING_PARAMETER(exec, 1, DefaultIsUndefined).toInt32(exec)); |
| 210 | + if (exec->hadException()) |
| 211 | + return JSValue::encode(jsUndefined()); |
| 212 | + |
| 213 | + JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl->slice(begin, end))); |
| 214 | + return JSValue::encode(result); |
| 215 | +} |
| 216 | + |
| 217 | +static inline bool isObservable(JSArrayBuffer* jsArrayBuffer) |
| 218 | +{ |
| 219 | + if (jsArrayBuffer->hasCustomProperties()) |
| 220 | + return true; |
| 221 | + return false; |
| 222 | +} |
| 223 | + |
| 224 | +bool JSArrayBufferOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor) |
| 225 | +{ |
| 226 | + JSArrayBuffer* jsArrayBuffer = jsCast<JSArrayBuffer*>(handle.get().asCell()); |
| 227 | + if (!isObservable(jsArrayBuffer)) |
| 228 | + return false; |
| 229 | + ArrayBuffer* root = jsArrayBuffer->impl(); |
| 230 | + return visitor.containsOpaqueRoot(root); |
| 231 | +} |
| 232 | + |
| 233 | +void JSArrayBufferOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
| 234 | +{ |
| 235 | + JSArrayBuffer* jsArrayBuffer = jsCast<JSArrayBuffer*>(handle.get().asCell()); |
| 236 | + DOMWrapperWorld* world = static_cast<DOMWrapperWorld*>(context); |
| 237 | + uncacheWrapper(world, jsArrayBuffer->impl(), jsArrayBuffer); |
| 238 | + jsArrayBuffer->releaseImpl(); |
| 239 | +} |
| 240 | + |
| 241 | +JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, ArrayBuffer* impl) |
| 242 | +{ |
| 243 | + return wrap<JSArrayBuffer>(exec, globalObject, impl); |
| 244 | +} |
| 245 | + |
| 246 | +ArrayBuffer* toArrayBuffer(JSC::JSValue value) |
| 247 | +{ |
| 248 | + return value.inherits(&JSArrayBuffer::s_info) ? jsCast<JSArrayBuffer*>(asObject(value))->impl() : 0; |
| 249 | +} |
| 250 | + |
| 251 | +} |
0 commit comments