ReactOS  0.4.14-dev-77-gd9e7c48
jsutils.c File Reference
#include "config.h"
#include "wine/port.h"
#include <math.h>
#include <assert.h>
#include "jscript.h"
#include "engine.h"
#include "wine/debug.h"
Include dependency graph for jsutils.c:

Go to the source code of this file.

Macros

#define MIN_BLOCK_SIZE   128
 
#define ARENA_FREE_FILLER   0xaa
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (jscript)
 
 WINE_DECLARE_DEBUG_CHANNEL (heap)
 
const chardebugstr_jsval (const jsval_t v)
 
BOOL is_finite (double n)
 
static DWORD block_size (DWORD block)
 
void heap_pool_init (heap_pool_t *heap)
 
voidheap_pool_alloc (heap_pool_t *heap, DWORD size)
 
voidheap_pool_grow (heap_pool_t *heap, void *mem, DWORD size, DWORD inc)
 
void heap_pool_clear (heap_pool_t *heap)
 
void heap_pool_free (heap_pool_t *heap)
 
heap_pool_theap_pool_mark (heap_pool_t *heap)
 
void jsval_release (jsval_t val)
 
static HRESULT jsval_variant (jsval_t *val, VARIANT *var)
 
HRESULT jsval_copy (jsval_t v, jsval_t *r)
 
HRESULT variant_to_jsval (VARIANT *var, jsval_t *r)
 
HRESULT jsval_to_variant (jsval_t val, VARIANT *retv)
 
HRESULT to_primitive (script_ctx_t *ctx, jsval_t val, jsval_t *ret, hint_t hint)
 
HRESULT to_boolean (jsval_t val, BOOL *ret)
 
static int hex_to_int (WCHAR c)
 
static HRESULT str_to_number (jsstr_t *str, double *ret)
 
HRESULT to_number (script_ctx_t *ctx, jsval_t val, double *ret)
 
HRESULT to_integer (script_ctx_t *ctx, jsval_t v, double *ret)
 
HRESULT to_int32 (script_ctx_t *ctx, jsval_t v, INT *ret)
 
HRESULT to_uint32 (script_ctx_t *ctx, jsval_t val, UINT32 *ret)
 
static jsstr_tint_to_string (int i)
 
HRESULT double_to_string (double n, jsstr_t **str)
 
HRESULT to_string (script_ctx_t *ctx, jsval_t val, jsstr_t **str)
 
HRESULT to_flat_string (script_ctx_t *ctx, jsval_t val, jsstr_t **str, const WCHAR **ret_str)
 
HRESULT to_object (script_ctx_t *ctx, jsval_t val, IDispatch **disp)
 
HRESULT variant_change_type (script_ctx_t *ctx, VARIANT *dst, VARIANT *src, VARTYPE vt)
 
static JSCallerimpl_from_IServiceProvider (IServiceProvider *iface)
 
static HRESULT WINAPI JSCaller_QueryInterface (IServiceProvider *iface, REFIID riid, void **ppv)
 
static ULONG WINAPI JSCaller_AddRef (IServiceProvider *iface)
 
static ULONG WINAPI JSCaller_Release (IServiceProvider *iface)
 
static HRESULT WINAPI JSCaller_QueryService (IServiceProvider *iface, REFGUID guidService, REFIID riid, void **ppv)
 
HRESULT create_jscaller (script_ctx_t *ctx)
 

Variables

static const IServiceProviderVtbl ServiceProviderVtbl
 

Macro Definition Documentation

◆ ARENA_FREE_FILLER

#define ARENA_FREE_FILLER   0xaa

Definition at line 62 of file jsutils.c.

◆ MIN_BLOCK_SIZE

#define MIN_BLOCK_SIZE   128

Definition at line 61 of file jsutils.c.

Function Documentation

◆ block_size()

◆ create_jscaller()

HRESULT create_jscaller ( script_ctx_t ctx)

Definition at line 1031 of file jsutils.c.

1032 {
1033  JSCaller *ret;
1034 
1035  ret = heap_alloc(sizeof(*ret));
1036  if(!ret)
1037  return E_OUTOFMEMORY;
1038 
1039  ret->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
1040  ret->ref = 1;
1041  ret->ctx = ctx;
1042 
1043  ctx->jscaller = ret;
1044  return S_OK;
1045 }
static const IServiceProviderVtbl ServiceProviderVtbl
Definition: jsutils.c:1024
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
JSCaller * jscaller
Definition: jscript.h:420
int ret
#define S_OK
Definition: intsafe.h:59

Referenced by JScriptParse_InitNew().

◆ debugstr_jsval()

const char* debugstr_jsval ( const jsval_t  v)

Definition at line 33 of file jsutils.c.

34 {
35  switch(jsval_type(v)) {
36  case JSV_UNDEFINED:
37  return "undefined";
38  case JSV_NULL:
39  return "null";
40  case JSV_OBJECT:
41  return wine_dbg_sprintf("obj(%p)", get_object(v));
42  case JSV_STRING:
43  return wine_dbg_sprintf("str(%s)", debugstr_jsstr(get_string(v)));
44  case JSV_NUMBER:
45  return wine_dbg_sprintf("%lf", get_number(v));
46  case JSV_BOOL:
47  return get_bool(v) ? "true" : "false";
48  case JSV_VARIANT:
50  }
51 
52  assert(0);
53  return NULL;
54 }
static IDispatch * get_object(jsval_t v)
Definition: jsval.h:219
#define assert(x)
Definition: debug.h:53
const char * wine_dbg_sprintf(const char *format,...)
Definition: compat.c:271
static jsstr_t * get_string(jsval_t v)
Definition: jsval.h:229
static BOOL get_bool(D3DXPARAMETER_TYPE type, const void *data)
smooth NULL
Definition: ftsmooth.c:416
const char * debugstr_jsstr(jsstr_t *str)
Definition: jsstr.c:37
Definition: jsval.h:46
static VARIANT * get_variant(jsval_t v)
Definition: jsval.h:234
static double get_number(jsval_t v)
Definition: jsval.h:224
static jsval_type_t jsval_type(jsval_t v)
Definition: jsval.h:210
static const char * debugstr_variant(const VARIANT *var)
Definition: container.c:46
const GLdouble * v
Definition: gl.h:2040
Definition: jsval.h:50

Referenced by Arguments_idx_put(), bind_event_target(), builtin_set_const(), create_regexp_var(), exprval_call(), interp_add(), interp_carray_set(), interp_eq(), interp_eq2(), interp_gt(), interp_gteq(), interp_lt(), interp_lteq(), interp_neq(), invoke_prop_func(), jsdisp_define_property(), JSGlobal_eval(), JSON_stringify(), print_backtrace(), prop_get(), prop_put(), to_string(), and unwind_exception().

◆ double_to_string()

HRESULT double_to_string ( double  n,
jsstr_t **  str 
)

Definition at line 719 of file jsutils.c.

720 {
721  static const WCHAR InfinityW[] = {'-','I','n','f','i','n','i','t','y',0};
722 
723  if(isnan(n)) {
724  *str = jsstr_nan();
725  }else if(isinf(n)) {
726  *str = jsstr_alloc(n<0 ? InfinityW : InfinityW+1);
727  }else if(is_int32(n)) {
728  *str = int_to_string(n);
729  }else {
730  VARIANT strv, v;
731  HRESULT hres;
732 
733  /* FIXME: Don't use VariantChangeTypeEx */
734  V_VT(&v) = VT_R8;
735  V_R8(&v) = n;
736  V_VT(&strv) = VT_EMPTY;
738  if(FAILED(hres))
739  return hres;
740 
741  *str = jsstr_alloc(V_BSTR(&strv));
742  SysFreeString(V_BSTR(&strv));
743  }
744 
745  return *str ? S_OK : E_OUTOFMEMORY;
746 }
static jsstr_t * jsstr_alloc(const WCHAR *str)
Definition: jsstr.h:103
jsstr_t * jsstr_nan(void)
Definition: jsstr.c:283
#define MAKELCID(lgid, srtid)
#define V_R8(A)
Definition: oleauto.h:262
GLdouble n
Definition: glext.h:7729
#define SUBLANG_ENGLISH_US
Definition: nls.h:222
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
const WCHAR * str
HRESULT hres
Definition: protocol.c:465
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define SORT_DEFAULT
LONG HRESULT
Definition: typedefs.h:77
int isinf(double x)
#define LANG_ENGLISH
Definition: nls.h:52
#define V_VT(A)
Definition: oleauto.h:211
#define V_BSTR(A)
Definition: oleauto.h:226
int isnan(double x)
#define S_OK
Definition: intsafe.h:59
const GLdouble * v
Definition: gl.h:2040
static jsstr_t * int_to_string(int i)
Definition: jsutils.c:689
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:274
static const WCHAR InfinityW[]
Definition: global.c:33
#define MAKELANGID(p, s)
Definition: nls.h:15
static BOOL is_int32(double d)
Definition: jscript.h:518
Definition: compat.h:1941
HRESULT WINAPI VariantChangeTypeEx(VARIANTARG *pvargDest, VARIANTARG *pvargSrc, LCID lcid, USHORT wFlags, VARTYPE vt)
Definition: variant.c:991

