private static MemberAddInfo Member(string name, AnalysisValue value) {
     return new MemberAddInfo(name, value);
 }
        private BuiltinFunctionValue NumberFunction(out AnalysisValue numberPrototype) {
            var builtinEntry = _analyzer._builtinEntry;

            var prototype = new BuiltinObjectValue(builtinEntry) {
                    BuiltinFunction("constructor"),
                    ReturningFunction(
                        "toExponential",
                        _analyzer._emptyStringValue,
                        "Returns a string containing a number represented in exponential notation."
                    ),
                    ReturningFunction(
                        "toFixed",
                        _analyzer._emptyStringValue,
                        "Returns a string representing a number in fixed-point notation."
                    ),
                    BuiltinFunction("toLocaleString"),
                    BuiltinFunction(
                        "toPrecision",
                        "Returns a string containing a number represented either in exponential or fixed-point notation with a specified number of digits.",
                        Parameter("precision", "Number of significant digits. Must be in the range 1 - 21, inclusive.", isOptional: true)
                    ),
                    ReturningFunction(
                        "toString",
                        _analyzer._emptyStringValue,
                        "Returns a string representation of an object.",
                        Parameter("radix", "Specifies a radix for converting numeric values to strings. This value is only used for numbers.", isOptional: true)
                    ),
                    BuiltinFunction("valueOf"),
            };
            numberPrototype = prototype;

            return new BuiltinFunctionValue(builtinEntry, "Number", null, prototype) { 
                Member("length", _analyzer.GetConstant(1.0)),
                Member("name", _analyzer.GetConstant("Number")),
                Member("arguments", _analyzer._nullInst),
                Member("caller", _analyzer._nullInst),
                Member("MAX_VALUE", _analyzer.GetConstant(Double.MaxValue)),
                Member("MIN_VALUE", _analyzer.GetConstant(Double.MinValue)),
                Member("NaN", _analyzer.GetConstant(Double.NaN)),
                Member("NEGATIVE_INFINITY", _analyzer.GetConstant(Double.NegativeInfinity)),
                Member("POSITIVE_INFINITY", _analyzer.GetConstant(Double.PositiveInfinity)),
                ReturningFunction(
                    "isFinite", 
                    _analyzer._trueInst,
                    "Determines whether a supplied number is finite."
                ),
                ReturningFunction(
                    "isNaN", 
                    _analyzer._falseInst,
                    "Returns a Boolean value that indicates whether a value is the reserved value NaN (not a number)."
                ),
            };
        }
        private BuiltinFunctionValue StringFunction(out AnalysisValue stringPrototype) {
            var builtinEntry = _analyzer._builtinEntry;
            var prototype = new BuiltinObjectValue(builtinEntry) {
                    ReturningFunction(
                        "anchor",
                        _analyzer._emptyStringValue,
                        "Surrounds the provided string with an <a name=...> tag.",
                        Parameter("name", "the name attribute for the anchor")
                    ),
                    ReturningFunction(
                        "big",
                        _analyzer._emptyStringValue,
                        "Surrounds the provided string with a <big> tag."
                    ),
                    ReturningFunction(
                        "blink",
                        _analyzer._emptyStringValue,
                        "Surrounds the provided string with a <blink> tag."
                    ),
                    ReturningFunction(
                        "bold",
                        _analyzer._emptyStringValue,
                        "Surrounds the provided string with a <bold> tag."
                    ),
                    ReturningFunction(
                        "charAt", 
                        _analyzer._emptyStringValue,
                        "Returns the character at the specified index.", 
                        Parameter("pos", "The zero-based index of the desired character.")
                    ),
                    ReturningFunction(
                        "charCodeAt", 
                        _analyzer._zeroIntValue,
                        "Returns the Unicode value of the character at the specified location.", 
                        Parameter("index", "The zero-based index of the desired character. If there is no character at the specified index, NaN is returned.")
                    ),
                    BuiltinFunction("concat", 
                        "Returns a string that contains the concatenation of two or more strings.", 
                        Parameter("...")
                    ),
                    BuiltinFunction("constructor"),
                    ReturningFunction(
                        "fixed",
                        _analyzer._emptyStringValue,
                        "Surrounds the provided string with a <tt> tag."
                    ),
                    ReturningFunction(
                        "fontcolor",
                        _analyzer._emptyStringValue,
                        "Surrounds the provided string with a <font color=...> tag.",
                        Parameter("color", "the color attribute for the font tag")
                    ),
                    ReturningFunction(
                        "fontsize",
                        _analyzer._emptyStringValue,
                        "Surrounds the provided string with a <font size=...> tag.",
                        Parameter("size", "the size attribute for the font tag")
                    ),
                    BuiltinFunction("indexOf", 
                        "Returns the position of the first occurrence of a substring.", 
                        Parameter("searchString", "The substring to search for in the string"), 
                        Parameter("position", "The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.", true)
                    ),
                    ReturningFunction(
                        "italics",
                        _analyzer._emptyStringValue,
                        "Surrounds the provided string with an <i> tag."
                    ),
                    BuiltinFunction(
                        "lastIndexOf", 
                        "Returns the last occurrence of a substring in the string.", 
                        Parameter("searchString", "The substring to search for."), 
                        Parameter("position", "The index at which to begin searching. If omitted, the search begins at the end of the string.", true)
                    ),
                    BuiltinProperty("length", _analyzer._zeroIntValue),
                    ReturningFunction(
                        "link",
                        _analyzer._emptyStringValue,
                        "Surrounds the provided string with an <a href=...> tag.",
                        Parameter("href", "the href attribute for the tag")
                    ),
                    BuiltinFunction(
                        "localeCompare", 
                        "Determines whether two strings are equivalent in the current locale.",
                        Parameter("that", "String to compare to target string")
                    ),
                    BuiltinFunction(
                        "match",
                        "Matches a string with a regular expression, and returns an array containing the results of that search.",
                        Parameter("regexp", "A string containing the regular expression pattern and flags or a RegExp.")

                    ),
                    BuiltinFunction(
                        "replace",
                        "Replaces text in a string, using a regular expression or search string.",
                        Parameter("searchValue", "A string that represents the regular expression or a RegExp"),
                        Parameter("replaceValue", "A string containing the text replacement text or a function which returns it.")
                    ),
                    BuiltinFunction(
                        "search",
                        "Finds the first substring match in a regular expression search.",
                        Parameter("regexp", "The regular expression pattern and applicable flags.")
                    ),
                    BuiltinFunction(
                        "slice",
                        "Returns a section of a string.",
                        Parameter("start", "The index to the beginning of the specified portion of stringObj."),
                        Parameter("end", "The index to the end of the specified portion of stringObj. The substring includes the characters up to, but not including, the character indicated by end.  If this value is not specified, the substring continues to the end of stringObj.")
                    ),
                    ReturningFunction(
                        "small",
                        _analyzer._emptyStringValue,
                        "Surrounds the provided string with a <small> tag."
                    ),
                    BuiltinFunction(
                        "split",
                        "Split a string into substrings using the specified separator and return them as an array.",
                        Parameter("separator", "A string that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned. "),
                        Parameter("limit", "A value used to limit the number of elements returned in the array.", isOptional: true)
                    ),
                    ReturningFunction(
                        "strike",
                        _analyzer._emptyStringValue,
                        "Surrounds the provided string with a <strike> tag."
                    ),
                    ReturningFunction(
                        "sub",
                        _analyzer._emptyStringValue,
                        "Surrounds the provided string with a <sub> tag."
                    ),
                    BuiltinFunction("substr"),
                    BuiltinFunction(
                        "substring",
                        "Returns the substring at the specified location within a String object. ",
                        Parameter("start", "The zero-based index number indicating the beginning of the substring."),
                        Parameter("end", "Zero-based index number indicating the end of the substring. The substring includes the characters up to, but not including, the character indicated by end.  If end is omitted, the characters from start through the end of the original string are returned.")
                    ),
                    ReturningFunction(
                        "sup",
                        _analyzer._emptyStringValue,
                        "Surrounds the provided string with a <sup> tag."
                    ),
                    BuiltinFunction(
                        "toLocaleLowerCase",
                        "Converts all alphabetic characters to lowercase, taking into account the host environment's current locale."
                    ),
                    BuiltinFunction(
                        "toLocaleUpperCase",
                        "Returns a string where all alphabetic characters have been converted to uppercase, taking into account the host environment's current locale."
                    ),
                    SpecializedFunction(
                        "toLowerCase",
                        StringToLowerCase,
                        "Converts all the alphabetic characters in a string to lowercase."
                    ),
                    BuiltinFunction(
                        "toString",
                        "Returns a string representation of a string."
                    ),
                    SpecializedFunction(
                        "toUpperCase",
                        StringToUpperCase,
                        "Converts all the alphabetic characters in a string to uppercase."
                    ),
                    BuiltinFunction(
                        "trim",
                        "Removes the leading and trailing white space and line terminator characters from a string."
                    ),
                    BuiltinFunction(
                        "trimLeft",
                        "Removes the leading white space and line terminator characters from a string."
                    ),
                    BuiltinFunction(
                        "trimRight",
                        "Removes the trailing white space and line terminator characters from a string."
                    ),
                    BuiltinFunction("valueOf"),
            };
            stringPrototype = prototype;

            return new BuiltinFunctionValue(builtinEntry, "String", null, prototype) { 
                ReturningFunction("fromCharCode", _analyzer.GetConstant(String.Empty)),
            };
        }
 public override FunctionValue Specialize(ProjectEntry projectEntry, string name, string doc, AnalysisValue returnValue, ParameterResult[] parameters)
 {
     return(new CallbackReturningFunctionValue(
                projectEntry,
                name,
                returnValue != null ? returnValue.SelfSet : AnalysisSet.Empty,
                _index,
                _args,
                doc,
                parameters
                ));
 }
 /// <summary>
 /// Determines whether two analysis values are effectively equivalent.
 /// </summary>
 /// <remarks>
 /// The intent of <paramref name="strength"/> is to allow different
 /// types to merge more aggressively. For example, string constants
 /// may merge into a non-specific string instance at a low strength,
 /// while distinct user-defined types may merge into <c>object</c> only
 /// at higher strengths. There is no defined maximum value.
 /// </remarks>
 internal virtual bool UnionEquals(AnalysisValue av, int strength) {
     return Equals(av);
 }
 public Globals(ObjectValue globalObject, AnalysisValue numberPrototype, AnalysisValue stringPrototype, AnalysisValue booleanPrototype, AnalysisValue functionPrototype, FunctionValue arrayFunction, ObjectValue objectPrototype, BuiltinFunctionValue requireFunction, ExpandoValue arrayPrototype, BuiltinFunctionValue objectGetOwnPropertyDescriptor) {
     GlobalObject = globalObject;
     NumberPrototype = numberPrototype;
     StringPrototype = stringPrototype;
     BooleanPrototype = booleanPrototype;
     FunctionPrototype = functionPrototype;
     ArrayFunction = arrayFunction;
     ObjectPrototype = objectPrototype;
     RequireFunction = requireFunction;
     ArrayPrototype = arrayPrototype;
     ObjectGetOwnPropertyDescriptor = objectGetOwnPropertyDescriptor;
 }
        private BuiltinFunctionValue FunctionFunction(out AnalysisValue functionPrototype) {
            var builtinEntry = _analyzer._builtinEntry;
            var prototype = new ReturningConstructingFunctionValue(builtinEntry, "Empty", _analyzer._undefined.Proxy, null) {
                    SpecializedFunction(
                        "apply",
                        ApplyFunction,
                        "Calls the function, substituting the specified object for the this value of the function, and the specified array for the arguments of the function.",
                        Parameter("thisArg", "The object to be used as the this object."),
                        Parameter("argArray", "A set of arguments to be passed to the function.")
                    ),
                    BuiltinFunction(
                        "bind",
                        @"For a given function, creates a bound function that has the same body as the original function. 
The this object of the bound function is associated with the specified object, and has the specified initial parameters.",
                        Parameter("thisArg", "An object to which the this keyword can refer inside the new function."),
                        Parameter("argArray", "A list of arguments to be passed to the new function.")

                    ),
                    BuiltinFunction(
                        "call",
                        "Calls a method of an object, substituting another object for the current object.",
                        Parameter("thisArg", "The object to be used as the current object."),
                        Parameter("argArray", "A list of arguments to be passed to the method.")
                    ),
                    BuiltinFunction("constructor"),
                    ReturningFunction("toString", _analyzer._emptyStringValue),
            };
            functionPrototype = prototype;
            return new BuiltinFunctionValue(builtinEntry, "Function", null, prototype);
        }
 public override FunctionValue Specialize(ProjectEntry projectEntry, string name, string doc, AnalysisValue returnValue, ParameterResult[] parameters) {
     return new SpecializedFunctionValue(
         projectEntry,
         name,
         _delegate,
         doc,
         null,
         parameters
     );
 }
 public override FunctionValue Specialize(ProjectEntry projectEntry, string name, string doc, AnalysisValue returnValue, ParameterResult[] parameters) {
     return new CallbackReturningFunctionValue(
         projectEntry,
         name,
         returnValue != null ? returnValue.SelfSet : AnalysisSet.Empty,
         _index,
         _args,
         doc,
         parameters
     );
 }
