JSInspectedObjectWrapper::JSInspectedObjectWrapper(ExecState* unwrappedExec, JSObject* unwrappedObject, JSValue* wrappedPrototype)
    : JSQuarantinedObjectWrapper(unwrappedExec, unwrappedObject, wrappedPrototype)
{
    WrapperMap* wrapperMap = wrappers().get(unwrappedGlobalObject());
    if (!wrapperMap) {
        wrapperMap = new WrapperMap;
        wrappers().set(unwrappedGlobalObject(), wrapperMap);
    }

    ASSERT(!wrapperMap->contains(unwrappedObject));
    wrapperMap->set(unwrappedObject, this);
}
JSInspectedObjectWrapper::~JSInspectedObjectWrapper()
{
    ASSERT(wrappers().contains(unwrappedGlobalObject()));
    WrapperMap* wrapperMap = wrappers().get(unwrappedGlobalObject());

    ASSERT(wrapperMap->contains(unwrappedObject()));
    wrapperMap->remove(unwrappedObject());

    if (wrapperMap->isEmpty()) {
        wrappers().remove(unwrappedGlobalObject());
        delete wrapperMap;
    }
}
Beispiel #3
0
static std::vector<Ptr<InfEngineBackendWrapper> >
infEngineWrappers(const std::vector<Ptr<BackendWrapper> >& ptrs)
{
    std::vector<Ptr<InfEngineBackendWrapper> > wrappers(ptrs.size());
    for (int i = 0; i < ptrs.size(); ++i)
    {
        CV_Assert(!ptrs[i].empty());
        wrappers[i] = ptrs[i].dynamicCast<InfEngineBackendWrapper>();
        CV_Assert(!wrappers[i].empty());
    }
    return wrappers;
}
JSValue* JSInspectedObjectWrapper::wrap(ExecState* unwrappedExec, JSValue* unwrappedValue)
{
    if (!unwrappedValue->isObject())
        return unwrappedValue;

    JSObject* unwrappedObject = static_cast<JSObject*>(unwrappedValue);

    if (unwrappedObject->inherits(&JSInspectedObjectWrapper::s_info))
        return unwrappedObject;

    if (WrapperMap* wrapperMap = wrappers().get(unwrappedExec->dynamicGlobalObject()))
        if (JSInspectedObjectWrapper* wrapper = wrapperMap->get(unwrappedObject))
            return wrapper;

    JSValue* prototype = unwrappedObject->prototype();
    JSValue* wrappedPrototype = prototype ? wrap(unwrappedExec, prototype) : 0;

    return new (unwrappedExec) JSInspectedObjectWrapper(unwrappedExec, unwrappedObject, wrappedPrototype);
}