|
| 1 | +2021-04-09 Alexey Shvayka <shvaikalesh@gmail.com> |
| 2 | + |
| 3 | + Remove className() and toStringName() from the method table |
| 4 | + https://bugs.webkit.org/show_bug.cgi?id=224247 |
| 5 | + |
| 6 | + Reviewed by Darin Adler. |
| 7 | + |
| 8 | + ES6 introduced Symbol.toStringTag to customize Object.prototype.toString return value. |
| 9 | + It was adopted by WebIDL spec, Chrome's DevTools, Node.js etc. There is no reason to |
| 10 | + keep 2 method table methods, each with only 1 call site, instead of using the symbol. |
| 11 | + |
| 12 | + Also, it's a bit confusing that for some objects, method table's className() returns |
| 13 | + different result than JSCell::className(VM&). |
| 14 | + |
| 15 | + This change: |
| 16 | + |
| 17 | + 1. Removes JSProxy's className() / toStringName() methods because its target() is a |
| 18 | + global object that never has these overrides and uses Symbol.toStringTag instead. |
| 19 | + |
| 20 | + 2. Removes DebuggerScope's className() / toStringName() overrides because its objectAtScope() |
| 21 | + has these methods extremely rarely (e.g. `with (new Date) {}`), and its not displayed |
| 22 | + by Web Inspector. |
| 23 | + |
| 24 | + 3. Merges JSCallbackObject's className() / toStringName() methods into Symbol.toStringTag |
| 25 | + branch of getOwnPropertySlot(), with permissive property attributes. To avoid any possible |
| 26 | + breakage, we make sure that it will be shadowed by a structure property. |
| 27 | + |
| 28 | + 4. Reworks JSObject::calculatedClassName() to rely on Symbol.toStringTag, matching Chrome's |
| 29 | + DevTools behavior. On its own, it's a nice change for Web Inspector. We make sure to |
| 30 | + lookup Symbol.toStringTag if `constructor.name` inference fails to avoid confusion when |
| 31 | + extending builtins. |
| 32 | + |
| 33 | + 5. Removes now unused className() from the method table. |
| 34 | + |
| 35 | + 6. Removes toStringName() override from JSFinalizationRegistry because its builtin tag [1] |
| 36 | + is already "Object". |
| 37 | + |
| 38 | + 7. Introduces BooleanObjectType for Boolean wrapper object, and Boolean.prototype as it's |
| 39 | + also required to have a [[BooleanData]] internal slot [2]. |
| 40 | + |
| 41 | + 8. Reworks Object.prototype.toString to determine builtin tag [1] based on JSType rather than |
| 42 | + performing method table call. It's guaranteed that a) the set of types we are checking |
| 43 | + against won't be expanded, and b) objects with these types have correct `className`. |
| 44 | + |
| 45 | + 9. Removes now unused toStringTag() from the method table. |
| 46 | + |
| 47 | + This patch is performance-neutral and carefully preserves current behavior for API objects, |
| 48 | + including isPokerBros() hack. |
| 49 | + |
| 50 | + [1]: https://tc39.es/ecma262/#sec-object.prototype.tostring (steps 5-14) |
| 51 | + [2]: https://tc39.es/ecma262/#sec-properties-of-the-boolean-prototype-object |
| 52 | + |
| 53 | + * API/JSCallbackObject.h: |
| 54 | + * API/JSCallbackObjectFunctions.h: |
| 55 | + (JSC::JSCallbackObject<Parent>::getOwnPropertySlot): |
| 56 | + (JSC::JSCallbackObject<Parent>::className): Deleted. |
| 57 | + (JSC::JSCallbackObject<Parent>::toStringName): Deleted. |
| 58 | + * API/tests/testapiScripts/testapi.js: |
| 59 | + * debugger/DebuggerScope.cpp: |
| 60 | + (JSC::DebuggerScope::className): Deleted. |
| 61 | + (JSC::DebuggerScope::toStringName): Deleted. |
| 62 | + * debugger/DebuggerScope.h: |
| 63 | + * runtime/BooleanObject.cpp: |
| 64 | + (JSC::BooleanObject::toStringName): Deleted. |
| 65 | + * runtime/BooleanObject.h: |
| 66 | + (JSC::BooleanObject::createStructure): |
| 67 | + * runtime/BooleanPrototype.h: |
| 68 | + * runtime/ClassInfo.h: |
| 69 | + * runtime/DateInstance.cpp: |
| 70 | + (JSC::DateInstance::toStringName): Deleted. |
| 71 | + * runtime/DateInstance.h: |
| 72 | + * runtime/ErrorInstance.cpp: |
| 73 | + (JSC::ErrorInstance::toStringName): Deleted. |
| 74 | + * runtime/ErrorInstance.h: |
| 75 | + * runtime/JSCell.cpp: |
| 76 | + (JSC::JSCell::className): Deleted. |
| 77 | + (JSC::JSCell::toStringName): Deleted. |
| 78 | + * runtime/JSCell.h: |
| 79 | + * runtime/JSFinalizationRegistry.cpp: |
| 80 | + (JSC::JSFinalizationRegistry::toStringName): Deleted. |
| 81 | + * runtime/JSFinalizationRegistry.h: |
| 82 | + * runtime/JSObject.cpp: |
| 83 | + (JSC::JSObject::calculatedClassName): |
| 84 | + (JSC::JSObject::className): Deleted. |
| 85 | + (JSC::isPokerBros): Deleted. |
| 86 | + (JSC::JSObject::toStringName): Deleted. |
| 87 | + * runtime/JSObject.h: |
| 88 | + * runtime/JSProxy.cpp: |
| 89 | + (JSC::JSProxy::className): Deleted. |
| 90 | + (JSC::JSProxy::toStringName): Deleted. |
| 91 | + * runtime/JSProxy.h: |
| 92 | + * runtime/JSType.cpp: |
| 93 | + (WTF::printInternal): |
| 94 | + * runtime/JSType.h: |
| 95 | + * runtime/NumberObject.cpp: |
| 96 | + (JSC::NumberObject::toStringName): Deleted. |
| 97 | + * runtime/NumberObject.h: |
| 98 | + (JSC::NumberObject::createStructure): |
| 99 | + * runtime/ObjectPrototype.cpp: |
| 100 | + (JSC::isPokerBros): |
| 101 | + (JSC::inferBuiltinTag): |
| 102 | + (JSC::objectPrototypeToString): |
| 103 | + 1. Removes jsNontrivialString() because it's assertion may fail in case of iOS hack. |
| 104 | + 2. Utilizes AtomStringImpl to avoid allocating StringImpl for a small fixed set of strings. |
| 105 | + |
| 106 | + * runtime/RegExpObject.cpp: |
| 107 | + (JSC::RegExpObject::toStringName): Deleted. |
| 108 | + * runtime/RegExpObject.h: |
| 109 | + * runtime/StringObject.cpp: |
| 110 | + (JSC::StringObject::toStringName): Deleted. |
| 111 | + * runtime/StringObject.h: |
| 112 | + |
1 | 113 | 2021-04-08 Khem Raj <raj.khem@gmail.com> |
2 | 114 |
|
3 | 115 | [WPE] Build fixes for musl C library on Linux |
|
0 commit comments