Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index 707ace30cac4b67a04843afa564361de485ff8f7..918e5e2ccae97edb74b9245a5ae2f17b23d7b572 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -15654,50 +15654,32 @@ class StringSharedKey : public HashTableKey { |
}; |
-// static |
-MaybeHandle<JSRegExp> JSRegExp::New(Handle<String> pattern, |
- Handle<String> flags) { |
- Isolate* isolate = pattern->GetIsolate(); |
- Handle<JSFunction> constructor = isolate->regexp_function(); |
- Handle<JSRegExp> regexp = |
- Handle<JSRegExp>::cast(isolate->factory()->NewJSObject(constructor)); |
- |
- return JSRegExp::Initialize(regexp, pattern, flags); |
-} |
- |
- |
-// static |
-Handle<JSRegExp> JSRegExp::Copy(Handle<JSRegExp> regexp) { |
- Isolate* const isolate = regexp->GetIsolate(); |
- return Handle<JSRegExp>::cast(isolate->factory()->CopyJSObject(regexp)); |
-} |
- |
+namespace { |
-static JSRegExp::Flags RegExpFlagsFromString(Handle<String> flags, |
- bool* success) { |
- uint32_t value = JSRegExp::NONE; |
+JSRegExp::Flags RegExpFlagsFromString(Handle<String> flags, bool* success) { |
+ JSRegExp::Flags value = JSRegExp::kNone; |
int length = flags->length(); |
// A longer flags string cannot be valid. |
if (length > 5) return JSRegExp::Flags(0); |
for (int i = 0; i < length; i++) { |
- uint32_t flag = JSRegExp::NONE; |
+ JSRegExp::Flag flag = JSRegExp::kNone; |
switch (flags->Get(i)) { |
case 'g': |
- flag = JSRegExp::GLOBAL; |
+ flag = JSRegExp::kGlobal; |
break; |
case 'i': |
- flag = JSRegExp::IGNORE_CASE; |
+ flag = JSRegExp::kIgnoreCase; |
break; |
case 'm': |
- flag = JSRegExp::MULTILINE; |
+ flag = JSRegExp::kMultiline; |
break; |
case 'u': |
if (!FLAG_harmony_unicode_regexps) return JSRegExp::Flags(0); |
- flag = JSRegExp::UNICODE_ESCAPES; |
+ flag = JSRegExp::kUnicode; |
break; |
case 'y': |
if (!FLAG_harmony_regexps) return JSRegExp::Flags(0); |
- flag = JSRegExp::STICKY; |
+ flag = JSRegExp::kSticky; |
break; |
default: |
return JSRegExp::Flags(0); |
@@ -15707,7 +15689,43 @@ static JSRegExp::Flags RegExpFlagsFromString(Handle<String> flags, |
value |= flag; |
} |
*success = true; |
- return JSRegExp::Flags(value); |
+ return value; |
+} |
+ |
+} // namespace |
+ |
+ |
+// static |
+MaybeHandle<JSRegExp> JSRegExp::New(Handle<String> pattern, Flags flags) { |
+ Isolate* isolate = pattern->GetIsolate(); |
+ Handle<JSFunction> constructor = isolate->regexp_function(); |
+ Handle<JSRegExp> regexp = |
+ Handle<JSRegExp>::cast(isolate->factory()->NewJSObject(constructor)); |
+ |
+ return JSRegExp::Initialize(regexp, pattern, flags); |
+} |
+ |
+ |
+// static |
+MaybeHandle<JSRegExp> JSRegExp::New(Handle<String> pattern, |
+ Handle<String> flags_string) { |
+ Isolate* isolate = pattern->GetIsolate(); |
+ bool success = false; |
+ Flags flags = RegExpFlagsFromString(flags_string, &success); |
+ if (!success) { |
+ THROW_NEW_ERROR( |
+ isolate, |
+ NewSyntaxError(MessageTemplate::kInvalidRegExpFlags, flags_string), |
+ JSRegExp); |
+ } |
+ return New(pattern, flags); |
+} |
+ |
+ |
+// static |
+Handle<JSRegExp> JSRegExp::Copy(Handle<JSRegExp> regexp) { |
+ Isolate* const isolate = regexp->GetIsolate(); |
+ return Handle<JSRegExp>::cast(isolate->factory()->CopyJSObject(regexp)); |
} |
@@ -15769,27 +15787,34 @@ MaybeHandle<String> EscapeRegExpSource(Isolate* isolate, |
MaybeHandle<JSRegExp> JSRegExp::Initialize(Handle<JSRegExp> regexp, |
Handle<String> source, |
Handle<String> flags_string) { |
- Isolate* isolate = regexp->GetIsolate(); |
- Factory* factory = isolate->factory(); |
- // If source is the empty string we set it to "(?:)" instead as |
- // suggested by ECMA-262, 5th, section 15.10.4.1. |
- if (source->length() == 0) source = factory->query_colon_string(); |
- |
+ Isolate* isolate = source->GetIsolate(); |
bool success = false; |
- JSRegExp::Flags flags = RegExpFlagsFromString(flags_string, &success); |
+ Flags flags = RegExpFlagsFromString(flags_string, &success); |
if (!success) { |
THROW_NEW_ERROR( |
isolate, |
NewSyntaxError(MessageTemplate::kInvalidRegExpFlags, flags_string), |
JSRegExp); |
} |
+ return Initialize(regexp, source, flags); |
+} |
+ |
+ |
+// static |
+MaybeHandle<JSRegExp> JSRegExp::Initialize(Handle<JSRegExp> regexp, |
+ Handle<String> source, Flags flags) { |
+ Isolate* isolate = regexp->GetIsolate(); |
+ Factory* factory = isolate->factory(); |
+ // If source is the empty string we set it to "(?:)" instead as |
+ // suggested by ECMA-262, 5th, section 15.10.4.1. |
+ if (source->length() == 0) source = factory->query_colon_string(); |
Handle<String> escaped_source; |
ASSIGN_RETURN_ON_EXCEPTION(isolate, escaped_source, |
EscapeRegExpSource(isolate, source), JSRegExp); |
regexp->set_source(*escaped_source); |
- regexp->set_flags(Smi::FromInt(flags.value())); |
+ regexp->set_flags(Smi::FromInt(flags)); |
Map* map = regexp->map(); |
Object* constructor = map->GetConstructor(); |
@@ -15819,8 +15844,7 @@ MaybeHandle<JSRegExp> JSRegExp::Initialize(Handle<JSRegExp> regexp, |
class RegExpKey : public HashTableKey { |
public: |
RegExpKey(Handle<String> string, JSRegExp::Flags flags) |
- : string_(string), |
- flags_(Smi::FromInt(flags.value())) { } |
+ : string_(string), flags_(Smi::FromInt(flags)) {} |
// Rather than storing the key in the hash table, a pointer to the |
// stored value is stored where the key should be. IsMatch then |