UNPKG

fast-check

Version:

Property based testing framework for JavaScript (like QuickCheck)

27 lines (26 loc) 697 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.safeApply = safeApply; const untouchedApply = Function.prototype.apply; const ApplySymbol = Symbol('apply'); function safeExtractApply(f) { try { return f.apply; } catch (err) { return undefined; } } function safeApplyHacky(f, instance, args) { const ff = f; ff[ApplySymbol] = untouchedApply; const out = ff[ApplySymbol](instance, args); delete ff[ApplySymbol]; return out; } function safeApply(f, instance, args) { if (safeExtractApply(f) === untouchedApply) { return f.apply(instance, args); } return safeApplyHacky(f, instance, args); }