This project has moved and is read-only. For the latest updates, please go here.

Hidden classes: implementation and performance question

Feb 1, 2013 at 9:38 PM
Edited Feb 1, 2013 at 9:51 PM
First of all, please let me say many thanks for your developing of this absolutely great JavaScript engine. I use it a lot, and it is really simple to use due to its excellent documentation.

Nevertheless, a question: In the source code, I saw that the engine makes use of "hidden classes"; it is, however, not clear to me what that means in the following situation.

Suppose I have the following C# class
class MyClass { public List<int> myList; }
The program will, at execution time, know at which positions the list items it needs (let's call them "a" and "b") appear in the list. (I read the MyClass objects from a database. Each MyClass object represents a record. Thus I know which columns will exist before handling the 100000 rows. However, I do not have this information at development time, nor do I know which columns the program will need exactly, so I cannot solve the problem by exposing .NET properties to JavaScript.)

Now I want to make my objects available to JavaScript. I do that by writing a wrapper class, e.g.
class Js_MyClass : ObjectInstance {
    private MyClass wrappedObj;
    public Js_MyClass ( /* ... */, MyClass wrappedObj ) : base ( /* ... */ ) {
        this.wrappedObj = wrappedObj;

    public Js_MyClass ( ... ) : base (/* ... */) { // prototype constructor
        /* here I create properties by
        DefineProperty ("a" ...);
        DefineProperty ("b", ...) using getters that access wrappedObj.myList
Is this the best (and intended) way to do it, or is there a better one? As an alternative, I could do something like
var creatorFn = engine.Evaluate (@"(function (a, b) { return ({a: a, b: b}); })") as FunctionInstance;
and then
var jsObj = creatorFn.Call (null, myClassObj.myList [aPos], myClassObj.myList [bPos]);
for each row. I want to avoid "a" and "b" being looked up in a dictionary every time they are accessed.