Browse Source

Avoid referencing WASM types from blazor.server.js (#28944)

Pranav K 5 years ago
parent
commit
121939fda8

File diff suppressed because it is too large
+ 0 - 0
src/Components/Web.JS/dist/Release/blazor.server.js


+ 3 - 0
src/Components/Web.JS/src/Boot.Server.ts

@@ -13,6 +13,7 @@ import { resolveOptions, CircuitStartOptions } from './Platform/Circuits/Circuit
 import { DefaultReconnectionHandler } from './Platform/Circuits/DefaultReconnectionHandler';
 import { attachRootComponentToLogicalElement } from './Rendering/Renderer';
 import { discoverComponents, ServerComponentDescriptor } from './Services/ComponentDescriptorDiscovery';
+import { InputFile } from './InputFile';
 
 let renderingFailed = false;
 let started = false;
@@ -27,6 +28,8 @@ async function boot(userOptions?: Partial<CircuitStartOptions>): Promise<void> {
   const options = resolveOptions(userOptions);
   const logger = new ConsoleLogger(options.logLevel);
   window['Blazor'].defaultReconnectionHandler = new DefaultReconnectionHandler(logger);
+  window['Blazor']._internal.InputFile = InputFile;
+
   options.reconnectionHandler = options.reconnectionHandler || window['Blazor'].defaultReconnectionHandler;
   logger.log(LogLevel.Information, 'Starting up blazor server-side application.');
 

+ 3 - 0
src/Components/Web.JS/src/Boot.WebAssembly.ts

@@ -13,6 +13,7 @@ import { Pointer } from './Platform/Platform';
 import { WebAssemblyStartOptions } from './Platform/WebAssemblyStartOptions';
 import { WebAssemblyComponentAttacher } from './Platform/WebAssemblyComponentAttacher';
 import { discoverComponents, WebAssemblyComponentDescriptor } from './Services/ComponentDescriptorDiscovery';
+import { WasmInputFile } from './WasmInputFile';
 
 let started = false;
 
@@ -34,6 +35,8 @@ async function boot(options?: Partial<WebAssemblyStartOptions>): Promise<void> {
     }
   });
 
+  window['Blazor']._internal.InputFile = WasmInputFile;
+
   // Configure JS interop
   window['Blazor']._internal.invokeJSFromDotNet = invokeJSFromDotNet;
 

+ 0 - 3
src/Components/Web.JS/src/GlobalExports.ts

@@ -1,8 +1,6 @@
 import { navigateTo, internalFunctions as navigationManagerInternalFunctions } from './Services/NavigationManager';
-import { attachRootComponentToElement } from './Rendering/Renderer';
 import { domFunctions } from './DomWrapper';
 import { Virtualize } from './Virtualize';
-import { InputFile } from './InputFile';
 
 // Make the following APIs available in global scope for invocation from JS
 window['Blazor'] = {
@@ -12,6 +10,5 @@ window['Blazor'] = {
     navigationManager: navigationManagerInternalFunctions,
     domWrapper: domFunctions,
     Virtualize,
-    InputFile,
   },
 };

+ 2 - 24
src/Components/Web.JS/src/InputFile.ts

@@ -1,12 +1,9 @@
-import { monoPlatform } from './Platform/Mono/MonoPlatform';
-import { System_Array } from './Platform/Platform';
 
 export const InputFile = {
   init,
   toImageFile,
   ensureArrayBufferReadyForSharedMemoryInterop,
   readFileData,
-  readFileDataSharedMemory,
 };
 
 interface BrowserFile {
@@ -19,7 +16,7 @@ interface BrowserFile {
   arrayBuffer: ArrayBuffer | undefined;
 }
 
-interface InputElement extends HTMLInputElement {
+export interface InputElement extends HTMLInputElement {
   _blazorInputFileNextFileId: number;
   _blazorFilesById: { [id: number]: BrowserFile };
 }
@@ -109,26 +106,7 @@ async function readFileData(elem: InputElement, fileId: number, startOffset: num
   return btoa(String.fromCharCode.apply(null, new Uint8Array(arrayBuffer, startOffset, count) as unknown as number[]));
 }
 
-function readFileDataSharedMemory(readRequest: any): number {
-  const inputFileElementReferenceId = monoPlatform.readStringField(readRequest, 0);
-  const inputFileElement = document.querySelector(`[_bl_${inputFileElementReferenceId}]`);
-  const fileId = monoPlatform.readInt32Field(readRequest, 8);
-  const sourceOffset = monoPlatform.readUint64Field(readRequest, 12);
-  const destination = monoPlatform.readInt32Field(readRequest, 24) as unknown as System_Array<number>;
-  const destinationOffset = monoPlatform.readInt32Field(readRequest, 32);
-  const maxBytes = monoPlatform.readInt32Field(readRequest, 36);
-
-  const sourceArrayBuffer = getFileById(inputFileElement as InputElement, fileId).arrayBuffer as ArrayBuffer;
-  const bytesToRead = Math.min(maxBytes, sourceArrayBuffer.byteLength - sourceOffset);
-  const sourceUint8Array = new Uint8Array(sourceArrayBuffer, sourceOffset, bytesToRead);
-
-  const destinationUint8Array = monoPlatform.toUint8Array(destination);
-  destinationUint8Array.set(sourceUint8Array, destinationOffset);
-
-  return bytesToRead;
-}
-
-function getFileById(elem: InputElement, fileId: number): BrowserFile {
+export function getFileById(elem: InputElement, fileId: number): BrowserFile {
   const file = elem._blazorFilesById[fileId];
 
   if (!file) {

+ 27 - 0
src/Components/Web.JS/src/WasmInputFile.ts

@@ -0,0 +1,27 @@
+import { monoPlatform } from './Platform/Mono/MonoPlatform';
+import { System_Array } from './Platform/Platform';
+import { InputFile, InputElement, getFileById } from './InputFile';
+
+export const WasmInputFile = {
+    ...InputFile,
+    readFileDataSharedMemory,
+};
+
+function readFileDataSharedMemory(readRequest: any): number {
+    const inputFileElementReferenceId = monoPlatform.readStringField(readRequest, 0);
+    const inputFileElement = document.querySelector(`[_bl_${inputFileElementReferenceId}]`);
+    const fileId = monoPlatform.readInt32Field(readRequest, 8);
+    const sourceOffset = monoPlatform.readUint64Field(readRequest, 12);
+    const destination = monoPlatform.readInt32Field(readRequest, 24) as unknown as System_Array<number>;
+    const destinationOffset = monoPlatform.readInt32Field(readRequest, 32);
+    const maxBytes = monoPlatform.readInt32Field(readRequest, 36);
+  
+    const sourceArrayBuffer = getFileById(inputFileElement as InputElement, fileId).arrayBuffer as ArrayBuffer;
+    const bytesToRead = Math.min(maxBytes, sourceArrayBuffer.byteLength - sourceOffset);
+    const sourceUint8Array = new Uint8Array(sourceArrayBuffer, sourceOffset, bytesToRead);
+  
+    const destinationUint8Array = monoPlatform.toUint8Array(destination);
+    destinationUint8Array.set(sourceUint8Array, destinationOffset);
+  
+    return bytesToRead;
+  }

Some files were not shown because too many files changed in this diff