~ubuntu-branches/ubuntu/karmic/edbrowse/karmic-security

« back to all changes in this revision

Viewing changes to jsrt

  • Committer: Bazaar Package Importer
  • Author(s): Kapil Hari Paranjape
  • Date: 2006-10-20 10:47:30 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061020104730-o7vxbrypwaz932dt
Tags: 3.1.2-1
* New upstream version (3.1.2). Closes: #306486.
  - programs now written in C
  - support for javascript.
* debian/control:
  - added Kapil Hari Paranjape to Uploaders.
  - Build-depends on "libssl-dev", "libmozjs-dev", "libpcre3-dev".
  - Standards-Version to 3.7.2. No changes required.
* debian/rules:
  - add "noopt" feature.
  - set CFLAGS and LIBS.
  - Put $(MAKE) into the build rules.
* debian/copyright: Edited to add the current copyright which
  is GPL with the exception for linking with OpenSSL.
* debian/docs: added "README".
* debian/examples: added "jsrt".

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<body onload=onlfunc() onunload=onunlfunc()>
 
2
<script language="JavaScript">
 
3
/* This is the javascript regression test for edbrowse.
 
4
It attempts to exercise all the implemented features of javascript,
 
5
which is, by the way, not all the features of javascript by any means.
 
6
Run this program after every software change,
 
7
and certainly before each release.
 
8
If a test fails, we give you the test number and abort.
 
9
Fix the bug and rerun, until all tests pass.
 
10
Warning: these tests are in no particular order, except if you rearrange
 
11
them they will fail, because some depend on variables that were
 
12
set by others.  Yeah, it's ugly. */
 
13
 
 
14
var udef = "undefined";
 
15
function fail(n) { alert("failed "+n); close(); }
 
16
 
 
17
var popwin = new Window("http://www.moreAndMoreCrap.com/BuyNow.html", "obnoxious_ad", "width=72");
 
18
 
 
19
var n, j;
 
20
// for loop with break and continue
 
21
for(n=0, j=1; j<=20; ++j) {
 
22
n += j*j;
 
23
if(j%7 == 0) continue;
 
24
--n;
 
25
if(j == 18) break;
 
26
}
 
27
if(n != 2093) fail(1);
 
28
 
 
29
// while loop with break and continue
 
30
j = 0;
 
31
while(j < 20) {
 
32
++j;
 
33
n += j*j;
 
34
if(j >= 3 && j <= 5) continue;
 
35
++n;
 
36
if(j == 7) break;
 
37
}
 
38
if(n != 2237) fail(2);
 
39
 
 
40
// else ambiguity
 
41
if(j == 7)
 
42
if(n == 29) n = 282; else n = 321;
 
43
if(n-1 != 320) fail(3);
 
44
 
 
45
// switch, default
 
46
switch(n) {
 
47
case j: j=1; break;
 
48
case 19: j=2; break;
 
49
case 321: j=3; break;
 
50
} /* switch */
 
51
if(j != 3) fail(4);
 
52
switch(n) {
 
53
case j: j=1; break;
 
54
case 19: j=2; break;
 
55
case 321: j=3;
 
56
case 11: j = 4;
 
57
} /* switch */
 
58
if(j != 4) fail(5);
 
59
switch(n) {
 
60
case j: j=1; break;
 
61
case 19: j=2; break;
 
62
default: j=3; break;
 
63
case 777: j = 7; break;
 
64
} /* switch */
 
65
if(j != 3) fail(6);
 
66
 
 
67
var bt = true; // a boolean value
 
68
var f = 6.25; // a perfectly representable floating value
 
69
if("cat" + 15 + "dog" + f + bt != "cat15dog6.25true") fail(7);
 
70
if(Math.sqrt(f) != 2.5) fail(8);
 
71
 
 
72
// silly braces and semis, and optional semis
 
73
{{
 
74
j = 7
 
75
j += 2
 
76
;;;;
 
77
j *= 3
 
78
}}
 
79
if(j != 27) fail(9);
 
80
 
 
81
if(Math.pow(11,4) != 14641) fail(10);
 
82
 
 
83
var alpha = "abc\144\x65fghijklmnopqrstuvwxyz\r\n";
 
84
if(alpha.substring(2,7) != "cdefg") fail(11);
 
85
if(alpha.length != 28) fail(12);
 
86
if(alpha.charAt(10) != 'k') fail(13);
 
