JavaScript:SpiderMonkey:Coding Style: Difference between revisions

Jump to navigation Jump to search
Reflect change from |T *t| to |T* t|. Also remove the edge cases that are obvious with the new style.
(→‎Control Flow: Add the jorendorff rule)
(Reflect change from |T *t| to |T* t|. Also remove the edge cases that are obvious with the new style.)
Line 44: Line 44:
These rules are inconsistently applied.  Be consistent with the code you're editing rather than adhere too closely to these guidelines!
These rules are inconsistently applied.  Be consistent with the code you're editing rather than adhere too closely to these guidelines!


* In a declaration of a pointer, the <code>*</code> goes with the variable name:
* In a declaration of a pointer, the <code>*</code> goes with the type:
  char* s;                  /* bad */
  char *s;                  /* bad */
  char *s;                  /* OK */
  char* s;                  /* OK */
* Even in the return type of a method:
class JSString
{
    ...
    JSString* dependentBase() const;  /* bad */
    JSString * dependentBase() const;  /* bad */
    JSString *dependentBase() const;  /* OK */
    ...
};
* But in top-level function declarations/definitions, put a line break immediately before the name being declared:
extern const char *
js_GetStringBytes(JSContext *cx, JSString *str);  /* OK */
* And put a space in <code>*JS_FASTCALL</code>, because that would be crazy.
extern JSString *JS_FASTCALL          /* bad */
js_ConcatStrings(JSContext *cx, JSString *left, JSString *right);
extern JSString * JS_FASTCALL          /* OK */
js_ConcatStrings(JSContext *cx, JSString *left, JSString *right);
* In C++ method declarations with default arguments, use spaces and comments like so:
* In C++ method declarations with default arguments, use spaces and comments like so:
  static void
  static void
  Frob(JSContext *cx, uint32_t defaultValue = 0);
  Frob(JSContext* cx, uint32_t defaultValue = 0);
  static void
  static void
  Frob(JSContext *cx, uint32_t defaultValue /* = 0 */)
  Frob(JSContext* cx, uint32_t defaultValue /* = 0 */)
  {
  {
     /* ... */
     /* ... */
Line 98: Line 81:
* Conditions with multi-line tests should put the brace on the new line to provide a visual separation between the condition and the body.
* Conditions with multi-line tests should put the brace on the new line to provide a visual separation between the condition and the body.


   types::TypeSet *types = frame.extra(lhs).types;
   types::TypeSet* types = frame.extra(lhs).types;
   if (JSOp(*PC) == JSOP_SETPROP && id == types::MakeTypeId(cx, id) &&
   if (JSOp(*PC) == JSOP_SETPROP && id == types::MakeTypeId(cx, id) &&
       types && !types->unknownObject() &&
       types && !types->unknownObject() &&
Line 106: Line 89:
   {
   {
       JS_ASSERT(usePropCache);
       JS_ASSERT(usePropCache);
       types::TypeObject *object = types->getTypeObject(0);
       types::TypeObject* object = types->getTypeObject(0);
       types::TypeSet *propertyTypes = object->getProperty(cx, id, false);
       types::TypeSet* propertyTypes = object->getProperty(cx, id, false);
       ...
       ...
   } else {
   } else {
Line 333: Line 316:
  {
  {
     size_t capacity;  // common
     size_t capacity;  // common
     T *begin_;        // also common, being used more as time goes on
     T* begin_;        // also common, being used more as time goes on
  }
  }
Sometimes a canonical argument name may conflict with a member name.  In this case, one can disambiguate with "this->", although such explicit qualification should only be added when necessary:
Sometimes a canonical argument name may conflict with a member name.  In this case, one can disambiguate with "this->", although such explicit qualification should only be added when necessary:
Line 390: Line 373:
  class Eater
  class Eater
  {
  {
     Food *obtainFoodFromEatery(Eatery &eatery) {
     Food* obtainFoodFromEatery(Eatery &eatery) {
         if (!eatery.hasFood())
         if (!eatery.hasFood())
             return NULL;
             return NULL;
Line 401: Line 384:
  class SpaceGoo
  class SpaceGoo
  {
  {
     inline BlobbyWrapper *enblob(Entity &other);
     inline BlobbyWrapper* enblob(Entity &other);
  };
  };
   
   
  inline BlobbyWrapper *
  inline BlobbyWrapper*
  SpaceGoo::enblob(Entity &other)
  SpaceGoo::enblob(Entity &other)
  {
  {
2

edits

Navigation menu