| Index: src/builtins/builtins-regexp-gen.cc
|
| diff --git a/src/builtins/builtins-regexp.cc b/src/builtins/builtins-regexp-gen.cc
|
| similarity index 93%
|
| copy from src/builtins/builtins-regexp.cc
|
| copy to src/builtins/builtins-regexp-gen.cc
|
| index eef9953a8a565cd97f7e62fdda95743db041e2b6..707d7661f19d90cd2ab1c9cfba7db3170f0c3a6b 100644
|
| --- a/src/builtins/builtins-regexp.cc
|
| +++ b/src/builtins/builtins-regexp-gen.cc
|
| @@ -1,26 +1,21 @@
|
| -// Copyright 2016 the V8 project authors. All rights reserved.
|
| +// Copyright 2017 the V8 project authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "src/builtins/builtins-regexp.h"
|
| +#include "src/builtins/builtins-regexp-gen.h"
|
|
|
| #include "src/builtins/builtins-constructor.h"
|
| -#include "src/builtins/builtins-utils.h"
|
| +#include "src/builtins/builtins-utils-gen.h"
|
| #include "src/builtins/builtins.h"
|
| #include "src/code-factory.h"
|
| #include "src/code-stub-assembler.h"
|
| -#include "src/counters.h"
|
| -#include "src/objects-inl.h"
|
| #include "src/objects/regexp-match-info.h"
|
| -#include "src/regexp/jsregexp.h"
|
| -#include "src/regexp/regexp-utils.h"
|
| -#include "src/string-builder.h"
|
| +#include "src/regexp/regexp-macro-assembler.h"
|
|
|
| namespace v8 {
|
| namespace internal {
|
|
|
| -typedef CodeStubAssembler::ParameterMode ParameterMode;
|
| -
|
| +using compiler::Node;
|
|
|
| // -----------------------------------------------------------------------------
|
| // ES6 section 21.2 RegExp Objects
|
| @@ -1175,43 +1170,6 @@ TF_BUILTIN(RegExpPrototypeSourceGetter, RegExpBuiltinsAssembler) {
|
| }
|
| }
|
|
|
| -BUILTIN(RegExpPrototypeToString) {
|
| - HandleScope scope(isolate);
|
| - CHECK_RECEIVER(JSReceiver, recv, "RegExp.prototype.toString");
|
| -
|
| - if (*recv == isolate->regexp_function()->prototype()) {
|
| - isolate->CountUsage(v8::Isolate::kRegExpPrototypeToString);
|
| - }
|
| -
|
| - IncrementalStringBuilder builder(isolate);
|
| -
|
| - builder.AppendCharacter('/');
|
| - {
|
| - Handle<Object> source;
|
| - ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
|
| - isolate, source,
|
| - JSReceiver::GetProperty(recv, isolate->factory()->source_string()));
|
| - Handle<String> source_str;
|
| - ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, source_str,
|
| - Object::ToString(isolate, source));
|
| - builder.AppendString(source_str);
|
| - }
|
| -
|
| - builder.AppendCharacter('/');
|
| - {
|
| - Handle<Object> flags;
|
| - ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
|
| - isolate, flags,
|
| - JSReceiver::GetProperty(recv, isolate->factory()->flags_string()));
|
| - Handle<String> flags_str;
|
| - ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, flags_str,
|
| - Object::ToString(isolate, flags));
|
| - builder.AppendString(flags_str);
|
| - }
|
| -
|
| - RETURN_RESULT_OR_FAILURE(isolate, builder.Finish());
|
| -}
|
| -
|
| // Fast-path implementation for flag checks on an unmodified JSRegExp instance.
|
| Node* RegExpBuiltinsAssembler::FastFlagGetter(Node* const regexp,
|
| JSRegExp::Flag flag) {
|
| @@ -1372,89 +1330,6 @@ TF_BUILTIN(RegExpPrototypeUnicodeGetter, RegExpBuiltinsAssembler) {
|
| "RegExp.prototype.unicode");
|
| }
|
|
|
| -// The properties $1..$9 are the first nine capturing substrings of the last
|
| -// successful match, or ''. The function RegExpMakeCaptureGetter will be
|
| -// called with indices from 1 to 9.
|
| -#define DEFINE_CAPTURE_GETTER(i) \
|
| - BUILTIN(RegExpCapture##i##Getter) { \
|
| - HandleScope scope(isolate); \
|
| - return *RegExpUtils::GenericCaptureGetter( \
|
| - isolate, isolate->regexp_last_match_info(), i); \
|
| - }
|
| -DEFINE_CAPTURE_GETTER(1)
|
| -DEFINE_CAPTURE_GETTER(2)
|
| -DEFINE_CAPTURE_GETTER(3)
|
| -DEFINE_CAPTURE_GETTER(4)
|
| -DEFINE_CAPTURE_GETTER(5)
|
| -DEFINE_CAPTURE_GETTER(6)
|
| -DEFINE_CAPTURE_GETTER(7)
|
| -DEFINE_CAPTURE_GETTER(8)
|
| -DEFINE_CAPTURE_GETTER(9)
|
| -#undef DEFINE_CAPTURE_GETTER
|
| -
|
| -// The properties `input` and `$_` are aliases for each other. When this
|
| -// value is set, the value it is set to is coerced to a string.
|
| -// Getter and setter for the input.
|
| -
|
| -BUILTIN(RegExpInputGetter) {
|
| - HandleScope scope(isolate);
|
| - Handle<Object> obj(isolate->regexp_last_match_info()->LastInput(), isolate);
|
| - return obj->IsUndefined(isolate) ? isolate->heap()->empty_string()
|
| - : String::cast(*obj);
|
| -}
|
| -
|
| -BUILTIN(RegExpInputSetter) {
|
| - HandleScope scope(isolate);
|
| - Handle<Object> value = args.atOrUndefined(isolate, 1);
|
| - Handle<String> str;
|
| - ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, str,
|
| - Object::ToString(isolate, value));
|
| - isolate->regexp_last_match_info()->SetLastInput(*str);
|
| - return isolate->heap()->undefined_value();
|
| -}
|
| -
|
| -// Getters for the static properties lastMatch, lastParen, leftContext, and
|
| -// rightContext of the RegExp constructor. The properties are computed based
|
| -// on the captures array of the last successful match and the subject string
|
| -// of the last successful match.
|
| -BUILTIN(RegExpLastMatchGetter) {
|
| - HandleScope scope(isolate);
|
| - return *RegExpUtils::GenericCaptureGetter(
|
| - isolate, isolate->regexp_last_match_info(), 0);
|
| -}
|
| -
|
| -BUILTIN(RegExpLastParenGetter) {
|
| - HandleScope scope(isolate);
|
| - Handle<RegExpMatchInfo> match_info = isolate->regexp_last_match_info();
|
| - const int length = match_info->NumberOfCaptureRegisters();
|
| - if (length <= 2) return isolate->heap()->empty_string(); // No captures.
|
| -
|
| - DCHECK_EQ(0, length % 2);
|
| - const int last_capture = (length / 2) - 1;
|
| -
|
| - // We match the SpiderMonkey behavior: return the substring defined by the
|
| - // last pair (after the first pair) of elements of the capture array even if
|
| - // it is empty.
|
| - return *RegExpUtils::GenericCaptureGetter(isolate, match_info, last_capture);
|
| -}
|
| -
|
| -BUILTIN(RegExpLeftContextGetter) {
|
| - HandleScope scope(isolate);
|
| - Handle<RegExpMatchInfo> match_info = isolate->regexp_last_match_info();
|
| - const int start_index = match_info->Capture(0);
|
| - Handle<String> last_subject(match_info->LastSubject());
|
| - return *isolate->factory()->NewSubString(last_subject, 0, start_index);
|
| -}
|
| -
|
| -BUILTIN(RegExpRightContextGetter) {
|
| - HandleScope scope(isolate);
|
| - Handle<RegExpMatchInfo> match_info = isolate->regexp_last_match_info();
|
| - const int start_index = match_info->Capture(1);
|
| - Handle<String> last_subject(match_info->LastSubject());
|
| - const int len = last_subject->length();
|
| - return *isolate->factory()->NewSubString(last_subject, start_index, len);
|
| -}
|
| -
|
| // ES#sec-regexpexec Runtime Semantics: RegExpExec ( R, S )
|
| Node* RegExpBuiltinsAssembler::RegExpExec(Node* context, Node* regexp,
|
| Node* string) {
|
| @@ -1729,7 +1604,8 @@ class GrowableFixedArray {
|
|
|
| const ElementsKind kind = FAST_ELEMENTS;
|
| const WriteBarrierMode barrier_mode = UPDATE_WRITE_BARRIER;
|
| - const ParameterMode mode = CodeStubAssembler::INTPTR_PARAMETERS;
|
| + const CodeStubAssembler::ParameterMode mode =
|
| + CodeStubAssembler::INTPTR_PARAMETERS;
|
| const CodeStubAssembler::AllocationFlags flags =
|
| CodeStubAssembler::kAllowLargeObjectAllocation;
|
|
|
| @@ -2514,40 +2390,42 @@ Node* RegExpBuiltinsAssembler::ReplaceGlobalCallableFastPath(
|
| Node* const to = SmiUntag(res_length);
|
| const int increment = 1;
|
|
|
| - BuildFastLoop(
|
| - from, to,
|
| - [this, res_elems, isolate, native_context, context, undefined,
|
| - replace_callable](Node* index) {
|
| - Node* const elem = LoadFixedArrayElement(res_elems, index);
|
| + BuildFastLoop(from, to,
|
| + [this, res_elems, isolate, native_context, context, undefined,
|
| + replace_callable](Node* index) {
|
| + Node* const elem = LoadFixedArrayElement(res_elems, index);
|
|
|
| - Label do_continue(this);
|
| - GotoIf(TaggedIsSmi(elem), &do_continue);
|
| + Label do_continue(this);
|
| + GotoIf(TaggedIsSmi(elem), &do_continue);
|
|
|
| - // elem must be an Array.
|
| - // Use the apply argument as backing for global RegExp properties.
|
| + // elem must be an Array.
|
| + // Use the apply argument as backing for global RegExp
|
| + // properties.
|
|
|
| - CSA_ASSERT(this, HasInstanceType(elem, JS_ARRAY_TYPE));
|
| + CSA_ASSERT(this, HasInstanceType(elem, JS_ARRAY_TYPE));
|
|
|
| - // TODO(jgruber): Remove indirection through Call->ReflectApply.
|
| - Callable call_callable = CodeFactory::Call(isolate);
|
| - Node* const reflect_apply =
|
| - LoadContextElement(native_context, Context::REFLECT_APPLY_INDEX);
|
| + // TODO(jgruber): Remove indirection through
|
| + // Call->ReflectApply.
|
| + Callable call_callable = CodeFactory::Call(isolate);
|
| + Node* const reflect_apply = LoadContextElement(
|
| + native_context, Context::REFLECT_APPLY_INDEX);
|
|
|
| - Node* const replacement_obj =
|
| - CallJS(call_callable, context, reflect_apply, undefined,
|
| - replace_callable, undefined, elem);
|
| + Node* const replacement_obj =
|
| + CallJS(call_callable, context, reflect_apply, undefined,
|
| + replace_callable, undefined, elem);
|
|
|
| - // Overwrite the i'th element in the results with the string we got
|
| - // back from the callback function.
|
| + // Overwrite the i'th element in the results with the string
|
| + // we got back from the callback function.
|
|
|
| - Node* const replacement_str = ToString(context, replacement_obj);
|
| - StoreFixedArrayElement(res_elems, index, replacement_str);
|
| + Node* const replacement_str =
|
| + ToString(context, replacement_obj);
|
| + StoreFixedArrayElement(res_elems, index, replacement_str);
|
|
|
| - Goto(&do_continue);
|
| - Bind(&do_continue);
|
| - },
|
| - increment, CodeStubAssembler::INTPTR_PARAMETERS,
|
| - CodeStubAssembler::IndexAdvanceMode::kPost);
|
| + Goto(&do_continue);
|
| + Bind(&do_continue);
|
| + },
|
| + increment, CodeStubAssembler::INTPTR_PARAMETERS,
|
| + CodeStubAssembler::IndexAdvanceMode::kPost);
|
|
|
| Goto(&create_result);
|
| }
|
|
|