public void SetNormalArrayWorks() { var arr = new Uint8ClampedArray(4); arr.Set(new byte[] { 3, 6, 7 }); AssertContent(arr, new[] { 3, 6, 7, 0 }, "Content"); }
public void BufferPropertyWorks() { var buf = new ArrayBuffer(100); var arr = new Uint8ClampedArray(buf); Assert.True(arr.Buffer == buf, "Should be correct"); }
public void SetNormalArrayWithOffsetWorks() { var arr = new Uint8ClampedArray(6); arr.Set(new byte[] { 3, 6, 7 }, 2); AssertContent(arr, new[] { 0, 0, 3, 6, 7, 0 }, "Content"); }
public void IndexOfWorks() { var arr = new Uint8ClampedArray(new byte[] { 3, 6, 2, 9, 5 }); Assert.AreEqual(arr.IndexOf(9), 3, "9"); Assert.AreEqual(arr.IndexOf(1), -1, "1"); }
public void ContainsWorks() { var arr = new Uint8ClampedArray(new byte[] { 3, 6, 2, 9, 5 }); Assert.IsTrue(arr.Contains(9), "9"); Assert.IsFalse(arr.Contains(1), "1"); }
public void ByteOffsetPropertyWorks() { var buf = new ArrayBuffer(100); var arr = new Uint8ClampedArray(buf, 32); Assert.AreEqual(arr.ByteOffset, 32, "Should be correct"); }
public static Task <byte[]> readAsBytes(this File f) { // X:\jsc.svn\examples\javascript\io\WebApplicationSelectingFile\WebApplicationSelectingFile\Application.cs // X:\jsc.svn\examples\javascript\io\DropFileForMD5Experiment\DropFileForMD5Experiment\Application.cs var y = new TaskCompletionSource <byte[]>(); var x = new FileReader(); //Console.WriteLine("readAsText FileReader"); x.onload = new Action( delegate { var a = (ArrayBuffer)x.result; var u8c = new Uint8ClampedArray(array: a); // X:\jsc.svn\core\ScriptCoreLib\JavaScript\BCLImplementation\System\Net\WebClient.cs y.SetResult((byte[])u8c); } ); // partial build? // move to .Async? x.readAsArrayBuffer(f); //Console.WriteLine("readAsText FileReader readAsText"); return(y.Task); }
public static void Uint8ClampedArrayFromArrayBuffer(Function objectPrototype) { Uint8ClampedArray from = new Uint8ClampedArray(new ArrayBuffer(50)); Assert.True(from.Length == 50); Assert.Equal("[object Uint8ClampedArray]", objectPrototype.Call(from)); }
public void LengthConstructorWorks() { var arr = new Uint8ClampedArray(13); Assert.IsTrue((object)arr is Uint8ClampedArray, "is Uint8ClampedArray"); Assert.AreEqual(arr.Length, 13, "Length"); }
public static Task<byte[]> readAsBytes(this File f) { // X:\jsc.svn\examples\javascript\io\WebApplicationSelectingFile\WebApplicationSelectingFile\Application.cs // X:\jsc.svn\examples\javascript\io\DropFileForMD5Experiment\DropFileForMD5Experiment\Application.cs var y = new TaskCompletionSource<byte[]>(); var x = new FileReader(); //Console.WriteLine("readAsText FileReader"); x.onload = new Action( delegate { var a = (ArrayBuffer)x.result; var u8c = new Uint8ClampedArray(array: a); // X:\jsc.svn\core\ScriptCoreLib\JavaScript\BCLImplementation\System\Net\WebClient.cs y.SetResult((byte[])u8c); } ); // partial build? // move to .Async? x.readAsArrayBuffer(f); //Console.WriteLine("readAsText FileReader readAsText"); return y.Task; }
public void IndexingWorks() { var arr = new Uint8ClampedArray(3); arr[1] = 42; AssertContent(arr, new[] { 0, 42, 0 }, "Content"); Assert.AreEqual(42, arr[1], "[1]"); }
public static void Uint8ClampedArrayFrom(Function objectPrototype) { var clamped = new byte[50]; Uint8ClampedArray from = Uint8ClampedArray.From(clamped); Assert.Equal(50, from.Length); Assert.Equal("[object Uint8ClampedArray]", objectPrototype.Call(from)); }
public void ArrayBufferConstructorWorks() { var buf = new ArrayBuffer(80); var arr = new Uint8ClampedArray(buf); Assert.IsTrue((object)arr is Uint8ClampedArray); Assert.IsTrue(arr.Buffer == buf, "buffer"); Assert.AreEqual(arr.Length, 80, "length"); }
public void SubarrayWithBeginWorks() { var source = new Uint8ClampedArray(10); var arr = source.SubArray(3); Assert.False(arr == source, "Should be a new array"); Assert.True(arr.Buffer == source.Buffer, "Should be the same buffer"); Assert.AreEqual(3, arr.ByteOffset, "ByteOffset should be correct"); }
public void CopyConstructorWorks() { var source = new Uint8ClampedArray(new byte[] { 3, 8, 4 }); var arr = new Uint8ClampedArray(source); Assert.True(arr != source, "New object"); Assert.True((object)arr is Uint8ClampedArray, "is Uint8ClampedArray"); AssertContent(arr, new[] { 3, 8, 4 }, "content"); }
public void ArrayBufferWithOffsetConstructorWorks() { var buf = new ArrayBuffer(80); var arr = new Uint8ClampedArray(buf, 16); Assert.True((object)arr is Uint8ClampedArray); Assert.True(arr.Buffer == buf, "buffer"); Assert.AreEqual(64, arr.Length, "length"); }
public ImageData(byte[] image, int imageWidth, int imageHeight) { var uint8ClampedArray = new Uint8ClampedArray(image.Length); uint8ClampedArray.CopyFrom(image); var imageDataObject = (JSObject)Runtime.GetGlobalObject("ImageData"); Handle = Runtime.NewJSObject(imageDataObject, uint8ClampedArray, imageWidth, imageHeight); }
public void SubarrayWithBeginAndEndWorks() { var source = new Uint8ClampedArray(10); var arr = source.Subarray(3, 7); Assert.IsFalse(arr == source, "Should be a new array"); Assert.IsTrue(arr.Buffer == source.Buffer, "Should be the same buffer"); Assert.AreEqual(arr.ByteOffset, 3, "ByteOffset should be correct"); Assert.AreEqual(arr.Length, 4, "Length should be correct"); }
public void ForeachWorks() { var arr = new Uint8ClampedArray(new byte[] { 3, 6, 2, 9, 5 }); var l = new List <int>(); foreach (var i in arr) { l.Add(i); } Assert.AreEqual(l, new[] { 3, 6, 2, 9, 5 }); }
public void ForeachWorks_SPI_1401() { var arr = new Uint8ClampedArray(new byte[] { 3, 6, 2, 9, 5 }); var l = new List <int>(); // #1401 foreach (var i in arr) { l.Add(i); } Assert.AreEqual(l.ToArray(), new[] { 3, 6, 2, 9, 5 }); }
public void GetEnumeratorWorks() { var arr = new Uint8ClampedArray(new byte[] { 3, 6, 2, 9, 5 }); var l = new List <int>(); var enm = arr.GetEnumerator(); while (enm.MoveNext()) { l.Add(enm.Current); } Assert.AreEqual(l, new[] { 3, 6, 2, 9, 5 }); }
private void AssertContent(Uint8ClampedArray actual, int[] expected, string message) { if (actual.Length != expected.Length) { Assert.Fail(message + ": Expected length " + expected.Length + ", actual: " + actual.Length); return; } for (int i = 0; i < expected.Length; i++) { if (actual[i] != expected[i]) { Assert.Fail(message + ": Position " + i + ": expected " + expected[i] + ", actual: " + actual[i]); return; } } Assert.True(true, message); }
public void TypePropertiesAreCorrect() { Assert.AreEqual(typeof(Uint8ClampedArray).FullName, "Uint8ClampedArray", "FullName"); var interfaces = typeof(Uint8ClampedArray).GetInterfaces(); Assert.AreEqual(interfaces.Length, 3, "Interface count should be 3"); Assert.IsTrue(interfaces.Contains(typeof(IEnumerable <byte>)), "Interfaces should contain IEnumerable<byte>"); Assert.IsTrue(interfaces.Contains(typeof(ICollection <byte>)), "Interfaces should contain ICollection<byte>"); Assert.IsTrue(interfaces.Contains(typeof(IList <byte>)), "Interfaces should contain IList<byte>"); object arr = new Uint8ClampedArray(0); Assert.IsTrue(arr is Uint8ClampedArray, "Is Uint8ClampedArray"); Assert.IsTrue(arr is IEnumerable <byte>, "Is IEnumerable<byte>"); Assert.IsTrue(arr is ICollection <byte>, "Is ICollection<byte>"); Assert.IsTrue(arr is IList <byte>, "Is IList<byte>"); }
public static void TestUseCase(Assert assert) { assert.Expect(10); var array1 = new Int8Array(1); Bridge550.TestMethod(array1, "Int8Array", assert); var array2 = new Uint8Array(1); Bridge550.TestMethod(array2, "Uint8Array", assert); var array3 = new Uint8ClampedArray(1); Bridge550.TestMethod(array3, "Uint8ClampedArray", assert); var array4 = new Int16Array(1); Bridge550.TestMethod(array4, "Int16Array", assert); var array5 = new Uint16Array(1); Bridge550.TestMethod(array5, "Uint16Array", assert); var array6 = new Int32Array(1); Bridge550.TestMethod(array6, "Int32Array", assert); var array7 = new Uint32Array(1); Bridge550.TestMethod(array7, "Uint32Array", assert); var array8 = new Float32Array(1); Bridge550.TestMethod(array8, "Float32Array", assert); var array9 = new Float64Array(1); Bridge550.TestMethod(array9, "Float64Array", assert); var array10 = new DataView(array9.Buffer); Bridge550.TestMethod(array10, "DataView", assert); }
private async void yield(AcceptInfo accept) { //TcpClient c; //c.GetStream().ReadAsync( var read = await accept.socketId.read(); // { read = { resultCode = 370 } } //Console.WriteLine(new { read = new { read.resultCode } }); var u = new Uint8ClampedArray(read.data, 0, (uint)read.data.byteLength); var input = Encoding.UTF8.GetString(u); new IHTMLPre { new { input } }.AttachToDocument(); // http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol var outputString = "HTTP/1.0 200 OK \r\nConnection: close\r\n\r\nhello world\r\n"; var xx = new Uint8ClampedArray( Encoding.UTF8.GetBytes( outputString ) ); //nn.Title = "before headers"; accept.socketId.write( xx.buffer ); accept.socketId.disconnect(); accept.socketId.destroy(); }
/// <summary> /// Creates an ImageData object from a given Uint8ClampedArray and the size of the image it contains. /// Note that this is the most common way to create such an object in workers as createImageData() /// is not available there. /// </summary> /// <param name="array">A Uint8ClampedArray containing the underlying pixel representation of theimage.</param> /// <param name="width">An unsigned number representing the width of the represented image.</param> /// <param name="height"> /// An unsigned number representing the height of the represented image. This value is optional /// if an array is given: it will be inferred from its size and the given width. /// </param> /// <remarks>This is experimental API that should not be used in production code.</remarks> public ImageData(Uint8ClampedArray array, uint width, uint?height = null) { }
public static Uint8ClampedArray Uint8ClampedArrayFrom() { var clamped = new byte[50]; return(Uint8ClampedArray.From(clamped)); }
public static void CoreTypes() { var arr = new Uint8ClampedArray(50); Assert.Equal(50, arr.Length); Assert.Equal(TypedArrayTypeCode.Uint8ClampedArray, arr.GetTypedArrayType()); var arr1 = new Uint8Array(50); Assert.Equal(50, arr1.Length); Assert.Equal(TypedArrayTypeCode.Uint8Array, arr1.GetTypedArrayType()); var arr2 = new Uint16Array(50); Assert.Equal(50, arr2.Length); Assert.Equal(TypedArrayTypeCode.Uint16Array, arr2.GetTypedArrayType()); var arr3 = new Uint32Array(50); Assert.Equal(50, arr3.Length); Assert.Equal(TypedArrayTypeCode.Uint32Array, arr3.GetTypedArrayType()); var arr4 = new Int8Array(50); Assert.Equal(50, arr4.Length); Assert.Equal(TypedArrayTypeCode.Int8Array, arr4.GetTypedArrayType()); var arr5 = new Int16Array(50); Assert.Equal(50, arr5.Length); Assert.Equal(TypedArrayTypeCode.Int16Array, arr5.GetTypedArrayType()); var arr6 = new Int32Array(50); Assert.Equal(50, arr6.Length); Assert.Equal(TypedArrayTypeCode.Int32Array, arr6.GetTypedArrayType()); var arr7 = new Float32Array(50); Assert.Equal(50, arr7.Length); Assert.Equal(TypedArrayTypeCode.Float32Array, arr7.GetTypedArrayType()); var arr8 = new Float64Array(50); Assert.Equal(50, arr8.Length); Assert.Equal(TypedArrayTypeCode.Float64Array, arr8.GetTypedArrayType()); var sharedArr40 = new SharedArrayBuffer(40); var sharedArr50 = new SharedArrayBuffer(50); var arr9 = new Uint8ClampedArray(sharedArr50); Assert.Equal(50, arr9.Length); var arr10 = new Uint8Array(sharedArr50); Assert.Equal(50, arr10.Length); var arr11 = new Uint16Array(sharedArr50); Assert.Equal(25, arr11.Length); var arr12 = new Uint32Array(sharedArr40); Assert.Equal(10, arr12.Length); var arr13 = new Int8Array(sharedArr50); Assert.Equal(50, arr13.Length); var arr14 = new Int16Array(sharedArr40); Assert.Equal(20, arr14.Length); var arr15 = new Int32Array(sharedArr40); Assert.Equal(10, arr15.Length); var arr16 = new Float32Array(sharedArr40); Assert.Equal(10, arr16.Length); var arr17 = new Float64Array(sharedArr40); Assert.Equal(5, arr17.Length); }
// called by // X:\jsc.svn\core\ScriptCoreLib.Ultra\ScriptCoreLib.Ultra\JavaScript\Remoting\InternalWebMethodRequest.cs public Task<byte[]> UploadValuesTaskAsync(Uri address, NameValueCollection data) { //Console.WriteLine("enter WebClient.UploadValuesTaskAsync! " + new { address }); // Z:\jsc.svn\examples\javascript\Test\TestAfterInvokeResponseHeaders\ApplicationWebService.cs // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201511/20151123/uploadvaluestaskasync // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201511/20151123/ubuntumidexperiment var r = new TaskCompletionSource<byte[]> { }; // Z:\jsc.svn\examples\javascript\ubuntu\Test\UbuntuTestUploadValues\Application.cs // "Z:\jsc.svn\examples\javascript\ubuntu\Test\UbuntuTestUserHostAddress\UbuntuTestUserHostAddress.sln" // http://stackoverflow.com/questions/9713058/sending-post-data-with-a-xmlhttprequest // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201401/20140119 // http://stackoverflow.com/questions/8286934/post-formdata-via-xmlhttprequest-object-in-js-cross-browser // http://stackoverflow.com/questions/16917772/ie-lags-on-sending-post-data // http://robertnyman.com/2013/02/11/using-formdata-to-send-forms-with-xhr-as-keyvalue-pairs/ // https://blog.yorkxin.org/posts/2014/02/06/ajax-with-formdata-is-broken-on-ie10-ie11/ var x = new IXMLHttpRequest(); // InvalidStateException //x.withCredentials = true; x.open(Shared.HTTPMethodEnum.POST, address.ToString(), async: true); x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); var xFormDataString = ToFormDataString(data); //Uncaught InvalidStateError: Failed to execute 'send' on 'XMLHttpRequest': the object's state must be OPENED. // X:\jsc.svn\examples\javascript\Test\TestUploadValuesAsync\TestUploadValuesAsync\Application.cs // UploadValuesAsync { responseType = , response = <document><TaskComplete><TaskResult>13</TaskResult></TaskComplete></document> } x.InvokeOnComplete( delegate { //Console.WriteLine("after WebClient.UploadValuesTaskAsync! " + new { address }); #region complete var response = new byte[0]; // UploadValuesAsync { status = 204, responseType = arraybuffer, response = [object Uint8ClampedArray] } //if (x.status == 204) // 304? //if (x.status == IXMLHttpRequest.HTTPStatusCodes.NoContent) //{ // // android webview wants us to do this // response = new byte[0]; //} //Uncaught InvalidStateError: Failed to read the 'responseText' property from 'XMLHttpRequest': // The value is only accessible if the object's 'responseType' is '' or 'text' (was 'arraybuffer'). // X:\jsc.svn\examples\javascript\android\com.abstractatech.battery\com.abstractatech.battery\ApplicationWebService.cs //Console.WriteLine("UploadValuesAsync " + new { x.status, x.responseType }); //I/chromium(10616): [INFO:CONSOLE(36216)] "%c0:576ms UploadValuesAsync { status = 204, responseType = arraybuffer }", source: http://192.168.1.103:10129/view-source (36216) //I/chromium(10616): [INFO:CONSOLE(49940)] "Uncaught InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable.", source: http://192.168.1.103:10129/view-source (49940) // what about android webview? if (x.response == null) { //Console.WriteLine("UploadValuesAsync " + new { x.status, x.responseType, x.response, x.responseText }); //I/Web Console( 5012): %c0:198484ms UploadValuesAsync { status = 200, responseType = arraybuffer } at http://192.168.43.1:9417/view-source:37081 //I/Web Console( 5012): %c0:198500ms UploadValuesAsync { status = 200, responseType = arraybuffer, response = , responseText = <document><avatar><obj>aHR0cDovL3d3dy5ncmF2YXRhci5jb20vYXZhdGFyLzhlNmQzZGUw //I/Web Console( 5012): %c0:198524ms InternalWebMethodRequest.Complete { Name = Gravatar, Length = 0 } at http://192.168.43.1:9417/view-source:37081 // did we not fix it already? // android 2.3 only seems to have responseText // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201404/20140413 try { response = Encoding.UTF8.GetBytes(x.responseText); } catch { //I/chromium(30556): [INFO:CONSOLE(37861)] "%c92:28288ms UploadValuesAsync { status = 204, responseType = arraybuffer }", source: http://192.168.43.7:4394/view-source (37861) //I/chromium(30556): [INFO:CONSOLE(37861)] "%c92:28290ms responseText failed. thanks webview devs. { status = 204 }", source: http://192.168.43.7:4394/view-source (37861) // X:\jsc.svn\examples\javascript\p2p\SharedBrowserSessionExperiment\SharedBrowserSessionExperiment\ApplicationWebService.cs Console.WriteLine("responseText failed? " + new { x.status }); } } else { // http://stackoverflow.com/questions/8022425/getting-blob-data-from-xhr-request var a = (ArrayBuffer)x.response; //Console.WriteLine("UploadValuesAsync " + new { x.status, x.responseType, a.byteLength }); // IE? //var u8 = new Uint8Array(array: a); // X:\jsc.svn\core\ScriptCoreLib.Async\ScriptCoreLib.Async\JavaScript\DOM\FileEntryAsyncExtensions.cs var u8c = new Uint8ClampedArray(array: a); response = u8c; } //Console.WriteLine("UploadValuesAsync " + new { x.status, x.responseType, response }); #region ResponseHeaders this.ResponseHeaders = new WebHeaderCollection(); //this.ResponseHeaders.Clear(); var ResponseHeaders = x.getAllResponseHeaders(); // Z:\jsc.svn\examples\javascript\Test\TestAfterInvokeResponseHeaders\ApplicationWebService.cs //Console.WriteLine("after WebClient.UploadValuesTaskAsync! " + new { ResponseHeaders }); //0:8209ms { ResponseHeaders = Date: Sat, 15 Mar 2014 12:25:45 GMT //Server: ASP.NET Development Server/11.0.0.0 //X-AspNet-Version: 4.0.30319 //ETag: BqShORsRkdny750pWBdVyQ== //X-ElapsedMilliseconds: 10 //Content-Type: text/xml; charset=utf-8 //Access-Control-Allow-Origin: * //Cache-Control: private //Connection: Close //Content-Length: 239 foreach (var item in ResponseHeaders.Split('\n')) { var u = item.IndexOf(":"); if (u > 0) { var ukey = item.Substring(0, u); var uvalue = item.Substring(u + 1).Trim(); //Console.WriteLine(new { ukey, uvalue }); this.ResponseHeaders[ukey] = uvalue; } } #endregion //Console.WriteLine(new { ResponseHeaders }); r.SetResult(response); #endregion } ); x.responseType = "arraybuffer"; // Z:\jsc.svn\examples\javascript\ubuntu\UbuntuSSLWebApplication\UbuntuSSLWebApplication\Application.cs // allow basejump? // breaks Task<> call? //x.responseType = "text"; // is IE actually sending it? or is our server decoding it wrong? //Console.WriteLine("WebClient.UploadValuesAsync IXMLHttpRequest " + new { xFormDataString }); x.send(xFormDataString); return r.Task; }
public static IEnumerable <object[]> ArrayType_TestData() { _objectPrototype ??= new Function("return Object.prototype.toString;"); yield return(new object[] { _objectPrototype.Call(), "Uint8Array", Uint8Array.From(new byte[10]) }); yield return(new object[] { _objectPrototype.Call(), "Uint8ClampedArray", Uint8ClampedArray.From(new byte[10]) }); yield return(new object[] { _objectPrototype.Call(), "Int8Array", Int8Array.From(new sbyte[10]) }); yield return(new object[] { _objectPrototype.Call(), "Uint16Array", Uint16Array.From(new ushort[10]) }); yield return(new object[] { _objectPrototype.Call(), "Int16Array", Int16Array.From(new short[10]) }); yield return(new object[] { _objectPrototype.Call(), "Uint32Array", Uint32Array.From(new uint[10]) }); yield return(new object[] { _objectPrototype.Call(), "Int32Array", Int32Array.From(new int[10]) }); yield return(new object[] { _objectPrototype.Call(), "Float32Array", Float32Array.From(new float[10]) }); yield return(new object[] { _objectPrototype.Call(), "Float64Array", Float64Array.From(new double[10]) }); yield return(new object[] { _objectPrototype.Call(), "Array", new Array(10) }); }
public static void TestUseCase() { var isSpecialTypeName = BrowserHelper.IsPhantomJs(); var v1 = new Float32Array(1); var thisType = "Float32Array"; Assert.True(v1 != null, thisType + " created"); var thisName = isSpecialTypeName ? "Object" : thisType; Assert.AreEqual(thisName, v1.GetType().FullName, thisType + " class name"); var v2 = new Float64Array(1); thisType = "Float64Array"; Assert.True(v2 != null, thisType + " created"); thisName = isSpecialTypeName ? "Object" : thisType; Assert.AreEqual(thisName, v2.GetType().FullName, thisType + " class name"); var v3 = new Int16Array(1); thisType = "Int16Array"; Assert.True(v3 != null, thisType + " created"); thisName = isSpecialTypeName ? "Object" : thisType; Assert.AreEqual(thisName, v3.GetType().FullName, thisType + " class name"); var v4 = new Int32Array(1); thisType = "Int32Array"; Assert.True(v4 != null, thisType + " created"); thisName = isSpecialTypeName ? "Object" : thisType; Assert.AreEqual(thisName, v4.GetType().FullName, thisType + " class name"); var v5 = new Int8Array(1); thisType = "Int8Array"; Assert.True(v5 != null, thisType + " created"); thisName = isSpecialTypeName ? "Object" : thisType; Assert.AreEqual(thisName, v5.GetType().FullName, thisType + " class name"); var v6 = new Uint16Array(1); thisType = "Uint16Array"; Assert.True(v6 != null, thisType + " created"); thisName = isSpecialTypeName ? "Object" : thisType; Assert.AreEqual(thisName, v6.GetType().FullName, thisType + " class name"); var v7 = new Uint32Array(1); thisType = "Uint32Array"; Assert.True(v7 != null, thisType + " created"); thisName = isSpecialTypeName ? "Object" : thisType; Assert.AreEqual(thisName, v7.GetType().FullName, thisType + " class name"); var v8 = new Uint8Array(1); thisType = "Uint8Array"; Assert.True(v8 != null, thisType + " created"); thisName = isSpecialTypeName ? "Object" : thisType; Assert.AreEqual(thisName, v8.GetType().FullName, thisType + " class name"); var v9 = new Uint8ClampedArray(1); thisType = "Uint8ClampedArray"; Assert.True(v9 != null, thisType + " created"); thisName = isSpecialTypeName ? "Object" : thisType; Assert.AreEqual(thisName, v9.GetType().FullName, thisType + " class name"); }
public static void TestUseCase(Assert assert) { var isToStringToTypeNameLogic = !BrowserHelper.IsChrome(); assert.Expect(153); var v1 = new Float32Array(10); assert.Ok(v1 != null, "Float32Array created"); v1[1] = 11; v1[5] = 5; v1[9] = 99; assert.Equal(v1[1], 11, "Float32Array indexier works 1"); assert.Equal(v1[9], 99, "Float32Array indexier works 9"); // Check just a select number of references inside the Prototype inheritance. assert.Ok(v1.Buffer != null, "Float32Array Buffer"); assert.Equal(v1.ByteLength, 40, "Float32Array ByteLength"); assert.Equal(v1.ByteOffset, 0, "Float32Array ByteOffset"); assert.Equal(v1.Length, 10, "Float32Array Length"); /* * Commented out. Reason: Only Firefox implements them. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array * var mA = v1.Join(); * v1.Reverse(); * var mB = v1.Slice(); * var mC = v1.Sort(); */ var expectedToStringFloat32Array1 = isToStringToTypeNameLogic ? "[object Float32Array]" : "0,11,0,0,0,5,0,0,0,99"; assert.Equal(v1.ToLocaleString(), expectedToStringFloat32Array1, "Float32Array ToLocaleString"); assert.Equal(v1.ToString(), expectedToStringFloat32Array1, "Float32Array ToString"); // Some browsers do not support SubArray() with no parameters. // At least 'begin' must be provided. var subArray11 = v1.SubArray(1); var expectedToStringFloat32Array2 = isToStringToTypeNameLogic ? "[object Float32Array]" : "11,0,0,0,5,0,0,0,99"; assert.Ok(subArray11 != null, "Float32Array SubArray1"); assert.Equal(subArray11.Length, 9, "Float32Array SubArray1 Length"); assert.Equal(subArray11.ToString(), expectedToStringFloat32Array2, "Float32Array SubArray1 ToString"); assert.Equal(subArray11.ByteOffset, 4, "Float32Array SubArray1 ByteOffset"); var subArray12 = subArray11.SubArray(2, 6); var expectedToStringFloat32Array3 = isToStringToTypeNameLogic ? "[object Float32Array]" : "0,0,5,0"; assert.Ok(subArray12 != null, "Float32Array SubArray2"); assert.Equal(subArray12.Length, 4, "Float32Array SubArray2 Length"); assert.Equal(subArray12.ToString(), expectedToStringFloat32Array3, "Float32Array SubArray2 ToString"); assert.Equal(subArray12.ByteOffset, 12, "Float32Array SubArray2 ByteOffset"); var v2 = new Float64Array(10); assert.Ok(v2 != null, "Float64Array created"); v2[1] = 11; v2[5] = 5; v2[9] = 99; assert.Equal(v2[1], 11, "Float64Array indexier works 1"); assert.Equal(v2[9], 99, "Float64Array indexier works 9"); assert.Ok(v2.Buffer != null, "Float64Array Buffer"); assert.Equal(v2.ByteLength, 80, "Float64Array ByteLength"); assert.Equal(v2.ByteOffset, 0, "Float64Array ByteOffset"); assert.Equal(v2.Length, 10, "Float64Array Length"); var expectedToStringFloat64Array1 = isToStringToTypeNameLogic ? "[object Float64Array]" : "0,11,0,0,0,5,0,0,0,99"; assert.Equal(v2.ToLocaleString(), expectedToStringFloat64Array1, "Float64Array ToLocaleString"); assert.Equal(v2.ToString(), expectedToStringFloat64Array1, "Float64Array ToString"); var subArray21 = v2.SubArray(1); var expectedToStringFloat64Array2 = isToStringToTypeNameLogic ? "[object Float64Array]" : "11,0,0,0,5,0,0,0,99"; assert.Ok(subArray21 != null, "Float64Array SubArray1"); assert.Equal(subArray21.Length, 9, "Float64Array SubArray1 Length"); assert.Equal(subArray21.ToString(), expectedToStringFloat64Array2, "Float64Array SubArray1 ToString"); assert.Equal(subArray21.ByteOffset, 8, "Float64Array SubArray1 ByteOffset"); var subArray22 = subArray21.SubArray(2, 6); var expectedToStringFloat64Array3 = isToStringToTypeNameLogic ? "[object Float64Array]" : "0,0,5,0"; assert.Ok(subArray22 != null, "Float64Array SubArray2"); assert.Equal(subArray22.Length, 4, "Float64Array SubArray2 Length"); assert.Equal(subArray22.ToString(), expectedToStringFloat64Array3, "Float64Array SubArray2 ToString"); assert.Equal(subArray22.ByteOffset, 24, "Float64Array SubArray2 ByteOffset"); var v3 = new Int16Array(10); assert.Ok(v3 != null, "Int16Array created"); v3[1] = 11; v3[5] = 5; v3[9] = 99; assert.Equal(v3[1], 11, "Int16Array indexier works 1"); assert.Equal(v3[9], 99, "Int16Array indexier works 9"); assert.Ok(v3.Buffer != null, "Int16Array Buffer"); assert.Equal(v3.ByteLength, 20, "Int16Array ByteLength"); assert.Equal(v3.ByteOffset, 0, "Int16Array ByteOffset"); assert.Equal(v3.Length, 10, "Int16Array Length"); var expectedToStringInt16Array1 = isToStringToTypeNameLogic ? "[object Int16Array]" : "0,11,0,0,0,5,0,0,0,99"; assert.Equal(v3.ToLocaleString(), expectedToStringInt16Array1, "Int16Array ToLocaleString"); assert.Equal(v3.ToString(), expectedToStringInt16Array1, "Int16Array ToString"); var subArray31 = v3.SubArray(1); var expectedToStringInt16Array2 = isToStringToTypeNameLogic ? "[object Int16Array]" : "11,0,0,0,5,0,0,0,99"; assert.Ok(subArray31 != null, "Int16Array SubArray1"); assert.Equal(subArray31.Length, 9, "Int16Array SubArray1 Length"); assert.Equal(subArray31.ToString(), expectedToStringInt16Array2, "Int16Array SubArray1 ToString"); assert.Equal(subArray31.ByteOffset, 2, "Int16Array SubArray1 ByteOffset"); var subArray32 = subArray31.SubArray(2, 6); var expectedToStringInt16Array3 = isToStringToTypeNameLogic ? "[object Int16Array]" : "0,0,5,0"; assert.Ok(subArray32 != null, "Int16Array SubArray2"); assert.Equal(subArray32.Length, 4, "Int16Array SubArray2 Length"); assert.Equal(subArray32.ToString(), expectedToStringInt16Array3, "Int16Array SubArray2 ToString"); assert.Equal(subArray32.ByteOffset, 6, "Int16Array SubArray2 ByteOffset"); var v4 = new Int32Array(10); assert.Ok(v4 != null, "Int32Array created"); v4[1] = 11; v4[5] = 5; v4[9] = 99; assert.Equal(v4[1], 11, "Int32Array indexier works 1"); assert.Equal(v4[9], 99, "Int32Array indexier works 9"); assert.Ok(v4.Buffer != null, "Int32Array Buffer"); assert.Equal(v4.ByteLength, 40, "Int32Array ByteLength"); assert.Equal(v4.ByteOffset, 0, "Int32Array ByteOffset"); assert.Equal(v4.Length, 10, "Int32Array Length"); var expectedToStringInt32Array1 = isToStringToTypeNameLogic ? "[object Int32Array]" : "0,11,0,0,0,5,0,0,0,99"; assert.Equal(v4.ToLocaleString(), expectedToStringInt32Array1, "Int32Array ToLocaleString"); assert.Equal(v4.ToString(), expectedToStringInt32Array1, "Int32Array ToString"); var subArray41 = v4.SubArray(1); var expectedToStringInt32Array2 = isToStringToTypeNameLogic ? "[object Int32Array]" : "11,0,0,0,5,0,0,0,99"; assert.Ok(subArray41 != null, "Int32Array SubArray1"); assert.Equal(subArray41.Length, 9, "Int32Array SubArray1 Length"); assert.Equal(subArray41.ToString(), expectedToStringInt32Array2, "Int32Array SubArray1 ToString"); assert.Equal(subArray41.ByteOffset, 4, "Int32Array SubArray1 ByteOffset"); var subArray42 = subArray41.SubArray(2, 6); var expectedToStringInt32Array3 = isToStringToTypeNameLogic ? "[object Int32Array]" : "0,0,5,0"; assert.Ok(subArray42 != null, "Int32Array SubArray2"); assert.Equal(subArray42.Length, 4, "Int32Array SubArray2 Length"); assert.Equal(subArray42.ToString(), expectedToStringInt32Array3, "Int32Array SubArray2 ToString"); assert.Equal(subArray42.ByteOffset, 12, "Int32Array SubArray2 ByteOffset"); var v5 = new Int8Array(10); assert.Ok(v5 != null, "Int8Array created"); v5[1] = 11; v5[5] = 5; v5[9] = 99; assert.Equal(v5[1], 11, "Int8Array indexier works 1"); assert.Equal(v5[9], 99, "Int8Array indexier works 9"); assert.Ok(v5.Buffer != null, "Int8Array Buffer"); assert.Equal(v5.ByteLength, 10, "Int8Array ByteLength"); assert.Equal(v5.ByteOffset, 0, "Int8Array ByteOffset"); assert.Equal(v5.Length, 10, "Int8Array Length"); var expectedToStringInt8Array1 = isToStringToTypeNameLogic ? "[object Int8Array]" : "0,11,0,0,0,5,0,0,0,99"; assert.Equal(v5.ToLocaleString(), expectedToStringInt8Array1, "Int8Array ToLocaleString"); assert.Equal(v5.ToString(), expectedToStringInt8Array1, "Int8Array ToString"); var subArray51 = v5.SubArray(1); var expectedToStringInt8Array2 = isToStringToTypeNameLogic ? "[object Int8Array]" : "11,0,0,0,5,0,0,0,99"; assert.Ok(subArray51 != null, "Int8Array SubArray1"); assert.Equal(subArray51.Length, 9, "Int8Array SubArray1 Length"); assert.Equal(subArray51.ToString(), expectedToStringInt8Array2, "Int8Array SubArray1 ToString"); assert.Equal(subArray51.ByteOffset, 1, "Int8Array SubArray1 ByteOffset"); var subArray52 = subArray51.SubArray(2, 6); var expectedToStringInt8Array3 = isToStringToTypeNameLogic ? "[object Int8Array]" : "0,0,5,0"; assert.Ok(subArray52 != null, "Int8Array SubArray2"); assert.Equal(subArray52.Length, 4, "Int8Array SubArray2 Length"); assert.Equal(subArray52.ToString(), expectedToStringInt8Array3, "Int8Array SubArray2 ToString"); assert.Equal(subArray52.ByteOffset, 3, "Int8Array SubArray2 ByteOffset"); var v6 = new Uint16Array(10); assert.Ok(v6 != null, "Uint16Array created"); v6[1] = 11; v6[5] = 5; v6[9] = 99; assert.Equal(v6[1], 11, "Uint16Array indexier works 1"); assert.Equal(v6[9], 99, "Uint16Array indexier works 9"); assert.Ok(v6.Buffer != null, "Uint16Array Buffer"); assert.Equal(v6.ByteLength, 20, "Uint16Array ByteLength"); assert.Equal(v6.ByteOffset, 0, "Uint16Array ByteOffset"); assert.Equal(v6.Length, 10, "Uint16Array Length"); var expectedToStringUint16Array1 = isToStringToTypeNameLogic ? "[object Uint16Array]" : "0,11,0,0,0,5,0,0,0,99"; assert.Equal(v6.ToLocaleString(), expectedToStringUint16Array1, "Uint16Array ToLocaleString"); assert.Equal(v6.ToString(), expectedToStringUint16Array1, "Uint16Array ToString"); var subArray61 = v6.SubArray(1); var expectedToStringUint16Array2 = isToStringToTypeNameLogic ? "[object Uint16Array]" : "11,0,0,0,5,0,0,0,99"; assert.Ok(subArray61 != null, "Uint16Array SubArray1"); assert.Equal(subArray61.Length, 9, "Uint16Array SubArray1 Length"); assert.Equal(subArray61.ToString(), expectedToStringUint16Array2, "Uint16Array SubArray1 ToString"); assert.Equal(subArray61.ByteOffset, 2, "Uint16Array SubArray1 ByteOffset"); var subArray62 = subArray61.SubArray(2, 6); var expectedToStringUint16Array3 = isToStringToTypeNameLogic ? "[object Uint16Array]" : "0,0,5,0"; assert.Ok(subArray62 != null, "Uint16Array SubArray2"); assert.Equal(subArray62.Length, 4, "Uint16Array SubArray2 Length"); assert.Equal(subArray62.ToString(), expectedToStringUint16Array3, "Uint16Array SubArray2 ToString"); assert.Equal(subArray62.ByteOffset, 6, "Uint16Array SubArray2 ByteOffset"); var v7 = new Uint32Array(10); assert.Ok(v7 != null, "Uint32Array created"); v7[1] = 11; v7[5] = 5; v7[9] = 99; assert.Equal(v7[1], 11, "Uint32Array indexier works 1"); assert.Equal(v7[9], 99, "Uint32Array indexier works 9"); assert.Ok(v7.Buffer != null, "Uint32Array Buffer"); assert.Equal(v7.ByteLength, 40, "Uint32Array ByteLength"); assert.Equal(v7.ByteOffset, 0, "Uint32Array ByteOffset"); assert.Equal(v7.Length, 10, "Uint32Array Length"); var expectedToStringUint32Array1 = isToStringToTypeNameLogic ? "[object Uint32Array]" : "0,11,0,0,0,5,0,0,0,99"; assert.Equal(v7.ToLocaleString(), expectedToStringUint32Array1, "Uint32Array ToLocaleString"); assert.Equal(v7.ToString(), expectedToStringUint32Array1, "Uint32Array ToString"); var subArray71 = v7.SubArray(1); var expectedToStringUint32Array2 = isToStringToTypeNameLogic ? "[object Uint32Array]" : "11,0,0,0,5,0,0,0,99"; assert.Ok(subArray71 != null, "Uint32Array SubArray1"); assert.Equal(subArray71.Length, 9, "Uint32Array SubArray1 Length"); assert.Equal(subArray71.ToString(), expectedToStringUint32Array2, "Uint32Array SubArray1 ToString"); assert.Equal(subArray71.ByteOffset, 4, "Uint32Array SubArray1 ByteOffset"); var subArray72 = subArray71.SubArray(2, 6); var expectedToStringUint32Array3 = isToStringToTypeNameLogic ? "[object Uint32Array]" : "0,0,5,0"; assert.Ok(subArray72 != null, "Uint32Array SubArray2"); assert.Equal(subArray72.Length, 4, "Uint32Array SubArray2 Length"); assert.Equal(subArray72.ToString(), expectedToStringUint32Array3, "Uint32Array SubArray2 ToString"); assert.Equal(subArray72.ByteOffset, 12, "Uint32Array SubArray2 ByteOffset"); var v8 = new Uint8Array(10); assert.Ok(v8 != null, "Uint8Array created"); v8[1] = 11; v8[5] = 5; v8[9] = 99; assert.Equal(v8[1], 11, "Uint8Array indexier works 1"); assert.Equal(v8[9], 99, "Uint8Array indexier works 9"); assert.Ok(v8.Buffer != null, "Uint8Array Buffer"); assert.Equal(v8.ByteLength, 10, "Uint8Array ByteLength"); assert.Equal(v8.ByteOffset, 0, "Uint8Array ByteOffset"); assert.Equal(v8.Length, 10, "Uint8Array Length"); var expectedToStringUint8Array1 = isToStringToTypeNameLogic ? "[object Uint8Array]" : "0,11,0,0,0,5,0,0,0,99"; assert.Equal(v8.ToLocaleString(), expectedToStringUint8Array1, "Uint8Array ToLocaleString"); assert.Equal(v8.ToString(), expectedToStringUint8Array1, "Uint8Array ToString"); var subArray81 = v8.SubArray(1); var expectedToStringUint8Array2 = isToStringToTypeNameLogic ? "[object Uint8Array]" : "11,0,0,0,5,0,0,0,99"; assert.Ok(subArray81 != null, "Uint8Array SubArray1"); assert.Equal(subArray81.Length, 9, "Uint8Array SubArray1 Length"); assert.Equal(subArray81.ToString(), expectedToStringUint8Array2, "Uint8Array SubArray1 ToString"); assert.Equal(subArray81.ByteOffset, 1, "Uint8Array SubArray1 ByteOffset"); var subArray82 = subArray81.SubArray(2, 6); var expectedToStringUint8Array3 = isToStringToTypeNameLogic ? "[object Uint8Array]" : "0,0,5,0"; assert.Ok(subArray82 != null, "Uint8Array SubArray2"); assert.Equal(subArray82.Length, 4, "Uint8Array SubArray2 Length"); assert.Equal(subArray82.ToString(), expectedToStringUint8Array3, "Uint8Array SubArray2 ToString"); assert.Equal(subArray82.ByteOffset, 3, "Uint8Array SubArray2 ByteOffset"); var v9 = new Uint8ClampedArray(10); assert.Ok(v9 != null, "Uint8ClampedArray created"); v9[1] = 11; v9[5] = 5; v9[9] = 99; assert.Equal(v9[1], 11, "Uint8ClampedArray indexier works 1"); assert.Equal(v9[9], 99, "Uint8ClampedArray indexier works 9"); assert.Ok(v9.Buffer != null, "Uint8ClampedArray Buffer"); assert.Equal(v9.ByteLength, 10, "Uint8ClampedArray ByteLength"); assert.Equal(v9.ByteOffset, 0, "Uint8ClampedArray ByteOffset"); assert.Equal(v9.Length, 10, "Uint8ClampedArray Length"); var expectedToStringUint8ClampedArray1 = isToStringToTypeNameLogic ? "[object Uint8ClampedArray]" : "0,11,0,0,0,5,0,0,0,99"; assert.Equal(v9.ToLocaleString(), expectedToStringUint8ClampedArray1, "Uint8ClampedArray ToLocaleString"); assert.Equal(v9.ToString(), expectedToStringUint8ClampedArray1, "Uint8ClampedArray ToString"); var subArray91 = v9.SubArray(1); var expectedToStringUint8ClampedArray2 = isToStringToTypeNameLogic ? "[object Uint8ClampedArray]" : "11,0,0,0,5,0,0,0,99"; assert.Ok(subArray91 != null, "Uint8ClampedArray SubArray1"); assert.Equal(subArray91.Length, 9, "Uint8ClampedArray SubArray1 Length"); assert.Equal(subArray91.ToString(), expectedToStringUint8ClampedArray2, "Uint8ClampedArray SubArray1 ToString"); assert.Equal(subArray91.ByteOffset, 1, "Uint8ClampedArray SubArray1 ByteOffset"); var subArray92 = subArray91.SubArray(2, 6); var expectedToStringUint8ClampedArray3 = isToStringToTypeNameLogic ? "[object Uint8ClampedArray]" : "0,0,5,0"; assert.Ok(subArray92 != null, "Uint8ClampedArray SubArray2"); assert.Equal(subArray92.Length, 4, "Uint8ClampedArray SubArray2 Length"); assert.Equal(subArray92.ToString(), expectedToStringUint8ClampedArray3, "Uint8ClampedArray SubArray2 ToString"); assert.Equal(subArray92.ByteOffset, 3, "Uint8ClampedArray SubArray2 ByteOffset"); }
// X:\jsc.internal.svn\compiler\jsc.meta\jsc.meta\Library\Templates\Java\InternalAndroidWebServiceActivity.cs static void MulticastSend(string reason, string data, string preview, string nn) { /// http://www.daniweb.com/software-development/java/threads/424998/udp-client-server-in-java MulticastSend_c++; //var n = c + " hello world"; var message = new XElement("string", new XAttribute("reason", reason), new XAttribute("c", "" + MulticastSend_c), new XAttribute("preview", preview), new XAttribute("n", nn), data ).ToString(); Console.WriteLine(new { message }); Action x = async delegate { var socket = await chrome.socket.create("udp", new object()); var port = new Random().Next(16000, 40000); socket.socketId.bind("0.0.0.0", port); // http://stackoverflow.com/questions/12253507/how-can-chrome-socket-be-used-for-broadcasting-or-multicasting // To send multicast packets all you need to do is bind to a local interface (0.0.0.0 with a random port works, as you've discovered), and then address a packet to the correct group/port (which is what sendTo will do). var xmessage = message.ToString(); Console.WriteLine(new { socket.socketId, port, xmessage }); var bytes = Encoding.UTF8.GetBytes(xmessage); var xdata = new Uint8ClampedArray(bytes); // Uncaught Error: Invocation of form socket.sendTo(object, string, integer, function) // doesn't match definition socket.sendTo(integer socketId, binary data, string address, integer port, function callback) // https://code.google.com/p/chromium/issues/detail?id=253304 // { socketId = 68, bytesWritten = -15 } var result = await socket.socketId.sendTo( // ! we need ScriptCoreLib.Redux build here xdata.buffer, "239.1.2.3", 40404 ); Console.WriteLine(new { socket.socketId, result.bytesWritten }); socket.socketId.destroy(); }; x(); //new Thread( // delegate() // { // try // { // var socket = new DatagramSocket(); //construct a datagram socket and binds it to the available port and the localhos // byte[] b = Encoding.UTF8.GetBytes(message.ToString()); //creates a variable b of type byte // var dgram = new DatagramPacket((sbyte[])(object)b, b.Length, InetAddress.getByName("239.1.2.3"), 40404);//sends the packet details, length of the packet,destination address and the port number as parameters to the DatagramPacket // socket.send(dgram); //send the datagram packet from this port // } // catch // { // System.Console.WriteLine("server error"); // } // } //) //{ // Name = "server" //}.Start(); }
public void UploadValuesAsync(Uri address, NameValueCollection data) { //Console.WriteLine("enter WebClient.UploadValuesAsync"); // called by // X:\jsc.svn\core\ScriptCoreLib.Ultra\ScriptCoreLib.Ultra\JavaScript\Remoting\InternalWebMethodRequest.cs // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201401/20140119 var x = new IXMLHttpRequest(); x.open(Shared.HTTPMethodEnum.POST, address.ToString(), async: true); x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); var xFormDataString = ToFormDataString(data); //Uncaught InvalidStateError: Failed to execute 'send' on 'XMLHttpRequest': the object's state must be OPENED. // X:\jsc.svn\examples\javascript\Test\TestUploadValuesAsync\TestUploadValuesAsync\Application.cs // UploadValuesAsync { responseType = , response = <document><TaskComplete><TaskResult>13</TaskResult></TaskComplete></document> } x.InvokeOnComplete( delegate { #region complete var response = new byte[0]; // UploadValuesAsync { status = 204, responseType = arraybuffer, response = [object Uint8ClampedArray] } //if (x.status == 204) // 304? //if (x.status == IXMLHttpRequest.HTTPStatusCodes.NoContent) //{ // // android webview wants us to do this // response = new byte[0]; //} //Uncaught InvalidStateError: Failed to read the 'responseText' property from 'XMLHttpRequest': // The value is only accessible if the object's 'responseType' is '' or 'text' (was 'arraybuffer'). // X:\jsc.svn\examples\javascript\android\com.abstractatech.battery\com.abstractatech.battery\ApplicationWebService.cs //Console.WriteLine("UploadValuesAsync " + new { x.status, x.responseType }); //I/chromium(10616): [INFO:CONSOLE(36216)] "%c0:576ms UploadValuesAsync { status = 204, responseType = arraybuffer }", source: http://192.168.1.103:10129/view-source (36216) //I/chromium(10616): [INFO:CONSOLE(49940)] "Uncaught InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable.", source: http://192.168.1.103:10129/view-source (49940) // what about android webview? if (x.response == null) { //Console.WriteLine("UploadValuesAsync " + new { x.status, x.responseType, x.response, x.responseText }); //I/Web Console( 5012): %c0:198484ms UploadValuesAsync { status = 200, responseType = arraybuffer } at http://192.168.43.1:9417/view-source:37081 //I/Web Console( 5012): %c0:198500ms UploadValuesAsync { status = 200, responseType = arraybuffer, response = , responseText = <document><avatar><obj>aHR0cDovL3d3dy5ncmF2YXRhci5jb20vYXZhdGFyLzhlNmQzZGUw //I/Web Console( 5012): %c0:198524ms InternalWebMethodRequest.Complete { Name = Gravatar, Length = 0 } at http://192.168.43.1:9417/view-source:37081 // did we not fix it already? // android 2.3 only seems to have responseText // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201404/20140413 try { response = Encoding.UTF8.GetBytes(x.responseText); } catch { //I/chromium(30556): [INFO:CONSOLE(37861)] "%c92:28288ms UploadValuesAsync { status = 204, responseType = arraybuffer }", source: http://192.168.43.7:4394/view-source (37861) //I/chromium(30556): [INFO:CONSOLE(37861)] "%c92:28290ms responseText failed. thanks webview devs. { status = 204 }", source: http://192.168.43.7:4394/view-source (37861) // X:\jsc.svn\examples\javascript\p2p\SharedBrowserSessionExperiment\SharedBrowserSessionExperiment\ApplicationWebService.cs Console.WriteLine("responseText failed. thanks webview devs. " + new { x.status }); } } else { // http://stackoverflow.com/questions/8022425/getting-blob-data-from-xhr-request var a = (ArrayBuffer)x.response; //Console.WriteLine("UploadValuesAsync " + new { x.status, x.responseType, a.byteLength }); // IE? //var u8 = new Uint8Array(array: a); // X:\jsc.svn\core\ScriptCoreLib.Async\ScriptCoreLib.Async\JavaScript\DOM\FileEntryAsyncExtensions.cs var u8c = new Uint8ClampedArray(array: a); response = u8c; } //Console.WriteLine("UploadValuesAsync " + new { x.status, x.responseType, response }); var e = new __UploadValuesCompletedEventArgs { Result = response }; #region ResponseHeaders this.ResponseHeaders = new WebHeaderCollection(); //this.ResponseHeaders.Clear(); var ResponseHeaders = x.getAllResponseHeaders(); //0:8209ms { ResponseHeaders = Date: Sat, 15 Mar 2014 12:25:45 GMT //Server: ASP.NET Development Server/11.0.0.0 //X-AspNet-Version: 4.0.30319 //ETag: BqShORsRkdny750pWBdVyQ== //X-ElapsedMilliseconds: 10 //Content-Type: text/xml; charset=utf-8 //Access-Control-Allow-Origin: * //Cache-Control: private //Connection: Close //Content-Length: 239 foreach (var item in ResponseHeaders.Split('\n')) { var u = item.IndexOf(":"); var ukey = item.Substring(0, u); var uvalue = item.Substring(u + 1).Trim(); this.ResponseHeaders[ukey] = uvalue; } #endregion //Console.WriteLine(new { ResponseHeaders }); if (UploadValuesCompleted != null) { UploadValuesCompleted(null, (UploadValuesCompletedEventArgs)(object)e); } #endregion } ); x.responseType = "arraybuffer"; //Console.WriteLine("WebClient.UploadValuesAsync IXMLHttpRequest " + new { xFormDataString }); x.send(xFormDataString); }
public static void InvokeAsync( string __PageSource, Func<string, Task> open ) { Console.WriteLine("enter ChromeTCPServer.TheServer.InvokeAsync"); // https://code.google.com/p/chromium/issues/detail?id=179940 // https://github.com/GoogleChrome/chrome-app-samples/blob/master/websocket-server/http.js #region chrome.runtime chrome.app.runtime.Restarted += delegate { new chrome.Notification { Message = "Restarted!" }; // um. new IP? }; //Error in event handler for runtime.onInstalled: undefined Console.WriteLine("before chrome.runtime.Installed"); chrome.runtime.Installed += delegate { Console.WriteLine("at chrome.runtime.Installed"); new chrome.Notification { Message = "Installed!" }; }; chrome.runtime.Startup += delegate { new chrome.Notification { Message = "Startup!" }; }; var t = new Stopwatch(); t.Start(); chrome.runtime.Suspend += delegate { var n = new chrome.Notification { Message = "Suspend! " + new { t.ElapsedMilliseconds } }; n.Clicked += delegate { runtime.reload(); }; }; #endregion // getNetworkList: //{ name = {CE7A76DF-BCB0-4C3B-8466-D712A03F10A0}, address = fe80::55cc:63eb:5b4:60b4 } //{ name = {CE7A76DF-BCB0-4C3B-8466-D712A03F10A0}, address = 192.168.43.252 } //{ name = {4E818D17-30DD-46D2-9592-9E1F497D3D82}, address = 2001:0:5ef5:79fb:24f2:176e:3f57:d403 } //{ name = {4E818D17-30DD-46D2-9592-9E1F497D3D82}, address = fe80::24f2:176e:3f57:d403 } // getNetworkList: //{ name = {CE7A76DF-BCB0-4C3B-8466-D712A03F10A0}, address = 192.168.43.252 } //{ name = {CE7A76DF-BCB0-4C3B-8466-D712A03F10A0}, address = fe80::55cc:63eb:5b4:60b4 } //{ name = {4E818D17-30DD-46D2-9592-9E1F497D3D82}, address = 2001:0:5ef5:79fb:24f2:176e:3f57:d403 } //{ name = {4E818D17-30DD-46D2-9592-9E1F497D3D82}, address = fe80::24f2:176e:3f57:d403 } #region GetAddresss Func<NetworkInterface[], string> GetAddresss = n => { var a = n.OrderBy(k => k.address.Contains(":")).ToArray(); if (a.Length > 0) { return a[0].address; } return "127.0.0.1"; }; #endregion //Func<string, Func<string, Task<chrome.WriteInfo>>, Func<byte[], Task<chrome.WriteInfo>>, Task<object>> Handler = #region Handler Func<string, chrome.socketId, Task<string>> doaccept_Handler = async (RequestLine, socketId) => { //var x = new TaskCompletionSource<object>(); var PageSource = __PageSource; // 9:138973ms {{ input = GET /favicon.ico HTTP/1.1 var path = RequestLine.SkipUntilIfAny(" ").TakeUntilIfAny(" "); // we can do it over here on UI thead, not in the sandboxed worker below, yet the input data is the same.. // would jsc be able to move around such method use in time? // did we rebuild chrome with 2015 yet? var xpath = chrome.runtime.getURL(path); // 9:60202ms RequestLine: {{ path = /, RequestLine = GET / HTTP/1.1 }} Console.WriteLine( "doaccept_Handler RequestLine: " + new { path, xpath, RequestLine } ); //{ RequestLine = GET /view-source HTTP/1.1, path = /view-source } //var nn = new Notification //{ // Message = path, // Title = "ChromeTCPServer" //}; //Console.WriteLine("before StartNewWithProgress: " + new { path, Thread.CurrentThread.ManagedThreadId }); //var yyy = new TaskCompletionSource<string>(); var yyy = default(TaskCompletionSource<string>); var worker = default(Task); #region progress IProgress<x> progress = new Progress<x>( state => { if (state.write == null) { Console.WriteLine("progress done StartNewWithProgress: " + new { state.path, Thread.CurrentThread.ManagedThreadId }); yyy.SetResult(state.path); // can we terminate our thread? worker.Dispose(); return; } Console.WriteLine("progress StartNewWithProgress: " + new { state.path, state.write.Length, Thread.CurrentThread.ManagedThreadId }); var xx = new Uint8ClampedArray(state.write); //nn.Title = "before headers"; socketId.write( xx.buffer ); } ); #endregion //9:55056ms inside worker RequestLine: { { path = } } //9:55059ms at zApplicationHandler: { { path = , ManagedThreadId = 10 } } //worker = // "X:\jsc.svn\examples\javascript\async\Test\TestUnwrap\TestUnwrap.sln" // func Task will blow up? Console.WriteLine("doaccept_Handler will hop to worker " + new { Thread.CurrentThread.ManagedThreadId }); // clone data to the other thrad. worker = Task.Run( delegate { Console.WriteLine("doaccept_Handler will hop to worker, done " + new { Thread.CurrentThread.ManagedThreadId }); // X:\jsc.svn\core\ScriptCoreLib\JavaScript\DOM\Worker.cs // wtf? where is my path? Console.WriteLine( "doaccept_Handler inside worker RequestLine: " + new { path } ); // rebuild the scope. var scope = Tuple.Create( progress, new x { chromePath = xpath, path = path, PageSource = PageSource, write = default(byte[]) } ); //return TheServer.zApplicationHandler(scope); TheServer.WorkerApplicationHandler(scope); // Uncaught Error: bugcheck TaskExtensions.Unwrap Task<Task> {{ xResultTask = [object Object], t = ?function Object() { [native code] } }} Console.WriteLine("doaccept_Handler will hop to worker, exit, return sync void?"); // return void? // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150428 } ); // TaskCompletionSource is incorrectly sent to the worker.. need to assign it after data was cloned... yyy = new TaskCompletionSource<string>(); var result = await yyy.Task; // obsolete? // Error 115 'System.Threading.Tasks.TaskAsyncIProgressExtensions.StartNewWithProgress<TSource>(System.Threading.Tasks.TaskFactory, TSource, System.Func<System.Tuple<System.IProgress<TSource>, TSource>, TSource>, System.Action<TSource>)' is obsolete: 'we now support scope sharing!' X:\jsc.svn\examples\javascript\chrome\apps\ChromeTCPServer\ChromeTCPServer\Application.cs 503 30 ChromeTCPServer /// what will be done by this task? socketId.disconnect // this is not working anymore? // why we need to return a task anyways? return result; }; #endregion #region doaccept Action<chrome.AcceptInfo> doaccept = async accept => { //Console.WriteLine("accept enter " + new { accept.socketId }); //var acceptn = new Notification //{ // Message = "accept! " + new { accept.socketId }, // Title = "ChromeTCPServer" //}; // { read = { resultCode = -2 } } var read = await accept.socketId.read(); // { read = { resultCode = 370 } } Console.WriteLine("doaccept " + new { read = new { read.resultCode } }); var u = new Uint8ClampedArray(read.data, 0, (uint)read.data.byteLength); var input = Encoding.UTF8.GetString(u); Console.WriteLine("doaccept " + new { input }); // { input = GET / HTTP/1.1 //Host: 192.168.43.252:8763 //Connection: keep-alive //Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 //User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1631.0 Safari/537.36 //Accept-Encoding: gzip,deflate,sdch //Accept-Language: en-US,en;q=0.8,et;q=0.6,cs;q=0.4,fr;q=0.2 // } // http://stackoverflow.com/questions/8550383/read-file-packaged-with-chrome-extension-in-content-script //var xhr = new IXMLHttpRequest(); //xhr.open(ScriptCoreLib.Shared.HTTPMethodEnum.GET, "manifest.json"); //var xbytes = await xhr.bytes; //var output = "HTTP/1.0 200 OK\r\n\r\nhello world\n\n" // + input + Encoding.UTF8.GetString(xbytes); //GET /favicon.ico HTTP/1.1 var HandlerStopwatch = new Stopwatch(); HandlerStopwatch.Start(); if (string.IsNullOrEmpty(input)) { // ?? } else { var Request = new StringReader(input); var RequestLine = Request.ReadLine(); Console.WriteLine("doaccept will call doaccept_Handler " + new { accept.socketId }); var xxx = doaccept_Handler(RequestLine, accept.socketId); await xxx; Console.WriteLine("doaccept will call doaccept_Handler done " + new { accept.socketId }); } // https://code.google.com/p/chromium/issues/detail?id=170595 Console.WriteLine("doaccept exit " + new { accept.socketId, HandlerStopwatch.ElapsedMilliseconds }); accept.socketId.disconnect(); accept.socketId.destroy(); }; #endregion // Error in response to socket.getNetworkList: illegal access #region getNetworkList chrome.socket.getNetworkList().ContinueWithResult( async n => { // um. new IP? //Console.WriteLine(new { n.Length }); // Error in response to socket.getNetworkList: TypeError: Cannot read property 'address' of undefined foreach (var item in n) { Console.WriteLine(new { item.name, item.address }); } //a.WithEach(item => Console.WriteLine(new { item.name, item.address }.ToString())); // do we even have wifi? var address = GetAddresss(n); var port = new Random().Next(8000, 9000); var uri = "http://" + address + ":" + port; // Error in response to socket.create: illegal access // The uncaught illegal access error usually means you are trying to parse something that is NULL. -edit- IMHO this.end === null over == also. // wtf chrome??? // http://developer.chrome.com/apps/socket.html Console.WriteLine("before socket.create"); //var i = await socket.create("tcp", new object { }); var ix = await socket.create("tcp", null); // ix.toString now causes invalid access? // Error 5 A local variable named 'socket' cannot be declared in this scope because it would give a different meaning to 'socket', which is already used in a 'parent or current' scope to denote something else X:\jsc.svn\examples\javascript\chrome\apps\ChromeTCPServer\ChromeTCPServer\Application.cs 653 24 ChromeTCPServer var isocket = ix.socketId; Console.WriteLine("after socket.create "); // no longer can call implict toString? Console.WriteLine("after socket.create " + new { isocket }.ToString()); // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2013/201310/20131029-nuget // https://code.google.com/p/ssh-persistent-tunnel/issues/detail?id=6 //var listen = await i.socketId.listen(address, port, 50); // Error in response to socket.listen: illegal access var host = "0.0.0.0"; Console.WriteLine("before socketId.listen " + new { host, port }); var listen = await isocket.listen(host, port, 50); //Console.WriteLine(new { i.socketId, uri }); //// https://code.google.com/p/chromium/issues/detail?id=253304 Console.WriteLine(new { listen }); //{ listen = -1 } if (listen >= 0) { #region advertise Action advertise = delegate { var visitme = "Visit me at " + address + ":" + port; // send one without image too... MulticastSend( "", visitme, "", chrome.Notification.DefaultTitle ); new IHTMLImage { src = chrome.Notification.DefaultIconUrl }.InvokeOnComplete( preview => { MulticastSend( "", visitme, preview.toDataURL(), chrome.Notification.DefaultTitle ); } ); }; #endregion #region ShowUri Action ShowUri = null; ShowUri = delegate { var nn = new chrome.Notification { //Message = new { uri }.ToString(), Message = uri, }; nn.Clicked += async delegate { advertise(); await open(uri); ShowUri(); }; }; ShowUri(); #endregion #region Launched chrome.app.runtime.Launched += async delegate { advertise(); await open(uri); ShowUri(); }; #endregion var forever = true; var accept_gap = new Stopwatch(); while (forever) { Console.WriteLine("before accept gap: " + new { accept_gap.ElapsedMilliseconds }); var accept = await isocket.accept(); accept_gap.Restart(); // https://code.google.com/p/chromium/issues/detail?id=170595 //await Task.Delay(1000); var delayaccept = accept; Task.Delay(111).GetAwaiter().OnCompleted( delegate { Console.WriteLine("at accept " + new { delayaccept.socketId }); doaccept(delayaccept); } ); } } Console.WriteLine("done!"); } ); #endregion }
// FIXME: Make overloads for other types, as this one is supposed to clamp values? /// <summary> /// Creates a new Uint8ClampedArray out of the specified Uint8ClampedArray. /// </summary> /// <param name="typedArray">Uint8ClampedArray to use as initial contents to the new array.</param> public Uint8ClampedArray(Uint8ClampedArray typedArray) { }
/// <summary> /// Creates an ImageData object from a given Uint8ClampedArray and the size of the image it contains. /// Note that this is the most common way to create such an object in workers as createImageData() /// is not available there. /// </summary> /// <param name="array">A Uint8ClampedArray containing the underlying pixel representation of theimage.</param> /// <param name="width">An unsigned long representing the width of the represented image.</param> /// <param name="height"> /// An unsigned long representing the height of the represented image. This value is optional /// if an array is given: it will be inferred from its size and the given width. /// </param> /// <remarks>This is experimental API that should not be used in production code.</remarks> public ImageData(Uint8ClampedArray array, ulong width, ulong? height = null) { }
// X:\jsc.svn\examples\javascript\chrome\apps\ChromeTCPMultiPort\ChromeTCPMultiPort\Application.cs // X:\jsc.svn\core\ScriptCoreLib\JavaScript\BCLImplementation\System\Net\IPAddress.cs // X:\jsc.svn\examples\javascript\chrome\apps\ChromeTCPServerAsync\ChromeTCPServerAsync\Application.cs public __TcpListener(IPAddress localaddr, int port) { var host = "0.0.0.0"; var isocket_after_listen = new TaskCompletionSource<socketId>(); // we have to set it ahead of time! this.VirtualAcceptTcpClientAsync = async delegate { Console.WriteLine("at VirtualAcceptTcpClientAsync"); // idl is not marking it as enum:int? socketId iisocket = await isocket_after_listen.Task; Console.WriteLine("at VirtualAcceptTcpClientAsync accept... " + new { iisocket }); if (!((int)(object)iisocket > 0)) { // Unchecked runtime.lastError while running socket.listen: Could not listen on the specified port. // throw? return null; } var accept = await iisocket.accept(); // accept {{ c = {{ resultCode = -2, socketId = null }} }} Console.WriteLine("at VirtualAcceptTcpClientAsync accept... " + new { accept.resultCode, accept.socketId }); //33551ms at VirtualAcceptTcpClientAsync accept... { { accept = [object Object] } } if (accept.resultCode < 0) { // throw? return null; } return new __TcpClient { VirtualClose = delegate { accept.socketId.disconnect(); accept.socketId.destroy(); }, VirtualGetStream = () => new __NetworkStream { VirtualWriteAsync = async (byte[] buffer, int offset, int count) => { var copy = new byte[count]; Array.Copy( buffer, offset, copy, 0, count ); var xx = new Uint8ClampedArray(copy); var write = await accept.socketId.write(xx.buffer); // report error? }, VirtualReadAsync = async (byte[] buffer, int offset, int count) => { var read = await accept.socketId.read(bufferSize: count); // whats the best way to copy buffer to buffer? byte[] sourceArray = new Uint8ClampedArray(read.data, 0, (uint)read.data.byteLength); Array.Copy( sourceArray, sourceIndex: 0, destinationArray: buffer, destinationIndex: offset, length: sourceArray.Length ); return sourceArray.Length; } }, VirtualToString = () => new { accept.resultCode, accept.socketId }.ToString() }; }; #region VirtualStart this.VirtualStart = async backlog => { var ix = await socket.create("tcp", null); var isocket = ix.socketId; Console.WriteLine("at VirtualStart " + new { isocket }); var listen = await isocket.listen(host, port, backlog: backlog); Console.WriteLine("at VirtualStart " + new { listen }); isocket_after_listen.SetResult(isocket); }; #endregion }
public void set(Uint8ClampedArray array, uint offset) { }