Closed
Bug 154693
Opened 23 years ago
Closed 23 years ago
Interpreted mode doesn't grok different functions on different objects
Categories
(Rhino Graveyard :: Core, defect)
Tracking
(Not tracked)
VERIFIED
FIXED
1.5R4
People
(Reporter: erik, Assigned: norrisboyd)
References
Details
Attachments
(2 files, 2 obsolete files)
795 bytes,
text/plain
|
Details | |
2.22 KB,
patch
|
Details | Diff | Splinter Review |
I have a script where I define a function on an object, I construct the object
twice and then Rhino thinks that the the functions in the two different objects
are identical. This only occurs in interpretted mode
(Context.setOptimizationLevel(-1)). I'll attach a test case to demonstrate the
problem.
![]() |
Reporter | |
Comment 1•23 years ago
|
||
![]() |
Reporter | |
Comment 2•23 years ago
|
||
I forgot to mention that I also tried this against the latest release version
(1.5 R3) and it demonstrates the same problem.
![]() |
||
Comment 3•23 years ago
|
||
Here is a simpler example to expose the problem in Rhino shell:
function f() {
function nested() { }
return nested;
}
var f1 = f();
var f2 = f();
var ok = (f1 != f2);
print(ok ? "GOOD" : "BAD");
![]() |
||
Comment 4•23 years ago
|
||
Igor: thank you for this test! I have added it to the JS testsuite:
mozilla/js/tests/js1_5/Scope/regress-154693.js
It is currently passing in SpiderMonkey and Rhino compiled mode,
but failing in Rhino interpreted mode, as Erik reported -
Summary: Interpretted mode doesn't grok different functions on different objects → Interpreted mode doesn't grok different functions on different objects
![]() |
||
Comment 5•23 years ago
|
||
The reason for the bug is the current code in Interpreter.interpret that
instead of creating new InterpretedFunction for each nested function statement
on function entry, put to the activation scope a function currently stored in
InterpretedData.itsNestedFunction.
I believe the patch fixes that (Rhino passes all tests with it) but as it
removes redundant generation of CLOSURE statements for each nested function
statement, as it seems they are only needed for function expression and
function expression statements, it would be nice to here something from someone
who wrote initial code.
![]() |
||
Comment 6•23 years ago
|
||
I commited essentially cosmetics part of the previous patch as it reduces
codesize and makes a real bug fix smaller which still needs some considerations
before the commit.
Attachment #108053 -
Attachment is obsolete: true
![]() |
||
Comment 7•23 years ago
|
||
I commited another part of the patch where it removes closure icode generation
for function statements. It seems for me it was a bug on its own.
diff -u -r1.115 Interpreter.java
--- Interpreter.java 4 Dec 2002 09:49:07 -0000 1.115
+++ Interpreter.java 5 Dec 2002 20:57:58 -0000
@@ -271,13 +271,20 @@
switch (type) {
case TokenStream.FUNCTION : {
- Node fn = (Node) node.getProp(Node.FUNCTION_PROP);
- int index = fn.getExistingIntProp(Node.FUNCTION_PROP);
- iCodeTop = addByte(TokenStream.CLOSURE, iCodeTop);
- iCodeTop = addIndex(index, iCodeTop);
- itsStackDepth++;
- if (itsStackDepth > itsData.itsMaxStack)
- itsData.itsMaxStack = itsStackDepth;
+ FunctionNode fn
+ = (FunctionNode) node.getProp(Node.FUNCTION_PROP);
+ if (fn.itsFunctionType != FunctionNode.FUNCTION_STATEMENT) {
+ // Only function expressions or function expression
+ // statements needs closure code creating new function
+ // object on stack as function statements are initialized
+ // at script/function start
+ int index = fn.getExistingIntProp(Node.FUNCTION_PROP);
+ iCodeTop = addByte(TokenStream.CLOSURE, iCodeTop);
+ iCodeTop = addIndex(index, iCodeTop);
+ itsStackDepth++;
+ if (itsStackDepth > itsData.itsMaxStack)
+ itsData.itsMaxStack = itsStackDepth;
+ }
break;
}
![]() |
||
Updated•23 years ago
|
Attachment #108193 -
Attachment is obsolete: true
![]() |
||
Comment 8•23 years ago
|
||
I commited the fix, so the bug can be marked as fixed.
![]() |
||
Comment 9•23 years ago
|
||
Marking FIXED -
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
![]() |
||
Comment 10•23 years ago
|
||
Marking Verified Fixed.
The above testcase used to pass in Rhino compiled mode,
but fail in interpreted mode. Now it passes in both -
Status: RESOLVED → VERIFIED
You need to log in
before you can comment on or make changes to this bug.
Description
•