- return jsBoolean(asRegExpObject(slotBase)->regExp()->ignoreCase());
-}
-
-JSValue regExpObjectMultiline(ExecState*, JSValue slotBase, const Identifier&)
-{
- return jsBoolean(asRegExpObject(slotBase)->regExp()->multiline());
-}
-
-JSValue regExpObjectSource(ExecState* exec, JSValue slotBase, const Identifier&)
-{
- UString pattern = asRegExpObject(slotBase)->regExp()->pattern();
- unsigned length = pattern.length();
- const UChar* characters = pattern.characters();
- bool previousCharacterWasBackslash = false;
- bool inBrackets = false;
- bool shouldEscape = false;
-
- // 15.10.6.4 specifies that RegExp.prototype.toString must return '/' + source + '/',
- // and also states that the result must be a valid RegularExpressionLiteral. '//' is
- // not a valid RegularExpressionLiteral (since it is a single line comment), and hence
- // source cannot ever validly be "". If the source is empty, return a different Pattern
- // that would match the same thing.
- if (!length)
- return jsString(exec, "(?:)");
-
- // early return for strings that don't contain a forwards slash and LineTerminator
- for (unsigned i = 0; i < length; ++i) {
- UChar ch = characters[i];
- if (!previousCharacterWasBackslash) {
- if (inBrackets) {
- if (ch == ']')
- inBrackets = false;
- } else {
- if (ch == '/') {
- shouldEscape = true;
- break;
- }
- if (ch == '[')
- inBrackets = true;
- }
- }
-
- if (Lexer<UChar>::isLineTerminator(ch)) {
- shouldEscape = true;
- break;
- }
-
- if (previousCharacterWasBackslash)
- previousCharacterWasBackslash = false;
- else
- previousCharacterWasBackslash = ch == '\\';
- }
-
- if (!shouldEscape)
- return jsString(exec, pattern);
-
- previousCharacterWasBackslash = false;
- inBrackets = false;
- UStringBuilder result;
- for (unsigned i = 0; i < length; ++i) {
- UChar ch = characters[i];
- if (!previousCharacterWasBackslash) {
- if (inBrackets) {
- if (ch == ']')
- inBrackets = false;
- } else {
- if (ch == '/')
- result.append('\\');
- else if (ch == '[')
- inBrackets = true;
- }
- }
-
- // escape LineTerminator
- if (Lexer<UChar>::isLineTerminator(ch)) {
- if (!previousCharacterWasBackslash)
- result.append('\\');
-
- if (ch == '\n')
- result.append('n');
- else if (ch == '\r')
- result.append('r');
- else if (ch == 0x2028)
- result.append("u2028");
- else
- result.append("u2029");
- } else
- result.append(ch);
-
- if (previousCharacterWasBackslash)
- previousCharacterWasBackslash = false;
- else
- previousCharacterWasBackslash = ch == '\\';
- }
-
- return jsString(exec, result.toUString());