#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 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 HRESULT | JSON_parse (script_ctx_t *ctx, vdisp_t *jsthis, 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, jsval_t val) |
|
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, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) |
|
HRESULT | create_json (script_ctx_t *ctx, jsdisp_t **ret) |
|
|
static const WCHAR | parseW [] = {'p','a','r','s','e',0} |
|
static const WCHAR | stringifyW [] = {'s','t','r','i','n','g','i','f','y',0} |
|
static const WCHAR | nullW [] = {'n','u','l','l',0} |
|
static const WCHAR | trueW [] = {'t','r','u','e',0} |
|
static const WCHAR | falseW [] = {'f','a','l','s','e',0} |
|
static const WCHAR | toJSONW [] = {'t','o','J','S','O','N',0} |
|
static const builtin_prop_t | JSON_props [] |
|
static const builtin_info_t | JSON_info |
|
◆ append_char()
◆ append_simple_quote()
◆ append_string()
◆ append_string_len()
◆ create_json()
Definition at line 837 of file json.c.
838{
841
842 json = heap_alloc_zero(sizeof(*json));
843 if(!json)
845
850 }
851
854}
static BOOL heap_free(void *mem)
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()
Definition at line 498 of file json.c.
499{
501}
static BOOL is_class(jsdisp_t *jsdisp, jsclass_t class)
Referenced by stringify().
◆ is_json_space()
Definition at line 44 of file json.c.
45{
46 return c ==
' ' ||
c ==
'\t' ||
c ==
'\n' ||
c ==
'\r';
47}
Referenced by skip_spaces().
◆ is_keyword()
Definition at line 56 of file json.c.
57{
62 }
67}
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 280 of file json.c.
281{
287
289 FIXME(
"Unsupported args\n");
291 }
292
296
298
306
308 FIXME(
"syntax error\n");
311 }
312
315 else
318}
GLdouble GLdouble GLdouble r
GLenum GLuint GLenum GLsizei const GLchar * buf
HRESULT to_flat_string(script_ctx_t *, jsval_t, jsstr_t **, const WCHAR **) DECLSPEC_HIDDEN
static WCHAR skip_spaces(json_parse_ctx_t *ctx)
static HRESULT parse_json_value(json_parse_ctx_t *ctx, jsval_t *r)
static void jsstr_release(jsstr_t *str)
static unsigned jsstr_length(jsstr_t *str)
void jsval_release(jsval_t val)
◆ json_quote()
Definition at line 448 of file json.c.
449{
452
455 case '"':
456 case '\\':
459 break;
460 case '\b':
463 break;
464 case '\f':
467 break;
468 case '\n':
471 break;
472 case '\r':
475 break;
476 case '\t':
479 break;
480 default:
482 static const WCHAR formatW[] = {
'\\',
'u',
'%',
'0',
'4',
'x',0};
487 }else {
490 }
491 }
493 }
494
496}
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 756 of file json.c.
757{
760
762
767 }
768
772 }
773
776
780
789 stringify_ctx.
gap[
i] =
' ';
790 stringify_ctx.
gap[
len] = 0;
791 }
798 }
799
801 }
802
806
811 else
813 }else {
815 }
816 }
817
821}
_Check_return_ _CRTIMP double __cdecl floor(_In_ double x)
const char * debugstr_jsval(const jsval_t) DECLSPEC_HIDDEN
static HRESULT maybe_to_primitive(script_ctx_t *ctx, jsval_t val, jsval_t *r)
static HRESULT stringify(stringify_ctx_t *ctx, jsval_t val)
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_object_instance(jsval_t v)
static BOOL is_string(parse_buffer *buf)
◆ maybe_to_primitive()
Definition at line 411 of file json.c.
412{
415
418
426 }
427
435 }
436
441 }
442
445}
BOOL bool_obj_value(jsdisp_t *obj)
static HRESULT to_string(VARIANT *src, BSTR *dst)
jsdisp_t * iface_to_jsdisp(IDispatch *iface)
static void jsdisp_release(jsdisp_t *jsdisp)
HRESULT to_number(script_ctx_t *, jsval_t, double *) DECLSPEC_HIDDEN
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 IDispatch * get_object(jsval_t v)
static jsval_t jsval_number(double n)
Referenced by JSON_stringify(), and stringify().
◆ parse_json_string()
Definition at line 70 of file json.c.
71{
75
76 while(*
ctx->ptr && *
ctx->ptr !=
'"') {
77 if(*
ctx->ptr++ ==
'\\')
79 }
81 FIXME(
"unterminated string\n");
83 }
84
91
93 FIXME(
"unescape failed\n");
96 }
97
102}
BOOL unescape(WCHAR *str, size_t *len)
Referenced by parse_json_value().
◆ parse_json_value()
Definition at line 105 of file json.c.
106{
108
110
111
112 case 'n':
114 break;
117
118
119 case 't':
121 break;
124 case 'f':
126 break;
129
130
131 case '{': {
135
139
145 }
146
147 while(1) {
149 break;
152 break;
153
155 FIXME(
"missing ':'\n");
157 break;
158 }
159
165 }
168 break;
169
174 }
175
176 if(*
ctx->ptr++ !=
',') {
177 FIXME(
"expected ','\n");
178 break;
179 }
181 }
182
184 break;
185 }
186
187
188 case '"': {
191
195
196
201
204 }
205
206
207 case '[': {
211
215
221 }
222
223 while(1) {
226 break;
227
231 break;
232
237 }
238
239 if(*
ctx->ptr !=
',') {
240 FIXME(
"expected ','\n");
241 break;
242 }
243
246 }
247
249 break;
250 }
251
252
253 default: {
256
257 if(*
ctx->ptr ==
'-') {
261 }
262
264 break;
265
268 break;
269
272 }
273 }
274
277}
HRESULT create_array(script_ctx_t *ctx, DWORD length, jsdisp_t **ret)
HRESULT jsdisp_propput_name(jsdisp_t *obj, const WCHAR *name, jsval_t val)
HRESULT jsdisp_propput_idx(jsdisp_t *obj, DWORD idx, jsval_t val)
HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret)
HRESULT create_object(script_ctx_t *, jsdisp_t *, jsdisp_t **) DECLSPEC_HIDDEN
static BOOL is_keyword(json_parse_ctx_t *ctx, const WCHAR *keyword)
static const WCHAR falseW[]
static const WCHAR trueW[]
static const WCHAR nullW[]
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 661 of file json.c.
662{
665
669
673
677 FIXME(
"Use toJSON.\n");
678 }
679
680
681
685
690 break;
694 break;
700 else
702 break;
703 }
709
710
713 break;
714
719 }else {
722 }
723 break;
724 }
727
731 break;
732 }
733
736 else
738
740 break;
741 }
744 break;
748 break;
749 }
750
753}
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 double_to_string(double, jsstr_t **) DECLSPEC_HIDDEN
BOOL is_finite(double) DECLSPEC_HIDDEN
static const WCHAR toJSONW[]
static HRESULT stringify_array(stringify_ctx_t *ctx, jsdisp_t *obj)
static HRESULT stringify_object(stringify_ctx_t *ctx, jsdisp_t *obj)
static BOOL is_callable(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 VARIANTARG static DISPID
Referenced by JSON_stringify(), stringify_array(), and stringify_object().
◆ stringify_array()
Definition at line 506 of file json.c.
507{
511
513 FIXME(
"Found a cycle\n");
515 }
516
519
522
524
528
532
533 for(
j=0;
j <
ctx->stack_top;
j++) {
536 }
537 }
538
549 }else {
551 }
552 }
553
556
559}
unsigned array_get_length(jsdisp_t *array)
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
HRESULT jsdisp_get_idx(jsdisp_t *obj, DWORD idx, jsval_t *r)
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)
#define DISP_E_UNKNOWNNAME
Referenced by stringify().
◆ stringify_object()
Definition at line 562 of file json.c.
563{
564 DISPID dispid = DISPID_STARTENUM;
566 unsigned prop_cnt = 0,
i;
567 size_t stepback;
570
572 FIXME(
"Found a cycle\n");
574 }
575
578
581
582 while((
hres = IDispatchEx_GetNextDispID(&
obj->IDispatchEx_iface, fdexEnumDefault, dispid, &dispid)) ==
S_OK) {
587
589 continue;
590
591 stepback =
ctx->buf_len;
592
595 break;
596 }
597
601 break;
602 }
603
604 for(
i=0;
i <
ctx->stack_top;
i++) {
607 break;
608 }
609 }
610 }
611
612 hres = IDispatchEx_GetMemberName(&
obj->IDispatchEx_iface, dispid, &prop_name);
614 break;
615
619 break;
620
623 break;
624 }
625
628 break;
629
631 ctx->buf_len = stepback;
632 continue;
633 }
634
635 prop_cnt++;
636 }
640
641 if(prop_cnt && *
ctx->gap) {
644
645 for(
i=1;
i <
ctx->stack_top;
i++) {
648 break;
649 }
650 }
651 }
652
655
658}
HRESULT jsdisp_propget(jsdisp_t *jsdisp, DISPID id, jsval_t *val)
static BOOL is_undefined(jsval_t v)
UINT WINAPI SysStringLen(BSTR str)
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Referenced by stringify().
◆ stringify_pop_obj()
◆ stringify_push_obj()
◆ WINE_DEFAULT_DEBUG_CHANNEL()
WINE_DEFAULT_DEBUG_CHANNEL |
( |
jscript |
| ) |
|
◆ falseW
◆ JSON_info
Initial value:= {
}
static const builtin_prop_t JSON_props[]
Definition at line 828 of file json.c.
Referenced by create_json().
◆ JSON_props
Initial value:= {
}
static const WCHAR stringifyW[]
static const WCHAR parseW[]
static HRESULT JSON_parse(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
static HRESULT JSON_stringify(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition at line 823 of file json.c.
◆ nullW
◆ parseW
◆ stringifyW
◆ toJSONW
◆ trueW