Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(464)

Unified Diff: src/builtins/builtins-regexp.cc

Issue 2392463005: [regexp] Port RegExpCompile and RegExpToString (Closed)
Patch Set: Rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/builtins/builtins.h ('k') | src/js/regexp.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins/builtins-regexp.cc
diff --git a/src/builtins/builtins-regexp.cc b/src/builtins/builtins-regexp.cc
index a121a951c9da4abf6ca8d99fed8c4e6545592e99..a555d45073049034fb4d7ff1f9d7315ff2a07a5f 100644
--- a/src/builtins/builtins-regexp.cc
+++ b/src/builtins/builtins-regexp.cc
@@ -7,6 +7,7 @@
#include "src/code-factory.h"
#include "src/regexp/jsregexp.h"
+#include "src/string-builder.h"
namespace v8 {
namespace internal {
@@ -158,6 +159,36 @@ BUILTIN(RegExpConstructor) {
RegExpInitialize(isolate, regexp, pattern, flags));
}
+BUILTIN(RegExpPrototypeCompile) {
+ HandleScope scope(isolate);
+ CHECK_RECEIVER(JSRegExp, regexp, "RegExp.prototype.compile");
+
+ Handle<Object> pattern = args.atOrUndefined(isolate, 1);
+ Handle<Object> flags = args.atOrUndefined(isolate, 2);
+
+ if (pattern->IsJSRegExp()) {
+ Handle<JSRegExp> pattern_regexp = Handle<JSRegExp>::cast(pattern);
+
+ if (!flags->IsUndefined(isolate)) {
+ THROW_NEW_ERROR_RETURN_FAILURE(
+ isolate, NewTypeError(MessageTemplate::kRegExpFlags));
+ }
+
+ flags = PatternFlags(isolate, pattern_regexp);
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, pattern,
+ Object::GetProperty(pattern, isolate->factory()->source_string()));
+ }
+
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, regexp, RegExpInitialize(isolate, regexp, pattern, flags));
+
+ // Return undefined for compatibility with JSC.
+ // See http://crbug.com/585775 for web compat details.
+
+ return isolate->heap()->undefined_value();
+}
+
namespace {
compiler::Node* LoadLastIndex(CodeStubAssembler* a, compiler::Node* context,
@@ -656,6 +687,43 @@ BUILTIN(RegExpPrototypeSourceGetter) {
return regexp->source();
}
+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());
+}
+
// ES6 21.2.4.2.
BUILTIN(RegExpPrototypeSpeciesGetter) {
HandleScope scope(isolate);
« no previous file with comments | « src/builtins/builtins.h ('k') | src/js/regexp.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698