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

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

Issue 6694044: Strict mode poison pills for function.caller and function.arguments (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Final touches. Created 9 years, 9 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 | « src/x64/lithium-codegen-x64.cc ('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 20641625ab2a62d420c67b9c3fda6945d33271fb..0a511809d5e5ad64946d2678c481b3a42cbcaec2 100644
--- a/test/mjsunit/strict-mode.js
+++ b/test/mjsunit/strict-mode.js
@@ -976,3 +976,68 @@ repeat(10, function() { testAssignToUndefined(false); });
assertEquals(["c", "d", "a", "b"], strict("a", "b"));
assertEquals(["c", "d", "c", "d"], nonstrict("a", "b"));
})();
+
+
+(function TestStrictFunctionPills() {
+ function strict() {
+ "use strict";
+ }
+ assertThrows(function() { strict.caller; }, TypeError);
+ assertThrows(function() { strict.arguments; }, TypeError);
+
+ var another = new Function("'use strict'");
+ assertThrows(function() { another.caller; }, TypeError);
+ assertThrows(function() { another.arguments; }, TypeError);
+
+ var third = (function() { "use strict"; return function() {}; })();
+ assertThrows(function() { third.caller; }, TypeError);
+ assertThrows(function() { third.arguments; }, TypeError);
+
+ function CheckPill(pill) {
+ assertEquals("function", typeof pill);
+ assertInstanceof(pill, Function);
+ assertThrows(function() { pill.property = "value"; }, TypeError);
+ assertThrows(pill, TypeError);
+ assertEquals(pill.prototype, (function(){}).prototype);
+ var d = Object.getOwnPropertyDescriptor(pill, "prototype");
+ assertFalse(d.writable);
+ assertFalse(d.configurable);
+ assertFalse(d.enumerable);
+ }
+
+ function CheckPillDescriptor(func, name) {
+ var descriptor = Object.getOwnPropertyDescriptor(func, name);
+ CheckPill(descriptor.get)
+ CheckPill(descriptor.set);
+ assertFalse(descriptor.enumerable);
+ assertFalse(descriptor.configurable);
+ }
+
+ CheckPillDescriptor(strict, "caller");
+ CheckPillDescriptor(strict, "arguments");
+ CheckPillDescriptor(another, "caller");
+ CheckPillDescriptor(another, "arguments");
+ CheckPillDescriptor(third, "caller");
+ CheckPillDescriptor(third, "arguments");
+})();
+
+
+(function TestStrictFunctionWritablePrototype() {
+ "use strict";
+ function TheClass() {
+ }
+ assertThrows(function() { TheClass.caller; }, TypeError);
+ assertThrows(function() { TheClass.arguments; }, TypeError);
+
+ // Strict functions must have writable prototype.
+ TheClass.prototype = {
+ func: function() { return "func_value"; },
+ get accessor() { return "accessor_value"; },
+ property: "property_value",
+ };
+
+ var o = new TheClass();
+ assertEquals(o.func(), "func_value");
+ assertEquals(o.accessor, "accessor_value");
+ assertEquals(o.property, "property_value");
+})();
« no previous file with comments | « src/x64/lithium-codegen-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698