Reflect.apply.js 983 B

12345678910111213141516171819202122232425262728293031323334353637
  1. load("test-common.js");
  2. try {
  3. assert(Reflect.apply.length === 3);
  4. [null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
  5. assertThrowsError(() => {
  6. Reflect.apply(value);
  7. }, {
  8. error: TypeError,
  9. message: "First argument of Reflect.apply() must be a function"
  10. });
  11. assertThrowsError(() => {
  12. Reflect.apply(() => {}, undefined, value);
  13. }, {
  14. error: TypeError,
  15. message: "Arguments list must be an object"
  16. });
  17. });
  18. assert(Reflect.apply(String.prototype.charAt, "foo", [0]) === "f");
  19. assert(Reflect.apply(Array.prototype.indexOf, ["hello", 123, "foo", "bar"], ["foo"]) === 2);
  20. function Foo(foo) {
  21. this.foo = foo;
  22. }
  23. var o = {};
  24. assert(o.foo === undefined);
  25. assert(Reflect.apply(Foo, o, ["bar"]) === undefined);
  26. assert(o.foo === "bar");
  27. console.log("PASS");
  28. } catch (e) {
  29. console.log("FAIL: " + e);
  30. }