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

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

Issue 6697023: Merge 6800:7180 from the bleeding edge branch to the experimental/gc branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: 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 | « test/mjsunit/sin-cos.js ('k') | test/mjsunit/tools/tickprocessor-test-func-info.log » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/strict-mode.js
===================================================================
--- test/mjsunit/strict-mode.js (revision 7180)
+++ test/mjsunit/strict-mode.js (working copy)
@@ -280,6 +280,19 @@
CheckStrictMode("function strict() { var x = --eval; }", SyntaxError);
CheckStrictMode("function strict() { var x = --arguments; }", SyntaxError);
+// Use of const in strict mode is disallowed in anticipation of ES Harmony.
+CheckStrictMode("const x = 0;", SyntaxError);
+CheckStrictMode("for (const x = 0; false;) {}", SyntaxError);
+CheckStrictMode("function strict() { const x = 0; }", SyntaxError);
+
+// Strict mode only allows functions in SourceElements
+CheckStrictMode("if (true) { function invalid() {} }", SyntaxError);
+CheckStrictMode("for (;false;) { function invalid() {} }", SyntaxError);
+CheckStrictMode("{ function invalid() {} }", SyntaxError);
+CheckStrictMode("try { function invalid() {} } catch(e) {}", SyntaxError);
+CheckStrictMode("try { } catch(e) { function invalid() {} }", SyntaxError);
+CheckStrictMode("function outer() {{ function invalid() {} }}", SyntaxError);
+
// Delete of an unqualified identifier
CheckStrictMode("delete unqualified;", SyntaxError);
CheckStrictMode("function strict() { delete unqualified; }", SyntaxError);
@@ -291,6 +304,13 @@
SyntaxError);
CheckStrictMode("var variable; delete variable;", SyntaxError);
+(function TestStrictDelete() {
+ "use strict";
+ // "delete this" is allowed in strict mode and should work.
+ function strict_delete() { delete this; }
+ strict_delete();
+})();
+
// Prefix unary operators other than delete, ++, -- are valid in strict mode
(function StrictModeUnaryOperators() {
"use strict";
@@ -438,7 +458,7 @@
})();
// Not transforming this in Function.call and Function.apply.
-(function testThisTransform() {
+(function testThisTransformCallApply() {
function non_strict() {
return this;
}
@@ -478,3 +498,481 @@
assertEquals(typeof strict.apply("Hello"), "string");
assertTrue(strict.apply(object) === object);
})();
+
+(function testThisTransform() {
+ try {
+ function strict() {
+ "use strict";
+ return typeof(this);
+ }
+ function nonstrict() {
+ return typeof(this);
+ }
+
+ // Concat to avoid symbol.
+ var strict_name = "str" + "ict";
+ var nonstrict_name = "non" + "str" + "ict";
+ var strict_number = 17;
+ var nonstrict_number = 19;
+ var strict_name_get = "str" + "ict" + "get";
+ var nonstrict_name_get = "non" + "str" + "ict" + "get"
+ var strict_number_get = 23;
+ var nonstrict_number_get = 29;
+
+ function install(t) {
+ t.prototype.strict = strict;
+ t.prototype.nonstrict = nonstrict;
+ t.prototype[strict_number] = strict;
+ t.prototype[nonstrict_number] = nonstrict;
+ Object.defineProperty(t.prototype, strict_name_get,
+ { get: function() { return strict; },
+ configurable: true });
+ Object.defineProperty(t.prototype, nonstrict_name_get,
+ { get: function() { return nonstrict; },
+ configurable: true });
+ Object.defineProperty(t.prototype, strict_number_get,
+ { get: function() { return strict; },
+ configurable: true });
+ Object.defineProperty(t.prototype, nonstrict_number_get,
+ { get: function() { return nonstrict; },
+ configurable: true });
+ }
+
+ function cleanup(t) {
+ delete t.prototype.strict;
+ delete t.prototype.nonstrict;
+ delete t.prototype[strict_number];
+ delete t.prototype[nonstrict_number];
+ delete t.prototype[strict_name_get];
+ delete t.prototype[nonstrict_name_get];
+ delete t.prototype[strict_number_get];
+ delete t.prototype[nonstrict_number_get];
+ }
+
+ // Set up fakes
+ install(String);
+ install(Number);
+ install(Boolean)
+
+ function callStrict(o) {
+ return o.strict();
+ }
+ function callNonStrict(o) {
+ return o.nonstrict();
+ }
+ function callKeyedStrict(o) {
+ return o[strict_name]();
+ }
+ function callKeyedNonStrict(o) {
+ return o[nonstrict_name]();
+ }
+ function callIndexedStrict(o) {
+ return o[strict_number]();
+ }
+ function callIndexedNonStrict(o) {
+ return o[nonstrict_number]();
+ }
+ function callStrictGet(o) {
+ return o.strictget();
+ }
+ function callNonStrictGet(o) {
+ return o.nonstrictget();
+ }
+ function callKeyedStrictGet(o) {
+ return o[strict_name_get]();
+ }
+ function callKeyedNonStrictGet(o) {
+ return o[nonstrict_name_get]();
+ }
+ function callIndexedStrictGet(o) {
+ return o[strict_number_get]();
+ }
+ function callIndexedNonStrictGet(o) {
+ return o[nonstrict_number_get]();
+ }
+
+ for (var i = 0; i < 10; i ++) {
+ assertEquals(("hello").strict(), "string");
+ assertEquals(("hello").nonstrict(), "object");
+ assertEquals(("hello")[strict_name](), "string");
+ assertEquals(("hello")[nonstrict_name](), "object");
+ assertEquals(("hello")[strict_number](), "string");
+ assertEquals(("hello")[nonstrict_number](), "object");
+
+ assertEquals((10 + i).strict(), "number");
+ assertEquals((10 + i).nonstrict(), "object");
+ assertEquals((10 + i)[strict_name](), "number");
+ assertEquals((10 + i)[nonstrict_name](), "object");
+ assertEquals((10 + i)[strict_number](), "number");
+ assertEquals((10 + i)[nonstrict_number](), "object");
+
+ assertEquals((true).strict(), "boolean");
+ assertEquals((true).nonstrict(), "object");
+ assertEquals((true)[strict_name](), "boolean");
+ assertEquals((true)[nonstrict_name](), "object");
+ assertEquals((true)[strict_number](), "boolean");
+ assertEquals((true)[nonstrict_number](), "object");
+
+ assertEquals((false).strict(), "boolean");
+ assertEquals((false).nonstrict(), "object");
+ assertEquals((false)[strict_name](), "boolean");
+ assertEquals((false)[nonstrict_name](), "object");
+ assertEquals((false)[strict_number](), "boolean");
+ assertEquals((false)[nonstrict_number](), "object");
+
+ assertEquals(callStrict("howdy"), "string");
+ assertEquals(callNonStrict("howdy"), "object");
+ assertEquals(callKeyedStrict("howdy"), "string");
+ assertEquals(callKeyedNonStrict("howdy"), "object");
+ assertEquals(callIndexedStrict("howdy"), "string");
+ assertEquals(callIndexedNonStrict("howdy"), "object");
+
+ assertEquals(callStrict(17 + i), "number");
+ assertEquals(callNonStrict(17 + i), "object");
+ assertEquals(callKeyedStrict(17 + i), "number");
+ assertEquals(callKeyedNonStrict(17 + i), "object");
+ assertEquals(callIndexedStrict(17 + i), "number");
+ assertEquals(callIndexedNonStrict(17 + i), "object");
+
+ assertEquals(callStrict(true), "boolean");
+ assertEquals(callNonStrict(true), "object");
+ assertEquals(callKeyedStrict(true), "boolean");
+ assertEquals(callKeyedNonStrict(true), "object");
+ assertEquals(callIndexedStrict(true), "boolean");
+ assertEquals(callIndexedNonStrict(true), "object");
+
+ assertEquals(callStrict(false), "boolean");
+ assertEquals(callNonStrict(false), "object");
+ assertEquals(callKeyedStrict(false), "boolean");
+ assertEquals(callKeyedNonStrict(false), "object");
+ assertEquals(callIndexedStrict(false), "boolean");
+ assertEquals(callIndexedNonStrict(false), "object");
+
+ // All of the above, with getters
+ assertEquals(("hello").strictget(), "string");
+ assertEquals(("hello").nonstrictget(), "object");
+ assertEquals(("hello")[strict_name_get](), "string");
+ assertEquals(("hello")[nonstrict_name_get](), "object");
+ assertEquals(("hello")[strict_number_get](), "string");
+ assertEquals(("hello")[nonstrict_number_get](), "object");
+
+ assertEquals((10 + i).strictget(), "number");
+ assertEquals((10 + i).nonstrictget(), "object");
+ assertEquals((10 + i)[strict_name_get](), "number");
+ assertEquals((10 + i)[nonstrict_name_get](), "object");
+ assertEquals((10 + i)[strict_number_get](), "number");
+ assertEquals((10 + i)[nonstrict_number_get](), "object");
+
+ assertEquals((true).strictget(), "boolean");
+ assertEquals((true).nonstrictget(), "object");
+ assertEquals((true)[strict_name_get](), "boolean");
+ assertEquals((true)[nonstrict_name_get](), "object");
+ assertEquals((true)[strict_number_get](), "boolean");
+ assertEquals((true)[nonstrict_number_get](), "object");
+
+ assertEquals((false).strictget(), "boolean");
+ assertEquals((false).nonstrictget(), "object");
+ assertEquals((false)[strict_name_get](), "boolean");
+ assertEquals((false)[nonstrict_name_get](), "object");
+ assertEquals((false)[strict_number_get](), "boolean");
+ assertEquals((false)[nonstrict_number_get](), "object");
+
+ assertEquals(callStrictGet("howdy"), "string");
+ assertEquals(callNonStrictGet("howdy"), "object");
+ assertEquals(callKeyedStrictGet("howdy"), "string");
+ assertEquals(callKeyedNonStrictGet("howdy"), "object");
+ assertEquals(callIndexedStrictGet("howdy"), "string");
+ assertEquals(callIndexedNonStrictGet("howdy"), "object");
+
+ assertEquals(callStrictGet(17 + i), "number");
+ assertEquals(callNonStrictGet(17 + i), "object");
+ assertEquals(callKeyedStrictGet(17 + i), "number");
+ assertEquals(callKeyedNonStrictGet(17 + i), "object");
+ assertEquals(callIndexedStrictGet(17 + i), "number");
+ assertEquals(callIndexedNonStrictGet(17 + i), "object");
+
+ assertEquals(callStrictGet(true), "boolean");
+ assertEquals(callNonStrictGet(true), "object");
+ assertEquals(callKeyedStrictGet(true), "boolean");
+ assertEquals(callKeyedNonStrictGet(true), "object");
+ assertEquals(callIndexedStrictGet(true), "boolean");
+ assertEquals(callIndexedNonStrictGet(true), "object");
+
+ assertEquals(callStrictGet(false), "boolean");
+ assertEquals(callNonStrictGet(false), "object");
+ assertEquals(callKeyedStrictGet(false), "boolean");
+ assertEquals(callKeyedNonStrictGet(false), "object");
+ assertEquals(callIndexedStrictGet(false), "boolean");
+ assertEquals(callIndexedNonStrictGet(false), "object");
+
+ }
+ } finally {
+ // Cleanup
+ cleanup(String);
+ cleanup(Number);
+ 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);
+ }
+})();
+
+
+(function TestSetElementWithoutSetter() {
+ "use strict";
+
+ var o = { };
+ Object.defineProperty(o, 0, { get : function() { } });
+
+ var zero_smi = 0;
+ var zero_number = new Number(0);
+ var zero_symbol = "0";
+ var zero_string = "-0-".substring(1,2);
+
+ assertThrows(function() { o[zero_smi] = "new value"; }, TypeError);
+ assertThrows(function() { o[zero_number] = "new value"; }, TypeError);
+ assertThrows(function() { o[zero_symbol] = "new value"; }, TypeError);
+ assertThrows(function() { o[zero_string] = "new value"; }, TypeError);
+})();
+
+
+(function TestSetElementNonConfigurable() {
+ "use strict";
+ var frozen = Object.freeze({});
+ var sealed = Object.seal({});
+
+ var zero_number = 0;
+ var zero_symbol = "0";
+ var zero_string = "-0-".substring(1,2);
+
+ assertThrows(function() { frozen[zero_number] = "value"; }, TypeError);
+ assertThrows(function() { sealed[zero_number] = "value"; }, TypeError);
+ assertThrows(function() { frozen[zero_symbol] = "value"; }, TypeError);
+ assertThrows(function() { sealed[zero_symbol] = "value"; }, TypeError);
+ assertThrows(function() { frozen[zero_string] = "value"; }, TypeError);
+ assertThrows(function() { sealed[zero_string] = "value"; }, TypeError);
+})();
+
+
+(function TestAssignmentToReadOnlyElement() {
+ "use strict";
+
+ var o = {};
+ Object.defineProperty(o, 7, { value: 17 });
+
+ var seven_smi = 7;
+ var seven_number = new Number(7);
+ var seven_symbol = "7";
+ var seven_string = "-7-".substring(1,2);
+
+ // Index with number.
+ assertThrows(function() { o[seven_smi] = "value"; }, TypeError);
+ assertThrows(function() { o[seven_smi] += 10; }, TypeError);
+ assertThrows(function() { o[seven_smi] -= 10; }, TypeError);
+ assertThrows(function() { o[seven_smi] *= 10; }, TypeError);
+ assertThrows(function() { o[seven_smi] /= 10; }, TypeError);
+ assertThrows(function() { o[seven_smi]++; }, TypeError);
+ assertThrows(function() { o[seven_smi]--; }, TypeError);
+ assertThrows(function() { ++o[seven_smi]; }, TypeError);
+ assertThrows(function() { --o[seven_smi]; }, TypeError);
+
+ assertThrows(function() { o[seven_number] = "value"; }, TypeError);
+ assertThrows(function() { o[seven_number] += 10; }, TypeError);
+ assertThrows(function() { o[seven_number] -= 10; }, TypeError);
+ assertThrows(function() { o[seven_number] *= 10; }, TypeError);
+ assertThrows(function() { o[seven_number] /= 10; }, TypeError);
+ assertThrows(function() { o[seven_number]++; }, TypeError);
+ assertThrows(function() { o[seven_number]--; }, TypeError);
+ assertThrows(function() { ++o[seven_number]; }, TypeError);
+ assertThrows(function() { --o[seven_number]; }, TypeError);
+
+ assertThrows(function() { o[seven_symbol] = "value"; }, TypeError);
+ assertThrows(function() { o[seven_symbol] += 10; }, TypeError);
+ assertThrows(function() { o[seven_symbol] -= 10; }, TypeError);
+ assertThrows(function() { o[seven_symbol] *= 10; }, TypeError);
+ assertThrows(function() { o[seven_symbol] /= 10; }, TypeError);
+ assertThrows(function() { o[seven_symbol]++; }, TypeError);
+ assertThrows(function() { o[seven_symbol]--; }, TypeError);
+ assertThrows(function() { ++o[seven_symbol]; }, TypeError);
+ assertThrows(function() { --o[seven_symbol]; }, TypeError);
+
+ assertThrows(function() { o[seven_string] = "value"; }, TypeError);
+ assertThrows(function() { o[seven_string] += 10; }, TypeError);
+ assertThrows(function() { o[seven_string] -= 10; }, TypeError);
+ assertThrows(function() { o[seven_string] *= 10; }, TypeError);
+ assertThrows(function() { o[seven_string] /= 10; }, TypeError);
+ assertThrows(function() { o[seven_string]++; }, TypeError);
+ assertThrows(function() { o[seven_string]--; }, TypeError);
+ assertThrows(function() { ++o[seven_string]; }, TypeError);
+ assertThrows(function() { --o[seven_string]; }, TypeError);
+
+ assertEquals(o[seven_number], 17);
+ assertEquals(o[seven_symbol], 17);
+ assertEquals(o[seven_string], 17);
+})();
+
+
+(function TestAssignmentToReadOnlyLoop() {
+ "use strict";
+
+ var o = {};
+ Object.defineProperty(o, 7, { value: 17 });
+
+ var seven_smi = 7;
+ var seven_number = new Number(7);
+ var seven_symbol = "7";
+ var seven_string = "-7-".substring(1,2);
+
+ for (var i = 0; i < 10; i ++) {
+ assertThrows(function() { o[seven_smi] = "value" }, TypeError);
+ assertThrows(function() { o[seven_number] = "value" }, TypeError);
+ assertThrows(function() { o[seven_symbol] = "value" }, TypeError);
+ assertThrows(function() { o[seven_string] = "value" }, TypeError);
+ }
+
+ assertEquals(o[7], 17);
+})();
+
+
+(function TestAssignmentToStringLength() {
+ "use strict";
+
+ var str_val = "string";
+ var str_obj = new String(str_val);
+ var str_cat = str_val + str_val + str_obj;
+
+ assertThrows(function() { str_val.length = 1; }, TypeError);
+ assertThrows(function() { str_obj.length = 1; }, TypeError);
+ assertThrows(function() { str_cat.length = 1; }, TypeError);
+})();
+
+
+(function TestArgumentsAliasing() {
+ function strict(a, b) {
+ "use strict";
+ a = "c";
+ b = "d";
+ return [a, b, arguments[0], arguments[1]];
+ }
+
+ function nonstrict(a, b) {
+ a = "c";
+ b = "d";
+ return [a, b, arguments[0], arguments[1]];
+ }
+
+ assertEquals(["c", "d", "a", "b"], strict("a", "b"));
+ assertEquals(["c", "d", "c", "d"], nonstrict("a", "b"));
+})();
« no previous file with comments | « test/mjsunit/sin-cos.js ('k') | test/mjsunit/tools/tickprocessor-test-func-info.log » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698