From 9abcd79da8b5bba323089dc6aa50ea6f64e63cd6 Mon Sep 17 00:00:00 2001 From: "rogerl%netscape.com" Date: Fri, 3 Dec 1999 00:10:36 +0000 Subject: [PATCH] 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 --- .../mozilla/javascript/NativeFunction.java | 24 ++++++++++++------- .../mozilla/javascript/NativeFunction.java | 24 ++++++++++++------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/mozilla/js/rhino/org/mozilla/javascript/NativeFunction.java b/mozilla/js/rhino/org/mozilla/javascript/NativeFunction.java index 92cf240f646..6f2d04986f3 100644 --- a/mozilla/js/rhino/org/mozilla/javascript/NativeFunction.java +++ b/mozilla/js/rhino/org/mozilla/javascript/NativeFunction.java @@ -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; } diff --git a/mozilla/js/rhino/src/org/mozilla/javascript/NativeFunction.java b/mozilla/js/rhino/src/org/mozilla/javascript/NativeFunction.java index 92cf240f646..6f2d04986f3 100644 --- a/mozilla/js/rhino/src/org/mozilla/javascript/NativeFunction.java +++ b/mozilla/js/rhino/src/org/mozilla/javascript/NativeFunction.java @@ -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; }