Bug 145460
| Summary: | Make Function.(name|length) configurable | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Yury Selivanov <yselivanov> |
| Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
| Status: | RESOLVED WORKSFORME | ||
| Severity: | Normal | CC: | cdumez, ggaren, gskachkov, mark.lam, yselivanov, zcorpan |
| Priority: | P2 | ||
| Version: | 528+ (Nightly build) | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
Yury Selivanov
This is an important feature for OOP libraries: typically classes are emulated using functions, hence class *static* properties are properties of the function object that represents the class. Since '.name' and '.length' properties are read-only and non-configurable for functions, there is no way to have '.name' and '.length' static properties for classes.
This is something that has already been fixed in Chrome and Firefox:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1084019
- https://chromium.googlesource.com/v8/v8/+/f6cd009efd7a032907b11265e74102b0d45207a1%5E!/
And InternetExplorer doesn't have any restrictions on these properties, which leaves WebKit/Safari the only browser that doesn't support this.
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Yury Selivanov
In short, the following should work:
function f(){};
Object.defineProperty(f, 'name', {value: 'g'});
Simon Pieters (:zcorpan)
*** Bug 158062 has been marked as a duplicate of this bug. ***
Simon Pieters (:zcorpan)
Test for "length" in test262 at
https://github.com/tc39/test262/blob/83b27c9beb7b3ea78b319148b5c82a5411a333b1/test/language/statements/function/13.2-15-1.js#L19
Mark Lam
This is already fixed in ToT. You can verify this for yourself using Safari Technology Preview or a WebKit Nightly build (https://webkit.org/downloads/).