Chromium Code Reviews| Index: src/factory.cc |
| diff --git a/src/factory.cc b/src/factory.cc |
| index 3948eec3a722461b50bfdc241322fedb837f6060..00f98e084766ee8ff70acc419095607fde60a237 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(String::cast(*descriptive_string)); |
|
Igor Sheludko
2017/05/23 07:08:23
String::cast is not necessary here.
Benedikt Meurer
2017/05/23 08:37:39
Done.
|
| + } |
| + return symbol; |
| +} |
| Handle<Symbol> Factory::NewPrivateSymbol() { |
|
Igor Sheludko
2017/05/23 07:08:23
Is this method still used?
Benedikt Meurer
2017/05/23 08:37:39
Yes.
|
| 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()); |