Skip to content
Merged
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
13 changes: 4 additions & 9 deletions src/jsifier.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ function(${args}) {
// what we just added to the library.
}

function addFromLibrary(symbol, dependent, force = false) {
function addFromLibrary(symbol, dependent) {
// don't process any special identifiers. These are looked up when
// processing the base name of the identifier.
if (isDecorator(symbol)) {
Expand All @@ -514,7 +514,7 @@ function(${args}) {

// if the function was implemented in compiled code, there is no need to
// include the js version
if (WASM_EXPORTS.has(symbol) && !force) {
if (WASM_EXPORTS.has(symbol)) {
return;
}

Expand Down Expand Up @@ -639,7 +639,6 @@ function(${args}) {
});

let isFunction = false;
let aliasTarget;

const postsetId = symbol + '__postset';
const postset = LibraryManager.library[postsetId];
Expand All @@ -659,7 +658,7 @@ function(${args}) {
// Redirection for aliases. We include the parent, and at runtime
// make ourselves equal to it. This avoid having duplicate
// functions with identical content.
aliasTarget = snippet;
const aliasTarget = snippet;
snippet = mangleCSymbolName(aliasTarget);
deps.push(aliasTarget);
}
Expand Down Expand Up @@ -690,7 +689,7 @@ function(${args}) {
'noExitRuntime cannot be referenced via __deps mechanism. Use DEFAULT_LIBRARY_FUNCS_TO_INCLUDE or EXPORTED_RUNTIME_METHODS',
);
}
return addFromLibrary(dep, `${symbol}, referenced by ${dependent}`, dep === aliasTarget);
return addFromLibrary(dep, `${symbol}, referenced by ${dependent}`);
}
let contentText;
if (isFunction) {
Expand Down Expand Up @@ -777,10 +776,6 @@ function(${args}) {
}

let commentText = '';
if (force) {
commentText += '/** @suppress {duplicate } */\n';
}

let docs = LibraryManager.library[symbol + '__docs'];
// Add the docs if they exist and if we are actually emitting a declaration.
// See the TODO about wasmTable above.
Expand Down
26 changes: 23 additions & 3 deletions src/lib/libwebgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4346,17 +4346,37 @@ createGLPassthroughFunctions(LibraryGL, glPassthroughFuncs);

autoAddDeps(LibraryGL, '$GL');

function renameSymbol(lib, oldName, newName) {
lib[newName] = lib[oldName];
delete lib[oldName];
for (const suffix of decoratorSuffixes) {
const oldDecorator = oldName + suffix;
if (lib.hasOwnProperty(oldDecorator)) {
const newDecorator = newName + suffix;
lib[newDecorator] = lib[oldDecorator];
delete lib[oldDecorator];
}
}
}

function recordGLProcAddressGet(lib) {
// GL proc address retrieval - allow access through glX and emscripten_glX, to
// allow name collisions with user-implemented things having the same name
// (see gl.c)
//
// We do this by renaming `glX` symbols to `emscripten_glX` and then setting
// `glX` as an alias of `emscripten_glX`. The reason for this renaming is to
// ensure that `emscripten_glX` is always available, even in cases where native
// code defines `glX`.
const glSyms = [];
for (const sym of Object.keys(lib)) {
if (sym.startsWith('gl') && !isDecorator(sym)) {
const alias = 'emscripten_' + sym;
lib[alias] = sym;
const newSym = 'emscripten_' + sym;
renameSymbol(lib, sym, newSym);
lib[sym] = newSym;
var sig = LibraryManager.library[sym + '__sig'];
if (sig) {
lib[alias + '__sig'] = sig;
lib[newSym + '__sig'] = sig;
}
}
}
Expand Down
34 changes: 18 additions & 16 deletions src/utility.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export function mergeInto(obj, other, options = null) {
const deps = other[key];
if (!Array.isArray(deps)) {
error(
`JS library directive ${key}=${deps.toString()} is of type '${type}', but it should be an array`,
`JS library directive ${key}=${deps} is of type '${type}', but it should be an array`,
);
}
for (let dep of deps) {
Expand Down Expand Up @@ -199,22 +199,23 @@ export function isJsOnlySymbol(symbol) {
return symbol[0] == '$';
}

export const decoratorSuffixes = [
'__sig',
'__proxy',
'__asm',
'__deps',
'__postset',
'__docs',
'__nothrow',
'__noleakcheck',
'__internal',
'__user',
'__async',
'__i53abi',
];

export function isDecorator(ident) {
const suffixes = [
'__sig',
'__proxy',
'__asm',
'__deps',
'__postset',
'__docs',
'__nothrow',
'__noleakcheck',
'__internal',
'__user',
'__async',
'__i53abi',
];
return suffixes.some((suffix) => ident.endsWith(suffix));
return decoratorSuffixes.some((suffix) => ident.endsWith(suffix));
}

export function readFile(filename) {
Expand Down Expand Up @@ -330,6 +331,7 @@ export function runInMacroContext(code, options) {

addToCompileTimeContext({
assert,
decoratorSuffixes,
error,
isDecorator,
isJsOnlySymbol,
Expand Down
4 changes: 2 additions & 2 deletions test/codesize/test_codesize_hello_dylink_all.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"a.out.js": 245842,
"a.out.js": 245841,
"a.out.nodebug.wasm": 597755,
"total": 843597,
"total": 843596,
"sent": [
"IMG_Init",
"IMG_Load",
Expand Down
2 changes: 1 addition & 1 deletion test/test_override_system_js_lib_symbol.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if (!LibraryManager.library.glTexImage3D) throw 'This file should be getting processed after library_webgl2.js!';

addToLibrary({
orig_glTexImage3D__deps: LibraryManager.library.glTexImage3D__deps,
orig_glTexImage3D__deps: LibraryManager.library.glTexImage3D__deps || [],
orig_glTexImage3D: LibraryManager.library.glTexImage3D,

glTexImage3D__deps: ['orig_glTexImage3D'],
Expand Down