87
if(alpha.indexOf("rrr") != -1) fail(15);
 
88
if(alpha.lastIndexOf("quack") != -1) fail(16);
 
89
if(alpha.indexOf("def") != 3) fail(17);
 
90
alpha += "ubcxyz";
 
91
if(alpha.lastIndexOf("bc") != 29) fail(18);
 
92
 
 
93
var a = alpha.split('b');
 
94
if(a.length != 3) fail(20);
 
95
if(a[0] != 'a') fail(21);
 
96
if(a[2] != "cxyz") fail(22);
 
97
if(a.join("--") != "a--cdefghijklmnopqrstuvwxyz\r\nu--cxyz") fail(23);
 
98
 
 
99
a = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"];
 
100
if(a.length != 7) fail(30);
 
101
a[3] = 99;
 
102
a[4] = [9, 8, 7];
 
103
if(a[3] + a[4][0] != 108) fail(32);
 
104
a.length = 6; // lop off violet
 
105
if(typeof(a[8]) != udef || a.length != 6) fail(33);
 
106
if(a[5]+a[0] != "indigored") fail(34);
 
107
 
 
108
//escape unescape
 
109
alpha = "This 3rd-line is �me!";
 
110
if(unescape(escape(alpha)) != alpha) fail(36);
 
111
 
 
112
// function with a static variable
 
113
function mult$sv(x,y)
 
114
{
 
115
++mult$sv.counter;
 
116
return mult$sv.counter*x*y;
 
117
}
 
118
mult$sv.counter = 0;
 
119
if(mult$sv(17,3) != 51) fail(40);
 
120
if(mult$sv(19,5) != 190) fail(41);
 
121
if(mult$sv.counter != 2) fail(42);
 
122
 
 
123
// A recursive function with func.x references
 
124
function factorial(n)
 
125
{
 
126
if(n <= 1) return 1;
 
127
var y = 7+n;
 
128
return n*factorial(n-1);
 
129
}
 
130
if(factorial(6) != 720) fail(44);
 
131
var bang = factorial;
 
132
if(bang(8) != 40320) fail(45);
 
133
if(bang != factorial) fail(46);
 
134
if(typeof factorial.n != udef || typeof factorial.y != udef) fail(47);
 
135
 
 
136
// vararg function
 
137
var domax = function() {
 
138
if(arguments.length != 7) fail(50);
 
139
var max = -Number.MAX_VALUE;
 
140
for(var j=0; j<arguments.length; ++j) {
 
141
var k = arguments[j];
 
142
if(k > max) max = k;
 
143
}
 
144
return max;
 
145
}
 
146
if(domax(7, 2.5, 12, -3, -955.5, 76, 19) != 76) fail(51);
 
147
 
 
148
/*********************************************************************
 
149
function fc1(x) {
 
150
 function g(z) { return z*z*z; }
 
151
return x + fc2(7);
 
152
}
 
153
function fc2(y) {
 
154
if(caller != fc1) fail(52);
 
155
return y*y + caller.g(3);
 
156
}
 
157
if(fc1(8) != 84) fail(53);
 
158
if(fc1.g(5) != 125) fail(54);
 
159
*********************************************************************/
 
160
 
 
161
var mysqrt = Math.sqrt;
 
162
if(mysqrt(1089) != 33) fail(55);
 
163
 
 
164
// bits
 
165
if((10&7) != 2) fail(60);
 
166
if((10|7) != 15) fail(61);
 
167
if((10^7) != 13) fail(62);
 
168
if(~10 != -11) fail(63);
 
169
if(10<<2 != 40) fail(64);
 
170
if(10>>2 != 2) fail(66);
 
171
if(-15 >> 2 != -4) fail(67);
 
172
if(-1 >>> 16 != 65535) fail(68);
 
173
 
 
174
// a little bit of oo stuff
 
175
// Let's make methods both ways.
 
176
function Circle()
 
177
{
 
178
this.r = 1;
 
179
if(arguments.length == 1) this.r = arguments[0];
 
180
this.c = function() { return this.r*Math.PI*2; }
 
181
this.a = CircleArea;
 
182
}
 
183
function CircleArea() { return this.r*this.r*Math.PI; }
 
184
var c1 = new Circle();
 
185
var c2 = new Circle(23);
 
186
// also test the with construct
 
