func_test.go 693 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package goja
  2. import "testing"
  3. func TestFuncProto(t *testing.T) {
  4. const SCRIPT = `
  5. "use strict";
  6. function A() {}
  7. A.__proto__ = Object;
  8. A.prototype = {};
  9. function B() {}
  10. B.__proto__ = Object.create(null);
  11. var thrown = false;
  12. try {
  13. delete B.prototype;
  14. } catch (e) {
  15. thrown = e instanceof TypeError;
  16. }
  17. thrown;
  18. `
  19. testScript1(SCRIPT, valueTrue, t)
  20. }
  21. func TestFuncPrototypeRedefine(t *testing.T) {
  22. const SCRIPT = `
  23. let thrown = false;
  24. try {
  25. Object.defineProperty(function() {}, "prototype", {
  26. set: function(_value) {},
  27. });
  28. } catch (e) {
  29. if (e instanceof TypeError) {
  30. thrown = true;
  31. } else {
  32. throw e;
  33. }
  34. }
  35. thrown;
  36. `
  37. testScript1(SCRIPT, valueTrue, t)
  38. }