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/counters.h" |
7 | #include "src/heap/heap-inl.h" // For ToBoolean. TODO(jkummerow): Drop. |
8 | #include "src/isolate-inl.h" |
9 | #include "src/objects-inl.h" |
10 | #include "src/runtime/runtime-utils.h" |
11 | #include "src/string-builder-inl.h" |
12 | |
13 | namespace v8 { |
14 | namespace internal { |
15 | |
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 | CONVERT_ARG_HANDLE_CHECKED(Object, name, 0); |
22 | CHECK(name->IsString() || name->IsUndefined(isolate)); |
23 | if (name->IsString()) symbol->set_name(*name); |
24 | } |
25 | return *symbol; |
26 | } |
27 | |
28 | RUNTIME_FUNCTION(Runtime_CreatePrivateNameSymbol) { |
29 | HandleScope scope(isolate); |
30 | DCHECK_EQ(1, args.length()); |
31 | CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
32 | Handle<Symbol> symbol = isolate->factory()->NewPrivateNameSymbol(name); |
33 | return *symbol; |
34 | } |
35 | |
36 | RUNTIME_FUNCTION(Runtime_SymbolDescriptiveString) { |
37 | HandleScope scope(isolate); |
38 | DCHECK_EQ(1, args.length()); |
39 | CONVERT_ARG_HANDLE_CHECKED(Symbol, symbol, 0); |
40 | IncrementalStringBuilder builder(isolate); |
41 | builder.AppendCString("Symbol(" ); |
42 | if (symbol->name()->IsString()) { |
43 | builder.AppendString(handle(String::cast(symbol->name()), isolate)); |
44 | } |
45 | builder.AppendCharacter(')'); |
46 | RETURN_RESULT_OR_FAILURE(isolate, builder.Finish()); |
47 | } |
48 | |
49 | |
50 | RUNTIME_FUNCTION(Runtime_SymbolIsPrivate) { |
51 | SealHandleScope shs(isolate); |
52 | DCHECK_EQ(1, args.length()); |
53 | CONVERT_ARG_CHECKED(Symbol, symbol, 0); |
54 | return isolate->heap()->ToBoolean(symbol->is_private()); |
55 | } |
56 | } // namespace internal |
57 | } // namespace v8 |
58 | |