Bug 777385 - Support (some) Paris bindings objects as weak map keys. r=peterv

This adds support for many kinds of Paris bindings objects as weak map keys.
This patch supports nsISupports objects as well as non-cycle-collected
non-nsISupports objects. What is needed for support is to preserve any wrapper,
if the object is wrapper cached. In other cases, we don't need to do anything.
This commit is contained in:
Andrew McCreight
2012-11-09 10:59:02 -08:00
parent 4f85369fd9
commit 6c50b4a672
7 changed files with 155 additions and 19 deletions

View File

@@ -291,7 +291,10 @@ WeakMap_set_impl(JSContext *cx, CallArgs args)
}
// Preserve wrapped native keys to prevent wrapper optimization.
if (key->getClass()->ext.isWrappedNative) {
if (key->getClass()->ext.isWrappedNative ||
(key->getClass()->flags & JSCLASS_IS_DOMJSCLASS) ||
(key->isProxy() && GetProxyHandler(key)->family() == GetListBaseHandlerFamily()))
{
JS_ASSERT(cx->runtime->preserveWrapperCallback);
if (!cx->runtime->preserveWrapperCallback(cx, key)) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_WEAKMAP_KEY);