duktape 1.3.0.6 → 2.6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,13 @@
1
1
  /*
2
- * Duktape public API for Duktape 1.3.0.
3
- * See the API reference for documentation on call semantics.
4
- * The exposed API is inside the DUK_API_PUBLIC_H_INCLUDED
5
- * include guard. Other parts of the header are Duktape
6
- * internal and related to platform/compiler/feature detection.
2
+ * Duktape public API for Duktape 2.6.0.
7
3
  *
8
- * Git commit 675165f35ea3a5bac34ff4d0a58b007cc2f442dc (v1.3.0).
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 ee81aa9e0076e8049edbfe6aea96702e04f1827d (v2.0.1.0-13-gee81aa9-dirty).
10
+ * Git branch duktape-2.6.
9
11
  *
10
12
  * See Duktape AUTHORS.rst and LICENSE.txt for copyright and
11
13
  * licensing information.
@@ -19,7 +21,7 @@
19
21
  *
20
22
  * (http://opensource.org/licenses/MIT)
21
23
  *
22
- * Copyright (c) 2013-2015 by Duktape authors (see AUTHORS.rst)
24
+ * Copyright (c) 2013-2019 by Duktape authors (see AUTHORS.rst)
23
25
  *
24
26
  * Permission is hereby granted, free of charge, to any person obtaining a copy
25
27
  * of this software and associated documentation files (the "Software"), to deal
@@ -70,6 +72,44 @@
70
72
  * * Legimet <legimet.calc@gmail.com>
71
73
  * * Karl Skomski <karl@skomski.com>
72
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)
73
113
  *
74
114
  * Other contributions
75
115
  * ===================
@@ -106,34 +146,60 @@
106
146
  * * https://github.com/sstruchtrup
107
147
  * * Michael Drake (https://github.com/tlsa)
108
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)
109
155
  *
110
156
  * If you are accidentally missing from this list, send me an e-mail
111
157
  * (``sami.vaarala@iki.fi``) and I'll fix the omission.
112
158
  */
113
159
 
114
- #ifndef DUKTAPE_H_INCLUDED
160
+ #if !defined(DUKTAPE_H_INCLUDED)
115
161
  #define DUKTAPE_H_INCLUDED
116
162
 
117
163
  #define DUK_SINGLE_FILE
118
164
 
119
- /* External duk_config.h provides platform/compiler/OS dependent
120
- * typedefs and macros, and DUK_USE_xxx config options so that
121
- * the rest of Duktape doesn't need to do any feature detection.
165
+ /*
166
+ * BEGIN PUBLIC API
122
167
  */
123
- #include "duk_config.h"
124
168
 
125
169
  /*
126
- * BEGIN PUBLIC API
170
+ * Version and Git commit identification
127
171
  */
128
172
 
129
- #ifndef DUK_API_PUBLIC_H_INCLUDED
130
- #define DUK_API_PUBLIC_H_INCLUDED
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 "ee81aa9e0076e8049edbfe6aea96702e04f1827d"
187
+ #define DUK_GIT_DESCRIBE "v2.0.1.0-13-gee81aa9-dirty"
188
+ #define DUK_GIT_BRANCH "duktape-2.6"
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"
131
197
 
132
198
  /*
133
199
  * Avoid C++ name mangling
134
200
  */
135
201
 
