duktape 2.0.1.1 → 2.3.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,13 +1,13 @@
1
1
  /*
2
- * Duktape public API for Duktape 2.0.1.
2
+ * Duktape public API for Duktape 2.3.0.
3
3
  *
4
- * See the API reference for documentation on call semantics.
5
- * The exposed API is inside the DUK_API_PUBLIC_H_INCLUDED
6
- * include guard. Other parts of the header are Duktape
7
- * internal and related to platform/compiler/feature detection.
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
8
  *
9
- * Git commit 3f5e91704aff97c754f6ef5d44aedc5e529d1b16 (v2.0.1).
10
- * Git branch v2.0-maintenance.
9
+ * Git commit 7551eee6615c2633375bff51ceb297bc3bc7c77e (v2.0.1.0-5-g7551eee-dirty).
10
+ * Git branch master.
11
11
  *
12
12
  * See Duktape AUTHORS.rst and LICENSE.txt for copyright and
13
13
  * licensing information.
@@ -21,7 +21,7 @@
21
21
  *
22
22
  * (http://opensource.org/licenses/MIT)
23
23
  *
24
- * Copyright (c) 2013-2017 by Duktape authors (see AUTHORS.rst)
24
+ * Copyright (c) 2013-2018 by Duktape authors (see AUTHORS.rst)
25
25
  *
26
26
  * Permission is hereby granted, free of charge, to any person obtaining a copy
27
27
  * of this software and associated documentation files (the "Software"), to deal
@@ -87,6 +87,19 @@
87
87
  * * Brett Vickers (https://github.com/beevik)
88
88
  * * Dominik Okwieka (https://github.com/okitec)
89
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)
90
103
  *
91
104
  * Other contributions
92
105
  * ===================
@@ -125,6 +138,8 @@
125
138
  * * https://github.com/chris-y
126
139
  * * Laurent Zubiaur (https://github.com/lzubiaur)
127
140
  * * Neil Kolban (https://github.com/nkolban)
141
+ * * Wilhelm Wanecek (https://github.com/wanecek)
142
+ * * Andrew Janke (https://github.com/apjanke)
128
143
  *
129
144
  * If you are accidentally missing from this list, send me an e-mail
130
145
  * (``sami.vaarala@iki.fi``) and I'll fix the omission.
@@ -135,18 +150,38 @@
135
150
 
136
151
  #define DUK_SINGLE_FILE
137
152
 
138
- /* External duk_config.h provides platform/compiler/OS dependent
139
- * typedefs and macros, and DUK_USE_xxx config options so that
140
- * the rest of Duktape doesn't need to do any feature detection.
153
+ /*
154
+ * BEGIN PUBLIC API
141
155
  */
142
- #include "duk_config.h"
143
156
 
144
157
  /*
145
- * BEGIN PUBLIC API
158
+ * Version and Git commit identification
159
+ */
160
+
161
+ /* Duktape version, (major * 10000) + (minor * 100) + patch. Allows C code
162
+ * to #if (DUK_VERSION >= NNN) against Duktape API version. The same value
163
+ * is also available to ECMAScript code in Duktape.version. Unofficial
164
+ * development snapshots have 99 for patch level (e.g. 0.10.99 would be a
165
+ * development version after 0.10.0 but before the next official release).
146
166
  */
167
+ #define DUK_VERSION 20300L
147
168
 
148
- #if !defined(DUK_API_PUBLIC_H_INCLUDED)
149
- #define DUK_API_PUBLIC_H_INCLUDED
169
+ /* Git commit, describe, and branch for Duktape build. Useful for
170
+ * non-official snapshot builds so that application code can easily log
171
+ * which Duktape snapshot was used. Not available in the ECMAScript
172
+ * environment.
173
+ */
174
+ #define DUK_GIT_COMMIT "7551eee6615c2633375bff51ceb297bc3bc7c77e"
175
+ #define DUK_GIT_DESCRIBE "v2.0.1.0-5-g7551eee-dirty"
176
+ #define DUK_GIT_BRANCH "master"
177
+
178
+ /* External duk_config.h provides platform/compiler/OS dependent
179
+ * typedefs and macros, and DUK_USE_xxx config options so that
180
+ * the rest of Duktape doesn't need to do any feature detection.
181
+ * DUK_VERSION is defined before including so that configuration
182
+ * snippets can react to it.
183
+ */
184
+ #include "duk_config.h"
150
185
 
151
186
  /*
152
187
  * Avoid C++ name mangling
@@ -233,7 +268,7 @@ struct duk_number_list_entry {
233
268
  };
234
269
 
235
270
  struct duk_time_components {
236
- duk_double_t year; /* year, e.g. 2016, Ecmascript year range */
271
+ duk_double_t year; /* year, e.g. 2016, ECMAScript year range */
237
272
  duk_double_t month; /* month: 1-12 */
238
273
  duk_double_t day; /* day: 1-31 */
239
274
  duk_double_t hours; /* hour: 0-59 */
