// Build a function declaration closure.
	public static Closure JScriptFunctionDeclaration
				(RuntimeTypeHandle handle, String name, String method_name,
				 String[] formal_parameters, JSLocalField[] fields,
				 bool must_save_stack_locals, bool hasArgumentsObject,
				 String text, Object declaringObject, VsaEngine engine)
			{
				// TODO
				return null;
			}
示例#2
0
        public static object JScriptEvaluate(object source, object unsafeOption, VsaEngine engine)
        {
            if (Microsoft.JScript.Convert.GetTypeCode(source) != TypeCode.String)
            {
                return(source);
            }
            bool isUnsafe = false;

            if ((Microsoft.JScript.Convert.GetTypeCode(unsafeOption) == TypeCode.String) && (((IConvertible)unsafeOption).ToString() == "unsafe"))
            {
                isUnsafe = true;
            }
            return(DoEvaluate(source, engine, isUnsafe));
        }
示例#3
0
 internal DocumentContext(string name, VsaEngine engine)
 {
     this.documentName      = name;
     this.documentWriter    = null;
     this.startLine         = 0;
     this.startCol          = 0;
     this.lastLineInSource  = 0;
     this.sourceItem        = null;
     this.engine            = engine;
     this.debugOn           = (engine != null) && engine.GenerateDebugInfo;
     this._compilerGlobals  = null;
     this.reportedVariables = null;
     this.checkForFirst     = false;
 }
示例#4
0
文件: VsaItems.cs 项目: ForNeVeR/pnet
 // Close this item list.
 public virtual void Close()
 {
     lock (this)
     {
         CheckForClosed();
         foreach (VsaItem item in itemList)
         {
             item.Close();
         }
         isClosed = true;
         itemList = null;
         engine   = null;
     }
 }
