WebCoreTestSupport.cpp [plain text]
#include "config.h"
#include "WebCoreTestSupport.h"
#include "Internals.h"
#include "JSDocument.h"
#include "JSInternals.h"
#include <JavaScriptCore/APICast.h>
#include <interpreter/CallFrame.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();
Document* document = scriptContext->isDocument() ? static_cast<Document*>(scriptContext) : 0;
globalObject->putDirect(exec->globalData(), Identifier(exec, Internals::internalsId), toJS(exec, globalObject, Internals::create(document)));
}
void resetInternalsObject(JSContextRef context)
{
ExecState* exec = toJS(context);
JSLockHolder lock(exec);
JSDOMGlobalObject* globalObject = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject());
JSValue internalsJS = globalObject->getDirect(exec->globalData(), Identifier(exec, Internals::internalsId));
if (internalsJS.isNull() || internalsJS.isEmpty())
return;
if (Internals* internals = toInternals(internalsJS)) {
ScriptExecutionContext* scriptContext = globalObject->scriptExecutionContext();
if (scriptContext->isDocument())
internals->reset(static_cast<Document*>(scriptContext));
}
}
}