public static object MarshalV8ToCLR(IntPtr v8Object, V8Type objectType) { switch (objectType) { case V8Type.String: return Marshal.PtrToStringAnsi(v8Object); case V8Type.Object: return V8ObjectToExpando(Marshal.PtrToStructure<V8ObjectData>(v8Object)); case V8Type.Boolean: return Marshal.ReadByte(v8Object) != 0; case V8Type.Number: return ReadDouble(v8Object); case V8Type.Date: double ticks = ReadDouble(v8Object); return new DateTime(Convert.ToInt64(ticks) * 10000 + MinDateTimeTicks, DateTimeKind.Utc); case V8Type.Null: return null; case V8Type.Int32: return Marshal.ReadInt32(v8Object); case V8Type.UInt32: return (uint)Marshal.ReadInt32(v8Object); case V8Type.Function: NodejsFunc nodejsFunc = new NodejsFunc(v8Object); return nodejsFunc.GetFunc(); case V8Type.Array: V8ArrayData arrayData = Marshal.PtrToStructure<V8ArrayData>(v8Object); object[] array = new object[arrayData.arrayLength]; for (int i = 0; i < arrayData.arrayLength; i++) { int itemType = Marshal.ReadInt32(arrayData.itemTypes, i * sizeof(int)); IntPtr itemValuePointer = Marshal.ReadIntPtr(arrayData.itemValues, i * PointerSize); array[i] = MarshalV8ToCLR(itemValuePointer, (V8Type)itemType); } return array; case V8Type.Buffer: V8BufferData bufferData = Marshal.PtrToStructure<V8BufferData>(v8Object); byte[] buffer = new byte[bufferData.bufferLength]; Marshal.Copy(bufferData.buffer, buffer, 0, bufferData.bufferLength); return buffer; case V8Type.Exception: string message = Marshal.PtrToStringAnsi(v8Object); return new Exception(message); default: throw new Exception("Unsupported V8 object type: " + objectType + "."); } }
public NodejsFuncInvokeContext(NodejsFunc functionContext, object payload) { this.functionContext = functionContext; this.payload = payload; this.TaskCompletionSource = new TaskCompletionSource<object>(); }
public NodejsFuncInvokeContext(NodejsFunc functionContext, object payload) { this.functionContext = functionContext; this.payload = payload; this.TaskCompletionSource = new TaskCompletionSource <object>(); }
public static object MarshalV8ToCLR(IntPtr v8Object, V8Type objectType) { switch (objectType) { case V8Type.String: return(Marshal.PtrToStringAnsi(v8Object)); case V8Type.Object: return(V8ObjectToExpando(Marshal.PtrToStructure <V8ObjectData>(v8Object))); case V8Type.Boolean: return(Marshal.ReadByte(v8Object) != 0); case V8Type.Number: return(ReadDouble(v8Object)); case V8Type.Date: double ticks = ReadDouble(v8Object); return(new DateTime(Convert.ToInt64(ticks) * 10000 + MinDateTimeTicks, DateTimeKind.Utc)); case V8Type.Null: return(null); case V8Type.Int32: return(Marshal.ReadInt32(v8Object)); case V8Type.UInt32: return((uint)Marshal.ReadInt32(v8Object)); case V8Type.Function: NodejsFunc nodejsFunc = new NodejsFunc(v8Object); return(nodejsFunc.GetFunc()); case V8Type.Array: V8ArrayData arrayData = Marshal.PtrToStructure <V8ArrayData>(v8Object); object[] array = new object[arrayData.arrayLength]; for (int i = 0; i < arrayData.arrayLength; i++) { int itemType = Marshal.ReadInt32(arrayData.itemTypes, i * sizeof(int)); IntPtr itemValuePointer = Marshal.ReadIntPtr(arrayData.itemValues, i * PointerSize); array[i] = MarshalV8ToCLR(itemValuePointer, (V8Type)itemType); } return(array); case V8Type.Buffer: V8BufferData bufferData = Marshal.PtrToStructure <V8BufferData>(v8Object); byte[] buffer = new byte[bufferData.bufferLength]; Marshal.Copy(bufferData.buffer, buffer, 0, bufferData.bufferLength); return(buffer); case V8Type.Exception: string message = Marshal.PtrToStringAnsi(v8Object); return(new Exception(message)); default: throw new Exception("Unsupported V8 object type: " + objectType + "."); } }