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

Unified Diff: src/factory.cc

Issue 2900703002: [es2015] Precompute the descriptive string for symbols. (Closed)
Patch Set: Address feedback. Created 3 years, 7 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/factory.h ('k') | src/heap-symbols.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index 3948eec3a722461b50bfdc241322fedb837f6060..9c73a519ae0512cbb6284c89395d55f47b116464 100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -16,6 +16,7 @@
#include "src/objects/frame-array-inl.h"
#include "src/objects/module-info.h"
#include "src/objects/scope-info.h"
+#include "src/string-builder.h"
namespace v8 {
namespace internal {
@@ -909,6 +910,28 @@ Handle<Symbol> Factory::NewSymbol() {
Symbol);
}
+MaybeHandle<Symbol> Factory::NewSymbol(Handle<Object> name) {
+ DCHECK(name->IsString() || name->IsUndefined(isolate()));
+ Handle<Symbol> symbol = NewSymbol();
+ if (name->IsString()) {
+ // Compute the descriptive string for the {symbol}.
+ Handle<String> descriptive_string;
+ IncrementalStringBuilder builder(isolate());
+ builder.AppendCString("Symbol(");
+ builder.AppendString(Handle<String>::cast(name));
+ builder.AppendCharacter(')');
+ ASSIGN_RETURN_ON_EXCEPTION(isolate(), descriptive_string, builder.Finish(),
+ Symbol);
+
+ // Make sure those strings are flattened.
+ name = String::Flatten(Handle<String>::cast(name), TENURED);
+ descriptive_string = String::Flatten(descriptive_string, TENURED);
+
+ symbol->set_name(String::cast(*name));
+ symbol->set_descriptive_string(*descriptive_string);
+ }
+ return symbol;
+}
Handle<Symbol> Factory::NewPrivateSymbol() {
Handle<Symbol> symbol = NewSymbol();
@@ -916,6 +939,13 @@ Handle<Symbol> Factory::NewPrivateSymbol() {
return symbol;
}
+MaybeHandle<Symbol> Factory::NewPrivateSymbol(Handle<Object> name) {
+ Handle<Symbol> symbol;
+ ASSIGN_RETURN_ON_EXCEPTION(isolate(), symbol, NewSymbol(name), Symbol);
+ symbol->set_is_private(true);
+ return symbol;
+}
+
Handle<JSPromise> Factory::NewJSPromise() {
Handle<JSFunction> constructor(
isolate()->native_context()->promise_function(), isolate());
« no previous file with comments | « src/factory.h ('k') | src/heap-symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698