Bug 1130798 - Return "(?:)" for source of RegExp with empty pattern. r=till

This commit is contained in:
Tooru Fujisawa 2015-02-10 02:04:41 +09:00
Родитель df97a41a15
Коммит 3df47ea12f
7 изменённых файлов: 14 добавлений и 71 удалений

Просмотреть файл

@ -494,7 +494,12 @@ regexp_source_impl(JSContext *cx, CallArgs args)
if (!src)
return false;
args.rval().setString(src);
/* Step 7. */
if (src->length() == 0)
args.rval().setString(cx->names().emptyRegExp);
else
args.rval().setString(src);
return true;
}

Просмотреть файл

@ -6,10 +6,10 @@
/* Check the undefined pattern is equivalent to empty string. */
assertEq(RegExp(undefined).source, '');
assertEq(RegExp(undefined).source, '(?:)');
assertEq(RegExp(undefined).global, false);
assertEq("test".replace(RegExp(undefined), "*"), '*test');
assertEq(new RegExp(undefined).source, '');
assertEq(new RegExp(undefined).source, '(?:)');
assertEq(new RegExp(undefined).global, false);
assertEq('test'.replace(new RegExp(undefined), "*"), '*test');

Просмотреть файл

@ -40,7 +40,7 @@ AddTestCase(
AddTestCase(
"(new RegExp()).source",
"",
"(?:)",
re.source );
AddTestCase(

Просмотреть файл

@ -1,66 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* File Name: RegExp/function-001.js
* ECMA Section: 15.7.2.1
* Description: Based on ECMA 2 Draft 7 February 1999
*
* Author: christine@netscape.com
* Date: 19 February 1999
*/
var SECTION = "RegExp/function-001";
var VERSION = "ECMA_2";
var TITLE = "RegExp( pattern, flags )";
startTest();
/*
* for each test case, verify:
* - verify that [[Class]] property is RegExp
* - prototype property should be set to RegExp.prototype
* - source is set to the empty string
* - global property is set to false
* - ignoreCase property is set to false
* - multiline property is set to false
* - lastIndex property is set to 0
*/
RegExp.prototype.getClassProperty = Object.prototype.toString;
var re = new RegExp();
AddTestCase(
"RegExp.prototype.getClassProperty = Object.prototype.toString; " +
"(new RegExp()).getClassProperty()",
"[object RegExp]",
re.getClassProperty() );
AddTestCase(
"(new RegExp()).source",
"",
re.source );
AddTestCase(
"(new RegExp()).global",
false,
re.global );
AddTestCase(
"(new RegExp()).ignoreCase",
false,
re.ignoreCase );
AddTestCase(
"(new RegExp()).multiline",
false,
re.multiline );
AddTestCase(
"(new RegExp()).lastIndex",
0,
re.lastIndex );
test()

Просмотреть файл

@ -19,7 +19,7 @@ var BUGNUMBER ="";
startTest();
AddRegExpCases( new RegExp, "", false, false, false, 0 );
AddRegExpCases( new RegExp, "(?:)", false, false, false, 0 );
AddRegExpCases( /.*/, ".*", false, false, false, 0 );
AddRegExpCases( /[\d]{5}/g, "[\\d]{5}", true, false, false, 0 );
AddRegExpCases( /[\S]?$/i, "[\\S]?$", false, true, false, 0 );

Просмотреть файл

@ -3,9 +3,12 @@ var summary = "Implement RegExp.prototype.source";
print(BUGNUMBER + ": " + summary);
assertEq(RegExp.prototype.source, "(?:)");
assertEq(/foo/.source, "foo");
assertEq(/foo/iymg.source, "foo");
assertEq(/\//.source, "\\/");
assertEq(RegExp("").source, "(?:)");
assertEq(RegExp("", "mygi").source, "(?:)");
assertEq(RegExp("/").source, "\\/");
assertThrowsInstanceOf(() => genericSource(), TypeError);

Просмотреть файл

@ -64,6 +64,7 @@
macro(each, each, "each") \
macro(elementType, elementType, "elementType") \
macro(empty, empty, "") \
macro(emptyRegExp, emptyRegExp, "(?:)") \
macro(encodeURI, encodeURI, "encodeURI") \
macro(encodeURIComponent, encodeURIComponent, "encodeURIComponent") \
macro(enumerable, enumerable, "enumerable") \