Innovenergy_trunk/frontend/node_modules/testcafe/lib/utils/delegated-api.js

74 lines
9.2 KiB
JavaScript
Raw Normal View History

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.delegateAPI = exports.getDelegatedAPIList = void 0;
const API_IMPLEMENTATION_METHOD_RE = /^_(\S+)\$(getter|setter)?$/;
function isTestController(obj) {
var _a;
return ((_a = obj === null || obj === void 0 ? void 0 : obj.constructor) === null || _a === void 0 ? void 0 : _a.name) === 'TestController';
}
function getTestController(obj) {
if (isTestController(obj))
return obj;
else if (isTestController(obj._testController))
return obj._testController;
return null;
}
function getDelegatedAPIList(src) {
return Object
.getOwnPropertyNames(src)
.map(prop => {
const match = prop.match(API_IMPLEMENTATION_METHOD_RE);
if (match) {
return {
srcProp: prop,
apiProp: match[1],
accessor: match[2],
};
}
return null;
})
.filter(item => !!item);
}
exports.getDelegatedAPIList = getDelegatedAPIList;
function delegateAPI(dest, apiList, opts) {
apiList.forEach(({ srcProp, apiProp, accessor }) => {
let fn = function (...args) {
if (opts.proxyMethod)
opts.proxyMethod();
let handler = null;
if (opts.useCurrentCtxAsHandler)
handler = this;
else if (opts.getHandler)
handler = opts.getHandler(apiProp, accessor);
else
handler = opts.handler;
return handler[srcProp](...args);
};
// NOTE: need to create named function to process possible err.stack correctly
const createNamedFunction = new Function('srcProp', 'apiProp', 'accessor', 'opts', `
return ${fn.toString().replace('function', 'function ' + apiProp)}
`);
fn = createNamedFunction(srcProp, apiProp, accessor, opts);
if (accessor === 'getter')
Object.defineProperty(dest, apiProp, { get: fn, configurable: true });
else if (accessor === 'setter')
Object.defineProperty(dest, apiProp, { set: fn, configurable: true });
else {
// NOTE: need to create `property` but not a `function` to stop on `debugger`
// before the action is called
Object.defineProperty(dest, apiProp, {
get() {
const testController = getTestController(this);
if (testController && testController.shouldStop(apiProp)) {
// eslint-disable-next-line no-debugger
debugger;
}
return fn;
},
configurable: true,
});
}
});
}
exports.delegateAPI = delegateAPI;
//# sourceMappingURL=data:application/json;base64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UZXN0Q29udHJvbGxlciAob2JqKSB7XG4gICAgcmV0dXJuIG9iaj8uY29uc3RydWN0b3I/Lm5hbWUgPT09ICdUZXN0Q29udHJvbGxlcic7XG59XG5cbmZ1bmN0aW9uIGdldFRlc3RDb250cm9sbGVyIChvYmopIHtcbiAgICBpZiAoaXNUZXN0Q29udHJvbGxlcihvYmopKVxuICAgICAgICByZXR1cm4gb2JqO1xuXG4gICAgZWxzZSBpZiAoaXNUZXN0Q29udHJvbGxlcihvYmouX3Rlc3RDb250cm9sbGVyKSlcbiAgICAgICAgcmV0dXJuIG9iai5fdGVzdENvbnRyb2xsZXI7XG5cbiAgICByZXR1cm4gbnVsbDtcbn1cblxuZXhwb3J0IGZ1bmN0aW9uIGdldERlbGVnYXRlZEFQSUxpc3QgKHNyYykge1xuICAgIHJldHVybiBPYmplY3RcbiAgICAgICAgLmdldE93blByb3BlcnR5TmFtZXMoc3JjKVxuICAgICAgICAubWFwKHByb3AgPT4ge1xuICAgICAgICAgICAgY29uc3QgbWF0Y2ggPSBwcm9wLm1hdGNoKEFQSV9JTVBMRU1FTlRBVElPTl9NRVRIT0RfUkUpO1xuXG4gICAgICAgICAgICBpZiAobWF0Y2gpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgICAgICAgICBzcmNQcm9wOiAgcHJvcCxcbiAgICAgICAgICAgICAgICAgICAgYXBpUHJvcDogIG1hdGNoWzFdLFxuICAgICAgICAgICAgICAgICAgICBhY2Nlc3NvcjogbWF0Y2hbMl0sXG4gICAgICAgICAgICAgICAgfTtcbiAgICAgICAgI