v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
runtime-symbol.cc
Go to the documentation of this file.
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
7#include "src/heap/heap-inl.h" // For ToBoolean. TODO(jkummerow): Drop.
10
11namespace v8 {
12namespace internal {
13
14RUNTIME_FUNCTION(Runtime_CreatePrivateSymbol) {
15 HandleScope scope(isolate);
16 DCHECK_GE(1, args.length());
17 DirectHandle<Symbol> symbol = isolate->factory()->NewPrivateSymbol();
18 if (args.length() == 1) {
19 DirectHandle<Object> description = args.at(0);
20 CHECK(IsString(*description) || IsUndefined(*description, isolate));
21 if (IsString(*description))
22 symbol->set_description(Cast<String>(*description));
23 }
24 return *symbol;
25}
26
27RUNTIME_FUNCTION(Runtime_CreatePrivateBrandSymbol) {
28 HandleScope scope(isolate);
29 DCHECK_EQ(1, args.length());
30 DirectHandle<String> name = args.at<String>(0);
31 DirectHandle<Symbol> symbol = isolate->factory()->NewPrivateNameSymbol(name);
32 symbol->set_is_private_brand();
33 return *symbol;
34}
35
36RUNTIME_FUNCTION(Runtime_CreatePrivateNameSymbol) {
37 HandleScope scope(isolate);
38 DCHECK_EQ(1, args.length());
39 DirectHandle<String> name = args.at<String>(0);
40 DirectHandle<Symbol> symbol = isolate->factory()->NewPrivateNameSymbol(name);
41 return *symbol;
42}
43
44RUNTIME_FUNCTION(Runtime_SymbolDescriptiveString) {
45 HandleScope scope(isolate);
46 DCHECK_EQ(1, args.length());
47 DirectHandle<Symbol> symbol = args.at<Symbol>(0);
48 IncrementalStringBuilder builder(isolate);
49 builder.AppendCStringLiteral("Symbol(");
50 if (IsString(symbol->description())) {
51 builder.AppendString(
52 direct_handle(Cast<String>(symbol->description()), isolate));
53 }
54 builder.AppendCharacter(')');
55 RETURN_RESULT_OR_FAILURE(isolate, builder.Finish());
56}
57
58
59RUNTIME_FUNCTION(Runtime_SymbolIsPrivate) {
60 SealHandleScope shs(isolate);
61 DCHECK_EQ(1, args.length());
62 auto symbol = Cast<Symbol>(args[0]);
63 return isolate->heap()->ToBoolean(symbol->is_private());
64}
65} // namespace internal
66} // namespace v8
#define RUNTIME_FUNCTION(Name)
Definition arguments.h:162
#define RETURN_RESULT_OR_FAILURE(isolate, call)
Definition isolate.h:264
base::Vector< const DirectHandle< Object > > args
Definition execution.cc:74
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
#define CHECK(condition)
Definition logging.h:124
#define DCHECK_GE(v1, v2)
Definition logging.h:488
#define DCHECK_EQ(v1, v2)
Definition logging.h:485