@@ -247,23 +282,6 @@ struct duk_time_components {
247
282
  * Constants
248
283
  */
249
284
 
250
- /* Duktape version, (major * 10000) + (minor * 100) + patch. Allows C code
251
- * to #if (DUK_VERSION >= NNN) against Duktape API version. The same value
252
- * is also available to Ecmascript code in Duktape.version. Unofficial
253
- * development snapshots have 99 for patch level (e.g. 0.10.99 would be a
254
- * development version after 0.10.0 but before the next official release).
255
- */
256
- #define DUK_VERSION 20001L
257
-
258
- /* Git commit, describe, and branch for Duktape build. Useful for
259
- * non-official snapshot builds so that application code can easily log
260
- * which Duktape snapshot was used. Not available in the Ecmascript
261
- * environment.
262
- */
263
- #define DUK_GIT_COMMIT "3f5e91704aff97c754f6ef5d44aedc5e529d1b16"
264
- #define DUK_GIT_DESCRIBE "v2.0.1"
265
- #define DUK_GIT_BRANCH "v2.0-maintenance"
266
-
267
285
  /* Duktape debug protocol version used by this build. */
268
286
  #define DUK_DEBUG_PROTOCOL_VERSION 2
269
287
 
@@ -281,35 +299,35 @@ struct duk_time_components {
281
299
  /* Number of value stack entries (in addition to actual call arguments)
282
300
  * guaranteed to be allocated on entry to a Duktape/C function.
283
301
  */
284
- #define DUK_API_ENTRY_STACK 64
302
+ #define DUK_API_ENTRY_STACK 64U
285
303
 
286
304
  /* Value types, used by e.g. duk_get_type() */
287
- #define DUK_TYPE_MIN 0
288
- #define DUK_TYPE_NONE 0 /* no value, e.g. invalid index */
289
- #define DUK_TYPE_UNDEFINED 1 /* Ecmascript undefined */
290
- #define DUK_TYPE_NULL 2 /* Ecmascript null */
291
- #define DUK_TYPE_BOOLEAN 3 /* Ecmascript boolean: 0 or 1 */
292
- #define DUK_TYPE_NUMBER 4 /* Ecmascript number: double */
293
- #define DUK_TYPE_STRING 5 /* Ecmascript string: CESU-8 / extended UTF-8 encoded */
294
- #define DUK_TYPE_OBJECT 6 /* Ecmascript object: includes objects, arrays, functions, threads */
295
- #define DUK_TYPE_BUFFER 7 /* fixed or dynamic, garbage collected byte buffer */
296
- #define DUK_TYPE_POINTER 8 /* raw void pointer */
297
- #define DUK_TYPE_LIGHTFUNC 9 /* lightweight function pointer */
298
- #define DUK_TYPE_MAX 9
305
+ #define DUK_TYPE_MIN 0U
306
+ #define DUK_TYPE_NONE 0U /* no value, e.g. invalid index */
307
+ #define DUK_TYPE_UNDEFINED 1U /* ECMAScript undefined */
308
+ #define DUK_TYPE_NULL 2U /* ECMAScript null */
309
+ #define DUK_TYPE_BOOLEAN 3U /* ECMAScript boolean: 0 or 1 */
310
+ #define DUK_TYPE_NUMBER 4U /* ECMAScript number: double */
311
+ #define DUK_TYPE_STRING 5U /* ECMAScript string: CESU-8 / extended UTF-8 encoded */
312
+ #define DUK_TYPE_OBJECT 6U /* ECMAScript object: includes objects, arrays, functions, threads */
313
+ #define DUK_TYPE_BUFFER 7U /* fixed or dynamic, garbage collected byte buffer */
314
+ #define DUK_TYPE_POINTER 8U /* raw void pointer */
315
+ #define DUK_TYPE_LIGHTFUNC 9U /* lightweight function pointer */
316
+ #define DUK_TYPE_MAX 9U
299
317
 
300
318
  /* Value mask types, used by e.g. duk_get_type_mask() */
301
- #define DUK_TYPE_MASK_NONE (1 << DUK_TYPE_NONE)
302
- #define DUK_TYPE_MASK_UNDEFINED (1 << DUK_TYPE_UNDEFINED)
303
- #define DUK_TYPE_MASK_NULL (1 << DUK_TYPE_NULL)
304
- #define DUK_TYPE_MASK_BOOLEAN (1 << DUK_TYPE_BOOLEAN)
305
- #define DUK_TYPE_MASK_NUMBER (1 << DUK_TYPE_NUMBER)
306
- #define DUK_TYPE_MASK_STRING (1 << DUK_TYPE_STRING)
307
- #define DUK_TYPE_MASK_OBJECT (1 << DUK_TYPE_OBJECT)
308
- #define DUK_TYPE_MASK_BUFFER (1 << DUK_TYPE_BUFFER)
309
- #define DUK_TYPE_MASK_POINTER (1 << DUK_TYPE_POINTER)
310
- #define DUK_TYPE_MASK_LIGHTFUNC (1 << DUK_TYPE_LIGHTFUNC)
311
- #define DUK_TYPE_MASK_THROW (1 << 10) /* internal flag value: throw if mask doesn't match */
312
- #define DUK_TYPE_MASK_PROMOTE (1 << 11) /* internal flag value: promote to object if mask matches */
319
+ #define DUK_TYPE_MASK_NONE (1U << DUK_TYPE_NONE)
320
+ #define DUK_TYPE_MASK_UNDEFINED (1U << DUK_TYPE_UNDEFINED)
321
+ #define DUK_TYPE_MASK_NULL (1U << DUK_TYPE_NULL)
322
+ #define DUK_TYPE_MASK_BOOLEAN (1U << DUK_TYPE_BOOLEAN)
323
+ #define DUK_TYPE_MASK_NUMBER (1U << DUK_TYPE_NUMBER)
324
+ #define DUK_TYPE_MASK_STRING (1U << DUK_TYPE_STRING)
325
+ #define DUK_TYPE_MASK_OBJECT (1U << DUK_TYPE_OBJECT)
326
+ #define DUK_TYPE_MASK_BUFFER (1U << DUK_TYPE_BUFFER)
327
+ #define DUK_TYPE_MASK_POINTER (1U << DUK_TYPE_POINTER)
328
+ #define DUK_TYPE_MASK_LIGHTFUNC (1U << DUK_TYPE_LIGHTFUNC)
329
+ #define DUK_TYPE_MASK_THROW (1U << 10) /* internal flag value: throw if mask doesn't match */
330
+ #define DUK_TYPE_MASK_PROMOTE (1U << 11) /* internal flag value: promote to object if mask matches */
313
331
 
314
332
  /* Coercion hints */
315
333
  #define DUK_HINT_NONE 0 /* prefer number, unless input is a Date, in which
@@ -319,50 +337,83 @@ struct duk_time_components {
319
337
  #define DUK_HINT_NUMBER 2 /* prefer number */
320
338
 
321
339
  /* Enumeration flags for duk_enum() */
322
- #define DUK_ENUM_INCLUDE_NONENUMERABLE (1 << 0) /* enumerate non-numerable properties in addition to enumerable */
323
- #define DUK_ENUM_INCLUDE_HIDDEN (1 << 1) /* enumerate hidden symbols too (in Duktape 1.x called internal properties) */
324
- #define DUK_ENUM_INCLUDE_SYMBOLS (1 << 2) /* enumerate symbols */
325
- #define DUK_ENUM_EXCLUDE_STRINGS (1 << 3) /* exclude strings */
326
- #define DUK_ENUM_OWN_PROPERTIES_ONLY (1 << 4) /* don't walk prototype chain, only check own properties */
327
- #define DUK_ENUM_ARRAY_INDICES_ONLY (1 << 5) /* only enumerate array indices */
328
- #define DUK_ENUM_SORT_ARRAY_INDICES (1 << 6) /* sort array indices (applied to full enumeration result, including inherited array indices) */
329
- #define DUK_ENUM_NO_PROXY_BEHAVIOR (1 << 7) /* enumerate a proxy object itself without invoking proxy behavior */
340
+ #define DUK_ENUM_INCLUDE_NONENUMERABLE (1U << 0) /* enumerate non-numerable properties in addition to enumerable */
341
+ #define DUK_ENUM_INCLUDE_HIDDEN (1U << 1) /* enumerate hidden symbols too (in Duktape 1.x called internal properties) */
342
+ #define DUK_ENUM_INCLUDE_SYMBOLS (1U << 2) /* enumerate symbols */
343
+ #define DUK_ENUM_EXCLUDE_STRINGS (1U << 3) /* exclude strings */
344
+ #define DUK_ENUM_OWN_PROPERTIES_ONLY (1U << 4) /* don't walk prototype chain, only check own properties */
345
+ #define DUK_ENUM_ARRAY_INDICES_ONLY (1U << 5) /* only enumerate array indices */
346
+ /* XXX: misleading name */
347
+ #define DUK_ENUM_SORT_ARRAY_INDICES (1U << 6) /* sort array indices (applied to full enumeration result, including inherited array indices); XXX: misleading name */
348
+ #define DUK_ENUM_NO_PROXY_BEHAVIOR (1U << 7) /* enumerate a proxy object itself without invoking proxy behavior */
330
349
 
331
350
  /* Compilation flags for duk_compile() and duk_eval() */
332
351
  /* DUK_COMPILE_xxx bits 0-2 are reserved for an internal 'nargs' argument.
333
352
  */
334
- #define DUK_COMPILE_EVAL (1 << 3) /* compile eval code (instead of global code) */
335
- #define DUK_COMPILE_FUNCTION (1 << 4) /* compile function code (instead of global code) */
336
- #define DUK_COMPILE_STRICT (1 << 5) /* use strict (outer) context for global, eval, or function code */
337
- #define DUK_COMPILE_SAFE (1 << 6) /* (internal) catch compilation errors */
338
- #define DUK_COMPILE_NORESULT (1 << 7) /* (internal) omit eval result */
339
- #define DUK_COMPILE_NOSOURCE (1 << 8) /* (internal) no source string on stack */
340
- #define DUK_COMPILE_STRLEN (1 << 9) /* (internal) take strlen() of src_buffer (avoids double evaluation in macro) */
341
- #define DUK_COMPILE_NOFILENAME (1 << 10) /* (internal) no filename on stack */
342
-
343
- /* Flags for duk_def_prop() and its variants */
344
- #define DUK_DEFPROP_WRITABLE (1 << 0) /* set writable (effective if DUK_DEFPROP_HAVE_WRITABLE set) */
345
- #define DUK_DEFPROP_ENUMERABLE (1 << 1) /* set enumerable (effective if DUK_DEFPROP_HAVE_ENUMERABLE set) */
346
- #define DUK_DEFPROP_CONFIGURABLE (1 << 2) /* set configurable (effective if DUK_DEFPROP_HAVE_CONFIGURABLE set) */
347
- #define DUK_DEFPROP_HAVE_WRITABLE (1 << 3) /* set/clear writable */
348
- #define DUK_DEFPROP_HAVE_ENUMERABLE (1 << 4) /* set/clear enumerable */
349
- #define DUK_DEFPROP_HAVE_CONFIGURABLE (1 << 5) /* set/clear configurable */
350
- #define DUK_DEFPROP_HAVE_VALUE (1 << 6) /* set value (given on value stack) */
351
- #define DUK_DEFPROP_HAVE_GETTER (1 << 7) /* set getter (given on value stack) */
352
- #define DUK_DEFPROP_HAVE_SETTER (1 << 8) /* set setter (given on value stack) */
353
- #define DUK_DEFPROP_FORCE (1 << 9) /* force change if possible, may still fail for e.g. virtual properties */
353
+ #define DUK_COMPILE_EVAL (1U << 3) /* compile eval code (instead of global code) */
354
+ #define DUK_COMPILE_FUNCTION (1U << 4) /* compile function code (instead of global code) */
355
+ #define DUK_COMPILE_STRICT (1U << 5) /* use strict (outer) context for global, eval, or function code */
356
+ #define DUK_COMPILE_SHEBANG (1U << 6) /* allow shebang ('#! ...') comment on first line of source */
357
+ #define DUK_COMPILE_SAFE (1U << 7) /* (internal) catch compilation errors */
358
+ #define DUK_COMPILE_NORESULT (1U << 8) /* (internal) omit eval result */
359
+ #define DUK_COMPILE_NOSOURCE (1U << 9) /* (internal) no source string on stack */
360
+ #define DUK_COMPILE_STRLEN (1U << 10) /* (internal) take strlen() of src_buffer (avoids double evaluation in macro) */
361
+ #define DUK_COMPILE_NOFILENAME (1U << 11) /* (internal) no filename on stack */
362
+ #define DUK_COMPILE_FUNCEXPR (1U << 12) /* (internal) source is a function expression (used for Function constructor) */
363
+
364
+ /* Flags for duk_def_prop() and its variants; base flags + a lot of convenience shorthands */
365
+ #define DUK_DEFPROP_WRITABLE (1U << 0) /* set writable (effective if DUK_DEFPROP_HAVE_WRITABLE set) */
366
+ #define DUK_DEFPROP_ENUMERABLE (1U << 1) /* set enumerable (effective if DUK_DEFPROP_HAVE_ENUMERABLE set) */
367
+ #define DUK_DEFPROP_CONFIGURABLE (1U << 2) /* set configurable (effective if DUK_DEFPROP_HAVE_CONFIGURABLE set) */
368
+ #define DUK_DEFPROP_HAVE_WRITABLE (1U << 3) /* set/clear writable */
369
+ #define DUK_DEFPROP_HAVE_ENUMERABLE (1U << 4) /* set/clear enumerable */
370
+ #define DUK_DEFPROP_HAVE_CONFIGURABLE (1U << 5) /* set/clear configurable */
371
+ #define DUK_DEFPROP_HAVE_VALUE (1U << 6) /* set value (given on value stack) */
372
+ #define DUK_DEFPROP_HAVE_GETTER (1U << 7) /* set getter (given on value stack) */
373
+ #define DUK_DEFPROP_HAVE_SETTER (1U << 8) /* set setter (given on value stack) */
374
+ #define DUK_DEFPROP_FORCE (1U << 9) /* force change if possible, may still fail for e.g. virtual properties */
354
375
  #define DUK_DEFPROP_SET_WRITABLE (DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_WRITABLE)
355
376
  #define DUK_DEFPROP_CLEAR_WRITABLE DUK_DEFPROP_HAVE_WRITABLE
356
377
  #define DUK_DEFPROP_SET_ENUMERABLE (DUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_ENUMERABLE)
357
378
  #define DUK_DEFPROP_CLEAR_ENUMERABLE DUK_DEFPROP_HAVE_ENUMERABLE
358
379
  #define DUK_DEFPROP_SET_CONFIGURABLE (DUK_DEFPROP_HAVE_CONFIGURABLE | DUK_DEFPROP_CONFIGURABLE)
359
380
  #define DUK_DEFPROP_CLEAR_CONFIGURABLE DUK_DEFPROP_HAVE_CONFIGURABLE
381
+ #define DUK_DEFPROP_W DUK_DEFPROP_WRITABLE
382
+ #define DUK_DEFPROP_E DUK_DEFPROP_ENUMERABLE
383
+ #define DUK_DEFPROP_C DUK_DEFPROP_CONFIGURABLE
384
+ #define DUK_DEFPROP_WE (DUK_DEFPROP_WRITABLE | DUK_DEFPROP_ENUMERABLE)
385
+ #define DUK_DEFPROP_WC (DUK_DEFPROP_WRITABLE | DUK_DEFPROP_CONFIGURABLE)
386
+ #define DUK_DEFPROP_WEC (DUK_DEFPROP_WRITABLE | DUK_DEFPROP_ENUMERABLE | DUK_DEFPROP_CONFIGURABLE)
387
+ #define DUK_DEFPROP_HAVE_W DUK_DEFPROP_HAVE_WRITABLE
388
+ #define DUK_DEFPROP_HAVE_E DUK_DEFPROP_HAVE_ENUMERABLE
389
+ #define DUK_DEFPROP_HAVE_C DUK_DEFPROP_HAVE_CONFIGURABLE
390
+ #define DUK_DEFPROP_HAVE_WE (DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_HAVE_ENUMERABLE)
391
+ #define DUK_DEFPROP_HAVE_WC (DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_HAVE_CONFIGURABLE)
392
+ #define DUK_DEFPROP_HAVE_WEC (DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_HAVE_CONFIGURABLE)
393
+ #define DUK_DEFPROP_SET_W DUK_DEFPROP_SET_WRITABLE
394
+ #define DUK_DEFPROP_SET_E DUK_DEFPROP_SET_ENUMERABLE
395
+ #define DUK_DEFPROP_SET_C DUK_DEFPROP_SET_CONFIGURABLE
396
+ #define DUK_DEFPROP_SET_WE (DUK_DEFPROP_SET_WRITABLE | DUK_DEFPROP_SET_ENUMERABLE)
397
+ #define DUK_DEFPROP_SET_WC (DUK_DEFPROP_SET_WRITABLE | DUK_DEFPROP_SET_CONFIGURABLE)
398
+ #define DUK_DEFPROP_SET_WEC (DUK_DEFPROP_SET_WRITABLE | DUK_DEFPROP_SET_ENUMERABLE | DUK_DEFPROP_SET_CONFIGURABLE)
399
+ #define DUK_DEFPROP_CLEAR_W DUK_DEFPROP_CLEAR_WRITABLE
400
+ #define DUK_DEFPROP_CLEAR_E DUK_DEFPROP_CLEAR_ENUMERABLE
401
+ #define DUK_DEFPROP_CLEAR_C DUK_DEFPROP_CLEAR_CONFIGURABLE
402
+ #define DUK_DEFPROP_CLEAR_WE (DUK_DEFPROP_CLEAR_WRITABLE | DUK_DEFPROP_CLEAR_ENUMERABLE)
403
+ #define DUK_DEFPROP_CLEAR_WC (DUK_DEFPROP_CLEAR_WRITABLE | DUK_DEFPROP_CLEAR_CONFIGURABLE)
404
+ #define DUK_DEFPROP_CLEAR_WEC (DUK_DEFPROP_CLEAR_WRITABLE | DUK_DEFPROP_CLEAR_ENUMERABLE | DUK_DEFPROP_CLEAR_CONFIGURABLE)
405
+ #define DUK_DEFPROP_ATTR_W (DUK_DEFPROP_HAVE_WEC | DUK_DEFPROP_W)
406
+ #define DUK_DEFPROP_ATTR_E (DUK_DEFPROP_HAVE_WEC | DUK_DEFPROP_E)
407
+ #define DUK_DEFPROP_ATTR_C (DUK_DEFPROP_HAVE_WEC | DUK_DEFPROP_C)
408
+ #define DUK_DEFPROP_ATTR_WE (DUK_DEFPROP_HAVE_WEC | DUK_DEFPROP_WE)
409
+ #define DUK_DEFPROP_ATTR_WC (DUK_DEFPROP_HAVE_WEC | DUK_DEFPROP_WC)
410
+ #define DUK_DEFPROP_ATTR_WEC (DUK_DEFPROP_HAVE_WEC | DUK_DEFPROP_WEC)
360
411
 
361
412
  /* Flags for duk_push_thread_raw() */
362
- #define DUK_THREAD_NEW_GLOBAL_ENV (1 << 0) /* create a new global environment */
413
+ #define DUK_THREAD_NEW_GLOBAL_ENV (1U << 0) /* create a new global environment */
363
414
 
364
415
  /* Flags for duk_gc() */
365
- #define DUK_GC_COMPACT (1 << 0) /* compact heap objects */
416
+ #define DUK_GC_COMPACT (1U << 0) /* compact heap objects */
366
417
 
367
418
  /* Error codes (must be 8 bits at most, see duk_error.h) */
368
419
  #define DUK_ERR_NONE 0 /* no error (e.g. from duk_get_error_code()) */
@@ -392,6 +443,23 @@ struct duk_time_components {
392
443
  #define DUK_LEVEL_DDEBUG 1
393
444
  #define DUK_LEVEL_DDDEBUG 2
394
445
 
446
+ /*
447
+ * Macros to create Symbols as C statically constructed strings.
448
+ *
449
+ * Call e.g. as DUK_HIDDEN_SYMBOL("myProperty") <=> ("\xFF" "myProperty").
450
+ * Local symbols have a unique suffix, caller should take care to avoid
451
+ * conflicting with the Duktape internal representation by e.g. prepending
452
+ * a '!' character: DUK_LOCAL_SYMBOL("myLocal", "!123").
453
+ *
454
+ * Note that these can only be used for string constants, not dynamically
455
+ * created strings.
456
+ */
457
+
458
+ #define DUK_HIDDEN_SYMBOL(x) ("\xFF" x)
459
+ #define DUK_GLOBAL_SYMBOL(x) ("\x80" x)
460
+ #define DUK_LOCAL_SYMBOL(x,uniq) ("\x81" x "\xff" uniq)
461
+ #define DUK_WELLKNOWN_SYMBOL(x) ("\x81" x "\xff")
462
+
395
463
  /*
396
464
  * If no variadic macros, __FILE__ and __LINE__ are passed through globals
397
465
  * which is ugly and not thread safe.
@@ -445,9 +513,9 @@ DUK_API_NORETURN(DUK_EXTERNAL_DECL void duk_throw_raw(duk_context *ctx));
445
513
  DUK_API_NORETURN(DUK_EXTERNAL_DECL void duk_fatal_raw(duk_context *ctx, const char *err_msg));
446
514
  #define duk_fatal(ctx,err_msg) \
447
515
  (duk_fatal_raw((ctx), (err_msg)), (duk_ret_t) 0)
516
+ 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, ...));
448
517
 
449
518
  #if defined(DUK_API_VARIADIC_MACROS)
450
- 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, ...));
451
519
  #define duk_error(ctx,err_code,...) \
452
520
  (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)
453
521
  #define duk_generic_error(ctx,...) \
@@ -516,6 +584,7 @@ DUK_API_NORETURN(DUK_EXTERNAL_DECL duk_ret_t duk_uri_error_stash(duk_context *ct
516
584
  #endif /* DUK_API_VARIADIC_MACROS */
517
585
 
518
586
  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));
587
+
519
588
  #define duk_error_va(ctx,err_code,fmt,ap) \
520
589
  (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)
521
590
  #define duk_generic_error_va(ctx,fmt,ap) \
@@ -609,7 +678,21 @@ DUK_EXTERNAL_DECL void duk_push_pointer(duk_context *ctx, void *p);
609
678
  DUK_EXTERNAL_DECL const char *duk_push_sprintf(duk_context *ctx, const char *fmt, ...);
610
679
  DUK_EXTERNAL_DECL const char *duk_push_vsprintf(duk_context *ctx, const char *fmt, va_list ap);
611
680
 
681
+ /* duk_push_literal() may evaluate its argument (a C string literal) more than
682
+ * once on purpose. When speed is preferred, sizeof() avoids an unnecessary
683
+ * strlen() at runtime. Sizeof("foo") == 4, so subtract 1. The argument
684
+ * must be non-NULL and should not contain internal NUL characters as the
685
+ * behavior will then depend on config options.
686
+ */
687
+ #if defined(DUK_USE_PREFER_SIZE)
688
+ #define duk_push_literal(ctx,cstring) duk_push_string((ctx), (cstring))
689
+ #else
690
+ DUK_EXTERNAL_DECL const char *duk_push_literal_raw(duk_context *ctx, const char *str, duk_size_t len);
691
+ #define duk_push_literal(ctx,cstring) duk_push_literal_raw((ctx), (cstring), sizeof((cstring)) - 1U)
692
+ #endif
693
+
612
694
  DUK_EXTERNAL_DECL void duk_push_this(duk_context *ctx);
695
+ DUK_EXTERNAL_DECL void duk_push_new_target(duk_context *ctx);
613
696
  DUK_EXTERNAL_DECL void duk_push_current_function(duk_context *ctx);
614
697
  DUK_EXTERNAL_DECL void duk_push_current_thread(duk_context *ctx);
615
698
  DUK_EXTERNAL_DECL void duk_push_global_object(duk_context *ctx);
@@ -623,6 +706,7 @@ DUK_EXTERNAL_DECL duk_idx_t duk_push_array(duk_context *ctx);
623
706
  DUK_EXTERNAL_DECL duk_idx_t duk_push_c_function(duk_context *ctx, duk_c_function func, duk_idx_t nargs);
624
707
  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);
625
708
  DUK_EXTERNAL_DECL duk_idx_t duk_push_thread_raw(duk_context *ctx, duk_uint_t flags);
709
+ DUK_EXTERNAL_DECL duk_idx_t duk_push_proxy(duk_context *ctx, duk_uint_t proxy_flags);
626
710
 
627
711
  #define duk_push_thread(ctx) \
628
712
  duk_push_thread_raw((ctx), 0 /*flags*/)
@@ -663,19 +747,18 @@ DUK_EXTERNAL_DECL void *duk_push_buffer_raw(duk_context *ctx, duk_size_t size, d
663
747
  #define duk_push_external_buffer(ctx) \
664
748
  ((void) duk_push_buffer_raw((ctx), 0, DUK_BUF_FLAG_DYNAMIC | DUK_BUF_FLAG_EXTERNAL))
665
749
 
666
- #define DUK_BUFOBJ_CREATE_ARRBUF (1 << 4) /* internal flag: create backing ArrayBuffer; keep in one byte */
667
750
  #define DUK_BUFOBJ_ARRAYBUFFER 0
668
- #define DUK_BUFOBJ_NODEJS_BUFFER (1 | DUK_BUFOBJ_CREATE_ARRBUF)
669
- #define DUK_BUFOBJ_DATAVIEW (2 | DUK_BUFOBJ_CREATE_ARRBUF)
670
- #define DUK_BUFOBJ_INT8ARRAY (3 | DUK_BUFOBJ_CREATE_ARRBUF)
671
- #define DUK_BUFOBJ_UINT8ARRAY (4 | DUK_BUFOBJ_CREATE_ARRBUF)
672
- #define DUK_BUFOBJ_UINT8CLAMPEDARRAY (5 | DUK_BUFOBJ_CREATE_ARRBUF)
673
- #define DUK_BUFOBJ_INT16ARRAY (6 | DUK_BUFOBJ_CREATE_ARRBUF)
674
- #define DUK_BUFOBJ_UINT16ARRAY (7 | DUK_BUFOBJ_CREATE_ARRBUF)
675
- #define DUK_BUFOBJ_INT32ARRAY (8 | DUK_BUFOBJ_CREATE_ARRBUF)
676
- #define DUK_BUFOBJ_UINT32ARRAY (9 | DUK_BUFOBJ_CREATE_ARRBUF)
677
- #define DUK_BUFOBJ_FLOAT32ARRAY (10 | DUK_BUFOBJ_CREATE_ARRBUF)
678
- #define DUK_BUFOBJ_FLOAT64ARRAY (11 | DUK_BUFOBJ_CREATE_ARRBUF)
751
+ #define DUK_BUFOBJ_NODEJS_BUFFER 1
752
+ #define DUK_BUFOBJ_DATAVIEW 2
753
+ #define DUK_BUFOBJ_INT8ARRAY 3
754
+ #define DUK_BUFOBJ_UINT8ARRAY 4
755
+ #define DUK_BUFOBJ_UINT8CLAMPEDARRAY 5
756
+ #define DUK_BUFOBJ_INT16ARRAY 6
757
+ #define DUK_BUFOBJ_UINT16ARRAY 7
758
+ #define DUK_BUFOBJ_INT32ARRAY 8
759
+ #define DUK_BUFOBJ_UINT32ARRAY 9
760
+ #define DUK_BUFOBJ_FLOAT32ARRAY 10
761
+ #define DUK_BUFOBJ_FLOAT64ARRAY 11
679
762
 
680
763
  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);
681
764
 
@@ -727,6 +810,8 @@ DUK_EXTERNAL_DECL duk_bool_t duk_is_thread(duk_context *ctx, duk_idx_t idx);
727
810
 
728
811
  #define duk_is_callable(ctx,idx) \
729
812
  duk_is_function((ctx), (idx))
813
+ DUK_EXTERNAL_DECL duk_bool_t duk_is_constructable(duk_context *ctx, duk_idx_t idx);
814
+
730
815
  DUK_EXTERNAL_DECL duk_bool_t duk_is_dynamic_buffer(duk_context *ctx, duk_idx_t idx);
731
816
  DUK_EXTERNAL_DECL duk_bool_t duk_is_fixed_buffer(duk_context *ctx, duk_idx_t idx);
732
817
  DUK_EXTERNAL_DECL duk_bool_t duk_is_external_buffer(duk_context *ctx, duk_idx_t idx);
@@ -789,8 +874,43 @@ DUK_EXTERNAL_DECL void *duk_get_pointer(duk_context *ctx, duk_idx_t idx);
789
874
  DUK_EXTERNAL_DECL duk_c_function duk_get_c_function(duk_context *ctx, duk_idx_t idx);
790
875
  DUK_EXTERNAL_DECL duk_context *duk_get_context(duk_context *ctx, duk_idx_t idx);
791
876
  DUK_EXTERNAL_DECL void *duk_get_heapptr(duk_context *ctx, duk_idx_t idx);
792
- DUK_EXTERNAL_DECL duk_size_t duk_get_length(duk_context *ctx, duk_idx_t idx);
793
- DUK_EXTERNAL_DECL void duk_set_length(duk_context *ctx, duk_idx_t idx, duk_size_t len);
877
+
878
+ /*
879
+ * Get-with-explicit default operations: like get operations but with an
880
+ * explicit default value.
881
+ */
882
+
883
+ DUK_EXTERNAL_DECL duk_bool_t duk_get_boolean_default(duk_context *ctx, duk_idx_t idx, duk_bool_t def_value);
884
+ DUK_EXTERNAL_DECL duk_double_t duk_get_number_default(duk_context *ctx, duk_idx_t idx, duk_double_t def_value);
885
+ DUK_EXTERNAL_DECL duk_int_t duk_get_int_default(duk_context *ctx, duk_idx_t idx, duk_int_t def_value);
886
+ DUK_EXTERNAL_DECL duk_uint_t duk_get_uint_default(duk_context *ctx, duk_idx_t idx, duk_uint_t def_value);
887
+ DUK_EXTERNAL_DECL const char *duk_get_string_default(duk_context *ctx, duk_idx_t idx, const char *def_value);
888
+ 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);
889
+ 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);
890
+ 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);
891
+ DUK_EXTERNAL_DECL void *duk_get_pointer_default(duk_context *ctx, duk_idx_t idx, void *def_value);
892
+ DUK_EXTERNAL_DECL duk_c_function duk_get_c_function_default(duk_context *ctx, duk_idx_t idx, duk_c_function def_value);
893
+ DUK_EXTERNAL_DECL duk_context *duk_get_context_default(duk_context *ctx, duk_idx_t idx, duk_context *def_value);
894
+ DUK_EXTERNAL_DECL void *duk_get_heapptr_default(duk_context *ctx, duk_idx_t idx, void *def_value);
895
+
896
+ /*
897
+ * Opt operations: like require operations but with an explicit default value
898
+ * when value is undefined or index is invalid, null and non-matching types
899
+ * cause a TypeError.
900
+ */
901
+
902
+ DUK_EXTERNAL_DECL duk_bool_t duk_opt_boolean(duk_context *ctx, duk_idx_t idx, duk_bool_t def_value);
903
+ DUK_EXTERNAL_DECL duk_double_t duk_opt_number(duk_context *ctx, duk_idx_t idx, duk_double_t def_value);
904
+ DUK_EXTERNAL_DECL duk_int_t duk_opt_int(duk_context *ctx, duk_idx_t idx, duk_int_t def_value);
905
+ DUK_EXTERNAL_DECL duk_uint_t duk_opt_uint(duk_context *ctx, duk_idx_t idx, duk_uint_t def_value);
906
+ DUK_EXTERNAL_DECL const char *duk_opt_string(duk_context *ctx, duk_idx_t idx, const char *def_ptr);
907
+ 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);
908
+ 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);
909
+ 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);
910
+ DUK_EXTERNAL_DECL void *duk_opt_pointer(duk_context *ctx, duk_idx_t idx, void *def_value);
911
+ DUK_EXTERNAL_DECL duk_c_function duk_opt_c_function(duk_context *ctx, duk_idx_t idx, duk_c_function def_value);
912
+ DUK_EXTERNAL_DECL duk_context *duk_opt_context(duk_context *ctx, duk_idx_t idx, duk_context *def_value);
913
+ DUK_EXTERNAL_DECL void *duk_opt_heapptr(duk_context *ctx, duk_idx_t idx, void *def_value);
794
914
 
