CreateReferenceError() public static method

Creates a new JavaScript ReferenceError error object
Requires an active script context.
public static CreateReferenceError ( string message ) : EdgeJsValue
message string The message that describes the error
return EdgeJsValue
        private void ProjectMethods(EdgeJsValue target, Type type, bool instance)
        {
            string       typeName            = type.FullName;
            BindingFlags defaultBindingFlags = ReflectionHelpers.GetDefaultBindingFlags(instance);

            MethodInfo[] methods = type.GetMethods(defaultBindingFlags);
            IEnumerable <IGrouping <string, MethodInfo> > methodGroups = methods.GroupBy(m => m.Name);

            foreach (IGrouping <string, MethodInfo> methodGroup in methodGroups)
            {
                string       methodName       = methodGroup.Key;
                MethodInfo[] methodCandidates = methodGroup.ToArray();

                EdgeJsNativeFunction nativeFunction = (callee, isConstructCall, args, argCount, callbackData) =>
                {
                    EdgeJsValue thisValue      = args[0];
                    EdgeJsValue undefinedValue = EdgeJsValue.Undefined;

                    object thisObj = null;

                    if (instance)
                    {
                        if (!thisValue.HasExternalData)
                        {
                            EdgeJsValue errorValue = EdgeJsErrorHelpers.CreateTypeError(
                                string.Format(NetCoreStrings.Runtime_InvalidThisContextForHostObjectMethod, methodName));
                            EdgeJsErrorHelpers.SetException(errorValue);

                            return(undefinedValue);
                        }

                        thisObj = MapToHostType(thisValue);
                    }

                    object[] processedArgs = MapToHostType(args.Skip(1).ToArray());

                    var bestFitMethod = (MethodInfo)ReflectionHelpers.GetBestFitMethod(
                        methodCandidates, processedArgs);
                    if (bestFitMethod == null)
                    {
                        EdgeJsValue errorValue = EdgeJsErrorHelpers.CreateReferenceError(
                            string.Format(NetCoreStrings.Runtime_SuitableMethodOfHostObjectNotFound, methodName));
                        EdgeJsErrorHelpers.SetException(errorValue);

                        return(undefinedValue);
                    }

                    ReflectionHelpers.FixArgumentTypes(ref processedArgs, bestFitMethod.GetParameters());

                    object result;

                    try
                    {
                        result = bestFitMethod.Invoke(thisObj, processedArgs);
                    }
                    catch (Exception e)
                    {
                        string errorMessage = instance ?
                                              string.Format(
                            NetCoreStrings.Runtime_HostObjectMethodInvocationFailed, methodName, e.Message)
                                                        :
                                              string.Format(
                            NetCoreStrings.Runtime_HostTypeMethodInvocationFailed, methodName, typeName, e.Message)
                        ;

                        EdgeJsValue errorValue = EdgeJsErrorHelpers.CreateError(errorMessage);
                        EdgeJsErrorHelpers.SetException(errorValue);

                        return(undefinedValue);
                    }

                    EdgeJsValue resultValue = MapToScriptType(result);

                    return(resultValue);
                };
                _nativeFunctions.Add(nativeFunction);

                EdgeJsValue methodValue = EdgeJsValue.CreateFunction(nativeFunction);
                target.SetProperty(methodName, methodValue, true);
            }
        }
        private EdgeJsValue CreateConstructor(Type type)
        {
            TypeInfo     typeInfo            = type.GetTypeInfo();
            string       typeName            = type.FullName;
            BindingFlags defaultBindingFlags = ReflectionHelpers.GetDefaultBindingFlags(true);

            ConstructorInfo[] constructors = type.GetConstructors(defaultBindingFlags);

            EdgeJsNativeFunction nativeFunction = (callee, isConstructCall, args, argCount, callbackData) =>
            {
                EdgeJsValue resultValue;
                EdgeJsValue undefinedValue = EdgeJsValue.Undefined;

                object[] processedArgs = MapToHostType(args.Skip(1).ToArray());
                object   result;

                if (processedArgs.Length == 0 && typeInfo.IsValueType)
                {
                    result      = Activator.CreateInstance(type);
                    resultValue = MapToScriptType(result);

                    return(resultValue);
                }

                if (constructors.Length == 0)
                {
                    EdgeJsValue errorValue = EdgeJsErrorHelpers.CreateError(
                        string.Format(NetCoreStrings.Runtime_HostTypeConstructorNotFound, typeName));
                    EdgeJsErrorHelpers.SetException(errorValue);

                    return(undefinedValue);
                }

                var bestFitConstructor = (ConstructorInfo)ReflectionHelpers.GetBestFitMethod(
                    constructors, processedArgs);
                if (bestFitConstructor == null)
                {
                    EdgeJsValue errorValue = EdgeJsErrorHelpers.CreateReferenceError(
                        string.Format(NetCoreStrings.Runtime_SuitableConstructorOfHostTypeNotFound, typeName));
                    EdgeJsErrorHelpers.SetException(errorValue);

                    return(undefinedValue);
                }

                ReflectionHelpers.FixArgumentTypes(ref processedArgs, bestFitConstructor.GetParameters());

                try
                {
                    result = bestFitConstructor.Invoke(processedArgs);
                }
                catch (Exception e)
                {
                    EdgeJsValue errorValue = EdgeJsErrorHelpers.CreateError(
                        string.Format(NetCoreStrings.Runtime_HostTypeConstructorInvocationFailed, typeName, e.Message));
                    EdgeJsErrorHelpers.SetException(errorValue);

                    return(undefinedValue);
                }

                resultValue = MapToScriptType(result);

                return(resultValue);
            };

            _nativeFunctions.Add(nativeFunction);

            EdgeJsValue constructorValue = EdgeJsValue.CreateFunction(nativeFunction);

            return(constructorValue);
        }