Reviewers: danno,
Message:
This make v8 behave like Safari does. And even as ECMAScript-262
mandates :)
Surprisingly, I found no Sputnik tests which verify this behviour, but I
only
inspected the tests for the given chapters and didn't run the follow suite.
Description:
Make Nan, Infinity and undefined on global object not overwritable.
That is to match both ECMAScript-262 and Safari.
Please review this at http://codereview.chromium.org/7551013/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/v8natives.js
A test/mjsunit/global-properties.js
M test/mjsunit/undeletable-functions.js
Index: src/v8natives.js
diff --git a/src/v8natives.js b/src/v8natives.js
index
be9b297f81315acf7f46ea6f117c518b6ea74cc9..8836b0e5914989f32db4d810259f3bee0ffde62d
100644
--- a/src/v8natives.js
+++ b/src/v8natives.js
@@ -162,13 +162,13 @@ 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/mjsunit/global-properties.js
diff --git a/test/mjsunit/global-properties.js
b/test/mjsunit/global-properties.js
new file mode 100644
index
0000000000000000000000000000000000000000..a0364d2002a366f6c84bd7a5e30c284263bf421c
--- /dev/null
+++ b/test/mjsunit/global-properties.js
@@ -0,0 +1,55 @@
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Test that global properties NaN, infinity and undefined has proper
+// attributes.
+
+var global = this;
+
+var NaN_descriptor = Object.getOwnPropertyDescriptor(global, 'NaN');
+assertFalse(NaN_descriptor.writable);
+assertFalse(NaN_descriptor.enumerable);
+assertFalse(NaN_descriptor.configurable);
+var original_NaN = global.NaN;
+global.NaN = 42;
+assertSame(original_NaN, global.NaN);
+
+var Infinity_descriptor =
Object.getOwnPropertyDescriptor(global, 'Infinity');
+assertFalse(Infinity_descriptor.writable);
+assertFalse(Infinity_descriptor.enumerable);
+assertFalse(Infinity_descriptor.configurable);
+var original_Infinity = global.Infinity;
+global.Infinity = 42;
+assertSame(original_Infinity, global.Infinity);
+
+var undefined_descriptor =
Object.getOwnPropertyDescriptor(global, 'undefined');
+assertFalse(undefined_descriptor.writable);
+assertFalse(undefined_descriptor.enumerable);
+assertFalse(undefined_descriptor.configurable);
+var original_undefined = global.undefined;
+global.undefined = 42;
+assertSame(original_undefined, global.undefined);
Index: test/mjsunit/undeletable-functions.js
diff --git a/test/mjsunit/undeletable-functions.js
b/test/mjsunit/undeletable-functions.js
index
04fd06068d0b7b7616070b143ec4aa4b9c015a36..32c85866d1e26d9d1cd0223f8f213457d664127b
100644
--- a/test/mjsunit/undeletable-functions.js
+++ b/test/mjsunit/undeletable-functions.js
@@ -189,7 +189,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");
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev