Bug 898338 - Binary Data: Adjust formatting, convert some static things to non-static. r=nsm
authorNiko Matsakis <niko@alum.mit.edu>
Fri, 26 Jul 2013 11:03:42 -0700
changeset 140191 79322a7a9e09
parent 140190 8636a1f6d3ce
child 140192 e7045ef73a3d
push id25016
push userryanvm@gmail.com
push dateSat, 27 Jul 2013 02:25:56 +0000
treeherdermozilla-central@fb48c7d58b8b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnsm
bugs898338
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 898338 - Binary Data: Adjust formatting, convert some static things to non-static. r=nsm
js/src/builtin/BinaryData.cpp
js/src/builtin/BinaryData.h
--- a/js/src/builtin/BinaryData.cpp
+++ b/js/src/builtin/BinaryData.cpp
@@ -1,13 +1,13 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
+ * vim: set ts=8 sts=4 et sw=4 tw=99:
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "builtin/BinaryData.h"
 
 #include <vector>
 
 #include "mozilla/FloatingPoint.h"
 
 #include "jscompartment.h"
@@ -38,22 +38,25 @@ static bool Reify(JSContext *cx, HandleO
 
 /*
  * ConvertAndCopyTo() converts `from` to type `type` and stores the result in
  * `mem`, which MUST be pre-allocated to the appropriate size for instances of
  * `type`.
  */
 static bool ConvertAndCopyTo(JSContext *cx, HandleObject type,
                              HandleValue from, uint8_t *mem);
-JSBool TypeThrowError(JSContext *cx, unsigned argc, Value *vp)
+
+static JSBool
+TypeThrowError(JSContext *cx, unsigned argc, Value *vp)
 {
     return ReportIsNotFunction(cx, *vp);
 }
 
-JSBool DataThrowError(JSContext *cx, unsigned argc, Value *vp)
+static JSBool
+DataThrowError(JSContext *cx, unsigned argc, Value *vp)
 {
     return ReportIsNotFunction(cx, *vp);
 }
 
 static void
 ReportTypeError(JSContext *cx, Value fromValue, const char *toType)
 {
     char *valueStr = JS_EncodeString(cx, JS_ValueToString(cx, fromValue));
@@ -178,16 +181,44 @@ GetAlign(JSContext *cx, HandleObject typ
 
 struct FieldInfo
 {
     jsid name;
     JSObject *type;
     size_t offset;
 };
 
+Class js::DataClass = {
+    "Data",
+    JSCLASS_HAS_CACHED_PROTO(JSProto_Data),
+    JS_PropertyStub,
+    JS_DeletePropertyStub,
+    JS_PropertyStub,
+    JS_StrictPropertyStub,
+    JS_EnumerateStub,
+    JS_ResolveStub,
+    JS_ConvertStub
+};
+
+Class js::TypeClass = {
+    "Type",
+    JSCLASS_HAS_CACHED_PROTO(JSProto_Type),
+    JS_PropertyStub,
+    JS_DeletePropertyStub,
+    JS_PropertyStub,
+    JS_StrictPropertyStub,
+    JS_EnumerateStub,
+    JS_ResolveStub,
+    JS_ConvertStub
+};
+
+Class js::NumericTypeClasses[NUMERICTYPES] = {
+    BINARYDATA_FOR_EACH_NUMERIC_TYPES(BINARYDATA_NUMERIC_CLASSES)
+};
+
 typedef std::vector<FieldInfo> FieldList;
 
 static
 bool
 LookupFieldList(FieldList *list, jsid fieldName, FieldInfo *out)
 {
     for (FieldList::const_iterator it = list->begin(); it != list->end(); ++it) {
         if ((*it).name == fieldName) {
@@ -782,17 +813,17 @@ ArrayType::repeat(JSContext *cx, unsigne
                              NULL, JSMSG_MORE_ARGS_NEEDED,
                              "repeat()", "0", "s");
         return false;
     }
 
     RootedObject thisObj(cx, args.thisv().toObjectOrNull());
     if (!IsArrayType(thisObj)) {
         JSString *valueStr = JS_ValueToString(cx, args.thisv());
-        char *valueChars = "(unknown type)";
+        char *valueChars = const_cast<char*>("(unknown type)");
         if (valueStr)
             valueChars = JS_EncodeString(cx, valueStr);
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_INCOMPATIBLE_PROTO, "ArrayType", "repeat", valueChars);
         if (valueStr)
             JS_free(cx, valueChars);
         return false;
     }
 
--- a/js/src/builtin/BinaryData.h
+++ b/js/src/builtin/BinaryData.h
@@ -1,13 +1,13 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
+ * vim: set ts=8 sts=4 et sw=4 tw=99:
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef builtin_BinaryData_h
 #define builtin_BinaryData_h
 
 #include "jsapi.h"
 #include "jsobj.h"
 #include "jsfriendapi.h"
 #include "gc/Heap.h"
@@ -37,49 +37,29 @@ enum TypeCommonSlots {
 };
 
 enum BlockCommonSlots {
     SLOT_DATATYPE = 0,
     SLOT_BLOCKREFOWNER,
     BLOCK_RESERVED_SLOTS
 };
 
-static Class DataClass = {
-    "Data",
-    JSCLASS_HAS_CACHED_PROTO(JSProto_Data),
-    JS_PropertyStub,
-    JS_DeletePropertyStub,
-    JS_PropertyStub,
-    JS_StrictPropertyStub,
-    JS_EnumerateStub,
-    JS_ResolveStub,
-    JS_ConvertStub
-};
+extern Class DataClass;
 
-static Class TypeClass = {
-    "Type",
-    JSCLASS_HAS_CACHED_PROTO(JSProto_Type),
-    JS_PropertyStub,
-    JS_DeletePropertyStub,
-    JS_PropertyStub,
-    JS_StrictPropertyStub,
-    JS_EnumerateStub,
-    JS_ResolveStub,
-    JS_ConvertStub
-};
+extern Class TypeClass;
 
 template <typename T>
 class NumericType
 {
-    private:
-        static Class * typeToClass();
-    public:
-        static bool convert(JSContext *cx, HandleValue val, T *converted);
-        static bool reify(JSContext *cx, void *mem, MutableHandleValue vp);
-        static JSBool call(JSContext *cx, unsigned argc, Value *vp);
+  private:
+    static Class * typeToClass();
+  public:
+    static bool convert(JSContext *cx, HandleValue val, T *converted);
+    static bool reify(JSContext *cx, void *mem, MutableHandleValue vp);
+    static JSBool call(JSContext *cx, unsigned argc, Value *vp);
 };
 
 template <typename T>
 JS_ALWAYS_INLINE
 bool NumericType<T>::reify(JSContext *cx, void *mem, MutableHandleValue vp)
 {
     vp.setInt32(* ((T*)mem) );
     return true;
@@ -128,217 +108,216 @@ bool NumericType<float64_t>::reify(JSCon
     NULL,\
     NULL,\
     NumericType<type_##_t>::call,\
     NULL,\
     NULL,\
     NULL\
 },
 
-static Class NumericTypeClasses[NUMERICTYPES] = {
-    BINARYDATA_FOR_EACH_NUMERIC_TYPES(BINARYDATA_NUMERIC_CLASSES)
-};
+extern Class NumericTypeClasses[NUMERICTYPES];
 
 /* This represents the 'A' and it's [[Prototype]] chain
  * in:
  *   A = new ArrayType(Type, N);
  *   a = new A();
  */
 class ArrayType : public JSObject
 {
-    private:
-    public:
-        static Class class_;
+  private:
+  public:
+    static Class class_;
 
-        static JSObject *create(JSContext *cx, HandleObject arrayTypeGlobal,
-                                HandleObject elementType, uint32_t length);
-        static JSBool construct(JSContext *cx, unsigned int argc, jsval *vp);
-        static JSBool repeat(JSContext *cx, unsigned int argc, jsval *vp);
+    static JSObject *create(JSContext *cx, HandleObject arrayTypeGlobal,
+                            HandleObject elementType, uint32_t length);
+    static JSBool construct(JSContext *cx, unsigned int argc, jsval *vp);
+    static JSBool repeat(JSContext *cx, unsigned int argc, jsval *vp);
 
-        static JSBool toString(JSContext *cx, unsigned int argc, jsval *vp);
+    static JSBool toString(JSContext *cx, unsigned int argc, jsval *vp);
 
-        static uint32_t length(JSContext *cx, HandleObject obj);
-        static JSObject *elementType(JSContext *cx, HandleObject obj);
-        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 uint32_t length(JSContext *cx, HandleObject obj);
+    static JSObject *elementType(JSContext *cx, HandleObject obj);
+    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);
 };
 
 /* This represents the 'a' and it's [[Prototype]] chain */
 class BinaryArray
 {
-    private:
-        static JSObject *createEmpty(JSContext *cx, HandleObject type);
+  private:
+    static JSObject *createEmpty(JSContext *cx, HandleObject type);
 
-        // attempts to [[Convert]]
-        static JSObject *create(JSContext *cx, HandleObject type,
-                                HandleValue initial);
+    // attempts to [[Convert]]
+    static JSObject *create(JSContext *cx, HandleObject type,
+                            HandleValue initial);
 
-    public:
-        static Class class_;
+  public:
+    static Class class_;
 
-        // creates initialized memory of size of type
-        static JSObject *create(JSContext *cx, HandleObject type);
-        // uses passed block as memory
-        static JSObject *create(JSContext *cx, HandleObject type,
-                                HandleObject owner, size_t offset);
-        static JSBool construct(JSContext *cx, unsigned int argc, jsval *vp);
+    // creates initialized memory of size of type
+    static JSObject *create(JSContext *cx, HandleObject type);
+    // uses passed block as memory
+    static JSObject *create(JSContext *cx, HandleObject type,
+                            HandleObject owner, size_t offset);
+    static JSBool construct(JSContext *cx, unsigned int argc, jsval *vp);
 
-        static void finalize(FreeOp *op, JSObject *obj);
-        static void obj_trace(JSTracer *tracer, JSObject *obj);
+    static void finalize(FreeOp *op, JSObject *obj);
+    static void obj_trace(JSTracer *tracer, JSObject *obj);
 
-        static JSBool subarray(JSContext *cx, unsigned int argc, jsval *vp);
-        static JSBool fill(JSContext *cx, unsigned int argc, jsval *vp);
+    static JSBool subarray(JSContext *cx, unsigned int argc, jsval *vp);
+    static JSBool fill(JSContext *cx, unsigned int argc, jsval *vp);
 
-        static JSBool obj_lookupGeneric(JSContext *cx, HandleObject obj,
-                                        HandleId id, MutableHandleObject objp,
-                                        MutableHandleShape propp);
+    static JSBool obj_lookupGeneric(JSContext *cx, HandleObject obj,
+                                    HandleId id, MutableHandleObject objp,
+                                    MutableHandleShape propp);
 
-        static JSBool obj_lookupProperty(JSContext *cx, HandleObject obj,
-                                         HandlePropertyName name,
-                                         MutableHandleObject objp,
-                                         MutableHandleShape propp);
+    static JSBool obj_lookupProperty(JSContext *cx, HandleObject obj,
+                                     HandlePropertyName name,
+                                     MutableHandleObject objp,
+                                     MutableHandleShape propp);
 
-        static JSBool obj_lookupElement(JSContext *cx, HandleObject obj,
-                                        uint32_t index, MutableHandleObject objp,
-                                        MutableHandleShape propp);
+    static JSBool obj_lookupElement(JSContext *cx, HandleObject obj,
+                                    uint32_t index, MutableHandleObject objp,
+                                    MutableHandleShape propp);
 
-        static JSBool obj_lookupSpecial(JSContext *cx, HandleObject obj,
-                                        HandleSpecialId sid,
-                                        MutableHandleObject objp,
-                                        MutableHandleShape propp);
+    static JSBool obj_lookupSpecial(JSContext *cx, HandleObject obj,
+                                    HandleSpecialId sid,
+                                    MutableHandleObject objp,
+                                    MutableHandleShape propp);
 
-        static JSBool obj_getGeneric(JSContext *cx, HandleObject obj,
-                                     HandleObject receiver,
-                                     HandleId id,
-                                     MutableHandleValue vp);
+    static JSBool obj_getGeneric(JSContext *cx, HandleObject obj,
+                                 HandleObject receiver,
+                                 HandleId id,
+                                 MutableHandleValue vp);
 
-        static JSBool obj_getProperty(JSContext *cx, HandleObject obj,
-                                      HandleObject receiver,
-                                      HandlePropertyName name,
-                                      MutableHandleValue vp);
+    static JSBool obj_getProperty(JSContext *cx, HandleObject obj,
+                                  HandleObject receiver,
+                                  HandlePropertyName name,
+                                  MutableHandleValue vp);
 
-        static JSBool obj_getElement(JSContext *cx, HandleObject obj,
-                                     HandleObject receiver,
-                                     uint32_t index,
-                                     MutableHandleValue vp);
+    static JSBool obj_getElement(JSContext *cx, HandleObject obj,
+                                 HandleObject receiver,
+                                 uint32_t index,
+                                 MutableHandleValue vp);
 
-        static JSBool obj_getElementIfPresent(JSContext *cx, HandleObject obj,
-                                              HandleObject receiver,
-                                              uint32_t index,
-                                              MutableHandleValue vp,
-                                              bool *present);
+    static JSBool obj_getElementIfPresent(JSContext *cx, HandleObject obj,
+                                          HandleObject receiver,
+                                          uint32_t index,
+                                          MutableHandleValue vp,
+                                          bool *present);
 
-        static JSBool obj_getSpecial(JSContext *cx, HandleObject obj,
-                                     HandleObject receiver,
-                                     HandleSpecialId sid,
-                                     MutableHandleValue vp);
+    static JSBool obj_getSpecial(JSContext *cx, HandleObject obj,
+                                 HandleObject receiver,
+                                 HandleSpecialId sid,
+                                 MutableHandleValue vp);
 
-        static JSBool obj_setGeneric(JSContext *cx, HandleObject obj,
-                                     HandleId id, MutableHandleValue vp,
-                                     JSBool strict);
+    static JSBool obj_setGeneric(JSContext *cx, HandleObject obj,
+                                 HandleId id, MutableHandleValue vp,
+                                 JSBool strict);
 
-        static JSBool obj_setProperty(JSContext *cx, HandleObject obj,
-                                      HandlePropertyName name,
-                                      MutableHandleValue vp,
-                                      JSBool strict);
+    static JSBool obj_setProperty(JSContext *cx, HandleObject obj,
+                                  HandlePropertyName name,
+                                  MutableHandleValue vp,
+                                  JSBool strict);
 
-        static JSBool obj_setElement(JSContext *cx, HandleObject obj,
-                                     uint32_t index, MutableHandleValue vp,
-                                     JSBool strict);
+    static JSBool obj_setElement(JSContext *cx, HandleObject obj,
+                                 uint32_t index, MutableHandleValue vp,
+                                 JSBool strict);
 
-        static JSBool obj_setSpecial(JSContext *cx, HandleObject obj,
-                                     HandleSpecialId sid,
-                                     MutableHandleValue vp,
-                                     JSBool strict);
+    static JSBool obj_setSpecial(JSContext *cx, HandleObject obj,
+                                 HandleSpecialId sid,
+                                 MutableHandleValue vp,
+                                 JSBool strict);
 
-        static JSBool obj_getGenericAttributes(JSContext *cx, HandleObject obj,
-                                               HandleId id, unsigned *attrsp);
+    static JSBool obj_getGenericAttributes(JSContext *cx, HandleObject obj,
+                                           HandleId id, unsigned *attrsp);
 
-        static JSBool obj_getPropertyAttributes(JSContext *cx, HandleObject obj,
-                                                HandlePropertyName name,
-                                                unsigned *attrsp);
+    static JSBool obj_getPropertyAttributes(JSContext *cx, HandleObject obj,
+                                            HandlePropertyName name,
+                                            unsigned *attrsp);
 
-        static JSBool obj_getElementAttributes(JSContext *cx, HandleObject obj,
-                                               uint32_t index, unsigned *attrsp);
+    static JSBool obj_getElementAttributes(JSContext *cx, HandleObject obj,
+                                           uint32_t index, unsigned *attrsp);
 
-        static JSBool obj_getSpecialAttributes(JSContext *cx, HandleObject obj,
-                                               HandleSpecialId sid,
-                                               unsigned *attrsp);
+    static JSBool obj_getSpecialAttributes(JSContext *cx, HandleObject obj,
+                                           HandleSpecialId sid,
+                                           unsigned *attrsp);
 
-        static JSBool obj_enumerate(JSContext *cx, HandleObject obj,
-                                    JSIterateOp enum_op,
-                                    MutableHandleValue statep,
-                                    MutableHandleId idp);
+    static JSBool obj_enumerate(JSContext *cx, HandleObject obj,
+                                JSIterateOp enum_op,
+                                MutableHandleValue statep,
+                                MutableHandleId idp);
 
-        static JSBool lengthGetter(JSContext *cx, unsigned int argc, jsval *vp);
+    static JSBool lengthGetter(JSContext *cx, unsigned int argc, jsval *vp);
 
 };
 
 class StructType : public JSObject
 {
-    private:
-        static JSObject *create(JSContext *cx, HandleObject structTypeGlobal,
-                                HandleObject fields);
-        /**
-         * Sets up structType slots based on calculated memory size
-         * and alignment and stores fieldmap as well.
-         */
-        static bool layout(JSContext *cx, HandleObject structType,
-                           HandleObject fields);
+  private:
+    static JSObject *create(JSContext *cx, HandleObject structTypeGlobal,
+                            HandleObject fields);
+    /**
+     * Sets up structType slots based on calculated memory size
+     * and alignment and stores fieldmap as well.
+     */
+    static bool layout(JSContext *cx, HandleObject structType,
+                       HandleObject fields);
 
-    public:
-        static Class class_;
+  public:
+    static Class class_;
 
-        static JSBool construct(JSContext *cx, unsigned int argc, jsval *vp);
-        static JSBool toString(JSContext *cx, unsigned int argc, jsval *vp);
+    static JSBool construct(JSContext *cx, unsigned int argc, jsval *vp);
+    static JSBool toString(JSContext *cx, unsigned int argc, jsval *vp);
 
-        static bool convertAndCopyTo(JSContext *cx, HandleObject exemplar,
-                                     HandleValue from, uint8_t *mem);
+    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 bool reify(JSContext *cx, HandleObject type, HandleObject owner,
+                      size_t offset, MutableHandleValue to);
 
-        static void finalize(js::FreeOp *op, JSObject *obj);
+    static void finalize(js::FreeOp *op, JSObject *obj);
 };
 
 class BinaryStruct : public JSObject
 {
-    private:
-        static JSObject *createEmpty(JSContext *cx, HandleObject type);
-        static JSObject *create(JSContext *cx, HandleObject type);
+  private:
+    static JSObject *createEmpty(JSContext *cx, HandleObject type);
+    static JSObject *create(JSContext *cx, HandleObject type);
 
-    public:
-        static Class class_;
+  public:
+    static Class class_;
 
-        static JSObject *create(JSContext *cx, HandleObject type,
-                                HandleObject owner, size_t offset);
-        static JSBool construct(JSContext *cx, unsigned int argc, jsval *vp);
+    static JSObject *create(JSContext *cx, HandleObject type,
+                            HandleObject owner, size_t offset);
+    static JSBool construct(JSContext *cx, unsigned int argc, jsval *vp);
 
-        static void finalize(js::FreeOp *op, JSObject *obj);
-        static void obj_trace(JSTracer *tracer, JSObject *obj);
+    static void finalize(js::FreeOp *op, JSObject *obj);
+    static void obj_trace(JSTracer *tracer, JSObject *obj);
 
-        static JSBool obj_getGeneric(JSContext *cx, HandleObject obj,
-                                     HandleObject receiver, HandleId id,
-                                     MutableHandleValue vp);
+    static JSBool obj_getGeneric(JSContext *cx, HandleObject obj,
+                                 HandleObject receiver, HandleId id,
+                                 MutableHandleValue vp);
 
-        static JSBool obj_getProperty(JSContext *cx, HandleObject obj,
-                                      HandleObject receiver,
-                                      HandlePropertyName name,
-                                      MutableHandleValue vp);
+    static JSBool obj_getProperty(JSContext *cx, HandleObject obj,
+                                  HandleObject receiver,
+                                  HandlePropertyName name,
+                                  MutableHandleValue vp);
 
-        static JSBool obj_getSpecial(JSContext *cx, HandleObject obj,
-                                     HandleObject receiver, HandleSpecialId sid,
-                                     MutableHandleValue vp);
+    static JSBool obj_getSpecial(JSContext *cx, HandleObject obj,
+                                 HandleObject receiver, HandleSpecialId sid,
+                                 MutableHandleValue vp);
 
-        static JSBool obj_setGeneric(JSContext *cx, HandleObject obj, HandleId id,
-                                     MutableHandleValue vp, JSBool strict);
+    static JSBool obj_setGeneric(JSContext *cx, HandleObject obj, HandleId id,
+                                 MutableHandleValue vp, JSBool strict);
 
-        static JSBool obj_setProperty(JSContext *cx, HandleObject obj,
-                                      HandlePropertyName name,
-                                      MutableHandleValue vp,
-                                      JSBool strict);
+    static JSBool obj_setProperty(JSContext *cx, HandleObject obj,
+                                  HandlePropertyName name,
+                                  MutableHandleValue vp,
+                                  JSBool strict);
 
 };
-}
+
+} // namespace js
 
 #endif /* builtin_BinaryData_h */