@@ -60,12 +60,12 @@ var functionNode = (function() {
6060 // Setup jsFunction and its string property + validate them
6161 //
6262 this . jsFunctionString = jsFunction . toString ( ) ;
63- if ( ! validateStringIsFunction ( this . jsFunctionString ) ) {
63+ if ( ! gpu_utils . isFunctionString ( this . jsFunctionString ) ) {
6464 console . error ( "jsFunction, to string conversion check falied: not a function?" , this . jsFunctionString ) ;
6565 throw "jsFunction, to string conversion check falied: not a function?" ;
6666 }
6767
68- if ( ! isFunction ( jsFunction ) ) {
68+ if ( ! gpu_utils . isFunction ( jsFunction ) ) {
6969 //throw "jsFunction, is not a valid JS Function";
7070 this . jsFunction = null ;
7171 } else {
@@ -75,15 +75,18 @@ var functionNode = (function() {
7575 //
7676 // Setup the function name property
7777 //
78- this . functionName = functionName || ( jsFunction && jsFunction . name ) || FUNCTION_NAME . exec ( this . jsFunctionString ) [ 1 ] ;
78+ this . functionName = functionName ||
79+ ( jsFunction && jsFunction . name ) ||
80+ gpu_utils . getFunctionName_fromString ( this . jsFunctionString ) ;
81+
7982 if ( ! ( this . functionName ) ) {
8083 throw "jsFunction, missing name argument or value" ;
8184 }
8285
8386 //
8487 // Extract parameter name, and its argument types
8588 //
86- this . paramNames = getParamNames ( this . jsFunctionString ) ;
89+ this . paramNames = gpu_utils . getParamNames_fromString ( this . jsFunctionString ) ;
8790 if ( paramTypeArray != null ) {
8891 if ( paramTypeArray . length != this . paramNames . length ) {
8992 throw "Invalid argument type array length, against function length -> (" +
@@ -105,78 +108,6 @@ var functionNode = (function() {
105108 this . returnType = returnType || "float" ;
106109 }
107110
108- //
109- // Utility functions
110- //----------------------------------------------------------------------------------------------------
111-
112- ///
113- /// Function: isFunction
114- ///
115- /// [static] Return TRUE, on a JS function
116- ///
117- /// This is 'static' function, not a class function functionNode.isFunction(...)
118- ///
119- /// Parameters:
120- /// funcObj - {JS Function} Object to validate if its a function
121- ///
122- /// Returns:
123- /// {Boolean} TRUE if the object is a JS function
124- ///
125- function isFunction ( funcObj ) {
126- return typeof ( funcObj ) === 'function' ;
127- }
128-
129- ///
130- /// Function: validateStringIsFunction
131- ///
132- /// [static] Return TRUE, on a valid JS function string
133- ///
134- /// This is 'static' function, not a class function functionNode.validateStringIsFunction(...)
135- ///
136- /// Parameters:
137- /// funcStr - {String} String of JS function to validate
138- ///
139- /// Returns:
140- /// {Boolean} TRUE if the string passes basic validation
141- ///
142- function validateStringIsFunction ( funcStr ) {
143- if ( funcStr !== null ) {
144- return ( funcStr . slice ( 0 , "function" . length ) . toLowerCase ( ) == "function" ) ;
145- }
146- return false ;
147- }
148-
149- var FUNCTION_NAME = / f u n c t i o n ( [ ^ ( ] * ) / ;
150- var STRIP_COMMENTS = / ( ( \/ \/ .* $ ) | ( \/ \* [ \s \S ] * ?\* \/ ) ) / mg;
151- var ARGUMENT_NAMES = / ( [ ^ \s , ] + ) / g;
152-
153- ///
154- /// Function: getParamNames
155- ///
156- /// [static] Return list of parameter names extracted from the JS function string
157- ///
158- /// This is 'static' function, not a class function: functionNode.getParamNames(...)
159- ///
160- /// Parameters:
161- /// funcStr - {String} String of JS function to validate
162- ///
163- /// Returns:
164- /// {[String, ...]} Array representing all the parameter names
165- ///
166- function getParamNames ( func ) {
167- var fnStr = func . toString ( ) . replace ( STRIP_COMMENTS , '' ) ;
168- var result = fnStr . slice ( fnStr . indexOf ( '(' ) + 1 , fnStr . indexOf ( ')' ) ) . match ( ARGUMENT_NAMES ) ;
169- if ( result === null )
170- result = [ ] ;
171- return result ;
172- }
173-
174- // Passing it to the class object, in case it is needed elsewhere
175- // Note, support for this is not guranteed across versions.
176- functionNode . isFunction = isFunction ;
177- functionNode . validateStringIsFunction = validateStringIsFunction ;
178- functionNode . getParamNames = getParamNames ;
179-
180111 //
181112 // Core function
182113 //----------------------------------------------------------------------------------------------------
0 commit comments