JSWeakObjectMapRefPrivate.cpp [plain text]
#include "config.h"
#include "JSWeakObjectMapRefPrivate.h"
#include "APICast.h"
#include "APIShims.h"
#include "JSCallbackObject.h"
#include "JSValue.h"
#include "JSWeakObjectMapRefInternal.h"
#include <wtf/HashMap.h>
#include <wtf/text/StringHash.h>
using namespace WTF;
using namespace JSC;
#ifdef __cplusplus
extern "C" {
#endif
JSWeakObjectMapRef JSWeakObjectMapCreate(JSContextRef context, void* privateData, JSWeakMapDestroyedCallback callback)
{
ExecState* exec = toJS(context);
APIEntryShim entryShim(exec);
RefPtr<OpaqueJSWeakObjectMap> map = OpaqueJSWeakObjectMap::create(privateData, callback);
exec->lexicalGlobalObject()->registerWeakMap(map.get());
return map.get();
}
void JSWeakObjectMapSet(JSContextRef ctx, JSWeakObjectMapRef map, void* key, JSObjectRef object)
{
ExecState* exec = toJS(ctx);
APIEntryShim entryShim(exec);
JSObject* obj = toJS(object);
if (!obj)
return;
ASSERT(obj->inherits(&JSCallbackObject<JSGlobalObject>::s_info) || obj->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::s_info));
map->map().set(exec->globalData(), key, obj);
}
JSObjectRef JSWeakObjectMapGet(JSContextRef ctx, JSWeakObjectMapRef map, void* key)
{
ExecState* exec = toJS(ctx);
APIEntryShim entryShim(exec);
return toRef(static_cast<JSObject*>(map->map().get(key)));
}
void JSWeakObjectMapRemove(JSContextRef ctx, JSWeakObjectMapRef map, void* key)
{
ExecState* exec = toJS(ctx);
APIEntryShim entryShim(exec);
map->map().take(key);
}
JS_EXPORT bool JSWeakObjectMapClear(JSContextRef, JSWeakObjectMapRef, void*, JSObjectRef);
bool JSWeakObjectMapClear(JSContextRef, JSWeakObjectMapRef, void*, JSObjectRef)
{
return true;
}
#ifdef __cplusplus
}
#endif