1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/arguments-inl.h"
6 #include "src/isolate-inl.h"
7 #include "src/objects-inl.h"
8 #include "src/runtime/runtime-utils.h"
9 #include "src/string-builder-inl.h"
10
11 namespace v8 {
12 namespace internal {
13
RUNTIME_FUNCTION(Runtime_CreatePrivateSymbol)14 RUNTIME_FUNCTION(Runtime_CreatePrivateSymbol) {
15 HandleScope scope(isolate);
16 DCHECK_GE(1, args.length());
17 Handle<Symbol> symbol = isolate->factory()->NewPrivateSymbol();
18 if (args.length() == 1) {
19 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0);
20 CHECK(name->IsString() || name->IsUndefined(isolate));
21 if (name->IsString()) symbol->set_name(*name);
22 }
23 return *symbol;
24 }
25
RUNTIME_FUNCTION(Runtime_CreatePrivateFieldSymbol)26 RUNTIME_FUNCTION(Runtime_CreatePrivateFieldSymbol) {
27 HandleScope scope(isolate);
28 DCHECK_EQ(0, args.length());
29 Handle<Symbol> symbol = isolate->factory()->NewPrivateFieldSymbol();
30 return *symbol;
31 }
32
RUNTIME_FUNCTION(Runtime_SymbolDescriptiveString)33 RUNTIME_FUNCTION(Runtime_SymbolDescriptiveString) {
34 HandleScope scope(isolate);
35 DCHECK_EQ(1, args.length());
36 CONVERT_ARG_HANDLE_CHECKED(Symbol, symbol, 0);
37 IncrementalStringBuilder builder(isolate);
38 builder.AppendCString("Symbol(");
39 if (symbol->name()->IsString()) {
40 builder.AppendString(handle(String::cast(symbol->name()), isolate));
41 }
42 builder.AppendCharacter(')');
43 RETURN_RESULT_OR_FAILURE(isolate, builder.Finish());
44 }
45
46
RUNTIME_FUNCTION(Runtime_SymbolIsPrivate)47 RUNTIME_FUNCTION(Runtime_SymbolIsPrivate) {
48 SealHandleScope shs(isolate);
49 DCHECK_EQ(1, args.length());
50 CONVERT_ARG_CHECKED(Symbol, symbol, 0);
51 return isolate->heap()->ToBoolean(symbol->is_private());
52 }
53 } // namespace internal
54 } // namespace v8
55