ReactOS 0.4.17-dev-357-ga8f14ff
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_this (jsval_t vthis)
 
unsigned array_get_length (jsdisp_t *array)
 
static HRESULT get_length (script_ctx_t *ctx, jsval_t vthis, jsdisp_t **jsthis, UINT32 *ret)
 
static HRESULT set_length (jsdisp_t *obj, DWORD length)
 
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, jsval_t vthis, 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, HRESULT(*to_string)(script_ctx_t *, jsval_t, jsstr_t **), jsval_t *r)
 
static HRESULT Array_join (script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_pop (script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_push (script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_reverse (script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_shift (script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_slice (script_ctx_t *ctx, jsval_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, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_splice (script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_toString (script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT to_locale_string (script_ctx_t *ctx, jsval_t val, jsstr_t **str)
 
static HRESULT Array_toLocaleString (script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_every (script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_filter (script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_forEach (script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_indexOf (script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_lastIndexOf (script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_map (script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_reduce (script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_some (script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Array_unshift (script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static void Array_on_put (jsdisp_t *dispex, const WCHAR *name)
 
static HRESULT ArrayConstr_isArray (script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT ArrayConstr_value (script_ctx_t *ctx, jsval_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 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 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 1731 of file array.c.

1732{
1734 HRESULT hres;
1735
1736 array = calloc(1, sizeof(ArrayInstance));
1737 if(!array)
1738 return E_OUTOFMEMORY;
1739
1740 if(object_prototype)
1741 hres = init_dispex(&array->dispex, ctx, &Array_info, object_prototype);
1742 else
1743 hres = init_dispex_from_constr(&array->dispex, ctx, &ArrayInst_info, ctx->array_constr);
1744
1745 if(FAILED(hres)) {
1746 free(array);
1747 return hres;
1748 }
1749
1750 *ret = array;
1751 return S_OK;
1752}
static const builtin_info_t ArrayInst_info
Definition: array.c:1652
static const builtin_info_t Array_info
Definition: array.c:1641
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define free
Definition: debug_ros.c:5
return ret
Definition: mutex.c:146
#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:2512
HRESULT init_dispex(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *prototype)
Definition: dispex.c:2454
HRESULT hres
Definition: protocol.c:465
#define calloc
Definition: rosglue.h:14
Definition: undname.c:54

Referenced by create_array(), and create_array_constr().

◆ Array_concat()

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

Definition at line 191 of file array.c.

193{
194 IDispatch *jsthis;
195 jsdisp_t *ret;
196 DWORD len = 0;
198
199 TRACE("\n");
200
201 hres = to_object(ctx, vthis, &jsthis);
202 if(FAILED(hres))
203 return hres;
204
205 hres = create_array(ctx, 0, &ret);
206 if(FAILED(hres))
207 goto done;
208
209 hres = concat_obj(ret, jsthis, &len);
210 if(SUCCEEDED(hres)) {
211 DWORD i;
212
213 for(i=0; i < argc; i++) {
216 else
218 if(FAILED(hres))
219 break;
220 }
221 }
222
223 if(FAILED(hres))
224 goto done;
225
226 if(r)
227 *r = jsval_obj(ret);
228 else
230done:
231 IDispatch_Release(jsthis);
232 return S_OK;
233}
HRESULT create_array(script_ctx_t *ctx, DWORD length, jsdisp_t **ret)
Definition: array.c:1780
static HRESULT concat_obj(jsdisp_t *array, IDispatch *obj, DWORD *len)
Definition: array.c:173
MonoAssembly int argc
Definition: metahost.c:107
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
ULONG jsdisp_release(jsdisp_t *obj)
Definition: dispex.c:1911
HRESULT jsdisp_propput_idx(jsdisp_t *obj, DWORD idx, jsval_t val)
Definition: dispex.c:2864
HRESULT to_object(script_ctx_t *, jsval_t, IDispatch **)
Definition: jsutils.c:864
static jsval_t jsval_obj(jsdisp_t *obj)
Definition: jsval.h:125
static IDispatch * get_object(jsval_t v)
Definition: jsval.h:228
static BOOL is_object_instance(jsval_t v)
Definition: jsval.h:175
#define argv
Definition: mplay32.c:18
#define TRACE(s)
Definition: solgame.cpp:4

◆ Array_every()

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

Definition at line 1034 of file array.c.

1036{
1037 jsval_t context_this = jsval_undefined();
1038 jsval_t value, args[3], res;
1039 BOOL boolval, ret = TRUE;
1041 unsigned length, i;
1042 jsdisp_t *jsthis;
1043 HRESULT hres;
1044
1045 TRACE("\n");
1046
1047 hres = get_length(ctx, vthis, &jsthis, &length);
1048 if(FAILED(hres))
1049 return hres;
1050
1051 /* FIXME: check IsCallable */
1052 if(!argc || !is_object_instance(argv[0])) {
1053 FIXME("Invalid arg %s\n", debugstr_jsval(argc ? argv[0] : jsval_undefined()));
1055 goto done;
1056 }
1057 callback = get_object(argv[0]);
1058
1059 if(argc > 1)
1060 context_this = argv[1];
1061
1062 for(i = 0; i < length; i++) {
1063 hres = jsdisp_get_idx(jsthis, i, &value);
1064 if(FAILED(hres)) {
1066 continue;
1067 goto done;
1068 }
1069 args[0] = value;
1070 args[1] = jsval_number(i);
1071 args[2] = jsval_obj(jsthis);
1074 if(FAILED(hres))
1075 goto done;
1076
1077 hres = to_boolean(res, &boolval);
1079 if(FAILED(hres))
1080 goto done;
1081 if(!boolval) {
1082 ret = FALSE;
1083 break;
1084 }
1085 }
1086
1087 if(r)
1088 *r = jsval_bool(ret);
1089 hres = S_OK;
1090done:
1091 jsdisp_release(jsthis);
1092 return hres;
1093}
static HRESULT get_length(script_ctx_t *ctx, jsval_t vthis, jsdisp_t **jsthis, UINT32 *ret)
Definition: array.c:56
#define ARRAY_SIZE(A)
Definition: main.h:20
#define FIXME(fmt,...)
Definition: precomp.h:53
#define E_INVALIDARG
Definition: ddrawi.h:101
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint res
Definition: glext.h:9613
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
HRESULT jsdisp_get_idx(jsdisp_t *obj, DWORD idx, jsval_t *r)
Definition: dispex.c:2963
static HRESULT disp_call_value(script_ctx_t *ctx, IDispatch *disp, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: jscript.h:518
const char * debugstr_jsval(const jsval_t)
Definition: jsutils.c:35
HRESULT to_boolean(jsval_t, BOOL *)
Definition: jsutils.c:489
void jsval_release(jsval_t val)
Definition: jsutils.c:186
static jsval_t jsval_undefined(void)
Definition: jsval.h:146
static jsval_t jsval_bool(BOOL b)
Definition: jsval.h:101
static jsval_t jsval_number(double n)
Definition: jsval.h:153
static IPrintDialogCallback callback
Definition: printdlg.c:326
#define DISPATCH_METHOD
Definition: oleauto.h:1006
Definition: jsval.h:54
Definition: match.c:390
Definition: pdh_main.c:96
#define DISP_E_UNKNOWNNAME
Definition: winerror.h:3618

◆ Array_filter()

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

Definition at line 1095 of file array.c.

1097{
1098 jsval_t context_this = jsval_undefined();
1099 jsval_t value, args[3], res;
1100 unsigned length, i, j = 0;
1101 jsdisp_t *jsthis, *arr;
1103 HRESULT hres;
1104 BOOL boolval;
1105
1106 TRACE("\n");
1107
1108 hres = get_length(ctx, vthis, &jsthis, &length);
1109 if(FAILED(hres))
1110 return hres;
1111
1112 /* FIXME: check IsCallable */
1113 if(!argc || !is_object_instance(argv[0])) {
1114 FIXME("Invalid arg %s\n", debugstr_jsval(argc ? argv[0] : jsval_undefined()));
1116 goto done;
1117 }
1118 callback = get_object(argv[0]);
1119
1120 if(argc > 1)
1121 context_this = argv[1];
1122
1123 hres = create_array(ctx, 0, &arr);
1124 if(FAILED(hres))
1125 goto done;
1126
1127 for(i = 0; i < length; i++) {
1128 hres = jsdisp_get_idx(jsthis, i, &value);
1129 if(FAILED(hres)) {
1130 if(hres == DISP_E_UNKNOWNNAME) {
1131 hres = S_OK;
1132 continue;
1133 }
1134 break;
1135 }
1136 args[0] = value;
1137 args[1] = jsval_number(i);
1138 args[2] = jsval_obj(jsthis);
1140 if(SUCCEEDED(hres)) {
1141 hres = to_boolean(res, &boolval);
1143 if(SUCCEEDED(hres) && boolval)
1144 hres = jsdisp_propput_idx(arr, j++, value);
1145 }
1147 if(FAILED(hres))
1148 break;
1149 }
1150
1151 if(FAILED(hres)) {
1152 jsdisp_release(arr);
1153 goto done;
1154 }
1155 set_length(arr, j);
1156
1157 if(r)
1158 *r = jsval_obj(arr);
1159 else
1160 jsdisp_release(arr);
1161done:
1162 jsdisp_release(jsthis);
1163 return hres;
1164}
static HRESULT set_length(jsdisp_t *obj, DWORD length)
Definition: array.c:90
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 GLint GLint j
Definition: glfuncs.h:250

◆ Array_forEach()

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

Definition at line 1166 of file array.c.

1168{
1169 jsval_t context_this = jsval_undefined();
1170 jsval_t value, args[3], res;
1172 jsdisp_t *jsthis;
1173 unsigned length, i;
1174 HRESULT hres;
1175
1176 TRACE("\n");
1177
1178 hres = get_length(ctx, vthis, &jsthis, &length);
1179 if(FAILED(hres))
1180 return hres;
1181
1182 /* Fixme check IsCallable */
1183 if(!argc || !is_object_instance(argv[0])) {
1184 FIXME("Invalid arg %s\n", debugstr_jsval(argc ? argv[0] : jsval_undefined()));
1186 goto done;
1187 }
1188 callback = get_object(argv[0]);
1189
1190 if(argc > 1)
1191 context_this = argv[1];
1192
1193 for(i = 0; i < length; i++) {
1194 hres = jsdisp_get_idx(jsthis, i, &value);
1196 continue;
1197 if(FAILED(hres))
1198 goto done;
1199
1200 args[0] = value;
1201 args[1] = jsval_number(i);
1202 args[2] = jsval_obj(jsthis);
1205 if(FAILED(hres))
1206 goto done;
1208 }
1209
1210 if(r) *r = jsval_undefined();
1211 hres = S_OK;
1212done:
1213 jsdisp_release(jsthis);
1214 return hres;
1215}

◆ array_from_jsdisp()

static ArrayInstance * array_from_jsdisp ( jsdisp_t jsdisp)
inlinestatic

Definition at line 39 of file array.c.

40{
41 return CONTAINING_RECORD(jsdisp, ArrayInstance, dispex);
42}
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by array_get_length(), Array_get_length(), Array_on_put(), Array_set_length(), array_this(), concat_obj(), get_length(), and set_length().

◆ array_get_length()

unsigned array_get_length ( jsdisp_t array)

Definition at line 50 of file array.c.

51{
54}
static ArrayInstance * array_from_jsdisp(jsdisp_t *jsdisp)
Definition: array.c:39
#define assert(_expr)
Definition: assert.h:32
@ JSCLASS_ARRAY
Definition: jscript.h:104
static BOOL is_class(jsdisp_t *jsdisp, jsclass_t class)
Definition: jscript.h:503
DWORD length
Definition: array.c:36

Referenced by stringify_array(), and transform_json_object().

◆ Array_get_length()

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

Definition at line 115 of file array.c.

116{
117 TRACE("%p\n", jsthis);
118
120 return S_OK;
121}

◆ Array_indexOf()

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

Definition at line 1217 of file array.c.

1219{
1220 jsdisp_t *jsthis;
1221 unsigned length, i, from = 0;
1223 BOOL eq;
1224 HRESULT hres;
1225
1226 TRACE("\n");
1227
1228 hres = get_length(ctx, vthis, &jsthis, &length);
1229 if(FAILED(hres))
1230 return hres;
1231 if(!length) {
1232 if(r) *r = jsval_number(-1);
1233 goto done;
1234 }
1235
1236 search = argc ? argv[0] : jsval_undefined();
1237
1238 if(argc > 1) {
1239 double from_arg;
1240
1241 hres = to_integer(ctx, argv[1], &from_arg);
1242 if(FAILED(hres))
1243 goto done;
1244
1245 if(from_arg >= 0)
1246 from = min(from_arg, length);
1247 else
1248 from = max(from_arg + length, 0);
1249 }
1250
1251 for(i = from; i < length; i++) {
1252 hres = jsdisp_get_idx(jsthis, i, &value);
1254 continue;
1255 if(FAILED(hres))
1256 goto done;
1257
1260 if(FAILED(hres))
1261 goto done;
1262 if(eq) {
1263 if(r) *r = jsval_number(i);
1264 goto done;
1265 }
1266 }
1267
1268 if(r) *r = jsval_number(-1);
1269 hres = S_OK;
1270done:
1271 jsdisp_release(jsthis);
1272 return hres;
1273}
HRESULT jsval_strict_equal(jsval_t lval, jsval_t rval, BOOL *ret)
Definition: engine.c:684
HRESULT to_integer(script_ctx_t *, jsval_t, double *)
Definition: jsutils.c:676
#define eq(received, expected, label, type)
Definition: locale.c:179
#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,
HRESULT(*)(script_ctx_t *, jsval_t, jsstr_t **)  to_string,
jsval_t r 
)
static

Definition at line 235 of file array.c.

237{
238 jsstr_t **str_tab, *ret = NULL;
239 jsval_t val;
240 DWORD i;
242
243 if(!length) {
244 if(r)
246 return S_OK;
247 }
248
249 str_tab = calloc(length, sizeof(*str_tab));
250 if(!str_tab)
251 return E_OUTOFMEMORY;
252
253 for(i=0; i < length; i++) {
255 if(hres == DISP_E_UNKNOWNNAME) {
256 hres = S_OK;
257 continue;
258 } else if(FAILED(hres))
259 break;
260
261 if(!is_undefined(val) && !is_null(val)) {
262 hres = to_string(ctx, val, str_tab+i);
264 if(FAILED(hres))
265 break;
266 }
267 }
268
269 if(SUCCEEDED(hres)) {
270 DWORD len = 0;
271
272 if(str_tab[0])
273 len = jsstr_length(str_tab[0]);
274 for(i=1; i < length; i++) {
275 len += seplen;
276 if(str_tab[i])
277 len += jsstr_length(str_tab[i]);
278 if(len > JSSTR_MAX_LENGTH) {
280 break;
281 }
282 }
283
284 if(SUCCEEDED(hres)) {
285 WCHAR *ptr = NULL;
286
288 if(ret) {
289 if(str_tab[0])
290 ptr += jsstr_flush(str_tab[0], ptr);
291
292 for(i=1; i < length; i++) {
293 if(seplen) {
294 memcpy(ptr, sep, seplen*sizeof(WCHAR));
295 ptr += seplen;
296 }
297
298 if(str_tab[i])
299 ptr += jsstr_flush(str_tab[i], ptr);
300 }
301 }else {
303 }
304 }
305 }
306
307 for(i=0; i < length; i++) {
308 if(str_tab[i])
309 jsstr_release(str_tab[i]);
310 }
311 free(str_tab);
312 if(FAILED(hres))
313 return hres;
314
315 TRACE("= %s\n", debugstr_jsstr(ret));
316
317 if(r)
318 *r = jsval_string(ret);
319 else
321 return S_OK;
322}
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
GLuint GLfloat * val
Definition: glext.h:7180
static HRESULT to_string(VARIANT *src, BSTR *dst)
Definition: host.c:46
jsstr_t * jsstr_empty(void)
Definition: jsstr.c:291
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:42
static void jsstr_release(jsstr_t *str)
Definition: jsstr.h:107
static unsigned jsstr_length(jsstr_t *str)
Definition: jsstr.h:55
static unsigned jsstr_flush(jsstr_t *str, WCHAR *buf)
Definition: jsstr.h:145
static jsval_t jsval_string(jsstr_t *str)
Definition: jsval.h:109
static BOOL is_undefined(jsval_t v)
Definition: jsval.h:180
static BOOL is_null(jsval_t v)
Definition: jsval.h:185
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static PVOID ptr
Definition: dispmode.c:27
short WCHAR
Definition: pedump.c:58
Definition: jsstr.h:36

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

◆ Array_join()

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

Definition at line 325 of file array.c.

327{
328 jsdisp_t *jsthis;
331
332 TRACE("\n");
333
334 hres = get_length(ctx, vthis, &jsthis, &length);
335 if(FAILED(hres))
336 return hres;
337
338 if(argc) {
339 const WCHAR *sep;
340 jsstr_t *sep_str;
341
342 hres = to_flat_string(ctx, argv[0], &sep_str, &sep);
343 if(FAILED(hres))
344 goto done;
345
346 hres = array_join(ctx, jsthis, length, sep, jsstr_length(sep_str), to_string, r);
347
348 jsstr_release(sep_str);
349 }else {
350 hres = array_join(ctx, jsthis, length, L",", 1, to_string, r);
351 }
352
353done:
354 jsdisp_release(jsthis);
355 return hres;
356}
static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, const WCHAR *sep, unsigned seplen, HRESULT(*to_string)(script_ctx_t *, jsval_t, jsstr_t **), jsval_t *r)
Definition: array.c:235
#define L(x)
Definition: resources.c:13
HRESULT to_flat_string(script_ctx_t *, jsval_t, jsstr_t **, const WCHAR **)
Definition: jsutils.c:846
uint32_t UINT32
Definition: typedefs.h:59

◆ Array_lastIndexOf()

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

Definition at line 1275 of file array.c.

1277{
1279 unsigned i, length;
1280 jsdisp_t *jsthis;
1281 HRESULT hres;
1282 BOOL eq;
1283
1284 TRACE("\n");
1285
1286 hres = get_length(ctx, vthis, &jsthis, &length);
1287 if(FAILED(hres))
1288 return hres;
1289 if(!length)
1290 goto notfound;
1291
1292 search = argc ? argv[0] : jsval_undefined();
1293
1294 i = length - 1;
1295 if(argc > 1) {
1296 double from_arg;
1297
1298 hres = to_integer(ctx, argv[1], &from_arg);
1299 if(FAILED(hres))
1300 goto done;
1301
1302 if(from_arg >= 0.0)
1303 i = min(from_arg, i);
1304 else {
1305 from_arg += length;
1306 if(from_arg < 0.0)
1307 goto notfound;
1308 i = from_arg;
1309 }
1310 }
1311
1312 do {
1313 hres = jsdisp_get_idx(jsthis, i, &value);
1315 continue;
1316 if(FAILED(hres))
1317 goto done;
1318
1321 if(FAILED(hres))
1322 goto done;
1323 if(eq) {
1324 if(r) *r = jsval_number(i);
1325 goto done;
1326 }
1327 } while(i--);
1328
1329notfound:
1330 if(r) *r = jsval_number(-1);
1331 hres = S_OK;
1332done:
1333 jsdisp_release(jsthis);
1334 return hres;
1335}

◆ Array_map()

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

Definition at line 1337 of file array.c.

1338{
1339 jsval_t context_this = jsval_undefined();
1340 jsval_t callback_args[3], mapped_value;
1341 jsdisp_t *jsthis, *array;
1343 UINT32 length, k;
1344 HRESULT hres;
1345
1346 TRACE("\n");
1347
1348 hres = get_length(ctx, vthis, &jsthis, &length);
1349 if(FAILED(hres)) {
1350 FIXME("Could not get length\n");
1351 return hres;
1352 }
1353
1354 /* FIXME: check IsCallable */
1355 if(!argc || !is_object_instance(argv[0])) {
1356 FIXME("Invalid arg %s\n", debugstr_jsval(argc ? argv[0] : jsval_undefined()));
1358 goto done;
1359 }
1360 callback = get_object(argv[0]);
1361
1362 if(argc > 1)
1363 context_this = argv[1];
1364
1365 hres = create_array(ctx, 0, &array);
1366 if(FAILED(hres))
1367 goto done;
1368
1369 for(k = 0; k < length; k++) {
1370 hres = jsdisp_get_idx(jsthis, k, &callback_args[0]);
1371 if(hres == DISP_E_UNKNOWNNAME) {
1372 hres = S_OK;
1373 continue;
1374 }
1375 if(FAILED(hres))
1376 break;
1377
1378 callback_args[1] = jsval_number(k);
1379 callback_args[2] = jsval_obj(jsthis);
1380 hres = disp_call_value(ctx, callback, context_this, DISPATCH_METHOD, 3, callback_args, &mapped_value);
1381 jsval_release(callback_args[0]);
1382 if(FAILED(hres))
1383 break;
1384
1385 hres = jsdisp_propput_idx(array, k, mapped_value);
1386 if(FAILED(hres))
1387 break;
1388 }
1389
1390 if(SUCCEEDED(hres) && r)
1391 *r = jsval_obj(array);
1392 else
1394done:
1395 jsdisp_release(jsthis);
1396 return hres;
1397}
int k
Definition: mpi.c:3369

◆ Array_on_put()

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

Definition at line 1596 of file array.c.

1597{
1599 const WCHAR *ptr = name;
1600 DWORD id = 0;
1601
1602 if(!is_digit(*ptr))
1603 return;
1604
1605 while(*ptr && is_digit(*ptr)) {
1606 id = id*10 + (*ptr-'0');
1607 ptr++;
1608 }
1609
1610 if(*ptr)
1611 return;
1612
1613 if(id >= array->length)
1614 array->length = id+1;
1615}
#define is_digit(c)
Definition: astoll.c:39
Definition: name.c:39

◆ Array_pop()

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

Definition at line 358 of file array.c.

360{
361 jsdisp_t *jsthis;
362 jsval_t val;
365
366 TRACE("\n");
367
368 hres = get_length(ctx, vthis, &jsthis, &length);
369 if(FAILED(hres))
370 return hres;
371
372 if(!length) {
373 hres = set_length(jsthis, 0);
374 if(FAILED(hres))
375 goto done;
376
377 if(r)
378 *r = jsval_undefined();
379 goto done;
380 }
381
382 length--;
383 hres = jsdisp_get_idx(jsthis, length, &val);
384 if(SUCCEEDED(hres))
385 hres = jsdisp_delete_idx(jsthis, length);
386 else if(hres == DISP_E_UNKNOWNNAME) {
388 hres = S_OK;
389 }else
390 goto done;
391
392 if(SUCCEEDED(hres))
393 hres = set_length(jsthis, length);
394
395 if(FAILED(hres)) {
397 goto done;
398 }
399
400 if(r)
401 *r = val;
402 else
404done:
405 jsdisp_release(jsthis);
406 return hres;
407}
HRESULT jsdisp_delete_idx(jsdisp_t *obj, DWORD idx)
Definition: dispex.c:3019

◆ Array_push()

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

Definition at line 410 of file array.c.

412{
413 jsdisp_t *jsthis;
414 UINT32 length = 0;
415 unsigned i;
417
418 TRACE("\n");
419
420 hres = get_length(ctx, vthis, &jsthis, &length);
421 if(FAILED(hres))
422 return hres;
423
424 for(i=0; i < argc; i++) {
425 hres = jsdisp_propput_idx(jsthis, length+i, argv[i]);
426 if(FAILED(hres))
427 goto done;
428 }
429
430 hres = set_length(jsthis, length+argc);
431 if(FAILED(hres))
432 goto done;
433
434 if(r)
436done:
437 jsdisp_release(jsthis);
438 return hres;
439}

◆ Array_reduce()

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

Definition at line 1399 of file array.c.

1400{
1401 jsval_t callback_args[4], acc, new_acc;
1402 BOOL have_value = FALSE;
1404 jsdisp_t *jsthis;
1405 UINT32 length, k;
1406 HRESULT hres;
1407
1408 TRACE("\n");
1409
1410 hres = get_length(ctx, vthis, &jsthis, &length);
1411 if(FAILED(hres)) {
1412 FIXME("Could not get length\n");
1413 return hres;
1414 }
1415
1416 /* Fixme check IsCallable */
1417 if(!argc || !is_object_instance(argv[0])) {
1418 FIXME("Invalid arg %s\n", debugstr_jsval(argc ? argv[0] : jsval_undefined()));
1420 goto done;
1421 }
1422 callback = get_object(argv[0]);
1423
1424 if(argc > 1) {
1425 have_value = TRUE;
1426 hres = jsval_copy(argv[1], &acc);
1427 if(FAILED(hres))
1428 goto done;
1429 }
1430
1431 for(k = 0; k < length; k++) {
1432 hres = jsdisp_get_idx(jsthis, k, &callback_args[1]);
1433 if(hres == DISP_E_UNKNOWNNAME) {
1434 hres = S_OK;
1435 continue;
1436 }
1437 if(FAILED(hres))
1438 break;
1439
1440 if(!have_value) {
1441 have_value = TRUE;
1442 acc = callback_args[1];
1443 continue;
1444 }
1445
1446 callback_args[0] = acc;
1447 callback_args[2] = jsval_number(k);
1448 callback_args[3] = jsval_obj(jsthis);
1449 hres = disp_call_value(ctx, callback, jsval_undefined(), DISPATCH_METHOD, ARRAY_SIZE(callback_args), callback_args, &new_acc);
1450 jsval_release(callback_args[1]);
1451 if(FAILED(hres))
1452 break;
1453
1454 jsval_release(acc);
1455 acc = new_acc;
1456 }
1457
1458 if(SUCCEEDED(hres) && !have_value) {
1459 WARN("No array element\n");
1461 }
1462
1463 if(SUCCEEDED(hres) && r)
1464 *r = acc;
1465 else if(have_value)
1466 jsval_release(acc);
1467done:
1468 jsdisp_release(jsthis);
1469 return hres;
1470}
#define WARN(fmt,...)
Definition: precomp.h:61
#define JS_E_INVALID_ACTION
Definition: jscript.h:533
HRESULT jsval_copy(jsval_t v, jsval_t *r)
Definition: jsutils.c:225

◆ Array_reverse()

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

Definition at line 441 of file array.c.

443{
444 jsdisp_t *jsthis;
445 UINT32 length, k, l;
446 jsval_t v1, v2;
447 HRESULT hres1, hres2;
448
449 TRACE("\n");
450
451 hres1 = get_length(ctx, vthis, &jsthis, &length);
452 if(FAILED(hres1))
453 return hres1;
454
455 for(k=0; k<length/2; k++) {
456 l = length-k-1;
457
458 hres1 = jsdisp_get_idx(jsthis, k, &v1);
459 if(FAILED(hres1) && hres1!=DISP_E_UNKNOWNNAME)
460 goto done;
461
462 hres2 = jsdisp_get_idx(jsthis, l, &v2);
463 if(FAILED(hres2) && hres2!=DISP_E_UNKNOWNNAME) {
465 hres1 = hres2;
466 goto done;
467 }
468
469 if(hres1 == DISP_E_UNKNOWNNAME)
470 hres1 = jsdisp_delete_idx(jsthis, l);
471 else
472 hres1 = jsdisp_propput_idx(jsthis, l, v1);
473
474 if(FAILED(hres1)) {
477 goto done;
478 }
479
480 if(hres2 == DISP_E_UNKNOWNNAME)
481 hres2 = jsdisp_delete_idx(jsthis, k);
482 else
483 hres2 = jsdisp_propput_idx(jsthis, k, v2);
484
485 if(FAILED(hres2)) {
487 hres1 = hres2;
488 goto done;
489 }
490 }
491
492 if(r)
493 *r = jsval_obj(jsdisp_addref(jsthis));
494done:
495 jsdisp_release(jsthis);
496 return hres1;
497}
r l[0]
Definition: byte_order.h:168
GLfloat GLfloat v1
Definition: glext.h:6062
GLfloat GLfloat GLfloat v2
Definition: glext.h:6063
jsdisp_t * jsdisp_addref(jsdisp_t *obj)
Definition: dispex.c:1902

◆ Array_set_length()

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

Definition at line 123 of file array.c.

124{
126 DOUBLE len = -1;
127 DWORD i;
129
130 TRACE("%p %ld\n", This, This->length);
131
132 hres = to_number(ctx, value, &len);
133 if(FAILED(hres))
134 return hres;
135
136 len = floor(len);
137 if(len!=(DWORD)len)
138 return JS_E_INVALID_LENGTH;
139
140 for(i=len; i < This->length; i++) {
141 hres = jsdisp_delete_idx(&This->dispex, i);
142 if(FAILED(hres))
143 return hres;
144 }
145
146 This->length = len;
147 return S_OK;
148}
_ACRTIMP double __cdecl floor(double)
Definition: floor.c:18
HRESULT to_number(script_ctx_t *, jsval_t, double *)
Definition: jsutils.c:630
#define JS_E_INVALID_LENGTH
Definition: jscript.h:571
double DOUBLE
Definition: typedefs.h:70

◆ Array_shift()

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

Definition at line 500 of file array.c.

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

◆ Array_slice()

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

Definition at line 559 of file array.c.

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

◆ Array_some()

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

Definition at line 1472 of file array.c.

1474{
1475 jsval_t context_this = jsval_undefined();
1476 jsval_t value, args[3], res;
1477 BOOL boolval, ret = FALSE;
1479 unsigned length, i;
1480 jsdisp_t *jsthis;
1481 HRESULT hres;
1482
1483 TRACE("\n");
1484
1485 hres = get_length(ctx, vthis, &jsthis, &length);
1486 if(FAILED(hres))
1487 return hres;
1488
1489 /* FIXME: check IsCallable */
1490 if(!argc || !is_object_instance(argv[0])) {
1491 FIXME("Invalid arg %s\n", debugstr_jsval(argc ? argv[0] : jsval_undefined()));
1493 goto done;
1494 }
1495 callback = get_object(argv[0]);
1496
1497 if(argc > 1)
1498 context_this = argv[1];
1499
1500 for(i = 0; i < length; i++) {
1501 hres = jsdisp_get_idx(jsthis, i, &value);
1502 if(FAILED(hres)) {
1504 continue;
1505 goto done;
1506 }
1507 args[0] = value;
1508 args[1] = jsval_number(i);
1509 args[2] = jsval_obj(jsthis);
1512 if(FAILED(hres))
1513 goto done;
1514
1515 hres = to_boolean(res, &boolval);
1517 if(FAILED(hres))
1518 goto done;
1519 if(boolval) {
1520 ret = TRUE;
1521 break;
1522 }
1523 }
1524
1525 if(r)
1526 *r = jsval_bool(ret);
1527 hres = S_OK;
1528done:
1529 jsdisp_release(jsthis);
1530 return hres;
1531}

◆ Array_sort()

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

Definition at line 683 of file array.c.

685{
686 jsdisp_t *jsthis, *cmp_func = NULL;
687 jsval_t *vtab, **sorttab = NULL;
689 DWORD i;
690 HRESULT hres = S_OK;
691
692 TRACE("\n");
693
694 hres = get_length(ctx, vthis, &jsthis, &length);
695 if(FAILED(hres))
696 return hres;
697
698 if(argc >= 1) {
699 if(is_object_instance(argv[0])) {
700 if(argc > 1 && ctx->version < SCRIPTLANGUAGEVERSION_ES5) {
701 WARN("invalid arg_cnt %d\n", argc);
703 goto done;
704 }
707 WARN("cmp_func is not a function\n");
708 if(cmp_func)
711 goto done;
712 }
713 }else if(ctx->version >= SCRIPTLANGUAGEVERSION_ES5 ? !is_undefined(argv[0]) :
714 (!is_null(argv[0]) || is_null_disp(argv[0]))) {
715 WARN("invalid arg %s\n", debugstr_jsval(argv[0]));
717 goto done;
718 }
719 }
720
721 if(!length) {
722 if(cmp_func)
724 if(r)
725 *r = jsval_obj(jsdisp_addref(jsthis));
726 goto done;
727 }
728
729 vtab = calloc(length, sizeof(*vtab));
730 if(vtab) {
731 for(i=0; i<length; i++) {
732 hres = jsdisp_get_idx(jsthis, i, vtab+i);
733 if(hres == DISP_E_UNKNOWNNAME) {
734 vtab[i] = jsval_undefined();
735 hres = S_OK;
736 } else if(FAILED(hres)) {
737 WARN("Could not get elem %ld: %08lx\n", i, hres);
738 break;
739 }
740 }
741 }else {
743 }
744
745 if(SUCCEEDED(hres)) {
746 sorttab = malloc(length*2*sizeof(*sorttab));
747 if(!sorttab)
749 }
750
751 /* merge-sort */
752 if(SUCCEEDED(hres)) {
753 jsval_t *tmpv, **tmpbuf;
754 INT cmp;
755
756 tmpbuf = sorttab + length;
757 for(i=0; i < length; i++)
758 sorttab[i] = vtab+i;
759
760 for(i=0; i < length/2; i++) {
761 hres = sort_cmp(ctx, cmp_func, *sorttab[2*i+1], *sorttab[2*i], &cmp);
762 if(FAILED(hres))
763 break;
764
765 if(cmp < 0) {
766 tmpv = sorttab[2*i];
767 sorttab[2*i] = sorttab[2*i+1];
768 sorttab[2*i+1] = tmpv;
769 }
770 }
771
772 if(SUCCEEDED(hres)) {
773 DWORD k, a, b, bend;
774
775 for(k=2; k < length; k *= 2) {
776 for(i=0; i+k < length; i += 2*k) {
777 a = b = 0;
778 if(i+2*k <= length)
779 bend = k;
780 else
781 bend = length - (i+k);
782
783 memcpy(tmpbuf, sorttab+i, k*sizeof(jsval_t*));
784
785 while(a < k && b < bend) {
786 hres = sort_cmp(ctx, cmp_func, *tmpbuf[a], *sorttab[i+k+b], &cmp);
787 if(FAILED(hres))
788 break;
789
790 if(cmp < 0) {
791 sorttab[i+a+b] = tmpbuf[a];
792 a++;
793 }else {
794 sorttab[i+a+b] = sorttab[i+k+b];
795 b++;
796 }
797 }
798
799 if(FAILED(hres))
800 break;
801
802 if(a < k)
803 memcpy(sorttab+i+a+b, tmpbuf+a, (k-a)*sizeof(jsval_t*));
804 }
805
806 if(FAILED(hres))
807 break;
808 }
809 }
810
811 for(i=0; SUCCEEDED(hres) && i < length; i++)
812 hres = jsdisp_propput_idx(jsthis, i, *sorttab[i]);
813 }
814
815 if(vtab) {
816 for(i=0; i < length; i++)
817 jsval_release(vtab[i]);
818 free(vtab);
819 }
820 free(sorttab);
821 if(cmp_func)
823
824 if(FAILED(hres))
825 goto done;
826
827 if(r)
828 *r = jsval_obj(jsdisp_addref(jsthis));
829done:
830 jsdisp_release(jsthis);
831 return hres;
832}
static HRESULT sort_cmp(script_ctx_t *ctx, jsdisp_t *cmp_func, jsval_t v1, jsval_t v2, INT *cmp)
Definition: array.c:631
int(* cmp_func)(const void *ptr1, const void *ptr2)
Definition: btrfs.c:38
#define malloc
Definition: debug_ros.c:4
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:2543
#define JS_E_JSCRIPT_EXPECTED
Definition: jscript.h:561
#define SCRIPTLANGUAGEVERSION_ES5
Definition: jscript.h:53
@ JSCLASS_FUNCTION
Definition: jscript.h:109
static BOOL is_null_disp(jsval_t v)
Definition: jsval.h:190
#define a
Definition: ke_i.h:78
#define b
Definition: ke_i.h:79
#define cmp(status, error)
Definition: error.c:118
int32_t INT
Definition: typedefs.h:58

◆ Array_splice()

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

Definition at line 835 of file array.c.

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

◆ array_this()

static ArrayInstance * array_this ( jsval_t  vthis)
inlinestatic

Definition at line 44 of file array.c.

45{
46 jsdisp_t *jsdisp = is_object_instance(vthis) ? to_jsdisp(get_object(vthis)) : NULL;
47 return (jsdisp && is_class(jsdisp, JSCLASS_ARRAY)) ? array_from_jsdisp(jsdisp) : NULL;
48}
jsdisp_t * to_jsdisp(IDispatch *disp)
Definition: dispex.c:2447

Referenced by Array_toLocaleString(), and Array_toString().

◆ Array_toLocaleString()

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

Definition at line 999 of file array.c.

1001{
1002 jsdisp_t *jsthis;
1003 UINT32 length;
1004 HRESULT hres;
1005 WCHAR buf[5];
1006 int len;
1007
1008 TRACE("\n");
1009
1010 if(ctx->version < SCRIPTLANGUAGEVERSION_ES5) {
1011 ArrayInstance *array = array_this(vthis);
1012 if(!array)
1013 return JS_E_ARRAY_EXPECTED;
1014 jsthis = jsdisp_addref(&array->dispex);
1015 length = array->length;
1016 }else {
1017 hres = get_length(ctx, vthis, &jsthis, &length);
1018 if(FAILED(hres))
1019 return hres;
1020 }
1021
1022 if(!(len = GetLocaleInfoW(ctx->lcid, LOCALE_SLIST, buf, ARRAY_SIZE(buf) - 1))) {
1023 buf[len++] = ',';
1024 len++;
1025 }
1026 buf[len - 1] = ' ';
1027 buf[len] = '\0';
1028
1030 jsdisp_release(jsthis);
1031 return hres;
1032}
static ArrayInstance * array_this(jsval_t vthis)
Definition: array.c:44
static HRESULT to_locale_string(script_ctx_t *ctx, jsval_t val, jsstr_t **str)
Definition: array.c:961
INT WINAPI GetLocaleInfoW(LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len)
Definition: locale.c:1675
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define JS_E_ARRAY_EXPECTED
Definition: jscript.h:572
#define LOCALE_SLIST
Definition: winnls.h:50

◆ Array_toString()

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

Definition at line 947 of file array.c.

949{
951
952 TRACE("\n");
953
954 array = array_this(vthis);
955 if(!array)
956 return JS_E_ARRAY_EXPECTED;
957
958 return array_join(ctx, &array->dispex, array->length, L",", 1, to_string, r);
959}

◆ Array_unshift()

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

Definition at line 1534 of file array.c.

1536{
1537 jsdisp_t *jsthis;
1538 WCHAR buf[14], *buf_end, *str;
1539 UINT32 i, length;
1540 jsval_t val;
1541 DISPID id;
1542 HRESULT hres;
1543
1544 TRACE("\n");
1545
1546 hres = get_length(ctx, vthis, &jsthis, &length);
1547 if(FAILED(hres))
1548 return hres;
1549
1550 if(argc) {
1551 buf_end = buf + ARRAY_SIZE(buf)-1;
1552 *buf_end-- = 0;
1553 i = length;
1554
1555 while(i--) {
1556 str = idx_to_str(i, buf_end);
1557
1558 hres = jsdisp_get_id(jsthis, str, 0, &id);
1559 if(SUCCEEDED(hres)) {
1560 hres = jsdisp_propget(jsthis, id, &val);
1561 if(FAILED(hres))
1562 goto done;
1563
1564 hres = jsdisp_propput_idx(jsthis, i+argc, val);
1566 }else if(hres == DISP_E_UNKNOWNNAME) {
1567 hres = IDispatchEx_DeleteMemberByDispID(to_dispex(jsthis), id);
1568 }
1569 }
1570
1571 if(FAILED(hres))
1572 goto done;
1573 }
1574
1575 for(i=0; i<argc; i++) {
1576 hres = jsdisp_propput_idx(jsthis, i, argv[i]);
1577 if(FAILED(hres))
1578 goto done;
1579 }
1580
1581 if(argc) {
1582 length += argc;
1583 hres = set_length(jsthis, length);
1584 if(FAILED(hres))
1585 goto done;
1586 }
1587
1588 if(r)
1589 *r = ctx->version < 2 ? jsval_undefined() : jsval_number(length);
1590 hres = S_OK;
1591done:
1592 jsdisp_release(jsthis);
1593 return hres;
1594}
WCHAR * idx_to_str(DWORD idx, WCHAR *ptr)
Definition: array.c:100
GLuint id
Definition: glext.h:5910
HRESULT jsdisp_get_id(jsdisp_t *jsdisp, const WCHAR *name, DWORD flags, DISPID *id)
Definition: dispex.c:2550
HRESULT jsdisp_propget(jsdisp_t *jsdisp, DISPID id, jsval_t *val)
Definition: dispex.c:2983
static IDispatchEx * to_dispex(jsdisp_t *jsdisp)
Definition: jscript.h:227
static VARIANTARG static DISPID
Definition: ordinal.c:49
const WCHAR * str

◆ ArrayConstr_isArray()

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

Definition at line 1660 of file array.c.

1661{
1662 jsdisp_t *obj;
1663
1664 TRACE("\n");
1665
1666 if(!argc || !is_object_instance(argv[0])) {
1667 if(r) *r = jsval_bool(FALSE);
1668 return S_OK;
1669 }
1670
1672 if(r) *r = jsval_bool(obj && is_class(obj, JSCLASS_ARRAY));
1673 return S_OK;
1674}

◆ ArrayConstr_value()

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

Definition at line 1676 of file array.c.

1678{
1679 jsdisp_t *obj;
1680 DWORD i;
1681 HRESULT hres;
1682
1683 TRACE("\n");
1684
1685 switch(flags) {
1686 case DISPATCH_METHOD:
1687 case DISPATCH_CONSTRUCT: {
1688 if(argc == 1 && is_number(argv[0])) {
1689 double n = get_number(argv[0]);
1690
1691 if(n < 0 || !is_int32(n))
1692 return JS_E_INVALID_LENGTH;
1693 if(!r)
1694 return S_OK;
1695
1696 hres = create_array(ctx, n, &obj);
1697 if(FAILED(hres))
1698 return hres;
1699
1700 *r = jsval_obj(obj);
1701 return S_OK;
1702 }
1703
1704 if(!r)
1705 return S_OK;
1707 if(FAILED(hres))
1708 return hres;
1709
1710 for(i=0; i < argc; i++) {
1712 if(FAILED(hres))
1713 break;
1714 }
1715 if(FAILED(hres)) {
1717 return hres;
1718 }
1719
1720 *r = jsval_obj(obj);
1721 break;
1722 }
1723 default:
1724 FIXME("unimplemented flags: %x\n", flags);
1725 return E_NOTIMPL;
1726 }
1727
1728 return S_OK;
1729}
#define E_NOTIMPL
Definition: ddrawi.h:99
GLbitfield flags
Definition: glext.h:7161
static BOOL is_number(jsval_t v)
Definition: jsval.h:200
static double get_number(jsval_t v)
Definition: jsval.h:233

Referenced by create_array_constr().

◆ concat_array()

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

Definition at line 150 of file array.c.

151{
152 jsval_t val;
153 DWORD i;
155
156 for(i=0; i < obj->length; i++) {
157 hres = jsdisp_get_idx(&obj->dispex, i, &val);
159 continue;
160 if(FAILED(hres))
161 return hres;
162
165 if(FAILED(hres))
166 return hres;
167 }
168
169 *len += obj->length;
170 return S_OK;
171}

Referenced by concat_obj().

◆ concat_obj()

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

Definition at line 173 of file array.c.

174{
175 jsdisp_t *jsobj;
177
178 jsobj = iface_to_jsdisp(obj);
179 if(jsobj) {
180 if(is_class(jsobj, JSCLASS_ARRAY)) {
182 jsdisp_release(jsobj);
183 return hres;
184 }
185 jsdisp_release(jsobj);
186 }
187
188 return jsdisp_propput_idx(array, (*len)++, jsval_disp(obj));
189}
static HRESULT concat_array(jsdisp_t *array, ArrayInstance *obj, DWORD *len)
Definition: array.c:150
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 1780 of file array.c.

1781{
1783 HRESULT hres;
1784
1786 if(FAILED(hres))
1787 return hres;
1788
1789 array->length = length;
1790
1791 *ret = &array->dispex;
1792 return S_OK;
1793}
static HRESULT alloc_array(script_ctx_t *ctx, jsdisp_t *object_prototype, ArrayInstance **ret)
Definition: array.c:1731

Referenced by Array_concat(), Array_filter(), Array_map(), Array_slice(), Array_splice(), ArrayConstr_value(), create_match_array(), interp_carray(), object_keys(), 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 1765 of file array.c.

1766{
1768 HRESULT hres;
1769
1770 hres = alloc_array(ctx, object_prototype, &array);
1771 if(FAILED(hres))
1772 return hres;
1773
1775
1776 jsdisp_release(&array->dispex);
1777 return hres;
1778}
static const builtin_info_t ArrayConstr_info
Definition: array.c:1758
static HRESULT ArrayConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1676
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:809
const unsigned int PROPF_CONSTR
Definition: jsdisp.idl:34

Referenced by init_constructors().

◆ get_length()

static HRESULT get_length ( script_ctx_t ctx,
jsval_t  vthis,
jsdisp_t **  jsthis,
UINT32 ret 
)
static

Definition at line 56 of file array.c.

57{
58 jsdisp_t *jsdisp;
59 IDispatch *disp;
62
63 hres = to_object(ctx, vthis, &disp);
64 if(FAILED(hres))
65 return hres;
66
67 jsdisp = iface_to_jsdisp(disp);
68 IDispatch_Release(disp);
69 if(!jsdisp)
71 *jsthis = jsdisp;
72
73 if(is_class(jsdisp, JSCLASS_ARRAY)) {
74 *ret = array_from_jsdisp(jsdisp)->length;
75 return S_OK;
76 }
77
78 hres = jsdisp_propget_name(jsdisp, L"length", &val);
79 if(SUCCEEDED(hres)) {
82 if(SUCCEEDED(hres))
83 return hres;
84 }
85
86 jsdisp_release(jsdisp);
87 return hres;
88}
HRESULT jsdisp_propget_name(jsdisp_t *obj, const WCHAR *name, jsval_t *val)
Definition: dispex.c:2946
HRESULT to_uint32(script_ctx_t *, jsval_t, UINT32 *)
Definition: jsutils.c:754

Referenced by Array_every(), Array_filter(), Array_forEach(), Array_indexOf(), Array_join(), Array_lastIndexOf(), Array_map(), Array_pop(), Array_push(), Array_reduce(), Array_reverse(), Array_shift(), Array_slice(), Array_some(), Array_sort(), Array_splice(), Array_toLocaleString(), and Array_unshift().

◆ idx_to_str()

WCHAR * idx_to_str ( DWORD  idx,
WCHAR ptr 
)

Definition at line 100 of file array.c.

101{
102 if(!idx) {
103 *ptr = '0';
104 return ptr;
105 }
106
107 while(idx) {
108 *ptr-- = '0' + (idx%10);
109 idx /= 10;
110 }
111
112 return ptr+1;
113}

Referenced by Array_unshift(), and transform_json_object().

◆ set_length()

static HRESULT set_length ( jsdisp_t obj,
DWORD  length 
)
static

Definition at line 90 of file array.c.

91{
94 return S_OK;
95 }
96
97 return jsdisp_propput_name(obj, L"length", jsval_number(length));
98}

Referenced by Array_filter(), 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 631 of file array.c.

632{
634
635 if(cmp_func) {
636 jsval_t args[2] = {v1, v2};
637 jsval_t res;
638 double n;
639
641 if(FAILED(hres))
642 return hres;
643
644 hres = to_number(ctx, res, &n);
646 if(FAILED(hres))
647 return hres;
648
649 if(n == 0)
650 *cmp = 0;
651 *cmp = n > 0.0 ? 1 : -1;
652 }else if(is_undefined(v1)) {
653 *cmp = is_undefined(v2) ? 0 : 1;
654 }else if(is_undefined(v2)) {
655 *cmp = -1;
656 }else if(is_number(v1) && is_number(v2)) {
657 double d = get_number(v1)-get_number(v2);
658 if(d > 0.0)
659 *cmp = 1;
660 else
661 *cmp = d < -0.0 ? -1 : 0;
662 }else {
663 jsstr_t *x, *y;
664
665 hres = to_string(ctx, v1, &x);
666 if(FAILED(hres))
667 return hres;
668
669 hres = to_string(ctx, v2, &y);
670 if(SUCCEEDED(hres)) {
671 *cmp = jsstr_cmp(x, y);
673 }
675 if(FAILED(hres))
676 return hres;
677 }
678
679 return S_OK;
680}
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, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: dispex.c:2581
int jsstr_cmp(jsstr_t *str1, jsstr_t *str2)
Definition: jsstr.c:192

Referenced by Array_sort().

◆ to_locale_string()

static HRESULT to_locale_string ( script_ctx_t ctx,
jsval_t  val,
jsstr_t **  str 
)
static

Definition at line 961 of file array.c.

962{
963 jsdisp_t *jsdisp;
964 IDispatch *obj;
966
967 switch(jsval_type(val)) {
968 case JSV_OBJECT:
969 hres = disp_call_name(ctx, get_object(val), L"toLocaleString", DISPATCH_METHOD, 0, NULL, &val);
970 if(FAILED(hres)) {
973 return hres;
974 }
975 break;
976 case JSV_NUMBER:
977 if(ctx->version >= SCRIPTLANGUAGEVERSION_ES5)
979 /* fall through */
980 default:
981 if(ctx->version >= SCRIPTLANGUAGEVERSION_ES5)
982 break;
983
984 hres = to_object(ctx, val, &obj);
985 if(FAILED(hres))
986 return hres;
987
988 jsdisp = as_jsdisp(obj);
989 hres = jsdisp_call_name(jsdisp, L"toLocaleString", DISPATCH_METHOD, 0, NULL, &val);
990 jsdisp_release(jsdisp);
991 if(FAILED(hres))
992 return hres;
993 break;
994 }
995
996 return to_string(ctx, val, str);
997}
HRESULT disp_call_name(script_ctx_t *ctx, IDispatch *disp, const WCHAR *name, WORD flags, unsigned argc, jsval_t *argv, jsval_t *ret)
Definition: dispex.c:2740
jsdisp_t * as_jsdisp(IDispatch *disp)
Definition: dispex.c:2441
HRESULT jsdisp_call_name(jsdisp_t *disp, const WCHAR *name, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: dispex.c:2615
#define JS_E_FUNCTION_EXPECTED
Definition: jscript.h:552
HRESULT localize_number(script_ctx_t *, DOUBLE, BOOL, jsstr_t **)
Definition: number.c:350
#define JS_E_INVALID_PROPERTY
Definition: jscript.h:532
@ JSV_NUMBER
Definition: jsval.h:49
@ JSV_OBJECT
Definition: jsval.h:47
static jsval_type_t jsval_type(jsval_t v)
Definition: jsval.h:219

Referenced by Array_toLocaleString().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( jscript  )

Variable Documentation

◆ Array_info

const builtin_info_t Array_info
static
Initial value:
= {
.class = JSCLASS_ARRAY,
.props_cnt = ARRAY_SIZE(Array_props),
.props = Array_props,
.on_put = Array_on_put,
}
static void Array_on_put(jsdisp_t *dispex, const WCHAR *name)
Definition: array.c:1596
static const builtin_prop_t Array_props[]
Definition: array.c:1617

Definition at line 1641 of file array.c.

Referenced by alloc_array().

◆ Array_props

const builtin_prop_t Array_props[]
static
Initial value:
= {
{L"concat", Array_concat, PROPF_METHOD|1},
{L"join", Array_join, PROPF_METHOD|1},
{L"push", Array_push, PROPF_METHOD|1},
{L"slice", Array_slice, PROPF_METHOD|2},
{L"sort", Array_sort, PROPF_METHOD|1},
{L"splice", Array_splice, PROPF_METHOD|2},
{L"toLocaleString", Array_toLocaleString, PROPF_METHOD},
{L"toString", Array_toString, PROPF_METHOD},
{L"unshift", Array_unshift, PROPF_METHOD|1},
}
static HRESULT Array_shift(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:500
static HRESULT Array_sort(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:683
static HRESULT Array_concat(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:191
static HRESULT Array_every(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1034
static HRESULT Array_push(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:410
static HRESULT Array_lastIndexOf(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1275
static HRESULT Array_splice(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:835
static HRESULT Array_slice(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:559
static HRESULT Array_toString(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:947
static HRESULT Array_toLocaleString(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:999
static HRESULT Array_map(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1337
static HRESULT Array_indexOf(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1217
static HRESULT Array_filter(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1095
static HRESULT Array_join(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:325
static HRESULT Array_get_length(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
Definition: array.c:115
static HRESULT Array_reduce(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1399
static HRESULT Array_some(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1472
static HRESULT Array_unshift(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1534
static HRESULT Array_reverse(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:441
static HRESULT Array_set_length(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t value)
Definition: array.c:123
static HRESULT Array_forEach(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1166
static HRESULT Array_pop(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:358
#define PROPF_ES5
Definition: jscript.h:90
const unsigned int PROPF_METHOD
Definition: jsdisp.idl:33

Definition at line 1617 of file array.c.

◆ ArrayConstr_info

const builtin_info_t ArrayConstr_info
static
Initial value:
= {
.class = JSCLASS_FUNCTION,
.call = Function_value,
}
static const builtin_prop_t ArrayConstr_props[]
Definition: array.c:1754
HRESULT Function_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:600

Definition at line 1758 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, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1660

Definition at line 1754 of file array.c.

◆ ArrayInst_info

const builtin_info_t ArrayInst_info
static
Initial value:
= {
.class = JSCLASS_ARRAY,
.props_cnt = ARRAY_SIZE(ArrayInst_props),
.props = ArrayInst_props,
.on_put = Array_on_put,
}
static const builtin_prop_t ArrayInst_props[]
Definition: array.c:1648

Definition at line 1652 of file array.c.

Referenced by alloc_array().

◆ ArrayInst_props

const builtin_prop_t ArrayInst_props[]
static
Initial value:
= {
}

Definition at line 1648 of file array.c.