Exemplo n.º 1
0
    public Object call(Scope scope, Object a, Object extra[]) {
      Object def = 0;
      if (extra != null && extra.length > 0) def = extra[0];

      if (scope.getThis() instanceof JSNumber) {
        JSNumber n = (JSNumber) (scope.getThis());
        n._val = _parse(a, def);
        return n._val;
      }

      return _parse(a, def);
    }
Exemplo n.º 2
0
  /** @unexpose */
  static Object _loop(final Scope s, final JSFunction f, final int start, final int end) {
    Object blah = s.getParent().getThis();
    s.setThis(blah);

    Boolean old = f.setUsePassedInScopeTL(true);

    for (int i = start; i < end; i++) f.call(s, i);

    f.setUsePassedInScopeTL(old);

    s.clearThisNormal(null);

    return null;
  }
Exemplo n.º 3
0
  private static String _getVersionForLibrary(Scope s, String name, AppContext ctxt) {
    final JSObject o1 =
        ctxt == null ? null : (JSObject) (s.get("version_" + ctxt.getEnvironmentName()));
    final JSObject o2 = (JSObject) s.get("version");

    _libraryLogger.debug(ctxt + "\t versionConfig:" + (o1 != null) + " config:" + (o2 != null));

    String version = _getString(name, o1, o2);
    if (version != null) return version;

    if (ctxt == null || ctxt._nonAdminParent == null) return null;

    return ctxt._nonAdminParent.getVersionForLibrary(name);
  }
Exemplo n.º 4
0
        public Object call(Scope sc, Object pointsInt, Object fo00000o[]) {
          Number n = (Number) (sc.getThis());
          int num = 0;
          if (pointsInt != null && pointsInt instanceof Number)
            num = ((Number) pointsInt).intValue();

          double mult = Math.pow(10, num);

          long foo = Math.round(n.doubleValue() * mult);
          double d = foo;
          d = d / mult;

          String s = String.valueOf(d);
          int idx = s.indexOf(".");

          if (idx < 0) {
            if (num > 0) {
              s += ".";
              while (num > 0) {
                s += "0";
                num--;
              }
            }
            return new JSString(s);
          }

          if (s.length() - idx <= num) { // need more
            int toAdd = (num + 1) - (s.length() - idx);
            for (int i = 0; i < toAdd; i++) s += "0";
            return new JSString(s);
          }

          if (num == 0) return s.substring(0, idx);
          return new JSString(s.substring(0, idx + 1 + num));
        }
Exemplo n.º 5
0
  public static AppContext findThreadLocal() {

    AppContext context = _tl.get();
    if (context != null) return context;

    AppRequest req = AppRequest.getThreadLocal();
    if (req != null) return req._context;

    Scope s = Scope.getThreadLocal();
    if (s != null) {
      Object foo = s.get("__instance__");
      if (foo instanceof AppContext) return (AppContext) foo;
    }

    return null;
  }
Exemplo n.º 6
0
  private AppContext(
      String root, File rootFile, String name, String environment, AppContext nonAdminParent) {
    super(name + ":" + environment);
    if (root == null) throw new NullPointerException("AppContext root can't be null");

    if (rootFile == null) throw new NullPointerException("AppContext rootFile can't be null");

    if (name == null) name = guessNameAndEnv(root).name;

    if (name == null) throw new NullPointerException("how could name be null");

    _root = root;
    _rootFile = rootFile;
    _git = new GitDir(_rootFile);
    _name = name;

    _environment = environment;
    _nonAdminParent = nonAdminParent;
    _admin = _nonAdminParent != null;
    _codePrefix = _admin ? "/~~/modules/admin/" : "";
    _moduleRegistry = ModuleRegistry.getNewGlobalChild();

    if (_git.isValid()) {
      _gitBranch = _git.getBranchOrTagName();
      _gitHash = _git.getCurrentHash();
    }

    _isGrid = name.equals("grid");

    _scope =
        new Scope(
            "AppContext:" + root + (_admin ? ":admin" : ""),
            _isGrid ? ed.cloud.Cloud.getInstance().getScope() : Scope.newGlobal(),
            null,
            Language.JS(),
            _rootFile);
    _scope.setGlobal(true);
    _initScope = _scope.child("_init");

    _usage = new UsageTracker(this);

    _baseScopeInit();

    _adminContext = _admin ? null : new AppContext(root, rootFile, name, environment, this);

    _rootContextReachable = new SeenPath();

    if (!_admin)
      _logger.info(
          "Started Context.  root:"
              + _root
              + " environment:"
              + environment
              + " git branch: "
              + _gitBranch);
  }
Exemplo n.º 7
0
 public Object call(Scope s, Object foo[]) {
   Number n = (Number) s.getThis();
   return n.doubleValue() * _conversion;
 }
Exemplo n.º 8
0
 public static Cons getCons() {
   return (Cons) (Scope.getThreadLocalFunction("Number", new Cons()));
 }
Exemplo n.º 9
0
  private void _setupScope() {
    if (_inScopeSetup) return;

    final Scope saveTLPref = _scope.getTLPreferred();
    _scope.setTLPreferred(null);

    final Scope saveTL = Scope.getThreadLocal();
    _scope.makeThreadLocal();

    _inScopeSetup = true;

    try {
      Object fo = getConfigObject("framework");

      if (fo != null) {

        Framework f = null;

        if (fo instanceof JSString) {
          f = Framework.byName(fo.toString(), null); // we allow people to just specify name
          _logger.info("Setting framework by name [" + fo.toString() + "]");
        } else if (fo instanceof JSObjectBase) {

          JSObjectBase obj = (JSObjectBase) fo;

          if (obj.containsKey("name")) {

            String s = obj.getAsString("version");

            f = Framework.byName(obj.getAsString("name"), s);
            _logger.info("Setting framework by name [" + obj.getAsString("name") + "]");
          } else if (obj.containsKey("custom")) {

            Object o = obj.get("custom");

            if (o instanceof JSObjectBase) {
              f = Framework.byCustom((JSObjectBase) o);
              _logger.info("Setting framework by custom [" + o + "]");
            } else {
              throw new RuntimeException("Error - custom framework wasn't an object [" + o + "]");
            }
          } else if (obj.containsKey("classname")) {
            f = Framework.byClass(obj.getAsString("classname"));
            _logger.info("Setting framework by class [" + obj.getAsString("classname") + "]");
          }
        }

        if (f == null) {
          throw new RuntimeException("Error : can't find framework [" + fo + "]");
        }

        f.install(this);
      }

      _runInitFiles(INIT_FILES);

      if (_adminContext != null) {
        _adminContext._scope.set("siteScope", _scope);
        _adminContext._setLocalObject(_localObject);
      }

      _lastScopeInitTime = _getScopeTime();
    } catch (RuntimeException re) {
      _scopeInited = false;
      throw re;
    } catch (Exception e) {
      _scopeInited = false;
      throw new RuntimeException(e);
    } finally {
      _inScopeSetup = false;
      _scope.setTLPreferred(saveTLPref);

      if (saveTL != null) saveTL.makeThreadLocal();

      this.approxSize(_rootContextReachable);
    }
  }