Changeset 197999 in webkit


Ignore:
Timestamp:
Mar 10, 2016, 11:10:18 PM (9 years ago)
Author:
sbarati@apple.com
Message:

[ES6] Make RegExp.prototype.toString spec compliant
https://bugs.webkit.org/show_bug.cgi?id=155341

Reviewed by Filip Pizlo.

Before we were directly calling into the flagsString
function. Instead, we must get the "flags" property
of the thisObject. This will usually call into the flags
getter, but not always. Specifically, you can you a Proxy
to observe this behavior.

  • runtime/RegExpPrototype.cpp:

(JSC::regExpProtoFuncToString):
(JSC::regExpProtoGetterGlobal):

  • tests/es6.yaml:
  • tests/es6/Proxy_internal_get_calls_RegExp.prototype.toString.js: Added.

(test.get var):
(test.):

  • tests/stress/regexp-prototype-tostring.js: Added.

(assert):
(test):
(test.get var):
(test.):
(let.handler.get switch):
(let.handler):
(get test):
(test.get RegExp):

Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/js/regexp-toString-expected.txt

    r185528 r197999  
    1212PASS RegExp.prototype.toString.call(new RegExp('a')) is '/a/'
    1313PASS RegExp.prototype.toString.call(new RegExp('\\\\')) is '/\\\\/'
    14 PASS RegExp.prototype.toString.call({}) is '/undefined/'
    15 PASS RegExp.prototype.toString.call({source: 'hi'}) is '/hi/'
    16 PASS RegExp.prototype.toString.call({ __proto__: { source: 'yo' } }) is '/yo/'
    17 PASS RegExp.prototype.toString.call({source: ''}) is '//'
    18 PASS RegExp.prototype.toString.call({source: '/'}) is '///'
     14PASS RegExp.prototype.toString.call({}) is '/undefined/undefined'
     15PASS RegExp.prototype.toString.call({source: 'hi'}) is '/hi/undefined'
     16PASS RegExp.prototype.toString.call({ __proto__: { source: 'yo' } }) is '/yo/undefined'
     17PASS RegExp.prototype.toString.call({source: ''}) is '//undefined'
     18PASS RegExp.prototype.toString.call({source: '/'}) is '///undefined'
    1919PASS RegExp.prototype.toString.call(undefined) threw exception TypeError: Type error.
    2020PASS RegExp.prototype.toString.call(null) threw exception TypeError: Type error.
  • trunk/LayoutTests/js/script-tests/regexp-toString.js

    r185528 r197999  
    1111shouldBe("RegExp.prototype.toString.call(new RegExp('\\\\\\\\'))", "'/\\\\\\\\/'");
    1212
    13 shouldBe("RegExp.prototype.toString.call({})", "'/undefined/'");
    14 shouldBe("RegExp.prototype.toString.call({source: 'hi'})", "'/hi/'");
    15 shouldBe("RegExp.prototype.toString.call({ __proto__: { source: 'yo' } })", "'/yo/'");
    16 shouldBe("RegExp.prototype.toString.call({source: ''})", "'//'");
    17 shouldBe("RegExp.prototype.toString.call({source: '/'})", "'///'");
     13shouldBe("RegExp.prototype.toString.call({})", "'/undefined/undefined'");
     14shouldBe("RegExp.prototype.toString.call({source: 'hi'})", "'/hi/undefined'");
     15shouldBe("RegExp.prototype.toString.call({ __proto__: { source: 'yo' } })", "'/yo/undefined'");
     16shouldBe("RegExp.prototype.toString.call({source: ''})", "'//undefined'");
     17shouldBe("RegExp.prototype.toString.call({source: '/'})", "'///undefined'");
    1818
    1919shouldThrow("RegExp.prototype.toString.call(undefined)");
  • trunk/Source/JavaScriptCore/ChangeLog

    r197994 r197999  
     12016-03-10  Saam barati  <sbarati@apple.com>
     2
     3        [ES6] Make RegExp.prototype.toString spec compliant
     4        https://bugs.webkit.org/show_bug.cgi?id=155341
     5
     6        Reviewed by Filip Pizlo.
     7
     8        Before we were directly calling into the flagsString
     9        function. Instead, we must get the "flags" property
     10        of the thisObject. This will usually call into the flags
     11        getter, but not always. Specifically, you can you a Proxy
     12        to observe this behavior.
     13
     14        * runtime/RegExpPrototype.cpp:
     15        (JSC::regExpProtoFuncToString):
     16        (JSC::regExpProtoGetterGlobal):
     17        * tests/es6.yaml:
     18        * tests/es6/Proxy_internal_get_calls_RegExp.prototype.toString.js: Added.
     19        (test.get var):
     20        (test.):
     21        * tests/stress/regexp-prototype-tostring.js: Added.
     22        (assert):
     23        (test):
     24        (test.get var):
     25        (test.):
     26        (let.handler.get switch):
     27        (let.handler):
     28        (get test):
     29        (test.get RegExp):
     30
    1312016-03-10  Benjamin Poulain  <bpoulain@apple.com>
    232
  • trunk/Source/JavaScriptCore/runtime/RegExpPrototype.cpp

    r197869 r197999  
    209209        return JSValue::encode(earlyReturnValue);
    210210
    211     JSValue sourceValue = thisObject->get(exec, exec->propertyNames().source);
    212     if (exec->hadException())
     211    VM& vm = exec->vm();
     212    JSValue sourceValue = thisObject->get(exec, vm.propertyNames->source);
     213    if (vm.exception())
    213214        return JSValue::encode(jsUndefined());
    214215    String source = sourceValue.toString(exec)->value(exec);
    215     if (exec->hadException())
    216         return JSValue::encode(jsUndefined());
    217 
    218     auto flags = flagsString(exec, thisObject);
    219     if (exec->hadException())
    220         return JSValue::encode(jsUndefined());
    221 
    222     return JSValue::encode(jsMakeNontrivialString(exec, '/', source, '/', flags.data()));
     216    if (vm.exception())
     217        return JSValue::encode(jsUndefined());
     218
     219    JSValue flagsValue = thisObject->get(exec, vm.propertyNames->flags);
     220    if (vm.exception())
     221        return JSValue::encode(jsUndefined());
     222    String flags = flagsValue.toString(exec)->value(exec);
     223    if (vm.exception())
     224        return JSValue::encode(jsUndefined());
     225
     226    return JSValue::encode(jsMakeNontrivialString(exec, '/', source, '/', flags));
    223227}
    224228
  • trunk/Source/JavaScriptCore/tests/es6.yaml

    r197970 r197999  
    995995- path: es6/Proxy_internal_get_calls_RegExp.prototype.test.js
    996996  cmd: runES6 :fail
     997- path: es6/Proxy_internal_get_calls_RegExp.prototype.toString.js
     998  cmd: runES6 :normal
    997999- path: es6/Proxy_internal_get_calls_RegExp.prototype[Symbol.match].js
    9981000  cmd: runES6 :fail
Note: See TracChangeset for help on using the changeset viewer.