mirror of
git://source.winehq.org/git/wine.git
synced 2024-09-02 10:23:37 +00:00
jscript: Iterate through the map in a helper function.
So it can be re-used by Set objects. Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com> Signed-off-by: Jacek Caban <jacek@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
27ce397307
commit
ce644eedae
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue