propertyDescriptorNonObject.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
  6. var tests = [
  7. {
  8. name: "Object.create with propertyDescriptor containing non-object keys",
  9. body: function() {
  10. assert.throws(function() { Object.create({}, {a: 0}) },
  11. TypeError,
  12. "Should throw TypeError because property 'a' is not an object.",
  13. "Invalid descriptor for property 'a'")
  14. }
  15. },
  16. {
  17. name: "Object.defineProperty with number for propertyDescriptor",
  18. body: function() {
  19. assert.throws(function() { Object.defineProperty({}, "x", 0) },
  20. TypeError,
  21. "Should throw TypeError because property 'x' is a number.",
  22. "Invalid descriptor for property 'x'")
  23. }
  24. },
  25. {
  26. name: "Object.create with array of non-objects for propertyDescriptor",
  27. body: function() {
  28. assert.throws(function() { Object.create({}, [0]) },
  29. TypeError,
  30. "Should throw TypeError because propertyDescriptor is an array containing non-objects.",
  31. "Invalid descriptor for property '0'")
  32. }
  33. },
  34. {
  35. name: "Object.create in sloppy mode with `this` as a propertyDescriptor when it contains non-object properties",
  36. body: function() {
  37. a = 0;
  38. assert.throws(function() { Object.create({}, this) },
  39. TypeError,
  40. "Should throw TypeError because property 'a' is defined on `this` and is a non-object.",
  41. "Invalid descriptor for property 'a'")
  42. }
  43. },
  44. ];
  45. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });