emsdk-env 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: emsdk-env
3
- * version: 0.9.0
3
+ * version: 0.10.0
4
4
  * description: Emscripten environment builder
5
5
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
6
  * license: MIT
7
7
  * repository.url: https://github.com/kekyo/emsdk-env
8
- * git.commit.hash: 73d7e217903f020ef22daa9289362dcd19bddac1
8
+ * git.commit.hash: 7ee173408d930a3cc7444806156538a24a617b55
9
9
  */
10
10
 
11
11
  "use strict";
@@ -889,9 +889,7 @@ const buildGeneratedLoaderContent = (generatedLoaderFile, targets) => {
889
889
  options?: TargetWasmLoadOptions
890
890
  ): Promise<WasmInstance<T>> => {
891
891
  const source = options?.url ?? new URL(${specifier}, import.meta.url);
892
- return await loadWasm<T>(source, {
893
- imports: options?.imports,
894
- });
892
+ return await loadWasm<T>(source, createWasmLoadOptions(options?.imports));
895
893
  };`;
896
894
  }).join("\n\n");
897
895
  return `// Generated by emsdk-env. DO NOT EDIT.
@@ -911,6 +909,13 @@ export interface TargetWasmLoadOptions extends WasmLoadOptions {
911
909
  readonly url?: string | URL;
912
910
  }
913
911
 
912
+ const isResponse = (value: WasmSource): value is Response =>
913
+ typeof Response !== 'undefined' && value instanceof Response;
914
+
915
+ const createWasmLoadOptions = (
916
+ imports: WebAssembly.Imports | undefined
917
+ ): WasmLoadOptions | undefined => (imports ? { imports } : undefined);
918
+
914
919
  export interface WasmInstance<T extends object> {
915
920
  readonly exports: T;
916
921
  readonly memory: WebAssembly.Memory;
@@ -923,7 +928,7 @@ export interface WasmInstance<T extends object> {
923
928
  }
924
929
 
925
930
  const resolveWasmBytes = async (source: WasmSource): Promise<ArrayBuffer> => {
926
- if (typeof Response !== 'undefined' && source instanceof Response) {
931
+ if (isResponse(source)) {
927
932
  return await source.arrayBuffer();
928
933
  }
929
934
  if (source instanceof URL || typeof source === 'string') {
@@ -933,6 +938,9 @@ const resolveWasmBytes = async (source: WasmSource): Promise<ArrayBuffer> => {
933
938
  }
934
939
  return await response.arrayBuffer();
935
940
  }
941
+ if (source instanceof ArrayBuffer) {
942
+ return source;
943
+ }
936
944
  if (ArrayBuffer.isView(source)) {
937
945
  const view = new Uint8Array(
938
946
  source.buffer,
@@ -941,7 +949,7 @@ const resolveWasmBytes = async (source: WasmSource): Promise<ArrayBuffer> => {
941
949
  );
942
950
  return view.slice().buffer;
943
951
  }
944
- return source;
952
+ throw new TypeError('Unsupported wasm source.');
945
953
  };
946
954
 
947
955
  const getImportValue = (
@@ -1678,4 +1686,4 @@ const buildWasm = async (options) => {
1678
1686
  exports.buildWasm = buildWasm;
1679
1687
  exports.createConsoleLogger = createConsoleLogger;
1680
1688
  exports.prepareEmsdk = prepareEmsdk;
1681
- //# sourceMappingURL=build-CgmcFNSR.cjs.map
1689
+ //# sourceMappingURL=build-BGtsNe6D.cjs.map