Bug 688277, part 1 - add JS friend API to get keys of a weak map. r=jorendorff

This commit is contained in:
Andrew McCreight
2011-10-13 09:33:39 -07:00
parent 7fb4a4362f
commit 5bba2c43dd
3 changed files with 32 additions and 1 deletions

View File

@@ -42,6 +42,7 @@
#include <string.h>
#include "jsapi.h"
#include "jscntxt.h"
#include "jsfriendapi.h"
#include "jsgc.h"
#include "jsobj.h"
#include "jsgc.h"
@@ -232,6 +233,27 @@ WeakMap_set(JSContext *cx, uintN argc, Value *vp)
return false;
}
JS_FRIEND_API(JSBool)
JS_NondeterministicGetWeakMapKeys(JSContext *cx, JSObject *obj, JSObject **ret)
{
if (!obj || !obj->isWeakMap()) {
*ret = NULL;
return true;
}
JSObject *arr = NewDenseEmptyArray(cx);
if (!arr)
return false;
ObjectValueMap *map = GetObjectMap(obj);
if (map) {
for (ObjectValueMap::Range r = map->nondeterministicAll(); !r.empty(); r.popFront()) {
if (!js_NewbornArrayPush(cx, arr, ObjectValue(*r.front().key)))
return false;
}
}
*ret = arr;
return true;
}
static void
WeakMap_mark(JSTracer *trc, JSObject *obj)
{