DUK_INTERNAL duk_hcompfunc *duk_hcompfunc_alloc(duk_heap *heap, duk_uint_t hobject_flags) { duk_hcompfunc *res; res = (duk_hcompfunc *) DUK_ALLOC(heap, sizeof(duk_hcompfunc)); if (DUK_UNLIKELY(res == NULL)) { return NULL; } DUK_MEMZERO(res, sizeof(duk_hcompfunc)); duk__init_object_parts(heap, &res->obj, hobject_flags); #if defined(DUK_USE_EXPLICIT_NULL_INIT) #if defined(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 res->lex_env = NULL; res->var_env = NULL; #endif return res; }
DUK_INTERNAL duk_harray *duk_harray_alloc(duk_heap *heap, duk_uint_t hobject_flags) { duk_harray *res; res = (duk_harray *) DUK_ALLOC(heap, sizeof(duk_harray)); if (DUK_UNLIKELY(res == NULL)) { return NULL; } DUK_MEMZERO(res, sizeof(duk_harray)); duk__init_object_parts(heap, &res->obj, hobject_flags); DUK_ASSERT(res->length == 0); return res; }
duk_hnativefunction *duk_hnativefunction_alloc(duk_heap *heap, int 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_hnatfunc *duk_hnatfunc_alloc(duk_heap *heap, duk_uint_t hobject_flags) { duk_hnatfunc *res; res = (duk_hnatfunc *) DUK_ALLOC(heap, sizeof(duk_hnatfunc)); if (DUK_UNLIKELY(res == NULL)) { return NULL; } DUK_MEMZERO(res, sizeof(duk_hnatfunc)); duk__init_object_parts(heap, &res->obj, hobject_flags); #if defined(DUK_USE_EXPLICIT_NULL_INIT) res->func = NULL; #endif return res; }
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 (DUK_UNLIKELY(res == NULL)) { return NULL; } DUK_MEMZERO(res, sizeof(duk_hthread)); duk__init_object_parts(heap, &res->obj, hobject_flags); #if defined(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, #if defined(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; }
DUK_INTERNAL duk_hbufobj *duk_hbufobj_alloc(duk_heap *heap, duk_uint_t hobject_flags) { duk_hbufobj *res; res = (duk_hbufobj *) DUK_ALLOC(heap, sizeof(duk_hbufobj)); if (DUK_UNLIKELY(res == NULL)) { return NULL; } DUK_MEMZERO(res, sizeof(duk_hbufobj)); duk__init_object_parts(heap, &res->obj, hobject_flags); #if defined(DUK_USE_EXPLICIT_NULL_INIT) res->buf = NULL; res->buf_prop = NULL; #endif DUK_ASSERT_HBUFOBJ_VALID(res); return res; }
duk_hobject *duk_hobject_alloc(duk_heap *heap, int 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_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_COMPFUNC) == 0); DUK_ASSERT((hobject_flags & DUK_HOBJECT_FLAG_NATFUNC) == 0); DUK_ASSERT((hobject_flags & DUK_HOBJECT_FLAG_THREAD) == 0); res = (duk_hobject *) DUK_ALLOC(heap, sizeof(duk_hobject)); if (DUK_UNLIKELY(res == NULL)) { return NULL; } DUK_MEMZERO(res, sizeof(duk_hobject)); duk__init_object_parts(heap, res, hobject_flags); return res; }
duk_hthread *duk_hthread_alloc(duk_heap *heap, int 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->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->strs = NULL; { 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; }