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
);
295 static HRESULT WINAPI
AXSite_QueryService(IServiceProvider
*iface
,
296 REFGUID guidService
, REFIID riid
, void **ppv
)
298 AXSite
*This
= impl_from_IServiceProvider(iface
);
300 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_guid(guidService
), debugstr_guid(riid
), ppv
);
302 return IServiceProvider_QueryService(This
->sp
, guidService
, riid
, ppv
);
305 static IServiceProviderVtbl AXSiteVtbl
= {
306 AXSite_QueryInterface
,
312 IUnknown
*create_ax_site(script_ctx_t
*ctx
)
314 IServiceProvider
*sp
;
318 hres
= IActiveScriptSite_QueryInterface(ctx
->site
, &IID_IServiceProvider
, (void**)&sp
);
320 ERR("Could not get IServiceProvider iface: %08x\n", hres
);
324 ret
= heap_alloc(sizeof(AXSite
));
326 IServiceProvider_Release(sp
);
330 ret
->IServiceProvider_iface
.lpVtbl
= &AXSiteVtbl
;
334 return (IUnknown
*)&ret
->IServiceProvider_iface
;
337 static inline JScript
*impl_from_IActiveScript(IActiveScript
*iface
)
339 return CONTAINING_RECORD(iface
, JScript
, IActiveScript_iface
);
342 static HRESULT WINAPI
JScript_QueryInterface(IActiveScript
*iface
, REFIID riid
, void **ppv
)
344 JScript
*This
= impl_from_IActiveScript(iface
);
348 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
349 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
350 *ppv
= &This
->IActiveScript_iface
;
351 }else if(IsEqualGUID(riid
, &IID_IActiveScript
)) {
352 TRACE("(%p)->(IID_IActiveScript %p)\n", This
, ppv
);
353 *ppv
= &This
->IActiveScript_iface
;
354 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParse
)) {
355 TRACE("(%p)->(IID_IActiveScriptParse %p)\n", This
, ppv
);
356 *ppv
= &This
->IActiveScriptParse_iface
;
357 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParseProcedure
)) {
358 TRACE("(%p)->(IID_IActiveScriptParseProcedure %p)\n", This
, ppv
);
359 *ppv
= &This
->IActiveScriptParseProcedure2_iface
;
360 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParseProcedure2
)) {
361 TRACE("(%p)->(IID_IActiveScriptParseProcedure2 %p)\n", This
, ppv
);
362 *ppv
= &This
->IActiveScriptParseProcedure2_iface
;
363 }else if(IsEqualGUID(riid
, &IID_IActiveScriptProperty
)) {
364 TRACE("(%p)->(IID_IActiveScriptProperty %p)\n", This
, ppv
);
365 *ppv
= &This
->IActiveScriptProperty_iface
;
366 }else if(IsEqualGUID(riid
, &IID_IObjectSafety
)) {
367 TRACE("(%p)->(IID_IObjectSafety %p)\n", This
, ppv
);
368 *ppv
= &This
->IObjectSafety_iface
;
372 IUnknown_AddRef((IUnknown
*)*ppv
);
376 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
377 return E_NOINTERFACE
;
380 static ULONG WINAPI
JScript_AddRef(IActiveScript
*iface
)
382 JScript
*This
= impl_from_IActiveScript(iface
);
383 LONG ref
= InterlockedIncrement(&This
->ref
);
385 TRACE("(%p) ref=%d\n", This
, ref
);
390 static ULONG WINAPI
JScript_Release(IActiveScript
*iface
)
392 JScript
*This
= impl_from_IActiveScript(iface
);
393 LONG ref
= InterlockedDecrement(&This
->ref
);
395 TRACE("(%p) ref=%d\n", iface
, ref
);
398 if(This
->ctx
&& This
->ctx
->state
!= SCRIPTSTATE_CLOSED
)
399 IActiveScript_Close(&This
->IActiveScript_iface
);
401 script_release(This
->ctx
);
409 static HRESULT WINAPI
JScript_SetScriptSite(IActiveScript
*iface
,
410 IActiveScriptSite
*pass
)
412 JScript
*This
= impl_from_IActiveScript(iface
);
416 TRACE("(%p)->(%p)\n", This
, pass
);
424 if(InterlockedCompareExchange(&This
->thread_id
, GetCurrentThreadId(), 0))
428 IActiveScriptSite_AddRef(This
->site
);
430 hres
= IActiveScriptSite_GetLCID(This
->site
, &lcid
);
434 return This
->ctx
? set_ctx_site(This
) : S_OK
;
437 static HRESULT WINAPI
JScript_GetScriptSite(IActiveScript
*iface
, REFIID riid
,
440 JScript
*This
= impl_from_IActiveScript(iface
);
441 FIXME("(%p)->()\n", This
);
445 static HRESULT WINAPI
JScript_SetScriptState(IActiveScript
*iface
, SCRIPTSTATE ss
)
447 JScript
*This
= impl_from_IActiveScript(iface
);
449 TRACE("(%p)->(%d)\n", This
, ss
);
451 if(This
->thread_id
&& GetCurrentThreadId() != This
->thread_id
)
454 if(ss
== SCRIPTSTATE_UNINITIALIZED
) {
455 if(This
->ctx
&& This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
458 decrease_state(This
, SCRIPTSTATE_UNINITIALIZED
);
466 case SCRIPTSTATE_STARTED
:
467 case SCRIPTSTATE_CONNECTED
: /* FIXME */
468 if(This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
471 exec_queued_code(This
);
473 case SCRIPTSTATE_INITIALIZED
:
474 FIXME("unimplemented SCRIPTSTATE_INITIALIZED\n");
477 FIXME("unimplemented state %d\n", ss
);
481 change_state(This
, ss
);
485 static HRESULT WINAPI
JScript_GetScriptState(IActiveScript
*iface
, SCRIPTSTATE
*pssState
)
487 JScript
*This
= impl_from_IActiveScript(iface
);
489 TRACE("(%p)->(%p)\n", This
, pssState
);
494 if(This
->thread_id
&& This
->thread_id
!= GetCurrentThreadId())
497 *pssState
= This
->ctx
? This
->ctx
->state
: SCRIPTSTATE_UNINITIALIZED
;
501 static HRESULT WINAPI
JScript_Close(IActiveScript
*iface
)
503 JScript
*This
= impl_from_IActiveScript(iface
);
505 TRACE("(%p)->()\n", This
);
507 if(This
->thread_id
&& This
->thread_id
!= GetCurrentThreadId())
510 decrease_state(This
, SCRIPTSTATE_CLOSED
);
514 static HRESULT WINAPI
JScript_AddNamedItem(IActiveScript
*iface
,
515 LPCOLESTR pstrName
, DWORD dwFlags
)
517 JScript
*This
= impl_from_IActiveScript(iface
);
519 IDispatch
*disp
= NULL
;
522 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(pstrName
), dwFlags
);
524 if(This
->thread_id
!= GetCurrentThreadId() || !This
->ctx
|| This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
527 if(dwFlags
& SCRIPTITEM_GLOBALMEMBERS
) {
530 hres
= IActiveScriptSite_GetItemInfo(This
->site
, pstrName
, SCRIPTINFO_IUNKNOWN
, &unk
, NULL
);
532 WARN("GetItemInfo failed: %08x\n", hres
);
536 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatch
, (void**)&disp
);
537 IUnknown_Release(unk
);
539 WARN("object does not implement IDispatch\n");
543 if(This
->ctx
->host_global
)
544 IDispatch_Release(This
->ctx
->host_global
);
545 IDispatch_AddRef(disp
);
546 This
->ctx
->host_global
= disp
;
549 item
= heap_alloc(sizeof(*item
));
552 IDispatch_Release(disp
);
553 return E_OUTOFMEMORY
;
557 item
->flags
= dwFlags
;
558 item
->name
= heap_strdupW(pstrName
);
561 IDispatch_Release(disp
);
563 return E_OUTOFMEMORY
;
566 item
->next
= This
->ctx
->named_items
;
567 This
->ctx
->named_items
= item
;
572 static HRESULT WINAPI
JScript_AddTypeLib(IActiveScript
*iface
, REFGUID rguidTypeLib
,
573 DWORD dwMajor
, DWORD dwMinor
, DWORD dwFlags
)
575 JScript
*This
= impl_from_IActiveScript(iface
);
576 FIXME("(%p)->()\n", This
);
580 static HRESULT WINAPI
JScript_GetScriptDispatch(IActiveScript
*iface
, LPCOLESTR pstrItemName
,
583 JScript
*This
= impl_from_IActiveScript(iface
);
585 TRACE("(%p)->(%p)\n", This
, ppdisp
);
590 if(This
->thread_id
!= GetCurrentThreadId() || !This
->ctx
->global
) {
595 *ppdisp
= to_disp(This
->ctx
->global
);
596 IDispatch_AddRef(*ppdisp
);
600 static HRESULT WINAPI
JScript_GetCurrentScriptThreadID(IActiveScript
*iface
,
601 SCRIPTTHREADID
*pstridThread
)
603 JScript
*This
= impl_from_IActiveScript(iface
);
604 FIXME("(%p)->()\n", This
);
608 static HRESULT WINAPI
JScript_GetScriptThreadID(IActiveScript
*iface
,
609 DWORD dwWin32ThreadId
, SCRIPTTHREADID
*pstidThread
)
611 JScript
*This
= impl_from_IActiveScript(iface
);
612 FIXME("(%p)->()\n", This
);
616 static HRESULT WINAPI
JScript_GetScriptThreadState(IActiveScript
*iface
,
617 SCRIPTTHREADID stidThread
, SCRIPTTHREADSTATE
*pstsState
)
619 JScript
*This
= impl_from_IActiveScript(iface
);
620 FIXME("(%p)->()\n", This
);
624 static HRESULT WINAPI
JScript_InterruptScriptThread(IActiveScript
*iface
,
625 SCRIPTTHREADID stidThread
, const EXCEPINFO
*pexcepinfo
, DWORD dwFlags
)
627 JScript
*This
= impl_from_IActiveScript(iface
);
628 FIXME("(%p)->()\n", This
);
632 static HRESULT WINAPI
JScript_Clone(IActiveScript
*iface
, IActiveScript
**ppscript
)
634 JScript
*This
= impl_from_IActiveScript(iface
);
635 FIXME("(%p)->()\n", This
);
639 static const IActiveScriptVtbl JScriptVtbl
= {
640 JScript_QueryInterface
,
643 JScript_SetScriptSite
,
644 JScript_GetScriptSite
,
645 JScript_SetScriptState
,
646 JScript_GetScriptState
,
648 JScript_AddNamedItem
,
650 JScript_GetScriptDispatch
,
651 JScript_GetCurrentScriptThreadID
,
652 JScript_GetScriptThreadID
,
653 JScript_GetScriptThreadState
,
654 JScript_InterruptScriptThread
,
658 static inline JScript
*impl_from_IActiveScriptParse(IActiveScriptParse
*iface
)
660 return CONTAINING_RECORD(iface
, JScript
, IActiveScriptParse_iface
);
663 static HRESULT WINAPI
JScriptParse_QueryInterface(IActiveScriptParse
*iface
, REFIID riid
, void **ppv
)
665 JScript
*This
= impl_from_IActiveScriptParse(iface
);
666 return IActiveScript_QueryInterface(&This
->IActiveScript_iface
, riid
, ppv
);
669 static ULONG WINAPI
JScriptParse_AddRef(IActiveScriptParse
*iface
)
671 JScript
*This
= impl_from_IActiveScriptParse(iface
);
672 return IActiveScript_AddRef(&This
->IActiveScript_iface
);
675 static ULONG WINAPI
JScriptParse_Release(IActiveScriptParse
*iface
)
677 JScript
*This
= impl_from_IActiveScriptParse(iface
);
678 return IActiveScript_Release(&This
->IActiveScript_iface
);
681 static HRESULT WINAPI
JScriptParse_InitNew(IActiveScriptParse
*iface
)
683 JScript
*This
= impl_from_IActiveScriptParse(iface
);
686 TRACE("(%p)\n", This
);
691 ctx
= heap_alloc_zero(sizeof(script_ctx_t
));
693 return E_OUTOFMEMORY
;
696 ctx
->state
= SCRIPTSTATE_UNINITIALIZED
;
697 ctx
->safeopt
= This
->safeopt
;
698 ctx
->version
= This
->version
;
699 jsheap_init(&ctx
->tmp_heap
);
701 ctx
= InterlockedCompareExchangePointer((void**)&This
->ctx
, ctx
, NULL
);
707 return This
->site
? set_ctx_site(This
) : S_OK
;
710 static HRESULT WINAPI
JScriptParse_AddScriptlet(IActiveScriptParse
*iface
,
711 LPCOLESTR pstrDefaultName
, LPCOLESTR pstrCode
, LPCOLESTR pstrItemName
,
712 LPCOLESTR pstrSubItemName
, LPCOLESTR pstrEventName
, LPCOLESTR pstrDelimiter
,
713 CTXARG_T dwSourceContextCookie
, ULONG ulStartingLineNumber
, DWORD dwFlags
,
714 BSTR
*pbstrName
, EXCEPINFO
*pexcepinfo
)
716 JScript
*This
= impl_from_IActiveScriptParse(iface
);
717 FIXME("(%p)->(%s %s %s %s %s %s %s %u %x %p %p)\n", This
, debugstr_w(pstrDefaultName
),
718 debugstr_w(pstrCode
), debugstr_w(pstrItemName
), debugstr_w(pstrSubItemName
),
719 debugstr_w(pstrEventName
), debugstr_w(pstrDelimiter
), wine_dbgstr_longlong(dwSourceContextCookie
),
720 ulStartingLineNumber
, dwFlags
, pbstrName
, pexcepinfo
);
724 static HRESULT WINAPI
JScriptParse_ParseScriptText(IActiveScriptParse
*iface
,
725 LPCOLESTR pstrCode
, LPCOLESTR pstrItemName
, IUnknown
*punkContext
,
726 LPCOLESTR pstrDelimiter
, CTXARG_T dwSourceContextCookie
, ULONG ulStartingLine
,
727 DWORD dwFlags
, VARIANT
*pvarResult
, EXCEPINFO
*pexcepinfo
)
729 JScript
*This
= impl_from_IActiveScriptParse(iface
);
730 parser_ctx_t
*parser_ctx
;
733 TRACE("(%p)->(%s %s %p %s %s %u %x %p %p)\n", This
, debugstr_w(pstrCode
),
734 debugstr_w(pstrItemName
), punkContext
, debugstr_w(pstrDelimiter
),
735 wine_dbgstr_longlong(dwSourceContextCookie
), ulStartingLine
, dwFlags
, pvarResult
, pexcepinfo
);
737 if(This
->thread_id
!= GetCurrentThreadId() || This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
740 hres
= script_parse(This
->ctx
, pstrCode
, pstrDelimiter
, &parser_ctx
);
744 if(!is_started(This
->ctx
)) {
746 This
->queue_tail
= This
->queue_tail
->next
= parser_ctx
;
748 This
->queue_head
= This
->queue_tail
= parser_ctx
;
752 hres
= exec_global_code(This
, parser_ctx
);
753 parser_release(parser_ctx
);
758 static const IActiveScriptParseVtbl JScriptParseVtbl
= {
759 JScriptParse_QueryInterface
,
761 JScriptParse_Release
,
762 JScriptParse_InitNew
,
763 JScriptParse_AddScriptlet
,
764 JScriptParse_ParseScriptText
767 static inline JScript
*impl_from_IActiveScriptParseProcedure2(IActiveScriptParseProcedure2
*iface
)
769 return CONTAINING_RECORD(iface
, JScript
, IActiveScriptParseProcedure2_iface
);
772 static HRESULT WINAPI
JScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2
*iface
, REFIID riid
, void **ppv
)
774 JScript
*This
= impl_from_IActiveScriptParseProcedure2(iface
);
775 return IActiveScript_QueryInterface(&This
->IActiveScript_iface
, riid
, ppv
);
778 static ULONG WINAPI
JScriptParseProcedure_AddRef(IActiveScriptParseProcedure2
*iface
)
780 JScript
*This
= impl_from_IActiveScriptParseProcedure2(iface
);
781 return IActiveScript_AddRef(&This
->IActiveScript_iface
);
784 static ULONG WINAPI
JScriptParseProcedure_Release(IActiveScriptParseProcedure2
*iface
)
786 JScript
*This
= impl_from_IActiveScriptParseProcedure2(iface
);
787 return IActiveScript_Release(&This
->IActiveScript_iface
);
790 static HRESULT WINAPI
JScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2
*iface
,
791 LPCOLESTR pstrCode
, LPCOLESTR pstrFormalParams
, LPCOLESTR pstrProcedureName
,
792 LPCOLESTR pstrItemName
, IUnknown
*punkContext
, LPCOLESTR pstrDelimiter
,
793 CTXARG_T dwSourceContextCookie
, ULONG ulStartingLineNumber
, DWORD dwFlags
, IDispatch
**ppdisp
)
795 JScript
*This
= impl_from_IActiveScriptParseProcedure2(iface
);
796 parser_ctx_t
*parser_ctx
;
800 TRACE("(%p)->(%s %s %s %s %p %s %s %u %x %p)\n", This
, debugstr_w(pstrCode
), debugstr_w(pstrFormalParams
),
801 debugstr_w(pstrProcedureName
), debugstr_w(pstrItemName
), punkContext
, debugstr_w(pstrDelimiter
),
802 wine_dbgstr_longlong(dwSourceContextCookie
), ulStartingLineNumber
, dwFlags
, ppdisp
);
804 if(This
->thread_id
!= GetCurrentThreadId() || This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
807 hres
= script_parse(This
->ctx
, pstrCode
, pstrDelimiter
, &parser_ctx
);
809 WARN("Parse failed %08x\n", hres
);
813 hres
= create_source_function(parser_ctx
, NULL
, parser_ctx
->source
, NULL
, NULL
, 0, &dispex
);
814 parser_release(parser_ctx
);
818 *ppdisp
= to_disp(dispex
);
822 static const IActiveScriptParseProcedure2Vtbl JScriptParseProcedureVtbl
= {
823 JScriptParseProcedure_QueryInterface
,
824 JScriptParseProcedure_AddRef
,
825 JScriptParseProcedure_Release
,
826 JScriptParseProcedure_ParseProcedureText
,
829 static inline JScript
*impl_from_IActiveScriptProperty(IActiveScriptProperty
*iface
)
831 return CONTAINING_RECORD(iface
, JScript
, IActiveScriptProperty_iface
);
834 static HRESULT WINAPI
JScriptProperty_QueryInterface(IActiveScriptProperty
*iface
, REFIID riid
, void **ppv
)
836 JScript
*This
= impl_from_IActiveScriptProperty(iface
);
837 return IActiveScript_QueryInterface(&This
->IActiveScript_iface
, riid
, ppv
);
840 static ULONG WINAPI
JScriptProperty_AddRef(IActiveScriptProperty
*iface
)
842 JScript
*This
= impl_from_IActiveScriptProperty(iface
);
843 return IActiveScript_AddRef(&This
->IActiveScript_iface
);
846 static ULONG WINAPI
JScriptProperty_Release(IActiveScriptProperty
*iface
)
848 JScript
*This
= impl_from_IActiveScriptProperty(iface
);
849 return IActiveScript_Release(&This
->IActiveScript_iface
);
852 static HRESULT WINAPI
JScriptProperty_GetProperty(IActiveScriptProperty
*iface
, DWORD dwProperty
,
853 VARIANT
*pvarIndex
, VARIANT
*pvarValue
)
855 JScript
*This
= impl_from_IActiveScriptProperty(iface
);
856 FIXME("(%p)->(%x %p %p)\n", This
, dwProperty
, pvarIndex
, pvarValue
);
860 static HRESULT WINAPI
JScriptProperty_SetProperty(IActiveScriptProperty
*iface
, DWORD dwProperty
,
861 VARIANT
*pvarIndex
, VARIANT
*pvarValue
)
863 JScript
*This
= impl_from_IActiveScriptProperty(iface
);
865 TRACE("(%p)->(%x %s %s)\n", This
, dwProperty
, debugstr_variant(pvarIndex
), debugstr_variant(pvarValue
));
868 FIXME("unsupported pvarIndex\n");
871 case SCRIPTPROP_INVOKEVERSIONING
:
872 if(V_VT(pvarValue
) != VT_I4
|| V_I4(pvarValue
) < 0 || V_I4(pvarValue
) > 15) {
873 WARN("invalid value %s\n", debugstr_variant(pvarValue
));
877 This
->version
= V_I4(pvarValue
);
880 FIXME("Unimplemented property %x\n", dwProperty
);
887 static const IActiveScriptPropertyVtbl JScriptPropertyVtbl
= {
888 JScriptProperty_QueryInterface
,
889 JScriptProperty_AddRef
,
890 JScriptProperty_Release
,
891 JScriptProperty_GetProperty
,
892 JScriptProperty_SetProperty
895 static inline JScript
*impl_from_IObjectSafety(IObjectSafety
*iface
)
897 return CONTAINING_RECORD(iface
, JScript
, IObjectSafety_iface
);
900 static HRESULT WINAPI
JScriptSafety_QueryInterface(IObjectSafety
*iface
, REFIID riid
, void **ppv
)
902 JScript
*This
= impl_from_IObjectSafety(iface
);
903 return IActiveScript_QueryInterface(&This
->IActiveScript_iface
, riid
, ppv
);
906 static ULONG WINAPI
JScriptSafety_AddRef(IObjectSafety
*iface
)
908 JScript
*This
= impl_from_IObjectSafety(iface
);
909 return IActiveScript_AddRef(&This
->IActiveScript_iface
);
912 static ULONG WINAPI
JScriptSafety_Release(IObjectSafety
*iface
)
914 JScript
*This
= impl_from_IObjectSafety(iface
);
915 return IActiveScript_Release(&This
->IActiveScript_iface
);
918 #define SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER)
920 static HRESULT WINAPI
JScriptSafety_GetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
921 DWORD
*pdwSupportedOptions
, DWORD
*pdwEnabledOptions
)
923 JScript
*This
= impl_from_IObjectSafety(iface
);
925 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_guid(riid
), pdwSupportedOptions
, pdwEnabledOptions
);
927 if(!pdwSupportedOptions
|| !pdwEnabledOptions
)
930 *pdwSupportedOptions
= SUPPORTED_OPTIONS
;
931 *pdwEnabledOptions
= This
->safeopt
;
936 static HRESULT WINAPI
JScriptSafety_SetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
937 DWORD dwOptionSetMask
, DWORD dwEnabledOptions
)
939 JScript
*This
= impl_from_IObjectSafety(iface
);
941 TRACE("(%p)->(%s %x %x)\n", This
, debugstr_guid(riid
), dwOptionSetMask
, dwEnabledOptions
);
943 if(dwOptionSetMask
& ~SUPPORTED_OPTIONS
)
946 This
->safeopt
= dwEnabledOptions
& dwEnabledOptions
;
950 static const IObjectSafetyVtbl JScriptSafetyVtbl
= {
951 JScriptSafety_QueryInterface
,
952 JScriptSafety_AddRef
,
953 JScriptSafety_Release
,
954 JScriptSafety_GetInterfaceSafetyOptions
,
955 JScriptSafety_SetInterfaceSafetyOptions
958 HRESULT WINAPI
JScriptFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*pUnkOuter
,
959 REFIID riid
, void **ppv
)
964 TRACE("(%p %s %p)\n", pUnkOuter
, debugstr_guid(riid
), ppv
);
968 ret
= heap_alloc_zero(sizeof(*ret
));
970 return E_OUTOFMEMORY
;
972 ret
->IActiveScript_iface
.lpVtbl
= &JScriptVtbl
;
973 ret
->IActiveScriptParse_iface
.lpVtbl
= &JScriptParseVtbl
;
974 ret
->IActiveScriptParseProcedure2_iface
.lpVtbl
= &JScriptParseProcedureVtbl
;
975 ret
->IActiveScriptProperty_iface
.lpVtbl
= &JScriptPropertyVtbl
;
976 ret
->IObjectSafety_iface
.lpVtbl
= &JScriptSafetyVtbl
;
978 ret
->safeopt
= INTERFACE_USES_DISPEX
;
980 hres
= IActiveScript_QueryInterface(&ret
->IActiveScript_iface
, riid
, ppv
);
981 IActiveScript_Release(&ret
->IActiveScript_iface
);