Index: test/mjsunit/const-redecl.js |
diff --git a/test/mjsunit/const-redecl.js b/test/mjsunit/const-redecl.js |
index c0b97e6ced14c90b57b5226e87a8e35352bf621f..f311f0de66d81d3a710297d35fac87cd41a206be 100644 |
--- a/test/mjsunit/const-redecl.js |
+++ b/test/mjsunit/const-redecl.js |
@@ -49,37 +49,6 @@ function TestLocal(s,e) { |
} |
-// NOTE: TestGlobal usually only tests the given string in the context |
-// of a global object in dictionary mode. This is because we use |
-// delete to get rid of any added properties. |
-function TestGlobal(s,e) { |
- // Collect the global properties before the call. |
- var properties = []; |
- for (var key in this) properties.push(key); |
- // Compute the result. |
- var result; |
- try { |
- var code = s + (e ? "; $$$result=" + e : ""); |
- if (this.execScript) { |
- execScript(code); |
- } else { |
- this.eval(code); |
- } |
- // Avoid issues if $$$result is not defined by |
- // reading it through this. |
- result = this.$$$result; |
- } catch (x) { |
- result = CheckException(x); |
- } |
- // Get rid of any introduced global properties before |
- // returning the result. |
- for (var key in this) { |
- if (properties.indexOf(key) == -1) delete this[key]; |
- } |
- return result; |
-} |
- |
- |
function TestContext(s,e) { |
try { |
// Use a with-statement to force the system to do dynamic |
@@ -98,8 +67,6 @@ function TestAll(expected,s,opt_e) { |
var msg = s; |
if (opt_e) { e = opt_e; msg += "; " + opt_e; } |
assertEquals(expected, TestLocal(s,e), "local:'" + msg + "'"); |
- // Redeclarations of global consts do not throw, they are silently ignored. |
- assertEquals(42, TestGlobal(s, 42), "global:'" + msg + "'"); |
assertEquals(expected, TestContext(s,e), "context:'" + msg + "'"); |
} |
@@ -112,7 +79,7 @@ function TestConflict(def0, def1) { |
// Eval first definition. |
TestAll("TypeError", 'eval("' + def0 +'"); ' + def1); |
// Eval second definition. |
- TestAll("TypeError", def0 + '; eval("' + def1 + '")'); |
+ TestAll("TypeError", def0 + '; eval("' + def1 +'")'); |
// Eval both definitions separately. |
TestAll("TypeError", 'eval("' + def0 +'"); eval("' + def1 + '")'); |
} |
@@ -234,47 +201,26 @@ var undefined = 1; // Should be silently ignored. |
assertEquals(original_undef, undefined, "undefined got overwritten"); |
undefined = original_undef; |
-var a; const a; const a = 1; |
-assertEquals(1, a, "a has wrong value"); |
-a = 2; |
-assertEquals(2, a, "a should be writable"); |
- |
-var b = 1; const b = 2; |
-assertEquals(2, b, "b has wrong value"); |
- |
-var c = 1; const c = 2; const c = 3; |
-assertEquals(3, c, "c has wrong value"); |
- |
-const d = 1; const d = 2; |
-assertEquals(1, d, "d has wrong value"); |
- |
-const e = 1; var e = 2; |
+const e = 1; eval('var e = 2'); |
assertEquals(1, e, "e has wrong value"); |
-const f = 1; const f; |
-assertEquals(1, f, "f has wrong value"); |
- |
-var g; const g = 1; |
-assertEquals(1, g, "g has wrong value"); |
-g = 2; |
-assertEquals(2, g, "g should be writable"); |
- |
-const h; var h = 1; |
-assertEquals(undefined,h, "h has wrong value"); |
+const h; eval('var h = 1'); |
+assertEquals(undefined, h, "h has wrong value"); |
eval("Object.defineProperty(this, 'i', { writable: true });" |
+ "const i = 7;" |
+ "assertEquals(7, i, \"i has wrong value\");"); |
var global = this; |
-assertThrows(function() { |
- Object.defineProperty(global, 'j', { writable: true }) |
-}, TypeError); |
-const j = 2; // This is what makes the function above throw, because the |
-// const declaration gets hoisted and makes the property non-configurable. |
+Object.defineProperty(global, 'j', { value: 100, writable: true }); |
+assertEquals(100, j); |
+// The const declaration stays configurable, so the declaration above goes |
+// through even though the const declaration is hoisted above. |
+const j = 2; |
assertEquals(2, j, "j has wrong value"); |
-var k = 1; const k; |
-// You could argue about the expected result here. For now, the winning |
-// argument is that "const k;" is equivalent to "const k = undefined;". |
-assertEquals(undefined, k, "k has wrong value"); |
+var k = 1; |
+try { eval('const k'); } catch(e) { } |
+assertEquals(1, k, "k has wrong value"); |
+try { eval('const k = 10'); } catch(e) { } |
+assertEquals(1, k, "k has wrong value"); |