char/avril
(wip) why'd you have to go and make things so complicaaaaated?
git clone https://git.t4t.associates/char/avril
81eaeb3
main
1use avril_core::{ Extension , Runtime , RuntimeOptions }; 2 3fn runtime () ->Runtime { 4Runtime :: new ( RuntimeOptions { 5extensions : vec! [ Extension { 6name : "ext:test" , 7dependencies : & [], 8ops : vec! [], 9modules : & [( "ext:test/main.js" , r#" 10import {clone} from 'ext:core/structured_clone'; 11const hosts=new WeakMap(); 12globalThis.hostCloneCount=0; 13globalThis.makeHost=value=>{const object={};hosts.set(object,value);return object;}; 14globalThis.hostValue=object=>hosts.get(object); 15const cloneHost=source=>{ 16if(hosts.get(source)==='fail')throw globalThis.reason; 17hostCloneCount++; 18return makeHost(hosts.get(source)); 19}; 20globalThis.cloneForTest=value=>clone(value,[],object=>hosts.has(object)?1:0,cloneHost,message=>new Error(message)); 21"# )], 22entry_point : Some ( "ext:test/main.js" ), 23}], 24 ..Default :: default () 25}). unwrap () 26} 27 28# [ test ] 29fn native_clone_bridge_preserves_extension_host_identity_without_web_policy () { 30let mut runtime =runtime (); 31assert! ( runtime. execute_script ::< bool >( "host graph" , r#" 32const host=makeHost('value'), source={host,again:host};source.self=source; 33const copy=cloneForTest(source); 34copy!==source && copy.self===copy && copy.host===copy.again && copy.host!==host && hostValue(copy.host)==='value' && hostCloneCount===1 35"# ). unwrap ()); 36} 37 38# [ test ] 39fn policy_and_getter_exceptions_preserve_identity_and_allow_reentrant_clones () { 40let mut runtime =runtime (); 41 runtime 42. execute_script ::<()>( 43"exceptions" , 44r#" 45globalThis.reason={reason:true}; 46for(const source of [makeHost('fail'),{get x(){throw reason;}}]){ 47try{cloneForTest(source);throw Error('Accepted');}catch(e){if(e!==reason)throw e;} 48} 49"# , 50) 51. unwrap (); 52assert! ( 53 runtime 54. execute_script ::< bool >( 55"next turn" , 56r#" 57const result=cloneForTest({get x(){return cloneForTest({value:3});}}); 58result.x.value===3 59"# 60) 61. unwrap () 62); 63}