Hello,

A little bit background to my work:
I implement not only transparent proxies and overwrite the opaque
proxies. I implement transparent proxies using a handler trap. If this
trap is implemented, the target of the proxy is compared instead the
proxy, else it is an opaque proxy with the behavior described in the
documentation.

After our discussion I've implemented a new version of the
GetIdentityObject, which directly gets the JSContext from the given
JSObject.

JS_FRIEND_API(JSObject *)
js::GetIdentityObject(JSObject *obj)
{
    JSObject *retObj = obj;
    if(!IsProxy(retObj))
    {
        return retObj;
    }
    else
    {
        JSRuntime * rt = JS_GetObjectRuntime(retObj);
        JSContext * cx = DefaultJSContext(rt);

        bool result = false;
        JS::RootedObject handleEqualsObj(cx,retObj);

        if(!Proxy::isTransparent(cx, handleEqualsObj, &result) || !result)
        {
            return retObj;
        }
        else
        {
            retObj = GetProxyTargetObject(retObj);
            return GetIdentityObject(retObj);
        }
    }
}

I thought if the function is called from LooselyEqual or StrictlyEqual
of Interpreter.cpp with the given JSContext this could lead to failures.

bool js::LooselyEqual(JSContext *cx, const Value &lval, const Value
&rval, bool *result)
-->JS_FRIEND_API(JSObject *) js::GetIdentityObject(JSContext *cx,
JSObject *obj)

But the JSContext and JSRuntime, which I get in the new
GetIdentityObject function are the same for both comparism objects (seen
by debugging the code) for the following test case:

var obj = {foo:"bar"};
var proxy = new Proxy(obj, handler);
var global = newGlobal();
global.obj = obj;
global.handler = handler;
evalcx('var proxy = new Proxy(obj, handler)', global);

msg = "Compare two different transparent proxies of the same object in
different Context";
reportCompare(true, proxy == global.proxy, msg);

But the test fails, because the left comparism argument will be handled
with a ScriptedDirectProxyHandler and the right argument not.

My Questions are:

Why is the proxy within the global not handled by a
ScriptedDirectProxyHandler and which handler is used for?
Why are the JSContext and JSRuntime identical, although the two objects
should use two different Runtimes?

Thanks a lot
Andreas

Am 14.01.2014 14:18, schrieb Andreas Schlegel:
> Hello,
>
> I've tested it, but I become a behavior which I don't understand.
>
> For Implementing the Proxy handler trap I asked where I have to
> implement the handler method, because of the various handlers
> (BaseProxyHandler, DirectProxyHandler, ScriptedDirectProxyHandler....).
> The answer was I should it implement into ScriptedDirectProxyHandler
> and for BaseProxyHandler I should only return false.
>
> But after the tests and some debugging I see the second value for
> comparism, which is from the new declarated global will only call
> BaseProxyHandler not ScriptedDirectProxyHandler, therefore my function
> get the answer "is not transparent" and return the proxy instead of
> the target for comparism.
>
> Why  is the BaseProxyHandler called instead of the
> ScriptedDirectProxyHandler? Or must I implement also a method for
> another proxy handler?
>
> Thanks a lot
> Andreas
>
> Am 12.01.2014 15:34, schrieb Andreas Schlegel:
>> Ok thank you I will test it.
>>
>> Am 12.01.2014 15:30, schrieb Till Schneidereit:
>>> On Sun, Jan 12, 2014 at 2:36 PM, Andreas Schlegel
>>> <[email protected] <mailto:[email protected]>> wrote:
>>>
>>>>     I don't know your code, so this is somewhat speculative, but:
>>>>     if you create an object (in your case a proxy, IINM) in one
>>>>     global and then do a comparison with another object from
>>>>     another global, that should blow up or give false results if
>>>>     you don't specifically handle these cases. If it doesn't, then
>>>>     your code is set up so that the comparison happens after some
>>>>     other code has already done the required unwrapping for you. In
>>>>     that case, great, but you might want to test in the browser,
>>>>     too, by creating multiple iframes and comparing objects from
>>>>     two of them.
>>>     I'm not so good in JavaScript, how can I assign the values to
>>>     the globals for testing? For my case the "transparent" proxies
>>>     are only the same, if the targets have the same identity.
>>>
>>>     var global1 = newGlobal();
>>>     evalcx('var obj = {foo:"bar"}', global1);
>>>     evalcx('var proxy1= new Proxy(obj)', global1);
>>>     var global2 = newGlobal();
>>>     evalcx('var proxy2= new Proxy(obj)', global2);
>>>     reportCompare(true, proxy1 == proxy2);
>>>
>>>     Is this correct?
>>>
>>>
>>> Almost. Your proxies don't specify handler object (which can be
>>> empty), and your second global doesn't contain the obj. Also, you
>>> don't need to create two new globals, as the main script is already
>>> running in one.
>>>
>>> Here's a version that does both an object and a proxy comparison:
>>>
>>> var obj = {foo:"bar"};
>>> var proxy = new Proxy(obj, {});
>>> var global = newGlobal();
>>> global.obj = obj;
>>> evalcx('var proxy = new Proxy(obj, {})', global);
>>> print(obj == global.obj); // prints true
>>> print(proxy == global.proxy); // prints false
>>>
>>> IIUC, the second print should also be true with your work applied.
>>>  
>>>
>>>     At the moment I've only installed the Spidermonkey Engine, can I
>>>     test the behaviour without a browser?
>>>
>>>
>>> Yes, largely. The browser uses different cross-compartment wrappers,
>>> which might or might not mean that your code has to do something
>>> different. For your exploratory work, testing in the shell should be
>>> fine, though.
>>>  
>>
>

_______________________________________________
dev-tech-js-engine-internals mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-internals

Reply via email to