Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(411)

Unified Diff: test/mjsunit/strict-mode.js

Issue 6594037: Strict Mode assignment to read only property. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CR Feedback. Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/es5conform/es5conform.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/strict-mode.js
diff --git a/test/mjsunit/strict-mode.js b/test/mjsunit/strict-mode.js
index ab3e535ec33055a8245ff5280c8b196a74170d3c..0bc117e14771471cfa0441dbe1bfd2e805e84975 100644
--- a/test/mjsunit/strict-mode.js
+++ b/test/mjsunit/strict-mode.js
@@ -700,3 +700,118 @@ repeat(10, function() { testAssignToUndefined(false); });
cleanup(Boolean);
}
})();
+
+
+(function ObjectEnvironment() {
+ var o = {};
+ Object.defineProperty(o, "foo", { value: "FOO", writable: false });
+ assertThrows(
+ function () {
+ with (o) {
+ (function() {
+ "use strict";
+ foo = "Hello";
+ })();
+ }
+ },
+ TypeError);
+})();
+
+
+(function TestSetPropertyWithoutSetter() {
+ var o = { get foo() { return "Yey"; } };
+ assertThrows(
+ function broken() {
+ "use strict";
+ o.foo = (0xBADBAD00 >> 1);
+ },
+ TypeError);
+})();
+
+
+(function TestSetPropertyNonConfigurable() {
+ var frozen = Object.freeze({});
+ var sealed = Object.seal({});
+
+ function strict(o) {
+ "use strict";
+ o.property = "value";
+ }
+
+ assertThrows(function() { strict(frozen); }, TypeError);
+ assertThrows(function() { strict(sealed); }, TypeError);
+})();
+
+
+(function TestAssignmentToReadOnlyProperty() {
+ "use strict";
+
+ var o = {};
+ Object.defineProperty(o, "property", { value: 7 });
+
+ assertThrows(function() { o.property = "new value"; }, TypeError);
+ assertThrows(function() { o.property += 10; }, TypeError);
+ assertThrows(function() { o.property -= 10; }, TypeError);
+ assertThrows(function() { o.property *= 10; }, TypeError);
+ assertThrows(function() { o.property /= 10; }, TypeError);
+ assertThrows(function() { o.property++; }, TypeError);
+ assertThrows(function() { o.property--; }, TypeError);
+ assertThrows(function() { ++o.property; }, TypeError);
+ assertThrows(function() { --o.property; }, TypeError);
+
+ var name = "prop" + "erty"; // to avoid symbol path.
+ assertThrows(function() { o[name] = "new value"; }, TypeError);
+ assertThrows(function() { o[name] += 10; }, TypeError);
+ assertThrows(function() { o[name] -= 10; }, TypeError);
+ assertThrows(function() { o[name] *= 10; }, TypeError);
+ assertThrows(function() { o[name] /= 10; }, TypeError);
+ assertThrows(function() { o[name]++; }, TypeError);
+ assertThrows(function() { o[name]--; }, TypeError);
+ assertThrows(function() { ++o[name]; }, TypeError);
+ assertThrows(function() { --o[name]; }, TypeError);
+
+ assertEquals(o.property, 7);
+})();
+
+
+(function TestAssignmentToReadOnlyLoop() {
+ var name = "prop" + "erty"; // to avoid symbol path.
+ var o = {};
+ Object.defineProperty(o, "property", { value: 7 });
+
+ function strict(o, name) {
+ "use strict";
+ o[name] = "new value";
+ }
+
+ for (var i = 0; i < 10; i ++) {
+ try {
+ strict(o, name);
+ assertUnreachable();
+ } catch(e) {
+ assertInstanceof(e, TypeError);
+ }
+ }
+})();
+
+
+// Specialized KeyedStoreIC experiencing miss.
+(function testKeyedStoreICStrict() {
+ var o = [9,8,7,6,5,4,3,2,1];
+
+ function test(o, i, v) {
+ "use strict";
+ o[i] = v;
+ }
+
+ for (var i = 0; i < 10; i ++) {
+ test(o, 5, 17); // start specialized for smi indices
+ assertEquals(o[5], 17);
+ test(o, "a", 19);
+ assertEquals(o["a"], 19);
+ test(o, "5", 29);
+ assertEquals(o[5], 29);
+ test(o, 100000, 31);
+ assertEquals(o[100000], 31);
+ }
+})();
« no previous file with comments | « test/es5conform/es5conform.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698