Diff
Modified: trunk/LayoutTests/ChangeLog (185431 => 185432)
--- trunk/LayoutTests/ChangeLog 2015-06-10 21:53:42 UTC (rev 185431)
+++ trunk/LayoutTests/ChangeLog 2015-06-10 22:32:36 UTC (rev 185432)
@@ -1,3 +1,17 @@
+2015-06-10 Jordan Harband <[email protected]>
+
+ Implement RegExp.prototype.flags
+ https://bugs.webkit.org/show_bug.cgi?id=145599
+
+ Reviewed by Geoffrey Garen.
+
+ * 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):
+
2015-06-10 Alex Christensen <[email protected]>
Move all content extension tests to same directory to fix flakiness.
Modified: trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt (185431 => 185432)
--- trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt 2015-06-10 21:53:42 UTC (rev 185431)
+++ trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt 2015-06-10 22:32:36 UTC (rev 185432)
@@ -56,7 +56,7 @@
PASS getSortedOwnPropertyNames(Date) is ['UTC', 'length', 'name', 'now', 'parse', 'prototype']
PASS 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']
PASS getSortedOwnPropertyNames(RegExp) is ['$&', "$'", '$*', '$+', '$1', '$2', '$3', '$4', '$5', '$6', '$7', '$8', '$9', '$_', '$`', 'input', 'lastMatch', 'lastParen', 'leftContext', 'length', 'multiline', 'name', 'prototype', 'rightContext']
-PASS getSortedOwnPropertyNames(RegExp.prototype) is ['compile', 'constructor', 'exec', 'global', 'ignoreCase', 'lastIndex', 'multiline', 'source', 'test', 'toString']
+PASS getSortedOwnPropertyNames(RegExp.prototype) is ['compile', 'constructor', 'exec', 'flags', 'global', 'ignoreCase', 'lastIndex', 'multiline', 'source', 'test', 'toString']
PASS getSortedOwnPropertyNames(Error) is ['length', 'name', 'prototype']
PASS getSortedOwnPropertyNames(Error.prototype) is ['constructor', 'message', 'name', 'toString']
PASS getSortedOwnPropertyNames(Math) is ['E','LN10','LN2','LOG10E','LOG2E','PI','SQRT1_2','SQRT2','abs','acos','acosh','asin','asinh','atan','atan2','atanh','cbrt','ceil','clz32','cos','cosh','exp','expm1','floor','fround','hypot','imul','log','log10','log1p','log2','max','min','pow','random','round','sign','sin','sinh','sqrt','tan','tanh','trunc']
Added: trunk/LayoutTests/js/regexp-flags-expected.txt (0 => 185432)
--- trunk/LayoutTests/js/regexp-flags-expected.txt (rev 0)
+++ trunk/LayoutTests/js/regexp-flags-expected.txt 2015-06-10 22:32:36 UTC (rev 185432)
@@ -0,0 +1,29 @@
+Test RegExp#flags accessor
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+property descriptor
+PASS descriptor.configurable is true
+PASS descriptor.enumerable is false
+PASS typeof descriptor.get is 'function'
+PASS descriptor.set is undefined
+PASS /a/g.flags is 'g'
+PASS /a/.flags is ''
+PASS /a/gmi.flags is 'gim'
+PASS new RegExp('a', 'gmi').flags is 'gim'
+PASS flags.call(/a/ig) is 'gi'
+non-object receivers
+PASS flags.call(undefined) threw exception TypeError: Type error.
+PASS flags.call(null) threw exception TypeError: Type error.
+PASS flags.call(false) threw exception TypeError: Type error.
+PASS flags.call(true) threw exception TypeError: Type error.
+non-regex objects
+PASS flags.call({}) is ''
+PASS flags.call({global: true, multiline: true, ignoreCase: true}) is 'gim'
+PASS flags.call({global: 1, multiline: 0, ignoreCase: 2}) is 'gi'
+PASS flags.call({ __proto__: { multiline: true } }) is 'm'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/js/regexp-flags.html (0 => 185432)
--- trunk/LayoutTests/js/regexp-flags.html (rev 0)
+++ trunk/LayoutTests/js/regexp-flags.html 2015-06-10 22:32:36 UTC (rev 185432)
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+</body>
+</html>
Modified: trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js (185431 => 185432)
--- trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js 2015-06-10 21:53:42 UTC (rev 185431)
+++ trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js 2015-06-10 22:32:36 UTC (rev 185432)
@@ -65,7 +65,7 @@
"Date": "['UTC', 'length', 'name', 'now', 'parse', 'prototype']",
"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']",
"RegExp": "['$&', \"$'\", '$*', '$+', '$1', '$2', '$3', '$4', '$5', '$6', '$7', '$8', '$9', '$_', '$`', 'input', 'lastMatch', 'lastParen', 'leftContext', 'length', 'multiline', 'name', 'prototype', 'rightContext']",
- "RegExp.prototype": "['compile', 'constructor', 'exec', 'global', 'ignoreCase', 'lastIndex', 'multiline', 'source', 'test', 'toString']",
+ "RegExp.prototype": "['compile', 'constructor', 'exec', 'flags', 'global', 'ignoreCase', 'lastIndex', 'multiline', 'source', 'test', 'toString']",
"Error": "['length', 'name', 'prototype']",
"Error.prototype": "['constructor', 'message', 'name', 'toString']",
"Math": "['E','LN10','LN2','LOG10E','LOG2E','PI','SQRT1_2','SQRT2','abs','acos','acosh','asin','asinh','atan','atan2','atanh','cbrt','ceil','clz32','cos','cosh','exp','expm1','floor','fround','hypot','imul','log','log10','log1p','log2','max','min','pow','random','round','sign','sin','sinh','sqrt','tan','tanh','trunc']",
Added: trunk/LayoutTests/js/script-tests/regexp-flags.js (0 => 185432)
--- trunk/LayoutTests/js/script-tests/regexp-flags.js (rev 0)
+++ trunk/LayoutTests/js/script-tests/regexp-flags.js 2015-06-10 22:32:36 UTC (rev 185432)
@@ -0,0 +1,46 @@
+description('Test RegExp#flags accessor');
+
+debug("property descriptor");
+var descriptor = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags');
+shouldBe("descriptor.configurable", "true");
+shouldBe("descriptor.enumerable", "false");
+shouldBe("typeof descriptor.get", "'function'");
+shouldBe("descriptor.set", "undefined");
+
+var flags = descriptor.get;
+
+shouldBe("/a/g.flags", "'g'");
+shouldBe("/a/.flags", "''");
+shouldBe("/a/gmi.flags", "'gim'"); // order is specified, happens to be alphabetic
+shouldBe("new RegExp('a', 'gmi').flags", "'gim'");
+shouldBe("flags.call(/a/ig)", "'gi'");
+
+debug("non-object receivers");
+shouldThrow("flags.call(undefined)", "'TypeError: Type error'");
+shouldThrow("flags.call(null)", "'TypeError: Type error'");
+shouldThrow("flags.call(false)", "'TypeError: Type error'");
+shouldThrow("flags.call(true)", "'TypeError: Type error'");
+
+debug("non-regex objects");
+shouldBe("flags.call({})", "''");
+shouldBe("flags.call({global: true, multiline: true, ignoreCase: true})", "'gim'");
+shouldBe("flags.call({global: 1, multiline: 0, ignoreCase: 2})", "'gi'");
+// inherited properties count
+shouldBe("flags.call({ __proto__: { multiline: true } })", "'m'");
+
+if (RegExp.prototype.hasOwnProperty('sticky')) {
+ debug("sticky flag");
+ // when the engine supports "sticky", these tests will fail by design.
+ // Hopefully, only the expected output will need updating.
+ shouldBe("/a/yimg.flags", "'gimy'");
+ shouldBe("new RegExp('a', 'yimg').flags", "'gimy'");
+ shouldBe("flags.call({global: true, multiline: true, ignoreCase: true, sticky: true})", "'gimy'");
+}
+if (RegExp.prototype.hasOwnProperty('unicode')) {
+ debug("unicode flag");
+ // when the engine supports "unicode", these tests will fail by design.
+ // Hopefully, only the expected output will need updating.
+ shouldBe("/a/uimg.flags", "'gimu'");
+ shouldBe("new RegExp('a', 'uimg').flags", "'gimu'");
+ shouldBe("flags.call({global: true, multiline: true, ignoreCase: true, unicode: true})", "'gimu'");
+}
Modified: trunk/Source/_javascript_Core/ChangeLog (185431 => 185432)
--- trunk/Source/_javascript_Core/ChangeLog 2015-06-10 21:53:42 UTC (rev 185431)
+++ trunk/Source/_javascript_Core/ChangeLog 2015-06-10 22:32:36 UTC (rev 185432)
@@ -1,3 +1,18 @@
+2015-06-10 Jordan Harband <[email protected]>
+
+ Implement RegExp.prototype.flags
+ https://bugs.webkit.org/show_bug.cgi?id=145599
+
+ Reviewed by Geoffrey Garen.
+ 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:
+
2015-06-10 Filip Pizlo <[email protected]>
DFG ASSERTION FAILED: !iterate() on stress/singleton-scope-then-overwrite.js.ftl-eager
Modified: trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h (185431 => 185432)
--- trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h 2015-06-10 21:53:42 UTC (rev 185431)
+++ trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h 2015-06-10 22:32:36 UTC (rev 185432)
@@ -103,6 +103,7 @@
macro(exec) \
macro(executionCount) \
macro(exitKind) \
+ macro(flags) \
macro(focus) \
macro(forEach) \
macro(forward) \
Modified: trunk/Source/_javascript_Core/runtime/RegExpPrototype.cpp (185431 => 185432)
--- trunk/Source/_javascript_Core/runtime/RegExpPrototype.cpp 2015-06-10 21:53:42 UTC (rev 185431)
+++ trunk/Source/_javascript_Core/runtime/RegExpPrototype.cpp 2015-06-10 22:32:36 UTC (rev 185432)
@@ -47,6 +47,7 @@
static EncodedJSValue JSC_HOST_CALL regExpProtoGetterIgnoreCase(ExecState*);
static EncodedJSValue JSC_HOST_CALL regExpProtoGetterMultiline(ExecState*);
static EncodedJSValue JSC_HOST_CALL regExpProtoGetterSource(ExecState*);
+static EncodedJSValue JSC_HOST_CALL regExpProtoGetterFlags(ExecState*);
}
@@ -66,6 +67,7 @@
ignoreCase regExpProtoGetterIgnoreCase DontEnum|Accessor
multiline regExpProtoGetterMultiline DontEnum|Accessor
source regExpProtoGetterSource DontEnum|Accessor
+ flags regExpProtoGetterFlags DontEnum|Accessor
@end
*/
@@ -135,6 +137,30 @@
return JSValue::encode(jsUndefined());
}
+static inline String flagsString(ExecState *exec, JSObject* regexp)
+{
+ char flags[4] = { 0, 0, 0, 0 };
+ int index = 0;
+
+ JSValue globalValue = regexp->get(exec, exec->propertyNames().global);
+ if (exec->hadException())
+ return String();
+ JSValue ignoreCaseValue = regexp->get(exec, exec->propertyNames().ignoreCase);
+ if (exec->hadException())
+ return String();
+ JSValue multilineValue = regexp->get(exec, exec->propertyNames().multiline);
+ if (exec->hadException())
+ return String();
+
+ if (globalValue.toBoolean(exec))
+ flags[index++] = 'g';
+ if (ignoreCaseValue.toBoolean(exec))
+ flags[index++] = 'i';
+ if (multilineValue.toBoolean(exec))
+ flags[index] = 'm';
+ return String(flags);
+}
+
EncodedJSValue JSC_HOST_CALL regExpProtoFuncToString(ExecState* exec)
{
JSValue thisValue = exec->thisValue();
@@ -147,17 +173,19 @@
if (JSValue earlyReturnValue = checker.earlyReturnValue())
return JSValue::encode(earlyReturnValue);
- char postfix[5] = { '/', 0, 0, 0, 0 };
- int index = 1;
- if (thisObject->get(exec, exec->propertyNames().global).toBoolean(exec))
- postfix[index++] = 'g';
- if (thisObject->get(exec, exec->propertyNames().ignoreCase).toBoolean(exec))
- postfix[index++] = 'i';
- if (thisObject->get(exec, exec->propertyNames().multiline).toBoolean(exec))
- postfix[index] = 'm';
- String source = thisObject->get(exec, exec->propertyNames().source).toString(exec)->value(exec);
+ JSValue sourceValue = thisObject->get(exec, exec->propertyNames().source);
+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
+ String source = sourceValue.toString(exec)->value(exec);
+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
+
+ String flags = flagsString(exec, thisObject);
+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
+
// If source is empty, use "/(?:)/" to avoid colliding with comment syntax
- return JSValue::encode(jsMakeNontrivialString(exec, "/", source, postfix));
+ return JSValue::encode(jsMakeNontrivialString(exec, "/", source, "/", flags));
}
EncodedJSValue JSC_HOST_CALL regExpProtoGetterGlobal(ExecState* exec)
@@ -187,6 +215,21 @@
return JSValue::encode(jsBoolean(asRegExpObject(thisValue)->regExp()->multiline()));
}
+EncodedJSValue JSC_HOST_CALL regExpProtoGetterFlags(ExecState* exec)
+{
+ JSValue thisValue = exec->thisValue();
+ if (!thisValue.isObject())
+ return JSValue::encode(throwTypeError(exec));
+
+ String flagsStr = flagsString(exec, asObject(thisValue));
+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
+
+ JSValue flags = jsMakeNontrivialString(exec, flagsStr);
+ return JSValue::encode(flags);
+}
+
+
template <typename CharacterType>
static inline void appendLineTerminatorEscape(StringBuilder&, CharacterType);
Modified: trunk/Source/_javascript_Core/tests/stress/static-getter-in-names.js (185431 => 185432)
--- trunk/Source/_javascript_Core/tests/stress/static-getter-in-names.js 2015-06-10 21:53:42 UTC (rev 185431)
+++ trunk/Source/_javascript_Core/tests/stress/static-getter-in-names.js 2015-06-10 22:32:36 UTC (rev 185432)
@@ -3,5 +3,5 @@
throw new Error('bad value: ' + actual);
}
-shouldBe(JSON.stringify(Object.getOwnPropertyNames(RegExp.prototype).sort()), '["compile","constructor","exec","global","ignoreCase","lastIndex","multiline","source","test","toString"]');
+shouldBe(JSON.stringify(Object.getOwnPropertyNames(RegExp.prototype).sort()), '["compile","constructor","exec","flags","global","ignoreCase","lastIndex","multiline","source","test","toString"]');
shouldBe(JSON.stringify(Object.getOwnPropertyNames(/Cocoa/).sort()), '["lastIndex"]');