So it can be re-used by Set objects.
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/jscript/set.c | 64 +++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 29 deletions(-)
diff --git a/dlls/jscript/set.c b/dlls/jscript/set.c index d87ce97..8946dbb 100644 --- a/dlls/jscript/set.c +++ b/dlls/jscript/set.c @@ -127,6 +127,40 @@ static void delete_map_entry(MapInstance *map, struct jsval_map_entry *entry) release_map_entry(entry); }
+static HRESULT iterate_map(MapInstance *map, script_ctx_t *ctx, unsigned argc, jsval_t *argv, jsval_t *r) +{ + struct jsval_map_entry *entry; + HRESULT hres; + + if(!argc || !is_object_instance(argv[0])) { + FIXME("invalid callback %s\n", debugstr_jsval(argc ? argv[0] : jsval_undefined())); + return E_FAIL; + } + + if(argc > 1) { + FIXME("Unsupported argument\n"); + return E_NOTIMPL; + } + + LIST_FOR_EACH_ENTRY(entry, &map->entries, struct jsval_map_entry, list_entry) { + jsval_t args[2], v; + if(entry->deleted) + continue; + args[0] = entry->value; + args[1] = entry->key; + grab_map_entry(entry); + hres = disp_call_value(ctx, get_object(argv[0]), NULL, DISPATCH_METHOD, + ARRAY_SIZE(args), args, &v); + release_map_entry(entry); + if(FAILED(hres)) + return hres; + jsval_release(v); + } + + if(r) *r = jsval_undefined(); + return S_OK; +} + static HRESULT Map_clear(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) { @@ -170,8 +204,6 @@ static HRESULT Map_delete(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned static HRESULT Map_forEach(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) { - jsval_t callback = argc ? argv[0] : jsval_undefined(); - struct jsval_map_entry *entry; MapInstance *map; HRESULT hres;
@@ -181,33 +213,7 @@ static HRESULT Map_forEach(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigne
TRACE("%p (%s)\n", map, debugstr_jsval(argc >= 1 ? argv[0] : jsval_undefined()));
- if(!is_object_instance(callback)) { - FIXME("invalid callback %s\n", debugstr_jsval(callback)); - return E_FAIL; - } - - if(argc > 1) { - FIXME("Unsupported argument\n"); - return E_NOTIMPL; - } - - LIST_FOR_EACH_ENTRY(entry, &map->entries, struct jsval_map_entry, list_entry) { - jsval_t args[2], v; - if(entry->deleted) - continue; - args[0] = entry->value; - args[1] = entry->key; - grab_map_entry(entry); - hres = disp_call_value(ctx, get_object(argv[0]), NULL, DISPATCH_METHOD, - ARRAY_SIZE(args), args, &v); - release_map_entry(entry); - if(FAILED(hres)) - return hres; - jsval_release(v); - } - - if(r) *r = jsval_undefined(); - return S_OK; + return iterate_map(map, ctx, argc, argv, r); }
static HRESULT Map_get(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv,