Removal of support for special handling of this for read-only methods exposed by IdScriptable under dynamic scoping. It was never used and its semantic had little to do with dynamic scoping itself.

This commit is contained in:
igor%mir2.org 2003-04-22 16:09:40 +00:00
Родитель 97d4809dd9
Коммит 27f1930196
8 изменённых файлов: 61 добавлений и 86 удалений

Просмотреть файл

@ -379,18 +379,6 @@ public abstract class IdScriptable extends ScriptableObject
setSetupFlag(SEAL_FUNCTIONS_FLAG, sealed); setSetupFlag(SEAL_FUNCTIONS_FLAG, sealed);
} }
/**
* Set parameters of function properties.
* Currently only determines whether functions should use dynamic scope.
* @param cx context to read function parameters.
*
* @see org.mozilla.javascript.Context#hasCompileFunctionsWithDynamicScope
*/
protected void setFunctionParametrs(Context cx) {
setSetupFlag(USE_DYNAMIC_SCOPE_FLAG,
cx.hasCompileFunctionsWithDynamicScope());
}
private void setSetupFlag(int flag, boolean value) { private void setSetupFlag(int flag, boolean value) {
setupFlags = (byte)(value ? setupFlags | flag : setupFlags & ~flag); setupFlags = (byte)(value ? setupFlags | flag : setupFlags & ~flag);
} }
@ -411,7 +399,6 @@ public abstract class IdScriptable extends ScriptableObject
setMaxId(maxId); setMaxId(maxId);
setSealFunctionsFlag(sealed); setSealFunctionsFlag(sealed);
setFunctionParametrs(cx);
int constructorId = mapNameToId("constructor"); int constructorId = mapNameToId("constructor");
if (constructorId == 0) { if (constructorId == 0) {
@ -471,14 +458,8 @@ public abstract class IdScriptable extends ScriptableObject
* @throws RuntimeException if no more instanceof target can be found * @throws RuntimeException if no more instanceof target can be found
*/ */
protected Scriptable nextInstanceCheck(Scriptable thisObj, protected Scriptable nextInstanceCheck(Scriptable thisObj,
IdFunction f, IdFunction f)
boolean readOnly)
{ {
if (readOnly && 0 != (setupFlags & USE_DYNAMIC_SCOPE_FLAG)) {
// for read only functions under dynamic scope look prototype chain
thisObj = thisObj.getPrototype();
if (thisObj != null) { return thisObj; }
}
throw NativeGlobal.typeError1("msg.incompat.call", throw NativeGlobal.typeError1("msg.incompat.call",
f.getFunctionName(), f); f.getFunctionName(), f);
} }
@ -572,7 +553,6 @@ public abstract class IdScriptable extends ScriptableObject
private static final boolean CACHE_NAMES = true; private static final boolean CACHE_NAMES = true;
private int lastIdCache; private int lastIdCache;
private static final int USE_DYNAMIC_SCOPE_FLAG = 1 << 0;
private static final int SEAL_FUNCTIONS_FLAG = 1 << 1; private static final int SEAL_FUNCTIONS_FLAG = 1 << 1;
private byte setupFlags; private byte setupFlags;

Просмотреть файл

@ -101,7 +101,7 @@ final class NativeBoolean extends IdScriptable {
private NativeBoolean realThis(Scriptable thisObj, IdFunction f) { private NativeBoolean realThis(Scriptable thisObj, IdFunction f) {
while (!(thisObj instanceof NativeBoolean)) { while (!(thisObj instanceof NativeBoolean)) {
thisObj = nextInstanceCheck(thisObj, f, true); thisObj = nextInstanceCheck(thisObj, f);
} }
return (NativeBoolean)thisObj; return (NativeBoolean)thisObj;
} }

Просмотреть файл

@ -163,217 +163,217 @@ final class NativeDate extends IdScriptable {
return jsConstructor(args, thisObj == null); return jsConstructor(args, thisObj == null);
case Id_toString: { case Id_toString: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
return date_format(t, FORMATSPEC_FULL); return date_format(t, FORMATSPEC_FULL);
} }
case Id_toTimeString: { case Id_toTimeString: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
return date_format(t, FORMATSPEC_TIME); return date_format(t, FORMATSPEC_TIME);
} }
case Id_toDateString: { case Id_toDateString: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
return date_format(t, FORMATSPEC_DATE); return date_format(t, FORMATSPEC_DATE);
} }
case Id_toLocaleString: { case Id_toLocaleString: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
return js_toLocaleString(t); return js_toLocaleString(t);
} }
case Id_toLocaleTimeString: { case Id_toLocaleTimeString: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
return js_toLocaleTimeString(t); return js_toLocaleTimeString(t);
} }
case Id_toLocaleDateString: { case Id_toLocaleDateString: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
return js_toLocaleDateString(t); return js_toLocaleDateString(t);
} }
case Id_toUTCString: { case Id_toUTCString: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
if (t == t) { return js_toUTCString(t); } if (t == t) { return js_toUTCString(t); }
return js_NaN_date_str; return js_NaN_date_str;
} }
case Id_valueOf: case Id_valueOf:
return wrap_double(realThis(thisObj, f, true).date); return wrap_double(realThis(thisObj, f).date);
case Id_getTime: case Id_getTime:
return wrap_double(realThis(thisObj, f, true).date); return wrap_double(realThis(thisObj, f).date);
case Id_getYear: { case Id_getYear: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
if (t == t) { t = js_getYear(cx, t); } if (t == t) { t = js_getYear(cx, t); }
return wrap_double(t); return wrap_double(t);
} }
case Id_getFullYear: { case Id_getFullYear: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
if (t == t) { t = YearFromTime(LocalTime(t)); } if (t == t) { t = YearFromTime(LocalTime(t)); }
return wrap_double(t); return wrap_double(t);
} }
case Id_getUTCFullYear: { case Id_getUTCFullYear: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
if (t == t) { t = YearFromTime(t); } if (t == t) { t = YearFromTime(t); }
return wrap_double(t); return wrap_double(t);
} }
case Id_getMonth: { case Id_getMonth: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
if (t == t) { t = MonthFromTime(LocalTime(t)); } if (t == t) { t = MonthFromTime(LocalTime(t)); }
return wrap_double(t); return wrap_double(t);
} }
case Id_getUTCMonth: { case Id_getUTCMonth: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
if (t == t) { t = MonthFromTime(t); } if (t == t) { t = MonthFromTime(t); }
return wrap_double(t); return wrap_double(t);
} }
case Id_getDate: { case Id_getDate: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
if (t == t) { t = DateFromTime(LocalTime(t)); } if (t == t) { t = DateFromTime(LocalTime(t)); }
return wrap_double(t); return wrap_double(t);
} }
case Id_getUTCDate: { case Id_getUTCDate: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
if (t == t) { t = DateFromTime(t); } if (t == t) { t = DateFromTime(t); }
return wrap_double(t); return wrap_double(t);
} }
case Id_getDay: { case Id_getDay: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
if (t == t) { t = WeekDay(LocalTime(t)); } if (t == t) { t = WeekDay(LocalTime(t)); }
return wrap_double(t); return wrap_double(t);
} }
case Id_getUTCDay: { case Id_getUTCDay: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
if (t == t) { t = WeekDay(t); } if (t == t) { t = WeekDay(t); }
return wrap_double(t); return wrap_double(t);
} }
case Id_getHours: { case Id_getHours: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
if (t == t) { t = HourFromTime(LocalTime(t)); } if (t == t) { t = HourFromTime(LocalTime(t)); }
return wrap_double(t); return wrap_double(t);
} }
case Id_getUTCHours: { case Id_getUTCHours: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
if (t == t) { t = HourFromTime(t); } if (t == t) { t = HourFromTime(t); }
return wrap_double(t); return wrap_double(t);
} }
case Id_getMinutes: { case Id_getMinutes: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
if (t == t) { t = MinFromTime(LocalTime(t)); } if (t == t) { t = MinFromTime(LocalTime(t)); }
return wrap_double(t); return wrap_double(t);
} }
case Id_getUTCMinutes: { case Id_getUTCMinutes: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
if (t == t) { t = MinFromTime(t); } if (t == t) { t = MinFromTime(t); }
return wrap_double(t); return wrap_double(t);
} }
case Id_getSeconds: { case Id_getSeconds: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
if (t == t) { t = SecFromTime(LocalTime(t)); } if (t == t) { t = SecFromTime(LocalTime(t)); }
return wrap_double(t); return wrap_double(t);
} }
case Id_getUTCSeconds: { case Id_getUTCSeconds: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
if (t == t) { t = SecFromTime(t); } if (t == t) { t = SecFromTime(t); }
return wrap_double(t); return wrap_double(t);
} }
case Id_getMilliseconds: { case Id_getMilliseconds: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
if (t == t) { t = msFromTime(LocalTime(t)); } if (t == t) { t = msFromTime(LocalTime(t)); }
return wrap_double(t); return wrap_double(t);
} }
case Id_getUTCMilliseconds: { case Id_getUTCMilliseconds: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
if (t == t) { t = msFromTime(t); } if (t == t) { t = msFromTime(t); }
return wrap_double(t); return wrap_double(t);
} }
case Id_getTimezoneOffset: { case Id_getTimezoneOffset: {
double t = realThis(thisObj, f, true).date; double t = realThis(thisObj, f).date;
if (t == t) { t = js_getTimezoneOffset(t); } if (t == t) { t = js_getTimezoneOffset(t); }
return wrap_double(t); return wrap_double(t);
} }
case Id_setTime: case Id_setTime:
return wrap_double(realThis(thisObj, f, true). return wrap_double(realThis(thisObj, f).
js_setTime(ScriptRuntime.toNumber(args, 0))); js_setTime(ScriptRuntime.toNumber(args, 0)));
case Id_setMilliseconds: case Id_setMilliseconds:
return wrap_double(realThis(thisObj, f, false). return wrap_double(realThis(thisObj, f).
makeTime(args, 1, true)); makeTime(args, 1, true));
case Id_setUTCMilliseconds: case Id_setUTCMilliseconds:
return wrap_double(realThis(thisObj, f, false). return wrap_double(realThis(thisObj, f).
makeTime(args, 1, false)); makeTime(args, 1, false));
case Id_setSeconds: case Id_setSeconds:
return wrap_double(realThis(thisObj, f, false). return wrap_double(realThis(thisObj, f).
makeTime(args, 2, true)); makeTime(args, 2, true));
case Id_setUTCSeconds: case Id_setUTCSeconds:
return wrap_double(realThis(thisObj, f, false). return wrap_double(realThis(thisObj, f).
makeTime(args, 2, false)); makeTime(args, 2, false));
case Id_setMinutes: case Id_setMinutes:
return wrap_double(realThis(thisObj, f, false). return wrap_double(realThis(thisObj, f).
makeTime(args, 3, true)); makeTime(args, 3, true));
case Id_setUTCMinutes: case Id_setUTCMinutes:
return wrap_double(realThis(thisObj, f, false). return wrap_double(realThis(thisObj, f).
makeTime(args, 3, false)); makeTime(args, 3, false));
case Id_setHours: case Id_setHours:
return wrap_double(realThis(thisObj, f, false). return wrap_double(realThis(thisObj, f).
makeTime(args, 4, true)); makeTime(args, 4, true));
case Id_setUTCHours: case Id_setUTCHours:
return wrap_double(realThis(thisObj, f, false). return wrap_double(realThis(thisObj, f).
makeTime(args, 4, false)); makeTime(args, 4, false));
case Id_setDate: case Id_setDate:
return wrap_double(realThis(thisObj, f, false). return wrap_double(realThis(thisObj, f).
makeDate(args, 1, true)); makeDate(args, 1, true));
case Id_setUTCDate: case Id_setUTCDate:
return wrap_double(realThis(thisObj, f, false). return wrap_double(realThis(thisObj, f).
makeDate(args, 1, false)); makeDate(args, 1, false));
case Id_setMonth: case Id_setMonth:
return wrap_double(realThis(thisObj, f, false). return wrap_double(realThis(thisObj, f).
makeDate(args, 2, true)); makeDate(args, 2, true));
case Id_setUTCMonth: case Id_setUTCMonth:
return wrap_double(realThis(thisObj, f, false). return wrap_double(realThis(thisObj, f).
makeDate(args, 2, false)); makeDate(args, 2, false));
case Id_setFullYear: case Id_setFullYear:
return wrap_double(realThis(thisObj, f, false). return wrap_double(realThis(thisObj, f).
makeDate(args, 3, true)); makeDate(args, 3, true));
case Id_setUTCFullYear: case Id_setUTCFullYear:
return wrap_double(realThis(thisObj, f, false). return wrap_double(realThis(thisObj, f).
makeDate(args, 3, false)); makeDate(args, 3, false));
case Id_setYear: case Id_setYear:
return wrap_double(realThis(thisObj, f, false). return wrap_double(realThis(thisObj, f).
js_setYear(ScriptRuntime.toNumber(args, 0))); js_setYear(ScriptRuntime.toNumber(args, 0)));
} }
} }
@ -381,11 +381,10 @@ final class NativeDate extends IdScriptable {
return super.execMethod(methodId, f, cx, scope, thisObj, args); return super.execMethod(methodId, f, cx, scope, thisObj, args);
} }
private NativeDate realThis(Scriptable thisObj, IdFunction f, private NativeDate realThis(Scriptable thisObj, IdFunction f)
boolean readOnly)
{ {
while (!(thisObj instanceof NativeDate)) { while (!(thisObj instanceof NativeDate)) {
thisObj = nextInstanceCheck(thisObj, f, readOnly); thisObj = nextInstanceCheck(thisObj, f);
} }
return (NativeDate)thisObj; return (NativeDate)thisObj;
} }

