PageRenderTime 41ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/external/contributions/Google/sputnik_conformance_modified/15_Native/15.1_The_Global_Object/15.1.3_URI_Handling_Function_Properties/15.1.3.4_encodeURIComponent/S15.1.3.4_A6_T1.js

https://bitbucket.org/beala/test262
JavaScript | 78 lines | 53 code | 9 blank | 16 comment | 10 complexity | 8ab2de76421ec513682d95aac4b4ab2c MD5 | raw file
Possible License(s): BSD-3-Clause
  1. // Copyright 2009 the Sputnik authors. All rights reserved.
  2. // This code is governed by the BSD license found in the LICENSE file.
  3. /**
  4. * @name: S15.1.3.4_A6_T1;
  5. * @section: 15.1.3.4, 9.8, 8.6.2.6;
  6. * @assertion: Operator use ToString;
  7. * @description: If Type(value) is Object, evaluate ToPrimitive(value, String);
  8. */
  9. //CHECK#1
  10. var object = {valueOf: function() {return "^"}};
  11. if (encodeURIComponent(object) !== "%5Bobject%20Object%5D") {
  12. $ERROR('#1: var object = {valueOf: function() {return "^"}}; encodeURIComponent(object) === %5Bobject%20Object%5D. Actual: ' + (encodeURIComponent(object)));
  13. }
  14. //CHECK#2
  15. var object = {valueOf: function() {return ""}, toString: function() {return "^"}};
  16. if (encodeURIComponent(object) !== "%5E") {
  17. $ERROR('#2: var object = {valueOf: function() {return ""}, toString: function() {return "^"}}; encodeURIComponent(object) === "%5E". Actual: ' + (encodeURIComponent(object)));
  18. }
  19. //CHECK#3
  20. var object = {valueOf: function() {return "^"}, toString: function() {return {}}};
  21. if (encodeURIComponent(object) !== "%5E") {
  22. $ERROR('#3: var object = {valueOf: function() {return "^"}, toString: function() {return {}}}; encodeURIComponent(object) === "%5E". Actual: ' + (encodeURIComponent(object)));
  23. }
  24. //CHECK#4
  25. try {
  26. var object = {valueOf: function() {throw "error"}, toString: function() {return "^"}};
  27. if (encodeURIComponent(object) !== "%5E") {
  28. $ERROR('#4.1: var object = {valueOf: function() {throw "error"}, toString: function() {return "^"}}; encodeURIComponent(object) === "%5E". Actual: ' + (encodeURIComponent(object)));
  29. }
  30. }
  31. catch (e) {
  32. if (e === "error") {
  33. $ERROR('#4.2: var object = {valueOf: function() {throw "error"}, toString: function() {return "^"}}; encodeURIComponent(object) not throw "error"');
  34. } else {
  35. $ERROR('#4.3: var object = {valueOf: function() {throw "error"}, toString: function() {return "^"}}; encodeURIComponent(object) not throw Error. Actual: ' + (e));
  36. }
  37. }
  38. //CHECK#5
  39. var object = {toString: function() {return "^"}};
  40. if (encodeURIComponent(object) !== "%5E") {
  41. $ERROR('#5: var object = {toString: function() {return "^"}}; encodeURIComponent(object) === "%5E". Actual: ' + (encodeURIComponent(object)));
  42. }
  43. //CHECK#6
  44. var object = {valueOf: function() {return {}}, toString: function() {return "^"}}
  45. if (encodeURIComponent(object) !== "%5E") {
  46. $ERROR('#6: var object = {valueOf: function() {return {}}, toString: function() {return "^"}}; encodeURIComponent(object) === "%5E". Actual: ' + (encodeURIComponent(object)));
  47. }
  48. //CHECK#7
  49. try {
  50. var object = {valueOf: function() {return "^"}, toString: function() {throw "error"}};
  51. encodeURIComponent(object);
  52. $ERROR('#7.1: var object = {valueOf: function() {return "^"}, toString: function() {throw "error"}}; encodeURIComponent(object) throw "error". Actual: ' + (encodeURIComponent(object)));
  53. }
  54. catch (e) {
  55. if (e !== "error") {
  56. $ERROR('#7.2: var object = {valueOf: function() {return "^"}, toString: function() {throw "error"}}; encodeURIComponent(object) throw "error". Actual: ' + (e));
  57. }
  58. }
  59. //CHECK#8
  60. try {
  61. var object = {valueOf: function() {return {}}, toString: function() {return {}}};
  62. encodeURIComponent(object);
  63. $ERROR('#8.1: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; encodeURIComponent(object) throw TypeError. Actual: ' + (encodeURIComponent(object)));
  64. }
  65. catch (e) {
  66. if ((e instanceof TypeError) !== true) {
  67. $ERROR('#8.2: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; encodeURIComponent(object) throw TypeError. Actual: ' + (e));
  68. }
  69. }