Skip to content

Commit d9d4239

Browse files
authored
fix closure minification of Math.*, and remove previous workaround code for it. fixes #7472 (#7476)
See google/closure-compiler#3141
1 parent e25e42c commit d9d4239

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

src/closure-externs.js

+29
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,35 @@ flags.binary;
9393
*/
9494
Document.prototype.currentScript;
9595

96+
/**
97+
* Don't minify Math.*
98+
*/
99+
/**
100+
* @suppress {duplicate}
101+
*/
102+
var Math = {};
103+
Math.abs = function() {};
104+
Math.cos = function() {};
105+
Math.sin = function() {};
106+
Math.tan = function() {};
107+
Math.acos = function() {};
108+
Math.asin = function() {};
109+
Math.atan = function() {};
110+
Math.atan2 = function() {};
111+
Math.exp = function() {};
112+
Math.log = function() {};
113+
Math.sqrt = function() {};
114+
Math.ceil = function() {};
115+
Math.floor = function() {};
116+
Math.pow = function() {};
117+
Math.imul = function() {};
118+
Math.fround = function() {};
119+
Math.round = function() {};
120+
Math.min = function() {};
121+
Math.max = function() {};
122+
Math.clz32 = function() {};
123+
Math.trunc = function() {};
124+
96125
/**
97126
* SIMD.js support (not in upstream closure yet).
98127
*/

src/preamble.js

+11-15
Original file line numberDiff line numberDiff line change
@@ -1422,32 +1422,30 @@ function writeAsciiToMemory(str, buffer, dontAddNull) {
14221422

14231423
#if POLYFILL_OLD_MATH_FUNCTIONS
14241424
// check for imul support, and also for correctness ( https://bugs.webkit.org/show_bug.cgi?id=126345 )
1425-
if (!Math['imul'] || Math['imul'](0xffffffff, 5) !== -5) Math['imul'] = function imul(a, b) {
1425+
if (!Math.imul || Math.imul(0xffffffff, 5) !== -5) Math.imul = function imul(a, b) {
14261426
var ah = a >>> 16;
14271427
var al = a & 0xffff;
14281428
var bh = b >>> 16;
14291429
var bl = b & 0xffff;
14301430
return (al*bl + ((ah*bl + al*bh) << 16))|0;
14311431
};
1432-
Math.imul = Math['imul'];
14331432

14341433
#if PRECISE_F32
14351434
#if PRECISE_F32 == 1
1436-
if (!Math['fround']) {
1435+
if (!Math.fround) {
14371436
var froundBuffer = new Float32Array(1);
1438-
Math['fround'] = function(x) { froundBuffer[0] = x; return froundBuffer[0] };
1437+
Math.fround = function(x) { froundBuffer[0] = x; return froundBuffer[0] };
14391438
}
14401439
#else // 2
1441-
if (!Math['fround']) Math['fround'] = function(x) { return x };
1440+
if (!Math.fround) Math.fround = function(x) { return x };
14421441
#endif
1443-
Math.fround = Math['fround'];
14441442
#else
14451443
#if SIMD
1446-
if (!Math['fround']) Math['fround'] = function(x) { return x };
1444+
if (!Math.fround) Math.fround = function(x) { return x };
14471445
#endif
14481446
#endif
14491447

1450-
if (!Math['clz32']) Math['clz32'] = function(x) {
1448+
if (!Math.clz32) Math.clz32 = function(x) {
14511449
var n = 32;
14521450
var y = x >> 16; if (y) { n -= 16; x = y; }
14531451
y = x >> 8; if (y) { n -= 8; x = y; }
@@ -1456,18 +1454,16 @@ if (!Math['clz32']) Math['clz32'] = function(x) {
14561454
y = x >> 1; if (y) return n - 2;
14571455
return n - x;
14581456
};
1459-
Math.clz32 = Math['clz32']
14601457

1461-
if (!Math['trunc']) Math['trunc'] = function(x) {
1458+
if (!Math.trunc) Math.trunc = function(x) {
14621459
return x < 0 ? Math.ceil(x) : Math.floor(x);
14631460
};
1464-
Math.trunc = Math['trunc'];
14651461
#else // POLYFILL_OLD_MATH_FUNCTIONS
14661462
#if ASSERTIONS
1467-
assert(Math['imul'], 'This browser does not support Math.imul(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
1468-
assert(Math['fround'], 'This browser does not support Math.fround(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
1469-
assert(Math['clz32'], 'This browser does not support Math.clz32(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
1470-
assert(Math['trunc'], 'This browser does not support Math.trunc(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
1463+
assert(Math.imul, 'This browser does not support Math.imul(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
1464+
assert(Math.fround, 'This browser does not support Math.fround(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
1465+
assert(Math.clz32, 'This browser does not support Math.clz32(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
1466+
assert(Math.trunc, 'This browser does not support Math.trunc(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
14711467
#endif
14721468
#endif // LEGACY_VM_SUPPORT
14731469

tests/webgl_create_context.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ int main()
178178
if (vb2 != vb4) printf("Index 1: Generated VB: %d, read back VB: %d\n", vb2, vb4);
179179
assert(vb2 == vb4);
180180

181+
// Test bug https://github.com/kripken/emscripten/issues/7472:
182+
GLint enabled = 0;
183+
glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &enabled);
184+
assert(enabled == 0);
185+
181186
// Test that deleting the context works.
182187
res = emscripten_webgl_destroy_context(context);
183188
assert(res == 0);

0 commit comments

Comments
 (0)