Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/mono/wasm/build/WasmApp.Native.targets
Original file line numberDiff line numberDiff line change
Expand Up@@ -156,6 +156,8 @@
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == '' and '$(Configuration)' == 'Debug' and '$(WasmBuildingForNestedPublish)' != 'true'">false</WasmNativeStrip>
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == ''">true</WasmNativeStrip>
<WasmNativeDebugSymbols Condition="'$(WasmNativeDebugSymbols)' == ''">true</WasmNativeDebugSymbols>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == '' and '$(Configuration)' == 'Release'">SIMPLE_OPTIMIZATIONS</WasmMinifyJsLevel>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == ''">NONE</WasmMinifyJsLevel>
<WasmLinkIcalls Condition="'$(WasmLinkIcalls)' == ''">$(WasmBuildNative)</WasmLinkIcalls>

<_WasmICallTablePath>$(_WasmIntermediateOutputPath)icall-table.h</_WasmICallTablePath>
Expand DownExpand Up@@ -232,6 +234,9 @@
<_EmccLDFlags Include="@(_EmccCommonFlags)" />
<_EmccLDSFlags Include="-Wl,--allow-undefined" />
<_EmccLDSFlags Include="-s INITIAL_MEMORY=$(EmccInitialHeapSize)" />
<_EmccLDSFlags Condition="'$(WasmNativeStrip)' != 'false' and '$(WasmMinifyJsLevel)' != 'NONE'" Include="--closure 1" />
<_EmccLDSFlags Condition="'$(WasmNativeStrip)' != 'false' and '$(WasmMinifyJsLevel)' != 'NONE'" Include="--closure-args=--compilation_level=$(WasmMinifyJsLevel)" />


<!-- ILLinker should have removed unused imports, so error for Publish -->
<_EmccLDSFlags Include="-s ERROR_ON_UNDEFINED_SYMBOLS=0" Condition="'$(WasmBuildingForNestedPublish)' != 'true'" />
Expand Down
1 change: 1 addition & 0 deletions src/mono/wasm/build/WasmApp.targets
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,6 +24,7 @@
- $(WasmNativeDebugSymbols) - Build with native debug symbols, useful only with `$(RunAOTCompilation)`, or `$(WasmBuildNative)`
Defaults to true.
- $(WasmEmitSymbolMap) - Generates a `dotnet.js.symbols` file with a map of wasm function number to name.
- $(WasmMinifyJsLevel) - Use closure compiler to minify dotnet.js after linking. Default:`SIMPLE_OPTIMIZATIONS`. Other option is `NONE`.
- $(WasmDedup) - Whenever to dedup generic instances when using AOT. Defaults to true.

- $(WasmProfilers) - Profilers to use
Expand Down
5 changes: 5 additions & 0 deletions src/mono/wasm/runtime/es6/dotnet.es6.extpost.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
const ENVIRONMENT_IS_WEB = typeof window == "object";
const ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string";
const MONO = {}, BINDING = {}, INTERNAL = {}, IMPORTS = {};
var fetch = fetch || undefined; var require = require || undefined; var __dirname = __dirname || '';
__dotnet_runtime.__setEmscriptenEntrypoint(createDotnetRuntime);
const __initializeImportsAndExports = __dotnet_runtime.__initializeImportsAndExports;
const __requirePromise = ENVIRONMENT_IS_NODE ? import(/* webpackIgnore: true */'module').then(mod => mod.createRequire(import.meta.url)) : undefined;
const dotnet = __dotnet_runtime.moduleExports.dotnet;
const exit = __dotnet_runtime.moduleExports.exit;
export { dotnet, exit, INTERNAL };
32 changes: 16 additions & 16 deletions src/mono/wasm/runtime/es6/dotnet.es6.lib.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,16 +5,16 @@
"use strict";

#if USE_PTHREADS
const usePThreads = `true`;
const usePThreads = true;
const isPThread = `ENVIRONMENT_IS_PTHREAD`;
#else
const usePThreads = `false`;
const usePThreads = false;
const isPThread = `false`;
Comment thread
ilonatommy marked this conversation as resolved.
#endif

