/// <summary> /// Declares a function with the specified a name. /// </summary> /// <param name="context">The runtime context.</param> /// <param name="name">The function name.</param> /// <param name="value">The function object.</param> /// <exception cref="InvalidOperationException">The function has not been declared in hoisting. <see cref="HoistingDecalreFunction"/> should be called first.</exception> protected virtual void DecalreFunction(RuntimeContext context, string name, IFunctionObject value) { if (this.Functions.ContainsKey(name)) { this.Functions[name] = value; } else { throw new InvalidOperationException( string.Format(ExceptionResource.Undefined, name)); } }
private ExecuteResult ExecuteStatement(FunctionDeclarationStatement statement) { var name = statement.Name; var paras = statement.Parameters; var stats = statement.Statements; try { IFunctionObject value = this.ObjectCreator.CreateFunction(this, paras, stats); Memory.DecalreFunction(this, name, value); } catch (RuntimeException) { throw; } catch (Exception ex) { throw new RuntimeException(statement.LinePragma, ex.Message, ex); } return(ExecuteResult.Next); }
/// <summary> /// Declares a function with the specified a name. /// </summary> /// <param name="context">The runtime context.</param> /// <param name="name">The function name.</param> /// <param name="value">The function object.</param> protected override void DecalreFunction(RuntimeContext context, string name, IFunctionObject value) { if (this.Functions.ContainsKey(name)) { this.Functions[name] = value; } else if (this.Variables.ContainsKey(name)) { Variables.Remove(name); this.Functions.Add(name, value); } else if (this.Classes.ContainsKey(name)) { Classes.Remove(name); this.Functions.Add(name, value); } else { this.Functions.Add(name, value); } }
/// <summary> /// Declares a function with the specified a name. /// </summary> /// <param name="context">The runtime context.</param> /// <param name="name">The function name.</param> /// <param name="value">The function object.</param> /// <exception cref="InvalidOperationException">The function has not been declared in hoisting. <see cref="HoistingDecalreFunction"/> should be called first.</exception> void IVariableMemory.DecalreFunction(RuntimeContext context, string name, IFunctionObject value) { DecalreFunction(context, name, value); }