Proxy.handler-isExtensible.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. load("test-common.js");
  2. try {
  3. assert(Object.isExtensible(new Proxy({}, { isExtensible: null })) === true);
  4. assert(Object.isExtensible(new Proxy({}, { isExtensible: undefined })) === true);
  5. assert(Object.isExtensible(new Proxy({}, {})) === true);
  6. let o = {};
  7. let p = new Proxy(o, {
  8. isExtensible(target) {
  9. assert(target === o);
  10. return true;
  11. }
  12. });
  13. Object.isExtensible(p);
  14. // Invariants
  15. o = {};
  16. p = new Proxy(o, {
  17. isExtensible(proxyTarget) {
  18. assert(proxyTarget === o);
  19. return true;
  20. },
  21. });
  22. assert(Object.isExtensible(p) === true);
  23. Object.preventExtensions(o);
  24. assertThrowsError(() => {
  25. Object.isExtensible(p);
  26. }, {
  27. error: TypeError,
  28. message: "Proxy handler's isExtensible trap violates invariant: return value must match the target's extensibility",
  29. });
  30. p = new Proxy(o, {
  31. isExtensible(proxyTarget) {
  32. assert(proxyTarget === o);
  33. return false;
  34. },
  35. });
  36. assert(Object.isExtensible(p) === false);
  37. console.log("PASS");
  38. } catch (e) {
  39. console.log("FAIL: " + e);
  40. }