proxyTrapsHelper.js 1.7 KB

123456789101112131415161718192021222324252627282930
  1. // Copyright (C) 2016 Jordan Harband. All rights reserved.
  2. // This code is governed by the BSD license found in the LICENSE file.
  3. /*---
  4. description: |
  5. Used to assert the correctness of object behavior in the presence
  6. and context of Proxy objects.
  7. ---*/
  8. function allowProxyTraps(overrides) {
  9. function throwTest262Error(msg) {
  10. return function () { throw new Test262Error(msg); };
  11. }
  12. if (!overrides) { overrides = {}; }
  13. return {
  14. getPrototypeOf: overrides.getPrototypeOf || throwTest262Error('[[GetPrototypeOf]] trap called'),
  15. setPrototypeOf: overrides.setPrototypeOf || throwTest262Error('[[SetPrototypeOf]] trap called'),
  16. isExtensible: overrides.isExtensible || throwTest262Error('[[IsExtensible]] trap called'),
  17. preventExtensions: overrides.preventExtensions || throwTest262Error('[[PreventExtensions]] trap called'),
  18. getOwnPropertyDescriptor: overrides.getOwnPropertyDescriptor || throwTest262Error('[[GetOwnProperty]] trap called'),
  19. has: overrides.has || throwTest262Error('[[HasProperty]] trap called'),
  20. get: overrides.get || throwTest262Error('[[Get]] trap called'),
  21. set: overrides.set || throwTest262Error('[[Set]] trap called'),
  22. deleteProperty: overrides.deleteProperty || throwTest262Error('[[Delete]] trap called'),
  23. defineProperty: overrides.defineProperty || throwTest262Error('[[DefineOwnProperty]] trap called'),
  24. enumerate: throwTest262Error('[[Enumerate]] trap called: this trap has been removed'),
  25. ownKeys: overrides.ownKeys || throwTest262Error('[[OwnPropertyKeys]] trap called'),
  26. apply: overrides.apply || throwTest262Error('[[Call]] trap called'),
  27. construct: overrides.construct || throwTest262Error('[[Construct]] trap called')
  28. };
  29. }