Просмотреть файл

@ -47,7 +47,6 @@ final class NativeMath extends IdScriptable
static void init(Context cx, Scriptable scope, boolean sealed) { static void init(Context cx, Scriptable scope, boolean sealed) {
NativeMath obj = new NativeMath(); NativeMath obj = new NativeMath();
obj.setSealFunctionsFlag(sealed); obj.setSealFunctionsFlag(sealed);
obj.setFunctionParametrs(cx);
obj.setPrototype(getObjectPrototype(scope)); obj.setPrototype(getObjectPrototype(scope));
obj.setParentScope(scope); obj.setParentScope(scope);
if (sealed) { obj.sealObject(); } if (sealed) { obj.sealObject(); }

Просмотреть файл

@ -137,7 +137,7 @@ final class NativeNumber extends IdScriptable {
private NativeNumber realThis(Scriptable thisObj, IdFunction f) { private NativeNumber realThis(Scriptable thisObj, IdFunction f) {
while (!(thisObj instanceof NativeNumber)) { while (!(thisObj instanceof NativeNumber)) {
thisObj = nextInstanceCheck(thisObj, f, true); thisObj = nextInstanceCheck(thisObj, f);
} }
return (NativeNumber)thisObj; return (NativeNumber)thisObj;
} }

Просмотреть файл

@ -112,13 +112,13 @@ public class NativeScript extends NativeFunction implements Script {
return jsConstructor(cx, scope, args); return jsConstructor(cx, scope, args);
case Id_toString: case Id_toString:
return realThis(thisObj, f, true).js_toString(cx, args); return realThis(thisObj, f).js_toString(cx, args);
case Id_exec: case Id_exec:
return realThis(thisObj, f, true).js_exec(); return realThis(thisObj, f).js_exec();
case Id_compile: case Id_compile:
return realThis(thisObj, f, false). return realThis(thisObj, f).
js_compile(cx, ScriptRuntime.toString(args, 0)); js_compile(cx, ScriptRuntime.toString(args, 0));
} }
} }
@ -126,11 +126,10 @@ public class NativeScript extends NativeFunction implements Script {
return super.execMethod(methodId, f, cx, scope, thisObj, args); return super.execMethod(methodId, f, cx, scope, thisObj, args);
} }
private NativeScript realThis(Scriptable thisObj, IdFunction f, private NativeScript realThis(Scriptable thisObj, IdFunction f)
boolean readOnly)
{ {
while (!(thisObj instanceof NativeScript)) { while (!(thisObj instanceof NativeScript)) {
thisObj = nextInstanceCheck(thisObj, f, readOnly); thisObj = nextInstanceCheck(thisObj, f);
} }
return (NativeScript)thisObj; return (NativeScript)thisObj;
} }

