зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1587007 - P1 - Tunnel the prefs for Coop and Coep to js; r=jandem
Differential Revision: https://phabricator.services.mozilla.com/D51420 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
6bdd603252
Коммит
212da22601
|
@ -128,6 +128,15 @@ class JS_PUBLIC_API RealmCreationOptions {
|
|||
bool getSharedMemoryAndAtomicsEnabled() const;
|
||||
RealmCreationOptions& setSharedMemoryAndAtomicsEnabled(bool flag);
|
||||
|
||||
// When these prefs (COOP and COEP) are not enabled, shared memory objects
|
||||
// (e.g. SAB) are not allowed to be postMessage()'ed. And we want to provide
|
||||
// a clear warning message to users/developer so that they would have an idea
|
||||
// if the implementations of the COOP and COEP headers are finished or not. So
|
||||
// that they would know if they can fix the SAB by deploying the COOP and
|
||||
// COEP headers or not.
|
||||
bool getCoopAndCoepEnabled() const;
|
||||
RealmCreationOptions& setCoopAndCoepEnabled(bool flag);
|
||||
|
||||
bool getStreamsEnabled() const { return streams_; }
|
||||
RealmCreationOptions& setStreamsEnabled(bool flag) {
|
||||
streams_ = flag;
|
||||
|
@ -199,6 +208,7 @@ class JS_PUBLIC_API RealmCreationOptions {
|
|||
bool preserveJitCode_ = false;
|
||||
bool cloneSingletons_ = false;
|
||||
bool sharedMemoryAndAtomics_ = false;
|
||||
bool coopAndCoep_ = false;
|
||||
bool streams_ = false;
|
||||
bool readableByteStreams_ = false;
|
||||
bool byobStreamReaders_ = false;
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
// |jit-test| skip-if: !this.sharedMemoryEnabled
|
||||
// Need this testing function to continue.
|
||||
|
||||
// Check the error mssage when the prefs for COOP/COEP are both enable or not.
|
||||
var g = newGlobal();
|
||||
var ex;
|
||||
const sab = new SharedArrayBuffer();
|
||||
try {
|
||||
g.serialize(sab);
|
||||
} catch (e) {
|
||||
ex = e;
|
||||
}
|
||||
assertEq(ex.toString(),
|
||||
`TypeError: The SharedArrayBuffer object cannot be serialized. The ` +
|
||||
`Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy HTTP ` +
|
||||
`headers will enable this in the future.`);
|
|
@ -1717,6 +1717,16 @@ JS::RealmCreationOptions::setSharedMemoryAndAtomicsEnabled(bool flag) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
bool JS::RealmCreationOptions::getCoopAndCoepEnabled() const {
|
||||
return coopAndCoep_;
|
||||
}
|
||||
|
||||
JS::RealmCreationOptions& JS::RealmCreationOptions::setCoopAndCoepEnabled(
|
||||
bool flag) {
|
||||
coopAndCoep_ = flag;
|
||||
return *this;
|
||||
}
|
||||
|
||||
JS::RealmBehaviors& JS::RealmBehaviorsRef(JS::Realm* realm) {
|
||||
return realm->behaviors();
|
||||
}
|
||||
|
|
|
@ -3731,6 +3731,7 @@ static const JSClass sandbox_class = {"sandbox", JSCLASS_GLOBAL_FLAGS,
|
|||
static void SetStandardRealmOptions(JS::RealmOptions& options) {
|
||||
options.creationOptions()
|
||||
.setSharedMemoryAndAtomicsEnabled(enableSharedMemory)
|
||||
.setCoopAndCoepEnabled(false)
|
||||
.setStreamsEnabled(enableStreams)
|
||||
.setReadableByteStreamsEnabled(enableReadableByteStreams)
|
||||
.setBYOBStreamReadersEnabled(enableBYOBStreamReaders)
|
||||
|
@ -6201,6 +6202,13 @@ static bool NewGlobal(JSContext* cx, unsigned argc, Value* vp) {
|
|||
}
|
||||
principals.reset(newPrincipals);
|
||||
}
|
||||
|
||||
if (!JS_GetProperty(cx, opts, "enableCoopAndCoep", &v)) {
|
||||
return false;
|
||||
}
|
||||
if (v.isBoolean()) {
|
||||
creationOptions.setCoopAndCoepEnabled(v.toBoolean());
|
||||
}
|
||||
}
|
||||
|
||||
if (!CheckRealmOptions(cx, options, principals.get())) {
|
||||
|
|
|
@ -771,6 +771,9 @@ static mozilla::Atomic<bool> sAwaitFixEnabled(false);
|
|||
void xpc::SetPrefableRealmOptions(JS::RealmOptions& options) {
|
||||
options.creationOptions()
|
||||
.setSharedMemoryAndAtomicsEnabled(sSharedMemoryEnabled)
|
||||
.setCoopAndCoepEnabled(
|
||||
StaticPrefs::browser_tabs_remote_useCrossOriginOpenerPolicy() &&
|
||||
StaticPrefs::browser_tabs_remote_useCrossOriginEmbedderPolicy())
|
||||
.setStreamsEnabled(sStreamsEnabled)
|
||||
.setWritableStreamsEnabled(
|
||||
StaticPrefs::javascript_options_writable_streams())
|
||||
|
|
Загрузка…
Ссылка в новой задаче