Skip to content

Commit

Permalink
Cherry-pick WebKit/WebKit#27964 (#10727)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner authored May 1, 2024
1 parent 23e4f60 commit 32120fe
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/bun.js/bindings/webcore/CustomEventCustom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ namespace WebCore {

JSC::JSValue JSCustomEvent::detail(JSC::JSGlobalObject& lexicalGlobalObject) const
{
return cachedPropertyValue(lexicalGlobalObject, *this, wrapped().cachedDetail(), [this] {
auto throwScope = DECLARE_THROW_SCOPE(lexicalGlobalObject.vm());
return cachedPropertyValue(throwScope, lexicalGlobalObject, *this, wrapped().cachedDetail(), [this](JSC::ThrowScope&) {
return wrapped().detail().getValue(JSC::jsNull());
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/bindings/webcore/JSMessageEventCustom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace WebCore {
JSC::JSValue JSMessageEvent::ports(JSC::JSGlobalObject& lexicalGlobalObject) const
{
auto throwScope = DECLARE_THROW_SCOPE(lexicalGlobalObject.vm());
return cachedPropertyValue(lexicalGlobalObject, *this, wrapped().cachedPorts(), [&] {
return cachedPropertyValue(throwScope, lexicalGlobalObject, *this, wrapped().cachedPorts(), [&](JSC::ThrowScope& throwScope) {
JSC::JSValue ports = toJS<IDLFrozenArray<IDLInterface<MessagePort>>>(lexicalGlobalObject, *globalObject(), throwScope, wrapped().ports());
return ports;
});
Expand Down
14 changes: 2 additions & 12 deletions src/bun.js/bindings/webcore/JSValueInWrappedObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class JSValueInWrappedObject {
JSC::Weak<JSC::JSCell> m_cell {};
};

JSC::JSValue cachedPropertyValue(JSC::ThrowScope&, JSC::JSGlobalObject&, const JSDOMObject& owner, JSValueInWrappedObject& cacheSlot, const Function<JSC::JSValue(JSC::ThrowScope&)>&);
JSC::JSValue cachedPropertyValue(JSC::ThrowScope&, JSC::JSGlobalObject&, const JSDOMObject& owner, JSValueInWrappedObject& cacheSlot, const auto&);

inline JSValueInWrappedObject::JSValueInWrappedObject(JSC::JSValue value)
{
Expand Down Expand Up @@ -110,17 +110,7 @@ inline void JSValueInWrappedObject::clear()
m_cell.clear();
}

inline JSC::JSValue cachedPropertyValue(JSC::JSGlobalObject& lexicalGlobalObject, const JSDOMObject& owner, JSValueInWrappedObject& cachedValue, const Function<JSC::JSValue()>& function)
{
if (cachedValue && isWorldCompatible(lexicalGlobalObject, cachedValue.getValue()))
return cachedValue.getValue();
auto value = function();
cachedValue.set(lexicalGlobalObject.vm(), &owner, cloneAcrossWorlds(lexicalGlobalObject, owner, value));
ASSERT(isWorldCompatible(lexicalGlobalObject, cachedValue.getValue()));
return cachedValue.getValue();
}

inline JSC::JSValue cachedPropertyValue(JSC::ThrowScope& throwScope, JSC::JSGlobalObject& lexicalGlobalObject, const JSDOMObject& owner, JSValueInWrappedObject& cachedValue, const Function<JSC::JSValue(JSC::ThrowScope&)>& function)
inline JSC::JSValue cachedPropertyValue(JSC::ThrowScope& throwScope, JSC::JSGlobalObject& lexicalGlobalObject, const JSDOMObject& owner, JSValueInWrappedObject& cachedValue, const auto& function)
{
if (cachedValue && isWorldCompatible(lexicalGlobalObject, cachedValue.getValue()))
return cachedValue.getValue();
Expand Down

0 comments on commit 32120fe

Please sign in to comment.