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
;
49 IVariantChangeType IVariantChangeType_iface
;
59 IActiveScriptSite
*site
;
61 bytecode_t
*queue_head
;
62 bytecode_t
*queue_tail
;
65 void script_release(script_ctx_t
*ctx
)
72 jsheap_free(&ctx
->tmp_heap
);
73 SysFreeString(ctx
->last_match
);
75 ctx
->jscaller
->ctx
= NULL
;
76 IServiceProvider_Release(&ctx
->jscaller
->IServiceProvider_iface
);
81 static void change_state(JScript
*This
, SCRIPTSTATE state
)
83 if(This
->ctx
->state
== state
)
86 This
->ctx
->state
= state
;
88 IActiveScriptSite_OnStateChange(This
->site
, state
);
91 static inline BOOL
is_started(script_ctx_t
*ctx
)
93 return ctx
->state
== SCRIPTSTATE_STARTED
94 || ctx
->state
== SCRIPTSTATE_CONNECTED
95 || ctx
->state
== SCRIPTSTATE_DISCONNECTED
;
98 static HRESULT
exec_global_code(JScript
*This
, bytecode_t
*code
)
100 exec_ctx_t
*exec_ctx
;
104 hres
= create_exec_ctx(This
->ctx
, NULL
, This
->ctx
->global
, NULL
, TRUE
, &exec_ctx
);
108 IActiveScriptSite_OnEnterScript(This
->site
);
110 memset(&jsexcept
, 0, sizeof(jsexcept
));
111 hres
= exec_source(exec_ctx
, code
, code
->parser
->source
, FALSE
, &jsexcept
, NULL
);
112 VariantClear(&jsexcept
.var
);
113 exec_release(exec_ctx
);
115 IActiveScriptSite_OnLeaveScript(This
->site
);
119 static void clear_script_queue(JScript
*This
)
121 bytecode_t
*iter
, *iter2
;
123 if(!This
->queue_head
)
126 iter
= This
->queue_head
;
130 release_bytecode(iter
);
134 This
->queue_head
= This
->queue_tail
= NULL
;
137 static void exec_queued_code(JScript
*This
)
141 for(iter
= This
->queue_head
; iter
; iter
= iter
->next
)
142 exec_global_code(This
, iter
);
144 clear_script_queue(This
);
147 static HRESULT
set_ctx_site(JScript
*This
)
151 This
->ctx
->lcid
= This
->lcid
;
153 hres
= init_global(This
->ctx
);
157 IActiveScriptSite_AddRef(This
->site
);
158 This
->ctx
->site
= This
->site
;
160 change_state(This
, SCRIPTSTATE_INITIALIZED
);
164 static void decrease_state(JScript
*This
, SCRIPTSTATE state
)
167 switch(This
->ctx
->state
) {
168 case SCRIPTSTATE_CONNECTED
:
169 change_state(This
, SCRIPTSTATE_DISCONNECTED
);
170 if(state
== SCRIPTSTATE_DISCONNECTED
)
173 case SCRIPTSTATE_STARTED
:
174 case SCRIPTSTATE_DISCONNECTED
:
175 clear_script_queue(This
);
177 if(This
->ctx
->state
== SCRIPTSTATE_DISCONNECTED
)
178 change_state(This
, SCRIPTSTATE_INITIALIZED
);
179 if(state
== SCRIPTSTATE_INITIALIZED
)
182 case SCRIPTSTATE_INITIALIZED
:
183 if(This
->ctx
->host_global
) {
184 IDispatch_Release(This
->ctx
->host_global
);
185 This
->ctx
->host_global
= NULL
;
188 if(This
->ctx
->named_items
) {
189 named_item_t
*iter
, *iter2
;
191 iter
= This
->ctx
->named_items
;
196 IDispatch_Release(iter
->disp
);
197 heap_free(iter
->name
);
202 This
->ctx
->named_items
= NULL
;
205 if(This
->ctx
->secmgr
) {
206 IInternetHostSecurityManager_Release(This
->ctx
->secmgr
);
207 This
->ctx
->secmgr
= NULL
;
210 if(This
->ctx
->site
) {
211 IActiveScriptSite_Release(This
->ctx
->site
);
212 This
->ctx
->site
= NULL
;
215 if(This
->ctx
->global
) {
216 jsdisp_release(This
->ctx
->global
);
217 This
->ctx
->global
= NULL
;
220 case SCRIPTSTATE_UNINITIALIZED
:
221 change_state(This
, state
);
227 change_state(This
, state
);
228 }else if(state
== SCRIPTSTATE_UNINITIALIZED
) {
230 IActiveScriptSite_OnStateChange(This
->site
, state
);
235 if(state
== SCRIPTSTATE_UNINITIALIZED
)
239 IActiveScriptSite_Release(This
->site
);
245 IServiceProvider IServiceProvider_iface
;
249 IServiceProvider
*sp
;
252 static inline AXSite
*impl_from_IServiceProvider(IServiceProvider
*iface
)
254 return CONTAINING_RECORD(iface
, AXSite
, IServiceProvider_iface
);
257 static HRESULT WINAPI
AXSite_QueryInterface(IServiceProvider
*iface
, REFIID riid
, void **ppv
)
259 AXSite
*This
= impl_from_IServiceProvider(iface
);
261 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
262 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
263 *ppv
= &This
->IServiceProvider_iface
;
264 }else if(IsEqualGUID(&IID_IServiceProvider
, riid
)) {
265 TRACE("(%p)->(IID_IServiceProvider %p)\n", This
, ppv
);
266 *ppv
= &This
->IServiceProvider_iface
;
268 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
270 return E_NOINTERFACE
;
273 IUnknown_AddRef((IUnknown
*)*ppv
);
277 static ULONG WINAPI
AXSite_AddRef(IServiceProvider
*iface
)
279 AXSite
*This
= impl_from_IServiceProvider(iface
);
280 LONG ref
= InterlockedIncrement(&This
->ref
);
282 TRACE("(%p) ref=%d\n", This
, ref
);
287 static ULONG WINAPI
AXSite_Release(IServiceProvider
*iface
)
289 AXSite
*This
= impl_from_IServiceProvider(iface
);
290 LONG ref
= InterlockedDecrement(&This
->ref
);
292 TRACE("(%p) ref=%d\n", This
, ref
);
297 IServiceProvider_Release(This
->sp
);
305 static HRESULT WINAPI
AXSite_QueryService(IServiceProvider
*iface
,
306 REFGUID guidService
, REFIID riid
, void **ppv
)
308 AXSite
*This
= impl_from_IServiceProvider(iface
);
310 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_guid(guidService
), debugstr_guid(riid
), ppv
);
313 return E_NOINTERFACE
;
315 return IServiceProvider_QueryService(This
->sp
, guidService
, riid
, ppv
);
318 static IServiceProviderVtbl AXSiteVtbl
= {
319 AXSite_QueryInterface
,
325 IUnknown
*create_ax_site(script_ctx_t
*ctx
)
327 IServiceProvider
*sp
= NULL
;
331 hres
= IActiveScriptSite_QueryInterface(ctx
->site
, &IID_IServiceProvider
, (void**)&sp
);
333 TRACE("Could not get IServiceProvider iface: %08x\n", hres
);
336 ret
= heap_alloc(sizeof(AXSite
));
338 IServiceProvider_Release(sp
);
342 ret
->IServiceProvider_iface
.lpVtbl
= &AXSiteVtbl
;
346 return (IUnknown
*)&ret
->IServiceProvider_iface
;
349 static inline JScript
*impl_from_IActiveScript(IActiveScript
*iface
)
351 return CONTAINING_RECORD(iface
, JScript
, IActiveScript_iface
);
354 static HRESULT WINAPI
JScript_QueryInterface(IActiveScript
*iface
, REFIID riid
, void **ppv
)
356 JScript
*This
= impl_from_IActiveScript(iface
);
360 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
361 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
362 *ppv
= &This
->IActiveScript_iface
;
363 }else if(IsEqualGUID(riid
, &IID_IActiveScript
)) {
364 TRACE("(%p)->(IID_IActiveScript %p)\n", This
, ppv
);
365 *ppv
= &This
->IActiveScript_iface
;
366 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParse
)) {
367 TRACE("(%p)->(IID_IActiveScriptParse %p)\n", This
, ppv
);
368 *ppv
= &This
->IActiveScriptParse_iface
;
369 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParseProcedure
)) {
370 TRACE("(%p)->(IID_IActiveScriptParseProcedure %p)\n", This
, ppv
);
371 *ppv
= &This
->IActiveScriptParseProcedure2_iface
;
372 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParseProcedure2
)) {
373 TRACE("(%p)->(IID_IActiveScriptParseProcedure2 %p)\n", This
, ppv
);
374 *ppv
= &This
->IActiveScriptParseProcedure2_iface
;
375 }else if(IsEqualGUID(riid
, &IID_IActiveScriptProperty
)) {
376 TRACE("(%p)->(IID_IActiveScriptProperty %p)\n", This
, ppv
);
377 *ppv
= &This
->IActiveScriptProperty_iface
;
378 }else if(IsEqualGUID(riid
, &IID_IObjectSafety
)) {
379 TRACE("(%p)->(IID_IObjectSafety %p)\n", This
, ppv
);
380 *ppv
= &This
->IObjectSafety_iface
;
381 }else if(IsEqualGUID(riid
, &IID_IVariantChangeType
)) {
382 TRACE("(%p)->(IID_IVariantChangeType %p)\n", This
, ppv
);
383 *ppv
= &This
->IVariantChangeType_iface
;
387 IUnknown_AddRef((IUnknown
*)*ppv
);
391 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
392 return E_NOINTERFACE
;
395 static ULONG WINAPI
JScript_AddRef(IActiveScript
*iface
)
397 JScript
*This
= impl_from_IActiveScript(iface
);
398 LONG ref
= InterlockedIncrement(&This
->ref
);
400 TRACE("(%p) ref=%d\n", This
, ref
);
405 static ULONG WINAPI
JScript_Release(IActiveScript
*iface
)
407 JScript
*This
= impl_from_IActiveScript(iface
);
408 LONG ref
= InterlockedDecrement(&This
->ref
);
410 TRACE("(%p) ref=%d\n", iface
, ref
);
413 if(This
->ctx
&& This
->ctx
->state
!= SCRIPTSTATE_CLOSED
)
414 IActiveScript_Close(&This
->IActiveScript_iface
);
416 This
->ctx
->active_script
= NULL
;
417 script_release(This
->ctx
);
426 static HRESULT WINAPI
JScript_SetScriptSite(IActiveScript
*iface
,
427 IActiveScriptSite
*pass
)
429 JScript
*This
= impl_from_IActiveScript(iface
);
433 TRACE("(%p)->(%p)\n", This
, pass
);
441 if(InterlockedCompareExchange(&This
->thread_id
, GetCurrentThreadId(), 0))
445 IActiveScriptSite_AddRef(This
->site
);
447 hres
= IActiveScriptSite_GetLCID(This
->site
, &lcid
);
451 return This
->ctx
? set_ctx_site(This
) : S_OK
;
454 static HRESULT WINAPI
JScript_GetScriptSite(IActiveScript
*iface
, REFIID riid
,
457 JScript
*This
= impl_from_IActiveScript(iface
);
458 FIXME("(%p)->()\n", This
);
462 static HRESULT WINAPI
JScript_SetScriptState(IActiveScript
*iface
, SCRIPTSTATE ss
)
464 JScript
*This
= impl_from_IActiveScript(iface
);
466 TRACE("(%p)->(%d)\n", This
, ss
);
468 if(This
->thread_id
&& GetCurrentThreadId() != This
->thread_id
)
471 if(ss
== SCRIPTSTATE_UNINITIALIZED
) {
472 if(This
->ctx
&& This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
475 decrease_state(This
, SCRIPTSTATE_UNINITIALIZED
);
483 case SCRIPTSTATE_STARTED
:
484 case SCRIPTSTATE_CONNECTED
: /* FIXME */
485 if(This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
488 exec_queued_code(This
);
490 case SCRIPTSTATE_INITIALIZED
:
491 FIXME("unimplemented SCRIPTSTATE_INITIALIZED\n");
494 FIXME("unimplemented state %d\n", ss
);
498 change_state(This
, ss
);
502 static HRESULT WINAPI
JScript_GetScriptState(IActiveScript
*iface
, SCRIPTSTATE
*pssState
)
504 JScript
*This
= impl_from_IActiveScript(iface
);
506 TRACE("(%p)->(%p)\n", This
, pssState
);
511 if(This
->thread_id
&& This
->thread_id
!= GetCurrentThreadId())
514 *pssState
= This
->ctx
? This
->ctx
->state
: SCRIPTSTATE_UNINITIALIZED
;
518 static HRESULT WINAPI
JScript_Close(IActiveScript
*iface
)
520 JScript
*This
= impl_from_IActiveScript(iface
);
522 TRACE("(%p)->()\n", This
);
524 if(This
->thread_id
&& This
->thread_id
!= GetCurrentThreadId())
527 decrease_state(This
, SCRIPTSTATE_CLOSED
);
531 static HRESULT WINAPI
JScript_AddNamedItem(IActiveScript
*iface
,
532 LPCOLESTR pstrName
, DWORD dwFlags
)
534 JScript
*This
= impl_from_IActiveScript(iface
);
536 IDispatch
*disp
= NULL
;
539 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(pstrName
), dwFlags
);
541 if(This
->thread_id
!= GetCurrentThreadId() || !This
->ctx
|| This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
544 if(dwFlags
& SCRIPTITEM_GLOBALMEMBERS
) {
547 hres
= IActiveScriptSite_GetItemInfo(This
->site
, pstrName
, SCRIPTINFO_IUNKNOWN
, &unk
, NULL
);
549 WARN("GetItemInfo failed: %08x\n", hres
);
553 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatch
, (void**)&disp
);
554 IUnknown_Release(unk
);
556 WARN("object does not implement IDispatch\n");
560 if(This
->ctx
->host_global
)
561 IDispatch_Release(This
->ctx
->host_global
);
562 IDispatch_AddRef(disp
);
563 This
->ctx
->host_global
= disp
;
566 item
= heap_alloc(sizeof(*item
));
569 IDispatch_Release(disp
);
570 return E_OUTOFMEMORY
;
574 item
->flags
= dwFlags
;
575 item
->name
= heap_strdupW(pstrName
);
578 IDispatch_Release(disp
);
580 return E_OUTOFMEMORY
;
583 item
->next
= This
->ctx
->named_items
;
584 This
->ctx
->named_items
= item
;
589 static HRESULT WINAPI
JScript_AddTypeLib(IActiveScript
*iface
, REFGUID rguidTypeLib
,
590 DWORD dwMajor
, DWORD dwMinor
, DWORD dwFlags
)
592 JScript
*This
= impl_from_IActiveScript(iface
);
593 FIXME("(%p)->()\n", This
);
597 static HRESULT WINAPI
JScript_GetScriptDispatch(IActiveScript
*iface
, LPCOLESTR pstrItemName
,
600 JScript
*This
= impl_from_IActiveScript(iface
);
602 TRACE("(%p)->(%p)\n", This
, ppdisp
);
607 if(This
->thread_id
!= GetCurrentThreadId() || !This
->ctx
->global
) {
612 *ppdisp
= to_disp(This
->ctx
->global
);
613 IDispatch_AddRef(*ppdisp
);
617 static HRESULT WINAPI
JScript_GetCurrentScriptThreadID(IActiveScript
*iface
,
618 SCRIPTTHREADID
*pstridThread
)
620 JScript
*This
= impl_from_IActiveScript(iface
);
621 FIXME("(%p)->()\n", This
);
625 static HRESULT WINAPI
JScript_GetScriptThreadID(IActiveScript
*iface
,
626 DWORD dwWin32ThreadId
, SCRIPTTHREADID
*pstidThread
)
628 JScript
*This
= impl_from_IActiveScript(iface
);
629 FIXME("(%p)->()\n", This
);
633 static HRESULT WINAPI
JScript_GetScriptThreadState(IActiveScript
*iface
,
634 SCRIPTTHREADID stidThread
, SCRIPTTHREADSTATE
*pstsState
)
636 JScript
*This
= impl_from_IActiveScript(iface
);
637 FIXME("(%p)->()\n", This
);
641 static HRESULT WINAPI
JScript_InterruptScriptThread(IActiveScript
*iface
,
642 SCRIPTTHREADID stidThread
, const EXCEPINFO
*pexcepinfo
, DWORD dwFlags
)
644 JScript
*This
= impl_from_IActiveScript(iface
);
645 FIXME("(%p)->()\n", This
);
649 static HRESULT WINAPI
JScript_Clone(IActiveScript
*iface
, IActiveScript
**ppscript
)
651 JScript
*This
= impl_from_IActiveScript(iface
);
652 FIXME("(%p)->()\n", This
);
656 static const IActiveScriptVtbl JScriptVtbl
= {
657 JScript_QueryInterface
,
660 JScript_SetScriptSite
,
661 JScript_GetScriptSite
,
662 JScript_SetScriptState
,
663 JScript_GetScriptState
,
665 JScript_AddNamedItem
,
667 JScript_GetScriptDispatch
,
668 JScript_GetCurrentScriptThreadID
,
669 JScript_GetScriptThreadID
,
670 JScript_GetScriptThreadState
,
671 JScript_InterruptScriptThread
,
675 static inline JScript
*impl_from_IActiveScriptParse(IActiveScriptParse
*iface
)
677 return CONTAINING_RECORD(iface
, JScript
, IActiveScriptParse_iface
);
680 static HRESULT WINAPI
JScriptParse_QueryInterface(IActiveScriptParse
*iface
, REFIID riid
, void **ppv
)
682 JScript
*This
= impl_from_IActiveScriptParse(iface
);
683 return IActiveScript_QueryInterface(&This
->IActiveScript_iface
, riid
, ppv
);
686 static ULONG WINAPI
JScriptParse_AddRef(IActiveScriptParse
*iface
)
688 JScript
*This
= impl_from_IActiveScriptParse(iface
);
689 return IActiveScript_AddRef(&This
->IActiveScript_iface
);
692 static ULONG WINAPI
JScriptParse_Release(IActiveScriptParse
*iface
)
694 JScript
*This
= impl_from_IActiveScriptParse(iface
);
695 return IActiveScript_Release(&This
->IActiveScript_iface
);
698 static HRESULT WINAPI
JScriptParse_InitNew(IActiveScriptParse
*iface
)
700 JScript
*This
= impl_from_IActiveScriptParse(iface
);
704 TRACE("(%p)\n", This
);
709 ctx
= heap_alloc_zero(sizeof(script_ctx_t
));
711 return E_OUTOFMEMORY
;
714 ctx
->state
= SCRIPTSTATE_UNINITIALIZED
;
715 ctx
->active_script
= &This
->IActiveScript_iface
;
716 ctx
->safeopt
= This
->safeopt
;
717 ctx
->version
= This
->version
;
718 jsheap_init(&ctx
->tmp_heap
);
720 hres
= create_jscaller(ctx
);
726 ctx
= InterlockedCompareExchangePointer((void**)&This
->ctx
, ctx
, NULL
);
732 return This
->site
? set_ctx_site(This
) : S_OK
;
735 static HRESULT WINAPI
JScriptParse_AddScriptlet(IActiveScriptParse
*iface
,
736 LPCOLESTR pstrDefaultName
, LPCOLESTR pstrCode
, LPCOLESTR pstrItemName
,
737 LPCOLESTR pstrSubItemName
, LPCOLESTR pstrEventName
, LPCOLESTR pstrDelimiter
,
738 CTXARG_T dwSourceContextCookie
, ULONG ulStartingLineNumber
, DWORD dwFlags
,
739 BSTR
*pbstrName
, EXCEPINFO
*pexcepinfo
)
741 JScript
*This
= impl_from_IActiveScriptParse(iface
);
742 FIXME("(%p)->(%s %s %s %s %s %s %s %u %x %p %p)\n", This
, debugstr_w(pstrDefaultName
),
743 debugstr_w(pstrCode
), debugstr_w(pstrItemName
), debugstr_w(pstrSubItemName
),
744 debugstr_w(pstrEventName
), debugstr_w(pstrDelimiter
), wine_dbgstr_longlong(dwSourceContextCookie
),
745 ulStartingLineNumber
, dwFlags
, pbstrName
, pexcepinfo
);
749 static HRESULT WINAPI
JScriptParse_ParseScriptText(IActiveScriptParse
*iface
,
750 LPCOLESTR pstrCode
, LPCOLESTR pstrItemName
, IUnknown
*punkContext
,
751 LPCOLESTR pstrDelimiter
, CTXARG_T dwSourceContextCookie
, ULONG ulStartingLine
,
752 DWORD dwFlags
, VARIANT
*pvarResult
, EXCEPINFO
*pexcepinfo
)
754 JScript
*This
= impl_from_IActiveScriptParse(iface
);
758 TRACE("(%p)->(%s %s %p %s %s %u %x %p %p)\n", This
, debugstr_w(pstrCode
),
759 debugstr_w(pstrItemName
), punkContext
, debugstr_w(pstrDelimiter
),
760 wine_dbgstr_longlong(dwSourceContextCookie
), ulStartingLine
, dwFlags
, pvarResult
, pexcepinfo
);
762 if(This
->thread_id
!= GetCurrentThreadId() || This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
765 hres
= compile_script(This
->ctx
, pstrCode
, pstrDelimiter
, FALSE
, &code
);
769 if(!is_started(This
->ctx
)) {
771 This
->queue_tail
= This
->queue_tail
->next
= code
;
773 This
->queue_head
= This
->queue_tail
= code
;
777 hres
= exec_global_code(This
, code
);
779 release_bytecode(code
);
783 static const IActiveScriptParseVtbl JScriptParseVtbl
= {
784 JScriptParse_QueryInterface
,
786 JScriptParse_Release
,
787 JScriptParse_InitNew
,
788 JScriptParse_AddScriptlet
,
789 JScriptParse_ParseScriptText
792 static inline JScript
*impl_from_IActiveScriptParseProcedure2(IActiveScriptParseProcedure2
*iface
)
794 return CONTAINING_RECORD(iface
, JScript
, IActiveScriptParseProcedure2_iface
);
797 static HRESULT WINAPI
JScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2
*iface
, REFIID riid
, void **ppv
)
799 JScript
*This
= impl_from_IActiveScriptParseProcedure2(iface
);
800 return IActiveScript_QueryInterface(&This
->IActiveScript_iface
, riid
, ppv
);
803 static ULONG WINAPI
JScriptParseProcedure_AddRef(IActiveScriptParseProcedure2
*iface
)
805 JScript
*This
= impl_from_IActiveScriptParseProcedure2(iface
);
806 return IActiveScript_AddRef(&This
->IActiveScript_iface
);
809 static ULONG WINAPI
JScriptParseProcedure_Release(IActiveScriptParseProcedure2
*iface
)
811 JScript
*This
= impl_from_IActiveScriptParseProcedure2(iface
);
812 return IActiveScript_Release(&This
->IActiveScript_iface
);
815 static HRESULT WINAPI
JScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2
*iface
,
816 LPCOLESTR pstrCode
, LPCOLESTR pstrFormalParams
, LPCOLESTR pstrProcedureName
,
817 LPCOLESTR pstrItemName
, IUnknown
*punkContext
, LPCOLESTR pstrDelimiter
,
818 CTXARG_T dwSourceContextCookie
, ULONG ulStartingLineNumber
, DWORD dwFlags
, IDispatch
**ppdisp
)
820 JScript
*This
= impl_from_IActiveScriptParseProcedure2(iface
);
825 TRACE("(%p)->(%s %s %s %s %p %s %s %u %x %p)\n", This
, debugstr_w(pstrCode
), debugstr_w(pstrFormalParams
),
826 debugstr_w(pstrProcedureName
), debugstr_w(pstrItemName
), punkContext
, debugstr_w(pstrDelimiter
),
827 wine_dbgstr_longlong(dwSourceContextCookie
), ulStartingLineNumber
, dwFlags
, ppdisp
);
829 if(This
->thread_id
!= GetCurrentThreadId() || This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
832 hres
= compile_script(This
->ctx
, pstrCode
, pstrDelimiter
, FALSE
, &code
);
834 WARN("Parse failed %08x\n", hres
);
838 hres
= create_source_function(This
->ctx
, code
, NULL
, code
->parser
->source
, NULL
, NULL
, 0, &dispex
);
839 release_bytecode(code
);
843 *ppdisp
= to_disp(dispex
);
847 static const IActiveScriptParseProcedure2Vtbl JScriptParseProcedureVtbl
= {
848 JScriptParseProcedure_QueryInterface
,
849 JScriptParseProcedure_AddRef
,
850 JScriptParseProcedure_Release
,
851 JScriptParseProcedure_ParseProcedureText
,
854 static inline JScript
*impl_from_IActiveScriptProperty(IActiveScriptProperty
*iface
)
856 return CONTAINING_RECORD(iface
, JScript
, IActiveScriptProperty_iface
);
859 static HRESULT WINAPI
JScriptProperty_QueryInterface(IActiveScriptProperty
*iface
, REFIID riid
, void **ppv
)
861 JScript
*This
= impl_from_IActiveScriptProperty(iface
);
862 return IActiveScript_QueryInterface(&This
->IActiveScript_iface
, riid
, ppv
);
865 static ULONG WINAPI
JScriptProperty_AddRef(IActiveScriptProperty
*iface
)
867 JScript
*This
= impl_from_IActiveScriptProperty(iface
);
868 return IActiveScript_AddRef(&This
->IActiveScript_iface
);
871 static ULONG WINAPI
JScriptProperty_Release(IActiveScriptProperty
*iface
)
873 JScript
*This
= impl_from_IActiveScriptProperty(iface
);
874 return IActiveScript_Release(&This
->IActiveScript_iface
);
877 static HRESULT WINAPI
JScriptProperty_GetProperty(IActiveScriptProperty
*iface
, DWORD dwProperty
,
878 VARIANT
*pvarIndex
, VARIANT
*pvarValue
)
880 JScript
*This
= impl_from_IActiveScriptProperty(iface
);
881 FIXME("(%p)->(%x %p %p)\n", This
, dwProperty
, pvarIndex
, pvarValue
);
885 static HRESULT WINAPI
JScriptProperty_SetProperty(IActiveScriptProperty
*iface
, DWORD dwProperty
,
886 VARIANT
*pvarIndex
, VARIANT
*pvarValue
)
888 JScript
*This
= impl_from_IActiveScriptProperty(iface
);
890 TRACE("(%p)->(%x %s %s)\n", This
, dwProperty
, debugstr_variant(pvarIndex
), debugstr_variant(pvarValue
));
893 FIXME("unsupported pvarIndex\n");
896 case SCRIPTPROP_INVOKEVERSIONING
:
897 if(V_VT(pvarValue
) != VT_I4
|| V_I4(pvarValue
) < 0 || V_I4(pvarValue
) > 15) {
898 WARN("invalid value %s\n", debugstr_variant(pvarValue
));
902 This
->version
= V_I4(pvarValue
);
905 FIXME("Unimplemented property %x\n", dwProperty
);
912 static const IActiveScriptPropertyVtbl JScriptPropertyVtbl
= {
913 JScriptProperty_QueryInterface
,
914 JScriptProperty_AddRef
,
915 JScriptProperty_Release
,
916 JScriptProperty_GetProperty
,
917 JScriptProperty_SetProperty
920 static inline JScript
*impl_from_IObjectSafety(IObjectSafety
*iface
)
922 return CONTAINING_RECORD(iface
, JScript
, IObjectSafety_iface
);
925 static HRESULT WINAPI
JScriptSafety_QueryInterface(IObjectSafety
*iface
, REFIID riid
, void **ppv
)
927 JScript
*This
= impl_from_IObjectSafety(iface
);
928 return IActiveScript_QueryInterface(&This
->IActiveScript_iface
, riid
, ppv
);
931 static ULONG WINAPI
JScriptSafety_AddRef(IObjectSafety
*iface
)
933 JScript
*This
= impl_from_IObjectSafety(iface
);
934 return IActiveScript_AddRef(&This
->IActiveScript_iface
);
937 static ULONG WINAPI
JScriptSafety_Release(IObjectSafety
*iface
)
939 JScript
*This
= impl_from_IObjectSafety(iface
);
940 return IActiveScript_Release(&This
->IActiveScript_iface
);
943 #define SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER)
945 static HRESULT WINAPI
JScriptSafety_GetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
946 DWORD
*pdwSupportedOptions
, DWORD
*pdwEnabledOptions
)
948 JScript
*This
= impl_from_IObjectSafety(iface
);
950 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_guid(riid
), pdwSupportedOptions
, pdwEnabledOptions
);
952 if(!pdwSupportedOptions
|| !pdwEnabledOptions
)
955 *pdwSupportedOptions
= SUPPORTED_OPTIONS
;
956 *pdwEnabledOptions
= This
->safeopt
;
961 static HRESULT WINAPI
JScriptSafety_SetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
962 DWORD dwOptionSetMask
, DWORD dwEnabledOptions
)
964 JScript
*This
= impl_from_IObjectSafety(iface
);
966 TRACE("(%p)->(%s %x %x)\n", This
, debugstr_guid(riid
), dwOptionSetMask
, dwEnabledOptions
);
968 if(dwOptionSetMask
& ~SUPPORTED_OPTIONS
)
971 This
->safeopt
= (dwEnabledOptions
& dwOptionSetMask
) | (This
->safeopt
& ~dwOptionSetMask
) | INTERFACE_USES_DISPEX
;
975 static const IObjectSafetyVtbl JScriptSafetyVtbl
= {
976 JScriptSafety_QueryInterface
,
977 JScriptSafety_AddRef
,
978 JScriptSafety_Release
,
979 JScriptSafety_GetInterfaceSafetyOptions
,
980 JScriptSafety_SetInterfaceSafetyOptions
983 static inline JScript
*impl_from_IVariantChangeType(IVariantChangeType
*iface
)
985 return CONTAINING_RECORD(iface
, JScript
, IVariantChangeType_iface
);
988 static HRESULT WINAPI
VariantChangeType_QueryInterface(IVariantChangeType
*iface
, REFIID riid
, void **ppv
)
990 JScript
*This
= impl_from_IVariantChangeType(iface
);
991 return IActiveScript_QueryInterface(&This
->IActiveScript_iface
, riid
, ppv
);
994 static ULONG WINAPI
VariantChangeType_AddRef(IVariantChangeType
*iface
)
996 JScript
*This
= impl_from_IVariantChangeType(iface
);
997 return IActiveScript_AddRef(&This
->IActiveScript_iface
);
1000 static ULONG WINAPI
VariantChangeType_Release(IVariantChangeType
*iface
)
1002 JScript
*This
= impl_from_IVariantChangeType(iface
);
1003 return IActiveScript_Release(&This
->IActiveScript_iface
);
1006 static HRESULT WINAPI
VariantChangeType_ChangeType(IVariantChangeType
*iface
, VARIANT
*dst
, VARIANT
*src
, LCID lcid
, VARTYPE vt
)
1008 JScript
*This
= impl_from_IVariantChangeType(iface
);
1011 TRACE("(%p)->(%p %s %x %d)\n", This
, dst
, debugstr_variant(src
), lcid
, vt
);
1014 FIXME("Object uninitialized\n");
1015 return E_UNEXPECTED
;
1018 hres
= VariantClear(dst
);
1022 return variant_change_type(This
->ctx
, dst
, src
, vt
);
1025 static const IVariantChangeTypeVtbl VariantChangeTypeVtbl
= {
1026 VariantChangeType_QueryInterface
,
1027 VariantChangeType_AddRef
,
1028 VariantChangeType_Release
,
1029 VariantChangeType_ChangeType
1032 HRESULT WINAPI
JScriptFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*pUnkOuter
,
1033 REFIID riid
, void **ppv
)
1038 TRACE("(%p %s %p)\n", pUnkOuter
, debugstr_guid(riid
), ppv
);
1042 return CLASS_E_NOAGGREGATION
;
1047 ret
= heap_alloc_zero(sizeof(*ret
));
1049 return E_OUTOFMEMORY
;
1051 ret
->IActiveScript_iface
.lpVtbl
= &JScriptVtbl
;
1052 ret
->IActiveScriptParse_iface
.lpVtbl
= &JScriptParseVtbl
;
1053 ret
->IActiveScriptParseProcedure2_iface
.lpVtbl
= &JScriptParseProcedureVtbl
;
1054 ret
->IActiveScriptProperty_iface
.lpVtbl
= &JScriptPropertyVtbl
;
1055 ret
->IObjectSafety_iface
.lpVtbl
= &JScriptSafetyVtbl
;
1056 ret
->IVariantChangeType_iface
.lpVtbl
= &VariantChangeTypeVtbl
;
1058 ret
->safeopt
= INTERFACE_USES_DISPEX
;
1060 hres
= IActiveScript_QueryInterface(&ret
->IActiveScript_iface
, riid
, ppv
);
1061 IActiveScript_Release(&ret
->IActiveScript_iface
);