Skip to content

Commit 923faf0

Browse files
committed
Fixing class.name issue
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.
1 parent 61b8b22 commit 923faf0

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
@@ -233,6 +233,25 @@ var tests = [
233233
var_3 = Promise.prototype.finally.call(var_0, var_1);
234234
assert.throws(() => { new var_2([]).var_3(); },TypeError);
235235
}
236+
},
237+
{
238+
name: "class name should not change if calling multiple times",
239+
body: function () {
240+
function getClass() {
241+
class A {
242+
constructor() {
243+
244+
}
245+
};
246+
return A;
247+
}
248+
let f1 = getClass();
249+
let f2 = getClass();
250+
let f3 = getClass();
251+
assert.areEqual("A", f1.name);
252+
assert.areEqual("A", f2.name);
253+
assert.areEqual("A", f3.name);
254+
}
236255
}
237256

238257
];

0 commit comments

Comments
 (0)