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 "JSBlob.h"
23
24#include "JSBlob.h"
25#include "JSBlobPropertyBag.h"
26#include "JSDOMAttribute.h"
27#include "JSDOMBinding.h"
28#include "JSDOMConstructor.h"
29#include "JSDOMConvertBufferSource.h"
30#include "JSDOMConvertDictionary.h"
31#include "JSDOMConvertInterface.h"
32#include "JSDOMConvertNullable.h"
33#include "JSDOMConvertNumbers.h"
34#include "JSDOMConvertSequences.h"
35#include "JSDOMConvertStrings.h"
36#include "JSDOMConvertUnion.h"
37#include "JSDOMExceptionHandling.h"
38#include "JSDOMGlobalObject.h"
39#include "JSDOMOperation.h"
40#include "JSDOMWrapperCache.h"
41#include "ScriptExecutionContext.h"
42#include <JavaScriptCore/FunctionPrototype.h>
43#include <JavaScriptCore/HeapSnapshotBuilder.h>
44#include <JavaScriptCore/JSArray.h>
45#include <JavaScriptCore/JSCInlines.h>
46#include <wtf/GetPtr.h>
47#include <wtf/PointerPreparations.h>
48#include <wtf/URL.h>
49#include <wtf/Variant.h>
50
51
52namespace WebCore {
53using namespace JSC;
54
55// Functions
56
57JSC::EncodedJSValue JSC_HOST_CALL jsBlobPrototypeFunctionSlice(JSC::ExecState*);
58
59// Attributes
60
61JSC::EncodedJSValue jsBlobConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
62bool setJSBlobConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
63JSC::EncodedJSValue jsBlobSize(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
64JSC::EncodedJSValue jsBlobType(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
65
66class JSBlobPrototype : public JSC::JSNonFinalObject {
67public:
68 using Base = JSC::JSNonFinalObject;
69 static JSBlobPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
70 {
71 JSBlobPrototype* ptr = new (NotNull, JSC::allocateCell<JSBlobPrototype>(vm.heap)) JSBlobPrototype(vm, globalObject, structure);
72 ptr->finishCreation(vm);
73 return ptr;
74 }
75
76 DECLARE_INFO;
77 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
78 {
79 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
80 }
81
82private:
83 JSBlobPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
84 : JSC::JSNonFinalObject(vm, structure)
85 {
86 }
87
88 void finishCreation(JSC::VM&);
89};
90
91using JSBlobConstructor = JSDOMConstructor<JSBlob>;
92
93template<> EncodedJSValue JSC_HOST_CALL JSBlobConstructor::construct(ExecState* state)
94{
95 VM& vm = state->vm();
96 auto throwScope = DECLARE_THROW_SCOPE(vm);
97 UNUSED_PARAM(throwScope);
98 auto* castedThis = jsCast<JSBlobConstructor*>(state->jsCallee());
99 ASSERT(castedThis);
100 auto blobParts = state->argument(0).isUndefined() ? Converter<IDLSequence<IDLUnion<IDLArrayBufferView, IDLArrayBuffer, IDLInterface<Blob>, IDLUSVString>>>::ReturnType{ } : convert<IDLSequence<IDLUnion<IDLArrayBufferView, IDLArrayBuffer, IDLInterface<Blob>, IDLUSVString>>>(*state, state->uncheckedArgument(0));
101 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
102 auto options = convert<IDLDictionary<BlobPropertyBag>>(*state, state->argument(1));
103 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
104 auto object = Blob::create(WTFMove(blobParts), WTFMove(options));
105 return JSValue::encode(toJSNewlyCreated<IDLInterface<Blob>>(*state, *castedThis->globalObject(), WTFMove(object)));
106}
107
108template<> JSValue JSBlobConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
109{
110 UNUSED_PARAM(vm);
111 return globalObject.functionPrototype();
112}
113
114template<> void JSBlobConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
115{
116 putDirect(vm, vm.propertyNames->prototype, JSBlob::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
117 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("Blob"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
118 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
119}
120
121template<> const ClassInfo JSBlobConstructor::s_info = { "Blob", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSBlobConstructor) };
122
123/* Hash table for prototype */
124
125static const HashTableValue JSBlobPrototypeTableValues[] =
126{
127 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsBlobConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSBlobConstructor) } },
128 { "size", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsBlobSize), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
129 { "type", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsBlobType), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
130 { "slice", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsBlobPrototypeFunctionSlice), (intptr_t) (0) } },
131};
132
133const ClassInfo JSBlobPrototype::s_info = { "BlobPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSBlobPrototype) };
134
135void JSBlobPrototype::finishCreation(VM& vm)
136{
137 Base::finishCreation(vm);
138 reifyStaticProperties(vm, JSBlob::info(), JSBlobPrototypeTableValues, *this);
139}
140
141const ClassInfo JSBlob::s_info = { "Blob", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSBlob) };
142
143JSBlob::JSBlob(Structure* structure, JSDOMGlobalObject& globalObject, Ref<Blob>&& impl)
144 : JSDOMWrapper<Blob>(structure, globalObject, WTFMove(impl))
145{
146}
147
148void JSBlob::finishCreation(VM& vm)
149{
150 Base::finishCreation(vm);
151 ASSERT(inherits(vm, info()));
152
153}
154
155JSObject* JSBlob::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
156{
157 return JSBlobPrototype::create(vm, &globalObject, JSBlobPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
158}
159
160JSObject* JSBlob::prototype(VM& vm, JSDOMGlobalObject& globalObject)
161{
162 return getDOMPrototype<JSBlob>(vm, globalObject);
163}
164
165JSValue JSBlob::getConstructor(VM& vm, const JSGlobalObject* globalObject)
166{
167 return getDOMConstructor<JSBlobConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
168}
169
170void JSBlob::destroy(JSC::JSCell* cell)
171{
172 JSBlob* thisObject = static_cast<JSBlob*>(cell);
173 thisObject->JSBlob::~JSBlob();
174}
175
176template<> inline JSBlob* IDLAttribute<JSBlob>::cast(ExecState& state, EncodedJSValue thisValue)
177{
178 return jsDynamicCast<JSBlob*>(state.vm(), JSValue::decode(thisValue));
179}
180
181template<> inline JSBlob* IDLOperation<JSBlob>::cast(ExecState& state)
182{
183 return jsDynamicCast<JSBlob*>(state.vm(), state.thisValue());
184}
185
186EncodedJSValue jsBlobConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
187{
188 VM& vm = state->vm();
189 auto throwScope = DECLARE_THROW_SCOPE(vm);
190 auto* prototype = jsDynamicCast<JSBlobPrototype*>(vm, JSValue::decode(thisValue));
191 if (UNLIKELY(!prototype))
192 return throwVMTypeError(state, throwScope);
193 return JSValue::encode(JSBlob::getConstructor(state->vm(), prototype->globalObject()));
194}
195
196bool setJSBlobConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
197{
198 VM& vm = state->vm();
199 auto throwScope = DECLARE_THROW_SCOPE(vm);
200 auto* prototype = jsDynamicCast<JSBlobPrototype*>(vm, JSValue::decode(thisValue));
201 if (UNLIKELY(!prototype)) {
202 throwVMTypeError(state, throwScope);
203 return false;
204 }
205 // Shadowing a built-in constructor
206 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
207}
208
209static inline JSValue jsBlobSizeGetter(ExecState& state, JSBlob& thisObject, ThrowScope& throwScope)
210{
211 UNUSED_PARAM(throwScope);
212 UNUSED_PARAM(state);
213 auto& impl = thisObject.wrapped();
214 JSValue result = toJS<IDLUnsignedLongLong>(state, throwScope, impl.size());
215 return result;
216}
217
218EncodedJSValue jsBlobSize(ExecState* state, EncodedJSValue thisValue, PropertyName)
219{
220 return IDLAttribute<JSBlob>::get<jsBlobSizeGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "size");
221}
222
223static inline JSValue jsBlobTypeGetter(ExecState& state, JSBlob& thisObject, ThrowScope& throwScope)
224{
225 UNUSED_PARAM(throwScope);
226 UNUSED_PARAM(state);
227 auto& impl = thisObject.wrapped();
228 JSValue result = toJS<IDLDOMString>(state, throwScope, impl.type());
229 return result;
230}
231
232EncodedJSValue jsBlobType(ExecState* state, EncodedJSValue thisValue, PropertyName)
233{
234 return IDLAttribute<JSBlob>::get<jsBlobTypeGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "type");
235}
236
237static inline JSC::EncodedJSValue jsBlobPrototypeFunctionSliceBody(JSC::ExecState* state, typename IDLOperation<JSBlob>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
238{
239 UNUSED_PARAM(state);
240 UNUSED_PARAM(throwScope);
241 auto& impl = castedThis->wrapped();
242 auto start = convert<IDLLongLong>(*state, state->argument(0));
243 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
244 auto end = state->argument(1).isUndefined() ? 0x7FFFFFFFFFFFFFFF : convert<IDLLongLong>(*state, state->uncheckedArgument(1));
245 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
246 auto contentType = state->argument(2).isUndefined() ? String() : convert<IDLNullable<IDLDOMString>>(*state, state->uncheckedArgument(2));
247 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
248 return JSValue::encode(toJS<IDLInterface<Blob>>(*state, *castedThis->globalObject(), impl.slice(WTFMove(start), WTFMove(end), WTFMove(contentType))));
249}
250
251EncodedJSValue JSC_HOST_CALL jsBlobPrototypeFunctionSlice(ExecState* state)
252{
253 return IDLOperation<JSBlob>::call<jsBlobPrototypeFunctionSliceBody>(*state, "slice");
254}
255
256void JSBlob::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
257{
258 auto* thisObject = jsCast<JSBlob*>(cell);
259 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
260 if (thisObject->scriptExecutionContext())
261 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
262 Base::heapSnapshot(cell, builder);
263}
264
265bool JSBlobOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
266{
267 auto* jsBlob = jsCast<JSBlob*>(handle.slot()->asCell());
268 Blob* root = &jsBlob->wrapped();
269 if (UNLIKELY(reason))
270 *reason = "Reachable from Blob";
271 return visitor.containsOpaqueRoot(root);
272}
273
274void JSBlobOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
275{
276 auto* jsBlob = static_cast<JSBlob*>(handle.slot()->asCell());
277 auto& world = *static_cast<DOMWrapperWorld*>(context);
278 uncacheWrapper(world, &jsBlob->wrapped(), jsBlob);
279}
280
281Blob* JSBlob::toWrapped(JSC::VM& vm, JSC::JSValue value)
282{
283 if (auto* wrapper = jsDynamicCast<JSBlob*>(vm, value))
284 return &wrapper->wrapped();
285 return nullptr;
286}
287
288}
289