http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/ede68a10/thirdparty/civetweb-1.10/src/third_party/duktape-1.5.2/src-separate/duk_hobject.h ---------------------------------------------------------------------- diff --git a/thirdparty/civetweb-1.10/src/third_party/duktape-1.5.2/src-separate/duk_hobject.h b/thirdparty/civetweb-1.10/src/third_party/duktape-1.5.2/src-separate/duk_hobject.h deleted file mode 100644 index 4127e0e..0000000 --- a/thirdparty/civetweb-1.10/src/third_party/duktape-1.5.2/src-separate/duk_hobject.h +++ /dev/null @@ -1,926 +0,0 @@ -/* - * Heap object representation. - * - * Heap objects are used for Ecmascript objects, arrays, and functions, - * but also for internal control like declarative and object environment - * records. Compiled functions, native functions, and threads are also - * objects but with an extended C struct. - * - * Objects provide the required Ecmascript semantics and exotic behaviors - * especially for property access. - * - * Properties are stored in three conceptual parts: - * - * 1. A linear 'entry part' contains ordered key-value-attributes triples - * and is the main method of string properties. - * - * 2. An optional linear 'array part' is used for array objects to store a - * (dense) range of [0,N[ array indexed entries with default attributes - * (writable, enumerable, configurable). If the array part would become - * sparse or non-default attributes are required, the array part is - * abandoned and moved to the 'entry part'. - * - * 3. An optional 'hash part' is used to optimize lookups of the entry - * part; it is used only for objects with sufficiently many properties - * and can be abandoned without loss of information. - * - * These three conceptual parts are stored in a single memory allocated area. - * This minimizes memory allocation overhead but also means that all three - * parts are resized together, and makes property access a bit complicated. - */ - -#ifndef DUK_HOBJECT_H_INCLUDED -#define DUK_HOBJECT_H_INCLUDED - -/* Object flag. There are currently 26 flag bits available. Make sure - * this stays in sync with debugger object inspection code. - */ -#define DUK_HOBJECT_FLAG_EXTENSIBLE DUK_HEAPHDR_USER_FLAG(0) /* object is extensible */ -#define DUK_HOBJECT_FLAG_CONSTRUCTABLE DUK_HEAPHDR_USER_FLAG(1) /* object is constructable */ -#define DUK_HOBJECT_FLAG_BOUND DUK_HEAPHDR_USER_FLAG(2) /* object established using Function.prototype.bind() */ -#define DUK_HOBJECT_FLAG_COMPILEDFUNCTION DUK_HEAPHDR_USER_FLAG(4) /* object is a compiled function (duk_hcompiledfunction) */ -#define DUK_HOBJECT_FLAG_NATIVEFUNCTION DUK_HEAPHDR_USER_FLAG(5) /* object is a native function (duk_hnativefunction) */ -#define DUK_HOBJECT_FLAG_BUFFEROBJECT DUK_HEAPHDR_USER_FLAG(6) /* object is a buffer object (duk_hbufferobject) (always exotic) */ -#define DUK_HOBJECT_FLAG_THREAD DUK_HEAPHDR_USER_FLAG(7) /* object is a thread (duk_hthread) */ -#define DUK_HOBJECT_FLAG_ARRAY_PART DUK_HEAPHDR_USER_FLAG(8) /* object has an array part (a_size may still be 0) */ -#define DUK_HOBJECT_FLAG_STRICT DUK_HEAPHDR_USER_FLAG(9) /* function: function object is strict */ -#define DUK_HOBJECT_FLAG_NOTAIL DUK_HEAPHDR_USER_FLAG(10) /* function: function must not be tail called */ -#define DUK_HOBJECT_FLAG_NEWENV DUK_HEAPHDR_USER_FLAG(11) /* function: create new environment when called (see duk_hcompiledfunction) */ -#define DUK_HOBJECT_FLAG_NAMEBINDING DUK_HEAPHDR_USER_FLAG(12) /* function: create binding for func name (function templates only, used for named function expressions) */ -#define DUK_HOBJECT_FLAG_CREATEARGS DUK_HEAPHDR_USER_FLAG(13) /* function: create an arguments object on function call */ -#define DUK_HOBJECT_FLAG_ENVRECCLOSED DUK_HEAPHDR_USER_FLAG(14) /* envrec: (declarative) record is closed */ -#define DUK_HOBJECT_FLAG_EXOTIC_ARRAY DUK_HEAPHDR_USER_FLAG(15) /* 'Array' object, array length and index exotic behavior */ -#define DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ DUK_HEAPHDR_USER_FLAG(16) /* 'String' object, array index exotic behavior */ -#define DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS DUK_HEAPHDR_USER_FLAG(17) /* 'Arguments' object and has arguments exotic behavior (non-strict callee) */ -#define DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC DUK_HEAPHDR_USER_FLAG(18) /* Duktape/C (nativefunction) object, exotic 'length' */ -#define DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ DUK_HEAPHDR_USER_FLAG(19) /* 'Proxy' object */ - -#define DUK_HOBJECT_FLAG_CLASS_BASE DUK_HEAPHDR_USER_FLAG_NUMBER(20) -#define DUK_HOBJECT_FLAG_CLASS_BITS 5 - -#define DUK_HOBJECT_GET_CLASS_NUMBER(h) \ - DUK_HEAPHDR_GET_FLAG_RANGE(&(h)->hdr, DUK_HOBJECT_FLAG_CLASS_BASE, DUK_HOBJECT_FLAG_CLASS_BITS) -#define DUK_HOBJECT_SET_CLASS_NUMBER(h,v) \ - DUK_HEAPHDR_SET_FLAG_RANGE(&(h)->hdr, DUK_HOBJECT_FLAG_CLASS_BASE, DUK_HOBJECT_FLAG_CLASS_BITS, (v)) - -#define DUK_HOBJECT_GET_CLASS_MASK(h) \ - (1UL << DUK_HEAPHDR_GET_FLAG_RANGE(&(h)->hdr, DUK_HOBJECT_FLAG_CLASS_BASE, DUK_HOBJECT_FLAG_CLASS_BITS)) - -/* Macro for creating flag initializer from a class number. - * Unsigned type cast is needed to avoid warnings about coercing - * a signed integer to an unsigned one; the largest class values - * have the highest bit (bit 31) set which causes this. - */ -#define DUK_HOBJECT_CLASS_AS_FLAGS(v) (((duk_uint_t) (v)) << DUK_HOBJECT_FLAG_CLASS_BASE) - -/* E5 Section 8.6.2 + custom classes */ -#define DUK_HOBJECT_CLASS_UNUSED 0 -#define DUK_HOBJECT_CLASS_ARGUMENTS 1 -#define DUK_HOBJECT_CLASS_ARRAY 2 -#define DUK_HOBJECT_CLASS_BOOLEAN 3 -#define DUK_HOBJECT_CLASS_DATE 4 -#define DUK_HOBJECT_CLASS_ERROR 5 -#define DUK_HOBJECT_CLASS_FUNCTION 6 -#define DUK_HOBJECT_CLASS_JSON 7 -#define DUK_HOBJECT_CLASS_MATH 8 -#define DUK_HOBJECT_CLASS_NUMBER 9 -#define DUK_HOBJECT_CLASS_OBJECT 10 -#define DUK_HOBJECT_CLASS_REGEXP 11 -#define DUK_HOBJECT_CLASS_STRING 12 -#define DUK_HOBJECT_CLASS_GLOBAL 13 -#define DUK_HOBJECT_CLASS_OBJENV 14 /* custom */ -#define DUK_HOBJECT_CLASS_DECENV 15 /* custom */ -#define DUK_HOBJECT_CLASS_BUFFER 16 /* custom; implies DUK_HOBJECT_IS_BUFFEROBJECT */ -#define DUK_HOBJECT_CLASS_POINTER 17 /* custom */ -#define DUK_HOBJECT_CLASS_THREAD 18 /* custom; implies DUK_HOBJECT_IS_THREAD */ -#define DUK_HOBJECT_CLASS_ARRAYBUFFER 19 /* implies DUK_HOBJECT_IS_BUFFEROBJECT */ -#define DUK_HOBJECT_CLASS_DATAVIEW 20 -#define DUK_HOBJECT_CLASS_INT8ARRAY 21 -#define DUK_HOBJECT_CLASS_UINT8ARRAY 22 -#define DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY 23 -#define DUK_HOBJECT_CLASS_INT16ARRAY 24 -#define DUK_HOBJECT_CLASS_UINT16ARRAY 25 -#define DUK_HOBJECT_CLASS_INT32ARRAY 26 -#define DUK_HOBJECT_CLASS_UINT32ARRAY 27 -#define DUK_HOBJECT_CLASS_FLOAT32ARRAY 28 -#define DUK_HOBJECT_CLASS_FLOAT64ARRAY 29 -#define DUK_HOBJECT_CLASS_MAX 29 - -/* class masks */ -#define DUK_HOBJECT_CMASK_ALL ((1UL << (DUK_HOBJECT_CLASS_MAX + 1)) - 1UL) -#define DUK_HOBJECT_CMASK_UNUSED (1UL << DUK_HOBJECT_CLASS_UNUSED) -#define DUK_HOBJECT_CMASK_ARGUMENTS (1UL << DUK_HOBJECT_CLASS_ARGUMENTS) -#define DUK_HOBJECT_CMASK_ARRAY (1UL << DUK_HOBJECT_CLASS_ARRAY) -#define DUK_HOBJECT_CMASK_BOOLEAN (1UL << DUK_HOBJECT_CLASS_BOOLEAN) -#define DUK_HOBJECT_CMASK_DATE (1UL << DUK_HOBJECT_CLASS_DATE) -#define DUK_HOBJECT_CMASK_ERROR (1UL << DUK_HOBJECT_CLASS_ERROR) -#define DUK_HOBJECT_CMASK_FUNCTION (1UL << DUK_HOBJECT_CLASS_FUNCTION) -#define DUK_HOBJECT_CMASK_JSON (1UL << DUK_HOBJECT_CLASS_JSON) -#define DUK_HOBJECT_CMASK_MATH (1UL << DUK_HOBJECT_CLASS_MATH) -#define DUK_HOBJECT_CMASK_NUMBER (1UL << DUK_HOBJECT_CLASS_NUMBER) -#define DUK_HOBJECT_CMASK_OBJECT (1UL << DUK_HOBJECT_CLASS_OBJECT) -#define DUK_HOBJECT_CMASK_REGEXP (1UL << DUK_HOBJECT_CLASS_REGEXP) -#define DUK_HOBJECT_CMASK_STRING (1UL << DUK_HOBJECT_CLASS_STRING) -#define DUK_HOBJECT_CMASK_GLOBAL (1UL << DUK_HOBJECT_CLASS_GLOBAL) -#define DUK_HOBJECT_CMASK_OBJENV (1UL << DUK_HOBJECT_CLASS_OBJENV) -#define DUK_HOBJECT_CMASK_DECENV (1UL << DUK_HOBJECT_CLASS_DECENV) -#define DUK_HOBJECT_CMASK_BUFFER (1UL << DUK_HOBJECT_CLASS_BUFFER) -#define DUK_HOBJECT_CMASK_POINTER (1UL << DUK_HOBJECT_CLASS_POINTER) -#define DUK_HOBJECT_CMASK_THREAD (1UL << DUK_HOBJECT_CLASS_THREAD) -#define DUK_HOBJECT_CMASK_ARRAYBUFFER (1UL << DUK_HOBJECT_CLASS_ARRAYBUFFER) -#define DUK_HOBJECT_CMASK_DATAVIEW (1UL << DUK_HOBJECT_CLASS_DATAVIEW) -#define DUK_HOBJECT_CMASK_INT8ARRAY (1UL << DUK_HOBJECT_CLASS_INT8ARRAY) -#define DUK_HOBJECT_CMASK_UINT8ARRAY (1UL << DUK_HOBJECT_CLASS_UINT8ARRAY) -#define DUK_HOBJECT_CMASK_UINT8CLAMPEDARRAY (1UL << DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY) -#define DUK_HOBJECT_CMASK_INT16ARRAY (1UL << DUK_HOBJECT_CLASS_INT16ARRAY) -#define DUK_HOBJECT_CMASK_UINT16ARRAY (1UL << DUK_HOBJECT_CLASS_UINT16ARRAY) -#define DUK_HOBJECT_CMASK_INT32ARRAY (1UL << DUK_HOBJECT_CLASS_INT32ARRAY) -#define DUK_HOBJECT_CMASK_UINT32ARRAY (1UL << DUK_HOBJECT_CLASS_UINT32ARRAY) -#define DUK_HOBJECT_CMASK_FLOAT32ARRAY (1UL << DUK_HOBJECT_CLASS_FLOAT32ARRAY) -#define DUK_HOBJECT_CMASK_FLOAT64ARRAY (1UL << DUK_HOBJECT_CLASS_FLOAT64ARRAY) - -#define DUK_HOBJECT_CMASK_ALL_BUFFEROBJECTS \ - (DUK_HOBJECT_CMASK_BUFFER | \ - DUK_HOBJECT_CMASK_ARRAYBUFFER | \ - DUK_HOBJECT_CMASK_DATAVIEW | \ - DUK_HOBJECT_CMASK_INT8ARRAY | \ - DUK_HOBJECT_CMASK_UINT8ARRAY | \ - DUK_HOBJECT_CMASK_UINT8CLAMPEDARRAY | \ - DUK_HOBJECT_CMASK_INT16ARRAY | \ - DUK_HOBJECT_CMASK_UINT16ARRAY | \ - DUK_HOBJECT_CMASK_INT32ARRAY | \ - DUK_HOBJECT_CMASK_UINT32ARRAY | \ - DUK_HOBJECT_CMASK_FLOAT32ARRAY | \ - DUK_HOBJECT_CMASK_FLOAT64ARRAY) - -#define DUK_HOBJECT_IS_OBJENV(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_OBJENV) -#define DUK_HOBJECT_IS_DECENV(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_DECENV) -#define DUK_HOBJECT_IS_ENV(h) (DUK_HOBJECT_IS_OBJENV((h)) || DUK_HOBJECT_IS_DECENV((h))) -#define DUK_HOBJECT_IS_ARRAY(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_ARRAY) -#define DUK_HOBJECT_IS_COMPILEDFUNCTION(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPILEDFUNCTION) -#define DUK_HOBJECT_IS_NATIVEFUNCTION(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATIVEFUNCTION) -#define DUK_HOBJECT_IS_BUFFEROBJECT(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFFEROBJECT) -#define DUK_HOBJECT_IS_THREAD(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_THREAD) - -#define DUK_HOBJECT_IS_NONBOUND_FUNCTION(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, \ - DUK_HOBJECT_FLAG_COMPILEDFUNCTION | \ - DUK_HOBJECT_FLAG_NATIVEFUNCTION) - -#define DUK_HOBJECT_IS_FUNCTION(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, \ - DUK_HOBJECT_FLAG_BOUND | \ - DUK_HOBJECT_FLAG_COMPILEDFUNCTION | \ - DUK_HOBJECT_FLAG_NATIVEFUNCTION) - -#define DUK_HOBJECT_IS_CALLABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, \ - DUK_HOBJECT_FLAG_BOUND | \ - DUK_HOBJECT_FLAG_COMPILEDFUNCTION | \ - DUK_HOBJECT_FLAG_NATIVEFUNCTION) - -/* object has any exotic behavior(s) */ -#define DUK_HOBJECT_EXOTIC_BEHAVIOR_FLAGS (DUK_HOBJECT_FLAG_EXOTIC_ARRAY | \ - DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS | \ - DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | \ - DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC | \ - DUK_HOBJECT_FLAG_BUFFEROBJECT | \ - DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) - -#define DUK_HOBJECT_HAS_EXOTIC_BEHAVIOR(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_EXOTIC_BEHAVIOR_FLAGS) - -#define DUK_HOBJECT_HAS_EXTENSIBLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) -#define DUK_HOBJECT_HAS_CONSTRUCTABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) -#define DUK_HOBJECT_HAS_BOUND(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUND) -#define DUK_HOBJECT_HAS_COMPILEDFUNCTION(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPILEDFUNCTION) -#define DUK_HOBJECT_HAS_NATIVEFUNCTION(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATIVEFUNCTION) -#define DUK_HOBJECT_HAS_BUFFEROBJECT(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFFEROBJECT) -#define DUK_HOBJECT_HAS_THREAD(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_THREAD) -#define DUK_HOBJECT_HAS_ARRAY_PART(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) -#define DUK_HOBJECT_HAS_STRICT(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) -#define DUK_HOBJECT_HAS_NOTAIL(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) -#define DUK_HOBJECT_HAS_NEWENV(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) -#define DUK_HOBJECT_HAS_NAMEBINDING(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) -#define DUK_HOBJECT_HAS_CREATEARGS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) -#define DUK_HOBJECT_HAS_ENVRECCLOSED(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ENVRECCLOSED) -#define DUK_HOBJECT_HAS_EXOTIC_ARRAY(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) -#define DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) -#define DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) -#define DUK_HOBJECT_HAS_EXOTIC_DUKFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC) -#define DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) - -#define DUK_HOBJECT_SET_EXTENSIBLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) -#define DUK_HOBJECT_SET_CONSTRUCTABLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) -#define DUK_HOBJECT_SET_BOUND(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUND) -#define DUK_HOBJECT_SET_COMPILEDFUNCTION(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPILEDFUNCTION) -#define DUK_HOBJECT_SET_NATIVEFUNCTION(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATIVEFUNCTION) -#define DUK_HOBJECT_SET_BUFFEROBJECT(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFFEROBJECT) -#define DUK_HOBJECT_SET_THREAD(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_THREAD) -#define DUK_HOBJECT_SET_ARRAY_PART(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) -#define DUK_HOBJECT_SET_STRICT(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) -#define DUK_HOBJECT_SET_NOTAIL(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) -#define DUK_HOBJECT_SET_NEWENV(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) -#define DUK_HOBJECT_SET_NAMEBINDING(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) -#define DUK_HOBJECT_SET_CREATEARGS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) -#define DUK_HOBJECT_SET_ENVRECCLOSED(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ENVRECCLOSED) -#define DUK_HOBJECT_SET_EXOTIC_ARRAY(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) -#define DUK_HOBJECT_SET_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) -#define DUK_HOBJECT_SET_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) -#define DUK_HOBJECT_SET_EXOTIC_DUKFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC) -#define DUK_HOBJECT_SET_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) - -#define DUK_HOBJECT_CLEAR_EXTENSIBLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) -#define DUK_HOBJECT_CLEAR_CONSTRUCTABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) -#define DUK_HOBJECT_CLEAR_BOUND(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUND) -#define DUK_HOBJECT_CLEAR_COMPILEDFUNCTION(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPILEDFUNCTION) -#define DUK_HOBJECT_CLEAR_NATIVEFUNCTION(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATIVEFUNCTION) -#define DUK_HOBJECT_CLEAR_BUFFEROBJECT(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFFEROBJECT) -#define DUK_HOBJECT_CLEAR_THREAD(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_THREAD) -#define DUK_HOBJECT_CLEAR_ARRAY_PART(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) -#define DUK_HOBJECT_CLEAR_STRICT(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) -#define DUK_HOBJECT_CLEAR_NOTAIL(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) -#define DUK_HOBJECT_CLEAR_NEWENV(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) -#define DUK_HOBJECT_CLEAR_NAMEBINDING(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) -#define DUK_HOBJECT_CLEAR_CREATEARGS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) -#define DUK_HOBJECT_CLEAR_ENVRECCLOSED(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ENVRECCLOSED) -#define DUK_HOBJECT_CLEAR_EXOTIC_ARRAY(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) -#define DUK_HOBJECT_CLEAR_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) -#define DUK_HOBJECT_CLEAR_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) -#define DUK_HOBJECT_CLEAR_EXOTIC_DUKFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC) -#define DUK_HOBJECT_CLEAR_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) - -/* flags used for property attributes in duk_propdesc and packed flags */ -#define DUK_PROPDESC_FLAG_WRITABLE (1 << 0) /* E5 Section 8.6.1 */ -#define DUK_PROPDESC_FLAG_ENUMERABLE (1 << 1) /* E5 Section 8.6.1 */ -#define DUK_PROPDESC_FLAG_CONFIGURABLE (1 << 2) /* E5 Section 8.6.1 */ -#define DUK_PROPDESC_FLAG_ACCESSOR (1 << 3) /* accessor */ -#define DUK_PROPDESC_FLAG_VIRTUAL (1 << 4) /* property is virtual: used in duk_propdesc, never stored - * (used by e.g. buffer virtual properties) - */ -#define DUK_PROPDESC_FLAGS_MASK (DUK_PROPDESC_FLAG_WRITABLE | \ - DUK_PROPDESC_FLAG_ENUMERABLE | \ - DUK_PROPDESC_FLAG_CONFIGURABLE | \ - DUK_PROPDESC_FLAG_ACCESSOR) - -/* additional flags which are passed in the same flags argument as property - * flags but are not stored in object properties. - */ -#define DUK_PROPDESC_FLAG_NO_OVERWRITE (1 << 4) /* internal define property: skip write silently if exists */ - -/* convenience */ -#define DUK_PROPDESC_FLAGS_NONE 0 -#define DUK_PROPDESC_FLAGS_W (DUK_PROPDESC_FLAG_WRITABLE) -#define DUK_PROPDESC_FLAGS_E (DUK_PROPDESC_FLAG_ENUMERABLE) -#define DUK_PROPDESC_FLAGS_C (DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_PROPDESC_FLAGS_WE (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE) -#define DUK_PROPDESC_FLAGS_WC (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_PROPDESC_FLAGS_EC (DUK_PROPDESC_FLAG_ENUMERABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_PROPDESC_FLAGS_WEC (DUK_PROPDESC_FLAG_WRITABLE | \ - DUK_PROPDESC_FLAG_ENUMERABLE | \ - DUK_PROPDESC_FLAG_CONFIGURABLE) - -/* flags for duk_hobject_get_own_propdesc() and variants */ -#define DUK_GETDESC_FLAG_PUSH_VALUE (1 << 0) /* push value to stack */ -#define DUK_GETDESC_FLAG_IGNORE_PROTOLOOP (1 << 1) /* don't throw for prototype loop */ - -/* - * Macro for object validity check - * - * Assert for currently guaranteed relations between flags, for instance. - */ - -#define DUK_ASSERT_HOBJECT_VALID(h) do { \ - DUK_ASSERT((h) != NULL); \ - DUK_ASSERT(!DUK_HOBJECT_IS_CALLABLE((h)) || \ - DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_FUNCTION); \ - DUK_ASSERT(!DUK_HOBJECT_IS_BUFFEROBJECT((h)) || \ - (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_BUFFER || \ - DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_ARRAYBUFFER || \ - DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_DATAVIEW || \ - DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_INT8ARRAY || \ - DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_UINT8ARRAY || \ - DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY || \ - DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_INT16ARRAY || \ - DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_UINT16ARRAY || \ - DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_INT32ARRAY || \ - DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_UINT32ARRAY || \ - DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_FLOAT32ARRAY || \ - DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_FLOAT64ARRAY)); \ - } while (0) - -/* - * Macros to access the 'props' allocation. - */ - -#if defined(DUK_USE_HEAPPTR16) -#define DUK_HOBJECT_GET_PROPS(heap,h) \ - ((duk_uint8_t *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, ((duk_heaphdr *) (h))->h_extra16)) -#define DUK_HOBJECT_SET_PROPS(heap,h,x) do { \ - ((duk_heaphdr *) (h))->h_extra16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (x)); \ - } while (0) -#else -#define DUK_HOBJECT_GET_PROPS(heap,h) \ - ((h)->props) -#define DUK_HOBJECT_SET_PROPS(heap,h,x) do { \ - (h)->props = (duk_uint8_t *) (x); \ - } while (0) -#endif - -#if defined(DUK_USE_HOBJECT_LAYOUT_1) -/* LAYOUT 1 */ -#define DUK_HOBJECT_E_GET_KEY_BASE(heap,h) \ - ((duk_hstring **) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) \ - )) -#define DUK_HOBJECT_E_GET_VALUE_BASE(heap,h) \ - ((duk_propvalue *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_hstring *) \ - )) -#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap,h) \ - ((duk_uint8_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue)) \ - )) -#define DUK_HOBJECT_A_GET_BASE(heap,h) \ - ((duk_tval *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) \ - )) -#define DUK_HOBJECT_H_GET_BASE(heap,h) \ - ((duk_uint32_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) \ - )) -#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent,n_arr,n_hash) \ - ( \ - (n_ent) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - (n_arr) * sizeof(duk_tval) + \ - (n_hash) * sizeof(duk_uint32_t) \ - ) -#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base,set_e_k,set_e_pv,set_e_f,set_a,set_h,n_ent,n_arr,n_hash) do { \ - (set_e_k) = (duk_hstring **) (void *) (p_base); \ - (set_e_pv) = (duk_propvalue *) (void *) ((set_e_k) + (n_ent)); \ - (set_e_f) = (duk_uint8_t *) (void *) ((set_e_pv) + (n_ent)); \ - (set_a) = (duk_tval *) (void *) ((set_e_f) + (n_ent)); \ - (set_h) = (duk_uint32_t *) (void *) ((set_a) + (n_arr)); \ - } while (0) -#elif defined(DUK_USE_HOBJECT_LAYOUT_2) -/* LAYOUT 2 */ -#if (DUK_USE_ALIGN_BY == 4) -#define DUK_HOBJECT_E_FLAG_PADDING(e_sz) ((4 - (e_sz)) & 0x03) -#elif (DUK_USE_ALIGN_BY == 8) -#define DUK_HOBJECT_E_FLAG_PADDING(e_sz) ((8 - (e_sz)) & 0x07) -#elif (DUK_USE_ALIGN_BY == 1) -#define DUK_HOBJECT_E_FLAG_PADDING(e_sz) 0 -#else -#error invalid DUK_USE_ALIGN_BY -#endif -#define DUK_HOBJECT_E_GET_KEY_BASE(heap,h) \ - ((duk_hstring **) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue) \ - )) -#define DUK_HOBJECT_E_GET_VALUE_BASE(heap,h) \ - ((duk_propvalue *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) \ - )) -#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap,h) \ - ((duk_uint8_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue)) \ - )) -#define DUK_HOBJECT_A_GET_BASE(heap,h) \ - ((duk_tval *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - DUK_HOBJECT_E_FLAG_PADDING(DUK_HOBJECT_GET_ESIZE((h))) \ - )) -#define DUK_HOBJECT_H_GET_BASE(heap,h) \ - ((duk_uint32_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - DUK_HOBJECT_E_FLAG_PADDING(DUK_HOBJECT_GET_ESIZE((h))) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) \ - )) -#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent,n_arr,n_hash) \ - ( \ - (n_ent) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - DUK_HOBJECT_E_FLAG_PADDING((n_ent)) + \ - (n_arr) * sizeof(duk_tval) + \ - (n_hash) * sizeof(duk_uint32_t) \ - ) -#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base,set_e_k,set_e_pv,set_e_f,set_a,set_h,n_ent,n_arr,n_hash) do { \ - (set_e_pv) = (duk_propvalue *) (void *) (p_base); \ - (set_e_k) = (duk_hstring **) (void *) ((set_e_pv) + (n_ent)); \ - (set_e_f) = (duk_uint8_t *) (void *) ((set_e_k) + (n_ent)); \ - (set_a) = (duk_tval *) (void *) (((duk_uint8_t *) (set_e_f)) + \ - sizeof(duk_uint8_t) * (n_ent) + \ - DUK_HOBJECT_E_FLAG_PADDING((n_ent))); \ - (set_h) = (duk_uint32_t *) (void *) ((set_a) + (n_arr)); \ - } while (0) -#elif defined(DUK_USE_HOBJECT_LAYOUT_3) -/* LAYOUT 3 */ -#define DUK_HOBJECT_E_GET_KEY_BASE(heap,h) \ - ((duk_hstring **) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) \ - )) -#define DUK_HOBJECT_E_GET_VALUE_BASE(heap,h) \ - ((duk_propvalue *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) \ - )) -#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap,h) \ - ((duk_uint8_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_propvalue) + sizeof(duk_hstring *)) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) + \ - DUK_HOBJECT_GET_HSIZE((h)) * sizeof(duk_uint32_t) \ - )) -#define DUK_HOBJECT_A_GET_BASE(heap,h) \ - ((duk_tval *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue) \ - )) -#define DUK_HOBJECT_H_GET_BASE(heap,h) \ - ((duk_uint32_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_propvalue) + sizeof(duk_hstring *)) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) \ - )) -#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent,n_arr,n_hash) \ - ( \ - (n_ent) * (sizeof(duk_propvalue) + sizeof(duk_hstring *) + sizeof(duk_uint8_t)) + \ - (n_arr) * sizeof(duk_tval) + \ - (n_hash) * sizeof(duk_uint32_t) \ - ) -#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base,set_e_k,set_e_pv,set_e_f,set_a,set_h,n_ent,n_arr,n_hash) do { \ - (set_e_pv) = (duk_propvalue *) (void *) (p_base); \ - (set_a) = (duk_tval *) (void *) ((set_e_pv) + (n_ent)); \ - (set_e_k) = (duk_hstring **) (void *) ((set_a) + (n_arr)); \ - (set_h) = (duk_uint32_t *) (void *) ((set_e_k) + (n_ent)); \ - (set_e_f) = (duk_uint8_t *) (void *) ((set_h) + (n_hash)); \ - } while (0) -#else -#error invalid hobject layout defines -#endif /* hobject property layout */ - -#define DUK_HOBJECT_P_ALLOC_SIZE(h) \ - DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE((h)), DUK_HOBJECT_GET_ASIZE((h)), DUK_HOBJECT_GET_HSIZE((h))) - -#define DUK_HOBJECT_E_GET_KEY(heap,h,i) (DUK_HOBJECT_E_GET_KEY_BASE((heap), (h))[(i)]) -#define DUK_HOBJECT_E_GET_KEY_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_KEY_BASE((heap), (h))[(i)]) -#define DUK_HOBJECT_E_GET_VALUE(heap,h,i) (DUK_HOBJECT_E_GET_VALUE_BASE((heap), (h))[(i)]) -#define DUK_HOBJECT_E_GET_VALUE_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_VALUE_BASE((heap), (h))[(i)]) -#define DUK_HOBJECT_E_GET_VALUE_TVAL(heap,h,i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v) -#define DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v) -#define DUK_HOBJECT_E_GET_VALUE_GETTER(heap,h,i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get) -#define DUK_HOBJECT_E_GET_VALUE_GETTER_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get) -#define DUK_HOBJECT_E_GET_VALUE_SETTER(heap,h,i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set) -#define DUK_HOBJECT_E_GET_VALUE_SETTER_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set) -#define DUK_HOBJECT_E_GET_FLAGS(heap,h,i) (DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))[(i)]) -#define DUK_HOBJECT_E_GET_FLAGS_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))[(i)]) -#define DUK_HOBJECT_A_GET_VALUE(heap,h,i) (DUK_HOBJECT_A_GET_BASE((heap), (h))[(i)]) -#define DUK_HOBJECT_A_GET_VALUE_PTR(heap,h,i) (&DUK_HOBJECT_A_GET_BASE((heap), (h))[(i)]) -#define DUK_HOBJECT_H_GET_INDEX(heap,h,i) (DUK_HOBJECT_H_GET_BASE((heap), (h))[(i)]) -#define DUK_HOBJECT_H_GET_INDEX_PTR(heap,h,i) (&DUK_HOBJECT_H_GET_BASE((heap), (h))[(i)]) - -#define DUK_HOBJECT_E_SET_KEY(heap,h,i,k) do { \ - DUK_HOBJECT_E_GET_KEY((heap), (h), (i)) = (k); \ - } while (0) -#define DUK_HOBJECT_E_SET_VALUE(heap,h,i,v) do { \ - DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)) = (v); \ - } while (0) -#define DUK_HOBJECT_E_SET_VALUE_TVAL(heap,h,i,v) do { \ - DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v = (v); \ - } while (0) -#define DUK_HOBJECT_E_SET_VALUE_GETTER(heap,h,i,v) do { \ - DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get = (v); \ - } while (0) -#define DUK_HOBJECT_E_SET_VALUE_SETTER(heap,h,i,v) do { \ - DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set = (v); \ - } while (0) -#define DUK_HOBJECT_E_SET_FLAGS(heap,h,i,f) do { \ - DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) = (duk_uint8_t) (f); \ - } while (0) -#define DUK_HOBJECT_A_SET_VALUE(heap,h,i,v) do { \ - DUK_HOBJECT_A_GET_VALUE((heap), (h), (i)) = (v); \ - } while (0) -#define DUK_HOBJECT_A_SET_VALUE_TVAL(heap,h,i,v) \ - DUK_HOBJECT_A_SET_VALUE((heap), (h), (i), (v)) /* alias for above */ -#define DUK_HOBJECT_H_SET_INDEX(heap,h,i,v) do { \ - DUK_HOBJECT_H_GET_INDEX((heap), (h), (i)) = (v); \ - } while (0) - -#define DUK_HOBJECT_E_SET_FLAG_BITS(heap,h,i,mask) do { \ - DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))[(i)] |= (mask); \ - } while (0) - -#define DUK_HOBJECT_E_CLEAR_FLAG_BITS(heap,h,i,mask) do { \ - DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))[(i)] &= ~(mask); \ - } while (0) - -#define DUK_HOBJECT_E_SLOT_IS_WRITABLE(heap,h,i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_WRITABLE) != 0) -#define DUK_HOBJECT_E_SLOT_IS_ENUMERABLE(heap,h,i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_ENUMERABLE) != 0) -#define DUK_HOBJECT_E_SLOT_IS_CONFIGURABLE(heap,h,i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_CONFIGURABLE) != 0) -#define DUK_HOBJECT_E_SLOT_IS_ACCESSOR(heap,h,i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_ACCESSOR) != 0) - -#define DUK_HOBJECT_E_SLOT_SET_WRITABLE(heap,h,i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_WRITABLE) -#define DUK_HOBJECT_E_SLOT_SET_ENUMERABLE(heap,h,i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_ENUMERABLE) -#define DUK_HOBJECT_E_SLOT_SET_CONFIGURABLE(heap,h,i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_HOBJECT_E_SLOT_SET_ACCESSOR(heap,h,i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_ACCESSOR) - -#define DUK_HOBJECT_E_SLOT_CLEAR_WRITABLE(heap,h,i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_WRITABLE) -#define DUK_HOBJECT_E_SLOT_CLEAR_ENUMERABLE(heap,h,i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_ENUMERABLE) -#define DUK_HOBJECT_E_SLOT_CLEAR_CONFIGURABLE(heap,h,i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_HOBJECT_E_SLOT_CLEAR_ACCESSOR(heap,h,i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_ACCESSOR) - -#define DUK_PROPDESC_IS_WRITABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_WRITABLE) != 0) -#define DUK_PROPDESC_IS_ENUMERABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_ENUMERABLE) != 0) -#define DUK_PROPDESC_IS_CONFIGURABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_CONFIGURABLE) != 0) -#define DUK_PROPDESC_IS_ACCESSOR(p) (((p)->flags & DUK_PROPDESC_FLAG_ACCESSOR) != 0) - -#define DUK_HOBJECT_HASHIDX_UNUSED 0xffffffffUL -#define DUK_HOBJECT_HASHIDX_DELETED 0xfffffffeUL - -/* - * Macros for accessing size fields - */ - -#if defined(DUK_USE_OBJSIZES16) -#define DUK_HOBJECT_GET_ESIZE(h) ((h)->e_size16) -#define DUK_HOBJECT_SET_ESIZE(h,v) do { (h)->e_size16 = (v); } while (0) -#define DUK_HOBJECT_GET_ENEXT(h) ((h)->e_next16) -#define DUK_HOBJECT_SET_ENEXT(h,v) do { (h)->e_next16 = (v); } while (0) -#define DUK_HOBJECT_POSTINC_ENEXT(h) ((h)->e_next16++) -#define DUK_HOBJECT_GET_ASIZE(h) ((h)->a_size16) -#define DUK_HOBJECT_SET_ASIZE(h,v) do { (h)->a_size16 = (v); } while (0) -#if defined(DUK_USE_HOBJECT_HASH_PART) -#define DUK_HOBJECT_GET_HSIZE(h) ((h)->h_size16) -#define DUK_HOBJECT_SET_HSIZE(h,v) do { (h)->h_size16 = (v); } while (0) -#else -#define DUK_HOBJECT_GET_HSIZE(h) 0 -#define DUK_HOBJECT_SET_HSIZE(h,v) do { DUK_ASSERT((v) == 0); } while (0) -#endif -#else -#define DUK_HOBJECT_GET_ESIZE(h) ((h)->e_size) -#define DUK_HOBJECT_SET_ESIZE(h,v) do { (h)->e_size = (v); } while (0) -#define DUK_HOBJECT_GET_ENEXT(h) ((h)->e_next) -#define DUK_HOBJECT_SET_ENEXT(h,v) do { (h)->e_next = (v); } while (0) -#define DUK_HOBJECT_POSTINC_ENEXT(h) ((h)->e_next++) -#define DUK_HOBJECT_GET_ASIZE(h) ((h)->a_size) -#define DUK_HOBJECT_SET_ASIZE(h,v) do { (h)->a_size = (v); } while (0) -#if defined(DUK_USE_HOBJECT_HASH_PART) -#define DUK_HOBJECT_GET_HSIZE(h) ((h)->h_size) -#define DUK_HOBJECT_SET_HSIZE(h,v) do { (h)->h_size = (v); } while (0) -#else -#define DUK_HOBJECT_GET_HSIZE(h) 0 -#define DUK_HOBJECT_SET_HSIZE(h,v) do { DUK_ASSERT((v) == 0); } while (0) -#endif -#endif - -/* - * Misc - */ - -/* Maximum prototype traversal depth. Sanity limit which handles e.g. - * prototype loops (even complex ones like 1->2->3->4->2->3->4->2->3->4). - */ -#define DUK_HOBJECT_PROTOTYPE_CHAIN_SANITY 10000L - -/* Maximum traversal depth for "bound function" chains. */ -#define DUK_HOBJECT_BOUND_CHAIN_SANITY 10000L - -/* - * Ecmascript [[Class]] - */ - -/* range check not necessary because all 4-bit values are mapped */ -#define DUK_HOBJECT_CLASS_NUMBER_TO_STRIDX(n) duk_class_number_to_stridx[(n)] - -#define DUK_HOBJECT_GET_CLASS_STRING(heap,h) \ - DUK_HEAP_GET_STRING( \ - (heap), \ - DUK_HOBJECT_CLASS_NUMBER_TO_STRIDX(DUK_HOBJECT_GET_CLASS_NUMBER((h))) \ - ) - -/* - * Macros for property handling - */ - -#if defined(DUK_USE_HEAPPTR16) -#define DUK_HOBJECT_GET_PROTOTYPE(heap,h) \ - ((duk_hobject *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->prototype16)) -#define DUK_HOBJECT_SET_PROTOTYPE(heap,h,x) do { \ - (h)->prototype16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (x)); \ - } while (0) -#else -#define DUK_HOBJECT_GET_PROTOTYPE(heap,h) \ - ((h)->prototype) -#define DUK_HOBJECT_SET_PROTOTYPE(heap,h,x) do { \ - (h)->prototype = (x); \ - } while (0) -#endif - -/* note: this updates refcounts */ -#define DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr,h,p) duk_hobject_set_prototype_updref((thr), (h), (p)) - -/* - * Resizing and hash behavior - */ - -/* Sanity limit on max number of properties (allocated, not necessarily used). - * This is somewhat arbitrary, but if we're close to 2**32 properties some - * algorithms will fail (e.g. hash size selection, next prime selection). - * Also, we use negative array/entry table indices to indicate 'not found', - * so anything above 0x80000000 will cause trouble now. - */ -#if defined(DUK_USE_OBJSIZES16) -#define DUK_HOBJECT_MAX_PROPERTIES 0x0000ffffUL -#else -#define DUK_HOBJECT_MAX_PROPERTIES 0x7fffffffUL /* 2**31-1 ~= 2G properties */ -#endif - -/* higher value conserves memory; also note that linear scan is cache friendly */ -#define DUK_HOBJECT_E_USE_HASH_LIMIT 32 - -/* hash size relative to entries size: for value X, approx. hash_prime(e_size + e_size / X) */ -#define DUK_HOBJECT_H_SIZE_DIVISOR 4 /* hash size approx. 1.25 times entries size */ - -/* if new_size < L * old_size, resize without abandon check; L = 3-bit fixed point, e.g. 9 -> 9/8 = 112.5% */ -#define DUK_HOBJECT_A_FAST_RESIZE_LIMIT 9 /* 112.5%, i.e. new size less than 12.5% higher -> fast resize */ - -/* if density < L, abandon array part, L = 3-bit fixed point, e.g. 2 -> 2/8 = 25% */ -/* limit is quite low: one array entry is 8 bytes, one normal entry is 4+1+8+4 = 17 bytes (with hash entry) */ -#define DUK_HOBJECT_A_ABANDON_LIMIT 2 /* 25%, i.e. less than 25% used -> abandon */ - -/* internal align target for props allocation, must be 2*n for some n */ -#if (DUK_USE_ALIGN_BY == 4) -#define DUK_HOBJECT_ALIGN_TARGET 4 -#elif (DUK_USE_ALIGN_BY == 8) -#define DUK_HOBJECT_ALIGN_TARGET 8 -#elif (DUK_USE_ALIGN_BY == 1) -#define DUK_HOBJECT_ALIGN_TARGET 1 -#else -#error invalid DUK_USE_ALIGN_BY -#endif - -/* controls for minimum entry part growth */ -#define DUK_HOBJECT_E_MIN_GROW_ADD 16 -#define DUK_HOBJECT_E_MIN_GROW_DIVISOR 8 /* 2^3 -> 1/8 = 12.5% min growth */ - -/* controls for minimum array part growth */ -#define DUK_HOBJECT_A_MIN_GROW_ADD 16 -#define DUK_HOBJECT_A_MIN_GROW_DIVISOR 8 /* 2^3 -> 1/8 = 12.5% min growth */ - -/* probe sequence */ -#define DUK_HOBJECT_HASH_INITIAL(hash,h_size) ((hash) % (h_size)) -#define DUK_HOBJECT_HASH_PROBE_STEP(hash) DUK_UTIL_GET_HASH_PROBE_STEP((hash)) - -/* - * PC-to-line constants - */ - -#define DUK_PC2LINE_SKIP 64 - -/* maximum length for a SKIP-1 diffstream: 35 bits per entry, rounded up to bytes */ -#define DUK_PC2LINE_MAX_DIFF_LENGTH (((DUK_PC2LINE_SKIP - 1) * 35 + 7) / 8) - -/* - * Struct defs - */ - -struct duk_propaccessor { - duk_hobject *get; - duk_hobject *set; -}; - -union duk_propvalue { - /* The get/set pointers could be 16-bit pointer compressed but it - * would make no difference on 32-bit platforms because duk_tval is - * 8 bytes or more anyway. - */ - duk_tval v; - duk_propaccessor a; -}; - -struct duk_propdesc { - /* read-only values 'lifted' for ease of use */ - duk_small_int_t flags; - duk_hobject *get; - duk_hobject *set; - - /* for updating (all are set to < 0 for virtual properties) */ - duk_int_t e_idx; /* prop index in 'entry part', < 0 if not there */ - duk_int_t h_idx; /* prop index in 'hash part', < 0 if not there */ - duk_int_t a_idx; /* prop index in 'array part', < 0 if not there */ -}; - -struct duk_hobject { - duk_heaphdr hdr; - - /* - * 'props' contains {key,value,flags} entries, optional array entries, and - * an optional hash lookup table for non-array entries in a single 'sliced' - * allocation. There are several layout options, which differ slightly in - * generated code size/speed and alignment/padding; duk_features.h selects - * the layout used. - * - * Layout 1 (DUK_USE_HOBJECT_LAYOUT_1): - * - * e_size * sizeof(duk_hstring *) bytes of entry keys (e_next gc reachable) - * e_size * sizeof(duk_propvalue) bytes of entry values (e_next gc reachable) - * e_size * sizeof(duk_uint8_t) bytes of entry flags (e_next gc reachable) - * a_size * sizeof(duk_tval) bytes of (opt) array values (plain only) (all gc reachable) - * h_size * sizeof(duk_uint32_t) bytes of (opt) hash indexes to entries (e_size), - * 0xffffffffUL = unused, 0xfffffffeUL = deleted - * - * Layout 2 (DUK_USE_HOBJECT_LAYOUT_2): - * - * e_size * sizeof(duk_propvalue) bytes of entry values (e_next gc reachable) - * e_size * sizeof(duk_hstring *) bytes of entry keys (e_next gc reachable) - * e_size * sizeof(duk_uint8_t) + pad bytes of entry flags (e_next gc reachable) - * a_size * sizeof(duk_tval) bytes of (opt) array values (plain only) (all gc reachable) - * h_size * sizeof(duk_uint32_t) bytes of (opt) hash indexes to entries (e_size), - * 0xffffffffUL = unused, 0xfffffffeUL = deleted - * - * Layout 3 (DUK_USE_HOBJECT_LAYOUT_3): - * - * e_size * sizeof(duk_propvalue) bytes of entry values (e_next gc reachable) - * a_size * sizeof(duk_tval) bytes of (opt) array values (plain only) (all gc reachable) - * e_size * sizeof(duk_hstring *) bytes of entry keys (e_next gc reachable) - * h_size * sizeof(duk_uint32_t) bytes of (opt) hash indexes to entries (e_size), - * 0xffffffffUL = unused, 0xfffffffeUL = deleted - * e_size * sizeof(duk_uint8_t) bytes of entry flags (e_next gc reachable) - * - * In layout 1, the 'e_next' count is rounded to 4 or 8 on platforms - * requiring 4 or 8 byte alignment. This ensures proper alignment - * for the entries, at the cost of memory footprint. However, it's - * probably preferable to use another layout on such platforms instead. - * - * In layout 2, the key and value parts are swapped to avoid padding - * the key array on platforms requiring alignment by 8. The flags part - * is padded to get alignment for array entries. The 'e_next' count does - * not need to be rounded as in layout 1. - * - * In layout 3, entry values and array values are always aligned properly, - * and assuming pointers are at most 8 bytes, so are the entry keys. Hash - * indices will be properly aligned (assuming pointers are at least 4 bytes). - * Finally, flags don't need additional alignment. This layout provides - * compact allocations without padding (even on platforms with alignment - * requirements) at the cost of a bit slower lookups. - * - * Objects with few keys don't have a hash index; keys are looked up linearly, - * which is cache efficient because the keys are consecutive. Larger objects - * have a hash index part which contains integer indexes to the entries part. - * - * A single allocation reduces memory allocation overhead but requires more - * work when any part needs to be resized. A sliced allocation for entries - * makes linear key matching faster on most platforms (more locality) and - * skimps on flags size (which would be followed by 3 bytes of padding in - * most architectures if entries were placed in a struct). - * - * 'props' also contains internal properties distinguished with a non-BMP - * prefix. Often used properties should be placed early in 'props' whenever - * possible to make accessing them as fast a possible. - */ - -#if defined(DUK_USE_HEAPPTR16) - /* Located in duk_heaphdr h_extra16. Subclasses of duk_hobject (like - * duk_hcompiledfunction) are not free to use h_extra16 for this reason. - */ -#else - duk_uint8_t *props; -#endif - - /* prototype: the only internal property lifted outside 'e' as it is so central */ -#if defined(DUK_USE_HEAPPTR16) - duk_uint16_t prototype16; -#else - duk_hobject *prototype; -#endif - -#if defined(DUK_USE_OBJSIZES16) - duk_uint16_t e_size16; - duk_uint16_t e_next16; - duk_uint16_t a_size16; -#if defined(DUK_USE_HOBJECT_HASH_PART) - duk_uint16_t h_size16; -#endif -#else - duk_uint32_t e_size; /* entry part size */ - duk_uint32_t e_next; /* index for next new key ([0,e_next[ are gc reachable) */ - duk_uint32_t a_size; /* array part size (entirely gc reachable) */ -#if defined(DUK_USE_HOBJECT_HASH_PART) - duk_uint32_t h_size; /* hash part size or 0 if unused */ -#endif -#endif -}; - -/* - * Exposed data - */ - -#if !defined(DUK_SINGLE_FILE) -DUK_INTERNAL_DECL duk_uint8_t duk_class_number_to_stridx[32]; -#endif /* !DUK_SINGLE_FILE */ - -/* - * Prototypes - */ - -/* alloc and init */ -DUK_INTERNAL_DECL duk_hobject *duk_hobject_alloc(duk_heap *heap, duk_uint_t hobject_flags); -#if 0 /* unused */ -DUK_INTERNAL_DECL duk_hobject *duk_hobject_alloc_checked(duk_hthread *thr, duk_uint_t hobject_flags); -#endif -DUK_INTERNAL_DECL duk_hcompiledfunction *duk_hcompiledfunction_alloc(duk_heap *heap, duk_uint_t hobject_flags); -DUK_INTERNAL_DECL duk_hnativefunction *duk_hnativefunction_alloc(duk_heap *heap, duk_uint_t hobject_flags); -DUK_INTERNAL duk_hbufferobject *duk_hbufferobject_alloc(duk_heap *heap, duk_uint_t hobject_flags); -DUK_INTERNAL_DECL duk_hthread *duk_hthread_alloc(duk_heap *heap, duk_uint_t hobject_flags); - -/* low-level property functions */ -DUK_INTERNAL_DECL void duk_hobject_find_existing_entry(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_int_t *e_idx, duk_int_t *h_idx); -DUK_INTERNAL_DECL duk_tval *duk_hobject_find_existing_entry_tval_ptr(duk_heap *heap, duk_hobject *obj, duk_hstring *key); -DUK_INTERNAL_DECL duk_tval *duk_hobject_find_existing_entry_tval_ptr_and_attrs(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_int_t *out_attrs); -DUK_INTERNAL_DECL duk_tval *duk_hobject_find_existing_array_entry_tval_ptr(duk_heap *heap, duk_hobject *obj, duk_uarridx_t i); -DUK_INTERNAL_DECL duk_bool_t duk_hobject_get_own_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags); - -/* XXX: when optimizing for guaranteed property slots, use a guaranteed - * slot for internal value; this call can then access it directly. - */ -#define duk_hobject_get_internal_value_tval_ptr(heap,obj) \ - duk_hobject_find_existing_entry_tval_ptr((heap), (obj), DUK_HEAP_STRING_INT_VALUE((heap))) - -/* core property functions */ -DUK_INTERNAL_DECL duk_bool_t duk_hobject_getprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key); -DUK_INTERNAL_DECL duk_bool_t duk_hobject_putprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_tval *tv_val, duk_bool_t throw_flag); -DUK_INTERNAL_DECL duk_bool_t duk_hobject_delprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_bool_t throw_flag); -DUK_INTERNAL_DECL duk_bool_t duk_hobject_hasprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key); - -/* internal property functions */ -#define DUK_DELPROP_FLAG_THROW (1 << 0) -#define DUK_DELPROP_FLAG_FORCE (1 << 1) -DUK_INTERNAL_DECL duk_bool_t duk_hobject_delprop_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_small_uint_t flags); -DUK_INTERNAL_DECL duk_bool_t duk_hobject_hasprop_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key); -DUK_INTERNAL_DECL void duk_hobject_define_property_internal(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_small_uint_t flags); -DUK_INTERNAL_DECL void duk_hobject_define_property_internal_arridx(duk_hthread *thr, duk_hobject *obj, duk_uarridx_t arr_idx, duk_small_uint_t flags); -DUK_INTERNAL_DECL void duk_hobject_define_accessor_internal(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_hobject *getter, duk_hobject *setter, duk_small_uint_t propflags); -DUK_INTERNAL_DECL void duk_hobject_set_length(duk_hthread *thr, duk_hobject *obj, duk_uint32_t length); /* XXX: duk_uarridx_t? */ -DUK_INTERNAL_DECL void duk_hobject_set_length_zero(duk_hthread *thr, duk_hobject *obj); -DUK_INTERNAL_DECL duk_uint32_t duk_hobject_get_length(duk_hthread *thr, duk_hobject *obj); /* XXX: duk_uarridx_t? */ - -/* helpers for defineProperty() and defineProperties() */ -DUK_INTERNAL_DECL -void duk_hobject_prepare_property_descriptor(duk_context *ctx, - duk_idx_t idx_in, - duk_uint_t *out_defprop_flags, - duk_idx_t *out_idx_value, - duk_hobject **out_getter, - duk_hobject **out_setter); -DUK_INTERNAL_DECL -void duk_hobject_define_property_helper(duk_context *ctx, - duk_uint_t defprop_flags, - duk_hobject *obj, - duk_hstring *key, - duk_idx_t idx_value, - duk_hobject *get, - duk_hobject *set); - -/* Object built-in methods */ -DUK_INTERNAL_DECL duk_ret_t duk_hobject_object_get_own_property_descriptor(duk_context *ctx); -DUK_INTERNAL_DECL void duk_hobject_object_seal_freeze_helper(duk_hthread *thr, duk_hobject *obj, duk_bool_t is_freeze); -DUK_INTERNAL_DECL duk_bool_t duk_hobject_object_is_sealed_frozen_helper(duk_hthread *thr, duk_hobject *obj, duk_bool_t is_frozen); -DUK_INTERNAL_DECL duk_bool_t duk_hobject_object_ownprop_helper(duk_context *ctx, duk_small_uint_t required_desc_flags); - -/* internal properties */ -DUK_INTERNAL_DECL duk_bool_t duk_hobject_get_internal_value(duk_heap *heap, duk_hobject *obj, duk_tval *tv); -DUK_INTERNAL_DECL duk_hstring *duk_hobject_get_internal_value_string(duk_heap *heap, duk_hobject *obj); - -/* hobject management functions */ -DUK_INTERNAL_DECL void duk_hobject_compact_props(duk_hthread *thr, duk_hobject *obj); - -/* ES6 proxy */ -#if defined(DUK_USE_ES6_PROXY) -DUK_INTERNAL_DECL duk_bool_t duk_hobject_proxy_check(duk_hthread *thr, duk_hobject *obj, duk_hobject **out_target, duk_hobject **out_handler); -DUK_INTERNAL_DECL duk_hobject *duk_hobject_resolve_proxy_target(duk_hthread *thr, duk_hobject *obj); -#endif - -/* enumeration */ -DUK_INTERNAL_DECL void duk_hobject_enumerator_create(duk_context *ctx, duk_small_uint_t enum_flags); -DUK_INTERNAL_DECL duk_ret_t duk_hobject_get_enumerated_keys(duk_context *ctx, duk_small_uint_t enum_flags); -DUK_INTERNAL_DECL duk_bool_t duk_hobject_enumerator_next(duk_context *ctx, duk_bool_t get_value); - -/* macros */ -DUK_INTERNAL_DECL void duk_hobject_set_prototype_updref(duk_hthread *thr, duk_hobject *h, duk_hobject *p); - -/* finalization */ -DUK_INTERNAL_DECL void duk_hobject_run_finalizer(duk_hthread *thr, duk_hobject *obj); - -/* pc2line */ -#if defined(DUK_USE_PC2LINE) -DUK_INTERNAL_DECL void duk_hobject_pc2line_pack(duk_hthread *thr, duk_compiler_instr *instrs, duk_uint_fast32_t length); -DUK_INTERNAL_DECL duk_uint_fast32_t duk_hobject_pc2line_query(duk_context *ctx, duk_idx_t idx_func, duk_uint_fast32_t pc); -#endif - -/* misc */ -DUK_INTERNAL_DECL duk_bool_t duk_hobject_prototype_chain_contains(duk_hthread *thr, duk_hobject *h, duk_hobject *p, duk_bool_t ignore_loop); - -#endif /* DUK_HOBJECT_H_INCLUDED */
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/ede68a10/thirdparty/civetweb-1.10/src/third_party/duktape-1.5.2/src-separate/duk_hobject_alloc.c ---------------------------------------------------------------------- diff --git a/thirdparty/civetweb-1.10/src/third_party/duktape-1.5.2/src-separate/duk_hobject_alloc.c b/thirdparty/civetweb-1.10/src/third_party/duktape-1.5.2/src-separate/duk_hobject_alloc.c deleted file mode 100644 index 9a426a7..0000000 --- a/thirdparty/civetweb-1.10/src/third_party/duktape-1.5.2/src-separate/duk_hobject_alloc.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Hobject allocation. - * - * Provides primitive allocation functions for all object types (plain object, - * compiled function, native function, thread). The object return is not yet - * in "heap allocated" list and has a refcount of zero, so caller must careful. - */ - -#include "duk_internal.h" - -DUK_LOCAL void duk__init_object_parts(duk_heap *heap, duk_hobject *obj, duk_uint_t hobject_flags) { -#ifdef DUK_USE_EXPLICIT_NULL_INIT - DUK_HOBJECT_SET_PROPS(heap, obj, NULL); -#endif - - /* XXX: macro? sets both heaphdr and object flags */ - obj->hdr.h_flags = hobject_flags; - DUK_HEAPHDR_SET_TYPE(&obj->hdr, DUK_HTYPE_OBJECT); /* also goes into flags */ - -#if defined(DUK_USE_HEAPPTR16) - /* Zero encoded pointer is required to match NULL */ - DUK_HEAPHDR_SET_NEXT(heap, &obj->hdr, NULL); -#if defined(DUK_USE_DOUBLE_LINKED_HEAP) - DUK_HEAPHDR_SET_PREV(heap, &obj->hdr, NULL); -#endif -#endif - DUK_ASSERT_HEAPHDR_LINKS(heap, &obj->hdr); - DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, &obj->hdr); - - /* - * obj->props is intentionally left as NULL, and duk_hobject_props.c must deal - * with this properly. This is intentional: empty objects consume a minimum - * amount of memory. Further, an initial allocation might fail and cause - * 'obj' to "leak" (require a mark-and-sweep) since it is not reachable yet. - */ -} - -/* - * Allocate an duk_hobject. - * - * The allocated object has no allocation for properties; the caller may - * want to force a resize if a desired size is known. - * - * The allocated object has zero reference count and is not reachable. - * The caller MUST make the object reachable and increase its reference - * count before invoking any operation that might require memory allocation. - */ - -DUK_INTERNAL duk_hobject *duk_hobject_alloc(duk_heap *heap, duk_uint_t hobject_flags) { - duk_hobject *res; - - DUK_ASSERT(heap != NULL); - - /* different memory layout, alloc size, and init */ - DUK_ASSERT((hobject_flags & DUK_HOBJECT_FLAG_COMPILEDFUNCTION) == 0); - DUK_ASSERT((hobject_flags & DUK_HOBJECT_FLAG_NATIVEFUNCTION) == 0); - DUK_ASSERT((hobject_flags & DUK_HOBJECT_FLAG_THREAD) == 0); - - res = (duk_hobject *) DUK_ALLOC(heap, sizeof(duk_hobject)); - if (!res) { - return NULL; - } - DUK_MEMZERO(res, sizeof(duk_hobject)); - - duk__init_object_parts(heap, res, hobject_flags); - - return res; -} - -DUK_INTERNAL duk_hcompiledfunction *duk_hcompiledfunction_alloc(duk_heap *heap, duk_uint_t hobject_flags) { - duk_hcompiledfunction *res; - - res = (duk_hcompiledfunction *) DUK_ALLOC(heap, sizeof(duk_hcompiledfunction)); - if (!res) { - return NULL; - } - DUK_MEMZERO(res, sizeof(duk_hcompiledfunction)); - - duk__init_object_parts(heap, &res->obj, hobject_flags); - -#ifdef DUK_USE_EXPLICIT_NULL_INIT -#ifdef DUK_USE_HEAPPTR16 - /* NULL pointer is required to encode to zero, so memset is enough. */ -#else - res->data = NULL; - res->funcs = NULL; - res->bytecode = NULL; -#endif -#endif - - return res; -} - -DUK_INTERNAL duk_hnativefunction *duk_hnativefunction_alloc(duk_heap *heap, duk_uint_t hobject_flags) { - duk_hnativefunction *res; - - res = (duk_hnativefunction *) DUK_ALLOC(heap, sizeof(duk_hnativefunction)); - if (!res) { - return NULL; - } - DUK_MEMZERO(res, sizeof(duk_hnativefunction)); - - duk__init_object_parts(heap, &res->obj, hobject_flags); - -#ifdef DUK_USE_EXPLICIT_NULL_INIT - res->func = NULL; -#endif - - return res; -} - -DUK_INTERNAL duk_hbufferobject *duk_hbufferobject_alloc(duk_heap *heap, duk_uint_t hobject_flags) { - duk_hbufferobject *res; - - res = (duk_hbufferobject *) DUK_ALLOC(heap, sizeof(duk_hbufferobject)); - if (!res) { - return NULL; - } - DUK_MEMZERO(res, sizeof(duk_hbufferobject)); - - duk__init_object_parts(heap, &res->obj, hobject_flags); - -#ifdef DUK_USE_EXPLICIT_NULL_INIT - res->buf = NULL; -#endif - - DUK_ASSERT_HBUFFEROBJECT_VALID(res); - return res; -} - -/* - * Allocate a new thread. - * - * Leaves the built-ins array uninitialized. The caller must either - * initialize a new global context or share existing built-ins from - * another thread. - */ - -DUK_INTERNAL duk_hthread *duk_hthread_alloc(duk_heap *heap, duk_uint_t hobject_flags) { - duk_hthread *res; - - res = (duk_hthread *) DUK_ALLOC(heap, sizeof(duk_hthread)); - if (!res) { - return NULL; - } - DUK_MEMZERO(res, sizeof(duk_hthread)); - - duk__init_object_parts(heap, &res->obj, hobject_flags); - -#ifdef DUK_USE_EXPLICIT_NULL_INIT - res->ptr_curr_pc = NULL; - res->heap = NULL; - res->valstack = NULL; - res->valstack_end = NULL; - res->valstack_bottom = NULL; - res->valstack_top = NULL; - res->callstack = NULL; - res->catchstack = NULL; - res->resumer = NULL; - res->compile_ctx = NULL, -#ifdef DUK_USE_HEAPPTR16 - res->strs16 = NULL; -#else - res->strs = NULL; -#endif - { - int i; - for (i = 0; i < DUK_NUM_BUILTINS; i++) { - res->builtins[i] = NULL; - } - } -#endif - /* when nothing is running, API calls are in non-strict mode */ - DUK_ASSERT(res->strict == 0); - - res->heap = heap; - res->valstack_max = DUK_VALSTACK_DEFAULT_MAX; - res->callstack_max = DUK_CALLSTACK_DEFAULT_MAX; - res->catchstack_max = DUK_CATCHSTACK_DEFAULT_MAX; - - return res; -} - -#if 0 /* unused now */ -DUK_INTERNAL duk_hobject *duk_hobject_alloc_checked(duk_hthread *thr, duk_uint_t hobject_flags) { - duk_hobject *res = duk_hobject_alloc(thr->heap, hobject_flags); - if (!res) { - DUK_ERROR_ALLOC_DEFMSG(thr); - } - return res; -} -#endif http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/ede68a10/thirdparty/civetweb-1.10/src/third_party/duktape-1.5.2/src-separate/duk_hobject_class.c ---------------------------------------------------------------------- diff --git a/thirdparty/civetweb-1.10/src/third_party/duktape-1.5.2/src-separate/duk_hobject_class.c b/thirdparty/civetweb-1.10/src/third_party/duktape-1.5.2/src-separate/duk_hobject_class.c deleted file mode 100644 index bb2dc64..0000000 --- a/thirdparty/civetweb-1.10/src/third_party/duktape-1.5.2/src-separate/duk_hobject_class.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Hobject Ecmascript [[Class]]. - */ - -#include "duk_internal.h" - -#if (DUK_STRIDX_UC_ARGUMENTS > 255) -#error constant too large -#endif -#if (DUK_STRIDX_ARRAY > 255) -#error constant too large -#endif -#if (DUK_STRIDX_UC_BOOLEAN > 255) -#error constant too large -#endif -#if (DUK_STRIDX_DATE > 255) -#error constant too large -#endif -#if (DUK_STRIDX_UC_ERROR > 255) -#error constant too large -#endif -#if (DUK_STRIDX_UC_FUNCTION > 255) -#error constant too large -#endif -#if (DUK_STRIDX_JSON > 255) -#error constant too large -#endif -#if (DUK_STRIDX_MATH > 255) -#error constant too large -#endif -#if (DUK_STRIDX_UC_NUMBER > 255) -#error constant too large -#endif -#if (DUK_STRIDX_UC_OBJECT > 255) -#error constant too large -#endif -#if (DUK_STRIDX_REG_EXP > 255) -#error constant too large -#endif -#if (DUK_STRIDX_UC_STRING > 255) -#error constant too large -#endif -#if (DUK_STRIDX_GLOBAL > 255) -#error constant too large -#endif -#if (DUK_STRIDX_OBJ_ENV > 255) -#error constant too large -#endif -#if (DUK_STRIDX_DEC_ENV > 255) -#error constant too large -#endif -#if (DUK_STRIDX_UC_BUFFER > 255) -#error constant too large -#endif -#if (DUK_STRIDX_UC_POINTER > 255) -#error constant too large -#endif -#if (DUK_STRIDX_UC_THREAD > 255) -#error constant too large -#endif -#if (DUK_STRIDX_ARRAY_BUFFER > 255) -#error constant too large -#endif -#if (DUK_STRIDX_DATA_VIEW > 255) -#error constant too large -#endif -#if (DUK_STRIDX_INT8_ARRAY > 255) -#error constant too large -#endif -#if (DUK_STRIDX_UINT8_ARRAY > 255) -#error constant too large -#endif -#if (DUK_STRIDX_UINT8_CLAMPED_ARRAY > 255) -#error constant too large -#endif -#if (DUK_STRIDX_INT16_ARRAY > 255) -#error constant too large -#endif -#if (DUK_STRIDX_UINT16_ARRAY > 255) -#error constant too large -#endif -#if (DUK_STRIDX_INT32_ARRAY > 255) -#error constant too large -#endif -#if (DUK_STRIDX_UINT32_ARRAY > 255) -#error constant too large -#endif -#if (DUK_STRIDX_FLOAT32_ARRAY > 255) -#error constant too large -#endif -#if (DUK_STRIDX_FLOAT64_ARRAY > 255) -#error constant too large -#endif -#if (DUK_STRIDX_EMPTY_STRING > 255) -#error constant too large -#endif - -/* Note: assumes that these string indexes are 8-bit, genstrings.py must ensure that */ -DUK_INTERNAL duk_uint8_t duk_class_number_to_stridx[32] = { - DUK_STRIDX_EMPTY_STRING, /* UNUSED, intentionally empty */ - DUK_STRIDX_UC_ARGUMENTS, - DUK_STRIDX_ARRAY, - DUK_STRIDX_UC_BOOLEAN, - DUK_STRIDX_DATE, - DUK_STRIDX_UC_ERROR, - DUK_STRIDX_UC_FUNCTION, - DUK_STRIDX_JSON, - DUK_STRIDX_MATH, - DUK_STRIDX_UC_NUMBER, - DUK_STRIDX_UC_OBJECT, - DUK_STRIDX_REG_EXP, - DUK_STRIDX_UC_STRING, - DUK_STRIDX_GLOBAL, - DUK_STRIDX_OBJ_ENV, - DUK_STRIDX_DEC_ENV, - DUK_STRIDX_UC_BUFFER, - DUK_STRIDX_UC_POINTER, - DUK_STRIDX_UC_THREAD, - DUK_STRIDX_ARRAY_BUFFER, - DUK_STRIDX_DATA_VIEW, - DUK_STRIDX_INT8_ARRAY, - DUK_STRIDX_UINT8_ARRAY, - DUK_STRIDX_UINT8_CLAMPED_ARRAY, - DUK_STRIDX_INT16_ARRAY, - DUK_STRIDX_UINT16_ARRAY, - DUK_STRIDX_INT32_ARRAY, - DUK_STRIDX_UINT32_ARRAY, - DUK_STRIDX_FLOAT32_ARRAY, - DUK_STRIDX_FLOAT64_ARRAY, - DUK_STRIDX_EMPTY_STRING, /* UNUSED, intentionally empty */ - DUK_STRIDX_EMPTY_STRING, /* UNUSED, intentionally empty */ -}; http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/ede68a10/thirdparty/civetweb-1.10/src/third_party/duktape-1.5.2/src-separate/duk_hobject_enum.c ---------------------------------------------------------------------- diff --git a/thirdparty/civetweb-1.10/src/third_party/duktape-1.5.2/src-separate/duk_hobject_enum.c b/thirdparty/civetweb-1.10/src/third_party/duktape-1.5.2/src-separate/duk_hobject_enum.c deleted file mode 100644 index 75142ab..0000000 --- a/thirdparty/civetweb-1.10/src/third_party/duktape-1.5.2/src-separate/duk_hobject_enum.c +++ /dev/null @@ -1,626 +0,0 @@ -/* - * Hobject enumeration support. - * - * Creates an internal enumeration state object to be used e.g. with for-in - * enumeration. The state object contains a snapshot of target object keys - * and internal control state for enumeration. Enumerator flags allow caller - * to e.g. request internal/non-enumerable properties, and to enumerate only - * "own" properties. - * - * Also creates the result value for e.g. Object.keys() based on the same - * internal structure. - * - * This snapshot-based enumeration approach is used to simplify enumeration: - * non-snapshot-based approaches are difficult to reconcile with mutating - * the enumeration target, running multiple long-lived enumerators at the - * same time, garbage collection details, etc. The downside is that the - * enumerator object is memory inefficient especially for iterating arrays. - */ - -#include "duk_internal.h" - -/* XXX: identify enumeration target with an object index (not top of stack) */ - -/* must match exactly the number of internal properties inserted to enumerator */ -#define DUK__ENUM_START_INDEX 2 - -DUK_LOCAL const duk_uint16_t duk__bufferobject_virtual_props[] = { - DUK_STRIDX_LENGTH, - DUK_STRIDX_BYTE_LENGTH, - DUK_STRIDX_BYTE_OFFSET, - DUK_STRIDX_BYTES_PER_ELEMENT -}; - -/* - * Helper to sort array index keys. The keys are in the enumeration object - * entry part, starting from DUK__ENUM_START_INDEX, and the entry part is dense. - * - * We use insertion sort because it is simple (leading to compact code,) - * works nicely in-place, and minimizes operations if data is already sorted - * or nearly sorted (which is a very common case here). It also minimizes - * the use of element comparisons in general. This is nice because element - * comparisons here involve re-parsing the string keys into numbers each - * time, which is naturally very expensive. - * - * Note that the entry part values are all "true", e.g. - * - * "1" -> true, "3" -> true, "2" -> true - * - * so it suffices to only work in the key part without exchanging any keys, - * simplifying the sort. - * - * http://en.wikipedia.org/wiki/Insertion_sort - * - * (Compiles to about 160 bytes now as a stand-alone function.) - */ - -DUK_LOCAL void duk__sort_array_indices(duk_hthread *thr, duk_hobject *h_obj) { - duk_hstring **keys; - duk_hstring **p_curr, **p_insert, **p_end; - duk_hstring *h_curr; - duk_uarridx_t val_highest, val_curr, val_insert; - - DUK_ASSERT(h_obj != NULL); - DUK_ASSERT(DUK_HOBJECT_GET_ENEXT(h_obj) >= 2); /* control props */ - DUK_UNREF(thr); - - if (DUK_HOBJECT_GET_ENEXT(h_obj) <= 1 + DUK__ENUM_START_INDEX) { - return; - } - - keys = DUK_HOBJECT_E_GET_KEY_BASE(thr->heap, h_obj); - p_end = keys + DUK_HOBJECT_GET_ENEXT(h_obj); - keys += DUK__ENUM_START_INDEX; - - DUK_DDD(DUK_DDDPRINT("keys=%p, p_end=%p (after skipping enum props)", - (void *) keys, (void *) p_end)); - -#ifdef DUK_USE_DDDPRINT - { - duk_uint_fast32_t i; - for (i = 0; i < (duk_uint_fast32_t) DUK_HOBJECT_GET_ENEXT(h_obj); i++) { - DUK_DDD(DUK_DDDPRINT("initial: %ld %p -> %!O", - (long) i, - (void *) DUK_HOBJECT_E_GET_KEY_PTR(thr->heap, h_obj, i), - (duk_heaphdr *) DUK_HOBJECT_E_GET_KEY(thr->heap, h_obj, i))); - } - } -#endif - - val_highest = DUK_HSTRING_GET_ARRIDX_SLOW(keys[0]); - for (p_curr = keys + 1; p_curr < p_end; p_curr++) { - DUK_ASSERT(*p_curr != NULL); - val_curr = DUK_HSTRING_GET_ARRIDX_SLOW(*p_curr); - - if (val_curr >= val_highest) { - DUK_DDD(DUK_DDDPRINT("p_curr=%p, p_end=%p, val_highest=%ld, val_curr=%ld -> " - "already in correct order, next", - (void *) p_curr, (void *) p_end, (long) val_highest, (long) val_curr)); - val_highest = val_curr; - continue; - } - - DUK_DDD(DUK_DDDPRINT("p_curr=%p, p_end=%p, val_highest=%ld, val_curr=%ld -> " - "needs to be inserted", - (void *) p_curr, (void *) p_end, (long) val_highest, (long) val_curr)); - - /* Needs to be inserted; scan backwards, since we optimize - * for the case where elements are nearly in order. - */ - - p_insert = p_curr - 1; - for (;;) { - val_insert = DUK_HSTRING_GET_ARRIDX_SLOW(*p_insert); - if (val_insert < val_curr) { - DUK_DDD(DUK_DDDPRINT("p_insert=%p, val_insert=%ld, val_curr=%ld -> insert after this", - (void *) p_insert, (long) val_insert, (long) val_curr)); - p_insert++; - break; - } - if (p_insert == keys) { - DUK_DDD(DUK_DDDPRINT("p_insert=%p -> out of keys, insert to beginning", (void *) p_insert)); - break; - } - DUK_DDD(DUK_DDDPRINT("p_insert=%p, val_insert=%ld, val_curr=%ld -> search backwards", - (void *) p_insert, (long) val_insert, (long) val_curr)); - p_insert--; - } - - DUK_DDD(DUK_DDDPRINT("final p_insert=%p", (void *) p_insert)); - - /* .-- p_insert .-- p_curr - * v v - * | ... | insert | ... | curr - */ - - h_curr = *p_curr; - DUK_DDD(DUK_DDDPRINT("memmove: dest=%p, src=%p, size=%ld, h_curr=%p", - (void *) (p_insert + 1), (void *) p_insert, - (long) (p_curr - p_insert), (void *) h_curr)); - - DUK_MEMMOVE((void *) (p_insert + 1), - (const void *) p_insert, - (size_t) ((p_curr - p_insert) * sizeof(duk_hstring *))); - *p_insert = h_curr; - /* keep val_highest */ - } - -#ifdef DUK_USE_DDDPRINT - { - duk_uint_fast32_t i; - for (i = 0; i < (duk_uint_fast32_t) DUK_HOBJECT_GET_ENEXT(h_obj); i++) { - DUK_DDD(DUK_DDDPRINT("final: %ld %p -> %!O", - (long) i, - (void *) DUK_HOBJECT_E_GET_KEY_PTR(thr->heap, h_obj, i), - (duk_heaphdr *) DUK_HOBJECT_E_GET_KEY(thr->heap, h_obj, i))); - } - } -#endif -} - -/* - * Create an internal enumerator object E, which has its keys ordered - * to match desired enumeration ordering. Also initialize internal control - * properties for enumeration. - * - * Note: if an array was used to hold enumeration keys instead, an array - * scan would be needed to eliminate duplicates found in the prototype chain. - */ - -DUK_INTERNAL void duk_hobject_enumerator_create(duk_context *ctx, duk_small_uint_t enum_flags) { - duk_hthread *thr = (duk_hthread *) ctx; - duk_hobject *enum_target; - duk_hobject *curr; - duk_hobject *res; -#if defined(DUK_USE_ES6_PROXY) - duk_hobject *h_proxy_target; - duk_hobject *h_proxy_handler; - duk_hobject *h_trap_result; -#endif - duk_uint_fast32_t i, len; /* used for array, stack, and entry indices */ - - DUK_ASSERT(ctx != NULL); - - DUK_DDD(DUK_DDDPRINT("create enumerator, stack top: %ld", (long) duk_get_top(ctx))); - - enum_target = duk_require_hobject(ctx, -1); - DUK_ASSERT(enum_target != NULL); - - duk_push_object_internal(ctx); - res = duk_require_hobject(ctx, -1); - - DUK_DDD(DUK_DDDPRINT("created internal object")); - - /* [enum_target res] */ - - /* Target must be stored so that we can recheck whether or not - * keys still exist when we enumerate. This is not done if the - * enumeration result comes from a proxy trap as there is no - * real object to check against. - */ - duk_push_hobject(ctx, enum_target); - duk_put_prop_stridx(ctx, -2, DUK_STRIDX_INT_TARGET); - - /* Initialize index so that we skip internal control keys. */ - duk_push_int(ctx, DUK__ENUM_START_INDEX); - duk_put_prop_stridx(ctx, -2, DUK_STRIDX_INT_NEXT); - - /* - * Proxy object handling - */ - -#if defined(DUK_USE_ES6_PROXY) - if (DUK_LIKELY((enum_flags & DUK_ENUM_NO_PROXY_BEHAVIOR) != 0)) { - goto skip_proxy; - } - if (DUK_LIKELY(!duk_hobject_proxy_check(thr, - enum_target, - &h_proxy_target, - &h_proxy_handler))) { - goto skip_proxy; - } - - DUK_DDD(DUK_DDDPRINT("proxy enumeration")); - duk_push_hobject(ctx, h_proxy_handler); - if (!duk_get_prop_stridx(ctx, -1, DUK_STRIDX_ENUMERATE)) { - /* No need to replace the 'enum_target' value in stack, only the - * enum_target reference. This also ensures that the original - * enum target is reachable, which keeps the proxy and the proxy - * target reachable. We do need to replace the internal _Target. - */ - DUK_DDD(DUK_DDDPRINT("no enumerate trap, enumerate proxy target instead")); - DUK_DDD(DUK_DDDPRINT("h_proxy_target=%!O", (duk_heaphdr *) h_proxy_target)); - enum_target = h_proxy_target; - - duk_push_hobject(ctx, enum_target); /* -> [ ... enum_target res handler undefined target ] */ - duk_put_prop_stridx(ctx, -4, DUK_STRIDX_INT_TARGET); - - duk_pop_2(ctx); /* -> [ ... enum_target res ] */ - goto skip_proxy; - } - - /* [ ... enum_target res handler trap ] */ - duk_insert(ctx, -2); - duk_push_hobject(ctx, h_proxy_target); /* -> [ ... enum_target res trap handler target ] */ - duk_call_method(ctx, 1 /*nargs*/); /* -> [ ... enum_target res trap_result ] */ - h_trap_result = duk_require_hobject(ctx, -1); - DUK_UNREF(h_trap_result); - - /* Copy trap result keys into the enumerator object. */ - len = (duk_uint_fast32_t) duk_get_length(ctx, -1); - for (i = 0; i < len; i++) { - /* XXX: not sure what the correct semantic details are here, - * e.g. handling of missing values (gaps), handling of non-array - * trap results, etc. - * - * For keys, we simply skip non-string keys which seems to be - * consistent with how e.g. Object.keys() will process proxy trap - * results (ES6, Section 19.1.2.14). - */ - if (duk_get_prop_index(ctx, -1, i) && duk_is_string(ctx, -1)) { - /* [ ... enum_target res trap_result val ] */ - duk_push_true(ctx); - /* [ ... enum_target res trap_result val true ] */ - duk_put_prop(ctx, -4); - } else { - duk_pop(ctx); - } - } - /* [ ... enum_target res trap_result ] */ - duk_pop(ctx); - duk_remove(ctx, -2); - - /* [ ... res ] */ - - /* The internal _Target property is kept pointing to the original - * enumeration target (the proxy object), so that the enumerator - * 'next' operation can read property values if so requested. The - * fact that the _Target is a proxy disables key existence check - * during enumeration. - */ - DUK_DDD(DUK_DDDPRINT("proxy enumeration, final res: %!O", (duk_heaphdr *) res)); - goto compact_and_return; - - skip_proxy: -#endif /* DUK_USE_ES6_PROXY */ - - curr = enum_target; - while (curr) { - /* - * Virtual properties. - * - * String and buffer indices are virtual and always enumerable, - * 'length' is virtual and non-enumerable. Array and arguments - * object props have special behavior but are concrete. - */ - - if (DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(curr) || - DUK_HOBJECT_IS_BUFFEROBJECT(curr)) { - /* String and buffer enumeration behavior is identical now, - * so use shared handler. - */ - if (DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(curr)) { - duk_hstring *h_val; - h_val = duk_hobject_get_internal_value_string(thr->heap, curr); - DUK_ASSERT(h_val != NULL); /* string objects must not created without internal value */ - len = (duk_uint_fast32_t) DUK_HSTRING_GET_CHARLEN(h_val); - } else { - duk_hbufferobject *h_bufobj; - DUK_ASSERT(DUK_HOBJECT_IS_BUFFEROBJECT(curr)); - h_bufobj = (duk_hbufferobject *) curr; - if (h_bufobj == NULL) { - /* Neutered buffer, zero length seems - * like good behavior here. - */ - len = 0; - } else { - /* There's intentionally no check for - * current underlying buffer length. - */ - len = (duk_uint_fast32_t) (h_bufobj->length >> h_bufobj->shift); - } - } - - for (i = 0; i < len; i++) { - duk_hstring *k; - - k = duk_heap_string_intern_u32_checked(thr, i); - DUK_ASSERT(k); - duk_push_hstring(ctx, k); - duk_push_true(ctx); - - /* [enum_target res key true] */ - duk_put_prop(ctx, -3); - - /* [enum_target res] */ - } - - /* 'length' and other virtual properties are not - * enumerable, but are included if non-enumerable - * properties are requested. - */ - - if (enum_flags & DUK_ENUM_INCLUDE_NONENUMERABLE) { - duk_uint_fast32_t n; - - if (DUK_HOBJECT_IS_BUFFEROBJECT(curr)) { - n = sizeof(duk__bufferobject_virtual_props) / sizeof(duk_uint16_t); - } else { - DUK_ASSERT(DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(curr)); - DUK_ASSERT(duk__bufferobject_virtual_props[0] == DUK_STRIDX_LENGTH); - n = 1; /* only 'length' */ - } - - for (i = 0; i < n; i++) { - duk_push_hstring_stridx(ctx, duk__bufferobject_virtual_props[i]); - duk_push_true(ctx); - duk_put_prop(ctx, -3); - } - - } - } else if (DUK_HOBJECT_HAS_EXOTIC_DUKFUNC(curr)) { - if (enum_flags & DUK_ENUM_INCLUDE_NONENUMERABLE) { - duk_push_hstring_stridx(ctx, DUK_STRIDX_LENGTH); - duk_push_true(ctx); - duk_put_prop(ctx, -3); - } - } - - /* - * Array part - * - * Note: ordering between array and entry part must match 'abandon array' - * behavior in duk_hobject_props.c: key order after an array is abandoned - * must be the same. - */ - - for (i = 0; i < (duk_uint_fast32_t) DUK_HOBJECT_GET_ASIZE(curr); i++) { - duk_hstring *k; - duk_tval *tv; - - tv = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, curr, i); - if (DUK_TVAL_IS_UNUSED(tv)) { - continue; - } - k = duk_heap_string_intern_u32_checked(thr, i); - DUK_ASSERT(k); - - duk_push_hstring(ctx, k); - duk_push_true(ctx); - - /* [enum_target res key true] */ - duk_put_prop(ctx, -3); - - /* [enum_target res] */ - } - - /* - * Entries part - */ - - for (i = 0; i < (duk_uint_fast32_t) DUK_HOBJECT_GET_ENEXT(curr); i++) { - duk_hstring *k; - - k = DUK_HOBJECT_E_GET_KEY(thr->heap, curr, i); - if (!k) { - continue; - } - if (!DUK_HOBJECT_E_SLOT_IS_ENUMERABLE(thr->heap, curr, i) && - !(enum_flags & DUK_ENUM_INCLUDE_NONENUMERABLE)) { - continue; - } - if (DUK_HSTRING_HAS_INTERNAL(k) && - !(enum_flags & DUK_ENUM_INCLUDE_INTERNAL)) { - continue; - } - if ((enum_flags & DUK_ENUM_ARRAY_INDICES_ONLY) && - (DUK_HSTRING_GET_ARRIDX_SLOW(k) == DUK_HSTRING_NO_ARRAY_INDEX)) { - continue; - } - - DUK_ASSERT(DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, curr, i) || - !DUK_TVAL_IS_UNUSED(&DUK_HOBJECT_E_GET_VALUE_PTR(thr->heap, curr, i)->v)); - - duk_push_hstring(ctx, k); - duk_push_true(ctx); - - /* [enum_target res key true] */ - duk_put_prop(ctx, -3); - - /* [enum_target res] */ - } - - if (enum_flags & DUK_ENUM_OWN_PROPERTIES_ONLY) { - break; - } - - curr = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, curr); - } - - /* [enum_target res] */ - - duk_remove(ctx, -2); - - /* [res] */ - - if ((enum_flags & (DUK_ENUM_ARRAY_INDICES_ONLY | DUK_ENUM_SORT_ARRAY_INDICES)) == - (DUK_ENUM_ARRAY_INDICES_ONLY | DUK_ENUM_SORT_ARRAY_INDICES)) { - /* - * Some E5/E5.1 algorithms require that array indices are iterated - * in a strictly ascending order. This is the case for e.g. - * Array.prototype.forEach() and JSON.stringify() PropertyList - * handling. - * - * To ensure this property for arrays with an array part (and - * arbitrary objects too, since e.g. forEach() can be applied - * to an array), the caller can request that we sort the keys - * here. - */ - - /* XXX: avoid this at least when enum_target is an Array, it has an - * array part, and no ancestor properties were included? Not worth - * it for JSON, but maybe worth it for forEach(). - */ - - /* XXX: may need a 'length' filter for forEach() - */ - DUK_DDD(DUK_DDDPRINT("sort array indices by caller request")); - duk__sort_array_indices(thr, res); - } - -#if defined(DUK_USE_ES6_PROXY) - compact_and_return: -#endif - /* compact; no need to seal because object is internal */ - duk_hobject_compact_props(thr, res); - - DUK_DDD(DUK_DDDPRINT("created enumerator object: %!iT", (duk_tval *) duk_get_tval(ctx, -1))); -} - -/* - * Returns non-zero if a key and/or value was enumerated, and: - * - * [enum] -> [key] (get_value == 0) - * [enum] -> [key value] (get_value == 1) - * - * Returns zero without pushing anything on the stack otherwise. - */ -DUK_INTERNAL duk_bool_t duk_hobject_enumerator_next(duk_context *ctx, duk_bool_t get_value) { - duk_hthread *thr = (duk_hthread *) ctx; - duk_hobject *e; - duk_hobject *enum_target; - duk_hstring *res = NULL; - duk_uint_fast32_t idx; - duk_bool_t check_existence; - - DUK_ASSERT(ctx != NULL); - - /* [... enum] */ - - e = duk_require_hobject(ctx, -1); - - /* XXX use get tval ptr, more efficient */ - duk_get_prop_stridx(ctx, -1, DUK_STRIDX_INT_NEXT); - idx = (duk_uint_fast32_t) duk_require_uint(ctx, -1); - duk_pop(ctx); - DUK_DDD(DUK_DDDPRINT("enumeration: index is: %ld", (long) idx)); - - /* Enumeration keys are checked against the enumeration target (to see - * that they still exist). In the proxy enumeration case _Target will - * be the proxy, and checking key existence against the proxy is not - * required (or sensible, as the keys may be fully virtual). - */ - duk_get_prop_stridx(ctx, -1, DUK_STRIDX_INT_TARGET); - enum_target = duk_require_hobject(ctx, -1); - DUK_ASSERT(enum_target != NULL); -#if defined(DUK_USE_ES6_PROXY) - check_existence = (!DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(enum_target)); -#else - check_existence = 1; -#endif - duk_pop(ctx); /* still reachable */ - - DUK_DDD(DUK_DDDPRINT("getting next enum value, enum_target=%!iO, enumerator=%!iT", - (duk_heaphdr *) enum_target, (duk_tval *) duk_get_tval(ctx, -1))); - - /* no array part */ - for (;;) { - duk_hstring *k; - - if (idx >= DUK_HOBJECT_GET_ENEXT(e)) { - DUK_DDD(DUK_DDDPRINT("enumeration: ran out of elements")); - break; - } - - /* we know these because enum objects are internally created */ - k = DUK_HOBJECT_E_GET_KEY(thr->heap, e, idx); - DUK_ASSERT(k != NULL); - DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, e, idx)); - DUK_ASSERT(!DUK_TVAL_IS_UNUSED(&DUK_HOBJECT_E_GET_VALUE(thr->heap, e, idx).v)); - - idx++; - - /* recheck that the property still exists */ - if (check_existence && !duk_hobject_hasprop_raw(thr, enum_target, k)) { - DUK_DDD(DUK_DDDPRINT("property deleted during enumeration, skip")); - continue; - } - - DUK_DDD(DUK_DDDPRINT("enumeration: found element, key: %!O", (duk_heaphdr *) k)); - res = k; - break; - } - - DUK_DDD(DUK_DDDPRINT("enumeration: updating next index to %ld", (long) idx)); - - duk_push_u32(ctx, (duk_uint32_t) idx); - duk_put_prop_stridx(ctx, -2, DUK_STRIDX_INT_NEXT); - - /* [... enum] */ - - if (res) { - duk_push_hstring(ctx, res); - if (get_value) { - duk_push_hobject(ctx, enum_target); - duk_dup(ctx, -2); /* -> [... enum key enum_target key] */ - duk_get_prop(ctx, -2); /* -> [... enum key enum_target val] */ - duk_remove(ctx, -2); /* -> [... enum key val] */ - duk_remove(ctx, -3); /* -> [... key val] */ - } else { - duk_remove(ctx, -2); /* -> [... key] */ - } - return 1; - } else { - duk_pop(ctx); /* -> [...] */ - return 0; - } -} - -/* - * Get enumerated keys in an Ecmascript array. Matches Object.keys() behavior - * described in E5 Section 15.2.3.14. - */ - -DUK_INTERNAL duk_ret_t duk_hobject_get_enumerated_keys(duk_context *ctx, duk_small_uint_t enum_flags) { - duk_hthread *thr = (duk_hthread *) ctx; - duk_hobject *e; - duk_uint_fast32_t i; - duk_uint_fast32_t idx; - - DUK_ASSERT(ctx != NULL); - DUK_ASSERT(duk_get_hobject(ctx, -1) != NULL); - DUK_UNREF(thr); - - /* Create a temporary enumerator to get the (non-duplicated) key list; - * the enumerator state is initialized without being needed, but that - * has little impact. - */ - - duk_hobject_enumerator_create(ctx, enum_flags); - duk_push_array(ctx); - - /* [enum_target enum res] */ - - e = duk_require_hobject(ctx, -2); - DUK_ASSERT(e != NULL); - - idx = 0; - for (i = DUK__ENUM_START_INDEX; i < (duk_uint_fast32_t) DUK_HOBJECT_GET_ENEXT(e); i++) { - duk_hstring *k; - - k = DUK_HOBJECT_E_GET_KEY(thr->heap, e, i); - DUK_ASSERT(k); /* enumerator must have no keys deleted */ - - /* [enum_target enum res] */ - duk_push_hstring(ctx, k); - duk_put_prop_index(ctx, -2, idx); - idx++; - } - - /* [enum_target enum res] */ - duk_remove(ctx, -2); - - /* [enum_target res] */ - - return 1; /* return 1 to allow callers to tail call */ -} http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/ede68a10/thirdparty/civetweb-1.10/src/third_party/duktape-1.5.2/src-separate/duk_hobject_finalizer.c ---------------------------------------------------------------------- diff --git a/thirdparty/civetweb-1.10/src/third_party/duktape-1.5.2/src-separate/duk_hobject_finalizer.c b/thirdparty/civetweb-1.10/src/third_party/duktape-1.5.2/src-separate/duk_hobject_finalizer.c deleted file mode 100644 index 8cf6354..0000000 --- a/thirdparty/civetweb-1.10/src/third_party/duktape-1.5.2/src-separate/duk_hobject_finalizer.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Run an duk_hobject finalizer. Used for both reference counting - * and mark-and-sweep algorithms. Must never throw an error. - * - * There is no return value. Any return value or error thrown by - * the finalizer is ignored (although errors are debug logged). - * - * Notes: - * - * - The thread used for calling the finalizer is the same as the - * 'thr' argument. This may need to change later. - * - * - The finalizer thread 'top' assertions are there because it is - * critical that strict stack policy is observed (i.e. no cruft - * left on the finalizer stack). - */ - -#include "duk_internal.h" - -DUK_LOCAL duk_ret_t duk__finalize_helper(duk_context *ctx) { - duk_hthread *thr; - - DUK_ASSERT(ctx != NULL); - thr = (duk_hthread *) ctx; - - DUK_DDD(DUK_DDDPRINT("protected finalization helper running")); - - /* [... obj] */ - - /* XXX: Finalizer lookup should traverse the prototype chain (to allow - * inherited finalizers) but should not invoke accessors or proxy object - * behavior. At the moment this lookup will invoke proxy behavior, so - * caller must ensure that this function is not called if the target is - * a Proxy. - */ - - duk_get_prop_stridx(ctx, -1, DUK_STRIDX_INT_FINALIZER); /* -> [... obj finalizer] */ - if (!duk_is_callable(ctx, -1)) { - DUK_DDD(DUK_DDDPRINT("-> no finalizer or finalizer not callable")); - return 0; - } - duk_dup(ctx, -2); - duk_push_boolean(ctx, DUK_HEAP_HAS_FINALIZER_NORESCUE(thr->heap)); - DUK_DDD(DUK_DDDPRINT("-> finalizer found, calling finalizer")); - duk_call(ctx, 2); /* [ ... obj finalizer obj heapDestruct ] -> [ ... obj retval ] */ - DUK_DDD(DUK_DDDPRINT("finalizer finished successfully")); - return 0; - - /* Note: we rely on duk_safe_call() to fix up the stack for the caller, - * so we don't need to pop stuff here. There is no return value; - * caller determines rescued status based on object refcount. - */ -} - -DUK_INTERNAL void duk_hobject_run_finalizer(duk_hthread *thr, duk_hobject *obj) { - duk_context *ctx = (duk_context *) thr; - duk_ret_t rc; -#ifdef DUK_USE_ASSERTIONS - duk_idx_t entry_top; -#endif - - DUK_DDD(DUK_DDDPRINT("running object finalizer for object: %p", (void *) obj)); - - DUK_ASSERT(thr != NULL); - DUK_ASSERT(ctx != NULL); - DUK_ASSERT(obj != NULL); - DUK_ASSERT_VALSTACK_SPACE(thr, 1); - -#ifdef DUK_USE_ASSERTIONS - entry_top = duk_get_top(ctx); -#endif - /* - * Get and call the finalizer. All of this must be wrapped - * in a protected call, because even getting the finalizer - * may trigger an error (getter may throw one, for instance). - */ - - DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); - if (DUK_HEAPHDR_HAS_FINALIZED((duk_heaphdr *) obj)) { - DUK_D(DUK_DPRINT("object already finalized, avoid running finalizer twice: %!O", obj)); - return; - } - DUK_HEAPHDR_SET_FINALIZED((duk_heaphdr *) obj); /* ensure never re-entered until rescue cycle complete */ - if (DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(obj)) { - /* This shouldn't happen; call sites should avoid looking up - * _Finalizer "through" a Proxy, but ignore if we come here - * with a Proxy to avoid finalizer re-entry. - */ - DUK_D(DUK_DPRINT("object is a proxy, skip finalizer call")); - return; - } - - /* XXX: use a NULL error handler for the finalizer call? */ - - DUK_DDD(DUK_DDDPRINT("-> finalizer found, calling wrapped finalize helper")); - duk_push_hobject(ctx, obj); /* this also increases refcount by one */ - rc = duk_safe_call(ctx, duk__finalize_helper, 0 /*nargs*/, 1 /*nrets*/); /* -> [... obj retval/error] */ - DUK_ASSERT_TOP(ctx, entry_top + 2); /* duk_safe_call discipline */ - - if (rc != DUK_EXEC_SUCCESS) { - /* Note: we ask for one return value from duk_safe_call to get this - * error debugging here. - */ - DUK_D(DUK_DPRINT("wrapped finalizer call failed for object %p (ignored); error: %!T", - (void *) obj, (duk_tval *) duk_get_tval(ctx, -1))); - } - duk_pop_2(ctx); /* -> [...] */ - - DUK_ASSERT_TOP(ctx, entry_top); -}