Debian Codegraph @

rhino/toolsrc/org/mozilla/javascript/tools/debugger/test.js

raw symbols SCIP
1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
8 // Test file for Rhino debugger
9
10
11
12 var x = 12;
13
14 function sleep(millis)
15 {
16 java.lang.Thread.sleep(millis);
17 }
18
19 function thread_loop_body(counter, thread_title)
20 {
21 print("["+counter+"] Thread '"+thread_title);
22 sleep(1000);
23 }
24
25 function make_thread(thread_title, repeat_count, loop_body)
26 {
27 var Thread = java.lang.Thread;
28 var thread = new Thread(function() {
29 for (var i = 0; i < repeat_count; ++i) {
30 loop_body(i, thread_title);
31 }
32 print("[DONE] Thread "+thread_title);
33 });
34 return thread;
35 }
36
37 function make_thread2(thread_title, repeat_count, loop_body, loop_end)
38 {
39 var Thread = java.lang.Thread;
40 var thread = new Thread(function() {
41 create_gui();
42 for (var i = 0; i < repeat_count; ++i) {
43 loop_body(i, thread_title);
44 }
45 loop_end(thread_title);
46 });
47 return thread;
48 }
49
50
51 var loop_body_text = thread_loop_body.toSource(0);
52 var loop_body;
53 eval("loop_body = "+loop_body_text);
54
55 var thread1 = make_thread("A", 5, loop_body);
56 var thread2 = make_thread("B", 1000, loop_body);
57 var thread3 = make_thread2("C", 2, loop_body,
58 function loop_end(thread_title) {
59 print("[DONE] Thread "+thread_title);
60 // Do somethig to throw exception
61 Math.xxxx();
62 });
63
64 thread1.start();
65 thread2.start();
66 thread3.start();
67
68 thread1.join();
69 thread2.join();
70 thread3.join();
71
72
73 function create_gui()
74 {
75 var swing = Packages.javax.swing;
76 var awt = Packages.java.awt;
77
78 var frame = new swing.JFrame("SwingApplication");
79 var labelPrefix = "Number of button clicks: ";
80 var numClicks = 0;
81 var label = new swing.JLabel(labelPrefix + numClicks);
82 var button = new swing.JButton("Click Me!");
83 button.mnemonic = Packages.java.awt.event.KeyEvent.VK_I;
84 button.addActionListener(function() {
85 numClicks += 1;
86 label.setText(labelPrefix + numClicks);
87 });
88 label.setLabelFor(button);
89
90 var pane = new swing.JPanel();
91 pane.setLayout(new awt.GridLayout(0, 1));
92 pane.add(button);
93 pane.add(label);
94
95 frame.getContentPane().add(pane, awt.BorderLayout.CENTER);
96 frame.addWindowListener(function(event, methodName) {
97 print(event + " "+methodName);
98 if (methodName == "windowClosing") {
99 //java.lang.System.exit(0);
100 }
101 });
102
103 //Finish setting up the frame, and show it.
104 frame.pack();
105 frame.setVisible(true);
106
107 }
108