136
- #ifdef __cplusplus
202
+ #if defined(__cplusplus)
137
203
  extern "C" {
138
204
  #endif
139
205
 
@@ -142,7 +208,7 @@ extern "C" {
142
208
  */
143
209
 
144
210
  #undef DUK_API_VARIADIC_MACROS
145
- #ifdef DUK_USE_VARIADIC_MACROS
211
+ #if defined(DUK_USE_VARIADIC_MACROS)
146
212
  #define DUK_API_VARIADIC_MACROS
147
213
  #endif
148
214
 
@@ -156,31 +222,44 @@ extern "C" {
156
222
  * in Duktape web documentation.
157
223
  */
158
224
 
225
+ struct duk_thread_state;
159
226
  struct duk_memory_functions;
160
227
  struct duk_function_list_entry;
161
228
  struct duk_number_list_entry;
229
+ struct duk_time_components;
162
230
 
163
231
  /* duk_context is now defined in duk_config.h because it may also be
164
232
  * referenced there by prototypes.
165
233
  */
234
+ typedef struct duk_thread_state duk_thread_state;
166
235
  typedef struct duk_memory_functions duk_memory_functions;
167
236
  typedef struct duk_function_list_entry duk_function_list_entry;
168
237
  typedef struct duk_number_list_entry duk_number_list_entry;
238
+ typedef struct duk_time_components duk_time_components;
169
239
 
170
240
  typedef duk_ret_t (*duk_c_function)(duk_context *ctx);
171
241
  typedef void *(*duk_alloc_function) (void *udata, duk_size_t size);
172
242
  typedef void *(*duk_realloc_function) (void *udata, void *ptr, duk_size_t size);
173
243
  typedef void (*duk_free_function) (void *udata, void *ptr);
174
- typedef void (*duk_fatal_function) (duk_context *ctx, duk_errcode_t code, const char *msg);
244
+ typedef void (*duk_fatal_function) (void *udata, const char *msg);
175
245
  typedef void (*duk_decode_char_function) (void *udata, duk_codepoint_t codepoint);
176
246
  typedef duk_codepoint_t (*duk_map_char_function) (void *udata, duk_codepoint_t codepoint);
177
- typedef duk_ret_t (*duk_safe_call_function) (duk_context *ctx);
247
+ typedef duk_ret_t (*duk_safe_call_function) (duk_context *ctx, void *udata);
178
248
  typedef duk_size_t (*duk_debug_read_function) (void *udata, char *buffer, duk_size_t length);
179
249
  typedef duk_size_t (*duk_debug_write_function) (void *udata, const char *buffer, duk_size_t length);
180
250
  typedef duk_size_t (*duk_debug_peek_function) (void *udata);
181
251
  typedef void (*duk_debug_read_flush_function) (void *udata);
182
252
  typedef void (*duk_debug_write_flush_function) (void *udata);
183
- typedef void (*duk_debug_detached_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
+ };
184
263
 
185
264
  struct duk_memory_functions {
186
265
  duk_alloc_function alloc_func;
@@ -200,26 +279,23 @@ struct duk_number_list_entry {
200
279
  duk_double_t value;
201
280
  };
202
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
+
203
293
  /*
204
294
  * Constants
205
295
  */
206
296
 
207
- /* Duktape version, (major * 10000) + (minor * 100) + patch. Allows C code
208
- * to #ifdef against Duktape API version. The same value is also available
209
- * 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
211
- * after 0.10.0 but before the next official release).
212
- */
213
- #define DUK_VERSION 10300L
214
-
215
- /* Git describe for Duktape build. Useful for non-official snapshot builds
216
- * so that application code can easily log which Duktape snapshot was used.
217
- * Not available in the Ecmascript environment.
218
- */
219
- #define DUK_GIT_DESCRIBE "v1.3.0"
220
-
221
297
  /* Duktape debug protocol version used by this build. */
222
- #define DUK_DEBUG_PROTOCOL_VERSION 1
298
+ #define DUK_DEBUG_PROTOCOL_VERSION 2
223
299
 
224
300
  /* Used to represent invalid index; if caller uses this without checking,
225
301
  * this index will map to a non-existent stack entry. Also used in some
@@ -235,32 +311,35 @@ struct duk_number_list_entry {
235
311
  /* Number of value stack entries (in addition to actual call arguments)
236
312
  * guaranteed to be allocated on entry to a Duktape/C function.
237
313
  */
238
- #define DUK_API_ENTRY_STACK 64
314
+ #define DUK_API_ENTRY_STACK 64U
239
315
 
240
316
  /* Value types, used by e.g. duk_get_type() */
241
- #define DUK_TYPE_NONE 0 /* no value, e.g. invalid index */
242
- #define DUK_TYPE_UNDEFINED 1 /* Ecmascript undefined */
243
- #define DUK_TYPE_NULL 2 /* Ecmascript null */
244
- #define DUK_TYPE_BOOLEAN 3 /* Ecmascript boolean: 0 or 1 */
245
- #define DUK_TYPE_NUMBER 4 /* Ecmascript number: double */
246
- #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 */
248
- #define DUK_TYPE_BUFFER 7 /* fixed or dynamic, garbage collected byte buffer */
249
- #define DUK_TYPE_POINTER 8 /* raw void pointer */
250
- #define DUK_TYPE_LIGHTFUNC 9 /* lightweight function pointer */
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
251
329
 
252
330
  /* Value mask types, used by e.g. duk_get_type_mask() */
253
- #define DUK_TYPE_MASK_NONE (1 << DUK_TYPE_NONE)
254
- #define DUK_TYPE_MASK_UNDEFINED (1 << DUK_TYPE_UNDEFINED)
255
- #define DUK_TYPE_MASK_NULL (1 << DUK_TYPE_NULL)
256
- #define DUK_TYPE_MASK_BOOLEAN (1 << DUK_TYPE_BOOLEAN)
257
- #define DUK_TYPE_MASK_NUMBER (1 << DUK_TYPE_NUMBER)
258
- #define DUK_TYPE_MASK_STRING (1 << DUK_TYPE_STRING)
259
- #define DUK_TYPE_MASK_OBJECT (1 << DUK_TYPE_OBJECT)
260
- #define DUK_TYPE_MASK_BUFFER (1 << DUK_TYPE_BUFFER)
261
- #define DUK_TYPE_MASK_POINTER (1 << DUK_TYPE_POINTER)
262
- #define DUK_TYPE_MASK_LIGHTFUNC (1 << DUK_TYPE_LIGHTFUNC)
263
- #define DUK_TYPE_MASK_THROW (1 << 10) /* internal flag value: throw if mask doesn't match */
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 */
264
343
 
265
344
  /* Coercion hints */
266
345
  #define DUK_HINT_NONE 0 /* prefer number, unless input is a Date, in which
@@ -270,67 +349,100 @@ struct duk_number_list_entry {
270
349
  #define DUK_HINT_NUMBER 2 /* prefer number */
271
350
 
272
351
  /* Enumeration flags for duk_enum() */
273
- #define DUK_ENUM_INCLUDE_NONENUMERABLE (1 << 0) /* enumerate non-numerable properties in addition to enumerable */
274
- #define DUK_ENUM_INCLUDE_INTERNAL (1 << 1) /* enumerate internal properties (regardless of enumerability) */
275
- #define DUK_ENUM_OWN_PROPERTIES_ONLY (1 << 2) /* don't walk prototype chain, only check own properties */
276
- #define DUK_ENUM_ARRAY_INDICES_ONLY (1 << 3) /* only enumerate array indices */
277
- #define DUK_ENUM_SORT_ARRAY_INDICES (1 << 4) /* sort array indices, use with DUK_ENUM_ARRAY_INDICES_ONLY */
278
- #define DUK_ENUM_NO_PROXY_BEHAVIOR (1 << 5) /* enumerate a proxy object itself without invoking proxy behavior */
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 */
279
361
 
280
362
  /* Compilation flags for duk_compile() and duk_eval() */
281
- #define DUK_COMPILE_EVAL (1 << 0) /* compile eval code (instead of global code) */
282
- #define DUK_COMPILE_FUNCTION (1 << 1) /* compile function code (instead of global code) */
283
- #define DUK_COMPILE_STRICT (1 << 2) /* use strict (outer) context for global, eval, or function code */
284
- #define DUK_COMPILE_SAFE (1 << 3) /* (internal) catch compilation errors */
285
- #define DUK_COMPILE_NORESULT (1 << 4) /* (internal) omit eval result */
286
- #define DUK_COMPILE_NOSOURCE (1 << 5) /* (internal) no source string on stack */
287
- #define DUK_COMPILE_STRLEN (1 << 6) /* (internal) take strlen() of src_buffer (avoids double evaluation in macro) */
288
-
289
- /* Flags for duk_def_prop() and its variants */
290
- #define DUK_DEFPROP_WRITABLE (1 << 0) /* set writable (effective if DUK_DEFPROP_HAVE_WRITABLE set) */
291
- #define DUK_DEFPROP_ENUMERABLE (1 << 1) /* set enumerable (effective if DUK_DEFPROP_HAVE_ENUMERABLE set) */
292
- #define DUK_DEFPROP_CONFIGURABLE (1 << 2) /* set configurable (effective if DUK_DEFPROP_HAVE_CONFIGURABLE set) */
293
- #define DUK_DEFPROP_HAVE_WRITABLE (1 << 3) /* set/clear writable */
294
- #define DUK_DEFPROP_HAVE_ENUMERABLE (1 << 4) /* set/clear enumerable */
295
- #define DUK_DEFPROP_HAVE_CONFIGURABLE (1 << 5) /* set/clear configurable */
296
- #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) */
298
- #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 */
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)
300
428
 
301
429
  /* Flags for duk_push_thread_raw() */
302
- #define DUK_THREAD_NEW_GLOBAL_ENV (1 << 0) /* create a new global environment */
430
+ #define DUK_THREAD_NEW_GLOBAL_ENV (1U << 0) /* create a new global environment */
303
431
 
304
- /* Flags for duk_push_string_file_raw() */
305
- #define DUK_STRING_PUSH_SAFE (1 << 0) /* no error if file does not exist */
432
+ /* Flags for duk_gc() */
433
+ #define DUK_GC_COMPACT (1U << 0) /* compact heap objects */
306
434
 
307
- /* Duktape specific error codes */
435
+ /* Error codes (must be 8 bits at most, see duk_error.h) */
308
436
  #define DUK_ERR_NONE 0 /* no error (e.g. from duk_get_error_code()) */
309
- #define DUK_ERR_UNIMPLEMENTED_ERROR 50 /* UnimplementedError */
310
- #define DUK_ERR_UNSUPPORTED_ERROR 51 /* UnsupportedError */
311
- #define DUK_ERR_INTERNAL_ERROR 52 /* InternalError */
312
- #define DUK_ERR_ALLOC_ERROR 53 /* AllocError */
313
- #define DUK_ERR_ASSERTION_ERROR 54 /* AssertionError */
314
- #define DUK_ERR_API_ERROR 55 /* APIError */
315
- #define DUK_ERR_UNCAUGHT_ERROR 56 /* UncaughtError */
316
-
317
- /* Ecmascript E5 specification error codes */
318
- #define DUK_ERR_ERROR 100 /* Error */
319
- #define DUK_ERR_EVAL_ERROR 101 /* EvalError */
320
- #define DUK_ERR_RANGE_ERROR 102 /* RangeError */
321
- #define DUK_ERR_REFERENCE_ERROR 103 /* ReferenceError */
322
- #define DUK_ERR_SYNTAX_ERROR 104 /* SyntaxError */
323
- #define DUK_ERR_TYPE_ERROR 105 /* TypeError */
324
- #define DUK_ERR_URI_ERROR 106 /* URIError */
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 */
325
444
 
326
445
  /* Return codes for C functions (shortcut for throwing an error) */
327
- #define DUK_RET_UNIMPLEMENTED_ERROR (-DUK_ERR_UNIMPLEMENTED_ERROR)
328
- #define DUK_RET_UNSUPPORTED_ERROR (-DUK_ERR_UNSUPPORTED_ERROR)
329
- #define DUK_RET_INTERNAL_ERROR (-DUK_ERR_INTERNAL_ERROR)
330
- #define DUK_RET_ALLOC_ERROR (-DUK_ERR_ALLOC_ERROR)
331
- #define DUK_RET_ASSERTION_ERROR (-DUK_ERR_ASSERTION_ERROR)
332
- #define DUK_RET_API_ERROR (-DUK_ERR_API_ERROR)
333
- #define DUK_RET_UNCAUGHT_ERROR (-DUK_ERR_UNCAUGHT_ERROR)
334
446
  #define DUK_RET_ERROR (-DUK_ERR_ERROR)
335
447
  #define DUK_RET_EVAL_ERROR (-DUK_ERR_EVAL_ERROR)
336
448
  #define DUK_RET_RANGE_ERROR (-DUK_ERR_RANGE_ERROR)
@@ -339,24 +451,44 @@ struct duk_number_list_entry {
339
451
  #define DUK_RET_TYPE_ERROR (-DUK_ERR_TYPE_ERROR)
340
452
  #define DUK_RET_URI_ERROR (-DUK_ERR_URI_ERROR)
341
453
 
342
- /* Return codes for protected calls (duk_safe_call(), duk_pcall()). */
454
+ /* Return codes for protected calls (duk_safe_call(), duk_pcall()) */
343
455
  #define DUK_EXEC_SUCCESS 0
344
456
  #define DUK_EXEC_ERROR 1
345
457
 
346
- /* Log levels */
347
- #define DUK_LOG_TRACE 0
348
- #define DUK_LOG_DEBUG 1
349
- #define DUK_LOG_INFO 2
350
- #define DUK_LOG_WARN 3
351
- #define DUK_LOG_ERROR 4
352
- #define DUK_LOG_FATAL 5
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)
353
485
 
354
486
  /*
355
487
  * If no variadic macros, __FILE__ and __LINE__ are passed through globals
356
488
  * which is ugly and not thread safe.
357
489
  */
358
490
 
359
- #ifndef DUK_API_VARIADIC_MACROS
491
+ #if !defined(DUK_API_VARIADIC_MACROS)
360
492
  DUK_EXTERNAL_DECL const char *duk_api_global_filename;
361
493
  DUK_EXTERNAL_DECL duk_int_t duk_api_global_line;
362
494
  #endif
@@ -373,6 +505,9 @@ duk_context *duk_create_heap(duk_alloc_function alloc_func,
373
505
  duk_fatal_function fatal_handler);
374
506
  DUK_EXTERNAL_DECL void duk_destroy_heap(duk_context *ctx);
375
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
+
376
511
  #define duk_create_heap_default() \
377
512
  duk_create_heap(NULL, NULL, NULL, NULL, NULL)
378
513
 
@@ -395,29 +530,100 @@ DUK_EXTERNAL_DECL void duk_gc(duk_context *ctx, duk_uint_t flags);
395
530
  * Error handling
396
531
  */
397
532
 
398
- DUK_API_NORETURN(DUK_EXTERNAL_DECL void duk_throw(duk_context *ctx));
399
- DUK_API_NORETURN(DUK_EXTERNAL_DECL void duk_fatal(duk_context *ctx, duk_errcode_t err_code, const char *err_msg));
400
-
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)
401
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, ...));
402
540
 
403
- #ifdef DUK_API_VARIADIC_MACROS
541
+ #if defined(DUK_API_VARIADIC_MACROS)
404
542
  #define duk_error(ctx,err_code,...) \
405
- duk_error_raw((ctx), (duk_errcode_t) (err_code), (const char *) (__FILE__), (duk_int_t) (__LINE__), __VA_ARGS__)
406
- #else
407
- DUK_API_NORETURN(DUK_EXTERNAL_DECL void duk_error_stash(duk_context *ctx, duk_errcode_t err_code, const char *fmt, ...));
408
- /* One problem with this macro is that expressions like the following fail
409
- * to compile: "(void) duk_error(...)". But because duk_error() is noreturn,
410
- * they make little sense anyway.
411
- */
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, ...));
412
575
  #define duk_error \
413
- (duk_api_global_filename = (const char *) (__FILE__), \
414
- duk_api_global_line = (duk_int_t) (__LINE__), \
576
+ (duk_api_global_filename = (const char *) (DUK_FILE_MACRO), \
577
+ duk_api_global_line = (duk_int_t) (DUK_LINE_MACRO), \
415
578
  duk_error_stash) /* last value is func pointer, arguments follow in parens */
416
- #endif
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 */
417
608
 
418
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
+
419
611
  #define duk_error_va(ctx,err_code,fmt,ap) \
420
- duk_error_va_raw((ctx), (duk_errcode_t) (err_code), (const char *) (__FILE__), (duk_int_t) (__LINE__), (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)
421
627
 
422
628
  /*
423
629
  * Other state related functions
@@ -430,13 +636,13 @@ DUK_EXTERNAL_DECL duk_bool_t duk_is_constructor_call(duk_context *ctx);
430
636
  * Stack management
431
637
  */
432
638
 
433
- DUK_EXTERNAL_DECL duk_idx_t duk_normalize_index(duk_context *ctx, duk_idx_t index);
434
- DUK_EXTERNAL_DECL duk_idx_t duk_require_normalize_index(duk_context *ctx, duk_idx_t index);
435
- DUK_EXTERNAL_DECL duk_bool_t duk_is_valid_index(duk_context *ctx, duk_idx_t index);
436
- DUK_EXTERNAL_DECL void duk_require_valid_index(duk_context *ctx, duk_idx_t index);
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);
437
643
 
438
644
  DUK_EXTERNAL_DECL duk_idx_t duk_get_top(duk_context *ctx);
439
- DUK_EXTERNAL_DECL void duk_set_top(duk_context *ctx, duk_idx_t index);
645
+ DUK_EXTERNAL_DECL void duk_set_top(duk_context *ctx, duk_idx_t idx);
440
646
  DUK_EXTERNAL_DECL duk_idx_t duk_get_top_index(duk_context *ctx);
441
647
  DUK_EXTERNAL_DECL duk_idx_t duk_require_top_index(duk_context *ctx);
442
648
 
@@ -456,14 +662,15 @@ DUK_EXTERNAL_DECL void duk_require_stack_top(duk_context *ctx, duk_idx_t top);
456
662
  * Stack manipulation (other than push/pop)
457
663
  */
458
664
 
459
- DUK_EXTERNAL_DECL void duk_swap(duk_context *ctx, duk_idx_t index1, duk_idx_t index2);
460
- DUK_EXTERNAL_DECL void duk_swap_top(duk_context *ctx, duk_idx_t index);
461
- DUK_EXTERNAL_DECL void duk_dup(duk_context *ctx, duk_idx_t from_index);
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);
462
668
  DUK_EXTERNAL_DECL void duk_dup_top(duk_context *ctx);
