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/objects-inl.h" | 8 #include "src/objects-inl.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 RUNTIME_FUNCTION(Runtime_CreatePrivateSymbol) { | 24 RUNTIME_FUNCTION(Runtime_CreatePrivateSymbol) { |
25 HandleScope scope(isolate); | 25 HandleScope scope(isolate); |
26 DCHECK(args.length() == 1); | 26 DCHECK(args.length() == 1); |
27 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0); | 27 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0); |
28 RUNTIME_ASSERT(name->IsString() || name->IsUndefined()); | 28 RUNTIME_ASSERT(name->IsString() || name->IsUndefined()); |
29 return *isolate->factory()->NewPrivateSymbol(name); | 29 return *isolate->factory()->NewPrivateSymbol(name); |
30 } | 30 } |
31 | 31 |
32 | 32 |
33 RUNTIME_FUNCTION(Runtime_CreateGlobalPrivateSymbol) { | |
34 HandleScope scope(isolate); | |
35 DCHECK(args.length() == 1); | |
36 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | |
37 Handle<JSObject> registry = isolate->GetSymbolRegistry(); | |
38 Handle<String> part = isolate->factory()->private_intern_string(); | |
39 Handle<Object> privates; | |
40 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, privates, | |
41 Object::GetProperty(registry, part)); | |
42 Handle<Object> symbol; | |
43 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, symbol, | |
44 Object::GetProperty(privates, name)); | |
45 if (!symbol->IsSymbol()) { | |
46 DCHECK(symbol->IsUndefined()); | |
47 symbol = isolate->factory()->NewPrivateSymbol(name); | |
48 JSObject::AddProperty(Handle<JSObject>::cast(privates), name, symbol, NONE); | |
49 } | |
50 return *symbol; | |
51 } | |
52 | |
53 | |
54 RUNTIME_FUNCTION(Runtime_SymbolDescription) { | 33 RUNTIME_FUNCTION(Runtime_SymbolDescription) { |
55 SealHandleScope shs(isolate); | 34 SealHandleScope shs(isolate); |
56 DCHECK(args.length() == 1); | 35 DCHECK(args.length() == 1); |
57 CONVERT_ARG_CHECKED(Symbol, symbol, 0); | 36 CONVERT_ARG_CHECKED(Symbol, symbol, 0); |
58 return symbol->name(); | 37 return symbol->name(); |
59 } | 38 } |
60 | 39 |
61 | 40 |
62 RUNTIME_FUNCTION(Runtime_SymbolRegistry) { | 41 RUNTIME_FUNCTION(Runtime_SymbolRegistry) { |
63 HandleScope scope(isolate); | 42 HandleScope scope(isolate); |
64 DCHECK(args.length() == 0); | 43 DCHECK(args.length() == 0); |
65 return *isolate->GetSymbolRegistry(); | 44 return *isolate->GetSymbolRegistry(); |
66 } | 45 } |
67 | 46 |
68 | 47 |
69 RUNTIME_FUNCTION(Runtime_SymbolIsPrivate) { | 48 RUNTIME_FUNCTION(Runtime_SymbolIsPrivate) { |
70 SealHandleScope shs(isolate); | 49 SealHandleScope shs(isolate); |
71 DCHECK(args.length() == 1); | 50 DCHECK(args.length() == 1); |
72 CONVERT_ARG_CHECKED(Symbol, symbol, 0); | 51 CONVERT_ARG_CHECKED(Symbol, symbol, 0); |
73 return isolate->heap()->ToBoolean(symbol->is_private()); | 52 return isolate->heap()->ToBoolean(symbol->is_private()); |
74 } | 53 } |
75 } // namespace internal | 54 } // namespace internal |
76 } // namespace v8 | 55 } // namespace v8 |
OLD | NEW |