Beispiel #10
0
 /// <summary>
 /// Determines whether two analysis values are effectively equivalent.
 /// </summary>
 /// <remarks>
 /// The intent of <paramref name="strength"/> is to allow different
 /// types to merge more aggressively. For example, string constants
 /// may merge into a non-specific string instance at a low strength,
 /// while distinct user-defined types may merge into <c>object</c> only
 /// at higher strengths. There is no defined maximum value.
 /// </remarks>
 internal virtual bool UnionEquals(AnalysisValue av, int strength)
 {
     return(Equals(av));
 }
 public abstract FunctionValue Specialize(ProjectEntry projectEntry, string name, string doc, AnalysisValue returnValue, ParameterResult[] parameters);
Beispiel #12
0
 /// <summary>
 /// Returns an analysis value representative of both this and another
 /// analysis value. This should only be called when
 /// <see cref="UnionEquals"/> returns true for the two values.
 /// </summary>
 /// <param name="av">The value to merge with.</param>
 /// <param name="strength">A value matching that passed to
 /// <see cref="UnionEquals"/>.</param>
 /// <returns>A merged analysis value.</returns>
 /// <remarks>
 /// <para>Calling this function when <see cref="UnionEquals"/> returns
 /// false for the same parameters is undefined.</para>
 ///
 /// <para>Where there is no analysis value representative of those
 /// provided, it is preferable to return this rather than
 /// <paramref name="av"/>.</para>
 ///
 /// <para>
 /// <paramref name="strength"/> is used as a key in this function and must
 /// match the value used in <see cref="UnionEquals"/>.
 /// </para>
 /// </remarks>
 internal virtual AnalysisValue UnionMergeTypes(AnalysisValue av, int strength)
 {
     return(this);
 }
