Reviewers: Kevin Millikin,

Message:
PTAL. And thanks for the help.

Description:
Make window.{undefined,NaN,Infinity} read-only

as per ES5.


BUG=89490
TEST=es5conform 15.1.*, 15.2.3.*; mjsunit/undeletable-functions


Please review this at http://codereview.chromium.org/7538016/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/runtime.cc
  M src/v8natives.js
  M test/cctest/test-decls.cc
  M test/es5conform/es5conform.status
  M test/mjsunit/undeletable-functions.js
  M test/sputnik/sputnik.status


Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index f9652769886c91333542e3a268f3728fed334310..ca83a109915f2b2b3e8560e665ed3a2557492132 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -1172,7 +1172,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareGlobals) {
             return ThrowRedeclarationError(isolate, "const", name);
           }
           // Otherwise, we check for locally conflicting declarations.
-          if (is_local && (is_read_only || is_const_property)) {
+          if (is_local && is_const_property) {
             const char* type = (is_read_only) ? "const" : "var";
             return ThrowRedeclarationError(isolate, type, name);
           }
@@ -1406,12 +1406,11 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeVarGlobal) {
           // make sure to introduce it.
           found = false;
         } else if ((intercepted & READ_ONLY) != 0) {
-          // The property is present, but read-only. Since we're trying to
-          // overwrite it with a variable declaration we must throw a
-          // re-declaration error.  However if we found readonly property
+          // The property is present, but read-only, so we ignore the
+          // redeclaration. However if we found readonly property
           // on one of hidden prototypes, just shadow it.
           if (real_holder != isolate->context()->global()) break;
-          return ThrowRedeclarationError(isolate, "const", name);
+          return isolate->heap()->undefined_value();
         }
       }

Index: src/v8natives.js
diff --git a/src/v8natives.js b/src/v8natives.js
index be9b297f81315acf7f46ea6f117c518b6ea74cc9..7242506720719e475eaef8983febce2cdc2ee9c9 100644
--- a/src/v8natives.js
+++ b/src/v8natives.js
@@ -162,13 +162,14 @@ function GlobalEval(x) {

 function SetupGlobal() {
   // ECMA 262 - 15.1.1.1.
-  %SetProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE);
+  %SetProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE | READ_ONLY);

   // ECMA-262 - 15.1.1.2.
-  %SetProperty(global, "Infinity", 1/0, DONT_ENUM | DONT_DELETE);
+ %SetProperty(global, "Infinity", 1/0, DONT_ENUM | DONT_DELETE | READ_ONLY);

   // ECMA-262 - 15.1.1.3.
-  %SetProperty(global, "undefined", void 0, DONT_ENUM | DONT_DELETE);
+  %SetProperty(global, "undefined", void 0,
+               DONT_ENUM | DONT_DELETE | READ_ONLY);

   // Setup non-enumerable function on the global object.
   InstallFunctions(global, DONT_ENUM, $Array(
Index: test/cctest/test-decls.cc
diff --git a/test/cctest/test-decls.cc b/test/cctest/test-decls.cc
index 619839185e651aab3e16787145ea154872357404..9f7340e38a5096dd5d4f5f35a714ffee8d7658d1 100644
--- a/test/cctest/test-decls.cc
+++ b/test/cctest/test-decls.cc
@@ -498,7 +498,7 @@ TEST(Reappearing) {
                   0,
                   2,  // var declaration + const initialization
                   4,  // 2 x declaration + 2 x initialization
-                  EXPECT_EXCEPTION);  // x has already been declared!
+                  EXPECT_RESULT, Undefined());  // x = 0 fails for a const.
   }
 }

Index: test/es5conform/es5conform.status
diff --git a/test/es5conform/es5conform.status b/test/es5conform/es5conform.status index 55712baf69cee7ce6a5d4d0f6829c82a296b05f2..3a56f0b010b66133798f15d7c14a5d17ea06711b 100644
--- a/test/es5conform/es5conform.status
+++ b/test/es5conform/es5conform.status
@@ -41,16 +41,6 @@ chapter10/10.4/10.4.2/10.4.2-2-c-1: FAIL_OK
 # We are compatible with Safari and Firefox.
 chapter11/11.1/11.1.5: UNIMPLEMENTED

-# We do not have a global object called 'global' as required by tests.
-chapter15/15.1: FAIL_OK
-
-# NaN is writable. We are compatible with JSC.
-chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-178: FAIL_OK
-# Infinity is writable. We are compatible with JSC.
-chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-179: FAIL_OK
-# undefined is writable. We are compatible with JSC.
-chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-180: FAIL_OK
-
 # Our Function object has an "arguments" property which is used as a
 # non-property in the test.
 chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-183: FAIL_OK
Index: test/mjsunit/undeletable-functions.js
diff --git a/test/mjsunit/undeletable-functions.js b/test/mjsunit/undeletable-functions.js index 04fd06068d0b7b7616070b143ec4aa4b9c015a36..bbb798f3516e7f2a96f85540e9443271246e65ed 100644
--- a/test/mjsunit/undeletable-functions.js
+++ b/test/mjsunit/undeletable-functions.js
@@ -76,6 +76,8 @@ array = [
   "execScript"];
 CheckEcmaSemantics(this, array, "Global");
 CheckReadOnlyAttr(this, "Infinity");
+CheckReadOnlyAttr(this, "NaN");
+CheckReadOnlyAttr(this, "undefined");

 array = ["exec", "test", "toString", "compile"];
 CheckEcmaSemantics(RegExp.prototype, array, "RegExp prototype");
@@ -189,7 +191,7 @@ function CheckReadOnlyAttr(type, prop) {
   assertFalse(deleted, "delete operator returned true: " + prop);
   assertTrue(type.hasOwnProperty(prop), "not there after delete: " + prop);
   type[prop] = "foo";
-  assertEquals("foo", type[prop], "overwritable: " + prop);
+  assertEquals(old, type[prop], "overwritable: " + prop);
 }

 print("OK");
Index: test/sputnik/sputnik.status
diff --git a/test/sputnik/sputnik.status b/test/sputnik/sputnik.status
index 82d8a61c7a7ca3892d58a5ae20995f7661bfea32..02acec02834d5210a44883014273d52a73d945cf 100644
--- a/test/sputnik/sputnik.status
+++ b/test/sputnik/sputnik.status
@@ -178,6 +178,17 @@ S15.5.4.13_A1_T3: FAIL_OK
 S15.5.4.14_A1_T3: FAIL_OK
 S15.5.4.15_A1_T3: FAIL_OK

+# NaN, Infinity and undefined are read-only according to ES5.
+S15.1.1.1_A2_T1: FAIL_OK  # NaN
+S15.1.1.1_A2_T2: FAIL_OK  # NaN
+S15.1.1.2_A2_T1: FAIL_OK  # Infinity
+# S15.1.1.2_A2_T2 would fail if it weren't bogus in r97. sputnik bug #45.
+S15.1.1.3_A2_T1: FAIL_OK  # undefined
+S15.1.1.3_A2_T2: FAIL_OK  # undefined
+S8.1_A3: FAIL_OK # undefined (comment is correct, test itself is bogus/ES3)
+S8.5_A4: FAIL_OK  # NaN
+S8.5_A10: FAIL_OK  # Infinity
+
 ##################### SKIPPED TESTS #####################

 # These tests take a looong time to run in debug mode.


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to