Bug 898623 - Root StructType FieldInfo properties. r=terrence
authorNikhil Marathe <nsm.nikhil@gmail.com>
Fri, 26 Jul 2013 16:21:53 -0700
changeset 140274 318216ea648d6acfee79c017517c3edba1c03af9
parent 140273 1bb4b1eba285fd3074140b1af90b62e22502254f
child 140275 a8b32e58a5484f5e8d589848901ebb017df6301a
push id25023
push useremorley@mozilla.com
push dateMon, 29 Jul 2013 14:13:44 +0000
treeherdermozilla-central@8c89fe2a5c92 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs898623
milestone25.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 898623 - Root StructType FieldInfo properties. r=terrence
js/src/builtin/BinaryData.cpp
js/src/builtin/BinaryData.h
--- a/js/src/builtin/BinaryData.cpp
+++ b/js/src/builtin/BinaryData.cpp
@@ -10,16 +10,17 @@
 
 #include "mozilla/FloatingPoint.h"
 
 #include "jscompartment.h"
 #include "jsfun.h"
 #include "jsobj.h"
 #include "jsutil.h"
 
+#include "gc/Marking.h"
 #include "vm/TypedArrayObject.h"
 #include "vm/String.h"
 #include "vm/StringBuffer.h"
 #include "vm/GlobalObject.h"
 
 #include "jsatominlines.h"
 #include "jsobjinlines.h"
 
@@ -176,19 +177,26 @@ GetAlign(JSContext *cx, HandleObject typ
     JS_ASSERT(&NumericTypeClasses[NUMERICTYPE_UINT8] <= type->getClass() &&
               type->getClass() <= &NumericTypeClasses[NUMERICTYPE_FLOAT64]);
     JSObject::getProperty(cx, typeObj, typeObj, cx->names().bytes, &val);
     return val.toInt32();
 }
 
 struct FieldInfo
 {
-    jsid name;
-    JSObject *type;
+    HeapId name;
+    HeapPtrObject type;
     size_t offset;
+
+    FieldInfo() : offset(0) {}
+
+    FieldInfo(const FieldInfo &o)
+        : name(o.name.get()), type(o.type), offset(o.offset)
+    {
+    }
 };
 
 Class js::DataClass = {
     "Data",
     JSCLASS_HAS_CACHED_PROTO(JSProto_Data),
     JS_PropertyStub,
     JS_DeletePropertyStub,
     JS_PropertyStub,
@@ -257,17 +265,17 @@ IsSameStructType(JSContext *cx, HandleOb
     if (fieldList1->size() != fieldList2->size())
         return false;
 
     // Names and layout should be the same.
     for (uint32_t i = 0; i < fieldList1->size(); ++i) {
         FieldInfo fieldInfo1 = fieldList1->at(i);
         FieldInfo fieldInfo2 = fieldList2->at(i);
 
-        if (fieldInfo1.name != fieldInfo2.name)
+        if (fieldInfo1.name.get() != fieldInfo2.name.get())
             return false;
 
         if (fieldInfo1.offset != fieldInfo2.offset)
             return false;
 
         RootedObject fieldType1(cx, fieldInfo1.type);
         RootedObject fieldType2(cx, fieldInfo2.type);
         if (!IsSameBinaryDataType(cx, fieldType1, fieldType2))
@@ -1422,21 +1430,21 @@ Class StructType::class_ = {
     JS_PropertyStub,
     JS_DeletePropertyStub,
     JS_PropertyStub,
     JS_StrictPropertyStub,
     JS_EnumerateStub,
     JS_ResolveStub,
     JS_ConvertStub,
     StructType::finalize,
-    NULL,
-    NULL,
-    NULL,
+    NULL, /* checkAccess */
+    NULL, /* call */
+    NULL, /* hasInstance */
     BinaryStruct::construct,
-    NULL
+    StructType::trace
 };
 
 Class BinaryStruct::class_ = {
     "BinaryStruct",
     Class::NON_NATIVE |
     JSCLASS_HAS_RESERVED_SLOTS(BLOCK_RESERVED_SLOTS) |
     JSCLASS_HAS_PRIVATE |
     JSCLASS_HAS_CACHED_PROTO(JSProto_StructType),
@@ -1445,18 +1453,18 @@ Class BinaryStruct::class_ = {
     JS_PropertyStub,
     JS_StrictPropertyStub,
     JS_EnumerateStub,
     JS_ResolveStub,
     JS_ConvertStub,
     BinaryStruct::finalize,
     NULL,           /* checkAccess */
     NULL,           /* call        */
+    NULL,           /* hasInstance */
     NULL,           /* construct   */
-    NULL,           /* hasInstance */
     BinaryStruct::obj_trace,
     JS_NULL_CLASS_EXT,
     {
         NULL, /* lookupGeneric */
         NULL, /* lookupProperty */
         NULL, /* lookupElement */
         NULL, /* lookupSpecial */
         NULL, /* defineGeneric */
@@ -1685,16 +1693,27 @@ StructType::construct(JSContext *cx, uns
 
 void
 StructType::finalize(FreeOp *op, JSObject *obj)
 {
     FieldList *list = static_cast<FieldList *>(obj->getPrivate());
     delete list;
 }
 
+void
+StructType::trace(JSTracer *tracer, JSObject *obj)
+{
+    FieldList *fieldList = static_cast<FieldList *>(obj->getPrivate());
+    JS_ASSERT(fieldList);
+    for (FieldList::iterator it = fieldList->begin(); it != fieldList->end(); ++it) {
+        gc::MarkId(tracer, &(it->name), "structtype.field.name");
+        MarkObject(tracer, &(it->type), "structtype.field.type");
+    }
+}
+
 JSBool
 StructType::toString(JSContext *cx, unsigned int argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
     RootedObject thisObj(cx, args.thisv().toObjectOrNull());
 
     if (!IsStructType(thisObj))
--- a/js/src/builtin/BinaryData.h
+++ b/js/src/builtin/BinaryData.h
@@ -272,16 +272,17 @@ class StructType : public JSObject
 
     static bool convertAndCopyTo(JSContext *cx, HandleObject exemplar,
                                  HandleValue from, uint8_t *mem);
 
     static bool reify(JSContext *cx, HandleObject type, HandleObject owner,
                       size_t offset, MutableHandleValue to);
 
     static void finalize(js::FreeOp *op, JSObject *obj);
+    static void trace(JSTracer *tracer, JSObject *obj);
 };
 
 class BinaryStruct : public JSObject
 {
   private:
     static JSObject *createEmpty(JSContext *cx, HandleObject type);
     static JSObject *create(JSContext *cx, HandleObject type);