1999-04-27 02:50:50 +04:00
|
|
|
class JSValue extends ExpressionNode {
|
|
|
|
|
|
|
|
String print(String indent)
|
|
|
|
{
|
1999-05-20 04:13:38 +04:00
|
|
|
return indent + "JSValue\n";
|
1999-04-27 02:50:50 +04:00
|
|
|
}
|
1999-05-08 02:07:22 +04:00
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSReference evalLHS(Environment theEnv)
|
1999-05-08 02:07:22 +04:00
|
|
|
{
|
1999-05-20 04:13:38 +04:00
|
|
|
throw new RuntimeException("EvalLHS on non-lvalue");
|
1999-05-08 02:07:22 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue eval(Environment theEnv)
|
1999-05-08 02:07:22 +04:00
|
|
|
{
|
1999-05-20 04:13:38 +04:00
|
|
|
throw new RuntimeException("Eval on JSValue");
|
1999-05-21 01:16:11 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue unimplemented(String op)
|
1999-05-21 01:16:11 +04:00
|
|
|
{
|
|
|
|
throw new RuntimeException("unimplemented " + op + " called");
|
1999-05-20 04:13:38 +04:00
|
|
|
}
|
1999-05-21 01:16:11 +04:00
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue gt(Environment theEnv, JSValue rV) {
|
1999-05-26 05:01:07 +04:00
|
|
|
JSValue lV = toPrimitive(theEnv, "Number");
|
1999-05-28 23:00:48 +04:00
|
|
|
rV = rV.toPrimitive(theEnv, "Number");
|
|
|
|
if ((lV instanceof JSString) && (rV instanceof JSString))
|
|
|
|
return lV.gt(theEnv, rV);
|
|
|
|
else
|
|
|
|
return lV.toJSDouble(theEnv).gt(theEnv, rV.toJSDouble(theEnv));
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue ge(Environment theEnv, JSValue rV) {
|
1999-05-26 05:01:07 +04:00
|
|
|
JSValue lV = toPrimitive(theEnv, "Number");
|
1999-05-28 23:00:48 +04:00
|
|
|
rV = rV.toPrimitive(theEnv, "Number");
|
|
|
|
if ((lV instanceof JSString) && (rV instanceof JSString))
|
|
|
|
return lV.ge(theEnv, rV);
|
|
|
|
else
|
|
|
|
return lV.toJSDouble(theEnv).ge(theEnv, rV.toJSDouble(theEnv));
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue lt(Environment theEnv, JSValue rV) {
|
1999-05-26 05:01:07 +04:00
|
|
|
JSValue lV = toPrimitive(theEnv, "Number");
|
1999-05-28 23:00:48 +04:00
|
|
|
rV = rV.toPrimitive(theEnv, "Number");
|
|
|
|
if ((lV instanceof JSString) && (rV instanceof JSString))
|
|
|
|
return lV.lt(theEnv, rV);
|
|
|
|
else
|
|
|
|
return lV.toJSDouble(theEnv).lt(theEnv, rV.toJSDouble(theEnv));
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue le(Environment theEnv, JSValue rV) {
|
1999-05-26 05:01:07 +04:00
|
|
|
JSValue lV = toPrimitive(theEnv, "Number");
|
1999-05-28 23:00:48 +04:00
|
|
|
rV = rV.toPrimitive(theEnv, "Number");
|
|
|
|
if ((lV instanceof JSString) && (rV instanceof JSString))
|
|
|
|
return lV.le(theEnv, rV);
|
|
|
|
else
|
|
|
|
return lV.toJSDouble(theEnv).le(theEnv, rV.toJSDouble(theEnv));
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue eq(Environment theEnv, JSValue rV) {
|
1999-05-26 05:01:07 +04:00
|
|
|
JSValue lV = toPrimitive(theEnv, "Number");
|
1999-05-28 23:00:48 +04:00
|
|
|
rV = rV.toPrimitive(theEnv, "Number");
|
|
|
|
if ((lV instanceof JSString) && (rV instanceof JSString))
|
|
|
|
return lV.eq(theEnv, rV);
|
|
|
|
else
|
|
|
|
return lV.toJSDouble(theEnv).eq(theEnv, rV.toJSDouble(theEnv));
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue ne(Environment theEnv, JSValue rV) {
|
1999-05-26 05:01:07 +04:00
|
|
|
JSValue lV = toPrimitive(theEnv, "Number");
|
1999-05-28 23:00:48 +04:00
|
|
|
rV = rV.toPrimitive(theEnv, "Number");
|
|
|
|
if ((lV instanceof JSString) && (rV instanceof JSString))
|
|
|
|
return lV.ne(theEnv, rV);
|
|
|
|
else
|
|
|
|
return lV.toJSDouble(theEnv).ne(theEnv, rV.toJSDouble(theEnv));
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue plus(Environment theEnv) {
|
|
|
|
return toJSDouble(theEnv).plus(theEnv);
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue minus(Environment theEnv) {
|
|
|
|
return toJSDouble(theEnv).minus(theEnv);
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue twiddle(Environment theEnv) {
|
|
|
|
return toJSInteger(theEnv).twiddle(theEnv);
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue bang(Environment theEnv) {
|
|
|
|
return toJSBoolean(theEnv).bang(theEnv);
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue typeof(Environment theEnv) {
|
|
|
|
return unimplemented("typeof");
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue add(Environment theEnv, JSValue rV) {
|
1999-05-26 05:01:07 +04:00
|
|
|
JSValue lV = toPrimitive(theEnv, "");
|
1999-05-28 23:00:48 +04:00
|
|
|
rV = rV.toPrimitive(theEnv, "");
|
|
|
|
if ((lV instanceof JSString) || (rV instanceof JSString))
|
|
|
|
return lV.add(theEnv, rV);
|
|
|
|
else
|
|
|
|
return lV.toJSDouble(theEnv).add(theEnv, rV);
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue subtract(Environment theEnv, JSValue rV) {
|
|
|
|
return toJSDouble(theEnv).subtract(theEnv, rV.toJSDouble(theEnv));
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue multiply(Environment theEnv, JSValue rV) {
|
|
|
|
return toJSDouble(theEnv).multiply(theEnv, rV.toJSDouble(theEnv));
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue divide(Environment theEnv, JSValue rV) {
|
|
|
|
return toJSDouble(theEnv).divide(theEnv, rV.toJSDouble(theEnv));
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue remainder(Environment theEnv, JSValue rV) {
|
|
|
|
return toJSDouble(theEnv).remainder(theEnv, rV.toJSDouble(theEnv));
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue and(Environment theEnv, JSValue rV) {
|
|
|
|
return toJSInteger(theEnv).and(theEnv, rV.toJSInteger(theEnv));
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue or(Environment theEnv, JSValue rV) {
|
|
|
|
return toJSInteger(theEnv).or(theEnv, rV.toJSInteger(theEnv));
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue xor(Environment theEnv, JSValue rV) {
|
|
|
|
return toJSInteger(theEnv).xor(theEnv, rV.toJSInteger(theEnv));
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue shl(Environment theEnv, JSValue rV) {
|
|
|
|
return toJSInteger(theEnv).shl(theEnv, rV.toJSInteger(theEnv));
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue shr(Environment theEnv, JSValue rV) {
|
|
|
|
return toJSInteger(theEnv).shr(theEnv, rV.toJSInteger(theEnv));
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue ushl(Environment theEnv, JSValue rV) {
|
|
|
|
return toJSInteger(theEnv).ushl(theEnv, rV.toJSInteger(theEnv));
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue getProp(Environment theEnv, JSString id) {
|
|
|
|
return toJSObject(theEnv).getProp(theEnv, id);
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue putProp(Environment theEnv, JSString id, JSValue rV) {
|
|
|
|
return toJSObject(theEnv).putProp(theEnv, id, rV);
|
1999-05-26 01:49:40 +04:00
|
|
|
}
|
|
|
|
|
1999-06-11 04:21:26 +04:00
|
|
|
JSValue call(Environment theEnv, JSValue rV) {
|
|
|
|
throw new JSException(new JSString("[[call]] not implemented"));
|
|
|
|
}
|
|
|
|
|
1999-05-26 05:01:07 +04:00
|
|
|
JSValue defaultValue(Environment theEnv, String hint) {
|
|
|
|
/*
|
|
|
|
When the [[DefaultValue]] method of O is called with hint String, the following steps are taken:
|
|
|
|
1. Call the [[Get]] method of object O with argument "toString".
|
|
|
|
2. If Result(1) is not an object, go to step 5.
|
|
|
|
3. Call the [[Call]] method of Result(1), with O as the this value and an empty argument list.
|
|
|
|
4. If Result(3) is a primitive value, return Result(3).
|
|
|
|
5. Call the [[Get]] method of object O with argument "valueOf".
|
|
|
|
6. If Result(5) is not an object, go to step 9.
|
|
|
|
7. Call the [[Call]] method of Result(5), with O as the this value and an empty argument list.
|
|
|
|
8. If Result(7) is a primitive value, return Result(7).
|
|
|
|
9. Generate a runtime error.
|
|
|
|
*/
|
|
|
|
JSValue v = null;
|
|
|
|
if (hint.equals("String")) {
|
1999-05-28 23:00:48 +04:00
|
|
|
v = getProp(theEnv, new JSString("toString"));
|
1999-05-26 05:01:07 +04:00
|
|
|
if (v instanceof JSObject) {
|
|
|
|
// invoke 'v.Call' with 'this' as the JS this
|
|
|
|
}
|
|
|
|
else {
|
1999-05-28 23:00:48 +04:00
|
|
|
v = getProp(theEnv, new JSString("valueOf"));
|
1999-05-26 05:01:07 +04:00
|
|
|
if (v instanceof JSObject) {
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw new JSException(new JSString("No default value"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // hint.equals("Number")
|
|
|
|
/*
|
|
|
|
When the [[DefaultValue]] method of O is called with hint Number, the following steps are taken:
|
|
|
|
1. Call the [[Get]] method of object O with argument "valueOf".
|
|
|
|
2. If Result(1) is not an object, go to step 5.
|
|
|
|
3. Call the [[Call]] method of Result(1), with O as the this value and an empty argument list.
|
|
|
|
4. If Result(3) is a primitive value, return Result(3).
|
|
|
|
5. Call the [[Get]] method of object O with argument "toString".
|
|
|
|
6. If Result(5) is not an object, go to step 9.
|
|
|
|
7. Call the [[Call]] method of Result(5), with O as the this value and an empty argument list.
|
|
|
|
8. If Result(7) is a primitive value, return Result(7).
|
|
|
|
9. Generate a runtime error.
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
1999-05-26 01:49:40 +04:00
|
|
|
|
1999-05-26 05:01:07 +04:00
|
|
|
JSValue toPrimitive(Environment theEnv, String hint) {
|
|
|
|
JSValue result = defaultValue(theEnv, hint);
|
|
|
|
if (result instanceof JSObject)
|
|
|
|
throw new JSException(new JSString("default value returned object"));
|
|
|
|
else
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-05-21 01:16:11 +04:00
|
|
|
|
1999-05-26 05:01:07 +04:00
|
|
|
JSObject toJSObject(Environment theEnv) { unimplemented("toJSObjet"); return null; }
|
|
|
|
JSDouble toJSDouble(Environment theEnv) { unimplemented("toJSDouble"); return null; }
|
|
|
|
JSInteger toJSInteger(Environment theEnv) { unimplemented("toJSInteger"); return null; }
|
|
|
|
JSString toJSString(Environment theEnv) { unimplemented("toJSString"); return null; }
|
|
|
|
JSBoolean toJSBoolean(Environment theEnv) { unimplemented("toJSBoolean"); return null; }
|
1999-04-27 02:50:50 +04:00
|
|
|
|
|
|
|
}
|