Make j$.isError_ compatible with Trusted Types

The isError_ check uses a heuristic that calls the Function constructor
to determine if the given value is an Error object. This results in a
runtime violation in test suites that enforce Trusted Types.

Since Trusted Types are only supported in modern browsers (currently,
Chromium-based browsers), we can use a more straightforward heuristic in
environments where Trusted Types are supported.

Fixes #1910. See that thread for more details.
This commit is contained in:
Bjarki
2021-07-01 20:21:44 +00:00
parent 27c650ec08
commit dc80a282ba
2 changed files with 20 additions and 0 deletions

View File

@@ -270,6 +270,16 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
if (value instanceof Error) {
return true;
}
if (
typeof window !== 'undefined' &&
typeof window.trustedTypes !== 'undefined'
) {
return (
value &&
typeof value.stack === 'string' &&
typeof value.message === 'string'
);
}
if (value && value.constructor && value.constructor.constructor) {
var valueGlobal = value.constructor.constructor('return this');
if (j$.isFunction_(valueGlobal)) {

View File

@@ -102,6 +102,16 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
if (value instanceof Error) {
return true;
}
if (
typeof window !== 'undefined' &&
typeof window.trustedTypes !== 'undefined'
) {
return (
value &&
typeof value.stack === 'string' &&
typeof value.message === 'string'
);
}
if (value && value.constructor && value.constructor.constructor) {
var valueGlobal = value.constructor.constructor('return this');
if (j$.isFunction_(valueGlobal)) {