public void GetPropertyTest() { using (var tc = new TestContext()) { var evalResult = tc.Context.Evaluate( tc.Global, @"var o = { 'a': 1, 'b': 'hello', 'c': 3.5 }; o" ); Assert.AreEqual(JSValueType.OBJECT, evalResult.Value.ValueType); var obj = new JSObjectReference(evalResult); var a = obj["a"]; Assert.AreEqual(JSValueType.INT32, a.ValueType); Assert.AreEqual(1, (int)a); var b = obj["b"]; Assert.AreEqual(JSValueType.STRING, b.ValueType); Assert.AreEqual("hello", b.ToManaged(tc)); var c = obj["c"]; Assert.AreEqual(JSValueType.DOUBLE, c.ValueType); Assert.AreEqual(3.5, (double)c); var d = obj["d"]; Assert.IsTrue(d.IsNullOrUndefined); } }
public void GetPrototypeTest() { using (var tc = new TestContext()) { var evalResult = tc.Context.Evaluate( tc.Global, "[new String('a'), new Error('b'), []]" ); var arr = new JSArray(evalResult); var s = new JSObjectReference(tc, arr[0]); var e = new JSObjectReference(tc, arr[1]); var a = new JSObjectReference(tc, arr[2]); var getClassProto = (Func <string, JSObjectReference>)((name) => { JSObjectPtr p; if (!tc.Global.TryGetNested(out p, name, "prototype")) { throw new Exception("Prototype not found"); } return(new JSObjectReference(tc, p)); }); Assert.AreEqual( getClassProto("String"), s.Prototype ); Assert.AreEqual( getClassProto("Error"), e.Prototype ); Assert.AreEqual( getClassProto("Array"), a.Prototype ); } }
/// <summary> /// コンストラクタ。 /// </summary> public Offscreen(Size2D size, IJSInProcessRuntime jsRuntime) { _jsOffscreen = JSObjectReference.From(jsRuntime, "Sample.BlazorWasm.TextEditor.Offscreen.create", new { w = size.Width, h = size.Height }); _writer = new Utf8JsonWriter(_utf8jsonMemory); Init(); }
public void Write_WritesValidJson() { // Arrange var jsObjectRef = new JSObjectReference(JSRuntime, 7); // Act var json = JsonSerializer.Serialize((IJSObjectReference)jsObjectRef, JsonSerializerOptions); // Assert Assert.Equal($"{{\"__jsObjectId\":{jsObjectRef.Id}}}", json); }
public void JSObjectReference_InvokeAsync_CallsUnderlyingJSRuntimeInvokeAsync() { // Arrange var jsRuntime = new TestJSRuntime(); var jsObject = new JSObjectReference(jsRuntime, 0); // Act _ = jsObject.InvokeAsync <object>("test", "arg1", "arg2"); // Assert Assert.Equal(1, jsRuntime.BeginInvokeJSInvocationCount); }
public void NewInstanceTest() { using (var tc = new TestContext()) { tc.Context.Evaluate(tc.Global, "function cls (x) { this.x = x; };"); var cls = tc.Global["cls"]; var arg1 = new JS.Value(1.5); var instance = new JSObjectReference( tc, cls.InvokeConstructor(tc, arg1) ); Assert.AreEqual(arg1, instance["x"]); } }
public async Task JSObjectReference_Dispose_DisallowsFurtherInteropCalls() { // Arrange var jsRuntime = new TestJSRuntime(); var jsObject = new JSObjectReference(jsRuntime, 0); // Act _ = jsObject.DisposeAsync(); // Assert await Assert.ThrowsAsync <ObjectDisposedException>(async() => await jsObject.InvokeAsync <object>("test", "arg1", "arg2")); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await jsObject.InvokeAsync <object>("test", CancellationToken.None, "arg1", "arg2")); }
/// <summary> /// Gets the maximum zoom level on which the bounds fit the map view. /// </summary> /// <param name="bounds">The <see cref="LatLngBounds"/> to fit to the map.</param> /// <param name="inside">A flag indicating the fit direction. If true, method returns minimum zoom level /// on which the map fits into the bounds.</param> /// <param name="padding">The padding in pixels.</param> /// <returns></returns> public async Task <int> GetBoundsZoom(LatLngBounds bounds, bool inside = false, Point padding = null) { if (bounds.JSBinder is null) { await bounds.BindJsObjectReference(this.JSBinder); } bounds.GuardAgainstNullBinding("Cannot get bounds zoom. No JavaScript binding has been set up for the bounds parameter."); if (padding is not null) { if (padding.JSBinder is null) { await padding.BindJsObjectReference(this.JSBinder); } padding.GuardAgainstNullBinding("Cannot get bounds zoom. No JavaScript binding has been set up for the padding parameter."); } return(await JSObjectReference.InvokeAsync <int>("getBoundsZoom", bounds.JSObjectReference, inside, padding?.JSObjectReference)); }
public void CustomClassTest() { using (var tc = new TestContext()) using (var cc = new JSCustomClass(tc, "testClass", tc.Global)) { cc.Initialize(); cc.Prototype["a"] = new JSString(tc, "hello"); var jsCtor = tc.Global["testClass"]; var classObj = new JSObjectReference(tc, jsCtor); Assert.AreEqual(cc.Prototype.Pointer, classObj["prototype"].AsObject); Assert.AreEqual("hello", tc.Context.Evaluate(tc.Global, "testClass.prototype.a").Value.ToManagedString(tc)); var evalResult = tc.Context.Evaluate(tc.Global, "(new testClass())"); var resultObj = new JSObjectReference(evalResult); Assert.AreEqual(jsCtor.AsObject, resultObj["constructor"].AsObject); Assert.AreEqual("hello", resultObj["a"].ToManagedString(tc)); } }
public static JSObjectReference RoundTripJSObjectReference(JSObjectReference jsObjectReference) { return(jsObjectReference); }
/// <summary> /// Gets the size of the map container in pixels. /// </summary> /// <returns>A <see cref="Point"/> representing the size of the map container in pixels.</returns> public async Task <Point> GetSize() { return(await JSObjectReference.InvokeAsync <Point>("getSize")); }
public JsObjectReferenceDynamic(JSObjectReference module) { Module = module; }
internal async ValueTask ImportModule() { module = await jsRuntime.InvokeAsync <JSObjectReference>("import", "./_content/Append.Blazor.Printing/scripts.js"); }
/// <summary> /// コンストラクタ。 /// </summary> public Font(string family, double height, IJSInProcessRuntime jsRuntime) { _jsFont = JSObjectReference.From(jsRuntime, "Sample.BlazorWasm.TextEditor.Font.create", family, height); }
/// <summary> /// Gets the bounds of the map view in projected pixel coordinates. /// </summary> /// <returns>A <see cref="Bounds"/> representing the size of the map container in pixels.</returns> public async Task <Bounds> GetPixelBounds() { return(await JSObjectReference.InvokeAsync <Bounds>("getPixelBounds")); }
/// <summary> /// Gets the projected pixel coordinates of the top left point of the map layer. /// </summary> /// <returns>A <see cref="Point"/> representing top left point of the map in pixels.</returns> public async Task <Point> GetPixelOrigin() { return(await JSObjectReference.InvokeAsync <Point>("getPixelOrigin")); }
/// <summary> /// Gets the world's bounds in pixel coordinates. /// </summary> /// <param name="zoom">The zoom level used to calculate the bounds. Current map zoom level is used if null or omitted.</param> /// <returns>A <see cref="Bounds"/> representing the size of the map container in pixels.</returns> public async Task <Bounds> GetPixelWorldBounds(int?zoom = null) { return(await JSObjectReference.InvokeAsync <Bounds>("getPixelWorldBounds", zoom)); }
/// <summary> /// Gets the point at the centre of the map view. /// </summary> /// <returns>A <see cref="LatLng"/> representing the geographical centre of the map.</returns> public async Task <LatLng> GetCenter() { return(await JSObjectReference.InvokeAsync <LatLng>("getCenter")); }
/// <summary> /// Gets the maximum zoom level of the map view. /// </summary> /// <returns>The maximum zoom level.</returns> public async Task <int> GetMaxZoom() { return(await JSObjectReference.InvokeAsync <int>("getMaxZoom")); }
/// <summary> /// Gets the geographical bounds of the map view. /// </summary> /// <returns>A <see cref="LatLngBounds"/> object representing the geographical bounds of the map.</returns> public async Task <LatLngBounds> GetBounds() { return(await JSObjectReference.InvokeAsync <LatLngBounds>("getBounds")); }
public static int TestManagedObjArg(JSObjectReference o) { return((int)(o["x"]) * 2); }
public static async Task <JSObjectReference> RoundTripJSObjectReferenceAsync(JSObjectReference jSObjectReference) { await Task.Yield(); return(jSObjectReference); }
public static async Task <string> InvokeDisposedJSObjectReferenceExceptionAsync(JSObjectReference jsObjectReference) { try { await jsObjectReference.InvokeVoidAsync("noop"); return("No exception thrown"); } catch (JSException e) { return(e.Message); } }
/// <summary> /// コンストラクタ。 /// </summary> public InputMethod(JSObjectReference jsRefTextEditorComponent) { _jsInputMethod = JSObjectReference.From(jsRefTextEditorComponent, "bindInputMethod"); }