Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
133 lines (112 loc) · 4.62 KB

File metadata and controls

133 lines (112 loc) · 4.62 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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 + ""); }
Object.prototype.oString = Object.prototype.toString;
Array.prototype.oString = Object.prototype.toString;
Boolean.prototype.oString = Object.prototype.toString;
Date.prototype.oString = Object.prototype.toString;
Function.prototype.oString = Object.prototype.toString;
Number.prototype.oString = Object.prototype.toString;
RegExp.prototype.oString = Object.prototype.toString;
String.prototype.oString = Object.prototype.toString;
var x = 0;
function testEval(str) {
eval(str);
write(str + " x:" + x + " typeof(x):" + typeof(x) + " x.str():" + x.oString());
}
function foo() {}
var objs = [ "undefined", "null",
"true", "false",
"Boolean(true)", "Boolean(false)",
"new Boolean(true)", "new Boolean(false)",
"NaN", "+0", "-0", "0", "0.0", "-0.0", "+0.0",
"1", "10", "10.0", "10.1", "-1",
"-10", "-10.0", "-10.1",
"Number.MAX_VALUE", "Number.MIN_VALUE", "Number.NaN", "Number.POSITIVE_INFINITY", "Number.NEGATIVE_INFINITY",
"new Number(NaN)", "new Number(+0)", "new Number(-0)", "new Number(0)",
"new Number(0.0)", "new Number(-0.0)", "new Number(+0.0)",
"new Number(1)", "new Number(10)", "new Number(10.0)", "new Number(10.1)", "new Number(-1)",
"new Number(-10)", "new Number(-10.0)", "new Number(-10.1)",
"new Number(Number.MAX_VALUE)", "new Number(Number.MIN_VALUE)", "new Number(Number.NaN)",
"new Number(Number.POSITIVE_INFINITY)", "new Number(Number.NEGATIVE_INFINITY)",
"''", "0xa", "04", "'hello'", "'hel' + 'lo'",
"String('')", "String('hello')", "String('h' + 'ello')",
"new String('')", "new String('hello')", "new String('he' + 'llo')",
"new Object()", "new Object()",
"[1, 2, 3]", "[1 ,2 , 3]",
"new Array(3)", "Array(3)", "new Array(1 ,2 ,3)", "Array(1)",
"foo"
];
testEval("x = Object();");
testEval("x = new Object();");
for (var i=0; i< objs.length; i++) {
testEval("x = Object(" + objs[i] + ");");
testEval("x = new Object(" + objs[i] + ");");
}
Object.prototype.protoFunc = function () { WScript.Echo("ObjectprotoFunc");}
var customPrototype = { protoFunc: function () { WScript.Echo("protoFunc");}}
// Constructor with only this statements
function constr(arg1, arg2)
{
this.a = arg1;
this.b = arg1;
}
// Constructor with more than only this statements
function constr1(arg1, arg2)
{
if(!arg1) arg1 = 0;
if(!arg2) arg2 = 0;
this.a = arg1;
this.b = arg1;
}
function body()
{
var arr = [];
for(var i= 0; i < 2; i++)
{
arr.push(new constr(1, 2, 3)); // with arg constructor cache
arr.push(new constr()); // no arg constructor cache test
arr.push(new constr1(1, 2, 3)); // with arg constructor cache
arr.push(new constr1()); // no arg constructor cache test
}
return arr;
}
WScript.Echo("Testing no prototype property construction");
var arrayOfObjects = body();
Dump(arrayOfObjects);
WScript.Echo("Testing custom object prototype construction");
constr.prototype = customPrototype;
constr1.prototype = customPrototype;
arrayOfObjects = body();
Dump(arrayOfObjects);
WScript.Echo("Testing integer prototype construction");
constr.prototype = 1;
constr1.prototype = 1;
arrayOfObjects = body();
Dump(arrayOfObjects);
WScript.Echo("Testing no prototype property construction");
delete constr.prototype;
delete constr1.prototype;
arrayOfObjects = body();
Dump(arrayOfObjects);
function Dump(arrayOfObjects)
{
for(var j= 0; j < arrayOfObjects.length; j++)
{
arrayOfObjects[j].protoFunc();
}
}
WScript.Echo("Testing cross script context object creation");
var otherScriptContext = WScript.LoadScriptFile("constructor-crossScript.js", "samethread");
var obj = new otherScriptContext.crossContextObject();
WScript.Echo(obj.prop);
obj = new otherScriptContext.crossContextObject();
WScript.Echo(obj.prop);
obj = otherScriptContext.createObject();
WScript.Echo(obj.prop);
obj = otherScriptContext.createObject();
WScript.Echo(obj.prop);
obj = new otherScriptContext.crossContextObject();
WScript.Echo(obj.prop);
Morty Proxy This is a proxified and sanitized view of the page, visit original site.