示例#5
0
        public static object EvalJScript(string JScript)
        {
            object Result = null;

            try
            {
                Result = Microsoft.JScript.Eval.JScriptEvaluate(JScript, VsaEngine.CreateEngine());
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            return(Result);
        }
示例#6
0
        // Perform a constructor call on this object.
        internal virtual Object Construct(VsaEngine engine, Object[] args)
        {
            JSObject obj    = new JSObject(GetPrototypeForConstructedObject());
            Object   result = Call(engine, obj, args);

            if (result is ScriptObject)
            {
                return(result);
            }
            else
            {
                return(obj);
            }
        }
示例#7
0
        static javascript()
        {
#if USEVSAHOST
            Engine = Evaluator.Evaluator.Engine;
#else
            List <string> assemblies        = new List <string>(DefaultAssemblyReferences);
            Assembly      executingAssembly = Assembly.GetExecutingAssembly();
            foreach (var name in executingAssembly.GetReferencedAssemblies())
            {
                string codeBase = name.CodeBase;
                try
                {
                    Assembly assembly = Assembly.Load(name);

                    if (assembly.GlobalAssemblyCache)
                    {
                        codeBase = Path.GetFileName(assembly.Location);
                    }
                    else
                    {
                        codeBase = assembly.Location;
                    }
                }
                catch (ChatSignal ex)
                {
                    throw;
                }
                catch (Exception)
                {
                }
                if (codeBase == null)
                {
                    codeBase = name.Name + ".dll";
                }
                if (!assemblies.Contains(codeBase))
                {
                    assemblies.Add(codeBase);
                }
            }
            var GS = VsaEngine.CreateEngineAndGetGlobalScope(true, assemblies.ToArray());
            Engine = GS.engine;
#endif
            foreach (string reference in DefaultNamespaceReferences)
            {
                Import.JScriptImport(reference, Engine);
            }
            object o = Eval.JScriptEvaluate("this", Engine);
            writeDebugLine("JSciptThis = " + o);
        }
示例#8
0
        internal void PrintBanner(VsaEngine engine, TextWriter output)
        {
            string jsVersion = BuildVersionInfo.MajorVersion
                               + "." + BuildVersionInfo.MinorVersion.ToString().PadLeft(2, '0')
                               + "." + BuildVersionInfo.Build.ToString().PadLeft(4, '0');
            Version version        = System.Environment.Version;
            string  runtimeVersion = version.Major
                                     + "." + version.Minor.ToString().PadLeft(2, '0')
                                     + "." + version.Build.ToString().PadLeft(4, '0');
            string banner = JScriptException.Localize("Banner line 1", engine.ErrorCultureInfo);

            output.WriteLine(String.Format(JScriptException.Localize("Banner line 1", engine.ErrorCultureInfo), jsVersion));
            output.WriteLine(String.Format(JScriptException.Localize("Banner line 2", engine.ErrorCultureInfo), runtimeVersion));
            output.WriteLine(JScriptException.Localize("Banner line 3", engine.ErrorCultureInfo) + Environment.NewLine);
        }
示例#9
0
        // Initialize this object, after all dependencies have been created.
        internal virtual void Init(VsaEngine engine, ScriptObject parent)
        {
            // Set the prototype and engine.
            this.parent = parent;
            this.engine = engine;
            InitPrototype(parent);

            // Add the builtin "Function" properties to the prototype.
            EngineInstance inst = EngineInstance.GetEngineInstance(engine);

            Put("constructor", inst.GetFunctionConstructor());
            AddBuiltin(inst, "apply");
            AddBuiltin(inst, "call");
            AddBuiltin(inst, "toString");
        }
示例#10
0
        private string EvalExpression(string expression)
        {
            VsaEngine engine = VsaEngine.CreateEngine();

            try
            {
                object o = Eval.JScriptEvaluate(expression, engine);
                return(System.Convert.ToDouble(o).ToString());
            }
            catch
            {
                return("No se puede evaluar la expresión");
            }
            engine.Close();
        }
示例#11
0
        public static Object JScriptExceptionValue(object e, VsaEngine engine)
        {
            Exception exc     = e as Exception;
            string    message = null;

            if (exc != null)
            {
                message = exc.Message;
            }
            else
            {
                message = String.Format("Unknown exception of type {0}", exc.GetType());
            }
            return(new ErrorObject(message));
        }
        internal virtual ArrayObject toArray(VsaEngine engine)
        {
            IList       aList  = this.array;
            ArrayObject result = engine.GetOriginalArrayConstructor().Construct();
            uint        i      = 0;
            int         n      = aList.Count;
            IEnumerator e      = aList.GetEnumerator();

            result.length = n;
            while (e.MoveNext())
            {
                result.SetValueAtIndex(i++, e.Current);
            }
            return(result);
        }
示例#13
0
 // Perform a constructor call on this object.
 internal override Object Construct(VsaEngine engine, Object[] args)
 {
     if (args.Length == 0)
     {
         return(ConstructNewObject(engine));
     }
     else if (args[0] == null || args[0] == DBNull.Value)
     {
         return(ConstructNewObject(engine));
     }
     else
     {
         return(Convert.ToObject(args[0], engine));
     }
 }
        internal virtual ArrayObject toArray(VsaEngine engine)
        {
            IList       array      = this.array;
            ArrayObject obj2       = engine.GetOriginalArrayConstructor().Construct();
            uint        num        = 0;
            int         count      = array.Count;
            IEnumerator enumerator = array.GetEnumerator();

            obj2.length = count;
            while (enumerator.MoveNext())
            {
                obj2.SetValueAtIndex(num++, enumerator.Current);
            }
            return(obj2);
        }
示例#15
0
        public static ArrayObject EvalJScript(string JScript)
        {
            VsaEngine   Engine = VsaEngine.CreateEngine();
            ArrayObject Result = null;

            try
            {
                Result = Microsoft.JScript.Eval.JScriptEvaluate(JScript, Engine) as ArrayObject;
            }
            catch (Exception ex)
            {
                return(null);
            }
            return(Result);
        }
示例#16
0
        private static decimal EvaluateNumericExpression(string istrExpresion)
        {
            VsaEngine engine = VsaEngine.CreateEngine();

            try
            {
                object resultado = Eval.JScriptEvaluate(istrExpresion, engine);
                return(System.Convert.ToDecimal(resultado));
            }
            catch
            {
                return(0);
            }
            engine.Close();
        }
示例#17
0
 // Perform a constructor call on this object.
 internal override Object Construct(VsaEngine engine, Object[] args)
 {
     if (args.Length == 0)
     {
         return(new NumberObject
                    (EngineInstance.GetEngineInstance(engine)
                    .GetNumberPrototype(), 0));
     }
     else
     {
         return(new NumberObject
                    (EngineInstance.GetEngineInstance(engine)
                    .GetNumberPrototype(), args[0]));
     }
 }
        public static Closure JScriptFunctionDeclaration(RuntimeTypeHandle handle, string name,
                                                         string methodName, string [] formalParameters,
                                                         JSLocalField [] fields, bool mustSaveStackLocals,
                                                         bool hasArgumentsObjects, string text,
                                                         Object declaringObject, VsaEngine engine)
        {
            FunctionObject f = new FunctionObject(name, null, null, null, null);

            f.source = text;
            MethodInfo method = engine.ScriptObjectStackTop().GetType().GetMethod(methodName);

            f.method     = method;
            f.vsa_engine = engine;
            return(new Closure(f));
        }
示例#19
0
 public string getUrl(string guid)
 {
     try
     {
         string    txt       = GlobalClass.LoadTextFile("getUrl.js", string.Format("jscript\\{0}\\", gc.ForWeb));
         string    allscript = string.Format("{0};getUrl('{1}');", txt, guid);
         VsaEngine Engine    = VsaEngine.CreateEngine();
         object    value     = Eval.JScriptEvaluate(allscript, Engine);
         return(value?.ToString());
     }
     catch (Exception ce)
     {
         return(null);
     }
 }
示例#20
0
        public static object CallValue(object thisObj, object val, object [] arguments,
                                       bool construct, bool brackets, VsaEngine engine)
        {
            if (construct)
            {
                if (brackets)
                {
                }

                if (val is Closure)
                {
                    return(((Closure)val).func.CreateInstance(arguments));
                }
                else if (val is FunctionObject)
                {
                    return(((FunctionObject)val).CreateInstance(arguments));
                }
            }
            else if (brackets)
            {
                object first_arg = arguments.Length > 0 ? arguments [0] : null;
                return(GetObjectProperty((ScriptObject)Convert.ToObject(val, engine), Convert.ToString(first_arg)));
            }
            else
            {
                if (val is Closure)
                {
                    return(((Closure)val).func.Invoke(thisObj, arguments));
                }
                else if (val is FunctionObject)
                {
                    return(((FunctionObject)val).Invoke(thisObj, arguments));
                }
                else if (val is RegExpObject)
                {
                    object first_arg = arguments.Length > 0 ? arguments [0] : null;
                    return(RegExpPrototype.exec(val, first_arg));
                }
                else
                {
                    return(null);
                }
            }

            Console.WriteLine("CallValue: construct = {0}, brackets = {1}, this = {2}, val = {3} ({4}), arg[0] = {5}",
                              construct, brackets, thisObj.GetType(), val, val.GetType(), arguments [0]);
            throw new NotImplementedException();
        }
示例#21
0
文件: globals.cs 项目: ydunk/masters
        [ContextStatic] public static VsaEngine contextEngine = null; //This keeps track of the (single) engine running in the current context

        internal Globals(bool fast, VsaEngine engine)
        {
            this.engine           = engine;
            this.callContextStack = null;
            this.scopeStack       = null;
            this.caller           = DBNull.Value;
            this.regExpTable      = null;
            if (fast)
            {
                this.globalObject = GlobalObject.commonInstance;
            }
            else
            {
                this.globalObject = new LenientGlobalObject(engine);
            }
        }
示例#22
0
        // Initialize this object, after all dependencies have been created.
        internal virtual void Init(VsaEngine engine)
        {
            // Set the engine.
            this.engine = engine;

            // Add the builtin "Object" properties to the prototype.
            EngineInstance inst = EngineInstance.GetEngineInstance(engine);

            Put("constructor", inst.GetObjectConstructor());
            AddBuiltin(inst, "toString");
            AddBuiltin(inst, "toLocaleString");
            AddBuiltin(inst, "valueOf");
            AddBuiltin(inst, "hasOwnProperty");
            AddBuiltin(inst, "isPrototypeOf");
            AddBuiltin(inst, "propertyIsEnumerable");
        }
示例#23
0
 // Perform a constructor call on this object.
 internal override Object Construct(VsaEngine engine, Object[] args)
 {
     if (args.Length == 0)
     {
         return(new StringObject
                    (EngineInstance.GetEngineInstance(engine)
                    .GetStringPrototype(), String.Empty));
     }
     else
     {
         return(new StringObject
                    (EngineInstance.GetEngineInstance(engine)
                    .GetStringPrototype(),
                    Convert.ToString(args[0])));
     }
 }
示例#24
0
        // Initialize this object, after all dependencies have been created.
        internal void Init(VsaEngine engine, ScriptObject parent)
        {
            // Set the prototype and engine.
            this.parent = parent;
            this.engine = engine;

            // Set the "prototype" property value.
            ScriptObject prototype =
                EngineInstance.GetEngineInstance(engine)
                .GetObjectPrototype();

            Put("prototype", prototype,
                PropertyAttributes.ReadOnly |
                PropertyAttributes.DontEnum |
                PropertyAttributes.DontDelete);
        }
示例#25
0
        // Validate an item name.
        internal static void ValidateName(VsaEngine engine, String name)
        {
            // Validate the name with the engine.
            if (!engine.IsValidIdentifier(name))
            {
                throw new VsaException(VsaError.ItemNameInvalid);
            }

            // Make sure that there are no items with this name.
            foreach (VsaItem item in engine.Items)
            {
                if (item.Name == name)
                {
                    throw new VsaException(VsaError.ItemNameInUse);
                }
            }
        }
示例#26
0
        public static Object JScriptEvaluate(Object source, Object unsafeOption, VsaEngine engine)
        {
            if (Convert.GetTypeCode(source) != TypeCode.String)
            {
                return(source);
            }
            bool isUnsafe = false;

            if (Convert.GetTypeCode(unsafeOption) == TypeCode.String)
            {
                if (((IConvertible)unsafeOption).ToString() == "unsafe")
                {
                    isUnsafe = true;
                }
            }
            return(Eval.DoEvaluate(source, engine, isUnsafe));
        }
示例#27
0
        public static int search(object thisObj, VsaEngine engine, object regExp)
        {
            string       string_obj = Convert.ToString(thisObj);
            RegExpObject regex_obj  = Convert.ToRegExp(regExp);
            Match        md         = regex_obj.regex.Match(string_obj);

            /* Note: Microsoft's implementation updates the lastIndex property of regex_obj here, but
             * ECMA-262, 15.5.4.12, NOTE 1 explicitely says not to do so. We do the ECMA-262 behavior. */
            if (md.Success)
            {
                return(md.Index);
            }
            else
            {
                return(-1);
            }
        }
示例#28
0
        public void OnItemFlagNotSupported()
        {
            VsaEngine engine = new VsaEngine();
            IVsaItems items;
            IVsaItem  item;

            engine             = new VsaEngine();
            engine.RootMoniker = "com.foo://path/to/nowhere";
            engine.Site        = new Site();

            engine.InitNew();
            items = engine.Items;

            try {
                item = items.CreateItem("item1",
                                        VsaItemType.Reference,
                                        VsaItemFlag.Class);
            } catch (VsaException e) {
                Assert.AreEqual(VsaError.ItemFlagNotSupported, e.ErrorCode, "#8");
            }

            try {
                item = items.CreateItem("item2",
                                        VsaItemType.Reference,
                                        VsaItemFlag.Module);
            } catch (VsaException e) {
                Assert.AreEqual(VsaError.ItemFlagNotSupported, e.ErrorCode, "#9");
            }

            try {
                item = items.CreateItem("item3",
                                        VsaItemType.AppGlobal,
                                        VsaItemFlag.Class);
            } catch (VsaException e) {
                Assert.AreEqual(VsaError.ItemFlagNotSupported, e.ErrorCode, "#10");
            }

            try {
                item = items.CreateItem("item4",
                                        VsaItemType.AppGlobal,
                                        VsaItemFlag.Module);
            } catch (VsaException e) {
                Assert.AreEqual(VsaError.ItemFlagNotSupported, e.ErrorCode, "#11");
            }
        }
示例#29
0
        public string GetErrorMessageForHR(int hr, IJSVsaEngine engine)
        {
            CultureInfo culture = null;
            VsaEngine   engine2 = engine as VsaEngine;

            if (engine2 != null)
            {
                culture = engine2.ErrorCultureInfo;
            }
            if (((hr & 0xffff0000L) == 0x800a0000L) && Enum.IsDefined(typeof(JSError), hr & 0xffff))
            {
                int num = hr & 0xffff;
                return(JScriptException.Localize(num.ToString(CultureInfo.InvariantCulture), culture));
            }
            int num2 = 0x177b;

            return(JScriptException.Localize(num2.ToString(CultureInfo.InvariantCulture), "0x" + hr.ToString("X", CultureInfo.InvariantCulture), culture));
        }
示例#30
0
        public void OnItemNotFound()
        {
            VsaEngine engine = new VsaEngine();
            IVsaItems items;
            IVsaItem  item;

            engine             = new VsaEngine();
            engine.RootMoniker = "com.foo://path/to/nowhere";
            engine.Site        = new Site();

            engine.InitNew();
            items = engine.Items;

            try {
                item = items [-1];
            } catch (VsaException e) {
                Assert.AreEqual(VsaError.ItemNotFound, e.ErrorCode, "#3");
            }


            try {
                item = items [20];
            } catch (VsaException e) {
                Assert.AreEqual(VsaError.ItemNotFound, e.ErrorCode, "#4");
            }

            try {
                item = items ["IamNotHere"];
            } catch (VsaException e) {
                Assert.AreEqual(VsaError.ItemNotFound, e.ErrorCode, "#5");
            }

            try {
                items.Remove(20);
            } catch (VsaException e) {
                Assert.AreEqual(VsaError.ItemNotFound, e.ErrorCode, "#6");
            }

            try {
                items.Remove(-1);
            } catch (VsaException e) {
                Assert.AreEqual(VsaError.ItemNotFound, e.ErrorCode, "#7");
            }
        }
示例#31
0
        private static ArrayObject SplitWithRegExp(String thisob, VsaEngine engine, RegExpObject regExpObject, uint limit)
        {
            ArrayObject array = (ArrayObject)engine.GetOriginalArrayConstructor().Construct();
            Match       match = regExpObject.regex.Match(thisob);

            if (!match.Success)
            {
                array.SetValueAtIndex(0, thisob);
                regExpObject.lastIndexInt = 0;
                return(array);
            }


            Match lastMatch;
            int   prevIndex = 0;
            uint  i         = 0;

            do
            {
                int len = match.Index - prevIndex;
                if (len > 0)
                {
                    array.SetValueAtIndex(i++, thisob.Substring(prevIndex, len));
                    if (limit > 0 && i >= limit)
                    {
                        regExpObject.lastIndexInt = regExpObject.regExpConst.UpdateConstructor(regExpObject.regex, match, thisob);
                        return(array);
                    }
                }


                prevIndex = match.Index + match.Length;
                lastMatch = match;
                match     = match.NextMatch();
            }while(match.Success);

            if (prevIndex < thisob.Length)
            {
                array.SetValueAtIndex(i, thisob.Substring(prevIndex));
            }
            regExpObject.lastIndexInt = regExpObject.regExpConst.UpdateConstructor(regExpObject.regex, lastMatch, thisob);

            return(array);
        }