⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 185432 in webkit


Ignore:
Timestamp:
Jun 10, 2015, 3:32:36 PM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Implement RegExp.prototype.flags
​https://bugs.webkit.org/show_bug.cgi?id=145599

Patch by Jordan Harband <​ljharb@gmail.com> on 2015-06-10
Reviewed by Geoffrey Garen.
Source/JavaScriptCore:

Per ​https://people.mozilla.org/~jorendorff/es6-draft.html#sec-get-regexp.prototype.flags

  • runtime/CommonIdentifiers.h:
  • runtime/RegExpPrototype.cpp:

(JSC::flagsString):
(JSC::regExpProtoFuncToString):
(JSC::regExpProtoGetterFlags):

  • tests/stress/static-getter-in-names.js:

LayoutTests:

  • js/Object-getOwnPropertyNames-expected.txt:
  • js/regexp-flags-expected.txt: Added.
  • js/regexp-flags.html: Added.
  • js/script-tests/Object-getOwnPropertyNames.js:
  • js/script-tests/regexp-flags.js: Added.

(.get shouldBe):

Location:
trunk
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r185430 r185432  
     12015-06-10  Jordan Harband  <ljharb@gmail.com>
     2
     3        Implement RegExp.prototype.flags
     4        https://bugs.webkit.org/show_bug.cgi?id=145599
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * js/Object-getOwnPropertyNames-expected.txt:
     9        * js/regexp-flags-expected.txt: Added.
     10        * js/regexp-flags.html: Added.
     11        * js/script-tests/Object-getOwnPropertyNames.js:
     12        * js/script-tests/regexp-flags.js: Added.
     13        (.get shouldBe):
     14
    1152015-06-10  Alex Christensen  <achristensen@webkit.org>
    216
  • trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt

    r185370 r185432  
    5757PASS getSortedOwnPropertyNames(Date.prototype) is ['constructor', 'getDate', 'getDay', 'getFullYear', 'getHours', 'getMilliseconds', 'getMinutes', 'getMonth', 'getSeconds', 'getTime', 'getTimezoneOffset', 'getUTCDate', 'getUTCDay', 'getUTCFullYear', 'getUTCHours', 'getUTCMilliseconds', 'getUTCMinutes', 'getUTCMonth', 'getUTCSeconds', 'getYear', 'setDate', 'setFullYear', 'setHours', 'setMilliseconds', 'setMinutes', 'setMonth', 'setSeconds', 'setTime', 'setUTCDate', 'setUTCFullYear', 'setUTCHours', 'setUTCMilliseconds', 'setUTCMinutes', 'setUTCMonth', 'setUTCSeconds', 'setYear', 'toDateString', 'toGMTString', 'toISOString', 'toJSON', 'toLocaleDateString', 'toLocaleString', 'toLocaleTimeString', 'toString', 'toTimeString', 'toUTCString', 'valueOf']
    5858PASS getSortedOwnPropertyNames(RegExp) is ['$&', "$'", '$*', '$+', '$1', '$2', '$3', '$4', '$5', '$6', '$7', '$8', '$9', '$_', '$`', 'input', 'lastMatch', 'lastParen', 'leftContext', 'length', 'multiline', 'name', 'prototype', 'rightContext']
    59 PASS getSortedOwnPropertyNames(RegExp.prototype) is ['compile', 'constructor', 'exec', 'global', 'ignoreCase', 'lastIndex', 'multiline', 'source', 'test', 'toString']
     59PASS getSortedOwnPropertyNames(RegExp.prototype) is ['compile', 'constructor', 'exec', 'flags', 'global', 'ignoreCase', 'lastIndex', 'multiline', 'source', 'test', 'toString']
    6060PASS getSortedOwnPropertyNames(Error) is ['length', 'name', 'prototype']
    6161PASS getSortedOwnPropertyNames(Error.prototype) is ['constructor', 'message', 'name', 'toString']
  • trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js

    r185370 r185432  
    6666    "Date.prototype": "['constructor', 'getDate', 'getDay', 'getFullYear', 'getHours', 'getMilliseconds', 'getMinutes', 'getMonth', 'getSeconds', 'getTime', 'getTimezoneOffset', 'getUTCDate', 'getUTCDay', 'getUTCFullYear', 'getUTCHours', 'getUTCMilliseconds', 'getUTCMinutes', 'getUTCMonth', 'getUTCSeconds', 'getYear', 'setDate', 'setFullYear', 'setHours', 'setMilliseconds', 'setMinutes', 'setMonth', 'setSeconds', 'setTime', 'setUTCDate', 'setUTCFullYear', 'setUTCHours', 'setUTCMilliseconds', 'setUTCMinutes', 'setUTCMonth', 'setUTCSeconds', 'setYear', 'toDateString', 'toGMTString', 'toISOString', 'toJSON', 'toLocaleDateString', 'toLocaleString', 'toLocaleTimeString', 'toString', 'toTimeString', 'toUTCString', 'valueOf']",
    6767    "RegExp": "['$&', \"$'\", '$*', '$+', '$1', '$2', '$3', '$4', '$5', '$6', '$7', '$8', '$9', '$_', '$`', 'input', 'lastMatch', 'lastParen', 'leftContext', 'length', 'multiline', 'name', 'prototype', 'rightContext']",
    68     "RegExp.prototype": "['compile', 'constructor', 'exec', 'global', 'ignoreCase', 'lastIndex', 'multiline', 'source', 'test', 'toString']",
     68    "RegExp.prototype": "['compile', 'constructor', 'exec', 'flags', 'global', 'ignoreCase', 'lastIndex', 'multiline', 'source', 'test', 'toString']",
    6969    "Error": "['length', 'name', 'prototype']",
    7070    "Error.prototype": "['constructor', 'message', 'name', 'toString']",
  • trunk/Source/JavaScriptCore/ChangeLog

    r185427 r185432  
     12015-06-10  Jordan Harband  <ljharb@gmail.com>
     2
     3        Implement RegExp.prototype.flags
     4        https://bugs.webkit.org/show_bug.cgi?id=145599
     5
     6        Reviewed by Geoffrey Garen.
     7        Per https://people.mozilla.org/~jorendorff/es6-draft.html#sec-get-regexp.prototype.flags
     8
     9        * runtime/CommonIdentifiers.h:
     10        * runtime/RegExpPrototype.cpp:
     11        (JSC::flagsString):
     12        (JSC::regExpProtoFuncToString):
     13        (JSC::regExpProtoGetterFlags):
     14        * tests/stress/static-getter-in-names.js:
     15
    1162015-06-10  Filip Pizlo  <fpizlo@apple.com>
    217
  • trunk/Source/JavaScriptCore/runtime/CommonIdentifiers.h

    r185322 r185432  
    104104    macro(executionCount) \
    105105    macro(exitKind) \
     106    macro(flags) \
    106107    macro(focus) \
    107108    macro(forEach) \
  • trunk/Source/JavaScriptCore/runtime/RegExpPrototype.cpp

    r185370 r185432  
    4848static EncodedJSValue JSC_HOST_CALL regExpProtoGetterMultiline(ExecState*);
    4949static EncodedJSValue JSC_HOST_CALL regExpProtoGetterSource(ExecState*);
     50static EncodedJSValue JSC_HOST_CALL regExpProtoGetterFlags(ExecState*);
    5051
    5152}
    … …  
    6768  multiline     regExpProtoGetterMultiline  DontEnum|Accessor
    6869  source        regExpProtoGetterSource     DontEnum|Accessor
     70  flags         regExpProtoGetterFlags      DontEnum|Accessor
    6971@end
    7072*/
    … …  
    136138}
    137139
     140static inline String flagsString(ExecState *exec, JSObject* regexp)
     141{
     142    char flags[4] = { 0, 0, 0, 0 };
     143    int index = 0;
     144
     145    JSValue globalValue = regexp->get(exec, exec->propertyNames().global);
     146    if (exec->hadException())
     147        return String();
     148    JSValue ignoreCaseValue = regexp->get(exec, exec->propertyNames().ignoreCase);
     149    if (exec->hadException())
     150        return String();
     151    JSValue multilineValue = regexp->get(exec, exec->propertyNames().multiline);
     152    if (exec->hadException())
     153        return String();
     154
     155    if (globalValue.toBoolean(exec))
     156        flags[index++] = 'g';
     157    if (ignoreCaseValue.toBoolean(exec))
     158        flags[index++] = 'i';
     159    if (multilineValue.toBoolean(exec))
     160        flags[index] = 'm';
     161    return String(flags);
     162}
     163
    138164EncodedJSValue JSC_HOST_CALL regExpProtoFuncToString(ExecState* exec)
    139165{
    … …  
    148174        return JSValue::encode(earlyReturnValue);
    149175
    150     char postfix[5] = { '/', 0, 0, 0, 0 };
    151     int index = 1;
    152     if (thisObject->get(exec, exec->propertyNames().global).toBoolean(exec))
    153         postfix[index++] = 'g';
    154     if (thisObject->get(exec, exec->propertyNames().ignoreCase).toBoolean(exec))
    155         postfix[index++] = 'i';
    156     if (thisObject->get(exec, exec->propertyNames().multiline).toBoolean(exec))
    157         postfix[index] = 'm';
    158     String source = thisObject->get(exec, exec->propertyNames().source).toString(exec)->value(exec);
     176    JSValue sourceValue = thisObject->get(exec, exec->propertyNames().source);
     177    if (exec->hadException())
     178        return JSValue::encode(jsUndefined());
     179    String source = sourceValue.toString(exec)->value(exec);
     180    if (exec->hadException())
     181        return JSValue::encode(jsUndefined());
     182
     183    String flags = flagsString(exec, thisObject);
     184    if (exec->hadException())
     185        return JSValue::encode(jsUndefined());
     186
    159187    // If source is empty, use "/(?:)/" to avoid colliding with comment syntax
    160     return JSValue::encode(jsMakeNontrivialString(exec, "/", source, postfix));
     188    return JSValue::encode(jsMakeNontrivialString(exec, "/", source, "/", flags));
    161189}
    162190
    … …  
    187215    return JSValue::encode(jsBoolean(asRegExpObject(thisValue)->regExp()->multiline()));
    188216}
     217
     218EncodedJSValue JSC_HOST_CALL regExpProtoGetterFlags(ExecState* exec)
     219{
     220    JSValue thisValue = exec->thisValue();
     221    if (!thisValue.isObject())
     222        return JSValue::encode(throwTypeError(exec));
     223
     224    String flagsStr = flagsString(exec, asObject(thisValue));
     225    if (exec->hadException())
     226        return JSValue::encode(jsUndefined());
     227
     228    JSValue flags = jsMakeNontrivialString(exec, flagsStr);
     229    return JSValue::encode(flags);
     230}
     231
    189232
    190233template <typename CharacterType>
  • trunk/Source/JavaScriptCore/tests/stress/static-getter-in-names.js

    r185370 r185432  
    44}
    55
    6 shouldBe(JSON.stringify(Object.getOwnPropertyNames(RegExp.prototype).sort()), '["compile","constructor","exec","global","ignoreCase","lastIndex","multiline","source","test","toString"]');
     6shouldBe(JSON.stringify(Object.getOwnPropertyNames(RegExp.prototype).sort()), '["compile","constructor","exec","flags","global","ignoreCase","lastIndex","multiline","source","test","toString"]');
    77shouldBe(JSON.stringify(Object.getOwnPropertyNames(/Cocoa/).sort()), '["lastIndex"]');
Note: See TracChangeset for help on using the changeset viewer.