2008-03-16 21:10:13 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Jacek Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2011-02-21 17:49:15 +01:00
|
|
|
#include <assert.h>
|
|
|
|
|
2008-03-16 21:10:13 +01:00
|
|
|
#include "jscript.h"
|
2008-09-03 00:25:21 +02:00
|
|
|
#include "engine.h"
|
2008-03-21 13:03:07 +01:00
|
|
|
#include "objsafe.h"
|
2008-03-16 21:10:13 +01:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(jscript);
|
|
|
|
|
2009-02-02 15:27:24 +01:00
|
|
|
#ifdef _WIN64
|
|
|
|
|
|
|
|
#define CTXARG_T DWORDLONG
|
|
|
|
#define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
|
2009-02-09 21:11:36 +01:00
|
|
|
#define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_64Vtbl
|
2009-02-02 15:27:24 +01:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define CTXARG_T DWORD
|
|
|
|
#define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
|
2009-02-09 21:11:36 +01:00
|
|
|
#define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_32Vtbl
|
2009-02-02 15:27:24 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2008-03-16 21:10:13 +01:00
|
|
|
typedef struct {
|
2011-01-16 21:30:46 +01:00
|
|
|
IActiveScript IActiveScript_iface;
|
|
|
|
IActiveScriptParse IActiveScriptParse_iface;
|
|
|
|
IActiveScriptParseProcedure2 IActiveScriptParseProcedure2_iface;
|
|
|
|
IActiveScriptProperty IActiveScriptProperty_iface;
|
|
|
|
IObjectSafety IObjectSafety_iface;
|
2012-03-08 14:27:47 +01:00
|
|
|
IVariantChangeType IVariantChangeType_iface;
|
2008-03-16 21:10:13 +01:00
|
|
|
|
|
|
|
LONG ref;
|
2008-04-07 12:35:41 +02:00
|
|
|
|
|
|
|
DWORD safeopt;
|
2008-09-01 01:23:16 +02:00
|
|
|
script_ctx_t *ctx;
|
2008-09-01 01:17:14 +02:00
|
|
|
LONG thread_id;
|
2008-11-05 01:03:03 +01:00
|
|
|
LCID lcid;
|
2009-10-19 20:39:24 +02:00
|
|
|
DWORD version;
|
2018-03-01 19:18:26 +01:00
|
|
|
BOOL html_mode;
|
2012-03-26 11:41:56 +02:00
|
|
|
BOOL is_encode;
|
2020-02-20 21:26:38 +01:00
|
|
|
BOOL is_initialized;
|
2008-09-01 01:17:14 +02:00
|
|
|
|
|
|
|
IActiveScriptSite *site;
|
2008-09-05 02:37:59 +02:00
|
|
|
|
2019-11-07 18:17:13 +01:00
|
|
|
struct list persistent_code;
|
2019-11-07 18:17:06 +01:00
|
|
|
struct list queued_code;
|
2008-03-16 21:10:13 +01:00
|
|
|
} JScript;
|
|
|
|
|
2020-01-30 15:50:47 +01:00
|
|
|
typedef struct {
|
|
|
|
IActiveScriptError IActiveScriptError_iface;
|
|
|
|
LONG ref;
|
|
|
|
jsexcept_t ei;
|
|
|
|
} JScriptError;
|
|
|
|
|
2008-09-01 01:23:16 +02:00
|
|
|
void script_release(script_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
if(--ctx->ref)
|
|
|
|
return;
|
|
|
|
|
2018-06-12 14:04:11 +02:00
|
|
|
jsval_release(ctx->acc);
|
2010-12-28 15:40:00 +01:00
|
|
|
if(ctx->cc)
|
|
|
|
release_cc(ctx->cc);
|
2013-02-15 14:04:14 +01:00
|
|
|
heap_pool_free(&ctx->tmp_heap);
|
2012-10-11 12:16:01 +02:00
|
|
|
if(ctx->last_match)
|
|
|
|
jsstr_release(ctx->last_match);
|
2016-03-25 17:49:24 +01:00
|
|
|
assert(!ctx->stack_top);
|
|
|
|
heap_free(ctx->stack);
|
2012-03-08 14:27:47 +01:00
|
|
|
|
2012-03-12 12:12:40 +01:00
|
|
|
ctx->jscaller->ctx = NULL;
|
2012-03-08 14:28:16 +01:00
|
|
|
IServiceProvider_Release(&ctx->jscaller->IServiceProvider_iface);
|
|
|
|
|
2008-09-01 01:23:16 +02:00
|
|
|
heap_free(ctx);
|
|
|
|
}
|
|
|
|
|
2008-09-01 01:17:14 +02:00
|
|
|
static void change_state(JScript *This, SCRIPTSTATE state)
|
|
|
|
{
|
|
|
|
if(This->ctx->state == state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
This->ctx->state = state;
|
2011-02-21 17:49:15 +01:00
|
|
|
if(This->site)
|
|
|
|
IActiveScriptSite_OnStateChange(This->site, state);
|
2008-09-01 01:17:14 +02:00
|
|
|
}
|
|
|
|
|
2008-09-05 02:37:59 +02:00
|
|
|
static inline BOOL is_started(script_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
return ctx->state == SCRIPTSTATE_STARTED
|
|
|
|
|| ctx->state == SCRIPTSTATE_CONNECTED
|
|
|
|
|| ctx->state == SCRIPTSTATE_DISCONNECTED;
|
|
|
|
}
|
|
|
|
|
2020-03-07 14:40:32 +01:00
|
|
|
HRESULT create_named_item_script_obj(script_ctx_t *ctx, named_item_t *item)
|
|
|
|
{
|
2020-03-18 14:19:50 +01:00
|
|
|
static const builtin_info_t disp_info = {
|
|
|
|
JSCLASS_GLOBAL,
|
2021-11-25 21:01:37 +01:00
|
|
|
NULL,
|
2020-03-18 14:19:50 +01:00
|
|
|
0, NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
return create_dispex(ctx, &disp_info, NULL, &item->script_obj);
|
2020-03-07 14:40:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void release_named_item_script_obj(named_item_t *item)
|
|
|
|
{
|
|
|
|
if(!item->script_obj) return;
|
|
|
|
|
|
|
|
jsdisp_release(item->script_obj);
|
|
|
|
item->script_obj = NULL;
|
|
|
|
}
|
|
|
|
|
2020-03-24 17:49:56 +01:00
|
|
|
static HRESULT retrieve_named_item_disp(IActiveScriptSite *site, named_item_t *item)
|
|
|
|
{
|
|
|
|
IUnknown *unk;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if(!site)
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
|
|
|
hr = IActiveScriptSite_GetItemInfo(site, item->name, SCRIPTINFO_IUNKNOWN, &unk, NULL);
|
|
|
|
if(FAILED(hr)) {
|
|
|
|
WARN("GetItemInfo failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&item->disp);
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
if(FAILED(hr)) {
|
|
|
|
WARN("object does not implement IDispatch\n");
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-02-20 21:26:49 +01:00
|
|
|
named_item_t *lookup_named_item(script_ctx_t *ctx, const WCHAR *item_name, unsigned flags)
|
|
|
|
{
|
|
|
|
named_item_t *item;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2020-03-05 17:11:56 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(item, &ctx->named_items, named_item_t, entry) {
|
2020-02-20 21:26:49 +01:00
|
|
|
if((item->flags & flags) == flags && !wcscmp(item->name, item_name)) {
|
2020-03-07 14:40:32 +01:00
|
|
|
if(!item->script_obj && !(item->flags & SCRIPTITEM_GLOBALMEMBERS)) {
|
|
|
|
hr = create_named_item_script_obj(ctx, item);
|
|
|
|
if(FAILED(hr)) return NULL;
|
|
|
|
}
|
2020-03-24 17:49:56 +01:00
|
|
|
|
2020-02-20 21:26:54 +01:00
|
|
|
if(!item->disp && (flags || !(item->flags & SCRIPTITEM_CODEONLY))) {
|
2020-03-24 17:49:56 +01:00
|
|
|
hr = retrieve_named_item_disp(ctx->site, item);
|
|
|
|
if(FAILED(hr)) continue;
|
2020-02-20 21:26:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-02-26 13:41:24 +01:00
|
|
|
void release_named_item(named_item_t *item)
|
|
|
|
{
|
|
|
|
if(--item->ref) return;
|
|
|
|
|
|
|
|
heap_free(item->name);
|
|
|
|
heap_free(item);
|
|
|
|
}
|
|
|
|
|
2020-01-30 15:50:47 +01:00
|
|
|
static inline JScriptError *impl_from_IActiveScriptError(IActiveScriptError *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, JScriptError, IActiveScriptError_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScriptError_QueryInterface(IActiveScriptError *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
JScriptError *This = impl_from_IActiveScriptError(iface);
|
|
|
|
|
|
|
|
if(IsEqualGUID(riid, &IID_IUnknown)) {
|
|
|
|
TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
|
|
|
|
*ppv = &This->IActiveScriptError_iface;
|
|
|
|
}else if(IsEqualGUID(riid, &IID_IActiveScriptError)) {
|
|
|
|
TRACE("(%p)->(IID_IActiveScriptError %p)\n", This, ppv);
|
|
|
|
*ppv = &This->IActiveScriptError_iface;
|
|
|
|
}else {
|
|
|
|
FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI JScriptError_AddRef(IActiveScriptError *iface)
|
|
|
|
{
|
|
|
|
JScriptError *This = impl_from_IActiveScriptError(iface);
|
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI JScriptError_Release(IActiveScriptError *iface)
|
|
|
|
{
|
|
|
|
JScriptError *This = impl_from_IActiveScriptError(iface);
|
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
if(!ref) {
|
|
|
|
reset_ei(&This->ei);
|
|
|
|
heap_free(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScriptError_GetExceptionInfo(IActiveScriptError *iface, EXCEPINFO *excepinfo)
|
|
|
|
{
|
|
|
|
JScriptError *This = impl_from_IActiveScriptError(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, excepinfo);
|
|
|
|
|
|
|
|
if(!excepinfo)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
memset(excepinfo, 0, sizeof(*excepinfo));
|
|
|
|
excepinfo->scode = This->ei.error;
|
2020-02-03 14:47:59 +01:00
|
|
|
if(This->ei.source)
|
|
|
|
jsstr_to_bstr(This->ei.source, &excepinfo->bstrSource);
|
|
|
|
if(This->ei.message)
|
|
|
|
jsstr_to_bstr(This->ei.message, &excepinfo->bstrDescription);
|
2020-01-30 15:50:47 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScriptError_GetSourcePosition(IActiveScriptError *iface, DWORD *source_context, ULONG *line, LONG *character)
|
|
|
|
{
|
|
|
|
JScriptError *This = impl_from_IActiveScriptError(iface);
|
2020-02-03 14:48:07 +01:00
|
|
|
bytecode_t *code = This->ei.code;
|
2021-03-10 14:59:57 +01:00
|
|
|
unsigned line_pos, char_pos;
|
2020-01-30 15:50:47 +01:00
|
|
|
|
2020-02-03 14:48:07 +01:00
|
|
|
TRACE("(%p)->(%p %p %p)\n", This, source_context, line, character);
|
|
|
|
|
|
|
|
if(!This->ei.code) {
|
|
|
|
FIXME("unknown position\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2020-01-30 15:50:47 +01:00
|
|
|
|
|
|
|
if(source_context)
|
2020-02-03 14:48:07 +01:00
|
|
|
*source_context = This->ei.code->source_context;
|
|
|
|
if(!line && !character)
|
|
|
|
return S_OK;
|
|
|
|
|
2021-03-10 14:59:57 +01:00
|
|
|
line_pos = get_location_line(code, This->ei.loc, &char_pos);
|
2020-01-30 15:50:47 +01:00
|
|
|
if(line)
|
2021-03-10 14:59:57 +01:00
|
|
|
*line = line_pos;
|
2020-01-30 15:50:47 +01:00
|
|
|
if(character)
|
2021-03-10 14:59:57 +01:00
|
|
|
*character = char_pos;
|
2020-01-30 15:50:47 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScriptError_GetSourceLineText(IActiveScriptError *iface, BSTR *source)
|
|
|
|
{
|
|
|
|
JScriptError *This = impl_from_IActiveScriptError(iface);
|
|
|
|
|
2020-02-04 20:28:38 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, source);
|
2020-01-30 15:50:47 +01:00
|
|
|
|
|
|
|
if(!source)
|
|
|
|
return E_POINTER;
|
2020-02-04 20:28:38 +01:00
|
|
|
|
|
|
|
if(!This->ei.line) {
|
|
|
|
*source = NULL;
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jsstr_to_bstr(This->ei.line, source);
|
2020-01-30 15:50:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IActiveScriptErrorVtbl JScriptErrorVtbl = {
|
|
|
|
JScriptError_QueryInterface,
|
|
|
|
JScriptError_AddRef,
|
|
|
|
JScriptError_Release,
|
|
|
|
JScriptError_GetExceptionInfo,
|
|
|
|
JScriptError_GetSourcePosition,
|
|
|
|
JScriptError_GetSourceLineText
|
|
|
|
};
|
|
|
|
|
2020-01-30 15:50:15 +01:00
|
|
|
void reset_ei(jsexcept_t *ei)
|
|
|
|
{
|
2020-01-30 15:50:33 +01:00
|
|
|
ei->error = S_OK;
|
2020-01-30 15:50:22 +01:00
|
|
|
if(ei->valid_value) {
|
|
|
|
jsval_release(ei->value);
|
|
|
|
ei->valid_value = FALSE;
|
|
|
|
}
|
2020-02-03 14:47:15 +01:00
|
|
|
if(ei->code) {
|
|
|
|
release_bytecode(ei->code);
|
|
|
|
ei->code = NULL;
|
|
|
|
ei->loc = 0;
|
|
|
|
}
|
|
|
|
if(ei->source) {
|
|
|
|
jsstr_release(ei->source);
|
|
|
|
ei->source = NULL;
|
|
|
|
}
|
2020-02-03 14:47:25 +01:00
|
|
|
if(ei->message) {
|
|
|
|
jsstr_release(ei->message);
|
|
|
|
ei->message = NULL;
|
|
|
|
}
|
2020-02-04 20:28:38 +01:00
|
|
|
if(ei->line) {
|
|
|
|
jsstr_release(ei->line);
|
|
|
|
ei->line = NULL;
|
|
|
|
}
|
2020-01-30 15:50:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void enter_script(script_ctx_t *ctx, jsexcept_t *ei)
|
|
|
|
{
|
|
|
|
memset(ei, 0, sizeof(*ei));
|
|
|
|
ei->prev = ctx->ei;
|
|
|
|
ctx->ei = ei;
|
|
|
|
TRACE("ctx %p ei %p prev %p\n", ctx, ei, ei->prev);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT leave_script(script_ctx_t *ctx, HRESULT result)
|
|
|
|
{
|
|
|
|
jsexcept_t *ei = ctx->ei;
|
2020-02-20 21:28:01 +01:00
|
|
|
BOOL enter_notified = ei->enter_notified;
|
2020-01-30 15:50:47 +01:00
|
|
|
JScriptError *error;
|
2020-01-30 15:50:15 +01:00
|
|
|
|
|
|
|
TRACE("ctx %p ei %p prev %p\n", ctx, ei, ei->prev);
|
|
|
|
|
|
|
|
ctx->ei = ei->prev;
|
2020-01-30 15:50:47 +01:00
|
|
|
if(result == DISP_E_EXCEPTION) {
|
2020-01-30 15:50:33 +01:00
|
|
|
result = ei->error;
|
2020-01-30 15:50:47 +01:00
|
|
|
}else {
|
|
|
|
reset_ei(ei);
|
|
|
|
ei->error = result;
|
|
|
|
}
|
|
|
|
if(FAILED(result)) {
|
2020-01-30 15:50:15 +01:00
|
|
|
WARN("%08x\n", result);
|
2020-01-30 15:50:47 +01:00
|
|
|
if(ctx->site && (error = heap_alloc(sizeof(*error)))) {
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
error->IActiveScriptError_iface.lpVtbl = &JScriptErrorVtbl;
|
|
|
|
error->ref = 1;
|
|
|
|
error->ei = *ei;
|
|
|
|
memset(ei, 0, sizeof(*ei));
|
|
|
|
|
|
|
|
hres = IActiveScriptSite_OnScriptError(ctx->site, &error->IActiveScriptError_iface);
|
|
|
|
IActiveScriptError_Release(&error->IActiveScriptError_iface);
|
|
|
|
if(hres == S_OK)
|
|
|
|
result = SCRIPT_E_REPORTED;
|
|
|
|
}
|
|
|
|
}
|
2020-02-20 21:28:01 +01:00
|
|
|
if(enter_notified && ctx->site)
|
2020-01-30 15:50:39 +01:00
|
|
|
IActiveScriptSite_OnLeaveScript(ctx->site);
|
2020-01-30 15:50:15 +01:00
|
|
|
reset_ei(ei);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-09-05 02:37:59 +02:00
|
|
|
static void clear_script_queue(JScript *This)
|
|
|
|
{
|
2019-11-07 18:17:06 +01:00
|
|
|
while(!list_empty(&This->queued_code))
|
|
|
|
{
|
|
|
|
bytecode_t *iter = LIST_ENTRY(list_head(&This->queued_code), bytecode_t, entry);
|
|
|
|
list_remove(&iter->entry);
|
2019-11-07 18:17:13 +01:00
|
|
|
if (iter->is_persistent)
|
|
|
|
list_add_tail(&This->persistent_code, &iter->entry);
|
|
|
|
else
|
|
|
|
release_bytecode(iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void clear_persistent_code_list(JScript *This)
|
|
|
|
{
|
2019-11-14 17:11:09 +01:00
|
|
|
while(!list_empty(&This->persistent_code))
|
2019-11-07 18:17:13 +01:00
|
|
|
{
|
|
|
|
bytecode_t *iter = LIST_ENTRY(list_head(&This->persistent_code), bytecode_t, entry);
|
|
|
|
list_remove(&iter->entry);
|
2012-03-12 19:24:22 +01:00
|
|
|
release_bytecode(iter);
|
2008-09-05 02:37:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-07 14:40:32 +01:00
|
|
|
static void release_persistent_script_objs(JScript *This)
|
|
|
|
{
|
|
|
|
bytecode_t *iter;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(iter, &This->persistent_code, bytecode_t, entry)
|
|
|
|
if(iter->named_item)
|
|
|
|
release_named_item_script_obj(iter->named_item);
|
|
|
|
}
|
|
|
|
|
2020-03-24 17:49:57 +01:00
|
|
|
static void release_named_item_list(JScript *This)
|
|
|
|
{
|
|
|
|
while(!list_empty(&This->ctx->named_items)) {
|
|
|
|
named_item_t *iter = LIST_ENTRY(list_head(&This->ctx->named_items), named_item_t, entry);
|
|
|
|
list_remove(&iter->entry);
|
|
|
|
release_named_item(iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-05 02:38:17 +02:00
|
|
|
static void exec_queued_code(JScript *This)
|
|
|
|
{
|
2012-03-12 19:24:22 +01:00
|
|
|
bytecode_t *iter;
|
2020-01-30 15:50:15 +01:00
|
|
|
jsexcept_t ei;
|
2020-01-30 15:50:47 +01:00
|
|
|
HRESULT hres = S_OK;
|
2008-09-05 02:38:17 +02:00
|
|
|
|
2020-01-30 15:50:15 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(iter, &This->queued_code, bytecode_t, entry) {
|
|
|
|
enter_script(This->ctx, &ei);
|
2020-03-17 19:19:25 +01:00
|
|
|
hres = exec_source(This->ctx, EXEC_GLOBAL, iter, &iter->global_code, NULL, NULL, NULL, 0, NULL, NULL);
|
2020-01-30 15:50:15 +01:00
|
|
|
leave_script(This->ctx, hres);
|
2020-01-30 15:50:47 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
2020-01-30 15:50:15 +01:00
|
|
|
}
|
2008-09-05 02:38:17 +02:00
|
|
|
|
|
|
|
clear_script_queue(This);
|
|
|
|
}
|
|
|
|
|
2011-02-21 17:49:15 +01:00
|
|
|
static void decrease_state(JScript *This, SCRIPTSTATE state)
|
|
|
|
{
|
2020-03-24 17:49:57 +01:00
|
|
|
named_item_t *item, *item_next;
|
|
|
|
|
2011-02-21 17:49:15 +01:00
|
|
|
if(This->ctx) {
|
|
|
|
switch(This->ctx->state) {
|
|
|
|
case SCRIPTSTATE_CONNECTED:
|
|
|
|
change_state(This, SCRIPTSTATE_DISCONNECTED);
|
|
|
|
if(state == SCRIPTSTATE_DISCONNECTED)
|
|
|
|
return;
|
2011-03-18 01:50:23 +01:00
|
|
|
/* FALLTHROUGH */
|
2011-02-21 17:49:15 +01:00
|
|
|
case SCRIPTSTATE_STARTED:
|
|
|
|
case SCRIPTSTATE_DISCONNECTED:
|
|
|
|
clear_script_queue(This);
|
|
|
|
|
|
|
|
if(This->ctx->state == SCRIPTSTATE_DISCONNECTED)
|
|
|
|
change_state(This, SCRIPTSTATE_INITIALIZED);
|
|
|
|
if(state == SCRIPTSTATE_INITIALIZED)
|
|
|
|
return;
|
2011-03-18 01:50:23 +01:00
|
|
|
/* FALLTHROUGH */
|
2011-02-21 17:49:15 +01:00
|
|
|
case SCRIPTSTATE_INITIALIZED:
|
2020-02-20 21:26:41 +01:00
|
|
|
clear_script_queue(This);
|
2020-03-07 14:40:32 +01:00
|
|
|
release_persistent_script_objs(This);
|
2020-02-20 21:26:41 +01:00
|
|
|
|
2020-03-24 17:49:57 +01:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(item, item_next, &This->ctx->named_items, named_item_t, entry)
|
|
|
|
{
|
|
|
|
if(item->disp)
|
|
|
|
{
|
|
|
|
IDispatch_Release(item->disp);
|
|
|
|
item->disp = NULL;
|
|
|
|
}
|
|
|
|
release_named_item_script_obj(item);
|
|
|
|
if(!(item->flags & SCRIPTITEM_ISPERSISTENT))
|
|
|
|
{
|
|
|
|
list_remove(&item->entry);
|
|
|
|
release_named_item(item);
|
|
|
|
}
|
2011-02-21 17:49:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(This->ctx->secmgr) {
|
|
|
|
IInternetHostSecurityManager_Release(This->ctx->secmgr);
|
|
|
|
This->ctx->secmgr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(This->ctx->site) {
|
|
|
|
IActiveScriptSite_Release(This->ctx->site);
|
|
|
|
This->ctx->site = NULL;
|
|
|
|
}
|
|
|
|
|
2021-04-27 18:11:37 +02:00
|
|
|
if(This->ctx->map_prototype) {
|
|
|
|
jsdisp_release(This->ctx->map_prototype);
|
|
|
|
This->ctx->map_prototype = NULL;
|
|
|
|
}
|
|
|
|
|
2021-04-22 01:47:35 +02:00
|
|
|
if(This->ctx->set_prototype) {
|
|
|
|
jsdisp_release(This->ctx->set_prototype);
|
|
|
|
This->ctx->set_prototype = NULL;
|
|
|
|
}
|
|
|
|
|
2021-03-11 17:01:08 +01:00
|
|
|
if(This->ctx->object_prototype) {
|
|
|
|
jsdisp_release(This->ctx->object_prototype);
|
|
|
|
This->ctx->object_prototype = NULL;
|
|
|
|
}
|
|
|
|
|
2011-02-21 17:49:15 +01:00
|
|
|
if(This->ctx->global) {
|
|
|
|
jsdisp_release(This->ctx->global);
|
|
|
|
This->ctx->global = NULL;
|
|
|
|
}
|
2011-03-18 01:50:23 +01:00
|
|
|
/* FALLTHROUGH */
|
2011-02-21 17:49:15 +01:00
|
|
|
case SCRIPTSTATE_UNINITIALIZED:
|
|
|
|
change_state(This, state);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
change_state(This, state);
|
|
|
|
}else if(state == SCRIPTSTATE_UNINITIALIZED) {
|
|
|
|
if(This->site)
|
|
|
|
IActiveScriptSite_OnStateChange(This->site, state);
|
|
|
|
}else {
|
|
|
|
FIXME("NULL ctx\n");
|
|
|
|
}
|
|
|
|
|
2019-11-06 16:28:00 +01:00
|
|
|
if(state == SCRIPTSTATE_UNINITIALIZED || state == SCRIPTSTATE_CLOSED)
|
2011-02-21 17:49:15 +01:00
|
|
|
This->thread_id = 0;
|
|
|
|
|
|
|
|
if(This->site) {
|
|
|
|
IActiveScriptSite_Release(This->site);
|
|
|
|
This->site = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-06 21:23:14 +02:00
|
|
|
typedef struct {
|
2011-01-16 21:32:07 +01:00
|
|
|
IServiceProvider IServiceProvider_iface;
|
2009-10-06 21:23:14 +02:00
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
IServiceProvider *sp;
|
|
|
|
} AXSite;
|
|
|
|
|
2011-01-16 21:32:07 +01:00
|
|
|
static inline AXSite *impl_from_IServiceProvider(IServiceProvider *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, AXSite, IServiceProvider_iface);
|
|
|
|
}
|
2009-10-06 21:23:14 +02:00
|
|
|
|
|
|
|
static HRESULT WINAPI AXSite_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-16 21:32:07 +01:00
|
|
|
AXSite *This = impl_from_IServiceProvider(iface);
|
2009-10-06 21:23:14 +02:00
|
|
|
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
|
2011-01-16 21:32:07 +01:00
|
|
|
*ppv = &This->IServiceProvider_iface;
|
2009-10-06 21:23:14 +02:00
|
|
|
}else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
|
2011-01-16 21:32:07 +01:00
|
|
|
*ppv = &This->IServiceProvider_iface;
|
2009-10-06 21:23:14 +02:00
|
|
|
}else {
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI AXSite_AddRef(IServiceProvider *iface)
|
|
|
|
{
|
2011-01-16 21:32:07 +01:00
|
|
|
AXSite *This = impl_from_IServiceProvider(iface);
|
2009-10-06 21:23:14 +02:00
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI AXSite_Release(IServiceProvider *iface)
|
|
|
|
{
|
2011-01-16 21:32:07 +01:00
|
|
|
AXSite *This = impl_from_IServiceProvider(iface);
|
2009-10-06 21:23:14 +02:00
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
if(!ref)
|
2012-01-23 02:21:23 +01:00
|
|
|
{
|
|
|
|
if(This->sp)
|
|
|
|
IServiceProvider_Release(This->sp);
|
|
|
|
|
2009-10-06 21:23:14 +02:00
|
|
|
heap_free(This);
|
2012-01-23 02:21:23 +01:00
|
|
|
}
|
2009-10-06 21:23:14 +02:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AXSite_QueryService(IServiceProvider *iface,
|
|
|
|
REFGUID guidService, REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-16 21:32:07 +01:00
|
|
|
AXSite *This = impl_from_IServiceProvider(iface);
|
2009-10-06 21:23:14 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
|
|
|
|
|
2012-01-23 02:21:23 +01:00
|
|
|
if(!This->sp)
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
2009-10-06 21:23:14 +02:00
|
|
|
return IServiceProvider_QueryService(This->sp, guidService, riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static IServiceProviderVtbl AXSiteVtbl = {
|
|
|
|
AXSite_QueryInterface,
|
|
|
|
AXSite_AddRef,
|
|
|
|
AXSite_Release,
|
|
|
|
AXSite_QueryService
|
|
|
|
};
|
|
|
|
|
|
|
|
IUnknown *create_ax_site(script_ctx_t *ctx)
|
|
|
|
{
|
2012-01-23 02:21:23 +01:00
|
|
|
IServiceProvider *sp = NULL;
|
2009-10-06 21:23:14 +02:00
|
|
|
AXSite *ret;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = IActiveScriptSite_QueryInterface(ctx->site, &IID_IServiceProvider, (void**)&sp);
|
|
|
|
if(FAILED(hres)) {
|
2012-01-23 02:21:23 +01:00
|
|
|
TRACE("Could not get IServiceProvider iface: %08x\n", hres);
|
2009-10-06 21:23:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = heap_alloc(sizeof(AXSite));
|
|
|
|
if(!ret) {
|
|
|
|
IServiceProvider_Release(sp);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-01-16 21:32:07 +01:00
|
|
|
ret->IServiceProvider_iface.lpVtbl = &AXSiteVtbl;
|
2009-10-06 21:23:14 +02:00
|
|
|
ret->ref = 1;
|
|
|
|
ret->sp = sp;
|
|
|
|
|
2011-01-16 21:32:07 +01:00
|
|
|
return (IUnknown*)&ret->IServiceProvider_iface;
|
2009-10-06 21:23:14 +02:00
|
|
|
}
|
|
|
|
|
2011-01-16 21:30:46 +01:00
|
|
|
static inline JScript *impl_from_IActiveScript(IActiveScript *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, JScript, IActiveScript_iface);
|
|
|
|
}
|
2008-03-16 21:10:13 +01:00
|
|
|
|
|
|
|
static HRESULT WINAPI JScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScript(iface);
|
2008-03-16 21:10:13 +01:00
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if(IsEqualGUID(riid, &IID_IUnknown)) {
|
|
|
|
TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
|
2011-01-16 21:30:46 +01:00
|
|
|
*ppv = &This->IActiveScript_iface;
|
2008-03-16 21:10:13 +01:00
|
|
|
}else if(IsEqualGUID(riid, &IID_IActiveScript)) {
|
|
|
|
TRACE("(%p)->(IID_IActiveScript %p)\n", This, ppv);
|
2011-01-16 21:30:46 +01:00
|
|
|
*ppv = &This->IActiveScript_iface;
|
2008-03-19 11:31:36 +01:00
|
|
|
}else if(IsEqualGUID(riid, &IID_IActiveScriptParse)) {
|
|
|
|
TRACE("(%p)->(IID_IActiveScriptParse %p)\n", This, ppv);
|
2011-01-16 21:30:46 +01:00
|
|
|
*ppv = &This->IActiveScriptParse_iface;
|
2008-03-21 13:02:46 +01:00
|
|
|
}else if(IsEqualGUID(riid, &IID_IActiveScriptParseProcedure)) {
|
|
|
|
TRACE("(%p)->(IID_IActiveScriptParseProcedure %p)\n", This, ppv);
|
2011-01-16 21:30:46 +01:00
|
|
|
*ppv = &This->IActiveScriptParseProcedure2_iface;
|
2008-03-21 13:02:46 +01:00
|
|
|
}else if(IsEqualGUID(riid, &IID_IActiveScriptParseProcedure2)) {
|
|
|
|
TRACE("(%p)->(IID_IActiveScriptParseProcedure2 %p)\n", This, ppv);
|
2011-01-16 21:30:46 +01:00
|
|
|
*ppv = &This->IActiveScriptParseProcedure2_iface;
|
2008-03-19 11:31:54 +01:00
|
|
|
}else if(IsEqualGUID(riid, &IID_IActiveScriptProperty)) {
|
|
|
|
TRACE("(%p)->(IID_IActiveScriptProperty %p)\n", This, ppv);
|
2011-01-16 21:30:46 +01:00
|
|
|
*ppv = &This->IActiveScriptProperty_iface;
|
2008-03-21 13:03:07 +01:00
|
|
|
}else if(IsEqualGUID(riid, &IID_IObjectSafety)) {
|
|
|
|
TRACE("(%p)->(IID_IObjectSafety %p)\n", This, ppv);
|
2011-01-16 21:30:46 +01:00
|
|
|
*ppv = &This->IObjectSafety_iface;
|
2012-03-08 14:27:47 +01:00
|
|
|
}else if(IsEqualGUID(riid, &IID_IVariantChangeType)) {
|
|
|
|
TRACE("(%p)->(IID_IVariantChangeType %p)\n", This, ppv);
|
|
|
|
*ppv = &This->IVariantChangeType_iface;
|
2008-03-16 21:10:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(*ppv) {
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI JScript_AddRef(IActiveScript *iface)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScript(iface);
|
2008-03-16 21:10:13 +01:00
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI JScript_Release(IActiveScript *iface)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScript(iface);
|
2008-03-16 21:10:13 +01:00
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", iface, ref);
|
|
|
|
|
2008-03-24 21:53:34 +01:00
|
|
|
if(!ref) {
|
2008-09-01 01:17:53 +02:00
|
|
|
if(This->ctx && This->ctx->state != SCRIPTSTATE_CLOSED)
|
2011-01-16 21:30:46 +01:00
|
|
|
IActiveScript_Close(&This->IActiveScript_iface);
|
2012-03-12 12:12:40 +01:00
|
|
|
if(This->ctx) {
|
|
|
|
This->ctx->active_script = NULL;
|
2008-09-01 01:23:16 +02:00
|
|
|
script_release(This->ctx);
|
2012-03-12 12:12:40 +01:00
|
|
|
}
|
2008-03-16 21:10:13 +01:00
|
|
|
heap_free(This);
|
2008-03-24 21:53:34 +01:00
|
|
|
unlock_module();
|
|
|
|
}
|
2008-03-16 21:10:13 +01:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScript_SetScriptSite(IActiveScript *iface,
|
|
|
|
IActiveScriptSite *pass)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScript(iface);
|
2020-03-24 17:49:57 +01:00
|
|
|
named_item_t *item;
|
2008-09-01 01:17:14 +02:00
|
|
|
LCID lcid;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, pass);
|
|
|
|
|
|
|
|
if(!pass)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
if(This->site)
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
|
|
|
if(InterlockedCompareExchange(&This->thread_id, GetCurrentThreadId(), 0))
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
2020-02-20 21:26:38 +01:00
|
|
|
if(!This->ctx) {
|
|
|
|
script_ctx_t *ctx = heap_alloc_zero(sizeof(script_ctx_t));
|
|
|
|
if(!ctx)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
ctx->ref = 1;
|
|
|
|
ctx->state = SCRIPTSTATE_UNINITIALIZED;
|
|
|
|
ctx->active_script = &This->IActiveScript_iface;
|
|
|
|
ctx->safeopt = This->safeopt;
|
|
|
|
ctx->version = This->version;
|
|
|
|
ctx->html_mode = This->html_mode;
|
|
|
|
ctx->acc = jsval_undefined();
|
2020-03-05 17:11:56 +01:00
|
|
|
list_init(&ctx->named_items);
|
2020-02-20 21:26:38 +01:00
|
|
|
heap_pool_init(&ctx->tmp_heap);
|
|
|
|
|
|
|
|
hres = create_jscaller(ctx);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
heap_free(ctx);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->last_match = jsstr_empty();
|
|
|
|
|
|
|
|
ctx = InterlockedCompareExchangePointer((void**)&This->ctx, ctx, NULL);
|
|
|
|
if(ctx) {
|
|
|
|
script_release(ctx);
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-24 17:49:57 +01:00
|
|
|
/* Retrieve new dispatches for persistent named items */
|
|
|
|
LIST_FOR_EACH_ENTRY(item, &This->ctx->named_items, named_item_t, entry)
|
|
|
|
{
|
|
|
|
if(!item->disp)
|
|
|
|
{
|
|
|
|
hres = retrieve_named_item_disp(pass, item);
|
|
|
|
if(FAILED(hres)) return hres;
|
|
|
|
}
|
2020-03-27 18:34:56 +01:00
|
|
|
|
|
|
|
/* For some reason, CODEONLY flag is lost in re-initialized scripts */
|
|
|
|
item->flags &= ~SCRIPTITEM_CODEONLY;
|
2020-03-24 17:49:57 +01:00
|
|
|
}
|
|
|
|
|
2008-09-01 01:17:14 +02:00
|
|
|
This->site = pass;
|
|
|
|
IActiveScriptSite_AddRef(This->site);
|
|
|
|
|
|
|
|
hres = IActiveScriptSite_GetLCID(This->site, &lcid);
|
|
|
|
if(hres == S_OK)
|
2008-11-21 19:33:03 +01:00
|
|
|
This->lcid = lcid;
|
2008-09-01 01:17:14 +02:00
|
|
|
|
2020-02-20 21:26:38 +01:00
|
|
|
This->ctx->lcid = This->lcid;
|
|
|
|
|
|
|
|
hres = init_global(This->ctx);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
IActiveScriptSite_AddRef(This->site);
|
|
|
|
This->ctx->site = This->site;
|
|
|
|
|
|
|
|
if(This->is_initialized)
|
|
|
|
change_state(This, SCRIPTSTATE_INITIALIZED);
|
|
|
|
return S_OK;
|
2008-03-16 21:10:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScript_GetScriptSite(IActiveScript *iface, REFIID riid,
|
|
|
|
void **ppvObject)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScript(iface);
|
2008-03-16 21:10:13 +01:00
|
|
|
FIXME("(%p)->()\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScript(iface);
|
2008-09-05 02:38:17 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%d)\n", This, ss);
|
|
|
|
|
2011-02-21 17:49:15 +01:00
|
|
|
if(This->thread_id && GetCurrentThreadId() != This->thread_id)
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
|
|
|
if(ss == SCRIPTSTATE_UNINITIALIZED) {
|
|
|
|
if(This->ctx && This->ctx->state == SCRIPTSTATE_CLOSED)
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
|
|
|
decrease_state(This, SCRIPTSTATE_UNINITIALIZED);
|
2019-11-07 18:17:13 +01:00
|
|
|
list_move_tail(&This->queued_code, &This->persistent_code);
|
2011-02-21 17:49:15 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-02-20 21:26:38 +01:00
|
|
|
if(!This->is_initialized || !This->ctx)
|
2008-09-05 02:38:17 +02:00
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
|
|
|
switch(ss) {
|
|
|
|
case SCRIPTSTATE_STARTED:
|
2008-11-05 01:03:19 +01:00
|
|
|
case SCRIPTSTATE_CONNECTED: /* FIXME */
|
2008-09-05 02:38:17 +02:00
|
|
|
if(This->ctx->state == SCRIPTSTATE_CLOSED)
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
|
|
|
exec_queued_code(This);
|
|
|
|
break;
|
2010-07-27 15:51:29 +02:00
|
|
|
case SCRIPTSTATE_INITIALIZED:
|
|
|
|
FIXME("unimplemented SCRIPTSTATE_INITIALIZED\n");
|
|
|
|
return S_OK;
|
2008-09-05 02:38:17 +02:00
|
|
|
default:
|
|
|
|
FIXME("unimplemented state %d\n", ss);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
change_state(This, ss);
|
|
|
|
return S_OK;
|
2008-03-16 21:10:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScript(iface);
|
2008-09-01 01:25:29 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, pssState);
|
|
|
|
|
|
|
|
if(!pssState)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2011-02-21 17:49:15 +01:00
|
|
|
if(This->thread_id && This->thread_id != GetCurrentThreadId())
|
2008-09-01 01:25:29 +02:00
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
|
|
|
*pssState = This->ctx ? This->ctx->state : SCRIPTSTATE_UNINITIALIZED;
|
|
|
|
return S_OK;
|
2008-03-16 21:10:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScript_Close(IActiveScript *iface)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScript(iface);
|
2008-09-01 01:17:53 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->()\n", This);
|
|
|
|
|
2011-02-21 17:49:15 +01:00
|
|
|
if(This->thread_id && This->thread_id != GetCurrentThreadId())
|
2008-09-01 01:17:53 +02:00
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
2011-02-21 17:49:15 +01:00
|
|
|
decrease_state(This, SCRIPTSTATE_CLOSED);
|
2019-11-07 18:17:13 +01:00
|
|
|
clear_persistent_code_list(This);
|
2020-03-24 17:49:57 +01:00
|
|
|
release_named_item_list(This);
|
2008-09-01 01:17:53 +02:00
|
|
|
return S_OK;
|
2008-03-16 21:10:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScript_AddNamedItem(IActiveScript *iface,
|
|
|
|
LPCOLESTR pstrName, DWORD dwFlags)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScript(iface);
|
2008-09-09 01:22:31 +02:00
|
|
|
named_item_t *item;
|
2008-12-15 22:24:33 +01:00
|
|
|
IDispatch *disp = NULL;
|
2008-09-09 01:22:31 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %x)\n", This, debugstr_w(pstrName), dwFlags);
|
|
|
|
|
|
|
|
if(This->thread_id != GetCurrentThreadId() || !This->ctx || This->ctx->state == SCRIPTSTATE_CLOSED)
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
2008-12-15 22:24:33 +01:00
|
|
|
if(dwFlags & SCRIPTITEM_GLOBALMEMBERS) {
|
|
|
|
IUnknown *unk;
|
2008-09-09 01:22:31 +02:00
|
|
|
|
2008-12-15 22:24:33 +01:00
|
|
|
hres = IActiveScriptSite_GetItemInfo(This->site, pstrName, SCRIPTINFO_IUNKNOWN, &unk, NULL);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
WARN("GetItemInfo failed: %08x\n", hres);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
WARN("object does not implement IDispatch\n");
|
|
|
|
return hres;
|
|
|
|
}
|
2008-09-09 01:22:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
item = heap_alloc(sizeof(*item));
|
|
|
|
if(!item) {
|
2008-12-15 22:24:33 +01:00
|
|
|
if(disp)
|
|
|
|
IDispatch_Release(disp);
|
2008-09-09 01:22:31 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2020-02-26 13:41:24 +01:00
|
|
|
item->ref = 1;
|
2008-09-09 01:22:31 +02:00
|
|
|
item->disp = disp;
|
|
|
|
item->flags = dwFlags;
|
2020-03-07 14:40:32 +01:00
|
|
|
item->script_obj = NULL;
|
2008-11-05 01:03:38 +01:00
|
|
|
item->name = heap_strdupW(pstrName);
|
|
|
|
if(!item->name) {
|
2011-01-27 13:38:36 +01:00
|
|
|
if(disp)
|
|
|
|
IDispatch_Release(disp);
|
2008-11-05 01:03:38 +01:00
|
|
|
heap_free(item);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2020-03-05 17:11:56 +01:00
|
|
|
list_add_tail(&This->ctx->named_items, &item->entry);
|
2008-09-09 01:22:31 +02:00
|
|
|
return S_OK;
|
2008-03-16 21:10:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
|
|
|
|
DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScript(iface);
|
2008-03-16 21:10:13 +01:00
|
|
|
FIXME("(%p)->()\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName,
|
|
|
|
IDispatch **ppdisp)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScript(iface);
|
2020-03-07 14:40:33 +01:00
|
|
|
jsdisp_t *script_obj;
|
2008-09-01 01:23:38 +02:00
|
|
|
|
2019-11-14 17:14:10 +01:00
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_w(pstrItemName), ppdisp);
|
2008-09-01 01:23:38 +02:00
|
|
|
|
|
|
|
if(!ppdisp)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2009-09-27 20:59:28 +02:00
|
|
|
if(This->thread_id != GetCurrentThreadId() || !This->ctx->global) {
|
2008-09-01 01:23:38 +02:00
|
|
|
*ppdisp = NULL;
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2020-03-07 14:40:33 +01:00
|
|
|
script_obj = This->ctx->global;
|
|
|
|
if(pstrItemName) {
|
|
|
|
named_item_t *item = lookup_named_item(This->ctx, pstrItemName, 0);
|
|
|
|
if(!item) return E_INVALIDARG;
|
|
|
|
if(item->script_obj) script_obj = item->script_obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppdisp = to_disp(script_obj);
|
2008-09-01 01:23:38 +02:00
|
|
|
IDispatch_AddRef(*ppdisp);
|
|
|
|
return S_OK;
|
2008-03-16 21:10:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScript_GetCurrentScriptThreadID(IActiveScript *iface,
|
|
|
|
SCRIPTTHREADID *pstridThread)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScript(iface);
|
2008-03-16 21:10:13 +01:00
|
|
|
FIXME("(%p)->()\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScript_GetScriptThreadID(IActiveScript *iface,
|
|
|
|
DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScript(iface);
|
2008-03-16 21:10:13 +01:00
|
|
|
FIXME("(%p)->()\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScript_GetScriptThreadState(IActiveScript *iface,
|
|
|
|
SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScript(iface);
|
2008-03-16 21:10:13 +01:00
|
|
|
FIXME("(%p)->()\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScript_InterruptScriptThread(IActiveScript *iface,
|
|
|
|
SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScript(iface);
|
2008-03-16 21:10:13 +01:00
|
|
|
FIXME("(%p)->()\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScript(iface);
|
2008-03-16 21:10:13 +01:00
|
|
|
FIXME("(%p)->()\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IActiveScriptVtbl JScriptVtbl = {
|
|
|
|
JScript_QueryInterface,
|
|
|
|
JScript_AddRef,
|
|
|
|
JScript_Release,
|
|
|
|
JScript_SetScriptSite,
|
|
|
|
JScript_GetScriptSite,
|
|
|
|
JScript_SetScriptState,
|
|
|
|
JScript_GetScriptState,
|
|
|
|
JScript_Close,
|
|
|
|
JScript_AddNamedItem,
|
|
|
|
JScript_AddTypeLib,
|
|
|
|
JScript_GetScriptDispatch,
|
|
|
|
JScript_GetCurrentScriptThreadID,
|
|
|
|
JScript_GetScriptThreadID,
|
|
|
|
JScript_GetScriptThreadState,
|
|
|
|
JScript_InterruptScriptThread,
|
|
|
|
JScript_Clone
|
|
|
|
};
|
|
|
|
|
2011-01-16 21:30:46 +01:00
|
|
|
static inline JScript *impl_from_IActiveScriptParse(IActiveScriptParse *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, JScript, IActiveScriptParse_iface);
|
|
|
|
}
|
2008-03-19 11:31:36 +01:00
|
|
|
|
|
|
|
static HRESULT WINAPI JScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScriptParse(iface);
|
|
|
|
return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
|
2008-03-19 11:31:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI JScriptParse_AddRef(IActiveScriptParse *iface)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScriptParse(iface);
|
|
|
|
return IActiveScript_AddRef(&This->IActiveScript_iface);
|
2008-03-19 11:31:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI JScriptParse_Release(IActiveScriptParse *iface)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScriptParse(iface);
|
|
|
|
return IActiveScript_Release(&This->IActiveScript_iface);
|
2008-03-19 11:31:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScriptParse_InitNew(IActiveScriptParse *iface)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScriptParse(iface);
|
2008-09-01 01:23:16 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
2020-02-20 21:26:38 +01:00
|
|
|
if(This->is_initialized)
|
2008-09-01 01:23:16 +02:00
|
|
|
return E_UNEXPECTED;
|
2020-02-20 21:26:38 +01:00
|
|
|
This->is_initialized = TRUE;
|
2008-09-01 01:23:16 +02:00
|
|
|
|
2020-02-20 21:26:38 +01:00
|
|
|
if(This->site)
|
|
|
|
change_state(This, SCRIPTSTATE_INITIALIZED);
|
|
|
|
return S_OK;
|
2008-03-19 11:31:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScriptParse_AddScriptlet(IActiveScriptParse *iface,
|
|
|
|
LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode, LPCOLESTR pstrItemName,
|
|
|
|
LPCOLESTR pstrSubItemName, LPCOLESTR pstrEventName, LPCOLESTR pstrDelimiter,
|
2009-02-02 15:27:24 +01:00
|
|
|
CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags,
|
2008-03-19 11:31:36 +01:00
|
|
|
BSTR *pbstrName, EXCEPINFO *pexcepinfo)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScriptParse(iface);
|
2009-02-02 15:27:24 +01:00
|
|
|
FIXME("(%p)->(%s %s %s %s %s %s %s %u %x %p %p)\n", This, debugstr_w(pstrDefaultName),
|
2008-03-19 11:31:36 +01:00
|
|
|
debugstr_w(pstrCode), debugstr_w(pstrItemName), debugstr_w(pstrSubItemName),
|
2009-02-02 15:27:24 +01:00
|
|
|
debugstr_w(pstrEventName), debugstr_w(pstrDelimiter), wine_dbgstr_longlong(dwSourceContextCookie),
|
2008-03-19 11:31:36 +01:00
|
|
|
ulStartingLineNumber, dwFlags, pbstrName, pexcepinfo);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScriptParse_ParseScriptText(IActiveScriptParse *iface,
|
|
|
|
LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
|
2009-02-02 15:27:24 +01:00
|
|
|
LPCOLESTR pstrDelimiter, CTXARG_T dwSourceContextCookie, ULONG ulStartingLine,
|
2008-03-19 11:31:36 +01:00
|
|
|
DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScriptParse(iface);
|
2020-03-07 14:40:31 +01:00
|
|
|
named_item_t *item = NULL;
|
2012-03-12 19:24:22 +01:00
|
|
|
bytecode_t *code;
|
2020-01-30 15:50:15 +01:00
|
|
|
jsexcept_t ei;
|
2008-09-03 00:25:21 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2009-02-02 15:27:24 +01:00
|
|
|
TRACE("(%p)->(%s %s %p %s %s %u %x %p %p)\n", This, debugstr_w(pstrCode),
|
2008-03-19 11:31:36 +01:00
|
|
|
debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
|
2009-02-02 15:27:24 +01:00
|
|
|
wine_dbgstr_longlong(dwSourceContextCookie), ulStartingLine, dwFlags, pvarResult, pexcepinfo);
|
2008-09-03 00:25:21 +02:00
|
|
|
|
2008-09-05 02:37:59 +02:00
|
|
|
if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED)
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
2020-03-07 14:40:31 +01:00
|
|
|
if(pstrItemName) {
|
|
|
|
item = lookup_named_item(This->ctx, pstrItemName, 0);
|
|
|
|
if(!item) {
|
|
|
|
WARN("Unknown context %s\n", debugstr_w(pstrItemName));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2020-03-07 14:40:32 +01:00
|
|
|
if(!item->script_obj) item = NULL;
|
2020-03-07 14:40:31 +01:00
|
|
|
}
|
|
|
|
|
2020-01-30 15:50:15 +01:00
|
|
|
enter_script(This->ctx, &ei);
|
2020-01-30 15:49:58 +01:00
|
|
|
hres = compile_script(This->ctx, pstrCode, dwSourceContextCookie, ulStartingLine, NULL, pstrDelimiter,
|
2020-03-07 14:40:31 +01:00
|
|
|
(dwFlags & SCRIPTTEXT_ISEXPRESSION) != 0, This->is_encode, item, &code);
|
2008-09-03 00:25:21 +02:00
|
|
|
if(FAILED(hres))
|
2020-01-30 15:50:15 +01:00
|
|
|
return leave_script(This->ctx, hres);
|
2008-09-03 00:25:21 +02:00
|
|
|
|
2012-12-12 13:12:17 +01:00
|
|
|
if(dwFlags & SCRIPTTEXT_ISEXPRESSION) {
|
2016-03-25 17:50:16 +01:00
|
|
|
jsval_t r;
|
2012-12-12 13:12:17 +01:00
|
|
|
|
2020-03-17 19:19:25 +01:00
|
|
|
hres = exec_source(This->ctx, EXEC_GLOBAL, code, &code->global_code, NULL, NULL, NULL, 0, NULL, &r);
|
2016-03-25 17:50:16 +01:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
if(pvarResult)
|
|
|
|
hres = jsval_to_variant(r, pvarResult);
|
|
|
|
jsval_release(r);
|
2012-12-12 13:12:17 +01:00
|
|
|
}
|
|
|
|
|
2020-01-30 15:50:15 +01:00
|
|
|
return leave_script(This->ctx, hres);
|
2012-12-12 13:12:17 +01:00
|
|
|
}
|
|
|
|
|
2019-11-07 18:17:13 +01:00
|
|
|
code->is_persistent = (dwFlags & SCRIPTTEXT_ISPERSISTENT) != 0;
|
|
|
|
|
2015-05-29 18:07:37 +02:00
|
|
|
/*
|
|
|
|
* Although pvarResult is not really used without SCRIPTTEXT_ISEXPRESSION flag, if it's not NULL,
|
|
|
|
* script is executed immediately, even if it's not in started state yet.
|
|
|
|
*/
|
|
|
|
if(!pvarResult && !is_started(This->ctx)) {
|
2019-11-07 18:17:06 +01:00
|
|
|
list_add_tail(&This->queued_code, &code->entry);
|
2020-01-30 15:50:15 +01:00
|
|
|
}else {
|
2020-03-17 19:19:25 +01:00
|
|
|
hres = exec_source(This->ctx, EXEC_GLOBAL, code, &code->global_code, NULL, NULL, NULL, 0, NULL, NULL);
|
2020-01-30 15:50:15 +01:00
|
|
|
if(code->is_persistent)
|
|
|
|
list_add_tail(&This->persistent_code, &code->entry);
|
|
|
|
else
|
|
|
|
release_bytecode(code);
|
|
|
|
}
|
2019-11-07 18:17:13 +01:00
|
|
|
|
2020-01-30 15:50:15 +01:00
|
|
|
if(FAILED(hres = leave_script(This->ctx, hres)))
|
2015-05-29 18:07:37 +02:00
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(pvarResult)
|
|
|
|
V_VT(pvarResult) = VT_EMPTY;
|
|
|
|
return S_OK;
|
2008-03-19 11:31:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IActiveScriptParseVtbl JScriptParseVtbl = {
|
|
|
|
JScriptParse_QueryInterface,
|
|
|
|
JScriptParse_AddRef,
|
|
|
|
JScriptParse_Release,
|
|
|
|
JScriptParse_InitNew,
|
|
|
|
JScriptParse_AddScriptlet,
|
|
|
|
JScriptParse_ParseScriptText
|
|
|
|
};
|
|
|
|
|
2011-01-16 21:30:46 +01:00
|
|
|
static inline JScript *impl_from_IActiveScriptParseProcedure2(IActiveScriptParseProcedure2 *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, JScript, IActiveScriptParseProcedure2_iface);
|
|
|
|
}
|
2008-03-21 13:02:46 +01:00
|
|
|
|
|
|
|
static HRESULT WINAPI JScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2 *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScriptParseProcedure2(iface);
|
|
|
|
return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
|
2008-03-21 13:02:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI JScriptParseProcedure_AddRef(IActiveScriptParseProcedure2 *iface)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScriptParseProcedure2(iface);
|
|
|
|
return IActiveScript_AddRef(&This->IActiveScript_iface);
|
2008-03-21 13:02:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI JScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScriptParseProcedure2(iface);
|
|
|
|
return IActiveScript_Release(&This->IActiveScript_iface);
|
2008-03-21 13:02:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2 *iface,
|
|
|
|
LPCOLESTR pstrCode, LPCOLESTR pstrFormalParams, LPCOLESTR pstrProcedureName,
|
|
|
|
LPCOLESTR pstrItemName, IUnknown *punkContext, LPCOLESTR pstrDelimiter,
|
2009-02-09 21:11:36 +01:00
|
|
|
CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags, IDispatch **ppdisp)
|
2008-03-21 13:02:46 +01:00
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScriptParseProcedure2(iface);
|
2020-03-07 14:40:31 +01:00
|
|
|
named_item_t *item = NULL;
|
2012-03-12 19:24:22 +01:00
|
|
|
bytecode_t *code;
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *dispex;
|
2020-01-30 15:50:15 +01:00
|
|
|
jsexcept_t ei;
|
2008-09-10 21:09:48 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2009-02-09 21:11:36 +01:00
|
|
|
TRACE("(%p)->(%s %s %s %s %p %s %s %u %x %p)\n", This, debugstr_w(pstrCode), debugstr_w(pstrFormalParams),
|
2008-09-10 21:09:48 +02:00
|
|
|
debugstr_w(pstrProcedureName), debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
|
2009-02-09 21:11:36 +01:00
|
|
|
wine_dbgstr_longlong(dwSourceContextCookie), ulStartingLineNumber, dwFlags, ppdisp);
|
2008-09-10 21:09:48 +02:00
|
|
|
|
|
|
|
if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED)
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
2020-03-07 14:40:31 +01:00
|
|
|
if(pstrItemName) {
|
|
|
|
item = lookup_named_item(This->ctx, pstrItemName, 0);
|
|
|
|
if(!item) {
|
|
|
|
WARN("Unknown context %s\n", debugstr_w(pstrItemName));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2020-03-07 14:40:32 +01:00
|
|
|
if(!item->script_obj) item = NULL;
|
2020-03-07 14:40:31 +01:00
|
|
|
}
|
|
|
|
|
2020-01-30 15:50:15 +01:00
|
|
|
enter_script(This->ctx, &ei);
|
2020-01-30 15:49:58 +01:00
|
|
|
hres = compile_script(This->ctx, pstrCode, dwSourceContextCookie, ulStartingLineNumber, pstrFormalParams,
|
2020-03-07 14:40:31 +01:00
|
|
|
pstrDelimiter, FALSE, This->is_encode, item, &code);
|
2020-01-30 15:50:15 +01:00
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
hres = create_source_function(This->ctx, code, &code->global_code, NULL, &dispex);
|
2012-03-12 19:24:22 +01:00
|
|
|
release_bytecode(code);
|
2020-01-30 15:50:15 +01:00
|
|
|
hres = leave_script(This->ctx, hres);
|
2008-09-10 21:09:48 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-09-07 15:42:01 +02:00
|
|
|
*ppdisp = to_disp(dispex);
|
2008-09-10 21:09:48 +02:00
|
|
|
return S_OK;
|
2008-03-21 13:02:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IActiveScriptParseProcedure2Vtbl JScriptParseProcedureVtbl = {
|
|
|
|
JScriptParseProcedure_QueryInterface,
|
|
|
|
JScriptParseProcedure_AddRef,
|
|
|
|
JScriptParseProcedure_Release,
|
|
|
|
JScriptParseProcedure_ParseProcedureText,
|
|
|
|
};
|
|
|
|
|
2011-01-16 21:30:46 +01:00
|
|
|
static inline JScript *impl_from_IActiveScriptProperty(IActiveScriptProperty *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, JScript, IActiveScriptProperty_iface);
|
|
|
|
}
|
2008-03-19 11:31:54 +01:00
|
|
|
|
|
|
|
static HRESULT WINAPI JScriptProperty_QueryInterface(IActiveScriptProperty *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScriptProperty(iface);
|
|
|
|
return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
|
2008-03-19 11:31:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI JScriptProperty_AddRef(IActiveScriptProperty *iface)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScriptProperty(iface);
|
|
|
|
return IActiveScript_AddRef(&This->IActiveScript_iface);
|
2008-03-19 11:31:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI JScriptProperty_Release(IActiveScriptProperty *iface)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScriptProperty(iface);
|
|
|
|
return IActiveScript_Release(&This->IActiveScript_iface);
|
2008-03-19 11:31:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScriptProperty_GetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
|
|
|
|
VARIANT *pvarIndex, VARIANT *pvarValue)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScriptProperty(iface);
|
2008-03-19 11:31:54 +01:00
|
|
|
FIXME("(%p)->(%x %p %p)\n", This, dwProperty, pvarIndex, pvarValue);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScriptProperty_SetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
|
|
|
|
VARIANT *pvarIndex, VARIANT *pvarValue)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IActiveScriptProperty(iface);
|
2009-10-19 20:39:24 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%x %s %s)\n", This, dwProperty, debugstr_variant(pvarIndex), debugstr_variant(pvarValue));
|
|
|
|
|
|
|
|
if(pvarIndex)
|
|
|
|
FIXME("unsupported pvarIndex\n");
|
|
|
|
|
|
|
|
switch(dwProperty) {
|
|
|
|
case SCRIPTPROP_INVOKEVERSIONING:
|
2018-03-01 19:18:26 +01:00
|
|
|
if(V_VT(pvarValue) != VT_I4 || V_I4(pvarValue) < 0
|
|
|
|
|| (V_I4(pvarValue) > 15 && !(V_I4(pvarValue) & SCRIPTLANGUAGEVERSION_HTML))) {
|
2009-10-19 20:39:24 +02:00
|
|
|
WARN("invalid value %s\n", debugstr_variant(pvarValue));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-03-01 19:18:26 +01:00
|
|
|
This->version = V_I4(pvarValue) & 0x1ff;
|
|
|
|
This->html_mode = (V_I4(pvarValue) & SCRIPTLANGUAGEVERSION_HTML) != 0;
|
2009-10-19 20:39:24 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unimplemented property %x\n", dwProperty);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2008-03-19 11:31:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IActiveScriptPropertyVtbl JScriptPropertyVtbl = {
|
|
|
|
JScriptProperty_QueryInterface,
|
|
|
|
JScriptProperty_AddRef,
|
|
|
|
JScriptProperty_Release,
|
|
|
|
JScriptProperty_GetProperty,
|
|
|
|
JScriptProperty_SetProperty
|
|
|
|
};
|
|
|
|
|
2011-01-16 21:30:46 +01:00
|
|
|
static inline JScript *impl_from_IObjectSafety(IObjectSafety *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, JScript, IObjectSafety_iface);
|
|
|
|
}
|
2008-03-21 13:03:07 +01:00
|
|
|
|
|
|
|
static HRESULT WINAPI JScriptSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IObjectSafety(iface);
|
|
|
|
return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
|
2008-03-21 13:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI JScriptSafety_AddRef(IObjectSafety *iface)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IObjectSafety(iface);
|
|
|
|
return IActiveScript_AddRef(&This->IActiveScript_iface);
|
2008-03-21 13:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI JScriptSafety_Release(IObjectSafety *iface)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IObjectSafety(iface);
|
|
|
|
return IActiveScript_Release(&This->IActiveScript_iface);
|
2008-03-21 13:03:07 +01:00
|
|
|
}
|
|
|
|
|
2008-04-07 12:35:41 +02:00
|
|
|
#define SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER)
|
|
|
|
|
2008-03-21 13:03:07 +01:00
|
|
|
static HRESULT WINAPI JScriptSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
|
|
|
|
DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IObjectSafety(iface);
|
2008-04-07 12:35:41 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p %p)\n", This, debugstr_guid(riid), pdwSupportedOptions, pdwEnabledOptions);
|
|
|
|
|
|
|
|
if(!pdwSupportedOptions || !pdwEnabledOptions)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*pdwSupportedOptions = SUPPORTED_OPTIONS;
|
|
|
|
*pdwEnabledOptions = This->safeopt;
|
|
|
|
|
|
|
|
return S_OK;
|
2008-03-21 13:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JScriptSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
|
|
|
|
DWORD dwOptionSetMask, DWORD dwEnabledOptions)
|
|
|
|
{
|
2011-01-16 21:30:46 +01:00
|
|
|
JScript *This = impl_from_IObjectSafety(iface);
|
2008-04-07 12:35:41 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s %x %x)\n", This, debugstr_guid(riid), dwOptionSetMask, dwEnabledOptions);
|
|
|
|
|
|
|
|
if(dwOptionSetMask & ~SUPPORTED_OPTIONS)
|
|
|
|
return E_FAIL;
|
|
|
|
|
2011-09-01 17:47:41 +02:00
|
|
|
This->safeopt = (dwEnabledOptions & dwOptionSetMask) | (This->safeopt & ~dwOptionSetMask) | INTERFACE_USES_DISPEX;
|
2008-03-21 13:03:07 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IObjectSafetyVtbl JScriptSafetyVtbl = {
|
|
|
|
JScriptSafety_QueryInterface,
|
|
|
|
JScriptSafety_AddRef,
|
|
|
|
JScriptSafety_Release,
|
|
|
|
JScriptSafety_GetInterfaceSafetyOptions,
|
|
|
|
JScriptSafety_SetInterfaceSafetyOptions
|
|
|
|
};
|
|
|
|
|
2012-03-08 14:27:47 +01:00
|
|
|
static inline JScript *impl_from_IVariantChangeType(IVariantChangeType *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, JScript, IVariantChangeType_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI VariantChangeType_QueryInterface(IVariantChangeType *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
JScript *This = impl_from_IVariantChangeType(iface);
|
|
|
|
return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI VariantChangeType_AddRef(IVariantChangeType *iface)
|
|
|
|
{
|
|
|
|
JScript *This = impl_from_IVariantChangeType(iface);
|
|
|
|
return IActiveScript_AddRef(&This->IActiveScript_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI VariantChangeType_Release(IVariantChangeType *iface)
|
|
|
|
{
|
|
|
|
JScript *This = impl_from_IVariantChangeType(iface);
|
|
|
|
return IActiveScript_Release(&This->IActiveScript_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI VariantChangeType_ChangeType(IVariantChangeType *iface, VARIANT *dst, VARIANT *src, LCID lcid, VARTYPE vt)
|
|
|
|
{
|
|
|
|
JScript *This = impl_from_IVariantChangeType(iface);
|
2020-01-30 15:50:15 +01:00
|
|
|
jsexcept_t ei;
|
2012-09-21 18:00:33 +02:00
|
|
|
VARIANT res;
|
2012-03-12 12:12:26 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
2020-01-30 15:50:15 +01:00
|
|
|
TRACE("(%p)->(%p %s %x %s)\n", This, dst, debugstr_variant(src), lcid, debugstr_vt(vt));
|
2012-03-12 12:12:26 +01:00
|
|
|
|
|
|
|
if(!This->ctx) {
|
|
|
|
FIXME("Object uninitialized\n");
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2020-01-30 15:50:15 +01:00
|
|
|
enter_script(This->ctx, &ei);
|
2012-09-21 18:00:33 +02:00
|
|
|
hres = variant_change_type(This->ctx, &res, src, vt);
|
2020-01-30 15:50:15 +01:00
|
|
|
hres = leave_script(This->ctx, hres);
|
2012-03-12 12:12:26 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-21 18:00:33 +02:00
|
|
|
hres = VariantClear(dst);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
VariantClear(&res);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dst = res;
|
|
|
|
return S_OK;
|
2012-03-08 14:27:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IVariantChangeTypeVtbl VariantChangeTypeVtbl = {
|
|
|
|
VariantChangeType_QueryInterface,
|
|
|
|
VariantChangeType_AddRef,
|
|
|
|
VariantChangeType_Release,
|
|
|
|
VariantChangeType_ChangeType
|
|
|
|
};
|
|
|
|
|
2012-03-26 11:41:56 +02:00
|
|
|
HRESULT create_jscript_object(BOOL is_encode, REFIID riid, void **ppv)
|
2008-03-16 21:10:13 +01:00
|
|
|
{
|
|
|
|
JScript *ret;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2008-09-01 01:23:16 +02:00
|
|
|
ret = heap_alloc_zero(sizeof(*ret));
|
2008-10-06 16:57:20 +02:00
|
|
|
if(!ret)
|
|
|
|
return E_OUTOFMEMORY;
|
2008-03-16 21:10:13 +01:00
|
|
|
|
2012-03-26 11:41:56 +02:00
|
|
|
lock_module();
|
|
|
|
|
2011-01-16 21:30:46 +01:00
|
|
|
ret->IActiveScript_iface.lpVtbl = &JScriptVtbl;
|
|
|
|
ret->IActiveScriptParse_iface.lpVtbl = &JScriptParseVtbl;
|
|
|
|
ret->IActiveScriptParseProcedure2_iface.lpVtbl = &JScriptParseProcedureVtbl;
|
|
|
|
ret->IActiveScriptProperty_iface.lpVtbl = &JScriptPropertyVtbl;
|
|
|
|
ret->IObjectSafety_iface.lpVtbl = &JScriptSafetyVtbl;
|
2012-03-08 14:27:47 +01:00
|
|
|
ret->IVariantChangeType_iface.lpVtbl = &VariantChangeTypeVtbl;
|
2008-03-16 21:10:13 +01:00
|
|
|
ret->ref = 1;
|
2008-04-07 12:35:41 +02:00
|
|
|
ret->safeopt = INTERFACE_USES_DISPEX;
|
2012-03-26 11:41:56 +02:00
|
|
|
ret->is_encode = is_encode;
|
2019-11-07 18:17:13 +01:00
|
|
|
list_init(&ret->persistent_code);
|
2019-11-07 18:17:06 +01:00
|
|
|
list_init(&ret->queued_code);
|
2008-03-16 21:10:13 +01:00
|
|
|
|
2011-01-16 21:30:46 +01:00
|
|
|
hres = IActiveScript_QueryInterface(&ret->IActiveScript_iface, riid, ppv);
|
|
|
|
IActiveScript_Release(&ret->IActiveScript_iface);
|
2008-03-16 21:10:13 +01:00
|
|
|
return hres;
|
|
|
|
}
|