Skip to content

Commit a571a3f

Browse files
committed
GIANT changeset yikes
ADDED first version of JavaScript visualizations!!! Removed: - py2crazy option - drawParentPointers option - showOnlyOutputs option
1 parent 5240adc commit a571a3f

17 files changed

Lines changed: 472 additions & 450 deletions
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
try {
2+
var x = 5;
3+
throw new Error("oh crapo");
4+
}
5+
catch (e) {
6+
console.log('hello');
7+
console.log('caught');
8+
}
9+
finally {
10+
console.log('done');
11+
}

v3/js-example-code/closure1.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var globalZ = 10;
2+
3+
function foo(y) {
4+
function bar(x) {
5+
globalZ += 100;
6+
return x + y + globalZ;
7+
}
8+
return bar;
9+
}
10+
11+
var b = foo(1);
12+
b(2);

v3/js-example-code/constructor.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function Vector(x, y) {
2+
this.x = x;
3+
this.y = y;
4+
}
5+
6+
Vector.prototype.plus = function(other) {
7+
return new Vector(this.x + other.x, this.y + other.y);
8+
};
9+
10+
var v1 = new Vector(1, 2);
11+
var v2 = Vector(20, 30); // whoops, forgot 'new'

v3/js-example-code/data-types.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var intNum = 42;
2+
var floatNum = 3.14159;
3+
var nanNum = NaN;
4+
var infNum = Infinity;
5+
var ninfNum = -Infinity;
6+
7+
var str = "hello world";
8+
9+
var boolTrue = true;
10+
var boolFalse = false;
11+
12+
var nullVal = null;
13+
var undefVal = undefined;
14+
15+
var lst = ['a', 'b', 3, 4, 5, 'f'];
16+
17+
var obj = {name: 'John', age: 35, hasChildren: true};
18+
19+
var i = 5;
20+
var obj_lst = [i, {foo: i+1, poop: [1, 2, 3]}, {bar: i+2}];
21+
22+
obj.name = 'Jane';

v3/js-example-code/fact.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function fact(n) {
2+
if (n == 0) {
3+
return 1;
4+
}
5+
else {
6+
return n * fact(n-1);
7+
}
8+
}
9+
10+
fact(3);
11+
fact(3);

v3/js-example-code/inheritance.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Adapted from Effective JavaScript
2+
function Actor(x, y) {
3+
this.x = x;
4+
this.y = y;
5+
}
6+
7+
Actor.prototype.moveTo = function(x, y) {
8+
this.x = x;
9+
this.y = y;
10+
}
11+
12+
function SpaceShip(x, y) {
13+
Actor.call(this, x, y);
14+
this.points = 0;
15+
}
16+
17+
SpaceShip.prototype = Object.create(Actor.prototype); // inherit!
18+
SpaceShip.prototype.type = "spaceship";
19+
SpaceShip.prototype.scorePoint = function() {
20+
this.points++;
21+
}
22+
23+
var s = new SpaceShip(10, 20);
24+
s.moveTo(30, 40);
25+
s.scorePoint();
26+
s.scorePoint();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var x = 10; // global
2+
function foo() {
3+
var x = 10;
4+
function bar() {
5+
var y = x;
6+
x *= 2;
7+
console.log(x, y);
8+
}
9+
return bar;
10+
}
11+
var b = foo();
12+
// x inside of bar should be the x in foo, *not* the global x
13+
b();

v3/js/ace/src-min-noconflict/mode-javascript.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

v3/js/ace/src-min-noconflict/worker-javascript.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

v3/js/iframe-embed.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ $(document).ready(function() {
4444
var pyState = queryStrOptions.py;
4545
var verticalStackBool = (queryStrOptions.verticalStack == 'true');
4646
var heapPrimitivesBool = (queryStrOptions.heapPrimitives == 'true');
47-
var drawParentPointerBool = (queryStrOptions.drawParentPointers == 'true');
4847
var textRefsBool = (queryStrOptions.textReferences == 'true');
49-
var showOnlyOutputsBool = (queryStrOptions.showOnlyOutputs == 'true');
5048
var cumModeBool = (queryStrOptions.cumulative == 'true');
5149

50+
// these two are deprecated
51+
var drawParentPointerBool = (queryStrOptions.drawParentPointers == 'true');
52+
var showOnlyOutputsBool = (queryStrOptions.showOnlyOutputs == 'true');
53+
5254
var codeDivWidth = undefined;
5355
var cdw = $.bbq.getState('codeDivWidth');
5456
if (cdw) {
@@ -77,7 +79,10 @@ $(document).ready(function() {
7779
else if (pyState == '2crazy') {
7880
backend_script = python2crazy_backend_script;
7981
}
80-
82+
else if (pyState == 'js') {
83+
backend_script = js_backend_script;
84+
}
85+
assert(backend_script);
8186

8287
// David Pritchard's code for resizeContainer option ...
8388
var resizeContainer = ($.bbq.getState('resizeContainer') == 'true');

0 commit comments

Comments
 (0)