From: "Gabriel Ivăncescu" Subject: [PATCH v3 02/11] jscript: Add a getter to obtain the function's code, if available. Message-Id: Date: Wed, 11 Dec 2019 16:08:23 +0200 In-Reply-To: <1303bac3ad3092538ac78d9257d3d976ff41f958.1576073190.git.gabrielopcode@gmail.com> References: <1303bac3ad3092538ac78d9257d3d976ff41f958.1576073190.git.gabrielopcode@gmail.com> Signed-off-by: Gabriel Ivăncescu --- dlls/jscript/function.c | 28 ++++++++++++++++++++++++++++ dlls/jscript/jscript.h | 1 + 2 files changed, 29 insertions(+) diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c index 7a44f50..3c3098f 100644 --- a/dlls/jscript/function.c +++ b/dlls/jscript/function.c @@ -37,6 +37,7 @@ typedef struct { struct _function_vtbl_t { HRESULT (*call)(script_ctx_t*,FunctionInstance*,IDispatch*,unsigned,unsigned,jsval_t*,jsval_t*); HRESULT (*toString)(FunctionInstance*,jsstr_t**); + function_code_t* (*get_code)(FunctionInstance*); void (*destructor)(FunctionInstance*); }; @@ -524,6 +525,13 @@ static HRESULT Function_get_arguments(script_ctx_t *ctx, jsdisp_t *jsthis, jsval return S_OK; } +function_code_t *Function_get_code(jsdisp_t *jsthis) +{ + FunctionInstance *function = function_from_jsdisp(jsthis); + + return function->vtbl->get_code(function); +} + static void Function_destructor(jsdisp_t *dispex) { FunctionInstance *function = function_from_jsdisp(dispex); @@ -638,6 +646,11 @@ static HRESULT NativeFunction_toString(FunctionInstance *func, jsstr_t **ret) return S_OK; } +static function_code_t *NativeFunction_get_code(FunctionInstance *function) +{ + return NULL; +} + static void NativeFunction_destructor(FunctionInstance *function) { } @@ -645,6 +658,7 @@ static void NativeFunction_destructor(FunctionInstance *function) static const function_vtbl_t NativeFunctionVtbl = { NativeFunction_call, NativeFunction_toString, + NativeFunction_get_code, NativeFunction_destructor }; @@ -749,6 +763,13 @@ static HRESULT InterpretedFunction_toString(FunctionInstance *func, jsstr_t **re return *ret ? S_OK : E_OUTOFMEMORY; } +static function_code_t *InterpretedFunction_get_code(FunctionInstance *func) +{ + InterpretedFunction *function = (InterpretedFunction*)func; + + return function->func_code; +} + static void InterpretedFunction_destructor(FunctionInstance *func) { InterpretedFunction *function = (InterpretedFunction*)func; @@ -761,6 +782,7 @@ static void InterpretedFunction_destructor(FunctionInstance *func) static const function_vtbl_t InterpretedFunctionVtbl = { InterpretedFunction_call, InterpretedFunction_toString, + InterpretedFunction_get_code, InterpretedFunction_destructor }; @@ -842,6 +864,11 @@ static HRESULT BindFunction_toString(FunctionInstance *function, jsstr_t **ret) return *ret ? S_OK : E_OUTOFMEMORY; } +static function_code_t *BindFunction_get_code(FunctionInstance *function) +{ + return NULL; +} + static void BindFunction_destructor(FunctionInstance *func) { BindFunction *function = (BindFunction*)func; @@ -858,6 +885,7 @@ static void BindFunction_destructor(FunctionInstance *func) static const function_vtbl_t BindFunctionVtbl = { BindFunction_call, BindFunction_toString, + BindFunction_get_code, BindFunction_destructor }; diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index 5d635b7..7174db8 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -307,6 +307,7 @@ HRESULT Function_invoke(jsdisp_t*,IDispatch*,WORD,unsigned,jsval_t*,jsval_t*) DE HRESULT Function_value(script_ctx_t*,vdisp_t*,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN; HRESULT Function_get_value(script_ctx_t*,jsdisp_t*,jsval_t*) DECLSPEC_HIDDEN; +struct _function_code_t *Function_get_code(jsdisp_t*) DECLSPEC_HIDDEN; #define DEFAULT_FUNCTION_VALUE {NULL, Function_value,0, Function_get_value} HRESULT throw_eval_error(script_ctx_t*,HRESULT,const WCHAR*) DECLSPEC_HIDDEN; -- 2.21.0