Closed Bug 173906 Opened 23 years ago Closed 23 years ago

Dynamic scope not working correctly with optimzation level >= 1

Categories

(Rhino Graveyard :: Compiler, defect)

PowerPC
macOS
defect
Not set
normal

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: hannesw, Assigned: norrisboyd)

Details

Attachments

(2 files)

User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; de-AT; rv:1.1) Gecko/20020826 Build Identifier: When optimization is set to 1 or higher, per-thread dynamic scopes stop working as soon as more than one nested function is executed. This means that as soon as I have one function calling another, variables will be looked up in the shared scope only instead of the per-thread scope. I'm seeing this using both Rhino 1.5_R3 and the latest CVS version, running on JDK 1.3.1 on Mac OS X. The bug is reproducable with a slightly modified version of examples/DynamicScopes.java. (I'm also attaching the modified source file.) --- DynamicScopes.java.orig Fri Oct 11 11:03:13 2002 +++ DynamicScopes.java Fri Oct 11 11:04:27 2002 @@ -63,6 +63,7 @@ throws JavaScriptException { Context cx = Context.enter(); + cx.setOptimizationLevel(1); try { cx.setCompileFunctionsWithDynamicScope(false); runScripts(cx); @@ -84,7 +85,8 @@ // Now we can evaluate a script and functions will be compiled to // use dynamic scope if the Context is so initialized. String source = "var x = 'sharedScope';" + - "function f() { return x; }"; + "function f() { return f2(); }" + + "function f2() { return x; }"; cx.evaluateString(scope, source, "MySource", 1, null); // Now we spawn some threads that execute a script that calls the Reproducible: Always Steps to Reproduce: 1. Run the modified version of DynamicScopes.java Actual Results: sharedScope sharedScope sharedScope sharedScope sharedScope sharedScope Expected Results: sharedScope sharedScope sharedScope thread1 thread0 thread2
cc'ing Igor -
The patch fixes the reported problem but as currently there are no tests for dynamic scope mode I need at leat a confirmation that the patch works as expected from a real-life Rhino usage.
Thanks Igor, I just checked it out with some pretty complex Java/JavaScript combination and everything works fine now (same results with optimization turned on and off).
I commited the patch
Based on Hannes' findings in Comment #4, marking FIXED
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
And marking Verified -
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

Created:
Updated:
Size: