Permalink
Browse files

altered initialization to help facilitate testing of edge cases

  • Loading branch information...
1 parent 450e60a commit 60042509872fb821a422c7a1184f04c4a167256e @sinisterchipmunk sinisterchipmunk committed Nov 4, 2011
Showing with 26 additions and 18 deletions.
  1. +22 −14 gl-matrix.js
  2. +4 −4 spec/node_helper.js
View
@@ -29,20 +29,28 @@
"use strict";
// Type declarations
-var MatrixArray = (typeof Float32Array !== 'undefined') ? Float32Array : Array, // Fallback for systems that don't support TypedArrays
- glMatrixArrayType = MatrixArray, // For Backwards compatibility
- vec3 = {},
- mat3 = {},
- mat4 = {},
- quat4 = {};
-
-// for CommonJS environments
-if (typeof(exports) != 'undefined') {
- exports.vec3 = vec3;
- exports.mat3 = mat3;
- exports.mat4 = mat4;
- exports.quat4 = quat4;
-}
+(function() {
+ // account for CommonJS environments
+ var _global = (typeof(exports) != 'undefined') ? global : window;
+ _global.glMatrixArrayType = _global.MatrixArray = null;
+ _global.vec3 = {};
+ _global.mat3 = {};
+ _global.mat4 = {};
+ _global.quat4 = {};
+
+ // explicitly sets and returns the type of array to use within glMatrix
+ _global.setMatrixArrayType = function(type) {
+ return glMatrixArrayType = MatrixArray = type;
+ };
+
+ // auto-detects and returns the best type of array to use within glMatrix, falling
+ // back to Array if typed arrays are unsupported
+ _global.determineMatrixArrayType = function() {
+ return setMatrixArrayType((typeof Float32Array !== 'undefined') ? Float32Array : Array);
+ };
+
+ determineMatrixArrayType();
+})();
/*
* vec3 - 3 Dimensional Vector
View
@@ -1,9 +1,9 @@
glMatrix = require("gl-matrix");
-// exports from glMatrix are expected to be global
-var i;
-for (i in glMatrix)
- global[i] = glMatrix[i];
+beforeEach(function() {
+ // reset array type to default in case a test changed it
+ determineMatrixArrayType();
+});
// import the specs (see Rakefile for why)
var specs = jasmine.getAllSpecFiles("spec/javascripts", /_spec\.js$/);

0 comments on commit 6004250

Please sign in to comment.