• 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/execution/arguments-inl.h"
6 #include "src/execution/isolate-inl.h"
7 #include "src/heap/heap-inl.h"  // For ToBoolean. TODO(jkummerow): Drop.
8 #include "src/logging/counters.h"
9 #include "src/objects/objects-inl.h"
10 #include "src/runtime/runtime-utils.h"
11 #include "src/strings/string-builder-inl.h"
12 
13 namespace v8 {
14 namespace internal {
15 
RUNTIME_FUNCTION(Runtime_CreatePrivateSymbol)16 RUNTIME_FUNCTION(Runtime_CreatePrivateSymbol) {
17   HandleScope scope(isolate);
18   DCHECK_GE(1, args.length());
19   Handle<Symbol> symbol = isolate->factory()->NewPrivateSymbol();
20   if (args.length() == 1) {
21     Handle<Object> description = args.at(0);
22     CHECK(description->IsString() || description->IsUndefined(isolate));
23     if (description->IsString())
24       symbol->set_description(String::cast(*description));
25   }
26   return *symbol;
27 }
28 
RUNTIME_FUNCTION(Runtime_CreatePrivateBrandSymbol)29 RUNTIME_FUNCTION(Runtime_CreatePrivateBrandSymbol) {
30   HandleScope scope(isolate);
31   DCHECK_EQ(1, args.length());
32   Handle<String> name = args.at<String>(0);
33   Handle<Symbol> symbol = isolate->factory()->NewPrivateNameSymbol(name);
34   symbol->set_is_private_brand();
35   return *symbol;
36 }
37 
RUNTIME_FUNCTION(Runtime_CreatePrivateNameSymbol)38 RUNTIME_FUNCTION(Runtime_CreatePrivateNameSymbol) {
39   HandleScope scope(isolate);
40   DCHECK_EQ(1, args.length());
41   Handle<String> name = args.at<String>(0);
42   Handle<Symbol> symbol = isolate->factory()->NewPrivateNameSymbol(name);
43   return *symbol;
44 }
45 
RUNTIME_FUNCTION(Runtime_SymbolDescriptiveString)46 RUNTIME_FUNCTION(Runtime_SymbolDescriptiveString) {
47   HandleScope scope(isolate);
48   DCHECK_EQ(1, args.length());
49   Handle<Symbol> symbol = args.at<Symbol>(0);
50   IncrementalStringBuilder builder(isolate);
51   builder.AppendCStringLiteral("Symbol(");
52   if (symbol->description().IsString()) {
53     builder.AppendString(handle(String::cast(symbol->description()), isolate));
54   }
55   builder.AppendCharacter(')');
56   RETURN_RESULT_OR_FAILURE(isolate, builder.Finish());
57 }
58 
59 
RUNTIME_FUNCTION(Runtime_SymbolIsPrivate)60 RUNTIME_FUNCTION(Runtime_SymbolIsPrivate) {
61   SealHandleScope shs(isolate);
62   DCHECK_EQ(1, args.length());
63   auto symbol = Symbol::cast(args[0]);
64   return isolate->heap()->ToBoolean(symbol.is_private());
65 }
66 }  // namespace internal
67 }  // namespace v8
68