5 #include "duk_internal.h"
11 DUK_INTERNAL duk_ret_t
duk_bi_pointer_constructor(duk_context
*ctx
) {
12 /* XXX: this behavior is quite useless now; it would be nice to be able
13 * to create pointer values from e.g. numbers or strings. Numbers are
14 * problematic on 64-bit platforms though. Hex encoded strings?
16 if (duk_get_top(ctx
) == 0) {
17 duk_push_pointer(ctx
, NULL
);
19 duk_to_pointer(ctx
, 0);
21 DUK_ASSERT(duk_is_pointer(ctx
, 0));
24 if (duk_is_constructor_call(ctx
)) {
25 duk_push_object_helper(ctx
,
26 DUK_HOBJECT_FLAG_EXTENSIBLE
|
27 DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_POINTER
),
28 DUK_BIDX_POINTER_PROTOTYPE
);
30 /* Pointer object internal value is immutable */
32 duk_xdef_prop_stridx(ctx
, -2, DUK_STRIDX_INT_VALUE
, DUK_PROPDESC_FLAGS_NONE
);
34 /* Note: unbalanced stack on purpose */
40 * toString(), valueOf()
43 DUK_INTERNAL duk_ret_t
duk_bi_pointer_prototype_tostring_shared(duk_context
*ctx
) {
45 duk_small_int_t to_string
= duk_get_current_magic(ctx
);
48 tv
= duk_require_tval(ctx
, -1);
49 DUK_ASSERT(tv
!= NULL
);
51 if (DUK_TVAL_IS_POINTER(tv
)) {
53 } else if (DUK_TVAL_IS_OBJECT(tv
)) {
54 duk_hobject
*h
= DUK_TVAL_GET_OBJECT(tv
);
55 DUK_ASSERT(h
!= NULL
);
57 /* Must be a "pointer object", i.e. class "Pointer" */
58 if (DUK_HOBJECT_GET_CLASS_NUMBER(h
) != DUK_HOBJECT_CLASS_POINTER
) {
62 duk_get_prop_stridx(ctx
, -1, DUK_STRIDX_INT_VALUE
);
68 duk_to_string(ctx
, -1);
73 return DUK_RET_TYPE_ERROR
;