Files
jasmine/src/core/deprecatingThisProxy.js
Steve Gravrock 61fb353197 Deprecate access to Suite objects via this in describes
Jasmine 1.x exposed Suite objects to user code as the `this` in describe
functions. That should have been removed in 2.0 but it was missed. It
will be removed in 4.0. This change adds a deprecation warning if anything
on a describe's `this` is accessed.

The deprecation warning relies on Proxy, and won't work in environments
that don't have it. Among Jasmine's supported environments, that's Safari 9,
Safari 8, and all versions of IE. In those browsers, a describe's `this`
will still be a Suite for now, but there will be no deprecation warnings.
2021-05-22 09:07:31 -07:00

33 lines
836 B
JavaScript

/* eslint-disable compat/compat */
// TODO: Remove this in the next major release.
getJasmineRequireObj().deprecatingThisProxy = function(j$) {
var msg = "Access to 'this' in describe functions is deprecated.";
try {
new Proxy({}, {});
} catch (e) {
// Environment does not support Poxy.
return function(suite) {
return suite;
};
}
function DeprecatingThisProxyHandler(env) {
this._env = env;
}
DeprecatingThisProxyHandler.prototype.get = function(target, prop, receiver) {
this._env.deprecated(msg);
return target[prop];
};
DeprecatingThisProxyHandler.prototype.set = function(target, prop, value) {
this._env.deprecated(msg);
return (target[prop] = value);
};
return function(suite, env) {
return new Proxy(suite, new DeprecatingThisProxyHandler(env));
};
};