wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / jscript / jscript.c
blob67a25d1714bd131b7ad3d859cbb1ebd0e3b231ce
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 <assert.h>
21 #include "jscript.h"
22 #include "engine.h"
23 #include "objsafe.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
29 #ifdef _WIN64
31 #define CTXARG_T DWORDLONG
32 #define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
33 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_64Vtbl
35 #else
37 #define CTXARG_T DWORD
38 #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
39 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_32Vtbl
41 #endif
43 typedef struct {
44 IActiveScript IActiveScript_iface;
45 IActiveScriptParse IActiveScriptParse_iface;
46 IActiveScriptParseProcedure2 IActiveScriptParseProcedure2_iface;
47 IActiveScriptProperty IActiveScriptProperty_iface;
48 IObjectSafety IObjectSafety_iface;
49 IVariantChangeType IVariantChangeType_iface;
51 LONG ref;
53 DWORD safeopt;
54 script_ctx_t *ctx;
55 LONG thread_id;
56 LCID lcid;
57 DWORD version;
58 BOOL html_mode;
59 BOOL is_encode;
60 BOOL is_initialized;
62 IActiveScriptSite *site;
64 struct list persistent_code;
65 struct list queued_code;
66 } JScript;
68 typedef struct {
69 IActiveScriptError IActiveScriptError_iface;
70 LONG ref;
71 jsexcept_t ei;
72 } JScriptError;
74 void script_release(script_ctx_t *ctx)
76 if(--ctx->ref)
77 return;
79 jsval_release(ctx->acc);
80 if(ctx->cc)
81 release_cc(ctx->cc);
82 heap_pool_free(&ctx->tmp_heap);
83 if(ctx->last_match)
84 jsstr_release(ctx->last_match);
85 assert(!ctx->stack_top);
86 heap_free(ctx->stack);
88 ctx->jscaller->ctx = NULL;
89 IServiceProvider_Release(&ctx->jscaller->IServiceProvider_iface);
91 heap_free(ctx);
94 static void change_state(JScript *This, SCRIPTSTATE state)
96 if(This->ctx->state == state)
97 return;
99 This->ctx->state = state;
100 if(This->site)
101 IActiveScriptSite_OnStateChange(This->site, state);
104 static inline BOOL is_started(script_ctx_t *ctx)
106 return ctx->state == SCRIPTSTATE_STARTED
107 || ctx->state == SCRIPTSTATE_CONNECTED
108 || ctx->state == SCRIPTSTATE_DISCONNECTED;
111 HRESULT create_named_item_script_obj(script_ctx_t *ctx, named_item_t *item)
113 static const builtin_info_t disp_info = {
114 JSCLASS_GLOBAL,
115 {NULL, NULL, 0},
116 0, NULL,
117 NULL,
118 NULL
121 return create_dispex(ctx, &disp_info, NULL, &item->script_obj);
124 static void release_named_item_script_obj(named_item_t *item)
126 if(!item->script_obj) return;
128 jsdisp_release(item->script_obj);
129 item->script_obj = NULL;
132 static HRESULT retrieve_named_item_disp(IActiveScriptSite *site, named_item_t *item)
134 IUnknown *unk;
135 HRESULT hr;
137 if(!site)
138 return E_UNEXPECTED;
140 hr = IActiveScriptSite_GetItemInfo(site, item->name, SCRIPTINFO_IUNKNOWN, &unk, NULL);
141 if(FAILED(hr)) {
142 WARN("GetItemInfo failed: %08x\n", hr);
143 return hr;
146 hr = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&item->disp);
147 IUnknown_Release(unk);
148 if(FAILED(hr)) {
149 WARN("object does not implement IDispatch\n");
150 return hr;
153 return S_OK;
156 named_item_t *lookup_named_item(script_ctx_t *ctx, const WCHAR *item_name, unsigned flags)
158 named_item_t *item;
159 HRESULT hr;
161 LIST_FOR_EACH_ENTRY(item, &ctx->named_items, named_item_t, entry) {
162 if((item->flags & flags) == flags && !wcscmp(item->name, item_name)) {
163 if(!item->script_obj && !(item->flags & SCRIPTITEM_GLOBALMEMBERS)) {
164 hr = create_named_item_script_obj(ctx, item);
165 if(FAILED(hr)) return NULL;
168 if(!item->disp && (flags || !(item->flags & SCRIPTITEM_CODEONLY))) {
169 hr = retrieve_named_item_disp(ctx->site, item);
170 if(FAILED(hr)) continue;
173 return item;
177 return NULL;
180 void release_named_item(named_item_t *item)
182 if(--item->ref) return;
184 heap_free(item->name);
185 heap_free(item);
188 static inline JScriptError *impl_from_IActiveScriptError(IActiveScriptError *iface)
190 return CONTAINING_RECORD(iface, JScriptError, IActiveScriptError_iface);
193 static HRESULT WINAPI JScriptError_QueryInterface(IActiveScriptError *iface, REFIID riid, void **ppv)
195 JScriptError *This = impl_from_IActiveScriptError(iface);
197 if(IsEqualGUID(riid, &IID_IUnknown)) {
198 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
199 *ppv = &This->IActiveScriptError_iface;
200 }else if(IsEqualGUID(riid, &IID_IActiveScriptError)) {
201 TRACE("(%p)->(IID_IActiveScriptError %p)\n", This, ppv);
202 *ppv = &This->IActiveScriptError_iface;
203 }else {
204 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
205 *ppv = NULL;
206 return E_NOINTERFACE;
209 IUnknown_AddRef((IUnknown*)*ppv);
210 return S_OK;
213 static ULONG WINAPI JScriptError_AddRef(IActiveScriptError *iface)
215 JScriptError *This = impl_from_IActiveScriptError(iface);
216 LONG ref = InterlockedIncrement(&This->ref);
218 TRACE("(%p) ref=%d\n", This, ref);
220 return ref;
223 static ULONG WINAPI JScriptError_Release(IActiveScriptError *iface)
225 JScriptError *This = impl_from_IActiveScriptError(iface);
226 LONG ref = InterlockedDecrement(&This->ref);
228 TRACE("(%p) ref=%d\n", This, ref);
230 if(!ref) {
231 reset_ei(&This->ei);
232 heap_free(This);
235 return ref;
238 static HRESULT WINAPI JScriptError_GetExceptionInfo(IActiveScriptError *iface, EXCEPINFO *excepinfo)
240 JScriptError *This = impl_from_IActiveScriptError(iface);
242 TRACE("(%p)->(%p)\n", This, excepinfo);
244 if(!excepinfo)
245 return E_POINTER;
247 memset(excepinfo, 0, sizeof(*excepinfo));
248 excepinfo->scode = This->ei.error;
249 if(This->ei.source)
250 jsstr_to_bstr(This->ei.source, &excepinfo->bstrSource);
251 if(This->ei.message)
252 jsstr_to_bstr(This->ei.message, &excepinfo->bstrDescription);
253 return S_OK;
256 static HRESULT WINAPI JScriptError_GetSourcePosition(IActiveScriptError *iface, DWORD *source_context, ULONG *line, LONG *character)
258 JScriptError *This = impl_from_IActiveScriptError(iface);
259 bytecode_t *code = This->ei.code;
260 unsigned line_pos, char_pos;
262 TRACE("(%p)->(%p %p %p)\n", This, source_context, line, character);
264 if(!This->ei.code) {
265 FIXME("unknown position\n");
266 return E_FAIL;
269 if(source_context)
270 *source_context = This->ei.code->source_context;
271 if(!line && !character)
272 return S_OK;
274 line_pos = get_location_line(code, This->ei.loc, &char_pos);
275 if(line)
276 *line = line_pos;
277 if(character)
278 *character = char_pos;
279 return S_OK;
282 static HRESULT WINAPI JScriptError_GetSourceLineText(IActiveScriptError *iface, BSTR *source)
284 JScriptError *This = impl_from_IActiveScriptError(iface);
286 TRACE("(%p)->(%p)\n", This, source);
288 if(!source)
289 return E_POINTER;
291 if(!This->ei.line) {
292 *source = NULL;
293 return E_FAIL;
296 return jsstr_to_bstr(This->ei.line, source);
299 static const IActiveScriptErrorVtbl JScriptErrorVtbl = {
300 JScriptError_QueryInterface,
301 JScriptError_AddRef,
302 JScriptError_Release,
303 JScriptError_GetExceptionInfo,
304 JScriptError_GetSourcePosition,
305 JScriptError_GetSourceLineText
308 void reset_ei(jsexcept_t *ei)
310 ei->error = S_OK;
311 if(ei->valid_value) {
312 jsval_release(ei->value);
313 ei->valid_value = FALSE;
315 if(ei->code) {
316 release_bytecode(ei->code);
317 ei->code = NULL;
318 ei->loc = 0;
320 if(ei->source) {
321 jsstr_release(ei->source);
322 ei->source = NULL;
324 if(ei->message) {
325 jsstr_release(ei->message);
326 ei->message = NULL;
328 if(ei->line) {
329 jsstr_release(ei->line);
330 ei->line = NULL;
334 void enter_script(script_ctx_t *ctx, jsexcept_t *ei)
336 memset(ei, 0, sizeof(*ei));
337 ei->prev = ctx->ei;
338 ctx->ei = ei;
339 TRACE("ctx %p ei %p prev %p\n", ctx, ei, ei->prev);
342 HRESULT leave_script(script_ctx_t *ctx, HRESULT result)
344 jsexcept_t *ei = ctx->ei;
345 BOOL enter_notified = ei->enter_notified;
346 JScriptError *error;
348 TRACE("ctx %p ei %p prev %p\n", ctx, ei, ei->prev);
350 ctx->ei = ei->prev;
351 if(result == DISP_E_EXCEPTION) {
352 result = ei->error;
353 }else {
354 reset_ei(ei);
355 ei->error = result;
357 if(FAILED(result)) {
358 WARN("%08x\n", result);
359 if(ctx->site && (error = heap_alloc(sizeof(*error)))) {
360 HRESULT hres;
362 error->IActiveScriptError_iface.lpVtbl = &JScriptErrorVtbl;
363 error->ref = 1;
364 error->ei = *ei;
365 memset(ei, 0, sizeof(*ei));
367 hres = IActiveScriptSite_OnScriptError(ctx->site, &error->IActiveScriptError_iface);
368 IActiveScriptError_Release(&error->IActiveScriptError_iface);
369 if(hres == S_OK)
370 result = SCRIPT_E_REPORTED;
373 if(enter_notified && ctx->site)
374 IActiveScriptSite_OnLeaveScript(ctx->site);
375 reset_ei(ei);
376 return result;
379 static void clear_script_queue(JScript *This)
381 while(!list_empty(&This->queued_code))
383 bytecode_t *iter = LIST_ENTRY(list_head(&This->queued_code), bytecode_t, entry);
384 list_remove(&iter->entry);
385 if (iter->is_persistent)
386 list_add_tail(&This->persistent_code, &iter->entry);
387 else
388 release_bytecode(iter);
392 static void clear_persistent_code_list(JScript *This)
394 while(!list_empty(&This->persistent_code))
396 bytecode_t *iter = LIST_ENTRY(list_head(&This->persistent_code), bytecode_t, entry);
397 list_remove(&iter->entry);
398 release_bytecode(iter);
402 static void release_persistent_script_objs(JScript *This)
404 bytecode_t *iter;
406 LIST_FOR_EACH_ENTRY(iter, &This->persistent_code, bytecode_t, entry)
407 if(iter->named_item)
408 release_named_item_script_obj(iter->named_item);
411 static void release_named_item_list(JScript *This)
413 while(!list_empty(&This->ctx->named_items)) {
414 named_item_t *iter = LIST_ENTRY(list_head(&This->ctx->named_items), named_item_t, entry);
415 list_remove(&iter->entry);
416 release_named_item(iter);
420 static void exec_queued_code(JScript *This)
422 bytecode_t *iter;
423 jsexcept_t ei;
424 HRESULT hres = S_OK;
426 LIST_FOR_EACH_ENTRY(iter, &This->queued_code, bytecode_t, entry) {
427 enter_script(This->ctx, &ei);
428 hres = exec_source(This->ctx, EXEC_GLOBAL, iter, &iter->global_code, NULL, NULL, NULL, 0, NULL, NULL);
429 leave_script(This->ctx, hres);
430 if(FAILED(hres))
431 break;
434 clear_script_queue(This);
437 static void decrease_state(JScript *This, SCRIPTSTATE state)
439 named_item_t *item, *item_next;
441 if(This->ctx) {
442 switch(This->ctx->state) {
443 case SCRIPTSTATE_CONNECTED:
444 change_state(This, SCRIPTSTATE_DISCONNECTED);
445 if(state == SCRIPTSTATE_DISCONNECTED)
446 return;
447 /* FALLTHROUGH */
448 case SCRIPTSTATE_STARTED:
449 case SCRIPTSTATE_DISCONNECTED:
450 clear_script_queue(This);
452 if(This->ctx->state == SCRIPTSTATE_DISCONNECTED)
453 change_state(This, SCRIPTSTATE_INITIALIZED);
454 if(state == SCRIPTSTATE_INITIALIZED)
455 return;
456 /* FALLTHROUGH */
457 case SCRIPTSTATE_INITIALIZED:
458 clear_script_queue(This);
459 release_persistent_script_objs(This);
461 LIST_FOR_EACH_ENTRY_SAFE(item, item_next, &This->ctx->named_items, named_item_t, entry)
463 if(item->disp)
465 IDispatch_Release(item->disp);
466 item->disp = NULL;
468 release_named_item_script_obj(item);
469 if(!(item->flags & SCRIPTITEM_ISPERSISTENT))
471 list_remove(&item->entry);
472 release_named_item(item);
476 if(This->ctx->secmgr) {
477 IInternetHostSecurityManager_Release(This->ctx->secmgr);
478 This->ctx->secmgr = NULL;
481 if(This->ctx->site) {
482 IActiveScriptSite_Release(This->ctx->site);
483 This->ctx->site = NULL;
486 if(This->ctx->object_prototype) {
487 jsdisp_release(This->ctx->object_prototype);
488 This->ctx->object_prototype = NULL;
491 if(This->ctx->global) {
492 jsdisp_release(This->ctx->global);
493 This->ctx->global = NULL;
495 /* FALLTHROUGH */
496 case SCRIPTSTATE_UNINITIALIZED:
497 change_state(This, state);
498 break;
499 default:
500 assert(0);
503 change_state(This, state);
504 }else if(state == SCRIPTSTATE_UNINITIALIZED) {
505 if(This->site)
506 IActiveScriptSite_OnStateChange(This->site, state);
507 }else {
508 FIXME("NULL ctx\n");
511 if(state == SCRIPTSTATE_UNINITIALIZED || state == SCRIPTSTATE_CLOSED)
512 This->thread_id = 0;
514 if(This->site) {
515 IActiveScriptSite_Release(This->site);
516 This->site = NULL;
520 typedef struct {
521 IServiceProvider IServiceProvider_iface;
523 LONG ref;
525 IServiceProvider *sp;
526 } AXSite;
528 static inline AXSite *impl_from_IServiceProvider(IServiceProvider *iface)
530 return CONTAINING_RECORD(iface, AXSite, IServiceProvider_iface);
533 static HRESULT WINAPI AXSite_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
535 AXSite *This = impl_from_IServiceProvider(iface);
537 if(IsEqualGUID(&IID_IUnknown, riid)) {
538 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
539 *ppv = &This->IServiceProvider_iface;
540 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
541 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
542 *ppv = &This->IServiceProvider_iface;
543 }else {
544 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
545 *ppv = NULL;
546 return E_NOINTERFACE;
549 IUnknown_AddRef((IUnknown*)*ppv);
550 return S_OK;
553 static ULONG WINAPI AXSite_AddRef(IServiceProvider *iface)
555 AXSite *This = impl_from_IServiceProvider(iface);
556 LONG ref = InterlockedIncrement(&This->ref);
558 TRACE("(%p) ref=%d\n", This, ref);
560 return ref;
563 static ULONG WINAPI AXSite_Release(IServiceProvider *iface)
565 AXSite *This = impl_from_IServiceProvider(iface);
566 LONG ref = InterlockedDecrement(&This->ref);
568 TRACE("(%p) ref=%d\n", This, ref);
570 if(!ref)
572 if(This->sp)
573 IServiceProvider_Release(This->sp);
575 heap_free(This);
578 return ref;
581 static HRESULT WINAPI AXSite_QueryService(IServiceProvider *iface,
582 REFGUID guidService, REFIID riid, void **ppv)
584 AXSite *This = impl_from_IServiceProvider(iface);
586 TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
588 if(!This->sp)
589 return E_NOINTERFACE;
591 return IServiceProvider_QueryService(This->sp, guidService, riid, ppv);
594 static IServiceProviderVtbl AXSiteVtbl = {
595 AXSite_QueryInterface,
596 AXSite_AddRef,
597 AXSite_Release,
598 AXSite_QueryService
601 IUnknown *create_ax_site(script_ctx_t *ctx)
603 IServiceProvider *sp = NULL;
604 AXSite *ret;
605 HRESULT hres;
607 hres = IActiveScriptSite_QueryInterface(ctx->site, &IID_IServiceProvider, (void**)&sp);
608 if(FAILED(hres)) {
609 TRACE("Could not get IServiceProvider iface: %08x\n", hres);
612 ret = heap_alloc(sizeof(AXSite));
613 if(!ret) {
614 IServiceProvider_Release(sp);
615 return NULL;
618 ret->IServiceProvider_iface.lpVtbl = &AXSiteVtbl;
619 ret->ref = 1;
620 ret->sp = sp;
622 return (IUnknown*)&ret->IServiceProvider_iface;
625 static inline JScript *impl_from_IActiveScript(IActiveScript *iface)
627 return CONTAINING_RECORD(iface, JScript, IActiveScript_iface);
630 static HRESULT WINAPI JScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
632 JScript *This = impl_from_IActiveScript(iface);
634 *ppv = NULL;
636 if(IsEqualGUID(riid, &IID_IUnknown)) {
637 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
638 *ppv = &This->IActiveScript_iface;
639 }else if(IsEqualGUID(riid, &IID_IActiveScript)) {
640 TRACE("(%p)->(IID_IActiveScript %p)\n", This, ppv);
641 *ppv = &This->IActiveScript_iface;
642 }else if(IsEqualGUID(riid, &IID_IActiveScriptParse)) {
643 TRACE("(%p)->(IID_IActiveScriptParse %p)\n", This, ppv);
644 *ppv = &This->IActiveScriptParse_iface;
645 }else if(IsEqualGUID(riid, &IID_IActiveScriptParseProcedure)) {
646 TRACE("(%p)->(IID_IActiveScriptParseProcedure %p)\n", This, ppv);
647 *ppv = &This->IActiveScriptParseProcedure2_iface;
648 }else if(IsEqualGUID(riid, &IID_IActiveScriptParseProcedure2)) {
649 TRACE("(%p)->(IID_IActiveScriptParseProcedure2 %p)\n", This, ppv);
650 *ppv = &This->IActiveScriptParseProcedure2_iface;
651 }else if(IsEqualGUID(riid, &IID_IActiveScriptProperty)) {
652 TRACE("(%p)->(IID_IActiveScriptProperty %p)\n", This, ppv);
653 *ppv = &This->IActiveScriptProperty_iface;
654 }else if(IsEqualGUID(riid, &IID_IObjectSafety)) {
655 TRACE("(%p)->(IID_IObjectSafety %p)\n", This, ppv);
656 *ppv = &This->IObjectSafety_iface;
657 }else if(IsEqualGUID(riid, &IID_IVariantChangeType)) {
658 TRACE("(%p)->(IID_IVariantChangeType %p)\n", This, ppv);
659 *ppv = &This->IVariantChangeType_iface;
662 if(*ppv) {
663 IUnknown_AddRef((IUnknown*)*ppv);
664 return S_OK;
667 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
668 return E_NOINTERFACE;
671 static ULONG WINAPI JScript_AddRef(IActiveScript *iface)
673 JScript *This = impl_from_IActiveScript(iface);
674 LONG ref = InterlockedIncrement(&This->ref);
676 TRACE("(%p) ref=%d\n", This, ref);
678 return ref;
681 static ULONG WINAPI JScript_Release(IActiveScript *iface)
683 JScript *This = impl_from_IActiveScript(iface);
684 LONG ref = InterlockedDecrement(&This->ref);
686 TRACE("(%p) ref=%d\n", iface, ref);
688 if(!ref) {
689 if(This->ctx && This->ctx->state != SCRIPTSTATE_CLOSED)
690 IActiveScript_Close(&This->IActiveScript_iface);
691 if(This->ctx) {
692 This->ctx->active_script = NULL;
693 script_release(This->ctx);
695 heap_free(This);
696 unlock_module();
699 return ref;
702 static HRESULT WINAPI JScript_SetScriptSite(IActiveScript *iface,
703 IActiveScriptSite *pass)
705 JScript *This = impl_from_IActiveScript(iface);
706 named_item_t *item;
707 LCID lcid;
708 HRESULT hres;
710 TRACE("(%p)->(%p)\n", This, pass);
712 if(!pass)
713 return E_POINTER;
715 if(This->site)
716 return E_UNEXPECTED;
718 if(InterlockedCompareExchange(&This->thread_id, GetCurrentThreadId(), 0))
719 return E_UNEXPECTED;
721 if(!This->ctx) {
722 script_ctx_t *ctx = heap_alloc_zero(sizeof(script_ctx_t));
723 if(!ctx)
724 return E_OUTOFMEMORY;
726 ctx->ref = 1;
727 ctx->state = SCRIPTSTATE_UNINITIALIZED;
728 ctx->active_script = &This->IActiveScript_iface;
729 ctx->safeopt = This->safeopt;
730 ctx->version = This->version;
731 ctx->html_mode = This->html_mode;
732 ctx->acc = jsval_undefined();
733 list_init(&ctx->named_items);
734 heap_pool_init(&ctx->tmp_heap);
736 hres = create_jscaller(ctx);
737 if(FAILED(hres)) {
738 heap_free(ctx);
739 return hres;
742 ctx->last_match = jsstr_empty();
744 ctx = InterlockedCompareExchangePointer((void**)&This->ctx, ctx, NULL);
745 if(ctx) {
746 script_release(ctx);
747 return E_UNEXPECTED;
751 /* Retrieve new dispatches for persistent named items */
752 LIST_FOR_EACH_ENTRY(item, &This->ctx->named_items, named_item_t, entry)
754 if(!item->disp)
756 hres = retrieve_named_item_disp(pass, item);
757 if(FAILED(hres)) return hres;
760 /* For some reason, CODEONLY flag is lost in re-initialized scripts */
761 item->flags &= ~SCRIPTITEM_CODEONLY;
764 This->site = pass;
765 IActiveScriptSite_AddRef(This->site);
767 hres = IActiveScriptSite_GetLCID(This->site, &lcid);
768 if(hres == S_OK)
769 This->lcid = lcid;
771 This->ctx->lcid = This->lcid;
773 hres = init_global(This->ctx);
774 if(FAILED(hres))
775 return hres;
777 IActiveScriptSite_AddRef(This->site);
778 This->ctx->site = This->site;
780 if(This->is_initialized)
781 change_state(This, SCRIPTSTATE_INITIALIZED);
782 return S_OK;
785 static HRESULT WINAPI JScript_GetScriptSite(IActiveScript *iface, REFIID riid,
786 void **ppvObject)
788 JScript *This = impl_from_IActiveScript(iface);
789 FIXME("(%p)->()\n", This);
790 return E_NOTIMPL;
793 static HRESULT WINAPI JScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
795 JScript *This = impl_from_IActiveScript(iface);
797 TRACE("(%p)->(%d)\n", This, ss);
799 if(This->thread_id && GetCurrentThreadId() != This->thread_id)
800 return E_UNEXPECTED;
802 if(ss == SCRIPTSTATE_UNINITIALIZED) {
803 if(This->ctx && This->ctx->state == SCRIPTSTATE_CLOSED)
804 return E_UNEXPECTED;
806 decrease_state(This, SCRIPTSTATE_UNINITIALIZED);
807 list_move_tail(&This->queued_code, &This->persistent_code);
808 return S_OK;
811 if(!This->is_initialized || !This->ctx)
812 return E_UNEXPECTED;
814 switch(ss) {
815 case SCRIPTSTATE_STARTED:
816 case SCRIPTSTATE_CONNECTED: /* FIXME */
817 if(This->ctx->state == SCRIPTSTATE_CLOSED)
818 return E_UNEXPECTED;
820 exec_queued_code(This);
821 break;
822 case SCRIPTSTATE_INITIALIZED:
823 FIXME("unimplemented SCRIPTSTATE_INITIALIZED\n");
824 return S_OK;
825 default:
826 FIXME("unimplemented state %d\n", ss);
827 return E_NOTIMPL;
830 change_state(This, ss);
831 return S_OK;
834 static HRESULT WINAPI JScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
836 JScript *This = impl_from_IActiveScript(iface);
838 TRACE("(%p)->(%p)\n", This, pssState);
840 if(!pssState)
841 return E_POINTER;
843 if(This->thread_id && This->thread_id != GetCurrentThreadId())
844 return E_UNEXPECTED;
846 *pssState = This->ctx ? This->ctx->state : SCRIPTSTATE_UNINITIALIZED;
847 return S_OK;
850 static HRESULT WINAPI JScript_Close(IActiveScript *iface)
852 JScript *This = impl_from_IActiveScript(iface);
854 TRACE("(%p)->()\n", This);
856 if(This->thread_id && This->thread_id != GetCurrentThreadId())
857 return E_UNEXPECTED;
859 decrease_state(This, SCRIPTSTATE_CLOSED);
860 clear_persistent_code_list(This);
861 release_named_item_list(This);
862 return S_OK;
865 static HRESULT WINAPI JScript_AddNamedItem(IActiveScript *iface,
866 LPCOLESTR pstrName, DWORD dwFlags)
868 JScript *This = impl_from_IActiveScript(iface);
869 named_item_t *item;
870 IDispatch *disp = NULL;
871 HRESULT hres;
873 TRACE("(%p)->(%s %x)\n", This, debugstr_w(pstrName), dwFlags);
875 if(This->thread_id != GetCurrentThreadId() || !This->ctx || This->ctx->state == SCRIPTSTATE_CLOSED)
876 return E_UNEXPECTED;
878 if(dwFlags & SCRIPTITEM_GLOBALMEMBERS) {
879 IUnknown *unk;
881 hres = IActiveScriptSite_GetItemInfo(This->site, pstrName, SCRIPTINFO_IUNKNOWN, &unk, NULL);
882 if(FAILED(hres)) {
883 WARN("GetItemInfo failed: %08x\n", hres);
884 return hres;
887 hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
888 IUnknown_Release(unk);
889 if(FAILED(hres)) {
890 WARN("object does not implement IDispatch\n");
891 return hres;
895 item = heap_alloc(sizeof(*item));
896 if(!item) {
897 if(disp)
898 IDispatch_Release(disp);
899 return E_OUTOFMEMORY;
902 item->ref = 1;
903 item->disp = disp;
904 item->flags = dwFlags;
905 item->script_obj = NULL;
906 item->name = heap_strdupW(pstrName);
907 if(!item->name) {
908 if(disp)
909 IDispatch_Release(disp);
910 heap_free(item);
911 return E_OUTOFMEMORY;
914 list_add_tail(&This->ctx->named_items, &item->entry);
915 return S_OK;
918 static HRESULT WINAPI JScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
919 DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
921 JScript *This = impl_from_IActiveScript(iface);
922 FIXME("(%p)->()\n", This);
923 return E_NOTIMPL;
926 static HRESULT WINAPI JScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName,
927 IDispatch **ppdisp)
929 JScript *This = impl_from_IActiveScript(iface);
930 jsdisp_t *script_obj;
932 TRACE("(%p)->(%s %p)\n", This, debugstr_w(pstrItemName), ppdisp);
934 if(!ppdisp)
935 return E_POINTER;
937 if(This->thread_id != GetCurrentThreadId() || !This->ctx->global) {
938 *ppdisp = NULL;
939 return E_UNEXPECTED;
942 script_obj = This->ctx->global;
943 if(pstrItemName) {
944 named_item_t *item = lookup_named_item(This->ctx, pstrItemName, 0);
945 if(!item) return E_INVALIDARG;
946 if(item->script_obj) script_obj = item->script_obj;
949 *ppdisp = to_disp(script_obj);
950 IDispatch_AddRef(*ppdisp);
951 return S_OK;
954 static HRESULT WINAPI JScript_GetCurrentScriptThreadID(IActiveScript *iface,
955 SCRIPTTHREADID *pstridThread)
957 JScript *This = impl_from_IActiveScript(iface);
958 FIXME("(%p)->()\n", This);
959 return E_NOTIMPL;
962 static HRESULT WINAPI JScript_GetScriptThreadID(IActiveScript *iface,
963 DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
965 JScript *This = impl_from_IActiveScript(iface);
966 FIXME("(%p)->()\n", This);
967 return E_NOTIMPL;
970 static HRESULT WINAPI JScript_GetScriptThreadState(IActiveScript *iface,
971 SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
973 JScript *This = impl_from_IActiveScript(iface);
974 FIXME("(%p)->()\n", This);
975 return E_NOTIMPL;
978 static HRESULT WINAPI JScript_InterruptScriptThread(IActiveScript *iface,
979 SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
981 JScript *This = impl_from_IActiveScript(iface);
982 FIXME("(%p)->()\n", This);
983 return E_NOTIMPL;
986 static HRESULT WINAPI JScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
988 JScript *This = impl_from_IActiveScript(iface);
989 FIXME("(%p)->()\n", This);
990 return E_NOTIMPL;
993 static const IActiveScriptVtbl JScriptVtbl = {
994 JScript_QueryInterface,
995 JScript_AddRef,
996 JScript_Release,
997 JScript_SetScriptSite,
998 JScript_GetScriptSite,
999 JScript_SetScriptState,
1000 JScript_GetScriptState,
1001 JScript_Close,
1002 JScript_AddNamedItem,
1003 JScript_AddTypeLib,
1004 JScript_GetScriptDispatch,
1005 JScript_GetCurrentScriptThreadID,
1006 JScript_GetScriptThreadID,
1007 JScript_GetScriptThreadState,
1008 JScript_InterruptScriptThread,
1009 JScript_Clone
1012 static inline JScript *impl_from_IActiveScriptParse(IActiveScriptParse *iface)
1014 return CONTAINING_RECORD(iface, JScript, IActiveScriptParse_iface);
1017 static HRESULT WINAPI JScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
1019 JScript *This = impl_from_IActiveScriptParse(iface);
1020 return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
1023 static ULONG WINAPI JScriptParse_AddRef(IActiveScriptParse *iface)
1025 JScript *This = impl_from_IActiveScriptParse(iface);
1026 return IActiveScript_AddRef(&This->IActiveScript_iface);
1029 static ULONG WINAPI JScriptParse_Release(IActiveScriptParse *iface)
1031 JScript *This = impl_from_IActiveScriptParse(iface);
1032 return IActiveScript_Release(&This->IActiveScript_iface);
1035 static HRESULT WINAPI JScriptParse_InitNew(IActiveScriptParse *iface)
1037 JScript *This = impl_from_IActiveScriptParse(iface);
1039 TRACE("(%p)\n", This);
1041 if(This->is_initialized)
1042 return E_UNEXPECTED;
1043 This->is_initialized = TRUE;
1045 if(This->site)
1046 change_state(This, SCRIPTSTATE_INITIALIZED);
1047 return S_OK;
1050 static HRESULT WINAPI JScriptParse_AddScriptlet(IActiveScriptParse *iface,
1051 LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode, LPCOLESTR pstrItemName,
1052 LPCOLESTR pstrSubItemName, LPCOLESTR pstrEventName, LPCOLESTR pstrDelimiter,
1053 CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags,
1054 BSTR *pbstrName, EXCEPINFO *pexcepinfo)
1056 JScript *This = impl_from_IActiveScriptParse(iface);
1057 FIXME("(%p)->(%s %s %s %s %s %s %s %u %x %p %p)\n", This, debugstr_w(pstrDefaultName),
1058 debugstr_w(pstrCode), debugstr_w(pstrItemName), debugstr_w(pstrSubItemName),
1059 debugstr_w(pstrEventName), debugstr_w(pstrDelimiter), wine_dbgstr_longlong(dwSourceContextCookie),
1060 ulStartingLineNumber, dwFlags, pbstrName, pexcepinfo);
1061 return E_NOTIMPL;
1064 static HRESULT WINAPI JScriptParse_ParseScriptText(IActiveScriptParse *iface,
1065 LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
1066 LPCOLESTR pstrDelimiter, CTXARG_T dwSourceContextCookie, ULONG ulStartingLine,
1067 DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
1069 JScript *This = impl_from_IActiveScriptParse(iface);
1070 named_item_t *item = NULL;
1071 bytecode_t *code;
1072 jsexcept_t ei;
1073 HRESULT hres;
1075 TRACE("(%p)->(%s %s %p %s %s %u %x %p %p)\n", This, debugstr_w(pstrCode),
1076 debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
1077 wine_dbgstr_longlong(dwSourceContextCookie), ulStartingLine, dwFlags, pvarResult, pexcepinfo);
1079 if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED)
1080 return E_UNEXPECTED;
1082 if(pstrItemName) {
1083 item = lookup_named_item(This->ctx, pstrItemName, 0);
1084 if(!item) {
1085 WARN("Unknown context %s\n", debugstr_w(pstrItemName));
1086 return E_INVALIDARG;
1088 if(!item->script_obj) item = NULL;
1091 enter_script(This->ctx, &ei);
1092 hres = compile_script(This->ctx, pstrCode, dwSourceContextCookie, ulStartingLine, NULL, pstrDelimiter,
1093 (dwFlags & SCRIPTTEXT_ISEXPRESSION) != 0, This->is_encode, item, &code);
1094 if(FAILED(hres))
1095 return leave_script(This->ctx, hres);
1097 if(dwFlags & SCRIPTTEXT_ISEXPRESSION) {
1098 jsval_t r;
1100 hres = exec_source(This->ctx, EXEC_GLOBAL, code, &code->global_code, NULL, NULL, NULL, 0, NULL, &r);
1101 if(SUCCEEDED(hres)) {
1102 if(pvarResult)
1103 hres = jsval_to_variant(r, pvarResult);
1104 jsval_release(r);
1107 return leave_script(This->ctx, hres);
1110 code->is_persistent = (dwFlags & SCRIPTTEXT_ISPERSISTENT) != 0;
1113 * Although pvarResult is not really used without SCRIPTTEXT_ISEXPRESSION flag, if it's not NULL,
1114 * script is executed immediately, even if it's not in started state yet.
1116 if(!pvarResult && !is_started(This->ctx)) {
1117 list_add_tail(&This->queued_code, &code->entry);
1118 }else {
1119 hres = exec_source(This->ctx, EXEC_GLOBAL, code, &code->global_code, NULL, NULL, NULL, 0, NULL, NULL);
1120 if(code->is_persistent)
1121 list_add_tail(&This->persistent_code, &code->entry);
1122 else
1123 release_bytecode(code);
1126 if(FAILED(hres = leave_script(This->ctx, hres)))
1127 return hres;
1129 if(pvarResult)
1130 V_VT(pvarResult) = VT_EMPTY;
1131 return S_OK;
1134 static const IActiveScriptParseVtbl JScriptParseVtbl = {
1135 JScriptParse_QueryInterface,
1136 JScriptParse_AddRef,
1137 JScriptParse_Release,
1138 JScriptParse_InitNew,
1139 JScriptParse_AddScriptlet,
1140 JScriptParse_ParseScriptText
1143 static inline JScript *impl_from_IActiveScriptParseProcedure2(IActiveScriptParseProcedure2 *iface)
1145 return CONTAINING_RECORD(iface, JScript, IActiveScriptParseProcedure2_iface);
1148 static HRESULT WINAPI JScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2 *iface, REFIID riid, void **ppv)
1150 JScript *This = impl_from_IActiveScriptParseProcedure2(iface);
1151 return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
1154 static ULONG WINAPI JScriptParseProcedure_AddRef(IActiveScriptParseProcedure2 *iface)
1156 JScript *This = impl_from_IActiveScriptParseProcedure2(iface);
1157 return IActiveScript_AddRef(&This->IActiveScript_iface);
1160 static ULONG WINAPI JScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface)
1162 JScript *This = impl_from_IActiveScriptParseProcedure2(iface);
1163 return IActiveScript_Release(&This->IActiveScript_iface);
1166 static HRESULT WINAPI JScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2 *iface,
1167 LPCOLESTR pstrCode, LPCOLESTR pstrFormalParams, LPCOLESTR pstrProcedureName,
1168 LPCOLESTR pstrItemName, IUnknown *punkContext, LPCOLESTR pstrDelimiter,
1169 CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags, IDispatch **ppdisp)
1171 JScript *This = impl_from_IActiveScriptParseProcedure2(iface);
1172 named_item_t *item = NULL;
1173 bytecode_t *code;
1174 jsdisp_t *dispex;
1175 jsexcept_t ei;
1176 HRESULT hres;
1178 TRACE("(%p)->(%s %s %s %s %p %s %s %u %x %p)\n", This, debugstr_w(pstrCode), debugstr_w(pstrFormalParams),
1179 debugstr_w(pstrProcedureName), debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
1180 wine_dbgstr_longlong(dwSourceContextCookie), ulStartingLineNumber, dwFlags, ppdisp);
1182 if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED)
1183 return E_UNEXPECTED;
1185 if(pstrItemName) {
1186 item = lookup_named_item(This->ctx, pstrItemName, 0);
1187 if(!item) {
1188 WARN("Unknown context %s\n", debugstr_w(pstrItemName));
1189 return E_INVALIDARG;
1191 if(!item->script_obj) item = NULL;
1194 enter_script(This->ctx, &ei);
1195 hres = compile_script(This->ctx, pstrCode, dwSourceContextCookie, ulStartingLineNumber, pstrFormalParams,
1196 pstrDelimiter, FALSE, This->is_encode, item, &code);
1197 if(SUCCEEDED(hres))
1198 hres = create_source_function(This->ctx, code, &code->global_code, NULL, &dispex);
1199 release_bytecode(code);
1200 hres = leave_script(This->ctx, hres);
1201 if(FAILED(hres))
1202 return hres;
1204 *ppdisp = to_disp(dispex);
1205 return S_OK;
1208 static const IActiveScriptParseProcedure2Vtbl JScriptParseProcedureVtbl = {
1209 JScriptParseProcedure_QueryInterface,
1210 JScriptParseProcedure_AddRef,
1211 JScriptParseProcedure_Release,
1212 JScriptParseProcedure_ParseProcedureText,
1215 static inline JScript *impl_from_IActiveScriptProperty(IActiveScriptProperty *iface)
1217 return CONTAINING_RECORD(iface, JScript, IActiveScriptProperty_iface);
1220 static HRESULT WINAPI JScriptProperty_QueryInterface(IActiveScriptProperty *iface, REFIID riid, void **ppv)
1222 JScript *This = impl_from_IActiveScriptProperty(iface);
1223 return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
1226 static ULONG WINAPI JScriptProperty_AddRef(IActiveScriptProperty *iface)
1228 JScript *This = impl_from_IActiveScriptProperty(iface);
1229 return IActiveScript_AddRef(&This->IActiveScript_iface);
1232 static ULONG WINAPI JScriptProperty_Release(IActiveScriptProperty *iface)
1234 JScript *This = impl_from_IActiveScriptProperty(iface);
1235 return IActiveScript_Release(&This->IActiveScript_iface);
1238 static HRESULT WINAPI JScriptProperty_GetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
1239 VARIANT *pvarIndex, VARIANT *pvarValue)
1241 JScript *This = impl_from_IActiveScriptProperty(iface);
1242 FIXME("(%p)->(%x %p %p)\n", This, dwProperty, pvarIndex, pvarValue);
1243 return E_NOTIMPL;
1246 static HRESULT WINAPI JScriptProperty_SetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
1247 VARIANT *pvarIndex, VARIANT *pvarValue)
1249 JScript *This = impl_from_IActiveScriptProperty(iface);
1251 TRACE("(%p)->(%x %s %s)\n", This, dwProperty, debugstr_variant(pvarIndex), debugstr_variant(pvarValue));
1253 if(pvarIndex)
1254 FIXME("unsupported pvarIndex\n");
1256 switch(dwProperty) {
1257 case SCRIPTPROP_INVOKEVERSIONING:
1258 if(V_VT(pvarValue) != VT_I4 || V_I4(pvarValue) < 0
1259 || (V_I4(pvarValue) > 15 && !(V_I4(pvarValue) & SCRIPTLANGUAGEVERSION_HTML))) {
1260 WARN("invalid value %s\n", debugstr_variant(pvarValue));
1261 return E_INVALIDARG;
1264 This->version = V_I4(pvarValue) & 0x1ff;
1265 This->html_mode = (V_I4(pvarValue) & SCRIPTLANGUAGEVERSION_HTML) != 0;
1266 break;
1267 default:
1268 FIXME("Unimplemented property %x\n", dwProperty);
1269 return E_NOTIMPL;
1272 return S_OK;
1275 static const IActiveScriptPropertyVtbl JScriptPropertyVtbl = {
1276 JScriptProperty_QueryInterface,
1277 JScriptProperty_AddRef,
1278 JScriptProperty_Release,
1279 JScriptProperty_GetProperty,
1280 JScriptProperty_SetProperty
1283 static inline JScript *impl_from_IObjectSafety(IObjectSafety *iface)
1285 return CONTAINING_RECORD(iface, JScript, IObjectSafety_iface);
1288 static HRESULT WINAPI JScriptSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
1290 JScript *This = impl_from_IObjectSafety(iface);
1291 return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
1294 static ULONG WINAPI JScriptSafety_AddRef(IObjectSafety *iface)
1296 JScript *This = impl_from_IObjectSafety(iface);
1297 return IActiveScript_AddRef(&This->IActiveScript_iface);
1300 static ULONG WINAPI JScriptSafety_Release(IObjectSafety *iface)
1302 JScript *This = impl_from_IObjectSafety(iface);
1303 return IActiveScript_Release(&This->IActiveScript_iface);
1306 #define SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER)
1308 static HRESULT WINAPI JScriptSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1309 DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
1311 JScript *This = impl_from_IObjectSafety(iface);
1313 TRACE("(%p)->(%s %p %p)\n", This, debugstr_guid(riid), pdwSupportedOptions, pdwEnabledOptions);
1315 if(!pdwSupportedOptions || !pdwEnabledOptions)
1316 return E_POINTER;
1318 *pdwSupportedOptions = SUPPORTED_OPTIONS;
1319 *pdwEnabledOptions = This->safeopt;
1321 return S_OK;
1324 static HRESULT WINAPI JScriptSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1325 DWORD dwOptionSetMask, DWORD dwEnabledOptions)
1327 JScript *This = impl_from_IObjectSafety(iface);
1329 TRACE("(%p)->(%s %x %x)\n", This, debugstr_guid(riid), dwOptionSetMask, dwEnabledOptions);
1331 if(dwOptionSetMask & ~SUPPORTED_OPTIONS)
1332 return E_FAIL;
1334 This->safeopt = (dwEnabledOptions & dwOptionSetMask) | (This->safeopt & ~dwOptionSetMask) | INTERFACE_USES_DISPEX;
1335 return S_OK;
1338 static const IObjectSafetyVtbl JScriptSafetyVtbl = {
1339 JScriptSafety_QueryInterface,
1340 JScriptSafety_AddRef,
1341 JScriptSafety_Release,
1342 JScriptSafety_GetInterfaceSafetyOptions,
1343 JScriptSafety_SetInterfaceSafetyOptions
1346 static inline JScript *impl_from_IVariantChangeType(IVariantChangeType *iface)
1348 return CONTAINING_RECORD(iface, JScript, IVariantChangeType_iface);
1351 static HRESULT WINAPI VariantChangeType_QueryInterface(IVariantChangeType *iface, REFIID riid, void **ppv)
1353 JScript *This = impl_from_IVariantChangeType(iface);
1354 return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
1357 static ULONG WINAPI VariantChangeType_AddRef(IVariantChangeType *iface)
1359 JScript *This = impl_from_IVariantChangeType(iface);
1360 return IActiveScript_AddRef(&This->IActiveScript_iface);
1363 static ULONG WINAPI VariantChangeType_Release(IVariantChangeType *iface)
1365 JScript *This = impl_from_IVariantChangeType(iface);
1366 return IActiveScript_Release(&This->IActiveScript_iface);
1369 static HRESULT WINAPI VariantChangeType_ChangeType(IVariantChangeType *iface, VARIANT *dst, VARIANT *src, LCID lcid, VARTYPE vt)
1371 JScript *This = impl_from_IVariantChangeType(iface);
1372 jsexcept_t ei;
1373 VARIANT res;
1374 HRESULT hres;
1376 TRACE("(%p)->(%p %s %x %s)\n", This, dst, debugstr_variant(src), lcid, debugstr_vt(vt));
1378 if(!This->ctx) {
1379 FIXME("Object uninitialized\n");
1380 return E_UNEXPECTED;
1383 enter_script(This->ctx, &ei);
1384 hres = variant_change_type(This->ctx, &res, src, vt);
1385 hres = leave_script(This->ctx, hres);
1386 if(FAILED(hres))
1387 return hres;
1389 hres = VariantClear(dst);
1390 if(FAILED(hres)) {
1391 VariantClear(&res);
1392 return hres;
1395 *dst = res;
1396 return S_OK;
1399 static const IVariantChangeTypeVtbl VariantChangeTypeVtbl = {
1400 VariantChangeType_QueryInterface,
1401 VariantChangeType_AddRef,
1402 VariantChangeType_Release,
1403 VariantChangeType_ChangeType
1406 HRESULT create_jscript_object(BOOL is_encode, REFIID riid, void **ppv)
1408 JScript *ret;
1409 HRESULT hres;
1411 ret = heap_alloc_zero(sizeof(*ret));
1412 if(!ret)
1413 return E_OUTOFMEMORY;
1415 lock_module();
1417 ret->IActiveScript_iface.lpVtbl = &JScriptVtbl;
1418 ret->IActiveScriptParse_iface.lpVtbl = &JScriptParseVtbl;
1419 ret->IActiveScriptParseProcedure2_iface.lpVtbl = &JScriptParseProcedureVtbl;
1420 ret->IActiveScriptProperty_iface.lpVtbl = &JScriptPropertyVtbl;
1421 ret->IObjectSafety_iface.lpVtbl = &JScriptSafetyVtbl;
1422 ret->IVariantChangeType_iface.lpVtbl = &VariantChangeTypeVtbl;
1423 ret->ref = 1;
1424 ret->safeopt = INTERFACE_USES_DISPEX;
1425 ret->is_encode = is_encode;
1426 list_init(&ret->persistent_code);
1427 list_init(&ret->queued_code);
1429 hres = IActiveScript_QueryInterface(&ret->IActiveScript_iface, riid, ppv);
1430 IActiveScript_Release(&ret->IActiveScript_iface);
1431 return hres;