public static void NodejsFuncComplete(IntPtr context, int taskStatus, IntPtr result, int resultType) { CoreCLREmbedding.DebugMessage("NodejsFuncInvokeContext::NodejsFuncComplete (CLR) - Starting"); GCHandle gcHandle = GCHandle.FromIntPtr(context); NodejsFuncInvokeContext actualContext = (NodejsFuncInvokeContext)gcHandle.Target; gcHandle.Free(); V8Type v8ResultType = (V8Type)resultType; object marshalledResult = CoreCLREmbedding.MarshalV8ToCLR(result, v8ResultType); CoreCLREmbedding.DebugMessage("NodejsFuncInvokeContext::NodejsFuncComplete (CLR) - Marshalled result data back to the CLR"); if (taskStatus == (int)TaskStatus.Faulted) { actualContext.TaskCompletionSource.SetException((Exception)marshalledResult); CoreCLREmbedding.DebugMessage("NodejsFuncInvokeContext::NodejsFuncComplete (CLR) - Set the exception received from Node.js: {0}", ((Exception)marshalledResult).Message); } else { actualContext.TaskCompletionSource.SetResult(marshalledResult); CoreCLREmbedding.DebugMessage("NodejsFuncInvokeContext::NodejsFuncComplete (CLR) - Set result data"); } CoreCLREmbedding.DebugMessage("NodejsFuncInvokeContext::NodejsFuncComplete (CLR) - Finished"); }
private Task <object> FunctionWrapper(object payload) { CoreCLREmbedding.DebugMessage("NodejsFunc::FunctionWrapper (CLR) - Started"); NodejsFuncInvokeContext invokeContext = new NodejsFuncInvokeContext(this, payload); invokeContext.CallFunc(); CoreCLREmbedding.DebugMessage("NodejsFunc::FunctionWrapper (CLR) - Node.js function invoked on the V8 thread, returning the task completion source"); return(invokeContext.TaskCompletionSource.Task); }
internal void CallFunc() { CoreCLREmbedding.DebugMessage("NodejsFuncInvokeContext::CallFunc (CLR) - Starting"); V8Type v8PayloadType; IntPtr v8Payload = CoreCLREmbedding.MarshalCLRToV8(payload, out v8PayloadType); CoreCLREmbedding.DebugMessage("NodejsFuncInvokeContext::CallFunc (CLR) - Marshalled payload data for V8"); IntPtr callbackContext = GCHandle.ToIntPtr(GCHandle.Alloc(this)); CoreCLREmbedding.DebugMessage("NodejsFuncInvokeContext::CallFunc (CLR) - Getting a GCHandle for this context object"); CoreCLREmbedding.DebugMessage("NodejsFuncInvokeContext::CallFunc (CLR) - Invoking the unmanaged V8 function to invoke the Node.js function on the V8 thread"); CallV8Function(v8Payload, (int)v8PayloadType, functionContext.Context, callbackContext, NodejsFuncCompleteCallback); }