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
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(jscript
);
31 #define CTXARG_T DWORDLONG
32 #define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
33 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_64Vtbl
37 #define CTXARG_T DWORD
38 #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
39 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_32Vtbl
44 IActiveScript IActiveScript_iface
;
45 IActiveScriptParse IActiveScriptParse_iface
;
46 IActiveScriptParseProcedure2 IActiveScriptParseProcedure2_iface
;
47 IActiveScriptProperty IActiveScriptProperty_iface
;
48 IObjectSafety IObjectSafety_iface
;
58 IActiveScriptSite
*site
;
60 parser_ctx_t
*queue_head
;
61 parser_ctx_t
*queue_tail
;
64 void script_release(script_ctx_t
*ctx
)
71 jsheap_free(&ctx
->tmp_heap
);
72 SysFreeString(ctx
->last_match
);
76 static void change_state(JScript
*This
, SCRIPTSTATE state
)
78 if(This
->ctx
->state
== state
)
81 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
, TRUE
, &exec_ctx
);
103 IActiveScriptSite_OnEnterScript(This
->site
);
105 memset(&jsexcept
, 0, sizeof(jsexcept
));
106 hres
= exec_source(exec_ctx
, parser_ctx
, parser_ctx
->source
, FALSE
, &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
);
159 static void decrease_state(JScript
*This
, SCRIPTSTATE state
)
162 switch(This
->ctx
->state
) {
163 case SCRIPTSTATE_CONNECTED
:
164 change_state(This
, SCRIPTSTATE_DISCONNECTED
);
165 if(state
== SCRIPTSTATE_DISCONNECTED
)
168 case SCRIPTSTATE_STARTED
:
169 case SCRIPTSTATE_DISCONNECTED
:
170 clear_script_queue(This
);
172 if(This
->ctx
->state
== SCRIPTSTATE_DISCONNECTED
)
173 change_state(This
, SCRIPTSTATE_INITIALIZED
);
174 if(state
== SCRIPTSTATE_INITIALIZED
)
177 case SCRIPTSTATE_INITIALIZED
:
178 if(This
->ctx
->host_global
) {
179 IDispatch_Release(This
->ctx
->host_global
);
180 This
->ctx
->host_global
= NULL
;
183 if(This
->ctx
->named_items
) {
184 named_item_t
*iter
, *iter2
;
186 iter
= This
->ctx
->named_items
;
191 IDispatch_Release(iter
->disp
);
192 heap_free(iter
->name
);
197 This
->ctx
->named_items
= NULL
;
200 if(This
->ctx
->secmgr
) {
201 IInternetHostSecurityManager_Release(This
->ctx
->secmgr
);
202 This
->ctx
->secmgr
= NULL
;
205 if(This
->ctx
->site
) {
206 IActiveScriptSite_Release(This
->ctx
->site
);
207 This
->ctx
->site
= NULL
;
210 if(This
->ctx
->global
) {
211 jsdisp_release(This
->ctx
->global
);
212 This
->ctx
->global
= NULL
;
215 case SCRIPTSTATE_UNINITIALIZED
:
216 change_state(This
, state
);
222 change_state(This
, state
);
223 }else if(state
== SCRIPTSTATE_UNINITIALIZED
) {
225 IActiveScriptSite_OnStateChange(This
->site
, state
);
230 if(state
== SCRIPTSTATE_UNINITIALIZED
)
234 IActiveScriptSite_Release(This
->site
);
240 IServiceProvider IServiceProvider_iface
;
244 IServiceProvider
*sp
;
247 static inline AXSite
*impl_from_IServiceProvider(IServiceProvider
*iface
)
249 return CONTAINING_RECORD(iface
, AXSite
, IServiceProvider_iface
);
252 static HRESULT WINAPI
AXSite_QueryInterface(IServiceProvider
*iface
, REFIID riid
, void **ppv
)
254 AXSite
*This
= impl_from_IServiceProvider(iface
);
256 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
257 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
258 *ppv
= &This
->IServiceProvider_iface
;
259 }else if(IsEqualGUID(&IID_IServiceProvider
, riid
)) {
260 TRACE("(%p)->(IID_IServiceProvider %p)\n", This
, ppv
);
261 *ppv
= &This
->IServiceProvider_iface
;
263 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
265 return E_NOINTERFACE
;
268 IUnknown_AddRef((IUnknown
*)*ppv
);
272 static ULONG WINAPI
AXSite_AddRef(IServiceProvider
*iface
)
274 AXSite
*This
= impl_from_IServiceProvider(iface
);
275 LONG ref
= InterlockedIncrement(&This
->ref
);
277 TRACE("(%p) ref=%d\n", This
, ref
);
282 static ULONG WINAPI
AXSite_Release(IServiceProvider
*iface
)
284 AXSite
*This
= impl_from_IServiceProvider(iface
);
285 LONG ref
= InterlockedDecrement(&This
->ref
);
287 TRACE("(%p) ref=%d\n", This
, ref
);
292 IServiceProvider_Release(This
->sp
);
300 static HRESULT WINAPI
AXSite_QueryService(IServiceProvider
*iface
,
301 REFGUID guidService
, REFIID riid
, void **ppv
)
303 AXSite
*This
= impl_from_IServiceProvider(iface
);
305 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_guid(guidService
), debugstr_guid(riid
), ppv
);
308 return E_NOINTERFACE
;
310 return IServiceProvider_QueryService(This
->sp
, guidService
, riid
, ppv
);
313 static IServiceProviderVtbl AXSiteVtbl
= {
314 AXSite_QueryInterface
,
320 IUnknown
*create_ax_site(script_ctx_t
*ctx
)
322 IServiceProvider
*sp
= NULL
;
326 hres
= IActiveScriptSite_QueryInterface(ctx
->site
, &IID_IServiceProvider
, (void**)&sp
);
328 TRACE("Could not get IServiceProvider iface: %08x\n", hres
);
331 ret
= heap_alloc(sizeof(AXSite
));
333 IServiceProvider_Release(sp
);
337 ret
->IServiceProvider_iface
.lpVtbl
= &AXSiteVtbl
;
341 return (IUnknown
*)&ret
->IServiceProvider_iface
;
344 static inline JScript
*impl_from_IActiveScript(IActiveScript
*iface
)
346 return CONTAINING_RECORD(iface
, JScript
, IActiveScript_iface
);
349 static HRESULT WINAPI
JScript_QueryInterface(IActiveScript
*iface
, REFIID riid
, void **ppv
)
351 JScript
*This
= impl_from_IActiveScript(iface
);
355 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
356 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
357 *ppv
= &This
->IActiveScript_iface
;
358 }else if(IsEqualGUID(riid
, &IID_IActiveScript
)) {
359 TRACE("(%p)->(IID_IActiveScript %p)\n", This
, ppv
);
360 *ppv
= &This
->IActiveScript_iface
;
361 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParse
)) {
362 TRACE("(%p)->(IID_IActiveScriptParse %p)\n", This
, ppv
);
363 *ppv
= &This
->IActiveScriptParse_iface
;
364 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParseProcedure
)) {
365 TRACE("(%p)->(IID_IActiveScriptParseProcedure %p)\n", This
, ppv
);
366 *ppv
= &This
->IActiveScriptParseProcedure2_iface
;
367 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParseProcedure2
)) {
368 TRACE("(%p)->(IID_IActiveScriptParseProcedure2 %p)\n", This
, ppv
);
369 *ppv
= &This
->IActiveScriptParseProcedure2_iface
;
370 }else if(IsEqualGUID(riid
, &IID_IActiveScriptProperty
)) {
371 TRACE("(%p)->(IID_IActiveScriptProperty %p)\n", This
, ppv
);
372 *ppv
= &This
->IActiveScriptProperty_iface
;
373 }else if(IsEqualGUID(riid
, &IID_IObjectSafety
)) {
374 TRACE("(%p)->(IID_IObjectSafety %p)\n", This
, ppv
);
375 *ppv
= &This
->IObjectSafety_iface
;
379 IUnknown_AddRef((IUnknown
*)*ppv
);
383 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
384 return E_NOINTERFACE
;
387 static ULONG WINAPI
JScript_AddRef(IActiveScript
*iface
)
389 JScript
*This
= impl_from_IActiveScript(iface
);
390 LONG ref
= InterlockedIncrement(&This
->ref
);
392 TRACE("(%p) ref=%d\n", This
, ref
);
397 static ULONG WINAPI
JScript_Release(IActiveScript
*iface
)
399 JScript
*This
= impl_from_IActiveScript(iface
);
400 LONG ref
= InterlockedDecrement(&This
->ref
);
402 TRACE("(%p) ref=%d\n", iface
, ref
);
405 if(This
->ctx
&& This
->ctx
->state
!= SCRIPTSTATE_CLOSED
)
406 IActiveScript_Close(&This
->IActiveScript_iface
);
408 script_release(This
->ctx
);
416 static HRESULT WINAPI
JScript_SetScriptSite(IActiveScript
*iface
,
417 IActiveScriptSite
*pass
)
419 JScript
*This
= impl_from_IActiveScript(iface
);
423 TRACE("(%p)->(%p)\n", This
, pass
);
431 if(InterlockedCompareExchange(&This
->thread_id
, GetCurrentThreadId(), 0))
435 IActiveScriptSite_AddRef(This
->site
);
437 hres
= IActiveScriptSite_GetLCID(This
->site
, &lcid
);
441 return This
->ctx
? set_ctx_site(This
) : S_OK
;
444 static HRESULT WINAPI
JScript_GetScriptSite(IActiveScript
*iface
, REFIID riid
,
447 JScript
*This
= impl_from_IActiveScript(iface
);
448 FIXME("(%p)->()\n", This
);
452 static HRESULT WINAPI
JScript_SetScriptState(IActiveScript
*iface
, SCRIPTSTATE ss
)
454 JScript
*This
= impl_from_IActiveScript(iface
);
456 TRACE("(%p)->(%d)\n", This
, ss
);
458 if(This
->thread_id
&& GetCurrentThreadId() != This
->thread_id
)
461 if(ss
== SCRIPTSTATE_UNINITIALIZED
) {
462 if(This
->ctx
&& This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
465 decrease_state(This
, SCRIPTSTATE_UNINITIALIZED
);
473 case SCRIPTSTATE_STARTED
:
474 case SCRIPTSTATE_CONNECTED
: /* FIXME */
475 if(This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
478 exec_queued_code(This
);
480 case SCRIPTSTATE_INITIALIZED
:
481 FIXME("unimplemented SCRIPTSTATE_INITIALIZED\n");
484 FIXME("unimplemented state %d\n", ss
);
488 change_state(This
, ss
);
492 static HRESULT WINAPI
JScript_GetScriptState(IActiveScript
*iface
, SCRIPTSTATE
*pssState
)
494 JScript
*This
= impl_from_IActiveScript(iface
);
496 TRACE("(%p)->(%p)\n", This
, pssState
);
501 if(This
->thread_id
&& This
->thread_id
!= GetCurrentThreadId())
504 *pssState
= This
->ctx
? This
->ctx
->state
: SCRIPTSTATE_UNINITIALIZED
;
508 static HRESULT WINAPI
JScript_Close(IActiveScript
*iface
)
510 JScript
*This
= impl_from_IActiveScript(iface
);
512 TRACE("(%p)->()\n", This
);
514 if(This
->thread_id
&& This
->thread_id
!= GetCurrentThreadId())
517 decrease_state(This
, SCRIPTSTATE_CLOSED
);
521 static HRESULT WINAPI
JScript_AddNamedItem(IActiveScript
*iface
,
522 LPCOLESTR pstrName
, DWORD dwFlags
)
524 JScript
*This
= impl_from_IActiveScript(iface
);
526 IDispatch
*disp
= NULL
;
529 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(pstrName
), dwFlags
);
531 if(This
->thread_id
!= GetCurrentThreadId() || !This
->ctx
|| This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
534 if(dwFlags
& SCRIPTITEM_GLOBALMEMBERS
) {
537 hres
= IActiveScriptSite_GetItemInfo(This
->site
, pstrName
, SCRIPTINFO_IUNKNOWN
, &unk
, NULL
);
539 WARN("GetItemInfo failed: %08x\n", hres
);
543 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatch
, (void**)&disp
);
544 IUnknown_Release(unk
);
546 WARN("object does not implement IDispatch\n");
550 if(This
->ctx
->host_global
)
551 IDispatch_Release(This
->ctx
->host_global
);
552 IDispatch_AddRef(disp
);
553 This
->ctx
->host_global
= disp
;
556 item
= heap_alloc(sizeof(*item
));
559 IDispatch_Release(disp
);
560 return E_OUTOFMEMORY
;
564 item
->flags
= dwFlags
;
565 item
->name
= heap_strdupW(pstrName
);
568 IDispatch_Release(disp
);
570 return E_OUTOFMEMORY
;
573 item
->next
= This
->ctx
->named_items
;
574 This
->ctx
->named_items
= item
;
579 static HRESULT WINAPI
JScript_AddTypeLib(IActiveScript
*iface
, REFGUID rguidTypeLib
,
580 DWORD dwMajor
, DWORD dwMinor
, DWORD dwFlags
)
582 JScript
*This
= impl_from_IActiveScript(iface
);
583 FIXME("(%p)->()\n", This
);
587 static HRESULT WINAPI
JScript_GetScriptDispatch(IActiveScript
*iface
, LPCOLESTR pstrItemName
,
590 JScript
*This
= impl_from_IActiveScript(iface
);
592 TRACE("(%p)->(%p)\n", This
, ppdisp
);
597 if(This
->thread_id
!= GetCurrentThreadId() || !This
->ctx
->global
) {
602 *ppdisp
= to_disp(This
->ctx
->global
);
603 IDispatch_AddRef(*ppdisp
);
607 static HRESULT WINAPI
JScript_GetCurrentScriptThreadID(IActiveScript
*iface
,
608 SCRIPTTHREADID
*pstridThread
)
610 JScript
*This
= impl_from_IActiveScript(iface
);
611 FIXME("(%p)->()\n", This
);
615 static HRESULT WINAPI
JScript_GetScriptThreadID(IActiveScript
*iface
,
616 DWORD dwWin32ThreadId
, SCRIPTTHREADID
*pstidThread
)
618 JScript
*This
= impl_from_IActiveScript(iface
);
619 FIXME("(%p)->()\n", This
);
623 static HRESULT WINAPI
JScript_GetScriptThreadState(IActiveScript
*iface
,
624 SCRIPTTHREADID stidThread
, SCRIPTTHREADSTATE
*pstsState
)
626 JScript
*This
= impl_from_IActiveScript(iface
);
627 FIXME("(%p)->()\n", This
);
631 static HRESULT WINAPI
JScript_InterruptScriptThread(IActiveScript
*iface
,
632 SCRIPTTHREADID stidThread
, const EXCEPINFO
*pexcepinfo
, DWORD dwFlags
)
634 JScript
*This
= impl_from_IActiveScript(iface
);
635 FIXME("(%p)->()\n", This
);
639 static HRESULT WINAPI
JScript_Clone(IActiveScript
*iface
, IActiveScript
**ppscript
)
641 JScript
*This
= impl_from_IActiveScript(iface
);
642 FIXME("(%p)->()\n", This
);
646 static const IActiveScriptVtbl JScriptVtbl
= {
647 JScript_QueryInterface
,
650 JScript_SetScriptSite
,
651 JScript_GetScriptSite
,
652 JScript_SetScriptState
,
653 JScript_GetScriptState
,
655 JScript_AddNamedItem
,
657 JScript_GetScriptDispatch
,
658 JScript_GetCurrentScriptThreadID
,
659 JScript_GetScriptThreadID
,
660 JScript_GetScriptThreadState
,
661 JScript_InterruptScriptThread
,
665 static inline JScript
*impl_from_IActiveScriptParse(IActiveScriptParse
*iface
)
667 return CONTAINING_RECORD(iface
, JScript
, IActiveScriptParse_iface
);
670 static HRESULT WINAPI
JScriptParse_QueryInterface(IActiveScriptParse
*iface
, REFIID riid
, void **ppv
)
672 JScript
*This
= impl_from_IActiveScriptParse(iface
);
673 return IActiveScript_QueryInterface(&This
->IActiveScript_iface
, riid
, ppv
);
676 static ULONG WINAPI
JScriptParse_AddRef(IActiveScriptParse
*iface
)
678 JScript
*This
= impl_from_IActiveScriptParse(iface
);
679 return IActiveScript_AddRef(&This
->IActiveScript_iface
);
682 static ULONG WINAPI
JScriptParse_Release(IActiveScriptParse
*iface
)
684 JScript
*This
= impl_from_IActiveScriptParse(iface
);
685 return IActiveScript_Release(&This
->IActiveScript_iface
);
688 static HRESULT WINAPI
JScriptParse_InitNew(IActiveScriptParse
*iface
)
690 JScript
*This
= impl_from_IActiveScriptParse(iface
);
693 TRACE("(%p)\n", This
);
698 ctx
= heap_alloc_zero(sizeof(script_ctx_t
));
700 return E_OUTOFMEMORY
;
703 ctx
->state
= SCRIPTSTATE_UNINITIALIZED
;
704 ctx
->safeopt
= This
->safeopt
;
705 ctx
->version
= This
->version
;
706 jsheap_init(&ctx
->tmp_heap
);
708 ctx
= InterlockedCompareExchangePointer((void**)&This
->ctx
, ctx
, NULL
);
714 return This
->site
? set_ctx_site(This
) : S_OK
;
717 static HRESULT WINAPI
JScriptParse_AddScriptlet(IActiveScriptParse
*iface
,
718 LPCOLESTR pstrDefaultName
, LPCOLESTR pstrCode
, LPCOLESTR pstrItemName
,
719 LPCOLESTR pstrSubItemName
, LPCOLESTR pstrEventName
, LPCOLESTR pstrDelimiter
,
720 CTXARG_T dwSourceContextCookie
, ULONG ulStartingLineNumber
, DWORD dwFlags
,
721 BSTR
*pbstrName
, EXCEPINFO
*pexcepinfo
)
723 JScript
*This
= impl_from_IActiveScriptParse(iface
);
724 FIXME("(%p)->(%s %s %s %s %s %s %s %u %x %p %p)\n", This
, debugstr_w(pstrDefaultName
),
725 debugstr_w(pstrCode
), debugstr_w(pstrItemName
), debugstr_w(pstrSubItemName
),
726 debugstr_w(pstrEventName
), debugstr_w(pstrDelimiter
), wine_dbgstr_longlong(dwSourceContextCookie
),
727 ulStartingLineNumber
, dwFlags
, pbstrName
, pexcepinfo
);
731 static HRESULT WINAPI
JScriptParse_ParseScriptText(IActiveScriptParse
*iface
,
732 LPCOLESTR pstrCode
, LPCOLESTR pstrItemName
, IUnknown
*punkContext
,
733 LPCOLESTR pstrDelimiter
, CTXARG_T dwSourceContextCookie
, ULONG ulStartingLine
,
734 DWORD dwFlags
, VARIANT
*pvarResult
, EXCEPINFO
*pexcepinfo
)
736 JScript
*This
= impl_from_IActiveScriptParse(iface
);
737 parser_ctx_t
*parser_ctx
;
740 TRACE("(%p)->(%s %s %p %s %s %u %x %p %p)\n", This
, debugstr_w(pstrCode
),
741 debugstr_w(pstrItemName
), punkContext
, debugstr_w(pstrDelimiter
),
742 wine_dbgstr_longlong(dwSourceContextCookie
), ulStartingLine
, dwFlags
, pvarResult
, pexcepinfo
);
744 if(This
->thread_id
!= GetCurrentThreadId() || This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
747 hres
= script_parse(This
->ctx
, pstrCode
, pstrDelimiter
, &parser_ctx
);
751 if(!is_started(This
->ctx
)) {
753 This
->queue_tail
= This
->queue_tail
->next
= parser_ctx
;
755 This
->queue_head
= This
->queue_tail
= parser_ctx
;
759 hres
= exec_global_code(This
, parser_ctx
);
760 parser_release(parser_ctx
);
765 static const IActiveScriptParseVtbl JScriptParseVtbl
= {
766 JScriptParse_QueryInterface
,
768 JScriptParse_Release
,
769 JScriptParse_InitNew
,
770 JScriptParse_AddScriptlet
,
771 JScriptParse_ParseScriptText
774 static inline JScript
*impl_from_IActiveScriptParseProcedure2(IActiveScriptParseProcedure2
*iface
)
776 return CONTAINING_RECORD(iface
, JScript
, IActiveScriptParseProcedure2_iface
);
779 static HRESULT WINAPI
JScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2
*iface
, REFIID riid
, void **ppv
)
781 JScript
*This
= impl_from_IActiveScriptParseProcedure2(iface
);
782 return IActiveScript_QueryInterface(&This
->IActiveScript_iface
, riid
, ppv
);
785 static ULONG WINAPI
JScriptParseProcedure_AddRef(IActiveScriptParseProcedure2
*iface
)
787 JScript
*This
= impl_from_IActiveScriptParseProcedure2(iface
);
788 return IActiveScript_AddRef(&This
->IActiveScript_iface
);
791 static ULONG WINAPI
JScriptParseProcedure_Release(IActiveScriptParseProcedure2
*iface
)
793 JScript
*This
= impl_from_IActiveScriptParseProcedure2(iface
);
794 return IActiveScript_Release(&This
->IActiveScript_iface
);
797 static HRESULT WINAPI
JScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2
*iface
,
798 LPCOLESTR pstrCode
, LPCOLESTR pstrFormalParams
, LPCOLESTR pstrProcedureName
,
799 LPCOLESTR pstrItemName
, IUnknown
*punkContext
, LPCOLESTR pstrDelimiter
,
800 CTXARG_T dwSourceContextCookie
, ULONG ulStartingLineNumber
, DWORD dwFlags
, IDispatch
**ppdisp
)
802 JScript
*This
= impl_from_IActiveScriptParseProcedure2(iface
);
803 parser_ctx_t
*parser_ctx
;
807 TRACE("(%p)->(%s %s %s %s %p %s %s %u %x %p)\n", This
, debugstr_w(pstrCode
), debugstr_w(pstrFormalParams
),
808 debugstr_w(pstrProcedureName
), debugstr_w(pstrItemName
), punkContext
, debugstr_w(pstrDelimiter
),
809 wine_dbgstr_longlong(dwSourceContextCookie
), ulStartingLineNumber
, dwFlags
, ppdisp
);
811 if(This
->thread_id
!= GetCurrentThreadId() || This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
814 hres
= script_parse(This
->ctx
, pstrCode
, pstrDelimiter
, &parser_ctx
);
816 WARN("Parse failed %08x\n", hres
);
820 hres
= create_source_function(parser_ctx
, NULL
, parser_ctx
->source
, NULL
, NULL
, 0, &dispex
);
821 parser_release(parser_ctx
);
825 *ppdisp
= to_disp(dispex
);
829 static const IActiveScriptParseProcedure2Vtbl JScriptParseProcedureVtbl
= {
830 JScriptParseProcedure_QueryInterface
,
831 JScriptParseProcedure_AddRef
,
832 JScriptParseProcedure_Release
,
833 JScriptParseProcedure_ParseProcedureText
,
836 static inline JScript
*impl_from_IActiveScriptProperty(IActiveScriptProperty
*iface
)
838 return CONTAINING_RECORD(iface
, JScript
, IActiveScriptProperty_iface
);
841 static HRESULT WINAPI
JScriptProperty_QueryInterface(IActiveScriptProperty
*iface
, REFIID riid
, void **ppv
)
843 JScript
*This
= impl_from_IActiveScriptProperty(iface
);
844 return IActiveScript_QueryInterface(&This
->IActiveScript_iface
, riid
, ppv
);
847 static ULONG WINAPI
JScriptProperty_AddRef(IActiveScriptProperty
*iface
)
849 JScript
*This
= impl_from_IActiveScriptProperty(iface
);
850 return IActiveScript_AddRef(&This
->IActiveScript_iface
);
853 static ULONG WINAPI
JScriptProperty_Release(IActiveScriptProperty
*iface
)
855 JScript
*This
= impl_from_IActiveScriptProperty(iface
);
856 return IActiveScript_Release(&This
->IActiveScript_iface
);
859 static HRESULT WINAPI
JScriptProperty_GetProperty(IActiveScriptProperty
*iface
, DWORD dwProperty
,
860 VARIANT
*pvarIndex
, VARIANT
*pvarValue
)
862 JScript
*This
= impl_from_IActiveScriptProperty(iface
);
863 FIXME("(%p)->(%x %p %p)\n", This
, dwProperty
, pvarIndex
, pvarValue
);
867 static HRESULT WINAPI
JScriptProperty_SetProperty(IActiveScriptProperty
*iface
, DWORD dwProperty
,
868 VARIANT
*pvarIndex
, VARIANT
*pvarValue
)
870 JScript
*This
= impl_from_IActiveScriptProperty(iface
);
872 TRACE("(%p)->(%x %s %s)\n", This
, dwProperty
, debugstr_variant(pvarIndex
), debugstr_variant(pvarValue
));
875 FIXME("unsupported pvarIndex\n");
878 case SCRIPTPROP_INVOKEVERSIONING
:
879 if(V_VT(pvarValue
) != VT_I4
|| V_I4(pvarValue
) < 0 || V_I4(pvarValue
) > 15) {
880 WARN("invalid value %s\n", debugstr_variant(pvarValue
));
884 This
->version
= V_I4(pvarValue
);
887 FIXME("Unimplemented property %x\n", dwProperty
);
894 static const IActiveScriptPropertyVtbl JScriptPropertyVtbl
= {
895 JScriptProperty_QueryInterface
,
896 JScriptProperty_AddRef
,
897 JScriptProperty_Release
,
898 JScriptProperty_GetProperty
,
899 JScriptProperty_SetProperty
902 static inline JScript
*impl_from_IObjectSafety(IObjectSafety
*iface
)
904 return CONTAINING_RECORD(iface
, JScript
, IObjectSafety_iface
);
907 static HRESULT WINAPI
JScriptSafety_QueryInterface(IObjectSafety
*iface
, REFIID riid
, void **ppv
)
909 JScript
*This
= impl_from_IObjectSafety(iface
);
910 return IActiveScript_QueryInterface(&This
->IActiveScript_iface
, riid
, ppv
);
913 static ULONG WINAPI
JScriptSafety_AddRef(IObjectSafety
*iface
)
915 JScript
*This
= impl_from_IObjectSafety(iface
);
916 return IActiveScript_AddRef(&This
->IActiveScript_iface
);
919 static ULONG WINAPI
JScriptSafety_Release(IObjectSafety
*iface
)
921 JScript
*This
= impl_from_IObjectSafety(iface
);
922 return IActiveScript_Release(&This
->IActiveScript_iface
);
925 #define SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER)
927 static HRESULT WINAPI
JScriptSafety_GetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
928 DWORD
*pdwSupportedOptions
, DWORD
*pdwEnabledOptions
)
930 JScript
*This
= impl_from_IObjectSafety(iface
);
932 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_guid(riid
), pdwSupportedOptions
, pdwEnabledOptions
);
934 if(!pdwSupportedOptions
|| !pdwEnabledOptions
)
937 *pdwSupportedOptions
= SUPPORTED_OPTIONS
;
938 *pdwEnabledOptions
= This
->safeopt
;
943 static HRESULT WINAPI
JScriptSafety_SetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
944 DWORD dwOptionSetMask
, DWORD dwEnabledOptions
)
946 JScript
*This
= impl_from_IObjectSafety(iface
);
948 TRACE("(%p)->(%s %x %x)\n", This
, debugstr_guid(riid
), dwOptionSetMask
, dwEnabledOptions
);
950 if(dwOptionSetMask
& ~SUPPORTED_OPTIONS
)
953 This
->safeopt
= (dwEnabledOptions
& dwOptionSetMask
) | (This
->safeopt
& ~dwOptionSetMask
) | INTERFACE_USES_DISPEX
;
957 static const IObjectSafetyVtbl JScriptSafetyVtbl
= {
958 JScriptSafety_QueryInterface
,
959 JScriptSafety_AddRef
,
960 JScriptSafety_Release
,
961 JScriptSafety_GetInterfaceSafetyOptions
,
962 JScriptSafety_SetInterfaceSafetyOptions
965 HRESULT WINAPI
JScriptFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*pUnkOuter
,
966 REFIID riid
, void **ppv
)
971 TRACE("(%p %s %p)\n", pUnkOuter
, debugstr_guid(riid
), ppv
);
975 return CLASS_E_NOAGGREGATION
;
980 ret
= heap_alloc_zero(sizeof(*ret
));
982 return E_OUTOFMEMORY
;
984 ret
->IActiveScript_iface
.lpVtbl
= &JScriptVtbl
;
985 ret
->IActiveScriptParse_iface
.lpVtbl
= &JScriptParseVtbl
;
986 ret
->IActiveScriptParseProcedure2_iface
.lpVtbl
= &JScriptParseProcedureVtbl
;
987 ret
->IActiveScriptProperty_iface
.lpVtbl
= &JScriptPropertyVtbl
;
988 ret
->IObjectSafety_iface
.lpVtbl
= &JScriptSafetyVtbl
;
990 ret
->safeopt
= INTERFACE_USES_DISPEX
;
992 hres
= IActiveScript_QueryInterface(&ret
->IActiveScript_iface
, riid
, ppv
);
993 IActiveScript_Release(&ret
->IActiveScript_iface
);