const DotnetSupportLib = {
$DOTNET: {},
// this line will be placed early on emscripten runtime creation, passing import and export objects into __dotnet_runtime IFFE
// this line will be placed early on emscripten runtime creation, passing import and export objects into __dotnet_runtime IIFE
// Emscripten uses require function for nodeJS even in ES6 module. We need https://nodejs.org/api/module.html#modulecreaterequirefilename
// We use dynamic import because there is no "module" module in the browser.
// This is async init of it, note it would become available only after first tick.
Expand All@@ -23,33 +23,33 @@ const DotnetSupportLib = {
// We also replace implementation of fetch
$DOTNET__postset: `
let __dotnet_replacement_PThread = ${usePThreads} ? {} : undefined;
if (${usePThreads}) {
__dotnet_replacement_PThread.loadWasmModuleToWorker = PThread.loadWasmModuleToWorker;
__dotnet_replacement_PThread.threadInitTLS = PThread.threadInitTLS;
__dotnet_replacement_PThread.allocateUnusedWorker = PThread.allocateUnusedWorker;
}
${usePThreads ? `
__dotnet_replacement_PThread.loadWasmModuleToWorker = PThread.loadWasmModuleToWorker;
__dotnet_replacement_PThread.threadInitTLS = PThread.threadInitTLS;
__dotnet_replacement_PThread.allocateUnusedWorker = PThread.allocateUnusedWorker;
` : ''}
let __dotnet_replacements = {scriptUrl: import.meta.url, fetch: globalThis.fetch, require, updateGlobalBufferAndViews, pthreadReplacements: __dotnet_replacement_PThread};
if (ENVIRONMENT_IS_NODE) {
__dotnet_replacements.requirePromise = import(/* webpackIgnore: true */'module').then(mod => mod.createRequire(import.meta.url));
__dotnet_replacements.requirePromise = __requirePromise;
}
let __dotnet_exportedAPI = __dotnet_runtime.__initializeImportsAndExports(
let __dotnet_exportedAPI = __initializeImportsAndExports(
{ isGlobal:false, isNode:ENVIRONMENT_IS_NODE, isWorker:ENVIRONMENT_IS_WORKER, isShell:ENVIRONMENT_IS_SHELL, isWeb:ENVIRONMENT_IS_WEB, isPThread:${isPThread}, quit_, ExitStatus, requirePromise:__dotnet_replacements.requirePromise },
{ mono:MONO, binding:BINDING, internal:INTERNAL, module:Module, marshaled_imports: IMPORTS },
__dotnet_replacements, __callbackAPI);
updateGlobalBufferAndViews = __dotnet_replacements.updateGlobalBufferAndViews;
var fetch = __dotnet_replacements.fetch;
fetch = __dotnet_replacements.fetch;
_scriptDir = __dirname = scriptDirectory = __dotnet_replacements.scriptDirectory;
if (ENVIRONMENT_IS_NODE) {
__dotnet_replacements.requirePromise.then(someRequire => {
require = someRequire;
});
}
var noExitRuntime = __dotnet_replacements.noExitRuntime;
if (${usePThreads}) {
PThread.loadWasmModuleToWorker = __dotnet_replacements.pthreadReplacements.loadWasmModuleToWorker;
PThread.threadInitTLS = __dotnet_replacements.pthreadReplacements.threadInitTLS;
PThread.allocateUnusedWorker = __dotnet_replacements.pthreadReplacements.allocateUnusedWorker;
}
${usePThreads ? `
PThread.loadWasmModuleToWorker = __dotnet_replacements.pthreadReplacements.loadWasmModuleToWorker;
PThread.threadInitTLS = __dotnet_replacements.pthreadReplacements.threadInitTLS;
PThread.allocateUnusedWorker = __dotnet_replacements.pthreadReplacements.allocateUnusedWorker;
` : ''}
`,
};

Expand Down
2 changes: 0 additions & 2 deletions src/mono/wasm/runtime/es6/dotnet.es6.pre.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
var require = require || undefined;
var __dirname = __dirname || '';
var __callbackAPI = { MONO, BINDING, INTERNAL, IMPORTS };
if (typeof createDotnetRuntime === "function") {
__callbackAPI.Module = Module = { ready: Module.ready };
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/runtime/exports.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,7 @@ function initializeImportsAndExports(
const module = exports.module as DotnetModule;
const globalThisAny = globalThis as any;

// we want to have same instance of MONO, BINDING and Module in dotnet iffe
// we want to have same instance of MONO, BINDING and Module in dotnet iife
set_imports_exports(imports, exports);
set_legacy_exports(exports);
init_polyfills(replacements);
Expand Down
4 changes: 2 additions & 2 deletions src/mono/wasm/runtime/logging.ts
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
//! Licensed to the .NET Foundation under one or more agreements.
//! The .NET Foundation licenses this file to you under the MIT license.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import BuildConfiguration from "consts:configuration";
import { INTERNAL, Module, runtimeHelpers } from "./imports";
Expand Down
4 changes: 0 additions & 4 deletions src/mono/wasm/runtime/run-outer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,10 +22,6 @@ export interface DotnetHostBuilder {
run(): Promise<number>
}

// these constants duplicate detection inside emscripten internals, but happen earlier
const ENVIRONMENT_IS_WEB = typeof window == "object";
const ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string";

class HostBuilder implements DotnetHostBuilder {
private instance?: RuntimeAPI;
private applicationArguments?: string[];
Expand Down
3 changes: 3 additions & 0 deletions src/mono/wasm/runtime/types/consts.d.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,3 +17,6 @@ declare module "consts:monoDiagnosticsMock" {
const constant: boolean;
export default constant;
}

declare const ENVIRONMENT_IS_NODE: boolean;
declare const ENVIRONMENT_IS_WEB: boolean;
6 changes: 5 additions & 1 deletion src/mono/wasm/wasm.proj
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,8 @@
<_EmccCompileRspPath>$(NativeBinDir)src\emcc-compile.rsp</_EmccCompileRspPath>
<_EmccLinkRspPath>$(NativeBinDir)src\emcc-link.rsp</_EmccLinkRspPath>
<WasmNativeStrip Condition="'$(ContinuousIntegrationBuild)' == 'true'">false</WasmNativeStrip>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == '' and '$(Configuration)' == 'Release'">SIMPLE_OPTIMIZATIONS</WasmMinifyJsLevel>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == ''">NONE</WasmMinifyJsLevel>
</PropertyGroup>

<Target Name="CheckEnv">
Expand DownExpand Up@@ -254,10 +256,12 @@
<PInvokeTableFile>$(ArtifactsObjDir)wasm/pinvoke-table.h</PInvokeTableFile>
<InterpToNativeTableFile>$(ArtifactsObjDir)wasm/wasm_m2n_invoke.g.h</InterpToNativeTableFile>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Debug'">-g -Os -s -DDEBUG=1 -DENABLE_AOT_PROFILER=1 -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Release'">-Oz -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Release'">-Oz -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>

<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Debug'" >$(CMakeConfigurationEmccFlags)</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Release'">-O2</CMakeConfigurationLinkFlags>

<CMakeConfigurationLinkFlags Condition="'$(WasmMinifyJsLevel)' != 'NONE'">$(CMakeConfigurationLinkFlags) --closure 1 --closure-args=--compilation_level=$(WasmMinifyJsLevel)</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags>$(CMakeConfigurationLinkFlags) -s EXPORT_ES6=1</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(MonoWasmThreads)' == 'true'">$(CMakeConfigurationLinkFlags) -Wno-pthreads-mem-growth</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags >$(CMakeConfigurationLinkFlags) --emit-symbol-map</CMakeConfigurationLinkFlags>
Expand Down
15 changes: 8 additions & 7 deletions src/native/libs/System.Native/pal_random.lib.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,11 +3,12 @@

const DotNetEntropyLib = {
$DOTNETENTROPY: {
// batchedQuotaMax is the max number of bytes as specified by the api spec.
// If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm.
// https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
batchedQuotaMax: 65536,
getBatchedRandomValues: function (buffer, bufferLength) {
// batchedQuotaMax is the max number of bytes as specified by the api spec.
// If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm.
// https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
const batchedQuotaMax = 65536;

// Chrome doesn't want SharedArrayBuffer to be passed to crypto APIs
const needTempBuf = typeof SharedArrayBuffer !== 'undefined' && Module.HEAPU8.buffer instanceof SharedArrayBuffer;
// if we need a temporary buffer, make one that is big enough and write into it from the beginning
Expand All@@ -16,14 +17,14 @@ const DotNetEntropyLib = {
const offset = needTempBuf ? 0 : buffer;
// for modern web browsers
// map the work array to the memory buffer passed with the length
for (let i = 0; i < bufferLength; i += this.batchedQuotaMax) {
const view = new Uint8Array(buf, offset + i, Math.min(bufferLength - i, this.batchedQuotaMax));
for (let i = 0; i < bufferLength; i += batchedQuotaMax) {
const view = new Uint8Array(buf, offset + i, Math.min(bufferLength - i, batchedQuotaMax));
crypto.getRandomValues(view)
}
if (needTempBuf) {
// copy data out of the temporary buffer into the wasm instance memory
const heapView = new Uint8Array(Module.HEAPU8.buffer, buffer, bufferLength);
heapView.set(new Uint8Array(buf));
heapView.set(new Uint8Array(buf));
}
}
},
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
[draft][browser] enable closure compiler for dotnet.js by pavelsavara · Pull Request #80178 · dotnet/runtime · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/mono/wasm/build/WasmApp.Native.targets
Original file line numberDiff line numberDiff line change
Expand Up@@ -156,6 +156,8 @@
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == '' and '$(Configuration)' == 'Debug' and '$(WasmBuildingForNestedPublish)' != 'true'">false</WasmNativeStrip>
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == ''">true</WasmNativeStrip>
<WasmNativeDebugSymbols Condition="'$(WasmNativeDebugSymbols)' == ''">true</WasmNativeDebugSymbols>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == '' and '$(Configuration)' == 'Release'">SIMPLE_OPTIMIZATIONS</WasmMinifyJsLevel>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == ''">NONE</WasmMinifyJsLevel>
<WasmLinkIcalls Condition="'$(WasmLinkIcalls)' == ''">$(WasmBuildNative)</WasmLinkIcalls>

<_WasmICallTablePath>$(_WasmIntermediateOutputPath)icall-table.h</_WasmICallTablePath>
Expand DownExpand Up@@ -232,6 +234,9 @@
<_EmccLDFlags Include="@(_EmccCommonFlags)" />
<_EmccLDSFlags Include="-Wl,--allow-undefined" />
<_EmccLDSFlags Include="-s INITIAL_MEMORY=$(EmccInitialHeapSize)" />
<_EmccLDSFlags Condition="'$(WasmNativeStrip)' != 'false' and '$(WasmMinifyJsLevel)' != 'NONE'" Include="--closure 1" />
<_EmccLDSFlags Condition="'$(WasmNativeStrip)' != 'false' and '$(WasmMinifyJsLevel)' != 'NONE'" Include="--closure-args=--compilation_level=$(WasmMinifyJsLevel)" />


<!-- ILLinker should have removed unused imports, so error for Publish -->
<_EmccLDSFlags Include="-s ERROR_ON_UNDEFINED_SYMBOLS=0" Condition="'$(WasmBuildingForNestedPublish)' != 'true'" />
Expand Down
1 change: 1 addition & 0 deletions src/mono/wasm/build/WasmApp.targets
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,6 +24,7 @@
- $(WasmNativeDebugSymbols) - Build with native debug symbols, useful only with `$(RunAOTCompilation)`, or `$(WasmBuildNative)`
Defaults to true.
- $(WasmEmitSymbolMap) - Generates a `dotnet.js.symbols` file with a map of wasm function number to name.
- $(WasmMinifyJsLevel) - Use closure compiler to minify dotnet.js after linking. Default:`SIMPLE_OPTIMIZATIONS`. Other option is `NONE`.
- $(WasmDedup) - Whenever to dedup generic instances when using AOT. Defaults to true.

- $(WasmProfilers) - Profilers to use
Expand Down
5 changes: 5 additions & 0 deletions src/mono/wasm/runtime/es6/dotnet.es6.extpost.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
const ENVIRONMENT_IS_WEB = typeof window == "object";
const ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string";
const MONO = {}, BINDING = {}, INTERNAL = {}, IMPORTS = {};
var fetch = fetch || undefined; var require = require || undefined; var __dirname = __dirname || '';
__dotnet_runtime.__setEmscriptenEntrypoint(createDotnetRuntime);
const __initializeImportsAndExports = __dotnet_runtime.__initializeImportsAndExports;
const __requirePromise = ENVIRONMENT_IS_NODE ? import(/* webpackIgnore: true */'module').then(mod => mod.createRequire(import.meta.url)) : undefined;
const dotnet = __dotnet_runtime.moduleExports.dotnet;
const exit = __dotnet_runtime.moduleExports.exit;
export { dotnet, exit, INTERNAL };
32 changes: 16 additions & 16 deletions src/mono/wasm/runtime/es6/dotnet.es6.lib.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,16 +5,16 @@
"use strict";

#if USE_PTHREADS
const usePThreads = `true`;
const usePThreads = true;
const isPThread = `ENVIRONMENT_IS_PTHREAD`;
#else
const usePThreads = `false`;
const usePThreads = false;
const isPThread = `false`;
Comment thread
ilonatommy marked this conversation as resolved.
#endif

const DotnetSupportLib = {
$DOTNET: {},
// this line will be placed early on emscripten runtime creation, passing import and export objects into __dotnet_runtime IFFE
// this line will be placed early on emscripten runtime creation, passing import and export objects into __dotnet_runtime IIFE
// Emscripten uses require function for nodeJS even in ES6 module. We need https://nodejs.org/api/module.html#modulecreaterequirefilename
// We use dynamic import because there is no "module" module in the browser.
// This is async init of it, note it would become available only after first tick.
Expand All@@ -23,33 +23,33 @@ const DotnetSupportLib = {
// We also replace implementation of fetch
$DOTNET__postset: `
let __dotnet_replacement_PThread = ${usePThreads} ? {} : undefined;
if (${usePThreads}) {
__dotnet_replacement_PThread.loadWasmModuleToWorker = PThread.loadWasmModuleToWorker;
__dotnet_replacement_PThread.threadInitTLS = PThread.threadInitTLS;
__dotnet_replacement_PThread.allocateUnusedWorker = PThread.allocateUnusedWorker;
}
${usePThreads ? `
__dotnet_replacement_PThread.loadWasmModuleToWorker = PThread.loadWasmModuleToWorker;
__dotnet_replacement_PThread.threadInitTLS = PThread.threadInitTLS;
__dotnet_replacement_PThread.allocateUnusedWorker = PThread.allocateUnusedWorker;
` : ''}
let __dotnet_replacements = {scriptUrl: import.meta.url, fetch: globalThis.fetch, require, updateGlobalBufferAndViews, pthreadReplacements: __dotnet_replacement_PThread};
if (ENVIRONMENT_IS_NODE) {
__dotnet_replacements.requirePromise = import(/* webpackIgnore: true */'module').then(mod => mod.createRequire(import.meta.url));
__dotnet_replacements.requirePromise = __requirePromise;
}
let __dotnet_exportedAPI = __dotnet_runtime.__initializeImportsAndExports(
let __dotnet_exportedAPI = __initializeImportsAndExports(
{ isGlobal:false, isNode:ENVIRONMENT_IS_NODE, isWorker:ENVIRONMENT_IS_WORKER, isShell:ENVIRONMENT_IS_SHELL, isWeb:ENVIRONMENT_IS_WEB, isPThread:${isPThread}, quit_, ExitStatus, requirePromise:__dotnet_replacements.requirePromise },
{ mono:MONO, binding:BINDING, internal:INTERNAL, module:Module, marshaled_imports: IMPORTS },
__dotnet_replacements, __callbackAPI);
updateGlobalBufferAndViews = __dotnet_replacements.updateGlobalBufferAndViews;
var fetch = __dotnet_replacements.fetch;
fetch = __dotnet_replacements.fetch;
_scriptDir = __dirname = scriptDirectory = __dotnet_replacements.scriptDirectory;
if (ENVIRONMENT_IS_NODE) {
__dotnet_replacements.requirePromise.then(someRequire => {
require = someRequire;
});
}
var noExitRuntime = __dotnet_replacements.noExitRuntime;
if (${usePThreads}) {
PThread.loadWasmModuleToWorker = __dotnet_replacements.pthreadReplacements.loadWasmModuleToWorker;
PThread.threadInitTLS = __dotnet_replacements.pthreadReplacements.threadInitTLS;
PThread.allocateUnusedWorker = __dotnet_replacements.pthreadReplacements.allocateUnusedWorker;
}
${usePThreads ? `
PThread.loadWasmModuleToWorker = __dotnet_replacements.pthreadReplacements.loadWasmModuleToWorker;
PThread.threadInitTLS = __dotnet_replacements.pthreadReplacements.threadInitTLS;
PThread.allocateUnusedWorker = __dotnet_replacements.pthreadReplacements.allocateUnusedWorker;
` : ''}
`,
};

Expand Down
2 changes: 0 additions & 2 deletions src/mono/wasm/runtime/es6/dotnet.es6.pre.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
var require = require || undefined;
var __dirname = __dirname || '';
var __callbackAPI = { MONO, BINDING, INTERNAL, IMPORTS };
if (typeof createDotnetRuntime === "function") {
__callbackAPI.Module = Module = { ready: Module.ready };
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/runtime/exports.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,7 @@ function initializeImportsAndExports(
const module = exports.module as DotnetModule;
const globalThisAny = globalThis as any;

// we want to have same instance of MONO, BINDING and Module in dotnet iffe
// we want to have same instance of MONO, BINDING and Module in dotnet iife
set_imports_exports(imports, exports);
set_legacy_exports(exports);
init_polyfills(replacements);
Expand Down
4 changes: 2 additions & 2 deletions src/mono/wasm/runtime/logging.ts
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
//! Licensed to the .NET Foundation under one or more agreements.
//! The .NET Foundation licenses this file to you under the MIT license.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import BuildConfiguration from "consts:configuration";
import { INTERNAL, Module, runtimeHelpers } from "./imports";
Expand Down
4 changes: 0 additions & 4 deletions src/mono/wasm/runtime/run-outer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,10 +22,6 @@ export interface DotnetHostBuilder {
run(): Promise<number>
}

// these constants duplicate detection inside emscripten internals, but happen earlier
const ENVIRONMENT_IS_WEB = typeof window == "object";
const ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string";

class HostBuilder implements DotnetHostBuilder {
private instance?: RuntimeAPI;
private applicationArguments?: string[];
Expand Down
3 changes: 3 additions & 0 deletions src/mono/wasm/runtime/types/consts.d.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,3 +17,6 @@ declare module "consts:monoDiagnosticsMock" {
const constant: boolean;
export default constant;
}

declare const ENVIRONMENT_IS_NODE: boolean;
declare const ENVIRONMENT_IS_WEB: boolean;
6 changes: 5 additions & 1 deletion src/mono/wasm/wasm.proj
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,8 @@
<_EmccCompileRspPath>$(NativeBinDir)src\emcc-compile.rsp</_EmccCompileRspPath>
<_EmccLinkRspPath>$(NativeBinDir)src\emcc-link.rsp</_EmccLinkRspPath>
<WasmNativeStrip Condition="'$(ContinuousIntegrationBuild)' == 'true'">false</WasmNativeStrip>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == '' and '$(Configuration)' == 'Release'">SIMPLE_OPTIMIZATIONS</WasmMinifyJsLevel>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == ''">NONE</WasmMinifyJsLevel>
</PropertyGroup>

<Target Name="CheckEnv">
Expand DownExpand Up@@ -254,10 +256,12 @@
<PInvokeTableFile>$(ArtifactsObjDir)wasm/pinvoke-table.h</PInvokeTableFile>
<InterpToNativeTableFile>$(ArtifactsObjDir)wasm/wasm_m2n_invoke.g.h</InterpToNativeTableFile>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Debug'">-g -Os -s -DDEBUG=1 -DENABLE_AOT_PROFILER=1 -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Release'">-Oz -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Release'">-Oz -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>

<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Debug'" >$(CMakeConfigurationEmccFlags)</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Release'">-O2</CMakeConfigurationLinkFlags>

<CMakeConfigurationLinkFlags Condition="'$(WasmMinifyJsLevel)' != 'NONE'">$(CMakeConfigurationLinkFlags) --closure 1 --closure-args=--compilation_level=$(WasmMinifyJsLevel)</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags>$(CMakeConfigurationLinkFlags) -s EXPORT_ES6=1</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(MonoWasmThreads)' == 'true'">$(CMakeConfigurationLinkFlags) -Wno-pthreads-mem-growth</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags >$(CMakeConfigurationLinkFlags) --emit-symbol-map</CMakeConfigurationLinkFlags>
Expand Down
15 changes: 8 additions & 7 deletions src/native/libs/System.Native/pal_random.lib.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,11 +3,12 @@

const DotNetEntropyLib = {
$DOTNETENTROPY: {
// batchedQuotaMax is the max number of bytes as specified by the api spec.
// If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm.
// https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
batchedQuotaMax: 65536,
getBatchedRandomValues: function (buffer, bufferLength) {
// batchedQuotaMax is the max number of bytes as specified by the api spec.
// If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm.
// https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
const batchedQuotaMax = 65536;

// Chrome doesn't want SharedArrayBuffer to be passed to crypto APIs
const needTempBuf = typeof SharedArrayBuffer !== 'undefined' && Module.HEAPU8.buffer instanceof SharedArrayBuffer;
// if we need a temporary buffer, make one that is big enough and write into it from the beginning
Expand All@@ -16,14 +17,14 @@ const DotNetEntropyLib = {
const offset = needTempBuf ? 0 : buffer;
// for modern web browsers
// map the work array to the memory buffer passed with the length
for (let i = 0; i < bufferLength; i += this.batchedQuotaMax) {
const view = new Uint8Array(buf, offset + i, Math.min(bufferLength - i, this.batchedQuotaMax));
for (let i = 0; i < bufferLength; i += batchedQuotaMax) {
const view = new Uint8Array(buf, offset + i, Math.min(bufferLength - i, batchedQuotaMax));
crypto.getRandomValues(view)
}
if (needTempBuf) {
// copy data out of the temporary buffer into the wasm instance memory
const heapView = new Uint8Array(Module.HEAPU8.buffer, buffer, bufferLength);
heapView.set(new Uint8Array(buf));
heapView.set(new Uint8Array(buf));
}
}
},
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [draft][browser] enable closure compiler for dotnet.js by pavelsavara · Pull Request #80178 · dotnet/runtime · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/mono/wasm/build/WasmApp.Native.targets
Original file line numberDiff line numberDiff line change
Expand Up@@ -156,6 +156,8 @@
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == '' and '$(Configuration)' == 'Debug' and '$(WasmBuildingForNestedPublish)' != 'true'">false</WasmNativeStrip>
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == ''">true</WasmNativeStrip>
<WasmNativeDebugSymbols Condition="'$(WasmNativeDebugSymbols)' == ''">true</WasmNativeDebugSymbols>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == '' and '$(Configuration)' == 'Release'">SIMPLE_OPTIMIZATIONS</WasmMinifyJsLevel>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == ''">NONE</WasmMinifyJsLevel>
<WasmLinkIcalls Condition="'$(WasmLinkIcalls)' == ''">$(WasmBuildNative)</WasmLinkIcalls>

<_WasmICallTablePath>$(_WasmIntermediateOutputPath)icall-table.h</_WasmICallTablePath>
Expand DownExpand Up@@ -232,6 +234,9 @@
<_EmccLDFlags Include="@(_EmccCommonFlags)" />
<_EmccLDSFlags Include="-Wl,--allow-undefined" />
<_EmccLDSFlags Include="-s INITIAL_MEMORY=$(EmccInitialHeapSize)" />
<_EmccLDSFlags Condition="'$(WasmNativeStrip)' != 'false' and '$(WasmMinifyJsLevel)' != 'NONE'" Include="--closure 1" />
<_EmccLDSFlags Condition="'$(WasmNativeStrip)' != 'false' and '$(WasmMinifyJsLevel)' != 'NONE'" Include="--closure-args=--compilation_level=$(WasmMinifyJsLevel)" />


<!-- ILLinker should have removed unused imports, so error for Publish -->
<_EmccLDSFlags Include="-s ERROR_ON_UNDEFINED_SYMBOLS=0" Condition="'$(WasmBuildingForNestedPublish)' != 'true'" />
Expand Down
1 change: 1 addition & 0 deletions src/mono/wasm/build/WasmApp.targets
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,6 +24,7 @@
- $(WasmNativeDebugSymbols) - Build with native debug symbols, useful only with `$(RunAOTCompilation)`, or `$(WasmBuildNative)`
Defaults to true.
- $(WasmEmitSymbolMap) - Generates a `dotnet.js.symbols` file with a map of wasm function number to name.
- $(WasmMinifyJsLevel) - Use closure compiler to minify dotnet.js after linking. Default:`SIMPLE_OPTIMIZATIONS`. Other option is `NONE`.
- $(WasmDedup) - Whenever to dedup generic instances when using AOT. Defaults to true.

- $(WasmProfilers) - Profilers to use
Expand Down
5 changes: 5 additions & 0 deletions src/mono/wasm/runtime/es6/dotnet.es6.extpost.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
const ENVIRONMENT_IS_WEB = typeof window == "object";
const ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string";
const MONO = {}, BINDING = {}, INTERNAL = {}, IMPORTS = {};
var fetch = fetch || undefined; var require = require || undefined; var __dirname = __dirname || '';
__dotnet_runtime.__setEmscriptenEntrypoint(createDotnetRuntime);
const __initializeImportsAndExports = __dotnet_runtime.__initializeImportsAndExports;
const __requirePromise = ENVIRONMENT_IS_NODE ? import(/* webpackIgnore: true */'module').then(mod => mod.createRequire(import.meta.url)) : undefined;
const dotnet = __dotnet_runtime.moduleExports.dotnet;
const exit = __dotnet_runtime.moduleExports.exit;
export { dotnet, exit, INTERNAL };
32 changes: 16 additions & 16 deletions src/mono/wasm/runtime/es6/dotnet.es6.lib.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,16 +5,16 @@
"use strict";

#if USE_PTHREADS
const usePThreads = `true`;
const usePThreads = true;
const isPThread = `ENVIRONMENT_IS_PTHREAD`;
#else
const usePThreads = `false`;
const usePThreads = false;
const isPThread = `false`;
Comment thread
ilonatommy marked this conversation as resolved.
#endif

const DotnetSupportLib = {
$DOTNET: {},
// this line will be placed early on emscripten runtime creation, passing import and export objects into __dotnet_runtime IFFE
// this line will be placed early on emscripten runtime creation, passing import and export objects into __dotnet_runtime IIFE
// Emscripten uses require function for nodeJS even in ES6 module. We need https://nodejs.org/api/module.html#modulecreaterequirefilename
// We use dynamic import because there is no "module" module in the browser.
// This is async init of it, note it would become available only after first tick.
Expand All@@ -23,33 +23,33 @@ const DotnetSupportLib = {
// We also replace implementation of fetch
$DOTNET__postset: `
let __dotnet_replacement_PThread = ${usePThreads} ? {} : undefined;
if (${usePThreads}) {
__dotnet_replacement_PThread.loadWasmModuleToWorker = PThread.loadWasmModuleToWorker;
__dotnet_replacement_PThread.threadInitTLS = PThread.threadInitTLS;
__dotnet_replacement_PThread.allocateUnusedWorker = PThread.allocateUnusedWorker;
}
${usePThreads ? `
__dotnet_replacement_PThread.loadWasmModuleToWorker = PThread.loadWasmModuleToWorker;
__dotnet_replacement_PThread.threadInitTLS = PThread.threadInitTLS;
__dotnet_replacement_PThread.allocateUnusedWorker = PThread.allocateUnusedWorker;
` : ''}
let __dotnet_replacements = {scriptUrl: import.meta.url, fetch: globalThis.fetch, require, updateGlobalBufferAndViews, pthreadReplacements: __dotnet_replacement_PThread};
if (ENVIRONMENT_IS_NODE) {
__dotnet_replacements.requirePromise = import(/* webpackIgnore: true */'module').then(mod => mod.createRequire(import.meta.url));
__dotnet_replacements.requirePromise = __requirePromise;
}
let __dotnet_exportedAPI = __dotnet_runtime.__initializeImportsAndExports(
let __dotnet_exportedAPI = __initializeImportsAndExports(
{ isGlobal:false, isNode:ENVIRONMENT_IS_NODE, isWorker:ENVIRONMENT_IS_WORKER, isShell:ENVIRONMENT_IS_SHELL, isWeb:ENVIRONMENT_IS_WEB, isPThread:${isPThread}, quit_, ExitStatus, requirePromise:__dotnet_replacements.requirePromise },
{ mono:MONO, binding:BINDING, internal:INTERNAL, module:Module, marshaled_imports: IMPORTS },
__dotnet_replacements, __callbackAPI);
updateGlobalBufferAndViews = __dotnet_replacements.updateGlobalBufferAndViews;
var fetch = __dotnet_replacements.fetch;
fetch = __dotnet_replacements.fetch;
_scriptDir = __dirname = scriptDirectory = __dotnet_replacements.scriptDirectory;
if (ENVIRONMENT_IS_NODE) {
__dotnet_replacements.requirePromise.then(someRequire => {
require = someRequire;
});
}
var noExitRuntime = __dotnet_replacements.noExitRuntime;
if (${usePThreads}) {
PThread.loadWasmModuleToWorker = __dotnet_replacements.pthreadReplacements.loadWasmModuleToWorker;
PThread.threadInitTLS = __dotnet_replacements.pthreadReplacements.threadInitTLS;
PThread.allocateUnusedWorker = __dotnet_replacements.pthreadReplacements.allocateUnusedWorker;
}
${usePThreads ? `
PThread.loadWasmModuleToWorker = __dotnet_replacements.pthreadReplacements.loadWasmModuleToWorker;
PThread.threadInitTLS = __dotnet_replacements.pthreadReplacements.threadInitTLS;
PThread.allocateUnusedWorker = __dotnet_replacements.pthreadReplacements.allocateUnusedWorker;
` : ''}
`,
};

Expand Down
2 changes: 0 additions & 2 deletions src/mono/wasm/runtime/es6/dotnet.es6.pre.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
var require = require || undefined;
var __dirname = __dirname || '';
var __callbackAPI = { MONO, BINDING, INTERNAL, IMPORTS };
if (typeof createDotnetRuntime === "function") {
__callbackAPI.Module = Module = { ready: Module.ready };
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/runtime/exports.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,7 @@ function initializeImportsAndExports(
const module = exports.module as DotnetModule;
const globalThisAny = globalThis as any;

// we want to have same instance of MONO, BINDING and Module in dotnet iffe
// we want to have same instance of MONO, BINDING and Module in dotnet iife
set_imports_exports(imports, exports);
set_legacy_exports(exports);
init_polyfills(replacements);
Expand Down
4 changes: 2 additions & 2 deletions src/mono/wasm/runtime/logging.ts
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
//! Licensed to the .NET Foundation under one or more agreements.
//! The .NET Foundation licenses this file to you under the MIT license.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import BuildConfiguration from "consts:configuration";
import { INTERNAL, Module, runtimeHelpers } from "./imports";
Expand Down
4 changes: 0 additions & 4 deletions src/mono/wasm/runtime/run-outer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,10 +22,6 @@ export interface DotnetHostBuilder {
run(): Promise<number>
}

// these constants duplicate detection inside emscripten internals, but happen earlier
const ENVIRONMENT_IS_WEB = typeof window == "object";
const ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string";

class HostBuilder implements DotnetHostBuilder {
private instance?: RuntimeAPI;
private applicationArguments?: string[];
Expand Down
3 changes: 3 additions & 0 deletions src/mono/wasm/runtime/types/consts.d.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,3 +17,6 @@ declare module "consts:monoDiagnosticsMock" {
const constant: boolean;
export default constant;
}

declare const ENVIRONMENT_IS_NODE: boolean;
declare const ENVIRONMENT_IS_WEB: boolean;
6 changes: 5 additions & 1 deletion src/mono/wasm/wasm.proj
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,8 @@
<_EmccCompileRspPath>$(NativeBinDir)src\emcc-compile.rsp</_EmccCompileRspPath>
<_EmccLinkRspPath>$(NativeBinDir)src\emcc-link.rsp</_EmccLinkRspPath>
<WasmNativeStrip Condition="'$(ContinuousIntegrationBuild)' == 'true'">false</WasmNativeStrip>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == '' and '$(Configuration)' == 'Release'">SIMPLE_OPTIMIZATIONS</WasmMinifyJsLevel>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == ''">NONE</WasmMinifyJsLevel>
</PropertyGroup>

<Target Name="CheckEnv">
Expand DownExpand Up@@ -254,10 +256,12 @@
<PInvokeTableFile>$(ArtifactsObjDir)wasm/pinvoke-table.h</PInvokeTableFile>
<InterpToNativeTableFile>$(ArtifactsObjDir)wasm/wasm_m2n_invoke.g.h</InterpToNativeTableFile>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Debug'">-g -Os -s -DDEBUG=1 -DENABLE_AOT_PROFILER=1 -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Release'">-Oz -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Release'">-Oz -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>

<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Debug'" >$(CMakeConfigurationEmccFlags)</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Release'">-O2</CMakeConfigurationLinkFlags>

<CMakeConfigurationLinkFlags Condition="'$(WasmMinifyJsLevel)' != 'NONE'">$(CMakeConfigurationLinkFlags) --closure 1 --closure-args=--compilation_level=$(WasmMinifyJsLevel)</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags>$(CMakeConfigurationLinkFlags) -s EXPORT_ES6=1</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(MonoWasmThreads)' == 'true'">$(CMakeConfigurationLinkFlags) -Wno-pthreads-mem-growth</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags >$(CMakeConfigurationLinkFlags) --emit-symbol-map</CMakeConfigurationLinkFlags>
Expand Down
15 changes: 8 additions & 7 deletions src/native/libs/System.Native/pal_random.lib.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,11 +3,12 @@

const DotNetEntropyLib = {
$DOTNETENTROPY: {
// batchedQuotaMax is the max number of bytes as specified by the api spec.
// If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm.
// https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
batchedQuotaMax: 65536,
getBatchedRandomValues: function (buffer, bufferLength) {
// batchedQuotaMax is the max number of bytes as specified by the api spec.
// If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm.
// https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
const batchedQuotaMax = 65536;

// Chrome doesn't want SharedArrayBuffer to be passed to crypto APIs
const needTempBuf = typeof SharedArrayBuffer !== 'undefined' && Module.HEAPU8.buffer instanceof SharedArrayBuffer;
// if we need a temporary buffer, make one that is big enough and write into it from the beginning
Expand All@@ -16,14 +17,14 @@ const DotNetEntropyLib = {
const offset = needTempBuf ? 0 : buffer;
// for modern web browsers
// map the work array to the memory buffer passed with the length
for (let i = 0; i < bufferLength; i += this.batchedQuotaMax) {
const view = new Uint8Array(buf, offset + i, Math.min(bufferLength - i, this.batchedQuotaMax));
for (let i = 0; i < bufferLength; i += batchedQuotaMax) {
const view = new Uint8Array(buf, offset + i, Math.min(bufferLength - i, batchedQuotaMax));
crypto.getRandomValues(view)
}
if (needTempBuf) {
// copy data out of the temporary buffer into the wasm instance memory
const heapView = new Uint8Array(Module.HEAPU8.buffer, buffer, bufferLength);
heapView.set(new Uint8Array(buf));
heapView.set(new Uint8Array(buf));
}
}
},
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [draft][browser] enable closure compiler for dotnet.js by pavelsavara · Pull Request #80178 · dotnet/runtime · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/mono/wasm/build/WasmApp.Native.targets
Original file line numberDiff line numberDiff line change
Expand Up@@ -156,6 +156,8 @@
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == '' and '$(Configuration)' == 'Debug' and '$(WasmBuildingForNestedPublish)' != 'true'">false</WasmNativeStrip>
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == ''">true</WasmNativeStrip>
<WasmNativeDebugSymbols Condition="'$(WasmNativeDebugSymbols)' == ''">true</WasmNativeDebugSymbols>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == '' and '$(Configuration)' == 'Release'">SIMPLE_OPTIMIZATIONS</WasmMinifyJsLevel>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == ''">NONE</WasmMinifyJsLevel>
<WasmLinkIcalls Condition="'$(WasmLinkIcalls)' == ''">$(WasmBuildNative)</WasmLinkIcalls>

<_WasmICallTablePath>$(_WasmIntermediateOutputPath)icall-table.h</_WasmICallTablePath>
Expand DownExpand Up@@ -232,6 +234,9 @@
<_EmccLDFlags Include="@(_EmccCommonFlags)" />
<_EmccLDSFlags Include="-Wl,--allow-undefined" />
<_EmccLDSFlags Include="-s INITIAL_MEMORY=$(EmccInitialHeapSize)" />
<_EmccLDSFlags Condition="'$(WasmNativeStrip)' != 'false' and '$(WasmMinifyJsLevel)' != 'NONE'" Include="--closure 1" />
<_EmccLDSFlags Condition="'$(WasmNativeStrip)' != 'false' and '$(WasmMinifyJsLevel)' != 'NONE'" Include="--closure-args=--compilation_level=$(WasmMinifyJsLevel)" />


<!-- ILLinker should have removed unused imports, so error for Publish -->
<_EmccLDSFlags Include="-s ERROR_ON_UNDEFINED_SYMBOLS=0" Condition="'$(WasmBuildingForNestedPublish)' != 'true'" />
Expand Down
1 change: 1 addition & 0 deletions src/mono/wasm/build/WasmApp.targets
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,6 +24,7 @@
- $(WasmNativeDebugSymbols) - Build with native debug symbols, useful only with `$(RunAOTCompilation)`, or `$(WasmBuildNative)`
Defaults to true.
- $(WasmEmitSymbolMap) - Generates a `dotnet.js.symbols` file with a map of wasm function number to name.
- $(WasmMinifyJsLevel) - Use closure compiler to minify dotnet.js after linking. Default:`SIMPLE_OPTIMIZATIONS`. Other option is `NONE`.
- $(WasmDedup) - Whenever to dedup generic instances when using AOT. Defaults to true.

- $(WasmProfilers) - Profilers to use
Expand Down
5 changes: 5 additions & 0 deletions src/mono/wasm/runtime/es6/dotnet.es6.extpost.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
const ENVIRONMENT_IS_WEB = typeof window == "object";
const ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string";
const MONO = {}, BINDING = {}, INTERNAL = {}, IMPORTS = {};
var fetch = fetch || undefined; var require = require || undefined; var __dirname = __dirname || '';
__dotnet_runtime.__setEmscriptenEntrypoint(createDotnetRuntime);
const __initializeImportsAndExports = __dotnet_runtime.__initializeImportsAndExports;
const __requirePromise = ENVIRONMENT_IS_NODE ? import(/* webpackIgnore: true */'module').then(mod => mod.createRequire(import.meta.url)) : undefined;
const dotnet = __dotnet_runtime.moduleExports.dotnet;
const exit = __dotnet_runtime.moduleExports.exit;
export { dotnet, exit, INTERNAL };
32 changes: 16 additions & 16 deletions src/mono/wasm/runtime/es6/dotnet.es6.lib.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,16 +5,16 @@
"use strict";

#if USE_PTHREADS
const usePThreads = `true`;
const usePThreads = true;
const isPThread = `ENVIRONMENT_IS_PTHREAD`;
#else
const usePThreads = `false`;
const usePThreads = false;
const isPThread = `false`;
Comment thread
ilonatommy marked this conversation as resolved.
#endif

const DotnetSupportLib = {
$DOTNET: {},
// this line will be placed early on emscripten runtime creation, passing import and export objects into __dotnet_runtime IFFE
// this line will be placed early on emscripten runtime creation, passing import and export objects into __dotnet_runtime IIFE
// Emscripten uses require function for nodeJS even in ES6 module. We need https://nodejs.org/api/module.html#modulecreaterequirefilename
// We use dynamic import because there is no "module" module in the browser.
// This is async init of it, note it would become available only after first tick.
Expand All@@ -23,33 +23,33 @@ const DotnetSupportLib = {
// We also replace implementation of fetch
$DOTNET__postset: `
let __dotnet_replacement_PThread = ${usePThreads} ? {} : undefined;
if (${usePThreads}) {
__dotnet_replacement_PThread.loadWasmModuleToWorker = PThread.loadWasmModuleToWorker;
__dotnet_replacement_PThread.threadInitTLS = PThread.threadInitTLS;
__dotnet_replacement_PThread.allocateUnusedWorker = PThread.allocateUnusedWorker;
}
${usePThreads ? `
__dotnet_replacement_PThread.loadWasmModuleToWorker = PThread.loadWasmModuleToWorker;
__dotnet_replacement_PThread.threadInitTLS = PThread.threadInitTLS;
__dotnet_replacement_PThread.allocateUnusedWorker = PThread.allocateUnusedWorker;
` : ''}
let __dotnet_replacements = {scriptUrl: import.meta.url, fetch: globalThis.fetch, require, updateGlobalBufferAndViews, pthreadReplacements: __dotnet_replacement_PThread};
if (ENVIRONMENT_IS_NODE) {
__dotnet_replacements.requirePromise = import(/* webpackIgnore: true */'module').then(mod => mod.createRequire(import.meta.url));
__dotnet_replacements.requirePromise = __requirePromise;
}
let __dotnet_exportedAPI = __dotnet_runtime.__initializeImportsAndExports(
let __dotnet_exportedAPI = __initializeImportsAndExports(
{ isGlobal:false, isNode:ENVIRONMENT_IS_NODE, isWorker:ENVIRONMENT_IS_WORKER, isShell:ENVIRONMENT_IS_SHELL, isWeb:ENVIRONMENT_IS_WEB, isPThread:${isPThread}, quit_, ExitStatus, requirePromise:__dotnet_replacements.requirePromise },
{ mono:MONO, binding:BINDING, internal:INTERNAL, module:Module, marshaled_imports: IMPORTS },
__dotnet_replacements, __callbackAPI);
updateGlobalBufferAndViews = __dotnet_replacements.updateGlobalBufferAndViews;
var fetch = __dotnet_replacements.fetch;
fetch = __dotnet_replacements.fetch;
_scriptDir = __dirname = scriptDirectory = __dotnet_replacements.scriptDirectory;
if (ENVIRONMENT_IS_NODE) {
__dotnet_replacements.requirePromise.then(someRequire => {
require = someRequire;
});
}
var noExitRuntime = __dotnet_replacements.noExitRuntime;
if (${usePThreads}) {
PThread.loadWasmModuleToWorker = __dotnet_replacements.pthreadReplacements.loadWasmModuleToWorker;
PThread.threadInitTLS = __dotnet_replacements.pthreadReplacements.threadInitTLS;
PThread.allocateUnusedWorker = __dotnet_replacements.pthreadReplacements.allocateUnusedWorker;
}
${usePThreads ? `
PThread.loadWasmModuleToWorker = __dotnet_replacements.pthreadReplacements.loadWasmModuleToWorker;
PThread.threadInitTLS = __dotnet_replacements.pthreadReplacements.threadInitTLS;
PThread.allocateUnusedWorker = __dotnet_replacements.pthreadReplacements.allocateUnusedWorker;
` : ''}
`,
};

Expand Down
2 changes: 0 additions & 2 deletions src/mono/wasm/runtime/es6/dotnet.es6.pre.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
var require = require || undefined;
var __dirname = __dirname || '';
var __callbackAPI = { MONO, BINDING, INTERNAL, IMPORTS };
if (typeof createDotnetRuntime === "function") {
__callbackAPI.Module = Module = { ready: Module.ready };
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/runtime/exports.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,7 @@ function initializeImportsAndExports(
const module = exports.module as DotnetModule;
const globalThisAny = globalThis as any;

// we want to have same instance of MONO, BINDING and Module in dotnet iffe
// we want to have same instance of MONO, BINDING and Module in dotnet iife
set_imports_exports(imports, exports);
set_legacy_exports(exports);
init_polyfills(replacements);
Expand Down
4 changes: 2 additions & 2 deletions src/mono/wasm/runtime/logging.ts
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
//! Licensed to the .NET Foundation under one or more agreements.
//! The .NET Foundation licenses this file to you under the MIT license.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import BuildConfiguration from "consts:configuration";
import { INTERNAL, Module, runtimeHelpers } from "./imports";
Expand Down
4 changes: 0 additions & 4 deletions src/mono/wasm/runtime/run-outer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,10 +22,6 @@ export interface DotnetHostBuilder {
run(): Promise<number>
}

// these constants duplicate detection inside emscripten internals, but happen earlier
const ENVIRONMENT_IS_WEB = typeof window == "object";
const ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string";

class HostBuilder implements DotnetHostBuilder {
private instance?: RuntimeAPI;
private applicationArguments?: string[];
Expand Down
3 changes: 3 additions & 0 deletions src/mono/wasm/runtime/types/consts.d.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,3 +17,6 @@ declare module "consts:monoDiagnosticsMock" {
const constant: boolean;
export default constant;
}

declare const ENVIRONMENT_IS_NODE: boolean;
declare const ENVIRONMENT_IS_WEB: boolean;
6 changes: 5 additions & 1 deletion src/mono/wasm/wasm.proj
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,8 @@
<_EmccCompileRspPath>$(NativeBinDir)src\emcc-compile.rsp</_EmccCompileRspPath>
<_EmccLinkRspPath>$(NativeBinDir)src\emcc-link.rsp</_EmccLinkRspPath>
<WasmNativeStrip Condition="'$(ContinuousIntegrationBuild)' == 'true'">false</WasmNativeStrip>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == '' and '$(Configuration)' == 'Release'">SIMPLE_OPTIMIZATIONS</WasmMinifyJsLevel>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == ''">NONE</WasmMinifyJsLevel>
</PropertyGroup>

<Target Name="CheckEnv">
Expand DownExpand Up@@ -254,10 +256,12 @@
<PInvokeTableFile>$(ArtifactsObjDir)wasm/pinvoke-table.h</PInvokeTableFile>
<InterpToNativeTableFile>$(ArtifactsObjDir)wasm/wasm_m2n_invoke.g.h</InterpToNativeTableFile>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Debug'">-g -Os -s -DDEBUG=1 -DENABLE_AOT_PROFILER=1 -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Release'">-Oz -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Release'">-Oz -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>

<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Debug'" >$(CMakeConfigurationEmccFlags)</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Release'">-O2</CMakeConfigurationLinkFlags>

<CMakeConfigurationLinkFlags Condition="'$(WasmMinifyJsLevel)' != 'NONE'">$(CMakeConfigurationLinkFlags) --closure 1 --closure-args=--compilation_level=$(WasmMinifyJsLevel)</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags>$(CMakeConfigurationLinkFlags) -s EXPORT_ES6=1</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(MonoWasmThreads)' == 'true'">$(CMakeConfigurationLinkFlags) -Wno-pthreads-mem-growth</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags >$(CMakeConfigurationLinkFlags) --emit-symbol-map</CMakeConfigurationLinkFlags>
Expand Down
15 changes: 8 additions & 7 deletions src/native/libs/System.Native/pal_random.lib.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,11 +3,12 @@

const DotNetEntropyLib = {
$DOTNETENTROPY: {
// batchedQuotaMax is the max number of bytes as specified by the api spec.
// If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm.
// https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
batchedQuotaMax: 65536,
getBatchedRandomValues: function (buffer, bufferLength) {
// batchedQuotaMax is the max number of bytes as specified by the api spec.
// If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm.
// https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
const batchedQuotaMax = 65536;

// Chrome doesn't want SharedArrayBuffer to be passed to crypto APIs
const needTempBuf = typeof SharedArrayBuffer !== 'undefined' && Module.HEAPU8.buffer instanceof SharedArrayBuffer;
// if we need a temporary buffer, make one that is big enough and write into it from the beginning
Expand All@@ -16,14 +17,14 @@ const DotNetEntropyLib = {
const offset = needTempBuf ? 0 : buffer;
// for modern web browsers
// map the work array to the memory buffer passed with the length
for (let i = 0; i < bufferLength; i += this.batchedQuotaMax) {
const view = new Uint8Array(buf, offset + i, Math.min(bufferLength - i, this.batchedQuotaMax));
for (let i = 0; i < bufferLength; i += batchedQuotaMax) {
const view = new Uint8Array(buf, offset + i, Math.min(bufferLength - i, batchedQuotaMax));
crypto.getRandomValues(view)
}
if (needTempBuf) {
// copy data out of the temporary buffer into the wasm instance memory
const heapView = new Uint8Array(Module.HEAPU8.buffer, buffer, bufferLength);
heapView.set(new Uint8Array(buf));
heapView.set(new Uint8Array(buf));
}
}
},
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' [draft][browser] enable closure compiler for dotnet.js by pavelsavara · Pull Request #80178 · dotnet/runtime · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/mono/wasm/build/WasmApp.Native.targets
Original file line numberDiff line numberDiff line change
Expand Up@@ -156,6 +156,8 @@
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == '' and '$(Configuration)' == 'Debug' and '$(WasmBuildingForNestedPublish)' != 'true'">false</WasmNativeStrip>
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == ''">true</WasmNativeStrip>
<WasmNativeDebugSymbols Condition="'$(WasmNativeDebugSymbols)' == ''">true</WasmNativeDebugSymbols>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == '' and '$(Configuration)' == 'Release'">SIMPLE_OPTIMIZATIONS</WasmMinifyJsLevel>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == ''">NONE</WasmMinifyJsLevel>
<WasmLinkIcalls Condition="'$(WasmLinkIcalls)' == ''">$(WasmBuildNative)</WasmLinkIcalls>

<_WasmICallTablePath>$(_WasmIntermediateOutputPath)icall-table.h</_WasmICallTablePath>
Expand DownExpand Up@@ -232,6 +234,9 @@
<_EmccLDFlags Include="@(_EmccCommonFlags)" />
<_EmccLDSFlags Include="-Wl,--allow-undefined" />
<_EmccLDSFlags Include="-s INITIAL_MEMORY=$(EmccInitialHeapSize)" />
<_EmccLDSFlags Condition="'$(WasmNativeStrip)' != 'false' and '$(WasmMinifyJsLevel)' != 'NONE'" Include="--closure 1" />
<_EmccLDSFlags Condition="'$(WasmNativeStrip)' != 'false' and '$(WasmMinifyJsLevel)' != 'NONE'" Include="--closure-args=--compilation_level=$(WasmMinifyJsLevel)" />


<!-- ILLinker should have removed unused imports, so error for Publish -->
<_EmccLDSFlags Include="-s ERROR_ON_UNDEFINED_SYMBOLS=0" Condition="'$(WasmBuildingForNestedPublish)' != 'true'" />
Expand Down
1 change: 1 addition & 0 deletions src/mono/wasm/build/WasmApp.targets
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,6 +24,7 @@
- $(WasmNativeDebugSymbols) - Build with native debug symbols, useful only with `$(RunAOTCompilation)`, or `$(WasmBuildNative)`
Defaults to true.
- $(WasmEmitSymbolMap) - Generates a `dotnet.js.symbols` file with a map of wasm function number to name.
- $(WasmMinifyJsLevel) - Use closure compiler to minify dotnet.js after linking. Default:`SIMPLE_OPTIMIZATIONS`. Other option is `NONE`.
- $(WasmDedup) - Whenever to dedup generic instances when using AOT. Defaults to true.

- $(WasmProfilers) - Profilers to use
Expand Down
5 changes: 5 additions & 0 deletions src/mono/wasm/runtime/es6/dotnet.es6.extpost.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
const ENVIRONMENT_IS_WEB = typeof window == "object";
const ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string";
const MONO = {}, BINDING = {}, INTERNAL = {}, IMPORTS = {};
var fetch = fetch || undefined; var require = require || undefined; var __dirname = __dirname || '';
__dotnet_runtime.__setEmscriptenEntrypoint(createDotnetRuntime);
const __initializeImportsAndExports = __dotnet_runtime.__initializeImportsAndExports;
const __requirePromise = ENVIRONMENT_IS_NODE ? import(/* webpackIgnore: true */'module').then(mod => mod.createRequire(import.meta.url)) : undefined;
const dotnet = __dotnet_runtime.moduleExports.dotnet;
const exit = __dotnet_runtime.moduleExports.exit;
export { dotnet, exit, INTERNAL };
32 changes: 16 additions & 16 deletions src/mono/wasm/runtime/es6/dotnet.es6.lib.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,16 +5,16 @@
"use strict";

#if USE_PTHREADS
const usePThreads = `true`;
const usePThreads = true;
const isPThread = `ENVIRONMENT_IS_PTHREAD`;
#else
const usePThreads = `false`;
const usePThreads = false;
const isPThread = `false`;
Comment thread
ilonatommy marked this conversation as resolved.
#endif

const DotnetSupportLib = {
$DOTNET: {},
// this line will be placed early on emscripten runtime creation, passing import and export objects into __dotnet_runtime IFFE
// this line will be placed early on emscripten runtime creation, passing import and export objects into __dotnet_runtime IIFE
// Emscripten uses require function for nodeJS even in ES6 module. We need https://nodejs.org/api/module.html#modulecreaterequirefilename
// We use dynamic import because there is no "module" module in the browser.
// This is async init of it, note it would become available only after first tick.
Expand All@@ -23,33 +23,33 @@ const DotnetSupportLib = {
// We also replace implementation of fetch
$DOTNET__postset: `
let __dotnet_replacement_PThread = ${usePThreads} ? {} : undefined;
if (${usePThreads}) {
__dotnet_replacement_PThread.loadWasmModuleToWorker = PThread.loadWasmModuleToWorker;
__dotnet_replacement_PThread.threadInitTLS = PThread.threadInitTLS;
__dotnet_replacement_PThread.allocateUnusedWorker = PThread.allocateUnusedWorker;
}
${usePThreads ? `
__dotnet_replacement_PThread.loadWasmModuleToWorker = PThread.loadWasmModuleToWorker;
__dotnet_replacement_PThread.threadInitTLS = PThread.threadInitTLS;
__dotnet_replacement_PThread.allocateUnusedWorker = PThread.allocateUnusedWorker;
` : ''}
let __dotnet_replacements = {scriptUrl: import.meta.url, fetch: globalThis.fetch, require, updateGlobalBufferAndViews, pthreadReplacements: __dotnet_replacement_PThread};
if (ENVIRONMENT_IS_NODE) {
__dotnet_replacements.requirePromise = import(/* webpackIgnore: true */'module').then(mod => mod.createRequire(import.meta.url));
__dotnet_replacements.requirePromise = __requirePromise;
}
let __dotnet_exportedAPI = __dotnet_runtime.__initializeImportsAndExports(
let __dotnet_exportedAPI = __initializeImportsAndExports(
{ isGlobal:false, isNode:ENVIRONMENT_IS_NODE, isWorker:ENVIRONMENT_IS_WORKER, isShell:ENVIRONMENT_IS_SHELL, isWeb:ENVIRONMENT_IS_WEB, isPThread:${isPThread}, quit_, ExitStatus, requirePromise:__dotnet_replacements.requirePromise },
{ mono:MONO, binding:BINDING, internal:INTERNAL, module:Module, marshaled_imports: IMPORTS },
__dotnet_replacements, __callbackAPI);
updateGlobalBufferAndViews = __dotnet_replacements.updateGlobalBufferAndViews;
var fetch = __dotnet_replacements.fetch;
fetch = __dotnet_replacements.fetch;
_scriptDir = __dirname = scriptDirectory = __dotnet_replacements.scriptDirectory;
if (ENVIRONMENT_IS_NODE) {
__dotnet_replacements.requirePromise.then(someRequire => {
require = someRequire;
});
}
var noExitRuntime = __dotnet_replacements.noExitRuntime;
if (${usePThreads}) {
PThread.loadWasmModuleToWorker = __dotnet_replacements.pthreadReplacements.loadWasmModuleToWorker;
PThread.threadInitTLS = __dotnet_replacements.pthreadReplacements.threadInitTLS;
PThread.allocateUnusedWorker = __dotnet_replacements.pthreadReplacements.allocateUnusedWorker;
}
${usePThreads ? `
PThread.loadWasmModuleToWorker = __dotnet_replacements.pthreadReplacements.loadWasmModuleToWorker;
PThread.threadInitTLS = __dotnet_replacements.pthreadReplacements.threadInitTLS;
PThread.allocateUnusedWorker = __dotnet_replacements.pthreadReplacements.allocateUnusedWorker;
` : ''}
`,
};

Expand Down
2 changes: 0 additions & 2 deletions src/mono/wasm/runtime/es6/dotnet.es6.pre.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
var require = require || undefined;
var __dirname = __dirname || '';
var __callbackAPI = { MONO, BINDING, INTERNAL, IMPORTS };
if (typeof createDotnetRuntime === "function") {
__callbackAPI.Module = Module = { ready: Module.ready };
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/runtime/exports.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,7 @@ function initializeImportsAndExports(
const module = exports.module as DotnetModule;
const globalThisAny = globalThis as any;

// we want to have same instance of MONO, BINDING and Module in dotnet iffe
// we want to have same instance of MONO, BINDING and Module in dotnet iife
set_imports_exports(imports, exports);
set_legacy_exports(exports);
init_polyfills(replacements);
Expand Down
4 changes: 2 additions & 2 deletions src/mono/wasm/runtime/logging.ts
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
//! Licensed to the .NET Foundation under one or more agreements.
//! The .NET Foundation licenses this file to you under the MIT license.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import BuildConfiguration from "consts:configuration";
import { INTERNAL, Module, runtimeHelpers } from "./imports";
Expand Down
4 changes: 0 additions & 4 deletions src/mono/wasm/runtime/run-outer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,10 +22,6 @@ export interface DotnetHostBuilder {
run(): Promise<number>
}

// these constants duplicate detection inside emscripten internals, but happen earlier
const ENVIRONMENT_IS_WEB = typeof window == "object";
const ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string";

class HostBuilder implements DotnetHostBuilder {
private instance?: RuntimeAPI;
private applicationArguments?: string[];
Expand Down
3 changes: 3 additions & 0 deletions src/mono/wasm/runtime/types/consts.d.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,3 +17,6 @@ declare module "consts:monoDiagnosticsMock" {
const constant: boolean;
export default constant;
}

declare const ENVIRONMENT_IS_NODE: boolean;
declare const ENVIRONMENT_IS_WEB: boolean;
6 changes: 5 additions & 1 deletion src/mono/wasm/wasm.proj
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,8 @@
<_EmccCompileRspPath>$(NativeBinDir)src\emcc-compile.rsp</_EmccCompileRspPath>
<_EmccLinkRspPath>$(NativeBinDir)src\emcc-link.rsp</_EmccLinkRspPath>
<WasmNativeStrip Condition="'$(ContinuousIntegrationBuild)' == 'true'">false</WasmNativeStrip>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == '' and '$(Configuration)' == 'Release'">SIMPLE_OPTIMIZATIONS</WasmMinifyJsLevel>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == ''">NONE</WasmMinifyJsLevel>
</PropertyGroup>

<Target Name="CheckEnv">
Expand DownExpand Up@@ -254,10 +256,12 @@
<PInvokeTableFile>$(ArtifactsObjDir)wasm/pinvoke-table.h</PInvokeTableFile>
<InterpToNativeTableFile>$(ArtifactsObjDir)wasm/wasm_m2n_invoke.g.h</InterpToNativeTableFile>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Debug'">-g -Os -s -DDEBUG=1 -DENABLE_AOT_PROFILER=1 -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Release'">-Oz -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Release'">-Oz -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>

<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Debug'" >$(CMakeConfigurationEmccFlags)</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Release'">-O2</CMakeConfigurationLinkFlags>

<CMakeConfigurationLinkFlags Condition="'$(WasmMinifyJsLevel)' != 'NONE'">$(CMakeConfigurationLinkFlags) --closure 1 --closure-args=--compilation_level=$(WasmMinifyJsLevel)</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags>$(CMakeConfigurationLinkFlags) -s EXPORT_ES6=1</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(MonoWasmThreads)' == 'true'">$(CMakeConfigurationLinkFlags) -Wno-pthreads-mem-growth</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags >$(CMakeConfigurationLinkFlags) --emit-symbol-map</CMakeConfigurationLinkFlags>
Expand Down
15 changes: 8 additions & 7 deletions src/native/libs/System.Native/pal_random.lib.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,11 +3,12 @@

const DotNetEntropyLib = {
$DOTNETENTROPY: {
// batchedQuotaMax is the max number of bytes as specified by the api spec.
// If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm.
// https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
batchedQuotaMax: 65536,
getBatchedRandomValues: function (buffer, bufferLength) {
// batchedQuotaMax is the max number of bytes as specified by the api spec.
// If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm.
// https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
const batchedQuotaMax = 65536;

// Chrome doesn't want SharedArrayBuffer to be passed to crypto APIs
const needTempBuf = typeof SharedArrayBuffer !== 'undefined' && Module.HEAPU8.buffer instanceof SharedArrayBuffer;
// if we need a temporary buffer, make one that is big enough and write into it from the beginning
Expand All@@ -16,14 +17,14 @@ const DotNetEntropyLib = {
const offset = needTempBuf ? 0 : buffer;
// for modern web browsers
// map the work array to the memory buffer passed with the length
for (let i = 0; i < bufferLength; i += this.batchedQuotaMax) {
const view = new Uint8Array(buf, offset + i, Math.min(bufferLength - i, this.batchedQuotaMax));
for (let i = 0; i < bufferLength; i += batchedQuotaMax) {
const view = new Uint8Array(buf, offset + i, Math.min(bufferLength - i, batchedQuotaMax));
crypto.getRandomValues(view)
}
if (needTempBuf) {
// copy data out of the temporary buffer into the wasm instance memory
const heapView = new Uint8Array(Module.HEAPU8.buffer, buffer, bufferLength);
heapView.set(new Uint8Array(buf));
heapView.set(new Uint8Array(buf));
}
}
},
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [draft][browser] enable closure compiler for dotnet.js by pavelsavara · Pull Request #80178 · dotnet/runtime · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/mono/wasm/build/WasmApp.Native.targets
Original file line numberDiff line numberDiff line change
Expand Up@@ -156,6 +156,8 @@
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == '' and '$(Configuration)' == 'Debug' and '$(WasmBuildingForNestedPublish)' != 'true'">false</WasmNativeStrip>
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == ''">true</WasmNativeStrip>
<WasmNativeDebugSymbols Condition="'$(WasmNativeDebugSymbols)' == ''">true</WasmNativeDebugSymbols>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == '' and '$(Configuration)' == 'Release'">SIMPLE_OPTIMIZATIONS</WasmMinifyJsLevel>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == ''">NONE</WasmMinifyJsLevel>
<WasmLinkIcalls Condition="'$(WasmLinkIcalls)' == ''">$(WasmBuildNative)</WasmLinkIcalls>

<_WasmICallTablePath>$(_WasmIntermediateOutputPath)icall-table.h</_WasmICallTablePath>
Expand DownExpand Up@@ -232,6 +234,9 @@
<_EmccLDFlags Include="@(_EmccCommonFlags)" />
<_EmccLDSFlags Include="-Wl,--allow-undefined" />
<_EmccLDSFlags Include="-s INITIAL_MEMORY=$(EmccInitialHeapSize)" />
<_EmccLDSFlags Condition="'$(WasmNativeStrip)' != 'false' and '$(WasmMinifyJsLevel)' != 'NONE'" Include="--closure 1" />
<_EmccLDSFlags Condition="'$(WasmNativeStrip)' != 'false' and '$(WasmMinifyJsLevel)' != 'NONE'" Include="--closure-args=--compilation_level=$(WasmMinifyJsLevel)" />


<!-- ILLinker should have removed unused imports, so error for Publish -->
<_EmccLDSFlags Include="-s ERROR_ON_UNDEFINED_SYMBOLS=0" Condition="'$(WasmBuildingForNestedPublish)' != 'true'" />
Expand Down
1 change: 1 addition & 0 deletions src/mono/wasm/build/WasmApp.targets
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,6 +24,7 @@
- $(WasmNativeDebugSymbols) - Build with native debug symbols, useful only with `$(RunAOTCompilation)`, or `$(WasmBuildNative)`
Defaults to true.
- $(WasmEmitSymbolMap) - Generates a `dotnet.js.symbols` file with a map of wasm function number to name.
- $(WasmMinifyJsLevel) - Use closure compiler to minify dotnet.js after linking. Default:`SIMPLE_OPTIMIZATIONS`. Other option is `NONE`.
- $(WasmDedup) - Whenever to dedup generic instances when using AOT. Defaults to true.

- $(WasmProfilers) - Profilers to use
Expand Down
5 changes: 5 additions & 0 deletions src/mono/wasm/runtime/es6/dotnet.es6.extpost.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
const ENVIRONMENT_IS_WEB = typeof window == "object";
const ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string";
const MONO = {}, BINDING = {}, INTERNAL = {}, IMPORTS = {};
var fetch = fetch || undefined; var require = require || undefined; var __dirname = __dirname || '';
__dotnet_runtime.__setEmscriptenEntrypoint(createDotnetRuntime);
const __initializeImportsAndExports = __dotnet_runtime.__initializeImportsAndExports;
const __requirePromise = ENVIRONMENT_IS_NODE ? import(/* webpackIgnore: true */'module').then(mod => mod.createRequire(import.meta.url)) : undefined;
const dotnet = __dotnet_runtime.moduleExports.dotnet;
const exit = __dotnet_runtime.moduleExports.exit;
export { dotnet, exit, INTERNAL };
32 changes: 16 additions & 16 deletions src/mono/wasm/runtime/es6/dotnet.es6.lib.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,16 +5,16 @@
"use strict";

#if USE_PTHREADS
const usePThreads = `true`;
const usePThreads = true;
const isPThread = `ENVIRONMENT_IS_PTHREAD`;
#else
const usePThreads = `false`;
const usePThreads = false;
const isPThread = `false`;
Comment thread
ilonatommy marked this conversation as resolved.
#endif

const DotnetSupportLib = {
$DOTNET: {},
// this line will be placed early on emscripten runtime creation, passing import and export objects into __dotnet_runtime IFFE
// this line will be placed early on emscripten runtime creation, passing import and export objects into __dotnet_runtime IIFE
// Emscripten uses require function for nodeJS even in ES6 module. We need https://nodejs.org/api/module.html#modulecreaterequirefilename
// We use dynamic import because there is no "module" module in the browser.
// This is async init of it, note it would become available only after first tick.
Expand All@@ -23,33 +23,33 @@ const DotnetSupportLib = {
// We also replace implementation of fetch
$DOTNET__postset: `
let __dotnet_replacement_PThread = ${usePThreads} ? {} : undefined;
if (${usePThreads}) {
__dotnet_replacement_PThread.loadWasmModuleToWorker = PThread.loadWasmModuleToWorker;
__dotnet_replacement_PThread.threadInitTLS = PThread.threadInitTLS;
__dotnet_replacement_PThread.allocateUnusedWorker = PThread.allocateUnusedWorker;
}
${usePThreads ? `
__dotnet_replacement_PThread.loadWasmModuleToWorker = PThread.loadWasmModuleToWorker;
__dotnet_replacement_PThread.threadInitTLS = PThread.threadInitTLS;
__dotnet_replacement_PThread.allocateUnusedWorker = PThread.allocateUnusedWorker;
` : ''}
let __dotnet_replacements = {scriptUrl: import.meta.url, fetch: globalThis.fetch, require, updateGlobalBufferAndViews, pthreadReplacements: __dotnet_replacement_PThread};
if (ENVIRONMENT_IS_NODE) {
__dotnet_replacements.requirePromise = import(/* webpackIgnore: true */'module').then(mod => mod.createRequire(import.meta.url));
__dotnet_replacements.requirePromise = __requirePromise;
}
let __dotnet_exportedAPI = __dotnet_runtime.__initializeImportsAndExports(
let __dotnet_exportedAPI = __initializeImportsAndExports(
{ isGlobal:false, isNode:ENVIRONMENT_IS_NODE, isWorker:ENVIRONMENT_IS_WORKER, isShell:ENVIRONMENT_IS_SHELL, isWeb:ENVIRONMENT_IS_WEB, isPThread:${isPThread}, quit_, ExitStatus, requirePromise:__dotnet_replacements.requirePromise },
{ mono:MONO, binding:BINDING, internal:INTERNAL, module:Module, marshaled_imports: IMPORTS },
__dotnet_replacements, __callbackAPI);
updateGlobalBufferAndViews = __dotnet_replacements.updateGlobalBufferAndViews;
var fetch = __dotnet_replacements.fetch;
fetch = __dotnet_replacements.fetch;
_scriptDir = __dirname = scriptDirectory = __dotnet_replacements.scriptDirectory;
if (ENVIRONMENT_IS_NODE) {
__dotnet_replacements.requirePromise.then(someRequire => {
require = someRequire;
});
}
var noExitRuntime = __dotnet_replacements.noExitRuntime;
if (${usePThreads}) {
PThread.loadWasmModuleToWorker = __dotnet_replacements.pthreadReplacements.loadWasmModuleToWorker;
PThread.threadInitTLS = __dotnet_replacements.pthreadReplacements.threadInitTLS;
PThread.allocateUnusedWorker = __dotnet_replacements.pthreadReplacements.allocateUnusedWorker;
}
${usePThreads ? `
PThread.loadWasmModuleToWorker = __dotnet_replacements.pthreadReplacements.loadWasmModuleToWorker;
PThread.threadInitTLS = __dotnet_replacements.pthreadReplacements.threadInitTLS;
PThread.allocateUnusedWorker = __dotnet_replacements.pthreadReplacements.allocateUnusedWorker;
` : ''}
`,
};

Expand Down
2 changes: 0 additions & 2 deletions src/mono/wasm/runtime/es6/dotnet.es6.pre.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
var require = require || undefined;
var __dirname = __dirname || '';
var __callbackAPI = { MONO, BINDING, INTERNAL, IMPORTS };
if (typeof createDotnetRuntime === "function") {
__callbackAPI.Module = Module = { ready: Module.ready };
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/runtime/exports.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,7 @@ function initializeImportsAndExports(
const module = exports.module as DotnetModule;
const globalThisAny = globalThis as any;

// we want to have same instance of MONO, BINDING and Module in dotnet iffe
// we want to have same instance of MONO, BINDING and Module in dotnet iife
set_imports_exports(imports, exports);
set_legacy_exports(exports);
init_polyfills(replacements);
Expand Down
4 changes: 2 additions & 2 deletions src/mono/wasm/runtime/logging.ts
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
//! Licensed to the .NET Foundation under one or more agreements.
//! The .NET Foundation licenses this file to you under the MIT license.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import BuildConfiguration from "consts:configuration";
import { INTERNAL, Module, runtimeHelpers } from "./imports";
Expand Down
4 changes: 0 additions & 4 deletions src/mono/wasm/runtime/run-outer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,10 +22,6 @@ export interface DotnetHostBuilder {
run(): Promise<number>
}

// these constants duplicate detection inside emscripten internals, but happen earlier
const ENVIRONMENT_IS_WEB = typeof window == "object";
const ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string";

class HostBuilder implements DotnetHostBuilder {
private instance?: RuntimeAPI;
private applicationArguments?: string[];
Expand Down
3 changes: 3 additions & 0 deletions src/mono/wasm/runtime/types/consts.d.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,3 +17,6 @@ declare module "consts:monoDiagnosticsMock" {
const constant: boolean;
export default constant;
}

declare const ENVIRONMENT_IS_NODE: boolean;
declare const ENVIRONMENT_IS_WEB: boolean;
6 changes: 5 additions & 1 deletion src/mono/wasm/wasm.proj
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,8 @@
<_EmccCompileRspPath>$(NativeBinDir)src\emcc-compile.rsp</_EmccCompileRspPath>
<_EmccLinkRspPath>$(NativeBinDir)src\emcc-link.rsp</_EmccLinkRspPath>
<WasmNativeStrip Condition="'$(ContinuousIntegrationBuild)' == 'true'">false</WasmNativeStrip>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == '' and '$(Configuration)' == 'Release'">SIMPLE_OPTIMIZATIONS</WasmMinifyJsLevel>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == ''">NONE</WasmMinifyJsLevel>
</PropertyGroup>

<Target Name="CheckEnv">
Expand DownExpand Up@@ -254,10 +256,12 @@
<PInvokeTableFile>$(ArtifactsObjDir)wasm/pinvoke-table.h</PInvokeTableFile>
<InterpToNativeTableFile>$(ArtifactsObjDir)wasm/wasm_m2n_invoke.g.h</InterpToNativeTableFile>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Debug'">-g -Os -s -DDEBUG=1 -DENABLE_AOT_PROFILER=1 -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Release'">-Oz -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Release'">-Oz -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>

<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Debug'" >$(CMakeConfigurationEmccFlags)</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Release'">-O2</CMakeConfigurationLinkFlags>

<CMakeConfigurationLinkFlags Condition="'$(WasmMinifyJsLevel)' != 'NONE'">$(CMakeConfigurationLinkFlags) --closure 1 --closure-args=--compilation_level=$(WasmMinifyJsLevel)</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags>$(CMakeConfigurationLinkFlags) -s EXPORT_ES6=1</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(MonoWasmThreads)' == 'true'">$(CMakeConfigurationLinkFlags) -Wno-pthreads-mem-growth</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags >$(CMakeConfigurationLinkFlags) --emit-symbol-map</CMakeConfigurationLinkFlags>
Expand Down
15 changes: 8 additions & 7 deletions src/native/libs/System.Native/pal_random.lib.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,11 +3,12 @@

const DotNetEntropyLib = {
$DOTNETENTROPY: {
// batchedQuotaMax is the max number of bytes as specified by the api spec.
// If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm.
// https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
batchedQuotaMax: 65536,
getBatchedRandomValues: function (buffer, bufferLength) {
// batchedQuotaMax is the max number of bytes as specified by the api spec.
// If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm.
// https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
const batchedQuotaMax = 65536;

// Chrome doesn't want SharedArrayBuffer to be passed to crypto APIs
const needTempBuf = typeof SharedArrayBuffer !== 'undefined' && Module.HEAPU8.buffer instanceof SharedArrayBuffer;
// if we need a temporary buffer, make one that is big enough and write into it from the beginning
Expand All@@ -16,14 +17,14 @@ const DotNetEntropyLib = {
const offset = needTempBuf ? 0 : buffer;
// for modern web browsers
// map the work array to the memory buffer passed with the length
for (let i = 0; i < bufferLength; i += this.batchedQuotaMax) {
const view = new Uint8Array(buf, offset + i, Math.min(bufferLength - i, this.batchedQuotaMax));
for (let i = 0; i < bufferLength; i += batchedQuotaMax) {
const view = new Uint8Array(buf, offset + i, Math.min(bufferLength - i, batchedQuotaMax));
crypto.getRandomValues(view)
}
if (needTempBuf) {
// copy data out of the temporary buffer into the wasm instance memory
const heapView = new Uint8Array(Module.HEAPU8.buffer, buffer, bufferLength);
heapView.set(new Uint8Array(buf));
heapView.set(new Uint8Array(buf));
}
}
},
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [draft][browser] enable closure compiler for dotnet.js by pavelsavara · Pull Request #80178 · dotnet/runtime · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/mono/wasm/build/WasmApp.Native.targets
Original file line numberDiff line numberDiff line change
Expand Up@@ -156,6 +156,8 @@
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == '' and '$(Configuration)' == 'Debug' and '$(WasmBuildingForNestedPublish)' != 'true'">false</WasmNativeStrip>
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == ''">true</WasmNativeStrip>
<WasmNativeDebugSymbols Condition="'$(WasmNativeDebugSymbols)' == ''">true</WasmNativeDebugSymbols>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == '' and '$(Configuration)' == 'Release'">SIMPLE_OPTIMIZATIONS</WasmMinifyJsLevel>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == ''">NONE</WasmMinifyJsLevel>
<WasmLinkIcalls Condition="'$(WasmLinkIcalls)' == ''">$(WasmBuildNative)</WasmLinkIcalls>

<_WasmICallTablePath>$(_WasmIntermediateOutputPath)icall-table.h</_WasmICallTablePath>
Expand DownExpand Up@@ -232,6 +234,9 @@
<_EmccLDFlags Include="@(_EmccCommonFlags)" />
<_EmccLDSFlags Include="-Wl,--allow-undefined" />
<_EmccLDSFlags Include="-s INITIAL_MEMORY=$(EmccInitialHeapSize)" />
<_EmccLDSFlags Condition="'$(WasmNativeStrip)' != 'false' and '$(WasmMinifyJsLevel)' != 'NONE'" Include="--closure 1" />
<_EmccLDSFlags Condition="'$(WasmNativeStrip)' != 'false' and '$(WasmMinifyJsLevel)' != 'NONE'" Include="--closure-args=--compilation_level=$(WasmMinifyJsLevel)" />


<!-- ILLinker should have removed unused imports, so error for Publish -->
<_EmccLDSFlags Include="-s ERROR_ON_UNDEFINED_SYMBOLS=0" Condition="'$(WasmBuildingForNestedPublish)' != 'true'" />
Expand Down
1 change: 1 addition & 0 deletions src/mono/wasm/build/WasmApp.targets
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,6 +24,7 @@
- $(WasmNativeDebugSymbols) - Build with native debug symbols, useful only with `$(RunAOTCompilation)`, or `$(WasmBuildNative)`
Defaults to true.
- $(WasmEmitSymbolMap) - Generates a `dotnet.js.symbols` file with a map of wasm function number to name.
- $(WasmMinifyJsLevel) - Use closure compiler to minify dotnet.js after linking. Default:`SIMPLE_OPTIMIZATIONS`. Other option is `NONE`.
- $(WasmDedup) - Whenever to dedup generic instances when using AOT. Defaults to true.

- $(WasmProfilers) - Profilers to use
Expand Down
5 changes: 5 additions & 0 deletions src/mono/wasm/runtime/es6/dotnet.es6.extpost.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
const ENVIRONMENT_IS_WEB = typeof window == "object";
const ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string";
const MONO = {}, BINDING = {}, INTERNAL = {}, IMPORTS = {};
var fetch = fetch || undefined; var require = require || undefined; var __dirname = __dirname || '';
__dotnet_runtime.__setEmscriptenEntrypoint(createDotnetRuntime);
const __initializeImportsAndExports = __dotnet_runtime.__initializeImportsAndExports;
const __requirePromise = ENVIRONMENT_IS_NODE ? import(/* webpackIgnore: true */'module').then(mod => mod.createRequire(import.meta.url)) : undefined;
const dotnet = __dotnet_runtime.moduleExports.dotnet;
const exit = __dotnet_runtime.moduleExports.exit;
export { dotnet, exit, INTERNAL };
32 changes: 16 additions & 16 deletions src/mono/wasm/runtime/es6/dotnet.es6.lib.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,16 +5,16 @@
"use strict";

#if USE_PTHREADS
const usePThreads = `true`;
const usePThreads = true;
const isPThread = `ENVIRONMENT_IS_PTHREAD`;
#else
const usePThreads = `false`;
const usePThreads = false;
const isPThread = `false`;
Comment thread
ilonatommy marked this conversation as resolved.
#endif

const DotnetSupportLib = {
$DOTNET: {},
// this line will be placed early on emscripten runtime creation, passing import and export objects into __dotnet_runtime IFFE
// this line will be placed early on emscripten runtime creation, passing import and export objects into __dotnet_runtime IIFE
// Emscripten uses require function for nodeJS even in ES6 module. We need https://nodejs.org/api/module.html#modulecreaterequirefilename
// We use dynamic import because there is no "module" module in the browser.
// This is async init of it, note it would become available only after first tick.
Expand All@@ -23,33 +23,33 @@ const DotnetSupportLib = {
// We also replace implementation of fetch
$DOTNET__postset: `
let __dotnet_replacement_PThread = ${usePThreads} ? {} : undefined;
if (${usePThreads}) {
__dotnet_replacement_PThread.loadWasmModuleToWorker = PThread.loadWasmModuleToWorker;
__dotnet_replacement_PThread.threadInitTLS = PThread.threadInitTLS;
__dotnet_replacement_PThread.allocateUnusedWorker = PThread.allocateUnusedWorker;
}
${usePThreads ? `
__dotnet_replacement_PThread.loadWasmModuleToWorker = PThread.loadWasmModuleToWorker;
__dotnet_replacement_PThread.threadInitTLS = PThread.threadInitTLS;
__dotnet_replacement_PThread.allocateUnusedWorker = PThread.allocateUnusedWorker;
` : ''}
let __dotnet_replacements = {scriptUrl: import.meta.url, fetch: globalThis.fetch, require, updateGlobalBufferAndViews, pthreadReplacements: __dotnet_replacement_PThread};
if (ENVIRONMENT_IS_NODE) {
__dotnet_replacements.requirePromise = import(/* webpackIgnore: true */'module').then(mod => mod.createRequire(import.meta.url));
__dotnet_replacements.requirePromise = __requirePromise;
}
let __dotnet_exportedAPI = __dotnet_runtime.__initializeImportsAndExports(
let __dotnet_exportedAPI = __initializeImportsAndExports(
{ isGlobal:false, isNode:ENVIRONMENT_IS_NODE, isWorker:ENVIRONMENT_IS_WORKER, isShell:ENVIRONMENT_IS_SHELL, isWeb:ENVIRONMENT_IS_WEB, isPThread:${isPThread}, quit_, ExitStatus, requirePromise:__dotnet_replacements.requirePromise },
{ mono:MONO, binding:BINDING, internal:INTERNAL, module:Module, marshaled_imports: IMPORTS },
__dotnet_replacements, __callbackAPI);
updateGlobalBufferAndViews = __dotnet_replacements.updateGlobalBufferAndViews;
var fetch = __dotnet_replacements.fetch;
fetch = __dotnet_replacements.fetch;
_scriptDir = __dirname = scriptDirectory = __dotnet_replacements.scriptDirectory;
if (ENVIRONMENT_IS_NODE) {
__dotnet_replacements.requirePromise.then(someRequire => {
require = someRequire;
});
}
var noExitRuntime = __dotnet_replacements.noExitRuntime;
if (${usePThreads}) {
PThread.loadWasmModuleToWorker = __dotnet_replacements.pthreadReplacements.loadWasmModuleToWorker;
PThread.threadInitTLS = __dotnet_replacements.pthreadReplacements.threadInitTLS;
PThread.allocateUnusedWorker = __dotnet_replacements.pthreadReplacements.allocateUnusedWorker;
}
${usePThreads ? `
PThread.loadWasmModuleToWorker = __dotnet_replacements.pthreadReplacements.loadWasmModuleToWorker;
PThread.threadInitTLS = __dotnet_replacements.pthreadReplacements.threadInitTLS;
PThread.allocateUnusedWorker = __dotnet_replacements.pthreadReplacements.allocateUnusedWorker;
` : ''}
`,
};

Expand Down
2 changes: 0 additions & 2 deletions src/mono/wasm/runtime/es6/dotnet.es6.pre.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
var require = require || undefined;
var __dirname = __dirname || '';
var __callbackAPI = { MONO, BINDING, INTERNAL, IMPORTS };
if (typeof createDotnetRuntime === "function") {
__callbackAPI.Module = Module = { ready: Module.ready };
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/runtime/exports.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,7 @@ function initializeImportsAndExports(
const module = exports.module as DotnetModule;
const globalThisAny = globalThis as any;

// we want to have same instance of MONO, BINDING and Module in dotnet iffe
// we want to have same instance of MONO, BINDING and Module in dotnet iife
set_imports_exports(imports, exports);
set_legacy_exports(exports);
init_polyfills(replacements);
Expand Down
4 changes: 2 additions & 2 deletions src/mono/wasm/runtime/logging.ts
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
//! Licensed to the .NET Foundation under one or more agreements.
//! The .NET Foundation licenses this file to you under the MIT license.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import BuildConfiguration from "consts:configuration";
import { INTERNAL, Module, runtimeHelpers } from "./imports";
Expand Down
4 changes: 0 additions & 4 deletions src/mono/wasm/runtime/run-outer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,10 +22,6 @@ export interface DotnetHostBuilder {
run(): Promise<number>
}

// these constants duplicate detection inside emscripten internals, but happen earlier
const ENVIRONMENT_IS_WEB = typeof window == "object";
const ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string";

class HostBuilder implements DotnetHostBuilder {
private instance?: RuntimeAPI;
private applicationArguments?: string[];
Expand Down
3 changes: 3 additions & 0 deletions src/mono/wasm/runtime/types/consts.d.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,3 +17,6 @@ declare module "consts:monoDiagnosticsMock" {
const constant: boolean;
export default constant;
}

declare const ENVIRONMENT_IS_NODE: boolean;
declare const ENVIRONMENT_IS_WEB: boolean;
6 changes: 5 additions & 1 deletion src/mono/wasm/wasm.proj
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,8 @@
<_EmccCompileRspPath>$(NativeBinDir)src\emcc-compile.rsp</_EmccCompileRspPath>
<_EmccLinkRspPath>$(NativeBinDir)src\emcc-link.rsp</_EmccLinkRspPath>
<WasmNativeStrip Condition="'$(ContinuousIntegrationBuild)' == 'true'">false</WasmNativeStrip>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == '' and '$(Configuration)' == 'Release'">SIMPLE_OPTIMIZATIONS</WasmMinifyJsLevel>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == ''">NONE</WasmMinifyJsLevel>
</PropertyGroup>

<Target Name="CheckEnv">
Expand DownExpand Up@@ -254,10 +256,12 @@
<PInvokeTableFile>$(ArtifactsObjDir)wasm/pinvoke-table.h</PInvokeTableFile>
<InterpToNativeTableFile>$(ArtifactsObjDir)wasm/wasm_m2n_invoke.g.h</InterpToNativeTableFile>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Debug'">-g -Os -s -DDEBUG=1 -DENABLE_AOT_PROFILER=1 -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Release'">-Oz -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Release'">-Oz -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>

<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Debug'" >$(CMakeConfigurationEmccFlags)</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Release'">-O2</CMakeConfigurationLinkFlags>

<CMakeConfigurationLinkFlags Condition="'$(WasmMinifyJsLevel)' != 'NONE'">$(CMakeConfigurationLinkFlags) --closure 1 --closure-args=--compilation_level=$(WasmMinifyJsLevel)</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags>$(CMakeConfigurationLinkFlags) -s EXPORT_ES6=1</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(MonoWasmThreads)' == 'true'">$(CMakeConfigurationLinkFlags) -Wno-pthreads-mem-growth</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags >$(CMakeConfigurationLinkFlags) --emit-symbol-map</CMakeConfigurationLinkFlags>
Expand Down
15 changes: 8 additions & 7 deletions src/native/libs/System.Native/pal_random.lib.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,11 +3,12 @@

const DotNetEntropyLib = {
$DOTNETENTROPY: {
// batchedQuotaMax is the max number of bytes as specified by the api spec.
// If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm.
// https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
batchedQuotaMax: 65536,
getBatchedRandomValues: function (buffer, bufferLength) {
// batchedQuotaMax is the max number of bytes as specified by the api spec.
// If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm.
// https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
const batchedQuotaMax = 65536;

// Chrome doesn't want SharedArrayBuffer to be passed to crypto APIs
const needTempBuf = typeof SharedArrayBuffer !== 'undefined' && Module.HEAPU8.buffer instanceof SharedArrayBuffer;
// if we need a temporary buffer, make one that is big enough and write into it from the beginning
Expand All@@ -16,14 +17,14 @@ const DotNetEntropyLib = {
const offset = needTempBuf ? 0 : buffer;
// for modern web browsers
// map the work array to the memory buffer passed with the length
for (let i = 0; i < bufferLength; i += this.batchedQuotaMax) {
const view = new Uint8Array(buf, offset + i, Math.min(bufferLength - i, this.batchedQuotaMax));
for (let i = 0; i < bufferLength; i += batchedQuotaMax) {
const view = new Uint8Array(buf, offset + i, Math.min(bufferLength - i, batchedQuotaMax));
crypto.getRandomValues(view)
}
if (needTempBuf) {
// copy data out of the temporary buffer into the wasm instance memory
const heapView = new Uint8Array(Module.HEAPU8.buffer, buffer, bufferLength);
heapView.set(new Uint8Array(buf));
heapView.set(new Uint8Array(buf));
}
}
},
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); [draft][browser] enable closure compiler for dotnet.js by pavelsavara · Pull Request #80178 · dotnet/runtime · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/mono/wasm/build/WasmApp.Native.targets
Original file line numberDiff line numberDiff line change
Expand Up@@ -156,6 +156,8 @@
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == '' and '$(Configuration)' == 'Debug' and '$(WasmBuildingForNestedPublish)' != 'true'">false</WasmNativeStrip>
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == ''">true</WasmNativeStrip>
<WasmNativeDebugSymbols Condition="'$(WasmNativeDebugSymbols)' == ''">true</WasmNativeDebugSymbols>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == '' and '$(Configuration)' == 'Release'">SIMPLE_OPTIMIZATIONS</WasmMinifyJsLevel>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == ''">NONE</WasmMinifyJsLevel>
<WasmLinkIcalls Condition="'$(WasmLinkIcalls)' == ''">$(WasmBuildNative)</WasmLinkIcalls>

<_WasmICallTablePath>$(_WasmIntermediateOutputPath)icall-table.h</_WasmICallTablePath>
Expand DownExpand Up@@ -232,6 +234,9 @@
<_EmccLDFlags Include="@(_EmccCommonFlags)" />
<_EmccLDSFlags Include="-Wl,--allow-undefined" />
<_EmccLDSFlags Include="-s INITIAL_MEMORY=$(EmccInitialHeapSize)" />
<_EmccLDSFlags Condition="'$(WasmNativeStrip)' != 'false' and '$(WasmMinifyJsLevel)' != 'NONE'" Include="--closure 1" />
<_EmccLDSFlags Condition="'$(WasmNativeStrip)' != 'false' and '$(WasmMinifyJsLevel)' != 'NONE'" Include="--closure-args=--compilation_level=$(WasmMinifyJsLevel)" />


<!-- ILLinker should have removed unused imports, so error for Publish -->
<_EmccLDSFlags Include="-s ERROR_ON_UNDEFINED_SYMBOLS=0" Condition="'$(WasmBuildingForNestedPublish)' != 'true'" />
Expand Down
1 change: 1 addition & 0 deletions src/mono/wasm/build/WasmApp.targets
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,6 +24,7 @@
- $(WasmNativeDebugSymbols) - Build with native debug symbols, useful only with `$(RunAOTCompilation)`, or `$(WasmBuildNative)`
Defaults to true.
- $(WasmEmitSymbolMap) - Generates a `dotnet.js.symbols` file with a map of wasm function number to name.
- $(WasmMinifyJsLevel) - Use closure compiler to minify dotnet.js after linking. Default:`SIMPLE_OPTIMIZATIONS`. Other option is `NONE`.
- $(WasmDedup) - Whenever to dedup generic instances when using AOT. Defaults to true.

- $(WasmProfilers) - Profilers to use
Expand Down
5 changes: 5 additions & 0 deletions src/mono/wasm/runtime/es6/dotnet.es6.extpost.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
const ENVIRONMENT_IS_WEB = typeof window == "object";
const ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string";
const MONO = {}, BINDING = {}, INTERNAL = {}, IMPORTS = {};
var fetch = fetch || undefined; var require = require || undefined; var __dirname = __dirname || '';
__dotnet_runtime.__setEmscriptenEntrypoint(createDotnetRuntime);
const __initializeImportsAndExports = __dotnet_runtime.__initializeImportsAndExports;
const __requirePromise = ENVIRONMENT_IS_NODE ? import(/* webpackIgnore: true */'module').then(mod => mod.createRequire(import.meta.url)) : undefined;
const dotnet = __dotnet_runtime.moduleExports.dotnet;
const exit = __dotnet_runtime.moduleExports.exit;
export { dotnet, exit, INTERNAL };
32 changes: 16 additions & 16 deletions src/mono/wasm/runtime/es6/dotnet.es6.lib.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,16 +5,16 @@
"use strict";

#if USE_PTHREADS
const usePThreads = `true`;
const usePThreads = true;
const isPThread = `ENVIRONMENT_IS_PTHREAD`;
#else
const usePThreads = `false`;
const usePThreads = false;
const isPThread = `false`;
Comment thread
ilonatommy marked this conversation as resolved.
#endif

const DotnetSupportLib = {
$DOTNET: {},
// this line will be placed early on emscripten runtime creation, passing import and export objects into __dotnet_runtime IFFE
// this line will be placed early on emscripten runtime creation, passing import and export objects into __dotnet_runtime IIFE
// Emscripten uses require function for nodeJS even in ES6 module. We need https://nodejs.org/api/module.html#modulecreaterequirefilename
// We use dynamic import because there is no "module" module in the browser.
// This is async init of it, note it would become available only after first tick.
Expand All@@ -23,33 +23,33 @@ const DotnetSupportLib = {
// We also replace implementation of fetch
$DOTNET__postset: `
let __dotnet_replacement_PThread = ${usePThreads} ? {} : undefined;
if (${usePThreads}) {
__dotnet_replacement_PThread.loadWasmModuleToWorker = PThread.loadWasmModuleToWorker;
__dotnet_replacement_PThread.threadInitTLS = PThread.threadInitTLS;
__dotnet_replacement_PThread.allocateUnusedWorker = PThread.allocateUnusedWorker;
}
${usePThreads ? `
__dotnet_replacement_PThread.loadWasmModuleToWorker = PThread.loadWasmModuleToWorker;
__dotnet_replacement_PThread.threadInitTLS = PThread.threadInitTLS;
__dotnet_replacement_PThread.allocateUnusedWorker = PThread.allocateUnusedWorker;
` : ''}
let __dotnet_replacements = {scriptUrl: import.meta.url, fetch: globalThis.fetch, require, updateGlobalBufferAndViews, pthreadReplacements: __dotnet_replacement_PThread};
if (ENVIRONMENT_IS_NODE) {
__dotnet_replacements.requirePromise = import(/* webpackIgnore: true */'module').then(mod => mod.createRequire(import.meta.url));
__dotnet_replacements.requirePromise = __requirePromise;
}
let __dotnet_exportedAPI = __dotnet_runtime.__initializeImportsAndExports(
let __dotnet_exportedAPI = __initializeImportsAndExports(
{ isGlobal:false, isNode:ENVIRONMENT_IS_NODE, isWorker:ENVIRONMENT_IS_WORKER, isShell:ENVIRONMENT_IS_SHELL, isWeb:ENVIRONMENT_IS_WEB, isPThread:${isPThread}, quit_, ExitStatus, requirePromise:__dotnet_replacements.requirePromise },
{ mono:MONO, binding:BINDING, internal:INTERNAL, module:Module, marshaled_imports: IMPORTS },
__dotnet_replacements, __callbackAPI);
updateGlobalBufferAndViews = __dotnet_replacements.updateGlobalBufferAndViews;
var fetch = __dotnet_replacements.fetch;
fetch = __dotnet_replacements.fetch;
_scriptDir = __dirname = scriptDirectory = __dotnet_replacements.scriptDirectory;
if (ENVIRONMENT_IS_NODE) {
__dotnet_replacements.requirePromise.then(someRequire => {
require = someRequire;
});
}
var noExitRuntime = __dotnet_replacements.noExitRuntime;
if (${usePThreads}) {
PThread.loadWasmModuleToWorker = __dotnet_replacements.pthreadReplacements.loadWasmModuleToWorker;
PThread.threadInitTLS = __dotnet_replacements.pthreadReplacements.threadInitTLS;
PThread.allocateUnusedWorker = __dotnet_replacements.pthreadReplacements.allocateUnusedWorker;
}
${usePThreads ? `
PThread.loadWasmModuleToWorker = __dotnet_replacements.pthreadReplacements.loadWasmModuleToWorker;
PThread.threadInitTLS = __dotnet_replacements.pthreadReplacements.threadInitTLS;
PThread.allocateUnusedWorker = __dotnet_replacements.pthreadReplacements.allocateUnusedWorker;
` : ''}
`,
};

Expand Down
2 changes: 0 additions & 2 deletions src/mono/wasm/runtime/es6/dotnet.es6.pre.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
var require = require || undefined;
var __dirname = __dirname || '';
var __callbackAPI = { MONO, BINDING, INTERNAL, IMPORTS };
if (typeof createDotnetRuntime === "function") {
__callbackAPI.Module = Module = { ready: Module.ready };
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/runtime/exports.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,7 @@ function initializeImportsAndExports(
const module = exports.module as DotnetModule;
const globalThisAny = globalThis as any;

// we want to have same instance of MONO, BINDING and Module in dotnet iffe
// we want to have same instance of MONO, BINDING and Module in dotnet iife
set_imports_exports(imports, exports);
set_legacy_exports(exports);
init_polyfills(replacements);
Expand Down
4 changes: 2 additions & 2 deletions src/mono/wasm/runtime/logging.ts
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
//! Licensed to the .NET Foundation under one or more agreements.
//! The .NET Foundation licenses this file to you under the MIT license.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import BuildConfiguration from "consts:configuration";
import { INTERNAL, Module, runtimeHelpers } from "./imports";
Expand Down
4 changes: 0 additions & 4 deletions src/mono/wasm/runtime/run-outer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,10 +22,6 @@ export interface DotnetHostBuilder {
run(): Promise<number>
}

// these constants duplicate detection inside emscripten internals, but happen earlier
const ENVIRONMENT_IS_WEB = typeof window == "object";
const ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string";

class HostBuilder implements DotnetHostBuilder {
private instance?: RuntimeAPI;
private applicationArguments?: string[];
Expand Down
3 changes: 3 additions & 0 deletions src/mono/wasm/runtime/types/consts.d.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,3 +17,6 @@ declare module "consts:monoDiagnosticsMock" {
const constant: boolean;
export default constant;
}

declare const ENVIRONMENT_IS_NODE: boolean;
declare const ENVIRONMENT_IS_WEB: boolean;
6 changes: 5 additions & 1 deletion src/mono/wasm/wasm.proj
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,8 @@
<_EmccCompileRspPath>$(NativeBinDir)src\emcc-compile.rsp</_EmccCompileRspPath>
<_EmccLinkRspPath>$(NativeBinDir)src\emcc-link.rsp</_EmccLinkRspPath>
<WasmNativeStrip Condition="'$(ContinuousIntegrationBuild)' == 'true'">false</WasmNativeStrip>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == '' and '$(Configuration)' == 'Release'">SIMPLE_OPTIMIZATIONS</WasmMinifyJsLevel>
<WasmMinifyJsLevel Condition="'$(WasmMinifyJsLevel)' == ''">NONE</WasmMinifyJsLevel>
</PropertyGroup>

<Target Name="CheckEnv">
Expand DownExpand Up@@ -254,10 +256,12 @@
<PInvokeTableFile>$(ArtifactsObjDir)wasm/pinvoke-table.h</PInvokeTableFile>
<InterpToNativeTableFile>$(ArtifactsObjDir)wasm/wasm_m2n_invoke.g.h</InterpToNativeTableFile>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Debug'">-g -Os -s -DDEBUG=1 -DENABLE_AOT_PROFILER=1 -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Release'">-Oz -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Release'">-Oz -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>

<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Debug'" >$(CMakeConfigurationEmccFlags)</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Release'">-O2</CMakeConfigurationLinkFlags>

<CMakeConfigurationLinkFlags Condition="'$(WasmMinifyJsLevel)' != 'NONE'">$(CMakeConfigurationLinkFlags) --closure 1 --closure-args=--compilation_level=$(WasmMinifyJsLevel)</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags>$(CMakeConfigurationLinkFlags) -s EXPORT_ES6=1</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(MonoWasmThreads)' == 'true'">$(CMakeConfigurationLinkFlags) -Wno-pthreads-mem-growth</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags >$(CMakeConfigurationLinkFlags) --emit-symbol-map</CMakeConfigurationLinkFlags>
Expand Down
15 changes: 8 additions & 7 deletions src/native/libs/System.Native/pal_random.lib.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,11 +3,12 @@

const DotNetEntropyLib = {
$DOTNETENTROPY: {
// batchedQuotaMax is the max number of bytes as specified by the api spec.
// If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm.
// https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
batchedQuotaMax: 65536,
getBatchedRandomValues: function (buffer, bufferLength) {
// batchedQuotaMax is the max number of bytes as specified by the api spec.
// If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm.
// https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
const batchedQuotaMax = 65536;

// Chrome doesn't want SharedArrayBuffer to be passed to crypto APIs
const needTempBuf = typeof SharedArrayBuffer !== 'undefined' && Module.HEAPU8.buffer instanceof SharedArrayBuffer;
// if we need a temporary buffer, make one that is big enough and write into it from the beginning
Expand All@@ -16,14 +17,14 @@ const DotNetEntropyLib = {
const offset = needTempBuf ? 0 : buffer;
// for modern web browsers
// map the work array to the memory buffer passed with the length
for (let i = 0; i < bufferLength; i += this.batchedQuotaMax) {
const view = new Uint8Array(buf, offset + i, Math.min(bufferLength - i, this.batchedQuotaMax));
for (let i = 0; i < bufferLength; i += batchedQuotaMax) {
const view = new Uint8Array(buf, offset + i, Math.min(bufferLength - i, batchedQuotaMax));
crypto.getRandomValues(view)
}
if (needTempBuf) {
// copy data out of the temporary buffer into the wasm instance memory
const heapView = new Uint8Array(Module.HEAPU8.buffer, buffer, bufferLength);
heapView.set(new Uint8Array(buf));
heapView.set(new Uint8Array(buf));
}
}
},
Expand Down