char/avril
(wip) why'd you have to go and make things so complicaaaaated?
git clone https://git.t4t.associates/char/avril
7325e8c
main
1mod env; 2mod host; 3 4use std:: cell:: RefCell ; 5use std:: convert:: Infallible ; 6use std:: rc:: Rc ; 7use std:: sync:: Arc ; 8 9use avril_caps::{ Capabilities , Category , Pledge }; 10use avril_core::{ Extension , Op , PublicModule }; 11use avril_host:: environment:: Environment ; 12 13pub fn init ( 14caps : Arc < Capabilities >, 15environment : Rc < RefCell < Environment >>, 16args : Vec < String >, 17) ->Extension { 18let mut ops = env:: ops ( caps. clone (), environment); 19 ops. extend ( host:: ops ( caps. clone (), args)); 20 ops. push ( Op :: new ( 21"op_pledge" , 22move |request : Vec <( String , Option < Vec < String >>, Vec < String >)> |{ 23let error = request 24. into_iter () 25. map ( |( category, allow, deny) |{ 26 category 27. parse ::< Category >() 28. map ( |category|( category, allow, deny)) 29}) 30. collect ::< Result < Pledge , _ >>() 31. and_then ( |request| caps. pledge ( request)) 32. map_err ( |error| error. to_string ()) 33. err (); 34Ok ::< _ , Infallible >( error) 35}, 36)); 37Extension { 38name : "ext:base" , 39dependencies : & [ 40"ext:console" , 41"ext:file" , 42"ext:http" , 43"ext:net" , 44"ext:process" , 45"ext:stdio" , 46"ext:test" , 47"ext:web" , 48], 49 ops, 50modules : const { 51& [ 52PUBLIC_MODULES [ 0 ]. module , 53PUBLIC_MODULES [ 1 ]. module , 54( 55"ext:base/env.js" , 56include_str! ( concat! ( env! ( "OUT_DIR" ), "/env.js" )), 57), 58( 59"ext:base/host.js" , 60include_str! ( concat! ( env! ( "OUT_DIR" ), "/host.js" )), 61), 62( 63"ext:base/pledge.js" , 64include_str! ( concat! ( env! ( "OUT_DIR" ), "/pledge.js" )), 65), 66] 67}, 68entry_point : Some ( "ext:base/main.js" ), 69} 70} 71 72pub const PUBLIC_MODULES : & [ PublicModule ] =& [ 73 avril_core:: public_module!( "avril:std" , "ext:base" , "main" ), 74 avril_core:: public_module!( "avril:std/sync" , "ext:base" , "sync" ), 75];