JavaScript:SpiderMonkey:Coding Style: Difference between revisions

Jump to navigation Jump to search
Line 250: Line 250:
== #include ordering ==
== #include ordering ==


The following order is used for includesthe module's .h (this ensures it includes all the headers it needs itself), mozilla/*.h; <*.h>, js*.h; */*.h; js*inlines.h and js*-inl.h; */*-inl.h. The public JSAPI headers in js/public/*.h should be included as js/*.h in the */*.h block.
The following order is used for module X:   
* If X-inl.h exists, it goes first.  (And X-inl.h's first #include should be X.h.) Otherwise, X.h goes first.  This rule ensures that X.h and X-inl.h both #include all the headers that they need themselves.
* mozilla/*.h
* <*.h>
* js*.h
* */*.h (this includes the public JSAPI headers in js/public/*.h which should be included using the form js/*.h)
* js*inlines.h
* */*-inl.h.


Example for jsfoo.cpp:
Example for X.cpp:


  #include "jsfoo.h"
  #include "X.h"   // put "X-inl.h" instead, if it exists
   
   
  #include "mozilla/StdInt.h"
  #include "mozilla/StdInt.h"
Line 273: Line 280:
  #include "vm/VirtualReality-inl.h"
  #include "vm/VirtualReality-inl.h"


Including X-inl.h implies that X.h is included as well. If possible, keep lexicographic order with each section.
If possible, keep lexicographic order with each section.


= C++ =
= C++ =
Confirmed users
1,345

edits

Navigation menu