Beispiel #13
0
        private void GenerateProperties(dynamic klass, ObjectValue value, Dictionary <string, PropertySpecializer> specializers)
        {
            if (klass.ContainsKey("properties"))
            {
                foreach (var prop in klass["properties"])
                {
                    string propName = prop["name"];
                    string desc     = ParseDocumentation(prop["desc"]);

                    string textRaw = "";
                    if (prop.ContainsKey("textRaw"))
                    {
                        textRaw = prop["textRaw"];
                    }

                    PropertySpecializer specializer;
                    AnalysisValue       propValue = null;
                    if (specializers != null &&
                        specializers.TryGetValue(propName, out specializer))
                    {
                        propValue = specializer.Specialize(value.ProjectEntry, propName);
                    }
                    else if (desc.IndexOf("<code>Boolean</code>") != -1)
                    {
                        propValue = value.ProjectEntry.Analyzer._trueInst;
                    }
                    else if (desc.IndexOf("<code>Number</code>") != -1)
                    {
                        propValue = value.ProjectEntry.Analyzer._zeroIntValue;
                    }
                    else if (desc.IndexOf("<code>Readable Stream</code>") != -1)
                    {
                        propValue = _readableStream;
                    }
                    else if (desc.IndexOf("<code>Writable Stream</code>") != -1 || textRaw == "process.stderr")
                    {
                        propValue = _writableStream;
                    }
                    else if (!String.IsNullOrWhiteSpace(textRaw))
                    {
                        int start, end;
                        if ((start = textRaw.IndexOf('{')) != -1 && (end = textRaw.IndexOf('}')) != -1 &&
                            start < end)
                        {
                            string typeName = textRaw.Substring(start, end - start);
                            switch (typeName)
                            {
                            case "Boolean":
                                propValue = value.ProjectEntry.Analyzer._trueInst;
                                break;

                            case "Number":
                                propValue = value.ProjectEntry.Analyzer._zeroIntValue;
                                break;
                            }
                        }
                    }

                    if (propValue == null)
                    {
                        propValue = new BuiltinObjectValue(value.ProjectEntry);
                    }

                    value.Add(
                        new MemberAddInfo(
                            propName,
                            propValue,
                            desc,
                            true
                            )
                        );
                }
            }
        }
 public override FunctionValue Specialize(ProjectEntry projectEntry, string name, string doc, AnalysisValue returnValue, ParameterResult[] parameters)
 {
     return(new ReturningFunctionValue(
                projectEntry,
                name,
                GetReturnValue(projectEntry.Analyzer),
                doc,
                parameters
                ));
 }
