PageRenderTime 63ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/webview/native/Source/JavaScriptCore/tests/mozilla/ecma_3/Function/regress-97921.js

https://bitbucket.org/rbair/rbair-controls-8
JavaScript | 131 lines | 77 code | 23 blank | 31 comment | 2 complexity | 7bf780bdf8d82533817d72ce6cfbb3f6 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0, LGPL-2.0
  1. /*
  2. * The contents of this file are subject to the Netscape Public
  3. * License Version 1.1 (the "License"); you may not use this file
  4. * except in compliance with the License. You may obtain a copy of
  5. * the License at http://www.mozilla.org/NPL/
  6. *
  7. * Software distributed under the License is distributed on an "AS
  8. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9. * implied. See the License for the specific language governing
  10. * rights and limitations under the License.
  11. *
  12. * The Original Code is mozilla.org code.
  13. *
  14. * The Initial Developer of the Original Code is Netscape
  15. * Communications Corporation. Portions created by Netscape are
  16. * Copyright (C) 1998 Netscape Communications Corporation. All
  17. * Rights Reserved.
  18. *
  19. * Contributor(s): georg@bioshop.de, pschwartau@netscape.com
  20. * Date: 10 September 2001
  21. *
  22. * SUMMARY: Testing with() statement with nested functions
  23. * See http://bugzilla.mozilla.org/show_bug.cgi?id=97921
  24. *
  25. * Brendan: "The bug is peculiar to functions that have formal parameters,
  26. * but that are called with fewer actual arguments than the declared number
  27. * of formal parameters."
  28. */
  29. //-----------------------------------------------------------------------------
  30. var UBound = 0;
  31. var bug = 97921;
  32. var summary = 'Testing with() statement with nested functions';
  33. var cnYES = 'Inner value === outer value';
  34. var cnNO = "Inner value !== outer value!";
  35. var status = '';
  36. var statusitems = [];
  37. var actual = '';
  38. var actualvalues = [];
  39. var expect= '';
  40. var expectedvalues = [];
  41. var outerValue = '';
  42. var innerValue = '';
  43. var useWith = '';
  44. function F(i)
  45. {
  46. i = 0;
  47. if(useWith) with(1){i;}
  48. i++;
  49. outerValue = i; // capture value of i in outer function
  50. F1 = function() {innerValue = i;}; // capture value of i in inner function
  51. F1();
  52. }
  53. status = inSection(1);
  54. useWith=false;
  55. F(); // call F without supplying the argument
  56. actual = innerValue === outerValue;
  57. expect = true;
  58. addThis();
  59. status = inSection(2);
  60. useWith=true;
  61. F(); // call F without supplying the argument
  62. actual = innerValue === outerValue;
  63. expect = true;
  64. addThis();
  65. function G(i)
  66. {
  67. i = 0;
  68. with (new Object()) {i=100};
  69. i++;
  70. outerValue = i; // capture value of i in outer function
  71. G1 = function() {innerValue = i;}; // capture value of i in inner function
  72. G1();
  73. }
  74. status = inSection(3);
  75. G(); // call G without supplying the argument
  76. actual = innerValue === 101;
  77. expect = true;
  78. addThis();
  79. status = inSection(4);
  80. G(); // call G without supplying the argument
  81. actual = innerValue === outerValue;
  82. expect = true;
  83. addThis();
  84. //-----------------------------------------------------------------------------
  85. test();
  86. //-----------------------------------------------------------------------------
  87. function addThis()
  88. {
  89. statusitems[UBound] = status;
  90. actualvalues[UBound] = areTheseEqual(actual);
  91. expectedvalues[UBound] = areTheseEqual(expect);
  92. UBound++;
  93. }
  94. function test()
  95. {
  96. enterFunc ('test');
  97. printBugNumber (bug);
  98. printStatus (summary);
  99. for (var i = 0; i < UBound; i++)
  100. {
  101. reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
  102. }
  103. exitFunc ('test');
  104. }
  105. function areTheseEqual(yes)
  106. {
  107. return yes? cnYES : cnNO
  108. }