795
915
  /*
796
916
  * Require operations: no coercion, throw error if index or type
@@ -808,6 +928,7 @@ DUK_EXTERNAL_DECL duk_int_t duk_require_int(duk_context *ctx, duk_idx_t idx);
808
928
  DUK_EXTERNAL_DECL duk_uint_t duk_require_uint(duk_context *ctx, duk_idx_t idx);
809
929
  DUK_EXTERNAL_DECL const char *duk_require_string(duk_context *ctx, duk_idx_t idx);
810
930
  DUK_EXTERNAL_DECL const char *duk_require_lstring(duk_context *ctx, duk_idx_t idx, duk_size_t *out_len);
931
+ DUK_EXTERNAL_DECL void duk_require_object(duk_context *ctx, duk_idx_t idx);
811
932
  DUK_EXTERNAL_DECL void *duk_require_buffer(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size);
812
933
  DUK_EXTERNAL_DECL void *duk_require_buffer_data(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size);
813
934
  DUK_EXTERNAL_DECL void *duk_require_pointer(duk_context *ctx, duk_idx_t idx);
@@ -868,6 +989,17 @@ DUK_EXTERNAL_DECL const char *duk_safe_to_lstring(duk_context *ctx, duk_idx_t id
868
989
  #define duk_safe_to_string(ctx,idx) \
869
990
  duk_safe_to_lstring((ctx), (idx), NULL)
870
991
 
992
+ /*
993
+ * Value length
994
+ */
995
+
996
+ DUK_EXTERNAL_DECL duk_size_t duk_get_length(duk_context *ctx, duk_idx_t idx);
997
+ DUK_EXTERNAL_DECL void duk_set_length(duk_context *ctx, duk_idx_t idx, duk_size_t len);
998
+ #if 0
999
+ /* duk_require_length()? */
1000
+ /* duk_opt_length()? */
1001
+ #endif
1002
+
871
1003
  /*
872
1004
  * Misc conversion
873
1005
  */