Beispiel #15
0
 private BuiltinFunctionValue ReturningFunction(string name, AnalysisValue value, string documentation = null, params ParameterResult[] parameters) {
     return new ReturningFunctionValue(_analyzer._builtinEntry, name, value.Proxy, documentation, parameters);
 }
 public override FunctionValue Specialize(ProjectEntry projectEntry, string name, string doc, AnalysisValue returnValue, ParameterResult[] parameters) {
     return new ReturningFunctionValue(
         projectEntry,
         name,
         GetReturnValue(projectEntry.Analyzer),
         doc,
         parameters
     );
 }
Beispiel #17
0
 private MemberAddInfo BuiltinProperty(string name, AnalysisValue propertyType, string documentation = null) {
     return new MemberAddInfo(name, propertyType, documentation, isProperty: true);
 }
Beispiel #18
0
 public abstract FunctionValue Specialize(ProjectEntry projectEntry, string name, string doc, AnalysisValue returnValue, ParameterResult[] parameters);
Beispiel #19
0
 private BuiltinFunctionValue BooleanFunction(out AnalysisValue booleanPrototype) {
     var builtinEntry = _analyzer._builtinEntry;
     var prototype = new BuiltinObjectValue(builtinEntry) {
             BuiltinFunction("constructor"),
             ReturningFunction("toString", _analyzer._emptyStringValue),
             BuiltinFunction("valueOf"),
     };
     booleanPrototype = prototype;
     return new BuiltinFunctionValue(builtinEntry, "Boolean", null, prototype);
 }
 /// <summary>
 /// Returns an analysis value representative of both this and another
 /// analysis value. This should only be called when
 /// <see cref="UnionEquals"/> returns true for the two values.
 /// </summary>
 /// <param name="av">The value to merge with.</param>
 /// <param name="strength">A value matching that passed to
 /// <see cref="UnionEquals"/>.</param>
 /// <returns>A merged analysis value.</returns>
 /// <remarks>
 /// <para>Calling this function when <see cref="UnionEquals"/> returns
 /// false for the same parameters is undefined.</para>
 /// 
 /// <para>Where there is no analysis value representative of those
 /// provided, it is preferable to return this rather than
 /// <paramref name="av"/>.</para>
 /// 
 /// <para>
 /// <paramref name="strength"/> is used as a key in this function and must
 /// match the value used in <see cref="UnionEquals"/>.
 /// </para>
 /// </remarks>
 internal virtual AnalysisValue UnionMergeTypes(AnalysisValue av, int strength) {
     return this;
 }
 public AnalysisProxy WrapAnalysisValue(AnalysisValue value) {
     var res = new AnalysisProxy(value);
     _proxies.Add(res);
     return res;
 }
 public override FunctionValue Specialize(ProjectEntry projectEntry, string name, string doc, AnalysisValue returnValue, ParameterResult[] parameters)
 {
     return(new SpecializedFunctionValue(
                projectEntry,
                name,
                _delegate,
                doc,
                null,
                parameters
                ));
 }