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(WEB_CRYPTO) |
24 | |
25 | #include "JSCryptoKey.h" |
26 | |
27 | #include "JSCryptoAesKeyAlgorithm.h" |
28 | #include "JSCryptoEcKeyAlgorithm.h" |
29 | #include "JSCryptoHmacKeyAlgorithm.h" |
30 | #include "JSCryptoKeyAlgorithm.h" |
31 | #include "JSCryptoKeyUsage.h" |
32 | #include "JSCryptoRsaHashedKeyAlgorithm.h" |
33 | #include "JSCryptoRsaKeyAlgorithm.h" |
34 | #include "JSDOMAttribute.h" |
35 | #include "JSDOMBinding.h" |
36 | #include "JSDOMConstructorNotConstructable.h" |
37 | #include "JSDOMConvertBoolean.h" |
38 | #include "JSDOMConvertDictionary.h" |
39 | #include "JSDOMConvertSequences.h" |
40 | #include "JSDOMConvertUnion.h" |
41 | #include "JSDOMExceptionHandling.h" |
42 | #include "JSDOMGlobalObject.h" |
43 | #include "JSDOMWrapperCache.h" |
44 | #include "ScriptExecutionContext.h" |
45 | #include <JavaScriptCore/FunctionPrototype.h> |
46 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
47 | #include <JavaScriptCore/JSArray.h> |
48 | #include <JavaScriptCore/JSCInlines.h> |
49 | #include <JavaScriptCore/JSString.h> |
50 | #include <wtf/GetPtr.h> |
51 | #include <wtf/PointerPreparations.h> |
52 | #include <wtf/URL.h> |
53 | #include <wtf/Variant.h> |
54 | |
55 | |
56 | namespace WebCore { |
57 | using namespace JSC; |
58 | |
59 | String convertEnumerationToString(CryptoKey::Type enumerationValue) |
60 | { |
61 | static const NeverDestroyed<String> values[] = { |
62 | MAKE_STATIC_STRING_IMPL("public" ), |
63 | MAKE_STATIC_STRING_IMPL("private" ), |
64 | MAKE_STATIC_STRING_IMPL("secret" ), |
65 | }; |
66 | static_assert(static_cast<size_t>(CryptoKey::Type::Public) == 0, "CryptoKey::Type::Public is not 0 as expected" ); |
67 | static_assert(static_cast<size_t>(CryptoKey::Type::Private) == 1, "CryptoKey::Type::Private is not 1 as expected" ); |
68 | static_assert(static_cast<size_t>(CryptoKey::Type::Secret) == 2, "CryptoKey::Type::Secret is not 2 as expected" ); |
69 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
70 | return values[static_cast<size_t>(enumerationValue)]; |
71 | } |
72 | |
73 | template<> JSString* convertEnumerationToJS(ExecState& state, CryptoKey::Type enumerationValue) |
74 | { |
75 | return jsStringWithCache(&state, convertEnumerationToString(enumerationValue)); |
76 | } |
77 | |
78 | template<> Optional<CryptoKey::Type> parseEnumeration<CryptoKey::Type>(ExecState& state, JSValue value) |
79 | { |
80 | auto stringValue = value.toWTFString(&state); |
81 | if (stringValue == "public" ) |
82 | return CryptoKey::Type::Public; |
83 | if (stringValue == "private" ) |
84 | return CryptoKey::Type::Private; |
85 | if (stringValue == "secret" ) |
86 | return CryptoKey::Type::Secret; |
87 | return WTF::nullopt; |
88 | } |
89 | |
90 | template<> const char* expectedEnumerationValues<CryptoKey::Type>() |
91 | { |
92 | return "\"public\", \"private\", \"secret\"" ; |
93 | } |
94 | |
95 | // Attributes |
96 | |
97 | JSC::EncodedJSValue jsCryptoKeyConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
98 | bool setJSCryptoKeyConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
99 | JSC::EncodedJSValue jsCryptoKeyType(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
100 | JSC::EncodedJSValue jsCryptoKeyExtractable(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
101 | JSC::EncodedJSValue jsCryptoKeyAlgorithm(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
102 | JSC::EncodedJSValue jsCryptoKeyUsages(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
103 | |
104 | class JSCryptoKeyPrototype : public JSC::JSNonFinalObject { |
105 | public: |
106 | using Base = JSC::JSNonFinalObject; |
107 | static JSCryptoKeyPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
108 | { |
109 | JSCryptoKeyPrototype* ptr = new (NotNull, JSC::allocateCell<JSCryptoKeyPrototype>(vm.heap)) JSCryptoKeyPrototype(vm, globalObject, structure); |
110 | ptr->finishCreation(vm); |
111 | return ptr; |
112 | } |
113 | |
114 | DECLARE_INFO; |
115 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
116 | { |
117 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
118 | } |
119 | |
120 | private: |
121 | JSCryptoKeyPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
122 | : JSC::JSNonFinalObject(vm, structure) |
123 | { |
124 | } |
125 | |
126 | void finishCreation(JSC::VM&); |
127 | }; |
128 | |
129 | using JSCryptoKeyConstructor = JSDOMConstructorNotConstructable<JSCryptoKey>; |
130 | |
131 | template<> JSValue JSCryptoKeyConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
132 | { |
133 | UNUSED_PARAM(vm); |
134 | return globalObject.functionPrototype(); |
135 | } |
136 | |
137 | template<> void JSCryptoKeyConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
138 | { |
139 | putDirect(vm, vm.propertyNames->prototype, JSCryptoKey::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
140 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("CryptoKey"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
141 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
142 | } |
143 | |
144 | template<> const ClassInfo JSCryptoKeyConstructor::s_info = { "CryptoKey" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCryptoKeyConstructor) }; |
145 | |
146 | /* Hash table for prototype */ |
147 | |
148 | static const HashTableValue JSCryptoKeyPrototypeTableValues[] = |
149 | { |
150 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCryptoKeyConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSCryptoKeyConstructor) } }, |
151 | { "type" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCryptoKeyType), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
152 | { "extractable" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCryptoKeyExtractable), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
153 | { "algorithm" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCryptoKeyAlgorithm), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
154 | { "usages" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCryptoKeyUsages), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
155 | }; |
156 | |
157 | const ClassInfo JSCryptoKeyPrototype::s_info = { "CryptoKeyPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCryptoKeyPrototype) }; |
158 | |
159 | void JSCryptoKeyPrototype::finishCreation(VM& vm) |
160 | { |
161 | Base::finishCreation(vm); |
162 | reifyStaticProperties(vm, JSCryptoKey::info(), JSCryptoKeyPrototypeTableValues, *this); |
163 | } |
164 | |
165 | const ClassInfo JSCryptoKey::s_info = { "CryptoKey" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCryptoKey) }; |
166 | |
167 | JSCryptoKey::JSCryptoKey(Structure* structure, JSDOMGlobalObject& globalObject, Ref<CryptoKey>&& impl) |
168 | : JSDOMWrapper<CryptoKey>(structure, globalObject, WTFMove(impl)) |
169 | { |
170 | } |
171 | |
172 | void JSCryptoKey::finishCreation(VM& vm) |
173 | { |
174 | Base::finishCreation(vm); |
175 | ASSERT(inherits(vm, info())); |
176 | |
177 | } |
178 | |
179 | JSObject* JSCryptoKey::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
180 | { |
181 | return JSCryptoKeyPrototype::create(vm, &globalObject, JSCryptoKeyPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
182 | } |
183 | |
184 | JSObject* JSCryptoKey::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
185 | { |
186 | return getDOMPrototype<JSCryptoKey>(vm, globalObject); |
187 | } |
188 | |
189 | JSValue JSCryptoKey::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
190 | { |
191 | return getDOMConstructor<JSCryptoKeyConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
192 | } |
193 | |
194 | void JSCryptoKey::destroy(JSC::JSCell* cell) |
195 | { |
196 | JSCryptoKey* thisObject = static_cast<JSCryptoKey*>(cell); |
197 | thisObject->JSCryptoKey::~JSCryptoKey(); |
198 | } |
199 | |
200 | template<> inline JSCryptoKey* IDLAttribute<JSCryptoKey>::cast(ExecState& state, EncodedJSValue thisValue) |
201 | { |
202 | return jsDynamicCast<JSCryptoKey*>(state.vm(), JSValue::decode(thisValue)); |
203 | } |
204 | |
205 | EncodedJSValue jsCryptoKeyConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
206 | { |
207 | VM& vm = state->vm(); |
208 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
209 | auto* prototype = jsDynamicCast<JSCryptoKeyPrototype*>(vm, JSValue::decode(thisValue)); |
210 | if (UNLIKELY(!prototype)) |
211 | return throwVMTypeError(state, throwScope); |
212 | return JSValue::encode(JSCryptoKey::getConstructor(state->vm(), prototype->globalObject())); |
213 | } |
214 | |
215 | bool setJSCryptoKeyConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
216 | { |
217 | VM& vm = state->vm(); |
218 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
219 | auto* prototype = jsDynamicCast<JSCryptoKeyPrototype*>(vm, JSValue::decode(thisValue)); |
220 | if (UNLIKELY(!prototype)) { |
221 | throwVMTypeError(state, throwScope); |
222 | return false; |
223 | } |
224 | // Shadowing a built-in constructor |
225 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
226 | } |
227 | |
228 | static inline JSValue jsCryptoKeyTypeGetter(ExecState& state, JSCryptoKey& thisObject, ThrowScope& throwScope) |
229 | { |
230 | UNUSED_PARAM(throwScope); |
231 | UNUSED_PARAM(state); |
232 | auto& impl = thisObject.wrapped(); |
233 | JSValue result = toJS<IDLEnumeration<CryptoKey::Type>>(state, throwScope, impl.type()); |
234 | return result; |
235 | } |
236 | |
237 | EncodedJSValue jsCryptoKeyType(ExecState* state, EncodedJSValue thisValue, PropertyName) |
238 | { |
239 | return IDLAttribute<JSCryptoKey>::get<jsCryptoKeyTypeGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "type" ); |
240 | } |
241 | |
242 | static inline JSValue (ExecState& state, JSCryptoKey& thisObject, ThrowScope& throwScope) |
243 | { |
244 | UNUSED_PARAM(throwScope); |
245 | UNUSED_PARAM(state); |
246 | auto& impl = thisObject.wrapped(); |
247 | JSValue result = toJS<IDLBoolean>(state, throwScope, impl.extractable()); |
248 | return result; |
249 | } |
250 | |
251 | EncodedJSValue (ExecState* state, EncodedJSValue thisValue, PropertyName) |
252 | { |
253 | return IDLAttribute<JSCryptoKey>::get<jsCryptoKeyExtractableGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "extractable" ); |
254 | } |
255 | |
256 | static inline JSValue jsCryptoKeyAlgorithmGetter(ExecState& state, JSCryptoKey& thisObject, ThrowScope& throwScope) |
257 | { |
258 | UNUSED_PARAM(throwScope); |
259 | UNUSED_PARAM(state); |
260 | if (JSValue cachedValue = thisObject.m_algorithm.get()) |
261 | return cachedValue; |
262 | auto& impl = thisObject.wrapped(); |
263 | JSValue result = toJS<IDLUnion<IDLDictionary<CryptoKeyAlgorithm>, IDLDictionary<CryptoAesKeyAlgorithm>, IDLDictionary<CryptoEcKeyAlgorithm>, IDLDictionary<CryptoHmacKeyAlgorithm>, IDLDictionary<CryptoRsaHashedKeyAlgorithm>, IDLDictionary<CryptoRsaKeyAlgorithm>>>(state, *thisObject.globalObject(), throwScope, impl.algorithm()); |
264 | thisObject.m_algorithm.set(state.vm(), &thisObject, result); |
265 | return result; |
266 | } |
267 | |
268 | EncodedJSValue jsCryptoKeyAlgorithm(ExecState* state, EncodedJSValue thisValue, PropertyName) |
269 | { |
270 | return IDLAttribute<JSCryptoKey>::get<jsCryptoKeyAlgorithmGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "algorithm" ); |
271 | } |
272 | |
273 | static inline JSValue jsCryptoKeyUsagesGetter(ExecState& state, JSCryptoKey& thisObject, ThrowScope& throwScope) |
274 | { |
275 | UNUSED_PARAM(throwScope); |
276 | UNUSED_PARAM(state); |
277 | if (JSValue cachedValue = thisObject.m_usages.get()) |
278 | return cachedValue; |
279 | auto& impl = thisObject.wrapped(); |
280 | JSValue result = toJS<IDLSequence<IDLEnumeration<CryptoKeyUsage>>>(state, *thisObject.globalObject(), throwScope, impl.usages()); |
281 | thisObject.m_usages.set(state.vm(), &thisObject, result); |
282 | return result; |
283 | } |
284 | |
285 | EncodedJSValue jsCryptoKeyUsages(ExecState* state, EncodedJSValue thisValue, PropertyName) |
286 | { |
287 | return IDLAttribute<JSCryptoKey>::get<jsCryptoKeyUsagesGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "usages" ); |
288 | } |
289 | |
290 | void JSCryptoKey::visitChildren(JSCell* cell, SlotVisitor& visitor) |
291 | { |
292 | auto* thisObject = jsCast<JSCryptoKey*>(cell); |
293 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
294 | Base::visitChildren(thisObject, visitor); |
295 | visitor.append(thisObject->m_algorithm); |
296 | visitor.append(thisObject->m_usages); |
297 | } |
298 | |
299 | void JSCryptoKey::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
300 | { |
301 | auto* thisObject = jsCast<JSCryptoKey*>(cell); |
302 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
303 | if (thisObject->scriptExecutionContext()) |
304 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
305 | Base::heapSnapshot(cell, builder); |
306 | } |
307 | |
308 | bool JSCryptoKeyOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
309 | { |
310 | auto* jsCryptoKey = jsCast<JSCryptoKey*>(handle.slot()->asCell()); |
311 | CryptoKey* root = &jsCryptoKey->wrapped(); |
312 | if (UNLIKELY(reason)) |
313 | *reason = "Reachable from CryptoKey" ; |
314 | return visitor.containsOpaqueRoot(root); |
315 | } |
316 | |
317 | void JSCryptoKeyOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
318 | { |
319 | auto* jsCryptoKey = static_cast<JSCryptoKey*>(handle.slot()->asCell()); |
320 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
321 | uncacheWrapper(world, &jsCryptoKey->wrapped(), jsCryptoKey); |
322 | } |
323 | |
324 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<CryptoKey>&& impl) |
325 | { |
326 | return createWrapper<CryptoKey>(globalObject, WTFMove(impl)); |
327 | } |
328 | |
329 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, CryptoKey& impl) |
330 | { |
331 | return wrap(state, globalObject, impl); |
332 | } |
333 | |
334 | CryptoKey* JSCryptoKey::toWrapped(JSC::VM& vm, JSC::JSValue value) |
335 | { |
336 | if (auto* wrapper = jsDynamicCast<JSCryptoKey*>(vm, value)) |
337 | return &wrapper->wrapped(); |
338 | return nullptr; |
339 | } |
340 | |
341 | } |
342 | |
343 | #endif // ENABLE(WEB_CRYPTO) |
344 | |