Index: test/mjsunit/strict-mode.js |
diff --git a/test/mjsunit/strict-mode.js b/test/mjsunit/strict-mode.js |
index fbba64ed66606c125dbbec74a5849402c3b41144..b2e676c7c83fbcda23b9d6102505d15fa63c40ef 100644 |
--- a/test/mjsunit/strict-mode.js |
+++ b/test/mjsunit/strict-mode.js |
@@ -438,7 +438,7 @@ repeat(10, function() { testAssignToUndefined(false); }); |
})(); |
// Not transforming this in Function.call and Function.apply. |
-(function testThisTransform() { |
+(function testThisTransformCallApply() { |
function non_strict() { |
return this; |
} |
@@ -478,3 +478,122 @@ repeat(10, function() { testAssignToUndefined(false); }); |
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 = 1943; |
+ var nonstrict_number = 1974; |
+ |
+ function install(t) { |
+ t.prototype.strict = strict; |
+ t.prototype.nonstrict = nonstrict; |
+ t.prototype[strict_number] = strict; |
+ t.prototype[nonstrict_number] = nonstrict; |
+ } |
+ |
+ function cleanup(t) { |
+ delete t.prototype.strict; |
+ delete t.prototype.nonstrict; |
+ delete t.prototype[strict_number]; |
+ delete t.prototype[nonstrict_number]; |
+ } |
+ |
+ // 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](); |
+ } |
+ |
+ 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"); |
+ } |
+ } finally { |
+ // Cleanup |
+ cleanup(String); |
+ cleanup(Number); |
+ cleanup(Boolean); |
+ } |
+})(); |