187
with(Math) {
 
188
if(c1.r != 1 || c2.r != 23) fail(70);
 
189
c2.r = 10;
 
190
if(c2.a() != 100*PI) fail(72);
 
191
}
 
192
n = "";
 
193
for(j in c2) n += j;
 
194
if(n != "rca") fail(73);
 
195
 
 
196
// internal sort
 
197
a = new Array("red", "orange", "yellow", "green", "blue", "indigo", "violet");
 
198
function acmp(x,y) { return x > y ? 1 : -1; }
 
199
a.sort(acmp);
 
200
if(a.join(':') != "blue:green:indigo:orange:red:violet:yellow") fail(74);
 
201
if(a.length != 7) fail(75);
 
202
if(a[5] != "violet") fail(76);
 
203
 
 
204
var oo = new Object;
 
205
if(typeof oo != "object") fail(77);
 
206
oo.p = 61, oo.q = 67;
 
207
n = "";
 
208
for(j in oo) n += j+oo[j];
 
209
if(n != "p61q67") fail(78);
 
210
if(c2.constructor != Circle || oo.constructor != Object) fail(79);
 
211
 
 
212
// the date object
 
213
var d = new Date(2003,11,25,17,55,9);
 
214
d.setYear(d.getYear()-1);
 
215
if(d.getMonth() != 11 || d.getDate() != 25) fail(81);
 
216
if(d.getHours() != 17 || d.getMinutes() != 55 || d.getSeconds() != 9) fail(82);
 
217
if(d.constructor != Date || a.constructor != Array) fail(84);
 
218
 
 
219
// default this
 
220
function topthis() { this.topprop = 887; }
 
221
topthis();
 
222
if(topprop != 887) fail(88);
 
223
 
 
224
// A couple functions, and the first couple lines of the input form.
 
225
function calc(thisform)
 
226
    {
 
227
var l = thisform.body.value.length;
 
228
thisform.result.value = l;
 
229
if (l > 2000) {
 
230
alert("You cant go over Limit of 2000 Characters!");
 
231
}
 
232
    }
 
