зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1130798 - Return "(?:)" for source of RegExp with empty pattern. r=till
This commit is contained in:
Родитель
df97a41a15
Коммит
3df47ea12f
|
@ -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") \
|
||||
|
|
Загрузка…
Ссылка в новой задаче