Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.dynjs.runtime;
  
  import java.util.List;
  
  import org.dynjs.Config;
 
 public class GlobalObject extends DynObject {
 
     private DynJS runtime;
     private BlockManager blockManager;
     private List<ModuleProvidermoduleProviders = new ArrayList<>();
     private List<StringloadPaths = new ArrayList<>();
     private List<AbstractBuiltinTypebuiltinTypes = new ArrayList<>();
 
     public GlobalObject(DynJS runtime) {
         super(null);
         this. = runtime;
         this. = new BlockManager();
 
         defineReadOnlyGlobalProperty("__throwTypeError"new ThrowTypeError(this));
 
         // ----------------------------------------
         // Built-in types
         // ----------------------------------------
 
         registerBuiltinType("Object"new BuiltinObject(this));
         registerBuiltinType("Function"new BuiltinFunction(this));
         registerBuiltinType("Boolean"new BuiltinBoolean(this));
         registerBuiltinType("Number"new BuiltinNumber(this));
         registerBuiltinType("Array"new BuiltinArray(this));
         registerBuiltinType("String"new BuiltinString(this));
         registerBuiltinType("RegExp"new BuiltinRegExp(this));
         registerBuiltinType("Date"new BuiltinDate(this));
         registerBuiltinType("Error"new BuiltinError(this));
         registerBuiltinType("ReferenceError"new BuiltinReferenceError(this));
         registerBuiltinType("RangeError"new BuiltinRangeError(this));
         registerBuiltinType("SyntaxError"new BuiltinSyntaxError(this));
         registerBuiltinType("TypeError"new BuiltinTypeError(this));
         registerBuiltinType("URIError"new BuiltinURIError(this));
         registerBuiltinType("EvalError"new BuiltinEvalError(this));
 
         initializeBuiltinTypes();
 
         // ----------------------------------------
         // Built-in global functions
         // ----------------------------------------
 
         defineReadOnlyGlobalProperty("undefined".);
 
         defineGlobalProperty("parseFloat"new ParseFloat(this));
         defineGlobalProperty("parseInt"new ParseInt(this));
         defineGlobalProperty("eval"new Eval(this));
         defineGlobalProperty("isNaN"new IsNaN(this));
         defineGlobalProperty("isFinite"new IsFinite(this));
 
         defineGlobalProperty("encodeURI"new EncodeUri(this));
        defineGlobalProperty("decodeURI"new DecodeUri(this));
        defineGlobalProperty("encodeURIComponent"new EncodeUriComponent(this));
        defineGlobalProperty("decodeURIComponent"new DecodeUriComponent(this));
        if (runtime.getConfig().isNodePackageManagerEnabled()) {
            defineGlobalProperty("require"new Require(this));
        }
        defineGlobalProperty("include"new Include(this));
        defineGlobalProperty("escape"new Escape(this));
        defineGlobalProperty("unescape"new Unescape(this));
        defineGlobalProperty("print"new Print(this));
        // ----------------------------------------
        // Built-in global objects
        // ----------------------------------------
        put(null"JSON"new JSON(this), false);
        defineGlobalProperty("Math"new Math(this));
        defineGlobalProperty("Intl"new Intl(this));
        // ----------------------------------------
        // Module-provider setup
        // ----------------------------------------
        this..add(new FilesystemModuleProvider(this));
        this..add(new ClasspathModuleProvider());
        JavaClassModuleProvider javaClassModuleProvider = new JavaClassModuleProvider();
        javaClassModuleProvider.addModule(new ConsoleModule());
        javaClassModuleProvider.addModule(new UtilModule());
        this..add(javaClassModuleProvider);
        // ----------------------------------------
        // Java integration
        // ----------------------------------------
        defineGlobalProperty("java"new JavaPackage(this"java"));
        defineGlobalProperty("org"new JavaPackage(this"org"));
        defineGlobalProperty("com"new JavaPackage(this"com"));
        setPrototype(getPrototypeFor("Object"));
    }
    private void registerBuiltinType(String namefinal AbstractBuiltinType type) {
        defineOwnProperty(nullnamenew PropertyDescriptor() {
            {
                set("Value"type);
                set("Enumerable"false);
                set("Writable"true);
                set("Configurable"true);
            }
        }, false);
        put(null"__Builtin_" + nametypefalse);
        this..add(type);
    }
    private void initializeBuiltinTypes() {
        for (AbstractBuiltinType each : this.) {
            each.setPrototype(getPrototypeFor("Function"));
            each.initialize(this);
        }
    }
    public static GlobalObject newGlobalObject(DynJS runtime) {
        return runtime.getConfig().getGlobalObjectFactory().newGlobalObject(runtime);
    }
        return this.;
    }
    public void addLoadPath(String path) {
        this..add(path);
    }
    public List<StringgetLoadPaths() {
        return this.;
    }
    public DynJS getRuntime() {
        return this.;
    }
    public Config getConfig() {
        return getRuntime().getConfig();
    }
    public JSCompiler getCompiler() {
        return this..getCompiler();
    }
    public BlockManager getBlockManager() {
        return this.;
    }
    public org.dynjs.runtime.BlockManager.Entry retrieveBlockEntry(int statementNumber) {
        return this..retrieve(statementNumber);
    }
    public void defineGlobalProperty(final String namefinal Object value) {
        PropertyDescriptor desc = new PropertyDescriptor() {
            {
                set("Value"value);
                set("Writable"true);
                set("Enumerable"false);
                set("Configurable"true);
            }
        };
        defineOwnProperty(nullnamedescfalse);
    }
    public void defineReadOnlyGlobalProperty(final String namefinal Object value) {
        PropertyDescriptor desc = new PropertyDescriptor() {
            {
                set("Value"value);
                set("Writable"false);
                set("Configurable"false);
                set("Enumerable"false);
            }
        };
        defineOwnProperty(nullnamedescfalse);
    }
    public JSObject getPrototypeFor(String type) {
        Object typeObj = get(nulltype);
        if (typeObj == .) {
            return null;
        }
        Object prototype = ((JSObjecttypeObj).get(null"prototype");
        if (prototype == .) {
            return null;
        }
        return (JSObjectprototype;
    }
New to GrepCode? Check out our FAQ X