Esempio n. 1
0
        public JsAnalyzer(AnalysisLimits limits = null)
        {
            _modules      = new ModuleTable();
            _itemCache    = new Dictionary <object, AnalysisValue>();
            _builtinEntry = new ProjectEntry(this, String.Empty, null);

            Limits = limits ?? new AnalysisLimits();

            _queue = new Deque <AnalysisUnit>();

            _nullInst  = new NullValue(this);
            _trueInst  = new BooleanValue(true, this);
            _falseInst = new BooleanValue(false, this);
            _undefined = new UndefinedValue(this);

            _emptyStringValue = GetConstant(String.Empty);
            _zeroIntValue     = GetConstant(0.0);

            var globals = GlobalBuilder.MakeGlobal(this);

            _globalObject      = globals.GlobalObject;
            _numberPrototype   = globals.NumberPrototype;
            _stringPrototype   = globals.StringPrototype;
            _booleanPrototype  = globals.BooleanPrototype;
            _functionPrototype = globals.FunctionPrototype;
            _arrayFunction     = globals.ArrayFunction;
            _objectPrototype   = globals.ObjectPrototype;
            _requireFunc       = globals.RequireFunction;
            _arrayPrototype    = globals.ArrayPrototype;
            _objectGetOwnPropertyDescriptor = globals.ObjectGetOwnPropertyDescriptor;
            _immutableObject = new ImmutableObjectValue(_builtinEntry);

            var allJson = Path.Combine(
                Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                "all.json"
                );


            if (File.Exists(allJson))
            {
                NodejsModuleBuilder.Build(allJson, this);
            }
            else
            {
                Debug.Fail("Could not find all.json");
            }
        }
Esempio n. 2
0
        private void GenerateMethod(ExpandoValue exports, Dictionary <string, FunctionSpecializer> specialMethods, dynamic method)
        {
            string methodName = (string)method["name"];

            ObjectValue returnValue = null;

            if (methodName.StartsWith("create") && methodName.Length > 6)
            {
                string klassName = methodName.Substring(6);
                PropertyDescriptorValue propDesc;
                if (exports.Descriptors.TryGetValue(klassName, out propDesc) && propDesc.Values != null)
                {
                    var types = propDesc.Values.Types;
                    if (types != null && types.Count == 1)
                    {
                        var type = types.First().Value;
                        if (type is FunctionValue)
                        {
                            returnValue = ((FunctionValue)type)._instance;
                        }
                    }
                }
            }

            foreach (var sig in method["signatures"])
            {
                BuiltinFunctionValue function;
                FunctionSpecializer  specialMethod;
                if (specialMethods != null &&
                    specialMethods.TryGetValue(methodName, out specialMethod))
                {
                    function = specialMethod.Specialize(
                        exports.ProjectEntry,
                        methodName,
                        ParseDocumentation((string)method["desc"]),
                        returnValue,
                        GetParameters(sig["params"])
                        );
                }
                else if (returnValue != null)
                {
                    function = new ReturningFunctionValue(
                        exports.ProjectEntry,
                        methodName,
                        returnValue.SelfSet,
                        ParseDocumentation((string)method["desc"]),
                        GetParameters(sig["params"])
                        );
                }
                else
                {
                    function = new BuiltinFunctionValue(
                        exports.ProjectEntry,
                        methodName,
                        ParseDocumentation((string)method["desc"]),
                        null,
                        GetParameters(sig["params"])
                        );
                }

                exports.Add(function);
            }
        }
 private BuiltinFunctionExpression()
 {
     functionValue = new BuiltinFunctionValue(this);
 }