Funny implementation :P You did it vice-versa: functional objects _do_
work, but simple calls do not :D
No, not good to depend on `this' value and non-Reference type.
Dmitry.
On 21.12.2011 16:05, Andrea Giammarchi wrote:
This is almost the exact behavior I was talking about ...
Object.withNoSuchMethod = function withNoSuchMethod(obj,
__noSuchMethod__) {
var cachedInvokes = {};
return Proxy.create({
get: function (receiver, name) {
return name in obj ?
obj[name] :
cachedInvokes.hasOwnProperty(name) ?
cachedInvokes[name] :
cachedInvokes[name] = function () {
if(this === receiver)
return __noSuchMethod__.call(obj, name, arguments);
throw new Error("undefined is not a function");
}
;
}
});
};
var p = Object.withNoSuchMethod({/*generic object*/}, function (prop,
args) {
alert([prop, args.length]);
});
(p.test)(1, 2, 3);
var test = p.test;
test.call(p, 1, 2, 3);
test.apply(p, [1, 2, 3]);
p.test(1, 2, 3);
test.bind(p)(1, 2, 3);
test(1, 2, 3); // undefined is not a function
test.call(null, 1, 2, 3); // undefined is not a function
On Tue, Dec 20, 2011 at 2:00 PM, Tom Van Cutsem <[email protected]
<mailto:[email protected]>> wrote:
- @Tom: Found bugs in DirectProxies.js
Thanks for reporting, but I don't think these are bugs:
1. Properties created via assignment gets `false' value for
descriptor attributes; should be true. E.g. foo.bar = 10,
where `foo' is direct proxy, makes bar non-configurable
I can't reproduce this. Both in tracemonkey and ff8 I get the
following:
js> var t = {}
js> var p = Proxy(t, {})
js> p.x = 1
1
js> Object.getOwnPropertyDescriptor(t, 'x')
({value:1, writable:true, enumerable:true, configurable:true})
js> Object.getOwnPropertyDescriptor(p, 'x')
({value:1, writable:true, enumerable:true, configurable:true})
There is, however, a TM-specific bug that I suspect may be the
cause of your observed "non-configurable by default" behavior:
<https://bugzilla.mozilla.org/show_bug.cgi?id=601329>
2. Can't return descriptor with `configurable: false' for
non-existing property; get: "cannot report a non-configurable
descriptor for non-existent property" But we need it in case
virtual methods
You can (and probably should) advertise a virtual method as
configurable:true.
The proxy throws this exception because, for properties that do
not exist on the wrapped target, it cannot guarantee that they
will always be non-configurable. For example, if your proxy
handler now says that "foo" is {value:10, configurable:false},
nothing stops your proxy handler from later claiming that "foo" is
{value:0, configurable:true}.
Cheers,
Tom
_______________________________________________
es-discuss mailing list
[email protected] <mailto:[email protected]>
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss