PageRenderTime 23ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
C++ Header | 140 lines | 54 code | 21 blank | 65 comment | 1 complexity | c1a9245b3f64d1a0a7d6959f498329f5 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. * vim: set ts=8 sw=4 et tw=78:
  3. *
  4. * ***** BEGIN LICENSE BLOCK *****
  5. * Version: MPL 1.1/GPL 2.0/LGPL 2.1 *
  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 jsiter_h___
  40. #define jsiter_h___
  41. /*
  42. * JavaScript iterators.
  43. */
  44. #include "jsprvtd.h"
  45. #include "jspubtd.h"
  46. JS_BEGIN_EXTERN_C
  47. /*
  48. * NB: these flag bits are encoded into the bytecode stream in the immediate
  49. * operand of JSOP_ITER, so don't change them without advancing jsxdrapi.h's
  50. * JSXDR_BYTECODE_VERSION.
  51. */
  52. #define JSITER_ENUMERATE 0x1 /* for-in compatible hidden default iterator */
  53. #define JSITER_FOREACH 0x2 /* return [key, value] pair rather than key */
  54. #define JSITER_KEYVALUE 0x4 /* destructuring for-in wants [key, value] */
  55. /*
  56. * Native iterator object slots, shared between jsiter.cpp and jstracer.cpp.
  57. */
  58. #define JSSLOT_ITER_STATE (JSSLOT_PRIVATE)
  59. #define JSSLOT_ITER_FLAGS (JSSLOT_PRIVATE + 1)
  60. /*
  61. * Convert the value stored in *vp to its iteration object. The flags should
  62. * contain JSITER_ENUMERATE if js_ValueToIterator is called when enumerating
  63. * for-in semantics are required, and when the caller can guarantee that the
  64. * iterator will never be exposed to scripts.
  65. */
  66. extern JS_FRIEND_API(JSBool)
  67. js_ValueToIterator(JSContext *cx, uintN flags, jsval *vp);
  68. extern JS_FRIEND_API(JSBool) JS_FASTCALL
  69. js_CloseIterator(JSContext *cx, jsval v);
  70. /*
  71. * Given iterobj, call iterobj.next(). If the iterator stopped, set *rval to
  72. * JSVAL_HOLE. Otherwise set it to the result of the next call.
  73. */
  74. extern JS_FRIEND_API(JSBool)
  75. js_CallIteratorNext(JSContext *cx, JSObject *iterobj, jsval *rval);
  76. /*
  77. * Close iterobj, whose class must be js_IteratorClass.
  78. */
  79. extern void
  80. js_CloseNativeIterator(JSContext *cx, JSObject *iterobj);
  81. extern JSBool
  82. js_ThrowStopIteration(JSContext *cx);
  83. #if JS_HAS_GENERATORS
  84. /*
  85. * Generator state codes.
  86. */
  87. typedef enum JSGeneratorState {
  88. JSGEN_NEWBORN, /* not yet started */
  89. JSGEN_OPEN, /* started by a .next() or .send(undefined) call */
  90. JSGEN_RUNNING, /* currently executing via .next(), etc., call */
  91. JSGEN_CLOSING, /* close method is doing asynchronous return */
  92. JSGEN_CLOSED /* closed, cannot be started or closed again */
  93. } JSGeneratorState;
  94. struct JSGenerator {
  95. JSObject *obj;
  96. JSGeneratorState state;
  97. JSStackFrame frame;
  98. JSFrameRegs savedRegs;
  99. JSArena arena;
  100. jsval slots[1];
  101. };
  102. #define FRAME_TO_GENERATOR(fp) \
  103. ((JSGenerator *) ((uint8 *)(fp) - offsetof(JSGenerator, frame)))
  104. extern JSObject *
  105. js_NewGenerator(JSContext *cx, JSStackFrame *fp);
  106. #endif
  107. extern JSClass js_GeneratorClass;
  108. extern JSClass js_IteratorClass;
  109. extern JSClass js_StopIterationClass;
  110. static inline bool
  111. js_ValueIsStopIteration(jsval v)
  112. {
  113. return !JSVAL_IS_PRIMITIVE(v) &&
  114. STOBJ_GET_CLASS(JSVAL_TO_OBJECT(v)) == &js_StopIterationClass;
  115. }
  116. extern JSObject *
  117. js_InitIteratorClasses(JSContext *cx, JSObject *obj);
  118. JS_END_EXTERN_C
  119. #endif /* jsiter_h___ */