/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/js/jsarray.h

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs · C++ Header · 191 lines · 72 code · 32 blank · 87 comment · 3 complexity · 60cdb9079c248a505940afed47f65631 MD5 · raw file

  1. /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. *
  3. * ***** BEGIN LICENSE BLOCK *****
  4. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5. *
  6. * The contents of this file are subject to the Mozilla Public License Version
  7. * 1.1 (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. * http://www.mozilla.org/MPL/
  10. *
  11. * Software distributed under the License is distributed on an "AS IS" basis,
  12. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. * for the specific language governing rights and limitations under the
  14. * License.
  15. *
  16. * The Original Code is Mozilla Communicator client code, released
  17. * March 31, 1998.
  18. *
  19. * The Initial Developer of the Original Code is
  20. * Netscape Communications Corporation.
  21. * Portions created by the Initial Developer are Copyright (C) 1998
  22. * the Initial Developer. All Rights Reserved.
  23. *
  24. * Contributor(s):
  25. *
  26. * Alternatively, the contents of this file may be used under the terms of
  27. * either of the GNU General Public License Version 2 or later (the "GPL"),
  28. * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29. * in which case the provisions of the GPL or the LGPL are applicable instead
  30. * of those above. If you wish to allow use of your version of this file only
  31. * under the terms of either the GPL or the LGPL, and not to allow others to
  32. * use your version of this file under the terms of the MPL, indicate your
  33. * decision by deleting the provisions above and replace them with the notice
  34. * and other provisions required by the GPL or the LGPL. If you do not delete
  35. * the provisions above, a recipient may use your version of this file under
  36. * the terms of any one of the MPL, the GPL or the LGPL.
  37. *
  38. * ***** END LICENSE BLOCK ***** */
  39. #ifndef jsarray_h___
  40. #define jsarray_h___
  41. /*
  42. * JS Array interface.
  43. */
  44. #include "jsprvtd.h"
  45. #include "jspubtd.h"
  46. JS_BEGIN_EXTERN_C
  47. /* Generous sanity-bound on length (in elements) of array initialiser. */
  48. #define ARRAY_INIT_LIMIT JS_BIT(24)
  49. extern JSBool
  50. js_IdIsIndex(jsval id, jsuint *indexp);
  51. extern JSClass js_ArrayClass, js_SlowArrayClass;
  52. #define OBJ_IS_DENSE_ARRAY(cx,obj) (OBJ_GET_CLASS(cx, obj) == &js_ArrayClass)
  53. #define OBJ_IS_ARRAY(cx,obj) (OBJ_IS_DENSE_ARRAY(cx, obj) || \
  54. OBJ_GET_CLASS(cx, obj) == &js_SlowArrayClass)
  55. extern JSObject *
  56. js_InitArrayClass(JSContext *cx, JSObject *obj);
  57. extern JSObject *
  58. js_NewArrayObject(JSContext *cx, jsuint length, jsval *vector,
  59. JSBool holey = JS_FALSE);
  60. /* Create an array object that starts out already made slow/sparse. */
  61. extern JSObject *
  62. js_NewSlowArrayObject(JSContext *cx);
  63. extern JSBool
  64. js_MakeArraySlow(JSContext *cx, JSObject *obj);
  65. #define JSSLOT_ARRAY_LENGTH JSSLOT_PRIVATE
  66. #define JSSLOT_ARRAY_COUNT (JSSLOT_ARRAY_LENGTH + 1)
  67. #define JSSLOT_ARRAY_LOOKUP_HOLDER (JSSLOT_ARRAY_COUNT + 1)
  68. #define ARRAY_DENSE_LENGTH(obj) \
  69. (JS_ASSERT(OBJ_IS_DENSE_ARRAY(cx, obj)), \
  70. (obj)->dslots ? (uint32)(obj)->dslots[-1] : 0)
  71. #define ARRAY_SET_DENSE_LENGTH(obj, max) \
  72. (JS_ASSERT((obj)->dslots), (obj)->dslots[-1] = (jsval)(max))
  73. #define ARRAY_GROWBY 8
  74. extern JSBool
  75. js_GetLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);
  76. extern JSBool
  77. js_SetLengthProperty(JSContext *cx, JSObject *obj, jsuint length);
  78. extern JSBool
  79. js_HasLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);
  80. extern JSBool JS_FASTCALL
  81. js_IndexToId(JSContext *cx, jsuint index, jsid *idp);
  82. /*
  83. * Test whether an object is "array-like". Currently this means whether obj
  84. * is an Array or an arguments object. We would like an API, and probably a
  85. * way in the language, to bless other objects as array-like: having indexed
  86. * properties, and a 'length' property of uint32 value equal to one more than
  87. * the greatest index.
  88. */
  89. extern JSBool
  90. js_IsArrayLike(JSContext *cx, JSObject *obj, JSBool *answerp, jsuint *lengthp);
  91. /*
  92. * JS-specific merge sort function.
  93. */
  94. typedef JSBool (*JSComparator)(void *arg, const void *a, const void *b,
  95. int *result);
  96. /*
  97. * NB: vec is the array to be sorted, tmp is temporary space at least as big
  98. * as vec. Both should be GC-rooted if appropriate.
  99. *
  100. * The sorted result is in vec. vec may be in an inconsistent state if the
  101. * comparator function cmp returns an error inside a comparison, so remember
  102. * to check the return value of this function.
  103. */
  104. extern JSBool
  105. js_MergeSort(void *vec, size_t nel, size_t elsize, JSComparator cmp,
  106. void *arg, void *tmp);
  107. #ifdef DEBUG_ARRAYS
  108. extern JSBool
  109. js_ArrayInfo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
  110. #endif
  111. /*
  112. * Fast dense-array-to-buffer conversions.
  113. *
  114. * If the array is a dense array, fill [offset..offset+count] values
  115. * into destination, assuming that types are consistent. Return
  116. * JS_TRUE if successful, otherwise JS_FALSE -- note that the
  117. * destination buffer may be modified even if JS_FALSE is returned
  118. * (e.g. due to finding an inappropriate type later on in the array).
  119. * If JS_FALSE is returned, no error conditions or exceptions are set
  120. * on the context.
  121. *
  122. * For ArrayToJSUint8, ArrayToJSUint16, and ArrayToJSUint32, each element
  123. * in the array a) must be an integer; b) must be >= 0. Integers
  124. * are clamped to fit in the destination size. Only JSVAL_IS_INT values
  125. * are considered to be valid, so for JSUint32, the maximum value that
  126. * can be fast-converted is less than the full unsigned 32-bit range.
  127. *
  128. * For ArrayToJSInt8, ArrayToJSInt16, ArrayToJSInt32, each element in
  129. * the array must be an integer. Integers are clamped to fit in the
  130. * destination size. Only JSVAL_IS_INT values are considered to be
  131. * valid, so for JSInt32, the maximum value that can be
  132. * fast-converted is less than the full signed 32-bit range.
  133. *
  134. * For ArrayToJSDouble, each element in the array must be an
  135. * integer -or- a double (JSVAL_IS_NUMBER).
  136. */
  137. JS_FRIEND_API(JSBool)
  138. js_ArrayToJSUint8Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
  139. JSUint8 *dest);
  140. JS_FRIEND_API(JSBool)
  141. js_ArrayToJSUint16Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
  142. JSUint16 *dest);
  143. JS_FRIEND_API(JSBool)
  144. js_ArrayToJSUint32Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
  145. JSUint32 *dest);
  146. JS_FRIEND_API(JSBool)
  147. js_ArrayToJSInt8Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
  148. JSInt8 *dest);
  149. JS_FRIEND_API(JSBool)
  150. js_ArrayToJSInt16Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
  151. JSInt16 *dest);
  152. JS_FRIEND_API(JSBool)
  153. js_ArrayToJSInt32Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
  154. JSInt32 *dest);
  155. JS_FRIEND_API(JSBool)
  156. js_ArrayToJSDoubleBuffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
  157. jsdouble *dest);
  158. JS_END_EXTERN_C
  159. #endif /* jsarray_h___ */