#include <math.h>
#include <assert.h>
#include "jscript.h"
#include "parser.h"
#include "wine/debug.h"
Go to the source code of this file.
|
| | WINE_DEFAULT_DEBUG_CHANNEL (jscript) |
| |
| static BOOL | is_json_space (WCHAR c) |
| |
| static WCHAR | skip_spaces (json_parse_ctx_t *ctx) |
| |
| static BOOL | is_keyword (json_parse_ctx_t *ctx, const WCHAR *keyword) |
| |
| static BOOL | unescape_json_string (WCHAR *str, size_t *len) |
| |
| static HRESULT | parse_json_string (json_parse_ctx_t *ctx, WCHAR **r) |
| |
| static HRESULT | parse_json_value (json_parse_ctx_t *ctx, jsval_t *r) |
| |
| static jsval_t | transform_json_object (struct transform_json_object_ctx *proc_ctx, jsdisp_t *holder, jsstr_t *name) |
| |
| static HRESULT | JSON_parse (script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) |
| |
| static BOOL | stringify_push_obj (stringify_ctx_t *ctx, jsdisp_t *obj) |
| |
| static void | stringify_pop_obj (stringify_ctx_t *ctx) |
| |
| static BOOL | is_on_stack (stringify_ctx_t *ctx, jsdisp_t *obj) |
| |
| static BOOL | append_string_len (stringify_ctx_t *ctx, const WCHAR *str, size_t len) |
| |
| static BOOL | append_string (stringify_ctx_t *ctx, const WCHAR *str) |
| |
| static BOOL | append_char (stringify_ctx_t *ctx, WCHAR c) |
| |
| static BOOL | append_simple_quote (stringify_ctx_t *ctx, WCHAR c) |
| |
| static HRESULT | maybe_to_primitive (script_ctx_t *ctx, jsval_t val, jsval_t *r) |
| |
| static HRESULT | json_quote (stringify_ctx_t *ctx, const WCHAR *ptr, size_t len) |
| |
| static BOOL | is_callable (jsdisp_t *obj) |
| |
| static HRESULT | stringify (stringify_ctx_t *ctx, jsdisp_t *object, const WCHAR *name) |
| |
| static HRESULT | stringify_array (stringify_ctx_t *ctx, jsdisp_t *obj) |
| |
| static HRESULT | stringify_object (stringify_ctx_t *ctx, jsdisp_t *obj) |
| |
| static HRESULT | JSON_stringify (script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) |
| |
| HRESULT | create_json (script_ctx_t *ctx, jsdisp_t **ret) |
| |
◆ append_char()
◆ append_simple_quote()
◆ append_string()
◆ append_string_len()
◆ create_json()
Definition at line 1032 of file json.c.
1033{
1036
1037 json =
calloc(1,
sizeof(*json));
1038 if(!json)
1040
1045 }
1046
1049}
HRESULT init_dispex_from_constr(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *constr)
static const builtin_info_t JSON_info
Referenced by init_global().
◆ is_callable()
◆ is_json_space()
Definition at line 40 of file json.c.
41{
42 return c ==
' ' ||
c ==
'\t' ||
c ==
'\n' ||
c ==
'\r';
43}
Referenced by skip_spaces().
◆ is_keyword()
Definition at line 52 of file json.c.
53{
58 }
63}
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
BOOL is_identifier_char(WCHAR c)
Referenced by parse_json_value().
◆ is_on_stack()
◆ JSON_parse()
Definition at line 437 of file json.c.
438{
445
449
451
457 FIXME(
"syntax error\n");
460 }
464
465
471 }
474
477
482 }
486 }
487
490 else
493}
GLdouble GLdouble GLdouble r
GLenum GLuint GLenum GLsizei const GLchar * buf
HRESULT jsdisp_define_data_property(jsdisp_t *obj, const WCHAR *name, unsigned flags, jsval_t value)
ULONG jsdisp_release(jsdisp_t *obj)
HRESULT to_flat_string(script_ctx_t *, jsval_t, jsstr_t **, const WCHAR **)
HRESULT create_object(script_ctx_t *, jsdisp_t *, jsdisp_t **)
const unsigned int PROPF_WRITABLE
const unsigned int PROPF_ENUMERABLE
const unsigned int PROPF_CONFIGURABLE
static jsval_t transform_json_object(struct transform_json_object_ctx *proc_ctx, jsdisp_t *holder, jsstr_t *name)
static WCHAR skip_spaces(json_parse_ctx_t *ctx)
static HRESULT parse_json_value(json_parse_ctx_t *ctx, jsval_t *r)
jsstr_t * jsstr_empty(void)
static void jsstr_release(jsstr_t *str)
static unsigned jsstr_length(jsstr_t *str)
void jsval_release(jsval_t val)
static IDispatch * get_object(jsval_t v)
static BOOL is_object_instance(jsval_t v)
◆ json_quote()
Definition at line 625 of file json.c.
626{
629
632 case '"':
633 case '\\':
636 break;
637 case '\b':
640 break;
641 case '\f':
644 break;
645 case '\n':
648 break;
649 case '\r':
652 break;
653 case '\t':
656 break;
657 default:
663 }else {
666 }
667 }
669 }
670
672}
static BOOL append_string(stringify_ctx_t *ctx, const WCHAR *str)
static BOOL append_simple_quote(stringify_ctx_t *ctx, WCHAR c)
static BOOL append_char(stringify_ctx_t *ctx, WCHAR c)
Referenced by stringify(), and stringify_object().
◆ JSON_stringify()
Definition at line 939 of file json.c.
940{
944
946
951 }
952
957 FIXME(
"Array replacer not yet supported\n");
959 }
960 }
961
964
967 goto fail;
968
977 stringify_ctx.
gap[
i] =
' ';
978 stringify_ctx.
gap[
len] = 0;
979 }
986 }
987
989 }
990
992 goto fail;
994 goto fail;
995
999
1004 else
1006 }else {
1008 }
1009 }
1010
1011fail:
1019}
_ACRTIMP double __cdecl floor(double)
HRESULT jsdisp_propput_name(jsdisp_t *obj, const WCHAR *name, jsval_t val)
jsdisp_t * jsdisp_addref(jsdisp_t *obj)
jsdisp_t * to_jsdisp(IDispatch *disp)
static HRESULT maybe_to_primitive(script_ctx_t *ctx, jsval_t val, jsval_t *r)
static HRESULT stringify(stringify_ctx_t *ctx, jsdisp_t *object, const WCHAR *name)
static BOOL is_callable(jsdisp_t *obj)
jsstr_t * jsstr_alloc_len(const WCHAR *buf, unsigned len)
void jsstr_extract(jsstr_t *str, unsigned off, unsigned len, WCHAR *buf)
static BOOL is_number(jsval_t v)
static jsval_t jsval_string(jsstr_t *str)
static jsval_t jsval_undefined(void)
static jsstr_t * get_string(jsval_t v)
static double get_number(jsval_t v)
static BOOL is_string(parse_buffer *buf)
◆ maybe_to_primitive()
Definition at line 588 of file json.c.
589{
592
595
603 }
604
612 }
613
618 }
619
622}
BOOL bool_obj_value(jsdisp_t *obj)
static HRESULT to_string(VARIANT *src, BSTR *dst)
jsdisp_t * iface_to_jsdisp(IDispatch *iface)
HRESULT to_number(script_ctx_t *, jsval_t, double *)
HRESULT jsval_copy(jsval_t v, jsval_t *r)
static jsval_t jsval_obj(jsdisp_t *obj)
static jsval_t jsval_bool(BOOL b)
static jsval_t jsval_number(double n)
Referenced by JSON_stringify(), and stringify().
◆ parse_json_string()
Definition at line 137 of file json.c.
138{
142
143 while(*
ctx->ptr && *
ctx->ptr !=
'"') {
144 if(*
ctx->ptr++ ==
'\\')
146 }
148 FIXME(
"unterminated string\n");
150 }
151
158
160 WARN(
"unescape failed\n");
163 }
164
169}
BOOL unescape(WCHAR *str, size_t *len)
#define JS_E_INVALID_CHAR
static BOOL unescape_json_string(WCHAR *str, size_t *len)
Referenced by parse_json_value().
◆ parse_json_value()
Definition at line 172 of file json.c.
173{
175
177
178
179 case 'n':
181 break;
184
185
186 case 't':
188 break;
191 case 'f':
193 break;
196
197
198 case '{': {
202
206
212 }
213
214 while(1) {
216 break;
219 break;
220
222 FIXME(
"missing ':'\n");
224 break;
225 }
226
232 }
235 break;
236
241 }
242
243 if(*
ctx->ptr++ !=
',') {
244 FIXME(
"expected ','\n");
245 break;
246 }
248 }
249
251 break;
252 }
253
254
255 case '"': {
258
262
263
268
271 }
272
273
274 case '[': {
278
282
288 }
289
290 while(1) {
293 break;
294
298 break;
299
304 }
305
306 if(*
ctx->ptr !=
',') {
307 FIXME(
"expected ','\n");
308 break;
309 }
310
313 }
314
316 break;
317 }
318
319
320 default: {
323
324 if(*
ctx->ptr ==
'-') {
328 }
329
331 break;
332
335 break;
336
339 }
340 }
341
344}
HRESULT create_array(script_ctx_t *ctx, DWORD length, jsdisp_t **ret)
HRESULT jsdisp_propput_idx(jsdisp_t *obj, DWORD idx, jsval_t val)
HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret)
static BOOL is_keyword(json_parse_ctx_t *ctx, const WCHAR *keyword)
static HRESULT parse_json_string(json_parse_ctx_t *ctx, WCHAR **r)
static jsstr_t * jsstr_alloc(const WCHAR *str)
static jsval_t jsval_null(void)
Referenced by JSON_parse(), and parse_json_value().
◆ skip_spaces()
◆ stringify()
Definition at line 820 of file json.c.
821{
824
828
832
837 }
838
841 FIXME(
"Use toJSON.\n");
842 }
843
850 }
859 }
860
866
873 break;
877 break;
883 else
885 break;
886 }
892
893
896 break;
897
902 }else {
905 }
906 break;
907 }
910
914 break;
915 }
916
919 else
921
923 break;
924 }
927 break;
931 break;
932 }
933
936}
static BOOL get_bool(D3DXPARAMETER_TYPE type, const void *data)
HRESULT jsdisp_get_id(jsdisp_t *jsdisp, const WCHAR *name, DWORD flags, DISPID *id)
HRESULT jsdisp_call_value(jsdisp_t *jsfunc, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
HRESULT jsdisp_propget_name(jsdisp_t *obj, const WCHAR *name, jsval_t *val)
HRESULT double_to_string(double, jsstr_t **)
static HRESULT stringify_array(stringify_ctx_t *ctx, jsdisp_t *obj)
static HRESULT stringify_object(stringify_ctx_t *ctx, jsdisp_t *obj)
static HRESULT json_quote(stringify_ctx_t *ctx, const WCHAR *ptr, size_t len)
static const WCHAR * jsstr_flatten(jsstr_t *str)
static jsval_type_t jsval_type(jsval_t v)
static BOOL is_null_disp(jsval_t v)
static VARIANTARG static DISPID
#define DISP_E_UNKNOWNNAME
Referenced by JSON_stringify(), stringify_array(), and stringify_object().
◆ stringify_array()
Definition at line 682 of file json.c.
683{
687
689 FIXME(
"Found a cycle\n");
691 }
692
695
698
700
704
708
709 for(
j=0;
j <
ctx->stack_top;
j++) {
712 }
713 }
714
721 }
722
725
728}
unsigned array_get_length(jsdisp_t *array)
_ACRTIMP wchar_t *__cdecl _itow(int, wchar_t *, int)
GLuint GLsizei GLsizei * length
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
static void stringify_pop_obj(stringify_ctx_t *ctx)
static BOOL stringify_push_obj(stringify_ctx_t *ctx, jsdisp_t *obj)
static BOOL is_on_stack(stringify_ctx_t *ctx, jsdisp_t *obj)
Referenced by stringify().
◆ stringify_object()
Definition at line 731 of file json.c.
732{
733 DISPID dispid = DISPID_STARTENUM;
734 unsigned prop_cnt = 0,
i;
735 size_t stepback;
738
740 FIXME(
"Found a cycle\n");
742 }
743
746
749
750 while((
hres = IDispatchEx_GetNextDispID(
to_dispex(
obj), fdexEnumDefault, dispid, &dispid)) ==
S_OK) {
751 stepback =
ctx->buf_len;
752
755 break;
756 }
757
761 break;
762 }
763
764 for(
i=0;
i <
ctx->stack_top;
i++) {
767 break;
768 }
769 }
770 }
771
775
780 }
781
785 }
786
791
793 ctx->buf_len = stepback;
794 continue;
795 }
796
797 prop_cnt++;
798 }
799
800 if(prop_cnt && *
ctx->gap) {
803
804 for(
i=1;
i <
ctx->stack_top;
i++) {
807 break;
808 }
809 }
810 }
811
814
817}
static IDispatchEx * to_dispex(jsdisp_t *jsdisp)
UINT WINAPI SysStringLen(BSTR str)
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Referenced by stringify().
◆ stringify_pop_obj()
◆ stringify_push_obj()
◆ transform_json_object()
Definition at line 353 of file json.c.
354{
357
360 else
364
370
378
380 *buf_end-- = 0;
386 }
393 continue;
395 }else {
398 }
401 }
402 }else {
403 id = DISPID_STARTENUM;
404 for(;;) {
407 break;
414 }else {
417 else
420 }
424 }
425 }
426 }
427
434}
WCHAR * idx_to_str(DWORD idx, WCHAR *ptr)
GLboolean GLboolean GLboolean b
HRESULT disp_delete(IDispatch *disp, DISPID id, BOOL *ret)
HRESULT jsdisp_get_prop_name(jsdisp_t *obj, DISPID id, jsstr_t **r)
HRESULT jsdisp_next_prop(jsdisp_t *obj, DISPID id, enum jsdisp_enum_type enum_type, DISPID *ret)
@ JSDISP_ENUM_OWN_ENUMERABLE
static HRESULT disp_call_value(script_ctx_t *ctx, IDispatch *disp, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
static IDispatch * to_disp(jsdisp_t *jsdisp)
static BOOL is_undefined(jsval_t v)
Referenced by JSON_parse(), and transform_json_object().
◆ unescape_json_string()
Definition at line 65 of file json.c.
66{
69
74 continue;
75 }
76
79
81 case '\"':
82 case '\\':
83 case '/':
85 break;
86 case 'b':
88 break;
89 case 't':
91 break;
92 case 'n':
94 break;
95 case 'f':
97 break;
98 case 'r':
100 break;
101 case 'u':
108
113
118
123 break;
124 default:
126 }
127
130 }
131
134}
static int hex_to_int(const WCHAR wch)
Referenced by parse_json_string().
◆ WINE_DEFAULT_DEBUG_CHANNEL()
| WINE_DEFAULT_DEBUG_CHANNEL |
( |
jscript |
| ) |
|
◆ JSON_info
Initial value:= {
}
static const builtin_prop_t JSON_props[]
Definition at line 1026 of file json.c.
Referenced by create_json().
◆ JSON_props
Initial value:= {
}
const unsigned int PROPF_METHOD
static HRESULT JSON_parse(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
static HRESULT JSON_stringify(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition at line 1021 of file json.c.