Skip to content

Commit a623755

Browse files
committed
wip
1 parent ddf637f commit a623755

3 files changed

Lines changed: 45 additions & 9 deletions

File tree

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<!-- Copyright (C) Microsoft Corporation. All rights reserved. -->
22
<!DOCTYPE html>
33
<html>
4-
<head>
5-
<meta charset="utf-8" />
6-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src 'self' https: data: vscode-remote:; media-src 'none'; child-src 'self'; object-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' https:; font-src 'self' https:;">
7-
</head>
8-
<body class="vs-dark" aria-label="">
9-
</body>
4+
<head>
5+
<meta charset="utf-8" />
6+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src 'self' https: data: vscode-remote:; media-src 'none'; child-src 'self'; object-src 'self'; script-src 'self' data:; style-src 'self' 'unsafe-inline'; connect-src 'self' https:; font-src 'self' https:;">
7+
</head>
8+
<body class="vs-dark" aria-label="">
9+
</body>
1010

11-
<!-- Startup via workbench.js -->
12-
<script src="workbench.js"></script>
13-
</html>
11+
<!-- Startup via workbench.js -->
12+
<script src="workbench.js"></script>
13+
</html>

src/vs/workbench/contrib/workerExtensions/worker/extensionHostWorker.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { IRequestHandler } from 'vs/base/common/worker/simpleWorker';
77
import { IMessagePassingProtocol } from 'vs/base/parts/ipc/common/ipc';
88
import { VSBuffer } from 'vs/base/common/buffer';
99
import { Emitter } from 'vs/base/common/event';
10+
import { importWrappedScript } from 'vs/workbench/contrib/workerExtensions/worker/extensionLoader';
1011

1112
class ExtensionWorker implements IRequestHandler {
1213

@@ -42,5 +43,16 @@ export function create(postMessage: (message: any, transfer?: Transferable[]) =>
4243
const res = new ExtensionWorker(postMessage);
4344
res.protocol.onMessage(buff => console.log(buff.toString()));
4445
res.protocol.send(VSBuffer.fromString('HELLO from WORKER'));
46+
47+
const source = `Object.defineProperty(exports, "__esModule", { value: true });
48+
const model = require('./model');
49+
const vscode = require('vscode');
50+
function activate() {
51+
\tconsole.log('HELLO');
52+
}
53+
exports.activate = activate;`;
54+
55+
importWrappedScript(source, 'somepath');
56+
4557
return res;
4658
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
7+
self['extensions'] = {};
8+
function wrap(name: string, script: string) {
9+
//https://github.com/nodejs/node/blob/master/lib/internal/modules/cjs/loader.js#L125
10+
return `self['extensions']['${name}']= (function (exports, require) { ${script}\n});`;
11+
}
12+
13+
export function importWrappedScript(scriptSrc: string, scriptPath: string) {
14+
15+
importScripts(`data:text/javascript;charset=utf-8,${encodeURIComponent(wrap(scriptPath, scriptSrc))}`);
16+
17+
// const fn = new Function('exports', 'require', 'module', scriptSrc);
18+
// const exports = Object.create(null);
19+
// const thisRequire = function (path: string) {
20+
// console.log(path);
21+
// };
22+
// fn(exports, thisRequire, undefined);
23+
// console.log(exports);
24+
}

0 commit comments

Comments
 (0)