Skip to content

Commit

Permalink
Bug 1905239 - Introduce HostGetCodeForEval hook for PerformEval. r=ts…
Browse files Browse the repository at this point in the history
…chuster

See https://tc39.es/proposal-dynamic-code-brand-checks

Differential Revision: https://phabricator.services.mozilla.com/D229477

UltraBlame original commit: b575160525c1fe6d5beab39f995e88ba83df06a3
  • Loading branch information
marco-c committed Dec 13, 2024
1 parent 2e05e57 commit aa70c31
Show file tree
Hide file tree
Showing 9 changed files with 763 additions and 10 deletions.
1 change: 1 addition & 0 deletions caps/nsScriptSecurityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6987,6 +6987,7 @@ securityCallbacks
=
{
ContentSecurityPolicyPermitsJSAction
nullptr
JSPrincipalsSubsume
}
;
Expand Down
29 changes: 29 additions & 0 deletions js/public/Principals.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,41 @@ HandleString
code
)
;
typedef
bool
(
*
JSCodeForEvalOp
)
(
JSContext
*
cx
JS
:
:
HandleObject
code
JS
:
:
MutableHandle
<
JSString
*
>
outCode
)
;
struct
JSSecurityCallbacks
{
JSCSPEvalChecker
contentSecurityPolicyAllows
;
JSCodeForEvalOp
codeForEvalGets
;
JSSubsumesOp
subsumes
;
Expand Down
70 changes: 60 additions & 10 deletions js/src/builtin/Eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1312,34 +1312,48 @@ cx
env
)
;
RootedString
str
(
cx
)
;
if
(
!
v
.
isString
(
)
)
{
vp
str
=
v
.
set
toString
(
v
)
;
return
true
;
}
RootedString
str
else
if
(
v
.
isObject
(
)
)
{
RootedObject
obj
(
cx
&
v
.
toString
toObject
(
)
)
Expand All @@ -1350,6 +1364,42 @@ if
cx
-
>
getCodeForEval
(
obj
&
str
)
)
{
return
false
;
}
}
if
(
!
str
)
{
vp
.
set
(
v
)
;
return
true
;
}
if
(
!
cx
-
>
isRuntimeCodeGenEnabled
(
JS
Expand Down
5 changes: 5 additions & 0 deletions js/src/jsapi-tests/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ testDifferentNewTargetInvokeConstructor
cpp
"
"
testDynamicCodeBrandChecks
.
cpp
"
"
testEmptyWindowIsOmitted
.
cpp
Expand Down
Loading

0 comments on commit aa70c31

Please sign in to comment.