ChakraCore icon indicating copy to clipboard operation
ChakraCore copied to clipboard

Function.name property is non-writable. It should be initialized as such.

Open rajatd opened this issue 10 years ago • 7 comments

SimplePropertyDescriptor const JavascriptLibrary::SharedFunctionPropertyDescriptors[2] = { SimplePropertyDescriptor(BuiltInPropertyRecords::prototype, PropertyWritable), SimplePropertyDescriptor(BuiltInPropertyRecords::name, PropertyConfigurable | PropertyWritable) };

rajatd avatar Jan 20 '16 20:01 rajatd

this line also needs to be changed: SimpleTypeHandler<1> JavascriptLibrary::SharedFunctionWithoutPrototypeTypeHandler(BuiltInPropertyRecords::name, PropertyConfigurable | PropertyWritable);

And probably clarify that this effects built in function names so creating a test case is easier.

farzonl avatar Jan 21 '16 06:01 farzonl

Yes you are right, that needs to be changed as well. I'll look into the existing test case to see what kind of coverage we have there and how can I augment that.

rajatd avatar Jan 21 '16 06:01 rajatd

Oh btw, you are welcome to make the change ;)

rajatd avatar Jan 21 '16 06:01 rajatd

@farzonl doooooo it :P

ianwjhalliday avatar Jan 21 '16 08:01 ianwjhalliday

Hi, I am not able to reproduce this on current master. My test case is as follows:

var x =[];
print(x.slice.name); // prints slice
x.slice.name = "hello";
print(x.slice.name); // prints slice

Am I doing something wrong?

ngsankha avatar Jan 21 '16 19:01 ngsankha

Ah yes. That's because although we are initializing the name property as writable, when setting the actual name to this property, we set the property attributes as only configurable. So, not a functional bug I guess. But, good to fix as setting attributes different from what were originally there on the property may disable type sharing. For reference, you could see the following code in SimpleTypeHandler<size>::SetPropertyWithAttriutes

 SimpleTypeHandler * typeHandler = this;
                if (GetIsLocked())
                {
#if DBG
                    DynamicType* oldType = instance->GetDynamicType();
#endif
                    typeHandler = this->ConvertToNonSharedSimpleType(instance);
#if DBG
                    Assert(!oldType->GetIsLocked() || instance->GetDynamicType() != oldType);
#endif
                }

rajatd avatar Jan 21 '16 20:01 rajatd

@rajatd I opened PR #170.

ngsankha avatar Jan 22 '16 03:01 ngsankha