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