[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    tests/khtmltests/regression/tests/js
From:       Maks Orlovich <maksim () kde ! org>
Date:       2008-06-29 19:18:53
Message-ID: 1214767133.869976.5301.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 826070 by orlovich:

Regression tests for #108538


 M  +41 -0     scope.js  
 M  +21 -0     sequencing.js  


--- trunk/tests/khtmltests/regression/tests/js/scope.js #826069:826070
@@ -69,4 +69,45 @@
 
 shouldBe('y', '42');
 
+//# 108538 -- bind var assignments are proper assignments, not statically
+function testVarInCatch()
+{
+   try {
+      throw "any exception";
+   } catch (x) { 
+      var x = 2; // The catches scope is on of the chain, so
+                 // this should assign there
+      if (x != 2)
+        return "FAIL";
+   }
+
+   // Now we should touch the normal local, which should be unchanged.
+   if (x == undefined)
+      return "PASS";
+   else
+      return "FAIL #2";
+}
+
+shouldBe('testVarInCatch()', '"PASS"');
+
+function testVarInWith()
+{
+   o = { x: 42 };
+   with (o) {
+      if (x != 42)
+        return "FAIL"; // Should lookup from 'o'.
+      var x = 4; // Since o is in scope, should set there, not global.
+      if (x != 4)
+        return "FAIL #2";
+      if (o.x != 4)
+        return "FAIL #3";
+   }
+   if (x != undefined)
+      return "FAIL #4";
+
+   return "PASS";
+}
+
+shouldBe('testVarInWith()', '"PASS"');
+
 debug("Done.");
--- trunk/tests/khtmltests/regression/tests/js/sequencing.js #826069:826070
@@ -116,5 +116,26 @@
 shouldBe("out", "1234");
 
 
+// Like assignment, 'var' binds the scope before doing evaluation
+// So make sure it gets it right. eval can't inject a new variable here, so use catch/with capture.
+function varScopeTest1() {
+    var capturer = { captureInject: function(val) { this.local = val; return "ret:" + val; } }
+
+    with (capturer) {
+        // This should write to the activation's local.
+        var local = captureInject(42);
+    }
+
+    if (local != "ret:42")
+        return "FAIL";
+
+    if (capturer.local != 42)
+        return "FAIL #2";
+
+    return "PASS";
+}
+
+shouldBe("varScopeTest1()", "'PASS'");
+
 debug("Done.");
 // kate: indent-width 4; replace-tabs on; tab-width 4; space-indent on;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic