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)

x86
Windows 2000
defect
Not set
normal

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: erik, Assigned: norrisboyd)

References

Details

Attachments

(2 files, 2 obsolete files)

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.
I forgot to mention that I also tried this against the latest release version (1.5 R3) and it demonstrates the same problem.
Blocks: 181834
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");
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
Attached patch Fix for omj/Interpreter.java (obsolete) — Splinter Review
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.
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
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; }
Attachment #108193 - Attachment is obsolete: true
I commited the fix, so the bug can be marked as fixed.
Marking FIXED -
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
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
Targeting as resolved against 1.5R4
Target Milestone: --- → 1.5R4
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: