On Wed, Apr 24, 2013 at 11:00 AM, Ben Noordhuis <[email protected]> wrote:
> ...The trick I mentioned in my other post is that you add a second > internal field that points to some atom (usually a char > class_name_id[] = "MyClassName") that you check for in your prototype > methods so you can be sure that args.This() is what you expect it to > be. Be sure to check args.This()->InternalFieldCount() as well. > Another option, as opposed to using a string, is take the address of some internal static value. The value and type of that pointer is largely irrelevant - it's _address_ can be used as the type identifier. In cvv8 we use a mixture: we use the address of a static string (not its value) defined in a template, since comparing the address is much faster than doing a strcmp and the address is guaranteed to be unique within the app's address space. > We don't use that trick in node.js actually but that's because native > objects are not exposed directly, there's (almost) always some pure JS > object sitting in front of it. It's a pretty good approach when > you're not operating in a hostile environment (running untrusted > code), it saves a lot of headaches. > Here's an example where it is important to have such a type-safety net: Assume Foo and Bar are both client-define native types: var x = new Foo(); var y = new Bar(); x.doBar = y.doBar; x.doBar(); // doBar expects that 'this' is-a (Bar*) -- ----- stephan beal http://wanderinghorse.net/home/stephan/ http://gplus.to/sgbeal -- -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
