ReactOS 0.4.15-dev-7924-g5949c20
array.c File Reference
#include <math.h>
#include <assert.h>
#include "jscript.h"
#include "wine/debug.h"
Include dependency graph for array.c:

Go to the source code of this file.

Classes

struct  ArrayInstance
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (jscript)
 
static ArrayInstancearray_from_jsdisp (jsdisp_t *jsdisp)
 
static ArrayInstancearray_from_vdisp (vdisp_t *vdisp)
 
static ArrayInstancearray_this (vdisp_t *jsthis)
 
unsigned array_get_length (jsdisp_t *array)
 
static HRESULT get_length (script_ctx_t *ctx, vdisp_t *vdisp, jsdisp_t **jsthis, DWORD *ret)
 
static HRESULT set_length (jsdisp_t *obj, DWORD length)
 
static WCHARidx_to_str (DWORD idx, WCHAR *ptr)
 
static HRESULT Array_get_length (script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
 
static HRESULT Array_set_length (script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t value)
 
static HRESULT concat_array (jsdisp_t *array, ArrayInstance *obj, DWORD *len)
 
static HRESULT concat_obj (jsdisp_t *array, IDispatch *obj, DWORD *len)
 
static HRESULT Array_concat (script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT array_join (script_ctx_t *ctx, jsdisp_t *array, DWORD length, const WCHAR *sep, unsigned seplen, jsval_t *r)
 
static HRESULT Array_join (script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_pop (script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_push (script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_reverse (script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_shift (script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_slice (script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT sort_cmp (script_ctx_t *ctx, jsdisp_t *cmp_func, jsval_t v1, jsval_t v2, INT *cmp)
 
static HRESULT Array_sort (script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_splice (script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_toString (script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_toLocaleString (script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_forEach (script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_indexOf (script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_map (script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_unshift (script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_get_value (script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
 
static void Array_destructor (jsdisp_t *dispex)
 
static void Array_on_put (jsdisp_t *dispex, const WCHAR *name)
 
static HRESULT ArrayConstr_isArray (script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT ArrayConstr_value (script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT alloc_array (script_ctx_t *ctx, jsdisp_t *object_prototype, ArrayInstance **ret)
 
HRESULT create_array_constr (script_ctx_t *ctx, jsdisp_t *object_prototype, jsdisp_t **ret)
 
HRESULT create_array (script_ctx_t *ctx, DWORD length, jsdisp_t **ret)
 

Variables

static const WCHAR lengthW [] = {'l','e','n','g','t','h',0}
 
static const WCHAR concatW [] = {'c','o','n','c','a','t',0}
 
static const WCHAR forEachW [] = {'f','o','r','E','a','c','h',0}
 
static const WCHAR joinW [] = {'j','o','i','n',0}
 
static const WCHAR popW [] = {'p','o','p',0}
 
static const WCHAR pushW [] = {'p','u','s','h',0}
 
static const WCHAR reverseW [] = {'r','e','v','e','r','s','e',0}
 
static const WCHAR shiftW [] = {'s','h','i','f','t',0}
 
static const WCHAR sliceW [] = {'s','l','i','c','e',0}
 
static const WCHAR sortW [] = {'s','o','r','t',0}
 
static const WCHAR spliceW [] = {'s','p','l','i','c','e',0}
 
static const WCHAR toStringW [] = {'t','o','S','t','r','i','n','g',0}
 
static const WCHAR toLocaleStringW [] = {'t','o','L','o','c','a','l','e','S','t','r','i','n','g',0}
 
static const WCHAR unshiftW [] = {'u','n','s','h','i','f','t',0}
 
static const WCHAR indexOfW [] = {'i','n','d','e','x','O','f',0}
 
static const WCHAR mapW [] = {'m','a','p',0}
 
static const WCHAR default_separatorW [] = {',',0}
 
static const builtin_prop_t Array_props []
 
static const builtin_info_t Array_info
 
static const builtin_prop_t ArrayInst_props []
 
static const builtin_info_t ArrayInst_info
 
static const WCHAR isArrayW [] = {'i','s','A','r','r','a','y',0}
 
static const builtin_prop_t ArrayConstr_props []
 
static const builtin_info_t ArrayConstr_info
 

Function Documentation

◆ alloc_array()

static HRESULT alloc_array ( script_ctx_t ctx,
jsdisp_t object_prototype,
ArrayInstance **  ret 
)
static

Definition at line 1326 of file array.c.

1327{
1329 HRESULT hres;
1330
1331 array = heap_alloc_zero(sizeof(ArrayInstance));
1332 if(!array)
1333 return E_OUTOFMEMORY;
1334
1335 if(object_prototype)
1336 hres = init_dispex(&array->dispex, ctx, &Array_info, object_prototype);
1337 else
1338 hres = init_dispex_from_constr(&array->dispex, ctx, &ArrayInst_info, ctx->array_constr);
1339
1340 if(FAILED(hres)) {
1342 return hres;
1343 }
1344
1345 *ret = array;
1346 return S_OK;
1347}
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
static const builtin_info_t ArrayInst_info
Definition: array.c:1248
static const builtin_info_t Array_info
Definition: array.c:1235
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
HRESULT init_dispex_from_constr(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *constr)
Definition: dispex.c:1030
HRESULT init_dispex(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *prototype)
Definition: dispex.c:919
HRESULT hres
Definition: protocol.c:465
int ret

Referenced by create_array(), and create_array_constr().

◆ Array_concat()

static HRESULT Array_concat ( script_ctx_t ctx,
vdisp_t jsthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 209 of file array.c.

211{
212 jsdisp_t *ret;
213 DWORD len = 0;
215
216 TRACE("\n");
217
218 hres = create_array(ctx, 0, &ret);
219 if(FAILED(hres))
220 return hres;
221
222 hres = concat_obj(ret, jsthis->u.disp, &len);
223 if(SUCCEEDED(hres)) {
224 DWORD i;
225
226 for(i=0; i < argc; i++) {
229 else
231 if(FAILED(hres))
232 break;
233 }
234 }
235
236 if(FAILED(hres))
237 return hres;
238
239 if(r)
240 *r = jsval_obj(ret);
241 else
243 return S_OK;
244}
static int argc
Definition: ServiceArgs.c:12
HRESULT create_array(script_ctx_t *ctx, DWORD length, jsdisp_t **ret)
Definition: array.c:1381
static HRESULT concat_obj(jsdisp_t *array, IDispatch *obj, DWORD *len)
Definition: array.c:191
unsigned long DWORD
Definition: ntddk_ex.h:95
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define SUCCEEDED(hr)
Definition: intsafe.h:50
HRESULT jsdisp_propput_idx(jsdisp_t *obj, DWORD idx, jsval_t val)
Definition: dispex.c:1349
static void jsdisp_release(jsdisp_t *jsdisp)
Definition: jscript.h:268
static jsval_t jsval_obj(jsdisp_t *obj)
Definition: jsval.h:125
static IDispatch * get_object(jsval_t v)
Definition: jsval.h:219
static BOOL is_object_instance(jsval_t v)
Definition: jsval.h:166
#define argv
Definition: mplay32.c:18
#define TRACE(s)
Definition: solgame.cpp:4
union vdisp_t::@443 u
IDispatch * disp
Definition: jscript.h:142

◆ Array_destructor()

static void Array_destructor ( jsdisp_t dispex)
static

Definition at line 1190 of file array.c.

1191{
1192 heap_free(dispex);
1193}

◆ Array_forEach()

static HRESULT Array_forEach ( script_ctx_t ctx,
vdisp_t vthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 957 of file array.c.

959{
960 jsval_t value, args[3], res;
961 jsdisp_t *jsthis;
962 unsigned length, i;
964
965 TRACE("\n");
966
967 hres = get_length(ctx, vthis, &jsthis, &length);
968 if(FAILED(hres))
969 return hres;
970
971 /* Fixme check IsCallable */
972 if(!argc || !is_object_instance(argv[0]) || !get_object(argv[0])) {
973 FIXME("Invalid arg %s\n", debugstr_jsval(argc ? argv[0] : jsval_undefined()));
974 return E_INVALIDARG;
975 }
976
977 if(argc > 1 && !is_undefined(argv[1])) {
978 FIXME("Unsupported context this %s\n", debugstr_jsval(argv[1]));
979 return E_NOTIMPL;
980 }
981
982 for(i = 0; i < length; i++) {
983 hres = jsdisp_get_idx(jsthis, i, &value);
985 continue;
986 if(FAILED(hres))
987 return hres;
988
989 args[0] = value;
990 args[1] = jsval_number(i);
991 args[2] = jsval_obj(jsthis);
994 if(FAILED(hres))
995 return hres;
997 }
998
999 if(r) *r = jsval_undefined();
1000 return S_OK;
1001}
static HRESULT get_length(script_ctx_t *ctx, vdisp_t *vdisp, jsdisp_t **jsthis, DWORD *ret)
Definition: array.c:79
#define ARRAY_SIZE(A)
Definition: main.h:33
#define FIXME(fmt,...)
Definition: debug.h:111
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define NULL
Definition: types.h:112
GLuint res
Definition: glext.h:9613
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
HRESULT disp_call_value(script_ctx_t *ctx, IDispatch *disp, IDispatch *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: dispex.c:1228
HRESULT jsdisp_get_idx(jsdisp_t *obj, DWORD idx, jsval_t *r)
Definition: dispex.c:1425
const char * debugstr_jsval(const jsval_t) DECLSPEC_HIDDEN
Definition: jsutils.c:35
void jsval_release(jsval_t val)
Definition: jsutils.c:191
static jsval_t jsval_undefined(void)
Definition: jsval.h:137
static BOOL is_undefined(jsval_t v)
Definition: jsval.h:171
static jsval_t jsval_number(double n)
Definition: jsval.h:144
#define DISPATCH_METHOD
Definition: oleauto.h:1006
Definition: jsval.h:54
Definition: match.c:390
Definition: pdh_main.c:94
#define DISP_E_UNKNOWNNAME
Definition: winerror.h:2515

◆ array_from_jsdisp()

static ArrayInstance * array_from_jsdisp ( jsdisp_t jsdisp)
inlinestatic

Definition at line 58 of file array.c.

59{
60 return CONTAINING_RECORD(jsdisp, ArrayInstance, dispex);
61}
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by array_from_vdisp(), array_get_length(), Array_get_length(), Array_get_value(), Array_on_put(), Array_set_length(), concat_obj(), and set_length().

◆ array_from_vdisp()

static ArrayInstance * array_from_vdisp ( vdisp_t vdisp)
inlinestatic

Definition at line 63 of file array.c.

64{
65 return array_from_jsdisp(vdisp->u.jsdisp);
66}
static ArrayInstance * array_from_jsdisp(jsdisp_t *jsdisp)
Definition: array.c:58
jsdisp_t * jsdisp
Definition: jscript.h:144

Referenced by array_this().

◆ array_get_length()

unsigned array_get_length ( jsdisp_t array)

Definition at line 73 of file array.c.

74{
77}
#define assert(x)
Definition: debug.h:53
@ JSCLASS_ARRAY
Definition: jscript.h:121
static BOOL is_class(jsdisp_t *jsdisp, jsclass_t class)
Definition: jscript.h:504
DWORD length
Definition: array.c:36

Referenced by stringify_array().

◆ Array_get_length()

static HRESULT Array_get_length ( script_ctx_t ctx,
jsdisp_t jsthis,
jsval_t r 
)
static

Definition at line 133 of file array.c.

134{
135 TRACE("%p\n", jsthis);
136
138 return S_OK;
139}

◆ Array_get_value()

static HRESULT Array_get_value ( script_ctx_t ctx,
jsdisp_t jsthis,
jsval_t r 
)
static

Definition at line 1180 of file array.c.

1181{
1183
1184 TRACE("\n");
1185
1186 return array_join(ctx, &array->dispex, array->length, default_separatorW,
1188}
static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, const WCHAR *sep, unsigned seplen, jsval_t *r)
Definition: array.c:246
static const WCHAR default_separatorW[]
Definition: array.c:56
#define lstrlenW
Definition: compat.h:750

◆ Array_indexOf()

static HRESULT Array_indexOf ( script_ctx_t ctx,
vdisp_t vthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 1003 of file array.c.

1005{
1006 jsdisp_t *jsthis;
1007 unsigned length, i, from = 0;
1009 BOOL eq;
1010 HRESULT hres;
1011
1012 TRACE("\n");
1013
1014 hres = get_length(ctx, vthis, &jsthis, &length);
1015 if(FAILED(hres))
1016 return hres;
1017 if(!length) {
1018 if(r) *r = jsval_number(-1);
1019 return S_OK;
1020 }
1021
1022 search = argc ? argv[0] : jsval_undefined();
1023
1024 if(argc > 1) {
1025 double from_arg;
1026
1027 hres = to_integer(ctx, argv[1], &from_arg);
1028 if(FAILED(hres))
1029 return hres;
1030
1031 if(from_arg >= 0)
1032 from = min(from_arg, length);
1033 else
1034 from = max(from_arg + length, 0);
1035 }
1036
1037 for(i = from; i < length; i++) {
1038 hres = jsdisp_get_idx(jsthis, i, &value);
1040 continue;
1041 if(FAILED(hres))
1042 return hres;
1043
1046 if(FAILED(hres))
1047 return hres;
1048 if(eq) {
1049 if(r) *r = jsval_number(i);
1050 return S_OK;
1051 }
1052 }
1053
1054 if(r) *r = jsval_number(-1);
1055 return S_OK;
1056}
HRESULT jsval_strict_equal(jsval_t lval, jsval_t rval, BOOL *ret)
Definition: engine.c:531
unsigned int BOOL
Definition: ntddk_ex.h:94
HRESULT to_integer(script_ctx_t *, jsval_t, double *) DECLSPEC_HIDDEN
Definition: jsutils.c:648
#define eq(received, expected, label, type)
Definition: locale.c:144
#define min(a, b)
Definition: monoChain.cc:55
static short search(int val, const short *table, int size)
Definition: msg711.c:255
CardRegion * from
Definition: spigame.cpp:19
#define max(a, b)
Definition: svc.c:63

◆ array_join()

static HRESULT array_join ( script_ctx_t ctx,
jsdisp_t array,
DWORD  length,
const WCHAR sep,
unsigned  seplen,
jsval_t r 
)
static

Definition at line 246 of file array.c.

248{
249 jsstr_t **str_tab, *ret = NULL;
250 jsval_t val;
251 DWORD i;
253
254 if(!length) {
255 if(r)
257 return S_OK;
258 }
259
260 str_tab = heap_alloc_zero(length * sizeof(*str_tab));
261 if(!str_tab)
262 return E_OUTOFMEMORY;
263
264 for(i=0; i < length; i++) {
266 if(hres == DISP_E_UNKNOWNNAME) {
267 hres = S_OK;
268 continue;
269 } else if(FAILED(hres))
270 break;
271
272 if(!is_undefined(val) && !is_null(val)) {
273 hres = to_string(ctx, val, str_tab+i);
275 if(FAILED(hres))
276 break;
277 }
278 }
279
280 if(SUCCEEDED(hres)) {
281 DWORD len = 0;
282
283 if(str_tab[0])
284 len = jsstr_length(str_tab[0]);
285 for(i=1; i < length; i++) {
286 len += seplen;
287 if(str_tab[i])
288 len += jsstr_length(str_tab[i]);
289 if(len > JSSTR_MAX_LENGTH) {
291 break;
292 }
293 }
294
295 if(SUCCEEDED(hres)) {
296 WCHAR *ptr = NULL;
297
299 if(ret) {
300 if(str_tab[0])
301 ptr += jsstr_flush(str_tab[0], ptr);
302
303 for(i=1; i < length; i++) {
304 if(seplen) {
305 memcpy(ptr, sep, seplen*sizeof(WCHAR));
306 ptr += seplen;
307 }
308
309 if(str_tab[i])
310 ptr += jsstr_flush(str_tab[i], ptr);
311 }
312 }else {
314 }
315 }
316 }
317
318 for(i=0; i < length; i++) {
319 if(str_tab[i])
320 jsstr_release(str_tab[i]);
321 }
322 heap_free(str_tab);
323 if(FAILED(hres))
324 return hres;
325
326 TRACE("= %s\n", debugstr_jsstr(ret));
327
328 if(r)
329 *r = jsval_string(ret);
330 else
332 return S_OK;
333}
#define E_FAIL
Definition: ddrawi.h:102
GLuint GLfloat * val
Definition: glext.h:7180
static HRESULT to_string(VARIANT *src, BSTR *dst)
Definition: host.c:47
jsstr_t * jsstr_empty(void)
Definition: jsstr.c:288
const char * debugstr_jsstr(jsstr_t *str)
Definition: jsstr.c:37
jsstr_t * jsstr_alloc_buf(unsigned len, WCHAR **buf)
Definition: jsstr.c:69
#define JSSTR_MAX_LENGTH
Definition: jsstr.h:45
static void jsstr_release(jsstr_t *str)
Definition: jsstr.h:110
static unsigned jsstr_length(jsstr_t *str)
Definition: jsstr.h:58
static unsigned jsstr_flush(jsstr_t *str, WCHAR *buf)
Definition: jsstr.h:148
static jsval_t jsval_string(jsstr_t *str)
Definition: jsval.h:109
static BOOL is_null(jsval_t v)
Definition: jsval.h:176
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static PVOID ptr
Definition: dispmode.c:27
Definition: jsstr.h:39
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by Array_get_value(), Array_join(), and Array_toString().

◆ Array_join()

static HRESULT Array_join ( script_ctx_t ctx,
vdisp_t vthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 336 of file array.c.

338{
339 jsdisp_t *jsthis;
342
343 TRACE("\n");
344
345 hres = get_length(ctx, vthis, &jsthis, &length);
346 if(FAILED(hres))
347 return hres;
348
349 if(argc) {
350 const WCHAR *sep;
351 jsstr_t *sep_str;
352
353 hres = to_flat_string(ctx, argv[0], &sep_str, &sep);
354 if(FAILED(hres))
355 return hres;
356
357 hres = array_join(ctx, jsthis, length, sep, jsstr_length(sep_str), r);
358
359 jsstr_release(sep_str);
360 }else {
362 }
363
364 return hres;
365}
HRESULT to_flat_string(script_ctx_t *, jsval_t, jsstr_t **, const WCHAR **) DECLSPEC_HIDDEN
Definition: jsutils.c:798

◆ Array_map()

static HRESULT Array_map ( script_ctx_t ctx,
vdisp_t vthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 1058 of file array.c.

1059{
1060 IDispatch *context_this = NULL, *callback;
1061 jsval_t callback_args[3], mapped_value;
1062 jsdisp_t *jsthis, *array;
1063 DWORD length, k;
1064 HRESULT hres;
1065
1066 TRACE("\n");
1067
1068 hres = get_length(ctx, vthis, &jsthis, &length);
1069 if(FAILED(hres)) {
1070 FIXME("Could not get length\n");
1071 return hres;
1072 }
1073
1074 /* Fixme check IsCallable */
1075 if(!argc || !is_object_instance(argv[0]) || !get_object(argv[0])) {
1076 FIXME("Invalid arg %s\n", debugstr_jsval(argc ? argv[0] : jsval_undefined()));
1077 return E_INVALIDARG;
1078 }
1079 callback = get_object(argv[0]);
1080
1081 if(argc > 1) {
1082 if(is_object_instance(argv[1]) && get_object(argv[1])) {
1083 context_this = get_object(argv[1]);
1084 }else if(!is_undefined(argv[1])) {
1085 FIXME("Unsupported context this %s\n", debugstr_jsval(argv[1]));
1086 return E_NOTIMPL;
1087 }
1088 }
1089
1091 if(FAILED(hres))
1092 return hres;
1093
1094 for(k = 0; k < length; k++) {
1095 hres = jsdisp_get_idx(jsthis, k, &callback_args[0]);
1097 continue;
1098 if(FAILED(hres))
1099 break;
1100
1101 callback_args[1] = jsval_number(k);
1102 callback_args[2] = jsval_obj(jsthis);
1103 hres = disp_call_value(ctx, callback, context_this, DISPATCH_METHOD, 3, callback_args, &mapped_value);
1104 jsval_release(callback_args[0]);
1105 if(FAILED(hres))
1106 break;
1107
1108 hres = jsdisp_propput_idx(array, k, mapped_value);
1109 if(FAILED(hres))
1110 break;
1111 }
1112
1113 if(SUCCEEDED(hres) && r)
1114 *r = jsval_obj(array);
1115 else
1117 return hres;
1118}
static IPrintDialogCallback callback
Definition: printdlg.c:326
int k
Definition: mpi.c:3369

◆ Array_on_put()

static void Array_on_put ( jsdisp_t dispex,
const WCHAR name 
)
static

Definition at line 1195 of file array.c.

1196{
1198 const WCHAR *ptr = name;
1199 DWORD id = 0;
1200
1201 if(!iswdigit(*ptr))
1202 return;
1203
1204 while(*ptr && iswdigit(*ptr)) {
1205 id = id*10 + (*ptr-'0');
1206 ptr++;
1207 }
1208
1209 if(*ptr)
1210 return;
1211
1212 if(id >= array->length)
1213 array->length = id+1;
1214}
#define iswdigit(_c)
Definition: ctype.h:667
Definition: name.c:39

◆ Array_pop()

static HRESULT Array_pop ( script_ctx_t ctx,
vdisp_t vthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 367 of file array.c.

369{
370 jsdisp_t *jsthis;
371 jsval_t val;
374
375 TRACE("\n");
376
377 hres = get_length(ctx, vthis, &jsthis, &length);
378 if(FAILED(hres))
379 return hres;
380
381 if(!length) {
382 hres = set_length(jsthis, 0);
383 if(FAILED(hres))
384 return hres;
385
386 if(r)
387 *r = jsval_undefined();
388 return S_OK;
389 }
390
391 length--;
392 hres = jsdisp_get_idx(jsthis, length, &val);
393 if(SUCCEEDED(hres))
394 hres = jsdisp_delete_idx(jsthis, length);
395 else if(hres == DISP_E_UNKNOWNNAME) {
397 hres = S_OK;
398 }else
399 return hres;
400
401 if(SUCCEEDED(hres))
402 hres = set_length(jsthis, length);
403
404 if(FAILED(hres)) {
406 return hres;
407 }
408
409 if(r)
410 *r = val;
411 else
413 return hres;
414}
static HRESULT set_length(jsdisp_t *obj, DWORD length)
Definition: array.c:108
HRESULT jsdisp_delete_idx(jsdisp_t *obj, DWORD idx)
Definition: dispex.c:1494

◆ Array_push()

static HRESULT Array_push ( script_ctx_t ctx,
vdisp_t vthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 417 of file array.c.

419{
420 jsdisp_t *jsthis;
421 DWORD length = 0;
422 unsigned i;
424
425 TRACE("\n");
426
427 hres = get_length(ctx, vthis, &jsthis, &length);
428 if(FAILED(hres))
429 return hres;
430
431 for(i=0; i < argc; i++) {
432 hres = jsdisp_propput_idx(jsthis, length+i, argv[i]);
433 if(FAILED(hres))
434 return hres;
435 }
436
437 hres = set_length(jsthis, length+argc);
438 if(FAILED(hres))
439 return hres;
440
441 if(r)
443 return S_OK;
444}

◆ Array_reverse()

static HRESULT Array_reverse ( script_ctx_t ctx,
vdisp_t vthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 446 of file array.c.

448{
449 jsdisp_t *jsthis;
450 DWORD length, k, l;
451 jsval_t v1, v2;
452 HRESULT hres1, hres2;
453
454 TRACE("\n");
455
456 hres1 = get_length(ctx, vthis, &jsthis, &length);
457 if(FAILED(hres1))
458 return hres1;
459
460 for(k=0; k<length/2; k++) {
461 l = length-k-1;
462
463 hres1 = jsdisp_get_idx(jsthis, k, &v1);
464 if(FAILED(hres1) && hres1!=DISP_E_UNKNOWNNAME)
465 return hres1;
466
467 hres2 = jsdisp_get_idx(jsthis, l, &v2);
468 if(FAILED(hres2) && hres2!=DISP_E_UNKNOWNNAME) {
470 return hres2;
471 }
472
473 if(hres1 == DISP_E_UNKNOWNNAME)
474 hres1 = jsdisp_delete_idx(jsthis, l);
475 else
476 hres1 = jsdisp_propput_idx(jsthis, l, v1);
477
478 if(FAILED(hres1)) {
481 return hres1;
482 }
483
484 if(hres2 == DISP_E_UNKNOWNNAME)
485 hres2 = jsdisp_delete_idx(jsthis, k);
486 else
487 hres2 = jsdisp_propput_idx(jsthis, k, v2);
488
489 if(FAILED(hres2)) {
491 return hres2;
492 }
493 }
494
495 if(r)
496 *r = jsval_obj(jsdisp_addref(jsthis));
497 return S_OK;
498}
r l[0]
Definition: byte_order.h:168
GLfloat GLfloat v1
Definition: glext.h:6062
GLfloat GLfloat GLfloat v2
Definition: glext.h:6063
static jsdisp_t * jsdisp_addref(jsdisp_t *jsdisp)
Definition: jscript.h:262

◆ Array_set_length()

static HRESULT Array_set_length ( script_ctx_t ctx,
jsdisp_t jsthis,
jsval_t  value 
)
static

Definition at line 141 of file array.c.

142{
144 DOUBLE len = -1;
145 DWORD i;
147
148 TRACE("%p %d\n", This, This->length);
149
150 hres = to_number(ctx, value, &len);
151 if(FAILED(hres))
152 return hres;
153
154 len = floor(len);
155 if(len!=(DWORD)len)
157
158 for(i=len; i < This->length; i++) {
159 hres = jsdisp_delete_idx(&This->dispex, i);
160 if(FAILED(hres))
161 return hres;
162 }
163
164 This->length = len;
165 return S_OK;
166}
HRESULT throw_range_error(script_ctx_t *ctx, HRESULT error, const WCHAR *str)
Definition: error.c:420
_Check_return_ _CRTIMP double __cdecl floor(_In_ double x)
HRESULT to_number(script_ctx_t *, jsval_t, double *) DECLSPEC_HIDDEN
Definition: jsutils.c:609
#define JS_E_INVALID_LENGTH
Definition: jscript.h:568
double DOUBLE
Definition: typedefs.h:70

◆ Array_shift()

static HRESULT Array_shift ( script_ctx_t ctx,
vdisp_t vthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 501 of file array.c.

503{
504 jsdisp_t *jsthis;
505 DWORD length = 0, i;
506 jsval_t v, ret;
508
509 TRACE("\n");
510
511 hres = get_length(ctx, vthis, &jsthis, &length);
512 if(FAILED(hres))
513 return hres;
514
515 if(!length) {
516 hres = set_length(jsthis, 0);
517 if(FAILED(hres))
518 return hres;
519
520 if(r)
521 *r = jsval_undefined();
522 return S_OK;
523 }
524
525 hres = jsdisp_get_idx(jsthis, 0, &ret);
526 if(hres == DISP_E_UNKNOWNNAME) {
528 hres = S_OK;
529 }
530
531 for(i=1; SUCCEEDED(hres) && i<length; i++) {
532 hres = jsdisp_get_idx(jsthis, i, &v);
534 hres = jsdisp_delete_idx(jsthis, i-1);
535 else if(SUCCEEDED(hres))
536 hres = jsdisp_propput_idx(jsthis, i-1, v);
537 }
538
539 if(SUCCEEDED(hres)) {
540 hres = jsdisp_delete_idx(jsthis, length-1);
541 if(SUCCEEDED(hres))
542 hres = set_length(jsthis, length-1);
543 }
544
545 if(FAILED(hres))
546 return hres;
547
548 if(r)
549 *r = ret;
550 else
552 return hres;
553}
const GLdouble * v
Definition: gl.h:2040

◆ Array_slice()

static HRESULT Array_slice ( script_ctx_t ctx,
vdisp_t vthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 556 of file array.c.

557{
558 jsdisp_t *arr, *jsthis;
562
563 TRACE("\n");
564
565 hres = get_length(ctx, vthis, &jsthis, &length);
566 if(FAILED(hres))
567 return hres;
568
569 if(argc) {
570 hres = to_number(ctx, argv[0], &range);
571 if(FAILED(hres))
572 return hres;
573
574 range = floor(range);
575 if(-range>length || isnan(range)) start = 0;
576 else if(range < 0) start = range+length;
577 else if(range <= length) start = range;
578 else start = length;
579 }
580 else start = 0;
581
582 if(argc > 1) {
583 hres = to_number(ctx, argv[1], &range);
584 if(FAILED(hres))
585 return hres;
586
587 range = floor(range);
588 if(-range>length) end = 0;
589 else if(range < 0) end = range+length;
590 else if(range <= length) end = range;
591 else end = length;
592 }
593 else end = length;
594
595 hres = create_array(ctx, (end>start)?end-start:0, &arr);
596 if(FAILED(hres))
597 return hres;
598
599 for(idx=start; idx<end; idx++) {
600 jsval_t v;
601
602 hres = jsdisp_get_idx(jsthis, idx, &v);
604 continue;
605
606 if(SUCCEEDED(hres)) {
609 }
610
611 if(FAILED(hres)) {
612 jsdisp_release(arr);
613 return hres;
614 }
615 }
616
617 if(r)
618 *r = jsval_obj(arr);
619 else
620 jsdisp_release(arr);
621
622 return S_OK;
623}
unsigned int idx
Definition: utils.c:41
GLuint start
Definition: gl.h:1545
GLuint GLuint end
Definition: gl.h:1545
GLenum GLint * range
Definition: glext.h:7539
#define isnan(x)
Definition: mingw_math.h:133

◆ Array_sort()

static HRESULT Array_sort ( script_ctx_t ctx,
vdisp_t vthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 680 of file array.c.

682{
683 jsdisp_t *jsthis, *cmp_func = NULL;
684 jsval_t *vtab, **sorttab = NULL;
686 DWORD i;
687 HRESULT hres = S_OK;
688
689 TRACE("\n");
690
691 hres = get_length(ctx, vthis, &jsthis, &length);
692 if(FAILED(hres))
693 return hres;
694
695 if(argc > 1) {
696 WARN("invalid arg_cnt %d\n", argc);
697 return E_FAIL;
698 }
699
700 if(argc == 1) {
701 if(!is_object_instance(argv[0])) {
702 WARN("arg is not dispatch\n");
703 return E_FAIL;
704 }
705
708 WARN("cmp_func is not a function\n");
709 if(cmp_func)
711 return E_FAIL;
712 }
713 }
714
715 if(!length) {
716 if(cmp_func)
718 if(r)
719 *r = jsval_obj(jsdisp_addref(jsthis));
720 return S_OK;
721 }
722
723 vtab = heap_alloc_zero(length * sizeof(*vtab));
724 if(vtab) {
725 for(i=0; i<length; i++) {
726 hres = jsdisp_get_idx(jsthis, i, vtab+i);
727 if(hres == DISP_E_UNKNOWNNAME) {
728 vtab[i] = jsval_undefined();
729 hres = S_OK;
730 } else if(FAILED(hres)) {
731 WARN("Could not get elem %d: %08x\n", i, hres);
732 break;
733 }
734 }
735 }else {
737 }
738
739 if(SUCCEEDED(hres)) {
740 sorttab = heap_alloc(length*2*sizeof(*sorttab));
741 if(!sorttab)
743 }
744
745 /* merge-sort */
746 if(SUCCEEDED(hres)) {
747 jsval_t *tmpv, **tmpbuf;
748 INT cmp;
749
750 tmpbuf = sorttab + length;
751 for(i=0; i < length; i++)
752 sorttab[i] = vtab+i;
753
754 for(i=0; i < length/2; i++) {
755 hres = sort_cmp(ctx, cmp_func, *sorttab[2*i+1], *sorttab[2*i], &cmp);
756 if(FAILED(hres))
757 break;
758
759 if(cmp < 0) {
760 tmpv = sorttab[2*i];
761 sorttab[2*i] = sorttab[2*i+1];
762 sorttab[2*i+1] = tmpv;
763 }
764 }
765
766 if(SUCCEEDED(hres)) {
767 DWORD k, a, b, bend;
768
769 for(k=2; k < length; k *= 2) {
770 for(i=0; i+k < length; i += 2*k) {
771 a = b = 0;
772 if(i+2*k <= length)
773 bend = k;
774 else
775 bend = length - (i+k);
776
777 memcpy(tmpbuf, sorttab+i, k*sizeof(jsval_t*));
778
779 while(a < k && b < bend) {
780 hres = sort_cmp(ctx, cmp_func, *tmpbuf[a], *sorttab[i+k+b], &cmp);
781 if(FAILED(hres))
782 break;
783
784 if(cmp < 0) {
785 sorttab[i+a+b] = tmpbuf[a];
786 a++;
787 }else {
788 sorttab[i+a+b] = sorttab[i+k+b];
789 b++;
790 }
791 }
792
793 if(FAILED(hres))
794 break;
795
796 if(a < k)
797 memcpy(sorttab+i+a+b, tmpbuf+a, (k-a)*sizeof(jsval_t*));
798 }
799
800 if(FAILED(hres))
801 break;
802 }
803 }
804
805 for(i=0; SUCCEEDED(hres) && i < length; i++)
806 hres = jsdisp_propput_idx(jsthis, i, *sorttab[i]);
807 }
808
809 if(vtab) {
810 for(i=0; i < length; i++)
811 jsval_release(vtab[i]);
812 heap_free(vtab);
813 }
814 heap_free(sorttab);
815 if(cmp_func)
817
818 if(FAILED(hres))
819 return hres;
820
821 if(r)
822 *r = jsval_obj(jsdisp_addref(jsthis));
823 return S_OK;
824}
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
static HRESULT sort_cmp(script_ctx_t *ctx, jsdisp_t *cmp_func, jsval_t v1, jsval_t v2, INT *cmp)
Definition: array.c:625
#define WARN(fmt,...)
Definition: debug.h:112
int(* cmp_func)(const void *ptr1, const void *ptr2)
Definition: btrfs.c:37
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
jsdisp_t * iface_to_jsdisp(IDispatch *iface)
Definition: dispex.c:1060
@ JSCLASS_FUNCTION
Definition: jscript.h:126
#define a
Definition: ke_i.h:78
#define b
Definition: ke_i.h:79
#define cmp(status, error)
Definition: error.c:114
int32_t INT
Definition: typedefs.h:58

◆ Array_splice()

static HRESULT Array_splice ( script_ctx_t ctx,
vdisp_t vthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 827 of file array.c.

829{
830 DWORD length, start=0, delete_cnt=0, i, add_args = 0;
831 jsdisp_t *ret_array = NULL, *jsthis;
832 jsval_t val;
833 double d;
834 int n;
835 HRESULT hres = S_OK;
836
837 TRACE("\n");
838
839 hres = get_length(ctx, vthis, &jsthis, &length);
840 if(FAILED(hres))
841 return hres;
842
843 if(argc) {
844 hres = to_integer(ctx, argv[0], &d);
845 if(FAILED(hres))
846 return hres;
847
848 if(is_int32(d)) {
849 if((n = d) >= 0)
850 start = min(n, length);
851 else
852 start = -n > length ? 0 : length + n;
853 }else {
854 start = d < 0.0 ? 0 : length;
855 }
856 }
857
858 if(argc >= 2) {
859 hres = to_integer(ctx, argv[1], &d);
860 if(FAILED(hres))
861 return hres;
862
863 if(is_int32(d)) {
864 if((n = d) > 0)
865 delete_cnt = min(n, length-start);
866 }else if(d > 0.0) {
867 delete_cnt = length-start;
868 }
869
870 add_args = argc-2;
871 }
872
873 if(r) {
874 hres = create_array(ctx, 0, &ret_array);
875 if(FAILED(hres))
876 return hres;
877
878 for(i=0; SUCCEEDED(hres) && i < delete_cnt; i++) {
879 hres = jsdisp_get_idx(jsthis, start+i, &val);
880 if(hres == DISP_E_UNKNOWNNAME) {
881 hres = S_OK;
882 }else if(SUCCEEDED(hres)) {
883 hres = jsdisp_propput_idx(ret_array, i, val);
885 }
886 }
887
888 if(SUCCEEDED(hres))
889 hres = jsdisp_propput_name(ret_array, lengthW, jsval_number(delete_cnt));
890 }
891
892 if(add_args < delete_cnt) {
893 for(i = start; SUCCEEDED(hres) && i < length-delete_cnt; i++) {
894 hres = jsdisp_get_idx(jsthis, i+delete_cnt, &val);
895 if(hres == DISP_E_UNKNOWNNAME) {
896 hres = jsdisp_delete_idx(jsthis, i+add_args);
897 }else if(SUCCEEDED(hres)) {
898 hres = jsdisp_propput_idx(jsthis, i+add_args, val);
900 }
901 }
902
903 for(i=length; SUCCEEDED(hres) && i != length-delete_cnt+add_args; i--)
904 hres = jsdisp_delete_idx(jsthis, i-1);
905 }else if(add_args > delete_cnt) {
906 for(i=length-delete_cnt; SUCCEEDED(hres) && i != start; i--) {
907 hres = jsdisp_get_idx(jsthis, i+delete_cnt-1, &val);
908 if(hres == DISP_E_UNKNOWNNAME) {
909 hres = jsdisp_delete_idx(jsthis, i+add_args-1);
910 }else if(SUCCEEDED(hres)) {
911 hres = jsdisp_propput_idx(jsthis, i+add_args-1, val);
913 }
914 }
915 }
916
917 for(i=0; SUCCEEDED(hres) && i < add_args; i++)
918 hres = jsdisp_propput_idx(jsthis, start+i, argv[i+2]);
919
920 if(SUCCEEDED(hres))
921 hres = jsdisp_propput_name(jsthis, lengthW, jsval_number(length-delete_cnt+add_args));
922
923 if(FAILED(hres)) {
924 if(ret_array)
925 jsdisp_release(ret_array);
926 return hres;
927 }
928
929 if(r)
930 *r = jsval_obj(ret_array);
931 return S_OK;
932}
static const WCHAR lengthW[]
Definition: array.c:39
GLdouble n
Definition: glext.h:7729
HRESULT jsdisp_propput_name(jsdisp_t *obj, const WCHAR *name, jsval_t val)
Definition: dispex.c:1344
static BOOL is_int32(double d)
Definition: jscript.h:514
#define d
Definition: ke_i.h:81

◆ array_this()

static ArrayInstance * array_this ( vdisp_t jsthis)
inlinestatic

Definition at line 68 of file array.c.

69{
70 return is_vclass(jsthis, JSCLASS_ARRAY) ? array_from_vdisp(jsthis) : NULL;
71}
static ArrayInstance * array_from_vdisp(vdisp_t *vdisp)
Definition: array.c:63
static BOOL is_vclass(vdisp_t *vdisp, jsclass_t class)
Definition: jscript.h:509

Referenced by Array_toString(), and get_length().

◆ Array_toLocaleString()

static HRESULT Array_toLocaleString ( script_ctx_t ctx,
vdisp_t vthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 950 of file array.c.

952{
953 FIXME("\n");
954 return E_NOTIMPL;
955}

◆ Array_toString()

static HRESULT Array_toString ( script_ctx_t ctx,
vdisp_t jsthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 935 of file array.c.

937{
939
940 TRACE("\n");
941
942 array = array_this(jsthis);
943 if(!array)
945
946 return array_join(ctx, &array->dispex, array->length, default_separatorW,
948}
static ArrayInstance * array_this(vdisp_t *jsthis)
Definition: array.c:68
HRESULT throw_type_error(script_ctx_t *ctx, HRESULT error, const WCHAR *str)
Definition: error.c:440
#define JS_E_ARRAY_EXPECTED
Definition: jscript.h:569

◆ Array_unshift()

static HRESULT Array_unshift ( script_ctx_t ctx,
vdisp_t vthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 1121 of file array.c.

1123{
1124 jsdisp_t *jsthis;
1125 WCHAR buf[14], *buf_end, *str;
1126 DWORD i, length;
1127 jsval_t val;
1128 DISPID id;
1129 HRESULT hres;
1130
1131 TRACE("\n");
1132
1133 hres = get_length(ctx, vthis, &jsthis, &length);
1134 if(FAILED(hres))
1135 return hres;
1136
1137 if(argc) {
1138 buf_end = buf + ARRAY_SIZE(buf)-1;
1139 *buf_end-- = 0;
1140 i = length;
1141
1142 while(i--) {
1143 str = idx_to_str(i, buf_end);
1144
1145 hres = jsdisp_get_id(jsthis, str, 0, &id);
1146 if(SUCCEEDED(hres)) {
1147 hres = jsdisp_propget(jsthis, id, &val);
1148 if(FAILED(hres))
1149 return hres;
1150
1151 hres = jsdisp_propput_idx(jsthis, i+argc, val);
1153 }else if(hres == DISP_E_UNKNOWNNAME) {
1154 hres = IDispatchEx_DeleteMemberByDispID(vthis->u.dispex, id);
1155 }
1156 }
1157
1158 if(FAILED(hres))
1159 return hres;
1160 }
1161
1162 for(i=0; i<argc; i++) {
1163 hres = jsdisp_propput_idx(jsthis, i, argv[i]);
1164 if(FAILED(hres))
1165 return hres;
1166 }
1167
1168 if(argc) {
1169 length += argc;
1170 hres = set_length(jsthis, length);
1171 if(FAILED(hres))
1172 return hres;
1173 }
1174
1175 if(r)
1176 *r = ctx->version < 2 ? jsval_undefined() : jsval_number(length);
1177 return S_OK;
1178}
static WCHAR * idx_to_str(DWORD idx, WCHAR *ptr)
Definition: array.c:118
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint id
Definition: glext.h:5910
HRESULT jsdisp_get_id(jsdisp_t *jsdisp, const WCHAR *name, DWORD flags, DISPID *id)
Definition: dispex.c:1067
HRESULT jsdisp_propget(jsdisp_t *jsdisp, DISPID id, jsval_t *val)
Definition: dispex.c:1447
static VARIANTARG static DISPID
Definition: ordinal.c:52
const WCHAR * str
IDispatchEx * dispex
Definition: jscript.h:143

◆ ArrayConstr_isArray()

static HRESULT ArrayConstr_isArray ( script_ctx_t ctx,
vdisp_t vthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 1258 of file array.c.

1259{
1260 jsdisp_t *obj;
1261
1262 TRACE("\n");
1263
1264 if(!argc || !is_object_instance(argv[0])) {
1265 if(r) *r = jsval_bool(FALSE);
1266 return S_OK;
1267 }
1268
1270 if(r) *r = jsval_bool(obj && is_class(obj, JSCLASS_ARRAY));
1271 if(obj) jsdisp_release(obj);
1272 return S_OK;
1273}
#define FALSE
Definition: types.h:117
static jsval_t jsval_bool(BOOL b)
Definition: jsval.h:101

◆ ArrayConstr_value()

static HRESULT ArrayConstr_value ( script_ctx_t ctx,
vdisp_t vthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 1275 of file array.c.

1277{
1278 jsdisp_t *obj;
1279 DWORD i;
1280 HRESULT hres;
1281
1282 TRACE("\n");
1283
1284 switch(flags) {
1285 case DISPATCH_METHOD:
1286 case DISPATCH_CONSTRUCT: {
1287 if(argc == 1 && is_number(argv[0])) {
1288 double n = get_number(argv[0]);
1289
1290 if(n < 0 || !is_int32(n))
1292
1293 hres = create_array(ctx, n, &obj);
1294 if(FAILED(hres))
1295 return hres;
1296
1297 *r = jsval_obj(obj);
1298 return S_OK;
1299 }
1300
1302 if(FAILED(hres))
1303 return hres;
1304
1305 for(i=0; i < argc; i++) {
1307 if(FAILED(hres))
1308 break;
1309 }
1310 if(FAILED(hres)) {
1312 return hres;
1313 }
1314
1315 *r = jsval_obj(obj);
1316 break;
1317 }
1318 default:
1319 FIXME("unimplemented flags: %x\n", flags);
1320 return E_NOTIMPL;
1321 }
1322
1323 return S_OK;
1324}
GLbitfield flags
Definition: glext.h:7161
static BOOL is_number(jsval_t v)
Definition: jsval.h:191
static double get_number(jsval_t v)
Definition: jsval.h:224

Referenced by create_array_constr().

◆ concat_array()

static HRESULT concat_array ( jsdisp_t array,
ArrayInstance obj,
DWORD len 
)
static

Definition at line 168 of file array.c.

169{
170 jsval_t val;
171 DWORD i;
173
174 for(i=0; i < obj->length; i++) {
175 hres = jsdisp_get_idx(&obj->dispex, i, &val);
177 continue;
178 if(FAILED(hres))
179 return hres;
180
183 if(FAILED(hres))
184 return hres;
185 }
186
187 *len += obj->length;
188 return S_OK;
189}

Referenced by concat_obj().

◆ concat_obj()

static HRESULT concat_obj ( jsdisp_t array,
IDispatch obj,
DWORD len 
)
static

Definition at line 191 of file array.c.

192{
193 jsdisp_t *jsobj;
195
196 jsobj = iface_to_jsdisp(obj);
197 if(jsobj) {
198 if(is_class(jsobj, JSCLASS_ARRAY)) {
200 jsdisp_release(jsobj);
201 return hres;
202 }
203 jsdisp_release(jsobj);
204 }
205
206 return jsdisp_propput_idx(array, (*len)++, jsval_disp(obj));
207}
static HRESULT concat_array(jsdisp_t *array, ArrayInstance *obj, DWORD *len)
Definition: array.c:168
static jsval_t jsval_disp(IDispatch *obj)
Definition: jsval.h:117

Referenced by Array_concat().

◆ create_array()

HRESULT create_array ( script_ctx_t ctx,
DWORD  length,
jsdisp_t **  ret 
)

Definition at line 1381 of file array.c.

1382{
1384 HRESULT hres;
1385
1387 if(FAILED(hres))
1388 return hres;
1389
1390 array->length = length;
1391
1392 *ret = &array->dispex;
1393 return S_OK;
1394}
static HRESULT alloc_array(script_ctx_t *ctx, jsdisp_t *object_prototype, ArrayInstance **ret)
Definition: array.c:1326

Referenced by Array_concat(), Array_map(), Array_slice(), Array_splice(), ArrayConstr_value(), create_match_array(), interp_carray(), parse_json_value(), regexp_string_match(), String_split(), and VBArray_toArray().

◆ create_array_constr()

HRESULT create_array_constr ( script_ctx_t ctx,
jsdisp_t object_prototype,
jsdisp_t **  ret 
)

Definition at line 1364 of file array.c.

1365{
1367 HRESULT hres;
1368
1369 static const WCHAR ArrayW[] = {'A','r','r','a','y',0};
1370
1371 hres = alloc_array(ctx, object_prototype, &array);
1372 if(FAILED(hres))
1373 return hres;
1374
1376
1377 jsdisp_release(&array->dispex);
1378 return hres;
1379}
static const builtin_info_t ArrayConstr_info
Definition: array.c:1355
static HRESULT ArrayConstr_value(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1275
HRESULT create_builtin_constructor(script_ctx_t *ctx, builtin_invoke_t value_proc, const WCHAR *name, const builtin_info_t *builtin_info, DWORD flags, jsdisp_t *prototype, jsdisp_t **ret)
Definition: function.c:686
static const WCHAR ArrayW[]
Definition: global.c:36
#define PROPF_CONSTR
Definition: jscript.h:98

Referenced by init_constructors().

◆ get_length()

static HRESULT get_length ( script_ctx_t ctx,
vdisp_t vdisp,
jsdisp_t **  jsthis,
DWORD ret 
)
static

Definition at line 79 of file array.c.

80{
84
85 array = array_this(vdisp);
86 if(array) {
87 *jsthis = &array->dispex;
88 *ret = array->length;
89 return S_OK;
90 }
91
92 if(!is_jsdisp(vdisp))
94
96 if(FAILED(hres))
97 return hres;
98
101 if(FAILED(hres))
102 return hres;
103
104 *jsthis = vdisp->u.jsdisp;
105 return S_OK;
106}
HRESULT jsdisp_propget_name(jsdisp_t *obj, const WCHAR *name, jsval_t *val)
Definition: dispex.c:1408
#define JS_E_JSCRIPT_EXPECTED
Definition: jscript.h:561
static BOOL is_jsdisp(vdisp_t *vdisp)
Definition: jscript.h:157
HRESULT to_uint32(script_ctx_t *, jsval_t, UINT32 *) DECLSPEC_HIDDEN
Definition: jsutils.c:686

Referenced by Array_forEach(), Array_indexOf(), Array_join(), Array_map(), Array_pop(), Array_push(), Array_reverse(), Array_shift(), Array_slice(), Array_sort(), Array_splice(), and Array_unshift().

◆ idx_to_str()

static WCHAR * idx_to_str ( DWORD  idx,
WCHAR ptr 
)
static

Definition at line 118 of file array.c.

119{
120 if(!idx) {
121 *ptr = '0';
122 return ptr;
123 }
124
125 while(idx) {
126 *ptr-- = '0' + (idx%10);
127 idx /= 10;
128 }
129
130 return ptr+1;
131}

Referenced by Array_unshift().

◆ set_length()

static HRESULT set_length ( jsdisp_t obj,
DWORD  length 
)
static

Definition at line 108 of file array.c.

109{
112 return S_OK;
113 }
114
116}

Referenced by Array_pop(), Array_push(), Array_shift(), and Array_unshift().

◆ sort_cmp()

static HRESULT sort_cmp ( script_ctx_t ctx,
jsdisp_t cmp_func,
jsval_t  v1,
jsval_t  v2,
INT cmp 
)
static

Definition at line 625 of file array.c.

626{
628
629 if(cmp_func) {
630 jsval_t args[2];
631 jsval_t res;
632 double n;
633
634 args[0] = v1;
635 args[1] = v2;
636
638 if(FAILED(hres))
639 return hres;
640
641 hres = to_number(ctx, res, &n);
643 if(FAILED(hres))
644 return hres;
645
646 if(n == 0)
647 *cmp = 0;
648 *cmp = n > 0.0 ? 1 : -1;
649 }else if(is_undefined(v1)) {
650 *cmp = is_undefined(v2) ? 0 : 1;
651 }else if(is_undefined(v2)) {
652 *cmp = -1;
653 }else if(is_number(v1) && is_number(v2)) {
654 double d = get_number(v1)-get_number(v2);
655 if(d > 0.0)
656 *cmp = 1;
657 else
658 *cmp = d < -0.0 ? -1 : 0;
659 }else {
660 jsstr_t *x, *y;
661
662 hres = to_string(ctx, v1, &x);
663 if(FAILED(hres))
664 return hres;
665
666 hres = to_string(ctx, v2, &y);
667 if(SUCCEEDED(hres)) {
668 *cmp = jsstr_cmp(x, y);
670 }
672 if(FAILED(hres))
673 return hres;
674 }
675
676 return S_OK;
677}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
HRESULT jsdisp_call_value(jsdisp_t *jsfunc, IDispatch *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: dispex.c:1089
int jsstr_cmp(jsstr_t *str1, jsstr_t *str2)
Definition: jsstr.c:189

Referenced by Array_sort().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( jscript  )

Variable Documentation

◆ Array_info

const builtin_info_t Array_info
static
Initial value:
= {
}
static void Array_destructor(jsdisp_t *dispex)
Definition: array.c:1190
static void Array_on_put(jsdisp_t *dispex, const WCHAR *name)
Definition: array.c:1195
static HRESULT Array_get_value(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
Definition: array.c:1180
static const builtin_prop_t Array_props[]
Definition: array.c:1216

Definition at line 1235 of file array.c.

Referenced by alloc_array().

◆ Array_props

const builtin_prop_t Array_props[]
static
Initial value:
= {
}
static const WCHAR forEachW[]
Definition: array.c:41
static const WCHAR shiftW[]
Definition: array.c:46
static HRESULT Array_sort(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:680
static const WCHAR indexOfW[]
Definition: array.c:53
static HRESULT Array_map(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1058
static const WCHAR sliceW[]
Definition: array.c:47
static HRESULT Array_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:935
static const WCHAR reverseW[]
Definition: array.c:45
static HRESULT Array_push(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:417
static const WCHAR joinW[]
Definition: array.c:42
static HRESULT Array_concat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:209
static HRESULT Array_pop(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:367
static const WCHAR toLocaleStringW[]
Definition: array.c:51
static HRESULT Array_unshift(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1121
static const WCHAR mapW[]
Definition: array.c:54
static const WCHAR unshiftW[]
Definition: array.c:52
static const WCHAR concatW[]
Definition: array.c:40
static HRESULT Array_splice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:827
static HRESULT Array_toLocaleString(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:950
static const WCHAR toStringW[]
Definition: array.c:50
static HRESULT Array_indexOf(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1003
static HRESULT Array_forEach(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:957
static const WCHAR popW[]
Definition: array.c:43
static const WCHAR spliceW[]
Definition: array.c:49
static const WCHAR pushW[]
Definition: array.c:44
static HRESULT Array_get_length(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
Definition: array.c:133
static HRESULT Array_reverse(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:446
static HRESULT Array_join(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:336
static const WCHAR sortW[]
Definition: array.c:48
static HRESULT Array_shift(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:501
static HRESULT Array_set_length(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t value)
Definition: array.c:141
static HRESULT Array_slice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:556
#define PROPF_ES5
Definition: jscript.h:108
#define PROPF_METHOD
Definition: jscript.h:97

Definition at line 1216 of file array.c.

◆ ArrayConstr_info

const builtin_info_t ArrayConstr_info
static
Initial value:
= {
}
static const builtin_prop_t ArrayConstr_props[]
Definition: array.c:1351
#define DEFAULT_FUNCTION_VALUE
Definition: jscript.h:315

Definition at line 1355 of file array.c.

Referenced by create_array_constr().

◆ ArrayConstr_props

const builtin_prop_t ArrayConstr_props[]
static
Initial value:
= {
}
static HRESULT ArrayConstr_isArray(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1258
static const WCHAR isArrayW[]
Definition: array.c:1349

Definition at line 1351 of file array.c.

◆ ArrayInst_info

const builtin_info_t ArrayInst_info
static
Initial value:

Definition at line 1248 of file array.c.

Referenced by alloc_array().

◆ ArrayInst_props

const builtin_prop_t ArrayInst_props[]
static
Initial value:

Definition at line 1244 of file array.c.

◆ concatW

const WCHAR concatW[] = {'c','o','n','c','a','t',0}
static

Definition at line 40 of file array.c.

◆ default_separatorW

const WCHAR default_separatorW[] = {',',0}
static

Definition at line 56 of file array.c.

Referenced by Array_get_value(), Array_join(), and Array_toString().

◆ forEachW

const WCHAR forEachW[] = {'f','o','r','E','a','c','h',0}
static

Definition at line 41 of file array.c.

◆ indexOfW

const WCHAR indexOfW[] = {'i','n','d','e','x','O','f',0}
static

Definition at line 53 of file array.c.

◆ isArrayW

const WCHAR isArrayW[] = {'i','s','A','r','r','a','y',0}
static

Definition at line 1349 of file array.c.

◆ joinW

const WCHAR joinW[] = {'j','o','i','n',0}
static

Definition at line 42 of file array.c.

◆ lengthW

const WCHAR lengthW[] = {'l','e','n','g','t','h',0}
static

Definition at line 39 of file array.c.

Referenced by Array_splice(), get_length(), read_bitmap_patterns(), and set_length().

◆ mapW

const WCHAR mapW[] = {'m','a','p',0}
static

Definition at line 54 of file array.c.

◆ popW

const WCHAR popW[] = {'p','o','p',0}
static

Definition at line 43 of file array.c.

◆ pushW

const WCHAR pushW[] = {'p','u','s','h',0}
static

Definition at line 44 of file array.c.

◆ reverseW

const WCHAR reverseW[] = {'r','e','v','e','r','s','e',0}
static

Definition at line 45 of file array.c.

◆ shiftW

const WCHAR shiftW[] = {'s','h','i','f','t',0}
static

Definition at line 46 of file array.c.

◆ sliceW

const WCHAR sliceW[] = {'s','l','i','c','e',0}
static

Definition at line 47 of file array.c.

◆ sortW

const WCHAR sortW[] = {'s','o','r','t',0}
static

Definition at line 48 of file array.c.

◆ spliceW

const WCHAR spliceW[] = {'s','p','l','i','c','e',0}
static

Definition at line 49 of file array.c.

◆ toLocaleStringW

const WCHAR toLocaleStringW[] = {'t','o','L','o','c','a','l','e','S','t','r','i','n','g',0}
static

Definition at line 51 of file array.c.

◆ toStringW

const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0}
static

Definition at line 50 of file array.c.

Referenced by to_primitive().

◆ unshiftW

const WCHAR unshiftW[] = {'u','n','s','h','i','f','t',0}
static

Definition at line 52 of file array.c.