Browse Source

Add duk_is_buffer_data() API call

pull/1221/head
Sami Vaarala 8 years ago
parent
commit
3f6066e223
  1. 1
      src-input/duk_api_public.h.in
  2. 28
      src-input/duk_api_stack.c

1
src-input/duk_api_public.h.in

@ -570,6 +570,7 @@ DUK_EXTERNAL_DECL duk_bool_t duk_is_nan(duk_context *ctx, duk_idx_t idx);
DUK_EXTERNAL_DECL duk_bool_t duk_is_string(duk_context *ctx, duk_idx_t idx); DUK_EXTERNAL_DECL duk_bool_t duk_is_string(duk_context *ctx, duk_idx_t idx);
DUK_EXTERNAL_DECL duk_bool_t duk_is_object(duk_context *ctx, duk_idx_t idx); DUK_EXTERNAL_DECL duk_bool_t duk_is_object(duk_context *ctx, duk_idx_t idx);
DUK_EXTERNAL_DECL duk_bool_t duk_is_buffer(duk_context *ctx, duk_idx_t idx); DUK_EXTERNAL_DECL duk_bool_t duk_is_buffer(duk_context *ctx, duk_idx_t idx);
DUK_EXTERNAL_DECL duk_bool_t duk_is_buffer_data(duk_context *ctx, duk_idx_t idx);
DUK_EXTERNAL_DECL duk_bool_t duk_is_pointer(duk_context *ctx, duk_idx_t idx); DUK_EXTERNAL_DECL duk_bool_t duk_is_pointer(duk_context *ctx, duk_idx_t idx);
DUK_EXTERNAL_DECL duk_bool_t duk_is_lightfunc(duk_context *ctx, duk_idx_t idx); DUK_EXTERNAL_DECL duk_bool_t duk_is_lightfunc(duk_context *ctx, duk_idx_t idx);

28
src-input/duk_api_stack.c

@ -3238,6 +3238,34 @@ DUK_EXTERNAL duk_bool_t duk_is_buffer(duk_context *ctx, duk_idx_t idx) {
return duk__tag_check(ctx, idx, DUK_TAG_BUFFER); return duk__tag_check(ctx, idx, DUK_TAG_BUFFER);
} }
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_EXTERNAL duk_bool_t duk_is_buffer_data(duk_context *ctx, duk_idx_t idx) {
duk_tval *tv;
DUK_ASSERT_CTX_VALID(ctx);
tv = duk_get_tval_or_unused(ctx, idx);
DUK_ASSERT(tv != NULL);
if (DUK_TVAL_IS_BUFFER(tv)) {
return 1;
} else if (DUK_TVAL_IS_OBJECT(tv)) {
duk_hobject *h = DUK_TVAL_GET_OBJECT(tv);
DUK_ASSERT(h != NULL);
if (DUK_HOBJECT_IS_BUFOBJ(h)) {
return 1;
}
}
return 0;
}
#else /* DUK_USE_BUFFEROBJECT_SUPPORT */
DUK_EXTERNAL duk_bool_t duk_is_buffer_data(duk_context *ctx, duk_idx_t idx) {
DUK_ASSERT_CTX_VALID(ctx);
return duk_is_buffer(ctx, idx);
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
DUK_EXTERNAL duk_bool_t duk_is_pointer(duk_context *ctx, duk_idx_t idx) { DUK_EXTERNAL duk_bool_t duk_is_pointer(duk_context *ctx, duk_idx_t idx) {
DUK_ASSERT_CTX_VALID(ctx); DUK_ASSERT_CTX_VALID(ctx);
return duk__tag_check(ctx, idx, DUK_TAG_POINTER); return duk__tag_check(ctx, idx, DUK_TAG_POINTER);

Loading…
Cancel
Save