]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma_3/Object/shell.js
2 * The contents of this file are subject to the Netscape Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/NPL/
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is mozilla.org code.
14 * The Initial Developer of the Original Code is Netscape
15 * Communications Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
19 * Contributor(s): pschwartau@netscape.com
22 * SUMMARY: Utility functions for testing objects -
24 * Suppose obj is an instance of a native type, e.g. Number.
25 * Then obj.toString() invokes Number.prototype.toString().
26 * We would also like to access Object.prototype.toString().
28 * The difference is this: suppose obj = new Number(7).
29 * Invoking Number.prototype.toString() on this just returns 7.
30 * Object.prototype.toString() on this returns '[object Number]'.
32 * The getJSType() function below will return '[object Number]' for us.
33 * The getJSClass() function returns 'Number', the [[Class]] property of obj.
34 * See ECMA-262 Edition 3, 13-Oct-1999, Section 8.6.2
36 //-------------------------------------------------------------------------------------------------
37 var cnNoObject
= 'Unexpected Error!!! Parameter to this function must be an object';
38 var cnNoClass
= 'Unexpected Error!!! Cannot find Class property';
39 var cnObjectToString
= Object
.prototype.toString
;
42 // checks that it's safe to call findType()
43 function getJSType(obj
)
51 // checks that it's safe to call findType()
52 function getJSClass(obj
)
55 return findClass(findType(obj
));
60 function findType(obj
)
62 return cnObjectToString
.apply(obj
);
66 // given '[object Number]', return 'Number'
67 function findClass(sType
)
69 var re
= /^\[.*\s+(\w+)\s*\]$/;
70 var a
= sType
.match(re
);
78 function isObject(obj
)
80 return obj
instanceof Object
;