1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_3_1/Object/regress-444787.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,122 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +//----------------------------------------------------------------------------- 1.10 +var BUGNUMBER = 444787; 1.11 +var summary = 'Object.getPrototypeOf'; 1.12 +var actual = ''; 1.13 +var expect = ''; 1.14 + 1.15 + 1.16 +//----------------------------------------------------------------------------- 1.17 +test(); 1.18 +//----------------------------------------------------------------------------- 1.19 + 1.20 +function test() 1.21 +{ 1.22 + enterFunc ('test'); 1.23 + printBugNumber(BUGNUMBER); 1.24 + printStatus (summary); 1.25 + 1.26 + var i; 1.27 + var type; 1.28 + var instance; 1.29 + var types = [ 1.30 + Array, 1.31 + Boolean, 1.32 + Date, 1.33 + Error, 1.34 + Function, 1.35 + Math, 1.36 + Number, 1.37 + Object, 1.38 + RegExp, 1.39 + String, 1.40 + ]; 1.41 + 1.42 + for (i = 0; i < types.length; i++) 1.43 + { 1.44 + type = types[i]; 1.45 + 1.46 + if (typeof type.__proto__ != 'undefined') 1.47 + { 1.48 + expect = type.__proto__; 1.49 + actual = Object.getPrototypeOf(type); 1.50 + reportCompare(expect, actual, summary + ': ' + type.name); 1.51 + } 1.52 + 1.53 + try 1.54 + { 1.55 + eval('instance = new ' + type.name); 1.56 + expect = type.prototype; 1.57 + actual = Object.getPrototypeOf(instance); 1.58 + reportCompare(expect, actual, summary + ': new ' + type.name); 1.59 + } 1.60 + catch(ex if ex instanceof TypeError) 1.61 + { 1.62 + print('Ignore ' + ex); 1.63 + } 1.64 + catch(ex) 1.65 + { 1.66 + actual = ex + ''; 1.67 + reportCompare(expect, actual, summary + ': new ' + type.name); 1.68 + } 1.69 + 1.70 + } 1.71 + 1.72 + types = [null, undefined]; 1.73 + 1.74 + for (i = 0; i < types.length; i++) 1.75 + { 1.76 + type = types[i]; 1.77 + expect = 'TypeError: Object.getPrototype is not a function'; 1.78 + try 1.79 + { 1.80 + actual = Object.getPrototype(null); 1.81 + } 1.82 + catch(ex) 1.83 + { 1.84 + actual = ex + ''; 1.85 + } 1.86 + reportCompare(expect, actual, summary + ': ' + type); 1.87 + } 1.88 + 1.89 + var objects = [ 1.90 + {instance: [0], type: Array}, 1.91 + {instance: (function () {}), type: Function}, 1.92 + {instance: eval, type: Function}, 1.93 + {instance: parseInt, type: Function}, 1.94 + {instance: {a: ''}, type: Object}, 1.95 + {instance: /foo/, type: RegExp} 1.96 + ]; 1.97 + 1.98 + for (i = 0; i < objects.length; i++) 1.99 + { 1.100 + instance = objects[i].instance; 1.101 + type = objects[i].type; 1.102 + expect = type.prototype; 1.103 + actual = Object.getPrototypeOf(instance); 1.104 + reportCompare(expect, actual, summary + ' instance: ' + instance + ', type: ' + type.name); 1.105 + } 1.106 + 1.107 + var non_objects = [ true, false, 1.0, Infinity, NaN, Math.PI, "bar" ]; 1.108 + 1.109 + for (i = 0; i < non_objects.length; i++) 1.110 + { 1.111 + instance = non_objects[i]; 1.112 + expect = 'TypeError: instance is not an object'; 1.113 + try 1.114 + { 1.115 + actual = Object.getPrototypeOf(instance); 1.116 + } 1.117 + catch(ex) 1.118 + { 1.119 + actual = ex + ''; 1.120 + } 1.121 + reportCompare(expect, actual, summary + ' non-object: ' + actual); 1.122 + } 1.123 + 1.124 + exitFunc ('test'); 1.125 +}