Bug 1162772, part 1 - Allow CompartmentCreationOptions to store Secure Context state. r=jorendorff
MozReview-Commit-ID: 4edUIF2rcBR
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -2211,17 +2211,18 @@ class JS_PUBLIC_API(CompartmentCreationO
CompartmentCreationOptions()
: addonId_(nullptr),
traceGlobal_(nullptr),
invisibleToDebugger_(false),
mergeable_(false),
preserveJitCode_(false),
cloneSingletons_(false),
experimentalDateTimeFormatFormatToPartsEnabled_(false),
- sharedMemoryAndAtomics_(false)
+ sharedMemoryAndAtomics_(false),
+ secureContext_(false)
{
zone_.spec = JS::FreshZone;
}
// A null add-on ID means that the compartment is not associated with an
// add-on.
JSAddonId* addonIdOrNull() const { return addonId_; }
CompartmentCreationOptions& setAddonId(JSAddonId* id) {
@@ -2294,29 +2295,40 @@ class JS_PUBLIC_API(CompartmentCreationO
CompartmentCreationOptions& setExperimentalDateTimeFormatFormatToPartsEnabled(bool flag) {
experimentalDateTimeFormatFormatToPartsEnabled_ = flag;
return *this;
}
bool getSharedMemoryAndAtomicsEnabled() const;
CompartmentCreationOptions& setSharedMemoryAndAtomicsEnabled(bool flag);
+ // This flag doesn't affect JS engine behavior. It is used by Gecko to
+ // mark whether content windows and workers are "Secure Context"s. See
+ // https://w3c.github.io/webappsec-secure-contexts/
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1162772#c34
+ bool secureContext() const { return secureContext_; }
+ CompartmentCreationOptions& setSecureContext(bool flag) {
+ secureContext_ = flag;
+ return *this;
+ }
+
private:
JSAddonId* addonId_;
JSTraceOp traceGlobal_;
union {
ZoneSpecifier spec;
void* pointer; // js::Zone* is not exposed in the API.
} zone_;
bool invisibleToDebugger_;
bool mergeable_;
bool preserveJitCode_;
bool cloneSingletons_;
bool experimentalDateTimeFormatFormatToPartsEnabled_;
bool sharedMemoryAndAtomics_;
+ bool secureContext_;
};
/**
* CompartmentBehaviors specifies behaviors of a compartment that can be
* changed after the compartment's been created.
*/
class JS_PUBLIC_API(CompartmentBehaviors)
{
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -138,16 +138,22 @@ JS_NewObjectWithUniqueType(JSContext* cx
JS_FRIEND_API(JSObject*)
JS_NewObjectWithoutMetadata(JSContext* cx, const JSClass* clasp, JS::Handle<JSObject*> proto)
{
AutoSuppressAllocationMetadataBuilder suppressMetadata(cx);
return JS_NewObjectWithGivenProto(cx, clasp, proto);
}
+JS_FRIEND_API(bool)
+JS_GetIsSecureContext(JSCompartment* compartment)
+{
+ return compartment->creationOptions().secureContext();
+}
+
JS_FRIEND_API(JSPrincipals*)
JS_GetCompartmentPrincipals(JSCompartment* compartment)
{
return compartment->principals();
}
JS_FRIEND_API(void)
JS_SetCompartmentPrincipals(JSCompartment* compartment, JSPrincipals* principals)
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -142,16 +142,19 @@ static_assert(JS_TELEMETRY_DEFINE_GETTER
"This value needs to be kept in sync with SelfHostingDefines.h");
typedef void
(*JSAccumulateTelemetryDataCallback)(int id, uint32_t sample, const char* key);
extern JS_FRIEND_API(void)
JS_SetAccumulateTelemetryCallback(JSRuntime* rt, JSAccumulateTelemetryDataCallback callback);
+extern JS_FRIEND_API(bool)
+JS_GetIsSecureContext(JSCompartment* compartment);
+
extern JS_FRIEND_API(JSPrincipals*)
JS_GetCompartmentPrincipals(JSCompartment* compartment);
extern JS_FRIEND_API(void)
JS_SetCompartmentPrincipals(JSCompartment* compartment, JSPrincipals* principals);
extern JS_FRIEND_API(JSPrincipals*)
JS_GetScriptPrincipals(JSScript* script);