Просмотреть файл

@ -249,7 +249,7 @@ final class NativeString extends IdScriptable {
private NativeString realThis(Scriptable thisObj, IdFunction f) { private NativeString realThis(Scriptable thisObj, IdFunction f) {
while (!(thisObj instanceof NativeString)) { while (!(thisObj instanceof NativeString)) {
thisObj = nextInstanceCheck(thisObj, f, true); thisObj = nextInstanceCheck(thisObj, f);
} }
return (NativeString)thisObj; return (NativeString)thisObj;
} }

Просмотреть файл

@ -133,7 +133,6 @@ public class NativeRegExp extends IdScriptable implements Function {
proto.prototypeFlag = true; proto.prototypeFlag = true;
proto.setMaxId(MAX_PROTOTYPE_ID); proto.setMaxId(MAX_PROTOTYPE_ID);
proto.setSealFunctionsFlag(sealed); proto.setSealFunctionsFlag(sealed);
proto.setFunctionParametrs(cx);
proto.setParentScope(scope); proto.setParentScope(scope);
proto.setPrototype(getObjectPrototype(scope)); proto.setPrototype(getObjectPrototype(scope));
@ -2700,29 +2699,28 @@ System.out.println("Testing at " + x.cp + ", op = " + op);
if (prototypeFlag) { if (prototypeFlag) {
switch (methodId) { switch (methodId) {
case Id_compile: case Id_compile:
return realThis(thisObj, f, false).compile(cx, scope, args); return realThis(thisObj, f).compile(cx, scope, args);
case Id_toString: case Id_toString:
return realThis(thisObj, f, true).toString(); return realThis(thisObj, f).toString();
case Id_exec: case Id_exec:
return realThis(thisObj, f, false).exec(cx, scope, args); return realThis(thisObj, f).exec(cx, scope, args);
case Id_test: case Id_test:
return realThis(thisObj, f, false).test(cx, scope, args); return realThis(thisObj, f).test(cx, scope, args);
case Id_prefix: case Id_prefix:
return realThis(thisObj, f, false).prefix(cx, scope, args); return realThis(thisObj, f).prefix(cx, scope, args);
} }
} }
return super.execMethod(methodId, f, cx, scope, thisObj, args); return super.execMethod(methodId, f, cx, scope, thisObj, args);
} }
private NativeRegExp realThis(Scriptable thisObj, IdFunction f, private NativeRegExp realThis(Scriptable thisObj, IdFunction f)
boolean readOnly)
{ {
while (!(thisObj instanceof NativeRegExp)) { while (!(thisObj instanceof NativeRegExp)) {
thisObj = nextInstanceCheck(thisObj, f, readOnly); thisObj = nextInstanceCheck(thisObj, f);
} }
return (NativeRegExp)thisObj; return (NativeRegExp)thisObj;
} }