Skip to content

Commit fb50f90

Browse files
committed
Merge branch 'main' into bigint_on
2 parents b9c8be1 + 1171ada commit fb50f90

File tree

114 files changed

+297
-344
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+297
-344
lines changed

ChangeLog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ See docs/process.md for more on how version tagging works.
2323
- The file system was updated to independently track atime, mtime and ctime
2424
instead of using the same time for all three. (#22998)
2525
- The minimum supported chrome version was bumped from 32 to 33. (#23077)
26+
- Emscripten-generated code will now use async/await internally when loading
27+
the Wasm module. This will be lowered away by babel when targeting older
28+
browsers. (#23068)
29+
- Due to the discontinued support for invalid specializations of
30+
- `std::basic_string` (https://github.com/llvm/llvm-project/pull/72694), the
31+
support for `std::basic_string<unsigned char>` was removed from embind.
32+
(#23070)
2633

2734
3.1.73 - 11/28/24
2835
-----------------

emcc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ def get_clang_flags(user_args):
391391
# Bulk memory may be enabled via threads or directly via -s.
392392
if not settings.BULK_MEMORY:
393393
flags.append('-mno-bulk-memory')
394+
flags.append('-mno-bulk-memory-opt')
394395
if '-mnontrapping-fptoint' not in user_args and '-mno-nontrapping-fptoint' not in user_args:
395396
flags.append('-mno-nontrapping-fptoint')
396397

site/source/docs/porting/files/Synchronous-Virtual-XHR-Backed-File-System-Usage.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ Instructions
6363

6464
.. include:: ../../../../../test/test_browser.py
6565
:literal:
66-
:start-after: create_file('main.html',
67-
:end-before: """ % (worker_filename, self.port))
66+
:start-after: create_file('main.html', '''
67+
:end-before: ''' % self.PORT)
6868
:code: html

src/embind/embind.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,7 @@ var LibraryEmbind = {
496496
name = readLatin1String(name);
497497
var stdStringIsUTF8
498498
#if EMBIND_STD_STRING_IS_UTF8
499-
//process only std::string bindings with UTF8 support, in contrast to e.g. std::basic_string<unsigned char>
500-
= (name === "std::string");
499+
= true;
501500
#else
502501
= false;
503502
#endif

src/library_webgl.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,6 @@ for (/**@suppress{duplicate}*/var i = 0; i <= {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
940940
gl.uniform1i(gl.getUniformLocation(blitProgram, "sampler"), 0);
941941
gl.useProgram(null);
942942

943-
context.defaultVao = undefined;
944943
if (gl.createVertexArray) {
945944
context.defaultVao = gl.createVertexArray();
946945
gl.bindVertexArray(context.defaultVao);
@@ -1020,17 +1019,13 @@ for (/**@suppress{duplicate}*/var i = 0; i <= {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
10201019
gl.drawArrays(5/*GL_TRIANGLE_STRIP*/, 0, 4);
10211020
}
10221021

1023-
#if !OFFSCREEN_FRAMEBUFFER_FORBID_VAO_PATH
10241022
if (context.defaultVao) {
10251023
// WebGL 2 or OES_vertex_array_object
10261024
var prevVAO = gl.getParameter(0x85B5 /*GL_VERTEX_ARRAY_BINDING*/);
10271025
gl.bindVertexArray(context.defaultVao);
10281026
draw();
10291027
gl.bindVertexArray(prevVAO);
1030-
}
1031-
else
1032-
#endif
1033-
{
1028+
} else {
10341029
var prevVertexAttribPointer = {
10351030
buffer: gl.getVertexAttrib(context.blitPosLoc, 0x889F /*GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING*/),
10361031
size: gl.getVertexAttrib(context.blitPosLoc, 0x8623 /*GL_VERTEX_ATTRIB_ARRAY_SIZE*/),

src/preamble.js

Lines changed: 85 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ function getBinarySync(file) {
647647
#endif
648648
}
649649

650-
function getBinaryPromise(binaryFile) {
650+
async function getWasmBinary(binaryFile) {
651651
#if !SINGLE_FILE
652652
// If we don't have the binary yet, load it asynchronously using readAsync.
653653
if (!wasmBinary
@@ -656,16 +656,17 @@ function getBinaryPromise(binaryFile) {
656656
#endif
657657
) {
658658
// Fetch the binary using readAsync
659-
return readAsync(binaryFile).then(
660-
(response) => new Uint8Array(/** @type{!ArrayBuffer} */(response)),
661-
// Fall back to getBinarySync if readAsync fails
662-
() => getBinarySync(binaryFile)
663-
);
659+
try {
660+
var response = await readAsync(binaryFile);
661+
return new Uint8Array(response);
662+
} catch {
663+
// Fall back to getBinarySync below;
664+
}
664665
}
665666
#endif
666667

667668
// Otherwise, getBinarySync should be able to get it synchronously
668-
return Promise.resolve(getBinarySync(binaryFile));
669+
return getBinarySync(binaryFile);
669670
}
670671

671672
#if LOAD_SOURCE_MAP
@@ -773,56 +774,47 @@ function resetPrototype(constructor, attrs) {
773774
#endif
774775

775776
#if WASM_ASYNC_COMPILATION
776-
function instantiateArrayBuffer(binaryFile, imports) {
777+
async function instantiateArrayBuffer(binaryFile, imports) {
778+
try {
779+
var binary = await getWasmBinary(binaryFile);
780+
var instance = await WebAssembly.instantiate(binary, imports);
777781
#if USE_OFFSET_CONVERTER
778-
var savedBinary;
782+
// wasmOffsetConverter needs to be assigned before calling resolve.
783+
// See comments below in instantiateAsync.
784+
wasmOffsetConverter = new WasmOffsetConverter(binary, instance.module);
779785
#endif
780-
return new Promise((resolve, reject) => {
781-
getBinaryPromise(binaryFile).then((binary) => {
782-
#if USE_OFFSET_CONVERTER
783-
savedBinary = binary;
784-
#endif
785-
return WebAssembly.instantiate(binary, imports);
786-
#if USE_OFFSET_CONVERTER
787-
}).then((instance) => {
788-
// wasmOffsetConverter needs to be assigned before calling resolve.
789-
// See comments below in instantiateAsync.
790-
wasmOffsetConverter = new WasmOffsetConverter(savedBinary, instance.module);
791-
return instance;
792-
#endif
793-
}).then(resolve, (reason) => {
794-
err(`failed to asynchronously prepare wasm: ${reason}`);
795-
786+
return instance;
787+
} catch (reason) {
788+
err(`failed to asynchronously prepare wasm: ${reason}`);
796789
#if WASM == 2
797790
#if ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL
798-
if (typeof location != 'undefined') {
799-
#endif
800-
// WebAssembly compilation failed, try running the JS fallback instead.
801-
var search = location.search;
802-
if (search.indexOf('_rwasm=0') < 0) {
803-
location.href += (search ? search + '&' : '?') + '_rwasm=0';
804-
// Return here to avoid calling abort() below. The application
805-
// still has a chance to start successfully do we don't want to
806-
// trigger onAbort or onExit handlers.
807-
return;
808-
}
809-
#if ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL
791+
if (typeof location != 'undefined') {
792+
#endif
793+
// WebAssembly compilation failed, try running the JS fallback instead.
794+
var search = location.search;
795+
if (search.indexOf('_rwasm=0') < 0) {
796+
// Reload the page with the `_rwasm=0` argument
797+
location.href += (search ? search + '&' : '?') + '_rwasm=0';
798+
// Return a promise that never resolves. We don't want to
799+
// call abort below, or return an error to our caller.
800+
return new Promise(() => {});
810801
}
802+
#if ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL
803+
}
811804
#endif
812805
#endif // WASM == 2
813806

814807
#if ASSERTIONS
815-
// Warn on some common problems.
816-
if (isFileURI(wasmBinaryFile)) {
817-
err(`warning: Loading from a file URI (${wasmBinaryFile}) is not supported in most browsers. See https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing`);
818-
}
808+
// Warn on some common problems.
809+
if (isFileURI(wasmBinaryFile)) {
810+
err(`warning: Loading from a file URI (${wasmBinaryFile}) is not supported in most browsers. See https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing`);
811+
}
819812
#endif
820-
abort(reason);
821-
});
822-
});
813+
abort(reason);
814+
}
823815
}
824816

825-
function instantiateAsync(binary, binaryFile, imports) {
817+
async function instantiateAsync(binary, binaryFile, imports) {
826818
#if !SINGLE_FILE
827819
if (!binary &&
828820
typeof WebAssembly.instantiateStreaming == 'function' &&
@@ -841,56 +833,41 @@ function instantiateAsync(binary, binaryFile, imports) {
841833
!ENVIRONMENT_IS_NODE &&
842834
#endif
843835
typeof fetch == 'function') {
844-
return new Promise((resolve) => {
845-
fetch(binaryFile, {{{ makeModuleReceiveExpr('fetchSettings', "{ credentials: 'same-origin' }") }}}).then((response) => {
846-
// Suppress closure warning here since the upstream definition for
847-
// instantiateStreaming only allows Promise<Repsponse> rather than
848-
// an actual Response.
849-
// TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure is fixed.
850-
/** @suppress {checkTypes} */
851-
var result = WebAssembly.instantiateStreaming(response, imports);
852-
836+
try {
837+
var response = fetch(binaryFile, {{{ makeModuleReceiveExpr('fetchSettings', "{ credentials: 'same-origin' }") }}});
853838
#if USE_OFFSET_CONVERTER
854-
// We need the wasm binary for the offset converter. Clone the response
855-
// in order to get its arrayBuffer (cloning should be more efficient
856-
// than doing another entire request).
857-
// (We must clone the response now in order to use it later, as if we
858-
// try to clone it asynchronously lower down then we will get a
859-
// "response was already consumed" error.)
860-
var clonedResponsePromise = response.clone().arrayBuffer();
861-
#endif
862-
863-
result.then(
839+
// We need the wasm binary for the offset converter. Clone the response
840+
// in order to get its arrayBuffer (cloning should be more efficient
841+
// than doing another entire request).
842+
// (We must clone the response now in order to use it later, as if we
843+
// try to clone it asynchronously lower down then we will get a
844+
// "response was already consumed" error.)
845+
var clonedResponse = (await response).clone();
846+
#endif
847+
var instantiationResult = await WebAssembly.instantiateStreaming(response, imports);
864848
#if USE_OFFSET_CONVERTER
865-
(instantiationResult) => {
866-
// When using the offset converter, we must interpose here. First,
867-
// the instantiation result must arrive (if it fails, the error
868-
// handling later down will handle it). Once it arrives, we can
869-
// initialize the offset converter. And only then is it valid to
870-
// call receiveInstantiationResult, as that function will use the
871-
// offset converter (in the case of pthreads, it will create the
872-
// pthreads and send them the offsets along with the wasm instance).
873-
874-
clonedResponsePromise.then((arrayBufferResult) => {
875-
wasmOffsetConverter = new WasmOffsetConverter(new Uint8Array(arrayBufferResult), instantiationResult.module);
876-
resolve(instantiationResult);
877-
},
878-
(reason) => err(`failed to initialize offset-converter: ${reason}`)
879-
);
880-
},
881-
#else
882-
resolve,
883-
#endif
884-
(reason) => {
885-
// We expect the most common failure cause to be a bad MIME type for the binary,
886-
// in which case falling back to ArrayBuffer instantiation should work.
887-
err(`wasm streaming compile failed: ${reason}`);
888-
err('falling back to ArrayBuffer instantiation');
889-
return resolve(instantiateArrayBuffer(binaryFile, imports));
890-
}
891-
);
892-
});
893-
});
849+
// When using the offset converter, we must interpose here. First,
850+
// the instantiation result must arrive (if it fails, the error
851+
// handling later down will handle it). Once it arrives, we can
852+
// initialize the offset converter. And only then is it valid to
853+
// call receiveInstantiationResult, as that function will use the
854+
// offset converter (in the case of pthreads, it will create the
855+
// pthreads and send them the offsets along with the wasm instance).
856+
var arrayBufferResult = await clonedResponse.arrayBuffer();
857+
try {
858+
wasmOffsetConverter = new WasmOffsetConverter(new Uint8Array(arrayBufferResult), instantiationResult.module);
859+
} catch (reason) {
860+
err(`failed to initialize offset-converter: ${reason}`);
861+
}
862+
#endif
863+
return instantiationResult;
864+
} catch (reason) {
865+
// We expect the most common failure cause to be a bad MIME type for the binary,
866+
// in which case falling back to ArrayBuffer instantiation should work.
867+
err(`wasm streaming compile failed: ${reason}`);
868+
err('falling back to ArrayBuffer instantiation');
869+
// fall back of instantiateArrayBuffer below
870+
};
894871
}
895872
#endif
896873
return instantiateArrayBuffer(binaryFile, imports);
@@ -936,7 +913,7 @@ function getWasmImports() {
936913

937914
// Create the wasm instance.
938915
// Receives the wasm imports, returns the exports.
939-
function createWasm() {
916+
{{{ asyncIf(WASM_ASYNC_COMPILATION) }}} function createWasm() {
940917
// Load the wasm module and create an instance of using native support in the JS engine.
941918
// handle a generated wasm instance, receiving its exports and
942919
// performing other necessary setup
@@ -1104,17 +1081,23 @@ function createWasm() {
11041081
#if RUNTIME_DEBUG
11051082
dbg('asynchronously preparing wasm');
11061083
#endif
1107-
instantiateAsync(wasmBinary, wasmBinaryFile, info).then(receiveInstantiationResult)
11081084
#if MODULARIZE
1109-
// If instantiation fails, reject the module ready promise.
1110-
.catch(readyPromiseReject)
1085+
try {
11111086
#endif
1112-
;
1087+
var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info);
1088+
receiveInstantiationResult(result);
11131089
#if LOAD_SOURCE_MAP
1114-
getSourceMapPromise().then(receiveSourceMapJSON);
1090+
receiveSourceMapJSON(await getSourceMapPromise());
11151091
#endif
1116-
return {}; // no exports yet; we'll fill them in later
1117-
#else
1092+
return result;
1093+
#if MODULARIZE
1094+
} catch (e) {
1095+
// If instantiation fails, reject the module ready promise.
1096+
readyPromiseReject(e);
1097+
return;
1098+
}
1099+
#endif
1100+
#else // WASM_ASYNC_COMPILATION
11181101
var result = instantiateSync(wasmBinaryFile, info);
11191102
#if PTHREADS || MAIN_MODULE
11201103
return receiveInstance(result[0], result[1]);
@@ -1124,7 +1107,7 @@ function createWasm() {
11241107
// When the regression is fixed, we can remove this if/else.
11251108
return receiveInstance(result[0]);
11261109
#endif
1127-
#endif
1110+
#endif // WASM_ASYNC_COMPILATION
11281111
}
11291112

11301113
#if !WASM_BIGINT

src/settings.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,14 +2186,6 @@ var LEGACY_RUNTIME = false;
21862186
// [link]
21872187
var SIGNATURE_CONVERSIONS = [];
21882188

2189-
//===========================================
2190-
// Internal, used for testing only, from here
2191-
//===========================================
2192-
2193-
// Internal (testing only): Disables the blitOffscreenFramebuffer VAO path.
2194-
// [link]
2195-
var OFFSCREEN_FRAMEBUFFER_FORBID_VAO_PATH = false;
2196-
21972189
// For renamed settings the format is:
21982190
// [OLD_NAME, NEW_NAME]
21992191
// For removed settings (which now effectively have a fixed value and can no

system/lib/embind/bind.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ EMSCRIPTEN_BINDINGS(builtin) {
149149
register_float<double>("double");
150150

151151
_embind_register_std_string(TypeID<std::string>::get(), "std::string");
152-
_embind_register_std_string(
153-
TypeID<std::basic_string<unsigned char>>::get(), "std::basic_string<unsigned char>");
154152
_embind_register_std_wstring(TypeID<std::wstring>::get(), sizeof(wchar_t), "std::wstring");
155153
_embind_register_std_wstring(TypeID<std::u16string>::get(), sizeof(char16_t), "std::u16string");
156154
_embind_register_std_wstring(TypeID<std::u32string>::get(), sizeof(char32_t), "std::u32string");

0 commit comments

Comments
 (0)