Title: [251483] trunk
Revision
251483
Author
ross.kirsl...@sony.com
Date
2019-10-23 11:45:37 -0700 (Wed, 23 Oct 2019)

Log Message

String.prototype.matchAll should throw on non-global regex
https://bugs.webkit.org/show_bug.cgi?id=202838

Reviewed by Keith Miller.

JSTests:

* stress/string-matchall.js: Added.

* test262/expectations.yaml:
Mark four test cases as passing.

Source/_javascript_Core:

* builtins/StringPrototype.js:
(matchAll):
Implement normative change from https://github.com/tc39/ecma262/pull/1716.

* builtins/BuiltinNames.h:
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):
* runtime/RegExpConstructor.cpp:
(JSC::esSpecIsRegExp): Added.
* runtime/RegExpConstructor.h:
Expose isRegExp to builtins. (This differs from @isRegExpObject by first checking for Symbol.match.)

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (251482 => 251483)


--- trunk/JSTests/ChangeLog	2019-10-23 18:29:29 UTC (rev 251482)
+++ trunk/JSTests/ChangeLog	2019-10-23 18:45:37 UTC (rev 251483)
@@ -1,5 +1,17 @@
 2019-10-23  Ross Kirsling  <ross.kirsl...@sony.com>
 
+        String.prototype.matchAll should throw on non-global regex
+        https://bugs.webkit.org/show_bug.cgi?id=202838
+
+        Reviewed by Keith Miller.
+
+        * stress/string-matchall.js: Added.
+
+        * test262/expectations.yaml:
+        Mark four test cases as passing.
+
+2019-10-23  Ross Kirsling  <ross.kirsl...@sony.com>
+
         Update test262 (2019.10.11)
         https://bugs.webkit.org/show_bug.cgi?id=202861
 

Added: trunk/JSTests/stress/string-matchall.js (0 => 251483)


--- trunk/JSTests/stress/string-matchall.js	                        (rev 0)
+++ trunk/JSTests/stress/string-matchall.js	2019-10-23 18:45:37 UTC (rev 251483)
@@ -0,0 +1,30 @@
+function shouldBe(actual, expected) {
+    if (actual !== expected)
+        throw new Error(`expected ${expected} but got ${actual}`);
+}
+
+function shouldNotThrow(func) {
+  func();
+}
+
+function shouldThrowTypeError(func) {
+    let error;
+    try {
+        func();
+    } catch (e) {
+        error = e;
+    }
+
+    if (!(error instanceof TypeError))
+        throw new Error('Expected TypeError!');
+}
+
+shouldThrowTypeError(() => { 'abaca'.matchAll(/a/); });
+shouldThrowTypeError(() => { 'abaca'.matchAll(new RegExp('a')); });
+shouldThrowTypeError(() => { 'abaca'.matchAll({ [Symbol.match]() {} }); });
+
+shouldNotThrow(() => { 'abaca'.matchAll({ [Symbol.match]() {}, flags: 'g' }); });
+
+shouldBe([...'abaca'.matchAll(/a/g)].join(), 'a,a,a');
+shouldBe([...'abaca'.matchAll(new RegExp('a', 'g'))].join(), 'a,a,a');
+shouldBe([...'abaca'.matchAll({ [Symbol.matchAll]: RegExp.prototype[Symbol.matchAll].bind(/a/g) })].join(), 'a,a,a');

Modified: trunk/JSTests/test262/expectations.yaml (251482 => 251483)


--- trunk/JSTests/test262/expectations.yaml	2019-10-23 18:29:29 UTC (rev 251482)
+++ trunk/JSTests/test262/expectations.yaml	2019-10-23 18:45:37 UTC (rev 251483)
@@ -1804,12 +1804,6 @@
 test/built-ins/String/proto-from-ctor-realm.js:
   default: 'Test262Error: Expected SameValue(«», «») to be true'
   strict mode: 'Test262Error: Expected SameValue(«», «») to be true'
-test/built-ins/String/prototype/matchAll/flags-nonglobal-throws.js:
-  default: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
-  strict mode: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
-test/built-ins/String/prototype/matchAll/flags-undefined-throws.js:
-  default: 'Test262Error: Expected a TypeError but got a SyntaxError'
-  strict mode: 'Test262Error: Expected a TypeError but got a SyntaxError'
 test/built-ins/ThrowTypeError/extensible.js:
   default: 'Test262Error: Expected SameValue(«true», «false») to be true'
   strict mode: 'Test262Error: Expected SameValue(«true», «false») to be true'

Modified: trunk/Source/_javascript_Core/ChangeLog (251482 => 251483)


