1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_5/Function/builtin-no-construct.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,52 @@ 1.4 +/* 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/licenses/publicdomain/ 1.7 + */ 1.8 + 1.9 +function checkMethod(method) { 1.10 + try { 1.11 + new method(); 1.12 + assertEq(0, 1, "not reached " + method); 1.13 + } catch (e) { 1.14 + assertEq(e.message, "method is not a constructor"); 1.15 + } 1.16 +} 1.17 + 1.18 +function checkMethods(proto) { 1.19 + var names = Object.getOwnPropertyNames(proto); 1.20 + for (var i = 0; i < names.length; i++) { 1.21 + var name = names[i]; 1.22 + if (name == "constructor") 1.23 + continue; 1.24 + var prop = proto[name]; 1.25 + if (typeof prop === "function") 1.26 + checkMethod(prop); 1.27 + } 1.28 +} 1.29 + 1.30 +checkMethod(Function.prototype); 1.31 +checkMethods(JSON); 1.32 +checkMethods(Math); 1.33 +checkMethods(Proxy); 1.34 + 1.35 +var builtin_ctors = [ 1.36 + Object, Function, Array, String, Boolean, Number, Date, RegExp, Error, 1.37 + EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError, 1.38 +]; 1.39 + 1.40 +for (var i = 0; i < builtin_ctors.length; i++) { 1.41 + checkMethods(builtin_ctors[i]); 1.42 + checkMethods(builtin_ctors[i].prototype); 1.43 +} 1.44 + 1.45 +var builtin_funcs = [ 1.46 + eval, isFinite, isNaN, parseFloat, parseInt, 1.47 + decodeURI, decodeURIComponent, encodeURI, encodeURIComponent 1.48 +]; 1.49 + 1.50 +for (var i = 0; i < builtin_funcs.length; i++) { 1.51 + checkMethod(builtin_funcs[i]); 1.52 +} 1.53 + 1.54 +if (typeof reportCompare == 'function') 1.55 + reportCompare(0, 0, "ok");