| 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 "JSPerformance.h" |
| 23 | |
| 24 | #include "EventNames.h" |
| 25 | #include "JSDOMAttribute.h" |
| 26 | #include "JSDOMBinding.h" |
| 27 | #include "JSDOMConstructorNotConstructable.h" |
| 28 | #include "JSDOMConvertInterface.h" |
| 29 | #include "JSDOMConvertNumbers.h" |
| 30 | #include "JSDOMConvertSequences.h" |
| 31 | #include "JSDOMConvertStrings.h" |
| 32 | #include "JSDOMExceptionHandling.h" |
| 33 | #include "JSDOMGlobalObject.h" |
| 34 | #include "JSDOMOperation.h" |
| 35 | #include "JSDOMWrapperCache.h" |
| 36 | #include "JSEventListener.h" |
| 37 | #include "JSPerformanceEntry.h" |
| 38 | #include "JSPerformanceNavigation.h" |
| 39 | #include "JSPerformanceTiming.h" |
| 40 | #include "RuntimeEnabledFeatures.h" |
| 41 | #include "ScriptExecutionContext.h" |
| 42 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
| 43 | #include <JavaScriptCore/JSArray.h> |
| 44 | #include <JavaScriptCore/JSCInlines.h> |
| 45 | #include <wtf/GetPtr.h> |
| 46 | #include <wtf/PointerPreparations.h> |
| 47 | #include <wtf/URL.h> |
| 48 | |
| 49 | |
| 50 | namespace WebCore { |
| 51 | using namespace JSC; |
| 52 | |
| 53 | // Functions |
| 54 | |
| 55 | JSC::EncodedJSValue JSC_HOST_CALL jsPerformancePrototypeFunctionNow(JSC::ExecState*); |
| 56 | JSC::EncodedJSValue JSC_HOST_CALL jsPerformancePrototypeFunctionGetEntries(JSC::ExecState*); |
| 57 | JSC::EncodedJSValue JSC_HOST_CALL jsPerformancePrototypeFunctionGetEntriesByType(JSC::ExecState*); |
| 58 | JSC::EncodedJSValue JSC_HOST_CALL jsPerformancePrototypeFunctionGetEntriesByName(JSC::ExecState*); |
| 59 | JSC::EncodedJSValue JSC_HOST_CALL jsPerformancePrototypeFunctionClearResourceTimings(JSC::ExecState*); |
| 60 | JSC::EncodedJSValue JSC_HOST_CALL jsPerformancePrototypeFunctionSetResourceTimingBufferSize(JSC::ExecState*); |
| 61 | JSC::EncodedJSValue JSC_HOST_CALL jsPerformancePrototypeFunctionMark(JSC::ExecState*); |
| 62 | JSC::EncodedJSValue JSC_HOST_CALL jsPerformancePrototypeFunctionClearMarks(JSC::ExecState*); |
| 63 | JSC::EncodedJSValue JSC_HOST_CALL jsPerformancePrototypeFunctionMeasure(JSC::ExecState*); |
| 64 | JSC::EncodedJSValue JSC_HOST_CALL jsPerformancePrototypeFunctionClearMeasures(JSC::ExecState*); |
| 65 | |
| 66 | // Attributes |
| 67 | |
| 68 | JSC::EncodedJSValue jsPerformanceConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 69 | bool setJSPerformanceConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 70 | JSC::EncodedJSValue jsPerformanceNavigation(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 71 | JSC::EncodedJSValue jsPerformanceTiming(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 72 | JSC::EncodedJSValue jsPerformanceOnresourcetimingbufferfull(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 73 | bool setJSPerformanceOnresourcetimingbufferfull(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 74 | |
| 75 | class JSPerformancePrototype : public JSC::JSNonFinalObject { |
| 76 | public: |
| 77 | using Base = JSC::JSNonFinalObject; |
| 78 | static JSPerformancePrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
| 79 | { |
| 80 | JSPerformancePrototype* ptr = new (NotNull, JSC::allocateCell<JSPerformancePrototype>(vm.heap)) JSPerformancePrototype(vm, globalObject, structure); |
| 81 | ptr->finishCreation(vm); |
| 82 | return ptr; |
| 83 | } |
| 84 | |
| 85 | DECLARE_INFO; |
| 86 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
| 87 | { |
| 88 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
| 89 | } |
| 90 | |
| 91 | private: |
| 92 | JSPerformancePrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| 93 | : JSC::JSNonFinalObject(vm, structure) |
| 94 | { |
| 95 | } |
| 96 | |
| 97 | void finishCreation(JSC::VM&); |
| 98 | }; |
| 99 | |
| 100 | using JSPerformanceConstructor = JSDOMConstructorNotConstructable<JSPerformance>; |
| 101 | |
| 102 | template<> JSValue JSPerformanceConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| 103 | { |
| 104 | return JSEventTarget::getConstructor(vm, &globalObject); |
| 105 | } |
| 106 | |
| 107 | template<> void JSPerformanceConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
| 108 | { |
| 109 | putDirect(vm, vm.propertyNames->prototype, JSPerformance::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 110 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("Performance"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 111 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 112 | } |
| 113 | |
| 114 | template<> const ClassInfo JSPerformanceConstructor::s_info = { "Performance" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSPerformanceConstructor) }; |
| 115 | |
| 116 | /* Hash table for prototype */ |
| 117 | |
| 118 | static const HashTableValue JSPerformancePrototypeTableValues[] = |
| 119 | { |
| 120 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsPerformanceConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSPerformanceConstructor) } }, |
| 121 | { "navigation" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsPerformanceNavigation), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 122 | { "timing" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsPerformanceTiming), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 123 | { "onresourcetimingbufferfull" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsPerformanceOnresourcetimingbufferfull), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSPerformanceOnresourcetimingbufferfull) } }, |
| 124 | { "now" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsPerformancePrototypeFunctionNow), (intptr_t) (0) } }, |
| 125 | { "getEntries" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsPerformancePrototypeFunctionGetEntries), (intptr_t) (0) } }, |
| 126 | { "getEntriesByType" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsPerformancePrototypeFunctionGetEntriesByType), (intptr_t) (1) } }, |
| 127 | { "getEntriesByName" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsPerformancePrototypeFunctionGetEntriesByName), (intptr_t) (1) } }, |
| 128 | { "clearResourceTimings" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsPerformancePrototypeFunctionClearResourceTimings), (intptr_t) (0) } }, |
| 129 | { "setResourceTimingBufferSize" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsPerformancePrototypeFunctionSetResourceTimingBufferSize), (intptr_t) (1) } }, |
| 130 | { "mark" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsPerformancePrototypeFunctionMark), (intptr_t) (1) } }, |
| 131 | { "clearMarks" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsPerformancePrototypeFunctionClearMarks), (intptr_t) (0) } }, |
| 132 | { "measure" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsPerformancePrototypeFunctionMeasure), (intptr_t) (1) } }, |
| 133 | { "clearMeasures" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsPerformancePrototypeFunctionClearMeasures), (intptr_t) (0) } }, |
| 134 | }; |
| 135 | |
| 136 | const ClassInfo JSPerformancePrototype::s_info = { "PerformancePrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSPerformancePrototype) }; |
| 137 | |
| 138 | void JSPerformancePrototype::finishCreation(VM& vm) |
| 139 | { |
| 140 | Base::finishCreation(vm); |
| 141 | reifyStaticProperties(vm, JSPerformance::info(), JSPerformancePrototypeTableValues, *this); |
| 142 | bool hasDisabledRuntimeProperties = false; |
| 143 | if (!RuntimeEnabledFeatures::sharedFeatures().performanceTimelineEnabled()) { |
| 144 | hasDisabledRuntimeProperties = true; |
| 145 | auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("getEntries" ), strlen("getEntries" )); |
| 146 | VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable); |
| 147 | JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName); |
| 148 | } |
| 149 | if (!RuntimeEnabledFeatures::sharedFeatures().performanceTimelineEnabled()) { |
| 150 | hasDisabledRuntimeProperties = true; |
| 151 | auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("getEntriesByType" ), strlen("getEntriesByType" )); |
| 152 | VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable); |
| 153 | JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName); |
| 154 | } |
| 155 | if (!RuntimeEnabledFeatures::sharedFeatures().performanceTimelineEnabled()) { |
| 156 | hasDisabledRuntimeProperties = true; |
| 157 | auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("getEntriesByName" ), strlen("getEntriesByName" )); |
| 158 | VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable); |
| 159 | JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName); |
| 160 | } |
| 161 | if (!RuntimeEnabledFeatures::sharedFeatures().resourceTimingEnabled()) { |
| 162 | hasDisabledRuntimeProperties = true; |
| 163 | auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("clearResourceTimings" ), strlen("clearResourceTimings" )); |
| 164 | VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable); |
| 165 | JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName); |
| 166 | } |
| 167 | if (!RuntimeEnabledFeatures::sharedFeatures().resourceTimingEnabled()) { |
| 168 | hasDisabledRuntimeProperties = true; |
| 169 | auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("setResourceTimingBufferSize" ), strlen("setResourceTimingBufferSize" )); |
| 170 | VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable); |
| 171 | JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName); |
| 172 | } |
| 173 | if (!RuntimeEnabledFeatures::sharedFeatures().userTimingEnabled()) { |
| 174 | hasDisabledRuntimeProperties = true; |
| 175 | auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("mark" ), strlen("mark" )); |
| 176 | VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable); |
| 177 | JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName); |
| 178 | } |
| 179 | if (!RuntimeEnabledFeatures::sharedFeatures().userTimingEnabled()) { |
| 180 | hasDisabledRuntimeProperties = true; |
| 181 | auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("clearMarks" ), strlen("clearMarks" )); |
| 182 | VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable); |
| 183 | JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName); |
| 184 | } |
| 185 | if (!RuntimeEnabledFeatures::sharedFeatures().userTimingEnabled()) { |
| 186 | hasDisabledRuntimeProperties = true; |
| 187 | auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("measure" ), strlen("measure" )); |
| 188 | VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable); |
| 189 | JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName); |
| 190 | } |
| 191 | if (!RuntimeEnabledFeatures::sharedFeatures().userTimingEnabled()) { |
| 192 | hasDisabledRuntimeProperties = true; |
| 193 | auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("clearMeasures" ), strlen("clearMeasures" )); |
| 194 | VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable); |
| 195 | JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName); |
| 196 | } |
| 197 | if (!RuntimeEnabledFeatures::sharedFeatures().resourceTimingEnabled()) { |
| 198 | hasDisabledRuntimeProperties = true; |
| 199 | auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("onresourcetimingbufferfull" ), strlen("onresourcetimingbufferfull" )); |
| 200 | VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable); |
| 201 | JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName); |
| 202 | } |
| 203 | if (hasDisabledRuntimeProperties && structure()->isDictionary()) |
| 204 | flattenDictionaryObject(vm); |
| 205 | } |
| 206 | |
| 207 | const ClassInfo JSPerformance::s_info = { "Performance" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSPerformance) }; |
| 208 | |
| 209 | JSPerformance::JSPerformance(Structure* structure, JSDOMGlobalObject& globalObject, Ref<Performance>&& impl) |
| 210 | : JSEventTarget(structure, globalObject, WTFMove(impl)) |
| 211 | { |
| 212 | } |
| 213 | |
| 214 | void JSPerformance::finishCreation(VM& vm) |
| 215 | { |
| 216 | Base::finishCreation(vm); |
| 217 | ASSERT(inherits(vm, info())); |
| 218 | |
| 219 | } |
| 220 | |
| 221 | JSObject* JSPerformance::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 222 | { |
| 223 | return JSPerformancePrototype::create(vm, &globalObject, JSPerformancePrototype::createStructure(vm, &globalObject, JSEventTarget::prototype(vm, globalObject))); |
| 224 | } |
| 225 | |
| 226 | JSObject* JSPerformance::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 227 | { |
| 228 | return getDOMPrototype<JSPerformance>(vm, globalObject); |
| 229 | } |
| 230 | |
| 231 | JSValue JSPerformance::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| 232 | { |
| 233 | return getDOMConstructor<JSPerformanceConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| 234 | } |
| 235 | |
| 236 | template<> inline JSPerformance* IDLAttribute<JSPerformance>::cast(ExecState& state, EncodedJSValue thisValue) |
| 237 | { |
| 238 | return jsDynamicCast<JSPerformance*>(state.vm(), JSValue::decode(thisValue)); |
| 239 | } |
| 240 | |
| 241 | template<> inline JSPerformance* IDLOperation<JSPerformance>::cast(ExecState& state) |
| 242 | { |
| 243 | return jsDynamicCast<JSPerformance*>(state.vm(), state.thisValue()); |
| 244 | } |
| 245 | |
| 246 | EncodedJSValue jsPerformanceConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 247 | { |
| 248 | VM& vm = state->vm(); |
| 249 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 250 | auto* prototype = jsDynamicCast<JSPerformancePrototype*>(vm, JSValue::decode(thisValue)); |
| 251 | if (UNLIKELY(!prototype)) |
| 252 | return throwVMTypeError(state, throwScope); |
| 253 | return JSValue::encode(JSPerformance::getConstructor(state->vm(), prototype->globalObject())); |
| 254 | } |
| 255 | |
| 256 | bool setJSPerformanceConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 257 | { |
| 258 | VM& vm = state->vm(); |
| 259 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 260 | auto* prototype = jsDynamicCast<JSPerformancePrototype*>(vm, JSValue::decode(thisValue)); |
| 261 | if (UNLIKELY(!prototype)) { |
| 262 | throwVMTypeError(state, throwScope); |
| 263 | return false; |
| 264 | } |
| 265 | // Shadowing a built-in constructor |
| 266 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
| 267 | } |
| 268 | |
| 269 | static inline JSValue jsPerformanceNavigationGetter(ExecState& state, JSPerformance& thisObject, ThrowScope& throwScope) |
| 270 | { |
| 271 | UNUSED_PARAM(throwScope); |
| 272 | UNUSED_PARAM(state); |
| 273 | auto& impl = thisObject.wrapped(); |
| 274 | JSValue result = toJS<IDLInterface<PerformanceNavigation>>(state, *thisObject.globalObject(), throwScope, impl.navigation()); |
| 275 | return result; |
| 276 | } |
| 277 | |
| 278 | EncodedJSValue jsPerformanceNavigation(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 279 | { |
| 280 | return IDLAttribute<JSPerformance>::get<jsPerformanceNavigationGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "navigation" ); |
| 281 | } |
| 282 | |
| 283 | static inline JSValue jsPerformanceTimingGetter(ExecState& state, JSPerformance& thisObject, ThrowScope& throwScope) |
| 284 | { |
| 285 | UNUSED_PARAM(throwScope); |
| 286 | UNUSED_PARAM(state); |
| 287 | auto& impl = thisObject.wrapped(); |
| 288 | JSValue result = toJS<IDLInterface<PerformanceTiming>>(state, *thisObject.globalObject(), throwScope, impl.timing()); |
| 289 | return result; |
| 290 | } |
| 291 | |
| 292 | EncodedJSValue jsPerformanceTiming(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 293 | { |
| 294 | return IDLAttribute<JSPerformance>::get<jsPerformanceTimingGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "timing" ); |
| 295 | } |
| 296 | |
| 297 | static inline JSValue jsPerformanceOnresourcetimingbufferfullGetter(ExecState& state, JSPerformance& thisObject, ThrowScope& throwScope) |
| 298 | { |
| 299 | UNUSED_PARAM(throwScope); |
| 300 | UNUSED_PARAM(state); |
| 301 | return eventHandlerAttribute(thisObject.wrapped(), eventNames().resourcetimingbufferfullEvent, worldForDOMObject(thisObject)); |
| 302 | } |
| 303 | |
| 304 | EncodedJSValue jsPerformanceOnresourcetimingbufferfull(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 305 | { |
| 306 | return IDLAttribute<JSPerformance>::get<jsPerformanceOnresourcetimingbufferfullGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onresourcetimingbufferfull" ); |
| 307 | } |
| 308 | |
| 309 | static inline bool setJSPerformanceOnresourcetimingbufferfullSetter(ExecState& state, JSPerformance& thisObject, JSValue value, ThrowScope& throwScope) |
| 310 | { |
| 311 | UNUSED_PARAM(throwScope); |
| 312 | setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().resourcetimingbufferfullEvent, value); |
| 313 | return true; |
| 314 | } |
| 315 | |
| 316 | bool setJSPerformanceOnresourcetimingbufferfull(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 317 | { |
| 318 | return IDLAttribute<JSPerformance>::set<setJSPerformanceOnresourcetimingbufferfullSetter>(*state, thisValue, encodedValue, "onresourcetimingbufferfull" ); |
| 319 | } |
| 320 | |
| 321 | static inline JSC::EncodedJSValue jsPerformancePrototypeFunctionNowBody(JSC::ExecState* state, typename IDLOperation<JSPerformance>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 322 | { |
| 323 | UNUSED_PARAM(state); |
| 324 | UNUSED_PARAM(throwScope); |
| 325 | auto& impl = castedThis->wrapped(); |
| 326 | return JSValue::encode(toJS<IDLDouble>(impl.now())); |
| 327 | } |
| 328 | |
| 329 | EncodedJSValue JSC_HOST_CALL jsPerformancePrototypeFunctionNow(ExecState* state) |
| 330 | { |
| 331 | return IDLOperation<JSPerformance>::call<jsPerformancePrototypeFunctionNowBody>(*state, "now" ); |
| 332 | } |
| 333 | |
| 334 | static inline JSC::EncodedJSValue jsPerformancePrototypeFunctionGetEntriesBody(JSC::ExecState* state, typename IDLOperation<JSPerformance>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 335 | { |
| 336 | UNUSED_PARAM(state); |
| 337 | UNUSED_PARAM(throwScope); |
| 338 | auto& impl = castedThis->wrapped(); |
| 339 | return JSValue::encode(toJS<IDLSequence<IDLInterface<PerformanceEntry>>>(*state, *castedThis->globalObject(), impl.getEntries())); |
| 340 | } |
| 341 | |
| 342 | EncodedJSValue JSC_HOST_CALL jsPerformancePrototypeFunctionGetEntries(ExecState* state) |
| 343 | { |
| 344 | return IDLOperation<JSPerformance>::call<jsPerformancePrototypeFunctionGetEntriesBody>(*state, "getEntries" ); |
| 345 | } |
| 346 | |
| 347 | static inline JSC::EncodedJSValue jsPerformancePrototypeFunctionGetEntriesByTypeBody(JSC::ExecState* state, typename IDLOperation<JSPerformance>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 348 | { |
| 349 | UNUSED_PARAM(state); |
| 350 | UNUSED_PARAM(throwScope); |
| 351 | auto& impl = castedThis->wrapped(); |
| 352 | if (UNLIKELY(state->argumentCount() < 1)) |
| 353 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| 354 | auto entryType = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
| 355 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 356 | return JSValue::encode(toJS<IDLSequence<IDLInterface<PerformanceEntry>>>(*state, *castedThis->globalObject(), impl.getEntriesByType(WTFMove(entryType)))); |
| 357 | } |
| 358 | |
| 359 | EncodedJSValue JSC_HOST_CALL jsPerformancePrototypeFunctionGetEntriesByType(ExecState* state) |
| 360 | { |
| 361 | return IDLOperation<JSPerformance>::call<jsPerformancePrototypeFunctionGetEntriesByTypeBody>(*state, "getEntriesByType" ); |
| 362 | } |
| 363 | |
| 364 | static inline JSC::EncodedJSValue jsPerformancePrototypeFunctionGetEntriesByNameBody(JSC::ExecState* state, typename IDLOperation<JSPerformance>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 365 | { |
| 366 | UNUSED_PARAM(state); |
| 367 | UNUSED_PARAM(throwScope); |
| 368 | auto& impl = castedThis->wrapped(); |
| 369 | if (UNLIKELY(state->argumentCount() < 1)) |
| 370 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| 371 | auto name = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
| 372 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 373 | auto entryType = state->argument(1).isUndefined() ? String() : convert<IDLDOMString>(*state, state->uncheckedArgument(1)); |
| 374 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 375 | return JSValue::encode(toJS<IDLSequence<IDLInterface<PerformanceEntry>>>(*state, *castedThis->globalObject(), impl.getEntriesByName(WTFMove(name), WTFMove(entryType)))); |
| 376 | } |
| 377 | |
| 378 | EncodedJSValue JSC_HOST_CALL jsPerformancePrototypeFunctionGetEntriesByName(ExecState* state) |
| 379 | { |
| 380 | return IDLOperation<JSPerformance>::call<jsPerformancePrototypeFunctionGetEntriesByNameBody>(*state, "getEntriesByName" ); |
| 381 | } |
| 382 | |
| 383 | static inline JSC::EncodedJSValue jsPerformancePrototypeFunctionClearResourceTimingsBody(JSC::ExecState* state, typename IDLOperation<JSPerformance>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 384 | { |
| 385 | UNUSED_PARAM(state); |
| 386 | UNUSED_PARAM(throwScope); |
| 387 | auto& impl = castedThis->wrapped(); |
| 388 | impl.clearResourceTimings(); |
| 389 | return JSValue::encode(jsUndefined()); |
| 390 | } |
| 391 | |
| 392 | EncodedJSValue JSC_HOST_CALL jsPerformancePrototypeFunctionClearResourceTimings(ExecState* state) |
| 393 | { |
| 394 | return IDLOperation<JSPerformance>::call<jsPerformancePrototypeFunctionClearResourceTimingsBody>(*state, "clearResourceTimings" ); |
| 395 | } |
| 396 | |
| 397 | static inline JSC::EncodedJSValue jsPerformancePrototypeFunctionSetResourceTimingBufferSizeBody(JSC::ExecState* state, typename IDLOperation<JSPerformance>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 398 | { |
| 399 | UNUSED_PARAM(state); |
| 400 | UNUSED_PARAM(throwScope); |
| 401 | auto& impl = castedThis->wrapped(); |
| 402 | if (UNLIKELY(state->argumentCount() < 1)) |
| 403 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| 404 | auto maxSize = convert<IDLUnsignedLong>(*state, state->uncheckedArgument(0)); |
| 405 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 406 | impl.setResourceTimingBufferSize(WTFMove(maxSize)); |
| 407 | return JSValue::encode(jsUndefined()); |
| 408 | } |
| 409 | |
| 410 | EncodedJSValue JSC_HOST_CALL jsPerformancePrototypeFunctionSetResourceTimingBufferSize(ExecState* state) |
| 411 | { |
| 412 | return IDLOperation<JSPerformance>::call<jsPerformancePrototypeFunctionSetResourceTimingBufferSizeBody>(*state, "setResourceTimingBufferSize" ); |
| 413 | } |
| 414 | |
| 415 | static inline JSC::EncodedJSValue jsPerformancePrototypeFunctionMarkBody(JSC::ExecState* state, typename IDLOperation<JSPerformance>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 416 | { |
| 417 | UNUSED_PARAM(state); |
| 418 | UNUSED_PARAM(throwScope); |
| 419 | auto& impl = castedThis->wrapped(); |
| 420 | if (UNLIKELY(state->argumentCount() < 1)) |
| 421 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| 422 | auto markName = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
| 423 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 424 | propagateException(*state, throwScope, impl.mark(WTFMove(markName))); |
| 425 | return JSValue::encode(jsUndefined()); |
| 426 | } |
| 427 | |
| 428 | EncodedJSValue JSC_HOST_CALL jsPerformancePrototypeFunctionMark(ExecState* state) |
| 429 | { |
| 430 | return IDLOperation<JSPerformance>::call<jsPerformancePrototypeFunctionMarkBody>(*state, "mark" ); |
| 431 | } |
| 432 | |
| 433 | static inline JSC::EncodedJSValue jsPerformancePrototypeFunctionClearMarksBody(JSC::ExecState* state, typename IDLOperation<JSPerformance>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 434 | { |
| 435 | UNUSED_PARAM(state); |
| 436 | UNUSED_PARAM(throwScope); |
| 437 | auto& impl = castedThis->wrapped(); |
| 438 | auto markName = state->argument(0).isUndefined() ? String() : convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
| 439 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 440 | impl.clearMarks(WTFMove(markName)); |
| 441 | return JSValue::encode(jsUndefined()); |
| 442 | } |
| 443 | |
| 444 | EncodedJSValue JSC_HOST_CALL jsPerformancePrototypeFunctionClearMarks(ExecState* state) |
| 445 | { |
| 446 | return IDLOperation<JSPerformance>::call<jsPerformancePrototypeFunctionClearMarksBody>(*state, "clearMarks" ); |
| 447 | } |
| 448 | |
| 449 | static inline JSC::EncodedJSValue jsPerformancePrototypeFunctionMeasureBody(JSC::ExecState* state, typename IDLOperation<JSPerformance>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 450 | { |
| 451 | UNUSED_PARAM(state); |
| 452 | UNUSED_PARAM(throwScope); |
| 453 | auto& impl = castedThis->wrapped(); |
| 454 | if (UNLIKELY(state->argumentCount() < 1)) |
| 455 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| 456 | auto measureName = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
| 457 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 458 | auto startMark = state->argument(1).isUndefined() ? String() : convert<IDLDOMString>(*state, state->uncheckedArgument(1)); |
| 459 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 460 | auto endMark = state->argument(2).isUndefined() ? String() : convert<IDLDOMString>(*state, state->uncheckedArgument(2)); |
| 461 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 462 | propagateException(*state, throwScope, impl.measure(WTFMove(measureName), WTFMove(startMark), WTFMove(endMark))); |
| 463 | return JSValue::encode(jsUndefined()); |
| 464 | } |
| 465 | |
| 466 | EncodedJSValue JSC_HOST_CALL jsPerformancePrototypeFunctionMeasure(ExecState* state) |
| 467 | { |
| 468 | return IDLOperation<JSPerformance>::call<jsPerformancePrototypeFunctionMeasureBody>(*state, "measure" ); |
| 469 | } |
| 470 | |
| 471 | static inline JSC::EncodedJSValue jsPerformancePrototypeFunctionClearMeasuresBody(JSC::ExecState* state, typename IDLOperation<JSPerformance>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 472 | { |
| 473 | UNUSED_PARAM(state); |
| 474 | UNUSED_PARAM(throwScope); |
| 475 | auto& impl = castedThis->wrapped(); |
| 476 | auto measureName = state->argument(0).isUndefined() ? String() : convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
| 477 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 478 | impl.clearMeasures(WTFMove(measureName)); |
| 479 | return JSValue::encode(jsUndefined()); |
| 480 | } |
| 481 | |
| 482 | EncodedJSValue JSC_HOST_CALL jsPerformancePrototypeFunctionClearMeasures(ExecState* state) |
| 483 | { |
| 484 | return IDLOperation<JSPerformance>::call<jsPerformancePrototypeFunctionClearMeasuresBody>(*state, "clearMeasures" ); |
| 485 | } |
| 486 | |
| 487 | void JSPerformance::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
| 488 | { |
| 489 | auto* thisObject = jsCast<JSPerformance*>(cell); |
| 490 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
| 491 | if (thisObject->scriptExecutionContext()) |
| 492 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
| 493 | Base::heapSnapshot(cell, builder); |
| 494 | } |
| 495 | |
| 496 | bool JSPerformanceOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
| 497 | { |
| 498 | auto* jsPerformance = jsCast<JSPerformance*>(handle.slot()->asCell()); |
| 499 | if (jsPerformance->wrapped().isFiringEventListeners()) { |
| 500 | if (UNLIKELY(reason)) |
| 501 | *reason = "EventTarget firing event listeners" ; |
| 502 | return true; |
| 503 | } |
| 504 | ScriptExecutionContext* root = WTF::getPtr(jsPerformance->wrapped().scriptExecutionContext()); |
| 505 | if (!root) |
| 506 | return false; |
| 507 | if (UNLIKELY(reason)) |
| 508 | *reason = "Reachable from ScriptExecutionContext" ; |
| 509 | return visitor.containsOpaqueRoot(root); |
| 510 | } |
| 511 | |
| 512 | void JSPerformanceOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
| 513 | { |
| 514 | auto* jsPerformance = static_cast<JSPerformance*>(handle.slot()->asCell()); |
| 515 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
| 516 | uncacheWrapper(world, &jsPerformance->wrapped(), jsPerformance); |
| 517 | } |
| 518 | |
| 519 | #if ENABLE(BINDING_INTEGRITY) |
| 520 | #if PLATFORM(WIN) |
| 521 | #pragma warning(disable: 4483) |
| 522 | extern "C" { extern void (*const __identifier("??_7Performance@WebCore@@6B@" )[])(); } |
| 523 | #else |
| 524 | extern "C" { extern void* _ZTVN7WebCore11PerformanceE[]; } |
| 525 | #endif |
| 526 | #endif |
| 527 | |
| 528 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<Performance>&& impl) |
| 529 | { |
| 530 | |
| 531 | #if ENABLE(BINDING_INTEGRITY) |
| 532 | void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr())); |
| 533 | #if PLATFORM(WIN) |
| 534 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7Performance@WebCore@@6B@" )); |
| 535 | #else |
| 536 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore11PerformanceE[2]); |
| 537 | #endif |
| 538 | |
| 539 | // If this fails Performance does not have a vtable, so you need to add the |
| 540 | // ImplementationLacksVTable attribute to the interface definition |
| 541 | static_assert(std::is_polymorphic<Performance>::value, "Performance is not polymorphic" ); |
| 542 | |
| 543 | // If you hit this assertion you either have a use after free bug, or |
| 544 | // Performance has subclasses. If Performance has subclasses that get passed |
| 545 | // to toJS() we currently require Performance you to opt out of binding hardening |
| 546 | // by adding the SkipVTableValidation attribute to the interface IDL definition |
| 547 | RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer); |
| 548 | #endif |
| 549 | return createWrapper<Performance>(globalObject, WTFMove(impl)); |
| 550 | } |
| 551 | |
| 552 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, Performance& impl) |
| 553 | { |
| 554 | return wrap(state, globalObject, impl); |
| 555 | } |
| 556 | |
| 557 | Performance* JSPerformance::toWrapped(JSC::VM& vm, JSC::JSValue value) |
| 558 | { |
| 559 | if (auto* wrapper = jsDynamicCast<JSPerformance*>(vm, value)) |
| 560 | return &wrapper->wrapped(); |
| 561 | return nullptr; |
| 562 | } |
| 563 | |
| 564 | } |
| 565 | |