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, &exec_ctx);
104 IActiveScriptSite_OnEnterScript(This->site);
106 memset(&jsexcept, 0, sizeof(jsexcept));
107 hres = exec_source(exec_ctx, parser_ctx, parser_ctx->source, EXECT_PROGRAM, &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);
382 FIXME("unimplemented state %d\n", ss);
386 change_state(This, ss);
390 static HRESULT WINAPI JScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
392 JScript *This = ACTSCRIPT_THIS(iface);
394 TRACE("(%p)->(%p)\n", This, pssState);
399 if(!This->thread_id) {
400 *pssState = SCRIPTSTATE_UNINITIALIZED;
404 if(This->thread_id != GetCurrentThreadId())
407 *pssState = This->ctx ? This->ctx->state : SCRIPTSTATE_UNINITIALIZED;
411 static HRESULT WINAPI JScript_Close(IActiveScript *iface)
413 JScript *This = ACTSCRIPT_THIS(iface);
415 TRACE("(%p)->()\n", This);
417 if(This->thread_id != GetCurrentThreadId())
421 if(This->ctx->state == SCRIPTSTATE_CONNECTED)
422 change_state(This, SCRIPTSTATE_DISCONNECTED);
424 clear_script_queue(This);
426 if(This->ctx->state == SCRIPTSTATE_DISCONNECTED)
427 change_state(This, SCRIPTSTATE_INITIALIZED);
429 if(This->ctx->host_global) {
430 IDispatch_Release(This->ctx->host_global);
431 This->ctx->host_global = NULL;
434 if(This->ctx->named_items) {
435 named_item_t *iter, *iter2;
437 iter = This->ctx->named_items;
442 IDispatch_Release(iter->disp);
443 heap_free(iter->name);
448 This->ctx->named_items = NULL;
451 if(This->ctx->secmgr) {
452 IInternetHostSecurityManager_Release(This->ctx->secmgr);
453 This->ctx->secmgr = NULL;
456 if(This->ctx->site) {
457 IActiveScriptSite_Release(This->ctx->site);
458 This->ctx->site = NULL;
462 change_state(This, SCRIPTSTATE_CLOSED);
464 if(This->ctx->global) {
465 jsdisp_release(This->ctx->global);
466 This->ctx->global = NULL;
471 IActiveScriptSite_Release(This->site);
478 static HRESULT WINAPI JScript_AddNamedItem(IActiveScript *iface,
479 LPCOLESTR pstrName, DWORD dwFlags)
481 JScript *This = ACTSCRIPT_THIS(iface);
483 IDispatch *disp = NULL;
486 TRACE("(%p)->(%s %x)\n", This, debugstr_w(pstrName), dwFlags);
488 if(This->thread_id != GetCurrentThreadId() || !This->ctx || This->ctx->state == SCRIPTSTATE_CLOSED)
491 if(dwFlags & SCRIPTITEM_GLOBALMEMBERS) {
494 hres = IActiveScriptSite_GetItemInfo(This->site, pstrName, SCRIPTINFO_IUNKNOWN, &unk, NULL);
496 WARN("GetItemInfo failed: %08x\n", hres);
500 hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
501 IUnknown_Release(unk);
503 WARN("object does not implement IDispatch\n");
507 if(This->ctx->host_global)
508 IDispatch_Release(This->ctx->host_global);
509 IDispatch_AddRef(disp);
510 This->ctx->host_global = disp;
513 item = heap_alloc(sizeof(*item));
516 IDispatch_Release(disp);
517 return E_OUTOFMEMORY;
521 item->flags = dwFlags;
522 item->name = heap_strdupW(pstrName);
524 IDispatch_Release(disp);
526 return E_OUTOFMEMORY;
529 item->next = This->ctx->named_items;
530 This->ctx->named_items = item;
535 static HRESULT WINAPI JScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
536 DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
538 JScript *This = ACTSCRIPT_THIS(iface);
539 FIXME("(%p)->()\n", This);
543 static HRESULT WINAPI JScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName,
546 JScript *This = ACTSCRIPT_THIS(iface);
548 TRACE("(%p)->(%p)\n", This, ppdisp);
553 if(This->thread_id != GetCurrentThreadId() || !This->ctx->global) {
558 *ppdisp = (IDispatch*)_IDispatchEx_(This->ctx->global);
559 IDispatch_AddRef(*ppdisp);
563 static HRESULT WINAPI JScript_GetCurrentScriptThreadID(IActiveScript *iface,
564 SCRIPTTHREADID *pstridThread)
566 JScript *This = ACTSCRIPT_THIS(iface);
567 FIXME("(%p)->()\n", This);
571 static HRESULT WINAPI JScript_GetScriptThreadID(IActiveScript *iface,
572 DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
574 JScript *This = ACTSCRIPT_THIS(iface);
575 FIXME("(%p)->()\n", This);
579 static HRESULT WINAPI JScript_GetScriptThreadState(IActiveScript *iface,
580 SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
582 JScript *This = ACTSCRIPT_THIS(iface);
583 FIXME("(%p)->()\n", This);
587 static HRESULT WINAPI JScript_InterruptScriptThread(IActiveScript *iface,
588 SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
590 JScript *This = ACTSCRIPT_THIS(iface);
591 FIXME("(%p)->()\n", This);
595 static HRESULT WINAPI JScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
597 JScript *This = ACTSCRIPT_THIS(iface);
598 FIXME("(%p)->()\n", This);
602 #undef ACTSCRIPT_THIS
604 static const IActiveScriptVtbl JScriptVtbl = {
605 JScript_QueryInterface,
608 JScript_SetScriptSite,
609 JScript_GetScriptSite,
610 JScript_SetScriptState,
611 JScript_GetScriptState,
613 JScript_AddNamedItem,
615 JScript_GetScriptDispatch,
616 JScript_GetCurrentScriptThreadID,
617 JScript_GetScriptThreadID,
618 JScript_GetScriptThreadState,
619 JScript_InterruptScriptThread,
623 #define ASPARSE_THIS(iface) DEFINE_THIS(JScript, IActiveScriptParse, iface)
625 static HRESULT WINAPI JScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
627 JScript *This = ASPARSE_THIS(iface);
628 return IActiveScript_QueryInterface(ACTSCRIPT(This), riid, ppv);
631 static ULONG WINAPI JScriptParse_AddRef(IActiveScriptParse *iface)
633 JScript *This = ASPARSE_THIS(iface);
634 return IActiveScript_AddRef(ACTSCRIPT(This));
637 static ULONG WINAPI JScriptParse_Release(IActiveScriptParse *iface)
639 JScript *This = ASPARSE_THIS(iface);
640 return IActiveScript_Release(ACTSCRIPT(This));
643 static HRESULT WINAPI JScriptParse_InitNew(IActiveScriptParse *iface)
645 JScript *This = ASPARSE_THIS(iface);
648 TRACE("(%p)\n", This);
653 ctx = heap_alloc_zero(sizeof(script_ctx_t));
655 return E_OUTOFMEMORY;
658 ctx->state = SCRIPTSTATE_UNINITIALIZED;
659 ctx->safeopt = This->safeopt;
660 ctx->version = This->version;
661 jsheap_init(&ctx->tmp_heap);
663 ctx = InterlockedCompareExchangePointer((void**)&This->ctx, ctx, NULL);
669 return This->site ? set_ctx_site(This) : S_OK;
672 static HRESULT WINAPI JScriptParse_AddScriptlet(IActiveScriptParse *iface,
673 LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode, LPCOLESTR pstrItemName,
674 LPCOLESTR pstrSubItemName, LPCOLESTR pstrEventName, LPCOLESTR pstrDelimiter,
675 CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags,
676 BSTR *pbstrName, EXCEPINFO *pexcepinfo)
678 JScript *This = ASPARSE_THIS(iface);
679 FIXME("(%p)->(%s %s %s %s %s %s %s %u %x %p %p)\n", This, debugstr_w(pstrDefaultName),
680 debugstr_w(pstrCode), debugstr_w(pstrItemName), debugstr_w(pstrSubItemName),
681 debugstr_w(pstrEventName), debugstr_w(pstrDelimiter), wine_dbgstr_longlong(dwSourceContextCookie),
682 ulStartingLineNumber, dwFlags, pbstrName, pexcepinfo);
686 static HRESULT WINAPI JScriptParse_ParseScriptText(IActiveScriptParse *iface,
687 LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
688 LPCOLESTR pstrDelimiter, CTXARG_T dwSourceContextCookie, ULONG ulStartingLine,
689 DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
691 JScript *This = ASPARSE_THIS(iface);
692 parser_ctx_t *parser_ctx;
695 TRACE("(%p)->(%s %s %p %s %s %u %x %p %p)\n", This, debugstr_w(pstrCode),
696 debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
697 wine_dbgstr_longlong(dwSourceContextCookie), ulStartingLine, dwFlags, pvarResult, pexcepinfo);
699 if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED)
702 hres = script_parse(This->ctx, pstrCode, pstrDelimiter, &parser_ctx);
706 if(!is_started(This->ctx)) {
708 This->queue_tail = This->queue_tail->next = parser_ctx;
710 This->queue_head = This->queue_tail = parser_ctx;
714 hres = exec_global_code(This, parser_ctx);
715 parser_release(parser_ctx);
722 static const IActiveScriptParseVtbl JScriptParseVtbl = {
723 JScriptParse_QueryInterface,
725 JScriptParse_Release,
726 JScriptParse_InitNew,
727 JScriptParse_AddScriptlet,
728 JScriptParse_ParseScriptText
731 #define ASPARSEPROC_THIS(iface) DEFINE_THIS(JScript, IActiveScriptParseProcedure2, iface)
733 static HRESULT WINAPI JScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2 *iface, REFIID riid, void **ppv)
735 JScript *This = ASPARSEPROC_THIS(iface);
736 return IActiveScript_QueryInterface(ACTSCRIPT(This), riid, ppv);
739 static ULONG WINAPI JScriptParseProcedure_AddRef(IActiveScriptParseProcedure2 *iface)
741 JScript *This = ASPARSEPROC_THIS(iface);
742 return IActiveScript_AddRef(ACTSCRIPT(This));
745 static ULONG WINAPI JScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface)
747 JScript *This = ASPARSEPROC_THIS(iface);
748 return IActiveScript_Release(ACTSCRIPT(This));
751 static HRESULT WINAPI JScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2 *iface,
752 LPCOLESTR pstrCode, LPCOLESTR pstrFormalParams, LPCOLESTR pstrProcedureName,
753 LPCOLESTR pstrItemName, IUnknown *punkContext, LPCOLESTR pstrDelimiter,
754 CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags, IDispatch **ppdisp)
756 JScript *This = ASPARSEPROC_THIS(iface);
757 parser_ctx_t *parser_ctx;
761 TRACE("(%p)->(%s %s %s %s %p %s %s %u %x %p)\n", This, debugstr_w(pstrCode), debugstr_w(pstrFormalParams),
762 debugstr_w(pstrProcedureName), debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
763 wine_dbgstr_longlong(dwSourceContextCookie), ulStartingLineNumber, dwFlags, ppdisp);
765 if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED)
768 hres = script_parse(This->ctx, pstrCode, pstrDelimiter, &parser_ctx);
770 WARN("Parse failed %08x\n", hres);
774 hres = create_source_function(parser_ctx, NULL, parser_ctx->source, NULL, NULL, 0, &dispex);
775 parser_release(parser_ctx);
779 *ppdisp = (IDispatch*)_IDispatchEx_(dispex);
783 #undef ASPARSEPROC_THIS
785 static const IActiveScriptParseProcedure2Vtbl JScriptParseProcedureVtbl = {
786 JScriptParseProcedure_QueryInterface,
787 JScriptParseProcedure_AddRef,
788 JScriptParseProcedure_Release,
789 JScriptParseProcedure_ParseProcedureText,
792 #define ACTSCPPROP_THIS(iface) DEFINE_THIS(JScript, IActiveScriptProperty, iface)
794 static HRESULT WINAPI JScriptProperty_QueryInterface(IActiveScriptProperty *iface, REFIID riid, void **ppv)
796 JScript *This = ACTSCPPROP_THIS(iface);
797 return IActiveScript_QueryInterface(ACTSCRIPT(This), riid, ppv);
800 static ULONG WINAPI JScriptProperty_AddRef(IActiveScriptProperty *iface)
802 JScript *This = ACTSCPPROP_THIS(iface);
803 return IActiveScript_AddRef(ACTSCRIPT(This));
806 static ULONG WINAPI JScriptProperty_Release(IActiveScriptProperty *iface)
808 JScript *This = ACTSCPPROP_THIS(iface);
809 return IActiveScript_Release(ACTSCRIPT(This));
812 static HRESULT WINAPI JScriptProperty_GetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
813 VARIANT *pvarIndex, VARIANT *pvarValue)
815 JScript *This = ACTSCPPROP_THIS(iface);
816 FIXME("(%p)->(%x %p %p)\n", This, dwProperty, pvarIndex, pvarValue);
820 static HRESULT WINAPI JScriptProperty_SetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
821 VARIANT *pvarIndex, VARIANT *pvarValue)
823 JScript *This = ACTSCPPROP_THIS(iface);
825 TRACE("(%p)->(%x %s %s)\n", This, dwProperty, debugstr_variant(pvarIndex), debugstr_variant(pvarValue));
828 FIXME("unsupported pvarIndex\n");
831 case SCRIPTPROP_INVOKEVERSIONING:
832 if(V_VT(pvarValue) != VT_I4 || V_I4(pvarValue) < 0 || V_I4(pvarValue) > 15) {
833 WARN("invalid value %s\n", debugstr_variant(pvarValue));
837 This->version = V_I4(pvarValue);
840 FIXME("Unimplemented property %x\n", dwProperty);
847 #undef ACTSCPPROP_THIS
849 static const IActiveScriptPropertyVtbl JScriptPropertyVtbl = {
850 JScriptProperty_QueryInterface,
851 JScriptProperty_AddRef,
852 JScriptProperty_Release,
853 JScriptProperty_GetProperty,
854 JScriptProperty_SetProperty
857 #define OBJSAFETY_THIS(iface) DEFINE_THIS(JScript, IObjectSafety, iface)
859 static HRESULT WINAPI JScriptSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
861 JScript *This = OBJSAFETY_THIS(iface);
862 return IActiveScript_QueryInterface(ACTSCRIPT(This), riid, ppv);
865 static ULONG WINAPI JScriptSafety_AddRef(IObjectSafety *iface)
867 JScript *This = OBJSAFETY_THIS(iface);
868 return IActiveScript_AddRef(ACTSCRIPT(This));
871 static ULONG WINAPI JScriptSafety_Release(IObjectSafety *iface)
873 JScript *This = OBJSAFETY_THIS(iface);
874 return IActiveScript_Release(ACTSCRIPT(This));
877 #define SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER)
879 static HRESULT WINAPI JScriptSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
880 DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
882 JScript *This = OBJSAFETY_THIS(iface);
884 TRACE("(%p)->(%s %p %p)\n", This, debugstr_guid(riid), pdwSupportedOptions, pdwEnabledOptions);
886 if(!pdwSupportedOptions || !pdwEnabledOptions)
889 *pdwSupportedOptions = SUPPORTED_OPTIONS;
890 *pdwEnabledOptions = This->safeopt;
895 static HRESULT WINAPI JScriptSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
896 DWORD dwOptionSetMask, DWORD dwEnabledOptions)
898 JScript *This = OBJSAFETY_THIS(iface);
900 TRACE("(%p)->(%s %x %x)\n", This, debugstr_guid(riid), dwOptionSetMask, dwEnabledOptions);
902 if(dwOptionSetMask & ~SUPPORTED_OPTIONS)
905 This->safeopt = dwEnabledOptions & dwEnabledOptions;
909 #undef OBJSAFETY_THIS
911 static const IObjectSafetyVtbl JScriptSafetyVtbl = {
912 JScriptSafety_QueryInterface,
913 JScriptSafety_AddRef,
914 JScriptSafety_Release,
915 JScriptSafety_GetInterfaceSafetyOptions,
916 JScriptSafety_SetInterfaceSafetyOptions
919 HRESULT WINAPI JScriptFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
920 REFIID riid, void **ppv)
925 TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppv);
929 ret = heap_alloc_zero(sizeof(*ret));
931 return E_OUTOFMEMORY;
933 ret->lpIActiveScriptVtbl = &JScriptVtbl;
934 ret->lpIActiveScriptParseVtbl = &JScriptParseVtbl;
935 ret->lpIActiveScriptParseProcedure2Vtbl = &JScriptParseProcedureVtbl;
936 ret->lpIActiveScriptPropertyVtbl = &JScriptPropertyVtbl;
937 ret->lpIObjectSafetyVtbl = &JScriptSafetyVtbl;
939 ret->safeopt = INTERFACE_USES_DISPEX;
941 hres = IActiveScript_QueryInterface(ACTSCRIPT(ret), riid, ppv);
942 IActiveScript_Release(ACTSCRIPT(ret));