Bug Description
Short hand method in object literals (e.g. { foo () {} } are not constructor functions and as such should not have a prototype property nor have a [[Construct]] behavior.
A similar issue was fixed last year for arrow functions in c42491d
Hermes git revision (if applicable): c2f7dcd
React Native version: N/A
OS: Linux
Platform (most likely one of arm64-v8a, armeabi-v7a, x86, x86_64): x86_64
Steps To Reproduce
const hasConstruct = target => {
const proxy = new Proxy(target, {
construct() {
return {};
},
});
try {
new proxy();
return true;
} catch (e) {
return false;
}
};
for (const [name, fn] of [
['function', function () {}],
['short-hand method', { foo() {} }.foo],
['arrow', () => {}],
]) {
print(name, 'hasConstruct', hasConstruct(fn));
print(
name,
'.prototype',
JSON.stringify(Object.getOwnPropertyDescriptor(fn, 'prototype')),
);
}
eshost -s test-has-construct.js
Expected Behavior
#### JavaScriptCore, Moddable XS, SpiderMonkey, V8
function hasConstruct true
function .prototype {"value":{},"writable":true,"enumerable":false,"configurable":false}
short-hand method hasConstruct false
short-hand method .prototype undefined
arrow hasConstruct false
arrow .prototype undefined
Actual Behavior
#### Hermes
function hasConstruct true
function .prototype {"value":{},"writable":true,"enumerable":false,"configurable":false}
short-hand method hasConstruct true
short-hand method .prototype {"value":{},"writable":true,"enumerable":false,"configurable":false}
arrow hasConstruct false
arrow .prototype undefined
Bug Description
Short hand method in object literals (e.g.
{ foo () {} }are not constructor functions and as such should not have aprototypeproperty nor have a[[Construct]]behavior.A similar issue was fixed last year for arrow functions in c42491d
gradle cleanand confirmed this bug does not occur with JSCHermes git revision (if applicable): c2f7dcd
React Native version: N/A
OS: Linux
Platform (most likely one of arm64-v8a, armeabi-v7a, x86, x86_64): x86_64
Steps To Reproduce
eshost -s test-has-construct.jsExpected Behavior
Actual Behavior