--- trunk/Source/_javascript_Core/ChangeLog	2019-10-23 18:29:29 UTC (rev 251482)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-10-23 18:45:37 UTC (rev 251483)
@@ -1,3 +1,22 @@
+2019-10-23  Ross Kirsling  <ross.kirsl...@sony.com>
+
+        String.prototype.matchAll should throw on non-global regex
+        https://bugs.webkit.org/show_bug.cgi?id=202838
+
+        Reviewed by Keith Miller.
+
+        * builtins/StringPrototype.js:
+        (matchAll):
+        Implement normative change from https://github.com/tc39/ecma262/pull/1716.
+
+        * builtins/BuiltinNames.h:
+        * runtime/JSGlobalObject.cpp:
+        (JSC::JSGlobalObject::init):
+        * runtime/RegExpConstructor.cpp:
+        (JSC::esSpecIsRegExp): Added.
+        * runtime/RegExpConstructor.h:
+        Expose isRegExp to builtins. (This differs from @isRegExpObject by first checking for Symbol.match.)
+
 2019-10-23  Sihui Liu  <sihui_...@apple.com>
 
         [ Mac WK1 ] REGRESSION (r251261): Layout Test inspector/console/webcore-logging.html is consistently Failing

Modified: trunk/Source/_javascript_Core/builtins/BuiltinNames.h (251482 => 251483)


--- trunk/Source/_javascript_Core/builtins/BuiltinNames.h	2019-10-23 18:29:29 UTC (rev 251482)
+++ trunk/Source/_javascript_Core/builtins/BuiltinNames.h	2019-10-23 18:45:37 UTC (rev 251483)
@@ -126,6 +126,7 @@
     macro(concatMemcpy) \
     macro(appendMemcpy) \
     macro(regExpCreate) \
+    macro(isRegExp) \
     macro(replaceUsingRegExp) \
     macro(replaceUsingStringSearch) \
     macro(makeTypeError) \

Modified: trunk/Source/_javascript_Core/builtins/StringPrototype.js (251482 => 251483)


--- trunk/Source/_javascript_Core/builtins/StringPrototype.js	2019-10-23 18:29:29 UTC (rev 251482)
+++ trunk/Source/_javascript_Core/builtins/StringPrototype.js	2019-10-23 18:45:37 UTC (rev 251483)
@@ -51,6 +51,9 @@
         @throwTypeError("String.prototype.matchAll requires |this| not to be null nor undefined");
 
     if (!@isUndefinedOrNull(arg)) {
+        if (@isRegExp(arg) && !@stringIncludesInternal.@call(@toString(arg.flags), "g"))
+            @throwTypeError("String.prototype.matchAll argument must not be a non-global regular _expression_");
+
         let matcher = arg.@matchAllSymbol;
         if (!@isUndefinedOrNull(matcher))
             return matcher.@call(arg, this);

Modified: trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp (251482 => 251483)


--- trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp	2019-10-23 18:29:29 UTC (rev 251482)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp	2019-10-23 18:45:37 UTC (rev 251483)
@@ -1036,6 +1036,7 @@
         // RegExp.prototype helpers.
         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpBuiltinExecPrivateName(), builtinRegExpExec, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpCreatePrivateName(), JSFunction::create(vm, this, 2, String(), esSpecRegExpCreate, NoIntrinsic), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
+        GlobalPropertyInfo(vm.propertyNames->builtinNames().isRegExpPrivateName(), JSFunction::create(vm, this, 1, String(), esSpecIsRegExp, NoIntrinsic), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpMatchFastPrivateName(), JSFunction::create(vm, this, 1, String(), regExpProtoFuncMatchFast, RegExpMatchFastIntrinsic), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpSearchFastPrivateName(), JSFunction::create(vm, this, 1, String(), regExpProtoFuncSearchFast), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpSplitFastPrivateName(), JSFunction::create(vm, this, 2, String(), regExpProtoFuncSplitFast), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),

Modified: trunk/Source/_javascript_Core/runtime/RegExpConstructor.cpp (251482 => 251483)


--- trunk/Source/_javascript_Core/runtime/RegExpConstructor.cpp	2019-10-23 18:29:29 UTC (rev 251482)
+++ trunk/Source/_javascript_Core/runtime/RegExpConstructor.cpp	2019-10-23 18:45:37 UTC (rev 251483)
@@ -277,6 +277,12 @@
     return JSValue::encode(regExpCreate(globalObject, jsUndefined(), patternArg, flagsArg));
 }
 
+EncodedJSValue JSC_HOST_CALL esSpecIsRegExp(JSGlobalObject* globalObject, CallFrame* callFrame)
+{
+    VM& vm = globalObject->vm();
+    return JSValue::encode(jsBoolean(isRegExp(vm, globalObject, callFrame->argument(0))));
+}
+
 static EncodedJSValue JSC_HOST_CALL constructWithRegExpConstructor(JSGlobalObject* globalObject, CallFrame* callFrame)
 {
     ArgList args(callFrame);

Modified: trunk/Source/_javascript_Core/runtime/RegExpConstructor.h (251482 => 251483)


--- trunk/Source/_javascript_Core/runtime/RegExpConstructor.h	2019-10-23 18:29:29 UTC (rev 251482)
+++ trunk/Source/_javascript_Core/runtime/RegExpConstructor.h	2019-10-23 18:45:37 UTC (rev 251483)
@@ -76,5 +76,6 @@
 }
 
 EncodedJSValue JSC_HOST_CALL esSpecRegExpCreate(JSGlobalObject*, CallFrame*);
+EncodedJSValue JSC_HOST_CALL esSpecIsRegExp(JSGlobalObject*, CallFrame*);
 
 } // namespace JSC
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to