From b5fe01d3ac81fc955260a679af059183b81be237 Mon Sep 17 00:00:00 2001 From: Tooru Fujisawa Date: Mon, 9 May 2016 20:48:40 +0900 Subject: [PATCH] Bug 1271147 - Merge RegExpCreate and regexp_construct self-hosting builtins. r=till --- js/src/builtin/Intl.js | 12 ++++++------ js/src/builtin/RegExp.cpp | 27 +-------------------------- js/src/builtin/RegExp.h | 10 ---------- js/src/builtin/String.js | 4 ++-- js/src/vm/SelfHosting.cpp | 7 +++---- 5 files changed, 12 insertions(+), 48 deletions(-) diff --git a/js/src/builtin/Intl.js b/js/src/builtin/Intl.js index 68c1a0692e58..cf3fbb5efe10 100644 --- a/js/src/builtin/Intl.js +++ b/js/src/builtin/Intl.js @@ -81,7 +81,7 @@ internalIntlRegExps.currencyDigitsRE = null; function getUnicodeLocaleExtensionSequenceRE() { return internalIntlRegExps.unicodeLocaleExtensionSequenceRE || (internalIntlRegExps.unicodeLocaleExtensionSequenceRE = - regexp_construct("-u(?:-[a-z0-9]{2,8})+")); + RegExpCreate("-u(?:-[a-z0-9]{2,8})+")); } @@ -215,7 +215,7 @@ function getLanguageTagRE() { var languageTag = "^(?:" + langtag + "|" + privateuse + "|" + grandfathered + ")$"; // Language tags are case insensitive (RFC 5646 section 2.1.1). - return (internalIntlRegExps.languageTagRE = regexp_construct(languageTag, "i")); + return (internalIntlRegExps.languageTagRE = RegExpCreate(languageTag, "i")); } @@ -261,7 +261,7 @@ function getDuplicateVariantRE() { // regular expression to address this. (Note that there's no worry about // case transformation accepting invalid characters here: users have // already verified the string is alphanumeric Latin plus "-".) - return (internalIntlRegExps.duplicateVariantRE = regexp_construct(duplicateVariant, "i")); + return (internalIntlRegExps.duplicateVariantRE = RegExpCreate(duplicateVariant, "i")); } @@ -306,7 +306,7 @@ function getDuplicateSingletonRE() { // expression to address this. (Note that there's no worry about case // transformation accepting invalid characters here: users have already // verified the string is alphanumeric Latin plus "-".) - return (internalIntlRegExps.duplicateSingletonRE = regexp_construct(duplicateSingleton, "i")); + return (internalIntlRegExps.duplicateSingletonRE = RegExpCreate(duplicateSingleton, "i")); } @@ -611,7 +611,7 @@ function DefaultLocale() { */ function getIsWellFormedCurrencyCodeRE() { return internalIntlRegExps.isWellFormedCurrencyCodeRE || - (internalIntlRegExps.isWellFormedCurrencyCodeRE = regexp_construct("[^A-Z]")); + (internalIntlRegExps.isWellFormedCurrencyCodeRE = RegExpCreate("[^A-Z]")); } function IsWellFormedCurrencyCode(currency) { var c = ToString(currency); @@ -1936,7 +1936,7 @@ var currencyDigits = { */ function getCurrencyDigitsRE() { return internalIntlRegExps.currencyDigitsRE || - (internalIntlRegExps.currencyDigitsRE = regexp_construct("^[A-Z]{3}$")); + (internalIntlRegExps.currencyDigitsRE = RegExpCreate("^[A-Z]{3}$")); } function CurrencyDigits(currency) { assert(typeof currency === "string", "CurrencyDigits"); diff --git a/js/src/builtin/RegExp.cpp b/js/src/builtin/RegExp.cpp index a73258ca1cf0..7e102694217f 100644 --- a/js/src/builtin/RegExp.cpp +++ b/js/src/builtin/RegExp.cpp @@ -243,7 +243,7 @@ js::RegExpCreate(JSContext* cx, HandleValue patternValue, HandleValue flagsValue MutableHandleValue rval) { /* Step 1. */ - Rooted regexp(cx, RegExpAlloc(cx, nullptr)); + Rooted regexp(cx, RegExpAlloc(cx)); if (!regexp) return false; @@ -492,31 +492,6 @@ js::regexp_construct(JSContext* cx, unsigned argc, Value* vp) return true; } -bool -js::regexp_construct_self_hosting(JSContext* cx, unsigned argc, Value* vp) -{ - CallArgs args = CallArgsFromVp(argc, vp); - - MOZ_ASSERT(args.length() == 1 || args.length() == 2); - MOZ_ASSERT(args[0].isString()); - MOZ_ASSERT_IF(args.length() == 2, args[1].isString()); - MOZ_ASSERT(!args.isConstructing()); - - /* Steps 1-6 are not required since pattern is always string. */ - - /* Steps 7-10. */ - Rooted regexp(cx, RegExpAlloc(cx)); - if (!regexp) - return false; - - if (!RegExpInitializeIgnoringLastIndex(cx, regexp, args[0], args.get(1))) - return false; - regexp->zeroLastIndex(cx); - - args.rval().setObject(*regexp); - return true; -} - /* * ES 2017 draft rev 6a13789aa9e7c6de4e96b7d3e24d9e6eba6584ad 21.2.3.1 * steps 4, 7-8. diff --git a/js/src/builtin/RegExp.h b/js/src/builtin/RegExp.h index 80d88e104b07..8de688bf0b07 100644 --- a/js/src/builtin/RegExp.h +++ b/js/src/builtin/RegExp.h @@ -87,16 +87,6 @@ regexp_exec_no_statics(JSContext* cx, unsigned argc, Value* vp); extern bool regexp_test_no_statics(JSContext* cx, unsigned argc, Value* vp); -/* - * Behaves like RegExp(string) or RegExp(string, string), for self-hosted JS. - * pattern and flags should be string, and should be called without |new|. - * - * Usage: re = regexp_construct(pattern) - * re = regexp_construct(pattern, flags) - */ -extern bool -regexp_construct_self_hosting(JSContext* cx, unsigned argc, Value* vp); - /* * Behaves like RegExp(pattern, string). * pattern should be a RegExp object, and flags should be a string, diff --git a/js/src/builtin/String.js b/js/src/builtin/String.js index 1e271a308bbb..5deff7f19a7c 100644 --- a/js/src/builtin/String.js +++ b/js/src/builtin/String.js @@ -47,7 +47,7 @@ function String_match(regexp) { } // Step 4. - var rx = RegExpCreate(regexp, undefined); + var rx = RegExpCreate(regexp); // Step 5 (optimized case). if (IsStringMatchOptimizable()) @@ -240,7 +240,7 @@ function String_search(regexp) { } // Step 4. - var rx = RegExpCreate(regexp, undefined); + var rx = RegExpCreate(regexp); // Step 5. return callContentFunction(GetMethod(rx, std_search), rx, string); diff --git a/js/src/vm/SelfHosting.cpp b/js/src/vm/SelfHosting.cpp index a41be8984aa6..6bc37057f2c8 100644 --- a/js/src/vm/SelfHosting.cpp +++ b/js/src/vm/SelfHosting.cpp @@ -1565,11 +1565,11 @@ intrinsic_RegExpCreate(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); - MOZ_ASSERT(args.length() == 2); - MOZ_ASSERT(args[1].isString() || args[1].isUndefined()); + MOZ_ASSERT(args.length() == 1 || args.length() == 2); + MOZ_ASSERT_IF(args.length() == 2, args[1].isString() || args[1].isUndefined()); MOZ_ASSERT(!args.isConstructing()); - return RegExpCreate(cx, args[0], args[1], args.rval()); + return RegExpCreate(cx, args[0], args.get(1), args.rval()); } static bool @@ -2540,7 +2540,6 @@ static const JSFunctionSpec intrinsic_functions[] = { // See builtin/RegExp.h for descriptions of the regexp_* functions. JS_FN("regexp_exec_no_statics", regexp_exec_no_statics, 2,0), JS_FN("regexp_test_no_statics", regexp_test_no_statics, 2,0), - JS_FN("regexp_construct", regexp_construct_self_hosting, 2,0), JS_FN("regexp_construct_no_sticky", regexp_construct_no_sticky, 2,0), JS_FN("IsModule", intrinsic_IsInstanceOfBuiltin, 1, 0),