From 7b30a5de9944ea644a556b9b7a7e71b3f57d4ff7 Mon Sep 17 00:00:00 2001 From: "igor%mir2.org" Date: Wed, 9 Jun 2004 17:01:01 +0000 Subject: [PATCH] Fixing regression after previous commit for bug 245882: when used as top scope ImporterTopLevel should not define constructor property not to hide Object.prototype.constructor. --- .../mozilla/javascript/ImporterTopLevel.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/js/rhino/src/org/mozilla/javascript/ImporterTopLevel.java b/js/rhino/src/org/mozilla/javascript/ImporterTopLevel.java index 9a8fa413cb5..a577871729e 100644 --- a/js/rhino/src/org/mozilla/javascript/ImporterTopLevel.java +++ b/js/rhino/src/org/mozilla/javascript/ImporterTopLevel.java @@ -100,10 +100,16 @@ public class ImporterTopLevel extends IdScriptable { cx.initStandardObjects(this, sealed); prototypeFlag = true; - addAsPrototype(MAX_PROTOTYPE_ID, cx, this, sealed); - // set the flag after IdScriptable.addAsPrototype() calls - // getClassName() to get constructor name right. topScopeFlag = true; + // topScopeFlag hides constructor property so constructor name + // would refer to constructor property in the prototype of the scope + // and not to JavaImporter.prototype.constructor. + // For this reason addAsPrototype can not be used to replace + // the following 4 lines as it requires to have id for "constructor". + setMaxId(MAX_PROTOTYPE_ID); + IdFunction ctor = newIdFunction("JavaImporter", Id_constructor, this); + ctor.markAsConstructor(this); + ctor.exportAsScopeProperty(sealed); } public boolean has(String name, Scriptable start) { @@ -291,6 +297,11 @@ public class ImporterTopLevel extends IdScriptable if (X!=null && X!=s && !X.equals(s)) id = 0; } // #/generated# + + if (id == Id_constructor && topScopeFlag) { + // see comments in initStandardObjects + id = 0; + } return id; }