1 28 29 package com.caucho.es; 30 31 34 abstract public class ESGlobal extends ESObject implements ESCallable { 35 private Global resin; 36 37 40 protected ESGlobal(Global resin) 41 { 42 super("Global", resin); 43 45 this.resin = resin; 46 } 47 48 51 public ESBase typeof() throws ESException 52 { 53 return ESString.create("function"); 54 } 55 56 59 public ESString toStr() throws ESException 60 { 61 return ESString.create("[global]"); 62 } 63 64 67 public ESBase toPrimitive(int hint) throws ESException 68 { 69 return toStr(); 70 } 71 72 public void setProperty(String name, ESBase value) 73 throws Throwable 74 { 75 setProperty(ESId.intern(name), value); 76 } 77 78 public Object toJavaObject() 79 throws ESException 80 { 81 Object o = prototype.toJavaObject(); 82 return (o == null) ? this : o; 83 } 84 85 88 ESBase execute() 89 throws Throwable 90 { 91 Global resin = (Global) prototype; 92 93 try { 94 Call call = resin.getCall(); 95 call.caller = call; 96 call.setArg(0, this); 97 call.top = 1; 98 99 call.scopeLength = 1; 100 call.scope[0] = this; 101 call.global = this; 102 103 ESBase value = null; 104 105 try { 106 value = call(0, call, 0); 107 } finally { 108 resin.freeCall(call); 109 } 110 111 return value; 112 } catch (ESException e) { 113 throw e; 114 } catch (Throwable e) { 115 throw new ESWrapperException(e); 116 } 117 } 118 119 120 public void export(ESObject dest) 121 throws Throwable 122 { 123 124 } 125 126 129 public ESBase wrap(Object obj) 130 throws Throwable 131 { 132 return resin.wrap(obj); 133 } 134 135 public abstract ESBase call(int n, Call call, int length) 136 throws Throwable ; 137 } 138 | Popular Tags |