@@ -892,35 +1024,79 @@ DUK_EXTERNAL_DECL void duk_config_buffer(duk_context *ctx, duk_idx_t idx, void *
892
1024
  /*
893
1025
  * Property access
894
1026
  *
895
- * The basic function assumes key is on stack. The _string variant takes
896
- * a C string as a property name, while the _index variant takes an array
897
- * index as a property name (e.g. 123 is equivalent to the key "123").
1027
+ * The basic function assumes key is on stack. The _(l)string variant takes
1028
+ * a C string as a property name; the _literal variant takes a C literal.
1029
+ * The _index variant takes an array index as a property name (e.g. 123 is
1030
+ * equivalent to the key "123"). The _heapptr variant takes a raw, borrowed
1031
+ * heap pointer.
898
1032
  */
899
1033
 
900
1034
  DUK_EXTERNAL_DECL duk_bool_t duk_get_prop(duk_context *ctx, duk_idx_t obj_idx);
901
1035
  DUK_EXTERNAL_DECL duk_bool_t duk_get_prop_string(duk_context *ctx, duk_idx_t obj_idx, const char *key);
902
1036
  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);
1037
+ #if defined(DUK_USE_PREFER_SIZE)
1038
+ #define duk_get_prop_literal(ctx,obj_idx,key) duk_get_prop_string((ctx), (obj_idx), (key))
1039
+ #else
1040
+ 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);
1041
+ #define duk_get_prop_literal(ctx,obj_idx,key) duk_get_prop_literal_raw((ctx), (obj_idx), (key), sizeof((key)) - 1U)
1042
+ #endif
903
1043
  DUK_EXTERNAL_DECL duk_bool_t duk_get_prop_index(duk_context *ctx, duk_idx_t obj_idx, duk_uarridx_t arr_idx);
