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:
@@ -270,6 +270,16 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
if (value instanceof Error) {
|
if (value instanceof Error) {
|
||||||
return true;
|
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) {
|
if (value && value.constructor && value.constructor.constructor) {
|
||||||
var valueGlobal = value.constructor.constructor('return this');
|
var valueGlobal = value.constructor.constructor('return this');
|
||||||
if (j$.isFunction_(valueGlobal)) {
|
if (j$.isFunction_(valueGlobal)) {
|
||||||
|
|||||||
@@ -102,6 +102,16 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
if (value instanceof Error) {
|
if (value instanceof Error) {
|
||||||
return true;
|
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) {
|
if (value && value.constructor && value.constructor.constructor) {
|
||||||
var valueGlobal = value.constructor.constructor('return this');
|
var valueGlobal = value.constructor.constructor('return this');
|
||||||
if (j$.isFunction_(valueGlobal)) {
|
if (j$.isFunction_(valueGlobal)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user