Don't let Undefined prototype be assigned to new objects, revert to Object

instead. Also, detect Undefined prototype in hasInstance and bail.


git-svn-id: svn://10.0.0.236/trunk@55123 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
rogerl%netscape.com 1999-12-03 00:10:36 +00:00
parent 498dc1681d
commit 9abcd79da8
2 changed files with 30 additions and 18 deletions

View File

@ -114,16 +114,20 @@ public class NativeFunction extends ScriptableObject implements Function {
FlattenedObject flat = new FlattenedObject(this);
Object protoProp = flat.getProperty("prototype");
try {
protoProp = ((FlattenedObject)protoProp).getObject();
} catch (ClassCastException e) {
Object[] args = { names[0] };
throw Context.reportRuntimeError(Context.getMessage
("msg.instanceof.bad.prototype", args));
if ((protoProp instanceof Scriptable)
&& (protoProp != Undefined.instance)) {
try {
protoProp = ((FlattenedObject)protoProp).getObject();
return ScriptRuntime.jsDelegatesTo(instance, (Scriptable)protoProp);
} catch (ClassCastException e) { }
}
Object[] args = { names[0] };
throw NativeGlobal.constructError(
Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.instanceof.bad.prototype", args),
instance);
return ScriptRuntime.jsDelegatesTo(instance, (Scriptable)protoProp);
}
/**
@ -138,7 +142,9 @@ public class NativeFunction extends ScriptableObject implements Function {
protected Scriptable getClassPrototype() {
Object protoVal = get("prototype", this);
if (protoVal == null || !(protoVal instanceof Scriptable))
if (protoVal == null
|| !(protoVal instanceof Scriptable)
|| (protoVal == Undefined.instance))
protoVal = getClassPrototype(this, "Object");
return (Scriptable) protoVal;
}

View File

@ -114,16 +114,20 @@ public class NativeFunction extends ScriptableObject implements Function {
FlattenedObject flat = new FlattenedObject(this);
Object protoProp = flat.getProperty("prototype");
try {
protoProp = ((FlattenedObject)protoProp).getObject();
} catch (ClassCastException e) {
Object[] args = { names[0] };
throw Context.reportRuntimeError(Context.getMessage
("msg.instanceof.bad.prototype", args));
if ((protoProp instanceof Scriptable)
&& (protoProp != Undefined.instance)) {
try {
protoProp = ((FlattenedObject)protoProp).getObject();
return ScriptRuntime.jsDelegatesTo(instance, (Scriptable)protoProp);
} catch (ClassCastException e) { }
}
Object[] args = { names[0] };
throw NativeGlobal.constructError(
Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.instanceof.bad.prototype", args),
instance);
return ScriptRuntime.jsDelegatesTo(instance, (Scriptable)protoProp);
}
/**
@ -138,7 +142,9 @@ public class NativeFunction extends ScriptableObject implements Function {
protected Scriptable getClassPrototype() {
Object protoVal = get("prototype", this);
if (protoVal == null || !(protoVal instanceof Scriptable))
if (protoVal == null
|| !(protoVal instanceof Scriptable)
|| (protoVal == Undefined.instance))
protoVal = getClassPrototype(this, "Object");
return (Scriptable) protoVal;
}