1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_5/strict/unbrand-this.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,45 @@ 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 +/* Test JSOP_UNBRANDTHIS's behavior on object and non-object |this| values. */ 1.12 + 1.13 +function strict() { 1.14 + "use strict"; 1.15 + this.insert = function(){ bar(); }; 1.16 + function bar() {} 1.17 +} 1.18 + 1.19 +var exception; 1.20 + 1.21 +// Try 'undefined' as a |this| value. 1.22 +exception = null; 1.23 +try { 1.24 + strict.call(undefined); 1.25 +} catch (x) { 1.26 + exception = x; 1.27 +} 1.28 +assertEq(exception instanceof TypeError, true); 1.29 + 1.30 +// Try 'null' as a |this| value. 1.31 +exception = null; 1.32 +try { 1.33 + strict.call(null); 1.34 +} catch (x) { 1.35 + exception = x; 1.36 +} 1.37 +assertEq(exception instanceof TypeError, true); 1.38 + 1.39 +// An object as a |this| value should be fine. 1.40 +exception = null; 1.41 +try { 1.42 + strict.call({}); 1.43 +} catch (x) { 1.44 + exception = x; 1.45 +} 1.46 +assertEq(exception, null); 1.47 + 1.48 +reportCompare(true, true);