michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: */ michael@0: michael@0: var obj = {} michael@0: michael@0: function strict() { "use strict"; return this; } michael@0: assertEq(strict.call(""), ""); michael@0: assertEq(strict.call(true), true); michael@0: assertEq(strict.call(42), 42); michael@0: assertEq(strict.call(null), null); michael@0: assertEq(strict.call(undefined), undefined); michael@0: assertEq(strict.call(obj), obj); michael@0: assertEq(new strict() instanceof Object, true); michael@0: michael@0: /* michael@0: * The compiler internally converts x['foo'] to x.foo. Writing x[s] where michael@0: * s='foo' is enough to throw it off the scent for now. michael@0: */ michael@0: var strictString = 'strict'; michael@0: michael@0: Boolean.prototype.strict = strict; michael@0: assertEq(true.strict(), true); michael@0: assertEq(true[strictString](), true); michael@0: michael@0: Number.prototype.strict = strict; michael@0: assertEq((42).strict(), 42); michael@0: assertEq(42[strictString](), 42); michael@0: michael@0: String.prototype.strict = strict; michael@0: assertEq("".strict(), ""); michael@0: assertEq(""[strictString](), ""); michael@0: michael@0: function lenient() { return this; } michael@0: assertEq(lenient.call("") instanceof String, true); michael@0: assertEq(lenient.call(true) instanceof Boolean, true); michael@0: assertEq(lenient.call(42) instanceof Number, true); michael@0: assertEq(lenient.call(null), this); michael@0: assertEq(lenient.call(undefined), this); michael@0: assertEq(lenient.call(obj), obj); michael@0: assertEq(new lenient() instanceof Object, true); michael@0: michael@0: var lenientString = 'lenient'; michael@0: michael@0: Boolean.prototype.lenient = lenient; michael@0: assertEq(true.lenient() instanceof Boolean, true); michael@0: assertEq(true[lenientString]() instanceof Boolean, true); michael@0: michael@0: Number.prototype.lenient = lenient; michael@0: assertEq(42[lenientString]() instanceof Number, true); michael@0: michael@0: String.prototype.lenient = lenient; michael@0: assertEq(""[lenientString]() instanceof String, true); michael@0: michael@0: reportCompare(true, true);