Commit b8dbee69 authored by Gabriel Ivăncescu's avatar Gabriel Ivăncescu Committed by Alexandre Julliard

jscript: Implement WeakMap instance stub and constructor.

parent 3f20b8aa
......@@ -117,6 +117,7 @@ typedef enum {
JSCLASS_JSON,
JSCLASS_MAP,
JSCLASS_SET,
JSCLASS_WEAKMAP,
} jsclass_t;
jsdisp_t *iface_to_jsdisp(IDispatch*);
......@@ -418,11 +419,12 @@ struct _script_ctx_t {
jsdisp_t *vbarray_constr;
jsdisp_t *map_prototype;
jsdisp_t *set_prototype;
jsdisp_t *weakmap_prototype;
};
jsdisp_t *global_objects[22];
jsdisp_t *global_objects[23];
};
};
C_ASSERT(RTL_SIZEOF_THROUGH_FIELD(script_ctx_t, set_prototype) == RTL_SIZEOF_THROUGH_FIELD(script_ctx_t, global_objects));
C_ASSERT(RTL_SIZEOF_THROUGH_FIELD(script_ctx_t, weakmap_prototype) == RTL_SIZEOF_THROUGH_FIELD(script_ctx_t, global_objects));
void script_release(script_ctx_t*);
......
......@@ -51,6 +51,7 @@ static HRESULT Object_toString(script_ctx_t *ctx, jsval_t vthis, WORD flags, uns
L"[object Object]",
L"[object Object]",
L"[object Object]",
L"[object Object]",
L"[object Object]"
};
......
......@@ -614,6 +614,125 @@ static HRESULT Set_constructor(script_ctx_t *ctx, jsval_t vthis, WORD flags, uns
}
}
typedef struct {
jsdisp_t dispex;
} WeakMapInstance;
static HRESULT WeakMap_clear(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT WeakMap_delete(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT WeakMap_get(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT WeakMap_set(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT WeakMap_has(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT WeakMap_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
FIXME("\n");
return E_NOTIMPL;
}
static void WeakMap_destructor(jsdisp_t *dispex)
{
WeakMapInstance *weakmap = (WeakMapInstance*)dispex;
free(weakmap);
}
static HRESULT WeakMap_gc_traverse(struct gc_ctx *gc_ctx, enum gc_traverse_op op, jsdisp_t *dispex)
{
return S_OK;
}
static const builtin_prop_t WeakMap_prototype_props[] = {
{L"clear", WeakMap_clear, PROPF_METHOD},
{L"delete", WeakMap_delete, PROPF_METHOD|1},
{L"get", WeakMap_get, PROPF_METHOD|1},
{L"has", WeakMap_has, PROPF_METHOD|1},
{L"set", WeakMap_set, PROPF_METHOD|2},
};
static const builtin_info_t WeakMap_prototype_info = {
JSCLASS_OBJECT,
WeakMap_value,
ARRAY_SIZE(WeakMap_prototype_props),
WeakMap_prototype_props,
NULL,
NULL
};
static const builtin_info_t WeakMap_info = {
JSCLASS_WEAKMAP,
WeakMap_value,
0,
NULL,
WeakMap_destructor,
NULL,
NULL,
NULL,
NULL,
WeakMap_gc_traverse
};
static HRESULT WeakMap_constructor(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
WeakMapInstance *weakmap;
HRESULT hres;
switch(flags) {
case DISPATCH_CONSTRUCT:
TRACE("\n");
if(!r)
return S_OK;
if(!(weakmap = calloc(1, sizeof(*weakmap))))
return E_OUTOFMEMORY;
hres = init_dispex(&weakmap->dispex, ctx, &WeakMap_info, ctx->weakmap_prototype);
if(FAILED(hres))
return hres;
*r = jsval_obj(&weakmap->dispex);
return S_OK;
case DISPATCH_METHOD:
return throw_error(ctx, JS_E_WRONG_THIS, L"WeakMap");
default:
FIXME("unimplemented flags %x\n", flags);
return E_NOTIMPL;
}
}
HRESULT init_set_constructor(script_ctx_t *ctx)
{
jsdisp_t *constructor;
......@@ -649,5 +768,20 @@ HRESULT init_set_constructor(script_ctx_t *ctx)
hres = jsdisp_define_data_property(ctx->global, L"Map", PROPF_WRITABLE,
jsval_obj(constructor));
jsdisp_release(constructor);
if(FAILED(hres))
return hres;
hres = create_dispex(ctx, &WeakMap_prototype_info, ctx->object_prototype, &ctx->weakmap_prototype);
if(FAILED(hres))
return hres;
hres = create_builtin_constructor(ctx, WeakMap_constructor, L"WeakMap", NULL,
PROPF_CONSTR, ctx->weakmap_prototype, &constructor);
if(FAILED(hres))
return hres;
hres = jsdisp_define_data_property(ctx->global, L"WeakMap", PROPF_WRITABLE,
jsval_obj(constructor));
jsdisp_release(constructor);
return hres;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment