2008-09-10 00:33:15 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2012-11-14 14:49:46 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
2008-09-10 00:33:15 +00:00
|
|
|
#include "jscript.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(jscript);
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
static HRESULT Object_toString(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:15 +00:00
|
|
|
{
|
2010-09-06 14:11:49 +00:00
|
|
|
jsdisp_t *jsdisp;
|
2009-09-23 14:19:58 +00:00
|
|
|
const WCHAR *str;
|
2022-03-17 16:25:39 +00:00
|
|
|
IDispatch *disp;
|
|
|
|
HRESULT hres;
|
2009-09-23 14:18:39 +00:00
|
|
|
|
2009-07-15 23:16:15 +00:00
|
|
|
/* Keep in sync with jsclass_t enum */
|
2020-03-20 13:35:27 +00:00
|
|
|
static const WCHAR *names[] = {
|
|
|
|
NULL,
|
|
|
|
L"[object Array]",
|
|
|
|
L"[object Boolean]",
|
|
|
|
L"[object Date]",
|
|
|
|
L"[object Object]",
|
|
|
|
L"[object Error]",
|
|
|
|
L"[object Function]",
|
|
|
|
NULL,
|
|
|
|
L"[object Math]",
|
|
|
|
L"[object Number]",
|
|
|
|
L"[object Object]",
|
|
|
|
L"[object RegExp]",
|
|
|
|
L"[object String]",
|
|
|
|
L"[object Object]",
|
|
|
|
L"[object Object]",
|
2021-04-21 23:47:35 +00:00
|
|
|
L"[object Object]",
|
2021-04-27 16:11:37 +00:00
|
|
|
L"[object Object]",
|
2020-03-20 13:35:27 +00:00
|
|
|
L"[object Object]"
|
|
|
|
};
|
2009-07-15 23:16:15 +00:00
|
|
|
|
2009-07-07 11:45:38 +00:00
|
|
|
TRACE("\n");
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
if(is_undefined(vthis) || is_null(vthis)) {
|
2022-03-18 15:24:09 +00:00
|
|
|
if(ctx->version < SCRIPTLANGUAGEVERSION_ES5)
|
|
|
|
str = L"[object Object]";
|
|
|
|
else
|
2022-03-18 15:24:11 +00:00
|
|
|
str = is_null(vthis) ? L"[object Null]" : L"[object Undefined]";
|
2022-03-17 16:25:39 +00:00
|
|
|
goto set_output;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = to_object(ctx, vthis, &disp);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
jsdisp = to_jsdisp(disp);
|
2009-09-23 14:19:58 +00:00
|
|
|
if(!jsdisp) {
|
2020-03-20 13:35:27 +00:00
|
|
|
str = L"[object Object]";
|
2009-09-23 14:19:58 +00:00
|
|
|
}else if(names[jsdisp->builtin_info->class]) {
|
|
|
|
str = names[jsdisp->builtin_info->class];
|
|
|
|
}else {
|
2012-11-14 14:49:46 +00:00
|
|
|
assert(jsdisp->builtin_info->class != JSCLASS_NONE);
|
2020-03-17 04:36:38 +00:00
|
|
|
FIXME("jsdisp->builtin_info->class = %d\n", jsdisp->builtin_info->class);
|
2022-03-17 16:25:39 +00:00
|
|
|
hres = E_FAIL;
|
2009-07-15 23:16:15 +00:00
|
|
|
}
|
2022-03-17 16:25:39 +00:00
|
|
|
IDispatch_Release(disp);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2009-07-15 23:16:15 +00:00
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
set_output:
|
2012-09-17 13:16:20 +00:00
|
|
|
if(r) {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_t *ret;
|
2020-03-20 13:35:27 +00:00
|
|
|
ret = jsstr_alloc(str);
|
2016-09-07 08:50:11 +00:00
|
|
|
if(!ret)
|
2009-07-07 11:45:38 +00:00
|
|
|
return E_OUTOFMEMORY;
|
2012-09-17 13:16:20 +00:00
|
|
|
*r = jsval_string(ret);
|
2009-07-07 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2008-09-10 00:33:15 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
static HRESULT Object_toLocaleString(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:15 +00:00
|
|
|
{
|
2022-03-17 16:25:39 +00:00
|
|
|
jsdisp_t *jsdisp;
|
|
|
|
IDispatch *disp;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2009-07-07 11:45:38 +00:00
|
|
|
TRACE("\n");
|
2009-08-12 10:48:58 +00:00
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
hres = to_object(ctx, vthis, &disp);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(!(jsdisp = to_jsdisp(disp))) {
|
2009-09-23 14:18:39 +00:00
|
|
|
FIXME("Host object this\n");
|
2022-03-17 16:25:39 +00:00
|
|
|
hres = E_FAIL;
|
|
|
|
goto done;
|
2009-09-23 14:18:39 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
hres = jsdisp_call_name(jsdisp, L"toString", DISPATCH_METHOD, 0, NULL, r);
|
|
|
|
done:
|
|
|
|
IDispatch_Release(disp);
|
|
|
|
return hres;
|
2008-09-10 00:33:15 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
static HRESULT Object_valueOf(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:15 +00:00
|
|
|
{
|
2022-03-17 16:25:39 +00:00
|
|
|
IDispatch *disp;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2009-07-07 12:07:47 +00:00
|
|
|
TRACE("\n");
|
|
|
|
|
2022-03-24 15:31:06 +00:00
|
|
|
if(is_null_disp(vthis)) {
|
|
|
|
if(r) *r = jsval_null_disp();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
hres = to_object(ctx, vthis, &disp);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(r)
|
|
|
|
*r = jsval_disp(disp);
|
|
|
|
else
|
|
|
|
IDispatch_Release(disp);
|
2009-07-07 12:07:47 +00:00
|
|
|
return S_OK;
|
2008-09-10 00:33:15 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
static HRESULT Object_hasOwnProperty(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:15 +00:00
|
|
|
{
|
2022-03-17 16:25:39 +00:00
|
|
|
IDispatchEx *dispex;
|
|
|
|
jsdisp_t *jsdisp;
|
|
|
|
IDispatch *disp;
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_t *name;
|
2011-09-02 10:24:12 +00:00
|
|
|
DISPID id;
|
2013-03-11 15:05:27 +00:00
|
|
|
BSTR bstr;
|
2011-09-02 10:24:12 +00:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
hres = to_object(ctx, vthis, &disp);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-06-25 12:08:38 +00:00
|
|
|
if(!argc) {
|
2012-09-17 13:16:20 +00:00
|
|
|
if(r)
|
|
|
|
*r = jsval_bool(FALSE);
|
2022-03-17 16:25:39 +00:00
|
|
|
goto done;
|
2011-09-02 10:24:12 +00:00
|
|
|
}
|
|
|
|
|
2012-09-18 17:01:49 +00:00
|
|
|
hres = to_string(ctx, argv[0], &name);
|
2011-09-02 10:24:12 +00:00
|
|
|
if(FAILED(hres))
|
2022-03-17 16:25:39 +00:00
|
|
|
goto done;
|
2011-09-02 10:24:12 +00:00
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
if((jsdisp = to_jsdisp(disp))) {
|
2018-05-10 17:20:06 +00:00
|
|
|
property_desc_t prop_desc;
|
2013-03-27 10:04:09 +00:00
|
|
|
const WCHAR *name_str;
|
2012-07-23 13:53:52 +00:00
|
|
|
|
2013-03-27 10:04:09 +00:00
|
|
|
name_str = jsstr_flatten(name);
|
2018-05-10 17:20:06 +00:00
|
|
|
if(!name_str) {
|
|
|
|
jsstr_release(name);
|
2022-03-17 16:25:39 +00:00
|
|
|
hres = E_OUTOFMEMORY;
|
|
|
|
goto done;
|
2018-05-10 17:20:06 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
hres = jsdisp_get_own_property(jsdisp, name_str, TRUE, &prop_desc);
|
2013-03-11 15:05:27 +00:00
|
|
|
jsstr_release(name);
|
2018-05-10 17:20:06 +00:00
|
|
|
if(FAILED(hres) && hres != DISP_E_UNKNOWNNAME)
|
2022-03-17 16:25:39 +00:00
|
|
|
goto done;
|
2012-07-23 13:53:52 +00:00
|
|
|
|
2018-05-10 17:20:06 +00:00
|
|
|
if(r) *r = jsval_bool(hres == S_OK);
|
2022-03-17 16:25:39 +00:00
|
|
|
hres = S_OK;
|
|
|
|
goto done;
|
2012-07-23 13:53:52 +00:00
|
|
|
}
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
|
2013-03-11 15:05:27 +00:00
|
|
|
bstr = SysAllocStringLen(NULL, jsstr_length(name));
|
|
|
|
if(bstr)
|
|
|
|
jsstr_flush(name, bstr);
|
|
|
|
jsstr_release(name);
|
2022-03-17 16:25:39 +00:00
|
|
|
if(!bstr) {
|
|
|
|
hres = E_OUTOFMEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
2011-09-02 10:24:12 +00:00
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = IDispatchEx_GetDispID(dispex, bstr, make_grfdex(ctx, fdexNameCaseSensitive), &id);
|
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
}else {
|
|
|
|
hres = IDispatch_GetIDsOfNames(disp, &IID_NULL, &bstr, 1, ctx->lcid, &id);
|
|
|
|
}
|
2013-03-11 15:05:27 +00:00
|
|
|
SysFreeString(bstr);
|
2012-09-17 13:16:20 +00:00
|
|
|
if(r)
|
|
|
|
*r = jsval_bool(SUCCEEDED(hres));
|
2022-03-17 16:25:39 +00:00
|
|
|
hres = S_OK;
|
|
|
|
done:
|
|
|
|
IDispatch_Release(disp);
|
|
|
|
return hres;
|
2008-09-10 00:33:15 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
static HRESULT Object_propertyIsEnumerable(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:15 +00:00
|
|
|
{
|
2018-05-10 17:20:16 +00:00
|
|
|
property_desc_t prop_desc;
|
2013-03-27 10:04:09 +00:00
|
|
|
const WCHAR *name;
|
|
|
|
jsstr_t *name_str;
|
2022-03-17 16:25:39 +00:00
|
|
|
jsdisp_t *jsdisp;
|
|
|
|
IDispatch *disp;
|
2012-11-05 14:04:19 +00:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
hres = to_object(ctx, vthis, &disp);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-11-05 14:04:19 +00:00
|
|
|
if(argc != 1) {
|
|
|
|
FIXME("argc %d not supported\n", argc);
|
2022-03-17 16:25:39 +00:00
|
|
|
hres = E_NOTIMPL;
|
|
|
|
goto done;
|
2012-11-05 14:04:19 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
if(!(jsdisp = to_jsdisp(disp))) {
|
2012-11-05 14:04:19 +00:00
|
|
|
FIXME("Host object this\n");
|
2022-03-17 16:25:39 +00:00
|
|
|
hres = E_FAIL;
|
|
|
|
goto done;
|
2012-11-05 14:04:19 +00:00
|
|
|
}
|
|
|
|
|
2013-03-27 10:04:09 +00:00
|
|
|
hres = to_flat_string(ctx, argv[0], &name_str, &name);
|
2012-11-05 14:04:19 +00:00
|
|
|
if(FAILED(hres))
|
2022-03-17 16:25:39 +00:00
|
|
|
goto done;
|
2012-11-05 14:04:19 +00:00
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
hres = jsdisp_get_own_property(jsdisp, name, TRUE, &prop_desc);
|
2013-03-27 10:04:09 +00:00
|
|
|
jsstr_release(name_str);
|
2018-05-10 17:20:16 +00:00
|
|
|
if(FAILED(hres) && hres != DISP_E_UNKNOWNNAME)
|
2022-03-17 16:25:39 +00:00
|
|
|
goto done;
|
2012-11-05 14:04:19 +00:00
|
|
|
|
|
|
|
if(r)
|
2018-05-10 17:20:16 +00:00
|
|
|
*r = jsval_bool(hres == S_OK && (prop_desc.flags & PROPF_ENUMERABLE) != 0);
|
2022-03-17 16:25:39 +00:00
|
|
|
hres = S_OK;
|
|
|
|
done:
|
|
|
|
IDispatch_Release(disp);
|
|
|
|
return hres;
|
2008-09-10 00:33:15 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
static HRESULT Object_isPrototypeOf(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:15 +00:00
|
|
|
{
|
2022-03-17 16:25:39 +00:00
|
|
|
jsdisp_t *jsthis, *jsdisp;
|
|
|
|
IDispatch *disp;
|
2021-11-02 18:07:10 +00:00
|
|
|
BOOL ret = FALSE;
|
2022-03-17 16:25:39 +00:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = to_object(ctx, vthis, &disp);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2021-11-02 18:07:10 +00:00
|
|
|
|
|
|
|
if(!r)
|
2022-03-17 16:25:39 +00:00
|
|
|
goto done;
|
2021-11-02 18:07:10 +00:00
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
if(argc && (jsthis = to_jsdisp(disp)) && is_object_instance(argv[0]) &&
|
|
|
|
(jsdisp = to_jsdisp(get_object(argv[0])))) {
|
2021-11-02 18:07:10 +00:00
|
|
|
while(jsdisp->prototype) {
|
2022-03-17 16:25:39 +00:00
|
|
|
if(jsdisp->prototype == jsthis) {
|
2021-11-02 18:07:10 +00:00
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
jsdisp = jsdisp->prototype;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*r = jsval_bool(ret);
|
2022-03-17 16:25:39 +00:00
|
|
|
done:
|
|
|
|
IDispatch_Release(disp);
|
|
|
|
return hres;
|
2008-09-10 00:33:15 +00:00
|
|
|
}
|
|
|
|
|
2022-03-25 14:45:38 +00:00
|
|
|
static HRESULT Object_defineGetter(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
|
|
|
|
{
|
|
|
|
property_desc_t desc;
|
|
|
|
const WCHAR *name;
|
|
|
|
jsstr_t *name_str;
|
|
|
|
jsdisp_t *jsthis;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if(!is_object_instance(vthis) || !(jsthis = to_jsdisp(get_object(vthis))))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if(argc < 2 || !is_object_instance(argv[1]))
|
|
|
|
return JS_E_FUNCTION_EXPECTED;
|
|
|
|
|
|
|
|
desc.getter = to_jsdisp(get_object(argv[1]));
|
|
|
|
if(!desc.getter) {
|
|
|
|
FIXME("getter is not JS object\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
/* FIXME: Check IsCallable */
|
|
|
|
|
|
|
|
hres = to_flat_string(ctx, argv[0], &name_str, &name);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
desc.flags = desc.mask = PROPF_CONFIGURABLE | PROPF_ENUMERABLE;
|
|
|
|
desc.explicit_getter = TRUE;
|
|
|
|
desc.explicit_setter = FALSE;
|
|
|
|
desc.explicit_value = FALSE;
|
|
|
|
desc.setter = NULL;
|
|
|
|
hres = jsdisp_define_property(jsthis, name, &desc);
|
|
|
|
|
|
|
|
jsstr_release(name_str);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
done:
|
|
|
|
if(r)
|
|
|
|
*r = jsval_undefined();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2022-03-25 14:45:39 +00:00
|
|
|
static HRESULT Object_defineSetter(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
|
|
|
|
{
|
|
|
|
property_desc_t desc;
|
|
|
|
const WCHAR *name;
|
|
|
|
jsstr_t *name_str;
|
|
|
|
jsdisp_t *jsthis;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if(!is_object_instance(vthis) || !(jsthis = to_jsdisp(get_object(vthis))))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if(argc < 2 || !is_object_instance(argv[1]))
|
|
|
|
return JS_E_FUNCTION_EXPECTED;
|
|
|
|
|
|
|
|
desc.setter = to_jsdisp(get_object(argv[1]));
|
|
|
|
if(!desc.setter) {
|
|
|
|
FIXME("setter is not JS object\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
/* FIXME: Check IsCallable */
|
|
|
|
|
|
|
|
hres = to_flat_string(ctx, argv[0], &name_str, &name);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
desc.flags = desc.mask = PROPF_CONFIGURABLE | PROPF_ENUMERABLE;
|
|
|
|
desc.explicit_getter = FALSE;
|
|
|
|
desc.explicit_setter = TRUE;
|
|
|
|
desc.explicit_value = FALSE;
|
|
|
|
desc.getter = NULL;
|
|
|
|
hres = jsdisp_define_property(jsthis, name, &desc);
|
|
|
|
|
|
|
|
jsstr_release(name_str);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
done:
|
|
|
|
if(r)
|
|
|
|
*r = jsval_undefined();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2022-03-21 15:58:30 +00:00
|
|
|
HRESULT Object_get_proto_(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
|
2021-11-02 18:07:11 +00:00
|
|
|
{
|
2022-03-21 15:58:30 +00:00
|
|
|
jsdisp_t *jsthis;
|
|
|
|
IDispatch *disp;
|
|
|
|
HRESULT hres;
|
2021-11-02 18:07:11 +00:00
|
|
|
|
2022-03-21 15:58:30 +00:00
|
|
|
TRACE("%s\n", debugstr_jsval(vthis));
|
|
|
|
|
|
|
|
hres = to_object(ctx, vthis, &disp);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(!r)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if(!(jsthis = to_jsdisp(disp))) {
|
|
|
|
FIXME("Host object this\n");
|
|
|
|
hres = E_FAIL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
*r = jsthis->prototype
|
|
|
|
? jsval_obj(jsdisp_addref(jsthis->prototype))
|
|
|
|
: jsval_null();
|
|
|
|
done:
|
|
|
|
IDispatch_Release(disp);
|
|
|
|
return hres;
|
2021-11-02 18:07:11 +00:00
|
|
|
}
|
|
|
|
|
2022-03-21 15:58:30 +00:00
|
|
|
HRESULT Object_set_proto_(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
|
2021-11-02 18:07:11 +00:00
|
|
|
{
|
2022-03-21 15:58:30 +00:00
|
|
|
jsdisp_t *jsthis, *proto;
|
|
|
|
HRESULT hres;
|
2021-11-02 18:07:11 +00:00
|
|
|
|
2022-03-21 15:58:30 +00:00
|
|
|
TRACE("%s\n", debugstr_jsval(vthis));
|
2021-11-02 18:07:11 +00:00
|
|
|
|
2022-03-21 15:58:30 +00:00
|
|
|
if(is_undefined(vthis) || is_null(vthis))
|
|
|
|
return JS_E_OBJECT_EXPECTED;
|
|
|
|
if(!argc) {
|
|
|
|
if(r)
|
|
|
|
*r = jsval_undefined();
|
|
|
|
return S_OK;
|
2021-11-02 18:07:11 +00:00
|
|
|
}
|
2022-03-21 15:58:30 +00:00
|
|
|
if(!is_object_instance(vthis) || !(jsthis = to_jsdisp(get_object(vthis))))
|
|
|
|
goto done;
|
2021-11-02 18:07:11 +00:00
|
|
|
|
2022-03-21 15:58:30 +00:00
|
|
|
if(is_null(argv[0])) {
|
|
|
|
proto = NULL;
|
|
|
|
}else if(is_object_instance(argv[0])) {
|
|
|
|
proto = to_jsdisp(get_object(argv[0]));
|
|
|
|
if(!proto) {
|
|
|
|
FIXME("Host object value\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}else
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
hres = jsdisp_change_prototype(jsthis, proto);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
done:
|
|
|
|
return r ? jsval_copy(argv[0], r) : S_OK;
|
2021-11-02 18:07:11 +00:00
|
|
|
}
|
|
|
|
|
2010-09-06 14:11:49 +00:00
|
|
|
static void Object_destructor(jsdisp_t *dispex)
|
2008-09-10 00:33:15 +00:00
|
|
|
{
|
|
|
|
heap_free(dispex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const builtin_prop_t Object_props[] = {
|
2022-03-25 14:45:38 +00:00
|
|
|
{L"__defineGetter__", Object_defineGetter, PROPF_METHOD|PROPF_ES6|2},
|
2022-03-25 14:45:39 +00:00
|
|
|
{L"__defineSetter__", Object_defineSetter, PROPF_METHOD|PROPF_ES6|2},
|
2020-03-23 20:30:09 +00:00
|
|
|
{L"hasOwnProperty", Object_hasOwnProperty, PROPF_METHOD|1},
|
|
|
|
{L"isPrototypeOf", Object_isPrototypeOf, PROPF_METHOD|1},
|
|
|
|
{L"propertyIsEnumerable", Object_propertyIsEnumerable, PROPF_METHOD|1},
|
|
|
|
{L"toLocaleString", Object_toLocaleString, PROPF_METHOD},
|
|
|
|
{L"toString", Object_toString, PROPF_METHOD},
|
|
|
|
{L"valueOf", Object_valueOf, PROPF_METHOD}
|
2008-09-10 00:33:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const builtin_info_t Object_info = {
|
|
|
|
JSCLASS_OBJECT,
|
2021-11-25 20:01:37 +00:00
|
|
|
NULL,
|
2018-07-09 18:59:12 +00:00
|
|
|
ARRAY_SIZE(Object_props),
|
2008-09-10 00:33:15 +00:00
|
|
|
Object_props,
|
|
|
|
Object_destructor,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2012-07-23 13:53:22 +00:00
|
|
|
static const builtin_info_t ObjectInst_info = {
|
|
|
|
JSCLASS_OBJECT,
|
2021-11-25 20:01:37 +00:00
|
|
|
NULL,
|
2012-07-23 13:53:22 +00:00
|
|
|
0, NULL,
|
|
|
|
Object_destructor,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2018-05-10 17:19:56 +00:00
|
|
|
static void release_property_descriptor(property_desc_t *desc)
|
|
|
|
{
|
2018-05-11 12:43:20 +00:00
|
|
|
if(desc->explicit_value)
|
|
|
|
jsval_release(desc->value);
|
|
|
|
if(desc->getter)
|
|
|
|
jsdisp_release(desc->getter);
|
|
|
|
if(desc->setter)
|
|
|
|
jsdisp_release(desc->setter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT to_property_descriptor(script_ctx_t *ctx, jsdisp_t *attr_obj, property_desc_t *desc)
|
|
|
|
{
|
|
|
|
DISPID id;
|
|
|
|
jsval_t v;
|
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
memset(desc, 0, sizeof(*desc));
|
|
|
|
desc->value = jsval_undefined();
|
|
|
|
|
2020-03-23 20:30:09 +00:00
|
|
|
hres = jsdisp_get_id(attr_obj, L"enumerable", 0, &id);
|
2018-05-11 12:43:20 +00:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
desc->mask |= PROPF_ENUMERABLE;
|
|
|
|
hres = jsdisp_propget(attr_obj, id, &v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
hres = to_boolean(v, &b);
|
|
|
|
jsval_release(v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
if(b)
|
|
|
|
desc->flags |= PROPF_ENUMERABLE;
|
|
|
|
}else if(hres != DISP_E_UNKNOWNNAME) {
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2020-03-23 20:30:09 +00:00
|
|
|
hres = jsdisp_get_id(attr_obj, L"configurable", 0, &id);
|
2018-05-11 12:43:20 +00:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
desc->mask |= PROPF_CONFIGURABLE;
|
|
|
|
hres = jsdisp_propget(attr_obj, id, &v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
hres = to_boolean(v, &b);
|
|
|
|
jsval_release(v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
if(b)
|
|
|
|
desc->flags |= PROPF_CONFIGURABLE;
|
|
|
|
}else if(hres != DISP_E_UNKNOWNNAME) {
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2020-03-23 20:30:09 +00:00
|
|
|
hres = jsdisp_get_id(attr_obj, L"value", 0, &id);
|
2018-05-11 12:43:20 +00:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = jsdisp_propget(attr_obj, id, &desc->value);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
desc->explicit_value = TRUE;
|
|
|
|
}else if(hres != DISP_E_UNKNOWNNAME) {
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2020-03-23 20:30:09 +00:00
|
|
|
hres = jsdisp_get_id(attr_obj, L"writable", 0, &id);
|
2018-05-11 12:43:20 +00:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
desc->mask |= PROPF_WRITABLE;
|
|
|
|
hres = jsdisp_propget(attr_obj, id, &v);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = to_boolean(v, &b);
|
|
|
|
jsval_release(v);
|
|
|
|
if(SUCCEEDED(hres) && b)
|
|
|
|
desc->flags |= PROPF_WRITABLE;
|
|
|
|
}
|
|
|
|
}else if(hres == DISP_E_UNKNOWNNAME) {
|
|
|
|
hres = S_OK;
|
|
|
|
}
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
release_property_descriptor(desc);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2020-03-23 20:30:09 +00:00
|
|
|
hres = jsdisp_get_id(attr_obj, L"get", 0, &id);
|
2018-05-11 12:43:20 +00:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
desc->explicit_getter = TRUE;
|
|
|
|
hres = jsdisp_propget(attr_obj, id, &v);
|
|
|
|
if(SUCCEEDED(hres) && !is_undefined(v)) {
|
|
|
|
if(!is_object_instance(v)) {
|
|
|
|
FIXME("getter is not an object\n");
|
|
|
|
jsval_release(v);
|
|
|
|
hres = E_FAIL;
|
|
|
|
}else {
|
|
|
|
/* FIXME: Check IsCallable */
|
|
|
|
desc->getter = to_jsdisp(get_object(v));
|
|
|
|
if(!desc->getter)
|
|
|
|
FIXME("getter is not JS object\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else if(hres == DISP_E_UNKNOWNNAME) {
|
|
|
|
hres = S_OK;
|
|
|
|
}
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
release_property_descriptor(desc);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2020-03-23 20:30:09 +00:00
|
|
|
hres = jsdisp_get_id(attr_obj, L"set", 0, &id);
|
2018-05-11 12:43:20 +00:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
desc->explicit_setter = TRUE;
|
|
|
|
hres = jsdisp_propget(attr_obj, id, &v);
|
|
|
|
if(SUCCEEDED(hres) && !is_undefined(v)) {
|
|
|
|
if(!is_object_instance(v)) {
|
|
|
|
FIXME("setter is not an object\n");
|
|
|
|
jsval_release(v);
|
|
|
|
hres = E_FAIL;
|
|
|
|
}else {
|
|
|
|
/* FIXME: Check IsCallable */
|
|
|
|
desc->setter = to_jsdisp(get_object(v));
|
|
|
|
if(!desc->setter)
|
|
|
|
FIXME("setter is not JS object\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else if(hres == DISP_E_UNKNOWNNAME) {
|
|
|
|
hres = S_OK;
|
|
|
|
}
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
release_property_descriptor(desc);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(desc->explicit_getter || desc->explicit_setter) {
|
|
|
|
if(desc->explicit_value)
|
2020-01-31 16:23:33 +00:00
|
|
|
hres = JS_E_PROP_DESC_MISMATCH;
|
2018-05-11 12:43:20 +00:00
|
|
|
else if(desc->mask & PROPF_WRITABLE)
|
2020-01-31 16:23:33 +00:00
|
|
|
hres = JS_E_INVALID_WRITABLE_PROP_DESC;
|
2018-05-11 12:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(FAILED(hres))
|
|
|
|
release_property_descriptor(desc);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2019-08-21 10:31:18 +00:00
|
|
|
static HRESULT jsdisp_define_properties(script_ctx_t *ctx, jsdisp_t *obj, jsval_t list_val)
|
|
|
|
{
|
|
|
|
DISPID id = DISPID_STARTENUM;
|
|
|
|
property_desc_t prop_desc;
|
|
|
|
IDispatch *list_disp;
|
|
|
|
jsdisp_t *list_obj, *desc_obj;
|
|
|
|
jsval_t desc_val;
|
|
|
|
BSTR name;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = to_object(ctx, list_val, &list_disp);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(!(list_obj = to_jsdisp(list_disp))) {
|
|
|
|
FIXME("non-JS list obj\n");
|
|
|
|
IDispatch_Release(list_disp);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(1) {
|
2021-04-20 17:11:56 +00:00
|
|
|
hres = jsdisp_next_prop(list_obj, id, JSDISP_ENUM_OWN_ENUMERABLE, &id);
|
2019-08-21 10:31:18 +00:00
|
|
|
if(hres != S_OK)
|
|
|
|
break;
|
|
|
|
|
|
|
|
hres = jsdisp_propget(list_obj, id, &desc_val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
2022-03-24 15:31:06 +00:00
|
|
|
if(!is_object_instance(desc_val) || !(desc_obj = to_jsdisp(get_object(desc_val)))) {
|
2019-08-21 10:31:18 +00:00
|
|
|
jsval_release(desc_val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = to_property_descriptor(ctx, desc_obj, &prop_desc);
|
|
|
|
jsdisp_release(desc_obj);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
|
|
|
hres = IDispatchEx_GetMemberName(&list_obj->IDispatchEx_iface, id, &name);
|
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
hres = jsdisp_define_property(obj, name, &prop_desc);
|
|
|
|
release_property_descriptor(&prop_desc);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsdisp_release(list_obj);
|
|
|
|
return FAILED(hres) ? hres : S_OK;
|
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
static HRESULT Object_defineProperty(script_ctx_t *ctx, jsval_t vthis, WORD flags,
|
2018-05-11 12:43:20 +00:00
|
|
|
unsigned argc, jsval_t *argv, jsval_t *r)
|
|
|
|
{
|
|
|
|
property_desc_t prop_desc;
|
|
|
|
jsdisp_t *obj, *attr_obj;
|
|
|
|
const WCHAR *name;
|
|
|
|
jsstr_t *name_str;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if(argc < 1 || !is_object_instance(argv[0]))
|
2020-01-31 16:23:33 +00:00
|
|
|
return JS_E_OBJECT_EXPECTED;
|
2018-05-11 12:43:20 +00:00
|
|
|
obj = to_jsdisp(get_object(argv[0]));
|
|
|
|
if(!obj) {
|
|
|
|
FIXME("not implemented non-JS object\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = to_flat_string(ctx, argc >= 2 ? argv[1] : jsval_undefined(), &name_str, &name);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(argc >= 3 && is_object_instance(argv[2])) {
|
|
|
|
attr_obj = to_jsdisp(get_object(argv[2]));
|
|
|
|
if(attr_obj) {
|
|
|
|
hres = to_property_descriptor(ctx, attr_obj, &prop_desc);
|
|
|
|
}else {
|
|
|
|
FIXME("not implemented non-JS object\n");
|
|
|
|
hres = E_NOTIMPL;
|
|
|
|
}
|
|
|
|
}else {
|
2020-01-31 16:23:33 +00:00
|
|
|
hres = JS_E_OBJECT_EXPECTED;
|
2018-05-11 12:43:20 +00:00
|
|
|
}
|
2021-08-04 22:28:49 +00:00
|
|
|
|
2018-05-11 12:43:20 +00:00
|
|
|
if(FAILED(hres))
|
2021-08-04 22:28:49 +00:00
|
|
|
{
|
|
|
|
jsstr_release(name_str);
|
2018-05-11 12:43:20 +00:00
|
|
|
return hres;
|
2021-08-04 22:28:49 +00:00
|
|
|
}
|
2018-05-11 12:43:20 +00:00
|
|
|
|
|
|
|
hres = jsdisp_define_property(obj, name, &prop_desc);
|
2021-08-04 22:28:49 +00:00
|
|
|
jsstr_release(name_str);
|
2018-05-11 12:43:20 +00:00
|
|
|
release_property_descriptor(&prop_desc);
|
2019-08-21 10:32:01 +00:00
|
|
|
if(SUCCEEDED(hres) && r)
|
|
|
|
*r = jsval_obj(jsdisp_addref(obj));
|
2018-05-11 12:43:20 +00:00
|
|
|
return hres;
|
2018-05-10 17:19:56 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
static HRESULT Object_defineProperties(script_ctx_t *ctx, jsval_t vthis, WORD flags,
|
2018-05-14 11:34:13 +00:00
|
|
|
unsigned argc, jsval_t *argv, jsval_t *r)
|
|
|
|
{
|
2019-08-21 10:31:18 +00:00
|
|
|
jsdisp_t *obj;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2022-03-24 15:31:06 +00:00
|
|
|
if(argc < 1 || !is_object_instance(argv[0]) || !(obj = to_jsdisp(get_object(argv[0])))) {
|
2019-08-21 10:31:18 +00:00
|
|
|
FIXME("not an object\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("%p\n", obj);
|
|
|
|
|
|
|
|
hres = jsdisp_define_properties(ctx, obj, argc >= 2 ? argv[1] : jsval_undefined());
|
|
|
|
if(SUCCEEDED(hres) && r)
|
|
|
|
*r = jsval_obj(jsdisp_addref(obj));
|
|
|
|
return hres;
|
2018-05-14 11:34:13 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
static HRESULT Object_getOwnPropertyDescriptor(script_ctx_t *ctx, jsval_t vthis, WORD flags,
|
2018-05-10 17:19:56 +00:00
|
|
|
unsigned argc, jsval_t *argv, jsval_t *r)
|
|
|
|
{
|
|
|
|
property_desc_t prop_desc;
|
|
|
|
jsdisp_t *obj, *desc_obj;
|
|
|
|
const WCHAR *name;
|
|
|
|
jsstr_t *name_str;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if(argc < 1 || !is_object_instance(argv[0]))
|
2020-01-31 16:23:33 +00:00
|
|
|
return JS_E_OBJECT_EXPECTED;
|
2018-05-10 17:19:56 +00:00
|
|
|
obj = to_jsdisp(get_object(argv[0]));
|
|
|
|
if(!obj) {
|
|
|
|
FIXME("not implemented non-JS object\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = to_flat_string(ctx, argc >= 2 ? argv[1] : jsval_undefined(), &name_str, &name);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = jsdisp_get_own_property(obj, name, FALSE, &prop_desc);
|
|
|
|
jsstr_release(name_str);
|
|
|
|
if(hres == DISP_E_UNKNOWNNAME) {
|
|
|
|
if(r) *r = jsval_undefined();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = create_object(ctx, NULL, &desc_obj);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2018-05-11 12:43:20 +00:00
|
|
|
if(prop_desc.explicit_getter || prop_desc.explicit_setter) {
|
2020-03-23 20:30:09 +00:00
|
|
|
hres = jsdisp_define_data_property(desc_obj, L"get", PROPF_ALL,
|
2018-06-11 13:54:26 +00:00
|
|
|
prop_desc.getter ? jsval_obj(prop_desc.getter) : jsval_undefined());
|
2018-05-11 12:43:20 +00:00
|
|
|
if(SUCCEEDED(hres))
|
2020-03-23 20:30:09 +00:00
|
|
|
hres = jsdisp_define_data_property(desc_obj, L"set", PROPF_ALL,
|
2018-06-11 13:54:26 +00:00
|
|
|
prop_desc.setter ? jsval_obj(prop_desc.setter) : jsval_undefined());
|
2018-05-11 12:43:20 +00:00
|
|
|
}else {
|
2020-03-23 20:30:09 +00:00
|
|
|
hres = jsdisp_propput_name(desc_obj, L"value", prop_desc.value);
|
2018-05-11 12:43:20 +00:00
|
|
|
if(SUCCEEDED(hres))
|
2020-03-23 20:30:09 +00:00
|
|
|
hres = jsdisp_define_data_property(desc_obj, L"writable", PROPF_ALL,
|
2018-06-11 13:54:26 +00:00
|
|
|
jsval_bool(!!(prop_desc.flags & PROPF_WRITABLE)));
|
2018-05-11 12:43:20 +00:00
|
|
|
}
|
2018-05-10 17:19:56 +00:00
|
|
|
if(SUCCEEDED(hres))
|
2020-03-23 20:30:09 +00:00
|
|
|
hres = jsdisp_define_data_property(desc_obj, L"enumerable", PROPF_ALL,
|
2018-06-11 13:54:26 +00:00
|
|
|
jsval_bool(!!(prop_desc.flags & PROPF_ENUMERABLE)));
|
2018-05-10 17:19:56 +00:00
|
|
|
if(SUCCEEDED(hres))
|
2020-03-23 20:30:09 +00:00
|
|
|
hres = jsdisp_define_data_property(desc_obj, L"configurable", PROPF_ALL,
|
2018-06-11 13:54:26 +00:00
|
|
|
jsval_bool(!!(prop_desc.flags & PROPF_CONFIGURABLE)));
|
2018-05-10 17:19:56 +00:00
|
|
|
|
|
|
|
release_property_descriptor(&prop_desc);
|
|
|
|
if(SUCCEEDED(hres) && r)
|
|
|
|
*r = jsval_obj(desc_obj);
|
|
|
|
else
|
|
|
|
jsdisp_release(desc_obj);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
static HRESULT Object_create(script_ctx_t *ctx, jsval_t vthis, WORD flags,
|
2019-03-15 15:14:44 +00:00
|
|
|
unsigned argc, jsval_t *argv, jsval_t *r)
|
|
|
|
{
|
|
|
|
jsdisp_t *proto = NULL, *obj;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if(!argc || (!is_object_instance(argv[0]) && !is_null(argv[0]))) {
|
|
|
|
FIXME("Invalid arg\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_jsval(argv[0]));
|
|
|
|
|
|
|
|
if(argc && is_object_instance(argv[0])) {
|
|
|
|
if(get_object(argv[0]))
|
|
|
|
proto = to_jsdisp(get_object(argv[0]));
|
|
|
|
if(!proto) {
|
|
|
|
FIXME("Non-JS prototype\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
}else if(!is_null(argv[0])) {
|
|
|
|
FIXME("Invalid arg %s\n", debugstr_jsval(argc ? argv[0] : jsval_undefined()));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2020-03-17 04:36:37 +00:00
|
|
|
hres = create_dispex(ctx, &ObjectInst_info, proto, &obj);
|
2019-08-21 10:31:33 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(argc >= 2 && !is_undefined(argv[1]))
|
|
|
|
hres = jsdisp_define_properties(ctx, obj, argv[1]);
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres) && r)
|
2019-03-15 15:14:44 +00:00
|
|
|
*r = jsval_obj(obj);
|
2019-08-21 10:31:33 +00:00
|
|
|
else
|
|
|
|
jsdisp_release(obj);
|
|
|
|
return hres;
|
2019-03-15 15:14:44 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
static HRESULT Object_getPrototypeOf(script_ctx_t *ctx, jsval_t vthis, WORD flags,
|
2019-03-11 13:39:27 +00:00
|
|
|
unsigned argc, jsval_t *argv, jsval_t *r)
|
|
|
|
{
|
|
|
|
jsdisp_t *obj;
|
|
|
|
|
|
|
|
if(!argc || !is_object_instance(argv[0])) {
|
|
|
|
FIXME("invalid arguments\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2020-06-04 15:29:51 +00:00
|
|
|
TRACE("(%s)\n", debugstr_jsval(argv[0]));
|
2019-03-11 13:39:27 +00:00
|
|
|
|
|
|
|
obj = to_jsdisp(get_object(argv[0]));
|
|
|
|
if(!obj) {
|
|
|
|
FIXME("Non-JS object\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(r)
|
|
|
|
*r = obj->prototype
|
|
|
|
? jsval_obj(jsdisp_addref(obj->prototype))
|
|
|
|
: jsval_null();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2021-04-20 17:12:07 +00:00
|
|
|
static HRESULT object_keys(script_ctx_t *ctx, jsval_t arg, enum jsdisp_enum_type enum_type, jsval_t *r)
|
2020-06-04 15:29:51 +00:00
|
|
|
{
|
|
|
|
DISPID id = DISPID_STARTENUM;
|
|
|
|
jsdisp_t *obj, *array;
|
|
|
|
unsigned i = 0;
|
|
|
|
jsstr_t *key;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2022-03-24 15:31:06 +00:00
|
|
|
if(!is_object_instance(arg)) {
|
2021-04-20 17:12:07 +00:00
|
|
|
FIXME("invalid arguments %s\n", debugstr_jsval(arg));
|
2020-06-04 15:29:51 +00:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2021-04-20 17:12:07 +00:00
|
|
|
obj = to_jsdisp(get_object(arg));
|
2020-06-04 15:29:51 +00:00
|
|
|
if(!obj) {
|
|
|
|
FIXME("Non-JS object\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = create_array(ctx, 0, &array);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
do {
|
2021-04-20 17:12:07 +00:00
|
|
|
hres = jsdisp_next_prop(obj, id, enum_type, &id);
|
2020-06-04 15:29:51 +00:00
|
|
|
if(hres != S_OK)
|
|
|
|
break;
|
|
|
|
|
|
|
|
hres = jsdisp_get_prop_name(obj, id, &key);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
|
|
|
hres = jsdisp_propput_idx(array, i++, jsval_string(key));
|
|
|
|
jsstr_release(key);
|
|
|
|
} while(hres == S_OK);
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres) && r)
|
|
|
|
*r = jsval_obj(array);
|
|
|
|
else
|
|
|
|
jsdisp_release(array);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
static HRESULT Object_keys(script_ctx_t *ctx, jsval_t vthis, WORD flags,
|
2021-04-20 17:12:07 +00:00
|
|
|
unsigned argc, jsval_t *argv, jsval_t *r)
|
|
|
|
{
|
|
|
|
jsval_t arg = argc ? argv[0] : jsval_undefined();
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_jsval(arg));
|
|
|
|
|
|
|
|
return object_keys(ctx, arg, JSDISP_ENUM_OWN_ENUMERABLE, r);
|
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
static HRESULT Object_getOwnPropertyNames(script_ctx_t *ctx, jsval_t vthis, WORD flags,
|
2021-04-20 17:12:07 +00:00
|
|
|
unsigned argc, jsval_t *argv, jsval_t *r)
|
|
|
|
{
|
|
|
|
jsval_t arg = argc ? argv[0] : jsval_undefined();
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_jsval(arg));
|
|
|
|
|
|
|
|
return object_keys(ctx, arg, JSDISP_ENUM_OWN, r);
|
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
static HRESULT Object_preventExtensions(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
|
2020-06-05 16:26:39 +00:00
|
|
|
{
|
|
|
|
jsdisp_t *obj;
|
|
|
|
|
2022-03-24 15:31:06 +00:00
|
|
|
if(!argc || !is_object_instance(argv[0])) {
|
2020-06-05 16:26:39 +00:00
|
|
|
FIXME("invalid arguments\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2021-04-01 16:18:40 +00:00
|
|
|
TRACE("(%s)\n", debugstr_jsval(argv[0]));
|
2020-06-05 16:26:39 +00:00
|
|
|
|
|
|
|
obj = to_jsdisp(get_object(argv[0]));
|
|
|
|
if(!obj) {
|
|
|
|
FIXME("Non-JS object\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2021-04-01 16:18:40 +00:00
|
|
|
obj->extensible = FALSE;
|
2020-06-05 16:26:39 +00:00
|
|
|
if(r) *r = jsval_obj(jsdisp_addref(obj));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
static HRESULT Object_freeze(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc,
|
2021-04-01 16:19:09 +00:00
|
|
|
jsval_t *argv, jsval_t *r)
|
|
|
|
{
|
|
|
|
jsdisp_t *obj;
|
|
|
|
|
2022-03-24 15:31:06 +00:00
|
|
|
if(!argc || !is_object_instance(argv[0])) {
|
2021-04-01 16:19:09 +00:00
|
|
|
WARN("argument is not an object\n");
|
|
|
|
return JS_E_OBJECT_EXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_jsval(argv[0]));
|
|
|
|
|
|
|
|
obj = to_jsdisp(get_object(argv[0]));
|
|
|
|
if(!obj) {
|
|
|
|
FIXME("Non-JS object\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2021-04-01 16:19:16 +00:00
|
|
|
jsdisp_freeze(obj, FALSE);
|
|
|
|
if(r) *r = jsval_obj(jsdisp_addref(obj));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
static HRESULT Object_seal(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc,
|
2021-04-01 16:19:16 +00:00
|
|
|
jsval_t *argv, jsval_t *r)
|
|
|
|
{
|
|
|
|
jsdisp_t *obj;
|
|
|
|
|
2022-03-24 15:31:06 +00:00
|
|
|
if(!argc || !is_object_instance(argv[0])) {
|
2021-04-01 16:19:16 +00:00
|
|
|
WARN("argument is not an object\n");
|
|
|
|
return JS_E_OBJECT_EXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_jsval(argv[0]));
|
|
|
|
|
|
|
|
obj = to_jsdisp(get_object(argv[0]));
|
|
|
|
if(!obj) {
|
|
|
|
FIXME("Non-JS object\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsdisp_freeze(obj, TRUE);
|
2021-04-01 16:19:09 +00:00
|
|
|
if(r) *r = jsval_obj(jsdisp_addref(obj));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
static HRESULT Object_isExtensible(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
|
2021-04-01 16:18:47 +00:00
|
|
|
{
|
|
|
|
jsdisp_t *obj;
|
|
|
|
|
2022-03-24 15:31:06 +00:00
|
|
|
if(!argc || !is_object_instance(argv[0])) {
|
2021-04-01 16:18:47 +00:00
|
|
|
WARN("argument is not an object\n");
|
|
|
|
return JS_E_OBJECT_EXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_jsval(argv[0]));
|
|
|
|
|
|
|
|
obj = to_jsdisp(get_object(argv[0]));
|
|
|
|
if(!obj) {
|
|
|
|
FIXME("Non-JS object\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(r) *r = jsval_bool(obj->extensible);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
static HRESULT Object_isFrozen(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc,
|
2021-04-02 18:24:37 +00:00
|
|
|
jsval_t *argv, jsval_t *r)
|
|
|
|
{
|
|
|
|
jsdisp_t *obj;
|
|
|
|
|
2022-03-24 15:31:06 +00:00
|
|
|
if(!argc || !is_object_instance(argv[0])) {
|
2021-04-02 18:24:37 +00:00
|
|
|
WARN("argument is not an object\n");
|
|
|
|
return JS_E_OBJECT_EXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_jsval(argv[0]));
|
|
|
|
|
|
|
|
obj = to_jsdisp(get_object(argv[0]));
|
|
|
|
if(!obj) {
|
|
|
|
FIXME("Non-JS object\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(r) *r = jsval_bool(jsdisp_is_frozen(obj, FALSE));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
static HRESULT Object_isSealed(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc,
|
2021-04-02 18:24:37 +00:00
|
|
|
jsval_t *argv, jsval_t *r)
|
|
|
|
{
|
|
|
|
jsdisp_t *obj;
|
|
|
|
|
2022-03-24 15:31:06 +00:00
|
|
|
if(!argc || !is_object_instance(argv[0])) {
|
2021-04-02 18:24:37 +00:00
|
|
|
WARN("argument is not an object\n");
|
|
|
|
return JS_E_OBJECT_EXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_jsval(argv[0]));
|
|
|
|
|
|
|
|
obj = to_jsdisp(get_object(argv[0]));
|
|
|
|
if(!obj) {
|
|
|
|
FIXME("Non-JS object\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(r) *r = jsval_bool(jsdisp_is_frozen(obj, TRUE));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-05-10 17:19:56 +00:00
|
|
|
static const builtin_prop_t ObjectConstr_props[] = {
|
2020-03-23 20:30:09 +00:00
|
|
|
{L"create", Object_create, PROPF_ES5|PROPF_METHOD|2},
|
|
|
|
{L"defineProperties", Object_defineProperties, PROPF_ES5|PROPF_METHOD|2},
|
|
|
|
{L"defineProperty", Object_defineProperty, PROPF_ES5|PROPF_METHOD|2},
|
2021-04-01 16:19:09 +00:00
|
|
|
{L"freeze", Object_freeze, PROPF_ES5|PROPF_METHOD|1},
|
2020-03-23 20:30:09 +00:00
|
|
|
{L"getOwnPropertyDescriptor", Object_getOwnPropertyDescriptor, PROPF_ES5|PROPF_METHOD|2},
|
2021-04-20 17:12:07 +00:00
|
|
|
{L"getOwnPropertyNames", Object_getOwnPropertyNames, PROPF_ES5|PROPF_METHOD|1},
|
2020-06-04 15:29:51 +00:00
|
|
|
{L"getPrototypeOf", Object_getPrototypeOf, PROPF_ES5|PROPF_METHOD|1},
|
2021-04-01 16:18:47 +00:00
|
|
|
{L"isExtensible", Object_isExtensible, PROPF_ES5|PROPF_METHOD|1},
|
2021-04-02 18:24:37 +00:00
|
|
|
{L"isFrozen", Object_isFrozen, PROPF_ES5|PROPF_METHOD|1},
|
|
|
|
{L"isSealed", Object_isSealed, PROPF_ES5|PROPF_METHOD|1},
|
2020-06-05 16:26:39 +00:00
|
|
|
{L"keys", Object_keys, PROPF_ES5|PROPF_METHOD|1},
|
|
|
|
{L"preventExtensions", Object_preventExtensions, PROPF_ES5|PROPF_METHOD|1},
|
2021-04-01 16:19:16 +00:00
|
|
|
{L"seal", Object_seal, PROPF_ES5|PROPF_METHOD|1},
|
2018-05-10 17:19:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const builtin_info_t ObjectConstr_info = {
|
|
|
|
JSCLASS_FUNCTION,
|
2021-11-25 20:01:37 +00:00
|
|
|
Function_value,
|
2018-07-09 18:59:12 +00:00
|
|
|
ARRAY_SIZE(ObjectConstr_props),
|
2018-05-10 17:19:56 +00:00
|
|
|
ObjectConstr_props,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2022-03-17 16:25:39 +00:00
|
|
|
static HRESULT ObjectConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:15 +00:00
|
|
|
{
|
2008-09-10 19:08:09 +00:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
switch(flags) {
|
2009-09-16 23:05:55 +00:00
|
|
|
case DISPATCH_METHOD:
|
2016-06-20 18:54:48 +00:00
|
|
|
case DISPATCH_CONSTRUCT: {
|
|
|
|
jsdisp_t *obj;
|
|
|
|
|
2012-06-25 12:08:38 +00:00
|
|
|
if(argc) {
|
2022-03-24 15:31:06 +00:00
|
|
|
if(!is_undefined(argv[0]) && !is_null(argv[0])) {
|
2009-09-16 23:05:55 +00:00
|
|
|
IDispatch *disp;
|
|
|
|
|
2012-09-17 13:19:19 +00:00
|
|
|
hres = to_object(ctx, argv[0], &disp);
|
2009-09-16 23:05:55 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
if(r)
|
|
|
|
*r = jsval_disp(disp);
|
|
|
|
else
|
2009-09-16 23:05:55 +00:00
|
|
|
IDispatch_Release(disp);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
2008-09-10 19:08:09 +00:00
|
|
|
|
2009-09-23 14:17:17 +00:00
|
|
|
hres = create_object(ctx, NULL, &obj);
|
2008-09-10 19:08:09 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
if(r)
|
|
|
|
*r = jsval_obj(obj);
|
2010-10-19 21:14:35 +00:00
|
|
|
else
|
|
|
|
jsdisp_release(obj);
|
2008-09-10 19:08:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("unimplemented flags: %x\n", flags);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2008-09-10 00:33:15 +00:00
|
|
|
}
|
|
|
|
|
2010-09-06 14:11:49 +00:00
|
|
|
HRESULT create_object_constr(script_ctx_t *ctx, jsdisp_t *object_prototype, jsdisp_t **ret)
|
2008-09-10 00:33:15 +00:00
|
|
|
{
|
2020-03-23 20:30:09 +00:00
|
|
|
return create_builtin_constructor(ctx, ObjectConstr_value, L"Object", &ObjectConstr_info, PROPF_CONSTR,
|
2009-07-12 17:52:31 +00:00
|
|
|
object_prototype, ret);
|
|
|
|
}
|
2008-09-10 00:33:15 +00:00
|
|
|
|
2010-09-06 14:11:49 +00:00
|
|
|
HRESULT create_object_prototype(script_ctx_t *ctx, jsdisp_t **ret)
|
2009-07-12 17:52:31 +00:00
|
|
|
{
|
|
|
|
return create_dispex(ctx, &Object_info, NULL, ret);
|
2008-09-10 00:33:15 +00:00
|
|
|
}
|
2008-09-10 19:08:09 +00:00
|
|
|
|
2010-09-06 14:11:49 +00:00
|
|
|
HRESULT create_object(script_ctx_t *ctx, jsdisp_t *constr, jsdisp_t **ret)
|
2008-09-10 19:08:09 +00:00
|
|
|
{
|
2010-09-06 14:11:49 +00:00
|
|
|
jsdisp_t *object;
|
2008-09-10 19:08:09 +00:00
|
|
|
HRESULT hres;
|
|
|
|
|
2010-09-06 14:11:49 +00:00
|
|
|
object = heap_alloc_zero(sizeof(jsdisp_t));
|
2008-09-10 19:08:09 +00:00
|
|
|
if(!object)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2012-07-23 13:53:22 +00:00
|
|
|
hres = init_dispex_from_constr(object, ctx, &ObjectInst_info, constr ? constr : ctx->object_constr);
|
2008-09-10 19:08:09 +00:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
heap_free(object);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret = object;
|
|
|
|
return S_OK;
|
|
|
|
}
|