Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Source/JavaScriptCore/runtime/JSObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2948,6 +2948,10 @@ void JSObject::reifyAllStaticProperties(JSGlobalObject* globalObject)
if (!structure()->isDictionary())
convertToDictionary(vm);

// A PropertyCallback builder can enter JS; defer termination (like
// LazyProperty::callFunc) so it can't return with one pending.
auto scope = DECLARE_THROW_SCOPE(vm);
DeferTerminationForAWhile deferScope(vm);
for (const ClassInfo* info = classInfo(); info; info = info->parentClass) {
const HashTable* hashTable = info->staticPropHashTable;
if (!hashTable)
Expand All @@ -2957,8 +2961,11 @@ void JSObject::reifyAllStaticProperties(JSGlobalObject* globalObject)
unsigned attributes;
auto key = Identifier::fromString(vm, value.m_key);
PropertyOffset offset = getDirectOffset(vm, key, attributes);
if (!isValidOffset(offset))
if (!isValidOffset(offset)) {
reifyStaticProperty(vm, hashTable->classForThis, key, value, *this);
// Leave the rest lazy on throw; the caller propagates.
RETURN_IF_EXCEPTION(scope, void());
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
}

Expand Down
13 changes: 12 additions & 1 deletion Source/JavaScriptCore/runtime/Lookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "config.h"
#include "Lookup.h"

#include "DeferTermination.h"
#include "GetterSetter.h"
#include "JSCInlines.h"
#include <wtf/text/MakeString.h>
Expand Down Expand Up @@ -58,7 +59,17 @@ bool setUpStaticFunctionSlot(VM& vm, const ClassInfo* classInfo, const HashTable
if (thisObject->staticPropertiesReified())
return false;

reifyStaticProperty(vm, classInfo, propertyName, *entry, *thisObject);
auto scope = DECLARE_THROW_SCOPE(vm);
{
// A PropertyCallback builder can enter JS; defer termination (like
// LazyProperty::callFunc) so it can't return with one pending.
DeferTerminationForAWhile deferScope(vm);
reifyStaticProperty(vm, classInfo, propertyName, *entry, *thisObject);
}
// The builder may still throw a non-termination exception; report the
// slot as not found so JSValue::get / getOwnPropertyDescriptor's
// EXCEPTION_ASSERT(!scope.exception() || !result) holds.
RETURN_IF_EXCEPTION(scope, false);

offset = thisObject->getDirectOffset(vm, propertyName, attributes);
if (!isValidOffset(offset)) {
Expand Down
5 changes: 5 additions & 0 deletions Source/JavaScriptCore/runtime/Lookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,11 @@ inline void reifyStaticProperty(VM& vm, const ClassInfo* classInfo, const Proper

if (value.attributes() & PropertyAttribute::PropertyCallback) {
JSValue result = value.lazyPropertyCallback()(vm, &thisObj);
// A callback that enters JS may return empty with an exception pending;
// the two callers (setUpStaticFunctionSlot / reifyAllStaticProperties)
// check and propagate, so don't put an empty value in the slot here.
if (!result) [[unlikely]]
return;
thisObj.putDirect(vm, propertyName, result, attributesForStructure(value.attributes()));
return;
}
Expand Down
Loading