5 #include "duk_internal.h"
7 DUK_EXTERNAL
void duk_get_var(duk_context
*ctx
) {
8 duk_hthread
*thr
= (duk_hthread
*) ctx
;
10 duk_hstring
*h_varname
;
11 duk_small_int_t throw_flag
= 1; /* always throw ReferenceError for unresolvable */
13 DUK_ASSERT_CTX_VALID(ctx
);
15 h_varname
= duk_require_hstring(ctx
, -1); /* XXX: tostring? */
16 DUK_ASSERT(h_varname
!= NULL
);
18 act
= duk_hthread_get_current_activation(thr
);
20 (void) duk_js_getvar_activation(thr
, act
, h_varname
, throw_flag
); /* -> [ ... varname val this ] */
22 /* Outside any activation -> look up from global. */
23 DUK_ASSERT(thr
->builtins
[DUK_BIDX_GLOBAL_ENV
] != NULL
);
24 (void) duk_js_getvar_envrec(thr
, thr
->builtins
[DUK_BIDX_GLOBAL_ENV
], h_varname
, throw_flag
);
27 /* [ ... varname val this ] (because throw_flag == 1, always resolved) */
34 /* Return value would be pointless: because throw_flag==1, we always
35 * throw if the identifier doesn't resolve.
40 DUK_EXTERNAL
void duk_put_var(duk_context
*ctx
) {
41 duk_hthread
*thr
= (duk_hthread
*) ctx
;
43 duk_hstring
*h_varname
;
45 duk_small_int_t throw_flag
;
47 DUK_ASSERT_CTX_VALID(ctx
);
49 h_varname
= duk_require_hstring(ctx
, -2); /* XXX: tostring? */
50 DUK_ASSERT(h_varname
!= NULL
);
52 tv_val
= duk_require_tval(ctx
, -1);
54 throw_flag
= duk_is_strict_call(ctx
);
56 act
= duk_hthread_get_current_activation(thr
);
58 duk_js_putvar_activation(thr
, act
, h_varname
, tv_val
, throw_flag
); /* -> [ ... varname val this ] */
60 /* Outside any activation -> put to global. */
61 DUK_ASSERT(thr
->builtins
[DUK_BIDX_GLOBAL_ENV
] != NULL
);
62 duk_js_putvar_envrec(thr
, thr
->builtins
[DUK_BIDX_GLOBAL_ENV
], h_varname
, tv_val
, throw_flag
);
65 /* [ ... varname val ] */
74 DUK_EXTERNAL duk_bool_t
duk_del_var(duk_context
*ctx
) {
75 DUK_ASSERT_CTX_VALID(ctx
);
77 DUK_ERROR((duk_hthread
*) ctx
, DUK_ERR_UNIMPLEMENTED_ERROR
, DUK_STR_UNIMPLEMENTED
);
81 DUK_EXTERNAL duk_bool_t
duk_has_var(duk_context
*ctx
) {
82 DUK_ASSERT_CTX_VALID(ctx
);
84 DUK_ERROR((duk_hthread
*) ctx
, DUK_ERR_UNIMPLEMENTED_ERROR
, DUK_STR_UNIMPLEMENTED
);