Bug 1723715 part 2 - Remove the RUNTIME_CODEGEN_ENABLED slot. r=jonco

Originally this slot was used to cache the return value of the callback. However
that was changed at some point, now the slot is only set to TrueValue when there
is no callback installed. It's now better and simpler to remove the slot.

Depends on D121981

Differential Revision: https://phabricator.services.mozilla.com/D121982
This commit is contained in:
Jan de Mooij 2021-08-09 15:25:05 +00:00
parent 1c8f0d1a67
commit 939aa16efa
3 changed files with 9 additions and 20 deletions

View File

@ -572,7 +572,7 @@ static const uint32_t JSCLASS_FOREGROUND_FINALIZE =
// application.
static const uint32_t JSCLASS_GLOBAL_APPLICATION_SLOTS = 5;
static const uint32_t JSCLASS_GLOBAL_SLOT_COUNT =
JSCLASS_GLOBAL_APPLICATION_SLOTS + JSProto_LIMIT * 2 + 30;
JSCLASS_GLOBAL_APPLICATION_SLOTS + JSProto_LIMIT * 2 + 29;
static constexpr uint32_t JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(uint32_t n) {
return JSCLASS_IS_GLOBAL |

View File

@ -769,25 +769,15 @@ bool GlobalObject::initStandardClasses(JSContext* cx,
/* static */
bool GlobalObject::isRuntimeCodeGenEnabled(JSContext* cx, HandleString code,
Handle<GlobalObject*> global) {
Value v = global->getReservedSlot(RUNTIME_CODEGEN_ENABLED);
if (v.isUndefined()) {
/*
* If there are callbacks, make sure that the CSP callback is installed
* and that it permits runtime code generation.
*/
JSCSPEvalChecker allows =
cx->runtime()->securityCallbacks->contentSecurityPolicyAllows;
if (allows) {
return allows(cx, code);
}
// Let's cache the result only if the contentSecurityPolicyAllows callback
// is not set. In this way, contentSecurityPolicyAllows callback is executed
// each time, with the current HandleValue code.
v = JS::TrueValue();
global->setReservedSlot(RUNTIME_CODEGEN_ENABLED, v);
// If there are callbacks, make sure that the CSP callback is installed
// and that it permits runtime code generation.
JSCSPEvalChecker allows =
cx->runtime()->securityCallbacks->contentSecurityPolicyAllows;
if (allows) {
return allows(cx, code);
}
return !v.isFalse();
return true;
}
/* static */

View File

@ -134,7 +134,6 @@ class GlobalObject : public NativeObject {
REQUESTED_MODULE_PROTO,
MODULE_REQUEST_PROTO,
REGEXP_STATICS,
RUNTIME_CODEGEN_ENABLED,
INTRINSICS,
FOR_OF_PIC_CHAIN,
WINDOW_PROXY,