Referenced by literal_as_bstr(), stringify(), and to_string().

◆ heap_pool_alloc()

void* heap_pool_alloc ( heap_pool_t heap,
DWORD  size 
)

Definition at line 75 of file jsutils.c.

76 {
77  struct list *list;
78  void *tmp;
79 
80  if(!heap->block_cnt) {
81  if(!heap->blocks) {
82  heap->blocks = heap_alloc(sizeof(void*));
83  if(!heap->blocks)
84  return NULL;
85  }
86 
87  tmp = heap_alloc(block_size(0));
88  if(!tmp)
89  return NULL;
90 
91  heap->blocks[0] = tmp;
92  heap->block_cnt = 1;
93  }
94 
95  if(heap->offset + size <= block_size(heap->last_block)) {
96  tmp = ((BYTE*)heap->blocks[heap->last_block])+heap->offset;
97  heap->offset += size;
98  return tmp;
99  }
100 
101  if(size <= block_size(heap->last_block+1)) {
102  if(heap->last_block+1 == heap->block_cnt) {
103  tmp = heap_realloc(heap->blocks, (heap->block_cnt+1)*sizeof(void*));
104  if(!tmp)
105  return NULL;
106 
107  heap->blocks = tmp;
108  heap->blocks[heap->block_cnt] = heap_alloc(block_size(heap->block_cnt));
109  if(!heap->blocks[heap->block_cnt])
110  return NULL;
111 
112  heap->block_cnt++;
113  }
114 
115  heap->last_block++;
116  heap->offset = size;
117  return heap->blocks[heap->last_block];
118  }
119 
120  list = heap_alloc(size + sizeof(struct list));
121  if(!list)
122  return NULL;
123 
125  return list+1;
126 }
__WINE_SERVER_LIST_INLINE void list_add_head(struct list *list, struct list *elem)
Definition: list.h:96
static void * heap_realloc(void *mem, size_t len)
Definition: appwiz.h:70
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
static DWORD block_size(DWORD block)
Definition: jsutils.c:64
smooth NULL
Definition: ftsmooth.c:416
GLsizeiptr size
Definition: glext.h:5919
DWORD offset
Definition: jscript.h:61
struct list custom_blocks
Definition: jscript.h:63
unsigned char BYTE
Definition: mem.h:68
Definition: _list.h:228
void ** blocks
Definition: jscript.h:58
#define list
Definition: rosglue.h:35
DWORD last_block
Definition: jscript.h:60
DWORD block_cnt
Definition: jscript.h:59

Referenced by add_dynamic_var(), alloc_local(), alloc_match_state(), compiler_alloc(), compiler_alloc_zero(), heap_pool_grow(), InitMatch(), NewRENode(), parser_alloc(), and parser_alloc_tmp().

◆ heap_pool_clear()

void heap_pool_clear ( heap_pool_t heap)

Definition at line 144 of file jsutils.c.

145 {
146  struct list *tmp;
147 
148  if(!heap)
149  return;
150 
151  while((tmp = list_head(&heap->custom_blocks))) {
152  list_remove(tmp);
153  heap_free(tmp);
154  }
155 
156  if(WARN_ON(heap)) {
157  DWORD i;
158 
159  for(i=0; i < heap->block_cnt; i++)
161  }
162 
163  heap->last_block = heap->offset = 0;
164  heap->mark = FALSE;
165 }
#define ARENA_FREE_FILLER
Definition: jsutils.c:62
static DWORD block_size(DWORD block)
Definition: jsutils.c:64
__WINE_SERVER_LIST_INLINE struct list * list_head(const struct list *list)
Definition: list.h:131
BOOL mark
Definition: jscript.h:62
#define WARN_ON(c)
Definition: module.h:255
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
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD offset
Definition: jscript.h:61
struct list custom_blocks
Definition: jscript.h:63
Definition: _list.h:228
void ** blocks
Definition: jscript.h:58
DWORD last_block
Definition: jscript.h:60
#define memset(x, y, z)
Definition: compat.h:39
DWORD block_cnt
Definition: jscript.h:59
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by heap_pool_free().

◆ heap_pool_free()

void heap_pool_free ( heap_pool_t heap)

Definition at line 167 of file jsutils.c.

168 {
169  DWORD i;
170 
171  heap_pool_clear(heap);
172 
173  for(i=0; i < heap->block_cnt; i++)
174  heap_free(heap->blocks[i]);
175  heap_free(heap->blocks);
176 
177  heap_pool_init(heap);
178 }
void heap_pool_clear(heap_pool_t *heap)
Definition: jsutils.c:144
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
unsigned long DWORD
Definition: ntddk_ex.h:95
void ** blocks
Definition: jscript.h:58
void heap_pool_init(heap_pool_t *heap)
Definition: jsutils.c:69
DWORD block_cnt
Definition: jscript.h:59
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

◆ heap_pool_grow()

void* heap_pool_grow ( heap_pool_t heap,
void mem,
DWORD  size,
DWORD  inc 
)

Definition at line 128 of file jsutils.c.

129 {
130  void *ret;
131 
132  if(mem == (BYTE*)heap->blocks[heap->last_block] + heap->offset-size
133  && heap->offset+inc < block_size(heap->last_block)) {
134  heap->offset += inc;
135  return mem;
136  }
137 
138  ret = heap_pool_alloc(heap, size+inc);
139  if(ret) /* FIXME: avoid copying for custom blocks */
140  memcpy(ret, mem, size);
141  return ret;
142 }
static DWORD block_size(DWORD block)
Definition: jsutils.c:64
void * heap_pool_alloc(heap_pool_t *heap, DWORD size)
Definition: jsutils.c:75
GLsizeiptr size
Definition: glext.h:5919
int ret
DWORD offset
Definition: jscript.h:61
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
void ** blocks
Definition: jscript.h:58
DWORD last_block
Definition: jscript.h:60
Definition: mem.c:156

◆ heap_pool_init()

void heap_pool_init ( heap_pool_t heap)

Definition at line 69 of file jsutils.c.

70 {
71  memset(heap, 0, sizeof(*heap));
72  list_init(&heap->custom_blocks);
73 }
struct list custom_blocks
Definition: jscript.h:63
__WINE_SERVER_LIST_INLINE void list_init(struct list *list)
Definition: list.h:149
#define memset(x, y, z)
Definition: compat.h:39

Referenced by heap_pool_free().

◆ heap_pool_mark()

heap_pool_t* heap_pool_mark ( heap_pool_t heap)

Definition at line 180 of file jsutils.c.

181 {
182  if(heap->mark)
183  return NULL;
184 
185  heap->mark = TRUE;
186  return heap;
187 }
#define TRUE
Definition: types.h:120
BOOL mark
Definition: jscript.h:62
smooth NULL
Definition: ftsmooth.c:416

◆ hex_to_int()

static int hex_to_int ( WCHAR  c)
static

Definition at line 492 of file jsutils.c.

493 {
494  if('0' <= c && c <= '9')
495  return c-'0';
496 
497  if('a' <= c && c <= 'f')
498  return c-'a'+10;
499 
500  if('A' <= c && c <= 'F')
501  return c-'A'+10;
502 
503  return -1;
504 }
const GLubyte * c
Definition: glext.h:8905

Referenced by str_to_number().

◆ impl_from_IServiceProvider()

static JSCaller* impl_from_IServiceProvider ( IServiceProvider iface)
inlinestatic

Definition at line 958 of file jsutils.c.

959 {
960  return CONTAINING_RECORD(iface, JSCaller, IServiceProvider_iface);
961 }
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560

Referenced by JSCaller_AddRef(), JSCaller_QueryInterface(), JSCaller_QueryService(), and JSCaller_Release().

◆ int_to_string()

static jsstr_t* int_to_string ( int  i)
static

Definition at line 689 of file jsutils.c.

690 {
691  WCHAR buf[12], *p;
692  BOOL neg = FALSE;
693 
694  if(!i) {
695  static const WCHAR zeroW[] = {'0',0};
696  return jsstr_alloc(zeroW);
697  }
698 
699  if(i < 0) {
700  neg = TRUE;
701  i = -i;
702  }
703 
704  p = buf + ARRAY_SIZE(buf)-1;
705  *p-- = 0;
706  while(i) {
707  *p-- = i%10 + '0';
708  i /= 10;
709  }
710 
711  if(neg)
712  *p = '-';
713  else
714  p++;
715 
716  return jsstr_alloc(p);
717 }
static jsstr_t * jsstr_alloc(const WCHAR *str)
Definition: jsstr.h:103
#define TRUE
Definition: types.h:120
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
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
unsigned int BOOL
Definition: ntddk_ex.h:94
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define ARRAY_SIZE(a)
Definition: main.h:24
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by double_to_string().

◆ is_finite()

BOOL is_finite ( double  n)

Definition at line 56 of file jsutils.c.

57 {
58  return !isnan(n) && !isinf(n);
59 }
GLdouble n
Definition: glext.h:7729
int isinf(double x)
int isnan(double x)

Referenced by JSGlobal_isFinite(), Number_toExponential(), Number_toFixed(), Number_toPrecision(), Number_toString(), stringify(), and to_int32().

◆ JSCaller_AddRef()

static ULONG WINAPI JSCaller_AddRef ( IServiceProvider iface)
static

Definition at line 983 of file jsutils.c.

984 {
987 
988  TRACE("(%p) ref=%d\n", This, ref);
989 
990  return ref;
991 }
Definition: send.c:47
long LONG
Definition: pedump.c:60
GLenum GLint ref
Definition: glext.h:6028
#define TRACE(s)
Definition: solgame.cpp:4
#define InterlockedIncrement
Definition: armddk.h:53
static JSCaller * impl_from_IServiceProvider(IServiceProvider *iface)
Definition: jsutils.c:958

◆ JSCaller_QueryInterface()

static HRESULT WINAPI JSCaller_QueryInterface ( IServiceProvider iface,
REFIID  riid,
void **  ppv 
)
static

Definition at line 963 of file jsutils.c.

964 {
966 
967  if(IsEqualGUID(&IID_IUnknown, riid)) {
968  TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
969  *ppv = &This->IServiceProvider_iface;
970  }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
971  TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
972  *ppv = &This->IServiceProvider_iface;
973  }else {
974  WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
975  *ppv = NULL;
976  return E_NOINTERFACE;
977  }
978 
979  IUnknown_AddRef((IUnknown*)*ppv);
980  return S_OK;
981 }
#define E_NOINTERFACE
Definition: winerror.h:2364
REFIID riid
Definition: precomp.h:44
#define WARN(fmt,...)
Definition: debug.h:111
REFIID LPVOID * ppv
Definition: atlbase.h:39
smooth NULL
Definition: ftsmooth.c:416
#define debugstr_guid
Definition: kernel32.h:35
#define TRACE(s)
Definition: solgame.cpp:4
const GUID IID_IUnknown
#define S_OK
Definition: intsafe.h:59
static JSCaller * impl_from_IServiceProvider(IServiceProvider *iface)
Definition: jsutils.c:958
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4021

◆ JSCaller_QueryService()

static HRESULT WINAPI JSCaller_QueryService ( IServiceProvider iface,
REFGUID  guidService,
REFIID  riid,
void **  ppv 
)
static

Definition at line 1008 of file jsutils.c.

