Skip to content

Commit

Permalink
Merge pull request #1409 from Floorp-Projects/upstream-esr128-2024090…
Browse files Browse the repository at this point in the history
…2013837

Pull upstream
  • Loading branch information
surapunoyousei authored Sep 2, 2024
2 parents c3f0417 + 2219f22 commit 970dfc1
Show file tree
Hide file tree
Showing 48 changed files with 1,209 additions and 2,136 deletions.
1 change: 1 addition & 0 deletions .hgtags
Original file line number Diff line number Diff line change
Expand Up @@ -5079,3 +5079,4 @@ e62c89485ef081311edf625308f0093307516d68 FIREFOX_128_0esr_BUILD1
18b5deccfd5a73daddfc8a2ab5a6a41384ba8af5 FIREFOX_128_1_0esr_BUILD1
b5f945290d0a97227a9de2c841b6695e40a9f7c2 FIREFOX_128_1_0esr_BUILD2
b5f945290d0a97227a9de2c841b6695e40a9f7c2 FIREFOX_128_1_0esr_RELEASE
49e746f805bd2d0c6a18e9db2df6ccbac0242eae FIREFOX_128_2_0esr_BUILD1
2 changes: 1 addition & 1 deletion CLOBBER
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
# changes to stick? As of bug 928195, this shouldn't be necessary! Please
# don't change CLOBBER for WebIDL changes any more.

Merge day clobber 2024-08-05
Merge day clobber 2024-09-02
2 changes: 1 addition & 1 deletion browser/config/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
128.2.0
128.3.0
2 changes: 1 addition & 1 deletion config/milestone.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# hardcoded milestones in the tree from these two files.
#--------------------------------------------------------

128.2.0
128.3.0
29 changes: 24 additions & 5 deletions dom/bindings/BindingDeclarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -548,14 +548,33 @@ class SystemCallerGuarantee {
operator CallerType() const { return CallerType::System; }
};

enum class DefineInterfaceProperty {
No,
CheckExposure,
Always,
};

class ProtoAndIfaceCache;
typedef void (*CreateInterfaceObjectsMethod)(JSContext* aCx,
JS::Handle<JSObject*> aGlobal,
ProtoAndIfaceCache& aCache,
bool aDefineOnGlobal);
using CreateInterfaceObjectsMethod =
void (*)(JSContext*, JS::Handle<JSObject*>, ProtoAndIfaceCache&,
DefineInterfaceProperty aDefineOnGlobal);

// GetPerInterfaceObjectHandle has 3 possible behaviours for defining the named
// properties on the global for an interface or namespace when it creates an
// interface or namespace object. aDefineOnGlobal can be used to pick the
// behaviour. GetPerInterfaceObjectHandle either:
//
// * does not define any properties on the global object
// (for DefineInterfaceProperty::No),
// * checks whether the interface is exposed in the global object before
// defining properties (for DefineInterfaceProperty::CheckExposure),
// * always defines properties (for DefineInterfaceProperty::Always).
//
// Callers should be careful when passing DefineInterfaceProperty::Always and
// make sure to check exposure themselves if needed.
JS::Handle<JSObject*> GetPerInterfaceObjectHandle(
JSContext* aCx, size_t aSlotId, CreateInterfaceObjectsMethod aCreator,
bool aDefineOnGlobal);
DefineInterfaceProperty aDefineOnGlobal);

