| 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 "JSAttr.h" |
| 23 | |
| 24 | #include "CustomElementReactionQueue.h" |
| 25 | #include "JSCSSStyleDeclaration.h" |
| 26 | #include "JSDOMAttribute.h" |
| 27 | #include "JSDOMBinding.h" |
| 28 | #include "JSDOMConstructorNotConstructable.h" |
| 29 | #include "JSDOMConvertBoolean.h" |
| 30 | #include "JSDOMConvertInterface.h" |
| 31 | #include "JSDOMConvertNullable.h" |
| 32 | #include "JSDOMConvertStrings.h" |
| 33 | #include "JSDOMExceptionHandling.h" |
| 34 | #include "JSDOMGlobalObject.h" |
| 35 | #include "JSDOMWrapperCache.h" |
| 36 | #include "JSElement.h" |
| 37 | #include "RuntimeEnabledFeatures.h" |
| 38 | #include "ScriptExecutionContext.h" |
| 39 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
| 40 | #include <JavaScriptCore/JSCInlines.h> |
| 41 | #include <wtf/GetPtr.h> |
| 42 | #include <wtf/PointerPreparations.h> |
| 43 | #include <wtf/URL.h> |
| 44 | |
| 45 | |
| 46 | namespace WebCore { |
| 47 | using namespace JSC; |
| 48 | |
| 49 | // Attributes |
| 50 | |
| 51 | JSC::EncodedJSValue jsAttrConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 52 | bool setJSAttrConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 53 | JSC::EncodedJSValue jsAttrNamespaceURI(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 54 | JSC::EncodedJSValue jsAttrPrefix(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 55 | JSC::EncodedJSValue jsAttrLocalName(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 56 | JSC::EncodedJSValue jsAttrName(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 57 | JSC::EncodedJSValue jsAttrValue(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 58 | bool setJSAttrValue(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 59 | JSC::EncodedJSValue jsAttrOwnerElement(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 60 | JSC::EncodedJSValue jsAttrSpecified(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 61 | JSC::EncodedJSValue jsAttrStyle(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 62 | |
| 63 | class JSAttrPrototype : public JSC::JSNonFinalObject { |
| 64 | public: |
| 65 | using Base = JSC::JSNonFinalObject; |
| 66 | static JSAttrPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
| 67 | { |
| 68 | JSAttrPrototype* ptr = new (NotNull, JSC::allocateCell<JSAttrPrototype>(vm.heap)) JSAttrPrototype(vm, globalObject, structure); |
| 69 | ptr->finishCreation(vm); |
| 70 | return ptr; |
| 71 | } |
| 72 | |
| 73 | DECLARE_INFO; |
| 74 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
| 75 | { |
| 76 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
| 77 | } |
| 78 | |
| 79 | private: |
| 80 | JSAttrPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| 81 | : JSC::JSNonFinalObject(vm, structure) |
| 82 | { |
| 83 | } |
| 84 | |
| 85 | void finishCreation(JSC::VM&); |
| 86 | }; |
| 87 | |
| 88 | using JSAttrConstructor = JSDOMConstructorNotConstructable<JSAttr>; |
| 89 | |
| 90 | template<> JSValue JSAttrConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| 91 | { |
| 92 | return JSNode::getConstructor(vm, &globalObject); |
| 93 | } |
| 94 | |
| 95 | template<> void JSAttrConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
| 96 | { |
| 97 | putDirect(vm, vm.propertyNames->prototype, JSAttr::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 98 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("Attr"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 99 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 100 | } |
| 101 | |
| 102 | template<> const ClassInfo JSAttrConstructor::s_info = { "Attr" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSAttrConstructor) }; |
| 103 | |
| 104 | /* Hash table for prototype */ |
| 105 | |
| 106 | static const HashTableValue JSAttrPrototypeTableValues[] = |
| 107 | { |
| 108 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAttrConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSAttrConstructor) } }, |
| 109 | { "namespaceURI" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAttrNamespaceURI), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 110 | { "prefix" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAttrPrefix), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 111 | { "localName" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAttrLocalName), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 112 | { "name" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAttrName), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 113 | { "value" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAttrValue), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSAttrValue) } }, |
| 114 | { "ownerElement" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAttrOwnerElement), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 115 | { "specified" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAttrSpecified), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 116 | { "style" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAttrStyle), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 117 | }; |
| 118 | |
| 119 | const ClassInfo JSAttrPrototype::s_info = { "AttrPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSAttrPrototype) }; |
| 120 | |
| 121 | void JSAttrPrototype::finishCreation(VM& vm) |
| 122 | { |
| 123 | Base::finishCreation(vm); |
| 124 | reifyStaticProperties(vm, JSAttr::info(), JSAttrPrototypeTableValues, *this); |
| 125 | bool hasDisabledRuntimeProperties = false; |
| 126 | if (!RuntimeEnabledFeatures::sharedFeatures().attrStyleEnabled()) { |
| 127 | hasDisabledRuntimeProperties = true; |
| 128 | auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("style" ), strlen("style" )); |
| 129 | VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable); |
| 130 | JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName); |
| 131 | } |
| 132 | if (hasDisabledRuntimeProperties && structure()->isDictionary()) |
| 133 | flattenDictionaryObject(vm); |
| 134 | } |
| 135 | |
| 136 | const ClassInfo JSAttr::s_info = { "Attr" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSAttr) }; |
| 137 | |
| 138 | JSAttr::JSAttr(Structure* structure, JSDOMGlobalObject& globalObject, Ref<Attr>&& impl) |
| 139 | : JSNode(structure, globalObject, WTFMove(impl)) |
| 140 | { |
| 141 | } |
| 142 | |
| 143 | void JSAttr::finishCreation(VM& vm) |
| 144 | { |
| 145 | Base::finishCreation(vm); |
| 146 | ASSERT(inherits(vm, info())); |
| 147 | |
| 148 | } |
| 149 | |
| 150 | JSObject* JSAttr::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 151 | { |
| 152 | return JSAttrPrototype::create(vm, &globalObject, JSAttrPrototype::createStructure(vm, &globalObject, JSNode::prototype(vm, globalObject))); |
| 153 | } |
| 154 | |
| 155 | JSObject* JSAttr::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 156 | { |
| 157 | return getDOMPrototype<JSAttr>(vm, globalObject); |
| 158 | } |
| 159 | |
| 160 | JSValue JSAttr::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| 161 | { |
| 162 | return getDOMConstructor<JSAttrConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| 163 | } |
| 164 | |
| 165 | template<> inline JSAttr* IDLAttribute<JSAttr>::cast(ExecState& state, EncodedJSValue thisValue) |
| 166 | { |
| 167 | return jsDynamicCast<JSAttr*>(state.vm(), JSValue::decode(thisValue)); |
| 168 | } |
| 169 | |
| 170 | EncodedJSValue jsAttrConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 171 | { |
| 172 | VM& vm = state->vm(); |
| 173 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 174 | auto* prototype = jsDynamicCast<JSAttrPrototype*>(vm, JSValue::decode(thisValue)); |
| 175 | if (UNLIKELY(!prototype)) |
| 176 | return throwVMTypeError(state, throwScope); |
| 177 | return JSValue::encode(JSAttr::getConstructor(state->vm(), prototype->globalObject())); |
| 178 | } |
| 179 | |
| 180 | bool setJSAttrConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 181 | { |
| 182 | VM& vm = state->vm(); |
| 183 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 184 | auto* prototype = jsDynamicCast<JSAttrPrototype*>(vm, JSValue::decode(thisValue)); |
| 185 | if (UNLIKELY(!prototype)) { |
| 186 | throwVMTypeError(state, throwScope); |
| 187 | return false; |
| 188 | } |
| 189 | // Shadowing a built-in constructor |
| 190 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
| 191 | } |
| 192 | |
| 193 | static inline JSValue jsAttrNamespaceURIGetter(ExecState& state, JSAttr& thisObject, ThrowScope& throwScope) |
| 194 | { |
| 195 | UNUSED_PARAM(throwScope); |
| 196 | UNUSED_PARAM(state); |
| 197 | auto& impl = thisObject.wrapped(); |
| 198 | JSValue result = toJS<IDLNullable<IDLDOMString>>(state, throwScope, impl.namespaceURI()); |
| 199 | return result; |
| 200 | } |
| 201 | |
| 202 | EncodedJSValue jsAttrNamespaceURI(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 203 | { |
| 204 | return IDLAttribute<JSAttr>::get<jsAttrNamespaceURIGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "namespaceURI" ); |
| 205 | } |
| 206 | |
| 207 | static inline JSValue jsAttrPrefixGetter(ExecState& state, JSAttr& thisObject, ThrowScope& throwScope) |
| 208 | { |
| 209 | UNUSED_PARAM(throwScope); |
| 210 | UNUSED_PARAM(state); |
| 211 | auto& impl = thisObject.wrapped(); |
| 212 | JSValue result = toJS<IDLNullable<IDLDOMString>>(state, throwScope, impl.prefix()); |
| 213 | return result; |
| 214 | } |
| 215 | |
| 216 | EncodedJSValue jsAttrPrefix(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 217 | { |
| 218 | return IDLAttribute<JSAttr>::get<jsAttrPrefixGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "prefix" ); |
| 219 | } |
| 220 | |
| 221 | static inline JSValue jsAttrLocalNameGetter(ExecState& state, JSAttr& thisObject, ThrowScope& throwScope) |
| 222 | { |
| 223 | UNUSED_PARAM(throwScope); |
| 224 | UNUSED_PARAM(state); |
| 225 | auto& impl = thisObject.wrapped(); |
| 226 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.localName()); |
| 227 | return result; |
| 228 | } |
| 229 | |
| 230 | EncodedJSValue jsAttrLocalName(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 231 | { |
| 232 | return IDLAttribute<JSAttr>::get<jsAttrLocalNameGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "localName" ); |
| 233 | } |
| 234 | |
| 235 | static inline JSValue jsAttrNameGetter(ExecState& state, JSAttr& thisObject, ThrowScope& throwScope) |
| 236 | { |
| 237 | UNUSED_PARAM(throwScope); |
| 238 | UNUSED_PARAM(state); |
| 239 | auto& impl = thisObject.wrapped(); |
| 240 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.name()); |
| 241 | return result; |
| 242 | } |
| 243 | |
| 244 | EncodedJSValue jsAttrName(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 245 | { |
| 246 | return IDLAttribute<JSAttr>::get<jsAttrNameGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "name" ); |
| 247 | } |
| 248 | |
| 249 | static inline JSValue jsAttrValueGetter(ExecState& state, JSAttr& thisObject, ThrowScope& throwScope) |
| 250 | { |
| 251 | UNUSED_PARAM(throwScope); |
| 252 | UNUSED_PARAM(state); |
| 253 | auto& impl = thisObject.wrapped(); |
| 254 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.value()); |
| 255 | return result; |
| 256 | } |
| 257 | |
| 258 | EncodedJSValue jsAttrValue(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 259 | { |
| 260 | return IDLAttribute<JSAttr>::get<jsAttrValueGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "value" ); |
| 261 | } |
| 262 | |
| 263 | static inline bool setJSAttrValueSetter(ExecState& state, JSAttr& thisObject, JSValue value, ThrowScope& throwScope) |
| 264 | { |
| 265 | UNUSED_PARAM(throwScope); |
| 266 | CustomElementReactionStack customElementReactionStack(state); |
| 267 | auto& impl = thisObject.wrapped(); |
| 268 | auto nativeValue = convert<IDLDOMString>(state, value); |
| 269 | RETURN_IF_EXCEPTION(throwScope, false); |
| 270 | AttributeSetter::call(state, throwScope, [&] { |
| 271 | return impl.setValue(WTFMove(nativeValue)); |
| 272 | }); |
| 273 | return true; |
| 274 | } |
| 275 | |
| 276 | bool setJSAttrValue(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 277 | { |
| 278 | return IDLAttribute<JSAttr>::set<setJSAttrValueSetter>(*state, thisValue, encodedValue, "value" ); |
| 279 | } |
| 280 | |
| 281 | static inline JSValue jsAttrOwnerElementGetter(ExecState& state, JSAttr& thisObject, ThrowScope& throwScope) |
| 282 | { |
| 283 | UNUSED_PARAM(throwScope); |
| 284 | UNUSED_PARAM(state); |
| 285 | auto& impl = thisObject.wrapped(); |
| 286 | JSValue result = toJS<IDLNullable<IDLInterface<Element>>>(state, *thisObject.globalObject(), throwScope, impl.ownerElement()); |
| 287 | return result; |
| 288 | } |
| 289 | |
| 290 | EncodedJSValue jsAttrOwnerElement(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 291 | { |
| 292 | return IDLAttribute<JSAttr>::get<jsAttrOwnerElementGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "ownerElement" ); |
| 293 | } |
| 294 | |
| 295 | static inline JSValue jsAttrSpecifiedGetter(ExecState& state, JSAttr& thisObject, ThrowScope& throwScope) |
| 296 | { |
| 297 | UNUSED_PARAM(throwScope); |
| 298 | UNUSED_PARAM(state); |
| 299 | auto& impl = thisObject.wrapped(); |
| 300 | JSValue result = toJS<IDLBoolean>(state, throwScope, impl.specified()); |
| 301 | return result; |
| 302 | } |
| 303 | |
| 304 | EncodedJSValue jsAttrSpecified(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 305 | { |
| 306 | return IDLAttribute<JSAttr>::get<jsAttrSpecifiedGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "specified" ); |
| 307 | } |
| 308 | |
| 309 | static inline JSValue jsAttrStyleGetter(ExecState& state, JSAttr& thisObject, ThrowScope& throwScope) |
| 310 | { |
| 311 | UNUSED_PARAM(throwScope); |
| 312 | UNUSED_PARAM(state); |
| 313 | auto& impl = thisObject.wrapped(); |
| 314 | JSValue result = toJS<IDLInterface<CSSStyleDeclaration>>(state, *thisObject.globalObject(), throwScope, impl.style()); |
| 315 | return result; |
| 316 | } |
| 317 | |
| 318 | EncodedJSValue jsAttrStyle(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 319 | { |
| 320 | return IDLAttribute<JSAttr>::get<jsAttrStyleGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "style" ); |
| 321 | } |
| 322 | |
| 323 | void JSAttr::visitChildren(JSCell* cell, SlotVisitor& visitor) |
| 324 | { |
| 325 | auto* thisObject = jsCast<JSAttr*>(cell); |
| 326 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
| 327 | Base::visitChildren(thisObject, visitor); |
| 328 | thisObject->visitAdditionalChildren(visitor); |
| 329 | } |
| 330 | |
| 331 | void JSAttr::visitOutputConstraints(JSCell* cell, SlotVisitor& visitor) |
| 332 | { |
| 333 | auto* thisObject = jsCast<JSAttr*>(cell); |
| 334 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
| 335 | Base::visitOutputConstraints(thisObject, visitor); |
| 336 | thisObject->visitAdditionalChildren(visitor); |
| 337 | } |
| 338 | |
| 339 | void JSAttr::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
| 340 | { |
| 341 | auto* thisObject = jsCast<JSAttr*>(cell); |
| 342 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
| 343 | if (thisObject->scriptExecutionContext()) |
| 344 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
| 345 | Base::heapSnapshot(cell, builder); |
| 346 | } |
| 347 | |
| 348 | #if ENABLE(BINDING_INTEGRITY) |
| 349 | #if PLATFORM(WIN) |
| 350 | #pragma warning(disable: 4483) |
| 351 | extern "C" { extern void (*const __identifier("??_7Attr@WebCore@@6B@" )[])(); } |
| 352 | #else |
| 353 | extern "C" { extern void* _ZTVN7WebCore4AttrE[]; } |
| 354 | #endif |
| 355 | #endif |
| 356 | |
| 357 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<Attr>&& impl) |
| 358 | { |
| 359 | |
| 360 | #if ENABLE(BINDING_INTEGRITY) |
| 361 | void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr())); |
| 362 | #if PLATFORM(WIN) |
| 363 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7Attr@WebCore@@6B@" )); |
| 364 | #else |
| 365 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore4AttrE[2]); |
| 366 | #endif |
| 367 | |
| 368 | // If this fails Attr does not have a vtable, so you need to add the |
| 369 | // ImplementationLacksVTable attribute to the interface definition |
| 370 | static_assert(std::is_polymorphic<Attr>::value, "Attr is not polymorphic" ); |
| 371 | |
| 372 | // If you hit this assertion you either have a use after free bug, or |
| 373 | // Attr has subclasses. If Attr has subclasses that get passed |
| 374 | // to toJS() we currently require Attr you to opt out of binding hardening |
| 375 | // by adding the SkipVTableValidation attribute to the interface IDL definition |
| 376 | RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer); |
| 377 | #endif |
| 378 | return createWrapper<Attr>(globalObject, WTFMove(impl)); |
| 379 | } |
| 380 | |
| 381 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, Attr& impl) |
| 382 | { |
| 383 | return wrap(state, globalObject, impl); |
| 384 | } |
| 385 | |
| 386 | Attr* JSAttr::toWrapped(JSC::VM& vm, JSC::JSValue value) |
| 387 | { |
| 388 | if (auto* wrapper = jsDynamicCast<JSAttr*>(vm, value)) |
| 389 | return &wrapper->wrapped(); |
| 390 | return nullptr; |
| 391 | } |
| 392 | |
| 393 | } |
| 394 | |