Questions tagged [proxy-object]

26 questions
27
votes
1 answer

Which Python dunder/magic methods do you need to implement to correctly proxy an object?

I'm trying to create an object proxy. Attribute/property lookup can be done by simply implementing the __getattribute__, __setattr__ and __delattr__ methods. However, other functionalities like len(x), x[], bool(x) require other dunder methods like…
26
votes
3 answers

How to control property enumeration (for...in) with Proxy objects?

I'm wrapping an object in a Proxy and then iterate through it. How can I control the keys it iterates through? The proxy works if I don't override the keys: var obj = {"hello": "world"} var proxy = new Proxy(obj, {}) for (var key in proxy){ …
Matt Zeunert
  • 16,075
  • 6
  • 52
  • 78
7
votes
6 answers

Would this optimization in the implementation of std::string be allowed?

I was just thinking about the implementation of std::string::substr. It returns a new std::string object, which seems a bit wasteful to me. Why not return an object that refers to the contents of the original string and can be implicitly assigned to…
Evan Teran
  • 87,561
  • 32
  • 179
  • 238
6
votes
2 answers

Can methods of objects be intercepted when iterating over them as part of a collection?

I'm wondering if an object belonging to a collection class, whilst being iterated on can know it's being iterated and know about the collection class it belongs to? e.g.
SlashEquip
  • 126
  • 5
5
votes
1 answer

What is a revocable proxy in JavaScript for?

Why would you want to revoke a proxy? Could you provide a practical application of Proxy.revocable()? Based on the MDN Proxy.revocable() documentation I understand it allows garbage collection. However, wouldn't it also allow garbage collection if…
ADJenks
  • 2,973
  • 27
  • 38
3
votes
1 answer

Does Hibernate.unproxy have any side effects?

In our project we have a part of code that does things based on the class of the passed object. Something like this: public class A { } public class B extends A { } public class Manager { public void manageA(A obj) { …
valepu
  • 3,136
  • 7
  • 36
  • 67
2
votes
1 answer

Replace objects by other objects in-place

Suppose I'd like to build a database abstraction layer, which uses a lazy loading mechanism. If I ask the layer to load a root object, it loads its external representation and constructs itself. It then somehow identifies that certain linked…
SteAp
  • 11,853
  • 10
  • 53
  • 88
2
votes
0 answers

Distinguish the final property from the intermediate properties being accessed with javascript proxies

Is there a way to figure out if the property being read of a proxy object is the final property or the intermediate property. var handler = { get(target, key) { return new Proxy(target[key], handler) }, set (target, key, value) { …
Ayush Goel
  • 435
  • 6
  • 16
2
votes
1 answer

How to update object with lazy properties (proxy object) in another session?

I attempted to get the object that has lazy properties in a session and tried to update it in another session. But it failed to do so with an Error: No persister for SecUserProxy (actual class is SecUser) I'm using NHibernate 3.4. When I googled I…
Sadiq
  • 786
  • 1
  • 10
  • 35
2
votes
2 answers

ES6 proxies cannot intercept array indices

Here is my test code (to be run using node --harmony-proxies foo.js: var a = Proxy.create({ get : function (proxy, prop) { return 5 } }) console.log(a['foo']) console.log(a.length) console.log(a['10']) console.log(a[10]) Why…
nponeccop
  • 13,527
  • 1
  • 44
  • 106
1
vote
0 answers

How can I reliably convert a proxy to a standard object?

I'm working with events in JavaScript, and often the event is a proxy object. When debugging I can usually use this to get a copy of the object. console.log(JSON.parse(JSON.stringify(event.detail))); Sometimes (today, a few times), this outputs a…
Chuck
  • 4,662
  • 2
  • 33
  • 55
1
vote
2 answers

How to implement object proxy or Class proxy in Java?

I have requirement to extend a .class file in my project and need to override a simple method. Consider i have class A which is in some .jar package.Now i want to override test() method of class A.I did it using creating subclass B of A and override…
1
vote
1 answer

Replacing a constructor call with a factory method call by using a proxy in C#

I might be going crazy, but I swear I've seen a snippet that allows the consumers of your code to write new Foo() while something like FooProxy.Create() is called behind the scenes instead of the constructor. I've been searching and searching for…
Alexey
  • 1,354
  • 13
  • 30
1
vote
1 answer

Generate proxy objects on the fly (programmatically generate class derived from given object and override single method)

I'd like to create a method that does the following: Takes an arbitrary instance as parameter Generates a wrapper instance providing all properties and methods in the same way as the passed instance Overrides one method with a different…
Seven
  • 4,353
  • 2
  • 27
  • 30
1
vote
1 answer

dart proxy objects can or cannot be assigned to typed variables?

I have the following test code: @proxy class A{ noSuchMethod(Invocation inv) => "no problems"; } class B{ String get aString => "I'm a B string"; } void main() { B b = new A(); print(b.aString); } from what I read on the api site about…
Daniel Robinson
  • 13,806
  • 18
  • 64
  • 112
1
2