001: /*
002: * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.es;
030:
031: /**
032: * Implementation class representing the global object.
033: */
034: abstract public class ESGlobal extends ESObject implements ESCallable {
035: private Global resin;
036:
037: /**
038: * Null constructor
039: */
040: protected ESGlobal(Global resin) {
041: super ("Global", resin);
042: //snapPrototype = true;
043:
044: this .resin = resin;
045: }
046:
047: /**
048: * Returns the string representation of the type.
049: */
050: public ESBase typeof() throws ESException {
051: return ESString.create("function");
052: }
053:
054: /**
055: * returns the string representation
056: */
057: public ESString toStr() throws ESException {
058: return ESString.create("[global]");
059: }
060:
061: /**
062: * returns a primitive
063: */
064: public ESBase toPrimitive(int hint) throws ESException {
065: return toStr();
066: }
067:
068: public void setProperty(String name, ESBase value) throws Throwable {
069: setProperty(ESId.intern(name), value);
070: }
071:
072: public Object toJavaObject() throws ESException {
073: Object o = prototype.toJavaObject();
074: return (o == null) ? this : o;
075: }
076:
077: /**
078: * Execute the static function
079: */
080: ESBase execute() throws Throwable {
081: Global resin = (Global) prototype;
082:
083: try {
084: Call call = resin.getCall();
085: call.caller = call;
086: call.setArg(0, this );
087: call.top = 1;
088:
089: call.scopeLength = 1;
090: call.scope[0] = this ;
091: call.global = this ;
092:
093: ESBase value = null;
094:
095: try {
096: value = call(0, call, 0);
097: } finally {
098: resin.freeCall(call);
099: }
100:
101: return value;
102: } catch (ESException e) {
103: throw e;
104: } catch (Throwable e) {
105: throw new ESWrapperException(e);
106: }
107: }
108:
109: public void export(ESObject dest) throws Throwable {
110:
111: }
112:
113: /**
114: * Wraps the java object in an ES wrapper
115: */
116: public ESBase wrap(Object obj) throws Throwable {
117: return resin.wrap(obj);
118: }
119:
120: public abstract ESBase call(int n, Call call, int length)
121: throws Throwable;
122: }
|