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(USER_MESSAGE_HANDLERS) |
24 | |
25 | #include "JSUserMessageHandler.h" |
26 | |
27 | #include "JSDOMBinding.h" |
28 | #include "JSDOMConstructorNotConstructable.h" |
29 | #include "JSDOMConvertSerializedScriptValue.h" |
30 | #include "JSDOMExceptionHandling.h" |
31 | #include "JSDOMOperation.h" |
32 | #include "JSDOMWrapperCache.h" |
33 | #include "ScriptExecutionContext.h" |
34 | #include "SerializedScriptValue.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 | |
43 | namespace WebCore { |
44 | using namespace JSC; |
45 | |
46 | // Functions |
47 | |
48 | JSC::EncodedJSValue JSC_HOST_CALL jsUserMessageHandlerPrototypeFunctionPostMessage(JSC::ExecState*); |
49 | |
50 | // Attributes |
51 | |
52 | JSC::EncodedJSValue jsUserMessageHandlerConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
53 | bool setJSUserMessageHandlerConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
54 | |
55 | class JSUserMessageHandlerPrototype : public JSC::JSNonFinalObject { |
56 | public: |
57 | using Base = JSC::JSNonFinalObject; |
58 | static JSUserMessageHandlerPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
59 | { |
60 | JSUserMessageHandlerPrototype* ptr = new (NotNull, JSC::allocateCell<JSUserMessageHandlerPrototype>(vm.heap)) JSUserMessageHandlerPrototype(vm, globalObject, structure); |
61 | ptr->finishCreation(vm); |
62 | return ptr; |
63 | } |
64 | |
65 | DECLARE_INFO; |
66 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
67 | { |
68 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
69 | } |
70 | |
71 | private: |
72 | JSUserMessageHandlerPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
73 | : JSC::JSNonFinalObject(vm, structure) |
74 | { |
75 | } |
76 | |
77 | void finishCreation(JSC::VM&); |
78 | }; |
79 | |
80 | using JSUserMessageHandlerConstructor = JSDOMConstructorNotConstructable<JSUserMessageHandler>; |
81 | |
82 | template<> JSValue JSUserMessageHandlerConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
83 | { |
84 | UNUSED_PARAM(vm); |
85 | return globalObject.functionPrototype(); |
86 | } |
87 | |
88 | template<> void JSUserMessageHandlerConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
89 | { |
90 | putDirect(vm, vm.propertyNames->prototype, JSUserMessageHandler::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
91 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("UserMessageHandler"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
92 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
93 | } |
94 | |
95 | template<> const ClassInfo JSUserMessageHandlerConstructor::s_info = { "UserMessageHandler" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSUserMessageHandlerConstructor) }; |
96 | |
97 | /* Hash table for prototype */ |
98 | |
99 | static const HashTableValue JSUserMessageHandlerPrototypeTableValues[] = |
100 | { |
101 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsUserMessageHandlerConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSUserMessageHandlerConstructor) } }, |
102 | { "postMessage" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsUserMessageHandlerPrototypeFunctionPostMessage), (intptr_t) (1) } }, |
103 | }; |
104 | |
105 | const ClassInfo JSUserMessageHandlerPrototype::s_info = { "UserMessageHandlerPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSUserMessageHandlerPrototype) }; |
106 | |
107 | void JSUserMessageHandlerPrototype::finishCreation(VM& vm) |
108 | { |
109 | Base::finishCreation(vm); |
110 | reifyStaticProperties(vm, JSUserMessageHandler::info(), JSUserMessageHandlerPrototypeTableValues, *this); |
111 | } |
112 | |
113 | const ClassInfo JSUserMessageHandler::s_info = { "UserMessageHandler" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSUserMessageHandler) }; |
114 | |
115 | JSUserMessageHandler::JSUserMessageHandler(Structure* structure, JSDOMGlobalObject& globalObject, Ref<UserMessageHandler>&& impl) |
116 | : JSDOMWrapper<UserMessageHandler>(structure, globalObject, WTFMove(impl)) |
117 | { |
118 | } |
119 | |
120 | void JSUserMessageHandler::finishCreation(VM& vm) |
121 | { |
122 | Base::finishCreation(vm); |
123 | ASSERT(inherits(vm, info())); |
124 | |
125 | } |
126 | |
127 | JSObject* JSUserMessageHandler::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
128 | { |
129 | return JSUserMessageHandlerPrototype::create(vm, &globalObject, JSUserMessageHandlerPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
130 | } |
131 | |
132 | JSObject* JSUserMessageHandler::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
133 | { |
134 | return getDOMPrototype<JSUserMessageHandler>(vm, globalObject); |
135 | } |
136 | |
137 | JSValue JSUserMessageHandler::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
138 | { |
139 | return getDOMConstructor<JSUserMessageHandlerConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
140 | } |
141 | |
142 | void JSUserMessageHandler::destroy(JSC::JSCell* cell) |
143 | { |
144 | JSUserMessageHandler* thisObject = static_cast<JSUserMessageHandler*>(cell); |
145 | thisObject->JSUserMessageHandler::~JSUserMessageHandler(); |
146 | } |
147 | |
148 | template<> inline JSUserMessageHandler* IDLOperation<JSUserMessageHandler>::cast(ExecState& state) |
149 | { |
150 | return jsDynamicCast<JSUserMessageHandler*>(state.vm(), state.thisValue()); |
151 | } |
152 | |
153 | EncodedJSValue jsUserMessageHandlerConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
154 | { |
155 | VM& vm = state->vm(); |
156 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
157 | auto* prototype = jsDynamicCast<JSUserMessageHandlerPrototype*>(vm, JSValue::decode(thisValue)); |
158 | if (UNLIKELY(!prototype)) |
159 | return throwVMTypeError(state, throwScope); |
160 | return JSValue::encode(JSUserMessageHandler::getConstructor(state->vm(), prototype->globalObject())); |
161 | } |
162 | |
163 | bool setJSUserMessageHandlerConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
164 | { |
165 | VM& vm = state->vm(); |
166 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
167 | auto* prototype = jsDynamicCast<JSUserMessageHandlerPrototype*>(vm, JSValue::decode(thisValue)); |
168 | if (UNLIKELY(!prototype)) { |
169 | throwVMTypeError(state, throwScope); |
170 | return false; |
171 | } |
172 | // Shadowing a built-in constructor |
173 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
174 | } |
175 | |
176 | static inline JSC::EncodedJSValue jsUserMessageHandlerPrototypeFunctionPostMessageBody(JSC::ExecState* state, typename IDLOperation<JSUserMessageHandler>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
177 | { |
178 | UNUSED_PARAM(state); |
179 | UNUSED_PARAM(throwScope); |
180 | auto& impl = castedThis->wrapped(); |
181 | if (UNLIKELY(state->argumentCount() < 1)) |
182 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
183 | auto message = convert<IDLSerializedScriptValue<SerializedScriptValue>>(*state, state->uncheckedArgument(0)); |
184 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
185 | propagateException(*state, throwScope, impl.postMessage(WTFMove(message))); |
186 | return JSValue::encode(jsUndefined()); |
187 | } |
188 | |
189 | EncodedJSValue JSC_HOST_CALL jsUserMessageHandlerPrototypeFunctionPostMessage(ExecState* state) |
190 | { |
191 | return IDLOperation<JSUserMessageHandler>::call<jsUserMessageHandlerPrototypeFunctionPostMessageBody>(*state, "postMessage" ); |
192 | } |
193 | |
194 | void JSUserMessageHandler::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
195 | { |
196 | auto* thisObject = jsCast<JSUserMessageHandler*>(cell); |
197 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
198 | if (thisObject->scriptExecutionContext()) |
199 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
200 | Base::heapSnapshot(cell, builder); |
201 | } |
202 | |
203 | bool JSUserMessageHandlerOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
204 | { |
205 | UNUSED_PARAM(handle); |
206 | UNUSED_PARAM(visitor); |
207 | UNUSED_PARAM(reason); |
208 | return false; |
209 | } |
210 | |
211 | void JSUserMessageHandlerOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
212 | { |
213 | auto* jsUserMessageHandler = static_cast<JSUserMessageHandler*>(handle.slot()->asCell()); |
214 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
215 | uncacheWrapper(world, &jsUserMessageHandler->wrapped(), jsUserMessageHandler); |
216 | } |
217 | |
218 | #if ENABLE(BINDING_INTEGRITY) |
219 | #if PLATFORM(WIN) |
220 | #pragma warning(disable: 4483) |
221 | extern "C" { extern void (*const __identifier("??_7UserMessageHandler@WebCore@@6B@" )[])(); } |
222 | #else |
223 | extern "C" { extern void* _ZTVN7WebCore18UserMessageHandlerE[]; } |
224 | #endif |
225 | #endif |
226 | |
227 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<UserMessageHandler>&& impl) |
228 | { |
229 | |
230 | #if ENABLE(BINDING_INTEGRITY) |
231 | void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr())); |
232 | #if PLATFORM(WIN) |
233 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7UserMessageHandler@WebCore@@6B@" )); |
234 | #else |
235 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore18UserMessageHandlerE[2]); |
236 | #endif |
237 | |
238 | // If this fails UserMessageHandler does not have a vtable, so you need to add the |
239 | // ImplementationLacksVTable attribute to the interface definition |
240 | static_assert(std::is_polymorphic<UserMessageHandler>::value, "UserMessageHandler is not polymorphic" ); |
241 | |
242 | // If you hit this assertion you either have a use after free bug, or |
243 | // UserMessageHandler has subclasses. If UserMessageHandler has subclasses that get passed |
244 | // to toJS() we currently require UserMessageHandler you to opt out of binding hardening |
245 | // by adding the SkipVTableValidation attribute to the interface IDL definition |
246 | RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer); |
247 | #endif |
248 | return createWrapper<UserMessageHandler>(globalObject, WTFMove(impl)); |
249 | } |
250 | |
251 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, UserMessageHandler& impl) |
252 | { |
253 | return wrap(state, globalObject, impl); |
254 | } |
255 | |
256 | UserMessageHandler* JSUserMessageHandler::toWrapped(JSC::VM& vm, JSC::JSValue value) |
257 | { |
258 | if (auto* wrapper = jsDynamicCast<JSUserMessageHandler*>(vm, value)) |
259 | return &wrapper->wrapped(); |
260 | return nullptr; |
261 | } |
262 | |
263 | } |
264 | |
265 | #endif // ENABLE(USER_MESSAGE_HANDLERS) |
266 | |