ErrorCtorProps.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 ctors = [Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError];
  6. safeCall(eval, "ctors.push(RegExpError);");
  7. safeCall(eval, "ctors.push(ConversionError);");
  8. var props = ["message", "name", "description", "call", "apply"];
  9. for (var i in ctors)
  10. {
  11. Test(ctors[i]);
  12. }
  13. function Test(ctor)
  14. {
  15. WScript.Echo("---------------------------------");
  16. WScript.Echo("toString(): " + ctor.toString());
  17. for (var j in props)
  18. {
  19. var prop = props[j];
  20. WScript.Echo("Property: '" + prop + "'");
  21. WScript.Echo("Value: '" + ctor[prop] + "'");
  22. WScript.Echo("hasOwnProperty: " + ctor.hasOwnProperty(prop));
  23. }
  24. WScript.Echo();
  25. }
  26. function safeCall(f) {
  27. var args = [];
  28. for (var a = 1; a < arguments.length; ++a)
  29. args.push(arguments[a]);
  30. try {
  31. return f.apply(this, args);
  32. } catch (ex) {
  33. WScript.Echo(ex.name + ": " + ex.message);
  34. }
  35. }