valueof.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. var x = {};
  6. WScript.Echo("x.valueOf()");
  7. try {
  8. x.valueOf(); //Fine - there's no way to inject null or undefined as the 'this' value
  9. }
  10. catch (e)
  11. {
  12. WScript.Echo(e);
  13. }
  14. WScript.Echo("x.valueOf.call(undefined)");
  15. try {
  16. x.valueOf.call(undefined); //SHOULD throw a TypeError in ES5/IE10
  17. }
  18. catch (e)
  19. {
  20. WScript.Echo(e);
  21. }
  22. WScript.Echo("x.valueOf.call(null)");
  23. try {
  24. x.valueOf.call(null); //SHOULD throw a TypeError in ES5/IE10
  25. }
  26. catch (e)
  27. {
  28. WScript.Echo(e);
  29. }
  30. WScript.Echo("x.valueOf.call()");
  31. try {
  32. x.valueOf.call(); //SHOULD throw a TypeError in ES5/IE10
  33. }
  34. catch (e)
  35. {
  36. WScript.Echo(e);
  37. }
  38. WScript.Echo("typeof x.valueOf.call(true)");
  39. WScript.Echo(typeof x.valueOf.call(true)); //SHOULD print 'object' in ES5/IE10
  40. WScript.Echo("typeof x.valueOf.call(42)");
  41. WScript.Echo(typeof x.valueOf.call(42)); //SHOULD print 'object' in ES5/IE10
  42. WScript.Echo("typeof x.valueOf.call('Hello')");
  43. WScript.Echo(typeof x.valueOf.call('Hello')); //SHOULD print 'object' in ES5/IE10