protected override JsTypeDefinition OnBuildRequest(Type t) { JsTypeDefinition typedefinition = new JsTypeDefinition(t.Name); //only instance /public method /prop*** //MethodInfo[] methods = t.GetMethods(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); var methods = t.GetRuntimeMethods(); foreach (var met in methods) { if (!met.IsStatic && met.IsPublic) { typedefinition.AddMember(new JsMethodDefinition(met.Name, met)); } } //var properties = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); var properties = t.GetRuntimeProperties(); //TODO finding GetProperties with BindingFlags foreach (var property in properties) { typedefinition.AddMember(new JsPropertyDefinition(property.Name, property)); } return(typedefinition); }
public void SetResultObj(object result, JsTypeDefinition jsTypeDef) { if (!jsTypeDef.IsRegisterd) { this.context.RegisterTypeDefinition(jsTypeDef); } var proxy = this.context.CreateWrapper(result, jsTypeDef); NativeV8JsInterOp.ResultSetJsValue(metArgsPtr, this.context.Converter.ToJsValue(proxy)); }
public INativeRef CreateProxyForTypeDefinition(JsTypeDefinition jsTypeDefinition) { var proxyObject = new NativeRef(nativeRefList.Count, jsTypeDefinition); //store data this side too jsTypeDefinition.nativeProxy = proxyObject; //store in exported list nativeRefList.Add(proxyObject); //register type definition NativeV8JsInterOp.RegisterTypeDef(ownerContext, jsTypeDefinition); return(proxyObject); }
public NativeJsInstanceProxy CreateProxyForObject(object o, JsTypeDefinition jsTypeDefinition) { NativeJsInstanceProxy found; if (this.createdWrappers.TryGetValue(o, out found)) { return(found); } var proxyObject = new NativeJsInstanceProxy( nativeRefList.Count, o, jsTypeDefinition); nativeRefList.Add(proxyObject); this.createdWrappers.Add(o, proxyObject); //register NativeV8JsInterOp.CreateNativePart(ownerContext, proxyObject); return(proxyObject); }
protected override JsTypeDefinition OnBuildRequest(Type t) { JsTypeDefinition typedefinition = new JsTypeDefinition(t.Name); //only instance /public method /prop*** var methods = t.GetMethods(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); foreach (var met in methods) { typedefinition.AddMember(new JsMethodDefinition(met.Name, met)); } var properties = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); foreach (var property in properties) { typedefinition.AddMember(new JsPropertyDefinition(property.Name, property)); } return(typedefinition); }
internal void CollectionTypeMembers(JsTypeDefinition jsTypeDefinition) { List <JsMethodDefinition> methods = jsTypeDefinition.GetMethods(); int j = methods.Count; for (int i = 0; i < j; ++i) { JsMethodDefinition met = methods[i]; met.SetMemberId(registerMethods.Count); registerMethods.Add(met); } List <JsPropertyDefinition> properties = jsTypeDefinition.GetProperties(); j = properties.Count; for (int i = 0; i < j; ++i) { var p = properties[i]; p.SetMemberId(registerProperties.Count); registerProperties.Add(p); } }
public static unsafe void RegisterTypeDef(JsContext context, JsTypeDefinition jsTypeDefinition) { INativeRef proxObject = jsTypeDefinition.nativeProxy; byte[] finalBuffer = null; using (MemoryStream ms = new MemoryStream()) { //serialize with our custom protocol //plan change to json ? //utf16 BinaryWriter binWriter = new BinaryWriter(ms, System.Text.Encoding.Unicode); //binay format //1. typename //2. fields //3. method //4. indexer get/set binWriter.Write((short)1);//start marker context.CollectionTypeMembers(jsTypeDefinition); //------------------------------------------------ jsTypeDefinition.WriteDefinitionToStream(binWriter); //------------------------------------------------ finalBuffer = ms.ToArray(); fixed(byte *tt = &finalBuffer[0]) { proxObject.SetUnmanagedPtr( ContextRegisterTypeDefinition( context.Handle.Handle, 0, tt, finalBuffer.Length)); } //ms.Close(); } }
public void SetOwner(JsTypeDefinition owner) { this.owner = owner; }
public void RegisterTypeDefinition(JsTypeDefinition jsTypeDefinition) { proxyStore.CreateProxyForTypeDefinition(jsTypeDefinition); }
public INativeScriptable CreateWrapper(object o, JsTypeDefinition jsTypeDefinition) { return(proxyStore.CreateProxyForObject(o, jsTypeDefinition)); }
public NativeJsInstanceProxy(int mIndex, object wrapObject, JsTypeDefinition jsTypeDef) : base(mIndex, wrapObject) { this.jsTypeDef = jsTypeDef; }