Почему я не могу скомпилировать его в WASM на стороне клиента браузера, а не на сервере? Последняя ошибка:
Ошибка инициализации компилятора. Проверьте консоль для получения подробной информации.
Не удалось выполнить postMessage на «Worker»: для передачи SharedArrayBuffer требуется self.crossOriginIsolated.
редактор hello.js:
document.addEventListener('DOMContentLoaded', () => {
(async () => {
try { // Add a try block here
const { WebContainer } = await import('https://cdn.jsdelivr.net/npm/@webcontai ... t/index.js');
await WebContainer.boot();
const out = document.getElementById('out');
const codeEl = document.getElementById('code-editor');
const compiler = new Worker('./compile-worker.js', { type: 'module' });
const runner = new Worker('./run-worker.js', { type: 'module' });
compiler.onmessage = (e) => {
if (e.data.type === 'error') {
out.textContent += 'Compile error: ' + e.data.message + '\n';
return;
}
out.textContent += 'Running...\n';
runner.onmessage = (m) => {
const { stdout, stderr, exitCode } = m.data || {};
out.textContent += stdout + (stderr ? '\n[stderr]\n' + stderr : '') + '\n[exit ' + exitCode + ']';
};
runner.postMessage({ type: 'runWasi', wasm: e.data.wasm });
};
document.getElementById('run').onclick = () => {
out.textContent = 'Compiling...\n';
compiler.postMessage({ code: codeEl.value });
};
} catch (error) { // And a catch block here
console.error("Error during WebContainer initialization or setup:", error);
const out = document.getElementById('out');
if (out) {
out.textContent = "Error initializing compiler. Check console for details. " + error.message;
}
}
})();
});
compile-worker.js:
import { WebContainer } from '@webcontainer/api';
let wc;
self.onmessage = async (e) => {
const code = e.data?.code || '#include \nint main(){std::cout
Подробнее здесь: https://stackoverflow.com/questions/798 ... lient-side
Скомпилируйте C++ в WASM на стороне клиента браузера ⇐ Javascript
Форум по Javascript
-
Anonymous
1762902738
Anonymous
Почему я не могу скомпилировать его в WASM на стороне клиента браузера, а не на сервере? Последняя ошибка:
Ошибка инициализации компилятора. Проверьте консоль для получения подробной информации.
Не удалось выполнить postMessage на «Worker»: для передачи SharedArrayBuffer требуется self.crossOriginIsolated.
редактор hello.js:
document.addEventListener('DOMContentLoaded', () => {
(async () => {
try { // Add a try block here
const { WebContainer } = await import('https://cdn.jsdelivr.net/npm/@webcontainer/api/dist/index.js');
await WebContainer.boot();
const out = document.getElementById('out');
const codeEl = document.getElementById('code-editor');
const compiler = new Worker('./compile-worker.js', { type: 'module' });
const runner = new Worker('./run-worker.js', { type: 'module' });
compiler.onmessage = (e) => {
if (e.data.type === 'error') {
out.textContent += 'Compile error: ' + e.data.message + '\n';
return;
}
out.textContent += 'Running...\n';
runner.onmessage = (m) => {
const { stdout, stderr, exitCode } = m.data || {};
out.textContent += stdout + (stderr ? '\n[stderr]\n' + stderr : '') + '\n[exit ' + exitCode + ']';
};
runner.postMessage({ type: 'runWasi', wasm: e.data.wasm });
};
document.getElementById('run').onclick = () => {
out.textContent = 'Compiling...\n';
compiler.postMessage({ code: codeEl.value });
};
} catch (error) { // And a catch block here
console.error("Error during WebContainer initialization or setup:", error);
const out = document.getElementById('out');
if (out) {
out.textContent = "Error initializing compiler. Check console for details. " + error.message;
}
}
})();
});
compile-worker.js:
import { WebContainer } from '@webcontainer/api';
let wc;
self.onmessage = async (e) => {
const code = e.data?.code || '#include \nint main(){std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79817127/compile-c-to-wasm-in-browser-client-side[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия