1 28 29 package com.caucho.es; 30 31 import com.caucho.util.IntMap; 32 33 import java.util.HashMap ; 34 35 38 class ESJavaWrapper extends ESObject { 39 public Object value; 40 41 public ESString toStr() throws Throwable 42 { 43 return ESString.create(value == null ? "null" : value.toString()); 44 } 45 46 public ESString toSource(IntMap map, boolean isLoopPath) throws Throwable 47 { 48 if (isLoopPath) 49 return null; 50 else 51 return toStr(); 52 } 53 54 public ESBase toPrimitive(int hint) throws Throwable 55 { 56 if (value instanceof ESBase) 57 return (ESBase) value; 58 else 59 return toStr(); 60 } 61 62 public Object toJavaObject() { return value; } 63 64 public ESJavaWrapper wrap(Object value) 65 { 66 if (value == null) 67 throw new NullPointerException (); 68 69 ESJavaWrapper child = (ESJavaWrapper) dup(); 70 child.value = value; 71 child.init(className, prototype); 72 73 return child; 74 } 75 76 public boolean ecmaEquals(ESBase b) 77 { 78 if (! (b instanceof ESJavaWrapper)) 79 return false; 80 else 81 return value == ((ESJavaWrapper) b).value; 82 } 83 84 protected ESJavaWrapper() {} 85 protected ESObject dup() { return new ESJavaWrapper(); } 86 87 protected void copy(HashMap refs, Object newObj) 88 { 89 ESJavaWrapper obj = (ESJavaWrapper) newObj; 90 91 super.copy(refs, obj); 92 93 obj.value = value; 94 } 95 96 protected ESJavaWrapper(ESBase proto, Object value) 97 { 98 super("javaWrapper", proto); 99 100 this.value = value; 101 } 102 } 103 | Popular Tags |