This project is read-only.

Return a set of functions as properties

Jan 30, 2015 at 12:53 PM
I export a .NET method
internal class Svc 
{
    [ScriptMember(inScriptName: "getNode", security: ScriptMemberSecurity.Permanent)]
    public InternalHandle GetNode(string path)
    {
    return Template.TemplateEngine._singleton.CreateNamespaceObject(path);
    }
}
this method returns an object
private ObjectHandle CreateNamespaceObject(string path)
{
    // ....
    ObjectHandle ns = CreateObject();
    ns.SetProperty("name", this.CreateValue(treeNode.Path == "/" ? "/" : Path.GetFileName(treeNode.Path)));

    FunctionTemplate funTemplate = this.CreateFunctionTemplate();
    {
        ObjectHandle entries = CreateObject();
        ns.SetProperty("entries", entries);

        if( treeNode.Entity != null )
        {
        foreach (var pair in treeNode.Entity.Entries)
        {
            entries.SetProperty(pair.Key, funTemplate.GetFunctionObject(GetEntryContent).AsInternalHandle, V8PropertyAttributes.Locked);
        }
        }
    }

    return ns;
}

private InternalHandle GetEntryContent(V8Engine engine, bool isConstructCall, InternalHandle _this, params InternalHandle[] args)
{
    return null;
}
But when I call getNode in javascript
JSON.stringify($.getNode($context.path)) 
the returned value is
{"name":"home","entries":{}}
but if I replace that line with
entries.SetProperty(pair.Key, this.CreateValue("XX"), V8PropertyAttributes.Locked);
I do see entries appears with properties.

How can I set the property to a callback function to .NET?
Jan 30, 2015 at 2:30 PM
Ah, reason found.

JSON.stringify can not print out the functions