comparison extern/duktape/duktape.h @ 425:70b0c9e40131

Irccd: import Duktape 2.0.1, closes #636
author David Demelier <markand@malikania.fr>
date Thu, 09 Feb 2017 18:44:22 +0100
parents c26b75fb97e3
children 3b63f8b1c224
comparison
equal deleted inserted replaced
424:cd3f7c712d9e 425:70b0c9e40131
1 /* 1 /*
2 * Duktape public API for Duktape 1.5.1. 2 * Duktape public API for Duktape 2.0.1.
3 * 3 *
4 * See the API reference for documentation on call semantics. 4 * See the API reference for documentation on call semantics.
5 * The exposed API is inside the DUK_API_PUBLIC_H_INCLUDED 5 * The exposed API is inside the DUK_API_PUBLIC_H_INCLUDED
6 * include guard. Other parts of the header are Duktape 6 * include guard. Other parts of the header are Duktape
7 * internal and related to platform/compiler/feature detection. 7 * internal and related to platform/compiler/feature detection.
8 * 8 *
9 * Git commit 2cc76e9ff1f64869e1146ad7317d8cbe33bbd27e (v1.5.1). 9 * Git commit 3f5e91704aff97c754f6ef5d44aedc5e529d1b16 (v2.0.1).
10 * Git branch HEAD. 10 * Git branch v2.0-maintenance.
11 * 11 *
12 * See Duktape AUTHORS.rst and LICENSE.txt for copyright and 12 * See Duktape AUTHORS.rst and LICENSE.txt for copyright and
13 * licensing information. 13 * licensing information.
14 */ 14 */
15 15
19 * Duktape license 19 * Duktape license
20 * =============== 20 * ===============
21 * 21 *
22 * (http://opensource.org/licenses/MIT) 22 * (http://opensource.org/licenses/MIT)
23 * 23 *
24 * Copyright (c) 2013-2016 by Duktape authors (see AUTHORS.rst) 24 * Copyright (c) 2013-2017 by Duktape authors (see AUTHORS.rst)
25 * 25 *
26 * Permission is hereby granted, free of charge, to any person obtaining a copy 26 * Permission is hereby granted, free of charge, to any person obtaining a copy
27 * of this software and associated documentation files (the "Software"), to deal 27 * of this software and associated documentation files (the "Software"), to deal
28 * in the Software without restriction, including without limitation the rights 28 * in the Software without restriction, including without limitation the rights
29 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 29 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
73 * * Karl Skomski <karl@skomski.com> 73 * * Karl Skomski <karl@skomski.com>
74 * * Bruce Pascoe <fatcerberus1@gmail.com> 74 * * Bruce Pascoe <fatcerberus1@gmail.com>
75 * * Ren\u00e9 Hollander <rene@rene8888.at> 75 * * Ren\u00e9 Hollander <rene@rene8888.at>
76 * * Julien Hamaide (https://github.com/crazyjul) 76 * * Julien Hamaide (https://github.com/crazyjul)
77 * * Sebastian G\u00f6tte (https://github.com/jaseg) 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)
78 * 90 *
79 * Other contributions 91 * Other contributions
80 * =================== 92 * ===================
81 * 93 *
82 * The following people have contributed something other than code (e.g. reported 94 * The following people have contributed something other than code (e.g. reported
110 * * https://github.com/Kelledin 122 * * https://github.com/Kelledin
111 * * https://github.com/sstruchtrup 123 * * https://github.com/sstruchtrup
112 * * Michael Drake (https://github.com/tlsa) 124 * * Michael Drake (https://github.com/tlsa)
113 * * https://github.com/chris-y 125 * * https://github.com/chris-y
114 * * Laurent Zubiaur (https://github.com/lzubiaur) 126 * * Laurent Zubiaur (https://github.com/lzubiaur)
115 * * Ole Andr\u00e9 Vadla Ravn\u00e5s (https://github.com/oleavr) 127 * * Neil Kolban (https://github.com/nkolban)
116 * 128 *
117 * If you are accidentally missing from this list, send me an e-mail 129 * If you are accidentally missing from this list, send me an e-mail
118 * (``sami.vaarala@iki.fi``) and I'll fix the omission. 130 * (``sami.vaarala@iki.fi``) and I'll fix the omission.
119 */ 131 */
120 132
121 #ifndef DUKTAPE_H_INCLUDED 133 #if !defined(DUKTAPE_H_INCLUDED)
122 #define DUKTAPE_H_INCLUDED 134 #define DUKTAPE_H_INCLUDED
123 135
124 #define DUK_SINGLE_FILE 136 #define DUK_SINGLE_FILE
125 137
126 /* External duk_config.h provides platform/compiler/OS dependent 138 /* External duk_config.h provides platform/compiler/OS dependent
131 143
132 /* 144 /*
133 * BEGIN PUBLIC API 145 * BEGIN PUBLIC API
134 */ 146 */
135 147
136 #ifndef DUK_API_PUBLIC_H_INCLUDED 148 #if !defined(DUK_API_PUBLIC_H_INCLUDED)
137 #define DUK_API_PUBLIC_H_INCLUDED 149 #define DUK_API_PUBLIC_H_INCLUDED
138 150
139 /* 151 /*
140 * Avoid C++ name mangling 152 * Avoid C++ name mangling
141 */ 153 */
142 154
143 #ifdef __cplusplus 155 #if defined(__cplusplus)
144 extern "C" { 156 extern "C" {
145 #endif 157 #endif
146 158
147 /* 159 /*
148 * Some defines forwarded from feature detection 160 * Some defines forwarded from feature detection
149 */ 161 */
150 162
151 #undef DUK_API_VARIADIC_MACROS 163 #undef DUK_API_VARIADIC_MACROS
152 #ifdef DUK_USE_VARIADIC_MACROS 164 #if defined(DUK_USE_VARIADIC_MACROS)
153 #define DUK_API_VARIADIC_MACROS 165 #define DUK_API_VARIADIC_MACROS
154 #endif 166 #endif
155 167
156 #define DUK_API_NORETURN(decl) DUK_NORETURN(decl) 168 #define DUK_API_NORETURN(decl) DUK_NORETURN(decl)
157 169
161 * Many types are wrapped by Duktape for portability to rare platforms 173 * Many types are wrapped by Duktape for portability to rare platforms
162 * where e.g. 'int' is a 16-bit type. See practical typing discussion 174 * where e.g. 'int' is a 16-bit type. See practical typing discussion
163 * in Duktape web documentation. 175 * in Duktape web documentation.
164 */ 176 */
165 177
178 struct duk_thread_state;
166 struct duk_memory_functions; 179 struct duk_memory_functions;
167 struct duk_function_list_entry; 180 struct duk_function_list_entry;
168 struct duk_number_list_entry; 181 struct duk_number_list_entry;
182 struct duk_time_components;
169 183
170 /* duk_context is now defined in duk_config.h because it may also be 184 /* duk_context is now defined in duk_config.h because it may also be
171 * referenced there by prototypes. 185 * referenced there by prototypes.
172 */ 186 */
187 typedef struct duk_thread_state duk_thread_state;
173 typedef struct duk_memory_functions duk_memory_functions; 188 typedef struct duk_memory_functions duk_memory_functions;
174 typedef struct duk_function_list_entry duk_function_list_entry; 189 typedef struct duk_function_list_entry duk_function_list_entry;
175 typedef struct duk_number_list_entry duk_number_list_entry; 190 typedef struct duk_number_list_entry duk_number_list_entry;
191 typedef struct duk_time_components duk_time_components;
176 192
177 typedef duk_ret_t (*duk_c_function)(duk_context *ctx); 193 typedef duk_ret_t (*duk_c_function)(duk_context *ctx);
178 typedef void *(*duk_alloc_function) (void *udata, duk_size_t size); 194 typedef void *(*duk_alloc_function) (void *udata, duk_size_t size);
179 typedef void *(*duk_realloc_function) (void *udata, void *ptr, duk_size_t size); 195 typedef void *(*duk_realloc_function) (void *udata, void *ptr, duk_size_t size);
180 typedef void (*duk_free_function) (void *udata, void *ptr); 196 typedef void (*duk_free_function) (void *udata, void *ptr);
181 typedef void (*duk_fatal_function) (duk_context *ctx, duk_errcode_t code, const char *msg); 197 typedef void (*duk_fatal_function) (void *udata, const char *msg);
182 typedef void (*duk_decode_char_function) (void *udata, duk_codepoint_t codepoint); 198 typedef void (*duk_decode_char_function) (void *udata, duk_codepoint_t codepoint);
183 typedef duk_codepoint_t (*duk_map_char_function) (void *udata, duk_codepoint_t codepoint); 199 typedef duk_codepoint_t (*duk_map_char_function) (void *udata, duk_codepoint_t codepoint);
184 typedef duk_ret_t (*duk_safe_call_function) (duk_context *ctx); 200 typedef duk_ret_t (*duk_safe_call_function) (duk_context *ctx, void *udata);
185 typedef duk_size_t (*duk_debug_read_function) (void *udata, char *buffer, duk_size_t length); 201 typedef duk_size_t (*duk_debug_read_function) (void *udata, char *buffer, duk_size_t length);
186 typedef duk_size_t (*duk_debug_write_function) (void *udata, const char *buffer, duk_size_t length); 202 typedef duk_size_t (*duk_debug_write_function) (void *udata, const char *buffer, duk_size_t length);
187 typedef duk_size_t (*duk_debug_peek_function) (void *udata); 203 typedef duk_size_t (*duk_debug_peek_function) (void *udata);
188 typedef void (*duk_debug_read_flush_function) (void *udata); 204 typedef void (*duk_debug_read_flush_function) (void *udata);
189 typedef void (*duk_debug_write_flush_function) (void *udata); 205 typedef void (*duk_debug_write_flush_function) (void *udata);
190 typedef duk_idx_t (*duk_debug_request_function) (duk_context *ctx, void *udata, duk_idx_t nvalues); 206 typedef duk_idx_t (*duk_debug_request_function) (duk_context *ctx, void *udata, duk_idx_t nvalues);
191 typedef void (*duk_debug_detached_function) (void *udata); 207 typedef void (*duk_debug_detached_function) (duk_context *ctx, void *udata);
208
209 struct duk_thread_state {
210 /* XXX: Enough space to hold internal suspend/resume structure.
211 * This is rather awkward and to be fixed when the internal
212 * structure is visible for the public API header.
213 */
214 char data[128];
215 };
192 216
193 struct duk_memory_functions { 217 struct duk_memory_functions {
194 duk_alloc_function alloc_func; 218 duk_alloc_function alloc_func;
195 duk_realloc_function realloc_func; 219 duk_realloc_function realloc_func;
196 duk_free_function free_func; 220 duk_free_function free_func;
206 struct duk_number_list_entry { 230 struct duk_number_list_entry {
207 const char *key; 231 const char *key;
208 duk_double_t value; 232 duk_double_t value;
209 }; 233 };
210 234
235 struct duk_time_components {
236 duk_double_t year; /* year, e.g. 2016, Ecmascript year range */
237 duk_double_t month; /* month: 1-12 */
238 duk_double_t day; /* day: 1-31 */
239 duk_double_t hours; /* hour: 0-59 */
240 duk_double_t minutes; /* minute: 0-59 */
241 duk_double_t seconds; /* second: 0-59 (in POSIX time no leap second) */
242 duk_double_t milliseconds; /* may contain sub-millisecond fractions */
243 duk_double_t weekday; /* weekday: 0-6, 0=Sunday, 1=Monday, ..., 6=Saturday */
244 };
245
211 /* 246 /*
212 * Constants 247 * Constants
213 */ 248 */
214 249
215 /* Duktape version, (major * 10000) + (minor * 100) + patch. Allows C code 250 /* Duktape version, (major * 10000) + (minor * 100) + patch. Allows C code
216 * to #ifdef against Duktape API version. The same value is also available 251 * to #if (DUK_VERSION >= NNN) against Duktape API version. The same value
217 * to Ecmascript code in Duktape.version. Unofficial development snapshots 252 * is also available to Ecmascript code in Duktape.version. Unofficial
218 * have 99 for patch level (e.g. 0.10.99 would be a development version 253 * development snapshots have 99 for patch level (e.g. 0.10.99 would be a
219 * after 0.10.0 but before the next official release). 254 * development version after 0.10.0 but before the next official release).
220 */ 255 */
221 #define DUK_VERSION 10501L 256 #define DUK_VERSION 20001L
222 257
223 /* Git commit, describe, and branch for Duktape build. Useful for 258 /* Git commit, describe, and branch for Duktape build. Useful for
224 * non-official snapshot builds so that application code can easily log 259 * non-official snapshot builds so that application code can easily log
225 * which Duktape snapshot was used. Not available in the Ecmascript 260 * which Duktape snapshot was used. Not available in the Ecmascript
226 * environment. 261 * environment.
227 */ 262 */
228 #define DUK_GIT_COMMIT "2cc76e9ff1f64869e1146ad7317d8cbe33bbd27e" 263 #define DUK_GIT_COMMIT "3f5e91704aff97c754f6ef5d44aedc5e529d1b16"
229 #define DUK_GIT_DESCRIBE "v1.5.1" 264 #define DUK_GIT_DESCRIBE "v2.0.1"
230 #define DUK_GIT_BRANCH "HEAD" 265 #define DUK_GIT_BRANCH "v2.0-maintenance"
231 266
232 /* Duktape debug protocol version used by this build. */ 267 /* Duktape debug protocol version used by this build. */
233 #define DUK_DEBUG_PROTOCOL_VERSION 1 268 #define DUK_DEBUG_PROTOCOL_VERSION 2
234 269
235 /* Used to represent invalid index; if caller uses this without checking, 270 /* Used to represent invalid index; if caller uses this without checking,
236 * this index will map to a non-existent stack entry. Also used in some 271 * this index will map to a non-existent stack entry. Also used in some
237 * API calls as a marker to denote "no value". 272 * API calls as a marker to denote "no value".
238 */ 273 */
272 #define DUK_TYPE_MASK_OBJECT (1 << DUK_TYPE_OBJECT) 307 #define DUK_TYPE_MASK_OBJECT (1 << DUK_TYPE_OBJECT)
273 #define DUK_TYPE_MASK_BUFFER (1 << DUK_TYPE_BUFFER) 308 #define DUK_TYPE_MASK_BUFFER (1 << DUK_TYPE_BUFFER)
274 #define DUK_TYPE_MASK_POINTER (1 << DUK_TYPE_POINTER) 309 #define DUK_TYPE_MASK_POINTER (1 << DUK_TYPE_POINTER)
275 #define DUK_TYPE_MASK_LIGHTFUNC (1 << DUK_TYPE_LIGHTFUNC) 310 #define DUK_TYPE_MASK_LIGHTFUNC (1 << DUK_TYPE_LIGHTFUNC)
276 #define DUK_TYPE_MASK_THROW (1 << 10) /* internal flag value: throw if mask doesn't match */ 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 */
277 313
278 /* Coercion hints */ 314 /* Coercion hints */
279 #define DUK_HINT_NONE 0 /* prefer number, unless input is a Date, in which 315 #define DUK_HINT_NONE 0 /* prefer number, unless input is a Date, in which
280 * case prefer string (E5 Section 8.12.8) 316 * case prefer string (E5 Section 8.12.8)
281 */ 317 */
282 #define DUK_HINT_STRING 1 /* prefer string */ 318 #define DUK_HINT_STRING 1 /* prefer string */
283 #define DUK_HINT_NUMBER 2 /* prefer number */ 319 #define DUK_HINT_NUMBER 2 /* prefer number */
284 320
285 /* Enumeration flags for duk_enum() */ 321 /* Enumeration flags for duk_enum() */
286 #define DUK_ENUM_INCLUDE_NONENUMERABLE (1 << 0) /* enumerate non-numerable properties in addition to enumerable */ 322 #define DUK_ENUM_INCLUDE_NONENUMERABLE (1 << 0) /* enumerate non-numerable properties in addition to enumerable */
287 #define DUK_ENUM_INCLUDE_INTERNAL (1 << 1) /* enumerate internal properties (regardless of enumerability) */ 323 #define DUK_ENUM_INCLUDE_HIDDEN (1 << 1) /* enumerate hidden symbols too (in Duktape 1.x called internal properties) */
288 #define DUK_ENUM_OWN_PROPERTIES_ONLY (1 << 2) /* don't walk prototype chain, only check own properties */ 324 #define DUK_ENUM_INCLUDE_SYMBOLS (1 << 2) /* enumerate symbols */
289 #define DUK_ENUM_ARRAY_INDICES_ONLY (1 << 3) /* only enumerate array indices */ 325 #define DUK_ENUM_EXCLUDE_STRINGS (1 << 3) /* exclude strings */
290 #define DUK_ENUM_SORT_ARRAY_INDICES (1 << 4) /* sort array indices, use with DUK_ENUM_ARRAY_INDICES_ONLY */ 326 #define DUK_ENUM_OWN_PROPERTIES_ONLY (1 << 4) /* don't walk prototype chain, only check own properties */
291 #define DUK_ENUM_NO_PROXY_BEHAVIOR (1 << 5) /* enumerate a proxy object itself without invoking proxy behavior */ 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 */
292 330
293 /* Compilation flags for duk_compile() and duk_eval() */ 331 /* Compilation flags for duk_compile() and duk_eval() */
294 /* DUK_COMPILE_xxx bits 0-2 are reserved for an internal 'nargs' argument 332 /* DUK_COMPILE_xxx bits 0-2 are reserved for an internal 'nargs' argument.
295 * (the nargs value passed is direct stack arguments + 1 to account for an
296 * internal extra argument).
297 */ 333 */
298 #define DUK_COMPILE_EVAL (1 << 3) /* compile eval code (instead of global code) */ 334 #define DUK_COMPILE_EVAL (1 << 3) /* compile eval code (instead of global code) */
299 #define DUK_COMPILE_FUNCTION (1 << 4) /* compile function code (instead of global code) */ 335 #define DUK_COMPILE_FUNCTION (1 << 4) /* compile function code (instead of global code) */
300 #define DUK_COMPILE_STRICT (1 << 5) /* use strict (outer) context for global, eval, or function code */ 336 #define DUK_COMPILE_STRICT (1 << 5) /* use strict (outer) context for global, eval, or function code */
301 #define DUK_COMPILE_SAFE (1 << 6) /* (internal) catch compilation errors */ 337 #define DUK_COMPILE_SAFE (1 << 6) /* (internal) catch compilation errors */
323 #define DUK_DEFPROP_CLEAR_CONFIGURABLE DUK_DEFPROP_HAVE_CONFIGURABLE 359 #define DUK_DEFPROP_CLEAR_CONFIGURABLE DUK_DEFPROP_HAVE_CONFIGURABLE
324 360
325 /* Flags for duk_push_thread_raw() */ 361 /* Flags for duk_push_thread_raw() */
326 #define DUK_THREAD_NEW_GLOBAL_ENV (1 << 0) /* create a new global environment */ 362 #define DUK_THREAD_NEW_GLOBAL_ENV (1 << 0) /* create a new global environment */
327 363
328 /* Flags for duk_push_string_file_raw() */ 364 /* Flags for duk_gc() */
329 #define DUK_STRING_PUSH_SAFE (1 << 0) /* no error if file does not exist */ 365 #define DUK_GC_COMPACT (1 << 0) /* compact heap objects */
330 366
331 /* Duktape specific error codes (must be 8 bits at most, see duk_error.h) */ 367 /* Error codes (must be 8 bits at most, see duk_error.h) */
332 #define DUK_ERR_NONE 0 /* no error (e.g. from duk_get_error_code()) */ 368 #define DUK_ERR_NONE 0 /* no error (e.g. from duk_get_error_code()) */
333 #define DUK_ERR_UNIMPLEMENTED_ERROR 50 /* UnimplementedError */ /* XXX: replace with TypeError? */ 369 #define DUK_ERR_ERROR 1 /* Error */
334 #define DUK_ERR_UNSUPPORTED_ERROR 51 /* UnsupportedError */ /* XXX: replace with TypeError? */ 370 #define DUK_ERR_EVAL_ERROR 2 /* EvalError */
335 #define DUK_ERR_INTERNAL_ERROR 52 /* InternalError */ /* XXX: replace with plain Error? */ 371 #define DUK_ERR_RANGE_ERROR 3 /* RangeError */
336 #define DUK_ERR_ALLOC_ERROR 53 /* AllocError */ /* XXX: replace with RangeError? */ 372 #define DUK_ERR_REFERENCE_ERROR 4 /* ReferenceError */
337 #define DUK_ERR_ASSERTION_ERROR 54 /* AssertionError */ /* XXX: to be removed? */ 373 #define DUK_ERR_SYNTAX_ERROR 5 /* SyntaxError */
338 #define DUK_ERR_API_ERROR 55 /* APIError */ /* XXX: replace with TypeError? */ 374 #define DUK_ERR_TYPE_ERROR 6 /* TypeError */
339 #define DUK_ERR_UNCAUGHT_ERROR 56 /* UncaughtError */ /* XXX: to be removed? */ 375 #define DUK_ERR_URI_ERROR 7 /* URIError */
340
341 /* Ecmascript E5 specification error codes */
342 #define DUK_ERR_ERROR 100 /* Error */
343 #define DUK_ERR_EVAL_ERROR 101 /* EvalError */
344 #define DUK_ERR_RANGE_ERROR 102 /* RangeError */
345 #define DUK_ERR_REFERENCE_ERROR 103 /* ReferenceError */
346 #define DUK_ERR_SYNTAX_ERROR 104 /* SyntaxError */
347 #define DUK_ERR_TYPE_ERROR 105 /* TypeError */
348 #define DUK_ERR_URI_ERROR 106 /* URIError */
349 376
350 /* Return codes for C functions (shortcut for throwing an error) */ 377 /* Return codes for C functions (shortcut for throwing an error) */
351 #define DUK_RET_UNIMPLEMENTED_ERROR (-DUK_ERR_UNIMPLEMENTED_ERROR)
352 #define DUK_RET_UNSUPPORTED_ERROR (-DUK_ERR_UNSUPPORTED_ERROR)
353 #define DUK_RET_INTERNAL_ERROR (-DUK_ERR_INTERNAL_ERROR)
354 #define DUK_RET_ALLOC_ERROR (-DUK_ERR_ALLOC_ERROR)
355 #define DUK_RET_ASSERTION_ERROR (-DUK_ERR_ASSERTION_ERROR)
356 #define DUK_RET_API_ERROR (-DUK_ERR_API_ERROR)
357 #define DUK_RET_UNCAUGHT_ERROR (-DUK_ERR_UNCAUGHT_ERROR)
358 #define DUK_RET_ERROR (-DUK_ERR_ERROR) 378 #define DUK_RET_ERROR (-DUK_ERR_ERROR)
359 #define DUK_RET_EVAL_ERROR (-DUK_ERR_EVAL_ERROR) 379 #define DUK_RET_EVAL_ERROR (-DUK_ERR_EVAL_ERROR)
360 #define DUK_RET_RANGE_ERROR (-DUK_ERR_RANGE_ERROR) 380 #define DUK_RET_RANGE_ERROR (-DUK_ERR_RANGE_ERROR)
361 #define DUK_RET_REFERENCE_ERROR (-DUK_ERR_REFERENCE_ERROR) 381 #define DUK_RET_REFERENCE_ERROR (-DUK_ERR_REFERENCE_ERROR)
362 #define DUK_RET_SYNTAX_ERROR (-DUK_ERR_SYNTAX_ERROR) 382 #define DUK_RET_SYNTAX_ERROR (-DUK_ERR_SYNTAX_ERROR)
365 385
366 /* Return codes for protected calls (duk_safe_call(), duk_pcall()) */ 386 /* Return codes for protected calls (duk_safe_call(), duk_pcall()) */
367 #define DUK_EXEC_SUCCESS 0 387 #define DUK_EXEC_SUCCESS 0
368 #define DUK_EXEC_ERROR 1 388 #define DUK_EXEC_ERROR 1
369 389
370 /* Log levels */ 390 /* Debug levels for DUK_USE_DEBUG_WRITE(). */
371 #define DUK_LOG_TRACE 0 391 #define DUK_LEVEL_DEBUG 0
372 #define DUK_LOG_DEBUG 1 392 #define DUK_LEVEL_DDEBUG 1
373 #define DUK_LOG_INFO 2 393 #define DUK_LEVEL_DDDEBUG 2
374 #define DUK_LOG_WARN 3
375 #define DUK_LOG_ERROR 4
376 #define DUK_LOG_FATAL 5
377 394
378 /* 395 /*
379 * If no variadic macros, __FILE__ and __LINE__ are passed through globals 396 * If no variadic macros, __FILE__ and __LINE__ are passed through globals
380 * which is ugly and not thread safe. 397 * which is ugly and not thread safe.
381 */ 398 */
382 399
383 #ifndef DUK_API_VARIADIC_MACROS 400 #if !defined(DUK_API_VARIADIC_MACROS)
384 DUK_EXTERNAL_DECL const char *duk_api_global_filename; 401 DUK_EXTERNAL_DECL const char *duk_api_global_filename;
385 DUK_EXTERNAL_DECL duk_int_t duk_api_global_line; 402 DUK_EXTERNAL_DECL duk_int_t duk_api_global_line;
386 #endif 403 #endif
387 404
388 /* 405 /*
394 duk_realloc_function realloc_func, 411 duk_realloc_function realloc_func,
395 duk_free_function free_func, 412 duk_free_function free_func,
396 void *heap_udata, 413 void *heap_udata,
397 duk_fatal_function fatal_handler); 414 duk_fatal_function fatal_handler);
398 DUK_EXTERNAL_DECL void duk_destroy_heap(duk_context *ctx); 415 DUK_EXTERNAL_DECL void duk_destroy_heap(duk_context *ctx);
416
417 DUK_EXTERNAL_DECL void duk_suspend(duk_context *ctx, duk_thread_state *state);
418 DUK_EXTERNAL_DECL void duk_resume(duk_context *ctx, const duk_thread_state *state);
399 419
400 #define duk_create_heap_default() \ 420 #define duk_create_heap_default() \
401 duk_create_heap(NULL, NULL, NULL, NULL, NULL) 421 duk_create_heap(NULL, NULL, NULL, NULL, NULL)
402 422
403 /* 423 /*
417 437
418 /* 438 /*
419 * Error handling 439 * Error handling
420 */ 440 */
421 441
422 DUK_API_NORETURN(DUK_EXTERNAL_DECL void duk_throw(duk_context *ctx)); 442 DUK_API_NORETURN(DUK_EXTERNAL_DECL void duk_throw_raw(duk_context *ctx));
423 DUK_API_NORETURN(DUK_EXTERNAL_DECL void duk_fatal(duk_context *ctx, duk_errcode_t err_code, const char *err_msg)); 443 #define duk_throw(ctx) \
424 444 (duk_throw_raw((ctx)), (duk_ret_t) 0)
445 DUK_API_NORETURN(DUK_EXTERNAL_DECL void duk_fatal_raw(duk_context *ctx, const char *err_msg));
446 #define duk_fatal(ctx,err_msg) \
447 (duk_fatal_raw((ctx), (err_msg)), (duk_ret_t) 0)
448
449 #if defined(DUK_API_VARIADIC_MACROS)
425 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, ...)); 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, ...));
426
427 #ifdef DUK_API_VARIADIC_MACROS
428 #define duk_error(ctx,err_code,...) \ 451 #define duk_error(ctx,err_code,...) \
429 duk_error_raw((ctx), (duk_errcode_t) (err_code), (const char *) (DUK_FILE_MACRO), (duk_int_t) (DUK_LINE_MACRO), __VA_ARGS__) 452 (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)
430 #else 453 #define duk_generic_error(ctx,...) \
431 DUK_API_NORETURN(DUK_EXTERNAL_DECL void duk_error_stash(duk_context *ctx, duk_errcode_t err_code, const char *fmt, ...)); 454 (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)
432 /* One problem with this macro is that expressions like the following fail 455 #define duk_eval_error(ctx,...) \
433 * to compile: "(void) duk_error(...)". But because duk_error() is noreturn, 456 (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)
434 * they make little sense anyway. 457 #define duk_range_error(ctx,...) \
435 */ 458 (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)
459 #define duk_reference_error(ctx,...) \
460 (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)
461 #define duk_syntax_error(ctx,...) \
462 (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)
463 #define duk_type_error(ctx,...) \
464 (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)
465 #define duk_uri_error(ctx,...) \
466 (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)
467 #else /* DUK_API_VARIADIC_MACROS */
468 /* For legacy compilers without variadic macros a macro hack is used to allow
469 * variable arguments. While the macro allows "return duk_error(...)", it
470 * will fail with e.g. "(void) duk_error(...)". The calls are noreturn but
471 * with a return value to allow the "return duk_error(...)" idiom. This may
472 * cause some compiler warnings, but without noreturn the generated code is
473 * often worse. The same approach as with variadic macros (using
474 * "(duk_error(...), 0)") won't work due to the macro hack structure.
475 */
476 DUK_API_NORETURN(DUK_EXTERNAL_DECL duk_ret_t duk_error_stash(duk_context *ctx, duk_errcode_t err_code, const char *fmt, ...));
477 DUK_API_NORETURN(DUK_EXTERNAL_DECL duk_ret_t duk_generic_error_stash(duk_context *ctx, const char *fmt, ...));
478 DUK_API_NORETURN(DUK_EXTERNAL_DECL duk_ret_t duk_eval_error_stash(duk_context *ctx, const char *fmt, ...));
479 DUK_API_NORETURN(DUK_EXTERNAL_DECL duk_ret_t duk_range_error_stash(duk_context *ctx, const char *fmt, ...));
480 DUK_API_NORETURN(DUK_EXTERNAL_DECL duk_ret_t duk_reference_error_stash(duk_context *ctx, const char *fmt, ...));
481 DUK_API_NORETURN(DUK_EXTERNAL_DECL duk_ret_t duk_syntax_error_stash(duk_context *ctx, const char *fmt, ...));
482 DUK_API_NORETURN(DUK_EXTERNAL_DECL duk_ret_t duk_type_error_stash(duk_context *ctx, const char *fmt, ...));
483 DUK_API_NORETURN(DUK_EXTERNAL_DECL duk_ret_t duk_uri_error_stash(duk_context *ctx, const char *fmt, ...));
436 #define duk_error \ 484 #define duk_error \
437 (duk_api_global_filename = (const char *) (DUK_FILE_MACRO), \ 485 (duk_api_global_filename = (const char *) (DUK_FILE_MACRO), \
438 duk_api_global_line = (duk_int_t) (DUK_LINE_MACRO), \ 486 duk_api_global_line = (duk_int_t) (DUK_LINE_MACRO), \
439 duk_error_stash) /* last value is func pointer, arguments follow in parens */ 487 duk_error_stash) /* last value is func pointer, arguments follow in parens */
440 #endif 488 #define duk_generic_error \
489 (duk_api_global_filename = (const char *) (DUK_FILE_MACRO), \
490 duk_api_global_line = (duk_int_t) (DUK_LINE_MACRO), \
491 duk_generic_error_stash)
492 #define duk_eval_error \
493 (duk_api_global_filename = (const char *) (DUK_FILE_MACRO), \
494 duk_api_global_line = (duk_int_t) (DUK_LINE_MACRO), \
495 duk_eval_error_stash)
496 #define duk_range_error \
497 (duk_api_global_filename = (const char *) (DUK_FILE_MACRO), \
498 duk_api_global_line = (duk_int_t) (DUK_LINE_MACRO), \
499 duk_range_error_stash)
500 #define duk_reference_error \
501 (duk_api_global_filename = (const char *) (DUK_FILE_MACRO), \
502 duk_api_global_line = (duk_int_t) (DUK_LINE_MACRO), \
503 duk_reference_error_stash)
504 #define duk_syntax_error \
505 (duk_api_global_filename = (const char *) (DUK_FILE_MACRO), \
506 duk_api_global_line = (duk_int_t) (DUK_LINE_MACRO), \
507 duk_syntax_error_stash)
508 #define duk_type_error \
509 (duk_api_global_filename = (const char *) (DUK_FILE_MACRO), \
510 duk_api_global_line = (duk_int_t) (DUK_LINE_MACRO), \
511 duk_type_error_stash)
512 #define duk_uri_error \
513 (duk_api_global_filename = (const char *) (DUK_FILE_MACRO), \
514 duk_api_global_line = (duk_int_t) (DUK_LINE_MACRO), \
515 duk_uri_error_stash)
516 #endif /* DUK_API_VARIADIC_MACROS */
441 517
442 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)); 518 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));
443 #define duk_error_va(ctx,err_code,fmt,ap) \ 519 #define duk_error_va(ctx,err_code,fmt,ap) \
444 duk_error_va_raw((ctx), (duk_errcode_t) (err_code), (const char *) (DUK_FILE_MACRO), (duk_int_t) (DUK_LINE_MACRO), (fmt), (ap)) 520 (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 #define duk_generic_error_va(ctx,fmt,ap) \
522 (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)
523 #define duk_eval_error_va(ctx,fmt,ap) \
524 (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)
525 #define duk_range_error_va(ctx,fmt,ap) \
526 (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)
527 #define duk_reference_error_va(ctx,fmt,ap) \
528 (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)
529 #define duk_syntax_error_va(ctx,fmt,ap) \
530 (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)
531 #define duk_type_error_va(ctx,fmt,ap) \
532 (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)
533 #define duk_uri_error_va(ctx,fmt,ap) \
534 (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)
445 535
446 /* 536 /*
447 * Other state related functions 537 * Other state related functions
448 */ 538 */
449 539
452 542
453 /* 543 /*
454 * Stack management 544 * Stack management
455 */ 545 */
456 546
457 DUK_EXTERNAL_DECL duk_idx_t duk_normalize_index(duk_context *ctx, duk_idx_t index); 547 DUK_EXTERNAL_DECL duk_idx_t duk_normalize_index(duk_context *ctx, duk_idx_t idx);
458 DUK_EXTERNAL_DECL duk_idx_t duk_require_normalize_index(duk_context *ctx, duk_idx_t index); 548 DUK_EXTERNAL_DECL duk_idx_t duk_require_normalize_index(duk_context *ctx, duk_idx_t idx);
459 DUK_EXTERNAL_DECL duk_bool_t duk_is_valid_index(duk_context *ctx, duk_idx_t index); 549 DUK_EXTERNAL_DECL duk_bool_t duk_is_valid_index(duk_context *ctx, duk_idx_t idx);
460 DUK_EXTERNAL_DECL void duk_require_valid_index(duk_context *ctx, duk_idx_t index); 550 DUK_EXTERNAL_DECL void duk_require_valid_index(duk_context *ctx, duk_idx_t idx);
461 551
462 DUK_EXTERNAL_DECL duk_idx_t duk_get_top(duk_context *ctx); 552 DUK_EXTERNAL_DECL duk_idx_t duk_get_top(duk_context *ctx);
463 DUK_EXTERNAL_DECL void duk_set_top(duk_context *ctx, duk_idx_t index); 553 DUK_EXTERNAL_DECL void duk_set_top(duk_context *ctx, duk_idx_t idx);
464 DUK_EXTERNAL_DECL duk_idx_t duk_get_top_index(duk_context *ctx); 554 DUK_EXTERNAL_DECL duk_idx_t duk_get_top_index(duk_context *ctx);
465 DUK_EXTERNAL_DECL duk_idx_t duk_require_top_index(duk_context *ctx); 555 DUK_EXTERNAL_DECL duk_idx_t duk_require_top_index(duk_context *ctx);
466 556
467 /* Although extra/top could be an unsigned type here, using a signed type 557 /* Although extra/top could be an unsigned type here, using a signed type
468 * makes the API more robust to calling code calculation errors or corner 558 * makes the API more robust to calling code calculation errors or corner
478 568
479 /* 569 /*
480 * Stack manipulation (other than push/pop) 570 * Stack manipulation (other than push/pop)
481 */ 571 */
482 572
483 DUK_EXTERNAL_DECL void duk_swap(duk_context *ctx, duk_idx_t index1, duk_idx_t index2); 573 DUK_EXTERNAL_DECL void duk_swap(duk_context *ctx, duk_idx_t idx1, duk_idx_t idx2);
484 DUK_EXTERNAL_DECL void duk_swap_top(duk_context *ctx, duk_idx_t index); 574 DUK_EXTERNAL_DECL void duk_swap_top(duk_context *ctx, duk_idx_t idx);
485 DUK_EXTERNAL_DECL void duk_dup(duk_context *ctx, duk_idx_t from_index); 575 DUK_EXTERNAL_DECL void duk_dup(duk_context *ctx, duk_idx_t from_idx);
486 DUK_EXTERNAL_DECL void duk_dup_top(duk_context *ctx); 576 DUK_EXTERNAL_DECL void duk_dup_top(duk_context *ctx);
487 DUK_EXTERNAL_DECL void duk_insert(duk_context *ctx, duk_idx_t to_index); 577 DUK_EXTERNAL_DECL void duk_insert(duk_context *ctx, duk_idx_t to_idx);
488 DUK_EXTERNAL_DECL void duk_replace(duk_context *ctx, duk_idx_t to_index); 578 DUK_EXTERNAL_DECL void duk_replace(duk_context *ctx, duk_idx_t to_idx);
489 DUK_EXTERNAL_DECL void duk_copy(duk_context *ctx, duk_idx_t from_index, duk_idx_t to_index); 579 DUK_EXTERNAL_DECL void duk_copy(duk_context *ctx, duk_idx_t from_idx, duk_idx_t to_idx);
490 DUK_EXTERNAL_DECL void duk_remove(duk_context *ctx, duk_idx_t index); 580 DUK_EXTERNAL_DECL void duk_remove(duk_context *ctx, duk_idx_t idx);
491 DUK_EXTERNAL_DECL void duk_xcopymove_raw(duk_context *to_ctx, duk_context *from_ctx, duk_idx_t count, duk_bool_t is_copy); 581 DUK_EXTERNAL_DECL void duk_xcopymove_raw(duk_context *to_ctx, duk_context *from_ctx, duk_idx_t count, duk_bool_t is_copy);
492 582
493 #define duk_xmove_top(to_ctx,from_ctx,count) \ 583 #define duk_xmove_top(to_ctx,from_ctx,count) \
494 duk_xcopymove_raw((to_ctx), (from_ctx), (count), 0 /*is_copy*/) 584 duk_xcopymove_raw((to_ctx), (from_ctx), (count), 0 /*is_copy*/)
495 #define duk_xcopy_top(to_ctx,from_ctx,count) \ 585 #define duk_xcopy_top(to_ctx,from_ctx,count) \
517 DUK_EXTERNAL_DECL const char *duk_push_lstring(duk_context *ctx, const char *str, duk_size_t len); 607 DUK_EXTERNAL_DECL const char *duk_push_lstring(duk_context *ctx, const char *str, duk_size_t len);
518 DUK_EXTERNAL_DECL void duk_push_pointer(duk_context *ctx, void *p); 608 DUK_EXTERNAL_DECL void duk_push_pointer(duk_context *ctx, void *p);
519 DUK_EXTERNAL_DECL const char *duk_push_sprintf(duk_context *ctx, const char *fmt, ...); 609 DUK_EXTERNAL_DECL const char *duk_push_sprintf(duk_context *ctx, const char *fmt, ...);
520 DUK_EXTERNAL_DECL const char *duk_push_vsprintf(duk_context *ctx, const char *fmt, va_list ap); 610 DUK_EXTERNAL_DECL const char *duk_push_vsprintf(duk_context *ctx, const char *fmt, va_list ap);
521 611
522 DUK_EXTERNAL_DECL const char *duk_push_string_file_raw(duk_context *ctx, const char *path, duk_uint_t flags);
523 #define duk_push_string_file(ctx,path) \
524 duk_push_string_file_raw((ctx), (path), 0)
525
526 DUK_EXTERNAL_DECL void duk_push_this(duk_context *ctx); 612 DUK_EXTERNAL_DECL void duk_push_this(duk_context *ctx);
527 DUK_EXTERNAL_DECL void duk_push_current_function(duk_context *ctx); 613 DUK_EXTERNAL_DECL void duk_push_current_function(duk_context *ctx);
528 DUK_EXTERNAL_DECL void duk_push_current_thread(duk_context *ctx); 614 DUK_EXTERNAL_DECL void duk_push_current_thread(duk_context *ctx);
529 DUK_EXTERNAL_DECL void duk_push_global_object(duk_context *ctx); 615 DUK_EXTERNAL_DECL void duk_push_global_object(duk_context *ctx);
530 DUK_EXTERNAL_DECL void duk_push_heap_stash(duk_context *ctx); 616 DUK_EXTERNAL_DECL void duk_push_heap_stash(duk_context *ctx);
531 DUK_EXTERNAL_DECL void duk_push_global_stash(duk_context *ctx); 617 DUK_EXTERNAL_DECL void duk_push_global_stash(duk_context *ctx);
532 DUK_EXTERNAL_DECL void duk_push_thread_stash(duk_context *ctx, duk_context *target_ctx); 618 DUK_EXTERNAL_DECL void duk_push_thread_stash(duk_context *ctx, duk_context *target_ctx);
533 619
534 DUK_EXTERNAL_DECL duk_idx_t duk_push_object(duk_context *ctx); 620 DUK_EXTERNAL_DECL duk_idx_t duk_push_object(duk_context *ctx);
621 DUK_EXTERNAL_DECL duk_idx_t duk_push_bare_object(duk_context *ctx);
535 DUK_EXTERNAL_DECL duk_idx_t duk_push_array(duk_context *ctx); 622 DUK_EXTERNAL_DECL duk_idx_t duk_push_array(duk_context *ctx);
536 DUK_EXTERNAL_DECL duk_idx_t duk_push_c_function(duk_context *ctx, duk_c_function func, duk_idx_t nargs); 623 DUK_EXTERNAL_DECL duk_idx_t duk_push_c_function(duk_context *ctx, duk_c_function func, duk_idx_t nargs);
537 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); 624 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);
538 DUK_EXTERNAL_DECL duk_idx_t duk_push_thread_raw(duk_context *ctx, duk_uint_t flags); 625 DUK_EXTERNAL_DECL duk_idx_t duk_push_thread_raw(duk_context *ctx, duk_uint_t flags);
539 626
543 #define duk_push_thread_new_globalenv(ctx) \ 630 #define duk_push_thread_new_globalenv(ctx) \
544 duk_push_thread_raw((ctx), DUK_THREAD_NEW_GLOBAL_ENV /*flags*/) 631 duk_push_thread_raw((ctx), DUK_THREAD_NEW_GLOBAL_ENV /*flags*/)
545 632
546 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, ...); 633 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, ...);
547 634
548 #ifdef DUK_API_VARIADIC_MACROS 635 #if defined(DUK_API_VARIADIC_MACROS)
549 #define duk_push_error_object(ctx,err_code,...) \ 636 #define duk_push_error_object(ctx,err_code,...) \
550 duk_push_error_object_raw((ctx), (err_code), (const char *) (DUK_FILE_MACRO), (duk_int_t) (DUK_LINE_MACRO), __VA_ARGS__) 637 duk_push_error_object_raw((ctx), (err_code), (const char *) (DUK_FILE_MACRO), (duk_int_t) (DUK_LINE_MACRO), __VA_ARGS__)
551 #else 638 #else
552 DUK_EXTERNAL_DECL duk_idx_t duk_push_error_object_stash(duk_context *ctx, duk_errcode_t err_code, const char *fmt, ...); 639 DUK_EXTERNAL_DECL duk_idx_t duk_push_error_object_stash(duk_context *ctx, duk_errcode_t err_code, const char *fmt, ...);
553 /* Note: parentheses are required so that the comma expression works in assignments. */ 640 /* Note: parentheses are required so that the comma expression works in assignments. */
575 duk_push_buffer_raw((ctx), (size), DUK_BUF_FLAG_DYNAMIC /*flags*/) 662 duk_push_buffer_raw((ctx), (size), DUK_BUF_FLAG_DYNAMIC /*flags*/)
576 #define duk_push_external_buffer(ctx) \ 663 #define duk_push_external_buffer(ctx) \
577 ((void) duk_push_buffer_raw((ctx), 0, DUK_BUF_FLAG_DYNAMIC | DUK_BUF_FLAG_EXTERNAL)) 664 ((void) duk_push_buffer_raw((ctx), 0, DUK_BUF_FLAG_DYNAMIC | DUK_BUF_FLAG_EXTERNAL))
578 665
579 #define DUK_BUFOBJ_CREATE_ARRBUF (1 << 4) /* internal flag: create backing ArrayBuffer; keep in one byte */ 666 #define DUK_BUFOBJ_CREATE_ARRBUF (1 << 4) /* internal flag: create backing ArrayBuffer; keep in one byte */
580 #define DUK_BUFOBJ_DUKTAPE_BUFFER 0 667 #define DUK_BUFOBJ_ARRAYBUFFER 0
581 #define DUK_BUFOBJ_NODEJS_BUFFER 1 668 #define DUK_BUFOBJ_NODEJS_BUFFER (1 | DUK_BUFOBJ_CREATE_ARRBUF)
582 #define DUK_BUFOBJ_ARRAYBUFFER 2 669 #define DUK_BUFOBJ_DATAVIEW (2 | DUK_BUFOBJ_CREATE_ARRBUF)
583 #define DUK_BUFOBJ_DATAVIEW (3 | DUK_BUFOBJ_CREATE_ARRBUF) 670 #define DUK_BUFOBJ_INT8ARRAY (3 | DUK_BUFOBJ_CREATE_ARRBUF)
584 #define DUK_BUFOBJ_INT8ARRAY (4 | DUK_BUFOBJ_CREATE_ARRBUF) 671 #define DUK_BUFOBJ_UINT8ARRAY (4 | DUK_BUFOBJ_CREATE_ARRBUF)
585 #define DUK_BUFOBJ_UINT8ARRAY (5 | DUK_BUFOBJ_CREATE_ARRBUF) 672 #define DUK_BUFOBJ_UINT8CLAMPEDARRAY (5 | DUK_BUFOBJ_CREATE_ARRBUF)
586 #define DUK_BUFOBJ_UINT8CLAMPEDARRAY (6 | DUK_BUFOBJ_CREATE_ARRBUF) 673 #define DUK_BUFOBJ_INT16ARRAY (6 | DUK_BUFOBJ_CREATE_ARRBUF)
587 #define DUK_BUFOBJ_INT16ARRAY (7 | DUK_BUFOBJ_CREATE_ARRBUF) 674 #define DUK_BUFOBJ_UINT16ARRAY (7 | DUK_BUFOBJ_CREATE_ARRBUF)
588 #define DUK_BUFOBJ_UINT16ARRAY (8 | DUK_BUFOBJ_CREATE_ARRBUF) 675 #define DUK_BUFOBJ_INT32ARRAY (8 | DUK_BUFOBJ_CREATE_ARRBUF)
589 #define DUK_BUFOBJ_INT32ARRAY (9 | DUK_BUFOBJ_CREATE_ARRBUF) 676 #define DUK_BUFOBJ_UINT32ARRAY (9 | DUK_BUFOBJ_CREATE_ARRBUF)
590 #define DUK_BUFOBJ_UINT32ARRAY (10 | DUK_BUFOBJ_CREATE_ARRBUF) 677 #define DUK_BUFOBJ_FLOAT32ARRAY (10 | DUK_BUFOBJ_CREATE_ARRBUF)
591 #define DUK_BUFOBJ_FLOAT32ARRAY (11 | DUK_BUFOBJ_CREATE_ARRBUF) 678 #define DUK_BUFOBJ_FLOAT64ARRAY (11 | DUK_BUFOBJ_CREATE_ARRBUF)
592 #define DUK_BUFOBJ_FLOAT64ARRAY (12 | DUK_BUFOBJ_CREATE_ARRBUF)
593 679
594 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); 680 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);
595 681
596 DUK_EXTERNAL_DECL duk_idx_t duk_push_heapptr(duk_context *ctx, void *ptr); 682 DUK_EXTERNAL_DECL duk_idx_t duk_push_heapptr(duk_context *ctx, void *ptr);
597 683
609 * 695 *
610 * duk_is_none(), which would indicate whether index it outside of stack, 696 * duk_is_none(), which would indicate whether index it outside of stack,
611 * is not needed; duk_is_valid_index() gives the same information. 697 * is not needed; duk_is_valid_index() gives the same information.
612 */ 698 */
613 699
614 DUK_EXTERNAL_DECL duk_int_t duk_get_type(duk_context *ctx, duk_idx_t index); 700 DUK_EXTERNAL_DECL duk_int_t duk_get_type(duk_context *ctx, duk_idx_t idx);
615 DUK_EXTERNAL_DECL duk_bool_t duk_check_type(duk_context *ctx, duk_idx_t index, duk_int_t type); 701 DUK_EXTERNAL_DECL duk_bool_t duk_check_type(duk_context *ctx, duk_idx_t idx, duk_int_t type);
616 DUK_EXTERNAL_DECL duk_uint_t duk_get_type_mask(duk_context *ctx, duk_idx_t index); 702 DUK_EXTERNAL_DECL duk_uint_t duk_get_type_mask(duk_context *ctx, duk_idx_t idx);
617 DUK_EXTERNAL_DECL duk_bool_t duk_check_type_mask(duk_context *ctx, duk_idx_t index, duk_uint_t mask); 703 DUK_EXTERNAL_DECL duk_bool_t duk_check_type_mask(duk_context *ctx, duk_idx_t idx, duk_uint_t mask);
618 704
619 DUK_EXTERNAL_DECL duk_bool_t duk_is_undefined(duk_context *ctx, duk_idx_t index); 705 DUK_EXTERNAL_DECL duk_bool_t duk_is_undefined(duk_context *ctx, duk_idx_t idx);
620 DUK_EXTERNAL_DECL duk_bool_t duk_is_null(duk_context *ctx, duk_idx_t index); 706 DUK_EXTERNAL_DECL duk_bool_t duk_is_null(duk_context *ctx, duk_idx_t idx);
621 DUK_EXTERNAL_DECL duk_bool_t duk_is_null_or_undefined(duk_context *ctx, duk_idx_t index); 707 #define duk_is_null_or_undefined(ctx, idx) \
622 DUK_EXTERNAL_DECL duk_bool_t duk_is_boolean(duk_context *ctx, duk_idx_t index); 708 ((duk_get_type_mask((ctx), (idx)) & (DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_UNDEFINED)) ? 1 : 0)
623 DUK_EXTERNAL_DECL duk_bool_t duk_is_number(duk_context *ctx, duk_idx_t index); 709
624 DUK_EXTERNAL_DECL duk_bool_t duk_is_nan(duk_context *ctx, duk_idx_t index); 710 DUK_EXTERNAL_DECL duk_bool_t duk_is_boolean(duk_context *ctx, duk_idx_t idx);
625 DUK_EXTERNAL_DECL duk_bool_t duk_is_string(duk_context *ctx, duk_idx_t index); 711 DUK_EXTERNAL_DECL duk_bool_t duk_is_number(duk_context *ctx, duk_idx_t idx);
626 DUK_EXTERNAL_DECL duk_bool_t duk_is_object(duk_context *ctx, duk_idx_t index); 712 DUK_EXTERNAL_DECL duk_bool_t duk_is_nan(duk_context *ctx, duk_idx_t idx);
627 DUK_EXTERNAL_DECL duk_bool_t duk_is_buffer(duk_context *ctx, duk_idx_t index); 713 DUK_EXTERNAL_DECL duk_bool_t duk_is_string(duk_context *ctx, duk_idx_t idx);
628 DUK_EXTERNAL_DECL duk_bool_t duk_is_pointer(duk_context *ctx, duk_idx_t index); 714 DUK_EXTERNAL_DECL duk_bool_t duk_is_object(duk_context *ctx, duk_idx_t idx);
629 DUK_EXTERNAL_DECL duk_bool_t duk_is_lightfunc(duk_context *ctx, duk_idx_t index); 715 DUK_EXTERNAL_DECL duk_bool_t duk_is_buffer(duk_context *ctx, duk_idx_t idx);
630 716 DUK_EXTERNAL_DECL duk_bool_t duk_is_buffer_data(duk_context *ctx, duk_idx_t idx);
631 DUK_EXTERNAL_DECL duk_bool_t duk_is_array(duk_context *ctx, duk_idx_t index); 717 DUK_EXTERNAL_DECL duk_bool_t duk_is_pointer(duk_context *ctx, duk_idx_t idx);
632 DUK_EXTERNAL_DECL duk_bool_t duk_is_function(duk_context *ctx, duk_idx_t index); 718 DUK_EXTERNAL_DECL duk_bool_t duk_is_lightfunc(duk_context *ctx, duk_idx_t idx);
633 DUK_EXTERNAL_DECL duk_bool_t duk_is_c_function(duk_context *ctx, duk_idx_t index); 719
634 DUK_EXTERNAL_DECL duk_bool_t duk_is_ecmascript_function(duk_context *ctx, duk_idx_t index); 720 DUK_EXTERNAL_DECL duk_bool_t duk_is_symbol(duk_context *ctx, duk_idx_t idx);
635 DUK_EXTERNAL_DECL duk_bool_t duk_is_bound_function(duk_context *ctx, duk_idx_t index); 721 DUK_EXTERNAL_DECL duk_bool_t duk_is_array(duk_context *ctx, duk_idx_t idx);
636 DUK_EXTERNAL_DECL duk_bool_t duk_is_thread(duk_context *ctx, duk_idx_t index); 722 DUK_EXTERNAL_DECL duk_bool_t duk_is_function(duk_context *ctx, duk_idx_t idx);
637 723 DUK_EXTERNAL_DECL duk_bool_t duk_is_c_function(duk_context *ctx, duk_idx_t idx);
638 #define duk_is_callable(ctx,index) \ 724 DUK_EXTERNAL_DECL duk_bool_t duk_is_ecmascript_function(duk_context *ctx, duk_idx_t idx);
639 duk_is_function((ctx), (index)) 725 DUK_EXTERNAL_DECL duk_bool_t duk_is_bound_function(duk_context *ctx, duk_idx_t idx);
640 DUK_EXTERNAL_DECL duk_bool_t duk_is_dynamic_buffer(duk_context *ctx, duk_idx_t index); 726 DUK_EXTERNAL_DECL duk_bool_t duk_is_thread(duk_context *ctx, duk_idx_t idx);
641 DUK_EXTERNAL_DECL duk_bool_t duk_is_fixed_buffer(duk_context *ctx, duk_idx_t index); 727
642 DUK_EXTERNAL_DECL duk_bool_t duk_is_external_buffer(duk_context *ctx, duk_idx_t index); 728 #define duk_is_callable(ctx,idx) \
643 729 duk_is_function((ctx), (idx))
644 #define duk_is_primitive(ctx,index) \ 730 DUK_EXTERNAL_DECL duk_bool_t duk_is_dynamic_buffer(duk_context *ctx, duk_idx_t idx);
645 duk_check_type_mask((ctx), (index), DUK_TYPE_MASK_UNDEFINED | \ 731 DUK_EXTERNAL_DECL duk_bool_t duk_is_fixed_buffer(duk_context *ctx, duk_idx_t idx);
646 DUK_TYPE_MASK_NULL | \ 732 DUK_EXTERNAL_DECL duk_bool_t duk_is_external_buffer(duk_context *ctx, duk_idx_t idx);
647 DUK_TYPE_MASK_BOOLEAN | \ 733
648 DUK_TYPE_MASK_NUMBER | \ 734 /* Buffers and lightfuncs are not considered primitive because they mimic
649 DUK_TYPE_MASK_STRING | \ 735 * objects and e.g. duk_to_primitive() will coerce them instead of returning
650 DUK_TYPE_MASK_BUFFER | \ 736 * them as is. Symbols are represented as strings internally.
651 DUK_TYPE_MASK_POINTER | \ 737 */
652 DUK_TYPE_MASK_LIGHTFUNC) 738 #define duk_is_primitive(ctx,idx) \
653 739 duk_check_type_mask((ctx), (idx), DUK_TYPE_MASK_UNDEFINED | \
654 #define duk_is_object_coercible(ctx,index) \ 740 DUK_TYPE_MASK_NULL | \
655 duk_check_type_mask((ctx), (index), DUK_TYPE_MASK_BOOLEAN | \ 741 DUK_TYPE_MASK_BOOLEAN | \
656 DUK_TYPE_MASK_NUMBER | \ 742 DUK_TYPE_MASK_NUMBER | \
657 DUK_TYPE_MASK_STRING | \ 743 DUK_TYPE_MASK_STRING | \
658 DUK_TYPE_MASK_OBJECT | \ 744 DUK_TYPE_MASK_POINTER)
659 DUK_TYPE_MASK_BUFFER | \ 745
660 DUK_TYPE_MASK_POINTER | \ 746 /* Symbols are object coercible, covered by DUK_TYPE_MASK_STRING. */
661 DUK_TYPE_MASK_LIGHTFUNC) 747 #define duk_is_object_coercible(ctx,idx) \
662 748 duk_check_type_mask((ctx), (idx), DUK_TYPE_MASK_BOOLEAN | \
663 DUK_EXTERNAL_DECL duk_errcode_t duk_get_error_code(duk_context *ctx, duk_idx_t index); 749 DUK_TYPE_MASK_NUMBER | \
664 #define duk_is_error(ctx,index) \ 750 DUK_TYPE_MASK_STRING | \
665 (duk_get_error_code((ctx), (index)) != 0) 751 DUK_TYPE_MASK_OBJECT | \
666 #define duk_is_eval_error(ctx,index) \ 752 DUK_TYPE_MASK_BUFFER | \
667 (duk_get_error_code((ctx), (index)) == DUK_ERR_EVAL_ERROR) 753 DUK_TYPE_MASK_POINTER | \
668 #define duk_is_range_error(ctx,index) \ 754 DUK_TYPE_MASK_LIGHTFUNC)
669 (duk_get_error_code((ctx), (index)) == DUK_ERR_RANGE_ERROR) 755
670 #define duk_is_reference_error(ctx,index) \ 756 DUK_EXTERNAL_DECL duk_errcode_t duk_get_error_code(duk_context *ctx, duk_idx_t idx);
671 (duk_get_error_code((ctx), (index)) == DUK_ERR_REFERENCE_ERROR) 757 #define duk_is_error(ctx,idx) \
672 #define duk_is_syntax_error(ctx,index) \ 758 (duk_get_error_code((ctx), (idx)) != 0)
673 (duk_get_error_code((ctx), (index)) == DUK_ERR_SYNTAX_ERROR) 759 #define duk_is_eval_error(ctx,idx) \
674 #define duk_is_type_error(ctx,index) \ 760 (duk_get_error_code((ctx), (idx)) == DUK_ERR_EVAL_ERROR)
675 (duk_get_error_code((ctx), (index)) == DUK_ERR_TYPE_ERROR) 761 #define duk_is_range_error(ctx,idx) \
676 #define duk_is_uri_error(ctx,index) \ 762 (duk_get_error_code((ctx), (idx)) == DUK_ERR_RANGE_ERROR)
677 (duk_get_error_code((ctx), (index)) == DUK_ERR_URI_ERROR) 763 #define duk_is_reference_error(ctx,idx) \
764 (duk_get_error_code((ctx), (idx)) == DUK_ERR_REFERENCE_ERROR)
765 #define duk_is_syntax_error(ctx,idx) \
766 (duk_get_error_code((ctx), (idx)) == DUK_ERR_SYNTAX_ERROR)
767 #define duk_is_type_error(ctx,idx) \
768 (duk_get_error_code((ctx), (idx)) == DUK_ERR_TYPE_ERROR)
769 #define duk_is_uri_error(ctx,idx) \
770 (duk_get_error_code((ctx), (idx)) == DUK_ERR_URI_ERROR)
678 771
679 /* 772 /*
680 * Get operations: no coercion, returns default value for invalid 773 * Get operations: no coercion, returns default value for invalid
681 * indices and invalid value types. 774 * indices and invalid value types.
682 * 775 *
683 * duk_get_undefined() and duk_get_null() would be pointless and 776 * duk_get_undefined() and duk_get_null() would be pointless and
684 * are not included. 777 * are not included.
685 */ 778 */
686 779
687 DUK_EXTERNAL_DECL duk_bool_t duk_get_boolean(duk_context *ctx, duk_idx_t index); 780 DUK_EXTERNAL_DECL duk_bool_t duk_get_boolean(duk_context *ctx, duk_idx_t idx);
688 DUK_EXTERNAL_DECL duk_double_t duk_get_number(duk_context *ctx, duk_idx_t index); 781 DUK_EXTERNAL_DECL duk_double_t duk_get_number(duk_context *ctx, duk_idx_t idx);
689 DUK_EXTERNAL_DECL duk_int_t duk_get_int(duk_context *ctx, duk_idx_t index); 782 DUK_EXTERNAL_DECL duk_int_t duk_get_int(duk_context *ctx, duk_idx_t idx);
690 DUK_EXTERNAL_DECL duk_uint_t duk_get_uint(duk_context *ctx, duk_idx_t index); 783 DUK_EXTERNAL_DECL duk_uint_t duk_get_uint(duk_context *ctx, duk_idx_t idx);
691 DUK_EXTERNAL_DECL const char *duk_get_string(duk_context *ctx, duk_idx_t index); 784 DUK_EXTERNAL_DECL const char *duk_get_string(duk_context *ctx, duk_idx_t idx);
692 DUK_EXTERNAL_DECL const char *duk_get_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len); 785 DUK_EXTERNAL_DECL const char *duk_get_lstring(duk_context *ctx, duk_idx_t idx, duk_size_t *out_len);
693 DUK_EXTERNAL_DECL void *duk_get_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size); 786 DUK_EXTERNAL_DECL void *duk_get_buffer(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size);
694 DUK_EXTERNAL_DECL void *duk_get_buffer_data(duk_context *ctx, duk_idx_t index, duk_size_t *out_size); 787 DUK_EXTERNAL_DECL void *duk_get_buffer_data(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size);
695 DUK_EXTERNAL_DECL void *duk_get_pointer(duk_context *ctx, duk_idx_t index); 788 DUK_EXTERNAL_DECL void *duk_get_pointer(duk_context *ctx, duk_idx_t idx);
696 DUK_EXTERNAL_DECL duk_c_function duk_get_c_function(duk_context *ctx, duk_idx_t index); 789 DUK_EXTERNAL_DECL duk_c_function duk_get_c_function(duk_context *ctx, duk_idx_t idx);
697 DUK_EXTERNAL_DECL duk_context *duk_get_context(duk_context *ctx, duk_idx_t index); 790 DUK_EXTERNAL_DECL duk_context *duk_get_context(duk_context *ctx, duk_idx_t idx);
698 DUK_EXTERNAL_DECL void *duk_get_heapptr(duk_context *ctx, duk_idx_t index); 791 DUK_EXTERNAL_DECL void *duk_get_heapptr(duk_context *ctx, duk_idx_t idx);
699 DUK_EXTERNAL_DECL duk_size_t duk_get_length(duk_context *ctx, duk_idx_t index); 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);
700 794
701 /* 795 /*
702 * Require operations: no coercion, throw error if index or type 796 * Require operations: no coercion, throw error if index or type
703 * is incorrect. No defaulting. 797 * is incorrect. No defaulting.
704 */ 798 */
705 799
706 #define duk_require_type_mask(ctx,index,mask) \ 800 #define duk_require_type_mask(ctx,idx,mask) \
707 ((void) duk_check_type_mask((ctx), (index), (mask) | DUK_TYPE_MASK_THROW)) 801 ((void) duk_check_type_mask((ctx), (idx), (mask) | DUK_TYPE_MASK_THROW))
708 802
709 DUK_EXTERNAL_DECL void duk_require_undefined(duk_context *ctx, duk_idx_t index); 803 DUK_EXTERNAL_DECL void duk_require_undefined(duk_context *ctx, duk_idx_t idx);
710 DUK_EXTERNAL_DECL void duk_require_null(duk_context *ctx, duk_idx_t index); 804 DUK_EXTERNAL_DECL void duk_require_null(duk_context *ctx, duk_idx_t idx);
711 DUK_EXTERNAL_DECL duk_bool_t duk_require_boolean(duk_context *ctx, duk_idx_t index); 805 DUK_EXTERNAL_DECL duk_bool_t duk_require_boolean(duk_context *ctx, duk_idx_t idx);
712 DUK_EXTERNAL_DECL duk_double_t duk_require_number(duk_context *ctx, duk_idx_t index); 806 DUK_EXTERNAL_DECL duk_double_t duk_require_number(duk_context *ctx, duk_idx_t idx);
713 DUK_EXTERNAL_DECL duk_int_t duk_require_int(duk_context *ctx, duk_idx_t index); 807 DUK_EXTERNAL_DECL duk_int_t duk_require_int(duk_context *ctx, duk_idx_t idx);
714 DUK_EXTERNAL_DECL duk_uint_t duk_require_uint(duk_context *ctx, duk_idx_t index); 808 DUK_EXTERNAL_DECL duk_uint_t duk_require_uint(duk_context *ctx, duk_idx_t idx);
715 DUK_EXTERNAL_DECL const char *duk_require_string(duk_context *ctx, duk_idx_t index); 809 DUK_EXTERNAL_DECL const char *duk_require_string(duk_context *ctx, duk_idx_t idx);
716 DUK_EXTERNAL_DECL const char *duk_require_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len); 810 DUK_EXTERNAL_DECL const char *duk_require_lstring(duk_context *ctx, duk_idx_t idx, duk_size_t *out_len);
717 DUK_EXTERNAL_DECL void *duk_require_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size); 811 DUK_EXTERNAL_DECL void *duk_require_buffer(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size);
718 DUK_EXTERNAL_DECL void *duk_require_buffer_data(duk_context *ctx, duk_idx_t index, duk_size_t *out_size); 812 DUK_EXTERNAL_DECL void *duk_require_buffer_data(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size);
719 DUK_EXTERNAL_DECL void *duk_require_pointer(duk_context *ctx, duk_idx_t index); 813 DUK_EXTERNAL_DECL void *duk_require_pointer(duk_context *ctx, duk_idx_t idx);
720 DUK_EXTERNAL_DECL duk_c_function duk_require_c_function(duk_context *ctx, duk_idx_t index); 814 DUK_EXTERNAL_DECL duk_c_function duk_require_c_function(duk_context *ctx, duk_idx_t idx);
721 DUK_EXTERNAL_DECL duk_context *duk_require_context(duk_context *ctx, duk_idx_t index); 815 DUK_EXTERNAL_DECL duk_context *duk_require_context(duk_context *ctx, duk_idx_t idx);
722 DUK_EXTERNAL_DECL void duk_require_function(duk_context *ctx, duk_idx_t index); 816 DUK_EXTERNAL_DECL void duk_require_function(duk_context *ctx, duk_idx_t idx);
723 #define duk_require_callable(ctx,index) \ 817 #define duk_require_callable(ctx,idx) \
724 duk_require_function((ctx), (index)) 818 duk_require_function((ctx), (idx))
725 DUK_EXTERNAL_DECL void *duk_require_heapptr(duk_context *ctx, duk_idx_t index); 819 DUK_EXTERNAL_DECL void *duk_require_heapptr(duk_context *ctx, duk_idx_t idx);
726 820
727 #define duk_require_object_coercible(ctx,index) \ 821 /* Symbols are object coercible and covered by DUK_TYPE_MASK_STRING. */
728 ((void) duk_check_type_mask((ctx), (index), DUK_TYPE_MASK_BOOLEAN | \ 822 #define duk_require_object_coercible(ctx,idx) \
823 ((void) duk_check_type_mask((ctx), (idx), DUK_TYPE_MASK_BOOLEAN | \
729 DUK_TYPE_MASK_NUMBER | \ 824 DUK_TYPE_MASK_NUMBER | \
730 DUK_TYPE_MASK_STRING | \ 825 DUK_TYPE_MASK_STRING | \
731 DUK_TYPE_MASK_OBJECT | \ 826 DUK_TYPE_MASK_OBJECT | \
732 DUK_TYPE_MASK_BUFFER | \ 827 DUK_TYPE_MASK_BUFFER | \
733 DUK_TYPE_MASK_POINTER | \ 828 DUK_TYPE_MASK_POINTER | \
739 * applicable. If index is invalid, throw error. Some coercions may 834 * applicable. If index is invalid, throw error. Some coercions may
740 * throw an expected error (e.g. from a toString() or valueOf() call) 835 * throw an expected error (e.g. from a toString() or valueOf() call)
741 * or an internal error (e.g. from out of memory). 836 * or an internal error (e.g. from out of memory).
742 */ 837 */
743 838
744 DUK_EXTERNAL_DECL void duk_to_undefined(duk_context *ctx, duk_idx_t index); 839 DUK_EXTERNAL_DECL void duk_to_undefined(duk_context *ctx, duk_idx_t idx);
745 DUK_EXTERNAL_DECL void duk_to_null(duk_context *ctx, duk_idx_t index); 840 DUK_EXTERNAL_DECL void duk_to_null(duk_context *ctx, duk_idx_t idx);
746 DUK_EXTERNAL_DECL duk_bool_t duk_to_boolean(duk_context *ctx, duk_idx_t index); 841 DUK_EXTERNAL_DECL duk_bool_t duk_to_boolean(duk_context *ctx, duk_idx_t idx);
747 DUK_EXTERNAL_DECL duk_double_t duk_to_number(duk_context *ctx, duk_idx_t index); 842 DUK_EXTERNAL_DECL duk_double_t duk_to_number(duk_context *ctx, duk_idx_t idx);
748 DUK_EXTERNAL_DECL duk_int_t duk_to_int(duk_context *ctx, duk_idx_t index); 843 DUK_EXTERNAL_DECL duk_int_t duk_to_int(duk_context *ctx, duk_idx_t idx);
749 DUK_EXTERNAL_DECL duk_uint_t duk_to_uint(duk_context *ctx, duk_idx_t index); 844 DUK_EXTERNAL_DECL duk_uint_t duk_to_uint(duk_context *ctx, duk_idx_t idx);
750 DUK_EXTERNAL_DECL duk_int32_t duk_to_int32(duk_context *ctx, duk_idx_t index); 845 DUK_EXTERNAL_DECL duk_int32_t duk_to_int32(duk_context *ctx, duk_idx_t idx);
751 DUK_EXTERNAL_DECL duk_uint32_t duk_to_uint32(duk_context *ctx, duk_idx_t index); 846 DUK_EXTERNAL_DECL duk_uint32_t duk_to_uint32(duk_context *ctx, duk_idx_t idx);
752 DUK_EXTERNAL_DECL duk_uint16_t duk_to_uint16(duk_context *ctx, duk_idx_t index); 847 DUK_EXTERNAL_DECL duk_uint16_t duk_to_uint16(duk_context *ctx, duk_idx_t idx);
753 DUK_EXTERNAL_DECL const char *duk_to_string(duk_context *ctx, duk_idx_t index); 848 DUK_EXTERNAL_DECL const char *duk_to_string(duk_context *ctx, duk_idx_t idx);
754 DUK_EXTERNAL_DECL const char *duk_to_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len); 849 DUK_EXTERNAL_DECL const char *duk_to_lstring(duk_context *ctx, duk_idx_t idx, duk_size_t *out_len);
755 DUK_EXTERNAL_DECL void *duk_to_buffer_raw(duk_context *ctx, duk_idx_t index, duk_size_t *out_size, duk_uint_t flags); 850 DUK_EXTERNAL_DECL void *duk_to_buffer_raw(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size, duk_uint_t flags);
756 DUK_EXTERNAL_DECL void *duk_to_pointer(duk_context *ctx, duk_idx_t index); 851 DUK_EXTERNAL_DECL void *duk_to_pointer(duk_context *ctx, duk_idx_t idx);
757 DUK_EXTERNAL_DECL void duk_to_object(duk_context *ctx, duk_idx_t index); 852 DUK_EXTERNAL_DECL void duk_to_object(duk_context *ctx, duk_idx_t idx);
758 DUK_EXTERNAL_DECL void duk_to_defaultvalue(duk_context *ctx, duk_idx_t index, duk_int_t hint); 853 DUK_EXTERNAL_DECL void duk_to_primitive(duk_context *ctx, duk_idx_t idx, duk_int_t hint);
759 DUK_EXTERNAL_DECL void duk_to_primitive(duk_context *ctx, duk_idx_t index, duk_int_t hint);
760 854
761 #define DUK_BUF_MODE_FIXED 0 /* internal: request fixed buffer result */ 855 #define DUK_BUF_MODE_FIXED 0 /* internal: request fixed buffer result */
762 #define DUK_BUF_MODE_DYNAMIC 1 /* internal: request dynamic buffer result */ 856 #define DUK_BUF_MODE_DYNAMIC 1 /* internal: request dynamic buffer result */
763 #define DUK_BUF_MODE_DONTCARE 2 /* internal: don't care about fixed/dynamic nature */ 857 #define DUK_BUF_MODE_DONTCARE 2 /* internal: don't care about fixed/dynamic nature */
764 858
765 #define duk_to_buffer(ctx,index,out_size) \ 859 #define duk_to_buffer(ctx,idx,out_size) \
766 duk_to_buffer_raw((ctx), (index), (out_size), DUK_BUF_MODE_DONTCARE) 860 duk_to_buffer_raw((ctx), (idx), (out_size), DUK_BUF_MODE_DONTCARE)
767 #define duk_to_fixed_buffer(ctx,index,out_size) \ 861 #define duk_to_fixed_buffer(ctx,idx,out_size) \
768 duk_to_buffer_raw((ctx), (index), (out_size), DUK_BUF_MODE_FIXED) 862 duk_to_buffer_raw((ctx), (idx), (out_size), DUK_BUF_MODE_FIXED)
769 #define duk_to_dynamic_buffer(ctx,index,out_size) \ 863 #define duk_to_dynamic_buffer(ctx,idx,out_size) \
770 duk_to_buffer_raw((ctx), (index), (out_size), DUK_BUF_MODE_DYNAMIC) 864 duk_to_buffer_raw((ctx), (idx), (out_size), DUK_BUF_MODE_DYNAMIC)
771 865
772 /* safe variants of a few coercion operations */ 866 /* safe variants of a few coercion operations */
773 DUK_EXTERNAL_DECL const char *duk_safe_to_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len); 867 DUK_EXTERNAL_DECL const char *duk_safe_to_lstring(duk_context *ctx, duk_idx_t idx, duk_size_t *out_len);
774 #define duk_safe_to_string(ctx,index) \ 868 #define duk_safe_to_string(ctx,idx) \
775 duk_safe_to_lstring((ctx), (index), NULL) 869 duk_safe_to_lstring((ctx), (idx), NULL)
776 870
777 /* 871 /*
778 * Misc conversion 872 * Misc conversion
779 */ 873 */
780 874
781 DUK_EXTERNAL_DECL const char *duk_base64_encode(duk_context *ctx, duk_idx_t index); 875 DUK_EXTERNAL_DECL const char *duk_base64_encode(duk_context *ctx, duk_idx_t idx);
782 DUK_EXTERNAL_DECL void duk_base64_decode(duk_context *ctx, duk_idx_t index); 876 DUK_EXTERNAL_DECL void duk_base64_decode(duk_context *ctx, duk_idx_t idx);
783 DUK_EXTERNAL_DECL const char *duk_hex_encode(duk_context *ctx, duk_idx_t index); 877 DUK_EXTERNAL_DECL const char *duk_hex_encode(duk_context *ctx, duk_idx_t idx);
784 DUK_EXTERNAL_DECL void duk_hex_decode(duk_context *ctx, duk_idx_t index); 878 DUK_EXTERNAL_DECL void duk_hex_decode(duk_context *ctx, duk_idx_t idx);
785 DUK_EXTERNAL_DECL const char *duk_json_encode(duk_context *ctx, duk_idx_t index); 879 DUK_EXTERNAL_DECL const char *duk_json_encode(duk_context *ctx, duk_idx_t idx);
786 DUK_EXTERNAL_DECL void duk_json_decode(duk_context *ctx, duk_idx_t index); 880 DUK_EXTERNAL_DECL void duk_json_decode(duk_context *ctx, duk_idx_t idx);
881
882 DUK_EXTERNAL_DECL const char *duk_buffer_to_string(duk_context *ctx, duk_idx_t idx);
787 883
788 /* 884 /*
789 * Buffer 885 * Buffer
790 */ 886 */
791 887
792 DUK_EXTERNAL_DECL void *duk_resize_buffer(duk_context *ctx, duk_idx_t index, duk_size_t new_size); 888 DUK_EXTERNAL_DECL void *duk_resize_buffer(duk_context *ctx, duk_idx_t idx, duk_size_t new_size);
793 DUK_EXTERNAL_DECL void *duk_steal_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size); 889 DUK_EXTERNAL_DECL void *duk_steal_buffer(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size);
794 DUK_EXTERNAL_DECL void duk_config_buffer(duk_context *ctx, duk_idx_t index, void *ptr, duk_size_t len); 890 DUK_EXTERNAL_DECL void duk_config_buffer(duk_context *ctx, duk_idx_t idx, void *ptr, duk_size_t len);
795 891
796 /* 892 /*
797 * Property access 893 * Property access
798 * 894 *
799 * The basic function assumes key is on stack. The _string variant takes 895 * The basic function assumes key is on stack. The _string variant takes
800 * a C string as a property name, while the _index variant takes an array 896 * a C string as a property name, while the _index variant takes an array
801 * index as a property name (e.g. 123 is equivalent to the key "123"). 897 * index as a property name (e.g. 123 is equivalent to the key "123").
802 */ 898 */
803 899
804 DUK_EXTERNAL_DECL duk_bool_t duk_get_prop(duk_context *ctx, duk_idx_t obj_index); 900 DUK_EXTERNAL_DECL duk_bool_t duk_get_prop(duk_context *ctx, duk_idx_t obj_idx);
805 DUK_EXTERNAL_DECL duk_bool_t duk_get_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key); 901 DUK_EXTERNAL_DECL duk_bool_t duk_get_prop_string(duk_context *ctx, duk_idx_t obj_idx, const char *key);
806 DUK_EXTERNAL_DECL duk_bool_t duk_get_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index); 902 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);
807 DUK_EXTERNAL_DECL duk_bool_t duk_put_prop(duk_context *ctx, duk_idx_t obj_index); 903 DUK_EXTERNAL_DECL duk_bool_t duk_get_prop_index(duk_context *ctx, duk_idx_t obj_idx, duk_uarridx_t arr_idx);
808 DUK_EXTERNAL_DECL duk_bool_t duk_put_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key); 904 DUK_EXTERNAL_DECL duk_bool_t duk_put_prop(duk_context *ctx, duk_idx_t obj_idx);
809 DUK_EXTERNAL_DECL duk_bool_t duk_put_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index); 905 DUK_EXTERNAL_DECL duk_bool_t duk_put_prop_string(duk_context *ctx, duk_idx_t obj_idx, const char *key);
810 DUK_EXTERNAL_DECL duk_bool_t duk_del_prop(duk_context *ctx, duk_idx_t obj_index); 906 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);
811 DUK_EXTERNAL_DECL duk_bool_t duk_del_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key); 907 DUK_EXTERNAL_DECL duk_bool_t duk_put_prop_index(duk_context *ctx, duk_idx_t obj_idx, duk_uarridx_t arr_idx);
812 DUK_EXTERNAL_DECL duk_bool_t duk_del_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index); 908 DUK_EXTERNAL_DECL duk_bool_t duk_del_prop(duk_context *ctx, duk_idx_t obj_idx);
813 DUK_EXTERNAL_DECL duk_bool_t duk_has_prop(duk_context *ctx, duk_idx_t obj_index); 909 DUK_EXTERNAL_DECL duk_bool_t duk_del_prop_string(duk_context *ctx, duk_idx_t obj_idx, const char *key);
814 DUK_EXTERNAL_DECL duk_bool_t duk_has_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key); 910 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);
815 DUK_EXTERNAL_DECL duk_bool_t duk_has_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index); 911 DUK_EXTERNAL_DECL duk_bool_t duk_del_prop_index(duk_context *ctx, duk_idx_t obj_idx, duk_uarridx_t arr_idx);
816 DUK_EXTERNAL_DECL void duk_def_prop(duk_context *ctx, duk_idx_t obj_index, duk_uint_t flags); 912 DUK_EXTERNAL_DECL duk_bool_t duk_has_prop(duk_context *ctx, duk_idx_t obj_idx);
913 DUK_EXTERNAL_DECL duk_bool_t duk_has_prop_string(duk_context *ctx, duk_idx_t obj_idx, const char *key);
914 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);
915 DUK_EXTERNAL_DECL duk_bool_t duk_has_prop_index(duk_context *ctx, duk_idx_t obj_idx, duk_uarridx_t arr_idx);
916
917 DUK_EXTERNAL_DECL void duk_get_prop_desc(duk_context *ctx, duk_idx_t obj_idx, duk_uint_t flags);
918 DUK_EXTERNAL_DECL void duk_def_prop(duk_context *ctx, duk_idx_t obj_idx, duk_uint_t flags);
817 919
818 DUK_EXTERNAL_DECL duk_bool_t duk_get_global_string(duk_context *ctx, const char *key); 920 DUK_EXTERNAL_DECL duk_bool_t duk_get_global_string(duk_context *ctx, const char *key);
921 DUK_EXTERNAL_DECL duk_bool_t duk_get_global_lstring(duk_context *ctx, const char *key, duk_size_t key_len);
819 DUK_EXTERNAL_DECL duk_bool_t duk_put_global_string(duk_context *ctx, const char *key); 922 DUK_EXTERNAL_DECL duk_bool_t duk_put_global_string(duk_context *ctx, const char *key);
923 DUK_EXTERNAL_DECL duk_bool_t duk_put_global_lstring(duk_context *ctx, const char *key, duk_size_t key_len);
924
925 /*
926 * Inspection
927 */
928
929 DUK_EXTERNAL_DECL void duk_inspect_value(duk_context *ctx, duk_idx_t idx);
930 DUK_EXTERNAL_DECL void duk_inspect_callstack_entry(duk_context *ctx, duk_int_t level);
820 931
821 /* 932 /*
822 * Object prototype 933 * Object prototype
823 */ 934 */
824 935
825 DUK_EXTERNAL_DECL void duk_get_prototype(duk_context *ctx, duk_idx_t index); 936 DUK_EXTERNAL_DECL void duk_get_prototype(duk_context *ctx, duk_idx_t idx);
826 DUK_EXTERNAL_DECL void duk_set_prototype(duk_context *ctx, duk_idx_t index); 937 DUK_EXTERNAL_DECL void duk_set_prototype(duk_context *ctx, duk_idx_t idx);
827 938
828 /* 939 /*
829 * Object finalizer 940 * Object finalizer
830 */ 941 */
831 942
832 DUK_EXTERNAL_DECL void duk_get_finalizer(duk_context *ctx, duk_idx_t index); 943 DUK_EXTERNAL_DECL void duk_get_finalizer(duk_context *ctx, duk_idx_t idx);
833 DUK_EXTERNAL_DECL void duk_set_finalizer(duk_context *ctx, duk_idx_t index); 944 DUK_EXTERNAL_DECL void duk_set_finalizer(duk_context *ctx, duk_idx_t idx);
834 945
835 /* 946 /*
836 * Global object 947 * Global object
837 */ 948 */
838 949
840 951
841 /* 952 /*
842 * Duktape/C function magic value 953 * Duktape/C function magic value
843 */ 954 */
844 955
845 DUK_EXTERNAL_DECL duk_int_t duk_get_magic(duk_context *ctx, duk_idx_t index); 956 DUK_EXTERNAL_DECL duk_int_t duk_get_magic(duk_context *ctx, duk_idx_t idx);
846 DUK_EXTERNAL_DECL void duk_set_magic(duk_context *ctx, duk_idx_t index, duk_int_t magic); 957 DUK_EXTERNAL_DECL void duk_set_magic(duk_context *ctx, duk_idx_t idx, duk_int_t magic);
847 DUK_EXTERNAL_DECL duk_int_t duk_get_current_magic(duk_context *ctx); 958 DUK_EXTERNAL_DECL duk_int_t duk_get_current_magic(duk_context *ctx);
848 959
849 /* 960 /*
850 * Module helpers: put multiple function or constant properties 961 * Module helpers: put multiple function or constant properties
851 */ 962 */
852 963
853 DUK_EXTERNAL_DECL void duk_put_function_list(duk_context *ctx, duk_idx_t obj_index, const duk_function_list_entry *funcs); 964 DUK_EXTERNAL_DECL void duk_put_function_list(duk_context *ctx, duk_idx_t obj_idx, const duk_function_list_entry *funcs);
854 DUK_EXTERNAL_DECL void duk_put_number_list(duk_context *ctx, duk_idx_t obj_index, const duk_number_list_entry *numbers); 965 DUK_EXTERNAL_DECL void duk_put_number_list(duk_context *ctx, duk_idx_t obj_idx, const duk_number_list_entry *numbers);
855
856 /*
857 * Variable access
858 */
859
860 /* XXX: These calls are incomplete and not usable now. They are not (yet)
861 * part of the public API.
862 */
863 DUK_EXTERNAL_DECL void duk_get_var(duk_context *ctx);
864 DUK_EXTERNAL_DECL void duk_put_var(duk_context *ctx);
865 DUK_EXTERNAL_DECL duk_bool_t duk_del_var(duk_context *ctx);
866 DUK_EXTERNAL_DECL duk_bool_t duk_has_var(duk_context *ctx);
867 966
868 /* 967 /*
869 * Object operations 968 * Object operations
870 */ 969 */
871 970
872 DUK_EXTERNAL_DECL void duk_compact(duk_context *ctx, duk_idx_t obj_index); 971 DUK_EXTERNAL_DECL void duk_compact(duk_context *ctx, duk_idx_t obj_idx);
873 DUK_EXTERNAL_DECL void duk_enum(duk_context *ctx, duk_idx_t obj_index, duk_uint_t enum_flags); 972 DUK_EXTERNAL_DECL void duk_enum(duk_context *ctx, duk_idx_t obj_idx, duk_uint_t enum_flags);
874 DUK_EXTERNAL_DECL duk_bool_t duk_next(duk_context *ctx, duk_idx_t enum_index, duk_bool_t get_value); 973 DUK_EXTERNAL_DECL duk_bool_t duk_next(duk_context *ctx, duk_idx_t enum_idx, duk_bool_t get_value);
875 974
876 /* 975 /*
877 * String manipulation 976 * String manipulation
878 */ 977 */
879 978
880 DUK_EXTERNAL_DECL void duk_concat(duk_context *ctx, duk_idx_t count); 979 DUK_EXTERNAL_DECL void duk_concat(duk_context *ctx, duk_idx_t count);
881 DUK_EXTERNAL_DECL void duk_join(duk_context *ctx, duk_idx_t count); 980 DUK_EXTERNAL_DECL void duk_join(duk_context *ctx, duk_idx_t count);
882 DUK_EXTERNAL_DECL void duk_decode_string(duk_context *ctx, duk_idx_t index, duk_decode_char_function callback, void *udata); 981 DUK_EXTERNAL_DECL void duk_decode_string(duk_context *ctx, duk_idx_t idx, duk_decode_char_function callback, void *udata);
883 DUK_EXTERNAL_DECL void duk_map_string(duk_context *ctx, duk_idx_t index, duk_map_char_function callback, void *udata); 982 DUK_EXTERNAL_DECL void duk_map_string(duk_context *ctx, duk_idx_t idx, duk_map_char_function callback, void *udata);
884 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); 983 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);
885 DUK_EXTERNAL_DECL void duk_trim(duk_context *ctx, duk_idx_t index); 984 DUK_EXTERNAL_DECL void duk_trim(duk_context *ctx, duk_idx_t idx);
886 DUK_EXTERNAL_DECL duk_codepoint_t duk_char_code_at(duk_context *ctx, duk_idx_t index, duk_size_t char_offset); 985 DUK_EXTERNAL_DECL duk_codepoint_t duk_char_code_at(duk_context *ctx, duk_idx_t idx, duk_size_t char_offset);
887 986
888 /* 987 /*
889 * Ecmascript operators 988 * Ecmascript operators
890 */ 989 */
891 990
892 DUK_EXTERNAL_DECL duk_bool_t duk_equals(duk_context *ctx, duk_idx_t index1, duk_idx_t index2); 991 DUK_EXTERNAL_DECL duk_bool_t duk_equals(duk_context *ctx, duk_idx_t idx1, duk_idx_t idx2);
893 DUK_EXTERNAL_DECL duk_bool_t duk_strict_equals(duk_context *ctx, duk_idx_t index1, duk_idx_t index2); 992 DUK_EXTERNAL_DECL duk_bool_t duk_strict_equals(duk_context *ctx, duk_idx_t idx1, duk_idx_t idx2);
894 DUK_EXTERNAL_DECL duk_bool_t duk_instanceof(duk_context *ctx, duk_idx_t index1, duk_idx_t index2); 993 DUK_EXTERNAL_DECL duk_bool_t duk_samevalue(duk_context *ctx, duk_idx_t idx1, duk_idx_t idx2);
994 DUK_EXTERNAL_DECL duk_bool_t duk_instanceof(duk_context *ctx, duk_idx_t idx1, duk_idx_t idx2);
895 995
896 /* 996 /*
897 * Function (method) calls 997 * Function (method) calls
898 */ 998 */
899 999
900 DUK_EXTERNAL_DECL void duk_call(duk_context *ctx, duk_idx_t nargs); 1000 DUK_EXTERNAL_DECL void duk_call(duk_context *ctx, duk_idx_t nargs);
901 DUK_EXTERNAL_DECL void duk_call_method(duk_context *ctx, duk_idx_t nargs); 1001 DUK_EXTERNAL_DECL void duk_call_method(duk_context *ctx, duk_idx_t nargs);
902 DUK_EXTERNAL_DECL void duk_call_prop(duk_context *ctx, duk_idx_t obj_index, duk_idx_t nargs); 1002 DUK_EXTERNAL_DECL void duk_call_prop(duk_context *ctx, duk_idx_t obj_idx, duk_idx_t nargs);
903 DUK_EXTERNAL_DECL duk_int_t duk_pcall(duk_context *ctx, duk_idx_t nargs); 1003 DUK_EXTERNAL_DECL duk_int_t duk_pcall(duk_context *ctx, duk_idx_t nargs);
904 DUK_EXTERNAL_DECL duk_int_t duk_pcall_method(duk_context *ctx, duk_idx_t nargs); 1004 DUK_EXTERNAL_DECL duk_int_t duk_pcall_method(duk_context *ctx, duk_idx_t nargs);
905 DUK_EXTERNAL_DECL duk_int_t duk_pcall_prop(duk_context *ctx, duk_idx_t obj_index, duk_idx_t nargs); 1005 DUK_EXTERNAL_DECL duk_int_t duk_pcall_prop(duk_context *ctx, duk_idx_t obj_idx, duk_idx_t nargs);
906 DUK_EXTERNAL_DECL void duk_new(duk_context *ctx, duk_idx_t nargs); 1006 DUK_EXTERNAL_DECL void duk_new(duk_context *ctx, duk_idx_t nargs);
907 DUK_EXTERNAL_DECL duk_int_t duk_pnew(duk_context *ctx, duk_idx_t nargs); 1007 DUK_EXTERNAL_DECL duk_int_t duk_pnew(duk_context *ctx, duk_idx_t nargs);
908 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); 1008 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);
909 1009
910 /* 1010 /*
911 * Thread management 1011 * Thread management
912 */ 1012 */
913 1013
922 DUK_EXTERNAL_DECL duk_int_t duk_eval_raw(duk_context *ctx, const char *src_buffer, duk_size_t src_length, duk_uint_t flags); 1022 DUK_EXTERNAL_DECL duk_int_t duk_eval_raw(duk_context *ctx, const char *src_buffer, duk_size_t src_length, duk_uint_t flags);
923 DUK_EXTERNAL_DECL duk_int_t duk_compile_raw(duk_context *ctx, const char *src_buffer, duk_size_t src_length, duk_uint_t flags); 1023 DUK_EXTERNAL_DECL duk_int_t duk_compile_raw(duk_context *ctx, const char *src_buffer, duk_size_t src_length, duk_uint_t flags);
924 1024
925 /* plain */ 1025 /* plain */
926 #define duk_eval(ctx) \ 1026 #define duk_eval(ctx) \
927 ((void) duk_eval_raw((ctx), NULL, 0, 2 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOFILENAME)) 1027 ((void) duk_eval_raw((ctx), NULL, 0, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOFILENAME))
928 1028
929 #define duk_eval_noresult(ctx) \ 1029 #define duk_eval_noresult(ctx) \
930 ((void) duk_eval_raw((ctx), NULL, 0, 2 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME)) 1030 ((void) duk_eval_raw((ctx), NULL, 0, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME))
931 1031
932 #define duk_peval(ctx) \ 1032 #define duk_peval(ctx) \
933 (duk_eval_raw((ctx), NULL, 0, 2 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOFILENAME)) 1033 (duk_eval_raw((ctx), NULL, 0, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOFILENAME))
934 1034
935 #define duk_peval_noresult(ctx) \ 1035 #define duk_peval_noresult(ctx) \
936 (duk_eval_raw((ctx), NULL, 0, 2 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME)) 1036 (duk_eval_raw((ctx), NULL, 0, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME))
937 1037
938 #define duk_compile(ctx,flags) \ 1038 #define duk_compile(ctx,flags) \
939 ((void) duk_compile_raw((ctx), NULL, 0, 3 /*args*/ | (flags))) 1039 ((void) duk_compile_raw((ctx), NULL, 0, 2 /*args*/ | (flags)))
940 1040
941 #define duk_pcompile(ctx,flags) \ 1041 #define duk_pcompile(ctx,flags) \
942 (duk_compile_raw((ctx), NULL, 0, 3 /*args*/ | (flags) | DUK_COMPILE_SAFE)) 1042 (duk_compile_raw((ctx), NULL, 0, 2 /*args*/ | (flags) | DUK_COMPILE_SAFE))
943 1043
944 /* string */ 1044 /* string */
945 #define duk_eval_string(ctx,src) \ 1045 #define duk_eval_string(ctx,src) \
946 ((void) duk_eval_raw((ctx), (src), 0, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME)) 1046 ((void) duk_eval_raw((ctx), (src), 0, 0 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME))
947 1047
948 #define duk_eval_string_noresult(ctx,src) \ 1048 #define duk_eval_string_noresult(ctx,src) \
949 ((void) duk_eval_raw((ctx), (src), 0, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME)) 1049 ((void) duk_eval_raw((ctx), (src), 0, 0 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME))
950 1050
951 #define duk_peval_string(ctx,src) \ 1051 #define duk_peval_string(ctx,src) \
952 (duk_eval_raw((ctx), (src), 0, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME)) 1052 (duk_eval_raw((ctx), (src), 0, 0 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME))
953 1053
954 #define duk_peval_string_noresult(ctx,src) \ 1054 #define duk_peval_string_noresult(ctx,src) \
955 (duk_eval_raw((ctx), (src), 0, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME)) 1055 (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))
956 1056
957 #define duk_compile_string(ctx,flags,src) \ 1057 #define duk_compile_string(ctx,flags,src) \
958 ((void) duk_compile_raw((ctx), (src), 0, 1 /*args*/ | (flags) | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME)) 1058 ((void) duk_compile_raw((ctx), (src), 0, 0 /*args*/ | (flags) | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME))
959 1059
960 #define duk_compile_string_filename(ctx,flags,src) \ 1060 #define duk_compile_string_filename(ctx,flags,src) \
961 ((void) duk_compile_raw((ctx), (src), 0, 2 /*args*/ | (flags) | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN)) 1061 ((void) duk_compile_raw((ctx), (src), 0, 1 /*args*/ | (flags) | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN))
962 1062
963 #define duk_pcompile_string(ctx,flags,src) \ 1063 #define duk_pcompile_string(ctx,flags,src) \
964 (duk_compile_raw((ctx), (src), 0, 1 /*args*/ | (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME)) 1064 (duk_compile_raw((ctx), (src), 0, 0 /*args*/ | (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME))
965 1065
966 #define duk_pcompile_string_filename(ctx,flags,src) \ 1066 #define duk_pcompile_string_filename(ctx,flags,src) \
967 (duk_compile_raw((ctx), (src), 0, 2 /*args*/ | (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN)) 1067 (duk_compile_raw((ctx), (src), 0, 1 /*args*/ | (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN))
968 1068
969 /* lstring */ 1069 /* lstring */
970 #define duk_eval_lstring(ctx,buf,len) \ 1070 #define duk_eval_lstring(ctx,buf,len) \
971 ((void) duk_eval_raw((ctx), buf, len, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NOFILENAME)) 1071 ((void) duk_eval_raw((ctx), buf, len, 0 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NOFILENAME))
972 1072
973 #define duk_eval_lstring_noresult(ctx,buf,len) \ 1073 #define duk_eval_lstring_noresult(ctx,buf,len) \
974 ((void) duk_eval_raw((ctx), buf, len, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME)) 1074 ((void) duk_eval_raw((ctx), buf, len, 0 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME))
975 1075
976 #define duk_peval_lstring(ctx,buf,len) \ 1076 #define duk_peval_lstring(ctx,buf,len) \
977 (duk_eval_raw((ctx), buf, len, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_SAFE | DUK_COMPILE_NOFILENAME)) 1077 (duk_eval_raw((ctx), buf, len, 0 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_SAFE | DUK_COMPILE_NOFILENAME))
978 1078
979 #define duk_peval_lstring_noresult(ctx,buf,len) \ 1079 #define duk_peval_lstring_noresult(ctx,buf,len) \
980 (duk_eval_raw((ctx), buf, len, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME)) 1080 (duk_eval_raw((ctx), buf, len, 0 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME))
981 1081
982 #define duk_compile_lstring(ctx,flags,buf,len) \ 1082 #define duk_compile_lstring(ctx,flags,buf,len) \
983 ((void) duk_compile_raw((ctx), buf, len, 1 /*args*/ | (flags) | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NOFILENAME)) 1083 ((void) duk_compile_raw((ctx), buf, len, 0 /*args*/ | (flags) | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NOFILENAME))
984 1084
985 #define duk_compile_lstring_filename(ctx,flags,buf,len) \ 1085 #define duk_compile_lstring_filename(ctx,flags,buf,len) \
986 ((void) duk_compile_raw((ctx), buf, len, 2 /*args*/ | (flags) | DUK_COMPILE_NOSOURCE)) 1086 ((void) duk_compile_raw((ctx), buf, len, 1 /*args*/ | (flags) | DUK_COMPILE_NOSOURCE))
987 1087
988 #define duk_pcompile_lstring(ctx,flags,buf,len) \ 1088 #define duk_pcompile_lstring(ctx,flags,buf,len) \
989 (duk_compile_raw((ctx), buf, len, 1 /*args*/ | (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NOFILENAME)) 1089 (duk_compile_raw((ctx), buf, len, 0 /*args*/ | (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NOFILENAME))
990 1090
991 #define duk_pcompile_lstring_filename(ctx,flags,buf,len) \ 1091 #define duk_pcompile_lstring_filename(ctx,flags,buf,len) \
992 (duk_compile_raw((ctx), buf, len, 2 /*args*/ | (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE)) 1092 (duk_compile_raw((ctx), buf, len, 1 /*args*/ | (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE))
993
994 /* file */
995 #define duk_eval_file(ctx,path) \
996 ((void) duk_push_string_file_raw((ctx), (path), 0), \
997 (void) duk_push_string((ctx), (path)), \
998 (void) duk_eval_raw((ctx), NULL, 0, 3 /*args*/ | DUK_COMPILE_EVAL))
999
1000 #define duk_eval_file_noresult(ctx,path) \
1001 ((void) duk_push_string_file_raw((ctx), (path), 0), \
1002 (void) duk_push_string((ctx), (path)), \
1003 (void) duk_eval_raw((ctx), NULL, 0, 3 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NORESULT))
1004
1005 #define duk_peval_file(ctx,path) \
1006 ((void) duk_push_string_file_raw((ctx), (path), DUK_STRING_PUSH_SAFE), \
1007 (void) duk_push_string((ctx), (path)), \
1008 duk_eval_raw((ctx), NULL, 0, 3 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE))
1009
1010 #define duk_peval_file_noresult(ctx,path) \
1011 ((void) duk_push_string_file_raw((ctx), (path), DUK_STRING_PUSH_SAFE), \
1012 (void) duk_push_string((ctx), (path)), \
1013 duk_eval_raw((ctx), NULL, 0, 3 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NORESULT))
1014
1015 #define duk_compile_file(ctx,flags,path) \
1016 ((void) duk_push_string_file_raw((ctx), (path), 0), \
1017 (void) duk_push_string((ctx), (path)), \
1018 (void) duk_compile_raw((ctx), NULL, 0, 3 /*args*/ | (flags)))
1019
1020 #define duk_pcompile_file(ctx,flags,path) \
1021 ((void) duk_push_string_file_raw((ctx), (path), DUK_STRING_PUSH_SAFE), \
1022 (void) duk_push_string((ctx), (path)), \
1023 duk_compile_raw((ctx), NULL, 0, 3 /*args*/ | (flags) | DUK_COMPILE_SAFE))
1024 1093
1025 /* 1094 /*
1026 * Bytecode load/dump 1095 * Bytecode load/dump
1027 */ 1096 */
1028 1097
1029 DUK_EXTERNAL_DECL void duk_dump_function(duk_context *ctx); 1098 DUK_EXTERNAL_DECL void duk_dump_function(duk_context *ctx);
1030 DUK_EXTERNAL_DECL void duk_load_function(duk_context *ctx); 1099 DUK_EXTERNAL_DECL void duk_load_function(duk_context *ctx);
1031 1100
1032 /* 1101 /*
1033 * Logging
1034 */
1035
1036 DUK_EXTERNAL_DECL void duk_log(duk_context *ctx, duk_int_t level, const char *fmt, ...);
1037 DUK_EXTERNAL_DECL void duk_log_va(duk_context *ctx, duk_int_t level, const char *fmt, va_list ap);
1038
1039 /*
1040 * Debugging 1102 * Debugging
1041 */ 1103 */
1042 1104
1043 DUK_EXTERNAL_DECL void duk_push_context_dump(duk_context *ctx); 1105 DUK_EXTERNAL_DECL void duk_push_context_dump(duk_context *ctx);
1044 1106
1045 #if defined(DUK_USE_FILE_IO)
1046 /* internal use */
1047 #define duk_dump_context_filehandle(ctx,fh) \
1048 (duk_push_context_dump((ctx)), \
1049 DUK_FPRINTF((fh), "%s\n", duk_safe_to_string(ctx, -1)), \
1050 duk_pop(ctx))
1051
1052 /* external use */
1053 #define duk_dump_context_stdout(ctx) \
1054 duk_dump_context_filehandle((ctx), DUK_STDOUT)
1055 #define duk_dump_context_stderr(ctx) \
1056 duk_dump_context_filehandle((ctx), DUK_STDERR)
1057 #else /* DUK_USE_FILE_IO */
1058 #define duk_dump_context_stdout(ctx) ((void) 0)
1059 #define duk_dump_context_stderr(ctx) ((void) 0)
1060 #endif /* DUK_USE_FILE_IO */
1061
1062 /* 1107 /*
1063 * Debugger (debug protocol) 1108 * Debugger (debug protocol)
1064 */ 1109 */
1065 1110
1066 #define duk_debugger_attach(ctx,read_cb,write_cb,peek_cb,read_flush_cb,write_flush_cb,detached_cb,udata) \ 1111 DUK_EXTERNAL_DECL void duk_debugger_attach(duk_context *ctx,
1067 duk_debugger_attach_custom((ctx), (read_cb), (write_cb), (peek_cb), (read_flush_cb), (write_flush_cb), \ 1112 duk_debug_read_function read_cb,
1068 NULL, (detached_cb), (udata)) 1113 duk_debug_write_function write_cb,
1069 1114 duk_debug_peek_function peek_cb,
1070 DUK_EXTERNAL_DECL void duk_debugger_attach_custom(duk_context *ctx, 1115 duk_debug_read_flush_function read_flush_cb,
1071 duk_debug_read_function read_cb, 1116 duk_debug_write_flush_function write_flush_cb,
1072 duk_debug_write_function write_cb, 1117 duk_debug_request_function request_cb,
1073 duk_debug_peek_function peek_cb, 1118 duk_debug_detached_function detached_cb,
1074 duk_debug_read_flush_function read_flush_cb, 1119 void *udata);
1075 duk_debug_write_flush_function write_flush_cb,
1076 duk_debug_request_function request_cb,
1077 duk_debug_detached_function detached_cb,
1078 void *udata);
1079 DUK_EXTERNAL_DECL void duk_debugger_detach(duk_context *ctx); 1120 DUK_EXTERNAL_DECL void duk_debugger_detach(duk_context *ctx);
1080 DUK_EXTERNAL_DECL void duk_debugger_cooperate(duk_context *ctx); 1121 DUK_EXTERNAL_DECL void duk_debugger_cooperate(duk_context *ctx);
1081 DUK_EXTERNAL_DECL duk_bool_t duk_debugger_notify(duk_context *ctx, duk_idx_t nvalues); 1122 DUK_EXTERNAL_DECL duk_bool_t duk_debugger_notify(duk_context *ctx, duk_idx_t nvalues);
1082 DUK_EXTERNAL_DECL void duk_debugger_pause(duk_context *ctx); 1123 DUK_EXTERNAL_DECL void duk_debugger_pause(duk_context *ctx);
1124
1125 /*
1126 * Time handling
1127 */
1128
1129 DUK_EXTERNAL_DECL duk_double_t duk_get_now(duk_context *ctx);
1130 DUK_EXTERNAL_DECL void duk_time_to_components(duk_context *ctx, duk_double_t timeval, duk_time_components *comp);
1131 DUK_EXTERNAL_DECL duk_double_t duk_components_to_time(duk_context *ctx, duk_time_components *comp);
1083 1132
1084 /* 1133 /*
1085 * Date provider related constants 1134 * Date provider related constants
1086 * 1135 *
1087 * NOTE: These are "semi public" - you should only use these if you write 1136 * NOTE: These are "semi public" - you should only use these if you write
1115 * to DUK_DATE_IDX_MILLISECOND matches argument ordering of Ecmascript API 1164 * to DUK_DATE_IDX_MILLISECOND matches argument ordering of Ecmascript API
1116 * calls (like Date constructor call). Some functions in duk_bi_date.c 1165 * calls (like Date constructor call). Some functions in duk_bi_date.c
1117 * depend on the specific ordering, so change with care. 16 bits are not 1166 * depend on the specific ordering, so change with care. 16 bits are not
1118 * enough for all parts (year, specifically). 1167 * enough for all parts (year, specifically).
1119 * 1168 *
1120 * (Must be in-sync with genbuiltins.py.) 1169 * Must be in-sync with genbuiltins.py.
1121 */ 1170 */
1122 #define DUK_DATE_IDX_YEAR 0 /* year */ 1171 #define DUK_DATE_IDX_YEAR 0 /* year */
1123 #define DUK_DATE_IDX_MONTH 1 /* month: 0 to 11 */ 1172 #define DUK_DATE_IDX_MONTH 1 /* month: 0 to 11 */
1124 #define DUK_DATE_IDX_DAY 2 /* day within month: 0 to 30 */ 1173 #define DUK_DATE_IDX_DAY 2 /* day within month: 0 to 30 */
1125 #define DUK_DATE_IDX_HOUR 3 1174 #define DUK_DATE_IDX_HOUR 3
1127 #define DUK_DATE_IDX_SECOND 5 1176 #define DUK_DATE_IDX_SECOND 5
1128 #define DUK_DATE_IDX_MILLISECOND 6 1177 #define DUK_DATE_IDX_MILLISECOND 6
1129 #define DUK_DATE_IDX_WEEKDAY 7 /* weekday: 0 to 6, 0=sunday, 1=monday, etc */ 1178 #define DUK_DATE_IDX_WEEKDAY 7 /* weekday: 0 to 6, 0=sunday, 1=monday, etc */
1130 #define DUK_DATE_IDX_NUM_PARTS 8 1179 #define DUK_DATE_IDX_NUM_PARTS 8
1131 1180
1132 /* Internal API call flags, used for various functions in this file. 1181 /* Internal API call flags, used for various functions in duk_bi_date.c.
1133 * Certain flags are used by only certain functions, but since the flags 1182 * Certain flags are used by only certain functions, but since the flags
1134 * don't overlap, a single flags value can be passed around to multiple 1183 * don't overlap, a single flags value can be passed around to multiple
1135 * functions. 1184 * functions.
1136 * 1185 *
1137 * The unused top bits of the flags field are also used to pass values 1186 * The unused top bits of the flags field are also used to pass values
1138 * to helpers (duk__get_part_helper() and duk__set_part_helper()). 1187 * to helpers (duk__get_part_helper() and duk__set_part_helper()).
1139 * 1188 *
1140 * (Must be in-sync with genbuiltins.py.) 1189 * Must be in-sync with genbuiltins.py.
1141 */ 1190 */
1142 1191
1143 /* NOTE: when writing a Date provider you only need a few specific 1192 /* NOTE: when writing a Date provider you only need a few specific
1144 * flags from here, the rest are internal. Avoid using anything you 1193 * flags from here, the rest are internal. Avoid using anything you
1145 * don't need. 1194 * don't need.
1172 1221
1173 /* 1222 /*
1174 * C++ name mangling 1223 * C++ name mangling
1175 */ 1224 */
1176 1225
1177 #ifdef __cplusplus 1226 #if defined(__cplusplus)
1178 /* end 'extern "C"' wrapper */ 1227 /* end 'extern "C"' wrapper */
1179 } 1228 }
1180 #endif 1229 #endif
1181 1230
1182 #endif /* DUK_API_PUBLIC_H_INCLUDED */ 1231 #endif /* DUK_API_PUBLIC_H_INCLUDED */
1233 * For instance, on X86 a FLD + FSTP may convert a signaling NaN to a 1282 * For instance, on X86 a FLD + FSTP may convert a signaling NaN to a
1234 * quiet one. This is catastrophic when NaN space is used in packed 1283 * quiet one. This is catastrophic when NaN space is used in packed
1235 * duk_tval values. See: misc/clang_aliasing.c. 1284 * duk_tval values. See: misc/clang_aliasing.c.
1236 */ 1285 */
1237 1286
1238 #ifndef DUK_DBLUNION_H_INCLUDED 1287 #if !defined(DUK_DBLUNION_H_INCLUDED)
1239 #define DUK_DBLUNION_H_INCLUDED 1288 #define DUK_DBLUNION_H_INCLUDED
1240 1289
1241 /* 1290 /*
1242 * Union for accessing double parts, also serves as packed duk_tval 1291 * Union for accessing double parts, also serves as packed duk_tval
1243 */ 1292 */
1261 /* 1310 /*
1262 * Indexes of various types with respect to big endian (logical) layout 1311 * Indexes of various types with respect to big endian (logical) layout
1263 */ 1312 */
1264 1313
1265 #if defined(DUK_USE_DOUBLE_LE) 1314 #if defined(DUK_USE_DOUBLE_LE)
1266 #ifdef DUK_USE_64BIT_OPS 1315 #if defined(DUK_USE_64BIT_OPS)
1267 #define DUK_DBL_IDX_ULL0 0 1316 #define DUK_DBL_IDX_ULL0 0
1268 #endif 1317 #endif
1269 #define DUK_DBL_IDX_UI0 1 1318 #define DUK_DBL_IDX_UI0 1
1270 #define DUK_DBL_IDX_UI1 0 1319 #define DUK_DBL_IDX_UI1 0
1271 #define DUK_DBL_IDX_US0 3 1320 #define DUK_DBL_IDX_US0 3
1281 #define DUK_DBL_IDX_UC6 1 1330 #define DUK_DBL_IDX_UC6 1
1282 #define DUK_DBL_IDX_UC7 0 1331 #define DUK_DBL_IDX_UC7 0
1283 #define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ 1332 #define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */
1284 #define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ 1333 #define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */
1285 #elif defined(DUK_USE_DOUBLE_BE) 1334 #elif defined(DUK_USE_DOUBLE_BE)
1286 #ifdef DUK_USE_64BIT_OPS 1335 #if defined(DUK_USE_64BIT_OPS)
1287 #define DUK_DBL_IDX_ULL0 0 1336 #define DUK_DBL_IDX_ULL0 0
1288 #endif 1337 #endif
1289 #define DUK_DBL_IDX_UI0 0 1338 #define DUK_DBL_IDX_UI0 0
1290 #define DUK_DBL_IDX_UI1 1 1339 #define DUK_DBL_IDX_UI1 1
1291 #define DUK_DBL_IDX_US0 0 1340 #define DUK_DBL_IDX_US0 0
1301 #define DUK_DBL_IDX_UC6 6 1350 #define DUK_DBL_IDX_UC6 6
1302 #define DUK_DBL_IDX_UC7 7 1351 #define DUK_DBL_IDX_UC7 7
1303 #define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ 1352 #define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */
1304 #define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ 1353 #define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */
1305 #elif defined(DUK_USE_DOUBLE_ME) 1354 #elif defined(DUK_USE_DOUBLE_ME)
1306 #ifdef DUK_USE_64BIT_OPS 1355 #if defined(DUK_USE_64BIT_OPS)
1307 #define DUK_DBL_IDX_ULL0 0 /* not directly applicable, byte order differs from a double */ 1356 #define DUK_DBL_IDX_ULL0 0 /* not directly applicable, byte order differs from a double */
1308 #endif 1357 #endif
1309 #define DUK_DBL_IDX_UI0 0 1358 #define DUK_DBL_IDX_UI0 0
1310 #define DUK_DBL_IDX_UI1 1 1359 #define DUK_DBL_IDX_UI1 1
1311 #define DUK_DBL_IDX_US0 1 1360 #define DUK_DBL_IDX_US0 1
1337 1386
1338 #define DUK_DBLUNION_SET_HIGH32(u,v) do { \ 1387 #define DUK_DBLUNION_SET_HIGH32(u,v) do { \
1339 (u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) (v); \ 1388 (u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) (v); \
1340 } while (0) 1389 } while (0)
1341 1390
1342 #ifdef DUK_USE_64BIT_OPS 1391 #if defined(DUK_USE_64BIT_OPS)
1343 #ifdef DUK_USE_DOUBLE_ME 1392 #if defined(DUK_USE_DOUBLE_ME)
1344 #define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \ 1393 #define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \
1345 (u)->ull[DUK_DBL_IDX_ULL0] = (duk_uint64_t) (v); \ 1394 (u)->ull[DUK_DBL_IDX_ULL0] = (duk_uint64_t) (v); \
1346 } while (0) 1395 } while (0)
1347 #else 1396 #else
1348 #define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \ 1397 #define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \
1362 1411
1363 #define DUK_DBLUNION_GET_DOUBLE(u) ((u)->d) 1412 #define DUK_DBLUNION_GET_DOUBLE(u) ((u)->d)
1364 #define DUK_DBLUNION_GET_HIGH32(u) ((u)->ui[DUK_DBL_IDX_UI0]) 1413 #define DUK_DBLUNION_GET_HIGH32(u) ((u)->ui[DUK_DBL_IDX_UI0])
1365 #define DUK_DBLUNION_GET_LOW32(u) ((u)->ui[DUK_DBL_IDX_UI1]) 1414 #define DUK_DBLUNION_GET_LOW32(u) ((u)->ui[DUK_DBL_IDX_UI1])
1366 1415
1367 #ifdef DUK_USE_64BIT_OPS 1416 #if defined(DUK_USE_64BIT_OPS)
1368 #ifdef DUK_USE_DOUBLE_ME 1417 #if defined(DUK_USE_DOUBLE_ME)
1369 #define DUK_DBLUNION_SET_UINT64(u,v) do { \ 1418 #define DUK_DBLUNION_SET_UINT64(u,v) do { \
1370 (u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) ((v) >> 32); \ 1419 (u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) ((v) >> 32); \
1371 (u)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) (v); \ 1420 (u)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) (v); \
1372 } while (0) 1421 } while (0)
1373 #define DUK_DBLUNION_GET_UINT64(u) \ 1422 #define DUK_DBLUNION_GET_UINT64(u) \
1403 * 1452 *
1404 * The ME variant below is specifically for ARM byte order, which has the 1453 * The ME variant below is specifically for ARM byte order, which has the
1405 * feature that while doubles have a mixed byte order (32107654), unsigned 1454 * feature that while doubles have a mixed byte order (32107654), unsigned
1406 * long long values has a little endian byte order (76543210). When writing 1455 * long long values has a little endian byte order (76543210). When writing
1407 * a logical double value through a ULL pointer, the 32-bit words need to be 1456 * a logical double value through a ULL pointer, the 32-bit words need to be
1408 * swapped; hence the #ifdefs below for ULL writes with DUK_USE_DOUBLE_ME. 1457 * swapped; hence the #if defined()s below for ULL writes with DUK_USE_DOUBLE_ME.
1409 * This is not full ARM support but suffices for some environments. 1458 * This is not full ARM support but suffices for some environments.
1410 */ 1459 */
1411 1460
1412 #ifdef DUK_USE_64BIT_OPS 1461 #if defined(DUK_USE_64BIT_OPS)
1413 #ifdef DUK_USE_DOUBLE_ME 1462 #if defined(DUK_USE_DOUBLE_ME)
1463 /* Macros for 64-bit ops + mixed endian doubles. */
1414 #define DUK__DBLUNION_SET_NAN_FULL(u) do { \ 1464 #define DUK__DBLUNION_SET_NAN_FULL(u) do { \
1415 (u)->ull[DUK_DBL_IDX_ULL0] = 0x000000007ff80000ULL; \ 1465 (u)->ull[DUK_DBL_IDX_ULL0] = 0x000000007ff80000ULL; \
1416 } while (0) 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)
1417 #else 1484 #else
1485 /* Macros for 64-bit ops + big/little endian doubles. */
1418 #define DUK__DBLUNION_SET_NAN_FULL(u) do { \ 1486 #define DUK__DBLUNION_SET_NAN_FULL(u) do { \
1419 (u)->ull[DUK_DBL_IDX_ULL0] = 0x7ff8000000000000ULL; \ 1487 (u)->ull[DUK_DBL_IDX_ULL0] = 0x7ff8000000000000ULL; \
1420 } while (0) 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)
1421 #endif 1506 #endif
1422 #else /* DUK_USE_64BIT_OPS */ 1507 #else /* DUK_USE_64BIT_OPS */
1508 /* Macros for no 64-bit ops, any endianness. */
1423 #define DUK__DBLUNION_SET_NAN_FULL(u) do { \ 1509 #define DUK__DBLUNION_SET_NAN_FULL(u) do { \
1424 (u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) 0x7ff80000UL; \ 1510 (u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) 0x7ff80000UL; \
1425 (u)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) 0x00000000UL; \ 1511 (u)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) 0x00000000UL; \
1426 } while (0) 1512 } while (0)
1427 #endif /* DUK_USE_64BIT_OPS */
1428
1429 #define DUK__DBLUNION_SET_NAN_NOTFULL(u) do { \
1430 (u)->us[DUK_DBL_IDX_US0] = 0x7ff8UL; \
1431 } while (0)
1432
1433 #ifdef DUK_USE_64BIT_OPS
1434 #ifdef DUK_USE_DOUBLE_ME
1435 #define DUK__DBLUNION_IS_NAN_FULL(u) \ 1513 #define DUK__DBLUNION_IS_NAN_FULL(u) \
1436 /* E == 0x7ff, F != 0 => NaN */ \
1437 ((((u)->us[DUK_DBL_IDX_US0] & 0x7ff0UL) == 0x7ff0UL) && \
1438 ((((u)->ull[DUK_DBL_IDX_ULL0]) & 0xffffffff000fffffULL) != 0))
1439 #else
1440 #define DUK__DBLUNION_IS_NAN_FULL(u) \
1441 /* E == 0x7ff, F != 0 => NaN */ \
1442 ((((u)->us[DUK_DBL_IDX_US0] & 0x7ff0UL) == 0x7ff0UL) && \
1443 ((((u)->ull[DUK_DBL_IDX_ULL0]) & 0x000fffffffffffffULL) != 0))
1444 #endif
1445 #else /* DUK_USE_64BIT_OPS */
1446 #define DUK__DBLUNION_IS_NAN_FULL(u) \
1447 /* E == 0x7ff, F != 0 => NaN */ \
1448 ((((u)->ui[DUK_DBL_IDX_UI0] & 0x7ff00000UL) == 0x7ff00000UL) && \ 1514 ((((u)->ui[DUK_DBL_IDX_UI0] & 0x7ff00000UL) == 0x7ff00000UL) && \
1449 (((u)->ui[DUK_DBL_IDX_UI0] & 0x000fffffUL) != 0 || \ 1515 (((u)->ui[DUK_DBL_IDX_UI0] & 0x000fffffUL) != 0 || \
1450 (u)->ui[DUK_DBL_IDX_UI1] != 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))
1451 #endif /* DUK_USE_64BIT_OPS */ 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)
1452 1543
1453 #define DUK__DBLUNION_IS_NAN_NOTFULL(u) \ 1544 #define DUK__DBLUNION_IS_NAN_NOTFULL(u) \
1454 /* E == 0x7ff, topmost four bits of F != 0 => assume NaN */ \ 1545 /* E == 0x7ff, topmost four bits of F != 0 => assume NaN */ \
1455 ((((u)->us[DUK_DBL_IDX_US0] & 0x7ff0UL) == 0x7ff0UL) && \ 1546 ((((u)->us[DUK_DBL_IDX_US0] & 0x7ff0UL) == 0x7ff0UL) && \
1456 (((u)->us[DUK_DBL_IDX_US0] & 0x000fUL) != 0x0000UL)) 1547 (((u)->us[DUK_DBL_IDX_US0] & 0x000fUL) != 0x0000UL))
1457
1458 #ifdef DUK_USE_64BIT_OPS
1459 #ifdef DUK_USE_DOUBLE_ME
1460 #define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \
1461 ((u)->ull[DUK_DBL_IDX_ULL0] == 0x000000007ff80000ULL)
1462 #else
1463 #define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \
1464 ((u)->ull[DUK_DBL_IDX_ULL0] == 0x7ff8000000000000ULL)
1465 #endif
1466 #else /* DUK_USE_64BIT_OPS */
1467 #define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \
1468 (((u)->ui[DUK_DBL_IDX_UI0] == 0x7ff80000UL) && \
1469 ((u)->ui[DUK_DBL_IDX_UI1] == 0x00000000UL))
1470 #endif /* DUK_USE_64BIT_OPS */
1471 1548
1472 #define DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL(u) \ 1549 #define DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL(u) \
1473 /* E == 0x7ff, F == 8 => normalized NaN */ \ 1550 /* E == 0x7ff, F == 8 => normalized NaN */ \
1474 ((u)->us[DUK_DBL_IDX_US0] == 0x7ff8UL) 1551 ((u)->us[DUK_DBL_IDX_US0] == 0x7ff8UL)
1475 1552
1506 #define DUK_DBLUNION_IS_NORMALIZED(u) \ 1583 #define DUK_DBLUNION_IS_NORMALIZED(u) \
1507 (!DUK_DBLUNION_IS_NAN((u)) || /* either not a NaN */ \ 1584 (!DUK_DBLUNION_IS_NAN((u)) || /* either not a NaN */ \
1508 DUK_DBLUNION_IS_NORMALIZED_NAN((u))) /* or is a normalized NaN */ 1585 DUK_DBLUNION_IS_NORMALIZED_NAN((u))) /* or is a normalized NaN */
1509 #else /* DUK_USE_PACKED_TVAL */ 1586 #else /* DUK_USE_PACKED_TVAL */
1510 #define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) /* nop: no need to normalize */ 1587 #define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) /* nop: no need to normalize */
1511 #define DUK_DBLUNION_IS_NAN(u) (DUK_ISNAN((u)->d)) 1588 #define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) /* (DUK_ISNAN((u)->d)) */
1512 #define DUK_DBLUNION_IS_NORMALIZED_NAN(u) (DUK_ISNAN((u)->d)) 1589 #define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) /* (DUK_ISNAN((u)->d)) */
1513 #define DUK_DBLUNION_IS_NORMALIZED(u) 1 /* all doubles are considered normalized */ 1590 #define DUK_DBLUNION_IS_NORMALIZED(u) 1 /* all doubles are considered normalized */
1514 #define DUK_DBLUNION_SET_NAN(u) do { \ 1591 #define DUK_DBLUNION_SET_NAN(u) do { \
1515 /* in non-packed representation we don't care about which NaN is used */ \ 1592 /* in non-packed representation we don't care about which NaN is used */ \
1516 (u)->d = DUK_DOUBLE_NAN; \ 1593 (u)->d = DUK_DOUBLE_NAN; \
1517 } while (0) 1594 } while (0)
1518 #endif /* DUK_USE_PACKED_TVAL */ 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))
1519 1604
1520 /* XXX: native 64-bit byteswaps when available */ 1605 /* XXX: native 64-bit byteswaps when available */
1521 1606
1522 /* 64-bit byteswap, same operation independent of target endianness. */ 1607 /* 64-bit byteswap, same operation independent of target endianness. */
1523 #define DUK_DBLUNION_BSWAP64(u) do { \ 1608 #define DUK_DBLUNION_BSWAP64(u) do { \
1560 #endif 1645 #endif
1561 1646
1562 /* Reverse operation is the same. */ 1647 /* Reverse operation is the same. */
1563 #define DUK_DBLUNION_DOUBLE_NTOH(u) DUK_DBLUNION_DOUBLE_HTON((u)) 1648 #define DUK_DBLUNION_DOUBLE_NTOH(u) DUK_DBLUNION_DOUBLE_HTON((u))
1564 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
1565 #endif /* DUK_DBLUNION_H_INCLUDED */ 1659 #endif /* DUK_DBLUNION_H_INCLUDED */
1566 1660
1567 #endif /* DUKTAPE_H_INCLUDED */ 1661 #endif /* DUKTAPE_H_INCLUDED */