private static void EmitInvoker(EmitHelper emit, MethodInfo method, int?argc, bool setter) { var parameters = method.GetParameters(); var methodArgC = parameters.Length; if (!argc.HasValue) { EmitThrowIfArgumentCountMismatch(emit, methodArgC); argc = methodArgC; } emit.LdArg(retvalArgIndex); // instance method if (!method.IsStatic) { emit.LdArg(objArgIndex); } // prepare arguments for (var i = 0; i < parameters.Length; i++) { var parameter = parameters[i]; if (i < argc.Value) { var changeTypeMethod = CefConvert.GetChangeTypeMethod(typeof(cef_v8value_t *), parameter.ParameterType); EmitLdV8Argument(emit, i); emit.Call(changeTypeMethod); } else { // push default arg if (!parameter.IsOptional) { throw new JSBindingException("MethodInvoker compilation error."); } EmitLdRawDefaultValue(emit, parameter.RawDefaultValue); } } // call target method if (method.IsStatic) { emit.Call(method); } else { emit.CallVirt(method); } if (method.ReturnType == typeof(void)) { // If method is setter, then it can be called with retval == null from V8Accessor. if (setter) { var returnValueLabel = emit.DefineLabel(); emit.Dup() .BrTrueS(returnValueLabel) .Pop() .Ret() .MarkLabel(returnValueLabel); ; } if (ForceVoidToUndefined) { emit.Call(createUndefinedNativeV8ValueMethod); } else { emit.LdNull(); } } else { // convert return value var retValchangeTypeMethod = CefConvert.GetChangeTypeMethod(method.ReturnType, typeof(cef_v8value_t *)); emit.Call(retValchangeTypeMethod); } // store result at retval emit.StIndI(); // return emit.Ret(); }
private static void EmitInvoker(EmitHelper emit, MethodInfo method, int? argc, bool setter) { var parameters = method.GetParameters(); var methodArgC = parameters.Length; if (!argc.HasValue) { EmitThrowIfArgumentCountMismatch(emit, methodArgC); argc = methodArgC; } emit.LdArg(retvalArgIndex); // instance method if (!method.IsStatic) { emit.LdArg(objArgIndex); } // prepare arguments for (var i = 0; i < parameters.Length; i++) { var parameter = parameters[i]; if (i < argc.Value) { var changeTypeMethod = CefConvert.GetChangeTypeMethod(typeof(cef_v8value_t*), parameter.ParameterType); EmitLdV8Argument(emit, i); emit.Call(changeTypeMethod); } else { // push default arg if (!parameter.IsOptional) throw new JSBindingException("MethodInvoker compilation error."); EmitLdRawDefaultValue(emit, parameter.RawDefaultValue); } } // call target method if (method.IsStatic) { emit.Call(method); } else { emit.CallVirt(method); } if (method.ReturnType == typeof(void)) { // If method is setter, then it can be called with retval == null from V8Accessor. if (setter) { var returnValueLabel = emit.DefineLabel(); emit.Dup() .BrTrueS(returnValueLabel) .Pop() .Ret() .MarkLabel(returnValueLabel); ; } if (ForceVoidToUndefined) { emit.Call(createUndefinedNativeV8ValueMethod); } else { emit.LdNull(); } } else { // convert return value var retValchangeTypeMethod = CefConvert.GetChangeTypeMethod(method.ReturnType, typeof(cef_v8value_t*)); emit.Call(retValchangeTypeMethod); } // store result at retval emit.StIndI(); // return emit.Ret(); }