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