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
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default [{
'require-jsdoc': 'off',
'arrow-body-style': ['error', 'as-needed'],
'space-infix-ops': 'error',
'no-prototype-builtins': 'off',
'prefer-object-has-own': 'error',

quotes: ['error', 'single', {
avoidEscape: true,
Expand Down
4 changes: 2 additions & 2 deletions src/jsifier.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ function(${args}) {
const postset = LibraryManager.library[postsetId];

if (symbolsOnly) {
if (LibraryManager.library.hasOwnProperty(symbol)) {
if (Object.hasOwn(LibraryManager.library, symbol)) {
let snippet = LibraryManager.library[symbol];
if (!LibraryManager.isAlias(snippet)) {
if (typeof snippet === 'object') {
Expand Down Expand Up @@ -831,7 +831,7 @@ function(${args}) {
const mangled = mangleCSymbolName(symbol);
let snippet = LibraryManager.library[symbol];

if (!LibraryManager.library.hasOwnProperty(symbol)) {
if (!Object.hasOwn(LibraryManager.library, symbol)) {
const isWeakImport = WEAK_IMPORTS.has(symbol);
if (!isDefined(symbol) && !isWeakImport) {
if (PROXY_TO_PTHREAD && !MAIN_MODULE && symbol == '__main_argc_argv') {
Expand Down
7 changes: 1 addition & 6 deletions src/lib/libc_preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,7 @@ addToLibrary({
var kind2 = classifyChar(str, j);
if (kind2 != 2/*0-9*/ && kind2 != 3/*a-z*/) {
var symbol = str.substring(i, j);
#if MIN_FIREFOX_VERSION < 92
// Firefox only introduced Object.hasOwn() in Firefox 92.
if (defs.hasOwnProperty(symbol)) {
#else
if (Object.hasOwn(defs, symbol)) {
#endif
if (hasOwn(defs, symbol)) {
var pp = defs[symbol], expanded;
if (typeof pp === 'function') { // definition is a function?
if (pp.length) { // Expanding a macro? (#define FOO(X) ...)
Expand Down
17 changes: 15 additions & 2 deletions src/lib/libcore.js
Original file line number Diff line number Diff line change
Expand Up @@ -1629,11 +1629,24 @@ addToLibrary({
return readEmAsmArgsArray;
},

$hasOwn__internal: true,
#if MIN_FIREFOX_VERSION < 92 || MIN_CHROME_VERSION < 93 || MIN_SAFARI_VERSION < 150400
Comment thread
sbc100 marked this conversation as resolved.
Resolved
// https://caniuse.com/mdn-javascript_builtins_object_hasown
$hasOwn__docs: '/** @noinline */',
$hasOwn: (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop),
#else
// Closure's built-in extern for `Object.hasOwn` is typed as
// `function(!Object, (string|symbol)): boolean`, which rejects nullable
// `Object` types (such as `Module`) and numeric property keys.
$hasOwn__docs: '/** @type {function(?, ?): boolean} */',
$hasOwn: 'Object.hasOwn',
#endif

#if HAVE_EM_ASM
$runEmAsmFunction: (code, sigPtr, argbuf) => {
var args = readEmAsmArgs(sigPtr, argbuf);
#if ASSERTIONS
assert(ASM_CONSTS.hasOwnProperty(code), `No EM_ASM constant found at address ${code}. The loaded WebAssembly file is likely out of sync with the generated JavaScript.`);
assert(hasOwn(ASM_CONSTS, code), `No EM_ASM constant found at address ${code}. The loaded WebAssembly file is likely out of sync with the generated JavaScript.`);
#endif
return ASM_CONSTS[code](...args);
},
Expand Down Expand Up @@ -1666,7 +1679,7 @@ addToLibrary({
}
#endif
#if ASSERTIONS
assert(ASM_CONSTS.hasOwnProperty(emAsmAddr), `No EM_ASM constant found at address ${emAsmAddr}. The loaded WebAssembly file is likely out of sync with the generated JavaScript.`);
assert(hasOwn(ASM_CONSTS, emAsmAddr), `No EM_ASM constant found at address ${emAsmAddr}. The loaded WebAssembly file is likely out of sync with the generated JavaScript.`);
#endif
return ASM_CONSTS[emAsmAddr](...args);
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libdylink.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ var LibraryDylink = {
for (var [sym, exp] of Object.entries(exports)) {
if (sym.startsWith('dynCall_')) {
var sig = sym.substring(8);
if (!dynCalls.hasOwnProperty(sig)) {
if (!hasOwn(dynCalls, sig)) {
dynCalls[sig] = exp;
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/lib/libembind.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var LibraryEmbind = {
// Inject an overload resolver function that routes to the appropriate overload based on the number of arguments.
proto[methodName] = function(...args) {
// TODO This check can be removed in -O3 level "unsafe" optimizations.
if (!proto[methodName].overloadTable.hasOwnProperty(args.length)) {
if (!hasOwn(proto[methodName].overloadTable, args.length)) {
throwBindingError(`Function '${humanName}' called with an invalid number of arguments (${args.length}) - expects one of (${proto[methodName].overloadTable})!`);
}
return proto[methodName].overloadTable[args.length].apply(this, args);
Expand All @@ -83,15 +83,15 @@ var LibraryEmbind = {
actually registered, since it carries a slight performance penalty. */
$exposePublicSymbol__docs: '/** @param {number=} numArguments */',
$exposePublicSymbol: (name, value, numArguments) => {
if (Module.hasOwnProperty(name)) {
if (hasOwn(Module, name)) {
if (undefined === numArguments || (undefined !== Module[name].overloadTable && undefined !== Module[name].overloadTable[numArguments])) {
throwBindingError(`Cannot register public name '${name}' twice`);
}

// We are exposing a function with the same name as an existing function. Create an overload table and a function selector
// that routes between the two.
ensureOverloadTable(Module, name, name);
if (Module[name].overloadTable.hasOwnProperty(numArguments)) {
if (hasOwn(Module[name].overloadTable, numArguments)) {
throwBindingError(`Cannot register multiple overloads of a function with the same number of arguments (${numArguments})!`);
}
// Add the new function into the overload table.
Expand All @@ -104,7 +104,7 @@ var LibraryEmbind = {

$replacePublicSymbol__docs: '/** @param {number=} numArguments */',
$replacePublicSymbol: (name, value, numArguments) => {
if (!Module.hasOwnProperty(name)) {
if (!hasOwn(Module, name)) {
throwInternalError('Replacing nonexistent public symbol');
}
// If there's an overload table for this symbol, replace the symbol in the overload table instead.
Expand Down Expand Up @@ -144,7 +144,7 @@ var LibraryEmbind = {

$registerInheritedInstance: (class_, ptr, instance) => {
ptr = getBasestPointer(class_, ptr);
if (registeredInstances.hasOwnProperty(ptr)) {
if (hasOwn(registeredInstances, ptr)) {
throwBindingError(`Tried to register registered instance: ${ptr}`);
} else {
registeredInstances[ptr] = instance;
Expand All @@ -153,7 +153,7 @@ var LibraryEmbind = {

$unregisterInheritedInstance: (class_, ptr) => {
ptr = getBasestPointer(class_, ptr);
if (registeredInstances.hasOwnProperty(ptr)) {
if (hasOwn(registeredInstances, ptr)) {
delete registeredInstances[ptr];
} else {
throwBindingError(`Tried to unregister unregistered instance: ${ptr}`);
Expand Down Expand Up @@ -1972,7 +1972,7 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence

if (classType.registeredClass.__derivedClasses) {
for (const derivedClass of classType.registeredClass.__derivedClasses) {
if (!derivedClass.constructor.hasOwnProperty(methodName)) {
if (!hasOwn(derivedClass.constructor, methodName)) {
// TODO: Add support for overloads
derivedClass.constructor[methodName] = func;
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib/libembind_shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var LibraryEmbindShared = {
if (!rawType) {
throwBindingError(`type "${name}" must have a positive integer typeid pointer`);
}
if (registeredTypes.hasOwnProperty(rawType)) {
if (hasOwn(registeredTypes, rawType)) {
if (options.ignoreDuplicateRegistrations) {
return;
} else {
Expand All @@ -50,7 +50,7 @@ var LibraryEmbindShared = {
registeredTypes[rawType] = registeredInstance;
delete typeDependencies[rawType];

if (awaitingDependencies.hasOwnProperty(rawType)) {
if (hasOwn(awaitingDependencies, rawType)) {
var callbacks = awaitingDependencies[rawType];
delete awaitingDependencies[rawType];
callbacks.forEach((cb) => cb());
Expand All @@ -74,11 +74,11 @@ var LibraryEmbindShared = {
var unregisteredTypes = [];
var registered = 0;
for (let [i, dt] of dependentTypes.entries()) {
if (registeredTypes.hasOwnProperty(dt)) {
if (hasOwn(registeredTypes, dt)) {
typeConverters[i] = registeredTypes[dt];
} else {
unregisteredTypes.push(dt);
if (!awaitingDependencies.hasOwnProperty(dt)) {
if (!hasOwn(awaitingDependencies, dt)) {
awaitingDependencies[dt] = [];
}
awaitingDependencies[dt].push(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/libglfw.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ var LibraryGLFW = {
if (entriesTree[fullpath].subpaths.length != 0) return;
delete entriesTree[fullpath];
let parentpath = fullpath.substring(0, fullpath.lastIndexOf('/'));
if (!entriesTree.hasOwnProperty(parentpath)) {
if (!hasOwn(entriesTree, parentpath)) {
if (Object.keys(entriesTree).length == 0) finalize();
return;
}
Expand All @@ -905,7 +905,7 @@ var LibraryGLFW = {
if (entry.isFile) {
entry.file((f) => { filesQ.push({ file: f, path: pp }); markDone(fp, false); })
} else if (entry.isDirectory) {
if (entriesTree.hasOwnProperty(pp)) entriesTree[pp].subpaths.push(fp);
if (hasOwn(entriesTree, pp)) entriesTree[pp].subpaths.push(fp);
FS.createPath('/' + drop_dir + pp, entry.name);
var reader = entry.createReader();
var rRead = function (dirEntries) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/liblegacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ legacyFuncs = {
$getLiveInheritedInstances: () => {
var rv = [];
for (var k in registeredInstances) {
if (registeredInstances.hasOwnProperty(k)) {
if (hasOwn(registeredInstances, k)) {
rv.push(registeredInstances[k]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/libsdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3354,7 +3354,7 @@ var LibrarySDL = {
var gamepad = SDL.getGamepad(deviceIndex);
if (gamepad) {
var name = gamepad.id;
if (SDL.joystickNamePool.hasOwnProperty(name)) {
if (hasOwn(SDL.joystickNamePool, name)) {
return SDL.joystickNamePool[name];
}
return SDL.joystickNamePool[name] = stringToNewUTF8(name);
Expand All @@ -3375,7 +3375,7 @@ var LibrarySDL = {
},

SDL_JoystickOpened__proxy: 'sync',
SDL_JoystickOpened: (deviceIndex) => SDL.lastJoystickState.hasOwnProperty(deviceIndex+1) ? 1 : 0,
SDL_JoystickOpened: (deviceIndex) => hasOwn(SDL.lastJoystickState, deviceIndex+1) ? 1 : 0,

// joystick pointers are simply the deviceIndex+1.
SDL_JoystickIndex: (joystick) => joystick - 1,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/libwebgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4200,7 +4200,7 @@ function renameSymbol(lib, oldName, newName) {
delete lib[oldName];
for (const suffix of decoratorSuffixes) {
const oldDecorator = oldName + suffix;
if (lib.hasOwnProperty(oldDecorator)) {
if (Object.hasOwn(lib, oldDecorator)) {
const newDecorator = newName + suffix;
lib[newDecorator] = lib[oldDecorator];
delete lib[oldDecorator];
Expand Down Expand Up @@ -4236,8 +4236,8 @@ function recordGLProcAddressGet(lib) {
// are looked up in LibraryManager.library as well.
for (const [sym, target] of Object.entries(lib)) {
if (sym.startsWith('emscripten_gl') && typeof target === 'string' &&
(lib.hasOwnProperty('emscripten_' + target) ||
LibraryManager.library.hasOwnProperty('emscripten_' + target))) {
(Object.hasOwn(lib, 'emscripten_' + target) ||
Object.hasOwn(LibraryManager.library, 'emscripten_' + target))) {
lib[sym] = 'emscripten_' + target;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export const LibraryManager = {
},

isAlias(entry) {
return (typeof entry === 'string' && entry[0] != '=' && (this.library.hasOwnProperty(entry) || WASM_EXPORTS.has(entry)));
return (typeof entry === 'string' && entry[0] != '=' && (Object.hasOwn(this.library, entry) || WASM_EXPORTS.has(entry)));
},

/**
Expand Down
6 changes: 3 additions & 3 deletions src/utility.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function mergeInto(obj, other, options = null) {
// check for unintended symbol redefinition
if (options.noOverride) {
for (const key of Object.keys(other)) {
if (obj.hasOwnProperty(key)) {
if (Object.hasOwn(obj, key)) {
error(`Symbol re-definition in JavaScript library: ${key}. Do not use noOverride if this is intended`);
return;
}
Expand All @@ -113,7 +113,7 @@ export function mergeInto(obj, other, options = null) {
// check if sig is missing for added functions
if (options.checkSig) {
for (const [key, value] of Object.entries(other)) {
if (typeof value === 'function' && !other.hasOwnProperty(key + '__sig')) {
if (typeof value === 'function' && !Object.hasOwn(other, key + '__sig')) {
error(`__sig is missing for function: ${key}. Do not use checkSig if this is intended`);
return;
}
Expand All @@ -136,7 +136,7 @@ export function mergeInto(obj, other, options = null) {
for (const key of Object.keys(other)) {
if (isDecorator(key)) {
if (key.endsWith('__sig')) {
if (obj.hasOwnProperty(key)) {
if (Object.hasOwn(obj, key)) {
const oldsig = obj[key];
const newsig = other[key];
if (oldsig == newsig) {
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": 272893,
"a.out.js": 272921,
"a.out.nodebug.wasm": 589512,
"total": 862405,
"total": 862433,
"sent": [
"IMG_Init",
"IMG_Load",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.html": 540,
"a.html.gz": 367,
"a.js": 7455,
"a.js.gz": 3399,
"a.js": 7405,
"a.js.gz": 3416,
"a.wasm": 7201,
"a.wasm.gz": 3305,
"total": 15196,
"total_gz": 7071
"total": 15146,
"total_gz": 7088
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.html": 540,
"a.html.gz": 367,
"a.js": 5343,
"a.js.gz": 2500,
"a.js": 5370,
"a.js.gz": 2518,
"a.wasm": 5817,
"a.wasm.gz": 2736,
"total": 11700,
"total_gz": 5603
"total": 11727,
"total_gz": 5621
}
12 changes: 6 additions & 6 deletions test/embind/embind.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -988,15 +988,15 @@ module({
var dummy_overloads = cm.MultipleOverloadsDependingOnDummy.prototype.dummy;
// check if the overloadTable is correctly named
// it can be minimized if using closure compiler
if (dummy_overloads.hasOwnProperty('overloadTable')) {
assert.false(dummy_overloads.overloadTable.hasOwnProperty('undefined'));
if (Object.hasOwn(dummy_overloads, 'overloadTable')) {
assert.false(Object.hasOwn(dummy_overloads.overloadTable, 'undefined'));
}

var dummy_static_overloads = cm.MultipleOverloadsDependingOnDummy.staticDummy;
// check if the overloadTable is correctly named
// it can be minimized if using closure compiler
if (dummy_static_overloads.hasOwnProperty('overloadTable')) {
assert.false(dummy_static_overloads.overloadTable.hasOwnProperty('undefined'));
if (Object.hasOwn(dummy_static_overloads, 'overloadTable')) {
assert.false(Object.hasOwn(dummy_static_overloads.overloadTable, 'undefined'));
}

// this part should fail anyway if there is no overloadTable
Expand All @@ -1016,8 +1016,8 @@ module({
var dummy_free_func = cm.getDummy;
console.log(dummy_free_func);

if (dummy_free_func.hasOwnProperty('overloadTable')) {
assert.false(dummy_free_func.overloadTable.hasOwnProperty('undefined'));
if (Object.hasOwn(dummy_free_func, 'overloadTable')) {
assert.false(Object.hasOwn(dummy_free_func.overloadTable, 'undefined'));
}

var dummy = cm.getDummy();
Expand Down
Loading
Loading