JSInspectorCallbackWrapper.cpp [plain text]
#include "config.h"
#include "JSInspectorCallbackWrapper.h"
#include "JSInspectedObjectWrapper.h"
#include <wtf/StdLibExtras.h>
using namespace JSC;
namespace WebCore {
ASSERT_CLASS_FITS_IN_CELL(JSInspectorCallbackWrapper);
typedef HashMap<JSObject*, JSInspectorCallbackWrapper*> WrapperMap;
static WrapperMap& wrappers()
{
DEFINE_STATIC_LOCAL(WrapperMap, map, ());
return map;
}
const ClassInfo JSInspectorCallbackWrapper::s_info = { "JSInspectorCallbackWrapper", &JSQuarantinedObjectWrapper::s_info, 0, 0 };
static Structure* leakInspectorCallbackWrapperStructure()
{
Structure::startIgnoringLeaks();
Structure* structure = JSInspectorCallbackWrapper::createStructure(jsNull()).releaseRef();
Structure::stopIgnoringLeaks();
return structure;
}
JSValue JSInspectorCallbackWrapper::wrap(ExecState* unwrappedExec, JSValue unwrappedValue)
{
if (!unwrappedValue.isObject())
return unwrappedValue;
JSObject* unwrappedObject = asObject(unwrappedValue);
if (unwrappedObject->inherits(&JSInspectorCallbackWrapper::s_info))
return unwrappedObject;
if (JSInspectorCallbackWrapper* wrapper = wrappers().get(unwrappedObject))
return wrapper;
JSValue prototype = unwrappedObject->prototype();
ASSERT(prototype.isNull() || prototype.isObject());
if (prototype.isNull()) {
static Structure* structure = leakInspectorCallbackWrapperStructure();
return new (unwrappedExec) JSInspectorCallbackWrapper(unwrappedExec, unwrappedObject, structure);
}
return new (unwrappedExec) JSInspectorCallbackWrapper(unwrappedExec, unwrappedObject, asObject(wrap(unwrappedExec, prototype))->inheritorID());
}
JSInspectorCallbackWrapper::JSInspectorCallbackWrapper(ExecState* unwrappedExec, JSObject* unwrappedObject, PassRefPtr<Structure> structure)
: JSQuarantinedObjectWrapper(unwrappedExec, unwrappedObject, structure)
{
ASSERT(!wrappers().contains(unwrappedObject));
wrappers().set(unwrappedObject, this);
}
JSInspectorCallbackWrapper::~JSInspectorCallbackWrapper()
{
wrappers().remove(unwrappedObject());
}
JSValue JSInspectorCallbackWrapper::prepareIncomingValue(ExecState* unwrappedExec, JSValue unwrappedValue) const
{
if (JSQuarantinedObjectWrapper* wrapper = asWrapper(unwrappedValue)) {
ASSERT_WITH_MESSAGE(wrapper == this, "A different wrapper was passed into a JSInspectorCallbackWrapper");
if (wrapper != this)
return jsUndefined();
return wrapper->unwrappedObject();
}
return JSInspectedObjectWrapper::wrap(unwrappedExec, unwrappedValue);
}
}