Overview
Comment: | More work Duktape-based chrome-alike environment |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: | d73ab988adc8175b6bc1e0253027a5b43a275b0d |
User & Date: | rkeene on 2019-06-12 19:39:48 |
Other Links: | manifest | tags |
Context
2019-06-12
| ||
19:40 | Tcl-based interface to JS SSH Agent check-in: 7ef094be65 user: rkeene tags: trunk | |
19:39 | More work Duktape-based chrome-alike environment check-in: d73ab988ad user: rkeene tags: trunk | |
19:38 | Handle converting from buffers which cannot be converted to byte arrays check-in: af11332c35 user: rkeene tags: trunk | |
Changes
Modified build/tcl/chrome-emu.js from [cfc05731e7] to [37c439b24d].
1 +console = {}; 2 +console._formatArgs = function(argInfo) { 3 + var idx, outArray; 4 + var arg; 5 + 6 + idx = 0; 7 + outArray = []; 8 + for (idx = 0; idx < argInfo.length; idx++) { 9 + arg = argInfo[idx]; 10 + if (typeof(arg) === 'string' || typeof(arg) === 'number') { 11 + outArray.push(arg); 12 + } else if (typeof(arg) === 'undefined') { 13 + outArray.push("<undefined>"); 14 + } else if (arg === null) { 15 + outArray.push("<null>"); 16 + } else { 17 + outArray.push(JSON.stringify(arg)); 18 + } 19 + } 20 + return(outArray.join(' ')); 21 +} 22 +console.log = function() { 23 + runtime.puts("CON> " + console._formatArgs(arguments)); 24 +} 25 +console.error = function(message) { 26 + runtime.puts(runtime.stderr, "ERR> " + console._formatArgs(arguments)); 27 + return; 28 +} 29 +console.debug = function(message) { 30 + runtime.puts(runtime.stderr, "DBG> " + console._formatArgs(arguments)); 31 + return; 32 +} 33 + 34 +if (!Array.from) { 35 + Array.from = function(source) { 36 + var result, idx; 37 + result = new Array(source.length); 38 + for (idx = 0; idx < source.length; idx++) { 39 + result[idx] = source[idx]; 40 + } 41 + return(result); 42 + } 43 +} 44 + 45 +if (!Array.prototype.slice) { 46 + Array.prototype.slice = function(start) { 47 + var result, idx, outIdx; 48 + result = []; 49 + outIdx = 0; 50 + for (idx = start; idx < this.length; idx++) { 51 + result[outIdx] = this[idx]; 52 + outIdx++; 53 + } 54 + return(result); 55 + } 56 +} 57 + 58 +if (!String.prototype.padStart) { 59 + String.prototype.padStart = function(len, char) { 60 + if (this.length >= len) { 61 + return(this); 62 + } 63 + 64 + return((char + this).padStart(len, char)) 65 + } 66 +} 67 + 68 +if (!RegExp.prototype.compile) { 69 + RegExp.prototype.compile = function() { 70 + return; 71 + }; 72 +} 73 + 74 +if (!Uint8Array.prototype.forEach) { 75 + Uint8Array.prototype.forEach = function(callback) { 76 + var idx; 77 + for (idx = 0; idx < this.length; idx++) { 78 + callback(this[idx]); 79 + } 80 + } 81 +} 82 + 83 +if (!Uint8Array.prototype.map) { 84 + Uint8Array.prototype.map = function(callback) { 85 + var result, idx; 86 + result = []; 87 + 88 + for (idx = 0; idx < this.length; idx++) { 89 + result.push(callback(this[idx])); 90 + } 1 91 2 -console = { 3 - log: function() { 4 - /* XXX:TODO: Logging */ 92 + return(result); 5 93 } 6 94 } 95 + 96 +navigator = { 97 + userAgent: "" 98 +}; 99 + 100 +crypto = { 101 + subtle: { 102 + digest: function(hash, data) { 103 + var bufferData; 104 + bufferData = new Buffer(data); 105 + return(crypto.subtle.digest.internal(hash, bufferData)); 106 + } 107 + } 108 +}; 109 + 7 110 chrome = { 8 111 runtime: { 9 112 connectCallbacks: [], 10 113 onConnectExternal: { 11 114 addListener: function(callback) { 12 115 if (!callback) { 13 116 return; ................................................................................ 22 125 return; 23 126 } 24 127 25 128 chrome.runtime.connectCallbacks.splice(idx, 1); 26 129 } 27 130 } 28 131 } 29 -} 132 +}; 133 + 134 +chrome.runtime.externalConnect = function(data) { 135 + chrome.runtime.connectCallbacks.forEach(function(callback) { 136 + callback(data); 137 + }); 138 +};