소스 검색

Have RegExp.prototype.flags work correctly when 'unicode' and 'sticky' features are disabled

Gorkem Yakin 10 년 전
부모
커밋
a9a88b7ee7
3개의 변경된 파일42개의 추가작업 그리고 3개의 파일을 삭제
  1. 12 2
      lib/Runtime/Library/JavascriptRegularExpression.cpp
  2. 23 0
      test/es6/regexflags-disabled-features.js
  3. 7 1
      test/es6/rlexe.xml

+ 12 - 2
lib/Runtime/Library/JavascriptRegularExpression.cpp

@@ -614,8 +614,18 @@ namespace Js
             APPEND_FLAG(PropertyIds::global, L'g');
             APPEND_FLAG(PropertyIds::ignoreCase, L'i');
             APPEND_FLAG(PropertyIds::multiline, L'm');
-            APPEND_FLAG(PropertyIds::unicode, L'u');
-            APPEND_FLAG(PropertyIds::sticky, L'y');
+
+            ScriptConfiguration const * scriptConfig = scriptContext->GetConfig();
+
+            if (scriptConfig->IsES6UnicodeExtensionsEnabled())
+            {
+                APPEND_FLAG(PropertyIds::unicode, L'u');
+            }
+
+            if (scriptConfig->IsES6RegExStickyEnabled())
+            {
+                APPEND_FLAG(PropertyIds::sticky, L'y');
+            }
 #undef APPEND_FLAG
 
             flags = Js::JavascriptString::NewCopyBuffer(bs.Detach(), bs.Count(), scriptContext);

+ 23 - 0
test/es6/regexflags-disabled-features.js

@@ -0,0 +1,23 @@
+//-------------------------------------------------------------------------------------------------------
+// Copyright (C) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
+WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
+
+var tests =
+    [['sticky', 'y'],
+     ['unicode', 'u']].map(function ([propertyName, flag]) {
+        return {
+            name: "RegExp.prototype.flags should not include the '" + propertyName + "' flag when the feature is disabled",
+            body: function () {
+                var object = {};
+                object[propertyName] = true;
+                var getFlags = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get;
+                var flags = getFlags.call(object);
+                assert.isFalse(flags.includes(flag));
+            }
+        };
+     });
+
+testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });

+ 7 - 1
test/es6/rlexe.xml

@@ -912,7 +912,13 @@
   <test>
     <default>
       <files>regexflags.js</files>
-      <compile-flags>-version:6 -ES6RegExSticky -ES6RegExPrototypeProperties -ES6Destructuring -args summary -endargs</compile-flags>
+      <compile-flags>-version:6 -ES6RegExSticky -ES6Unicode -ES6RegExPrototypeProperties -ES6Destructuring -args summary -endargs</compile-flags>
+    </default>
+  </test>
+  <test>
+    <default>
+      <files>regexflags-disabled-features.js</files>
+      <compile-flags>-ES6RegExSticky- -ES6Unicode- -ES6RegExPrototypeProperties -ES6Destructuring -args summary -endargs</compile-flags>
     </default>
   </test>
   <test>