Skip to content

Commit 1beabd7

Browse files
committed
Reverted to earlier error reporting
1 parent 0eb7473 commit 1beabd7

File tree

5 files changed

+561
-18
lines changed

5 files changed

+561
-18
lines changed

GlowScriptOffline2.7.zip

0 Bytes
Binary file not shown.

test.html

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<div id="glowscript" class="glowscript">
2+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
3+
<link type="text/css" href="https://s3.amazonaws.com/glowscript/css/redmond/2.1/jquery-ui.custom.css" rel="stylesheet" />
4+
<link href="https://fonts.googleapis.com/css?family=Inconsolata" rel="stylesheet" type="text/css" />
5+
<link type="text/css" href="https://s3.amazonaws.com/glowscript/css/ide.css" rel="stylesheet" />
6+
<script type="text/javascript" src="https://s3.amazonaws.com/glowscript/lib/jquery/2.1/jquery.min.js"></script>
7+
<script type="text/javascript" src="https://s3.amazonaws.com/glowscript/lib/jquery/2.1/jquery-ui.custom.min.js"></script>
8+
<script type="text/javascript" src="package/glow.2.7.min.js"></script>
9+
<script type="text/javascript" src="package/RSrun.2.7.min.js"></script>
10+
<script type="text/javascript"><!--//--><![CDATA[//><!--
11+
12+
// START JAVASCRIPT
13+
;(function() {"use strict";
14+
15+
var regeneratorRuntime = typeof srequire === 'function' ? srequire("streamline-runtime/lib/callbacks/regenerator") : Streamline.srequire("streamline-runtime/lib/callbacks/regenerator");
16+
17+
var _streamline = typeof srequire === 'function' ? srequire("streamline-runtime/lib/callbacks/runtime") : Streamline.srequire("streamline-runtime/lib/callbacks/runtime");
18+
19+
var _filename = "unknown";
20+
21+
var main = _streamline.async(regeneratorRuntime.mark(function _$$main$$(_2) {
22+
var version, aaa, box, sphere, simple_sphere, cylinder, pyramid, cone, helix, ellipsoid, ring, arrow, compound, display, vector, print, type, scene, RS_ls, __name__, strings;
23+
24+
return regeneratorRuntime.wrap(function _$$main$$$(_context) {
25+
while (1) {
26+
switch (_context.prev = _context.next) {
27+
case 0:
28+
version = RS_list_decorate(["2.7", "glowscript"]);
29+
Array.prototype['+'] = function (r) {
30+
return this.concat(r);
31+
};
32+
Array.prototype['*'] = function (r) {
33+
return __array_times_number(this, r);
34+
};
35+
__name__ = '__main__';
36+
37+
window.__GSlang = "vpython";
38+
box = vp_box;
39+
sphere = vp_sphere;
40+
simple_sphere = vp_simple_sphere;
41+
cylinder = vp_cylinder;
42+
pyramid = vp_pyramid;
43+
cone = vp_cone;
44+
helix = vp_helix;
45+
ellipsoid = vp_ellipsoid;
46+
ring = vp_ring;
47+
arrow = vp_arrow;
48+
compound = vp_compound;
49+
display = canvas;
50+
vector = vec;
51+
print = GSprint;
52+
type = pytype;
53+
scene = canvas();
54+
strings = RS_modules.pythonize.strings;
55+
56+
57+
strings();
58+
"2";
59+
cone();
60+
61+
case 25:
62+
case "end":
63+
return _context.stop();
64+
}
65+
}
66+
}, _$$main$$, this);
67+
}), 0, 1);
68+
69+
var RS_modules = {};
70+
RS_modules.pythonize = {};
71+
72+
(function () {
73+
var strings = function strings() {
74+
var string_funcs, exclude, name;
75+
string_funcs = set("capitalize strip lstrip rstrip islower isupper isspace lower upper swapcase center count endswith startswith find rfind index rindex format join ljust rjust partition rpartition replace split rsplit splitlines zfill".split(" "));
76+
if (!arguments.length) {
77+
exclude = function () {
78+
var s = RS_set();
79+
s.jsset.add("split");
80+
s.jsset.add("replace");
81+
return s;
82+
}();
83+
} else if (arguments[0]) {
84+
exclude = Array.prototype.slice.call(arguments);
85+
} else {
86+
exclude = null;
87+
}
88+
if (exclude) {
89+
string_funcs = string_funcs.difference(set(exclude));
90+
}
91+
var RS_Iter0 = RS_Iterable(string_funcs);
92+
for (var RS_Index0 = 0; RS_Index0["<"](RS_Iter0.length); RS_Index0++) {
93+
name = RS_Iter0[RS_Index0];
94+
(RS_expr_temp = String.prototype)[typeof name === "number" && name["<"](0) ? RS_expr_temp.length["+"](name) : name] = (RS_expr_temp = RS_str.prototype)[typeof name === "number" && name["<"](0) ? RS_expr_temp.length["+"](name) : name];
95+
}
96+
};
97+
98+
;
99+
100+
RS_modules.pythonize.strings = strings;
101+
})();
102+
;
103+
if (!main.__argnames__) Object.defineProperties(main, {
104+
__argnames__: { value: ["_"] }
105+
});
106+
;$(function(){ window.__context = { glowscript_container: $("#glowscript").removeAttr("id") };
107+
108+
main(function(err) {
109+
var aaaaaaa = 1
110+
})
111+
112+
})})()
113+
// END JAVASCRIPT
114+
115+
//--><!]]></script>
116+
</div>

