• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/runtime/runtime-utils.h"
6 
7 #include "src/arguments.h"
8 #include "src/isolate-inl.h"
9 #include "src/objects-inl.h"
10 #include "src/string-builder.h"
11 
12 namespace v8 {
13 namespace internal {
14 
RUNTIME_FUNCTION(Runtime_CreateSymbol)15 RUNTIME_FUNCTION(Runtime_CreateSymbol) {
16   HandleScope scope(isolate);
17   DCHECK(args.length() == 1);
18   CONVERT_ARG_HANDLE_CHECKED(Object, name, 0);
19   RUNTIME_ASSERT(name->IsString() || name->IsUndefined());
20   Handle<Symbol> symbol = isolate->factory()->NewSymbol();
21   if (name->IsString()) symbol->set_name(*name);
22   return *symbol;
23 }
24 
25 
RUNTIME_FUNCTION(Runtime_CreatePrivateSymbol)26 RUNTIME_FUNCTION(Runtime_CreatePrivateSymbol) {
27   HandleScope scope(isolate);
28   DCHECK(args.length() == 1);
29   CONVERT_ARG_HANDLE_CHECKED(Object, name, 0);
30   RUNTIME_ASSERT(name->IsString() || name->IsUndefined());
31   Handle<Symbol> symbol = isolate->factory()->NewPrivateSymbol();
32   if (name->IsString()) symbol->set_name(*name);
33   return *symbol;
34 }
35 
36 
RUNTIME_FUNCTION(Runtime_SymbolDescription)37 RUNTIME_FUNCTION(Runtime_SymbolDescription) {
38   SealHandleScope shs(isolate);
39   DCHECK(args.length() == 1);
40   CONVERT_ARG_CHECKED(Symbol, symbol, 0);
41   return symbol->name();
42 }
43 
44 
RUNTIME_FUNCTION(Runtime_SymbolDescriptiveString)45 RUNTIME_FUNCTION(Runtime_SymbolDescriptiveString) {
46   HandleScope scope(isolate);
47   DCHECK_EQ(1, args.length());
48   CONVERT_ARG_HANDLE_CHECKED(Symbol, symbol, 0);
49   IncrementalStringBuilder builder(isolate);
50   builder.AppendCString("Symbol(");
51   if (symbol->name()->IsString()) {
52     builder.AppendString(handle(String::cast(symbol->name()), isolate));
53   }
54   builder.AppendCharacter(')');
55   Handle<String> result;
56   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, builder.Finish());
57   return *result;
58 }
59 
60 
RUNTIME_FUNCTION(Runtime_SymbolRegistry)61 RUNTIME_FUNCTION(Runtime_SymbolRegistry) {
62   HandleScope scope(isolate);
63   DCHECK(args.length() == 0);
64   return *isolate->GetSymbolRegistry();
65 }
66 
67 
RUNTIME_FUNCTION(Runtime_SymbolIsPrivate)68 RUNTIME_FUNCTION(Runtime_SymbolIsPrivate) {
69   SealHandleScope shs(isolate);
70   DCHECK(args.length() == 1);
71   CONVERT_ARG_CHECKED(Symbol, symbol, 0);
72   return isolate->heap()->ToBoolean(symbol->is_private());
73 }
74 }  // namespace internal
75 }  // namespace v8
76