001 
002 /*
003  *  JScripter Simulation 1.0 - For Java To Script
004  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.jscripter.org>
005  *  
006  *  This program is free software: you can redistribute it and/or modify
007  *  it under the terms of the GNU Affero General Public License as published by
008  *  the Free Software Foundation, either version 3 of the License, or
009  *  (at your option) any later version.
010  *  
011  *  This program is distributed in the hope that it will be useful,
012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014  *  GNU Affero General Public License for more details.
015  *  
016  *  You should have received a copy of the GNU Affero General Public License
017  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
018  */
019 
020 package org.jscripter.sim.core;
021 
022 import java.util.Iterator;
023 
024 import js.*;
025 import js.core.*;
026 
027 final class JscString extends JsString implements
028     Iterable<JsString.Mid>, Like<StringLike>, LikeObject, Unwrappable<JscObject>
029 {
030     public JscString(JscObject var) {
031         super((Object)var);
032     }
033     public JscString(StringLike var, ObjectLike objectLike) {
034         this(new JscObject(var, objectLike));
035     }
036     public JscString(StringLike var) {
037         this(var, Js.object());
038     }
039 
040     public final JscObject unwrap() {
041         return (JscObject)var;
042     }
043 
044     public final StringLike like() {
045         return (StringLike)unwrap().like();
046     }
047 
048     public final ObjectLike likeObject() {
049         return unwrap().likeObject();
050     }
051 
052     @Override
053     public final JscString var() {
054         return this;
055     }
056 
057     public final Iterator<Mid> iterator() {
058         return unwrap().iterator();
059     }
060 
061     @Override
062     public final String typeof() {
063         return undefined() ? "undefined" : "object";
064     }
065 
066     @Override
067     public final String toString() {
068         return toString.with(this).call(this);
069     }
070 
071     @Override
072     public final String valueOf() {
073         return valueOf.with(this).call(this);
074     }
075 
076     @Override
077     public final boolean undefined() {
078         return unwrap().undefined();
079     }
080 
081     @Override
082     public final boolean delete() {
083         return unwrap().delete();
084     }
085 
086     @Override
087     public final boolean delete(Mid mid) {
088         return unwrap().delete();
089     }
090 
091     @Override
092     public final Object var(Mid mid) {
093         if (mid == Members.length) {
094             return like().length();
095         }
096         return unwrap().var(mid);
097     }
098     @Override
099     public final <S> S var(Mid mid, S v) {
100         return unwrap().var(mid, v);
101     }
102 
103     @Override
104     protected final <T> T call(JsFunction.Member<T> member) {
105         return member.with(this).call(this);
106     }
107     @Override
108     protected final <T> T call(JsFunction.Member<T> member, Object arg) {
109         return member.with(this).call(this, arg);
110     }
111     @Override
112     protected final <T> T call(JsFunction.Member<T> member, Vars<?> args) {
113         return member.with(this).call(this, args);
114     }
115 }