test_run_in_glowscript.html

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
var regeneratorRuntime = typeof srequire === 'function' ? srequire("streamline-runtime/lib/callbacks/regenerator") : Streamline.srequire("streamline-runtime/lib/callbacks/regenerator");
2+
3+
var _streamline = typeof srequire === 'function' ? srequire("streamline-runtime/lib/callbacks/runtime") : Streamline.srequire("streamline-runtime/lib/callbacks/runtime");
4+
5+
var _filename = "unknown";
6+
7+
var main = _streamline.async(regeneratorRuntime.mark(function _$$main$$(_2) {
8+
var version, box, sphere, simple_sphere, cylinder, pyramid, cone, helix, ellipsoid, ring, arrow, compound, display, vector, print, type, scene, RS_ls, __name__, strings;
9+
10+
return regeneratorRuntime.wrap(function _$$main$$$(_context) {
11+
while (1) {
12+
switch (_context.prev = _context.next) {
13+
case 0:
14+
version = RS_list_decorate(["2.7", "glowscript"]);
15+
Array.prototype['+'] = function (r) {
16+
return this.concat(r);
17+
};
18+
Array.prototype['*'] = function (r) {
19+
return __array_times_number(this, r);
20+
};
21+
__name__ = '__main__';
22+
23+
window.__GSlang = "vpython";
24+
box = vp_box;
25+
sphere = vp_sphere;
26+
simple_sphere = vp_simple_sphere;
27+
cylinder = vp_cylinder;
28+
pyramid = vp_pyramid;
29+
cone = vp_cone;
30+
helix = vp_helix;
31+
ellipsoid = vp_ellipsoid;
32+
ring = vp_ring;
33+
arrow = vp_arrow;
34+
compound = vp_compound;
35+
display = canvas;
36+
vector = vec;
37+
print = GSprint;
38+
type = pytype;
39+
scene = canvas();
40+
strings = RS_modules.pythonize.strings;
41+
42+
43+
strings();
44+
"2";
45+
cone();
46+
47+
case 25:
48+
case "end":
49+
return _context.stop();
50+
}
51+
}
52+
}, _$$main$$, this);
53+
}), 0, 1);
54+
55+
var RS_modules = {};
56+
RS_modules.pythonize = {};
57+
58+
(function () {
59+
var strings = function strings() {
60+
var string_funcs, exclude, name;
61+
string_funcs = set("capitalize strip lstrip rstrip islower isupper isspace lower upper swapcase center count endswith startswith find rfind index rindex format join ljust rjust partition rpartition replace split rsplit splitlines zfill".split(" "));
62+
if (!arguments.length) {
63+
exclude = function () {
64+
var s = RS_set();
65+
s.jsset.add("split");
66+
s.jsset.add("replace");
67+
return s;
68+
}();
69+
} else if (arguments[0]) {
70+
exclude = Array.prototype.slice.call(arguments);
71+
} else {
72+
exclude = null;
73+
}
74+
if (exclude) {
75+
string_funcs = string_funcs.difference(set(exclude));
76+
}
77+
var RS_Iter0 = RS_Iterable(string_funcs);
78+
for (var RS_Index0 = 0; RS_Index0["<"](RS_Iter0.length); RS_Index0++) {
79+
name = RS_Iter0[RS_Index0];
80+
(RS_expr_temp = String.prototype)[typeof name === "number" && name["<"](0) ? RS_expr_temp.length["+"](name) : name] = (RS_expr_temp = RS_str.prototype)[typeof name === "number" && name["<"](0) ? RS_expr_temp.length["+"](name) : name];
81+
}
82+
};
83+
84+
;
85+
86+
RS_modules.pythonize.strings = strings;
87+
})();
88+
;
89+
if (!main.__argnames__) Object.defineProperties(main, {
90+
__argnames__: { value: ["_"] }
91+
});

