1 module etc.c.duktape;
2 
3 public import etc.c.duk_config;
4 import std..string : toStringz;
5 /**
6  *  Duktape public API for Duktape 2.3.0.
7  *
8  *  See the API reference for documentation on call semantics.  The exposed,
9  *  supported API is between the "BEGIN PUBLIC API" and "END PUBLIC API"
10  *  comments.  Other parts of the header are Duktape internal and related to
11  *  e.g. platform/compiler/feature detection.
12  *
13  *  Git commit d7fdb67f18561a50e06bafd196c6b423af9ad6fe (v2.3.0).
14  *  Git branch master.
15  *
16  *  See Duktape AUTHORS.rst and LICENSE.txt for copyright and
17  *  licensing information.
18  */
19 
20 /* LICENSE.txt */
21 /*
22  *  ===============
23  *  Duktape license
24  *  ===============
25  *
26  *  (http://opensource.org/licenses/MIT)
27  *
28  *  Copyright (c) 2013-2018 by Duktape authors (see AUTHORS.rst)
29  *
30  *  Permission is hereby granted, free of charge, to any person obtaining a copy
31  *  of this software and associated documentation files (the "Software"), to deal
32  *  in the Software without restriction, including without limitation the rights
33  *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
34  *  copies of the Software, and to permit persons to whom the Software is
35  *  furnished to do so, subject to the following conditions:
36  *
37  *  The above copyright notice and this permission notice shall be included in
38  *  all copies or substantial portions of the Software.
39  *
40  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
43  *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
44  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
45  *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
46  *  THE SOFTWARE.
47  */
48 
49 /* AUTHORS.rst */
50 /*
51  *  ===============
52  *  Duktape authors
53  *  ===============
54  *
55  *  Copyright
56  *  =========
57  *
58  *  Duktape copyrights are held by its authors.  Each author has a copyright
59  *  to their contribution, and agrees to irrevocably license the contribution
60  *  under the Duktape ``LICENSE.txt``.
61  *
62  *  Authors
63  *  =======
64  *
65  *  Please include an e-mail address, a link to your GitHub profile, or something
66  *  similar to allow your contribution to be identified accurately.
67  *
68  *  The following people have contributed code, website contents, or Wiki contents,
69  *  and agreed to irrevocably license their contributions under the Duktape
70  *  ``LICENSE.txt`` (in order of appearance):
71  *
72  *  * Sami Vaarala <sami.vaarala@iki.fi>
73  *  * Niki Dobrev
74  *  * Andreas \u00d6man <andreas@lonelycoder.com>
75  *  * L\u00e1szl\u00f3 Lang\u00f3 <llango.u-szeged@partner.samsung.com>
76  *  * Legimet <legimet.calc@gmail.com>
77  *  * Karl Skomski <karl@skomski.com>
78  *  * Bruce Pascoe <fatcerberus1@gmail.com>
79  *  * Ren\u00e9 Hollander <rene@rene8888.at>
80  *  * Julien Hamaide (https://github.com/crazyjul)
81  *  * Sebastian G\u00f6tte (https://github.com/jaseg)
82  *  * Tomasz Magulski (https://github.com/magul)
83  *  * \D. Bohdan (https://github.com/dbohdan)
84  *  * Ond\u0159ej Jirman (https://github.com/megous)
85  *  * Sa\u00fal Ibarra Corretg\u00e9 <saghul@gmail.com>
86  *  * Jeremy HU <huxingyi@msn.com>
87  *  * Ole Andr\u00e9 Vadla Ravn\u00e5s (https://github.com/oleavr)
88  *  * Harold Brenes (https://github.com/harold-b)
89  *  * Oliver Crow (https://github.com/ocrow)
90  *  * Jakub Ch\u0142api\u0144ski (https://github.com/jchlapinski)
91  *  * Brett Vickers (https://github.com/beevik)
92  *  * Dominik Okwieka (https://github.com/okitec)
93  *  * Remko Tron\u00e7on (https://el-tramo.be)
94  *  * Romero Malaquias (rbsm@ic.ufal.br)
95  *  * Michael Drake <michael.drake@codethink.co.uk>
96  *  * Steven Don (https://github.com/shdon)
97  *  * Simon Stone (https://github.com/sstone1)
98  *  * \J. McC. (https://github.com/jmhmccr)
99  *  * Jakub Nowakowski (https://github.com/jimvonmoon)
100  *  * Tommy Nguyen (https://github.com/tn0502)
101  *  * Fabrice Fontaine (https://github.com/ffontaine)
102  *  * Christopher Hiller (https://github.com/boneskull)
103  *  * Gonzalo Diethelm (https://github.com/gonzus)
104  *  * Michal Kasperek (https://github.com/michalkas)
105  *  * Andrew Janke (https://github.com/apjanke)
106  *  * Steve Fan (https://github.com/stevefan1999)
107  *
108  *  Other contributions
109  *  ===================
110  *
111  *  The following people have contributed something other than code (e.g. reported
112  *  bugs, provided ideas, etc; roughly in order of appearance):
113  *
114  *  * Greg Burns
115  *  * Anthony Rabine
116  *  * Carlos Costa
117  *  * Aur\u00e9lien Bouilland
118  *  * Preet Desai (Pris Matic)
119  *  * judofyr (http://www.reddit.com/user/judofyr)
120  *  * Jason Woofenden
121  *  * Micha\u0142 Przyby\u015b
122  *  * Anthony Howe
123  *  * Conrad Pankoff
124  *  * Jim Schimpf
125  *  * Rajaran Gaunker (https://github.com/zimbabao)
126  *  * Andreas \u00d6man
127  *  * Doug Sanden
128  *  * Josh Engebretson (https://github.com/JoshEngebretson)
129  *  * Remo Eichenberger (https://github.com/remoe)
130  *  * Mamod Mehyar (https://github.com/mamod)
131  *  * David Demelier (https://github.com/markand)
132  *  * Tim Caswell (https://github.com/creationix)
133  *  * Mitchell Blank Jr (https://github.com/mitchblank)
134  *  * https://github.com/yushli
135  *  * Seo Sanghyeon (https://github.com/sanxiyn)
136  *  * Han ChoongWoo (https://github.com/tunz)
137  *  * Joshua Peek (https://github.com/josh)
138  *  * Bruce E. Pascoe (https://github.com/fatcerberus)
139  *  * https://github.com/Kelledin
140  *  * https://github.com/sstruchtrup
141  *  * Michael Drake (https://github.com/tlsa)
142  *  * https://github.com/chris-y
143  *  * Laurent Zubiaur (https://github.com/lzubiaur)
144  *  * Neil Kolban (https://github.com/nkolban)
145  *  * Wilhelm Wanecek (https://github.com/wanecek)
146  *  * Andrew Janke (https://github.com/apjanke)
147  *
148  *  If you are accidentally missing from this list, send me an e-mail
149  *  (``sami.vaarala@iki.fi``) and I'll fix the omission.
150  */
151 
152 extern (C):
153 
154 /*
155  *  BEGIN PUBLimport core.stdc.config;
156 import core.stdc.stdio;
157 
158 import core.sys.posix.sys.types;
159 
160 IC API
161  */
162 
163 /*
164  *  Version and Git commit identification
165  */
166 
167 /* Duktape version, (major * 10000) + (minor * 100) + patch.  Allows C code
168  * to #if (DUK_VERSION >= NNN) against Duktape API version.  The same value
169  * is also available to ECMAScript code in Duktape.version.  Unofficial
170  * development snapshots have 99 for patch level (e.g. 0.10.99 would be a
171  * development version after 0.10.0 but before the next official release).
172  */
173 enum DUK_VERSION = 20300L;
174 
175 /* Git commit, describe, and branch for Duktape build.  Useful for
176  * non-official snapshot builds so that application code can easily log
177  * which Duktape snapshot was used.  Not available in the ECMAScript
178  * environment.
179  */
180 enum DUK_GIT_COMMIT = "d7fdb67f18561a50e06bafd196c6b423af9ad6fe";
181 enum DUK_GIT_DESCRIBE = "v2.3.0";
182 enum DUK_GIT_BRANCH = "master";
183 
184 /* External duk_config.h provides platform/compiler/OS dependent
185  * typedefs and macros, and DUK_USE_xxx config options so that
186  * the rest of Duktape doesn't need to do any feature detection.
187  * DUK_VERSION is defined before including so that configuration
188  * snippets can react to it.
189  */
190 
191 /*
192  *  Avoid C++ name mangling
193  */
194 
195 /*
196  *  Some defines forwarded from feature detection
197  */
198 
199 /*
200  *  Public API specific typedefs
201  *
202  *  Many types are wrapped by Duktape for portability to rare platforms
203  *  where e.g. 'int' is a 16-bit type.  See practical typing discussion
204  *  in Duktape web documentation.
205  */
206 
207 /* duk_context is now defined in duk_config.h because it may also be
208  * referenced there by prototypes.
209  */
210 
211 alias duk_c_function = int function (duk_context* ctx);
212 alias duk_alloc_function = void* function (void* udata, duk_size_t size);
213 alias duk_realloc_function = void* function (void* udata, void* ptr, duk_size_t size);
214 alias duk_free_function = void function (void* udata, void* ptr);
215 alias duk_fatal_function = void function (void* udata, const(char)* msg);
216 alias duk_decode_char_function = void function (void* udata, duk_codepoint_t codepoint);
217 alias duk_map_char_function = int function (void* udata, duk_codepoint_t codepoint);
218 alias duk_safe_call_function = int function (duk_context* ctx, void* udata);
219 alias duk_debug_read_function = ulong function (void* udata, char* buffer, duk_size_t length);
220 alias duk_debug_write_function = ulong function (void* udata, const(char)* buffer, duk_size_t length);
221 alias duk_debug_peek_function = ulong function (void* udata);
222 alias duk_debug_read_flush_function = void function (void* udata);
223 alias duk_debug_write_flush_function = void function (void* udata);
224 alias duk_debug_request_function = int function (duk_context* ctx, void* udata, duk_idx_t nvalues);
225 alias duk_debug_detached_function = void function (duk_context* ctx, void* udata);
226 
227 struct duk_thread_state
228 {
229     /* XXX: Enough space to hold internal suspend/resume structure.
230          * This is rather awkward and to be fixed when the internal
231          * structure is visible for the public API header.
232          */
233     char[128] data;
234 }
235 
236 struct duk_memory_functions
237 {
238     duk_alloc_function alloc_func;
239     duk_realloc_function realloc_func;
240     duk_free_function free_func;
241     void* udata;
242 }
243 
244 struct duk_function_list_entry
245 {
246     const(char)* key;
247     duk_c_function value;
248     duk_idx_t nargs;
249 }
250 
251 struct duk_number_list_entry
252 {
253     const(char)* key;
254     duk_double_t value;
255 }
256 
257 struct duk_time_components
258 {
259     duk_double_t year; /* year, e.g. 2016, ECMAScript year range */
260     duk_double_t month; /* month: 1-12 */
261     duk_double_t day; /* day: 1-31 */
262     duk_double_t hours; /* hour: 0-59 */
263     duk_double_t minutes; /* minute: 0-59 */
264     duk_double_t seconds; /* second: 0-59 (in POSIX time no leap second) */
265     duk_double_t milliseconds; /* may contain sub-millisecond fractions */
266     duk_double_t weekday; /* weekday: 0-6, 0=Sunday, 1=Monday, ..., 6=Saturday */
267 }
268 
269 /*
270  *  Constants
271  */
272 
273 /* Duktape debug protocol version used by this build. */
274 enum DUK_DEBUG_PROTOCOL_VERSION = 2;
275 
276 /* Used to represent invalid index; if caller uses this without checking,
277  * this index will map to a non-existent stack entry.  Also used in some
278  * API calls as a marker to denote "no value".
279  */
280 enum DUK_INVALID_INDEX = DUK_IDX_MIN;
281 
282 /* Indicates that a native function does not have a fixed number of args,
283  * and the argument stack should not be capped/extended at all.
284  */
285 enum DUK_VARARGS = cast(duk_int_t) -1;
286 
287 /* Number of value stack entries (in addition to actual call arguments)
288  * guaranteed to be allocated on entry to a Duktape/C function.
289  */
290 enum DUK_API_ENTRY_STACK = 64U;
291 
292 /* Value types, used by e.g. duk_get_type() */
293 enum DUK_TYPE_MIN = 0U;
294 enum DUK_TYPE_NONE = 0U; /* no value, e.g. invalid index */
295 enum DUK_TYPE_UNDEFINED = 1U; /* ECMAScript undefined */
296 enum DUK_TYPE_NULL = 2U; /* ECMAScript null */
297 enum DUK_TYPE_BOOLEAN = 3U; /* ECMAScript boolean: 0 or 1 */
298 enum DUK_TYPE_NUMBER = 4U; /* ECMAScript number: double */
299 enum DUK_TYPE_STRING = 5U; /* ECMAScript string: CESU-8 / extended UTF-8 encoded */
300 enum DUK_TYPE_OBJECT = 6U; /* ECMAScript object: includes objects, arrays, functions, threads */
301 enum DUK_TYPE_BUFFER = 7U; /* fixed or dynamic, garbage collected byte buffer */
302 enum DUK_TYPE_POINTER = 8U; /* raw void pointer */
303 enum DUK_TYPE_LIGHTFUNC = 9U; /* lightweight function pointer */
304 enum DUK_TYPE_MAX = 9U;
305 
306 /* Value mask types, used by e.g. duk_get_type_mask() */
307 enum DUK_TYPE_MASK_NONE = 1U << DUK_TYPE_NONE;
308 enum DUK_TYPE_MASK_UNDEFINED = 1U << DUK_TYPE_UNDEFINED;
309 enum DUK_TYPE_MASK_NULL = 1U << DUK_TYPE_NULL;
310 enum DUK_TYPE_MASK_BOOLEAN = 1U << DUK_TYPE_BOOLEAN;
311 enum DUK_TYPE_MASK_NUMBER = 1U << DUK_TYPE_NUMBER;
312 enum DUK_TYPE_MASK_STRING = 1U << DUK_TYPE_STRING;
313 enum DUK_TYPE_MASK_OBJECT = 1U << DUK_TYPE_OBJECT;
314 enum DUK_TYPE_MASK_BUFFER = 1U << DUK_TYPE_BUFFER;
315 enum DUK_TYPE_MASK_POINTER = 1U << DUK_TYPE_POINTER;
316 enum DUK_TYPE_MASK_LIGHTFUNC = 1U << DUK_TYPE_LIGHTFUNC;
317 enum DUK_TYPE_MASK_THROW = 1U << 10; /* internal flag value: throw if mask doesn't match */
318 enum DUK_TYPE_MASK_PROMOTE = 1U << 11; /* internal flag value: promote to object if mask matches */
319 
320 /* Coercion hints */
321 enum DUK_HINT_NONE = 0; /* prefer number, unless input is a Date, in which
322  * case prefer string (E5 Section 8.12.8)
323  */
324 enum DUK_HINT_STRING = 1; /* prefer string */
325 enum DUK_HINT_NUMBER = 2; /* prefer number */
326 
327 /* Enumeration flags for duk_enum() */
328 enum DUK_ENUM_INCLUDE_NONENUMERABLE = 1U << 0; /* enumerate non-numerable properties in addition to enumerable */
329 enum DUK_ENUM_INCLUDE_HIDDEN = 1U << 1; /* enumerate hidden symbols too (in Duktape 1.x called internal properties) */
330 enum DUK_ENUM_INCLUDE_SYMBOLS = 1U << 2; /* enumerate symbols */
331 enum DUK_ENUM_EXCLUDE_STRINGS = 1U << 3; /* exclude strings */
332 enum DUK_ENUM_OWN_PROPERTIES_ONLY = 1U << 4; /* don't walk prototype chain, only check own properties */
333 enum DUK_ENUM_ARRAY_INDICES_ONLY = 1U << 5; /* only enumerate array indices */
334 /* XXX: misleading name */
335 enum DUK_ENUM_SORT_ARRAY_INDICES = 1U << 6; /* sort array indices (applied to full enumeration result, including inherited array indices); XXX: misleading name */
336 enum DUK_ENUM_NO_PROXY_BEHAVIOR = 1U << 7; /* enumerate a proxy object itself without invoking proxy behavior */
337 
338 /* Compilation flags for duk_compile() and duk_eval() */
339 /* DUK_COMPILE_xxx bits 0-2 are reserved for an internal 'nargs' argument.
340  */
341 enum DUK_COMPILE_EVAL = 1U << 3; /* compile eval code (instead of global code) */
342 enum DUK_COMPILE_FUNCTION = 1U << 4; /* compile function code (instead of global code) */
343 enum DUK_COMPILE_STRICT = 1U << 5; /* use strict (outer) context for global, eval, or function code */
344 enum DUK_COMPILE_SHEBANG = 1U << 6; /* allow shebang ('#! ...') comment on first line of source */
345 enum DUK_COMPILE_SAFE = 1U << 7; /* (internal) catch compilation errors */
346 enum DUK_COMPILE_NORESULT = 1U << 8; /* (internal) omit eval result */
347 enum DUK_COMPILE_NOSOURCE = 1U << 9; /* (internal) no source string on stack */
348 enum DUK_COMPILE_STRLEN = 1U << 10; /* (internal) take strlen() of src_buffer (avoids double evaluation in macro) */
349 enum DUK_COMPILE_NOFILENAME = 1U << 11; /* (internal) no filename on stack */
350 enum DUK_COMPILE_FUNCEXPR = 1U << 12; /* (internal) source is a function expression (used for Function constructor) */
351 
352 /* Flags for duk_def_prop() and its variants; base flags + a lot of convenience shorthands */
353 enum DUK_DEFPROP_WRITABLE = 1U << 0; /* set writable (effective if DUK_DEFPROP_HAVE_WRITABLE set) */
354 enum DUK_DEFPROP_ENUMERABLE = 1U << 1; /* set enumerable (effective if DUK_DEFPROP_HAVE_ENUMERABLE set) */
355 enum DUK_DEFPROP_CONFIGURABLE = 1U << 2; /* set configurable (effective if DUK_DEFPROP_HAVE_CONFIGURABLE set) */
356 enum DUK_DEFPROP_HAVE_WRITABLE = 1U << 3; /* set/clear writable */
357 enum DUK_DEFPROP_HAVE_ENUMERABLE = 1U << 4; /* set/clear enumerable */
358 enum DUK_DEFPROP_HAVE_CONFIGURABLE = 1U << 5; /* set/clear configurable */
359 enum DUK_DEFPROP_HAVE_VALUE = 1U << 6; /* set value (given on value stack) */
360 enum DUK_DEFPROP_HAVE_GETTER = 1U << 7; /* set getter (given on value stack) */
361 enum DUK_DEFPROP_HAVE_SETTER = 1U << 8; /* set setter (given on value stack) */
362 enum DUK_DEFPROP_FORCE = 1U << 9; /* force change if possible, may still fail for e.g. virtual properties */
363 enum DUK_DEFPROP_SET_WRITABLE = DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_WRITABLE;
364 enum DUK_DEFPROP_CLEAR_WRITABLE = DUK_DEFPROP_HAVE_WRITABLE;
365 enum DUK_DEFPROP_SET_ENUMERABLE = DUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_ENUMERABLE;
366 enum DUK_DEFPROP_CLEAR_ENUMERABLE = DUK_DEFPROP_HAVE_ENUMERABLE;
367 enum DUK_DEFPROP_SET_CONFIGURABLE = DUK_DEFPROP_HAVE_CONFIGURABLE | DUK_DEFPROP_CONFIGURABLE;
368 enum DUK_DEFPROP_CLEAR_CONFIGURABLE = DUK_DEFPROP_HAVE_CONFIGURABLE;
369 enum DUK_DEFPROP_W = DUK_DEFPROP_WRITABLE;
370 enum DUK_DEFPROP_E = DUK_DEFPROP_ENUMERABLE;
371 enum DUK_DEFPROP_C = DUK_DEFPROP_CONFIGURABLE;
372 enum DUK_DEFPROP_WE = DUK_DEFPROP_WRITABLE | DUK_DEFPROP_ENUMERABLE;
373 enum DUK_DEFPROP_WC = DUK_DEFPROP_WRITABLE | DUK_DEFPROP_CONFIGURABLE;
374 enum DUK_DEFPROP_WEC = DUK_DEFPROP_WRITABLE | DUK_DEFPROP_ENUMERABLE | DUK_DEFPROP_CONFIGURABLE;
375 enum DUK_DEFPROP_HAVE_W = DUK_DEFPROP_HAVE_WRITABLE;
376 enum DUK_DEFPROP_HAVE_E = DUK_DEFPROP_HAVE_ENUMERABLE;
377 enum DUK_DEFPROP_HAVE_C = DUK_DEFPROP_HAVE_CONFIGURABLE;
378 enum DUK_DEFPROP_HAVE_WE = DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_HAVE_ENUMERABLE;
379 enum DUK_DEFPROP_HAVE_WC = DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_HAVE_CONFIGURABLE;
380 enum DUK_DEFPROP_HAVE_WEC = DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_HAVE_CONFIGURABLE;
381 enum DUK_DEFPROP_SET_W = DUK_DEFPROP_SET_WRITABLE;
382 enum DUK_DEFPROP_SET_E = DUK_DEFPROP_SET_ENUMERABLE;
383 enum DUK_DEFPROP_SET_C = DUK_DEFPROP_SET_CONFIGURABLE;
384 enum DUK_DEFPROP_SET_WE = DUK_DEFPROP_SET_WRITABLE | DUK_DEFPROP_SET_ENUMERABLE;
385 enum DUK_DEFPROP_SET_WC = DUK_DEFPROP_SET_WRITABLE | DUK_DEFPROP_SET_CONFIGURABLE;
386 enum DUK_DEFPROP_SET_WEC = DUK_DEFPROP_SET_WRITABLE | DUK_DEFPROP_SET_ENUMERABLE | DUK_DEFPROP_SET_CONFIGURABLE;
387 enum DUK_DEFPROP_CLEAR_W = DUK_DEFPROP_CLEAR_WRITABLE;
388 enum DUK_DEFPROP_CLEAR_E = DUK_DEFPROP_CLEAR_ENUMERABLE;
389 enum DUK_DEFPROP_CLEAR_C = DUK_DEFPROP_CLEAR_CONFIGURABLE;
390 enum DUK_DEFPROP_CLEAR_WE = DUK_DEFPROP_CLEAR_WRITABLE | DUK_DEFPROP_CLEAR_ENUMERABLE;
391 enum DUK_DEFPROP_CLEAR_WC = DUK_DEFPROP_CLEAR_WRITABLE | DUK_DEFPROP_CLEAR_CONFIGURABLE;
392 enum DUK_DEFPROP_CLEAR_WEC = DUK_DEFPROP_CLEAR_WRITABLE | DUK_DEFPROP_CLEAR_ENUMERABLE | DUK_DEFPROP_CLEAR_CONFIGURABLE;
393 enum DUK_DEFPROP_ATTR_W = DUK_DEFPROP_HAVE_WEC | DUK_DEFPROP_W;
394 enum DUK_DEFPROP_ATTR_E = DUK_DEFPROP_HAVE_WEC | DUK_DEFPROP_E;
395 enum DUK_DEFPROP_ATTR_C = DUK_DEFPROP_HAVE_WEC | DUK_DEFPROP_C;
396 enum DUK_DEFPROP_ATTR_WE = DUK_DEFPROP_HAVE_WEC | DUK_DEFPROP_WE;
397 enum DUK_DEFPROP_ATTR_WC = DUK_DEFPROP_HAVE_WEC | DUK_DEFPROP_WC;
398 enum DUK_DEFPROP_ATTR_WEC = DUK_DEFPROP_HAVE_WEC | DUK_DEFPROP_WEC;
399 
400 /* Flags for duk_push_thread_raw() */
401 enum DUK_THREAD_NEW_GLOBAL_ENV = 1U << 0; /* create a new global environment */
402 
403 /* Flags for duk_gc() */
404 enum DUK_GC_COMPACT = 1U << 0; /* compact heap objects */
405 
406 /* Error codes (must be 8 bits at most, see duk_error.h) */
407 enum DUK_ERR_NONE = 0; /* no error (e.g. from duk_get_error_code()) */
408 enum DUK_ERR_ERROR = 1; /* Error */
409 enum DUK_ERR_EVAL_ERROR = 2; /* EvalError */
410 enum DUK_ERR_RANGE_ERROR = 3; /* RangeError */
411 enum DUK_ERR_REFERENCE_ERROR = 4; /* ReferenceError */
412 enum DUK_ERR_SYNTAX_ERROR = 5; /* SyntaxError */
413 enum DUK_ERR_TYPE_ERROR = 6; /* TypeError */
414 enum DUK_ERR_URI_ERROR = 7; /* URIError */
415 
416 /* Return codes for C functions (shortcut for throwing an error) */
417 enum DUK_RET_ERROR = -DUK_ERR_ERROR;
418 enum DUK_RET_EVAL_ERROR = -DUK_ERR_EVAL_ERROR;
419 enum DUK_RET_RANGE_ERROR = -DUK_ERR_RANGE_ERROR;
420 enum DUK_RET_REFERENCE_ERROR = -DUK_ERR_REFERENCE_ERROR;
421 enum DUK_RET_SYNTAX_ERROR = -DUK_ERR_SYNTAX_ERROR;
422 enum DUK_RET_TYPE_ERROR = -DUK_ERR_TYPE_ERROR;
423 enum DUK_RET_URI_ERROR = -DUK_ERR_URI_ERROR;
424 
425 /* Return codes for protected calls (duk_safe_call(), duk_pcall()) */
426 enum DUK_EXEC_SUCCESS = 0;
427 enum DUK_EXEC_ERROR = 1;
428 
429 /* Debug levels for DUK_USE_DEBUG_WRITE(). */
430 enum DUK_LEVEL_DEBUG = 0;
431 enum DUK_LEVEL_DDEBUG = 1;
432 enum DUK_LEVEL_DDDEBUG = 2;
433 
434 /*
435  *  Macros to create Symbols as C statically constructed strings.
436  *
437  *  Call e.g. as DUK_HIDDEN_SYMBOL("myProperty") <=> ("\xFF" "myProperty").
438  *  Local symbols have a unique suffix, caller should take care to avoid
439  *  conflicting with the Duktape internal representation by e.g. prepending
440  *  a '!' character: DUK_LOCAL_SYMBOL("myLocal", "!123").
441  *
442  *  Note that these can only be used for string constants, not dynamically
443  *  created strings.
444  */
445 
446 /*
447  *  If no variadic macros, __FILE__ and __LINE__ are passed through globals
448  *  which is ugly and not thread safe.
449  */
450 
451 /*
452  *  Context management
453  */
454 
455 duk_context* duk_create_heap (
456     duk_alloc_function alloc_func,
457     duk_realloc_function realloc_func,
458     duk_free_function free_func,
459     void* heap_udata,
460     duk_fatal_function fatal_handler);
461 void duk_destroy_heap (duk_context* ctx);
462 
463 void duk_suspend (duk_context* ctx, duk_thread_state* state);
464 void duk_resume (duk_context* ctx, const(duk_thread_state)* state);
465 
466 extern (D) auto duk_create_heap_default()
467 {
468     return duk_create_heap(null, null, null, null, null);
469 }
470 
471 /*
472  *  Memory management
473  *
474  *  Raw functions have no side effects (cannot trigger GC).
475  */
476 
477 void* duk_alloc_raw (duk_context* ctx, duk_size_t size);
478 void duk_free_raw (duk_context* ctx, void* ptr);
479 void* duk_realloc_raw (duk_context* ctx, void* ptr, duk_size_t size);
480 void* duk_alloc (duk_context* ctx, duk_size_t size);
481 void duk_free (duk_context* ctx, void* ptr);
482 void* duk_realloc (duk_context* ctx, void* ptr, duk_size_t size);
483 void duk_get_memory_functions (duk_context* ctx, duk_memory_functions* out_funcs);
484 void duk_gc (duk_context* ctx, duk_uint_t flags);
485 
486 /*
487  *  Error handling
488  */
489 
490 void duk_throw_raw (duk_context* ctx);
491 void duk_fatal_raw (duk_context* ctx, const(char)* err_msg);
492 void duk_error_raw (duk_context* ctx, duk_errcode_t err_code, const(char)* filename, duk_int_t line, const(char)* fmt, ...);
493 
494 /*
495  *  Error handling
496  */
497 void duk_error(duk_context *ctx, duk_errcode_t err_code, const char *fmt, ...)
498 {
499     va_list ap;
500 
501     static if (is(typeof(__va_argsave)))
502         va_start(ap, __va_argsave);
503     else
504         va_start(ap, fmt);
505 
506     duk_error_raw(ctx, cast(duk_errcode_t)err_code, toStringz(__FILE__), cast(duk_int_t)__LINE__, fmt, ap);
507 
508     va_end(ap);
509 }
510 
511 /* DUK_API_VARIADIC_MACROS */
512 /* For legacy compilers without variadic macros a macro hack is used to allow
513  * variable arguments.  While the macro allows "return duk_error(...)", it
514  * will fail with e.g. "(void) duk_error(...)".  The calls are noreturn but
515  * with a return value to allow the "return duk_error(...)" idiom.  This may
516  * cause some compiler warnings, but without noreturn the generated code is
517  * often worse.  The same approach as with variadic macros (using
518  * "(duk_error(...), 0)") won't work due to the macro hack structure.
519  */
520 
521 /* last value is func pointer, arguments follow in parens */
522 
523 /* DUK_API_VARIADIC_MACROS */
524 
525 void duk_error_va_raw (duk_context* ctx, duk_errcode_t err_code, const(char)* filename, duk_int_t line, const(char)* fmt, va_list ap);
526 
527 /*
528  *  Other state related functions
529  */
530 
531 duk_bool_t duk_is_strict_call (duk_context* ctx);
532 duk_bool_t duk_is_constructor_call (duk_context* ctx);
533 
534 /*
535  *  Stack management
536  */
537 
538 duk_idx_t duk_normalize_index (duk_context* ctx, duk_idx_t idx);
539 duk_idx_t duk_require_normalize_index (duk_context* ctx, duk_idx_t idx);
540 duk_bool_t duk_is_valid_index (duk_context* ctx, duk_idx_t idx);
541 void duk_require_valid_index (duk_context* ctx, duk_idx_t idx);
542 
543 duk_idx_t duk_get_top (duk_context* ctx);
544 void duk_set_top (duk_context* ctx, duk_idx_t idx);
545 duk_idx_t duk_get_top_index (duk_context* ctx);
546 duk_idx_t duk_require_top_index (duk_context* ctx);
547 
548 /* Although extra/top could be an unsigned type here, using a signed type
549  * makes the API more robust to calling code calculation errors or corner
550  * cases (where caller might occasionally come up with negative values).
551  * Negative values are treated as zero, which is better than casting them
552  * to a large unsigned number.  (This principle is used elsewhere in the
553  * API too.)
554  */
555 duk_bool_t duk_check_stack (duk_context* ctx, duk_idx_t extra);
556 void duk_require_stack (duk_context* ctx, duk_idx_t extra);
557 duk_bool_t duk_check_stack_top (duk_context* ctx, duk_idx_t top);
558 void duk_require_stack_top (duk_context* ctx, duk_idx_t top);
559 
560 /*
561  *  Stack manipulation (other than push/pop)
562  */
563 
564 void duk_swap (duk_context* ctx, duk_idx_t idx1, duk_idx_t idx2);
565 void duk_swap_top (duk_context* ctx, duk_idx_t idx);
566 void duk_dup (duk_context* ctx, duk_idx_t from_idx);
567 void duk_dup_top (duk_context* ctx);
568 void duk_insert (duk_context* ctx, duk_idx_t to_idx);
569 void duk_replace (duk_context* ctx, duk_idx_t to_idx);
570 void duk_copy (duk_context* ctx, duk_idx_t from_idx, duk_idx_t to_idx);
571 void duk_remove (duk_context* ctx, duk_idx_t idx);
572 void duk_xcopymove_raw (duk_context* to_ctx, duk_context* from_ctx, duk_idx_t count, duk_bool_t is_copy);
573 
574 /*is_copy*/
575 
576 /*is_copy*/
577 
578 /*
579  *  Push operations
580  *
581  *  Push functions return the absolute (relative to bottom of frame)
582  *  position of the pushed value for convenience.
583  *
584  *  Note: duk_dup() is technically a push.
585  */
586 
587 void duk_push_undefined (duk_context* ctx);
588 void duk_push_null (duk_context* ctx);
589 void duk_push_boolean (duk_context* ctx, duk_bool_t val);
590 void duk_push_true (duk_context* ctx);
591 void duk_push_false (duk_context* ctx);
592 void duk_push_number (duk_context* ctx, duk_double_t val);
593 void duk_push_nan (duk_context* ctx);
594 void duk_push_int (duk_context* ctx, duk_int_t val);
595 void duk_push_uint (duk_context* ctx, duk_uint_t val);
596 const(char)* duk_push_string (duk_context* ctx, const(char)* str);
597 const(char)* duk_push_lstring (duk_context* ctx, const(char)* str, duk_size_t len);
598 void duk_push_pointer (duk_context* ctx, void* p);
599 const(char)* duk_push_sprintf (duk_context* ctx, const(char)* fmt, ...);
600 const(char)* duk_push_vsprintf (duk_context* ctx, const(char)* fmt, va_list ap);
601 
602 /* duk_push_literal() may evaluate its argument (a C string literal) more than
603  * once on purpose.  When speed is preferred, sizeof() avoids an unnecessary
604  * strlen() at runtime.  Sizeof("foo") == 4, so subtract 1.  The argument
605  * must be non-NULL and should not contain internal NUL characters as the
606  * behavior will then depend on config options.
607  */
608 
609 const(char)* duk_push_literal_raw (duk_context* ctx, const(char)* str, duk_size_t len);
610 
611 extern (D) auto duk_push_literal(T0, T1)(auto ref T0 ctx, auto ref T1 cstring)
612 {
613     return duk_push_literal_raw(ctx, cstring, (cstring).sizeof - 1U);
614 }
615 
616 void duk_push_this (duk_context* ctx);
617 void duk_push_new_target (duk_context* ctx);
618 void duk_push_current_function (duk_context* ctx);
619 void duk_push_current_thread (duk_context* ctx);
620 void duk_push_global_object (duk_context* ctx);
621 void duk_push_heap_stash (duk_context* ctx);
622 void duk_push_global_stash (duk_context* ctx);
623 void duk_push_thread_stash (duk_context* ctx, duk_context* target_ctx);
624 
625 duk_idx_t duk_push_object (duk_context* ctx);
626 duk_idx_t duk_push_bare_object (duk_context* ctx);
627 duk_idx_t duk_push_array (duk_context* ctx);
628 duk_idx_t duk_push_c_function (duk_context* ctx, duk_c_function func, duk_idx_t nargs);
629 duk_idx_t duk_push_c_lightfunc (duk_context* ctx, duk_c_function func, duk_idx_t nargs, duk_idx_t length, duk_int_t magic);
630 duk_idx_t duk_push_thread_raw (duk_context* ctx, duk_uint_t flags);
631 duk_idx_t duk_push_proxy (duk_context* ctx, duk_uint_t proxy_flags);
632 
633 /*flags*/
634 
635 /*flags*/
636 
637 duk_idx_t duk_push_error_object_raw (duk_context* ctx, duk_errcode_t err_code, const(char)* filename, duk_int_t line, const(char)* fmt, ...);
638 
639 duk_idx_t duk_push_error_object(duk_context *ctx, duk_errcode_t err_code, const char *fmt, ...) {
640     va_list ap;
641 
642     static if (is(typeof(__va_argsave)))
643         va_start(ap, __va_argsave);
644     else
645         va_start(ap, fmt);
646 
647     auto r =  duk_push_error_object_raw(ctx, err_code, toStringz(__FILE__), cast(duk_int_t)__LINE__, fmt, ap);
648 
649     va_end(ap);
650 
651     return r;
652 }
653 
654 /* Note: parentheses are required so that the comma expression works in assignments. */
655 
656 /* last value is func pointer, arguments follow in parens */
657 
658 duk_idx_t duk_push_error_object_va_raw (duk_context* ctx, duk_errcode_t err_code, const(char)* filename, duk_int_t line, const(char)* fmt, va_list ap);
659 
660 extern (D) auto duk_push_error_object_va(T0, T1, T2, T3)(auto ref T0 ctx, auto ref T1 err_code, auto ref T2 fmt, auto ref T3 ap)
661 {
662     return duk_push_error_object_va_raw(ctx, err_code, cast(const(char)*) DUK_FILE_MACRO, cast(duk_int_t) DUK_LINE_MACRO, fmt, ap);
663 }
664 
665 enum DUK_BUF_FLAG_DYNAMIC = 1 << 0; /* internal flag: dynamic buffer */
666 enum DUK_BUF_FLAG_EXTERNAL = 1 << 1; /* internal flag: external buffer */
667 enum DUK_BUF_FLAG_NOZERO = 1 << 2; /* internal flag: don't zero allocated buffer */
668 
669 void* duk_push_buffer_raw (duk_context* ctx, duk_size_t size, duk_small_uint_t flags);
670 
671 /*flags*/
672 
673 /*flags*/
674 
675 enum DUK_BUFOBJ_ARRAYBUFFER = 0;
676 enum DUK_BUFOBJ_NODEJS_BUFFER = 1;
677 enum DUK_BUFOBJ_DATAVIEW = 2;
678 enum DUK_BUFOBJ_INT8ARRAY = 3;
679 enum DUK_BUFOBJ_UINT8ARRAY = 4;
680 enum DUK_BUFOBJ_UINT8CLAMPEDARRAY = 5;
681 enum DUK_BUFOBJ_INT16ARRAY = 6;
682 enum DUK_BUFOBJ_UINT16ARRAY = 7;
683 enum DUK_BUFOBJ_INT32ARRAY = 8;
684 enum DUK_BUFOBJ_UINT32ARRAY = 9;
685 enum DUK_BUFOBJ_FLOAT32ARRAY = 10;
686 enum DUK_BUFOBJ_FLOAT64ARRAY = 11;
687 
688 void duk_push_buffer_object (duk_context* ctx, duk_idx_t idx_buffer, duk_size_t byte_offset, duk_size_t byte_length, duk_uint_t flags);
689 
690 duk_idx_t duk_push_heapptr (duk_context* ctx, void* ptr);
691 
692 /*
693  *  Pop operations
694  */
695 
696 void duk_pop (duk_context* ctx);
697 void duk_pop_n (duk_context* ctx, duk_idx_t count);
698 void duk_pop_2 (duk_context* ctx);
699 void duk_pop_3 (duk_context* ctx);
700 
701 /*
702  *  Type checks
703  *
704  *  duk_is_none(), which would indicate whether index it outside of stack,
705  *  is not needed; duk_is_valid_index() gives the same information.
706  */
707 
708 duk_int_t duk_get_type (duk_context* ctx, duk_idx_t idx);
709 duk_bool_t duk_check_type (duk_context* ctx, duk_idx_t idx, duk_int_t type);
710 duk_uint_t duk_get_type_mask (duk_context* ctx, duk_idx_t idx);
711 duk_bool_t duk_check_type_mask (duk_context* ctx, duk_idx_t idx, duk_uint_t mask);
712 
713 duk_bool_t duk_is_undefined (duk_context* ctx, duk_idx_t idx);
714 duk_bool_t duk_is_null (duk_context* ctx, duk_idx_t idx);
715 
716 extern (D) int duk_is_null_or_undefined(T0, T1)(auto ref T0 ctx, auto ref T1 idx)
717 {
718     return (duk_get_type_mask(ctx, idx) & (DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_UNDEFINED)) ? 1 : 0;
719 }
720 
721 duk_bool_t duk_is_boolean (duk_context* ctx, duk_idx_t idx);
722 duk_bool_t duk_is_number (duk_context* ctx, duk_idx_t idx);
723 duk_bool_t duk_is_nan (duk_context* ctx, duk_idx_t idx);
724 duk_bool_t duk_is_string (duk_context* ctx, duk_idx_t idx);
725 duk_bool_t duk_is_object (duk_context* ctx, duk_idx_t idx);
726 duk_bool_t duk_is_buffer (duk_context* ctx, duk_idx_t idx);
727 duk_bool_t duk_is_buffer_data (duk_context* ctx, duk_idx_t idx);
728 duk_bool_t duk_is_pointer (duk_context* ctx, duk_idx_t idx);
729 duk_bool_t duk_is_lightfunc (duk_context* ctx, duk_idx_t idx);
730 
731 duk_bool_t duk_is_symbol (duk_context* ctx, duk_idx_t idx);
732 duk_bool_t duk_is_array (duk_context* ctx, duk_idx_t idx);
733 duk_bool_t duk_is_function (duk_context* ctx, duk_idx_t idx);
734 duk_bool_t duk_is_c_function (duk_context* ctx, duk_idx_t idx);
735 duk_bool_t duk_is_ecmascript_function (duk_context* ctx, duk_idx_t idx);
736 duk_bool_t duk_is_bound_function (duk_context* ctx, duk_idx_t idx);
737 duk_bool_t duk_is_thread (duk_context* ctx, duk_idx_t idx);
738 
739 alias duk_is_callable = duk_is_function;
740 duk_bool_t duk_is_constructable (duk_context* ctx, duk_idx_t idx);
741 
742 duk_bool_t duk_is_dynamic_buffer (duk_context* ctx, duk_idx_t idx);
743 duk_bool_t duk_is_fixed_buffer (duk_context* ctx, duk_idx_t idx);
744 duk_bool_t duk_is_external_buffer (duk_context* ctx, duk_idx_t idx);
745 
746 /* Buffers and lightfuncs are not considered primitive because they mimic
747  * objects and e.g. duk_to_primitive() will coerce them instead of returning
748  * them as is.  Symbols are represented as strings internally.
749  */
750 
751 /* Symbols are object coercible, covered by DUK_TYPE_MASK_STRING. */
752 
753 duk_errcode_t duk_get_error_code (duk_context* ctx, duk_idx_t idx);
754 
755 extern (D) auto duk_is_error(T0, T1)(auto ref T0 ctx, auto ref T1 idx)
756 {
757     return duk_get_error_code(ctx, idx) != 0;
758 }
759 
760 extern (D) auto duk_is_eval_error(T0, T1)(auto ref T0 ctx, auto ref T1 idx)
761 {
762     return duk_get_error_code(ctx, idx) == DUK_ERR_EVAL_ERROR;
763 }
764 
765 extern (D) auto duk_is_range_error(T0, T1)(auto ref T0 ctx, auto ref T1 idx)
766 {
767     return duk_get_error_code(ctx, idx) == DUK_ERR_RANGE_ERROR;
768 }
769 
770 extern (D) auto duk_is_reference_error(T0, T1)(auto ref T0 ctx, auto ref T1 idx)
771 {
772     return duk_get_error_code(ctx, idx) == DUK_ERR_REFERENCE_ERROR;
773 }
774 
775 extern (D) auto duk_is_syntax_error(T0, T1)(auto ref T0 ctx, auto ref T1 idx)
776 {
777     return duk_get_error_code(ctx, idx) == DUK_ERR_SYNTAX_ERROR;
778 }
779 
780 extern (D) auto duk_is_type_error(T0, T1)(auto ref T0 ctx, auto ref T1 idx)
781 {
782     return duk_get_error_code(ctx, idx) == DUK_ERR_TYPE_ERROR;
783 }
784 
785 extern (D) auto duk_is_uri_error(T0, T1)(auto ref T0 ctx, auto ref T1 idx)
786 {
787     return duk_get_error_code(ctx, idx) == DUK_ERR_URI_ERROR;
788 }
789 
790 /*
791  *  Get operations: no coercion, returns default value for invalid
792  *  indices and invalid value types.
793  *
794  *  duk_get_undefined() and duk_get_null() would be pointless and
795  *  are not included.
796  */
797 
798 duk_bool_t duk_get_boolean (duk_context* ctx, duk_idx_t idx);
799 duk_double_t duk_get_number (duk_context* ctx, duk_idx_t idx);
800 duk_int_t duk_get_int (duk_context* ctx, duk_idx_t idx);
801 duk_uint_t duk_get_uint (duk_context* ctx, duk_idx_t idx);
802 const(char)* duk_get_string (duk_context* ctx, duk_idx_t idx);
803 const(char)* duk_get_lstring (duk_context* ctx, duk_idx_t idx, duk_size_t* out_len);
804 void* duk_get_buffer (duk_context* ctx, duk_idx_t idx, duk_size_t* out_size);
805 void* duk_get_buffer_data (duk_context* ctx, duk_idx_t idx, duk_size_t* out_size);
806 void* duk_get_pointer (duk_context* ctx, duk_idx_t idx);
807 duk_c_function duk_get_c_function (duk_context* ctx, duk_idx_t idx);
808 duk_context* duk_get_context (duk_context* ctx, duk_idx_t idx);
809 void* duk_get_heapptr (duk_context* ctx, duk_idx_t idx);
810 
811 /*
812  *  Get-with-explicit default operations: like get operations but with an
813  *  explicit default value.
814  */
815 
816 duk_bool_t duk_get_boolean_default (duk_context* ctx, duk_idx_t idx, duk_bool_t def_value);
817 duk_double_t duk_get_number_default (duk_context* ctx, duk_idx_t idx, duk_double_t def_value);
818 duk_int_t duk_get_int_default (duk_context* ctx, duk_idx_t idx, duk_int_t def_value);
819 duk_uint_t duk_get_uint_default (duk_context* ctx, duk_idx_t idx, duk_uint_t def_value);
820 const(char)* duk_get_string_default (duk_context* ctx, duk_idx_t idx, const(char)* def_value);
821 const(char)* duk_get_lstring_default (duk_context* ctx, duk_idx_t idx, duk_size_t* out_len, const(char)* def_ptr, duk_size_t def_len);
822 void* duk_get_buffer_default (duk_context* ctx, duk_idx_t idx, duk_size_t* out_size, void* def_ptr, duk_size_t def_len);
823 void* duk_get_buffer_data_default (duk_context* ctx, duk_idx_t idx, duk_size_t* out_size, void* def_ptr, duk_size_t def_len);
824 void* duk_get_pointer_default (duk_context* ctx, duk_idx_t idx, void* def_value);
825 duk_c_function duk_get_c_function_default (duk_context* ctx, duk_idx_t idx, duk_c_function def_value);
826 duk_context* duk_get_context_default (duk_context* ctx, duk_idx_t idx, duk_context* def_value);
827 void* duk_get_heapptr_default (duk_context* ctx, duk_idx_t idx, void* def_value);
828 
829 /*
830  *  Opt operations: like require operations but with an explicit default value
831  *  when value is undefined or index is invalid, null and non-matching types
832  *  cause a TypeError.
833  */
834 
835 duk_bool_t duk_opt_boolean (duk_context* ctx, duk_idx_t idx, duk_bool_t def_value);
836 duk_double_t duk_opt_number (duk_context* ctx, duk_idx_t idx, duk_double_t def_value);
837 duk_int_t duk_opt_int (duk_context* ctx, duk_idx_t idx, duk_int_t def_value);
838 duk_uint_t duk_opt_uint (duk_context* ctx, duk_idx_t idx, duk_uint_t def_value);
839 const(char)* duk_opt_string (duk_context* ctx, duk_idx_t idx, const(char)* def_ptr);
840 const(char)* duk_opt_lstring (duk_context* ctx, duk_idx_t idx, duk_size_t* out_len, const(char)* def_ptr, duk_size_t def_len);
841 void* duk_opt_buffer (duk_context* ctx, duk_idx_t idx, duk_size_t* out_size, void* def_ptr, duk_size_t def_size);
842 void* duk_opt_buffer_data (duk_context* ctx, duk_idx_t idx, duk_size_t* out_size, void* def_ptr, duk_size_t def_size);
843 void* duk_opt_pointer (duk_context* ctx, duk_idx_t idx, void* def_value);
844 duk_c_function duk_opt_c_function (duk_context* ctx, duk_idx_t idx, duk_c_function def_value);
845 duk_context* duk_opt_context (duk_context* ctx, duk_idx_t idx, duk_context* def_value);
846 void* duk_opt_heapptr (duk_context* ctx, duk_idx_t idx, void* def_value);
847 
848 /*
849  *  Require operations: no coercion, throw error if index or type
850  *  is incorrect.  No defaulting.
851  */
852 
853 void duk_require_undefined (duk_context* ctx, duk_idx_t idx);
854 void duk_require_null (duk_context* ctx, duk_idx_t idx);
855 duk_bool_t duk_require_boolean (duk_context* ctx, duk_idx_t idx);
856 duk_double_t duk_require_number (duk_context* ctx, duk_idx_t idx);
857 duk_int_t duk_require_int (duk_context* ctx, duk_idx_t idx);
858 duk_uint_t duk_require_uint (duk_context* ctx, duk_idx_t idx);
859 const(char)* duk_require_string (duk_context* ctx, duk_idx_t idx);
860 const(char)* duk_require_lstring (duk_context* ctx, duk_idx_t idx, duk_size_t* out_len);
861 void duk_require_object (duk_context* ctx, duk_idx_t idx);
862 void* duk_require_buffer (duk_context* ctx, duk_idx_t idx, duk_size_t* out_size);
863 void* duk_require_buffer_data (duk_context* ctx, duk_idx_t idx, duk_size_t* out_size);
864 void* duk_require_pointer (duk_context* ctx, duk_idx_t idx);
865 duk_c_function duk_require_c_function (duk_context* ctx, duk_idx_t idx);
866 duk_context* duk_require_context (duk_context* ctx, duk_idx_t idx);
867 void duk_require_function (duk_context* ctx, duk_idx_t idx);
868 alias duk_require_callable = duk_require_function;
869 void* duk_require_heapptr (duk_context* ctx, duk_idx_t idx);
870 
871 /* Symbols are object coercible and covered by DUK_TYPE_MASK_STRING. */
872 
873 /*
874  *  Coercion operations: in-place coercion, return coerced value where
875  *  applicable.  If index is invalid, throw error.  Some coercions may
876  *  throw an expected error (e.g. from a toString() or valueOf() call)
877  *  or an internal error (e.g. from out of memory).
878  */
879 
880 void duk_to_undefined (duk_context* ctx, duk_idx_t idx);
881 void duk_to_null (duk_context* ctx, duk_idx_t idx);
882 duk_bool_t duk_to_boolean (duk_context* ctx, duk_idx_t idx);
883 duk_double_t duk_to_number (duk_context* ctx, duk_idx_t idx);
884 duk_int_t duk_to_int (duk_context* ctx, duk_idx_t idx);
885 duk_uint_t duk_to_uint (duk_context* ctx, duk_idx_t idx);
886 duk_int32_t duk_to_int32 (duk_context* ctx, duk_idx_t idx);
887 duk_uint32_t duk_to_uint32 (duk_context* ctx, duk_idx_t idx);
888 duk_uint16_t duk_to_uint16 (duk_context* ctx, duk_idx_t idx);
889 const(char)* duk_to_string (duk_context* ctx, duk_idx_t idx);
890 const(char)* duk_to_lstring (duk_context* ctx, duk_idx_t idx, duk_size_t* out_len);
891 void* duk_to_buffer_raw (duk_context* ctx, duk_idx_t idx, duk_size_t* out_size, duk_uint_t flags);
892 void* duk_to_pointer (duk_context* ctx, duk_idx_t idx);
893 void duk_to_object (duk_context* ctx, duk_idx_t idx);
894 void duk_to_primitive (duk_context* ctx, duk_idx_t idx, duk_int_t hint);
895 
896 enum DUK_BUF_MODE_FIXED = 0; /* internal: request fixed buffer result */
897 enum DUK_BUF_MODE_DYNAMIC = 1; /* internal: request dynamic buffer result */
898 enum DUK_BUF_MODE_DONTCARE = 2; /* internal: don't care about fixed/dynamic nature */
899 
900 extern (D) auto duk_to_buffer(T0, T1, T2)(auto ref T0 ctx, auto ref T1 idx, auto ref T2 out_size)
901 {
902     return duk_to_buffer_raw(ctx, idx, out_size, DUK_BUF_MODE_DONTCARE);
903 }
904 
905 extern (D) auto duk_to_fixed_buffer(T0, T1, T2)(auto ref T0 ctx, auto ref T1 idx, auto ref T2 out_size)
906 {
907     return duk_to_buffer_raw(ctx, idx, out_size, DUK_BUF_MODE_FIXED);
908 }
909 
910 extern (D) auto duk_to_dynamic_buffer(T0, T1, T2)(auto ref T0 ctx, auto ref T1 idx, auto ref T2 out_size)
911 {
912     return duk_to_buffer_raw(ctx, idx, out_size, DUK_BUF_MODE_DYNAMIC);
913 }
914 
915 /* safe variants of a few coercion operations */
916 const(char)* duk_safe_to_lstring (duk_context* ctx, duk_idx_t idx, duk_size_t* out_len);
917 
918 extern (D) auto duk_safe_to_string(T0, T1)(auto ref T0 ctx, auto ref T1 idx)
919 {
920     return duk_safe_to_lstring(ctx, idx, null);
921 }
922 
923 /*
924  *  Value length
925  */
926 
927 duk_size_t duk_get_length (duk_context* ctx, duk_idx_t idx);
928 void duk_set_length (duk_context* ctx, duk_idx_t idx, duk_size_t len);
929 
930 /* duk_require_length()? */
931 /* duk_opt_length()? */
932 
933 /*
934  *  Misc conversion
935  */
936 
937 const(char)* duk_base64_encode (duk_context* ctx, duk_idx_t idx);
938 void duk_base64_decode (duk_context* ctx, duk_idx_t idx);
939 const(char)* duk_hex_encode (duk_context* ctx, duk_idx_t idx);
940 void duk_hex_decode (duk_context* ctx, duk_idx_t idx);
941 const(char)* duk_json_encode (duk_context* ctx, duk_idx_t idx);
942 void duk_json_decode (duk_context* ctx, duk_idx_t idx);
943 
944 const(char)* duk_buffer_to_string (duk_context* ctx, duk_idx_t idx);
945 
946 /*
947  *  Buffer
948  */
949 
950 void* duk_resize_buffer (duk_context* ctx, duk_idx_t idx, duk_size_t new_size);
951 void* duk_steal_buffer (duk_context* ctx, duk_idx_t idx, duk_size_t* out_size);
952 void duk_config_buffer (duk_context* ctx, duk_idx_t idx, void* ptr, duk_size_t len);
953 
954 /*
955  *  Property access
956  *
957  *  The basic function assumes key is on stack.  The _(l)string variant takes
958  *  a C string as a property name; the _literal variant takes a C literal.
959  *  The _index variant takes an array index as a property name (e.g. 123 is
960  *  equivalent to the key "123").  The _heapptr variant takes a raw, borrowed
961  *  heap pointer.
962  */
963 
964 duk_bool_t duk_get_prop (duk_context* ctx, duk_idx_t obj_idx);
965 duk_bool_t duk_get_prop_string (duk_context* ctx, duk_idx_t obj_idx, const(char)* key);
966 duk_bool_t duk_get_prop_lstring (duk_context* ctx, duk_idx_t obj_idx, const(char)* key, duk_size_t key_len);
967 
968 duk_bool_t duk_get_prop_literal_raw (duk_context* ctx, duk_idx_t obj_idx, const(char)* key, duk_size_t key_len);
969 
970 extern (D) auto duk_get_prop_literal(T0, T1, T2)(auto ref T0 ctx, auto ref T1 obj_idx, auto ref T2 key)
971 {
972     return duk_get_prop_literal_raw(ctx, obj_idx, key, (key).sizeof - 1U);
973 }
974 
975 duk_bool_t duk_get_prop_index (duk_context* ctx, duk_idx_t obj_idx, duk_uarridx_t arr_idx);
976 duk_bool_t duk_get_prop_heapptr (duk_context* ctx, duk_idx_t obj_idx, void* ptr);
977 duk_bool_t duk_put_prop (duk_context* ctx, duk_idx_t obj_idx);
978 duk_bool_t duk_put_prop_string (duk_context* ctx, duk_idx_t obj_idx, const(char)* key);
979 duk_bool_t duk_put_prop_lstring (duk_context* ctx, duk_idx_t obj_idx, const(char)* key, duk_size_t key_len);
980 
981 duk_bool_t duk_put_prop_literal_raw (duk_context* ctx, duk_idx_t obj_idx, const(char)* key, duk_size_t key_len);
982 
983 extern (D) auto duk_put_prop_literal(T0, T1, T2)(auto ref T0 ctx, auto ref T1 obj_idx, auto ref T2 key)
984 {
985     return duk_put_prop_literal_raw(ctx, obj_idx, key, (key).sizeof - 1U);
986 }
987 
988 duk_bool_t duk_put_prop_index (duk_context* ctx, duk_idx_t obj_idx, duk_uarridx_t arr_idx);
989 duk_bool_t duk_put_prop_heapptr (duk_context* ctx, duk_idx_t obj_idx, void* ptr);
990 duk_bool_t duk_del_prop (duk_context* ctx, duk_idx_t obj_idx);
991 duk_bool_t duk_del_prop_string (duk_context* ctx, duk_idx_t obj_idx, const(char)* key);
992 duk_bool_t duk_del_prop_lstring (duk_context* ctx, duk_idx_t obj_idx, const(char)* key, duk_size_t key_len);
993 
994 duk_bool_t duk_del_prop_literal_raw (duk_context* ctx, duk_idx_t obj_idx, const(char)* key, duk_size_t key_len);
995 
996 extern (D) auto duk_del_prop_literal(T0, T1, T2)(auto ref T0 ctx, auto ref T1 obj_idx, auto ref T2 key)
997 {
998     return duk_del_prop_literal_raw(ctx, obj_idx, key, (key).sizeof - 1U);
999 }
1000 
1001 duk_bool_t duk_del_prop_index (duk_context* ctx, duk_idx_t obj_idx, duk_uarridx_t arr_idx);
1002 duk_bool_t duk_del_prop_heapptr (duk_context* ctx, duk_idx_t obj_idx, void* ptr);
1003 duk_bool_t duk_has_prop (duk_context* ctx, duk_idx_t obj_idx);
1004 duk_bool_t duk_has_prop_string (duk_context* ctx, duk_idx_t obj_idx, const(char)* key);
1005 duk_bool_t duk_has_prop_lstring (duk_context* ctx, duk_idx_t obj_idx, const(char)* key, duk_size_t key_len);
1006 
1007 duk_bool_t duk_has_prop_literal_raw (duk_context* ctx, duk_idx_t obj_idx, const(char)* key, duk_size_t key_len);
1008 
1009 extern (D) auto duk_has_prop_literal(T0, T1, T2)(auto ref T0 ctx, auto ref T1 obj_idx, auto ref T2 key)
1010 {
1011     return duk_has_prop_literal_raw(ctx, obj_idx, key, (key).sizeof - 1U);
1012 }
1013 
1014 duk_bool_t duk_has_prop_index (duk_context* ctx, duk_idx_t obj_idx, duk_uarridx_t arr_idx);
1015 duk_bool_t duk_has_prop_heapptr (duk_context* ctx, duk_idx_t obj_idx, void* ptr);
1016 
1017 void duk_get_prop_desc (duk_context* ctx, duk_idx_t obj_idx, duk_uint_t flags);
1018 void duk_def_prop (duk_context* ctx, duk_idx_t obj_idx, duk_uint_t flags);
1019 
1020 duk_bool_t duk_get_global_string (duk_context* ctx, const(char)* key);
1021 duk_bool_t duk_get_global_lstring (duk_context* ctx, const(char)* key, duk_size_t key_len);
1022 
1023 duk_bool_t duk_get_global_literal_raw (duk_context* ctx, const(char)* key, duk_size_t key_len);
1024 
1025 extern (D) auto duk_get_global_literal(T0, T1)(auto ref T0 ctx, auto ref T1 key)
1026 {
1027     return duk_get_global_literal_raw(ctx, key, (key).sizeof - 1U);
1028 }
1029 
1030 duk_bool_t duk_get_global_heapptr (duk_context* ctx, void* ptr);
1031 duk_bool_t duk_put_global_string (duk_context* ctx, const(char)* key);
1032 duk_bool_t duk_put_global_lstring (duk_context* ctx, const(char)* key, duk_size_t key_len);
1033 
1034 duk_bool_t duk_put_global_literal_raw (duk_context* ctx, const(char)* key, duk_size_t key_len);
1035 
1036 extern (D) auto duk_put_global_literal(T0, T1)(auto ref T0 ctx, auto ref T1 key)
1037 {
1038     return duk_put_global_literal_raw(ctx, key, (key).sizeof - 1U);
1039 }
1040 
1041 duk_bool_t duk_put_global_heapptr (duk_context* ctx, void* ptr);
1042 
1043 /*
1044  *  Inspection
1045  */
1046 
1047 void duk_inspect_value (duk_context* ctx, duk_idx_t idx);
1048 void duk_inspect_callstack_entry (duk_context* ctx, duk_int_t level);
1049 
1050 /*
1051  *  Object prototype
1052  */
1053 
1054 void duk_get_prototype (duk_context* ctx, duk_idx_t idx);
1055 void duk_set_prototype (duk_context* ctx, duk_idx_t idx);
1056 
1057 /*
1058  *  Object finalizer
1059  */
1060 
1061 void duk_get_finalizer (duk_context* ctx, duk_idx_t idx);
1062 void duk_set_finalizer (duk_context* ctx, duk_idx_t idx);
1063 
1064 /*
1065  *  Global object
1066  */
1067 
1068 void duk_set_global_object (duk_context* ctx);
1069 
1070 /*
1071  *  Duktape/C function magic value
1072  */
1073 
1074 duk_int_t duk_get_magic (duk_context* ctx, duk_idx_t idx);
1075 void duk_set_magic (duk_context* ctx, duk_idx_t idx, duk_int_t magic);
1076 duk_int_t duk_get_current_magic (duk_context* ctx);
1077 
1078 /*
1079  *  Module helpers: put multiple function or constant properties
1080  */
1081 
1082 void duk_put_function_list (duk_context* ctx, duk_idx_t obj_idx, const(duk_function_list_entry)* funcs);
1083 void duk_put_number_list (duk_context* ctx, duk_idx_t obj_idx, const(duk_number_list_entry)* numbers);
1084 
1085 /*
1086  *  Object operations
1087  */
1088 
1089 void duk_compact (duk_context* ctx, duk_idx_t obj_idx);
1090 void duk_enum (duk_context* ctx, duk_idx_t obj_idx, duk_uint_t enum_flags);
1091 duk_bool_t duk_next (duk_context* ctx, duk_idx_t enum_idx, duk_bool_t get_value);
1092 void duk_seal (duk_context* ctx, duk_idx_t obj_idx);
1093 void duk_freeze (duk_context* ctx, duk_idx_t obj_idx);
1094 
1095 /*
1096  *  String manipulation
1097  */
1098 
1099 void duk_concat (duk_context* ctx, duk_idx_t count);
1100 void duk_join (duk_context* ctx, duk_idx_t count);
1101 void duk_decode_string (duk_context* ctx, duk_idx_t idx, duk_decode_char_function callback, void* udata);
1102 void duk_map_string (duk_context* ctx, duk_idx_t idx, duk_map_char_function callback, void* udata);
1103 void duk_substring (duk_context* ctx, duk_idx_t idx, duk_size_t start_char_offset, duk_size_t end_char_offset);
1104 void duk_trim (duk_context* ctx, duk_idx_t idx);
1105 duk_codepoint_t duk_char_code_at (duk_context* ctx, duk_idx_t idx, duk_size_t char_offset);
1106 
1107 /*
1108  *  ECMAScript operators
1109  */
1110 
1111 duk_bool_t duk_equals (duk_context* ctx, duk_idx_t idx1, duk_idx_t idx2);
1112 duk_bool_t duk_strict_equals (duk_context* ctx, duk_idx_t idx1, duk_idx_t idx2);
1113 duk_bool_t duk_samevalue (duk_context* ctx, duk_idx_t idx1, duk_idx_t idx2);
1114 duk_bool_t duk_instanceof (duk_context* ctx, duk_idx_t idx1, duk_idx_t idx2);
1115 
1116 /*
1117  *  Random
1118  */
1119 
1120 duk_double_t duk_random (duk_context* ctx);
1121 
1122 /*
1123  *  Function (method) calls
1124  */
1125 
1126 void duk_call (duk_context* ctx, duk_idx_t nargs);
1127 void duk_call_method (duk_context* ctx, duk_idx_t nargs);
1128 void duk_call_prop (duk_context* ctx, duk_idx_t obj_idx, duk_idx_t nargs);
1129 duk_int_t duk_pcall (duk_context* ctx, duk_idx_t nargs);
1130 duk_int_t duk_pcall_method (duk_context* ctx, duk_idx_t nargs);
1131 duk_int_t duk_pcall_prop (duk_context* ctx, duk_idx_t obj_idx, duk_idx_t nargs);
1132 void duk_new (duk_context* ctx, duk_idx_t nargs);
1133 duk_int_t duk_pnew (duk_context* ctx, duk_idx_t nargs);
1134 duk_int_t duk_safe_call (duk_context* ctx, duk_safe_call_function func, void* udata, duk_idx_t nargs, duk_idx_t nrets);
1135 
1136 /*
1137  *  Thread management
1138  */
1139 
1140 /* There are currently no native functions to yield/resume, due to the internal
1141  * limitations on coroutine handling.  These will be added later.
1142  */
1143 
1144 /*
1145  *  Compilation and evaluation
1146  */
1147 
1148 duk_int_t duk_eval_raw (duk_context* ctx, const(char)* src_buffer, duk_size_t src_length, duk_uint_t flags);
1149 duk_int_t duk_compile_raw (duk_context* ctx, const(char)* src_buffer, duk_size_t src_length, duk_uint_t flags);
1150 
1151 /* plain */
1152 void duk_eval(duk_context *ctx) {
1153     duk_eval_raw(ctx, null, 0, 2 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOFILENAME);
1154 }
1155 
1156 void duk_eval_noresult(duk_context *ctx) {
1157     duk_eval_raw(ctx, null, 0, 2 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME);
1158 }
1159 
1160 duk_int_t duk_peval(duk_context *ctx) {
1161     return duk_eval_raw(ctx, null, 0, 2 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOFILENAME);
1162 }
1163 
1164 duk_int_t duk_peval_noresult(duk_context *ctx) {
1165     return duk_eval_raw(ctx, null, 0, 2 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME);
1166 }
1167 
1168 void duk_compile(duk_context *ctx, duk_uint_t flags) {
1169     duk_compile_raw(ctx, null, 0, 3 /*args*/ | flags);
1170 }
1171 
1172 duk_int_t duk_pcompile(duk_context *ctx, duk_uint_t flags) {
1173     return duk_compile_raw(ctx, null, 0, 3 /*args*/ | flags | DUK_COMPILE_SAFE);
1174 }
1175 
1176 /* string */
1177 void duk_eval_string(duk_context *ctx, const char *src) {
1178     duk_eval_raw(ctx, src, 0, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME);
1179 }
1180 
1181 void duk_eval_string_noresult(duk_context *ctx, const char *src) {
1182     duk_eval_raw(ctx, src, 0, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME);
1183 }
1184 
1185 duk_int_t duk_peval_string(duk_context *ctx, const char *src) {
1186     return duk_eval_raw(ctx, src, 0, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME);
1187 }
1188 
1189 duk_int_t duk_peval_string_noresult(duk_context *ctx, const char *src) {
1190     return duk_eval_raw(ctx, src, 0, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME);
1191 }
1192 
1193 void duk_compile_string(duk_context *ctx, duk_uint_t flags, const char *src) {
1194     duk_compile_raw(ctx, src, 0, 1 /*args*/ | flags | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME);
1195 }
1196 
1197 void duk_compile_string_filename(duk_context *ctx, duk_uint_t flags, const char *src) {
1198     duk_compile_raw(ctx, src, 0, 2 /*args*/ | flags | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN);
1199 }
1200 
1201 duk_int_t duk_pcompile_string(duk_context *ctx, duk_uint_t flags, const char *src) {
1202     return duk_compile_raw(ctx, src, 0, 1 /*args*/ | flags | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME);
1203 }
1204 
1205 duk_int_t duk_pcompile_string_filename(duk_context *ctx, duk_uint_t flags, const char *src) {
1206     return duk_compile_raw(ctx, src, 0, 2 /*args*/ | flags | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN);
1207 }
1208 
1209 /* lstring */
1210 void duk_eval_lstring(duk_context *ctx, const char *buf, duk_size_t len)  {
1211     duk_eval_raw(ctx, buf, len, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NOFILENAME);
1212 }
1213 
1214 void duk_eval_lstring_noresult(duk_context *ctx, const char *buf, duk_size_t len)  {
1215     duk_eval_raw(ctx, buf, len, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME);
1216 }
1217 
1218 duk_int_t duk_peval_lstring(duk_context *ctx, const char *buf, duk_size_t len)  {
1219     return duk_eval_raw(ctx, buf, len, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_SAFE | DUK_COMPILE_NOFILENAME);
1220 }
1221 
1222 duk_int_t duk_peval_lstring_noresult(duk_context *ctx, const char *buf, duk_size_t len)  {
1223     return duk_eval_raw(ctx, buf, len, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME);
1224 }
1225 
1226 void duk_compile_lstring(duk_context *ctx, duk_uint_t flags, const char *buf, duk_size_t len)  {
1227     duk_compile_raw(ctx, buf, len, 1 /*args*/ | flags | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NOFILENAME);
1228 }
1229 
1230 void duk_compile_lstring_filename(duk_context *ctx, duk_uint_t flags, const char *buf, duk_size_t len)  {
1231     duk_compile_raw(ctx, buf, len, 2 /*args*/ | flags | DUK_COMPILE_NOSOURCE);
1232 }
1233 
1234 duk_int_t duk_pcompile_lstring(duk_context *ctx, duk_uint_t flags, const char *buf, duk_size_t len)  {
1235     return duk_compile_raw(ctx, buf, len, 1 /*args*/ | flags | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NOFILENAME);
1236 }
1237 
1238 duk_int_t duk_pcompile_lstring_filename(duk_context *ctx, duk_uint_t flags, const char *buf, duk_size_t len)  {
1239     return duk_compile_raw(ctx, buf, len, 2 /*args*/ | flags | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE);
1240 }
1241 
1242 
1243 /*
1244  *  Bytecode load/dump
1245  */
1246 
1247 void duk_dump_function (duk_context* ctx);
1248 void duk_load_function (duk_context* ctx);
1249 
1250 /*
1251  *  Debugging
1252  */
1253 
1254 void duk_push_context_dump (duk_context* ctx);
1255 
1256 /*
1257  *  Debugger (debug protocol)
1258  */
1259 
1260 void duk_debugger_attach (
1261     duk_context* ctx,
1262     duk_debug_read_function read_cb,
1263     duk_debug_write_function write_cb,
1264     duk_debug_peek_function peek_cb,
1265     duk_debug_read_flush_function read_flush_cb,
1266     duk_debug_write_flush_function write_flush_cb,
1267     duk_debug_request_function request_cb,
1268     duk_debug_detached_function detached_cb,
1269     void* udata);
1270 void duk_debugger_detach (duk_context* ctx);
1271 void duk_debugger_cooperate (duk_context* ctx);
1272 duk_bool_t duk_debugger_notify (duk_context* ctx, duk_idx_t nvalues);
1273 void duk_debugger_pause (duk_context* ctx);
1274 
1275 /*
1276  *  Time handling
1277  */
1278 
1279 duk_double_t duk_get_now (duk_context* ctx);
1280 void duk_time_to_components (duk_context* ctx, duk_double_t timeval, duk_time_components* comp);
1281 duk_double_t duk_components_to_time (duk_context* ctx, duk_time_components* comp);
1282 
1283 /*
1284  *  Date provider related constants
1285  *
1286  *  NOTE: These are "semi public" - you should only use these if you write
1287  *  your own platform specific Date provider, see doc/datetime.rst.
1288  */
1289 
1290 /* Millisecond count constants. */
1291 enum DUK_DATE_MSEC_SECOND = 1000L;
1292 enum DUK_DATE_MSEC_MINUTE = 60L * 1000L;
1293 enum DUK_DATE_MSEC_HOUR = 60L * 60L * 1000L;
1294 enum DUK_DATE_MSEC_DAY = 24L * 60L * 60L * 1000L;
1295 
1296 /* ECMAScript date range is 100 million days from Epoch:
1297  * > 100e6 * 24 * 60 * 60 * 1000  // 100M days in millisecs
1298  * 8640000000000000
1299  * (= 8.64e15)
1300  */
1301 enum DUK_DATE_MSEC_100M_DAYS = 8.64e15;
1302 enum DUK_DATE_MSEC_100M_DAYS_LEEWAY = 8.64e15 + 24 * 3600e3;
1303 
1304 /* ECMAScript year range:
1305  * > new Date(100e6 * 24 * 3600e3).toISOString()
1306  * '+275760-09-13T00:00:00.000Z'
1307  * > new Date(-100e6 * 24 * 3600e3).toISOString()
1308  * '-271821-04-20T00:00:00.000Z'
1309  */
1310 enum DUK_DATE_MIN_ECMA_YEAR = -271821L;
1311 enum DUK_DATE_MAX_ECMA_YEAR = 275760L;
1312 
1313 /* Part indices for internal breakdowns.  Part order from DUK_DATE_IDX_YEAR
1314  * to DUK_DATE_IDX_MILLISECOND matches argument ordering of ECMAScript API
1315  * calls (like Date constructor call).  Some functions in duk_bi_date.c
1316  * depend on the specific ordering, so change with care.  16 bits are not
1317  * enough for all parts (year, specifically).
1318  *
1319  * Must be in-sync with genbuiltins.py.
1320  */
1321 enum DUK_DATE_IDX_YEAR = 0; /* year */
1322 enum DUK_DATE_IDX_MONTH = 1; /* month: 0 to 11 */
1323 enum DUK_DATE_IDX_DAY = 2; /* day within month: 0 to 30 */
1324 enum DUK_DATE_IDX_HOUR = 3;
1325 enum DUK_DATE_IDX_MINUTE = 4;
1326 enum DUK_DATE_IDX_SECOND = 5;
1327 enum DUK_DATE_IDX_MILLISECOND = 6;
1328 enum DUK_DATE_IDX_WEEKDAY = 7; /* weekday: 0 to 6, 0=sunday, 1=monday, etc */
1329 enum DUK_DATE_IDX_NUM_PARTS = 8;
1330 
1331 /* Internal API call flags, used for various functions in duk_bi_date.c.
1332  * Certain flags are used by only certain functions, but since the flags
1333  * don't overlap, a single flags value can be passed around to multiple
1334  * functions.
1335  *
1336  * The unused top bits of the flags field are also used to pass values
1337  * to helpers (duk__get_part_helper() and duk__set_part_helper()).
1338  *
1339  * Must be in-sync with genbuiltins.py.
1340  */
1341 
1342 /* NOTE: when writing a Date provider you only need a few specific
1343  * flags from here, the rest are internal.  Avoid using anything you
1344  * don't need.
1345  */
1346 
1347 enum DUK_DATE_FLAG_NAN_TO_ZERO = 1 << 0; /* timeval breakdown: internal time value NaN -> zero */
1348 enum DUK_DATE_FLAG_NAN_TO_RANGE_ERROR = 1 << 1; /* timeval breakdown: internal time value NaN -> RangeError (toISOString) */
1349 enum DUK_DATE_FLAG_ONEBASED = 1 << 2; /* timeval breakdown: convert month and day-of-month parts to one-based (default is zero-based) */
1350 enum DUK_DATE_FLAG_EQUIVYEAR = 1 << 3; /* timeval breakdown: replace year with equivalent year in the [1971,2037] range for DST calculations */
1351 enum DUK_DATE_FLAG_LOCALTIME = 1 << 4; /* convert time value to local time */
1352 enum DUK_DATE_FLAG_SUB1900 = 1 << 5; /* getter: subtract 1900 from year when getting year part */
1353 enum DUK_DATE_FLAG_TOSTRING_DATE = 1 << 6; /* include date part in string conversion result */
1354 enum DUK_DATE_FLAG_TOSTRING_TIME = 1 << 7; /* include time part in string conversion result */
1355 enum DUK_DATE_FLAG_TOSTRING_LOCALE = 1 << 8; /* use locale specific formatting if available */
1356 enum DUK_DATE_FLAG_TIMESETTER = 1 << 9; /* setter: call is a time setter (affects hour, min, sec, ms); otherwise date setter (affects year, month, day-in-month) */
1357 enum DUK_DATE_FLAG_YEAR_FIXUP = 1 << 10; /* setter: perform 2-digit year fixup (00...99 -> 1900...1999) */
1358 enum DUK_DATE_FLAG_SEP_T = 1 << 11; /* string conversion: use 'T' instead of ' ' as a separator */
1359 enum DUK_DATE_FLAG_VALUE_SHIFT = 12; /* additional values begin at bit 12 */
1360 
1361 /*
1362  *  ROM pointer compression
1363  */
1364 
1365 /* Support array for ROM pointer compression.  Only declared when ROM
1366  * pointer compression is active.
1367  */
1368 
1369 /*
1370  *  C++ name mangling
1371  */
1372 
1373 /* end 'extern "C"' wrapper */
1374 
1375 /*
1376  *  END PUBLIC API
1377  */
1378 
1379 /* DUKTAPE_H_INCLUDED */