233
document.writeln("<form method=POST \
 
234
name=questionnaire \
 
235
onsubmit='return submitFunction(questionnaire)' \
 
236
onreset='return resetFunction()' \
 
237
onload=formLoad(this.name) onunload=formUnload(this.name)>");
 
238
// The rest of the form you'll see in straight html
 
239
// Let javascript generate another javascript tag
 
240
document.writeln("<script language=JavaScript>document.writeln('Subject: ');</" + "script>");
 
241
 
 
242
</script>
 
243
 
 
244
<input type='hidden' name='id' value='eklhad'>
 
245
<input type='hidden' name='password' value='secret'>
 
246
<input type='text' name='subject' size='50' maxlength='80'>
 
247
<br>State and zip:
 
248
<select name=state onchange=newSelect(this)>
 
249
<option selected value=-->
 
250
Please choose one
 
251
<option value=AL>
 
252
Alabama
 
253
<option value=AK>
 
254
Alaska
 
255
<option value=AS>
 
256
American Samoa
 
257
<option value=AZ>
 
258
Arizona
 
259
<option value=AR>
 
260
Arkansas
 
261
<option value=CA>
 
262
California
 
263
<option value=CO>
 
264
Colorado
 
265
<option value=CT>
 
266
Connecticut
 
267
<option value=DE>
 
268
Delaware
 
269
<option value=DC>
 
270
District Of Columbia
 
271
<option value=FM>
 
272
Federated States Of Micronesia
 
273
<option value=FL>
 
274
Florida
 
275
<option value=GA>
 
276
Georgia
 
277
<option value=GU>
 
278
Guam
 
279
<option value=HI>
 
280
Hawaii
 
281
<option value=ID>
 
282
Idaho
 
283
<option value=IL>
 
284
Illinois
 
285
<option value=IN>
 
286
Indiana
 
287
<option value=IA>
 
288
Iowa
 
289
<option value=KS>
 
290
Kansas
 
291
<option value=KY>
 
292
Kentucky
 
293
<option value=LA>
 
294
Louisiana
 
295
<option value=ME>
 
296
Maine
 
297
<option value=MH>
 
298
Marshall Islands
 
299
<option value=MD>
 
300
Maryland
 
301
<option value=MA>
 
302
Massachusetts
 
303
<option value=MI>
 
304
Michigan
 
305
<option value=MN>
 
306
Minnesota
 
307
<option value=MS>
 
308
Mississippi
 
309
<option value=MO>
 
310
Missouri
 
311
<option value=MT>
 
312
Montana
 
313
<option value=NE>
 
314
Nebraska
 
315
<option value=NV>
 
316
Nevada
 
317
<option value=NH>
 
318
New Hampshire
 
319
<option value=NJ>
 
320
New Jersey
 
321
<option value=NM>
 
322
New Mexico
 
323
<option value=NY>
 
324
New York
 
325
<option value=NC>
 
326
North Carolina
 
327
<option value=ND>
 
328
North Dakota
 
329
<option value=MP>
 
330
Northern Mariana Islands
 
331
<option value=OH>
 
332
Ohio
 
333
<option value=OK>
 
334
Oklahoma
 
335
<option value=OR>
 
336
Oregon
 
337
<option value=PW>
 
338
Palau
 
339
<option value=PA>
 
340
Pennsylvania
 
341
<option value=PR>
 
342
Puerto Rico
 
343
<option value=RI>
 
344
Rhode Island
 
345
<option value=SC>
 
346
South Carolina
 
347
<option value=SD>
 
348
South Dakota
 
349
<option value=TN>
 
350
Tennessee
 
351
<option value=TX>
 
352
Texas
 
353
<option value=UT>
 
354
Utah
 
355
<option value=VT>
 
356
Vermont
 
357
<option value=VI>
 
358
Virgin Islands
 
359
<option value=VA>
 
360
Virginia
 
361
<option value=WA>
 
362
Washington
 
363
<option value=WV>
 
364
West Virginia
 
365
<option value=WI>
 
366
Wisconsin
 
367
<option value=WY>
 
368
Wyoming
 
369
<option value=BH>
 
370
90210
 
371
</select>
 
372
<input type=number maxlength=5 name="zip code" readonly value="&#56;8888">
 
373
<span id=almond></span>
 
374
<table><tr></tr><tr id=pecan></tr></table>
 
375
<br>My favorite colors are:
 
376
<select name=colors multiple>
 
377
<option> red
 
378
<option> orange
 
379
<option> yellow
 
380
<option selected> green
 
381
<option> blue
 
382
<option> indigo
 
383
<option> violet
 
384
<option selected> white
 
385
<-- MSU colors -->
 
386
</select>
 
387
<br>Salary range:
 
388
poverty
 
389
<input type=radio name=money value=0>
 
390
gettin-by
 
391
<input type=radio name=money value=1 checked>
 
392
comfortable
 
393
<input type=radio name=money value=2>
 
394
rich
 
395
<input type=radio name=money value=3>
 
396
<br>Pets:
 
397
dog <input type=checkbox name=dog id=hound checked onclick=alert('rover')>
 
398
cat <input type=checkbox name=cat onclick="alert('fluffy'); if(this.checked&&questionnaire.dog.checked) alert('chased by dog');" value=meow>
 
399
bird <input type=checkbox name=bird>
 
400
rabbit <input type=checkbox name=rabbit>
 
401
<br>Message Body:
 
402
<textarea name='body' rows='6' cols='50'>
 
403
Type your brilliant thoughts here.
 
404
We'll get back to you if we like what you have to say.
 
405
</textarea>
 
406
<br>
 
407
<input type=button name=b value=calc onclick=calc(this.form)>
 
408
<input type='text' readonly name='result' size='4'>
 
409
<input type='reset' value='Reset' name='b0'>
 
410
<input type='submit' value='Send Message' name='b1'
 
411
onclick="alert('rock and roll')">
 
412
</form>
 
413
<bgsound src=whatever.mid>
 
414
 
 
415
<script language="JavaScript">
 
416
// I'll push the button for you
 
417
document.questionnaire.b.onclick();
 
418
if(document.questionnaire.result.value != 90) fail(85);
 
419
if(document.questionnaire.id.value != "eklhad") fail(86);
 
420
if(document.forms[0].elements[1].value != "secret") fail(87);
 
421
 
 
422
// prototype objects, use the Circle model
 
423
Circle.prototype.q = 97;
 
424
Circle.prototype.m = function(z) { return z*z*z; };
 
425
c2.q = 84; // hide 97
 
426
if(c1.q != 97) fail(90);
 
427
if(c2.q != 84) fail(91);
 
428
if(c1["m"](9) != 729) fail(92);
 
429
with(c1) {
 
430
if(q != 97) fail(93);
 
431
if(m(7) != 343) fail(94);
 
432
}
 
433
 
 
434
// prototype an implicite class
 
435
String.prototype.xy = function() {
 
436
return this.replace(/x/g, 'y');
 
437
}
 
438
n = "sixty";
 
439
if(n.xy() != "siyty") fail(95);
 
440
if("fix my fox".xy() != "fiy my foy") fail(96);
 
441
Array.prototype.firstLast = function() {
 
442
var temp = this[0];
 
443
var l = this.length-1;
 
444
this[0] = this[l];
 
445
this[l] = temp;
 
446
};
 
447
a = [17,21,25];
 
448
a.firstLast();
 
449
if(a.join('zz') != "25zz21zz17") fail(97);
 
450
 
 
451
// check some of the element tags
 
452
with(document.questionnaire) {
 
453
if(!(dog.checked && dog.defaultChecked)) fail(100);
 
454
if(cat.checked || cat.defaultChecked) fail(101);
 
455
if(dog.type != "checkbox" || money.type != "radio" || money.length != 4) fail(102);
 
456
if(id.type != "hidden" || subject.type != "text") fail(103);
 
457
if(b0.type != "reset" || b1.type != "submit") fail(104);
 
458
if(body.type != "textarea" || b.type != "button") fail(105);
 
459
if(state.type != "select-one" || colors.type != "select-multiple") fail(106);
 
460
if(id.defaultValue != "eklhad") fail(107);
 
461
if(body.value.substring(10,19) != "brilliant") fail(108);
 
462
// focus and blur are ignored
 
463
dog.focus();
 
464
cat.blur();
 
465
focus();
 
466
blur();
 
467
}
 
468
 
 
469
// for(var i in document.idMaster) alert(i);
 
470
if(document.getElementById("hound").name != "dog") fail(110);
 
471
if(document.getElementById("almond") != document.spans[0]) fail(111);
 
472
// I'm not sure of any of this table row stuff
 
473
if(document.getElementById("pecan") != document.tables[0].rows[1]) fail(112);
 
474
if(document.all.tags("FORM")[0] != document.questionnaire) fail(113);
 
475
if(document.all.tags("span").length != 1) fail(114);
 
476
 
 
477
n = 0;
 
478
a = [29,31,37];
 
479
for(j in a) {
 
480
if(j.length > 1) continue;
 
481
n += (j*1+2)*a[j];
 
482
}
 
483
if(n != 299) fail(119);
 
484
 
 
485
/* inline object */
 
486
var ilo = {a:document.questionnaire, b:9+5*3};
 
487
if(typeof ilo.a != "object") fail(120);
 
488
if(ilo.b != 24) fail(121);
 
489
if(ilo.a.id.value != "eklhad") fail(122);
 
490
 
 
491
function submitFunction(me) {
 
492
if(document.questionnaire != me) fail(123);
 
493
var where = prompt("Enter m for mail, w for web, a to autosubmit, x to abort.", "x");
 
494
me.action =
 
495
(where == 'm' ? "mailto:karl@eklhad.net" : "http://localhost:1200/foobar");
 
496
if(where == 'a') me.submit();
 
497
if(where != 'm' && where != 'w') return false;
 
498
return true;
 
499
}
 
500
 
 
501
function resetFunction() {
 
502
return confirm("All that hard work, are you sure you want to reset?");
 
503
}
 
504
 
 
505
function newSelect(e) {
 
506
alert(e.name + " in " + e.form.name + " has become " +
 
507
e.options[e.selectedIndex].value);
 
508
}
 
509
 
 
510
function onlfunc() {
 
511
alert("page loading");
 
512
}
 
513
function onunlfunc() {
 
514
if(confirm("Care to visit MathReference.com"))
 
515
new Window("http://www.mathreference.com");
 
516
else alert("ok, never mind");
 
517
}
 
518
function formLoad(name) { onlv++; alert("form " + name + " loading"); }
 
519
function formUnload(name) { alert("form " + name + " unloading"); }
 
520
var onlv = 77;
 
521
 
 
522
setTimeout("joker()", 750);
 
523
function joker()
 
524
{
 
525
alert("times up!");
 
526
document.writeln("<P>Some extra html in another buffer.");
 
527
}
 
528
 
 
529
</script>
 
530
 
 
531
</body>