Skip to content

Commit f03efc5

Browse files
committed
Update F.script() also supports compilation.
1 parent 3b1e879 commit f03efc5

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

changes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- updated: `U.streamer(beg, [end], function, [skip])` add a new argument `skip`
2626
- updated: deprecated methods in Node.js v7
2727
- updated: `String.parseJSON([date])` added `date` argument (date fields will be converted to `datetime`)
28+
- updated: `F.script()` can compile code to function e.g.: `F.script('next(a + b)', true)` returns a compiled function
2829

2930
- removed: behaviours
3031
- removed: restrictions

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,14 +934,18 @@ Framework.prototype.$routesSort = function(type) {
934934
Framework.prototype.script = function(body, value, callback) {
935935

936936
var fn;
937+
var compilation = value === true && callback === undefined;
937938

938939
try {
939940
fn = new Function('next', 'value', 'now', 'var model=value;var global,require,process,GLOBAL,root,clearImmediate,clearInterval,clearTimeout,setImmediate,setInterval,setTimeout,console,$STRING,$VIEWCACHE,framework_internal,TransformBuilder,Pagination,Page,URLBuilder,UrlBuilder,SchemaBuilder,framework_builders,framework_utils,framework_mail,Image,framework_image,framework_nosql,Builders,U,utils,Utils,Mail,WTF,SOURCE,INCLUDE,MODULE,NOSQL,NOBIN,NOCOUNTER,NOSQLMEMORY,NOMEM,DATABASE,DB,CONFIG,INSTALL,UNINSTALL,RESOURCE,TRANSLATOR,LOG,LOGGER,MODEL,GETSCHEMA,CREATE,UID,TRANSFORM,MAKE,SINGLETON,NEWTRANSFORM,NEWSCHEMA,EACHSCHEMA,FUNCTION,ROUTING,SCHEDULE,OBSOLETE,DEBUG,TEST,RELEASE,is_client,is_server,F,framework,Controller,setTimeout2,clearTimeout2,String,Number,Boolean,Object,Function,Date,isomorphic,I,eval;UPTODATE;try{' + body + '}catch(e){next(e)}');
940941
} catch(e) {
941942
callback && callback(e);
942-
return F;
943+
return compilation ? null : F;
943944
}
944945

946+
if (compilation)
947+
return fn;
948+
945949
fn.call(EMPTYOBJECT, function(value) {
946950

947951
if (!callback)

0 commit comments

Comments
 (0)