jscript: Added Array constructor implementation.
[wine.git] / dlls / jscript / jscript.c
blob899f59d4aaaa4c670971d14c0cc6196e82e352f2
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 typedef struct {
28 const IActiveScriptVtbl *lpIActiveScriptVtbl;
29 const IActiveScriptParseVtbl *lpIActiveScriptParseVtbl;
30 const IActiveScriptParseProcedure2Vtbl *lpIActiveScriptParseProcedure2Vtbl;
31 const IActiveScriptPropertyVtbl *lpIActiveScriptPropertyVtbl;
32 const IObjectSafetyVtbl *lpIObjectSafetyVtbl;
34 LONG ref;
36 DWORD safeopt;
37 script_ctx_t *ctx;
38 LONG thread_id;
40 IActiveScriptSite *site;
42 parser_ctx_t *queue_head;
43 parser_ctx_t *queue_tail;
44 } JScript;
46 #define ACTSCRIPT(x) ((IActiveScript*) &(x)->lpIActiveScriptVtbl)
47 #define ASPARSE(x) ((IActiveScriptParse*) &(x)->lpIActiveScriptParseVtbl)
48 #define ASPARSEPROC(x) ((IActiveScriptParseProcedure2*) &(x)->lpIActiveScriptParseProcedure2Vtbl)
49 #define ACTSCPPROP(x) ((IActiveScriptProperty*) &(x)->lpIActiveScriptPropertyVtbl)
50 #define OBJSAFETY(x) ((IObjectSafety*) &(x)->lpIObjectSafetyVtbl)
52 void script_release(script_ctx_t *ctx)
54 if(--ctx->ref)
55 return;
57 heap_free(ctx);
60 static void change_state(JScript *This, SCRIPTSTATE state)
62 if(This->ctx->state == state)
63 return;
65 This->ctx->state = state;
66 IActiveScriptSite_OnStateChange(This->site, state);
69 static inline BOOL is_started(script_ctx_t *ctx)
71 return ctx->state == SCRIPTSTATE_STARTED
72 || ctx->state == SCRIPTSTATE_CONNECTED
73 || ctx->state == SCRIPTSTATE_DISCONNECTED;
76 static HRESULT exec_global_code(JScript *This, parser_ctx_t *parser_ctx)
78 exec_ctx_t *exec_ctx;
79 jsexcept_t jsexcept;
80 VARIANT var;
81 HRESULT hres;
83 hres = create_exec_ctx((IDispatch*)_IDispatchEx_(This->ctx->script_disp), This->ctx->script_disp, NULL, &exec_ctx);
84 if(FAILED(hres))
85 return hres;
87 IActiveScriptSite_OnEnterScript(This->site);
89 memset(&jsexcept, 0, sizeof(jsexcept));
90 hres = exec_source(exec_ctx, parser_ctx, parser_ctx->source, &jsexcept, &var);
91 VariantClear(&jsexcept.var);
92 exec_release(exec_ctx);
93 if(SUCCEEDED(hres))
94 VariantClear(&var);
96 IActiveScriptSite_OnLeaveScript(This->site);
98 return hres;
101 static void clear_script_queue(JScript *This)
103 parser_ctx_t *iter, *iter2;
105 if(!This->queue_head)
106 return;
108 iter = This->queue_head;
109 while(iter) {
110 iter2 = iter->next;
111 iter->next = NULL;
112 parser_release(iter);
113 iter = iter2;
116 This->queue_head = This->queue_tail = NULL;
119 static void exec_queued_code(JScript *This)
121 parser_ctx_t *iter;
123 for(iter = This->queue_head; iter; iter = iter->next)
124 exec_global_code(This, iter);
126 clear_script_queue(This);
129 #define ACTSCRIPT_THIS(iface) DEFINE_THIS(JScript, IActiveScript, iface)
131 static HRESULT WINAPI JScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
133 JScript *This = ACTSCRIPT_THIS(iface);
135 *ppv = NULL;
137 if(IsEqualGUID(riid, &IID_IUnknown)) {
138 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
139 *ppv = ACTSCRIPT(This);
140 }else if(IsEqualGUID(riid, &IID_IActiveScript)) {
141 TRACE("(%p)->(IID_IActiveScript %p)\n", This, ppv);
142 *ppv = ACTSCRIPT(This);
143 }else if(IsEqualGUID(riid, &IID_IActiveScriptParse)) {
144 TRACE("(%p)->(IID_IActiveScriptParse %p)\n", This, ppv);
145 *ppv = ASPARSE(This);
146 }else if(IsEqualGUID(riid, &IID_IActiveScriptParseProcedure)) {
147 TRACE("(%p)->(IID_IActiveScriptParseProcedure %p)\n", This, ppv);
148 *ppv = ASPARSEPROC(This);
149 }else if(IsEqualGUID(riid, &IID_IActiveScriptParseProcedure2)) {
150 TRACE("(%p)->(IID_IActiveScriptParseProcedure2 %p)\n", This, ppv);
151 *ppv = ASPARSEPROC(This);
152 }else if(IsEqualGUID(riid, &IID_IActiveScriptProperty)) {
153 TRACE("(%p)->(IID_IActiveScriptProperty %p)\n", This, ppv);
154 *ppv = ACTSCPPROP(This);
155 }else if(IsEqualGUID(riid, &IID_IObjectSafety)) {
156 TRACE("(%p)->(IID_IObjectSafety %p)\n", This, ppv);
157 *ppv = OBJSAFETY(This);
160 if(*ppv) {
161 IUnknown_AddRef((IUnknown*)*ppv);
162 return S_OK;
165 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
166 return E_NOINTERFACE;
169 static ULONG WINAPI JScript_AddRef(IActiveScript *iface)
171 JScript *This = ACTSCRIPT_THIS(iface);
172 LONG ref = InterlockedIncrement(&This->ref);
174 TRACE("(%p) ref=%d\n", This, ref);
176 return ref;
179 static ULONG WINAPI JScript_Release(IActiveScript *iface)
181 JScript *This = ACTSCRIPT_THIS(iface);
182 LONG ref = InterlockedDecrement(&This->ref);
184 TRACE("(%p) ref=%d\n", iface, ref);
186 if(!ref) {
187 if(This->ctx && This->ctx->state != SCRIPTSTATE_CLOSED)
188 IActiveScript_Close(ACTSCRIPT(This));
189 if(This->ctx)
190 script_release(This->ctx);
191 heap_free(This);
192 unlock_module();
195 return ref;
198 static HRESULT WINAPI JScript_SetScriptSite(IActiveScript *iface,
199 IActiveScriptSite *pass)
201 JScript *This = ACTSCRIPT_THIS(iface);
202 LCID lcid;
203 HRESULT hres;
205 TRACE("(%p)->(%p)\n", This, pass);
207 if(!pass)
208 return E_POINTER;
210 if(This->site)
211 return E_UNEXPECTED;
213 if(!This->ctx) {
214 hres = IActiveScriptParse_InitNew(ASPARSE(This));
215 if(FAILED(hres))
216 return hres;
219 if(!This->ctx->script_disp) {
220 hres = create_dispex(This->ctx, NULL, NULL, &This->ctx->script_disp);
221 if(FAILED(hres))
222 return hres;
225 hres = init_global(This->ctx);
226 if(FAILED(hres))
227 return hres;
229 if(InterlockedCompareExchange(&This->thread_id, GetCurrentThreadId(), 0))
230 return E_UNEXPECTED;
232 This->site = pass;
233 IActiveScriptSite_AddRef(This->site);
235 hres = IActiveScriptSite_GetLCID(This->site, &lcid);
236 if(hres == S_OK)
237 This->ctx->lcid = lcid;
239 change_state(This, SCRIPTSTATE_INITIALIZED);
240 return S_OK;
243 static HRESULT WINAPI JScript_GetScriptSite(IActiveScript *iface, REFIID riid,
244 void **ppvObject)
246 JScript *This = ACTSCRIPT_THIS(iface);
247 FIXME("(%p)->()\n", This);
248 return E_NOTIMPL;
251 static HRESULT WINAPI JScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
253 JScript *This = ACTSCRIPT_THIS(iface);
255 TRACE("(%p)->(%d)\n", This, ss);
257 if(!This->ctx || GetCurrentThreadId() != This->thread_id)
258 return E_UNEXPECTED;
260 switch(ss) {
261 case SCRIPTSTATE_STARTED:
262 if(This->ctx->state == SCRIPTSTATE_CLOSED)
263 return E_UNEXPECTED;
265 exec_queued_code(This);
266 break;
267 default:
268 FIXME("unimplemented state %d\n", ss);
269 return E_NOTIMPL;
272 change_state(This, ss);
273 return S_OK;
276 static HRESULT WINAPI JScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
278 JScript *This = ACTSCRIPT_THIS(iface);
280 TRACE("(%p)->(%p)\n", This, pssState);
282 if(!pssState)
283 return E_POINTER;
285 if(!This->thread_id) {
286 *pssState = SCRIPTSTATE_UNINITIALIZED;
287 return S_OK;
290 if(This->thread_id != GetCurrentThreadId())
291 return E_UNEXPECTED;
293 *pssState = This->ctx ? This->ctx->state : SCRIPTSTATE_UNINITIALIZED;
294 return S_OK;
297 static HRESULT WINAPI JScript_Close(IActiveScript *iface)
299 JScript *This = ACTSCRIPT_THIS(iface);
301 TRACE("(%p)->()\n", This);
303 if(This->thread_id != GetCurrentThreadId())
304 return E_UNEXPECTED;
306 clear_script_queue(This);
308 if(This->ctx->named_items) {
309 named_item_t *iter, *iter2;
311 iter = This->ctx->named_items;
312 while(iter) {
313 iter2 = iter->next;
315 IDispatch_Release(iter->disp);
316 heap_free(iter);
317 iter = iter2;
320 This->ctx->named_items = NULL;
323 if(This->ctx) {
324 change_state(This, SCRIPTSTATE_CLOSED);
326 if(This->ctx->script_disp) {
327 IDispatchEx_Release(_IDispatchEx_(This->ctx->script_disp));
328 This->ctx->script_disp = NULL;
331 if(This->ctx->global) {
332 IDispatchEx_Release(_IDispatchEx_(This->ctx->global));
333 This->ctx->global = NULL;
337 if(This->site) {
338 IActiveScriptSite_Release(This->site);
339 This->site = NULL;
342 return S_OK;
345 static HRESULT WINAPI JScript_AddNamedItem(IActiveScript *iface,
346 LPCOLESTR pstrName, DWORD dwFlags)
348 JScript *This = ACTSCRIPT_THIS(iface);
349 named_item_t *item;
350 IDispatch *disp;
351 IUnknown *unk;
352 HRESULT hres;
354 TRACE("(%p)->(%s %x)\n", This, debugstr_w(pstrName), dwFlags);
356 if(This->thread_id != GetCurrentThreadId() || !This->ctx || This->ctx->state == SCRIPTSTATE_CLOSED)
357 return E_UNEXPECTED;
359 hres = IActiveScriptSite_GetItemInfo(This->site, pstrName, SCRIPTINFO_IUNKNOWN, &unk, NULL);
360 if(FAILED(hres)) {
361 WARN("GetItemInfo failed: %08x\n", hres);
362 return hres;
365 hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
366 IUnknown_Release(unk);
367 if(FAILED(hres)) {
368 WARN("object does not implement IDispatch\n");
369 return hres;
372 item = heap_alloc(sizeof(*item));
373 if(!item) {
374 IDispatch_Release(disp);
375 return E_OUTOFMEMORY;
378 item->disp = disp;
379 item->flags = dwFlags;
380 item->next = This->ctx->named_items;
381 This->ctx->named_items = item;
383 return S_OK;
386 static HRESULT WINAPI JScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
387 DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
389 JScript *This = ACTSCRIPT_THIS(iface);
390 FIXME("(%p)->()\n", This);
391 return E_NOTIMPL;
394 static HRESULT WINAPI JScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName,
395 IDispatch **ppdisp)
397 JScript *This = ACTSCRIPT_THIS(iface);
399 TRACE("(%p)->(%p)\n", This, ppdisp);
401 if(!ppdisp)
402 return E_POINTER;
404 if(This->thread_id != GetCurrentThreadId() || !This->ctx->script_disp) {
405 *ppdisp = NULL;
406 return E_UNEXPECTED;
409 *ppdisp = (IDispatch*)_IDispatchEx_(This->ctx->script_disp);
410 IDispatch_AddRef(*ppdisp);
411 return S_OK;
414 static HRESULT WINAPI JScript_GetCurrentScriptThreadID(IActiveScript *iface,
415 SCRIPTTHREADID *pstridThread)
417 JScript *This = ACTSCRIPT_THIS(iface);
418 FIXME("(%p)->()\n", This);
419 return E_NOTIMPL;
422 static HRESULT WINAPI JScript_GetScriptThreadID(IActiveScript *iface,
423 DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
425 JScript *This = ACTSCRIPT_THIS(iface);
426 FIXME("(%p)->()\n", This);
427 return E_NOTIMPL;
430 static HRESULT WINAPI JScript_GetScriptThreadState(IActiveScript *iface,
431 SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
433 JScript *This = ACTSCRIPT_THIS(iface);
434 FIXME("(%p)->()\n", This);
435 return E_NOTIMPL;
438 static HRESULT WINAPI JScript_InterruptScriptThread(IActiveScript *iface,
439 SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
441 JScript *This = ACTSCRIPT_THIS(iface);
442 FIXME("(%p)->()\n", This);
443 return E_NOTIMPL;
446 static HRESULT WINAPI JScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
448 JScript *This = ACTSCRIPT_THIS(iface);
449 FIXME("(%p)->()\n", This);
450 return E_NOTIMPL;
453 #undef ACTSCRIPT_THIS
455 static const IActiveScriptVtbl JScriptVtbl = {
456 JScript_QueryInterface,
457 JScript_AddRef,
458 JScript_Release,
459 JScript_SetScriptSite,
460 JScript_GetScriptSite,
461 JScript_SetScriptState,
462 JScript_GetScriptState,
463 JScript_Close,
464 JScript_AddNamedItem,
465 JScript_AddTypeLib,
466 JScript_GetScriptDispatch,
467 JScript_GetCurrentScriptThreadID,
468 JScript_GetScriptThreadID,
469 JScript_GetScriptThreadState,
470 JScript_InterruptScriptThread,
471 JScript_Clone
474 #define ASPARSE_THIS(iface) DEFINE_THIS(JScript, IActiveScriptParse, iface)
476 static HRESULT WINAPI JScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
478 JScript *This = ASPARSE_THIS(iface);
479 return IActiveScript_QueryInterface(ACTSCRIPT(This), riid, ppv);
482 static ULONG WINAPI JScriptParse_AddRef(IActiveScriptParse *iface)
484 JScript *This = ASPARSE_THIS(iface);
485 return IActiveScript_AddRef(ACTSCRIPT(This));
488 static ULONG WINAPI JScriptParse_Release(IActiveScriptParse *iface)
490 JScript *This = ASPARSE_THIS(iface);
491 return IActiveScript_Release(ACTSCRIPT(This));
494 static HRESULT WINAPI JScriptParse_InitNew(IActiveScriptParse *iface)
496 JScript *This = ASPARSE_THIS(iface);
497 script_ctx_t *ctx;
499 TRACE("(%p)\n", This);
501 if(This->ctx)
502 return E_UNEXPECTED;
504 ctx = heap_alloc_zero(sizeof(script_ctx_t));
505 if(!ctx)
506 return E_OUTOFMEMORY;
508 ctx->ref = 1;
509 ctx->state = SCRIPTSTATE_UNINITIALIZED;
511 ctx = InterlockedCompareExchangePointer((void**)&This->ctx, ctx, NULL);
512 if(ctx) {
513 script_release(ctx);
514 return E_UNEXPECTED;
517 return S_OK;
520 static HRESULT WINAPI JScriptParse_AddScriptlet(IActiveScriptParse *iface,
521 LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode, LPCOLESTR pstrItemName,
522 LPCOLESTR pstrSubItemName, LPCOLESTR pstrEventName, LPCOLESTR pstrDelimiter,
523 DWORD dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags,
524 BSTR *pbstrName, EXCEPINFO *pexcepinfo)
526 JScript *This = ASPARSE_THIS(iface);
527 FIXME("(%p)->(%s %s %s %s %s %s %x %u %x %p %p)\n", This, debugstr_w(pstrDefaultName),
528 debugstr_w(pstrCode), debugstr_w(pstrItemName), debugstr_w(pstrSubItemName),
529 debugstr_w(pstrEventName), debugstr_w(pstrDelimiter), dwSourceContextCookie,
530 ulStartingLineNumber, dwFlags, pbstrName, pexcepinfo);
531 return E_NOTIMPL;
534 static HRESULT WINAPI JScriptParse_ParseScriptText(IActiveScriptParse *iface,
535 LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
536 LPCOLESTR pstrDelimiter, DWORD dwSourceContextCookie, ULONG ulStartingLine,
537 DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
539 JScript *This = ASPARSE_THIS(iface);
540 parser_ctx_t *parser_ctx;
541 HRESULT hres;
543 TRACE("(%p)->(%s %s %p %s %x %u %x %p %p)\n", This, debugstr_w(pstrCode),
544 debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
545 dwSourceContextCookie, ulStartingLine, dwFlags, pvarResult, pexcepinfo);
547 if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED)
548 return E_UNEXPECTED;
550 hres = script_parse(This->ctx, pstrCode, &parser_ctx);
551 if(FAILED(hres))
552 return hres;
554 if(!is_started(This->ctx)) {
555 if(This->queue_tail)
556 This->queue_tail = This->queue_tail->next = parser_ctx;
557 else
558 This->queue_head = This->queue_tail = parser_ctx;
559 return S_OK;
562 hres = exec_global_code(This, parser_ctx);
563 parser_release(parser_ctx);
565 return hres;
568 #undef ASPARSE_THIS
570 static const IActiveScriptParseVtbl JScriptParseVtbl = {
571 JScriptParse_QueryInterface,
572 JScriptParse_AddRef,
573 JScriptParse_Release,
574 JScriptParse_InitNew,
575 JScriptParse_AddScriptlet,
576 JScriptParse_ParseScriptText
579 #define ASPARSEPROC_THIS(iface) DEFINE_THIS(JScript, IActiveScriptParseProcedure2, iface)
581 static HRESULT WINAPI JScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2 *iface, REFIID riid, void **ppv)
583 JScript *This = ASPARSEPROC_THIS(iface);
584 return IActiveScript_QueryInterface(ACTSCRIPT(This), riid, ppv);
587 static ULONG WINAPI JScriptParseProcedure_AddRef(IActiveScriptParseProcedure2 *iface)
589 JScript *This = ASPARSEPROC_THIS(iface);
590 return IActiveScript_AddRef(ACTSCRIPT(This));
593 static ULONG WINAPI JScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface)
595 JScript *This = ASPARSEPROC_THIS(iface);
596 return IActiveScript_Release(ACTSCRIPT(This));
599 static HRESULT WINAPI JScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2 *iface,
600 LPCOLESTR pstrCode, LPCOLESTR pstrFormalParams, LPCOLESTR pstrProcedureName,
601 LPCOLESTR pstrItemName, IUnknown *punkContext, LPCOLESTR pstrDelimiter,
602 DWORD dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags, IDispatch **ppdisp)
604 JScript *This = ASPARSEPROC_THIS(iface);
605 parser_ctx_t *parser_ctx;
606 DispatchEx *dispex;
607 HRESULT hres;
609 TRACE("(%p)->(%s %s %s %s %p %s %x %u %x %p)\n", This, debugstr_w(pstrCode), debugstr_w(pstrFormalParams),
610 debugstr_w(pstrProcedureName), debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
611 dwSourceContextCookie, ulStartingLineNumber, dwFlags, ppdisp);
613 if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED)
614 return E_UNEXPECTED;
616 hres = script_parse(This->ctx, pstrCode, &parser_ctx);
617 if(FAILED(hres)) {
618 WARN("Parse failed %08x\n", hres);
619 return hres;
622 hres = create_source_function(parser_ctx, NULL, parser_ctx->source, NULL, &dispex);
623 parser_release(parser_ctx);
624 if(FAILED(hres))
625 return hres;
627 *ppdisp = (IDispatch*)_IDispatchEx_(dispex);
628 return S_OK;
631 #undef ASPARSEPROC_THIS
633 static const IActiveScriptParseProcedure2Vtbl JScriptParseProcedureVtbl = {
634 JScriptParseProcedure_QueryInterface,
635 JScriptParseProcedure_AddRef,
636 JScriptParseProcedure_Release,
637 JScriptParseProcedure_ParseProcedureText,
640 #define ACTSCPPROP_THIS(iface) DEFINE_THIS(JScript, IActiveScriptProperty, iface)
642 static HRESULT WINAPI JScriptProperty_QueryInterface(IActiveScriptProperty *iface, REFIID riid, void **ppv)
644 JScript *This = ACTSCPPROP_THIS(iface);
645 return IActiveScript_QueryInterface(ACTSCRIPT(This), riid, ppv);
648 static ULONG WINAPI JScriptProperty_AddRef(IActiveScriptProperty *iface)
650 JScript *This = ACTSCPPROP_THIS(iface);
651 return IActiveScript_AddRef(ACTSCRIPT(This));
654 static ULONG WINAPI JScriptProperty_Release(IActiveScriptProperty *iface)
656 JScript *This = ACTSCPPROP_THIS(iface);
657 return IActiveScript_Release(ACTSCRIPT(This));
660 static HRESULT WINAPI JScriptProperty_GetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
661 VARIANT *pvarIndex, VARIANT *pvarValue)
663 JScript *This = ACTSCPPROP_THIS(iface);
664 FIXME("(%p)->(%x %p %p)\n", This, dwProperty, pvarIndex, pvarValue);
665 return E_NOTIMPL;
668 static HRESULT WINAPI JScriptProperty_SetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
669 VARIANT *pvarIndex, VARIANT *pvarValue)
671 JScript *This = ACTSCPPROP_THIS(iface);
672 FIXME("(%p)->(%x %p %p)\n", This, dwProperty, pvarIndex, pvarValue);
673 return E_NOTIMPL;
676 #undef ACTSCPPROP_THIS
678 static const IActiveScriptPropertyVtbl JScriptPropertyVtbl = {
679 JScriptProperty_QueryInterface,
680 JScriptProperty_AddRef,
681 JScriptProperty_Release,
682 JScriptProperty_GetProperty,
683 JScriptProperty_SetProperty
686 #define OBJSAFETY_THIS(iface) DEFINE_THIS(JScript, IObjectSafety, iface)
688 static HRESULT WINAPI JScriptSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
690 JScript *This = OBJSAFETY_THIS(iface);
691 return IActiveScript_QueryInterface(ACTSCRIPT(This), riid, ppv);
694 static ULONG WINAPI JScriptSafety_AddRef(IObjectSafety *iface)
696 JScript *This = OBJSAFETY_THIS(iface);
697 return IActiveScript_AddRef(ACTSCRIPT(This));
700 static ULONG WINAPI JScriptSafety_Release(IObjectSafety *iface)
702 JScript *This = OBJSAFETY_THIS(iface);
703 return IActiveScript_Release(ACTSCRIPT(This));
706 #define SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER)
708 static HRESULT WINAPI JScriptSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
709 DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
711 JScript *This = OBJSAFETY_THIS(iface);
713 TRACE("(%p)->(%s %p %p)\n", This, debugstr_guid(riid), pdwSupportedOptions, pdwEnabledOptions);
715 if(!pdwSupportedOptions || !pdwEnabledOptions)
716 return E_POINTER;
718 *pdwSupportedOptions = SUPPORTED_OPTIONS;
719 *pdwEnabledOptions = This->safeopt;
721 return S_OK;
724 static HRESULT WINAPI JScriptSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
725 DWORD dwOptionSetMask, DWORD dwEnabledOptions)
727 JScript *This = OBJSAFETY_THIS(iface);
729 TRACE("(%p)->(%s %x %x)\n", This, debugstr_guid(riid), dwOptionSetMask, dwEnabledOptions);
731 if(dwOptionSetMask & ~SUPPORTED_OPTIONS)
732 return E_FAIL;
734 This->safeopt = dwEnabledOptions & dwEnabledOptions;
735 return S_OK;
738 #undef OBJSAFETY_THIS
740 static const IObjectSafetyVtbl JScriptSafetyVtbl = {
741 JScriptSafety_QueryInterface,
742 JScriptSafety_AddRef,
743 JScriptSafety_Release,
744 JScriptSafety_GetInterfaceSafetyOptions,
745 JScriptSafety_SetInterfaceSafetyOptions
748 HRESULT WINAPI JScriptFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
749 REFIID riid, void **ppv)
751 JScript *ret;
752 HRESULT hres;
754 TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppv);
756 lock_module();
758 ret = heap_alloc_zero(sizeof(*ret));
760 ret->lpIActiveScriptVtbl = &JScriptVtbl;
761 ret->lpIActiveScriptParseVtbl = &JScriptParseVtbl;
762 ret->lpIActiveScriptParseProcedure2Vtbl = &JScriptParseProcedureVtbl;
763 ret->lpIActiveScriptPropertyVtbl = &JScriptPropertyVtbl;
764 ret->lpIObjectSafetyVtbl = &JScriptSafetyVtbl;
765 ret->ref = 1;
766 ret->safeopt = INTERFACE_USES_DISPEX;
768 hres = IActiveScript_QueryInterface(ACTSCRIPT(ret), riid, ppv);
769 IActiveScript_Release(ACTSCRIPT(ret));
770 return hres;