Mucking about with stuff.

This commit is contained in:
rogerl%netscape.com 1999-06-11 23:05:16 +00:00
parent 5b9a8f1310
commit f25d7b5229
5 changed files with 27 additions and 13 deletions

View File

@ -3,7 +3,12 @@ import java.util.Hashtable;
class Environment {
JSObject scope = new JSObject("globals");
JSObject scope = new JSObject("globals", null);
void enterNewScope(JSObject newScope)
{
}
String print()
{

View File

@ -81,15 +81,15 @@ primary_expression[boolean initial] returns [ExpressionNode e]
simple_expression returns [ExpressionNode e]
{ e = null; }
: "null" { e = new JSObject("null"); }
: "null" { e = new JSObject("null", null); } // XXX
| "true" { e = JSBoolean.JSTrue; }
| "false" { e = JSBoolean.JSFalse; }
| opN:NUMBER { e = new JSDouble(opN.getText()); }
| opS:STRING { e = new JSString(opS.getText()); }
| "this" { e = new JSObject("this"); }
| "super" { e = new JSObject("super"); }
| "this" { e = new JSObject("this", null); } // XXX
| "super" { e = new JSObject("super", null); } // XXX
| e = qualified_identifier_or_parenthesized_expression[true]
| opR:REGEXP { e = new JSObject(opR.getText()); }
| opR:REGEXP { e = new JSObject(opR.getText(), null); } // XXX
| e = array_literal
;

View File

@ -3,11 +3,12 @@ import java.util.Hashtable;
class JSObject extends JSValue {
static JSObject JSUndefined = new JSObject("undefined");
static JSObject JSUndefined = new JSObject("undefined", null);
JSObject(String aValue)
JSObject(String aValue, JSObject aPrototype)
{
value = aValue;
prototype = aPrototype;
}
String print(String indent)
@ -38,9 +39,17 @@ class JSObject extends JSValue {
JSDouble toJSDouble(Environment theEnv) {
return toPrimitive(theEnv, "Number").toJSDouble(theEnv);
}
JSValue getProp(Environment theEnv, JSString id) {
return (JSValue)(contents.get(id.s));
JSValue getProp(Environment theEnv, JSString id)
{
Object v = contents.get(id.s);
if (v == null)
if (prototype == null)
return JSUndefined;
else
return prototype.getProp(theEnv, id);
else
return (JSValue)v;
}
JSValue putProp(Environment theEnv, JSString id, JSValue rV) {
@ -53,4 +62,5 @@ class JSObject extends JSValue {
String value;
JSObject prototype;
}

View File

@ -2,7 +2,7 @@ class NativeFunction extends JSObject {
NativeFunction(ControlNode aBody)
{
super("Function");
super("Function", null);
body = aBody;
}
@ -14,7 +14,6 @@ class NativeFunction extends JSObject {
return theEnv.resultValue;
}
ControlNode body;
}

View File

@ -1,7 +1,7 @@
class NativeNumber extends JSObject {
NativeNumber(double p) {
super("Number");
super("Number", null);
d = p;
}