private UserFunctionValue CreateUserFunction(FunctionObject node, AnalysisUnit outerUnit) { UserFunctionValue func = null; BaseSpecialization[] specializations; var funcName = node.Name ?? node.NameGuess; if (funcName != null && _specializations.TryGetValue(funcName, out specializations)) { foreach (var specialization in specializations) { if (specialization.IsMatch(node)) { func = new SpecializedUserFunctionValue( specialization.Specialization, node, outerUnit, _scope, specialization.CallBase ); break; } } } if (func == null) { func = new UserFunctionValue(node, outerUnit, _scope, _isNested); } _scope.GlobalEnvironment.AddNodeValue(NodeEnvironmentKind.UserFunctionValue, node, func.Proxy); return(func); }
/// <summary> /// Opens a file, appends the specified string to the file, and then closes the file. If the file does not exist, this method creates a file, writes the specified string to the file, then closes the file. /// </summary> internal static void AppendJson(FunctionObject ctx, ScriptObject instance, BoxedValue path, BoxedValue contents, BoxedValue onComplete, BoxedValue encodingName) { if (!path.IsString) throw new ArgumentException("[appendJson] First parameter should be defined and be a string."); if (!contents.IsStrictlyObject) throw new ArgumentException("[appendJson] Second parameter should be defined and be an object."); if (!onComplete.IsUndefined && !onComplete.IsFunction) throw new ArgumentException("[appendJson] Third parameter should be an onComplete function."); // Get the curent channel var channel = Channel.Current; // Dispatch the task channel.Async(() => { // The encoding to use Encoding encoding = encodingName.IsString ? TextEncoding.GetEncoding(encodingName.String) : null; // Defaults to UTF8 if (encoding == null) encoding = TextEncoding.UTF8; // Unbox the array of lines and execute the append File.AppendAllText( path.Unbox<string>(), Native.Serialize(instance.Env, contents, false).Unbox<string>(), encoding ); // Dispatch the on complete asynchronously channel.DispatchCallback(onComplete, instance); }); }
static void AddHandler( FunctionObject func, CommonObject that, string eventName, FunctionObject handler) { EventObject self = that.CastTo<EventObject>(); self.AddHandler(eventName, handler); }
private Completion EvaluateTypeof(Interpreter interpreter) { var valComp = unaryExpression.Evaluate(interpreter); if (valComp.value is ReferenceValue reference) { if (reference.IsUnresolvableReference()) { return(Completion.NormalCompletion(new StringValue("undefined"))); } } var val = valComp.GetValue(); if (val.IsAbrupt()) { return(val); } return(Completion.NormalCompletion(new StringValue(val.value switch { UndefinedValue _ => "undefined", NullValue _ => "object", BooleanValue _ => "boolean", NumberValue _ => "number", StringValue _ => "string", FunctionObject _ => "function", Object _ => "object", _ => throw new InvalidOperationException("OperatorUnaryExpression.EvaluateTypeof: unknown type"), })));
public static string HttpGet(FunctionObject _, CommonObject that, FunctionObject function) { var self = that.CastTo <HttpObject>(); var wc = new WebClient(); return(wc.DownloadString(self.Url)); }
private void runCommand(FunctionObject func) { if (func.Type == FunctionObject.CommandType.Buy) { if (func.Offset == 0) { this.chromeUtil.BuyPercent(func.AType, func.Amount); } else { this.chromeUtil.CurrentBuyPercent(func.AskType, func.Offset, func.Detail, func.AType, func.Amount); } } else if (func.Type == FunctionObject.CommandType.Sell) { if (func.Offset == 0) { this.chromeUtil.SellPercent(func.AType, func.Amount); } else { this.chromeUtil.CurrentSellPercent(func.AskType, func.Offset, func.Detail, func.AType, func.Amount); } } else if (func.Type == FunctionObject.CommandType.Cancel) { this.chromeUtil.CancelOrder(); } else if (func.Type == FunctionObject.CommandType.Close) { } }
internal static void Dir(FunctionObject func, CommonObject that, object value) { Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Yellow; ObjectDumper.Write(value, 15); Console.ResetColor(); }
public ScriptRunner() { _context = new CSharp.Context(); var file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources/calculate.js"); _context.ExecuteFile(file); _calculate = _context.Globals.GetT<FunctionObject>("calculate"); }
public override void Visit(FunctionObject node) { base.Visit(node); List <BindingInformation> bindings = GetBindings(node); if (bindings != null) { FunctionMapEntry functionMapEntry = new FunctionMapEntry { Bindings = bindings, StartSourcePosition = new SourcePosition { ZeroBasedLineNumber = node.Body.Context.StartLineNumber - 1, // Souce maps work with zero based line and column numbers, the AST works with one based line numbers. We want to use zero-based everywhere. ZeroBasedColumnNumber = node.Body.Context.StartColumn }, EndSourcePosition = new SourcePosition { ZeroBasedLineNumber = node.Body.Context.EndLineNumber - 1, // Souce maps work with zero based line and column numbers, the AST works with one based line numbers. We want to use zero-based everywhere. ZeroBasedColumnNumber = node.Body.Context.EndColumn } }; FunctionMap.Add(functionMapEntry); } }
public void Visit(FunctionObject node) { // if this is an arrow function, then we're good to go. Otherwise // this shouldn't be called for anything but a function expression, // which is definitely NOT safe to start a statement off because it would // then be interpreted as a function *declaration*. m_isSafe = node.IfNotNull(n => n.FunctionType == FunctionType.ArrowFunction); }
public void Visit(FunctionObject node) { // recurse the function binding if (node != null && node.Binding != null) { node.Binding.Accept(this); } }
public override string ToString() { return(String.Format("UserFunction {0} {1}\r\n{2}", FunctionObject.Name, FunctionObject.GetStart(ProjectEntry.Tree.LocationResolver), ProjectEntry.FilePath )); }
public void Evaluate_CanEvaluateFunctionObject() { IObject actual = this.subject.Evaluate("fn(x) { x + 2; }", this.environment); FunctionObject fn = this.AssertAndCast <FunctionObject>(actual); Assert.Equal(1, fn.Parameters.Count); Assert.Equal("x", fn.Parameters[0].StringValue); Assert.Equal("(x + 2)", fn.Body.StringValue); }
public Completion EvaluateBody(FunctionObject functionObject, IReadOnlyList <IValue> arguments) { var comp = functionObject.FunctionDeclarationInstantiation(arguments); if (comp.IsAbrupt()) { return(comp); } return(Evaluate(Interpreter.Instance())); }
public virtual void Visit(FunctionObject node) { if (node != null) { if (node.Body != null) { node.Body.Accept(this); } } }
public override void PostWalk(FunctionObject node) { if (node.Body != null) { Debug.Assert(_scope is DeclarativeEnvironmentRecord && ((DeclarativeEnvironmentRecord)_scope).Node == node); Debug.Assert(!(_scope.Parent is DeclarativeEnvironmentRecord) || ((DeclarativeEnvironmentRecord)_scope.Parent).Node != node); _scope = _scope.Parent; _curUnit = _analysisStack.Pop(); Debug.Assert(_scope.EnumerateTowardsGlobal.Contains(_curUnit.Environment)); } }
LookupExpression GetLookupToFirstParameter(FunctionObject function) { var firstParameter = function.ParameterDeclarations[0] as ParameterDeclaration; var bindingIdentifier = firstParameter.Binding as BindingIdentifier; return(new LookupExpression(function.Body.Context.FlattenToStart()) { Name = bindingIdentifier.Name, VariableField = bindingIdentifier.VariableField }); }
public Enviroment ExtendEnviroment(FunctionObject fn, List <IObject> args) { var enviroment = Enviroment.CreateNewEnclosedEnviroment(fn.Enviroment); for (int i = 0; i < fn.Parameters.Count; i++) { enviroment.Set(fn.Parameters[i].Value, args[i]); } return(enviroment); }
public Completion PropertyDefinitionEvaluation(Object @object, bool enumerable) { var strict = functionBody.IsStrictMode; var scope = Interpreter.Instance().RunningExecutionContext().LexicalEnvironment; var closure = FunctionObject.FunctionCreate(FunctionObject.FunctionCreateKind.Method, new FormalParameters(), functionBody, scope, strict); closure.MakeMethod(@object); closure.SetFunctionName(propertyName, "get"); var desc = new PropertyDescriptor(closure, null, enumerable, true); return(@object.DefinePropertyOrThrow(propertyName, desc)); }
/// <summary> /// Gets the session time. /// </summary> /// <param name="ctx">The function context.</param> /// <param name="instance">The console object instance.</param> /// <param name="eventName">The name of the event.</param> internal static BoxedValue GetConnectedFor(FunctionObject ctx, ScriptObject instance) { // Get the first client var client = Channel.Current.First; if (client == null) return Undefined.Boxed; // Return the address return BoxedValue.Box( client.Channel.ConnectedFor ); }
public void ToString_WhenCalledAndHasValue_CorrectStringIsSet() { //Arrange var function = new Func <double, double>(Math.Sin); var functionObject = new FunctionObject(function); //Act var result = functionObject.ToString(); //Assert Assert.AreEqual(result, "Sin"); }
public void Constructor_WhenCalled_ValueIsSet() { //Arrange var function = new Func <double, double>(Math.Sin); //Act var functionObject = new FunctionObject(function); //Assert Assert.AreEqual(function, functionObject.Value); Assert.AreEqual(GraphObjectType.Function, functionObject.GraphObjectType); Assert.AreEqual("Sin", functionObject.FunctionName); }
/// <summary> /// Initializes a new instance of the <see cref="RequireDefinition"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="resourceHelper">The resource helper.</param> public RequireDefinition(CSharp.Context context, ResourceHelper resourceHelper) { if (context == null) throw new ArgumentNullException("context"); if (resourceHelper == null) throw new ArgumentNullException("resourceHelper"); this.context = context; this.resourceHelper = resourceHelper; this.requireCache = new Dictionary<string, CommonObject>(); this.cacheLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); this.require = Utils.CreateFunction<Func<string, CommonObject>>(this.context.Environment, 1, Require); }
internal static void Log(FunctionObject func, CommonObject that, object value) { Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Yellow; if(value is string) Console.WriteLine(value); else if (value is BoxedValue) { BoxedValue boxedValue = ((BoxedValue)value); Console.WriteLine(TypeConverter.ToString(boxedValue)); } Console.ResetColor(); }
internal FunctionAnalysisUnit AddFunction(FunctionObject node, AnalysisUnit outerUnit, bool isExpression = false) { EnvironmentRecord scope; if (!_scope.GlobalEnvironment.TryGetNodeEnvironment(node, out scope)) { if (node.Body == null) { return(null); } IAnalysisSet functionObj; UserFunctionValue func = null; if (!_scope.GlobalEnvironment.TryGetNodeValue(NodeEnvironmentKind.UserFunctionValue, node, out functionObj)) { func = CreateUserFunction(node, outerUnit); } else { func = (UserFunctionValue)functionObj; } var funcScope = GetFunctionEnvironment(func); scope = funcScope; VariableDef[] parameters = new VariableDef[node.ParameterDeclarations != null ? node.ParameterDeclarations.Length : 0]; for (int i = 0; i < parameters.Length; i++) { parameters[i] = funcScope.AddLocatedVariable( node.ParameterDeclarations[i].Name, node.ParameterDeclarations[i], _curUnit.ProjectEntry ); } _scope.Children.Add(scope); _scope.GlobalEnvironment.AddNodeEnvironment(node, scope); if (!isExpression && node.Name != null) { // lambdas don't have their names published var funcVar = _scope.AddLocatedVariable(node.Name, node, funcScope.AnalysisUnit); funcVar.AddTypes(funcScope.AnalysisUnit, func.SelfSet); } funcScope.AnalysisUnit.Enqueue(); } return(((FunctionEnvironmentRecord)scope).AnalysisUnit); }
/// <summary> /// Gets the name and location information related to the function name binding for a FunctionObject node /// </summary> private IReadOnlyList <BindingInformation> GetBindings(FunctionObject node) { List <BindingInformation> result = new List <BindingInformation>(); // Gets the name of an object property that a function is bound to, like the static method foo in the example "object.foo = function () {}" if (node.Parent is BinaryOperator parentBinaryOperator) { result.AddRange(ExtractBindingsFromBinaryOperator(parentBinaryOperator)); return(result); } // Gets the name of an object property that a function is bound to against the prototype, like the instance method foo in the example "object.prototype = {foo: function () {}}" if (node.Parent is ObjectLiteralProperty parentObjectLiteralProperty) { // See if we can get the name of the object that this method belongs to ObjectLiteral objectLiteralParent = parentObjectLiteralProperty.Parent?.Parent as ObjectLiteral; if (objectLiteralParent != null && objectLiteralParent.Parent is BinaryOperator binaryOperator) { result.AddRange(ExtractBindingsFromBinaryOperator(binaryOperator)); } result.Add( new BindingInformation( name: parentObjectLiteralProperty.Name.Name, sourcePosition: new SourcePosition( zeroBasedLineNumber: parentObjectLiteralProperty.Context.StartLineNumber - 1, zeroBasedColumnNumber: parentObjectLiteralProperty.Context.StartColumn))); return(result); } // Gets the name of a variable that a function is bound to, like foo in the example "var foo = function () {}" BindingIdentifier bindingIdentifier = (node.Parent is VariableDeclaration parentVariableDeclaration) ? parentVariableDeclaration.Binding as BindingIdentifier : node.Binding; // Gets the name bound to the function, like foo in the example "function foo() {} if (bindingIdentifier != null) { result.Add( new BindingInformation( name: bindingIdentifier.Name, sourcePosition: new SourcePosition( zeroBasedLineNumber: bindingIdentifier.Context.StartLineNumber - 1, // Souce maps work with zero based line and column numbers, the AST works with one based line numbers. We want to use zero-based everywhere. zeroBasedColumnNumber: bindingIdentifier.Context.StartColumn))); return(result); } return(null); }
private bool WalkFunction(FunctionObject node, bool isExpression) { var functionAnalysis = AddFunction(node, _curUnit, isExpression); if (functionAnalysis != null) { _analysisStack.Push(_curUnit); _curUnit = functionAnalysis; Debug.Assert(_scope.EnumerateTowardsGlobal.Contains(functionAnalysis.Environment.Parent)); _scope = functionAnalysis.Environment; return(true); } return(false); }
public override void Visit(FunctionObject node) { if (node != null) { // if we are reordering ANYTHING, then we need to do the reordering on a scope level. // so if that's the case, we need to create a list of all the child functions and NOT // recurse at this point. Then we'll reorder, then we'll use the lists to recurse. // BUT if we are not reordering anything, no sense making the lists and recursing later. // if that's the case, we can just recurse now and not have to worry about anything later. if (m_moveVarStatements || m_moveFunctionDecls) { // add the node to the appropriate list: either function expression or function declaration. // assume if it's not a function declaration, it must be an expression since the other types // are not declaration (getter, setter) and we want to treat declarations special. // if the conditional comment level isn't zero, then something funky is going on with // the conditional-compilation statements, and we don't want to move the declarations, so // don't add them to the declaration list. But we still want to recurse them, so add them // to the expression list (which get recursed but not moved). if (node.FunctionType == FunctionType.Declaration && m_conditionalCommentLevel == 0) { if (m_functionDeclarations == null) { m_functionDeclarations = new List <FunctionObject>(); } m_functionDeclarations.Add(node); } else { if (m_functionExpressions == null) { m_functionExpressions = new List <FunctionObject>(); } m_functionExpressions.Add(node); } // BUT DO NOT RECURSE!!!! // we only want the functions and variables in THIS scope, not child function scopes. //base.Visit(node); } else { // we're not reordering, so just recurse now to save the hassle base.Visit(node); } } }
public void GetCompositeFunction_WhenCalledWithNonEmptyList_CorrectFunctionIsReturned() { //Arrange var plotter = new FunctionPlotterViewModel(); var funcObject = new FunctionObject(Math.Sin); var testObject = new VariableObject(); //Act plotter.AddComponent(funcObject); plotter.AddComponent(testObject); var result = plotter.GetCompositeFunction(); //Assert Assert.IsTrue(!string.IsNullOrEmpty(result)); Assert.IsTrue(result == "Sinx"); }
public void GetLast_WhenCalledWithNonEmptyList_CorrectObjectIsReturned() { //Arrange var plotter = new FunctionPlotterViewModel(); var funcObject = new FunctionObject(Math.Sin); var testObject = new VariableObject(); //Act plotter.AddComponent(funcObject); plotter.AddComponent(testObject); var result = plotter.GetLast(); //Assert Assert.IsTrue(result != null); Assert.IsTrue(result == testObject); }
internal ClassObject(BaseScripter scripter, int class_id, int owner_id, ClassKind ck) : base(scripter, class_id, owner_id) { this.PatternMethod = null; this.UnderlyingType = null; this.RType = null; this._namespaceNameIndex = -1; this.MinValueId = 0; this.MaxValueId = 0; this.RangeTypeId = 0; this.IndexTypeId = 0; this.ht = new Hashtable(); this.AncestorIds = new IntegerList(false); this.ImportedType = null; this.Class_Kind = ck; this.PatternMethod = null; }
public void Visit(FunctionObject node) { if (node != null) { // if this is an arrow function with a single statement in the block that isn't a return statement, // then we need to ask the block statement if it requires a separator. if (node.FunctionType == FunctionType.ArrowFunction && node.Body.IfNotNull(b => b.Count == 1 && !(b[0] is ReturnStatement))) { node.Body[0].Accept(this); } else { DoesRequire = false; } } }
public ScriptEngineContext(IResourceManager resourceManager) { var envJs = resourceManager.GetStringFromAssemblyOf<ScriptEngine>("Forseti.Scripting.Scripts.env.js"); _context = Context.enter(); _context.setOptimizationLevel(-1); _scope = _context.initStandardObjects(); Class myJClass = typeof(SystemConsole); Member method = myJClass.getMethod("Print", typeof(string)); Scriptable function = new FunctionObject("print", method, _scope); _scope.put("print", _scope, function); SystemConsole.LoggingEnabled = false; _context.evaluateString(_scope, envJs, "env.js", 1, null); SystemConsole.LoggingEnabled = true; }
void AddGlobalMethodsFromStaticMethodsInType(System.Type type, params string[] methodNames) { MethodInfo[] methods; var query = type.GetMethods(BindingFlags.Public | BindingFlags.Static).Select(m => m); if( methodNames.Length > 0 ) query = query.Where(m => methodNames.Contains(m.Name)); methods = query.ToArray(); Class javaClass = type; foreach (var method in methods) { Member methodMember = javaClass.getMethod(method.Name, GetParametersForMethod(method)); var functionName = method.Name.ToCamelCase(); Scriptable methodFunction = new FunctionObject(functionName, methodMember, _scope); _scope.put(functionName, _scope, methodFunction); } }
public void EnableValidTransitions_WhenCalledWithFunction_CorrectStatesAreEnabled() { //Arrange var uiElements = GetTestComboBox(); var nextState = new FunctionObject(Math.Sin); var automaton = new FiniteStateAutomatonValidator(uiElements); //Act automaton.DoTransition(nextState); var result = automaton.GetUiElements(); //Assert Assert.IsTrue(result[1].IsEnabled == false); Assert.IsTrue(result[2].IsEnabled); //var Assert.IsTrue(result[0].IsEnabled); //rightBracket Assert.IsTrue(result[3].IsEnabled == false); Assert.IsTrue(result[4].IsEnabled == false); }
public UserFunctionValue(FunctionObject node, AnalysisUnit declUnit, EnvironmentRecord declScope, bool isNested = false) : base(declUnit.ProjectEntry, null, node.Name ?? node.NameGuess) { ReturnValue = new VariableDef(); _funcObject = node; _analysisUnit = new FunctionAnalysisUnit(this, declUnit, declScope, ProjectEntry); declUnit.Analyzer.AnalysisValueCreated(typeof(UserFunctionValue)); var argsWalker = new ArgumentsWalker(); FunctionObject.Body.Walk(argsWalker); if (argsWalker.UsesArguments) { Arguments = new ArgumentsValue(this); ArgumentsVariable = new VariableDef(); ArgumentsVariable.AddTypes(_analysisUnit, Arguments.SelfSet); } }
public override void Visit(FunctionObject node) { base.Visit(node); var bindings = GetBindings(node); if (bindings != null) { FunctionMapEntry functionMapEntry = new FunctionMapEntry( bindings: bindings, deminifiedMethodName: SourceMap.GetDeminifiedMethodName(bindings), startSourcePosition: new SourcePosition( zeroBasedLineNumber: node.Body.Context.StartLineNumber - 1, // Souce maps work with zero based line and column numbers, the AST works with one based line numbers. We want to use zero-based everywhere. zeroBasedColumnNumber: node.Body.Context.StartColumn), endSourcePosition: new SourcePosition( zeroBasedLineNumber: node.Body.Context.EndLineNumber - 1, // Souce maps work with zero based line and column numbers, the AST works with one based line numbers. We want to use zero-based everywhere. zeroBasedColumnNumber: node.Body.Context.EndColumn)); FunctionMap.Add(functionMapEntry); } }
private void KeyHandler(KeyMessage obj) { CommandObject cmd = this.core.SaveData.commandList[obj.CmdIndex]; FunctionObject func = this.core.findFunction(cmd.Command); if (func == null || string.IsNullOrEmpty(func.Name)) { updateStatus("선택된 명령이 없습니다."); } else { try { this.runCommand(func); updateStatus(cmd.Command + " 실행."); } catch (Exception e) { updateStatus(cmd.Command + " 실행 실패."); } } }
public Delegate CreateDelegate(object instance, EventInfo event_info, FunctionObject f, object script_delegate) { Type eventHandlerType = event_info.EventHandlerType; string name = event_info.Name; for (int i = 0; i < this.registered_event_handlers.Count; i++) { EventRec rec = this.registered_event_handlers[i] as EventRec; Delegate hostDelegate = rec.HostDelegate; if ((eventHandlerType == rec.EventHandlerType) && (name == rec.EventName)) { EventRec rec2 = new EventRec(); rec2.Sender = instance; rec2.EventHandlerType = eventHandlerType; rec2.ScriptDelegate = script_delegate; rec2.HostDelegate = hostDelegate; rec2.EventName = name; this.event_rec_list.Add(rec2); return hostDelegate; } } return null; }
private CompletionOr <(string Key, FunctionObject Closure)> DefineMethod(Object @object, IValue?functionPrototype = null) { var strict = functionBody.IsStrictMode; var scope = Interpreter.Instance().RunningExecutionContext().LexicalEnvironment; FunctionObject.FunctionCreateKind kind; IValue prototype; if (functionPrototype != null) { kind = FunctionObject.FunctionCreateKind.Normal; prototype = functionPrototype; } else { kind = FunctionObject.FunctionCreateKind.Method; prototype = Interpreter.Instance().CurrentRealm().Intrinsics.FunctionPrototype; } var closure = FunctionObject.FunctionCreate(kind, formalParameters, functionBody, scope, strict, prototype); closure.MakeMethod(@object); return(Completion.NormalWithStruct((propertyName, closure))); }
public override bool Walk(FunctionObject node) { IAnalysisSet value; EnvironmentRecord record; if (_scope.GlobalEnvironment.TryGetNodeEnvironment(node, out record) && _scope.GlobalEnvironment.TryGetNodeValue(NodeEnvironmentKind.UserFunctionValue, node, out value) && node.Name != null) { if (node.IsExpression) { // Only assign if the variable wasn't defined explicitly in the // functions scope. var varDef = record.GetVariable(node.Name); if (varDef != null && varDef is LocatedVariableDef && ((LocatedVariableDef)varDef).Node == node) { varDef.AddTypes( _projectEntry, value, false ); } } else { Debug.Assert(record.Parent.ContainsVariable(node.Name)); record.Parent.GetVariable(node.Name).AddTypes( _projectEntry, value, false ); } } return(true); }
public static void Run(FunctionObject _, CommonObject that, BoxedValue obj) { var configObj = that.CastTo<ConfigJsObject>(); configObj.configBase.Run(new JavaScriptApp(obj.Object)); }
static CommonObject NewEditor(FunctionObject func, CommonObject that) { var self = that.CastTo<EditorProviderObject>(); IEditor editor = self.provider.NewEditor(); return new EditorObject(func.Env, self.editorPrototype, editor); }
/// <summary> /// Displays an interactive listing of the properties of a specified JavaScript object. This /// listing lets you use disclosure triangles to examine the contents of child objects. /// </summary> /// <param name="ctx">The function context.</param> /// <param name="instance">The console object instance.</param> /// <param name="eventName">The name of the event.</param> /// <param name="eventValue">The value of the event.</param> internal static void Dir(FunctionObject ctx, ScriptObject instance, BoxedValue eventValue) { ConsoleObject.SendEvent("dir", eventValue); }
/// <summary> /// Creates a new inline group, indenting all following output by another level; unlike group(), /// this starts with the inline group collapsed, requiring the use of a disclosure button to /// expand it. To move back out a level, call groupEnd() /// </summary> /// <param name="ctx">The function context.</param> /// <param name="instance">The console object instance.</param> /// <param name="eventName">The name of the event.</param> /// <param name="eventValue">The value of the event.</param> internal static void GroupCollapsed(FunctionObject ctx, ScriptObject instance, BoxedValue eventValue) { ConsoleObject.SendEvent("groupCollapsed", eventValue); }
static CommonObject ConstructHttp(FunctionObject ctor, CommonObject _, string x) { var prototype = ctor.GetT<CommonObject>("prototype"); return new HttpObject(x, ctor.Env, prototype); }
private void FindApplicableMethodList(int name_index, IntegerList a, IntegerList param_mod, int res_id, ref FunctionObject best, ref IntegerList applicable_list, bool upcase) { string upcaseNameByNameIndex = base.Scripter.GetUpcaseNameByNameIndex(name_index); for (int i = 0; i < base.Members.Count; i++) { MemberObject obj2 = base.Members[i]; if (obj2.Kind == MemberKind.Method) { bool flag; if (upcase) { flag = upcaseNameByNameIndex == obj2.UpcaseName; } else { flag = obj2.NameIndex == name_index; } if (flag) { FunctionObject f = (FunctionObject)obj2; this.AddApplicableMethod(f, a, param_mod, res_id, ref best, ref applicable_list); } } } ClassObject ancestorClass = this.AncestorClass; if (!base.Imported) { if (ancestorClass != null) { ancestorClass.FindApplicableMethodList(name_index, a, param_mod, res_id, ref best, ref applicable_list, upcase); } } else { string str2 = base.Scripter.names[name_index]; IntegerList list = new IntegerList(false); foreach (MethodInfo info in this.ImportedType.GetMethods()) { if (str2 == info.Name) { bool flag2 = true; foreach (Attribute attribute in Attribute.GetCustomAttributes(info)) { if (attribute is CSLite_ScriptForbid) { flag2 = false; } } if (flag2) { int avalue = base.Scripter.symbol_table.RegisterMethod(info, base.Id); list.Add(avalue); } } } if (base.Scripter.SearchProtected) { foreach (MethodInfo info2 in this.ImportedType.GetMethods(base.Scripter.protected_binding_flags)) { if (str2 == info2.Name) { bool flag3 = true; foreach (Attribute attribute2 in Attribute.GetCustomAttributes(info2)) { if (attribute2 is CSLite_ScriptForbid) { flag3 = false; } } if (flag3) { int num3 = base.Scripter.symbol_table.RegisterMethod(info2, base.Id); list.Add(num3); } } } } for (int j = 0; j < list.Count; j++) { FunctionObject functionObject = base.Scripter.GetFunctionObject(list[j]); this.AddApplicableMethod(functionObject, a, param_mod, res_id, ref best, ref applicable_list); } if (ancestorClass != null) { ancestorClass.FindApplicableMethodList(name_index, a, param_mod, res_id, ref best, ref applicable_list, upcase); } for (int k = 0; k < this.AncestorIds.Count; k++) { ClassObject classObject = base.Scripter.GetClassObject(this.AncestorIds[k]); if (classObject.IsInterface) { classObject.FindApplicableMethodList(name_index, a, param_mod, res_id, ref best, ref applicable_list, upcase); } } } }
public static Action<Builder> MapBuilder(FunctionObject func) { return builder => func.Call(func.Env.NewObject(), new BuilderJsObject(func.Env, builder)); }
public static void Use(FunctionObject _, CommonObject that, CommonObject obj) { var configObj = that.CastTo<ConfigJsObject>(); configObj.configBase.Use(typeof(JavaScriptApp), obj); }
private void FindApplicableConstructorList(IntegerList a, IntegerList param_mod, ref FunctionObject best, ref IntegerList applicable_list) { for (int i = 0; i < base.Members.Count; i++) { MemberObject obj2 = base.Members[i]; if ((obj2.Kind == MemberKind.Constructor) && !obj2.HasModifier(Modifier.Static)) { FunctionObject f = (FunctionObject)obj2; this.AddApplicableMethod(f, a, param_mod, 0, ref best, ref applicable_list); } } ClassObject ancestorClass = this.AncestorClass; if (!base.Imported) { if ((ancestorClass != null) && (best == null)) { ancestorClass.FindApplicableConstructorList(a, param_mod, ref best, ref applicable_list); } } else { IntegerList list = new IntegerList(false); foreach (ConstructorInfo info in this.ImportedType.GetConstructors()) { list.Add(base.Scripter.symbol_table.RegisterConstructor(info, base.Id)); } if (base.Scripter.SearchProtected) { foreach (ConstructorInfo info2 in this.ImportedType.GetConstructors(base.Scripter.protected_binding_flags)) { list.Add(base.Scripter.symbol_table.RegisterConstructor(info2, base.Id)); } } for (int j = 0; j < list.Count; j++) { FunctionObject functionObject = base.Scripter.GetFunctionObject(list[j]); this.AddApplicableMethod(functionObject, a, param_mod, 0, ref best, ref applicable_list); } if ((ancestorClass != null) && (best == null)) { ancestorClass.FindApplicableConstructorList(a, param_mod, ref best, ref applicable_list); } } }
static CommonObject Construct(FunctionObject ctor, CommonObject that) { return new EventObject(ctor.Env, ctor.GetT<CommonObject>("prototype")); }
/// <summary> /// Gets the hash code reference of the channel. /// </summary> /// <param name="ctx">The function context.</param> /// <param name="instance">The console object instance.</param> /// <param name="eventName">The name of the event.</param> internal static BoxedValue GetHashCode(FunctionObject ctx, ScriptObject instance) { // Return the address return BoxedValue.Box( Channel.Current.GetHashCode() ); }
public static void Map(FunctionObject _, CommonObject that, string str, BoxedValue func) { var configObj = that.CastTo<ConfigJsObject>(); configObj.configBase.Map(str, BuilderJsObject.MapBuilder(func.Func)); }
static void Trigger( FunctionObject func, CommonObject that, string eventName, BoxedValue data) { EventObject self = that.CastTo<EventObject>(); self.Trigger(eventName, data); }
static CommonObject Construct(FunctionObject ctor, CommonObject _, double x) { var prototype = ctor.GetT<CommonObject>("prototype"); return new RobotObject(ctor.Env, prototype); }
/// <summary> /// Exits the current inline group. /// </summary> /// <param name="ctx">The function context.</param> /// <param name="instance">The console object instance.</param> /// <param name="eventName">The name of the event.</param> /// <param name="eventValue">The value of the event.</param> internal static void GroupEnd(FunctionObject ctx, ScriptObject instance) { ConsoleObject.SendEvent("groupEnd", Undefined.Boxed); }
/// <summary> /// Stops the specified timer and logs the elapsed time in seconds since its start. /// </summary> /// <param name="ctx">The function context.</param> /// <param name="instance">The console object instance.</param> /// <param name="eventName">The name of the event.</param> /// <param name="eventValue">The value of the event.</param> internal static void TimeEnd(FunctionObject ctx, ScriptObject instance, BoxedValue eventValue) { ConsoleObject.SendEvent("timeEnd", eventValue); }
private static CommonObject Construct(FunctionObject ctor, CommonObject _) { CommonObject prototype = ctor.GetT<CommonObject>("prototype"); return new CommonObject(ctor.Env, prototype); }
bool RemoveHandler(string eventName, FunctionObject handler) { List<FunctionObject> handlers; if (events.TryGetValue(eventName, out handlers)) return handlers.Remove(handler); return false; }
void AddHandler(string eventName, FunctionObject handler) { List<FunctionObject> handlers; if (!events.TryGetValue(eventName, out handlers)) handlers = events[eventName] = new List<FunctionObject>(); handlers.Add(handler); }