-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathpropertyIsEnumerable.js
133 lines (111 loc) · 5.6 KB
/
propertyIsEnumerable.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
function write(v) { WScript.Echo(v + ""); }
function foo() { this.y = 10; }
var o = new Object();
var f = new foo();
var a = new Array();
var s = new String("hello");
var b = new Boolean(true);
var n = new Number(10);
var d = new Date();
var r = new RegExp();
var e = new Error();
o.x = f.x = foo.x = a.x = s.x = b.x = n.x = d.x = r.x = e.x = 10;
function doEval(str)
{
//write(str);
write(str + " : " + eval(str));
}
// Check for standard properties on various built-in constructors
function Test1() {
var objs = [
"Object", "Function", "Array", "String", "Boolean", "Number", "Math", "Date", "RegExp", "Error",
"Object.prototype", "Function.prototype", "Array.prototype", "String.prototype", "Boolean.prototype",
"Number.prototype", "Date.prototype", "RegExp.prototype", "Error.prototype",
"o", "f", "foo", "foo.prototype", "a", "s", "b", "n", "d", "r", "e"
]
var props = [
"abs", "acos", "anchor", "apply", "Array", "asin", "atan", "atan2", "big", "bind",
"blink", "bold", "Boolean", "call", "ceil", "charAt", "charCodeAt", "concat", "constructor", "cos",
"Date", "decodeURI", "decodeURIComponent", "description", "E", "encodeURI", "encodeURIComponent", "escape", "Error", "eval", "EvalError",
"every", "exec", "exp", "flags", "filter", "fixed", "floor", "fontcolor", "fontsize", "forEach",
"fromCharCode", "Function", "getDate", "getDay", "getFullYear", "getHours", "getMilliseconds", "getMinutes", "getMonth", "getSeconds",
"getTime", "getTimezoneOffset", "getUTCDate", "getUTCDay", "getUTCFullYear", "getUTCHours", "getUTCMilliseconds", "getUTCMinutes", "getUTCMonth",
"getUTCSeconds", "getYear", "hasOwnProperty", "indexOf", "Infinity", "isFinite", "isNaN", "isPrototypeOf", "italics", "join", "lastIndexOf",
"length", "link", "LN10", "LN2", "localeCompare", "log", "LOG10E", "LOG2E", "map", "Math",
"max", "MAX_VALUE", "match", "message", "min", "MIN_VALUE", "NaN", "name", "Now", "Number",
"number", "NEGATIVE_INFINITY", "Object", "parse", "parseFloat", "parseInt", "PI", "pop", "POSITIVE_INFINITY", "pow",
"propertyIsEnumerable", "prototype", "push", "random", "RangeError", "reduce", "reduceRight", "ReferenceError", "replace", "reverse",
"round", "RegExp", "search", "setDate", "setFullYear", "setHours", "setMilliseconds", "setMinutes", "setMonth", "setSeconds",
"setTime", "setUTCDate", "setUTCFullYear", "setUTCHours", "setUTCMilliseconds", "setUTCMinutes", "setUTCMonth", "setUTCSeconds", "setYear", "shift",
"sin", "slice", "some", "sort", "source", "splice", "split", "sqrt", "SQRT1_2", "SQRT2",
"strike", "String", "sub", "substring", "substr", "sup", "SyntaxError", "tan", "test", "toDateString",
"toExponential", "toFixed", "toISOString", "toJSON", "toLocaleDateString", "toLocaleLowerCase", "toLocaleString", "toLocaleTimeString",
"toLocaleUpperCase", "toLowerCase", "toPrecision", "toString", "toTimeString", "toUpperCase", "toUTCString", "trim", "TypeError", "undefined",
"unescape", "unshift", "URIError", "UTC", "valueOf", "enumerable", "configurable", "writable", "value", "get", "set", "defineProperty",
"defineProperties", "toGMTString", "compile", "global", "lastIndex", "multiline", "ignoreCase", "index", "input",
"lastMatch", "lastParen", "leftContext", "rightContext",
"x", "y"
];
for (var i=0; i<objs.length; i++)
{
for (var j=0; j< props.length; j++)
{
doEval(objs[i] + ".propertyIsEnumerable(\"" + props[j] + "\")");
}
}
}
function Test2() {
function base() {
this.x = "base.x";
this.y = "base.y";
}
function derived() {
this.y = "derived.y";
this.z = "derived.z";
}
derived.prototype = new base();
var d = new derived();
write("Test2 d.propertyIsEnumerable(x): " + d.propertyIsEnumerable("x"));
write("Test2 d.propertyIsEnumerable(y): " + d.propertyIsEnumerable("y"));
write("Test2 d.propertyIsEnumerable(z): " + d.propertyIsEnumerable("z"));
write("Test2 d.hasOwnProperty(x): " + d.hasOwnProperty("x"));
write("Test2 d.hasOwnProperty(y): " + d.hasOwnProperty("y"));
write("Test2 d.hasOwnProperty(z): " + d.hasOwnProperty("z"));
}
function Test3() {
try {
write(Object.prototype.propertyIsEnumerable.call(undefined, "length"));
} catch (e) {
write("Exception: " + e + " " + e.message);
}
try {
write(Object.prototype.propertyIsEnumerable.call(null, "length"));
} catch (e) {
write("Exception: " + e + " " + e.message);
}
}
var re = new RegExp("d(b+)(d)", "ig");
function TestRegex()
{
var propso = [
"lastIndex", "source", "global", "ignoreCase", "multiline", "options"];
var props = [
"input","$_","index","lastIndex","lastMatch",'$&',"lastParen",'$+','$`',"rightContext",
"$'","$2","$3","$4","$5","$6","$7","$8","$9"];
for (var j=0; j< props.length; j++)
{
doEval("re" + ".propertyIsEnumerable(\"" + propso[j] + "\")");
}
for (var j=0; j< props.length; j++)
{
doEval("RegExp" + ".propertyIsEnumerable(\"" + props[j] + "\")");
}
}
Test1();
Test2();
Test3();
TestRegex();