Message from discussion
Feature Request: Managed Objects
Received: by 10.220.179.66 with SMTP id bp2mr476910vcb.16.1292616062323;
Fri, 17 Dec 2010 12:01:02 -0800 (PST)
X-BeenThere: nodejs@googlegroups.com
Received: by 10.220.64.95 with SMTP id d31ls380624vci.3.p; Fri, 17 Dec 2010
12:00:54 -0800 (PST)
Received: by 10.220.201.193 with SMTP id fb1mr487951vcb.1.1292616054672;
Fri, 17 Dec 2010 12:00:54 -0800 (PST)
Received: by 10.220.201.193 with SMTP id fb1mr487950vcb.1.1292616054653;
Fri, 17 Dec 2010 12:00:54 -0800 (PST)
Return-Path: <nhus...@gmail.com>
Received: from mail-vw0-f52.google.com (mail-vw0-f52.google.com [209.85.212.52])
by gmr-mx.google.com with ESMTP id m31si44399vcr.1.2010.12.17.12.00.53;
Fri, 17 Dec 2010 12:00:53 -0800 (PST)
Received-SPF: pass (google.com: domain of nhus...@gmail.com designates 209.85.212.52 as permitted sender) client-ip=209.85.212.52;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of nhus...@gmail.com designates 209.85.212.52 as permitted sender) smtp.mail=nhus...@gmail.com; dkim=pass (test mode) header...@gmail.com
Received: by vws13 with SMTP id 13so377857vws.25
for <nodejs@googlegroups.com>; Fri, 17 Dec 2010 12:00:53 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=gamma;
h=domainkey-signature:received:received:content-type:mime-version
:subject:from:in-reply-to:date:content-transfer-encoding:message-id
:references:to:x-mailer;
bh=se6NDxO3EcWH1wDejxSob++45XTmyGI6XiGqoi6S27U=;
b=OFhasazu7gKXgZSGUDgUP9YN82DAFdVpHTodxrkqkKXSbcfx5+oXXza57oPNXoShVd
Vutco7DYbCT0OHaL+JPKsR+8EwcABERr4RGA7Y5UcdsdOk21lw6TApElETfOztsompmJ
i0il7t0SIGT9wNbk1OJkBhs7BEsQGC5cCTIWY=
DomainKey-Signature: a=rsa-sha1; c=nofws;
d=gmail.com; s=gamma;
h=content-type:mime-version:subject:from:in-reply-to:date
:content-transfer-encoding:message-id:references:to:x-mailer;
b=khxACHsZ45dGFyvLHjV02BluwgnIOCVULB01e23+hEvFlH1/wr5jPma7/X75U9k0R1
33KHEYUccZy5gdWSWFJLcGSXE7gEwsKbFtTnAKmY/YoPm+W2zn+1AAOFldqQMDjoXw02
5XVhnRNOOCiGJWbJHNh+ctgZjJS/pkOES1jCE=
Received: by 10.220.193.11 with SMTP id ds11mr327140vcb.209.1292616053360;
Fri, 17 Dec 2010 12:00:53 -0800 (PST)
Return-Path: <nhus...@gmail.com>
Received: from [192.168.1.44] (pool-72-92-134-54.burl.east.myfairpoint.net [72.92.134.54])
by mx.google.com with ESMTPS id u4sm180988vch.36.2010.12.17.12.00.51
(version=TLSv1/SSLv3 cipher=RC4-MD5);
Fri, 17 Dec 2010 12:00:52 -0800 (PST)
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0 (Apple Message framework v1082)
Subject: Re: [nodejs] Re: Feature Request: Managed Objects
From: Nick Husher <nhus...@gmail.com>
In-Reply-To: <922cbe6c-e951-4307-8a38-168e688de...@q18g2000vbm.googlegroups.com>
Date: Fri, 17 Dec 2010 15:00:49 -0500
Content-Transfer-Encoding: quoted-printable
Message-Id: <20726C81-1691-4C16-A134-AED89E9EE...@gmail.com>
References: <b593565f-f3ae-4202-aaec-24a536a03...@l24g2000vby.googlegroups.com> <922cbe6c-e951-4307-8a38-168e688de...@q18g2000vbm.googlegroups.com>
To: nodejs@googlegroups.com
X-Mailer: Apple Mail (2.1082)
I believe ECMAScript5 object and property descriptors API is the desired =
way to do what you're after:
http://ejohn.org/blog/ecmascript-5-objects-and-properties/
As far as I know, v8 has reasonably good ES5 object and property =
support. Last time I checked, though, they had one bug that may or may =
not apply to you:
Let's say you have a native object (say a DOM element in a web browser) =
and it has a property on it with an internal setter. For example, =
"innerHTML."
As you may know, you can do myDomElement.innerHTML =3D someString, and =
it will update the innards of the element with the browser-evaluated =
string. Clearly there's magic happening here beyond just setting a =
property. The problem is that if you try to get a pointer that getter or =
setter method in v8, it will return undefined:
var d =3D Object.getOwnPropertyDescriptor(myDomElement, "innerHTML");
d.getter // undefined
d.setter // undefined
This makes it impossible to intercept native property assignments. If =
you wanted to toss an event any time content was assigned to innerHTML, =
you would be unable in v8.
Testing in firefox indicates that its JS engine *does* hand back a =
pointer to a native function. In that browser it's possible to shim =
property assignments.
Last I checked, bugs filed about this get flagged as "not a bug."
Nick
____________________
Nicholas Husher
nhus...@gmail.com
http://nickol.us
On 17 Dec 2010, at 1:37 PM, Shimon Doodkin wrote:
> http://ejohn.org/blog/javascript-getters-and-setters/
>=20
> On Dec 17, 5:39 pm, ollym <oliver.mor...@kohark.com> wrote:
>> Would it be possible to add something like this:
>> It would obviously need some C++ implementation, but would be useful
>> for clever OEM/datastore implementations.
>>=20
>> var ManagedObject =3D require('util').ManagedObject;
>>=20
>> var obj =3D new ManagedObject({
>> get: function(key) { console.log('GET: ' + key); return true; }
>> set: function(key, value) { console.log('SET: ' + key + '=3D' +
>> value }
>>=20
>> });
>>=20
>> obj.value; // returns true
>> // Output:
>> // GET: value
>>=20
>> obj.value =3D false;
>> // Output:
>> // SET: value=3Dfalse
>>=20
>> obj.value; // returns true (still)
>> // Output:
>> // GET: value
>=20
> --=20
> You received this message because you are subscribed to the Google =
Groups "nodejs" group.
> To post to this group, send email to nodejs@googlegroups.com.
> To unsubscribe from this group, send email to =
nodejs+unsubscribe@googlegroups.com.
> For more options, visit this group at =
http://groups.google.com/group/nodejs?hl=3Den.
>=20