1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_5/strict/10.4.3.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,58 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 + 1.6 +/* 1.7 + * Any copyright is dedicated to the Public Domain. 1.8 + * http://creativecommons.org/licenses/publicdomain/ 1.9 + */ 1.10 + 1.11 +var obj = {} 1.12 + 1.13 +function strict() { "use strict"; return this; } 1.14 +assertEq(strict.call(""), ""); 1.15 +assertEq(strict.call(true), true); 1.16 +assertEq(strict.call(42), 42); 1.17 +assertEq(strict.call(null), null); 1.18 +assertEq(strict.call(undefined), undefined); 1.19 +assertEq(strict.call(obj), obj); 1.20 +assertEq(new strict() instanceof Object, true); 1.21 + 1.22 +/* 1.23 + * The compiler internally converts x['foo'] to x.foo. Writing x[s] where 1.24 + * s='foo' is enough to throw it off the scent for now. 1.25 + */ 1.26 +var strictString = 'strict'; 1.27 + 1.28 +Boolean.prototype.strict = strict; 1.29 +assertEq(true.strict(), true); 1.30 +assertEq(true[strictString](), true); 1.31 + 1.32 +Number.prototype.strict = strict; 1.33 +assertEq((42).strict(), 42); 1.34 +assertEq(42[strictString](), 42); 1.35 + 1.36 +String.prototype.strict = strict; 1.37 +assertEq("".strict(), ""); 1.38 +assertEq(""[strictString](), ""); 1.39 + 1.40 +function lenient() { return this; } 1.41 +assertEq(lenient.call("") instanceof String, true); 1.42 +assertEq(lenient.call(true) instanceof Boolean, true); 1.43 +assertEq(lenient.call(42) instanceof Number, true); 1.44 +assertEq(lenient.call(null), this); 1.45 +assertEq(lenient.call(undefined), this); 1.46 +assertEq(lenient.call(obj), obj); 1.47 +assertEq(new lenient() instanceof Object, true); 1.48 + 1.49 +var lenientString = 'lenient'; 1.50 + 1.51 +Boolean.prototype.lenient = lenient; 1.52 +assertEq(true.lenient() instanceof Boolean, true); 1.53 +assertEq(true[lenientString]() instanceof Boolean, true); 1.54 + 1.55 +Number.prototype.lenient = lenient; 1.56 +assertEq(42[lenientString]() instanceof Number, true); 1.57 + 1.58 +String.prototype.lenient = lenient; 1.59 +assertEq(""[lenientString]() instanceof String, true); 1.60 + 1.61 +reportCompare(true, true);