1044
+ DUK_EXTERNAL_DECL duk_bool_t duk_get_prop_heapptr(duk_context *ctx, duk_idx_t obj_idx, void *ptr);
904
1045
  DUK_EXTERNAL_DECL duk_bool_t duk_put_prop(duk_context *ctx, duk_idx_t obj_idx);
905
1046
  DUK_EXTERNAL_DECL duk_bool_t duk_put_prop_string(duk_context *ctx, duk_idx_t obj_idx, const char *key);
906
1047
  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);
1048
+ #if defined(DUK_USE_PREFER_SIZE)
1049
+ #define duk_put_prop_literal(ctx,obj_idx,key) duk_put_prop_string((ctx), (obj_idx), (key))
1050
+ #else
1051
+ 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);
1052
+ #define duk_put_prop_literal(ctx,obj_idx,key) duk_put_prop_literal_raw((ctx), (obj_idx), (key), sizeof((key)) - 1U)
1053
+ #endif
907
1054
  DUK_EXTERNAL_DECL duk_bool_t duk_put_prop_index(duk_context *ctx, duk_idx_t obj_idx, duk_uarridx_t arr_idx);
1055
+ DUK_EXTERNAL_DECL duk_bool_t duk_put_prop_heapptr(duk_context *ctx, duk_idx_t obj_idx, void *ptr);
908
1056
  DUK_EXTERNAL_DECL duk_bool_t duk_del_prop(duk_context *ctx, duk_idx_t obj_idx);
909
1057
  DUK_EXTERNAL_DECL duk_bool_t duk_del_prop_string(duk_context *ctx, duk_idx_t obj_idx, const char *key);
910
1058
  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);
1059
+ #if defined(DUK_USE_PREFER_SIZE)
1060
+ #define duk_del_prop_literal(ctx,obj_idx,key) duk_del_prop_string((ctx), (obj_idx), (key))
1061
+ #else
1062
+ 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);
1063
+ #define duk_del_prop_literal(ctx,obj_idx,key) duk_del_prop_literal_raw((ctx), (obj_idx), (key), sizeof((key)) - 1U)
1064
+ #endif
911
1065
  DUK_EXTERNAL_DECL duk_bool_t duk_del_prop_index(duk_context *ctx, duk_idx_t obj_idx, duk_uarridx_t arr_idx);
1066
+ DUK_EXTERNAL_DECL duk_bool_t duk_del_prop_heapptr(duk_context *ctx, duk_idx_t obj_idx, void *ptr);
912
1067
  DUK_EXTERNAL_DECL duk_bool_t duk_has_prop(duk_context *ctx, duk_idx_t obj_idx);
913
1068
  DUK_EXTERNAL_DECL duk_bool_t duk_has_prop_string(duk_context *ctx, duk_idx_t obj_idx, const char *key);
914
1069
  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);
1070
+ #if defined(DUK_USE_PREFER_SIZE)
1071
+ #define duk_has_prop_literal(ctx,obj_idx,key) duk_has_prop_string((ctx), (obj_idx), (key))
1072
+ #else
1073
+ 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);
1074
+ #define duk_has_prop_literal(ctx,obj_idx,key) duk_has_prop_literal_raw((ctx), (obj_idx), (key), sizeof((key)) - 1U)
1075
+ #endif
915
1076
  DUK_EXTERNAL_DECL duk_bool_t duk_has_prop_index(duk_context *ctx, duk_idx_t obj_idx, duk_uarridx_t arr_idx);
1077
+ DUK_EXTERNAL_DECL duk_bool_t duk_has_prop_heapptr(duk_context *ctx, duk_idx_t obj_idx, void *ptr);
916
1078
 
917
1079
  DUK_EXTERNAL_DECL void duk_get_prop_desc(duk_context *ctx, duk_idx_t obj_idx, duk_uint_t flags);
918
1080
  DUK_EXTERNAL_DECL void duk_def_prop(duk_context *ctx, duk_idx_t obj_idx, duk_uint_t flags);
919
1081
 
920
1082
  DUK_EXTERNAL_DECL duk_bool_t duk_get_global_string(duk_context *ctx, const char *key);
921
1083
  DUK_EXTERNAL_DECL duk_bool_t duk_get_global_lstring(duk_context *ctx, const char *key, duk_size_t key_len);
1084
+ #if defined(DUK_USE_PREFER_SIZE)
1085
+ #define duk_get_global_literal(ctx,key) duk_get_global_string((ctx), (key))
1086
+ #else
1087
+ DUK_EXTERNAL_DECL duk_bool_t duk_get_global_literal_raw(duk_context *ctx, const char *key, duk_size_t key_len);
1088
+ #define duk_get_global_literal(ctx,key) duk_get_global_literal_raw((ctx), (key), sizeof((key)) - 1U)
1089
+ #endif
1090
+ DUK_EXTERNAL_DECL duk_bool_t duk_get_global_heapptr(duk_context *ctx, void *ptr);
922
1091
  DUK_EXTERNAL_DECL duk_bool_t duk_put_global_string(duk_context *ctx, const char *key);
923
1092
  DUK_EXTERNAL_DECL duk_bool_t duk_put_global_lstring(duk_context *ctx, const char *key, duk_size_t key_len);
1093
+ #if defined(DUK_USE_PREFER_SIZE)
1094
+ #define duk_put_global_literal(ctx,key) duk_put_global_string((ctx), (key))
1095
+ #else
1096
+ DUK_EXTERNAL_DECL duk_bool_t duk_put_global_literal_raw(duk_context *ctx, const char *key, duk_size_t key_len);
1097
+ #define duk_put_global_literal(ctx,key) duk_put_global_literal_raw((ctx), (key), sizeof((key)) - 1U)
1098
+ #endif
1099
+ DUK_EXTERNAL_DECL duk_bool_t duk_put_global_heapptr(duk_context *ctx, void *ptr);
924
1100
 
925
1101
  /*
926
1102
  * Inspection
@@ -971,6 +1147,8 @@ DUK_EXTERNAL_DECL void duk_put_number_list(duk_context *ctx, duk_idx_t obj_idx,
971
1147
  DUK_EXTERNAL_DECL void duk_compact(duk_context *ctx, duk_idx_t obj_idx);
972
1148
  DUK_EXTERNAL_DECL void duk_enum(duk_context *ctx, duk_idx_t obj_idx, duk_uint_t enum_flags);
973
1149
  DUK_EXTERNAL_DECL duk_bool_t duk_next(duk_context *ctx, duk_idx_t enum_idx, duk_bool_t get_value);
1150
+ DUK_EXTERNAL_DECL void duk_seal(duk_context *ctx, duk_idx_t obj_idx);
1151
+ DUK_EXTERNAL_DECL void duk_freeze(duk_context *ctx, duk_idx_t obj_idx);
974
1152
 
975
1153
  /*
976
1154
  * String manipulation
@@ -985,7 +1163,7 @@ DUK_EXTERNAL_DECL void duk_trim(duk_context *ctx, duk_idx_t idx);
985
1163
  DUK_EXTERNAL_DECL duk_codepoint_t duk_char_code_at(duk_context *ctx, duk_idx_t idx, duk_size_t char_offset);
986
1164
 
987
1165
  /*
988
- * Ecmascript operators
1166
+ * ECMAScript operators
989
1167
  */
