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
;
60 IActiveScriptSite
*site
;
62 bytecode_t
*queue_head
;
63 bytecode_t
*queue_tail
;
66 void script_release(script_ctx_t
*ctx
)
73 jsheap_free(&ctx
->tmp_heap
);
74 SysFreeString(ctx
->last_match
);
76 ctx
->jscaller
->ctx
= NULL
;
77 IServiceProvider_Release(&ctx
->jscaller
->IServiceProvider_iface
);
82 static void change_state(JScript
*This
, SCRIPTSTATE state
)
84 if(This
->ctx
->state
== state
)
87 This
->ctx
->state
= state
;
89 IActiveScriptSite_OnStateChange(This
->site
, state
);
92 static inline BOOL
is_started(script_ctx_t
*ctx
)
94 return ctx
->state
== SCRIPTSTATE_STARTED
95 || ctx
->state
== SCRIPTSTATE_CONNECTED
96 || ctx
->state
== SCRIPTSTATE_DISCONNECTED
;
99 static HRESULT
exec_global_code(JScript
*This
, bytecode_t
*code
)
101 exec_ctx_t
*exec_ctx
;
105 hres
= create_exec_ctx(This
->ctx
, NULL
, This
->ctx
->global
, NULL
, TRUE
, &exec_ctx
);
109 IActiveScriptSite_OnEnterScript(This
->site
);
111 memset(&jsexcept
, 0, sizeof(jsexcept
));
112 hres
= exec_source(exec_ctx
, code
, &code
->global_code
, FALSE
, &jsexcept
, NULL
);
113 VariantClear(&jsexcept
.var
);
114 exec_release(exec_ctx
);
116 IActiveScriptSite_OnLeaveScript(This
->site
);
120 static void clear_script_queue(JScript
*This
)
122 bytecode_t
*iter
, *iter2
;
124 if(!This
->queue_head
)
127 iter
= This
->queue_head
;
131 release_bytecode(iter
);
135 This
->queue_head
= This
->queue_tail
= NULL
;
138 static void exec_queued_code(JScript
*This
)
142 for(iter
= This
->queue_head
; iter
; iter
= iter
->next
)
143 exec_global_code(This
, iter
);
145 clear_script_queue(This
);
148 static HRESULT
set_ctx_site(JScript
*This
)
152 This
->ctx
->lcid
= This
->lcid
;
154 hres
= init_global(This
->ctx
);
158 IActiveScriptSite_AddRef(This
->site
);
159 This
->ctx
->site
= This
->site
;
161 change_state(This
, SCRIPTSTATE_INITIALIZED
);
165 static void decrease_state(JScript
*This
, SCRIPTSTATE state
)
168 switch(This
->ctx
->state
) {
169 case SCRIPTSTATE_CONNECTED
:
170 change_state(This
, SCRIPTSTATE_DISCONNECTED
);
171 if(state
== SCRIPTSTATE_DISCONNECTED
)
174 case SCRIPTSTATE_STARTED
:
175 case SCRIPTSTATE_DISCONNECTED
:
176 clear_script_queue(This
);
178 if(This
->ctx
->state
== SCRIPTSTATE_DISCONNECTED
)
179 change_state(This
, SCRIPTSTATE_INITIALIZED
);
180 if(state
== SCRIPTSTATE_INITIALIZED
)
183 case SCRIPTSTATE_INITIALIZED
:
184 if(This
->ctx
->host_global
) {
185 IDispatch_Release(This
->ctx
->host_global
);
186 This
->ctx
->host_global
= NULL
;
189 if(This
->ctx
->named_items
) {
190 named_item_t
*iter
, *iter2
;
192 iter
= This
->ctx
->named_items
;
197 IDispatch_Release(iter
->disp
);
198 heap_free(iter
->name
);
203 This
->ctx
->named_items
= NULL
;
206 if(This
->ctx
->secmgr
) {
207 IInternetHostSecurityManager_Release(This
->ctx
->secmgr
);
208 This
->ctx
->secmgr
= NULL
;
211 if(This
->ctx
->site
) {
212 IActiveScriptSite_Release(This
->ctx
->site
);
213 This
->ctx
->site
= NULL
;
216 if(This
->ctx
->global
) {
217 jsdisp_release(This
->ctx
->global
);
218 This
->ctx
->global
= NULL
;
221 case SCRIPTSTATE_UNINITIALIZED
:
222 change_state(This
, state
);
228 change_state(This
, state
);
229 }else if(state
== SCRIPTSTATE_UNINITIALIZED
) {
231 IActiveScriptSite_OnStateChange(This
->site
, state
);
236 if(state
== SCRIPTSTATE_UNINITIALIZED
)
240 IActiveScriptSite_Release(This
->site
);
246 IServiceProvider IServiceProvider_iface
;
250 IServiceProvider
*sp
;
253 static inline AXSite
*impl_from_IServiceProvider(IServiceProvider
*iface
)
255 return CONTAINING_RECORD(iface
, AXSite
, IServiceProvider_iface
);
258 static HRESULT WINAPI
AXSite_QueryInterface(IServiceProvider
*iface
, REFIID riid
, void **ppv
)
260 AXSite
*This
= impl_from_IServiceProvider(iface
);
262 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
263 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
264 *ppv
= &This
->IServiceProvider_iface
;
265 }else if(IsEqualGUID(&IID_IServiceProvider
, riid
)) {
266 TRACE("(%p)->(IID_IServiceProvider %p)\n", This
, ppv
);
267 *ppv
= &This
->IServiceProvider_iface
;
269 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
271 return E_NOINTERFACE
;
274 IUnknown_AddRef((IUnknown
*)*ppv
);
278 static ULONG WINAPI
AXSite_AddRef(IServiceProvider
*iface
)
280 AXSite
*This
= impl_from_IServiceProvider(iface
);
281 LONG ref
= InterlockedIncrement(&This
->ref
);
283 TRACE("(%p) ref=%d\n", This
, ref
);
288 static ULONG WINAPI
AXSite_Release(IServiceProvider
*iface
)
290 AXSite
*This
= impl_from_IServiceProvider(iface
);
291 LONG ref
= InterlockedDecrement(&This
->ref
);
293 TRACE("(%p) ref=%d\n", This
, ref
);
298 IServiceProvider_Release(This
->sp
);
306 static HRESULT WINAPI
AXSite_QueryService(IServiceProvider
*iface
,
307 REFGUID guidService
, REFIID riid
, void **ppv
)
309 AXSite
*This
= impl_from_IServiceProvider(iface
);
311 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_guid(guidService
), debugstr_guid(riid
), ppv
);
314 return E_NOINTERFACE
;
316 return IServiceProvider_QueryService(This
->sp
, guidService
, riid
, ppv
);
319 static IServiceProviderVtbl AXSiteVtbl
= {
320 AXSite_QueryInterface
,
326 IUnknown
*create_ax_site(script_ctx_t
*ctx
)
328 IServiceProvider
*sp
= NULL
;
332 hres
= IActiveScriptSite_QueryInterface(ctx
->site
, &IID_IServiceProvider
, (void**)&sp
);
334 TRACE("Could not get IServiceProvider iface: %08x\n", hres
);
337 ret
= heap_alloc(sizeof(AXSite
));
339 IServiceProvider_Release(sp
);
343 ret
->IServiceProvider_iface
.lpVtbl
= &AXSiteVtbl
;
347 return (IUnknown
*)&ret
->IServiceProvider_iface
;
350 static inline JScript
*impl_from_IActiveScript(IActiveScript
*iface
)
352 return CONTAINING_RECORD(iface
, JScript
, IActiveScript_iface
);
355 static HRESULT WINAPI
JScript_QueryInterface(IActiveScript
*iface
, REFIID riid
, void **ppv
)
357 JScript
*This
= impl_from_IActiveScript(iface
);
361 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
362 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
363 *ppv
= &This
->IActiveScript_iface
;
364 }else if(IsEqualGUID(riid
, &IID_IActiveScript
)) {
365 TRACE("(%p)->(IID_IActiveScript %p)\n", This
, ppv
);
366 *ppv
= &This
->IActiveScript_iface
;
367 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParse
)) {
368 TRACE("(%p)->(IID_IActiveScriptParse %p)\n", This
, ppv
);
369 *ppv
= &This
->IActiveScriptParse_iface
;
370 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParseProcedure
)) {
371 TRACE("(%p)->(IID_IActiveScriptParseProcedure %p)\n", This
, ppv
);
372 *ppv
= &This
->IActiveScriptParseProcedure2_iface
;
373 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParseProcedure2
)) {
374 TRACE("(%p)->(IID_IActiveScriptParseProcedure2 %p)\n", This
, ppv
);
375 *ppv
= &This
->IActiveScriptParseProcedure2_iface
;
376 }else if(IsEqualGUID(riid
, &IID_IActiveScriptProperty
)) {
377 TRACE("(%p)->(IID_IActiveScriptProperty %p)\n", This
, ppv
);
378 *ppv
= &This
->IActiveScriptProperty_iface
;
379 }else if(IsEqualGUID(riid
, &IID_IObjectSafety
)) {
380 TRACE("(%p)->(IID_IObjectSafety %p)\n", This
, ppv
);
381 *ppv
= &This
->IObjectSafety_iface
;
382 }else if(IsEqualGUID(riid
, &IID_IVariantChangeType
)) {
383 TRACE("(%p)->(IID_IVariantChangeType %p)\n", This
, ppv
);
384 *ppv
= &This
->IVariantChangeType_iface
;
388 IUnknown_AddRef((IUnknown
*)*ppv
);
392 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
393 return E_NOINTERFACE
;
396 static ULONG WINAPI
JScript_AddRef(IActiveScript
*iface
)
398 JScript
*This
= impl_from_IActiveScript(iface
);
399 LONG ref
= InterlockedIncrement(&This
->ref
);
401 TRACE("(%p) ref=%d\n", This
, ref
);
406 static ULONG WINAPI
JScript_Release(IActiveScript
*iface
)
408 JScript
*This
= impl_from_IActiveScript(iface
);
409 LONG ref
= InterlockedDecrement(&This
->ref
);
411 TRACE("(%p) ref=%d\n", iface
, ref
);
414 if(This
->ctx
&& This
->ctx
->state
!= SCRIPTSTATE_CLOSED
)
415 IActiveScript_Close(&This
->IActiveScript_iface
);
417 This
->ctx
->active_script
= NULL
;
418 script_release(This
->ctx
);
427 static HRESULT WINAPI
JScript_SetScriptSite(IActiveScript
*iface
,
428 IActiveScriptSite
*pass
)
430 JScript
*This
= impl_from_IActiveScript(iface
);
434 TRACE("(%p)->(%p)\n", This
, pass
);
442 if(InterlockedCompareExchange(&This
->thread_id
, GetCurrentThreadId(), 0))
446 IActiveScriptSite_AddRef(This
->site
);
448 hres
= IActiveScriptSite_GetLCID(This
->site
, &lcid
);
452 return This
->ctx
? set_ctx_site(This
) : S_OK
;
455 static HRESULT WINAPI
JScript_GetScriptSite(IActiveScript
*iface
, REFIID riid
,
458 JScript
*This
= impl_from_IActiveScript(iface
);
459 FIXME("(%p)->()\n", This
);
463 static HRESULT WINAPI
JScript_SetScriptState(IActiveScript
*iface
, SCRIPTSTATE ss
)
465 JScript
*This
= impl_from_IActiveScript(iface
);
467 TRACE("(%p)->(%d)\n", This
, ss
);
469 if(This
->thread_id
&& GetCurrentThreadId() != This
->thread_id
)
472 if(ss
== SCRIPTSTATE_UNINITIALIZED
) {
473 if(This
->ctx
&& This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
476 decrease_state(This
, SCRIPTSTATE_UNINITIALIZED
);
484 case SCRIPTSTATE_STARTED
:
485 case SCRIPTSTATE_CONNECTED
: /* FIXME */
486 if(This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
489 exec_queued_code(This
);
491 case SCRIPTSTATE_INITIALIZED
:
492 FIXME("unimplemented SCRIPTSTATE_INITIALIZED\n");
495 FIXME("unimplemented state %d\n", ss
);
499 change_state(This
, ss
);
503 static HRESULT WINAPI
JScript_GetScriptState(IActiveScript
*iface
, SCRIPTSTATE
*pssState
)
505 JScript
*This
= impl_from_IActiveScript(iface
);
507 TRACE("(%p)->(%p)\n", This
, pssState
);
512 if(This
->thread_id
&& This
->thread_id
!= GetCurrentThreadId())
515 *pssState
= This
->ctx
? This
->ctx
->state
: SCRIPTSTATE_UNINITIALIZED
;
519 static HRESULT WINAPI
JScript_Close(IActiveScript
*iface
)
521 JScript
*This
= impl_from_IActiveScript(iface
);
523 TRACE("(%p)->()\n", This
);
525 if(This
->thread_id
&& This
->thread_id
!= GetCurrentThreadId())
528 decrease_state(This
, SCRIPTSTATE_CLOSED
);
532 static HRESULT WINAPI
JScript_AddNamedItem(IActiveScript
*iface
,
533 LPCOLESTR pstrName
, DWORD dwFlags
)
535 JScript
*This
= impl_from_IActiveScript(iface
);
537 IDispatch
*disp
= NULL
;
540 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(pstrName
), dwFlags
);
542 if(This
->thread_id
!= GetCurrentThreadId() || !This
->ctx
|| This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
545 if(dwFlags
& SCRIPTITEM_GLOBALMEMBERS
) {
548 hres
= IActiveScriptSite_GetItemInfo(This
->site
, pstrName
, SCRIPTINFO_IUNKNOWN
, &unk
, NULL
);
550 WARN("GetItemInfo failed: %08x\n", hres
);
554 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatch
, (void**)&disp
);
555 IUnknown_Release(unk
);
557 WARN("object does not implement IDispatch\n");
561 if(This
->ctx
->host_global
)
562 IDispatch_Release(This
->ctx
->host_global
);
563 IDispatch_AddRef(disp
);
564 This
->ctx
->host_global
= disp
;
567 item
= heap_alloc(sizeof(*item
));
570 IDispatch_Release(disp
);
571 return E_OUTOFMEMORY
;
575 item
->flags
= dwFlags
;
576 item
->name
= heap_strdupW(pstrName
);
579 IDispatch_Release(disp
);
581 return E_OUTOFMEMORY
;
584 item
->next
= This
->ctx
->named_items
;
585 This
->ctx
->named_items
= item
;
590 static HRESULT WINAPI
JScript_AddTypeLib(IActiveScript
*iface
, REFGUID rguidTypeLib
,
591 DWORD dwMajor
, DWORD dwMinor
, DWORD dwFlags
)
593 JScript
*This
= impl_from_IActiveScript(iface
);
594 FIXME("(%p)->()\n", This
);
598 static HRESULT WINAPI
JScript_GetScriptDispatch(IActiveScript
*iface
, LPCOLESTR pstrItemName
,
601 JScript
*This
= impl_from_IActiveScript(iface
);
603 TRACE("(%p)->(%p)\n", This
, ppdisp
);
608 if(This
->thread_id
!= GetCurrentThreadId() || !This
->ctx
->global
) {
613 *ppdisp
= to_disp(This
->ctx
->global
);
614 IDispatch_AddRef(*ppdisp
);
618 static HRESULT WINAPI
JScript_GetCurrentScriptThreadID(IActiveScript
*iface
,
619 SCRIPTTHREADID
*pstridThread
)
621 JScript
*This
= impl_from_IActiveScript(iface
);
622 FIXME("(%p)->()\n", This
);
626 static HRESULT WINAPI
JScript_GetScriptThreadID(IActiveScript
*iface
,
627 DWORD dwWin32ThreadId
, SCRIPTTHREADID
*pstidThread
)
629 JScript
*This
= impl_from_IActiveScript(iface
);
630 FIXME("(%p)->()\n", This
);
634 static HRESULT WINAPI
JScript_GetScriptThreadState(IActiveScript
*iface
,
635 SCRIPTTHREADID stidThread
, SCRIPTTHREADSTATE
*pstsState
)
637 JScript
*This
= impl_from_IActiveScript(iface
);
638 FIXME("(%p)->()\n", This
);
642 static HRESULT WINAPI
JScript_InterruptScriptThread(IActiveScript
*iface
,
643 SCRIPTTHREADID stidThread
, const EXCEPINFO
*pexcepinfo
, DWORD dwFlags
)
645 JScript
*This
= impl_from_IActiveScript(iface
);
646 FIXME("(%p)->()\n", This
);
650 static HRESULT WINAPI
JScript_Clone(IActiveScript
*iface
, IActiveScript
**ppscript
)
652 JScript
*This
= impl_from_IActiveScript(iface
);
653 FIXME("(%p)->()\n", This
);
657 static const IActiveScriptVtbl JScriptVtbl
= {
658 JScript_QueryInterface
,
661 JScript_SetScriptSite
,
662 JScript_GetScriptSite
,
663 JScript_SetScriptState
,
664 JScript_GetScriptState
,
666 JScript_AddNamedItem
,
668 JScript_GetScriptDispatch
,
669 JScript_GetCurrentScriptThreadID
,
670 JScript_GetScriptThreadID
,
671 JScript_GetScriptThreadState
,
672 JScript_InterruptScriptThread
,
676 static inline JScript
*impl_from_IActiveScriptParse(IActiveScriptParse
*iface
)
678 return CONTAINING_RECORD(iface
, JScript
, IActiveScriptParse_iface
);
681 static HRESULT WINAPI
JScriptParse_QueryInterface(IActiveScriptParse
*iface
, REFIID riid
, void **ppv
)
683 JScript
*This
= impl_from_IActiveScriptParse(iface
);
684 return IActiveScript_QueryInterface(&This
->IActiveScript_iface
, riid
, ppv
);
687 static ULONG WINAPI
JScriptParse_AddRef(IActiveScriptParse
*iface
)
689 JScript
*This
= impl_from_IActiveScriptParse(iface
);
690 return IActiveScript_AddRef(&This
->IActiveScript_iface
);
693 static ULONG WINAPI
JScriptParse_Release(IActiveScriptParse
*iface
)
695 JScript
*This
= impl_from_IActiveScriptParse(iface
);
696 return IActiveScript_Release(&This
->IActiveScript_iface
);
699 static HRESULT WINAPI
JScriptParse_InitNew(IActiveScriptParse
*iface
)
701 JScript
*This
= impl_from_IActiveScriptParse(iface
);
705 TRACE("(%p)\n", This
);
710 ctx
= heap_alloc_zero(sizeof(script_ctx_t
));
712 return E_OUTOFMEMORY
;
715 ctx
->state
= SCRIPTSTATE_UNINITIALIZED
;
716 ctx
->active_script
= &This
->IActiveScript_iface
;
717 ctx
->safeopt
= This
->safeopt
;
718 ctx
->version
= This
->version
;
719 jsheap_init(&ctx
->tmp_heap
);
721 hres
= create_jscaller(ctx
);
727 ctx
= InterlockedCompareExchangePointer((void**)&This
->ctx
, ctx
, NULL
);
733 return This
->site
? set_ctx_site(This
) : S_OK
;
736 static HRESULT WINAPI
JScriptParse_AddScriptlet(IActiveScriptParse
*iface
,
737 LPCOLESTR pstrDefaultName
, LPCOLESTR pstrCode
, LPCOLESTR pstrItemName
,
738 LPCOLESTR pstrSubItemName
, LPCOLESTR pstrEventName
, LPCOLESTR pstrDelimiter
,
739 CTXARG_T dwSourceContextCookie
, ULONG ulStartingLineNumber
, DWORD dwFlags
,
740 BSTR
*pbstrName
, EXCEPINFO
*pexcepinfo
)
742 JScript
*This
= impl_from_IActiveScriptParse(iface
);
743 FIXME("(%p)->(%s %s %s %s %s %s %s %u %x %p %p)\n", This
, debugstr_w(pstrDefaultName
),
744 debugstr_w(pstrCode
), debugstr_w(pstrItemName
), debugstr_w(pstrSubItemName
),
745 debugstr_w(pstrEventName
), debugstr_w(pstrDelimiter
), wine_dbgstr_longlong(dwSourceContextCookie
),
746 ulStartingLineNumber
, dwFlags
, pbstrName
, pexcepinfo
);
750 static HRESULT WINAPI
JScriptParse_ParseScriptText(IActiveScriptParse
*iface
,
751 LPCOLESTR pstrCode
, LPCOLESTR pstrItemName
, IUnknown
*punkContext
,
752 LPCOLESTR pstrDelimiter
, CTXARG_T dwSourceContextCookie
, ULONG ulStartingLine
,
753 DWORD dwFlags
, VARIANT
*pvarResult
, EXCEPINFO
*pexcepinfo
)
755 JScript
*This
= impl_from_IActiveScriptParse(iface
);
759 TRACE("(%p)->(%s %s %p %s %s %u %x %p %p)\n", This
, debugstr_w(pstrCode
),
760 debugstr_w(pstrItemName
), punkContext
, debugstr_w(pstrDelimiter
),
761 wine_dbgstr_longlong(dwSourceContextCookie
), ulStartingLine
, dwFlags
, pvarResult
, pexcepinfo
);
763 if(This
->thread_id
!= GetCurrentThreadId() || This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
766 hres
= compile_script(This
->ctx
, pstrCode
, pstrDelimiter
, FALSE
, This
->is_encode
, &code
);
770 if(!is_started(This
->ctx
)) {
772 This
->queue_tail
= This
->queue_tail
->next
= code
;
774 This
->queue_head
= This
->queue_tail
= code
;
778 hres
= exec_global_code(This
, code
);
780 release_bytecode(code
);
784 static const IActiveScriptParseVtbl JScriptParseVtbl
= {
785 JScriptParse_QueryInterface
,
787 JScriptParse_Release
,
788 JScriptParse_InitNew
,
789 JScriptParse_AddScriptlet
,
790 JScriptParse_ParseScriptText
793 static inline JScript
*impl_from_IActiveScriptParseProcedure2(IActiveScriptParseProcedure2
*iface
)
795 return CONTAINING_RECORD(iface
, JScript
, IActiveScriptParseProcedure2_iface
);
798 static HRESULT WINAPI
JScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2
*iface
, REFIID riid
, void **ppv
)
800 JScript
*This
= impl_from_IActiveScriptParseProcedure2(iface
);
801 return IActiveScript_QueryInterface(&This
->IActiveScript_iface
, riid
, ppv
);
804 static ULONG WINAPI
JScriptParseProcedure_AddRef(IActiveScriptParseProcedure2
*iface
)
806 JScript
*This
= impl_from_IActiveScriptParseProcedure2(iface
);
807 return IActiveScript_AddRef(&This
->IActiveScript_iface
);
810 static ULONG WINAPI
JScriptParseProcedure_Release(IActiveScriptParseProcedure2
*iface
)
812 JScript
*This
= impl_from_IActiveScriptParseProcedure2(iface
);
813 return IActiveScript_Release(&This
->IActiveScript_iface
);
816 static HRESULT WINAPI
JScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2
*iface
,
817 LPCOLESTR pstrCode
, LPCOLESTR pstrFormalParams
, LPCOLESTR pstrProcedureName
,
818 LPCOLESTR pstrItemName
, IUnknown
*punkContext
, LPCOLESTR pstrDelimiter
,
819 CTXARG_T dwSourceContextCookie
, ULONG ulStartingLineNumber
, DWORD dwFlags
, IDispatch
**ppdisp
)
821 JScript
*This
= impl_from_IActiveScriptParseProcedure2(iface
);
826 TRACE("(%p)->(%s %s %s %s %p %s %s %u %x %p)\n", This
, debugstr_w(pstrCode
), debugstr_w(pstrFormalParams
),
827 debugstr_w(pstrProcedureName
), debugstr_w(pstrItemName
), punkContext
, debugstr_w(pstrDelimiter
),
828 wine_dbgstr_longlong(dwSourceContextCookie
), ulStartingLineNumber
, dwFlags
, ppdisp
);
830 if(This
->thread_id
!= GetCurrentThreadId() || This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
833 hres
= compile_script(This
->ctx
, pstrCode
, pstrDelimiter
, FALSE
, This
->is_encode
, &code
);
835 WARN("Parse failed %08x\n", hres
);
839 hres
= create_source_function(This
->ctx
, code
, &code
->global_code
, NULL
, &dispex
);
840 release_bytecode(code
);
844 *ppdisp
= to_disp(dispex
);
848 static const IActiveScriptParseProcedure2Vtbl JScriptParseProcedureVtbl
= {
849 JScriptParseProcedure_QueryInterface
,
850 JScriptParseProcedure_AddRef
,
851 JScriptParseProcedure_Release
,
852 JScriptParseProcedure_ParseProcedureText
,
855 static inline JScript
*impl_from_IActiveScriptProperty(IActiveScriptProperty
*iface
)
857 return CONTAINING_RECORD(iface
, JScript
, IActiveScriptProperty_iface
);
860 static HRESULT WINAPI
JScriptProperty_QueryInterface(IActiveScriptProperty
*iface
, REFIID riid
, void **ppv
)
862 JScript
*This
= impl_from_IActiveScriptProperty(iface
);
863 return IActiveScript_QueryInterface(&This
->IActiveScript_iface
, riid
, ppv
);
866 static ULONG WINAPI
JScriptProperty_AddRef(IActiveScriptProperty
*iface
)
868 JScript
*This
= impl_from_IActiveScriptProperty(iface
);
869 return IActiveScript_AddRef(&This
->IActiveScript_iface
);
872 static ULONG WINAPI
JScriptProperty_Release(IActiveScriptProperty
*iface
)
874 JScript
*This
= impl_from_IActiveScriptProperty(iface
);
875 return IActiveScript_Release(&This
->IActiveScript_iface
);
878 static HRESULT WINAPI
JScriptProperty_GetProperty(IActiveScriptProperty
*iface
, DWORD dwProperty
,
879 VARIANT
*pvarIndex
, VARIANT
*pvarValue
)
881 JScript
*This
= impl_from_IActiveScriptProperty(iface
);
882 FIXME("(%p)->(%x %p %p)\n", This
, dwProperty
, pvarIndex
, pvarValue
);
886 static HRESULT WINAPI
JScriptProperty_SetProperty(IActiveScriptProperty
*iface
, DWORD dwProperty
,
887 VARIANT
*pvarIndex
, VARIANT
*pvarValue
)
889 JScript
*This
= impl_from_IActiveScriptProperty(iface
);
891 TRACE("(%p)->(%x %s %s)\n", This
, dwProperty
, debugstr_variant(pvarIndex
), debugstr_variant(pvarValue
));
894 FIXME("unsupported pvarIndex\n");
897 case SCRIPTPROP_INVOKEVERSIONING
:
898 if(V_VT(pvarValue
) != VT_I4
|| V_I4(pvarValue
) < 0 || V_I4(pvarValue
) > 15) {
899 WARN("invalid value %s\n", debugstr_variant(pvarValue
));
903 This
->version
= V_I4(pvarValue
);
906 FIXME("Unimplemented property %x\n", dwProperty
);
913 static const IActiveScriptPropertyVtbl JScriptPropertyVtbl
= {
914 JScriptProperty_QueryInterface
,
915 JScriptProperty_AddRef
,
916 JScriptProperty_Release
,
917 JScriptProperty_GetProperty
,
918 JScriptProperty_SetProperty
921 static inline JScript
*impl_from_IObjectSafety(IObjectSafety
*iface
)
923 return CONTAINING_RECORD(iface
, JScript
, IObjectSafety_iface
);
926 static HRESULT WINAPI
JScriptSafety_QueryInterface(IObjectSafety
*iface
, REFIID riid
, void **ppv
)
928 JScript
*This
= impl_from_IObjectSafety(iface
);
929 return IActiveScript_QueryInterface(&This
->IActiveScript_iface
, riid
, ppv
);
932 static ULONG WINAPI
JScriptSafety_AddRef(IObjectSafety
*iface
)
934 JScript
*This
= impl_from_IObjectSafety(iface
);
935 return IActiveScript_AddRef(&This
->IActiveScript_iface
);
938 static ULONG WINAPI
JScriptSafety_Release(IObjectSafety
*iface
)
940 JScript
*This
= impl_from_IObjectSafety(iface
);
941 return IActiveScript_Release(&This
->IActiveScript_iface
);
944 #define SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER)
946 static HRESULT WINAPI
JScriptSafety_GetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
947 DWORD
*pdwSupportedOptions
, DWORD
*pdwEnabledOptions
)
949 JScript
*This
= impl_from_IObjectSafety(iface
);
951 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_guid(riid
), pdwSupportedOptions
, pdwEnabledOptions
);
953 if(!pdwSupportedOptions
|| !pdwEnabledOptions
)
956 *pdwSupportedOptions
= SUPPORTED_OPTIONS
;
957 *pdwEnabledOptions
= This
->safeopt
;
962 static HRESULT WINAPI
JScriptSafety_SetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
963 DWORD dwOptionSetMask
, DWORD dwEnabledOptions
)
965 JScript
*This
= impl_from_IObjectSafety(iface
);
967 TRACE("(%p)->(%s %x %x)\n", This
, debugstr_guid(riid
), dwOptionSetMask
, dwEnabledOptions
);
969 if(dwOptionSetMask
& ~SUPPORTED_OPTIONS
)
972 This
->safeopt
= (dwEnabledOptions
& dwOptionSetMask
) | (This
->safeopt
& ~dwOptionSetMask
) | INTERFACE_USES_DISPEX
;
976 static const IObjectSafetyVtbl JScriptSafetyVtbl
= {
977 JScriptSafety_QueryInterface
,
978 JScriptSafety_AddRef
,
979 JScriptSafety_Release
,
980 JScriptSafety_GetInterfaceSafetyOptions
,
981 JScriptSafety_SetInterfaceSafetyOptions
984 static inline JScript
*impl_from_IVariantChangeType(IVariantChangeType
*iface
)
986 return CONTAINING_RECORD(iface
, JScript
, IVariantChangeType_iface
);
989 static HRESULT WINAPI
VariantChangeType_QueryInterface(IVariantChangeType
*iface
, REFIID riid
, void **ppv
)
991 JScript
*This
= impl_from_IVariantChangeType(iface
);
992 return IActiveScript_QueryInterface(&This
->IActiveScript_iface
, riid
, ppv
);
995 static ULONG WINAPI
VariantChangeType_AddRef(IVariantChangeType
*iface
)
997 JScript
*This
= impl_from_IVariantChangeType(iface
);
998 return IActiveScript_AddRef(&This
->IActiveScript_iface
);
1001 static ULONG WINAPI
VariantChangeType_Release(IVariantChangeType
*iface
)
1003 JScript
*This
= impl_from_IVariantChangeType(iface
);
1004 return IActiveScript_Release(&This
->IActiveScript_iface
);
1007 static HRESULT WINAPI
VariantChangeType_ChangeType(IVariantChangeType
*iface
, VARIANT
*dst
, VARIANT
*src
, LCID lcid
, VARTYPE vt
)
1009 JScript
*This
= impl_from_IVariantChangeType(iface
);
1012 TRACE("(%p)->(%p %s %x %d)\n", This
, dst
, debugstr_variant(src
), lcid
, vt
);
1015 FIXME("Object uninitialized\n");
1016 return E_UNEXPECTED
;
1019 hres
= VariantClear(dst
);
1023 return variant_change_type(This
->ctx
, dst
, src
, vt
);
1026 static const IVariantChangeTypeVtbl VariantChangeTypeVtbl
= {
1027 VariantChangeType_QueryInterface
,
1028 VariantChangeType_AddRef
,
1029 VariantChangeType_Release
,
1030 VariantChangeType_ChangeType
1033 HRESULT
create_jscript_object(BOOL is_encode
, REFIID riid
, void **ppv
)
1038 ret
= heap_alloc_zero(sizeof(*ret
));
1040 return E_OUTOFMEMORY
;
1044 ret
->IActiveScript_iface
.lpVtbl
= &JScriptVtbl
;
1045 ret
->IActiveScriptParse_iface
.lpVtbl
= &JScriptParseVtbl
;
1046 ret
->IActiveScriptParseProcedure2_iface
.lpVtbl
= &JScriptParseProcedureVtbl
;
1047 ret
->IActiveScriptProperty_iface
.lpVtbl
= &JScriptPropertyVtbl
;
1048 ret
->IObjectSafety_iface
.lpVtbl
= &JScriptSafetyVtbl
;
1049 ret
->IVariantChangeType_iface
.lpVtbl
= &VariantChangeTypeVtbl
;
1051 ret
->safeopt
= INTERFACE_USES_DISPEX
;
1052 ret
->is_encode
= is_encode
;
1054 hres
= IActiveScript_QueryInterface(&ret
->IActiveScript_iface
, riid
, ppv
);
1055 IActiveScript_Release(&ret
->IActiveScript_iface
);