Bug 680937, part 2 - Add native wrapper preservation hook, call it in WeakMap_set. r=billm

This commit is contained in:
Andrew McCreight
2011-12-15 17:45:21 -08:00
parent 611268b266
commit fa01f822af
6 changed files with 62 additions and 23 deletions

View File

@@ -233,6 +233,15 @@ WeakMap_set(JSContext *cx, uintN argc, Value *vp)
if (!map->put(key, value))
goto out_of_memory;
// Preserve wrapped native keys to prevent wrapper optimization.
if (key->getClass()->ext.isWrappedNative) {
if (!cx->runtime->preserveWrapperCallback ||
!cx->runtime->preserveWrapperCallback(cx, key)) {
JS_ReportWarning(cx, "Failed to preserve wrapper of wrapped native weak map key.");
}
}
args.rval().setUndefined();
return true;