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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/runtime/runtime-utils.h" | 8 #include "src/runtime/runtime-utils.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 | 12 |
13 RUNTIME_FUNCTION(Runtime_CreateSymbol) { | 13 RUNTIME_FUNCTION(Runtime_CreateSymbol) { |
14 HandleScope scope(isolate); | 14 HandleScope scope(isolate); |
15 DCHECK(args.length() == 1); | 15 DCHECK(args.length() == 1); |
16 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0); | 16 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0); |
17 RUNTIME_ASSERT(name->IsString() || name->IsUndefined()); | 17 RUNTIME_ASSERT(name->IsString() || name->IsUndefined()); |
18 Handle<Symbol> symbol = isolate->factory()->NewSymbol(); | 18 Handle<Symbol> symbol = isolate->factory()->NewSymbol(); |
19 if (name->IsString()) symbol->set_name(*name); | 19 if (name->IsString()) symbol->set_name(*name); |
20 return *symbol; | 20 return *symbol; |
21 } | 21 } |
22 | 22 |
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 Handle<Symbol> symbol = isolate->factory()->NewPrivateSymbol(); | 29 return *isolate->factory()->NewPrivateSymbol(name); |
30 if (name->IsString()) symbol->set_name(*name); | |
31 return *symbol; | |
32 } | 30 } |
33 | 31 |
34 | 32 |
35 RUNTIME_FUNCTION(Runtime_CreatePrivateOwnSymbol) { | 33 RUNTIME_FUNCTION(Runtime_CreateGlobalPrivateSymbol) { |
36 HandleScope scope(isolate); | |
37 DCHECK(args.length() == 1); | |
38 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0); | |
39 RUNTIME_ASSERT(name->IsString() || name->IsUndefined()); | |
40 return *isolate->factory()->NewPrivateOwnSymbol(name); | |
41 } | |
42 | |
43 | |
44 RUNTIME_FUNCTION(Runtime_CreateGlobalPrivateOwnSymbol) { | |
45 HandleScope scope(isolate); | 34 HandleScope scope(isolate); |
46 DCHECK(args.length() == 1); | 35 DCHECK(args.length() == 1); |
47 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | 36 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
48 Handle<JSObject> registry = isolate->GetSymbolRegistry(); | 37 Handle<JSObject> registry = isolate->GetSymbolRegistry(); |
49 Handle<String> part = isolate->factory()->private_intern_string(); | 38 Handle<String> part = isolate->factory()->private_intern_string(); |
50 Handle<Object> privates; | 39 Handle<Object> privates; |
51 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, privates, | 40 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, privates, |
52 Object::GetProperty(registry, part)); | 41 Object::GetProperty(registry, part)); |
53 Handle<Object> symbol; | 42 Handle<Object> symbol; |
54 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, symbol, | 43 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, symbol, |
55 Object::GetProperty(privates, name)); | 44 Object::GetProperty(privates, name)); |
56 if (!symbol->IsSymbol()) { | 45 if (!symbol->IsSymbol()) { |
57 DCHECK(symbol->IsUndefined()); | 46 DCHECK(symbol->IsUndefined()); |
58 symbol = isolate->factory()->NewPrivateOwnSymbol(name); | 47 symbol = isolate->factory()->NewPrivateSymbol(name); |
59 JSObject::AddProperty(Handle<JSObject>::cast(privates), name, symbol, NONE); | 48 JSObject::AddProperty(Handle<JSObject>::cast(privates), name, symbol, NONE); |
60 } | 49 } |
61 return *symbol; | 50 return *symbol; |
62 } | 51 } |
63 | 52 |
64 | 53 |
65 RUNTIME_FUNCTION(Runtime_NewSymbolWrapper) { | 54 RUNTIME_FUNCTION(Runtime_NewSymbolWrapper) { |
66 HandleScope scope(isolate); | 55 HandleScope scope(isolate); |
67 DCHECK(args.length() == 1); | 56 DCHECK(args.length() == 1); |
68 CONVERT_ARG_HANDLE_CHECKED(Symbol, symbol, 0); | 57 CONVERT_ARG_HANDLE_CHECKED(Symbol, symbol, 0); |
(...skipping 17 matching lines...) Expand all Loading... |
86 | 75 |
87 | 76 |
88 RUNTIME_FUNCTION(Runtime_SymbolIsPrivate) { | 77 RUNTIME_FUNCTION(Runtime_SymbolIsPrivate) { |
89 SealHandleScope shs(isolate); | 78 SealHandleScope shs(isolate); |
90 DCHECK(args.length() == 1); | 79 DCHECK(args.length() == 1); |
91 CONVERT_ARG_CHECKED(Symbol, symbol, 0); | 80 CONVERT_ARG_CHECKED(Symbol, symbol, 0); |
92 return isolate->heap()->ToBoolean(symbol->is_private()); | 81 return isolate->heap()->ToBoolean(symbol->is_private()); |
93 } | 82 } |
94 } // namespace internal | 83 } // namespace internal |
95 } // namespace v8 | 84 } // namespace v8 |
OLD | NEW |