aboutsummaryrefslogtreecommitdiff
path: root/src/builtins/builtins-symbol.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/builtins/builtins-symbol.cc')
-rw-r--r--src/builtins/builtins-symbol.cc78
1 files changed, 59 insertions, 19 deletions
diff --git a/src/builtins/builtins-symbol.cc b/src/builtins/builtins-symbol.cc
index 8dd8a1fa..f57d0bff 100644
--- a/src/builtins/builtins-symbol.cc
+++ b/src/builtins/builtins-symbol.cc
@@ -2,8 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "src/builtins/builtins.h"
#include "src/builtins/builtins-utils.h"
+#include "src/builtins/builtins.h"
+#include "src/code-stub-assembler.h"
+#include "src/counters.h"
+#include "src/objects-inl.h"
namespace v8 {
namespace internal {
@@ -32,44 +35,81 @@ 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(
- CodeStubAssembler* assembler) {
+ compiler::CodeAssemblerState* state) {
typedef compiler::Node Node;
+ CodeStubAssembler assembler(state);
- Node* receiver = assembler->Parameter(0);
- Node* context = assembler->Parameter(4);
+ Node* receiver = assembler.Parameter(0);
+ Node* context = assembler.Parameter(4);
Node* result =
- assembler->ToThisValue(context, receiver, PrimitiveType::kSymbol,
- "Symbol.prototype [ @@toPrimitive ]");
- assembler->Return(result);
+ assembler.ToThisValue(context, receiver, PrimitiveType::kSymbol,
+ "Symbol.prototype [ @@toPrimitive ]");
+ assembler.Return(result);
}
// ES6 section 19.4.3.2 Symbol.prototype.toString ( )
-void Builtins::Generate_SymbolPrototypeToString(CodeStubAssembler* assembler) {
+void Builtins::Generate_SymbolPrototypeToString(
+ compiler::CodeAssemblerState* state) {
typedef compiler::Node Node;
+ CodeStubAssembler assembler(state);
- Node* receiver = assembler->Parameter(0);
- Node* context = assembler->Parameter(3);
+ Node* receiver = assembler.Parameter(0);
+ Node* context = assembler.Parameter(3);
- Node* value = assembler->ToThisValue(
- context, receiver, PrimitiveType::kSymbol, "Symbol.prototype.toString");
+ Node* value = assembler.ToThisValue(context, receiver, PrimitiveType::kSymbol,
+ "Symbol.prototype.toString");
Node* result =
- assembler->CallRuntime(Runtime::kSymbolDescriptiveString, context, value);
- assembler->Return(result);
+ assembler.CallRuntime(Runtime::kSymbolDescriptiveString, context, value);
+ assembler.Return(result);
}
// ES6 section 19.4.3.3 Symbol.prototype.valueOf ( )
-void Builtins::Generate_SymbolPrototypeValueOf(CodeStubAssembler* assembler) {
+void Builtins::Generate_SymbolPrototypeValueOf(
+ compiler::CodeAssemblerState* state) {
typedef compiler::Node Node;
+ CodeStubAssembler assembler(state);
- Node* receiver = assembler->Parameter(0);
- Node* context = assembler->Parameter(3);
+ Node* receiver = assembler.Parameter(0);
+ Node* context = assembler.Parameter(3);
- Node* result = assembler->ToThisValue(
+ Node* result = assembler.ToThisValue(
context, receiver, PrimitiveType::kSymbol, "Symbol.prototype.valueOf");
- assembler->Return(result);
+ assembler.Return(result);
}
} // namespace internal