| 140 | typedef std::unordered_map<void*, duk_uarridx_t> RefMap; |
| 141 | |
| 142 | static RefMap* get_ref_map(duk_context* ctx) |
| 143 | { |
| 144 | static const char* DUKGLUE_REF_MAP = "dukglue_ref_map"; |
| 145 | static const char* PTR = "ptr"; |
| 146 | |
| 147 | duk_push_heap_stash(ctx); |
| 148 | |
| 149 | if (!duk_has_prop_string(ctx, -1, DUKGLUE_REF_MAP)) { |
| 150 | // doesn't exist yet, need to create it |
| 151 | duk_push_object(ctx); |
| 152 | |
| 153 | duk_push_pointer(ctx, new RefMap()); |
| 154 | duk_put_prop_string(ctx, -2, PTR); |
| 155 | |
| 156 | duk_push_c_function(ctx, ref_map_finalizer, 1); |
| 157 | duk_set_finalizer(ctx, -2); |
| 158 | |
| 159 | duk_put_prop_string(ctx, -2, DUKGLUE_REF_MAP); |
| 160 | } |
| 161 | |
| 162 | duk_get_prop_string(ctx, -1, DUKGLUE_REF_MAP); |
| 163 | duk_get_prop_string(ctx, -1, PTR); |
| 164 | RefMap* map = static_cast<RefMap*>(duk_require_pointer(ctx, -1)); |
| 165 | duk_pop_3(ctx); |
| 166 | |
| 167 | return map; |
| 168 | } |
| 169 | |
| 170 | static duk_ret_t ref_map_finalizer(duk_context* ctx) |
| 171 | { |
nothing calls this directly
no outgoing calls
no test coverage detected