mirror of
git://source.winehq.org/git/wine.git
synced 2024-09-02 09:03:38 +00:00
jscript: Implement Array.prototype.every.
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
c603fb490a
commit
eb80db6f8a
|
@ -1023,6 +1023,72 @@ static HRESULT Array_toLocaleString(script_ctx_t *ctx, jsval_t vthis, WORD flags
|
|||
return hres;
|
||||
}
|
||||
|
||||
static HRESULT Array_every(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv,
|
||||
jsval_t *r)
|
||||
{
|
||||
IDispatch *context_obj = NULL, *callback;
|
||||
jsval_t value, args[3], res;
|
||||
BOOL boolval, ret = TRUE;
|
||||
unsigned length, i;
|
||||
jsdisp_t *jsthis;
|
||||
HRESULT hres;
|
||||
|
||||
TRACE("\n");
|
||||
|
||||
hres = get_length(ctx, vthis, &jsthis, &length);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
/* FIXME: check IsCallable */
|
||||
if(!argc || !is_object_instance(argv[0])) {
|
||||
FIXME("Invalid arg %s\n", debugstr_jsval(argc ? argv[0] : jsval_undefined()));
|
||||
hres = E_INVALIDARG;
|
||||
goto done;
|
||||
}
|
||||
callback = get_object(argv[0]);
|
||||
|
||||
if(argc > 1 && !is_undefined(argv[1])) {
|
||||
if(!is_object_instance(argv[1])) {
|
||||
FIXME("Unsupported context this %s\n", debugstr_jsval(argv[1]));
|
||||
hres = E_NOTIMPL;
|
||||
goto done;
|
||||
}
|
||||
context_obj = get_object(argv[1]);
|
||||
}
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
hres = jsdisp_get_idx(jsthis, i, &value);
|
||||
if(FAILED(hres)) {
|
||||
if(hres == DISP_E_UNKNOWNNAME)
|
||||
continue;
|
||||
goto done;
|
||||
}
|
||||
args[0] = value;
|
||||
args[1] = jsval_number(i);
|
||||
args[2] = jsval_obj(jsthis);
|
||||
hres = disp_call_value(ctx, callback, context_obj, DISPATCH_METHOD, ARRAY_SIZE(args), args, &res);
|
||||
jsval_release(value);
|
||||
if(FAILED(hres))
|
||||
goto done;
|
||||
|
||||
hres = to_boolean(res, &boolval);
|
||||
jsval_release(res);
|
||||
if(FAILED(hres))
|
||||
goto done;
|
||||
if(!boolval) {
|
||||
ret = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(r)
|
||||
*r = jsval_bool(ret);
|
||||
hres = S_OK;
|
||||
done:
|
||||
jsdisp_release(jsthis);
|
||||
return hres;
|
||||
}
|
||||
|
||||
static HRESULT Array_filter(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv,
|
||||
jsval_t *r)
|
||||
{
|
||||
|
@ -1439,6 +1505,7 @@ static void Array_on_put(jsdisp_t *dispex, const WCHAR *name)
|
|||
|
||||
static const builtin_prop_t Array_props[] = {
|
||||
{L"concat", Array_concat, PROPF_METHOD|1},
|
||||
{L"every", Array_every, PROPF_METHOD|PROPF_ES5|1},
|
||||
{L"filter", Array_filter, PROPF_METHOD|PROPF_ES5|1},
|
||||
{L"forEach", Array_forEach, PROPF_METHOD|PROPF_ES5|1},
|
||||
{L"indexOf", Array_indexOf, PROPF_METHOD|PROPF_ES5|1},
|
||||
|
|
Loading…
Reference in a new issue