/// <summary> /// Removes the Layer from the <see cref="Map"/> it's currently active on. /// </summary> /// <returns>The Layer.</returns> public async Task <Layer> Remove() { GuardAgainstNullBinding("Cannot remove layer from map. No JavaScript binding has been set up."); var module = await JSBinder.GetLeafletMapModule(); await module.InvokeVoidAsync("LeafletMap.Layer.remove", this.JSObjectReference); return(this); }
/// <summary> /// Adds a point to the Polyline /// </summary> /// <param name="latLng">The point to add to the Polyline.</param> /// <returns>The Polyline.</returns> public async Task <Polyline> AddLatLng(LatLng latLng) { GuardAgainstNullBinding("Cannot remove layer from map. No JavaScript binding has been set up."); var module = await JSBinder.GetLeafletMapModule(); await module.InvokeVoidAsync("LeafletMap.Polyline.addLatLng", this.JSObjectReference, latLng); return(this); }
public void WebBind() { jsListener = new JSBinder(this.Controller); jsListener.MaxAmountToBuy = decimal.ToInt32(numMaxAmount2Buy.Value); jsListener.ItemPriority = decimal.ToSingle(numPriority.Value); webClient = new ChromiumWebBrowser("https://www.pathofexile.com/trade"); webClient.JavascriptObjectRepository.Register("netListner", jsListener, isAsync: true, options: BindingOptions.DefaultBinder); webClient.Dock = DockStyle.Fill; this.pnlWeb.Controls.Add(webClient); webClient.Dock = DockStyle.Fill; }
/// <summary> /// Adds the layer to a <see cref="Map"/>. /// </summary> /// <param name="map">The <see cref="Map"/> to add the Layer to.</param> /// <returns>The Layer.</returns> public async Task <Layer> AddTo(Map map) { if (JSBinder is null) { await BindJsObjectReference(map.JSBinder); } GuardAgainstNullBinding("Cannot add layer to map. No JavaScript binding has been set up."); var module = await JSBinder.GetLeafletMapModule(); await module.InvokeVoidAsync("LeafletMap.Layer.addTo", this.JSObjectReference, map.JSObjectReference); return(this); }
/// <summary> /// Sets the view of the map with the given centre and zoom. /// </summary> /// <param name="center">A <see cref="LatLng"/> representing the geogrpahical centre of the map.</param> /// <param name="zoom">The zoom level of the map.</param> /// <returns>The Map.</returns> public async Task <Map> SetView(LatLng center, int zoom) { if (center.JSBinder is null) { await center.BindJsObjectReference(this.JSBinder); } center.GuardAgainstNullBinding("Cannot set map view. No JavaScript binding has been set up for the center argument."); var module = await JSBinder.GetLeafletMapModule(); await module.InvokeVoidAsync("LeafletMap.Map.setView", this.JSObjectReference, center.JSObjectReference, zoom); return(this); }
internal MemberInfo[] GetDefaultMembers() { MemberInfo[] defaultMembers = this.defaultMembers; if (defaultMembers == null) { defaultMembers = JSBinder.GetDefaultMembers(this.type); if (defaultMembers == null) { defaultMembers = new MemberInfo[0]; } WrapMembers(this.defaultMembers = defaultMembers); } return(defaultMembers); }
internal MemberInfo[] GetDefaultMembers() { MemberInfo[] result = this.defaultMembers; if (result == null) { result = JSBinder.GetDefaultMembers(this.type); if (result == null) { result = new MemberInfo[0]; } TypeReflector.WrapMembers(this.defaultMembers = result); } return(result); }
internal override void ResolveCall(ASTList args, IReflect[] argIRs, bool constructor, bool brackets) { string str; if (constructor || !brackets) { if (this.isSuper) { base.context.HandleError(JSError.IllegalUseOfSuper); return; } base.context.HandleError(JSError.IllegalUseOfThis); return; } IReflect reflect = this.InferType(null); Type t = (reflect is Type) ? ((Type)reflect) : null; if (reflect is ClassScope) { t = ((ClassScope)reflect).GetBakedSuperType(); } MemberInfo[] defaultMembers = JSBinder.GetDefaultMembers(t); if ((defaultMembers != null) && (defaultMembers.Length > 0)) { try { this.method = JSBinder.SelectMethod(defaultMembers, argIRs); if (this.method == null) { goto Label_00C5; } if (!Binding.CheckParameters(this.method.GetParameters(), argIRs, args, base.context, 0, false, true)) { this.method = null; } } catch (AmbiguousMatchException) { base.context.HandleError(JSError.AmbiguousMatch); } return; } Label_00C5: str = (reflect is ClassScope) ? ((ClassScope)reflect).GetName() : ((Type)reflect).Name; base.context.HandleError(JSError.NotIndexable, str); }
internal override void ResolveCall(ASTList args, IReflect[] argIRs, bool constructor, bool brackets) { if (constructor || !brackets) { if (this.isSuper) { this.context.HandleError(JSError.IllegalUseOfSuper); } else { this.context.HandleError(JSError.IllegalUseOfThis); } return; } IReflect ir = this.InferType(null); Type t = ir is Type ? (Type)ir : null; if (ir is ClassScope) { t = ((ClassScope)ir).GetBakedSuperType(); } MemberInfo[] defaultMembers = JSBinder.GetDefaultMembers(t); if (defaultMembers != null && defaultMembers.Length > 0) { try{ this.method = JSBinder.SelectMethod(defaultMembers, argIRs); //Returns property getters as well if (this.method != null) { if (!Binding.CheckParameters(this.method.GetParameters(), argIRs, args, this.context, 0, false, true)) { this.method = null; } return; } }catch (AmbiguousMatchException) { this.context.HandleError(JSError.AmbiguousMatch); return; } } String tname = ir is ClassScope ? ((ClassScope)ir).GetName() : ((Type)ir).Name; this.context.HandleError(JSError.NotIndexable, tname); }
internal void ResolveAssignmentToDefaultIndexedProperty(ASTList args, IReflect[] argIRs, AST rhvalue) { string str; IReflect reflect = this.InferType(null); Type t = (reflect is Type) ? ((Type)reflect) : null; if (reflect is ClassScope) { t = ((ClassScope)reflect).GetBakedSuperType(); } MemberInfo[] defaultMembers = JSBinder.GetDefaultMembers(t); if ((defaultMembers != null) && (defaultMembers.Length > 0)) { try { PropertyInfo prop = JSBinder.SelectProperty(defaultMembers, argIRs); if (prop == null) { goto Label_00B1; } this.method = JSProperty.GetSetMethod(prop, true); if (this.method == null) { base.context.HandleError(JSError.AssignmentToReadOnly, true); } if (!Binding.CheckParameters(prop.GetIndexParameters(), argIRs, args, base.context, 0, false, true)) { this.method = null; } } catch (AmbiguousMatchException) { base.context.HandleError(JSError.AmbiguousMatch); } return; } Label_00B1: str = (reflect is ClassScope) ? ((ClassScope)reflect).GetName() : ((Type)reflect).Name; base.context.HandleError(JSError.NotIndexable, str); }
internal void ResolveAssignmentToDefaultIndexedProperty(ASTList args, IReflect[] argIRs, AST rhvalue) { IReflect ir = this.InferType(null); Type t = ir is Type ? (Type)ir : null; if (ir is ClassScope) { t = ((ClassScope)ir).GetBakedSuperType(); } MemberInfo[] defaultMembers = JSBinder.GetDefaultMembers(t); if (defaultMembers != null && defaultMembers.Length > 0) { try{ PropertyInfo prop = JSBinder.SelectProperty(defaultMembers, argIRs); //Returns property getters as well if (prop != null) { this.method = JSProperty.GetSetMethod(prop, true); if (this.method == null) { this.context.HandleError(JSError.AssignmentToReadOnly, true); } if (!Binding.CheckParameters(prop.GetIndexParameters(), argIRs, args, this.context, 0, false, true)) { this.method = null; } return; } }catch (AmbiguousMatchException) { this.context.HandleError(JSError.AmbiguousMatch); return; } } String tname = ir is ClassScope ? ((ClassScope)ir).GetName() : ((Type)ir).Name; this.context.HandleError(JSError.NotIndexable, tname); }
/// <summary> /// Constructs a <see cref="GeolocationService"/> object. /// </summary> /// <param name="JSRuntime"></param> public GeolocationService(IJSRuntime JSRuntime) { _jsBinder = new JSBinder(JSRuntime, "./_content/Darnton.Blazor.DeviceInterop/js/Geolocation.js"); }
protected MethodInfo GetOperator(IReflect ir1, IReflect ir2) { if (ir1 is ClassScope) { ir1 = ((ClassScope)ir1).GetUnderlyingTypeIfEnum(); } if (ir2 is ClassScope) { ir2 = ((ClassScope)ir2).GetUnderlyingTypeIfEnum(); } Type t1 = ir1 is Type ? (Type)ir1 : Typeob.Object; Type t2 = ir2 is Type ? (Type)ir2 : Typeob.Object; if (this.type1 == t1 && this.type2 == t2) { return(this.operatorMeth); } this.type1 = t1; this.type2 = t2; this.operatorMeth = null; if (t1 == Typeob.String || Convert.IsPrimitiveNumericType(ir1) || Typeob.JSObject.IsAssignableFrom(t1)) { t1 = null; } if (t2 == Typeob.String || Convert.IsPrimitiveNumericType(ir2) || Typeob.JSObject.IsAssignableFrom(t2)) { t2 = null; } if (t1 == null && t2 == null) { return(null); } //One of the operands is an object of a type that might have a user defined operator. String name = "op_NoSuchOp"; switch (this.operatorTok) { case JSToken.BitwiseAnd: name = "op_BitwiseAnd"; break; case JSToken.BitwiseOr: name = "op_BitwiseOr"; break; case JSToken.BitwiseXor: name = "op_ExclusiveOr"; break; case JSToken.Divide: name = "op_Division"; break; case JSToken.Equal: name = "op_Equality"; break; case JSToken.GreaterThan: name = "op_GreaterThan"; break; case JSToken.GreaterThanEqual: name = "op_GreaterThanOrEqual"; break; case JSToken.LeftShift: name = "op_LeftShift"; break; case JSToken.LessThan: name = "op_LessThan"; break; case JSToken.LessThanEqual: name = "op_LessThanOrEqual"; break; case JSToken.Minus: name = "op_Subtraction"; break; case JSToken.Modulo: name = "op_Modulus"; break; case JSToken.Multiply: name = "op_Multiply"; break; case JSToken.NotEqual: name = "op_Inequality"; break; case JSToken.Plus: name = "op_Addition"; break; case JSToken.RightShift: name = "op_RightShift"; break; } Type[] types = new Type[] { this.type1, this.type2 }; if (t1 == t2) { MethodInfo op = t1.GetMethod(name, BindingFlags.Public | BindingFlags.Static, JSBinder.ob, types, null); if (op != null && (op.Attributes & MethodAttributes.SpecialName) != 0 && op.GetParameters().Length == 2) { this.operatorMeth = op; } } else { //Search both operand types, but only if there is a possibility that they might have operators defined on them MethodInfo op1 = t1 == null ? null : t1.GetMethod(name, BindingFlags.Public | BindingFlags.Static, JSBinder.ob, types, null); MethodInfo op2 = t2 == null ? null : t2.GetMethod(name, BindingFlags.Public | BindingFlags.Static, JSBinder.ob, types, null); this.operatorMeth = JSBinder.SelectOperator(op1, op2, this.type1, this.type2); //Choose the better of the two } if (this.operatorMeth != null) { this.operatorMeth = new JSMethodInfo(this.operatorMeth); } return(this.operatorMeth); }
/// <summary> /// Constructs a <see cref="GeolocationService"/> object. /// </summary> /// <param name="JSRuntime"></param> public GeolocationService(IJSRuntime JSRuntime) { _jsBinder = new JSBinder(JSRuntime, "./js/geolocation.js"); }
private void BindName(JSField inferenceTarget) { MemberInfo[] members = null; this.rootObject = this.rootObject.PartiallyEvaluate(); IReflect obType = this.rootObjectInferredType = this.rootObject.InferType(inferenceTarget); if (this.rootObject is ConstantWrapper) { Object ob = Convert.ToObject2(this.rootObject.Evaluate(), this.Engine); if (ob == null) { this.rootObject.context.HandleError(JSError.ObjectExpected); return; } ClassScope csc = ob as ClassScope; Type t = ob as Type; if (csc != null || t != null) { //object is a type. Look for static members on the type only. If none are found, look for instance members on type Type. if (csc != null) { this.members = members = csc.GetMember(this.name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly); } else { this.members = members = t.GetMember(this.name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly); } if (members.Length > 0) { return; //found a binding } //Look for instance members on type Type this.members = members = Typeob.Type.GetMember(this.name, BindingFlags.Public | BindingFlags.Instance); return; } Namespace ns = ob as Namespace; if (ns != null) { String fullname = ns.Name + "." + this.name; csc = this.Engine.GetClass(fullname); if (csc != null) { FieldAttributes attrs = FieldAttributes.Literal; if ((csc.owner.attributes & TypeAttributes.Public) == 0) { attrs |= FieldAttributes.Private; } this.members = new MemberInfo[] { new JSGlobalField(null, this.name, csc, attrs) }; return; } else { t = this.Engine.GetType(fullname); if (t != null) { this.members = new MemberInfo[] { t }; return; } } } else if (ob is MathObject || ob is ScriptFunction && !(ob is FunctionObject)) //It is a built in constructor function { obType = (IReflect)ob; } } obType = this.ProvideWrapperForPrototypeProperties(obType); //Give up and go late bound if not enough is known about the object at compile time. if (obType == Typeob.Object && !this.isNonVirtual) //The latter provides for super in classes that extend System.Object { this.members = new MemberInfo[0]; return; } Type ty = obType as Type; //Interfaces are weird, call a helper if (ty != null && ty.IsInterface) { this.members = JSBinder.GetInterfaceMembers(this.name, ty); return; } ClassScope cs = obType as ClassScope; if (cs != null && cs.owner.isInterface) { this.members = cs.owner.GetInterfaceMember(this.name); return; } //Now run up the inheritance chain until a member is found while (obType != null) { cs = obType as ClassScope; if (cs != null) { //The FlattenHierachy flag here tells ClassScope to add in any overloads found on base classes members = this.members = obType.GetMember(this.name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.FlattenHierarchy); if (members.Length > 0) { return; } obType = cs.GetSuperType(); continue; } ty = obType as Type; if (ty == null) //Dealing with the global scope via the this literal or with a built in object in fast mode { this.members = obType.GetMember(this.name, BindingFlags.Public | BindingFlags.Instance); return; } members = this.members = ty.GetMember(this.name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly); if (members.Length > 0) { MemberInfo mem = LateBinding.SelectMember(members); if (mem == null) { //Found a method or methods. Need to add any overloads found in base classes. //Do another lookup, this time with the DeclaredOnly flag cleared and asking only for methods members = this.members = ty.GetMember(this.name, MemberTypes.Method, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (members.Length == 0) //Dealing with an indexed property, ask again { this.members = ty.GetMember(this.name, MemberTypes.Property, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); } } return; } obType = ty.BaseType; } }
private void BindName(JSField inferenceTarget) { MemberInfo[] mems = null; this.rootObject = this.rootObject.PartiallyEvaluate(); IReflect obType = this.rootObjectInferredType = this.rootObject.InferType(inferenceTarget); if (this.rootObject is ConstantWrapper) { object obj2 = Microsoft.JScript.Convert.ToObject2(this.rootObject.Evaluate(), base.Engine); if (obj2 == null) { this.rootObject.context.HandleError(JSError.ObjectExpected); return; } ClassScope scope = obj2 as ClassScope; Type type = obj2 as Type; if ((scope != null) || (type != null)) { if (scope != null) { base.members = mems = scope.GetMember(base.name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly); } else { base.members = mems = type.GetMember(base.name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly); } if (mems.Length <= 0) { base.members = mems = Typeob.Type.GetMember(base.name, BindingFlags.Public | BindingFlags.Instance); } return; } Namespace namespace2 = obj2 as Namespace; if (namespace2 != null) { string className = namespace2.Name + "." + base.name; scope = base.Engine.GetClass(className); if (scope != null) { FieldAttributes literal = FieldAttributes.Literal; if ((scope.owner.attributes & TypeAttributes.Public) == TypeAttributes.AnsiClass) { literal |= FieldAttributes.Private; } base.members = new MemberInfo[] { new JSGlobalField(null, base.name, scope, literal) }; return; } type = base.Engine.GetType(className); if (type != null) { base.members = new MemberInfo[] { type }; return; } } else if ((obj2 is MathObject) || ((obj2 is ScriptFunction) && !(obj2 is FunctionObject))) { obType = (IReflect)obj2; } } obType = this.ProvideWrapperForPrototypeProperties(obType); if ((obType == Typeob.Object) && !base.isNonVirtual) { base.members = new MemberInfo[0]; } else { Type t = obType as Type; if ((t != null) && t.IsInterface) { base.members = JSBinder.GetInterfaceMembers(base.name, t); } else { ClassScope scope2 = obType as ClassScope; if ((scope2 != null) && scope2.owner.isInterface) { base.members = scope2.owner.GetInterfaceMember(base.name); } else { while (obType != null) { scope2 = obType as ClassScope; if (scope2 != null) { mems = base.members = obType.GetMember(base.name, BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); if (mems.Length > 0) { return; } obType = scope2.GetSuperType(); } else { t = obType as Type; if (t == null) { base.members = obType.GetMember(base.name, BindingFlags.Public | BindingFlags.Instance); return; } mems = base.members = t.GetMember(base.name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); if (mems.Length > 0) { if (LateBinding.SelectMember(mems) == null) { mems = base.members = t.GetMember(base.name, MemberTypes.Method, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); if (mems.Length == 0) { base.members = t.GetMember(base.name, MemberTypes.Property, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); } } return; } obType = t.BaseType; } } } } } }
protected MethodInfo GetOperator(IReflect ir1, IReflect ir2) { if (ir1 is ClassScope) { ir1 = ((ClassScope)ir1).GetUnderlyingTypeIfEnum(); } if (ir2 is ClassScope) { ir2 = ((ClassScope)ir2).GetUnderlyingTypeIfEnum(); } Type c = (ir1 is Type) ? ((Type)ir1) : Typeob.Object; Type type2 = (ir2 is Type) ? ((Type)ir2) : Typeob.Object; if ((this.type1 != c) || (this.type2 != type2)) { this.type1 = c; this.type2 = type2; this.operatorMeth = null; if (((c == Typeob.String) || Microsoft.JScript.Convert.IsPrimitiveNumericType(ir1)) || Typeob.JSObject.IsAssignableFrom(c)) { c = null; } if (((type2 == Typeob.String) || Microsoft.JScript.Convert.IsPrimitiveNumericType(ir2)) || Typeob.JSObject.IsAssignableFrom(type2)) { type2 = null; } if ((c == null) && (type2 == null)) { return(null); } string name = "op_NoSuchOp"; switch (this.operatorTok) { case JSToken.FirstBinaryOp: name = "op_Addition"; break; case JSToken.Minus: name = "op_Subtraction"; break; case JSToken.BitwiseOr: name = "op_BitwiseOr"; break; case JSToken.BitwiseXor: name = "op_ExclusiveOr"; break; case JSToken.BitwiseAnd: name = "op_BitwiseAnd"; break; case JSToken.Equal: name = "op_Equality"; break; case JSToken.NotEqual: name = "op_Inequality"; break; case JSToken.GreaterThan: name = "op_GreaterThan"; break; case JSToken.LessThan: name = "op_LessThan"; break; case JSToken.LessThanEqual: name = "op_LessThanOrEqual"; break; case JSToken.GreaterThanEqual: name = "op_GreaterThanOrEqual"; break; case JSToken.LeftShift: name = "op_LeftShift"; break; case JSToken.RightShift: name = "op_RightShift"; break; case JSToken.Multiply: name = "op_Multiply"; break; case JSToken.Divide: name = "op_Division"; break; case JSToken.Modulo: name = "op_Modulus"; break; } Type[] types = new Type[] { this.type1, this.type2 }; if (c == type2) { MethodInfo info = c.GetMethod(name, BindingFlags.Public | BindingFlags.Static, JSBinder.ob, types, null); if (((info != null) && ((info.Attributes & MethodAttributes.SpecialName) != MethodAttributes.PrivateScope)) && (info.GetParameters().Length == 2)) { this.operatorMeth = info; } } else { MethodInfo info2 = (c == null) ? null : c.GetMethod(name, BindingFlags.Public | BindingFlags.Static, JSBinder.ob, types, null); MethodInfo info3 = (type2 == null) ? null : type2.GetMethod(name, BindingFlags.Public | BindingFlags.Static, JSBinder.ob, types, null); this.operatorMeth = JSBinder.SelectOperator(info2, info3, this.type1, this.type2); } if (this.operatorMeth != null) { this.operatorMeth = new JSMethodInfo(this.operatorMeth); } } return(this.operatorMeth); }