예제 #1
0
        public JScriptAssertion(string expression, string[] assemblyNames, string[] imports)
        {
            if (string.IsNullOrEmpty(expression) ||
                expression.TrimStart().Length == 0)
            {
                return;
            }

            ProcessDirectives(expression, ref assemblyNames, ref imports);

            var engine = VsaEngine.CreateEngineAndGetGlobalScope(/* fast */ false,
                                                                 assemblyNames ?? new string[0]).engine;

            if (imports != null && imports.Length > 0)
            {
                foreach (var import in imports)
                {
                    Import.JScriptImport(import, engine);
                }
            }

            //
            // We pick on of two expression evaluation strategies depending
            // on the level of trust available. The full trust version is
            // faster as it compiles the expression once into a JScript
            // function and then simply invokes at the time it needs to
            // evaluate the context. The partial trust strategy is slower
            // as it compiles the expression each time an evaluation occurs
            // using the JScript eval.
            //

            _evaluationStrategy = FullTrustEvaluationStrategy.IsApplicable() ? (EvaluationStrategy)
                                  new FullTrustEvaluationStrategy(expression, engine) :
                                  new PartialTrustEvaluationStrategy(expression, engine);
        }
예제 #2
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);
        }