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 "JSTextEncoder.h"
23
24#include "JSDOMAttribute.h"
25#include "JSDOMBinding.h"
26#include "JSDOMConstructor.h"
27#include "JSDOMConvertBufferSource.h"
28#include "JSDOMConvertInterface.h"
29#include "JSDOMConvertStrings.h"
30#include "JSDOMExceptionHandling.h"
31#include "JSDOMGlobalObject.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
43namespace WebCore {
44using namespace JSC;
45
46// Functions
47
48JSC::EncodedJSValue JSC_HOST_CALL jsTextEncoderPrototypeFunctionEncode(JSC::ExecState*);
49
50// Attributes
51
52JSC::EncodedJSValue jsTextEncoderConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
53bool setJSTextEncoderConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
54JSC::EncodedJSValue jsTextEncoderEncoding(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
55
56class JSTextEncoderPrototype : public JSC::JSNonFinalObject {
57public:
58 using Base = JSC::JSNonFinalObject;
59 static JSTextEncoderPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
60 {
61 JSTextEncoderPrototype* ptr = new (NotNull, JSC::allocateCell<JSTextEncoderPrototype>(vm.heap)) JSTextEncoderPrototype(vm, globalObject, structure);
62 ptr->finishCreation(vm);
63 return ptr;
64 }
65
66 DECLARE_INFO;
67 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
68 {
69 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
70 }
71
72private:
73 JSTextEncoderPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
74 : JSC::JSNonFinalObject(vm, structure)
75 {
76 }
77
78 void finishCreation(JSC::VM&);
79};
80
81using JSTextEncoderConstructor = JSDOMConstructor<JSTextEncoder>;
82
83template<> EncodedJSValue JSC_HOST_CALL JSTextEncoderConstructor::construct(ExecState* state)
84{
85 VM& vm = state->vm();
86 auto throwScope = DECLARE_THROW_SCOPE(vm);
87 UNUSED_PARAM(throwScope);
88 auto* castedThis = jsCast<JSTextEncoderConstructor*>(state->jsCallee());
89 ASSERT(castedThis);
90 auto object = TextEncoder::create();
91 return JSValue::encode(toJSNewlyCreated<IDLInterface<TextEncoder>>(*state, *castedThis->globalObject(), WTFMove(object)));
92}
93
94template<> JSValue JSTextEncoderConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
95{
96 UNUSED_PARAM(vm);
97 return globalObject.functionPrototype();
98}
99
100template<> void JSTextEncoderConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
101{
102 putDirect(vm, vm.propertyNames->prototype, JSTextEncoder::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
103 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("TextEncoder"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
104 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
105}
106
107template<> const ClassInfo JSTextEncoderConstructor::s_info = { "TextEncoder", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTextEncoderConstructor) };
108
109/* Hash table for prototype */
110
111static const HashTableValue JSTextEncoderPrototypeTableValues[] =
112{
113 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTextEncoderConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTextEncoderConstructor) } },
114 { "encoding", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTextEncoderEncoding), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
115 { "encode", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsTextEncoderPrototypeFunctionEncode), (intptr_t) (0) } },
116};
117
118const ClassInfo JSTextEncoderPrototype::s_info = { "TextEncoderPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTextEncoderPrototype) };
119
120void JSTextEncoderPrototype::finishCreation(VM& vm)
121{
122 Base::finishCreation(vm);
123 reifyStaticProperties(vm, JSTextEncoder::info(), JSTextEncoderPrototypeTableValues, *this);
124}
125
126const ClassInfo JSTextEncoder::s_info = { "TextEncoder", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTextEncoder) };
127
128JSTextEncoder::JSTextEncoder(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TextEncoder>&& impl)
129 : JSDOMWrapper<TextEncoder>(structure, globalObject, WTFMove(impl))
130{
131}
132
133void JSTextEncoder::finishCreation(VM& vm)
134{
135 Base::finishCreation(vm);
136 ASSERT(inherits(vm, info()));
137
138}
139
140JSObject* JSTextEncoder::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
141{
142 return JSTextEncoderPrototype::create(vm, &globalObject, JSTextEncoderPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
143}
144
145JSObject* JSTextEncoder::prototype(VM& vm, JSDOMGlobalObject& globalObject)
146{
147 return getDOMPrototype<JSTextEncoder>(vm, globalObject);
148}
149
150JSValue JSTextEncoder::getConstructor(VM& vm, const JSGlobalObject* globalObject)
151{
152 return getDOMConstructor<JSTextEncoderConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
153}
154
155void JSTextEncoder::destroy(JSC::JSCell* cell)
156{
157 JSTextEncoder* thisObject = static_cast<JSTextEncoder*>(cell);
158 thisObject->JSTextEncoder::~JSTextEncoder();
159}
160
161template<> inline JSTextEncoder* IDLAttribute<JSTextEncoder>::cast(ExecState& state, EncodedJSValue thisValue)
162{
163 return jsDynamicCast<JSTextEncoder*>(state.vm(), JSValue::decode(thisValue));
164}
165
166template<> inline JSTextEncoder* IDLOperation<JSTextEncoder>::cast(ExecState& state)
167{
168 return jsDynamicCast<JSTextEncoder*>(state.vm(), state.thisValue());
169}
170
171EncodedJSValue jsTextEncoderConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
172{
173 VM& vm = state->vm();
174 auto throwScope = DECLARE_THROW_SCOPE(vm);
175 auto* prototype = jsDynamicCast<JSTextEncoderPrototype*>(vm, JSValue::decode(thisValue));
176 if (UNLIKELY(!prototype))
177 return throwVMTypeError(state, throwScope);
178 return JSValue::encode(JSTextEncoder::getConstructor(state->vm(), prototype->globalObject()));
179}
180
181bool setJSTextEncoderConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
182{
183 VM& vm = state->vm();
184 auto throwScope = DECLARE_THROW_SCOPE(vm);
185 auto* prototype = jsDynamicCast<JSTextEncoderPrototype*>(vm, JSValue::decode(thisValue));
186 if (UNLIKELY(!prototype)) {
187 throwVMTypeError(state, throwScope);
188 return false;
189 }
190 // Shadowing a built-in constructor
191 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
192}
193
194static inline JSValue jsTextEncoderEncodingGetter(ExecState& state, JSTextEncoder& thisObject, ThrowScope& throwScope)
195{
196 UNUSED_PARAM(throwScope);
197 UNUSED_PARAM(state);
198 auto& impl = thisObject.wrapped();
199 JSValue result = toJS<IDLDOMString>(state, throwScope, impl.encoding());
200 return result;
201}
202
203EncodedJSValue jsTextEncoderEncoding(ExecState* state, EncodedJSValue thisValue, PropertyName)
204{
205 return IDLAttribute<JSTextEncoder>::get<jsTextEncoderEncodingGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "encoding");
206}
207
208static inline JSC::EncodedJSValue jsTextEncoderPrototypeFunctionEncodeBody(JSC::ExecState* state, typename IDLOperation<JSTextEncoder>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
209{
210 UNUSED_PARAM(state);
211 UNUSED_PARAM(throwScope);
212 auto& impl = castedThis->wrapped();
213 auto input = state->argument(0).isUndefined() ? emptyString() : convert<IDLUSVString>(*state, state->uncheckedArgument(0));
214 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
215 return JSValue::encode(toJS<IDLUint8Array>(*state, *castedThis->globalObject(), impl.encode(WTFMove(input))));
216}
217
218EncodedJSValue JSC_HOST_CALL jsTextEncoderPrototypeFunctionEncode(ExecState* state)
219{
220 return IDLOperation<JSTextEncoder>::call<jsTextEncoderPrototypeFunctionEncodeBody>(*state, "encode");
221}
222
223void JSTextEncoder::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
224{
225 auto* thisObject = jsCast<JSTextEncoder*>(cell);
226 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
227 if (thisObject->scriptExecutionContext())
228 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
229 Base::heapSnapshot(cell, builder);
230}
231
232bool JSTextEncoderOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
233{
234 UNUSED_PARAM(handle);
235 UNUSED_PARAM(visitor);
236 UNUSED_PARAM(reason);
237 return false;
238}
239
240void JSTextEncoderOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
241{
242 auto* jsTextEncoder = static_cast<JSTextEncoder*>(handle.slot()->asCell());
243 auto& world = *static_cast<DOMWrapperWorld*>(context);
244 uncacheWrapper(world, &jsTextEncoder->wrapped(), jsTextEncoder);
245}
246
247JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TextEncoder>&& impl)
248{
249 // If you hit this failure the interface definition has the ImplementationLacksVTable
250 // attribute. You should remove that attribute. If the class has subclasses
251 // that may be passed through this toJS() function you should use the SkipVTableValidation
252 // attribute to TextEncoder.
253 static_assert(!std::is_polymorphic<TextEncoder>::value, "TextEncoder is polymorphic but the IDL claims it is not");
254 return createWrapper<TextEncoder>(globalObject, WTFMove(impl));
255}
256
257JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TextEncoder& impl)
258{
259 return wrap(state, globalObject, impl);
260}
261
262TextEncoder* JSTextEncoder::toWrapped(JSC::VM& vm, JSC::JSValue value)
263{
264 if (auto* wrapper = jsDynamicCast<JSTextEncoder*>(vm, value))
265 return &wrapper->wrapped();
266 return nullptr;
267}
268
269}
270