WebCoreTestSupport.cpp [plain text]
#include "config.h"
#include "WebCoreTestSupport.h"
#include "Frame.h"
#include "InternalSettings.h"
#include "Internals.h"
#include "JSDocument.h"
#include "JSInternals.h"
#include "Page.h"
#include "WheelEventTestTrigger.h"
#include <JavaScriptCore/APICast.h>
#include <JavaScriptCore/JSValueRef.h>
#include <JavaScriptCore/Profile.h>
#include <interpreter/CallFrame.h>
#include <runtime/IdentifierInlines.h>
using namespace JSC;
using namespace WebCore;
namespace WebCoreTestSupport {
void injectInternalsObject(JSContextRef context)
{
ExecState* exec = toJS(context);
JSLockHolder lock(exec);
JSDOMGlobalObject* globalObject = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject());
ScriptExecutionContext* scriptContext = globalObject->scriptExecutionContext();
if (is<Document>(*scriptContext))
globalObject->putDirect(exec->vm(), Identifier::fromString(exec, Internals::internalsId), toJS(exec, globalObject, Internals::create(downcast<Document>(scriptContext))));
}
void resetInternalsObject(JSContextRef context)
{
ExecState* exec = toJS(context);
JSLockHolder lock(exec);
JSDOMGlobalObject* globalObject = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject());
ScriptExecutionContext* scriptContext = globalObject->scriptExecutionContext();
Page* page = downcast<Document>(scriptContext)->frame()->page();
Internals::resetToConsistentState(page);
InternalSettings::from(page)->resetToConsistentState();
}
void monitorWheelEvents(WebCore::Frame& frame)
{
Page* page = frame.page();
if (!page)
return;
page->ensureTestTrigger();
}
void setTestCallbackAndStartNotificationTimer(WebCore::Frame& frame, JSContextRef context, JSObjectRef jsCallbackFunction)
{
Page* page = frame.page();
if (!page || !page->expectsWheelEventTriggers())
return;
JSValueProtect(context, jsCallbackFunction);
page->ensureTestTrigger().setTestCallbackAndStartNotificationTimer([=](void) {
JSObjectCallAsFunction(context, jsCallbackFunction, nullptr, 0, nullptr, nullptr);
JSValueUnprotect(context, jsCallbackFunction);
});
}
void clearWheelEventTestTrigger(WebCore::Frame& frame)
{
Page* page = frame.page();
if (!page)
return;
page->clearTrigger();
}
}