Skip to content

Commit c8452c8

Browse files
authored
fix: disable http by default (#121)
1 parent 68eb86e commit c8452c8

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,16 @@ export function componentize(jsSource: string, opts: {
144144
engine?: string,
145145
preview2Adapter?: string,
146146
disableFeatures?: ('stdio' | 'random' | 'clocks')[],
147+
enableFeatures?: ('http')[],
147148
}): {
148149
component: Uint8Array,
149150
imports: string[]
150151
}
151152
```
152153

154+
`http` provides support for the host APIs used by the `fetch` method and is disabled by default,
155+
while this API is still being developed. Contributions very welcome to improve `fetch` support.
156+
153157
Converts a JS source into a component binary.
154158

155159
Imports provides the list of used guest imports only, while the StarlingMonkey engine may pull in additional

src/componentize.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export async function componentize(jsSource, witWorld, opts) {
8888
if (!disableFeatures.includes('clocks')) {
8989
features.push('clocks');
9090
}
91-
if (!disableFeatures.includes('http')) {
91+
if (enableFeatures.includes('http')) {
9292
features.push('http');
9393
}
9494

test/cases/http-request/test.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { ok } from 'node:assert';
22

3+
export const enableFeatures = ['http'];
4+
35
export function test (instance) {
46
ok(instance.getResult().includes('"content-type":"text/html'));
57
ok(instance.getResult().includes('WebAssembly'));

test/test.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,19 @@ suite('Bindings', () => {
141141

142142
const test = await import(`./cases/${name}/test.js`);
143143

144+
const enableFeatures = test.enableFeatures || [];
145+
const disableFeatures = test.disableFeatures || (isWasiTarget ? [] : ['random', 'clocks', 'http', 'stdio']);
146+
144147
let testArg;
145148
try {
146-
const { component, imports, exports } = await componentize(source, {
149+
const { component, imports } = await componentize(source, {
147150
sourceName: `${name}.js`,
148151
witWorld,
149152
witPath,
150153
worldName,
151-
disableFeatures: isWasiTarget ? [] : ['random', 'clocks', 'http', 'stdio']
154+
enableFeatures,
155+
disableFeatures
152156
});
153-
testArg = { imports, exports };
154-
155157
const map = {
156158
'wasi:cli-base/*': '@bytecodealliance/preview2-shim/cli-base#*',
157159
'wasi:clocks/*': '@bytecodealliance/preview2-shim/clocks#*',
@@ -170,13 +172,15 @@ suite('Bindings', () => {
170172
map[impt] = `../../cases/${name}/${importName}.js`;
171173
}
172174

173-
const { files } = await transpile(component, {
175+
const { files, imports: componentImports, exports: componentExports } = await transpile(component, {
174176
name,
175177
map,
176178
wasiShim: true,
177179
validLiftingOptimization: false,
178180
});
179181

182+
testArg = { imports, componentImports, componentExports };
183+
180184
await mkdir(new URL(`./output/${name}/interfaces`, import.meta.url), {
181185
recursive: true,
182186
});

0 commit comments

Comments
 (0)