463
- DUK_EXTERNAL_DECL void duk_insert(duk_context *ctx, duk_idx_t to_index);
464
- DUK_EXTERNAL_DECL void duk_replace(duk_context *ctx, duk_idx_t to_index);
465
- DUK_EXTERNAL_DECL void duk_copy(duk_context *ctx, duk_idx_t from_index, duk_idx_t to_index);
466
- DUK_EXTERNAL_DECL void duk_remove(duk_context *ctx, duk_idx_t index);
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);
467
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);
468
675
 
469
676
  #define duk_xmove_top(to_ctx,from_ctx,count) \
@@ -495,11 +702,21 @@ DUK_EXTERNAL_DECL void duk_push_pointer(duk_context *ctx, void *p);
495
702
  DUK_EXTERNAL_DECL const char *duk_push_sprintf(duk_context *ctx, const char *fmt, ...);
496
703
  DUK_EXTERNAL_DECL const char *duk_push_vsprintf(duk_context *ctx, const char *fmt, va_list ap);
497
704
 
498
- DUK_EXTERNAL_DECL const char *duk_push_string_file_raw(duk_context *ctx, const char *path, duk_uint_t flags);
499
- #define duk_push_string_file(ctx,path) \
500
- duk_push_string_file_raw((ctx), (path), 0)
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
501
717
 
502
718
  DUK_EXTERNAL_DECL void duk_push_this(duk_context *ctx);
719
+ DUK_EXTERNAL_DECL void duk_push_new_target(duk_context *ctx);
503
720
  DUK_EXTERNAL_DECL void duk_push_current_function(duk_context *ctx);
504
721
  DUK_EXTERNAL_DECL void duk_push_current_thread(duk_context *ctx);
505
722
  DUK_EXTERNAL_DECL void duk_push_global_object(duk_context *ctx);
@@ -508,10 +725,13 @@ DUK_EXTERNAL_DECL void duk_push_global_stash(duk_context *ctx);
508
725
  DUK_EXTERNAL_DECL void duk_push_thread_stash(duk_context *ctx, duk_context *target_ctx);
509
726
 
510
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);
511
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);
512
731
  DUK_EXTERNAL_DECL duk_idx_t duk_push_c_function(duk_context *ctx, duk_c_function func, duk_idx_t nargs);
513
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);
514
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);
515
735
 
516
736
  #define duk_push_thread(ctx) \
517
737
  duk_push_thread_raw((ctx), 0 /*flags*/)
@@ -521,21 +741,21 @@ DUK_EXTERNAL_DECL duk_idx_t duk_push_thread_raw(duk_context *ctx, duk_uint_t fla
521
741
 
522
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, ...);
523
743
 
524
- #ifdef DUK_API_VARIADIC_MACROS
744
+ #if defined(DUK_API_VARIADIC_MACROS)
525
745
  #define duk_push_error_object(ctx,err_code,...) \
526
- duk_push_error_object_raw((ctx), (err_code), (const char *) (__FILE__), (duk_int_t) (__LINE__), __VA_ARGS__)
746
+ duk_push_error_object_raw((ctx), (err_code), (const char *) (DUK_FILE_MACRO), (duk_int_t) (DUK_LINE_MACRO), __VA_ARGS__)
527
747
  #else
528
748
  DUK_EXTERNAL_DECL duk_idx_t duk_push_error_object_stash(duk_context *ctx, duk_errcode_t err_code, const char *fmt, ...);
529
749
  /* Note: parentheses are required so that the comma expression works in assignments. */
530
750
  #define duk_push_error_object \
531
- (duk_api_global_filename = (const char *) (__FILE__), \
532
- duk_api_global_line = (duk_int_t) (__LINE__), \
751
+ (duk_api_global_filename = (const char *) (DUK_FILE_MACRO), \
752
+ duk_api_global_line = (duk_int_t) (DUK_LINE_MACRO), \
533
753
  duk_push_error_object_stash) /* last value is func pointer, arguments follow in parens */
534
754
  #endif
535
755
 
536
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);
537
757
  #define duk_push_error_object_va(ctx,err_code,fmt,ap) \
538
- duk_push_error_object_va_raw((ctx), (err_code), (const char *) (__FILE__), (duk_int_t) (__LINE__), (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))
539
759
 
540
760
  #define DUK_BUF_FLAG_DYNAMIC (1 << 0) /* internal flag: dynamic buffer */
541
761
  #define DUK_BUF_FLAG_EXTERNAL (1 << 1) /* internal flag: external buffer */
@@ -544,7 +764,7 @@ DUK_EXTERNAL_DECL duk_idx_t duk_push_error_object_va_raw(duk_context *ctx, duk_e
544
764
  DUK_EXTERNAL_DECL void *duk_push_buffer_raw(duk_context *ctx, duk_size_t size, duk_small_uint_t flags);
545
765
 
546
766
  #define duk_push_buffer(ctx,size,dynamic) \
547
- duk_push_buffer_raw((ctx), (size), (dynamic) ? DUK_BUF_FLAG_DYNAMIC : 0);
767
+ duk_push_buffer_raw((ctx), (size), (dynamic) ? DUK_BUF_FLAG_DYNAMIC : 0)
548
768
  #define duk_push_fixed_buffer(ctx,size) \
549
769
  duk_push_buffer_raw((ctx), (size), 0 /*flags*/)
550
770
  #define duk_push_dynamic_buffer(ctx,size) \
@@ -552,20 +772,18 @@ DUK_EXTERNAL_DECL void *duk_push_buffer_raw(duk_context *ctx, duk_size_t size, d
552
772
  #define duk_push_external_buffer(ctx) \
553
773
  ((void) duk_push_buffer_raw((ctx), 0, DUK_BUF_FLAG_DYNAMIC | DUK_BUF_FLAG_EXTERNAL))
554
774
 
555
- #define DUK_BUFOBJ_CREATE_ARRBUF (1 << 4) /* internal flag: create backing ArrayBuffer; keep in one byte */
556
- #define DUK_BUFOBJ_DUKTAPE_BUFFER 0
775
+ #define DUK_BUFOBJ_ARRAYBUFFER 0
557
776
  #define DUK_BUFOBJ_NODEJS_BUFFER 1
558
- #define DUK_BUFOBJ_ARRAYBUFFER 2
559
- #define DUK_BUFOBJ_DATAVIEW (3 | DUK_BUFOBJ_CREATE_ARRBUF)
560
- #define DUK_BUFOBJ_INT8ARRAY (4 | DUK_BUFOBJ_CREATE_ARRBUF)
561
- #define DUK_BUFOBJ_UINT8ARRAY (5 | DUK_BUFOBJ_CREATE_ARRBUF)
562
- #define DUK_BUFOBJ_UINT8CLAMPEDARRAY (6 | DUK_BUFOBJ_CREATE_ARRBUF)
563
- #define DUK_BUFOBJ_INT16ARRAY (7 | DUK_BUFOBJ_CREATE_ARRBUF)
564
- #define DUK_BUFOBJ_UINT16ARRAY (8 | DUK_BUFOBJ_CREATE_ARRBUF)
565
- #define DUK_BUFOBJ_INT32ARRAY (9 | DUK_BUFOBJ_CREATE_ARRBUF)
566
- #define DUK_BUFOBJ_UINT32ARRAY (10 | DUK_BUFOBJ_CREATE_ARRBUF)
567
- #define DUK_BUFOBJ_FLOAT32ARRAY (11 | DUK_BUFOBJ_CREATE_ARRBUF)
568
- #define DUK_BUFOBJ_FLOAT64ARRAY (12 | DUK_BUFOBJ_CREATE_ARRBUF)
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
569
787
 
570
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);
571
789
 
@@ -587,57 +805,79 @@ DUK_EXTERNAL_DECL void duk_pop_3(duk_context *ctx);
587
805
  * is not needed; duk_is_valid_index() gives the same information.
588
806
  */
589
807
 
590
- DUK_EXTERNAL_DECL duk_int_t duk_get_type(duk_context *ctx, duk_idx_t index);
591
- DUK_EXTERNAL_DECL duk_bool_t duk_check_type(duk_context *ctx, duk_idx_t index, duk_int_t type);
592
- DUK_EXTERNAL_DECL duk_uint_t duk_get_type_mask(duk_context *ctx, duk_idx_t index);
593
- DUK_EXTERNAL_DECL duk_bool_t duk_check_type_mask(duk_context *ctx, duk_idx_t index, duk_uint_t mask);
594
-
595
- DUK_EXTERNAL_DECL duk_bool_t duk_is_undefined(duk_context *ctx, duk_idx_t index);
596
- DUK_EXTERNAL_DECL duk_bool_t duk_is_null(duk_context *ctx, duk_idx_t index);
597
- DUK_EXTERNAL_DECL duk_bool_t duk_is_null_or_undefined(duk_context *ctx, duk_idx_t index);
598
- DUK_EXTERNAL_DECL duk_bool_t duk_is_boolean(duk_context *ctx, duk_idx_t index);
599
- DUK_EXTERNAL_DECL duk_bool_t duk_is_number(duk_context *ctx, duk_idx_t index);
600
- DUK_EXTERNAL_DECL duk_bool_t duk_is_nan(duk_context *ctx, duk_idx_t index);
601
- DUK_EXTERNAL_DECL duk_bool_t duk_is_string(duk_context *ctx, duk_idx_t index);
602
- DUK_EXTERNAL_DECL duk_bool_t duk_is_object(duk_context *ctx, duk_idx_t index);
603
- DUK_EXTERNAL_DECL duk_bool_t duk_is_buffer(duk_context *ctx, duk_idx_t index);
604
- DUK_EXTERNAL_DECL duk_bool_t duk_is_pointer(duk_context *ctx, duk_idx_t index);
605
- DUK_EXTERNAL_DECL duk_bool_t duk_is_lightfunc(duk_context *ctx, duk_idx_t index);
606
-
607
- DUK_EXTERNAL_DECL duk_bool_t duk_is_array(duk_context *ctx, duk_idx_t index);
608
- DUK_EXTERNAL_DECL duk_bool_t duk_is_function(duk_context *ctx, duk_idx_t index);
609
- 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);
611
- 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);
613
-
614
- DUK_EXTERNAL_DECL duk_bool_t duk_is_callable(duk_context *ctx, duk_idx_t index);
615
- 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);
617
- DUK_EXTERNAL_DECL duk_bool_t duk_is_external_buffer(duk_context *ctx, duk_idx_t index);
618
-
619
- #define duk_is_primitive(ctx,index) \
620
- duk_check_type_mask((ctx), (index), DUK_TYPE_MASK_UNDEFINED | \
621
- DUK_TYPE_MASK_NULL | \
622
- DUK_TYPE_MASK_BOOLEAN | \
623
- DUK_TYPE_MASK_NUMBER | \
624
- DUK_TYPE_MASK_STRING | \
625
- DUK_TYPE_MASK_BUFFER | \
626
- DUK_TYPE_MASK_POINTER | \
627
- DUK_TYPE_MASK_LIGHTFUNC)
628
-
629
- #define duk_is_object_coercible(ctx,index) \
630
- duk_check_type_mask((ctx), (index), DUK_TYPE_MASK_BOOLEAN | \
631
- DUK_TYPE_MASK_NUMBER | \
632
- DUK_TYPE_MASK_STRING | \
633
- DUK_TYPE_MASK_OBJECT | \
634
- DUK_TYPE_MASK_BUFFER | \
635
- DUK_TYPE_MASK_POINTER | \
636
- DUK_TYPE_MASK_LIGHTFUNC)
637
-
638
- DUK_EXTERNAL_DECL duk_errcode_t duk_get_error_code(duk_context *ctx, duk_idx_t index);
639
- #define duk_is_error(ctx,index) \
640
- (duk_get_error_code((ctx), (index)) != 0)
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)
641
881
 
