2 * Copyright 2008 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(jscript
);
29 #define CTXARG_T DWORDLONG
30 #define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
31 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_64Vtbl
35 #define CTXARG_T DWORD
36 #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
37 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_32Vtbl
42 const IActiveScriptVtbl
*lpIActiveScriptVtbl
;
43 const IActiveScriptParseVtbl
*lpIActiveScriptParseVtbl
;
44 const IActiveScriptParseProcedure2Vtbl
*lpIActiveScriptParseProcedure2Vtbl
;
45 const IActiveScriptPropertyVtbl
*lpIActiveScriptPropertyVtbl
;
46 const IObjectSafetyVtbl
*lpIObjectSafetyVtbl
;
56 IActiveScriptSite
*site
;
58 parser_ctx_t
*queue_head
;
59 parser_ctx_t
*queue_tail
;
62 #define ACTSCRIPT(x) ((IActiveScript*) &(x)->lpIActiveScriptVtbl)
63 #define ASPARSE(x) (&(x)->lpIActiveScriptParseVtbl)
64 #define ASPARSEPROC(x) (&(x)->lpIActiveScriptParseProcedure2Vtbl)
65 #define ACTSCPPROP(x) (&(x)->lpIActiveScriptPropertyVtbl)
66 #define OBJSAFETY(x) (&(x)->lpIObjectSafetyVtbl)
68 void script_release(script_ctx_t
*ctx
)
73 jsheap_free(&ctx
->tmp_heap
);
74 SysFreeString(ctx
->last_match
);
78 static void change_state(JScript
*This
, SCRIPTSTATE state
)
80 if(This
->ctx
->state
== state
)
83 This
->ctx
->state
= state
;
84 IActiveScriptSite_OnStateChange(This
->site
, state
);
87 static inline BOOL
is_started(script_ctx_t
*ctx
)
89 return ctx
->state
== SCRIPTSTATE_STARTED
90 || ctx
->state
== SCRIPTSTATE_CONNECTED
91 || ctx
->state
== SCRIPTSTATE_DISCONNECTED
;
94 static HRESULT
exec_global_code(JScript
*This
, parser_ctx_t
*parser_ctx
)
100 hres
= create_exec_ctx(This
->ctx
, NULL
, This
->ctx
->global
, NULL
, TRUE
, &exec_ctx
);
104 IActiveScriptSite_OnEnterScript(This
->site
);
106 memset(&jsexcept
, 0, sizeof(jsexcept
));
107 hres
= exec_source(exec_ctx
, parser_ctx
, parser_ctx
->source
, FALSE
, &jsexcept
, NULL
);
108 VariantClear(&jsexcept
.var
);
109 exec_release(exec_ctx
);
111 IActiveScriptSite_OnLeaveScript(This
->site
);
115 static void clear_script_queue(JScript
*This
)
117 parser_ctx_t
*iter
, *iter2
;
119 if(!This
->queue_head
)
122 iter
= This
->queue_head
;
126 parser_release(iter
);
130 This
->queue_head
= This
->queue_tail
= NULL
;
133 static void exec_queued_code(JScript
*This
)
137 for(iter
= This
->queue_head
; iter
; iter
= iter
->next
)
138 exec_global_code(This
, iter
);
140 clear_script_queue(This
);
143 static HRESULT
set_ctx_site(JScript
*This
)
147 This
->ctx
->lcid
= This
->lcid
;
149 hres
= init_global(This
->ctx
);
153 IActiveScriptSite_AddRef(This
->site
);
154 This
->ctx
->site
= This
->site
;
156 change_state(This
, SCRIPTSTATE_INITIALIZED
);
161 const IServiceProviderVtbl
*lpIServiceProviderVtbl
;
165 IServiceProvider
*sp
;
168 #define SERVPROV(x) ((IServiceProvider*) &(x)->lpIServiceProviderVtbl)
170 #define SERVPROV_THIS(iface) DEFINE_THIS(AXSite, IServiceProvider, iface)
172 static HRESULT WINAPI
AXSite_QueryInterface(IServiceProvider
*iface
, REFIID riid
, void **ppv
)
174 AXSite
*This
= SERVPROV_THIS(iface
);
176 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
177 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
178 *ppv
= SERVPROV(This
);
179 }else if(IsEqualGUID(&IID_IServiceProvider
, riid
)) {
180 TRACE("(%p)->(IID_IServiceProvider %p)\n", This
, ppv
);
181 *ppv
= SERVPROV(This
);
183 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
185 return E_NOINTERFACE
;
188 IUnknown_AddRef((IUnknown
*)*ppv
);
192 static ULONG WINAPI
AXSite_AddRef(IServiceProvider
*iface
)
194 AXSite
*This
= SERVPROV_THIS(iface
);
195 LONG ref
= InterlockedIncrement(&This
->ref
);
197 TRACE("(%p) ref=%d\n", This
, ref
);
202 static ULONG WINAPI
AXSite_Release(IServiceProvider
*iface
)
204 AXSite
*This
= SERVPROV_THIS(iface
);
205 LONG ref
= InterlockedDecrement(&This
->ref
);
207 TRACE("(%p) ref=%d\n", This
, ref
);
215 static HRESULT WINAPI
AXSite_QueryService(IServiceProvider
*iface
,
216 REFGUID guidService
, REFIID riid
, void **ppv
)
218 AXSite
*This
= SERVPROV_THIS(iface
);
220 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_guid(guidService
), debugstr_guid(riid
), ppv
);
222 return IServiceProvider_QueryService(This
->sp
, guidService
, riid
, ppv
);
227 static IServiceProviderVtbl AXSiteVtbl
= {
228 AXSite_QueryInterface
,
234 IUnknown
*create_ax_site(script_ctx_t
*ctx
)
236 IServiceProvider
*sp
;
240 hres
= IActiveScriptSite_QueryInterface(ctx
->site
, &IID_IServiceProvider
, (void**)&sp
);
242 ERR("Could not get IServiceProvider iface: %08x\n", hres
);
246 ret
= heap_alloc(sizeof(AXSite
));
248 IServiceProvider_Release(sp
);
252 ret
->lpIServiceProviderVtbl
= &AXSiteVtbl
;
256 return (IUnknown
*)SERVPROV(ret
);
259 #define ACTSCRIPT_THIS(iface) DEFINE_THIS(JScript, IActiveScript, iface)
261 static HRESULT WINAPI
JScript_QueryInterface(IActiveScript
*iface
, REFIID riid
, void **ppv
)
263 JScript
*This
= ACTSCRIPT_THIS(iface
);
267 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
268 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
269 *ppv
= ACTSCRIPT(This
);
270 }else if(IsEqualGUID(riid
, &IID_IActiveScript
)) {
271 TRACE("(%p)->(IID_IActiveScript %p)\n", This
, ppv
);
272 *ppv
= ACTSCRIPT(This
);
273 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParse
)) {
274 TRACE("(%p)->(IID_IActiveScriptParse %p)\n", This
, ppv
);
275 *ppv
= ASPARSE(This
);
276 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParseProcedure
)) {
277 TRACE("(%p)->(IID_IActiveScriptParseProcedure %p)\n", This
, ppv
);
278 *ppv
= ASPARSEPROC(This
);
279 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParseProcedure2
)) {
280 TRACE("(%p)->(IID_IActiveScriptParseProcedure2 %p)\n", This
, ppv
);
281 *ppv
= ASPARSEPROC(This
);
282 }else if(IsEqualGUID(riid
, &IID_IActiveScriptProperty
)) {
283 TRACE("(%p)->(IID_IActiveScriptProperty %p)\n", This
, ppv
);
284 *ppv
= ACTSCPPROP(This
);
285 }else if(IsEqualGUID(riid
, &IID_IObjectSafety
)) {
286 TRACE("(%p)->(IID_IObjectSafety %p)\n", This
, ppv
);
287 *ppv
= OBJSAFETY(This
);
291 IUnknown_AddRef((IUnknown
*)*ppv
);
295 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
296 return E_NOINTERFACE
;
299 static ULONG WINAPI
JScript_AddRef(IActiveScript
*iface
)
301 JScript
*This
= ACTSCRIPT_THIS(iface
);
302 LONG ref
= InterlockedIncrement(&This
->ref
);
304 TRACE("(%p) ref=%d\n", This
, ref
);
309 static ULONG WINAPI
JScript_Release(IActiveScript
*iface
)
311 JScript
*This
= ACTSCRIPT_THIS(iface
);
312 LONG ref
= InterlockedDecrement(&This
->ref
);
314 TRACE("(%p) ref=%d\n", iface
, ref
);
317 if(This
->ctx
&& This
->ctx
->state
!= SCRIPTSTATE_CLOSED
)
318 IActiveScript_Close(ACTSCRIPT(This
));
320 script_release(This
->ctx
);
328 static HRESULT WINAPI
JScript_SetScriptSite(IActiveScript
*iface
,
329 IActiveScriptSite
*pass
)
331 JScript
*This
= ACTSCRIPT_THIS(iface
);
335 TRACE("(%p)->(%p)\n", This
, pass
);
343 if(InterlockedCompareExchange(&This
->thread_id
, GetCurrentThreadId(), 0))
347 IActiveScriptSite_AddRef(This
->site
);
349 hres
= IActiveScriptSite_GetLCID(This
->site
, &lcid
);
353 return This
->ctx
? set_ctx_site(This
) : S_OK
;
356 static HRESULT WINAPI
JScript_GetScriptSite(IActiveScript
*iface
, REFIID riid
,
359 JScript
*This
= ACTSCRIPT_THIS(iface
);
360 FIXME("(%p)->()\n", This
);
364 static HRESULT WINAPI
JScript_SetScriptState(IActiveScript
*iface
, SCRIPTSTATE ss
)
366 JScript
*This
= ACTSCRIPT_THIS(iface
);
368 TRACE("(%p)->(%d)\n", This
, ss
);
370 if(!This
->ctx
|| GetCurrentThreadId() != This
->thread_id
)
374 case SCRIPTSTATE_STARTED
:
375 case SCRIPTSTATE_CONNECTED
: /* FIXME */
376 if(This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
379 exec_queued_code(This
);
381 case SCRIPTSTATE_INITIALIZED
:
382 FIXME("unimplemented SCRIPTSTATE_INITIALIZED\n");
385 FIXME("unimplemented state %d\n", ss
);
389 change_state(This
, ss
);
393 static HRESULT WINAPI
JScript_GetScriptState(IActiveScript
*iface
, SCRIPTSTATE
*pssState
)
395 JScript
*This
= ACTSCRIPT_THIS(iface
);
397 TRACE("(%p)->(%p)\n", This
, pssState
);
402 if(!This
->thread_id
) {
403 *pssState
= SCRIPTSTATE_UNINITIALIZED
;
407 if(This
->thread_id
!= GetCurrentThreadId())
410 *pssState
= This
->ctx
? This
->ctx
->state
: SCRIPTSTATE_UNINITIALIZED
;
414 static HRESULT WINAPI
JScript_Close(IActiveScript
*iface
)
416 JScript
*This
= ACTSCRIPT_THIS(iface
);
418 TRACE("(%p)->()\n", This
);
420 if(This
->thread_id
!= GetCurrentThreadId())
424 if(This
->ctx
->state
== SCRIPTSTATE_CONNECTED
)
425 change_state(This
, SCRIPTSTATE_DISCONNECTED
);
427 clear_script_queue(This
);
429 if(This
->ctx
->state
== SCRIPTSTATE_DISCONNECTED
)
430 change_state(This
, SCRIPTSTATE_INITIALIZED
);
432 if(This
->ctx
->host_global
) {
433 IDispatch_Release(This
->ctx
->host_global
);
434 This
->ctx
->host_global
= NULL
;
437 if(This
->ctx
->named_items
) {
438 named_item_t
*iter
, *iter2
;
440 iter
= This
->ctx
->named_items
;
445 IDispatch_Release(iter
->disp
);
446 heap_free(iter
->name
);
451 This
->ctx
->named_items
= NULL
;
454 if(This
->ctx
->secmgr
) {
455 IInternetHostSecurityManager_Release(This
->ctx
->secmgr
);
456 This
->ctx
->secmgr
= NULL
;
459 if(This
->ctx
->site
) {
460 IActiveScriptSite_Release(This
->ctx
->site
);
461 This
->ctx
->site
= NULL
;
465 change_state(This
, SCRIPTSTATE_CLOSED
);
467 if(This
->ctx
->global
) {
468 jsdisp_release(This
->ctx
->global
);
469 This
->ctx
->global
= NULL
;
474 IActiveScriptSite_Release(This
->site
);
481 static HRESULT WINAPI
JScript_AddNamedItem(IActiveScript
*iface
,
482 LPCOLESTR pstrName
, DWORD dwFlags
)
484 JScript
*This
= ACTSCRIPT_THIS(iface
);
486 IDispatch
*disp
= NULL
;
489 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(pstrName
), dwFlags
);
491 if(This
->thread_id
!= GetCurrentThreadId() || !This
->ctx
|| This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
494 if(dwFlags
& SCRIPTITEM_GLOBALMEMBERS
) {
497 hres
= IActiveScriptSite_GetItemInfo(This
->site
, pstrName
, SCRIPTINFO_IUNKNOWN
, &unk
, NULL
);
499 WARN("GetItemInfo failed: %08x\n", hres
);
503 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatch
, (void**)&disp
);
504 IUnknown_Release(unk
);
506 WARN("object does not implement IDispatch\n");
510 if(This
->ctx
->host_global
)
511 IDispatch_Release(This
->ctx
->host_global
);
512 IDispatch_AddRef(disp
);
513 This
->ctx
->host_global
= disp
;
516 item
= heap_alloc(sizeof(*item
));
519 IDispatch_Release(disp
);
520 return E_OUTOFMEMORY
;
524 item
->flags
= dwFlags
;
525 item
->name
= heap_strdupW(pstrName
);
527 IDispatch_Release(disp
);
529 return E_OUTOFMEMORY
;
532 item
->next
= This
->ctx
->named_items
;
533 This
->ctx
->named_items
= item
;
538 static HRESULT WINAPI
JScript_AddTypeLib(IActiveScript
*iface
, REFGUID rguidTypeLib
,
539 DWORD dwMajor
, DWORD dwMinor
, DWORD dwFlags
)
541 JScript
*This
= ACTSCRIPT_THIS(iface
);
542 FIXME("(%p)->()\n", This
);
546 static HRESULT WINAPI
JScript_GetScriptDispatch(IActiveScript
*iface
, LPCOLESTR pstrItemName
,
549 JScript
*This
= ACTSCRIPT_THIS(iface
);
551 TRACE("(%p)->(%p)\n", This
, ppdisp
);
556 if(This
->thread_id
!= GetCurrentThreadId() || !This
->ctx
->global
) {
561 *ppdisp
= to_disp(This
->ctx
->global
);
562 IDispatch_AddRef(*ppdisp
);
566 static HRESULT WINAPI
JScript_GetCurrentScriptThreadID(IActiveScript
*iface
,
567 SCRIPTTHREADID
*pstridThread
)
569 JScript
*This
= ACTSCRIPT_THIS(iface
);
570 FIXME("(%p)->()\n", This
);
574 static HRESULT WINAPI
JScript_GetScriptThreadID(IActiveScript
*iface
,
575 DWORD dwWin32ThreadId
, SCRIPTTHREADID
*pstidThread
)
577 JScript
*This
= ACTSCRIPT_THIS(iface
);
578 FIXME("(%p)->()\n", This
);
582 static HRESULT WINAPI
JScript_GetScriptThreadState(IActiveScript
*iface
,
583 SCRIPTTHREADID stidThread
, SCRIPTTHREADSTATE
*pstsState
)
585 JScript
*This
= ACTSCRIPT_THIS(iface
);
586 FIXME("(%p)->()\n", This
);
590 static HRESULT WINAPI
JScript_InterruptScriptThread(IActiveScript
*iface
,
591 SCRIPTTHREADID stidThread
, const EXCEPINFO
*pexcepinfo
, DWORD dwFlags
)
593 JScript
*This
= ACTSCRIPT_THIS(iface
);
594 FIXME("(%p)->()\n", This
);
598 static HRESULT WINAPI
JScript_Clone(IActiveScript
*iface
, IActiveScript
**ppscript
)
600 JScript
*This
= ACTSCRIPT_THIS(iface
);
601 FIXME("(%p)->()\n", This
);
605 #undef ACTSCRIPT_THIS
607 static const IActiveScriptVtbl JScriptVtbl
= {
608 JScript_QueryInterface
,
611 JScript_SetScriptSite
,
612 JScript_GetScriptSite
,
613 JScript_SetScriptState
,
614 JScript_GetScriptState
,
616 JScript_AddNamedItem
,
618 JScript_GetScriptDispatch
,
619 JScript_GetCurrentScriptThreadID
,
620 JScript_GetScriptThreadID
,
621 JScript_GetScriptThreadState
,
622 JScript_InterruptScriptThread
,
626 #define ASPARSE_THIS(iface) DEFINE_THIS(JScript, IActiveScriptParse, iface)
628 static HRESULT WINAPI
JScriptParse_QueryInterface(IActiveScriptParse
*iface
, REFIID riid
, void **ppv
)
630 JScript
*This
= ASPARSE_THIS(iface
);
631 return IActiveScript_QueryInterface(ACTSCRIPT(This
), riid
, ppv
);
634 static ULONG WINAPI
JScriptParse_AddRef(IActiveScriptParse
*iface
)
636 JScript
*This
= ASPARSE_THIS(iface
);
637 return IActiveScript_AddRef(ACTSCRIPT(This
));
640 static ULONG WINAPI
JScriptParse_Release(IActiveScriptParse
*iface
)
642 JScript
*This
= ASPARSE_THIS(iface
);
643 return IActiveScript_Release(ACTSCRIPT(This
));
646 static HRESULT WINAPI
JScriptParse_InitNew(IActiveScriptParse
*iface
)
648 JScript
*This
= ASPARSE_THIS(iface
);
651 TRACE("(%p)\n", This
);
656 ctx
= heap_alloc_zero(sizeof(script_ctx_t
));
658 return E_OUTOFMEMORY
;
661 ctx
->state
= SCRIPTSTATE_UNINITIALIZED
;
662 ctx
->safeopt
= This
->safeopt
;
663 ctx
->version
= This
->version
;
664 jsheap_init(&ctx
->tmp_heap
);
666 ctx
= InterlockedCompareExchangePointer((void**)&This
->ctx
, ctx
, NULL
);
672 return This
->site
? set_ctx_site(This
) : S_OK
;
675 static HRESULT WINAPI
JScriptParse_AddScriptlet(IActiveScriptParse
*iface
,
676 LPCOLESTR pstrDefaultName
, LPCOLESTR pstrCode
, LPCOLESTR pstrItemName
,
677 LPCOLESTR pstrSubItemName
, LPCOLESTR pstrEventName
, LPCOLESTR pstrDelimiter
,
678 CTXARG_T dwSourceContextCookie
, ULONG ulStartingLineNumber
, DWORD dwFlags
,
679 BSTR
*pbstrName
, EXCEPINFO
*pexcepinfo
)
681 JScript
*This
= ASPARSE_THIS(iface
);
682 FIXME("(%p)->(%s %s %s %s %s %s %s %u %x %p %p)\n", This
, debugstr_w(pstrDefaultName
),
683 debugstr_w(pstrCode
), debugstr_w(pstrItemName
), debugstr_w(pstrSubItemName
),
684 debugstr_w(pstrEventName
), debugstr_w(pstrDelimiter
), wine_dbgstr_longlong(dwSourceContextCookie
),
685 ulStartingLineNumber
, dwFlags
, pbstrName
, pexcepinfo
);
689 static HRESULT WINAPI
JScriptParse_ParseScriptText(IActiveScriptParse
*iface
,
690 LPCOLESTR pstrCode
, LPCOLESTR pstrItemName
, IUnknown
*punkContext
,
691 LPCOLESTR pstrDelimiter
, CTXARG_T dwSourceContextCookie
, ULONG ulStartingLine
,
692 DWORD dwFlags
, VARIANT
*pvarResult
, EXCEPINFO
*pexcepinfo
)
694 JScript
*This
= ASPARSE_THIS(iface
);
695 parser_ctx_t
*parser_ctx
;
698 TRACE("(%p)->(%s %s %p %s %s %u %x %p %p)\n", This
, debugstr_w(pstrCode
),
699 debugstr_w(pstrItemName
), punkContext
, debugstr_w(pstrDelimiter
),
700 wine_dbgstr_longlong(dwSourceContextCookie
), ulStartingLine
, dwFlags
, pvarResult
, pexcepinfo
);
702 if(This
->thread_id
!= GetCurrentThreadId() || This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
705 hres
= script_parse(This
->ctx
, pstrCode
, pstrDelimiter
, &parser_ctx
);
709 if(!is_started(This
->ctx
)) {
711 This
->queue_tail
= This
->queue_tail
->next
= parser_ctx
;
713 This
->queue_head
= This
->queue_tail
= parser_ctx
;
717 hres
= exec_global_code(This
, parser_ctx
);
718 parser_release(parser_ctx
);
725 static const IActiveScriptParseVtbl JScriptParseVtbl
= {
726 JScriptParse_QueryInterface
,
728 JScriptParse_Release
,
729 JScriptParse_InitNew
,
730 JScriptParse_AddScriptlet
,
731 JScriptParse_ParseScriptText
734 #define ASPARSEPROC_THIS(iface) DEFINE_THIS(JScript, IActiveScriptParseProcedure2, iface)
736 static HRESULT WINAPI
JScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2
*iface
, REFIID riid
, void **ppv
)
738 JScript
*This
= ASPARSEPROC_THIS(iface
);
739 return IActiveScript_QueryInterface(ACTSCRIPT(This
), riid
, ppv
);
742 static ULONG WINAPI
JScriptParseProcedure_AddRef(IActiveScriptParseProcedure2
*iface
)
744 JScript
*This
= ASPARSEPROC_THIS(iface
);
745 return IActiveScript_AddRef(ACTSCRIPT(This
));
748 static ULONG WINAPI
JScriptParseProcedure_Release(IActiveScriptParseProcedure2
*iface
)
750 JScript
*This
= ASPARSEPROC_THIS(iface
);
751 return IActiveScript_Release(ACTSCRIPT(This
));
754 static HRESULT WINAPI
JScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2
*iface
,
755 LPCOLESTR pstrCode
, LPCOLESTR pstrFormalParams
, LPCOLESTR pstrProcedureName
,
756 LPCOLESTR pstrItemName
, IUnknown
*punkContext
, LPCOLESTR pstrDelimiter
,
757 CTXARG_T dwSourceContextCookie
, ULONG ulStartingLineNumber
, DWORD dwFlags
, IDispatch
**ppdisp
)
759 JScript
*This
= ASPARSEPROC_THIS(iface
);
760 parser_ctx_t
*parser_ctx
;
764 TRACE("(%p)->(%s %s %s %s %p %s %s %u %x %p)\n", This
, debugstr_w(pstrCode
), debugstr_w(pstrFormalParams
),
765 debugstr_w(pstrProcedureName
), debugstr_w(pstrItemName
), punkContext
, debugstr_w(pstrDelimiter
),
766 wine_dbgstr_longlong(dwSourceContextCookie
), ulStartingLineNumber
, dwFlags
, ppdisp
);
768 if(This
->thread_id
!= GetCurrentThreadId() || This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
771 hres
= script_parse(This
->ctx
, pstrCode
, pstrDelimiter
, &parser_ctx
);
773 WARN("Parse failed %08x\n", hres
);
777 hres
= create_source_function(parser_ctx
, NULL
, parser_ctx
->source
, NULL
, NULL
, 0, &dispex
);
778 parser_release(parser_ctx
);
782 *ppdisp
= to_disp(dispex
);
786 #undef ASPARSEPROC_THIS
788 static const IActiveScriptParseProcedure2Vtbl JScriptParseProcedureVtbl
= {
789 JScriptParseProcedure_QueryInterface
,
790 JScriptParseProcedure_AddRef
,
791 JScriptParseProcedure_Release
,
792 JScriptParseProcedure_ParseProcedureText
,
795 #define ACTSCPPROP_THIS(iface) DEFINE_THIS(JScript, IActiveScriptProperty, iface)
797 static HRESULT WINAPI
JScriptProperty_QueryInterface(IActiveScriptProperty
*iface
, REFIID riid
, void **ppv
)
799 JScript
*This
= ACTSCPPROP_THIS(iface
);
800 return IActiveScript_QueryInterface(ACTSCRIPT(This
), riid
, ppv
);
803 static ULONG WINAPI
JScriptProperty_AddRef(IActiveScriptProperty
*iface
)
805 JScript
*This
= ACTSCPPROP_THIS(iface
);
806 return IActiveScript_AddRef(ACTSCRIPT(This
));
809 static ULONG WINAPI
JScriptProperty_Release(IActiveScriptProperty
*iface
)
811 JScript
*This
= ACTSCPPROP_THIS(iface
);
812 return IActiveScript_Release(ACTSCRIPT(This
));
815 static HRESULT WINAPI
JScriptProperty_GetProperty(IActiveScriptProperty
*iface
, DWORD dwProperty
,
816 VARIANT
*pvarIndex
, VARIANT
*pvarValue
)
818 JScript
*This
= ACTSCPPROP_THIS(iface
);
819 FIXME("(%p)->(%x %p %p)\n", This
, dwProperty
, pvarIndex
, pvarValue
);
823 static HRESULT WINAPI
JScriptProperty_SetProperty(IActiveScriptProperty
*iface
, DWORD dwProperty
,
824 VARIANT
*pvarIndex
, VARIANT
*pvarValue
)
826 JScript
*This
= ACTSCPPROP_THIS(iface
);
828 TRACE("(%p)->(%x %s %s)\n", This
, dwProperty
, debugstr_variant(pvarIndex
), debugstr_variant(pvarValue
));
831 FIXME("unsupported pvarIndex\n");
834 case SCRIPTPROP_INVOKEVERSIONING
:
835 if(V_VT(pvarValue
) != VT_I4
|| V_I4(pvarValue
) < 0 || V_I4(pvarValue
) > 15) {
836 WARN("invalid value %s\n", debugstr_variant(pvarValue
));
840 This
->version
= V_I4(pvarValue
);
843 FIXME("Unimplemented property %x\n", dwProperty
);
850 #undef ACTSCPPROP_THIS
852 static const IActiveScriptPropertyVtbl JScriptPropertyVtbl
= {
853 JScriptProperty_QueryInterface
,
854 JScriptProperty_AddRef
,
855 JScriptProperty_Release
,
856 JScriptProperty_GetProperty
,
857 JScriptProperty_SetProperty
860 #define OBJSAFETY_THIS(iface) DEFINE_THIS(JScript, IObjectSafety, iface)
862 static HRESULT WINAPI
JScriptSafety_QueryInterface(IObjectSafety
*iface
, REFIID riid
, void **ppv
)
864 JScript
*This
= OBJSAFETY_THIS(iface
);
865 return IActiveScript_QueryInterface(ACTSCRIPT(This
), riid
, ppv
);
868 static ULONG WINAPI
JScriptSafety_AddRef(IObjectSafety
*iface
)
870 JScript
*This
= OBJSAFETY_THIS(iface
);
871 return IActiveScript_AddRef(ACTSCRIPT(This
));
874 static ULONG WINAPI
JScriptSafety_Release(IObjectSafety
*iface
)
876 JScript
*This
= OBJSAFETY_THIS(iface
);
877 return IActiveScript_Release(ACTSCRIPT(This
));
880 #define SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER)
882 static HRESULT WINAPI
JScriptSafety_GetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
883 DWORD
*pdwSupportedOptions
, DWORD
*pdwEnabledOptions
)
885 JScript
*This
= OBJSAFETY_THIS(iface
);
887 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_guid(riid
), pdwSupportedOptions
, pdwEnabledOptions
);
889 if(!pdwSupportedOptions
|| !pdwEnabledOptions
)
892 *pdwSupportedOptions
= SUPPORTED_OPTIONS
;
893 *pdwEnabledOptions
= This
->safeopt
;
898 static HRESULT WINAPI
JScriptSafety_SetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
899 DWORD dwOptionSetMask
, DWORD dwEnabledOptions
)
901 JScript
*This
= OBJSAFETY_THIS(iface
);
903 TRACE("(%p)->(%s %x %x)\n", This
, debugstr_guid(riid
), dwOptionSetMask
, dwEnabledOptions
);
905 if(dwOptionSetMask
& ~SUPPORTED_OPTIONS
)
908 This
->safeopt
= dwEnabledOptions
& dwEnabledOptions
;
912 #undef OBJSAFETY_THIS
914 static const IObjectSafetyVtbl JScriptSafetyVtbl
= {
915 JScriptSafety_QueryInterface
,
916 JScriptSafety_AddRef
,
917 JScriptSafety_Release
,
918 JScriptSafety_GetInterfaceSafetyOptions
,
919 JScriptSafety_SetInterfaceSafetyOptions
922 HRESULT WINAPI
JScriptFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*pUnkOuter
,
923 REFIID riid
, void **ppv
)
928 TRACE("(%p %s %p)\n", pUnkOuter
, debugstr_guid(riid
), ppv
);
932 ret
= heap_alloc_zero(sizeof(*ret
));
934 return E_OUTOFMEMORY
;
936 ret
->lpIActiveScriptVtbl
= &JScriptVtbl
;
937 ret
->lpIActiveScriptParseVtbl
= &JScriptParseVtbl
;
938 ret
->lpIActiveScriptParseProcedure2Vtbl
= &JScriptParseProcedureVtbl
;
939 ret
->lpIActiveScriptPropertyVtbl
= &JScriptPropertyVtbl
;
940 ret
->lpIObjectSafetyVtbl
= &JScriptSafetyVtbl
;
942 ret
->safeopt
= INTERFACE_USES_DISPEX
;
944 hres
= IActiveScript_QueryInterface(ACTSCRIPT(ret
), riid
, ppv
);
945 IActiveScript_Release(ACTSCRIPT(ret
));