@@ -2,31 +2,55 @@ var __OOAPI;
22
33importScripts ( "OOAPI.js" ) ;
44
5- if ( ! __OOAPI ) {
6- console . log ( "Error: OOAPI Not Loaded" ) ;
7- self . close ( ) ;
5+ if ( ! __OOAPI ) {
6+ console . log ( "Error: OOAPI Not Loaded" ) ;
7+ self . close ( ) ;
88} ;
99
10- /** Hook independant channels, channel will not be deletable **/
10+ // Hook independent channels that cannot be removed
1111__OOAPI . createChannel ( "::eval" , 1 , Math . round ( Math . random ( ) * 100000 ) ) ;
1212__OOAPI . createChannel ( "::debug" , 1 , Math . round ( Math . random ( ) * 100000 ) ) ;
1313
14- /** Load the BSE Abstraction Runtime **/
15- importScripts ( 'api/Runtime.js' , 'api/ScriptManager.js' , 'api/Player.js' , 'api/Display.js' , 'api/Tween.js' , 'api/Utils.js' , 'api/Global.js' , 'api/Function.js' ) ;
14+ // Load the BSE Abstraction Runtime
15+ importScripts ( 'api/Runtime.js' ,
16+ 'api/ScriptManager.js' ,
17+ 'api/Player.js' ,
18+ 'api/Display.js' ,
19+ 'api/Tween.js' ,
20+ 'api/Utils.js' ,
21+ 'api/Global.js' ,
22+ 'api/Function.js' ) ;
1623
17- /** Immediately Hook into the eval channel, blocking future hooks **/
18- __schannel ( "::eval" , function ( msg ) {
19- if ( Tween && Tween . extendWithEasingFunctions ) {
20- Tween . extendWithEasingFunctions ( this ) ;
21- }
22- var clearTimeout = Utils . clearTimeout ;
23- var clearInterval = Utils . clearInterval ;
24- eval ( msg ) ;
24+ // Immediately Hook into the eval channel, blocking future hooks
25+ __schannel ( "::eval" , function ( msg ) {
26+ // Prevent some things from being accessed in eval easily
27+ ( function ( __code , importScripts , postMessage , addEventListener , self ) {
28+ if ( Tween && Tween . extendWithEasingFunctions ) {
29+ Tween . extendWithEasingFunctions ( this ) ;
30+ }
31+ var clearTimeout = Utils . clearTimeout ;
32+ var clearInterval = Utils . clearInterval ;
33+ eval ( __code ) ;
34+ } ) ( msg ) ;
2535} ) ;
26- __schannel ( "::debug" , function ( msg ) {
27- if ( msg . action === "list_channels" ) {
28- __achannel ( "::worker:debug" , "worker" , __OOAPI . listChannels ( ) ) ;
29- }
36+
37+ __schannel ( "::debug" , function ( msg ) {
38+ if ( typeof msg === 'undefined' || msg === null ||
39+ ! msg . hasOwnProperty ( 'action' ) ) {
40+ __achannel ( '::worker:debug' , 'worker' , 'Malformed request' ) ;
41+ return ;
42+ }
43+ if ( msg . action === 'list-channels' ) {
44+ __achannel ( '::worker:debug' , 'worker' , __OOAPI . listChannels ( ) ) ;
45+ } else if ( msg . action === 'raw-eval' ) {
46+ try {
47+ __achannel ( '::worker:debug' , 'worker' , eval ( msg . code ) ) ;
48+ } catch ( e ) {
49+ __achannel ( '::worker:debug' , 'worker' , 'Error: ' + e ) ;
50+ }
51+ } else {
52+ __achannel ( '::worker:debug' , 'worker' , 'Unrecognized action' ) ;
53+ }
3054} ) ;
3155
3256__achannel ( "::worker:state" , "worker" , "running" ) ;
0 commit comments