2006-04-18 Eric Seidel <eseidel@apple.com>
authoreseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Apr 2006 22:17:41 +0000 (22:17 +0000)
committereseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Apr 2006 22:17:41 +0000 (22:17 +0000)
        Reviewed by ggaren.

        Fix "new Function()" to correctly use lexical scoping.
        Add ScopeChain::print() function for debugging.
        <rdar://problem/4067864> REGRESSION (125-407): JavaScript failure on PeopleSoft REN Server

        * kjs/function_object.cpp:
        (FunctionObjectImp::construct):
        * kjs/scope_chain.cpp:
        (KJS::ScopeChain::print):
        * kjs/scope_chain.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@13960 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/kjs/function_object.cpp
JavaScriptCore/kjs/scope_chain.cpp
JavaScriptCore/kjs/scope_chain.h
LayoutTests/ChangeLog
LayoutTests/fast/js/lexical-lookup-in-function-constructor-expected.txt [new file with mode: 0644]
LayoutTests/fast/js/lexical-lookup-in-function-constructor.html [new file with mode: 0644]
LayoutTests/fast/js/resources/lexical-lookup-in-function-constructor-child.html [new file with mode: 0644]

index fbbd1f9..af6d8c7 100644 (file)
@@ -1,3 +1,17 @@
+2006-04-18  Eric Seidel  <eseidel@apple.com>
+
+        Reviewed by ggaren.
+
+        Fix "new Function()" to correctly use lexical scoping.
+        Add ScopeChain::print() function for debugging.
+        <rdar://problem/4067864> REGRESSION (125-407): JavaScript failure on PeopleSoft REN Server
+
+        * kjs/function_object.cpp:
+        (FunctionObjectImp::construct):
+        * kjs/scope_chain.cpp:
+        (KJS::ScopeChain::print):
+        * kjs/scope_chain.h:
+
 2006-04-14  James G. Speth  <speth@end.com>
 
         Reviewed by Timothy.
index d11012c..219b38d 100644 (file)
@@ -204,7 +204,7 @@ JSObject* FunctionObjectImp::construct(ExecState* exec, const List& args, const
     return throwError(exec, SyntaxError, errMsg, errLine, sid, &sourceURL);
 
   ScopeChain scopeChain;
-  scopeChain.push(exec->dynamicInterpreter()->globalObject());
+  scopeChain.push(exec->lexicalInterpreter()->globalObject());
   FunctionBodyNode *bodyNode = progNode.get();
 
   FunctionImp* fimp = new DeclaredFunctionImp(exec, functionName, bodyNode, scopeChain);
index 229fc22..72ad595 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "config.h"
 #include "scope_chain.h"
+#include "reference_list.h"
 
 namespace KJS {
 
@@ -34,4 +35,25 @@ void ScopeChain::push(const ScopeChain &c)
     }
 }
 
+#ifndef NDEBUG
+
+void ScopeChain::print(ExecState* exec)
+{
+    ScopeChainIterator scopeEnd = end();
+    for (ScopeChainIterator scopeIter = begin(); scopeIter != scopeEnd; ++scopeIter) {
+        JSObject* o = *scopeIter;
+        ReferenceList propList = o->propList(exec, false);
+        ReferenceListIterator propEnd = propList.end();
+
+        fprintf(stderr, "----- [scope %p] -----\n", o);
+        for (ReferenceListIterator propIter = propList.begin(); propIter != propEnd; propIter++) {
+            Identifier name = propIter->getPropertyName(exec);
+            fprintf(stderr, "%s, ", name.ascii());
+        }
+        fprintf(stderr, "\n");
+    }
+}
+
+#endif
+
 } // namespace KJS
index 421fdfa..f227dac 100644 (file)
@@ -27,6 +27,7 @@
 namespace KJS {
 
     class JSObject;
+    class ExecState;
     
     class ScopeChainNode {
     public:
@@ -79,6 +80,10 @@ namespace KJS {
         void pop();
         
         void mark();
+
+#ifndef NDEBUG        
+        void print(ExecState*);
+#endif
         
     private:
         ScopeChainNode *_node;
index a596b85..809f491 100644 (file)
@@ -1,3 +1,13 @@
+2006-04-18  Eric Seidel  <eseidel@apple.com>
+
+        Reviewed by ggaren.
+
+        <rdar://problem/4067864> REGRESSION (125-407): JavaScript failure on PeopleSoft REN Server
+
+        * fast/js/lexical-lookup-in-function-constructor.html: Added.
+        * fast/js/resources/lexical-lookup-in-function-constructor-child.html: Added.
+        * fast/js/lexical-lookup-in-function-constructor-expected.txt: Added.
+
 2006-04-18  Beth Dakin  <bdakin@apple.com>
 
         Reviewed by Hyatt
diff --git a/LayoutTests/fast/js/lexical-lookup-in-function-constructor-expected.txt b/LayoutTests/fast/js/lexical-lookup-in-function-constructor-expected.txt
new file mode 100644 (file)
index 0000000..86aefce
--- /dev/null
@@ -0,0 +1,3 @@
+SUCCESS
+
+
diff --git a/LayoutTests/fast/js/lexical-lookup-in-function-constructor.html b/LayoutTests/fast/js/lexical-lookup-in-function-constructor.html
new file mode 100644 (file)
index 0000000..feeff28
--- /dev/null
@@ -0,0 +1,14 @@
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+message = "FAILURE (Bad lookup)";
+function doTest() {
+    var para = document.getElementById("test");
+    frames[0].doTest(para);
+}
+</script>
+<body onLoad="doTest()">
+<p id="test">FAILURE (Didn't execute)</p>
+<iframe src="resources/lexical-lookup-in-function-constructor-child.html"></iframe>
+</body>
diff --git a/LayoutTests/fast/js/resources/lexical-lookup-in-function-constructor-child.html b/LayoutTests/fast/js/resources/lexical-lookup-in-function-constructor-child.html
new file mode 100644 (file)
index 0000000..ec10581
--- /dev/null
@@ -0,0 +1,10 @@
+<script>
+message = "SUCCESS";
+function doTest(para) {
+    var f = new Function('para', 'para.innerHTML = message;');
+    f(para);
+}
+</script>
+<body>
+</body>
+