ReactOS 0.4.16-dev-122-g325d74c
function.c File Reference
#include <assert.h>
#include "jscript.h"
#include "engine.h"
#include "wine/debug.h"
Include dependency graph for function.c:

Go to the source code of this file.

Classes

struct  FunctionInstance
 
struct  _function_vtbl_t
 
struct  InterpretedFunction
 
struct  NativeFunction
 
struct  BindFunction
 
struct  ArgumentsInstance
 

Typedefs

typedef struct _function_vtbl_t function_vtbl_t
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (jscript)
 
static HRESULT create_bind_function (script_ctx_t *, FunctionInstance *, IDispatch *, unsigned, jsval_t *, jsdisp_t **r)
 
static FunctionInstancefunction_from_jsdisp (jsdisp_t *jsdisp)
 
static FunctionInstancefunction_from_vdisp (vdisp_t *vdisp)
 
static FunctionInstancefunction_this (vdisp_t *jsthis)
 
static ArgumentsInstancearguments_from_jsdisp (jsdisp_t *jsdisp)
 
static HRESULT Arguments_value (script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static void Arguments_destructor (jsdisp_t *jsdisp)
 
static unsigned Arguments_idx_length (jsdisp_t *jsdisp)
 
static jsval_tget_argument_ref (ArgumentsInstance *arguments, unsigned idx)
 
static HRESULT Arguments_idx_get (jsdisp_t *jsdisp, unsigned idx, jsval_t *r)
 
static HRESULT Arguments_idx_put (jsdisp_t *jsdisp, unsigned idx, jsval_t val)
 
HRESULT setup_arguments_object (script_ctx_t *ctx, call_frame_t *frame)
 
void detach_arguments_object (jsdisp_t *args_disp)
 
HRESULT Function_invoke (jsdisp_t *func_this, IDispatch *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Function_get_length (script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
 
static HRESULT Function_toString (script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT array_to_args (script_ctx_t *ctx, jsdisp_t *arg_array, unsigned *argc, jsval_t **ret)
 
static HRESULT Function_apply (script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Function_call (script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Function_bind (script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
HRESULT Function_value (script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
HRESULT Function_get_value (script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
 
static HRESULT Function_get_arguments (script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
 
static void Function_destructor (jsdisp_t *dispex)
 
static HRESULT create_function (script_ctx_t *ctx, const builtin_info_t *builtin_info, const function_vtbl_t *vtbl, size_t size, DWORD flags, BOOL funcprot, jsdisp_t *prototype, void **ret)
 
static HRESULT NativeFunction_call (script_ctx_t *ctx, FunctionInstance *func, IDispatch *this_disp, unsigned flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT NativeFunction_toString (FunctionInstance *func, jsstr_t **ret)
 
static void NativeFunction_destructor (FunctionInstance *function)
 
HRESULT create_builtin_function (script_ctx_t *ctx, builtin_invoke_t value_proc, const WCHAR *name, const builtin_info_t *builtin_info, DWORD flags, jsdisp_t *prototype, jsdisp_t **ret)
 
static HRESULT set_constructor_prop (script_ctx_t *ctx, jsdisp_t *constr, jsdisp_t *prot)
 
HRESULT create_builtin_constructor (script_ctx_t *ctx, builtin_invoke_t value_proc, const WCHAR *name, const builtin_info_t *builtin_info, DWORD flags, jsdisp_t *prototype, jsdisp_t **ret)
 
static HRESULT InterpretedFunction_call (script_ctx_t *ctx, FunctionInstance *func, IDispatch *this_obj, unsigned flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT InterpretedFunction_toString (FunctionInstance *func, jsstr_t **ret)
 
static void InterpretedFunction_destructor (FunctionInstance *func)
 
HRESULT create_source_function (script_ctx_t *ctx, bytecode_t *code, function_code_t *func_code, scope_chain_t *scope_chain, jsdisp_t **ret)
 
static HRESULT BindFunction_call (script_ctx_t *ctx, FunctionInstance *func, IDispatch *this_obj, unsigned flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT BindFunction_toString (FunctionInstance *function, jsstr_t **ret)
 
static void BindFunction_destructor (FunctionInstance *func)
 
static HRESULT construct_function (script_ctx_t *ctx, unsigned argc, jsval_t *argv, IDispatch **ret)
 
static HRESULT FunctionConstr_value (script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT FunctionProt_value (script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
HRESULT init_function_constr (script_ctx_t *ctx, jsdisp_t *object_prototype)
 

Variables

static const WCHAR prototypeW [] = {'p','r','o','t','o','t', 'y', 'p','e',0}
 
static const WCHAR lengthW [] = {'l','e','n','g','t','h',0}
 
static const WCHAR toStringW [] = {'t','o','S','t','r','i','n','g',0}
 
static const WCHAR applyW [] = {'a','p','p','l','y',0}
 
static const WCHAR bindW [] = {'b','i','n','d',0}
 
static const WCHAR callW [] = {'c','a','l','l',0}
 
static const WCHAR argumentsW [] = {'a','r','g','u','m','e','n','t','s',0}
 
static const builtin_info_t Arguments_info
 
static const builtin_prop_t Function_props []
 
static const builtin_info_t Function_info
 
static const builtin_prop_t FunctionInst_props []
 
static const builtin_info_t FunctionInst_info
 
static const function_vtbl_t NativeFunctionVtbl
 
static const function_vtbl_t InterpretedFunctionVtbl
 
static const function_vtbl_t BindFunctionVtbl
 

Typedef Documentation

◆ function_vtbl_t

Definition at line 28 of file function.c.

Function Documentation

◆ Arguments_destructor()

static void Arguments_destructor ( jsdisp_t jsdisp)
static

Definition at line 110 of file function.c.

111{
112 ArgumentsInstance *arguments = arguments_from_jsdisp(jsdisp);
113
114 TRACE("(%p)\n", arguments);
115
116 if(arguments->buf) {
117 unsigned i;
118 for(i = 0; i < arguments->argc; i++)
119 jsval_release(arguments->buf[i]);
120 heap_free(arguments->buf);
121 }
122
124 heap_free(arguments);
125}
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
static ArgumentsInstance * arguments_from_jsdisp(jsdisp_t *jsdisp)
Definition: function.c:89
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
static void jsdisp_release(jsdisp_t *jsdisp)
Definition: jscript.h:268
void jsval_release(jsval_t val)
Definition: jsutils.c:191
#define TRACE(s)
Definition: solgame.cpp:4
InterpretedFunction * function
Definition: function.c:66
jsval_t * buf
Definition: function.c:67
unsigned argc
Definition: function.c:69
jsdisp_t dispex
Definition: function.c:31
FunctionInstance function
Definition: function.c:44

◆ arguments_from_jsdisp()

static ArgumentsInstance * arguments_from_jsdisp ( jsdisp_t jsdisp)
inlinestatic

Definition at line 89 of file function.c.

90{
91 return CONTAINING_RECORD(jsdisp, ArgumentsInstance, jsdisp);
92}
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by Arguments_destructor(), Arguments_idx_get(), Arguments_idx_length(), Arguments_idx_put(), and detach_arguments_object().

◆ Arguments_idx_get()

static HRESULT Arguments_idx_get ( jsdisp_t jsdisp,
unsigned  idx,
jsval_t r 
)
static

Definition at line 142 of file function.c.

143{
144 ArgumentsInstance *arguments = arguments_from_jsdisp(jsdisp);
145 jsval_t *ref;
146
147 TRACE("%p[%u]\n", arguments, idx);
148
149 if((ref = get_argument_ref(arguments, idx)))
150 return jsval_copy(*ref, r);
151
152 /* FIXME: Accessing by name won't work for duplicated argument names */
153 return jsdisp_propget_name(arguments->frame->base_scope->jsobj,
154 arguments->function->func_code->params[idx], r);
155}
unsigned int idx
Definition: utils.c:41
static jsval_t * get_argument_ref(ArgumentsInstance *arguments, unsigned idx)
Definition: function.c:133
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
HRESULT jsdisp_propget_name(jsdisp_t *obj, const WCHAR *name, jsval_t *val)
Definition: dispex.c:1408
HRESULT jsval_copy(jsval_t v, jsval_t *r)
Definition: jsutils.c:231
call_frame_t * frame
Definition: function.c:68
function_code_t * func_code
Definition: function.c:47
scope_chain_t * base_scope
Definition: engine.h:226
BSTR * params
Definition: engine.h:164
Definition: jsval.h:54
jsdisp_t * jsobj
Definition: engine.h:204
Definition: send.c:48

◆ Arguments_idx_length()

static unsigned Arguments_idx_length ( jsdisp_t jsdisp)
static

Definition at line 127 of file function.c.

128{
129 ArgumentsInstance *arguments = arguments_from_jsdisp(jsdisp);
130 return arguments->argc;
131}

◆ Arguments_idx_put()

static HRESULT Arguments_idx_put ( jsdisp_t jsdisp,
unsigned  idx,
jsval_t  val 
)
static

Definition at line 157 of file function.c.

158{
159 ArgumentsInstance *arguments = arguments_from_jsdisp(jsdisp);
160 jsval_t *ref;
162
163 TRACE("%p[%u] = %s\n", arguments, idx, debugstr_jsval(val));
164
165 if((ref = get_argument_ref(arguments, idx))) {
167 hres = jsval_copy(val, &copy);
168 if(FAILED(hres))
169 return hres;
170
172 *ref = copy;
173 return S_OK;
174 }
175
176 /* FIXME: Accessing by name won't work for duplicated argument names */
177 return jsdisp_propput_name(arguments->frame->base_scope->jsobj,
178 arguments->function->func_code->params[idx], val);
179}
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
GLuint GLfloat * val
Definition: glext.h:7180
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
HRESULT jsdisp_propput_name(jsdisp_t *obj, const WCHAR *name, jsval_t val)
Definition: dispex.c:1344
const char * debugstr_jsval(const jsval_t) DECLSPEC_HIDDEN
Definition: jsutils.c:35
HRESULT hres
Definition: protocol.c:465

◆ Arguments_value()

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

Definition at line 103 of file function.c.

105{
106 FIXME("\n");
107 return E_NOTIMPL;
108}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ array_to_args()

static HRESULT array_to_args ( script_ctx_t ctx,
jsdisp_t arg_array,
unsigned argc,
jsval_t **  ret 
)
static

Definition at line 307 of file function.c.

308{
309 jsval_t *argv, val;
310 DWORD length, i;
312
313 hres = jsdisp_propget_name(arg_array, lengthW, &val);
314 if(FAILED(hres))
315 return hres;
316
319 if(FAILED(hres))
320 return hres;
321
322 argv = heap_alloc(length * sizeof(*argv));
323 if(!argv)
324 return E_OUTOFMEMORY;
325
326 for(i=0; i<length; i++) {
327 hres = jsdisp_get_idx(arg_array, i, argv+i);
328 if(hres == DISP_E_UNKNOWNNAME) {
330 }else if(FAILED(hres)) {
331 while(i--)
334 return hres;
335 }
336 }
337
338 *argc = length;
339 *ret = argv;
340 return S_OK;
341}
static int argc
Definition: ServiceArgs.c:12
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
static const WCHAR lengthW[]
Definition: function.c:96
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
HRESULT jsdisp_get_idx(jsdisp_t *obj, DWORD idx, jsval_t *r)
Definition: dispex.c:1425
HRESULT to_uint32(script_ctx_t *, jsval_t, UINT32 *) DECLSPEC_HIDDEN
Definition: jsutils.c:686
static jsval_t jsval_undefined(void)
Definition: jsval.h:137
#define argv
Definition: mplay32.c:18
int ret
#define DISP_E_UNKNOWNNAME
Definition: winerror.h:2515

Referenced by Function_apply().

◆ BindFunction_call()

static HRESULT BindFunction_call ( script_ctx_t ctx,
FunctionInstance func,
IDispatch this_obj,
unsigned  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 806 of file function.c.

808{
809 BindFunction *function = (BindFunction*)func;
810 jsval_t *call_args = NULL;
811 unsigned call_argc;
813
814 TRACE("%p\n", function);
815
816 call_argc = function->argc + argc;
817 if(call_argc) {
818 call_args = heap_alloc(function->argc * sizeof(*function->args));
819 if(!call_args)
820 return E_OUTOFMEMORY;
821
822 if(function->argc)
823 memcpy(call_args, function->args, function->argc * sizeof(*call_args));
824 if(argc)
825 memcpy(call_args + function->argc, argv, argc * sizeof(*call_args));
826 }
827
828 hres = function->target->vtbl->call(ctx, function->target, function->this, flags, call_argc, call_args, r);
829
830 heap_free(call_args);
831 return hres;
832}
#define NULL
Definition: types.h:112
GLenum func
Definition: glext.h:6028
GLbitfield flags
Definition: glext.h:7161
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned argc
Definition: function.c:60
FunctionInstance * target
Definition: function.c:58
IDispatch * this
Definition: function.c:59
jsval_t args[1]
Definition: function.c:61
const function_vtbl_t * vtbl
Definition: function.c:32
HRESULT(* call)(script_ctx_t *, FunctionInstance *, IDispatch *, unsigned, unsigned, jsval_t *, jsval_t *)
Definition: function.c:38

◆ BindFunction_destructor()

static void BindFunction_destructor ( FunctionInstance func)
static

Definition at line 845 of file function.c.

846{
847 BindFunction *function = (BindFunction*)func;
848 unsigned i;
849
850 TRACE("%p\n", function);
851
852 for(i = 0; i < function->argc; i++)
853 jsval_release(function->args[i]);
854 jsdisp_release(&function->target->dispex);
855 IDispatch_Release(function->this);
856}

◆ BindFunction_toString()

static HRESULT BindFunction_toString ( FunctionInstance function,
jsstr_t **  ret 
)
static

Definition at line 834 of file function.c.

835{
836 static const WCHAR native_functionW[] =
837 {'\n','f','u','n','c','t','i','o','n','(',')',' ','{','\n',
838 ' ',' ',' ',' ','[','n','a','t','i','v','e',' ','c','o','d','e',']','\n',
839 '}','\n',0};
840
841 *ret = jsstr_alloc(native_functionW);
842 return *ret ? S_OK : E_OUTOFMEMORY;
843}
static jsstr_t * jsstr_alloc(const WCHAR *str)
Definition: jsstr.h:103
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ construct_function()

static HRESULT construct_function ( script_ctx_t ctx,
unsigned  argc,
jsval_t argv,
IDispatch **  ret 
)
static

Definition at line 894 of file function.c.

895{
896 WCHAR *str = NULL, *ptr;
897 unsigned len = 0, i = 0;
899 jsdisp_t *function;
900 jsstr_t **params = NULL;
901 int j = 0;
902 HRESULT hres = S_OK;
903
904 static const WCHAR function_anonymousW[] = {'f','u','n','c','t','i','o','n',' ','a','n','o','n','y','m','o','u','s','('};
905 static const WCHAR function_beginW[] = {')',' ','{','\n'};
906 static const WCHAR function_endW[] = {'\n','}',0};
907
908 if(argc) {
909 params = heap_alloc(argc*sizeof(*params));
910 if(!params)
911 return E_OUTOFMEMORY;
912
913 if(argc > 2)
914 len = (argc-2)*2; /* separating commas */
915 for(i=0; i < argc; i++) {
917 if(FAILED(hres))
918 break;
920 }
921 }
922
923 if(SUCCEEDED(hres)) {
924 len += ARRAY_SIZE(function_anonymousW) + ARRAY_SIZE(function_beginW) + ARRAY_SIZE(function_endW);
925 str = heap_alloc(len*sizeof(WCHAR));
926 if(str) {
927 memcpy(str, function_anonymousW, sizeof(function_anonymousW));
928 ptr = str + ARRAY_SIZE(function_anonymousW);
929 if(argc > 1) {
930 while(1) {
931 ptr += jsstr_flush(params[j], ptr);
932 if(++j == argc-1)
933 break;
934 *ptr++ = ',';
935 *ptr++ = ' ';
936 }
937 }
938 memcpy(ptr, function_beginW, sizeof(function_beginW));
939 ptr += ARRAY_SIZE(function_beginW);
940 if(argc)
941 ptr += jsstr_flush(params[argc-1], ptr);
942 memcpy(ptr, function_endW, sizeof(function_endW));
943
944 TRACE("%s\n", debugstr_w(str));
945 }else {
947 }
948 }
949
950 while(i)
953 if(FAILED(hres))
954 return hres;
955
957 heap_free(str);
958 if(FAILED(hres))
959 return hres;
960
961 if(code->global_code.func_cnt != 1 || code->global_code.var_cnt != 1) {
962 ERR("Invalid parser result!\n");
964 return E_UNEXPECTED;
965 }
966
967 hres = create_source_function(ctx, code, code->global_code.funcs, NULL, &function);
969 if(FAILED(hres))
970 return hres;
971
972 *ret = to_disp(function);
973 return S_OK;
974}
#define ARRAY_SIZE(A)
Definition: main.h:20
#define ERR(fmt,...)
Definition: precomp.h:57
#define FALSE
Definition: types.h:117
HRESULT create_source_function(script_ctx_t *ctx, bytecode_t *code, function_code_t *func_code, scope_chain_t *scope_chain, jsdisp_t **ret)
Definition: function.c:767
GLenum const GLfloat * params
Definition: glext.h:5645
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
static HRESULT to_string(VARIANT *src, BSTR *dst)
Definition: host.c:47
#define SUCCEEDED(hr)
Definition: intsafe.h:50
void release_bytecode(bytecode_t *code)
Definition: compile.c:2226
HRESULT compile_script(script_ctx_t *ctx, const WCHAR *code, const WCHAR *args, const WCHAR *delimiter, BOOL from_eval, BOOL use_decode, bytecode_t **ret)
Definition: compile.c:2461
static IDispatch * to_disp(jsdisp_t *jsdisp)
Definition: jscript.h:245
static void jsstr_release(jsstr_t *str)
Definition: jsstr.h:110
static unsigned jsstr_length(jsstr_t *str)
Definition: jsstr.h:58
static unsigned jsstr_flush(jsstr_t *str, WCHAR *buf)
Definition: jsstr.h:148
#define debugstr_w
Definition: kernel32.h:32
static PVOID ptr
Definition: dispmode.c:27
const WCHAR * str
Definition: jsstr.h:39
Definition: inflate.c:139
#define E_UNEXPECTED
Definition: winerror.h:2456

Referenced by FunctionConstr_value().

◆ create_bind_function()

static HRESULT create_bind_function ( script_ctx_t ctx,
FunctionInstance target,
IDispatch bound_this,
unsigned  argc,
jsval_t argv,
jsdisp_t **  r 
)
static

Definition at line 864 of file function.c.

866{
867 BindFunction *function;
869
871 FALSE, NULL, (void**)&function);
872 if(FAILED(hres))
873 return hres;
874
875 jsdisp_addref(&target->dispex);
876 function->target = target;
877
878 IDispatch_AddRef(function->this = bound_this);
879
880 for(function->argc = 0; function->argc < argc; function->argc++) {
881 hres = jsval_copy(argv[function->argc], function->args + function->argc);
882 if(FAILED(hres)) {
883 jsdisp_release(&function->function.dispex);
884 return hres;
885 }
886 }
887
888 function->function.length = target->length > argc ? target->length - argc : 0;
889
890 *ret = &function->function.dispex;
891 return S_OK;
892}
static const function_vtbl_t BindFunctionVtbl
Definition: function.c:858
static HRESULT create_function(script_ctx_t *ctx, const builtin_info_t *builtin_info, const function_vtbl_t *vtbl, size_t size, DWORD flags, BOOL funcprot, jsdisp_t *prototype, void **ret)
Definition: function.c:566
GLenum target
Definition: glext.h:7315
#define PROPF_METHOD
Definition: jscript.h:97
static jsdisp_t * jsdisp_addref(jsdisp_t *jsdisp)
Definition: jscript.h:262
FunctionInstance function
Definition: function.c:57
Definition: match.c:390
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255

Referenced by Function_bind().

◆ create_builtin_constructor()

HRESULT create_builtin_constructor ( script_ctx_t ctx,
builtin_invoke_t  value_proc,
const WCHAR name,
const builtin_info_t builtin_info,
DWORD  flags,
jsdisp_t prototype,
jsdisp_t **  ret 
)

Definition at line 686 of file function.c.

688{
689 jsdisp_t *constr;
691
692 hres = create_builtin_function(ctx, value_proc, name, builtin_info, flags, prototype, &constr);
693 if(FAILED(hres))
694 return hres;
695
696 hres = set_constructor_prop(ctx, constr, prototype);
697 if(FAILED(hres)) {
698 jsdisp_release(constr);
699 return hres;
700 }
701
702 *ret = constr;
703 return S_OK;
704}
static HRESULT set_constructor_prop(script_ctx_t *ctx, jsdisp_t *constr, jsdisp_t *prot)
Definition: function.c:678
HRESULT create_builtin_function(script_ctx_t *ctx, builtin_invoke_t value_proc, const WCHAR *name, const builtin_info_t *builtin_info, DWORD flags, jsdisp_t *prototype, jsdisp_t **ret)
Definition: function.c:651
Definition: name.c:39

Referenced by create_array_constr(), create_bool_constr(), create_date_constr(), create_enumerator_constr(), create_number_constr(), create_object_constr(), create_regexp_constr(), create_string_constr(), create_vbarray_constr(), and init_error_constr().

◆ create_builtin_function()

HRESULT create_builtin_function ( script_ctx_t ctx,
builtin_invoke_t  value_proc,
const WCHAR name,
const builtin_info_t builtin_info,
DWORD  flags,
jsdisp_t prototype,
jsdisp_t **  ret 
)

Definition at line 651 of file function.c.

653{
654 NativeFunction *function;
656
657 hres = create_function(ctx, builtin_info, &NativeFunctionVtbl, sizeof(NativeFunction), flags, FALSE, NULL, (void**)&function);
658 if(FAILED(hres))
659 return hres;
660
661 if(builtin_info)
663 jsval_number(function->function.length));
664 if(SUCCEEDED(hres))
666 if(FAILED(hres)) {
667 jsdisp_release(&function->function.dispex);
668 return hres;
669 }
670
671 function->proc = value_proc;
672 function->name = name;
673
674 *ret = &function->function.dispex;
675 return S_OK;
676}
static const WCHAR prototypeW[]
Definition: function.c:94
static const function_vtbl_t NativeFunctionVtbl
Definition: function.c:645
HRESULT jsdisp_define_data_property(jsdisp_t *obj, const WCHAR *name, unsigned flags, jsval_t value)
Definition: dispex.c:1801
static jsval_t jsval_obj(jsdisp_t *obj)
Definition: jsval.h:125
static jsval_t jsval_number(double n)
Definition: jsval.h:144
FunctionInstance function
Definition: function.c:51
const WCHAR * name
Definition: function.c:53
builtin_invoke_t proc
Definition: function.c:52

Referenced by create_activex_constr(), create_builtin_constructor(), and prop_get().

◆ create_function()

static HRESULT create_function ( script_ctx_t ctx,
const builtin_info_t builtin_info,
const function_vtbl_t vtbl,
size_t  size,
DWORD  flags,
BOOL  funcprot,
jsdisp_t prototype,
void **  ret 
)
static

Definition at line 566 of file function.c.

568{
569 FunctionInstance *function;
571
572 function = heap_alloc_zero(size);
573 if(!function)
574 return E_OUTOFMEMORY;
575
576 if(funcprot)
577 hres = init_dispex(&function->dispex, ctx, builtin_info, prototype);
578 else if(builtin_info)
579 hres = init_dispex_from_constr(&function->dispex, ctx, builtin_info, ctx->function_constr);
580 else
581 hres = init_dispex_from_constr(&function->dispex, ctx, &FunctionInst_info, ctx->function_constr);
582 if(FAILED(hres)) {
583 heap_free(function);
584 return hres;
585 }
586
587 function->vtbl = vtbl;
588 function->flags = flags;
589 function->length = flags & PROPF_ARGMASK;
590
591 *ret = function;
592 return S_OK;
593}
static const builtin_info_t FunctionInst_info
Definition: function.c:557
GLsizeiptr size
Definition: glext.h:5919
HRESULT init_dispex_from_constr(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *constr)
Definition: dispex.c:1030
HRESULT init_dispex(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *prototype)
Definition: dispex.c:919
#define PROPF_ARGMASK
Definition: jscript.h:96

Referenced by create_bind_function(), create_builtin_function(), create_source_function(), and init_function_constr().

◆ create_source_function()

HRESULT create_source_function ( script_ctx_t ctx,
bytecode_t code,
function_code_t func_code,
scope_chain_t scope_chain,
jsdisp_t **  ret 
)

Definition at line 767 of file function.c.

769{
770 InterpretedFunction *function;
771 jsdisp_t *prototype;
773
774 hres = create_object(ctx, NULL, &prototype);
775 if(FAILED(hres))
776 return hres;
777
779 FALSE, NULL, (void**)&function);
780 if(SUCCEEDED(hres)) {
782 jsval_obj(prototype));
783 if(SUCCEEDED(hres))
784 hres = set_constructor_prop(ctx, &function->function.dispex, prototype);
785 if(FAILED(hres))
786 jsdisp_release(&function->function.dispex);
787 }
788 jsdisp_release(prototype);
789 if(FAILED(hres))
790 return hres;
791
792 if(scope_chain) {
793 scope_addref(scope_chain);
794 function->scope_chain = scope_chain;
795 }
796
798 function->code = code;
799 function->func_code = func_code;
800 function->function.length = function->func_code->param_cnt;
801
802 *ret = &function->function.dispex;
803 return S_OK;
804}
static const function_vtbl_t InterpretedFunctionVtbl
Definition: function.c:761
static scope_chain_t * scope_addref(scope_chain_t *scope)
Definition: engine.h:212
static bytecode_t * bytecode_addref(bytecode_t *code)
Definition: engine.h:196
#define PROPF_CONSTR
Definition: jscript.h:98
HRESULT create_object(script_ctx_t *, jsdisp_t *, jsdisp_t **) DECLSPEC_HIDDEN
Definition: object.c:731
#define PROPF_WRITABLE
Definition: jscript.h:101
bytecode_t * code
Definition: function.c:46
scope_chain_t * scope_chain
Definition: function.c:45
unsigned param_cnt
Definition: engine.h:163

Referenced by construct_function(), exec_source(), interp_func(), JScriptParseProcedure_ParseProcedureText(), and setup_scope().

◆ detach_arguments_object()

void detach_arguments_object ( jsdisp_t args_disp)

Definition at line 229 of file function.c.

230{
231 ArgumentsInstance *arguments = arguments_from_jsdisp(args_disp);
232 call_frame_t *frame = arguments->frame;
233 const BOOL on_stack = frame->base_scope->frame == frame;
235
236 /* Reset arguments value to cut the reference cycle. Note that since all activation contexts have
237 * their own arguments property, it's impossible to use prototype's one during name lookup */
239 arguments->frame = NULL;
240
241 /* Don't bother coppying arguments if call frame holds the last reference. */
242 if(arguments->jsdisp.ref > 1) {
243 arguments->buf = heap_alloc(arguments->argc * sizeof(*arguments->buf));
244 if(arguments->buf) {
245 int i;
246
247 for(i = 0; i < arguments->argc ; i++) {
248 if(on_stack || i >= frame->function->param_cnt)
249 hres = jsval_copy(arguments->jsdisp.ctx->stack[frame->arguments_off + i], arguments->buf+i);
250 else
251 hres = jsdisp_propget_name(frame->base_scope->jsobj, frame->function->params[i], arguments->buf+i);
252 if(FAILED(hres))
253 arguments->buf[i] = jsval_undefined();
254 }
255 }else {
256 ERR("out of memory\n");
257 arguments->argc = 0;
258 }
259 }
260
262}
static const WCHAR argumentsW[]
Definition: function.c:101
unsigned int BOOL
Definition: ntddk_ex.h:94
jsdisp_t jsdisp
Definition: function.c:65
jsdisp_t * arguments_obj
Definition: engine.h:233
function_code_t * function
Definition: engine.h:243
unsigned arguments_off
Definition: engine.h:238
struct _call_frame_t * frame
Definition: engine.h:206
jsval_t * stack
Definition: jscript.h:431
LONG ref
Definition: jscript.h:233
script_ctx_t * ctx
Definition: jscript.h:238

Referenced by pop_call_frame().

◆ Function_apply()

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

Definition at line 343 of file function.c.

344{
345 FunctionInstance *function;
346 jsval_t *args = NULL;
347 unsigned i, cnt = 0;
348 IDispatch *this_obj = NULL;
349 HRESULT hres = S_OK;
350
351 TRACE("\n");
352
353 if(!(function = function_this(jsthis)) && (jsthis->flags & VDISP_JSDISP))
355
356 if(argc) {
357 if(!is_undefined(argv[0]) && !is_null(argv[0])) {
358 hres = to_object(ctx, argv[0], &this_obj);
359 if(FAILED(hres))
360 return hres;
361 }
362 }
363
364 if(argc >= 2) {
365 jsdisp_t *arg_array = NULL;
366
367 if(is_object_instance(argv[1])) {
368 arg_array = iface_to_jsdisp(get_object(argv[1]));
369 if(arg_array &&
370 (!is_class(arg_array, JSCLASS_ARRAY) && !is_class(arg_array, JSCLASS_ARGUMENTS) )) {
371 jsdisp_release(arg_array);
372 arg_array = NULL;
373 }
374 }
375
376 if(arg_array) {
377 hres = array_to_args(ctx, arg_array, &cnt, &args);
378 jsdisp_release(arg_array);
379 }else {
380 FIXME("throw TypeError\n");
381 hres = E_FAIL;
382 }
383 }
384
385 if(SUCCEEDED(hres)) {
386 if(function) {
387 hres = function->vtbl->call(ctx, function, this_obj, flags, cnt, args, r);
388 }else {
389 jsval_t res;
390 hres = disp_call_value(ctx, jsthis->u.disp, this_obj, DISPATCH_METHOD, cnt, args, &res);
391 if(SUCCEEDED(hres)) {
392 if(r)
393 *r = res;
394 else
396 }
397 }
398 }
399
400 if(this_obj)
401 IDispatch_Release(this_obj);
402 for(i=0; i < cnt; i++)
405 return hres;
406}
#define E_FAIL
Definition: ddrawi.h:102
HRESULT throw_type_error(script_ctx_t *ctx, HRESULT error, const WCHAR *str)
Definition: error.c:440
static HRESULT array_to_args(script_ctx_t *ctx, jsdisp_t *arg_array, unsigned *argc, jsval_t **ret)
Definition: function.c:307
static FunctionInstance * function_this(vdisp_t *jsthis)
Definition: function.c:84
GLuint res
Definition: glext.h:9613
jsdisp_t * iface_to_jsdisp(IDispatch *iface)
Definition: dispex.c:1060
HRESULT disp_call_value(script_ctx_t *ctx, IDispatch *disp, IDispatch *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: dispex.c:1228
HRESULT to_object(script_ctx_t *, jsval_t, IDispatch **) DECLSPEC_HIDDEN
Definition: jsutils.c:816
#define JS_E_FUNCTION_EXPECTED
Definition: jscript.h:552
#define VDISP_JSDISP
Definition: jscript.h:150
@ JSCLASS_ARGUMENTS
Definition: jscript.h:133
@ JSCLASS_ARRAY
Definition: jscript.h:121
static BOOL is_class(jsdisp_t *jsdisp, jsclass_t class)
Definition: jscript.h:504
static BOOL is_undefined(jsval_t v)
Definition: jsval.h:171
static IDispatch * get_object(jsval_t v)
Definition: jsval.h:219
static BOOL is_object_instance(jsval_t v)
Definition: jsval.h:166
static BOOL is_null(jsval_t v)
Definition: jsval.h:176
#define DISPATCH_METHOD
Definition: oleauto.h:1006
DWORD flags
Definition: jscript.h:146
union vdisp_t::@441 u
IDispatch * disp
Definition: jscript.h:142

◆ Function_bind()

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

Definition at line 438 of file function.c.

440{
441 FunctionInstance *function;
442 jsdisp_t *new_function;
444
445 TRACE("\n");
446
447 if(!(function = function_this(jsthis)))
449
450 if(argc < 1) {
451 FIXME("no this argument\n");
452 return E_NOTIMPL;
453 }
454
455 if(!is_object_instance(argv[0]) || !get_object(argv[0])) {
456 FIXME("%s is not an object instance\n", debugstr_jsval(argv[0]));
457 return E_NOTIMPL;
458 }
459
460 hres = create_bind_function(ctx, function, get_object(argv[0]), argc - 1, argv + 1, &new_function);
461 if(FAILED(hres))
462 return hres;
463
464 if(r)
465 *r = jsval_obj(new_function);
466 else
467 jsdisp_release(new_function);
468 return S_OK;
469}
static HRESULT create_bind_function(script_ctx_t *, FunctionInstance *, IDispatch *, unsigned, jsval_t *, jsdisp_t **r)
Definition: function.c:864

◆ Function_call()

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

Definition at line 408 of file function.c.

410{
411 FunctionInstance *function;
412 IDispatch *this_obj = NULL;
413 unsigned cnt = 0;
415
416 TRACE("\n");
417
418 if(!(function = function_this(jsthis)))
420
421 if(argc) {
422 if(!is_undefined(argv[0]) && !is_null(argv[0])) {
423 hres = to_object(ctx, argv[0], &this_obj);
424 if(FAILED(hres))
425 return hres;
426 }
427
428 cnt = argc-1;
429 }
430
431 hres = function->vtbl->call(ctx, function, this_obj, flags, cnt, argv + 1, r);
432
433 if(this_obj)
434 IDispatch_Release(this_obj);
435 return hres;
436}

◆ Function_destructor()

static void Function_destructor ( jsdisp_t dispex)
static

Definition at line 527 of file function.c.

528{
529 FunctionInstance *function = function_from_jsdisp(dispex);
530 function->vtbl->destructor(function);
531 heap_free(function);
532}
static FunctionInstance * function_from_jsdisp(jsdisp_t *jsdisp)
Definition: function.c:74
void(* destructor)(FunctionInstance *)
Definition: function.c:40

◆ function_from_jsdisp()

static FunctionInstance * function_from_jsdisp ( jsdisp_t jsdisp)
inlinestatic

◆ function_from_vdisp()

static FunctionInstance * function_from_vdisp ( vdisp_t vdisp)
inlinestatic

Definition at line 79 of file function.c.

80{
81 return function_from_jsdisp(vdisp->u.jsdisp);
82}
jsdisp_t * jsdisp
Definition: jscript.h:144

Referenced by function_this().

◆ Function_get_arguments()

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

Definition at line 503 of file function.c.

504{
505 FunctionInstance *function = function_from_jsdisp(jsthis);
506 call_frame_t *frame;
508
509 TRACE("\n");
510
511 for(frame = ctx->call_ctx; frame; frame = frame->prev_frame) {
512 if(frame->function_instance == &function->dispex) {
513 if(!frame->arguments_obj) {
515 if(FAILED(hres))
516 return hres;
517 }
519 return S_OK;
520 }
521 }
522
523 *r = jsval_null();
524 return S_OK;
525}
HRESULT setup_arguments_object(script_ctx_t *ctx, call_frame_t *frame)
Definition: function.c:192
static jsval_t jsval_null(void)
Definition: jsval.h:130
struct _call_frame_t * prev_frame
Definition: engine.h:245
jsdisp_t * function_instance
Definition: engine.h:231

◆ Function_get_length()

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

Definition at line 276 of file function.c.

277{
278 TRACE("%p\n", jsthis);
279
281 return S_OK;
282}

◆ Function_get_value()

HRESULT Function_get_value ( script_ctx_t ctx,
jsdisp_t jsthis,
jsval_t r 
)

Definition at line 487 of file function.c.

488{
489 FunctionInstance *function = function_from_jsdisp(jsthis);
490 jsstr_t *str;
492
493 TRACE("\n");
494
495 hres = function->vtbl->toString(function, &str);
496 if(FAILED(hres))
497 return hres;
498
499 *r = jsval_string(str);
500 return S_OK;
501}
static jsval_t jsval_string(jsstr_t *str)
Definition: jsval.h:109
HRESULT(* toString)(FunctionInstance *, jsstr_t **)
Definition: function.c:39

◆ Function_invoke()

HRESULT Function_invoke ( jsdisp_t func_this,
IDispatch jsthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)

Definition at line 264 of file function.c.

265{
266 FunctionInstance *function;
267
268 TRACE("func %p this %p\n", func_this, jsthis);
269
270 assert(is_class(func_this, JSCLASS_FUNCTION));
271 function = function_from_jsdisp(func_this);
272
273 return function->vtbl->call(function->dispex.ctx, function, jsthis, flags, argc, argv, r);
274}
#define assert(x)
Definition: debug.h:53
@ JSCLASS_FUNCTION
Definition: jscript.h:126

Referenced by invoke_prop_func(), and jsdisp_call_value().

◆ function_this()

static FunctionInstance * function_this ( vdisp_t jsthis)
inlinestatic

Definition at line 84 of file function.c.

85{
86 return is_vclass(jsthis, JSCLASS_FUNCTION) ? function_from_vdisp(jsthis) : NULL;
87}
static FunctionInstance * function_from_vdisp(vdisp_t *vdisp)
Definition: function.c:79
static BOOL is_vclass(vdisp_t *vdisp, jsclass_t class)
Definition: jscript.h:509

Referenced by Function_apply(), Function_bind(), Function_call(), and Function_toString().

◆ Function_toString()

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

Definition at line 284 of file function.c.

286{
287 FunctionInstance *function;
288 jsstr_t *str;
290
291 TRACE("\n");
292
293 if(!(function = function_this(jsthis)))
295
296 hres = function->vtbl->toString(function, &str);
297 if(FAILED(hres))
298 return hres;
299
300 if(r)
301 *r = jsval_string(str);
302 else
304 return S_OK;
305}

◆ Function_value()

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

Definition at line 471 of file function.c.

473{
474 FunctionInstance *function;
475
476 TRACE("\n");
477
478 if(!is_vclass(jsthis, JSCLASS_FUNCTION)) {
479 ERR("dispex is not a function\n");
480 return E_FAIL;
481 }
482
483 function = function_from_jsdisp(jsthis->u.jsdisp);
484 return function->vtbl->call(ctx, function, NULL, flags, argc, argv, r);
485}

◆ FunctionConstr_value()

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

Definition at line 976 of file function.c.

978{
980
981 TRACE("\n");
982
983 switch(flags) {
984 case DISPATCH_METHOD:
985 case DISPATCH_CONSTRUCT: {
986 IDispatch *ret;
987
989 if(FAILED(hres))
990 return hres;
991
992 *r = jsval_disp(ret);
993 break;
994 }
995 default:
996 FIXME("unimplemented flags %x\n", flags);
997 return E_NOTIMPL;
998 }
999
1000 return S_OK;
1001}
static HRESULT construct_function(script_ctx_t *ctx, unsigned argc, jsval_t *argv, IDispatch **ret)
Definition: function.c:894
static jsval_t jsval_disp(IDispatch *obj)
Definition: jsval.h:117

Referenced by init_function_constr().

◆ FunctionProt_value()

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

Definition at line 1003 of file function.c.

1005{
1006 FIXME("\n");
1007 return E_NOTIMPL;
1008}

Referenced by init_function_constr().

◆ get_argument_ref()

static jsval_t * get_argument_ref ( ArgumentsInstance arguments,
unsigned  idx 
)
static

Definition at line 133 of file function.c.

134{
135 if(arguments->buf)
136 return arguments->buf + idx;
137 if(arguments->frame->base_scope->frame || idx >= arguments->frame->function->param_cnt)
138 return arguments->jsdisp.ctx->stack + arguments->frame->arguments_off + idx;
139 return NULL;
140}

Referenced by Arguments_idx_get(), and Arguments_idx_put().

◆ init_function_constr()

HRESULT init_function_constr ( script_ctx_t ctx,
jsdisp_t object_prototype 
)

Definition at line 1010 of file function.c.

1011{
1012 NativeFunction *prot, *constr;
1013 HRESULT hres;
1014
1015 static const WCHAR FunctionW[] = {'F','u','n','c','t','i','o','n',0};
1016
1018 TRUE, object_prototype, (void**)&prot);
1019 if(FAILED(hres))
1020 return hres;
1021
1022 prot->proc = FunctionProt_value;
1023 prot->name = prototypeW;
1024
1026 TRUE, &prot->function.dispex, (void**)&constr);
1027 if(SUCCEEDED(hres)) {
1028 constr->proc = FunctionConstr_value;
1029 constr->name = FunctionW;
1031 if(SUCCEEDED(hres))
1033 if(FAILED(hres))
1034 jsdisp_release(&constr->function.dispex);
1035 }
1037 if(FAILED(hres))
1038 return hres;
1039
1040 ctx->function_constr = &constr->function.dispex;
1041 return S_OK;
1042}
#define TRUE
Definition: types.h:120
static const builtin_info_t Function_info
Definition: function.c:543
static HRESULT FunctionConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:976
static HRESULT FunctionProt_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:1003
static const WCHAR FunctionW[]
Definition: global.c:46

Referenced by init_constructors().

◆ InterpretedFunction_call()

static HRESULT InterpretedFunction_call ( script_ctx_t ctx,
FunctionInstance func,
IDispatch this_obj,
unsigned  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 706 of file function.c.

708{
710 jsdisp_t *var_disp, *new_obj = NULL;
711 DWORD exec_flags = 0;
713
714 TRACE("%p\n", function);
715
716 if(ctx->state == SCRIPTSTATE_UNINITIALIZED || ctx->state == SCRIPTSTATE_CLOSED) {
717 WARN("Script engine state does not allow running code.\n");
718 return E_UNEXPECTED;
719 }
720
721 if(flags & DISPATCH_CONSTRUCT) {
722 hres = create_object(ctx, &function->function.dispex, &new_obj);
723 if(FAILED(hres))
724 return hres;
725 this_obj = to_disp(new_obj);
726 }
727
729 exec_flags |= EXEC_RETURN_TO_INTERP;
730 if(flags & DISPATCH_CONSTRUCT)
731 exec_flags |= EXEC_CONSTRUCTOR;
732
733 hres = create_dispex(ctx, NULL, NULL, &var_disp);
734 if(SUCCEEDED(hres))
735 hres = exec_source(ctx, exec_flags, function->code, function->func_code, function->scope_chain, this_obj,
736 &function->function.dispex, var_disp, argc, argv, r);
737 if(new_obj)
738 jsdisp_release(new_obj);
739
740 jsdisp_release(var_disp);
741 return hres;
742}
@ SCRIPTSTATE_UNINITIALIZED
Definition: activscp.idl:57
@ SCRIPTSTATE_CLOSED
Definition: activscp.idl:61
#define WARN(fmt,...)
Definition: precomp.h:61
HRESULT exec_source(script_ctx_t *ctx, DWORD flags, bytecode_t *bytecode, function_code_t *function, scope_chain_t *scope, IDispatch *this_obj, jsdisp_t *function_instance, jsdisp_t *variable_obj, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: engine.c:2958
#define EXEC_RETURN_TO_INTERP
Definition: engine.h:250
#define EXEC_CONSTRUCTOR
Definition: engine.h:249
HRESULT create_dispex(script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *prototype, jsdisp_t **dispex)
Definition: dispex.c:957
#define DISPATCH_JSCRIPT_CALLEREXECSSOURCE
Definition: jscript.h:115

◆ InterpretedFunction_destructor()

static void InterpretedFunction_destructor ( FunctionInstance func)
static

Definition at line 752 of file function.c.

753{
755
756 release_bytecode(function->code);
757 if(function->scope_chain)
758 scope_release(function->scope_chain);
759}
void scope_release(scope_chain_t *scope)
Definition: engine.c:437

◆ InterpretedFunction_toString()

static HRESULT InterpretedFunction_toString ( FunctionInstance func,
jsstr_t **  ret 
)
static

Definition at line 744 of file function.c.

745{
747
748 *ret = jsstr_alloc_len(function->func_code->source, function->func_code->source_len);
749 return *ret ? S_OK : E_OUTOFMEMORY;
750}
jsstr_t * jsstr_alloc_len(const WCHAR *buf, unsigned len)
Definition: jsstr.c:86
unsigned source_len
Definition: engine.h:152
const WCHAR * source
Definition: engine.h:151

◆ NativeFunction_call()

static HRESULT NativeFunction_call ( script_ctx_t ctx,
FunctionInstance func,
IDispatch this_disp,
unsigned  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 595 of file function.c.

597{
598 NativeFunction *function = (NativeFunction*)func;
599 vdisp_t vthis;
601
602 if(this_disp)
603 set_disp(&vthis, this_disp);
604 else if(ctx->host_global)
605 set_disp(&vthis, ctx->host_global);
606 else
607 set_jsdisp(&vthis, ctx->global);
608
609 hres = function->proc(ctx, &vthis, flags & ~DISPATCH_JSCRIPT_INTERNAL_MASK, argc, argv, r);
610
611 vdisp_release(&vthis);
612 return hres;
613}
static void set_disp(vdisp_t *vdisp, IDispatch *disp)
Definition: jscript.h:174
static void set_jsdisp(vdisp_t *vdisp, jsdisp_t *jsdisp)
Definition: jscript.h:167
static void vdisp_release(vdisp_t *vdisp)
Definition: jscript.h:152
#define DISPATCH_JSCRIPT_INTERNAL_MASK
Definition: jscript.h:116

◆ NativeFunction_destructor()

static void NativeFunction_destructor ( FunctionInstance function)
static

Definition at line 641 of file function.c.

642{
643}

◆ NativeFunction_toString()

static HRESULT NativeFunction_toString ( FunctionInstance func,
jsstr_t **  ret 
)
static

Definition at line 615 of file function.c.

616{
617 NativeFunction *function = (NativeFunction*)func;
618 DWORD name_len;
619 jsstr_t *str;
620 WCHAR *ptr;
621
622 static const WCHAR native_prefixW[] = {'\n','f','u','n','c','t','i','o','n',' '};
623 static const WCHAR native_suffixW[] =
624 {'(',')',' ','{','\n',' ',' ',' ',' ','[','n','a','t','i','v','e',' ','c','o','d','e',']','\n','}','\n'};
625
626 name_len = function->name ? lstrlenW(function->name) : 0;
627 str = jsstr_alloc_buf(ARRAY_SIZE(native_prefixW) + ARRAY_SIZE(native_suffixW) + name_len, &ptr);
628 if(!str)
629 return E_OUTOFMEMORY;
630
631 memcpy(ptr, native_prefixW, sizeof(native_prefixW));
632 ptr += ARRAY_SIZE(native_prefixW);
633 memcpy(ptr, function->name, name_len*sizeof(WCHAR));
634 ptr += name_len;
635 memcpy(ptr, native_suffixW, sizeof(native_suffixW));
636
637 *ret = str;
638 return S_OK;
639}
#define lstrlenW
Definition: compat.h:750
jsstr_t * jsstr_alloc_buf(unsigned len, WCHAR **buf)
Definition: jsstr.c:69

◆ set_constructor_prop()

static HRESULT set_constructor_prop ( script_ctx_t ctx,
jsdisp_t constr,
jsdisp_t prot 
)
static

Definition at line 678 of file function.c.

679{
680 static const WCHAR constructorW[] = {'c','o','n','s','t','r','u','c','t','o','r',0};
681
683 jsval_obj(constr));
684}
#define PROPF_CONFIGURABLE
Definition: jscript.h:102

Referenced by create_builtin_constructor(), create_source_function(), and init_function_constr().

◆ setup_arguments_object()

HRESULT setup_arguments_object ( script_ctx_t ctx,
call_frame_t frame 
)

Definition at line 192 of file function.c.

193{
196
197 static const WCHAR caleeW[] = {'c','a','l','l','e','e',0};
198
199 args = heap_alloc_zero(sizeof(*args));
200 if(!args)
201 return E_OUTOFMEMORY;
202
203 hres = init_dispex_from_constr(&args->jsdisp, ctx, &Arguments_info, ctx->object_constr);
204 if(FAILED(hres)) {
206 return hres;
207 }
208
210 args->argc = frame->argc;
211 args->frame = frame;
212
214 jsval_number(args->argc));
215 if(SUCCEEDED(hres))
217 jsval_obj(&args->function->function.dispex));
218 if(SUCCEEDED(hres))
220 if(FAILED(hres)) {
221 jsdisp_release(&args->jsdisp);
222 return hres;
223 }
224
225 frame->arguments_obj = &args->jsdisp;
226 return S_OK;
227}
static const builtin_info_t Arguments_info
Definition: function.c:181
HRESULT jsdisp_propput(jsdisp_t *obj, const WCHAR *name, DWORD flags, jsval_t val)
Definition: dispex.c:1332
#define args
Definition: format.c:66
unsigned argc
Definition: engine.h:236

Referenced by detach_variable_object(), and Function_get_arguments().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( jscript  )

Variable Documentation

◆ applyW

const WCHAR applyW[] = {'a','p','p','l','y',0}
static

Definition at line 98 of file function.c.

◆ Arguments_info

const builtin_info_t Arguments_info
static
Initial value:
= {
0, NULL,
}
static HRESULT Arguments_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:103
static void Arguments_destructor(jsdisp_t *jsdisp)
Definition: function.c:110
static HRESULT Arguments_idx_get(jsdisp_t *jsdisp, unsigned idx, jsval_t *r)
Definition: function.c:142
static unsigned Arguments_idx_length(jsdisp_t *jsdisp)
Definition: function.c:127
static HRESULT Arguments_idx_put(jsdisp_t *jsdisp, unsigned idx, jsval_t val)
Definition: function.c:157

Definition at line 181 of file function.c.

Referenced by setup_arguments_object().

◆ argumentsW

const WCHAR argumentsW[] = {'a','r','g','u','m','e','n','t','s',0}
static

Definition at line 101 of file function.c.

Referenced by detach_arguments_object(), identifier_eval(), and setup_arguments_object().

◆ BindFunctionVtbl

const function_vtbl_t BindFunctionVtbl
static
Initial value:
= {
}
static void BindFunction_destructor(FunctionInstance *func)
Definition: function.c:845
static HRESULT BindFunction_call(script_ctx_t *ctx, FunctionInstance *func, IDispatch *this_obj, unsigned flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:806
static HRESULT BindFunction_toString(FunctionInstance *function, jsstr_t **ret)
Definition: function.c:834

Definition at line 858 of file function.c.

Referenced by create_bind_function().

◆ bindW

const WCHAR bindW[] = {'b','i','n','d',0}
static

Definition at line 99 of file function.c.

◆ callW

const WCHAR callW[] = {'c','a','l','l',0}
static

Definition at line 100 of file function.c.

◆ Function_info

const builtin_info_t Function_info
static
Initial value:
= {
}
static const builtin_prop_t Function_props[]
Definition: function.c:534
static void Function_destructor(jsdisp_t *dispex)
Definition: function.c:527
#define DEFAULT_FUNCTION_VALUE
Definition: jscript.h:315

Definition at line 543 of file function.c.

Referenced by init_function_constr().

◆ Function_props

const builtin_prop_t Function_props[]
static
Initial value:
= {
}
static const WCHAR callW[]
Definition: function.c:100
static HRESULT Function_get_arguments(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
Definition: function.c:503
static const WCHAR applyW[]
Definition: function.c:98
static const WCHAR toStringW[]
Definition: function.c:97
static HRESULT Function_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:284
static HRESULT Function_apply(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:343
static HRESULT Function_call(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:408
static HRESULT Function_bind(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:438
static HRESULT Function_get_length(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
Definition: function.c:276
static const WCHAR bindW[]
Definition: function.c:99
#define PROPF_ES5
Definition: jscript.h:108

Definition at line 534 of file function.c.

◆ FunctionInst_info

const builtin_info_t FunctionInst_info
static
Initial value:

Definition at line 557 of file function.c.

Referenced by create_function(), and init_function_constr().

◆ FunctionInst_props

const builtin_prop_t FunctionInst_props[]
static
Initial value:

Definition at line 552 of file function.c.

◆ InterpretedFunctionVtbl

const function_vtbl_t InterpretedFunctionVtbl
static
Initial value:
= {
}
static HRESULT InterpretedFunction_call(script_ctx_t *ctx, FunctionInstance *func, IDispatch *this_obj, unsigned flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:706
static HRESULT InterpretedFunction_toString(FunctionInstance *func, jsstr_t **ret)
Definition: function.c:744
static void InterpretedFunction_destructor(FunctionInstance *func)
Definition: function.c:752

Definition at line 761 of file function.c.

Referenced by create_source_function().

◆ lengthW

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

Definition at line 96 of file function.c.

Referenced by array_to_args(), create_builtin_function(), and setup_arguments_object().

◆ NativeFunctionVtbl

const function_vtbl_t NativeFunctionVtbl
static
Initial value:
= {
}
static void NativeFunction_destructor(FunctionInstance *function)
Definition: function.c:641
static HRESULT NativeFunction_toString(FunctionInstance *func, jsstr_t **ret)
Definition: function.c:615
static HRESULT NativeFunction_call(script_ctx_t *ctx, FunctionInstance *func, IDispatch *this_disp, unsigned flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:595

Definition at line 645 of file function.c.

Referenced by create_builtin_function(), and init_function_constr().

◆ prototypeW

const WCHAR prototypeW[] = {'p','r','o','t','o','t', 'y', 'p','e',0}
static

◆ toStringW

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

Definition at line 97 of file function.c.