Skip to content

Commit 18824af

Browse files
committed
wrap strings in Error objects
1 parent 75b093e commit 18824af

File tree

8 files changed

+114
-114
lines changed

8 files changed

+114
-114
lines changed

src/main.js

+21-21
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var gl;
33

44
var GL = {
55
// ### Initialization
6-
//
6+
//
77
// `GL.create()` creates a new WebGL context and augments it with more
88
// methods. The alpha channel is disabled by default because it usually causes
99
// unintended transparencies in the canvas.
@@ -15,7 +15,7 @@ var GL = {
1515
if (!('alpha' in options)) options.alpha = false;
1616
try { gl = canvas.getContext('webgl', options); } catch (e) {}
1717
try { gl = gl || canvas.getContext('experimental-webgl', options); } catch (e) {}
18-
if (!gl) throw 'WebGL not supported';
18+
if (!gl) throw new Error('WebGL not supported');
1919
addMatrixStack();
2020
addImmediateMode();
2121
addEventListeners();
@@ -40,7 +40,7 @@ var GL = {
4040
};
4141

4242
// ### Matrix stack
43-
//
43+
//
4444
// Implement the OpenGL modelview and projection matrix stacks, along with some
4545
// other useful GLU matrix functions.
4646

@@ -65,7 +65,7 @@ function addMatrixStack() {
6565
stack = projectionStack;
6666
break;
6767
default:
68-
throw 'invalid matrix mode ' + mode;
68+
throw new Error('invalid matrix mode ' + mode);
6969
}
7070
};
7171
gl.loadIdentity = function() {
@@ -134,7 +134,7 @@ function addMatrixStack() {
134134
}
135135

136136
// ### Immediate mode
137-
//
137+
//
138138
// Provide an implementation of OpenGL's deprecated immediate mode. This is
139139
// depricated for a reason: constantly re-specifying the geometry is a bad
140140
// idea for performance. You should use a `GL.Mesh` instead, which specifies
@@ -176,7 +176,7 @@ function addImmediateMode() {
176176
immediateMode.shader.uniforms({ pointSize: pointSize });
177177
};
178178
gl.begin = function(mode) {
179-
if (immediateMode.mode != -1) throw 'mismatched gl.begin() and gl.end() calls';
179+
if (immediateMode.mode != -1) throw new Error('mismatched gl.begin() and gl.end() calls');
180180
immediateMode.mode = mode;
181181
immediateMode.mesh.colors = [];
182182
immediateMode.mesh.coords = [];
@@ -194,7 +194,7 @@ function addImmediateMode() {
194194
immediateMode.mesh.vertices.push(arguments.length == 1 ? x.toArray() : [x, y, z]);
195195
};
196196
gl.end = function() {
197-
if (immediateMode.mode == -1) throw 'mismatched gl.begin() and gl.end() calls';
197+
if (immediateMode.mode == -1) throw new Error('mismatched gl.begin() and gl.end() calls');
198198
immediateMode.mesh.compile();
199199
immediateMode.shader.uniforms({
200200
useTexture: !!gl.getParameter(gl.TEXTURE_BINDING_2D)
@@ -204,7 +204,7 @@ function addImmediateMode() {
204204
}
205205

206206
// ### Improved mouse events
207-
//
207+
//
208208
// This adds event listeners on the `gl.canvas` element that call
209209
// `gl.onmousedown()`, `gl.onmousemove()`, and `gl.onmouseup()` with an
210210
// augmented event object. The event object also has the properties `x`, `y`,
@@ -312,7 +312,7 @@ function addEventListeners() {
312312
}
313313

314314
// ### Automatic keyboard state
315-
//
315+
//
316316
// The current keyboard state is stored in `GL.keys`, a map of integer key
317317
// codes to booleans indicating whether that key is currently pressed. Certain
318318
// keys also have named identifiers that can be used directly, such as
@@ -363,7 +363,7 @@ on(document, 'keyup', function(e) {
363363

364364
function addOtherMethods() {
365365
// ### Multiple contexts
366-
//
366+
//
367367
// When using multiple contexts in one web page, `gl.makeCurrent()` must be
368368
// called before issuing commands to a different context.
369369
(function(context) {
@@ -373,7 +373,7 @@ function addOtherMethods() {
373373
})(gl);
374374

375375
// ### Animation
376-
//
376+
//
377377
// Call `gl.animate()` to provide an animation loop that repeatedly calls
378378
// `gl.onupdate()` and `gl.ondraw()`.
379379
gl.animate = function() {
@@ -396,32 +396,32 @@ function addOtherMethods() {
396396
};
397397

398398
// ### Fullscreen
399-
//
399+
//
400400
// Provide an easy way to get a fullscreen app running, including an
401401
// automatic 3D perspective projection matrix by default. This should be
402402
// called once.
403-
//
403+
//
404404
// Just fullscreen, no automatic camera:
405-
//
405+
//
406406
// gl.fullscreen({ camera: false });
407-
//
407+
//
408408
// Adjusting field of view, near plane distance, and far plane distance:
409-
//
409+
//
410410
// gl.fullscreen({ fov: 45, near: 0.1, far: 1000 });
411-
//
411+
//
412412
// Adding padding from the edge of the window:
413-
//
413+
//
414414
// gl.fullscreen({ paddingLeft: 250, paddingBottom: 60 });
415-
//
415+
//
416416
gl.fullscreen = function(options) {
417417
options = options || {};
418418
var top = options.paddingTop || 0;
419419
var left = options.paddingLeft || 0;
420420
var right = options.paddingRight || 0;
421421
var bottom = options.paddingBottom || 0;
422422
if (!document.body) {
423-
throw 'document.body doesn\'t exist yet (call gl.fullscreen() from ' +
424-
'window.onload() or from inside the <body> tag)';
423+
throw new Error('document.body doesn\'t exist yet (call gl.fullscreen() from ' +
424+
'window.onload() or from inside the <body> tag)');
425425
}
426426
document.body.appendChild(gl.canvas);
427427
document.body.style.overflow = 'hidden';

src/matrix.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
var hasFloat32Array = (typeof Float32Array != 'undefined');
77

88
// ### new GL.Matrix([elements])
9-
//
9+
//
1010
// This constructor takes 16 arguments in row-major order, which can be passed
1111
// individually, as a list, or even as four lists, one for each row. If the
1212
// arguments are omitted then the identity matrix is constructed instead.
@@ -25,30 +25,30 @@ function Matrix() {
2525

2626
Matrix.prototype = {
2727
// ### .inverse()
28-
//
28+
//
2929
// Returns the matrix that when multiplied with this matrix results in the
3030
// identity matrix.
3131
inverse: function() {
3232
return Matrix.inverse(this, new Matrix());
3333
},
3434

3535
// ### .transpose()
36-
//
36+
//
3737
// Returns this matrix, exchanging columns for rows.
3838
transpose: function() {
3939
return Matrix.transpose(this, new Matrix());
4040
},
4141

4242
// ### .multiply(matrix)
43-
//
43+
//
4444
// Returns the concatenation of the transforms for this matrix and `matrix`.
4545
// This emulates the OpenGL function `glMultMatrix()`.
4646
multiply: function(matrix) {
4747
return Matrix.multiply(this, matrix, new Matrix());
4848
},
4949

5050
// ### .transformPoint(point)
51-
//
51+
//
5252
// Transforms the vector as a point with a w coordinate of 1. This
5353
// means translations will have an effect, for example.
5454
transformPoint: function(v) {
@@ -61,7 +61,7 @@ Matrix.prototype = {
6161
},
6262

6363
// ### .transformPoint(vector)
64-
//
64+
//
6565
// Transforms the vector as a vector with a w coordinate of 0. This
6666
// means translations will have no effect, for example.
6767
transformVector: function(v) {
@@ -75,7 +75,7 @@ Matrix.prototype = {
7575
};
7676

7777
// ### GL.Matrix.inverse(matrix[, result])
78-
//
78+
//
7979
// Returns the matrix that when multiplied with `matrix` results in the
8080
// identity matrix. You can optionally pass an existing matrix in `result`
8181
// to avoid allocating a new matrix. This implementation is from the Mesa
@@ -110,7 +110,7 @@ Matrix.inverse = function(matrix, result) {
110110
};
111111

112112
// ### GL.Matrix.transpose(matrix[, result])
113-
//
113+
//
114114
// Returns `matrix`, exchanging columns for rows. You can optionally pass an
115115
// existing matrix in `result` to avoid allocating a new matrix.
116116
Matrix.transpose = function(matrix, result) {
@@ -124,7 +124,7 @@ Matrix.transpose = function(matrix, result) {
124124
};
125125

126126
// ### GL.Matrix.multiply(left, right[, result])
127-
//
127+
//
128128
// Returns the concatenation of the transforms for `left` and `right`. You can
129129
// optionally pass an existing matrix in `result` to avoid allocating a new
130130
// matrix. This emulates the OpenGL function `glMultMatrix()`.
@@ -156,7 +156,7 @@ Matrix.multiply = function(left, right, result) {
156156
};
157157

158158
// ### GL.Matrix.identity([result])
159-
//
159+
//
160160
// Returns an identity matrix. You can optionally pass an existing matrix in
161161
// `result` to avoid allocating a new matrix. This emulates the OpenGL function
162162
// `glLoadIdentity()`.
@@ -169,7 +169,7 @@ Matrix.identity = function(result) {
169169
};
170170

171171
// ### GL.Matrix.perspective(fov, aspect, near, far[, result])
172-
//
172+
//
173173
// Returns a perspective transform matrix, which makes far away objects appear
174174
// smaller than nearby objects. The `aspect` argument should be the width
175175
// divided by the height of your viewport and `fov` is the top-to-bottom angle
@@ -183,7 +183,7 @@ Matrix.perspective = function(fov, aspect, near, far, result) {
183183
};
184184

185185
// ### GL.Matrix.frustum(left, right, bottom, top, near, far[, result])
186-
//
186+
//
187187
// Sets up a viewing frustum, which is shaped like a truncated pyramid with the
188188
// camera where the point of the pyramid would be. You can optionally pass an
189189
// existing matrix in `result` to avoid allocating a new matrix. This emulates
@@ -216,7 +216,7 @@ Matrix.frustum = function(l, r, b, t, n, f, result) {
216216
};
217217

218218
// ### GL.Matrix.ortho(left, right, bottom, top, near, far[, result])
219-
//
219+
//
220220
// Returns an orthographic projection, in which objects are the same size no
221221
// matter how far away or nearby they are. You can optionally pass an existing
222222
// matrix in `result` to avoid allocating a new matrix. This emulates the OpenGL
@@ -249,9 +249,9 @@ Matrix.ortho = function(l, r, b, t, n, f, result) {
249249
};
250250

251251
// ### GL.Matrix.scale(x, y, z[, result])
252-
//
252+
//
253253
// This emulates the OpenGL function `glScale()`. You can optionally pass an
254-
// existing matrix in `result` to avoid allocating a new matrix.
254+
// existing matrix in `result` to avoid allocating a new matrix.
255255
Matrix.scale = function(x, y, z, result) {
256256
result = result || new Matrix();
257257
var m = result.m;
@@ -280,9 +280,9 @@ Matrix.scale = function(x, y, z, result) {
280280
};
281281

282282
// ### GL.Matrix.translate(x, y, z[, result])
283-
//
283+
//
284284
// This emulates the OpenGL function `glTranslate()`. You can optionally pass
285-
// an existing matrix in `result` to avoid allocating a new matrix.
285+
// an existing matrix in `result` to avoid allocating a new matrix.
286286
Matrix.translate = function(x, y, z, result) {
287287
result = result || new Matrix();
288288
var m = result.m;
@@ -311,10 +311,10 @@ Matrix.translate = function(x, y, z, result) {
311311
};
312312

313313
// ### GL.Matrix.rotate(a, x, y, z[, result])
314-
//
314+
//
315315
// Returns a matrix that rotates by `a` degrees around the vector `x, y, z`.
316316
// You can optionally pass an existing matrix in `result` to avoid allocating
317-
// a new matrix. This emulates the OpenGL function `glRotate()`.
317+
// a new matrix. This emulates the OpenGL function `glRotate()`.
318318
Matrix.rotate = function(a, x, y, z, result) {
319319
if (!a || (!x && !y && !z)) {
320320
return Matrix.identity(result);
@@ -351,7 +351,7 @@ Matrix.rotate = function(a, x, y, z, result) {
351351
};
352352

353353
// ### GL.Matrix.lookAt(ex, ey, ez, cx, cy, cz, ux, uy, uz[, result])
354-
//
354+
//
355355
// Returns a matrix that puts the camera at the eye point `ex, ey, ez` looking
356356
// toward the center point `cx, cy, cz` with an up direction of `ux, uy, uz`.
357357
// You can optionally pass an existing matrix in `result` to avoid allocating

0 commit comments

Comments
 (0)