public JSObjectDef(object target, Type targetType, string member, JSBindingOptions options) { if (string.IsNullOrEmpty(member)) { throw new ArgumentNullException(member); } if (target == null) { throw new ArgumentNullException("target"); } if (targetType == null) { throw new ArgumentNullException("targetType"); } // validate options here if (!targetType.IsAssignableFrom(target.GetType())) { throw new JSBindingException(string.Format( "ScriptableObject is not assignable from '{0}'.", target.GetType().FullName )); } this.member = member; this.target = target; this.targetType = targetType; this.options = options; }
public void BindJSObject(string name, object obj, Type type, JSBindingOptions options) { if (this.owner != null && (options & JSBindingOptions.Extension) != 0) { throw new NotSupportedException("Extension can be bound only on global context. Use Cef.JSBinding instead."); } var def = new JSObjectDef(obj, type, name, options); if (this.objects.ContainsKey(def.MemberName)) { throw new JSBindingException(string.Format( "JSObject with name '{0}' already registered.", name )); } // force binder creation var binder = ScriptableObjectBinder.Get(def.TargetType, options); if (def.Extension) { // Register V8 extension var javaScriptCode = binder.CreateJavaScriptExtension(def.MemberName); var handler = new ScriptableObjectV8Handler(binder, def.Target, true); if (!Cef.RegisterExtension(def.ExtensionName, javaScriptCode, (CefV8Handler)handler)) { throw new InvalidOperationException("Cef.RegisterExtension failed."); } } this.objects.Add(def.MemberName, def); }
private ScriptableObjectBinder(Type type, JSBindingOptions options, NamingConvention namingConvention) { if (type == null) throw new ArgumentNullException("type"); if (!type.IsClass && !type.IsInterface) throw new ArgumentException("The type must be a class or interface."); this.type = type; var attr = GetJSObjectAttribute(this.type); if (attr != null) { if (options == JSBindingContext.DefaultOptions) { this.options = attr.Options; } } else { this.options = options; } this.namingConvention = namingConvention; this.Create(); Debug.Assert(this.dispatchTable != null); Debug.Assert(this.propertyDispatchTable != null); if ((this.options & JSBindingOptions.LazyCompile) == 0) { this.Compile(); } }
public void BindJSObject(string name, object obj, JSBindingOptions options) { if (obj == null) { throw new ArgumentNullException("obj"); } this.BindJSObject(name, obj, obj.GetType(), DefaultOptions); }
private JSObjectBinder(Type type, JSBindingOptions options, NamingConvention namingConvention) { if (type == null) throw new ArgumentNullException("type"); if (!type.IsInterface) throw new ArgumentException("Only interface type allowed.", "type"); this.type = type; this.options = options; this.namingConvention = namingConvention; this.proxyType = JSObjectTypeBuilder.Create(type, options, namingConvention); }
public static JSObjectBinder Get(Type type, JSBindingOptions options) { lock (binders) { JSObjectBinder value; if (binders.TryGetValue(type, out value)) { return value; } else { var binder = new JSObjectBinder(type, options); binders[type] = binder; return binder; } } }
public static ScriptableObjectBinder Get(Type type, JSBindingOptions options) { lock (binders) { ScriptableObjectBinder value; if (binders.TryGetValue(type, out value)) { return(value); } else { var binder = new ScriptableObjectBinder(type, options); binders[type] = binder; return(binder); } } }
private JSObjectBinder(Type type, JSBindingOptions options, NamingConvention namingConvention) { if (type == null) { throw new ArgumentNullException("type"); } if (!type.IsInterface) { throw new ArgumentException("Only interface type allowed.", "type"); } this.type = type; this.options = options; this.namingConvention = namingConvention; this.proxyType = JSObjectTypeBuilder.Create(type, options, namingConvention); }
public JSObjectDef(object target, Type targetType, string member, JSBindingOptions options) { if (string.IsNullOrEmpty(member)) throw new ArgumentNullException(member); if (target == null) throw new ArgumentNullException("target"); if (targetType == null) throw new ArgumentNullException("targetType"); // validate options here if (!targetType.IsAssignableFrom(target.GetType())) { throw new JSBindingException(string.Format( "ScriptableObject is not assignable from '{0}'.", target.GetType().FullName )); } this.member = member; this.target = target; this.targetType = targetType; this.options = options; }
private ScriptableObjectBinder(Type type, JSBindingOptions options, NamingConvention namingConvention) { if (type == null) { throw new ArgumentNullException("type"); } if (!type.IsClass && !type.IsInterface) { throw new ArgumentException("The type must be a class or interface."); } this.type = type; var attr = GetJSObjectAttribute(this.type); if (attr != null) { if (options == JSBindingContext.DefaultOptions) { this.options = attr.Options; } } else { this.options = options; } this.namingConvention = namingConvention; this.Create(); Debug.Assert(this.dispatchTable != null); Debug.Assert(this.propertyDispatchTable != null); if ((this.options & JSBindingOptions.LazyCompile) == 0) { this.Compile(); } }
public static Type Create(Type targetType, JSBindingOptions options, NamingConvention namingConvention) { Initialize(); // create the type TypeBuilder type = module.DefineType( string.Format("{0}.{1}Proxy", namespaceName, targetType.FullName), TypeAttributes.Public | TypeAttributes.Sealed, typeof(JSObjectBase), new Type[] { targetType } ); // TODO: properties // create members foreach (var method in targetType.GetMethods()) { // explicit interface implementation MethodBuilder mb = type.DefineMethod( targetType.Name + "." + method.Name, MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Virtual | MethodAttributes.Final, method.ReturnType, method.GetParameters().Select(_ => _.ParameterType).ToArray() ); type.DefineMethodOverride(mb, method); var emit = new EmitHelper(mb.GetILGenerator()); emit.LdArg(1) .Ret() ; } return type.CreateType(); }
public static Type Create(Type targetType, JSBindingOptions options, NamingConvention namingConvention) { Initialize(); // create the type TypeBuilder type = module.DefineType( string.Format("{0}.{1}Proxy", namespaceName, targetType.FullName), TypeAttributes.Public | TypeAttributes.Sealed, typeof(JSObjectBase), new Type[] { targetType } ); // TODO: properties // create members foreach (var method in targetType.GetMethods()) { // explicit interface implementation MethodBuilder mb = type.DefineMethod( targetType.Name + "." + method.Name, MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Virtual | MethodAttributes.Final, method.ReturnType, method.GetParameters().Select(_ => _.ParameterType).ToArray() ); type.DefineMethodOverride(mb, method); var emit = new EmitHelper(mb.GetILGenerator()); emit.LdArg(1) .Ret() ; } return(type.CreateType()); }
private ScriptableObjectBinder(Type type, JSBindingOptions options) : this(type, options, NamingConvention.Default) { }
public void BindJSObject(object obj, Type type, JSBindingOptions options) { this.JSBindingContext.BindJSObject(obj, type, options); }
public void BindJSObject <T>(T obj, JSBindingOptions options) where T : class { this.JSBindingContext.BindJSObject <T>(obj, options); }
public void BindJSObject(string name, object obj, JSBindingOptions options) { this.JSBindingContext.BindJSObject(name, obj, options); }
public JSObjectAttribute(JSBindingOptions bindingFlags) { this.options = bindingFlags; }
public void BindJSObject <T>(T obj, JSBindingOptions options) where T : class { this.BindJSObject(obj, typeof(T), options); }
public JSObjectAttribute(JSBindingOptions bindingFlags) { this.options = bindingFlags; }
private ScriptableObjectBinder(Type type, JSBindingOptions options) : this(type, options, NamingConvention.Default) { }
public void BindJSObject(object obj, Type type, JSBindingOptions options) { this.BindJSObject(GetMemberNameForType(type), obj, type, options); }
public void BindJSObject <T>(string name, T obj, JSBindingOptions options) where T : class { this.JSBindingContext.BindJSObject <T>(name, obj, options); }