642
882
  /*
643
883
  * Get operations: no coercion, returns default value for invalid
@@ -647,45 +887,88 @@ DUK_EXTERNAL_DECL duk_errcode_t duk_get_error_code(duk_context *ctx, duk_idx_t i
647
887
  * are not included.
648
888
  */
649
889
 
650
- DUK_EXTERNAL_DECL duk_bool_t duk_get_boolean(duk_context *ctx, duk_idx_t index);
651
- DUK_EXTERNAL_DECL duk_double_t duk_get_number(duk_context *ctx, duk_idx_t index);
652
- DUK_EXTERNAL_DECL duk_int_t duk_get_int(duk_context *ctx, duk_idx_t index);
653
- DUK_EXTERNAL_DECL duk_uint_t duk_get_uint(duk_context *ctx, duk_idx_t index);
654
- DUK_EXTERNAL_DECL const char *duk_get_string(duk_context *ctx, duk_idx_t index);
655
- DUK_EXTERNAL_DECL const char *duk_get_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len);
656
- DUK_EXTERNAL_DECL void *duk_get_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size);
657
- DUK_EXTERNAL_DECL void *duk_get_buffer_data(duk_context *ctx, duk_idx_t index, duk_size_t *out_size);
658
- DUK_EXTERNAL_DECL void *duk_get_pointer(duk_context *ctx, duk_idx_t index);
659
- DUK_EXTERNAL_DECL duk_c_function duk_get_c_function(duk_context *ctx, duk_idx_t index);
660
- DUK_EXTERNAL_DECL duk_context *duk_get_context(duk_context *ctx, duk_idx_t index);
661
- DUK_EXTERNAL_DECL void *duk_get_heapptr(duk_context *ctx, duk_idx_t index);
662
- DUK_EXTERNAL_DECL duk_size_t duk_get_length(duk_context *ctx, duk_idx_t index);
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);
663
939
 
664
940
  /*
665
941
  * Require operations: no coercion, throw error if index or type
666
942
  * is incorrect. No defaulting.
667
943
  */
668
944
 
669
- #define duk_require_type_mask(ctx,index,mask) \
670
- ((void) duk_check_type_mask((ctx), (index), (mask) | DUK_TYPE_MASK_THROW))
671
-
672
- DUK_EXTERNAL_DECL void duk_require_undefined(duk_context *ctx, duk_idx_t index);
673
- DUK_EXTERNAL_DECL void duk_require_null(duk_context *ctx, duk_idx_t index);
674
- DUK_EXTERNAL_DECL duk_bool_t duk_require_boolean(duk_context *ctx, duk_idx_t index);
675
- DUK_EXTERNAL_DECL duk_double_t duk_require_number(duk_context *ctx, duk_idx_t index);
676
- DUK_EXTERNAL_DECL duk_int_t duk_require_int(duk_context *ctx, duk_idx_t index);
677
- DUK_EXTERNAL_DECL duk_uint_t duk_require_uint(duk_context *ctx, duk_idx_t index);
678
- DUK_EXTERNAL_DECL const char *duk_require_string(duk_context *ctx, duk_idx_t index);
679
- DUK_EXTERNAL_DECL const char *duk_require_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len);
680
- 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);
682
- 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);
684
- DUK_EXTERNAL_DECL duk_context *duk_require_context(duk_context *ctx, duk_idx_t index);
685
- DUK_EXTERNAL_DECL void *duk_require_heapptr(duk_context *ctx, duk_idx_t index);
686
-
687
- #define duk_require_object_coercible(ctx,index) \
688
- ((void) duk_check_type_mask((ctx), (index), DUK_TYPE_MASK_BOOLEAN | \
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 | \
689
972
  DUK_TYPE_MASK_NUMBER | \
690
973
  DUK_TYPE_MASK_STRING | \
691
974
  DUK_TYPE_MASK_OBJECT | \
@@ -701,96 +984,171 @@ DUK_EXTERNAL_DECL void *duk_require_heapptr(duk_context *ctx, duk_idx_t index);
701
984
  * or an internal error (e.g. from out of memory).
702
985
  */
703
986
 
704
- DUK_EXTERNAL_DECL void duk_to_undefined(duk_context *ctx, duk_idx_t index);
705
- DUK_EXTERNAL_DECL void duk_to_null(duk_context *ctx, duk_idx_t index);
706
- DUK_EXTERNAL_DECL duk_bool_t duk_to_boolean(duk_context *ctx, duk_idx_t index);
707
- DUK_EXTERNAL_DECL duk_double_t duk_to_number(duk_context *ctx, duk_idx_t index);
708
- DUK_EXTERNAL_DECL duk_int_t duk_to_int(duk_context *ctx, duk_idx_t index);
709
- DUK_EXTERNAL_DECL duk_uint_t duk_to_uint(duk_context *ctx, duk_idx_t index);
710
- DUK_EXTERNAL_DECL duk_int32_t duk_to_int32(duk_context *ctx, duk_idx_t index);
711
- DUK_EXTERNAL_DECL duk_uint32_t duk_to_uint32(duk_context *ctx, duk_idx_t index);
712
- DUK_EXTERNAL_DECL duk_uint16_t duk_to_uint16(duk_context *ctx, duk_idx_t index);
713
- DUK_EXTERNAL_DECL const char *duk_to_string(duk_context *ctx, duk_idx_t index);
714
- DUK_EXTERNAL_DECL const char *duk_to_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len);
715
- DUK_EXTERNAL_DECL void *duk_to_buffer_raw(duk_context *ctx, duk_idx_t index, duk_size_t *out_size, duk_uint_t flags);
716
- DUK_EXTERNAL_DECL void *duk_to_pointer(duk_context *ctx, duk_idx_t index);
717
- DUK_EXTERNAL_DECL void duk_to_object(duk_context *ctx, duk_idx_t index);
718
- DUK_EXTERNAL_DECL void duk_to_defaultvalue(duk_context *ctx, duk_idx_t index, duk_int_t hint);
719
- DUK_EXTERNAL_DECL void duk_to_primitive(duk_context *ctx, duk_idx_t index, duk_int_t hint);
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);
720
1002
 
721
1003
  #define DUK_BUF_MODE_FIXED 0 /* internal: request fixed buffer result */
722
1004
  #define DUK_BUF_MODE_DYNAMIC 1 /* internal: request dynamic buffer result */
723
1005
  #define DUK_BUF_MODE_DONTCARE 2 /* internal: don't care about fixed/dynamic nature */
724
1006
 
725
- #define duk_to_buffer(ctx,index,out_size) \
726
- duk_to_buffer_raw((ctx), (index), (out_size), DUK_BUF_MODE_DONTCARE)
727
- #define duk_to_fixed_buffer(ctx,index,out_size) \
728
- duk_to_buffer_raw((ctx), (index), (out_size), DUK_BUF_MODE_FIXED)
729
- #define duk_to_dynamic_buffer(ctx,index,out_size) \
730
- duk_to_buffer_raw((ctx), (index), (out_size), DUK_BUF_MODE_DYNAMIC)
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)
731
1013
 
732
1014
  /* safe variants of a few coercion operations */
733
- DUK_EXTERNAL_DECL const char *duk_safe_to_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len);
734
- #define duk_safe_to_string(ctx,index) \
735
- duk_safe_to_lstring((ctx), (index), NULL)
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
736
1031
 
737
1032
  /*
738
1033
  * Misc conversion
739
1034
  */
740
1035
 
741
- DUK_EXTERNAL_DECL const char *duk_base64_encode(duk_context *ctx, duk_idx_t index);
742
- DUK_EXTERNAL_DECL void duk_base64_decode(duk_context *ctx, duk_idx_t index);
743
- DUK_EXTERNAL_DECL const char *duk_hex_encode(duk_context *ctx, duk_idx_t index);
744
- DUK_EXTERNAL_DECL void duk_hex_decode(duk_context *ctx, duk_idx_t index);
745
- DUK_EXTERNAL_DECL const char *duk_json_encode(duk_context *ctx, duk_idx_t index);
746
- DUK_EXTERNAL_DECL void duk_json_decode(duk_context *ctx, duk_idx_t index);
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);
747
1046
 
748
1047
  /*
749
1048
  * Buffer
750
1049
  */
751
1050
 
752
- DUK_EXTERNAL_DECL void *duk_resize_buffer(duk_context *ctx, duk_idx_t index, duk_size_t new_size);
753
- DUK_EXTERNAL_DECL void *duk_steal_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size);
754
- DUK_EXTERNAL_DECL void duk_config_buffer(duk_context *ctx, duk_idx_t index, void *ptr, duk_size_t len);
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);
755
1054
 
756
1055
  /*
757
1056
  * Property access
758
1057
  *
759
- * The basic function assumes key is on stack. The _string variant takes
760
- * a C string as a property name, while the _index variant takes an array
761
- * index as a property name (e.g. 123 is equivalent to the key "123").
762
- */
763
-
764
- DUK_EXTERNAL_DECL duk_bool_t duk_get_prop(duk_context *ctx, duk_idx_t obj_index);
765
- DUK_EXTERNAL_DECL duk_bool_t duk_get_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key);
766
- DUK_EXTERNAL_DECL duk_bool_t duk_get_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index);
767
- DUK_EXTERNAL_DECL duk_bool_t duk_put_prop(duk_context *ctx, duk_idx_t obj_index);
768
- DUK_EXTERNAL_DECL duk_bool_t duk_put_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key);
769
- DUK_EXTERNAL_DECL duk_bool_t duk_put_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index);
770
- DUK_EXTERNAL_DECL duk_bool_t duk_del_prop(duk_context *ctx, duk_idx_t obj_index);
771
- DUK_EXTERNAL_DECL duk_bool_t duk_del_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key);
772
- DUK_EXTERNAL_DECL duk_bool_t duk_del_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index);
773
- DUK_EXTERNAL_DECL duk_bool_t duk_has_prop(duk_context *ctx, duk_idx_t obj_index);
774
- DUK_EXTERNAL_DECL duk_bool_t duk_has_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key);
775
- DUK_EXTERNAL_DECL duk_bool_t duk_has_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index);
776
- DUK_EXTERNAL_DECL void duk_def_prop(duk_context *ctx, duk_idx_t obj_index, duk_uint_t flags);
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);
777
1112
 
