/// <summary> /// Initializes a new Module with specified code, callback for output compiler messages and compiler options. /// </summary> /// <param name="path">Path to file with script. Used for resolving paths to other modules for importing via import directive. Can be null or empty</param> /// <param name="code">JavaScript code.</param> /// <param name="messageCallback">Callback used to output compiler messages or null</param> /// <param name="options">Compiler options</param> public Module(string path, string code, CompilerMessageCallback messageCallback, Options options) { if (code == null) { throw new ArgumentNullException(); } Code = code; Context = new Context(Context.CurrentGlobalContext, true, null); Context._module = this; if (!string.IsNullOrWhiteSpace(path)) { lock (__modulesCache) { if (!__modulesCache.ContainsKey(path)) { __modulesCache[path] = this; } } FilePath = path; } if (code == "") { return; } var internalCallback = messageCallback != null ? (level, cord, message) => messageCallback(level, CodeCoordinates.FromTextPosition(code, cord.Column, cord.Length), message) : null as CompilerMessageCallback; int i = 0; _root = (CodeBlock)CodeBlock.Parse(new ParseInfo(Tools.removeComments(code, 0), Code, internalCallback), ref i); var stat = new FunctionInfo(); Parser.Build(ref _root, 0, new Dictionary <string, VariableDescriptor>(), CodeContext.None, internalCallback, stat, options); var body = _root as CodeBlock; body._suppressScopeIsolation = SuppressScopeIsolationMode.Suppress; Context._thisBind = new GlobalObject(Context); Context._strict = body._strict; var tv = stat.WithLexicalEnvironment ? null : new Dictionary <string, VariableDescriptor>(); body.RebuildScope(stat, tv, body._variables.Length == 0 || !stat.WithLexicalEnvironment ? 1 : 0); var bd = body as CodeNode; body.Optimize(ref bd, null, internalCallback, options, stat); if (tv != null) { body._variables = new List <VariableDescriptor>(tv.Values).ToArray(); } if (stat.NeedDecompose) { body.Decompose(ref bd); } }
/// <summary> /// Initializes a new Module with specified code, callback for output compiler messages and compiler options. /// </summary> /// <param name="virtualPath">Path to file with script. Used for resolving paths to other modules for importing via import directive. Can be null or empty</param> /// <param name="code">JavaScript code.</param> /// <param name="messageCallback">Callback used to output compiler messages or null</param> /// <param name="options">Compiler options</param> public Module(string virtualPath, string code, CompilerMessageCallback messageCallback, Options options) { if (code == null) { throw new ArgumentNullException(); } if (!string.IsNullOrWhiteSpace(virtualPath)) { lock (_modulesCache) { if (!_modulesCache.ContainsKey(virtualPath)) { _modulesCache[virtualPath] = this; } } FilePath = virtualPath; } Context = new Context(Context.CurrentGlobalContext, true, null); Context._module = this; Context._thisBind = new GlobalObject(Context); Script = Script.Parse(code, messageCallback, options); Context._strict = Script.Root._strict; }
public void KeyExistence() { var m = new StringMap(); m["a"] = "Albert"; m["b"] = "Benedict"; Assert.AreEqual(2, m.Count); Assert.AreEqual("Albert", m["a"]); Assert.AreEqual("Benedict", m["b"]); Assert.IsNull(m["c"]); Assert.IsTrue(m.ContainsKey("a")); Assert.IsFalse(m.ContainsKey("c")); }
internal Module Import(string path) { path = processPath(path); var e = new ResolveModuleEventArgs(path); for (var i = 0; i < _resolveModuleHandlers.Count && e.Module == null; i++) { _resolveModuleHandlers[i](this, e); } if (e.Module == null) { throw new InvalidOperationException("Unable to load module \"" + path + "\""); } if (e.AddToCache && !_modulesCache.ContainsKey(e.ModulePath)) { _modulesCache[e.ModulePath] = e.Module; } if (e.Module.FilePath == null) { e.Module.FilePath = path; } return(e.Module); }
public GameObject GetTarget(StringMap actorMap) { if (actorMap != null) { if (actorMap.ContainsKey(Name)) { return GameObject.Find(actorMap.Get(Name).Value); } } return GameObject.Find(Name); }
public static StringMap operator +(StringMap a, StringMap b) { StringMap c = a.Clone(); foreach (string key in b.Keys) { if (!c.ContainsKey(key)) { c[key] = b[key]; } } return(c); }
public void KeyExistence() { var m = new StringMap(); m["a"] = "Albert"; m["b"] = "Benedict"; Assert.AreEqual(2, m.Count); Assert.AreEqual("Albert", m["a"]); Assert.AreEqual("Benedict", m["b"]); Assert.IsNull( m["c"] ); Assert.IsTrue( m.ContainsKey("a")); Assert.IsFalse( m.ContainsKey("c")); }
public virtual bool isSource(string id) { return(cellIdMap.ContainsKey(id.ToLower())); }