Permalink
Browse files

adding builtin load support

  • Loading branch information...
qmx committed May 3, 2012
1 parent 793dac5 commit f0e6de9d047276505bfb7d7207972c417b3d0c8d
Showing with 12 additions and 4 deletions.
  1. +12 −4 src/main/java/org/dynjs/runtime/DynThreadContext.java
@@ -19,10 +19,7 @@
import org.dynjs.api.Function;
import org.dynjs.api.Scope;
-import java.util.Deque;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.Map;
+import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
public class DynThreadContext {
@@ -35,13 +32,23 @@ public String toString() {
};
public static final Object NULL = new Object();
+
+ private static final Map<String, Object> BUILTINS = new LinkedHashMap<String, Object>() {{
+ }};
+
private ThreadLocal<DynJS> runtime = new ThreadLocal<>();
private AtomicInteger storageCounter = new AtomicInteger();
private Map<Integer, CodeBlock> storage = new HashMap<>();
private Scope scope = new DynObject();
private Deque<Function> callStack = new LinkedList<>();
private DynamicClassLoader classLoader;
+ public DynThreadContext() {
+ for (Map.Entry<String, Object> builin : BUILTINS.entrySet()) {
+ scope.define(builin.getKey(), builin.getValue());
+ }
+ }
+
public DynJS getRuntime() {
return this.runtime.get();
}
@@ -102,4 +109,5 @@ public void setClassLoader(DynamicClassLoader classLoader) {
public DynamicClassLoader getClassLoader() {
return classLoader;
}
+
}

0 comments on commit f0e6de9

Please sign in to comment.