namespace binding_detail {

Expand Down
10 changes: 5 additions & 5 deletions dom/bindings/BindingUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3665,8 +3665,8 @@ bool GetDesiredProto(JSContext* aCx, const JS::CallArgs& aCallArgs,
// JS::GetRealmGlobalOrNull should not be returning null here, because we
// have live objects in the Realm.
JSAutoRealm ar(aCx, JS::GetRealmGlobalOrNull(realm));
aDesiredProto.set(
GetPerInterfaceObjectHandle(aCx, aProtoId, aCreator, true));
aDesiredProto.set(GetPerInterfaceObjectHandle(
aCx, aProtoId, aCreator, DefineInterfaceProperty::CheckExposure));
if (!aDesiredProto) {
return false;
}
Expand Down Expand Up @@ -3797,8 +3797,8 @@ bool HTMLConstructor(JSContext* aCx, unsigned aArgc, JS::Value* aVp,
// makes sense to start with: https://github.com/whatwg/html/issues/3575
{
JSAutoRealm ar(aCx, newTarget);
JS::Handle<JSObject*> constructor =
GetPerInterfaceObjectHandle(aCx, aConstructorId, aCreator, true);
JS::Handle<JSObject*> constructor = GetPerInterfaceObjectHandle(
aCx, aConstructorId, aCreator, DefineInterfaceProperty::CheckExposure);
if (!constructor) {
return false;
}
Expand Down Expand Up @@ -4211,7 +4211,7 @@ JSObject* UnprivilegedJunkScopeOrWorkerGlobal(const fallible_t&) {

JS::Handle<JSObject*> GetPerInterfaceObjectHandle(
JSContext* aCx, size_t aSlotId, CreateInterfaceObjectsMethod aCreator,
bool aDefineOnGlobal) {
DefineInterfaceProperty aDefineOnGlobal) {
/* Make sure our global is sane. Hopefully we can remove this sometime */
JSObject* global = JS::CurrentGlobalOrNull(aCx);
if (!(JS::GetClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
Expand Down
8 changes: 8 additions & 0 deletions dom/bindings/BindingUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3367,6 +3367,14 @@ class StringIdChars {
already_AddRefed<Promise> CreateRejectedPromiseFromThrownException(
JSContext* aCx, ErrorResult& aError);

template <auto ConstructorEnabled>
inline bool ShouldExpose(JSContext* aCx, JS::Handle<JSObject*> aGlobal,
DefineInterfaceProperty aDefine) {
return aDefine == DefineInterfaceProperty::Always ||
(aDefine == DefineInterfaceProperty::CheckExposure &&
ConstructorEnabled(aCx, aGlobal));
}

} // namespace binding_detail

} // namespace dom
Expand Down
166 changes: 92 additions & 74 deletions dom/bindings/Codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3494,7 +3494,7 @@ def __init__(
Argument("JSContext*", "aCx"),
Argument("JS::Handle<JSObject*>", "aGlobal"),
Argument("ProtoAndIfaceCache&", "aProtoAndIfaceCache"),
Argument("bool", "aDefineOnGlobal"),
Argument("DefineInterfaceProperty", "aDefineOnGlobal"),
]
CGAbstractMethod.__init__(
self, descriptor, "CreateInterfaceObjects", "void", args, static=static
Expand All @@ -3505,6 +3505,19 @@ def __init__(

def definition_body(self):
needInterfaceObject = self.descriptor.interface.hasInterfaceObject()
if needInterfaceObject and self.descriptor.isExposedConditionally():
# This code might be called when we're trying to create an object
# in a non-system compartment, for example when system code is
# calling a constructor through Xrays. In that case we do want to
# create an interface object in the non-system compartment, but we
# don't want to expose the name on the non-system global if the
# interface itself is marked as ChromeOnly.
defineOnGlobal = (
"ShouldExpose<%s::ConstructorEnabled>(aCx, aGlobal, aDefineOnGlobal)"
% toBindingNamespace(self.descriptor.name)
)
else:
defineOnGlobal = "aDefineOnGlobal != DefineInterfaceProperty::No"
if needInterfaceObject:
(protoGetter, protoHandleGetter) = InterfaceObjectProtoGetter(
self.descriptor
Expand Down Expand Up @@ -3572,13 +3585,15 @@ def definition_body(self):
interfaceCache,
${properties},
${chromeProperties},
"${name}", aDefineOnGlobal);
"${name}",
${defineOnGlobal});
""",
interfaceCache=interfaceCache,
constructorProto=constructorProto,
properties=properties,
chromeProperties=chromeProperties,
name=name,
defineOnGlobal=defineOnGlobal,
)
return CGList(
[
Expand Down Expand Up @@ -3659,7 +3674,8 @@ def definition_body(self):
interfaceCache,
${properties},
${chromeProperties},
"${name}", aDefineOnGlobal,
"${name}",
${defineOnGlobal},
${unscopableNames},
${isGlobal},
${legacyWindowAliases});
Expand All @@ -3674,6 +3690,7 @@ def definition_body(self):
properties=properties,
chromeProperties=chromeProperties,
name=name,
defineOnGlobal=defineOnGlobal,
unscopableNames="unscopableNames" if self.haveUnscopables else "nullptr",
isGlobal=toStringBool(isGlobal),
legacyWindowAliases="legacyWindowAliases"
Expand Down Expand Up @@ -3913,6 +3930,40 @@ def defineAliasesFor(m):
).define()


class CGCreateAndDefineOnGlobalMethod(CGAbstractMethod):
"""
A method for creating the interface or namespace object and defining
properties for it on the global.
"""

def __init__(self, descriptor):
CGAbstractMethod.__init__(
self,
descriptor,
"CreateAndDefineOnGlobal",
"bool",
[
Argument("JSContext*", "aCx"),
],
inline=True,
)

def definition_body(self):
return fill(
"""
// Get the interface or namespace object for this class. This will
// create the object as needed and always define the properties for
// it on the global. The caller should make sure the interface or
// namespace is exposed on the global before calling this.
return GetPerInterfaceObjectHandle(aCx, constructors::id::${name},
&CreateInterfaceObjects,
DefineInterfaceProperty::Always);

""",
name=self.descriptor.name,
)


class CGGetProtoObjectHandleMethod(CGAbstractMethod):
"""
A method for getting the interface prototype object.
Expand All @@ -3937,7 +3988,7 @@ def definition_body(self):
object as needed. */
return GetPerInterfaceObjectHandle(aCx, prototypes::id::${name},
&CreateInterfaceObjects,
/* aDefineOnGlobal = */ true);
DefineInterfaceProperty::CheckExposure);

""",
name=self.descriptor.name,
Expand Down Expand Up @@ -3975,7 +4026,6 @@ def __init__(self, descriptor):
"JS::Handle<JSObject*>",
[
Argument("JSContext*", "aCx"),
Argument("bool", "aDefineOnGlobal", "true"),
],
inline=True,
)
Expand All @@ -3988,7 +4038,7 @@ def definition_body(self):

return GetPerInterfaceObjectHandle(aCx, constructors::id::${name},
&CreateInterfaceObjects,
aDefineOnGlobal);
DefineInterfaceProperty::CheckExposure);
""",
name=self.descriptor.name,
)
Expand Down Expand Up @@ -17122,6 +17172,11 @@ def __init__(self, descriptor, attributeTemplates):
if descriptor.interface.hasInterfaceObject():
cgThings.append(CGGetConstructorObjectHandleMethod(descriptor))
cgThings.append(CGGetConstructorObjectMethod(descriptor))
cgThings.append(
CGCreateAndDefineOnGlobalMethod(
descriptor,
)
)

# See whether we need to generate cross-origin property arrays.
if needCrossOriginPropertyArrays:
Expand Down Expand Up @@ -18305,6 +18360,21 @@ def dictionarySafeToJSONify(dictionary):
return all(CGDictionary.typeSafeToJSONify(m.type) for m in dictionary.members)


def RegisterNonWindowBindings(descriptors):
conditions = []
for desc in descriptors:
bindingNS = toBindingNamespace(desc.name)
condition = "!%s::CreateAndDefineOnGlobal(aCx)" % bindingNS
if desc.isExposedConditionally():
condition = "%s::ConstructorEnabled(aCx, aObj) && " % bindingNS + condition
conditions.append(condition)
lines = [
CGIfWrapper(CGGeneric("return false;\n"), condition) for condition in conditions
]
lines.append(CGGeneric("return true;\n"))
return CGList(lines, "\n").define()


class CGRegisterWorkerBindings(CGAbstractMethod):
def __init__(self, config):
CGAbstractMethod.__init__(
Expand All @@ -18317,24 +18387,11 @@ def __init__(self, config):
self.config = config

def definition_body(self):
descriptors = self.config.getDescriptors(
hasInterfaceObject=True, isExposedInAnyWorker=True, register=True
return RegisterNonWindowBindings(
self.config.getDescriptors(
hasInterfaceObject=True, isExposedInAnyWorker=True, register=True
)
)
conditions = []
for desc in descriptors:
bindingNS = toBindingNamespace(desc.name)
condition = "!%s::GetConstructorObject(aCx)" % bindingNS
if desc.isExposedConditionally():
condition = (
"%s::ConstructorEnabled(aCx, aObj) && " % bindingNS + condition
)
conditions.append(condition)
lines = [
CGIfWrapper(CGGeneric("return false;\n"), condition)
for condition in conditions
]
lines.append(CGGeneric("return true;\n"))
return CGList(lines, "\n").define()


class CGRegisterWorkerDebuggerBindings(CGAbstractMethod):
Expand All @@ -18349,24 +18406,11 @@ def __init__(self, config):
self.config = config

def definition_body(self):
descriptors = self.config.getDescriptors(
hasInterfaceObject=True, isExposedInWorkerDebugger=True, register=True
return RegisterNonWindowBindings(
self.config.getDescriptors(
hasInterfaceObject=True, isExposedInWorkerDebugger=True, register=True
)
)
conditions = []
for desc in descriptors:
bindingNS = toBindingNamespace(desc.name)
condition = "!%s::GetConstructorObject(aCx)" % bindingNS
if desc.isExposedConditionally():
condition = (
"%s::ConstructorEnabled(aCx, aObj) && " % bindingNS + condition
)
conditions.append(condition)
lines = [
CGIfWrapper(CGGeneric("return false;\n"), condition)
for condition in conditions
]
lines.append(CGGeneric("return true;\n"))
return CGList(lines, "\n").define()


class CGRegisterWorkletBindings(CGAbstractMethod):
Expand All @@ -18381,24 +18425,11 @@ def __init__(self, config):
self.config = config

def definition_body(self):
descriptors = self.config.getDescriptors(
hasInterfaceObject=True, isExposedInAnyWorklet=True, register=True
return RegisterNonWindowBindings(
self.config.getDescriptors(
hasInterfaceObject=True, isExposedInAnyWorklet=True, register=True
)
)
conditions = []
for desc in descriptors:
bindingNS = toBindingNamespace(desc.name)
condition = "!%s::GetConstructorObject(aCx)" % bindingNS
if desc.isExposedConditionally():
condition = (
"%s::ConstructorEnabled(aCx, aObj) && " % bindingNS + condition
)
conditions.append(condition)
lines = [
CGIfWrapper(CGGeneric("return false;\n"), condition)
for condition in conditions
]
lines.append(CGGeneric("return true;\n"))
return CGList(lines, "\n").define()


class CGRegisterShadowRealmBindings(CGAbstractMethod):
Expand All @@ -18413,24 +18444,11 @@ def __init__(self, config):
self.config = config

def definition_body(self):
descriptors = self.config.getDescriptors(
hasInterfaceObject=True, isExposedInShadowRealms=True, register=True
return RegisterNonWindowBindings(
self.config.getDescriptors(
hasInterfaceObject=True, isExposedInShadowRealms=True, register=True
)
)
conditions = []
for desc in descriptors:
bindingNS = toBindingNamespace(desc.name)
condition = "!%s::GetConstructorObject(aCx)" % bindingNS
if desc.isExposedConditionally():
condition = (
"%s::ConstructorEnabled(aCx, aObj) && " % bindingNS + condition
)
conditions.append(condition)
lines = [
CGIfWrapper(CGGeneric("return false;\n"), condition)
for condition in conditions
]
lines.append(CGGeneric("return true;\n"))
return CGList(lines, "\n").define()


def BindingNamesOffsetEnum(name):
Expand Down
Loading

0 comments on commit 970dfc1

Please sign in to comment.