Bug 686002 - Refactor WeakMap class initialization. r=bhackett
authorJeff Walden <jwalden@mit.edu>
Wed, 04 May 2011 16:54:24 -0400
changeset 78914 81329dc0ac9123654406d375d96605117438ce80
parent 78913 621b2adf85114828897c22748bb013b1e8d3db67
child 78915 66736ca9c8c381f7bf9e2a8b67bb492c1b55398e
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbhackett
bugs686002
milestone9.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 686002 - Refactor WeakMap class initialization. r=bhackett
js/src/jsweakmap.cpp
--- a/js/src/jsweakmap.cpp
+++ b/js/src/jsweakmap.cpp
@@ -44,16 +44,18 @@
 #include "jscntxt.h"
 #include "jsgc.h"
 #include "jshashtable.h"
 #include "jsobj.h"
 #include "jsgc.h"
 #include "jsgcmark.h"
 #include "jsweakmap.h"
 
+#include "vm/GlobalObject.h"
+
 #include "jsgcinlines.h"
 #include "jsobjinlines.h"
 
 using namespace js;
 
 namespace js {
 
 bool
@@ -285,17 +287,32 @@ static JSFunctionSpec weak_map_methods[]
     JS_FN("delete", WeakMap_delete, 1, 0),
     JS_FN("set",    WeakMap_set, 2, 0),
     JS_FS_END
 };
 
 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;
 }