Hello,
I've another general problem, like in the "Re: [JS-internals] JIT-Test:
self-test/assertDeepEq.js" thread.
I need the Context to get the value from the Proxy handler trap in the
HashPolicy structure, which is implemented like this (not tested at the
moment, because I don't know how I can get the JSContext ):
// Hash policy for WeakMaps for JSObject*.
template<>
struct WeakMapHasher<JSObject*> : DefaultHasher<JSObject*> {
typedef JSObject* Key;
typedef Key Lookup;
static uint32_t hash(const Lookup &l) {
return *GetIdentityObject(cx, *l);*;
}
static bool match(const Key &k, const Lookup &l) {
* Key kval = GetIdentityObject(cx, *k);**
** Key lval = GetIdentityObject(cx, *l);*
return *kval == *lval;
}
};
The GetIdentityObject-Method need the Context to call the
Proxy::isTransparent() method:
inline JSObject *
GetIdentityObject(JSContext *cx, JSObject &obj)
{
...
* JS::RootedObject handleEqualsObj(cx,equalsObj);*
if(!Proxy::isTransparent(*cx*, handleEqualsObj, &result) || !result)
...
}
The handler function, which is called by Proxy::isTransparent() needs
the Context to declare a RootedValue for the trap and call other
functions, which needs the context:
bool
ScriptedDirectProxyHandler::isTransparent(JSContext *cx, HandleObject
proxy, bool *bp)
{
// step 1
RootedObject handler(*cx*, GetDirectProxyHandlerObject(proxy));
// step 2
JSString* propStr = JS_InternString(*cx*, "isTransparent");
JSAtom& atom = propStr->asAtom();
*RootedValue trap(cx);*
if (!JSObject::getProperty(*cx*, handler, handler,
atom.asPropertyName(), &trap))
return false;
...
*RootedValue trapResult(cx);*
if (!Invoke(*cx*, ObjectValue(*handler), trap, 0, argv, &trapResult))
return false;
...
}
How can I get here the needed JSContext?
Thanks a lot
Andreas
Am 20.12.2013 18:07, schrieb Andreas Schlegel:
> Hello,
>
> thank you for your answer.
>
> First I will change the WeakMap.
>
> If I change the typedef for ObjectValueMap, I have to remove also the
> default value for the HashPolicy of the WeakMap (jsweakmap.h), I'm right?
>
> template <class Key, class Value, class HashPolicy = DefaultHasher<Key> >
> class WeakMap : public HashMap<Key, Value, HashPolicy,
> RuntimeAllocPolicy>, public WeakMapBase
>
> Have I to implement more than one template, if I want to distinguish
> between JSObject and the other types?
> I want only change the behaviour for JSObject and JSObject*, because
> only this types can be a Proxy type.
>
> In the HashTable.h are three implementations:
>
> * a generic one for pointer types
> * a generic one for Class Types
> * one for double Types
>
> Can I implement something like this:
>
> template <class Key>
> struct WeakMapHasher : DefaultHasher
> {
> ...
> }
>
> template <>
> struct WeakMapHasher<JSObject> : DefaultHasher<JSObject>
> {
> ...
> }
>
> template <>
> struct WeakMapHasher<JSObject*> : DefaultHasher<JSObject*>
> {
> ...
> }
>
> And change the implementation of hash() and match()?
>
> Thanks a lot
> Andreas
> Am 19.12.2013 19:58, schrieb Jason Orendorff:
>> On 12/19/13 3:21 AM, Andreas Schlegel wrote:
>>> Hello Jason,
>>>
>>> for comparing "transparent" proxies I have to change some things for
>>> WeakMap Map and Set.
>>>
>>> I should compare the key from a transparent Proxy with its object, e.g.
>>> for getting the value .
>>>
>>> I found the lookup is in the HashTable.h in the Folder JS/public may I
>>> change something there, or are this includes from somewhere?
>>>
>> (adding the list)
>>
>> Don't change js/public/HashTable.h.
>>
>> For Map and Set, you have to change hash() and match() methods in
>> builtin/MapObject.h and .cpp.
>>
>> For WeakMap, I think you need to modify js/src/vm/WeakMapObject.h. You
>> need to add a struct that is a hash policy (as defined in comments in
>> js/public/HashTable.h) and implements hash() and match() correctly for
>> your purpose. Then change this line:
>>
>> typedef WeakMap<EncapsulatedPtrObject, RelocatableValue> ObjectValueMap;
>>
>> to pass your new hash policy as the third parameter. (The default
>> HashPolicy has hash() and match() methods based on pointer equality. You
>> must provide an explicit hash policy to override that.)
>>
>> -j
>>
>>
>
_______________________________________________
dev-tech-js-engine-internals mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-internals