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
);
28 const IActiveScriptVtbl
*lpIActiveScriptVtbl
;
29 const IActiveScriptParseVtbl
*lpIActiveScriptParseVtbl
;
30 const IActiveScriptParseProcedure2Vtbl
*lpIActiveScriptParseProcedure2Vtbl
;
31 const IActiveScriptPropertyVtbl
*lpIActiveScriptPropertyVtbl
;
32 const IObjectSafetyVtbl
*lpIObjectSafetyVtbl
;
41 IActiveScriptSite
*site
;
43 parser_ctx_t
*queue_head
;
44 parser_ctx_t
*queue_tail
;
47 #define ACTSCRIPT(x) ((IActiveScript*) &(x)->lpIActiveScriptVtbl)
48 #define ASPARSE(x) ((IActiveScriptParse*) &(x)->lpIActiveScriptParseVtbl)
49 #define ASPARSEPROC(x) ((IActiveScriptParseProcedure2*) &(x)->lpIActiveScriptParseProcedure2Vtbl)
50 #define ACTSCPPROP(x) ((IActiveScriptProperty*) &(x)->lpIActiveScriptPropertyVtbl)
51 #define OBJSAFETY(x) ((IObjectSafety*) &(x)->lpIObjectSafetyVtbl)
53 void script_release(script_ctx_t
*ctx
)
58 jsheap_free(&ctx
->tmp_heap
);
62 static void change_state(JScript
*This
, SCRIPTSTATE state
)
64 if(This
->ctx
->state
== state
)
67 This
->ctx
->state
= state
;
68 IActiveScriptSite_OnStateChange(This
->site
, state
);
71 static inline BOOL
is_started(script_ctx_t
*ctx
)
73 return ctx
->state
== SCRIPTSTATE_STARTED
74 || ctx
->state
== SCRIPTSTATE_CONNECTED
75 || ctx
->state
== SCRIPTSTATE_DISCONNECTED
;
78 static HRESULT
exec_global_code(JScript
*This
, parser_ctx_t
*parser_ctx
)
85 hres
= create_exec_ctx((IDispatch
*)_IDispatchEx_(This
->ctx
->script_disp
), This
->ctx
->script_disp
, NULL
, &exec_ctx
);
89 IActiveScriptSite_OnEnterScript(This
->site
);
91 memset(&jsexcept
, 0, sizeof(jsexcept
));
92 hres
= exec_source(exec_ctx
, parser_ctx
, parser_ctx
->source
, &jsexcept
, &var
);
93 VariantClear(&jsexcept
.var
);
94 exec_release(exec_ctx
);
98 IActiveScriptSite_OnLeaveScript(This
->site
);
103 static void clear_script_queue(JScript
*This
)
105 parser_ctx_t
*iter
, *iter2
;
107 if(!This
->queue_head
)
110 iter
= This
->queue_head
;
114 parser_release(iter
);
118 This
->queue_head
= This
->queue_tail
= NULL
;
121 static void exec_queued_code(JScript
*This
)
125 for(iter
= This
->queue_head
; iter
; iter
= iter
->next
)
126 exec_global_code(This
, iter
);
128 clear_script_queue(This
);
131 static HRESULT
set_ctx_site(JScript
*This
)
135 This
->ctx
->lcid
= This
->lcid
;
137 if(!This
->ctx
->script_disp
) {
138 hres
= create_dispex(This
->ctx
, NULL
, NULL
, &This
->ctx
->script_disp
);
143 hres
= init_global(This
->ctx
);
147 IActiveScriptSite_AddRef(This
->site
);
148 This
->ctx
->site
= This
->site
;
150 change_state(This
, SCRIPTSTATE_INITIALIZED
);
154 #define ACTSCRIPT_THIS(iface) DEFINE_THIS(JScript, IActiveScript, iface)
156 static HRESULT WINAPI
JScript_QueryInterface(IActiveScript
*iface
, REFIID riid
, void **ppv
)
158 JScript
*This
= ACTSCRIPT_THIS(iface
);
162 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
163 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
164 *ppv
= ACTSCRIPT(This
);
165 }else if(IsEqualGUID(riid
, &IID_IActiveScript
)) {
166 TRACE("(%p)->(IID_IActiveScript %p)\n", This
, ppv
);
167 *ppv
= ACTSCRIPT(This
);
168 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParse
)) {
169 TRACE("(%p)->(IID_IActiveScriptParse %p)\n", This
, ppv
);
170 *ppv
= ASPARSE(This
);
171 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParseProcedure
)) {
172 TRACE("(%p)->(IID_IActiveScriptParseProcedure %p)\n", This
, ppv
);
173 *ppv
= ASPARSEPROC(This
);
174 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParseProcedure2
)) {
175 TRACE("(%p)->(IID_IActiveScriptParseProcedure2 %p)\n", This
, ppv
);
176 *ppv
= ASPARSEPROC(This
);
177 }else if(IsEqualGUID(riid
, &IID_IActiveScriptProperty
)) {
178 TRACE("(%p)->(IID_IActiveScriptProperty %p)\n", This
, ppv
);
179 *ppv
= ACTSCPPROP(This
);
180 }else if(IsEqualGUID(riid
, &IID_IObjectSafety
)) {
181 TRACE("(%p)->(IID_IObjectSafety %p)\n", This
, ppv
);
182 *ppv
= OBJSAFETY(This
);
186 IUnknown_AddRef((IUnknown
*)*ppv
);
190 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
191 return E_NOINTERFACE
;
194 static ULONG WINAPI
JScript_AddRef(IActiveScript
*iface
)
196 JScript
*This
= ACTSCRIPT_THIS(iface
);
197 LONG ref
= InterlockedIncrement(&This
->ref
);
199 TRACE("(%p) ref=%d\n", This
, ref
);
204 static ULONG WINAPI
JScript_Release(IActiveScript
*iface
)
206 JScript
*This
= ACTSCRIPT_THIS(iface
);
207 LONG ref
= InterlockedDecrement(&This
->ref
);
209 TRACE("(%p) ref=%d\n", iface
, ref
);
212 if(This
->ctx
&& This
->ctx
->state
!= SCRIPTSTATE_CLOSED
)
213 IActiveScript_Close(ACTSCRIPT(This
));
215 script_release(This
->ctx
);
223 static HRESULT WINAPI
JScript_SetScriptSite(IActiveScript
*iface
,
224 IActiveScriptSite
*pass
)
226 JScript
*This
= ACTSCRIPT_THIS(iface
);
230 TRACE("(%p)->(%p)\n", This
, pass
);
238 if(InterlockedCompareExchange(&This
->thread_id
, GetCurrentThreadId(), 0))
242 IActiveScriptSite_AddRef(This
->site
);
244 hres
= IActiveScriptSite_GetLCID(This
->site
, &lcid
);
248 return This
->ctx
? set_ctx_site(This
) : S_OK
;
251 static HRESULT WINAPI
JScript_GetScriptSite(IActiveScript
*iface
, REFIID riid
,
254 JScript
*This
= ACTSCRIPT_THIS(iface
);
255 FIXME("(%p)->()\n", This
);
259 static HRESULT WINAPI
JScript_SetScriptState(IActiveScript
*iface
, SCRIPTSTATE ss
)
261 JScript
*This
= ACTSCRIPT_THIS(iface
);
263 TRACE("(%p)->(%d)\n", This
, ss
);
265 if(!This
->ctx
|| GetCurrentThreadId() != This
->thread_id
)
269 case SCRIPTSTATE_STARTED
:
270 case SCRIPTSTATE_CONNECTED
: /* FIXME */
271 if(This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
274 exec_queued_code(This
);
277 FIXME("unimplemented state %d\n", ss
);
281 change_state(This
, ss
);
285 static HRESULT WINAPI
JScript_GetScriptState(IActiveScript
*iface
, SCRIPTSTATE
*pssState
)
287 JScript
*This
= ACTSCRIPT_THIS(iface
);
289 TRACE("(%p)->(%p)\n", This
, pssState
);
294 if(!This
->thread_id
) {
295 *pssState
= SCRIPTSTATE_UNINITIALIZED
;
299 if(This
->thread_id
!= GetCurrentThreadId())
302 *pssState
= This
->ctx
? This
->ctx
->state
: SCRIPTSTATE_UNINITIALIZED
;
306 static HRESULT WINAPI
JScript_Close(IActiveScript
*iface
)
308 JScript
*This
= ACTSCRIPT_THIS(iface
);
310 TRACE("(%p)->()\n", This
);
312 if(This
->thread_id
!= GetCurrentThreadId())
316 if(This
->ctx
->state
== SCRIPTSTATE_CONNECTED
)
317 change_state(This
, SCRIPTSTATE_DISCONNECTED
);
319 clear_script_queue(This
);
321 if(This
->ctx
->state
== SCRIPTSTATE_DISCONNECTED
)
322 change_state(This
, SCRIPTSTATE_INITIALIZED
);
324 if(This
->ctx
->named_items
) {
325 named_item_t
*iter
, *iter2
;
327 iter
= This
->ctx
->named_items
;
332 IDispatch_Release(iter
->disp
);
333 heap_free(iter
->name
);
338 This
->ctx
->named_items
= NULL
;
341 if(This
->ctx
->site
) {
342 IActiveScriptSite_Release(This
->ctx
->site
);
343 This
->ctx
->site
= NULL
;
347 change_state(This
, SCRIPTSTATE_CLOSED
);
349 if(This
->ctx
->script_disp
) {
350 IDispatchEx_Release(_IDispatchEx_(This
->ctx
->script_disp
));
351 This
->ctx
->script_disp
= NULL
;
354 if(This
->ctx
->global
) {
355 IDispatchEx_Release(_IDispatchEx_(This
->ctx
->global
));
356 This
->ctx
->global
= NULL
;
361 IActiveScriptSite_Release(This
->site
);
368 static HRESULT WINAPI
JScript_AddNamedItem(IActiveScript
*iface
,
369 LPCOLESTR pstrName
, DWORD dwFlags
)
371 JScript
*This
= ACTSCRIPT_THIS(iface
);
373 IDispatch
*disp
= NULL
;
376 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(pstrName
), dwFlags
);
378 if(This
->thread_id
!= GetCurrentThreadId() || !This
->ctx
|| This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
381 if(dwFlags
& SCRIPTITEM_GLOBALMEMBERS
) {
384 hres
= IActiveScriptSite_GetItemInfo(This
->site
, pstrName
, SCRIPTINFO_IUNKNOWN
, &unk
, NULL
);
386 WARN("GetItemInfo failed: %08x\n", hres
);
390 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatch
, (void**)&disp
);
391 IUnknown_Release(unk
);
393 WARN("object does not implement IDispatch\n");
398 item
= heap_alloc(sizeof(*item
));
401 IDispatch_Release(disp
);
402 return E_OUTOFMEMORY
;
406 item
->flags
= dwFlags
;
407 item
->name
= heap_strdupW(pstrName
);
409 IDispatch_Release(disp
);
411 return E_OUTOFMEMORY
;
414 item
->next
= This
->ctx
->named_items
;
415 This
->ctx
->named_items
= item
;
420 static HRESULT WINAPI
JScript_AddTypeLib(IActiveScript
*iface
, REFGUID rguidTypeLib
,
421 DWORD dwMajor
, DWORD dwMinor
, DWORD dwFlags
)
423 JScript
*This
= ACTSCRIPT_THIS(iface
);
424 FIXME("(%p)->()\n", This
);
428 static HRESULT WINAPI
JScript_GetScriptDispatch(IActiveScript
*iface
, LPCOLESTR pstrItemName
,
431 JScript
*This
= ACTSCRIPT_THIS(iface
);
433 TRACE("(%p)->(%p)\n", This
, ppdisp
);
438 if(This
->thread_id
!= GetCurrentThreadId() || !This
->ctx
->script_disp
) {
443 *ppdisp
= (IDispatch
*)_IDispatchEx_(This
->ctx
->script_disp
);
444 IDispatch_AddRef(*ppdisp
);
448 static HRESULT WINAPI
JScript_GetCurrentScriptThreadID(IActiveScript
*iface
,
449 SCRIPTTHREADID
*pstridThread
)
451 JScript
*This
= ACTSCRIPT_THIS(iface
);
452 FIXME("(%p)->()\n", This
);
456 static HRESULT WINAPI
JScript_GetScriptThreadID(IActiveScript
*iface
,
457 DWORD dwWin32ThreadId
, SCRIPTTHREADID
*pstidThread
)
459 JScript
*This
= ACTSCRIPT_THIS(iface
);
460 FIXME("(%p)->()\n", This
);
464 static HRESULT WINAPI
JScript_GetScriptThreadState(IActiveScript
*iface
,
465 SCRIPTTHREADID stidThread
, SCRIPTTHREADSTATE
*pstsState
)
467 JScript
*This
= ACTSCRIPT_THIS(iface
);
468 FIXME("(%p)->()\n", This
);
472 static HRESULT WINAPI
JScript_InterruptScriptThread(IActiveScript
*iface
,
473 SCRIPTTHREADID stidThread
, const EXCEPINFO
*pexcepinfo
, DWORD dwFlags
)
475 JScript
*This
= ACTSCRIPT_THIS(iface
);
476 FIXME("(%p)->()\n", This
);
480 static HRESULT WINAPI
JScript_Clone(IActiveScript
*iface
, IActiveScript
**ppscript
)
482 JScript
*This
= ACTSCRIPT_THIS(iface
);
483 FIXME("(%p)->()\n", This
);
487 #undef ACTSCRIPT_THIS
489 static const IActiveScriptVtbl JScriptVtbl
= {
490 JScript_QueryInterface
,
493 JScript_SetScriptSite
,
494 JScript_GetScriptSite
,
495 JScript_SetScriptState
,
496 JScript_GetScriptState
,
498 JScript_AddNamedItem
,
500 JScript_GetScriptDispatch
,
501 JScript_GetCurrentScriptThreadID
,
502 JScript_GetScriptThreadID
,
503 JScript_GetScriptThreadState
,
504 JScript_InterruptScriptThread
,
508 #define ASPARSE_THIS(iface) DEFINE_THIS(JScript, IActiveScriptParse, iface)
510 static HRESULT WINAPI
JScriptParse_QueryInterface(IActiveScriptParse
*iface
, REFIID riid
, void **ppv
)
512 JScript
*This
= ASPARSE_THIS(iface
);
513 return IActiveScript_QueryInterface(ACTSCRIPT(This
), riid
, ppv
);
516 static ULONG WINAPI
JScriptParse_AddRef(IActiveScriptParse
*iface
)
518 JScript
*This
= ASPARSE_THIS(iface
);
519 return IActiveScript_AddRef(ACTSCRIPT(This
));
522 static ULONG WINAPI
JScriptParse_Release(IActiveScriptParse
*iface
)
524 JScript
*This
= ASPARSE_THIS(iface
);
525 return IActiveScript_Release(ACTSCRIPT(This
));
528 static HRESULT WINAPI
JScriptParse_InitNew(IActiveScriptParse
*iface
)
530 JScript
*This
= ASPARSE_THIS(iface
);
533 TRACE("(%p)\n", This
);
538 ctx
= heap_alloc_zero(sizeof(script_ctx_t
));
540 return E_OUTOFMEMORY
;
543 ctx
->state
= SCRIPTSTATE_UNINITIALIZED
;
544 jsheap_init(&ctx
->tmp_heap
);
546 ctx
= InterlockedCompareExchangePointer((void**)&This
->ctx
, ctx
, NULL
);
552 return This
->site
? set_ctx_site(This
) : S_OK
;
555 static HRESULT WINAPI
JScriptParse_AddScriptlet(IActiveScriptParse
*iface
,
556 LPCOLESTR pstrDefaultName
, LPCOLESTR pstrCode
, LPCOLESTR pstrItemName
,
557 LPCOLESTR pstrSubItemName
, LPCOLESTR pstrEventName
, LPCOLESTR pstrDelimiter
,
558 DWORD dwSourceContextCookie
, ULONG ulStartingLineNumber
, DWORD dwFlags
,
559 BSTR
*pbstrName
, EXCEPINFO
*pexcepinfo
)
561 JScript
*This
= ASPARSE_THIS(iface
);
562 FIXME("(%p)->(%s %s %s %s %s %s %x %u %x %p %p)\n", This
, debugstr_w(pstrDefaultName
),
563 debugstr_w(pstrCode
), debugstr_w(pstrItemName
), debugstr_w(pstrSubItemName
),
564 debugstr_w(pstrEventName
), debugstr_w(pstrDelimiter
), dwSourceContextCookie
,
565 ulStartingLineNumber
, dwFlags
, pbstrName
, pexcepinfo
);
569 static HRESULT WINAPI
JScriptParse_ParseScriptText(IActiveScriptParse
*iface
,
570 LPCOLESTR pstrCode
, LPCOLESTR pstrItemName
, IUnknown
*punkContext
,
571 LPCOLESTR pstrDelimiter
, DWORD dwSourceContextCookie
, ULONG ulStartingLine
,
572 DWORD dwFlags
, VARIANT
*pvarResult
, EXCEPINFO
*pexcepinfo
)
574 JScript
*This
= ASPARSE_THIS(iface
);
575 parser_ctx_t
*parser_ctx
;
578 TRACE("(%p)->(%s %s %p %s %x %u %x %p %p)\n", This
, debugstr_w(pstrCode
),
579 debugstr_w(pstrItemName
), punkContext
, debugstr_w(pstrDelimiter
),
580 dwSourceContextCookie
, ulStartingLine
, dwFlags
, pvarResult
, pexcepinfo
);
582 if(This
->thread_id
!= GetCurrentThreadId() || This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
585 hres
= script_parse(This
->ctx
, pstrCode
, &parser_ctx
);
589 if(!is_started(This
->ctx
)) {
591 This
->queue_tail
= This
->queue_tail
->next
= parser_ctx
;
593 This
->queue_head
= This
->queue_tail
= parser_ctx
;
597 hres
= exec_global_code(This
, parser_ctx
);
598 parser_release(parser_ctx
);
605 static const IActiveScriptParseVtbl JScriptParseVtbl
= {
606 JScriptParse_QueryInterface
,
608 JScriptParse_Release
,
609 JScriptParse_InitNew
,
610 JScriptParse_AddScriptlet
,
611 JScriptParse_ParseScriptText
614 #define ASPARSEPROC_THIS(iface) DEFINE_THIS(JScript, IActiveScriptParseProcedure2, iface)
616 static HRESULT WINAPI
JScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2
*iface
, REFIID riid
, void **ppv
)
618 JScript
*This
= ASPARSEPROC_THIS(iface
);
619 return IActiveScript_QueryInterface(ACTSCRIPT(This
), riid
, ppv
);
622 static ULONG WINAPI
JScriptParseProcedure_AddRef(IActiveScriptParseProcedure2
*iface
)
624 JScript
*This
= ASPARSEPROC_THIS(iface
);
625 return IActiveScript_AddRef(ACTSCRIPT(This
));
628 static ULONG WINAPI
JScriptParseProcedure_Release(IActiveScriptParseProcedure2
*iface
)
630 JScript
*This
= ASPARSEPROC_THIS(iface
);
631 return IActiveScript_Release(ACTSCRIPT(This
));
634 static HRESULT WINAPI
JScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2
*iface
,
635 LPCOLESTR pstrCode
, LPCOLESTR pstrFormalParams
, LPCOLESTR pstrProcedureName
,
636 LPCOLESTR pstrItemName
, IUnknown
*punkContext
, LPCOLESTR pstrDelimiter
,
637 DWORD dwSourceContextCookie
, ULONG ulStartingLineNumber
, DWORD dwFlags
, IDispatch
**ppdisp
)
639 JScript
*This
= ASPARSEPROC_THIS(iface
);
640 parser_ctx_t
*parser_ctx
;
644 TRACE("(%p)->(%s %s %s %s %p %s %x %u %x %p)\n", This
, debugstr_w(pstrCode
), debugstr_w(pstrFormalParams
),
645 debugstr_w(pstrProcedureName
), debugstr_w(pstrItemName
), punkContext
, debugstr_w(pstrDelimiter
),
646 dwSourceContextCookie
, ulStartingLineNumber
, dwFlags
, ppdisp
);
648 if(This
->thread_id
!= GetCurrentThreadId() || This
->ctx
->state
== SCRIPTSTATE_CLOSED
)
651 hres
= script_parse(This
->ctx
, pstrCode
, &parser_ctx
);
653 WARN("Parse failed %08x\n", hres
);
657 hres
= create_source_function(parser_ctx
, NULL
, parser_ctx
->source
, NULL
, NULL
, 0, &dispex
);
658 parser_release(parser_ctx
);
662 *ppdisp
= (IDispatch
*)_IDispatchEx_(dispex
);
666 #undef ASPARSEPROC_THIS
668 static const IActiveScriptParseProcedure2Vtbl JScriptParseProcedureVtbl
= {
669 JScriptParseProcedure_QueryInterface
,
670 JScriptParseProcedure_AddRef
,
671 JScriptParseProcedure_Release
,
672 JScriptParseProcedure_ParseProcedureText
,
675 #define ACTSCPPROP_THIS(iface) DEFINE_THIS(JScript, IActiveScriptProperty, iface)
677 static HRESULT WINAPI
JScriptProperty_QueryInterface(IActiveScriptProperty
*iface
, REFIID riid
, void **ppv
)
679 JScript
*This
= ACTSCPPROP_THIS(iface
);
680 return IActiveScript_QueryInterface(ACTSCRIPT(This
), riid
, ppv
);
683 static ULONG WINAPI
JScriptProperty_AddRef(IActiveScriptProperty
*iface
)
685 JScript
*This
= ACTSCPPROP_THIS(iface
);
686 return IActiveScript_AddRef(ACTSCRIPT(This
));
689 static ULONG WINAPI
JScriptProperty_Release(IActiveScriptProperty
*iface
)
691 JScript
*This
= ACTSCPPROP_THIS(iface
);
692 return IActiveScript_Release(ACTSCRIPT(This
));
695 static HRESULT WINAPI
JScriptProperty_GetProperty(IActiveScriptProperty
*iface
, DWORD dwProperty
,
696 VARIANT
*pvarIndex
, VARIANT
*pvarValue
)
698 JScript
*This
= ACTSCPPROP_THIS(iface
);
699 FIXME("(%p)->(%x %p %p)\n", This
, dwProperty
, pvarIndex
, pvarValue
);
703 static HRESULT WINAPI
JScriptProperty_SetProperty(IActiveScriptProperty
*iface
, DWORD dwProperty
,
704 VARIANT
*pvarIndex
, VARIANT
*pvarValue
)
706 JScript
*This
= ACTSCPPROP_THIS(iface
);
707 FIXME("(%p)->(%x %p %p)\n", This
, dwProperty
, pvarIndex
, pvarValue
);
711 #undef ACTSCPPROP_THIS
713 static const IActiveScriptPropertyVtbl JScriptPropertyVtbl
= {
714 JScriptProperty_QueryInterface
,
715 JScriptProperty_AddRef
,
716 JScriptProperty_Release
,
717 JScriptProperty_GetProperty
,
718 JScriptProperty_SetProperty
721 #define OBJSAFETY_THIS(iface) DEFINE_THIS(JScript, IObjectSafety, iface)
723 static HRESULT WINAPI
JScriptSafety_QueryInterface(IObjectSafety
*iface
, REFIID riid
, void **ppv
)
725 JScript
*This
= OBJSAFETY_THIS(iface
);
726 return IActiveScript_QueryInterface(ACTSCRIPT(This
), riid
, ppv
);
729 static ULONG WINAPI
JScriptSafety_AddRef(IObjectSafety
*iface
)
731 JScript
*This
= OBJSAFETY_THIS(iface
);
732 return IActiveScript_AddRef(ACTSCRIPT(This
));
735 static ULONG WINAPI
JScriptSafety_Release(IObjectSafety
*iface
)
737 JScript
*This
= OBJSAFETY_THIS(iface
);
738 return IActiveScript_Release(ACTSCRIPT(This
));
741 #define SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER)
743 static HRESULT WINAPI
JScriptSafety_GetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
744 DWORD
*pdwSupportedOptions
, DWORD
*pdwEnabledOptions
)
746 JScript
*This
= OBJSAFETY_THIS(iface
);
748 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_guid(riid
), pdwSupportedOptions
, pdwEnabledOptions
);
750 if(!pdwSupportedOptions
|| !pdwEnabledOptions
)
753 *pdwSupportedOptions
= SUPPORTED_OPTIONS
;
754 *pdwEnabledOptions
= This
->safeopt
;
759 static HRESULT WINAPI
JScriptSafety_SetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
760 DWORD dwOptionSetMask
, DWORD dwEnabledOptions
)
762 JScript
*This
= OBJSAFETY_THIS(iface
);
764 TRACE("(%p)->(%s %x %x)\n", This
, debugstr_guid(riid
), dwOptionSetMask
, dwEnabledOptions
);
766 if(dwOptionSetMask
& ~SUPPORTED_OPTIONS
)
769 This
->safeopt
= dwEnabledOptions
& dwEnabledOptions
;
773 #undef OBJSAFETY_THIS
775 static const IObjectSafetyVtbl JScriptSafetyVtbl
= {
776 JScriptSafety_QueryInterface
,
777 JScriptSafety_AddRef
,
778 JScriptSafety_Release
,
779 JScriptSafety_GetInterfaceSafetyOptions
,
780 JScriptSafety_SetInterfaceSafetyOptions
783 HRESULT WINAPI
JScriptFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*pUnkOuter
,
784 REFIID riid
, void **ppv
)
789 TRACE("(%p %s %p)\n", pUnkOuter
, debugstr_guid(riid
), ppv
);
793 ret
= heap_alloc_zero(sizeof(*ret
));
795 return E_OUTOFMEMORY
;
797 ret
->lpIActiveScriptVtbl
= &JScriptVtbl
;
798 ret
->lpIActiveScriptParseVtbl
= &JScriptParseVtbl
;
799 ret
->lpIActiveScriptParseProcedure2Vtbl
= &JScriptParseProcedureVtbl
;
800 ret
->lpIActiveScriptPropertyVtbl
= &JScriptPropertyVtbl
;
801 ret
->lpIObjectSafetyVtbl
= &JScriptSafetyVtbl
;
803 ret
->safeopt
= INTERFACE_USES_DISPEX
;
805 hres
= IActiveScript_QueryInterface(ACTSCRIPT(ret
), riid
, ppv
);
806 IActiveScript_Release(ACTSCRIPT(ret
));