protected FunctionInstance(Engine engine, string[] parameters, LexicalEnvironment scope, bool strict) : base(engine) { _engine = engine; FormalParameters = parameters; Scope = scope; Strict = strict; }
/// <summary> /// http://www.ecma-international.org/ecma-262/5.1/#sec-13.2 /// </summary> /// <param name="engine"></param> /// <param name="functionDeclaration"></param> /// <param name="scope"></param> /// <param name="strict"></param> public ScriptFunctionInstance(Engine engine, IFunctionDeclaration functionDeclaration, LexicalEnvironment scope, bool strict) : base(engine, functionDeclaration.Parameters.Select(x => x.Name).ToArray(), scope, strict) { _functionDeclaration = functionDeclaration; Engine = engine; Extensible = true; Prototype = engine.Function.PrototypeObject; DefineOwnProperty("length", new PropertyDescriptor(new JsValue(FormalParameters.Length), false, false, false ), false); var proto = engine.Object.Construct(Arguments.Empty); proto.DefineOwnProperty("constructor", new PropertyDescriptor(this, true, false, true), false); DefineOwnProperty("prototype", new PropertyDescriptor(proto, true, false, false ), false); if (_functionDeclaration.Id != null) { DefineOwnProperty("name", new PropertyDescriptor(_functionDeclaration.Id.Name, null, null, null), false); } if (strict) { var thrower = engine.Function.ThrowTypeError; DefineOwnProperty("caller", new PropertyDescriptor(thrower, thrower, false, false), false); DefineOwnProperty("arguments", new PropertyDescriptor(thrower, thrower, false, false), false); } }
public EngineInstance(IWindow window, IDictionary<String, Object> assignments) { _objects = new Dictionary<Object, DomNodeInstance>(); _engine = new Engine(); _engine.SetValue("console", new ConsoleInstance(_engine)); foreach (var assignment in assignments) _engine.SetValue(assignment.Key, assignment.Value); _window = GetDomNode(window); _lexicals = LexicalEnvironment.NewObjectEnvironment(_engine, _window, _engine.ExecutionContext.LexicalEnvironment, true); _variables = LexicalEnvironment.NewObjectEnvironment(_engine, _engine.Global, null, false); _constructors = new DomConstructors(this); _constructors.Configure(); this.AddConstructors(_window, typeof(INode)); this.AddConstructors(_window, this.GetType()); }
public static Reference GetIdentifierReference(LexicalEnvironment lex, string name, bool strict) { if (lex == null) { return new Reference(Undefined.Instance, name, strict); } if (lex.Record.HasBinding(name)) { return new Reference(lex.Record, name, strict); } if (lex.Outer == null) { return new Reference(Undefined.Instance, name, strict); } return GetIdentifierReference(lex.Outer, name, strict); }
private static void AddRecordsFromEnvironment(LexicalEnvironment lex, Dictionary<string, JsValue> locals) { var bindings = lex.Record.GetAllBindingNames(); foreach (var binding in bindings) { if (locals.ContainsKey(binding) == false) { var jsValue = lex.Record.GetBindingValue(binding, false); if (jsValue.TryCast<ICallable>() == null) { locals.Add(binding, jsValue); } } } }
private static Dictionary<string, JsValue> GetGlobalVariables(LexicalEnvironment lex) { Dictionary<string, JsValue> globals = new Dictionary<string, JsValue>(); LexicalEnvironment tempLex = lex; while (tempLex != null && tempLex.Record != null) { AddRecordsFromEnvironment(tempLex, globals); tempLex = tempLex.Outer; } return globals; }
private static Dictionary<string, JsValue> GetLocalVariables(LexicalEnvironment lex) { Dictionary<string, JsValue> locals = new Dictionary<string, JsValue>(); if (lex != null && lex.Record != null) { AddRecordsFromEnvironment(lex, locals); } return locals; }
public LexicalEnvironment(Engine engine, EnvironmentRecord record, LexicalEnvironment outer) { _engine = engine; _record = record; _outer = outer; }
public Engine(Action<Options> options) { _executionContexts = new Stack<ExecutionContext>(); Global = GlobalObject.CreateGlobalObject(this); Object = ObjectConstructor.CreateObjectConstructor(this); Function = FunctionConstructor.CreateFunctionConstructor(this); Array = ArrayConstructor.CreateArrayConstructor(this); String = StringConstructor.CreateStringConstructor(this); RegExp = RegExpConstructor.CreateRegExpConstructor(this); Number = NumberConstructor.CreateNumberConstructor(this); Boolean = BooleanConstructor.CreateBooleanConstructor(this); Date = DateConstructor.CreateDateConstructor(this); Math = MathInstance.CreateMathObject(this); Json = JsonInstance.CreateJsonObject(this); Error = ErrorConstructor.CreateErrorConstructor(this, "Error"); EvalError = ErrorConstructor.CreateErrorConstructor(this, "EvalError"); RangeError = ErrorConstructor.CreateErrorConstructor(this, "RangeError"); ReferenceError = ErrorConstructor.CreateErrorConstructor(this, "ReferenceError"); SyntaxError = ErrorConstructor.CreateErrorConstructor(this, "SyntaxError"); TypeError = ErrorConstructor.CreateErrorConstructor(this, "TypeError"); UriError = ErrorConstructor.CreateErrorConstructor(this, "URIError"); // Because the properties might need some of the built-in object // their configuration is delayed to a later step Global.Configure(); Object.Configure(); Object.PrototypeObject.Configure(); Function.Configure(); Function.PrototypeObject.Configure(); Array.Configure(); Array.PrototypeObject.Configure(); String.Configure(); String.PrototypeObject.Configure(); RegExp.Configure(); RegExp.PrototypeObject.Configure(); Number.Configure(); Number.PrototypeObject.Configure(); Boolean.Configure(); Boolean.PrototypeObject.Configure(); Date.Configure(); Date.PrototypeObject.Configure(); Math.Configure(); Json.Configure(); Error.Configure(); Error.PrototypeObject.Configure(); // create the global environment http://www.ecma-international.org/ecma-262/5.1/#sec-10.2.3 GlobalEnvironment = LexicalEnvironment.NewObjectEnvironment(this, Global, null, false); // create the global execution context http://www.ecma-international.org/ecma-262/5.1/#sec-10.4.1.1 EnterExecutionContext(GlobalEnvironment, GlobalEnvironment, Global); Options = new Options(); if (options != null) { options(Options); } Eval = new EvalFunctionInstance(this, new string[0], LexicalEnvironment.NewDeclarativeEnvironment(this, ExecutionContext.LexicalEnvironment), StrictModeScope.IsStrictModeCode); Global.FastAddProperty("eval", Eval, true, false, true); _statements = new StatementInterpreter(this); _expressions = new ExpressionInterpreter(this); if (Options.IsClrAllowed()) { Global.FastAddProperty("System", new NamespaceReference(this, "System"), false, false, false); Global.FastAddProperty("importNamespace", new ClrFunctionInstance(this, (thisObj, arguments) => { return new NamespaceReference(this, TypeConverter.ToString(arguments.At(0))); }), false, false, false); } ClrTypeConverter = new DefaultTypeConverter(this); BreakPoints = new List<BreakPoint>(); DebugHandler = new DebugHandler(this); }
public static LexicalEnvironment NewObjectEnvironment(Engine engine, ObjectInstance objectInstance, LexicalEnvironment outer, bool provideThis) { return(new LexicalEnvironment(new ObjectEnvironmentRecord(engine, objectInstance, provideThis), outer)); }
public FunctionShim(Engine engine, string[] parameters, LexicalEnvironment scope) : base(engine, parameters, scope, false) { }
public static LexicalEnvironment NewObjectEnvironment(Engine engine, ObjectInstance objectInstance, LexicalEnvironment outer, bool provideThis) { return new LexicalEnvironment(new ObjectEnvironmentRecord(engine, objectInstance, provideThis), outer); }
public static LexicalEnvironment NewDeclarativeEnvironment(Engine engine, LexicalEnvironment outer = null) { return new LexicalEnvironment(new DeclarativeEnvironmentRecord(engine), outer); }
public LexicalEnvironment(EnvironmentRecord record, LexicalEnvironment outer) { _record = record; _outer = outer; }
public static LexicalEnvironment NewDeclarativeEnvironment(Engine engine, LexicalEnvironment outer = null) { return(new LexicalEnvironment(new DeclarativeEnvironmentRecord(engine), outer)); }
public ExecutionContext UpdateLexicalEnvironment(LexicalEnvironment newEnv) { return(new ExecutionContext(newEnv, VariableEnvironment, ThisBinding)); }
public ExecutionContext(LexicalEnvironment lexicalEnvironment, LexicalEnvironment variableEnvironment, JsValue thisBinding) { LexicalEnvironment = lexicalEnvironment; VariableEnvironment = variableEnvironment; ThisBinding = thisBinding; }
public EvalFunctionInstance(Engine engine, string[] parameters, LexicalEnvironment scope, bool strict) : base(engine, parameters, scope, strict) { _engine = engine; Prototype = Engine.Function.PrototypeObject; FastAddProperty("length", 1, false, false, false); }
public ExecutionContext EnterExecutionContext(LexicalEnvironment lexicalEnvironment, LexicalEnvironment variableEnvironment, JsValue thisBinding) { var executionContext = new ExecutionContext { LexicalEnvironment = lexicalEnvironment, VariableEnvironment = variableEnvironment, ThisBinding = thisBinding }; _executionContexts.Push(executionContext); return executionContext; }
internal static bool TryGetIdentifierEnvironmentWithBindingValue( LexicalEnvironment lex, in EnvironmentRecord.BindingName name,