crossContext.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 x = WScript.LoadScriptFile("crossContext_remoteContext.js", "samethread");
  7. var tests = {
  8. test01: {
  9. name: "Make sure when called with -nonative, marshaling of results is correct (Win8 628808)",
  10. body: function() {
  11. // Ñall this with -nonative
  12. // Win8 628808: the following cases used to cause an assertion.
  13. var str = "this is a sting";
  14. var result = str.match(x.re);
  15. var result = str.replace(x.re, null);
  16. var result = str.split(x.re, 1);
  17. var result = str.search(x.re);
  18. var result = x.str.match(x.re);
  19. var result = x.str.replace(x.re, null);
  20. var result = x.str.split(x.re, 1);
  21. var result = x.str.search(x.re);
  22. var result = x.strObject.match(x.re);
  23. var result = x.strObject.replace(x.re, null);
  24. var result = x.strObject.split(x.re, 1);
  25. var result = x.strObject.search(x.re);
  26. var result = String.prototype.replace.call(x.strObject, /forceNoMatch/, "");
  27. // The following cases are not impacted by Win8 628808, but it's worth verifying them for regressions in RegexHelper
  28. var result = x.str.replace(x.str, "I");
  29. var result = x.re.exec(x.str);
  30. var result = x.str.split(x.str, 1);
  31. var result = x.strObject.replace(x.strObject, "I");
  32. var result = x.re.exec(x.strObject);
  33. var result = x.strObject.split(x.strObject, 1);
  34. }
  35. },
  36. test02: {
  37. name: "lastIndex behavior",
  38. body: function() {
  39. x.reg.exec("_this_");
  40. assert.areEqual(5, x.reg.lastIndex, "wrong x.reg.lastIndex");
  41. }
  42. },
  43. test03: {
  44. name: "Updating $1, $2,.. behavior",
  45. body: function() {
  46. // Disabled for IE9-compat mode due to Win8 xxxxxxx.
  47. // TODO: re-enable when the bug is fixed.
  48. if (helpers.isVersion10OrLater) {
  49. "this".match(x.rep);
  50. assert.areEqual("t", RegExp.$1, "RegExp.$1 in local context wasn't updated to the capture group");
  51. }
  52. }
  53. },
  54. test04: {
  55. name: "Check in which context the results are created",
  56. body: function() {
  57. var result = "this".match(x.re);
  58. var expected = helpers.isVersion10OrLater ? Array : x.Array;
  59. assert.areEqual(expected, result.constructor, "The result should be created in local context");
  60. }
  61. },
  62. }
  63. testRunner.run(tests);