Back to index

lightning-sunbird  0.9+nobinonly
jsiter.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  * vim: set ts=8 sw=4 et tw=78:
00003  *
00004  * ***** BEGIN LICENSE BLOCK *****
00005  * Version: MPL 1.1/GPL 2.0/LGPL 2.1 *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Mozilla Communicator client code, released
00017  * March 31, 1998.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Netscape Communications Corporation.
00021  * Portions created by the Initial Developer are Copyright (C) 1998
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef jsiter_h___
00041 #define jsiter_h___
00042 /*
00043  * JavaScript iterators.
00044  */
00045 #include "jsprvtd.h"
00046 #include "jspubtd.h"
00047 
00048 #define JSITER_ENUMERATE  0x1   /* for-in compatible hidden default iterator */
00049 #define JSITER_FOREACH    0x2   /* return [key, value] pair rather than key */
00050 #define JSITER_KEYVALUE   0x4   /* destructuring for-in wants [key, value] */
00051 
00052 extern void
00053 js_CloseNativeIterator(JSContext *cx, JSObject *iterobj);
00054 
00055 extern void
00056 js_CloseIteratorState(JSContext *cx, JSObject *iterobj);
00057 
00058 /*
00059  * Convert the value stored in *vp to its iteration object. The flags should
00060  * contain JSITER_ENUMERATE if js_ValueToIterator is called when enumerating
00061  * for-in semantics are required, and when the caller can guarantee that the
00062  * iterator will never be exposed to scripts.
00063  */
00064 extern JSBool
00065 js_ValueToIterator(JSContext *cx, uintN flags, jsval *vp);
00066 
00067 /*
00068  * Given iterobj, call iterobj.next().  If the iterator stopped, set *rval to
00069  * JSVAL_HOLE. Otherwise set it to the result of the next call.
00070  */
00071 extern JSBool
00072 js_CallIteratorNext(JSContext *cx, JSObject *iterobj, jsval *rval);
00073 
00074 #if JS_HAS_GENERATORS
00075 
00076 /*
00077  * Generator state codes.
00078  */
00079 typedef enum JSGeneratorState {
00080     JSGEN_NEWBORN,  /* not yet started */
00081     JSGEN_OPEN,     /* started by a .next() or .send(undefined) call */
00082     JSGEN_RUNNING,  /* currently executing via .next(), etc., call */
00083     JSGEN_CLOSING,  /* close method is doing asynchronous return */
00084     JSGEN_CLOSED    /* closed, cannot be started or closed again */
00085 } JSGeneratorState;
00086 
00087 struct JSGenerator {
00088     JSGenerator         *next;
00089     JSObject            *obj;
00090     JSGeneratorState    state;
00091     JSStackFrame        frame;
00092     JSArena             arena;
00093     jsval               stack[1];
00094 };
00095 
00096 #define FRAME_TO_GENERATOR(fp) \
00097     ((JSGenerator *) ((uint8 *)(fp) - offsetof(JSGenerator, frame)))
00098 
00099 extern JSObject *
00100 js_NewGenerator(JSContext *cx, JSStackFrame *fp);
00101 
00102 extern JSBool
00103 js_CloseGeneratorObject(JSContext *cx, JSGenerator *gen);
00104 
00105 #endif
00106 
00107 extern JSClass          js_GeneratorClass;
00108 extern JSClass          js_IteratorClass;
00109 extern JSClass          js_StopIterationClass;
00110 
00111 extern JSObject *
00112 js_InitIteratorClasses(JSContext *cx, JSObject *obj);
00113 
00114 #endif /* jsiter_h___ */