778
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);
779
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);
780
1138
 
781
1139
  /*
782
1140
  * Object prototype
783
1141
  */
784
1142
 
785
- DUK_EXTERNAL_DECL void duk_get_prototype(duk_context *ctx, duk_idx_t index);
786
- DUK_EXTERNAL_DECL void duk_set_prototype(duk_context *ctx, duk_idx_t index);
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);
787
1145
 
788
1146
  /*
789
1147
  * Object finalizer
790
1148
  */
791
1149
 
792
- DUK_EXTERNAL_DECL void duk_get_finalizer(duk_context *ctx, duk_idx_t index);
793
- DUK_EXTERNAL_DECL void duk_set_finalizer(duk_context *ctx, duk_idx_t index);
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);
794
1152
 
795
1153
  /*
796
1154
  * Global object
@@ -802,36 +1160,26 @@ DUK_EXTERNAL_DECL void duk_set_global_object(duk_context *ctx);
802
1160
  * Duktape/C function magic value
803
1161
  */
804
1162
 
805
- DUK_EXTERNAL_DECL duk_int_t duk_get_magic(duk_context *ctx, duk_idx_t index);
806
- DUK_EXTERNAL_DECL void duk_set_magic(duk_context *ctx, duk_idx_t index, duk_int_t magic);
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);
807
1165
  DUK_EXTERNAL_DECL duk_int_t duk_get_current_magic(duk_context *ctx);
808
1166
 
809
1167
  /*
810
1168
  * Module helpers: put multiple function or constant properties
811
1169
  */
812
1170
 
813
- DUK_EXTERNAL_DECL void duk_put_function_list(duk_context *ctx, duk_idx_t obj_index, const duk_function_list_entry *funcs);
814
- DUK_EXTERNAL_DECL void duk_put_number_list(duk_context *ctx, duk_idx_t obj_index, const duk_number_list_entry *numbers);
815
-
816
- /*
817
- * Variable access
818
- */
819
-
820
- /* XXX: These calls are incomplete and not usable now. They are not (yet)
821
- * part of the public API.
822
- */
823
- DUK_EXTERNAL_DECL void duk_get_var(duk_context *ctx);
824
- DUK_EXTERNAL_DECL void duk_put_var(duk_context *ctx);
825
- DUK_EXTERNAL_DECL duk_bool_t duk_del_var(duk_context *ctx);
826
- DUK_EXTERNAL_DECL duk_bool_t duk_has_var(duk_context *ctx);
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);
827
1173
 
828
1174
  /*
829
1175
  * Object operations
830
1176
  */
831
1177
 
832
- DUK_EXTERNAL_DECL void duk_compact(duk_context *ctx, duk_idx_t obj_index);
833
- DUK_EXTERNAL_DECL void duk_enum(duk_context *ctx, duk_idx_t obj_index, duk_uint_t enum_flags);
834
- DUK_EXTERNAL_DECL duk_bool_t duk_next(duk_context *ctx, duk_idx_t enum_index, duk_bool_t get_value);
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);
835
1183
 
836
1184
  /*
837
1185
  * String manipulation
@@ -839,19 +1187,26 @@ DUK_EXTERNAL_DECL duk_bool_t duk_next(duk_context *ctx, duk_idx_t enum_index, du
839
1187
 
840
1188
  DUK_EXTERNAL_DECL void duk_concat(duk_context *ctx, duk_idx_t count);
841
1189
  DUK_EXTERNAL_DECL void duk_join(duk_context *ctx, duk_idx_t count);
842
- DUK_EXTERNAL_DECL void duk_decode_string(duk_context *ctx, duk_idx_t index, duk_decode_char_function callback, void *udata);
843
- DUK_EXTERNAL_DECL void duk_map_string(duk_context *ctx, duk_idx_t index, duk_map_char_function callback, void *udata);
844
- DUK_EXTERNAL_DECL void duk_substring(duk_context *ctx, duk_idx_t index, duk_size_t start_char_offset, duk_size_t end_char_offset);
845
- DUK_EXTERNAL_DECL void duk_trim(duk_context *ctx, duk_idx_t index);
846
- DUK_EXTERNAL_DECL duk_codepoint_t duk_char_code_at(duk_context *ctx, duk_idx_t index, duk_size_t char_offset);
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);
847
1195
 
848
1196
  /*
849
- * Ecmascript operators
1197
+ * ECMAScript operators
850
1198
  */
851
1199
 
852
- DUK_EXTERNAL_DECL duk_bool_t duk_equals(duk_context *ctx, duk_idx_t index1, duk_idx_t index2);
853
- DUK_EXTERNAL_DECL duk_bool_t duk_strict_equals(duk_context *ctx, duk_idx_t index1, duk_idx_t index2);
854
- DUK_EXTERNAL_DECL duk_bool_t duk_instanceof(duk_context *ctx, duk_idx_t index1, duk_idx_t index2);
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);
855
1210
 
856
1211
  /*
857
1212
  * Function (method) calls
@@ -859,13 +1214,13 @@ DUK_EXTERNAL_DECL duk_bool_t duk_instanceof(duk_context *ctx, duk_idx_t index1,
859
1214
 
860
1215
  DUK_EXTERNAL_DECL void duk_call(duk_context *ctx, duk_idx_t nargs);
861
1216
  DUK_EXTERNAL_DECL void duk_call_method(duk_context *ctx, duk_idx_t nargs);
862
- DUK_EXTERNAL_DECL void duk_call_prop(duk_context *ctx, duk_idx_t obj_index, duk_idx_t nargs);
1217
+ DUK_EXTERNAL_DECL void duk_call_prop(duk_context *ctx, duk_idx_t obj_idx, duk_idx_t nargs);
863
1218
  DUK_EXTERNAL_DECL duk_int_t duk_pcall(duk_context *ctx, duk_idx_t nargs);
864
1219
  DUK_EXTERNAL_DECL duk_int_t duk_pcall_method(duk_context *ctx, duk_idx_t nargs);
865
- DUK_EXTERNAL_DECL duk_int_t duk_pcall_prop(duk_context *ctx, duk_idx_t obj_index, 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);
866
1221
  DUK_EXTERNAL_DECL void duk_new(duk_context *ctx, duk_idx_t nargs);
867
1222
  DUK_EXTERNAL_DECL duk_int_t duk_pnew(duk_context *ctx, duk_idx_t nargs);
868
- DUK_EXTERNAL_DECL duk_int_t duk_safe_call(duk_context *ctx, duk_safe_call_function func, duk_idx_t nargs, duk_idx_t nrets);
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);
869
1224
 
870
1225
  /*
871
1226
  * Thread management
@@ -884,119 +1239,72 @@ DUK_EXTERNAL_DECL duk_int_t duk_compile_raw(duk_context *ctx, const char *src_bu
884
1239
 
885
1240
  /* plain */
886
1241
  #define duk_eval(ctx) \
887
- ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
888
- (void) duk_eval_raw((ctx), NULL, 0, DUK_COMPILE_EVAL))
1242
+ ((void) duk_eval_raw((ctx), NULL, 0, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOFILENAME))
889
1243
 
890
1244
  #define duk_eval_noresult(ctx) \
891
- ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
892
- (void) duk_eval_raw((ctx), NULL, 0, DUK_COMPILE_EVAL | DUK_COMPILE_NORESULT))
1245
+ ((void) duk_eval_raw((ctx), NULL, 0, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME))
893
1246
 
894
1247
  #define duk_peval(ctx) \
895
- ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
896
- duk_eval_raw((ctx), NULL, 0, DUK_COMPILE_EVAL | DUK_COMPILE_SAFE))
1248
+ (duk_eval_raw((ctx), NULL, 0, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOFILENAME))
897
1249
 
898
1250
  #define duk_peval_noresult(ctx) \
899
- ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
900
- duk_eval_raw((ctx), NULL, 0, DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NORESULT))
1251
+ (duk_eval_raw((ctx), NULL, 0, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME))
901
1252
 
902
1253
  #define duk_compile(ctx,flags) \
903
- ((void) duk_compile_raw((ctx), NULL, 0, (flags)))
1254
+ ((void) duk_compile_raw((ctx), NULL, 0, 2 /*args*/ | (flags)))
904
1255
 
905
1256
  #define duk_pcompile(ctx,flags) \
906
- (duk_compile_raw((ctx), NULL, 0, (flags) | DUK_COMPILE_SAFE))
1257
+ (duk_compile_raw((ctx), NULL, 0, 2 /*args*/ | (flags) | DUK_COMPILE_SAFE))
907
1258
 
908
1259
  /* string */
909
1260
  #define duk_eval_string(ctx,src) \
910
- ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
911
- (void) duk_eval_raw((ctx), (src), 0, DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN))
1261
+ ((void) duk_eval_raw((ctx), (src), 0, 0 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME))
912
1262
 
913
1263
  #define duk_eval_string_noresult(ctx,src) \
914
- ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
915
- (void) duk_eval_raw((ctx), (src), 0, DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NORESULT))
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))
916
1265
 
917
1266
  #define duk_peval_string(ctx,src) \
918
- ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
919
- duk_eval_raw((ctx), (src), 0, DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN))
1267
+ (duk_eval_raw((ctx), (src), 0, 0 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME))
920
1268
 
921
1269
  #define duk_peval_string_noresult(ctx,src) \
922
- ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
923
- duk_eval_raw((ctx), (src), 0, DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NORESULT))
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))
924
1271
 
925
1272
  #define duk_compile_string(ctx,flags,src) \
926
- ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
927
- (void) duk_compile_raw((ctx), (src), 0, (flags) | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN))
1273
+ ((void) duk_compile_raw((ctx), (src), 0, 0 /*args*/ | (flags) | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME))
928
1274
 
929
1275
  #define duk_compile_string_filename(ctx,flags,src) \
930
- ((void) duk_compile_raw((ctx), (src), 0, (flags) | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN))
1276
+ ((void) duk_compile_raw((ctx), (src), 0, 1 /*args*/ | (flags) | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN))
931
1277
 
932
1278
  #define duk_pcompile_string(ctx,flags,src) \
