This commit is contained in:
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
@@ -0,0 +1,123 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Security-Policy" content="
|
||||
default-src 'none';
|
||||
child-src 'self' data: blob:;
|
||||
script-src 'self' 'unsafe-eval' 'sha256-75NYUUvf+5++1WbfCZOV3PSWxBhONpaxwx+mkOFRv/Y=' https:;
|
||||
connect-src 'self' https: wss: http://localhost:* http://127.0.0.1:* ws://localhost:* ws://127.0.0.1:*;"/>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
(function () {
|
||||
const searchParams = new URL(document.location.href).searchParams;
|
||||
const vscodeWebWorkerExtHostId = searchParams.get('vscodeWebWorkerExtHostId') || '';
|
||||
const name = searchParams.get('debugged') ? 'DebugWorkerExtensionHost' : 'WorkerExtensionHost';
|
||||
const parentOrigin = searchParams.get('parentOrigin') || window.origin;
|
||||
const salt = searchParams.get('salt');
|
||||
|
||||
(async function () {
|
||||
const hostnameValidationMarker = 'v--';
|
||||
const hostname = location.hostname;
|
||||
if (!hostname.startsWith(hostnameValidationMarker)) {
|
||||
// validation not requested
|
||||
return start();
|
||||
}
|
||||
if (!crypto.subtle) {
|
||||
// cannot validate, not running in a secure context
|
||||
return sendError(new Error(`Cannot validate in current context!`));
|
||||
}
|
||||
|
||||
// Here the `parentOriginHash()` function from `src/vs/base/browser/iframe.ts` is inlined
|
||||
// compute a sha-256 composed of `parentOrigin` and `salt` converted to base 32
|
||||
/** @type {string} */
|
||||
let parentOriginHash;
|
||||
try {
|
||||
const strData = JSON.stringify({ parentOrigin, salt });
|
||||
const encoder = new TextEncoder();
|
||||
const arrData = encoder.encode(strData);
|
||||
const hash = await crypto.subtle.digest('sha-256', arrData);
|
||||
const hashArray = Array.from(new Uint8Array(hash));
|
||||
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
||||
// sha256 has 256 bits, so we need at most ceil(lg(2^256-1)/lg(32)) = 52 chars to represent it in base 32
|
||||
parentOriginHash = BigInt(`0x${hashHex}`).toString(32).padStart(52, '0');
|
||||
} catch (err) {
|
||||
return sendError(err instanceof Error ? err : new Error(String(err)));
|
||||
}
|
||||
|
||||
const requiredSubdomain = `${hostnameValidationMarker}${parentOriginHash}.`;
|
||||
if (hostname.substring(0, requiredSubdomain.length) === requiredSubdomain) {
|
||||
// validation succeeded!
|
||||
return start();
|
||||
}
|
||||
|
||||
return sendError(new Error(`Expected '${requiredSubdomain}' as subdomain!`));
|
||||
})();
|
||||
|
||||
function sendError(error) {
|
||||
window.parent.postMessage({
|
||||
vscodeWebWorkerExtHostId,
|
||||
error: {
|
||||
name: error ? error.name : '',
|
||||
message: error ? error.message : '',
|
||||
stack: error ? error.stack : []
|
||||
}
|
||||
}, '*');
|
||||
}
|
||||
|
||||
function start() {
|
||||
try {
|
||||
let workerUrl = '../../../../base/worker/workerMain.js';
|
||||
if (globalThis.crossOriginIsolated) {
|
||||
workerUrl += '?vscode-coi=2'; // COEP
|
||||
}
|
||||
|
||||
const worker = new Worker(workerUrl, { name });
|
||||
worker.postMessage('vs/workbench/api/worker/extensionHostWorker');
|
||||
const nestedWorkers = new Map();
|
||||
|
||||
worker.onmessage = (event) => {
|
||||
const { data } = event;
|
||||
|
||||
if (data?.type === '_newWorker') {
|
||||
const { id, port, url, options } = data;
|
||||
const newWorker = new Worker(url, options);
|
||||
newWorker.postMessage(port, [port]);
|
||||
newWorker.onerror = console.error.bind(console);
|
||||
nestedWorkers.set(id, newWorker);
|
||||
|
||||
} else if (data?.type === '_terminateWorker') {
|
||||
const { id } = data;
|
||||
if (nestedWorkers.has(id)) {
|
||||
nestedWorkers.get(id).terminate();
|
||||
nestedWorkers.delete(id);
|
||||
}
|
||||
} else {
|
||||
worker.onerror = console.error.bind(console);
|
||||
window.parent.postMessage({
|
||||
vscodeWebWorkerExtHostId,
|
||||
data
|
||||
}, parentOrigin, [data]);
|
||||
}
|
||||
};
|
||||
|
||||
worker.onerror = (event) => {
|
||||
console.error(event.message, event.error);
|
||||
sendError(event.error);
|
||||
};
|
||||
|
||||
self.onmessage = (event) => {
|
||||
if (event.origin !== parentOrigin) {
|
||||
return;
|
||||
}
|
||||
worker.postMessage(event.data, event.ports);
|
||||
};
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
sendError(err);
|
||||
}
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,5 @@
|
||||
/*!--------------------------------------------------------
|
||||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/(function(){var y=["vs/workbench/services/languageDetection/browser/languageDetectionSimpleWorker","require","exports","vs/base/common/stopwatch","vs/editor/common/services/editorSimpleWorker"],m=function(e){for(var n=[],i=0,u=e.length;i<u;i++)n[i]=y[e[i]];return n},O=this&&this.__createBinding||(Object.create?function(e,n,i,u){u===void 0&&(u=i);var d=Object.getOwnPropertyDescriptor(n,i);(!d||("get"in d?!n.__esModule:d.writable||d.configurable))&&(d={enumerable:!0,get:function(){return n[i]}}),Object.defineProperty(e,u,d)}:function(e,n,i,u){u===void 0&&(u=i),e[u]=n[i]}),M=this&&this.__setModuleDefault||(Object.create?function(e,n){Object.defineProperty(e,"default",{enumerable:!0,value:n})}:function(e,n){e.default=n}),b=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var n={};if(e!=null)for(var i in e)i!=="default"&&Object.prototype.hasOwnProperty.call(e,i)&&O(n,e,i);return M(n,e),n};define(y[0],m([1,2,3,4]),function(e,n,i,u){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.LanguageDetectionSimpleWorker=void 0,n.create=d;function d(_){return new f(_,null)}class f extends u.EditorSimpleWorker{constructor(){super(...arguments),this.v=!1,this.y=!1,this.z=new Map}static{this.q=.2}static{this.r=.05}static{this.s=.025}static{this.t=.5}async detectLanguage(c,s,t,a){const o=[],r=[],w=new i.$he,g=this.A(c);if(!g)return;const v=async()=>{for await(const h of this.F(g)){this.z.has(h.languageId)||this.z.set(h.languageId,await this.d.fhr("getLanguageId",[h.languageId]));const l=this.z.get(h.languageId);l&&(!a?.length||a.includes(l))&&(o.push(l),r.push(h.confidence))}if(w.stop(),o.length)return this.d.fhr("sendTelemetryEvent",[o,r,w.elapsed()]),o[0]},p=async()=>this.C(g,s??{},a);if(t){const h=await p();if(h)return h;const l=await v();if(l)return l}else{const h=await v();if(h)return h;const l=await p();if(l)return l}}A(c){const s=this.j(c);if(!s)return;const t=s.positionAt(1e4);return s.getValueInRange({startColumn:1,startLineNumber:1,endColumn:t.column,endLineNumber:t.lineNumber})}async B(){if(this.v)return;if(this.u)return this.u;const c=await this.d.fhr("getRegexpModelUri",[]);try{return this.u=await new Promise((s,t)=>{e([c],s,t)}).then(b),this.u}catch{this.v=!0;return}}async C(c,s,t){const a=await this.B();if(!a)return;if(t?.length)for(const r of Object.keys(s))t.includes(r)?s[r]=1:s[r]=0;return a.detect(c,s,t)}async D(){if(this.w)return this.w;const c=await this.d.fhr("getIndexJsUri",[]),{ModelOperations:s}=await new Promise((t,a)=>{e([c],t,a)}).then(b);return this.w=new s({modelJsonLoaderFunc:async()=>{const t=await fetch(await this.d.fhr("getModelJsonUri",[]));try{return await t.json()}catch{const o="Failed to parse model JSON.";throw new Error(o)}},weightsLoaderFunc:async()=>await(await fetch(await this.d.fhr("getWeightsUri",[]))).arrayBuffer()}),this.w}E(c){switch(c.languageId){case"js":case"html":case"json":case"ts":case"css":case"py":case"xml":case"php":c.confidence+=f.r;break;case"cpp":case"sh":case"java":case"cs":case"c":c.confidence+=f.s;break;case"bat":case"ini":case"makefile":case"sql":case"csv":case"toml":c.confidence-=f.t;break;default:break}return c}async*F(c){if(this.y)return;let s;try{s=await this.D()}catch(r){console.log(r),this.y=!0;return}let t;try{t=await s.runModel(c)}catch(r){console.warn(r)}if(!t||t.length===0||t[0].confidence<f.q)return;const a=this.E(t[0]);if(a.confidence<f.q)return;const o=[a];for(let r of t){if(r===a)continue;if(r=this.E(r),o[o.length-1].confidence-r.confidence>=f.q){for(;o.length;)yield o.shift();if(r.confidence>f.q){o.push(r);continue}return}else{if(r.confidence>f.q){o.push(r);continue}return}}}}n.LanguageDetectionSimpleWorker=f})}).call(this);
|
||||
|
||||
//# sourceMappingURL=https://main.vscode-cdn.net/sourcemaps/ea1445cc7016315d0f5728f8e8b12a45dc0a7286/core/vs/workbench/services/languageDetection/browser/languageDetectionSimpleWorker.js.map
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"type": "typescript",
|
||||
|
||||
"sources": [
|
||||
"examples/company.ts",
|
||||
"examples/conway.ts",
|
||||
"examples/employee.ts",
|
||||
"examples/large.ts",
|
||||
"examples/small.ts"
|
||||
]
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
<?xml>
|
||||
|
||||
</xml>
|
Reference in New Issue
Block a user