comparison extern/duktape/duktape.h @ 501:4c786b58eacd

Import duktape 1.4.0
author David Demelier <markand@malikania.fr>
date Thu, 28 Jan 2016 09:25:19 +0100
parents e2cefd0ee511
children
comparison
equal deleted inserted replaced
500:d8ed4da7688c 501:4c786b58eacd
1 /* 1 /*
2 * Duktape public API for Duktape 1.3.0. 2 * Duktape public API for Duktape 1.4.0.
3 * See the API reference for documentation on call semantics. 3 * See the API reference for documentation on call semantics.
4 * The exposed API is inside the DUK_API_PUBLIC_H_INCLUDED 4 * The exposed API is inside the DUK_API_PUBLIC_H_INCLUDED
5 * include guard. Other parts of the header are Duktape 5 * include guard. Other parts of the header are Duktape
6 * internal and related to platform/compiler/feature detection. 6 * internal and related to platform/compiler/feature detection.
7 * 7 *
8 * Git commit 675165f35ea3a5bac34ff4d0a58b007cc2f442dc (v1.3.0). 8 * Git commit cad6f595382a0cc1a7e4207794ade5be11b3e397 (v1.4.0).
9 * Git branch master.
9 * 10 *
10 * See Duktape AUTHORS.rst and LICENSE.txt for copyright and 11 * See Duktape AUTHORS.rst and LICENSE.txt for copyright and
11 * licensing information. 12 * licensing information.
12 */ 13 */
13 14
17 * Duktape license 18 * Duktape license
18 * =============== 19 * ===============
19 * 20 *
20 * (http://opensource.org/licenses/MIT) 21 * (http://opensource.org/licenses/MIT)
21 * 22 *
22 * Copyright (c) 2013-2015 by Duktape authors (see AUTHORS.rst) 23 * Copyright (c) 2013-2016 by Duktape authors (see AUTHORS.rst)
23 * 24 *
24 * Permission is hereby granted, free of charge, to any person obtaining a copy 25 * Permission is hereby granted, free of charge, to any person obtaining a copy
25 * of this software and associated documentation files (the "Software"), to deal 26 * of this software and associated documentation files (the "Software"), to deal
26 * in the Software without restriction, including without limitation the rights 27 * in the Software without restriction, including without limitation the rights
27 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 28 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
68 * * Andreas \u00d6man <andreas@lonelycoder.com> 69 * * Andreas \u00d6man <andreas@lonelycoder.com>
69 * * L\u00e1szl\u00f3 Lang\u00f3 <llango.u-szeged@partner.samsung.com> 70 * * L\u00e1szl\u00f3 Lang\u00f3 <llango.u-szeged@partner.samsung.com>
70 * * Legimet <legimet.calc@gmail.com> 71 * * Legimet <legimet.calc@gmail.com>
71 * * Karl Skomski <karl@skomski.com> 72 * * Karl Skomski <karl@skomski.com>
72 * * Bruce Pascoe <fatcerberus1@gmail.com> 73 * * Bruce Pascoe <fatcerberus1@gmail.com>
74 * * Ren\u00e9 Hollander <rene@rene8888.at>
73 * 75 *
74 * Other contributions 76 * Other contributions
75 * =================== 77 * ===================
76 * 78 *
77 * The following people have contributed something other than code (e.g. reported 79 * The following people have contributed something other than code (e.g. reported
104 * * Bruce E. Pascoe (https://github.com/fatcerberus) 106 * * Bruce E. Pascoe (https://github.com/fatcerberus)
105 * * https://github.com/Kelledin 107 * * https://github.com/Kelledin
106 * * https://github.com/sstruchtrup 108 * * https://github.com/sstruchtrup
107 * * Michael Drake (https://github.com/tlsa) 109 * * Michael Drake (https://github.com/tlsa)
108 * * https://github.com/chris-y 110 * * https://github.com/chris-y
111 * * Laurent Zubiaur (https://github.com/lzubiaur)
109 * 112 *
110 * If you are accidentally missing from this list, send me an e-mail 113 * If you are accidentally missing from this list, send me an e-mail
111 * (``sami.vaarala@iki.fi``) and I'll fix the omission. 114 * (``sami.vaarala@iki.fi``) and I'll fix the omission.
112 */ 115 */
113 116
208 * to #ifdef against Duktape API version. The same value is also available 211 * to #ifdef against Duktape API version. The same value is also available
209 * to Ecmascript code in Duktape.version. Unofficial development snapshots 212 * to Ecmascript code in Duktape.version. Unofficial development snapshots
210 * have 99 for patch level (e.g. 0.10.99 would be a development version 213 * have 99 for patch level (e.g. 0.10.99 would be a development version
211 * after 0.10.0 but before the next official release). 214 * after 0.10.0 but before the next official release).
212 */ 215 */
213 #define DUK_VERSION 10300L 216 #define DUK_VERSION 10400L
214 217
215 /* Git describe for Duktape build. Useful for non-official snapshot builds 218 /* Git commit, describe, and branch for Duktape build. Useful for
216 * so that application code can easily log which Duktape snapshot was used. 219 * non-official snapshot builds so that application code can easily log
217 * Not available in the Ecmascript environment. 220 * which Duktape snapshot was used. Not available in the Ecmascript
218 */ 221 * environment.
219 #define DUK_GIT_DESCRIBE "v1.3.0" 222 */
223 #define DUK_GIT_COMMIT "cad6f595382a0cc1a7e4207794ade5be11b3e397"
224 #define DUK_GIT_DESCRIBE "v1.4.0"
225 #define DUK_GIT_BRANCH "master"
220 226
221 /* Duktape debug protocol version used by this build. */ 227 /* Duktape debug protocol version used by this build. */
222 #define DUK_DEBUG_PROTOCOL_VERSION 1 228 #define DUK_DEBUG_PROTOCOL_VERSION 1
223 229
224 /* Used to represent invalid index; if caller uses this without checking, 230 /* Used to represent invalid index; if caller uses this without checking,
236 * guaranteed to be allocated on entry to a Duktape/C function. 242 * guaranteed to be allocated on entry to a Duktape/C function.
237 */ 243 */
238 #define DUK_API_ENTRY_STACK 64 244 #define DUK_API_ENTRY_STACK 64
239 245
240 /* Value types, used by e.g. duk_get_type() */ 246 /* Value types, used by e.g. duk_get_type() */
247 #define DUK_TYPE_MIN 0
241 #define DUK_TYPE_NONE 0 /* no value, e.g. invalid index */ 248 #define DUK_TYPE_NONE 0 /* no value, e.g. invalid index */
242 #define DUK_TYPE_UNDEFINED 1 /* Ecmascript undefined */ 249 #define DUK_TYPE_UNDEFINED 1 /* Ecmascript undefined */
243 #define DUK_TYPE_NULL 2 /* Ecmascript null */ 250 #define DUK_TYPE_NULL 2 /* Ecmascript null */
244 #define DUK_TYPE_BOOLEAN 3 /* Ecmascript boolean: 0 or 1 */ 251 #define DUK_TYPE_BOOLEAN 3 /* Ecmascript boolean: 0 or 1 */
245 #define DUK_TYPE_NUMBER 4 /* Ecmascript number: double */ 252 #define DUK_TYPE_NUMBER 4 /* Ecmascript number: double */
246 #define DUK_TYPE_STRING 5 /* Ecmascript string: CESU-8 / extended UTF-8 encoded */ 253 #define DUK_TYPE_STRING 5 /* Ecmascript string: CESU-8 / extended UTF-8 encoded */
247 #define DUK_TYPE_OBJECT 6 /* Ecmascript object: includes objects, arrays, functions, threads */ 254 #define DUK_TYPE_OBJECT 6 /* Ecmascript object: includes objects, arrays, functions, threads */
248 #define DUK_TYPE_BUFFER 7 /* fixed or dynamic, garbage collected byte buffer */ 255 #define DUK_TYPE_BUFFER 7 /* fixed or dynamic, garbage collected byte buffer */
249 #define DUK_TYPE_POINTER 8 /* raw void pointer */ 256 #define DUK_TYPE_POINTER 8 /* raw void pointer */
250 #define DUK_TYPE_LIGHTFUNC 9 /* lightweight function pointer */ 257 #define DUK_TYPE_LIGHTFUNC 9 /* lightweight function pointer */
258 #define DUK_TYPE_MAX 9
251 259
252 /* Value mask types, used by e.g. duk_get_type_mask() */ 260 /* Value mask types, used by e.g. duk_get_type_mask() */
253 #define DUK_TYPE_MASK_NONE (1 << DUK_TYPE_NONE) 261 #define DUK_TYPE_MASK_NONE (1 << DUK_TYPE_NONE)
254 #define DUK_TYPE_MASK_UNDEFINED (1 << DUK_TYPE_UNDEFINED) 262 #define DUK_TYPE_MASK_UNDEFINED (1 << DUK_TYPE_UNDEFINED)
255 #define DUK_TYPE_MASK_NULL (1 << DUK_TYPE_NULL) 263 #define DUK_TYPE_MASK_NULL (1 << DUK_TYPE_NULL)
295 #define DUK_DEFPROP_HAVE_CONFIGURABLE (1 << 5) /* set/clear configurable */ 303 #define DUK_DEFPROP_HAVE_CONFIGURABLE (1 << 5) /* set/clear configurable */
296 #define DUK_DEFPROP_HAVE_VALUE (1 << 6) /* set value (given on value stack) */ 304 #define DUK_DEFPROP_HAVE_VALUE (1 << 6) /* set value (given on value stack) */
297 #define DUK_DEFPROP_HAVE_GETTER (1 << 7) /* set getter (given on value stack) */ 305 #define DUK_DEFPROP_HAVE_GETTER (1 << 7) /* set getter (given on value stack) */
298 #define DUK_DEFPROP_HAVE_SETTER (1 << 8) /* set setter (given on value stack) */ 306 #define DUK_DEFPROP_HAVE_SETTER (1 << 8) /* set setter (given on value stack) */
299 #define DUK_DEFPROP_FORCE (1 << 9) /* force change if possible, may still fail for e.g. virtual properties */ 307 #define DUK_DEFPROP_FORCE (1 << 9) /* force change if possible, may still fail for e.g. virtual properties */
308 #define DUK_DEFPROP_SET_WRITABLE (DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_WRITABLE)
309 #define DUK_DEFPROP_CLEAR_WRITABLE DUK_DEFPROP_HAVE_WRITABLE
310 #define DUK_DEFPROP_SET_ENUMERABLE (DUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_ENUMERABLE)
311 #define DUK_DEFPROP_CLEAR_ENUMERABLE DUK_DEFPROP_HAVE_ENUMERABLE
312 #define DUK_DEFPROP_SET_CONFIGURABLE (DUK_DEFPROP_HAVE_CONFIGURABLE | DUK_DEFPROP_CONFIGURABLE)
313 #define DUK_DEFPROP_CLEAR_CONFIGURABLE DUK_DEFPROP_HAVE_CONFIGURABLE
300 314
301 /* Flags for duk_push_thread_raw() */ 315 /* Flags for duk_push_thread_raw() */
302 #define DUK_THREAD_NEW_GLOBAL_ENV (1 << 0) /* create a new global environment */ 316 #define DUK_THREAD_NEW_GLOBAL_ENV (1 << 0) /* create a new global environment */
303 317
304 /* Flags for duk_push_string_file_raw() */ 318 /* Flags for duk_push_string_file_raw() */
542 #define DUK_BUF_FLAG_NOZERO (1 << 2) /* internal flag: don't zero allocated buffer */ 556 #define DUK_BUF_FLAG_NOZERO (1 << 2) /* internal flag: don't zero allocated buffer */
543 557
544 DUK_EXTERNAL_DECL void *duk_push_buffer_raw(duk_context *ctx, duk_size_t size, duk_small_uint_t flags); 558 DUK_EXTERNAL_DECL void *duk_push_buffer_raw(duk_context *ctx, duk_size_t size, duk_small_uint_t flags);
545 559
546 #define duk_push_buffer(ctx,size,dynamic) \ 560 #define duk_push_buffer(ctx,size,dynamic) \
547 duk_push_buffer_raw((ctx), (size), (dynamic) ? DUK_BUF_FLAG_DYNAMIC : 0); 561 duk_push_buffer_raw((ctx), (size), (dynamic) ? DUK_BUF_FLAG_DYNAMIC : 0)
548 #define duk_push_fixed_buffer(ctx,size) \ 562 #define duk_push_fixed_buffer(ctx,size) \
549 duk_push_buffer_raw((ctx), (size), 0 /*flags*/) 563 duk_push_buffer_raw((ctx), (size), 0 /*flags*/)
550 #define duk_push_dynamic_buffer(ctx,size) \ 564 #define duk_push_dynamic_buffer(ctx,size) \
551 duk_push_buffer_raw((ctx), (size), DUK_BUF_FLAG_DYNAMIC /*flags*/) 565 duk_push_buffer_raw((ctx), (size), DUK_BUF_FLAG_DYNAMIC /*flags*/)
552 #define duk_push_external_buffer(ctx) \ 566 #define duk_push_external_buffer(ctx) \
609 DUK_EXTERNAL_DECL duk_bool_t duk_is_c_function(duk_context *ctx, duk_idx_t index); 623 DUK_EXTERNAL_DECL duk_bool_t duk_is_c_function(duk_context *ctx, duk_idx_t index);
610 DUK_EXTERNAL_DECL duk_bool_t duk_is_ecmascript_function(duk_context *ctx, duk_idx_t index); 624 DUK_EXTERNAL_DECL duk_bool_t duk_is_ecmascript_function(duk_context *ctx, duk_idx_t index);
611 DUK_EXTERNAL_DECL duk_bool_t duk_is_bound_function(duk_context *ctx, duk_idx_t index); 625 DUK_EXTERNAL_DECL duk_bool_t duk_is_bound_function(duk_context *ctx, duk_idx_t index);
612 DUK_EXTERNAL_DECL duk_bool_t duk_is_thread(duk_context *ctx, duk_idx_t index); 626 DUK_EXTERNAL_DECL duk_bool_t duk_is_thread(duk_context *ctx, duk_idx_t index);
613 627
614 DUK_EXTERNAL_DECL duk_bool_t duk_is_callable(duk_context *ctx, duk_idx_t index); 628 #define duk_is_callable(ctx,index) \
629 duk_is_function((ctx), (index))
615 DUK_EXTERNAL_DECL duk_bool_t duk_is_dynamic_buffer(duk_context *ctx, duk_idx_t index); 630 DUK_EXTERNAL_DECL duk_bool_t duk_is_dynamic_buffer(duk_context *ctx, duk_idx_t index);
616 DUK_EXTERNAL_DECL duk_bool_t duk_is_fixed_buffer(duk_context *ctx, duk_idx_t index); 631 DUK_EXTERNAL_DECL duk_bool_t duk_is_fixed_buffer(duk_context *ctx, duk_idx_t index);
617 DUK_EXTERNAL_DECL duk_bool_t duk_is_external_buffer(duk_context *ctx, duk_idx_t index); 632 DUK_EXTERNAL_DECL duk_bool_t duk_is_external_buffer(duk_context *ctx, duk_idx_t index);
618 633
619 #define duk_is_primitive(ctx,index) \ 634 #define duk_is_primitive(ctx,index) \
636 DUK_TYPE_MASK_LIGHTFUNC) 651 DUK_TYPE_MASK_LIGHTFUNC)
637 652
638 DUK_EXTERNAL_DECL duk_errcode_t duk_get_error_code(duk_context *ctx, duk_idx_t index); 653 DUK_EXTERNAL_DECL duk_errcode_t duk_get_error_code(duk_context *ctx, duk_idx_t index);
639 #define duk_is_error(ctx,index) \ 654 #define duk_is_error(ctx,index) \
640 (duk_get_error_code((ctx), (index)) != 0) 655 (duk_get_error_code((ctx), (index)) != 0)
656 #define duk_is_eval_error(ctx,index) \
657 (duk_get_error_code((ctx), (index)) == DUK_ERR_EVAL_ERROR)
658 #define duk_is_range_error(ctx,index) \
659 (duk_get_error_code((ctx), (index)) == DUK_ERR_RANGE_ERROR)
660 #define duk_is_reference_error(ctx,index) \
661 (duk_get_error_code((ctx), (index)) == DUK_ERR_REFERENCE_ERROR)
662 #define duk_is_syntax_error(ctx,index) \
663 (duk_get_error_code((ctx), (index)) == DUK_ERR_SYNTAX_ERROR)
664 #define duk_is_type_error(ctx,index) \
665 (duk_get_error_code((ctx), (index)) == DUK_ERR_TYPE_ERROR)
666 #define duk_is_uri_error(ctx,index) \
667 (duk_get_error_code((ctx), (index)) == DUK_ERR_URI_ERROR)
641 668
642 /* 669 /*
643 * Get operations: no coercion, returns default value for invalid 670 * Get operations: no coercion, returns default value for invalid
644 * indices and invalid value types. 671 * indices and invalid value types.
645 * 672 *
680 DUK_EXTERNAL_DECL void *duk_require_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size); 707 DUK_EXTERNAL_DECL void *duk_require_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size);
681 DUK_EXTERNAL_DECL void *duk_require_buffer_data(duk_context *ctx, duk_idx_t index, duk_size_t *out_size); 708 DUK_EXTERNAL_DECL void *duk_require_buffer_data(duk_context *ctx, duk_idx_t index, duk_size_t *out_size);
682 DUK_EXTERNAL_DECL void *duk_require_pointer(duk_context *ctx, duk_idx_t index); 709 DUK_EXTERNAL_DECL void *duk_require_pointer(duk_context *ctx, duk_idx_t index);
683 DUK_EXTERNAL_DECL duk_c_function duk_require_c_function(duk_context *ctx, duk_idx_t index); 710 DUK_EXTERNAL_DECL duk_c_function duk_require_c_function(duk_context *ctx, duk_idx_t index);
684 DUK_EXTERNAL_DECL duk_context *duk_require_context(duk_context *ctx, duk_idx_t index); 711 DUK_EXTERNAL_DECL duk_context *duk_require_context(duk_context *ctx, duk_idx_t index);
712 DUK_EXTERNAL_DECL void duk_require_function(duk_context *ctx, duk_idx_t index);
713 #define duk_require_callable(ctx,index) \
714 duk_require_function((ctx), (index))
685 DUK_EXTERNAL_DECL void *duk_require_heapptr(duk_context *ctx, duk_idx_t index); 715 DUK_EXTERNAL_DECL void *duk_require_heapptr(duk_context *ctx, duk_idx_t index);
686 716
687 #define duk_require_object_coercible(ctx,index) \ 717 #define duk_require_object_coercible(ctx,index) \
688 ((void) duk_check_type_mask((ctx), (index), DUK_TYPE_MASK_BOOLEAN | \ 718 ((void) duk_check_type_mask((ctx), (index), DUK_TYPE_MASK_BOOLEAN | \
689 DUK_TYPE_MASK_NUMBER | \ 719 DUK_TYPE_MASK_NUMBER | \
1201 */ 1231 */
1202 1232
1203 union duk_double_union { 1233 union duk_double_union {
1204 double d; 1234 double d;
1205 float f[2]; 1235 float f[2];
1206 #ifdef DUK_USE_64BIT_OPS 1236 #if defined(DUK_USE_64BIT_OPS)
1207 duk_uint64_t ull[1]; 1237 duk_uint64_t ull[1];
1208 #endif 1238 #endif
1209 duk_uint32_t ui[2]; 1239 duk_uint32_t ui[2];
1210 duk_uint16_t us[4]; 1240 duk_uint16_t us[4];
1211 duk_uint8_t uc[8]; 1241 duk_uint8_t uc[8];
1212 #ifdef DUK_USE_PACKED_TVAL_POSSIBLE 1242 #if defined(DUK_USE_PACKED_TVAL)
1213 void *vp[2]; /* used by packed duk_tval, assumes sizeof(void *) == 4 */ 1243 void *vp[2]; /* used by packed duk_tval, assumes sizeof(void *) == 4 */
1214 #endif 1244 #endif
1215 }; 1245 };
1216 1246
1217 typedef union duk_double_union duk_double_union; 1247 typedef union duk_double_union duk_double_union;
1346 * using the packed duk_tval representation. NaN normalization is necessary 1376 * using the packed duk_tval representation. NaN normalization is necessary
1347 * to keep double values compatible with the duk_tval format. 1377 * to keep double values compatible with the duk_tval format.
1348 * 1378 *
1349 * When packed duk_tval is used, the NaN space is used to store pointers 1379 * When packed duk_tval is used, the NaN space is used to store pointers
1350 * and other tagged values in addition to NaNs. Actual NaNs are normalized 1380 * and other tagged values in addition to NaNs. Actual NaNs are normalized
1351 * to a specific format. The macros below are used by the implementation 1381 * to a specific quiet NaN. The macros below are used by the implementation
1352 * to check and normalize NaN values when they might be created. The macros 1382 * to check and normalize NaN values when they might be created. The macros
1353 * are essentially NOPs when the non-packed duk_tval representation is used. 1383 * are essentially NOPs when the non-packed duk_tval representation is used.
1354 * 1384 *
1355 * A FULL check is exact and checks all bits. A NOTFULL check is used by 1385 * A FULL check is exact and checks all bits. A NOTFULL check is used by
1356 * the packed duk_tval and works correctly for all NaNs except those that 1386 * the packed duk_tval and works correctly for all NaNs except those that
1357 * begin with 0x7ff0. Since the 'normalized NaN' values used with packed 1387 * begin with 0x7ff0. Since the 'normalized NaN' values used with packed
1358 * duk_tval begin with 0x7ff8, the partial check is reliable when packed 1388 * duk_tval begin with 0x7ff8, the partial check is reliable when packed
1359 * duk_tval is used. 1389 * duk_tval is used. The 0x7ff8 prefix means the normalized NaN will be a
1390 * quiet NaN regardless of its remaining lower bits.
1360 * 1391 *
1361 * The ME variant below is specifically for ARM byte order, which has the 1392 * The ME variant below is specifically for ARM byte order, which has the
1362 * feature that while doubles have a mixed byte order (32107654), unsigned 1393 * feature that while doubles have a mixed byte order (32107654), unsigned
1363 * long long values has a little endian byte order (76543210). When writing 1394 * long long values has a little endian byte order (76543210). When writing
1364 * a logical double value through a ULL pointer, the 32-bit words need to be 1395 * a logical double value through a ULL pointer, the 32-bit words need to be