blob: 3cc33298dd17be756052e53afe4db0abfd38a272 (
plain)
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
<html>
<head>
<title>Ruby Example</title>
<script type="text/javascript">
RubyModule = null;
statusText = 'NO-STATUS';
rubyReady = false;
function moduleDidLoad() {
RubyModule = document.getElementById('ruby');
form = document.getElementById('source-form');
form.style.display = "block";
updateStatus('SUCCESS');
}
function evalSource() {
if (rubyReady) {
RubyModule.postMessage('eval:' + document.getElementById("source").value);
} else {
throw "Not yet ready";
}
return false;
}
function RubyError(message) {
this.message = message;
this.toString = function() {
return message;
}
}
function FatalError(message) {
this.message = message;
}
function handleMessage(message_event) {
var raw = message_event.data;
var components;
if (raw.indexOf("error") == 0) {
components = raw.split(":", 2);
throw new RubyError(components[1]);
} else if (raw.indexOf("return") == 0) {
components = raw.split(":", 2);
document.getElementById("result").value = components[1];
} else if (raw == "rubyReady") {
rubyReady = true;
} else {
throw new FatalError(raw);
}
}
function pageDidLoad() {
if (RubyModule == null) {
updateStatus('LOADING...');
} else {
updateStatus();
}
}
function updateStatus(opt_message) {
if (opt_message)
statusText = opt_message;
var statusField = document.getElementById('status_field');
if (statusField) {
statusField.innerHTML = statusText;
}
}
</script>
</head>
<body onload="pageDidLoad()">
<h1>Native Client Module Ruby</h1>
<p>
<div id="listener">
<script type="text/javascript">
var listener = document.getElementById('listener');
listener.addEventListener('load', moduleDidLoad, true);
listener.addEventListener('message', handleMessage, true);
</script>
<embed name="nacl_module"
id="ruby"
width="0" height="0"
src="ruby.nmf"
type="application/x-nacl" />
<form id="source-form" action="#" method="post" style="display:none"
onsubmit="evalSource(); return false">
<table>
<tbody>
<tr>
<th>Source</th>
<td>
<textarea rows="10" cols="80" id="source"></textarea>
<input type="submit" />
</td>
</tr>
<tr>
<th>Result</th>
<td>
<textarea rows="10" cols="80" id="result"></textarea>
</td>
</tr>
</tbody>
</table>
</form>
</div>
</p>
<h2>Status</h2>
<div id="status_field">NO-STATUS</div>
</body>
</html>
|