本文整理汇总了C++中DUK_ASSERT_CTX_VALID函数的典型用法代码示例。如果您正苦于以下问题:C++ DUK_ASSERT_CTX_VALID函数的具体用法?C++ DUK_ASSERT_CTX_VALID怎么用?C++ DUK_ASSERT_CTX_VALID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DUK_ASSERT_CTX_VALID函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: duk_call
DUK_EXTERNAL void duk_call(duk_context *ctx, duk_idx_t nargs) {
duk_hthread *thr = (duk_hthread *) ctx;
duk_small_uint_t call_flags;
duk_idx_t idx_func;
DUK_ASSERT_CTX_VALID(ctx);
DUK_ASSERT(thr != NULL);
idx_func = duk_get_top(ctx) - nargs - 1;
if (idx_func < 0 || nargs < 0) {
/* note that we can't reliably pop anything here */
DUK_ERROR_TYPE_INVALID_ARGS(thr);
}
/* XXX: awkward; we assume there is space for this, overwrite
* directly instead?
*/
duk_push_undefined(ctx);
duk_insert(ctx, idx_func + 1);
call_flags = 0; /* not protected, respect reclimit, not constructor */
duk_handle_call_unprotected(thr, /* thread */
nargs, /* num_stack_args */
call_flags); /* call_flags */
}
示例2: duk_put_prop
DUK_EXTERNAL duk_bool_t duk_put_prop(duk_context *ctx, duk_idx_t obj_index) {
duk_hthread *thr = (duk_hthread *) ctx;
duk_tval *tv_obj;
duk_tval *tv_key;
duk_tval *tv_val;
duk_small_int_t throw_flag;
duk_bool_t rc;
DUK_ASSERT_CTX_VALID(ctx);
/* Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property put right now (putprop protects
* against it internally).
*/
tv_obj = duk_require_tval(ctx, obj_index);
tv_key = duk_require_tval(ctx, -2);
tv_val = duk_require_tval(ctx, -1);
throw_flag = duk_is_strict_call(ctx);
rc = duk_hobject_putprop(thr, tv_obj, tv_key, tv_val, throw_flag);
DUK_ASSERT(rc == 0 || rc == 1);
duk_pop_2(ctx); /* remove key and value */
return rc; /* 1 if property found, 0 otherwise */
}
示例3: duk_get_magic
DUK_EXTERNAL duk_int_t duk_get_magic(duk_context *ctx, duk_idx_t idx) {
duk_hthread *thr = (duk_hthread *) ctx;
duk_tval *tv;
duk_hobject *h;
DUK_ASSERT_CTX_VALID(ctx);
tv = duk_require_tval(ctx, idx);
if (DUK_TVAL_IS_OBJECT(tv)) {
h = DUK_TVAL_GET_OBJECT(tv);
DUK_ASSERT(h != NULL);
if (!DUK_HOBJECT_HAS_NATFUNC(h)) {
goto type_error;
}
return (duk_int_t) ((duk_hnatfunc *) h)->magic;
} else if (DUK_TVAL_IS_LIGHTFUNC(tv)) {
duk_small_uint_t lf_flags = DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv);
return (duk_int_t) DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags);
}
/* fall through */
type_error:
DUK_ERROR_TYPE(thr, DUK_STR_UNEXPECTED_TYPE);
return 0;
}
示例4: duk_log_va
DUK_EXTERNAL void duk_log_va(duk_context *ctx, duk_int_t level, const char *fmt, va_list ap) {
/* stridx_logfunc[] must be static to allow initializer with old compilers like BCC */
static const duk_uint16_t stridx_logfunc[6] = {
DUK_STRIDX_LC_TRACE, DUK_STRIDX_LC_DEBUG, DUK_STRIDX_LC_INFO,
DUK_STRIDX_LC_WARN, DUK_STRIDX_LC_ERROR, DUK_STRIDX_LC_FATAL
};
DUK_ASSERT_CTX_VALID(ctx);
if (level < 0) {
level = 0;
} else if (level > (int) (sizeof(stridx_logfunc) / sizeof(duk_uint16_t)) - 1) {
level = (int) (sizeof(stridx_logfunc) / sizeof(duk_uint16_t)) - 1;
}
duk_push_hobject_bidx(ctx, DUK_BIDX_LOGGER_CONSTRUCTOR);
duk_get_prop_stridx(ctx, -1, DUK_STRIDX_CLOG);
duk_get_prop_stridx(ctx, -1, stridx_logfunc[level]);
duk_dup(ctx, -2);
/* [ ... Logger clog logfunc clog ] */
duk_push_vsprintf(ctx, fmt, ap);
/* [ ... Logger clog logfunc clog(=this) msg ] */
duk_call_method(ctx, 1 /*nargs*/);
/* [ ... Logger clog res ] */
duk_pop_3(ctx);
}
示例5: duk_get_current_magic
DUK_EXTERNAL duk_int_t duk_get_current_magic(duk_context *ctx) {
duk_hthread *thr = (duk_hthread *) ctx;
duk_activation *act;
duk_hobject *func;
DUK_ASSERT_CTX_VALID(ctx);
DUK_ASSERT(thr != NULL);
DUK_ASSERT_DISABLE(thr->callstack_top >= 0);
act = duk_hthread_get_current_activation(thr);
if (act) {
func = DUK_ACT_GET_FUNC(act);
if (!func) {
duk_tval *tv = &act->tv_func;
duk_small_uint_t lf_flags;
lf_flags = DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv);
return (duk_int_t) DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags);
}
DUK_ASSERT(func != NULL);
if (DUK_HOBJECT_IS_NATFUNC(func)) {
duk_hnatfunc *nf = (duk_hnatfunc *) func;
return (duk_int_t) nf->magic;
}
}
return 0;
}
示例6: duk__call_prop_prep_stack
/* Prepare value stack for a method call through an object property.
* May currently throw an error e.g. when getting the property.
*/
DUK_LOCAL void duk__call_prop_prep_stack(duk_context *ctx, duk_idx_t normalized_obj_idx, duk_idx_t nargs) {
DUK_ASSERT_CTX_VALID(ctx);
DUK_DDD(DUK_DDDPRINT("duk__call_prop_prep_stack, normalized_obj_idx=%ld, nargs=%ld, stacktop=%ld",
(long) normalized_obj_idx, (long) nargs, (long) duk_get_top(ctx)));
/* [... key arg1 ... argN] */
/* duplicate key */
duk_dup(ctx, -nargs - 1); /* Note: -nargs alone would fail for nargs == 0, this is OK */
duk_get_prop(ctx, normalized_obj_idx);
DUK_DDD(DUK_DDDPRINT("func: %!T", (duk_tval *) duk_get_tval(ctx, -1)));
/* [... key arg1 ... argN func] */
duk_replace(ctx, -nargs - 2);
/* [... func arg1 ... argN] */
duk_dup(ctx, normalized_obj_idx);
duk_insert(ctx, -nargs - 1);
/* [... func this arg1 ... argN] */
}
示例7: duk_next
DUK_EXTERNAL duk_bool_t duk_next(duk_context *ctx, duk_idx_t enum_index, duk_bool_t get_value) {
DUK_ASSERT_CTX_VALID(ctx);
duk_require_hobject(ctx, enum_index);
duk_dup(ctx, enum_index);
return duk_hobject_enumerator_next(ctx, get_value);
}
示例8: duk_get_prop_index
DUK_EXTERNAL duk_bool_t duk_get_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index) {
DUK_ASSERT_CTX_VALID(ctx);
obj_index = duk_require_normalize_index(ctx, obj_index);
duk_push_uarridx(ctx, arr_index);
return duk_get_prop(ctx, obj_index);
}
示例9: DUK_ASSERT_CTX_VALID
DUK_EXTERNAL void *duk_alloc_raw(duk_context *ctx, duk_size_t size) {
duk_hthread *thr = (duk_hthread *) ctx;
DUK_ASSERT_CTX_VALID(ctx);
return DUK_ALLOC_RAW(thr->heap, size);
}
示例10: duk_free
DUK_EXTERNAL void duk_free(duk_context *ctx, void *ptr) {
duk_hthread *thr = (duk_hthread *) ctx;
DUK_ASSERT_CTX_VALID(ctx);
DUK_FREE(thr->heap, ptr);
}
示例11: duk_enum
DUK_EXTERNAL void duk_enum(duk_context *ctx, duk_idx_t obj_index, duk_uint_t enum_flags) {
DUK_ASSERT_CTX_VALID(ctx);
duk_dup(ctx, obj_index);
duk_require_hobject_or_lfunc_coerce(ctx, -1);
duk_hobject_enumerator_create(ctx, enum_flags); /* [target] -> [enum] */
}
示例12: duk_put_prop_index
DUK_EXTERNAL duk_bool_t duk_put_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index) {
DUK_ASSERT_CTX_VALID(ctx);
obj_index = duk_require_normalize_index(ctx, obj_index);
duk_push_uarridx(ctx, arr_index);
duk_swap_top(ctx, -2); /* [val key] -> [key val] */
return duk_put_prop(ctx, obj_index);
}
示例13: duk_get_prop_string
DUK_EXTERNAL duk_bool_t duk_get_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key) {
DUK_ASSERT_CTX_VALID(ctx);
DUK_ASSERT(key != NULL);
obj_index = duk_require_normalize_index(ctx, obj_index);
duk_push_string(ctx, key);
return duk_get_prop(ctx, obj_index);
}
示例14: duk_set_magic
DUK_EXTERNAL void duk_set_magic(duk_context *ctx, duk_idx_t idx, duk_int_t magic) {
duk_hnatfunc *nf;
DUK_ASSERT_CTX_VALID(ctx);
nf = duk_require_hnatfunc(ctx, idx);
DUK_ASSERT(nf != NULL);
nf->magic = (duk_int16_t) magic;
}
示例15: duk_log
DUK_EXTERNAL void duk_log(duk_context *ctx, duk_int_t level, const char *fmt, ...) {
va_list ap;
DUK_ASSERT_CTX_VALID(ctx);
va_start(ap, fmt);
duk_log_va(ctx, level, fmt, ap);
va_end(ap);
}