Skip to content

Commit 65ae47f

Browse files
committed
make output a bit nicer
1 parent 3057d25 commit 65ae47f

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ <h1>engine262</h1>
4949

5050
<section id="output-section">
5151
<h2>Output:</h2>
52-
<textarea id="output" cols="80" autocomplete="off" disabled></textarea>
52+
<div id="output"></div>
5353
</section>
5454
</main>
5555

src/runner.mjs

+17-4
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,27 @@ function respawn(first = false) {
5252
});
5353
} else if (data.type === 'console') {
5454
if (data.value.method === 'clear') {
55-
output.value = '';
55+
const range = document.createRange();
56+
range.selectNodeContents(output);
57+
range.deleteContents();
5658
} else {
59+
const line = document.createElement('span');
5760
data.value.values.forEach((v) => {
58-
output.value += v;
59-
output.value += ' ';
61+
line.textContent += v;
62+
line.textContent += ' ';
6063
});
61-
output.value += '\n';
64+
const container = document.createElement('div');
65+
container.className = `log-${data.value.method}`;
66+
container.appendChild(line);
67+
output.appendChild(container);
6268
}
69+
} else if (data.type === 'unhandledRejection') {
70+
const line = document.createElement('span');
71+
line.textContent = `Unhandled Rejection:\n${data.value}`;
72+
const container = document.createElement('div');
73+
container.className = 'log-error';
74+
container.appendChild(line);
75+
output.appendChild(container);
6376
}
6477
});
6578
}

src/worker.js

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
/* eslint-env worker */
4+
/* eslint-disable no-restricted-globals */
45

56
importScripts('https://unpkg.com/acorn@7.0.0/dist/acorn.js');
67
importScripts('https://unpkg.com/nearley@2.16.0/lib/nearley.js');
@@ -29,6 +30,15 @@ addEventListener('message', ({ data }) => {
2930
try {
3031
initializeAgent({
3132
features: [...state.get('features')],
33+
promiseRejectionTracker(promise, operation) {
34+
if (operation === 'reject') {
35+
postMessage({
36+
type: 'unhandledRejection',
37+
// eslint-disable-next-line no-use-before-define
38+
value: inspect(promise.PromiseResult, realm),
39+
});
40+
}
41+
},
3242
});
3343
} catch (e) {
3444
// o.o

style.css

+25
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,41 @@ textarea:disabled {
4747
border: 1px solid black;
4848
color: black;
4949
}
50+
5051
#input-section, #output-section {
5152
display: flex;
5253
flex-direction: column;
5354
flex-grow: 1;
5455
flex-shrink: 1;
5556
}
57+
5658
#output {
5759
flex-grow: 1;
5860
min-height: 200px;
61+
background-color: white;
62+
border: 1px solid black;
63+
font-family: monospace;
64+
white-space: pre-wrap;
65+
}
66+
#output > div {
67+
padding-left: 0.3em;
68+
}
69+
70+
[class*="log"] {
71+
border-bottom: 1px solid black;
72+
}
73+
74+
.log-warn {
75+
background-color: yellow;
76+
}
77+
78+
.log-debug {}
79+
80+
.log-error {
81+
background-color: #FF000070;
5982
}
83+
84+
6085
#features {
6186
margin: 0;
6287
padding: 0;

0 commit comments

Comments
 (0)