990
1168
 
991
1169
  DUK_EXTERNAL_DECL duk_bool_t duk_equals(duk_context *ctx, duk_idx_t idx1, duk_idx_t idx2);
@@ -993,6 +1171,12 @@ DUK_EXTERNAL_DECL duk_bool_t duk_strict_equals(duk_context *ctx, duk_idx_t idx1,
993
1171
  DUK_EXTERNAL_DECL duk_bool_t duk_samevalue(duk_context *ctx, duk_idx_t idx1, duk_idx_t idx2);
994
1172
  DUK_EXTERNAL_DECL duk_bool_t duk_instanceof(duk_context *ctx, duk_idx_t idx1, duk_idx_t idx2);
995
1173
 
1174
+ /*
1175
+ * Random
1176
+ */
1177
+
1178
+ DUK_EXTERNAL_DECL duk_double_t duk_random(duk_context *ctx);
1179
+
996
1180
  /*
997
1181
  * Function (method) calls
998
1182
  */
@@ -1143,7 +1327,7 @@ DUK_EXTERNAL_DECL duk_double_t duk_components_to_time(duk_context *ctx, duk_time
1143
1327
  #define DUK_DATE_MSEC_HOUR (60L * 60L * 1000L)
1144
1328
  #define DUK_DATE_MSEC_DAY (24L * 60L * 60L * 1000L)
1145
1329
 
1146
- /* Ecmascript date range is 100 million days from Epoch:
1330
+ /* ECMAScript date range is 100 million days from Epoch:
1147
1331
  * > 100e6 * 24 * 60 * 60 * 1000 // 100M days in millisecs
1148
1332
  * 8640000000000000
1149
1333
  * (= 8.64e15)
@@ -1151,7 +1335,7 @@ DUK_EXTERNAL_DECL duk_double_t duk_components_to_time(duk_context *ctx, duk_time
1151
1335
  #define DUK_DATE_MSEC_100M_DAYS (8.64e15)
1152
1336
  #define DUK_DATE_MSEC_100M_DAYS_LEEWAY (8.64e15 + 24 * 3600e3)
1153
1337
 
1154
- /* Ecmascript year range:
1338
+ /* ECMAScript year range:
1155
1339
  * > new Date(100e6 * 24 * 3600e3).toISOString()
1156
1340
  * '+275760-09-13T00:00:00.000Z'
1157
1341
  * > new Date(-100e6 * 24 * 3600e3).toISOString()
@@ -1161,7 +1345,7 @@ DUK_EXTERNAL_DECL duk_double_t duk_components_to_time(duk_context *ctx, duk_time
1161
1345
  #define DUK_DATE_MAX_ECMA_YEAR 275760L
1162
1346
 
1163
1347
  /* Part indices for internal breakdowns. Part order from DUK_DATE_IDX_YEAR
1164
- * to DUK_DATE_IDX_MILLISECOND matches argument ordering of Ecmascript API
1348
+ * to DUK_DATE_IDX_MILLISECOND matches argument ordering of ECMAScript API
1165
1349
  * calls (like Date constructor call). Some functions in duk_bi_date.c
1166
1350
  * depend on the specific ordering, so change with care. 16 bits are not
1167
1351
  * enough for all parts (year, specifically).
@@ -1228,434 +1412,8 @@ DUK_EXTERNAL_DECL const void * const duk_rom_compressed_pointers[];
1228
1412
  }
1229
1413
  #endif
1230
1414
 
1231
- #endif /* DUK_API_PUBLIC_H_INCLUDED */
1232
-
1233
1415
  /*
1234
1416
  * END PUBLIC API
1235
1417
  */
1236
1418
 
1237
- /*
1238
- * Union to access IEEE double memory representation, indexes for double
1239
- * memory representation, and some macros for double manipulation.
1240
- *
1241
- * Also used by packed duk_tval. Use a union for bit manipulation to
1242
- * minimize aliasing issues in practice. The C99 standard does not
1243
- * guarantee that this should work, but it's a very widely supported
1244
- * practice for low level manipulation.
1245
- *
1246
- * IEEE double format summary:
1247
- *
1248
- * seeeeeee eeeeffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
1249
- * A B C D E F G H
1250
- *
1251
- * s sign bit
1252
- * eee... exponent field
1253
- * fff... fraction
1254
- *
1255
- * See http://en.wikipedia.org/wiki/Double_precision_floating-point_format.
1256
- *
1257
- * NaNs are represented as exponent 0x7ff and mantissa != 0. The NaN is a
1258
- * signaling NaN when the highest bit of the mantissa is zero, and a quiet
1259
- * NaN when the highest bit is set.
1260
- *
1261
- * At least three memory layouts are relevant here:
1262
- *
1263
- * A B C D E F G H Big endian (e.g. 68k) DUK_USE_DOUBLE_BE
1264
- * H G F E D C B A Little endian (e.g. x86) DUK_USE_DOUBLE_LE
1265
- * D C B A H G F E Mixed/cross endian (e.g. ARM) DUK_USE_DOUBLE_ME
1266
- *
1267
- * ARM is a special case: ARM double values are in mixed/cross endian
1268
- * format while ARM duk_uint64_t values are in standard little endian
1269
- * format (H G F E D C B A). When a double is read as a duk_uint64_t
1270
- * from memory, the register will contain the (logical) value
1271
- * E F G H A B C D. This requires some special handling below.
1272
- *
1273
- * Indexes of various types (8-bit, 16-bit, 32-bit) in memory relative to
1274
- * the logical (big endian) order:
1275
- *
1276
- * byte order duk_uint8_t duk_uint16_t duk_uint32_t
1277
- * BE 01234567 0123 01
1278
- * LE 76543210 3210 10
1279
- * ME (ARM) 32107654 1032 01
1280
- *
1281
- * Some processors may alter NaN values in a floating point load+store.
1282
- * For instance, on X86 a FLD + FSTP may convert a signaling NaN to a
1283
- * quiet one. This is catastrophic when NaN space is used in packed
1284
- * duk_tval values. See: misc/clang_aliasing.c.
1285
- */
1286
-
1287
- #if !defined(DUK_DBLUNION_H_INCLUDED)
1288
- #define DUK_DBLUNION_H_INCLUDED
1289
-
1290
- /*
1291
- * Union for accessing double parts, also serves as packed duk_tval
1292
- */
1293
-
1294
- union duk_double_union {
1295
- double d;
1296
- float f[2];
1297
- #if defined(DUK_USE_64BIT_OPS)
1298
- duk_uint64_t ull[1];
1299
- #endif
1300
- duk_uint32_t ui[2];
1301
- duk_uint16_t us[4];
1302
- duk_uint8_t uc[8];
1303
- #if defined(DUK_USE_PACKED_TVAL)
1304
- void *vp[2]; /* used by packed duk_tval, assumes sizeof(void *) == 4 */
1305
- #endif
1306
- };
1307
-
1308
- typedef union duk_double_union duk_double_union;
1309
-
1310
- /*
1311
- * Indexes of various types with respect to big endian (logical) layout
1312
- */
1313
-
1314
- #if defined(DUK_USE_DOUBLE_LE)
1315
- #if defined(DUK_USE_64BIT_OPS)
1316
- #define DUK_DBL_IDX_ULL0 0
1317
- #endif
1318
- #define DUK_DBL_IDX_UI0 1
1319
- #define DUK_DBL_IDX_UI1 0
1320
- #define DUK_DBL_IDX_US0 3
1321
- #define DUK_DBL_IDX_US1 2
1322
- #define DUK_DBL_IDX_US2 1
1323
- #define DUK_DBL_IDX_US3 0
1324
- #define DUK_DBL_IDX_UC0 7
1325
- #define DUK_DBL_IDX_UC1 6
1326
- #define DUK_DBL_IDX_UC2 5
1327
- #define DUK_DBL_IDX_UC3 4
1328
- #define DUK_DBL_IDX_UC4 3
1329
- #define DUK_DBL_IDX_UC5 2
1330
- #define DUK_DBL_IDX_UC6 1
1331
- #define DUK_DBL_IDX_UC7 0
1332
- #define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */
1333
- #define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */
1334
- #elif defined(DUK_USE_DOUBLE_BE)
1335
- #if defined(DUK_USE_64BIT_OPS)
1336
- #define DUK_DBL_IDX_ULL0 0
1337
- #endif
1338
- #define DUK_DBL_IDX_UI0 0
1339
- #define DUK_DBL_IDX_UI1 1
1340
- #define DUK_DBL_IDX_US0 0
1341
- #define DUK_DBL_IDX_US1 1
1342
- #define DUK_DBL_IDX_US2 2
1343
- #define DUK_DBL_IDX_US3 3
1344
- #define DUK_DBL_IDX_UC0 0
1345
- #define DUK_DBL_IDX_UC1 1
1346
- #define DUK_DBL_IDX_UC2 2
1347
- #define DUK_DBL_IDX_UC3 3
1348
- #define DUK_DBL_IDX_UC4 4
1349
- #define DUK_DBL_IDX_UC5 5
1350
- #define DUK_DBL_IDX_UC6 6
1351
- #define DUK_DBL_IDX_UC7 7
1352
- #define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */
1353
- #define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */
1354
- #elif defined(DUK_USE_DOUBLE_ME)
1355
- #if defined(DUK_USE_64BIT_OPS)
1356
- #define DUK_DBL_IDX_ULL0 0 /* not directly applicable, byte order differs from a double */
1357
- #endif
1358
- #define DUK_DBL_IDX_UI0 0
1359
- #define DUK_DBL_IDX_UI1 1
1360
- #define DUK_DBL_IDX_US0 1
1361
- #define DUK_DBL_IDX_US1 0
1362
- #define DUK_DBL_IDX_US2 3
1363
- #define DUK_DBL_IDX_US3 2
1364
- #define DUK_DBL_IDX_UC0 3
1365
- #define DUK_DBL_IDX_UC1 2
1366
- #define DUK_DBL_IDX_UC2 1
1367
- #define DUK_DBL_IDX_UC3 0
1368
- #define DUK_DBL_IDX_UC4 7
1369
- #define DUK_DBL_IDX_UC5 6
1370
- #define DUK_DBL_IDX_UC6 5
1371
- #define DUK_DBL_IDX_UC7 4
1372
- #define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */
1373
- #define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */
1374
- #else
1375
- #error internal error
1376
- #endif
1377
-
1378
- /*
1379
- * Helper macros for reading/writing memory representation parts, used
1380
- * by duk_numconv.c and duk_tval.h.
1381
- */
1382
-
1383
- #define DUK_DBLUNION_SET_DOUBLE(u,v) do { \
1384
- (u)->d = (v); \
1385
- } while (0)
1386
-
1387
- #define DUK_DBLUNION_SET_HIGH32(u,v) do { \
1388
- (u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) (v); \
1389
- } while (0)
1390
-
1391
- #if defined(DUK_USE_64BIT_OPS)
1392
- #if defined(DUK_USE_DOUBLE_ME)
1393
- #define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \
1394
- (u)->ull[DUK_DBL_IDX_ULL0] = (duk_uint64_t) (v); \
1395
- } while (0)
1396
- #else
1397
- #define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \
1398
- (u)->ull[DUK_DBL_IDX_ULL0] = ((duk_uint64_t) (v)) << 32; \
1399
- } while (0)
1400
- #endif
1401
- #else /* DUK_USE_64BIT_OPS */
1402
- #define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \
1403
- (u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) (v); \
1404
- (u)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) 0; \
1405
- } while (0)
1406
- #endif /* DUK_USE_64BIT_OPS */
1407
-
1408
- #define DUK_DBLUNION_SET_LOW32(u,v) do { \
1409
- (u)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) (v); \
1410
- } while (0)
1411
-
1412
- #define DUK_DBLUNION_GET_DOUBLE(u) ((u)->d)
1413
- #define DUK_DBLUNION_GET_HIGH32(u) ((u)->ui[DUK_DBL_IDX_UI0])
1414
- #define DUK_DBLUNION_GET_LOW32(u) ((u)->ui[DUK_DBL_IDX_UI1])
1415
-
1416
- #if defined(DUK_USE_64BIT_OPS)
1417
- #if defined(DUK_USE_DOUBLE_ME)
1418
- #define DUK_DBLUNION_SET_UINT64(u,v) do { \
1419
- (u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) ((v) >> 32); \
1420
- (u)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) (v); \
1421
- } while (0)
1422
- #define DUK_DBLUNION_GET_UINT64(u) \
1423
- ((((duk_uint64_t) (u)->ui[DUK_DBL_IDX_UI0]) << 32) | \
1424
- ((duk_uint64_t) (u)->ui[DUK_DBL_IDX_UI1]))
1425
- #else
1426
- #define DUK_DBLUNION_SET_UINT64(u,v) do { \
1427
- (u)->ull[DUK_DBL_IDX_ULL0] = (duk_uint64_t) (v); \
1428
- } while (0)
1429
- #define DUK_DBLUNION_GET_UINT64(u) ((u)->ull[DUK_DBL_IDX_ULL0])
1430
- #endif
1431
- #define DUK_DBLUNION_SET_INT64(u,v) DUK_DBLUNION_SET_UINT64((u), (duk_uint64_t) (v))
1432
- #define DUK_DBLUNION_GET_INT64(u) ((duk_int64_t) DUK_DBLUNION_GET_UINT64((u)))
1433
- #endif /* DUK_USE_64BIT_OPS */
1434
-
1435
- /*
1436
- * Double NaN manipulation macros related to NaN normalization needed when
1437
- * using the packed duk_tval representation. NaN normalization is necessary
1438
- * to keep double values compatible with the duk_tval format.
1439
- *
1440
- * When packed duk_tval is used, the NaN space is used to store pointers
1441
- * and other tagged values in addition to NaNs. Actual NaNs are normalized
1442
- * to a specific quiet NaN. The macros below are used by the implementation
1443
- * to check and normalize NaN values when they might be created. The macros
1444
- * are essentially NOPs when the non-packed duk_tval representation is used.
1445
- *
1446
- * A FULL check is exact and checks all bits. A NOTFULL check is used by
1447
- * the packed duk_tval and works correctly for all NaNs except those that
1448
- * begin with 0x7ff0. Since the 'normalized NaN' values used with packed
1449
- * duk_tval begin with 0x7ff8, the partial check is reliable when packed
1450
- * duk_tval is used. The 0x7ff8 prefix means the normalized NaN will be a
1451
- * quiet NaN regardless of its remaining lower bits.
1452
- *
1453
- * The ME variant below is specifically for ARM byte order, which has the
1454
- * feature that while doubles have a mixed byte order (32107654), unsigned
1455
- * long long values has a little endian byte order (76543210). When writing
1456
- * a logical double value through a ULL pointer, the 32-bit words need to be
1457
- * swapped; hence the #if defined()s below for ULL writes with DUK_USE_DOUBLE_ME.
1458
- * This is not full ARM support but suffices for some environments.
1459
- */
1460
-
1461
- #if defined(DUK_USE_64BIT_OPS)
1462
- #if defined(DUK_USE_DOUBLE_ME)
1463
- /* Macros for 64-bit ops + mixed endian doubles. */
1464
- #define DUK__DBLUNION_SET_NAN_FULL(u) do { \
1465
- (u)->ull[DUK_DBL_IDX_ULL0] = 0x000000007ff80000ULL; \
1466
- } while (0)
1467
- #define DUK__DBLUNION_IS_NAN_FULL(u) \
1468
- ((((u)->ull[DUK_DBL_IDX_ULL0] & 0x000000007ff00000ULL) == 0x000000007ff00000ULL) && \
1469
- ((((u)->ull[DUK_DBL_IDX_ULL0]) & 0xffffffff000fffffULL) != 0))
1470
- #define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \
1471
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0x000000007ff80000ULL)
1472
- #define DUK__DBLUNION_IS_ANYINF(u) \
1473
- (((u)->ull[DUK_DBL_IDX_ULL0] & 0xffffffff7fffffffULL) == 0x000000007ff00000ULL)
1474
- #define DUK__DBLUNION_IS_POSINF(u) \
1475
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0x000000007ff00000ULL)
1476
- #define DUK__DBLUNION_IS_NEGINF(u) \
1477
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0x00000000fff00000ULL)
1478
- #define DUK__DBLUNION_IS_ANYZERO(u) \
1479
- (((u)->ull[DUK_DBL_IDX_ULL0] & 0xffffffff7fffffffULL) == 0x0000000000000000ULL)
1480
- #define DUK__DBLUNION_IS_POSZERO(u) \
1481
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0x0000000000000000ULL)
1482
- #define DUK__DBLUNION_IS_NEGZERO(u) \
1483
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0x0000000080000000ULL)
1484
- #else
1485
- /* Macros for 64-bit ops + big/little endian doubles. */
1486
- #define DUK__DBLUNION_SET_NAN_FULL(u) do { \
1487
- (u)->ull[DUK_DBL_IDX_ULL0] = 0x7ff8000000000000ULL; \
1488
- } while (0)
1489
- #define DUK__DBLUNION_IS_NAN_FULL(u) \
1490
- ((((u)->ull[DUK_DBL_IDX_ULL0] & 0x7ff0000000000000ULL) == 0x7ff0000000000000UL) && \
1491
- ((((u)->ull[DUK_DBL_IDX_ULL0]) & 0x000fffffffffffffULL) != 0))
1492
- #define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \
1493
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0x7ff8000000000000ULL)
1494
- #define DUK__DBLUNION_IS_ANYINF(u) \
1495
- (((u)->ull[DUK_DBL_IDX_ULL0] & 0x7fffffffffffffffULL) == 0x7ff0000000000000ULL)
1496
- #define DUK__DBLUNION_IS_POSINF(u) \
1497
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0x7ff0000000000000ULL)
1498
- #define DUK__DBLUNION_IS_NEGINF(u) \
1499
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0xfff0000000000000ULL)
1500
- #define DUK__DBLUNION_IS_ANYZERO(u) \
1501
- (((u)->ull[DUK_DBL_IDX_ULL0] & 0x7fffffffffffffffULL) == 0x0000000000000000ULL)
1502
- #define DUK__DBLUNION_IS_POSZERO(u) \
1503
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0x0000000000000000ULL)
1504
- #define DUK__DBLUNION_IS_NEGZERO(u) \
1505
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0x8000000000000000ULL)
1506
- #endif
1507
- #else /* DUK_USE_64BIT_OPS */
1508
- /* Macros for no 64-bit ops, any endianness. */
1509
- #define DUK__DBLUNION_SET_NAN_FULL(u) do { \
1510
- (u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) 0x7ff80000UL; \
1511
- (u)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) 0x00000000UL; \
1512
- } while (0)
1513
- #define DUK__DBLUNION_IS_NAN_FULL(u) \
1514
- ((((u)->ui[DUK_DBL_IDX_UI0] & 0x7ff00000UL) == 0x7ff00000UL) && \
1515
- (((u)->ui[DUK_DBL_IDX_UI0] & 0x000fffffUL) != 0 || \
1516
- (u)->ui[DUK_DBL_IDX_UI1] != 0))
1517
- #define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \
1518
- (((u)->ui[DUK_DBL_IDX_UI0] == 0x7ff80000UL) && \
1519
- ((u)->ui[DUK_DBL_IDX_UI1] == 0x00000000UL))
1520
- #define DUK__DBLUNION_IS_ANYINF(u) \
1521
- ((((u)->ui[DUK_DBL_IDX_UI0] & 0x7fffffffUL) == 0x7ff00000UL) && \
1522
- ((u)->ui[DUK_DBL_IDX_UI1] == 0x00000000UL))
1523
- #define DUK__DBLUNION_IS_POSINF(u) \
1524
- (((u)->ui[DUK_DBL_IDX_UI0] == 0x7ff00000UL) && \
1525
- ((u)->ui[DUK_DBL_IDX_UI1] == 0x00000000UL))
1526
- #define DUK__DBLUNION_IS_NEGINF(u) \
1527
- (((u)->ui[DUK_DBL_IDX_UI0] == 0xfff00000UL) && \
1528
- ((u)->ui[DUK_DBL_IDX_UI1] == 0x00000000UL))
1529
- #define DUK__DBLUNION_IS_ANYZERO(u) \
1530
- ((((u)->ui[DUK_DBL_IDX_UI0] & 0x7fffffffUL) == 0x00000000UL) && \
1531
- ((u)->ui[DUK_DBL_IDX_UI1] == 0x00000000UL))
1532
- #define DUK__DBLUNION_IS_POSZERO(u) \
1533
- (((u)->ui[DUK_DBL_IDX_UI0] == 0x00000000UL) && \
1534
- ((u)->ui[DUK_DBL_IDX_UI1] == 0x00000000UL))
1535
- #define DUK__DBLUNION_IS_NEGZERO(u) \
1536
- (((u)->ui[DUK_DBL_IDX_UI0] == 0x80000000UL) && \
1537
- ((u)->ui[DUK_DBL_IDX_UI1] == 0x00000000UL))
1538
- #endif /* DUK_USE_64BIT_OPS */
1539
-
1540
- #define DUK__DBLUNION_SET_NAN_NOTFULL(u) do { \
1541
- (u)->us[DUK_DBL_IDX_US0] = 0x7ff8UL; \
1542
- } while (0)
1543
-
1544
- #define DUK__DBLUNION_IS_NAN_NOTFULL(u) \
1545
- /* E == 0x7ff, topmost four bits of F != 0 => assume NaN */ \
1546
- ((((u)->us[DUK_DBL_IDX_US0] & 0x7ff0UL) == 0x7ff0UL) && \
1547
- (((u)->us[DUK_DBL_IDX_US0] & 0x000fUL) != 0x0000UL))
1548
-
1549
- #define DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL(u) \
1550
- /* E == 0x7ff, F == 8 => normalized NaN */ \
1551
- ((u)->us[DUK_DBL_IDX_US0] == 0x7ff8UL)
1552
-
1553
- #define DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL(u) do { \
1554
- if (DUK__DBLUNION_IS_NAN_FULL((u))) { \
1555
- DUK__DBLUNION_SET_NAN_FULL((u)); \
1556
- } \
1557
- } while (0)
1558
-
1559
- #define DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL(u) do { \
1560
- if (DUK__DBLUNION_IS_NAN_NOTFULL((u))) { \
1561
- DUK__DBLUNION_SET_NAN_NOTFULL((u)); \
1562
- } \
1563
- } while (0)
1564
-
1565
- /* Concrete macros for NaN handling used by the implementation internals.
1566
- * Chosen so that they match the duk_tval representation: with a packed
1567
- * duk_tval, ensure NaNs are properly normalized; with a non-packed duk_tval
1568
- * these are essentially NOPs.
1569
- */
1570
-
1571
- #if defined(DUK_USE_PACKED_TVAL)
1572
- #if defined(DUK_USE_FULL_TVAL)
1573
- #define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL((u))
1574
- #define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u))
1575
- #define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_FULL((u))
1576
- #define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_FULL((d))
1577
- #else
1578
- #define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL((u))
1579
- #define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_NOTFULL((u))
1580
- #define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL((u))
1581
- #define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_NOTFULL((d))
1582
- #endif
1583
- #define DUK_DBLUNION_IS_NORMALIZED(u) \
1584
- (!DUK_DBLUNION_IS_NAN((u)) || /* either not a NaN */ \
1585
- DUK_DBLUNION_IS_NORMALIZED_NAN((u))) /* or is a normalized NaN */
1586
- #else /* DUK_USE_PACKED_TVAL */
1587
- #define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) /* nop: no need to normalize */
1588
- #define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) /* (DUK_ISNAN((u)->d)) */
1589
- #define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) /* (DUK_ISNAN((u)->d)) */
1590
- #define DUK_DBLUNION_IS_NORMALIZED(u) 1 /* all doubles are considered normalized */
1591
- #define DUK_DBLUNION_SET_NAN(u) do { \
1592
- /* in non-packed representation we don't care about which NaN is used */ \
1593
- (u)->d = DUK_DOUBLE_NAN; \
1594
- } while (0)
1595
- #endif /* DUK_USE_PACKED_TVAL */
1596
-
1597
- #define DUK_DBLUNION_IS_ANYINF(u) DUK__DBLUNION_IS_ANYINF((u))
1598
- #define DUK_DBLUNION_IS_POSINF(u) DUK__DBLUNION_IS_POSINF((u))
1599
- #define DUK_DBLUNION_IS_NEGINF(u) DUK__DBLUNION_IS_NEGINF((u))
1600
-
1601
- #define DUK_DBLUNION_IS_ANYZERO(u) DUK__DBLUNION_IS_ANYZERO((u))
1602
- #define DUK_DBLUNION_IS_POSZERO(u) DUK__DBLUNION_IS_POSZERO((u))
1603
- #define DUK_DBLUNION_IS_NEGZERO(u) DUK__DBLUNION_IS_NEGZERO((u))
1604
-
1605
- /* XXX: native 64-bit byteswaps when available */
1606
-
1607
- /* 64-bit byteswap, same operation independent of target endianness. */
1608
- #define DUK_DBLUNION_BSWAP64(u) do { \
1609
- duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \
1610
- duk__bswaptmp1 = (u)->ui[0]; \
1611
- duk__bswaptmp2 = (u)->ui[1]; \
1612
- duk__bswaptmp1 = DUK_BSWAP32(duk__bswaptmp1); \
1613
- duk__bswaptmp2 = DUK_BSWAP32(duk__bswaptmp2); \
1614
- (u)->ui[0] = duk__bswaptmp2; \
1615
- (u)->ui[1] = duk__bswaptmp1; \
1616
- } while (0)
1617
-
1618
- /* Byteswap an IEEE double in the duk_double_union from host to network
1619
- * order. For a big endian target this is a no-op.
1620
- */
1621
- #if defined(DUK_USE_DOUBLE_LE)
1622
- #define DUK_DBLUNION_DOUBLE_HTON(u) do { \
1623
- duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \
1624
- duk__bswaptmp1 = (u)->ui[0]; \
1625
- duk__bswaptmp2 = (u)->ui[1]; \
1626
- duk__bswaptmp1 = DUK_BSWAP32(duk__bswaptmp1); \
1627
- duk__bswaptmp2 = DUK_BSWAP32(duk__bswaptmp2); \
1628
- (u)->ui[0] = duk__bswaptmp2; \
1629
- (u)->ui[1] = duk__bswaptmp1; \
1630
- } while (0)
1631
- #elif defined(DUK_USE_DOUBLE_ME)
1632
- #define DUK_DBLUNION_DOUBLE_HTON(u) do { \
1633
- duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \
1634
- duk__bswaptmp1 = (u)->ui[0]; \
1635
- duk__bswaptmp2 = (u)->ui[1]; \
1636
- duk__bswaptmp1 = DUK_BSWAP32(duk__bswaptmp1); \
1637
- duk__bswaptmp2 = DUK_BSWAP32(duk__bswaptmp2); \
1638
- (u)->ui[0] = duk__bswaptmp1; \
1639
- (u)->ui[1] = duk__bswaptmp2; \
1640
- } while (0)
1641
- #elif defined(DUK_USE_DOUBLE_BE)
1642
- #define DUK_DBLUNION_DOUBLE_HTON(u) do { } while (0)
1643
- #else
1644
- #error internal error, double endianness insane
1645
- #endif
1646
-
1647
- /* Reverse operation is the same. */
1648
- #define DUK_DBLUNION_DOUBLE_NTOH(u) DUK_DBLUNION_DOUBLE_HTON((u))
1649
-
1650
- /* Some sign bit helpers. */
1651
- #if defined(DUK_USE_64BIT_OPS)
1652
- #define DUK_DBLUNION_HAS_SIGNBIT(u) (((u)->ull[DUK_DBL_IDX_ULL0] & 0x8000000000000000ULL) != 0)
1653
- #define DUK_DBLUNION_GET_SIGNBIT(u) (((u)->ull[DUK_DBL_IDX_ULL0] >> 63U))
1654
- #else
1655
- #define DUK_DBLUNION_HAS_SIGNBIT(u) (((u)->ui[DUK_DBL_IDX_UI0] & 0x80000000UL) != 0)
1656
- #define DUK_DBLUNION_GET_SIGNBIT(u) (((u)->ui[DUK_DBL_IDX_UI0] >> 31U))
1657
- #endif
1658
-
1659
- #endif /* DUK_DBLUNION_H_INCLUDED */
1660
-
1661
1419
  #endif /* DUKTAPE_H_INCLUDED */