stdweb-internal-runtime-0.1.5/Cargo.toml.orig010064400017500001750000000011431354366351500174220ustar0000000000000000[package] name = "stdweb-internal-runtime" version = "0.1.5" authors = ["Jan Bujak "] repository = "https://github.com/koute/stdweb" homepage = "https://github.com/koute/stdweb" documentation = "https://docs.rs/stdweb/*/stdweb/" license = "MIT/Apache-2.0" readme = "README.md" keywords = ["web", "asmjs", "webasm", "javascript"] categories = ["api-bindings", "gui", "web-programming"] description = "Internal runtime for the `stdweb` crate" build = "build.rs" [features] default = [] "docs-rs" = [] [package.metadata.docs.rs] features = ["docs-rs"] all-features = false no-default-features = true stdweb-internal-runtime-0.1.5/Cargo.toml0000644000000021540000000000000136610ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] name = "stdweb-internal-runtime" version = "0.1.5" authors = ["Jan Bujak "] build = "build.rs" description = "Internal runtime for the `stdweb` crate" homepage = "https://github.com/koute/stdweb" documentation = "https://docs.rs/stdweb/*/stdweb/" readme = "README.md" keywords = ["web", "asmjs", "webasm", "javascript"] categories = ["api-bindings", "gui", "web-programming"] license = "MIT/Apache-2.0" repository = "https://github.com/koute/stdweb" [package.metadata.docs.rs] all-features = false features = ["docs-rs"] no-default-features = true [features] default = [] docs-rs = [] stdweb-internal-runtime-0.1.5/README.md010064400017500001750000000002421337463116100160030ustar0000000000000000# Internal runtime for the `stdweb` crate These aren't the droids you are looking for; please go to [stdweb] instead. [stdweb]: https://github.com/koute/stdweb stdweb-internal-runtime-0.1.5/Web.toml010064400017500001750000000003211347032716600161400ustar0000000000000000[cargo-web] minimum-version = "0.6.24" [target.emscripten] prepend-js = ["src/runtime.js", "src/runtime_emscripten.js"] [target.wasm32-unknown-unknown] prepend-js = ["src/runtime.js", "src/runtime_wasm.js"] stdweb-internal-runtime-0.1.5/build.rs010064400017500001750000000045041337463116100161760ustar0000000000000000use std::env; use std::fs::File; use std::io::{self, Read, Write}; use std::path::Path; pub fn read< P: AsRef< Path > >( path: P ) -> Result< String, io::Error > { let mut fp = File::open( path.as_ref() )?; let mut output = String::new(); fp.read_to_string( &mut output )?; Ok( output ) } fn generate_body( output: &mut String ) -> &'static str { output.push_str( "$sub!( r##\"" ); let target = env::var( "TARGET" ).expect( "no TARGET defined" ); let target_specific_runtime_path = match target.as_str() { "wasm32-unknown-unknown" => "src/runtime_wasm.js", _ => "src/runtime_emscripten.js" }; let runtime = read( "src/runtime.js" ).expect( "cannot read runtime" ); let target_specific_runtime = read( target_specific_runtime_path ).expect( "cannot read target specific runtime" ); for line in runtime.lines().chain( target_specific_runtime.lines() ) { if let Some( position ) = line.find( "//" ) { // Strip out comments. output.push_str( &line[ 0..position ] ); } else { output.push_str( &line ); } output.push_str( " " ); } output.push_str( "\"## )" ); target_specific_runtime_path } fn main() { let out_dir = env::var( "OUT_DIR" ).expect( "no OUT_DIR defined" ); let out_path = Path::new( &out_dir ).join( "runtime.rs" ); let mut fp = File::create( &out_path ).expect( "cannot create a file in OUT_DIR" ); let separator = if cfg!( windows ) { "\\" } else { "/" }; println!( "cargo:rustc-env=PATH_SEPARATOR={}", separator ); let mut output = String::new(); output.push_str( "#[doc(hidden)]" ); output.push_str( "#[macro_export]" ); output.push_str( "macro_rules! stdweb_internal_runtime_initialize { ($sub:tt) => {" ); // We need to emit the runtime ourselves if we're not being compiled under cargo-web. if !env::var( "COMPILING_UNDER_CARGO_WEB" ).map( |var| var == "1" ).unwrap_or( false ) { let target_specific_runtime_path = generate_body( &mut output ); println!( "cargo:rerun-if-changed=src/runtime.js" ); println!( "cargo:rerun-if-changed={}", target_specific_runtime_path ); } output.push_str( "}}" ); fp.write_all( output.as_bytes() ).unwrap(); println!( "cargo:rerun-if-env-changed=COMPILING_UNDER_CARGO_WEB" ); } stdweb-internal-runtime-0.1.5/src/lib.rs010064400017500001750000000001631337463116100164310ustar0000000000000000#[cfg(not(feature = "docs-rs"))] include!( concat!( env!( "OUT_DIR" ), env!( "PATH_SEPARATOR" ), "runtime.rs" ) ); stdweb-internal-runtime-0.1.5/src/runtime.js010064400017500001750000000370431347032716600173510ustar0000000000000000Module.STDWEB_PRIVATE = {}; // This is based on code from Emscripten's preamble.js. Module.STDWEB_PRIVATE.to_utf8 = function to_utf8( str, addr ) { var HEAPU8 = Module.HEAPU8; for( var i = 0; i < str.length; ++i ) { // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! So decode UTF16->UTF32->UTF8. // See http://unicode.org/faq/utf_bom.html#utf16-3 // For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description and https://www.ietf.org/rfc/rfc2279.txt and https://tools.ietf.org/html/rfc3629 var u = str.charCodeAt( i ); // possibly a lead surrogate if( u >= 0xD800 && u <= 0xDFFF ) { u = 0x10000 + ((u & 0x3FF) << 10) | (str.charCodeAt( ++i ) & 0x3FF); } if( u <= 0x7F ) { HEAPU8[ addr++ ] = u; } else if( u <= 0x7FF ) { HEAPU8[ addr++ ] = 0xC0 | (u >> 6); HEAPU8[ addr++ ] = 0x80 | (u & 63); } else if( u <= 0xFFFF ) { HEAPU8[ addr++ ] = 0xE0 | (u >> 12); HEAPU8[ addr++ ] = 0x80 | ((u >> 6) & 63); HEAPU8[ addr++ ] = 0x80 | (u & 63); } else if( u <= 0x1FFFFF ) { HEAPU8[ addr++ ] = 0xF0 | (u >> 18); HEAPU8[ addr++ ] = 0x80 | ((u >> 12) & 63); HEAPU8[ addr++ ] = 0x80 | ((u >> 6) & 63); HEAPU8[ addr++ ] = 0x80 | (u & 63); } else if( u <= 0x3FFFFFF ) { HEAPU8[ addr++ ] = 0xF8 | (u >> 24); HEAPU8[ addr++ ] = 0x80 | ((u >> 18) & 63); HEAPU8[ addr++ ] = 0x80 | ((u >> 12) & 63); HEAPU8[ addr++ ] = 0x80 | ((u >> 6) & 63); HEAPU8[ addr++ ] = 0x80 | (u & 63); } else { HEAPU8[ addr++ ] = 0xFC | (u >> 30); HEAPU8[ addr++ ] = 0x80 | ((u >> 24) & 63); HEAPU8[ addr++ ] = 0x80 | ((u >> 18) & 63); HEAPU8[ addr++ ] = 0x80 | ((u >> 12) & 63); HEAPU8[ addr++ ] = 0x80 | ((u >> 6) & 63); HEAPU8[ addr++ ] = 0x80 | (u & 63); } } }; Module.STDWEB_PRIVATE.noop = function() {}; Module.STDWEB_PRIVATE.to_js = function to_js( address ) { var kind = Module.HEAPU8[ address + 12 ]; if( kind === 0 ) { return undefined; } else if( kind === 1 ) { return null; } else if( kind === 2 ) { return Module.HEAP32[ address / 4 ]; } else if( kind === 3 ) { return Module.HEAPF64[ address / 8 ]; } else if( kind === 4 ) { var pointer = Module.HEAPU32[ address / 4 ]; var length = Module.HEAPU32[ (address + 4) / 4 ]; return Module.STDWEB_PRIVATE.to_js_string( pointer, length ); } else if( kind === 5 ) { return false; } else if( kind === 6 ) { return true; } else if( kind === 7 ) { var pointer = Module.STDWEB_PRIVATE.arena + Module.HEAPU32[ address / 4 ]; var length = Module.HEAPU32[ (address + 4) / 4 ]; var output = []; for( var i = 0; i < length; ++i ) { output.push( Module.STDWEB_PRIVATE.to_js( pointer + i * 16 ) ); } return output; } else if( kind === 8 ) { var arena = Module.STDWEB_PRIVATE.arena; var value_array_pointer = arena + Module.HEAPU32[ address / 4 ]; var length = Module.HEAPU32[ (address + 4) / 4 ]; var key_array_pointer = arena + Module.HEAPU32[ (address + 8) / 4 ]; var output = {}; for( var i = 0; i < length; ++i ) { var key_pointer = Module.HEAPU32[ (key_array_pointer + i * 8) / 4 ]; var key_length = Module.HEAPU32[ (key_array_pointer + 4 + i * 8) / 4 ]; var key = Module.STDWEB_PRIVATE.to_js_string( key_pointer, key_length ); var value = Module.STDWEB_PRIVATE.to_js( value_array_pointer + i * 16 ); output[ key ] = value; } return output; } else if( kind === 9 ) { return Module.STDWEB_PRIVATE.acquire_js_reference( Module.HEAP32[ address / 4 ] ); } else if( kind === 10 || kind === 12 || kind === 13 ) { var adapter_pointer = Module.HEAPU32[ address / 4 ]; var pointer = Module.HEAPU32[ (address + 4) / 4 ]; var deallocator_pointer = Module.HEAPU32[ (address + 8) / 4 ]; var num_ongoing_calls = 0; var drop_queued = false; var output = function() { if( pointer === 0 || drop_queued === true ) { if (kind === 10) { throw new ReferenceError( "Already dropped Rust function called!" ); } else if (kind === 12) { throw new ReferenceError( "Already dropped FnMut function called!" ); } else { throw new ReferenceError( "Already called or dropped FnOnce function called!" ); } } var function_pointer = pointer; if (kind === 13) { output.drop = Module.STDWEB_PRIVATE.noop; pointer = 0; } if (num_ongoing_calls !== 0) { if (kind === 12 || kind === 13) { throw new ReferenceError( "FnMut function called multiple times concurrently!" ); } } var args = Module.STDWEB_PRIVATE.alloc( 16 ); Module.STDWEB_PRIVATE.serialize_array( args, arguments ); try { num_ongoing_calls += 1; Module.STDWEB_PRIVATE.dyncall( "vii", adapter_pointer, [function_pointer, args] ); var result = Module.STDWEB_PRIVATE.tmp; Module.STDWEB_PRIVATE.tmp = null; } finally { num_ongoing_calls -= 1; } if( drop_queued === true && num_ongoing_calls === 0 ) { output.drop(); } return result; }; output.drop = function() { if (num_ongoing_calls !== 0) { drop_queued = true; return; } output.drop = Module.STDWEB_PRIVATE.noop; var function_pointer = pointer; pointer = 0; if (function_pointer != 0) { Module.STDWEB_PRIVATE.dyncall( "vi", deallocator_pointer, [function_pointer] ); } }; return output; } else if( kind === 14 ) { var pointer = Module.HEAPU32[ address / 4 ]; var length = Module.HEAPU32[ (address + 4) / 4 ]; var array_kind = Module.HEAPU32[ (address + 8) / 4 ]; var pointer_end = pointer + length; switch( array_kind ) { case 0: return Module.HEAPU8.subarray( pointer, pointer_end ); case 1: return Module.HEAP8.subarray( pointer, pointer_end ); case 2: return Module.HEAPU16.subarray( pointer, pointer_end ); case 3: return Module.HEAP16.subarray( pointer, pointer_end ); case 4: return Module.HEAPU32.subarray( pointer, pointer_end ); case 5: return Module.HEAP32.subarray( pointer, pointer_end ); case 6: return Module.HEAPF32.subarray( pointer, pointer_end ); case 7: return Module.HEAPF64.subarray( pointer, pointer_end ); } } else if( kind === 15 ) { return Module.STDWEB_PRIVATE.get_raw_value( Module.HEAPU32[ address / 4 ] ); } }; Module.STDWEB_PRIVATE.serialize_object = function serialize_object( address, value ) { var keys = Object.keys( value ); var length = keys.length; var key_array_pointer = Module.STDWEB_PRIVATE.alloc( length * 8 ); var value_array_pointer = Module.STDWEB_PRIVATE.alloc( length * 16 ); Module.HEAPU8[ address + 12 ] = 8; Module.HEAPU32[ address / 4 ] = value_array_pointer; Module.HEAPU32[ (address + 4) / 4 ] = length; Module.HEAPU32[ (address + 8) / 4 ] = key_array_pointer; for( var i = 0; i < length; ++i ) { var key = keys[ i ]; var key_address = key_array_pointer + i * 8; Module.STDWEB_PRIVATE.to_utf8_string( key_address, key ); Module.STDWEB_PRIVATE.from_js( value_array_pointer + i * 16, value[ key ] ); } }; Module.STDWEB_PRIVATE.serialize_array = function serialize_array( address, value ) { var length = value.length; var pointer = Module.STDWEB_PRIVATE.alloc( length * 16 ); Module.HEAPU8[ address + 12 ] = 7; Module.HEAPU32[ address / 4 ] = pointer; Module.HEAPU32[ (address + 4) / 4 ] = length; for( var i = 0; i < length; ++i ) { Module.STDWEB_PRIVATE.from_js( pointer + i * 16, value[ i ] ); } }; // New browsers and recent Node var cachedEncoder = ( typeof TextEncoder === "function" ? new TextEncoder( "utf-8" ) // Old Node (before v11) : ( typeof util === "object" && util && typeof util.TextEncoder === "function" ? new util.TextEncoder( "utf-8" ) // Old browsers : null ) ); if ( cachedEncoder != null ) { Module.STDWEB_PRIVATE.to_utf8_string = function to_utf8_string( address, value ) { var buffer = cachedEncoder.encode( value ); var length = buffer.length; var pointer = 0; if ( length > 0 ) { pointer = Module.STDWEB_PRIVATE.alloc( length ); Module.HEAPU8.set( buffer, pointer ); } Module.HEAPU32[ address / 4 ] = pointer; Module.HEAPU32[ (address + 4) / 4 ] = length; }; } else { Module.STDWEB_PRIVATE.to_utf8_string = function to_utf8_string( address, value ) { var length = Module.STDWEB_PRIVATE.utf8_len( value ); var pointer = 0; if ( length > 0 ) { pointer = Module.STDWEB_PRIVATE.alloc( length ); Module.STDWEB_PRIVATE.to_utf8( value, pointer ); } Module.HEAPU32[ address / 4 ] = pointer; Module.HEAPU32[ (address + 4) / 4 ] = length; }; } Module.STDWEB_PRIVATE.from_js = function from_js( address, value ) { var kind = Object.prototype.toString.call( value ); if( kind === "[object String]" ) { Module.HEAPU8[ address + 12 ] = 4; Module.STDWEB_PRIVATE.to_utf8_string( address, value ); } else if( kind === "[object Number]" ) { if( value === (value|0) ) { Module.HEAPU8[ address + 12 ] = 2; Module.HEAP32[ address / 4 ] = value; } else { Module.HEAPU8[ address + 12 ] = 3; Module.HEAPF64[ address / 8 ] = value; } } else if( value === null ) { Module.HEAPU8[ address + 12 ] = 1; } else if( value === undefined ) { Module.HEAPU8[ address + 12 ] = 0; } else if( value === false ) { Module.HEAPU8[ address + 12 ] = 5; } else if( value === true ) { Module.HEAPU8[ address + 12 ] = 6; } else if( kind === "[object Symbol]" ) { var id = Module.STDWEB_PRIVATE.register_raw_value( value ); Module.HEAPU8[ address + 12 ] = 15; Module.HEAP32[ address / 4 ] = id; } else { var refid = Module.STDWEB_PRIVATE.acquire_rust_reference( value ); Module.HEAPU8[ address + 12 ] = 9; Module.HEAP32[ address / 4 ] = refid; } }; // New browsers and recent Node var cachedDecoder = ( typeof TextDecoder === "function" ? new TextDecoder( "utf-8" ) // Old Node (before v11) : ( typeof util === "object" && util && typeof util.TextDecoder === "function" ? new util.TextDecoder( "utf-8" ) // Old browsers : null ) ); if ( cachedDecoder != null ) { Module.STDWEB_PRIVATE.to_js_string = function to_js_string( index, length ) { return cachedDecoder.decode( Module.HEAPU8.subarray( index, index + length ) ); }; } else { // This is ported from Rust's stdlib; it's faster than // the string conversion from Emscripten. Module.STDWEB_PRIVATE.to_js_string = function to_js_string( index, length ) { var HEAPU8 = Module.HEAPU8; index = index|0; length = length|0; var end = (index|0) + (length|0); var output = ""; while( index < end ) { var x = HEAPU8[ index++ ]; if( x < 128 ) { output += String.fromCharCode( x ); continue; } var init = (x & (0x7F >> 2)); var y = 0; if( index < end ) { y = HEAPU8[ index++ ]; } var ch = (init << 6) | (y & 63); if( x >= 0xE0 ) { var z = 0; if( index < end ) { z = HEAPU8[ index++ ]; } var y_z = ((y & 63) << 6) | (z & 63); ch = init << 12 | y_z; if( x >= 0xF0 ) { var w = 0; if( index < end ) { w = HEAPU8[ index++ ]; } ch = (init & 7) << 18 | ((y_z << 6) | (w & 63)); output += String.fromCharCode( 0xD7C0 + (ch >> 10) ); ch = 0xDC00 + (ch & 0x3FF); } } output += String.fromCharCode( ch ); continue; } return output; }; } Module.STDWEB_PRIVATE.id_to_ref_map = {}; Module.STDWEB_PRIVATE.id_to_refcount_map = {}; Module.STDWEB_PRIVATE.ref_to_id_map = new WeakMap(); // Not all types can be stored in a WeakMap Module.STDWEB_PRIVATE.ref_to_id_map_fallback = new Map(); Module.STDWEB_PRIVATE.last_refid = 1; Module.STDWEB_PRIVATE.id_to_raw_value_map = {}; Module.STDWEB_PRIVATE.last_raw_value_id = 1; Module.STDWEB_PRIVATE.acquire_rust_reference = function( reference ) { if( reference === undefined || reference === null ) { return 0; } var id_to_refcount_map = Module.STDWEB_PRIVATE.id_to_refcount_map; var id_to_ref_map = Module.STDWEB_PRIVATE.id_to_ref_map; var ref_to_id_map = Module.STDWEB_PRIVATE.ref_to_id_map; var ref_to_id_map_fallback = Module.STDWEB_PRIVATE.ref_to_id_map_fallback; var refid = ref_to_id_map.get( reference ); if( refid === undefined ) { refid = ref_to_id_map_fallback.get( reference ); } if( refid === undefined ) { refid = Module.STDWEB_PRIVATE.last_refid++; try { ref_to_id_map.set( reference, refid ); } catch (e) { ref_to_id_map_fallback.set( reference, refid ); } } if( refid in id_to_ref_map ) { id_to_refcount_map[ refid ]++; } else { id_to_ref_map[ refid ] = reference; id_to_refcount_map[ refid ] = 1; } return refid; }; Module.STDWEB_PRIVATE.acquire_js_reference = function( refid ) { return Module.STDWEB_PRIVATE.id_to_ref_map[ refid ]; }; Module.STDWEB_PRIVATE.increment_refcount = function( refid ) { Module.STDWEB_PRIVATE.id_to_refcount_map[ refid ]++; }; Module.STDWEB_PRIVATE.decrement_refcount = function( refid ) { var id_to_refcount_map = Module.STDWEB_PRIVATE.id_to_refcount_map; if( 0 == --id_to_refcount_map[ refid ] ) { var id_to_ref_map = Module.STDWEB_PRIVATE.id_to_ref_map; var ref_to_id_map_fallback = Module.STDWEB_PRIVATE.ref_to_id_map_fallback; var reference = id_to_ref_map[ refid ]; delete id_to_ref_map[ refid ]; delete id_to_refcount_map[ refid ]; ref_to_id_map_fallback.delete(reference); } }; Module.STDWEB_PRIVATE.register_raw_value = function( value ) { var id = Module.STDWEB_PRIVATE.last_raw_value_id++; Module.STDWEB_PRIVATE.id_to_raw_value_map[ id ] = value; return id; }; Module.STDWEB_PRIVATE.unregister_raw_value = function( id ) { delete Module.STDWEB_PRIVATE.id_to_raw_value_map[ id ]; }; Module.STDWEB_PRIVATE.get_raw_value = function( id ) { return Module.STDWEB_PRIVATE.id_to_raw_value_map[ id ]; }; stdweb-internal-runtime-0.1.5/src/runtime_emscripten.js010064400017500001750000000004541354024445100215670ustar0000000000000000Module.STDWEB_PRIVATE.alloc = function alloc( size ) { return _malloc( size ); }; Module.STDWEB_PRIVATE.dyncall = function( signature, ptr, args ) { return dynCall( signature, ptr, args ); }; Module.STDWEB_PRIVATE.utf8_len = function utf8_len( str ) { return lengthBytesUTF8( str ); }; stdweb-internal-runtime-0.1.5/src/runtime_wasm.js010064400017500001750000000027521337463116100203730ustar0000000000000000Module.STDWEB_PRIVATE.alloc = function alloc( size ) { return Module.web_malloc( size ); }; Module.STDWEB_PRIVATE.dyncall = function( signature, ptr, args ) { return Module.web_table.get( ptr ).apply( null, args ); }; // This is based on code from Emscripten's preamble.js. Module.STDWEB_PRIVATE.utf8_len = function utf8_len( str ) { var len = 0; for( var i = 0; i < str.length; ++i ) { // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! So decode UTF16->UTF32->UTF8. // See http://unicode.org/faq/utf_bom.html#utf16-3 var u = str.charCodeAt( i ); // possibly a lead surrogate if( u >= 0xD800 && u <= 0xDFFF ) { u = 0x10000 + ((u & 0x3FF) << 10) | (str.charCodeAt( ++i ) & 0x3FF); } if( u <= 0x7F ) { ++len; } else if( u <= 0x7FF ) { len += 2; } else if( u <= 0xFFFF ) { len += 3; } else if( u <= 0x1FFFFF ) { len += 4; } else if( u <= 0x3FFFFFF ) { len += 5; } else { len += 6; } } return len; }; Module.STDWEB_PRIVATE.prepare_any_arg = function( value ) { var arg = Module.STDWEB_PRIVATE.alloc( 16 ); Module.STDWEB_PRIVATE.from_js( arg, value ); return arg; }; Module.STDWEB_PRIVATE.acquire_tmp = function( dummy ) { var value = Module.STDWEB_PRIVATE.tmp; Module.STDWEB_PRIVATE.tmp = null; return value; }; stdweb-internal-runtime-0.1.5/.cargo_vcs_info.json0000644000000001120000000000000156530ustar00{ "git": { "sha1": "7ffa8a37862d5692400f21086d14d92e654eaf65" } }