untrusted/run.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,12 @@ function ideRun() {
245245
// stacktrase.js https://github.com/stacktracejs/stacktrace.js https://www.stacktracejs.com/#!/docs/stacktrace-js
246246
// tracekit.js; https://github.com/csnover/TraceKit
247247
var feedback = err.toString()+'\n'
248+
var compile_error = (feedback.slice(0,7) === 'Error: ')
248249
var prog = program.split('\n')
249250
//for(var i=0; i<prog.length; i++) console.log(i, prog[i])
250251
var unpack = /[ ]*at[ ]([^ ]*)[^>]*>:(\d*):(\d*)/
251-
var traceback = []
252-
if (feedback.slice(0,7) == 'Error: ') {
253-
traceback = 'Error'
254-
} if (err.cursor) {
252+
var traceback = []
253+
if (err.cursor) {
255254
//console.log('err.cursor',err.cursor)
256255
// This is a syntax error from narcissus; extract the source
257256
var c = err.cursor
@@ -263,11 +262,9 @@ function ideRun() {
263262
try {
264263
// Strange behavior: sometimes err.stack is an array of end-of-line-terminated strings,
265264
// and at other times it is one long string; in the latter case we have to create rawStack
266-
// as an array of strings.
267-
var rawStack = err.__proto__.stack
268-
if (typeof rawStack == 'string') rawStack = rawStack.split('\n')
269-
else rawStack = rawStack.toString()
270-
//for (var i=0; i<rawStack.length; i++) console.log(i, rawStack[i])
265+
// as an array of strings.
266+
var rawStack = err.stack
267+
if (typeof err.stack == 'string') rawStack = rawStack.split('\n')
271268

272269
// TODO: Selection and highlighting in the dialog
273270
var first = true
@@ -276,13 +273,13 @@ function ideRun() {
276273
m = rawStack[i].match(unpack)
277274
if (m === null) continue
278275
caller = m[1]
279-
jsline = m[2]
276+
jsline = m[2]
280277
jschar = m[3]
281278
if (caller.slice(0,3) == 'RS_') continue
282279
if (caller == 'compileAndRun') break
283280
if (caller == 'main') break
284281

285-
var line = prog[jsline-1]
282+
var line = prog[jsline-1]
286283
if (window.__GSlang == 'javascript') { // Currently unable to embed line numbers in JavaScript programs
287284
traceback.push(line)
288285
traceback.push("")
@@ -305,9 +302,8 @@ function ideRun() {
305302
c = line.length
306303
}
307304
}
308-
if (L === undefined) continue
305+
if (L === undefined) continue
309306
var N = Number(L)
310-
if (isNaN(N)) break // I don't understand why this is necessary in 2.7 but not in 2.8dev
311307
if (first) traceback.push('At or near line '+N+': '+window.__original.text[N-2])
312308
else traceback.push('Called from line '+N+': '+window.__original.text[N-2])
313309
first = false
@@ -316,12 +312,18 @@ function ideRun() {
316312
}
317313
} catch (ignore) {
318314
}
315+
}
316+
317+
var out = ''
318+
if (compile_error) {
319+
for (var i= 0; i<traceback.length; i++) out += traceback[i] + '\n'
320+
send({ error: feedback, traceback: out })
321+
} else {
322+
for (var i= 0; i<traceback.length; i++) out += traceback[i] + '\n'
323+
send({ error: feedback, traceback: out})
319324
}
320-
321-
if (traceback == 'Error') send({ error: " ", traceback: feedback })
322-
else {for (var i= 0; i<traceback.length; i++) feedback += '\n'+traceback[i]}
323-
send({ error: " ", traceback: traceback.length ? feedback : ''})
324-
}
325+
326+
} // end of reportScriptError
325327

326328
waitScript()
327329
}

0 commit comments

Comments
 (0)