mlang/tests: Use a table for testing GetLcidFromRfc1766.
[wine.git] / dlls / jscript / jscript.c
blobb536014997ce8e994e16d2ee0f680f1f5c942f7c
1 /*
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
19 #include "jscript.h"
20 #include "engine.h"
21 #include "objsafe.h"
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
27 #ifdef _WIN64
29 #define CTXARG_T DWORDLONG
30 #define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
31 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_64Vtbl
33 #else
35 #define CTXARG_T DWORD
36 #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
37 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_32Vtbl
39 #endif
41 typedef struct {
42 const IActiveScriptVtbl *lpIActiveScriptVtbl;
43 const IActiveScriptParseVtbl *lpIActiveScriptParseVtbl;
44 const IActiveScriptParseProcedure2Vtbl *lpIActiveScriptParseProcedure2Vtbl;
45 const IActiveScriptPropertyVtbl *lpIActiveScriptPropertyVtbl;
46 const IObjectSafetyVtbl *lpIObjectSafetyVtbl;
48 LONG ref;
50 DWORD safeopt;
51 script_ctx_t *ctx;
52 LONG thread_id;
53 LCID lcid;
55 IActiveScriptSite *site;
57 parser_ctx_t *queue_head;
58 parser_ctx_t *queue_tail;
59 } JScript;
61 #define ACTSCRIPT(x) ((IActiveScript*) &(x)->lpIActiveScriptVtbl)
62 #define ASPARSE(x) (&(x)->lpIActiveScriptParseVtbl)
63 #define ASPARSEPROC(x) (&(x)->lpIActiveScriptParseProcedure2Vtbl)
64 #define ACTSCPPROP(x) (&(x)->lpIActiveScriptPropertyVtbl)
65 #define OBJSAFETY(x) (&(x)->lpIObjectSafetyVtbl)
67 void script_release(script_ctx_t *ctx)
69 if(--ctx->ref)
70 return;
72 jsheap_free(&ctx->tmp_heap);
73 heap_free(ctx);
76 static void change_state(JScript *This, SCRIPTSTATE state)
78 if(This->ctx->state == state)
79 return;
81 This->ctx->state = state;
82 IActiveScriptSite_OnStateChange(This->site, state);
85 static inline BOOL is_started(script_ctx_t *ctx)
87 return ctx->state == SCRIPTSTATE_STARTED
88 || ctx->state == SCRIPTSTATE_CONNECTED
89 || ctx->state == SCRIPTSTATE_DISCONNECTED;
92 static HRESULT exec_global_code(JScript *This, parser_ctx_t *parser_ctx)
94 exec_ctx_t *exec_ctx;
95 jsexcept_t jsexcept;
96 VARIANT var;
97 HRESULT hres;
99 hres = create_exec_ctx((IDispatch*)_IDispatchEx_(This->ctx->script_disp), This->ctx->script_disp, NULL, &exec_ctx);
100 if(FAILED(hres))
101 return hres;
103 IActiveScriptSite_OnEnterScript(This->site);
105 memset(&jsexcept, 0, sizeof(jsexcept));
106 hres = exec_source(exec_ctx, parser_ctx, parser_ctx->source, &jsexcept, &var);
107 VariantClear(&jsexcept.var);
108 exec_release(exec_ctx);
109 if(SUCCEEDED(hres))
110 VariantClear(&var);
112 IActiveScriptSite_OnLeaveScript(This->site);
114 return hres;
117 static void clear_script_queue(JScript *This)
119 parser_ctx_t *iter, *iter2;
121 if(!This->queue_head)
122 return;
124 iter = This->queue_head;
125 while(iter) {
126 iter2 = iter->next;
127 iter->next = NULL;
128 parser_release(iter);
129 iter = iter2;
132 This->queue_head = This->queue_tail = NULL;
135 static void exec_queued_code(JScript *This)
137 parser_ctx_t *iter;
139 for(iter = This->queue_head; iter; iter = iter->next)
140 exec_global_code(This, iter);
142 clear_script_queue(This);
145 static HRESULT set_ctx_site(JScript *This)
147 HRESULT hres;
149 This->ctx->lcid = This->lcid;
151 if(!This->ctx->script_disp) {
152 hres = create_dispex(This->ctx, NULL, NULL, &This->ctx->script_disp);
153 if(FAILED(hres))
154 return hres;
157 hres = init_global(This->ctx);
158 if(FAILED(hres))
159 return hres;
161 IActiveScriptSite_AddRef(This->site);
162 This->ctx->site = This->site;
164 change_state(This, SCRIPTSTATE_INITIALIZED);
165 return S_OK;
168 #define ACTSCRIPT_THIS(iface) DEFINE_THIS(JScript, IActiveScript, iface)
170 static HRESULT WINAPI JScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
172 JScript *This = ACTSCRIPT_THIS(iface);
174 *ppv = NULL;
176 if(IsEqualGUID(riid, &IID_IUnknown)) {
177 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
178 *ppv = ACTSCRIPT(This);
179 }else if(IsEqualGUID(riid, &IID_IActiveScript)) {
180 TRACE("(%p)->(IID_IActiveScript %p)\n", This, ppv);
181 *ppv = ACTSCRIPT(This);
182 }else if(IsEqualGUID(riid, &IID_IActiveScriptParse)) {
183 TRACE("(%p)->(IID_IActiveScriptParse %p)\n", This, ppv);
184 *ppv = ASPARSE(This);
185 }else if(IsEqualGUID(riid, &IID_IActiveScriptParseProcedure)) {
186 TRACE("(%p)->(IID_IActiveScriptParseProcedure %p)\n", This, ppv);
187 *ppv = ASPARSEPROC(This);
188 }else if(IsEqualGUID(riid, &IID_IActiveScriptParseProcedure2)) {
189 TRACE("(%p)->(IID_IActiveScriptParseProcedure2 %p)\n", This, ppv);
190 *ppv = ASPARSEPROC(This);
191 }else if(IsEqualGUID(riid, &IID_IActiveScriptProperty)) {
192 TRACE("(%p)->(IID_IActiveScriptProperty %p)\n", This, ppv);
193 *ppv = ACTSCPPROP(This);
194 }else if(IsEqualGUID(riid, &IID_IObjectSafety)) {
195 TRACE("(%p)->(IID_IObjectSafety %p)\n", This, ppv);
196 *ppv = OBJSAFETY(This);
199 if(*ppv) {
200 IUnknown_AddRef((IUnknown*)*ppv);
201 return S_OK;
204 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
205 return E_NOINTERFACE;
208 static ULONG WINAPI JScript_AddRef(IActiveScript *iface)
210 JScript *This = ACTSCRIPT_THIS(iface);
211 LONG ref = InterlockedIncrement(&This->ref);
213 TRACE("(%p) ref=%d\n", This, ref);
215 return ref;
218 static ULONG WINAPI JScript_Release(IActiveScript *iface)
220 JScript *This = ACTSCRIPT_THIS(iface);
221 LONG ref = InterlockedDecrement(&This->ref);
223 TRACE("(%p) ref=%d\n", iface, ref);
225 if(!ref) {
226 if(This->ctx && This->ctx->state != SCRIPTSTATE_CLOSED)
227 IActiveScript_Close(ACTSCRIPT(This));
228 if(This->ctx)
229 script_release(This->ctx);
230 heap_free(This);
231 unlock_module();
234 return ref;
237 static HRESULT WINAPI JScript_SetScriptSite(IActiveScript *iface,
238 IActiveScriptSite *pass)
240 JScript *This = ACTSCRIPT_THIS(iface);
241 LCID lcid;
242 HRESULT hres;
244 TRACE("(%p)->(%p)\n", This, pass);
246 if(!pass)
247 return E_POINTER;
249 if(This->site)
250 return E_UNEXPECTED;
252 if(InterlockedCompareExchange(&This->thread_id, GetCurrentThreadId(), 0))
253 return E_UNEXPECTED;
255 This->site = pass;
256 IActiveScriptSite_AddRef(This->site);
258 hres = IActiveScriptSite_GetLCID(This->site, &lcid);
259 if(hres == S_OK)
260 This->lcid = lcid;
262 return This->ctx ? set_ctx_site(This) : S_OK;
265 static HRESULT WINAPI JScript_GetScriptSite(IActiveScript *iface, REFIID riid,
266 void **ppvObject)
268 JScript *This = ACTSCRIPT_THIS(iface);
269 FIXME("(%p)->()\n", This);
270 return E_NOTIMPL;
273 static HRESULT WINAPI JScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
275 JScript *This = ACTSCRIPT_THIS(iface);
277 TRACE("(%p)->(%d)\n", This, ss);
279 if(!This->ctx || GetCurrentThreadId() != This->thread_id)
280 return E_UNEXPECTED;
282 switch(ss) {
283 case SCRIPTSTATE_STARTED:
284 case SCRIPTSTATE_CONNECTED: /* FIXME */
285 if(This->ctx->state == SCRIPTSTATE_CLOSED)
286 return E_UNEXPECTED;
288 exec_queued_code(This);
289 break;
290 default:
291 FIXME("unimplemented state %d\n", ss);
292 return E_NOTIMPL;
295 change_state(This, ss);
296 return S_OK;
299 static HRESULT WINAPI JScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
301 JScript *This = ACTSCRIPT_THIS(iface);
303 TRACE("(%p)->(%p)\n", This, pssState);
305 if(!pssState)
306 return E_POINTER;
308 if(!This->thread_id) {
309 *pssState = SCRIPTSTATE_UNINITIALIZED;
310 return S_OK;
313 if(This->thread_id != GetCurrentThreadId())
314 return E_UNEXPECTED;
316 *pssState = This->ctx ? This->ctx->state : SCRIPTSTATE_UNINITIALIZED;
317 return S_OK;
320 static HRESULT WINAPI JScript_Close(IActiveScript *iface)
322 JScript *This = ACTSCRIPT_THIS(iface);
324 TRACE("(%p)->()\n", This);
326 if(This->thread_id != GetCurrentThreadId())
327 return E_UNEXPECTED;
329 if(This->ctx) {
330 if(This->ctx->state == SCRIPTSTATE_CONNECTED)
331 change_state(This, SCRIPTSTATE_DISCONNECTED);
333 clear_script_queue(This);
335 if(This->ctx->state == SCRIPTSTATE_DISCONNECTED)
336 change_state(This, SCRIPTSTATE_INITIALIZED);
338 if(This->ctx->named_items) {
339 named_item_t *iter, *iter2;
341 iter = This->ctx->named_items;
342 while(iter) {
343 iter2 = iter->next;
345 if(iter->disp)
346 IDispatch_Release(iter->disp);
347 heap_free(iter->name);
348 heap_free(iter);
349 iter = iter2;
352 This->ctx->named_items = NULL;
355 if(This->ctx->site) {
356 IActiveScriptSite_Release(This->ctx->site);
357 This->ctx->site = NULL;
360 if (This->site)
361 change_state(This, SCRIPTSTATE_CLOSED);
363 if(This->ctx->script_disp) {
364 IDispatchEx_Release(_IDispatchEx_(This->ctx->script_disp));
365 This->ctx->script_disp = NULL;
368 if(This->ctx->global) {
369 IDispatchEx_Release(_IDispatchEx_(This->ctx->global));
370 This->ctx->global = NULL;
374 if(This->site) {
375 IActiveScriptSite_Release(This->site);
376 This->site = NULL;
379 return S_OK;
382 static HRESULT WINAPI JScript_AddNamedItem(IActiveScript *iface,
383 LPCOLESTR pstrName, DWORD dwFlags)
385 JScript *This = ACTSCRIPT_THIS(iface);
386 named_item_t *item;
387 IDispatch *disp = NULL;
388 HRESULT hres;
390 TRACE("(%p)->(%s %x)\n", This, debugstr_w(pstrName), dwFlags);
392 if(This->thread_id != GetCurrentThreadId() || !This->ctx || This->ctx->state == SCRIPTSTATE_CLOSED)
393 return E_UNEXPECTED;
395 if(dwFlags & SCRIPTITEM_GLOBALMEMBERS) {
396 IUnknown *unk;
398 hres = IActiveScriptSite_GetItemInfo(This->site, pstrName, SCRIPTINFO_IUNKNOWN, &unk, NULL);
399 if(FAILED(hres)) {
400 WARN("GetItemInfo failed: %08x\n", hres);
401 return hres;
404 hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
405 IUnknown_Release(unk);
406 if(FAILED(hres)) {
407 WARN("object does not implement IDispatch\n");
408 return hres;
412 item = heap_alloc(sizeof(*item));
413 if(!item) {
414 if(disp)
415 IDispatch_Release(disp);
416 return E_OUTOFMEMORY;
419 item->disp = disp;
420 item->flags = dwFlags;
421 item->name = heap_strdupW(pstrName);
422 if(!item->name) {
423 IDispatch_Release(disp);
424 heap_free(item);
425 return E_OUTOFMEMORY;
428 item->next = This->ctx->named_items;
429 This->ctx->named_items = item;
431 return S_OK;
434 static HRESULT WINAPI JScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
435 DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
437 JScript *This = ACTSCRIPT_THIS(iface);
438 FIXME("(%p)->()\n", This);
439 return E_NOTIMPL;
442 static HRESULT WINAPI JScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName,
443 IDispatch **ppdisp)
445 JScript *This = ACTSCRIPT_THIS(iface);
447 TRACE("(%p)->(%p)\n", This, ppdisp);
449 if(!ppdisp)
450 return E_POINTER;
452 if(This->thread_id != GetCurrentThreadId() || !This->ctx->script_disp) {
453 *ppdisp = NULL;
454 return E_UNEXPECTED;
457 *ppdisp = (IDispatch*)_IDispatchEx_(This->ctx->script_disp);
458 IDispatch_AddRef(*ppdisp);
459 return S_OK;
462 static HRESULT WINAPI JScript_GetCurrentScriptThreadID(IActiveScript *iface,
463 SCRIPTTHREADID *pstridThread)
465 JScript *This = ACTSCRIPT_THIS(iface);
466 FIXME("(%p)->()\n", This);
467 return E_NOTIMPL;
470 static HRESULT WINAPI JScript_GetScriptThreadID(IActiveScript *iface,
471 DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
473 JScript *This = ACTSCRIPT_THIS(iface);
474 FIXME("(%p)->()\n", This);
475 return E_NOTIMPL;
478 static HRESULT WINAPI JScript_GetScriptThreadState(IActiveScript *iface,
479 SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
481 JScript *This = ACTSCRIPT_THIS(iface);
482 FIXME("(%p)->()\n", This);
483 return E_NOTIMPL;
486 static HRESULT WINAPI JScript_InterruptScriptThread(IActiveScript *iface,
487 SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
489 JScript *This = ACTSCRIPT_THIS(iface);
490 FIXME("(%p)->()\n", This);
491 return E_NOTIMPL;
494 static HRESULT WINAPI JScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
496 JScript *This = ACTSCRIPT_THIS(iface);
497 FIXME("(%p)->()\n", This);
498 return E_NOTIMPL;
501 #undef ACTSCRIPT_THIS
503 static const IActiveScriptVtbl JScriptVtbl = {
504 JScript_QueryInterface,
505 JScript_AddRef,
506 JScript_Release,
507 JScript_SetScriptSite,
508 JScript_GetScriptSite,
509 JScript_SetScriptState,
510 JScript_GetScriptState,
511 JScript_Close,
512 JScript_AddNamedItem,
513 JScript_AddTypeLib,
514 JScript_GetScriptDispatch,
515 JScript_GetCurrentScriptThreadID,
516 JScript_GetScriptThreadID,
517 JScript_GetScriptThreadState,
518 JScript_InterruptScriptThread,
519 JScript_Clone
522 #define ASPARSE_THIS(iface) DEFINE_THIS(JScript, IActiveScriptParse, iface)
524 static HRESULT WINAPI JScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
526 JScript *This = ASPARSE_THIS(iface);
527 return IActiveScript_QueryInterface(ACTSCRIPT(This), riid, ppv);
530 static ULONG WINAPI JScriptParse_AddRef(IActiveScriptParse *iface)
532 JScript *This = ASPARSE_THIS(iface);
533 return IActiveScript_AddRef(ACTSCRIPT(This));
536 static ULONG WINAPI JScriptParse_Release(IActiveScriptParse *iface)
538 JScript *This = ASPARSE_THIS(iface);
539 return IActiveScript_Release(ACTSCRIPT(This));
542 static HRESULT WINAPI JScriptParse_InitNew(IActiveScriptParse *iface)
544 JScript *This = ASPARSE_THIS(iface);
545 script_ctx_t *ctx;
547 TRACE("(%p)\n", This);
549 if(This->ctx)
550 return E_UNEXPECTED;
552 ctx = heap_alloc_zero(sizeof(script_ctx_t));
553 if(!ctx)
554 return E_OUTOFMEMORY;
556 ctx->ref = 1;
557 ctx->state = SCRIPTSTATE_UNINITIALIZED;
558 jsheap_init(&ctx->tmp_heap);
560 ctx = InterlockedCompareExchangePointer((void**)&This->ctx, ctx, NULL);
561 if(ctx) {
562 script_release(ctx);
563 return E_UNEXPECTED;
566 return This->site ? set_ctx_site(This) : S_OK;
569 static HRESULT WINAPI JScriptParse_AddScriptlet(IActiveScriptParse *iface,
570 LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode, LPCOLESTR pstrItemName,
571 LPCOLESTR pstrSubItemName, LPCOLESTR pstrEventName, LPCOLESTR pstrDelimiter,
572 CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags,
573 BSTR *pbstrName, EXCEPINFO *pexcepinfo)
575 JScript *This = ASPARSE_THIS(iface);
576 FIXME("(%p)->(%s %s %s %s %s %s %s %u %x %p %p)\n", This, debugstr_w(pstrDefaultName),
577 debugstr_w(pstrCode), debugstr_w(pstrItemName), debugstr_w(pstrSubItemName),
578 debugstr_w(pstrEventName), debugstr_w(pstrDelimiter), wine_dbgstr_longlong(dwSourceContextCookie),
579 ulStartingLineNumber, dwFlags, pbstrName, pexcepinfo);
580 return E_NOTIMPL;
583 static HRESULT WINAPI JScriptParse_ParseScriptText(IActiveScriptParse *iface,
584 LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
585 LPCOLESTR pstrDelimiter, CTXARG_T dwSourceContextCookie, ULONG ulStartingLine,
586 DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
588 JScript *This = ASPARSE_THIS(iface);
589 parser_ctx_t *parser_ctx;
590 HRESULT hres;
592 TRACE("(%p)->(%s %s %p %s %s %u %x %p %p)\n", This, debugstr_w(pstrCode),
593 debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
594 wine_dbgstr_longlong(dwSourceContextCookie), ulStartingLine, dwFlags, pvarResult, pexcepinfo);
596 if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED)
597 return E_UNEXPECTED;
599 hres = script_parse(This->ctx, pstrCode, pstrDelimiter, &parser_ctx);
600 if(FAILED(hres))
601 return hres;
603 if(!is_started(This->ctx)) {
604 if(This->queue_tail)
605 This->queue_tail = This->queue_tail->next = parser_ctx;
606 else
607 This->queue_head = This->queue_tail = parser_ctx;
608 return S_OK;
611 hres = exec_global_code(This, parser_ctx);
612 parser_release(parser_ctx);
614 return hres;
617 #undef ASPARSE_THIS
619 static const IActiveScriptParseVtbl JScriptParseVtbl = {
620 JScriptParse_QueryInterface,
621 JScriptParse_AddRef,
622 JScriptParse_Release,
623 JScriptParse_InitNew,
624 JScriptParse_AddScriptlet,
625 JScriptParse_ParseScriptText
628 #define ASPARSEPROC_THIS(iface) DEFINE_THIS(JScript, IActiveScriptParseProcedure2, iface)
630 static HRESULT WINAPI JScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2 *iface, REFIID riid, void **ppv)
632 JScript *This = ASPARSEPROC_THIS(iface);
633 return IActiveScript_QueryInterface(ACTSCRIPT(This), riid, ppv);
636 static ULONG WINAPI JScriptParseProcedure_AddRef(IActiveScriptParseProcedure2 *iface)
638 JScript *This = ASPARSEPROC_THIS(iface);
639 return IActiveScript_AddRef(ACTSCRIPT(This));
642 static ULONG WINAPI JScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface)
644 JScript *This = ASPARSEPROC_THIS(iface);
645 return IActiveScript_Release(ACTSCRIPT(This));
648 static HRESULT WINAPI JScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2 *iface,
649 LPCOLESTR pstrCode, LPCOLESTR pstrFormalParams, LPCOLESTR pstrProcedureName,
650 LPCOLESTR pstrItemName, IUnknown *punkContext, LPCOLESTR pstrDelimiter,
651 CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags, IDispatch **ppdisp)
653 JScript *This = ASPARSEPROC_THIS(iface);
654 parser_ctx_t *parser_ctx;
655 DispatchEx *dispex;
656 HRESULT hres;
658 TRACE("(%p)->(%s %s %s %s %p %s %s %u %x %p)\n", This, debugstr_w(pstrCode), debugstr_w(pstrFormalParams),
659 debugstr_w(pstrProcedureName), debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
660 wine_dbgstr_longlong(dwSourceContextCookie), ulStartingLineNumber, dwFlags, ppdisp);
662 if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED)
663 return E_UNEXPECTED;
665 hres = script_parse(This->ctx, pstrCode, pstrDelimiter, &parser_ctx);
666 if(FAILED(hres)) {
667 WARN("Parse failed %08x\n", hres);
668 return hres;
671 hres = create_source_function(parser_ctx, NULL, parser_ctx->source, NULL, NULL, 0, &dispex);
672 parser_release(parser_ctx);
673 if(FAILED(hres))
674 return hres;
676 *ppdisp = (IDispatch*)_IDispatchEx_(dispex);
677 return S_OK;
680 #undef ASPARSEPROC_THIS
682 static const IActiveScriptParseProcedure2Vtbl JScriptParseProcedureVtbl = {
683 JScriptParseProcedure_QueryInterface,
684 JScriptParseProcedure_AddRef,
685 JScriptParseProcedure_Release,
686 JScriptParseProcedure_ParseProcedureText,
689 #define ACTSCPPROP_THIS(iface) DEFINE_THIS(JScript, IActiveScriptProperty, iface)
691 static HRESULT WINAPI JScriptProperty_QueryInterface(IActiveScriptProperty *iface, REFIID riid, void **ppv)
693 JScript *This = ACTSCPPROP_THIS(iface);
694 return IActiveScript_QueryInterface(ACTSCRIPT(This), riid, ppv);
697 static ULONG WINAPI JScriptProperty_AddRef(IActiveScriptProperty *iface)
699 JScript *This = ACTSCPPROP_THIS(iface);
700 return IActiveScript_AddRef(ACTSCRIPT(This));
703 static ULONG WINAPI JScriptProperty_Release(IActiveScriptProperty *iface)
705 JScript *This = ACTSCPPROP_THIS(iface);
706 return IActiveScript_Release(ACTSCRIPT(This));
709 static HRESULT WINAPI JScriptProperty_GetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
710 VARIANT *pvarIndex, VARIANT *pvarValue)
712 JScript *This = ACTSCPPROP_THIS(iface);
713 FIXME("(%p)->(%x %p %p)\n", This, dwProperty, pvarIndex, pvarValue);
714 return E_NOTIMPL;
717 static HRESULT WINAPI JScriptProperty_SetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
718 VARIANT *pvarIndex, VARIANT *pvarValue)
720 JScript *This = ACTSCPPROP_THIS(iface);
721 FIXME("(%p)->(%x %p %p)\n", This, dwProperty, pvarIndex, pvarValue);
722 return E_NOTIMPL;
725 #undef ACTSCPPROP_THIS
727 static const IActiveScriptPropertyVtbl JScriptPropertyVtbl = {
728 JScriptProperty_QueryInterface,
729 JScriptProperty_AddRef,
730 JScriptProperty_Release,
731 JScriptProperty_GetProperty,
732 JScriptProperty_SetProperty
735 #define OBJSAFETY_THIS(iface) DEFINE_THIS(JScript, IObjectSafety, iface)
737 static HRESULT WINAPI JScriptSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
739 JScript *This = OBJSAFETY_THIS(iface);
740 return IActiveScript_QueryInterface(ACTSCRIPT(This), riid, ppv);
743 static ULONG WINAPI JScriptSafety_AddRef(IObjectSafety *iface)
745 JScript *This = OBJSAFETY_THIS(iface);
746 return IActiveScript_AddRef(ACTSCRIPT(This));
749 static ULONG WINAPI JScriptSafety_Release(IObjectSafety *iface)
751 JScript *This = OBJSAFETY_THIS(iface);
752 return IActiveScript_Release(ACTSCRIPT(This));
755 #define SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER)
757 static HRESULT WINAPI JScriptSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
758 DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
760 JScript *This = OBJSAFETY_THIS(iface);
762 TRACE("(%p)->(%s %p %p)\n", This, debugstr_guid(riid), pdwSupportedOptions, pdwEnabledOptions);
764 if(!pdwSupportedOptions || !pdwEnabledOptions)
765 return E_POINTER;
767 *pdwSupportedOptions = SUPPORTED_OPTIONS;
768 *pdwEnabledOptions = This->safeopt;
770 return S_OK;
773 static HRESULT WINAPI JScriptSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
774 DWORD dwOptionSetMask, DWORD dwEnabledOptions)
776 JScript *This = OBJSAFETY_THIS(iface);
778 TRACE("(%p)->(%s %x %x)\n", This, debugstr_guid(riid), dwOptionSetMask, dwEnabledOptions);
780 if(dwOptionSetMask & ~SUPPORTED_OPTIONS)
781 return E_FAIL;
783 This->safeopt = dwEnabledOptions & dwEnabledOptions;
784 return S_OK;
787 #undef OBJSAFETY_THIS
789 static const IObjectSafetyVtbl JScriptSafetyVtbl = {
790 JScriptSafety_QueryInterface,
791 JScriptSafety_AddRef,
792 JScriptSafety_Release,
793 JScriptSafety_GetInterfaceSafetyOptions,
794 JScriptSafety_SetInterfaceSafetyOptions
797 HRESULT WINAPI JScriptFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
798 REFIID riid, void **ppv)
800 JScript *ret;
801 HRESULT hres;
803 TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppv);
805 lock_module();
807 ret = heap_alloc_zero(sizeof(*ret));
808 if(!ret)
809 return E_OUTOFMEMORY;
811 ret->lpIActiveScriptVtbl = &JScriptVtbl;
812 ret->lpIActiveScriptParseVtbl = &JScriptParseVtbl;
813 ret->lpIActiveScriptParseProcedure2Vtbl = &JScriptParseProcedureVtbl;
814 ret->lpIActiveScriptPropertyVtbl = &JScriptPropertyVtbl;
815 ret->lpIObjectSafetyVtbl = &JScriptSafetyVtbl;
816 ret->ref = 1;
817 ret->safeopt = INTERFACE_USES_DISPEX;
819 hres = IActiveScript_QueryInterface(ACTSCRIPT(ret), riid, ppv);
820 IActiveScript_Release(ACTSCRIPT(ret));
821 return hres;