933
- ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
934
- duk_compile_raw((ctx), (src), 0, (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN))
1279
+ (duk_compile_raw((ctx), (src), 0, 0 /*args*/ | (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME))
935
1280
 
936
1281
  #define duk_pcompile_string_filename(ctx,flags,src) \
937
- (duk_compile_raw((ctx), (src), 0, (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN))
1282
+ (duk_compile_raw((ctx), (src), 0, 1 /*args*/ | (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN))
938
1283
 
939
1284
  /* lstring */
940
1285
  #define duk_eval_lstring(ctx,buf,len) \
941
- ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
942
- (void) duk_eval_raw((ctx), buf, len, DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE))
1286
+ ((void) duk_eval_raw((ctx), buf, len, 0 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NOFILENAME))
943
1287
 
944
1288
  #define duk_eval_lstring_noresult(ctx,buf,len) \
945
- ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
946
- (void) duk_eval_raw((ctx), buf, len, DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NORESULT))
1289
+ ((void) duk_eval_raw((ctx), buf, len, 0 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME))
947
1290
 
948
1291
  #define duk_peval_lstring(ctx,buf,len) \
949
- ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
950
- duk_eval_raw((ctx), buf, len, DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_SAFE))
1292
+ (duk_eval_raw((ctx), buf, len, 0 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_SAFE | DUK_COMPILE_NOFILENAME))
951
1293
 
952
1294
  #define duk_peval_lstring_noresult(ctx,buf,len) \
953
- ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
954
- duk_eval_raw((ctx), buf, len, DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NORESULT))
1295
+ (duk_eval_raw((ctx), buf, len, 0 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME))
955
1296
 
956
1297
  #define duk_compile_lstring(ctx,flags,buf,len) \
957
- ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
958
- (void) duk_compile_raw((ctx), buf, len, (flags) | DUK_COMPILE_NOSOURCE))
1298
+ ((void) duk_compile_raw((ctx), buf, len, 0 /*args*/ | (flags) | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NOFILENAME))
959
1299
 
960
1300
  #define duk_compile_lstring_filename(ctx,flags,buf,len) \
961
- ((void) duk_compile_raw((ctx), buf, len, (flags) | DUK_COMPILE_NOSOURCE))
1301
+ ((void) duk_compile_raw((ctx), buf, len, 1 /*args*/ | (flags) | DUK_COMPILE_NOSOURCE))
962
1302
 
963
1303
  #define duk_pcompile_lstring(ctx,flags,buf,len) \
