Skip to content

Commit f7691ad

Browse files
committed
[MERGE #6064 @akroshg] Fixing class.name issue
Merge pull request #6064 from akroshg:classname When initializing the same class multiple times - we were failed to put the .name on the new function object. That is because we initialize the object by EnsureObjectReady before setting the homeobject. Fixed that by setting the name after setting the homeobject.
2 parents 49a3328 + 923faf0 commit f7691ad

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/Runtime/Library/ScriptFunction.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ using namespace Js;
119119
ScriptFunction* scriptFunc = ScriptFunction::OP_NewScFunc(environment, infoRef);
120120
scriptFunc->SetHomeObj(homeObj);
121121

122+
// After setting homeobject we need to set the name if the object is ready.
123+
if ((*infoRef)->GetFunctionProxy()->GetUndeferredFunctionType())
124+
{
125+
if (!scriptFunc->IsAnonymousFunction() && !scriptFunc->GetFunctionProxy()->EnsureDeserialized()->GetIsStaticNameFunction())
126+
{
127+
JavascriptString * functionName = scriptFunc->GetDisplayNameImpl();
128+
scriptFunc->SetPropertyWithAttributes(PropertyIds::name, functionName, PropertyConfigurable, nullptr);
129+
}
130+
}
131+
122132
return scriptFunc;
123133
JIT_HELPER_END(ScrFunc_OP_NewScFuncHomeObj);
124134
}

test/Bugs/misc_bugs.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,25 @@ var tests = [
258258
var_3 = Promise.prototype.finally.call(var_0, var_1);
259259
assert.throws(() => { new var_2([]).var_3(); },TypeError);
260260
}
261+
},
262+
{
263+
name: "class name should not change if calling multiple times",
264+
body: function () {
265+
function getClass() {
266+
class A {
267+
constructor() {
268+
269+
}
270+
};
271+
return A;
272+
}
273+
let f1 = getClass();
274+
let f2 = getClass();
275+
let f3 = getClass();
276+
assert.areEqual("A", f1.name);
277+
assert.areEqual("A", f2.name);
278+
assert.areEqual("A", f3.name);
279+
}
261280
}
262281

263282
];

0 commit comments

Comments
 (0)