1010 {
1012 
1013  if(IsEqualGUID(guidService, &SID_VariantConversion) && This->ctx && This->ctx->active_script) {
1014  TRACE("(%p)->(SID_VariantConversion)\n", This);
1015  return IActiveScript_QueryInterface(This->ctx->active_script, riid, ppv);
1016  }
1017 
1018  FIXME("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
1019 
1020  *ppv = NULL;
1021  return E_NOINTERFACE;
1022 }
#define E_NOINTERFACE
Definition: winerror.h:2364
REFIID riid
Definition: precomp.h:44
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:416
#define debugstr_guid
Definition: kernel32.h:35
#define TRACE(s)
Definition: solgame.cpp:4
static JSCaller * impl_from_IServiceProvider(IServiceProvider *iface)
Definition: jsutils.c:958
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4021

◆ JSCaller_Release()

static ULONG WINAPI JSCaller_Release ( IServiceProvider iface)
static

Definition at line 993 of file jsutils.c.

994 {
997 
998  TRACE("(%p) ref=%d\n", This, ref);
999 
1000  if(!ref) {
1001  assert(!This->ctx);
1002  heap_free(This);
1003  }
1004 
1005  return ref;
1006 }
#define assert(x)
Definition: debug.h:53
Definition: send.c:47
long LONG
Definition: pedump.c:60
GLenum GLint ref
Definition: glext.h:6028
#define TRACE(s)
Definition: solgame.cpp:4
#define InterlockedIncrement
Definition: armddk.h:53
static JSCaller * impl_from_IServiceProvider(IServiceProvider *iface)
Definition: jsutils.c:958
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

◆ jsval_copy()

HRESULT jsval_copy ( jsval_t  v,
jsval_t r 
)

Definition at line 229 of file jsutils.c.

230 {
231  switch(jsval_type(v)) {
232  case JSV_UNDEFINED:
233  case JSV_NULL:
234  case JSV_NUMBER:
235  case JSV_BOOL:
236  *r = v;
237  return S_OK;
238  case JSV_OBJECT:
239  if(get_object(v))
240  IDispatch_AddRef(get_object(v));
241  *r = v;
242  return S_OK;
243  case JSV_STRING: {
245  *r = v;
246  return S_OK;
247  }
248  case JSV_VARIANT:
249  return jsval_variant(r, get_variant(v));
250  }
251 
252  assert(0);
253  return E_FAIL;
254 }
static IDispatch * get_object(jsval_t v)
Definition: jsval.h:219
static jsstr_t * jsstr_addref(jsstr_t *str)
Definition: jsstr.h:116
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define assert(x)
Definition: debug.h:53
#define E_FAIL
Definition: ddrawi.h:102
static jsstr_t * get_string(jsval_t v)
Definition: jsval.h:229
Definition: jsval.h:46
static VARIANT * get_variant(jsval_t v)
Definition: jsval.h:234
static HRESULT jsval_variant(jsval_t *val, VARIANT *var)
Definition: jsutils.c:208
static jsval_type_t jsval_type(jsval_t v)
Definition: jsval.h:210
#define S_OK
Definition: intsafe.h:59
const GLdouble * v
Definition: gl.h:2040
Definition: jsval.h:50

Referenced by Arguments_idx_get(), Arguments_idx_put(), detach_arguments_object(), Enumerator_item(), exprval_propget(), exprval_propput(), interp_local(), jsdisp_define_property(), JSGlobal_eval(), maybe_to_primitive(), prop_get(), prop_put(), RegExp_get_lastIndex(), RegExp_set_lastIndex(), setup_scope(), to_primitive(), and VBArrayConstr_value().

◆ jsval_release()

void jsval_release ( jsval_t  val)

Definition at line 189 of file jsutils.c.

190 {
191  switch(jsval_type(val)) {
192  case JSV_OBJECT:
193  if(get_object(val))
194  IDispatch_Release(get_object(val));
195  break;
196  case JSV_STRING:
198  break;
199  case JSV_VARIANT:
202  break;
203  default:
204  break;
205  }
206 }
static IDispatch * get_object(jsval_t v)
Definition: jsval.h:219
static void jsstr_release(jsstr_t *str)
Definition: jsstr.h:110
static jsstr_t * get_string(jsval_t v)
Definition: jsval.h:229
GLuint GLfloat * val
Definition: glext.h:7180
static VARIANT * get_variant(jsval_t v)
Definition: jsval.h:234
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:651
static jsval_type_t jsval_type(jsval_t v)
Definition: jsval.h:210
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by add_eval(), Arguments_destructor(), Arguments_idx_put(), Array_forEach(), Array_indexOf(), array_join(), Array_pop(), Array_reverse(), Array_shift(), Array_slice(), Array_sort(), Array_splice(), array_to_args(), Array_unshift(), bind_event_target(), clear_acc(), clear_ei(), concat_array(), convert_params(), DateConstr_value(), delete_prop(), DispatchEx_InvokeEx(), enter_bytecode(), Enumerator_destructor(), enumvar_get_next_item(), equal_values(), Error_toString(), exprval_propput(), exprval_release(), Function_apply(), get_length(), init_dispex_from_constr(), interp_add(), interp_array(), interp_assign(), interp_bneg(), interp_carray_set(), interp_case(), interp_delete(), interp_enter_catch(), interp_eq(), interp_eq2(), interp_gt(), interp_gteq(), interp_in(), interp_instanceof(), interp_jmp_z(), interp_lt(), interp_lteq(), interp_memberid(), interp_neg(), interp_neq(), interp_neq2(), interp_obj_prop(), interp_postinc(), interp_preinc(), interp_push_scope(), interp_ret(), interp_setret(), interp_throw(), interp_tonum(), interp_typeof(), interp_typeofid(), interp_typeofident(), JScriptParse_ParseScriptText(), jsdisp_define_property(), jsdisp_free(), JSON_parse(), JSON_stringify(), less_eval(), parse_json_value(), pop_call_frame(), prop_put(), RegExp_destructor(), RegExp_set_lastIndex(), release_property_descriptor(), rep_call(), script_release(), set_last_index(), setup_scope(), sort_cmp(), stack_pop_number(), stack_pop_object(), stack_popn(), stack_push(), stringify(), stringify_object(), throw_error(), to_number(), to_property_descriptor(), to_string(), unwind_exception(), variant_change_type(), and VBArray_toArray().

◆ jsval_to_variant()

HRESULT jsval_to_variant ( jsval_t  val,
VARIANT retv 
)

Definition at line 339 of file jsutils.c.

340 {
341  switch(jsval_type(val)) {
342  case JSV_UNDEFINED:
343  V_VT(retv) = VT_EMPTY;
344  return S_OK;
345  case JSV_NULL:
346  V_VT(retv) = VT_NULL;
347  return S_OK;
348  case JSV_OBJECT:
349  V_VT(retv) = VT_DISPATCH;
350  if(get_object(val))
351  IDispatch_AddRef(get_object(val));
352  V_DISPATCH(retv) = get_object(val);
353  return S_OK;
354  case JSV_STRING: {
356 
357  V_VT(retv) = VT_BSTR;
358  if(is_null_bstr(str)) {
359  V_BSTR(retv) = NULL;
360  }else {
362  if(V_BSTR(retv))
363  jsstr_flush(str, V_BSTR(retv));
364  else
365  return E_OUTOFMEMORY;
366  }
367  return S_OK;
368  }
369  case JSV_NUMBER: {
370  double n = get_number(val);
371 
372  if(is_int32(n)) {
373  V_VT(retv) = VT_I4;
374  V_I4(retv) = n;
375  }else {
376  V_VT(retv) = VT_R8;
377  V_R8(retv) = n;
378  }
379 
380  return S_OK;
381  }
382  case JSV_BOOL:
383  V_VT(retv) = VT_BOOL;
384  V_BOOL(retv) = get_bool(val) ? VARIANT_TRUE : VARIANT_FALSE;
385  return S_OK;
386  case JSV_VARIANT:
387  V_VT(retv) = VT_EMPTY;
388  return VariantCopy(retv, get_variant(val));
389  }
390 
391  assert(0);
392  return E_FAIL;
393 }
Definition: compat.h:1939
BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
Definition: oleaut.c:342
Definition: jsstr.h:39
static IDispatch * get_object(jsval_t v)
Definition: jsval.h:219
#define V_R8(A)
Definition: oleauto.h:262
GLdouble n
Definition: glext.h:7729
static unsigned jsstr_flush(jsstr_t *str, WCHAR *buf)
Definition: jsstr.h:148
#define assert(x)
Definition: debug.h:53
static unsigned jsstr_length(jsstr_t *str)
Definition: jsstr.h:58
#define E_FAIL
Definition: ddrawi.h:102
#define V_I4(A)
Definition: oleauto.h:247
#define V_DISPATCH(A)
Definition: oleauto.h:239
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
static jsstr_t * get_string(jsval_t v)
Definition: jsval.h:229
static BOOL get_bool(D3DXPARAMETER_TYPE type, const void *data)
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
GLuint GLfloat * val
Definition: glext.h:7180
Definition: jsval.h:46
#define V_BOOL(A)
Definition: oleauto.h:224
static VARIANT * get_variant(jsval_t v)
Definition: jsval.h:234
static double get_number(jsval_t v)
Definition: jsval.h:224
static jsval_type_t jsval_type(jsval_t v)
Definition: jsval.h:210
#define V_VT(A)
Definition: oleauto.h:211
#define V_BSTR(A)
Definition: oleauto.h:226
#define S_OK
Definition: intsafe.h:59
BOOL is_null_bstr(jsstr_t *str)
Definition: jsstr.c:303
Definition: jsval.h:50
HRESULT WINAPI VariantCopy(VARIANTARG *pvargDest, VARIANTARG *pvargSrc)
Definition: variant.c:751
static BOOL is_int32(double d)
Definition: jscript.h:518
Definition: compat.h:1941

Referenced by disp_call(), disp_call_value(), disp_propput(), DispatchEx_InvokeEx(), and JScriptParse_ParseScriptText().

◆ jsval_variant()

static HRESULT jsval_variant ( jsval_t val,
VARIANT var 
)
static

Definition at line 208 of file jsutils.c.

209 {
210  VARIANT *v;
211  HRESULT hres;
212 
214  __JSVAL_VAR(*val) = v = heap_alloc(sizeof(VARIANT));
215  if(!v) {
216  *val = jsval_undefined();
217  return E_OUTOFMEMORY;
218  }
219 
220  V_VT(v) = VT_EMPTY;
221  hres = VariantCopy(v, var);
222  if(FAILED(hres)) {
223  *val = jsval_undefined();
224  heap_free(v);
225  }
226  return hres;
227 }
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
#define __JSVAL_VAR(x)
Definition: jsval.h:97
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
GLuint GLfloat * val
Definition: glext.h:7180
HRESULT hres
Definition: protocol.c:465
LONG HRESULT
Definition: typedefs.h:77
#define V_VT(A)
Definition: oleauto.h:211
static jsval_t jsval_undefined(void)
Definition: jsval.h:137
const GLdouble * v
Definition: gl.h:2040
HRESULT WINAPI VariantCopy(VARIANTARG *pvargDest, VARIANTARG *pvargSrc)
Definition: variant.c:751
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
#define __JSVAL_TYPE(x)
Definition: jsval.h:93

Referenced by jsval_copy(), and variant_to_jsval().

◆ str_to_number()

static HRESULT str_to_number ( jsstr_t str,
double ret 
)
static

Definition at line 507 of file jsutils.c.

508 {
509  const WCHAR *ptr;
510  BOOL neg = FALSE;
511  DOUBLE d = 0.0;
512 
513  static const WCHAR infinityW[] = {'I','n','f','i','n','i','t','y'};
514 
515  ptr = jsstr_flatten(str);
516  if(!ptr)
517  return E_OUTOFMEMORY;
518 
519  while(isspaceW(*ptr))
520  ptr++;
521 
522  if(*ptr == '-') {
523  neg = TRUE;
524  ptr++;
525  }else if(*ptr == '+') {
526  ptr++;
527  }
528 
529  if(!strncmpW(ptr, infinityW, ARRAY_SIZE(infinityW))) {
530  ptr += ARRAY_SIZE(infinityW);
531  while(*ptr && isspaceW(*ptr))
532  ptr++;
533 
534  if(*ptr)
535  *ret = NAN;
536  else
537  *ret = neg ? -INFINITY : INFINITY;
538  return S_OK;
539  }
540 
541  if(*ptr == '0' && ptr[1] == 'x') {
542  DWORD l = 0;
543 
544  ptr += 2;
545  while((l = hex_to_int(*ptr)) != -1) {
546  d = d*16 + l;
547  ptr++;
548  }
549 
550  *ret = d;
551  return S_OK;
552  }
553 
554  while(isdigitW(*ptr))
555  d = d*10 + (*ptr++ - '0');
556 
557  if(*ptr == 'e' || *ptr == 'E') {
558  BOOL eneg = FALSE;
559  LONG l = 0;
560 
561  ptr++;
562  if(*ptr == '-') {
563  ptr++;
564  eneg = TRUE;
565  }else if(*ptr == '+') {
566  ptr++;
567  }
568 
569  while(isdigitW(*ptr))
570  l = l*10 + (*ptr++ - '0');
571  if(eneg)
572  l = -l;
573 
574  d *= pow(10, l);
575  }else if(*ptr == '.') {
576  DOUBLE dec = 0.1;
577 
578  ptr++;
579  while(isdigitW(*ptr)) {
580  d += dec * (*ptr++ - '0');
581  dec *= 0.1;
582  }
583  }
584 
585  while(isspaceW(*ptr))
586  ptr++;
587 
588  if(*ptr) {
589  *ret = NAN;
590  return S_OK;
591  }
592 
593  if(neg)
594  d = -d;
595 
596  *ret = d;
597  return S_OK;
598 }
static const WCHAR * jsstr_flatten(jsstr_t *str)
Definition: jsstr.h:139
#define TRUE
Definition: types.h:120
WINE_UNICODE_INLINE int isspaceW(WCHAR wc)
Definition: unicode.h:165
ios_base &_STLP_CALL dec(ios_base &__s)
Definition: _ios_base.h:321
WINE_UNICODE_INLINE int strncmpW(const WCHAR *str1, const WCHAR *str2, int n)
Definition: unicode.h:235
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
float pow(float __x, int __y)
Definition: _cmath.h:458
static PVOID ptr
Definition: dispmode.c:27
const WCHAR * str
r l[0]
Definition: byte_order.h:167
static int hex_to_int(WCHAR c)
Definition: jsutils.c:492
#define d
Definition: ke_i.h:81
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define NAN
Definition: misc.c:46
int ret
#define S_OK
Definition: intsafe.h:59
#define ARRAY_SIZE(a)
Definition: main.h:24
WINE_UNICODE_INLINE int isdigitW(WCHAR wc)
Definition: unicode.h:170
double DOUBLE
Definition: typedefs.h:68
#define INFINITY
Definition: misc.c:36

Referenced by to_number().

◆ to_boolean()

HRESULT to_boolean ( jsval_t  val,
BOOL ret 
)

Definition at line 464 of file jsutils.c.

465 {
466  switch(jsval_type(val)) {
467  case JSV_UNDEFINED:
468  case JSV_NULL:
469  *ret = FALSE;
470  return S_OK;
471  case JSV_OBJECT:
472  *ret = get_object(val) != NULL;
473  return S_OK;
474  case JSV_STRING:
475  *ret = jsstr_length(get_string(val)) != 0;
476  return S_OK;
477  case JSV_NUMBER:
478  *ret = !isnan(get_number(val)) && get_number(val);
479  return S_OK;
480  case JSV_BOOL:
481  *ret = get_bool(val);
482  return S_OK;
483  case JSV_VARIANT:
484  FIXME("unimplemented for variant %s\n", debugstr_variant(get_variant(val)));
485  return E_NOTIMPL;
486  }
487 
488  assert(0);
489  return E_FAIL;
490 }
static IDispatch * get_object(jsval_t v)
Definition: jsval.h:219
#define assert(x)
Definition: debug.h:53
static unsigned jsstr_length(jsstr_t *str)
Definition: jsstr.h:58
#define E_FAIL
Definition: ddrawi.h:102
static jsstr_t * get_string(jsval_t v)
Definition: jsval.h:229
static BOOL get_bool(D3DXPARAMETER_TYPE type, const void *data)
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:416
GLuint GLfloat * val
Definition: glext.h:7180
Definition: jsval.h:46
static VARIANT * get_variant(jsval_t v)
Definition: jsval.h:234
static double get_number(jsval_t v)
Definition: jsval.h:224
int ret
static jsval_type_t jsval_type(jsval_t v)
Definition: jsval.h:210
int isnan(double x)
static const char * debugstr_variant(const VARIANT *var)
Definition: container.c:46
#define S_OK
Definition: intsafe.h:59
#define E_NOTIMPL
Definition: ddrawi.h:99
Definition: jsval.h:50

Referenced by BoolConstr_value(), interp_cnd_nz(), interp_cnd_z(), interp_jmp_z(), interp_neg(), to_property_descriptor(), and variant_change_type().

◆ to_flat_string()

HRESULT to_flat_string ( script_ctx_t ctx,
jsval_t  val,
jsstr_t **  str,
const WCHAR **  ret_str 
)

Definition at line 790 of file jsutils.c.

791 {
792  HRESULT hres;
793 
794  hres = to_string(ctx, val, str);
795  if(FAILED(hres))
796  return hres;
797 
798  *ret_str = jsstr_flatten(*str);
799  if(!*ret_str) {
800  jsstr_release(*str);
801  return E_OUTOFMEMORY;
802  }
803 
804  return S_OK;
805 }
static const WCHAR * jsstr_flatten(jsstr_t *str)
Definition: jsstr.h:139
static void jsstr_release(jsstr_t *str)
Definition: jsstr.h:110
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
HRESULT to_string(script_ctx_t *ctx, jsval_t val, jsstr_t **str)
Definition: jsutils.c:749
const WCHAR * str
GLuint GLfloat * val
Definition: glext.h:7180
HRESULT hres
Definition: protocol.c:465
LONG HRESULT
Definition: typedefs.h:77
#define S_OK
Definition: intsafe.h:59

Referenced by ActiveXObject_value(), Array_join(), interp_array(), interp_in(), interp_memberid(), JSGlobal_decodeURI(), JSGlobal_decodeURIComponent(), JSGlobal_encodeURI(), JSGlobal_encodeURIComponent(), JSGlobal_escape(), JSGlobal_parseFloat(), JSGlobal_parseInt(), JSGlobal_unescape(), JSON_parse(), Object_defineProperty(), Object_getOwnPropertyDescriptor(), Object_propertyIsEnumerable(), run_exec(), String_indexOf(), String_lastIndexOf(), String_replace(), String_split(), and String_trim().

◆ to_int32()

HRESULT to_int32 ( script_ctx_t ctx,
jsval_t  v,
INT ret 
)

Definition at line 657 of file jsutils.c.

658 {
659  double n;
660  HRESULT hres;
661 
662  const double p32 = (double)0xffffffff + 1;
663 
664  hres = to_number(ctx, v, &n);
665  if(FAILED(hres))
666  return hres;
667 
668  if(is_finite(n))
669  n = n > 0 ? fmod(n, p32) : -fmod(-n, p32);
670  else
671  n = 0;
672 
673  *ret = (UINT32)n;
674  return S_OK;
675 }
GLdouble n
Definition: glext.h:7729
unsigned int UINT32
static const char mbstate_t *static wchar_t const char mbstate_t *static const wchar_t int *static double
Definition: string.c:80
_Check_return_ double __cdecl fmod(_In_ double x, _In_ double y)
HRESULT hres
Definition: protocol.c:465
LONG HRESULT
Definition: typedefs.h:77
BOOL is_finite(double n)
Definition: jsutils.c:56
int ret
#define S_OK
Definition: intsafe.h:59
const GLdouble * v
Definition: gl.h:2040
HRESULT to_number(script_ctx_t *ctx, jsval_t val, double *ret)
Definition: jsutils.c:601

Referenced by interp_bneg(), JSGlobal_parseInt(), Number_toExponential(), Number_toFixed(), Number_toPrecision(), Number_toString(), stack_pop_int(), to_uint32(), variant_change_type(), VBArray_getItem(), VBArray_lbound(), and VBArray_ubound().

◆ to_integer()

HRESULT to_integer ( script_ctx_t ctx,
jsval_t  v,
double ret 
)

Definition at line 640 of file jsutils.c.

641 {
642  double n;
643  HRESULT hres;
644 
645  hres = to_number(ctx, v, &n);
646  if(FAILED(hres))
647  return hres;
648 
649  if(isnan(n))
650  *ret = 0;
651  else
652  *ret = n >= 0.0 ? floor(n) : -floor(-n);
653  return S_OK;
654 }
GLdouble n
Definition: glext.h:7729
HRESULT hres
Definition: protocol.c:465
LONG HRESULT
Definition: typedefs.h:77
int ret
int isnan(double x)
#define S_OK
Definition: intsafe.h:59
const GLdouble * v
Definition: gl.h:2040
HRESULT to_number(script_ctx_t *ctx, jsval_t val, double *ret)
Definition: jsutils.c:601
_Check_return_ _CRTIMP double __cdecl floor(_In_ double x)

Referenced by Array_indexOf(), Array_splice(), String_charAt(), String_charCodeAt(), String_indexOf(), String_lastIndexOf(), String_slice(), String_substr(), and String_substring().

◆ to_number()

HRESULT to_number ( script_ctx_t ctx,
jsval_t  val,
double ret 
)

Definition at line 601 of file jsutils.c.

602 {
603  switch(jsval_type(val)) {
604  case JSV_UNDEFINED:
605  *ret = NAN;
606  return S_OK;
607  case JSV_NULL:
608  *ret = 0;
609  return S_OK;
610  case JSV_NUMBER:
611  *ret = get_number(val);
612  return S_OK;
613  case JSV_STRING:
614  return str_to_number(get_string(val), ret);
615  case JSV_OBJECT: {
616  jsval_t prim;
617  HRESULT hres;
618 
619  hres = to_primitive(ctx, val, &prim, HINT_NUMBER);
620  if(FAILED(hres))
621  return hres;
622 
623  hres = to_number(ctx, prim, ret);
625  return hres;
626  }
627  case JSV_BOOL:
628  *ret = get_bool(val) ? 1 : 0;
629  return S_OK;
630  case JSV_VARIANT:
631  FIXME("unimplemented for variant %s\n", debugstr_variant(get_variant(val)));
632  return E_NOTIMPL;
633  };
634 
635  assert(0);
636  return E_FAIL;
637 }
Definition: jsval.h:54
void jsval_release(jsval_t val)
Definition: jsutils.c:189
static HRESULT str_to_number(jsstr_t *str, double *ret)
Definition: jsutils.c:507
#define assert(x)
Definition: debug.h:53
HRESULT to_primitive(script_ctx_t *ctx, jsval_t val, jsval_t *ret, hint_t hint)
Definition: jsutils.c:396
#define E_FAIL
Definition: ddrawi.h:102
static jsstr_t * get_string(jsval_t v)
Definition: jsval.h:229
static BOOL get_bool(D3DXPARAMETER_TYPE type, const void *data)
#define FIXME(fmt,...)
Definition: debug.h:110
GLuint GLfloat * val
Definition: glext.h:7180
Definition: jsval.h:46
HRESULT hres
Definition: protocol.c:465
LONG HRESULT
Definition: typedefs.h:77
#define NAN
Definition: misc.c:46
static VARIANT * get_variant(jsval_t v)
Definition: jsval.h:234
static double get_number(jsval_t v)
Definition: jsval.h:224
int ret
static jsval_type_t jsval_type(jsval_t v)
Definition: jsval.h:210
static const char * debugstr_variant(const VARIANT *var)
Definition: container.c:46
#define S_OK
Definition: intsafe.h:59
#define E_NOTIMPL
Definition: ddrawi.h:99
LOCAL int prim(arg_t *ap)
Definition: match.c:440
HRESULT to_number(script_ctx_t *ctx, jsval_t val, double *ret)
Definition: jsutils.c:601
Definition: jsval.h:50

Referenced by add_eval(), Array_set_length(), Array_slice(), Date_setDate(), Date_setFullYear(), Date_setHours(), Date_setMilliseconds(), Date_setMinutes(), Date_setMonth(), Date_setSeconds(), Date_setTime(), Date_setUTCDate(), Date_setUTCFullYear(), Date_setUTCHours(), Date_setUTCMilliseconds(), Date_setUTCMinutes(), Date_setUTCMonth(), Date_setUTCSeconds(), Date_setYear(), date_utc(), DateConstr_value(), equal_values(), error_constr(), index_from_val(), interp_postinc(), interp_preinc(), interp_tonum(), JSGlobal_isFinite(), JSGlobal_isNaN(), less_eval(), Math_abs(), Math_acos(), Math_asin(), Math_atan(), Math_atan2(), Math_ceil(), Math_cos(), Math_exp(), Math_floor(), Math_log(), Math_max(), Math_min(), Math_pow(), Math_round(), Math_sin(), Math_sqrt(), Math_tan(), maybe_to_primitive(), NumberConstr_value(), sort_cmp(), stack_pop_number(), to_int32(), to_integer(), and variant_change_type().

◆ to_object()

HRESULT to_object ( script_ctx_t ctx,
jsval_t  val,
IDispatch **  disp 
)

Definition at line 808 of file jsutils.c.

809 {
810  jsdisp_t *dispex;
811  HRESULT hres;
812 
813  switch(jsval_type(val)) {
814  case JSV_STRING:
815  hres = create_string(ctx, get_string(val), &dispex);
816  if(FAILED(hres))
817  return hres;
818 
819  *disp = to_disp(dispex);
820  break;
821  case JSV_NUMBER:
822  hres = create_number(ctx, get_number(val), &dispex);
823  if(FAILED(hres))
824  return hres;
825 
826  *disp = to_disp(dispex);
827  break;
828  case JSV_OBJECT:
829  if(get_object(val)) {
830  *disp = get_object(val);
831  IDispatch_AddRef(*disp);
832  }else {
833  jsdisp_t *obj;
834 
835  hres = create_object(ctx, NULL, &obj);
836  if(FAILED(hres))
837  return hres;
838 
839  *disp = to_disp(obj);
840  }
841  break;
842  case JSV_BOOL:
843  hres = create_bool(ctx, get_bool(val), &dispex);
844  if(FAILED(hres))
845  return hres;
846 
847  *disp = to_disp(dispex);
848  break;
849  case JSV_UNDEFINED:
850  case JSV_NULL:
851  WARN("object expected\n");
853  case JSV_VARIANT:
854  switch(V_VT(get_variant(val))) {
855  case VT_ARRAY|VT_VARIANT:
856  hres = create_vbarray(ctx, V_ARRAY(get_variant(val)), &dispex);
857  if(FAILED(hres))
858  return hres;
859 
860  *disp = to_disp(dispex);
861  break;
862 
863  default:
864  FIXME("Unsupported %s\n", debugstr_variant(get_variant(val)));
865  return E_NOTIMPL;
866  }
867  break;
868  }
869 
870  return S_OK;
871 }
disp
Definition: i386-dis.c:3181
static IDispatch * get_object(jsval_t v)
Definition: jsval.h:219
#define V_ARRAY(A)
Definition: oleauto.h:222
#define WARN(fmt,...)
Definition: debug.h:111
HRESULT create_string(script_ctx_t *, jsstr_t *, jsdisp_t **) DECLSPEC_HIDDEN
Definition: string.c:1768
GLsizei GLsizei GLuint * obj
Definition: glext.h:6042
static jsstr_t * get_string(jsval_t v)
Definition: jsval.h:229
static BOOL get_bool(D3DXPARAMETER_TYPE type, const void *data)
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:416
HRESULT create_number(script_ctx_t *, double, jsdisp_t **) DECLSPEC_HIDDEN
Definition: number.c:632
GLuint GLfloat * val
Definition: glext.h:7180
Definition: jsval.h:46
HRESULT hres
Definition: protocol.c:465
HRESULT create_bool(script_ctx_t *ctx, BOOL b, jsdisp_t **ret)
Definition: bool.c:216
LONG HRESULT
Definition: typedefs.h:77
static VARIANT * get_variant(jsval_t v)
Definition: jsval.h:234
static double get_number(jsval_t v)
Definition: jsval.h:224
static jsval_type_t jsval_type(jsval_t v)
Definition: jsval.h:210
#define V_VT(A)
Definition: oleauto.h:211
static IDispatch * to_disp(jsdisp_t *jsdisp)
Definition: jscript.h:242
static const char * debugstr_variant(const VARIANT *var)
Definition: container.c:46
#define S_OK
Definition: intsafe.h:59
#define E_NOTIMPL
Definition: ddrawi.h:99
HRESULT create_object(script_ctx_t *, jsdisp_t *, jsdisp_t **) DECLSPEC_HIDDEN
Definition: object.c:597
HRESULT throw_type_error(script_ctx_t *ctx, HRESULT error, const WCHAR *str)
Definition: error.c:438
Definition: jsval.h:50
HRESULT create_vbarray(script_ctx_t *, SAFEARRAY *, jsdisp_t **) DECLSPEC_HIDDEN
Definition: vbarray.c:347
#define JS_E_OBJECT_EXPECTED
Definition: jscript.h:559

Referenced by Function_apply(), Function_call(), interp_delete(), interp_memberid(), interp_push_scope(), ObjectConstr_value(), and stack_pop_object().

◆ to_primitive()

HRESULT to_primitive ( script_ctx_t ctx,
jsval_t  val,
jsval_t ret,
hint_t  hint 
)

Definition at line 396 of file jsutils.c.

397 {
398  if(is_object_instance(val)) {
399  jsdisp_t *jsdisp;
400  jsval_t prim;
401  DISPID id;
402  HRESULT hres;
403 
404  static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0};
405  static const WCHAR valueOfW[] = {'v','a','l','u','e','O','f',0};
406 
407  if(!get_object(val)) {
408  *ret = jsval_null();
409  return S_OK;
410  }
411 
412  jsdisp = iface_to_jsdisp(get_object(val));
413  if(!jsdisp)
414  return disp_propget(ctx, get_object(val), DISPID_VALUE, ret);
415 
416  if(hint == NO_HINT)
418 
419  /* Native implementation doesn't throw TypeErrors, returns strange values */
420 
421  hres = jsdisp_get_id(jsdisp, hint == HINT_STRING ? toStringW : valueOfW, 0, &id);
422  if(SUCCEEDED(hres)) {
423  hres = jsdisp_call(jsdisp, id, DISPATCH_METHOD, 0, NULL, &prim);
424  if(FAILED(hres)) {
425  WARN("call error - forwarding exception\n");
426  jsdisp_release(jsdisp);
427  return hres;
428  }else if(!is_object_instance(prim)) {
429  jsdisp_release(jsdisp);
430  *ret = prim;
431  return S_OK;
432  }else {
433  IDispatch_Release(get_object(prim));
434  }
435  }
436 
437  hres = jsdisp_get_id(jsdisp, hint == HINT_STRING ? valueOfW : toStringW, 0, &id);
438  if(SUCCEEDED(hres)) {
439  hres = jsdisp_call(jsdisp, id, DISPATCH_METHOD, 0, NULL, &prim);
440  if(FAILED(hres)) {
441  WARN("call error - forwarding exception\n");
442  jsdisp_release(jsdisp);
443  return hres;
444  }else if(!is_object_instance(prim)) {
445  jsdisp_release(jsdisp);
446  *ret = prim;
447  return S_OK;
448  }else {
449  IDispatch_Release(get_object(prim));
450  }
451  }
452 
453  jsdisp_release(jsdisp);
454 
455  WARN("failed\n");
457  }
458 
459  return jsval_copy(val, ret);
460 
461 }
Definition: jsval.h:54
static jsval_t jsval_null(void)
Definition: jsval.h:130
static IDispatch * get_object(jsval_t v)
Definition: jsval.h:219
#define WARN(fmt,...)
Definition: debug.h:111
static const WCHAR toStringW[]
Definition: array.c:48
static const WCHAR valueOfW[]
Definition: bool.c:35
#define JS_E_TO_PRIMITIVE
Definition: jscript.h:532
#define DISPATCH_METHOD
Definition: oleauto.h:1006
HRESULT jsdisp_call(jsdisp_t *disp, DISPID id, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: dispex.c:1134
HRESULT jsval_copy(jsval_t v, jsval_t *r)
Definition: jsutils.c:229
static BOOL is_class(jsdisp_t *jsdisp, jsclass_t class)
Definition: jscript.h:500
HRESULT disp_propget(script_ctx_t *ctx, IDispatch *disp, DISPID id, jsval_t *val)
Definition: dispex.c:1479
smooth NULL
Definition: ftsmooth.c:416
static BOOL is_object_instance(jsval_t v)
Definition: jsval.h:166
GLuint GLfloat * val
Definition: glext.h:7180
HRESULT hres
Definition: protocol.c:465
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
int ret
HRESULT jsdisp_get_id(jsdisp_t *jsdisp, const WCHAR *name, DWORD flags, DISPID *id)
Definition: dispex.c:1088
jsdisp_t * iface_to_jsdisp(IDispatch *iface)
Definition: dispex.c:1081
#define S_OK
Definition: intsafe.h:59
static VARIANTARG static DISPID
Definition: ordinal.c:49
DWORD hint
Definition: vfdcmd.c:88
static void jsdisp_release(jsdisp_t *jsdisp)
Definition: jscript.h:265
LOCAL int prim(arg_t *ap)
Definition: match.c:440
GLenum GLuint id
Definition: glext.h:5579
HRESULT throw_type_error(script_ctx_t *ctx, HRESULT error, const WCHAR *str)
Definition: error.c:438
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by add_eval(), DateConstr_value(), equal_values(), less_eval(), to_number(), and to_string().

◆ to_string()

HRESULT to_string ( script_ctx_t ctx,
jsval_t  val,
jsstr_t **  str 
)

Definition at line 749 of file jsutils.c.

750 {
751  static const WCHAR nullW[] = {'n','u','l','l',0};
752  static const WCHAR trueW[] = {'t','r','u','e',0};
753  static const WCHAR falseW[] = {'f','a','l','s','e',0};
754 
755  switch(jsval_type(val)) {
756  case JSV_UNDEFINED:
757  *str = jsstr_undefined();
758  return S_OK;
759  case JSV_NULL:
760  *str = jsstr_alloc(nullW);
761  break;
762  case JSV_NUMBER:
764  case JSV_STRING:
766  break;
767  case JSV_OBJECT: {
768  jsval_t prim;
769  HRESULT hres;
770 
771  hres = to_primitive(ctx, val, &prim, HINT_STRING);
772  if(FAILED(hres))
773  return hres;
774 
775  hres = to_string(ctx, prim, str);
777  return hres;
778  }
779  case JSV_BOOL:
781  break;
782  default:
783  FIXME("unsupported %s\n", debugstr_jsval(val));
784  return E_NOTIMPL;
785  }
786 
787  return *str ? S_OK : E_OUTOFMEMORY;
788 }
Definition: jsval.h:54
static jsstr_t * jsstr_alloc(const WCHAR *str)
Definition: jsstr.h:103
void jsval_release(jsval_t val)
Definition: jsutils.c:189
jsstr_t * jsstr_undefined(void)
Definition: jsstr.c:293
static jsstr_t * jsstr_addref(jsstr_t *str)
Definition: jsstr.h:116
HRESULT double_to_string(double n, jsstr_t **str)
Definition: jsutils.c:719
HRESULT to_primitive(script_ctx_t *ctx, jsval_t val, jsval_t *ret, hint_t hint)
Definition: jsutils.c:396
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
static jsstr_t * get_string(jsval_t v)
Definition: jsval.h:229
static BOOL get_bool(D3DXPARAMETER_TYPE type, const void *data)
HRESULT to_string(script_ctx_t *ctx, jsval_t val, jsstr_t **str)
Definition: jsutils.c:749
#define FIXME(fmt,...)
Definition: debug.h:110
const WCHAR * str
GLuint GLfloat * val
Definition: glext.h:7180
Definition: jsval.h:46
HRESULT hres
Definition: protocol.c:465
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
static const WCHAR falseW[]
Definition: json.c:35
static double get_number(jsval_t v)
Definition: jsval.h:224
static jsval_type_t jsval_type(jsval_t v)
Definition: jsval.h:210
const char * debugstr_jsval(const jsval_t v)
Definition: jsutils.c:33
#define S_OK
Definition: intsafe.h:59
#define E_NOTIMPL
Definition: ddrawi.h:99
LOCAL int prim(arg_t *ap)
Definition: match.c:440
Definition: jsval.h:50
static const WCHAR trueW[]
Definition: json.c:34
static const WCHAR nullW[]
Definition: json.c:33

Referenced by to_flat_string(), and variant_change_type().

◆ to_uint32()

HRESULT to_uint32 ( script_ctx_t ctx,
jsval_t  val,
UINT32 ret 
)

Definition at line 678 of file jsutils.c.

679 {
680  INT32 n;
681  HRESULT hres;
682 
683  hres = to_int32(ctx, val, &n);
684  if(SUCCEEDED(hres))
685  *ret = n;
686  return hres;
687 }
GLdouble n
Definition: glext.h:7729
GLuint GLfloat * val
Definition: glext.h:7180
HRESULT hres
Definition: protocol.c:465
LONG HRESULT
Definition: typedefs.h:77
int ret
HRESULT to_int32(script_ctx_t *ctx, jsval_t v, INT *ret)
Definition: jsutils.c:657
signed int INT32
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by array_to_args(), get_length(), stack_pop_uint(), String_split(), and StringConstr_fromCharCode().

◆ variant_change_type()

HRESULT variant_change_type ( script_ctx_t ctx,
VARIANT dst,
VARIANT src,
VARTYPE  vt 
)

Definition at line 873 of file jsutils.c.

874 {
875  jsval_t val;
876  HRESULT hres;
877 
878  clear_ei(ctx);
880  if(FAILED(hres))
881  return hres;
882 
883  switch(vt) {
884  case VT_I2:
885  case VT_I4: {
886  INT i;
887 
888  hres = to_int32(ctx, val, &i);
889  if(SUCCEEDED(hres)) {
890  if(vt == VT_I4)
891  V_I4(dst) = i;
892  else
893  V_I2(dst) = i;
894  }
895  break;
896  }
897  case VT_R8: {
898  double n;
899  hres = to_number(ctx, val, &n);
900  if(SUCCEEDED(hres))
901  V_R8(dst) = n;
902  break;
903  }
904  case VT_R4: {
905  double n;
906 
907  hres = to_number(ctx, val, &n);
908  if(SUCCEEDED(hres))
909  V_R4(dst) = n;
910  break;
911  }
912  case VT_BOOL: {
913  BOOL b;
914 
915  hres = to_boolean(val, &b);
916  if(SUCCEEDED(hres))
917  V_BOOL(dst) = b ? VARIANT_TRUE : VARIANT_FALSE;
918  break;
919  }
920  case VT_BSTR: {
921  jsstr_t *str;
922 
923  hres = to_string(ctx, val, &str);
924  if(FAILED(hres))
925  break;
926 
927  if(is_null_bstr(str)) {
928  V_BSTR(dst) = NULL;
929  break;
930  }
931 
933  if(V_BSTR(dst))
935  else
937  break;
938  }
939  case VT_EMPTY:
940  hres = V_VT(src) == VT_EMPTY ? S_OK : E_NOTIMPL;
941  break;
942  case VT_NULL:
943  hres = V_VT(src) == VT_NULL ? S_OK : E_NOTIMPL;
944  break;
945  default:
946  FIXME("vt %d not implemented\n", vt);
947  hres = E_NOTIMPL;
948  }
949 
951  if(FAILED(hres))
952  return hres;
953 
954  V_VT(dst) = vt;
955  return S_OK;
956 }
Definition: jsval.h:54
void jsval_release(jsval_t val)
Definition: jsutils.c:189
Definition: compat.h:1939
BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
Definition: oleaut.c:342
Definition: jsstr.h:39
#define V_R8(A)
Definition: oleauto.h:262
#define V_I2(A)
Definition: oleauto.h:245
GLdouble n
Definition: glext.h:7729
static unsigned jsstr_flush(jsstr_t *str, WCHAR *buf)
Definition: jsstr.h:148
static unsigned jsstr_length(jsstr_t *str)
Definition: jsstr.h:58
void clear_ei(script_ctx_t *ctx)
Definition: engine.c:428
int32_t INT
Definition: typedefs.h:56
#define V_I4(A)
Definition: oleauto.h:247
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
HRESULT to_boolean(jsval_t val, BOOL *ret)
Definition: jsutils.c:464
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
unsigned int BOOL
Definition: ntddk_ex.h:94
HRESULT to_string(script_ctx_t *ctx, jsval_t val, jsstr_t **str)
Definition: jsutils.c:749
#define FIXME(fmt,...)
Definition: debug.h:110
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
HRESULT variant_to_jsval(VARIANT *var, jsval_t *r)
Definition: jsutils.c:256
#define b
Definition: ke_i.h:79
GLuint GLfloat * val
Definition: glext.h:7180
#define V_R4(A)
Definition: oleauto.h:260
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
HRESULT hres
Definition: protocol.c:465
LONG HRESULT
Definition: typedefs.h:77
#define V_BOOL(A)
Definition: oleauto.h:224
static REFPROPVARIANT PROPVAR_CHANGE_FLAGS VARTYPE vt
Definition: suminfo.c:85
Definition: compat.h:1940
#define V_VT(A)
Definition: oleauto.h:211
HRESULT to_int32(script_ctx_t *ctx, jsval_t v, INT *ret)
Definition: jsutils.c:657
GLenum src
Definition: glext.h:6340
#define V_BSTR(A)
Definition: oleauto.h:226
#define S_OK
Definition: intsafe.h:59
BOOL is_null_bstr(jsstr_t *str)
Definition: jsstr.c:303
#define E_NOTIMPL
Definition: ddrawi.h:99
GLenum GLenum dst
Definition: glext.h:6340
HRESULT to_number(script_ctx_t *ctx, jsval_t val, double *ret)
Definition: jsutils.c:601
Definition: compat.h:1941
Definition: compat.h:1938
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by VariantChangeType_ChangeType().

◆ variant_to_jsval()

HRESULT variant_to_jsval ( VARIANT var,
jsval_t r 
)

Definition at line 256 of file jsutils.c.

257 {
258  if(V_VT(var) == (VT_VARIANT|VT_BYREF))
259  var = V_VARIANTREF(var);
260 
261  switch(V_VT(var)) {
262  case VT_EMPTY:
263  *r = jsval_undefined();
264  return S_OK;
265  case VT_NULL:
266  *r = jsval_null();
267  return S_OK;
268  case VT_BOOL:
269  *r = jsval_bool(V_BOOL(var));
270  return S_OK;
271  case VT_I4:
272  *r = jsval_number(V_I4(var));
273  return S_OK;
274  case VT_R8:
275  *r = jsval_number(V_R8(var));
276  return S_OK;
277  case VT_BSTR: {
278  jsstr_t *str;
279 
280  if(V_BSTR(var)) {
282  if(!str)
283  return E_OUTOFMEMORY;
284  }else {
285  str = jsstr_null_bstr();
286  }
287 
288  *r = jsval_string(str);
289  return S_OK;
290  }
291  case VT_DISPATCH: {
292  if(V_DISPATCH(var))
293  IDispatch_AddRef(V_DISPATCH(var));
294  *r = jsval_disp(V_DISPATCH(var));
295  return S_OK;
296  }
297  case VT_I2:
298  *r = jsval_number(V_I2(var));
299  return S_OK;
300  case VT_UI2:
301  *r = jsval_number(V_UI2(var));
302  return S_OK;
303  case VT_INT:
304  *r = jsval_number(V_INT(var));
305  return S_OK;
306  case VT_UI4:
307  *r = jsval_number(V_UI4(var));
308  return S_OK;
309  case VT_UI8:
310  /*
311  * Native doesn't support VT_UI8 here, but it's needed for IE9+ APIs
312  * (native IE9 doesn't use jscript.dll for JavaScript).
313  */
314  *r = jsval_number(V_UI8(var));
315  return S_OK;
316  case VT_R4:
317  *r = jsval_number(V_R4(var));
318  return S_OK;
319  case VT_UNKNOWN:
320  if(V_UNKNOWN(var)) {
321  IDispatch *disp;
322  HRESULT hres;
323 
324  hres = IUnknown_QueryInterface(V_UNKNOWN(var), &IID_IDispatch, (void**)&disp);
325  if(SUCCEEDED(hres)) {
326  *r = jsval_disp(disp);
327  return S_OK;
328  }
329  }else {
330  *r = jsval_disp(NULL);
331  return S_OK;
332  }
333  /* fall through */
334  default:
335  return jsval_variant(r, var);
336  }
337 }
jsstr_t * jsstr_alloc_len(const WCHAR *buf, unsigned len)
Definition: jsstr.c:86
disp
Definition: i386-dis.c:3181
Definition: compat.h:1939
jsstr_t * jsstr_null_bstr(void)
Definition: jsstr.c:298
Definition: jsstr.h:39
static jsval_t jsval_null(void)
Definition: jsval.h:130
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define V_R8(A)
Definition: oleauto.h:262
#define V_I2(A)
Definition: oleauto.h:245
#define V_UI8(A)
Definition: oleauto.h:272
#define V_I4(A)
Definition: oleauto.h:247
#define V_DISPATCH(A)
Definition: oleauto.h:239
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
#define V_UI2(A)
Definition: oleauto.h:268
static jsval_t jsval_string(jsstr_t *str)
Definition: jsval.h:109
#define V_R4(A)
Definition: oleauto.h:260
static jsval_t jsval_disp(IDispatch *obj)
Definition: jsval.h:117
HRESULT hres
Definition: protocol.c:465
LONG HRESULT
Definition: typedefs.h:77
#define V_BOOL(A)
Definition: oleauto.h:224
#define V_UI4(A)
Definition: oleauto.h:270
const GUID IID_IDispatch
static HRESULT jsval_variant(jsval_t *val, VARIANT *var)
Definition: jsutils.c:208
Definition: compat.h:1940
#define V_VT(A)
Definition: oleauto.h:211
UINT WINAPI SysStringLen(BSTR str)
Definition: oleaut.c:199
#define V_UNKNOWN(A)
Definition: oleauto.h:281
#define V_BSTR(A)
Definition: oleauto.h:226
static jsval_t jsval_undefined(void)
Definition: jsval.h:137
#define S_OK
Definition: intsafe.h:59
#define V_INT(x)
Definition: webchild.h:78
static jsval_t jsval_bool(BOOL b)
Definition: jsval.h:101
#define V_VARIANTREF(A)
Definition: oleauto.h:283
Definition: compat.h:1941
Definition: compat.h:1938
#define SUCCEEDED(hr)
Definition: intsafe.h:57
static jsval_t jsval_number(double n)
Definition: jsval.h:144

Referenced by convert_params(), disp_call(), disp_call_value(), disp_propget(), DispatchEx_InvokeEx(), enumvar_get_next_item(), variant_change_type(), VBArray_getItem(), and VBArray_toArray().

◆ WINE_DECLARE_DEBUG_CHANNEL()

WINE_DECLARE_DEBUG_CHANNEL ( heap  )

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( jscript  )

Variable Documentation

◆ ServiceProviderVtbl

const IServiceProviderVtbl ServiceProviderVtbl
static
Initial value:
= {
}
static ULONG WINAPI JSCaller_AddRef(IServiceProvider *iface)
Definition: jsutils.c:983
static HRESULT WINAPI JSCaller_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
Definition: jsutils.c:963
static ULONG WINAPI JSCaller_Release(IServiceProvider *iface)
Definition: jsutils.c:993
static HRESULT WINAPI JSCaller_QueryService(IServiceProvider *iface, REFGUID guidService, REFIID riid, void **ppv)
Definition: jsutils.c:1008

Definition at line 1024 of file jsutils.c.

Referenced by create_jscaller().