964
- ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
965
- duk_compile_raw((ctx), buf, len, (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE))
1304
+ (duk_compile_raw((ctx), buf, len, 0 /*args*/ | (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NOFILENAME))
966
1305
 
967
1306
  #define duk_pcompile_lstring_filename(ctx,flags,buf,len) \
968
- (duk_compile_raw((ctx), buf, len, (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE))
969
-
970
- /* file */
971
- #define duk_eval_file(ctx,path) \
972
- ((void) duk_push_string_file_raw((ctx), (path), 0), \
973
- (void) duk_push_string((ctx), (path)), \
974
- (void) duk_eval_raw((ctx), NULL, 0, DUK_COMPILE_EVAL))
975
-
976
- #define duk_eval_file_noresult(ctx,path) \
977
- ((void) duk_push_string_file_raw((ctx), (path), 0), \
978
- (void) duk_push_string((ctx), (path)), \
979
- (void) duk_eval_raw((ctx), NULL, 0, DUK_COMPILE_EVAL | DUK_COMPILE_NORESULT))
980
-
981
- #define duk_peval_file(ctx,path) \
982
- ((void) duk_push_string_file_raw((ctx), (path), DUK_STRING_PUSH_SAFE), \
983
- (void) duk_push_string((ctx), (path)), \
984
- duk_eval_raw((ctx), NULL, 0, DUK_COMPILE_EVAL | DUK_COMPILE_SAFE))
985
-
986
- #define duk_peval_file_noresult(ctx,path) \
987
- ((void) duk_push_string_file_raw((ctx), (path), DUK_STRING_PUSH_SAFE), \
988
- (void) duk_push_string((ctx), (path)), \
989
- duk_eval_raw((ctx), NULL, 0, DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NORESULT))
990
-
991
- #define duk_compile_file(ctx,flags,path) \
992
- ((void) duk_push_string_file_raw((ctx), (path), 0), \
993
- (void) duk_push_string((ctx), (path)), \
994
- (void) duk_compile_raw((ctx), NULL, 0, (flags)))
995
-
996
- #define duk_pcompile_file(ctx,flags,path) \
997
- ((void) duk_push_string_file_raw((ctx), (path), DUK_STRING_PUSH_SAFE), \
998
- (void) duk_push_string((ctx), (path)), \
999
- duk_compile_raw((ctx), NULL, 0, (flags) | DUK_COMPILE_SAFE))
1307
+ (duk_compile_raw((ctx), buf, len, 1 /*args*/ | (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE))
1000
1308
 
1001
1309
  /*
1002
1310
  * Bytecode load/dump
@@ -1005,36 +1313,12 @@ DUK_EXTERNAL_DECL duk_int_t duk_compile_raw(duk_context *ctx, const char *src_bu
1005
1313
  DUK_EXTERNAL_DECL void duk_dump_function(duk_context *ctx);
1006
1314
  DUK_EXTERNAL_DECL void duk_load_function(duk_context *ctx);
1007
1315
 
1008
- /*
1009
- * Logging
1010
- */
1011
-
1012
- DUK_EXTERNAL_DECL void duk_log(duk_context *ctx, duk_int_t level, const char *fmt, ...);
1013
- DUK_EXTERNAL_DECL void duk_log_va(duk_context *ctx, duk_int_t level, const char *fmt, va_list ap);
1014
-
1015
1316
  /*
1016
1317
  * Debugging
1017
1318
  */
1018
1319
 
1019
1320
  DUK_EXTERNAL_DECL void duk_push_context_dump(duk_context *ctx);
1020
1321
 
1021
- #if defined(DUK_USE_FILE_IO)
1022
- /* internal use */
1023
- #define duk_dump_context_filehandle(ctx,fh) \
1024
- (duk_push_context_dump((ctx)), \
1025
- DUK_FPRINTF((fh), "%s\n", duk_safe_to_string(ctx, -1)), \
1026
- duk_pop(ctx))
1027
-
1028
- /* external use */
1029
- #define duk_dump_context_stdout(ctx) \
1030
- duk_dump_context_filehandle((ctx), DUK_STDOUT)
1031
- #define duk_dump_context_stderr(ctx) \
1032
- duk_dump_context_filehandle((ctx), DUK_STDERR)
1033
- #else /* DUK_USE_FILE_IO */
1034
- #define duk_dump_context_stdout(ctx) ((void) 0)
1035
- #define duk_dump_context_stderr(ctx) ((void) 0)
1036
- #endif /* DUK_USE_FILE_IO */
1037
-
1038
1322
  /*
1039
1323
  * Debugger (debug protocol)
1040
1324
  */
@@ -1045,10 +1329,21 @@ DUK_EXTERNAL_DECL void duk_debugger_attach(duk_context *ctx,
1045
1329
  duk_debug_peek_function peek_cb,
1046
1330
  duk_debug_read_flush_function read_flush_cb,
1047
1331
  duk_debug_write_flush_function write_flush_cb,
1332
+ duk_debug_request_function request_cb,
1048
1333
  duk_debug_detached_function detached_cb,
1049
1334
  void *udata);
1050
1335
  DUK_EXTERNAL_DECL void duk_debugger_detach(duk_context *ctx);
1051
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);
1052
1347
 
1053
1348
  /*
1054
1349
  * Date provider related constants
@@ -1063,7 +1358,7 @@ DUK_EXTERNAL_DECL void duk_debugger_cooperate(duk_context *ctx);
1063
1358
  #define DUK_DATE_MSEC_HOUR (60L * 60L * 1000L)
1064
1359
  #define DUK_DATE_MSEC_DAY (24L * 60L * 60L * 1000L)
1065
1360
 
1066
- /* Ecmascript date range is 100 million days from Epoch:
1361
+ /* ECMAScript date range is 100 million days from Epoch:
1067
1362
  * > 100e6 * 24 * 60 * 60 * 1000 // 100M days in millisecs
1068
1363
  * 8640000000000000
1069
1364
  * (= 8.64e15)
@@ -1071,7 +1366,7 @@ DUK_EXTERNAL_DECL void duk_debugger_cooperate(duk_context *ctx);
1071
1366
  #define DUK_DATE_MSEC_100M_DAYS (8.64e15)
1072
1367
  #define DUK_DATE_MSEC_100M_DAYS_LEEWAY (8.64e15 + 24 * 3600e3)
1073
1368
 
1074
- /* Ecmascript year range:
1369
+ /* ECMAScript year range:
1075
1370
  * > new Date(100e6 * 24 * 3600e3).toISOString()
1076
1371
  * '+275760-09-13T00:00:00.000Z'
1077
1372
  * > new Date(-100e6 * 24 * 3600e3).toISOString()
@@ -1081,12 +1376,12 @@ DUK_EXTERNAL_DECL void duk_debugger_cooperate(duk_context *ctx);
1081
1376
  #define DUK_DATE_MAX_ECMA_YEAR 275760L
1082
1377
 
1083
1378
  /* Part indices for internal breakdowns. Part order from DUK_DATE_IDX_YEAR
1084
- * to DUK_DATE_IDX_MILLISECOND matches argument ordering of Ecmascript API
1379
+ * to DUK_DATE_IDX_MILLISECOND matches argument ordering of ECMAScript API
1085
1380
  * calls (like Date constructor call). Some functions in duk_bi_date.c
1086
1381
  * depend on the specific ordering, so change with care. 16 bits are not
1087
1382
  * enough for all parts (year, specifically).
1088
1383
  *
1089
- * (Must be in-sync with genbuiltins.py.)
1384
+ * Must be in-sync with genbuiltins.py.
1090
1385
  */
1091
1386
  #define DUK_DATE_IDX_YEAR 0 /* year */
1092
1387
  #define DUK_DATE_IDX_MONTH 1 /* month: 0 to 11 */
@@ -1098,7 +1393,7 @@ DUK_EXTERNAL_DECL void duk_debugger_cooperate(duk_context *ctx);
1098
1393
  #define DUK_DATE_IDX_WEEKDAY 7 /* weekday: 0 to 6, 0=sunday, 1=monday, etc */
1099
1394
  #define DUK_DATE_IDX_NUM_PARTS 8
1100
1395
 
1101
- /* Internal API call flags, used for various functions in this file.
1396
+ /* Internal API call flags, used for various functions in duk_bi_date.c.
1102
1397
  * Certain flags are used by only certain functions, but since the flags
1103
1398
  * don't overlap, a single flags value can be passed around to multiple
1104
1399
  * functions.
@@ -1106,7 +1401,7 @@ DUK_EXTERNAL_DECL void duk_debugger_cooperate(duk_context *ctx);
1106
1401
  * The unused top bits of the flags field are also used to pass values
1107
1402
  * to helpers (duk__get_part_helper() and duk__set_part_helper()).
1108
1403
  *
1109
- * (Must be in-sync with genbuiltins.py.)
1404
+ * Must be in-sync with genbuiltins.py.
1110
1405
  */
1111
1406
 
1112
1407
  /* NOTE: when writing a Date provider you only need a few specific
@@ -1129,396 +1424,27 @@ DUK_EXTERNAL_DECL void duk_debugger_cooperate(duk_context *ctx);
1129
1424
  #define DUK_DATE_FLAG_VALUE_SHIFT 12 /* additional values begin at bit 12 */
1130
1425
 
1131
1426
  /*
1132
- * C++ name mangling
1133
- */
1134
-
1135
- #ifdef __cplusplus
1136
- /* end 'extern "C"' wrapper */
1137
- }
1138
- #endif
1139
-
1140
- #endif /* DUK_API_PUBLIC_H_INCLUDED */
1141
-
1142
- /*
1143
- * END PUBLIC API
1427
+ * ROM pointer compression
1144
1428
  */
1145
1429
 
1146
- /*
1147
- * Union to access IEEE double memory representation, indexes for double
1148
- * memory representation, and some macros for double manipulation.
1149
- *
1150
- * Also used by packed duk_tval. Use a union for bit manipulation to
1151
- * minimize aliasing issues in practice. The C99 standard does not
1152
- * guarantee that this should work, but it's a very widely supported
1153
- * practice for low level manipulation.
1154
- *
1155
- * IEEE double format summary:
1156
- *
1157
- * seeeeeee eeeeffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
1158
- * A B C D E F G H
1159
- *
1160
- * s sign bit
1161
- * eee... exponent field
1162
- * fff... fraction
1163
- *
1164
- * See http://en.wikipedia.org/wiki/Double_precision_floating-point_format.
1165
- *
1166
- * NaNs are represented as exponent 0x7ff and mantissa != 0. The NaN is a
1167
- * signaling NaN when the highest bit of the mantissa is zero, and a quiet
1168
- * NaN when the highest bit is set.
1169
- *
1170
- * At least three memory layouts are relevant here:
1171
- *
1172
- * A B C D E F G H Big endian (e.g. 68k) DUK_USE_DOUBLE_BE
1173
- * H G F E D C B A Little endian (e.g. x86) DUK_USE_DOUBLE_LE
1174
- * D C B A H G F E Mixed/cross endian (e.g. ARM) DUK_USE_DOUBLE_ME
1175
- *
1176
- * ARM is a special case: ARM double values are in mixed/cross endian
1177
- * format while ARM duk_uint64_t values are in standard little endian
1178
- * format (H G F E D C B A). When a double is read as a duk_uint64_t
1179
- * from memory, the register will contain the (logical) value
1180
- * E F G H A B C D. This requires some special handling below.
1181
- *
1182
- * Indexes of various types (8-bit, 16-bit, 32-bit) in memory relative to
1183
- * the logical (big endian) order:
1184
- *
1185
- * byte order duk_uint8_t duk_uint16_t duk_uint32_t
1186
- * BE 01234567 0123 01
1187
- * LE 76543210 3210 10
1188
- * ME (ARM) 32107654 1032 01
1189
- *
1190
- * Some processors may alter NaN values in a floating point load+store.
1191
- * For instance, on X86 a FLD + FSTP may convert a signaling NaN to a
1192
- * quiet one. This is catastrophic when NaN space is used in packed
1193
- * duk_tval values. See: misc/clang_aliasing.c.
1430
+ /* Support array for ROM pointer compression. Only declared when ROM
1431
+ * pointer compression is active.
1194
1432
  */
1195
-
1196
- #ifndef DUK_DBLUNION_H_INCLUDED
1197
- #define DUK_DBLUNION_H_INCLUDED
1198
-
1199
- /*
1200
- * Union for accessing double parts, also serves as packed duk_tval
1201
- */
1202
-
1203
- union duk_double_union {
1204
- double d;
1205
- float f[2];
1206
- #ifdef DUK_USE_64BIT_OPS
1207
- duk_uint64_t ull[1];
1208
- #endif
1209
- duk_uint32_t ui[2];
1210
- duk_uint16_t us[4];
1211
- duk_uint8_t uc[8];
1212
- #ifdef DUK_USE_PACKED_TVAL_POSSIBLE
1213
- void *vp[2]; /* used by packed duk_tval, assumes sizeof(void *) == 4 */
1433
+ #if defined(DUK_USE_ROM_OBJECTS) && defined(DUK_USE_HEAPPTR16)
1434
+ DUK_EXTERNAL_DECL const void * const duk_rom_compressed_pointers[];
1214
1435
  #endif
1215
- };
1216
-
1217
- typedef union duk_double_union duk_double_union;
1218
1436
 
1219
1437
  /*
1220
- * Indexes of various types with respect to big endian (logical) layout
1438
+ * C++ name mangling
1221
1439
  */
1222
1440
 
1223
- #if defined(DUK_USE_DOUBLE_LE)
1224
- #ifdef DUK_USE_64BIT_OPS
1225
- #define DUK_DBL_IDX_ULL0 0
1226
- #endif
1227
- #define DUK_DBL_IDX_UI0 1
1228
- #define DUK_DBL_IDX_UI1 0
1229
- #define DUK_DBL_IDX_US0 3
1230
- #define DUK_DBL_IDX_US1 2
1231
- #define DUK_DBL_IDX_US2 1
1232
- #define DUK_DBL_IDX_US3 0
1233
- #define DUK_DBL_IDX_UC0 7
1234
- #define DUK_DBL_IDX_UC1 6
1235
- #define DUK_DBL_IDX_UC2 5
1236
- #define DUK_DBL_IDX_UC3 4
1237
- #define DUK_DBL_IDX_UC4 3
1238
- #define DUK_DBL_IDX_UC5 2
1239
- #define DUK_DBL_IDX_UC6 1
1240
- #define DUK_DBL_IDX_UC7 0
1241
- #define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */
1242
- #define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */
1243
- #elif defined(DUK_USE_DOUBLE_BE)
1244
- #ifdef DUK_USE_64BIT_OPS
1245
- #define DUK_DBL_IDX_ULL0 0
1246
- #endif
1247
- #define DUK_DBL_IDX_UI0 0
1248
- #define DUK_DBL_IDX_UI1 1
1249
- #define DUK_DBL_IDX_US0 0
1250
- #define DUK_DBL_IDX_US1 1
1251
- #define DUK_DBL_IDX_US2 2
1252
- #define DUK_DBL_IDX_US3 3
1253
- #define DUK_DBL_IDX_UC0 0
1254
- #define DUK_DBL_IDX_UC1 1
1255
- #define DUK_DBL_IDX_UC2 2
1256
- #define DUK_DBL_IDX_UC3 3
1257
- #define DUK_DBL_IDX_UC4 4
1258
- #define DUK_DBL_IDX_UC5 5
1259
- #define DUK_DBL_IDX_UC6 6
1260
- #define DUK_DBL_IDX_UC7 7
1261
- #define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */
1262
- #define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */
1263
- #elif defined(DUK_USE_DOUBLE_ME)
1264
- #ifdef DUK_USE_64BIT_OPS
1265
- #define DUK_DBL_IDX_ULL0 0 /* not directly applicable, byte order differs from a double */
1266
- #endif
1267
- #define DUK_DBL_IDX_UI0 0
1268
- #define DUK_DBL_IDX_UI1 1
1269
- #define DUK_DBL_IDX_US0 1
1270
- #define DUK_DBL_IDX_US1 0
1271
- #define DUK_DBL_IDX_US2 3
1272
- #define DUK_DBL_IDX_US3 2
1273
- #define DUK_DBL_IDX_UC0 3
1274
- #define DUK_DBL_IDX_UC1 2
1275
- #define DUK_DBL_IDX_UC2 1
1276
- #define DUK_DBL_IDX_UC3 0
1277
- #define DUK_DBL_IDX_UC4 7
1278
- #define DUK_DBL_IDX_UC5 6
1279
- #define DUK_DBL_IDX_UC6 5
1280
- #define DUK_DBL_IDX_UC7 4
1281
- #define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */
1282
- #define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */
1283
- #else
1284
- #error internal error
1441
+ #if defined(__cplusplus)
1442
+ /* end 'extern "C"' wrapper */
1443
+ }
1285
1444
  #endif
1286
1445
 
1287
1446
  /*
1288
- * Helper macros for reading/writing memory representation parts, used
1289
- * by duk_numconv.c and duk_tval.h.
1447
+ * END PUBLIC API
1290
1448
  */
1291
1449
 
