Changeset 284757 in webkit
- Timestamp:
- Oct 24, 2021, 8:32:25 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 edited
-
JSTests/ChangeLog (modified) (1 diff)
-
JSTests/stress/internal-function-subclass-structure-realm.js (added)
-
Source/JavaScriptCore/ChangeLog (modified) (1 diff)
-
Source/JavaScriptCore/runtime/InternalFunction.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/JSTests/ChangeLog
r284751 r284757 1 2021-10-24 Alexey Shvayka <ashvayka@apple.com> 2 3 InternalFunction::createSubclassStructure() should use prototype's global object 4 https://bugs.webkit.org/show_bug.cgi?id=231874 5 6 Reviewed by Yusuke Suzuki. 7 8 * stress/internal-function-subclass-structure-realm.js: Added. 9 1 10 2021-10-23 Phillip Mates <pmates@igalia.com> 2 11 -
trunk/Source/JavaScriptCore/ChangeLog
r284726 r284757 1 2021-10-24 Alexey Shvayka <ashvayka@apple.com> 2 3 InternalFunction::createSubclassStructure() should use prototype's global object 4 https://bugs.webkit.org/show_bug.cgi?id=231874 5 6 Reviewed by Yusuke Suzuki. 7 8 In case NewTarget has a cross-realm "prototype" object, even though the instance 9 structure is created with correct [[Prototype]], it's m_globalObject is of NewTarget's 10 realm instead of prototype's. 11 12 That is observable in various places, including when calling CustomAccessor, fast paths 13 for iteration protocol / collection constructors, isHavingABadTime() handling etc. 14 15 This patch fixes structure's global object to be correct: per spec [1], we fallback to 16 NewTarget's realm only if "prototype" is a primitive. 17 18 [1]: https://tc39.es/ecma262/#sec-getprototypefromconstructor (step 3.b) 19 20 * runtime/InternalFunction.cpp: 21 (JSC::InternalFunction::createSubclassStructure): 22 1 23 2021-10-22 Justin Michaud <justin_michaud@apple.com> 2 24 -
trunk/Source/JavaScriptCore/runtime/InternalFunction.cpp
r282864 r284757 143 143 // newTarget may be an InternalFunction if we were called from Reflect.construct. 144 144 JSFunction* targetFunction = jsDynamicCast<JSFunction*>(vm, newTarget); 145 JSGlobalObject* baseGlobalObject = baseClass->globalObject();146 145 147 146 if (LIKELY(targetFunction)) { 148 147 FunctionRareData* rareData = targetFunction->ensureRareData(vm); 149 148 Structure* structure = rareData->internalFunctionAllocationStructure(); 150 if (LIKELY(structure && structure->classInfo() == baseClass->classInfo() && structure->globalObject() == base GlobalObject))149 if (LIKELY(structure && structure->classInfo() == baseClass->classInfo() && structure->globalObject() == baseClass->globalObject())) 151 150 return structure; 152 151 … … 155 154 RETURN_IF_EXCEPTION(scope, nullptr); 156 155 if (JSObject* prototype = jsDynamicCast<JSObject*>(vm, prototypeValue)) 157 return rareData->createInternalFunctionAllocationStructureFromBase(vm, baseGlobalObject, prototype, baseClass);156 return rareData->createInternalFunctionAllocationStructureFromBase(vm, prototype->globalObject(vm), prototype, baseClass); 158 157 } else { 159 158 JSValue prototypeValue = newTarget->get(globalObject, vm.propertyNames->prototype); … … 162 161 // This only happens if someone Reflect.constructs our builtin constructor with another builtin constructor as the new.target. 163 162 // Thus, we don't care about the cost of looking up the structure from our hash table every time. 164 return vm.structureCache.emptyStructureForPrototypeFromBaseStructure( baseGlobalObject, prototype, baseClass);163 return vm.structureCache.emptyStructureForPrototypeFromBaseStructure(prototype->globalObject(vm), prototype, baseClass); 165 164 } 166 165 }
Note:
See TracChangeset
for help on using the changeset viewer.