jscript: Added global object implementation.
This commit is contained in:
parent
2bbd9d4105
commit
ca2b797f6a
|
@ -10,6 +10,7 @@ RC_SRCS = rsrc.rc
|
|||
C_SRCS = \
|
||||
dispex.c \
|
||||
engine.c \
|
||||
global.c \
|
||||
jscript.c \
|
||||
jscript_main.c \
|
||||
jsutils.c \
|
||||
|
|
|
@ -203,7 +203,12 @@ static HRESULT identifier_eval(exec_ctx_t *ctx, BSTR identifier, DWORD flags, ex
|
|||
TRACE("%s\n", debugstr_w(identifier));
|
||||
|
||||
/* FIXME: scope chain */
|
||||
/* FIXME: global */
|
||||
|
||||
hres = dispex_get_id(_IDispatchEx_(ctx->parser->script->global), identifier, 0, &id);
|
||||
if(SUCCEEDED(hres)) {
|
||||
exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(ctx->parser->script->global), id);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
for(item = ctx->parser->script->named_items; item; item = item->next) {
|
||||
hres = disp_get_id(item->disp, identifier, 0, &id);
|
||||
|
|
|
@ -0,0 +1,289 @@
|
|||
/*
|
||||
* Copyright 2008 Jacek Caban for CodeWeavers
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include "jscript.h"
|
||||
|
||||
#include "wine/debug.h"
|
||||
|
||||
WINE_DEFAULT_DEBUG_CHANNEL(jscript);
|
||||
|
||||
static const WCHAR NaNW[] = {'N','a','N',0};
|
||||
static const WCHAR InfinityW[] = {'I','n','f','i','n','i','t','y',0};
|
||||
static const WCHAR ArrayW[] = {'A','r','r','a','y',0};
|
||||
static const WCHAR BooleanW[] = {'B','o','o','l','e','a','n',0};
|
||||
static const WCHAR DateW[] = {'D','a','t','e',0};
|
||||
static const WCHAR FunctionW[] = {'F','u','n','c','t','i','o','n',0};
|
||||
static const WCHAR NumberW[] = {'N','u','m','b','e','r',0};
|
||||
static const WCHAR ObjectW[] = {'O','b','j','e','c','t',0};
|
||||
static const WCHAR StringW[] = {'S','t','r','i','n','g',0};
|
||||
static const WCHAR RegExpW[] = {'R','e','g','E','x','p',0};
|
||||
static const WCHAR ActiveXObjectW[] = {'A','c','t','i','v','e','X','O','b','j','e','c','t',0};
|
||||
static const WCHAR VBArrayW[] = {'V','B','A','r','r','a','y',0};
|
||||
static const WCHAR EnumeratorW[] = {'E','n','u','m','e','r','a','t','o','r',0};
|
||||
static const WCHAR escapeW[] = {'e','s','c','a','p','e',0};
|
||||
static const WCHAR evalW[] = {'e','v','a','l',0};
|
||||
static const WCHAR isNaNW[] = {'i','s','N','a','N',0};
|
||||
static const WCHAR isFiniteW[] = {'i','s','F','i','n','i','t','e',0};
|
||||
static const WCHAR parseIntW[] = {'p','a','r','s','e','I','n','t',0};
|
||||
static const WCHAR parseFloatW[] = {'p','a','r','s','e','F','l','o','a','t',0};
|
||||
static const WCHAR unescapeW[] = {'u','n','e','s','c','a','p','e',0};
|
||||
static const WCHAR GetObjectW[] = {'G','e','t','O','b','j','e','c','t',0};
|
||||
static const WCHAR ScriptEngineW[] = {'S','c','r','i','p','t','E','n','g','i','n','e',0};
|
||||
static const WCHAR ScriptEngineMajorVersionW[] =
|
||||
{'S','c','r','i','p','t','E','n','g','i','n','e','M','a','j','o','r','V','e','r','s','i','o','n',0};
|
||||
static const WCHAR ScriptEngineMinorVersionW[] =
|
||||
{'S','c','r','i','p','t','E','n','g','i','n','e','M','i','n','o','r','V','e','r','s','i','o','n',0};
|
||||
static const WCHAR ScriptEngineBuildVersionW[] =
|
||||
{'S','c','r','i','p','t','E','n','g','i','n','e','B','u','i','l','d','V','e','r','s','i','o','n',0};
|
||||
static const WCHAR CollectGarbageW[] = {'C','o','l','l','e','c','t','G','a','r','b','a','g','e',0};
|
||||
static const WCHAR MathW[] = {'M','a','t','h',0};
|
||||
|
||||
static HRESULT JSGlobal_NaN(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_Infinity(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_Array(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_Boolean(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_Date(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_Function(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_Number(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_Object(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_String(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_RegExp(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_ActiveXObject(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_VBArray(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_Enumerator(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_escape(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_eval(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_isNaN(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_isFinite(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_parseInt(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_parseFloat(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_unescape(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_GetObject(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_ScriptEngine(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_ScriptEngineMajorVersion(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_ScriptEngineMinorVersion(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_ScriptEngineBuildVersion(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_CollectGarbage(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_Math(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static const builtin_prop_t JSGlobal_props[] = {
|
||||
{ActiveXObjectW, JSGlobal_ActiveXObject, PROPF_METHOD},
|
||||
{ArrayW, JSGlobal_Array, PROPF_CONSTR},
|
||||
{BooleanW, JSGlobal_Boolean, PROPF_CONSTR},
|
||||
{CollectGarbageW, JSGlobal_CollectGarbage, PROPF_METHOD},
|
||||
{DateW, JSGlobal_Date, PROPF_CONSTR},
|
||||
{EnumeratorW, JSGlobal_Enumerator, PROPF_METHOD},
|
||||
{FunctionW, JSGlobal_Function, PROPF_CONSTR},
|
||||
{GetObjectW, JSGlobal_GetObject, PROPF_METHOD},
|
||||
{InfinityW, JSGlobal_Infinity, 0},
|
||||
{MathW, JSGlobal_Math, 0},
|
||||
{NaNW, JSGlobal_NaN, 0},
|
||||
{NumberW, JSGlobal_Number, PROPF_CONSTR},
|
||||
{ObjectW, JSGlobal_Object, PROPF_CONSTR},
|
||||
{RegExpW, JSGlobal_RegExp, PROPF_CONSTR},
|
||||
{ScriptEngineBuildVersionW, JSGlobal_ScriptEngineBuildVersion, PROPF_METHOD},
|
||||
{ScriptEngineMajorVersionW, JSGlobal_ScriptEngineMajorVersion, PROPF_METHOD},
|
||||
{ScriptEngineMinorVersionW, JSGlobal_ScriptEngineMinorVersion, PROPF_METHOD},
|
||||
{ScriptEngineW, JSGlobal_ScriptEngine, PROPF_METHOD},
|
||||
{StringW, JSGlobal_String, PROPF_CONSTR},
|
||||
{VBArrayW, JSGlobal_VBArray, PROPF_METHOD},
|
||||
{escapeW, JSGlobal_escape, PROPF_METHOD},
|
||||
{evalW, JSGlobal_eval, PROPF_METHOD},
|
||||
{isFiniteW, JSGlobal_isFinite, PROPF_METHOD},
|
||||
{isNaNW, JSGlobal_isNaN, PROPF_METHOD},
|
||||
{parseFloatW, JSGlobal_parseFloat, PROPF_METHOD},
|
||||
{parseIntW, JSGlobal_parseInt, PROPF_METHOD|2},
|
||||
{unescapeW, JSGlobal_unescape, PROPF_METHOD}
|
||||
};
|
||||
|
||||
static const builtin_info_t JSGlobal_info = {
|
||||
JSCLASS_GLOBAL,
|
||||
{NULL, NULL, 0},
|
||||
sizeof(JSGlobal_props)/sizeof(*JSGlobal_props),
|
||||
JSGlobal_props,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
HRESULT init_global(script_ctx_t *ctx)
|
||||
{
|
||||
if(ctx->global)
|
||||
return S_OK;
|
||||
|
||||
return create_dispex(ctx, &JSGlobal_info, NULL, &ctx->global);
|
||||
}
|
|
@ -216,9 +216,15 @@ static HRESULT WINAPI JScript_SetScriptSite(IActiveScript *iface,
|
|||
return hres;
|
||||
}
|
||||
|
||||
if(!This->ctx->script_disp) {
|
||||
hres = create_dispex(This->ctx, NULL, NULL, &This->ctx->script_disp);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
}
|
||||
|
||||
hres = init_global(This->ctx);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
if(InterlockedCompareExchange(&This->thread_id, GetCurrentThreadId(), 0))
|
||||
return E_UNEXPECTED;
|
||||
|
@ -306,6 +312,11 @@ static HRESULT WINAPI JScript_Close(IActiveScript *iface)
|
|||
IDispatchEx_Release(_IDispatchEx_(This->ctx->script_disp));
|
||||
This->ctx->script_disp = NULL;
|
||||
}
|
||||
|
||||
if(This->ctx->global) {
|
||||
IDispatchEx_Release(_IDispatchEx_(This->ctx->global));
|
||||
This->ctx->global = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(This->site) {
|
||||
|
|
|
@ -48,7 +48,8 @@ typedef struct DispatchEx DispatchEx;
|
|||
#define PROPF_CONSTR 0x0400
|
||||
|
||||
typedef enum {
|
||||
JSCLASS_NONE
|
||||
JSCLASS_NONE,
|
||||
JSCLASS_GLOBAL
|
||||
} jsclass_t;
|
||||
|
||||
typedef HRESULT (*builtin_invoke_t)(DispatchEx*,LCID,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
|
||||
|
@ -105,6 +106,7 @@ struct _script_ctx_t {
|
|||
LCID lcid;
|
||||
|
||||
DispatchEx *script_disp;
|
||||
DispatchEx *global;
|
||||
};
|
||||
|
||||
void script_release(script_ctx_t*);
|
||||
|
@ -114,6 +116,8 @@ static inline void script_addref(script_ctx_t *ctx)
|
|||
ctx->ref++;
|
||||
}
|
||||
|
||||
HRESULT init_global(script_ctx_t*);
|
||||
|
||||
const char *debugstr_variant(const VARIANT*);
|
||||
|
||||
HRESULT WINAPI JScriptFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**);
|
||||
|
|
Loading…
Reference in New Issue