1292
- #define DUK_DBLUNION_SET_DOUBLE(u,v) do { \
1293
- (u)->d = (v); \
1294
- } while (0)
1295
-
1296
- #define DUK_DBLUNION_SET_HIGH32(u,v) do { \
1297
- (u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) (v); \
1298
- } while (0)
1299
-
1300
- #ifdef DUK_USE_64BIT_OPS
1301
- #ifdef DUK_USE_DOUBLE_ME
1302
- #define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \
1303
- (u)->ull[DUK_DBL_IDX_ULL0] = (duk_uint64_t) (v); \
1304
- } while (0)
1305
- #else
1306
- #define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \
1307
- (u)->ull[DUK_DBL_IDX_ULL0] = ((duk_uint64_t) (v)) << 32; \
1308
- } while (0)
1309
- #endif
1310
- #else /* DUK_USE_64BIT_OPS */
1311
- #define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \
1312
- (u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) (v); \
1313
- (u)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) 0; \
1314
- } while (0)
1315
- #endif /* DUK_USE_64BIT_OPS */
1316
-
1317
- #define DUK_DBLUNION_SET_LOW32(u,v) do { \
1318
- (u)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) (v); \
1319
- } while (0)
1320
-
1321
- #define DUK_DBLUNION_GET_DOUBLE(u) ((u)->d)
1322
- #define DUK_DBLUNION_GET_HIGH32(u) ((u)->ui[DUK_DBL_IDX_UI0])
1323
- #define DUK_DBLUNION_GET_LOW32(u) ((u)->ui[DUK_DBL_IDX_UI1])
1324
-
1325
- #ifdef DUK_USE_64BIT_OPS
1326
- #ifdef DUK_USE_DOUBLE_ME
1327
- #define DUK_DBLUNION_SET_UINT64(u,v) do { \
1328
- (u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) ((v) >> 32); \
1329
- (u)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) (v); \
1330
- } while (0)
1331
- #define DUK_DBLUNION_GET_UINT64(u) \
1332
- ((((duk_uint64_t) (u)->ui[DUK_DBL_IDX_UI0]) << 32) | \
1333
- ((duk_uint64_t) (u)->ui[DUK_DBL_IDX_UI1]))
1334
- #else
1335
- #define DUK_DBLUNION_SET_UINT64(u,v) do { \
1336
- (u)->ull[DUK_DBL_IDX_ULL0] = (duk_uint64_t) (v); \
1337
- } while (0)
1338
- #define DUK_DBLUNION_GET_UINT64(u) ((u)->ull[DUK_DBL_IDX_ULL0])
1339
- #endif
1340
- #define DUK_DBLUNION_SET_INT64(u,v) DUK_DBLUNION_SET_UINT64((u), (duk_uint64_t) (v))
1341
- #define DUK_DBLUNION_GET_INT64(u) ((duk_int64_t) DUK_DBLUNION_GET_UINT64((u)))
1342
- #endif /* DUK_USE_64BIT_OPS */
1343
-
1344
- /*
1345
- * Double NaN manipulation macros related to NaN normalization needed when
1346
- * using the packed duk_tval representation. NaN normalization is necessary
1347
- * to keep double values compatible with the duk_tval format.
1348
- *
1349
- * 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
1351
- * to a specific format. The macros below are used by the implementation
1352
- * 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.
1354
- *
1355
- * 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
1357
- * begin with 0x7ff0. Since the 'normalized NaN' values used with packed
1358
- * duk_tval begin with 0x7ff8, the partial check is reliable when packed
1359
- * duk_tval is used.
1360
- *
1361
- * 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
1363
- * 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
1365
- * swapped; hence the #ifdefs below for ULL writes with DUK_USE_DOUBLE_ME.
1366
- * This is not full ARM support but suffices for some environments.
1367
- */
1368
-
1369
- #ifdef DUK_USE_64BIT_OPS
1370
- #ifdef DUK_USE_DOUBLE_ME
1371
- #define DUK__DBLUNION_SET_NAN_FULL(u) do { \
1372
- (u)->ull[DUK_DBL_IDX_ULL0] = 0x000000007ff80000ULL; \
1373
- } while (0)
1374
- #else
1375
- #define DUK__DBLUNION_SET_NAN_FULL(u) do { \
1376
- (u)->ull[DUK_DBL_IDX_ULL0] = 0x7ff8000000000000ULL; \
1377
- } while (0)
1378
- #endif
1379
- #else /* DUK_USE_64BIT_OPS */
1380
- #define DUK__DBLUNION_SET_NAN_FULL(u) do { \
1381
- (u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) 0x7ff80000UL; \
1382
- (u)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) 0x00000000UL; \
1383
- } while (0)
1384
- #endif /* DUK_USE_64BIT_OPS */
1385
-
1386
- #define DUK__DBLUNION_SET_NAN_NOTFULL(u) do { \
1387
- (u)->us[DUK_DBL_IDX_US0] = 0x7ff8UL; \
1388
- } while (0)
1389
-
1390
- #ifdef DUK_USE_64BIT_OPS
1391
- #ifdef DUK_USE_DOUBLE_ME
1392
- #define DUK__DBLUNION_IS_NAN_FULL(u) \
1393
- /* E == 0x7ff, F != 0 => NaN */ \
1394
- ((((u)->us[DUK_DBL_IDX_US0] & 0x7ff0UL) == 0x7ff0UL) && \
1395
- ((((u)->ull[DUK_DBL_IDX_ULL0]) & 0xffffffff000fffffULL) != 0))
1396
- #else
1397
- #define DUK__DBLUNION_IS_NAN_FULL(u) \
1398
- /* E == 0x7ff, F != 0 => NaN */ \
1399
- ((((u)->us[DUK_DBL_IDX_US0] & 0x7ff0UL) == 0x7ff0UL) && \
1400
- ((((u)->ull[DUK_DBL_IDX_ULL0]) & 0x000fffffffffffffULL) != 0))
1401
- #endif
1402
- #else /* DUK_USE_64BIT_OPS */
1403
- #define DUK__DBLUNION_IS_NAN_FULL(u) \
1404
- /* E == 0x7ff, F != 0 => NaN */ \
1405
- ((((u)->ui[DUK_DBL_IDX_UI0] & 0x7ff00000UL) == 0x7ff00000UL) && \
1406
- (((u)->ui[DUK_DBL_IDX_UI0] & 0x000fffffUL) != 0 || \
1407
- (u)->ui[DUK_DBL_IDX_UI1] != 0))
1408
- #endif /* DUK_USE_64BIT_OPS */
1409
-
1410
- #define DUK__DBLUNION_IS_NAN_NOTFULL(u) \
1411
- /* E == 0x7ff, topmost four bits of F != 0 => assume NaN */ \
1412
- ((((u)->us[DUK_DBL_IDX_US0] & 0x7ff0UL) == 0x7ff0UL) && \
1413
- (((u)->us[DUK_DBL_IDX_US0] & 0x000fUL) != 0x0000UL))
1414
-
1415
- #ifdef DUK_USE_64BIT_OPS
1416
- #ifdef DUK_USE_DOUBLE_ME
1417
- #define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \
1418
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0x000000007ff80000ULL)
1419
- #else
1420
- #define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \
1421
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0x7ff8000000000000ULL)
1422
- #endif
1423
- #else /* DUK_USE_64BIT_OPS */
1424
- #define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \
1425
- (((u)->ui[DUK_DBL_IDX_UI0] == 0x7ff80000UL) && \
1426
- ((u)->ui[DUK_DBL_IDX_UI1] == 0x00000000UL))
1427
- #endif /* DUK_USE_64BIT_OPS */
1428
-
1429
- #define DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL(u) \
1430
- /* E == 0x7ff, F == 8 => normalized NaN */ \
1431
- ((u)->us[DUK_DBL_IDX_US0] == 0x7ff8UL)
1432
-
1433
- #define DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL(u) do { \
1434
- if (DUK__DBLUNION_IS_NAN_FULL((u))) { \
1435
- DUK__DBLUNION_SET_NAN_FULL((u)); \
1436
- } \
1437
- } while (0)
1438
-
1439
- #define DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL(u) do { \
1440
- if (DUK__DBLUNION_IS_NAN_NOTFULL((u))) { \
1441
- DUK__DBLUNION_SET_NAN_NOTFULL((u)); \
1442
- } \
1443
- } while (0)
1444
-
1445
- /* Concrete macros for NaN handling used by the implementation internals.
1446
- * Chosen so that they match the duk_tval representation: with a packed
1447
- * duk_tval, ensure NaNs are properly normalized; with a non-packed duk_tval
1448
- * these are essentially NOPs.
1449
- */
1450
-
1451
- #if defined(DUK_USE_PACKED_TVAL)
1452
- #if defined(DUK_USE_FULL_TVAL)
1453
- #define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL((u))
1454
- #define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u))
1455
- #define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_FULL((u))
1456
- #define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_FULL((d))
1457
- #else
1458
- #define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL((u))
1459
- #define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_NOTFULL((u))
1460
- #define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL((u))
1461
- #define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_NOTFULL((d))
1462
- #endif
1463
- #define DUK_DBLUNION_IS_NORMALIZED(u) \
1464
- (!DUK_DBLUNION_IS_NAN((u)) || /* either not a NaN */ \
1465
- DUK_DBLUNION_IS_NORMALIZED_NAN((u))) /* or is a normalized NaN */
1466
- #else /* DUK_USE_PACKED_TVAL */
1467
- #define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) /* nop: no need to normalize */
1468
- #define DUK_DBLUNION_IS_NAN(u) (DUK_ISNAN((u)->d))
1469
- #define DUK_DBLUNION_IS_NORMALIZED_NAN(u) (DUK_ISNAN((u)->d))
1470
- #define DUK_DBLUNION_IS_NORMALIZED(u) 1 /* all doubles are considered normalized */
1471
- #define DUK_DBLUNION_SET_NAN(u) do { \
1472
- /* in non-packed representation we don't care about which NaN is used */ \
1473
- (u)->d = DUK_DOUBLE_NAN; \
1474
- } while (0)
1475
- #endif /* DUK_USE_PACKED_TVAL */
1476
-
1477
- /* XXX: native 64-bit byteswaps when available */
1478
-
1479
- /* 64-bit byteswap, same operation independent of target endianness. */
1480
- #define DUK_DBLUNION_BSWAP64(u) do { \
1481
- duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \
1482
- duk__bswaptmp1 = (u)->ui[0]; \
1483
- duk__bswaptmp2 = (u)->ui[1]; \
1484
- duk__bswaptmp1 = DUK_BSWAP32(duk__bswaptmp1); \
1485
- duk__bswaptmp2 = DUK_BSWAP32(duk__bswaptmp2); \
1486
- (u)->ui[0] = duk__bswaptmp2; \
1487
- (u)->ui[1] = duk__bswaptmp1; \
1488
- } while (0)
1489
-
1490
- /* Byteswap an IEEE double in the duk_double_union from host to network
1491
- * order. For a big endian target this is a no-op.
1492
- */
1493
- #if defined(DUK_USE_DOUBLE_LE)
1494
- #define DUK_DBLUNION_DOUBLE_HTON(u) do { \
1495
- duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \
1496
- duk__bswaptmp1 = (u)->ui[0]; \
1497
- duk__bswaptmp2 = (u)->ui[1]; \
1498
- duk__bswaptmp1 = DUK_BSWAP32(duk__bswaptmp1); \
1499
- duk__bswaptmp2 = DUK_BSWAP32(duk__bswaptmp2); \
1500
- (u)->ui[0] = duk__bswaptmp2; \
1501
- (u)->ui[1] = duk__bswaptmp1; \
1502
- } while (0)
1503
- #elif defined(DUK_USE_DOUBLE_ME)
1504
- #define DUK_DBLUNION_DOUBLE_HTON(u) do { \
1505
- duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \
1506
- duk__bswaptmp1 = (u)->ui[0]; \
1507
- duk__bswaptmp2 = (u)->ui[1]; \
1508
- duk__bswaptmp1 = DUK_BSWAP32(duk__bswaptmp1); \
1509
- duk__bswaptmp2 = DUK_BSWAP32(duk__bswaptmp2); \
1510
- (u)->ui[0] = duk__bswaptmp1; \
1511
- (u)->ui[1] = duk__bswaptmp2; \
1512
- } while (0)
1513
- #elif defined(DUK_USE_DOUBLE_BE)
1514
- #define DUK_DBLUNION_DOUBLE_HTON(u) do { } while (0)
1515
- #else
1516
- #error internal error, double endianness insane
1517
- #endif
1518
-
1519
- /* Reverse operation is the same. */
1520
- #define DUK_DBLUNION_DOUBLE_NTOH(u) DUK_DBLUNION_DOUBLE_HTON((u))
1521
-
1522
- #endif /* DUK_DBLUNION_H_INCLUDED */
1523
-
1524
1450
  #endif /* DUKTAPE_H_INCLUDED */