From 8a53b658180852a137988589b48e12dcc03d4825 Mon Sep 17 00:00:00 2001 From: Jeff Walden Date: Wed, 4 May 2011 16:54:24 -0400 Subject: [PATCH] Bug 686002 - Refactor WeakMap class initialization. r=bhackett --HG-- extra : rebase_source : cccef99e3ed5b084fa28bb59a1338ca6e7045e54 --- js/src/jsweakmap.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/js/src/jsweakmap.cpp b/js/src/jsweakmap.cpp index aae824f51e7c..00fbdd0f3907 100644 --- a/js/src/jsweakmap.cpp +++ b/js/src/jsweakmap.cpp @@ -49,6 +49,8 @@ #include "jsgcmark.h" #include "jsweakmap.h" +#include "vm/GlobalObject.h" + #include "jsgcinlines.h" #include "jsobjinlines.h" @@ -290,12 +292,27 @@ static JSFunctionSpec weak_map_methods[] = { JSObject * js_InitWeakMapClass(JSContext *cx, JSObject *obj) { - JSObject *proto = js_InitClass(cx, obj, NULL, &WeakMapClass, WeakMap_construct, 0, - NULL, weak_map_methods, NULL, NULL); - if (!proto) + JS_ASSERT(obj->isNative()); + + GlobalObject *global = obj->asGlobal(); + + JSObject *weakMapProto = global->createBlankPrototype(cx, &WeakMapClass); + if (!weakMapProto) + return NULL; + weakMapProto->setPrivate(NULL); + + JSFunction *ctor = global->createConstructor(cx, WeakMap_construct, &WeakMapClass, + CLASS_ATOM(cx, WeakMap), 0); + if (!ctor) return NULL; - proto->setPrivate(NULL); + if (!LinkConstructorAndPrototype(cx, ctor, weakMapProto)) + return NULL; - return proto; + if (!DefinePropertiesAndBrand(cx, weakMapProto, NULL, weak_map_methods)) + return NULL; + + if (!DefineConstructorAndPrototype(cx, global, JSProto_WeakMap, ctor, weakMapProto)) + return NULL; + return weakMapProto; }