OLD | NEW |
(Empty) | |
| 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/v8.h" |
| 6 |
| 7 #include "src/arguments.h" |
| 8 #include "src/runtime/runtime.h" |
| 9 #include "src/runtime/runtime-utils.h" |
| 10 |
| 11 namespace v8 { |
| 12 namespace internal { |
| 13 |
| 14 RUNTIME_FUNCTION(Runtime_CreateSymbol) { |
| 15 HandleScope scope(isolate); |
| 16 DCHECK(args.length() == 1); |
| 17 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0); |
| 18 RUNTIME_ASSERT(name->IsString() || name->IsUndefined()); |
| 19 Handle<Symbol> symbol = isolate->factory()->NewSymbol(); |
| 20 if (name->IsString()) symbol->set_name(*name); |
| 21 return *symbol; |
| 22 } |
| 23 |
| 24 |
| 25 RUNTIME_FUNCTION(Runtime_CreatePrivateSymbol) { |
| 26 HandleScope scope(isolate); |
| 27 DCHECK(args.length() == 1); |
| 28 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0); |
| 29 RUNTIME_ASSERT(name->IsString() || name->IsUndefined()); |
| 30 Handle<Symbol> symbol = isolate->factory()->NewPrivateSymbol(); |
| 31 if (name->IsString()) symbol->set_name(*name); |
| 32 return *symbol; |
| 33 } |
| 34 |
| 35 |
| 36 RUNTIME_FUNCTION(Runtime_CreatePrivateOwnSymbol) { |
| 37 HandleScope scope(isolate); |
| 38 DCHECK(args.length() == 1); |
| 39 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0); |
| 40 RUNTIME_ASSERT(name->IsString() || name->IsUndefined()); |
| 41 Handle<Symbol> symbol = isolate->factory()->NewPrivateOwnSymbol(); |
| 42 if (name->IsString()) symbol->set_name(*name); |
| 43 return *symbol; |
| 44 } |
| 45 |
| 46 |
| 47 RUNTIME_FUNCTION(Runtime_CreateGlobalPrivateOwnSymbol) { |
| 48 HandleScope scope(isolate); |
| 49 DCHECK(args.length() == 1); |
| 50 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
| 51 Handle<JSObject> registry = isolate->GetSymbolRegistry(); |
| 52 Handle<String> part = isolate->factory()->private_intern_string(); |
| 53 Handle<Object> privates; |
| 54 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 55 isolate, privates, Object::GetPropertyOrElement(registry, part)); |
| 56 Handle<Object> symbol; |
| 57 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 58 isolate, symbol, Object::GetPropertyOrElement(privates, name)); |
| 59 if (!symbol->IsSymbol()) { |
| 60 DCHECK(symbol->IsUndefined()); |
| 61 symbol = isolate->factory()->NewPrivateSymbol(); |
| 62 Handle<Symbol>::cast(symbol)->set_name(*name); |
| 63 Handle<Symbol>::cast(symbol)->set_is_own(true); |
| 64 JSObject::SetProperty(Handle<JSObject>::cast(privates), name, symbol, |
| 65 STRICT).Assert(); |
| 66 } |
| 67 return *symbol; |
| 68 } |
| 69 |
| 70 |
| 71 RUNTIME_FUNCTION(Runtime_NewSymbolWrapper) { |
| 72 HandleScope scope(isolate); |
| 73 DCHECK(args.length() == 1); |
| 74 CONVERT_ARG_HANDLE_CHECKED(Symbol, symbol, 0); |
| 75 return *Object::ToObject(isolate, symbol).ToHandleChecked(); |
| 76 } |
| 77 |
| 78 |
| 79 RUNTIME_FUNCTION(Runtime_SymbolDescription) { |
| 80 SealHandleScope shs(isolate); |
| 81 DCHECK(args.length() == 1); |
| 82 CONVERT_ARG_CHECKED(Symbol, symbol, 0); |
| 83 return symbol->name(); |
| 84 } |
| 85 |
| 86 |
| 87 RUNTIME_FUNCTION(Runtime_SymbolRegistry) { |
| 88 HandleScope scope(isolate); |
| 89 DCHECK(args.length() == 0); |
| 90 return *isolate->GetSymbolRegistry(); |
| 91 } |
| 92 |
| 93 |
| 94 RUNTIME_FUNCTION(Runtime_SymbolIsPrivate) { |
| 95 SealHandleScope shs(isolate); |
| 96 DCHECK(args.length() == 1); |
| 97 CONVERT_ARG_CHECKED(Symbol, symbol, 0); |
| 98 return isolate->heap()->ToBoolean(symbol->is_private()); |
| 99 } |
| 100 } |
| 101 } // namespace v8::internal |
OLD | NEW |