Do not call `toString` on functions in buildStyleInterpolator
Reviewed By: vjeux Differential Revision: D4292618 fbshipit-source-id: cd7cd1a88aeb2c800f2c2941c79855992613ec84
This commit is contained in:
parent
283d0c07f6
commit
d72c6fd500
|
@ -102,13 +102,13 @@ var ARGUMENT_NAMES_RE = /([^\s,]+)/g;
|
||||||
*
|
*
|
||||||
* inline(inlineMe, ['hi', 'bye']); // "hi = bye + bye;"
|
* inline(inlineMe, ['hi', 'bye']); // "hi = bye + bye;"
|
||||||
*
|
*
|
||||||
* @param {function} func Any simple function who's arguments can be replaced via a regex.
|
* @param {string} fnStr Source of any simple function who's arguments can be
|
||||||
|
* replaced via a regex.
|
||||||
* @param {array<string>} replaceWithArgs Corresponding names of variables
|
* @param {array<string>} replaceWithArgs Corresponding names of variables
|
||||||
* within an environment, to replace `func` args with.
|
* within an environment, to replace `func` args with.
|
||||||
* @return {string} Resulting function body string.
|
* @return {string} Resulting function body string.
|
||||||
*/
|
*/
|
||||||
var inline = function(func, replaceWithArgs) {
|
var inline = function(fnStr, replaceWithArgs) {
|
||||||
var fnStr = func.toString();
|
|
||||||
var parameterNames = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')'))
|
var parameterNames = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')'))
|
||||||
.match(ARGUMENT_NAMES_RE) ||
|
.match(ARGUMENT_NAMES_RE) ||
|
||||||
[];
|
[];
|
||||||
|
@ -126,11 +126,10 @@ var inline = function(func, replaceWithArgs) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simply a convenient way to inline functions using the function's toString
|
* Simply a convenient way to inline functions using the inline function.
|
||||||
* method.
|
|
||||||
*/
|
*/
|
||||||
var MatrixOps = {
|
var MatrixOps = {
|
||||||
unroll: function(matVar, m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15) {
|
unroll: `function(matVar, m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15) {
|
||||||
m0 = matVar[0];
|
m0 = matVar[0];
|
||||||
m1 = matVar[1];
|
m1 = matVar[1];
|
||||||
m2 = matVar[2];
|
m2 = matVar[2];
|
||||||
|
@ -147,29 +146,29 @@ var MatrixOps = {
|
||||||
m13 = matVar[13];
|
m13 = matVar[13];
|
||||||
m14 = matVar[14];
|
m14 = matVar[14];
|
||||||
m15 = matVar[15];
|
m15 = matVar[15];
|
||||||
},
|
}`,
|
||||||
|
|
||||||
matrixDiffers: function(retVar, matVar, m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15) {
|
matrixDiffers: `function(retVar, matVar, m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15) {
|
||||||
retVar = retVar ||
|
retVar = retVar ||
|
||||||
m0 !== matVar[0] ||
|
m0 !== matVar[0] ||
|
||||||
m1 !== matVar[1] ||
|
m1 !== matVar[1] ||
|
||||||
m2 !== matVar[2] ||
|
m2 !== matVar[2] ||
|
||||||
m3 !== matVar[3] ||
|
m3 !== matVar[3] ||
|
||||||
m4 !== matVar[4] ||
|
m4 !== matVar[4] ||
|
||||||
m5 !== matVar[5] ||
|
m5 !== matVar[5] ||
|
||||||
m6 !== matVar[6] ||
|
m6 !== matVar[6] ||
|
||||||
m7 !== matVar[7] ||
|
m7 !== matVar[7] ||
|
||||||
m8 !== matVar[8] ||
|
m8 !== matVar[8] ||
|
||||||
m9 !== matVar[9] ||
|
m9 !== matVar[9] ||
|
||||||
m10 !== matVar[10] ||
|
m10 !== matVar[10] ||
|
||||||
m11 !== matVar[11] ||
|
m11 !== matVar[11] ||
|
||||||
m12 !== matVar[12] ||
|
m12 !== matVar[12] ||
|
||||||
m13 !== matVar[13] ||
|
m13 !== matVar[13] ||
|
||||||
m14 !== matVar[14] ||
|
m14 !== matVar[14] ||
|
||||||
m15 !== matVar[15];
|
m15 !== matVar[15];
|
||||||
},
|
}`,
|
||||||
|
|
||||||
transformScale: function(matVar, opVar) {
|
transformScale: `function(matVar, opVar) {
|
||||||
// Scaling matVar by opVar
|
// Scaling matVar by opVar
|
||||||
var x = opVar[0];
|
var x = opVar[0];
|
||||||
var y = opVar[1];
|
var y = opVar[1];
|
||||||
|
@ -190,13 +189,13 @@ var MatrixOps = {
|
||||||
matVar[13] = matVar[13];
|
matVar[13] = matVar[13];
|
||||||
matVar[14] = matVar[14];
|
matVar[14] = matVar[14];
|
||||||
matVar[15] = matVar[15];
|
matVar[15] = matVar[15];
|
||||||
},
|
}`,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All of these matrix transforms are not general purpose utilities, and are
|
* All of these matrix transforms are not general purpose utilities, and are
|
||||||
* only suitable for being inlined for the use of building up interpolators.
|
* only suitable for being inlined for the use of building up interpolators.
|
||||||
*/
|
*/
|
||||||
transformTranslate: function(matVar, opVar) {
|
transformTranslate: `function(matVar, opVar) {
|
||||||
// Translating matVar by opVar
|
// Translating matVar by opVar
|
||||||
var x = opVar[0];
|
var x = opVar[0];
|
||||||
var y = opVar[1];
|
var y = opVar[1];
|
||||||
|
@ -205,13 +204,13 @@ var MatrixOps = {
|
||||||
matVar[13] = matVar[1] * x + matVar[5] * y + matVar[9] * z + matVar[13];
|
matVar[13] = matVar[1] * x + matVar[5] * y + matVar[9] * z + matVar[13];
|
||||||
matVar[14] = matVar[2] * x + matVar[6] * y + matVar[10] * z + matVar[14];
|
matVar[14] = matVar[2] * x + matVar[6] * y + matVar[10] * z + matVar[14];
|
||||||
matVar[15] = matVar[3] * x + matVar[7] * y + matVar[11] * z + matVar[15];
|
matVar[15] = matVar[3] * x + matVar[7] * y + matVar[11] * z + matVar[15];
|
||||||
},
|
}`,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {array} matVar Both the input, and the output matrix.
|
* @param {array} matVar Both the input, and the output matrix.
|
||||||
* @param {quaternion specification} q Four element array describing rotation.
|
* @param {quaternion specification} q Four element array describing rotation.
|
||||||
*/
|
*/
|
||||||
transformRotateRadians: function(matVar, q) {
|
transformRotateRadians: `function(matVar, q) {
|
||||||
// Rotating matVar by q
|
// Rotating matVar by q
|
||||||
var xQuat = q[0], yQuat = q[1], zQuat = q[2], wQuat = q[3];
|
var xQuat = q[0], yQuat = q[1], zQuat = q[2], wQuat = q[3];
|
||||||
var x2Quat = xQuat + xQuat;
|
var x2Quat = xQuat + xQuat;
|
||||||
|
@ -226,7 +225,7 @@ var MatrixOps = {
|
||||||
var wxQuat = wQuat * x2Quat;
|
var wxQuat = wQuat * x2Quat;
|
||||||
var wyQuat = wQuat * y2Quat;
|
var wyQuat = wQuat * y2Quat;
|
||||||
var wzQuat = wQuat * z2Quat;
|
var wzQuat = wQuat * z2Quat;
|
||||||
// Step 1: Inlines the construction of a quaternion matrix (`quatMat`)
|
// Step 1: Inlines the construction of a quaternion matrix ('quatMat')
|
||||||
var quatMat0 = 1 - (yyQuat + zzQuat);
|
var quatMat0 = 1 - (yyQuat + zzQuat);
|
||||||
var quatMat1 = xyQuat + wzQuat;
|
var quatMat1 = xyQuat + wzQuat;
|
||||||
var quatMat2 = xzQuat - wyQuat;
|
var quatMat2 = xzQuat - wyQuat;
|
||||||
|
@ -267,13 +266,13 @@ var MatrixOps = {
|
||||||
matVar[9] = b0 * a01 + b1 * a11 + b2 * a21;
|
matVar[9] = b0 * a01 + b1 * a11 + b2 * a21;
|
||||||
matVar[10] = b0 * a02 + b1 * a12 + b2 * a22;
|
matVar[10] = b0 * a02 + b1 * a12 + b2 * a22;
|
||||||
matVar[11] = b0 * a03 + b1 * a13 + b2 * a23;
|
matVar[11] = b0 * a03 + b1 * a13 + b2 * a23;
|
||||||
}
|
}`
|
||||||
};
|
};
|
||||||
|
|
||||||
// Optimized version of general operation applications that can be used when
|
// Optimized version of general operation applications that can be used when
|
||||||
// the target matrix is known to be the identity matrix.
|
// the target matrix is known to be the identity matrix.
|
||||||
var MatrixOpsInitial = {
|
var MatrixOpsInitial = {
|
||||||
transformScale: function(matVar, opVar) {
|
transformScale: `function(matVar, opVar) {
|
||||||
// Scaling matVar known to be identity by opVar
|
// Scaling matVar known to be identity by opVar
|
||||||
matVar[0] = opVar[0];
|
matVar[0] = opVar[0];
|
||||||
matVar[1] = 0;
|
matVar[1] = 0;
|
||||||
|
@ -291,10 +290,10 @@ var MatrixOpsInitial = {
|
||||||
matVar[13] = 0;
|
matVar[13] = 0;
|
||||||
matVar[14] = 0;
|
matVar[14] = 0;
|
||||||
matVar[15] = 1;
|
matVar[15] = 1;
|
||||||
},
|
}`,
|
||||||
|
|
||||||
transformTranslate: function(matVar, opVar) {
|
transformTranslate: `function(matVar, opVar) {
|
||||||
// Translating matVar known to be identity by opVar';
|
// Translating matVar known to be identity by opVar;
|
||||||
matVar[0] = 1;
|
matVar[0] = 1;
|
||||||
matVar[1] = 0;
|
matVar[1] = 0;
|
||||||
matVar[2] = 0;
|
matVar[2] = 0;
|
||||||
|
@ -311,14 +310,14 @@ var MatrixOpsInitial = {
|
||||||
matVar[13] = opVar[1];
|
matVar[13] = opVar[1];
|
||||||
matVar[14] = opVar[2];
|
matVar[14] = opVar[2];
|
||||||
matVar[15] = 1;
|
matVar[15] = 1;
|
||||||
},
|
}`,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {array} matVar Both the input, and the output matrix - assumed to be
|
* @param {array} matVar Both the input, and the output matrix - assumed to be
|
||||||
* identity.
|
* identity.
|
||||||
* @param {quaternion specification} q Four element array describing rotation.
|
* @param {quaternion specification} q Four element array describing rotation.
|
||||||
*/
|
*/
|
||||||
transformRotateRadians: function(matVar, q) {
|
transformRotateRadians: `function(matVar, q) {
|
||||||
|
|
||||||
// Rotating matVar which is known to be identity by q
|
// Rotating matVar which is known to be identity by q
|
||||||
var xQuat = q[0], yQuat = q[1], zQuat = q[2], wQuat = q[3];
|
var xQuat = q[0], yQuat = q[1], zQuat = q[2], wQuat = q[3];
|
||||||
|
@ -334,7 +333,7 @@ var MatrixOpsInitial = {
|
||||||
var wxQuat = wQuat * x2Quat;
|
var wxQuat = wQuat * x2Quat;
|
||||||
var wyQuat = wQuat * y2Quat;
|
var wyQuat = wQuat * y2Quat;
|
||||||
var wzQuat = wQuat * z2Quat;
|
var wzQuat = wQuat * z2Quat;
|
||||||
// Step 1: Inlines the construction of a quaternion matrix (`quatMat`)
|
// Step 1: Inlines the construction of a quaternion matrix ('quatMat')
|
||||||
var quatMat0 = 1 - (yyQuat + zzQuat);
|
var quatMat0 = 1 - (yyQuat + zzQuat);
|
||||||
var quatMat1 = xyQuat + wzQuat;
|
var quatMat1 = xyQuat + wzQuat;
|
||||||
var quatMat2 = xzQuat - wyQuat;
|
var quatMat2 = xzQuat - wyQuat;
|
||||||
|
@ -366,7 +365,7 @@ var MatrixOpsInitial = {
|
||||||
matVar[13] = 0;
|
matVar[13] = 0;
|
||||||
matVar[14] = 0;
|
matVar[14] = 0;
|
||||||
matVar[15] = 1;
|
matVar[15] = 1;
|
||||||
}
|
}`
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue