Index: src/builtins/builtins-symbol.cc |
diff --git a/src/builtins/builtins-symbol.cc b/src/builtins/builtins-symbol.cc |
index 209bd58f6faaa3ac09528829be9b60af492a7eca..b422d8f321fefbfb66f055958345689c2ba7f3c1 100644 |
--- a/src/builtins/builtins-symbol.cc |
+++ b/src/builtins/builtins-symbol.cc |
@@ -32,6 +32,38 @@ BUILTIN(SymbolConstructor_ConstructStub) { |
isolate->factory()->Symbol_string())); |
} |
+// ES6 section 19.4.2.1 Symbol.for. |
+BUILTIN(SymbolFor) { |
+ HandleScope scope(isolate); |
+ Handle<Object> key_obj = args.atOrUndefined(isolate, 1); |
+ Handle<String> key; |
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, key, |
+ Object::ToString(isolate, key_obj)); |
+ return *isolate->SymbolFor(Heap::kPublicSymbolTableRootIndex, key, false); |
+} |
+ |
+// ES6 section 19.4.2.5 Symbol.keyFor. |
+BUILTIN(SymbolKeyFor) { |
+ HandleScope scope(isolate); |
+ Handle<Object> obj = args.atOrUndefined(isolate, 1); |
+ if (!obj->IsSymbol()) { |
+ THROW_NEW_ERROR_RETURN_FAILURE( |
+ isolate, NewTypeError(MessageTemplate::kSymbolKeyFor, obj)); |
+ } |
+ Handle<Symbol> symbol = Handle<Symbol>::cast(obj); |
+ DisallowHeapAllocation no_gc; |
+ Object* result; |
+ if (symbol->is_public()) { |
+ result = symbol->name(); |
+ DCHECK(result->IsString()); |
+ } else { |
+ result = isolate->heap()->undefined_value(); |
+ } |
+ DCHECK_EQ(isolate->heap()->public_symbol_table()->SlowReverseLookup(*symbol), |
+ result); |
+ return result; |
+} |
+ |
// ES6 section 19.4.3.4 Symbol.prototype [ @@toPrimitive ] ( hint ) |
void Builtins::Generate_SymbolPrototypeToPrimitive( |
compiler::CodeAssemblerState* state) { |