commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbe...@apache.org
Subject svn commit: r986388 - in /commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js: AbstractEnumeratedStatechartGenerator.xsl AbstractStatechartGenerator.xsl StatePatternStatechartGenerator.xsl
Date Tue, 17 Aug 2010 16:46:25 GMT
Author: jbeard
Date: Tue Aug 17 16:46:25 2010
New Revision: 986388

URL: http://svn.apache.org/viewvc?rev=986388&view=rev
Log:
Changed noIndexOf so that it does not add alter Array.prototype, but instead provides a function
indexOf as a private method in the statechart constructor function.

Modified:
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/AbstractEnumeratedStatechartGenerator.xsl
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/AbstractStatechartGenerator.xsl
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/StatePatternStatechartGenerator.xsl

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/AbstractEnumeratedStatechartGenerator.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/AbstractEnumeratedStatechartGenerator.xsl?rev=986388&r1=986387&r2=986388&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/AbstractEnumeratedStatechartGenerator.xsl
(original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/AbstractEnumeratedStatechartGenerator.xsl
Tue Aug 17 16:46:25 2010
@@ -231,7 +231,12 @@
 		<param name="s"/>
 		<param name="t"/>
 
-		currentConfiguration.splice(currentConfiguration.indexOf(statesExited[0].id),1,
+		currentConfiguration.splice(
+			<call-template name="genIndexOf">
+				<with-param name="in" select="'currentConfiguration'"/>
+				<with-param name="var" select="'statesExited[0].id'"/>
+			</call-template>
+			,1,
 			<for-each select="$t/c:targets/c:target/c:targetState">
 				<variable name="targetStateId" select="."/>
 				<value-of select="$allStates[@id = $targetStateId]/@c:enumId"/>
@@ -246,7 +251,12 @@
 		<param name="s"/>
 		<param name="t"/>
 
-		currentConfiguration.splice(currentConfiguration.indexOf(<value-of select="$s/@c:enumId"/>),1,
+		currentConfiguration.splice(
+			<call-template name="genIndexOf">
+				<with-param name="in" select="'currentConfiguration'"/>
+				<with-param name="var" select="$s/@c:enumId"/>
+			</call-template>
+			,1,
 			<for-each select="$t/c:targets/c:target/c:targetState">
 				<variable name="targetStateId" select="."/>
 				<value-of select="$allStates[@id = $targetStateId]/@c:enumId"/>

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/AbstractStatechartGenerator.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/AbstractStatechartGenerator.xsl?rev=986388&r1=986387&r2=986388&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/AbstractStatechartGenerator.xsl
(original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/AbstractStatechartGenerator.xsl
Tue Aug 17 16:46:25 2010
@@ -23,6 +23,7 @@
 
 	<param name="log" select="false()"/>
 	<param name="genListenerHooks" select="true()"/>
+	<param name="noIndexOf" select="false()"/>
 
 	<!-- these variables get overridden by subclasses -->
 	<variable name="enumeratedEventDispatchInvocation"/>
@@ -77,7 +78,7 @@
 			<value-of select="$hoistVarName"/>=<value-of select="$in"/>.length;
 				<value-of select="$iteratorVarName"/> &lt; <value-of select="$hoistVarName"/>;
 				<value-of select="$iteratorVarName"/>++){
-			<value-of select="$var"/> = <value-of select="$in"/>[<value-of select="$iteratorVarName"/>];
+			var <value-of select="$var"/> = <value-of select="$in"/>[<value-of select="$iteratorVarName"/>];
 
 			<choose>
 				<when test="$when">
@@ -158,7 +159,7 @@
 			<value-of select="$hoistVarName"/>=<value-of select="$in"/>.length;
 				<value-of select="$iteratorVarName"/> &lt; <value-of select="$hoistVarName"/>;
 				<value-of select="$iteratorVarName"/>++){
-			<value-of select="$var"/> = <value-of select="$in"/>[<value-of select="$iteratorVarName"/>];
+			var <value-of select="$var"/> = <value-of select="$in"/>[<value-of select="$iteratorVarName"/>];
 
 			if(<value-of select="$when"/>){
 				<value-of select="$returnVarName"/> = true;
@@ -167,6 +168,33 @@
 		}
 	</template>
 
+	<template name="genIndexOf">
+		<param name="var"/>
+		<param name="in"/>
+
+		<choose>
+			<when test="$noIndexOf">
+				indexOf(<value-of select="$in"/>,<value-of select="$var"/>)
+			</when>
+			<otherwise>
+				<value-of select="$in"/>.indexOf(<value-of select="$var"/>)
+			</otherwise>
+		</choose>
+	</template>
+
+	<template name="genNoIndexOfCompatibilityFunction">
+		function indexOf(arr,obj){
+			for(var i=0, l=arr.length; i &lt; l; i++){
+				if(arr[i]===obj){
+					return i;
+				}
+			}
+			return -1;
+		}
+	</template>
+
+
+
 	<!-- helper template to safely get a state's parent's name -->
 	<template name="getParentNameFromState">
 		<param name="s"/>
@@ -246,6 +274,11 @@
 
 				<value-of select="$genInPredicateFunction"/>
 
+				<if test="$noIndexOf">
+					<call-template name="genNoIndexOfCompatibilityFunction"/>
+				</if>
+
+
 				<if test="$genListenerHooks">
 					<value-of select="$genListenerHookRegistrationFunctions"/>
 				</if>
@@ -795,8 +828,12 @@
 					</call-template>
 				</with-param>
 				<with-param name="when">
-					<value-of select="$genHistoryTriggerDispatcherInnerForEachStateReference"/>
-						.ancestors.indexOf(historyStateParent)!=-1
+					<call-template name="genIndexOf">
+						<with-param name="in">
+							<value-of select="$genHistoryTriggerDispatcherInnerForEachStateReference"/>.ancestors
+						</with-param>
+						<with-param name="var" select="'historyStateParent'"/>
+					 </call-template> !=-1
 				</with-param>
 			</call-template>
 			
@@ -810,8 +847,12 @@
 						<with-param name="var" select="'state'"/>
 						<with-param name="in" select="'currentConfiguration'"/>
 						<with-param name="when">
-							<value-of select="$genHistoryTriggerDispatcherInnerForEachStateReference"/>
-								.ancestors.indexOf(historyStateParent) == -1
+							<call-template name="genIndexOf">
+								<with-param name="in">
+									<value-of select="$genHistoryTriggerDispatcherInnerForEachStateReference"/>.ancestors
+								</with-param>
+								<with-param name="var" select="'historyStateParent'"/>
+							 </call-template> == -1
 						</with-param>
 					</call-template>
 
@@ -841,7 +882,10 @@
 			parent != null &amp;&amp;
 			<choose>
 				<when test="$isChildOfParallel">
-					siblingStates.indexOf(parent) == -1
+					<call-template name="genIndexOf">
+						<with-param name="in" select="'siblingStates'"/>
+						<with-param name="var" select="'parent'"/>
+					</call-template> == -1
 				</when>
 				<otherwise>
 					parent != historyState.parent 
@@ -889,10 +933,16 @@
 					statesExited.push(state);
 				}while((state = state.parent) &amp;&amp;
 					state != lca &amp;&amp; 
-					statesExited.indexOf(state) == -1)
+					<call-template name="genIndexOf">
+						<with-param name="in" select="'statesExited'"/>
+						<with-param name="var" select="'state'"/>
+					</call-template> == -1)
 			</with-param>
-			<with-param name="when">
-				state.ancestors.indexOf(lca) !== -1
+			<with-param name="when">					
+				<call-template name="genIndexOf">
+					<with-param name="in" select="'state.ancestors'"/>
+					<with-param name="var" select="'lca'"/>
+				</call-template> !== -1
 			</with-param>
 		</call-template>
 
@@ -1083,15 +1133,22 @@
 			var toReturn;
 
 			if(state.isBasic){
-				toReturn = currentConfiguration.indexOf(<value-of select="$inPredicateFunctionStateReference"/>)
!= -1;
+				toReturn = 	<call-template name="genIndexOf">
+							<with-param name="in" select="'currentConfiguration'"/>
+							<with-param name="var" select="$inPredicateFunctionStateReference"/>
+						</call-template> != -1;
 			}else{
 				<call-template name="genSome">
 					<with-param name="returnVarName" select="'toReturn'"/>
 					<with-param name="var" select="'s'"/>
 					<with-param name="in" select="'currentConfiguration'"/>
 					<with-param name="when">
-						<value-of select="$inPredicateFunctionStateIdReference"/>
-							.ancestors.indexOf(state) != -1
+						<call-template name="genIndexOf">
+							<with-param name="in">
+								<value-of select="$inPredicateFunctionStateIdReference"/>.ancestors
+							</with-param>
+							<with-param name="var" select="'state'"/>
+						</call-template> != -1
 					</with-param>
 				</call-template>
 			}
@@ -1108,10 +1165,14 @@
 		}
 
 		this.removeListener = function(listener){
-			listeners.splice(listeners.indexOf(listener),1);
+			listeners.splice(	<call-template name="genIndexOf">
+							<with-param name="in" select="'listeners'"/>
+							<with-param name="var" select="'listener'"/>
+						</call-template> ,1);
 		}
 	</variable>
 
+	
 	<template name="genContextHooks"/>
 	<template name="genStateHooks"/>
 	<template name="genParallelSubstateConfigurationSetString"/>

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/StatePatternStatechartGenerator.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/StatePatternStatechartGenerator.xsl?rev=986388&r1=986387&r2=986388&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/StatePatternStatechartGenerator.xsl
(original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/StatePatternStatechartGenerator.xsl
Tue Aug 17 16:46:25 2010
@@ -101,7 +101,12 @@
 		<param name="s"/>
 		<param name="t"/>
 
-		currentConfiguration.splice(currentConfiguration.indexOf(statesExited[0]),1,
+		currentConfiguration.splice(
+			<call-template name="genIndexOf">
+				<with-param name="in" select="'currentConfiguration'"/>
+				<with-param name="var" select="'statesExited[0]'"/>
+			</call-template>
+			,1,
 			<for-each select="$t/c:targets/c:target/c:targetState">
 				<value-of select="."/>
 				<if test="not(position() = last())">,</if>
@@ -113,7 +118,12 @@
 		<param name="s"/>
 		<param name="t"/>
 
-		currentConfiguration.splice(currentConfiguration.indexOf(this),1,
+		currentConfiguration.splice(
+			<call-template name="genIndexOf">
+				<with-param name="in" select="'currentConfiguration'"/>
+				<with-param name="var" select="'this'"/>
+			</call-template>
+			,1,
 			<for-each select="$t/c:targets/c:target/c:targetState">
 				<value-of select="."/>
 				<if test="not(position() = last())">,</if>



Mime
View raw message