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 "JSFontFace.h" |
23 | |
24 | #include "DOMPromiseProxy.h" |
25 | #include "Document.h" |
26 | #include "JSDOMAttribute.h" |
27 | #include "JSDOMBinding.h" |
28 | #include "JSDOMConstructor.h" |
29 | #include "JSDOMConvertBufferSource.h" |
30 | #include "JSDOMConvertInterface.h" |
31 | #include "JSDOMConvertPromise.h" |
32 | #include "JSDOMConvertStrings.h" |
33 | #include "JSDOMConvertUnion.h" |
34 | #include "JSDOMExceptionHandling.h" |
35 | #include "JSDOMGlobalObject.h" |
36 | #include "JSDOMOperation.h" |
37 | #include "JSDOMOperationReturningPromise.h" |
38 | #include "JSDOMWrapperCache.h" |
39 | #include "JSFontFace.h" |
40 | #include "ScriptExecutionContext.h" |
41 | #include <JavaScriptCore/FunctionPrototype.h> |
42 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
43 | #include <JavaScriptCore/JSCInlines.h> |
44 | #include <JavaScriptCore/JSString.h> |
45 | #include <wtf/GetPtr.h> |
46 | #include <wtf/PointerPreparations.h> |
47 | #include <wtf/URL.h> |
48 | #include <wtf/Variant.h> |
49 | |
50 | |
51 | namespace WebCore { |
52 | using namespace JSC; |
53 | |
54 | String convertEnumerationToString(FontFace::LoadStatus enumerationValue) |
55 | { |
56 | static const NeverDestroyed<String> values[] = { |
57 | MAKE_STATIC_STRING_IMPL("unloaded" ), |
58 | MAKE_STATIC_STRING_IMPL("loading" ), |
59 | MAKE_STATIC_STRING_IMPL("loaded" ), |
60 | MAKE_STATIC_STRING_IMPL("error" ), |
61 | }; |
62 | static_assert(static_cast<size_t>(FontFace::LoadStatus::Unloaded) == 0, "FontFace::LoadStatus::Unloaded is not 0 as expected" ); |
63 | static_assert(static_cast<size_t>(FontFace::LoadStatus::Loading) == 1, "FontFace::LoadStatus::Loading is not 1 as expected" ); |
64 | static_assert(static_cast<size_t>(FontFace::LoadStatus::Loaded) == 2, "FontFace::LoadStatus::Loaded is not 2 as expected" ); |
65 | static_assert(static_cast<size_t>(FontFace::LoadStatus::Error) == 3, "FontFace::LoadStatus::Error is not 3 as expected" ); |
66 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
67 | return values[static_cast<size_t>(enumerationValue)]; |
68 | } |
69 | |
70 | template<> JSString* convertEnumerationToJS(ExecState& state, FontFace::LoadStatus enumerationValue) |
71 | { |
72 | return jsStringWithCache(&state, convertEnumerationToString(enumerationValue)); |
73 | } |
74 | |
75 | template<> Optional<FontFace::LoadStatus> parseEnumeration<FontFace::LoadStatus>(ExecState& state, JSValue value) |
76 | { |
77 | auto stringValue = value.toWTFString(&state); |
78 | if (stringValue == "unloaded" ) |
79 | return FontFace::LoadStatus::Unloaded; |
80 | if (stringValue == "loading" ) |
81 | return FontFace::LoadStatus::Loading; |
82 | if (stringValue == "loaded" ) |
83 | return FontFace::LoadStatus::Loaded; |
84 | if (stringValue == "error" ) |
85 | return FontFace::LoadStatus::Error; |
86 | return WTF::nullopt; |
87 | } |
88 | |
89 | template<> const char* expectedEnumerationValues<FontFace::LoadStatus>() |
90 | { |
91 | return "\"unloaded\", \"loading\", \"loaded\", \"error\"" ; |
92 | } |
93 | |
94 | template<> FontFace::Descriptors convertDictionary<FontFace::Descriptors>(ExecState& state, JSValue value) |
95 | { |
96 | VM& vm = state.vm(); |
97 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
98 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
99 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
100 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
101 | throwTypeError(&state, throwScope); |
102 | return { }; |
103 | } |
104 | FontFace::Descriptors result; |
105 | JSValue displayValue; |
106 | if (isNullOrUndefined) |
107 | displayValue = jsUndefined(); |
108 | else { |
109 | displayValue = object->get(&state, Identifier::fromString(&state, "display" )); |
110 | RETURN_IF_EXCEPTION(throwScope, { }); |
111 | } |
112 | if (!displayValue.isUndefined()) { |
113 | result.display = convert<IDLDOMString>(state, displayValue); |
114 | RETURN_IF_EXCEPTION(throwScope, { }); |
115 | } else |
116 | result.display = "auto"_s ; |
117 | JSValue featureSettingsValue; |
118 | if (isNullOrUndefined) |
119 | featureSettingsValue = jsUndefined(); |
120 | else { |
121 | featureSettingsValue = object->get(&state, Identifier::fromString(&state, "featureSettings" )); |
122 | RETURN_IF_EXCEPTION(throwScope, { }); |
123 | } |
124 | if (!featureSettingsValue.isUndefined()) { |
125 | result.featureSettings = convert<IDLDOMString>(state, featureSettingsValue); |
126 | RETURN_IF_EXCEPTION(throwScope, { }); |
127 | } else |
128 | result.featureSettings = "normal"_s ; |
129 | JSValue stretchValue; |
130 | if (isNullOrUndefined) |
131 | stretchValue = jsUndefined(); |
132 | else { |
133 | stretchValue = object->get(&state, Identifier::fromString(&state, "stretch" )); |
134 | RETURN_IF_EXCEPTION(throwScope, { }); |
135 | } |
136 | if (!stretchValue.isUndefined()) { |
137 | result.stretch = convert<IDLDOMString>(state, stretchValue); |
138 | RETURN_IF_EXCEPTION(throwScope, { }); |
139 | } else |
140 | result.stretch = "normal"_s ; |
141 | JSValue styleValue; |
142 | if (isNullOrUndefined) |
143 | styleValue = jsUndefined(); |
144 | else { |
145 | styleValue = object->get(&state, Identifier::fromString(&state, "style" )); |
146 | RETURN_IF_EXCEPTION(throwScope, { }); |
147 | } |
148 | if (!styleValue.isUndefined()) { |
149 | result.style = convert<IDLDOMString>(state, styleValue); |
150 | RETURN_IF_EXCEPTION(throwScope, { }); |
151 | } else |
152 | result.style = "normal"_s ; |
153 | JSValue unicodeRangeValue; |
154 | if (isNullOrUndefined) |
155 | unicodeRangeValue = jsUndefined(); |
156 | else { |
157 | unicodeRangeValue = object->get(&state, Identifier::fromString(&state, "unicodeRange" )); |
158 | RETURN_IF_EXCEPTION(throwScope, { }); |
159 | } |
160 | if (!unicodeRangeValue.isUndefined()) { |
161 | result.unicodeRange = convert<IDLDOMString>(state, unicodeRangeValue); |
162 | RETURN_IF_EXCEPTION(throwScope, { }); |
163 | } else |
164 | result.unicodeRange = "U+0-10FFFF"_s ; |
165 | JSValue variantValue; |
166 | if (isNullOrUndefined) |
167 | variantValue = jsUndefined(); |
168 | else { |
169 | variantValue = object->get(&state, Identifier::fromString(&state, "variant" )); |
170 | RETURN_IF_EXCEPTION(throwScope, { }); |
171 | } |
172 | if (!variantValue.isUndefined()) { |
173 | result.variant = convert<IDLDOMString>(state, variantValue); |
174 | RETURN_IF_EXCEPTION(throwScope, { }); |
175 | } else |
176 | result.variant = "normal"_s ; |
177 | JSValue weightValue; |
178 | if (isNullOrUndefined) |
179 | weightValue = jsUndefined(); |
180 | else { |
181 | weightValue = object->get(&state, Identifier::fromString(&state, "weight" )); |
182 | RETURN_IF_EXCEPTION(throwScope, { }); |
183 | } |
184 | if (!weightValue.isUndefined()) { |
185 | result.weight = convert<IDLDOMString>(state, weightValue); |
186 | RETURN_IF_EXCEPTION(throwScope, { }); |
187 | } else |
188 | result.weight = "normal"_s ; |
189 | return result; |
190 | } |
191 | |
192 | // Functions |
193 | |
194 | JSC::EncodedJSValue JSC_HOST_CALL jsFontFacePrototypeFunctionLoad(JSC::ExecState*); |
195 | |
196 | // Attributes |
197 | |
198 | JSC::EncodedJSValue jsFontFaceConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
199 | bool setJSFontFaceConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
200 | JSC::EncodedJSValue jsFontFaceFamily(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
201 | bool setJSFontFaceFamily(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
202 | JSC::EncodedJSValue jsFontFaceStyle(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
203 | bool setJSFontFaceStyle(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
204 | JSC::EncodedJSValue jsFontFaceWeight(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
205 | bool setJSFontFaceWeight(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
206 | JSC::EncodedJSValue jsFontFaceStretch(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
207 | bool setJSFontFaceStretch(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
208 | JSC::EncodedJSValue jsFontFaceUnicodeRange(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
209 | bool setJSFontFaceUnicodeRange(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
210 | JSC::EncodedJSValue jsFontFaceVariant(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
211 | bool setJSFontFaceVariant(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
212 | JSC::EncodedJSValue jsFontFaceFeatureSettings(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
213 | bool setJSFontFaceFeatureSettings(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
214 | JSC::EncodedJSValue jsFontFaceDisplay(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
215 | bool setJSFontFaceDisplay(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
216 | JSC::EncodedJSValue jsFontFaceStatus(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
217 | JSC::EncodedJSValue jsFontFaceLoaded(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
218 | |
219 | class JSFontFacePrototype : public JSC::JSNonFinalObject { |
220 | public: |
221 | using Base = JSC::JSNonFinalObject; |
222 | static JSFontFacePrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
223 | { |
224 | JSFontFacePrototype* ptr = new (NotNull, JSC::allocateCell<JSFontFacePrototype>(vm.heap)) JSFontFacePrototype(vm, globalObject, structure); |
225 | ptr->finishCreation(vm); |
226 | return ptr; |
227 | } |
228 | |
229 | DECLARE_INFO; |
230 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
231 | { |
232 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
233 | } |
234 | |
235 | private: |
236 | JSFontFacePrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
237 | : JSC::JSNonFinalObject(vm, structure) |
238 | { |
239 | } |
240 | |
241 | void finishCreation(JSC::VM&); |
242 | }; |
243 | |
244 | using JSFontFaceConstructor = JSDOMConstructor<JSFontFace>; |
245 | |
246 | template<> EncodedJSValue JSC_HOST_CALL JSFontFaceConstructor::construct(ExecState* state) |
247 | { |
248 | VM& vm = state->vm(); |
249 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
250 | UNUSED_PARAM(throwScope); |
251 | auto* castedThis = jsCast<JSFontFaceConstructor*>(state->jsCallee()); |
252 | ASSERT(castedThis); |
253 | if (UNLIKELY(state->argumentCount() < 2)) |
254 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
255 | auto* context = castedThis->scriptExecutionContext(); |
256 | if (UNLIKELY(!context)) |
257 | return throwConstructorScriptExecutionContextUnavailableError(*state, throwScope, "FontFace" ); |
258 | ASSERT(context->isDocument()); |
259 | auto& document = downcast<Document>(*context); |
260 | auto family = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
261 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
262 | auto source = convert<IDLUnion<IDLDOMString, IDLArrayBuffer, IDLArrayBufferView>>(*state, state->uncheckedArgument(1)); |
263 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
264 | auto descriptors = convert<IDLDictionary<FontFace::Descriptors>>(*state, state->argument(2)); |
265 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
266 | auto object = FontFace::create(document, WTFMove(family), WTFMove(source), WTFMove(descriptors)); |
267 | return JSValue::encode(toJSNewlyCreated<IDLInterface<FontFace>>(*state, *castedThis->globalObject(), throwScope, WTFMove(object))); |
268 | } |
269 | |
270 | template<> JSValue JSFontFaceConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
271 | { |
272 | UNUSED_PARAM(vm); |
273 | return globalObject.functionPrototype(); |
274 | } |
275 | |
276 | template<> void JSFontFaceConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
277 | { |
278 | putDirect(vm, vm.propertyNames->prototype, JSFontFace::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
279 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("FontFace"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
280 | putDirect(vm, vm.propertyNames->length, jsNumber(2), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
281 | } |
282 | |
283 | template<> const ClassInfo JSFontFaceConstructor::s_info = { "FontFace" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSFontFaceConstructor) }; |
284 | |
285 | /* Hash table for prototype */ |
286 | |
287 | static const HashTableValue JSFontFacePrototypeTableValues[] = |
288 | { |
289 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFontFaceConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSFontFaceConstructor) } }, |
290 | { "family" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFontFaceFamily), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSFontFaceFamily) } }, |
291 | { "style" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFontFaceStyle), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSFontFaceStyle) } }, |
292 | { "weight" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFontFaceWeight), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSFontFaceWeight) } }, |
293 | { "stretch" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFontFaceStretch), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSFontFaceStretch) } }, |
294 | { "unicodeRange" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFontFaceUnicodeRange), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSFontFaceUnicodeRange) } }, |
295 | { "variant" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFontFaceVariant), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSFontFaceVariant) } }, |
296 | { "featureSettings" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFontFaceFeatureSettings), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSFontFaceFeatureSettings) } }, |
297 | { "display" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFontFaceDisplay), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSFontFaceDisplay) } }, |
298 | { "status" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFontFaceStatus), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
299 | { "loaded" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFontFaceLoaded), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
300 | { "load" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsFontFacePrototypeFunctionLoad), (intptr_t) (0) } }, |
301 | }; |
302 | |
303 | const ClassInfo JSFontFacePrototype::s_info = { "FontFacePrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSFontFacePrototype) }; |
304 | |
305 | void JSFontFacePrototype::finishCreation(VM& vm) |
306 | { |
307 | Base::finishCreation(vm); |
308 | reifyStaticProperties(vm, JSFontFace::info(), JSFontFacePrototypeTableValues, *this); |
309 | } |
310 | |
311 | const ClassInfo JSFontFace::s_info = { "FontFace" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSFontFace) }; |
312 | |
313 | JSFontFace::JSFontFace(Structure* structure, JSDOMGlobalObject& globalObject, Ref<FontFace>&& impl) |
314 | : JSDOMWrapper<FontFace>(structure, globalObject, WTFMove(impl)) |
315 | { |
316 | } |
317 | |
318 | void JSFontFace::finishCreation(VM& vm) |
319 | { |
320 | Base::finishCreation(vm); |
321 | ASSERT(inherits(vm, info())); |
322 | |
323 | } |
324 | |
325 | JSObject* JSFontFace::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
326 | { |
327 | return JSFontFacePrototype::create(vm, &globalObject, JSFontFacePrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
328 | } |
329 | |
330 | JSObject* JSFontFace::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
331 | { |
332 | return getDOMPrototype<JSFontFace>(vm, globalObject); |
333 | } |
334 | |
335 | JSValue JSFontFace::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
336 | { |
337 | return getDOMConstructor<JSFontFaceConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
338 | } |
339 | |
340 | void JSFontFace::destroy(JSC::JSCell* cell) |
341 | { |
342 | JSFontFace* thisObject = static_cast<JSFontFace*>(cell); |
343 | thisObject->JSFontFace::~JSFontFace(); |
344 | } |
345 | |
346 | template<> inline JSFontFace* IDLAttribute<JSFontFace>::cast(ExecState& state, EncodedJSValue thisValue) |
347 | { |
348 | return jsDynamicCast<JSFontFace*>(state.vm(), JSValue::decode(thisValue)); |
349 | } |
350 | |
351 | template<> inline JSFontFace* IDLOperation<JSFontFace>::cast(ExecState& state) |
352 | { |
353 | return jsDynamicCast<JSFontFace*>(state.vm(), state.thisValue()); |
354 | } |
355 | |
356 | EncodedJSValue jsFontFaceConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
357 | { |
358 | VM& vm = state->vm(); |
359 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
360 | auto* prototype = jsDynamicCast<JSFontFacePrototype*>(vm, JSValue::decode(thisValue)); |
361 | if (UNLIKELY(!prototype)) |
362 | return throwVMTypeError(state, throwScope); |
363 | return JSValue::encode(JSFontFace::getConstructor(state->vm(), prototype->globalObject())); |
364 | } |
365 | |
366 | bool setJSFontFaceConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
367 | { |
368 | VM& vm = state->vm(); |
369 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
370 | auto* prototype = jsDynamicCast<JSFontFacePrototype*>(vm, JSValue::decode(thisValue)); |
371 | if (UNLIKELY(!prototype)) { |
372 | throwVMTypeError(state, throwScope); |
373 | return false; |
374 | } |
375 | // Shadowing a built-in constructor |
376 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
377 | } |
378 | |
379 | static inline JSValue jsFontFaceFamilyGetter(ExecState& state, JSFontFace& thisObject, ThrowScope& throwScope) |
380 | { |
381 | UNUSED_PARAM(throwScope); |
382 | UNUSED_PARAM(state); |
383 | auto& impl = thisObject.wrapped(); |
384 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.family()); |
385 | return result; |
386 | } |
387 | |
388 | EncodedJSValue jsFontFaceFamily(ExecState* state, EncodedJSValue thisValue, PropertyName) |
389 | { |
390 | return IDLAttribute<JSFontFace>::get<jsFontFaceFamilyGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "family" ); |
391 | } |
392 | |
393 | static inline bool setJSFontFaceFamilySetter(ExecState& state, JSFontFace& thisObject, JSValue value, ThrowScope& throwScope) |
394 | { |
395 | UNUSED_PARAM(throwScope); |
396 | auto& impl = thisObject.wrapped(); |
397 | auto nativeValue = convert<IDLDOMString>(state, value); |
398 | RETURN_IF_EXCEPTION(throwScope, false); |
399 | AttributeSetter::call(state, throwScope, [&] { |
400 | return impl.setFamily(WTFMove(nativeValue)); |
401 | }); |
402 | return true; |
403 | } |
404 | |
405 | bool setJSFontFaceFamily(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
406 | { |
407 | return IDLAttribute<JSFontFace>::set<setJSFontFaceFamilySetter>(*state, thisValue, encodedValue, "family" ); |
408 | } |
409 | |
410 | static inline JSValue jsFontFaceStyleGetter(ExecState& state, JSFontFace& thisObject, ThrowScope& throwScope) |
411 | { |
412 | UNUSED_PARAM(throwScope); |
413 | UNUSED_PARAM(state); |
414 | auto& impl = thisObject.wrapped(); |
415 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.style()); |
416 | return result; |
417 | } |
418 | |
419 | EncodedJSValue jsFontFaceStyle(ExecState* state, EncodedJSValue thisValue, PropertyName) |
420 | { |
421 | return IDLAttribute<JSFontFace>::get<jsFontFaceStyleGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "style" ); |
422 | } |
423 | |
424 | static inline bool setJSFontFaceStyleSetter(ExecState& state, JSFontFace& thisObject, JSValue value, ThrowScope& throwScope) |
425 | { |
426 | UNUSED_PARAM(throwScope); |
427 | auto& impl = thisObject.wrapped(); |
428 | auto nativeValue = convert<IDLDOMString>(state, value); |
429 | RETURN_IF_EXCEPTION(throwScope, false); |
430 | AttributeSetter::call(state, throwScope, [&] { |
431 | return impl.setStyle(WTFMove(nativeValue)); |
432 | }); |
433 | return true; |
434 | } |
435 | |
436 | bool setJSFontFaceStyle(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
437 | { |
438 | return IDLAttribute<JSFontFace>::set<setJSFontFaceStyleSetter>(*state, thisValue, encodedValue, "style" ); |
439 | } |
440 | |
441 | static inline JSValue jsFontFaceWeightGetter(ExecState& state, JSFontFace& thisObject, ThrowScope& throwScope) |
442 | { |
443 | UNUSED_PARAM(throwScope); |
444 | UNUSED_PARAM(state); |
445 | auto& impl = thisObject.wrapped(); |
446 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.weight()); |
447 | return result; |
448 | } |
449 | |
450 | EncodedJSValue jsFontFaceWeight(ExecState* state, EncodedJSValue thisValue, PropertyName) |
451 | { |
452 | return IDLAttribute<JSFontFace>::get<jsFontFaceWeightGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "weight" ); |
453 | } |
454 | |
455 | static inline bool setJSFontFaceWeightSetter(ExecState& state, JSFontFace& thisObject, JSValue value, ThrowScope& throwScope) |
456 | { |
457 | UNUSED_PARAM(throwScope); |
458 | auto& impl = thisObject.wrapped(); |
459 | auto nativeValue = convert<IDLDOMString>(state, value); |
460 | RETURN_IF_EXCEPTION(throwScope, false); |
461 | AttributeSetter::call(state, throwScope, [&] { |
462 | return impl.setWeight(WTFMove(nativeValue)); |
463 | }); |
464 | return true; |
465 | } |
466 | |
467 | bool setJSFontFaceWeight(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
468 | { |
469 | return IDLAttribute<JSFontFace>::set<setJSFontFaceWeightSetter>(*state, thisValue, encodedValue, "weight" ); |
470 | } |
471 | |
472 | static inline JSValue jsFontFaceStretchGetter(ExecState& state, JSFontFace& thisObject, ThrowScope& throwScope) |
473 | { |
474 | UNUSED_PARAM(throwScope); |
475 | UNUSED_PARAM(state); |
476 | auto& impl = thisObject.wrapped(); |
477 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.stretch()); |
478 | return result; |
479 | } |
480 | |
481 | EncodedJSValue jsFontFaceStretch(ExecState* state, EncodedJSValue thisValue, PropertyName) |
482 | { |
483 | return IDLAttribute<JSFontFace>::get<jsFontFaceStretchGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "stretch" ); |
484 | } |
485 | |
486 | static inline bool setJSFontFaceStretchSetter(ExecState& state, JSFontFace& thisObject, JSValue value, ThrowScope& throwScope) |
487 | { |
488 | UNUSED_PARAM(throwScope); |
489 | auto& impl = thisObject.wrapped(); |
490 | auto nativeValue = convert<IDLDOMString>(state, value); |
491 | RETURN_IF_EXCEPTION(throwScope, false); |
492 | AttributeSetter::call(state, throwScope, [&] { |
493 | return impl.setStretch(WTFMove(nativeValue)); |
494 | }); |
495 | return true; |
496 | } |
497 | |
498 | bool setJSFontFaceStretch(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
499 | { |
500 | return IDLAttribute<JSFontFace>::set<setJSFontFaceStretchSetter>(*state, thisValue, encodedValue, "stretch" ); |
501 | } |
502 | |
503 | static inline JSValue jsFontFaceUnicodeRangeGetter(ExecState& state, JSFontFace& thisObject, ThrowScope& throwScope) |
504 | { |
505 | UNUSED_PARAM(throwScope); |
506 | UNUSED_PARAM(state); |
507 | auto& impl = thisObject.wrapped(); |
508 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.unicodeRange()); |
509 | return result; |
510 | } |
511 | |
512 | EncodedJSValue jsFontFaceUnicodeRange(ExecState* state, EncodedJSValue thisValue, PropertyName) |
513 | { |
514 | return IDLAttribute<JSFontFace>::get<jsFontFaceUnicodeRangeGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "unicodeRange" ); |
515 | } |
516 | |
517 | static inline bool setJSFontFaceUnicodeRangeSetter(ExecState& state, JSFontFace& thisObject, JSValue value, ThrowScope& throwScope) |
518 | { |
519 | UNUSED_PARAM(throwScope); |
520 | auto& impl = thisObject.wrapped(); |
521 | auto nativeValue = convert<IDLDOMString>(state, value); |
522 | RETURN_IF_EXCEPTION(throwScope, false); |
523 | AttributeSetter::call(state, throwScope, [&] { |
524 | return impl.setUnicodeRange(WTFMove(nativeValue)); |
525 | }); |
526 | return true; |
527 | } |
528 | |
529 | bool setJSFontFaceUnicodeRange(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
530 | { |
531 | return IDLAttribute<JSFontFace>::set<setJSFontFaceUnicodeRangeSetter>(*state, thisValue, encodedValue, "unicodeRange" ); |
532 | } |
533 | |
534 | static inline JSValue jsFontFaceVariantGetter(ExecState& state, JSFontFace& thisObject, ThrowScope& throwScope) |
535 | { |
536 | UNUSED_PARAM(throwScope); |
537 | UNUSED_PARAM(state); |
538 | auto& impl = thisObject.wrapped(); |
539 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.variant()); |
540 | return result; |
541 | } |
542 | |
543 | EncodedJSValue jsFontFaceVariant(ExecState* state, EncodedJSValue thisValue, PropertyName) |
544 | { |
545 | return IDLAttribute<JSFontFace>::get<jsFontFaceVariantGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "variant" ); |
546 | } |
547 | |
548 | static inline bool setJSFontFaceVariantSetter(ExecState& state, JSFontFace& thisObject, JSValue value, ThrowScope& throwScope) |
549 | { |
550 | UNUSED_PARAM(throwScope); |
551 | auto& impl = thisObject.wrapped(); |
552 | auto nativeValue = convert<IDLDOMString>(state, value); |
553 | RETURN_IF_EXCEPTION(throwScope, false); |
554 | AttributeSetter::call(state, throwScope, [&] { |
555 | return impl.setVariant(WTFMove(nativeValue)); |
556 | }); |
557 | return true; |
558 | } |
559 | |
560 | bool setJSFontFaceVariant(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
561 | { |
562 | return IDLAttribute<JSFontFace>::set<setJSFontFaceVariantSetter>(*state, thisValue, encodedValue, "variant" ); |
563 | } |
564 | |
565 | static inline JSValue jsFontFaceFeatureSettingsGetter(ExecState& state, JSFontFace& thisObject, ThrowScope& throwScope) |
566 | { |
567 | UNUSED_PARAM(throwScope); |
568 | UNUSED_PARAM(state); |
569 | auto& impl = thisObject.wrapped(); |
570 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.featureSettings()); |
571 | return result; |
572 | } |
573 | |
574 | EncodedJSValue jsFontFaceFeatureSettings(ExecState* state, EncodedJSValue thisValue, PropertyName) |
575 | { |
576 | return IDLAttribute<JSFontFace>::get<jsFontFaceFeatureSettingsGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "featureSettings" ); |
577 | } |
578 | |
579 | static inline bool setJSFontFaceFeatureSettingsSetter(ExecState& state, JSFontFace& thisObject, JSValue value, ThrowScope& throwScope) |
580 | { |
581 | UNUSED_PARAM(throwScope); |
582 | auto& impl = thisObject.wrapped(); |
583 | auto nativeValue = convert<IDLDOMString>(state, value); |
584 | RETURN_IF_EXCEPTION(throwScope, false); |
585 | AttributeSetter::call(state, throwScope, [&] { |
586 | return impl.setFeatureSettings(WTFMove(nativeValue)); |
587 | }); |
588 | return true; |
589 | } |
590 | |
591 | bool setJSFontFaceFeatureSettings(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
592 | { |
593 | return IDLAttribute<JSFontFace>::set<setJSFontFaceFeatureSettingsSetter>(*state, thisValue, encodedValue, "featureSettings" ); |
594 | } |
595 | |
596 | static inline JSValue jsFontFaceDisplayGetter(ExecState& state, JSFontFace& thisObject, ThrowScope& throwScope) |
597 | { |
598 | UNUSED_PARAM(throwScope); |
599 | UNUSED_PARAM(state); |
600 | auto& impl = thisObject.wrapped(); |
601 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.display()); |
602 | return result; |
603 | } |
604 | |
605 | EncodedJSValue jsFontFaceDisplay(ExecState* state, EncodedJSValue thisValue, PropertyName) |
606 | { |
607 | return IDLAttribute<JSFontFace>::get<jsFontFaceDisplayGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "display" ); |
608 | } |
609 | |
610 | static inline bool setJSFontFaceDisplaySetter(ExecState& state, JSFontFace& thisObject, JSValue value, ThrowScope& throwScope) |
611 | { |
612 | UNUSED_PARAM(throwScope); |
613 | auto& impl = thisObject.wrapped(); |
614 | auto nativeValue = convert<IDLDOMString>(state, value); |
615 | RETURN_IF_EXCEPTION(throwScope, false); |
616 | AttributeSetter::call(state, throwScope, [&] { |
617 | return impl.setDisplay(WTFMove(nativeValue)); |
618 | }); |
619 | return true; |
620 | } |
621 | |
622 | bool setJSFontFaceDisplay(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
623 | { |
624 | return IDLAttribute<JSFontFace>::set<setJSFontFaceDisplaySetter>(*state, thisValue, encodedValue, "display" ); |
625 | } |
626 | |
627 | static inline JSValue jsFontFaceStatusGetter(ExecState& state, JSFontFace& thisObject, ThrowScope& throwScope) |
628 | { |
629 | UNUSED_PARAM(throwScope); |
630 | UNUSED_PARAM(state); |
631 | auto& impl = thisObject.wrapped(); |
632 | JSValue result = toJS<IDLEnumeration<FontFace::LoadStatus>>(state, throwScope, impl.status()); |
633 | return result; |
634 | } |
635 | |
636 | EncodedJSValue jsFontFaceStatus(ExecState* state, EncodedJSValue thisValue, PropertyName) |
637 | { |
638 | return IDLAttribute<JSFontFace>::get<jsFontFaceStatusGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "status" ); |
639 | } |
640 | |
641 | static inline JSValue jsFontFaceLoadedGetter(ExecState& state, JSFontFace& thisObject, ThrowScope& throwScope) |
642 | { |
643 | UNUSED_PARAM(throwScope); |
644 | UNUSED_PARAM(state); |
645 | auto& impl = thisObject.wrapped(); |
646 | JSValue result = toJS<IDLPromise<IDLInterface<FontFace>>>(state, *thisObject.globalObject(), throwScope, impl.loaded()); |
647 | return result; |
648 | } |
649 | |
650 | EncodedJSValue jsFontFaceLoaded(ExecState* state, EncodedJSValue thisValue, PropertyName) |
651 | { |
652 | return IDLAttribute<JSFontFace>::get<jsFontFaceLoadedGetter, CastedThisErrorBehavior::RejectPromise>(*state, thisValue, "loaded" ); |
653 | } |
654 | |
655 | static inline JSC::EncodedJSValue jsFontFacePrototypeFunctionLoadBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSFontFace>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
656 | { |
657 | UNUSED_PARAM(state); |
658 | UNUSED_PARAM(throwScope); |
659 | auto& impl = castedThis->wrapped(); |
660 | return JSValue::encode(toJS<IDLPromise<IDLInterface<FontFace>>>(*state, *castedThis->globalObject(), impl.load())); |
661 | } |
662 | |
663 | EncodedJSValue JSC_HOST_CALL jsFontFacePrototypeFunctionLoad(ExecState* state) |
664 | { |
665 | return IDLOperationReturningPromise<JSFontFace>::callReturningOwnPromise<jsFontFacePrototypeFunctionLoadBody>(*state, "load" ); |
666 | } |
667 | |
668 | void JSFontFace::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
669 | { |
670 | auto* thisObject = jsCast<JSFontFace*>(cell); |
671 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
672 | if (thisObject->scriptExecutionContext()) |
673 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
674 | Base::heapSnapshot(cell, builder); |
675 | } |
676 | |
677 | bool JSFontFaceOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
678 | { |
679 | UNUSED_PARAM(handle); |
680 | UNUSED_PARAM(visitor); |
681 | UNUSED_PARAM(reason); |
682 | return false; |
683 | } |
684 | |
685 | void JSFontFaceOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
686 | { |
687 | auto* jsFontFace = static_cast<JSFontFace*>(handle.slot()->asCell()); |
688 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
689 | uncacheWrapper(world, &jsFontFace->wrapped(), jsFontFace); |
690 | } |
691 | |
692 | #if ENABLE(BINDING_INTEGRITY) |
693 | #if PLATFORM(WIN) |
694 | #pragma warning(disable: 4483) |
695 | extern "C" { extern void (*const __identifier("??_7FontFace@WebCore@@6B@" )[])(); } |
696 | #else |
697 | extern "C" { extern void* _ZTVN7WebCore8FontFaceE[]; } |
698 | #endif |
699 | #endif |
700 | |
701 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<FontFace>&& impl) |
702 | { |
703 | |
704 | #if ENABLE(BINDING_INTEGRITY) |
705 | void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr())); |
706 | #if PLATFORM(WIN) |
707 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7FontFace@WebCore@@6B@" )); |
708 | #else |
709 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore8FontFaceE[2]); |
710 | #endif |
711 | |
712 | // If this fails FontFace does not have a vtable, so you need to add the |
713 | // ImplementationLacksVTable attribute to the interface definition |
714 | static_assert(std::is_polymorphic<FontFace>::value, "FontFace is not polymorphic" ); |
715 | |
716 | // If you hit this assertion you either have a use after free bug, or |
717 | // FontFace has subclasses. If FontFace has subclasses that get passed |
718 | // to toJS() we currently require FontFace you to opt out of binding hardening |
719 | // by adding the SkipVTableValidation attribute to the interface IDL definition |
720 | RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer); |
721 | #endif |
722 | return createWrapper<FontFace>(globalObject, WTFMove(impl)); |
723 | } |
724 | |
725 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, FontFace& impl) |
726 | { |
727 | return wrap(state, globalObject, impl); |
728 | } |
729 | |
730 | FontFace* JSFontFace::toWrapped(JSC::VM& vm, JSC::JSValue value) |
731 | { |
732 | if (auto* wrapper = jsDynamicCast<JSFontFace*>(vm, value)) |
733 | return &wrapper->wrapped(); |
734 | return nullptr; |
735 | } |
736 | |
737 | } |
738 | |