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