Hmmm, new changes these are.
git-svn-id: svn://10.0.0.236/trunk@32641 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -21,97 +21,97 @@ class JSValue extends ExpressionNode {
|
||||
}
|
||||
|
||||
void gt(Environment theEnv) {
|
||||
JSValue lV = toPrimitive("Number");
|
||||
JSValue rV = theEnv.theStack.pop().toPrimitive("Number");
|
||||
JSValue lV = toPrimitive(theEnv, "Number");
|
||||
JSValue rV = theEnv.theStack.pop().toPrimitive(theEnv, "Number");
|
||||
if ((lV instanceof JSString) && (rV instanceof JSString)) {
|
||||
theEnv.theStack.push(rV);
|
||||
lV.gt(theEnv);
|
||||
}
|
||||
else {
|
||||
theEnv.theStack.push(rV.toJSDouble());
|
||||
lV.toJSDouble().gt(theEnv);
|
||||
theEnv.theStack.push(rV.toJSDouble(theEnv));
|
||||
lV.toJSDouble(theEnv).gt(theEnv);
|
||||
}
|
||||
}
|
||||
|
||||
void ge(Environment theEnv) {
|
||||
JSValue lV = toPrimitive("Number");
|
||||
JSValue rV = theEnv.theStack.pop().toPrimitive("Number");
|
||||
JSValue lV = toPrimitive(theEnv, "Number");
|
||||
JSValue rV = theEnv.theStack.pop().toPrimitive(theEnv, "Number");
|
||||
if ((lV instanceof JSString) && (rV instanceof JSString)) {
|
||||
theEnv.theStack.push(rV);
|
||||
lV.ge(theEnv);
|
||||
}
|
||||
else {
|
||||
theEnv.theStack.push(rV.toJSDouble());
|
||||
lV.toJSDouble().ge(theEnv);
|
||||
theEnv.theStack.push(rV.toJSDouble(theEnv));
|
||||
lV.toJSDouble(theEnv).ge(theEnv);
|
||||
}
|
||||
}
|
||||
|
||||
void lt(Environment theEnv) {
|
||||
JSValue lV = toPrimitive("Number");
|
||||
JSValue rV = theEnv.theStack.pop().toPrimitive("Number");
|
||||
JSValue lV = toPrimitive(theEnv, "Number");
|
||||
JSValue rV = theEnv.theStack.pop().toPrimitive(theEnv, "Number");
|
||||
if ((lV instanceof JSString) && (rV instanceof JSString)) {
|
||||
theEnv.theStack.push(rV);
|
||||
lV.lt(theEnv);
|
||||
}
|
||||
else {
|
||||
theEnv.theStack.push(rV.toJSDouble());
|
||||
lV.toJSDouble().lt(theEnv);
|
||||
theEnv.theStack.push(rV.toJSDouble(theEnv));
|
||||
lV.toJSDouble(theEnv).lt(theEnv);
|
||||
}
|
||||
}
|
||||
|
||||
void le(Environment theEnv) {
|
||||
JSValue lV = toPrimitive("Number");
|
||||
JSValue rV = theEnv.theStack.pop().toPrimitive("Number");
|
||||
JSValue lV = toPrimitive(theEnv, "Number");
|
||||
JSValue rV = theEnv.theStack.pop().toPrimitive(theEnv, "Number");
|
||||
if ((lV instanceof JSString) && (rV instanceof JSString)) {
|
||||
theEnv.theStack.push(rV);
|
||||
lV.le(theEnv);
|
||||
}
|
||||
else {
|
||||
theEnv.theStack.push(rV.toJSDouble());
|
||||
lV.toJSDouble().le(theEnv);
|
||||
theEnv.theStack.push(rV.toJSDouble(theEnv));
|
||||
lV.toJSDouble(theEnv).le(theEnv);
|
||||
}
|
||||
}
|
||||
|
||||
void eq(Environment theEnv) {
|
||||
JSValue lV = toPrimitive("Number");
|
||||
JSValue rV = theEnv.theStack.pop().toPrimitive("Number");
|
||||
JSValue lV = toPrimitive(theEnv, "Number");
|
||||
JSValue rV = theEnv.theStack.pop().toPrimitive(theEnv, "Number");
|
||||
if ((lV instanceof JSString) && (rV instanceof JSString)) {
|
||||
theEnv.theStack.push(rV);
|
||||
lV.eq(theEnv);
|
||||
}
|
||||
else {
|
||||
theEnv.theStack.push(rV.toJSDouble());
|
||||
lV.toJSDouble().eq(theEnv);
|
||||
theEnv.theStack.push(rV.toJSDouble(theEnv));
|
||||
lV.toJSDouble(theEnv).eq(theEnv);
|
||||
}
|
||||
}
|
||||
|
||||
void ne(Environment theEnv) {
|
||||
JSValue lV = toPrimitive("Number");
|
||||
JSValue rV = theEnv.theStack.pop().toPrimitive("Number");
|
||||
JSValue lV = toPrimitive(theEnv, "Number");
|
||||
JSValue rV = theEnv.theStack.pop().toPrimitive(theEnv, "Number");
|
||||
if ((lV instanceof JSString) && (rV instanceof JSString)) {
|
||||
theEnv.theStack.push(rV);
|
||||
lV.ne(theEnv);
|
||||
}
|
||||
else {
|
||||
theEnv.theStack.push(rV.toJSDouble());
|
||||
lV.toJSDouble().ne(theEnv);
|
||||
theEnv.theStack.push(rV.toJSDouble(theEnv));
|
||||
lV.toJSDouble(theEnv).ne(theEnv);
|
||||
}
|
||||
}
|
||||
|
||||
void plus(Environment theEnv) {
|
||||
toJSDouble().plus(theEnv);
|
||||
toJSDouble(theEnv).plus(theEnv);
|
||||
}
|
||||
|
||||
void minus(Environment theEnv) {
|
||||
toJSDouble().minus(theEnv);
|
||||
toJSDouble(theEnv).minus(theEnv);
|
||||
}
|
||||
|
||||
void twiddle(Environment theEnv) {
|
||||
toJSInteger().twiddle(theEnv);
|
||||
toJSInteger(theEnv).twiddle(theEnv);
|
||||
}
|
||||
|
||||
void bang(Environment theEnv) {
|
||||
toJSBoolean().bang(theEnv);
|
||||
toJSBoolean(theEnv).bang(theEnv);
|
||||
}
|
||||
|
||||
void typeof(Environment theEnv) {
|
||||
@@ -119,82 +119,138 @@ class JSValue extends ExpressionNode {
|
||||
}
|
||||
|
||||
void add(Environment theEnv) {
|
||||
JSValue lV = toPrimitive("");
|
||||
JSValue rV = theEnv.theStack.pop().toPrimitive("");
|
||||
JSValue lV = toPrimitive(theEnv, "");
|
||||
JSValue rV = theEnv.theStack.pop().toPrimitive(theEnv, "");
|
||||
if ((lV instanceof JSString) || (rV instanceof JSString)) {
|
||||
theEnv.theStack.push(rV);
|
||||
lV.ne(theEnv);
|
||||
}
|
||||
else {
|
||||
theEnv.theStack.push(rV.toJSDouble());
|
||||
lV.toJSDouble().add(theEnv);
|
||||
theEnv.theStack.push(rV.toJSDouble(theEnv));
|
||||
lV.toJSDouble(theEnv).add(theEnv);
|
||||
}
|
||||
}
|
||||
|
||||
void subtract(Environment theEnv) {
|
||||
theEnv.theStack.push(theEnv.theStack.pop().toJSDouble());
|
||||
toJSDouble().subtract(theEnv);
|
||||
theEnv.theStack.push(theEnv.theStack.pop().toJSDouble(theEnv));
|
||||
toJSDouble(theEnv).subtract(theEnv);
|
||||
}
|
||||
|
||||
void multiply(Environment theEnv) {
|
||||
theEnv.theStack.push(theEnv.theStack.pop().toJSDouble());
|
||||
toJSDouble().multiply(theEnv);
|
||||
theEnv.theStack.push(theEnv.theStack.pop().toJSDouble(theEnv));
|
||||
toJSDouble(theEnv).multiply(theEnv);
|
||||
}
|
||||
|
||||
void divide(Environment theEnv) {
|
||||
theEnv.theStack.push(theEnv.theStack.pop().toJSDouble());
|
||||
toJSDouble().divide(theEnv);
|
||||
theEnv.theStack.push(theEnv.theStack.pop().toJSDouble(theEnv));
|
||||
toJSDouble(theEnv).divide(theEnv);
|
||||
}
|
||||
|
||||
void remainder(Environment theEnv) {
|
||||
theEnv.theStack.push(theEnv.theStack.pop().toJSDouble());
|
||||
toJSDouble().remainder(theEnv);
|
||||
theEnv.theStack.push(theEnv.theStack.pop().toJSDouble(theEnv));
|
||||
toJSDouble(theEnv).remainder(theEnv);
|
||||
}
|
||||
|
||||
void and(Environment theEnv) {
|
||||
theEnv.theStack.push(theEnv.theStack.pop().toJSInteger());
|
||||
toJSInteger().and(theEnv);
|
||||
theEnv.theStack.push(theEnv.theStack.pop().toJSInteger(theEnv));
|
||||
toJSInteger(theEnv).and(theEnv);
|
||||
}
|
||||
|
||||
void or(Environment theEnv) {
|
||||
theEnv.theStack.push(theEnv.theStack.pop().toJSInteger());
|
||||
toJSInteger().or(theEnv);
|
||||
theEnv.theStack.push(theEnv.theStack.pop().toJSInteger(theEnv));
|
||||
toJSInteger(theEnv).or(theEnv);
|
||||
}
|
||||
|
||||
void xor(Environment theEnv) {
|
||||
theEnv.theStack.push(theEnv.theStack.pop().toJSInteger());
|
||||
toJSInteger().xor(theEnv);
|
||||
theEnv.theStack.push(theEnv.theStack.pop().toJSInteger(theEnv));
|
||||
toJSInteger(theEnv).xor(theEnv);
|
||||
}
|
||||
|
||||
void shl(Environment theEnv) {
|
||||
theEnv.theStack.push(theEnv.theStack.pop().toJSInteger());
|
||||
toJSInteger().shl(theEnv);
|
||||
theEnv.theStack.push(theEnv.theStack.pop().toJSInteger(theEnv));
|
||||
toJSInteger(theEnv).shl(theEnv);
|
||||
}
|
||||
|
||||
void shr(Environment theEnv) {
|
||||
theEnv.theStack.push(theEnv.theStack.pop().toJSInteger());
|
||||
toJSInteger().shr(theEnv);
|
||||
theEnv.theStack.push(theEnv.theStack.pop().toJSInteger(theEnv));
|
||||
toJSInteger(theEnv).shr(theEnv);
|
||||
}
|
||||
|
||||
void ushl(Environment theEnv) {
|
||||
theEnv.theStack.push(theEnv.theStack.pop().toJSInteger());
|
||||
toJSInteger().ushl(theEnv);
|
||||
theEnv.theStack.push(theEnv.theStack.pop().toJSInteger(theEnv));
|
||||
toJSInteger(theEnv).ushl(theEnv);
|
||||
}
|
||||
|
||||
void getProp(Environment theEnv) {
|
||||
unimplemented("getProp");
|
||||
toJSObject(theEnv).getProp(theEnv);
|
||||
}
|
||||
|
||||
void putProp(Environment theEnv) {
|
||||
unimplemented("putProp");
|
||||
toJSObject(theEnv).putProp(theEnv);
|
||||
}
|
||||
|
||||
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")) {
|
||||
theEnv.theStack.push(new JSString("toString"));
|
||||
getProp(theEnv);
|
||||
v = theEnv.theStack.pop();
|
||||
if (v instanceof JSObject) {
|
||||
// invoke 'v.Call' with 'this' as the JS this
|
||||
}
|
||||
else {
|
||||
theEnv.theStack.push(new JSString("valueOf"));
|
||||
getProp(theEnv);
|
||||
v = theEnv.theStack.pop();
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
JSDouble toJSDouble() { unimplemented("toJSDouble"); return null; }
|
||||
JSInteger toJSInteger() { unimplemented("toJSInteger"); return null; }
|
||||
JSString toJSString() { unimplemented("toJSString"); return null; }
|
||||
JSBoolean toJSBoolean() { unimplemented("toJSBoolean"); return null; }
|
||||
JSValue toPrimitive(String hint) { unimplemented("toPrimitive"); return null; }
|
||||
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; }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user