public virtual void SettingAndGettingVariableWithUndefinedValueIsCorrect() { // Arrange const string variableName = "myVar1"; object input = Undefined.Value; // Act _jsEngine.SetVariableValue(variableName, input); bool variableExists = _jsEngine.HasVariable(variableName); var output = _jsEngine.GetVariableValue(variableName); // Assert Assert.IsFalse(variableExists); Assert.AreEqual(input, output); }
public static string GetCondition(List <string> constants, List <int> useConstants, string condition, string className) { GetJsEngineSwitcher(); return(antiDupCache.GetOrAdd(condition, () => { var js = @"var antlr4={}; antlr4.Token={}; antlr4.Token.EOF=-1; var {3}={}; {3}.EOF = antlr4.Token.EOF; {0} var testNums=[{1}]; var result=[]; for(var i=0;i<testNums.length;i++){ var _la=testNums[i]; if({2}){ result.push(_la) } } outResult=result.join(','); "; js = js.Replace("{0}", string.Join("\r\n", constants)); js = js.Replace("{1}", string.Join(",", useConstants)); js = js.Replace("{2}", condition); js = js.Replace("{3}", className); IJsEngine engine = JsEngineSwitcher.Current.CreateEngine(JintJsEngine.EngineName); engine.SetVariableValue("outResult", ""); engine.Evaluate(js); var result = engine.GetVariableValue <string>("outResult"); engine.Dispose(); return result; })); }
public virtual void ArrayForEachMethodIsSupported() { // Arrange const string resultVariableName = "enginesString"; string initCode = string.Format(@"var engines = ['Chakra', 'V8', 'SpiderMonkey', 'Jurassic'], {0} = '' ; engines.forEach(function(value, index, array) {{ if (index > 0) {{ {0} += ';'; }} {0} += value; }});", resultVariableName); const string targetOutput = "Chakra;V8;SpiderMonkey;Jurassic"; // Act _jsEngine.Execute(initCode); var output = _jsEngine.GetVariableValue <string>(resultVariableName); // Assert Assert.AreEqual(targetOutput, output); }
public object GetVariableValue(string variableName) { CheckDisposed(); return(_engine.GetVariableValue(variableName)); }
public override object GetOutObject(string key) { return(js.GetVariableValue(key)); }