2 * Copyright 2008 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(jscript
);
29 #define CTXARG_T DWORDLONG
30 #define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
31 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_64Vtbl
35 #define CTXARG_T DWORD
36 #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
37 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_32Vtbl
42 const IActiveScriptVtbl
*lpIActiveScriptVtbl
;
43 const IActiveScriptParseVtbl
*lpIActiveScriptParseVtbl
;
44 const IActiveScriptParseProcedure2Vtbl
*lpIActiveScriptParseProcedure2Vtbl
;
45 const IActiveScriptPropertyVtbl
*lpIActiveScriptPropertyVtbl
;
46 const IObjectSafetyVtbl
*lpIObjectSafetyVtbl
;
56 IActiveScriptSite
*site
;
58 parser_ctx_t
*queue_head
;
59 parser_ctx_t
*queue_tail
;
62 #define ACTSCRIPT(x) ((IActiveScript*) &(x)->lpIActiveScriptVtbl)
63 #define ASPARSE(x) (&(x)->lpIActiveScriptParseVtbl)
64 #define ASPARSEPROC(x) (&(x)->lpIActiveScriptParseProcedure2Vtbl)
65 #define ACTSCPPROP(x) (&(x)->lpIActiveScriptPropertyVtbl)
66 #define OBJSAFETY(x) (&(x)->lpIObjectSafetyVtbl)
68 void script_release(script_ctx_t
*ctx
)
73 jsheap_free(&ctx
->tmp_heap
);
77 static void change_state(JScript
*This
, SCRIPTSTATE state
)
79 if(This
->ctx
->state
== state
)
82 This
->ctx
->state
= state
;
83 IActiveScriptSite_OnStateChange(This
->site
, state
);
86 static inline BOOL
is_started(script_ctx_t
*ctx
)
88 return ctx
->state
== SCRIPTSTATE_STARTED
89 || ctx
->state
== SCRIPTSTATE_CONNECTED
90 || ctx
->state
== SCRIPTSTATE_DISCONNECTED
;
93 static HRESULT
exec_global_code(JScript
*This
, parser_ctx_t
*parser_ctx
)
99 hres
= create_exec_ctx(This
->ctx
, NULL
, This
->ctx
->global
, NULL
, &exec_ctx
);
103 IActiveScriptSite_OnEnterScript(This
->site
);
105 memset(&jsexcept
, 0, sizeof(jsexcept
));
106 hres
= exec_source(exec_ctx
, parser_ctx
, parser_ctx
->source
, EXECT_PROGRAM
, &jsexcept
, NULL
);
107 VariantClear(&jsexcept
.var
);
108 exec_release(exec_ctx
);
110 IActiveScriptSite_OnLeaveScript(This
->site
);
114 static void clear_script_queue(JScript
*This
)
116 parser_ctx_t
*iter
, *iter2
;
118 if(!This
->queue_head
)
121 iter
= This
->queue_head
;
125 parser_release(iter
);
129 This
->queue_head
= This
->queue_tail
= NULL
;
132 static void exec_queued_code(JScript
*This
)
136 for(iter
= This
->queue_head
; iter
; iter
= iter
->next
)
137 exec_global_code(This
, iter
);
139 clear_script_queue(This
);
142 static HRESULT
set_ctx_site(JScript
*This
)
146 This
->ctx
->lcid
= This
->lcid
;
148 hres
= init_global(This
->ctx
);
152 IActiveScriptSite_AddRef(This
->site
);
153 This
->ctx
->site
= This
->site
;
155 change_state(This
, SCRIPTSTATE_INITIALIZED
);
160 const IServiceProviderVtbl
*lpIServiceProviderVtbl
;
164 IServiceProvider
*sp
;
167 #define SERVPROV(x) ((IServiceProvider*) &(x)->lpIServiceProviderVtbl)
169 #define SERVPROV_THIS(iface) DEFINE_THIS(AXSite, IServiceProvider, iface)
171 static HRESULT WINAPI
AXSite_QueryInterface(IServiceProvider
*iface
, REFIID riid
, void **ppv
)
173 AXSite
*This
= SERVPROV_THIS(iface
);
175 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
176 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
177 *ppv
= SERVPROV(This
);
178 }else if(IsEqualGUID(&IID_IServiceProvider
, riid
)) {
179 TRACE("(%p)->(IID_IServiceProvider %p)\n", This
, ppv
);
180 *ppv
= SERVPROV(This
);
182 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
184 return E_NOINTERFACE
;
187 IUnknown_AddRef((IUnknown
*)*ppv
);
191 static ULONG WINAPI
AXSite_AddRef(IServiceProvider
*iface
)
193 AXSite
*This
= SERVPROV_THIS(iface
);
194 LONG ref
= InterlockedIncrement(&This
->ref
);
196 TRACE("(%p) ref=%d\n", This
, ref
);
201 static ULONG WINAPI
AXSite_Release(IServiceProvider
*iface
)
203 AXSite
*This
= SERVPROV_THIS(iface
);
204 LONG ref
= InterlockedDecrement(&This
->ref
);
206 TRACE("(%p) ref=%d\n", This
, ref
);
214 static HRESULT WINAPI
AXSite_QueryService(IServiceProvider
*iface
,
215 REFGUID guidService
, REFIID riid
, void **ppv
)
217 AXSite
*This
= SERVPROV_THIS(iface
);
219 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_guid(guidService
), debugstr_guid(riid
), ppv
);
221 return IServiceProvider_QueryService(This
->sp
, guidService
, riid
, ppv
);
226 static IServiceProviderVtbl AXSiteVtbl
= {
227 AXSite_QueryInterface
,
233 IUnknown
*create_ax_site(script_ctx_t
*ctx
)
235 IServiceProvider
*sp
;
239 hres
= IActiveScriptSite_QueryInterface(ctx
->site
, &IID_IServiceProvider
, (void**)&sp
);
241 ERR("Could not get IServiceProvider iface: %08x\n", hres
);
245 ret
= heap_alloc(sizeof(AXSite
));
247 IServiceProvider_Release(sp
);
251 ret
->lpIServiceProviderVtbl
= &AXSiteVtbl
;
255 return (IUnknown
*)SERVPROV(ret
);
258 #define ACTSCRIPT_THIS(iface) DEFINE_THIS(JScript, IActiveScript, iface)
260 static HRESULT WINAPI
JScript_QueryInterface(IActiveScript
*iface
, REFIID riid
, void **ppv
)
262 JScript
*This
= ACTSCRIPT_THIS(iface
);
266 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
267 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
268 *ppv
= ACTSCRIPT(This
);
269 }else if(IsEqualGUID(riid
, &IID_IActiveScript
)) {
270 TRACE("(%p)->(IID_IActiveScript %p)\n", This
, ppv
);
271 *ppv
= ACTSCRIPT(This
);
272 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParse
)) {
273 TRACE("(%p)->(IID_IActiveScriptParse %p)\n", This
, ppv
);
274 *ppv
= ASPARSE(This
);
275 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParseProcedure
)) {
276 TRACE("(%p)->(IID_IActiveScriptParseProcedure %p)\n", This
, ppv
);
277 *ppv
= ASPARSEPROC(This
);
278 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParseProcedure2
)) {
279 TRACE("(%p)->(IID_IActiveScriptParseProcedure2 %p)\n", This
, ppv
);
280 *ppv
= ASPARSEPROC(This
);
281 }else if(IsEqualGUID(riid
, &IID_IActiveScriptProperty
)) {
282 TRACE("(%p)->(IID_IActiveScriptProperty %p)\n", This
, ppv
);
283 *ppv
= ACTSCPPROP(This
);
284 }else if(IsEqualGUID(riid
, &IID_IObjectSafety
)) {
285 TRACE("(%p)->(IID_IObjectSafety %p)\n", This
, ppv
);
286 *ppv
= OBJSAFETY(This
);
290 IUnknown_AddRef((IUnknown
*)*ppv
);
294 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
295 return E_NOINTERFACE
;
298 static ULONG WINAPI
JScript_AddRef(IActiveScript
*iface
)
300 JScript
*This
= ACTSCRIPT_THIS(iface
);
301 LONG ref
= InterlockedIncrement(&This
->ref
);
303 TRACE("(%p) ref=%d\n", This
, ref
);
308 static ULONG WINAPI
JScript_Release(IActiveScript
*iface
)
310 JScript
*This
= ACTSCRIPT_THIS(iface
);
311 LONG ref
= InterlockedDecrement(&This
->ref
);
313 TRACE("(%p) ref=%d\n", iface
, ref
);
316 if(This
->ctx
&& This
->ctx
->state
!= SCRIPTSTATE_CLOSED
)
317 IActiveScript_Close(ACTSCRIPT(This
));
319 script_release(This
->ctx
);
327 static HRESULT WINAPI
JScript_SetScriptSite(IActiveScript
*iface
,
328 IActiveScriptSite
*pass
)
330 JScript
*This
= ACTSCRIPT_THIS(iface
);
334 TRACE("(%p)->(%p)\n", This
, pass
);
342 if(InterlockedCompareExchange(&This
->thread_id
, GetCurrentThreadId(), 0))
346 IActiveScriptSite_AddRef(This
->site
);
348 hres
= IActiveScriptSite_GetLCID(This
->site
, &lcid
);
352 return This
->ctx
? set_ctx_site(This
) : S_OK
;
355 static HRESULT WINAPI
JScript_GetScriptSite(IActiveScript
*iface
, REFIID riid
,
358 JScript
*This
= ACTSCRIPT_THIS(iface
);
359 FIXME("(%p)->()\n", This
);
363 static HRESULT WINAPI
JScript_SetScriptState(IActiveScript
*iface
, SCRIPTSTATE ss
)
365 JScript
*This
= ACTSCRIPT_THIS(iface
);
367 TRACE("(%p)->(%d)\n", This
, ss
);
369 if(!This
->ctx
|| GetCurrentThreadId() != This
->thread_id
)
373 case SCRIPTSTATE_STARTED
:
374 case SCRIPTSTATE_CONNECTED
: /* FIXME */
375 if(This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
378 exec_queued_code(This
);
381 FIXME("unimplemented state %d\n", ss
);
385 change_state(This
, ss
);
389 static HRESULT WINAPI
JScript_GetScriptState(IActiveScript
*iface
, SCRIPTSTATE
*pssState
)
391 JScript
*This
= ACTSCRIPT_THIS(iface
);
393 TRACE("(%p)->(%p)\n", This
, pssState
);
398 if(!This
->thread_id
) {
399 *pssState
= SCRIPTSTATE_UNINITIALIZED
;
403 if(This
->thread_id
!= GetCurrentThreadId())
406 *pssState
= This
->ctx
? This
->ctx
->state
: SCRIPTSTATE_UNINITIALIZED
;
410 static HRESULT WINAPI
JScript_Close(IActiveScript
*iface
)
412 JScript
*This
= ACTSCRIPT_THIS(iface
);
414 TRACE("(%p)->()\n", This
);
416 if(This
->thread_id
!= GetCurrentThreadId())
420 if(This
->ctx
->state
== SCRIPTSTATE_CONNECTED
)
421 change_state(This
, SCRIPTSTATE_DISCONNECTED
);
423 clear_script_queue(This
);
425 if(This
->ctx
->state
== SCRIPTSTATE_DISCONNECTED
)
426 change_state(This
, SCRIPTSTATE_INITIALIZED
);
428 if(This
->ctx
->host_global
) {
429 IDispatch_Release(This
->ctx
->host_global
);
430 This
->ctx
->host_global
= NULL
;
433 if(This
->ctx
->named_items
) {
434 named_item_t
*iter
, *iter2
;
436 iter
= This
->ctx
->named_items
;
441 IDispatch_Release(iter
->disp
);
442 heap_free(iter
->name
);
447 This
->ctx
->named_items
= NULL
;
450 if(This
->ctx
->secmgr
) {
451 IInternetHostSecurityManager_Release(This
->ctx
->secmgr
);
452 This
->ctx
->secmgr
= NULL
;
455 if(This
->ctx
->site
) {
456 IActiveScriptSite_Release(This
->ctx
->site
);
457 This
->ctx
->site
= NULL
;
461 change_state(This
, SCRIPTSTATE_CLOSED
);
463 if(This
->ctx
->global
) {
464 jsdisp_release(This
->ctx
->global
);
465 This
->ctx
->global
= NULL
;
470 IActiveScriptSite_Release(This
->site
);
477 static HRESULT WINAPI
JScript_AddNamedItem(IActiveScript
*iface
,
478 LPCOLESTR pstrName
, DWORD dwFlags
)
480 JScript
*This
= ACTSCRIPT_THIS(iface
);
482 IDispatch
*disp
= NULL
;
485 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(pstrName
), dwFlags
);
487 if(This
->thread_id
!= GetCurrentThreadId() || !This
->ctx
|| This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
490 if(dwFlags
& SCRIPTITEM_GLOBALMEMBERS
) {
493 hres
= IActiveScriptSite_GetItemInfo(This
->site
, pstrName
, SCRIPTINFO_IUNKNOWN
, &unk
, NULL
);
495 WARN("GetItemInfo failed: %08x\n", hres
);
499 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatch
, (void**)&disp
);
500 IUnknown_Release(unk
);
502 WARN("object does not implement IDispatch\n");
506 if(This
->ctx
->host_global
)
507 IDispatch_Release(This
->ctx
->host_global
);
508 IDispatch_AddRef(disp
);
509 This
->ctx
->host_global
= disp
;
512 item
= heap_alloc(sizeof(*item
));
515 IDispatch_Release(disp
);
516 return E_OUTOFMEMORY
;
520 item
->flags
= dwFlags
;
521 item
->name
= heap_strdupW(pstrName
);
523 IDispatch_Release(disp
);
525 return E_OUTOFMEMORY
;
528 item
->next
= This
->ctx
->named_items
;
529 This
->ctx
->named_items
= item
;
534 static HRESULT WINAPI
JScript_AddTypeLib(IActiveScript
*iface
, REFGUID rguidTypeLib
,
535 DWORD dwMajor
, DWORD dwMinor
, DWORD dwFlags
)
537 JScript
*This
= ACTSCRIPT_THIS(iface
);
538 FIXME("(%p)->()\n", This
);
542 static HRESULT WINAPI
JScript_GetScriptDispatch(IActiveScript
*iface
, LPCOLESTR pstrItemName
,
545 JScript
*This
= ACTSCRIPT_THIS(iface
);
547 TRACE("(%p)->(%p)\n", This
, ppdisp
);
552 if(This
->thread_id
!= GetCurrentThreadId() || !This
->ctx
->global
) {
557 *ppdisp
= (IDispatch
*)_IDispatchEx_(This
->ctx
->global
);
558 IDispatch_AddRef(*ppdisp
);
562 static HRESULT WINAPI
JScript_GetCurrentScriptThreadID(IActiveScript
*iface
,
563 SCRIPTTHREADID
*pstridThread
)
565 JScript
*This
= ACTSCRIPT_THIS(iface
);
566 FIXME("(%p)->()\n", This
);
570 static HRESULT WINAPI
JScript_GetScriptThreadID(IActiveScript
*iface
,
571 DWORD dwWin32ThreadId
, SCRIPTTHREADID
*pstidThread
)
573 JScript
*This
= ACTSCRIPT_THIS(iface
);
574 FIXME("(%p)->()\n", This
);
578 static HRESULT WINAPI
JScript_GetScriptThreadState(IActiveScript
*iface
,
579 SCRIPTTHREADID stidThread
, SCRIPTTHREADSTATE
*pstsState
)
581 JScript
*This
= ACTSCRIPT_THIS(iface
);
582 FIXME("(%p)->()\n", This
);
586 static HRESULT WINAPI
JScript_InterruptScriptThread(IActiveScript
*iface
,
587 SCRIPTTHREADID stidThread
, const EXCEPINFO
*pexcepinfo
, DWORD dwFlags
)
589 JScript
*This
= ACTSCRIPT_THIS(iface
);
590 FIXME("(%p)->()\n", This
);
594 static HRESULT WINAPI
JScript_Clone(IActiveScript
*iface
, IActiveScript
**ppscript
)
596 JScript
*This
= ACTSCRIPT_THIS(iface
);
597 FIXME("(%p)->()\n", This
);
601 #undef ACTSCRIPT_THIS
603 static const IActiveScriptVtbl JScriptVtbl
= {
604 JScript_QueryInterface
,
607 JScript_SetScriptSite
,
608 JScript_GetScriptSite
,
609 JScript_SetScriptState
,
610 JScript_GetScriptState
,
612 JScript_AddNamedItem
,
614 JScript_GetScriptDispatch
,
615 JScript_GetCurrentScriptThreadID
,
616 JScript_GetScriptThreadID
,
617 JScript_GetScriptThreadState
,
618 JScript_InterruptScriptThread
,
622 #define ASPARSE_THIS(iface) DEFINE_THIS(JScript, IActiveScriptParse, iface)
624 static HRESULT WINAPI
JScriptParse_QueryInterface(IActiveScriptParse
*iface
, REFIID riid
, void **ppv
)
626 JScript
*This
= ASPARSE_THIS(iface
);
627 return IActiveScript_QueryInterface(ACTSCRIPT(This
), riid
, ppv
);
630 static ULONG WINAPI
JScriptParse_AddRef(IActiveScriptParse
*iface
)
632 JScript
*This
= ASPARSE_THIS(iface
);
633 return IActiveScript_AddRef(ACTSCRIPT(This
));
636 static ULONG WINAPI
JScriptParse_Release(IActiveScriptParse
*iface
)
638 JScript
*This
= ASPARSE_THIS(iface
);
639 return IActiveScript_Release(ACTSCRIPT(This
));
642 static HRESULT WINAPI
JScriptParse_InitNew(IActiveScriptParse
*iface
)
644 JScript
*This
= ASPARSE_THIS(iface
);
647 TRACE("(%p)\n", This
);
652 ctx
= heap_alloc_zero(sizeof(script_ctx_t
));
654 return E_OUTOFMEMORY
;
657 ctx
->state
= SCRIPTSTATE_UNINITIALIZED
;
658 ctx
->safeopt
= This
->safeopt
;
659 ctx
->version
= This
->version
;
660 jsheap_init(&ctx
->tmp_heap
);
662 ctx
= InterlockedCompareExchangePointer((void**)&This
->ctx
, ctx
, NULL
);
668 return This
->site
? set_ctx_site(This
) : S_OK
;
671 static HRESULT WINAPI
JScriptParse_AddScriptlet(IActiveScriptParse
*iface
,
672 LPCOLESTR pstrDefaultName
, LPCOLESTR pstrCode
, LPCOLESTR pstrItemName
,
673 LPCOLESTR pstrSubItemName
, LPCOLESTR pstrEventName
, LPCOLESTR pstrDelimiter
,
674 CTXARG_T dwSourceContextCookie
, ULONG ulStartingLineNumber
, DWORD dwFlags
,
675 BSTR
*pbstrName
, EXCEPINFO
*pexcepinfo
)
677 JScript
*This
= ASPARSE_THIS(iface
);
678 FIXME("(%p)->(%s %s %s %s %s %s %s %u %x %p %p)\n", This
, debugstr_w(pstrDefaultName
),
679 debugstr_w(pstrCode
), debugstr_w(pstrItemName
), debugstr_w(pstrSubItemName
),
680 debugstr_w(pstrEventName
), debugstr_w(pstrDelimiter
), wine_dbgstr_longlong(dwSourceContextCookie
),
681 ulStartingLineNumber
, dwFlags
, pbstrName
, pexcepinfo
);
685 static HRESULT WINAPI
JScriptParse_ParseScriptText(IActiveScriptParse
*iface
,
686 LPCOLESTR pstrCode
, LPCOLESTR pstrItemName
, IUnknown
*punkContext
,
687 LPCOLESTR pstrDelimiter
, CTXARG_T dwSourceContextCookie
, ULONG ulStartingLine
,
688 DWORD dwFlags
, VARIANT
*pvarResult
, EXCEPINFO
*pexcepinfo
)
690 JScript
*This
= ASPARSE_THIS(iface
);
691 parser_ctx_t
*parser_ctx
;
694 TRACE("(%p)->(%s %s %p %s %s %u %x %p %p)\n", This
, debugstr_w(pstrCode
),
695 debugstr_w(pstrItemName
), punkContext
, debugstr_w(pstrDelimiter
),
696 wine_dbgstr_longlong(dwSourceContextCookie
), ulStartingLine
, dwFlags
, pvarResult
, pexcepinfo
);
698 if(This
->thread_id
!= GetCurrentThreadId() || This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
701 hres
= script_parse(This
->ctx
, pstrCode
, pstrDelimiter
, &parser_ctx
);
705 if(!is_started(This
->ctx
)) {
707 This
->queue_tail
= This
->queue_tail
->next
= parser_ctx
;
709 This
->queue_head
= This
->queue_tail
= parser_ctx
;
713 hres
= exec_global_code(This
, parser_ctx
);
714 parser_release(parser_ctx
);
721 static const IActiveScriptParseVtbl JScriptParseVtbl
= {
722 JScriptParse_QueryInterface
,
724 JScriptParse_Release
,
725 JScriptParse_InitNew
,
726 JScriptParse_AddScriptlet
,
727 JScriptParse_ParseScriptText
730 #define ASPARSEPROC_THIS(iface) DEFINE_THIS(JScript, IActiveScriptParseProcedure2, iface)
732 static HRESULT WINAPI
JScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2
*iface
, REFIID riid
, void **ppv
)
734 JScript
*This
= ASPARSEPROC_THIS(iface
);
735 return IActiveScript_QueryInterface(ACTSCRIPT(This
), riid
, ppv
);
738 static ULONG WINAPI
JScriptParseProcedure_AddRef(IActiveScriptParseProcedure2
*iface
)
740 JScript
*This
= ASPARSEPROC_THIS(iface
);
741 return IActiveScript_AddRef(ACTSCRIPT(This
));
744 static ULONG WINAPI
JScriptParseProcedure_Release(IActiveScriptParseProcedure2
*iface
)
746 JScript
*This
= ASPARSEPROC_THIS(iface
);
747 return IActiveScript_Release(ACTSCRIPT(This
));
750 static HRESULT WINAPI
JScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2
*iface
,
751 LPCOLESTR pstrCode
, LPCOLESTR pstrFormalParams
, LPCOLESTR pstrProcedureName
,
752 LPCOLESTR pstrItemName
, IUnknown
*punkContext
, LPCOLESTR pstrDelimiter
,
753 CTXARG_T dwSourceContextCookie
, ULONG ulStartingLineNumber
, DWORD dwFlags
, IDispatch
**ppdisp
)
755 JScript
*This
= ASPARSEPROC_THIS(iface
);
756 parser_ctx_t
*parser_ctx
;
760 TRACE("(%p)->(%s %s %s %s %p %s %s %u %x %p)\n", This
, debugstr_w(pstrCode
), debugstr_w(pstrFormalParams
),
761 debugstr_w(pstrProcedureName
), debugstr_w(pstrItemName
), punkContext
, debugstr_w(pstrDelimiter
),
762 wine_dbgstr_longlong(dwSourceContextCookie
), ulStartingLineNumber
, dwFlags
, ppdisp
);
764 if(This
->thread_id
!= GetCurrentThreadId() || This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
767 hres
= script_parse(This
->ctx
, pstrCode
, pstrDelimiter
, &parser_ctx
);
769 WARN("Parse failed %08x\n", hres
);
773 hres
= create_source_function(parser_ctx
, NULL
, parser_ctx
->source
, NULL
, NULL
, 0, &dispex
);
774 parser_release(parser_ctx
);
778 *ppdisp
= (IDispatch
*)_IDispatchEx_(dispex
);
782 #undef ASPARSEPROC_THIS
784 static const IActiveScriptParseProcedure2Vtbl JScriptParseProcedureVtbl
= {
785 JScriptParseProcedure_QueryInterface
,
786 JScriptParseProcedure_AddRef
,
787 JScriptParseProcedure_Release
,
788 JScriptParseProcedure_ParseProcedureText
,
791 #define ACTSCPPROP_THIS(iface) DEFINE_THIS(JScript, IActiveScriptProperty, iface)
793 static HRESULT WINAPI
JScriptProperty_QueryInterface(IActiveScriptProperty
*iface
, REFIID riid
, void **ppv
)
795 JScript
*This
= ACTSCPPROP_THIS(iface
);
796 return IActiveScript_QueryInterface(ACTSCRIPT(This
), riid
, ppv
);
799 static ULONG WINAPI
JScriptProperty_AddRef(IActiveScriptProperty
*iface
)
801 JScript
*This
= ACTSCPPROP_THIS(iface
);
802 return IActiveScript_AddRef(ACTSCRIPT(This
));
805 static ULONG WINAPI
JScriptProperty_Release(IActiveScriptProperty
*iface
)
807 JScript
*This
= ACTSCPPROP_THIS(iface
);
808 return IActiveScript_Release(ACTSCRIPT(This
));
811 static HRESULT WINAPI
JScriptProperty_GetProperty(IActiveScriptProperty
*iface
, DWORD dwProperty
,
812 VARIANT
*pvarIndex
, VARIANT
*pvarValue
)
814 JScript
*This
= ACTSCPPROP_THIS(iface
);
815 FIXME("(%p)->(%x %p %p)\n", This
, dwProperty
, pvarIndex
, pvarValue
);
819 static HRESULT WINAPI
JScriptProperty_SetProperty(IActiveScriptProperty
*iface
, DWORD dwProperty
,
820 VARIANT
*pvarIndex
, VARIANT
*pvarValue
)
822 JScript
*This
= ACTSCPPROP_THIS(iface
);
824 TRACE("(%p)->(%x %s %s)\n", This
, dwProperty
, debugstr_variant(pvarIndex
), debugstr_variant(pvarValue
));
827 FIXME("unsupported pvarIndex\n");
830 case SCRIPTPROP_INVOKEVERSIONING
:
831 if(V_VT(pvarValue
) != VT_I4
|| V_I4(pvarValue
) < 0 || V_I4(pvarValue
) > 15) {
832 WARN("invalid value %s\n", debugstr_variant(pvarValue
));
836 This
->version
= V_I4(pvarValue
);
839 FIXME("Unimplemented property %x\n", dwProperty
);
846 #undef ACTSCPPROP_THIS
848 static const IActiveScriptPropertyVtbl JScriptPropertyVtbl
= {
849 JScriptProperty_QueryInterface
,
850 JScriptProperty_AddRef
,
851 JScriptProperty_Release
,
852 JScriptProperty_GetProperty
,
853 JScriptProperty_SetProperty
856 #define OBJSAFETY_THIS(iface) DEFINE_THIS(JScript, IObjectSafety, iface)
858 static HRESULT WINAPI
JScriptSafety_QueryInterface(IObjectSafety
*iface
, REFIID riid
, void **ppv
)
860 JScript
*This
= OBJSAFETY_THIS(iface
);
861 return IActiveScript_QueryInterface(ACTSCRIPT(This
), riid
, ppv
);
864 static ULONG WINAPI
JScriptSafety_AddRef(IObjectSafety
*iface
)
866 JScript
*This
= OBJSAFETY_THIS(iface
);
867 return IActiveScript_AddRef(ACTSCRIPT(This
));
870 static ULONG WINAPI
JScriptSafety_Release(IObjectSafety
*iface
)
872 JScript
*This
= OBJSAFETY_THIS(iface
);
873 return IActiveScript_Release(ACTSCRIPT(This
));
876 #define SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER)
878 static HRESULT WINAPI
JScriptSafety_GetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
879 DWORD
*pdwSupportedOptions
, DWORD
*pdwEnabledOptions
)
881 JScript
*This
= OBJSAFETY_THIS(iface
);
883 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_guid(riid
), pdwSupportedOptions
, pdwEnabledOptions
);
885 if(!pdwSupportedOptions
|| !pdwEnabledOptions
)
888 *pdwSupportedOptions
= SUPPORTED_OPTIONS
;
889 *pdwEnabledOptions
= This
->safeopt
;
894 static HRESULT WINAPI
JScriptSafety_SetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
895 DWORD dwOptionSetMask
, DWORD dwEnabledOptions
)
897 JScript
*This
= OBJSAFETY_THIS(iface
);
899 TRACE("(%p)->(%s %x %x)\n", This
, debugstr_guid(riid
), dwOptionSetMask
, dwEnabledOptions
);
901 if(dwOptionSetMask
& ~SUPPORTED_OPTIONS
)
904 This
->safeopt
= dwEnabledOptions
& dwEnabledOptions
;
908 #undef OBJSAFETY_THIS
910 static const IObjectSafetyVtbl JScriptSafetyVtbl
= {
911 JScriptSafety_QueryInterface
,
912 JScriptSafety_AddRef
,
913 JScriptSafety_Release
,
914 JScriptSafety_GetInterfaceSafetyOptions
,
915 JScriptSafety_SetInterfaceSafetyOptions
918 HRESULT WINAPI
JScriptFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*pUnkOuter
,
919 REFIID riid
, void **ppv
)
924 TRACE("(%p %s %p)\n", pUnkOuter
, debugstr_guid(riid
), ppv
);
928 ret
= heap_alloc_zero(sizeof(*ret
));
930 return E_OUTOFMEMORY
;
932 ret
->lpIActiveScriptVtbl
= &JScriptVtbl
;
933 ret
->lpIActiveScriptParseVtbl
= &JScriptParseVtbl
;
934 ret
->lpIActiveScriptParseProcedure2Vtbl
= &JScriptParseProcedureVtbl
;
935 ret
->lpIActiveScriptPropertyVtbl
= &JScriptPropertyVtbl
;
936 ret
->lpIObjectSafetyVtbl
= &JScriptSafetyVtbl
;
938 ret
->safeopt
= INTERFACE_USES_DISPEX
;
940 hres
= IActiveScript_QueryInterface(ACTSCRIPT(ret
), riid
, ppv
);
941 IActiveScript_Release(ACTSCRIPT(ret
));