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

/deps/v8/test/webkit/continue-break-multiple-labels.js

http://github.com/joyent/node
JavaScript | 111 lines | 69 code | 20 blank | 22 comment | 11 complexity | ac28def24ad3e8cc2f02c80c7474a955 MD5 | raw file
Possible License(s): 0BSD, BSD-3-Clause, MPL-2.0-no-copyleft-exception, GPL-2.0, ISC, Apache-2.0, MIT, AGPL-3.0
  1. // Copyright 2013 the V8 project authors. All rights reserved.
  2. // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions
  6. // are met:
  7. // 1. Redistributions of source code must retain the above copyright
  8. // notice, this list of conditions and the following disclaimer.
  9. // 2. Redistributions in binary form must reproduce the above copyright
  10. // notice, this list of conditions and the following disclaimer in the
  11. // documentation and/or other materials provided with the distribution.
  12. //
  13. // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
  14. // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  17. // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  18. // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19. // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  20. // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. description(
  24. 'This test checks break and continue behaviour in the presence of multiple labels.'
  25. );
  26. function test1()
  27. {
  28. var s = "";
  29. a:
  30. b:
  31. for (var i = 1; i < 10; i++) {
  32. if (i == 4)
  33. continue a;
  34. s += i;
  35. }
  36. return s;
  37. }
  38. shouldBe("test1()", "'12356789'");
  39. function test2()
  40. {
  41. var s = "";
  42. a:
  43. b:
  44. for (var i = 1; i < 10; i++) {
  45. if (i == 4)
  46. break a;
  47. s += i;
  48. }
  49. return s;
  50. }
  51. shouldBe("test2()", "'123'");
  52. function test3()
  53. {
  54. var i;
  55. for (i = 1; i < 10; i++) {
  56. try {
  57. continue;
  58. } finally {
  59. innerLoop:
  60. while (1) {
  61. break innerLoop;
  62. }
  63. }
  64. }
  65. return i;
  66. }
  67. shouldBe("test3()", "10");
  68. function test4()
  69. {
  70. var i = 0;
  71. a:
  72. i++;
  73. while (1) {
  74. break;
  75. }
  76. return i;
  77. }
  78. shouldBe("test4()", "1");
  79. function test5()
  80. {
  81. var i = 0;
  82. switch (1) {
  83. default:
  84. while (1) {
  85. break;
  86. }
  87. i++;
  88. }
  89. return i;
  90. }
  91. shouldBe("test5()", "1");