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 "JSMessagePort.h"
23
24#include "EventNames.h"
25#include "JSDOMAttribute.h"
26#include "JSDOMBinding.h"
27#include "JSDOMConstructorNotConstructable.h"
28#include "JSDOMConvertAny.h"
29#include "JSDOMConvertObject.h"
30#include "JSDOMConvertSequences.h"
31#include "JSDOMExceptionHandling.h"
32#include "JSDOMOperation.h"
33#include "JSDOMWrapperCache.h"
34#include "JSEventListener.h"
35#include "ScriptExecutionContext.h"
36#include <JavaScriptCore/HeapSnapshotBuilder.h>
37#include <JavaScriptCore/JSArray.h>
38#include <JavaScriptCore/JSCInlines.h>
39#include <wtf/GetPtr.h>
40#include <wtf/PointerPreparations.h>
41#include <wtf/URL.h>
42
43
44namespace WebCore {
45using namespace JSC;
46
47// Functions
48
49JSC::EncodedJSValue JSC_HOST_CALL jsMessagePortPrototypeFunctionPostMessage(JSC::ExecState*);
50JSC::EncodedJSValue JSC_HOST_CALL jsMessagePortPrototypeFunctionStart(JSC::ExecState*);
51JSC::EncodedJSValue JSC_HOST_CALL jsMessagePortPrototypeFunctionClose(JSC::ExecState*);
52
53// Attributes
54
55JSC::EncodedJSValue jsMessagePortConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
56bool setJSMessagePortConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
57JSC::EncodedJSValue jsMessagePortOnmessage(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
58bool setJSMessagePortOnmessage(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
59
60class JSMessagePortPrototype : public JSC::JSNonFinalObject {
61public:
62 using Base = JSC::JSNonFinalObject;
63 static JSMessagePortPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
64 {
65 JSMessagePortPrototype* ptr = new (NotNull, JSC::allocateCell<JSMessagePortPrototype>(vm.heap)) JSMessagePortPrototype(vm, globalObject, structure);
66 ptr->finishCreation(vm);
67 return ptr;
68 }
69
70 DECLARE_INFO;
71 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
72 {
73 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
74 }
75
76private:
77 JSMessagePortPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
78 : JSC::JSNonFinalObject(vm, structure)
79 {
80 }
81
82 void finishCreation(JSC::VM&);
83};
84
85using JSMessagePortConstructor = JSDOMConstructorNotConstructable<JSMessagePort>;
86
87template<> JSValue JSMessagePortConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
88{
89 return JSEventTarget::getConstructor(vm, &globalObject);
90}
91
92template<> void JSMessagePortConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
93{
94 putDirect(vm, vm.propertyNames->prototype, JSMessagePort::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
95 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("MessagePort"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
96 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
97}
98
99template<> const ClassInfo JSMessagePortConstructor::s_info = { "MessagePort", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMessagePortConstructor) };
100
101/* Hash table for prototype */
102
103static const HashTableValue JSMessagePortPrototypeTableValues[] =
104{
105 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMessagePortConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSMessagePortConstructor) } },
106 { "onmessage", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMessagePortOnmessage), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSMessagePortOnmessage) } },
107 { "postMessage", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMessagePortPrototypeFunctionPostMessage), (intptr_t) (1) } },
108 { "start", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMessagePortPrototypeFunctionStart), (intptr_t) (0) } },
109 { "close", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMessagePortPrototypeFunctionClose), (intptr_t) (0) } },
110};
111
112const ClassInfo JSMessagePortPrototype::s_info = { "MessagePortPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMessagePortPrototype) };
113
114void JSMessagePortPrototype::finishCreation(VM& vm)
115{
116 Base::finishCreation(vm);
117 reifyStaticProperties(vm, JSMessagePort::info(), JSMessagePortPrototypeTableValues, *this);
118}
119
120const ClassInfo JSMessagePort::s_info = { "MessagePort", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMessagePort) };
121
122JSMessagePort::JSMessagePort(Structure* structure, JSDOMGlobalObject& globalObject, Ref<MessagePort>&& impl)
123 : JSEventTarget(structure, globalObject, WTFMove(impl))
124{
125}
126
127void JSMessagePort::finishCreation(VM& vm)
128{
129 Base::finishCreation(vm);
130 ASSERT(inherits(vm, info()));
131
132}
133
134JSObject* JSMessagePort::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
135{
136 return JSMessagePortPrototype::create(vm, &globalObject, JSMessagePortPrototype::createStructure(vm, &globalObject, JSEventTarget::prototype(vm, globalObject)));
137}
138
139JSObject* JSMessagePort::prototype(VM& vm, JSDOMGlobalObject& globalObject)
140{
141 return getDOMPrototype<JSMessagePort>(vm, globalObject);
142}
143
144JSValue JSMessagePort::getConstructor(VM& vm, const JSGlobalObject* globalObject)
145{
146 return getDOMConstructor<JSMessagePortConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
147}
148
149template<> inline JSMessagePort* IDLAttribute<JSMessagePort>::cast(ExecState& state, EncodedJSValue thisValue)
150{
151 return jsDynamicCast<JSMessagePort*>(state.vm(), JSValue::decode(thisValue));
152}
153
154template<> inline JSMessagePort* IDLOperation<JSMessagePort>::cast(ExecState& state)
155{
156 return jsDynamicCast<JSMessagePort*>(state.vm(), state.thisValue());
157}
158
159EncodedJSValue jsMessagePortConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
160{
161 VM& vm = state->vm();
162 auto throwScope = DECLARE_THROW_SCOPE(vm);
163 auto* prototype = jsDynamicCast<JSMessagePortPrototype*>(vm, JSValue::decode(thisValue));
164 if (UNLIKELY(!prototype))
165 return throwVMTypeError(state, throwScope);
166 return JSValue::encode(JSMessagePort::getConstructor(state->vm(), prototype->globalObject()));
167}
168
169bool setJSMessagePortConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
170{
171 VM& vm = state->vm();
172 auto throwScope = DECLARE_THROW_SCOPE(vm);
173 auto* prototype = jsDynamicCast<JSMessagePortPrototype*>(vm, JSValue::decode(thisValue));
174 if (UNLIKELY(!prototype)) {
175 throwVMTypeError(state, throwScope);
176 return false;
177 }
178 // Shadowing a built-in constructor
179 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
180}
181
182static inline JSValue jsMessagePortOnmessageGetter(ExecState& state, JSMessagePort& thisObject, ThrowScope& throwScope)
183{
184 UNUSED_PARAM(throwScope);
185 UNUSED_PARAM(state);
186 return eventHandlerAttribute(thisObject.wrapped(), eventNames().messageEvent, worldForDOMObject(thisObject));
187}
188
189EncodedJSValue jsMessagePortOnmessage(ExecState* state, EncodedJSValue thisValue, PropertyName)
190{
191 return IDLAttribute<JSMessagePort>::get<jsMessagePortOnmessageGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onmessage");
192}
193
194static inline bool setJSMessagePortOnmessageSetter(ExecState& state, JSMessagePort& thisObject, JSValue value, ThrowScope& throwScope)
195{
196 UNUSED_PARAM(throwScope);
197 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().messageEvent, value);
198 return true;
199}
200
201bool setJSMessagePortOnmessage(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
202{
203 return IDLAttribute<JSMessagePort>::set<setJSMessagePortOnmessageSetter>(*state, thisValue, encodedValue, "onmessage");
204}
205
206static inline JSC::EncodedJSValue jsMessagePortPrototypeFunctionPostMessageBody(JSC::ExecState* state, typename IDLOperation<JSMessagePort>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
207{
208 UNUSED_PARAM(state);
209 UNUSED_PARAM(throwScope);
210 auto& impl = castedThis->wrapped();
211 if (UNLIKELY(state->argumentCount() < 1))
212 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
213 auto message = convert<IDLAny>(*state, state->uncheckedArgument(0));
214 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
215 auto transfer = state->argument(1).isUndefined() ? Converter<IDLSequence<IDLObject>>::ReturnType{ } : convert<IDLSequence<IDLObject>>(*state, state->uncheckedArgument(1));
216 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
217 propagateException(*state, throwScope, impl.postMessage(*state, WTFMove(message), WTFMove(transfer)));
218 return JSValue::encode(jsUndefined());
219}
220
221EncodedJSValue JSC_HOST_CALL jsMessagePortPrototypeFunctionPostMessage(ExecState* state)
222{
223 return IDLOperation<JSMessagePort>::call<jsMessagePortPrototypeFunctionPostMessageBody>(*state, "postMessage");
224}
225
226static inline JSC::EncodedJSValue jsMessagePortPrototypeFunctionStartBody(JSC::ExecState* state, typename IDLOperation<JSMessagePort>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
227{
228 UNUSED_PARAM(state);
229 UNUSED_PARAM(throwScope);
230 auto& impl = castedThis->wrapped();
231 impl.start();
232 return JSValue::encode(jsUndefined());
233}
234
235EncodedJSValue JSC_HOST_CALL jsMessagePortPrototypeFunctionStart(ExecState* state)
236{
237 return IDLOperation<JSMessagePort>::call<jsMessagePortPrototypeFunctionStartBody>(*state, "start");
238}
239
240static inline JSC::EncodedJSValue jsMessagePortPrototypeFunctionCloseBody(JSC::ExecState* state, typename IDLOperation<JSMessagePort>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
241{
242 UNUSED_PARAM(state);
243 UNUSED_PARAM(throwScope);
244 auto& impl = castedThis->wrapped();
245 impl.close();
246 return JSValue::encode(jsUndefined());
247}
248
249EncodedJSValue JSC_HOST_CALL jsMessagePortPrototypeFunctionClose(ExecState* state)
250{
251 return IDLOperation<JSMessagePort>::call<jsMessagePortPrototypeFunctionCloseBody>(*state, "close");
252}
253
254void JSMessagePort::visitChildren(JSCell* cell, SlotVisitor& visitor)
255{
256 auto* thisObject = jsCast<JSMessagePort*>(cell);
257 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
258 Base::visitChildren(thisObject, visitor);
259 thisObject->visitAdditionalChildren(visitor);
260}
261
262void JSMessagePort::visitOutputConstraints(JSCell* cell, SlotVisitor& visitor)
263{
264 auto* thisObject = jsCast<JSMessagePort*>(cell);
265 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
266 Base::visitOutputConstraints(thisObject, visitor);
267 thisObject->visitAdditionalChildren(visitor);
268}
269
270void JSMessagePort::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
271{
272 auto* thisObject = jsCast<JSMessagePort*>(cell);
273 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
274 if (thisObject->scriptExecutionContext())
275 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
276 Base::heapSnapshot(cell, builder);
277}
278
279bool JSMessagePortOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
280{
281 auto* jsMessagePort = jsCast<JSMessagePort*>(handle.slot()->asCell());
282 if (jsMessagePort->wrapped().hasPendingActivity()) {
283 if (UNLIKELY(reason))
284 *reason = "ActiveDOMObject with pending activity";
285 return true;
286 }
287 if (jsMessagePort->wrapped().isFiringEventListeners()) {
288 if (UNLIKELY(reason))
289 *reason = "EventTarget firing event listeners";
290 return true;
291 }
292 MessagePort* root = &jsMessagePort->wrapped();
293 if (UNLIKELY(reason))
294 *reason = "Reachable from MessagePort";
295 return visitor.containsOpaqueRoot(root);
296}
297
298void JSMessagePortOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
299{
300 auto* jsMessagePort = static_cast<JSMessagePort*>(handle.slot()->asCell());
301 auto& world = *static_cast<DOMWrapperWorld*>(context);
302 uncacheWrapper(world, &jsMessagePort->wrapped(), jsMessagePort);
303}
304
305#if ENABLE(BINDING_INTEGRITY)
306#if PLATFORM(WIN)
307#pragma warning(disable: 4483)
308extern "C" { extern void (*const __identifier("??_7MessagePort@WebCore@@6B@")[])(); }
309#else
310extern "C" { extern void* _ZTVN7WebCore11MessagePortE[]; }
311#endif
312#endif
313
314JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<MessagePort>&& impl)
315{
316
317#if ENABLE(BINDING_INTEGRITY)
318 void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
319#if PLATFORM(WIN)
320 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7MessagePort@WebCore@@6B@"));
321#else
322 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore11MessagePortE[2]);
323#endif
324
325 // If this fails MessagePort does not have a vtable, so you need to add the
326 // ImplementationLacksVTable attribute to the interface definition
327 static_assert(std::is_polymorphic<MessagePort>::value, "MessagePort is not polymorphic");
328
329 // If you hit this assertion you either have a use after free bug, or
330 // MessagePort has subclasses. If MessagePort has subclasses that get passed
331 // to toJS() we currently require MessagePort you to opt out of binding hardening
332 // by adding the SkipVTableValidation attribute to the interface IDL definition
333 RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
334#endif
335 return createWrapper<MessagePort>(globalObject, WTFMove(impl));
336}
337
338JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, MessagePort& impl)
339{
340 return wrap(state, globalObject, impl);
341}
342
343MessagePort* JSMessagePort::toWrapped(JSC::VM& vm, JSC::JSValue value)
344{
345 if (auto* wrapper = jsDynamicCast<JSMessagePort*>(vm, value))
346 return &wrapper->wrapped();
347 return nullptr;
348}
349
350}
351