1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
7 import org.ibex.util.*;
9 class JSString extends JSPrimitive {
11 public JSString(String s) { this.s = s; }
12 public int hashCode() { return s.hashCode(); }
14 public boolean jsequals(JS o) {
15 if(o == this) return true;
16 if(o instanceof JSString) {
17 return ((JSString)o).s.equals(s);
18 } else if(o instanceof JSNumber) {
19 return o.jsequals(this);
25 private final static Hash internHash = new Hash();
26 static synchronized JS intern(String s) {
27 synchronized(internHash) {
28 JS js = (JS)internHash.get(s);
29 if(js == null) internHash.put(s,js = new Intern(s));
33 static class Intern extends JSString {
34 public Intern(String s) { super(s); }
35 protected void finalize() { synchronized(internHash) { internHash.put(s,null); } }
38 String coerceToString() { return s; }